blob: 8184d121ff0904a285529ff234f75c3f15f522e5 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg552bff02012-09-19 09:26:06 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
24 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020025 enum nl80211_iftype type,
26 u32 *flags,
27 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070028{
29 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020030 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010031 struct ieee80211_sub_if_data *sdata;
32 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg84efbb82012-06-16 00:00:26 +020034 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010035 if (err)
36 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010037
Johannes Bergf9e10ce2010-12-03 09:20:42 +010038 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020039 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 sdata->u.mntr_flags = *flags;
41 }
42
Johannes Berg84efbb82012-06-16 00:00:26 +020043 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070044}
45
Johannes Berg84efbb82012-06-16 00:00:26 +020046static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070047{
Johannes Berg84efbb82012-06-16 00:00:26 +020048 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Johannes Berg75636522008-07-09 14:40:35 +020050 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070051}
52
Johannes Berge36d56b2009-06-09 21:04:43 +020053static int ieee80211_change_iface(struct wiphy *wiphy,
54 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010055 enum nl80211_iftype type, u32 *flags,
56 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020057{
Johannes Berg9607e6b2009-12-23 13:15:31 +010058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020060
Johannes Berg05c914f2008-09-11 00:01:58 +020061 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020062 if (ret)
63 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020064
Johannes Berg9bc383d2009-11-19 11:55:19 +010065 if (type == NL80211_IFTYPE_AP_VLAN &&
66 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000067 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010068 else if (type == NL80211_IFTYPE_STATION &&
69 params && params->use_4addr >= 0)
70 sdata->u.mgd.use_4addr = params->use_4addr;
71
Christian Lamparter85416a42010-10-02 13:17:07 +020072 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
73 struct ieee80211_local *local = sdata->local;
74
75 if (ieee80211_sdata_running(sdata)) {
Felix Fietkau31eba5b2013-05-28 13:01:53 +020076 u32 mask = MONITOR_FLAG_COOK_FRAMES |
77 MONITOR_FLAG_ACTIVE;
78
Christian Lamparter85416a42010-10-02 13:17:07 +020079 /*
Felix Fietkau31eba5b2013-05-28 13:01:53 +020080 * Prohibit MONITOR_FLAG_COOK_FRAMES and
81 * MONITOR_FLAG_ACTIVE to be changed while the
82 * interface is up.
Christian Lamparter85416a42010-10-02 13:17:07 +020083 * Else we would need to add a lot of cruft
84 * to update everything:
85 * cooked_mntrs, monitor and all fif_* counters
86 * reconfigure hardware
87 */
Felix Fietkau31eba5b2013-05-28 13:01:53 +020088 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
Christian Lamparter85416a42010-10-02 13:17:07 +020089 return -EBUSY;
90
91 ieee80211_adjust_monitor_flags(sdata, -1);
92 sdata->u.mntr_flags = *flags;
93 ieee80211_adjust_monitor_flags(sdata, 1);
94
95 ieee80211_configure_filter(local);
96 } else {
97 /*
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
101 */
102 sdata->u.mntr_flags = *flags;
103 }
104 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200105
Johannes Berg42613db2007-09-28 21:52:27 +0200106 return 0;
107}
108
Johannes Bergf142c6b2012-06-18 20:07:15 +0200109static int ieee80211_start_p2p_device(struct wiphy *wiphy,
110 struct wireless_dev *wdev)
111{
112 return ieee80211_do_open(wdev, true);
113}
114
115static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
116 struct wireless_dev *wdev)
117{
118 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
119}
120
Simon Wunderlichb53be792011-11-18 14:20:44 +0100121static int ieee80211_set_noack_map(struct wiphy *wiphy,
122 struct net_device *dev,
123 u16 noack_map)
124{
125 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
126
127 sdata->noack_map = noack_map;
128 return 0;
129}
130
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100131static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200132 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100133 struct key_params *params)
134{
Johannes Berg26a58452010-08-27 12:35:55 +0200135 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100136 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100137 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200138 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100139
Johannes Berg26a58452010-08-27 12:35:55 +0200140 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200141 return -ENETDOWN;
142
Johannes Berg97359d12010-08-10 09:46:38 +0200143 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100144 switch (params->cipher) {
145 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100146 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200147 case WLAN_CIPHER_SUITE_WEP104:
148 if (IS_ERR(sdata->local->wep_tx_tfm))
149 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200150 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100151 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200152 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100153 }
154
Johannes Berg97359d12010-08-10 09:46:38 +0200155 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
156 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100157 if (IS_ERR(key))
158 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100159
Johannes Berge31b8212010-10-05 19:39:30 +0200160 if (pairwise)
161 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
162
Johannes Bergad0e2b52010-06-01 10:19:19 +0200163 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200164
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100165 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700166 if (ieee80211_vif_is_mesh(&sdata->vif))
167 sta = sta_info_get(sdata, mac_addr);
168 else
169 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100170 /*
171 * The ASSOC test makes sure the driver is ready to
172 * receive the key. When wpa_supplicant has roamed
173 * using FT, it attempts to set the key before
174 * association has completed, this rejects that attempt
175 * so it will set the key again after assocation.
176 *
177 * TODO: accept the key if we have a station entry and
178 * add it to the device after the station.
179 */
180 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100181 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200182 err = -ENOENT;
183 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100184 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100185 }
186
Johannes Berge548c492012-09-04 17:08:23 +0200187 switch (sdata->vif.type) {
188 case NL80211_IFTYPE_STATION:
189 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
190 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
191 break;
192 case NL80211_IFTYPE_AP:
193 case NL80211_IFTYPE_AP_VLAN:
194 /* Keys without a station are used for TX only */
195 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
196 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
197 break;
198 case NL80211_IFTYPE_ADHOC:
199 /* no MFP (yet) */
200 break;
201 case NL80211_IFTYPE_MESH_POINT:
202#ifdef CONFIG_MAC80211_MESH
203 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
204 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
205 break;
206#endif
207 case NL80211_IFTYPE_WDS:
208 case NL80211_IFTYPE_MONITOR:
209 case NL80211_IFTYPE_P2P_DEVICE:
210 case NL80211_IFTYPE_UNSPECIFIED:
211 case NUM_NL80211_IFTYPES:
212 case NL80211_IFTYPE_P2P_CLIENT:
213 case NL80211_IFTYPE_P2P_GO:
214 /* shouldn't happen */
215 WARN_ON_ONCE(1);
216 break;
217 }
218
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300219 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100220
Johannes Berg3b967662008-04-08 17:56:52 +0200221 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200222 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200223
224 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100225}
226
227static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200228 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100229{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200230 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
231 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100232 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200233 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100234 int ret;
235
Johannes Berg5c0c3642011-05-12 14:31:49 +0200236 mutex_lock(&local->sta_mtx);
237 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200238
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100239 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200240 ret = -ENOENT;
241
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100242 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100243 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200244 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100245
Johannes Berg5c0c3642011-05-12 14:31:49 +0200246 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200247 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200248 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200249 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200250 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200251 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100252
Johannes Berg5c0c3642011-05-12 14:31:49 +0200253 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200254 ret = -ENOENT;
255 goto out_unlock;
256 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100257
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100258 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100259
Johannes Berg3b967662008-04-08 17:56:52 +0200260 ret = 0;
261 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200262 mutex_unlock(&local->key_mtx);
263 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200264
265 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100266}
267
Johannes Berg62da92f2007-12-19 02:03:31 +0100268static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200269 u8 key_idx, bool pairwise, const u8 *mac_addr,
270 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100271 void (*callback)(void *cookie,
272 struct key_params *params))
273{
Johannes Berg14db74b2008-07-29 13:22:52 +0200274 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100275 struct sta_info *sta = NULL;
276 u8 seq[6] = {0};
277 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200278 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200279 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100280 u32 iv32;
281 u16 iv16;
282 int err = -ENOENT;
283
Johannes Berg14db74b2008-07-29 13:22:52 +0200284 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
285
Johannes Berg3b967662008-04-08 17:56:52 +0200286 rcu_read_lock();
287
Johannes Berg62da92f2007-12-19 02:03:31 +0100288 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100289 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100290 if (!sta)
291 goto out;
292
Johannes Berge31b8212010-10-05 19:39:30 +0200293 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200294 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200295 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200296 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100297 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200298 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100299
300 if (!key)
301 goto out;
302
303 memset(&params, 0, sizeof(params));
304
Johannes Berg97359d12010-08-10 09:46:38 +0200305 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100306
Johannes Berg97359d12010-08-10 09:46:38 +0200307 switch (key->conf.cipher) {
308 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700309 iv32 = key->u.tkip.tx.iv32;
310 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100311
Johannes Berg24487982009-04-23 18:52:52 +0200312 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
313 drv_get_tkip_seq(sdata->local,
314 key->conf.hw_key_idx,
315 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100316
317 seq[0] = iv16 & 0xff;
318 seq[1] = (iv16 >> 8) & 0xff;
319 seq[2] = iv32 & 0xff;
320 seq[3] = (iv32 >> 8) & 0xff;
321 seq[4] = (iv32 >> 16) & 0xff;
322 seq[5] = (iv32 >> 24) & 0xff;
323 params.seq = seq;
324 params.seq_len = 6;
325 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200326 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200327 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
328 seq[0] = pn64;
329 seq[1] = pn64 >> 8;
330 seq[2] = pn64 >> 16;
331 seq[3] = pn64 >> 24;
332 seq[4] = pn64 >> 32;
333 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100334 params.seq = seq;
335 params.seq_len = 6;
336 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200337 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200338 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
339 seq[0] = pn64;
340 seq[1] = pn64 >> 8;
341 seq[2] = pn64 >> 16;
342 seq[3] = pn64 >> 24;
343 seq[4] = pn64 >> 32;
344 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200345 params.seq = seq;
346 params.seq_len = 6;
347 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100348 }
349
350 params.key = key->conf.key;
351 params.key_len = key->conf.keylen;
352
353 callback(cookie, &params);
354 err = 0;
355
356 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200357 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100358 return err;
359}
360
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100361static int ieee80211_config_default_key(struct wiphy *wiphy,
362 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100363 u8 key_idx, bool uni,
364 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100365{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200366 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100367
Johannes Bergf7e01042010-12-09 19:49:02 +0100368 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100369
370 return 0;
371}
372
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200373static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
374 struct net_device *dev,
375 u8 key_idx)
376{
Johannes Berg66c52422010-07-22 13:58:51 +0200377 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200378
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200379 ieee80211_set_default_mgmt_key(sdata, key_idx);
380
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200381 return 0;
382}
383
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800384void sta_set_rate_info_tx(struct sta_info *sta,
385 const struct ieee80211_tx_rate *rate,
386 struct rate_info *rinfo)
387{
388 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100389 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800390 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100391 rinfo->mcs = rate->idx;
392 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
393 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
394 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
395 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
396 } else {
397 struct ieee80211_supported_band *sband;
398 sband = sta->local->hw.wiphy->bands[
399 ieee80211_get_sdata_band(sta->sdata)];
400 rinfo->legacy = sband->bitrates[rate->idx].bitrate;
401 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800402 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
403 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100404 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
405 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
406 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
407 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800408 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
409 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800410}
411
Saravana003e6762012-11-28 18:29:38 +0530412void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
413{
414 rinfo->flags = 0;
415
416 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
417 rinfo->flags |= RATE_INFO_FLAGS_MCS;
418 rinfo->mcs = sta->last_rx_rate_idx;
419 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
420 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
421 rinfo->nss = sta->last_rx_rate_vht_nss;
422 rinfo->mcs = sta->last_rx_rate_idx;
423 } else {
424 struct ieee80211_supported_band *sband;
425
426 sband = sta->local->hw.wiphy->bands[
427 ieee80211_get_sdata_band(sta->sdata)];
428 rinfo->legacy =
429 sband->bitrates[sta->last_rx_rate_idx].bitrate;
430 }
431
432 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
433 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
434 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
435 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
436 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
437 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
438 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
439 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
440 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
441 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
442}
443
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100444static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
445{
Johannes Bergd0709a62008-02-25 16:27:46 +0100446 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300447 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530448 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100449 u64 packets = 0;
Felix Fietkauef0621e2013-04-22 16:29:31 +0200450 int i, ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100451
Johannes Bergf5ea9122009-08-07 16:17:38 +0200452 sinfo->generation = sdata->local->sta_generation;
453
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100454 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100455 STATION_INFO_RX_BYTES64 |
456 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200457 STATION_INFO_RX_PACKETS |
458 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900459 STATION_INFO_TX_RETRIES |
460 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700461 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100462 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700463 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530464 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200465 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800466 STATION_INFO_STA_FLAGS |
467 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530468
469 do_posix_clock_monotonic_gettime(&uptime);
470 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100471
472 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100473 sinfo->tx_bytes = 0;
474 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
475 sinfo->tx_bytes += sta->tx_bytes[ac];
476 packets += sta->tx_packets[ac];
477 }
478 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100479 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200480 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900481 sinfo->tx_retries = sta->tx_retry_count;
482 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700483 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800484 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100485
John W. Linville19deffb2009-12-08 17:10:13 -0500486 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
487 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900488 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300489 if (!local->ops->get_rssi ||
490 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
491 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900492 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100493 }
Felix Fietkauef0621e2013-04-22 16:29:31 +0200494 if (sta->chains) {
495 sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
496 STATION_INFO_CHAIN_SIGNAL_AVG;
497
498 sinfo->chains = sta->chains;
499 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
500 sinfo->chain_signal[i] = sta->chain_signal_last[i];
501 sinfo->chain_signal_avg[i] =
502 (s8) -ewma_read(&sta->chain_signal_avg[i]);
503 }
504 }
Henning Rogge420e7fa2008-12-11 22:04:19 +0100505
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800506 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530507 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100508
Johannes Berg902acc72008-02-23 15:17:19 +0100509 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100510#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100511 sinfo->filled |= STATION_INFO_LLID |
512 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100513 STATION_INFO_PLINK_STATE |
514 STATION_INFO_LOCAL_PM |
515 STATION_INFO_PEER_PM |
516 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100517
518 sinfo->llid = le16_to_cpu(sta->llid);
519 sinfo->plid = le16_to_cpu(sta->plid);
520 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700521 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
522 sinfo->filled |= STATION_INFO_T_OFFSET;
523 sinfo->t_offset = sta->t_offset;
524 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100525 sinfo->local_pm = sta->local_pm;
526 sinfo->peer_pm = sta->peer_pm;
527 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100528#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100529 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700530
531 sinfo->bss_param.flags = 0;
532 if (sdata->vif.bss_conf.use_cts_prot)
533 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
534 if (sdata->vif.bss_conf.use_short_preamble)
535 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
536 if (sdata->vif.bss_conf.use_short_slot)
537 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
538 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
539 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200540
541 sinfo->sta_flags.set = 0;
542 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
543 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
544 BIT(NL80211_STA_FLAG_WME) |
545 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100546 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200547 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100548 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200549 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
550 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
551 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
552 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
553 if (test_sta_flag(sta, WLAN_STA_WME))
554 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
555 if (test_sta_flag(sta, WLAN_STA_MFP))
556 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
557 if (test_sta_flag(sta, WLAN_STA_AUTH))
558 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200559 if (test_sta_flag(sta, WLAN_STA_ASSOC))
560 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100561 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
562 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100563}
564
Ben Greearb1ab7922012-04-23 12:50:30 -0700565static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
566 "rx_packets", "rx_bytes", "wep_weak_iv_count",
567 "rx_duplicates", "rx_fragments", "rx_dropped",
568 "tx_packets", "tx_bytes", "tx_fragments",
569 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700570 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
571 "channel", "noise", "ch_time", "ch_time_busy",
572 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700573};
574#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
575
576static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
577 struct net_device *dev,
578 int sset)
579{
Ben Greeare3521142012-04-23 12:50:31 -0700580 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
581 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700582
Ben Greeare3521142012-04-23 12:50:31 -0700583 if (sset == ETH_SS_STATS)
584 rv += STA_STATS_LEN;
585
586 rv += drv_get_et_sset_count(sdata, sset);
587
588 if (rv == 0)
589 return -EOPNOTSUPP;
590 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700591}
592
593static void ieee80211_get_et_stats(struct wiphy *wiphy,
594 struct net_device *dev,
595 struct ethtool_stats *stats,
596 u64 *data)
597{
598 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200599 struct ieee80211_chanctx_conf *chanctx_conf;
600 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700601 struct sta_info *sta;
602 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700603 struct station_info sinfo;
604 struct survey_info survey;
605 int i, q;
606#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700607
608 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
609
610#define ADD_STA_STATS(sta) \
611 do { \
612 data[i++] += sta->rx_packets; \
613 data[i++] += sta->rx_bytes; \
614 data[i++] += sta->wep_weak_iv_count; \
615 data[i++] += sta->num_duplicates; \
616 data[i++] += sta->rx_fragments; \
617 data[i++] += sta->rx_dropped; \
618 \
Johannes Berg560d2682013-02-05 10:55:21 +0100619 data[i++] += sinfo.tx_packets; \
620 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700621 data[i++] += sta->tx_fragments; \
622 data[i++] += sta->tx_filtered_count; \
623 data[i++] += sta->tx_retry_failed; \
624 data[i++] += sta->tx_retry_count; \
625 data[i++] += sta->beacon_loss_count; \
626 } while (0)
627
628 /* For Managed stations, find the single station based on BSSID
629 * and use that. For interface types, iterate through all available
630 * stations and add stats for any station that is assigned to this
631 * network device.
632 */
633
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300634 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700635
636 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
637 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700638
639 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
640 goto do_survey;
641
Johannes Berg560d2682013-02-05 10:55:21 +0100642 sinfo.filled = 0;
643 sta_set_sinfo(sta, &sinfo);
644
Ben Greear3073a7c2012-04-23 12:50:32 -0700645 i = 0;
646 ADD_STA_STATS(sta);
647
648 data[i++] = sta->sta_state;
649
Ben Greear3073a7c2012-04-23 12:50:32 -0700650
Joe Perches52042672012-05-30 13:25:54 -0700651 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700652 data[i] = 100000 *
653 cfg80211_calculate_bitrate(&sinfo.txrate);
654 i++;
Joe Perches52042672012-05-30 13:25:54 -0700655 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700656 data[i] = 100000 *
657 cfg80211_calculate_bitrate(&sinfo.rxrate);
658 i++;
659
Joe Perches52042672012-05-30 13:25:54 -0700660 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700661 data[i] = (u8)sinfo.signal_avg;
662 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700663 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300664 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700665 /* Make sure this station belongs to the proper dev */
666 if (sta->sdata->dev != dev)
667 continue;
668
669 i = 0;
670 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700671 }
672 }
673
Ben Greear3073a7c2012-04-23 12:50:32 -0700674do_survey:
675 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
676 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200677 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700678
Johannes Berg55de9082012-07-26 17:24:39 +0200679 rcu_read_lock();
680 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
681 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100682 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200683 else
684 channel = NULL;
685 rcu_read_unlock();
686
687 if (channel) {
688 q = 0;
689 do {
690 survey.filled = 0;
691 if (drv_get_survey(local, q, &survey) != 0) {
692 survey.filled = 0;
693 break;
694 }
695 q++;
696 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700697 }
698
699 if (survey.filled)
700 data[i++] = survey.channel->center_freq;
701 else
702 data[i++] = 0;
703 if (survey.filled & SURVEY_INFO_NOISE_DBM)
704 data[i++] = (u8)survey.noise;
705 else
706 data[i++] = -1LL;
707 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
708 data[i++] = survey.channel_time;
709 else
710 data[i++] = -1LL;
711 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
712 data[i++] = survey.channel_time_busy;
713 else
714 data[i++] = -1LL;
715 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
716 data[i++] = survey.channel_time_ext_busy;
717 else
718 data[i++] = -1LL;
719 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
720 data[i++] = survey.channel_time_rx;
721 else
722 data[i++] = -1LL;
723 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
724 data[i++] = survey.channel_time_tx;
725 else
726 data[i++] = -1LL;
727
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300728 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700729
Ben Greear3073a7c2012-04-23 12:50:32 -0700730 if (WARN_ON(i != STA_STATS_LEN))
731 return;
732
Ben Greeare3521142012-04-23 12:50:31 -0700733 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700734}
735
736static void ieee80211_get_et_strings(struct wiphy *wiphy,
737 struct net_device *dev,
738 u32 sset, u8 *data)
739{
Ben Greeare3521142012-04-23 12:50:31 -0700740 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
741 int sz_sta_stats = 0;
742
Ben Greearb1ab7922012-04-23 12:50:30 -0700743 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700744 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Johannes Bergbd500af2013-05-06 21:09:46 +0200745 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700746 }
Ben Greeare3521142012-04-23 12:50:31 -0700747 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700748}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100749
750static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
751 int idx, u8 *mac, struct station_info *sinfo)
752{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100753 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300754 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100755 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100756 int ret = -ENOENT;
757
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300758 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100759
Johannes Berg3b53fde82009-11-16 12:00:37 +0100760 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100761 if (sta) {
762 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200763 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100764 sta_set_sinfo(sta, sinfo);
765 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100766
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300767 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100768
Johannes Bergd0709a62008-02-25 16:27:46 +0100769 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100770}
771
Holger Schurig12897232010-04-19 10:23:57 +0200772static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
773 int idx, struct survey_info *survey)
774{
775 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
776
Holger Schurig12897232010-04-19 10:23:57 +0200777 return drv_get_survey(local, idx, survey);
778}
779
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100780static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100781 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100782{
Johannes Bergabe60632009-11-25 17:46:18 +0100783 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300784 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100785 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100786 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100787
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300788 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100789
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100790 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100791 if (sta) {
792 ret = 0;
793 sta_set_sinfo(sta, sinfo);
794 }
795
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300796 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100797
798 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100799}
800
Johannes Berge8c9bd52012-06-06 08:18:22 +0200801static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100802 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200803{
Johannes Berg55de9082012-07-26 17:24:39 +0200804 struct ieee80211_local *local = wiphy_priv(wiphy);
805 struct ieee80211_sub_if_data *sdata;
806 int ret = 0;
807
Johannes Berg4bf88532012-11-09 11:39:59 +0100808 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200809 return 0;
810
811 mutex_lock(&local->iflist_mtx);
812 if (local->use_chanctx) {
813 sdata = rcu_dereference_protected(
814 local->monitor_sdata,
815 lockdep_is_held(&local->iflist_mtx));
816 if (sdata) {
817 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100818 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200819 IEEE80211_CHANCTX_EXCLUSIVE);
820 }
821 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100822 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200823 ieee80211_hw_config(local, 0);
824 }
825
Johannes Berg4bf88532012-11-09 11:39:59 +0100826 if (ret == 0)
827 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200828 mutex_unlock(&local->iflist_mtx);
829
830 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200831}
832
Arik Nemtsov02945822011-11-10 11:28:57 +0200833static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100834 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200835{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300836 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200837
838 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530839 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200840
Arik Nemtsovf7248282011-11-19 10:51:26 +0200841 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200842
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300843 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200844 if (!new)
845 return -ENOMEM;
846
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300847 new->len = resp_len;
848 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200849
850 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300851 if (old)
852 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200853
854 return 0;
855}
856
Johannes Berg88600202012-02-13 15:17:18 +0100857static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
858 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100859{
860 struct beacon_data *new, *old;
861 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100862 int size, err;
863 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100864
Johannes Berg40b275b2011-05-13 14:15:49 +0200865 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100866
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100867 /* Need to have a beacon head if we don't have one yet */
868 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100869 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100870
871 /* new or old head? */
872 if (params->head)
873 new_head_len = params->head_len;
874 else
875 new_head_len = old->head_len;
876
877 /* new or old tail? */
878 if (params->tail || !old)
879 /* params->tail_len will be zero for !params->tail */
880 new_tail_len = params->tail_len;
881 else
882 new_tail_len = old->tail_len;
883
884 size = sizeof(*new) + new_head_len + new_tail_len;
885
886 new = kzalloc(size, GFP_KERNEL);
887 if (!new)
888 return -ENOMEM;
889
890 /* start filling the new info now */
891
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100892 /*
893 * pointers go into the block we allocated,
894 * memory is | beacon_data | head | tail |
895 */
896 new->head = ((u8 *) new) + sizeof(*new);
897 new->tail = new->head + new_head_len;
898 new->head_len = new_head_len;
899 new->tail_len = new_tail_len;
900
901 /* copy in head */
902 if (params->head)
903 memcpy(new->head, params->head, new_head_len);
904 else
905 memcpy(new->head, old->head, new_head_len);
906
907 /* copy in optional tail */
908 if (params->tail)
909 memcpy(new->tail, params->tail, new_tail_len);
910 else
911 if (old)
912 memcpy(new->tail, old->tail, new_tail_len);
913
Johannes Berg88600202012-02-13 15:17:18 +0100914 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
915 params->probe_resp_len);
916 if (err < 0)
917 return err;
918 if (err == 0)
919 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100920
Eric Dumazetcf778b02012-01-12 04:41:32 +0000921 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100922
Johannes Berg88600202012-02-13 15:17:18 +0100923 if (old)
924 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100925
Johannes Berg88600202012-02-13 15:17:18 +0100926 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100927}
928
Johannes Berg88600202012-02-13 15:17:18 +0100929static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
930 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100931{
Johannes Berg88600202012-02-13 15:17:18 +0100932 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100933 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100934 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100935 u32 changed = BSS_CHANGED_BEACON_INT |
936 BSS_CHANGED_BEACON_ENABLED |
937 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100938 BSS_CHANGED_SSID |
939 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100940 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200941
Johannes Berg40b275b2011-05-13 14:15:49 +0200942 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100943 if (old)
944 return -EALREADY;
945
Johannes Berg04ecd252012-09-11 14:34:12 +0200946 /* TODO: make hostapd tell us what it wants */
947 sdata->smps_mode = IEEE80211_SMPS_OFF;
948 sdata->needed_rx_chains = sdata->local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +0100949 sdata->radar_required = params->radar_required;
Johannes Berg04ecd252012-09-11 14:34:12 +0200950
Johannes Berg4bf88532012-11-09 11:39:59 +0100951 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200952 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200953 if (err)
954 return err;
Johannes Berg1f4ac5a2013-02-08 12:07:44 +0100955 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Bergaa430da2012-05-16 23:50:18 +0200956
Johannes Berg665c93a2011-11-04 11:18:11 +0100957 /*
958 * Apply control port protocol, this allows us to
959 * not encrypt dynamic WEP control frames.
960 */
961 sdata->control_port_protocol = params->crypto.control_port_ethertype;
962 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
963 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
964 vlan->control_port_protocol =
965 params->crypto.control_port_ethertype;
966 vlan->control_port_no_encrypt =
967 params->crypto.control_port_no_encrypt;
968 }
969
Johannes Berg88600202012-02-13 15:17:18 +0100970 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
971 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100972 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100973
974 sdata->vif.bss_conf.ssid_len = params->ssid_len;
975 if (params->ssid_len)
976 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
977 params->ssid_len);
978 sdata->vif.bss_conf.hidden_ssid =
979 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
980
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100981 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
982 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
983 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
984 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
985 if (params->p2p_opp_ps)
986 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
987 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100988
Johannes Berg88600202012-02-13 15:17:18 +0100989 err = ieee80211_assign_beacon(sdata, &params->beacon);
990 if (err < 0)
991 return err;
992 changed |= err;
993
Johannes Berg10416382012-10-19 15:44:42 +0200994 err = drv_start_ap(sdata->local, sdata);
995 if (err) {
996 old = rtnl_dereference(sdata->u.ap.beacon);
997 if (old)
998 kfree_rcu(old, rcu_head);
999 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
1000 return err;
1001 }
1002
Johannes Berg88600202012-02-13 15:17:18 +01001003 ieee80211_bss_info_change_notify(sdata, changed);
1004
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001005 netif_carrier_on(dev);
1006 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1007 netif_carrier_on(vlan->dev);
1008
Johannes Berg665c93a2011-11-04 11:18:11 +01001009 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001010}
1011
Johannes Berg88600202012-02-13 15:17:18 +01001012static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1013 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001014{
Johannes Berg14db74b2008-07-29 13:22:52 +02001015 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001016 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001017 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001018
Johannes Berg14db74b2008-07-29 13:22:52 +02001019 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1020
Johannes Berg40b275b2011-05-13 14:15:49 +02001021 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001022 if (!old)
1023 return -ENOENT;
1024
Johannes Berg88600202012-02-13 15:17:18 +01001025 err = ieee80211_assign_beacon(sdata, params);
1026 if (err < 0)
1027 return err;
1028 ieee80211_bss_info_change_notify(sdata, err);
1029 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001030}
1031
Johannes Berg88600202012-02-13 15:17:18 +01001032static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001033{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001034 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1035 struct ieee80211_sub_if_data *vlan;
1036 struct ieee80211_local *local = sdata->local;
1037 struct beacon_data *old_beacon;
1038 struct probe_resp *old_probe_resp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001039
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001040 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1041 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001042 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001043 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001044
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001045 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001046 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1047 netif_carrier_off(vlan->dev);
1048 netif_carrier_off(dev);
1049
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001050 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001051 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001052 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1053 kfree_rcu(old_beacon, rcu_head);
1054 if (old_probe_resp)
1055 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001056
Felix Fietkau2d4072a2012-12-10 20:02:34 +01001057 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
Johannes Berg75de9112012-12-14 14:56:03 +01001058 sta_info_flush_defer(vlan);
1059 sta_info_flush_defer(sdata);
Bob Copeland8ceb5952013-04-18 18:26:49 -04001060 synchronize_net();
Johannes Berg75de9112012-12-14 14:56:03 +01001061 rcu_barrier();
Johannes Berg7b4396b2013-02-23 01:14:20 +01001062 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
Johannes Berg75de9112012-12-14 14:56:03 +01001063 sta_info_flush_cleanup(vlan);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001064 ieee80211_free_keys(vlan);
1065 }
Johannes Berg75de9112012-12-14 14:56:03 +01001066 sta_info_flush_cleanup(sdata);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001067 ieee80211_free_keys(sdata);
Johannes Berg75de9112012-12-14 14:56:03 +01001068
Johannes Bergd6a83222012-12-14 14:06:28 +01001069 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001070 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001071 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001072 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001073
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001074 if (sdata->wdev.cac_started) {
1075 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
1076 cfg80211_cac_event(sdata->dev, NL80211_RADAR_CAC_ABORTED,
1077 GFP_KERNEL);
1078 }
1079
Johannes Berg10416382012-10-19 15:44:42 +02001080 drv_stop_ap(sdata->local, sdata);
1081
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001082 /* free all potentially still buffered bcast frames */
1083 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1084 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1085
Johannes Berg1f4ac5a2013-02-08 12:07:44 +01001086 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001087 ieee80211_vif_release_channel(sdata);
1088
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001089 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001090}
1091
Johannes Berg4fd69312007-12-19 02:03:35 +01001092/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1093struct iapp_layer2_update {
1094 u8 da[ETH_ALEN]; /* broadcast */
1095 u8 sa[ETH_ALEN]; /* STA addr */
1096 __be16 len; /* 6 */
1097 u8 dsap; /* 0 */
1098 u8 ssap; /* 0 */
1099 u8 control;
1100 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001101} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001102
1103static void ieee80211_send_layer2_update(struct sta_info *sta)
1104{
1105 struct iapp_layer2_update *msg;
1106 struct sk_buff *skb;
1107
1108 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1109 * bridge devices */
1110
1111 skb = dev_alloc_skb(sizeof(*msg));
1112 if (!skb)
1113 return;
1114 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1115
1116 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1117 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1118
Johannes Berge83e6542012-07-13 16:23:07 +02001119 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001120 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001121 msg->len = htons(6);
1122 msg->dsap = 0;
1123 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1124 msg->control = 0xaf; /* XID response lsb.1111F101.
1125 * F=0 (no poll command; unsolicited frame) */
1126 msg->xid_info[0] = 0x81; /* XID format identifier */
1127 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1128 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1129
Johannes Bergd0709a62008-02-25 16:27:46 +01001130 skb->dev = sta->sdata->dev;
1131 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001132 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001133 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001134}
1135
Johannes Bergd582cff2012-10-26 17:53:44 +02001136static int sta_apply_auth_flags(struct ieee80211_local *local,
1137 struct sta_info *sta,
1138 u32 mask, u32 set)
1139{
1140 int ret;
1141
1142 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1143 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1144 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1145 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1146 if (ret)
1147 return ret;
1148 }
1149
1150 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1151 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1152 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1153 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1154 if (ret)
1155 return ret;
1156 }
1157
1158 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1159 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1160 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1161 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1162 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1163 else
1164 ret = 0;
1165 if (ret)
1166 return ret;
1167 }
1168
1169 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1170 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1171 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1172 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1173 if (ret)
1174 return ret;
1175 }
1176
1177 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1178 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1179 test_sta_flag(sta, WLAN_STA_AUTH)) {
1180 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1181 if (ret)
1182 return ret;
1183 }
1184
1185 return 0;
1186}
1187
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001188static int sta_apply_parameters(struct ieee80211_local *local,
1189 struct sta_info *sta,
1190 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001191{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001192 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001193 u32 rates;
1194 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +01001195 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001196 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001197 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001198 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001199
Johannes Berg55de9082012-07-26 17:24:39 +02001200 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001201
Johannes Bergeccb8e82009-05-11 21:57:56 +03001202 mask = params->sta_flags_mask;
1203 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001204
Johannes Bergd582cff2012-10-26 17:53:44 +02001205 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1206 /*
1207 * In mesh mode, ASSOCIATED isn't part of the nl80211
1208 * API but must follow AUTHENTICATED for driver state.
1209 */
1210 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1211 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1212 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1213 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001214 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1215 /*
1216 * TDLS -- everything follows authorized, but
1217 * only becoming authorized is possible, not
1218 * going back
1219 */
1220 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1221 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1222 BIT(NL80211_STA_FLAG_ASSOCIATED);
1223 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1224 BIT(NL80211_STA_FLAG_ASSOCIATED);
1225 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001226 }
1227
Johannes Bergd582cff2012-10-26 17:53:44 +02001228 ret = sta_apply_auth_flags(local, sta, mask, set);
1229 if (ret)
1230 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001231
Johannes Bergeccb8e82009-05-11 21:57:56 +03001232 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001233 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001234 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1235 else
1236 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001237 }
1238
1239 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001240 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001241 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001242 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001243 } else {
1244 clear_sta_flag(sta, WLAN_STA_WME);
1245 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001246 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001247 }
1248
1249 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001250 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001251 set_sta_flag(sta, WLAN_STA_MFP);
1252 else
1253 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001254 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001255
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001256 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001257 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001258 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1259 else
1260 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001261 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001262
Johannes Berg3b9ce802011-09-27 20:56:12 +02001263 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1264 sta->sta.uapsd_queues = params->uapsd_queues;
1265 sta->sta.max_sp = params->max_sp;
1266 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001267
Johannes Berg73651ee2008-02-25 16:27:47 +01001268 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001269 * cfg80211 validates this (1-2007) and allows setting the AID
1270 * only when creating a new station entry
1271 */
1272 if (params->aid)
1273 sta->sta.aid = params->aid;
1274
1275 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001276 * Some of the following updates would be racy if called on an
1277 * existing station, via ieee80211_change_station(). However,
1278 * all such changes are rejected by cfg80211 except for updates
1279 * changing the supported rates on an existing but not yet used
1280 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001281 */
1282
Johannes Berg4fd69312007-12-19 02:03:35 +01001283 if (params->listen_interval >= 0)
1284 sta->listen_interval = params->listen_interval;
1285
1286 if (params->supported_rates) {
1287 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001288
Johannes Berg4fd69312007-12-19 02:03:35 +01001289 for (i = 0; i < params->supported_rates_len; i++) {
1290 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001291 for (j = 0; j < sband->n_bitrates; j++) {
1292 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001293 rates |= BIT(j);
1294 }
1295 }
Johannes Berg55de9082012-07-26 17:24:39 +02001296 sta->sta.supp_rates[band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001297 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001298
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001299 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001300 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001301 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001302
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001303 if (params->vht_capa)
1304 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001305 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001306
Javier Cardona9c3990a2011-05-03 16:57:11 -07001307 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001308#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001309 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001310
1311 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001312 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001313 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001314 if (sta->plink_state != NL80211_PLINK_ESTAB)
1315 changed = mesh_plink_inc_estab_count(
1316 sdata);
1317 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001318
1319 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001320 changed |= ieee80211_mps_set_sta_local_pm(sta,
1321 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001322 break;
1323 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001324 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001325 case NL80211_PLINK_OPN_SNT:
1326 case NL80211_PLINK_OPN_RCVD:
1327 case NL80211_PLINK_CNF_RCVD:
1328 case NL80211_PLINK_HOLDING:
1329 if (sta->plink_state == NL80211_PLINK_ESTAB)
1330 changed = mesh_plink_dec_estab_count(
1331 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001332 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001333
1334 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001335 changed |=
1336 ieee80211_mps_local_status_update(sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001337 break;
1338 default:
1339 /* nothing */
1340 break;
1341 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001342 }
1343
1344 switch (params->plink_action) {
1345 case NL80211_PLINK_ACTION_NO_ACTION:
1346 /* nothing */
1347 break;
1348 case NL80211_PLINK_ACTION_OPEN:
1349 changed |= mesh_plink_open(sta);
1350 break;
1351 case NL80211_PLINK_ACTION_BLOCK:
1352 changed |= mesh_plink_block(sta);
1353 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001354 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001355
1356 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001357 changed |=
1358 ieee80211_mps_set_sta_local_pm(sta,
1359 params->local_pm);
1360 ieee80211_bss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001361#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001362 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001363
1364 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001365}
1366
1367static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1368 u8 *mac, struct station_parameters *params)
1369{
Johannes Berg14db74b2008-07-29 13:22:52 +02001370 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001371 struct sta_info *sta;
1372 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001373 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001374 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001375
Johannes Berg4fd69312007-12-19 02:03:35 +01001376 if (params->vlan) {
1377 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1378
Johannes Berg05c914f2008-09-11 00:01:58 +02001379 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1380 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001381 return -EINVAL;
1382 } else
1383 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1384
Joe Perchesb203ca32012-05-08 18:56:52 +00001385 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001386 return -EINVAL;
1387
1388 if (is_multicast_ether_addr(mac))
1389 return -EINVAL;
1390
1391 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001392 if (!sta)
1393 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001394
Johannes Bergd582cff2012-10-26 17:53:44 +02001395 /*
1396 * defaults -- if userspace wants something else we'll
1397 * change it accordingly in sta_apply_parameters()
1398 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001399 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1400 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1401 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1402 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001403
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001404 err = sta_apply_parameters(local, sta, params);
1405 if (err) {
1406 sta_info_free(local, sta);
1407 return err;
1408 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001409
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001410 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001411 * for TDLS, rate control should be initialized only when
1412 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001413 */
1414 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1415 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001416
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001417 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1418 sdata->vif.type == NL80211_IFTYPE_AP;
1419
Johannes Berg34e89502010-02-03 13:59:58 +01001420 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001421 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001422 rcu_read_unlock();
1423 return err;
1424 }
1425
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001426 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001427 ieee80211_send_layer2_update(sta);
1428
1429 rcu_read_unlock();
1430
Johannes Berg4fd69312007-12-19 02:03:35 +01001431 return 0;
1432}
1433
1434static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1435 u8 *mac)
1436{
Johannes Berg14db74b2008-07-29 13:22:52 +02001437 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001438
Johannes Berg14db74b2008-07-29 13:22:52 +02001439 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1440
Johannes Berg34e89502010-02-03 13:59:58 +01001441 if (mac)
1442 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001443
Johannes Bergb998e8b2012-12-13 23:07:46 +01001444 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001445 return 0;
1446}
1447
1448static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001449 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001450 struct station_parameters *params)
1451{
Johannes Bergabe60632009-11-25 17:46:18 +01001452 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001453 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001454 struct sta_info *sta;
1455 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001456 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001457 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001458
Johannes Berg87be1e12011-12-14 12:20:29 +01001459 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001460
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001461 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001462 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001463 err = -ENOENT;
1464 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001465 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001466
Johannes Berg77ee7c82013-02-15 00:48:33 +01001467 switch (sdata->vif.type) {
1468 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001469 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001470 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001471 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001472 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001473 break;
1474 case NL80211_IFTYPE_ADHOC:
1475 statype = CFG80211_STA_IBSS;
1476 break;
1477 case NL80211_IFTYPE_STATION:
1478 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1479 statype = CFG80211_STA_AP_STA;
1480 break;
1481 }
1482 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1483 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1484 else
1485 statype = CFG80211_STA_TDLS_PEER_SETUP;
1486 break;
1487 case NL80211_IFTYPE_AP:
1488 case NL80211_IFTYPE_AP_VLAN:
1489 statype = CFG80211_STA_AP_CLIENT;
1490 break;
1491 default:
1492 err = -EOPNOTSUPP;
1493 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001494 }
1495
Johannes Berg77ee7c82013-02-15 00:48:33 +01001496 err = cfg80211_check_station_change(wiphy, params, statype);
1497 if (err)
1498 goto out_err;
1499
Johannes Bergd0709a62008-02-25 16:27:46 +01001500 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001501 bool prev_4addr = false;
1502 bool new_4addr = false;
1503
Johannes Berg4fd69312007-12-19 02:03:35 +01001504 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1505
Johannes Berg9bc383d2009-11-19 11:55:19 +01001506 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001507 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001508 err = -EBUSY;
1509 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001510 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001511
Eric Dumazetcf778b02012-01-12 04:41:32 +00001512 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001513 new_4addr = true;
1514 }
1515
1516 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1517 sta->sdata->u.vlan.sta) {
1518 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1519 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001520 }
1521
Johannes Berg14db74b2008-07-29 13:22:52 +02001522 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001523
1524 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1525 prev_4addr != new_4addr) {
1526 if (new_4addr)
1527 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1528 else
1529 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1530 }
1531
Johannes Berg4fd69312007-12-19 02:03:35 +01001532 ieee80211_send_layer2_update(sta);
1533 }
1534
Eliad Peller35b88622011-12-29 14:41:39 +02001535 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001536 if (err)
1537 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001538
Johannes Berg77ee7c82013-02-15 00:48:33 +01001539 /* When peer becomes authorized, init rate control as well */
1540 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1541 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001542 rate_control_rate_init(sta);
1543
Johannes Berg87be1e12011-12-14 12:20:29 +01001544 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001545
Jason Young808118c2011-03-10 16:43:19 -08001546 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001547 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001548 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001549 ieee80211_recalc_ps_vif(sdata);
1550 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001551
Johannes Berg4fd69312007-12-19 02:03:35 +01001552 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001553out_err:
1554 mutex_unlock(&local->sta_mtx);
1555 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001556}
1557
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001558#ifdef CONFIG_MAC80211_MESH
1559static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1560 u8 *dst, u8 *next_hop)
1561{
Johannes Berg14db74b2008-07-29 13:22:52 +02001562 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001563 struct mesh_path *mpath;
1564 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001565
Johannes Berg14db74b2008-07-29 13:22:52 +02001566 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1567
Johannes Bergd0709a62008-02-25 16:27:46 +01001568 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001569 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001570 if (!sta) {
1571 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001572 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001573 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001574
Bob Copelandae76eef2013-03-29 09:38:39 -04001575 mpath = mesh_path_add(sdata, dst);
1576 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001577 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001578 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001579 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001580
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001581 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001582
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001583 rcu_read_unlock();
1584 return 0;
1585}
1586
1587static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001588 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001589{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001590 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001591
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001592 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001593 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001594
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001595 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001596 return 0;
1597}
1598
1599static int ieee80211_change_mpath(struct wiphy *wiphy,
1600 struct net_device *dev,
1601 u8 *dst, u8 *next_hop)
1602{
Johannes Berg14db74b2008-07-29 13:22:52 +02001603 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001604 struct mesh_path *mpath;
1605 struct sta_info *sta;
1606
Johannes Berg14db74b2008-07-29 13:22:52 +02001607 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1608
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001609 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001610
Johannes Bergabe60632009-11-25 17:46:18 +01001611 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001612 if (!sta) {
1613 rcu_read_unlock();
1614 return -ENOENT;
1615 }
1616
Johannes Bergbf7cd942013-02-15 14:40:31 +01001617 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001618 if (!mpath) {
1619 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001620 return -ENOENT;
1621 }
1622
1623 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001624
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001625 rcu_read_unlock();
1626 return 0;
1627}
1628
1629static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1630 struct mpath_info *pinfo)
1631{
Johannes Berga3836e02011-05-12 15:11:37 +02001632 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1633
1634 if (next_hop_sta)
1635 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001636 else
1637 memset(next_hop, 0, ETH_ALEN);
1638
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001639 memset(pinfo, 0, sizeof(*pinfo));
1640
Johannes Bergf5ea9122009-08-07 16:17:38 +02001641 pinfo->generation = mesh_paths_generation;
1642
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001643 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001644 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001645 MPATH_INFO_METRIC |
1646 MPATH_INFO_EXPTIME |
1647 MPATH_INFO_DISCOVERY_TIMEOUT |
1648 MPATH_INFO_DISCOVERY_RETRIES |
1649 MPATH_INFO_FLAGS;
1650
1651 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001652 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001653 pinfo->metric = mpath->metric;
1654 if (time_before(jiffies, mpath->exp_time))
1655 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1656 pinfo->discovery_timeout =
1657 jiffies_to_msecs(mpath->discovery_timeout);
1658 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001659 if (mpath->flags & MESH_PATH_ACTIVE)
1660 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1661 if (mpath->flags & MESH_PATH_RESOLVING)
1662 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001663 if (mpath->flags & MESH_PATH_SN_VALID)
1664 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001665 if (mpath->flags & MESH_PATH_FIXED)
1666 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001667 if (mpath->flags & MESH_PATH_RESOLVED)
1668 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001669}
1670
1671static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1672 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1673
1674{
Johannes Berg14db74b2008-07-29 13:22:52 +02001675 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001676 struct mesh_path *mpath;
1677
Johannes Berg14db74b2008-07-29 13:22:52 +02001678 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1679
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001680 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001681 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001682 if (!mpath) {
1683 rcu_read_unlock();
1684 return -ENOENT;
1685 }
1686 memcpy(dst, mpath->dst, ETH_ALEN);
1687 mpath_set_pinfo(mpath, next_hop, pinfo);
1688 rcu_read_unlock();
1689 return 0;
1690}
1691
1692static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1693 int idx, u8 *dst, u8 *next_hop,
1694 struct mpath_info *pinfo)
1695{
Johannes Berg14db74b2008-07-29 13:22:52 +02001696 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001697 struct mesh_path *mpath;
1698
Johannes Berg14db74b2008-07-29 13:22:52 +02001699 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1700
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001701 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001702 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001703 if (!mpath) {
1704 rcu_read_unlock();
1705 return -ENOENT;
1706 }
1707 memcpy(dst, mpath->dst, ETH_ALEN);
1708 mpath_set_pinfo(mpath, next_hop, pinfo);
1709 rcu_read_unlock();
1710 return 0;
1711}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001712
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001713static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001714 struct net_device *dev,
1715 struct mesh_config *conf)
1716{
1717 struct ieee80211_sub_if_data *sdata;
1718 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1719
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001720 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1721 return 0;
1722}
1723
1724static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1725{
1726 return (mask >> (parm-1)) & 0x1;
1727}
1728
Javier Cardonac80d5452010-12-16 17:37:49 -08001729static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1730 const struct mesh_setup *setup)
1731{
1732 u8 *new_ie;
1733 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001734 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1735 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001736
Javier Cardona581a8b02011-04-07 15:08:27 -07001737 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001738 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001739 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001740
Javier Cardona581a8b02011-04-07 15:08:27 -07001741 if (setup->ie_len) {
1742 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001743 GFP_KERNEL);
1744 if (!new_ie)
1745 return -ENOMEM;
1746 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001747 ifmsh->ie_len = setup->ie_len;
1748 ifmsh->ie = new_ie;
1749 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001750
1751 /* now copy the rest of the setup parameters */
1752 ifmsh->mesh_id_len = setup->mesh_id_len;
1753 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001754 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001755 ifmsh->mesh_pp_id = setup->path_sel_proto;
1756 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001757 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001758 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001759 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1760 if (setup->is_authenticated)
1761 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1762 if (setup->is_secure)
1763 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001764
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001765 /* mcast rate setting in Mesh Node */
1766 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1767 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001768 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001769
Marco Porsch9bdbf042013-01-07 16:04:51 +01001770 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1771 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1772
Javier Cardonac80d5452010-12-16 17:37:49 -08001773 return 0;
1774}
1775
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001776static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001777 struct net_device *dev, u32 mask,
1778 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001779{
1780 struct mesh_config *conf;
1781 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001782 struct ieee80211_if_mesh *ifmsh;
1783
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001784 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001785 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001786
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001787 /* Set the config options which we are interested in setting */
1788 conf = &(sdata->u.mesh.mshcfg);
1789 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1790 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1791 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1792 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1793 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1794 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1795 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1796 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1797 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1798 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1799 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1800 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001801 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001802 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001803 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1804 if (ifmsh->user_mpm)
1805 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001806 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001807 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001808 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1809 conf->dot11MeshNbrOffsetMaxNeighbor =
1810 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001811 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1812 conf->dot11MeshHWMPmaxPREQretries =
1813 nconf->dot11MeshHWMPmaxPREQretries;
1814 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1815 conf->path_refresh_time = nconf->path_refresh_time;
1816 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1817 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1818 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1819 conf->dot11MeshHWMPactivePathTimeout =
1820 nconf->dot11MeshHWMPactivePathTimeout;
1821 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1822 conf->dot11MeshHWMPpreqMinInterval =
1823 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001824 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1825 conf->dot11MeshHWMPperrMinInterval =
1826 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001827 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1828 mask))
1829 conf->dot11MeshHWMPnetDiameterTraversalTime =
1830 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001831 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1832 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1833 ieee80211_mesh_root_setup(ifmsh);
1834 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001835 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001836 /* our current gate announcement implementation rides on root
1837 * announcements, so require this ifmsh to also be a root node
1838 * */
1839 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001840 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1841 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001842 ieee80211_mesh_root_setup(ifmsh);
1843 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001844 conf->dot11MeshGateAnnouncementProtocol =
1845 nconf->dot11MeshGateAnnouncementProtocol;
1846 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001847 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001848 conf->dot11MeshHWMPRannInterval =
1849 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001850 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1851 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001852 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1853 /* our RSSI threshold implementation is supported only for
1854 * devices that report signal in dBm.
1855 */
1856 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1857 return -ENOTSUPP;
1858 conf->rssi_threshold = nconf->rssi_threshold;
1859 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001860 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1861 conf->ht_opmode = nconf->ht_opmode;
1862 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1863 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1864 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001865 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1866 conf->dot11MeshHWMPactivePathToRootTimeout =
1867 nconf->dot11MeshHWMPactivePathToRootTimeout;
1868 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1869 conf->dot11MeshHWMProotInterval =
1870 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001871 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1872 conf->dot11MeshHWMPconfirmationInterval =
1873 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001874 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1875 conf->power_mode = nconf->power_mode;
1876 ieee80211_mps_local_status_update(sdata);
1877 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001878 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001879 conf->dot11MeshAwakeWindowDuration =
1880 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001881 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1882 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001883 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001884 return 0;
1885}
1886
Johannes Berg29cbe682010-12-03 09:20:44 +01001887static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1888 const struct mesh_config *conf,
1889 const struct mesh_setup *setup)
1890{
1891 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1892 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001893 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001894
Javier Cardonac80d5452010-12-16 17:37:49 -08001895 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1896 err = copy_mesh_setup(ifmsh, setup);
1897 if (err)
1898 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001899
Johannes Berg04ecd252012-09-11 14:34:12 +02001900 /* can mesh use other SMPS modes? */
1901 sdata->smps_mode = IEEE80211_SMPS_OFF;
1902 sdata->needed_rx_chains = sdata->local->rx_chains;
1903
Johannes Berg4bf88532012-11-09 11:39:59 +01001904 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001905 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001906 if (err)
1907 return err;
1908
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001909 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001910}
1911
1912static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1913{
1914 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1915
1916 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001917 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001918
1919 return 0;
1920}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001921#endif
1922
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001923static int ieee80211_change_bss(struct wiphy *wiphy,
1924 struct net_device *dev,
1925 struct bss_parameters *params)
1926{
Johannes Berg55de9082012-07-26 17:24:39 +02001927 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1928 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001929 u32 changed = 0;
1930
Johannes Berg55de9082012-07-26 17:24:39 +02001931 if (!rtnl_dereference(sdata->u.ap.beacon))
1932 return -ENOENT;
1933
1934 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001935
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001936 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001937 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001938 changed |= BSS_CHANGED_ERP_CTS_PROT;
1939 }
1940 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001941 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001942 params->use_short_preamble;
1943 changed |= BSS_CHANGED_ERP_PREAMBLE;
1944 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001945
1946 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001947 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001948 sdata->vif.bss_conf.use_short_slot = true;
1949 changed |= BSS_CHANGED_ERP_SLOT;
1950 }
1951
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001952 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001953 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001954 params->use_short_slot_time;
1955 changed |= BSS_CHANGED_ERP_SLOT;
1956 }
1957
Jouni Malinen90c97a02008-10-30 16:59:22 +02001958 if (params->basic_rates) {
1959 int i, j;
1960 u32 rates = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02001961 struct ieee80211_supported_band *sband = wiphy->bands[band];
Jouni Malinen90c97a02008-10-30 16:59:22 +02001962
1963 for (i = 0; i < params->basic_rates_len; i++) {
1964 int rate = (params->basic_rates[i] & 0x7f) * 5;
1965 for (j = 0; j < sband->n_bitrates; j++) {
1966 if (sband->bitrates[j].bitrate == rate)
1967 rates |= BIT(j);
1968 }
1969 }
1970 sdata->vif.bss_conf.basic_rates = rates;
1971 changed |= BSS_CHANGED_BASIC_RATES;
1972 }
1973
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001974 if (params->ap_isolate >= 0) {
1975 if (params->ap_isolate)
1976 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1977 else
1978 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1979 }
1980
Helmut Schaa80d7e402010-11-19 12:40:26 +01001981 if (params->ht_opmode >= 0) {
1982 sdata->vif.bss_conf.ht_operation_mode =
1983 (u16) params->ht_opmode;
1984 changed |= BSS_CHANGED_HT;
1985 }
1986
Johannes Berg339afbf2012-11-14 15:21:17 +01001987 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001988 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1989 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1990 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1991 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001992 changed |= BSS_CHANGED_P2P_PS;
1993 }
1994
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001995 if (params->p2p_opp_ps > 0) {
1996 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1997 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1998 changed |= BSS_CHANGED_P2P_PS;
1999 } else if (params->p2p_opp_ps == 0) {
2000 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2001 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002002 changed |= BSS_CHANGED_P2P_PS;
2003 }
2004
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002005 ieee80211_bss_info_change_notify(sdata, changed);
2006
2007 return 0;
2008}
2009
Jouni Malinen31888482008-10-30 16:59:24 +02002010static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002011 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002012 struct ieee80211_txq_params *params)
2013{
2014 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002015 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002016 struct ieee80211_tx_queue_params p;
2017
2018 if (!local->ops->conf_tx)
2019 return -EOPNOTSUPP;
2020
Johannes Berg54bcbc62012-03-28 11:04:25 +02002021 if (local->hw.queues < IEEE80211_NUM_ACS)
2022 return -EOPNOTSUPP;
2023
Jouni Malinen31888482008-10-30 16:59:24 +02002024 memset(&p, 0, sizeof(p));
2025 p.aifs = params->aifs;
2026 p.cw_max = params->cwmax;
2027 p.cw_min = params->cwmin;
2028 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002029
2030 /*
2031 * Setting tx queue params disables u-apsd because it's only
2032 * called in master mode.
2033 */
2034 p.uapsd = false;
2035
Johannes Berga3304b02012-03-28 11:04:24 +02002036 sdata->tx_conf[params->ac] = p;
2037 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002038 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002039 "failed to set TX queue parameters for AC %d\n",
2040 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002041 return -EINVAL;
2042 }
2043
Johannes Berg7d257452012-07-06 17:37:43 +02002044 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2045
Jouni Malinen31888482008-10-30 16:59:24 +02002046 return 0;
2047}
2048
Bob Copeland665af4f2009-01-19 11:20:53 -05002049#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002050static int ieee80211_suspend(struct wiphy *wiphy,
2051 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002052{
Johannes Bergeecc4802011-05-04 15:37:29 +02002053 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002054}
2055
2056static int ieee80211_resume(struct wiphy *wiphy)
2057{
2058 return __ieee80211_resume(wiphy_priv(wiphy));
2059}
2060#else
2061#define ieee80211_suspend NULL
2062#define ieee80211_resume NULL
2063#endif
2064
Johannes Berg2a519312009-02-10 21:25:55 +01002065static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002066 struct cfg80211_scan_request *req)
2067{
Johannes Bergfd014282012-06-18 19:17:03 +02002068 struct ieee80211_sub_if_data *sdata;
2069
2070 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002071
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002072 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2073 case NL80211_IFTYPE_STATION:
2074 case NL80211_IFTYPE_ADHOC:
2075 case NL80211_IFTYPE_MESH_POINT:
2076 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002077 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002078 break;
2079 case NL80211_IFTYPE_P2P_GO:
2080 if (sdata->local->ops->hw_scan)
2081 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002082 /*
2083 * FIXME: implement NoA while scanning in software,
2084 * for now fall through to allow scanning only when
2085 * beaconing hasn't been configured yet
2086 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002087 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002088 /*
2089 * If the scan has been forced (and the driver supports
2090 * forcing), don't care about being beaconing already.
2091 * This will create problems to the attached stations (e.g. all
2092 * the frames sent while scanning on other channel will be
2093 * lost)
2094 */
2095 if (sdata->u.ap.beacon &&
2096 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2097 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002098 return -EOPNOTSUPP;
2099 break;
2100 default:
2101 return -EOPNOTSUPP;
2102 }
Johannes Berg2a519312009-02-10 21:25:55 +01002103
2104 return ieee80211_request_scan(sdata, req);
2105}
2106
Luciano Coelho79f460c2011-05-11 17:09:36 +03002107static int
2108ieee80211_sched_scan_start(struct wiphy *wiphy,
2109 struct net_device *dev,
2110 struct cfg80211_sched_scan_request *req)
2111{
2112 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2113
2114 if (!sdata->local->ops->sched_scan_start)
2115 return -EOPNOTSUPP;
2116
2117 return ieee80211_request_sched_scan_start(sdata, req);
2118}
2119
2120static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002121ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002122{
2123 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2124
2125 if (!sdata->local->ops->sched_scan_stop)
2126 return -EOPNOTSUPP;
2127
Luciano Coelho85a99942011-05-12 16:28:29 +03002128 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002129}
2130
Jouni Malinen636a5d32009-03-19 13:39:22 +02002131static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2132 struct cfg80211_auth_request *req)
2133{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002134 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002135}
2136
2137static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2138 struct cfg80211_assoc_request *req)
2139{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002140 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002141}
2142
2143static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002144 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002145{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002146 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002147}
2148
2149static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002150 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002151{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002152 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002153}
2154
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002155static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2156 struct cfg80211_ibss_params *params)
2157{
Johannes Berg55de9082012-07-26 17:24:39 +02002158 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002159}
2160
2161static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2162{
Johannes Berg55de9082012-07-26 17:24:39 +02002163 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002164}
2165
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002166static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2167 int rate[IEEE80211_NUM_BANDS])
2168{
2169 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2170
Cong Ding9887dbf2013-02-06 17:23:45 +01002171 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2172 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002173
2174 return 0;
2175}
2176
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002177static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2178{
2179 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002180 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002181
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002182 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2183 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2184
2185 if (err)
2186 return err;
2187 }
2188
Lukáš Turek310bc672009-12-21 22:50:48 +01002189 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2190 err = drv_set_coverage_class(local, wiphy->coverage_class);
2191
2192 if (err)
2193 return err;
2194 }
2195
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002196 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002197 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002198
Johannes Berg24487982009-04-23 18:52:52 +02002199 if (err)
2200 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002201 }
2202
Johannes Berg8bc83c22012-11-09 18:38:32 +01002203 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2204 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2205 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002206 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002207 }
2208 if (changed & WIPHY_PARAM_RETRY_LONG) {
2209 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2210 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002211 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002212 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002213 if (changed &
2214 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2215 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2216
2217 return 0;
2218}
2219
Johannes Berg7643a2c2009-06-02 13:01:39 +02002220static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002221 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002222 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002223{
2224 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002225 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002226
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002227 if (wdev) {
2228 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2229
2230 switch (type) {
2231 case NL80211_TX_POWER_AUTOMATIC:
2232 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2233 break;
2234 case NL80211_TX_POWER_LIMITED:
2235 case NL80211_TX_POWER_FIXED:
2236 if (mbm < 0 || (mbm % 100))
2237 return -EOPNOTSUPP;
2238 sdata->user_power_level = MBM_TO_DBM(mbm);
2239 break;
2240 }
2241
2242 ieee80211_recalc_txpower(sdata);
2243
2244 return 0;
2245 }
Johannes Berg55de9082012-07-26 17:24:39 +02002246
Johannes Berg7643a2c2009-06-02 13:01:39 +02002247 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002248 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002249 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002250 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002251 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002252 case NL80211_TX_POWER_FIXED:
2253 if (mbm < 0 || (mbm % 100))
2254 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002255 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002256 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002257 }
2258
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002259 mutex_lock(&local->iflist_mtx);
2260 list_for_each_entry(sdata, &local->interfaces, list)
2261 sdata->user_power_level = local->user_power_level;
2262 list_for_each_entry(sdata, &local->interfaces, list)
2263 ieee80211_recalc_txpower(sdata);
2264 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002265
2266 return 0;
2267}
2268
Johannes Bergc8442112012-10-24 10:17:18 +02002269static int ieee80211_get_tx_power(struct wiphy *wiphy,
2270 struct wireless_dev *wdev,
2271 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002272{
2273 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002274 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002275
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002276 if (!local->use_chanctx)
2277 *dbm = local->hw.conf.power_level;
2278 else
2279 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002280
Johannes Berg7643a2c2009-06-02 13:01:39 +02002281 return 0;
2282}
2283
Johannes Bergab737a42009-07-01 21:26:58 +02002284static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002285 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002286{
2287 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2288
2289 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2290
2291 return 0;
2292}
2293
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002294static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2295{
2296 struct ieee80211_local *local = wiphy_priv(wiphy);
2297
2298 drv_rfkill_poll(local);
2299}
2300
Johannes Bergaff89a92009-07-01 21:26:51 +02002301#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002302static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002303{
2304 struct ieee80211_local *local = wiphy_priv(wiphy);
2305
2306 if (!local->ops->testmode_cmd)
2307 return -EOPNOTSUPP;
2308
2309 return local->ops->testmode_cmd(&local->hw, data, len);
2310}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002311
2312static int ieee80211_testmode_dump(struct wiphy *wiphy,
2313 struct sk_buff *skb,
2314 struct netlink_callback *cb,
2315 void *data, int len)
2316{
2317 struct ieee80211_local *local = wiphy_priv(wiphy);
2318
2319 if (!local->ops->testmode_dump)
2320 return -EOPNOTSUPP;
2321
2322 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2323}
Johannes Bergaff89a92009-07-01 21:26:51 +02002324#endif
2325
Johannes Berg0f782312009-12-01 13:37:02 +01002326int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2327 enum ieee80211_smps_mode smps_mode)
2328{
2329 const u8 *ap;
2330 enum ieee80211_smps_mode old_req;
2331 int err;
2332
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002333 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002334
Johannes Berg0f782312009-12-01 13:37:02 +01002335 old_req = sdata->u.mgd.req_smps;
2336 sdata->u.mgd.req_smps = smps_mode;
2337
2338 if (old_req == smps_mode &&
2339 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2340 return 0;
2341
2342 /*
2343 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002344 * association, there's no need to do anything, just store
2345 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002346 */
2347 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002348 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002349 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002350
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002351 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002352
2353 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2354 if (sdata->u.mgd.powersave)
2355 smps_mode = IEEE80211_SMPS_DYNAMIC;
2356 else
2357 smps_mode = IEEE80211_SMPS_OFF;
2358 }
2359
2360 /* send SM PS frame to AP */
2361 err = ieee80211_send_smps_action(sdata, smps_mode,
2362 ap, ap);
2363 if (err)
2364 sdata->u.mgd.req_smps = old_req;
2365
2366 return err;
2367}
2368
Johannes Bergbc92afd2009-07-01 21:26:57 +02002369static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2370 bool enabled, int timeout)
2371{
2372 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2373 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002374
Chun-Yeow Yeohee1f6682013-01-10 23:31:54 +08002375 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2376 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002377 return -EOPNOTSUPP;
2378
Johannes Bergbc92afd2009-07-01 21:26:57 +02002379 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2380 return -EOPNOTSUPP;
2381
2382 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002383 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002384 return 0;
2385
2386 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002387 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002388
Johannes Berg0f782312009-12-01 13:37:02 +01002389 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002390 sdata_lock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002391 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002392 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002393
Johannes Bergbc92afd2009-07-01 21:26:57 +02002394 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2395 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2396
2397 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002398 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002399
2400 return 0;
2401}
2402
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002403static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2404 struct net_device *dev,
2405 s32 rssi_thold, u32 rssi_hyst)
2406{
2407 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002408 struct ieee80211_vif *vif = &sdata->vif;
2409 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2410
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002411 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2412 rssi_hyst == bss_conf->cqm_rssi_hyst)
2413 return 0;
2414
2415 bss_conf->cqm_rssi_thold = rssi_thold;
2416 bss_conf->cqm_rssi_hyst = rssi_hyst;
2417
2418 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002419 if (sdata->u.mgd.associated &&
2420 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002421 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2422
2423 return 0;
2424}
2425
Johannes Berg99303802009-07-01 21:26:59 +02002426static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2427 struct net_device *dev,
2428 const u8 *addr,
2429 const struct cfg80211_bitrate_mask *mask)
2430{
2431 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2432 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302433 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002434
Eliad Peller554a43d2012-06-12 12:41:15 +03002435 if (!ieee80211_sdata_running(sdata))
2436 return -ENETDOWN;
2437
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302438 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2439 ret = drv_set_bitrate_mask(local, sdata, mask);
2440 if (ret)
2441 return ret;
2442 }
Johannes Berg99303802009-07-01 21:26:59 +02002443
Simon Wunderlich19468412012-01-28 17:25:33 +01002444 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002445 struct ieee80211_supported_band *sband = wiphy->bands[i];
2446 int j;
2447
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002448 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002449 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2450 sizeof(mask->control[i].mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002451
2452 sdata->rc_has_mcs_mask[i] = false;
2453 if (!sband)
2454 continue;
2455
2456 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2457 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2458 sdata->rc_has_mcs_mask[i] = true;
2459 break;
2460 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002461 }
Johannes Berg99303802009-07-01 21:26:59 +02002462
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002463 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002464}
2465
Johannes Berg2eb278e2012-06-05 14:28:42 +02002466static int ieee80211_start_roc_work(struct ieee80211_local *local,
2467 struct ieee80211_sub_if_data *sdata,
2468 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002469 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002470 struct sk_buff *txskb,
2471 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002472{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002473 struct ieee80211_roc_work *roc, *tmp;
2474 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002475 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002476
2477 lockdep_assert_held(&local->mtx);
2478
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002479 if (local->use_chanctx && !local->ops->remain_on_channel)
2480 return -EOPNOTSUPP;
2481
Johannes Berg2eb278e2012-06-05 14:28:42 +02002482 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2483 if (!roc)
2484 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002485
Johannes Berg2eb278e2012-06-05 14:28:42 +02002486 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002487 roc->duration = duration;
2488 roc->req_duration = duration;
2489 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002490 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002491 roc->mgmt_tx_cookie = (unsigned long)txskb;
2492 roc->sdata = sdata;
2493 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2494 INIT_LIST_HEAD(&roc->dependents);
2495
2496 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002497 if (!list_empty(&local->roc_list) ||
2498 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002499 goto out_check_combine;
2500
2501 /* if not HW assist, just queue & schedule work */
2502 if (!local->ops->remain_on_channel) {
2503 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2504 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002505 }
2506
Johannes Berg2eb278e2012-06-05 14:28:42 +02002507 /* otherwise actually kick it off here (for error handling) */
2508
2509 /*
2510 * If the duration is zero, then the driver
2511 * wouldn't actually do anything. Set it to
2512 * 10 for now.
2513 *
2514 * TODO: cancel the off-channel operation
2515 * when we get the SKB's TX status and
2516 * the wait time was zero before.
2517 */
2518 if (!duration)
2519 duration = 10;
2520
Ilan Peerd339d5c2013-02-12 09:34:13 +02002521 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002522 if (ret) {
2523 kfree(roc);
2524 return ret;
2525 }
2526
2527 roc->started = true;
2528 goto out_queue;
2529
2530 out_check_combine:
2531 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002532 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002533 continue;
2534
2535 /*
2536 * Extend this ROC if possible:
2537 *
2538 * If it hasn't started yet, just increase the duration
2539 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002540 * If the type of the new ROC has higher priority, modify the
2541 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002542 */
2543 if (!tmp->started) {
2544 list_add_tail(&roc->list, &tmp->dependents);
2545 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002546 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002547 queued = true;
2548 break;
2549 }
2550
2551 /* If it has already started, it's more difficult ... */
2552 if (local->ops->remain_on_channel) {
2553 unsigned long j = jiffies;
2554
2555 /*
2556 * In the offloaded ROC case, if it hasn't begun, add
2557 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002558 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002559 * check that there's still a minimum time left and
2560 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002561 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002562 * a reduced time so we'll ask the driver to execute
2563 * it right after finishing the previous one, in the
2564 * hope that it'll also be executed right afterwards,
2565 * effectively extending the old one.
2566 * If there's no minimum time left, just add it to the
2567 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002568 * TODO: the ROC type is ignored here, assuming that it
2569 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002570 */
2571 if (!tmp->hw_begun) {
2572 list_add_tail(&roc->list, &tmp->dependents);
2573 queued = true;
2574 break;
2575 }
2576
2577 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2578 tmp->hw_start_time +
2579 msecs_to_jiffies(tmp->duration))) {
2580 int new_dur;
2581
2582 ieee80211_handle_roc_started(roc);
2583
2584 new_dur = roc->duration -
2585 jiffies_to_msecs(tmp->hw_start_time +
2586 msecs_to_jiffies(
2587 tmp->duration) -
2588 j);
2589
2590 if (new_dur > 0) {
2591 /* add right after tmp */
2592 list_add(&roc->list, &tmp->list);
2593 } else {
2594 list_add_tail(&roc->list,
2595 &tmp->dependents);
2596 }
2597 queued = true;
2598 }
2599 } else if (del_timer_sync(&tmp->work.timer)) {
2600 unsigned long new_end;
2601
2602 /*
2603 * In the software ROC case, cancel the timer, if
2604 * that fails then the finish work is already
2605 * queued/pending and thus we queue the new ROC
2606 * normally, if that succeeds then we can extend
2607 * the timer duration and TX the frame (if any.)
2608 */
2609
2610 list_add_tail(&roc->list, &tmp->dependents);
2611 queued = true;
2612
2613 new_end = jiffies + msecs_to_jiffies(roc->duration);
2614
2615 /* ok, it was started & we canceled timer */
2616 if (time_after(new_end, tmp->work.timer.expires))
2617 mod_timer(&tmp->work.timer, new_end);
2618 else
2619 add_timer(&tmp->work.timer);
2620
2621 ieee80211_handle_roc_started(roc);
2622 }
2623 break;
2624 }
2625
2626 out_queue:
2627 if (!queued)
2628 list_add_tail(&roc->list, &local->roc_list);
2629
2630 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002631 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002632 * or the SKB (for mgmt TX)
2633 */
Johannes Berg50febf62012-10-26 16:13:06 +02002634 if (!txskb) {
2635 /* local->mtx protects this */
2636 local->roc_cookie_counter++;
2637 roc->cookie = local->roc_cookie_counter;
2638 /* wow, you wrapped 64 bits ... more likely a bug */
2639 if (WARN_ON(roc->cookie == 0)) {
2640 roc->cookie = 1;
2641 local->roc_cookie_counter++;
2642 }
2643 *cookie = roc->cookie;
2644 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002645 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002646 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002647
2648 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002649}
2650
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002651static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002652 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002653 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002654 unsigned int duration,
2655 u64 *cookie)
2656{
Johannes Berg71bbc992012-06-15 15:30:18 +02002657 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002658 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002659 int ret;
2660
Johannes Berg2eb278e2012-06-05 14:28:42 +02002661 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002662 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002663 duration, cookie, NULL,
2664 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002665 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002666
Johannes Berg2eb278e2012-06-05 14:28:42 +02002667 return ret;
2668}
2669
2670static int ieee80211_cancel_roc(struct ieee80211_local *local,
2671 u64 cookie, bool mgmt_tx)
2672{
2673 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2674 int ret;
2675
2676 mutex_lock(&local->mtx);
2677 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002678 struct ieee80211_roc_work *dep, *tmp2;
2679
2680 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002681 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002682 continue;
2683 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2684 continue;
2685 /* found dependent item -- just remove it */
2686 list_del(&dep->list);
2687 mutex_unlock(&local->mtx);
2688
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002689 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002690 return 0;
2691 }
2692
Johannes Berg50febf62012-10-26 16:13:06 +02002693 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002694 continue;
2695 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2696 continue;
2697
2698 found = roc;
2699 break;
2700 }
2701
2702 if (!found) {
2703 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002704 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002705 }
Johannes Berg21f83582010-12-18 17:20:47 +01002706
Johannes Berge979e332012-06-11 17:09:41 +02002707 /*
2708 * We found the item to cancel, so do that. Note that it
2709 * may have dependents, which we also cancel (and send
2710 * the expired signal for.) Not doing so would be quite
2711 * tricky here, but we may need to fix it later.
2712 */
2713
Johannes Berg2eb278e2012-06-05 14:28:42 +02002714 if (local->ops->remain_on_channel) {
2715 if (found->started) {
2716 ret = drv_cancel_remain_on_channel(local);
2717 if (WARN_ON_ONCE(ret)) {
2718 mutex_unlock(&local->mtx);
2719 return ret;
2720 }
2721 }
Johannes Berg21f83582010-12-18 17:20:47 +01002722
Johannes Berg2eb278e2012-06-05 14:28:42 +02002723 list_del(&found->list);
2724
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002725 if (found->started)
2726 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002727 mutex_unlock(&local->mtx);
2728
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002729 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002730 } else {
2731 /* work may be pending so use it all the time */
2732 found->abort = true;
2733 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2734
2735 mutex_unlock(&local->mtx);
2736
2737 /* work will clean up etc */
2738 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002739 WARN_ON(!found->to_be_freed);
2740 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002741 }
Johannes Berg21f83582010-12-18 17:20:47 +01002742
Johannes Berg21f83582010-12-18 17:20:47 +01002743 return 0;
2744}
2745
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002746static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002747 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002748 u64 cookie)
2749{
Johannes Berg71bbc992012-06-15 15:30:18 +02002750 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002751 struct ieee80211_local *local = sdata->local;
2752
Johannes Berg2eb278e2012-06-05 14:28:42 +02002753 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002754}
2755
Simon Wunderlich164eb022013-02-08 18:16:20 +01002756static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2757 struct net_device *dev,
2758 struct cfg80211_chan_def *chandef)
2759{
2760 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2761 struct ieee80211_local *local = sdata->local;
2762 unsigned long timeout;
2763 int err;
2764
2765 if (!list_empty(&local->roc_list) || local->scanning)
2766 return -EBUSY;
2767
2768 /* whatever, but channel contexts should not complain about that one */
2769 sdata->smps_mode = IEEE80211_SMPS_OFF;
2770 sdata->needed_rx_chains = local->rx_chains;
2771 sdata->radar_required = true;
2772
2773 mutex_lock(&local->iflist_mtx);
2774 err = ieee80211_vif_use_channel(sdata, chandef,
2775 IEEE80211_CHANCTX_SHARED);
2776 mutex_unlock(&local->iflist_mtx);
2777 if (err)
2778 return err;
2779
2780 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2781 ieee80211_queue_delayed_work(&sdata->local->hw,
2782 &sdata->dfs_cac_timer_work, timeout);
2783
2784 return 0;
2785}
2786
Johannes Berg71bbc992012-06-15 15:30:18 +02002787static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002788 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01002789 unsigned int wait, const u8 *buf, size_t len,
2790 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002791{
Johannes Berg71bbc992012-06-15 15:30:18 +02002792 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002793 struct ieee80211_local *local = sdata->local;
2794 struct sk_buff *skb;
2795 struct sta_info *sta;
2796 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002797 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002798 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002799 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002800
Johannes Berge247bd902011-11-04 11:18:21 +01002801 if (dont_wait_for_ack)
2802 flags = IEEE80211_TX_CTL_NO_ACK;
2803 else
2804 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2805 IEEE80211_TX_CTL_REQ_TX_STATUS;
2806
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302807 if (no_cck)
2808 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2809
Johannes Berg9d38d852010-06-09 17:20:33 +02002810 switch (sdata->vif.type) {
2811 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002812 if (!sdata->vif.bss_conf.ibss_joined)
2813 need_offchan = true;
2814 /* fall through */
2815#ifdef CONFIG_MAC80211_MESH
2816 case NL80211_IFTYPE_MESH_POINT:
2817 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2818 !sdata->u.mesh.mesh_id_len)
2819 need_offchan = true;
2820 /* fall through */
2821#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002822 case NL80211_IFTYPE_AP:
2823 case NL80211_IFTYPE_AP_VLAN:
2824 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002825 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2826 !ieee80211_vif_is_mesh(&sdata->vif) &&
2827 !rcu_access_pointer(sdata->bss->beacon))
2828 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002829 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07002830 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
2831 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED)
Johannes Berg9d38d852010-06-09 17:20:33 +02002832 break;
2833 rcu_read_lock();
2834 sta = sta_info_get(sdata, mgmt->da);
2835 rcu_read_unlock();
2836 if (!sta)
2837 return -ENOLINK;
2838 break;
2839 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002840 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002841 if (!sdata->u.mgd.associated)
2842 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002843 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002844 case NL80211_IFTYPE_P2P_DEVICE:
2845 need_offchan = true;
2846 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002847 default:
2848 return -EOPNOTSUPP;
2849 }
2850
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002851 /* configurations requiring offchan cannot work if no channel has been
2852 * specified
2853 */
2854 if (need_offchan && !chan)
2855 return -EINVAL;
2856
Johannes Berg2eb278e2012-06-05 14:28:42 +02002857 mutex_lock(&local->mtx);
2858
2859 /* Check if the operating channel is the requested channel */
2860 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02002861 struct ieee80211_chanctx_conf *chanctx_conf;
2862
2863 rcu_read_lock();
2864 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2865
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002866 if (chanctx_conf) {
2867 need_offchan = chan && (chan != chanctx_conf->def.chan);
2868 } else if (!chan) {
2869 ret = -EINVAL;
2870 rcu_read_unlock();
2871 goto out_unlock;
2872 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002873 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02002874 }
Johannes Berg55de9082012-07-26 17:24:39 +02002875 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02002876 }
2877
2878 if (need_offchan && !offchan) {
2879 ret = -EBUSY;
2880 goto out_unlock;
2881 }
2882
Johannes Berg9d38d852010-06-09 17:20:33 +02002883 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002884 if (!skb) {
2885 ret = -ENOMEM;
2886 goto out_unlock;
2887 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002888 skb_reserve(skb, local->hw.extra_tx_headroom);
2889
2890 memcpy(skb_put(skb, len), buf, len);
2891
2892 IEEE80211_SKB_CB(skb)->flags = flags;
2893
Johannes Berg2eb278e2012-06-05 14:28:42 +02002894 skb->dev = sdata->dev;
2895
2896 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002897 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002898 ieee80211_tx_skb(sdata, skb);
2899 ret = 0;
2900 goto out_unlock;
2901 }
2902
Seth Forshee6c17b772013-02-11 11:21:07 -06002903 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
2904 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002905 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002906 IEEE80211_SKB_CB(skb)->hw_queue =
2907 local->hw.offchannel_tx_hw_queue;
2908
Johannes Berg2eb278e2012-06-05 14:28:42 +02002909 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01002910 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002911 wait, cookie, skb,
2912 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002913 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002914 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002915 out_unlock:
2916 mutex_unlock(&local->mtx);
2917 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002918}
2919
Johannes Bergf30221e2010-11-25 10:02:30 +01002920static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002921 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002922 u64 cookie)
2923{
Johannes Berg71bbc992012-06-15 15:30:18 +02002924 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002925
Johannes Berg2eb278e2012-06-05 14:28:42 +02002926 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002927}
2928
Johannes Berg7be50862010-10-13 12:06:24 +02002929static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002930 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002931 u16 frame_type, bool reg)
2932{
2933 struct ieee80211_local *local = wiphy_priv(wiphy);
2934
Will Hawkins6abe0562012-06-20 11:51:14 -04002935 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04002936 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2937 if (reg)
2938 local->probe_req_reg++;
2939 else
2940 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002941
Felix Fietkau35f51492012-10-31 15:50:34 +01002942 if (!local->open_count)
2943 break;
2944
Will Hawkins6abe0562012-06-20 11:51:14 -04002945 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2946 break;
2947 default:
2948 break;
2949 }
Johannes Berg7be50862010-10-13 12:06:24 +02002950}
2951
Bruno Randolf15d96752010-11-10 12:50:56 +09002952static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2953{
2954 struct ieee80211_local *local = wiphy_priv(wiphy);
2955
2956 if (local->started)
2957 return -EOPNOTSUPP;
2958
2959 return drv_set_antenna(local, tx_ant, rx_ant);
2960}
2961
2962static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2963{
2964 struct ieee80211_local *local = wiphy_priv(wiphy);
2965
2966 return drv_get_antenna(local, tx_ant, rx_ant);
2967}
2968
John W. Linville38c09152011-03-07 16:19:18 -05002969static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2970{
2971 struct ieee80211_local *local = wiphy_priv(wiphy);
2972
2973 return drv_set_ringparam(local, tx, rx);
2974}
2975
2976static void ieee80211_get_ringparam(struct wiphy *wiphy,
2977 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2978{
2979 struct ieee80211_local *local = wiphy_priv(wiphy);
2980
2981 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2982}
2983
Johannes Bergc68f4b82011-07-05 16:35:41 +02002984static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2985 struct net_device *dev,
2986 struct cfg80211_gtk_rekey_data *data)
2987{
2988 struct ieee80211_local *local = wiphy_priv(wiphy);
2989 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2990
2991 if (!local->ops->set_rekey_data)
2992 return -EOPNOTSUPP;
2993
2994 drv_set_rekey_data(local, sdata, data);
2995
2996 return 0;
2997}
2998
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002999static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
3000{
3001 u8 *pos = (void *)skb_put(skb, 7);
3002
3003 *pos++ = WLAN_EID_EXT_CAPABILITY;
3004 *pos++ = 5; /* len */
3005 *pos++ = 0x0;
3006 *pos++ = 0x0;
3007 *pos++ = 0x0;
3008 *pos++ = 0x0;
3009 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
3010}
3011
3012static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
3013{
3014 struct ieee80211_local *local = sdata->local;
3015 u16 capab;
3016
3017 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003018 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003019 return capab;
3020
3021 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3022 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3023 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3024 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3025
3026 return capab;
3027}
3028
3029static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3030 u8 *peer, u8 *bssid)
3031{
3032 struct ieee80211_tdls_lnkie *lnkid;
3033
3034 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3035
3036 lnkid->ie_type = WLAN_EID_LINK_ID;
3037 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3038
3039 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3040 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3041 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3042}
3043
3044static int
3045ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3046 u8 *peer, u8 action_code, u8 dialog_token,
3047 u16 status_code, struct sk_buff *skb)
3048{
3049 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003050 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003051 struct ieee80211_tdls_data *tf;
3052
3053 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3054
3055 memcpy(tf->da, peer, ETH_ALEN);
3056 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3057 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3058 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3059
3060 switch (action_code) {
3061 case WLAN_TDLS_SETUP_REQUEST:
3062 tf->category = WLAN_CATEGORY_TDLS;
3063 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3064
3065 skb_put(skb, sizeof(tf->u.setup_req));
3066 tf->u.setup_req.dialog_token = dialog_token;
3067 tf->u.setup_req.capability =
3068 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3069
Johannes Berg55de9082012-07-26 17:24:39 +02003070 ieee80211_add_srates_ie(sdata, skb, false, band);
3071 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003072 ieee80211_tdls_add_ext_capab(skb);
3073 break;
3074 case WLAN_TDLS_SETUP_RESPONSE:
3075 tf->category = WLAN_CATEGORY_TDLS;
3076 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3077
3078 skb_put(skb, sizeof(tf->u.setup_resp));
3079 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3080 tf->u.setup_resp.dialog_token = dialog_token;
3081 tf->u.setup_resp.capability =
3082 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3083
Johannes Berg55de9082012-07-26 17:24:39 +02003084 ieee80211_add_srates_ie(sdata, skb, false, band);
3085 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003086 ieee80211_tdls_add_ext_capab(skb);
3087 break;
3088 case WLAN_TDLS_SETUP_CONFIRM:
3089 tf->category = WLAN_CATEGORY_TDLS;
3090 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3091
3092 skb_put(skb, sizeof(tf->u.setup_cfm));
3093 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3094 tf->u.setup_cfm.dialog_token = dialog_token;
3095 break;
3096 case WLAN_TDLS_TEARDOWN:
3097 tf->category = WLAN_CATEGORY_TDLS;
3098 tf->action_code = WLAN_TDLS_TEARDOWN;
3099
3100 skb_put(skb, sizeof(tf->u.teardown));
3101 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3102 break;
3103 case WLAN_TDLS_DISCOVERY_REQUEST:
3104 tf->category = WLAN_CATEGORY_TDLS;
3105 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3106
3107 skb_put(skb, sizeof(tf->u.discover_req));
3108 tf->u.discover_req.dialog_token = dialog_token;
3109 break;
3110 default:
3111 return -EINVAL;
3112 }
3113
3114 return 0;
3115}
3116
3117static int
3118ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3119 u8 *peer, u8 action_code, u8 dialog_token,
3120 u16 status_code, struct sk_buff *skb)
3121{
3122 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003123 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003124 struct ieee80211_mgmt *mgmt;
3125
3126 mgmt = (void *)skb_put(skb, 24);
3127 memset(mgmt, 0, 24);
3128 memcpy(mgmt->da, peer, ETH_ALEN);
3129 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3130 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3131
3132 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3133 IEEE80211_STYPE_ACTION);
3134
3135 switch (action_code) {
3136 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3137 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3138 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3139 mgmt->u.action.u.tdls_discover_resp.action_code =
3140 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3141 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3142 dialog_token;
3143 mgmt->u.action.u.tdls_discover_resp.capability =
3144 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3145
Johannes Berg55de9082012-07-26 17:24:39 +02003146 ieee80211_add_srates_ie(sdata, skb, false, band);
3147 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003148 ieee80211_tdls_add_ext_capab(skb);
3149 break;
3150 default:
3151 return -EINVAL;
3152 }
3153
3154 return 0;
3155}
3156
3157static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3158 u8 *peer, u8 action_code, u8 dialog_token,
3159 u16 status_code, const u8 *extra_ies,
3160 size_t extra_ies_len)
3161{
3162 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3163 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003164 struct sk_buff *skb = NULL;
3165 bool send_direct;
3166 int ret;
3167
3168 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3169 return -ENOTSUPP;
3170
3171 /* make sure we are in managed mode, and associated */
3172 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3173 !sdata->u.mgd.associated)
3174 return -EINVAL;
3175
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003176 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3177 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003178
3179 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3180 max(sizeof(struct ieee80211_mgmt),
3181 sizeof(struct ieee80211_tdls_data)) +
3182 50 + /* supported rates */
3183 7 + /* ext capab */
3184 extra_ies_len +
3185 sizeof(struct ieee80211_tdls_lnkie));
3186 if (!skb)
3187 return -ENOMEM;
3188
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003189 skb_reserve(skb, local->hw.extra_tx_headroom);
3190
3191 switch (action_code) {
3192 case WLAN_TDLS_SETUP_REQUEST:
3193 case WLAN_TDLS_SETUP_RESPONSE:
3194 case WLAN_TDLS_SETUP_CONFIRM:
3195 case WLAN_TDLS_TEARDOWN:
3196 case WLAN_TDLS_DISCOVERY_REQUEST:
3197 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3198 action_code, dialog_token,
3199 status_code, skb);
3200 send_direct = false;
3201 break;
3202 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3203 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3204 dialog_token, status_code,
3205 skb);
3206 send_direct = true;
3207 break;
3208 default:
3209 ret = -ENOTSUPP;
3210 break;
3211 }
3212
3213 if (ret < 0)
3214 goto fail;
3215
3216 if (extra_ies_len)
3217 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3218
3219 /* the TDLS link IE is always added last */
3220 switch (action_code) {
3221 case WLAN_TDLS_SETUP_REQUEST:
3222 case WLAN_TDLS_SETUP_CONFIRM:
3223 case WLAN_TDLS_TEARDOWN:
3224 case WLAN_TDLS_DISCOVERY_REQUEST:
3225 /* we are the initiator */
3226 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3227 sdata->u.mgd.bssid);
3228 break;
3229 case WLAN_TDLS_SETUP_RESPONSE:
3230 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3231 /* we are the responder */
3232 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3233 sdata->u.mgd.bssid);
3234 break;
3235 default:
3236 ret = -ENOTSUPP;
3237 goto fail;
3238 }
3239
3240 if (send_direct) {
3241 ieee80211_tx_skb(sdata, skb);
3242 return 0;
3243 }
3244
3245 /*
3246 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3247 * we should default to AC_VI.
3248 */
3249 switch (action_code) {
3250 case WLAN_TDLS_SETUP_REQUEST:
3251 case WLAN_TDLS_SETUP_RESPONSE:
3252 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3253 skb->priority = 2;
3254 break;
3255 default:
3256 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3257 skb->priority = 5;
3258 break;
3259 }
3260
3261 /* disable bottom halves when entering the Tx path */
3262 local_bh_disable();
3263 ret = ieee80211_subif_start_xmit(skb, dev);
3264 local_bh_enable();
3265
3266 return ret;
3267
3268fail:
3269 dev_kfree_skb(skb);
3270 return ret;
3271}
3272
3273static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3274 u8 *peer, enum nl80211_tdls_operation oper)
3275{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003276 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003277 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3278
3279 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3280 return -ENOTSUPP;
3281
3282 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3283 return -EINVAL;
3284
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003285 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003286
3287 switch (oper) {
3288 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003289 rcu_read_lock();
3290 sta = sta_info_get(sdata, peer);
3291 if (!sta) {
3292 rcu_read_unlock();
3293 return -ENOLINK;
3294 }
3295
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003296 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003297 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003298 break;
3299 case NL80211_TDLS_DISABLE_LINK:
3300 return sta_info_destroy_addr(sdata, peer);
3301 case NL80211_TDLS_TEARDOWN:
3302 case NL80211_TDLS_SETUP:
3303 case NL80211_TDLS_DISCOVERY_REQ:
3304 /* We don't support in-driver setup/teardown/discovery */
3305 return -ENOTSUPP;
3306 default:
3307 return -ENOTSUPP;
3308 }
3309
3310 return 0;
3311}
3312
Johannes Berg06500732011-11-04 11:18:16 +01003313static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3314 const u8 *peer, u64 *cookie)
3315{
3316 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3317 struct ieee80211_local *local = sdata->local;
3318 struct ieee80211_qos_hdr *nullfunc;
3319 struct sk_buff *skb;
3320 int size = sizeof(*nullfunc);
3321 __le16 fc;
3322 bool qos;
3323 struct ieee80211_tx_info *info;
3324 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003325 struct ieee80211_chanctx_conf *chanctx_conf;
3326 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003327
3328 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003329 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3330 if (WARN_ON(!chanctx_conf)) {
3331 rcu_read_unlock();
3332 return -EINVAL;
3333 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003334 band = chanctx_conf->def.chan->band;
Johannes Berg06500732011-11-04 11:18:16 +01003335 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003336 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003337 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003338 } else {
3339 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003340 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003341 }
Johannes Berg06500732011-11-04 11:18:16 +01003342
3343 if (qos) {
3344 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3345 IEEE80211_STYPE_QOS_NULLFUNC |
3346 IEEE80211_FCTL_FROMDS);
3347 } else {
3348 size -= 2;
3349 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3350 IEEE80211_STYPE_NULLFUNC |
3351 IEEE80211_FCTL_FROMDS);
3352 }
3353
3354 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003355 if (!skb) {
3356 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003357 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003358 }
Johannes Berg06500732011-11-04 11:18:16 +01003359
3360 skb->dev = dev;
3361
3362 skb_reserve(skb, local->hw.extra_tx_headroom);
3363
3364 nullfunc = (void *) skb_put(skb, size);
3365 nullfunc->frame_control = fc;
3366 nullfunc->duration_id = 0;
3367 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3368 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3369 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3370 nullfunc->seq_ctrl = 0;
3371
3372 info = IEEE80211_SKB_CB(skb);
3373
3374 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3375 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3376
3377 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3378 skb->priority = 7;
3379 if (qos)
3380 nullfunc->qos_ctrl = cpu_to_le16(7);
3381
3382 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003383 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003384 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003385 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003386
3387 *cookie = (unsigned long) skb;
3388 return 0;
3389}
3390
Johannes Berg683b6d32012-11-08 21:25:48 +01003391static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3392 struct wireless_dev *wdev,
3393 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003394{
Johannes Berg55de9082012-07-26 17:24:39 +02003395 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003396 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003397 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003398 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003399
Johannes Berg55de9082012-07-26 17:24:39 +02003400 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003401 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3402 if (chanctx_conf) {
3403 *chandef = chanctx_conf->def;
3404 ret = 0;
3405 } else if (local->open_count > 0 &&
3406 local->open_count == local->monitors &&
3407 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3408 if (local->use_chanctx)
3409 *chandef = local->monitor_chandef;
3410 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003411 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003412 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003413 }
3414 rcu_read_unlock();
3415
Johannes Berg683b6d32012-11-08 21:25:48 +01003416 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003417}
3418
Johannes Berg6d525632012-04-04 15:05:25 +02003419#ifdef CONFIG_PM
3420static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3421{
3422 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3423}
3424#endif
3425
Jiri Bencf0706e82007-05-05 11:45:53 -07003426struct cfg80211_ops mac80211_config_ops = {
3427 .add_virtual_intf = ieee80211_add_iface,
3428 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003429 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003430 .start_p2p_device = ieee80211_start_p2p_device,
3431 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003432 .add_key = ieee80211_add_key,
3433 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003434 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003435 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003436 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003437 .start_ap = ieee80211_start_ap,
3438 .change_beacon = ieee80211_change_beacon,
3439 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003440 .add_station = ieee80211_add_station,
3441 .del_station = ieee80211_del_station,
3442 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003443 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003444 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003445 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003446#ifdef CONFIG_MAC80211_MESH
3447 .add_mpath = ieee80211_add_mpath,
3448 .del_mpath = ieee80211_del_mpath,
3449 .change_mpath = ieee80211_change_mpath,
3450 .get_mpath = ieee80211_get_mpath,
3451 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003452 .update_mesh_config = ieee80211_update_mesh_config,
3453 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003454 .join_mesh = ieee80211_join_mesh,
3455 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003456#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003457 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003458 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003459 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003460 .suspend = ieee80211_suspend,
3461 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003462 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003463 .sched_scan_start = ieee80211_sched_scan_start,
3464 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003465 .auth = ieee80211_auth,
3466 .assoc = ieee80211_assoc,
3467 .deauth = ieee80211_deauth,
3468 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003469 .join_ibss = ieee80211_join_ibss,
3470 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003471 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003472 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003473 .set_tx_power = ieee80211_set_tx_power,
3474 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003475 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003476 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003477 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003478 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003479 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003480 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003481 .remain_on_channel = ieee80211_remain_on_channel,
3482 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003483 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003484 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003485 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003486 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003487 .set_antenna = ieee80211_set_antenna,
3488 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003489 .set_ringparam = ieee80211_set_ringparam,
3490 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003491 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003492 .tdls_oper = ieee80211_tdls_oper,
3493 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003494 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003495 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003496#ifdef CONFIG_PM
3497 .set_wakeup = ieee80211_set_wakeup,
3498#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003499 .get_et_sset_count = ieee80211_get_et_sset_count,
3500 .get_et_stats = ieee80211_get_et_stats,
3501 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003502 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003503 .start_radar_detection = ieee80211_start_radar_detection,
Jiri Bencf0706e82007-05-05 11:45:53 -07003504};