blob: b82fff6c0b306e3e11b4dbcdb434f7a7efb72e7d [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;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200398 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
399 u16 brate;
400
Johannes Berg8bc83c22012-11-09 18:38:32 +0100401 sband = sta->local->hw.wiphy->bands[
402 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200403 brate = sband->bitrates[rate->idx].bitrate;
404 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100405 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800406 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
407 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100408 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
409 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
410 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
411 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800412 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
413 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800414}
415
Saravana003e6762012-11-28 18:29:38 +0530416void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
417{
418 rinfo->flags = 0;
419
420 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
421 rinfo->flags |= RATE_INFO_FLAGS_MCS;
422 rinfo->mcs = sta->last_rx_rate_idx;
423 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
424 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
425 rinfo->nss = sta->last_rx_rate_vht_nss;
426 rinfo->mcs = sta->last_rx_rate_idx;
427 } else {
428 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200429 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
430 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530431
432 sband = sta->local->hw.wiphy->bands[
433 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200434 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
435 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530436 }
437
438 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
439 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
440 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
441 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
442 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
443 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
444 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
445 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
446 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
447 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
448}
449
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100450static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
451{
Johannes Bergd0709a62008-02-25 16:27:46 +0100452 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300453 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530454 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100455 u64 packets = 0;
Felix Fietkauef0621e2013-04-22 16:29:31 +0200456 int i, ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100457
Johannes Bergf5ea9122009-08-07 16:17:38 +0200458 sinfo->generation = sdata->local->sta_generation;
459
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100460 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100461 STATION_INFO_RX_BYTES64 |
462 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200463 STATION_INFO_RX_PACKETS |
464 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900465 STATION_INFO_TX_RETRIES |
466 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700467 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100468 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700469 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530470 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200471 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800472 STATION_INFO_STA_FLAGS |
473 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530474
475 do_posix_clock_monotonic_gettime(&uptime);
476 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100477
478 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100479 sinfo->tx_bytes = 0;
480 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
481 sinfo->tx_bytes += sta->tx_bytes[ac];
482 packets += sta->tx_packets[ac];
483 }
484 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100485 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200486 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900487 sinfo->tx_retries = sta->tx_retry_count;
488 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700489 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800490 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100491
John W. Linville19deffb2009-12-08 17:10:13 -0500492 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
493 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900494 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300495 if (!local->ops->get_rssi ||
496 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
497 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900498 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100499 }
Felix Fietkauef0621e2013-04-22 16:29:31 +0200500 if (sta->chains) {
501 sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
502 STATION_INFO_CHAIN_SIGNAL_AVG;
503
504 sinfo->chains = sta->chains;
505 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
506 sinfo->chain_signal[i] = sta->chain_signal_last[i];
507 sinfo->chain_signal_avg[i] =
508 (s8) -ewma_read(&sta->chain_signal_avg[i]);
509 }
510 }
Henning Rogge420e7fa2008-12-11 22:04:19 +0100511
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800512 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530513 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100514
Johannes Berg902acc72008-02-23 15:17:19 +0100515 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100516#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100517 sinfo->filled |= STATION_INFO_LLID |
518 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100519 STATION_INFO_PLINK_STATE |
520 STATION_INFO_LOCAL_PM |
521 STATION_INFO_PEER_PM |
522 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100523
524 sinfo->llid = le16_to_cpu(sta->llid);
525 sinfo->plid = le16_to_cpu(sta->plid);
526 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700527 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
528 sinfo->filled |= STATION_INFO_T_OFFSET;
529 sinfo->t_offset = sta->t_offset;
530 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100531 sinfo->local_pm = sta->local_pm;
532 sinfo->peer_pm = sta->peer_pm;
533 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100534#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100535 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700536
537 sinfo->bss_param.flags = 0;
538 if (sdata->vif.bss_conf.use_cts_prot)
539 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
540 if (sdata->vif.bss_conf.use_short_preamble)
541 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
542 if (sdata->vif.bss_conf.use_short_slot)
543 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
544 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
545 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200546
547 sinfo->sta_flags.set = 0;
548 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
549 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
550 BIT(NL80211_STA_FLAG_WME) |
551 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100552 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200553 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100554 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200555 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
556 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
557 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
558 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
559 if (test_sta_flag(sta, WLAN_STA_WME))
560 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
561 if (test_sta_flag(sta, WLAN_STA_MFP))
562 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
563 if (test_sta_flag(sta, WLAN_STA_AUTH))
564 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200565 if (test_sta_flag(sta, WLAN_STA_ASSOC))
566 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100567 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
568 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100569}
570
Ben Greearb1ab7922012-04-23 12:50:30 -0700571static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
572 "rx_packets", "rx_bytes", "wep_weak_iv_count",
573 "rx_duplicates", "rx_fragments", "rx_dropped",
574 "tx_packets", "tx_bytes", "tx_fragments",
575 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700576 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
577 "channel", "noise", "ch_time", "ch_time_busy",
578 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700579};
580#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
581
582static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
583 struct net_device *dev,
584 int sset)
585{
Ben Greeare3521142012-04-23 12:50:31 -0700586 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
587 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700588
Ben Greeare3521142012-04-23 12:50:31 -0700589 if (sset == ETH_SS_STATS)
590 rv += STA_STATS_LEN;
591
592 rv += drv_get_et_sset_count(sdata, sset);
593
594 if (rv == 0)
595 return -EOPNOTSUPP;
596 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700597}
598
599static void ieee80211_get_et_stats(struct wiphy *wiphy,
600 struct net_device *dev,
601 struct ethtool_stats *stats,
602 u64 *data)
603{
604 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200605 struct ieee80211_chanctx_conf *chanctx_conf;
606 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700607 struct sta_info *sta;
608 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700609 struct station_info sinfo;
610 struct survey_info survey;
611 int i, q;
612#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700613
614 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
615
616#define ADD_STA_STATS(sta) \
617 do { \
618 data[i++] += sta->rx_packets; \
619 data[i++] += sta->rx_bytes; \
620 data[i++] += sta->wep_weak_iv_count; \
621 data[i++] += sta->num_duplicates; \
622 data[i++] += sta->rx_fragments; \
623 data[i++] += sta->rx_dropped; \
624 \
Johannes Berg560d2682013-02-05 10:55:21 +0100625 data[i++] += sinfo.tx_packets; \
626 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700627 data[i++] += sta->tx_fragments; \
628 data[i++] += sta->tx_filtered_count; \
629 data[i++] += sta->tx_retry_failed; \
630 data[i++] += sta->tx_retry_count; \
631 data[i++] += sta->beacon_loss_count; \
632 } while (0)
633
634 /* For Managed stations, find the single station based on BSSID
635 * and use that. For interface types, iterate through all available
636 * stations and add stats for any station that is assigned to this
637 * network device.
638 */
639
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300640 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700641
642 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
643 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700644
645 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
646 goto do_survey;
647
Johannes Berg560d2682013-02-05 10:55:21 +0100648 sinfo.filled = 0;
649 sta_set_sinfo(sta, &sinfo);
650
Ben Greear3073a7c2012-04-23 12:50:32 -0700651 i = 0;
652 ADD_STA_STATS(sta);
653
654 data[i++] = sta->sta_state;
655
Ben Greear3073a7c2012-04-23 12:50:32 -0700656
Joe Perches52042672012-05-30 13:25:54 -0700657 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700658 data[i] = 100000 *
659 cfg80211_calculate_bitrate(&sinfo.txrate);
660 i++;
Joe Perches52042672012-05-30 13:25:54 -0700661 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700662 data[i] = 100000 *
663 cfg80211_calculate_bitrate(&sinfo.rxrate);
664 i++;
665
Joe Perches52042672012-05-30 13:25:54 -0700666 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700667 data[i] = (u8)sinfo.signal_avg;
668 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700669 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300670 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700671 /* Make sure this station belongs to the proper dev */
672 if (sta->sdata->dev != dev)
673 continue;
674
675 i = 0;
676 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700677 }
678 }
679
Ben Greear3073a7c2012-04-23 12:50:32 -0700680do_survey:
681 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
682 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200683 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700684
Johannes Berg55de9082012-07-26 17:24:39 +0200685 rcu_read_lock();
686 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
687 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100688 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200689 else
690 channel = NULL;
691 rcu_read_unlock();
692
693 if (channel) {
694 q = 0;
695 do {
696 survey.filled = 0;
697 if (drv_get_survey(local, q, &survey) != 0) {
698 survey.filled = 0;
699 break;
700 }
701 q++;
702 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700703 }
704
705 if (survey.filled)
706 data[i++] = survey.channel->center_freq;
707 else
708 data[i++] = 0;
709 if (survey.filled & SURVEY_INFO_NOISE_DBM)
710 data[i++] = (u8)survey.noise;
711 else
712 data[i++] = -1LL;
713 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
714 data[i++] = survey.channel_time;
715 else
716 data[i++] = -1LL;
717 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
718 data[i++] = survey.channel_time_busy;
719 else
720 data[i++] = -1LL;
721 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
722 data[i++] = survey.channel_time_ext_busy;
723 else
724 data[i++] = -1LL;
725 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
726 data[i++] = survey.channel_time_rx;
727 else
728 data[i++] = -1LL;
729 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
730 data[i++] = survey.channel_time_tx;
731 else
732 data[i++] = -1LL;
733
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300734 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700735
Ben Greear3073a7c2012-04-23 12:50:32 -0700736 if (WARN_ON(i != STA_STATS_LEN))
737 return;
738
Ben Greeare3521142012-04-23 12:50:31 -0700739 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700740}
741
742static void ieee80211_get_et_strings(struct wiphy *wiphy,
743 struct net_device *dev,
744 u32 sset, u8 *data)
745{
Ben Greeare3521142012-04-23 12:50:31 -0700746 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
747 int sz_sta_stats = 0;
748
Ben Greearb1ab7922012-04-23 12:50:30 -0700749 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700750 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Johannes Bergbd500af2013-05-06 21:09:46 +0200751 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700752 }
Ben Greeare3521142012-04-23 12:50:31 -0700753 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700754}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100755
756static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
757 int idx, u8 *mac, struct station_info *sinfo)
758{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100759 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300760 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100761 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100762 int ret = -ENOENT;
763
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300764 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100765
Johannes Berg3b53fde82009-11-16 12:00:37 +0100766 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100767 if (sta) {
768 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200769 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100770 sta_set_sinfo(sta, sinfo);
771 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100772
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300773 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100774
Johannes Bergd0709a62008-02-25 16:27:46 +0100775 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100776}
777
Holger Schurig12897232010-04-19 10:23:57 +0200778static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
779 int idx, struct survey_info *survey)
780{
781 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
782
Holger Schurig12897232010-04-19 10:23:57 +0200783 return drv_get_survey(local, idx, survey);
784}
785
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100786static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100787 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100788{
Johannes Bergabe60632009-11-25 17:46:18 +0100789 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300790 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100791 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100792 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100793
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300794 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100795
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100796 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100797 if (sta) {
798 ret = 0;
799 sta_set_sinfo(sta, sinfo);
800 }
801
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300802 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100803
804 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100805}
806
Johannes Berge8c9bd52012-06-06 08:18:22 +0200807static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100808 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200809{
Johannes Berg55de9082012-07-26 17:24:39 +0200810 struct ieee80211_local *local = wiphy_priv(wiphy);
811 struct ieee80211_sub_if_data *sdata;
812 int ret = 0;
813
Johannes Berg4bf88532012-11-09 11:39:59 +0100814 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200815 return 0;
816
817 mutex_lock(&local->iflist_mtx);
818 if (local->use_chanctx) {
819 sdata = rcu_dereference_protected(
820 local->monitor_sdata,
821 lockdep_is_held(&local->iflist_mtx));
822 if (sdata) {
823 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100824 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200825 IEEE80211_CHANCTX_EXCLUSIVE);
826 }
827 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100828 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200829 ieee80211_hw_config(local, 0);
830 }
831
Johannes Berg4bf88532012-11-09 11:39:59 +0100832 if (ret == 0)
833 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200834 mutex_unlock(&local->iflist_mtx);
835
836 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200837}
838
Arik Nemtsov02945822011-11-10 11:28:57 +0200839static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100840 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200841{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300842 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200843
844 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530845 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200846
Arik Nemtsovf7248282011-11-19 10:51:26 +0200847 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200848
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300849 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200850 if (!new)
851 return -ENOMEM;
852
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300853 new->len = resp_len;
854 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200855
856 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300857 if (old)
858 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200859
860 return 0;
861}
862
Johannes Berg88600202012-02-13 15:17:18 +0100863static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
864 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100865{
866 struct beacon_data *new, *old;
867 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100868 int size, err;
869 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100870
Johannes Berg40b275b2011-05-13 14:15:49 +0200871 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100872
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100873 /* Need to have a beacon head if we don't have one yet */
874 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100875 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100876
877 /* new or old head? */
878 if (params->head)
879 new_head_len = params->head_len;
880 else
881 new_head_len = old->head_len;
882
883 /* new or old tail? */
884 if (params->tail || !old)
885 /* params->tail_len will be zero for !params->tail */
886 new_tail_len = params->tail_len;
887 else
888 new_tail_len = old->tail_len;
889
890 size = sizeof(*new) + new_head_len + new_tail_len;
891
892 new = kzalloc(size, GFP_KERNEL);
893 if (!new)
894 return -ENOMEM;
895
896 /* start filling the new info now */
897
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100898 /*
899 * pointers go into the block we allocated,
900 * memory is | beacon_data | head | tail |
901 */
902 new->head = ((u8 *) new) + sizeof(*new);
903 new->tail = new->head + new_head_len;
904 new->head_len = new_head_len;
905 new->tail_len = new_tail_len;
906
907 /* copy in head */
908 if (params->head)
909 memcpy(new->head, params->head, new_head_len);
910 else
911 memcpy(new->head, old->head, new_head_len);
912
913 /* copy in optional tail */
914 if (params->tail)
915 memcpy(new->tail, params->tail, new_tail_len);
916 else
917 if (old)
918 memcpy(new->tail, old->tail, new_tail_len);
919
Johannes Berg88600202012-02-13 15:17:18 +0100920 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
921 params->probe_resp_len);
922 if (err < 0)
923 return err;
924 if (err == 0)
925 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100926
Eric Dumazetcf778b02012-01-12 04:41:32 +0000927 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100928
Johannes Berg88600202012-02-13 15:17:18 +0100929 if (old)
930 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100931
Johannes Berg88600202012-02-13 15:17:18 +0100932 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100933}
934
Johannes Berg88600202012-02-13 15:17:18 +0100935static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
936 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100937{
Johannes Berg88600202012-02-13 15:17:18 +0100938 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100939 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100940 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100941 u32 changed = BSS_CHANGED_BEACON_INT |
942 BSS_CHANGED_BEACON_ENABLED |
943 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100944 BSS_CHANGED_SSID |
945 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100946 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200947
Johannes Berg40b275b2011-05-13 14:15:49 +0200948 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100949 if (old)
950 return -EALREADY;
951
Johannes Berg04ecd252012-09-11 14:34:12 +0200952 /* TODO: make hostapd tell us what it wants */
953 sdata->smps_mode = IEEE80211_SMPS_OFF;
954 sdata->needed_rx_chains = sdata->local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +0100955 sdata->radar_required = params->radar_required;
Johannes Berg04ecd252012-09-11 14:34:12 +0200956
Johannes Berg4bf88532012-11-09 11:39:59 +0100957 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200958 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200959 if (err)
960 return err;
Johannes Berg1f4ac5a2013-02-08 12:07:44 +0100961 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Bergaa430da2012-05-16 23:50:18 +0200962
Johannes Berg665c93a2011-11-04 11:18:11 +0100963 /*
964 * Apply control port protocol, this allows us to
965 * not encrypt dynamic WEP control frames.
966 */
967 sdata->control_port_protocol = params->crypto.control_port_ethertype;
968 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
969 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
970 vlan->control_port_protocol =
971 params->crypto.control_port_ethertype;
972 vlan->control_port_no_encrypt =
973 params->crypto.control_port_no_encrypt;
974 }
975
Johannes Berg88600202012-02-13 15:17:18 +0100976 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
977 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100978 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100979
980 sdata->vif.bss_conf.ssid_len = params->ssid_len;
981 if (params->ssid_len)
982 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
983 params->ssid_len);
984 sdata->vif.bss_conf.hidden_ssid =
985 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
986
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100987 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
988 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
989 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
990 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
991 if (params->p2p_opp_ps)
992 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
993 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100994
Johannes Berg88600202012-02-13 15:17:18 +0100995 err = ieee80211_assign_beacon(sdata, &params->beacon);
996 if (err < 0)
997 return err;
998 changed |= err;
999
Johannes Berg10416382012-10-19 15:44:42 +02001000 err = drv_start_ap(sdata->local, sdata);
1001 if (err) {
1002 old = rtnl_dereference(sdata->u.ap.beacon);
1003 if (old)
1004 kfree_rcu(old, rcu_head);
1005 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1006 return err;
1007 }
1008
Johannes Berg88600202012-02-13 15:17:18 +01001009 ieee80211_bss_info_change_notify(sdata, changed);
1010
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001011 netif_carrier_on(dev);
1012 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1013 netif_carrier_on(vlan->dev);
1014
Johannes Berg665c93a2011-11-04 11:18:11 +01001015 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001016}
1017
Johannes Berg88600202012-02-13 15:17:18 +01001018static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1019 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001020{
Johannes Berg14db74b2008-07-29 13:22:52 +02001021 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001022 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001023 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001024
Johannes Berg14db74b2008-07-29 13:22:52 +02001025 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1026
Johannes Berg40b275b2011-05-13 14:15:49 +02001027 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001028 if (!old)
1029 return -ENOENT;
1030
Johannes Berg88600202012-02-13 15:17:18 +01001031 err = ieee80211_assign_beacon(sdata, params);
1032 if (err < 0)
1033 return err;
1034 ieee80211_bss_info_change_notify(sdata, err);
1035 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001036}
1037
Johannes Berg88600202012-02-13 15:17:18 +01001038static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001039{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001040 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1041 struct ieee80211_sub_if_data *vlan;
1042 struct ieee80211_local *local = sdata->local;
1043 struct beacon_data *old_beacon;
1044 struct probe_resp *old_probe_resp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001045
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001046 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1047 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001048 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001049 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001050
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001051 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001052 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1053 netif_carrier_off(vlan->dev);
1054 netif_carrier_off(dev);
1055
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001056 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001057 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001058 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1059 kfree_rcu(old_beacon, rcu_head);
1060 if (old_probe_resp)
1061 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001062
Felix Fietkau2d4072a2012-12-10 20:02:34 +01001063 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
Johannes Berg75de9112012-12-14 14:56:03 +01001064 sta_info_flush_defer(vlan);
1065 sta_info_flush_defer(sdata);
Bob Copeland8ceb5952013-04-18 18:26:49 -04001066 synchronize_net();
Johannes Berg75de9112012-12-14 14:56:03 +01001067 rcu_barrier();
Johannes Berg7b4396b2013-02-23 01:14:20 +01001068 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
Johannes Berg75de9112012-12-14 14:56:03 +01001069 sta_info_flush_cleanup(vlan);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001070 ieee80211_free_keys(vlan);
1071 }
Johannes Berg75de9112012-12-14 14:56:03 +01001072 sta_info_flush_cleanup(sdata);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001073 ieee80211_free_keys(sdata);
Johannes Berg75de9112012-12-14 14:56:03 +01001074
Johannes Bergd6a83222012-12-14 14:06:28 +01001075 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001076 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001077 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001078 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001079
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001080 if (sdata->wdev.cac_started) {
1081 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1082 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
1083 GFP_KERNEL);
1084 }
1085
Johannes Berg10416382012-10-19 15:44:42 +02001086 drv_stop_ap(sdata->local, sdata);
1087
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001088 /* free all potentially still buffered bcast frames */
1089 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1090 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1091
Johannes Berg1f4ac5a2013-02-08 12:07:44 +01001092 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001093 ieee80211_vif_release_channel(sdata);
1094
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001095 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001096}
1097
Johannes Berg4fd69312007-12-19 02:03:35 +01001098/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1099struct iapp_layer2_update {
1100 u8 da[ETH_ALEN]; /* broadcast */
1101 u8 sa[ETH_ALEN]; /* STA addr */
1102 __be16 len; /* 6 */
1103 u8 dsap; /* 0 */
1104 u8 ssap; /* 0 */
1105 u8 control;
1106 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001107} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001108
1109static void ieee80211_send_layer2_update(struct sta_info *sta)
1110{
1111 struct iapp_layer2_update *msg;
1112 struct sk_buff *skb;
1113
1114 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1115 * bridge devices */
1116
1117 skb = dev_alloc_skb(sizeof(*msg));
1118 if (!skb)
1119 return;
1120 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1121
1122 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1123 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1124
Johannes Berge83e6542012-07-13 16:23:07 +02001125 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001126 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001127 msg->len = htons(6);
1128 msg->dsap = 0;
1129 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1130 msg->control = 0xaf; /* XID response lsb.1111F101.
1131 * F=0 (no poll command; unsolicited frame) */
1132 msg->xid_info[0] = 0x81; /* XID format identifier */
1133 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1134 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1135
Johannes Bergd0709a62008-02-25 16:27:46 +01001136 skb->dev = sta->sdata->dev;
1137 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001138 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001139 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001140}
1141
Johannes Bergd582cff2012-10-26 17:53:44 +02001142static int sta_apply_auth_flags(struct ieee80211_local *local,
1143 struct sta_info *sta,
1144 u32 mask, u32 set)
1145{
1146 int ret;
1147
1148 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1149 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1150 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1151 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1152 if (ret)
1153 return ret;
1154 }
1155
1156 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1157 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1158 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1159 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1160 if (ret)
1161 return ret;
1162 }
1163
1164 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1165 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1166 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1167 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1168 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1169 else
1170 ret = 0;
1171 if (ret)
1172 return ret;
1173 }
1174
1175 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1176 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1177 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1178 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1179 if (ret)
1180 return ret;
1181 }
1182
1183 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1184 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1185 test_sta_flag(sta, WLAN_STA_AUTH)) {
1186 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1187 if (ret)
1188 return ret;
1189 }
1190
1191 return 0;
1192}
1193
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001194static int sta_apply_parameters(struct ieee80211_local *local,
1195 struct sta_info *sta,
1196 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001197{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001198 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001199 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001200 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001201 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001202 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001203
Johannes Berg55de9082012-07-26 17:24:39 +02001204 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001205
Johannes Bergeccb8e82009-05-11 21:57:56 +03001206 mask = params->sta_flags_mask;
1207 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001208
Johannes Bergd582cff2012-10-26 17:53:44 +02001209 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1210 /*
1211 * In mesh mode, ASSOCIATED isn't part of the nl80211
1212 * API but must follow AUTHENTICATED for driver state.
1213 */
1214 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1215 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1216 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1217 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001218 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1219 /*
1220 * TDLS -- everything follows authorized, but
1221 * only becoming authorized is possible, not
1222 * going back
1223 */
1224 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1225 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1226 BIT(NL80211_STA_FLAG_ASSOCIATED);
1227 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1228 BIT(NL80211_STA_FLAG_ASSOCIATED);
1229 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001230 }
1231
Johannes Bergd582cff2012-10-26 17:53:44 +02001232 ret = sta_apply_auth_flags(local, sta, mask, set);
1233 if (ret)
1234 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001235
Johannes Bergeccb8e82009-05-11 21:57:56 +03001236 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001237 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001238 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1239 else
1240 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001241 }
1242
1243 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001244 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001245 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001246 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001247 } else {
1248 clear_sta_flag(sta, WLAN_STA_WME);
1249 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001250 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001251 }
1252
1253 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001254 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001255 set_sta_flag(sta, WLAN_STA_MFP);
1256 else
1257 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001258 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001259
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001260 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001261 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001262 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1263 else
1264 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001265 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001266
Johannes Berg3b9ce802011-09-27 20:56:12 +02001267 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1268 sta->sta.uapsd_queues = params->uapsd_queues;
1269 sta->sta.max_sp = params->max_sp;
1270 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001271
Johannes Berg73651ee2008-02-25 16:27:47 +01001272 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001273 * cfg80211 validates this (1-2007) and allows setting the AID
1274 * only when creating a new station entry
1275 */
1276 if (params->aid)
1277 sta->sta.aid = params->aid;
1278
1279 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001280 * Some of the following updates would be racy if called on an
1281 * existing station, via ieee80211_change_station(). However,
1282 * all such changes are rejected by cfg80211 except for updates
1283 * changing the supported rates on an existing but not yet used
1284 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001285 */
1286
Johannes Berg4fd69312007-12-19 02:03:35 +01001287 if (params->listen_interval >= 0)
1288 sta->listen_interval = params->listen_interval;
1289
1290 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001291 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1292 sband, params->supported_rates,
1293 params->supported_rates_len,
1294 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001295 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001296
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001297 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001298 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001299 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001300
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001301 if (params->vht_capa)
1302 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001303 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001304
Javier Cardona9c3990a2011-05-03 16:57:11 -07001305 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001306#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001307 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001308
1309 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001310 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001311 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001312 if (sta->plink_state != NL80211_PLINK_ESTAB)
1313 changed = mesh_plink_inc_estab_count(
1314 sdata);
1315 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001316
1317 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001318 changed |= ieee80211_mps_set_sta_local_pm(sta,
1319 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001320 break;
1321 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001322 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001323 case NL80211_PLINK_OPN_SNT:
1324 case NL80211_PLINK_OPN_RCVD:
1325 case NL80211_PLINK_CNF_RCVD:
1326 case NL80211_PLINK_HOLDING:
1327 if (sta->plink_state == NL80211_PLINK_ESTAB)
1328 changed = mesh_plink_dec_estab_count(
1329 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001330 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001331
1332 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001333 changed |=
1334 ieee80211_mps_local_status_update(sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001335 break;
1336 default:
1337 /* nothing */
1338 break;
1339 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001340 }
1341
1342 switch (params->plink_action) {
1343 case NL80211_PLINK_ACTION_NO_ACTION:
1344 /* nothing */
1345 break;
1346 case NL80211_PLINK_ACTION_OPEN:
1347 changed |= mesh_plink_open(sta);
1348 break;
1349 case NL80211_PLINK_ACTION_BLOCK:
1350 changed |= mesh_plink_block(sta);
1351 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001352 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001353
1354 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001355 changed |=
1356 ieee80211_mps_set_sta_local_pm(sta,
1357 params->local_pm);
1358 ieee80211_bss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001359#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001360 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001361
1362 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001363}
1364
1365static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1366 u8 *mac, struct station_parameters *params)
1367{
Johannes Berg14db74b2008-07-29 13:22:52 +02001368 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001369 struct sta_info *sta;
1370 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001371 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001372 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001373
Johannes Berg4fd69312007-12-19 02:03:35 +01001374 if (params->vlan) {
1375 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1376
Johannes Berg05c914f2008-09-11 00:01:58 +02001377 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1378 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001379 return -EINVAL;
1380 } else
1381 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1382
Joe Perchesb203ca32012-05-08 18:56:52 +00001383 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001384 return -EINVAL;
1385
1386 if (is_multicast_ether_addr(mac))
1387 return -EINVAL;
1388
1389 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001390 if (!sta)
1391 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001392
Johannes Bergd582cff2012-10-26 17:53:44 +02001393 /*
1394 * defaults -- if userspace wants something else we'll
1395 * change it accordingly in sta_apply_parameters()
1396 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001397 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1398 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1399 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1400 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001401
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001402 err = sta_apply_parameters(local, sta, params);
1403 if (err) {
1404 sta_info_free(local, sta);
1405 return err;
1406 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001407
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001408 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001409 * for TDLS, rate control should be initialized only when
1410 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001411 */
1412 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1413 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001414
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001415 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1416 sdata->vif.type == NL80211_IFTYPE_AP;
1417
Johannes Berg34e89502010-02-03 13:59:58 +01001418 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001419 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001420 rcu_read_unlock();
1421 return err;
1422 }
1423
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001424 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001425 ieee80211_send_layer2_update(sta);
1426
1427 rcu_read_unlock();
1428
Johannes Berg4fd69312007-12-19 02:03:35 +01001429 return 0;
1430}
1431
1432static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1433 u8 *mac)
1434{
Johannes Berg14db74b2008-07-29 13:22:52 +02001435 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001436
Johannes Berg14db74b2008-07-29 13:22:52 +02001437 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1438
Johannes Berg34e89502010-02-03 13:59:58 +01001439 if (mac)
1440 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001441
Johannes Bergb998e8b2012-12-13 23:07:46 +01001442 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001443 return 0;
1444}
1445
1446static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001447 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001448 struct station_parameters *params)
1449{
Johannes Bergabe60632009-11-25 17:46:18 +01001450 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001451 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001452 struct sta_info *sta;
1453 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001454 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001455 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001456
Johannes Berg87be1e12011-12-14 12:20:29 +01001457 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001458
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001459 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001460 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001461 err = -ENOENT;
1462 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001463 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001464
Johannes Berg77ee7c82013-02-15 00:48:33 +01001465 switch (sdata->vif.type) {
1466 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001467 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001468 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001469 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001470 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001471 break;
1472 case NL80211_IFTYPE_ADHOC:
1473 statype = CFG80211_STA_IBSS;
1474 break;
1475 case NL80211_IFTYPE_STATION:
1476 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1477 statype = CFG80211_STA_AP_STA;
1478 break;
1479 }
1480 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1481 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1482 else
1483 statype = CFG80211_STA_TDLS_PEER_SETUP;
1484 break;
1485 case NL80211_IFTYPE_AP:
1486 case NL80211_IFTYPE_AP_VLAN:
1487 statype = CFG80211_STA_AP_CLIENT;
1488 break;
1489 default:
1490 err = -EOPNOTSUPP;
1491 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001492 }
1493
Johannes Berg77ee7c82013-02-15 00:48:33 +01001494 err = cfg80211_check_station_change(wiphy, params, statype);
1495 if (err)
1496 goto out_err;
1497
Johannes Bergd0709a62008-02-25 16:27:46 +01001498 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001499 bool prev_4addr = false;
1500 bool new_4addr = false;
1501
Johannes Berg4fd69312007-12-19 02:03:35 +01001502 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1503
Johannes Berg9bc383d2009-11-19 11:55:19 +01001504 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001505 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001506 err = -EBUSY;
1507 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001508 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001509
Eric Dumazetcf778b02012-01-12 04:41:32 +00001510 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001511 new_4addr = true;
1512 }
1513
1514 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1515 sta->sdata->u.vlan.sta) {
1516 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1517 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001518 }
1519
Johannes Berg14db74b2008-07-29 13:22:52 +02001520 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001521
1522 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1523 prev_4addr != new_4addr) {
1524 if (new_4addr)
1525 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1526 else
1527 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1528 }
1529
Johannes Berg4fd69312007-12-19 02:03:35 +01001530 ieee80211_send_layer2_update(sta);
1531 }
1532
Eliad Peller35b88622011-12-29 14:41:39 +02001533 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001534 if (err)
1535 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001536
Johannes Berg77ee7c82013-02-15 00:48:33 +01001537 /* When peer becomes authorized, init rate control as well */
1538 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1539 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001540 rate_control_rate_init(sta);
1541
Johannes Berg87be1e12011-12-14 12:20:29 +01001542 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001543
Jason Young808118c2011-03-10 16:43:19 -08001544 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001545 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001546 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001547 ieee80211_recalc_ps_vif(sdata);
1548 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001549
Johannes Berg4fd69312007-12-19 02:03:35 +01001550 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001551out_err:
1552 mutex_unlock(&local->sta_mtx);
1553 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001554}
1555
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001556#ifdef CONFIG_MAC80211_MESH
1557static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1558 u8 *dst, u8 *next_hop)
1559{
Johannes Berg14db74b2008-07-29 13:22:52 +02001560 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001561 struct mesh_path *mpath;
1562 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001563
Johannes Berg14db74b2008-07-29 13:22:52 +02001564 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1565
Johannes Bergd0709a62008-02-25 16:27:46 +01001566 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001567 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001568 if (!sta) {
1569 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001570 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001571 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001572
Bob Copelandae76eef2013-03-29 09:38:39 -04001573 mpath = mesh_path_add(sdata, dst);
1574 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001575 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001576 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001577 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001578
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001579 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001580
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001581 rcu_read_unlock();
1582 return 0;
1583}
1584
1585static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001586 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001587{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001588 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001589
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001590 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001591 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001592
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001593 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001594 return 0;
1595}
1596
1597static int ieee80211_change_mpath(struct wiphy *wiphy,
1598 struct net_device *dev,
1599 u8 *dst, u8 *next_hop)
1600{
Johannes Berg14db74b2008-07-29 13:22:52 +02001601 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001602 struct mesh_path *mpath;
1603 struct sta_info *sta;
1604
Johannes Berg14db74b2008-07-29 13:22:52 +02001605 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1606
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001607 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001608
Johannes Bergabe60632009-11-25 17:46:18 +01001609 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001610 if (!sta) {
1611 rcu_read_unlock();
1612 return -ENOENT;
1613 }
1614
Johannes Bergbf7cd942013-02-15 14:40:31 +01001615 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001616 if (!mpath) {
1617 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001618 return -ENOENT;
1619 }
1620
1621 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001622
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001623 rcu_read_unlock();
1624 return 0;
1625}
1626
1627static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1628 struct mpath_info *pinfo)
1629{
Johannes Berga3836e02011-05-12 15:11:37 +02001630 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1631
1632 if (next_hop_sta)
1633 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001634 else
1635 memset(next_hop, 0, ETH_ALEN);
1636
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001637 memset(pinfo, 0, sizeof(*pinfo));
1638
Johannes Bergf5ea9122009-08-07 16:17:38 +02001639 pinfo->generation = mesh_paths_generation;
1640
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001641 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001642 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001643 MPATH_INFO_METRIC |
1644 MPATH_INFO_EXPTIME |
1645 MPATH_INFO_DISCOVERY_TIMEOUT |
1646 MPATH_INFO_DISCOVERY_RETRIES |
1647 MPATH_INFO_FLAGS;
1648
1649 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001650 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001651 pinfo->metric = mpath->metric;
1652 if (time_before(jiffies, mpath->exp_time))
1653 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1654 pinfo->discovery_timeout =
1655 jiffies_to_msecs(mpath->discovery_timeout);
1656 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001657 if (mpath->flags & MESH_PATH_ACTIVE)
1658 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1659 if (mpath->flags & MESH_PATH_RESOLVING)
1660 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001661 if (mpath->flags & MESH_PATH_SN_VALID)
1662 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001663 if (mpath->flags & MESH_PATH_FIXED)
1664 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001665 if (mpath->flags & MESH_PATH_RESOLVED)
1666 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001667}
1668
1669static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1670 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1671
1672{
Johannes Berg14db74b2008-07-29 13:22:52 +02001673 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001674 struct mesh_path *mpath;
1675
Johannes Berg14db74b2008-07-29 13:22:52 +02001676 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1677
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001678 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001679 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001680 if (!mpath) {
1681 rcu_read_unlock();
1682 return -ENOENT;
1683 }
1684 memcpy(dst, mpath->dst, ETH_ALEN);
1685 mpath_set_pinfo(mpath, next_hop, pinfo);
1686 rcu_read_unlock();
1687 return 0;
1688}
1689
1690static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1691 int idx, u8 *dst, u8 *next_hop,
1692 struct mpath_info *pinfo)
1693{
Johannes Berg14db74b2008-07-29 13:22:52 +02001694 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001695 struct mesh_path *mpath;
1696
Johannes Berg14db74b2008-07-29 13:22:52 +02001697 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1698
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001699 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001700 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001701 if (!mpath) {
1702 rcu_read_unlock();
1703 return -ENOENT;
1704 }
1705 memcpy(dst, mpath->dst, ETH_ALEN);
1706 mpath_set_pinfo(mpath, next_hop, pinfo);
1707 rcu_read_unlock();
1708 return 0;
1709}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001710
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001711static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001712 struct net_device *dev,
1713 struct mesh_config *conf)
1714{
1715 struct ieee80211_sub_if_data *sdata;
1716 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1717
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001718 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1719 return 0;
1720}
1721
1722static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1723{
1724 return (mask >> (parm-1)) & 0x1;
1725}
1726
Javier Cardonac80d5452010-12-16 17:37:49 -08001727static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1728 const struct mesh_setup *setup)
1729{
1730 u8 *new_ie;
1731 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001732 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1733 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001734
Javier Cardona581a8b02011-04-07 15:08:27 -07001735 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001736 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001737 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001738
Javier Cardona581a8b02011-04-07 15:08:27 -07001739 if (setup->ie_len) {
1740 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001741 GFP_KERNEL);
1742 if (!new_ie)
1743 return -ENOMEM;
1744 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001745 ifmsh->ie_len = setup->ie_len;
1746 ifmsh->ie = new_ie;
1747 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001748
1749 /* now copy the rest of the setup parameters */
1750 ifmsh->mesh_id_len = setup->mesh_id_len;
1751 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001752 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001753 ifmsh->mesh_pp_id = setup->path_sel_proto;
1754 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001755 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001756 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001757 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1758 if (setup->is_authenticated)
1759 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1760 if (setup->is_secure)
1761 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001762
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001763 /* mcast rate setting in Mesh Node */
1764 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1765 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001766 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001767
Marco Porsch9bdbf042013-01-07 16:04:51 +01001768 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1769 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1770
Javier Cardonac80d5452010-12-16 17:37:49 -08001771 return 0;
1772}
1773
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001774static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001775 struct net_device *dev, u32 mask,
1776 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001777{
1778 struct mesh_config *conf;
1779 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001780 struct ieee80211_if_mesh *ifmsh;
1781
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001782 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001783 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001784
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001785 /* Set the config options which we are interested in setting */
1786 conf = &(sdata->u.mesh.mshcfg);
1787 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1788 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1789 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1790 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1791 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1792 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1793 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1794 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1795 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1796 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1797 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1798 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001799 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001800 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001801 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1802 if (ifmsh->user_mpm)
1803 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001804 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001805 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001806 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1807 conf->dot11MeshNbrOffsetMaxNeighbor =
1808 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001809 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1810 conf->dot11MeshHWMPmaxPREQretries =
1811 nconf->dot11MeshHWMPmaxPREQretries;
1812 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1813 conf->path_refresh_time = nconf->path_refresh_time;
1814 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1815 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1816 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1817 conf->dot11MeshHWMPactivePathTimeout =
1818 nconf->dot11MeshHWMPactivePathTimeout;
1819 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1820 conf->dot11MeshHWMPpreqMinInterval =
1821 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001822 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1823 conf->dot11MeshHWMPperrMinInterval =
1824 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001825 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1826 mask))
1827 conf->dot11MeshHWMPnetDiameterTraversalTime =
1828 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001829 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1830 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1831 ieee80211_mesh_root_setup(ifmsh);
1832 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001833 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001834 /* our current gate announcement implementation rides on root
1835 * announcements, so require this ifmsh to also be a root node
1836 * */
1837 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001838 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1839 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001840 ieee80211_mesh_root_setup(ifmsh);
1841 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001842 conf->dot11MeshGateAnnouncementProtocol =
1843 nconf->dot11MeshGateAnnouncementProtocol;
1844 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001845 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001846 conf->dot11MeshHWMPRannInterval =
1847 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001848 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1849 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001850 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1851 /* our RSSI threshold implementation is supported only for
1852 * devices that report signal in dBm.
1853 */
1854 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1855 return -ENOTSUPP;
1856 conf->rssi_threshold = nconf->rssi_threshold;
1857 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001858 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1859 conf->ht_opmode = nconf->ht_opmode;
1860 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1861 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1862 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001863 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1864 conf->dot11MeshHWMPactivePathToRootTimeout =
1865 nconf->dot11MeshHWMPactivePathToRootTimeout;
1866 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1867 conf->dot11MeshHWMProotInterval =
1868 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001869 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1870 conf->dot11MeshHWMPconfirmationInterval =
1871 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001872 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1873 conf->power_mode = nconf->power_mode;
1874 ieee80211_mps_local_status_update(sdata);
1875 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001876 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001877 conf->dot11MeshAwakeWindowDuration =
1878 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001879 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1880 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001881 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001882 return 0;
1883}
1884
Johannes Berg29cbe682010-12-03 09:20:44 +01001885static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1886 const struct mesh_config *conf,
1887 const struct mesh_setup *setup)
1888{
1889 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1890 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001891 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001892
Javier Cardonac80d5452010-12-16 17:37:49 -08001893 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1894 err = copy_mesh_setup(ifmsh, setup);
1895 if (err)
1896 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001897
Johannes Berg04ecd252012-09-11 14:34:12 +02001898 /* can mesh use other SMPS modes? */
1899 sdata->smps_mode = IEEE80211_SMPS_OFF;
1900 sdata->needed_rx_chains = sdata->local->rx_chains;
1901
Johannes Berg4bf88532012-11-09 11:39:59 +01001902 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001903 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001904 if (err)
1905 return err;
1906
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001907 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001908}
1909
1910static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1911{
1912 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1913
1914 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001915 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001916
1917 return 0;
1918}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001919#endif
1920
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001921static int ieee80211_change_bss(struct wiphy *wiphy,
1922 struct net_device *dev,
1923 struct bss_parameters *params)
1924{
Johannes Berg55de9082012-07-26 17:24:39 +02001925 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1926 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001927 u32 changed = 0;
1928
Johannes Berg55de9082012-07-26 17:24:39 +02001929 if (!rtnl_dereference(sdata->u.ap.beacon))
1930 return -ENOENT;
1931
1932 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001933
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001934 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001935 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001936 changed |= BSS_CHANGED_ERP_CTS_PROT;
1937 }
1938 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001939 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001940 params->use_short_preamble;
1941 changed |= BSS_CHANGED_ERP_PREAMBLE;
1942 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001943
1944 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001945 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001946 sdata->vif.bss_conf.use_short_slot = true;
1947 changed |= BSS_CHANGED_ERP_SLOT;
1948 }
1949
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001950 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001951 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001952 params->use_short_slot_time;
1953 changed |= BSS_CHANGED_ERP_SLOT;
1954 }
1955
Jouni Malinen90c97a02008-10-30 16:59:22 +02001956 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001957 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1958 wiphy->bands[band],
1959 params->basic_rates,
1960 params->basic_rates_len,
1961 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02001962 changed |= BSS_CHANGED_BASIC_RATES;
1963 }
1964
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001965 if (params->ap_isolate >= 0) {
1966 if (params->ap_isolate)
1967 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1968 else
1969 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1970 }
1971
Helmut Schaa80d7e402010-11-19 12:40:26 +01001972 if (params->ht_opmode >= 0) {
1973 sdata->vif.bss_conf.ht_operation_mode =
1974 (u16) params->ht_opmode;
1975 changed |= BSS_CHANGED_HT;
1976 }
1977
Johannes Berg339afbf2012-11-14 15:21:17 +01001978 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001979 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1980 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1981 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1982 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001983 changed |= BSS_CHANGED_P2P_PS;
1984 }
1985
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001986 if (params->p2p_opp_ps > 0) {
1987 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1988 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1989 changed |= BSS_CHANGED_P2P_PS;
1990 } else if (params->p2p_opp_ps == 0) {
1991 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1992 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001993 changed |= BSS_CHANGED_P2P_PS;
1994 }
1995
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001996 ieee80211_bss_info_change_notify(sdata, changed);
1997
1998 return 0;
1999}
2000
Jouni Malinen31888482008-10-30 16:59:24 +02002001static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002002 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002003 struct ieee80211_txq_params *params)
2004{
2005 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002006 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002007 struct ieee80211_tx_queue_params p;
2008
2009 if (!local->ops->conf_tx)
2010 return -EOPNOTSUPP;
2011
Johannes Berg54bcbc62012-03-28 11:04:25 +02002012 if (local->hw.queues < IEEE80211_NUM_ACS)
2013 return -EOPNOTSUPP;
2014
Jouni Malinen31888482008-10-30 16:59:24 +02002015 memset(&p, 0, sizeof(p));
2016 p.aifs = params->aifs;
2017 p.cw_max = params->cwmax;
2018 p.cw_min = params->cwmin;
2019 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002020
2021 /*
2022 * Setting tx queue params disables u-apsd because it's only
2023 * called in master mode.
2024 */
2025 p.uapsd = false;
2026
Johannes Berga3304b02012-03-28 11:04:24 +02002027 sdata->tx_conf[params->ac] = p;
2028 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002029 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002030 "failed to set TX queue parameters for AC %d\n",
2031 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002032 return -EINVAL;
2033 }
2034
Johannes Berg7d257452012-07-06 17:37:43 +02002035 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2036
Jouni Malinen31888482008-10-30 16:59:24 +02002037 return 0;
2038}
2039
Bob Copeland665af4f2009-01-19 11:20:53 -05002040#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002041static int ieee80211_suspend(struct wiphy *wiphy,
2042 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002043{
Johannes Bergeecc4802011-05-04 15:37:29 +02002044 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002045}
2046
2047static int ieee80211_resume(struct wiphy *wiphy)
2048{
2049 return __ieee80211_resume(wiphy_priv(wiphy));
2050}
2051#else
2052#define ieee80211_suspend NULL
2053#define ieee80211_resume NULL
2054#endif
2055
Johannes Berg2a519312009-02-10 21:25:55 +01002056static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002057 struct cfg80211_scan_request *req)
2058{
Johannes Bergfd014282012-06-18 19:17:03 +02002059 struct ieee80211_sub_if_data *sdata;
2060
2061 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002062
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002063 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2064 case NL80211_IFTYPE_STATION:
2065 case NL80211_IFTYPE_ADHOC:
2066 case NL80211_IFTYPE_MESH_POINT:
2067 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002068 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002069 break;
2070 case NL80211_IFTYPE_P2P_GO:
2071 if (sdata->local->ops->hw_scan)
2072 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002073 /*
2074 * FIXME: implement NoA while scanning in software,
2075 * for now fall through to allow scanning only when
2076 * beaconing hasn't been configured yet
2077 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002078 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002079 /*
2080 * If the scan has been forced (and the driver supports
2081 * forcing), don't care about being beaconing already.
2082 * This will create problems to the attached stations (e.g. all
2083 * the frames sent while scanning on other channel will be
2084 * lost)
2085 */
2086 if (sdata->u.ap.beacon &&
2087 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2088 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002089 return -EOPNOTSUPP;
2090 break;
2091 default:
2092 return -EOPNOTSUPP;
2093 }
Johannes Berg2a519312009-02-10 21:25:55 +01002094
2095 return ieee80211_request_scan(sdata, req);
2096}
2097
Luciano Coelho79f460c2011-05-11 17:09:36 +03002098static int
2099ieee80211_sched_scan_start(struct wiphy *wiphy,
2100 struct net_device *dev,
2101 struct cfg80211_sched_scan_request *req)
2102{
2103 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2104
2105 if (!sdata->local->ops->sched_scan_start)
2106 return -EOPNOTSUPP;
2107
2108 return ieee80211_request_sched_scan_start(sdata, req);
2109}
2110
2111static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002112ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002113{
2114 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2115
2116 if (!sdata->local->ops->sched_scan_stop)
2117 return -EOPNOTSUPP;
2118
Luciano Coelho85a99942011-05-12 16:28:29 +03002119 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002120}
2121
Jouni Malinen636a5d32009-03-19 13:39:22 +02002122static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2123 struct cfg80211_auth_request *req)
2124{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002125 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002126}
2127
2128static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2129 struct cfg80211_assoc_request *req)
2130{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002131 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002132}
2133
2134static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002135 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002136{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002137 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002138}
2139
2140static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002141 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002142{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002143 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002144}
2145
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002146static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2147 struct cfg80211_ibss_params *params)
2148{
Johannes Berg55de9082012-07-26 17:24:39 +02002149 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002150}
2151
2152static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2153{
Johannes Berg55de9082012-07-26 17:24:39 +02002154 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002155}
2156
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002157static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2158 int rate[IEEE80211_NUM_BANDS])
2159{
2160 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2161
Cong Ding9887dbf2013-02-06 17:23:45 +01002162 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2163 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002164
2165 return 0;
2166}
2167
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002168static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2169{
2170 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002171 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002172
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002173 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2174 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2175
2176 if (err)
2177 return err;
2178 }
2179
Lukáš Turek310bc672009-12-21 22:50:48 +01002180 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2181 err = drv_set_coverage_class(local, wiphy->coverage_class);
2182
2183 if (err)
2184 return err;
2185 }
2186
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002187 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002188 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002189
Johannes Berg24487982009-04-23 18:52:52 +02002190 if (err)
2191 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002192 }
2193
Johannes Berg8bc83c22012-11-09 18:38:32 +01002194 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2195 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2196 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002197 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002198 }
2199 if (changed & WIPHY_PARAM_RETRY_LONG) {
2200 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2201 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002202 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002203 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002204 if (changed &
2205 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2206 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2207
2208 return 0;
2209}
2210
Johannes Berg7643a2c2009-06-02 13:01:39 +02002211static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002212 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002213 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002214{
2215 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002216 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002217
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002218 if (wdev) {
2219 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2220
2221 switch (type) {
2222 case NL80211_TX_POWER_AUTOMATIC:
2223 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2224 break;
2225 case NL80211_TX_POWER_LIMITED:
2226 case NL80211_TX_POWER_FIXED:
2227 if (mbm < 0 || (mbm % 100))
2228 return -EOPNOTSUPP;
2229 sdata->user_power_level = MBM_TO_DBM(mbm);
2230 break;
2231 }
2232
2233 ieee80211_recalc_txpower(sdata);
2234
2235 return 0;
2236 }
Johannes Berg55de9082012-07-26 17:24:39 +02002237
Johannes Berg7643a2c2009-06-02 13:01:39 +02002238 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002239 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002240 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002241 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002242 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002243 case NL80211_TX_POWER_FIXED:
2244 if (mbm < 0 || (mbm % 100))
2245 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002246 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002247 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002248 }
2249
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002250 mutex_lock(&local->iflist_mtx);
2251 list_for_each_entry(sdata, &local->interfaces, list)
2252 sdata->user_power_level = local->user_power_level;
2253 list_for_each_entry(sdata, &local->interfaces, list)
2254 ieee80211_recalc_txpower(sdata);
2255 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002256
2257 return 0;
2258}
2259
Johannes Bergc8442112012-10-24 10:17:18 +02002260static int ieee80211_get_tx_power(struct wiphy *wiphy,
2261 struct wireless_dev *wdev,
2262 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002263{
2264 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002265 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002266
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002267 if (!local->use_chanctx)
2268 *dbm = local->hw.conf.power_level;
2269 else
2270 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002271
Johannes Berg7643a2c2009-06-02 13:01:39 +02002272 return 0;
2273}
2274
Johannes Bergab737a42009-07-01 21:26:58 +02002275static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002276 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002277{
2278 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2279
2280 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2281
2282 return 0;
2283}
2284
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002285static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2286{
2287 struct ieee80211_local *local = wiphy_priv(wiphy);
2288
2289 drv_rfkill_poll(local);
2290}
2291
Johannes Bergaff89a92009-07-01 21:26:51 +02002292#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002293static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002294{
2295 struct ieee80211_local *local = wiphy_priv(wiphy);
2296
2297 if (!local->ops->testmode_cmd)
2298 return -EOPNOTSUPP;
2299
2300 return local->ops->testmode_cmd(&local->hw, data, len);
2301}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002302
2303static int ieee80211_testmode_dump(struct wiphy *wiphy,
2304 struct sk_buff *skb,
2305 struct netlink_callback *cb,
2306 void *data, int len)
2307{
2308 struct ieee80211_local *local = wiphy_priv(wiphy);
2309
2310 if (!local->ops->testmode_dump)
2311 return -EOPNOTSUPP;
2312
2313 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2314}
Johannes Bergaff89a92009-07-01 21:26:51 +02002315#endif
2316
Johannes Berg0f782312009-12-01 13:37:02 +01002317int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2318 enum ieee80211_smps_mode smps_mode)
2319{
2320 const u8 *ap;
2321 enum ieee80211_smps_mode old_req;
2322 int err;
2323
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002324 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002325
Johannes Berg0f782312009-12-01 13:37:02 +01002326 old_req = sdata->u.mgd.req_smps;
2327 sdata->u.mgd.req_smps = smps_mode;
2328
2329 if (old_req == smps_mode &&
2330 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2331 return 0;
2332
2333 /*
2334 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002335 * association, there's no need to do anything, just store
2336 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002337 */
2338 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002339 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002340 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002341
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002342 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002343
2344 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2345 if (sdata->u.mgd.powersave)
2346 smps_mode = IEEE80211_SMPS_DYNAMIC;
2347 else
2348 smps_mode = IEEE80211_SMPS_OFF;
2349 }
2350
2351 /* send SM PS frame to AP */
2352 err = ieee80211_send_smps_action(sdata, smps_mode,
2353 ap, ap);
2354 if (err)
2355 sdata->u.mgd.req_smps = old_req;
2356
2357 return err;
2358}
2359
Johannes Bergbc92afd2009-07-01 21:26:57 +02002360static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2361 bool enabled, int timeout)
2362{
2363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2364 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002365
Chun-Yeow Yeohee1f6682013-01-10 23:31:54 +08002366 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2367 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002368 return -EOPNOTSUPP;
2369
Johannes Bergbc92afd2009-07-01 21:26:57 +02002370 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2371 return -EOPNOTSUPP;
2372
2373 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002374 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002375 return 0;
2376
2377 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002378 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002379
Johannes Berg0f782312009-12-01 13:37:02 +01002380 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002381 sdata_lock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002382 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002383 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002384
Johannes Bergbc92afd2009-07-01 21:26:57 +02002385 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2386 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2387
2388 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002389 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002390
2391 return 0;
2392}
2393
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002394static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2395 struct net_device *dev,
2396 s32 rssi_thold, u32 rssi_hyst)
2397{
2398 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002399 struct ieee80211_vif *vif = &sdata->vif;
2400 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2401
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002402 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2403 rssi_hyst == bss_conf->cqm_rssi_hyst)
2404 return 0;
2405
2406 bss_conf->cqm_rssi_thold = rssi_thold;
2407 bss_conf->cqm_rssi_hyst = rssi_hyst;
2408
2409 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002410 if (sdata->u.mgd.associated &&
2411 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002412 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2413
2414 return 0;
2415}
2416
Johannes Berg99303802009-07-01 21:26:59 +02002417static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2418 struct net_device *dev,
2419 const u8 *addr,
2420 const struct cfg80211_bitrate_mask *mask)
2421{
2422 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2423 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302424 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002425
Eliad Peller554a43d2012-06-12 12:41:15 +03002426 if (!ieee80211_sdata_running(sdata))
2427 return -ENETDOWN;
2428
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302429 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2430 ret = drv_set_bitrate_mask(local, sdata, mask);
2431 if (ret)
2432 return ret;
2433 }
Johannes Berg99303802009-07-01 21:26:59 +02002434
Simon Wunderlich19468412012-01-28 17:25:33 +01002435 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002436 struct ieee80211_supported_band *sband = wiphy->bands[i];
2437 int j;
2438
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002439 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002440 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2441 sizeof(mask->control[i].mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002442
2443 sdata->rc_has_mcs_mask[i] = false;
2444 if (!sband)
2445 continue;
2446
2447 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2448 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2449 sdata->rc_has_mcs_mask[i] = true;
2450 break;
2451 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002452 }
Johannes Berg99303802009-07-01 21:26:59 +02002453
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002454 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002455}
2456
Johannes Berg2eb278e2012-06-05 14:28:42 +02002457static int ieee80211_start_roc_work(struct ieee80211_local *local,
2458 struct ieee80211_sub_if_data *sdata,
2459 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002460 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002461 struct sk_buff *txskb,
2462 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002463{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002464 struct ieee80211_roc_work *roc, *tmp;
2465 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002466 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002467
2468 lockdep_assert_held(&local->mtx);
2469
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002470 if (local->use_chanctx && !local->ops->remain_on_channel)
2471 return -EOPNOTSUPP;
2472
Johannes Berg2eb278e2012-06-05 14:28:42 +02002473 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2474 if (!roc)
2475 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002476
Johannes Berg2eb278e2012-06-05 14:28:42 +02002477 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002478 roc->duration = duration;
2479 roc->req_duration = duration;
2480 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002481 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002482 roc->mgmt_tx_cookie = (unsigned long)txskb;
2483 roc->sdata = sdata;
2484 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2485 INIT_LIST_HEAD(&roc->dependents);
2486
2487 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002488 if (!list_empty(&local->roc_list) ||
2489 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002490 goto out_check_combine;
2491
2492 /* if not HW assist, just queue & schedule work */
2493 if (!local->ops->remain_on_channel) {
2494 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2495 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002496 }
2497
Johannes Berg2eb278e2012-06-05 14:28:42 +02002498 /* otherwise actually kick it off here (for error handling) */
2499
2500 /*
2501 * If the duration is zero, then the driver
2502 * wouldn't actually do anything. Set it to
2503 * 10 for now.
2504 *
2505 * TODO: cancel the off-channel operation
2506 * when we get the SKB's TX status and
2507 * the wait time was zero before.
2508 */
2509 if (!duration)
2510 duration = 10;
2511
Ilan Peerd339d5c2013-02-12 09:34:13 +02002512 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002513 if (ret) {
2514 kfree(roc);
2515 return ret;
2516 }
2517
2518 roc->started = true;
2519 goto out_queue;
2520
2521 out_check_combine:
2522 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002523 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002524 continue;
2525
2526 /*
2527 * Extend this ROC if possible:
2528 *
2529 * If it hasn't started yet, just increase the duration
2530 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002531 * If the type of the new ROC has higher priority, modify the
2532 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002533 */
2534 if (!tmp->started) {
2535 list_add_tail(&roc->list, &tmp->dependents);
2536 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002537 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002538 queued = true;
2539 break;
2540 }
2541
2542 /* If it has already started, it's more difficult ... */
2543 if (local->ops->remain_on_channel) {
2544 unsigned long j = jiffies;
2545
2546 /*
2547 * In the offloaded ROC case, if it hasn't begun, add
2548 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002549 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002550 * check that there's still a minimum time left and
2551 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002552 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002553 * a reduced time so we'll ask the driver to execute
2554 * it right after finishing the previous one, in the
2555 * hope that it'll also be executed right afterwards,
2556 * effectively extending the old one.
2557 * If there's no minimum time left, just add it to the
2558 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002559 * TODO: the ROC type is ignored here, assuming that it
2560 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002561 */
2562 if (!tmp->hw_begun) {
2563 list_add_tail(&roc->list, &tmp->dependents);
2564 queued = true;
2565 break;
2566 }
2567
2568 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2569 tmp->hw_start_time +
2570 msecs_to_jiffies(tmp->duration))) {
2571 int new_dur;
2572
2573 ieee80211_handle_roc_started(roc);
2574
2575 new_dur = roc->duration -
2576 jiffies_to_msecs(tmp->hw_start_time +
2577 msecs_to_jiffies(
2578 tmp->duration) -
2579 j);
2580
2581 if (new_dur > 0) {
2582 /* add right after tmp */
2583 list_add(&roc->list, &tmp->list);
2584 } else {
2585 list_add_tail(&roc->list,
2586 &tmp->dependents);
2587 }
2588 queued = true;
2589 }
2590 } else if (del_timer_sync(&tmp->work.timer)) {
2591 unsigned long new_end;
2592
2593 /*
2594 * In the software ROC case, cancel the timer, if
2595 * that fails then the finish work is already
2596 * queued/pending and thus we queue the new ROC
2597 * normally, if that succeeds then we can extend
2598 * the timer duration and TX the frame (if any.)
2599 */
2600
2601 list_add_tail(&roc->list, &tmp->dependents);
2602 queued = true;
2603
2604 new_end = jiffies + msecs_to_jiffies(roc->duration);
2605
2606 /* ok, it was started & we canceled timer */
2607 if (time_after(new_end, tmp->work.timer.expires))
2608 mod_timer(&tmp->work.timer, new_end);
2609 else
2610 add_timer(&tmp->work.timer);
2611
2612 ieee80211_handle_roc_started(roc);
2613 }
2614 break;
2615 }
2616
2617 out_queue:
2618 if (!queued)
2619 list_add_tail(&roc->list, &local->roc_list);
2620
2621 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002622 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002623 * or the SKB (for mgmt TX)
2624 */
Johannes Berg50febf62012-10-26 16:13:06 +02002625 if (!txskb) {
2626 /* local->mtx protects this */
2627 local->roc_cookie_counter++;
2628 roc->cookie = local->roc_cookie_counter;
2629 /* wow, you wrapped 64 bits ... more likely a bug */
2630 if (WARN_ON(roc->cookie == 0)) {
2631 roc->cookie = 1;
2632 local->roc_cookie_counter++;
2633 }
2634 *cookie = roc->cookie;
2635 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002636 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002637 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002638
2639 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002640}
2641
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002642static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002643 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002644 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002645 unsigned int duration,
2646 u64 *cookie)
2647{
Johannes Berg71bbc992012-06-15 15:30:18 +02002648 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002649 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002650 int ret;
2651
Johannes Berg2eb278e2012-06-05 14:28:42 +02002652 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002653 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002654 duration, cookie, NULL,
2655 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002656 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002657
Johannes Berg2eb278e2012-06-05 14:28:42 +02002658 return ret;
2659}
2660
2661static int ieee80211_cancel_roc(struct ieee80211_local *local,
2662 u64 cookie, bool mgmt_tx)
2663{
2664 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2665 int ret;
2666
2667 mutex_lock(&local->mtx);
2668 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002669 struct ieee80211_roc_work *dep, *tmp2;
2670
2671 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002672 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002673 continue;
2674 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2675 continue;
2676 /* found dependent item -- just remove it */
2677 list_del(&dep->list);
2678 mutex_unlock(&local->mtx);
2679
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002680 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002681 return 0;
2682 }
2683
Johannes Berg50febf62012-10-26 16:13:06 +02002684 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002685 continue;
2686 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2687 continue;
2688
2689 found = roc;
2690 break;
2691 }
2692
2693 if (!found) {
2694 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002695 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002696 }
Johannes Berg21f83582010-12-18 17:20:47 +01002697
Johannes Berge979e332012-06-11 17:09:41 +02002698 /*
2699 * We found the item to cancel, so do that. Note that it
2700 * may have dependents, which we also cancel (and send
2701 * the expired signal for.) Not doing so would be quite
2702 * tricky here, but we may need to fix it later.
2703 */
2704
Johannes Berg2eb278e2012-06-05 14:28:42 +02002705 if (local->ops->remain_on_channel) {
2706 if (found->started) {
2707 ret = drv_cancel_remain_on_channel(local);
2708 if (WARN_ON_ONCE(ret)) {
2709 mutex_unlock(&local->mtx);
2710 return ret;
2711 }
2712 }
Johannes Berg21f83582010-12-18 17:20:47 +01002713
Johannes Berg2eb278e2012-06-05 14:28:42 +02002714 list_del(&found->list);
2715
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002716 if (found->started)
2717 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002718 mutex_unlock(&local->mtx);
2719
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002720 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002721 } else {
2722 /* work may be pending so use it all the time */
2723 found->abort = true;
2724 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2725
2726 mutex_unlock(&local->mtx);
2727
2728 /* work will clean up etc */
2729 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002730 WARN_ON(!found->to_be_freed);
2731 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002732 }
Johannes Berg21f83582010-12-18 17:20:47 +01002733
Johannes Berg21f83582010-12-18 17:20:47 +01002734 return 0;
2735}
2736
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002737static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002738 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002739 u64 cookie)
2740{
Johannes Berg71bbc992012-06-15 15:30:18 +02002741 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002742 struct ieee80211_local *local = sdata->local;
2743
Johannes Berg2eb278e2012-06-05 14:28:42 +02002744 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002745}
2746
Simon Wunderlich164eb022013-02-08 18:16:20 +01002747static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2748 struct net_device *dev,
2749 struct cfg80211_chan_def *chandef)
2750{
2751 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2752 struct ieee80211_local *local = sdata->local;
2753 unsigned long timeout;
2754 int err;
2755
2756 if (!list_empty(&local->roc_list) || local->scanning)
2757 return -EBUSY;
2758
2759 /* whatever, but channel contexts should not complain about that one */
2760 sdata->smps_mode = IEEE80211_SMPS_OFF;
2761 sdata->needed_rx_chains = local->rx_chains;
2762 sdata->radar_required = true;
2763
2764 mutex_lock(&local->iflist_mtx);
2765 err = ieee80211_vif_use_channel(sdata, chandef,
2766 IEEE80211_CHANCTX_SHARED);
2767 mutex_unlock(&local->iflist_mtx);
2768 if (err)
2769 return err;
2770
2771 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2772 ieee80211_queue_delayed_work(&sdata->local->hw,
2773 &sdata->dfs_cac_timer_work, timeout);
2774
2775 return 0;
2776}
2777
Johannes Berg71bbc992012-06-15 15:30:18 +02002778static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002779 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01002780 unsigned int wait, const u8 *buf, size_t len,
2781 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002782{
Johannes Berg71bbc992012-06-15 15:30:18 +02002783 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002784 struct ieee80211_local *local = sdata->local;
2785 struct sk_buff *skb;
2786 struct sta_info *sta;
2787 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002788 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002789 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002790 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002791
Johannes Berge247bd902011-11-04 11:18:21 +01002792 if (dont_wait_for_ack)
2793 flags = IEEE80211_TX_CTL_NO_ACK;
2794 else
2795 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2796 IEEE80211_TX_CTL_REQ_TX_STATUS;
2797
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302798 if (no_cck)
2799 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2800
Johannes Berg9d38d852010-06-09 17:20:33 +02002801 switch (sdata->vif.type) {
2802 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002803 if (!sdata->vif.bss_conf.ibss_joined)
2804 need_offchan = true;
2805 /* fall through */
2806#ifdef CONFIG_MAC80211_MESH
2807 case NL80211_IFTYPE_MESH_POINT:
2808 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2809 !sdata->u.mesh.mesh_id_len)
2810 need_offchan = true;
2811 /* fall through */
2812#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002813 case NL80211_IFTYPE_AP:
2814 case NL80211_IFTYPE_AP_VLAN:
2815 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002816 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2817 !ieee80211_vif_is_mesh(&sdata->vif) &&
2818 !rcu_access_pointer(sdata->bss->beacon))
2819 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002820 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07002821 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
2822 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED)
Johannes Berg9d38d852010-06-09 17:20:33 +02002823 break;
2824 rcu_read_lock();
2825 sta = sta_info_get(sdata, mgmt->da);
2826 rcu_read_unlock();
2827 if (!sta)
2828 return -ENOLINK;
2829 break;
2830 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002831 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002832 if (!sdata->u.mgd.associated)
2833 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002834 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002835 case NL80211_IFTYPE_P2P_DEVICE:
2836 need_offchan = true;
2837 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002838 default:
2839 return -EOPNOTSUPP;
2840 }
2841
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002842 /* configurations requiring offchan cannot work if no channel has been
2843 * specified
2844 */
2845 if (need_offchan && !chan)
2846 return -EINVAL;
2847
Johannes Berg2eb278e2012-06-05 14:28:42 +02002848 mutex_lock(&local->mtx);
2849
2850 /* Check if the operating channel is the requested channel */
2851 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02002852 struct ieee80211_chanctx_conf *chanctx_conf;
2853
2854 rcu_read_lock();
2855 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2856
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002857 if (chanctx_conf) {
2858 need_offchan = chan && (chan != chanctx_conf->def.chan);
2859 } else if (!chan) {
2860 ret = -EINVAL;
2861 rcu_read_unlock();
2862 goto out_unlock;
2863 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002864 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002865 }
Johannes Berg55de9082012-07-26 17:24:39 +02002866 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02002867 }
2868
2869 if (need_offchan && !offchan) {
2870 ret = -EBUSY;
2871 goto out_unlock;
2872 }
2873
Johannes Berg9d38d852010-06-09 17:20:33 +02002874 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002875 if (!skb) {
2876 ret = -ENOMEM;
2877 goto out_unlock;
2878 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002879 skb_reserve(skb, local->hw.extra_tx_headroom);
2880
2881 memcpy(skb_put(skb, len), buf, len);
2882
2883 IEEE80211_SKB_CB(skb)->flags = flags;
2884
Johannes Berg2eb278e2012-06-05 14:28:42 +02002885 skb->dev = sdata->dev;
2886
2887 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002888 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002889 ieee80211_tx_skb(sdata, skb);
2890 ret = 0;
2891 goto out_unlock;
2892 }
2893
Seth Forshee6c17b772013-02-11 11:21:07 -06002894 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
2895 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002896 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002897 IEEE80211_SKB_CB(skb)->hw_queue =
2898 local->hw.offchannel_tx_hw_queue;
2899
Johannes Berg2eb278e2012-06-05 14:28:42 +02002900 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01002901 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002902 wait, cookie, skb,
2903 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002904 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002905 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002906 out_unlock:
2907 mutex_unlock(&local->mtx);
2908 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002909}
2910
Johannes Bergf30221e2010-11-25 10:02:30 +01002911static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002912 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002913 u64 cookie)
2914{
Johannes Berg71bbc992012-06-15 15:30:18 +02002915 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002916
Johannes Berg2eb278e2012-06-05 14:28:42 +02002917 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002918}
2919
Johannes Berg7be50862010-10-13 12:06:24 +02002920static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002921 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002922 u16 frame_type, bool reg)
2923{
2924 struct ieee80211_local *local = wiphy_priv(wiphy);
2925
Will Hawkins6abe0562012-06-20 11:51:14 -04002926 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04002927 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2928 if (reg)
2929 local->probe_req_reg++;
2930 else
2931 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002932
Felix Fietkau35f51492012-10-31 15:50:34 +01002933 if (!local->open_count)
2934 break;
2935
Will Hawkins6abe0562012-06-20 11:51:14 -04002936 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2937 break;
2938 default:
2939 break;
2940 }
Johannes Berg7be50862010-10-13 12:06:24 +02002941}
2942
Bruno Randolf15d96752010-11-10 12:50:56 +09002943static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2944{
2945 struct ieee80211_local *local = wiphy_priv(wiphy);
2946
2947 if (local->started)
2948 return -EOPNOTSUPP;
2949
2950 return drv_set_antenna(local, tx_ant, rx_ant);
2951}
2952
2953static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2954{
2955 struct ieee80211_local *local = wiphy_priv(wiphy);
2956
2957 return drv_get_antenna(local, tx_ant, rx_ant);
2958}
2959
John W. Linville38c09152011-03-07 16:19:18 -05002960static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2961{
2962 struct ieee80211_local *local = wiphy_priv(wiphy);
2963
2964 return drv_set_ringparam(local, tx, rx);
2965}
2966
2967static void ieee80211_get_ringparam(struct wiphy *wiphy,
2968 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2969{
2970 struct ieee80211_local *local = wiphy_priv(wiphy);
2971
2972 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2973}
2974
Johannes Bergc68f4b82011-07-05 16:35:41 +02002975static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2976 struct net_device *dev,
2977 struct cfg80211_gtk_rekey_data *data)
2978{
2979 struct ieee80211_local *local = wiphy_priv(wiphy);
2980 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2981
2982 if (!local->ops->set_rekey_data)
2983 return -EOPNOTSUPP;
2984
2985 drv_set_rekey_data(local, sdata, data);
2986
2987 return 0;
2988}
2989
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002990static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2991{
2992 u8 *pos = (void *)skb_put(skb, 7);
2993
2994 *pos++ = WLAN_EID_EXT_CAPABILITY;
2995 *pos++ = 5; /* len */
2996 *pos++ = 0x0;
2997 *pos++ = 0x0;
2998 *pos++ = 0x0;
2999 *pos++ = 0x0;
3000 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
3001}
3002
3003static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
3004{
3005 struct ieee80211_local *local = sdata->local;
3006 u16 capab;
3007
3008 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003009 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003010 return capab;
3011
3012 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3013 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3014 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3015 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3016
3017 return capab;
3018}
3019
3020static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3021 u8 *peer, u8 *bssid)
3022{
3023 struct ieee80211_tdls_lnkie *lnkid;
3024
3025 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3026
3027 lnkid->ie_type = WLAN_EID_LINK_ID;
3028 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3029
3030 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3031 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3032 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3033}
3034
3035static int
3036ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3037 u8 *peer, u8 action_code, u8 dialog_token,
3038 u16 status_code, struct sk_buff *skb)
3039{
3040 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003041 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003042 struct ieee80211_tdls_data *tf;
3043
3044 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3045
3046 memcpy(tf->da, peer, ETH_ALEN);
3047 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3048 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3049 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3050
3051 switch (action_code) {
3052 case WLAN_TDLS_SETUP_REQUEST:
3053 tf->category = WLAN_CATEGORY_TDLS;
3054 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3055
3056 skb_put(skb, sizeof(tf->u.setup_req));
3057 tf->u.setup_req.dialog_token = dialog_token;
3058 tf->u.setup_req.capability =
3059 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3060
Johannes Berg55de9082012-07-26 17:24:39 +02003061 ieee80211_add_srates_ie(sdata, skb, false, band);
3062 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003063 ieee80211_tdls_add_ext_capab(skb);
3064 break;
3065 case WLAN_TDLS_SETUP_RESPONSE:
3066 tf->category = WLAN_CATEGORY_TDLS;
3067 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3068
3069 skb_put(skb, sizeof(tf->u.setup_resp));
3070 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3071 tf->u.setup_resp.dialog_token = dialog_token;
3072 tf->u.setup_resp.capability =
3073 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3074
Johannes Berg55de9082012-07-26 17:24:39 +02003075 ieee80211_add_srates_ie(sdata, skb, false, band);
3076 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003077 ieee80211_tdls_add_ext_capab(skb);
3078 break;
3079 case WLAN_TDLS_SETUP_CONFIRM:
3080 tf->category = WLAN_CATEGORY_TDLS;
3081 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3082
3083 skb_put(skb, sizeof(tf->u.setup_cfm));
3084 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3085 tf->u.setup_cfm.dialog_token = dialog_token;
3086 break;
3087 case WLAN_TDLS_TEARDOWN:
3088 tf->category = WLAN_CATEGORY_TDLS;
3089 tf->action_code = WLAN_TDLS_TEARDOWN;
3090
3091 skb_put(skb, sizeof(tf->u.teardown));
3092 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3093 break;
3094 case WLAN_TDLS_DISCOVERY_REQUEST:
3095 tf->category = WLAN_CATEGORY_TDLS;
3096 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3097
3098 skb_put(skb, sizeof(tf->u.discover_req));
3099 tf->u.discover_req.dialog_token = dialog_token;
3100 break;
3101 default:
3102 return -EINVAL;
3103 }
3104
3105 return 0;
3106}
3107
3108static int
3109ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3110 u8 *peer, u8 action_code, u8 dialog_token,
3111 u16 status_code, struct sk_buff *skb)
3112{
3113 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003114 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003115 struct ieee80211_mgmt *mgmt;
3116
3117 mgmt = (void *)skb_put(skb, 24);
3118 memset(mgmt, 0, 24);
3119 memcpy(mgmt->da, peer, ETH_ALEN);
3120 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3121 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3122
3123 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3124 IEEE80211_STYPE_ACTION);
3125
3126 switch (action_code) {
3127 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3128 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3129 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3130 mgmt->u.action.u.tdls_discover_resp.action_code =
3131 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3132 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3133 dialog_token;
3134 mgmt->u.action.u.tdls_discover_resp.capability =
3135 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3136
Johannes Berg55de9082012-07-26 17:24:39 +02003137 ieee80211_add_srates_ie(sdata, skb, false, band);
3138 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003139 ieee80211_tdls_add_ext_capab(skb);
3140 break;
3141 default:
3142 return -EINVAL;
3143 }
3144
3145 return 0;
3146}
3147
3148static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3149 u8 *peer, u8 action_code, u8 dialog_token,
3150 u16 status_code, const u8 *extra_ies,
3151 size_t extra_ies_len)
3152{
3153 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3154 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003155 struct sk_buff *skb = NULL;
3156 bool send_direct;
3157 int ret;
3158
3159 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3160 return -ENOTSUPP;
3161
3162 /* make sure we are in managed mode, and associated */
3163 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3164 !sdata->u.mgd.associated)
3165 return -EINVAL;
3166
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003167 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3168 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003169
3170 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3171 max(sizeof(struct ieee80211_mgmt),
3172 sizeof(struct ieee80211_tdls_data)) +
3173 50 + /* supported rates */
3174 7 + /* ext capab */
3175 extra_ies_len +
3176 sizeof(struct ieee80211_tdls_lnkie));
3177 if (!skb)
3178 return -ENOMEM;
3179
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003180 skb_reserve(skb, local->hw.extra_tx_headroom);
3181
3182 switch (action_code) {
3183 case WLAN_TDLS_SETUP_REQUEST:
3184 case WLAN_TDLS_SETUP_RESPONSE:
3185 case WLAN_TDLS_SETUP_CONFIRM:
3186 case WLAN_TDLS_TEARDOWN:
3187 case WLAN_TDLS_DISCOVERY_REQUEST:
3188 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3189 action_code, dialog_token,
3190 status_code, skb);
3191 send_direct = false;
3192 break;
3193 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3194 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3195 dialog_token, status_code,
3196 skb);
3197 send_direct = true;
3198 break;
3199 default:
3200 ret = -ENOTSUPP;
3201 break;
3202 }
3203
3204 if (ret < 0)
3205 goto fail;
3206
3207 if (extra_ies_len)
3208 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3209
3210 /* the TDLS link IE is always added last */
3211 switch (action_code) {
3212 case WLAN_TDLS_SETUP_REQUEST:
3213 case WLAN_TDLS_SETUP_CONFIRM:
3214 case WLAN_TDLS_TEARDOWN:
3215 case WLAN_TDLS_DISCOVERY_REQUEST:
3216 /* we are the initiator */
3217 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3218 sdata->u.mgd.bssid);
3219 break;
3220 case WLAN_TDLS_SETUP_RESPONSE:
3221 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3222 /* we are the responder */
3223 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3224 sdata->u.mgd.bssid);
3225 break;
3226 default:
3227 ret = -ENOTSUPP;
3228 goto fail;
3229 }
3230
3231 if (send_direct) {
3232 ieee80211_tx_skb(sdata, skb);
3233 return 0;
3234 }
3235
3236 /*
3237 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3238 * we should default to AC_VI.
3239 */
3240 switch (action_code) {
3241 case WLAN_TDLS_SETUP_REQUEST:
3242 case WLAN_TDLS_SETUP_RESPONSE:
3243 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3244 skb->priority = 2;
3245 break;
3246 default:
3247 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3248 skb->priority = 5;
3249 break;
3250 }
3251
3252 /* disable bottom halves when entering the Tx path */
3253 local_bh_disable();
3254 ret = ieee80211_subif_start_xmit(skb, dev);
3255 local_bh_enable();
3256
3257 return ret;
3258
3259fail:
3260 dev_kfree_skb(skb);
3261 return ret;
3262}
3263
3264static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3265 u8 *peer, enum nl80211_tdls_operation oper)
3266{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003267 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003268 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3269
3270 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3271 return -ENOTSUPP;
3272
3273 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3274 return -EINVAL;
3275
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003276 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003277
3278 switch (oper) {
3279 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003280 rcu_read_lock();
3281 sta = sta_info_get(sdata, peer);
3282 if (!sta) {
3283 rcu_read_unlock();
3284 return -ENOLINK;
3285 }
3286
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003287 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003288 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003289 break;
3290 case NL80211_TDLS_DISABLE_LINK:
3291 return sta_info_destroy_addr(sdata, peer);
3292 case NL80211_TDLS_TEARDOWN:
3293 case NL80211_TDLS_SETUP:
3294 case NL80211_TDLS_DISCOVERY_REQ:
3295 /* We don't support in-driver setup/teardown/discovery */
3296 return -ENOTSUPP;
3297 default:
3298 return -ENOTSUPP;
3299 }
3300
3301 return 0;
3302}
3303
Johannes Berg06500732011-11-04 11:18:16 +01003304static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3305 const u8 *peer, u64 *cookie)
3306{
3307 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3308 struct ieee80211_local *local = sdata->local;
3309 struct ieee80211_qos_hdr *nullfunc;
3310 struct sk_buff *skb;
3311 int size = sizeof(*nullfunc);
3312 __le16 fc;
3313 bool qos;
3314 struct ieee80211_tx_info *info;
3315 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003316 struct ieee80211_chanctx_conf *chanctx_conf;
3317 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003318
3319 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003320 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3321 if (WARN_ON(!chanctx_conf)) {
3322 rcu_read_unlock();
3323 return -EINVAL;
3324 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003325 band = chanctx_conf->def.chan->band;
Johannes Berg06500732011-11-04 11:18:16 +01003326 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003327 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003328 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003329 } else {
3330 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003331 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003332 }
Johannes Berg06500732011-11-04 11:18:16 +01003333
3334 if (qos) {
3335 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3336 IEEE80211_STYPE_QOS_NULLFUNC |
3337 IEEE80211_FCTL_FROMDS);
3338 } else {
3339 size -= 2;
3340 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3341 IEEE80211_STYPE_NULLFUNC |
3342 IEEE80211_FCTL_FROMDS);
3343 }
3344
3345 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003346 if (!skb) {
3347 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003348 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003349 }
Johannes Berg06500732011-11-04 11:18:16 +01003350
3351 skb->dev = dev;
3352
3353 skb_reserve(skb, local->hw.extra_tx_headroom);
3354
3355 nullfunc = (void *) skb_put(skb, size);
3356 nullfunc->frame_control = fc;
3357 nullfunc->duration_id = 0;
3358 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3359 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3360 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3361 nullfunc->seq_ctrl = 0;
3362
3363 info = IEEE80211_SKB_CB(skb);
3364
3365 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3366 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3367
3368 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3369 skb->priority = 7;
3370 if (qos)
3371 nullfunc->qos_ctrl = cpu_to_le16(7);
3372
3373 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003374 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003375 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003376 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003377
3378 *cookie = (unsigned long) skb;
3379 return 0;
3380}
3381
Johannes Berg683b6d32012-11-08 21:25:48 +01003382static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3383 struct wireless_dev *wdev,
3384 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003385{
Johannes Berg55de9082012-07-26 17:24:39 +02003386 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003387 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003388 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003389 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003390
Johannes Berg55de9082012-07-26 17:24:39 +02003391 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003392 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3393 if (chanctx_conf) {
3394 *chandef = chanctx_conf->def;
3395 ret = 0;
3396 } else if (local->open_count > 0 &&
3397 local->open_count == local->monitors &&
3398 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3399 if (local->use_chanctx)
3400 *chandef = local->monitor_chandef;
3401 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003402 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003403 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003404 }
3405 rcu_read_unlock();
3406
Johannes Berg683b6d32012-11-08 21:25:48 +01003407 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003408}
3409
Johannes Berg6d525632012-04-04 15:05:25 +02003410#ifdef CONFIG_PM
3411static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3412{
3413 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3414}
3415#endif
3416
Jiri Bencf0706e82007-05-05 11:45:53 -07003417struct cfg80211_ops mac80211_config_ops = {
3418 .add_virtual_intf = ieee80211_add_iface,
3419 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003420 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003421 .start_p2p_device = ieee80211_start_p2p_device,
3422 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003423 .add_key = ieee80211_add_key,
3424 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003425 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003426 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003427 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003428 .start_ap = ieee80211_start_ap,
3429 .change_beacon = ieee80211_change_beacon,
3430 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003431 .add_station = ieee80211_add_station,
3432 .del_station = ieee80211_del_station,
3433 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003434 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003435 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003436 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003437#ifdef CONFIG_MAC80211_MESH
3438 .add_mpath = ieee80211_add_mpath,
3439 .del_mpath = ieee80211_del_mpath,
3440 .change_mpath = ieee80211_change_mpath,
3441 .get_mpath = ieee80211_get_mpath,
3442 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003443 .update_mesh_config = ieee80211_update_mesh_config,
3444 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003445 .join_mesh = ieee80211_join_mesh,
3446 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003447#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003448 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003449 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003450 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003451 .suspend = ieee80211_suspend,
3452 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003453 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003454 .sched_scan_start = ieee80211_sched_scan_start,
3455 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003456 .auth = ieee80211_auth,
3457 .assoc = ieee80211_assoc,
3458 .deauth = ieee80211_deauth,
3459 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003460 .join_ibss = ieee80211_join_ibss,
3461 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003462 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003463 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003464 .set_tx_power = ieee80211_set_tx_power,
3465 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003466 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003467 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003468 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003469 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003470 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003471 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003472 .remain_on_channel = ieee80211_remain_on_channel,
3473 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003474 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003475 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003476 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003477 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003478 .set_antenna = ieee80211_set_antenna,
3479 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003480 .set_ringparam = ieee80211_set_ringparam,
3481 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003482 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003483 .tdls_oper = ieee80211_tdls_oper,
3484 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003485 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003486 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003487#ifdef CONFIG_PM
3488 .set_wakeup = ieee80211_set_wakeup,
3489#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003490 .get_et_sset_count = ieee80211_get_et_sset_count,
3491 .get_et_stats = ieee80211_get_et_stats,
3492 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003493 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003494 .start_radar_detection = ieee80211_start_radar_detection,
Jiri Bencf0706e82007-05-05 11:45:53 -07003495};