blob: b9659b8b70f853c1aec7d2811dfa2132a4bb9208 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Johannes Bergd98ad832014-09-03 15:24:57 +03005 * Copyright 2013-2014 Intel Mobile Communications GmbH
Jiri Bencf0706e82007-05-05 11:45:53 -07006 *
7 * This file is GPLv2 as found in COPYING.
8 */
9
Johannes Berge8cbb4c2007-12-19 02:03:30 +010010#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070011#include <linux/nl80211.h>
12#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090013#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070014#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010015#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030016#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070017#include <net/cfg80211.h>
18#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020019#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040020#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040021#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022#include "mesh.h"
Johannes Berg02219b32014-10-07 10:38:50 +030023#include "wme.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010024
Johannes Berg552bff02012-09-19 09:26:06 +020025static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
26 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020027 enum nl80211_iftype type,
28 u32 *flags,
29 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070030{
31 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020032 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010033 struct ieee80211_sub_if_data *sdata;
34 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070035
Johannes Berg84efbb82012-06-16 00:00:26 +020036 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010037 if (err)
38 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010039
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020041 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010042 sdata->u.mntr_flags = *flags;
43 }
44
Johannes Berg84efbb82012-06-16 00:00:26 +020045 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070046}
47
Johannes Berg84efbb82012-06-16 00:00:26 +020048static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070049{
Johannes Berg84efbb82012-06-16 00:00:26 +020050 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070051
Johannes Berg75636522008-07-09 14:40:35 +020052 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070053}
54
Johannes Berge36d56b2009-06-09 21:04:43 +020055static int ieee80211_change_iface(struct wiphy *wiphy,
56 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010057 enum nl80211_iftype type, u32 *flags,
58 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020059{
Johannes Berg9607e6b2009-12-23 13:15:31 +010060 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020061 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020062
Johannes Berg05c914f2008-09-11 00:01:58 +020063 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020064 if (ret)
65 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020066
Johannes Berg9bc383d2009-11-19 11:55:19 +010067 if (type == NL80211_IFTYPE_AP_VLAN &&
68 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000069 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010070 else if (type == NL80211_IFTYPE_STATION &&
71 params && params->use_4addr >= 0)
72 sdata->u.mgd.use_4addr = params->use_4addr;
73
Christian Lamparter85416a42010-10-02 13:17:07 +020074 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
75 struct ieee80211_local *local = sdata->local;
76
77 if (ieee80211_sdata_running(sdata)) {
Felix Fietkau31eba5b2013-05-28 13:01:53 +020078 u32 mask = MONITOR_FLAG_COOK_FRAMES |
79 MONITOR_FLAG_ACTIVE;
80
Christian Lamparter85416a42010-10-02 13:17:07 +020081 /*
Felix Fietkau31eba5b2013-05-28 13:01:53 +020082 * Prohibit MONITOR_FLAG_COOK_FRAMES and
83 * MONITOR_FLAG_ACTIVE to be changed while the
84 * interface is up.
Christian Lamparter85416a42010-10-02 13:17:07 +020085 * Else we would need to add a lot of cruft
86 * to update everything:
87 * cooked_mntrs, monitor and all fif_* counters
88 * reconfigure hardware
89 */
Felix Fietkau31eba5b2013-05-28 13:01:53 +020090 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
Christian Lamparter85416a42010-10-02 13:17:07 +020091 return -EBUSY;
92
93 ieee80211_adjust_monitor_flags(sdata, -1);
94 sdata->u.mntr_flags = *flags;
95 ieee80211_adjust_monitor_flags(sdata, 1);
96
97 ieee80211_configure_filter(local);
98 } else {
99 /*
100 * Because the interface is down, ieee80211_do_stop
101 * and ieee80211_do_open take care of "everything"
102 * mentioned in the comment above.
103 */
104 sdata->u.mntr_flags = *flags;
105 }
106 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200107
Johannes Berg42613db2007-09-28 21:52:27 +0200108 return 0;
109}
110
Johannes Bergf142c6b2012-06-18 20:07:15 +0200111static int ieee80211_start_p2p_device(struct wiphy *wiphy,
112 struct wireless_dev *wdev)
113{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200114 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
115 int ret;
116
117 mutex_lock(&sdata->local->chanctx_mtx);
118 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
119 mutex_unlock(&sdata->local->chanctx_mtx);
120 if (ret < 0)
121 return ret;
122
Johannes Bergf142c6b2012-06-18 20:07:15 +0200123 return ieee80211_do_open(wdev, true);
124}
125
126static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
127 struct wireless_dev *wdev)
128{
129 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
130}
131
Simon Wunderlichb53be792011-11-18 14:20:44 +0100132static int ieee80211_set_noack_map(struct wiphy *wiphy,
133 struct net_device *dev,
134 u16 noack_map)
135{
136 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
137
138 sdata->noack_map = noack_map;
139 return 0;
140}
141
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100142static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200143 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100144 struct key_params *params)
145{
Johannes Berg26a58452010-08-27 12:35:55 +0200146 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200147 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100148 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200149 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100150 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200151 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100152
Johannes Berg26a58452010-08-27 12:35:55 +0200153 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200154 return -ENETDOWN;
155
Johannes Berg97359d12010-08-10 09:46:38 +0200156 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100157 switch (params->cipher) {
158 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100159 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200160 case WLAN_CIPHER_SUITE_WEP104:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200161 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg97359d12010-08-10 09:46:38 +0200162 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200163 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200164 case WLAN_CIPHER_SUITE_CCMP:
165 case WLAN_CIPHER_SUITE_AES_CMAC:
166 case WLAN_CIPHER_SUITE_GCMP:
167 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100168 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200169 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200170 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100171 }
172
Johannes Berg97359d12010-08-10 09:46:38 +0200173 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200174 params->key, params->seq_len, params->seq,
175 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100176 if (IS_ERR(key))
177 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100178
Johannes Berge31b8212010-10-05 19:39:30 +0200179 if (pairwise)
180 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
181
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200182 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200183
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100184 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700185 if (ieee80211_vif_is_mesh(&sdata->vif))
186 sta = sta_info_get(sdata, mac_addr);
187 else
188 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100189 /*
190 * The ASSOC test makes sure the driver is ready to
191 * receive the key. When wpa_supplicant has roamed
192 * using FT, it attempts to set the key before
193 * association has completed, this rejects that attempt
Stephen Hemmingerd070f912014-10-29 22:55:58 -0700194 * so it will set the key again after association.
Johannes Berg1626e0f2013-01-11 14:34:25 +0100195 *
196 * TODO: accept the key if we have a station entry and
197 * add it to the device after the station.
198 */
199 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100200 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200201 err = -ENOENT;
202 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100203 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100204 }
205
Johannes Berge548c492012-09-04 17:08:23 +0200206 switch (sdata->vif.type) {
207 case NL80211_IFTYPE_STATION:
208 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
209 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
210 break;
211 case NL80211_IFTYPE_AP:
212 case NL80211_IFTYPE_AP_VLAN:
213 /* Keys without a station are used for TX only */
214 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
215 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
216 break;
217 case NL80211_IFTYPE_ADHOC:
218 /* no MFP (yet) */
219 break;
220 case NL80211_IFTYPE_MESH_POINT:
221#ifdef CONFIG_MAC80211_MESH
222 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
223 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
224 break;
225#endif
226 case NL80211_IFTYPE_WDS:
227 case NL80211_IFTYPE_MONITOR:
228 case NL80211_IFTYPE_P2P_DEVICE:
229 case NL80211_IFTYPE_UNSPECIFIED:
230 case NUM_NL80211_IFTYPES:
231 case NL80211_IFTYPE_P2P_CLIENT:
232 case NL80211_IFTYPE_P2P_GO:
233 /* shouldn't happen */
234 WARN_ON_ONCE(1);
235 break;
236 }
237
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200238 if (sta)
239 sta->cipher_scheme = cs;
240
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300241 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100242
Johannes Berg3b967662008-04-08 17:56:52 +0200243 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200244 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200245
246 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100247}
248
249static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200250 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100251{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200252 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
253 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100254 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200255 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100256 int ret;
257
Johannes Berg5c0c3642011-05-12 14:31:49 +0200258 mutex_lock(&local->sta_mtx);
259 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200260
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100261 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200262 ret = -ENOENT;
263
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100264 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100265 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200266 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100267
Johannes Berg5c0c3642011-05-12 14:31:49 +0200268 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200269 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200270 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200271 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200272 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200273 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100274
Johannes Berg5c0c3642011-05-12 14:31:49 +0200275 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200276 ret = -ENOENT;
277 goto out_unlock;
278 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100279
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100280 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100281
Johannes Berg3b967662008-04-08 17:56:52 +0200282 ret = 0;
283 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200284 mutex_unlock(&local->key_mtx);
285 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200286
287 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100288}
289
Johannes Berg62da92f2007-12-19 02:03:31 +0100290static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200291 u8 key_idx, bool pairwise, const u8 *mac_addr,
292 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100293 void (*callback)(void *cookie,
294 struct key_params *params))
295{
Johannes Berg14db74b2008-07-29 13:22:52 +0200296 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100297 struct sta_info *sta = NULL;
298 u8 seq[6] = {0};
299 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200300 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200301 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100302 u32 iv32;
303 u16 iv16;
304 int err = -ENOENT;
305
Johannes Berg14db74b2008-07-29 13:22:52 +0200306 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307
Johannes Berg3b967662008-04-08 17:56:52 +0200308 rcu_read_lock();
309
Johannes Berg62da92f2007-12-19 02:03:31 +0100310 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100311 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100312 if (!sta)
313 goto out;
314
Max Stepanov354e1592013-12-08 13:30:52 +0200315 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200316 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200317 else if (!pairwise &&
318 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200319 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100320 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200321 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100322
323 if (!key)
324 goto out;
325
326 memset(&params, 0, sizeof(params));
327
Johannes Berg97359d12010-08-10 09:46:38 +0200328 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100329
Johannes Berg97359d12010-08-10 09:46:38 +0200330 switch (key->conf.cipher) {
331 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700332 iv32 = key->u.tkip.tx.iv32;
333 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100334
Johannes Berg24487982009-04-23 18:52:52 +0200335 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
336 drv_get_tkip_seq(sdata->local,
337 key->conf.hw_key_idx,
338 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100339
340 seq[0] = iv16 & 0xff;
341 seq[1] = (iv16 >> 8) & 0xff;
342 seq[2] = iv32 & 0xff;
343 seq[3] = (iv32 >> 8) & 0xff;
344 seq[4] = (iv32 >> 16) & 0xff;
345 seq[5] = (iv32 >> 24) & 0xff;
346 params.seq = seq;
347 params.seq_len = 6;
348 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200349 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200350 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
351 seq[0] = pn64;
352 seq[1] = pn64 >> 8;
353 seq[2] = pn64 >> 16;
354 seq[3] = pn64 >> 24;
355 seq[4] = pn64 >> 32;
356 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100357 params.seq = seq;
358 params.seq_len = 6;
359 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200360 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200361 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
362 seq[0] = pn64;
363 seq[1] = pn64 >> 8;
364 seq[2] = pn64 >> 16;
365 seq[3] = pn64 >> 24;
366 seq[4] = pn64 >> 32;
367 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200368 params.seq = seq;
369 params.seq_len = 6;
370 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100371 }
372
373 params.key = key->conf.key;
374 params.key_len = key->conf.keylen;
375
376 callback(cookie, &params);
377 err = 0;
378
379 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200380 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100381 return err;
382}
383
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100384static int ieee80211_config_default_key(struct wiphy *wiphy,
385 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100386 u8 key_idx, bool uni,
387 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100388{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200389 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100390
Johannes Bergf7e01042010-12-09 19:49:02 +0100391 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100392
393 return 0;
394}
395
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200396static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
397 struct net_device *dev,
398 u8 key_idx)
399{
Johannes Berg66c52422010-07-22 13:58:51 +0200400 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200401
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200402 ieee80211_set_default_mgmt_key(sdata, key_idx);
403
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200404 return 0;
405}
406
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800407void sta_set_rate_info_tx(struct sta_info *sta,
408 const struct ieee80211_tx_rate *rate,
409 struct rate_info *rinfo)
410{
411 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100412 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800413 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100414 rinfo->mcs = rate->idx;
415 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
416 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
417 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
418 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
419 } else {
420 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200421 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
422 u16 brate;
423
Johannes Berg8bc83c22012-11-09 18:38:32 +0100424 sband = sta->local->hw.wiphy->bands[
425 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200426 brate = sband->bitrates[rate->idx].bitrate;
427 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100428 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800429 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
430 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100431 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
432 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
433 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
434 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800435 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
436 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800437}
438
Saravana003e6762012-11-28 18:29:38 +0530439void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
440{
441 rinfo->flags = 0;
442
443 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
444 rinfo->flags |= RATE_INFO_FLAGS_MCS;
445 rinfo->mcs = sta->last_rx_rate_idx;
446 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
447 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
448 rinfo->nss = sta->last_rx_rate_vht_nss;
449 rinfo->mcs = sta->last_rx_rate_idx;
450 } else {
451 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200452 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
453 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530454
455 sband = sta->local->hw.wiphy->bands[
456 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200457 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
458 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530459 }
460
461 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
462 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
463 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
464 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200465 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530466 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200467 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80P80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530468 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200469 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
Saravana003e6762012-11-28 18:29:38 +0530470 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
471}
472
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100473static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200474 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100475{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100476 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300477 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100478 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100479 int ret = -ENOENT;
480
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300481 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100482
Johannes Berg3b53fde82009-11-16 12:00:37 +0100483 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100484 if (sta) {
485 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200486 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100487 sta_set_sinfo(sta, sinfo);
488 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100489
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300490 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100491
Johannes Bergd0709a62008-02-25 16:27:46 +0100492 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100493}
494
Holger Schurig12897232010-04-19 10:23:57 +0200495static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
496 int idx, struct survey_info *survey)
497{
498 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
499
Holger Schurig12897232010-04-19 10:23:57 +0200500 return drv_get_survey(local, idx, survey);
501}
502
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100503static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200504 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100505{
Johannes Bergabe60632009-11-25 17:46:18 +0100506 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300507 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100508 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100509 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100510
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300511 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100512
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100513 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100514 if (sta) {
515 ret = 0;
516 sta_set_sinfo(sta, sinfo);
517 }
518
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300519 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100520
521 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100522}
523
Johannes Berge8c9bd52012-06-06 08:18:22 +0200524static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100525 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200526{
Johannes Berg55de9082012-07-26 17:24:39 +0200527 struct ieee80211_local *local = wiphy_priv(wiphy);
528 struct ieee80211_sub_if_data *sdata;
529 int ret = 0;
530
Johannes Berg4bf88532012-11-09 11:39:59 +0100531 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200532 return 0;
533
Johannes Berg34a37402013-12-18 09:43:33 +0100534 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200535 mutex_lock(&local->iflist_mtx);
536 if (local->use_chanctx) {
537 sdata = rcu_dereference_protected(
538 local->monitor_sdata,
539 lockdep_is_held(&local->iflist_mtx));
540 if (sdata) {
541 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100542 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200543 IEEE80211_CHANCTX_EXCLUSIVE);
544 }
545 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100546 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200547 ieee80211_hw_config(local, 0);
548 }
549
Johannes Berg4bf88532012-11-09 11:39:59 +0100550 if (ret == 0)
551 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200552 mutex_unlock(&local->iflist_mtx);
Johannes Berg34a37402013-12-18 09:43:33 +0100553 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200554
555 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200556}
557
Arik Nemtsov02945822011-11-10 11:28:57 +0200558static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200559 const u8 *resp, size_t resp_len,
560 const struct ieee80211_csa_settings *csa)
Arik Nemtsov02945822011-11-10 11:28:57 +0200561{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300562 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200563
564 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530565 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200566
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100567 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200568
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300569 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200570 if (!new)
571 return -ENOMEM;
572
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300573 new->len = resp_len;
574 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200575
Michal Kazioraf296bd2014-06-05 14:21:36 +0200576 if (csa)
577 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
578 csa->n_counter_offsets_presp *
579 sizeof(new->csa_counter_offsets[0]));
580
Arik Nemtsov02945822011-11-10 11:28:57 +0200581 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300582 if (old)
583 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200584
585 return 0;
586}
587
Luciano Coelho0ae07962013-12-08 09:42:25 +0200588static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200589 struct cfg80211_beacon_data *params,
590 const struct ieee80211_csa_settings *csa)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100591{
592 struct beacon_data *new, *old;
593 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100594 int size, err;
595 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100596
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100597 old = sdata_dereference(sdata->u.ap.beacon, sdata);
598
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100599
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100600 /* Need to have a beacon head if we don't have one yet */
601 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100602 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100603
604 /* new or old head? */
605 if (params->head)
606 new_head_len = params->head_len;
607 else
608 new_head_len = old->head_len;
609
610 /* new or old tail? */
611 if (params->tail || !old)
612 /* params->tail_len will be zero for !params->tail */
613 new_tail_len = params->tail_len;
614 else
615 new_tail_len = old->tail_len;
616
617 size = sizeof(*new) + new_head_len + new_tail_len;
618
619 new = kzalloc(size, GFP_KERNEL);
620 if (!new)
621 return -ENOMEM;
622
623 /* start filling the new info now */
624
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100625 /*
626 * pointers go into the block we allocated,
627 * memory is | beacon_data | head | tail |
628 */
629 new->head = ((u8 *) new) + sizeof(*new);
630 new->tail = new->head + new_head_len;
631 new->head_len = new_head_len;
632 new->tail_len = new_tail_len;
633
Michal Kazioraf296bd2014-06-05 14:21:36 +0200634 if (csa) {
635 new->csa_current_counter = csa->count;
636 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
637 csa->n_counter_offsets_beacon *
638 sizeof(new->csa_counter_offsets[0]));
639 }
640
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100641 /* copy in head */
642 if (params->head)
643 memcpy(new->head, params->head, new_head_len);
644 else
645 memcpy(new->head, old->head, new_head_len);
646
647 /* copy in optional tail */
648 if (params->tail)
649 memcpy(new->tail, params->tail, new_tail_len);
650 else
651 if (old)
652 memcpy(new->tail, old->tail, new_tail_len);
653
Johannes Berg88600202012-02-13 15:17:18 +0100654 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200655 params->probe_resp_len, csa);
Johannes Berg88600202012-02-13 15:17:18 +0100656 if (err < 0)
657 return err;
658 if (err == 0)
659 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100660
Eric Dumazetcf778b02012-01-12 04:41:32 +0000661 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100662
Johannes Berg88600202012-02-13 15:17:18 +0100663 if (old)
664 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100665
Johannes Berg88600202012-02-13 15:17:18 +0100666 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100667}
668
Johannes Berg88600202012-02-13 15:17:18 +0100669static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
670 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100671{
Johannes Berg88600202012-02-13 15:17:18 +0100672 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100673 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100674 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100675 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100676 u32 changed = BSS_CHANGED_BEACON_INT |
677 BSS_CHANGED_BEACON_ENABLED |
678 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100679 BSS_CHANGED_SSID |
680 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100681 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200682
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100683 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100684 if (old)
685 return -EALREADY;
686
Eliad Pellerf6993172014-09-10 14:07:35 +0300687 switch (params->smps_mode) {
688 case NL80211_SMPS_OFF:
689 sdata->smps_mode = IEEE80211_SMPS_OFF;
690 break;
691 case NL80211_SMPS_STATIC:
692 sdata->smps_mode = IEEE80211_SMPS_STATIC;
693 break;
694 case NL80211_SMPS_DYNAMIC:
695 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
696 break;
697 default:
698 return -EINVAL;
699 }
Johannes Berg04ecd252012-09-11 14:34:12 +0200700 sdata->needed_rx_chains = sdata->local->rx_chains;
701
Johannes Berg34a37402013-12-18 09:43:33 +0100702 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100703 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200704 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100705 if (!err)
706 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100707 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200708 if (err)
709 return err;
710
Johannes Berg665c93a2011-11-04 11:18:11 +0100711 /*
712 * Apply control port protocol, this allows us to
713 * not encrypt dynamic WEP control frames.
714 */
715 sdata->control_port_protocol = params->crypto.control_port_ethertype;
716 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200717 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
718 &params->crypto,
719 sdata->vif.type);
720
Johannes Berg665c93a2011-11-04 11:18:11 +0100721 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
722 vlan->control_port_protocol =
723 params->crypto.control_port_ethertype;
724 vlan->control_port_no_encrypt =
725 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200726 vlan->encrypt_headroom =
727 ieee80211_cs_headroom(sdata->local,
728 &params->crypto,
729 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +0100730 }
731
Johannes Berg88600202012-02-13 15:17:18 +0100732 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
733 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100734 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100735
736 sdata->vif.bss_conf.ssid_len = params->ssid_len;
737 if (params->ssid_len)
738 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
739 params->ssid_len);
740 sdata->vif.bss_conf.hidden_ssid =
741 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
742
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100743 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
744 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
745 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
746 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
747 if (params->p2p_opp_ps)
748 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
749 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100750
Michal Kazioraf296bd2014-06-05 14:21:36 +0200751 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200752 if (err < 0) {
753 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100754 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200755 }
Johannes Berg88600202012-02-13 15:17:18 +0100756 changed |= err;
757
Johannes Berg10416382012-10-19 15:44:42 +0200758 err = drv_start_ap(sdata->local, sdata);
759 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100760 old = sdata_dereference(sdata->u.ap.beacon, sdata);
761
Johannes Berg10416382012-10-19 15:44:42 +0200762 if (old)
763 kfree_rcu(old, rcu_head);
764 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200765 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +0200766 return err;
767 }
768
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800769 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100770 ieee80211_bss_info_change_notify(sdata, changed);
771
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200772 netif_carrier_on(dev);
773 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
774 netif_carrier_on(vlan->dev);
775
Johannes Berg665c93a2011-11-04 11:18:11 +0100776 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100777}
778
Johannes Berg88600202012-02-13 15:17:18 +0100779static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
780 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100781{
Johannes Berg14db74b2008-07-29 13:22:52 +0200782 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100783 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100784 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100785
Johannes Berg14db74b2008-07-29 13:22:52 +0200786 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +0100787 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +0200788
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200789 /* don't allow changing the beacon while CSA is in place - offset
790 * of channel switch counter may change
791 */
792 if (sdata->vif.csa_active)
793 return -EBUSY;
794
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100795 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100796 if (!old)
797 return -ENOENT;
798
Michal Kazioraf296bd2014-06-05 14:21:36 +0200799 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100800 if (err < 0)
801 return err;
802 ieee80211_bss_info_change_notify(sdata, err);
803 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100804}
805
Johannes Berg88600202012-02-13 15:17:18 +0100806static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100807{
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200808 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
809 struct ieee80211_sub_if_data *vlan;
810 struct ieee80211_local *local = sdata->local;
811 struct beacon_data *old_beacon;
812 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100813 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100814
Michal Kaziordbd72852014-01-29 07:56:21 +0100815 sdata_assert_lock(sdata);
816
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100817 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200818 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100819 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100820 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100821
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200822 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +0200823 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200824 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +0300825 if (sdata->csa_block_tx) {
826 ieee80211_wake_vif_queues(local, sdata,
827 IEEE80211_QUEUE_STOP_REASON_CSA);
828 sdata->csa_block_tx = false;
829 }
830
Michal Kazior59af6922014-04-09 15:10:59 +0200831 mutex_unlock(&local->mtx);
832
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +0100833 kfree(sdata->u.ap.next_beacon);
834 sdata->u.ap.next_beacon = NULL;
835
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200836 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200837 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
838 netif_carrier_off(vlan->dev);
839 netif_carrier_off(dev);
840
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200841 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000842 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200843 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
844 kfree_rcu(old_beacon, rcu_head);
845 if (old_probe_resp)
846 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +0200847 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +0100848
Johannes Berge7162512013-12-04 23:18:37 +0100849 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +0100850 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +0100851
Johannes Bergd6a83222012-12-14 14:06:28 +0100852 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +0200853 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +0100854 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200855 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100856
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200857 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100858 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200859 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100860 cfg80211_cac_event(sdata->dev, &chandef,
861 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200862 GFP_KERNEL);
863 }
864
Johannes Berg10416382012-10-19 15:44:42 +0200865 drv_stop_ap(sdata->local, sdata);
866
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200867 /* free all potentially still buffered bcast frames */
868 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
869 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
870
Johannes Berg34a37402013-12-18 09:43:33 +0100871 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +0100872 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +0200873 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +0100874 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200875
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200876 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100877}
878
Johannes Berg4fd69312007-12-19 02:03:35 +0100879/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
880struct iapp_layer2_update {
881 u8 da[ETH_ALEN]; /* broadcast */
882 u8 sa[ETH_ALEN]; /* STA addr */
883 __be16 len; /* 6 */
884 u8 dsap; /* 0 */
885 u8 ssap; /* 0 */
886 u8 control;
887 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700888} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100889
890static void ieee80211_send_layer2_update(struct sta_info *sta)
891{
892 struct iapp_layer2_update *msg;
893 struct sk_buff *skb;
894
895 /* Send Level 2 Update Frame to update forwarding tables in layer 2
896 * bridge devices */
897
898 skb = dev_alloc_skb(sizeof(*msg));
899 if (!skb)
900 return;
901 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
902
903 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
904 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
905
Johannes Berge83e6542012-07-13 16:23:07 +0200906 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200907 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100908 msg->len = htons(6);
909 msg->dsap = 0;
910 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
911 msg->control = 0xaf; /* XID response lsb.1111F101.
912 * F=0 (no poll command; unsolicited frame) */
913 msg->xid_info[0] = 0x81; /* XID format identifier */
914 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
915 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
916
Johannes Bergd0709a62008-02-25 16:27:46 +0100917 skb->dev = sta->sdata->dev;
918 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100919 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400920 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100921}
922
Johannes Bergd582cff2012-10-26 17:53:44 +0200923static int sta_apply_auth_flags(struct ieee80211_local *local,
924 struct sta_info *sta,
925 u32 mask, u32 set)
926{
927 int ret;
928
929 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
930 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
931 !test_sta_flag(sta, WLAN_STA_AUTH)) {
932 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
933 if (ret)
934 return ret;
935 }
936
937 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
938 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
939 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
940 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
941 if (ret)
942 return ret;
943 }
944
945 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
946 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
947 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
948 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
949 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
950 else
951 ret = 0;
952 if (ret)
953 return ret;
954 }
955
956 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
957 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
958 test_sta_flag(sta, WLAN_STA_ASSOC)) {
959 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
960 if (ret)
961 return ret;
962 }
963
964 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
965 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
966 test_sta_flag(sta, WLAN_STA_AUTH)) {
967 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
968 if (ret)
969 return ret;
970 }
971
972 return 0;
973}
974
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100975static int sta_apply_parameters(struct ieee80211_local *local,
976 struct sta_info *sta,
977 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100978{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100979 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100980 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100981 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +0200982 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300983 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100984
Johannes Berg55de9082012-07-26 17:24:39 +0200985 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +0200986
Johannes Bergeccb8e82009-05-11 21:57:56 +0300987 mask = params->sta_flags_mask;
988 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100989
Johannes Bergd582cff2012-10-26 17:53:44 +0200990 if (ieee80211_vif_is_mesh(&sdata->vif)) {
991 /*
992 * In mesh mode, ASSOCIATED isn't part of the nl80211
993 * API but must follow AUTHENTICATED for driver state.
994 */
995 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
996 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
997 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
998 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +0100999 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1000 /*
1001 * TDLS -- everything follows authorized, but
1002 * only becoming authorized is possible, not
1003 * going back
1004 */
1005 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1006 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1007 BIT(NL80211_STA_FLAG_ASSOCIATED);
1008 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1009 BIT(NL80211_STA_FLAG_ASSOCIATED);
1010 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001011 }
1012
Arik Nemtsov68885a52014-06-11 17:18:19 +03001013 /* auth flags will be set later for TDLS stations */
1014 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1015 ret = sta_apply_auth_flags(local, sta, mask, set);
1016 if (ret)
1017 return ret;
1018 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001019
Johannes Bergeccb8e82009-05-11 21:57:56 +03001020 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001021 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001022 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1023 else
1024 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001025 }
1026
Johannes Berga74a8c82014-07-22 14:50:47 +02001027 if (mask & BIT(NL80211_STA_FLAG_WME))
1028 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001029
1030 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001031 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001032 set_sta_flag(sta, WLAN_STA_MFP);
1033 else
1034 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001035 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001036
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001037 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001038 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001039 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1040 else
1041 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001042 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001043
Johannes Berg3b9ce802011-09-27 20:56:12 +02001044 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1045 sta->sta.uapsd_queues = params->uapsd_queues;
1046 sta->sta.max_sp = params->max_sp;
1047 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001048
Johannes Berg73651ee2008-02-25 16:27:47 +01001049 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001050 * cfg80211 validates this (1-2007) and allows setting the AID
1051 * only when creating a new station entry
1052 */
1053 if (params->aid)
1054 sta->sta.aid = params->aid;
1055
1056 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001057 * Some of the following updates would be racy if called on an
1058 * existing station, via ieee80211_change_station(). However,
1059 * all such changes are rejected by cfg80211 except for updates
1060 * changing the supported rates on an existing but not yet used
1061 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001062 */
1063
Johannes Berg4fd69312007-12-19 02:03:35 +01001064 if (params->listen_interval >= 0)
1065 sta->listen_interval = params->listen_interval;
1066
1067 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001068 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1069 sband, params->supported_rates,
1070 params->supported_rates_len,
1071 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001072 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001073
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001074 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001075 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001076 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001077
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001078 if (params->vht_capa)
1079 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001080 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001081
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001082 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001083 /* returned value is only needed for rc update, but the
1084 * rc isn't initialized here yet, so ignore it
1085 */
1086 __ieee80211_vht_handle_opmode(sdata, sta,
1087 params->opmode_notif,
1088 band, false);
1089 }
1090
Javier Cardona9c3990a2011-05-03 16:57:11 -07001091 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001092#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001093 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001094
1095 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001096 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001097 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001098 if (sta->plink_state != NL80211_PLINK_ESTAB)
1099 changed = mesh_plink_inc_estab_count(
1100 sdata);
1101 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001102
1103 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001104 changed |= ieee80211_mps_set_sta_local_pm(sta,
1105 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001106 break;
1107 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001108 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001109 case NL80211_PLINK_OPN_SNT:
1110 case NL80211_PLINK_OPN_RCVD:
1111 case NL80211_PLINK_CNF_RCVD:
1112 case NL80211_PLINK_HOLDING:
1113 if (sta->plink_state == NL80211_PLINK_ESTAB)
1114 changed = mesh_plink_dec_estab_count(
1115 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001116 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001117
1118 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001119 changed |= ieee80211_mps_set_sta_local_pm(sta,
1120 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001121 break;
1122 default:
1123 /* nothing */
1124 break;
1125 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001126 }
1127
1128 switch (params->plink_action) {
1129 case NL80211_PLINK_ACTION_NO_ACTION:
1130 /* nothing */
1131 break;
1132 case NL80211_PLINK_ACTION_OPEN:
1133 changed |= mesh_plink_open(sta);
1134 break;
1135 case NL80211_PLINK_ACTION_BLOCK:
1136 changed |= mesh_plink_block(sta);
1137 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001138 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001139
1140 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001141 changed |=
1142 ieee80211_mps_set_sta_local_pm(sta,
1143 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001144 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001145#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001146 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001147
Arik Nemtsov68885a52014-06-11 17:18:19 +03001148 /* set the STA state after all sta info from usermode has been set */
1149 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1150 ret = sta_apply_auth_flags(local, sta, mask, set);
1151 if (ret)
1152 return ret;
1153 }
1154
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001155 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001156}
1157
1158static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001159 const u8 *mac,
1160 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001161{
Johannes Berg14db74b2008-07-29 13:22:52 +02001162 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001163 struct sta_info *sta;
1164 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001165 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001166 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001167
Johannes Berg4fd69312007-12-19 02:03:35 +01001168 if (params->vlan) {
1169 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1170
Johannes Berg05c914f2008-09-11 00:01:58 +02001171 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1172 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001173 return -EINVAL;
1174 } else
1175 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1176
Joe Perchesb203ca32012-05-08 18:56:52 +00001177 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001178 return -EINVAL;
1179
1180 if (is_multicast_ether_addr(mac))
1181 return -EINVAL;
1182
1183 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001184 if (!sta)
1185 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001186
Johannes Bergd582cff2012-10-26 17:53:44 +02001187 /*
1188 * defaults -- if userspace wants something else we'll
1189 * change it accordingly in sta_apply_parameters()
1190 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001191 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1192 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1193 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001194 } else {
1195 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001196 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001197
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001198 err = sta_apply_parameters(local, sta, params);
1199 if (err) {
1200 sta_info_free(local, sta);
1201 return err;
1202 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001203
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001204 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001205 * for TDLS, rate control should be initialized only when
1206 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001207 */
1208 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1209 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001210
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001211 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1212 sdata->vif.type == NL80211_IFTYPE_AP;
1213
Johannes Berg34e89502010-02-03 13:59:58 +01001214 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001215 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001216 rcu_read_unlock();
1217 return err;
1218 }
1219
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001220 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001221 ieee80211_send_layer2_update(sta);
1222
1223 rcu_read_unlock();
1224
Johannes Berg4fd69312007-12-19 02:03:35 +01001225 return 0;
1226}
1227
1228static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Jouni Malinen89c771e2014-10-10 20:52:40 +03001229 struct station_del_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001230{
Johannes Berg14db74b2008-07-29 13:22:52 +02001231 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001232
Johannes Berg14db74b2008-07-29 13:22:52 +02001233 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1234
Jouni Malinen89c771e2014-10-10 20:52:40 +03001235 if (params->mac)
1236 return sta_info_destroy_addr_bss(sdata, params->mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001237
Johannes Bergb998e8b2012-12-13 23:07:46 +01001238 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001239 return 0;
1240}
1241
1242static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001243 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001244 struct station_parameters *params)
1245{
Johannes Bergabe60632009-11-25 17:46:18 +01001246 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001247 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001248 struct sta_info *sta;
1249 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001250 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001251 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001252
Johannes Berg87be1e12011-12-14 12:20:29 +01001253 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001254
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001255 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001256 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001257 err = -ENOENT;
1258 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001259 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001260
Johannes Berg77ee7c82013-02-15 00:48:33 +01001261 switch (sdata->vif.type) {
1262 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001263 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001264 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001265 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001266 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001267 break;
1268 case NL80211_IFTYPE_ADHOC:
1269 statype = CFG80211_STA_IBSS;
1270 break;
1271 case NL80211_IFTYPE_STATION:
1272 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1273 statype = CFG80211_STA_AP_STA;
1274 break;
1275 }
1276 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1277 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1278 else
1279 statype = CFG80211_STA_TDLS_PEER_SETUP;
1280 break;
1281 case NL80211_IFTYPE_AP:
1282 case NL80211_IFTYPE_AP_VLAN:
1283 statype = CFG80211_STA_AP_CLIENT;
1284 break;
1285 default:
1286 err = -EOPNOTSUPP;
1287 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001288 }
1289
Johannes Berg77ee7c82013-02-15 00:48:33 +01001290 err = cfg80211_check_station_change(wiphy, params, statype);
1291 if (err)
1292 goto out_err;
1293
Johannes Bergd0709a62008-02-25 16:27:46 +01001294 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001295 bool prev_4addr = false;
1296 bool new_4addr = false;
1297
Johannes Berg4fd69312007-12-19 02:03:35 +01001298 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1299
Johannes Berg9bc383d2009-11-19 11:55:19 +01001300 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001301 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001302 err = -EBUSY;
1303 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001304 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001305
Eric Dumazetcf778b02012-01-12 04:41:32 +00001306 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001307 new_4addr = true;
1308 }
1309
1310 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1311 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301312 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001313 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001314 }
1315
Johannes Berg14db74b2008-07-29 13:22:52 +02001316 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001317
1318 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1319 prev_4addr != new_4addr) {
1320 if (new_4addr)
1321 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1322 else
1323 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1324 }
1325
Johannes Berg4fd69312007-12-19 02:03:35 +01001326 ieee80211_send_layer2_update(sta);
1327 }
1328
Eliad Peller35b88622011-12-29 14:41:39 +02001329 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001330 if (err)
1331 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001332
Johannes Berg77ee7c82013-02-15 00:48:33 +01001333 /* When peer becomes authorized, init rate control as well */
1334 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1335 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001336 rate_control_rate_init(sta);
1337
Johannes Berg87be1e12011-12-14 12:20:29 +01001338 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001339
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001340 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1341 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1342 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1343 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1344 sta_info_tx_streams(sta) != 1) {
1345 ht_dbg(sta->sdata,
1346 "%pM just authorized and MIMO capable - update SMPS\n",
1347 sta->sta.addr);
1348 ieee80211_send_smps_action(sta->sdata,
1349 sta->sdata->bss->req_smps,
1350 sta->sta.addr,
1351 sta->sdata->vif.bss_conf.bssid);
1352 }
1353
Jason Young808118c2011-03-10 16:43:19 -08001354 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001355 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001356 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001357 ieee80211_recalc_ps_vif(sdata);
1358 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001359
Johannes Berg4fd69312007-12-19 02:03:35 +01001360 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001361out_err:
1362 mutex_unlock(&local->sta_mtx);
1363 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001364}
1365
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001366#ifdef CONFIG_MAC80211_MESH
1367static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001368 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001369{
Johannes Berg14db74b2008-07-29 13:22:52 +02001370 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001371 struct mesh_path *mpath;
1372 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001373
Johannes Berg14db74b2008-07-29 13:22:52 +02001374 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1375
Johannes Bergd0709a62008-02-25 16:27:46 +01001376 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001377 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001378 if (!sta) {
1379 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001380 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001381 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001382
Bob Copelandae76eef2013-03-29 09:38:39 -04001383 mpath = mesh_path_add(sdata, dst);
1384 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001385 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001386 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001387 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001388
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001389 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001390
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001391 rcu_read_unlock();
1392 return 0;
1393}
1394
1395static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001396 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001397{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001398 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001399
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001400 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001401 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001402
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001403 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001404 return 0;
1405}
1406
Johannes Berg3b3a0162014-05-19 17:19:31 +02001407static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1408 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001409{
Johannes Berg14db74b2008-07-29 13:22:52 +02001410 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001411 struct mesh_path *mpath;
1412 struct sta_info *sta;
1413
Johannes Berg14db74b2008-07-29 13:22:52 +02001414 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1415
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001416 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001417
Johannes Bergabe60632009-11-25 17:46:18 +01001418 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001419 if (!sta) {
1420 rcu_read_unlock();
1421 return -ENOENT;
1422 }
1423
Johannes Bergbf7cd942013-02-15 14:40:31 +01001424 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001425 if (!mpath) {
1426 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001427 return -ENOENT;
1428 }
1429
1430 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001431
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001432 rcu_read_unlock();
1433 return 0;
1434}
1435
1436static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1437 struct mpath_info *pinfo)
1438{
Johannes Berga3836e02011-05-12 15:11:37 +02001439 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1440
1441 if (next_hop_sta)
1442 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001443 else
1444 memset(next_hop, 0, ETH_ALEN);
1445
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001446 memset(pinfo, 0, sizeof(*pinfo));
1447
Johannes Bergf5ea9122009-08-07 16:17:38 +02001448 pinfo->generation = mesh_paths_generation;
1449
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001450 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001451 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001452 MPATH_INFO_METRIC |
1453 MPATH_INFO_EXPTIME |
1454 MPATH_INFO_DISCOVERY_TIMEOUT |
1455 MPATH_INFO_DISCOVERY_RETRIES |
1456 MPATH_INFO_FLAGS;
1457
1458 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001459 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001460 pinfo->metric = mpath->metric;
1461 if (time_before(jiffies, mpath->exp_time))
1462 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1463 pinfo->discovery_timeout =
1464 jiffies_to_msecs(mpath->discovery_timeout);
1465 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001466 if (mpath->flags & MESH_PATH_ACTIVE)
1467 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1468 if (mpath->flags & MESH_PATH_RESOLVING)
1469 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001470 if (mpath->flags & MESH_PATH_SN_VALID)
1471 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001472 if (mpath->flags & MESH_PATH_FIXED)
1473 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001474 if (mpath->flags & MESH_PATH_RESOLVED)
1475 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001476}
1477
1478static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1479 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1480
1481{
Johannes Berg14db74b2008-07-29 13:22:52 +02001482 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001483 struct mesh_path *mpath;
1484
Johannes Berg14db74b2008-07-29 13:22:52 +02001485 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1486
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001487 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001488 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001489 if (!mpath) {
1490 rcu_read_unlock();
1491 return -ENOENT;
1492 }
1493 memcpy(dst, mpath->dst, ETH_ALEN);
1494 mpath_set_pinfo(mpath, next_hop, pinfo);
1495 rcu_read_unlock();
1496 return 0;
1497}
1498
1499static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001500 int idx, u8 *dst, u8 *next_hop,
1501 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001502{
Johannes Berg14db74b2008-07-29 13:22:52 +02001503 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001504 struct mesh_path *mpath;
1505
Johannes Berg14db74b2008-07-29 13:22:52 +02001506 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1507
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001508 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001509 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001510 if (!mpath) {
1511 rcu_read_unlock();
1512 return -ENOENT;
1513 }
1514 memcpy(dst, mpath->dst, ETH_ALEN);
1515 mpath_set_pinfo(mpath, next_hop, pinfo);
1516 rcu_read_unlock();
1517 return 0;
1518}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001519
Henning Roggea2db2ed2014-09-12 08:58:50 +02001520static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1521 struct mpath_info *pinfo)
1522{
1523 memset(pinfo, 0, sizeof(*pinfo));
1524 memcpy(mpp, mpath->mpp, ETH_ALEN);
1525
1526 pinfo->generation = mpp_paths_generation;
1527}
1528
1529static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1530 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1531
1532{
1533 struct ieee80211_sub_if_data *sdata;
1534 struct mesh_path *mpath;
1535
1536 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1537
1538 rcu_read_lock();
1539 mpath = mpp_path_lookup(sdata, dst);
1540 if (!mpath) {
1541 rcu_read_unlock();
1542 return -ENOENT;
1543 }
1544 memcpy(dst, mpath->dst, ETH_ALEN);
1545 mpp_set_pinfo(mpath, mpp, pinfo);
1546 rcu_read_unlock();
1547 return 0;
1548}
1549
1550static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1551 int idx, u8 *dst, u8 *mpp,
1552 struct mpath_info *pinfo)
1553{
1554 struct ieee80211_sub_if_data *sdata;
1555 struct mesh_path *mpath;
1556
1557 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1558
1559 rcu_read_lock();
1560 mpath = mpp_path_lookup_by_idx(sdata, idx);
1561 if (!mpath) {
1562 rcu_read_unlock();
1563 return -ENOENT;
1564 }
1565 memcpy(dst, mpath->dst, ETH_ALEN);
1566 mpp_set_pinfo(mpath, mpp, pinfo);
1567 rcu_read_unlock();
1568 return 0;
1569}
1570
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001571static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001572 struct net_device *dev,
1573 struct mesh_config *conf)
1574{
1575 struct ieee80211_sub_if_data *sdata;
1576 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1577
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001578 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1579 return 0;
1580}
1581
1582static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1583{
1584 return (mask >> (parm-1)) & 0x1;
1585}
1586
Javier Cardonac80d5452010-12-16 17:37:49 -08001587static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1588 const struct mesh_setup *setup)
1589{
1590 u8 *new_ie;
1591 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001592 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1593 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001594
Javier Cardona581a8b02011-04-07 15:08:27 -07001595 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001596 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001597 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001598
Javier Cardona581a8b02011-04-07 15:08:27 -07001599 if (setup->ie_len) {
1600 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001601 GFP_KERNEL);
1602 if (!new_ie)
1603 return -ENOMEM;
1604 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001605 ifmsh->ie_len = setup->ie_len;
1606 ifmsh->ie = new_ie;
1607 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001608
1609 /* now copy the rest of the setup parameters */
1610 ifmsh->mesh_id_len = setup->mesh_id_len;
1611 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001612 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001613 ifmsh->mesh_pp_id = setup->path_sel_proto;
1614 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001615 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001616 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001617 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1618 if (setup->is_authenticated)
1619 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1620 if (setup->is_secure)
1621 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001622
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001623 /* mcast rate setting in Mesh Node */
1624 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1625 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001626 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001627
Marco Porsch9bdbf042013-01-07 16:04:51 +01001628 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1629 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1630
Javier Cardonac80d5452010-12-16 17:37:49 -08001631 return 0;
1632}
1633
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001634static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001635 struct net_device *dev, u32 mask,
1636 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001637{
1638 struct mesh_config *conf;
1639 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001640 struct ieee80211_if_mesh *ifmsh;
1641
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001642 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001643 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001644
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001645 /* Set the config options which we are interested in setting */
1646 conf = &(sdata->u.mesh.mshcfg);
1647 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1648 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1649 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1650 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1651 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1652 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1653 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1654 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1655 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1656 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1657 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1658 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001659 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001660 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001661 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1662 if (ifmsh->user_mpm)
1663 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001664 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001665 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001666 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1667 conf->dot11MeshNbrOffsetMaxNeighbor =
1668 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001669 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1670 conf->dot11MeshHWMPmaxPREQretries =
1671 nconf->dot11MeshHWMPmaxPREQretries;
1672 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1673 conf->path_refresh_time = nconf->path_refresh_time;
1674 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1675 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1676 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1677 conf->dot11MeshHWMPactivePathTimeout =
1678 nconf->dot11MeshHWMPactivePathTimeout;
1679 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1680 conf->dot11MeshHWMPpreqMinInterval =
1681 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001682 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1683 conf->dot11MeshHWMPperrMinInterval =
1684 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001685 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1686 mask))
1687 conf->dot11MeshHWMPnetDiameterTraversalTime =
1688 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001689 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1690 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1691 ieee80211_mesh_root_setup(ifmsh);
1692 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001693 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001694 /* our current gate announcement implementation rides on root
1695 * announcements, so require this ifmsh to also be a root node
1696 * */
1697 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001698 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1699 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001700 ieee80211_mesh_root_setup(ifmsh);
1701 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001702 conf->dot11MeshGateAnnouncementProtocol =
1703 nconf->dot11MeshGateAnnouncementProtocol;
1704 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001705 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001706 conf->dot11MeshHWMPRannInterval =
1707 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001708 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1709 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001710 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1711 /* our RSSI threshold implementation is supported only for
1712 * devices that report signal in dBm.
1713 */
1714 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1715 return -ENOTSUPP;
1716 conf->rssi_threshold = nconf->rssi_threshold;
1717 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001718 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1719 conf->ht_opmode = nconf->ht_opmode;
1720 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1721 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1722 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001723 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1724 conf->dot11MeshHWMPactivePathToRootTimeout =
1725 nconf->dot11MeshHWMPactivePathToRootTimeout;
1726 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1727 conf->dot11MeshHWMProotInterval =
1728 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001729 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1730 conf->dot11MeshHWMPconfirmationInterval =
1731 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001732 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1733 conf->power_mode = nconf->power_mode;
1734 ieee80211_mps_local_status_update(sdata);
1735 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001736 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001737 conf->dot11MeshAwakeWindowDuration =
1738 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001739 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1740 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001741 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001742 return 0;
1743}
1744
Johannes Berg29cbe682010-12-03 09:20:44 +01001745static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1746 const struct mesh_config *conf,
1747 const struct mesh_setup *setup)
1748{
1749 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1750 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001751 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001752
Javier Cardonac80d5452010-12-16 17:37:49 -08001753 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1754 err = copy_mesh_setup(ifmsh, setup);
1755 if (err)
1756 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001757
Johannes Berg04ecd252012-09-11 14:34:12 +02001758 /* can mesh use other SMPS modes? */
1759 sdata->smps_mode = IEEE80211_SMPS_OFF;
1760 sdata->needed_rx_chains = sdata->local->rx_chains;
1761
Johannes Berg34a37402013-12-18 09:43:33 +01001762 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001763 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001764 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01001765 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001766 if (err)
1767 return err;
1768
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001769 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001770}
1771
1772static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1773{
1774 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1775
1776 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001777 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001778 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001779 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01001780
1781 return 0;
1782}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001783#endif
1784
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001785static int ieee80211_change_bss(struct wiphy *wiphy,
1786 struct net_device *dev,
1787 struct bss_parameters *params)
1788{
Johannes Berg55de9082012-07-26 17:24:39 +02001789 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1790 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001791 u32 changed = 0;
1792
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001793 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02001794 return -ENOENT;
1795
1796 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001797
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001798 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001799 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001800 changed |= BSS_CHANGED_ERP_CTS_PROT;
1801 }
1802 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001803 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001804 params->use_short_preamble;
1805 changed |= BSS_CHANGED_ERP_PREAMBLE;
1806 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001807
1808 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001809 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001810 sdata->vif.bss_conf.use_short_slot = true;
1811 changed |= BSS_CHANGED_ERP_SLOT;
1812 }
1813
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001814 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001815 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001816 params->use_short_slot_time;
1817 changed |= BSS_CHANGED_ERP_SLOT;
1818 }
1819
Jouni Malinen90c97a02008-10-30 16:59:22 +02001820 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001821 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1822 wiphy->bands[band],
1823 params->basic_rates,
1824 params->basic_rates_len,
1825 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001826 changed |= BSS_CHANGED_BASIC_RATES;
1827 }
1828
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001829 if (params->ap_isolate >= 0) {
1830 if (params->ap_isolate)
1831 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1832 else
1833 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1834 }
1835
Helmut Schaa80d7e402010-11-19 12:40:26 +01001836 if (params->ht_opmode >= 0) {
1837 sdata->vif.bss_conf.ht_operation_mode =
1838 (u16) params->ht_opmode;
1839 changed |= BSS_CHANGED_HT;
1840 }
1841
Johannes Berg339afbf2012-11-14 15:21:17 +01001842 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001843 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1844 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1845 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1846 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001847 changed |= BSS_CHANGED_P2P_PS;
1848 }
1849
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001850 if (params->p2p_opp_ps > 0) {
1851 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1852 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1853 changed |= BSS_CHANGED_P2P_PS;
1854 } else if (params->p2p_opp_ps == 0) {
1855 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1856 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001857 changed |= BSS_CHANGED_P2P_PS;
1858 }
1859
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001860 ieee80211_bss_info_change_notify(sdata, changed);
1861
1862 return 0;
1863}
1864
Jouni Malinen31888482008-10-30 16:59:24 +02001865static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001866 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001867 struct ieee80211_txq_params *params)
1868{
1869 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001870 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001871 struct ieee80211_tx_queue_params p;
1872
1873 if (!local->ops->conf_tx)
1874 return -EOPNOTSUPP;
1875
Johannes Berg54bcbc62012-03-28 11:04:25 +02001876 if (local->hw.queues < IEEE80211_NUM_ACS)
1877 return -EOPNOTSUPP;
1878
Jouni Malinen31888482008-10-30 16:59:24 +02001879 memset(&p, 0, sizeof(p));
1880 p.aifs = params->aifs;
1881 p.cw_max = params->cwmax;
1882 p.cw_min = params->cwmin;
1883 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001884
1885 /*
1886 * Setting tx queue params disables u-apsd because it's only
1887 * called in master mode.
1888 */
1889 p.uapsd = false;
1890
Johannes Berga3304b02012-03-28 11:04:24 +02001891 sdata->tx_conf[params->ac] = p;
1892 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001893 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001894 "failed to set TX queue parameters for AC %d\n",
1895 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001896 return -EINVAL;
1897 }
1898
Johannes Berg7d257452012-07-06 17:37:43 +02001899 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1900
Jouni Malinen31888482008-10-30 16:59:24 +02001901 return 0;
1902}
1903
Bob Copeland665af4f2009-01-19 11:20:53 -05001904#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001905static int ieee80211_suspend(struct wiphy *wiphy,
1906 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001907{
Johannes Bergeecc4802011-05-04 15:37:29 +02001908 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001909}
1910
1911static int ieee80211_resume(struct wiphy *wiphy)
1912{
1913 return __ieee80211_resume(wiphy_priv(wiphy));
1914}
1915#else
1916#define ieee80211_suspend NULL
1917#define ieee80211_resume NULL
1918#endif
1919
Johannes Berg2a519312009-02-10 21:25:55 +01001920static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001921 struct cfg80211_scan_request *req)
1922{
Johannes Bergfd014282012-06-18 19:17:03 +02001923 struct ieee80211_sub_if_data *sdata;
1924
1925 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001926
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001927 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1928 case NL80211_IFTYPE_STATION:
1929 case NL80211_IFTYPE_ADHOC:
1930 case NL80211_IFTYPE_MESH_POINT:
1931 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001932 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001933 break;
1934 case NL80211_IFTYPE_P2P_GO:
1935 if (sdata->local->ops->hw_scan)
1936 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001937 /*
1938 * FIXME: implement NoA while scanning in software,
1939 * for now fall through to allow scanning only when
1940 * beaconing hasn't been configured yet
1941 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001942 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02001943 /*
1944 * If the scan has been forced (and the driver supports
1945 * forcing), don't care about being beaconing already.
1946 * This will create problems to the attached stations (e.g. all
1947 * the frames sent while scanning on other channel will be
1948 * lost)
1949 */
1950 if (sdata->u.ap.beacon &&
1951 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1952 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001953 return -EOPNOTSUPP;
1954 break;
1955 default:
1956 return -EOPNOTSUPP;
1957 }
Johannes Berg2a519312009-02-10 21:25:55 +01001958
1959 return ieee80211_request_scan(sdata, req);
1960}
1961
Luciano Coelho79f460c2011-05-11 17:09:36 +03001962static int
1963ieee80211_sched_scan_start(struct wiphy *wiphy,
1964 struct net_device *dev,
1965 struct cfg80211_sched_scan_request *req)
1966{
1967 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1968
1969 if (!sdata->local->ops->sched_scan_start)
1970 return -EOPNOTSUPP;
1971
1972 return ieee80211_request_sched_scan_start(sdata, req);
1973}
1974
1975static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001976ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001977{
1978 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1979
1980 if (!sdata->local->ops->sched_scan_stop)
1981 return -EOPNOTSUPP;
1982
Luciano Coelho85a99942011-05-12 16:28:29 +03001983 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001984}
1985
Jouni Malinen636a5d32009-03-19 13:39:22 +02001986static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1987 struct cfg80211_auth_request *req)
1988{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001989 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001990}
1991
1992static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1993 struct cfg80211_assoc_request *req)
1994{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001995 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001996}
1997
1998static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001999 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002000{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002001 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002002}
2003
2004static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002005 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002006{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002007 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002008}
2009
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002010static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2011 struct cfg80211_ibss_params *params)
2012{
Johannes Berg55de9082012-07-26 17:24:39 +02002013 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002014}
2015
2016static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2017{
Johannes Berg55de9082012-07-26 17:24:39 +02002018 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002019}
2020
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002021static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2022 int rate[IEEE80211_NUM_BANDS])
2023{
2024 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2025
Cong Ding9887dbf2013-02-06 17:23:45 +01002026 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2027 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002028
2029 return 0;
2030}
2031
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002032static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2033{
2034 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002035 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002036
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002037 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2038 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2039
2040 if (err)
2041 return err;
2042 }
2043
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002044 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2045 (changed & WIPHY_PARAM_DYN_ACK)) {
2046 s16 coverage_class;
2047
2048 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2049 wiphy->coverage_class : -1;
2050 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002051
2052 if (err)
2053 return err;
2054 }
2055
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002056 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002057 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002058
Johannes Berg24487982009-04-23 18:52:52 +02002059 if (err)
2060 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002061 }
2062
Johannes Berg8bc83c22012-11-09 18:38:32 +01002063 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2064 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2065 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002066 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002067 }
2068 if (changed & WIPHY_PARAM_RETRY_LONG) {
2069 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2070 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002071 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002072 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002073 if (changed &
2074 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2075 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2076
2077 return 0;
2078}
2079
Johannes Berg7643a2c2009-06-02 13:01:39 +02002080static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002081 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002082 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002083{
2084 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002085 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002086
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002087 if (wdev) {
2088 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2089
2090 switch (type) {
2091 case NL80211_TX_POWER_AUTOMATIC:
2092 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2093 break;
2094 case NL80211_TX_POWER_LIMITED:
2095 case NL80211_TX_POWER_FIXED:
2096 if (mbm < 0 || (mbm % 100))
2097 return -EOPNOTSUPP;
2098 sdata->user_power_level = MBM_TO_DBM(mbm);
2099 break;
2100 }
2101
2102 ieee80211_recalc_txpower(sdata);
2103
2104 return 0;
2105 }
Johannes Berg55de9082012-07-26 17:24:39 +02002106
Johannes Berg7643a2c2009-06-02 13:01:39 +02002107 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002108 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002109 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002110 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002111 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002112 case NL80211_TX_POWER_FIXED:
2113 if (mbm < 0 || (mbm % 100))
2114 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002115 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002116 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002117 }
2118
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002119 mutex_lock(&local->iflist_mtx);
2120 list_for_each_entry(sdata, &local->interfaces, list)
2121 sdata->user_power_level = local->user_power_level;
2122 list_for_each_entry(sdata, &local->interfaces, list)
2123 ieee80211_recalc_txpower(sdata);
2124 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002125
2126 return 0;
2127}
2128
Johannes Bergc8442112012-10-24 10:17:18 +02002129static int ieee80211_get_tx_power(struct wiphy *wiphy,
2130 struct wireless_dev *wdev,
2131 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002132{
2133 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002134 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002135
Felix Fietkau5b3dc422014-10-26 00:32:53 +02002136 if (local->ops->get_txpower)
2137 return drv_get_txpower(local, sdata, dbm);
2138
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002139 if (!local->use_chanctx)
2140 *dbm = local->hw.conf.power_level;
2141 else
2142 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002143
Johannes Berg7643a2c2009-06-02 13:01:39 +02002144 return 0;
2145}
2146
Johannes Bergab737a42009-07-01 21:26:58 +02002147static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002148 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002149{
2150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2151
2152 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2153
2154 return 0;
2155}
2156
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002157static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2158{
2159 struct ieee80211_local *local = wiphy_priv(wiphy);
2160
2161 drv_rfkill_poll(local);
2162}
2163
Johannes Bergaff89a92009-07-01 21:26:51 +02002164#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002165static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2166 struct wireless_dev *wdev,
2167 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002168{
2169 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002170 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002171
2172 if (!local->ops->testmode_cmd)
2173 return -EOPNOTSUPP;
2174
David Spinadel52981cd2013-07-31 18:06:22 +03002175 if (wdev) {
2176 struct ieee80211_sub_if_data *sdata;
2177
2178 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2179 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2180 vif = &sdata->vif;
2181 }
2182
2183 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002184}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002185
2186static int ieee80211_testmode_dump(struct wiphy *wiphy,
2187 struct sk_buff *skb,
2188 struct netlink_callback *cb,
2189 void *data, int len)
2190{
2191 struct ieee80211_local *local = wiphy_priv(wiphy);
2192
2193 if (!local->ops->testmode_dump)
2194 return -EOPNOTSUPP;
2195
2196 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2197}
Johannes Bergaff89a92009-07-01 21:26:51 +02002198#endif
2199
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002200int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2201 enum ieee80211_smps_mode smps_mode)
2202{
2203 struct sta_info *sta;
2204 enum ieee80211_smps_mode old_req;
2205 int i;
2206
2207 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2208 return -EINVAL;
2209
2210 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2211 return 0;
2212
2213 old_req = sdata->u.ap.req_smps;
2214 sdata->u.ap.req_smps = smps_mode;
2215
2216 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2217 if (old_req == smps_mode ||
2218 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2219 return 0;
2220
2221 /* If no associated stations, there's no need to do anything */
2222 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2223 sdata->smps_mode = smps_mode;
2224 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2225 return 0;
2226 }
2227
2228 ht_dbg(sdata,
2229 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2230 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2231
2232 mutex_lock(&sdata->local->sta_mtx);
2233 for (i = 0; i < STA_HASH_SIZE; i++) {
2234 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2235 lockdep_is_held(&sdata->local->sta_mtx));
2236 sta;
2237 sta = rcu_dereference_protected(sta->hnext,
2238 lockdep_is_held(&sdata->local->sta_mtx))) {
2239 /*
2240 * Only stations associated to our AP and
2241 * associated VLANs
2242 */
2243 if (sta->sdata->bss != &sdata->u.ap)
2244 continue;
2245
2246 /* This station doesn't support MIMO - skip it */
2247 if (sta_info_tx_streams(sta) == 1)
2248 continue;
2249
2250 /*
2251 * Don't wake up a STA just to send the action frame
2252 * unless we are getting more restrictive.
2253 */
2254 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2255 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2256 smps_mode)) {
2257 ht_dbg(sdata,
2258 "Won't send SMPS to sleeping STA %pM\n",
2259 sta->sta.addr);
2260 continue;
2261 }
2262
2263 /*
2264 * If the STA is not authorized, wait until it gets
2265 * authorized and the action frame will be sent then.
2266 */
2267 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2268 continue;
2269
2270 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2271 ieee80211_send_smps_action(sdata, smps_mode,
2272 sta->sta.addr,
2273 sdata->vif.bss_conf.bssid);
2274 }
2275 }
2276 mutex_unlock(&sdata->local->sta_mtx);
2277
2278 sdata->smps_mode = smps_mode;
2279 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2280
2281 return 0;
2282}
2283
2284int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2285 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002286{
2287 const u8 *ap;
2288 enum ieee80211_smps_mode old_req;
2289 int err;
2290
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002291 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002292
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002293 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2294 return -EINVAL;
2295
Johannes Berg0f782312009-12-01 13:37:02 +01002296 old_req = sdata->u.mgd.req_smps;
2297 sdata->u.mgd.req_smps = smps_mode;
2298
2299 if (old_req == smps_mode &&
2300 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2301 return 0;
2302
2303 /*
2304 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002305 * association, there's no need to do anything, just store
2306 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002307 */
2308 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002309 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002310 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002311
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002312 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002313
2314 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2315 if (sdata->u.mgd.powersave)
2316 smps_mode = IEEE80211_SMPS_DYNAMIC;
2317 else
2318 smps_mode = IEEE80211_SMPS_OFF;
2319 }
2320
2321 /* send SM PS frame to AP */
2322 err = ieee80211_send_smps_action(sdata, smps_mode,
2323 ap, ap);
2324 if (err)
2325 sdata->u.mgd.req_smps = old_req;
2326
2327 return err;
2328}
2329
Johannes Bergbc92afd2009-07-01 21:26:57 +02002330static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2331 bool enabled, int timeout)
2332{
2333 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2334 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002335
Bob Copeland2d3db212013-10-29 18:11:59 -04002336 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002337 return -EOPNOTSUPP;
2338
Johannes Bergbc92afd2009-07-01 21:26:57 +02002339 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2340 return -EOPNOTSUPP;
2341
2342 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002343 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002344 return 0;
2345
2346 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002347 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002348
Johannes Berg0f782312009-12-01 13:37:02 +01002349 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002350 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002351 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002352 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002353
Johannes Bergbc92afd2009-07-01 21:26:57 +02002354 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2355 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2356
2357 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002358 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002359
2360 return 0;
2361}
2362
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002363static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2364 struct net_device *dev,
2365 s32 rssi_thold, u32 rssi_hyst)
2366{
2367 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002368 struct ieee80211_vif *vif = &sdata->vif;
2369 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2370
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002371 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2372 rssi_hyst == bss_conf->cqm_rssi_hyst)
2373 return 0;
2374
2375 bss_conf->cqm_rssi_thold = rssi_thold;
2376 bss_conf->cqm_rssi_hyst = rssi_hyst;
2377
2378 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002379 if (sdata->u.mgd.associated &&
2380 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002381 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2382
2383 return 0;
2384}
2385
Johannes Berg99303802009-07-01 21:26:59 +02002386static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2387 struct net_device *dev,
2388 const u8 *addr,
2389 const struct cfg80211_bitrate_mask *mask)
2390{
2391 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2392 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302393 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002394
Eliad Peller554a43d2012-06-12 12:41:15 +03002395 if (!ieee80211_sdata_running(sdata))
2396 return -ENETDOWN;
2397
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302398 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2399 ret = drv_set_bitrate_mask(local, sdata, mask);
2400 if (ret)
2401 return ret;
2402 }
Johannes Berg99303802009-07-01 21:26:59 +02002403
Simon Wunderlich19468412012-01-28 17:25:33 +01002404 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002405 struct ieee80211_supported_band *sband = wiphy->bands[i];
2406 int j;
2407
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002408 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002409 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2410 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002411
2412 sdata->rc_has_mcs_mask[i] = false;
2413 if (!sband)
2414 continue;
2415
2416 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2417 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2418 sdata->rc_has_mcs_mask[i] = true;
2419 break;
2420 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002421 }
Johannes Berg99303802009-07-01 21:26:59 +02002422
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002423 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002424}
2425
Eliad Pellereaa336b2014-09-03 15:25:06 +03002426static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2427 struct ieee80211_roc_work *new_roc,
2428 struct ieee80211_roc_work *cur_roc)
2429{
2430 unsigned long j = jiffies;
2431 unsigned long cur_roc_end = cur_roc->hw_start_time +
2432 msecs_to_jiffies(cur_roc->duration);
2433 struct ieee80211_roc_work *next_roc;
2434 int new_dur;
2435
2436 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2437 return false;
2438
2439 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2440 return false;
2441
2442 ieee80211_handle_roc_started(new_roc);
2443
2444 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2445
2446 /* cur_roc is long enough - add new_roc to the dependents list. */
2447 if (new_dur <= 0) {
2448 list_add_tail(&new_roc->list, &cur_roc->dependents);
2449 return true;
2450 }
2451
2452 new_roc->duration = new_dur;
2453
2454 /*
2455 * if cur_roc was already coalesced before, we might
2456 * want to extend the next roc instead of adding
2457 * a new one.
2458 */
2459 next_roc = list_entry(cur_roc->list.next,
2460 struct ieee80211_roc_work, list);
2461 if (&next_roc->list != &local->roc_list &&
2462 next_roc->chan == new_roc->chan &&
2463 next_roc->sdata == new_roc->sdata &&
2464 !WARN_ON(next_roc->started)) {
2465 list_add_tail(&new_roc->list, &next_roc->dependents);
2466 next_roc->duration = max(next_roc->duration,
2467 new_roc->duration);
2468 next_roc->type = max(next_roc->type, new_roc->type);
2469 return true;
2470 }
2471
2472 /* add right after cur_roc */
2473 list_add(&new_roc->list, &cur_roc->list);
2474
2475 return true;
2476}
2477
Johannes Berg2eb278e2012-06-05 14:28:42 +02002478static int ieee80211_start_roc_work(struct ieee80211_local *local,
2479 struct ieee80211_sub_if_data *sdata,
2480 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002481 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002482 struct sk_buff *txskb,
2483 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002484{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002485 struct ieee80211_roc_work *roc, *tmp;
2486 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002487 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002488
2489 lockdep_assert_held(&local->mtx);
2490
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002491 if (local->use_chanctx && !local->ops->remain_on_channel)
2492 return -EOPNOTSUPP;
2493
Johannes Berg2eb278e2012-06-05 14:28:42 +02002494 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2495 if (!roc)
2496 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002497
Ilan Peer2fae0622013-12-19 13:25:29 +02002498 /*
2499 * If the duration is zero, then the driver
2500 * wouldn't actually do anything. Set it to
2501 * 10 for now.
2502 *
2503 * TODO: cancel the off-channel operation
2504 * when we get the SKB's TX status and
2505 * the wait time was zero before.
2506 */
2507 if (!duration)
2508 duration = 10;
2509
Johannes Berg2eb278e2012-06-05 14:28:42 +02002510 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002511 roc->duration = duration;
2512 roc->req_duration = duration;
2513 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002514 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002515 roc->mgmt_tx_cookie = (unsigned long)txskb;
2516 roc->sdata = sdata;
2517 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2518 INIT_LIST_HEAD(&roc->dependents);
2519
Eliad Peller2f617432014-01-12 11:06:37 +02002520 /*
2521 * cookie is either the roc cookie (for normal roc)
2522 * or the SKB (for mgmt TX)
2523 */
2524 if (!txskb) {
2525 /* local->mtx protects this */
2526 local->roc_cookie_counter++;
2527 roc->cookie = local->roc_cookie_counter;
2528 /* wow, you wrapped 64 bits ... more likely a bug */
2529 if (WARN_ON(roc->cookie == 0)) {
2530 roc->cookie = 1;
2531 local->roc_cookie_counter++;
2532 }
2533 *cookie = roc->cookie;
2534 } else {
2535 *cookie = (unsigned long)txskb;
2536 }
2537
Johannes Berg2eb278e2012-06-05 14:28:42 +02002538 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002539 if (!list_empty(&local->roc_list) ||
2540 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002541 goto out_check_combine;
2542
2543 /* if not HW assist, just queue & schedule work */
2544 if (!local->ops->remain_on_channel) {
2545 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2546 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002547 }
2548
Johannes Berg2eb278e2012-06-05 14:28:42 +02002549 /* otherwise actually kick it off here (for error handling) */
2550
Ilan Peerd339d5c2013-02-12 09:34:13 +02002551 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002552 if (ret) {
2553 kfree(roc);
2554 return ret;
2555 }
2556
2557 roc->started = true;
2558 goto out_queue;
2559
2560 out_check_combine:
2561 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002562 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002563 continue;
2564
2565 /*
2566 * Extend this ROC if possible:
2567 *
2568 * If it hasn't started yet, just increase the duration
2569 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002570 * If the type of the new ROC has higher priority, modify the
2571 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002572 */
2573 if (!tmp->started) {
2574 list_add_tail(&roc->list, &tmp->dependents);
2575 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002576 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002577 queued = true;
2578 break;
2579 }
2580
2581 /* If it has already started, it's more difficult ... */
2582 if (local->ops->remain_on_channel) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002583 /*
2584 * In the offloaded ROC case, if it hasn't begun, add
2585 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002586 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002587 * check that there's still a minimum time left and
2588 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002589 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002590 * a reduced time so we'll ask the driver to execute
2591 * it right after finishing the previous one, in the
2592 * hope that it'll also be executed right afterwards,
2593 * effectively extending the old one.
2594 * If there's no minimum time left, just add it to the
2595 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002596 * TODO: the ROC type is ignored here, assuming that it
2597 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002598 */
2599 if (!tmp->hw_begun) {
2600 list_add_tail(&roc->list, &tmp->dependents);
2601 queued = true;
2602 break;
2603 }
2604
Eliad Pellereaa336b2014-09-03 15:25:06 +03002605 if (ieee80211_coalesce_started_roc(local, roc, tmp))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002606 queued = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002607 } else if (del_timer_sync(&tmp->work.timer)) {
2608 unsigned long new_end;
2609
2610 /*
2611 * In the software ROC case, cancel the timer, if
2612 * that fails then the finish work is already
2613 * queued/pending and thus we queue the new ROC
2614 * normally, if that succeeds then we can extend
2615 * the timer duration and TX the frame (if any.)
2616 */
2617
2618 list_add_tail(&roc->list, &tmp->dependents);
2619 queued = true;
2620
2621 new_end = jiffies + msecs_to_jiffies(roc->duration);
2622
2623 /* ok, it was started & we canceled timer */
2624 if (time_after(new_end, tmp->work.timer.expires))
2625 mod_timer(&tmp->work.timer, new_end);
2626 else
2627 add_timer(&tmp->work.timer);
2628
2629 ieee80211_handle_roc_started(roc);
2630 }
2631 break;
2632 }
2633
2634 out_queue:
2635 if (!queued)
2636 list_add_tail(&roc->list, &local->roc_list);
2637
Johannes Berg2eb278e2012-06-05 14:28:42 +02002638 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002639}
2640
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002641static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002642 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002643 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002644 unsigned int duration,
2645 u64 *cookie)
2646{
Johannes Berg71bbc992012-06-15 15:30:18 +02002647 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002648 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002649 int ret;
2650
Johannes Berg2eb278e2012-06-05 14:28:42 +02002651 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002652 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002653 duration, cookie, NULL,
2654 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002655 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002656
Johannes Berg2eb278e2012-06-05 14:28:42 +02002657 return ret;
2658}
2659
2660static int ieee80211_cancel_roc(struct ieee80211_local *local,
2661 u64 cookie, bool mgmt_tx)
2662{
2663 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2664 int ret;
2665
2666 mutex_lock(&local->mtx);
2667 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002668 struct ieee80211_roc_work *dep, *tmp2;
2669
2670 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002671 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002672 continue;
2673 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2674 continue;
2675 /* found dependent item -- just remove it */
2676 list_del(&dep->list);
2677 mutex_unlock(&local->mtx);
2678
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002679 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002680 return 0;
2681 }
2682
Johannes Berg50febf62012-10-26 16:13:06 +02002683 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002684 continue;
2685 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2686 continue;
2687
2688 found = roc;
2689 break;
2690 }
2691
2692 if (!found) {
2693 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002694 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002695 }
Johannes Berg21f83582010-12-18 17:20:47 +01002696
Johannes Berge979e332012-06-11 17:09:41 +02002697 /*
2698 * We found the item to cancel, so do that. Note that it
2699 * may have dependents, which we also cancel (and send
2700 * the expired signal for.) Not doing so would be quite
2701 * tricky here, but we may need to fix it later.
2702 */
2703
Johannes Berg2eb278e2012-06-05 14:28:42 +02002704 if (local->ops->remain_on_channel) {
2705 if (found->started) {
2706 ret = drv_cancel_remain_on_channel(local);
2707 if (WARN_ON_ONCE(ret)) {
2708 mutex_unlock(&local->mtx);
2709 return ret;
2710 }
2711 }
Johannes Berg21f83582010-12-18 17:20:47 +01002712
Johannes Berg2eb278e2012-06-05 14:28:42 +02002713 list_del(&found->list);
2714
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002715 if (found->started)
2716 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002717 mutex_unlock(&local->mtx);
2718
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002719 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002720 } else {
2721 /* work may be pending so use it all the time */
2722 found->abort = true;
2723 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2724
2725 mutex_unlock(&local->mtx);
2726
2727 /* work will clean up etc */
2728 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002729 WARN_ON(!found->to_be_freed);
2730 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002731 }
Johannes Berg21f83582010-12-18 17:20:47 +01002732
Johannes Berg21f83582010-12-18 17:20:47 +01002733 return 0;
2734}
2735
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002736static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002737 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002738 u64 cookie)
2739{
Johannes Berg71bbc992012-06-15 15:30:18 +02002740 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002741 struct ieee80211_local *local = sdata->local;
2742
Johannes Berg2eb278e2012-06-05 14:28:42 +02002743 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002744}
2745
Simon Wunderlich164eb022013-02-08 18:16:20 +01002746static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2747 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002748 struct cfg80211_chan_def *chandef,
2749 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002750{
2751 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2752 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002753 int err;
2754
Johannes Berg34a37402013-12-18 09:43:33 +01002755 mutex_lock(&local->mtx);
2756 if (!list_empty(&local->roc_list) || local->scanning) {
2757 err = -EBUSY;
2758 goto out_unlock;
2759 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002760
2761 /* whatever, but channel contexts should not complain about that one */
2762 sdata->smps_mode = IEEE80211_SMPS_OFF;
2763 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002764
Simon Wunderlich164eb022013-02-08 18:16:20 +01002765 err = ieee80211_vif_use_channel(sdata, chandef,
2766 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002767 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002768 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002769
Simon Wunderlich164eb022013-02-08 18:16:20 +01002770 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002771 &sdata->dfs_cac_timer_work,
2772 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002773
Johannes Berg34a37402013-12-18 09:43:33 +01002774 out_unlock:
2775 mutex_unlock(&local->mtx);
2776 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002777}
2778
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002779static struct cfg80211_beacon_data *
2780cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2781{
2782 struct cfg80211_beacon_data *new_beacon;
2783 u8 *pos;
2784 int len;
2785
2786 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2787 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2788 beacon->probe_resp_len;
2789
2790 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2791 if (!new_beacon)
2792 return NULL;
2793
2794 pos = (u8 *)(new_beacon + 1);
2795 if (beacon->head_len) {
2796 new_beacon->head_len = beacon->head_len;
2797 new_beacon->head = pos;
2798 memcpy(pos, beacon->head, beacon->head_len);
2799 pos += beacon->head_len;
2800 }
2801 if (beacon->tail_len) {
2802 new_beacon->tail_len = beacon->tail_len;
2803 new_beacon->tail = pos;
2804 memcpy(pos, beacon->tail, beacon->tail_len);
2805 pos += beacon->tail_len;
2806 }
2807 if (beacon->beacon_ies_len) {
2808 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2809 new_beacon->beacon_ies = pos;
2810 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2811 pos += beacon->beacon_ies_len;
2812 }
2813 if (beacon->proberesp_ies_len) {
2814 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2815 new_beacon->proberesp_ies = pos;
2816 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2817 pos += beacon->proberesp_ies_len;
2818 }
2819 if (beacon->assocresp_ies_len) {
2820 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2821 new_beacon->assocresp_ies = pos;
2822 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2823 pos += beacon->assocresp_ies_len;
2824 }
2825 if (beacon->probe_resp_len) {
2826 new_beacon->probe_resp_len = beacon->probe_resp_len;
2827 beacon->probe_resp = pos;
2828 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2829 pos += beacon->probe_resp_len;
2830 }
2831
2832 return new_beacon;
2833}
2834
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002835void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002836{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002837 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2838
2839 ieee80211_queue_work(&sdata->local->hw,
2840 &sdata->csa_finalize_work);
2841}
2842EXPORT_SYMBOL(ieee80211_csa_finish);
2843
Michal Kazior66199502014-04-09 15:11:00 +02002844static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2845 u32 *changed)
2846{
2847 int err;
2848
2849 switch (sdata->vif.type) {
2850 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002851 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2852 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002853 kfree(sdata->u.ap.next_beacon);
2854 sdata->u.ap.next_beacon = NULL;
2855
2856 if (err < 0)
2857 return err;
2858 *changed |= err;
2859 break;
2860 case NL80211_IFTYPE_ADHOC:
2861 err = ieee80211_ibss_finish_csa(sdata);
2862 if (err < 0)
2863 return err;
2864 *changed |= err;
2865 break;
2866#ifdef CONFIG_MAC80211_MESH
2867 case NL80211_IFTYPE_MESH_POINT:
2868 err = ieee80211_mesh_finish_csa(sdata);
2869 if (err < 0)
2870 return err;
2871 *changed |= err;
2872 break;
2873#endif
2874 default:
2875 WARN_ON(1);
2876 return -EINVAL;
2877 }
2878
2879 return 0;
2880}
2881
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002882static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002883{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002884 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02002885 u32 changed = 0;
2886 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002887
Michal Kaziordbd72852014-01-29 07:56:21 +01002888 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002889 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002890 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01002891
Michal Kazior03078de2014-06-25 12:35:08 +02002892 /*
2893 * using reservation isn't immediate as it may be deferred until later
2894 * with multi-vif. once reservation is complete it will re-schedule the
2895 * work with no reserved_chanctx so verify chandef to check if it
2896 * completed successfully
2897 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002898
Michal Kazior03078de2014-06-25 12:35:08 +02002899 if (sdata->reserved_chanctx) {
2900 /*
2901 * with multi-vif csa driver may call ieee80211_csa_finish()
2902 * many times while waiting for other interfaces to use their
2903 * reservations
2904 */
2905 if (sdata->reserved_ready)
2906 return 0;
2907
Fabian Frederick408b18a2014-10-09 20:36:22 +02002908 return ieee80211_vif_use_reserved_context(sdata);
Arik Nemtsov7578d572013-09-01 17:15:51 +03002909 }
2910
Michal Kazior03078de2014-06-25 12:35:08 +02002911 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2912 &sdata->csa_chandef))
2913 return -EINVAL;
2914
Simon Wunderliche487eae2013-11-21 18:19:51 +01002915 sdata->vif.csa_active = false;
Michal Kazior97518af2014-01-29 07:56:18 +01002916
Michal Kazior66199502014-04-09 15:11:00 +02002917 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2918 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002919 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002920
Michal Kaziorfaf046e2014-01-29 07:56:17 +01002921 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02002922
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002923 if (sdata->csa_block_tx) {
2924 ieee80211_wake_vif_queues(local, sdata,
2925 IEEE80211_QUEUE_STOP_REASON_CSA);
2926 sdata->csa_block_tx = false;
2927 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002928
Luciano Coelhof1d65582014-10-08 09:48:38 +03002929 err = drv_post_channel_switch(sdata);
2930 if (err)
2931 return err;
2932
2933 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2934
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002935 return 0;
2936}
2937
2938static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2939{
2940 if (__ieee80211_csa_finalize(sdata)) {
2941 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2942 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2943 GFP_KERNEL);
2944 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002945}
2946
2947void ieee80211_csa_finalize_work(struct work_struct *work)
2948{
2949 struct ieee80211_sub_if_data *sdata =
2950 container_of(work, struct ieee80211_sub_if_data,
2951 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02002952 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002953
2954 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002955 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002956 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002957
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002958 /* AP might have been stopped while waiting for the lock. */
2959 if (!sdata->vif.csa_active)
2960 goto unlock;
2961
2962 if (!ieee80211_sdata_running(sdata))
2963 goto unlock;
2964
2965 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002966
2967unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02002968 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002969 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002970 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002971}
2972
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002973static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
2974 struct cfg80211_csa_settings *params,
2975 u32 *changed)
2976{
Michal Kazioraf296bd2014-06-05 14:21:36 +02002977 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002978 int err;
2979
2980 switch (sdata->vif.type) {
2981 case NL80211_IFTYPE_AP:
2982 sdata->u.ap.next_beacon =
2983 cfg80211_beacon_dup(&params->beacon_after);
2984 if (!sdata->u.ap.next_beacon)
2985 return -ENOMEM;
2986
2987 /*
2988 * With a count of 0, we don't have to wait for any
2989 * TBTT before switching, so complete the CSA
2990 * immediately. In theory, with a count == 1 we
2991 * should delay the switch until just before the next
2992 * TBTT, but that would complicate things so we switch
2993 * immediately too. If we would delay the switch
2994 * until the next TBTT, we would have to set the probe
2995 * response here.
2996 *
2997 * TODO: A channel switch with count <= 1 without
2998 * sending a CSA action frame is kind of useless,
2999 * because the clients won't know we're changing
3000 * channels. The action frame must be implemented
3001 * either here or in the userspace.
3002 */
3003 if (params->count <= 1)
3004 break;
3005
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003006 if ((params->n_counter_offsets_beacon >
3007 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3008 (params->n_counter_offsets_presp >
3009 IEEE80211_MAX_CSA_COUNTERS_NUM))
3010 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003011
Michal Kazioraf296bd2014-06-05 14:21:36 +02003012 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3013 csa.counter_offsets_presp = params->counter_offsets_presp;
3014 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3015 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3016 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003017
Michal Kazioraf296bd2014-06-05 14:21:36 +02003018 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003019 if (err < 0) {
3020 kfree(sdata->u.ap.next_beacon);
3021 return err;
3022 }
3023 *changed |= err;
3024
3025 break;
3026 case NL80211_IFTYPE_ADHOC:
3027 if (!sdata->vif.bss_conf.ibss_joined)
3028 return -EINVAL;
3029
3030 if (params->chandef.width != sdata->u.ibss.chandef.width)
3031 return -EINVAL;
3032
3033 switch (params->chandef.width) {
3034 case NL80211_CHAN_WIDTH_40:
3035 if (cfg80211_get_chandef_type(&params->chandef) !=
3036 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3037 return -EINVAL;
3038 case NL80211_CHAN_WIDTH_5:
3039 case NL80211_CHAN_WIDTH_10:
3040 case NL80211_CHAN_WIDTH_20_NOHT:
3041 case NL80211_CHAN_WIDTH_20:
3042 break;
3043 default:
3044 return -EINVAL;
3045 }
3046
3047 /* changes into another band are not supported */
3048 if (sdata->u.ibss.chandef.chan->band !=
3049 params->chandef.chan->band)
3050 return -EINVAL;
3051
3052 /* see comments in the NL80211_IFTYPE_AP block */
3053 if (params->count > 1) {
3054 err = ieee80211_ibss_csa_beacon(sdata, params);
3055 if (err < 0)
3056 return err;
3057 *changed |= err;
3058 }
3059
3060 ieee80211_send_action_csa(sdata, params);
3061
3062 break;
3063#ifdef CONFIG_MAC80211_MESH
3064 case NL80211_IFTYPE_MESH_POINT: {
3065 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3066
3067 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3068 return -EINVAL;
3069
3070 /* changes into another band are not supported */
3071 if (sdata->vif.bss_conf.chandef.chan->band !=
3072 params->chandef.chan->band)
3073 return -EINVAL;
3074
3075 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3076 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3077 if (!ifmsh->pre_value)
3078 ifmsh->pre_value = 1;
3079 else
3080 ifmsh->pre_value++;
3081 }
3082
3083 /* see comments in the NL80211_IFTYPE_AP block */
3084 if (params->count > 1) {
3085 err = ieee80211_mesh_csa_beacon(sdata, params);
3086 if (err < 0) {
3087 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3088 return err;
3089 }
3090 *changed |= err;
3091 }
3092
3093 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3094 ieee80211_send_action_csa(sdata, params);
3095
3096 break;
3097 }
3098#endif
3099 default:
3100 return -EOPNOTSUPP;
3101 }
3102
3103 return 0;
3104}
3105
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003106static int
3107__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3108 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003109{
3110 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3111 struct ieee80211_local *local = sdata->local;
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003112 struct ieee80211_channel_switch ch_switch;
Michal Kazior2b327132014-04-09 15:29:32 +02003113 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003114 struct ieee80211_chanctx *chanctx;
Johannes Bergb08cc242014-10-20 21:36:04 +02003115 u32 changed = 0;
3116 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003117
Michal Kaziordbd72852014-01-29 07:56:21 +01003118 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003119 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003120
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003121 if (!list_empty(&local->roc_list) || local->scanning)
3122 return -EBUSY;
3123
3124 if (sdata->wdev.cac_started)
3125 return -EBUSY;
3126
3127 if (cfg80211_chandef_identical(&params->chandef,
3128 &sdata->vif.bss_conf.chandef))
3129 return -EINVAL;
3130
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003131 /* don't allow another channel switch if one is already active. */
3132 if (sdata->vif.csa_active)
3133 return -EBUSY;
3134
Michal Kazior03078de2014-06-25 12:35:08 +02003135 mutex_lock(&local->chanctx_mtx);
3136 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3137 lockdep_is_held(&local->chanctx_mtx));
3138 if (!conf) {
3139 err = -EBUSY;
3140 goto out;
3141 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003142
Michal Kazior03078de2014-06-25 12:35:08 +02003143 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3144 if (!chanctx) {
3145 err = -EBUSY;
3146 goto out;
3147 }
3148
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003149 err = drv_pre_channel_switch(sdata, &ch_switch);
3150 if (err)
3151 goto out;
3152
Michal Kazior03078de2014-06-25 12:35:08 +02003153 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3154 chanctx->mode,
3155 params->radar_required);
3156 if (err)
3157 goto out;
3158
3159 /* if reservation is invalid then this will fail */
3160 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3161 if (err) {
3162 ieee80211_vif_unreserve_chanctx(sdata);
3163 goto out;
3164 }
3165
Luciano Coelho6d027bc2014-10-08 09:48:37 +03003166 ch_switch.timestamp = 0;
3167 ch_switch.device_timestamp = 0;
3168 ch_switch.block_tx = params->block_tx;
3169 ch_switch.chandef = params->chandef;
3170 ch_switch.count = params->count;
3171
Michal Kazior03078de2014-06-25 12:35:08 +02003172 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3173 if (err) {
3174 ieee80211_vif_unreserve_chanctx(sdata);
3175 goto out;
3176 }
3177
Luciano Coelho33787fc2013-11-11 20:34:54 +02003178 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003179 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003180 sdata->vif.csa_active = true;
3181
Michal Kazior59af6922014-04-09 15:10:59 +02003182 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003183 ieee80211_stop_vif_queues(local, sdata,
3184 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003185
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003186 if (changed) {
3187 ieee80211_bss_info_change_notify(sdata, changed);
3188 drv_channel_switch_beacon(sdata, &params->chandef);
3189 } else {
3190 /* if the beacon didn't change, we can finalize immediately */
3191 ieee80211_csa_finalize(sdata);
3192 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003193
Michal Kazior03078de2014-06-25 12:35:08 +02003194out:
3195 mutex_unlock(&local->chanctx_mtx);
3196 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003197}
3198
Michal Kazior59af6922014-04-09 15:10:59 +02003199int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3200 struct cfg80211_csa_settings *params)
3201{
3202 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3203 struct ieee80211_local *local = sdata->local;
3204 int err;
3205
3206 mutex_lock(&local->mtx);
3207 err = __ieee80211_channel_switch(wiphy, dev, params);
3208 mutex_unlock(&local->mtx);
3209
3210 return err;
3211}
3212
Johannes Berg71bbc992012-06-15 15:30:18 +02003213static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003214 struct cfg80211_mgmt_tx_params *params,
3215 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003216{
Johannes Berg71bbc992012-06-15 15:30:18 +02003217 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003218 struct ieee80211_local *local = sdata->local;
3219 struct sk_buff *skb;
3220 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003221 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003222 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003223 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003224 int ret;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003225 u8 *data;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003226
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003227 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003228 flags = IEEE80211_TX_CTL_NO_ACK;
3229 else
3230 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3231 IEEE80211_TX_CTL_REQ_TX_STATUS;
3232
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003233 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303234 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3235
Johannes Berg9d38d852010-06-09 17:20:33 +02003236 switch (sdata->vif.type) {
3237 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003238 if (!sdata->vif.bss_conf.ibss_joined)
3239 need_offchan = true;
3240 /* fall through */
3241#ifdef CONFIG_MAC80211_MESH
3242 case NL80211_IFTYPE_MESH_POINT:
3243 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3244 !sdata->u.mesh.mesh_id_len)
3245 need_offchan = true;
3246 /* fall through */
3247#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003248 case NL80211_IFTYPE_AP:
3249 case NL80211_IFTYPE_AP_VLAN:
3250 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003251 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3252 !ieee80211_vif_is_mesh(&sdata->vif) &&
3253 !rcu_access_pointer(sdata->bss->beacon))
3254 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003255 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003256 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003257 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3258 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003259 break;
3260 rcu_read_lock();
3261 sta = sta_info_get(sdata, mgmt->da);
3262 rcu_read_unlock();
3263 if (!sta)
3264 return -ENOLINK;
3265 break;
3266 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003267 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003268 if (!sdata->u.mgd.associated)
3269 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003270 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003271 case NL80211_IFTYPE_P2P_DEVICE:
3272 need_offchan = true;
3273 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003274 default:
3275 return -EOPNOTSUPP;
3276 }
3277
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003278 /* configurations requiring offchan cannot work if no channel has been
3279 * specified
3280 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003281 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003282 return -EINVAL;
3283
Johannes Berg2eb278e2012-06-05 14:28:42 +02003284 mutex_lock(&local->mtx);
3285
3286 /* Check if the operating channel is the requested channel */
3287 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003288 struct ieee80211_chanctx_conf *chanctx_conf;
3289
3290 rcu_read_lock();
3291 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3292
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003293 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003294 need_offchan = params->chan &&
3295 (params->chan !=
3296 chanctx_conf->def.chan);
3297 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003298 ret = -EINVAL;
3299 rcu_read_unlock();
3300 goto out_unlock;
3301 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003302 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003303 }
Johannes Berg55de9082012-07-26 17:24:39 +02003304 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003305 }
3306
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003307 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003308 ret = -EBUSY;
3309 goto out_unlock;
3310 }
3311
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003312 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003313 if (!skb) {
3314 ret = -ENOMEM;
3315 goto out_unlock;
3316 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003317 skb_reserve(skb, local->hw.extra_tx_headroom);
3318
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003319 data = skb_put(skb, params->len);
3320 memcpy(data, params->buf, params->len);
3321
3322 /* Update CSA counters */
3323 if (sdata->vif.csa_active &&
3324 (sdata->vif.type == NL80211_IFTYPE_AP ||
3325 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3326 params->n_csa_offsets) {
3327 int i;
Michal Kazioraf296bd2014-06-05 14:21:36 +02003328 struct beacon_data *beacon = NULL;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003329
Michal Kazioraf296bd2014-06-05 14:21:36 +02003330 rcu_read_lock();
3331
3332 if (sdata->vif.type == NL80211_IFTYPE_AP)
3333 beacon = rcu_dereference(sdata->u.ap.beacon);
3334 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3335 beacon = rcu_dereference(sdata->u.ibss.presp);
3336 else if (ieee80211_vif_is_mesh(&sdata->vif))
3337 beacon = rcu_dereference(sdata->u.mesh.beacon);
3338
3339 if (beacon)
3340 for (i = 0; i < params->n_csa_offsets; i++)
3341 data[params->csa_offsets[i]] =
3342 beacon->csa_current_counter;
3343
3344 rcu_read_unlock();
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003345 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003346
3347 IEEE80211_SKB_CB(skb)->flags = flags;
3348
Johannes Berg2eb278e2012-06-05 14:28:42 +02003349 skb->dev = sdata->dev;
3350
3351 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003352 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003353 ieee80211_tx_skb(sdata, skb);
3354 ret = 0;
3355 goto out_unlock;
3356 }
3357
Seth Forshee6c17b772013-02-11 11:21:07 -06003358 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3359 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003360 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003361 IEEE80211_SKB_CB(skb)->hw_queue =
3362 local->hw.offchannel_tx_hw_queue;
3363
Johannes Berg2eb278e2012-06-05 14:28:42 +02003364 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003365 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3366 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003367 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003368 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003369 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003370 out_unlock:
3371 mutex_unlock(&local->mtx);
3372 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003373}
3374
Johannes Bergf30221e2010-11-25 10:02:30 +01003375static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003376 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003377 u64 cookie)
3378{
Johannes Berg71bbc992012-06-15 15:30:18 +02003379 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003380
Johannes Berg2eb278e2012-06-05 14:28:42 +02003381 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003382}
3383
Johannes Berg7be50862010-10-13 12:06:24 +02003384static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003385 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003386 u16 frame_type, bool reg)
3387{
3388 struct ieee80211_local *local = wiphy_priv(wiphy);
3389
Will Hawkins6abe0562012-06-20 11:51:14 -04003390 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003391 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3392 if (reg)
3393 local->probe_req_reg++;
3394 else
3395 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003396
Felix Fietkau35f51492012-10-31 15:50:34 +01003397 if (!local->open_count)
3398 break;
3399
Will Hawkins6abe0562012-06-20 11:51:14 -04003400 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3401 break;
3402 default:
3403 break;
3404 }
Johannes Berg7be50862010-10-13 12:06:24 +02003405}
3406
Bruno Randolf15d96752010-11-10 12:50:56 +09003407static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3408{
3409 struct ieee80211_local *local = wiphy_priv(wiphy);
3410
3411 if (local->started)
3412 return -EOPNOTSUPP;
3413
3414 return drv_set_antenna(local, tx_ant, rx_ant);
3415}
3416
3417static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3418{
3419 struct ieee80211_local *local = wiphy_priv(wiphy);
3420
3421 return drv_get_antenna(local, tx_ant, rx_ant);
3422}
3423
Johannes Bergc68f4b82011-07-05 16:35:41 +02003424static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3425 struct net_device *dev,
3426 struct cfg80211_gtk_rekey_data *data)
3427{
3428 struct ieee80211_local *local = wiphy_priv(wiphy);
3429 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3430
3431 if (!local->ops->set_rekey_data)
3432 return -EOPNOTSUPP;
3433
3434 drv_set_rekey_data(local, sdata, data);
3435
3436 return 0;
3437}
3438
Johannes Berg06500732011-11-04 11:18:16 +01003439static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3440 const u8 *peer, u64 *cookie)
3441{
3442 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3443 struct ieee80211_local *local = sdata->local;
3444 struct ieee80211_qos_hdr *nullfunc;
3445 struct sk_buff *skb;
3446 int size = sizeof(*nullfunc);
3447 __le16 fc;
3448 bool qos;
3449 struct ieee80211_tx_info *info;
3450 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003451 struct ieee80211_chanctx_conf *chanctx_conf;
3452 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003453
3454 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003455 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3456 if (WARN_ON(!chanctx_conf)) {
3457 rcu_read_unlock();
3458 return -EINVAL;
3459 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003460 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003461 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003462 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003463 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003464 } else {
3465 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003466 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003467 }
Johannes Berg06500732011-11-04 11:18:16 +01003468
3469 if (qos) {
3470 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3471 IEEE80211_STYPE_QOS_NULLFUNC |
3472 IEEE80211_FCTL_FROMDS);
3473 } else {
3474 size -= 2;
3475 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3476 IEEE80211_STYPE_NULLFUNC |
3477 IEEE80211_FCTL_FROMDS);
3478 }
3479
3480 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003481 if (!skb) {
3482 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003483 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003484 }
Johannes Berg06500732011-11-04 11:18:16 +01003485
3486 skb->dev = dev;
3487
3488 skb_reserve(skb, local->hw.extra_tx_headroom);
3489
3490 nullfunc = (void *) skb_put(skb, size);
3491 nullfunc->frame_control = fc;
3492 nullfunc->duration_id = 0;
3493 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3494 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3495 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3496 nullfunc->seq_ctrl = 0;
3497
3498 info = IEEE80211_SKB_CB(skb);
3499
3500 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3501 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3502
3503 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3504 skb->priority = 7;
3505 if (qos)
3506 nullfunc->qos_ctrl = cpu_to_le16(7);
3507
3508 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003509 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003510 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003511 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003512
3513 *cookie = (unsigned long) skb;
3514 return 0;
3515}
3516
Johannes Berg683b6d32012-11-08 21:25:48 +01003517static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3518 struct wireless_dev *wdev,
3519 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003520{
Johannes Berg55de9082012-07-26 17:24:39 +02003521 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003522 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003523 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003524 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003525
Johannes Berg55de9082012-07-26 17:24:39 +02003526 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003527 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3528 if (chanctx_conf) {
Luciano Coelhoc12bc482014-09-30 07:08:02 +03003529 *chandef = sdata->vif.bss_conf.chandef;
Johannes Bergfeda3022013-02-28 09:59:22 +01003530 ret = 0;
3531 } else if (local->open_count > 0 &&
3532 local->open_count == local->monitors &&
3533 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3534 if (local->use_chanctx)
3535 *chandef = local->monitor_chandef;
3536 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003537 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003538 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003539 }
3540 rcu_read_unlock();
3541
Johannes Berg683b6d32012-11-08 21:25:48 +01003542 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003543}
3544
Johannes Berg6d525632012-04-04 15:05:25 +02003545#ifdef CONFIG_PM
3546static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3547{
3548 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3549}
3550#endif
3551
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003552static int ieee80211_set_qos_map(struct wiphy *wiphy,
3553 struct net_device *dev,
3554 struct cfg80211_qos_map *qos_map)
3555{
3556 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3557 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3558
3559 if (qos_map) {
3560 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3561 if (!new_qos_map)
3562 return -ENOMEM;
3563 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3564 } else {
3565 /* A NULL qos_map was passed to disable QoS mapping */
3566 new_qos_map = NULL;
3567 }
3568
Johannes Berg194ff522013-12-30 23:12:37 +01003569 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003570 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3571 if (old_qos_map)
3572 kfree_rcu(old_qos_map, rcu_head);
3573
3574 return 0;
3575}
3576
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003577static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3578 struct net_device *dev,
3579 struct cfg80211_chan_def *chandef)
3580{
3581 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3582 int ret;
3583 u32 changed = 0;
3584
3585 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3586 if (ret == 0)
3587 ieee80211_bss_info_change_notify(sdata, changed);
3588
3589 return ret;
3590}
3591
Johannes Berg02219b32014-10-07 10:38:50 +03003592static int ieee80211_add_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3593 u8 tsid, const u8 *peer, u8 up,
3594 u16 admitted_time)
3595{
3596 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3597 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3598 int ac = ieee802_1d_to_ac[up];
3599
3600 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3601 return -EOPNOTSUPP;
3602
3603 if (!(sdata->wmm_acm & BIT(up)))
3604 return -EINVAL;
3605
3606 if (ifmgd->tx_tspec[ac].admitted_time)
3607 return -EBUSY;
3608
3609 if (admitted_time) {
3610 ifmgd->tx_tspec[ac].admitted_time = 32 * admitted_time;
3611 ifmgd->tx_tspec[ac].tsid = tsid;
3612 ifmgd->tx_tspec[ac].up = up;
3613 }
3614
3615 return 0;
3616}
3617
3618static int ieee80211_del_tx_ts(struct wiphy *wiphy, struct net_device *dev,
3619 u8 tsid, const u8 *peer)
3620{
3621 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3622 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
3623 struct ieee80211_local *local = wiphy_priv(wiphy);
3624 int ac;
3625
3626 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
3627 struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
3628
3629 /* skip unused entries */
3630 if (!tx_tspec->admitted_time)
3631 continue;
3632
3633 if (tx_tspec->tsid != tsid)
3634 continue;
3635
3636 /* due to this new packets will be reassigned to non-ACM ACs */
3637 tx_tspec->up = -1;
3638
3639 /* Make sure that all packets have been sent to avoid to
3640 * restore the QoS params on packets that are still on the
3641 * queues.
3642 */
3643 synchronize_net();
3644 ieee80211_flush_queues(local, sdata);
3645
3646 /* restore the normal QoS parameters
3647 * (unconditionally to avoid races)
3648 */
3649 tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
3650 tx_tspec->downgraded = false;
3651 ieee80211_sta_handle_tspec_ac_params(sdata);
3652
3653 /* finally clear all the data */
3654 memset(tx_tspec, 0, sizeof(*tx_tspec));
3655
3656 return 0;
3657 }
3658
3659 return -ENOENT;
3660}
3661
Johannes Berg8a47cea2014-01-20 23:55:44 +01003662const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003663 .add_virtual_intf = ieee80211_add_iface,
3664 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003665 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003666 .start_p2p_device = ieee80211_start_p2p_device,
3667 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003668 .add_key = ieee80211_add_key,
3669 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003670 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003671 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003672 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003673 .start_ap = ieee80211_start_ap,
3674 .change_beacon = ieee80211_change_beacon,
3675 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003676 .add_station = ieee80211_add_station,
3677 .del_station = ieee80211_del_station,
3678 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003679 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003680 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003681 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003682#ifdef CONFIG_MAC80211_MESH
3683 .add_mpath = ieee80211_add_mpath,
3684 .del_mpath = ieee80211_del_mpath,
3685 .change_mpath = ieee80211_change_mpath,
3686 .get_mpath = ieee80211_get_mpath,
3687 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02003688 .get_mpp = ieee80211_get_mpp,
3689 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003690 .update_mesh_config = ieee80211_update_mesh_config,
3691 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003692 .join_mesh = ieee80211_join_mesh,
3693 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003694#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003695 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003696 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003697 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003698 .suspend = ieee80211_suspend,
3699 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003700 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003701 .sched_scan_start = ieee80211_sched_scan_start,
3702 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003703 .auth = ieee80211_auth,
3704 .assoc = ieee80211_assoc,
3705 .deauth = ieee80211_deauth,
3706 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003707 .join_ibss = ieee80211_join_ibss,
3708 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003709 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003710 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003711 .set_tx_power = ieee80211_set_tx_power,
3712 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003713 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003714 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003715 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003716 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003717 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003718 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003719 .remain_on_channel = ieee80211_remain_on_channel,
3720 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003721 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003722 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003723 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003724 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003725 .set_antenna = ieee80211_set_antenna,
3726 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003727 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003728 .tdls_oper = ieee80211_tdls_oper,
3729 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003730 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003731 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003732#ifdef CONFIG_PM
3733 .set_wakeup = ieee80211_set_wakeup,
3734#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003735 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003736 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003737 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003738 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003739 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Johannes Berg02219b32014-10-07 10:38:50 +03003740 .add_tx_ts = ieee80211_add_tx_ts,
3741 .del_tx_ts = ieee80211_del_tx_ts,
Jiri Bencf0706e82007-05-05 11:45:53 -07003742};