blob: 61fc9116380daa3f101cf82d8fd6d156d34f1044 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg552bff02012-09-19 09:26:06 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
24 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020025 enum nl80211_iftype type,
26 u32 *flags,
27 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070028{
29 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020030 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010031 struct ieee80211_sub_if_data *sdata;
32 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg84efbb82012-06-16 00:00:26 +020034 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010035 if (err)
36 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010037
Johannes Bergf9e10ce2010-12-03 09:20:42 +010038 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020039 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 sdata->u.mntr_flags = *flags;
41 }
42
Johannes Berg84efbb82012-06-16 00:00:26 +020043 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070044}
45
Johannes Berg84efbb82012-06-16 00:00:26 +020046static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070047{
Johannes Berg84efbb82012-06-16 00:00:26 +020048 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Johannes Berg75636522008-07-09 14:40:35 +020050 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070051}
52
Johannes Berge36d56b2009-06-09 21:04:43 +020053static int ieee80211_change_iface(struct wiphy *wiphy,
54 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010055 enum nl80211_iftype type, u32 *flags,
56 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020057{
Johannes Berg9607e6b662009-12-23 13:15:31 +010058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020060
Johannes Berg05c914f2008-09-11 00:01:58 +020061 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020062 if (ret)
63 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020064
Johannes Berg9bc383d2009-11-19 11:55:19 +010065 if (type == NL80211_IFTYPE_AP_VLAN &&
66 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000067 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010068 else if (type == NL80211_IFTYPE_STATION &&
69 params && params->use_4addr >= 0)
70 sdata->u.mgd.use_4addr = params->use_4addr;
71
Christian Lamparter85416a42010-10-02 13:17:07 +020072 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
73 struct ieee80211_local *local = sdata->local;
74
75 if (ieee80211_sdata_running(sdata)) {
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)) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700178 ieee80211_key_free(sdata->local, 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);
217 if (err)
218 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100219
Johannes Berg3b967662008-04-08 17:56:52 +0200220 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200221 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200222
223 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100224}
225
226static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200227 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100228{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200229 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
230 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100231 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200232 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100233 int ret;
234
Johannes Berg5c0c3642011-05-12 14:31:49 +0200235 mutex_lock(&local->sta_mtx);
236 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200237
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100238 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200239 ret = -ENOENT;
240
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100241 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100242 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200243 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100244
Johannes Berg5c0c3642011-05-12 14:31:49 +0200245 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200246 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200247 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200248 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200249 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200250 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100251
Johannes Berg5c0c3642011-05-12 14:31:49 +0200252 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200253 ret = -ENOENT;
254 goto out_unlock;
255 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100256
Johannes Berg8d1f7ec2013-02-23 00:59:03 +0100257 __ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100258
Johannes Berg3b967662008-04-08 17:56:52 +0200259 ret = 0;
260 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200261 mutex_unlock(&local->key_mtx);
262 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200263
264 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100265}
266
Johannes Berg62da92f2007-12-19 02:03:31 +0100267static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200268 u8 key_idx, bool pairwise, const u8 *mac_addr,
269 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100270 void (*callback)(void *cookie,
271 struct key_params *params))
272{
Johannes Berg14db74b2008-07-29 13:22:52 +0200273 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100274 struct sta_info *sta = NULL;
275 u8 seq[6] = {0};
276 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200277 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200278 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100279 u32 iv32;
280 u16 iv16;
281 int err = -ENOENT;
282
Johannes Berg14db74b2008-07-29 13:22:52 +0200283 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
284
Johannes Berg3b967662008-04-08 17:56:52 +0200285 rcu_read_lock();
286
Johannes Berg62da92f2007-12-19 02:03:31 +0100287 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100288 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100289 if (!sta)
290 goto out;
291
Johannes Berge31b8212010-10-05 19:39:30 +0200292 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200293 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200294 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200295 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100296 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200297 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100298
299 if (!key)
300 goto out;
301
302 memset(&params, 0, sizeof(params));
303
Johannes Berg97359d12010-08-10 09:46:38 +0200304 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100305
Johannes Berg97359d12010-08-10 09:46:38 +0200306 switch (key->conf.cipher) {
307 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700308 iv32 = key->u.tkip.tx.iv32;
309 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100310
Johannes Berg24487982009-04-23 18:52:52 +0200311 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
312 drv_get_tkip_seq(sdata->local,
313 key->conf.hw_key_idx,
314 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100315
316 seq[0] = iv16 & 0xff;
317 seq[1] = (iv16 >> 8) & 0xff;
318 seq[2] = iv32 & 0xff;
319 seq[3] = (iv32 >> 8) & 0xff;
320 seq[4] = (iv32 >> 16) & 0xff;
321 seq[5] = (iv32 >> 24) & 0xff;
322 params.seq = seq;
323 params.seq_len = 6;
324 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200325 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200326 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
327 seq[0] = pn64;
328 seq[1] = pn64 >> 8;
329 seq[2] = pn64 >> 16;
330 seq[3] = pn64 >> 24;
331 seq[4] = pn64 >> 32;
332 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100333 params.seq = seq;
334 params.seq_len = 6;
335 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200336 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200337 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
338 seq[0] = pn64;
339 seq[1] = pn64 >> 8;
340 seq[2] = pn64 >> 16;
341 seq[3] = pn64 >> 24;
342 seq[4] = pn64 >> 32;
343 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200344 params.seq = seq;
345 params.seq_len = 6;
346 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100347 }
348
349 params.key = key->conf.key;
350 params.key_len = key->conf.keylen;
351
352 callback(cookie, &params);
353 err = 0;
354
355 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200356 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100357 return err;
358}
359
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100360static int ieee80211_config_default_key(struct wiphy *wiphy,
361 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100362 u8 key_idx, bool uni,
363 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100364{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200365 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100366
Johannes Bergf7e01042010-12-09 19:49:02 +0100367 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100368
369 return 0;
370}
371
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200372static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
373 struct net_device *dev,
374 u8 key_idx)
375{
Johannes Berg66c52422010-07-22 13:58:51 +0200376 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200377
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200378 ieee80211_set_default_mgmt_key(sdata, key_idx);
379
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200380 return 0;
381}
382
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800383void sta_set_rate_info_tx(struct sta_info *sta,
384 const struct ieee80211_tx_rate *rate,
385 struct rate_info *rinfo)
386{
387 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100388 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800389 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100390 rinfo->mcs = rate->idx;
391 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
392 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
393 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
394 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
395 } else {
396 struct ieee80211_supported_band *sband;
397 sband = sta->local->hw.wiphy->bands[
398 ieee80211_get_sdata_band(sta->sdata)];
399 rinfo->legacy = sband->bitrates[rate->idx].bitrate;
400 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800401 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
402 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100403 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
404 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
405 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
406 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800407 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
408 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800409}
410
Saravana003e6762012-11-28 18:29:38 +0530411void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
412{
413 rinfo->flags = 0;
414
415 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
416 rinfo->flags |= RATE_INFO_FLAGS_MCS;
417 rinfo->mcs = sta->last_rx_rate_idx;
418 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
419 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
420 rinfo->nss = sta->last_rx_rate_vht_nss;
421 rinfo->mcs = sta->last_rx_rate_idx;
422 } else {
423 struct ieee80211_supported_band *sband;
424
425 sband = sta->local->hw.wiphy->bands[
426 ieee80211_get_sdata_band(sta->sdata)];
427 rinfo->legacy =
428 sband->bitrates[sta->last_rx_rate_idx].bitrate;
429 }
430
431 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
432 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
433 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
434 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
435 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
436 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
437 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
438 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
439 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
440 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
441}
442
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100443static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
444{
Johannes Bergd0709a62008-02-25 16:27:46 +0100445 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300446 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530447 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100448 u64 packets = 0;
449 int ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100450
Johannes Bergf5ea9122009-08-07 16:17:38 +0200451 sinfo->generation = sdata->local->sta_generation;
452
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100453 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100454 STATION_INFO_RX_BYTES64 |
455 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200456 STATION_INFO_RX_PACKETS |
457 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900458 STATION_INFO_TX_RETRIES |
459 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700460 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100461 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700462 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530463 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200464 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800465 STATION_INFO_STA_FLAGS |
466 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530467
468 do_posix_clock_monotonic_gettime(&uptime);
469 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100470
471 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100472 sinfo->tx_bytes = 0;
473 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
474 sinfo->tx_bytes += sta->tx_bytes[ac];
475 packets += sta->tx_packets[ac];
476 }
477 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100478 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200479 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900480 sinfo->tx_retries = sta->tx_retry_count;
481 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700482 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800483 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100484
John W. Linville19deffb2009-12-08 17:10:13 -0500485 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
486 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900487 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300488 if (!local->ops->get_rssi ||
489 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
490 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900491 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100492 }
493
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800494 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530495 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100496
Johannes Berg902acc72008-02-23 15:17:19 +0100497 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100498#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100499 sinfo->filled |= STATION_INFO_LLID |
500 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100501 STATION_INFO_PLINK_STATE |
502 STATION_INFO_LOCAL_PM |
503 STATION_INFO_PEER_PM |
504 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100505
506 sinfo->llid = le16_to_cpu(sta->llid);
507 sinfo->plid = le16_to_cpu(sta->plid);
508 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700509 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
510 sinfo->filled |= STATION_INFO_T_OFFSET;
511 sinfo->t_offset = sta->t_offset;
512 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100513 sinfo->local_pm = sta->local_pm;
514 sinfo->peer_pm = sta->peer_pm;
515 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100516#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100517 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700518
519 sinfo->bss_param.flags = 0;
520 if (sdata->vif.bss_conf.use_cts_prot)
521 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
522 if (sdata->vif.bss_conf.use_short_preamble)
523 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
524 if (sdata->vif.bss_conf.use_short_slot)
525 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
526 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
527 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200528
529 sinfo->sta_flags.set = 0;
530 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
531 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
532 BIT(NL80211_STA_FLAG_WME) |
533 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100534 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200535 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100536 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200537 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
538 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
539 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
540 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
541 if (test_sta_flag(sta, WLAN_STA_WME))
542 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
543 if (test_sta_flag(sta, WLAN_STA_MFP))
544 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
545 if (test_sta_flag(sta, WLAN_STA_AUTH))
546 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200547 if (test_sta_flag(sta, WLAN_STA_ASSOC))
548 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100549 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
550 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100551}
552
Ben Greearb1ab7922012-04-23 12:50:30 -0700553static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
554 "rx_packets", "rx_bytes", "wep_weak_iv_count",
555 "rx_duplicates", "rx_fragments", "rx_dropped",
556 "tx_packets", "tx_bytes", "tx_fragments",
557 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700558 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
559 "channel", "noise", "ch_time", "ch_time_busy",
560 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700561};
562#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
563
564static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
565 struct net_device *dev,
566 int sset)
567{
Ben Greeare3521142012-04-23 12:50:31 -0700568 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
569 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700570
Ben Greeare3521142012-04-23 12:50:31 -0700571 if (sset == ETH_SS_STATS)
572 rv += STA_STATS_LEN;
573
574 rv += drv_get_et_sset_count(sdata, sset);
575
576 if (rv == 0)
577 return -EOPNOTSUPP;
578 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700579}
580
581static void ieee80211_get_et_stats(struct wiphy *wiphy,
582 struct net_device *dev,
583 struct ethtool_stats *stats,
584 u64 *data)
585{
586 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200587 struct ieee80211_chanctx_conf *chanctx_conf;
588 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700589 struct sta_info *sta;
590 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700591 struct station_info sinfo;
592 struct survey_info survey;
593 int i, q;
594#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700595
596 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
597
598#define ADD_STA_STATS(sta) \
599 do { \
600 data[i++] += sta->rx_packets; \
601 data[i++] += sta->rx_bytes; \
602 data[i++] += sta->wep_weak_iv_count; \
603 data[i++] += sta->num_duplicates; \
604 data[i++] += sta->rx_fragments; \
605 data[i++] += sta->rx_dropped; \
606 \
Johannes Berg560d2682013-02-05 10:55:21 +0100607 data[i++] += sinfo.tx_packets; \
608 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700609 data[i++] += sta->tx_fragments; \
610 data[i++] += sta->tx_filtered_count; \
611 data[i++] += sta->tx_retry_failed; \
612 data[i++] += sta->tx_retry_count; \
613 data[i++] += sta->beacon_loss_count; \
614 } while (0)
615
616 /* For Managed stations, find the single station based on BSSID
617 * and use that. For interface types, iterate through all available
618 * stations and add stats for any station that is assigned to this
619 * network device.
620 */
621
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300622 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700623
624 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
625 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700626
627 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
628 goto do_survey;
629
Johannes Berg560d2682013-02-05 10:55:21 +0100630 sinfo.filled = 0;
631 sta_set_sinfo(sta, &sinfo);
632
Ben Greear3073a7c2012-04-23 12:50:32 -0700633 i = 0;
634 ADD_STA_STATS(sta);
635
636 data[i++] = sta->sta_state;
637
Ben Greear3073a7c2012-04-23 12:50:32 -0700638
Joe Perches52042672012-05-30 13:25:54 -0700639 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700640 data[i] = 100000 *
641 cfg80211_calculate_bitrate(&sinfo.txrate);
642 i++;
Joe Perches52042672012-05-30 13:25:54 -0700643 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700644 data[i] = 100000 *
645 cfg80211_calculate_bitrate(&sinfo.rxrate);
646 i++;
647
Joe Perches52042672012-05-30 13:25:54 -0700648 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700649 data[i] = (u8)sinfo.signal_avg;
650 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700651 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300652 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700653 /* Make sure this station belongs to the proper dev */
654 if (sta->sdata->dev != dev)
655 continue;
656
657 i = 0;
658 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700659 }
660 }
661
Ben Greear3073a7c2012-04-23 12:50:32 -0700662do_survey:
663 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
664 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200665 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700666
Johannes Berg55de9082012-07-26 17:24:39 +0200667 rcu_read_lock();
668 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
669 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100670 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200671 else
672 channel = NULL;
673 rcu_read_unlock();
674
675 if (channel) {
676 q = 0;
677 do {
678 survey.filled = 0;
679 if (drv_get_survey(local, q, &survey) != 0) {
680 survey.filled = 0;
681 break;
682 }
683 q++;
684 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700685 }
686
687 if (survey.filled)
688 data[i++] = survey.channel->center_freq;
689 else
690 data[i++] = 0;
691 if (survey.filled & SURVEY_INFO_NOISE_DBM)
692 data[i++] = (u8)survey.noise;
693 else
694 data[i++] = -1LL;
695 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
696 data[i++] = survey.channel_time;
697 else
698 data[i++] = -1LL;
699 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
700 data[i++] = survey.channel_time_busy;
701 else
702 data[i++] = -1LL;
703 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
704 data[i++] = survey.channel_time_ext_busy;
705 else
706 data[i++] = -1LL;
707 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
708 data[i++] = survey.channel_time_rx;
709 else
710 data[i++] = -1LL;
711 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
712 data[i++] = survey.channel_time_tx;
713 else
714 data[i++] = -1LL;
715
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300716 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700717
Ben Greear3073a7c2012-04-23 12:50:32 -0700718 if (WARN_ON(i != STA_STATS_LEN))
719 return;
720
Ben Greeare3521142012-04-23 12:50:31 -0700721 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700722}
723
724static void ieee80211_get_et_strings(struct wiphy *wiphy,
725 struct net_device *dev,
726 u32 sset, u8 *data)
727{
Ben Greeare3521142012-04-23 12:50:31 -0700728 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
729 int sz_sta_stats = 0;
730
Ben Greearb1ab7922012-04-23 12:50:30 -0700731 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700732 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700733 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
734 }
Ben Greeare3521142012-04-23 12:50:31 -0700735 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700736}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100737
738static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
739 int idx, u8 *mac, struct station_info *sinfo)
740{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100741 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300742 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100743 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100744 int ret = -ENOENT;
745
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300746 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100747
Johannes Berg3b53fde82009-11-16 12:00:37 +0100748 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100749 if (sta) {
750 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200751 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100752 sta_set_sinfo(sta, sinfo);
753 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100754
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300755 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100756
Johannes Bergd0709a62008-02-25 16:27:46 +0100757 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100758}
759
Holger Schurig12897232010-04-19 10:23:57 +0200760static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
761 int idx, struct survey_info *survey)
762{
763 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
764
Holger Schurig12897232010-04-19 10:23:57 +0200765 return drv_get_survey(local, idx, survey);
766}
767
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100768static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100769 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100770{
Johannes Bergabe60632009-11-25 17:46:18 +0100771 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300772 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100773 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100774 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100775
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300776 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100777
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100778 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100779 if (sta) {
780 ret = 0;
781 sta_set_sinfo(sta, sinfo);
782 }
783
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300784 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100785
786 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100787}
788
Johannes Berge8c9bd52012-06-06 08:18:22 +0200789static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100790 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200791{
Johannes Berg55de9082012-07-26 17:24:39 +0200792 struct ieee80211_local *local = wiphy_priv(wiphy);
793 struct ieee80211_sub_if_data *sdata;
794 int ret = 0;
795
Johannes Berg4bf88532012-11-09 11:39:59 +0100796 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200797 return 0;
798
799 mutex_lock(&local->iflist_mtx);
800 if (local->use_chanctx) {
801 sdata = rcu_dereference_protected(
802 local->monitor_sdata,
803 lockdep_is_held(&local->iflist_mtx));
804 if (sdata) {
805 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100806 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200807 IEEE80211_CHANCTX_EXCLUSIVE);
808 }
809 } else if (local->open_count == local->monitors) {
Johannes Berg683b6d32012-11-08 21:25:48 +0100810 local->_oper_channel = chandef->chan;
Johannes Berg4bf88532012-11-09 11:39:59 +0100811 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
Johannes Berg55de9082012-07-26 17:24:39 +0200812 ieee80211_hw_config(local, 0);
813 }
814
Johannes Berg4bf88532012-11-09 11:39:59 +0100815 if (ret == 0)
816 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200817 mutex_unlock(&local->iflist_mtx);
818
819 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200820}
821
Arik Nemtsov02945822011-11-10 11:28:57 +0200822static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100823 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200824{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300825 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200826
827 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530828 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200829
Arik Nemtsovf7248282011-11-19 10:51:26 +0200830 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200831
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300832 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200833 if (!new)
834 return -ENOMEM;
835
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300836 new->len = resp_len;
837 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200838
839 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300840 if (old)
841 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200842
843 return 0;
844}
845
Johannes Berg88600202012-02-13 15:17:18 +0100846static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
847 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100848{
849 struct beacon_data *new, *old;
850 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100851 int size, err;
852 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100853
Johannes Berg40b275b2011-05-13 14:15:49 +0200854 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100855
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100856 /* Need to have a beacon head if we don't have one yet */
857 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100858 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100859
860 /* new or old head? */
861 if (params->head)
862 new_head_len = params->head_len;
863 else
864 new_head_len = old->head_len;
865
866 /* new or old tail? */
867 if (params->tail || !old)
868 /* params->tail_len will be zero for !params->tail */
869 new_tail_len = params->tail_len;
870 else
871 new_tail_len = old->tail_len;
872
873 size = sizeof(*new) + new_head_len + new_tail_len;
874
875 new = kzalloc(size, GFP_KERNEL);
876 if (!new)
877 return -ENOMEM;
878
879 /* start filling the new info now */
880
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100881 /*
882 * pointers go into the block we allocated,
883 * memory is | beacon_data | head | tail |
884 */
885 new->head = ((u8 *) new) + sizeof(*new);
886 new->tail = new->head + new_head_len;
887 new->head_len = new_head_len;
888 new->tail_len = new_tail_len;
889
890 /* copy in head */
891 if (params->head)
892 memcpy(new->head, params->head, new_head_len);
893 else
894 memcpy(new->head, old->head, new_head_len);
895
896 /* copy in optional tail */
897 if (params->tail)
898 memcpy(new->tail, params->tail, new_tail_len);
899 else
900 if (old)
901 memcpy(new->tail, old->tail, new_tail_len);
902
Johannes Berg88600202012-02-13 15:17:18 +0100903 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
904 params->probe_resp_len);
905 if (err < 0)
906 return err;
907 if (err == 0)
908 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100909
Eric Dumazetcf778b02012-01-12 04:41:32 +0000910 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100911
Johannes Berg88600202012-02-13 15:17:18 +0100912 if (old)
913 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100914
Johannes Berg88600202012-02-13 15:17:18 +0100915 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100916}
917
Johannes Berg88600202012-02-13 15:17:18 +0100918static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
919 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100920{
Johannes Berg88600202012-02-13 15:17:18 +0100921 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100922 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100923 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100924 u32 changed = BSS_CHANGED_BEACON_INT |
925 BSS_CHANGED_BEACON_ENABLED |
926 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100927 BSS_CHANGED_SSID |
928 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100929 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200930
Johannes Berg40b275b2011-05-13 14:15:49 +0200931 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100932 if (old)
933 return -EALREADY;
934
Johannes Berg04ecd252012-09-11 14:34:12 +0200935 /* TODO: make hostapd tell us what it wants */
936 sdata->smps_mode = IEEE80211_SMPS_OFF;
937 sdata->needed_rx_chains = sdata->local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +0100938 sdata->radar_required = params->radar_required;
Johannes Berg04ecd252012-09-11 14:34:12 +0200939
Johannes Berg4bf88532012-11-09 11:39:59 +0100940 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200941 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200942 if (err)
943 return err;
Johannes Berg1f4ac5a2013-02-08 12:07:44 +0100944 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Bergaa430da2012-05-16 23:50:18 +0200945
Johannes Berg665c93a2011-11-04 11:18:11 +0100946 /*
947 * Apply control port protocol, this allows us to
948 * not encrypt dynamic WEP control frames.
949 */
950 sdata->control_port_protocol = params->crypto.control_port_ethertype;
951 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
952 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
953 vlan->control_port_protocol =
954 params->crypto.control_port_ethertype;
955 vlan->control_port_no_encrypt =
956 params->crypto.control_port_no_encrypt;
957 }
958
Johannes Berg88600202012-02-13 15:17:18 +0100959 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
960 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +0100961 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +0100962
963 sdata->vif.bss_conf.ssid_len = params->ssid_len;
964 if (params->ssid_len)
965 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
966 params->ssid_len);
967 sdata->vif.bss_conf.hidden_ssid =
968 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
969
Johannes Berg339afbf2012-11-14 15:21:17 +0100970 sdata->vif.bss_conf.p2p_ctwindow = params->p2p_ctwindow;
971 sdata->vif.bss_conf.p2p_oppps = params->p2p_opp_ps;
972
Johannes Berg88600202012-02-13 15:17:18 +0100973 err = ieee80211_assign_beacon(sdata, &params->beacon);
974 if (err < 0)
975 return err;
976 changed |= err;
977
Johannes Berg10416382012-10-19 15:44:42 +0200978 err = drv_start_ap(sdata->local, sdata);
979 if (err) {
980 old = rtnl_dereference(sdata->u.ap.beacon);
981 if (old)
982 kfree_rcu(old, rcu_head);
983 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
984 return err;
985 }
986
Johannes Berg88600202012-02-13 15:17:18 +0100987 ieee80211_bss_info_change_notify(sdata, changed);
988
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200989 netif_carrier_on(dev);
990 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
991 netif_carrier_on(vlan->dev);
992
Johannes Berg665c93a2011-11-04 11:18:11 +0100993 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100994}
995
Johannes Berg88600202012-02-13 15:17:18 +0100996static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
997 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100998{
Johannes Berg14db74b2008-07-29 13:22:52 +0200999 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001000 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001001 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001002
Johannes Berg14db74b2008-07-29 13:22:52 +02001003 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1004
Johannes Berg40b275b2011-05-13 14:15:49 +02001005 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001006 if (!old)
1007 return -ENOENT;
1008
Johannes Berg88600202012-02-13 15:17:18 +01001009 err = ieee80211_assign_beacon(sdata, params);
1010 if (err < 0)
1011 return err;
1012 ieee80211_bss_info_change_notify(sdata, err);
1013 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001014}
1015
Johannes Berg88600202012-02-13 15:17:18 +01001016static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001017{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001018 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1019 struct ieee80211_sub_if_data *vlan;
1020 struct ieee80211_local *local = sdata->local;
1021 struct beacon_data *old_beacon;
1022 struct probe_resp *old_probe_resp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001023
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001024 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
1025 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001026 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001027 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001028
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001029 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001030 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1031 netif_carrier_off(vlan->dev);
1032 netif_carrier_off(dev);
1033
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001034 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001035 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001036 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1037 kfree_rcu(old_beacon, rcu_head);
1038 if (old_probe_resp)
1039 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001040
Felix Fietkau2d4072a2012-12-10 20:02:34 +01001041 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
Johannes Berg75de9112012-12-14 14:56:03 +01001042 sta_info_flush_defer(vlan);
1043 sta_info_flush_defer(sdata);
1044 rcu_barrier();
Johannes Berg7b4396b2013-02-23 01:14:20 +01001045 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
Johannes Berg75de9112012-12-14 14:56:03 +01001046 sta_info_flush_cleanup(vlan);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001047 ieee80211_free_keys(vlan);
1048 }
Johannes Berg75de9112012-12-14 14:56:03 +01001049 sta_info_flush_cleanup(sdata);
Johannes Berg7b4396b2013-02-23 01:14:20 +01001050 ieee80211_free_keys(sdata);
Johannes Berg75de9112012-12-14 14:56:03 +01001051
Johannes Bergd6a83222012-12-14 14:06:28 +01001052 sdata->vif.bss_conf.enable_beacon = false;
1053 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001054 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001055
Johannes Berg10416382012-10-19 15:44:42 +02001056 drv_stop_ap(sdata->local, sdata);
1057
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001058 /* free all potentially still buffered bcast frames */
1059 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1060 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1061
Johannes Berg1f4ac5a2013-02-08 12:07:44 +01001062 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001063 ieee80211_vif_release_channel(sdata);
1064
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001065 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001066}
1067
Johannes Berg4fd69312007-12-19 02:03:35 +01001068/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1069struct iapp_layer2_update {
1070 u8 da[ETH_ALEN]; /* broadcast */
1071 u8 sa[ETH_ALEN]; /* STA addr */
1072 __be16 len; /* 6 */
1073 u8 dsap; /* 0 */
1074 u8 ssap; /* 0 */
1075 u8 control;
1076 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001077} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001078
1079static void ieee80211_send_layer2_update(struct sta_info *sta)
1080{
1081 struct iapp_layer2_update *msg;
1082 struct sk_buff *skb;
1083
1084 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1085 * bridge devices */
1086
1087 skb = dev_alloc_skb(sizeof(*msg));
1088 if (!skb)
1089 return;
1090 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1091
1092 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1093 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1094
Johannes Berge83e6542012-07-13 16:23:07 +02001095 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001096 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001097 msg->len = htons(6);
1098 msg->dsap = 0;
1099 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1100 msg->control = 0xaf; /* XID response lsb.1111F101.
1101 * F=0 (no poll command; unsolicited frame) */
1102 msg->xid_info[0] = 0x81; /* XID format identifier */
1103 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1104 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1105
Johannes Bergd0709a62008-02-25 16:27:46 +01001106 skb->dev = sta->sdata->dev;
1107 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001108 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001109 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001110}
1111
Johannes Bergd582cff2012-10-26 17:53:44 +02001112static int sta_apply_auth_flags(struct ieee80211_local *local,
1113 struct sta_info *sta,
1114 u32 mask, u32 set)
1115{
1116 int ret;
1117
1118 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1119 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1120 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1121 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1122 if (ret)
1123 return ret;
1124 }
1125
1126 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1127 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1128 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1129 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1130 if (ret)
1131 return ret;
1132 }
1133
1134 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1135 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1136 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1137 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1138 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1139 else
1140 ret = 0;
1141 if (ret)
1142 return ret;
1143 }
1144
1145 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1146 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1147 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1148 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1149 if (ret)
1150 return ret;
1151 }
1152
1153 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1154 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1155 test_sta_flag(sta, WLAN_STA_AUTH)) {
1156 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1157 if (ret)
1158 return ret;
1159 }
1160
1161 return 0;
1162}
1163
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001164static int sta_apply_parameters(struct ieee80211_local *local,
1165 struct sta_info *sta,
1166 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001167{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001168 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001169 u32 rates;
1170 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +01001171 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001172 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001173 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001174 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001175
Johannes Berg55de9082012-07-26 17:24:39 +02001176 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001177
Johannes Bergeccb8e82009-05-11 21:57:56 +03001178 mask = params->sta_flags_mask;
1179 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001180
Johannes Bergd582cff2012-10-26 17:53:44 +02001181 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1182 /*
1183 * In mesh mode, ASSOCIATED isn't part of the nl80211
1184 * API but must follow AUTHENTICATED for driver state.
1185 */
1186 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1187 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1188 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1189 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001190 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1191 /*
1192 * TDLS -- everything follows authorized, but
1193 * only becoming authorized is possible, not
1194 * going back
1195 */
1196 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1197 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1198 BIT(NL80211_STA_FLAG_ASSOCIATED);
1199 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1200 BIT(NL80211_STA_FLAG_ASSOCIATED);
1201 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001202 }
1203
Johannes Bergd582cff2012-10-26 17:53:44 +02001204 ret = sta_apply_auth_flags(local, sta, mask, set);
1205 if (ret)
1206 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001207
Johannes Bergeccb8e82009-05-11 21:57:56 +03001208 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001209 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001210 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1211 else
1212 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001213 }
1214
1215 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001216 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001217 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001218 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001219 } else {
1220 clear_sta_flag(sta, WLAN_STA_WME);
1221 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001222 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001223 }
1224
1225 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001226 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001227 set_sta_flag(sta, WLAN_STA_MFP);
1228 else
1229 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001230 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001231
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001232 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001233 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001234 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1235 else
1236 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001237 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001238
Johannes Berg3b9ce802011-09-27 20:56:12 +02001239 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1240 sta->sta.uapsd_queues = params->uapsd_queues;
1241 sta->sta.max_sp = params->max_sp;
1242 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001243
Johannes Berg73651ee2008-02-25 16:27:47 +01001244 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001245 * cfg80211 validates this (1-2007) and allows setting the AID
1246 * only when creating a new station entry
1247 */
1248 if (params->aid)
1249 sta->sta.aid = params->aid;
1250
1251 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001252 * Some of the following updates would be racy if called on an
1253 * existing station, via ieee80211_change_station(). However,
1254 * all such changes are rejected by cfg80211 except for updates
1255 * changing the supported rates on an existing but not yet used
1256 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001257 */
1258
Johannes Berg4fd69312007-12-19 02:03:35 +01001259 if (params->listen_interval >= 0)
1260 sta->listen_interval = params->listen_interval;
1261
1262 if (params->supported_rates) {
1263 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001264
Johannes Berg4fd69312007-12-19 02:03:35 +01001265 for (i = 0; i < params->supported_rates_len; i++) {
1266 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001267 for (j = 0; j < sband->n_bitrates; j++) {
1268 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001269 rates |= BIT(j);
1270 }
1271 }
Johannes Berg55de9082012-07-26 17:24:39 +02001272 sta->sta.supp_rates[band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001273 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001274
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001275 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001276 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001277 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001278
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001279 if (params->vht_capa)
1280 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001281 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001282
Javier Cardona9c3990a2011-05-03 16:57:11 -07001283 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001284#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001285 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001286
1287 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001288 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001289 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001290 if (sta->plink_state != NL80211_PLINK_ESTAB)
1291 changed = mesh_plink_inc_estab_count(
1292 sdata);
1293 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001294
1295 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001296 changed |= ieee80211_mps_set_sta_local_pm(sta,
1297 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001298 break;
1299 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001300 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001301 case NL80211_PLINK_OPN_SNT:
1302 case NL80211_PLINK_OPN_RCVD:
1303 case NL80211_PLINK_CNF_RCVD:
1304 case NL80211_PLINK_HOLDING:
1305 if (sta->plink_state == NL80211_PLINK_ESTAB)
1306 changed = mesh_plink_dec_estab_count(
1307 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001308 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001309
1310 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001311 changed |=
1312 ieee80211_mps_local_status_update(sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001313 break;
1314 default:
1315 /* nothing */
1316 break;
1317 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001318 }
1319
1320 switch (params->plink_action) {
1321 case NL80211_PLINK_ACTION_NO_ACTION:
1322 /* nothing */
1323 break;
1324 case NL80211_PLINK_ACTION_OPEN:
1325 changed |= mesh_plink_open(sta);
1326 break;
1327 case NL80211_PLINK_ACTION_BLOCK:
1328 changed |= mesh_plink_block(sta);
1329 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001330 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001331
1332 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001333 changed |=
1334 ieee80211_mps_set_sta_local_pm(sta,
1335 params->local_pm);
1336 ieee80211_bss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001337#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001338 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001339
1340 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001341}
1342
1343static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1344 u8 *mac, struct station_parameters *params)
1345{
Johannes Berg14db74b2008-07-29 13:22:52 +02001346 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001347 struct sta_info *sta;
1348 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001349 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001350 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001351
Johannes Berg4fd69312007-12-19 02:03:35 +01001352 if (params->vlan) {
1353 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1354
Johannes Berg05c914f2008-09-11 00:01:58 +02001355 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1356 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001357 return -EINVAL;
1358 } else
1359 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1360
Joe Perchesb203ca32012-05-08 18:56:52 +00001361 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001362 return -EINVAL;
1363
1364 if (is_multicast_ether_addr(mac))
1365 return -EINVAL;
1366
1367 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001368 if (!sta)
1369 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001370
Johannes Bergd582cff2012-10-26 17:53:44 +02001371 /*
1372 * defaults -- if userspace wants something else we'll
1373 * change it accordingly in sta_apply_parameters()
1374 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001375 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1376 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1377 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
1378 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001379
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001380 err = sta_apply_parameters(local, sta, params);
1381 if (err) {
1382 sta_info_free(local, sta);
1383 return err;
1384 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001385
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001386 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001387 * for TDLS, rate control should be initialized only when
1388 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001389 */
1390 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1391 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001392
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001393 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1394 sdata->vif.type == NL80211_IFTYPE_AP;
1395
Johannes Berg34e89502010-02-03 13:59:58 +01001396 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001397 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001398 rcu_read_unlock();
1399 return err;
1400 }
1401
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001402 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001403 ieee80211_send_layer2_update(sta);
1404
1405 rcu_read_unlock();
1406
Johannes Berg4fd69312007-12-19 02:03:35 +01001407 return 0;
1408}
1409
1410static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1411 u8 *mac)
1412{
Johannes Berg14db74b2008-07-29 13:22:52 +02001413 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001414
Johannes Berg14db74b2008-07-29 13:22:52 +02001415 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1416
Johannes Berg34e89502010-02-03 13:59:58 +01001417 if (mac)
1418 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001419
Johannes Bergb998e8b2012-12-13 23:07:46 +01001420 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001421 return 0;
1422}
1423
1424static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001425 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001426 struct station_parameters *params)
1427{
Johannes Bergabe60632009-11-25 17:46:18 +01001428 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001429 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001430 struct sta_info *sta;
1431 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001432 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001433 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001434
Johannes Berg87be1e12011-12-14 12:20:29 +01001435 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001436
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001437 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001438 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001439 err = -ENOENT;
1440 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001441 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001442
Johannes Berg77ee7c82013-02-15 00:48:33 +01001443 switch (sdata->vif.type) {
1444 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001445 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001446 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001447 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001448 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001449 break;
1450 case NL80211_IFTYPE_ADHOC:
1451 statype = CFG80211_STA_IBSS;
1452 break;
1453 case NL80211_IFTYPE_STATION:
1454 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1455 statype = CFG80211_STA_AP_STA;
1456 break;
1457 }
1458 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1459 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1460 else
1461 statype = CFG80211_STA_TDLS_PEER_SETUP;
1462 break;
1463 case NL80211_IFTYPE_AP:
1464 case NL80211_IFTYPE_AP_VLAN:
1465 statype = CFG80211_STA_AP_CLIENT;
1466 break;
1467 default:
1468 err = -EOPNOTSUPP;
1469 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001470 }
1471
Johannes Berg77ee7c82013-02-15 00:48:33 +01001472 err = cfg80211_check_station_change(wiphy, params, statype);
1473 if (err)
1474 goto out_err;
1475
Johannes Bergd0709a62008-02-25 16:27:46 +01001476 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001477 bool prev_4addr = false;
1478 bool new_4addr = false;
1479
Johannes Berg4fd69312007-12-19 02:03:35 +01001480 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1481
Johannes Berg9bc383d2009-11-19 11:55:19 +01001482 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001483 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001484 err = -EBUSY;
1485 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001486 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001487
Eric Dumazetcf778b02012-01-12 04:41:32 +00001488 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001489 new_4addr = true;
1490 }
1491
1492 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1493 sta->sdata->u.vlan.sta) {
1494 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1495 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001496 }
1497
Johannes Berg14db74b2008-07-29 13:22:52 +02001498 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001499
1500 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1501 prev_4addr != new_4addr) {
1502 if (new_4addr)
1503 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1504 else
1505 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1506 }
1507
Johannes Berg4fd69312007-12-19 02:03:35 +01001508 ieee80211_send_layer2_update(sta);
1509 }
1510
Eliad Peller35b88622011-12-29 14:41:39 +02001511 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001512 if (err)
1513 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001514
Johannes Berg77ee7c82013-02-15 00:48:33 +01001515 /* When peer becomes authorized, init rate control as well */
1516 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1517 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001518 rate_control_rate_init(sta);
1519
Johannes Berg87be1e12011-12-14 12:20:29 +01001520 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001521
Jason Young808118c2011-03-10 16:43:19 -08001522 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001523 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001524 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001525 ieee80211_recalc_ps_vif(sdata);
1526 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001527
Johannes Berg4fd69312007-12-19 02:03:35 +01001528 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001529out_err:
1530 mutex_unlock(&local->sta_mtx);
1531 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001532}
1533
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001534#ifdef CONFIG_MAC80211_MESH
1535static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1536 u8 *dst, u8 *next_hop)
1537{
Johannes Berg14db74b2008-07-29 13:22:52 +02001538 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001539 struct mesh_path *mpath;
1540 struct sta_info *sta;
1541 int err;
1542
Johannes Berg14db74b2008-07-29 13:22:52 +02001543 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1544
Johannes Bergd0709a62008-02-25 16:27:46 +01001545 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001546 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001547 if (!sta) {
1548 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001549 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001550 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001551
Johannes Bergbf7cd942013-02-15 14:40:31 +01001552 err = mesh_path_add(sdata, dst);
Johannes Bergd0709a62008-02-25 16:27:46 +01001553 if (err) {
1554 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001555 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001556 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001557
Johannes Bergbf7cd942013-02-15 14:40:31 +01001558 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001559 if (!mpath) {
1560 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001561 return -ENXIO;
1562 }
1563 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001564
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001565 rcu_read_unlock();
1566 return 0;
1567}
1568
1569static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001570 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001571{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001572 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001573
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001574 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001575 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001576
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001577 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001578 return 0;
1579}
1580
1581static int ieee80211_change_mpath(struct wiphy *wiphy,
1582 struct net_device *dev,
1583 u8 *dst, u8 *next_hop)
1584{
Johannes Berg14db74b2008-07-29 13:22:52 +02001585 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001586 struct mesh_path *mpath;
1587 struct sta_info *sta;
1588
Johannes Berg14db74b2008-07-29 13:22:52 +02001589 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1590
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001591 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001592
Johannes Bergabe60632009-11-25 17:46:18 +01001593 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001594 if (!sta) {
1595 rcu_read_unlock();
1596 return -ENOENT;
1597 }
1598
Johannes Bergbf7cd942013-02-15 14:40:31 +01001599 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001600 if (!mpath) {
1601 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001602 return -ENOENT;
1603 }
1604
1605 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001606
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001607 rcu_read_unlock();
1608 return 0;
1609}
1610
1611static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1612 struct mpath_info *pinfo)
1613{
Johannes Berga3836e02011-05-12 15:11:37 +02001614 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1615
1616 if (next_hop_sta)
1617 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001618 else
1619 memset(next_hop, 0, ETH_ALEN);
1620
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001621 memset(pinfo, 0, sizeof(*pinfo));
1622
Johannes Bergf5ea9122009-08-07 16:17:38 +02001623 pinfo->generation = mesh_paths_generation;
1624
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001625 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001626 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001627 MPATH_INFO_METRIC |
1628 MPATH_INFO_EXPTIME |
1629 MPATH_INFO_DISCOVERY_TIMEOUT |
1630 MPATH_INFO_DISCOVERY_RETRIES |
1631 MPATH_INFO_FLAGS;
1632
1633 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001634 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001635 pinfo->metric = mpath->metric;
1636 if (time_before(jiffies, mpath->exp_time))
1637 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1638 pinfo->discovery_timeout =
1639 jiffies_to_msecs(mpath->discovery_timeout);
1640 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001641 if (mpath->flags & MESH_PATH_ACTIVE)
1642 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1643 if (mpath->flags & MESH_PATH_RESOLVING)
1644 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001645 if (mpath->flags & MESH_PATH_SN_VALID)
1646 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001647 if (mpath->flags & MESH_PATH_FIXED)
1648 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001649 if (mpath->flags & MESH_PATH_RESOLVED)
1650 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001651}
1652
1653static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1654 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1655
1656{
Johannes Berg14db74b2008-07-29 13:22:52 +02001657 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001658 struct mesh_path *mpath;
1659
Johannes Berg14db74b2008-07-29 13:22:52 +02001660 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1661
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001662 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001663 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001664 if (!mpath) {
1665 rcu_read_unlock();
1666 return -ENOENT;
1667 }
1668 memcpy(dst, mpath->dst, ETH_ALEN);
1669 mpath_set_pinfo(mpath, next_hop, pinfo);
1670 rcu_read_unlock();
1671 return 0;
1672}
1673
1674static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1675 int idx, u8 *dst, u8 *next_hop,
1676 struct mpath_info *pinfo)
1677{
Johannes Berg14db74b2008-07-29 13:22:52 +02001678 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001679 struct mesh_path *mpath;
1680
Johannes Berg14db74b2008-07-29 13:22:52 +02001681 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1682
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001683 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001684 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001685 if (!mpath) {
1686 rcu_read_unlock();
1687 return -ENOENT;
1688 }
1689 memcpy(dst, mpath->dst, ETH_ALEN);
1690 mpath_set_pinfo(mpath, next_hop, pinfo);
1691 rcu_read_unlock();
1692 return 0;
1693}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001694
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001695static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001696 struct net_device *dev,
1697 struct mesh_config *conf)
1698{
1699 struct ieee80211_sub_if_data *sdata;
1700 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1701
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001702 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1703 return 0;
1704}
1705
1706static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1707{
1708 return (mask >> (parm-1)) & 0x1;
1709}
1710
Javier Cardonac80d5452010-12-16 17:37:49 -08001711static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1712 const struct mesh_setup *setup)
1713{
1714 u8 *new_ie;
1715 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001716 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1717 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001718
Javier Cardona581a8b02011-04-07 15:08:27 -07001719 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001720 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001721 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001722
Javier Cardona581a8b02011-04-07 15:08:27 -07001723 if (setup->ie_len) {
1724 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001725 GFP_KERNEL);
1726 if (!new_ie)
1727 return -ENOMEM;
1728 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001729 ifmsh->ie_len = setup->ie_len;
1730 ifmsh->ie = new_ie;
1731 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001732
1733 /* now copy the rest of the setup parameters */
1734 ifmsh->mesh_id_len = setup->mesh_id_len;
1735 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001736 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001737 ifmsh->mesh_pp_id = setup->path_sel_proto;
1738 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001739 ifmsh->user_mpm = setup->user_mpm;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001740 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1741 if (setup->is_authenticated)
1742 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1743 if (setup->is_secure)
1744 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001745
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001746 /* mcast rate setting in Mesh Node */
1747 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1748 sizeof(setup->mcast_rate));
1749
Marco Porsch9bdbf042013-01-07 16:04:51 +01001750 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1751 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1752
Javier Cardonac80d5452010-12-16 17:37:49 -08001753 return 0;
1754}
1755
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001756static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001757 struct net_device *dev, u32 mask,
1758 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001759{
1760 struct mesh_config *conf;
1761 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001762 struct ieee80211_if_mesh *ifmsh;
1763
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001764 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001765 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001766
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001767 /* Set the config options which we are interested in setting */
1768 conf = &(sdata->u.mesh.mshcfg);
1769 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1770 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1771 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1772 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1773 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1774 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1775 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1776 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1777 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1778 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1779 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1780 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001781 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001782 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001783 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1784 if (ifmsh->user_mpm)
1785 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001786 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001787 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001788 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1789 conf->dot11MeshNbrOffsetMaxNeighbor =
1790 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001791 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1792 conf->dot11MeshHWMPmaxPREQretries =
1793 nconf->dot11MeshHWMPmaxPREQretries;
1794 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1795 conf->path_refresh_time = nconf->path_refresh_time;
1796 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1797 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1798 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1799 conf->dot11MeshHWMPactivePathTimeout =
1800 nconf->dot11MeshHWMPactivePathTimeout;
1801 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1802 conf->dot11MeshHWMPpreqMinInterval =
1803 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001804 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1805 conf->dot11MeshHWMPperrMinInterval =
1806 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001807 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1808 mask))
1809 conf->dot11MeshHWMPnetDiameterTraversalTime =
1810 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001811 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1812 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1813 ieee80211_mesh_root_setup(ifmsh);
1814 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001815 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001816 /* our current gate announcement implementation rides on root
1817 * announcements, so require this ifmsh to also be a root node
1818 * */
1819 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001820 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1821 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001822 ieee80211_mesh_root_setup(ifmsh);
1823 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001824 conf->dot11MeshGateAnnouncementProtocol =
1825 nconf->dot11MeshGateAnnouncementProtocol;
1826 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001827 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001828 conf->dot11MeshHWMPRannInterval =
1829 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001830 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1831 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001832 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1833 /* our RSSI threshold implementation is supported only for
1834 * devices that report signal in dBm.
1835 */
1836 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1837 return -ENOTSUPP;
1838 conf->rssi_threshold = nconf->rssi_threshold;
1839 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001840 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1841 conf->ht_opmode = nconf->ht_opmode;
1842 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1843 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1844 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001845 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1846 conf->dot11MeshHWMPactivePathToRootTimeout =
1847 nconf->dot11MeshHWMPactivePathToRootTimeout;
1848 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1849 conf->dot11MeshHWMProotInterval =
1850 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001851 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1852 conf->dot11MeshHWMPconfirmationInterval =
1853 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001854 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1855 conf->power_mode = nconf->power_mode;
1856 ieee80211_mps_local_status_update(sdata);
1857 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001858 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001859 conf->dot11MeshAwakeWindowDuration =
1860 nconf->dot11MeshAwakeWindowDuration;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001861 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001862 return 0;
1863}
1864
Johannes Berg29cbe682010-12-03 09:20:44 +01001865static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1866 const struct mesh_config *conf,
1867 const struct mesh_setup *setup)
1868{
1869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1870 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001871 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001872
Javier Cardonac80d5452010-12-16 17:37:49 -08001873 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1874 err = copy_mesh_setup(ifmsh, setup);
1875 if (err)
1876 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001877
Johannes Berg04ecd252012-09-11 14:34:12 +02001878 /* can mesh use other SMPS modes? */
1879 sdata->smps_mode = IEEE80211_SMPS_OFF;
1880 sdata->needed_rx_chains = sdata->local->rx_chains;
1881
Johannes Berg4bf88532012-11-09 11:39:59 +01001882 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001883 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001884 if (err)
1885 return err;
1886
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001887 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001888}
1889
1890static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1891{
1892 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1893
1894 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001895 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001896
1897 return 0;
1898}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001899#endif
1900
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001901static int ieee80211_change_bss(struct wiphy *wiphy,
1902 struct net_device *dev,
1903 struct bss_parameters *params)
1904{
Johannes Berg55de9082012-07-26 17:24:39 +02001905 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1906 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001907 u32 changed = 0;
1908
Johannes Berg55de9082012-07-26 17:24:39 +02001909 if (!rtnl_dereference(sdata->u.ap.beacon))
1910 return -ENOENT;
1911
1912 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001913
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001914 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001915 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001916 changed |= BSS_CHANGED_ERP_CTS_PROT;
1917 }
1918 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001919 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001920 params->use_short_preamble;
1921 changed |= BSS_CHANGED_ERP_PREAMBLE;
1922 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001923
1924 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001925 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001926 sdata->vif.bss_conf.use_short_slot = true;
1927 changed |= BSS_CHANGED_ERP_SLOT;
1928 }
1929
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001930 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001931 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001932 params->use_short_slot_time;
1933 changed |= BSS_CHANGED_ERP_SLOT;
1934 }
1935
Jouni Malinen90c97a02008-10-30 16:59:22 +02001936 if (params->basic_rates) {
1937 int i, j;
1938 u32 rates = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02001939 struct ieee80211_supported_band *sband = wiphy->bands[band];
Jouni Malinen90c97a02008-10-30 16:59:22 +02001940
1941 for (i = 0; i < params->basic_rates_len; i++) {
1942 int rate = (params->basic_rates[i] & 0x7f) * 5;
1943 for (j = 0; j < sband->n_bitrates; j++) {
1944 if (sband->bitrates[j].bitrate == rate)
1945 rates |= BIT(j);
1946 }
1947 }
1948 sdata->vif.bss_conf.basic_rates = rates;
1949 changed |= BSS_CHANGED_BASIC_RATES;
1950 }
1951
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001952 if (params->ap_isolate >= 0) {
1953 if (params->ap_isolate)
1954 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1955 else
1956 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1957 }
1958
Helmut Schaa80d7e402010-11-19 12:40:26 +01001959 if (params->ht_opmode >= 0) {
1960 sdata->vif.bss_conf.ht_operation_mode =
1961 (u16) params->ht_opmode;
1962 changed |= BSS_CHANGED_HT;
1963 }
1964
Johannes Berg339afbf2012-11-14 15:21:17 +01001965 if (params->p2p_ctwindow >= 0) {
1966 sdata->vif.bss_conf.p2p_ctwindow = params->p2p_ctwindow;
1967 changed |= BSS_CHANGED_P2P_PS;
1968 }
1969
1970 if (params->p2p_opp_ps >= 0) {
1971 sdata->vif.bss_conf.p2p_oppps = params->p2p_opp_ps;
1972 changed |= BSS_CHANGED_P2P_PS;
1973 }
1974
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001975 ieee80211_bss_info_change_notify(sdata, changed);
1976
1977 return 0;
1978}
1979
Jouni Malinen31888482008-10-30 16:59:24 +02001980static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001981 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001982 struct ieee80211_txq_params *params)
1983{
1984 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001985 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001986 struct ieee80211_tx_queue_params p;
1987
1988 if (!local->ops->conf_tx)
1989 return -EOPNOTSUPP;
1990
Johannes Berg54bcbc62012-03-28 11:04:25 +02001991 if (local->hw.queues < IEEE80211_NUM_ACS)
1992 return -EOPNOTSUPP;
1993
Jouni Malinen31888482008-10-30 16:59:24 +02001994 memset(&p, 0, sizeof(p));
1995 p.aifs = params->aifs;
1996 p.cw_max = params->cwmax;
1997 p.cw_min = params->cwmin;
1998 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001999
2000 /*
2001 * Setting tx queue params disables u-apsd because it's only
2002 * called in master mode.
2003 */
2004 p.uapsd = false;
2005
Johannes Berga3304b02012-03-28 11:04:24 +02002006 sdata->tx_conf[params->ac] = p;
2007 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002008 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002009 "failed to set TX queue parameters for AC %d\n",
2010 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002011 return -EINVAL;
2012 }
2013
Johannes Berg7d257452012-07-06 17:37:43 +02002014 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2015
Jouni Malinen31888482008-10-30 16:59:24 +02002016 return 0;
2017}
2018
Bob Copeland665af4f2009-01-19 11:20:53 -05002019#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002020static int ieee80211_suspend(struct wiphy *wiphy,
2021 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002022{
Johannes Bergeecc4802011-05-04 15:37:29 +02002023 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002024}
2025
2026static int ieee80211_resume(struct wiphy *wiphy)
2027{
2028 return __ieee80211_resume(wiphy_priv(wiphy));
2029}
2030#else
2031#define ieee80211_suspend NULL
2032#define ieee80211_resume NULL
2033#endif
2034
Johannes Berg2a519312009-02-10 21:25:55 +01002035static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002036 struct cfg80211_scan_request *req)
2037{
Johannes Bergfd014282012-06-18 19:17:03 +02002038 struct ieee80211_sub_if_data *sdata;
2039
2040 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002041
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002042 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2043 case NL80211_IFTYPE_STATION:
2044 case NL80211_IFTYPE_ADHOC:
2045 case NL80211_IFTYPE_MESH_POINT:
2046 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002047 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002048 break;
2049 case NL80211_IFTYPE_P2P_GO:
2050 if (sdata->local->ops->hw_scan)
2051 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002052 /*
2053 * FIXME: implement NoA while scanning in software,
2054 * for now fall through to allow scanning only when
2055 * beaconing hasn't been configured yet
2056 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002057 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002058 /*
2059 * If the scan has been forced (and the driver supports
2060 * forcing), don't care about being beaconing already.
2061 * This will create problems to the attached stations (e.g. all
2062 * the frames sent while scanning on other channel will be
2063 * lost)
2064 */
2065 if (sdata->u.ap.beacon &&
2066 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2067 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002068 return -EOPNOTSUPP;
2069 break;
2070 default:
2071 return -EOPNOTSUPP;
2072 }
Johannes Berg2a519312009-02-10 21:25:55 +01002073
2074 return ieee80211_request_scan(sdata, req);
2075}
2076
Luciano Coelho79f460c2011-05-11 17:09:36 +03002077static int
2078ieee80211_sched_scan_start(struct wiphy *wiphy,
2079 struct net_device *dev,
2080 struct cfg80211_sched_scan_request *req)
2081{
2082 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2083
2084 if (!sdata->local->ops->sched_scan_start)
2085 return -EOPNOTSUPP;
2086
2087 return ieee80211_request_sched_scan_start(sdata, req);
2088}
2089
2090static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002091ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002092{
2093 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2094
2095 if (!sdata->local->ops->sched_scan_stop)
2096 return -EOPNOTSUPP;
2097
Luciano Coelho85a99942011-05-12 16:28:29 +03002098 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002099}
2100
Jouni Malinen636a5d32009-03-19 13:39:22 +02002101static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2102 struct cfg80211_auth_request *req)
2103{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002104 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002105}
2106
2107static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2108 struct cfg80211_assoc_request *req)
2109{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002110 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002111}
2112
2113static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002114 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002115{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002116 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002117}
2118
2119static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002120 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002121{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002122 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002123}
2124
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002125static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2126 struct cfg80211_ibss_params *params)
2127{
Johannes Berg55de9082012-07-26 17:24:39 +02002128 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002129}
2130
2131static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2132{
Johannes Berg55de9082012-07-26 17:24:39 +02002133 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002134}
2135
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002136static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2137 int rate[IEEE80211_NUM_BANDS])
2138{
2139 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2140
Cong Ding9887dbf2013-02-06 17:23:45 +01002141 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2142 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002143
2144 return 0;
2145}
2146
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002147static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2148{
2149 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002150 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002151
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002152 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2153 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2154
2155 if (err)
2156 return err;
2157 }
2158
Lukáš Turek310bc672009-12-21 22:50:48 +01002159 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2160 err = drv_set_coverage_class(local, wiphy->coverage_class);
2161
2162 if (err)
2163 return err;
2164 }
2165
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002166 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002167 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002168
Johannes Berg24487982009-04-23 18:52:52 +02002169 if (err)
2170 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002171 }
2172
Johannes Berg8bc83c22012-11-09 18:38:32 +01002173 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2174 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2175 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002176 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002177 }
2178 if (changed & WIPHY_PARAM_RETRY_LONG) {
2179 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2180 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002181 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002182 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002183 if (changed &
2184 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2185 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2186
2187 return 0;
2188}
2189
Johannes Berg7643a2c2009-06-02 13:01:39 +02002190static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002191 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002192 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002193{
2194 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002195 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002196
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002197 if (wdev) {
2198 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2199
2200 switch (type) {
2201 case NL80211_TX_POWER_AUTOMATIC:
2202 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2203 break;
2204 case NL80211_TX_POWER_LIMITED:
2205 case NL80211_TX_POWER_FIXED:
2206 if (mbm < 0 || (mbm % 100))
2207 return -EOPNOTSUPP;
2208 sdata->user_power_level = MBM_TO_DBM(mbm);
2209 break;
2210 }
2211
2212 ieee80211_recalc_txpower(sdata);
2213
2214 return 0;
2215 }
Johannes Berg55de9082012-07-26 17:24:39 +02002216
Johannes Berg7643a2c2009-06-02 13:01:39 +02002217 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002218 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002219 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002220 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002221 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002222 case NL80211_TX_POWER_FIXED:
2223 if (mbm < 0 || (mbm % 100))
2224 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002225 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002226 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002227 }
2228
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002229 mutex_lock(&local->iflist_mtx);
2230 list_for_each_entry(sdata, &local->interfaces, list)
2231 sdata->user_power_level = local->user_power_level;
2232 list_for_each_entry(sdata, &local->interfaces, list)
2233 ieee80211_recalc_txpower(sdata);
2234 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002235
2236 return 0;
2237}
2238
Johannes Bergc8442112012-10-24 10:17:18 +02002239static int ieee80211_get_tx_power(struct wiphy *wiphy,
2240 struct wireless_dev *wdev,
2241 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002242{
2243 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002244 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002245
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002246 if (!local->use_chanctx)
2247 *dbm = local->hw.conf.power_level;
2248 else
2249 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002250
Johannes Berg7643a2c2009-06-02 13:01:39 +02002251 return 0;
2252}
2253
Johannes Bergab737a42009-07-01 21:26:58 +02002254static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002255 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002256{
2257 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2258
2259 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2260
2261 return 0;
2262}
2263
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002264static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2265{
2266 struct ieee80211_local *local = wiphy_priv(wiphy);
2267
2268 drv_rfkill_poll(local);
2269}
2270
Johannes Bergaff89a92009-07-01 21:26:51 +02002271#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002272static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002273{
2274 struct ieee80211_local *local = wiphy_priv(wiphy);
2275
2276 if (!local->ops->testmode_cmd)
2277 return -EOPNOTSUPP;
2278
2279 return local->ops->testmode_cmd(&local->hw, data, len);
2280}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002281
2282static int ieee80211_testmode_dump(struct wiphy *wiphy,
2283 struct sk_buff *skb,
2284 struct netlink_callback *cb,
2285 void *data, int len)
2286{
2287 struct ieee80211_local *local = wiphy_priv(wiphy);
2288
2289 if (!local->ops->testmode_dump)
2290 return -EOPNOTSUPP;
2291
2292 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2293}
Johannes Bergaff89a92009-07-01 21:26:51 +02002294#endif
2295
Johannes Berg0f782312009-12-01 13:37:02 +01002296int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2297 enum ieee80211_smps_mode smps_mode)
2298{
2299 const u8 *ap;
2300 enum ieee80211_smps_mode old_req;
2301 int err;
2302
Johannes Berg243e6df2011-04-19 20:44:04 +02002303 lockdep_assert_held(&sdata->u.mgd.mtx);
2304
Johannes Berg0f782312009-12-01 13:37:02 +01002305 old_req = sdata->u.mgd.req_smps;
2306 sdata->u.mgd.req_smps = smps_mode;
2307
2308 if (old_req == smps_mode &&
2309 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2310 return 0;
2311
2312 /*
2313 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002314 * association, there's no need to do anything, just store
2315 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002316 */
2317 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002318 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002319 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002320
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002321 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002322
2323 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2324 if (sdata->u.mgd.powersave)
2325 smps_mode = IEEE80211_SMPS_DYNAMIC;
2326 else
2327 smps_mode = IEEE80211_SMPS_OFF;
2328 }
2329
2330 /* send SM PS frame to AP */
2331 err = ieee80211_send_smps_action(sdata, smps_mode,
2332 ap, ap);
2333 if (err)
2334 sdata->u.mgd.req_smps = old_req;
2335
2336 return err;
2337}
2338
Johannes Bergbc92afd2009-07-01 21:26:57 +02002339static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2340 bool enabled, int timeout)
2341{
2342 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2343 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002344
Chun-Yeow Yeohee1f6682013-01-10 23:31:54 +08002345 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
2346 sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002347 return -EOPNOTSUPP;
2348
Johannes Bergbc92afd2009-07-01 21:26:57 +02002349 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2350 return -EOPNOTSUPP;
2351
2352 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002353 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002354 return 0;
2355
2356 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002357 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002358
Johannes Berg0f782312009-12-01 13:37:02 +01002359 /* no change, but if automatic follow powersave */
2360 mutex_lock(&sdata->u.mgd.mtx);
2361 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2362 mutex_unlock(&sdata->u.mgd.mtx);
2363
Johannes Bergbc92afd2009-07-01 21:26:57 +02002364 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2365 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2366
2367 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002368 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002369
2370 return 0;
2371}
2372
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002373static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2374 struct net_device *dev,
2375 s32 rssi_thold, u32 rssi_hyst)
2376{
2377 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002378 struct ieee80211_vif *vif = &sdata->vif;
2379 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2380
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002381 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2382 rssi_hyst == bss_conf->cqm_rssi_hyst)
2383 return 0;
2384
2385 bss_conf->cqm_rssi_thold = rssi_thold;
2386 bss_conf->cqm_rssi_hyst = rssi_hyst;
2387
2388 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002389 if (sdata->u.mgd.associated &&
2390 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002391 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2392
2393 return 0;
2394}
2395
Johannes Berg99303802009-07-01 21:26:59 +02002396static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2397 struct net_device *dev,
2398 const u8 *addr,
2399 const struct cfg80211_bitrate_mask *mask)
2400{
2401 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2402 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302403 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002404
Eliad Peller554a43d2012-06-12 12:41:15 +03002405 if (!ieee80211_sdata_running(sdata))
2406 return -ENETDOWN;
2407
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302408 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2409 ret = drv_set_bitrate_mask(local, sdata, mask);
2410 if (ret)
2411 return ret;
2412 }
Johannes Berg99303802009-07-01 21:26:59 +02002413
Simon Wunderlich19468412012-01-28 17:25:33 +01002414 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002415 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002416 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2417 sizeof(mask->control[i].mcs));
2418 }
Johannes Berg99303802009-07-01 21:26:59 +02002419
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002420 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002421}
2422
Johannes Berg2eb278e2012-06-05 14:28:42 +02002423static int ieee80211_start_roc_work(struct ieee80211_local *local,
2424 struct ieee80211_sub_if_data *sdata,
2425 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002426 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002427 struct sk_buff *txskb,
2428 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002429{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002430 struct ieee80211_roc_work *roc, *tmp;
2431 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002432 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002433
2434 lockdep_assert_held(&local->mtx);
2435
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002436 if (local->use_chanctx && !local->ops->remain_on_channel)
2437 return -EOPNOTSUPP;
2438
Johannes Berg2eb278e2012-06-05 14:28:42 +02002439 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2440 if (!roc)
2441 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002442
Johannes Berg2eb278e2012-06-05 14:28:42 +02002443 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002444 roc->duration = duration;
2445 roc->req_duration = duration;
2446 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002447 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002448 roc->mgmt_tx_cookie = (unsigned long)txskb;
2449 roc->sdata = sdata;
2450 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2451 INIT_LIST_HEAD(&roc->dependents);
2452
2453 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002454 if (!list_empty(&local->roc_list) ||
2455 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002456 goto out_check_combine;
2457
2458 /* if not HW assist, just queue & schedule work */
2459 if (!local->ops->remain_on_channel) {
2460 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2461 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002462 }
2463
Johannes Berg2eb278e2012-06-05 14:28:42 +02002464 /* otherwise actually kick it off here (for error handling) */
2465
2466 /*
2467 * If the duration is zero, then the driver
2468 * wouldn't actually do anything. Set it to
2469 * 10 for now.
2470 *
2471 * TODO: cancel the off-channel operation
2472 * when we get the SKB's TX status and
2473 * the wait time was zero before.
2474 */
2475 if (!duration)
2476 duration = 10;
2477
Ilan Peerd339d5c2013-02-12 09:34:13 +02002478 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002479 if (ret) {
2480 kfree(roc);
2481 return ret;
2482 }
2483
2484 roc->started = true;
2485 goto out_queue;
2486
2487 out_check_combine:
2488 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002489 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002490 continue;
2491
2492 /*
2493 * Extend this ROC if possible:
2494 *
2495 * If it hasn't started yet, just increase the duration
2496 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002497 * If the type of the new ROC has higher priority, modify the
2498 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002499 */
2500 if (!tmp->started) {
2501 list_add_tail(&roc->list, &tmp->dependents);
2502 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002503 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002504 queued = true;
2505 break;
2506 }
2507
2508 /* If it has already started, it's more difficult ... */
2509 if (local->ops->remain_on_channel) {
2510 unsigned long j = jiffies;
2511
2512 /*
2513 * In the offloaded ROC case, if it hasn't begun, add
2514 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002515 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002516 * check that there's still a minimum time left and
2517 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002518 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002519 * a reduced time so we'll ask the driver to execute
2520 * it right after finishing the previous one, in the
2521 * hope that it'll also be executed right afterwards,
2522 * effectively extending the old one.
2523 * If there's no minimum time left, just add it to the
2524 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002525 * TODO: the ROC type is ignored here, assuming that it
2526 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002527 */
2528 if (!tmp->hw_begun) {
2529 list_add_tail(&roc->list, &tmp->dependents);
2530 queued = true;
2531 break;
2532 }
2533
2534 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2535 tmp->hw_start_time +
2536 msecs_to_jiffies(tmp->duration))) {
2537 int new_dur;
2538
2539 ieee80211_handle_roc_started(roc);
2540
2541 new_dur = roc->duration -
2542 jiffies_to_msecs(tmp->hw_start_time +
2543 msecs_to_jiffies(
2544 tmp->duration) -
2545 j);
2546
2547 if (new_dur > 0) {
2548 /* add right after tmp */
2549 list_add(&roc->list, &tmp->list);
2550 } else {
2551 list_add_tail(&roc->list,
2552 &tmp->dependents);
2553 }
2554 queued = true;
2555 }
2556 } else if (del_timer_sync(&tmp->work.timer)) {
2557 unsigned long new_end;
2558
2559 /*
2560 * In the software ROC case, cancel the timer, if
2561 * that fails then the finish work is already
2562 * queued/pending and thus we queue the new ROC
2563 * normally, if that succeeds then we can extend
2564 * the timer duration and TX the frame (if any.)
2565 */
2566
2567 list_add_tail(&roc->list, &tmp->dependents);
2568 queued = true;
2569
2570 new_end = jiffies + msecs_to_jiffies(roc->duration);
2571
2572 /* ok, it was started & we canceled timer */
2573 if (time_after(new_end, tmp->work.timer.expires))
2574 mod_timer(&tmp->work.timer, new_end);
2575 else
2576 add_timer(&tmp->work.timer);
2577
2578 ieee80211_handle_roc_started(roc);
2579 }
2580 break;
2581 }
2582
2583 out_queue:
2584 if (!queued)
2585 list_add_tail(&roc->list, &local->roc_list);
2586
2587 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002588 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002589 * or the SKB (for mgmt TX)
2590 */
Johannes Berg50febf62012-10-26 16:13:06 +02002591 if (!txskb) {
2592 /* local->mtx protects this */
2593 local->roc_cookie_counter++;
2594 roc->cookie = local->roc_cookie_counter;
2595 /* wow, you wrapped 64 bits ... more likely a bug */
2596 if (WARN_ON(roc->cookie == 0)) {
2597 roc->cookie = 1;
2598 local->roc_cookie_counter++;
2599 }
2600 *cookie = roc->cookie;
2601 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002602 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002603 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002604
2605 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002606}
2607
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002608static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002609 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002610 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002611 unsigned int duration,
2612 u64 *cookie)
2613{
Johannes Berg71bbc992012-06-15 15:30:18 +02002614 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002615 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002616 int ret;
2617
Johannes Berg2eb278e2012-06-05 14:28:42 +02002618 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002619 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002620 duration, cookie, NULL,
2621 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002622 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002623
Johannes Berg2eb278e2012-06-05 14:28:42 +02002624 return ret;
2625}
2626
2627static int ieee80211_cancel_roc(struct ieee80211_local *local,
2628 u64 cookie, bool mgmt_tx)
2629{
2630 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2631 int ret;
2632
2633 mutex_lock(&local->mtx);
2634 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002635 struct ieee80211_roc_work *dep, *tmp2;
2636
2637 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002638 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002639 continue;
2640 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2641 continue;
2642 /* found dependent item -- just remove it */
2643 list_del(&dep->list);
2644 mutex_unlock(&local->mtx);
2645
2646 ieee80211_roc_notify_destroy(dep);
2647 return 0;
2648 }
2649
Johannes Berg50febf62012-10-26 16:13:06 +02002650 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002651 continue;
2652 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2653 continue;
2654
2655 found = roc;
2656 break;
2657 }
2658
2659 if (!found) {
2660 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002661 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002662 }
Johannes Berg21f83582010-12-18 17:20:47 +01002663
Johannes Berge979e332012-06-11 17:09:41 +02002664 /*
2665 * We found the item to cancel, so do that. Note that it
2666 * may have dependents, which we also cancel (and send
2667 * the expired signal for.) Not doing so would be quite
2668 * tricky here, but we may need to fix it later.
2669 */
2670
Johannes Berg2eb278e2012-06-05 14:28:42 +02002671 if (local->ops->remain_on_channel) {
2672 if (found->started) {
2673 ret = drv_cancel_remain_on_channel(local);
2674 if (WARN_ON_ONCE(ret)) {
2675 mutex_unlock(&local->mtx);
2676 return ret;
2677 }
2678 }
Johannes Berg21f83582010-12-18 17:20:47 +01002679
Johannes Berg2eb278e2012-06-05 14:28:42 +02002680 list_del(&found->list);
2681
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002682 if (found->started)
2683 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002684 mutex_unlock(&local->mtx);
2685
2686 ieee80211_roc_notify_destroy(found);
2687 } else {
2688 /* work may be pending so use it all the time */
2689 found->abort = true;
2690 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2691
2692 mutex_unlock(&local->mtx);
2693
2694 /* work will clean up etc */
2695 flush_delayed_work(&found->work);
2696 }
Johannes Berg21f83582010-12-18 17:20:47 +01002697
Johannes Berg21f83582010-12-18 17:20:47 +01002698 return 0;
2699}
2700
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002701static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002702 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002703 u64 cookie)
2704{
Johannes Berg71bbc992012-06-15 15:30:18 +02002705 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002706 struct ieee80211_local *local = sdata->local;
2707
Johannes Berg2eb278e2012-06-05 14:28:42 +02002708 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002709}
2710
Simon Wunderlich164eb022013-02-08 18:16:20 +01002711static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2712 struct net_device *dev,
2713 struct cfg80211_chan_def *chandef)
2714{
2715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2716 struct ieee80211_local *local = sdata->local;
2717 unsigned long timeout;
2718 int err;
2719
2720 if (!list_empty(&local->roc_list) || local->scanning)
2721 return -EBUSY;
2722
2723 /* whatever, but channel contexts should not complain about that one */
2724 sdata->smps_mode = IEEE80211_SMPS_OFF;
2725 sdata->needed_rx_chains = local->rx_chains;
2726 sdata->radar_required = true;
2727
2728 mutex_lock(&local->iflist_mtx);
2729 err = ieee80211_vif_use_channel(sdata, chandef,
2730 IEEE80211_CHANCTX_SHARED);
2731 mutex_unlock(&local->iflist_mtx);
2732 if (err)
2733 return err;
2734
2735 timeout = msecs_to_jiffies(IEEE80211_DFS_MIN_CAC_TIME_MS);
2736 ieee80211_queue_delayed_work(&sdata->local->hw,
2737 &sdata->dfs_cac_timer_work, timeout);
2738
2739 return 0;
2740}
2741
Johannes Berg71bbc992012-06-15 15:30:18 +02002742static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002743 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01002744 unsigned int wait, const u8 *buf, size_t len,
2745 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002746{
Johannes Berg71bbc992012-06-15 15:30:18 +02002747 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002748 struct ieee80211_local *local = sdata->local;
2749 struct sk_buff *skb;
2750 struct sta_info *sta;
2751 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002752 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002753 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002754 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002755
Johannes Berge247bd902011-11-04 11:18:21 +01002756 if (dont_wait_for_ack)
2757 flags = IEEE80211_TX_CTL_NO_ACK;
2758 else
2759 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2760 IEEE80211_TX_CTL_REQ_TX_STATUS;
2761
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302762 if (no_cck)
2763 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2764
Johannes Berg9d38d852010-06-09 17:20:33 +02002765 switch (sdata->vif.type) {
2766 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002767 if (!sdata->vif.bss_conf.ibss_joined)
2768 need_offchan = true;
2769 /* fall through */
2770#ifdef CONFIG_MAC80211_MESH
2771 case NL80211_IFTYPE_MESH_POINT:
2772 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2773 !sdata->u.mesh.mesh_id_len)
2774 need_offchan = true;
2775 /* fall through */
2776#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002777 case NL80211_IFTYPE_AP:
2778 case NL80211_IFTYPE_AP_VLAN:
2779 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002780 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2781 !ieee80211_vif_is_mesh(&sdata->vif) &&
2782 !rcu_access_pointer(sdata->bss->beacon))
2783 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002784 if (!ieee80211_is_action(mgmt->frame_control) ||
2785 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002786 break;
2787 rcu_read_lock();
2788 sta = sta_info_get(sdata, mgmt->da);
2789 rcu_read_unlock();
2790 if (!sta)
2791 return -ENOLINK;
2792 break;
2793 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002794 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002795 if (!sdata->u.mgd.associated)
2796 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002797 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002798 case NL80211_IFTYPE_P2P_DEVICE:
2799 need_offchan = true;
2800 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002801 default:
2802 return -EOPNOTSUPP;
2803 }
2804
Johannes Berg2eb278e2012-06-05 14:28:42 +02002805 mutex_lock(&local->mtx);
2806
2807 /* Check if the operating channel is the requested channel */
2808 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02002809 struct ieee80211_chanctx_conf *chanctx_conf;
2810
2811 rcu_read_lock();
2812 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2813
Johannes Berg42d97a52012-11-08 18:31:02 +01002814 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +01002815 need_offchan = chan != chanctx_conf->def.chan;
Johannes Berg42d97a52012-11-08 18:31:02 +01002816 else
Johannes Berg2eb278e2012-06-05 14:28:42 +02002817 need_offchan = true;
Johannes Berg55de9082012-07-26 17:24:39 +02002818 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02002819 }
2820
2821 if (need_offchan && !offchan) {
2822 ret = -EBUSY;
2823 goto out_unlock;
2824 }
2825
Johannes Berg9d38d852010-06-09 17:20:33 +02002826 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002827 if (!skb) {
2828 ret = -ENOMEM;
2829 goto out_unlock;
2830 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002831 skb_reserve(skb, local->hw.extra_tx_headroom);
2832
2833 memcpy(skb_put(skb, len), buf, len);
2834
2835 IEEE80211_SKB_CB(skb)->flags = flags;
2836
Johannes Berg2eb278e2012-06-05 14:28:42 +02002837 skb->dev = sdata->dev;
2838
2839 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002840 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002841 ieee80211_tx_skb(sdata, skb);
2842 ret = 0;
2843 goto out_unlock;
2844 }
2845
Seth Forshee6c17b772013-02-11 11:21:07 -06002846 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
2847 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002848 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002849 IEEE80211_SKB_CB(skb)->hw_queue =
2850 local->hw.offchannel_tx_hw_queue;
2851
Johannes Berg2eb278e2012-06-05 14:28:42 +02002852 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01002853 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002854 wait, cookie, skb,
2855 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002856 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002857 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002858 out_unlock:
2859 mutex_unlock(&local->mtx);
2860 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002861}
2862
Johannes Bergf30221e2010-11-25 10:02:30 +01002863static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002864 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002865 u64 cookie)
2866{
Johannes Berg71bbc992012-06-15 15:30:18 +02002867 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002868
Johannes Berg2eb278e2012-06-05 14:28:42 +02002869 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002870}
2871
Johannes Berg7be50862010-10-13 12:06:24 +02002872static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002873 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002874 u16 frame_type, bool reg)
2875{
2876 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002877 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002878
Will Hawkins6abe0562012-06-20 11:51:14 -04002879 switch (frame_type) {
2880 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2881 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2882 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002883
Will Hawkins6abe0562012-06-20 11:51:14 -04002884 if (reg)
2885 ifibss->auth_frame_registrations++;
2886 else
2887 ifibss->auth_frame_registrations--;
2888 }
2889 break;
2890 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2891 if (reg)
2892 local->probe_req_reg++;
2893 else
2894 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002895
Felix Fietkau35f51492012-10-31 15:50:34 +01002896 if (!local->open_count)
2897 break;
2898
Will Hawkins6abe0562012-06-20 11:51:14 -04002899 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2900 break;
2901 default:
2902 break;
2903 }
Johannes Berg7be50862010-10-13 12:06:24 +02002904}
2905
Bruno Randolf15d96752010-11-10 12:50:56 +09002906static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2907{
2908 struct ieee80211_local *local = wiphy_priv(wiphy);
2909
2910 if (local->started)
2911 return -EOPNOTSUPP;
2912
2913 return drv_set_antenna(local, tx_ant, rx_ant);
2914}
2915
2916static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2917{
2918 struct ieee80211_local *local = wiphy_priv(wiphy);
2919
2920 return drv_get_antenna(local, tx_ant, rx_ant);
2921}
2922
John W. Linville38c09152011-03-07 16:19:18 -05002923static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2924{
2925 struct ieee80211_local *local = wiphy_priv(wiphy);
2926
2927 return drv_set_ringparam(local, tx, rx);
2928}
2929
2930static void ieee80211_get_ringparam(struct wiphy *wiphy,
2931 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2932{
2933 struct ieee80211_local *local = wiphy_priv(wiphy);
2934
2935 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2936}
2937
Johannes Bergc68f4b82011-07-05 16:35:41 +02002938static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2939 struct net_device *dev,
2940 struct cfg80211_gtk_rekey_data *data)
2941{
2942 struct ieee80211_local *local = wiphy_priv(wiphy);
2943 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2944
2945 if (!local->ops->set_rekey_data)
2946 return -EOPNOTSUPP;
2947
2948 drv_set_rekey_data(local, sdata, data);
2949
2950 return 0;
2951}
2952
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002953static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2954{
2955 u8 *pos = (void *)skb_put(skb, 7);
2956
2957 *pos++ = WLAN_EID_EXT_CAPABILITY;
2958 *pos++ = 5; /* len */
2959 *pos++ = 0x0;
2960 *pos++ = 0x0;
2961 *pos++ = 0x0;
2962 *pos++ = 0x0;
2963 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2964}
2965
2966static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2967{
2968 struct ieee80211_local *local = sdata->local;
2969 u16 capab;
2970
2971 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002972 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002973 return capab;
2974
2975 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2976 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2977 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2978 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2979
2980 return capab;
2981}
2982
2983static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2984 u8 *peer, u8 *bssid)
2985{
2986 struct ieee80211_tdls_lnkie *lnkid;
2987
2988 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2989
2990 lnkid->ie_type = WLAN_EID_LINK_ID;
2991 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2992
2993 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2994 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2995 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2996}
2997
2998static int
2999ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3000 u8 *peer, u8 action_code, u8 dialog_token,
3001 u16 status_code, struct sk_buff *skb)
3002{
3003 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003004 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003005 struct ieee80211_tdls_data *tf;
3006
3007 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3008
3009 memcpy(tf->da, peer, ETH_ALEN);
3010 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3011 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3012 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3013
3014 switch (action_code) {
3015 case WLAN_TDLS_SETUP_REQUEST:
3016 tf->category = WLAN_CATEGORY_TDLS;
3017 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3018
3019 skb_put(skb, sizeof(tf->u.setup_req));
3020 tf->u.setup_req.dialog_token = dialog_token;
3021 tf->u.setup_req.capability =
3022 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3023
Johannes Berg55de9082012-07-26 17:24:39 +02003024 ieee80211_add_srates_ie(sdata, skb, false, band);
3025 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003026 ieee80211_tdls_add_ext_capab(skb);
3027 break;
3028 case WLAN_TDLS_SETUP_RESPONSE:
3029 tf->category = WLAN_CATEGORY_TDLS;
3030 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3031
3032 skb_put(skb, sizeof(tf->u.setup_resp));
3033 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3034 tf->u.setup_resp.dialog_token = dialog_token;
3035 tf->u.setup_resp.capability =
3036 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3037
Johannes Berg55de9082012-07-26 17:24:39 +02003038 ieee80211_add_srates_ie(sdata, skb, false, band);
3039 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003040 ieee80211_tdls_add_ext_capab(skb);
3041 break;
3042 case WLAN_TDLS_SETUP_CONFIRM:
3043 tf->category = WLAN_CATEGORY_TDLS;
3044 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3045
3046 skb_put(skb, sizeof(tf->u.setup_cfm));
3047 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3048 tf->u.setup_cfm.dialog_token = dialog_token;
3049 break;
3050 case WLAN_TDLS_TEARDOWN:
3051 tf->category = WLAN_CATEGORY_TDLS;
3052 tf->action_code = WLAN_TDLS_TEARDOWN;
3053
3054 skb_put(skb, sizeof(tf->u.teardown));
3055 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3056 break;
3057 case WLAN_TDLS_DISCOVERY_REQUEST:
3058 tf->category = WLAN_CATEGORY_TDLS;
3059 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3060
3061 skb_put(skb, sizeof(tf->u.discover_req));
3062 tf->u.discover_req.dialog_token = dialog_token;
3063 break;
3064 default:
3065 return -EINVAL;
3066 }
3067
3068 return 0;
3069}
3070
3071static int
3072ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3073 u8 *peer, u8 action_code, u8 dialog_token,
3074 u16 status_code, struct sk_buff *skb)
3075{
3076 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003077 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003078 struct ieee80211_mgmt *mgmt;
3079
3080 mgmt = (void *)skb_put(skb, 24);
3081 memset(mgmt, 0, 24);
3082 memcpy(mgmt->da, peer, ETH_ALEN);
3083 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3084 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3085
3086 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3087 IEEE80211_STYPE_ACTION);
3088
3089 switch (action_code) {
3090 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3091 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3092 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3093 mgmt->u.action.u.tdls_discover_resp.action_code =
3094 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3095 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3096 dialog_token;
3097 mgmt->u.action.u.tdls_discover_resp.capability =
3098 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3099
Johannes Berg55de9082012-07-26 17:24:39 +02003100 ieee80211_add_srates_ie(sdata, skb, false, band);
3101 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003102 ieee80211_tdls_add_ext_capab(skb);
3103 break;
3104 default:
3105 return -EINVAL;
3106 }
3107
3108 return 0;
3109}
3110
3111static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3112 u8 *peer, u8 action_code, u8 dialog_token,
3113 u16 status_code, const u8 *extra_ies,
3114 size_t extra_ies_len)
3115{
3116 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3117 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003118 struct sk_buff *skb = NULL;
3119 bool send_direct;
3120 int ret;
3121
3122 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3123 return -ENOTSUPP;
3124
3125 /* make sure we are in managed mode, and associated */
3126 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3127 !sdata->u.mgd.associated)
3128 return -EINVAL;
3129
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003130 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3131 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003132
3133 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3134 max(sizeof(struct ieee80211_mgmt),
3135 sizeof(struct ieee80211_tdls_data)) +
3136 50 + /* supported rates */
3137 7 + /* ext capab */
3138 extra_ies_len +
3139 sizeof(struct ieee80211_tdls_lnkie));
3140 if (!skb)
3141 return -ENOMEM;
3142
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003143 skb_reserve(skb, local->hw.extra_tx_headroom);
3144
3145 switch (action_code) {
3146 case WLAN_TDLS_SETUP_REQUEST:
3147 case WLAN_TDLS_SETUP_RESPONSE:
3148 case WLAN_TDLS_SETUP_CONFIRM:
3149 case WLAN_TDLS_TEARDOWN:
3150 case WLAN_TDLS_DISCOVERY_REQUEST:
3151 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3152 action_code, dialog_token,
3153 status_code, skb);
3154 send_direct = false;
3155 break;
3156 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3157 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3158 dialog_token, status_code,
3159 skb);
3160 send_direct = true;
3161 break;
3162 default:
3163 ret = -ENOTSUPP;
3164 break;
3165 }
3166
3167 if (ret < 0)
3168 goto fail;
3169
3170 if (extra_ies_len)
3171 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3172
3173 /* the TDLS link IE is always added last */
3174 switch (action_code) {
3175 case WLAN_TDLS_SETUP_REQUEST:
3176 case WLAN_TDLS_SETUP_CONFIRM:
3177 case WLAN_TDLS_TEARDOWN:
3178 case WLAN_TDLS_DISCOVERY_REQUEST:
3179 /* we are the initiator */
3180 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3181 sdata->u.mgd.bssid);
3182 break;
3183 case WLAN_TDLS_SETUP_RESPONSE:
3184 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3185 /* we are the responder */
3186 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3187 sdata->u.mgd.bssid);
3188 break;
3189 default:
3190 ret = -ENOTSUPP;
3191 goto fail;
3192 }
3193
3194 if (send_direct) {
3195 ieee80211_tx_skb(sdata, skb);
3196 return 0;
3197 }
3198
3199 /*
3200 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3201 * we should default to AC_VI.
3202 */
3203 switch (action_code) {
3204 case WLAN_TDLS_SETUP_REQUEST:
3205 case WLAN_TDLS_SETUP_RESPONSE:
3206 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3207 skb->priority = 2;
3208 break;
3209 default:
3210 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3211 skb->priority = 5;
3212 break;
3213 }
3214
3215 /* disable bottom halves when entering the Tx path */
3216 local_bh_disable();
3217 ret = ieee80211_subif_start_xmit(skb, dev);
3218 local_bh_enable();
3219
3220 return ret;
3221
3222fail:
3223 dev_kfree_skb(skb);
3224 return ret;
3225}
3226
3227static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3228 u8 *peer, enum nl80211_tdls_operation oper)
3229{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003230 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3232
3233 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3234 return -ENOTSUPP;
3235
3236 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3237 return -EINVAL;
3238
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003239 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003240
3241 switch (oper) {
3242 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003243 rcu_read_lock();
3244 sta = sta_info_get(sdata, peer);
3245 if (!sta) {
3246 rcu_read_unlock();
3247 return -ENOLINK;
3248 }
3249
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003250 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003251 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003252 break;
3253 case NL80211_TDLS_DISABLE_LINK:
3254 return sta_info_destroy_addr(sdata, peer);
3255 case NL80211_TDLS_TEARDOWN:
3256 case NL80211_TDLS_SETUP:
3257 case NL80211_TDLS_DISCOVERY_REQ:
3258 /* We don't support in-driver setup/teardown/discovery */
3259 return -ENOTSUPP;
3260 default:
3261 return -ENOTSUPP;
3262 }
3263
3264 return 0;
3265}
3266
Johannes Berg06500732011-11-04 11:18:16 +01003267static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3268 const u8 *peer, u64 *cookie)
3269{
3270 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3271 struct ieee80211_local *local = sdata->local;
3272 struct ieee80211_qos_hdr *nullfunc;
3273 struct sk_buff *skb;
3274 int size = sizeof(*nullfunc);
3275 __le16 fc;
3276 bool qos;
3277 struct ieee80211_tx_info *info;
3278 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003279 struct ieee80211_chanctx_conf *chanctx_conf;
3280 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003281
3282 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003283 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3284 if (WARN_ON(!chanctx_conf)) {
3285 rcu_read_unlock();
3286 return -EINVAL;
3287 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003288 band = chanctx_conf->def.chan->band;
Johannes Berg06500732011-11-04 11:18:16 +01003289 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003290 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003291 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003292 } else {
3293 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003294 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003295 }
Johannes Berg06500732011-11-04 11:18:16 +01003296
3297 if (qos) {
3298 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3299 IEEE80211_STYPE_QOS_NULLFUNC |
3300 IEEE80211_FCTL_FROMDS);
3301 } else {
3302 size -= 2;
3303 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3304 IEEE80211_STYPE_NULLFUNC |
3305 IEEE80211_FCTL_FROMDS);
3306 }
3307
3308 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003309 if (!skb) {
3310 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003311 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003312 }
Johannes Berg06500732011-11-04 11:18:16 +01003313
3314 skb->dev = dev;
3315
3316 skb_reserve(skb, local->hw.extra_tx_headroom);
3317
3318 nullfunc = (void *) skb_put(skb, size);
3319 nullfunc->frame_control = fc;
3320 nullfunc->duration_id = 0;
3321 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3322 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3323 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3324 nullfunc->seq_ctrl = 0;
3325
3326 info = IEEE80211_SKB_CB(skb);
3327
3328 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3329 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3330
3331 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3332 skb->priority = 7;
3333 if (qos)
3334 nullfunc->qos_ctrl = cpu_to_le16(7);
3335
3336 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003337 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003338 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003339 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003340
3341 *cookie = (unsigned long) skb;
3342 return 0;
3343}
3344
Johannes Berg683b6d32012-11-08 21:25:48 +01003345static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3346 struct wireless_dev *wdev,
3347 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003348{
Johannes Berg55de9082012-07-26 17:24:39 +02003349 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003350 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003351 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003352 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003353
Johannes Berg55de9082012-07-26 17:24:39 +02003354 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003355 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3356 if (chanctx_conf) {
3357 *chandef = chanctx_conf->def;
3358 ret = 0;
3359 } else if (local->open_count > 0 &&
3360 local->open_count == local->monitors &&
3361 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3362 if (local->use_chanctx)
3363 *chandef = local->monitor_chandef;
3364 else
3365 cfg80211_chandef_create(chandef,
3366 local->_oper_channel,
3367 local->_oper_channel_type);
Johannes Berg683b6d32012-11-08 21:25:48 +01003368 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003369 }
3370 rcu_read_unlock();
3371
Johannes Berg683b6d32012-11-08 21:25:48 +01003372 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003373}
3374
Johannes Berg6d525632012-04-04 15:05:25 +02003375#ifdef CONFIG_PM
3376static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3377{
3378 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3379}
3380#endif
3381
Jiri Bencf0706e82007-05-05 11:45:53 -07003382struct cfg80211_ops mac80211_config_ops = {
3383 .add_virtual_intf = ieee80211_add_iface,
3384 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003385 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003386 .start_p2p_device = ieee80211_start_p2p_device,
3387 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003388 .add_key = ieee80211_add_key,
3389 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003390 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003391 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003392 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003393 .start_ap = ieee80211_start_ap,
3394 .change_beacon = ieee80211_change_beacon,
3395 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003396 .add_station = ieee80211_add_station,
3397 .del_station = ieee80211_del_station,
3398 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003399 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003400 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003401 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003402#ifdef CONFIG_MAC80211_MESH
3403 .add_mpath = ieee80211_add_mpath,
3404 .del_mpath = ieee80211_del_mpath,
3405 .change_mpath = ieee80211_change_mpath,
3406 .get_mpath = ieee80211_get_mpath,
3407 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003408 .update_mesh_config = ieee80211_update_mesh_config,
3409 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003410 .join_mesh = ieee80211_join_mesh,
3411 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003412#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003413 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003414 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003415 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003416 .suspend = ieee80211_suspend,
3417 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003418 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003419 .sched_scan_start = ieee80211_sched_scan_start,
3420 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003421 .auth = ieee80211_auth,
3422 .assoc = ieee80211_assoc,
3423 .deauth = ieee80211_deauth,
3424 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003425 .join_ibss = ieee80211_join_ibss,
3426 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003427 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003428 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003429 .set_tx_power = ieee80211_set_tx_power,
3430 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003431 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003432 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003433 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003434 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003435 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003436 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003437 .remain_on_channel = ieee80211_remain_on_channel,
3438 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003439 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003440 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003441 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003442 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003443 .set_antenna = ieee80211_set_antenna,
3444 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003445 .set_ringparam = ieee80211_set_ringparam,
3446 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003447 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003448 .tdls_oper = ieee80211_tdls_oper,
3449 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003450 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003451 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003452#ifdef CONFIG_PM
3453 .set_wakeup = ieee80211_set_wakeup,
3454#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003455 .get_et_sset_count = ieee80211_get_et_sset_count,
3456 .get_et_stats = ieee80211_get_et_stats,
3457 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003458 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01003459 .start_radar_detection = ieee80211_start_radar_detection,
Jiri Bencf0706e82007-05-05 11:45:53 -07003460};