blob: 50aaf25d47359a21e29c4ef1ae49ebf107317a88 [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)) {
76 /*
77 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
78 * changed while the interface is up.
79 * Else we would need to add a lot of cruft
80 * to update everything:
81 * cooked_mntrs, monitor and all fif_* counters
82 * reconfigure hardware
83 */
84 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
85 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
86 return -EBUSY;
87
88 ieee80211_adjust_monitor_flags(sdata, -1);
89 sdata->u.mntr_flags = *flags;
90 ieee80211_adjust_monitor_flags(sdata, 1);
91
92 ieee80211_configure_filter(local);
93 } else {
94 /*
95 * Because the interface is down, ieee80211_do_stop
96 * and ieee80211_do_open take care of "everything"
97 * mentioned in the comment above.
98 */
99 sdata->u.mntr_flags = *flags;
100 }
101 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200102
Johannes Berg42613db2007-09-28 21:52:27 +0200103 return 0;
104}
105
Johannes Bergf142c6b2012-06-18 20:07:15 +0200106static int ieee80211_start_p2p_device(struct wiphy *wiphy,
107 struct wireless_dev *wdev)
108{
109 return ieee80211_do_open(wdev, true);
110}
111
112static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
113 struct wireless_dev *wdev)
114{
115 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
116}
117
Simon Wunderlichb53be792011-11-18 14:20:44 +0100118static int ieee80211_set_noack_map(struct wiphy *wiphy,
119 struct net_device *dev,
120 u16 noack_map)
121{
122 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
123
124 sdata->noack_map = noack_map;
125 return 0;
126}
127
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100128static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200129 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100130 struct key_params *params)
131{
Johannes Berg26a58452010-08-27 12:35:55 +0200132 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100133 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100134 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200135 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100136
Johannes Berg26a58452010-08-27 12:35:55 +0200137 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200138 return -ENETDOWN;
139
Johannes Berg97359d12010-08-10 09:46:38 +0200140 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100141 switch (params->cipher) {
142 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100143 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200144 case WLAN_CIPHER_SUITE_WEP104:
145 if (IS_ERR(sdata->local->wep_tx_tfm))
146 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200147 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100148 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200149 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100150 }
151
Johannes Berg97359d12010-08-10 09:46:38 +0200152 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
153 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100154 if (IS_ERR(key))
155 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100156
Johannes Berge31b8212010-10-05 19:39:30 +0200157 if (pairwise)
158 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
159
Johannes Bergad0e2b52010-06-01 10:19:19 +0200160 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200161
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100162 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700163 if (ieee80211_vif_is_mesh(&sdata->vif))
164 sta = sta_info_get(sdata, mac_addr);
165 else
166 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100167 /*
168 * The ASSOC test makes sure the driver is ready to
169 * receive the key. When wpa_supplicant has roamed
170 * using FT, it attempts to set the key before
171 * association has completed, this rejects that attempt
172 * so it will set the key again after assocation.
173 *
174 * TODO: accept the key if we have a station entry and
175 * add it to the device after the station.
176 */
177 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100178 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200179 err = -ENOENT;
180 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100181 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100182 }
183
Johannes Berge548c492012-09-04 17:08:23 +0200184 switch (sdata->vif.type) {
185 case NL80211_IFTYPE_STATION:
186 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
187 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
188 break;
189 case NL80211_IFTYPE_AP:
190 case NL80211_IFTYPE_AP_VLAN:
191 /* Keys without a station are used for TX only */
192 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
193 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
194 break;
195 case NL80211_IFTYPE_ADHOC:
196 /* no MFP (yet) */
197 break;
198 case NL80211_IFTYPE_MESH_POINT:
199#ifdef CONFIG_MAC80211_MESH
200 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
201 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
202 break;
203#endif
204 case NL80211_IFTYPE_WDS:
205 case NL80211_IFTYPE_MONITOR:
206 case NL80211_IFTYPE_P2P_DEVICE:
207 case NL80211_IFTYPE_UNSPECIFIED:
208 case NUM_NL80211_IFTYPES:
209 case NL80211_IFTYPE_P2P_CLIENT:
210 case NL80211_IFTYPE_P2P_GO:
211 /* shouldn't happen */
212 WARN_ON_ONCE(1);
213 break;
214 }
215
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300216 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100217
Johannes Berg3b967662008-04-08 17:56:52 +0200218 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200219 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200220
221 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100222}
223
224static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200225 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100226{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200227 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
228 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100229 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200230 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100231 int ret;
232
Johannes Berg5c0c3642011-05-12 14:31:49 +0200233 mutex_lock(&local->sta_mtx);
234 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200235
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100236 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200237 ret = -ENOENT;
238
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100239 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100240 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200241 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100242
Johannes Berg5c0c3642011-05-12 14:31:49 +0200243 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200244 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200245 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200246 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200247 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200248 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100249
Johannes Berg5c0c3642011-05-12 14:31:49 +0200250 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200251 ret = -ENOENT;
252 goto out_unlock;
253 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100254
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100255 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100256
Johannes Berg3b967662008-04-08 17:56:52 +0200257 ret = 0;
258 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200259 mutex_unlock(&local->key_mtx);
260 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200261
262 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100263}
264
Johannes Berg62da92f2007-12-19 02:03:31 +0100265static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200266 u8 key_idx, bool pairwise, const u8 *mac_addr,
267 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100268 void (*callback)(void *cookie,
269 struct key_params *params))
270{
Johannes Berg14db74b2008-07-29 13:22:52 +0200271 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100272 struct sta_info *sta = NULL;
273 u8 seq[6] = {0};
274 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200275 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200276 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100277 u32 iv32;
278 u16 iv16;
279 int err = -ENOENT;
280
Johannes Berg14db74b2008-07-29 13:22:52 +0200281 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
282
Johannes Berg3b967662008-04-08 17:56:52 +0200283 rcu_read_lock();
284
Johannes Berg62da92f2007-12-19 02:03:31 +0100285 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100286 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100287 if (!sta)
288 goto out;
289
Johannes Berge31b8212010-10-05 19:39:30 +0200290 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200291 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200292 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200293 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100294 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200295 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100296
297 if (!key)
298 goto out;
299
300 memset(&params, 0, sizeof(params));
301
Johannes Berg97359d12010-08-10 09:46:38 +0200302 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100303
Johannes Berg97359d12010-08-10 09:46:38 +0200304 switch (key->conf.cipher) {
305 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700306 iv32 = key->u.tkip.tx.iv32;
307 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100308
Johannes Berg24487982009-04-23 18:52:52 +0200309 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
310 drv_get_tkip_seq(sdata->local,
311 key->conf.hw_key_idx,
312 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100313
314 seq[0] = iv16 & 0xff;
315 seq[1] = (iv16 >> 8) & 0xff;
316 seq[2] = iv32 & 0xff;
317 seq[3] = (iv32 >> 8) & 0xff;
318 seq[4] = (iv32 >> 16) & 0xff;
319 seq[5] = (iv32 >> 24) & 0xff;
320 params.seq = seq;
321 params.seq_len = 6;
322 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200323 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200324 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
325 seq[0] = pn64;
326 seq[1] = pn64 >> 8;
327 seq[2] = pn64 >> 16;
328 seq[3] = pn64 >> 24;
329 seq[4] = pn64 >> 32;
330 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100331 params.seq = seq;
332 params.seq_len = 6;
333 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200334 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200335 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
336 seq[0] = pn64;
337 seq[1] = pn64 >> 8;
338 seq[2] = pn64 >> 16;
339 seq[3] = pn64 >> 24;
340 seq[4] = pn64 >> 32;
341 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200342 params.seq = seq;
343 params.seq_len = 6;
344 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100345 }
346
347 params.key = key->conf.key;
348 params.key_len = key->conf.keylen;
349
350 callback(cookie, &params);
351 err = 0;
352
353 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200354 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100355 return err;
356}
357
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100358static int ieee80211_config_default_key(struct wiphy *wiphy,
359 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100360 u8 key_idx, bool uni,
361 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100362{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100364
Johannes Bergf7e01042010-12-09 19:49:02 +0100365 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100366
367 return 0;
368}
369
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200370static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
371 struct net_device *dev,
372 u8 key_idx)
373{
Johannes Berg66c52422010-07-22 13:58:51 +0200374 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200375
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200376 ieee80211_set_default_mgmt_key(sdata, key_idx);
377
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200378 return 0;
379}
380
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800381void sta_set_rate_info_tx(struct sta_info *sta,
382 const struct ieee80211_tx_rate *rate,
383 struct rate_info *rinfo)
384{
385 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100386 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800387 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100388 rinfo->mcs = rate->idx;
389 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
390 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
391 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
392 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
393 } else {
394 struct ieee80211_supported_band *sband;
395 sband = sta->local->hw.wiphy->bands[
396 ieee80211_get_sdata_band(sta->sdata)];
397 rinfo->legacy = sband->bitrates[rate->idx].bitrate;
398 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800399 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
400 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100401 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
402 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
403 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
404 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800405 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
406 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800407}
408
Saravana003e6762012-11-28 18:29:38 +0530409void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
410{
411 rinfo->flags = 0;
412
413 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
414 rinfo->flags |= RATE_INFO_FLAGS_MCS;
415 rinfo->mcs = sta->last_rx_rate_idx;
416 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
417 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
418 rinfo->nss = sta->last_rx_rate_vht_nss;
419 rinfo->mcs = sta->last_rx_rate_idx;
420 } else {
421 struct ieee80211_supported_band *sband;
422
423 sband = sta->local->hw.wiphy->bands[
424 ieee80211_get_sdata_band(sta->sdata)];
425 rinfo->legacy =
426 sband->bitrates[sta->last_rx_rate_idx].bitrate;
427 }
428
429 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
430 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
431 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
432 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
433 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
434 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
435 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
436 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
437 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
438 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
439}
440
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100441static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
442{
Johannes Bergd0709a62008-02-25 16:27:46 +0100443 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300444 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530445 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100446 u64 packets = 0;
447 int ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100448
Johannes Bergf5ea9122009-08-07 16:17:38 +0200449 sinfo->generation = sdata->local->sta_generation;
450
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100451 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100452 STATION_INFO_RX_BYTES64 |
453 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200454 STATION_INFO_RX_PACKETS |
455 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900456 STATION_INFO_TX_RETRIES |
457 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700458 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100459 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700460 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530461 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200462 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800463 STATION_INFO_STA_FLAGS |
464 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530465
466 do_posix_clock_monotonic_gettime(&uptime);
467 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100468
469 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100470 sinfo->tx_bytes = 0;
471 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
472 sinfo->tx_bytes += sta->tx_bytes[ac];
473 packets += sta->tx_packets[ac];
474 }
475 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100476 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200477 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900478 sinfo->tx_retries = sta->tx_retry_count;
479 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700480 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800481 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100482
John W. Linville19deffb2009-12-08 17:10:13 -0500483 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
484 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900485 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300486 if (!local->ops->get_rssi ||
487 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
488 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900489 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100490 }
491
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800492 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530493 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100494
Johannes Berg902acc72008-02-23 15:17:19 +0100495 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100496#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100497 sinfo->filled |= STATION_INFO_LLID |
498 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100499 STATION_INFO_PLINK_STATE |
500 STATION_INFO_LOCAL_PM |
501 STATION_INFO_PEER_PM |
502 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100503
504 sinfo->llid = le16_to_cpu(sta->llid);
505 sinfo->plid = le16_to_cpu(sta->plid);
506 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700507 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
508 sinfo->filled |= STATION_INFO_T_OFFSET;
509 sinfo->t_offset = sta->t_offset;
510 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100511 sinfo->local_pm = sta->local_pm;
512 sinfo->peer_pm = sta->peer_pm;
513 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100514#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100515 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700516
517 sinfo->bss_param.flags = 0;
518 if (sdata->vif.bss_conf.use_cts_prot)
519 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
520 if (sdata->vif.bss_conf.use_short_preamble)
521 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
522 if (sdata->vif.bss_conf.use_short_slot)
523 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
524 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
525 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200526
527 sinfo->sta_flags.set = 0;
528 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
529 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
530 BIT(NL80211_STA_FLAG_WME) |
531 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100532 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200533 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100534 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200535 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
536 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
537 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
538 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
539 if (test_sta_flag(sta, WLAN_STA_WME))
540 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
541 if (test_sta_flag(sta, WLAN_STA_MFP))
542 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
543 if (test_sta_flag(sta, WLAN_STA_AUTH))
544 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200545 if (test_sta_flag(sta, WLAN_STA_ASSOC))
546 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100547 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
548 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100549}
550
Ben Greearb1ab7922012-04-23 12:50:30 -0700551static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
552 "rx_packets", "rx_bytes", "wep_weak_iv_count",
553 "rx_duplicates", "rx_fragments", "rx_dropped",
554 "tx_packets", "tx_bytes", "tx_fragments",
555 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700556 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
557 "channel", "noise", "ch_time", "ch_time_busy",
558 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700559};
560#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
561
562static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
563 struct net_device *dev,
564 int sset)
565{
Ben Greeare3521142012-04-23 12:50:31 -0700566 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
567 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700568
Ben Greeare3521142012-04-23 12:50:31 -0700569 if (sset == ETH_SS_STATS)
570 rv += STA_STATS_LEN;
571
572 rv += drv_get_et_sset_count(sdata, sset);
573
574 if (rv == 0)
575 return -EOPNOTSUPP;
576 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700577}
578
579static void ieee80211_get_et_stats(struct wiphy *wiphy,
580 struct net_device *dev,
581 struct ethtool_stats *stats,
582 u64 *data)
583{
584 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200585 struct ieee80211_chanctx_conf *chanctx_conf;
586 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700587 struct sta_info *sta;
588 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700589 struct station_info sinfo;
590 struct survey_info survey;
591 int i, q;
592#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700593
594 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
595
596#define ADD_STA_STATS(sta) \
597 do { \
598 data[i++] += sta->rx_packets; \
599 data[i++] += sta->rx_bytes; \
600 data[i++] += sta->wep_weak_iv_count; \
601 data[i++] += sta->num_duplicates; \
602 data[i++] += sta->rx_fragments; \
603 data[i++] += sta->rx_dropped; \
604 \
Johannes Berg560d2682013-02-05 10:55:21 +0100605 data[i++] += sinfo.tx_packets; \
606 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700607 data[i++] += sta->tx_fragments; \
608 data[i++] += sta->tx_filtered_count; \
609 data[i++] += sta->tx_retry_failed; \
610 data[i++] += sta->tx_retry_count; \
611 data[i++] += sta->beacon_loss_count; \
612 } while (0)
613
614 /* For Managed stations, find the single station based on BSSID
615 * and use that. For interface types, iterate through all available
616 * stations and add stats for any station that is assigned to this
617 * network device.
618 */
619
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300620 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700621
622 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
623 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700624
625 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
626 goto do_survey;
627
Johannes Berg560d2682013-02-05 10:55:21 +0100628 sinfo.filled = 0;
629 sta_set_sinfo(sta, &sinfo);
630
Ben Greear3073a7c2012-04-23 12:50:32 -0700631 i = 0;
632 ADD_STA_STATS(sta);
633
634 data[i++] = sta->sta_state;
635
Ben Greear3073a7c2012-04-23 12:50:32 -0700636
Joe Perches52042672012-05-30 13:25:54 -0700637 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700638 data[i] = 100000 *
639 cfg80211_calculate_bitrate(&sinfo.txrate);
640 i++;
Joe Perches52042672012-05-30 13:25:54 -0700641 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700642 data[i] = 100000 *
643 cfg80211_calculate_bitrate(&sinfo.rxrate);
644 i++;
645
Joe Perches52042672012-05-30 13:25:54 -0700646 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700647 data[i] = (u8)sinfo.signal_avg;
648 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700649 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300650 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700651 /* Make sure this station belongs to the proper dev */
652 if (sta->sdata->dev != dev)
653 continue;
654
655 i = 0;
656 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700657 }
658 }
659
Ben Greear3073a7c2012-04-23 12:50:32 -0700660do_survey:
661 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
662 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200663 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700664
Johannes Berg55de9082012-07-26 17:24:39 +0200665 rcu_read_lock();
666 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
667 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100668 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200669 else
670 channel = NULL;
671 rcu_read_unlock();
672
673 if (channel) {
674 q = 0;
675 do {
676 survey.filled = 0;
677 if (drv_get_survey(local, q, &survey) != 0) {
678 survey.filled = 0;
679 break;
680 }
681 q++;
682 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700683 }
684
685 if (survey.filled)
686 data[i++] = survey.channel->center_freq;
687 else
688 data[i++] = 0;
689 if (survey.filled & SURVEY_INFO_NOISE_DBM)
690 data[i++] = (u8)survey.noise;
691 else
692 data[i++] = -1LL;
693 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
694 data[i++] = survey.channel_time;
695 else
696 data[i++] = -1LL;
697 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
698 data[i++] = survey.channel_time_busy;
699 else
700 data[i++] = -1LL;
701 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
702 data[i++] = survey.channel_time_ext_busy;
703 else
704 data[i++] = -1LL;
705 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
706 data[i++] = survey.channel_time_rx;
707 else
708 data[i++] = -1LL;
709 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
710 data[i++] = survey.channel_time_tx;
711 else
712 data[i++] = -1LL;
713
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300714 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700715
Ben Greear3073a7c2012-04-23 12:50:32 -0700716 if (WARN_ON(i != STA_STATS_LEN))
717 return;
718
Ben Greeare3521142012-04-23 12:50:31 -0700719 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700720}
721
722static void ieee80211_get_et_strings(struct wiphy *wiphy,
723 struct net_device *dev,
724 u32 sset, u8 *data)
725{
Ben Greeare3521142012-04-23 12:50:31 -0700726 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
727 int sz_sta_stats = 0;
728
Ben Greearb1ab7922012-04-23 12:50:30 -0700729 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700730 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700731 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
732 }
Ben Greeare3521142012-04-23 12:50:31 -0700733 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700734}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100735
736static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
737 int idx, u8 *mac, struct station_info *sinfo)
738{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100739 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300740 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100741 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100742 int ret = -ENOENT;
743
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300744 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100745
Johannes Berg3b53fde82009-11-16 12:00:37 +0100746 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100747 if (sta) {
748 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200749 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100750 sta_set_sinfo(sta, sinfo);
751 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100752
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300753 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100754
Johannes Bergd0709a62008-02-25 16:27:46 +0100755 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100756}
757
Holger Schurig12897232010-04-19 10:23:57 +0200758static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
759 int idx, struct survey_info *survey)
760{
761 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
762
Holger Schurig12897232010-04-19 10:23:57 +0200763 return drv_get_survey(local, idx, survey);
764}
765
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100766static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100767 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100768{
Johannes Bergabe60632009-11-25 17:46:18 +0100769 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300770 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100771 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100772 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100773
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300774 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100775
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100776 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100777 if (sta) {
778 ret = 0;
779 sta_set_sinfo(sta, sinfo);
780 }
781
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300782 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100783
784 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100785}
786
Johannes Berge8c9bd52012-06-06 08:18:22 +0200787static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100788 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200789{
Johannes Berg55de9082012-07-26 17:24:39 +0200790 struct ieee80211_local *local = wiphy_priv(wiphy);
791 struct ieee80211_sub_if_data *sdata;
792 int ret = 0;
793
Johannes Berg4bf88532012-11-09 11:39:59 +0100794 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200795 return 0;
796
797 mutex_lock(&local->iflist_mtx);
798 if (local->use_chanctx) {
799 sdata = rcu_dereference_protected(
800 local->monitor_sdata,
801 lockdep_is_held(&local->iflist_mtx));
802 if (sdata) {
803 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100804 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200805 IEEE80211_CHANCTX_EXCLUSIVE);
806 }
807 } else if (local->open_count == local->monitors) {
Johannes Berg683b6d32012-11-08 21:25:48 +0100808 local->_oper_channel = chandef->chan;
Johannes Berg4bf88532012-11-09 11:39:59 +0100809 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
Johannes Berg55de9082012-07-26 17:24:39 +0200810 ieee80211_hw_config(local, 0);
811 }
812
Johannes Berg4bf88532012-11-09 11:39:59 +0100813 if (ret == 0)
814 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200815 mutex_unlock(&local->iflist_mtx);
816
817 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200818}
819
Arik Nemtsov02945822011-11-10 11:28:57 +0200820static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100821 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200822{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300823 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200824
825 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530826 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200827
Arik Nemtsovf7248282011-11-19 10:51:26 +0200828 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200829
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300830 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200831 if (!new)
832 return -ENOMEM;
833
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300834 new->len = resp_len;
835 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200836
837 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300838 if (old)
839 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200840
841 return 0;
842}
843
Johannes Berg88600202012-02-13 15:17:18 +0100844static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
845 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100846{
847 struct beacon_data *new, *old;
848 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100849 int size, err;
850 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100851
Johannes Berg40b275b2011-05-13 14:15:49 +0200852 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100853
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100854 /* Need to have a beacon head if we don't have one yet */
855 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100856 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100857
858 /* new or old head? */
859 if (params->head)
860 new_head_len = params->head_len;
861 else
862 new_head_len = old->head_len;
863
864 /* new or old tail? */
865 if (params->tail || !old)
866 /* params->tail_len will be zero for !params->tail */
867 new_tail_len = params->tail_len;
868 else
869 new_tail_len = old->tail_len;
870
871 size = sizeof(*new) + new_head_len + new_tail_len;
872
873 new = kzalloc(size, GFP_KERNEL);
874 if (!new)
875 return -ENOMEM;
876
877 /* start filling the new info now */
878
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100879 /*
880 * pointers go into the block we allocated,
881 * memory is | beacon_data | head | tail |
882 */
883 new->head = ((u8 *) new) + sizeof(*new);
884 new->tail = new->head + new_head_len;
885 new->head_len = new_head_len;
886 new->tail_len = new_tail_len;
887
888 /* copy in head */
889 if (params->head)
890 memcpy(new->head, params->head, new_head_len);
891 else
892 memcpy(new->head, old->head, new_head_len);
893
894 /* copy in optional tail */
895 if (params->tail)
896 memcpy(new->tail, params->tail, new_tail_len);
897 else
898 if (old)
899 memcpy(new->tail, old->tail, new_tail_len);
900
Johannes Berg88600202012-02-13 15:17:18 +0100901 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
902 params->probe_resp_len);
903 if (err < 0)
904 return err;
905 if (err == 0)
906 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100907
Eric Dumazetcf778b02012-01-12 04:41:32 +0000908 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100909
Johannes Berg88600202012-02-13 15:17:18 +0100910 if (old)
911 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100912
Johannes Berg88600202012-02-13 15:17:18 +0100913 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100914}
915
Johannes Berg88600202012-02-13 15:17:18 +0100916static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
917 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100918{
Johannes Berg88600202012-02-13 15:17:18 +0100919 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100920 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100921 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100922 u32 changed = BSS_CHANGED_BEACON_INT |
923 BSS_CHANGED_BEACON_ENABLED |
924 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100925 BSS_CHANGED_SSID |
926 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100927 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200928
Johannes Berg40b275b2011-05-13 14:15:49 +0200929 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100930 if (old)
931 return -EALREADY;
932
Johannes Berg04ecd252012-09-11 14:34:12 +0200933 /* TODO: make hostapd tell us what it wants */
934 sdata->smps_mode = IEEE80211_SMPS_OFF;
935 sdata->needed_rx_chains = sdata->local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +0100936 sdata->radar_required = params->radar_required;
Johannes Berg04ecd252012-09-11 14:34:12 +0200937
Johannes Berg4bf88532012-11-09 11:39:59 +0100938 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200939 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200940 if (err)
941 return err;
Johannes Berg1f4ac5a2013-02-08 12:07:44 +0100942 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Bergaa430da2012-05-16 23:50:18 +0200943
Johannes Berg665c93a2011-11-04 11:18:11 +0100944 /*
945 * Apply control port protocol, this allows us to
946 * not encrypt dynamic WEP control frames.
947 */
948 sdata->control_port_protocol = params->crypto.control_port_ethertype;
949 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
950 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
951 vlan->control_port_protocol =
952 params->crypto.control_port_ethertype;
953 vlan->control_port_no_encrypt =
954 params->crypto.control_port_no_encrypt;
955 }
956
Johannes Berg88600202012-02-13 15:17:18 +0100957 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
958 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100959 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100960
961 sdata->vif.bss_conf.ssid_len = params->ssid_len;
962 if (params->ssid_len)
963 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
964 params->ssid_len);
965 sdata->vif.bss_conf.hidden_ssid =
966 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
967
Janusz Dziedzic67baf662013-03-21 15:47:56 +0100968 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
969 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
970 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
971 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
972 if (params->p2p_opp_ps)
973 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
974 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +0100975
Johannes Berg88600202012-02-13 15:17:18 +0100976 err = ieee80211_assign_beacon(sdata, &params->beacon);
977 if (err < 0)
978 return err;
979 changed |= err;
980
Johannes Berg10416382012-10-19 15:44:42 +0200981 err = drv_start_ap(sdata->local, sdata);
982 if (err) {
983 old = rtnl_dereference(sdata->u.ap.beacon);
984 if (old)
985 kfree_rcu(old, rcu_head);
986 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
987 return err;
988 }
989
Johannes Berg88600202012-02-13 15:17:18 +0100990 ieee80211_bss_info_change_notify(sdata, changed);
991
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200992 netif_carrier_on(dev);
993 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
994 netif_carrier_on(vlan->dev);
995
Johannes Berg665c93a2011-11-04 11:18:11 +0100996 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100997}
998
Johannes Berg88600202012-02-13 15:17:18 +0100999static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1000 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001001{
Johannes Berg14db74b2008-07-29 13:22:52 +02001002 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001003 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001004 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001005
Johannes Berg14db74b2008-07-29 13:22:52 +02001006 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1007
Johannes Berg40b275b2011-05-13 14:15:49 +02001008 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001009 if (!old)
1010 return -ENOENT;
1011
Johannes Berg88600202012-02-13 15:17:18 +01001012 err = ieee80211_assign_beacon(sdata, params);
1013 if (err < 0)
1014 return err;
1015 ieee80211_bss_info_change_notify(sdata, err);
1016 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001017}
1018
Johannes Berg88600202012-02-13 15:17:18 +01001019static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001020{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001021 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1022 struct ieee80211_sub_if_data *vlan;
1023 struct ieee80211_local *local = sdata->local;
1024 struct beacon_data *old_beacon;
1025 struct probe_resp *old_probe_resp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001026
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001027 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1028 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001029 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001030 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001031
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001032 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001033 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1034 netif_carrier_off(vlan->dev);
1035 netif_carrier_off(dev);
1036
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001037 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001038 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001039 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1040 kfree_rcu(old_beacon, rcu_head);
1041 if (old_probe_resp)
1042 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001043
Felix Fietkau2d4072a2012-12-10 20:02:34 +01001044 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
Johannes Berg75de9112012-12-14 14:56:03 +01001045 sta_info_flush_defer(vlan);
1046 sta_info_flush_defer(sdata);
1047 rcu_barrier();
Johannes Berg7b4396b2013-02-23 01:14:20 +01001048 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
Johannes Berg75de9112012-12-14 14:56:03 +01001049 sta_info_flush_cleanup(vlan);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001050 ieee80211_free_keys(vlan);
1051 }
Johannes Berg75de9112012-12-14 14:56:03 +01001052 sta_info_flush_cleanup(sdata);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001053 ieee80211_free_keys(sdata);
Johannes Berg75de9112012-12-14 14:56:03 +01001054
Johannes Bergd6a83222012-12-14 14:06:28 +01001055 sdata->vif.bss_conf.enable_beacon = false;
1056 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001057 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001058
Johannes Berg10416382012-10-19 15:44:42 +02001059 drv_stop_ap(sdata->local, sdata);
1060
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001061 /* free all potentially still buffered bcast frames */
1062 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1063 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1064
Johannes Berg1f4ac5a2013-02-08 12:07:44 +01001065 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001066 ieee80211_vif_release_channel(sdata);
1067
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001068 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001069}
1070
Johannes Berg4fd69312007-12-19 02:03:35 +01001071/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1072struct iapp_layer2_update {
1073 u8 da[ETH_ALEN]; /* broadcast */
1074 u8 sa[ETH_ALEN]; /* STA addr */
1075 __be16 len; /* 6 */
1076 u8 dsap; /* 0 */
1077 u8 ssap; /* 0 */
1078 u8 control;
1079 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001080} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001081
1082static void ieee80211_send_layer2_update(struct sta_info *sta)
1083{
1084 struct iapp_layer2_update *msg;
1085 struct sk_buff *skb;
1086
1087 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1088 * bridge devices */
1089
1090 skb = dev_alloc_skb(sizeof(*msg));
1091 if (!skb)
1092 return;
1093 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1094
1095 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1096 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1097
Johannes Berge83e6542012-07-13 16:23:07 +02001098 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001099 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001100 msg->len = htons(6);
1101 msg->dsap = 0;
1102 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1103 msg->control = 0xaf; /* XID response lsb.1111F101.
1104 * F=0 (no poll command; unsolicited frame) */
1105 msg->xid_info[0] = 0x81; /* XID format identifier */
1106 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1107 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1108
Johannes Bergd0709a62008-02-25 16:27:46 +01001109 skb->dev = sta->sdata->dev;
1110 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001111 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001112 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001113}
1114
Johannes Bergd582cff2012-10-26 17:53:44 +02001115static int sta_apply_auth_flags(struct ieee80211_local *local,
1116 struct sta_info *sta,
1117 u32 mask, u32 set)
1118{
1119 int ret;
1120
1121 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1122 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1123 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1124 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1125 if (ret)
1126 return ret;
1127 }
1128
1129 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1130 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1131 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1132 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1133 if (ret)
1134 return ret;
1135 }
1136
1137 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1138 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1139 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1140 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1141 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1142 else
1143 ret = 0;
1144 if (ret)
1145 return ret;
1146 }
1147
1148 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1149 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1150 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1151 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1152 if (ret)
1153 return ret;
1154 }
1155
1156 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1157 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1158 test_sta_flag(sta, WLAN_STA_AUTH)) {
1159 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1160 if (ret)
1161 return ret;
1162 }
1163
1164 return 0;
1165}
1166
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001167static int sta_apply_parameters(struct ieee80211_local *local,
1168 struct sta_info *sta,
1169 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001170{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001171 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001172 u32 rates;
1173 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +01001174 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001175 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001176 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001177 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001178
Johannes Berg55de9082012-07-26 17:24:39 +02001179 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001180
Johannes Bergeccb8e82009-05-11 21:57:56 +03001181 mask = params->sta_flags_mask;
1182 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001183
Johannes Bergd582cff2012-10-26 17:53:44 +02001184 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1185 /*
1186 * In mesh mode, ASSOCIATED isn't part of the nl80211
1187 * API but must follow AUTHENTICATED for driver state.
1188 */
1189 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1190 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1191 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1192 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001193 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1194 /*
1195 * TDLS -- everything follows authorized, but
1196 * only becoming authorized is possible, not
1197 * going back
1198 */
1199 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1200 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1201 BIT(NL80211_STA_FLAG_ASSOCIATED);
1202 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1203 BIT(NL80211_STA_FLAG_ASSOCIATED);
1204 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001205 }
1206
Johannes Bergd582cff2012-10-26 17:53:44 +02001207 ret = sta_apply_auth_flags(local, sta, mask, set);
1208 if (ret)
1209 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001210
Johannes Bergeccb8e82009-05-11 21:57:56 +03001211 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001212 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001213 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1214 else
1215 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001216 }
1217
1218 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001219 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001220 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001221 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001222 } else {
1223 clear_sta_flag(sta, WLAN_STA_WME);
1224 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001225 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001226 }
1227
1228 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001229 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001230 set_sta_flag(sta, WLAN_STA_MFP);
1231 else
1232 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001233 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001234
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001235 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001236 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001237 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1238 else
1239 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001240 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001241
Johannes Berg3b9ce802011-09-27 20:56:12 +02001242 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1243 sta->sta.uapsd_queues = params->uapsd_queues;
1244 sta->sta.max_sp = params->max_sp;
1245 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001246
Johannes Berg73651ee2008-02-25 16:27:47 +01001247 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001248 * cfg80211 validates this (1-2007) and allows setting the AID
1249 * only when creating a new station entry
1250 */
1251 if (params->aid)
1252 sta->sta.aid = params->aid;
1253
1254 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001255 * Some of the following updates would be racy if called on an
1256 * existing station, via ieee80211_change_station(). However,
1257 * all such changes are rejected by cfg80211 except for updates
1258 * changing the supported rates on an existing but not yet used
1259 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001260 */
1261
Johannes Berg4fd69312007-12-19 02:03:35 +01001262 if (params->listen_interval >= 0)
1263 sta->listen_interval = params->listen_interval;
1264
1265 if (params->supported_rates) {
1266 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001267
Johannes Berg4fd69312007-12-19 02:03:35 +01001268 for (i = 0; i < params->supported_rates_len; i++) {
1269 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001270 for (j = 0; j < sband->n_bitrates; j++) {
1271 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001272 rates |= BIT(j);
1273 }
1274 }
Johannes Berg55de9082012-07-26 17:24:39 +02001275 sta->sta.supp_rates[band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001276 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001277
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001278 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001279 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001280 params->ht_capa, sta);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001281
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001282 if (params->vht_capa)
1283 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001284 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001285
Javier Cardona9c3990a2011-05-03 16:57:11 -07001286 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001287#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001288 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001289
1290 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001291 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001292 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001293 if (sta->plink_state != NL80211_PLINK_ESTAB)
1294 changed = mesh_plink_inc_estab_count(
1295 sdata);
1296 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001297
1298 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001299 changed |= ieee80211_mps_set_sta_local_pm(sta,
1300 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001301 break;
1302 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001303 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001304 case NL80211_PLINK_OPN_SNT:
1305 case NL80211_PLINK_OPN_RCVD:
1306 case NL80211_PLINK_CNF_RCVD:
1307 case NL80211_PLINK_HOLDING:
1308 if (sta->plink_state == NL80211_PLINK_ESTAB)
1309 changed = mesh_plink_dec_estab_count(
1310 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001311 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001312
1313 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001314 changed |=
1315 ieee80211_mps_local_status_update(sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001316 break;
1317 default:
1318 /* nothing */
1319 break;
1320 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001321 }
1322
1323 switch (params->plink_action) {
1324 case NL80211_PLINK_ACTION_NO_ACTION:
1325 /* nothing */
1326 break;
1327 case NL80211_PLINK_ACTION_OPEN:
1328 changed |= mesh_plink_open(sta);
1329 break;
1330 case NL80211_PLINK_ACTION_BLOCK:
1331 changed |= mesh_plink_block(sta);
1332 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001333 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001334
1335 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001336 changed |=
1337 ieee80211_mps_set_sta_local_pm(sta,
1338 params->local_pm);
1339 ieee80211_bss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001340#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001341 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001342
1343 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001344}
1345
1346static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1347 u8 *mac, struct station_parameters *params)
1348{
Johannes Berg14db74b2008-07-29 13:22:52 +02001349 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001350 struct sta_info *sta;
1351 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001352 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001353 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001354
Johannes Berg4fd69312007-12-19 02:03:35 +01001355 if (params->vlan) {
1356 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1357
Johannes Berg05c914f2008-09-11 00:01:58 +02001358 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1359 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001360 return -EINVAL;
1361 } else
1362 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1363
Joe Perchesb203ca32012-05-08 18:56:52 +00001364 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001365 return -EINVAL;
1366
1367 if (is_multicast_ether_addr(mac))
1368 return -EINVAL;
1369
1370 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001371 if (!sta)
1372 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001373
Johannes Bergd582cff2012-10-26 17:53:44 +02001374 /*
1375 * defaults -- if userspace wants something else we'll
1376 * change it accordingly in sta_apply_parameters()
1377 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001378 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1379 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1380 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1381 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001382
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001383 err = sta_apply_parameters(local, sta, params);
1384 if (err) {
1385 sta_info_free(local, sta);
1386 return err;
1387 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001388
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001389 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001390 * for TDLS, rate control should be initialized only when
1391 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001392 */
1393 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1394 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001395
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001396 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1397 sdata->vif.type == NL80211_IFTYPE_AP;
1398
Johannes Berg34e89502010-02-03 13:59:58 +01001399 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001400 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001401 rcu_read_unlock();
1402 return err;
1403 }
1404
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001405 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001406 ieee80211_send_layer2_update(sta);
1407
1408 rcu_read_unlock();
1409
Johannes Berg4fd69312007-12-19 02:03:35 +01001410 return 0;
1411}
1412
1413static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1414 u8 *mac)
1415{
Johannes Berg14db74b2008-07-29 13:22:52 +02001416 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001417
Johannes Berg14db74b2008-07-29 13:22:52 +02001418 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1419
Johannes Berg34e89502010-02-03 13:59:58 +01001420 if (mac)
1421 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001422
Johannes Bergb998e8b2012-12-13 23:07:46 +01001423 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001424 return 0;
1425}
1426
1427static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001428 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001429 struct station_parameters *params)
1430{
Johannes Bergabe60632009-11-25 17:46:18 +01001431 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001432 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001433 struct sta_info *sta;
1434 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001435 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001436 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001437
Johannes Berg87be1e12011-12-14 12:20:29 +01001438 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001439
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001440 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001441 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001442 err = -ENOENT;
1443 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001444 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001445
Johannes Berg77ee7c82013-02-15 00:48:33 +01001446 switch (sdata->vif.type) {
1447 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001448 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001449 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001450 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001451 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001452 break;
1453 case NL80211_IFTYPE_ADHOC:
1454 statype = CFG80211_STA_IBSS;
1455 break;
1456 case NL80211_IFTYPE_STATION:
1457 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1458 statype = CFG80211_STA_AP_STA;
1459 break;
1460 }
1461 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1462 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1463 else
1464 statype = CFG80211_STA_TDLS_PEER_SETUP;
1465 break;
1466 case NL80211_IFTYPE_AP:
1467 case NL80211_IFTYPE_AP_VLAN:
1468 statype = CFG80211_STA_AP_CLIENT;
1469 break;
1470 default:
1471 err = -EOPNOTSUPP;
1472 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001473 }
1474
Johannes Berg77ee7c82013-02-15 00:48:33 +01001475 err = cfg80211_check_station_change(wiphy, params, statype);
1476 if (err)
1477 goto out_err;
1478
Johannes Bergd0709a62008-02-25 16:27:46 +01001479 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001480 bool prev_4addr = false;
1481 bool new_4addr = false;
1482
Johannes Berg4fd69312007-12-19 02:03:35 +01001483 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1484
Johannes Berg9bc383d2009-11-19 11:55:19 +01001485 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001486 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001487 err = -EBUSY;
1488 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001489 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001490
Eric Dumazetcf778b02012-01-12 04:41:32 +00001491 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001492 new_4addr = true;
1493 }
1494
1495 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1496 sta->sdata->u.vlan.sta) {
1497 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1498 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001499 }
1500
Johannes Berg14db74b2008-07-29 13:22:52 +02001501 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001502
1503 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1504 prev_4addr != new_4addr) {
1505 if (new_4addr)
1506 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1507 else
1508 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1509 }
1510
Johannes Berg4fd69312007-12-19 02:03:35 +01001511 ieee80211_send_layer2_update(sta);
1512 }
1513
Eliad Peller35b88622011-12-29 14:41:39 +02001514 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001515 if (err)
1516 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001517
Johannes Berg77ee7c82013-02-15 00:48:33 +01001518 /* When peer becomes authorized, init rate control as well */
1519 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1520 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001521 rate_control_rate_init(sta);
1522
Johannes Berg87be1e12011-12-14 12:20:29 +01001523 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001524
Jason Young808118c2011-03-10 16:43:19 -08001525 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001526 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001527 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001528 ieee80211_recalc_ps_vif(sdata);
1529 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001530
Johannes Berg4fd69312007-12-19 02:03:35 +01001531 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001532out_err:
1533 mutex_unlock(&local->sta_mtx);
1534 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001535}
1536
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001537#ifdef CONFIG_MAC80211_MESH
1538static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1539 u8 *dst, u8 *next_hop)
1540{
Johannes Berg14db74b2008-07-29 13:22:52 +02001541 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001542 struct mesh_path *mpath;
1543 struct sta_info *sta;
1544 int err;
1545
Johannes Berg14db74b2008-07-29 13:22:52 +02001546 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1547
Johannes Bergd0709a62008-02-25 16:27:46 +01001548 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001549 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001550 if (!sta) {
1551 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001552 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001553 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001554
Johannes Bergbf7cd942013-02-15 14:40:31 +01001555 err = mesh_path_add(sdata, dst);
Johannes Bergd0709a62008-02-25 16:27:46 +01001556 if (err) {
1557 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001558 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001559 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001560
Johannes Bergbf7cd942013-02-15 14:40:31 +01001561 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001562 if (!mpath) {
1563 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001564 return -ENXIO;
1565 }
1566 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001567
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001568 rcu_read_unlock();
1569 return 0;
1570}
1571
1572static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001573 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001574{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001575 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001576
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001577 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001578 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001579
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001580 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001581 return 0;
1582}
1583
1584static int ieee80211_change_mpath(struct wiphy *wiphy,
1585 struct net_device *dev,
1586 u8 *dst, u8 *next_hop)
1587{
Johannes Berg14db74b2008-07-29 13:22:52 +02001588 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001589 struct mesh_path *mpath;
1590 struct sta_info *sta;
1591
Johannes Berg14db74b2008-07-29 13:22:52 +02001592 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1593
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001594 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001595
Johannes Bergabe60632009-11-25 17:46:18 +01001596 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001597 if (!sta) {
1598 rcu_read_unlock();
1599 return -ENOENT;
1600 }
1601
Johannes Bergbf7cd942013-02-15 14:40:31 +01001602 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001603 if (!mpath) {
1604 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001605 return -ENOENT;
1606 }
1607
1608 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001609
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001610 rcu_read_unlock();
1611 return 0;
1612}
1613
1614static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1615 struct mpath_info *pinfo)
1616{
Johannes Berga3836e02011-05-12 15:11:37 +02001617 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1618
1619 if (next_hop_sta)
1620 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001621 else
1622 memset(next_hop, 0, ETH_ALEN);
1623
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001624 memset(pinfo, 0, sizeof(*pinfo));
1625
Johannes Bergf5ea9122009-08-07 16:17:38 +02001626 pinfo->generation = mesh_paths_generation;
1627
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001628 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001629 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001630 MPATH_INFO_METRIC |
1631 MPATH_INFO_EXPTIME |
1632 MPATH_INFO_DISCOVERY_TIMEOUT |
1633 MPATH_INFO_DISCOVERY_RETRIES |
1634 MPATH_INFO_FLAGS;
1635
1636 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001637 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001638 pinfo->metric = mpath->metric;
1639 if (time_before(jiffies, mpath->exp_time))
1640 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1641 pinfo->discovery_timeout =
1642 jiffies_to_msecs(mpath->discovery_timeout);
1643 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001644 if (mpath->flags & MESH_PATH_ACTIVE)
1645 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1646 if (mpath->flags & MESH_PATH_RESOLVING)
1647 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001648 if (mpath->flags & MESH_PATH_SN_VALID)
1649 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001650 if (mpath->flags & MESH_PATH_FIXED)
1651 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001652 if (mpath->flags & MESH_PATH_RESOLVED)
1653 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001654}
1655
1656static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1657 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1658
1659{
Johannes Berg14db74b2008-07-29 13:22:52 +02001660 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001661 struct mesh_path *mpath;
1662
Johannes Berg14db74b2008-07-29 13:22:52 +02001663 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1664
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001665 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001666 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001667 if (!mpath) {
1668 rcu_read_unlock();
1669 return -ENOENT;
1670 }
1671 memcpy(dst, mpath->dst, ETH_ALEN);
1672 mpath_set_pinfo(mpath, next_hop, pinfo);
1673 rcu_read_unlock();
1674 return 0;
1675}
1676
1677static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1678 int idx, u8 *dst, u8 *next_hop,
1679 struct mpath_info *pinfo)
1680{
Johannes Berg14db74b2008-07-29 13:22:52 +02001681 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001682 struct mesh_path *mpath;
1683
Johannes Berg14db74b2008-07-29 13:22:52 +02001684 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1685
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001686 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001687 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001688 if (!mpath) {
1689 rcu_read_unlock();
1690 return -ENOENT;
1691 }
1692 memcpy(dst, mpath->dst, ETH_ALEN);
1693 mpath_set_pinfo(mpath, next_hop, pinfo);
1694 rcu_read_unlock();
1695 return 0;
1696}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001697
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001698static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001699 struct net_device *dev,
1700 struct mesh_config *conf)
1701{
1702 struct ieee80211_sub_if_data *sdata;
1703 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1704
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001705 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1706 return 0;
1707}
1708
1709static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1710{
1711 return (mask >> (parm-1)) & 0x1;
1712}
1713
Javier Cardonac80d5452010-12-16 17:37:49 -08001714static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1715 const struct mesh_setup *setup)
1716{
1717 u8 *new_ie;
1718 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001719 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1720 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001721
Javier Cardona581a8b02011-04-07 15:08:27 -07001722 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001723 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001724 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001725
Javier Cardona581a8b02011-04-07 15:08:27 -07001726 if (setup->ie_len) {
1727 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001728 GFP_KERNEL);
1729 if (!new_ie)
1730 return -ENOMEM;
1731 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001732 ifmsh->ie_len = setup->ie_len;
1733 ifmsh->ie = new_ie;
1734 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001735
1736 /* now copy the rest of the setup parameters */
1737 ifmsh->mesh_id_len = setup->mesh_id_len;
1738 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001739 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001740 ifmsh->mesh_pp_id = setup->path_sel_proto;
1741 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001742 ifmsh->user_mpm = setup->user_mpm;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001743 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1744 if (setup->is_authenticated)
1745 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1746 if (setup->is_secure)
1747 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001748
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001749 /* mcast rate setting in Mesh Node */
1750 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1751 sizeof(setup->mcast_rate));
1752
Marco Porsch9bdbf042013-01-07 16:04:51 +01001753 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1754 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1755
Javier Cardonac80d5452010-12-16 17:37:49 -08001756 return 0;
1757}
1758
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001759static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001760 struct net_device *dev, u32 mask,
1761 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001762{
1763 struct mesh_config *conf;
1764 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001765 struct ieee80211_if_mesh *ifmsh;
1766
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001767 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001768 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001769
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001770 /* Set the config options which we are interested in setting */
1771 conf = &(sdata->u.mesh.mshcfg);
1772 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1773 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1774 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1775 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1776 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1777 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1778 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1779 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1780 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1781 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1782 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1783 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001784 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001785 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001786 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1787 if (ifmsh->user_mpm)
1788 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001789 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001790 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001791 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1792 conf->dot11MeshNbrOffsetMaxNeighbor =
1793 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001794 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1795 conf->dot11MeshHWMPmaxPREQretries =
1796 nconf->dot11MeshHWMPmaxPREQretries;
1797 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1798 conf->path_refresh_time = nconf->path_refresh_time;
1799 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1800 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1801 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1802 conf->dot11MeshHWMPactivePathTimeout =
1803 nconf->dot11MeshHWMPactivePathTimeout;
1804 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1805 conf->dot11MeshHWMPpreqMinInterval =
1806 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001807 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1808 conf->dot11MeshHWMPperrMinInterval =
1809 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001810 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1811 mask))
1812 conf->dot11MeshHWMPnetDiameterTraversalTime =
1813 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001814 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1815 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1816 ieee80211_mesh_root_setup(ifmsh);
1817 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001818 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001819 /* our current gate announcement implementation rides on root
1820 * announcements, so require this ifmsh to also be a root node
1821 * */
1822 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001823 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1824 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001825 ieee80211_mesh_root_setup(ifmsh);
1826 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001827 conf->dot11MeshGateAnnouncementProtocol =
1828 nconf->dot11MeshGateAnnouncementProtocol;
1829 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001830 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001831 conf->dot11MeshHWMPRannInterval =
1832 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001833 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1834 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001835 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1836 /* our RSSI threshold implementation is supported only for
1837 * devices that report signal in dBm.
1838 */
1839 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1840 return -ENOTSUPP;
1841 conf->rssi_threshold = nconf->rssi_threshold;
1842 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001843 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1844 conf->ht_opmode = nconf->ht_opmode;
1845 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1846 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1847 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001848 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1849 conf->dot11MeshHWMPactivePathToRootTimeout =
1850 nconf->dot11MeshHWMPactivePathToRootTimeout;
1851 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1852 conf->dot11MeshHWMProotInterval =
1853 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001854 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1855 conf->dot11MeshHWMPconfirmationInterval =
1856 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001857 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1858 conf->power_mode = nconf->power_mode;
1859 ieee80211_mps_local_status_update(sdata);
1860 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001861 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001862 conf->dot11MeshAwakeWindowDuration =
1863 nconf->dot11MeshAwakeWindowDuration;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001864 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001865 return 0;
1866}
1867
Johannes Berg29cbe682010-12-03 09:20:44 +01001868static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1869 const struct mesh_config *conf,
1870 const struct mesh_setup *setup)
1871{
1872 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1873 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001874 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001875
Javier Cardonac80d5452010-12-16 17:37:49 -08001876 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1877 err = copy_mesh_setup(ifmsh, setup);
1878 if (err)
1879 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001880
Johannes Berg04ecd252012-09-11 14:34:12 +02001881 /* can mesh use other SMPS modes? */
1882 sdata->smps_mode = IEEE80211_SMPS_OFF;
1883 sdata->needed_rx_chains = sdata->local->rx_chains;
1884
Johannes Berg4bf88532012-11-09 11:39:59 +01001885 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001886 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001887 if (err)
1888 return err;
1889
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001890 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001891}
1892
1893static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1894{
1895 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1896
1897 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001898 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001899
1900 return 0;
1901}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001902#endif
1903
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001904static int ieee80211_change_bss(struct wiphy *wiphy,
1905 struct net_device *dev,
1906 struct bss_parameters *params)
1907{
Johannes Berg55de9082012-07-26 17:24:39 +02001908 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1909 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001910 u32 changed = 0;
1911
Johannes Berg55de9082012-07-26 17:24:39 +02001912 if (!rtnl_dereference(sdata->u.ap.beacon))
1913 return -ENOENT;
1914
1915 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001916
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001917 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001918 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001919 changed |= BSS_CHANGED_ERP_CTS_PROT;
1920 }
1921 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001922 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001923 params->use_short_preamble;
1924 changed |= BSS_CHANGED_ERP_PREAMBLE;
1925 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001926
1927 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001928 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001929 sdata->vif.bss_conf.use_short_slot = true;
1930 changed |= BSS_CHANGED_ERP_SLOT;
1931 }
1932
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001933 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001934 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001935 params->use_short_slot_time;
1936 changed |= BSS_CHANGED_ERP_SLOT;
1937 }
1938
Jouni Malinen90c97a02008-10-30 16:59:22 +02001939 if (params->basic_rates) {
1940 int i, j;
1941 u32 rates = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02001942 struct ieee80211_supported_band *sband = wiphy->bands[band];
Jouni Malinen90c97a02008-10-30 16:59:22 +02001943
1944 for (i = 0; i < params->basic_rates_len; i++) {
1945 int rate = (params->basic_rates[i] & 0x7f) * 5;
1946 for (j = 0; j < sband->n_bitrates; j++) {
1947 if (sband->bitrates[j].bitrate == rate)
1948 rates |= BIT(j);
1949 }
1950 }
1951 sdata->vif.bss_conf.basic_rates = rates;
1952 changed |= BSS_CHANGED_BASIC_RATES;
1953 }
1954
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001955 if (params->ap_isolate >= 0) {
1956 if (params->ap_isolate)
1957 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1958 else
1959 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1960 }
1961
Helmut Schaa80d7e402010-11-19 12:40:26 +01001962 if (params->ht_opmode >= 0) {
1963 sdata->vif.bss_conf.ht_operation_mode =
1964 (u16) params->ht_opmode;
1965 changed |= BSS_CHANGED_HT;
1966 }
1967
Johannes Berg339afbf2012-11-14 15:21:17 +01001968 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001969 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1970 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1971 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1972 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01001973 changed |= BSS_CHANGED_P2P_PS;
1974 }
1975
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001976 if (params->p2p_opp_ps > 0) {
1977 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1978 IEEE80211_P2P_OPPPS_ENABLE_BIT;
1979 changed |= BSS_CHANGED_P2P_PS;
1980 } else if (params->p2p_opp_ps == 0) {
1981 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
1982 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001983 changed |= BSS_CHANGED_P2P_PS;
1984 }
1985
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001986 ieee80211_bss_info_change_notify(sdata, changed);
1987
1988 return 0;
1989}
1990
Jouni Malinen31888482008-10-30 16:59:24 +02001991static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001992 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001993 struct ieee80211_txq_params *params)
1994{
1995 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001996 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001997 struct ieee80211_tx_queue_params p;
1998
1999 if (!local->ops->conf_tx)
2000 return -EOPNOTSUPP;
2001
Johannes Berg54bcbc62012-03-28 11:04:25 +02002002 if (local->hw.queues < IEEE80211_NUM_ACS)
2003 return -EOPNOTSUPP;
2004
Jouni Malinen31888482008-10-30 16:59:24 +02002005 memset(&p, 0, sizeof(p));
2006 p.aifs = params->aifs;
2007 p.cw_max = params->cwmax;
2008 p.cw_min = params->cwmin;
2009 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002010
2011 /*
2012 * Setting tx queue params disables u-apsd because it's only
2013 * called in master mode.
2014 */
2015 p.uapsd = false;
2016
Johannes Berga3304b02012-03-28 11:04:24 +02002017 sdata->tx_conf[params->ac] = p;
2018 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002019 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002020 "failed to set TX queue parameters for AC %d\n",
2021 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002022 return -EINVAL;
2023 }
2024
Johannes Berg7d257452012-07-06 17:37:43 +02002025 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2026
Jouni Malinen31888482008-10-30 16:59:24 +02002027 return 0;
2028}
2029
Bob Copeland665af4f2009-01-19 11:20:53 -05002030#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002031static int ieee80211_suspend(struct wiphy *wiphy,
2032 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002033{
Johannes Bergeecc4802011-05-04 15:37:29 +02002034 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002035}
2036
2037static int ieee80211_resume(struct wiphy *wiphy)
2038{
2039 return __ieee80211_resume(wiphy_priv(wiphy));
2040}
2041#else
2042#define ieee80211_suspend NULL
2043#define ieee80211_resume NULL
2044#endif
2045
Johannes Berg2a519312009-02-10 21:25:55 +01002046static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002047 struct cfg80211_scan_request *req)
2048{
Johannes Bergfd014282012-06-18 19:17:03 +02002049 struct ieee80211_sub_if_data *sdata;
2050
2051 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002052
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002053 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2054 case NL80211_IFTYPE_STATION:
2055 case NL80211_IFTYPE_ADHOC:
2056 case NL80211_IFTYPE_MESH_POINT:
2057 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002058 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002059 break;
2060 case NL80211_IFTYPE_P2P_GO:
2061 if (sdata->local->ops->hw_scan)
2062 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002063 /*
2064 * FIXME: implement NoA while scanning in software,
2065 * for now fall through to allow scanning only when
2066 * beaconing hasn't been configured yet
2067 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002068 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002069 /*
2070 * If the scan has been forced (and the driver supports
2071 * forcing), don't care about being beaconing already.
2072 * This will create problems to the attached stations (e.g. all
2073 * the frames sent while scanning on other channel will be
2074 * lost)
2075 */
2076 if (sdata->u.ap.beacon &&
2077 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2078 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002079 return -EOPNOTSUPP;
2080 break;
2081 default:
2082 return -EOPNOTSUPP;
2083 }
Johannes Berg2a519312009-02-10 21:25:55 +01002084
2085 return ieee80211_request_scan(sdata, req);
2086}
2087
Luciano Coelho79f460c2011-05-11 17:09:36 +03002088static int
2089ieee80211_sched_scan_start(struct wiphy *wiphy,
2090 struct net_device *dev,
2091 struct cfg80211_sched_scan_request *req)
2092{
2093 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2094
2095 if (!sdata->local->ops->sched_scan_start)
2096 return -EOPNOTSUPP;
2097
2098 return ieee80211_request_sched_scan_start(sdata, req);
2099}
2100
2101static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002102ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002103{
2104 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2105
2106 if (!sdata->local->ops->sched_scan_stop)
2107 return -EOPNOTSUPP;
2108
Luciano Coelho85a99942011-05-12 16:28:29 +03002109 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002110}
2111
Jouni Malinen636a5d32009-03-19 13:39:22 +02002112static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2113 struct cfg80211_auth_request *req)
2114{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002115 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002116}
2117
2118static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2119 struct cfg80211_assoc_request *req)
2120{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002121 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002122}
2123
2124static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002125 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002126{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002127 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002128}
2129
2130static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002131 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002132{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002133 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002134}
2135
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002136static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2137 struct cfg80211_ibss_params *params)
2138{
Johannes Berg55de9082012-07-26 17:24:39 +02002139 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002140}
2141
2142static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2143{
Johannes Berg55de9082012-07-26 17:24:39 +02002144 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002145}
2146
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002147static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2148 int rate[IEEE80211_NUM_BANDS])
2149{
2150 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2151
Cong Ding9887dbf2013-02-06 17:23:45 +01002152 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2153 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002154
2155 return 0;
2156}
2157
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002158static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2159{
2160 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002161 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002162
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002163 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2164 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2165
2166 if (err)
2167 return err;
2168 }
2169
Lukáš Turek310bc672009-12-21 22:50:48 +01002170 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2171 err = drv_set_coverage_class(local, wiphy->coverage_class);
2172
2173 if (err)
2174 return err;
2175 }
2176
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002177 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002178 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002179
Johannes Berg24487982009-04-23 18:52:52 +02002180 if (err)
2181 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002182 }
2183
Johannes Berg8bc83c22012-11-09 18:38:32 +01002184 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2185 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2186 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002187 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002188 }
2189 if (changed & WIPHY_PARAM_RETRY_LONG) {
2190 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2191 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002192 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002193 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002194 if (changed &
2195 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2196 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2197
2198 return 0;
2199}
2200
Johannes Berg7643a2c2009-06-02 13:01:39 +02002201static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002202 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002203 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002204{
2205 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002206 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002207
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002208 if (wdev) {
2209 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2210
2211 switch (type) {
2212 case NL80211_TX_POWER_AUTOMATIC:
2213 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2214 break;
2215 case NL80211_TX_POWER_LIMITED:
2216 case NL80211_TX_POWER_FIXED:
2217 if (mbm < 0 || (mbm % 100))
2218 return -EOPNOTSUPP;
2219 sdata->user_power_level = MBM_TO_DBM(mbm);
2220 break;
2221 }
2222
2223 ieee80211_recalc_txpower(sdata);
2224
2225 return 0;
2226 }
Johannes Berg55de9082012-07-26 17:24:39 +02002227
Johannes Berg7643a2c2009-06-02 13:01:39 +02002228 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002229 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002230 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002231 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002232 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002233 case NL80211_TX_POWER_FIXED:
2234 if (mbm < 0 || (mbm % 100))
2235 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002236 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002237 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002238 }
2239
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002240 mutex_lock(&local->iflist_mtx);
2241 list_for_each_entry(sdata, &local->interfaces, list)
2242 sdata->user_power_level = local->user_power_level;
2243 list_for_each_entry(sdata, &local->interfaces, list)
2244 ieee80211_recalc_txpower(sdata);
2245 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002246
2247 return 0;
2248}
2249
Johannes Bergc8442112012-10-24 10:17:18 +02002250static int ieee80211_get_tx_power(struct wiphy *wiphy,
2251 struct wireless_dev *wdev,
2252 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002253{
2254 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002255 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002256
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002257 if (!local->use_chanctx)
2258 *dbm = local->hw.conf.power_level;
2259 else
2260 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002261
Johannes Berg7643a2c2009-06-02 13:01:39 +02002262 return 0;
2263}
2264
Johannes Bergab737a42009-07-01 21:26:58 +02002265static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002266 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002267{
2268 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2269
2270 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2271
2272 return 0;
2273}
2274
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002275static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2276{
2277 struct ieee80211_local *local = wiphy_priv(wiphy);
2278
2279 drv_rfkill_poll(local);
2280}
2281
Johannes Bergaff89a92009-07-01 21:26:51 +02002282#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002283static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002284{
2285 struct ieee80211_local *local = wiphy_priv(wiphy);
2286
2287 if (!local->ops->testmode_cmd)
2288 return -EOPNOTSUPP;
2289
2290 return local->ops->testmode_cmd(&local->hw, data, len);
2291}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002292
2293static int ieee80211_testmode_dump(struct wiphy *wiphy,
2294 struct sk_buff *skb,
2295 struct netlink_callback *cb,
2296 void *data, int len)
2297{
2298 struct ieee80211_local *local = wiphy_priv(wiphy);
2299
2300 if (!local->ops->testmode_dump)
2301 return -EOPNOTSUPP;
2302
2303 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2304}
Johannes Bergaff89a92009-07-01 21:26:51 +02002305#endif
2306
Johannes Berg0f782312009-12-01 13:37:02 +01002307int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2308 enum ieee80211_smps_mode smps_mode)
2309{
2310 const u8 *ap;
2311 enum ieee80211_smps_mode old_req;
2312 int err;
2313
Johannes Berg243e6df2011-04-19 20:44:04 +02002314 lockdep_assert_held(&sdata->u.mgd.mtx);
2315
Johannes Berg0f782312009-12-01 13:37:02 +01002316 old_req = sdata->u.mgd.req_smps;
2317 sdata->u.mgd.req_smps = smps_mode;
2318
2319 if (old_req == smps_mode &&
2320 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2321 return 0;
2322
2323 /*
2324 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002325 * association, there's no need to do anything, just store
2326 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002327 */
2328 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002329 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002330 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002331
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002332 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002333
2334 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2335 if (sdata->u.mgd.powersave)
2336 smps_mode = IEEE80211_SMPS_DYNAMIC;
2337 else
2338 smps_mode = IEEE80211_SMPS_OFF;
2339 }
2340
2341 /* send SM PS frame to AP */
2342 err = ieee80211_send_smps_action(sdata, smps_mode,
2343 ap, ap);
2344 if (err)
2345 sdata->u.mgd.req_smps = old_req;
2346
2347 return err;
2348}
2349
Johannes Bergbc92afd2009-07-01 21:26:57 +02002350static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2351 bool enabled, int timeout)
2352{
2353 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2354 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002355
Chun-Yeow Yeohee1f6682013-01-10 23:31:54 +08002356 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2357 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002358 return -EOPNOTSUPP;
2359
Johannes Bergbc92afd2009-07-01 21:26:57 +02002360 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2361 return -EOPNOTSUPP;
2362
2363 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002364 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002365 return 0;
2366
2367 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002368 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002369
Johannes Berg0f782312009-12-01 13:37:02 +01002370 /* no change, but if automatic follow powersave */
2371 mutex_lock(&sdata->u.mgd.mtx);
2372 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2373 mutex_unlock(&sdata->u.mgd.mtx);
2374
Johannes Bergbc92afd2009-07-01 21:26:57 +02002375 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2376 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2377
2378 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002379 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002380
2381 return 0;
2382}
2383
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002384static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2385 struct net_device *dev,
2386 s32 rssi_thold, u32 rssi_hyst)
2387{
2388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002389 struct ieee80211_vif *vif = &sdata->vif;
2390 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2391
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002392 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2393 rssi_hyst == bss_conf->cqm_rssi_hyst)
2394 return 0;
2395
2396 bss_conf->cqm_rssi_thold = rssi_thold;
2397 bss_conf->cqm_rssi_hyst = rssi_hyst;
2398
2399 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002400 if (sdata->u.mgd.associated &&
2401 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002402 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2403
2404 return 0;
2405}
2406
Johannes Berg99303802009-07-01 21:26:59 +02002407static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2408 struct net_device *dev,
2409 const u8 *addr,
2410 const struct cfg80211_bitrate_mask *mask)
2411{
2412 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2413 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302414 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002415
Eliad Peller554a43d2012-06-12 12:41:15 +03002416 if (!ieee80211_sdata_running(sdata))
2417 return -ENETDOWN;
2418
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302419 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2420 ret = drv_set_bitrate_mask(local, sdata, mask);
2421 if (ret)
2422 return ret;
2423 }
Johannes Berg99303802009-07-01 21:26:59 +02002424
Simon Wunderlich19468412012-01-28 17:25:33 +01002425 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002426 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002427 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2428 sizeof(mask->control[i].mcs));
2429 }
Johannes Berg99303802009-07-01 21:26:59 +02002430
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002431 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002432}
2433
Johannes Berg2eb278e2012-06-05 14:28:42 +02002434static int ieee80211_start_roc_work(struct ieee80211_local *local,
2435 struct ieee80211_sub_if_data *sdata,
2436 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002437 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002438 struct sk_buff *txskb,
2439 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002440{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002441 struct ieee80211_roc_work *roc, *tmp;
2442 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002443 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002444
2445 lockdep_assert_held(&local->mtx);
2446
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002447 if (local->use_chanctx && !local->ops->remain_on_channel)
2448 return -EOPNOTSUPP;
2449
Johannes Berg2eb278e2012-06-05 14:28:42 +02002450 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2451 if (!roc)
2452 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002453
Johannes Berg2eb278e2012-06-05 14:28:42 +02002454 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002455 roc->duration = duration;
2456 roc->req_duration = duration;
2457 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002458 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002459 roc->mgmt_tx_cookie = (unsigned long)txskb;
2460 roc->sdata = sdata;
2461 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2462 INIT_LIST_HEAD(&roc->dependents);
2463
2464 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002465 if (!list_empty(&local->roc_list) ||
2466 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002467 goto out_check_combine;
2468
2469 /* if not HW assist, just queue & schedule work */
2470 if (!local->ops->remain_on_channel) {
2471 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2472 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002473 }
2474
Johannes Berg2eb278e2012-06-05 14:28:42 +02002475 /* otherwise actually kick it off here (for error handling) */
2476
2477 /*
2478 * If the duration is zero, then the driver
2479 * wouldn't actually do anything. Set it to
2480 * 10 for now.
2481 *
2482 * TODO: cancel the off-channel operation
2483 * when we get the SKB's TX status and
2484 * the wait time was zero before.
2485 */
2486 if (!duration)
2487 duration = 10;
2488
Ilan Peerd339d5c2013-02-12 09:34:13 +02002489 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002490 if (ret) {
2491 kfree(roc);
2492 return ret;
2493 }
2494
2495 roc->started = true;
2496 goto out_queue;
2497
2498 out_check_combine:
2499 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002500 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002501 continue;
2502
2503 /*
2504 * Extend this ROC if possible:
2505 *
2506 * If it hasn't started yet, just increase the duration
2507 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002508 * If the type of the new ROC has higher priority, modify the
2509 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002510 */
2511 if (!tmp->started) {
2512 list_add_tail(&roc->list, &tmp->dependents);
2513 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002514 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002515 queued = true;
2516 break;
2517 }
2518
2519 /* If it has already started, it's more difficult ... */
2520 if (local->ops->remain_on_channel) {
2521 unsigned long j = jiffies;
2522
2523 /*
2524 * In the offloaded ROC case, if it hasn't begun, add
2525 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002526 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002527 * check that there's still a minimum time left and
2528 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002529 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002530 * a reduced time so we'll ask the driver to execute
2531 * it right after finishing the previous one, in the
2532 * hope that it'll also be executed right afterwards,
2533 * effectively extending the old one.
2534 * If there's no minimum time left, just add it to the
2535 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002536 * TODO: the ROC type is ignored here, assuming that it
2537 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002538 */
2539 if (!tmp->hw_begun) {
2540 list_add_tail(&roc->list, &tmp->dependents);
2541 queued = true;
2542 break;
2543 }
2544
2545 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2546 tmp->hw_start_time +
2547 msecs_to_jiffies(tmp->duration))) {
2548 int new_dur;
2549
2550 ieee80211_handle_roc_started(roc);
2551
2552 new_dur = roc->duration -
2553 jiffies_to_msecs(tmp->hw_start_time +
2554 msecs_to_jiffies(
2555 tmp->duration) -
2556 j);
2557
2558 if (new_dur > 0) {
2559 /* add right after tmp */
2560 list_add(&roc->list, &tmp->list);
2561 } else {
2562 list_add_tail(&roc->list,
2563 &tmp->dependents);
2564 }
2565 queued = true;
2566 }
2567 } else if (del_timer_sync(&tmp->work.timer)) {
2568 unsigned long new_end;
2569
2570 /*
2571 * In the software ROC case, cancel the timer, if
2572 * that fails then the finish work is already
2573 * queued/pending and thus we queue the new ROC
2574 * normally, if that succeeds then we can extend
2575 * the timer duration and TX the frame (if any.)
2576 */
2577
2578 list_add_tail(&roc->list, &tmp->dependents);
2579 queued = true;
2580
2581 new_end = jiffies + msecs_to_jiffies(roc->duration);
2582
2583 /* ok, it was started & we canceled timer */
2584 if (time_after(new_end, tmp->work.timer.expires))
2585 mod_timer(&tmp->work.timer, new_end);
2586 else
2587 add_timer(&tmp->work.timer);
2588
2589 ieee80211_handle_roc_started(roc);
2590 }
2591 break;
2592 }
2593
2594 out_queue:
2595 if (!queued)
2596 list_add_tail(&roc->list, &local->roc_list);
2597
2598 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002599 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002600 * or the SKB (for mgmt TX)
2601 */
Johannes Berg50febf62012-10-26 16:13:06 +02002602 if (!txskb) {
2603 /* local->mtx protects this */
2604 local->roc_cookie_counter++;
2605 roc->cookie = local->roc_cookie_counter;
2606 /* wow, you wrapped 64 bits ... more likely a bug */
2607 if (WARN_ON(roc->cookie == 0)) {
2608 roc->cookie = 1;
2609 local->roc_cookie_counter++;
2610 }
2611 *cookie = roc->cookie;
2612 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002613 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002614 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002615
2616 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002617}
2618
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002619static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002620 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002621 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002622 unsigned int duration,
2623 u64 *cookie)
2624{
Johannes Berg71bbc992012-06-15 15:30:18 +02002625 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002626 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002627 int ret;
2628
Johannes Berg2eb278e2012-06-05 14:28:42 +02002629 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002630 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002631 duration, cookie, NULL,
2632 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002633 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002634
Johannes Berg2eb278e2012-06-05 14:28:42 +02002635 return ret;
2636}
2637
2638static int ieee80211_cancel_roc(struct ieee80211_local *local,
2639 u64 cookie, bool mgmt_tx)
2640{
2641 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2642 int ret;
2643
2644 mutex_lock(&local->mtx);
2645 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002646 struct ieee80211_roc_work *dep, *tmp2;
2647
2648 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002649 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002650 continue;
2651 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2652 continue;
2653 /* found dependent item -- just remove it */
2654 list_del(&dep->list);
2655 mutex_unlock(&local->mtx);
2656
2657 ieee80211_roc_notify_destroy(dep);
2658 return 0;
2659 }
2660
Johannes Berg50febf62012-10-26 16:13:06 +02002661 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002662 continue;
2663 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2664 continue;
2665
2666 found = roc;
2667 break;
2668 }
2669
2670 if (!found) {
2671 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002672 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002673 }
Johannes Berg21f83582010-12-18 17:20:47 +01002674
Johannes Berge979e332012-06-11 17:09:41 +02002675 /*
2676 * We found the item to cancel, so do that. Note that it
2677 * may have dependents, which we also cancel (and send
2678 * the expired signal for.) Not doing so would be quite
2679 * tricky here, but we may need to fix it later.
2680 */
2681
Johannes Berg2eb278e2012-06-05 14:28:42 +02002682 if (local->ops->remain_on_channel) {
2683 if (found->started) {
2684 ret = drv_cancel_remain_on_channel(local);
2685 if (WARN_ON_ONCE(ret)) {
2686 mutex_unlock(&local->mtx);
2687 return ret;
2688 }
2689 }
Johannes Berg21f83582010-12-18 17:20:47 +01002690
Johannes Berg2eb278e2012-06-05 14:28:42 +02002691 list_del(&found->list);
2692
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002693 if (found->started)
2694 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002695 mutex_unlock(&local->mtx);
2696
2697 ieee80211_roc_notify_destroy(found);
2698 } else {
2699 /* work may be pending so use it all the time */
2700 found->abort = true;
2701 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2702
2703 mutex_unlock(&local->mtx);
2704
2705 /* work will clean up etc */
2706 flush_delayed_work(&found->work);
2707 }
Johannes Berg21f83582010-12-18 17:20:47 +01002708
Johannes Berg21f83582010-12-18 17:20:47 +01002709 return 0;
2710}
2711
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002712static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002713 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002714 u64 cookie)
2715{
Johannes Berg71bbc992012-06-15 15:30:18 +02002716 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002717 struct ieee80211_local *local = sdata->local;
2718
Johannes Berg2eb278e2012-06-05 14:28:42 +02002719 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002720}
2721
Simon Wunderlich164eb022013-02-08 18:16:20 +01002722static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2723 struct net_device *dev,
2724 struct cfg80211_chan_def *chandef)
2725{
2726 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2727 struct ieee80211_local *local = sdata->local;
2728 unsigned long timeout;
2729 int err;
2730
2731 if (!list_empty(&local->roc_list) || local->scanning)
2732 return -EBUSY;
2733
2734 /* whatever, but channel contexts should not complain about that one */
2735 sdata->smps_mode = IEEE80211_SMPS_OFF;
2736 sdata->needed_rx_chains = local->rx_chains;
2737 sdata->radar_required = true;
2738
2739 mutex_lock(&local->iflist_mtx);
2740 err = ieee80211_vif_use_channel(sdata, chandef,
2741 IEEE80211_CHANCTX_SHARED);
2742 mutex_unlock(&local->iflist_mtx);
2743 if (err)
2744 return err;
2745
2746 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2747 ieee80211_queue_delayed_work(&sdata->local->hw,
2748 &sdata->dfs_cac_timer_work, timeout);
2749
2750 return 0;
2751}
2752
Johannes Berg71bbc992012-06-15 15:30:18 +02002753static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002754 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01002755 unsigned int wait, const u8 *buf, size_t len,
2756 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002757{
Johannes Berg71bbc992012-06-15 15:30:18 +02002758 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002759 struct ieee80211_local *local = sdata->local;
2760 struct sk_buff *skb;
2761 struct sta_info *sta;
2762 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002763 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002764 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002765 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002766
Johannes Berge247bd902011-11-04 11:18:21 +01002767 if (dont_wait_for_ack)
2768 flags = IEEE80211_TX_CTL_NO_ACK;
2769 else
2770 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2771 IEEE80211_TX_CTL_REQ_TX_STATUS;
2772
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302773 if (no_cck)
2774 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2775
Johannes Berg9d38d852010-06-09 17:20:33 +02002776 switch (sdata->vif.type) {
2777 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002778 if (!sdata->vif.bss_conf.ibss_joined)
2779 need_offchan = true;
2780 /* fall through */
2781#ifdef CONFIG_MAC80211_MESH
2782 case NL80211_IFTYPE_MESH_POINT:
2783 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2784 !sdata->u.mesh.mesh_id_len)
2785 need_offchan = true;
2786 /* fall through */
2787#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002788 case NL80211_IFTYPE_AP:
2789 case NL80211_IFTYPE_AP_VLAN:
2790 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002791 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2792 !ieee80211_vif_is_mesh(&sdata->vif) &&
2793 !rcu_access_pointer(sdata->bss->beacon))
2794 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002795 if (!ieee80211_is_action(mgmt->frame_control) ||
2796 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002797 break;
2798 rcu_read_lock();
2799 sta = sta_info_get(sdata, mgmt->da);
2800 rcu_read_unlock();
2801 if (!sta)
2802 return -ENOLINK;
2803 break;
2804 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002805 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002806 if (!sdata->u.mgd.associated)
2807 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002808 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002809 case NL80211_IFTYPE_P2P_DEVICE:
2810 need_offchan = true;
2811 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002812 default:
2813 return -EOPNOTSUPP;
2814 }
2815
Johannes Berg2eb278e2012-06-05 14:28:42 +02002816 mutex_lock(&local->mtx);
2817
2818 /* Check if the operating channel is the requested channel */
2819 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02002820 struct ieee80211_chanctx_conf *chanctx_conf;
2821
2822 rcu_read_lock();
2823 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2824
Johannes Berg42d97a52012-11-08 18:31:02 +01002825 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +01002826 need_offchan = chan != chanctx_conf->def.chan;
Johannes Berg42d97a52012-11-08 18:31:02 +01002827 else
Johannes Berg2eb278e2012-06-05 14:28:42 +02002828 need_offchan = true;
Johannes Berg55de9082012-07-26 17:24:39 +02002829 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02002830 }
2831
2832 if (need_offchan && !offchan) {
2833 ret = -EBUSY;
2834 goto out_unlock;
2835 }
2836
Johannes Berg9d38d852010-06-09 17:20:33 +02002837 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002838 if (!skb) {
2839 ret = -ENOMEM;
2840 goto out_unlock;
2841 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002842 skb_reserve(skb, local->hw.extra_tx_headroom);
2843
2844 memcpy(skb_put(skb, len), buf, len);
2845
2846 IEEE80211_SKB_CB(skb)->flags = flags;
2847
Johannes Berg2eb278e2012-06-05 14:28:42 +02002848 skb->dev = sdata->dev;
2849
2850 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002851 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002852 ieee80211_tx_skb(sdata, skb);
2853 ret = 0;
2854 goto out_unlock;
2855 }
2856
Seth Forshee6c17b772013-02-11 11:21:07 -06002857 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
2858 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002859 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002860 IEEE80211_SKB_CB(skb)->hw_queue =
2861 local->hw.offchannel_tx_hw_queue;
2862
Johannes Berg2eb278e2012-06-05 14:28:42 +02002863 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01002864 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002865 wait, cookie, skb,
2866 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002867 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002868 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002869 out_unlock:
2870 mutex_unlock(&local->mtx);
2871 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002872}
2873
Johannes Bergf30221e2010-11-25 10:02:30 +01002874static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002875 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002876 u64 cookie)
2877{
Johannes Berg71bbc992012-06-15 15:30:18 +02002878 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002879
Johannes Berg2eb278e2012-06-05 14:28:42 +02002880 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002881}
2882
Johannes Berg7be50862010-10-13 12:06:24 +02002883static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002884 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002885 u16 frame_type, bool reg)
2886{
2887 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002888 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002889
Will Hawkins6abe0562012-06-20 11:51:14 -04002890 switch (frame_type) {
2891 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2892 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2893 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002894
Will Hawkins6abe0562012-06-20 11:51:14 -04002895 if (reg)
2896 ifibss->auth_frame_registrations++;
2897 else
2898 ifibss->auth_frame_registrations--;
2899 }
2900 break;
2901 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2902 if (reg)
2903 local->probe_req_reg++;
2904 else
2905 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002906
Felix Fietkau35f51492012-10-31 15:50:34 +01002907 if (!local->open_count)
2908 break;
2909
Will Hawkins6abe0562012-06-20 11:51:14 -04002910 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2911 break;
2912 default:
2913 break;
2914 }
Johannes Berg7be50862010-10-13 12:06:24 +02002915}
2916
Bruno Randolf15d96752010-11-10 12:50:56 +09002917static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2918{
2919 struct ieee80211_local *local = wiphy_priv(wiphy);
2920
2921 if (local->started)
2922 return -EOPNOTSUPP;
2923
2924 return drv_set_antenna(local, tx_ant, rx_ant);
2925}
2926
2927static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2928{
2929 struct ieee80211_local *local = wiphy_priv(wiphy);
2930
2931 return drv_get_antenna(local, tx_ant, rx_ant);
2932}
2933
John W. Linville38c09152011-03-07 16:19:18 -05002934static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2935{
2936 struct ieee80211_local *local = wiphy_priv(wiphy);
2937
2938 return drv_set_ringparam(local, tx, rx);
2939}
2940
2941static void ieee80211_get_ringparam(struct wiphy *wiphy,
2942 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2943{
2944 struct ieee80211_local *local = wiphy_priv(wiphy);
2945
2946 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2947}
2948
Johannes Bergc68f4b82011-07-05 16:35:41 +02002949static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2950 struct net_device *dev,
2951 struct cfg80211_gtk_rekey_data *data)
2952{
2953 struct ieee80211_local *local = wiphy_priv(wiphy);
2954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2955
2956 if (!local->ops->set_rekey_data)
2957 return -EOPNOTSUPP;
2958
2959 drv_set_rekey_data(local, sdata, data);
2960
2961 return 0;
2962}
2963
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002964static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2965{
2966 u8 *pos = (void *)skb_put(skb, 7);
2967
2968 *pos++ = WLAN_EID_EXT_CAPABILITY;
2969 *pos++ = 5; /* len */
2970 *pos++ = 0x0;
2971 *pos++ = 0x0;
2972 *pos++ = 0x0;
2973 *pos++ = 0x0;
2974 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2975}
2976
2977static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2978{
2979 struct ieee80211_local *local = sdata->local;
2980 u16 capab;
2981
2982 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002983 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002984 return capab;
2985
2986 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2987 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2988 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2989 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2990
2991 return capab;
2992}
2993
2994static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2995 u8 *peer, u8 *bssid)
2996{
2997 struct ieee80211_tdls_lnkie *lnkid;
2998
2999 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3000
3001 lnkid->ie_type = WLAN_EID_LINK_ID;
3002 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3003
3004 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3005 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3006 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3007}
3008
3009static int
3010ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3011 u8 *peer, u8 action_code, u8 dialog_token,
3012 u16 status_code, struct sk_buff *skb)
3013{
3014 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003015 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003016 struct ieee80211_tdls_data *tf;
3017
3018 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3019
3020 memcpy(tf->da, peer, ETH_ALEN);
3021 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3022 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3023 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3024
3025 switch (action_code) {
3026 case WLAN_TDLS_SETUP_REQUEST:
3027 tf->category = WLAN_CATEGORY_TDLS;
3028 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3029
3030 skb_put(skb, sizeof(tf->u.setup_req));
3031 tf->u.setup_req.dialog_token = dialog_token;
3032 tf->u.setup_req.capability =
3033 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3034
Johannes Berg55de9082012-07-26 17:24:39 +02003035 ieee80211_add_srates_ie(sdata, skb, false, band);
3036 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003037 ieee80211_tdls_add_ext_capab(skb);
3038 break;
3039 case WLAN_TDLS_SETUP_RESPONSE:
3040 tf->category = WLAN_CATEGORY_TDLS;
3041 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3042
3043 skb_put(skb, sizeof(tf->u.setup_resp));
3044 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3045 tf->u.setup_resp.dialog_token = dialog_token;
3046 tf->u.setup_resp.capability =
3047 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3048
Johannes Berg55de9082012-07-26 17:24:39 +02003049 ieee80211_add_srates_ie(sdata, skb, false, band);
3050 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003051 ieee80211_tdls_add_ext_capab(skb);
3052 break;
3053 case WLAN_TDLS_SETUP_CONFIRM:
3054 tf->category = WLAN_CATEGORY_TDLS;
3055 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3056
3057 skb_put(skb, sizeof(tf->u.setup_cfm));
3058 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3059 tf->u.setup_cfm.dialog_token = dialog_token;
3060 break;
3061 case WLAN_TDLS_TEARDOWN:
3062 tf->category = WLAN_CATEGORY_TDLS;
3063 tf->action_code = WLAN_TDLS_TEARDOWN;
3064
3065 skb_put(skb, sizeof(tf->u.teardown));
3066 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3067 break;
3068 case WLAN_TDLS_DISCOVERY_REQUEST:
3069 tf->category = WLAN_CATEGORY_TDLS;
3070 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3071
3072 skb_put(skb, sizeof(tf->u.discover_req));
3073 tf->u.discover_req.dialog_token = dialog_token;
3074 break;
3075 default:
3076 return -EINVAL;
3077 }
3078
3079 return 0;
3080}
3081
3082static int
3083ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3084 u8 *peer, u8 action_code, u8 dialog_token,
3085 u16 status_code, struct sk_buff *skb)
3086{
3087 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003088 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003089 struct ieee80211_mgmt *mgmt;
3090
3091 mgmt = (void *)skb_put(skb, 24);
3092 memset(mgmt, 0, 24);
3093 memcpy(mgmt->da, peer, ETH_ALEN);
3094 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3095 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3096
3097 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3098 IEEE80211_STYPE_ACTION);
3099
3100 switch (action_code) {
3101 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3102 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3103 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3104 mgmt->u.action.u.tdls_discover_resp.action_code =
3105 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3106 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3107 dialog_token;
3108 mgmt->u.action.u.tdls_discover_resp.capability =
3109 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3110
Johannes Berg55de9082012-07-26 17:24:39 +02003111 ieee80211_add_srates_ie(sdata, skb, false, band);
3112 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003113 ieee80211_tdls_add_ext_capab(skb);
3114 break;
3115 default:
3116 return -EINVAL;
3117 }
3118
3119 return 0;
3120}
3121
3122static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3123 u8 *peer, u8 action_code, u8 dialog_token,
3124 u16 status_code, const u8 *extra_ies,
3125 size_t extra_ies_len)
3126{
3127 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3128 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003129 struct sk_buff *skb = NULL;
3130 bool send_direct;
3131 int ret;
3132
3133 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3134 return -ENOTSUPP;
3135
3136 /* make sure we are in managed mode, and associated */
3137 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3138 !sdata->u.mgd.associated)
3139 return -EINVAL;
3140
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003141 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3142 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003143
3144 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3145 max(sizeof(struct ieee80211_mgmt),
3146 sizeof(struct ieee80211_tdls_data)) +
3147 50 + /* supported rates */
3148 7 + /* ext capab */
3149 extra_ies_len +
3150 sizeof(struct ieee80211_tdls_lnkie));
3151 if (!skb)
3152 return -ENOMEM;
3153
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003154 skb_reserve(skb, local->hw.extra_tx_headroom);
3155
3156 switch (action_code) {
3157 case WLAN_TDLS_SETUP_REQUEST:
3158 case WLAN_TDLS_SETUP_RESPONSE:
3159 case WLAN_TDLS_SETUP_CONFIRM:
3160 case WLAN_TDLS_TEARDOWN:
3161 case WLAN_TDLS_DISCOVERY_REQUEST:
3162 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3163 action_code, dialog_token,
3164 status_code, skb);
3165 send_direct = false;
3166 break;
3167 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3168 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3169 dialog_token, status_code,
3170 skb);
3171 send_direct = true;
3172 break;
3173 default:
3174 ret = -ENOTSUPP;
3175 break;
3176 }
3177
3178 if (ret < 0)
3179 goto fail;
3180
3181 if (extra_ies_len)
3182 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3183
3184 /* the TDLS link IE is always added last */
3185 switch (action_code) {
3186 case WLAN_TDLS_SETUP_REQUEST:
3187 case WLAN_TDLS_SETUP_CONFIRM:
3188 case WLAN_TDLS_TEARDOWN:
3189 case WLAN_TDLS_DISCOVERY_REQUEST:
3190 /* we are the initiator */
3191 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3192 sdata->u.mgd.bssid);
3193 break;
3194 case WLAN_TDLS_SETUP_RESPONSE:
3195 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3196 /* we are the responder */
3197 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3198 sdata->u.mgd.bssid);
3199 break;
3200 default:
3201 ret = -ENOTSUPP;
3202 goto fail;
3203 }
3204
3205 if (send_direct) {
3206 ieee80211_tx_skb(sdata, skb);
3207 return 0;
3208 }
3209
3210 /*
3211 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3212 * we should default to AC_VI.
3213 */
3214 switch (action_code) {
3215 case WLAN_TDLS_SETUP_REQUEST:
3216 case WLAN_TDLS_SETUP_RESPONSE:
3217 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3218 skb->priority = 2;
3219 break;
3220 default:
3221 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3222 skb->priority = 5;
3223 break;
3224 }
3225
3226 /* disable bottom halves when entering the Tx path */
3227 local_bh_disable();
3228 ret = ieee80211_subif_start_xmit(skb, dev);
3229 local_bh_enable();
3230
3231 return ret;
3232
3233fail:
3234 dev_kfree_skb(skb);
3235 return ret;
3236}
3237
3238static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3239 u8 *peer, enum nl80211_tdls_operation oper)
3240{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003241 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003242 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3243
3244 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3245 return -ENOTSUPP;
3246
3247 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3248 return -EINVAL;
3249
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003250 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003251
3252 switch (oper) {
3253 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003254 rcu_read_lock();
3255 sta = sta_info_get(sdata, peer);
3256 if (!sta) {
3257 rcu_read_unlock();
3258 return -ENOLINK;
3259 }
3260
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003261 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003262 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003263 break;
3264 case NL80211_TDLS_DISABLE_LINK:
3265 return sta_info_destroy_addr(sdata, peer);
3266 case NL80211_TDLS_TEARDOWN:
3267 case NL80211_TDLS_SETUP:
3268 case NL80211_TDLS_DISCOVERY_REQ:
3269 /* We don't support in-driver setup/teardown/discovery */
3270 return -ENOTSUPP;
3271 default:
3272 return -ENOTSUPP;
3273 }
3274
3275 return 0;
3276}
3277
Johannes Berg06500732011-11-04 11:18:16 +01003278static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3279 const u8 *peer, u64 *cookie)
3280{
3281 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3282 struct ieee80211_local *local = sdata->local;
3283 struct ieee80211_qos_hdr *nullfunc;
3284 struct sk_buff *skb;
3285 int size = sizeof(*nullfunc);
3286 __le16 fc;
3287 bool qos;
3288 struct ieee80211_tx_info *info;
3289 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003290 struct ieee80211_chanctx_conf *chanctx_conf;
3291 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003292
3293 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003294 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3295 if (WARN_ON(!chanctx_conf)) {
3296 rcu_read_unlock();
3297 return -EINVAL;
3298 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003299 band = chanctx_conf->def.chan->band;
Johannes Berg06500732011-11-04 11:18:16 +01003300 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003301 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003302 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003303 } else {
3304 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003305 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003306 }
Johannes Berg06500732011-11-04 11:18:16 +01003307
3308 if (qos) {
3309 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3310 IEEE80211_STYPE_QOS_NULLFUNC |
3311 IEEE80211_FCTL_FROMDS);
3312 } else {
3313 size -= 2;
3314 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3315 IEEE80211_STYPE_NULLFUNC |
3316 IEEE80211_FCTL_FROMDS);
3317 }
3318
3319 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003320 if (!skb) {
3321 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003322 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003323 }
Johannes Berg06500732011-11-04 11:18:16 +01003324
3325 skb->dev = dev;
3326
3327 skb_reserve(skb, local->hw.extra_tx_headroom);
3328
3329 nullfunc = (void *) skb_put(skb, size);
3330 nullfunc->frame_control = fc;
3331 nullfunc->duration_id = 0;
3332 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3333 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3334 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3335 nullfunc->seq_ctrl = 0;
3336
3337 info = IEEE80211_SKB_CB(skb);
3338
3339 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3340 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3341
3342 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3343 skb->priority = 7;
3344 if (qos)
3345 nullfunc->qos_ctrl = cpu_to_le16(7);
3346
3347 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003348 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003349 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003350 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003351
3352 *cookie = (unsigned long) skb;
3353 return 0;
3354}
3355
Johannes Berg683b6d32012-11-08 21:25:48 +01003356static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3357 struct wireless_dev *wdev,
3358 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003359{
Johannes Berg55de9082012-07-26 17:24:39 +02003360 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003361 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003362 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003363 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003364
Johannes Berg55de9082012-07-26 17:24:39 +02003365 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003366 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3367 if (chanctx_conf) {
3368 *chandef = chanctx_conf->def;
3369 ret = 0;
3370 } else if (local->open_count > 0 &&
3371 local->open_count == local->monitors &&
3372 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3373 if (local->use_chanctx)
3374 *chandef = local->monitor_chandef;
3375 else
3376 cfg80211_chandef_create(chandef,
3377 local->_oper_channel,
3378 local->_oper_channel_type);
Johannes Berg683b6d32012-11-08 21:25:48 +01003379 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003380 }
3381 rcu_read_unlock();
3382
Johannes Berg683b6d32012-11-08 21:25:48 +01003383 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003384}
3385
Johannes Berg6d525632012-04-04 15:05:25 +02003386#ifdef CONFIG_PM
3387static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3388{
3389 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3390}
3391#endif
3392
Jiri Bencf0706e82007-05-05 11:45:53 -07003393struct cfg80211_ops mac80211_config_ops = {
3394 .add_virtual_intf = ieee80211_add_iface,
3395 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003396 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003397 .start_p2p_device = ieee80211_start_p2p_device,
3398 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003399 .add_key = ieee80211_add_key,
3400 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003401 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003402 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003403 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003404 .start_ap = ieee80211_start_ap,
3405 .change_beacon = ieee80211_change_beacon,
3406 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003407 .add_station = ieee80211_add_station,
3408 .del_station = ieee80211_del_station,
3409 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003410 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003411 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003412 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003413#ifdef CONFIG_MAC80211_MESH
3414 .add_mpath = ieee80211_add_mpath,
3415 .del_mpath = ieee80211_del_mpath,
3416 .change_mpath = ieee80211_change_mpath,
3417 .get_mpath = ieee80211_get_mpath,
3418 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003419 .update_mesh_config = ieee80211_update_mesh_config,
3420 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003421 .join_mesh = ieee80211_join_mesh,
3422 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003423#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003424 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003425 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003426 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003427 .suspend = ieee80211_suspend,
3428 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003429 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003430 .sched_scan_start = ieee80211_sched_scan_start,
3431 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003432 .auth = ieee80211_auth,
3433 .assoc = ieee80211_assoc,
3434 .deauth = ieee80211_deauth,
3435 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003436 .join_ibss = ieee80211_join_ibss,
3437 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003438 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003439 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003440 .set_tx_power = ieee80211_set_tx_power,
3441 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003442 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003443 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003444 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003445 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003446 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003447 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003448 .remain_on_channel = ieee80211_remain_on_channel,
3449 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003450 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003451 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003452 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003453 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003454 .set_antenna = ieee80211_set_antenna,
3455 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003456 .set_ringparam = ieee80211_set_ringparam,
3457 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003458 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003459 .tdls_oper = ieee80211_tdls_oper,
3460 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003461 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003462 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003463#ifdef CONFIG_PM
3464 .set_wakeup = ieee80211_set_wakeup,
3465#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003466 .get_et_sset_count = ieee80211_get_et_sset_count,
3467 .get_et_stats = ieee80211_get_et_stats,
3468 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003469 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003470 .start_radar_detection = ieee80211_start_radar_detection,
Jiri Bencf0706e82007-05-05 11:45:53 -07003471};