blob: 44449ceb79664026037113126e2f13d0ed0ca16a [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>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg552bff02012-09-19 09:26:06 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
24 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020025 enum nl80211_iftype type,
26 u32 *flags,
27 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070028{
29 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020030 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010031 struct ieee80211_sub_if_data *sdata;
32 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg84efbb82012-06-16 00:00:26 +020034 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010035 if (err)
36 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010037
Johannes Bergf9e10ce2010-12-03 09:20:42 +010038 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020039 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 sdata->u.mntr_flags = *flags;
41 }
42
Johannes Berg84efbb82012-06-16 00:00:26 +020043 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070044}
45
Johannes Berg84efbb82012-06-16 00:00:26 +020046static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070047{
Johannes Berg84efbb82012-06-16 00:00:26 +020048 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Johannes Berg75636522008-07-09 14:40:35 +020050 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070051}
52
Johannes Berge36d56b2009-06-09 21:04:43 +020053static int ieee80211_change_iface(struct wiphy *wiphy,
54 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010055 enum nl80211_iftype type, u32 *flags,
56 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020057{
Johannes Berg9607e6b2009-12-23 13:15:31 +010058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020060
Johannes Berg05c914f2008-09-11 00:01:58 +020061 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020062 if (ret)
63 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020064
Johannes Berg9bc383d2009-11-19 11:55:19 +010065 if (type == NL80211_IFTYPE_AP_VLAN &&
66 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000067 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010068 else if (type == NL80211_IFTYPE_STATION &&
69 params && params->use_4addr >= 0)
70 sdata->u.mgd.use_4addr = params->use_4addr;
71
Christian Lamparter85416a42010-10-02 13:17:07 +020072 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
73 struct ieee80211_local *local = sdata->local;
74
75 if (ieee80211_sdata_running(sdata)) {
Felix Fietkau31eba5b2013-05-28 13:01:53 +020076 u32 mask = MONITOR_FLAG_COOK_FRAMES |
77 MONITOR_FLAG_ACTIVE;
78
Christian Lamparter85416a42010-10-02 13:17:07 +020079 /*
Felix Fietkau31eba5b2013-05-28 13:01:53 +020080 * Prohibit MONITOR_FLAG_COOK_FRAMES and
81 * MONITOR_FLAG_ACTIVE to be changed while the
82 * interface is up.
Christian Lamparter85416a42010-10-02 13:17:07 +020083 * Else we would need to add a lot of cruft
84 * to update everything:
85 * cooked_mntrs, monitor and all fif_* counters
86 * reconfigure hardware
87 */
Felix Fietkau31eba5b2013-05-28 13:01:53 +020088 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
Christian Lamparter85416a42010-10-02 13:17:07 +020089 return -EBUSY;
90
91 ieee80211_adjust_monitor_flags(sdata, -1);
92 sdata->u.mntr_flags = *flags;
93 ieee80211_adjust_monitor_flags(sdata, 1);
94
95 ieee80211_configure_filter(local);
96 } else {
97 /*
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
101 */
102 sdata->u.mntr_flags = *flags;
103 }
104 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200105
Johannes Berg42613db2007-09-28 21:52:27 +0200106 return 0;
107}
108
Johannes Bergf142c6b2012-06-18 20:07:15 +0200109static int ieee80211_start_p2p_device(struct wiphy *wiphy,
110 struct wireless_dev *wdev)
111{
112 return ieee80211_do_open(wdev, true);
113}
114
115static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
116 struct wireless_dev *wdev)
117{
118 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
119}
120
Simon Wunderlichb53be792011-11-18 14:20:44 +0100121static int ieee80211_set_noack_map(struct wiphy *wiphy,
122 struct net_device *dev,
123 u16 noack_map)
124{
125 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
126
127 sdata->noack_map = noack_map;
128 return 0;
129}
130
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100131static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200132 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100133 struct key_params *params)
134{
Johannes Berg26a58452010-08-27 12:35:55 +0200135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100136 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100137 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200138 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100139
Johannes Berg26a58452010-08-27 12:35:55 +0200140 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200141 return -ENETDOWN;
142
Johannes Berg97359d12010-08-10 09:46:38 +0200143 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100144 switch (params->cipher) {
145 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100146 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200147 case WLAN_CIPHER_SUITE_WEP104:
148 if (IS_ERR(sdata->local->wep_tx_tfm))
149 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200150 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100151 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200152 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100153 }
154
Johannes Berg97359d12010-08-10 09:46:38 +0200155 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
156 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100157 if (IS_ERR(key))
158 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100159
Johannes Berge31b8212010-10-05 19:39:30 +0200160 if (pairwise)
161 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
162
Johannes Bergad0e2b52010-06-01 10:19:19 +0200163 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200164
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100165 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700166 if (ieee80211_vif_is_mesh(&sdata->vif))
167 sta = sta_info_get(sdata, mac_addr);
168 else
169 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100170 /*
171 * The ASSOC test makes sure the driver is ready to
172 * receive the key. When wpa_supplicant has roamed
173 * using FT, it attempts to set the key before
174 * association has completed, this rejects that attempt
175 * so it will set the key again after assocation.
176 *
177 * TODO: accept the key if we have a station entry and
178 * add it to the device after the station.
179 */
180 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100181 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200182 err = -ENOENT;
183 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100184 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100185 }
186
Johannes Berge548c492012-09-04 17:08:23 +0200187 switch (sdata->vif.type) {
188 case NL80211_IFTYPE_STATION:
189 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
190 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
191 break;
192 case NL80211_IFTYPE_AP:
193 case NL80211_IFTYPE_AP_VLAN:
194 /* Keys without a station are used for TX only */
195 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
196 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
197 break;
198 case NL80211_IFTYPE_ADHOC:
199 /* no MFP (yet) */
200 break;
201 case NL80211_IFTYPE_MESH_POINT:
202#ifdef CONFIG_MAC80211_MESH
203 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
204 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
205 break;
206#endif
207 case NL80211_IFTYPE_WDS:
208 case NL80211_IFTYPE_MONITOR:
209 case NL80211_IFTYPE_P2P_DEVICE:
210 case NL80211_IFTYPE_UNSPECIFIED:
211 case NUM_NL80211_IFTYPES:
212 case NL80211_IFTYPE_P2P_CLIENT:
213 case NL80211_IFTYPE_P2P_GO:
214 /* shouldn't happen */
215 WARN_ON_ONCE(1);
216 break;
217 }
218
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300219 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100220
Johannes Berg3b967662008-04-08 17:56:52 +0200221 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200222 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200223
224 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100225}
226
227static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200228 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100229{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200230 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
231 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100232 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200233 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100234 int ret;
235
Johannes Berg5c0c3642011-05-12 14:31:49 +0200236 mutex_lock(&local->sta_mtx);
237 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200238
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100239 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200240 ret = -ENOENT;
241
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100242 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100243 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200244 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100245
Johannes Berg5c0c3642011-05-12 14:31:49 +0200246 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200247 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200248 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200249 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200250 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200251 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100252
Johannes Berg5c0c3642011-05-12 14:31:49 +0200253 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200254 ret = -ENOENT;
255 goto out_unlock;
256 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100257
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100258 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100259
Johannes Berg3b967662008-04-08 17:56:52 +0200260 ret = 0;
261 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200262 mutex_unlock(&local->key_mtx);
263 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200264
265 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100266}
267
Johannes Berg62da92f2007-12-19 02:03:31 +0100268static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200269 u8 key_idx, bool pairwise, const u8 *mac_addr,
270 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100271 void (*callback)(void *cookie,
272 struct key_params *params))
273{
Johannes Berg14db74b2008-07-29 13:22:52 +0200274 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100275 struct sta_info *sta = NULL;
276 u8 seq[6] = {0};
277 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200278 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200279 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100280 u32 iv32;
281 u16 iv16;
282 int err = -ENOENT;
283
Johannes Berg14db74b2008-07-29 13:22:52 +0200284 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
285
Johannes Berg3b967662008-04-08 17:56:52 +0200286 rcu_read_lock();
287
Johannes Berg62da92f2007-12-19 02:03:31 +0100288 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100289 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100290 if (!sta)
291 goto out;
292
Johannes Berge31b8212010-10-05 19:39:30 +0200293 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200294 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200295 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200296 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100297 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200298 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100299
300 if (!key)
301 goto out;
302
303 memset(&params, 0, sizeof(params));
304
Johannes Berg97359d12010-08-10 09:46:38 +0200305 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100306
Johannes Berg97359d12010-08-10 09:46:38 +0200307 switch (key->conf.cipher) {
308 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700309 iv32 = key->u.tkip.tx.iv32;
310 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100311
Johannes Berg24487982009-04-23 18:52:52 +0200312 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
313 drv_get_tkip_seq(sdata->local,
314 key->conf.hw_key_idx,
315 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100316
317 seq[0] = iv16 & 0xff;
318 seq[1] = (iv16 >> 8) & 0xff;
319 seq[2] = iv32 & 0xff;
320 seq[3] = (iv32 >> 8) & 0xff;
321 seq[4] = (iv32 >> 16) & 0xff;
322 seq[5] = (iv32 >> 24) & 0xff;
323 params.seq = seq;
324 params.seq_len = 6;
325 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200326 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200327 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
328 seq[0] = pn64;
329 seq[1] = pn64 >> 8;
330 seq[2] = pn64 >> 16;
331 seq[3] = pn64 >> 24;
332 seq[4] = pn64 >> 32;
333 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100334 params.seq = seq;
335 params.seq_len = 6;
336 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200337 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200338 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
339 seq[0] = pn64;
340 seq[1] = pn64 >> 8;
341 seq[2] = pn64 >> 16;
342 seq[3] = pn64 >> 24;
343 seq[4] = pn64 >> 32;
344 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200345 params.seq = seq;
346 params.seq_len = 6;
347 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100348 }
349
350 params.key = key->conf.key;
351 params.key_len = key->conf.keylen;
352
353 callback(cookie, &params);
354 err = 0;
355
356 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200357 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100358 return err;
359}
360
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100361static int ieee80211_config_default_key(struct wiphy *wiphy,
362 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 u8 key_idx, bool uni,
364 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100365{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200366 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100367
Johannes Bergf7e01042010-12-09 19:49:02 +0100368 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100369
370 return 0;
371}
372
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200373static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
374 struct net_device *dev,
375 u8 key_idx)
376{
Johannes Berg66c52422010-07-22 13:58:51 +0200377 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200378
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200379 ieee80211_set_default_mgmt_key(sdata, key_idx);
380
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200381 return 0;
382}
383
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800384void sta_set_rate_info_tx(struct sta_info *sta,
385 const struct ieee80211_tx_rate *rate,
386 struct rate_info *rinfo)
387{
388 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100389 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800390 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100391 rinfo->mcs = rate->idx;
392 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
393 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
394 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
395 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
396 } else {
397 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200398 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
399 u16 brate;
400
Johannes Berg8bc83c22012-11-09 18:38:32 +0100401 sband = sta->local->hw.wiphy->bands[
402 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200403 brate = sband->bitrates[rate->idx].bitrate;
404 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100405 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800406 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
407 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100408 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
409 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
410 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
411 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800412 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
413 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800414}
415
Saravana003e6762012-11-28 18:29:38 +0530416void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
417{
418 rinfo->flags = 0;
419
420 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
421 rinfo->flags |= RATE_INFO_FLAGS_MCS;
422 rinfo->mcs = sta->last_rx_rate_idx;
423 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
424 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
425 rinfo->nss = sta->last_rx_rate_vht_nss;
426 rinfo->mcs = sta->last_rx_rate_idx;
427 } else {
428 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200429 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
430 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530431
432 sband = sta->local->hw.wiphy->bands[
433 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200434 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
435 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530436 }
437
438 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
439 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
440 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
441 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
442 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
443 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
444 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
445 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
446 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
447 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
448}
449
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100450static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
451{
Johannes Bergd0709a62008-02-25 16:27:46 +0100452 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300453 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530454 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100455 u64 packets = 0;
Felix Fietkauef0621e2013-04-22 16:29:31 +0200456 int i, ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100457
Johannes Bergf5ea9122009-08-07 16:17:38 +0200458 sinfo->generation = sdata->local->sta_generation;
459
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100460 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100461 STATION_INFO_RX_BYTES64 |
462 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200463 STATION_INFO_RX_PACKETS |
464 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900465 STATION_INFO_TX_RETRIES |
466 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700467 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100468 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700469 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530470 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200471 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800472 STATION_INFO_STA_FLAGS |
473 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530474
475 do_posix_clock_monotonic_gettime(&uptime);
476 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100477
478 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100479 sinfo->tx_bytes = 0;
480 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
481 sinfo->tx_bytes += sta->tx_bytes[ac];
482 packets += sta->tx_packets[ac];
483 }
484 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100485 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200486 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900487 sinfo->tx_retries = sta->tx_retry_count;
488 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700489 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800490 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100491
John W. Linville19deffb2009-12-08 17:10:13 -0500492 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
493 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900494 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300495 if (!local->ops->get_rssi ||
496 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
497 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900498 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100499 }
Felix Fietkauef0621e2013-04-22 16:29:31 +0200500 if (sta->chains) {
501 sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
502 STATION_INFO_CHAIN_SIGNAL_AVG;
503
504 sinfo->chains = sta->chains;
505 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
506 sinfo->chain_signal[i] = sta->chain_signal_last[i];
507 sinfo->chain_signal_avg[i] =
508 (s8) -ewma_read(&sta->chain_signal_avg[i]);
509 }
510 }
Henning Rogge420e7fa2008-12-11 22:04:19 +0100511
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800512 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530513 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100514
Johannes Berg902acc72008-02-23 15:17:19 +0100515 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100516#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100517 sinfo->filled |= STATION_INFO_LLID |
518 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100519 STATION_INFO_PLINK_STATE |
520 STATION_INFO_LOCAL_PM |
521 STATION_INFO_PEER_PM |
522 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100523
524 sinfo->llid = le16_to_cpu(sta->llid);
525 sinfo->plid = le16_to_cpu(sta->plid);
526 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700527 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
528 sinfo->filled |= STATION_INFO_T_OFFSET;
529 sinfo->t_offset = sta->t_offset;
530 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100531 sinfo->local_pm = sta->local_pm;
532 sinfo->peer_pm = sta->peer_pm;
533 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100534#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100535 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700536
537 sinfo->bss_param.flags = 0;
538 if (sdata->vif.bss_conf.use_cts_prot)
539 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
540 if (sdata->vif.bss_conf.use_short_preamble)
541 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
542 if (sdata->vif.bss_conf.use_short_slot)
543 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
544 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
545 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200546
547 sinfo->sta_flags.set = 0;
548 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
549 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
550 BIT(NL80211_STA_FLAG_WME) |
551 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100552 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200553 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100554 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200555 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
556 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
557 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
558 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
559 if (test_sta_flag(sta, WLAN_STA_WME))
560 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
561 if (test_sta_flag(sta, WLAN_STA_MFP))
562 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
563 if (test_sta_flag(sta, WLAN_STA_AUTH))
564 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200565 if (test_sta_flag(sta, WLAN_STA_ASSOC))
566 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100567 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
568 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100569}
570
Ben Greearb1ab7922012-04-23 12:50:30 -0700571static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
572 "rx_packets", "rx_bytes", "wep_weak_iv_count",
573 "rx_duplicates", "rx_fragments", "rx_dropped",
574 "tx_packets", "tx_bytes", "tx_fragments",
575 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700576 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
577 "channel", "noise", "ch_time", "ch_time_busy",
578 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700579};
580#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
581
582static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
583 struct net_device *dev,
584 int sset)
585{
Ben Greeare3521142012-04-23 12:50:31 -0700586 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
587 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700588
Ben Greeare3521142012-04-23 12:50:31 -0700589 if (sset == ETH_SS_STATS)
590 rv += STA_STATS_LEN;
591
592 rv += drv_get_et_sset_count(sdata, sset);
593
594 if (rv == 0)
595 return -EOPNOTSUPP;
596 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700597}
598
599static void ieee80211_get_et_stats(struct wiphy *wiphy,
600 struct net_device *dev,
601 struct ethtool_stats *stats,
602 u64 *data)
603{
604 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200605 struct ieee80211_chanctx_conf *chanctx_conf;
606 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700607 struct sta_info *sta;
608 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700609 struct station_info sinfo;
610 struct survey_info survey;
611 int i, q;
612#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700613
614 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
615
616#define ADD_STA_STATS(sta) \
617 do { \
618 data[i++] += sta->rx_packets; \
619 data[i++] += sta->rx_bytes; \
620 data[i++] += sta->wep_weak_iv_count; \
621 data[i++] += sta->num_duplicates; \
622 data[i++] += sta->rx_fragments; \
623 data[i++] += sta->rx_dropped; \
624 \
Johannes Berg560d2682013-02-05 10:55:21 +0100625 data[i++] += sinfo.tx_packets; \
626 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700627 data[i++] += sta->tx_fragments; \
628 data[i++] += sta->tx_filtered_count; \
629 data[i++] += sta->tx_retry_failed; \
630 data[i++] += sta->tx_retry_count; \
631 data[i++] += sta->beacon_loss_count; \
632 } while (0)
633
634 /* For Managed stations, find the single station based on BSSID
635 * and use that. For interface types, iterate through all available
636 * stations and add stats for any station that is assigned to this
637 * network device.
638 */
639
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300640 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700641
642 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
643 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700644
645 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
646 goto do_survey;
647
Johannes Berg560d2682013-02-05 10:55:21 +0100648 sinfo.filled = 0;
649 sta_set_sinfo(sta, &sinfo);
650
Ben Greear3073a7c2012-04-23 12:50:32 -0700651 i = 0;
652 ADD_STA_STATS(sta);
653
654 data[i++] = sta->sta_state;
655
Ben Greear3073a7c2012-04-23 12:50:32 -0700656
Joe Perches52042672012-05-30 13:25:54 -0700657 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700658 data[i] = 100000 *
659 cfg80211_calculate_bitrate(&sinfo.txrate);
660 i++;
Joe Perches52042672012-05-30 13:25:54 -0700661 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700662 data[i] = 100000 *
663 cfg80211_calculate_bitrate(&sinfo.rxrate);
664 i++;
665
Joe Perches52042672012-05-30 13:25:54 -0700666 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700667 data[i] = (u8)sinfo.signal_avg;
668 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700669 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300670 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700671 /* Make sure this station belongs to the proper dev */
672 if (sta->sdata->dev != dev)
673 continue;
674
675 i = 0;
676 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700677 }
678 }
679
Ben Greear3073a7c2012-04-23 12:50:32 -0700680do_survey:
681 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
682 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200683 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700684
Johannes Berg55de9082012-07-26 17:24:39 +0200685 rcu_read_lock();
686 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
687 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100688 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200689 else
690 channel = NULL;
691 rcu_read_unlock();
692
693 if (channel) {
694 q = 0;
695 do {
696 survey.filled = 0;
697 if (drv_get_survey(local, q, &survey) != 0) {
698 survey.filled = 0;
699 break;
700 }
701 q++;
702 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700703 }
704
705 if (survey.filled)
706 data[i++] = survey.channel->center_freq;
707 else
708 data[i++] = 0;
709 if (survey.filled & SURVEY_INFO_NOISE_DBM)
710 data[i++] = (u8)survey.noise;
711 else
712 data[i++] = -1LL;
713 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
714 data[i++] = survey.channel_time;
715 else
716 data[i++] = -1LL;
717 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
718 data[i++] = survey.channel_time_busy;
719 else
720 data[i++] = -1LL;
721 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
722 data[i++] = survey.channel_time_ext_busy;
723 else
724 data[i++] = -1LL;
725 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
726 data[i++] = survey.channel_time_rx;
727 else
728 data[i++] = -1LL;
729 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
730 data[i++] = survey.channel_time_tx;
731 else
732 data[i++] = -1LL;
733
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300734 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700735
Ben Greear3073a7c2012-04-23 12:50:32 -0700736 if (WARN_ON(i != STA_STATS_LEN))
737 return;
738
Ben Greeare3521142012-04-23 12:50:31 -0700739 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700740}
741
742static void ieee80211_get_et_strings(struct wiphy *wiphy,
743 struct net_device *dev,
744 u32 sset, u8 *data)
745{
Ben Greeare3521142012-04-23 12:50:31 -0700746 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
747 int sz_sta_stats = 0;
748
Ben Greearb1ab7922012-04-23 12:50:30 -0700749 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700750 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Johannes Bergbd500af2013-05-06 21:09:46 +0200751 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700752 }
Ben Greeare3521142012-04-23 12:50:31 -0700753 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700754}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100755
756static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
757 int idx, u8 *mac, struct station_info *sinfo)
758{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100759 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300760 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100761 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100762 int ret = -ENOENT;
763
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300764 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100765
Johannes Berg3b53fde82009-11-16 12:00:37 +0100766 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100767 if (sta) {
768 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200769 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100770 sta_set_sinfo(sta, sinfo);
771 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100772
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300773 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100774
Johannes Bergd0709a62008-02-25 16:27:46 +0100775 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100776}
777
Holger Schurig12897232010-04-19 10:23:57 +0200778static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
779 int idx, struct survey_info *survey)
780{
781 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
782
Holger Schurig12897232010-04-19 10:23:57 +0200783 return drv_get_survey(local, idx, survey);
784}
785
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100786static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100787 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100788{
Johannes Bergabe60632009-11-25 17:46:18 +0100789 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300790 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100791 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100792 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100793
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300794 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100795
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100796 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100797 if (sta) {
798 ret = 0;
799 sta_set_sinfo(sta, sinfo);
800 }
801
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300802 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100803
804 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100805}
806
Johannes Berge8c9bd52012-06-06 08:18:22 +0200807static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100808 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200809{
Johannes Berg55de9082012-07-26 17:24:39 +0200810 struct ieee80211_local *local = wiphy_priv(wiphy);
811 struct ieee80211_sub_if_data *sdata;
812 int ret = 0;
813
Johannes Berg4bf88532012-11-09 11:39:59 +0100814 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200815 return 0;
816
817 mutex_lock(&local->iflist_mtx);
818 if (local->use_chanctx) {
819 sdata = rcu_dereference_protected(
820 local->monitor_sdata,
821 lockdep_is_held(&local->iflist_mtx));
822 if (sdata) {
823 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100824 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200825 IEEE80211_CHANCTX_EXCLUSIVE);
826 }
827 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100828 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200829 ieee80211_hw_config(local, 0);
830 }
831
Johannes Berg4bf88532012-11-09 11:39:59 +0100832 if (ret == 0)
833 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200834 mutex_unlock(&local->iflist_mtx);
835
836 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200837}
838
Arik Nemtsov02945822011-11-10 11:28:57 +0200839static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100840 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200841{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300842 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200843
844 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530845 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200846
Arik Nemtsovf7248282011-11-19 10:51:26 +0200847 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200848
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300849 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200850 if (!new)
851 return -ENOMEM;
852
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300853 new->len = resp_len;
854 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200855
856 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300857 if (old)
858 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200859
860 return 0;
861}
862
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200863int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
864 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100865{
866 struct beacon_data *new, *old;
867 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100868 int size, err;
869 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100870
Johannes Berg40b275b2011-05-13 14:15:49 +0200871 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100872
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100873 /* Need to have a beacon head if we don't have one yet */
874 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100875 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100876
877 /* new or old head? */
878 if (params->head)
879 new_head_len = params->head_len;
880 else
881 new_head_len = old->head_len;
882
883 /* new or old tail? */
884 if (params->tail || !old)
885 /* params->tail_len will be zero for !params->tail */
886 new_tail_len = params->tail_len;
887 else
888 new_tail_len = old->tail_len;
889
890 size = sizeof(*new) + new_head_len + new_tail_len;
891
892 new = kzalloc(size, GFP_KERNEL);
893 if (!new)
894 return -ENOMEM;
895
896 /* start filling the new info now */
897
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100898 /*
899 * pointers go into the block we allocated,
900 * memory is | beacon_data | head | tail |
901 */
902 new->head = ((u8 *) new) + sizeof(*new);
903 new->tail = new->head + new_head_len;
904 new->head_len = new_head_len;
905 new->tail_len = new_tail_len;
906
907 /* copy in head */
908 if (params->head)
909 memcpy(new->head, params->head, new_head_len);
910 else
911 memcpy(new->head, old->head, new_head_len);
912
913 /* copy in optional tail */
914 if (params->tail)
915 memcpy(new->tail, params->tail, new_tail_len);
916 else
917 if (old)
918 memcpy(new->tail, old->tail, new_tail_len);
919
Johannes Berg88600202012-02-13 15:17:18 +0100920 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
921 params->probe_resp_len);
922 if (err < 0)
923 return err;
924 if (err == 0)
925 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100926
Eric Dumazetcf778b02012-01-12 04:41:32 +0000927 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100928
Johannes Berg88600202012-02-13 15:17:18 +0100929 if (old)
930 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100931
Johannes Berg88600202012-02-13 15:17:18 +0100932 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100933}
934
Johannes Berg88600202012-02-13 15:17:18 +0100935static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
936 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100937{
Johannes Berg88600202012-02-13 15:17:18 +0100938 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100939 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100940 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100941 u32 changed = BSS_CHANGED_BEACON_INT |
942 BSS_CHANGED_BEACON_ENABLED |
943 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100944 BSS_CHANGED_SSID |
945 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100946 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200947
Johannes Berg40b275b2011-05-13 14:15:49 +0200948 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100949 if (old)
950 return -EALREADY;
951
Johannes Berg04ecd252012-09-11 14:34:12 +0200952 /* TODO: make hostapd tell us what it wants */
953 sdata->smps_mode = IEEE80211_SMPS_OFF;
954 sdata->needed_rx_chains = sdata->local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +0100955 sdata->radar_required = params->radar_required;
Johannes Berg04ecd252012-09-11 14:34:12 +0200956
Johannes Berg4bf88532012-11-09 11:39:59 +0100957 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200958 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200959 if (err)
960 return err;
Johannes Berg1f4ac5a2013-02-08 12:07:44 +0100961 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Bergaa430da2012-05-16 23:50:18 +0200962
Johannes Berg665c93a2011-11-04 11:18:11 +0100963 /*
964 * Apply control port protocol, this allows us to
965 * not encrypt dynamic WEP control frames.
966 */
967 sdata->control_port_protocol = params->crypto.control_port_ethertype;
968 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
969 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
970 vlan->control_port_protocol =
971 params->crypto.control_port_ethertype;
972 vlan->control_port_no_encrypt =
973 params->crypto.control_port_no_encrypt;
974 }
975
Johannes Berg88600202012-02-13 15:17:18 +0100976 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
977 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100978 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100979
980 sdata->vif.bss_conf.ssid_len = params->ssid_len;
981 if (params->ssid_len)
982 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
983 params->ssid_len);
984 sdata->vif.bss_conf.hidden_ssid =
985 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
986
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100987 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
988 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
989 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
990 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
991 if (params->p2p_opp_ps)
992 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
993 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100994
Johannes Berg88600202012-02-13 15:17:18 +0100995 err = ieee80211_assign_beacon(sdata, &params->beacon);
996 if (err < 0)
997 return err;
998 changed |= err;
999
Johannes Berg10416382012-10-19 15:44:42 +02001000 err = drv_start_ap(sdata->local, sdata);
1001 if (err) {
1002 old = rtnl_dereference(sdata->u.ap.beacon);
1003 if (old)
1004 kfree_rcu(old, rcu_head);
1005 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1006 return err;
1007 }
1008
Johannes Berg88600202012-02-13 15:17:18 +01001009 ieee80211_bss_info_change_notify(sdata, changed);
1010
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001011 netif_carrier_on(dev);
1012 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1013 netif_carrier_on(vlan->dev);
1014
Johannes Berg665c93a2011-11-04 11:18:11 +01001015 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001016}
1017
Johannes Berg88600202012-02-13 15:17:18 +01001018static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1019 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001020{
Johannes Berg14db74b2008-07-29 13:22:52 +02001021 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001022 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001023 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001024
Johannes Berg14db74b2008-07-29 13:22:52 +02001025 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1026
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001027 /* don't allow changing the beacon while CSA is in place - offset
1028 * of channel switch counter may change
1029 */
1030 if (sdata->vif.csa_active)
1031 return -EBUSY;
1032
Johannes Berg40b275b2011-05-13 14:15:49 +02001033 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001034 if (!old)
1035 return -ENOENT;
1036
Johannes Berg88600202012-02-13 15:17:18 +01001037 err = ieee80211_assign_beacon(sdata, params);
1038 if (err < 0)
1039 return err;
1040 ieee80211_bss_info_change_notify(sdata, err);
1041 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001042}
1043
Johannes Berg88600202012-02-13 15:17:18 +01001044static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001045{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001046 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1047 struct ieee80211_sub_if_data *vlan;
1048 struct ieee80211_local *local = sdata->local;
1049 struct beacon_data *old_beacon;
1050 struct probe_resp *old_probe_resp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001051
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001052 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1053 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001054 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001055 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001056
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001057 /* abort any running channel switch */
1058 sdata->vif.csa_active = false;
1059 cancel_work_sync(&sdata->csa_finalize_work);
1060
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001061 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001062 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1063 netif_carrier_off(vlan->dev);
1064 netif_carrier_off(dev);
1065
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001066 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001067 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001068 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1069 kfree_rcu(old_beacon, rcu_head);
1070 if (old_probe_resp)
1071 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001072
Felix Fietkau2d4072a2012-12-10 20:02:34 +01001073 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
Johannes Berg75de9112012-12-14 14:56:03 +01001074 sta_info_flush_defer(vlan);
1075 sta_info_flush_defer(sdata);
Bob Copeland8ceb5952013-04-18 18:26:49 -04001076 synchronize_net();
Johannes Berg75de9112012-12-14 14:56:03 +01001077 rcu_barrier();
Johannes Berg7b4396b2013-02-23 01:14:20 +01001078 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
Johannes Berg75de9112012-12-14 14:56:03 +01001079 sta_info_flush_cleanup(vlan);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001080 ieee80211_free_keys(vlan);
1081 }
Johannes Berg75de9112012-12-14 14:56:03 +01001082 sta_info_flush_cleanup(sdata);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001083 ieee80211_free_keys(sdata);
Johannes Berg75de9112012-12-14 14:56:03 +01001084
Johannes Bergd6a83222012-12-14 14:06:28 +01001085 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001086 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001087 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001088 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001089
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001090 if (sdata->wdev.cac_started) {
1091 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1092 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
1093 GFP_KERNEL);
1094 }
1095
Johannes Berg10416382012-10-19 15:44:42 +02001096 drv_stop_ap(sdata->local, sdata);
1097
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001098 /* free all potentially still buffered bcast frames */
1099 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1100 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1101
Johannes Berg1f4ac5a2013-02-08 12:07:44 +01001102 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001103 ieee80211_vif_release_channel(sdata);
1104
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001105 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001106}
1107
Johannes Berg4fd69312007-12-19 02:03:35 +01001108/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1109struct iapp_layer2_update {
1110 u8 da[ETH_ALEN]; /* broadcast */
1111 u8 sa[ETH_ALEN]; /* STA addr */
1112 __be16 len; /* 6 */
1113 u8 dsap; /* 0 */
1114 u8 ssap; /* 0 */
1115 u8 control;
1116 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001117} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001118
1119static void ieee80211_send_layer2_update(struct sta_info *sta)
1120{
1121 struct iapp_layer2_update *msg;
1122 struct sk_buff *skb;
1123
1124 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1125 * bridge devices */
1126
1127 skb = dev_alloc_skb(sizeof(*msg));
1128 if (!skb)
1129 return;
1130 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1131
1132 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1133 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1134
Johannes Berge83e6542012-07-13 16:23:07 +02001135 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001136 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001137 msg->len = htons(6);
1138 msg->dsap = 0;
1139 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1140 msg->control = 0xaf; /* XID response lsb.1111F101.
1141 * F=0 (no poll command; unsolicited frame) */
1142 msg->xid_info[0] = 0x81; /* XID format identifier */
1143 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1144 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1145
Johannes Bergd0709a62008-02-25 16:27:46 +01001146 skb->dev = sta->sdata->dev;
1147 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001148 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001149 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001150}
1151
Johannes Bergd582cff2012-10-26 17:53:44 +02001152static int sta_apply_auth_flags(struct ieee80211_local *local,
1153 struct sta_info *sta,
1154 u32 mask, u32 set)
1155{
1156 int ret;
1157
1158 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1159 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1160 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1161 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1162 if (ret)
1163 return ret;
1164 }
1165
1166 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1167 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1168 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1169 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1170 if (ret)
1171 return ret;
1172 }
1173
1174 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1175 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1176 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1177 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1178 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1179 else
1180 ret = 0;
1181 if (ret)
1182 return ret;
1183 }
1184
1185 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1186 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1187 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1188 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1189 if (ret)
1190 return ret;
1191 }
1192
1193 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1194 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1195 test_sta_flag(sta, WLAN_STA_AUTH)) {
1196 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1197 if (ret)
1198 return ret;
1199 }
1200
1201 return 0;
1202}
1203
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001204static int sta_apply_parameters(struct ieee80211_local *local,
1205 struct sta_info *sta,
1206 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001207{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001208 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001209 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001210 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001211 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001212 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001213
Johannes Berg55de9082012-07-26 17:24:39 +02001214 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001215
Johannes Bergeccb8e82009-05-11 21:57:56 +03001216 mask = params->sta_flags_mask;
1217 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001218
Johannes Bergd582cff2012-10-26 17:53:44 +02001219 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1220 /*
1221 * In mesh mode, ASSOCIATED isn't part of the nl80211
1222 * API but must follow AUTHENTICATED for driver state.
1223 */
1224 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1225 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1226 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1227 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001228 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1229 /*
1230 * TDLS -- everything follows authorized, but
1231 * only becoming authorized is possible, not
1232 * going back
1233 */
1234 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1235 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1236 BIT(NL80211_STA_FLAG_ASSOCIATED);
1237 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1238 BIT(NL80211_STA_FLAG_ASSOCIATED);
1239 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001240 }
1241
Johannes Bergd582cff2012-10-26 17:53:44 +02001242 ret = sta_apply_auth_flags(local, sta, mask, set);
1243 if (ret)
1244 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001245
Johannes Bergeccb8e82009-05-11 21:57:56 +03001246 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001247 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001248 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1249 else
1250 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001251 }
1252
1253 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001254 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001255 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001256 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001257 } else {
1258 clear_sta_flag(sta, WLAN_STA_WME);
1259 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001260 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001261 }
1262
1263 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001264 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001265 set_sta_flag(sta, WLAN_STA_MFP);
1266 else
1267 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001268 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001269
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001270 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001271 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001272 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1273 else
1274 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001275 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001276
Johannes Berg3b9ce802011-09-27 20:56:12 +02001277 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1278 sta->sta.uapsd_queues = params->uapsd_queues;
1279 sta->sta.max_sp = params->max_sp;
1280 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001281
Johannes Berg73651ee2008-02-25 16:27:47 +01001282 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001283 * cfg80211 validates this (1-2007) and allows setting the AID
1284 * only when creating a new station entry
1285 */
1286 if (params->aid)
1287 sta->sta.aid = params->aid;
1288
1289 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001290 * Some of the following updates would be racy if called on an
1291 * existing station, via ieee80211_change_station(). However,
1292 * all such changes are rejected by cfg80211 except for updates
1293 * changing the supported rates on an existing but not yet used
1294 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001295 */
1296
Johannes Berg4fd69312007-12-19 02:03:35 +01001297 if (params->listen_interval >= 0)
1298 sta->listen_interval = params->listen_interval;
1299
1300 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001301 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1302 sband, params->supported_rates,
1303 params->supported_rates_len,
1304 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001305 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001306
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001307 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001308 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001309 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001310
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001311 if (params->vht_capa)
1312 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001313 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001314
Javier Cardona9c3990a2011-05-03 16:57:11 -07001315 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001316#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001317 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001318
1319 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001320 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001321 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001322 if (sta->plink_state != NL80211_PLINK_ESTAB)
1323 changed = mesh_plink_inc_estab_count(
1324 sdata);
1325 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001326
1327 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001328 changed |= ieee80211_mps_set_sta_local_pm(sta,
1329 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001330 break;
1331 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001332 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001333 case NL80211_PLINK_OPN_SNT:
1334 case NL80211_PLINK_OPN_RCVD:
1335 case NL80211_PLINK_CNF_RCVD:
1336 case NL80211_PLINK_HOLDING:
1337 if (sta->plink_state == NL80211_PLINK_ESTAB)
1338 changed = mesh_plink_dec_estab_count(
1339 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001340 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001341
1342 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001343 changed |=
1344 ieee80211_mps_local_status_update(sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001345 break;
1346 default:
1347 /* nothing */
1348 break;
1349 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001350 }
1351
1352 switch (params->plink_action) {
1353 case NL80211_PLINK_ACTION_NO_ACTION:
1354 /* nothing */
1355 break;
1356 case NL80211_PLINK_ACTION_OPEN:
1357 changed |= mesh_plink_open(sta);
1358 break;
1359 case NL80211_PLINK_ACTION_BLOCK:
1360 changed |= mesh_plink_block(sta);
1361 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001362 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001363
1364 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001365 changed |=
1366 ieee80211_mps_set_sta_local_pm(sta,
1367 params->local_pm);
1368 ieee80211_bss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001369#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001370 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001371
1372 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001373}
1374
1375static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1376 u8 *mac, struct station_parameters *params)
1377{
Johannes Berg14db74b2008-07-29 13:22:52 +02001378 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001379 struct sta_info *sta;
1380 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001381 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001382 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001383
Johannes Berg4fd69312007-12-19 02:03:35 +01001384 if (params->vlan) {
1385 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1386
Johannes Berg05c914f2008-09-11 00:01:58 +02001387 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1388 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001389 return -EINVAL;
1390 } else
1391 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1392
Joe Perchesb203ca32012-05-08 18:56:52 +00001393 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001394 return -EINVAL;
1395
1396 if (is_multicast_ether_addr(mac))
1397 return -EINVAL;
1398
1399 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001400 if (!sta)
1401 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001402
Johannes Bergd582cff2012-10-26 17:53:44 +02001403 /*
1404 * defaults -- if userspace wants something else we'll
1405 * change it accordingly in sta_apply_parameters()
1406 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001407 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1408 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1409 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1410 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001411
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001412 err = sta_apply_parameters(local, sta, params);
1413 if (err) {
1414 sta_info_free(local, sta);
1415 return err;
1416 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001417
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001418 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001419 * for TDLS, rate control should be initialized only when
1420 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001421 */
1422 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1423 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001424
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001425 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1426 sdata->vif.type == NL80211_IFTYPE_AP;
1427
Johannes Berg34e89502010-02-03 13:59:58 +01001428 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001429 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001430 rcu_read_unlock();
1431 return err;
1432 }
1433
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001434 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001435 ieee80211_send_layer2_update(sta);
1436
1437 rcu_read_unlock();
1438
Johannes Berg4fd69312007-12-19 02:03:35 +01001439 return 0;
1440}
1441
1442static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1443 u8 *mac)
1444{
Johannes Berg14db74b2008-07-29 13:22:52 +02001445 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001446
Johannes Berg14db74b2008-07-29 13:22:52 +02001447 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1448
Johannes Berg34e89502010-02-03 13:59:58 +01001449 if (mac)
1450 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001451
Johannes Bergb998e8b2012-12-13 23:07:46 +01001452 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001453 return 0;
1454}
1455
1456static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001457 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001458 struct station_parameters *params)
1459{
Johannes Bergabe60632009-11-25 17:46:18 +01001460 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001461 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001462 struct sta_info *sta;
1463 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001464 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001465 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001466
Johannes Berg87be1e12011-12-14 12:20:29 +01001467 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001468
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001469 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001470 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001471 err = -ENOENT;
1472 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001473 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001474
Johannes Berg77ee7c82013-02-15 00:48:33 +01001475 switch (sdata->vif.type) {
1476 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001477 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001478 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001479 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001480 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001481 break;
1482 case NL80211_IFTYPE_ADHOC:
1483 statype = CFG80211_STA_IBSS;
1484 break;
1485 case NL80211_IFTYPE_STATION:
1486 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1487 statype = CFG80211_STA_AP_STA;
1488 break;
1489 }
1490 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1491 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1492 else
1493 statype = CFG80211_STA_TDLS_PEER_SETUP;
1494 break;
1495 case NL80211_IFTYPE_AP:
1496 case NL80211_IFTYPE_AP_VLAN:
1497 statype = CFG80211_STA_AP_CLIENT;
1498 break;
1499 default:
1500 err = -EOPNOTSUPP;
1501 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001502 }
1503
Johannes Berg77ee7c82013-02-15 00:48:33 +01001504 err = cfg80211_check_station_change(wiphy, params, statype);
1505 if (err)
1506 goto out_err;
1507
Johannes Bergd0709a62008-02-25 16:27:46 +01001508 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001509 bool prev_4addr = false;
1510 bool new_4addr = false;
1511
Johannes Berg4fd69312007-12-19 02:03:35 +01001512 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1513
Johannes Berg9bc383d2009-11-19 11:55:19 +01001514 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001515 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001516 err = -EBUSY;
1517 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001518 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001519
Eric Dumazetcf778b02012-01-12 04:41:32 +00001520 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001521 new_4addr = true;
1522 }
1523
1524 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1525 sta->sdata->u.vlan.sta) {
1526 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1527 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001528 }
1529
Johannes Berg14db74b2008-07-29 13:22:52 +02001530 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001531
1532 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1533 prev_4addr != new_4addr) {
1534 if (new_4addr)
1535 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1536 else
1537 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1538 }
1539
Johannes Berg4fd69312007-12-19 02:03:35 +01001540 ieee80211_send_layer2_update(sta);
1541 }
1542
Eliad Peller35b88622011-12-29 14:41:39 +02001543 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001544 if (err)
1545 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001546
Johannes Berg77ee7c82013-02-15 00:48:33 +01001547 /* When peer becomes authorized, init rate control as well */
1548 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1549 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001550 rate_control_rate_init(sta);
1551
Johannes Berg87be1e12011-12-14 12:20:29 +01001552 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001553
Jason Young808118c2011-03-10 16:43:19 -08001554 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001555 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001556 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001557 ieee80211_recalc_ps_vif(sdata);
1558 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001559
Johannes Berg4fd69312007-12-19 02:03:35 +01001560 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001561out_err:
1562 mutex_unlock(&local->sta_mtx);
1563 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001564}
1565
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001566#ifdef CONFIG_MAC80211_MESH
1567static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1568 u8 *dst, u8 *next_hop)
1569{
Johannes Berg14db74b2008-07-29 13:22:52 +02001570 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001571 struct mesh_path *mpath;
1572 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001573
Johannes Berg14db74b2008-07-29 13:22:52 +02001574 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1575
Johannes Bergd0709a62008-02-25 16:27:46 +01001576 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001577 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001578 if (!sta) {
1579 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001580 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001581 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001582
Bob Copelandae76eef2013-03-29 09:38:39 -04001583 mpath = mesh_path_add(sdata, dst);
1584 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001585 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001586 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001587 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001588
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001589 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001590
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001591 rcu_read_unlock();
1592 return 0;
1593}
1594
1595static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001596 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001597{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001598 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001599
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001600 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001601 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001602
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001603 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001604 return 0;
1605}
1606
1607static int ieee80211_change_mpath(struct wiphy *wiphy,
1608 struct net_device *dev,
1609 u8 *dst, u8 *next_hop)
1610{
Johannes Berg14db74b2008-07-29 13:22:52 +02001611 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001612 struct mesh_path *mpath;
1613 struct sta_info *sta;
1614
Johannes Berg14db74b2008-07-29 13:22:52 +02001615 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1616
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001617 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001618
Johannes Bergabe60632009-11-25 17:46:18 +01001619 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001620 if (!sta) {
1621 rcu_read_unlock();
1622 return -ENOENT;
1623 }
1624
Johannes Bergbf7cd942013-02-15 14:40:31 +01001625 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001626 if (!mpath) {
1627 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001628 return -ENOENT;
1629 }
1630
1631 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001632
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001633 rcu_read_unlock();
1634 return 0;
1635}
1636
1637static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1638 struct mpath_info *pinfo)
1639{
Johannes Berga3836e02011-05-12 15:11:37 +02001640 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1641
1642 if (next_hop_sta)
1643 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001644 else
1645 memset(next_hop, 0, ETH_ALEN);
1646
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001647 memset(pinfo, 0, sizeof(*pinfo));
1648
Johannes Bergf5ea9122009-08-07 16:17:38 +02001649 pinfo->generation = mesh_paths_generation;
1650
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001651 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001652 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001653 MPATH_INFO_METRIC |
1654 MPATH_INFO_EXPTIME |
1655 MPATH_INFO_DISCOVERY_TIMEOUT |
1656 MPATH_INFO_DISCOVERY_RETRIES |
1657 MPATH_INFO_FLAGS;
1658
1659 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001660 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001661 pinfo->metric = mpath->metric;
1662 if (time_before(jiffies, mpath->exp_time))
1663 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1664 pinfo->discovery_timeout =
1665 jiffies_to_msecs(mpath->discovery_timeout);
1666 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001667 if (mpath->flags & MESH_PATH_ACTIVE)
1668 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1669 if (mpath->flags & MESH_PATH_RESOLVING)
1670 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001671 if (mpath->flags & MESH_PATH_SN_VALID)
1672 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001673 if (mpath->flags & MESH_PATH_FIXED)
1674 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001675 if (mpath->flags & MESH_PATH_RESOLVED)
1676 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001677}
1678
1679static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1680 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1681
1682{
Johannes Berg14db74b2008-07-29 13:22:52 +02001683 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001684 struct mesh_path *mpath;
1685
Johannes Berg14db74b2008-07-29 13:22:52 +02001686 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1687
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001688 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001689 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001690 if (!mpath) {
1691 rcu_read_unlock();
1692 return -ENOENT;
1693 }
1694 memcpy(dst, mpath->dst, ETH_ALEN);
1695 mpath_set_pinfo(mpath, next_hop, pinfo);
1696 rcu_read_unlock();
1697 return 0;
1698}
1699
1700static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1701 int idx, u8 *dst, u8 *next_hop,
1702 struct mpath_info *pinfo)
1703{
Johannes Berg14db74b2008-07-29 13:22:52 +02001704 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001705 struct mesh_path *mpath;
1706
Johannes Berg14db74b2008-07-29 13:22:52 +02001707 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1708
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001709 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001710 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001711 if (!mpath) {
1712 rcu_read_unlock();
1713 return -ENOENT;
1714 }
1715 memcpy(dst, mpath->dst, ETH_ALEN);
1716 mpath_set_pinfo(mpath, next_hop, pinfo);
1717 rcu_read_unlock();
1718 return 0;
1719}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001720
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001721static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001722 struct net_device *dev,
1723 struct mesh_config *conf)
1724{
1725 struct ieee80211_sub_if_data *sdata;
1726 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1727
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001728 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1729 return 0;
1730}
1731
1732static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1733{
1734 return (mask >> (parm-1)) & 0x1;
1735}
1736
Javier Cardonac80d5452010-12-16 17:37:49 -08001737static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1738 const struct mesh_setup *setup)
1739{
1740 u8 *new_ie;
1741 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001742 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1743 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001744
Javier Cardona581a8b02011-04-07 15:08:27 -07001745 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001746 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001747 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001748
Javier Cardona581a8b02011-04-07 15:08:27 -07001749 if (setup->ie_len) {
1750 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001751 GFP_KERNEL);
1752 if (!new_ie)
1753 return -ENOMEM;
1754 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001755 ifmsh->ie_len = setup->ie_len;
1756 ifmsh->ie = new_ie;
1757 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001758
1759 /* now copy the rest of the setup parameters */
1760 ifmsh->mesh_id_len = setup->mesh_id_len;
1761 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001762 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001763 ifmsh->mesh_pp_id = setup->path_sel_proto;
1764 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001765 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001766 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001767 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1768 if (setup->is_authenticated)
1769 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1770 if (setup->is_secure)
1771 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001772
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001773 /* mcast rate setting in Mesh Node */
1774 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1775 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001776 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001777
Marco Porsch9bdbf042013-01-07 16:04:51 +01001778 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1779 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1780
Javier Cardonac80d5452010-12-16 17:37:49 -08001781 return 0;
1782}
1783
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001784static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001785 struct net_device *dev, u32 mask,
1786 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001787{
1788 struct mesh_config *conf;
1789 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001790 struct ieee80211_if_mesh *ifmsh;
1791
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001792 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001793 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001794
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001795 /* Set the config options which we are interested in setting */
1796 conf = &(sdata->u.mesh.mshcfg);
1797 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1798 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1799 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1800 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1801 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1802 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1803 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1804 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1805 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1806 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1807 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1808 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001809 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001810 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001811 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1812 if (ifmsh->user_mpm)
1813 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001814 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001815 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001816 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1817 conf->dot11MeshNbrOffsetMaxNeighbor =
1818 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001819 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1820 conf->dot11MeshHWMPmaxPREQretries =
1821 nconf->dot11MeshHWMPmaxPREQretries;
1822 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1823 conf->path_refresh_time = nconf->path_refresh_time;
1824 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1825 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1826 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1827 conf->dot11MeshHWMPactivePathTimeout =
1828 nconf->dot11MeshHWMPactivePathTimeout;
1829 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1830 conf->dot11MeshHWMPpreqMinInterval =
1831 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001832 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1833 conf->dot11MeshHWMPperrMinInterval =
1834 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001835 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1836 mask))
1837 conf->dot11MeshHWMPnetDiameterTraversalTime =
1838 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001839 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1840 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1841 ieee80211_mesh_root_setup(ifmsh);
1842 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001843 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001844 /* our current gate announcement implementation rides on root
1845 * announcements, so require this ifmsh to also be a root node
1846 * */
1847 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001848 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1849 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001850 ieee80211_mesh_root_setup(ifmsh);
1851 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001852 conf->dot11MeshGateAnnouncementProtocol =
1853 nconf->dot11MeshGateAnnouncementProtocol;
1854 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001855 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001856 conf->dot11MeshHWMPRannInterval =
1857 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001858 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1859 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001860 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1861 /* our RSSI threshold implementation is supported only for
1862 * devices that report signal in dBm.
1863 */
1864 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1865 return -ENOTSUPP;
1866 conf->rssi_threshold = nconf->rssi_threshold;
1867 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001868 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1869 conf->ht_opmode = nconf->ht_opmode;
1870 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1871 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1872 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001873 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1874 conf->dot11MeshHWMPactivePathToRootTimeout =
1875 nconf->dot11MeshHWMPactivePathToRootTimeout;
1876 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1877 conf->dot11MeshHWMProotInterval =
1878 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001879 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1880 conf->dot11MeshHWMPconfirmationInterval =
1881 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001882 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1883 conf->power_mode = nconf->power_mode;
1884 ieee80211_mps_local_status_update(sdata);
1885 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001886 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001887 conf->dot11MeshAwakeWindowDuration =
1888 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001889 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1890 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001891 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001892 return 0;
1893}
1894
Johannes Berg29cbe682010-12-03 09:20:44 +01001895static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1896 const struct mesh_config *conf,
1897 const struct mesh_setup *setup)
1898{
1899 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1900 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001901 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001902
Javier Cardonac80d5452010-12-16 17:37:49 -08001903 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1904 err = copy_mesh_setup(ifmsh, setup);
1905 if (err)
1906 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001907
Johannes Berg04ecd252012-09-11 14:34:12 +02001908 /* can mesh use other SMPS modes? */
1909 sdata->smps_mode = IEEE80211_SMPS_OFF;
1910 sdata->needed_rx_chains = sdata->local->rx_chains;
1911
Johannes Berg4bf88532012-11-09 11:39:59 +01001912 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001913 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001914 if (err)
1915 return err;
1916
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001917 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001918}
1919
1920static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1921{
1922 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1923
1924 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001925 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001926
1927 return 0;
1928}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001929#endif
1930
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001931static int ieee80211_change_bss(struct wiphy *wiphy,
1932 struct net_device *dev,
1933 struct bss_parameters *params)
1934{
Johannes Berg55de9082012-07-26 17:24:39 +02001935 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1936 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001937 u32 changed = 0;
1938
Johannes Berg55de9082012-07-26 17:24:39 +02001939 if (!rtnl_dereference(sdata->u.ap.beacon))
1940 return -ENOENT;
1941
1942 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001943
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001944 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001945 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001946 changed |= BSS_CHANGED_ERP_CTS_PROT;
1947 }
1948 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001949 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001950 params->use_short_preamble;
1951 changed |= BSS_CHANGED_ERP_PREAMBLE;
1952 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001953
1954 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001955 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001956 sdata->vif.bss_conf.use_short_slot = true;
1957 changed |= BSS_CHANGED_ERP_SLOT;
1958 }
1959
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001960 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001961 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001962 params->use_short_slot_time;
1963 changed |= BSS_CHANGED_ERP_SLOT;
1964 }
1965
Jouni Malinen90c97a02008-10-30 16:59:22 +02001966 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001967 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1968 wiphy->bands[band],
1969 params->basic_rates,
1970 params->basic_rates_len,
1971 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001972 changed |= BSS_CHANGED_BASIC_RATES;
1973 }
1974
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001975 if (params->ap_isolate >= 0) {
1976 if (params->ap_isolate)
1977 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1978 else
1979 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1980 }
1981
Helmut Schaa80d7e402010-11-19 12:40:26 +01001982 if (params->ht_opmode >= 0) {
1983 sdata->vif.bss_conf.ht_operation_mode =
1984 (u16) params->ht_opmode;
1985 changed |= BSS_CHANGED_HT;
1986 }
1987
Johannes Berg339afbf2012-11-14 15:21:17 +01001988 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001989 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1990 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1991 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1992 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001993 changed |= BSS_CHANGED_P2P_PS;
1994 }
1995
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001996 if (params->p2p_opp_ps > 0) {
1997 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1998 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1999 changed |= BSS_CHANGED_P2P_PS;
2000 } else if (params->p2p_opp_ps == 0) {
2001 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2002 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002003 changed |= BSS_CHANGED_P2P_PS;
2004 }
2005
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002006 ieee80211_bss_info_change_notify(sdata, changed);
2007
2008 return 0;
2009}
2010
Jouni Malinen31888482008-10-30 16:59:24 +02002011static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002012 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002013 struct ieee80211_txq_params *params)
2014{
2015 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002016 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002017 struct ieee80211_tx_queue_params p;
2018
2019 if (!local->ops->conf_tx)
2020 return -EOPNOTSUPP;
2021
Johannes Berg54bcbc62012-03-28 11:04:25 +02002022 if (local->hw.queues < IEEE80211_NUM_ACS)
2023 return -EOPNOTSUPP;
2024
Jouni Malinen31888482008-10-30 16:59:24 +02002025 memset(&p, 0, sizeof(p));
2026 p.aifs = params->aifs;
2027 p.cw_max = params->cwmax;
2028 p.cw_min = params->cwmin;
2029 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002030
2031 /*
2032 * Setting tx queue params disables u-apsd because it's only
2033 * called in master mode.
2034 */
2035 p.uapsd = false;
2036
Johannes Berga3304b02012-03-28 11:04:24 +02002037 sdata->tx_conf[params->ac] = p;
2038 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002039 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002040 "failed to set TX queue parameters for AC %d\n",
2041 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002042 return -EINVAL;
2043 }
2044
Johannes Berg7d257452012-07-06 17:37:43 +02002045 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2046
Jouni Malinen31888482008-10-30 16:59:24 +02002047 return 0;
2048}
2049
Bob Copeland665af4f2009-01-19 11:20:53 -05002050#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002051static int ieee80211_suspend(struct wiphy *wiphy,
2052 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002053{
Johannes Bergeecc4802011-05-04 15:37:29 +02002054 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002055}
2056
2057static int ieee80211_resume(struct wiphy *wiphy)
2058{
2059 return __ieee80211_resume(wiphy_priv(wiphy));
2060}
2061#else
2062#define ieee80211_suspend NULL
2063#define ieee80211_resume NULL
2064#endif
2065
Johannes Berg2a519312009-02-10 21:25:55 +01002066static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002067 struct cfg80211_scan_request *req)
2068{
Johannes Bergfd014282012-06-18 19:17:03 +02002069 struct ieee80211_sub_if_data *sdata;
2070
2071 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002072
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002073 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2074 case NL80211_IFTYPE_STATION:
2075 case NL80211_IFTYPE_ADHOC:
2076 case NL80211_IFTYPE_MESH_POINT:
2077 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002078 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002079 break;
2080 case NL80211_IFTYPE_P2P_GO:
2081 if (sdata->local->ops->hw_scan)
2082 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002083 /*
2084 * FIXME: implement NoA while scanning in software,
2085 * for now fall through to allow scanning only when
2086 * beaconing hasn't been configured yet
2087 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002088 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002089 /*
2090 * If the scan has been forced (and the driver supports
2091 * forcing), don't care about being beaconing already.
2092 * This will create problems to the attached stations (e.g. all
2093 * the frames sent while scanning on other channel will be
2094 * lost)
2095 */
2096 if (sdata->u.ap.beacon &&
2097 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2098 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002099 return -EOPNOTSUPP;
2100 break;
2101 default:
2102 return -EOPNOTSUPP;
2103 }
Johannes Berg2a519312009-02-10 21:25:55 +01002104
2105 return ieee80211_request_scan(sdata, req);
2106}
2107
Luciano Coelho79f460c2011-05-11 17:09:36 +03002108static int
2109ieee80211_sched_scan_start(struct wiphy *wiphy,
2110 struct net_device *dev,
2111 struct cfg80211_sched_scan_request *req)
2112{
2113 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2114
2115 if (!sdata->local->ops->sched_scan_start)
2116 return -EOPNOTSUPP;
2117
2118 return ieee80211_request_sched_scan_start(sdata, req);
2119}
2120
2121static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002122ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002123{
2124 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2125
2126 if (!sdata->local->ops->sched_scan_stop)
2127 return -EOPNOTSUPP;
2128
Luciano Coelho85a99942011-05-12 16:28:29 +03002129 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002130}
2131
Jouni Malinen636a5d32009-03-19 13:39:22 +02002132static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2133 struct cfg80211_auth_request *req)
2134{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002135 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002136}
2137
2138static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2139 struct cfg80211_assoc_request *req)
2140{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002141 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002142}
2143
2144static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002145 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002146{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002147 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002148}
2149
2150static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002151 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002152{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002153 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002154}
2155
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002156static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2157 struct cfg80211_ibss_params *params)
2158{
Johannes Berg55de9082012-07-26 17:24:39 +02002159 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002160}
2161
2162static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2163{
Johannes Berg55de9082012-07-26 17:24:39 +02002164 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002165}
2166
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002167static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2168 int rate[IEEE80211_NUM_BANDS])
2169{
2170 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2171
Cong Ding9887dbf2013-02-06 17:23:45 +01002172 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2173 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002174
2175 return 0;
2176}
2177
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002178static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2179{
2180 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002181 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002182
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002183 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2184 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2185
2186 if (err)
2187 return err;
2188 }
2189
Lukáš Turek310bc672009-12-21 22:50:48 +01002190 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2191 err = drv_set_coverage_class(local, wiphy->coverage_class);
2192
2193 if (err)
2194 return err;
2195 }
2196
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002197 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002198 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002199
Johannes Berg24487982009-04-23 18:52:52 +02002200 if (err)
2201 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002202 }
2203
Johannes Berg8bc83c22012-11-09 18:38:32 +01002204 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2205 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2206 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002207 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002208 }
2209 if (changed & WIPHY_PARAM_RETRY_LONG) {
2210 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2211 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002212 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002213 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002214 if (changed &
2215 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2216 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2217
2218 return 0;
2219}
2220
Johannes Berg7643a2c2009-06-02 13:01:39 +02002221static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002222 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002223 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002224{
2225 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002226 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002227
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002228 if (wdev) {
2229 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2230
2231 switch (type) {
2232 case NL80211_TX_POWER_AUTOMATIC:
2233 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2234 break;
2235 case NL80211_TX_POWER_LIMITED:
2236 case NL80211_TX_POWER_FIXED:
2237 if (mbm < 0 || (mbm % 100))
2238 return -EOPNOTSUPP;
2239 sdata->user_power_level = MBM_TO_DBM(mbm);
2240 break;
2241 }
2242
2243 ieee80211_recalc_txpower(sdata);
2244
2245 return 0;
2246 }
Johannes Berg55de9082012-07-26 17:24:39 +02002247
Johannes Berg7643a2c2009-06-02 13:01:39 +02002248 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002249 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002250 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002251 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002252 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002253 case NL80211_TX_POWER_FIXED:
2254 if (mbm < 0 || (mbm % 100))
2255 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002256 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002257 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002258 }
2259
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002260 mutex_lock(&local->iflist_mtx);
2261 list_for_each_entry(sdata, &local->interfaces, list)
2262 sdata->user_power_level = local->user_power_level;
2263 list_for_each_entry(sdata, &local->interfaces, list)
2264 ieee80211_recalc_txpower(sdata);
2265 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002266
2267 return 0;
2268}
2269
Johannes Bergc8442112012-10-24 10:17:18 +02002270static int ieee80211_get_tx_power(struct wiphy *wiphy,
2271 struct wireless_dev *wdev,
2272 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002273{
2274 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002275 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002276
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002277 if (!local->use_chanctx)
2278 *dbm = local->hw.conf.power_level;
2279 else
2280 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002281
Johannes Berg7643a2c2009-06-02 13:01:39 +02002282 return 0;
2283}
2284
Johannes Bergab737a42009-07-01 21:26:58 +02002285static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002286 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002287{
2288 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2289
2290 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2291
2292 return 0;
2293}
2294
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002295static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2296{
2297 struct ieee80211_local *local = wiphy_priv(wiphy);
2298
2299 drv_rfkill_poll(local);
2300}
2301
Johannes Bergaff89a92009-07-01 21:26:51 +02002302#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002303static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002304{
2305 struct ieee80211_local *local = wiphy_priv(wiphy);
2306
2307 if (!local->ops->testmode_cmd)
2308 return -EOPNOTSUPP;
2309
2310 return local->ops->testmode_cmd(&local->hw, data, len);
2311}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002312
2313static int ieee80211_testmode_dump(struct wiphy *wiphy,
2314 struct sk_buff *skb,
2315 struct netlink_callback *cb,
2316 void *data, int len)
2317{
2318 struct ieee80211_local *local = wiphy_priv(wiphy);
2319
2320 if (!local->ops->testmode_dump)
2321 return -EOPNOTSUPP;
2322
2323 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2324}
Johannes Bergaff89a92009-07-01 21:26:51 +02002325#endif
2326
Johannes Berg0f782312009-12-01 13:37:02 +01002327int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2328 enum ieee80211_smps_mode smps_mode)
2329{
2330 const u8 *ap;
2331 enum ieee80211_smps_mode old_req;
2332 int err;
2333
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002334 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002335
Johannes Berg0f782312009-12-01 13:37:02 +01002336 old_req = sdata->u.mgd.req_smps;
2337 sdata->u.mgd.req_smps = smps_mode;
2338
2339 if (old_req == smps_mode &&
2340 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2341 return 0;
2342
2343 /*
2344 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002345 * association, there's no need to do anything, just store
2346 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002347 */
2348 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002349 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002350 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002351
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002352 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002353
2354 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2355 if (sdata->u.mgd.powersave)
2356 smps_mode = IEEE80211_SMPS_DYNAMIC;
2357 else
2358 smps_mode = IEEE80211_SMPS_OFF;
2359 }
2360
2361 /* send SM PS frame to AP */
2362 err = ieee80211_send_smps_action(sdata, smps_mode,
2363 ap, ap);
2364 if (err)
2365 sdata->u.mgd.req_smps = old_req;
2366
2367 return err;
2368}
2369
Johannes Bergbc92afd2009-07-01 21:26:57 +02002370static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2371 bool enabled, int timeout)
2372{
2373 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2374 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002375
Chun-Yeow Yeohee1f6682013-01-10 23:31:54 +08002376 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2377 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002378 return -EOPNOTSUPP;
2379
Johannes Bergbc92afd2009-07-01 21:26:57 +02002380 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2381 return -EOPNOTSUPP;
2382
2383 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002384 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002385 return 0;
2386
2387 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002388 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002389
Johannes Berg0f782312009-12-01 13:37:02 +01002390 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002391 sdata_lock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002392 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002393 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002394
Johannes Bergbc92afd2009-07-01 21:26:57 +02002395 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2396 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2397
2398 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002399 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002400
2401 return 0;
2402}
2403
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002404static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2405 struct net_device *dev,
2406 s32 rssi_thold, u32 rssi_hyst)
2407{
2408 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002409 struct ieee80211_vif *vif = &sdata->vif;
2410 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2411
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002412 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2413 rssi_hyst == bss_conf->cqm_rssi_hyst)
2414 return 0;
2415
2416 bss_conf->cqm_rssi_thold = rssi_thold;
2417 bss_conf->cqm_rssi_hyst = rssi_hyst;
2418
2419 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002420 if (sdata->u.mgd.associated &&
2421 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002422 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2423
2424 return 0;
2425}
2426
Johannes Berg99303802009-07-01 21:26:59 +02002427static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2428 struct net_device *dev,
2429 const u8 *addr,
2430 const struct cfg80211_bitrate_mask *mask)
2431{
2432 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2433 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302434 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002435
Eliad Peller554a43d2012-06-12 12:41:15 +03002436 if (!ieee80211_sdata_running(sdata))
2437 return -ENETDOWN;
2438
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302439 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2440 ret = drv_set_bitrate_mask(local, sdata, mask);
2441 if (ret)
2442 return ret;
2443 }
Johannes Berg99303802009-07-01 21:26:59 +02002444
Simon Wunderlich19468412012-01-28 17:25:33 +01002445 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002446 struct ieee80211_supported_band *sband = wiphy->bands[i];
2447 int j;
2448
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002449 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002450 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2451 sizeof(mask->control[i].mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002452
2453 sdata->rc_has_mcs_mask[i] = false;
2454 if (!sband)
2455 continue;
2456
2457 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2458 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2459 sdata->rc_has_mcs_mask[i] = true;
2460 break;
2461 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002462 }
Johannes Berg99303802009-07-01 21:26:59 +02002463
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002464 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002465}
2466
Johannes Berg2eb278e2012-06-05 14:28:42 +02002467static int ieee80211_start_roc_work(struct ieee80211_local *local,
2468 struct ieee80211_sub_if_data *sdata,
2469 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002470 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002471 struct sk_buff *txskb,
2472 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002473{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002474 struct ieee80211_roc_work *roc, *tmp;
2475 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002476 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002477
2478 lockdep_assert_held(&local->mtx);
2479
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002480 if (local->use_chanctx && !local->ops->remain_on_channel)
2481 return -EOPNOTSUPP;
2482
Johannes Berg2eb278e2012-06-05 14:28:42 +02002483 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2484 if (!roc)
2485 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002486
Johannes Berg2eb278e2012-06-05 14:28:42 +02002487 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002488 roc->duration = duration;
2489 roc->req_duration = duration;
2490 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002491 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002492 roc->mgmt_tx_cookie = (unsigned long)txskb;
2493 roc->sdata = sdata;
2494 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2495 INIT_LIST_HEAD(&roc->dependents);
2496
2497 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002498 if (!list_empty(&local->roc_list) ||
2499 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002500 goto out_check_combine;
2501
2502 /* if not HW assist, just queue & schedule work */
2503 if (!local->ops->remain_on_channel) {
2504 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2505 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002506 }
2507
Johannes Berg2eb278e2012-06-05 14:28:42 +02002508 /* otherwise actually kick it off here (for error handling) */
2509
2510 /*
2511 * If the duration is zero, then the driver
2512 * wouldn't actually do anything. Set it to
2513 * 10 for now.
2514 *
2515 * TODO: cancel the off-channel operation
2516 * when we get the SKB's TX status and
2517 * the wait time was zero before.
2518 */
2519 if (!duration)
2520 duration = 10;
2521
Ilan Peerd339d5c2013-02-12 09:34:13 +02002522 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002523 if (ret) {
2524 kfree(roc);
2525 return ret;
2526 }
2527
2528 roc->started = true;
2529 goto out_queue;
2530
2531 out_check_combine:
2532 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002533 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002534 continue;
2535
2536 /*
2537 * Extend this ROC if possible:
2538 *
2539 * If it hasn't started yet, just increase the duration
2540 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002541 * If the type of the new ROC has higher priority, modify the
2542 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002543 */
2544 if (!tmp->started) {
2545 list_add_tail(&roc->list, &tmp->dependents);
2546 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002547 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002548 queued = true;
2549 break;
2550 }
2551
2552 /* If it has already started, it's more difficult ... */
2553 if (local->ops->remain_on_channel) {
2554 unsigned long j = jiffies;
2555
2556 /*
2557 * In the offloaded ROC case, if it hasn't begun, add
2558 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002559 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002560 * check that there's still a minimum time left and
2561 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002562 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002563 * a reduced time so we'll ask the driver to execute
2564 * it right after finishing the previous one, in the
2565 * hope that it'll also be executed right afterwards,
2566 * effectively extending the old one.
2567 * If there's no minimum time left, just add it to the
2568 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002569 * TODO: the ROC type is ignored here, assuming that it
2570 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002571 */
2572 if (!tmp->hw_begun) {
2573 list_add_tail(&roc->list, &tmp->dependents);
2574 queued = true;
2575 break;
2576 }
2577
2578 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2579 tmp->hw_start_time +
2580 msecs_to_jiffies(tmp->duration))) {
2581 int new_dur;
2582
2583 ieee80211_handle_roc_started(roc);
2584
2585 new_dur = roc->duration -
2586 jiffies_to_msecs(tmp->hw_start_time +
2587 msecs_to_jiffies(
2588 tmp->duration) -
2589 j);
2590
2591 if (new_dur > 0) {
2592 /* add right after tmp */
2593 list_add(&roc->list, &tmp->list);
2594 } else {
2595 list_add_tail(&roc->list,
2596 &tmp->dependents);
2597 }
2598 queued = true;
2599 }
2600 } else if (del_timer_sync(&tmp->work.timer)) {
2601 unsigned long new_end;
2602
2603 /*
2604 * In the software ROC case, cancel the timer, if
2605 * that fails then the finish work is already
2606 * queued/pending and thus we queue the new ROC
2607 * normally, if that succeeds then we can extend
2608 * the timer duration and TX the frame (if any.)
2609 */
2610
2611 list_add_tail(&roc->list, &tmp->dependents);
2612 queued = true;
2613
2614 new_end = jiffies + msecs_to_jiffies(roc->duration);
2615
2616 /* ok, it was started & we canceled timer */
2617 if (time_after(new_end, tmp->work.timer.expires))
2618 mod_timer(&tmp->work.timer, new_end);
2619 else
2620 add_timer(&tmp->work.timer);
2621
2622 ieee80211_handle_roc_started(roc);
2623 }
2624 break;
2625 }
2626
2627 out_queue:
2628 if (!queued)
2629 list_add_tail(&roc->list, &local->roc_list);
2630
2631 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002632 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002633 * or the SKB (for mgmt TX)
2634 */
Johannes Berg50febf62012-10-26 16:13:06 +02002635 if (!txskb) {
2636 /* local->mtx protects this */
2637 local->roc_cookie_counter++;
2638 roc->cookie = local->roc_cookie_counter;
2639 /* wow, you wrapped 64 bits ... more likely a bug */
2640 if (WARN_ON(roc->cookie == 0)) {
2641 roc->cookie = 1;
2642 local->roc_cookie_counter++;
2643 }
2644 *cookie = roc->cookie;
2645 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002646 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002647 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002648
2649 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002650}
2651
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002652static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002653 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002654 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002655 unsigned int duration,
2656 u64 *cookie)
2657{
Johannes Berg71bbc992012-06-15 15:30:18 +02002658 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002659 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002660 int ret;
2661
Johannes Berg2eb278e2012-06-05 14:28:42 +02002662 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002663 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002664 duration, cookie, NULL,
2665 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002666 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002667
Johannes Berg2eb278e2012-06-05 14:28:42 +02002668 return ret;
2669}
2670
2671static int ieee80211_cancel_roc(struct ieee80211_local *local,
2672 u64 cookie, bool mgmt_tx)
2673{
2674 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2675 int ret;
2676
2677 mutex_lock(&local->mtx);
2678 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002679 struct ieee80211_roc_work *dep, *tmp2;
2680
2681 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002682 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002683 continue;
2684 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2685 continue;
2686 /* found dependent item -- just remove it */
2687 list_del(&dep->list);
2688 mutex_unlock(&local->mtx);
2689
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002690 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002691 return 0;
2692 }
2693
Johannes Berg50febf62012-10-26 16:13:06 +02002694 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002695 continue;
2696 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2697 continue;
2698
2699 found = roc;
2700 break;
2701 }
2702
2703 if (!found) {
2704 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002705 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002706 }
Johannes Berg21f83582010-12-18 17:20:47 +01002707
Johannes Berge979e332012-06-11 17:09:41 +02002708 /*
2709 * We found the item to cancel, so do that. Note that it
2710 * may have dependents, which we also cancel (and send
2711 * the expired signal for.) Not doing so would be quite
2712 * tricky here, but we may need to fix it later.
2713 */
2714
Johannes Berg2eb278e2012-06-05 14:28:42 +02002715 if (local->ops->remain_on_channel) {
2716 if (found->started) {
2717 ret = drv_cancel_remain_on_channel(local);
2718 if (WARN_ON_ONCE(ret)) {
2719 mutex_unlock(&local->mtx);
2720 return ret;
2721 }
2722 }
Johannes Berg21f83582010-12-18 17:20:47 +01002723
Johannes Berg2eb278e2012-06-05 14:28:42 +02002724 list_del(&found->list);
2725
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002726 if (found->started)
2727 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002728 mutex_unlock(&local->mtx);
2729
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002730 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002731 } else {
2732 /* work may be pending so use it all the time */
2733 found->abort = true;
2734 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2735
2736 mutex_unlock(&local->mtx);
2737
2738 /* work will clean up etc */
2739 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002740 WARN_ON(!found->to_be_freed);
2741 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002742 }
Johannes Berg21f83582010-12-18 17:20:47 +01002743
Johannes Berg21f83582010-12-18 17:20:47 +01002744 return 0;
2745}
2746
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002747static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002748 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002749 u64 cookie)
2750{
Johannes Berg71bbc992012-06-15 15:30:18 +02002751 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002752 struct ieee80211_local *local = sdata->local;
2753
Johannes Berg2eb278e2012-06-05 14:28:42 +02002754 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002755}
2756
Simon Wunderlich164eb022013-02-08 18:16:20 +01002757static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2758 struct net_device *dev,
2759 struct cfg80211_chan_def *chandef)
2760{
2761 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2762 struct ieee80211_local *local = sdata->local;
2763 unsigned long timeout;
2764 int err;
2765
2766 if (!list_empty(&local->roc_list) || local->scanning)
2767 return -EBUSY;
2768
2769 /* whatever, but channel contexts should not complain about that one */
2770 sdata->smps_mode = IEEE80211_SMPS_OFF;
2771 sdata->needed_rx_chains = local->rx_chains;
2772 sdata->radar_required = true;
2773
2774 mutex_lock(&local->iflist_mtx);
2775 err = ieee80211_vif_use_channel(sdata, chandef,
2776 IEEE80211_CHANCTX_SHARED);
2777 mutex_unlock(&local->iflist_mtx);
2778 if (err)
2779 return err;
2780
2781 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2782 ieee80211_queue_delayed_work(&sdata->local->hw,
2783 &sdata->dfs_cac_timer_work, timeout);
2784
2785 return 0;
2786}
2787
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002788static struct cfg80211_beacon_data *
2789cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2790{
2791 struct cfg80211_beacon_data *new_beacon;
2792 u8 *pos;
2793 int len;
2794
2795 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2796 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2797 beacon->probe_resp_len;
2798
2799 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2800 if (!new_beacon)
2801 return NULL;
2802
2803 pos = (u8 *)(new_beacon + 1);
2804 if (beacon->head_len) {
2805 new_beacon->head_len = beacon->head_len;
2806 new_beacon->head = pos;
2807 memcpy(pos, beacon->head, beacon->head_len);
2808 pos += beacon->head_len;
2809 }
2810 if (beacon->tail_len) {
2811 new_beacon->tail_len = beacon->tail_len;
2812 new_beacon->tail = pos;
2813 memcpy(pos, beacon->tail, beacon->tail_len);
2814 pos += beacon->tail_len;
2815 }
2816 if (beacon->beacon_ies_len) {
2817 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2818 new_beacon->beacon_ies = pos;
2819 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2820 pos += beacon->beacon_ies_len;
2821 }
2822 if (beacon->proberesp_ies_len) {
2823 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2824 new_beacon->proberesp_ies = pos;
2825 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2826 pos += beacon->proberesp_ies_len;
2827 }
2828 if (beacon->assocresp_ies_len) {
2829 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2830 new_beacon->assocresp_ies = pos;
2831 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2832 pos += beacon->assocresp_ies_len;
2833 }
2834 if (beacon->probe_resp_len) {
2835 new_beacon->probe_resp_len = beacon->probe_resp_len;
2836 beacon->probe_resp = pos;
2837 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2838 pos += beacon->probe_resp_len;
2839 }
2840
2841 return new_beacon;
2842}
2843
2844void ieee80211_csa_finalize_work(struct work_struct *work)
2845{
2846 struct ieee80211_sub_if_data *sdata =
2847 container_of(work, struct ieee80211_sub_if_data,
2848 csa_finalize_work);
2849 struct ieee80211_local *local = sdata->local;
2850 int err, changed;
2851
2852 if (!ieee80211_sdata_running(sdata))
2853 return;
2854
2855 if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_AP))
2856 return;
2857
2858 sdata->radar_required = sdata->csa_radar_required;
2859 err = ieee80211_vif_change_channel(sdata, &local->csa_chandef,
2860 &changed);
2861 if (WARN_ON(err < 0))
2862 return;
2863
2864 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
2865 if (err < 0)
2866 return;
2867
2868 changed |= err;
2869 kfree(sdata->u.ap.next_beacon);
2870 sdata->u.ap.next_beacon = NULL;
2871 sdata->vif.csa_active = false;
2872
2873 ieee80211_wake_queues_by_reason(&sdata->local->hw,
2874 IEEE80211_MAX_QUEUE_MAP,
2875 IEEE80211_QUEUE_STOP_REASON_CSA);
2876
2877 ieee80211_bss_info_change_notify(sdata, changed);
2878
2879 cfg80211_ch_switch_notify(sdata->dev, &local->csa_chandef);
2880}
2881
2882static int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
2883 struct cfg80211_csa_settings *params)
2884{
2885 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2886 struct ieee80211_local *local = sdata->local;
2887 struct ieee80211_chanctx_conf *chanctx_conf;
2888 struct ieee80211_chanctx *chanctx;
2889 int err, num_chanctx;
2890
2891 if (!list_empty(&local->roc_list) || local->scanning)
2892 return -EBUSY;
2893
2894 if (sdata->wdev.cac_started)
2895 return -EBUSY;
2896
2897 if (cfg80211_chandef_identical(&params->chandef,
2898 &sdata->vif.bss_conf.chandef))
2899 return -EINVAL;
2900
2901 rcu_read_lock();
2902 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2903 if (!chanctx_conf) {
2904 rcu_read_unlock();
2905 return -EBUSY;
2906 }
2907
2908 /* don't handle for multi-VIF cases */
2909 chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
2910 if (chanctx->refcount > 1) {
2911 rcu_read_unlock();
2912 return -EBUSY;
2913 }
2914 num_chanctx = 0;
2915 list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
2916 num_chanctx++;
2917 rcu_read_unlock();
2918
2919 if (num_chanctx > 1)
2920 return -EBUSY;
2921
2922 /* don't allow another channel switch if one is already active. */
2923 if (sdata->vif.csa_active)
2924 return -EBUSY;
2925
2926 /* only handle AP for now. */
2927 switch (sdata->vif.type) {
2928 case NL80211_IFTYPE_AP:
2929 break;
2930 default:
2931 return -EOPNOTSUPP;
2932 }
2933
2934 sdata->u.ap.next_beacon = cfg80211_beacon_dup(&params->beacon_after);
2935 if (!sdata->u.ap.next_beacon)
2936 return -ENOMEM;
2937
2938 sdata->csa_counter_offset_beacon = params->counter_offset_beacon;
2939 sdata->csa_counter_offset_presp = params->counter_offset_presp;
2940 sdata->csa_radar_required = params->radar_required;
2941
2942 if (params->block_tx)
2943 ieee80211_stop_queues_by_reason(&local->hw,
2944 IEEE80211_MAX_QUEUE_MAP,
2945 IEEE80211_QUEUE_STOP_REASON_CSA);
2946
2947 err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
2948 if (err < 0)
2949 return err;
2950
2951 local->csa_chandef = params->chandef;
2952 sdata->vif.csa_active = true;
2953
2954 ieee80211_bss_info_change_notify(sdata, err);
2955 drv_channel_switch_beacon(sdata, &params->chandef);
2956
2957 return 0;
2958}
2959
Johannes Berg71bbc992012-06-15 15:30:18 +02002960static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002961 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01002962 unsigned int wait, const u8 *buf, size_t len,
2963 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002964{
Johannes Berg71bbc992012-06-15 15:30:18 +02002965 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002966 struct ieee80211_local *local = sdata->local;
2967 struct sk_buff *skb;
2968 struct sta_info *sta;
2969 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002970 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002971 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002972 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002973
Johannes Berge247bd902011-11-04 11:18:21 +01002974 if (dont_wait_for_ack)
2975 flags = IEEE80211_TX_CTL_NO_ACK;
2976 else
2977 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2978 IEEE80211_TX_CTL_REQ_TX_STATUS;
2979
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302980 if (no_cck)
2981 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2982
Johannes Berg9d38d852010-06-09 17:20:33 +02002983 switch (sdata->vif.type) {
2984 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002985 if (!sdata->vif.bss_conf.ibss_joined)
2986 need_offchan = true;
2987 /* fall through */
2988#ifdef CONFIG_MAC80211_MESH
2989 case NL80211_IFTYPE_MESH_POINT:
2990 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2991 !sdata->u.mesh.mesh_id_len)
2992 need_offchan = true;
2993 /* fall through */
2994#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002995 case NL80211_IFTYPE_AP:
2996 case NL80211_IFTYPE_AP_VLAN:
2997 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002998 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2999 !ieee80211_vif_is_mesh(&sdata->vif) &&
3000 !rcu_access_pointer(sdata->bss->beacon))
3001 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003002 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003003 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
3004 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED)
Johannes Berg9d38d852010-06-09 17:20:33 +02003005 break;
3006 rcu_read_lock();
3007 sta = sta_info_get(sdata, mgmt->da);
3008 rcu_read_unlock();
3009 if (!sta)
3010 return -ENOLINK;
3011 break;
3012 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003013 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003014 if (!sdata->u.mgd.associated)
3015 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003016 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003017 case NL80211_IFTYPE_P2P_DEVICE:
3018 need_offchan = true;
3019 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003020 default:
3021 return -EOPNOTSUPP;
3022 }
3023
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003024 /* configurations requiring offchan cannot work if no channel has been
3025 * specified
3026 */
3027 if (need_offchan && !chan)
3028 return -EINVAL;
3029
Johannes Berg2eb278e2012-06-05 14:28:42 +02003030 mutex_lock(&local->mtx);
3031
3032 /* Check if the operating channel is the requested channel */
3033 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003034 struct ieee80211_chanctx_conf *chanctx_conf;
3035
3036 rcu_read_lock();
3037 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3038
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003039 if (chanctx_conf) {
3040 need_offchan = chan && (chan != chanctx_conf->def.chan);
3041 } else if (!chan) {
3042 ret = -EINVAL;
3043 rcu_read_unlock();
3044 goto out_unlock;
3045 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003046 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003047 }
Johannes Berg55de9082012-07-26 17:24:39 +02003048 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003049 }
3050
3051 if (need_offchan && !offchan) {
3052 ret = -EBUSY;
3053 goto out_unlock;
3054 }
3055
Johannes Berg9d38d852010-06-09 17:20:33 +02003056 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003057 if (!skb) {
3058 ret = -ENOMEM;
3059 goto out_unlock;
3060 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003061 skb_reserve(skb, local->hw.extra_tx_headroom);
3062
3063 memcpy(skb_put(skb, len), buf, len);
3064
3065 IEEE80211_SKB_CB(skb)->flags = flags;
3066
Johannes Berg2eb278e2012-06-05 14:28:42 +02003067 skb->dev = sdata->dev;
3068
3069 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003070 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003071 ieee80211_tx_skb(sdata, skb);
3072 ret = 0;
3073 goto out_unlock;
3074 }
3075
Seth Forshee6c17b772013-02-11 11:21:07 -06003076 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3077 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003078 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003079 IEEE80211_SKB_CB(skb)->hw_queue =
3080 local->hw.offchannel_tx_hw_queue;
3081
Johannes Berg2eb278e2012-06-05 14:28:42 +02003082 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01003083 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003084 wait, cookie, skb,
3085 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003086 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003087 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003088 out_unlock:
3089 mutex_unlock(&local->mtx);
3090 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003091}
3092
Johannes Bergf30221e2010-11-25 10:02:30 +01003093static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003094 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003095 u64 cookie)
3096{
Johannes Berg71bbc992012-06-15 15:30:18 +02003097 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003098
Johannes Berg2eb278e2012-06-05 14:28:42 +02003099 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003100}
3101
Johannes Berg7be50862010-10-13 12:06:24 +02003102static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003103 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003104 u16 frame_type, bool reg)
3105{
3106 struct ieee80211_local *local = wiphy_priv(wiphy);
3107
Will Hawkins6abe0562012-06-20 11:51:14 -04003108 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003109 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3110 if (reg)
3111 local->probe_req_reg++;
3112 else
3113 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003114
Felix Fietkau35f51492012-10-31 15:50:34 +01003115 if (!local->open_count)
3116 break;
3117
Will Hawkins6abe0562012-06-20 11:51:14 -04003118 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3119 break;
3120 default:
3121 break;
3122 }
Johannes Berg7be50862010-10-13 12:06:24 +02003123}
3124
Bruno Randolf15d96752010-11-10 12:50:56 +09003125static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3126{
3127 struct ieee80211_local *local = wiphy_priv(wiphy);
3128
3129 if (local->started)
3130 return -EOPNOTSUPP;
3131
3132 return drv_set_antenna(local, tx_ant, rx_ant);
3133}
3134
3135static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3136{
3137 struct ieee80211_local *local = wiphy_priv(wiphy);
3138
3139 return drv_get_antenna(local, tx_ant, rx_ant);
3140}
3141
John W. Linville38c09152011-03-07 16:19:18 -05003142static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
3143{
3144 struct ieee80211_local *local = wiphy_priv(wiphy);
3145
3146 return drv_set_ringparam(local, tx, rx);
3147}
3148
3149static void ieee80211_get_ringparam(struct wiphy *wiphy,
3150 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
3151{
3152 struct ieee80211_local *local = wiphy_priv(wiphy);
3153
3154 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
3155}
3156
Johannes Bergc68f4b82011-07-05 16:35:41 +02003157static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3158 struct net_device *dev,
3159 struct cfg80211_gtk_rekey_data *data)
3160{
3161 struct ieee80211_local *local = wiphy_priv(wiphy);
3162 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3163
3164 if (!local->ops->set_rekey_data)
3165 return -EOPNOTSUPP;
3166
3167 drv_set_rekey_data(local, sdata, data);
3168
3169 return 0;
3170}
3171
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003172static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
3173{
3174 u8 *pos = (void *)skb_put(skb, 7);
3175
3176 *pos++ = WLAN_EID_EXT_CAPABILITY;
3177 *pos++ = 5; /* len */
3178 *pos++ = 0x0;
3179 *pos++ = 0x0;
3180 *pos++ = 0x0;
3181 *pos++ = 0x0;
3182 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
3183}
3184
3185static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
3186{
3187 struct ieee80211_local *local = sdata->local;
3188 u16 capab;
3189
3190 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003191 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003192 return capab;
3193
3194 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3195 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3196 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3197 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3198
3199 return capab;
3200}
3201
3202static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3203 u8 *peer, u8 *bssid)
3204{
3205 struct ieee80211_tdls_lnkie *lnkid;
3206
3207 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3208
3209 lnkid->ie_type = WLAN_EID_LINK_ID;
3210 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3211
3212 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3213 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3214 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3215}
3216
3217static int
3218ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3219 u8 *peer, u8 action_code, u8 dialog_token,
3220 u16 status_code, struct sk_buff *skb)
3221{
3222 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003223 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003224 struct ieee80211_tdls_data *tf;
3225
3226 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3227
3228 memcpy(tf->da, peer, ETH_ALEN);
3229 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3230 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3231 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3232
3233 switch (action_code) {
3234 case WLAN_TDLS_SETUP_REQUEST:
3235 tf->category = WLAN_CATEGORY_TDLS;
3236 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3237
3238 skb_put(skb, sizeof(tf->u.setup_req));
3239 tf->u.setup_req.dialog_token = dialog_token;
3240 tf->u.setup_req.capability =
3241 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3242
Johannes Berg55de9082012-07-26 17:24:39 +02003243 ieee80211_add_srates_ie(sdata, skb, false, band);
3244 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003245 ieee80211_tdls_add_ext_capab(skb);
3246 break;
3247 case WLAN_TDLS_SETUP_RESPONSE:
3248 tf->category = WLAN_CATEGORY_TDLS;
3249 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3250
3251 skb_put(skb, sizeof(tf->u.setup_resp));
3252 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3253 tf->u.setup_resp.dialog_token = dialog_token;
3254 tf->u.setup_resp.capability =
3255 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3256
Johannes Berg55de9082012-07-26 17:24:39 +02003257 ieee80211_add_srates_ie(sdata, skb, false, band);
3258 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003259 ieee80211_tdls_add_ext_capab(skb);
3260 break;
3261 case WLAN_TDLS_SETUP_CONFIRM:
3262 tf->category = WLAN_CATEGORY_TDLS;
3263 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3264
3265 skb_put(skb, sizeof(tf->u.setup_cfm));
3266 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3267 tf->u.setup_cfm.dialog_token = dialog_token;
3268 break;
3269 case WLAN_TDLS_TEARDOWN:
3270 tf->category = WLAN_CATEGORY_TDLS;
3271 tf->action_code = WLAN_TDLS_TEARDOWN;
3272
3273 skb_put(skb, sizeof(tf->u.teardown));
3274 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3275 break;
3276 case WLAN_TDLS_DISCOVERY_REQUEST:
3277 tf->category = WLAN_CATEGORY_TDLS;
3278 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3279
3280 skb_put(skb, sizeof(tf->u.discover_req));
3281 tf->u.discover_req.dialog_token = dialog_token;
3282 break;
3283 default:
3284 return -EINVAL;
3285 }
3286
3287 return 0;
3288}
3289
3290static int
3291ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3292 u8 *peer, u8 action_code, u8 dialog_token,
3293 u16 status_code, struct sk_buff *skb)
3294{
3295 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003296 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003297 struct ieee80211_mgmt *mgmt;
3298
3299 mgmt = (void *)skb_put(skb, 24);
3300 memset(mgmt, 0, 24);
3301 memcpy(mgmt->da, peer, ETH_ALEN);
3302 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3303 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3304
3305 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3306 IEEE80211_STYPE_ACTION);
3307
3308 switch (action_code) {
3309 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3310 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3311 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3312 mgmt->u.action.u.tdls_discover_resp.action_code =
3313 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3314 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3315 dialog_token;
3316 mgmt->u.action.u.tdls_discover_resp.capability =
3317 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3318
Johannes Berg55de9082012-07-26 17:24:39 +02003319 ieee80211_add_srates_ie(sdata, skb, false, band);
3320 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003321 ieee80211_tdls_add_ext_capab(skb);
3322 break;
3323 default:
3324 return -EINVAL;
3325 }
3326
3327 return 0;
3328}
3329
3330static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3331 u8 *peer, u8 action_code, u8 dialog_token,
3332 u16 status_code, const u8 *extra_ies,
3333 size_t extra_ies_len)
3334{
3335 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3336 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003337 struct sk_buff *skb = NULL;
3338 bool send_direct;
3339 int ret;
3340
3341 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3342 return -ENOTSUPP;
3343
3344 /* make sure we are in managed mode, and associated */
3345 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3346 !sdata->u.mgd.associated)
3347 return -EINVAL;
3348
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003349 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3350 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003351
3352 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3353 max(sizeof(struct ieee80211_mgmt),
3354 sizeof(struct ieee80211_tdls_data)) +
3355 50 + /* supported rates */
3356 7 + /* ext capab */
3357 extra_ies_len +
3358 sizeof(struct ieee80211_tdls_lnkie));
3359 if (!skb)
3360 return -ENOMEM;
3361
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003362 skb_reserve(skb, local->hw.extra_tx_headroom);
3363
3364 switch (action_code) {
3365 case WLAN_TDLS_SETUP_REQUEST:
3366 case WLAN_TDLS_SETUP_RESPONSE:
3367 case WLAN_TDLS_SETUP_CONFIRM:
3368 case WLAN_TDLS_TEARDOWN:
3369 case WLAN_TDLS_DISCOVERY_REQUEST:
3370 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3371 action_code, dialog_token,
3372 status_code, skb);
3373 send_direct = false;
3374 break;
3375 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3376 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3377 dialog_token, status_code,
3378 skb);
3379 send_direct = true;
3380 break;
3381 default:
3382 ret = -ENOTSUPP;
3383 break;
3384 }
3385
3386 if (ret < 0)
3387 goto fail;
3388
3389 if (extra_ies_len)
3390 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3391
3392 /* the TDLS link IE is always added last */
3393 switch (action_code) {
3394 case WLAN_TDLS_SETUP_REQUEST:
3395 case WLAN_TDLS_SETUP_CONFIRM:
3396 case WLAN_TDLS_TEARDOWN:
3397 case WLAN_TDLS_DISCOVERY_REQUEST:
3398 /* we are the initiator */
3399 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3400 sdata->u.mgd.bssid);
3401 break;
3402 case WLAN_TDLS_SETUP_RESPONSE:
3403 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3404 /* we are the responder */
3405 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3406 sdata->u.mgd.bssid);
3407 break;
3408 default:
3409 ret = -ENOTSUPP;
3410 goto fail;
3411 }
3412
3413 if (send_direct) {
3414 ieee80211_tx_skb(sdata, skb);
3415 return 0;
3416 }
3417
3418 /*
3419 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3420 * we should default to AC_VI.
3421 */
3422 switch (action_code) {
3423 case WLAN_TDLS_SETUP_REQUEST:
3424 case WLAN_TDLS_SETUP_RESPONSE:
3425 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3426 skb->priority = 2;
3427 break;
3428 default:
3429 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3430 skb->priority = 5;
3431 break;
3432 }
3433
3434 /* disable bottom halves when entering the Tx path */
3435 local_bh_disable();
3436 ret = ieee80211_subif_start_xmit(skb, dev);
3437 local_bh_enable();
3438
3439 return ret;
3440
3441fail:
3442 dev_kfree_skb(skb);
3443 return ret;
3444}
3445
3446static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3447 u8 *peer, enum nl80211_tdls_operation oper)
3448{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003449 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003450 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3451
3452 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3453 return -ENOTSUPP;
3454
3455 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3456 return -EINVAL;
3457
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003458 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003459
3460 switch (oper) {
3461 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003462 rcu_read_lock();
3463 sta = sta_info_get(sdata, peer);
3464 if (!sta) {
3465 rcu_read_unlock();
3466 return -ENOLINK;
3467 }
3468
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003469 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003470 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003471 break;
3472 case NL80211_TDLS_DISABLE_LINK:
3473 return sta_info_destroy_addr(sdata, peer);
3474 case NL80211_TDLS_TEARDOWN:
3475 case NL80211_TDLS_SETUP:
3476 case NL80211_TDLS_DISCOVERY_REQ:
3477 /* We don't support in-driver setup/teardown/discovery */
3478 return -ENOTSUPP;
3479 default:
3480 return -ENOTSUPP;
3481 }
3482
3483 return 0;
3484}
3485
Johannes Berg06500732011-11-04 11:18:16 +01003486static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3487 const u8 *peer, u64 *cookie)
3488{
3489 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3490 struct ieee80211_local *local = sdata->local;
3491 struct ieee80211_qos_hdr *nullfunc;
3492 struct sk_buff *skb;
3493 int size = sizeof(*nullfunc);
3494 __le16 fc;
3495 bool qos;
3496 struct ieee80211_tx_info *info;
3497 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003498 struct ieee80211_chanctx_conf *chanctx_conf;
3499 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003500
3501 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003502 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3503 if (WARN_ON(!chanctx_conf)) {
3504 rcu_read_unlock();
3505 return -EINVAL;
3506 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003507 band = chanctx_conf->def.chan->band;
Johannes Berg06500732011-11-04 11:18:16 +01003508 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003509 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003510 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003511 } else {
3512 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003513 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003514 }
Johannes Berg06500732011-11-04 11:18:16 +01003515
3516 if (qos) {
3517 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3518 IEEE80211_STYPE_QOS_NULLFUNC |
3519 IEEE80211_FCTL_FROMDS);
3520 } else {
3521 size -= 2;
3522 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3523 IEEE80211_STYPE_NULLFUNC |
3524 IEEE80211_FCTL_FROMDS);
3525 }
3526
3527 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003528 if (!skb) {
3529 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003530 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003531 }
Johannes Berg06500732011-11-04 11:18:16 +01003532
3533 skb->dev = dev;
3534
3535 skb_reserve(skb, local->hw.extra_tx_headroom);
3536
3537 nullfunc = (void *) skb_put(skb, size);
3538 nullfunc->frame_control = fc;
3539 nullfunc->duration_id = 0;
3540 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3541 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3542 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3543 nullfunc->seq_ctrl = 0;
3544
3545 info = IEEE80211_SKB_CB(skb);
3546
3547 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3548 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3549
3550 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3551 skb->priority = 7;
3552 if (qos)
3553 nullfunc->qos_ctrl = cpu_to_le16(7);
3554
3555 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003556 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003557 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003558 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003559
3560 *cookie = (unsigned long) skb;
3561 return 0;
3562}
3563
Johannes Berg683b6d32012-11-08 21:25:48 +01003564static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3565 struct wireless_dev *wdev,
3566 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003567{
Johannes Berg55de9082012-07-26 17:24:39 +02003568 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003569 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003570 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003571 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003572
Johannes Berg55de9082012-07-26 17:24:39 +02003573 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003574 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3575 if (chanctx_conf) {
3576 *chandef = chanctx_conf->def;
3577 ret = 0;
3578 } else if (local->open_count > 0 &&
3579 local->open_count == local->monitors &&
3580 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3581 if (local->use_chanctx)
3582 *chandef = local->monitor_chandef;
3583 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003584 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003585 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003586 }
3587 rcu_read_unlock();
3588
Johannes Berg683b6d32012-11-08 21:25:48 +01003589 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003590}
3591
Johannes Berg6d525632012-04-04 15:05:25 +02003592#ifdef CONFIG_PM
3593static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3594{
3595 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3596}
3597#endif
3598
Jiri Bencf0706e82007-05-05 11:45:53 -07003599struct cfg80211_ops mac80211_config_ops = {
3600 .add_virtual_intf = ieee80211_add_iface,
3601 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003602 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003603 .start_p2p_device = ieee80211_start_p2p_device,
3604 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003605 .add_key = ieee80211_add_key,
3606 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003607 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003608 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003609 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003610 .start_ap = ieee80211_start_ap,
3611 .change_beacon = ieee80211_change_beacon,
3612 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003613 .add_station = ieee80211_add_station,
3614 .del_station = ieee80211_del_station,
3615 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003616 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003617 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003618 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003619#ifdef CONFIG_MAC80211_MESH
3620 .add_mpath = ieee80211_add_mpath,
3621 .del_mpath = ieee80211_del_mpath,
3622 .change_mpath = ieee80211_change_mpath,
3623 .get_mpath = ieee80211_get_mpath,
3624 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003625 .update_mesh_config = ieee80211_update_mesh_config,
3626 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003627 .join_mesh = ieee80211_join_mesh,
3628 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003629#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003630 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003631 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003632 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003633 .suspend = ieee80211_suspend,
3634 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003635 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003636 .sched_scan_start = ieee80211_sched_scan_start,
3637 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003638 .auth = ieee80211_auth,
3639 .assoc = ieee80211_assoc,
3640 .deauth = ieee80211_deauth,
3641 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003642 .join_ibss = ieee80211_join_ibss,
3643 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003644 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003645 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003646 .set_tx_power = ieee80211_set_tx_power,
3647 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003648 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003649 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003650 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003651 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003652 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003653 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003654 .remain_on_channel = ieee80211_remain_on_channel,
3655 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003656 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003657 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003658 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003659 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003660 .set_antenna = ieee80211_set_antenna,
3661 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003662 .set_ringparam = ieee80211_set_ringparam,
3663 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003664 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003665 .tdls_oper = ieee80211_tdls_oper,
3666 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003667 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003668 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003669#ifdef CONFIG_PM
3670 .set_wakeup = ieee80211_set_wakeup,
3671#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003672 .get_et_sset_count = ieee80211_get_et_sset_count,
3673 .get_et_stats = ieee80211_get_et_stats,
3674 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003675 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003676 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003677 .channel_switch = ieee80211_channel_switch,
Jiri Bencf0706e82007-05-05 11:45:53 -07003678};