blob: 4c1681bae232edc439d11f471e757f0a9dc1b003 [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"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010023
Johannes Berg552bff02012-09-19 09:26:06 +020024static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
25 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020026 enum nl80211_iftype type,
27 u32 *flags,
28 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070029{
30 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020031 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010032 struct ieee80211_sub_if_data *sdata;
33 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070034
Johannes Berg84efbb82012-06-16 00:00:26 +020035 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010036 if (err)
37 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010038
Johannes Bergf9e10ce2010-12-03 09:20:42 +010039 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020040 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010041 sdata->u.mntr_flags = *flags;
42 }
43
Johannes Berg84efbb82012-06-16 00:00:26 +020044 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070045}
46
Johannes Berg84efbb82012-06-16 00:00:26 +020047static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070048{
Johannes Berg84efbb82012-06-16 00:00:26 +020049 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070050
Johannes Berg75636522008-07-09 14:40:35 +020051 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070052}
53
Johannes Berge36d56b2009-06-09 21:04:43 +020054static int ieee80211_change_iface(struct wiphy *wiphy,
55 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010056 enum nl80211_iftype type, u32 *flags,
57 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020058{
Johannes Berg9607e6b2009-12-23 13:15:31 +010059 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020060 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020061
Johannes Berg05c914f2008-09-11 00:01:58 +020062 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020063 if (ret)
64 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020065
Johannes Berg9bc383d2009-11-19 11:55:19 +010066 if (type == NL80211_IFTYPE_AP_VLAN &&
67 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000068 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010069 else if (type == NL80211_IFTYPE_STATION &&
70 params && params->use_4addr >= 0)
71 sdata->u.mgd.use_4addr = params->use_4addr;
72
Christian Lamparter85416a42010-10-02 13:17:07 +020073 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
74 struct ieee80211_local *local = sdata->local;
75
76 if (ieee80211_sdata_running(sdata)) {
Felix Fietkau31eba5b2013-05-28 13:01:53 +020077 u32 mask = MONITOR_FLAG_COOK_FRAMES |
78 MONITOR_FLAG_ACTIVE;
79
Christian Lamparter85416a42010-10-02 13:17:07 +020080 /*
Felix Fietkau31eba5b2013-05-28 13:01:53 +020081 * Prohibit MONITOR_FLAG_COOK_FRAMES and
82 * MONITOR_FLAG_ACTIVE to be changed while the
83 * interface is up.
Christian Lamparter85416a42010-10-02 13:17:07 +020084 * Else we would need to add a lot of cruft
85 * to update everything:
86 * cooked_mntrs, monitor and all fif_* counters
87 * reconfigure hardware
88 */
Felix Fietkau31eba5b2013-05-28 13:01:53 +020089 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
Christian Lamparter85416a42010-10-02 13:17:07 +020090 return -EBUSY;
91
92 ieee80211_adjust_monitor_flags(sdata, -1);
93 sdata->u.mntr_flags = *flags;
94 ieee80211_adjust_monitor_flags(sdata, 1);
95
96 ieee80211_configure_filter(local);
97 } else {
98 /*
99 * Because the interface is down, ieee80211_do_stop
100 * and ieee80211_do_open take care of "everything"
101 * mentioned in the comment above.
102 */
103 sdata->u.mntr_flags = *flags;
104 }
105 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200106
Johannes Berg42613db2007-09-28 21:52:27 +0200107 return 0;
108}
109
Johannes Bergf142c6b2012-06-18 20:07:15 +0200110static int ieee80211_start_p2p_device(struct wiphy *wiphy,
111 struct wireless_dev *wdev)
112{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200113 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
114 int ret;
115
116 mutex_lock(&sdata->local->chanctx_mtx);
117 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
118 mutex_unlock(&sdata->local->chanctx_mtx);
119 if (ret < 0)
120 return ret;
121
Johannes Bergf142c6b2012-06-18 20:07:15 +0200122 return ieee80211_do_open(wdev, true);
123}
124
125static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
126 struct wireless_dev *wdev)
127{
128 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
129}
130
Simon Wunderlichb53be792011-11-18 14:20:44 +0100131static int ieee80211_set_noack_map(struct wiphy *wiphy,
132 struct net_device *dev,
133 u16 noack_map)
134{
135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
136
137 sdata->noack_map = noack_map;
138 return 0;
139}
140
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100141static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200142 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100143 struct key_params *params)
144{
Johannes Berg26a58452010-08-27 12:35:55 +0200145 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200146 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100147 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200148 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100149 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200150 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100151
Johannes Berg26a58452010-08-27 12:35:55 +0200152 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200153 return -ENETDOWN;
154
Johannes Berg97359d12010-08-10 09:46:38 +0200155 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100156 switch (params->cipher) {
157 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100158 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200159 case WLAN_CIPHER_SUITE_WEP104:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200160 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg97359d12010-08-10 09:46:38 +0200161 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200162 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200163 case WLAN_CIPHER_SUITE_CCMP:
164 case WLAN_CIPHER_SUITE_AES_CMAC:
165 case WLAN_CIPHER_SUITE_GCMP:
166 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100167 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200168 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200169 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100170 }
171
Johannes Berg97359d12010-08-10 09:46:38 +0200172 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200173 params->key, params->seq_len, params->seq,
174 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100175 if (IS_ERR(key))
176 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100177
Johannes Berge31b8212010-10-05 19:39:30 +0200178 if (pairwise)
179 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
180
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200181 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200182
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100183 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700184 if (ieee80211_vif_is_mesh(&sdata->vif))
185 sta = sta_info_get(sdata, mac_addr);
186 else
187 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100188 /*
189 * The ASSOC test makes sure the driver is ready to
190 * receive the key. When wpa_supplicant has roamed
191 * using FT, it attempts to set the key before
192 * association has completed, this rejects that attempt
193 * so it will set the key again after assocation.
194 *
195 * TODO: accept the key if we have a station entry and
196 * add it to the device after the station.
197 */
198 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100199 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200200 err = -ENOENT;
201 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100202 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100203 }
204
Johannes Berge548c492012-09-04 17:08:23 +0200205 switch (sdata->vif.type) {
206 case NL80211_IFTYPE_STATION:
207 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
208 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
209 break;
210 case NL80211_IFTYPE_AP:
211 case NL80211_IFTYPE_AP_VLAN:
212 /* Keys without a station are used for TX only */
213 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
214 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
215 break;
216 case NL80211_IFTYPE_ADHOC:
217 /* no MFP (yet) */
218 break;
219 case NL80211_IFTYPE_MESH_POINT:
220#ifdef CONFIG_MAC80211_MESH
221 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
222 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
223 break;
224#endif
225 case NL80211_IFTYPE_WDS:
226 case NL80211_IFTYPE_MONITOR:
227 case NL80211_IFTYPE_P2P_DEVICE:
228 case NL80211_IFTYPE_UNSPECIFIED:
229 case NUM_NL80211_IFTYPES:
230 case NL80211_IFTYPE_P2P_CLIENT:
231 case NL80211_IFTYPE_P2P_GO:
232 /* shouldn't happen */
233 WARN_ON_ONCE(1);
234 break;
235 }
236
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200237 if (sta)
238 sta->cipher_scheme = cs;
239
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300240 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100241
Johannes Berg3b967662008-04-08 17:56:52 +0200242 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200243 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200244
245 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100246}
247
248static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200249 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100250{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200251 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
252 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100253 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200254 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100255 int ret;
256
Johannes Berg5c0c3642011-05-12 14:31:49 +0200257 mutex_lock(&local->sta_mtx);
258 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200259
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100260 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200261 ret = -ENOENT;
262
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100263 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100264 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200265 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100266
Johannes Berg5c0c3642011-05-12 14:31:49 +0200267 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200268 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200269 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200270 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200271 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200272 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100273
Johannes Berg5c0c3642011-05-12 14:31:49 +0200274 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200275 ret = -ENOENT;
276 goto out_unlock;
277 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100278
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100279 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100280
Johannes Berg3b967662008-04-08 17:56:52 +0200281 ret = 0;
282 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200283 mutex_unlock(&local->key_mtx);
284 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200285
286 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100287}
288
Johannes Berg62da92f2007-12-19 02:03:31 +0100289static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200290 u8 key_idx, bool pairwise, const u8 *mac_addr,
291 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100292 void (*callback)(void *cookie,
293 struct key_params *params))
294{
Johannes Berg14db74b2008-07-29 13:22:52 +0200295 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100296 struct sta_info *sta = NULL;
297 u8 seq[6] = {0};
298 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200299 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200300 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100301 u32 iv32;
302 u16 iv16;
303 int err = -ENOENT;
304
Johannes Berg14db74b2008-07-29 13:22:52 +0200305 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
306
Johannes Berg3b967662008-04-08 17:56:52 +0200307 rcu_read_lock();
308
Johannes Berg62da92f2007-12-19 02:03:31 +0100309 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100310 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100311 if (!sta)
312 goto out;
313
Max Stepanov354e1592013-12-08 13:30:52 +0200314 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200315 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200316 else if (!pairwise &&
317 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200318 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100319 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200320 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100321
322 if (!key)
323 goto out;
324
325 memset(&params, 0, sizeof(params));
326
Johannes Berg97359d12010-08-10 09:46:38 +0200327 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100328
Johannes Berg97359d12010-08-10 09:46:38 +0200329 switch (key->conf.cipher) {
330 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700331 iv32 = key->u.tkip.tx.iv32;
332 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100333
Johannes Berg24487982009-04-23 18:52:52 +0200334 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
335 drv_get_tkip_seq(sdata->local,
336 key->conf.hw_key_idx,
337 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100338
339 seq[0] = iv16 & 0xff;
340 seq[1] = (iv16 >> 8) & 0xff;
341 seq[2] = iv32 & 0xff;
342 seq[3] = (iv32 >> 8) & 0xff;
343 seq[4] = (iv32 >> 16) & 0xff;
344 seq[5] = (iv32 >> 24) & 0xff;
345 params.seq = seq;
346 params.seq_len = 6;
347 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200348 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200349 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
350 seq[0] = pn64;
351 seq[1] = pn64 >> 8;
352 seq[2] = pn64 >> 16;
353 seq[3] = pn64 >> 24;
354 seq[4] = pn64 >> 32;
355 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100356 params.seq = seq;
357 params.seq_len = 6;
358 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200359 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200360 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
361 seq[0] = pn64;
362 seq[1] = pn64 >> 8;
363 seq[2] = pn64 >> 16;
364 seq[3] = pn64 >> 24;
365 seq[4] = pn64 >> 32;
366 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200367 params.seq = seq;
368 params.seq_len = 6;
369 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100370 }
371
372 params.key = key->conf.key;
373 params.key_len = key->conf.keylen;
374
375 callback(cookie, &params);
376 err = 0;
377
378 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200379 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100380 return err;
381}
382
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100383static int ieee80211_config_default_key(struct wiphy *wiphy,
384 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100385 u8 key_idx, bool uni,
386 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100387{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100389
Johannes Bergf7e01042010-12-09 19:49:02 +0100390 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100391
392 return 0;
393}
394
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200395static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
396 struct net_device *dev,
397 u8 key_idx)
398{
Johannes Berg66c52422010-07-22 13:58:51 +0200399 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200400
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200401 ieee80211_set_default_mgmt_key(sdata, key_idx);
402
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200403 return 0;
404}
405
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800406void sta_set_rate_info_tx(struct sta_info *sta,
407 const struct ieee80211_tx_rate *rate,
408 struct rate_info *rinfo)
409{
410 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100411 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800412 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100413 rinfo->mcs = rate->idx;
414 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
415 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
416 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
417 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
418 } else {
419 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200420 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
421 u16 brate;
422
Johannes Berg8bc83c22012-11-09 18:38:32 +0100423 sband = sta->local->hw.wiphy->bands[
424 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200425 brate = sband->bitrates[rate->idx].bitrate;
426 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100427 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800428 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
429 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100430 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
431 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
432 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
433 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800434 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
435 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800436}
437
Saravana003e6762012-11-28 18:29:38 +0530438void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
439{
440 rinfo->flags = 0;
441
442 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
443 rinfo->flags |= RATE_INFO_FLAGS_MCS;
444 rinfo->mcs = sta->last_rx_rate_idx;
445 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
446 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
447 rinfo->nss = sta->last_rx_rate_vht_nss;
448 rinfo->mcs = sta->last_rx_rate_idx;
449 } else {
450 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200451 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
452 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530453
454 sband = sta->local->hw.wiphy->bands[
455 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200456 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
457 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530458 }
459
460 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
461 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
462 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
463 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200464 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530465 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200466 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80P80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530467 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200468 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
Saravana003e6762012-11-28 18:29:38 +0530469 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
470}
471
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100472static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200473 int idx, u8 *mac, struct station_info *sinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100474{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100475 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300476 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100477 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100478 int ret = -ENOENT;
479
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300480 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100481
Johannes Berg3b53fde82009-11-16 12:00:37 +0100482 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100483 if (sta) {
484 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200485 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100486 sta_set_sinfo(sta, sinfo);
487 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100488
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300489 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100490
Johannes Bergd0709a62008-02-25 16:27:46 +0100491 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100492}
493
Holger Schurig12897232010-04-19 10:23:57 +0200494static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
495 int idx, struct survey_info *survey)
496{
497 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
498
Holger Schurig12897232010-04-19 10:23:57 +0200499 return drv_get_survey(local, idx, survey);
500}
501
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100502static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +0200503 const u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100504{
Johannes Bergabe60632009-11-25 17:46:18 +0100505 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300506 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100507 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100508 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100509
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300510 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100511
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100512 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100513 if (sta) {
514 ret = 0;
515 sta_set_sinfo(sta, sinfo);
516 }
517
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300518 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100519
520 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100521}
522
Johannes Berge8c9bd52012-06-06 08:18:22 +0200523static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100524 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200525{
Johannes Berg55de9082012-07-26 17:24:39 +0200526 struct ieee80211_local *local = wiphy_priv(wiphy);
527 struct ieee80211_sub_if_data *sdata;
528 int ret = 0;
529
Johannes Berg4bf88532012-11-09 11:39:59 +0100530 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200531 return 0;
532
Johannes Berg34a37402013-12-18 09:43:33 +0100533 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200534 mutex_lock(&local->iflist_mtx);
535 if (local->use_chanctx) {
536 sdata = rcu_dereference_protected(
537 local->monitor_sdata,
538 lockdep_is_held(&local->iflist_mtx));
539 if (sdata) {
540 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100541 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200542 IEEE80211_CHANCTX_EXCLUSIVE);
543 }
544 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100545 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200546 ieee80211_hw_config(local, 0);
547 }
548
Johannes Berg4bf88532012-11-09 11:39:59 +0100549 if (ret == 0)
550 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200551 mutex_unlock(&local->iflist_mtx);
Johannes Berg34a37402013-12-18 09:43:33 +0100552 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200553
554 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200555}
556
Arik Nemtsov02945822011-11-10 11:28:57 +0200557static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200558 const u8 *resp, size_t resp_len,
559 const struct ieee80211_csa_settings *csa)
Arik Nemtsov02945822011-11-10 11:28:57 +0200560{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300561 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200562
563 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530564 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200565
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100566 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200567
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300568 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200569 if (!new)
570 return -ENOMEM;
571
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300572 new->len = resp_len;
573 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200574
Michal Kazioraf296bd2014-06-05 14:21:36 +0200575 if (csa)
576 memcpy(new->csa_counter_offsets, csa->counter_offsets_presp,
577 csa->n_counter_offsets_presp *
578 sizeof(new->csa_counter_offsets[0]));
579
Arik Nemtsov02945822011-11-10 11:28:57 +0200580 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300581 if (old)
582 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200583
584 return 0;
585}
586
Luciano Coelho0ae07962013-12-08 09:42:25 +0200587static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200588 struct cfg80211_beacon_data *params,
589 const struct ieee80211_csa_settings *csa)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100590{
591 struct beacon_data *new, *old;
592 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100593 int size, err;
594 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100595
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100596 old = sdata_dereference(sdata->u.ap.beacon, sdata);
597
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100598
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100599 /* Need to have a beacon head if we don't have one yet */
600 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100601 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100602
603 /* new or old head? */
604 if (params->head)
605 new_head_len = params->head_len;
606 else
607 new_head_len = old->head_len;
608
609 /* new or old tail? */
610 if (params->tail || !old)
611 /* params->tail_len will be zero for !params->tail */
612 new_tail_len = params->tail_len;
613 else
614 new_tail_len = old->tail_len;
615
616 size = sizeof(*new) + new_head_len + new_tail_len;
617
618 new = kzalloc(size, GFP_KERNEL);
619 if (!new)
620 return -ENOMEM;
621
622 /* start filling the new info now */
623
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100624 /*
625 * pointers go into the block we allocated,
626 * memory is | beacon_data | head | tail |
627 */
628 new->head = ((u8 *) new) + sizeof(*new);
629 new->tail = new->head + new_head_len;
630 new->head_len = new_head_len;
631 new->tail_len = new_tail_len;
632
Michal Kazioraf296bd2014-06-05 14:21:36 +0200633 if (csa) {
634 new->csa_current_counter = csa->count;
635 memcpy(new->csa_counter_offsets, csa->counter_offsets_beacon,
636 csa->n_counter_offsets_beacon *
637 sizeof(new->csa_counter_offsets[0]));
638 }
639
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100640 /* copy in head */
641 if (params->head)
642 memcpy(new->head, params->head, new_head_len);
643 else
644 memcpy(new->head, old->head, new_head_len);
645
646 /* copy in optional tail */
647 if (params->tail)
648 memcpy(new->tail, params->tail, new_tail_len);
649 else
650 if (old)
651 memcpy(new->tail, old->tail, new_tail_len);
652
Johannes Berg88600202012-02-13 15:17:18 +0100653 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
Michal Kazioraf296bd2014-06-05 14:21:36 +0200654 params->probe_resp_len, csa);
Johannes Berg88600202012-02-13 15:17:18 +0100655 if (err < 0)
656 return err;
657 if (err == 0)
658 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100659
Eric Dumazetcf778b02012-01-12 04:41:32 +0000660 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100661
Johannes Berg88600202012-02-13 15:17:18 +0100662 if (old)
663 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100664
Johannes Berg88600202012-02-13 15:17:18 +0100665 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100666}
667
Johannes Berg88600202012-02-13 15:17:18 +0100668static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
669 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100670{
Johannes Berg88600202012-02-13 15:17:18 +0100671 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100672 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100673 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100674 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100675 u32 changed = BSS_CHANGED_BEACON_INT |
676 BSS_CHANGED_BEACON_ENABLED |
677 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100678 BSS_CHANGED_SSID |
679 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100680 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200681
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100682 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100683 if (old)
684 return -EALREADY;
685
Johannes Berg04ecd252012-09-11 14:34:12 +0200686 /* TODO: make hostapd tell us what it wants */
687 sdata->smps_mode = IEEE80211_SMPS_OFF;
688 sdata->needed_rx_chains = sdata->local->rx_chains;
689
Johannes Berg34a37402013-12-18 09:43:33 +0100690 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100691 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200692 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100693 if (!err)
694 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100695 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200696 if (err)
697 return err;
698
Johannes Berg665c93a2011-11-04 11:18:11 +0100699 /*
700 * Apply control port protocol, this allows us to
701 * not encrypt dynamic WEP control frames.
702 */
703 sdata->control_port_protocol = params->crypto.control_port_ethertype;
704 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200705 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
706 &params->crypto,
707 sdata->vif.type);
708
Johannes Berg665c93a2011-11-04 11:18:11 +0100709 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
710 vlan->control_port_protocol =
711 params->crypto.control_port_ethertype;
712 vlan->control_port_no_encrypt =
713 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200714 vlan->encrypt_headroom =
715 ieee80211_cs_headroom(sdata->local,
716 &params->crypto,
717 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +0100718 }
719
Johannes Berg88600202012-02-13 15:17:18 +0100720 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
721 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100722 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100723
724 sdata->vif.bss_conf.ssid_len = params->ssid_len;
725 if (params->ssid_len)
726 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
727 params->ssid_len);
728 sdata->vif.bss_conf.hidden_ssid =
729 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
730
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100731 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
732 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
733 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
734 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
735 if (params->p2p_opp_ps)
736 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
737 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100738
Michal Kazioraf296bd2014-06-05 14:21:36 +0200739 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200740 if (err < 0) {
741 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100742 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200743 }
Johannes Berg88600202012-02-13 15:17:18 +0100744 changed |= err;
745
Johannes Berg10416382012-10-19 15:44:42 +0200746 err = drv_start_ap(sdata->local, sdata);
747 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100748 old = sdata_dereference(sdata->u.ap.beacon, sdata);
749
Johannes Berg10416382012-10-19 15:44:42 +0200750 if (old)
751 kfree_rcu(old, rcu_head);
752 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200753 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +0200754 return err;
755 }
756
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800757 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100758 ieee80211_bss_info_change_notify(sdata, changed);
759
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200760 netif_carrier_on(dev);
761 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
762 netif_carrier_on(vlan->dev);
763
Johannes Berg665c93a2011-11-04 11:18:11 +0100764 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100765}
766
Johannes Berg88600202012-02-13 15:17:18 +0100767static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
768 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100769{
Johannes Berg14db74b2008-07-29 13:22:52 +0200770 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100771 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100772 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100773
Johannes Berg14db74b2008-07-29 13:22:52 +0200774 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +0100775 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +0200776
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200777 /* don't allow changing the beacon while CSA is in place - offset
778 * of channel switch counter may change
779 */
780 if (sdata->vif.csa_active)
781 return -EBUSY;
782
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100783 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100784 if (!old)
785 return -ENOENT;
786
Michal Kazioraf296bd2014-06-05 14:21:36 +0200787 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100788 if (err < 0)
789 return err;
790 ieee80211_bss_info_change_notify(sdata, err);
791 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100792}
793
Johannes Berg88600202012-02-13 15:17:18 +0100794static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100795{
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200796 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
797 struct ieee80211_sub_if_data *vlan;
798 struct ieee80211_local *local = sdata->local;
799 struct beacon_data *old_beacon;
800 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100801 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100802
Michal Kaziordbd72852014-01-29 07:56:21 +0100803 sdata_assert_lock(sdata);
804
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100805 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200806 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100807 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100808 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100809
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200810 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +0200811 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200812 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +0300813 if (sdata->csa_block_tx) {
814 ieee80211_wake_vif_queues(local, sdata,
815 IEEE80211_QUEUE_STOP_REASON_CSA);
816 sdata->csa_block_tx = false;
817 }
818
Michal Kazior59af6922014-04-09 15:10:59 +0200819 mutex_unlock(&local->mtx);
820
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +0100821 kfree(sdata->u.ap.next_beacon);
822 sdata->u.ap.next_beacon = NULL;
823
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200824 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200825 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
826 netif_carrier_off(vlan->dev);
827 netif_carrier_off(dev);
828
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200829 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000830 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200831 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
832 kfree_rcu(old_beacon, rcu_head);
833 if (old_probe_resp)
834 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +0200835 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +0100836
Johannes Berge7162512013-12-04 23:18:37 +0100837 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +0100838 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +0100839
Johannes Bergd6a83222012-12-14 14:06:28 +0100840 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +0200841 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +0100842 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200843 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100844
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200845 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100846 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200847 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100848 cfg80211_cac_event(sdata->dev, &chandef,
849 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200850 GFP_KERNEL);
851 }
852
Johannes Berg10416382012-10-19 15:44:42 +0200853 drv_stop_ap(sdata->local, sdata);
854
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200855 /* free all potentially still buffered bcast frames */
856 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
857 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
858
Johannes Berg34a37402013-12-18 09:43:33 +0100859 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +0100860 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +0200861 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +0100862 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200863
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200864 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100865}
866
Johannes Berg4fd69312007-12-19 02:03:35 +0100867/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
868struct iapp_layer2_update {
869 u8 da[ETH_ALEN]; /* broadcast */
870 u8 sa[ETH_ALEN]; /* STA addr */
871 __be16 len; /* 6 */
872 u8 dsap; /* 0 */
873 u8 ssap; /* 0 */
874 u8 control;
875 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700876} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100877
878static void ieee80211_send_layer2_update(struct sta_info *sta)
879{
880 struct iapp_layer2_update *msg;
881 struct sk_buff *skb;
882
883 /* Send Level 2 Update Frame to update forwarding tables in layer 2
884 * bridge devices */
885
886 skb = dev_alloc_skb(sizeof(*msg));
887 if (!skb)
888 return;
889 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
890
891 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
892 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
893
Johannes Berge83e6542012-07-13 16:23:07 +0200894 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200895 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100896 msg->len = htons(6);
897 msg->dsap = 0;
898 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
899 msg->control = 0xaf; /* XID response lsb.1111F101.
900 * F=0 (no poll command; unsolicited frame) */
901 msg->xid_info[0] = 0x81; /* XID format identifier */
902 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
903 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
904
Johannes Bergd0709a62008-02-25 16:27:46 +0100905 skb->dev = sta->sdata->dev;
906 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100907 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400908 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100909}
910
Johannes Bergd582cff2012-10-26 17:53:44 +0200911static int sta_apply_auth_flags(struct ieee80211_local *local,
912 struct sta_info *sta,
913 u32 mask, u32 set)
914{
915 int ret;
916
917 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
918 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
919 !test_sta_flag(sta, WLAN_STA_AUTH)) {
920 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
921 if (ret)
922 return ret;
923 }
924
925 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
926 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
927 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
928 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
929 if (ret)
930 return ret;
931 }
932
933 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
934 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
935 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
936 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
937 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
938 else
939 ret = 0;
940 if (ret)
941 return ret;
942 }
943
944 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
945 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
946 test_sta_flag(sta, WLAN_STA_ASSOC)) {
947 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
948 if (ret)
949 return ret;
950 }
951
952 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
953 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
954 test_sta_flag(sta, WLAN_STA_AUTH)) {
955 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
956 if (ret)
957 return ret;
958 }
959
960 return 0;
961}
962
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100963static int sta_apply_parameters(struct ieee80211_local *local,
964 struct sta_info *sta,
965 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100966{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100967 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100968 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100969 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +0200970 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300971 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100972
Johannes Berg55de9082012-07-26 17:24:39 +0200973 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +0200974
Johannes Bergeccb8e82009-05-11 21:57:56 +0300975 mask = params->sta_flags_mask;
976 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100977
Johannes Bergd582cff2012-10-26 17:53:44 +0200978 if (ieee80211_vif_is_mesh(&sdata->vif)) {
979 /*
980 * In mesh mode, ASSOCIATED isn't part of the nl80211
981 * API but must follow AUTHENTICATED for driver state.
982 */
983 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
984 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
985 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
986 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +0100987 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
988 /*
989 * TDLS -- everything follows authorized, but
990 * only becoming authorized is possible, not
991 * going back
992 */
993 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
994 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
995 BIT(NL80211_STA_FLAG_ASSOCIATED);
996 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
997 BIT(NL80211_STA_FLAG_ASSOCIATED);
998 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100999 }
1000
Arik Nemtsov68885a52014-06-11 17:18:19 +03001001 /* auth flags will be set later for TDLS stations */
1002 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1003 ret = sta_apply_auth_flags(local, sta, mask, set);
1004 if (ret)
1005 return ret;
1006 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001007
Johannes Bergeccb8e82009-05-11 21:57:56 +03001008 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001009 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001010 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1011 else
1012 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001013 }
1014
Johannes Berga74a8c82014-07-22 14:50:47 +02001015 if (mask & BIT(NL80211_STA_FLAG_WME))
1016 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001017
1018 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001019 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001020 set_sta_flag(sta, WLAN_STA_MFP);
1021 else
1022 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001023 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001024
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001025 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001026 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001027 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1028 else
1029 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001030 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001031
Johannes Berg3b9ce802011-09-27 20:56:12 +02001032 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1033 sta->sta.uapsd_queues = params->uapsd_queues;
1034 sta->sta.max_sp = params->max_sp;
1035 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001036
Johannes Berg73651ee2008-02-25 16:27:47 +01001037 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001038 * cfg80211 validates this (1-2007) and allows setting the AID
1039 * only when creating a new station entry
1040 */
1041 if (params->aid)
1042 sta->sta.aid = params->aid;
1043
1044 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001045 * Some of the following updates would be racy if called on an
1046 * existing station, via ieee80211_change_station(). However,
1047 * all such changes are rejected by cfg80211 except for updates
1048 * changing the supported rates on an existing but not yet used
1049 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001050 */
1051
Johannes Berg4fd69312007-12-19 02:03:35 +01001052 if (params->listen_interval >= 0)
1053 sta->listen_interval = params->listen_interval;
1054
1055 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001056 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1057 sband, params->supported_rates,
1058 params->supported_rates_len,
1059 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001060 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001061
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001062 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001063 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001064 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001065
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001066 if (params->vht_capa)
1067 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001068 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001069
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001070 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001071 /* returned value is only needed for rc update, but the
1072 * rc isn't initialized here yet, so ignore it
1073 */
1074 __ieee80211_vht_handle_opmode(sdata, sta,
1075 params->opmode_notif,
1076 band, false);
1077 }
1078
Javier Cardona9c3990a2011-05-03 16:57:11 -07001079 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001080#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001081 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001082
1083 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001084 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001085 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001086 if (sta->plink_state != NL80211_PLINK_ESTAB)
1087 changed = mesh_plink_inc_estab_count(
1088 sdata);
1089 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001090
1091 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001092 changed |= ieee80211_mps_set_sta_local_pm(sta,
1093 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001094 break;
1095 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001096 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001097 case NL80211_PLINK_OPN_SNT:
1098 case NL80211_PLINK_OPN_RCVD:
1099 case NL80211_PLINK_CNF_RCVD:
1100 case NL80211_PLINK_HOLDING:
1101 if (sta->plink_state == NL80211_PLINK_ESTAB)
1102 changed = mesh_plink_dec_estab_count(
1103 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001104 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001105
1106 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001107 changed |= ieee80211_mps_set_sta_local_pm(sta,
1108 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001109 break;
1110 default:
1111 /* nothing */
1112 break;
1113 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001114 }
1115
1116 switch (params->plink_action) {
1117 case NL80211_PLINK_ACTION_NO_ACTION:
1118 /* nothing */
1119 break;
1120 case NL80211_PLINK_ACTION_OPEN:
1121 changed |= mesh_plink_open(sta);
1122 break;
1123 case NL80211_PLINK_ACTION_BLOCK:
1124 changed |= mesh_plink_block(sta);
1125 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001126 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001127
1128 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001129 changed |=
1130 ieee80211_mps_set_sta_local_pm(sta,
1131 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001132 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001133#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001134 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001135
Arik Nemtsov68885a52014-06-11 17:18:19 +03001136 /* set the STA state after all sta info from usermode has been set */
1137 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1138 ret = sta_apply_auth_flags(local, sta, mask, set);
1139 if (ret)
1140 return ret;
1141 }
1142
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001143 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001144}
1145
1146static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001147 const u8 *mac,
1148 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001149{
Johannes Berg14db74b2008-07-29 13:22:52 +02001150 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001151 struct sta_info *sta;
1152 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001153 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001154 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001155
Johannes Berg4fd69312007-12-19 02:03:35 +01001156 if (params->vlan) {
1157 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1158
Johannes Berg05c914f2008-09-11 00:01:58 +02001159 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1160 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001161 return -EINVAL;
1162 } else
1163 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1164
Joe Perchesb203ca32012-05-08 18:56:52 +00001165 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001166 return -EINVAL;
1167
1168 if (is_multicast_ether_addr(mac))
1169 return -EINVAL;
1170
1171 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001172 if (!sta)
1173 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001174
Johannes Bergd582cff2012-10-26 17:53:44 +02001175 /*
1176 * defaults -- if userspace wants something else we'll
1177 * change it accordingly in sta_apply_parameters()
1178 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001179 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1180 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1181 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001182 } else {
1183 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001184 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001185
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001186 err = sta_apply_parameters(local, sta, params);
1187 if (err) {
1188 sta_info_free(local, sta);
1189 return err;
1190 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001191
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001192 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001193 * for TDLS, rate control should be initialized only when
1194 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001195 */
1196 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1197 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001198
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001199 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1200 sdata->vif.type == NL80211_IFTYPE_AP;
1201
Johannes Berg34e89502010-02-03 13:59:58 +01001202 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001203 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001204 rcu_read_unlock();
1205 return err;
1206 }
1207
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001208 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001209 ieee80211_send_layer2_update(sta);
1210
1211 rcu_read_unlock();
1212
Johannes Berg4fd69312007-12-19 02:03:35 +01001213 return 0;
1214}
1215
1216static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001217 const u8 *mac)
Johannes Berg4fd69312007-12-19 02:03:35 +01001218{
Johannes Berg14db74b2008-07-29 13:22:52 +02001219 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001220
Johannes Berg14db74b2008-07-29 13:22:52 +02001221 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1222
Johannes Berg34e89502010-02-03 13:59:58 +01001223 if (mac)
1224 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001225
Johannes Bergb998e8b2012-12-13 23:07:46 +01001226 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001227 return 0;
1228}
1229
1230static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001231 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001232 struct station_parameters *params)
1233{
Johannes Bergabe60632009-11-25 17:46:18 +01001234 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001235 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001236 struct sta_info *sta;
1237 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001238 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001239 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001240
Johannes Berg87be1e12011-12-14 12:20:29 +01001241 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001242
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001243 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001244 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001245 err = -ENOENT;
1246 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001247 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001248
Johannes Berg77ee7c82013-02-15 00:48:33 +01001249 switch (sdata->vif.type) {
1250 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001251 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001252 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001253 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001254 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001255 break;
1256 case NL80211_IFTYPE_ADHOC:
1257 statype = CFG80211_STA_IBSS;
1258 break;
1259 case NL80211_IFTYPE_STATION:
1260 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1261 statype = CFG80211_STA_AP_STA;
1262 break;
1263 }
1264 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1265 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1266 else
1267 statype = CFG80211_STA_TDLS_PEER_SETUP;
1268 break;
1269 case NL80211_IFTYPE_AP:
1270 case NL80211_IFTYPE_AP_VLAN:
1271 statype = CFG80211_STA_AP_CLIENT;
1272 break;
1273 default:
1274 err = -EOPNOTSUPP;
1275 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001276 }
1277
Johannes Berg77ee7c82013-02-15 00:48:33 +01001278 err = cfg80211_check_station_change(wiphy, params, statype);
1279 if (err)
1280 goto out_err;
1281
Johannes Bergd0709a62008-02-25 16:27:46 +01001282 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001283 bool prev_4addr = false;
1284 bool new_4addr = false;
1285
Johannes Berg4fd69312007-12-19 02:03:35 +01001286 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1287
Johannes Berg9bc383d2009-11-19 11:55:19 +01001288 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001289 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001290 err = -EBUSY;
1291 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001292 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001293
Eric Dumazetcf778b02012-01-12 04:41:32 +00001294 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001295 new_4addr = true;
1296 }
1297
1298 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1299 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301300 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001301 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001302 }
1303
Johannes Berg14db74b2008-07-29 13:22:52 +02001304 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001305
1306 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1307 prev_4addr != new_4addr) {
1308 if (new_4addr)
1309 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1310 else
1311 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1312 }
1313
Johannes Berg4fd69312007-12-19 02:03:35 +01001314 ieee80211_send_layer2_update(sta);
1315 }
1316
Eliad Peller35b88622011-12-29 14:41:39 +02001317 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001318 if (err)
1319 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001320
Johannes Berg77ee7c82013-02-15 00:48:33 +01001321 /* When peer becomes authorized, init rate control as well */
1322 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1323 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001324 rate_control_rate_init(sta);
1325
Johannes Berg87be1e12011-12-14 12:20:29 +01001326 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001327
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001328 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1329 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1330 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1331 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1332 sta_info_tx_streams(sta) != 1) {
1333 ht_dbg(sta->sdata,
1334 "%pM just authorized and MIMO capable - update SMPS\n",
1335 sta->sta.addr);
1336 ieee80211_send_smps_action(sta->sdata,
1337 sta->sdata->bss->req_smps,
1338 sta->sta.addr,
1339 sta->sdata->vif.bss_conf.bssid);
1340 }
1341
Jason Young808118c2011-03-10 16:43:19 -08001342 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001343 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001344 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001345 ieee80211_recalc_ps_vif(sdata);
1346 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001347
Johannes Berg4fd69312007-12-19 02:03:35 +01001348 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001349out_err:
1350 mutex_unlock(&local->sta_mtx);
1351 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001352}
1353
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001354#ifdef CONFIG_MAC80211_MESH
1355static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001356 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001357{
Johannes Berg14db74b2008-07-29 13:22:52 +02001358 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001359 struct mesh_path *mpath;
1360 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001361
Johannes Berg14db74b2008-07-29 13:22:52 +02001362 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1363
Johannes Bergd0709a62008-02-25 16:27:46 +01001364 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001365 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001366 if (!sta) {
1367 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001368 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001369 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001370
Bob Copelandae76eef2013-03-29 09:38:39 -04001371 mpath = mesh_path_add(sdata, dst);
1372 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001373 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001374 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001375 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001376
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001377 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001378
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001379 rcu_read_unlock();
1380 return 0;
1381}
1382
1383static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001384 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001385{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001386 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001387
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001388 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001389 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001390
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001391 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001392 return 0;
1393}
1394
Johannes Berg3b3a0162014-05-19 17:19:31 +02001395static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1396 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001397{
Johannes Berg14db74b2008-07-29 13:22:52 +02001398 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001399 struct mesh_path *mpath;
1400 struct sta_info *sta;
1401
Johannes Berg14db74b2008-07-29 13:22:52 +02001402 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1403
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001404 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001405
Johannes Bergabe60632009-11-25 17:46:18 +01001406 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001407 if (!sta) {
1408 rcu_read_unlock();
1409 return -ENOENT;
1410 }
1411
Johannes Bergbf7cd942013-02-15 14:40:31 +01001412 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001413 if (!mpath) {
1414 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001415 return -ENOENT;
1416 }
1417
1418 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001419
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001420 rcu_read_unlock();
1421 return 0;
1422}
1423
1424static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1425 struct mpath_info *pinfo)
1426{
Johannes Berga3836e02011-05-12 15:11:37 +02001427 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1428
1429 if (next_hop_sta)
1430 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001431 else
1432 memset(next_hop, 0, ETH_ALEN);
1433
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001434 memset(pinfo, 0, sizeof(*pinfo));
1435
Johannes Bergf5ea9122009-08-07 16:17:38 +02001436 pinfo->generation = mesh_paths_generation;
1437
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001438 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001439 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001440 MPATH_INFO_METRIC |
1441 MPATH_INFO_EXPTIME |
1442 MPATH_INFO_DISCOVERY_TIMEOUT |
1443 MPATH_INFO_DISCOVERY_RETRIES |
1444 MPATH_INFO_FLAGS;
1445
1446 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001447 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001448 pinfo->metric = mpath->metric;
1449 if (time_before(jiffies, mpath->exp_time))
1450 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1451 pinfo->discovery_timeout =
1452 jiffies_to_msecs(mpath->discovery_timeout);
1453 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001454 if (mpath->flags & MESH_PATH_ACTIVE)
1455 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1456 if (mpath->flags & MESH_PATH_RESOLVING)
1457 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001458 if (mpath->flags & MESH_PATH_SN_VALID)
1459 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001460 if (mpath->flags & MESH_PATH_FIXED)
1461 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001462 if (mpath->flags & MESH_PATH_RESOLVED)
1463 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001464}
1465
1466static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1467 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1468
1469{
Johannes Berg14db74b2008-07-29 13:22:52 +02001470 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001471 struct mesh_path *mpath;
1472
Johannes Berg14db74b2008-07-29 13:22:52 +02001473 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1474
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001475 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001476 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001477 if (!mpath) {
1478 rcu_read_unlock();
1479 return -ENOENT;
1480 }
1481 memcpy(dst, mpath->dst, ETH_ALEN);
1482 mpath_set_pinfo(mpath, next_hop, pinfo);
1483 rcu_read_unlock();
1484 return 0;
1485}
1486
1487static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001488 int idx, u8 *dst, u8 *next_hop,
1489 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001490{
Johannes Berg14db74b2008-07-29 13:22:52 +02001491 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001492 struct mesh_path *mpath;
1493
Johannes Berg14db74b2008-07-29 13:22:52 +02001494 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1495
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001496 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001497 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001498 if (!mpath) {
1499 rcu_read_unlock();
1500 return -ENOENT;
1501 }
1502 memcpy(dst, mpath->dst, ETH_ALEN);
1503 mpath_set_pinfo(mpath, next_hop, pinfo);
1504 rcu_read_unlock();
1505 return 0;
1506}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001507
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001508static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001509 struct net_device *dev,
1510 struct mesh_config *conf)
1511{
1512 struct ieee80211_sub_if_data *sdata;
1513 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1514
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001515 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1516 return 0;
1517}
1518
1519static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1520{
1521 return (mask >> (parm-1)) & 0x1;
1522}
1523
Javier Cardonac80d5452010-12-16 17:37:49 -08001524static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1525 const struct mesh_setup *setup)
1526{
1527 u8 *new_ie;
1528 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001529 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1530 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001531
Javier Cardona581a8b02011-04-07 15:08:27 -07001532 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001533 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001534 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001535
Javier Cardona581a8b02011-04-07 15:08:27 -07001536 if (setup->ie_len) {
1537 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001538 GFP_KERNEL);
1539 if (!new_ie)
1540 return -ENOMEM;
1541 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001542 ifmsh->ie_len = setup->ie_len;
1543 ifmsh->ie = new_ie;
1544 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001545
1546 /* now copy the rest of the setup parameters */
1547 ifmsh->mesh_id_len = setup->mesh_id_len;
1548 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001549 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001550 ifmsh->mesh_pp_id = setup->path_sel_proto;
1551 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001552 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001553 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001554 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1555 if (setup->is_authenticated)
1556 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1557 if (setup->is_secure)
1558 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001559
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001560 /* mcast rate setting in Mesh Node */
1561 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1562 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001563 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001564
Marco Porsch9bdbf042013-01-07 16:04:51 +01001565 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1566 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1567
Javier Cardonac80d5452010-12-16 17:37:49 -08001568 return 0;
1569}
1570
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001571static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001572 struct net_device *dev, u32 mask,
1573 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001574{
1575 struct mesh_config *conf;
1576 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001577 struct ieee80211_if_mesh *ifmsh;
1578
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001579 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001580 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001581
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001582 /* Set the config options which we are interested in setting */
1583 conf = &(sdata->u.mesh.mshcfg);
1584 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1585 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1586 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1587 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1588 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1589 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1590 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1591 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1592 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1593 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1594 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1595 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001596 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001597 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001598 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1599 if (ifmsh->user_mpm)
1600 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001601 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001602 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001603 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1604 conf->dot11MeshNbrOffsetMaxNeighbor =
1605 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001606 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1607 conf->dot11MeshHWMPmaxPREQretries =
1608 nconf->dot11MeshHWMPmaxPREQretries;
1609 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1610 conf->path_refresh_time = nconf->path_refresh_time;
1611 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1612 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1613 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1614 conf->dot11MeshHWMPactivePathTimeout =
1615 nconf->dot11MeshHWMPactivePathTimeout;
1616 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1617 conf->dot11MeshHWMPpreqMinInterval =
1618 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001619 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1620 conf->dot11MeshHWMPperrMinInterval =
1621 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001622 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1623 mask))
1624 conf->dot11MeshHWMPnetDiameterTraversalTime =
1625 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001626 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1627 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1628 ieee80211_mesh_root_setup(ifmsh);
1629 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001630 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001631 /* our current gate announcement implementation rides on root
1632 * announcements, so require this ifmsh to also be a root node
1633 * */
1634 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001635 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1636 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001637 ieee80211_mesh_root_setup(ifmsh);
1638 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001639 conf->dot11MeshGateAnnouncementProtocol =
1640 nconf->dot11MeshGateAnnouncementProtocol;
1641 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001642 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001643 conf->dot11MeshHWMPRannInterval =
1644 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001645 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1646 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001647 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1648 /* our RSSI threshold implementation is supported only for
1649 * devices that report signal in dBm.
1650 */
1651 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1652 return -ENOTSUPP;
1653 conf->rssi_threshold = nconf->rssi_threshold;
1654 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001655 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1656 conf->ht_opmode = nconf->ht_opmode;
1657 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1658 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1659 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001660 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1661 conf->dot11MeshHWMPactivePathToRootTimeout =
1662 nconf->dot11MeshHWMPactivePathToRootTimeout;
1663 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1664 conf->dot11MeshHWMProotInterval =
1665 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001666 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1667 conf->dot11MeshHWMPconfirmationInterval =
1668 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001669 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1670 conf->power_mode = nconf->power_mode;
1671 ieee80211_mps_local_status_update(sdata);
1672 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001673 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001674 conf->dot11MeshAwakeWindowDuration =
1675 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001676 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1677 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001678 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001679 return 0;
1680}
1681
Johannes Berg29cbe682010-12-03 09:20:44 +01001682static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1683 const struct mesh_config *conf,
1684 const struct mesh_setup *setup)
1685{
1686 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1687 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001688 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001689
Javier Cardonac80d5452010-12-16 17:37:49 -08001690 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1691 err = copy_mesh_setup(ifmsh, setup);
1692 if (err)
1693 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001694
Johannes Berg04ecd252012-09-11 14:34:12 +02001695 /* can mesh use other SMPS modes? */
1696 sdata->smps_mode = IEEE80211_SMPS_OFF;
1697 sdata->needed_rx_chains = sdata->local->rx_chains;
1698
Johannes Berg34a37402013-12-18 09:43:33 +01001699 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001700 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001701 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01001702 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001703 if (err)
1704 return err;
1705
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001706 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001707}
1708
1709static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1710{
1711 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1712
1713 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001714 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001715 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001716 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01001717
1718 return 0;
1719}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001720#endif
1721
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001722static int ieee80211_change_bss(struct wiphy *wiphy,
1723 struct net_device *dev,
1724 struct bss_parameters *params)
1725{
Johannes Berg55de9082012-07-26 17:24:39 +02001726 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1727 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001728 u32 changed = 0;
1729
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001730 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02001731 return -ENOENT;
1732
1733 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001734
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001735 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001736 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001737 changed |= BSS_CHANGED_ERP_CTS_PROT;
1738 }
1739 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001740 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001741 params->use_short_preamble;
1742 changed |= BSS_CHANGED_ERP_PREAMBLE;
1743 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001744
1745 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001746 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001747 sdata->vif.bss_conf.use_short_slot = true;
1748 changed |= BSS_CHANGED_ERP_SLOT;
1749 }
1750
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001751 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001752 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001753 params->use_short_slot_time;
1754 changed |= BSS_CHANGED_ERP_SLOT;
1755 }
1756
Jouni Malinen90c97a02008-10-30 16:59:22 +02001757 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001758 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1759 wiphy->bands[band],
1760 params->basic_rates,
1761 params->basic_rates_len,
1762 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001763 changed |= BSS_CHANGED_BASIC_RATES;
1764 }
1765
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001766 if (params->ap_isolate >= 0) {
1767 if (params->ap_isolate)
1768 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1769 else
1770 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1771 }
1772
Helmut Schaa80d7e402010-11-19 12:40:26 +01001773 if (params->ht_opmode >= 0) {
1774 sdata->vif.bss_conf.ht_operation_mode =
1775 (u16) params->ht_opmode;
1776 changed |= BSS_CHANGED_HT;
1777 }
1778
Johannes Berg339afbf2012-11-14 15:21:17 +01001779 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001780 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1781 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1782 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1783 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001784 changed |= BSS_CHANGED_P2P_PS;
1785 }
1786
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001787 if (params->p2p_opp_ps > 0) {
1788 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1789 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1790 changed |= BSS_CHANGED_P2P_PS;
1791 } else if (params->p2p_opp_ps == 0) {
1792 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1793 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001794 changed |= BSS_CHANGED_P2P_PS;
1795 }
1796
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001797 ieee80211_bss_info_change_notify(sdata, changed);
1798
1799 return 0;
1800}
1801
Jouni Malinen31888482008-10-30 16:59:24 +02001802static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001803 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001804 struct ieee80211_txq_params *params)
1805{
1806 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001808 struct ieee80211_tx_queue_params p;
1809
1810 if (!local->ops->conf_tx)
1811 return -EOPNOTSUPP;
1812
Johannes Berg54bcbc62012-03-28 11:04:25 +02001813 if (local->hw.queues < IEEE80211_NUM_ACS)
1814 return -EOPNOTSUPP;
1815
Jouni Malinen31888482008-10-30 16:59:24 +02001816 memset(&p, 0, sizeof(p));
1817 p.aifs = params->aifs;
1818 p.cw_max = params->cwmax;
1819 p.cw_min = params->cwmin;
1820 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001821
1822 /*
1823 * Setting tx queue params disables u-apsd because it's only
1824 * called in master mode.
1825 */
1826 p.uapsd = false;
1827
Johannes Berga3304b02012-03-28 11:04:24 +02001828 sdata->tx_conf[params->ac] = p;
1829 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001830 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001831 "failed to set TX queue parameters for AC %d\n",
1832 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001833 return -EINVAL;
1834 }
1835
Johannes Berg7d257452012-07-06 17:37:43 +02001836 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1837
Jouni Malinen31888482008-10-30 16:59:24 +02001838 return 0;
1839}
1840
Bob Copeland665af4f2009-01-19 11:20:53 -05001841#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001842static int ieee80211_suspend(struct wiphy *wiphy,
1843 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001844{
Johannes Bergeecc4802011-05-04 15:37:29 +02001845 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001846}
1847
1848static int ieee80211_resume(struct wiphy *wiphy)
1849{
1850 return __ieee80211_resume(wiphy_priv(wiphy));
1851}
1852#else
1853#define ieee80211_suspend NULL
1854#define ieee80211_resume NULL
1855#endif
1856
Johannes Berg2a519312009-02-10 21:25:55 +01001857static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001858 struct cfg80211_scan_request *req)
1859{
Johannes Bergfd014282012-06-18 19:17:03 +02001860 struct ieee80211_sub_if_data *sdata;
1861
1862 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001863
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001864 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1865 case NL80211_IFTYPE_STATION:
1866 case NL80211_IFTYPE_ADHOC:
1867 case NL80211_IFTYPE_MESH_POINT:
1868 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001869 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001870 break;
1871 case NL80211_IFTYPE_P2P_GO:
1872 if (sdata->local->ops->hw_scan)
1873 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001874 /*
1875 * FIXME: implement NoA while scanning in software,
1876 * for now fall through to allow scanning only when
1877 * beaconing hasn't been configured yet
1878 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001879 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02001880 /*
1881 * If the scan has been forced (and the driver supports
1882 * forcing), don't care about being beaconing already.
1883 * This will create problems to the attached stations (e.g. all
1884 * the frames sent while scanning on other channel will be
1885 * lost)
1886 */
1887 if (sdata->u.ap.beacon &&
1888 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1889 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001890 return -EOPNOTSUPP;
1891 break;
1892 default:
1893 return -EOPNOTSUPP;
1894 }
Johannes Berg2a519312009-02-10 21:25:55 +01001895
1896 return ieee80211_request_scan(sdata, req);
1897}
1898
Luciano Coelho79f460c2011-05-11 17:09:36 +03001899static int
1900ieee80211_sched_scan_start(struct wiphy *wiphy,
1901 struct net_device *dev,
1902 struct cfg80211_sched_scan_request *req)
1903{
1904 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1905
1906 if (!sdata->local->ops->sched_scan_start)
1907 return -EOPNOTSUPP;
1908
1909 return ieee80211_request_sched_scan_start(sdata, req);
1910}
1911
1912static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001913ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001914{
1915 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1916
1917 if (!sdata->local->ops->sched_scan_stop)
1918 return -EOPNOTSUPP;
1919
Luciano Coelho85a99942011-05-12 16:28:29 +03001920 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001921}
1922
Jouni Malinen636a5d32009-03-19 13:39:22 +02001923static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1924 struct cfg80211_auth_request *req)
1925{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001926 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001927}
1928
1929static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1930 struct cfg80211_assoc_request *req)
1931{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001932 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001933}
1934
1935static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001936 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001937{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001938 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001939}
1940
1941static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001942 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001943{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001944 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001945}
1946
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001947static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1948 struct cfg80211_ibss_params *params)
1949{
Johannes Berg55de9082012-07-26 17:24:39 +02001950 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001951}
1952
1953static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1954{
Johannes Berg55de9082012-07-26 17:24:39 +02001955 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001956}
1957
Antonio Quartulli391e53e2012-11-02 13:27:49 +01001958static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
1959 int rate[IEEE80211_NUM_BANDS])
1960{
1961 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1962
Cong Ding9887dbf2013-02-06 17:23:45 +01001963 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
1964 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01001965
1966 return 0;
1967}
1968
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001969static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1970{
1971 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001972 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001973
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001974 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1975 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1976
1977 if (err)
1978 return err;
1979 }
1980
Lukáš Turek310bc672009-12-21 22:50:48 +01001981 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1982 err = drv_set_coverage_class(local, wiphy->coverage_class);
1983
1984 if (err)
1985 return err;
1986 }
1987
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001988 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001989 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001990
Johannes Berg24487982009-04-23 18:52:52 +02001991 if (err)
1992 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001993 }
1994
Johannes Berg8bc83c22012-11-09 18:38:32 +01001995 if (changed & WIPHY_PARAM_RETRY_SHORT) {
1996 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
1997 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001998 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01001999 }
2000 if (changed & WIPHY_PARAM_RETRY_LONG) {
2001 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2002 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002003 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002004 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002005 if (changed &
2006 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2007 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2008
2009 return 0;
2010}
2011
Johannes Berg7643a2c2009-06-02 13:01:39 +02002012static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002013 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002014 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002015{
2016 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002017 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002018
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002019 if (wdev) {
2020 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2021
2022 switch (type) {
2023 case NL80211_TX_POWER_AUTOMATIC:
2024 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2025 break;
2026 case NL80211_TX_POWER_LIMITED:
2027 case NL80211_TX_POWER_FIXED:
2028 if (mbm < 0 || (mbm % 100))
2029 return -EOPNOTSUPP;
2030 sdata->user_power_level = MBM_TO_DBM(mbm);
2031 break;
2032 }
2033
2034 ieee80211_recalc_txpower(sdata);
2035
2036 return 0;
2037 }
Johannes Berg55de9082012-07-26 17:24:39 +02002038
Johannes Berg7643a2c2009-06-02 13:01:39 +02002039 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002040 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002041 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002042 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002043 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002044 case NL80211_TX_POWER_FIXED:
2045 if (mbm < 0 || (mbm % 100))
2046 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002047 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002048 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002049 }
2050
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002051 mutex_lock(&local->iflist_mtx);
2052 list_for_each_entry(sdata, &local->interfaces, list)
2053 sdata->user_power_level = local->user_power_level;
2054 list_for_each_entry(sdata, &local->interfaces, list)
2055 ieee80211_recalc_txpower(sdata);
2056 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002057
2058 return 0;
2059}
2060
Johannes Bergc8442112012-10-24 10:17:18 +02002061static int ieee80211_get_tx_power(struct wiphy *wiphy,
2062 struct wireless_dev *wdev,
2063 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002064{
2065 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002066 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002067
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002068 if (!local->use_chanctx)
2069 *dbm = local->hw.conf.power_level;
2070 else
2071 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002072
Johannes Berg7643a2c2009-06-02 13:01:39 +02002073 return 0;
2074}
2075
Johannes Bergab737a42009-07-01 21:26:58 +02002076static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002077 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002078{
2079 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2080
2081 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2082
2083 return 0;
2084}
2085
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002086static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2087{
2088 struct ieee80211_local *local = wiphy_priv(wiphy);
2089
2090 drv_rfkill_poll(local);
2091}
2092
Johannes Bergaff89a92009-07-01 21:26:51 +02002093#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002094static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2095 struct wireless_dev *wdev,
2096 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002097{
2098 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002099 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002100
2101 if (!local->ops->testmode_cmd)
2102 return -EOPNOTSUPP;
2103
David Spinadel52981cd2013-07-31 18:06:22 +03002104 if (wdev) {
2105 struct ieee80211_sub_if_data *sdata;
2106
2107 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2108 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2109 vif = &sdata->vif;
2110 }
2111
2112 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002113}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002114
2115static int ieee80211_testmode_dump(struct wiphy *wiphy,
2116 struct sk_buff *skb,
2117 struct netlink_callback *cb,
2118 void *data, int len)
2119{
2120 struct ieee80211_local *local = wiphy_priv(wiphy);
2121
2122 if (!local->ops->testmode_dump)
2123 return -EOPNOTSUPP;
2124
2125 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2126}
Johannes Bergaff89a92009-07-01 21:26:51 +02002127#endif
2128
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002129int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2130 enum ieee80211_smps_mode smps_mode)
2131{
2132 struct sta_info *sta;
2133 enum ieee80211_smps_mode old_req;
2134 int i;
2135
2136 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2137 return -EINVAL;
2138
2139 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2140 return 0;
2141
2142 old_req = sdata->u.ap.req_smps;
2143 sdata->u.ap.req_smps = smps_mode;
2144
2145 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2146 if (old_req == smps_mode ||
2147 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2148 return 0;
2149
2150 /* If no associated stations, there's no need to do anything */
2151 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2152 sdata->smps_mode = smps_mode;
2153 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2154 return 0;
2155 }
2156
2157 ht_dbg(sdata,
2158 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2159 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2160
2161 mutex_lock(&sdata->local->sta_mtx);
2162 for (i = 0; i < STA_HASH_SIZE; i++) {
2163 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2164 lockdep_is_held(&sdata->local->sta_mtx));
2165 sta;
2166 sta = rcu_dereference_protected(sta->hnext,
2167 lockdep_is_held(&sdata->local->sta_mtx))) {
2168 /*
2169 * Only stations associated to our AP and
2170 * associated VLANs
2171 */
2172 if (sta->sdata->bss != &sdata->u.ap)
2173 continue;
2174
2175 /* This station doesn't support MIMO - skip it */
2176 if (sta_info_tx_streams(sta) == 1)
2177 continue;
2178
2179 /*
2180 * Don't wake up a STA just to send the action frame
2181 * unless we are getting more restrictive.
2182 */
2183 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2184 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2185 smps_mode)) {
2186 ht_dbg(sdata,
2187 "Won't send SMPS to sleeping STA %pM\n",
2188 sta->sta.addr);
2189 continue;
2190 }
2191
2192 /*
2193 * If the STA is not authorized, wait until it gets
2194 * authorized and the action frame will be sent then.
2195 */
2196 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2197 continue;
2198
2199 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2200 ieee80211_send_smps_action(sdata, smps_mode,
2201 sta->sta.addr,
2202 sdata->vif.bss_conf.bssid);
2203 }
2204 }
2205 mutex_unlock(&sdata->local->sta_mtx);
2206
2207 sdata->smps_mode = smps_mode;
2208 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2209
2210 return 0;
2211}
2212
2213int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2214 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002215{
2216 const u8 *ap;
2217 enum ieee80211_smps_mode old_req;
2218 int err;
2219
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002220 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002221
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002222 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2223 return -EINVAL;
2224
Johannes Berg0f782312009-12-01 13:37:02 +01002225 old_req = sdata->u.mgd.req_smps;
2226 sdata->u.mgd.req_smps = smps_mode;
2227
2228 if (old_req == smps_mode &&
2229 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2230 return 0;
2231
2232 /*
2233 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002234 * association, there's no need to do anything, just store
2235 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002236 */
2237 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002238 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002239 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002240
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002241 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002242
2243 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2244 if (sdata->u.mgd.powersave)
2245 smps_mode = IEEE80211_SMPS_DYNAMIC;
2246 else
2247 smps_mode = IEEE80211_SMPS_OFF;
2248 }
2249
2250 /* send SM PS frame to AP */
2251 err = ieee80211_send_smps_action(sdata, smps_mode,
2252 ap, ap);
2253 if (err)
2254 sdata->u.mgd.req_smps = old_req;
2255
2256 return err;
2257}
2258
Johannes Bergbc92afd2009-07-01 21:26:57 +02002259static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2260 bool enabled, int timeout)
2261{
2262 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2263 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002264
Bob Copeland2d3db212013-10-29 18:11:59 -04002265 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002266 return -EOPNOTSUPP;
2267
Johannes Bergbc92afd2009-07-01 21:26:57 +02002268 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2269 return -EOPNOTSUPP;
2270
2271 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002272 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002273 return 0;
2274
2275 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002276 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002277
Johannes Berg0f782312009-12-01 13:37:02 +01002278 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002279 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002280 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002281 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002282
Johannes Bergbc92afd2009-07-01 21:26:57 +02002283 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2284 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2285
2286 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002287 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002288
2289 return 0;
2290}
2291
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002292static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2293 struct net_device *dev,
2294 s32 rssi_thold, u32 rssi_hyst)
2295{
2296 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002297 struct ieee80211_vif *vif = &sdata->vif;
2298 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2299
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002300 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2301 rssi_hyst == bss_conf->cqm_rssi_hyst)
2302 return 0;
2303
2304 bss_conf->cqm_rssi_thold = rssi_thold;
2305 bss_conf->cqm_rssi_hyst = rssi_hyst;
2306
2307 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002308 if (sdata->u.mgd.associated &&
2309 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002310 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2311
2312 return 0;
2313}
2314
Johannes Berg99303802009-07-01 21:26:59 +02002315static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2316 struct net_device *dev,
2317 const u8 *addr,
2318 const struct cfg80211_bitrate_mask *mask)
2319{
2320 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2321 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302322 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002323
Eliad Peller554a43d2012-06-12 12:41:15 +03002324 if (!ieee80211_sdata_running(sdata))
2325 return -ENETDOWN;
2326
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302327 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2328 ret = drv_set_bitrate_mask(local, sdata, mask);
2329 if (ret)
2330 return ret;
2331 }
Johannes Berg99303802009-07-01 21:26:59 +02002332
Simon Wunderlich19468412012-01-28 17:25:33 +01002333 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002334 struct ieee80211_supported_band *sband = wiphy->bands[i];
2335 int j;
2336
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002337 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002338 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2339 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002340
2341 sdata->rc_has_mcs_mask[i] = false;
2342 if (!sband)
2343 continue;
2344
2345 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2346 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2347 sdata->rc_has_mcs_mask[i] = true;
2348 break;
2349 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002350 }
Johannes Berg99303802009-07-01 21:26:59 +02002351
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002352 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002353}
2354
Eliad Pellereaa336b2014-09-03 15:25:06 +03002355static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2356 struct ieee80211_roc_work *new_roc,
2357 struct ieee80211_roc_work *cur_roc)
2358{
2359 unsigned long j = jiffies;
2360 unsigned long cur_roc_end = cur_roc->hw_start_time +
2361 msecs_to_jiffies(cur_roc->duration);
2362 struct ieee80211_roc_work *next_roc;
2363 int new_dur;
2364
2365 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2366 return false;
2367
2368 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2369 return false;
2370
2371 ieee80211_handle_roc_started(new_roc);
2372
2373 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2374
2375 /* cur_roc is long enough - add new_roc to the dependents list. */
2376 if (new_dur <= 0) {
2377 list_add_tail(&new_roc->list, &cur_roc->dependents);
2378 return true;
2379 }
2380
2381 new_roc->duration = new_dur;
2382
2383 /*
2384 * if cur_roc was already coalesced before, we might
2385 * want to extend the next roc instead of adding
2386 * a new one.
2387 */
2388 next_roc = list_entry(cur_roc->list.next,
2389 struct ieee80211_roc_work, list);
2390 if (&next_roc->list != &local->roc_list &&
2391 next_roc->chan == new_roc->chan &&
2392 next_roc->sdata == new_roc->sdata &&
2393 !WARN_ON(next_roc->started)) {
2394 list_add_tail(&new_roc->list, &next_roc->dependents);
2395 next_roc->duration = max(next_roc->duration,
2396 new_roc->duration);
2397 next_roc->type = max(next_roc->type, new_roc->type);
2398 return true;
2399 }
2400
2401 /* add right after cur_roc */
2402 list_add(&new_roc->list, &cur_roc->list);
2403
2404 return true;
2405}
2406
Johannes Berg2eb278e2012-06-05 14:28:42 +02002407static int ieee80211_start_roc_work(struct ieee80211_local *local,
2408 struct ieee80211_sub_if_data *sdata,
2409 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002410 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002411 struct sk_buff *txskb,
2412 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002413{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002414 struct ieee80211_roc_work *roc, *tmp;
2415 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002416 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002417
2418 lockdep_assert_held(&local->mtx);
2419
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002420 if (local->use_chanctx && !local->ops->remain_on_channel)
2421 return -EOPNOTSUPP;
2422
Johannes Berg2eb278e2012-06-05 14:28:42 +02002423 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2424 if (!roc)
2425 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002426
Ilan Peer2fae0622013-12-19 13:25:29 +02002427 /*
2428 * If the duration is zero, then the driver
2429 * wouldn't actually do anything. Set it to
2430 * 10 for now.
2431 *
2432 * TODO: cancel the off-channel operation
2433 * when we get the SKB's TX status and
2434 * the wait time was zero before.
2435 */
2436 if (!duration)
2437 duration = 10;
2438
Johannes Berg2eb278e2012-06-05 14:28:42 +02002439 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002440 roc->duration = duration;
2441 roc->req_duration = duration;
2442 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002443 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002444 roc->mgmt_tx_cookie = (unsigned long)txskb;
2445 roc->sdata = sdata;
2446 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2447 INIT_LIST_HEAD(&roc->dependents);
2448
Eliad Peller2f617432014-01-12 11:06:37 +02002449 /*
2450 * cookie is either the roc cookie (for normal roc)
2451 * or the SKB (for mgmt TX)
2452 */
2453 if (!txskb) {
2454 /* local->mtx protects this */
2455 local->roc_cookie_counter++;
2456 roc->cookie = local->roc_cookie_counter;
2457 /* wow, you wrapped 64 bits ... more likely a bug */
2458 if (WARN_ON(roc->cookie == 0)) {
2459 roc->cookie = 1;
2460 local->roc_cookie_counter++;
2461 }
2462 *cookie = roc->cookie;
2463 } else {
2464 *cookie = (unsigned long)txskb;
2465 }
2466
Johannes Berg2eb278e2012-06-05 14:28:42 +02002467 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002468 if (!list_empty(&local->roc_list) ||
2469 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002470 goto out_check_combine;
2471
2472 /* if not HW assist, just queue & schedule work */
2473 if (!local->ops->remain_on_channel) {
2474 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2475 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002476 }
2477
Johannes Berg2eb278e2012-06-05 14:28:42 +02002478 /* otherwise actually kick it off here (for error handling) */
2479
Ilan Peerd339d5c2013-02-12 09:34:13 +02002480 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002481 if (ret) {
2482 kfree(roc);
2483 return ret;
2484 }
2485
2486 roc->started = true;
2487 goto out_queue;
2488
2489 out_check_combine:
2490 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002491 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002492 continue;
2493
2494 /*
2495 * Extend this ROC if possible:
2496 *
2497 * If it hasn't started yet, just increase the duration
2498 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002499 * If the type of the new ROC has higher priority, modify the
2500 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002501 */
2502 if (!tmp->started) {
2503 list_add_tail(&roc->list, &tmp->dependents);
2504 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002505 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002506 queued = true;
2507 break;
2508 }
2509
2510 /* If it has already started, it's more difficult ... */
2511 if (local->ops->remain_on_channel) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002512 /*
2513 * In the offloaded ROC case, if it hasn't begun, add
2514 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002515 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002516 * check that there's still a minimum time left and
2517 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002518 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002519 * a reduced time so we'll ask the driver to execute
2520 * it right after finishing the previous one, in the
2521 * hope that it'll also be executed right afterwards,
2522 * effectively extending the old one.
2523 * If there's no minimum time left, just add it to the
2524 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002525 * TODO: the ROC type is ignored here, assuming that it
2526 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002527 */
2528 if (!tmp->hw_begun) {
2529 list_add_tail(&roc->list, &tmp->dependents);
2530 queued = true;
2531 break;
2532 }
2533
Eliad Pellereaa336b2014-09-03 15:25:06 +03002534 if (ieee80211_coalesce_started_roc(local, roc, tmp))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002535 queued = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002536 } else if (del_timer_sync(&tmp->work.timer)) {
2537 unsigned long new_end;
2538
2539 /*
2540 * In the software ROC case, cancel the timer, if
2541 * that fails then the finish work is already
2542 * queued/pending and thus we queue the new ROC
2543 * normally, if that succeeds then we can extend
2544 * the timer duration and TX the frame (if any.)
2545 */
2546
2547 list_add_tail(&roc->list, &tmp->dependents);
2548 queued = true;
2549
2550 new_end = jiffies + msecs_to_jiffies(roc->duration);
2551
2552 /* ok, it was started & we canceled timer */
2553 if (time_after(new_end, tmp->work.timer.expires))
2554 mod_timer(&tmp->work.timer, new_end);
2555 else
2556 add_timer(&tmp->work.timer);
2557
2558 ieee80211_handle_roc_started(roc);
2559 }
2560 break;
2561 }
2562
2563 out_queue:
2564 if (!queued)
2565 list_add_tail(&roc->list, &local->roc_list);
2566
Johannes Berg2eb278e2012-06-05 14:28:42 +02002567 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002568}
2569
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002570static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002571 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002572 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002573 unsigned int duration,
2574 u64 *cookie)
2575{
Johannes Berg71bbc992012-06-15 15:30:18 +02002576 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002577 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002578 int ret;
2579
Johannes Berg2eb278e2012-06-05 14:28:42 +02002580 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002581 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002582 duration, cookie, NULL,
2583 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002584 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002585
Johannes Berg2eb278e2012-06-05 14:28:42 +02002586 return ret;
2587}
2588
2589static int ieee80211_cancel_roc(struct ieee80211_local *local,
2590 u64 cookie, bool mgmt_tx)
2591{
2592 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2593 int ret;
2594
2595 mutex_lock(&local->mtx);
2596 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002597 struct ieee80211_roc_work *dep, *tmp2;
2598
2599 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002600 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002601 continue;
2602 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2603 continue;
2604 /* found dependent item -- just remove it */
2605 list_del(&dep->list);
2606 mutex_unlock(&local->mtx);
2607
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002608 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002609 return 0;
2610 }
2611
Johannes Berg50febf62012-10-26 16:13:06 +02002612 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002613 continue;
2614 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2615 continue;
2616
2617 found = roc;
2618 break;
2619 }
2620
2621 if (!found) {
2622 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002623 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002624 }
Johannes Berg21f83582010-12-18 17:20:47 +01002625
Johannes Berge979e332012-06-11 17:09:41 +02002626 /*
2627 * We found the item to cancel, so do that. Note that it
2628 * may have dependents, which we also cancel (and send
2629 * the expired signal for.) Not doing so would be quite
2630 * tricky here, but we may need to fix it later.
2631 */
2632
Johannes Berg2eb278e2012-06-05 14:28:42 +02002633 if (local->ops->remain_on_channel) {
2634 if (found->started) {
2635 ret = drv_cancel_remain_on_channel(local);
2636 if (WARN_ON_ONCE(ret)) {
2637 mutex_unlock(&local->mtx);
2638 return ret;
2639 }
2640 }
Johannes Berg21f83582010-12-18 17:20:47 +01002641
Johannes Berg2eb278e2012-06-05 14:28:42 +02002642 list_del(&found->list);
2643
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002644 if (found->started)
2645 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002646 mutex_unlock(&local->mtx);
2647
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002648 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002649 } else {
2650 /* work may be pending so use it all the time */
2651 found->abort = true;
2652 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2653
2654 mutex_unlock(&local->mtx);
2655
2656 /* work will clean up etc */
2657 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002658 WARN_ON(!found->to_be_freed);
2659 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002660 }
Johannes Berg21f83582010-12-18 17:20:47 +01002661
Johannes Berg21f83582010-12-18 17:20:47 +01002662 return 0;
2663}
2664
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002665static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002666 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002667 u64 cookie)
2668{
Johannes Berg71bbc992012-06-15 15:30:18 +02002669 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002670 struct ieee80211_local *local = sdata->local;
2671
Johannes Berg2eb278e2012-06-05 14:28:42 +02002672 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002673}
2674
Simon Wunderlich164eb022013-02-08 18:16:20 +01002675static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2676 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002677 struct cfg80211_chan_def *chandef,
2678 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002679{
2680 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2681 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002682 int err;
2683
Johannes Berg34a37402013-12-18 09:43:33 +01002684 mutex_lock(&local->mtx);
2685 if (!list_empty(&local->roc_list) || local->scanning) {
2686 err = -EBUSY;
2687 goto out_unlock;
2688 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002689
2690 /* whatever, but channel contexts should not complain about that one */
2691 sdata->smps_mode = IEEE80211_SMPS_OFF;
2692 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002693
Simon Wunderlich164eb022013-02-08 18:16:20 +01002694 err = ieee80211_vif_use_channel(sdata, chandef,
2695 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002696 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002697 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002698
Simon Wunderlich164eb022013-02-08 18:16:20 +01002699 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002700 &sdata->dfs_cac_timer_work,
2701 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002702
Johannes Berg34a37402013-12-18 09:43:33 +01002703 out_unlock:
2704 mutex_unlock(&local->mtx);
2705 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002706}
2707
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002708static struct cfg80211_beacon_data *
2709cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2710{
2711 struct cfg80211_beacon_data *new_beacon;
2712 u8 *pos;
2713 int len;
2714
2715 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2716 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2717 beacon->probe_resp_len;
2718
2719 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2720 if (!new_beacon)
2721 return NULL;
2722
2723 pos = (u8 *)(new_beacon + 1);
2724 if (beacon->head_len) {
2725 new_beacon->head_len = beacon->head_len;
2726 new_beacon->head = pos;
2727 memcpy(pos, beacon->head, beacon->head_len);
2728 pos += beacon->head_len;
2729 }
2730 if (beacon->tail_len) {
2731 new_beacon->tail_len = beacon->tail_len;
2732 new_beacon->tail = pos;
2733 memcpy(pos, beacon->tail, beacon->tail_len);
2734 pos += beacon->tail_len;
2735 }
2736 if (beacon->beacon_ies_len) {
2737 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2738 new_beacon->beacon_ies = pos;
2739 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2740 pos += beacon->beacon_ies_len;
2741 }
2742 if (beacon->proberesp_ies_len) {
2743 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2744 new_beacon->proberesp_ies = pos;
2745 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2746 pos += beacon->proberesp_ies_len;
2747 }
2748 if (beacon->assocresp_ies_len) {
2749 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2750 new_beacon->assocresp_ies = pos;
2751 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2752 pos += beacon->assocresp_ies_len;
2753 }
2754 if (beacon->probe_resp_len) {
2755 new_beacon->probe_resp_len = beacon->probe_resp_len;
2756 beacon->probe_resp = pos;
2757 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2758 pos += beacon->probe_resp_len;
2759 }
2760
2761 return new_beacon;
2762}
2763
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002764void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002765{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002766 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2767
2768 ieee80211_queue_work(&sdata->local->hw,
2769 &sdata->csa_finalize_work);
2770}
2771EXPORT_SYMBOL(ieee80211_csa_finish);
2772
Michal Kazior66199502014-04-09 15:11:00 +02002773static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2774 u32 *changed)
2775{
2776 int err;
2777
2778 switch (sdata->vif.type) {
2779 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002780 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2781 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002782 kfree(sdata->u.ap.next_beacon);
2783 sdata->u.ap.next_beacon = NULL;
2784
2785 if (err < 0)
2786 return err;
2787 *changed |= err;
2788 break;
2789 case NL80211_IFTYPE_ADHOC:
2790 err = ieee80211_ibss_finish_csa(sdata);
2791 if (err < 0)
2792 return err;
2793 *changed |= err;
2794 break;
2795#ifdef CONFIG_MAC80211_MESH
2796 case NL80211_IFTYPE_MESH_POINT:
2797 err = ieee80211_mesh_finish_csa(sdata);
2798 if (err < 0)
2799 return err;
2800 *changed |= err;
2801 break;
2802#endif
2803 default:
2804 WARN_ON(1);
2805 return -EINVAL;
2806 }
2807
2808 return 0;
2809}
2810
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002811static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002812{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002813 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02002814 u32 changed = 0;
2815 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002816
Michal Kaziordbd72852014-01-29 07:56:21 +01002817 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002818 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002819 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01002820
Michal Kazior03078de2014-06-25 12:35:08 +02002821 /*
2822 * using reservation isn't immediate as it may be deferred until later
2823 * with multi-vif. once reservation is complete it will re-schedule the
2824 * work with no reserved_chanctx so verify chandef to check if it
2825 * completed successfully
2826 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002827
Michal Kazior03078de2014-06-25 12:35:08 +02002828 if (sdata->reserved_chanctx) {
2829 /*
2830 * with multi-vif csa driver may call ieee80211_csa_finish()
2831 * many times while waiting for other interfaces to use their
2832 * reservations
2833 */
2834 if (sdata->reserved_ready)
2835 return 0;
2836
2837 err = ieee80211_vif_use_reserved_context(sdata);
2838 if (err)
2839 return err;
2840
2841 return 0;
Arik Nemtsov7578d572013-09-01 17:15:51 +03002842 }
2843
Michal Kazior03078de2014-06-25 12:35:08 +02002844 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2845 &sdata->csa_chandef))
2846 return -EINVAL;
2847
Simon Wunderliche487eae2013-11-21 18:19:51 +01002848 sdata->vif.csa_active = false;
Michal Kazior97518af2014-01-29 07:56:18 +01002849
Michal Kazior66199502014-04-09 15:11:00 +02002850 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2851 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002852 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002853
Michal Kaziorfaf046e2014-01-29 07:56:17 +01002854 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02002855 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2856
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002857 if (sdata->csa_block_tx) {
2858 ieee80211_wake_vif_queues(local, sdata,
2859 IEEE80211_QUEUE_STOP_REASON_CSA);
2860 sdata->csa_block_tx = false;
2861 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002862
2863 return 0;
2864}
2865
2866static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2867{
2868 if (__ieee80211_csa_finalize(sdata)) {
2869 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2870 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2871 GFP_KERNEL);
2872 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002873}
2874
2875void ieee80211_csa_finalize_work(struct work_struct *work)
2876{
2877 struct ieee80211_sub_if_data *sdata =
2878 container_of(work, struct ieee80211_sub_if_data,
2879 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02002880 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002881
2882 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002883 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002884 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002885
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002886 /* AP might have been stopped while waiting for the lock. */
2887 if (!sdata->vif.csa_active)
2888 goto unlock;
2889
2890 if (!ieee80211_sdata_running(sdata))
2891 goto unlock;
2892
2893 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002894
2895unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02002896 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002897 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002898 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002899}
2900
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002901static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
2902 struct cfg80211_csa_settings *params,
2903 u32 *changed)
2904{
Michal Kazioraf296bd2014-06-05 14:21:36 +02002905 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002906 int err;
2907
2908 switch (sdata->vif.type) {
2909 case NL80211_IFTYPE_AP:
2910 sdata->u.ap.next_beacon =
2911 cfg80211_beacon_dup(&params->beacon_after);
2912 if (!sdata->u.ap.next_beacon)
2913 return -ENOMEM;
2914
2915 /*
2916 * With a count of 0, we don't have to wait for any
2917 * TBTT before switching, so complete the CSA
2918 * immediately. In theory, with a count == 1 we
2919 * should delay the switch until just before the next
2920 * TBTT, but that would complicate things so we switch
2921 * immediately too. If we would delay the switch
2922 * until the next TBTT, we would have to set the probe
2923 * response here.
2924 *
2925 * TODO: A channel switch with count <= 1 without
2926 * sending a CSA action frame is kind of useless,
2927 * because the clients won't know we're changing
2928 * channels. The action frame must be implemented
2929 * either here or in the userspace.
2930 */
2931 if (params->count <= 1)
2932 break;
2933
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03002934 if ((params->n_counter_offsets_beacon >
2935 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
2936 (params->n_counter_offsets_presp >
2937 IEEE80211_MAX_CSA_COUNTERS_NUM))
2938 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03002939
Michal Kazioraf296bd2014-06-05 14:21:36 +02002940 csa.counter_offsets_beacon = params->counter_offsets_beacon;
2941 csa.counter_offsets_presp = params->counter_offsets_presp;
2942 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
2943 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
2944 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03002945
Michal Kazioraf296bd2014-06-05 14:21:36 +02002946 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002947 if (err < 0) {
2948 kfree(sdata->u.ap.next_beacon);
2949 return err;
2950 }
2951 *changed |= err;
2952
2953 break;
2954 case NL80211_IFTYPE_ADHOC:
2955 if (!sdata->vif.bss_conf.ibss_joined)
2956 return -EINVAL;
2957
2958 if (params->chandef.width != sdata->u.ibss.chandef.width)
2959 return -EINVAL;
2960
2961 switch (params->chandef.width) {
2962 case NL80211_CHAN_WIDTH_40:
2963 if (cfg80211_get_chandef_type(&params->chandef) !=
2964 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
2965 return -EINVAL;
2966 case NL80211_CHAN_WIDTH_5:
2967 case NL80211_CHAN_WIDTH_10:
2968 case NL80211_CHAN_WIDTH_20_NOHT:
2969 case NL80211_CHAN_WIDTH_20:
2970 break;
2971 default:
2972 return -EINVAL;
2973 }
2974
2975 /* changes into another band are not supported */
2976 if (sdata->u.ibss.chandef.chan->band !=
2977 params->chandef.chan->band)
2978 return -EINVAL;
2979
2980 /* see comments in the NL80211_IFTYPE_AP block */
2981 if (params->count > 1) {
2982 err = ieee80211_ibss_csa_beacon(sdata, params);
2983 if (err < 0)
2984 return err;
2985 *changed |= err;
2986 }
2987
2988 ieee80211_send_action_csa(sdata, params);
2989
2990 break;
2991#ifdef CONFIG_MAC80211_MESH
2992 case NL80211_IFTYPE_MESH_POINT: {
2993 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
2994
2995 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
2996 return -EINVAL;
2997
2998 /* changes into another band are not supported */
2999 if (sdata->vif.bss_conf.chandef.chan->band !=
3000 params->chandef.chan->band)
3001 return -EINVAL;
3002
3003 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3004 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3005 if (!ifmsh->pre_value)
3006 ifmsh->pre_value = 1;
3007 else
3008 ifmsh->pre_value++;
3009 }
3010
3011 /* see comments in the NL80211_IFTYPE_AP block */
3012 if (params->count > 1) {
3013 err = ieee80211_mesh_csa_beacon(sdata, params);
3014 if (err < 0) {
3015 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3016 return err;
3017 }
3018 *changed |= err;
3019 }
3020
3021 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3022 ieee80211_send_action_csa(sdata, params);
3023
3024 break;
3025 }
3026#endif
3027 default:
3028 return -EOPNOTSUPP;
3029 }
3030
3031 return 0;
3032}
3033
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003034static int
3035__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3036 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003037{
3038 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3039 struct ieee80211_local *local = sdata->local;
Michal Kazior2b327132014-04-09 15:29:32 +02003040 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003041 struct ieee80211_chanctx *chanctx;
Michal Kazior03078de2014-06-25 12:35:08 +02003042 int err, changed = 0;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003043
Michal Kaziordbd72852014-01-29 07:56:21 +01003044 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003045 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003046
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003047 if (!list_empty(&local->roc_list) || local->scanning)
3048 return -EBUSY;
3049
3050 if (sdata->wdev.cac_started)
3051 return -EBUSY;
3052
3053 if (cfg80211_chandef_identical(&params->chandef,
3054 &sdata->vif.bss_conf.chandef))
3055 return -EINVAL;
3056
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003057 /* don't allow another channel switch if one is already active. */
3058 if (sdata->vif.csa_active)
3059 return -EBUSY;
3060
Michal Kazior03078de2014-06-25 12:35:08 +02003061 mutex_lock(&local->chanctx_mtx);
3062 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3063 lockdep_is_held(&local->chanctx_mtx));
3064 if (!conf) {
3065 err = -EBUSY;
3066 goto out;
3067 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003068
Michal Kazior03078de2014-06-25 12:35:08 +02003069 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3070 if (!chanctx) {
3071 err = -EBUSY;
3072 goto out;
3073 }
3074
3075 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3076 chanctx->mode,
3077 params->radar_required);
3078 if (err)
3079 goto out;
3080
3081 /* if reservation is invalid then this will fail */
3082 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3083 if (err) {
3084 ieee80211_vif_unreserve_chanctx(sdata);
3085 goto out;
3086 }
3087
3088 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3089 if (err) {
3090 ieee80211_vif_unreserve_chanctx(sdata);
3091 goto out;
3092 }
3093
Luciano Coelho33787fc2013-11-11 20:34:54 +02003094 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003095 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003096 sdata->vif.csa_active = true;
3097
Michal Kazior59af6922014-04-09 15:10:59 +02003098 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003099 ieee80211_stop_vif_queues(local, sdata,
3100 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003101
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003102 if (changed) {
3103 ieee80211_bss_info_change_notify(sdata, changed);
3104 drv_channel_switch_beacon(sdata, &params->chandef);
3105 } else {
3106 /* if the beacon didn't change, we can finalize immediately */
3107 ieee80211_csa_finalize(sdata);
3108 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003109
Michal Kazior03078de2014-06-25 12:35:08 +02003110out:
3111 mutex_unlock(&local->chanctx_mtx);
3112 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003113}
3114
Michal Kazior59af6922014-04-09 15:10:59 +02003115int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3116 struct cfg80211_csa_settings *params)
3117{
3118 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3119 struct ieee80211_local *local = sdata->local;
3120 int err;
3121
3122 mutex_lock(&local->mtx);
3123 err = __ieee80211_channel_switch(wiphy, dev, params);
3124 mutex_unlock(&local->mtx);
3125
3126 return err;
3127}
3128
Johannes Berg71bbc992012-06-15 15:30:18 +02003129static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003130 struct cfg80211_mgmt_tx_params *params,
3131 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003132{
Johannes Berg71bbc992012-06-15 15:30:18 +02003133 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003134 struct ieee80211_local *local = sdata->local;
3135 struct sk_buff *skb;
3136 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003137 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003138 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003139 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003140 int ret;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003141 u8 *data;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003142
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003143 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003144 flags = IEEE80211_TX_CTL_NO_ACK;
3145 else
3146 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3147 IEEE80211_TX_CTL_REQ_TX_STATUS;
3148
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003149 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303150 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3151
Johannes Berg9d38d852010-06-09 17:20:33 +02003152 switch (sdata->vif.type) {
3153 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003154 if (!sdata->vif.bss_conf.ibss_joined)
3155 need_offchan = true;
3156 /* fall through */
3157#ifdef CONFIG_MAC80211_MESH
3158 case NL80211_IFTYPE_MESH_POINT:
3159 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3160 !sdata->u.mesh.mesh_id_len)
3161 need_offchan = true;
3162 /* fall through */
3163#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003164 case NL80211_IFTYPE_AP:
3165 case NL80211_IFTYPE_AP_VLAN:
3166 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003167 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3168 !ieee80211_vif_is_mesh(&sdata->vif) &&
3169 !rcu_access_pointer(sdata->bss->beacon))
3170 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003171 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003172 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003173 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3174 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003175 break;
3176 rcu_read_lock();
3177 sta = sta_info_get(sdata, mgmt->da);
3178 rcu_read_unlock();
3179 if (!sta)
3180 return -ENOLINK;
3181 break;
3182 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003183 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003184 if (!sdata->u.mgd.associated)
3185 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003186 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003187 case NL80211_IFTYPE_P2P_DEVICE:
3188 need_offchan = true;
3189 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003190 default:
3191 return -EOPNOTSUPP;
3192 }
3193
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003194 /* configurations requiring offchan cannot work if no channel has been
3195 * specified
3196 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003197 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003198 return -EINVAL;
3199
Johannes Berg2eb278e2012-06-05 14:28:42 +02003200 mutex_lock(&local->mtx);
3201
3202 /* Check if the operating channel is the requested channel */
3203 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003204 struct ieee80211_chanctx_conf *chanctx_conf;
3205
3206 rcu_read_lock();
3207 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3208
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003209 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003210 need_offchan = params->chan &&
3211 (params->chan !=
3212 chanctx_conf->def.chan);
3213 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003214 ret = -EINVAL;
3215 rcu_read_unlock();
3216 goto out_unlock;
3217 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003218 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003219 }
Johannes Berg55de9082012-07-26 17:24:39 +02003220 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003221 }
3222
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003223 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003224 ret = -EBUSY;
3225 goto out_unlock;
3226 }
3227
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003228 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003229 if (!skb) {
3230 ret = -ENOMEM;
3231 goto out_unlock;
3232 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003233 skb_reserve(skb, local->hw.extra_tx_headroom);
3234
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003235 data = skb_put(skb, params->len);
3236 memcpy(data, params->buf, params->len);
3237
3238 /* Update CSA counters */
3239 if (sdata->vif.csa_active &&
3240 (sdata->vif.type == NL80211_IFTYPE_AP ||
3241 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3242 params->n_csa_offsets) {
3243 int i;
Michal Kazioraf296bd2014-06-05 14:21:36 +02003244 struct beacon_data *beacon = NULL;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003245
Michal Kazioraf296bd2014-06-05 14:21:36 +02003246 rcu_read_lock();
3247
3248 if (sdata->vif.type == NL80211_IFTYPE_AP)
3249 beacon = rcu_dereference(sdata->u.ap.beacon);
3250 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3251 beacon = rcu_dereference(sdata->u.ibss.presp);
3252 else if (ieee80211_vif_is_mesh(&sdata->vif))
3253 beacon = rcu_dereference(sdata->u.mesh.beacon);
3254
3255 if (beacon)
3256 for (i = 0; i < params->n_csa_offsets; i++)
3257 data[params->csa_offsets[i]] =
3258 beacon->csa_current_counter;
3259
3260 rcu_read_unlock();
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003261 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003262
3263 IEEE80211_SKB_CB(skb)->flags = flags;
3264
Johannes Berg2eb278e2012-06-05 14:28:42 +02003265 skb->dev = sdata->dev;
3266
3267 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003268 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003269 ieee80211_tx_skb(sdata, skb);
3270 ret = 0;
3271 goto out_unlock;
3272 }
3273
Seth Forshee6c17b772013-02-11 11:21:07 -06003274 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3275 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003276 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003277 IEEE80211_SKB_CB(skb)->hw_queue =
3278 local->hw.offchannel_tx_hw_queue;
3279
Johannes Berg2eb278e2012-06-05 14:28:42 +02003280 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003281 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3282 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003283 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003284 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003285 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003286 out_unlock:
3287 mutex_unlock(&local->mtx);
3288 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003289}
3290
Johannes Bergf30221e2010-11-25 10:02:30 +01003291static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003292 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003293 u64 cookie)
3294{
Johannes Berg71bbc992012-06-15 15:30:18 +02003295 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003296
Johannes Berg2eb278e2012-06-05 14:28:42 +02003297 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003298}
3299
Johannes Berg7be50862010-10-13 12:06:24 +02003300static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003301 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003302 u16 frame_type, bool reg)
3303{
3304 struct ieee80211_local *local = wiphy_priv(wiphy);
3305
Will Hawkins6abe0562012-06-20 11:51:14 -04003306 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003307 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3308 if (reg)
3309 local->probe_req_reg++;
3310 else
3311 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003312
Felix Fietkau35f51492012-10-31 15:50:34 +01003313 if (!local->open_count)
3314 break;
3315
Will Hawkins6abe0562012-06-20 11:51:14 -04003316 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3317 break;
3318 default:
3319 break;
3320 }
Johannes Berg7be50862010-10-13 12:06:24 +02003321}
3322
Bruno Randolf15d96752010-11-10 12:50:56 +09003323static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3324{
3325 struct ieee80211_local *local = wiphy_priv(wiphy);
3326
3327 if (local->started)
3328 return -EOPNOTSUPP;
3329
3330 return drv_set_antenna(local, tx_ant, rx_ant);
3331}
3332
3333static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3334{
3335 struct ieee80211_local *local = wiphy_priv(wiphy);
3336
3337 return drv_get_antenna(local, tx_ant, rx_ant);
3338}
3339
Johannes Bergc68f4b82011-07-05 16:35:41 +02003340static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3341 struct net_device *dev,
3342 struct cfg80211_gtk_rekey_data *data)
3343{
3344 struct ieee80211_local *local = wiphy_priv(wiphy);
3345 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3346
3347 if (!local->ops->set_rekey_data)
3348 return -EOPNOTSUPP;
3349
3350 drv_set_rekey_data(local, sdata, data);
3351
3352 return 0;
3353}
3354
Johannes Berg06500732011-11-04 11:18:16 +01003355static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3356 const u8 *peer, u64 *cookie)
3357{
3358 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3359 struct ieee80211_local *local = sdata->local;
3360 struct ieee80211_qos_hdr *nullfunc;
3361 struct sk_buff *skb;
3362 int size = sizeof(*nullfunc);
3363 __le16 fc;
3364 bool qos;
3365 struct ieee80211_tx_info *info;
3366 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003367 struct ieee80211_chanctx_conf *chanctx_conf;
3368 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003369
3370 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003371 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3372 if (WARN_ON(!chanctx_conf)) {
3373 rcu_read_unlock();
3374 return -EINVAL;
3375 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003376 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003377 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003378 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003379 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003380 } else {
3381 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003382 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003383 }
Johannes Berg06500732011-11-04 11:18:16 +01003384
3385 if (qos) {
3386 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3387 IEEE80211_STYPE_QOS_NULLFUNC |
3388 IEEE80211_FCTL_FROMDS);
3389 } else {
3390 size -= 2;
3391 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3392 IEEE80211_STYPE_NULLFUNC |
3393 IEEE80211_FCTL_FROMDS);
3394 }
3395
3396 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003397 if (!skb) {
3398 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003399 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003400 }
Johannes Berg06500732011-11-04 11:18:16 +01003401
3402 skb->dev = dev;
3403
3404 skb_reserve(skb, local->hw.extra_tx_headroom);
3405
3406 nullfunc = (void *) skb_put(skb, size);
3407 nullfunc->frame_control = fc;
3408 nullfunc->duration_id = 0;
3409 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3410 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3411 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3412 nullfunc->seq_ctrl = 0;
3413
3414 info = IEEE80211_SKB_CB(skb);
3415
3416 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3417 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3418
3419 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3420 skb->priority = 7;
3421 if (qos)
3422 nullfunc->qos_ctrl = cpu_to_le16(7);
3423
3424 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003425 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003426 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003427 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003428
3429 *cookie = (unsigned long) skb;
3430 return 0;
3431}
3432
Johannes Berg683b6d32012-11-08 21:25:48 +01003433static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3434 struct wireless_dev *wdev,
3435 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003436{
Johannes Berg55de9082012-07-26 17:24:39 +02003437 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003438 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003439 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003440 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003441
Johannes Berg55de9082012-07-26 17:24:39 +02003442 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003443 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3444 if (chanctx_conf) {
3445 *chandef = chanctx_conf->def;
3446 ret = 0;
3447 } else if (local->open_count > 0 &&
3448 local->open_count == local->monitors &&
3449 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3450 if (local->use_chanctx)
3451 *chandef = local->monitor_chandef;
3452 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003453 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003454 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003455 }
3456 rcu_read_unlock();
3457
Johannes Berg683b6d32012-11-08 21:25:48 +01003458 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003459}
3460
Johannes Berg6d525632012-04-04 15:05:25 +02003461#ifdef CONFIG_PM
3462static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3463{
3464 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3465}
3466#endif
3467
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003468static int ieee80211_set_qos_map(struct wiphy *wiphy,
3469 struct net_device *dev,
3470 struct cfg80211_qos_map *qos_map)
3471{
3472 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3473 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3474
3475 if (qos_map) {
3476 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3477 if (!new_qos_map)
3478 return -ENOMEM;
3479 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3480 } else {
3481 /* A NULL qos_map was passed to disable QoS mapping */
3482 new_qos_map = NULL;
3483 }
3484
Johannes Berg194ff522013-12-30 23:12:37 +01003485 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003486 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3487 if (old_qos_map)
3488 kfree_rcu(old_qos_map, rcu_head);
3489
3490 return 0;
3491}
3492
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003493static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3494 struct net_device *dev,
3495 struct cfg80211_chan_def *chandef)
3496{
3497 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3498 int ret;
3499 u32 changed = 0;
3500
3501 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3502 if (ret == 0)
3503 ieee80211_bss_info_change_notify(sdata, changed);
3504
3505 return ret;
3506}
3507
Johannes Berg8a47cea2014-01-20 23:55:44 +01003508const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003509 .add_virtual_intf = ieee80211_add_iface,
3510 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003511 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003512 .start_p2p_device = ieee80211_start_p2p_device,
3513 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003514 .add_key = ieee80211_add_key,
3515 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003516 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003517 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003518 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003519 .start_ap = ieee80211_start_ap,
3520 .change_beacon = ieee80211_change_beacon,
3521 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003522 .add_station = ieee80211_add_station,
3523 .del_station = ieee80211_del_station,
3524 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003525 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003526 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003527 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003528#ifdef CONFIG_MAC80211_MESH
3529 .add_mpath = ieee80211_add_mpath,
3530 .del_mpath = ieee80211_del_mpath,
3531 .change_mpath = ieee80211_change_mpath,
3532 .get_mpath = ieee80211_get_mpath,
3533 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003534 .update_mesh_config = ieee80211_update_mesh_config,
3535 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003536 .join_mesh = ieee80211_join_mesh,
3537 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003538#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003539 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003540 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003541 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003542 .suspend = ieee80211_suspend,
3543 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003544 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003545 .sched_scan_start = ieee80211_sched_scan_start,
3546 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003547 .auth = ieee80211_auth,
3548 .assoc = ieee80211_assoc,
3549 .deauth = ieee80211_deauth,
3550 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003551 .join_ibss = ieee80211_join_ibss,
3552 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003553 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003554 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003555 .set_tx_power = ieee80211_set_tx_power,
3556 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003557 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003558 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003559 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003560 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003561 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003562 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003563 .remain_on_channel = ieee80211_remain_on_channel,
3564 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003565 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003566 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003567 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003568 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003569 .set_antenna = ieee80211_set_antenna,
3570 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003571 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003572 .tdls_oper = ieee80211_tdls_oper,
3573 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003574 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003575 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003576#ifdef CONFIG_PM
3577 .set_wakeup = ieee80211_set_wakeup,
3578#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003579 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003580 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003581 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003582 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003583 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Jiri Bencf0706e82007-05-05 11:45:53 -07003584};