blob: 5232b010214351c80419c0054f8184d97b14d871 [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
Johannes Berge13bae42013-07-08 10:43:31 +0200675 sinfo.filled = 0;
676 sta_set_sinfo(sta, &sinfo);
Ben Greearb1ab7922012-04-23 12:50:30 -0700677 i = 0;
678 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700679 }
680 }
681
Ben Greear3073a7c2012-04-23 12:50:32 -0700682do_survey:
683 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
684 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200685 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700686
Johannes Berg55de9082012-07-26 17:24:39 +0200687 rcu_read_lock();
688 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
689 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100690 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200691 else
692 channel = NULL;
693 rcu_read_unlock();
694
695 if (channel) {
696 q = 0;
697 do {
698 survey.filled = 0;
699 if (drv_get_survey(local, q, &survey) != 0) {
700 survey.filled = 0;
701 break;
702 }
703 q++;
704 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700705 }
706
707 if (survey.filled)
708 data[i++] = survey.channel->center_freq;
709 else
710 data[i++] = 0;
711 if (survey.filled & SURVEY_INFO_NOISE_DBM)
712 data[i++] = (u8)survey.noise;
713 else
714 data[i++] = -1LL;
715 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
716 data[i++] = survey.channel_time;
717 else
718 data[i++] = -1LL;
719 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
720 data[i++] = survey.channel_time_busy;
721 else
722 data[i++] = -1LL;
723 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
724 data[i++] = survey.channel_time_ext_busy;
725 else
726 data[i++] = -1LL;
727 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
728 data[i++] = survey.channel_time_rx;
729 else
730 data[i++] = -1LL;
731 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
732 data[i++] = survey.channel_time_tx;
733 else
734 data[i++] = -1LL;
735
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300736 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700737
Ben Greear3073a7c2012-04-23 12:50:32 -0700738 if (WARN_ON(i != STA_STATS_LEN))
739 return;
740
Ben Greeare3521142012-04-23 12:50:31 -0700741 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700742}
743
744static void ieee80211_get_et_strings(struct wiphy *wiphy,
745 struct net_device *dev,
746 u32 sset, u8 *data)
747{
Ben Greeare3521142012-04-23 12:50:31 -0700748 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
749 int sz_sta_stats = 0;
750
Ben Greearb1ab7922012-04-23 12:50:30 -0700751 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700752 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Johannes Bergbd500af2013-05-06 21:09:46 +0200753 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700754 }
Ben Greeare3521142012-04-23 12:50:31 -0700755 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700756}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100757
758static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
759 int idx, u8 *mac, struct station_info *sinfo)
760{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100761 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300762 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100763 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100764 int ret = -ENOENT;
765
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300766 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100767
Johannes Berg3b53fde82009-11-16 12:00:37 +0100768 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100769 if (sta) {
770 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200771 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100772 sta_set_sinfo(sta, sinfo);
773 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100774
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300775 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100776
Johannes Bergd0709a62008-02-25 16:27:46 +0100777 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100778}
779
Holger Schurig12897232010-04-19 10:23:57 +0200780static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
781 int idx, struct survey_info *survey)
782{
783 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
784
Holger Schurig12897232010-04-19 10:23:57 +0200785 return drv_get_survey(local, idx, survey);
786}
787
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100788static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100789 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100790{
Johannes Bergabe60632009-11-25 17:46:18 +0100791 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300792 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100793 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100794 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100795
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300796 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100797
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100798 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100799 if (sta) {
800 ret = 0;
801 sta_set_sinfo(sta, sinfo);
802 }
803
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300804 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100805
806 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100807}
808
Johannes Berge8c9bd52012-06-06 08:18:22 +0200809static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100810 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200811{
Johannes Berg55de9082012-07-26 17:24:39 +0200812 struct ieee80211_local *local = wiphy_priv(wiphy);
813 struct ieee80211_sub_if_data *sdata;
814 int ret = 0;
815
Johannes Berg4bf88532012-11-09 11:39:59 +0100816 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200817 return 0;
818
819 mutex_lock(&local->iflist_mtx);
820 if (local->use_chanctx) {
821 sdata = rcu_dereference_protected(
822 local->monitor_sdata,
823 lockdep_is_held(&local->iflist_mtx));
824 if (sdata) {
825 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100826 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200827 IEEE80211_CHANCTX_EXCLUSIVE);
828 }
829 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100830 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200831 ieee80211_hw_config(local, 0);
832 }
833
Johannes Berg4bf88532012-11-09 11:39:59 +0100834 if (ret == 0)
835 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200836 mutex_unlock(&local->iflist_mtx);
837
838 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200839}
840
Arik Nemtsov02945822011-11-10 11:28:57 +0200841static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100842 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200843{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300844 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200845
846 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530847 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200848
Arik Nemtsovf7248282011-11-19 10:51:26 +0200849 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200850
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300851 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200852 if (!new)
853 return -ENOMEM;
854
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300855 new->len = resp_len;
856 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200857
858 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300859 if (old)
860 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200861
862 return 0;
863}
864
Simon Wunderlich73da7d52013-07-11 16:09:06 +0200865int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
866 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100867{
868 struct beacon_data *new, *old;
869 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100870 int size, err;
871 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100872
Johannes Berg40b275b2011-05-13 14:15:49 +0200873 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100874
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100875 /* Need to have a beacon head if we don't have one yet */
876 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100877 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100878
879 /* new or old head? */
880 if (params->head)
881 new_head_len = params->head_len;
882 else
883 new_head_len = old->head_len;
884
885 /* new or old tail? */
886 if (params->tail || !old)
887 /* params->tail_len will be zero for !params->tail */
888 new_tail_len = params->tail_len;
889 else
890 new_tail_len = old->tail_len;
891
892 size = sizeof(*new) + new_head_len + new_tail_len;
893
894 new = kzalloc(size, GFP_KERNEL);
895 if (!new)
896 return -ENOMEM;
897
898 /* start filling the new info now */
899
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100900 /*
901 * pointers go into the block we allocated,
902 * memory is | beacon_data | head | tail |
903 */
904 new->head = ((u8 *) new) + sizeof(*new);
905 new->tail = new->head + new_head_len;
906 new->head_len = new_head_len;
907 new->tail_len = new_tail_len;
908
909 /* copy in head */
910 if (params->head)
911 memcpy(new->head, params->head, new_head_len);
912 else
913 memcpy(new->head, old->head, new_head_len);
914
915 /* copy in optional tail */
916 if (params->tail)
917 memcpy(new->tail, params->tail, new_tail_len);
918 else
919 if (old)
920 memcpy(new->tail, old->tail, new_tail_len);
921
Johannes Berg88600202012-02-13 15:17:18 +0100922 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
923 params->probe_resp_len);
924 if (err < 0)
925 return err;
926 if (err == 0)
927 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100928
Eric Dumazetcf778b02012-01-12 04:41:32 +0000929 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100930
Johannes Berg88600202012-02-13 15:17:18 +0100931 if (old)
932 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100933
Johannes Berg88600202012-02-13 15:17:18 +0100934 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100935}
936
Johannes Berg88600202012-02-13 15:17:18 +0100937static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
938 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100939{
Johannes Berg88600202012-02-13 15:17:18 +0100940 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100941 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100942 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100943 u32 changed = BSS_CHANGED_BEACON_INT |
944 BSS_CHANGED_BEACON_ENABLED |
945 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100946 BSS_CHANGED_SSID |
947 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100948 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200949
Johannes Berg40b275b2011-05-13 14:15:49 +0200950 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100951 if (old)
952 return -EALREADY;
953
Johannes Berg04ecd252012-09-11 14:34:12 +0200954 /* TODO: make hostapd tell us what it wants */
955 sdata->smps_mode = IEEE80211_SMPS_OFF;
956 sdata->needed_rx_chains = sdata->local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +0100957 sdata->radar_required = params->radar_required;
Johannes Berg04ecd252012-09-11 14:34:12 +0200958
Johannes Berg4bf88532012-11-09 11:39:59 +0100959 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200960 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200961 if (err)
962 return err;
Johannes Berg1f4ac5a2013-02-08 12:07:44 +0100963 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Bergaa430da2012-05-16 23:50:18 +0200964
Johannes Berg665c93a2011-11-04 11:18:11 +0100965 /*
966 * Apply control port protocol, this allows us to
967 * not encrypt dynamic WEP control frames.
968 */
969 sdata->control_port_protocol = params->crypto.control_port_ethertype;
970 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
971 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
972 vlan->control_port_protocol =
973 params->crypto.control_port_ethertype;
974 vlan->control_port_no_encrypt =
975 params->crypto.control_port_no_encrypt;
976 }
977
Johannes Berg88600202012-02-13 15:17:18 +0100978 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
979 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100980 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100981
982 sdata->vif.bss_conf.ssid_len = params->ssid_len;
983 if (params->ssid_len)
984 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
985 params->ssid_len);
986 sdata->vif.bss_conf.hidden_ssid =
987 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
988
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100989 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
990 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
991 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
992 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
993 if (params->p2p_opp_ps)
994 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
995 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100996
Johannes Berg88600202012-02-13 15:17:18 +0100997 err = ieee80211_assign_beacon(sdata, &params->beacon);
998 if (err < 0)
999 return err;
1000 changed |= err;
1001
Johannes Berg10416382012-10-19 15:44:42 +02001002 err = drv_start_ap(sdata->local, sdata);
1003 if (err) {
1004 old = rtnl_dereference(sdata->u.ap.beacon);
1005 if (old)
1006 kfree_rcu(old, rcu_head);
1007 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1008 return err;
1009 }
1010
Johannes Berg88600202012-02-13 15:17:18 +01001011 ieee80211_bss_info_change_notify(sdata, changed);
1012
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001013 netif_carrier_on(dev);
1014 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1015 netif_carrier_on(vlan->dev);
1016
Johannes Berg665c93a2011-11-04 11:18:11 +01001017 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001018}
1019
Johannes Berg88600202012-02-13 15:17:18 +01001020static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1021 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001022{
Johannes Berg14db74b2008-07-29 13:22:52 +02001023 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001024 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001025 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001026
Johannes Berg14db74b2008-07-29 13:22:52 +02001027 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1028
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001029 /* don't allow changing the beacon while CSA is in place - offset
1030 * of channel switch counter may change
1031 */
1032 if (sdata->vif.csa_active)
1033 return -EBUSY;
1034
Johannes Berg40b275b2011-05-13 14:15:49 +02001035 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001036 if (!old)
1037 return -ENOENT;
1038
Johannes Berg88600202012-02-13 15:17:18 +01001039 err = ieee80211_assign_beacon(sdata, params);
1040 if (err < 0)
1041 return err;
1042 ieee80211_bss_info_change_notify(sdata, err);
1043 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001044}
1045
Johannes Berg88600202012-02-13 15:17:18 +01001046static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001047{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001048 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1049 struct ieee80211_sub_if_data *vlan;
1050 struct ieee80211_local *local = sdata->local;
1051 struct beacon_data *old_beacon;
1052 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001053 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001054
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001055 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1056 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001057 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001058 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001059
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001060 /* abort any running channel switch */
1061 sdata->vif.csa_active = false;
1062 cancel_work_sync(&sdata->csa_finalize_work);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001063 cancel_work_sync(&sdata->u.ap.request_smps_work);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001064
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001065 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001066 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1067 netif_carrier_off(vlan->dev);
1068 netif_carrier_off(dev);
1069
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001070 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001071 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001072 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1073 kfree_rcu(old_beacon, rcu_head);
1074 if (old_probe_resp)
1075 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001076
Felix Fietkau2d4072a2012-12-10 20:02:34 +01001077 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
Johannes Berg75de9112012-12-14 14:56:03 +01001078 sta_info_flush_defer(vlan);
1079 sta_info_flush_defer(sdata);
Bob Copeland8ceb5952013-04-18 18:26:49 -04001080 synchronize_net();
Johannes Berg75de9112012-12-14 14:56:03 +01001081 rcu_barrier();
Johannes Berg7b4396b2013-02-23 01:14:20 +01001082 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
Johannes Berg75de9112012-12-14 14:56:03 +01001083 sta_info_flush_cleanup(vlan);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001084 ieee80211_free_keys(vlan);
1085 }
Johannes Berg75de9112012-12-14 14:56:03 +01001086 sta_info_flush_cleanup(sdata);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001087 ieee80211_free_keys(sdata);
Johannes Berg75de9112012-12-14 14:56:03 +01001088
Johannes Bergd6a83222012-12-14 14:06:28 +01001089 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001090 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001091 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001092 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001093
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001094 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001095 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001096 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001097 cfg80211_cac_event(sdata->dev, &chandef,
1098 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001099 GFP_KERNEL);
1100 }
1101
Johannes Berg10416382012-10-19 15:44:42 +02001102 drv_stop_ap(sdata->local, sdata);
1103
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001104 /* free all potentially still buffered bcast frames */
1105 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1106 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1107
Johannes Berg1f4ac5a2013-02-08 12:07:44 +01001108 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001109 ieee80211_vif_release_channel(sdata);
1110
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001111 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001112}
1113
Johannes Berg4fd69312007-12-19 02:03:35 +01001114/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1115struct iapp_layer2_update {
1116 u8 da[ETH_ALEN]; /* broadcast */
1117 u8 sa[ETH_ALEN]; /* STA addr */
1118 __be16 len; /* 6 */
1119 u8 dsap; /* 0 */
1120 u8 ssap; /* 0 */
1121 u8 control;
1122 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001123} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001124
1125static void ieee80211_send_layer2_update(struct sta_info *sta)
1126{
1127 struct iapp_layer2_update *msg;
1128 struct sk_buff *skb;
1129
1130 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1131 * bridge devices */
1132
1133 skb = dev_alloc_skb(sizeof(*msg));
1134 if (!skb)
1135 return;
1136 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1137
1138 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1139 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1140
Johannes Berge83e6542012-07-13 16:23:07 +02001141 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001142 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001143 msg->len = htons(6);
1144 msg->dsap = 0;
1145 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1146 msg->control = 0xaf; /* XID response lsb.1111F101.
1147 * F=0 (no poll command; unsolicited frame) */
1148 msg->xid_info[0] = 0x81; /* XID format identifier */
1149 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1150 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1151
Johannes Bergd0709a62008-02-25 16:27:46 +01001152 skb->dev = sta->sdata->dev;
1153 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001154 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001155 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001156}
1157
Johannes Bergd582cff2012-10-26 17:53:44 +02001158static int sta_apply_auth_flags(struct ieee80211_local *local,
1159 struct sta_info *sta,
1160 u32 mask, u32 set)
1161{
1162 int ret;
1163
1164 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1165 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1166 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1167 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1168 if (ret)
1169 return ret;
1170 }
1171
1172 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1173 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1174 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1175 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1176 if (ret)
1177 return ret;
1178 }
1179
1180 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1181 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1182 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1183 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1184 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1185 else
1186 ret = 0;
1187 if (ret)
1188 return ret;
1189 }
1190
1191 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1192 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1193 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1194 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1195 if (ret)
1196 return ret;
1197 }
1198
1199 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1200 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1201 test_sta_flag(sta, WLAN_STA_AUTH)) {
1202 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1203 if (ret)
1204 return ret;
1205 }
1206
1207 return 0;
1208}
1209
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001210static int sta_apply_parameters(struct ieee80211_local *local,
1211 struct sta_info *sta,
1212 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001213{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001214 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001215 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001216 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001217 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001218 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001219
Johannes Berg55de9082012-07-26 17:24:39 +02001220 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001221
Johannes Bergeccb8e82009-05-11 21:57:56 +03001222 mask = params->sta_flags_mask;
1223 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001224
Johannes Bergd582cff2012-10-26 17:53:44 +02001225 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1226 /*
1227 * In mesh mode, ASSOCIATED isn't part of the nl80211
1228 * API but must follow AUTHENTICATED for driver state.
1229 */
1230 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1231 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1232 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1233 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001234 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1235 /*
1236 * TDLS -- everything follows authorized, but
1237 * only becoming authorized is possible, not
1238 * going back
1239 */
1240 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1241 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1242 BIT(NL80211_STA_FLAG_ASSOCIATED);
1243 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1244 BIT(NL80211_STA_FLAG_ASSOCIATED);
1245 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001246 }
1247
Johannes Bergd582cff2012-10-26 17:53:44 +02001248 ret = sta_apply_auth_flags(local, sta, mask, set);
1249 if (ret)
1250 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001251
Johannes Bergeccb8e82009-05-11 21:57:56 +03001252 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001253 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001254 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1255 else
1256 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001257 }
1258
1259 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001260 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001261 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001262 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001263 } else {
1264 clear_sta_flag(sta, WLAN_STA_WME);
1265 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001266 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001267 }
1268
1269 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001270 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001271 set_sta_flag(sta, WLAN_STA_MFP);
1272 else
1273 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001274 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001275
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001276 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001277 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001278 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1279 else
1280 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001281 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001282
Johannes Berg3b9ce802011-09-27 20:56:12 +02001283 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1284 sta->sta.uapsd_queues = params->uapsd_queues;
1285 sta->sta.max_sp = params->max_sp;
1286 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001287
Johannes Berg73651ee2008-02-25 16:27:47 +01001288 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001289 * cfg80211 validates this (1-2007) and allows setting the AID
1290 * only when creating a new station entry
1291 */
1292 if (params->aid)
1293 sta->sta.aid = params->aid;
1294
1295 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001296 * Some of the following updates would be racy if called on an
1297 * existing station, via ieee80211_change_station(). However,
1298 * all such changes are rejected by cfg80211 except for updates
1299 * changing the supported rates on an existing but not yet used
1300 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001301 */
1302
Johannes Berg4fd69312007-12-19 02:03:35 +01001303 if (params->listen_interval >= 0)
1304 sta->listen_interval = params->listen_interval;
1305
1306 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001307 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1308 sband, params->supported_rates,
1309 params->supported_rates_len,
1310 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001311 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001312
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001313 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001314 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001315 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001316
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001317 if (params->vht_capa)
1318 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001319 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001320
Javier Cardona9c3990a2011-05-03 16:57:11 -07001321 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001322#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001323 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001324
1325 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001326 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001327 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001328 if (sta->plink_state != NL80211_PLINK_ESTAB)
1329 changed = mesh_plink_inc_estab_count(
1330 sdata);
1331 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001332
1333 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001334 changed |= ieee80211_mps_set_sta_local_pm(sta,
1335 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001336 break;
1337 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001338 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001339 case NL80211_PLINK_OPN_SNT:
1340 case NL80211_PLINK_OPN_RCVD:
1341 case NL80211_PLINK_CNF_RCVD:
1342 case NL80211_PLINK_HOLDING:
1343 if (sta->plink_state == NL80211_PLINK_ESTAB)
1344 changed = mesh_plink_dec_estab_count(
1345 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001346 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001347
1348 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001349 changed |= ieee80211_mps_set_sta_local_pm(sta,
1350 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001351 break;
1352 default:
1353 /* nothing */
1354 break;
1355 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001356 }
1357
1358 switch (params->plink_action) {
1359 case NL80211_PLINK_ACTION_NO_ACTION:
1360 /* nothing */
1361 break;
1362 case NL80211_PLINK_ACTION_OPEN:
1363 changed |= mesh_plink_open(sta);
1364 break;
1365 case NL80211_PLINK_ACTION_BLOCK:
1366 changed |= mesh_plink_block(sta);
1367 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001368 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001369
1370 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001371 changed |=
1372 ieee80211_mps_set_sta_local_pm(sta,
1373 params->local_pm);
1374 ieee80211_bss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001375#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001376 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001377
1378 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001379}
1380
1381static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1382 u8 *mac, struct station_parameters *params)
1383{
Johannes Berg14db74b2008-07-29 13:22:52 +02001384 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001385 struct sta_info *sta;
1386 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001387 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001388 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001389
Johannes Berg4fd69312007-12-19 02:03:35 +01001390 if (params->vlan) {
1391 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1392
Johannes Berg05c914f2008-09-11 00:01:58 +02001393 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1394 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001395 return -EINVAL;
1396 } else
1397 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1398
Joe Perchesb203ca32012-05-08 18:56:52 +00001399 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001400 return -EINVAL;
1401
1402 if (is_multicast_ether_addr(mac))
1403 return -EINVAL;
1404
1405 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001406 if (!sta)
1407 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001408
Johannes Bergd582cff2012-10-26 17:53:44 +02001409 /*
1410 * defaults -- if userspace wants something else we'll
1411 * change it accordingly in sta_apply_parameters()
1412 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001413 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1414 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1415 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1416 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001417
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001418 err = sta_apply_parameters(local, sta, params);
1419 if (err) {
1420 sta_info_free(local, sta);
1421 return err;
1422 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001423
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001424 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001425 * for TDLS, rate control should be initialized only when
1426 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001427 */
1428 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1429 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001430
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001431 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1432 sdata->vif.type == NL80211_IFTYPE_AP;
1433
Johannes Berg34e89502010-02-03 13:59:58 +01001434 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001435 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001436 rcu_read_unlock();
1437 return err;
1438 }
1439
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001440 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001441 ieee80211_send_layer2_update(sta);
1442
1443 rcu_read_unlock();
1444
Johannes Berg4fd69312007-12-19 02:03:35 +01001445 return 0;
1446}
1447
1448static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1449 u8 *mac)
1450{
Johannes Berg14db74b2008-07-29 13:22:52 +02001451 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001452
Johannes Berg14db74b2008-07-29 13:22:52 +02001453 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1454
Johannes Berg34e89502010-02-03 13:59:58 +01001455 if (mac)
1456 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001457
Johannes Bergb998e8b2012-12-13 23:07:46 +01001458 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001459 return 0;
1460}
1461
1462static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001463 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001464 struct station_parameters *params)
1465{
Johannes Bergabe60632009-11-25 17:46:18 +01001466 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001467 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001468 struct sta_info *sta;
1469 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001470 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001471 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001472
Johannes Berg87be1e12011-12-14 12:20:29 +01001473 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001474
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001475 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001476 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001477 err = -ENOENT;
1478 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001479 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001480
Johannes Berg77ee7c82013-02-15 00:48:33 +01001481 switch (sdata->vif.type) {
1482 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001483 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001484 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001485 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001486 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001487 break;
1488 case NL80211_IFTYPE_ADHOC:
1489 statype = CFG80211_STA_IBSS;
1490 break;
1491 case NL80211_IFTYPE_STATION:
1492 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1493 statype = CFG80211_STA_AP_STA;
1494 break;
1495 }
1496 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1497 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1498 else
1499 statype = CFG80211_STA_TDLS_PEER_SETUP;
1500 break;
1501 case NL80211_IFTYPE_AP:
1502 case NL80211_IFTYPE_AP_VLAN:
1503 statype = CFG80211_STA_AP_CLIENT;
1504 break;
1505 default:
1506 err = -EOPNOTSUPP;
1507 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001508 }
1509
Johannes Berg77ee7c82013-02-15 00:48:33 +01001510 err = cfg80211_check_station_change(wiphy, params, statype);
1511 if (err)
1512 goto out_err;
1513
Johannes Bergd0709a62008-02-25 16:27:46 +01001514 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001515 bool prev_4addr = false;
1516 bool new_4addr = false;
1517
Johannes Berg4fd69312007-12-19 02:03:35 +01001518 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1519
Johannes Berg9bc383d2009-11-19 11:55:19 +01001520 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001521 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001522 err = -EBUSY;
1523 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001524 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001525
Eric Dumazetcf778b02012-01-12 04:41:32 +00001526 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001527 new_4addr = true;
1528 }
1529
1530 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1531 sta->sdata->u.vlan.sta) {
1532 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1533 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001534 }
1535
Johannes Berg14db74b2008-07-29 13:22:52 +02001536 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001537
1538 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1539 prev_4addr != new_4addr) {
1540 if (new_4addr)
1541 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1542 else
1543 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1544 }
1545
Johannes Berg4fd69312007-12-19 02:03:35 +01001546 ieee80211_send_layer2_update(sta);
1547 }
1548
Eliad Peller35b88622011-12-29 14:41:39 +02001549 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001550 if (err)
1551 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001552
Johannes Berg77ee7c82013-02-15 00:48:33 +01001553 /* When peer becomes authorized, init rate control as well */
1554 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1555 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001556 rate_control_rate_init(sta);
1557
Johannes Berg87be1e12011-12-14 12:20:29 +01001558 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001559
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001560 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1561 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1562 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1563 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1564 sta_info_tx_streams(sta) != 1) {
1565 ht_dbg(sta->sdata,
1566 "%pM just authorized and MIMO capable - update SMPS\n",
1567 sta->sta.addr);
1568 ieee80211_send_smps_action(sta->sdata,
1569 sta->sdata->bss->req_smps,
1570 sta->sta.addr,
1571 sta->sdata->vif.bss_conf.bssid);
1572 }
1573
Jason Young808118c2011-03-10 16:43:19 -08001574 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001575 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001576 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001577 ieee80211_recalc_ps_vif(sdata);
1578 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001579
Johannes Berg4fd69312007-12-19 02:03:35 +01001580 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001581out_err:
1582 mutex_unlock(&local->sta_mtx);
1583 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001584}
1585
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001586#ifdef CONFIG_MAC80211_MESH
1587static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1588 u8 *dst, u8 *next_hop)
1589{
Johannes Berg14db74b2008-07-29 13:22:52 +02001590 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001591 struct mesh_path *mpath;
1592 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001593
Johannes Berg14db74b2008-07-29 13:22:52 +02001594 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1595
Johannes Bergd0709a62008-02-25 16:27:46 +01001596 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001597 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001598 if (!sta) {
1599 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001600 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001601 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001602
Bob Copelandae76eef2013-03-29 09:38:39 -04001603 mpath = mesh_path_add(sdata, dst);
1604 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001605 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001606 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001607 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001608
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001609 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001610
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001611 rcu_read_unlock();
1612 return 0;
1613}
1614
1615static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001616 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001617{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001618 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001619
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001620 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001621 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001622
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001623 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001624 return 0;
1625}
1626
1627static int ieee80211_change_mpath(struct wiphy *wiphy,
1628 struct net_device *dev,
1629 u8 *dst, u8 *next_hop)
1630{
Johannes Berg14db74b2008-07-29 13:22:52 +02001631 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001632 struct mesh_path *mpath;
1633 struct sta_info *sta;
1634
Johannes Berg14db74b2008-07-29 13:22:52 +02001635 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1636
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001637 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001638
Johannes Bergabe60632009-11-25 17:46:18 +01001639 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001640 if (!sta) {
1641 rcu_read_unlock();
1642 return -ENOENT;
1643 }
1644
Johannes Bergbf7cd942013-02-15 14:40:31 +01001645 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001646 if (!mpath) {
1647 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001648 return -ENOENT;
1649 }
1650
1651 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001652
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001653 rcu_read_unlock();
1654 return 0;
1655}
1656
1657static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1658 struct mpath_info *pinfo)
1659{
Johannes Berga3836e02011-05-12 15:11:37 +02001660 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1661
1662 if (next_hop_sta)
1663 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001664 else
1665 memset(next_hop, 0, ETH_ALEN);
1666
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001667 memset(pinfo, 0, sizeof(*pinfo));
1668
Johannes Bergf5ea9122009-08-07 16:17:38 +02001669 pinfo->generation = mesh_paths_generation;
1670
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001671 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001672 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001673 MPATH_INFO_METRIC |
1674 MPATH_INFO_EXPTIME |
1675 MPATH_INFO_DISCOVERY_TIMEOUT |
1676 MPATH_INFO_DISCOVERY_RETRIES |
1677 MPATH_INFO_FLAGS;
1678
1679 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001680 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001681 pinfo->metric = mpath->metric;
1682 if (time_before(jiffies, mpath->exp_time))
1683 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1684 pinfo->discovery_timeout =
1685 jiffies_to_msecs(mpath->discovery_timeout);
1686 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001687 if (mpath->flags & MESH_PATH_ACTIVE)
1688 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1689 if (mpath->flags & MESH_PATH_RESOLVING)
1690 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001691 if (mpath->flags & MESH_PATH_SN_VALID)
1692 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001693 if (mpath->flags & MESH_PATH_FIXED)
1694 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001695 if (mpath->flags & MESH_PATH_RESOLVED)
1696 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001697}
1698
1699static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1700 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1701
1702{
Johannes Berg14db74b2008-07-29 13:22:52 +02001703 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001704 struct mesh_path *mpath;
1705
Johannes Berg14db74b2008-07-29 13:22:52 +02001706 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1707
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001708 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001709 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001710 if (!mpath) {
1711 rcu_read_unlock();
1712 return -ENOENT;
1713 }
1714 memcpy(dst, mpath->dst, ETH_ALEN);
1715 mpath_set_pinfo(mpath, next_hop, pinfo);
1716 rcu_read_unlock();
1717 return 0;
1718}
1719
1720static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1721 int idx, u8 *dst, u8 *next_hop,
1722 struct mpath_info *pinfo)
1723{
Johannes Berg14db74b2008-07-29 13:22:52 +02001724 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001725 struct mesh_path *mpath;
1726
Johannes Berg14db74b2008-07-29 13:22:52 +02001727 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1728
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001729 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001730 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001731 if (!mpath) {
1732 rcu_read_unlock();
1733 return -ENOENT;
1734 }
1735 memcpy(dst, mpath->dst, ETH_ALEN);
1736 mpath_set_pinfo(mpath, next_hop, pinfo);
1737 rcu_read_unlock();
1738 return 0;
1739}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001740
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001741static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001742 struct net_device *dev,
1743 struct mesh_config *conf)
1744{
1745 struct ieee80211_sub_if_data *sdata;
1746 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1747
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001748 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1749 return 0;
1750}
1751
1752static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1753{
1754 return (mask >> (parm-1)) & 0x1;
1755}
1756
Javier Cardonac80d5452010-12-16 17:37:49 -08001757static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1758 const struct mesh_setup *setup)
1759{
1760 u8 *new_ie;
1761 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001762 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1763 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001764
Javier Cardona581a8b02011-04-07 15:08:27 -07001765 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001766 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001767 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001768
Javier Cardona581a8b02011-04-07 15:08:27 -07001769 if (setup->ie_len) {
1770 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001771 GFP_KERNEL);
1772 if (!new_ie)
1773 return -ENOMEM;
1774 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001775 ifmsh->ie_len = setup->ie_len;
1776 ifmsh->ie = new_ie;
1777 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001778
1779 /* now copy the rest of the setup parameters */
1780 ifmsh->mesh_id_len = setup->mesh_id_len;
1781 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001782 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001783 ifmsh->mesh_pp_id = setup->path_sel_proto;
1784 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001785 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001786 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001787 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1788 if (setup->is_authenticated)
1789 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1790 if (setup->is_secure)
1791 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001792
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001793 /* mcast rate setting in Mesh Node */
1794 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1795 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001796 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001797
Marco Porsch9bdbf042013-01-07 16:04:51 +01001798 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1799 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1800
Javier Cardonac80d5452010-12-16 17:37:49 -08001801 return 0;
1802}
1803
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001804static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001805 struct net_device *dev, u32 mask,
1806 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001807{
1808 struct mesh_config *conf;
1809 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001810 struct ieee80211_if_mesh *ifmsh;
1811
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001812 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001813 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001814
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001815 /* Set the config options which we are interested in setting */
1816 conf = &(sdata->u.mesh.mshcfg);
1817 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1818 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1819 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1820 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1821 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1822 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1823 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1824 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1825 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1826 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1827 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1828 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001829 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001830 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001831 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1832 if (ifmsh->user_mpm)
1833 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001834 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001835 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001836 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1837 conf->dot11MeshNbrOffsetMaxNeighbor =
1838 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001839 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1840 conf->dot11MeshHWMPmaxPREQretries =
1841 nconf->dot11MeshHWMPmaxPREQretries;
1842 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1843 conf->path_refresh_time = nconf->path_refresh_time;
1844 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1845 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1846 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1847 conf->dot11MeshHWMPactivePathTimeout =
1848 nconf->dot11MeshHWMPactivePathTimeout;
1849 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1850 conf->dot11MeshHWMPpreqMinInterval =
1851 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001852 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1853 conf->dot11MeshHWMPperrMinInterval =
1854 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001855 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1856 mask))
1857 conf->dot11MeshHWMPnetDiameterTraversalTime =
1858 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001859 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1860 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1861 ieee80211_mesh_root_setup(ifmsh);
1862 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001863 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001864 /* our current gate announcement implementation rides on root
1865 * announcements, so require this ifmsh to also be a root node
1866 * */
1867 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001868 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1869 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001870 ieee80211_mesh_root_setup(ifmsh);
1871 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001872 conf->dot11MeshGateAnnouncementProtocol =
1873 nconf->dot11MeshGateAnnouncementProtocol;
1874 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001875 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001876 conf->dot11MeshHWMPRannInterval =
1877 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001878 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1879 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001880 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1881 /* our RSSI threshold implementation is supported only for
1882 * devices that report signal in dBm.
1883 */
1884 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1885 return -ENOTSUPP;
1886 conf->rssi_threshold = nconf->rssi_threshold;
1887 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001888 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1889 conf->ht_opmode = nconf->ht_opmode;
1890 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1891 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1892 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001893 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1894 conf->dot11MeshHWMPactivePathToRootTimeout =
1895 nconf->dot11MeshHWMPactivePathToRootTimeout;
1896 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1897 conf->dot11MeshHWMProotInterval =
1898 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001899 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1900 conf->dot11MeshHWMPconfirmationInterval =
1901 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001902 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1903 conf->power_mode = nconf->power_mode;
1904 ieee80211_mps_local_status_update(sdata);
1905 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001906 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001907 conf->dot11MeshAwakeWindowDuration =
1908 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001909 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1910 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001911 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001912 return 0;
1913}
1914
Johannes Berg29cbe682010-12-03 09:20:44 +01001915static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1916 const struct mesh_config *conf,
1917 const struct mesh_setup *setup)
1918{
1919 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1920 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001921 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001922
Javier Cardonac80d5452010-12-16 17:37:49 -08001923 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1924 err = copy_mesh_setup(ifmsh, setup);
1925 if (err)
1926 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001927
Johannes Berg04ecd252012-09-11 14:34:12 +02001928 /* can mesh use other SMPS modes? */
1929 sdata->smps_mode = IEEE80211_SMPS_OFF;
1930 sdata->needed_rx_chains = sdata->local->rx_chains;
1931
Johannes Berg4bf88532012-11-09 11:39:59 +01001932 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001933 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001934 if (err)
1935 return err;
1936
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001937 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001938}
1939
1940static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1941{
1942 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1943
1944 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001945 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001946
1947 return 0;
1948}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001949#endif
1950
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001951static int ieee80211_change_bss(struct wiphy *wiphy,
1952 struct net_device *dev,
1953 struct bss_parameters *params)
1954{
Johannes Berg55de9082012-07-26 17:24:39 +02001955 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1956 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001957 u32 changed = 0;
1958
Johannes Berg55de9082012-07-26 17:24:39 +02001959 if (!rtnl_dereference(sdata->u.ap.beacon))
1960 return -ENOENT;
1961
1962 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001963
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001964 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001965 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001966 changed |= BSS_CHANGED_ERP_CTS_PROT;
1967 }
1968 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001969 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001970 params->use_short_preamble;
1971 changed |= BSS_CHANGED_ERP_PREAMBLE;
1972 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001973
1974 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001975 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001976 sdata->vif.bss_conf.use_short_slot = true;
1977 changed |= BSS_CHANGED_ERP_SLOT;
1978 }
1979
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001980 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001981 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001982 params->use_short_slot_time;
1983 changed |= BSS_CHANGED_ERP_SLOT;
1984 }
1985
Jouni Malinen90c97a02008-10-30 16:59:22 +02001986 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001987 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1988 wiphy->bands[band],
1989 params->basic_rates,
1990 params->basic_rates_len,
1991 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001992 changed |= BSS_CHANGED_BASIC_RATES;
1993 }
1994
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001995 if (params->ap_isolate >= 0) {
1996 if (params->ap_isolate)
1997 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1998 else
1999 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2000 }
2001
Helmut Schaa80d7e402010-11-19 12:40:26 +01002002 if (params->ht_opmode >= 0) {
2003 sdata->vif.bss_conf.ht_operation_mode =
2004 (u16) params->ht_opmode;
2005 changed |= BSS_CHANGED_HT;
2006 }
2007
Johannes Berg339afbf2012-11-14 15:21:17 +01002008 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002009 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2010 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2011 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2012 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01002013 changed |= BSS_CHANGED_P2P_PS;
2014 }
2015
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002016 if (params->p2p_opp_ps > 0) {
2017 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2018 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2019 changed |= BSS_CHANGED_P2P_PS;
2020 } else if (params->p2p_opp_ps == 0) {
2021 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2022 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002023 changed |= BSS_CHANGED_P2P_PS;
2024 }
2025
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002026 ieee80211_bss_info_change_notify(sdata, changed);
2027
2028 return 0;
2029}
2030
Jouni Malinen31888482008-10-30 16:59:24 +02002031static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002032 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002033 struct ieee80211_txq_params *params)
2034{
2035 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002036 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002037 struct ieee80211_tx_queue_params p;
2038
2039 if (!local->ops->conf_tx)
2040 return -EOPNOTSUPP;
2041
Johannes Berg54bcbc62012-03-28 11:04:25 +02002042 if (local->hw.queues < IEEE80211_NUM_ACS)
2043 return -EOPNOTSUPP;
2044
Jouni Malinen31888482008-10-30 16:59:24 +02002045 memset(&p, 0, sizeof(p));
2046 p.aifs = params->aifs;
2047 p.cw_max = params->cwmax;
2048 p.cw_min = params->cwmin;
2049 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002050
2051 /*
2052 * Setting tx queue params disables u-apsd because it's only
2053 * called in master mode.
2054 */
2055 p.uapsd = false;
2056
Johannes Berga3304b02012-03-28 11:04:24 +02002057 sdata->tx_conf[params->ac] = p;
2058 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002059 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002060 "failed to set TX queue parameters for AC %d\n",
2061 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002062 return -EINVAL;
2063 }
2064
Johannes Berg7d257452012-07-06 17:37:43 +02002065 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2066
Jouni Malinen31888482008-10-30 16:59:24 +02002067 return 0;
2068}
2069
Bob Copeland665af4f2009-01-19 11:20:53 -05002070#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002071static int ieee80211_suspend(struct wiphy *wiphy,
2072 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002073{
Johannes Bergeecc4802011-05-04 15:37:29 +02002074 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002075}
2076
2077static int ieee80211_resume(struct wiphy *wiphy)
2078{
2079 return __ieee80211_resume(wiphy_priv(wiphy));
2080}
2081#else
2082#define ieee80211_suspend NULL
2083#define ieee80211_resume NULL
2084#endif
2085
Johannes Berg2a519312009-02-10 21:25:55 +01002086static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002087 struct cfg80211_scan_request *req)
2088{
Johannes Bergfd014282012-06-18 19:17:03 +02002089 struct ieee80211_sub_if_data *sdata;
2090
2091 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002092
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002093 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2094 case NL80211_IFTYPE_STATION:
2095 case NL80211_IFTYPE_ADHOC:
2096 case NL80211_IFTYPE_MESH_POINT:
2097 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002098 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002099 break;
2100 case NL80211_IFTYPE_P2P_GO:
2101 if (sdata->local->ops->hw_scan)
2102 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002103 /*
2104 * FIXME: implement NoA while scanning in software,
2105 * for now fall through to allow scanning only when
2106 * beaconing hasn't been configured yet
2107 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002108 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002109 /*
2110 * If the scan has been forced (and the driver supports
2111 * forcing), don't care about being beaconing already.
2112 * This will create problems to the attached stations (e.g. all
2113 * the frames sent while scanning on other channel will be
2114 * lost)
2115 */
2116 if (sdata->u.ap.beacon &&
2117 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2118 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002119 return -EOPNOTSUPP;
2120 break;
2121 default:
2122 return -EOPNOTSUPP;
2123 }
Johannes Berg2a519312009-02-10 21:25:55 +01002124
2125 return ieee80211_request_scan(sdata, req);
2126}
2127
Luciano Coelho79f460c2011-05-11 17:09:36 +03002128static int
2129ieee80211_sched_scan_start(struct wiphy *wiphy,
2130 struct net_device *dev,
2131 struct cfg80211_sched_scan_request *req)
2132{
2133 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2134
2135 if (!sdata->local->ops->sched_scan_start)
2136 return -EOPNOTSUPP;
2137
2138 return ieee80211_request_sched_scan_start(sdata, req);
2139}
2140
2141static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002142ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002143{
2144 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2145
2146 if (!sdata->local->ops->sched_scan_stop)
2147 return -EOPNOTSUPP;
2148
Luciano Coelho85a99942011-05-12 16:28:29 +03002149 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002150}
2151
Jouni Malinen636a5d32009-03-19 13:39:22 +02002152static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2153 struct cfg80211_auth_request *req)
2154{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002155 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002156}
2157
2158static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2159 struct cfg80211_assoc_request *req)
2160{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002161 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002162}
2163
2164static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002165 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002166{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002167 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002168}
2169
2170static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002171 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002172{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002173 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002174}
2175
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002176static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2177 struct cfg80211_ibss_params *params)
2178{
Johannes Berg55de9082012-07-26 17:24:39 +02002179 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002180}
2181
2182static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2183{
Johannes Berg55de9082012-07-26 17:24:39 +02002184 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002185}
2186
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002187static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2188 int rate[IEEE80211_NUM_BANDS])
2189{
2190 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2191
Cong Ding9887dbf2013-02-06 17:23:45 +01002192 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2193 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002194
2195 return 0;
2196}
2197
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002198static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2199{
2200 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002201 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002202
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002203 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2204 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2205
2206 if (err)
2207 return err;
2208 }
2209
Lukáš Turek310bc672009-12-21 22:50:48 +01002210 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2211 err = drv_set_coverage_class(local, wiphy->coverage_class);
2212
2213 if (err)
2214 return err;
2215 }
2216
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002217 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002218 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002219
Johannes Berg24487982009-04-23 18:52:52 +02002220 if (err)
2221 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002222 }
2223
Johannes Berg8bc83c22012-11-09 18:38:32 +01002224 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2225 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2226 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002227 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002228 }
2229 if (changed & WIPHY_PARAM_RETRY_LONG) {
2230 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2231 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002232 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002233 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002234 if (changed &
2235 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2236 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2237
2238 return 0;
2239}
2240
Johannes Berg7643a2c2009-06-02 13:01:39 +02002241static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002242 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002243 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002244{
2245 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002246 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002247
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002248 if (wdev) {
2249 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2250
2251 switch (type) {
2252 case NL80211_TX_POWER_AUTOMATIC:
2253 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2254 break;
2255 case NL80211_TX_POWER_LIMITED:
2256 case NL80211_TX_POWER_FIXED:
2257 if (mbm < 0 || (mbm % 100))
2258 return -EOPNOTSUPP;
2259 sdata->user_power_level = MBM_TO_DBM(mbm);
2260 break;
2261 }
2262
2263 ieee80211_recalc_txpower(sdata);
2264
2265 return 0;
2266 }
Johannes Berg55de9082012-07-26 17:24:39 +02002267
Johannes Berg7643a2c2009-06-02 13:01:39 +02002268 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002269 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002270 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002271 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002272 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002273 case NL80211_TX_POWER_FIXED:
2274 if (mbm < 0 || (mbm % 100))
2275 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002276 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002277 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002278 }
2279
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002280 mutex_lock(&local->iflist_mtx);
2281 list_for_each_entry(sdata, &local->interfaces, list)
2282 sdata->user_power_level = local->user_power_level;
2283 list_for_each_entry(sdata, &local->interfaces, list)
2284 ieee80211_recalc_txpower(sdata);
2285 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002286
2287 return 0;
2288}
2289
Johannes Bergc8442112012-10-24 10:17:18 +02002290static int ieee80211_get_tx_power(struct wiphy *wiphy,
2291 struct wireless_dev *wdev,
2292 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002293{
2294 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002295 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002296
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002297 if (!local->use_chanctx)
2298 *dbm = local->hw.conf.power_level;
2299 else
2300 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002301
Johannes Berg7643a2c2009-06-02 13:01:39 +02002302 return 0;
2303}
2304
Johannes Bergab737a42009-07-01 21:26:58 +02002305static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002306 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002307{
2308 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2309
2310 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2311
2312 return 0;
2313}
2314
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002315static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2316{
2317 struct ieee80211_local *local = wiphy_priv(wiphy);
2318
2319 drv_rfkill_poll(local);
2320}
2321
Johannes Bergaff89a92009-07-01 21:26:51 +02002322#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002323static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2324 struct wireless_dev *wdev,
2325 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002326{
2327 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002328 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002329
2330 if (!local->ops->testmode_cmd)
2331 return -EOPNOTSUPP;
2332
David Spinadel52981cd2013-07-31 18:06:22 +03002333 if (wdev) {
2334 struct ieee80211_sub_if_data *sdata;
2335
2336 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2337 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2338 vif = &sdata->vif;
2339 }
2340
2341 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002342}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002343
2344static int ieee80211_testmode_dump(struct wiphy *wiphy,
2345 struct sk_buff *skb,
2346 struct netlink_callback *cb,
2347 void *data, int len)
2348{
2349 struct ieee80211_local *local = wiphy_priv(wiphy);
2350
2351 if (!local->ops->testmode_dump)
2352 return -EOPNOTSUPP;
2353
2354 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2355}
Johannes Bergaff89a92009-07-01 21:26:51 +02002356#endif
2357
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002358int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2359 enum ieee80211_smps_mode smps_mode)
2360{
2361 struct sta_info *sta;
2362 enum ieee80211_smps_mode old_req;
2363 int i;
2364
2365 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2366 return -EINVAL;
2367
2368 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2369 return 0;
2370
2371 old_req = sdata->u.ap.req_smps;
2372 sdata->u.ap.req_smps = smps_mode;
2373
2374 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2375 if (old_req == smps_mode ||
2376 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2377 return 0;
2378
2379 /* If no associated stations, there's no need to do anything */
2380 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2381 sdata->smps_mode = smps_mode;
2382 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2383 return 0;
2384 }
2385
2386 ht_dbg(sdata,
2387 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2388 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2389
2390 mutex_lock(&sdata->local->sta_mtx);
2391 for (i = 0; i < STA_HASH_SIZE; i++) {
2392 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2393 lockdep_is_held(&sdata->local->sta_mtx));
2394 sta;
2395 sta = rcu_dereference_protected(sta->hnext,
2396 lockdep_is_held(&sdata->local->sta_mtx))) {
2397 /*
2398 * Only stations associated to our AP and
2399 * associated VLANs
2400 */
2401 if (sta->sdata->bss != &sdata->u.ap)
2402 continue;
2403
2404 /* This station doesn't support MIMO - skip it */
2405 if (sta_info_tx_streams(sta) == 1)
2406 continue;
2407
2408 /*
2409 * Don't wake up a STA just to send the action frame
2410 * unless we are getting more restrictive.
2411 */
2412 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2413 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2414 smps_mode)) {
2415 ht_dbg(sdata,
2416 "Won't send SMPS to sleeping STA %pM\n",
2417 sta->sta.addr);
2418 continue;
2419 }
2420
2421 /*
2422 * If the STA is not authorized, wait until it gets
2423 * authorized and the action frame will be sent then.
2424 */
2425 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2426 continue;
2427
2428 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2429 ieee80211_send_smps_action(sdata, smps_mode,
2430 sta->sta.addr,
2431 sdata->vif.bss_conf.bssid);
2432 }
2433 }
2434 mutex_unlock(&sdata->local->sta_mtx);
2435
2436 sdata->smps_mode = smps_mode;
2437 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2438
2439 return 0;
2440}
2441
2442int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2443 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002444{
2445 const u8 *ap;
2446 enum ieee80211_smps_mode old_req;
2447 int err;
2448
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002449 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002450
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002451 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2452 return -EINVAL;
2453
Johannes Berg0f782312009-12-01 13:37:02 +01002454 old_req = sdata->u.mgd.req_smps;
2455 sdata->u.mgd.req_smps = smps_mode;
2456
2457 if (old_req == smps_mode &&
2458 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2459 return 0;
2460
2461 /*
2462 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002463 * association, there's no need to do anything, just store
2464 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002465 */
2466 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002467 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002468 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002469
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002470 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002471
2472 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2473 if (sdata->u.mgd.powersave)
2474 smps_mode = IEEE80211_SMPS_DYNAMIC;
2475 else
2476 smps_mode = IEEE80211_SMPS_OFF;
2477 }
2478
2479 /* send SM PS frame to AP */
2480 err = ieee80211_send_smps_action(sdata, smps_mode,
2481 ap, ap);
2482 if (err)
2483 sdata->u.mgd.req_smps = old_req;
2484
2485 return err;
2486}
2487
Johannes Bergbc92afd2009-07-01 21:26:57 +02002488static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2489 bool enabled, int timeout)
2490{
2491 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2492 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002493
Chun-Yeow Yeohee1f6682013-01-10 23:31:54 +08002494 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2495 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002496 return -EOPNOTSUPP;
2497
Johannes Bergbc92afd2009-07-01 21:26:57 +02002498 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2499 return -EOPNOTSUPP;
2500
2501 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002502 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002503 return 0;
2504
2505 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002506 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002507
Johannes Berg0f782312009-12-01 13:37:02 +01002508 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002509 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002510 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002511 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002512
Johannes Bergbc92afd2009-07-01 21:26:57 +02002513 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2514 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2515
2516 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002517 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002518
2519 return 0;
2520}
2521
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002522static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2523 struct net_device *dev,
2524 s32 rssi_thold, u32 rssi_hyst)
2525{
2526 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002527 struct ieee80211_vif *vif = &sdata->vif;
2528 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2529
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002530 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2531 rssi_hyst == bss_conf->cqm_rssi_hyst)
2532 return 0;
2533
2534 bss_conf->cqm_rssi_thold = rssi_thold;
2535 bss_conf->cqm_rssi_hyst = rssi_hyst;
2536
2537 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002538 if (sdata->u.mgd.associated &&
2539 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002540 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2541
2542 return 0;
2543}
2544
Johannes Berg99303802009-07-01 21:26:59 +02002545static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2546 struct net_device *dev,
2547 const u8 *addr,
2548 const struct cfg80211_bitrate_mask *mask)
2549{
2550 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2551 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302552 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002553
Eliad Peller554a43d2012-06-12 12:41:15 +03002554 if (!ieee80211_sdata_running(sdata))
2555 return -ENETDOWN;
2556
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302557 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2558 ret = drv_set_bitrate_mask(local, sdata, mask);
2559 if (ret)
2560 return ret;
2561 }
Johannes Berg99303802009-07-01 21:26:59 +02002562
Simon Wunderlich19468412012-01-28 17:25:33 +01002563 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002564 struct ieee80211_supported_band *sband = wiphy->bands[i];
2565 int j;
2566
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002567 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002568 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2569 sizeof(mask->control[i].mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002570
2571 sdata->rc_has_mcs_mask[i] = false;
2572 if (!sband)
2573 continue;
2574
2575 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2576 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2577 sdata->rc_has_mcs_mask[i] = true;
2578 break;
2579 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002580 }
Johannes Berg99303802009-07-01 21:26:59 +02002581
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002582 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002583}
2584
Johannes Berg2eb278e2012-06-05 14:28:42 +02002585static int ieee80211_start_roc_work(struct ieee80211_local *local,
2586 struct ieee80211_sub_if_data *sdata,
2587 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002588 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002589 struct sk_buff *txskb,
2590 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002591{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002592 struct ieee80211_roc_work *roc, *tmp;
2593 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002594 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002595
2596 lockdep_assert_held(&local->mtx);
2597
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002598 if (local->use_chanctx && !local->ops->remain_on_channel)
2599 return -EOPNOTSUPP;
2600
Johannes Berg2eb278e2012-06-05 14:28:42 +02002601 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2602 if (!roc)
2603 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002604
Johannes Berg2eb278e2012-06-05 14:28:42 +02002605 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002606 roc->duration = duration;
2607 roc->req_duration = duration;
2608 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002609 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002610 roc->mgmt_tx_cookie = (unsigned long)txskb;
2611 roc->sdata = sdata;
2612 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2613 INIT_LIST_HEAD(&roc->dependents);
2614
2615 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002616 if (!list_empty(&local->roc_list) ||
2617 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002618 goto out_check_combine;
2619
2620 /* if not HW assist, just queue & schedule work */
2621 if (!local->ops->remain_on_channel) {
2622 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2623 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002624 }
2625
Johannes Berg2eb278e2012-06-05 14:28:42 +02002626 /* otherwise actually kick it off here (for error handling) */
2627
2628 /*
2629 * If the duration is zero, then the driver
2630 * wouldn't actually do anything. Set it to
2631 * 10 for now.
2632 *
2633 * TODO: cancel the off-channel operation
2634 * when we get the SKB's TX status and
2635 * the wait time was zero before.
2636 */
2637 if (!duration)
2638 duration = 10;
2639
Ilan Peerd339d5c2013-02-12 09:34:13 +02002640 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002641 if (ret) {
2642 kfree(roc);
2643 return ret;
2644 }
2645
2646 roc->started = true;
2647 goto out_queue;
2648
2649 out_check_combine:
2650 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002651 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002652 continue;
2653
2654 /*
2655 * Extend this ROC if possible:
2656 *
2657 * If it hasn't started yet, just increase the duration
2658 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002659 * If the type of the new ROC has higher priority, modify the
2660 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002661 */
2662 if (!tmp->started) {
2663 list_add_tail(&roc->list, &tmp->dependents);
2664 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002665 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002666 queued = true;
2667 break;
2668 }
2669
2670 /* If it has already started, it's more difficult ... */
2671 if (local->ops->remain_on_channel) {
2672 unsigned long j = jiffies;
2673
2674 /*
2675 * In the offloaded ROC case, if it hasn't begun, add
2676 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002677 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002678 * check that there's still a minimum time left and
2679 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002680 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002681 * a reduced time so we'll ask the driver to execute
2682 * it right after finishing the previous one, in the
2683 * hope that it'll also be executed right afterwards,
2684 * effectively extending the old one.
2685 * If there's no minimum time left, just add it to the
2686 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002687 * TODO: the ROC type is ignored here, assuming that it
2688 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002689 */
2690 if (!tmp->hw_begun) {
2691 list_add_tail(&roc->list, &tmp->dependents);
2692 queued = true;
2693 break;
2694 }
2695
2696 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2697 tmp->hw_start_time +
2698 msecs_to_jiffies(tmp->duration))) {
2699 int new_dur;
2700
2701 ieee80211_handle_roc_started(roc);
2702
2703 new_dur = roc->duration -
2704 jiffies_to_msecs(tmp->hw_start_time +
2705 msecs_to_jiffies(
2706 tmp->duration) -
2707 j);
2708
2709 if (new_dur > 0) {
2710 /* add right after tmp */
2711 list_add(&roc->list, &tmp->list);
2712 } else {
2713 list_add_tail(&roc->list,
2714 &tmp->dependents);
2715 }
2716 queued = true;
2717 }
2718 } else if (del_timer_sync(&tmp->work.timer)) {
2719 unsigned long new_end;
2720
2721 /*
2722 * In the software ROC case, cancel the timer, if
2723 * that fails then the finish work is already
2724 * queued/pending and thus we queue the new ROC
2725 * normally, if that succeeds then we can extend
2726 * the timer duration and TX the frame (if any.)
2727 */
2728
2729 list_add_tail(&roc->list, &tmp->dependents);
2730 queued = true;
2731
2732 new_end = jiffies + msecs_to_jiffies(roc->duration);
2733
2734 /* ok, it was started & we canceled timer */
2735 if (time_after(new_end, tmp->work.timer.expires))
2736 mod_timer(&tmp->work.timer, new_end);
2737 else
2738 add_timer(&tmp->work.timer);
2739
2740 ieee80211_handle_roc_started(roc);
2741 }
2742 break;
2743 }
2744
2745 out_queue:
2746 if (!queued)
2747 list_add_tail(&roc->list, &local->roc_list);
2748
2749 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002750 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002751 * or the SKB (for mgmt TX)
2752 */
Johannes Berg50febf62012-10-26 16:13:06 +02002753 if (!txskb) {
2754 /* local->mtx protects this */
2755 local->roc_cookie_counter++;
2756 roc->cookie = local->roc_cookie_counter;
2757 /* wow, you wrapped 64 bits ... more likely a bug */
2758 if (WARN_ON(roc->cookie == 0)) {
2759 roc->cookie = 1;
2760 local->roc_cookie_counter++;
2761 }
2762 *cookie = roc->cookie;
2763 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002764 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002765 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002766
2767 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002768}
2769
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002770static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002771 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002772 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002773 unsigned int duration,
2774 u64 *cookie)
2775{
Johannes Berg71bbc992012-06-15 15:30:18 +02002776 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002777 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002778 int ret;
2779
Johannes Berg2eb278e2012-06-05 14:28:42 +02002780 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002781 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002782 duration, cookie, NULL,
2783 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002784 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002785
Johannes Berg2eb278e2012-06-05 14:28:42 +02002786 return ret;
2787}
2788
2789static int ieee80211_cancel_roc(struct ieee80211_local *local,
2790 u64 cookie, bool mgmt_tx)
2791{
2792 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2793 int ret;
2794
2795 mutex_lock(&local->mtx);
2796 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002797 struct ieee80211_roc_work *dep, *tmp2;
2798
2799 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002800 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002801 continue;
2802 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2803 continue;
2804 /* found dependent item -- just remove it */
2805 list_del(&dep->list);
2806 mutex_unlock(&local->mtx);
2807
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002808 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002809 return 0;
2810 }
2811
Johannes Berg50febf62012-10-26 16:13:06 +02002812 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002813 continue;
2814 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2815 continue;
2816
2817 found = roc;
2818 break;
2819 }
2820
2821 if (!found) {
2822 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002823 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002824 }
Johannes Berg21f83582010-12-18 17:20:47 +01002825
Johannes Berge979e332012-06-11 17:09:41 +02002826 /*
2827 * We found the item to cancel, so do that. Note that it
2828 * may have dependents, which we also cancel (and send
2829 * the expired signal for.) Not doing so would be quite
2830 * tricky here, but we may need to fix it later.
2831 */
2832
Johannes Berg2eb278e2012-06-05 14:28:42 +02002833 if (local->ops->remain_on_channel) {
2834 if (found->started) {
2835 ret = drv_cancel_remain_on_channel(local);
2836 if (WARN_ON_ONCE(ret)) {
2837 mutex_unlock(&local->mtx);
2838 return ret;
2839 }
2840 }
Johannes Berg21f83582010-12-18 17:20:47 +01002841
Johannes Berg2eb278e2012-06-05 14:28:42 +02002842 list_del(&found->list);
2843
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002844 if (found->started)
2845 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002846 mutex_unlock(&local->mtx);
2847
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002848 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002849 } else {
2850 /* work may be pending so use it all the time */
2851 found->abort = true;
2852 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2853
2854 mutex_unlock(&local->mtx);
2855
2856 /* work will clean up etc */
2857 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002858 WARN_ON(!found->to_be_freed);
2859 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002860 }
Johannes Berg21f83582010-12-18 17:20:47 +01002861
Johannes Berg21f83582010-12-18 17:20:47 +01002862 return 0;
2863}
2864
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002865static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002866 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002867 u64 cookie)
2868{
Johannes Berg71bbc992012-06-15 15:30:18 +02002869 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002870 struct ieee80211_local *local = sdata->local;
2871
Johannes Berg2eb278e2012-06-05 14:28:42 +02002872 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002873}
2874
Simon Wunderlich164eb022013-02-08 18:16:20 +01002875static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2876 struct net_device *dev,
2877 struct cfg80211_chan_def *chandef)
2878{
2879 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2880 struct ieee80211_local *local = sdata->local;
2881 unsigned long timeout;
2882 int err;
2883
2884 if (!list_empty(&local->roc_list) || local->scanning)
2885 return -EBUSY;
2886
2887 /* whatever, but channel contexts should not complain about that one */
2888 sdata->smps_mode = IEEE80211_SMPS_OFF;
2889 sdata->needed_rx_chains = local->rx_chains;
2890 sdata->radar_required = true;
2891
2892 mutex_lock(&local->iflist_mtx);
2893 err = ieee80211_vif_use_channel(sdata, chandef,
2894 IEEE80211_CHANCTX_SHARED);
2895 mutex_unlock(&local->iflist_mtx);
2896 if (err)
2897 return err;
2898
2899 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2900 ieee80211_queue_delayed_work(&sdata->local->hw,
2901 &sdata->dfs_cac_timer_work, timeout);
2902
2903 return 0;
2904}
2905
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002906static struct cfg80211_beacon_data *
2907cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2908{
2909 struct cfg80211_beacon_data *new_beacon;
2910 u8 *pos;
2911 int len;
2912
2913 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2914 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2915 beacon->probe_resp_len;
2916
2917 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2918 if (!new_beacon)
2919 return NULL;
2920
2921 pos = (u8 *)(new_beacon + 1);
2922 if (beacon->head_len) {
2923 new_beacon->head_len = beacon->head_len;
2924 new_beacon->head = pos;
2925 memcpy(pos, beacon->head, beacon->head_len);
2926 pos += beacon->head_len;
2927 }
2928 if (beacon->tail_len) {
2929 new_beacon->tail_len = beacon->tail_len;
2930 new_beacon->tail = pos;
2931 memcpy(pos, beacon->tail, beacon->tail_len);
2932 pos += beacon->tail_len;
2933 }
2934 if (beacon->beacon_ies_len) {
2935 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2936 new_beacon->beacon_ies = pos;
2937 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2938 pos += beacon->beacon_ies_len;
2939 }
2940 if (beacon->proberesp_ies_len) {
2941 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2942 new_beacon->proberesp_ies = pos;
2943 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2944 pos += beacon->proberesp_ies_len;
2945 }
2946 if (beacon->assocresp_ies_len) {
2947 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
2948 new_beacon->assocresp_ies = pos;
2949 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
2950 pos += beacon->assocresp_ies_len;
2951 }
2952 if (beacon->probe_resp_len) {
2953 new_beacon->probe_resp_len = beacon->probe_resp_len;
2954 beacon->probe_resp = pos;
2955 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
2956 pos += beacon->probe_resp_len;
2957 }
2958
2959 return new_beacon;
2960}
2961
2962void ieee80211_csa_finalize_work(struct work_struct *work)
2963{
2964 struct ieee80211_sub_if_data *sdata =
2965 container_of(work, struct ieee80211_sub_if_data,
2966 csa_finalize_work);
2967 struct ieee80211_local *local = sdata->local;
Michal Kazior0951ebb2013-10-18 14:57:00 -07002968 int err, changed = 0;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002969
2970 if (!ieee80211_sdata_running(sdata))
2971 return;
2972
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002973 sdata->radar_required = sdata->csa_radar_required;
2974 err = ieee80211_vif_change_channel(sdata, &local->csa_chandef,
2975 &changed);
2976 if (WARN_ON(err < 0))
2977 return;
2978
Arik Nemtsov7578d572013-09-01 17:15:51 +03002979 if (!local->use_chanctx) {
2980 local->_oper_chandef = local->csa_chandef;
2981 ieee80211_hw_config(local, 0);
2982 }
2983
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002984 ieee80211_bss_info_change_notify(sdata, changed);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002985
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02002986 switch (sdata->vif.type) {
2987 case NL80211_IFTYPE_AP:
2988 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
2989 if (err < 0)
2990 return;
2991 changed |= err;
2992 kfree(sdata->u.ap.next_beacon);
2993 sdata->u.ap.next_beacon = NULL;
2994
2995 ieee80211_bss_info_change_notify(sdata, err);
2996 break;
2997 case NL80211_IFTYPE_ADHOC:
2998 ieee80211_ibss_finish_csa(sdata);
2999 break;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003000#ifdef CONFIG_MAC80211_MESH
3001 case NL80211_IFTYPE_MESH_POINT:
3002 err = ieee80211_mesh_finish_csa(sdata);
3003 if (err < 0)
3004 return;
3005 break;
3006#endif
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003007 default:
3008 WARN_ON(1);
3009 return;
3010 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003011 sdata->vif.csa_active = false;
3012
3013 ieee80211_wake_queues_by_reason(&sdata->local->hw,
3014 IEEE80211_MAX_QUEUE_MAP,
3015 IEEE80211_QUEUE_STOP_REASON_CSA);
3016
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003017 cfg80211_ch_switch_notify(sdata->dev, &local->csa_chandef);
3018}
3019
3020static int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3021 struct cfg80211_csa_settings *params)
3022{
3023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3024 struct ieee80211_local *local = sdata->local;
3025 struct ieee80211_chanctx_conf *chanctx_conf;
3026 struct ieee80211_chanctx *chanctx;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07003027 struct ieee80211_if_mesh __maybe_unused *ifmsh;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003028 int err, num_chanctx;
3029
3030 if (!list_empty(&local->roc_list) || local->scanning)
3031 return -EBUSY;
3032
3033 if (sdata->wdev.cac_started)
3034 return -EBUSY;
3035
3036 if (cfg80211_chandef_identical(&params->chandef,
3037 &sdata->vif.bss_conf.chandef))
3038 return -EINVAL;
3039
3040 rcu_read_lock();
3041 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3042 if (!chanctx_conf) {
3043 rcu_read_unlock();
3044 return -EBUSY;
3045 }
3046
3047 /* don't handle for multi-VIF cases */
3048 chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
3049 if (chanctx->refcount > 1) {
3050 rcu_read_unlock();
3051 return -EBUSY;
3052 }
3053 num_chanctx = 0;
3054 list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
3055 num_chanctx++;
3056 rcu_read_unlock();
3057
3058 if (num_chanctx > 1)
3059 return -EBUSY;
3060
3061 /* don't allow another channel switch if one is already active. */
3062 if (sdata->vif.csa_active)
3063 return -EBUSY;
3064
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003065 switch (sdata->vif.type) {
3066 case NL80211_IFTYPE_AP:
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003067 sdata->csa_counter_offset_beacon =
3068 params->counter_offset_beacon;
3069 sdata->csa_counter_offset_presp = params->counter_offset_presp;
3070 sdata->u.ap.next_beacon =
3071 cfg80211_beacon_dup(&params->beacon_after);
3072 if (!sdata->u.ap.next_beacon)
3073 return -ENOMEM;
3074
3075 err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
3076 if (err < 0) {
3077 kfree(sdata->u.ap.next_beacon);
3078 return err;
3079 }
3080 break;
3081 case NL80211_IFTYPE_ADHOC:
3082 if (!sdata->vif.bss_conf.ibss_joined)
3083 return -EINVAL;
3084
3085 if (params->chandef.width != sdata->u.ibss.chandef.width)
3086 return -EINVAL;
3087
3088 switch (params->chandef.width) {
3089 case NL80211_CHAN_WIDTH_40:
3090 if (cfg80211_get_chandef_type(&params->chandef) !=
3091 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3092 return -EINVAL;
3093 case NL80211_CHAN_WIDTH_5:
3094 case NL80211_CHAN_WIDTH_10:
3095 case NL80211_CHAN_WIDTH_20_NOHT:
3096 case NL80211_CHAN_WIDTH_20:
3097 break;
3098 default:
3099 return -EINVAL;
3100 }
3101
3102 /* changes into another band are not supported */
3103 if (sdata->u.ibss.chandef.chan->band !=
3104 params->chandef.chan->band)
3105 return -EINVAL;
3106
3107 err = ieee80211_ibss_csa_beacon(sdata, params);
3108 if (err < 0)
3109 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003110 break;
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07003111#ifdef CONFIG_MAC80211_MESH
3112 case NL80211_IFTYPE_MESH_POINT:
3113 ifmsh = &sdata->u.mesh;
3114
3115 if (!ifmsh->mesh_id)
3116 return -EINVAL;
3117
3118 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3119 return -EINVAL;
3120
3121 /* changes into another band are not supported */
3122 if (sdata->vif.bss_conf.chandef.chan->band !=
3123 params->chandef.chan->band)
3124 return -EINVAL;
3125
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003126 err = ieee80211_mesh_csa_beacon(sdata, params, true);
Chun-Yeow Yeohc6da6742013-10-14 19:08:28 -07003127 if (err < 0)
3128 return err;
3129 break;
3130#endif
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003131 default:
3132 return -EOPNOTSUPP;
3133 }
3134
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003135 sdata->csa_radar_required = params->radar_required;
3136
3137 if (params->block_tx)
3138 ieee80211_stop_queues_by_reason(&local->hw,
3139 IEEE80211_MAX_QUEUE_MAP,
3140 IEEE80211_QUEUE_STOP_REASON_CSA);
3141
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003142 local->csa_chandef = params->chandef;
3143 sdata->vif.csa_active = true;
3144
3145 ieee80211_bss_info_change_notify(sdata, err);
3146 drv_channel_switch_beacon(sdata, &params->chandef);
3147
3148 return 0;
3149}
3150
Johannes Berg71bbc992012-06-15 15:30:18 +02003151static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003152 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01003153 unsigned int wait, const u8 *buf, size_t len,
3154 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003155{
Johannes Berg71bbc992012-06-15 15:30:18 +02003156 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003157 struct ieee80211_local *local = sdata->local;
3158 struct sk_buff *skb;
3159 struct sta_info *sta;
3160 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003161 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003162 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003163 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003164
Johannes Berge247bd902011-11-04 11:18:21 +01003165 if (dont_wait_for_ack)
3166 flags = IEEE80211_TX_CTL_NO_ACK;
3167 else
3168 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3169 IEEE80211_TX_CTL_REQ_TX_STATUS;
3170
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303171 if (no_cck)
3172 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3173
Johannes Berg9d38d852010-06-09 17:20:33 +02003174 switch (sdata->vif.type) {
3175 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003176 if (!sdata->vif.bss_conf.ibss_joined)
3177 need_offchan = true;
3178 /* fall through */
3179#ifdef CONFIG_MAC80211_MESH
3180 case NL80211_IFTYPE_MESH_POINT:
3181 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3182 !sdata->u.mesh.mesh_id_len)
3183 need_offchan = true;
3184 /* fall through */
3185#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003186 case NL80211_IFTYPE_AP:
3187 case NL80211_IFTYPE_AP_VLAN:
3188 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003189 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3190 !ieee80211_vif_is_mesh(&sdata->vif) &&
3191 !rcu_access_pointer(sdata->bss->beacon))
3192 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003193 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003194 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003195 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3196 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003197 break;
3198 rcu_read_lock();
3199 sta = sta_info_get(sdata, mgmt->da);
3200 rcu_read_unlock();
3201 if (!sta)
3202 return -ENOLINK;
3203 break;
3204 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003205 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003206 if (!sdata->u.mgd.associated)
3207 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003208 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003209 case NL80211_IFTYPE_P2P_DEVICE:
3210 need_offchan = true;
3211 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003212 default:
3213 return -EOPNOTSUPP;
3214 }
3215
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003216 /* configurations requiring offchan cannot work if no channel has been
3217 * specified
3218 */
3219 if (need_offchan && !chan)
3220 return -EINVAL;
3221
Johannes Berg2eb278e2012-06-05 14:28:42 +02003222 mutex_lock(&local->mtx);
3223
3224 /* Check if the operating channel is the requested channel */
3225 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003226 struct ieee80211_chanctx_conf *chanctx_conf;
3227
3228 rcu_read_lock();
3229 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3230
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003231 if (chanctx_conf) {
3232 need_offchan = chan && (chan != chanctx_conf->def.chan);
3233 } else if (!chan) {
3234 ret = -EINVAL;
3235 rcu_read_unlock();
3236 goto out_unlock;
3237 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003238 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003239 }
Johannes Berg55de9082012-07-26 17:24:39 +02003240 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003241 }
3242
3243 if (need_offchan && !offchan) {
3244 ret = -EBUSY;
3245 goto out_unlock;
3246 }
3247
Johannes Berg9d38d852010-06-09 17:20:33 +02003248 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003249 if (!skb) {
3250 ret = -ENOMEM;
3251 goto out_unlock;
3252 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003253 skb_reserve(skb, local->hw.extra_tx_headroom);
3254
3255 memcpy(skb_put(skb, len), buf, len);
3256
3257 IEEE80211_SKB_CB(skb)->flags = flags;
3258
Johannes Berg2eb278e2012-06-05 14:28:42 +02003259 skb->dev = sdata->dev;
3260
3261 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003262 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003263 ieee80211_tx_skb(sdata, skb);
3264 ret = 0;
3265 goto out_unlock;
3266 }
3267
Seth Forshee6c17b772013-02-11 11:21:07 -06003268 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3269 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003270 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003271 IEEE80211_SKB_CB(skb)->hw_queue =
3272 local->hw.offchannel_tx_hw_queue;
3273
Johannes Berg2eb278e2012-06-05 14:28:42 +02003274 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01003275 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003276 wait, cookie, skb,
3277 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003278 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003279 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003280 out_unlock:
3281 mutex_unlock(&local->mtx);
3282 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003283}
3284
Johannes Bergf30221e2010-11-25 10:02:30 +01003285static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003286 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003287 u64 cookie)
3288{
Johannes Berg71bbc992012-06-15 15:30:18 +02003289 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003290
Johannes Berg2eb278e2012-06-05 14:28:42 +02003291 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003292}
3293
Johannes Berg7be50862010-10-13 12:06:24 +02003294static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003295 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003296 u16 frame_type, bool reg)
3297{
3298 struct ieee80211_local *local = wiphy_priv(wiphy);
3299
Will Hawkins6abe0562012-06-20 11:51:14 -04003300 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003301 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3302 if (reg)
3303 local->probe_req_reg++;
3304 else
3305 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003306
Felix Fietkau35f51492012-10-31 15:50:34 +01003307 if (!local->open_count)
3308 break;
3309
Will Hawkins6abe0562012-06-20 11:51:14 -04003310 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3311 break;
3312 default:
3313 break;
3314 }
Johannes Berg7be50862010-10-13 12:06:24 +02003315}
3316
Bruno Randolf15d96752010-11-10 12:50:56 +09003317static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3318{
3319 struct ieee80211_local *local = wiphy_priv(wiphy);
3320
3321 if (local->started)
3322 return -EOPNOTSUPP;
3323
3324 return drv_set_antenna(local, tx_ant, rx_ant);
3325}
3326
3327static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3328{
3329 struct ieee80211_local *local = wiphy_priv(wiphy);
3330
3331 return drv_get_antenna(local, tx_ant, rx_ant);
3332}
3333
John W. Linville38c09152011-03-07 16:19:18 -05003334static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
3335{
3336 struct ieee80211_local *local = wiphy_priv(wiphy);
3337
3338 return drv_set_ringparam(local, tx, rx);
3339}
3340
3341static void ieee80211_get_ringparam(struct wiphy *wiphy,
3342 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
3343{
3344 struct ieee80211_local *local = wiphy_priv(wiphy);
3345
3346 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
3347}
3348
Johannes Bergc68f4b82011-07-05 16:35:41 +02003349static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3350 struct net_device *dev,
3351 struct cfg80211_gtk_rekey_data *data)
3352{
3353 struct ieee80211_local *local = wiphy_priv(wiphy);
3354 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3355
3356 if (!local->ops->set_rekey_data)
3357 return -EOPNOTSUPP;
3358
3359 drv_set_rekey_data(local, sdata, data);
3360
3361 return 0;
3362}
3363
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003364static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
3365{
3366 u8 *pos = (void *)skb_put(skb, 7);
3367
3368 *pos++ = WLAN_EID_EXT_CAPABILITY;
3369 *pos++ = 5; /* len */
3370 *pos++ = 0x0;
3371 *pos++ = 0x0;
3372 *pos++ = 0x0;
3373 *pos++ = 0x0;
3374 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
3375}
3376
3377static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
3378{
3379 struct ieee80211_local *local = sdata->local;
3380 u16 capab;
3381
3382 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003383 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003384 return capab;
3385
3386 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3387 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3388 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3389 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3390
3391 return capab;
3392}
3393
3394static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3395 u8 *peer, u8 *bssid)
3396{
3397 struct ieee80211_tdls_lnkie *lnkid;
3398
3399 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3400
3401 lnkid->ie_type = WLAN_EID_LINK_ID;
3402 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3403
3404 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3405 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3406 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3407}
3408
3409static int
3410ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3411 u8 *peer, u8 action_code, u8 dialog_token,
3412 u16 status_code, struct sk_buff *skb)
3413{
3414 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003415 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003416 struct ieee80211_tdls_data *tf;
3417
3418 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3419
3420 memcpy(tf->da, peer, ETH_ALEN);
3421 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3422 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3423 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3424
3425 switch (action_code) {
3426 case WLAN_TDLS_SETUP_REQUEST:
3427 tf->category = WLAN_CATEGORY_TDLS;
3428 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3429
3430 skb_put(skb, sizeof(tf->u.setup_req));
3431 tf->u.setup_req.dialog_token = dialog_token;
3432 tf->u.setup_req.capability =
3433 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3434
Johannes Berg55de9082012-07-26 17:24:39 +02003435 ieee80211_add_srates_ie(sdata, skb, false, band);
3436 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003437 ieee80211_tdls_add_ext_capab(skb);
3438 break;
3439 case WLAN_TDLS_SETUP_RESPONSE:
3440 tf->category = WLAN_CATEGORY_TDLS;
3441 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3442
3443 skb_put(skb, sizeof(tf->u.setup_resp));
3444 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3445 tf->u.setup_resp.dialog_token = dialog_token;
3446 tf->u.setup_resp.capability =
3447 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3448
Johannes Berg55de9082012-07-26 17:24:39 +02003449 ieee80211_add_srates_ie(sdata, skb, false, band);
3450 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003451 ieee80211_tdls_add_ext_capab(skb);
3452 break;
3453 case WLAN_TDLS_SETUP_CONFIRM:
3454 tf->category = WLAN_CATEGORY_TDLS;
3455 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3456
3457 skb_put(skb, sizeof(tf->u.setup_cfm));
3458 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3459 tf->u.setup_cfm.dialog_token = dialog_token;
3460 break;
3461 case WLAN_TDLS_TEARDOWN:
3462 tf->category = WLAN_CATEGORY_TDLS;
3463 tf->action_code = WLAN_TDLS_TEARDOWN;
3464
3465 skb_put(skb, sizeof(tf->u.teardown));
3466 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3467 break;
3468 case WLAN_TDLS_DISCOVERY_REQUEST:
3469 tf->category = WLAN_CATEGORY_TDLS;
3470 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3471
3472 skb_put(skb, sizeof(tf->u.discover_req));
3473 tf->u.discover_req.dialog_token = dialog_token;
3474 break;
3475 default:
3476 return -EINVAL;
3477 }
3478
3479 return 0;
3480}
3481
3482static int
3483ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3484 u8 *peer, u8 action_code, u8 dialog_token,
3485 u16 status_code, struct sk_buff *skb)
3486{
3487 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003488 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003489 struct ieee80211_mgmt *mgmt;
3490
3491 mgmt = (void *)skb_put(skb, 24);
3492 memset(mgmt, 0, 24);
3493 memcpy(mgmt->da, peer, ETH_ALEN);
3494 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3495 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3496
3497 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3498 IEEE80211_STYPE_ACTION);
3499
3500 switch (action_code) {
3501 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3502 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3503 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3504 mgmt->u.action.u.tdls_discover_resp.action_code =
3505 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3506 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3507 dialog_token;
3508 mgmt->u.action.u.tdls_discover_resp.capability =
3509 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3510
Johannes Berg55de9082012-07-26 17:24:39 +02003511 ieee80211_add_srates_ie(sdata, skb, false, band);
3512 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003513 ieee80211_tdls_add_ext_capab(skb);
3514 break;
3515 default:
3516 return -EINVAL;
3517 }
3518
3519 return 0;
3520}
3521
3522static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3523 u8 *peer, u8 action_code, u8 dialog_token,
3524 u16 status_code, const u8 *extra_ies,
3525 size_t extra_ies_len)
3526{
3527 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3528 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003529 struct sk_buff *skb = NULL;
3530 bool send_direct;
3531 int ret;
3532
3533 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3534 return -ENOTSUPP;
3535
3536 /* make sure we are in managed mode, and associated */
3537 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3538 !sdata->u.mgd.associated)
3539 return -EINVAL;
3540
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003541 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3542 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003543
3544 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3545 max(sizeof(struct ieee80211_mgmt),
3546 sizeof(struct ieee80211_tdls_data)) +
3547 50 + /* supported rates */
3548 7 + /* ext capab */
3549 extra_ies_len +
3550 sizeof(struct ieee80211_tdls_lnkie));
3551 if (!skb)
3552 return -ENOMEM;
3553
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003554 skb_reserve(skb, local->hw.extra_tx_headroom);
3555
3556 switch (action_code) {
3557 case WLAN_TDLS_SETUP_REQUEST:
3558 case WLAN_TDLS_SETUP_RESPONSE:
3559 case WLAN_TDLS_SETUP_CONFIRM:
3560 case WLAN_TDLS_TEARDOWN:
3561 case WLAN_TDLS_DISCOVERY_REQUEST:
3562 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3563 action_code, dialog_token,
3564 status_code, skb);
3565 send_direct = false;
3566 break;
3567 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3568 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3569 dialog_token, status_code,
3570 skb);
3571 send_direct = true;
3572 break;
3573 default:
3574 ret = -ENOTSUPP;
3575 break;
3576 }
3577
3578 if (ret < 0)
3579 goto fail;
3580
3581 if (extra_ies_len)
3582 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3583
3584 /* the TDLS link IE is always added last */
3585 switch (action_code) {
3586 case WLAN_TDLS_SETUP_REQUEST:
3587 case WLAN_TDLS_SETUP_CONFIRM:
3588 case WLAN_TDLS_TEARDOWN:
3589 case WLAN_TDLS_DISCOVERY_REQUEST:
3590 /* we are the initiator */
3591 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3592 sdata->u.mgd.bssid);
3593 break;
3594 case WLAN_TDLS_SETUP_RESPONSE:
3595 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3596 /* we are the responder */
3597 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3598 sdata->u.mgd.bssid);
3599 break;
3600 default:
3601 ret = -ENOTSUPP;
3602 goto fail;
3603 }
3604
3605 if (send_direct) {
3606 ieee80211_tx_skb(sdata, skb);
3607 return 0;
3608 }
3609
3610 /*
3611 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3612 * we should default to AC_VI.
3613 */
3614 switch (action_code) {
3615 case WLAN_TDLS_SETUP_REQUEST:
3616 case WLAN_TDLS_SETUP_RESPONSE:
3617 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3618 skb->priority = 2;
3619 break;
3620 default:
3621 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3622 skb->priority = 5;
3623 break;
3624 }
3625
3626 /* disable bottom halves when entering the Tx path */
3627 local_bh_disable();
3628 ret = ieee80211_subif_start_xmit(skb, dev);
3629 local_bh_enable();
3630
3631 return ret;
3632
3633fail:
3634 dev_kfree_skb(skb);
3635 return ret;
3636}
3637
3638static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3639 u8 *peer, enum nl80211_tdls_operation oper)
3640{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003641 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003642 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3643
3644 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3645 return -ENOTSUPP;
3646
3647 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3648 return -EINVAL;
3649
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003650 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003651
3652 switch (oper) {
3653 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003654 rcu_read_lock();
3655 sta = sta_info_get(sdata, peer);
3656 if (!sta) {
3657 rcu_read_unlock();
3658 return -ENOLINK;
3659 }
3660
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003661 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003662 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003663 break;
3664 case NL80211_TDLS_DISABLE_LINK:
3665 return sta_info_destroy_addr(sdata, peer);
3666 case NL80211_TDLS_TEARDOWN:
3667 case NL80211_TDLS_SETUP:
3668 case NL80211_TDLS_DISCOVERY_REQ:
3669 /* We don't support in-driver setup/teardown/discovery */
3670 return -ENOTSUPP;
3671 default:
3672 return -ENOTSUPP;
3673 }
3674
3675 return 0;
3676}
3677
Johannes Berg06500732011-11-04 11:18:16 +01003678static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3679 const u8 *peer, u64 *cookie)
3680{
3681 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3682 struct ieee80211_local *local = sdata->local;
3683 struct ieee80211_qos_hdr *nullfunc;
3684 struct sk_buff *skb;
3685 int size = sizeof(*nullfunc);
3686 __le16 fc;
3687 bool qos;
3688 struct ieee80211_tx_info *info;
3689 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003690 struct ieee80211_chanctx_conf *chanctx_conf;
3691 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003692
3693 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003694 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3695 if (WARN_ON(!chanctx_conf)) {
3696 rcu_read_unlock();
3697 return -EINVAL;
3698 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003699 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003700 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003701 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003702 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003703 } else {
3704 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003705 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003706 }
Johannes Berg06500732011-11-04 11:18:16 +01003707
3708 if (qos) {
3709 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3710 IEEE80211_STYPE_QOS_NULLFUNC |
3711 IEEE80211_FCTL_FROMDS);
3712 } else {
3713 size -= 2;
3714 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3715 IEEE80211_STYPE_NULLFUNC |
3716 IEEE80211_FCTL_FROMDS);
3717 }
3718
3719 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003720 if (!skb) {
3721 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003722 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003723 }
Johannes Berg06500732011-11-04 11:18:16 +01003724
3725 skb->dev = dev;
3726
3727 skb_reserve(skb, local->hw.extra_tx_headroom);
3728
3729 nullfunc = (void *) skb_put(skb, size);
3730 nullfunc->frame_control = fc;
3731 nullfunc->duration_id = 0;
3732 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3733 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3734 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3735 nullfunc->seq_ctrl = 0;
3736
3737 info = IEEE80211_SKB_CB(skb);
3738
3739 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3740 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3741
3742 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3743 skb->priority = 7;
3744 if (qos)
3745 nullfunc->qos_ctrl = cpu_to_le16(7);
3746
3747 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003748 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003749 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003750 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003751
3752 *cookie = (unsigned long) skb;
3753 return 0;
3754}
3755
Johannes Berg683b6d32012-11-08 21:25:48 +01003756static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3757 struct wireless_dev *wdev,
3758 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003759{
Johannes Berg55de9082012-07-26 17:24:39 +02003760 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003761 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003762 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003763 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003764
Johannes Berg55de9082012-07-26 17:24:39 +02003765 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003766 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3767 if (chanctx_conf) {
3768 *chandef = chanctx_conf->def;
3769 ret = 0;
3770 } else if (local->open_count > 0 &&
3771 local->open_count == local->monitors &&
3772 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3773 if (local->use_chanctx)
3774 *chandef = local->monitor_chandef;
3775 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003776 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003777 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003778 }
3779 rcu_read_unlock();
3780
Johannes Berg683b6d32012-11-08 21:25:48 +01003781 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003782}
3783
Johannes Berg6d525632012-04-04 15:05:25 +02003784#ifdef CONFIG_PM
3785static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3786{
3787 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3788}
3789#endif
3790
Jiri Bencf0706e82007-05-05 11:45:53 -07003791struct cfg80211_ops mac80211_config_ops = {
3792 .add_virtual_intf = ieee80211_add_iface,
3793 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003794 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003795 .start_p2p_device = ieee80211_start_p2p_device,
3796 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003797 .add_key = ieee80211_add_key,
3798 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003799 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003800 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003801 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003802 .start_ap = ieee80211_start_ap,
3803 .change_beacon = ieee80211_change_beacon,
3804 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003805 .add_station = ieee80211_add_station,
3806 .del_station = ieee80211_del_station,
3807 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003808 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003809 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003810 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003811#ifdef CONFIG_MAC80211_MESH
3812 .add_mpath = ieee80211_add_mpath,
3813 .del_mpath = ieee80211_del_mpath,
3814 .change_mpath = ieee80211_change_mpath,
3815 .get_mpath = ieee80211_get_mpath,
3816 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003817 .update_mesh_config = ieee80211_update_mesh_config,
3818 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003819 .join_mesh = ieee80211_join_mesh,
3820 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003821#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003822 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003823 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003824 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003825 .suspend = ieee80211_suspend,
3826 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003827 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003828 .sched_scan_start = ieee80211_sched_scan_start,
3829 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003830 .auth = ieee80211_auth,
3831 .assoc = ieee80211_assoc,
3832 .deauth = ieee80211_deauth,
3833 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003834 .join_ibss = ieee80211_join_ibss,
3835 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003836 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003837 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003838 .set_tx_power = ieee80211_set_tx_power,
3839 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003840 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003841 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003842 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003843 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003844 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003845 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003846 .remain_on_channel = ieee80211_remain_on_channel,
3847 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003848 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003849 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003850 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003851 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003852 .set_antenna = ieee80211_set_antenna,
3853 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003854 .set_ringparam = ieee80211_set_ringparam,
3855 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003856 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003857 .tdls_oper = ieee80211_tdls_oper,
3858 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003859 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003860 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003861#ifdef CONFIG_PM
3862 .set_wakeup = ieee80211_set_wakeup,
3863#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003864 .get_et_sset_count = ieee80211_get_et_sset_count,
3865 .get_et_stats = ieee80211_get_et_stats,
3866 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003867 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003868 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003869 .channel_switch = ieee80211_channel_switch,
Jiri Bencf0706e82007-05-05 11:45:53 -07003870};