blob: 64cf294c2b9680329f3925857305ca7843a6281b [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 Berg9607e6b662009-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;
398 sband = sta->local->hw.wiphy->bands[
399 ieee80211_get_sdata_band(sta->sdata)];
400 rinfo->legacy = sband->bitrates[rate->idx].bitrate;
401 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800402 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
403 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100404 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
405 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
406 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
407 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800408 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
409 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800410}
411
Saravana003e6762012-11-28 18:29:38 +0530412void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
413{
414 rinfo->flags = 0;
415
416 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
417 rinfo->flags |= RATE_INFO_FLAGS_MCS;
418 rinfo->mcs = sta->last_rx_rate_idx;
419 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
420 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
421 rinfo->nss = sta->last_rx_rate_vht_nss;
422 rinfo->mcs = sta->last_rx_rate_idx;
423 } else {
424 struct ieee80211_supported_band *sband;
425
426 sband = sta->local->hw.wiphy->bands[
427 ieee80211_get_sdata_band(sta->sdata)];
428 rinfo->legacy =
429 sband->bitrates[sta->last_rx_rate_idx].bitrate;
430 }
431
432 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
433 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
434 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
435 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
436 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
437 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
438 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
439 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
440 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
441 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
442}
443
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100444static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
445{
Johannes Bergd0709a62008-02-25 16:27:46 +0100446 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300447 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530448 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100449 u64 packets = 0;
Felix Fietkauef0621e2013-04-22 16:29:31 +0200450 int i, ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100451
Johannes Bergf5ea9122009-08-07 16:17:38 +0200452 sinfo->generation = sdata->local->sta_generation;
453
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100454 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100455 STATION_INFO_RX_BYTES64 |
456 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200457 STATION_INFO_RX_PACKETS |
458 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900459 STATION_INFO_TX_RETRIES |
460 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700461 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100462 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700463 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530464 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200465 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800466 STATION_INFO_STA_FLAGS |
467 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530468
469 do_posix_clock_monotonic_gettime(&uptime);
470 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100471
472 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100473 sinfo->tx_bytes = 0;
474 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
475 sinfo->tx_bytes += sta->tx_bytes[ac];
476 packets += sta->tx_packets[ac];
477 }
478 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100479 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200480 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900481 sinfo->tx_retries = sta->tx_retry_count;
482 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700483 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800484 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100485
John W. Linville19deffb2009-12-08 17:10:13 -0500486 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
487 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900488 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300489 if (!local->ops->get_rssi ||
490 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
491 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900492 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100493 }
Felix Fietkauef0621e2013-04-22 16:29:31 +0200494 if (sta->chains) {
495 sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
496 STATION_INFO_CHAIN_SIGNAL_AVG;
497
498 sinfo->chains = sta->chains;
499 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
500 sinfo->chain_signal[i] = sta->chain_signal_last[i];
501 sinfo->chain_signal_avg[i] =
502 (s8) -ewma_read(&sta->chain_signal_avg[i]);
503 }
504 }
Henning Rogge420e7fa2008-12-11 22:04:19 +0100505
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800506 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530507 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100508
Johannes Berg902acc72008-02-23 15:17:19 +0100509 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100510#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100511 sinfo->filled |= STATION_INFO_LLID |
512 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100513 STATION_INFO_PLINK_STATE |
514 STATION_INFO_LOCAL_PM |
515 STATION_INFO_PEER_PM |
516 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100517
518 sinfo->llid = le16_to_cpu(sta->llid);
519 sinfo->plid = le16_to_cpu(sta->plid);
520 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700521 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
522 sinfo->filled |= STATION_INFO_T_OFFSET;
523 sinfo->t_offset = sta->t_offset;
524 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100525 sinfo->local_pm = sta->local_pm;
526 sinfo->peer_pm = sta->peer_pm;
527 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100528#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100529 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700530
531 sinfo->bss_param.flags = 0;
532 if (sdata->vif.bss_conf.use_cts_prot)
533 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
534 if (sdata->vif.bss_conf.use_short_preamble)
535 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
536 if (sdata->vif.bss_conf.use_short_slot)
537 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
538 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
539 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200540
541 sinfo->sta_flags.set = 0;
542 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
543 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
544 BIT(NL80211_STA_FLAG_WME) |
545 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100546 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200547 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100548 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200549 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
550 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
551 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
552 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
553 if (test_sta_flag(sta, WLAN_STA_WME))
554 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
555 if (test_sta_flag(sta, WLAN_STA_MFP))
556 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
557 if (test_sta_flag(sta, WLAN_STA_AUTH))
558 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200559 if (test_sta_flag(sta, WLAN_STA_ASSOC))
560 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100561 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
562 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100563}
564
Ben Greearb1ab7922012-04-23 12:50:30 -0700565static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
566 "rx_packets", "rx_bytes", "wep_weak_iv_count",
567 "rx_duplicates", "rx_fragments", "rx_dropped",
568 "tx_packets", "tx_bytes", "tx_fragments",
569 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700570 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
571 "channel", "noise", "ch_time", "ch_time_busy",
572 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700573};
574#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
575
576static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
577 struct net_device *dev,
578 int sset)
579{
Ben Greeare3521142012-04-23 12:50:31 -0700580 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
581 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700582
Ben Greeare3521142012-04-23 12:50:31 -0700583 if (sset == ETH_SS_STATS)
584 rv += STA_STATS_LEN;
585
586 rv += drv_get_et_sset_count(sdata, sset);
587
588 if (rv == 0)
589 return -EOPNOTSUPP;
590 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700591}
592
593static void ieee80211_get_et_stats(struct wiphy *wiphy,
594 struct net_device *dev,
595 struct ethtool_stats *stats,
596 u64 *data)
597{
598 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200599 struct ieee80211_chanctx_conf *chanctx_conf;
600 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700601 struct sta_info *sta;
602 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700603 struct station_info sinfo;
604 struct survey_info survey;
605 int i, q;
606#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700607
608 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
609
610#define ADD_STA_STATS(sta) \
611 do { \
612 data[i++] += sta->rx_packets; \
613 data[i++] += sta->rx_bytes; \
614 data[i++] += sta->wep_weak_iv_count; \
615 data[i++] += sta->num_duplicates; \
616 data[i++] += sta->rx_fragments; \
617 data[i++] += sta->rx_dropped; \
618 \
Johannes Berg560d2682013-02-05 10:55:21 +0100619 data[i++] += sinfo.tx_packets; \
620 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700621 data[i++] += sta->tx_fragments; \
622 data[i++] += sta->tx_filtered_count; \
623 data[i++] += sta->tx_retry_failed; \
624 data[i++] += sta->tx_retry_count; \
625 data[i++] += sta->beacon_loss_count; \
626 } while (0)
627
628 /* For Managed stations, find the single station based on BSSID
629 * and use that. For interface types, iterate through all available
630 * stations and add stats for any station that is assigned to this
631 * network device.
632 */
633
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300634 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700635
636 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
637 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700638
639 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
640 goto do_survey;
641
Johannes Berg560d2682013-02-05 10:55:21 +0100642 sinfo.filled = 0;
643 sta_set_sinfo(sta, &sinfo);
644
Ben Greear3073a7c2012-04-23 12:50:32 -0700645 i = 0;
646 ADD_STA_STATS(sta);
647
648 data[i++] = sta->sta_state;
649
Ben Greear3073a7c2012-04-23 12:50:32 -0700650
Joe Perches52042672012-05-30 13:25:54 -0700651 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700652 data[i] = 100000 *
653 cfg80211_calculate_bitrate(&sinfo.txrate);
654 i++;
Joe Perches52042672012-05-30 13:25:54 -0700655 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700656 data[i] = 100000 *
657 cfg80211_calculate_bitrate(&sinfo.rxrate);
658 i++;
659
Joe Perches52042672012-05-30 13:25:54 -0700660 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700661 data[i] = (u8)sinfo.signal_avg;
662 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700663 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300664 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700665 /* Make sure this station belongs to the proper dev */
666 if (sta->sdata->dev != dev)
667 continue;
668
669 i = 0;
670 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700671 }
672 }
673
Ben Greear3073a7c2012-04-23 12:50:32 -0700674do_survey:
675 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
676 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200677 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700678
Johannes Berg55de9082012-07-26 17:24:39 +0200679 rcu_read_lock();
680 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
681 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100682 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200683 else
684 channel = NULL;
685 rcu_read_unlock();
686
687 if (channel) {
688 q = 0;
689 do {
690 survey.filled = 0;
691 if (drv_get_survey(local, q, &survey) != 0) {
692 survey.filled = 0;
693 break;
694 }
695 q++;
696 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700697 }
698
699 if (survey.filled)
700 data[i++] = survey.channel->center_freq;
701 else
702 data[i++] = 0;
703 if (survey.filled & SURVEY_INFO_NOISE_DBM)
704 data[i++] = (u8)survey.noise;
705 else
706 data[i++] = -1LL;
707 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
708 data[i++] = survey.channel_time;
709 else
710 data[i++] = -1LL;
711 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
712 data[i++] = survey.channel_time_busy;
713 else
714 data[i++] = -1LL;
715 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
716 data[i++] = survey.channel_time_ext_busy;
717 else
718 data[i++] = -1LL;
719 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
720 data[i++] = survey.channel_time_rx;
721 else
722 data[i++] = -1LL;
723 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
724 data[i++] = survey.channel_time_tx;
725 else
726 data[i++] = -1LL;
727
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300728 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700729
Ben Greear3073a7c2012-04-23 12:50:32 -0700730 if (WARN_ON(i != STA_STATS_LEN))
731 return;
732
Ben Greeare3521142012-04-23 12:50:31 -0700733 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700734}
735
736static void ieee80211_get_et_strings(struct wiphy *wiphy,
737 struct net_device *dev,
738 u32 sset, u8 *data)
739{
Ben Greeare3521142012-04-23 12:50:31 -0700740 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
741 int sz_sta_stats = 0;
742
Ben Greearb1ab7922012-04-23 12:50:30 -0700743 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700744 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Johannes Bergbd500af2013-05-06 21:09:46 +0200745 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700746 }
Ben Greeare3521142012-04-23 12:50:31 -0700747 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700748}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100749
750static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
751 int idx, u8 *mac, struct station_info *sinfo)
752{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100753 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300754 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100755 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100756 int ret = -ENOENT;
757
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300758 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100759
Johannes Berg3b53fde82009-11-16 12:00:37 +0100760 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100761 if (sta) {
762 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200763 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100764 sta_set_sinfo(sta, sinfo);
765 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100766
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300767 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100768
Johannes Bergd0709a62008-02-25 16:27:46 +0100769 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100770}
771
Holger Schurig12897232010-04-19 10:23:57 +0200772static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
773 int idx, struct survey_info *survey)
774{
775 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
776
Holger Schurig12897232010-04-19 10:23:57 +0200777 return drv_get_survey(local, idx, survey);
778}
779
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100780static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100781 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100782{
Johannes Bergabe60632009-11-25 17:46:18 +0100783 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300784 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100785 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100786 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100787
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300788 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100789
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100790 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100791 if (sta) {
792 ret = 0;
793 sta_set_sinfo(sta, sinfo);
794 }
795
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300796 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100797
798 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100799}
800
Johannes Berge8c9bd52012-06-06 08:18:22 +0200801static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100802 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200803{
Johannes Berg55de9082012-07-26 17:24:39 +0200804 struct ieee80211_local *local = wiphy_priv(wiphy);
805 struct ieee80211_sub_if_data *sdata;
806 int ret = 0;
807
Johannes Berg4bf88532012-11-09 11:39:59 +0100808 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200809 return 0;
810
811 mutex_lock(&local->iflist_mtx);
812 if (local->use_chanctx) {
813 sdata = rcu_dereference_protected(
814 local->monitor_sdata,
815 lockdep_is_held(&local->iflist_mtx));
816 if (sdata) {
817 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100818 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200819 IEEE80211_CHANCTX_EXCLUSIVE);
820 }
821 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100822 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200823 ieee80211_hw_config(local, 0);
824 }
825
Johannes Berg4bf88532012-11-09 11:39:59 +0100826 if (ret == 0)
827 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200828 mutex_unlock(&local->iflist_mtx);
829
830 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200831}
832
Arik Nemtsov02945822011-11-10 11:28:57 +0200833static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100834 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200835{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300836 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200837
838 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530839 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200840
Arik Nemtsovf7248282011-11-19 10:51:26 +0200841 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200842
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300843 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200844 if (!new)
845 return -ENOMEM;
846
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300847 new->len = resp_len;
848 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200849
850 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300851 if (old)
852 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200853
854 return 0;
855}
856
Johannes Berg88600202012-02-13 15:17:18 +0100857static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
858 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100859{
860 struct beacon_data *new, *old;
861 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100862 int size, err;
863 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100864
Johannes Berg40b275b2011-05-13 14:15:49 +0200865 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100866
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100867 /* Need to have a beacon head if we don't have one yet */
868 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100869 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100870
871 /* new or old head? */
872 if (params->head)
873 new_head_len = params->head_len;
874 else
875 new_head_len = old->head_len;
876
877 /* new or old tail? */
878 if (params->tail || !old)
879 /* params->tail_len will be zero for !params->tail */
880 new_tail_len = params->tail_len;
881 else
882 new_tail_len = old->tail_len;
883
884 size = sizeof(*new) + new_head_len + new_tail_len;
885
886 new = kzalloc(size, GFP_KERNEL);
887 if (!new)
888 return -ENOMEM;
889
890 /* start filling the new info now */
891
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100892 /*
893 * pointers go into the block we allocated,
894 * memory is | beacon_data | head | tail |
895 */
896 new->head = ((u8 *) new) + sizeof(*new);
897 new->tail = new->head + new_head_len;
898 new->head_len = new_head_len;
899 new->tail_len = new_tail_len;
900
901 /* copy in head */
902 if (params->head)
903 memcpy(new->head, params->head, new_head_len);
904 else
905 memcpy(new->head, old->head, new_head_len);
906
907 /* copy in optional tail */
908 if (params->tail)
909 memcpy(new->tail, params->tail, new_tail_len);
910 else
911 if (old)
912 memcpy(new->tail, old->tail, new_tail_len);
913
Johannes Berg88600202012-02-13 15:17:18 +0100914 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
915 params->probe_resp_len);
916 if (err < 0)
917 return err;
918 if (err == 0)
919 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100920
Eric Dumazetcf778b02012-01-12 04:41:32 +0000921 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100922
Johannes Berg88600202012-02-13 15:17:18 +0100923 if (old)
924 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100925
Johannes Berg88600202012-02-13 15:17:18 +0100926 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100927}
928
Johannes Berg88600202012-02-13 15:17:18 +0100929static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
930 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100931{
Johannes Berg88600202012-02-13 15:17:18 +0100932 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100933 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100934 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100935 u32 changed = BSS_CHANGED_BEACON_INT |
936 BSS_CHANGED_BEACON_ENABLED |
937 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100938 BSS_CHANGED_SSID |
939 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100940 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200941
Johannes Berg40b275b2011-05-13 14:15:49 +0200942 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100943 if (old)
944 return -EALREADY;
945
Johannes Berg04ecd252012-09-11 14:34:12 +0200946 /* TODO: make hostapd tell us what it wants */
947 sdata->smps_mode = IEEE80211_SMPS_OFF;
948 sdata->needed_rx_chains = sdata->local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +0100949 sdata->radar_required = params->radar_required;
Johannes Berg04ecd252012-09-11 14:34:12 +0200950
Johannes Berg4bf88532012-11-09 11:39:59 +0100951 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200952 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200953 if (err)
954 return err;
Johannes Berg1f4ac5a2013-02-08 12:07:44 +0100955 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Bergaa430da2012-05-16 23:50:18 +0200956
Johannes Berg665c93a2011-11-04 11:18:11 +0100957 /*
958 * Apply control port protocol, this allows us to
959 * not encrypt dynamic WEP control frames.
960 */
961 sdata->control_port_protocol = params->crypto.control_port_ethertype;
962 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
963 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
964 vlan->control_port_protocol =
965 params->crypto.control_port_ethertype;
966 vlan->control_port_no_encrypt =
967 params->crypto.control_port_no_encrypt;
968 }
969
Johannes Berg88600202012-02-13 15:17:18 +0100970 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
971 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100972 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100973
974 sdata->vif.bss_conf.ssid_len = params->ssid_len;
975 if (params->ssid_len)
976 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
977 params->ssid_len);
978 sdata->vif.bss_conf.hidden_ssid =
979 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
980
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100981 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
982 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
983 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
984 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
985 if (params->p2p_opp_ps)
986 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
987 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100988
Johannes Berg88600202012-02-13 15:17:18 +0100989 err = ieee80211_assign_beacon(sdata, &params->beacon);
990 if (err < 0)
991 return err;
992 changed |= err;
993
Johannes Berg10416382012-10-19 15:44:42 +0200994 err = drv_start_ap(sdata->local, sdata);
995 if (err) {
996 old = rtnl_dereference(sdata->u.ap.beacon);
997 if (old)
998 kfree_rcu(old, rcu_head);
999 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1000 return err;
1001 }
1002
Johannes Berg88600202012-02-13 15:17:18 +01001003 ieee80211_bss_info_change_notify(sdata, changed);
1004
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001005 netif_carrier_on(dev);
1006 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1007 netif_carrier_on(vlan->dev);
1008
Johannes Berg665c93a2011-11-04 11:18:11 +01001009 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001010}
1011
Johannes Berg88600202012-02-13 15:17:18 +01001012static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1013 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001014{
Johannes Berg14db74b2008-07-29 13:22:52 +02001015 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001016 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001017 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001018
Johannes Berg14db74b2008-07-29 13:22:52 +02001019 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1020
Johannes Berg40b275b2011-05-13 14:15:49 +02001021 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001022 if (!old)
1023 return -ENOENT;
1024
Johannes Berg88600202012-02-13 15:17:18 +01001025 err = ieee80211_assign_beacon(sdata, params);
1026 if (err < 0)
1027 return err;
1028 ieee80211_bss_info_change_notify(sdata, err);
1029 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001030}
1031
Johannes Berg88600202012-02-13 15:17:18 +01001032static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001033{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001034 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1035 struct ieee80211_sub_if_data *vlan;
1036 struct ieee80211_local *local = sdata->local;
1037 struct beacon_data *old_beacon;
1038 struct probe_resp *old_probe_resp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001039
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001040 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1041 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001042 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001043 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001044
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001045 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001046 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1047 netif_carrier_off(vlan->dev);
1048 netif_carrier_off(dev);
1049
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001050 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001051 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001052 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1053 kfree_rcu(old_beacon, rcu_head);
1054 if (old_probe_resp)
1055 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001056
Felix Fietkau2d4072a2012-12-10 20:02:34 +01001057 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
Johannes Berg75de9112012-12-14 14:56:03 +01001058 sta_info_flush_defer(vlan);
1059 sta_info_flush_defer(sdata);
Bob Copeland8ceb5952013-04-18 18:26:49 -04001060 synchronize_net();
Johannes Berg75de9112012-12-14 14:56:03 +01001061 rcu_barrier();
Johannes Berg7b4396b2013-02-23 01:14:20 +01001062 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
Johannes Berg75de9112012-12-14 14:56:03 +01001063 sta_info_flush_cleanup(vlan);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001064 ieee80211_free_keys(vlan);
1065 }
Johannes Berg75de9112012-12-14 14:56:03 +01001066 sta_info_flush_cleanup(sdata);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001067 ieee80211_free_keys(sdata);
Johannes Berg75de9112012-12-14 14:56:03 +01001068
Johannes Bergd6a83222012-12-14 14:06:28 +01001069 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001070 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001071 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001072 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001073
Johannes Berg10416382012-10-19 15:44:42 +02001074 drv_stop_ap(sdata->local, sdata);
1075
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001076 /* free all potentially still buffered bcast frames */
1077 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1078 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1079
Johannes Berg1f4ac5a2013-02-08 12:07:44 +01001080 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001081 ieee80211_vif_release_channel(sdata);
1082
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001083 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001084}
1085
Johannes Berg4fd69312007-12-19 02:03:35 +01001086/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1087struct iapp_layer2_update {
1088 u8 da[ETH_ALEN]; /* broadcast */
1089 u8 sa[ETH_ALEN]; /* STA addr */
1090 __be16 len; /* 6 */
1091 u8 dsap; /* 0 */
1092 u8 ssap; /* 0 */
1093 u8 control;
1094 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001095} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001096
1097static void ieee80211_send_layer2_update(struct sta_info *sta)
1098{
1099 struct iapp_layer2_update *msg;
1100 struct sk_buff *skb;
1101
1102 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1103 * bridge devices */
1104
1105 skb = dev_alloc_skb(sizeof(*msg));
1106 if (!skb)
1107 return;
1108 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1109
1110 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1111 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1112
Johannes Berge83e6542012-07-13 16:23:07 +02001113 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001114 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001115 msg->len = htons(6);
1116 msg->dsap = 0;
1117 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1118 msg->control = 0xaf; /* XID response lsb.1111F101.
1119 * F=0 (no poll command; unsolicited frame) */
1120 msg->xid_info[0] = 0x81; /* XID format identifier */
1121 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1122 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1123
Johannes Bergd0709a62008-02-25 16:27:46 +01001124 skb->dev = sta->sdata->dev;
1125 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001126 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001127 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001128}
1129
Johannes Bergd582cff2012-10-26 17:53:44 +02001130static int sta_apply_auth_flags(struct ieee80211_local *local,
1131 struct sta_info *sta,
1132 u32 mask, u32 set)
1133{
1134 int ret;
1135
1136 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1137 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1138 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1139 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1140 if (ret)
1141 return ret;
1142 }
1143
1144 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1145 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1146 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1147 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1148 if (ret)
1149 return ret;
1150 }
1151
1152 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1153 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1154 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1155 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1156 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1157 else
1158 ret = 0;
1159 if (ret)
1160 return ret;
1161 }
1162
1163 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1164 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1165 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1166 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1167 if (ret)
1168 return ret;
1169 }
1170
1171 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1172 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1173 test_sta_flag(sta, WLAN_STA_AUTH)) {
1174 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1175 if (ret)
1176 return ret;
1177 }
1178
1179 return 0;
1180}
1181
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001182static int sta_apply_parameters(struct ieee80211_local *local,
1183 struct sta_info *sta,
1184 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001185{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001186 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001187 u32 rates;
1188 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +01001189 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001190 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001191 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001192 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001193
Johannes Berg55de9082012-07-26 17:24:39 +02001194 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001195
Johannes Bergeccb8e82009-05-11 21:57:56 +03001196 mask = params->sta_flags_mask;
1197 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001198
Johannes Bergd582cff2012-10-26 17:53:44 +02001199 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1200 /*
1201 * In mesh mode, ASSOCIATED isn't part of the nl80211
1202 * API but must follow AUTHENTICATED for driver state.
1203 */
1204 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1205 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1206 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1207 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001208 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1209 /*
1210 * TDLS -- everything follows authorized, but
1211 * only becoming authorized is possible, not
1212 * going back
1213 */
1214 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1215 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1216 BIT(NL80211_STA_FLAG_ASSOCIATED);
1217 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1218 BIT(NL80211_STA_FLAG_ASSOCIATED);
1219 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001220 }
1221
Johannes Bergd582cff2012-10-26 17:53:44 +02001222 ret = sta_apply_auth_flags(local, sta, mask, set);
1223 if (ret)
1224 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001225
Johannes Bergeccb8e82009-05-11 21:57:56 +03001226 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001227 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001228 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1229 else
1230 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001231 }
1232
1233 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001234 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001235 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001236 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001237 } else {
1238 clear_sta_flag(sta, WLAN_STA_WME);
1239 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001240 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001241 }
1242
1243 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001244 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001245 set_sta_flag(sta, WLAN_STA_MFP);
1246 else
1247 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001248 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001249
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001250 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001251 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001252 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1253 else
1254 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001255 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001256
Johannes Berg3b9ce802011-09-27 20:56:12 +02001257 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1258 sta->sta.uapsd_queues = params->uapsd_queues;
1259 sta->sta.max_sp = params->max_sp;
1260 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001261
Johannes Berg73651ee2008-02-25 16:27:47 +01001262 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001263 * cfg80211 validates this (1-2007) and allows setting the AID
1264 * only when creating a new station entry
1265 */
1266 if (params->aid)
1267 sta->sta.aid = params->aid;
1268
1269 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001270 * Some of the following updates would be racy if called on an
1271 * existing station, via ieee80211_change_station(). However,
1272 * all such changes are rejected by cfg80211 except for updates
1273 * changing the supported rates on an existing but not yet used
1274 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001275 */
1276
Johannes Berg4fd69312007-12-19 02:03:35 +01001277 if (params->listen_interval >= 0)
1278 sta->listen_interval = params->listen_interval;
1279
1280 if (params->supported_rates) {
1281 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001282
Johannes Berg4fd69312007-12-19 02:03:35 +01001283 for (i = 0; i < params->supported_rates_len; i++) {
1284 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001285 for (j = 0; j < sband->n_bitrates; j++) {
1286 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001287 rates |= BIT(j);
1288 }
1289 }
Johannes Berg55de9082012-07-26 17:24:39 +02001290 sta->sta.supp_rates[band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001291 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001292
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001293 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001294 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001295 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001296
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001297 if (params->vht_capa)
1298 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001299 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001300
Javier Cardona9c3990a2011-05-03 16:57:11 -07001301 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001302#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001303 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001304
1305 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001306 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001307 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001308 if (sta->plink_state != NL80211_PLINK_ESTAB)
1309 changed = mesh_plink_inc_estab_count(
1310 sdata);
1311 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001312
1313 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001314 changed |= ieee80211_mps_set_sta_local_pm(sta,
1315 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001316 break;
1317 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001318 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001319 case NL80211_PLINK_OPN_SNT:
1320 case NL80211_PLINK_OPN_RCVD:
1321 case NL80211_PLINK_CNF_RCVD:
1322 case NL80211_PLINK_HOLDING:
1323 if (sta->plink_state == NL80211_PLINK_ESTAB)
1324 changed = mesh_plink_dec_estab_count(
1325 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001326 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001327
1328 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001329 changed |=
1330 ieee80211_mps_local_status_update(sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001331 break;
1332 default:
1333 /* nothing */
1334 break;
1335 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001336 }
1337
1338 switch (params->plink_action) {
1339 case NL80211_PLINK_ACTION_NO_ACTION:
1340 /* nothing */
1341 break;
1342 case NL80211_PLINK_ACTION_OPEN:
1343 changed |= mesh_plink_open(sta);
1344 break;
1345 case NL80211_PLINK_ACTION_BLOCK:
1346 changed |= mesh_plink_block(sta);
1347 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001348 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001349
1350 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001351 changed |=
1352 ieee80211_mps_set_sta_local_pm(sta,
1353 params->local_pm);
1354 ieee80211_bss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001355#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001356 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001357
1358 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001359}
1360
1361static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1362 u8 *mac, struct station_parameters *params)
1363{
Johannes Berg14db74b2008-07-29 13:22:52 +02001364 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001365 struct sta_info *sta;
1366 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001367 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001368 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001369
Johannes Berg4fd69312007-12-19 02:03:35 +01001370 if (params->vlan) {
1371 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1372
Johannes Berg05c914f2008-09-11 00:01:58 +02001373 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1374 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001375 return -EINVAL;
1376 } else
1377 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1378
Joe Perchesb203ca32012-05-08 18:56:52 +00001379 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001380 return -EINVAL;
1381
1382 if (is_multicast_ether_addr(mac))
1383 return -EINVAL;
1384
1385 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001386 if (!sta)
1387 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001388
Johannes Bergd582cff2012-10-26 17:53:44 +02001389 /*
1390 * defaults -- if userspace wants something else we'll
1391 * change it accordingly in sta_apply_parameters()
1392 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001393 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1394 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1395 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1396 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001397
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001398 err = sta_apply_parameters(local, sta, params);
1399 if (err) {
1400 sta_info_free(local, sta);
1401 return err;
1402 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001403
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001404 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001405 * for TDLS, rate control should be initialized only when
1406 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001407 */
1408 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1409 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001410
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001411 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1412 sdata->vif.type == NL80211_IFTYPE_AP;
1413
Johannes Berg34e89502010-02-03 13:59:58 +01001414 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001415 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001416 rcu_read_unlock();
1417 return err;
1418 }
1419
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001420 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001421 ieee80211_send_layer2_update(sta);
1422
1423 rcu_read_unlock();
1424
Johannes Berg4fd69312007-12-19 02:03:35 +01001425 return 0;
1426}
1427
1428static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1429 u8 *mac)
1430{
Johannes Berg14db74b2008-07-29 13:22:52 +02001431 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001432
Johannes Berg14db74b2008-07-29 13:22:52 +02001433 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1434
Johannes Berg34e89502010-02-03 13:59:58 +01001435 if (mac)
1436 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001437
Johannes Bergb998e8b2012-12-13 23:07:46 +01001438 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001439 return 0;
1440}
1441
1442static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001443 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001444 struct station_parameters *params)
1445{
Johannes Bergabe60632009-11-25 17:46:18 +01001446 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001447 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001448 struct sta_info *sta;
1449 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001450 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001451 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001452
Johannes Berg87be1e12011-12-14 12:20:29 +01001453 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001454
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001455 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001456 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001457 err = -ENOENT;
1458 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001459 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001460
Johannes Berg77ee7c82013-02-15 00:48:33 +01001461 switch (sdata->vif.type) {
1462 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001463 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001464 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001465 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001466 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001467 break;
1468 case NL80211_IFTYPE_ADHOC:
1469 statype = CFG80211_STA_IBSS;
1470 break;
1471 case NL80211_IFTYPE_STATION:
1472 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1473 statype = CFG80211_STA_AP_STA;
1474 break;
1475 }
1476 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1477 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1478 else
1479 statype = CFG80211_STA_TDLS_PEER_SETUP;
1480 break;
1481 case NL80211_IFTYPE_AP:
1482 case NL80211_IFTYPE_AP_VLAN:
1483 statype = CFG80211_STA_AP_CLIENT;
1484 break;
1485 default:
1486 err = -EOPNOTSUPP;
1487 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001488 }
1489
Johannes Berg77ee7c82013-02-15 00:48:33 +01001490 err = cfg80211_check_station_change(wiphy, params, statype);
1491 if (err)
1492 goto out_err;
1493
Johannes Bergd0709a62008-02-25 16:27:46 +01001494 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001495 bool prev_4addr = false;
1496 bool new_4addr = false;
1497
Johannes Berg4fd69312007-12-19 02:03:35 +01001498 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1499
Johannes Berg9bc383d2009-11-19 11:55:19 +01001500 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001501 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001502 err = -EBUSY;
1503 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001504 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001505
Eric Dumazetcf778b02012-01-12 04:41:32 +00001506 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001507 new_4addr = true;
1508 }
1509
1510 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1511 sta->sdata->u.vlan.sta) {
1512 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1513 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001514 }
1515
Johannes Berg14db74b2008-07-29 13:22:52 +02001516 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001517
1518 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1519 prev_4addr != new_4addr) {
1520 if (new_4addr)
1521 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1522 else
1523 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1524 }
1525
Johannes Berg4fd69312007-12-19 02:03:35 +01001526 ieee80211_send_layer2_update(sta);
1527 }
1528
Eliad Peller35b88622011-12-29 14:41:39 +02001529 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001530 if (err)
1531 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001532
Johannes Berg77ee7c82013-02-15 00:48:33 +01001533 /* When peer becomes authorized, init rate control as well */
1534 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1535 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001536 rate_control_rate_init(sta);
1537
Johannes Berg87be1e12011-12-14 12:20:29 +01001538 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001539
Jason Young808118c2011-03-10 16:43:19 -08001540 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001541 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001542 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001543 ieee80211_recalc_ps_vif(sdata);
1544 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001545
Johannes Berg4fd69312007-12-19 02:03:35 +01001546 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001547out_err:
1548 mutex_unlock(&local->sta_mtx);
1549 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001550}
1551
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001552#ifdef CONFIG_MAC80211_MESH
1553static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1554 u8 *dst, u8 *next_hop)
1555{
Johannes Berg14db74b2008-07-29 13:22:52 +02001556 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001557 struct mesh_path *mpath;
1558 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001559
Johannes Berg14db74b2008-07-29 13:22:52 +02001560 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1561
Johannes Bergd0709a62008-02-25 16:27:46 +01001562 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001563 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001564 if (!sta) {
1565 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001566 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001567 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001568
Bob Copelandae76eef2013-03-29 09:38:39 -04001569 mpath = mesh_path_add(sdata, dst);
1570 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001571 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001572 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001573 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001574
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001575 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001576
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001577 rcu_read_unlock();
1578 return 0;
1579}
1580
1581static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001582 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001583{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001584 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001585
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001586 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001587 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001588
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001589 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001590 return 0;
1591}
1592
1593static int ieee80211_change_mpath(struct wiphy *wiphy,
1594 struct net_device *dev,
1595 u8 *dst, u8 *next_hop)
1596{
Johannes Berg14db74b2008-07-29 13:22:52 +02001597 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001598 struct mesh_path *mpath;
1599 struct sta_info *sta;
1600
Johannes Berg14db74b2008-07-29 13:22:52 +02001601 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1602
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001603 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001604
Johannes Bergabe60632009-11-25 17:46:18 +01001605 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001606 if (!sta) {
1607 rcu_read_unlock();
1608 return -ENOENT;
1609 }
1610
Johannes Bergbf7cd942013-02-15 14:40:31 +01001611 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001612 if (!mpath) {
1613 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001614 return -ENOENT;
1615 }
1616
1617 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001618
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001619 rcu_read_unlock();
1620 return 0;
1621}
1622
1623static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1624 struct mpath_info *pinfo)
1625{
Johannes Berga3836e02011-05-12 15:11:37 +02001626 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1627
1628 if (next_hop_sta)
1629 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001630 else
1631 memset(next_hop, 0, ETH_ALEN);
1632
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001633 memset(pinfo, 0, sizeof(*pinfo));
1634
Johannes Bergf5ea9122009-08-07 16:17:38 +02001635 pinfo->generation = mesh_paths_generation;
1636
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001637 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001638 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001639 MPATH_INFO_METRIC |
1640 MPATH_INFO_EXPTIME |
1641 MPATH_INFO_DISCOVERY_TIMEOUT |
1642 MPATH_INFO_DISCOVERY_RETRIES |
1643 MPATH_INFO_FLAGS;
1644
1645 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001646 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001647 pinfo->metric = mpath->metric;
1648 if (time_before(jiffies, mpath->exp_time))
1649 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1650 pinfo->discovery_timeout =
1651 jiffies_to_msecs(mpath->discovery_timeout);
1652 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001653 if (mpath->flags & MESH_PATH_ACTIVE)
1654 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1655 if (mpath->flags & MESH_PATH_RESOLVING)
1656 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001657 if (mpath->flags & MESH_PATH_SN_VALID)
1658 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001659 if (mpath->flags & MESH_PATH_FIXED)
1660 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001661 if (mpath->flags & MESH_PATH_RESOLVED)
1662 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001663}
1664
1665static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1666 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1667
1668{
Johannes Berg14db74b2008-07-29 13:22:52 +02001669 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001670 struct mesh_path *mpath;
1671
Johannes Berg14db74b2008-07-29 13:22:52 +02001672 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1673
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001674 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001675 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001676 if (!mpath) {
1677 rcu_read_unlock();
1678 return -ENOENT;
1679 }
1680 memcpy(dst, mpath->dst, ETH_ALEN);
1681 mpath_set_pinfo(mpath, next_hop, pinfo);
1682 rcu_read_unlock();
1683 return 0;
1684}
1685
1686static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1687 int idx, u8 *dst, u8 *next_hop,
1688 struct mpath_info *pinfo)
1689{
Johannes Berg14db74b2008-07-29 13:22:52 +02001690 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001691 struct mesh_path *mpath;
1692
Johannes Berg14db74b2008-07-29 13:22:52 +02001693 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1694
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001695 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001696 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001697 if (!mpath) {
1698 rcu_read_unlock();
1699 return -ENOENT;
1700 }
1701 memcpy(dst, mpath->dst, ETH_ALEN);
1702 mpath_set_pinfo(mpath, next_hop, pinfo);
1703 rcu_read_unlock();
1704 return 0;
1705}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001706
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001707static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001708 struct net_device *dev,
1709 struct mesh_config *conf)
1710{
1711 struct ieee80211_sub_if_data *sdata;
1712 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1713
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001714 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1715 return 0;
1716}
1717
1718static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1719{
1720 return (mask >> (parm-1)) & 0x1;
1721}
1722
Javier Cardonac80d5452010-12-16 17:37:49 -08001723static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1724 const struct mesh_setup *setup)
1725{
1726 u8 *new_ie;
1727 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001728 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1729 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001730
Javier Cardona581a8b02011-04-07 15:08:27 -07001731 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001732 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001733 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001734
Javier Cardona581a8b02011-04-07 15:08:27 -07001735 if (setup->ie_len) {
1736 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001737 GFP_KERNEL);
1738 if (!new_ie)
1739 return -ENOMEM;
1740 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001741 ifmsh->ie_len = setup->ie_len;
1742 ifmsh->ie = new_ie;
1743 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001744
1745 /* now copy the rest of the setup parameters */
1746 ifmsh->mesh_id_len = setup->mesh_id_len;
1747 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001748 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001749 ifmsh->mesh_pp_id = setup->path_sel_proto;
1750 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001751 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001752 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001753 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1754 if (setup->is_authenticated)
1755 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1756 if (setup->is_secure)
1757 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001758
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001759 /* mcast rate setting in Mesh Node */
1760 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1761 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001762 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001763
Marco Porsch9bdbf042013-01-07 16:04:51 +01001764 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1765 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1766
Javier Cardonac80d5452010-12-16 17:37:49 -08001767 return 0;
1768}
1769
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001770static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001771 struct net_device *dev, u32 mask,
1772 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001773{
1774 struct mesh_config *conf;
1775 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001776 struct ieee80211_if_mesh *ifmsh;
1777
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001778 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001779 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001780
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001781 /* Set the config options which we are interested in setting */
1782 conf = &(sdata->u.mesh.mshcfg);
1783 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1784 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1785 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1786 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1787 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1788 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1789 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1790 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1791 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1792 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1793 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1794 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001795 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001796 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001797 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1798 if (ifmsh->user_mpm)
1799 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001800 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001801 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001802 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1803 conf->dot11MeshNbrOffsetMaxNeighbor =
1804 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001805 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1806 conf->dot11MeshHWMPmaxPREQretries =
1807 nconf->dot11MeshHWMPmaxPREQretries;
1808 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1809 conf->path_refresh_time = nconf->path_refresh_time;
1810 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1811 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1812 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1813 conf->dot11MeshHWMPactivePathTimeout =
1814 nconf->dot11MeshHWMPactivePathTimeout;
1815 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1816 conf->dot11MeshHWMPpreqMinInterval =
1817 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001818 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1819 conf->dot11MeshHWMPperrMinInterval =
1820 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001821 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1822 mask))
1823 conf->dot11MeshHWMPnetDiameterTraversalTime =
1824 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001825 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1826 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1827 ieee80211_mesh_root_setup(ifmsh);
1828 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001829 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001830 /* our current gate announcement implementation rides on root
1831 * announcements, so require this ifmsh to also be a root node
1832 * */
1833 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001834 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1835 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001836 ieee80211_mesh_root_setup(ifmsh);
1837 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001838 conf->dot11MeshGateAnnouncementProtocol =
1839 nconf->dot11MeshGateAnnouncementProtocol;
1840 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001841 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001842 conf->dot11MeshHWMPRannInterval =
1843 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001844 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1845 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001846 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1847 /* our RSSI threshold implementation is supported only for
1848 * devices that report signal in dBm.
1849 */
1850 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1851 return -ENOTSUPP;
1852 conf->rssi_threshold = nconf->rssi_threshold;
1853 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001854 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1855 conf->ht_opmode = nconf->ht_opmode;
1856 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1857 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1858 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001859 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1860 conf->dot11MeshHWMPactivePathToRootTimeout =
1861 nconf->dot11MeshHWMPactivePathToRootTimeout;
1862 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1863 conf->dot11MeshHWMProotInterval =
1864 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001865 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1866 conf->dot11MeshHWMPconfirmationInterval =
1867 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001868 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1869 conf->power_mode = nconf->power_mode;
1870 ieee80211_mps_local_status_update(sdata);
1871 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001872 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001873 conf->dot11MeshAwakeWindowDuration =
1874 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001875 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1876 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001877 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001878 return 0;
1879}
1880
Johannes Berg29cbe682010-12-03 09:20:44 +01001881static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1882 const struct mesh_config *conf,
1883 const struct mesh_setup *setup)
1884{
1885 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1886 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001887 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001888
Javier Cardonac80d5452010-12-16 17:37:49 -08001889 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1890 err = copy_mesh_setup(ifmsh, setup);
1891 if (err)
1892 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001893
Johannes Berg04ecd252012-09-11 14:34:12 +02001894 /* can mesh use other SMPS modes? */
1895 sdata->smps_mode = IEEE80211_SMPS_OFF;
1896 sdata->needed_rx_chains = sdata->local->rx_chains;
1897
Johannes Berg4bf88532012-11-09 11:39:59 +01001898 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001899 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001900 if (err)
1901 return err;
1902
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001903 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001904}
1905
1906static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1907{
1908 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1909
1910 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001911 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001912
1913 return 0;
1914}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001915#endif
1916
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001917static int ieee80211_change_bss(struct wiphy *wiphy,
1918 struct net_device *dev,
1919 struct bss_parameters *params)
1920{
Johannes Berg55de9082012-07-26 17:24:39 +02001921 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1922 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001923 u32 changed = 0;
1924
Johannes Berg55de9082012-07-26 17:24:39 +02001925 if (!rtnl_dereference(sdata->u.ap.beacon))
1926 return -ENOENT;
1927
1928 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001929
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001930 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001931 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001932 changed |= BSS_CHANGED_ERP_CTS_PROT;
1933 }
1934 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001935 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001936 params->use_short_preamble;
1937 changed |= BSS_CHANGED_ERP_PREAMBLE;
1938 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001939
1940 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001941 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001942 sdata->vif.bss_conf.use_short_slot = true;
1943 changed |= BSS_CHANGED_ERP_SLOT;
1944 }
1945
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001946 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001947 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001948 params->use_short_slot_time;
1949 changed |= BSS_CHANGED_ERP_SLOT;
1950 }
1951
Jouni Malinen90c97a02008-10-30 16:59:22 +02001952 if (params->basic_rates) {
1953 int i, j;
1954 u32 rates = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02001955 struct ieee80211_supported_band *sband = wiphy->bands[band];
Jouni Malinen90c97a02008-10-30 16:59:22 +02001956
1957 for (i = 0; i < params->basic_rates_len; i++) {
1958 int rate = (params->basic_rates[i] & 0x7f) * 5;
1959 for (j = 0; j < sband->n_bitrates; j++) {
1960 if (sband->bitrates[j].bitrate == rate)
1961 rates |= BIT(j);
1962 }
1963 }
1964 sdata->vif.bss_conf.basic_rates = rates;
1965 changed |= BSS_CHANGED_BASIC_RATES;
1966 }
1967
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001968 if (params->ap_isolate >= 0) {
1969 if (params->ap_isolate)
1970 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1971 else
1972 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1973 }
1974
Helmut Schaa80d7e402010-11-19 12:40:26 +01001975 if (params->ht_opmode >= 0) {
1976 sdata->vif.bss_conf.ht_operation_mode =
1977 (u16) params->ht_opmode;
1978 changed |= BSS_CHANGED_HT;
1979 }
1980
Johannes Berg339afbf2012-11-14 15:21:17 +01001981 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001982 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1983 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1984 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1985 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001986 changed |= BSS_CHANGED_P2P_PS;
1987 }
1988
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001989 if (params->p2p_opp_ps > 0) {
1990 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1991 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1992 changed |= BSS_CHANGED_P2P_PS;
1993 } else if (params->p2p_opp_ps == 0) {
1994 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1995 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001996 changed |= BSS_CHANGED_P2P_PS;
1997 }
1998
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001999 ieee80211_bss_info_change_notify(sdata, changed);
2000
2001 return 0;
2002}
2003
Jouni Malinen31888482008-10-30 16:59:24 +02002004static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002005 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002006 struct ieee80211_txq_params *params)
2007{
2008 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002009 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002010 struct ieee80211_tx_queue_params p;
2011
2012 if (!local->ops->conf_tx)
2013 return -EOPNOTSUPP;
2014
Johannes Berg54bcbc62012-03-28 11:04:25 +02002015 if (local->hw.queues < IEEE80211_NUM_ACS)
2016 return -EOPNOTSUPP;
2017
Jouni Malinen31888482008-10-30 16:59:24 +02002018 memset(&p, 0, sizeof(p));
2019 p.aifs = params->aifs;
2020 p.cw_max = params->cwmax;
2021 p.cw_min = params->cwmin;
2022 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002023
2024 /*
2025 * Setting tx queue params disables u-apsd because it's only
2026 * called in master mode.
2027 */
2028 p.uapsd = false;
2029
Johannes Berga3304b02012-03-28 11:04:24 +02002030 sdata->tx_conf[params->ac] = p;
2031 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002032 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002033 "failed to set TX queue parameters for AC %d\n",
2034 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002035 return -EINVAL;
2036 }
2037
Johannes Berg7d257452012-07-06 17:37:43 +02002038 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2039
Jouni Malinen31888482008-10-30 16:59:24 +02002040 return 0;
2041}
2042
Bob Copeland665af4f2009-01-19 11:20:53 -05002043#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002044static int ieee80211_suspend(struct wiphy *wiphy,
2045 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002046{
Johannes Bergeecc4802011-05-04 15:37:29 +02002047 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002048}
2049
2050static int ieee80211_resume(struct wiphy *wiphy)
2051{
2052 return __ieee80211_resume(wiphy_priv(wiphy));
2053}
2054#else
2055#define ieee80211_suspend NULL
2056#define ieee80211_resume NULL
2057#endif
2058
Johannes Berg2a519312009-02-10 21:25:55 +01002059static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002060 struct cfg80211_scan_request *req)
2061{
Johannes Bergfd014282012-06-18 19:17:03 +02002062 struct ieee80211_sub_if_data *sdata;
2063
2064 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002065
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002066 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2067 case NL80211_IFTYPE_STATION:
2068 case NL80211_IFTYPE_ADHOC:
2069 case NL80211_IFTYPE_MESH_POINT:
2070 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002071 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002072 break;
2073 case NL80211_IFTYPE_P2P_GO:
2074 if (sdata->local->ops->hw_scan)
2075 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002076 /*
2077 * FIXME: implement NoA while scanning in software,
2078 * for now fall through to allow scanning only when
2079 * beaconing hasn't been configured yet
2080 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002081 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002082 /*
2083 * If the scan has been forced (and the driver supports
2084 * forcing), don't care about being beaconing already.
2085 * This will create problems to the attached stations (e.g. all
2086 * the frames sent while scanning on other channel will be
2087 * lost)
2088 */
2089 if (sdata->u.ap.beacon &&
2090 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2091 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002092 return -EOPNOTSUPP;
2093 break;
2094 default:
2095 return -EOPNOTSUPP;
2096 }
Johannes Berg2a519312009-02-10 21:25:55 +01002097
2098 return ieee80211_request_scan(sdata, req);
2099}
2100
Luciano Coelho79f460c2011-05-11 17:09:36 +03002101static int
2102ieee80211_sched_scan_start(struct wiphy *wiphy,
2103 struct net_device *dev,
2104 struct cfg80211_sched_scan_request *req)
2105{
2106 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2107
2108 if (!sdata->local->ops->sched_scan_start)
2109 return -EOPNOTSUPP;
2110
2111 return ieee80211_request_sched_scan_start(sdata, req);
2112}
2113
2114static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002115ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002116{
2117 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2118
2119 if (!sdata->local->ops->sched_scan_stop)
2120 return -EOPNOTSUPP;
2121
Luciano Coelho85a99942011-05-12 16:28:29 +03002122 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002123}
2124
Jouni Malinen636a5d32009-03-19 13:39:22 +02002125static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2126 struct cfg80211_auth_request *req)
2127{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002128 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002129}
2130
2131static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2132 struct cfg80211_assoc_request *req)
2133{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002134 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002135}
2136
2137static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002138 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002139{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002140 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002141}
2142
2143static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002144 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002145{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002146 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002147}
2148
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002149static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2150 struct cfg80211_ibss_params *params)
2151{
Johannes Berg55de9082012-07-26 17:24:39 +02002152 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002153}
2154
2155static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2156{
Johannes Berg55de9082012-07-26 17:24:39 +02002157 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002158}
2159
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002160static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2161 int rate[IEEE80211_NUM_BANDS])
2162{
2163 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2164
Cong Ding9887dbf2013-02-06 17:23:45 +01002165 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2166 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002167
2168 return 0;
2169}
2170
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002171static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2172{
2173 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002174 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002175
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002176 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2177 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2178
2179 if (err)
2180 return err;
2181 }
2182
Lukáš Turek310bc672009-12-21 22:50:48 +01002183 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2184 err = drv_set_coverage_class(local, wiphy->coverage_class);
2185
2186 if (err)
2187 return err;
2188 }
2189
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002190 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002191 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002192
Johannes Berg24487982009-04-23 18:52:52 +02002193 if (err)
2194 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002195 }
2196
Johannes Berg8bc83c22012-11-09 18:38:32 +01002197 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2198 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2199 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002200 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002201 }
2202 if (changed & WIPHY_PARAM_RETRY_LONG) {
2203 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2204 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002205 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002206 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002207 if (changed &
2208 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2209 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2210
2211 return 0;
2212}
2213
Johannes Berg7643a2c2009-06-02 13:01:39 +02002214static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002215 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002216 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002217{
2218 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002219 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002220
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002221 if (wdev) {
2222 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2223
2224 switch (type) {
2225 case NL80211_TX_POWER_AUTOMATIC:
2226 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2227 break;
2228 case NL80211_TX_POWER_LIMITED:
2229 case NL80211_TX_POWER_FIXED:
2230 if (mbm < 0 || (mbm % 100))
2231 return -EOPNOTSUPP;
2232 sdata->user_power_level = MBM_TO_DBM(mbm);
2233 break;
2234 }
2235
2236 ieee80211_recalc_txpower(sdata);
2237
2238 return 0;
2239 }
Johannes Berg55de9082012-07-26 17:24:39 +02002240
Johannes Berg7643a2c2009-06-02 13:01:39 +02002241 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002242 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002243 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002244 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002245 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002246 case NL80211_TX_POWER_FIXED:
2247 if (mbm < 0 || (mbm % 100))
2248 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002249 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002250 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002251 }
2252
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002253 mutex_lock(&local->iflist_mtx);
2254 list_for_each_entry(sdata, &local->interfaces, list)
2255 sdata->user_power_level = local->user_power_level;
2256 list_for_each_entry(sdata, &local->interfaces, list)
2257 ieee80211_recalc_txpower(sdata);
2258 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002259
2260 return 0;
2261}
2262
Johannes Bergc8442112012-10-24 10:17:18 +02002263static int ieee80211_get_tx_power(struct wiphy *wiphy,
2264 struct wireless_dev *wdev,
2265 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002266{
2267 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002268 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002269
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002270 if (!local->use_chanctx)
2271 *dbm = local->hw.conf.power_level;
2272 else
2273 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002274
Johannes Berg7643a2c2009-06-02 13:01:39 +02002275 return 0;
2276}
2277
Johannes Bergab737a42009-07-01 21:26:58 +02002278static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002279 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002280{
2281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2282
2283 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2284
2285 return 0;
2286}
2287
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002288static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2289{
2290 struct ieee80211_local *local = wiphy_priv(wiphy);
2291
2292 drv_rfkill_poll(local);
2293}
2294
Johannes Bergaff89a92009-07-01 21:26:51 +02002295#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002296static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002297{
2298 struct ieee80211_local *local = wiphy_priv(wiphy);
2299
2300 if (!local->ops->testmode_cmd)
2301 return -EOPNOTSUPP;
2302
2303 return local->ops->testmode_cmd(&local->hw, data, len);
2304}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002305
2306static int ieee80211_testmode_dump(struct wiphy *wiphy,
2307 struct sk_buff *skb,
2308 struct netlink_callback *cb,
2309 void *data, int len)
2310{
2311 struct ieee80211_local *local = wiphy_priv(wiphy);
2312
2313 if (!local->ops->testmode_dump)
2314 return -EOPNOTSUPP;
2315
2316 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2317}
Johannes Bergaff89a92009-07-01 21:26:51 +02002318#endif
2319
Johannes Berg0f782312009-12-01 13:37:02 +01002320int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2321 enum ieee80211_smps_mode smps_mode)
2322{
2323 const u8 *ap;
2324 enum ieee80211_smps_mode old_req;
2325 int err;
2326
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002327 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002328
Johannes Berg0f782312009-12-01 13:37:02 +01002329 old_req = sdata->u.mgd.req_smps;
2330 sdata->u.mgd.req_smps = smps_mode;
2331
2332 if (old_req == smps_mode &&
2333 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2334 return 0;
2335
2336 /*
2337 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002338 * association, there's no need to do anything, just store
2339 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002340 */
2341 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002342 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002343 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002344
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002345 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002346
2347 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2348 if (sdata->u.mgd.powersave)
2349 smps_mode = IEEE80211_SMPS_DYNAMIC;
2350 else
2351 smps_mode = IEEE80211_SMPS_OFF;
2352 }
2353
2354 /* send SM PS frame to AP */
2355 err = ieee80211_send_smps_action(sdata, smps_mode,
2356 ap, ap);
2357 if (err)
2358 sdata->u.mgd.req_smps = old_req;
2359
2360 return err;
2361}
2362
Johannes Bergbc92afd2009-07-01 21:26:57 +02002363static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2364 bool enabled, int timeout)
2365{
2366 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2367 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002368
Chun-Yeow Yeohee1f6682013-01-10 23:31:54 +08002369 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2370 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002371 return -EOPNOTSUPP;
2372
Johannes Bergbc92afd2009-07-01 21:26:57 +02002373 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2374 return -EOPNOTSUPP;
2375
2376 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002377 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002378 return 0;
2379
2380 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002381 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002382
Johannes Berg0f782312009-12-01 13:37:02 +01002383 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002384 sdata_lock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002385 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002386 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002387
Johannes Bergbc92afd2009-07-01 21:26:57 +02002388 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2389 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2390
2391 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002392 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002393
2394 return 0;
2395}
2396
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002397static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2398 struct net_device *dev,
2399 s32 rssi_thold, u32 rssi_hyst)
2400{
2401 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002402 struct ieee80211_vif *vif = &sdata->vif;
2403 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2404
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002405 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2406 rssi_hyst == bss_conf->cqm_rssi_hyst)
2407 return 0;
2408
2409 bss_conf->cqm_rssi_thold = rssi_thold;
2410 bss_conf->cqm_rssi_hyst = rssi_hyst;
2411
2412 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002413 if (sdata->u.mgd.associated &&
2414 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002415 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2416
2417 return 0;
2418}
2419
Johannes Berg99303802009-07-01 21:26:59 +02002420static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2421 struct net_device *dev,
2422 const u8 *addr,
2423 const struct cfg80211_bitrate_mask *mask)
2424{
2425 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2426 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302427 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002428
Eliad Peller554a43d2012-06-12 12:41:15 +03002429 if (!ieee80211_sdata_running(sdata))
2430 return -ENETDOWN;
2431
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302432 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2433 ret = drv_set_bitrate_mask(local, sdata, mask);
2434 if (ret)
2435 return ret;
2436 }
Johannes Berg99303802009-07-01 21:26:59 +02002437
Simon Wunderlich19468412012-01-28 17:25:33 +01002438 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002439 struct ieee80211_supported_band *sband = wiphy->bands[i];
2440 int j;
2441
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002442 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002443 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2444 sizeof(mask->control[i].mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002445
2446 sdata->rc_has_mcs_mask[i] = false;
2447 if (!sband)
2448 continue;
2449
2450 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2451 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2452 sdata->rc_has_mcs_mask[i] = true;
2453 break;
2454 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002455 }
Johannes Berg99303802009-07-01 21:26:59 +02002456
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002457 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002458}
2459
Johannes Berg2eb278e2012-06-05 14:28:42 +02002460static int ieee80211_start_roc_work(struct ieee80211_local *local,
2461 struct ieee80211_sub_if_data *sdata,
2462 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002463 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002464 struct sk_buff *txskb,
2465 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002466{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002467 struct ieee80211_roc_work *roc, *tmp;
2468 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002469 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002470
2471 lockdep_assert_held(&local->mtx);
2472
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002473 if (local->use_chanctx && !local->ops->remain_on_channel)
2474 return -EOPNOTSUPP;
2475
Johannes Berg2eb278e2012-06-05 14:28:42 +02002476 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2477 if (!roc)
2478 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002479
Johannes Berg2eb278e2012-06-05 14:28:42 +02002480 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002481 roc->duration = duration;
2482 roc->req_duration = duration;
2483 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002484 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002485 roc->mgmt_tx_cookie = (unsigned long)txskb;
2486 roc->sdata = sdata;
2487 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2488 INIT_LIST_HEAD(&roc->dependents);
2489
2490 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002491 if (!list_empty(&local->roc_list) ||
2492 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002493 goto out_check_combine;
2494
2495 /* if not HW assist, just queue & schedule work */
2496 if (!local->ops->remain_on_channel) {
2497 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2498 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002499 }
2500
Johannes Berg2eb278e2012-06-05 14:28:42 +02002501 /* otherwise actually kick it off here (for error handling) */
2502
2503 /*
2504 * If the duration is zero, then the driver
2505 * wouldn't actually do anything. Set it to
2506 * 10 for now.
2507 *
2508 * TODO: cancel the off-channel operation
2509 * when we get the SKB's TX status and
2510 * the wait time was zero before.
2511 */
2512 if (!duration)
2513 duration = 10;
2514
Ilan Peerd339d5c2013-02-12 09:34:13 +02002515 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002516 if (ret) {
2517 kfree(roc);
2518 return ret;
2519 }
2520
2521 roc->started = true;
2522 goto out_queue;
2523
2524 out_check_combine:
2525 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002526 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002527 continue;
2528
2529 /*
2530 * Extend this ROC if possible:
2531 *
2532 * If it hasn't started yet, just increase the duration
2533 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002534 * If the type of the new ROC has higher priority, modify the
2535 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002536 */
2537 if (!tmp->started) {
2538 list_add_tail(&roc->list, &tmp->dependents);
2539 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002540 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002541 queued = true;
2542 break;
2543 }
2544
2545 /* If it has already started, it's more difficult ... */
2546 if (local->ops->remain_on_channel) {
2547 unsigned long j = jiffies;
2548
2549 /*
2550 * In the offloaded ROC case, if it hasn't begun, add
2551 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002552 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002553 * check that there's still a minimum time left and
2554 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002555 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002556 * a reduced time so we'll ask the driver to execute
2557 * it right after finishing the previous one, in the
2558 * hope that it'll also be executed right afterwards,
2559 * effectively extending the old one.
2560 * If there's no minimum time left, just add it to the
2561 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002562 * TODO: the ROC type is ignored here, assuming that it
2563 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002564 */
2565 if (!tmp->hw_begun) {
2566 list_add_tail(&roc->list, &tmp->dependents);
2567 queued = true;
2568 break;
2569 }
2570
2571 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2572 tmp->hw_start_time +
2573 msecs_to_jiffies(tmp->duration))) {
2574 int new_dur;
2575
2576 ieee80211_handle_roc_started(roc);
2577
2578 new_dur = roc->duration -
2579 jiffies_to_msecs(tmp->hw_start_time +
2580 msecs_to_jiffies(
2581 tmp->duration) -
2582 j);
2583
2584 if (new_dur > 0) {
2585 /* add right after tmp */
2586 list_add(&roc->list, &tmp->list);
2587 } else {
2588 list_add_tail(&roc->list,
2589 &tmp->dependents);
2590 }
2591 queued = true;
2592 }
2593 } else if (del_timer_sync(&tmp->work.timer)) {
2594 unsigned long new_end;
2595
2596 /*
2597 * In the software ROC case, cancel the timer, if
2598 * that fails then the finish work is already
2599 * queued/pending and thus we queue the new ROC
2600 * normally, if that succeeds then we can extend
2601 * the timer duration and TX the frame (if any.)
2602 */
2603
2604 list_add_tail(&roc->list, &tmp->dependents);
2605 queued = true;
2606
2607 new_end = jiffies + msecs_to_jiffies(roc->duration);
2608
2609 /* ok, it was started & we canceled timer */
2610 if (time_after(new_end, tmp->work.timer.expires))
2611 mod_timer(&tmp->work.timer, new_end);
2612 else
2613 add_timer(&tmp->work.timer);
2614
2615 ieee80211_handle_roc_started(roc);
2616 }
2617 break;
2618 }
2619
2620 out_queue:
2621 if (!queued)
2622 list_add_tail(&roc->list, &local->roc_list);
2623
2624 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002625 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002626 * or the SKB (for mgmt TX)
2627 */
Johannes Berg50febf62012-10-26 16:13:06 +02002628 if (!txskb) {
2629 /* local->mtx protects this */
2630 local->roc_cookie_counter++;
2631 roc->cookie = local->roc_cookie_counter;
2632 /* wow, you wrapped 64 bits ... more likely a bug */
2633 if (WARN_ON(roc->cookie == 0)) {
2634 roc->cookie = 1;
2635 local->roc_cookie_counter++;
2636 }
2637 *cookie = roc->cookie;
2638 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002639 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002640 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002641
2642 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002643}
2644
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002645static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002646 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002647 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002648 unsigned int duration,
2649 u64 *cookie)
2650{
Johannes Berg71bbc992012-06-15 15:30:18 +02002651 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002652 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002653 int ret;
2654
Johannes Berg2eb278e2012-06-05 14:28:42 +02002655 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002656 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002657 duration, cookie, NULL,
2658 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002659 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002660
Johannes Berg2eb278e2012-06-05 14:28:42 +02002661 return ret;
2662}
2663
2664static int ieee80211_cancel_roc(struct ieee80211_local *local,
2665 u64 cookie, bool mgmt_tx)
2666{
2667 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2668 int ret;
2669
2670 mutex_lock(&local->mtx);
2671 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002672 struct ieee80211_roc_work *dep, *tmp2;
2673
2674 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002675 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002676 continue;
2677 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2678 continue;
2679 /* found dependent item -- just remove it */
2680 list_del(&dep->list);
2681 mutex_unlock(&local->mtx);
2682
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002683 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002684 return 0;
2685 }
2686
Johannes Berg50febf62012-10-26 16:13:06 +02002687 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002688 continue;
2689 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2690 continue;
2691
2692 found = roc;
2693 break;
2694 }
2695
2696 if (!found) {
2697 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002698 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002699 }
Johannes Berg21f83582010-12-18 17:20:47 +01002700
Johannes Berge979e332012-06-11 17:09:41 +02002701 /*
2702 * We found the item to cancel, so do that. Note that it
2703 * may have dependents, which we also cancel (and send
2704 * the expired signal for.) Not doing so would be quite
2705 * tricky here, but we may need to fix it later.
2706 */
2707
Johannes Berg2eb278e2012-06-05 14:28:42 +02002708 if (local->ops->remain_on_channel) {
2709 if (found->started) {
2710 ret = drv_cancel_remain_on_channel(local);
2711 if (WARN_ON_ONCE(ret)) {
2712 mutex_unlock(&local->mtx);
2713 return ret;
2714 }
2715 }
Johannes Berg21f83582010-12-18 17:20:47 +01002716
Johannes Berg2eb278e2012-06-05 14:28:42 +02002717 list_del(&found->list);
2718
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002719 if (found->started)
2720 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002721 mutex_unlock(&local->mtx);
2722
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002723 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002724 } else {
2725 /* work may be pending so use it all the time */
2726 found->abort = true;
2727 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2728
2729 mutex_unlock(&local->mtx);
2730
2731 /* work will clean up etc */
2732 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002733 WARN_ON(!found->to_be_freed);
2734 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002735 }
Johannes Berg21f83582010-12-18 17:20:47 +01002736
Johannes Berg21f83582010-12-18 17:20:47 +01002737 return 0;
2738}
2739
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002740static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002741 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002742 u64 cookie)
2743{
Johannes Berg71bbc992012-06-15 15:30:18 +02002744 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002745 struct ieee80211_local *local = sdata->local;
2746
Johannes Berg2eb278e2012-06-05 14:28:42 +02002747 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002748}
2749
Simon Wunderlich164eb022013-02-08 18:16:20 +01002750static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2751 struct net_device *dev,
2752 struct cfg80211_chan_def *chandef)
2753{
2754 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2755 struct ieee80211_local *local = sdata->local;
2756 unsigned long timeout;
2757 int err;
2758
2759 if (!list_empty(&local->roc_list) || local->scanning)
2760 return -EBUSY;
2761
2762 /* whatever, but channel contexts should not complain about that one */
2763 sdata->smps_mode = IEEE80211_SMPS_OFF;
2764 sdata->needed_rx_chains = local->rx_chains;
2765 sdata->radar_required = true;
2766
2767 mutex_lock(&local->iflist_mtx);
2768 err = ieee80211_vif_use_channel(sdata, chandef,
2769 IEEE80211_CHANCTX_SHARED);
2770 mutex_unlock(&local->iflist_mtx);
2771 if (err)
2772 return err;
2773
2774 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2775 ieee80211_queue_delayed_work(&sdata->local->hw,
2776 &sdata->dfs_cac_timer_work, timeout);
2777
2778 return 0;
2779}
2780
Johannes Berg71bbc992012-06-15 15:30:18 +02002781static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002782 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01002783 unsigned int wait, const u8 *buf, size_t len,
2784 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002785{
Johannes Berg71bbc992012-06-15 15:30:18 +02002786 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002787 struct ieee80211_local *local = sdata->local;
2788 struct sk_buff *skb;
2789 struct sta_info *sta;
2790 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002791 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002792 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002793 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002794
Johannes Berge247bd902011-11-04 11:18:21 +01002795 if (dont_wait_for_ack)
2796 flags = IEEE80211_TX_CTL_NO_ACK;
2797 else
2798 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2799 IEEE80211_TX_CTL_REQ_TX_STATUS;
2800
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302801 if (no_cck)
2802 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2803
Johannes Berg9d38d852010-06-09 17:20:33 +02002804 switch (sdata->vif.type) {
2805 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002806 if (!sdata->vif.bss_conf.ibss_joined)
2807 need_offchan = true;
2808 /* fall through */
2809#ifdef CONFIG_MAC80211_MESH
2810 case NL80211_IFTYPE_MESH_POINT:
2811 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2812 !sdata->u.mesh.mesh_id_len)
2813 need_offchan = true;
2814 /* fall through */
2815#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002816 case NL80211_IFTYPE_AP:
2817 case NL80211_IFTYPE_AP_VLAN:
2818 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002819 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2820 !ieee80211_vif_is_mesh(&sdata->vif) &&
2821 !rcu_access_pointer(sdata->bss->beacon))
2822 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002823 if (!ieee80211_is_action(mgmt->frame_control) ||
2824 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002825 break;
2826 rcu_read_lock();
2827 sta = sta_info_get(sdata, mgmt->da);
2828 rcu_read_unlock();
2829 if (!sta)
2830 return -ENOLINK;
2831 break;
2832 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002833 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002834 if (!sdata->u.mgd.associated)
2835 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002836 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002837 case NL80211_IFTYPE_P2P_DEVICE:
2838 need_offchan = true;
2839 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002840 default:
2841 return -EOPNOTSUPP;
2842 }
2843
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002844 /* configurations requiring offchan cannot work if no channel has been
2845 * specified
2846 */
2847 if (need_offchan && !chan)
2848 return -EINVAL;
2849
Johannes Berg2eb278e2012-06-05 14:28:42 +02002850 mutex_lock(&local->mtx);
2851
2852 /* Check if the operating channel is the requested channel */
2853 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02002854 struct ieee80211_chanctx_conf *chanctx_conf;
2855
2856 rcu_read_lock();
2857 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2858
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002859 if (chanctx_conf) {
2860 need_offchan = chan && (chan != chanctx_conf->def.chan);
2861 } else if (!chan) {
2862 ret = -EINVAL;
2863 rcu_read_unlock();
2864 goto out_unlock;
2865 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002866 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002867 }
Johannes Berg55de9082012-07-26 17:24:39 +02002868 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02002869 }
2870
2871 if (need_offchan && !offchan) {
2872 ret = -EBUSY;
2873 goto out_unlock;
2874 }
2875
Johannes Berg9d38d852010-06-09 17:20:33 +02002876 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002877 if (!skb) {
2878 ret = -ENOMEM;
2879 goto out_unlock;
2880 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002881 skb_reserve(skb, local->hw.extra_tx_headroom);
2882
2883 memcpy(skb_put(skb, len), buf, len);
2884
2885 IEEE80211_SKB_CB(skb)->flags = flags;
2886
Johannes Berg2eb278e2012-06-05 14:28:42 +02002887 skb->dev = sdata->dev;
2888
2889 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002890 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002891 ieee80211_tx_skb(sdata, skb);
2892 ret = 0;
2893 goto out_unlock;
2894 }
2895
Seth Forshee6c17b772013-02-11 11:21:07 -06002896 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
2897 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002898 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002899 IEEE80211_SKB_CB(skb)->hw_queue =
2900 local->hw.offchannel_tx_hw_queue;
2901
Johannes Berg2eb278e2012-06-05 14:28:42 +02002902 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01002903 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002904 wait, cookie, skb,
2905 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002906 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002907 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002908 out_unlock:
2909 mutex_unlock(&local->mtx);
2910 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002911}
2912
Johannes Bergf30221e2010-11-25 10:02:30 +01002913static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002914 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002915 u64 cookie)
2916{
Johannes Berg71bbc992012-06-15 15:30:18 +02002917 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002918
Johannes Berg2eb278e2012-06-05 14:28:42 +02002919 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002920}
2921
Johannes Berg7be50862010-10-13 12:06:24 +02002922static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002923 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002924 u16 frame_type, bool reg)
2925{
2926 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002927 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002928
Will Hawkins6abe0562012-06-20 11:51:14 -04002929 switch (frame_type) {
2930 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2931 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2932 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002933
Will Hawkins6abe0562012-06-20 11:51:14 -04002934 if (reg)
2935 ifibss->auth_frame_registrations++;
2936 else
2937 ifibss->auth_frame_registrations--;
2938 }
2939 break;
2940 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2941 if (reg)
2942 local->probe_req_reg++;
2943 else
2944 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002945
Felix Fietkau35f51492012-10-31 15:50:34 +01002946 if (!local->open_count)
2947 break;
2948
Will Hawkins6abe0562012-06-20 11:51:14 -04002949 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2950 break;
2951 default:
2952 break;
2953 }
Johannes Berg7be50862010-10-13 12:06:24 +02002954}
2955
Bruno Randolf15d96752010-11-10 12:50:56 +09002956static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2957{
2958 struct ieee80211_local *local = wiphy_priv(wiphy);
2959
2960 if (local->started)
2961 return -EOPNOTSUPP;
2962
2963 return drv_set_antenna(local, tx_ant, rx_ant);
2964}
2965
2966static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2967{
2968 struct ieee80211_local *local = wiphy_priv(wiphy);
2969
2970 return drv_get_antenna(local, tx_ant, rx_ant);
2971}
2972
John W. Linville38c09152011-03-07 16:19:18 -05002973static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2974{
2975 struct ieee80211_local *local = wiphy_priv(wiphy);
2976
2977 return drv_set_ringparam(local, tx, rx);
2978}
2979
2980static void ieee80211_get_ringparam(struct wiphy *wiphy,
2981 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2982{
2983 struct ieee80211_local *local = wiphy_priv(wiphy);
2984
2985 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2986}
2987
Johannes Bergc68f4b82011-07-05 16:35:41 +02002988static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2989 struct net_device *dev,
2990 struct cfg80211_gtk_rekey_data *data)
2991{
2992 struct ieee80211_local *local = wiphy_priv(wiphy);
2993 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2994
2995 if (!local->ops->set_rekey_data)
2996 return -EOPNOTSUPP;
2997
2998 drv_set_rekey_data(local, sdata, data);
2999
3000 return 0;
3001}
3002
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003003static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
3004{
3005 u8 *pos = (void *)skb_put(skb, 7);
3006
3007 *pos++ = WLAN_EID_EXT_CAPABILITY;
3008 *pos++ = 5; /* len */
3009 *pos++ = 0x0;
3010 *pos++ = 0x0;
3011 *pos++ = 0x0;
3012 *pos++ = 0x0;
3013 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
3014}
3015
3016static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
3017{
3018 struct ieee80211_local *local = sdata->local;
3019 u16 capab;
3020
3021 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003022 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003023 return capab;
3024
3025 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3026 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3027 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3028 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3029
3030 return capab;
3031}
3032
3033static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3034 u8 *peer, u8 *bssid)
3035{
3036 struct ieee80211_tdls_lnkie *lnkid;
3037
3038 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3039
3040 lnkid->ie_type = WLAN_EID_LINK_ID;
3041 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3042
3043 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3044 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3045 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3046}
3047
3048static int
3049ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3050 u8 *peer, u8 action_code, u8 dialog_token,
3051 u16 status_code, struct sk_buff *skb)
3052{
3053 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003054 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003055 struct ieee80211_tdls_data *tf;
3056
3057 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3058
3059 memcpy(tf->da, peer, ETH_ALEN);
3060 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3061 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3062 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3063
3064 switch (action_code) {
3065 case WLAN_TDLS_SETUP_REQUEST:
3066 tf->category = WLAN_CATEGORY_TDLS;
3067 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3068
3069 skb_put(skb, sizeof(tf->u.setup_req));
3070 tf->u.setup_req.dialog_token = dialog_token;
3071 tf->u.setup_req.capability =
3072 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3073
Johannes Berg55de9082012-07-26 17:24:39 +02003074 ieee80211_add_srates_ie(sdata, skb, false, band);
3075 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003076 ieee80211_tdls_add_ext_capab(skb);
3077 break;
3078 case WLAN_TDLS_SETUP_RESPONSE:
3079 tf->category = WLAN_CATEGORY_TDLS;
3080 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3081
3082 skb_put(skb, sizeof(tf->u.setup_resp));
3083 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3084 tf->u.setup_resp.dialog_token = dialog_token;
3085 tf->u.setup_resp.capability =
3086 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3087
Johannes Berg55de9082012-07-26 17:24:39 +02003088 ieee80211_add_srates_ie(sdata, skb, false, band);
3089 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003090 ieee80211_tdls_add_ext_capab(skb);
3091 break;
3092 case WLAN_TDLS_SETUP_CONFIRM:
3093 tf->category = WLAN_CATEGORY_TDLS;
3094 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3095
3096 skb_put(skb, sizeof(tf->u.setup_cfm));
3097 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3098 tf->u.setup_cfm.dialog_token = dialog_token;
3099 break;
3100 case WLAN_TDLS_TEARDOWN:
3101 tf->category = WLAN_CATEGORY_TDLS;
3102 tf->action_code = WLAN_TDLS_TEARDOWN;
3103
3104 skb_put(skb, sizeof(tf->u.teardown));
3105 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3106 break;
3107 case WLAN_TDLS_DISCOVERY_REQUEST:
3108 tf->category = WLAN_CATEGORY_TDLS;
3109 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3110
3111 skb_put(skb, sizeof(tf->u.discover_req));
3112 tf->u.discover_req.dialog_token = dialog_token;
3113 break;
3114 default:
3115 return -EINVAL;
3116 }
3117
3118 return 0;
3119}
3120
3121static int
3122ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3123 u8 *peer, u8 action_code, u8 dialog_token,
3124 u16 status_code, struct sk_buff *skb)
3125{
3126 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003127 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003128 struct ieee80211_mgmt *mgmt;
3129
3130 mgmt = (void *)skb_put(skb, 24);
3131 memset(mgmt, 0, 24);
3132 memcpy(mgmt->da, peer, ETH_ALEN);
3133 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3134 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3135
3136 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3137 IEEE80211_STYPE_ACTION);
3138
3139 switch (action_code) {
3140 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3141 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3142 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3143 mgmt->u.action.u.tdls_discover_resp.action_code =
3144 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3145 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3146 dialog_token;
3147 mgmt->u.action.u.tdls_discover_resp.capability =
3148 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3149
Johannes Berg55de9082012-07-26 17:24:39 +02003150 ieee80211_add_srates_ie(sdata, skb, false, band);
3151 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003152 ieee80211_tdls_add_ext_capab(skb);
3153 break;
3154 default:
3155 return -EINVAL;
3156 }
3157
3158 return 0;
3159}
3160
3161static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3162 u8 *peer, u8 action_code, u8 dialog_token,
3163 u16 status_code, const u8 *extra_ies,
3164 size_t extra_ies_len)
3165{
3166 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3167 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003168 struct sk_buff *skb = NULL;
3169 bool send_direct;
3170 int ret;
3171
3172 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3173 return -ENOTSUPP;
3174
3175 /* make sure we are in managed mode, and associated */
3176 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3177 !sdata->u.mgd.associated)
3178 return -EINVAL;
3179
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003180 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3181 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003182
3183 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3184 max(sizeof(struct ieee80211_mgmt),
3185 sizeof(struct ieee80211_tdls_data)) +
3186 50 + /* supported rates */
3187 7 + /* ext capab */
3188 extra_ies_len +
3189 sizeof(struct ieee80211_tdls_lnkie));
3190 if (!skb)
3191 return -ENOMEM;
3192
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003193 skb_reserve(skb, local->hw.extra_tx_headroom);
3194
3195 switch (action_code) {
3196 case WLAN_TDLS_SETUP_REQUEST:
3197 case WLAN_TDLS_SETUP_RESPONSE:
3198 case WLAN_TDLS_SETUP_CONFIRM:
3199 case WLAN_TDLS_TEARDOWN:
3200 case WLAN_TDLS_DISCOVERY_REQUEST:
3201 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3202 action_code, dialog_token,
3203 status_code, skb);
3204 send_direct = false;
3205 break;
3206 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3207 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3208 dialog_token, status_code,
3209 skb);
3210 send_direct = true;
3211 break;
3212 default:
3213 ret = -ENOTSUPP;
3214 break;
3215 }
3216
3217 if (ret < 0)
3218 goto fail;
3219
3220 if (extra_ies_len)
3221 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3222
3223 /* the TDLS link IE is always added last */
3224 switch (action_code) {
3225 case WLAN_TDLS_SETUP_REQUEST:
3226 case WLAN_TDLS_SETUP_CONFIRM:
3227 case WLAN_TDLS_TEARDOWN:
3228 case WLAN_TDLS_DISCOVERY_REQUEST:
3229 /* we are the initiator */
3230 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3231 sdata->u.mgd.bssid);
3232 break;
3233 case WLAN_TDLS_SETUP_RESPONSE:
3234 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3235 /* we are the responder */
3236 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3237 sdata->u.mgd.bssid);
3238 break;
3239 default:
3240 ret = -ENOTSUPP;
3241 goto fail;
3242 }
3243
3244 if (send_direct) {
3245 ieee80211_tx_skb(sdata, skb);
3246 return 0;
3247 }
3248
3249 /*
3250 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3251 * we should default to AC_VI.
3252 */
3253 switch (action_code) {
3254 case WLAN_TDLS_SETUP_REQUEST:
3255 case WLAN_TDLS_SETUP_RESPONSE:
3256 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3257 skb->priority = 2;
3258 break;
3259 default:
3260 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3261 skb->priority = 5;
3262 break;
3263 }
3264
3265 /* disable bottom halves when entering the Tx path */
3266 local_bh_disable();
3267 ret = ieee80211_subif_start_xmit(skb, dev);
3268 local_bh_enable();
3269
3270 return ret;
3271
3272fail:
3273 dev_kfree_skb(skb);
3274 return ret;
3275}
3276
3277static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3278 u8 *peer, enum nl80211_tdls_operation oper)
3279{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003280 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3282
3283 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3284 return -ENOTSUPP;
3285
3286 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3287 return -EINVAL;
3288
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003289 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003290
3291 switch (oper) {
3292 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003293 rcu_read_lock();
3294 sta = sta_info_get(sdata, peer);
3295 if (!sta) {
3296 rcu_read_unlock();
3297 return -ENOLINK;
3298 }
3299
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003300 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003301 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003302 break;
3303 case NL80211_TDLS_DISABLE_LINK:
3304 return sta_info_destroy_addr(sdata, peer);
3305 case NL80211_TDLS_TEARDOWN:
3306 case NL80211_TDLS_SETUP:
3307 case NL80211_TDLS_DISCOVERY_REQ:
3308 /* We don't support in-driver setup/teardown/discovery */
3309 return -ENOTSUPP;
3310 default:
3311 return -ENOTSUPP;
3312 }
3313
3314 return 0;
3315}
3316
Johannes Berg06500732011-11-04 11:18:16 +01003317static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3318 const u8 *peer, u64 *cookie)
3319{
3320 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3321 struct ieee80211_local *local = sdata->local;
3322 struct ieee80211_qos_hdr *nullfunc;
3323 struct sk_buff *skb;
3324 int size = sizeof(*nullfunc);
3325 __le16 fc;
3326 bool qos;
3327 struct ieee80211_tx_info *info;
3328 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003329 struct ieee80211_chanctx_conf *chanctx_conf;
3330 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003331
3332 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003333 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3334 if (WARN_ON(!chanctx_conf)) {
3335 rcu_read_unlock();
3336 return -EINVAL;
3337 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003338 band = chanctx_conf->def.chan->band;
Johannes Berg06500732011-11-04 11:18:16 +01003339 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003340 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003341 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003342 } else {
3343 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003344 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003345 }
Johannes Berg06500732011-11-04 11:18:16 +01003346
3347 if (qos) {
3348 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3349 IEEE80211_STYPE_QOS_NULLFUNC |
3350 IEEE80211_FCTL_FROMDS);
3351 } else {
3352 size -= 2;
3353 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3354 IEEE80211_STYPE_NULLFUNC |
3355 IEEE80211_FCTL_FROMDS);
3356 }
3357
3358 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003359 if (!skb) {
3360 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003361 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003362 }
Johannes Berg06500732011-11-04 11:18:16 +01003363
3364 skb->dev = dev;
3365
3366 skb_reserve(skb, local->hw.extra_tx_headroom);
3367
3368 nullfunc = (void *) skb_put(skb, size);
3369 nullfunc->frame_control = fc;
3370 nullfunc->duration_id = 0;
3371 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3372 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3373 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3374 nullfunc->seq_ctrl = 0;
3375
3376 info = IEEE80211_SKB_CB(skb);
3377
3378 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3379 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3380
3381 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3382 skb->priority = 7;
3383 if (qos)
3384 nullfunc->qos_ctrl = cpu_to_le16(7);
3385
3386 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003387 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003388 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003389 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003390
3391 *cookie = (unsigned long) skb;
3392 return 0;
3393}
3394
Johannes Berg683b6d32012-11-08 21:25:48 +01003395static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3396 struct wireless_dev *wdev,
3397 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003398{
Johannes Berg55de9082012-07-26 17:24:39 +02003399 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003400 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003401 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003402 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003403
Johannes Berg55de9082012-07-26 17:24:39 +02003404 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003405 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3406 if (chanctx_conf) {
3407 *chandef = chanctx_conf->def;
3408 ret = 0;
3409 } else if (local->open_count > 0 &&
3410 local->open_count == local->monitors &&
3411 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3412 if (local->use_chanctx)
3413 *chandef = local->monitor_chandef;
3414 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003415 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003416 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003417 }
3418 rcu_read_unlock();
3419
Johannes Berg683b6d32012-11-08 21:25:48 +01003420 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003421}
3422
Johannes Berg6d525632012-04-04 15:05:25 +02003423#ifdef CONFIG_PM
3424static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3425{
3426 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3427}
3428#endif
3429
Jiri Bencf0706e82007-05-05 11:45:53 -07003430struct cfg80211_ops mac80211_config_ops = {
3431 .add_virtual_intf = ieee80211_add_iface,
3432 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003433 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003434 .start_p2p_device = ieee80211_start_p2p_device,
3435 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003436 .add_key = ieee80211_add_key,
3437 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003438 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003439 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003440 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003441 .start_ap = ieee80211_start_ap,
3442 .change_beacon = ieee80211_change_beacon,
3443 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003444 .add_station = ieee80211_add_station,
3445 .del_station = ieee80211_del_station,
3446 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003447 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003448 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003449 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003450#ifdef CONFIG_MAC80211_MESH
3451 .add_mpath = ieee80211_add_mpath,
3452 .del_mpath = ieee80211_del_mpath,
3453 .change_mpath = ieee80211_change_mpath,
3454 .get_mpath = ieee80211_get_mpath,
3455 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003456 .update_mesh_config = ieee80211_update_mesh_config,
3457 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003458 .join_mesh = ieee80211_join_mesh,
3459 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003460#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003461 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003462 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003463 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003464 .suspend = ieee80211_suspend,
3465 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003466 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003467 .sched_scan_start = ieee80211_sched_scan_start,
3468 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003469 .auth = ieee80211_auth,
3470 .assoc = ieee80211_assoc,
3471 .deauth = ieee80211_deauth,
3472 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003473 .join_ibss = ieee80211_join_ibss,
3474 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003475 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003476 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003477 .set_tx_power = ieee80211_set_tx_power,
3478 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003479 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003480 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003481 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003482 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003483 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003484 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003485 .remain_on_channel = ieee80211_remain_on_channel,
3486 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003487 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003488 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003489 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003490 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003491 .set_antenna = ieee80211_set_antenna,
3492 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003493 .set_ringparam = ieee80211_set_ringparam,
3494 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003495 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003496 .tdls_oper = ieee80211_tdls_oper,
3497 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003498 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003499 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003500#ifdef CONFIG_PM
3501 .set_wakeup = ieee80211_set_wakeup,
3502#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003503 .get_et_sset_count = ieee80211_get_et_sset_count,
3504 .get_et_stats = ieee80211_get_et_stats,
3505 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003506 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003507 .start_radar_detection = ieee80211_start_radar_detection,
Jiri Bencf0706e82007-05-05 11:45:53 -07003508};