blob: 3a04f2edd3c3b93192b7a011b1f549a7a054d916 [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
Eliad Pellerf6993172014-09-10 14:07:35 +0300686 switch (params->smps_mode) {
687 case NL80211_SMPS_OFF:
688 sdata->smps_mode = IEEE80211_SMPS_OFF;
689 break;
690 case NL80211_SMPS_STATIC:
691 sdata->smps_mode = IEEE80211_SMPS_STATIC;
692 break;
693 case NL80211_SMPS_DYNAMIC:
694 sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
695 break;
696 default:
697 return -EINVAL;
698 }
Johannes Berg04ecd252012-09-11 14:34:12 +0200699 sdata->needed_rx_chains = sdata->local->rx_chains;
700
Johannes Berg34a37402013-12-18 09:43:33 +0100701 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100702 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200703 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100704 if (!err)
705 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100706 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200707 if (err)
708 return err;
709
Johannes Berg665c93a2011-11-04 11:18:11 +0100710 /*
711 * Apply control port protocol, this allows us to
712 * not encrypt dynamic WEP control frames.
713 */
714 sdata->control_port_protocol = params->crypto.control_port_ethertype;
715 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200716 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
717 &params->crypto,
718 sdata->vif.type);
719
Johannes Berg665c93a2011-11-04 11:18:11 +0100720 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
721 vlan->control_port_protocol =
722 params->crypto.control_port_ethertype;
723 vlan->control_port_no_encrypt =
724 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200725 vlan->encrypt_headroom =
726 ieee80211_cs_headroom(sdata->local,
727 &params->crypto,
728 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +0100729 }
730
Johannes Berg88600202012-02-13 15:17:18 +0100731 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
732 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100733 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100734
735 sdata->vif.bss_conf.ssid_len = params->ssid_len;
736 if (params->ssid_len)
737 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
738 params->ssid_len);
739 sdata->vif.bss_conf.hidden_ssid =
740 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
741
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100742 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
743 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
744 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
745 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
746 if (params->p2p_opp_ps)
747 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
748 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100749
Michal Kazioraf296bd2014-06-05 14:21:36 +0200750 err = ieee80211_assign_beacon(sdata, &params->beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200751 if (err < 0) {
752 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100753 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200754 }
Johannes Berg88600202012-02-13 15:17:18 +0100755 changed |= err;
756
Johannes Berg10416382012-10-19 15:44:42 +0200757 err = drv_start_ap(sdata->local, sdata);
758 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100759 old = sdata_dereference(sdata->u.ap.beacon, sdata);
760
Johannes Berg10416382012-10-19 15:44:42 +0200761 if (old)
762 kfree_rcu(old, rcu_head);
763 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +0200764 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +0200765 return err;
766 }
767
Thomas Pedersen057d5f42013-12-19 10:25:15 -0800768 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +0100769 ieee80211_bss_info_change_notify(sdata, changed);
770
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200771 netif_carrier_on(dev);
772 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
773 netif_carrier_on(vlan->dev);
774
Johannes Berg665c93a2011-11-04 11:18:11 +0100775 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100776}
777
Johannes Berg88600202012-02-13 15:17:18 +0100778static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
779 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100780{
Johannes Berg14db74b2008-07-29 13:22:52 +0200781 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100782 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100783 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100784
Johannes Berg14db74b2008-07-29 13:22:52 +0200785 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +0100786 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +0200787
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200788 /* don't allow changing the beacon while CSA is in place - offset
789 * of channel switch counter may change
790 */
791 if (sdata->vif.csa_active)
792 return -EBUSY;
793
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100794 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100795 if (!old)
796 return -ENOENT;
797
Michal Kazioraf296bd2014-06-05 14:21:36 +0200798 err = ieee80211_assign_beacon(sdata, params, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100799 if (err < 0)
800 return err;
801 ieee80211_bss_info_change_notify(sdata, err);
802 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100803}
804
Johannes Berg88600202012-02-13 15:17:18 +0100805static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100806{
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
808 struct ieee80211_sub_if_data *vlan;
809 struct ieee80211_local *local = sdata->local;
810 struct beacon_data *old_beacon;
811 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100812 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100813
Michal Kaziordbd72852014-01-29 07:56:21 +0100814 sdata_assert_lock(sdata);
815
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100816 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200817 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100818 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100819 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100820
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200821 /* abort any running channel switch */
Michal Kazior59af6922014-04-09 15:10:59 +0200822 mutex_lock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200823 sdata->vif.csa_active = false;
Luciano Coelhoa46992b2014-06-13 16:30:07 +0300824 if (sdata->csa_block_tx) {
825 ieee80211_wake_vif_queues(local, sdata,
826 IEEE80211_QUEUE_STOP_REASON_CSA);
827 sdata->csa_block_tx = false;
828 }
829
Michal Kazior59af6922014-04-09 15:10:59 +0200830 mutex_unlock(&local->mtx);
831
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +0100832 kfree(sdata->u.ap.next_beacon);
833 sdata->u.ap.next_beacon = NULL;
834
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200835 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200836 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
837 netif_carrier_off(vlan->dev);
838 netif_carrier_off(dev);
839
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200840 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000841 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200842 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
843 kfree_rcu(old_beacon, rcu_head);
844 if (old_probe_resp)
845 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +0200846 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +0100847
Johannes Berge7162512013-12-04 23:18:37 +0100848 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +0100849 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +0100850
Johannes Bergd6a83222012-12-14 14:06:28 +0100851 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +0200852 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +0100853 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200854 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100855
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200856 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100857 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200858 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +0100859 cfg80211_cac_event(sdata->dev, &chandef,
860 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +0200861 GFP_KERNEL);
862 }
863
Johannes Berg10416382012-10-19 15:44:42 +0200864 drv_stop_ap(sdata->local, sdata);
865
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200866 /* free all potentially still buffered bcast frames */
867 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
868 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
869
Johannes Berg34a37402013-12-18 09:43:33 +0100870 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +0100871 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +0200872 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +0100873 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200874
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200875 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100876}
877
Johannes Berg4fd69312007-12-19 02:03:35 +0100878/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
879struct iapp_layer2_update {
880 u8 da[ETH_ALEN]; /* broadcast */
881 u8 sa[ETH_ALEN]; /* STA addr */
882 __be16 len; /* 6 */
883 u8 dsap; /* 0 */
884 u8 ssap; /* 0 */
885 u8 control;
886 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700887} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100888
889static void ieee80211_send_layer2_update(struct sta_info *sta)
890{
891 struct iapp_layer2_update *msg;
892 struct sk_buff *skb;
893
894 /* Send Level 2 Update Frame to update forwarding tables in layer 2
895 * bridge devices */
896
897 skb = dev_alloc_skb(sizeof(*msg));
898 if (!skb)
899 return;
900 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
901
902 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
903 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
904
Johannes Berge83e6542012-07-13 16:23:07 +0200905 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200906 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100907 msg->len = htons(6);
908 msg->dsap = 0;
909 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
910 msg->control = 0xaf; /* XID response lsb.1111F101.
911 * F=0 (no poll command; unsolicited frame) */
912 msg->xid_info[0] = 0x81; /* XID format identifier */
913 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
914 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
915
Johannes Bergd0709a62008-02-25 16:27:46 +0100916 skb->dev = sta->sdata->dev;
917 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100918 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400919 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100920}
921
Johannes Bergd582cff2012-10-26 17:53:44 +0200922static int sta_apply_auth_flags(struct ieee80211_local *local,
923 struct sta_info *sta,
924 u32 mask, u32 set)
925{
926 int ret;
927
928 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
929 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
930 !test_sta_flag(sta, WLAN_STA_AUTH)) {
931 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
932 if (ret)
933 return ret;
934 }
935
936 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
937 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
938 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
939 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
940 if (ret)
941 return ret;
942 }
943
944 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
945 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
946 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
947 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
948 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
949 else
950 ret = 0;
951 if (ret)
952 return ret;
953 }
954
955 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
956 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
957 test_sta_flag(sta, WLAN_STA_ASSOC)) {
958 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
959 if (ret)
960 return ret;
961 }
962
963 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
964 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
965 test_sta_flag(sta, WLAN_STA_AUTH)) {
966 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
967 if (ret)
968 return ret;
969 }
970
971 return 0;
972}
973
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100974static int sta_apply_parameters(struct ieee80211_local *local,
975 struct sta_info *sta,
976 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100977{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100978 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100979 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100980 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +0200981 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300982 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100983
Johannes Berg55de9082012-07-26 17:24:39 +0200984 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +0200985
Johannes Bergeccb8e82009-05-11 21:57:56 +0300986 mask = params->sta_flags_mask;
987 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100988
Johannes Bergd582cff2012-10-26 17:53:44 +0200989 if (ieee80211_vif_is_mesh(&sdata->vif)) {
990 /*
991 * In mesh mode, ASSOCIATED isn't part of the nl80211
992 * API but must follow AUTHENTICATED for driver state.
993 */
994 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
995 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
996 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
997 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +0100998 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
999 /*
1000 * TDLS -- everything follows authorized, but
1001 * only becoming authorized is possible, not
1002 * going back
1003 */
1004 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1005 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1006 BIT(NL80211_STA_FLAG_ASSOCIATED);
1007 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1008 BIT(NL80211_STA_FLAG_ASSOCIATED);
1009 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001010 }
1011
Arik Nemtsov68885a52014-06-11 17:18:19 +03001012 /* auth flags will be set later for TDLS stations */
1013 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1014 ret = sta_apply_auth_flags(local, sta, mask, set);
1015 if (ret)
1016 return ret;
1017 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001018
Johannes Bergeccb8e82009-05-11 21:57:56 +03001019 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001020 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001021 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1022 else
1023 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001024 }
1025
Johannes Berga74a8c82014-07-22 14:50:47 +02001026 if (mask & BIT(NL80211_STA_FLAG_WME))
1027 sta->sta.wme = set & BIT(NL80211_STA_FLAG_WME);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001028
1029 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001030 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001031 set_sta_flag(sta, WLAN_STA_MFP);
1032 else
1033 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001034 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001035
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001036 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001037 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001038 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1039 else
1040 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001041 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001042
Johannes Berg3b9ce802011-09-27 20:56:12 +02001043 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1044 sta->sta.uapsd_queues = params->uapsd_queues;
1045 sta->sta.max_sp = params->max_sp;
1046 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001047
Johannes Berg73651ee2008-02-25 16:27:47 +01001048 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001049 * cfg80211 validates this (1-2007) and allows setting the AID
1050 * only when creating a new station entry
1051 */
1052 if (params->aid)
1053 sta->sta.aid = params->aid;
1054
1055 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001056 * Some of the following updates would be racy if called on an
1057 * existing station, via ieee80211_change_station(). However,
1058 * all such changes are rejected by cfg80211 except for updates
1059 * changing the supported rates on an existing but not yet used
1060 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001061 */
1062
Johannes Berg4fd69312007-12-19 02:03:35 +01001063 if (params->listen_interval >= 0)
1064 sta->listen_interval = params->listen_interval;
1065
1066 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001067 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1068 sband, params->supported_rates,
1069 params->supported_rates_len,
1070 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001071 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001072
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001073 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001074 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001075 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001076
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001077 if (params->vht_capa)
1078 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001079 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001080
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001081 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce142014-02-03 14:44:44 +01001082 /* returned value is only needed for rc update, but the
1083 * rc isn't initialized here yet, so ignore it
1084 */
1085 __ieee80211_vht_handle_opmode(sdata, sta,
1086 params->opmode_notif,
1087 band, false);
1088 }
1089
Javier Cardona9c3990a2011-05-03 16:57:11 -07001090 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001091#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001092 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001093
1094 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001095 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001096 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001097 if (sta->plink_state != NL80211_PLINK_ESTAB)
1098 changed = mesh_plink_inc_estab_count(
1099 sdata);
1100 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001101
1102 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001103 changed |= ieee80211_mps_set_sta_local_pm(sta,
1104 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001105 break;
1106 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001107 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001108 case NL80211_PLINK_OPN_SNT:
1109 case NL80211_PLINK_OPN_RCVD:
1110 case NL80211_PLINK_CNF_RCVD:
1111 case NL80211_PLINK_HOLDING:
1112 if (sta->plink_state == NL80211_PLINK_ESTAB)
1113 changed = mesh_plink_dec_estab_count(
1114 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001115 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001116
1117 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001118 changed |= ieee80211_mps_set_sta_local_pm(sta,
1119 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001120 break;
1121 default:
1122 /* nothing */
1123 break;
1124 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001125 }
1126
1127 switch (params->plink_action) {
1128 case NL80211_PLINK_ACTION_NO_ACTION:
1129 /* nothing */
1130 break;
1131 case NL80211_PLINK_ACTION_OPEN:
1132 changed |= mesh_plink_open(sta);
1133 break;
1134 case NL80211_PLINK_ACTION_BLOCK:
1135 changed |= mesh_plink_block(sta);
1136 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001137 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001138
1139 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001140 changed |=
1141 ieee80211_mps_set_sta_local_pm(sta,
1142 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001143 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001144#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001145 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001146
Arik Nemtsov68885a52014-06-11 17:18:19 +03001147 /* set the STA state after all sta info from usermode has been set */
1148 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1149 ret = sta_apply_auth_flags(local, sta, mask, set);
1150 if (ret)
1151 return ret;
1152 }
1153
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001154 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001155}
1156
1157static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001158 const u8 *mac,
1159 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001160{
Johannes Berg14db74b2008-07-29 13:22:52 +02001161 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001162 struct sta_info *sta;
1163 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001164 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001165 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001166
Johannes Berg4fd69312007-12-19 02:03:35 +01001167 if (params->vlan) {
1168 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1169
Johannes Berg05c914f2008-09-11 00:01:58 +02001170 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1171 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001172 return -EINVAL;
1173 } else
1174 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1175
Joe Perchesb203ca32012-05-08 18:56:52 +00001176 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001177 return -EINVAL;
1178
1179 if (is_multicast_ether_addr(mac))
1180 return -EINVAL;
1181
1182 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001183 if (!sta)
1184 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001185
Johannes Bergd582cff2012-10-26 17:53:44 +02001186 /*
1187 * defaults -- if userspace wants something else we'll
1188 * change it accordingly in sta_apply_parameters()
1189 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001190 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1191 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1192 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001193 } else {
1194 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001195 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001196
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001197 err = sta_apply_parameters(local, sta, params);
1198 if (err) {
1199 sta_info_free(local, sta);
1200 return err;
1201 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001202
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001203 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001204 * for TDLS, rate control should be initialized only when
1205 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001206 */
1207 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1208 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001209
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001210 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1211 sdata->vif.type == NL80211_IFTYPE_AP;
1212
Johannes Berg34e89502010-02-03 13:59:58 +01001213 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001214 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001215 rcu_read_unlock();
1216 return err;
1217 }
1218
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001219 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001220 ieee80211_send_layer2_update(sta);
1221
1222 rcu_read_unlock();
1223
Johannes Berg4fd69312007-12-19 02:03:35 +01001224 return 0;
1225}
1226
1227static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001228 const u8 *mac)
Johannes Berg4fd69312007-12-19 02:03:35 +01001229{
Johannes Berg14db74b2008-07-29 13:22:52 +02001230 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001231
Johannes Berg14db74b2008-07-29 13:22:52 +02001232 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1233
Johannes Berg34e89502010-02-03 13:59:58 +01001234 if (mac)
1235 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001236
Johannes Bergb998e8b2012-12-13 23:07:46 +01001237 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001238 return 0;
1239}
1240
1241static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001242 struct net_device *dev, const u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001243 struct station_parameters *params)
1244{
Johannes Bergabe60632009-11-25 17:46:18 +01001245 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001246 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001247 struct sta_info *sta;
1248 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001249 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001250 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001251
Johannes Berg87be1e12011-12-14 12:20:29 +01001252 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001253
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001254 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001255 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001256 err = -ENOENT;
1257 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001258 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001259
Johannes Berg77ee7c82013-02-15 00:48:33 +01001260 switch (sdata->vif.type) {
1261 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001262 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001263 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001264 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001265 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001266 break;
1267 case NL80211_IFTYPE_ADHOC:
1268 statype = CFG80211_STA_IBSS;
1269 break;
1270 case NL80211_IFTYPE_STATION:
1271 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1272 statype = CFG80211_STA_AP_STA;
1273 break;
1274 }
1275 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1276 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1277 else
1278 statype = CFG80211_STA_TDLS_PEER_SETUP;
1279 break;
1280 case NL80211_IFTYPE_AP:
1281 case NL80211_IFTYPE_AP_VLAN:
1282 statype = CFG80211_STA_AP_CLIENT;
1283 break;
1284 default:
1285 err = -EOPNOTSUPP;
1286 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001287 }
1288
Johannes Berg77ee7c82013-02-15 00:48:33 +01001289 err = cfg80211_check_station_change(wiphy, params, statype);
1290 if (err)
1291 goto out_err;
1292
Johannes Bergd0709a62008-02-25 16:27:46 +01001293 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001294 bool prev_4addr = false;
1295 bool new_4addr = false;
1296
Johannes Berg4fd69312007-12-19 02:03:35 +01001297 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1298
Johannes Berg9bc383d2009-11-19 11:55:19 +01001299 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001300 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001301 err = -EBUSY;
1302 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001303 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001304
Eric Dumazetcf778b02012-01-12 04:41:32 +00001305 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001306 new_4addr = true;
1307 }
1308
1309 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1310 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301311 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001312 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001313 }
1314
Johannes Berg14db74b2008-07-29 13:22:52 +02001315 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001316
1317 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1318 prev_4addr != new_4addr) {
1319 if (new_4addr)
1320 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1321 else
1322 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1323 }
1324
Johannes Berg4fd69312007-12-19 02:03:35 +01001325 ieee80211_send_layer2_update(sta);
1326 }
1327
Eliad Peller35b88622011-12-29 14:41:39 +02001328 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001329 if (err)
1330 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001331
Johannes Berg77ee7c82013-02-15 00:48:33 +01001332 /* When peer becomes authorized, init rate control as well */
1333 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1334 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001335 rate_control_rate_init(sta);
1336
Johannes Berg87be1e12011-12-14 12:20:29 +01001337 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001338
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001339 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1340 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1341 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1342 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1343 sta_info_tx_streams(sta) != 1) {
1344 ht_dbg(sta->sdata,
1345 "%pM just authorized and MIMO capable - update SMPS\n",
1346 sta->sta.addr);
1347 ieee80211_send_smps_action(sta->sdata,
1348 sta->sdata->bss->req_smps,
1349 sta->sta.addr,
1350 sta->sdata->vif.bss_conf.bssid);
1351 }
1352
Jason Young808118c2011-03-10 16:43:19 -08001353 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001354 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001355 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001356 ieee80211_recalc_ps_vif(sdata);
1357 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001358
Johannes Berg4fd69312007-12-19 02:03:35 +01001359 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001360out_err:
1361 mutex_unlock(&local->sta_mtx);
1362 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001363}
1364
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001365#ifdef CONFIG_MAC80211_MESH
1366static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001367 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001368{
Johannes Berg14db74b2008-07-29 13:22:52 +02001369 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001370 struct mesh_path *mpath;
1371 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001372
Johannes Berg14db74b2008-07-29 13:22:52 +02001373 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1374
Johannes Bergd0709a62008-02-25 16:27:46 +01001375 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001376 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001377 if (!sta) {
1378 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001379 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001380 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001381
Bob Copelandae76eef2013-03-29 09:38:39 -04001382 mpath = mesh_path_add(sdata, dst);
1383 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001384 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001385 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001386 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001387
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001388 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001389
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001390 rcu_read_unlock();
1391 return 0;
1392}
1393
1394static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001395 const u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001396{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001397 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001398
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001399 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001400 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001401
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001402 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001403 return 0;
1404}
1405
Johannes Berg3b3a0162014-05-19 17:19:31 +02001406static int ieee80211_change_mpath(struct wiphy *wiphy, struct net_device *dev,
1407 const u8 *dst, const u8 *next_hop)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001408{
Johannes Berg14db74b2008-07-29 13:22:52 +02001409 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001410 struct mesh_path *mpath;
1411 struct sta_info *sta;
1412
Johannes Berg14db74b2008-07-29 13:22:52 +02001413 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1414
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001415 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001416
Johannes Bergabe60632009-11-25 17:46:18 +01001417 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001418 if (!sta) {
1419 rcu_read_unlock();
1420 return -ENOENT;
1421 }
1422
Johannes Bergbf7cd942013-02-15 14:40:31 +01001423 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001424 if (!mpath) {
1425 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001426 return -ENOENT;
1427 }
1428
1429 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001430
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001431 rcu_read_unlock();
1432 return 0;
1433}
1434
1435static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1436 struct mpath_info *pinfo)
1437{
Johannes Berga3836e02011-05-12 15:11:37 +02001438 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1439
1440 if (next_hop_sta)
1441 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001442 else
1443 memset(next_hop, 0, ETH_ALEN);
1444
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001445 memset(pinfo, 0, sizeof(*pinfo));
1446
Johannes Bergf5ea9122009-08-07 16:17:38 +02001447 pinfo->generation = mesh_paths_generation;
1448
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001449 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001450 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001451 MPATH_INFO_METRIC |
1452 MPATH_INFO_EXPTIME |
1453 MPATH_INFO_DISCOVERY_TIMEOUT |
1454 MPATH_INFO_DISCOVERY_RETRIES |
1455 MPATH_INFO_FLAGS;
1456
1457 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001458 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001459 pinfo->metric = mpath->metric;
1460 if (time_before(jiffies, mpath->exp_time))
1461 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1462 pinfo->discovery_timeout =
1463 jiffies_to_msecs(mpath->discovery_timeout);
1464 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001465 if (mpath->flags & MESH_PATH_ACTIVE)
1466 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1467 if (mpath->flags & MESH_PATH_RESOLVING)
1468 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001469 if (mpath->flags & MESH_PATH_SN_VALID)
1470 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001471 if (mpath->flags & MESH_PATH_FIXED)
1472 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001473 if (mpath->flags & MESH_PATH_RESOLVED)
1474 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001475}
1476
1477static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1478 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1479
1480{
Johannes Berg14db74b2008-07-29 13:22:52 +02001481 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001482 struct mesh_path *mpath;
1483
Johannes Berg14db74b2008-07-29 13:22:52 +02001484 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1485
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001486 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001487 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001488 if (!mpath) {
1489 rcu_read_unlock();
1490 return -ENOENT;
1491 }
1492 memcpy(dst, mpath->dst, ETH_ALEN);
1493 mpath_set_pinfo(mpath, next_hop, pinfo);
1494 rcu_read_unlock();
1495 return 0;
1496}
1497
1498static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg3b3a0162014-05-19 17:19:31 +02001499 int idx, u8 *dst, u8 *next_hop,
1500 struct mpath_info *pinfo)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001501{
Johannes Berg14db74b2008-07-29 13:22:52 +02001502 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001503 struct mesh_path *mpath;
1504
Johannes Berg14db74b2008-07-29 13:22:52 +02001505 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1506
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001507 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001508 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001509 if (!mpath) {
1510 rcu_read_unlock();
1511 return -ENOENT;
1512 }
1513 memcpy(dst, mpath->dst, ETH_ALEN);
1514 mpath_set_pinfo(mpath, next_hop, pinfo);
1515 rcu_read_unlock();
1516 return 0;
1517}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001518
Henning Roggea2db2ed2014-09-12 08:58:50 +02001519static void mpp_set_pinfo(struct mesh_path *mpath, u8 *mpp,
1520 struct mpath_info *pinfo)
1521{
1522 memset(pinfo, 0, sizeof(*pinfo));
1523 memcpy(mpp, mpath->mpp, ETH_ALEN);
1524
1525 pinfo->generation = mpp_paths_generation;
1526}
1527
1528static int ieee80211_get_mpp(struct wiphy *wiphy, struct net_device *dev,
1529 u8 *dst, u8 *mpp, struct mpath_info *pinfo)
1530
1531{
1532 struct ieee80211_sub_if_data *sdata;
1533 struct mesh_path *mpath;
1534
1535 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1536
1537 rcu_read_lock();
1538 mpath = mpp_path_lookup(sdata, dst);
1539 if (!mpath) {
1540 rcu_read_unlock();
1541 return -ENOENT;
1542 }
1543 memcpy(dst, mpath->dst, ETH_ALEN);
1544 mpp_set_pinfo(mpath, mpp, pinfo);
1545 rcu_read_unlock();
1546 return 0;
1547}
1548
1549static int ieee80211_dump_mpp(struct wiphy *wiphy, struct net_device *dev,
1550 int idx, u8 *dst, u8 *mpp,
1551 struct mpath_info *pinfo)
1552{
1553 struct ieee80211_sub_if_data *sdata;
1554 struct mesh_path *mpath;
1555
1556 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1557
1558 rcu_read_lock();
1559 mpath = mpp_path_lookup_by_idx(sdata, idx);
1560 if (!mpath) {
1561 rcu_read_unlock();
1562 return -ENOENT;
1563 }
1564 memcpy(dst, mpath->dst, ETH_ALEN);
1565 mpp_set_pinfo(mpath, mpp, pinfo);
1566 rcu_read_unlock();
1567 return 0;
1568}
1569
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001570static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001571 struct net_device *dev,
1572 struct mesh_config *conf)
1573{
1574 struct ieee80211_sub_if_data *sdata;
1575 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1576
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001577 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1578 return 0;
1579}
1580
1581static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1582{
1583 return (mask >> (parm-1)) & 0x1;
1584}
1585
Javier Cardonac80d5452010-12-16 17:37:49 -08001586static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1587 const struct mesh_setup *setup)
1588{
1589 u8 *new_ie;
1590 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001591 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1592 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001593
Javier Cardona581a8b02011-04-07 15:08:27 -07001594 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001595 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001596 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001597
Javier Cardona581a8b02011-04-07 15:08:27 -07001598 if (setup->ie_len) {
1599 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001600 GFP_KERNEL);
1601 if (!new_ie)
1602 return -ENOMEM;
1603 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001604 ifmsh->ie_len = setup->ie_len;
1605 ifmsh->ie = new_ie;
1606 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001607
1608 /* now copy the rest of the setup parameters */
1609 ifmsh->mesh_id_len = setup->mesh_id_len;
1610 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001611 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001612 ifmsh->mesh_pp_id = setup->path_sel_proto;
1613 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001614 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001615 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001616 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1617 if (setup->is_authenticated)
1618 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1619 if (setup->is_secure)
1620 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001621
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001622 /* mcast rate setting in Mesh Node */
1623 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1624 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001625 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001626
Marco Porsch9bdbf042013-01-07 16:04:51 +01001627 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1628 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1629
Javier Cardonac80d5452010-12-16 17:37:49 -08001630 return 0;
1631}
1632
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001633static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001634 struct net_device *dev, u32 mask,
1635 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001636{
1637 struct mesh_config *conf;
1638 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001639 struct ieee80211_if_mesh *ifmsh;
1640
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001641 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001642 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001643
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001644 /* Set the config options which we are interested in setting */
1645 conf = &(sdata->u.mesh.mshcfg);
1646 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1647 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1648 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1649 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1650 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1651 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1652 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1653 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1654 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1655 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1656 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1657 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001658 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001659 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001660 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1661 if (ifmsh->user_mpm)
1662 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001663 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001664 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001665 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1666 conf->dot11MeshNbrOffsetMaxNeighbor =
1667 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001668 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1669 conf->dot11MeshHWMPmaxPREQretries =
1670 nconf->dot11MeshHWMPmaxPREQretries;
1671 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1672 conf->path_refresh_time = nconf->path_refresh_time;
1673 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1674 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1675 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1676 conf->dot11MeshHWMPactivePathTimeout =
1677 nconf->dot11MeshHWMPactivePathTimeout;
1678 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1679 conf->dot11MeshHWMPpreqMinInterval =
1680 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001681 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1682 conf->dot11MeshHWMPperrMinInterval =
1683 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001684 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1685 mask))
1686 conf->dot11MeshHWMPnetDiameterTraversalTime =
1687 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001688 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1689 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1690 ieee80211_mesh_root_setup(ifmsh);
1691 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001692 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001693 /* our current gate announcement implementation rides on root
1694 * announcements, so require this ifmsh to also be a root node
1695 * */
1696 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001697 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1698 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001699 ieee80211_mesh_root_setup(ifmsh);
1700 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001701 conf->dot11MeshGateAnnouncementProtocol =
1702 nconf->dot11MeshGateAnnouncementProtocol;
1703 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001704 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001705 conf->dot11MeshHWMPRannInterval =
1706 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001707 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1708 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001709 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1710 /* our RSSI threshold implementation is supported only for
1711 * devices that report signal in dBm.
1712 */
1713 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1714 return -ENOTSUPP;
1715 conf->rssi_threshold = nconf->rssi_threshold;
1716 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001717 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1718 conf->ht_opmode = nconf->ht_opmode;
1719 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1720 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1721 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001722 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1723 conf->dot11MeshHWMPactivePathToRootTimeout =
1724 nconf->dot11MeshHWMPactivePathToRootTimeout;
1725 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1726 conf->dot11MeshHWMProotInterval =
1727 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001728 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1729 conf->dot11MeshHWMPconfirmationInterval =
1730 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001731 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1732 conf->power_mode = nconf->power_mode;
1733 ieee80211_mps_local_status_update(sdata);
1734 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001735 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001736 conf->dot11MeshAwakeWindowDuration =
1737 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001738 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1739 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001740 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001741 return 0;
1742}
1743
Johannes Berg29cbe682010-12-03 09:20:44 +01001744static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1745 const struct mesh_config *conf,
1746 const struct mesh_setup *setup)
1747{
1748 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1749 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001750 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001751
Javier Cardonac80d5452010-12-16 17:37:49 -08001752 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1753 err = copy_mesh_setup(ifmsh, setup);
1754 if (err)
1755 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001756
Johannes Berg04ecd252012-09-11 14:34:12 +02001757 /* can mesh use other SMPS modes? */
1758 sdata->smps_mode = IEEE80211_SMPS_OFF;
1759 sdata->needed_rx_chains = sdata->local->rx_chains;
1760
Johannes Berg34a37402013-12-18 09:43:33 +01001761 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001762 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001763 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01001764 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001765 if (err)
1766 return err;
1767
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001768 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001769}
1770
1771static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1772{
1773 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1774
1775 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001776 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001777 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001778 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01001779
1780 return 0;
1781}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001782#endif
1783
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001784static int ieee80211_change_bss(struct wiphy *wiphy,
1785 struct net_device *dev,
1786 struct bss_parameters *params)
1787{
Johannes Berg55de9082012-07-26 17:24:39 +02001788 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1789 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001790 u32 changed = 0;
1791
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001792 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02001793 return -ENOENT;
1794
1795 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001796
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001797 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001798 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001799 changed |= BSS_CHANGED_ERP_CTS_PROT;
1800 }
1801 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001802 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001803 params->use_short_preamble;
1804 changed |= BSS_CHANGED_ERP_PREAMBLE;
1805 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001806
1807 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001808 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001809 sdata->vif.bss_conf.use_short_slot = true;
1810 changed |= BSS_CHANGED_ERP_SLOT;
1811 }
1812
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001813 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001814 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001815 params->use_short_slot_time;
1816 changed |= BSS_CHANGED_ERP_SLOT;
1817 }
1818
Jouni Malinen90c97a02008-10-30 16:59:22 +02001819 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001820 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1821 wiphy->bands[band],
1822 params->basic_rates,
1823 params->basic_rates_len,
1824 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001825 changed |= BSS_CHANGED_BASIC_RATES;
1826 }
1827
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001828 if (params->ap_isolate >= 0) {
1829 if (params->ap_isolate)
1830 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1831 else
1832 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1833 }
1834
Helmut Schaa80d7e402010-11-19 12:40:26 +01001835 if (params->ht_opmode >= 0) {
1836 sdata->vif.bss_conf.ht_operation_mode =
1837 (u16) params->ht_opmode;
1838 changed |= BSS_CHANGED_HT;
1839 }
1840
Johannes Berg339afbf2012-11-14 15:21:17 +01001841 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001842 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1843 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1844 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1845 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001846 changed |= BSS_CHANGED_P2P_PS;
1847 }
1848
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001849 if (params->p2p_opp_ps > 0) {
1850 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1851 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1852 changed |= BSS_CHANGED_P2P_PS;
1853 } else if (params->p2p_opp_ps == 0) {
1854 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1855 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001856 changed |= BSS_CHANGED_P2P_PS;
1857 }
1858
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001859 ieee80211_bss_info_change_notify(sdata, changed);
1860
1861 return 0;
1862}
1863
Jouni Malinen31888482008-10-30 16:59:24 +02001864static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001865 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001866 struct ieee80211_txq_params *params)
1867{
1868 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001870 struct ieee80211_tx_queue_params p;
1871
1872 if (!local->ops->conf_tx)
1873 return -EOPNOTSUPP;
1874
Johannes Berg54bcbc62012-03-28 11:04:25 +02001875 if (local->hw.queues < IEEE80211_NUM_ACS)
1876 return -EOPNOTSUPP;
1877
Jouni Malinen31888482008-10-30 16:59:24 +02001878 memset(&p, 0, sizeof(p));
1879 p.aifs = params->aifs;
1880 p.cw_max = params->cwmax;
1881 p.cw_min = params->cwmin;
1882 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001883
1884 /*
1885 * Setting tx queue params disables u-apsd because it's only
1886 * called in master mode.
1887 */
1888 p.uapsd = false;
1889
Johannes Berga3304b02012-03-28 11:04:24 +02001890 sdata->tx_conf[params->ac] = p;
1891 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001892 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001893 "failed to set TX queue parameters for AC %d\n",
1894 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001895 return -EINVAL;
1896 }
1897
Johannes Berg7d257452012-07-06 17:37:43 +02001898 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1899
Jouni Malinen31888482008-10-30 16:59:24 +02001900 return 0;
1901}
1902
Bob Copeland665af4f2009-01-19 11:20:53 -05001903#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001904static int ieee80211_suspend(struct wiphy *wiphy,
1905 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001906{
Johannes Bergeecc4802011-05-04 15:37:29 +02001907 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001908}
1909
1910static int ieee80211_resume(struct wiphy *wiphy)
1911{
1912 return __ieee80211_resume(wiphy_priv(wiphy));
1913}
1914#else
1915#define ieee80211_suspend NULL
1916#define ieee80211_resume NULL
1917#endif
1918
Johannes Berg2a519312009-02-10 21:25:55 +01001919static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001920 struct cfg80211_scan_request *req)
1921{
Johannes Bergfd014282012-06-18 19:17:03 +02001922 struct ieee80211_sub_if_data *sdata;
1923
1924 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001925
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001926 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1927 case NL80211_IFTYPE_STATION:
1928 case NL80211_IFTYPE_ADHOC:
1929 case NL80211_IFTYPE_MESH_POINT:
1930 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001931 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001932 break;
1933 case NL80211_IFTYPE_P2P_GO:
1934 if (sdata->local->ops->hw_scan)
1935 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001936 /*
1937 * FIXME: implement NoA while scanning in software,
1938 * for now fall through to allow scanning only when
1939 * beaconing hasn't been configured yet
1940 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001941 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02001942 /*
1943 * If the scan has been forced (and the driver supports
1944 * forcing), don't care about being beaconing already.
1945 * This will create problems to the attached stations (e.g. all
1946 * the frames sent while scanning on other channel will be
1947 * lost)
1948 */
1949 if (sdata->u.ap.beacon &&
1950 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1951 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001952 return -EOPNOTSUPP;
1953 break;
1954 default:
1955 return -EOPNOTSUPP;
1956 }
Johannes Berg2a519312009-02-10 21:25:55 +01001957
1958 return ieee80211_request_scan(sdata, req);
1959}
1960
Luciano Coelho79f460c2011-05-11 17:09:36 +03001961static int
1962ieee80211_sched_scan_start(struct wiphy *wiphy,
1963 struct net_device *dev,
1964 struct cfg80211_sched_scan_request *req)
1965{
1966 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1967
1968 if (!sdata->local->ops->sched_scan_start)
1969 return -EOPNOTSUPP;
1970
1971 return ieee80211_request_sched_scan_start(sdata, req);
1972}
1973
1974static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001975ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001976{
1977 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1978
1979 if (!sdata->local->ops->sched_scan_stop)
1980 return -EOPNOTSUPP;
1981
Luciano Coelho85a99942011-05-12 16:28:29 +03001982 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001983}
1984
Jouni Malinen636a5d32009-03-19 13:39:22 +02001985static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1986 struct cfg80211_auth_request *req)
1987{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001988 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001989}
1990
1991static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1992 struct cfg80211_assoc_request *req)
1993{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001994 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001995}
1996
1997static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001998 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001999{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002000 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002001}
2002
2003static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002004 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002005{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002006 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002007}
2008
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002009static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2010 struct cfg80211_ibss_params *params)
2011{
Johannes Berg55de9082012-07-26 17:24:39 +02002012 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002013}
2014
2015static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2016{
Johannes Berg55de9082012-07-26 17:24:39 +02002017 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002018}
2019
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002020static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2021 int rate[IEEE80211_NUM_BANDS])
2022{
2023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2024
Cong Ding9887dbf2013-02-06 17:23:45 +01002025 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2026 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002027
2028 return 0;
2029}
2030
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002031static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2032{
2033 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002034 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002035
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002036 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2037 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2038
2039 if (err)
2040 return err;
2041 }
2042
Lorenzo Bianconia4bcaf52014-09-04 23:57:41 +02002043 if ((changed & WIPHY_PARAM_COVERAGE_CLASS) ||
2044 (changed & WIPHY_PARAM_DYN_ACK)) {
2045 s16 coverage_class;
2046
2047 coverage_class = changed & WIPHY_PARAM_COVERAGE_CLASS ?
2048 wiphy->coverage_class : -1;
2049 err = drv_set_coverage_class(local, coverage_class);
Lukáš Turek310bc672009-12-21 22:50:48 +01002050
2051 if (err)
2052 return err;
2053 }
2054
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002055 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002056 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002057
Johannes Berg24487982009-04-23 18:52:52 +02002058 if (err)
2059 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002060 }
2061
Johannes Berg8bc83c22012-11-09 18:38:32 +01002062 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2063 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2064 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002065 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002066 }
2067 if (changed & WIPHY_PARAM_RETRY_LONG) {
2068 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2069 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002070 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002071 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002072 if (changed &
2073 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2074 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2075
2076 return 0;
2077}
2078
Johannes Berg7643a2c2009-06-02 13:01:39 +02002079static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002080 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002081 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002082{
2083 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002084 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002085
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002086 if (wdev) {
2087 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2088
2089 switch (type) {
2090 case NL80211_TX_POWER_AUTOMATIC:
2091 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2092 break;
2093 case NL80211_TX_POWER_LIMITED:
2094 case NL80211_TX_POWER_FIXED:
2095 if (mbm < 0 || (mbm % 100))
2096 return -EOPNOTSUPP;
2097 sdata->user_power_level = MBM_TO_DBM(mbm);
2098 break;
2099 }
2100
2101 ieee80211_recalc_txpower(sdata);
2102
2103 return 0;
2104 }
Johannes Berg55de9082012-07-26 17:24:39 +02002105
Johannes Berg7643a2c2009-06-02 13:01:39 +02002106 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002107 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002108 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002109 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002110 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002111 case NL80211_TX_POWER_FIXED:
2112 if (mbm < 0 || (mbm % 100))
2113 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002114 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002115 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002116 }
2117
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002118 mutex_lock(&local->iflist_mtx);
2119 list_for_each_entry(sdata, &local->interfaces, list)
2120 sdata->user_power_level = local->user_power_level;
2121 list_for_each_entry(sdata, &local->interfaces, list)
2122 ieee80211_recalc_txpower(sdata);
2123 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002124
2125 return 0;
2126}
2127
Johannes Bergc8442112012-10-24 10:17:18 +02002128static int ieee80211_get_tx_power(struct wiphy *wiphy,
2129 struct wireless_dev *wdev,
2130 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002131{
2132 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002133 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002134
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002135 if (!local->use_chanctx)
2136 *dbm = local->hw.conf.power_level;
2137 else
2138 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002139
Johannes Berg7643a2c2009-06-02 13:01:39 +02002140 return 0;
2141}
2142
Johannes Bergab737a42009-07-01 21:26:58 +02002143static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002144 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002145{
2146 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2147
2148 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2149
2150 return 0;
2151}
2152
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002153static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2154{
2155 struct ieee80211_local *local = wiphy_priv(wiphy);
2156
2157 drv_rfkill_poll(local);
2158}
2159
Johannes Bergaff89a92009-07-01 21:26:51 +02002160#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002161static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2162 struct wireless_dev *wdev,
2163 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002164{
2165 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002166 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002167
2168 if (!local->ops->testmode_cmd)
2169 return -EOPNOTSUPP;
2170
David Spinadel52981cd2013-07-31 18:06:22 +03002171 if (wdev) {
2172 struct ieee80211_sub_if_data *sdata;
2173
2174 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2175 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2176 vif = &sdata->vif;
2177 }
2178
2179 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002180}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002181
2182static int ieee80211_testmode_dump(struct wiphy *wiphy,
2183 struct sk_buff *skb,
2184 struct netlink_callback *cb,
2185 void *data, int len)
2186{
2187 struct ieee80211_local *local = wiphy_priv(wiphy);
2188
2189 if (!local->ops->testmode_dump)
2190 return -EOPNOTSUPP;
2191
2192 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2193}
Johannes Bergaff89a92009-07-01 21:26:51 +02002194#endif
2195
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002196int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2197 enum ieee80211_smps_mode smps_mode)
2198{
2199 struct sta_info *sta;
2200 enum ieee80211_smps_mode old_req;
2201 int i;
2202
2203 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2204 return -EINVAL;
2205
2206 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2207 return 0;
2208
2209 old_req = sdata->u.ap.req_smps;
2210 sdata->u.ap.req_smps = smps_mode;
2211
2212 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2213 if (old_req == smps_mode ||
2214 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2215 return 0;
2216
2217 /* If no associated stations, there's no need to do anything */
2218 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2219 sdata->smps_mode = smps_mode;
2220 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2221 return 0;
2222 }
2223
2224 ht_dbg(sdata,
2225 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2226 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2227
2228 mutex_lock(&sdata->local->sta_mtx);
2229 for (i = 0; i < STA_HASH_SIZE; i++) {
2230 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2231 lockdep_is_held(&sdata->local->sta_mtx));
2232 sta;
2233 sta = rcu_dereference_protected(sta->hnext,
2234 lockdep_is_held(&sdata->local->sta_mtx))) {
2235 /*
2236 * Only stations associated to our AP and
2237 * associated VLANs
2238 */
2239 if (sta->sdata->bss != &sdata->u.ap)
2240 continue;
2241
2242 /* This station doesn't support MIMO - skip it */
2243 if (sta_info_tx_streams(sta) == 1)
2244 continue;
2245
2246 /*
2247 * Don't wake up a STA just to send the action frame
2248 * unless we are getting more restrictive.
2249 */
2250 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2251 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2252 smps_mode)) {
2253 ht_dbg(sdata,
2254 "Won't send SMPS to sleeping STA %pM\n",
2255 sta->sta.addr);
2256 continue;
2257 }
2258
2259 /*
2260 * If the STA is not authorized, wait until it gets
2261 * authorized and the action frame will be sent then.
2262 */
2263 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2264 continue;
2265
2266 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2267 ieee80211_send_smps_action(sdata, smps_mode,
2268 sta->sta.addr,
2269 sdata->vif.bss_conf.bssid);
2270 }
2271 }
2272 mutex_unlock(&sdata->local->sta_mtx);
2273
2274 sdata->smps_mode = smps_mode;
2275 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2276
2277 return 0;
2278}
2279
2280int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2281 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002282{
2283 const u8 *ap;
2284 enum ieee80211_smps_mode old_req;
2285 int err;
2286
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002287 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002288
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002289 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2290 return -EINVAL;
2291
Johannes Berg0f782312009-12-01 13:37:02 +01002292 old_req = sdata->u.mgd.req_smps;
2293 sdata->u.mgd.req_smps = smps_mode;
2294
2295 if (old_req == smps_mode &&
2296 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2297 return 0;
2298
2299 /*
2300 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002301 * association, there's no need to do anything, just store
2302 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002303 */
2304 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002305 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002306 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002307
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002308 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002309
2310 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2311 if (sdata->u.mgd.powersave)
2312 smps_mode = IEEE80211_SMPS_DYNAMIC;
2313 else
2314 smps_mode = IEEE80211_SMPS_OFF;
2315 }
2316
2317 /* send SM PS frame to AP */
2318 err = ieee80211_send_smps_action(sdata, smps_mode,
2319 ap, ap);
2320 if (err)
2321 sdata->u.mgd.req_smps = old_req;
2322
2323 return err;
2324}
2325
Johannes Bergbc92afd2009-07-01 21:26:57 +02002326static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2327 bool enabled, int timeout)
2328{
2329 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2330 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002331
Bob Copeland2d3db212013-10-29 18:11:59 -04002332 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002333 return -EOPNOTSUPP;
2334
Johannes Bergbc92afd2009-07-01 21:26:57 +02002335 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2336 return -EOPNOTSUPP;
2337
2338 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002339 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002340 return 0;
2341
2342 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002343 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002344
Johannes Berg0f782312009-12-01 13:37:02 +01002345 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002346 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002347 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002348 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002349
Johannes Bergbc92afd2009-07-01 21:26:57 +02002350 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2351 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2352
2353 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002354 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002355
2356 return 0;
2357}
2358
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002359static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2360 struct net_device *dev,
2361 s32 rssi_thold, u32 rssi_hyst)
2362{
2363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002364 struct ieee80211_vif *vif = &sdata->vif;
2365 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2366
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002367 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2368 rssi_hyst == bss_conf->cqm_rssi_hyst)
2369 return 0;
2370
2371 bss_conf->cqm_rssi_thold = rssi_thold;
2372 bss_conf->cqm_rssi_hyst = rssi_hyst;
2373
2374 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002375 if (sdata->u.mgd.associated &&
2376 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002377 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2378
2379 return 0;
2380}
2381
Johannes Berg99303802009-07-01 21:26:59 +02002382static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2383 struct net_device *dev,
2384 const u8 *addr,
2385 const struct cfg80211_bitrate_mask *mask)
2386{
2387 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2388 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302389 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002390
Eliad Peller554a43d2012-06-12 12:41:15 +03002391 if (!ieee80211_sdata_running(sdata))
2392 return -ENETDOWN;
2393
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302394 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2395 ret = drv_set_bitrate_mask(local, sdata, mask);
2396 if (ret)
2397 return ret;
2398 }
Johannes Berg99303802009-07-01 21:26:59 +02002399
Simon Wunderlich19468412012-01-28 17:25:33 +01002400 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002401 struct ieee80211_supported_band *sband = wiphy->bands[i];
2402 int j;
2403
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002404 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002405 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2406 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002407
2408 sdata->rc_has_mcs_mask[i] = false;
2409 if (!sband)
2410 continue;
2411
2412 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2413 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2414 sdata->rc_has_mcs_mask[i] = true;
2415 break;
2416 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002417 }
Johannes Berg99303802009-07-01 21:26:59 +02002418
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002419 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002420}
2421
Eliad Pellereaa336b2014-09-03 15:25:06 +03002422static bool ieee80211_coalesce_started_roc(struct ieee80211_local *local,
2423 struct ieee80211_roc_work *new_roc,
2424 struct ieee80211_roc_work *cur_roc)
2425{
2426 unsigned long j = jiffies;
2427 unsigned long cur_roc_end = cur_roc->hw_start_time +
2428 msecs_to_jiffies(cur_roc->duration);
2429 struct ieee80211_roc_work *next_roc;
2430 int new_dur;
2431
2432 if (WARN_ON(!cur_roc->started || !cur_roc->hw_begun))
2433 return false;
2434
2435 if (time_after(j + IEEE80211_ROC_MIN_LEFT, cur_roc_end))
2436 return false;
2437
2438 ieee80211_handle_roc_started(new_roc);
2439
2440 new_dur = new_roc->duration - jiffies_to_msecs(cur_roc_end - j);
2441
2442 /* cur_roc is long enough - add new_roc to the dependents list. */
2443 if (new_dur <= 0) {
2444 list_add_tail(&new_roc->list, &cur_roc->dependents);
2445 return true;
2446 }
2447
2448 new_roc->duration = new_dur;
2449
2450 /*
2451 * if cur_roc was already coalesced before, we might
2452 * want to extend the next roc instead of adding
2453 * a new one.
2454 */
2455 next_roc = list_entry(cur_roc->list.next,
2456 struct ieee80211_roc_work, list);
2457 if (&next_roc->list != &local->roc_list &&
2458 next_roc->chan == new_roc->chan &&
2459 next_roc->sdata == new_roc->sdata &&
2460 !WARN_ON(next_roc->started)) {
2461 list_add_tail(&new_roc->list, &next_roc->dependents);
2462 next_roc->duration = max(next_roc->duration,
2463 new_roc->duration);
2464 next_roc->type = max(next_roc->type, new_roc->type);
2465 return true;
2466 }
2467
2468 /* add right after cur_roc */
2469 list_add(&new_roc->list, &cur_roc->list);
2470
2471 return true;
2472}
2473
Johannes Berg2eb278e2012-06-05 14:28:42 +02002474static int ieee80211_start_roc_work(struct ieee80211_local *local,
2475 struct ieee80211_sub_if_data *sdata,
2476 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002477 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002478 struct sk_buff *txskb,
2479 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002480{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002481 struct ieee80211_roc_work *roc, *tmp;
2482 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002483 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002484
2485 lockdep_assert_held(&local->mtx);
2486
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002487 if (local->use_chanctx && !local->ops->remain_on_channel)
2488 return -EOPNOTSUPP;
2489
Johannes Berg2eb278e2012-06-05 14:28:42 +02002490 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2491 if (!roc)
2492 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002493
Ilan Peer2fae0622013-12-19 13:25:29 +02002494 /*
2495 * If the duration is zero, then the driver
2496 * wouldn't actually do anything. Set it to
2497 * 10 for now.
2498 *
2499 * TODO: cancel the off-channel operation
2500 * when we get the SKB's TX status and
2501 * the wait time was zero before.
2502 */
2503 if (!duration)
2504 duration = 10;
2505
Johannes Berg2eb278e2012-06-05 14:28:42 +02002506 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002507 roc->duration = duration;
2508 roc->req_duration = duration;
2509 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002510 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002511 roc->mgmt_tx_cookie = (unsigned long)txskb;
2512 roc->sdata = sdata;
2513 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2514 INIT_LIST_HEAD(&roc->dependents);
2515
Eliad Peller2f617432014-01-12 11:06:37 +02002516 /*
2517 * cookie is either the roc cookie (for normal roc)
2518 * or the SKB (for mgmt TX)
2519 */
2520 if (!txskb) {
2521 /* local->mtx protects this */
2522 local->roc_cookie_counter++;
2523 roc->cookie = local->roc_cookie_counter;
2524 /* wow, you wrapped 64 bits ... more likely a bug */
2525 if (WARN_ON(roc->cookie == 0)) {
2526 roc->cookie = 1;
2527 local->roc_cookie_counter++;
2528 }
2529 *cookie = roc->cookie;
2530 } else {
2531 *cookie = (unsigned long)txskb;
2532 }
2533
Johannes Berg2eb278e2012-06-05 14:28:42 +02002534 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002535 if (!list_empty(&local->roc_list) ||
2536 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002537 goto out_check_combine;
2538
2539 /* if not HW assist, just queue & schedule work */
2540 if (!local->ops->remain_on_channel) {
2541 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2542 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002543 }
2544
Johannes Berg2eb278e2012-06-05 14:28:42 +02002545 /* otherwise actually kick it off here (for error handling) */
2546
Ilan Peerd339d5c2013-02-12 09:34:13 +02002547 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002548 if (ret) {
2549 kfree(roc);
2550 return ret;
2551 }
2552
2553 roc->started = true;
2554 goto out_queue;
2555
2556 out_check_combine:
2557 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002558 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002559 continue;
2560
2561 /*
2562 * Extend this ROC if possible:
2563 *
2564 * If it hasn't started yet, just increase the duration
2565 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002566 * If the type of the new ROC has higher priority, modify the
2567 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002568 */
2569 if (!tmp->started) {
2570 list_add_tail(&roc->list, &tmp->dependents);
2571 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002572 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002573 queued = true;
2574 break;
2575 }
2576
2577 /* If it has already started, it's more difficult ... */
2578 if (local->ops->remain_on_channel) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002579 /*
2580 * In the offloaded ROC case, if it hasn't begun, add
2581 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002582 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002583 * check that there's still a minimum time left and
2584 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002585 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002586 * a reduced time so we'll ask the driver to execute
2587 * it right after finishing the previous one, in the
2588 * hope that it'll also be executed right afterwards,
2589 * effectively extending the old one.
2590 * If there's no minimum time left, just add it to the
2591 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002592 * TODO: the ROC type is ignored here, assuming that it
2593 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002594 */
2595 if (!tmp->hw_begun) {
2596 list_add_tail(&roc->list, &tmp->dependents);
2597 queued = true;
2598 break;
2599 }
2600
Eliad Pellereaa336b2014-09-03 15:25:06 +03002601 if (ieee80211_coalesce_started_roc(local, roc, tmp))
Johannes Berg2eb278e2012-06-05 14:28:42 +02002602 queued = true;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002603 } else if (del_timer_sync(&tmp->work.timer)) {
2604 unsigned long new_end;
2605
2606 /*
2607 * In the software ROC case, cancel the timer, if
2608 * that fails then the finish work is already
2609 * queued/pending and thus we queue the new ROC
2610 * normally, if that succeeds then we can extend
2611 * the timer duration and TX the frame (if any.)
2612 */
2613
2614 list_add_tail(&roc->list, &tmp->dependents);
2615 queued = true;
2616
2617 new_end = jiffies + msecs_to_jiffies(roc->duration);
2618
2619 /* ok, it was started & we canceled timer */
2620 if (time_after(new_end, tmp->work.timer.expires))
2621 mod_timer(&tmp->work.timer, new_end);
2622 else
2623 add_timer(&tmp->work.timer);
2624
2625 ieee80211_handle_roc_started(roc);
2626 }
2627 break;
2628 }
2629
2630 out_queue:
2631 if (!queued)
2632 list_add_tail(&roc->list, &local->roc_list);
2633
Johannes Berg2eb278e2012-06-05 14:28:42 +02002634 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002635}
2636
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002637static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002638 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002639 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002640 unsigned int duration,
2641 u64 *cookie)
2642{
Johannes Berg71bbc992012-06-15 15:30:18 +02002643 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002644 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002645 int ret;
2646
Johannes Berg2eb278e2012-06-05 14:28:42 +02002647 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002648 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002649 duration, cookie, NULL,
2650 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002651 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002652
Johannes Berg2eb278e2012-06-05 14:28:42 +02002653 return ret;
2654}
2655
2656static int ieee80211_cancel_roc(struct ieee80211_local *local,
2657 u64 cookie, bool mgmt_tx)
2658{
2659 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2660 int ret;
2661
2662 mutex_lock(&local->mtx);
2663 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002664 struct ieee80211_roc_work *dep, *tmp2;
2665
2666 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002667 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002668 continue;
2669 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2670 continue;
2671 /* found dependent item -- just remove it */
2672 list_del(&dep->list);
2673 mutex_unlock(&local->mtx);
2674
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002675 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002676 return 0;
2677 }
2678
Johannes Berg50febf62012-10-26 16:13:06 +02002679 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002680 continue;
2681 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2682 continue;
2683
2684 found = roc;
2685 break;
2686 }
2687
2688 if (!found) {
2689 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002690 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002691 }
Johannes Berg21f83582010-12-18 17:20:47 +01002692
Johannes Berge979e332012-06-11 17:09:41 +02002693 /*
2694 * We found the item to cancel, so do that. Note that it
2695 * may have dependents, which we also cancel (and send
2696 * the expired signal for.) Not doing so would be quite
2697 * tricky here, but we may need to fix it later.
2698 */
2699
Johannes Berg2eb278e2012-06-05 14:28:42 +02002700 if (local->ops->remain_on_channel) {
2701 if (found->started) {
2702 ret = drv_cancel_remain_on_channel(local);
2703 if (WARN_ON_ONCE(ret)) {
2704 mutex_unlock(&local->mtx);
2705 return ret;
2706 }
2707 }
Johannes Berg21f83582010-12-18 17:20:47 +01002708
Johannes Berg2eb278e2012-06-05 14:28:42 +02002709 list_del(&found->list);
2710
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002711 if (found->started)
2712 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002713 mutex_unlock(&local->mtx);
2714
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002715 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002716 } else {
2717 /* work may be pending so use it all the time */
2718 found->abort = true;
2719 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2720
2721 mutex_unlock(&local->mtx);
2722
2723 /* work will clean up etc */
2724 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002725 WARN_ON(!found->to_be_freed);
2726 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002727 }
Johannes Berg21f83582010-12-18 17:20:47 +01002728
Johannes Berg21f83582010-12-18 17:20:47 +01002729 return 0;
2730}
2731
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002732static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002733 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002734 u64 cookie)
2735{
Johannes Berg71bbc992012-06-15 15:30:18 +02002736 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002737 struct ieee80211_local *local = sdata->local;
2738
Johannes Berg2eb278e2012-06-05 14:28:42 +02002739 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002740}
2741
Simon Wunderlich164eb022013-02-08 18:16:20 +01002742static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2743 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002744 struct cfg80211_chan_def *chandef,
2745 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002746{
2747 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2748 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002749 int err;
2750
Johannes Berg34a37402013-12-18 09:43:33 +01002751 mutex_lock(&local->mtx);
2752 if (!list_empty(&local->roc_list) || local->scanning) {
2753 err = -EBUSY;
2754 goto out_unlock;
2755 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002756
2757 /* whatever, but channel contexts should not complain about that one */
2758 sdata->smps_mode = IEEE80211_SMPS_OFF;
2759 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002760
Simon Wunderlich164eb022013-02-08 18:16:20 +01002761 err = ieee80211_vif_use_channel(sdata, chandef,
2762 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002763 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002764 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002765
Simon Wunderlich164eb022013-02-08 18:16:20 +01002766 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002767 &sdata->dfs_cac_timer_work,
2768 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002769
Johannes Berg34a37402013-12-18 09:43:33 +01002770 out_unlock:
2771 mutex_unlock(&local->mtx);
2772 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002773}
2774
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002775static struct cfg80211_beacon_data *
2776cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2777{
2778 struct cfg80211_beacon_data *new_beacon;
2779 u8 *pos;
2780 int len;
2781
2782 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2783 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2784 beacon->probe_resp_len;
2785
2786 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2787 if (!new_beacon)
2788 return NULL;
2789
2790 pos = (u8 *)(new_beacon + 1);
2791 if (beacon->head_len) {
2792 new_beacon->head_len = beacon->head_len;
2793 new_beacon->head = pos;
2794 memcpy(pos, beacon->head, beacon->head_len);
2795 pos += beacon->head_len;
2796 }
2797 if (beacon->tail_len) {
2798 new_beacon->tail_len = beacon->tail_len;
2799 new_beacon->tail = pos;
2800 memcpy(pos, beacon->tail, beacon->tail_len);
2801 pos += beacon->tail_len;
2802 }
2803 if (beacon->beacon_ies_len) {
2804 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2805 new_beacon->beacon_ies = pos;
2806 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2807 pos += beacon->beacon_ies_len;
2808 }
2809 if (beacon->proberesp_ies_len) {
2810 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2811 new_beacon->proberesp_ies = pos;
2812 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2813 pos += beacon->proberesp_ies_len;
2814 }
2815 if (beacon->assocresp_ies_len) {
2816 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2817 new_beacon->assocresp_ies = pos;
2818 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2819 pos += beacon->assocresp_ies_len;
2820 }
2821 if (beacon->probe_resp_len) {
2822 new_beacon->probe_resp_len = beacon->probe_resp_len;
2823 beacon->probe_resp = pos;
2824 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2825 pos += beacon->probe_resp_len;
2826 }
2827
2828 return new_beacon;
2829}
2830
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002831void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002832{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002833 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
2834
2835 ieee80211_queue_work(&sdata->local->hw,
2836 &sdata->csa_finalize_work);
2837}
2838EXPORT_SYMBOL(ieee80211_csa_finish);
2839
Michal Kazior66199502014-04-09 15:11:00 +02002840static int ieee80211_set_after_csa_beacon(struct ieee80211_sub_if_data *sdata,
2841 u32 *changed)
2842{
2843 int err;
2844
2845 switch (sdata->vif.type) {
2846 case NL80211_IFTYPE_AP:
Michal Kazioraf296bd2014-06-05 14:21:36 +02002847 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon,
2848 NULL);
Michal Kazior66199502014-04-09 15:11:00 +02002849 kfree(sdata->u.ap.next_beacon);
2850 sdata->u.ap.next_beacon = NULL;
2851
2852 if (err < 0)
2853 return err;
2854 *changed |= err;
2855 break;
2856 case NL80211_IFTYPE_ADHOC:
2857 err = ieee80211_ibss_finish_csa(sdata);
2858 if (err < 0)
2859 return err;
2860 *changed |= err;
2861 break;
2862#ifdef CONFIG_MAC80211_MESH
2863 case NL80211_IFTYPE_MESH_POINT:
2864 err = ieee80211_mesh_finish_csa(sdata);
2865 if (err < 0)
2866 return err;
2867 *changed |= err;
2868 break;
2869#endif
2870 default:
2871 WARN_ON(1);
2872 return -EINVAL;
2873 }
2874
2875 return 0;
2876}
2877
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002878static int __ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002879{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002880 struct ieee80211_local *local = sdata->local;
Michal Kazior66199502014-04-09 15:11:00 +02002881 u32 changed = 0;
2882 int err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002883
Michal Kaziordbd72852014-01-29 07:56:21 +01002884 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002885 lockdep_assert_held(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002886 lockdep_assert_held(&local->chanctx_mtx);
Michal Kaziordbd72852014-01-29 07:56:21 +01002887
Michal Kazior03078de2014-06-25 12:35:08 +02002888 /*
2889 * using reservation isn't immediate as it may be deferred until later
2890 * with multi-vif. once reservation is complete it will re-schedule the
2891 * work with no reserved_chanctx so verify chandef to check if it
2892 * completed successfully
2893 */
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002894
Michal Kazior03078de2014-06-25 12:35:08 +02002895 if (sdata->reserved_chanctx) {
2896 /*
2897 * with multi-vif csa driver may call ieee80211_csa_finish()
2898 * many times while waiting for other interfaces to use their
2899 * reservations
2900 */
2901 if (sdata->reserved_ready)
2902 return 0;
2903
2904 err = ieee80211_vif_use_reserved_context(sdata);
2905 if (err)
2906 return err;
2907
2908 return 0;
Arik Nemtsov7578d572013-09-01 17:15:51 +03002909 }
2910
Michal Kazior03078de2014-06-25 12:35:08 +02002911 if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
2912 &sdata->csa_chandef))
2913 return -EINVAL;
2914
Simon Wunderliche487eae2013-11-21 18:19:51 +01002915 sdata->vif.csa_active = false;
Michal Kazior97518af2014-01-29 07:56:18 +01002916
Michal Kazior66199502014-04-09 15:11:00 +02002917 err = ieee80211_set_after_csa_beacon(sdata, &changed);
2918 if (err)
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002919 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002920
Michal Kaziorfaf046e2014-01-29 07:56:17 +01002921 ieee80211_bss_info_change_notify(sdata, changed);
Michal Kazior59af6922014-04-09 15:10:59 +02002922 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
2923
Luciano Coelhoa46992b2014-06-13 16:30:07 +03002924 if (sdata->csa_block_tx) {
2925 ieee80211_wake_vif_queues(local, sdata,
2926 IEEE80211_QUEUE_STOP_REASON_CSA);
2927 sdata->csa_block_tx = false;
2928 }
Michal Kaziorcf8767d2014-05-08 09:10:02 +02002929
2930 return 0;
2931}
2932
2933static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
2934{
2935 if (__ieee80211_csa_finalize(sdata)) {
2936 sdata_info(sdata, "failed to finalize CSA, disconnecting\n");
2937 cfg80211_stop_iface(sdata->local->hw.wiphy, &sdata->wdev,
2938 GFP_KERNEL);
2939 }
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002940}
2941
2942void ieee80211_csa_finalize_work(struct work_struct *work)
2943{
2944 struct ieee80211_sub_if_data *sdata =
2945 container_of(work, struct ieee80211_sub_if_data,
2946 csa_finalize_work);
Michal Kazior59af6922014-04-09 15:10:59 +02002947 struct ieee80211_local *local = sdata->local;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002948
2949 sdata_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02002950 mutex_lock(&local->mtx);
Michal Kazior03078de2014-06-25 12:35:08 +02002951 mutex_lock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002952
Luciano Coelho66e01cf2014-01-13 19:43:00 +02002953 /* AP might have been stopped while waiting for the lock. */
2954 if (!sdata->vif.csa_active)
2955 goto unlock;
2956
2957 if (!ieee80211_sdata_running(sdata))
2958 goto unlock;
2959
2960 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002961
2962unlock:
Michal Kazior03078de2014-06-25 12:35:08 +02002963 mutex_unlock(&local->chanctx_mtx);
Michal Kazior59af6922014-04-09 15:10:59 +02002964 mutex_unlock(&local->mtx);
Simon Wunderliche487eae2013-11-21 18:19:51 +01002965 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002966}
2967
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002968static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
2969 struct cfg80211_csa_settings *params,
2970 u32 *changed)
2971{
Michal Kazioraf296bd2014-06-05 14:21:36 +02002972 struct ieee80211_csa_settings csa = {};
Michal Kazior37fa2bd2014-02-28 15:59:06 +01002973 int err;
2974
2975 switch (sdata->vif.type) {
2976 case NL80211_IFTYPE_AP:
2977 sdata->u.ap.next_beacon =
2978 cfg80211_beacon_dup(&params->beacon_after);
2979 if (!sdata->u.ap.next_beacon)
2980 return -ENOMEM;
2981
2982 /*
2983 * With a count of 0, we don't have to wait for any
2984 * TBTT before switching, so complete the CSA
2985 * immediately. In theory, with a count == 1 we
2986 * should delay the switch until just before the next
2987 * TBTT, but that would complicate things so we switch
2988 * immediately too. If we would delay the switch
2989 * until the next TBTT, we would have to set the probe
2990 * response here.
2991 *
2992 * TODO: A channel switch with count <= 1 without
2993 * sending a CSA action frame is kind of useless,
2994 * because the clients won't know we're changing
2995 * channels. The action frame must be implemented
2996 * either here or in the userspace.
2997 */
2998 if (params->count <= 1)
2999 break;
3000
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003001 if ((params->n_counter_offsets_beacon >
3002 IEEE80211_MAX_CSA_COUNTERS_NUM) ||
3003 (params->n_counter_offsets_presp >
3004 IEEE80211_MAX_CSA_COUNTERS_NUM))
3005 return -EINVAL;
Andrei Otcheretianski9a774c72014-05-09 14:11:46 +03003006
Michal Kazioraf296bd2014-06-05 14:21:36 +02003007 csa.counter_offsets_beacon = params->counter_offsets_beacon;
3008 csa.counter_offsets_presp = params->counter_offsets_presp;
3009 csa.n_counter_offsets_beacon = params->n_counter_offsets_beacon;
3010 csa.n_counter_offsets_presp = params->n_counter_offsets_presp;
3011 csa.count = params->count;
Andrei Otcheretianski0d06d9b2014-05-09 14:11:47 +03003012
Michal Kazioraf296bd2014-06-05 14:21:36 +02003013 err = ieee80211_assign_beacon(sdata, &params->beacon_csa, &csa);
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003014 if (err < 0) {
3015 kfree(sdata->u.ap.next_beacon);
3016 return err;
3017 }
3018 *changed |= err;
3019
3020 break;
3021 case NL80211_IFTYPE_ADHOC:
3022 if (!sdata->vif.bss_conf.ibss_joined)
3023 return -EINVAL;
3024
3025 if (params->chandef.width != sdata->u.ibss.chandef.width)
3026 return -EINVAL;
3027
3028 switch (params->chandef.width) {
3029 case NL80211_CHAN_WIDTH_40:
3030 if (cfg80211_get_chandef_type(&params->chandef) !=
3031 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3032 return -EINVAL;
3033 case NL80211_CHAN_WIDTH_5:
3034 case NL80211_CHAN_WIDTH_10:
3035 case NL80211_CHAN_WIDTH_20_NOHT:
3036 case NL80211_CHAN_WIDTH_20:
3037 break;
3038 default:
3039 return -EINVAL;
3040 }
3041
3042 /* changes into another band are not supported */
3043 if (sdata->u.ibss.chandef.chan->band !=
3044 params->chandef.chan->band)
3045 return -EINVAL;
3046
3047 /* see comments in the NL80211_IFTYPE_AP block */
3048 if (params->count > 1) {
3049 err = ieee80211_ibss_csa_beacon(sdata, params);
3050 if (err < 0)
3051 return err;
3052 *changed |= err;
3053 }
3054
3055 ieee80211_send_action_csa(sdata, params);
3056
3057 break;
3058#ifdef CONFIG_MAC80211_MESH
3059 case NL80211_IFTYPE_MESH_POINT: {
3060 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3061
3062 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3063 return -EINVAL;
3064
3065 /* changes into another band are not supported */
3066 if (sdata->vif.bss_conf.chandef.chan->band !=
3067 params->chandef.chan->band)
3068 return -EINVAL;
3069
3070 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3071 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3072 if (!ifmsh->pre_value)
3073 ifmsh->pre_value = 1;
3074 else
3075 ifmsh->pre_value++;
3076 }
3077
3078 /* see comments in the NL80211_IFTYPE_AP block */
3079 if (params->count > 1) {
3080 err = ieee80211_mesh_csa_beacon(sdata, params);
3081 if (err < 0) {
3082 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3083 return err;
3084 }
3085 *changed |= err;
3086 }
3087
3088 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3089 ieee80211_send_action_csa(sdata, params);
3090
3091 break;
3092 }
3093#endif
3094 default:
3095 return -EOPNOTSUPP;
3096 }
3097
3098 return 0;
3099}
3100
Luciano Coelhof29f58a2014-05-07 20:05:12 +03003101static int
3102__ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3103 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003104{
3105 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3106 struct ieee80211_local *local = sdata->local;
Michal Kazior2b327132014-04-09 15:29:32 +02003107 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003108 struct ieee80211_chanctx *chanctx;
Michal Kazior03078de2014-06-25 12:35:08 +02003109 int err, changed = 0;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003110
Michal Kaziordbd72852014-01-29 07:56:21 +01003111 sdata_assert_lock(sdata);
Michal Kazior59af6922014-04-09 15:10:59 +02003112 lockdep_assert_held(&local->mtx);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003113
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003114 if (!list_empty(&local->roc_list) || local->scanning)
3115 return -EBUSY;
3116
3117 if (sdata->wdev.cac_started)
3118 return -EBUSY;
3119
3120 if (cfg80211_chandef_identical(&params->chandef,
3121 &sdata->vif.bss_conf.chandef))
3122 return -EINVAL;
3123
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003124 /* don't allow another channel switch if one is already active. */
3125 if (sdata->vif.csa_active)
3126 return -EBUSY;
3127
Michal Kazior03078de2014-06-25 12:35:08 +02003128 mutex_lock(&local->chanctx_mtx);
3129 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3130 lockdep_is_held(&local->chanctx_mtx));
3131 if (!conf) {
3132 err = -EBUSY;
3133 goto out;
3134 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003135
Michal Kazior03078de2014-06-25 12:35:08 +02003136 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
3137 if (!chanctx) {
3138 err = -EBUSY;
3139 goto out;
3140 }
3141
3142 err = ieee80211_vif_reserve_chanctx(sdata, &params->chandef,
3143 chanctx->mode,
3144 params->radar_required);
3145 if (err)
3146 goto out;
3147
3148 /* if reservation is invalid then this will fail */
3149 err = ieee80211_check_combinations(sdata, NULL, chanctx->mode, 0);
3150 if (err) {
3151 ieee80211_vif_unreserve_chanctx(sdata);
3152 goto out;
3153 }
3154
3155 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3156 if (err) {
3157 ieee80211_vif_unreserve_chanctx(sdata);
3158 goto out;
3159 }
3160
Luciano Coelho33787fc2013-11-11 20:34:54 +02003161 sdata->csa_chandef = params->chandef;
Michal Kazior59af6922014-04-09 15:10:59 +02003162 sdata->csa_block_tx = params->block_tx;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003163 sdata->vif.csa_active = true;
3164
Michal Kazior59af6922014-04-09 15:10:59 +02003165 if (sdata->csa_block_tx)
Luciano Coelhoa46992b2014-06-13 16:30:07 +03003166 ieee80211_stop_vif_queues(local, sdata,
3167 IEEE80211_QUEUE_STOP_REASON_CSA);
Michal Kazior59af6922014-04-09 15:10:59 +02003168
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003169 if (changed) {
3170 ieee80211_bss_info_change_notify(sdata, changed);
3171 drv_channel_switch_beacon(sdata, &params->chandef);
3172 } else {
3173 /* if the beacon didn't change, we can finalize immediately */
3174 ieee80211_csa_finalize(sdata);
3175 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003176
Michal Kazior03078de2014-06-25 12:35:08 +02003177out:
3178 mutex_unlock(&local->chanctx_mtx);
3179 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003180}
3181
Michal Kazior59af6922014-04-09 15:10:59 +02003182int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3183 struct cfg80211_csa_settings *params)
3184{
3185 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3186 struct ieee80211_local *local = sdata->local;
3187 int err;
3188
3189 mutex_lock(&local->mtx);
3190 err = __ieee80211_channel_switch(wiphy, dev, params);
3191 mutex_unlock(&local->mtx);
3192
3193 return err;
3194}
3195
Johannes Berg71bbc992012-06-15 15:30:18 +02003196static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003197 struct cfg80211_mgmt_tx_params *params,
3198 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003199{
Johannes Berg71bbc992012-06-15 15:30:18 +02003200 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003201 struct ieee80211_local *local = sdata->local;
3202 struct sk_buff *skb;
3203 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003204 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003205 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003206 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003207 int ret;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003208 u8 *data;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003209
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003210 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003211 flags = IEEE80211_TX_CTL_NO_ACK;
3212 else
3213 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3214 IEEE80211_TX_CTL_REQ_TX_STATUS;
3215
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003216 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303217 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3218
Johannes Berg9d38d852010-06-09 17:20:33 +02003219 switch (sdata->vif.type) {
3220 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003221 if (!sdata->vif.bss_conf.ibss_joined)
3222 need_offchan = true;
3223 /* fall through */
3224#ifdef CONFIG_MAC80211_MESH
3225 case NL80211_IFTYPE_MESH_POINT:
3226 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3227 !sdata->u.mesh.mesh_id_len)
3228 need_offchan = true;
3229 /* fall through */
3230#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003231 case NL80211_IFTYPE_AP:
3232 case NL80211_IFTYPE_AP_VLAN:
3233 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003234 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3235 !ieee80211_vif_is_mesh(&sdata->vif) &&
3236 !rcu_access_pointer(sdata->bss->beacon))
3237 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003238 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003239 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003240 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3241 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003242 break;
3243 rcu_read_lock();
3244 sta = sta_info_get(sdata, mgmt->da);
3245 rcu_read_unlock();
3246 if (!sta)
3247 return -ENOLINK;
3248 break;
3249 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003250 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003251 if (!sdata->u.mgd.associated)
3252 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003253 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003254 case NL80211_IFTYPE_P2P_DEVICE:
3255 need_offchan = true;
3256 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003257 default:
3258 return -EOPNOTSUPP;
3259 }
3260
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003261 /* configurations requiring offchan cannot work if no channel has been
3262 * specified
3263 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003264 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003265 return -EINVAL;
3266
Johannes Berg2eb278e2012-06-05 14:28:42 +02003267 mutex_lock(&local->mtx);
3268
3269 /* Check if the operating channel is the requested channel */
3270 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003271 struct ieee80211_chanctx_conf *chanctx_conf;
3272
3273 rcu_read_lock();
3274 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3275
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003276 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003277 need_offchan = params->chan &&
3278 (params->chan !=
3279 chanctx_conf->def.chan);
3280 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003281 ret = -EINVAL;
3282 rcu_read_unlock();
3283 goto out_unlock;
3284 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003285 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003286 }
Johannes Berg55de9082012-07-26 17:24:39 +02003287 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003288 }
3289
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003290 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003291 ret = -EBUSY;
3292 goto out_unlock;
3293 }
3294
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003295 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003296 if (!skb) {
3297 ret = -ENOMEM;
3298 goto out_unlock;
3299 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003300 skb_reserve(skb, local->hw.extra_tx_headroom);
3301
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003302 data = skb_put(skb, params->len);
3303 memcpy(data, params->buf, params->len);
3304
3305 /* Update CSA counters */
3306 if (sdata->vif.csa_active &&
3307 (sdata->vif.type == NL80211_IFTYPE_AP ||
3308 sdata->vif.type == NL80211_IFTYPE_ADHOC) &&
3309 params->n_csa_offsets) {
3310 int i;
Michal Kazioraf296bd2014-06-05 14:21:36 +02003311 struct beacon_data *beacon = NULL;
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003312
Michal Kazioraf296bd2014-06-05 14:21:36 +02003313 rcu_read_lock();
3314
3315 if (sdata->vif.type == NL80211_IFTYPE_AP)
3316 beacon = rcu_dereference(sdata->u.ap.beacon);
3317 else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
3318 beacon = rcu_dereference(sdata->u.ibss.presp);
3319 else if (ieee80211_vif_is_mesh(&sdata->vif))
3320 beacon = rcu_dereference(sdata->u.mesh.beacon);
3321
3322 if (beacon)
3323 for (i = 0; i < params->n_csa_offsets; i++)
3324 data[params->csa_offsets[i]] =
3325 beacon->csa_current_counter;
3326
3327 rcu_read_unlock();
Andrei Otcheretianski387910c2014-05-09 14:11:45 +03003328 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003329
3330 IEEE80211_SKB_CB(skb)->flags = flags;
3331
Johannes Berg2eb278e2012-06-05 14:28:42 +02003332 skb->dev = sdata->dev;
3333
3334 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003335 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003336 ieee80211_tx_skb(sdata, skb);
3337 ret = 0;
3338 goto out_unlock;
3339 }
3340
Seth Forshee6c17b772013-02-11 11:21:07 -06003341 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3342 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003343 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003344 IEEE80211_SKB_CB(skb)->hw_queue =
3345 local->hw.offchannel_tx_hw_queue;
3346
Johannes Berg2eb278e2012-06-05 14:28:42 +02003347 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003348 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3349 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003350 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003351 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003352 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003353 out_unlock:
3354 mutex_unlock(&local->mtx);
3355 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003356}
3357
Johannes Bergf30221e2010-11-25 10:02:30 +01003358static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003359 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003360 u64 cookie)
3361{
Johannes Berg71bbc992012-06-15 15:30:18 +02003362 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003363
Johannes Berg2eb278e2012-06-05 14:28:42 +02003364 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003365}
3366
Johannes Berg7be50862010-10-13 12:06:24 +02003367static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003368 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003369 u16 frame_type, bool reg)
3370{
3371 struct ieee80211_local *local = wiphy_priv(wiphy);
3372
Will Hawkins6abe0562012-06-20 11:51:14 -04003373 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003374 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3375 if (reg)
3376 local->probe_req_reg++;
3377 else
3378 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003379
Felix Fietkau35f51492012-10-31 15:50:34 +01003380 if (!local->open_count)
3381 break;
3382
Will Hawkins6abe0562012-06-20 11:51:14 -04003383 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3384 break;
3385 default:
3386 break;
3387 }
Johannes Berg7be50862010-10-13 12:06:24 +02003388}
3389
Bruno Randolf15d96752010-11-10 12:50:56 +09003390static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3391{
3392 struct ieee80211_local *local = wiphy_priv(wiphy);
3393
3394 if (local->started)
3395 return -EOPNOTSUPP;
3396
3397 return drv_set_antenna(local, tx_ant, rx_ant);
3398}
3399
3400static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3401{
3402 struct ieee80211_local *local = wiphy_priv(wiphy);
3403
3404 return drv_get_antenna(local, tx_ant, rx_ant);
3405}
3406
Johannes Bergc68f4b82011-07-05 16:35:41 +02003407static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3408 struct net_device *dev,
3409 struct cfg80211_gtk_rekey_data *data)
3410{
3411 struct ieee80211_local *local = wiphy_priv(wiphy);
3412 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3413
3414 if (!local->ops->set_rekey_data)
3415 return -EOPNOTSUPP;
3416
3417 drv_set_rekey_data(local, sdata, data);
3418
3419 return 0;
3420}
3421
Johannes Berg06500732011-11-04 11:18:16 +01003422static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3423 const u8 *peer, u64 *cookie)
3424{
3425 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3426 struct ieee80211_local *local = sdata->local;
3427 struct ieee80211_qos_hdr *nullfunc;
3428 struct sk_buff *skb;
3429 int size = sizeof(*nullfunc);
3430 __le16 fc;
3431 bool qos;
3432 struct ieee80211_tx_info *info;
3433 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003434 struct ieee80211_chanctx_conf *chanctx_conf;
3435 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003436
3437 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003438 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3439 if (WARN_ON(!chanctx_conf)) {
3440 rcu_read_unlock();
3441 return -EINVAL;
3442 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003443 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003444 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003445 if (sta) {
Johannes Berga74a8c82014-07-22 14:50:47 +02003446 qos = sta->sta.wme;
Johannes Bergb4487c22011-11-11 20:22:30 +01003447 } else {
3448 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003449 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003450 }
Johannes Berg06500732011-11-04 11:18:16 +01003451
3452 if (qos) {
3453 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3454 IEEE80211_STYPE_QOS_NULLFUNC |
3455 IEEE80211_FCTL_FROMDS);
3456 } else {
3457 size -= 2;
3458 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3459 IEEE80211_STYPE_NULLFUNC |
3460 IEEE80211_FCTL_FROMDS);
3461 }
3462
3463 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003464 if (!skb) {
3465 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003466 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003467 }
Johannes Berg06500732011-11-04 11:18:16 +01003468
3469 skb->dev = dev;
3470
3471 skb_reserve(skb, local->hw.extra_tx_headroom);
3472
3473 nullfunc = (void *) skb_put(skb, size);
3474 nullfunc->frame_control = fc;
3475 nullfunc->duration_id = 0;
3476 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3477 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3478 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3479 nullfunc->seq_ctrl = 0;
3480
3481 info = IEEE80211_SKB_CB(skb);
3482
3483 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3484 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3485
3486 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3487 skb->priority = 7;
3488 if (qos)
3489 nullfunc->qos_ctrl = cpu_to_le16(7);
3490
3491 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003492 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003493 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003494 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003495
3496 *cookie = (unsigned long) skb;
3497 return 0;
3498}
3499
Johannes Berg683b6d32012-11-08 21:25:48 +01003500static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3501 struct wireless_dev *wdev,
3502 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003503{
Johannes Berg55de9082012-07-26 17:24:39 +02003504 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003505 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003506 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003507 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003508
Johannes Berg55de9082012-07-26 17:24:39 +02003509 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003510 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3511 if (chanctx_conf) {
3512 *chandef = chanctx_conf->def;
3513 ret = 0;
3514 } else if (local->open_count > 0 &&
3515 local->open_count == local->monitors &&
3516 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3517 if (local->use_chanctx)
3518 *chandef = local->monitor_chandef;
3519 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003520 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003521 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003522 }
3523 rcu_read_unlock();
3524
Johannes Berg683b6d32012-11-08 21:25:48 +01003525 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003526}
3527
Johannes Berg6d525632012-04-04 15:05:25 +02003528#ifdef CONFIG_PM
3529static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3530{
3531 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3532}
3533#endif
3534
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003535static int ieee80211_set_qos_map(struct wiphy *wiphy,
3536 struct net_device *dev,
3537 struct cfg80211_qos_map *qos_map)
3538{
3539 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3540 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3541
3542 if (qos_map) {
3543 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3544 if (!new_qos_map)
3545 return -ENOMEM;
3546 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3547 } else {
3548 /* A NULL qos_map was passed to disable QoS mapping */
3549 new_qos_map = NULL;
3550 }
3551
Johannes Berg194ff522013-12-30 23:12:37 +01003552 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003553 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3554 if (old_qos_map)
3555 kfree_rcu(old_qos_map, rcu_head);
3556
3557 return 0;
3558}
3559
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003560static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3561 struct net_device *dev,
3562 struct cfg80211_chan_def *chandef)
3563{
3564 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3565 int ret;
3566 u32 changed = 0;
3567
3568 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3569 if (ret == 0)
3570 ieee80211_bss_info_change_notify(sdata, changed);
3571
3572 return ret;
3573}
3574
Johannes Berg8a47cea2014-01-20 23:55:44 +01003575const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003576 .add_virtual_intf = ieee80211_add_iface,
3577 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003578 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003579 .start_p2p_device = ieee80211_start_p2p_device,
3580 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003581 .add_key = ieee80211_add_key,
3582 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003583 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003584 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003585 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003586 .start_ap = ieee80211_start_ap,
3587 .change_beacon = ieee80211_change_beacon,
3588 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003589 .add_station = ieee80211_add_station,
3590 .del_station = ieee80211_del_station,
3591 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003592 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003593 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003594 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003595#ifdef CONFIG_MAC80211_MESH
3596 .add_mpath = ieee80211_add_mpath,
3597 .del_mpath = ieee80211_del_mpath,
3598 .change_mpath = ieee80211_change_mpath,
3599 .get_mpath = ieee80211_get_mpath,
3600 .dump_mpath = ieee80211_dump_mpath,
Henning Roggea2db2ed2014-09-12 08:58:50 +02003601 .get_mpp = ieee80211_get_mpp,
3602 .dump_mpp = ieee80211_dump_mpp,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003603 .update_mesh_config = ieee80211_update_mesh_config,
3604 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003605 .join_mesh = ieee80211_join_mesh,
3606 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003607#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003608 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003609 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003610 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003611 .suspend = ieee80211_suspend,
3612 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003613 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003614 .sched_scan_start = ieee80211_sched_scan_start,
3615 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003616 .auth = ieee80211_auth,
3617 .assoc = ieee80211_assoc,
3618 .deauth = ieee80211_deauth,
3619 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003620 .join_ibss = ieee80211_join_ibss,
3621 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003622 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003623 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003624 .set_tx_power = ieee80211_set_tx_power,
3625 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003626 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003627 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003628 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003629 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003630 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003631 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003632 .remain_on_channel = ieee80211_remain_on_channel,
3633 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003634 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003635 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003636 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003637 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003638 .set_antenna = ieee80211_set_antenna,
3639 .get_antenna = ieee80211_get_antenna,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003640 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003641 .tdls_oper = ieee80211_tdls_oper,
3642 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003643 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003644 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003645#ifdef CONFIG_PM
3646 .set_wakeup = ieee80211_set_wakeup,
3647#endif
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003648 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003649 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003650 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003651 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003652 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Jiri Bencf0706e82007-05-05 11:45:53 -07003653};