blob: d8b236633ca333b48a1922a9c0a1b873edb8202c [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg552bff02012-09-19 09:26:06 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
24 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020025 enum nl80211_iftype type,
26 u32 *flags,
27 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070028{
29 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020030 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010031 struct ieee80211_sub_if_data *sdata;
32 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg84efbb82012-06-16 00:00:26 +020034 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010035 if (err)
36 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010037
Johannes Bergf9e10ce2010-12-03 09:20:42 +010038 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020039 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 sdata->u.mntr_flags = *flags;
41 }
42
Johannes Berg84efbb82012-06-16 00:00:26 +020043 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070044}
45
Johannes Berg84efbb82012-06-16 00:00:26 +020046static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070047{
Johannes Berg84efbb82012-06-16 00:00:26 +020048 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Johannes Berg75636522008-07-09 14:40:35 +020050 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070051}
52
Johannes Berge36d56b2009-06-09 21:04:43 +020053static int ieee80211_change_iface(struct wiphy *wiphy,
54 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010055 enum nl80211_iftype type, u32 *flags,
56 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020057{
Johannes Berg9607e6b662009-12-23 13:15:31 +010058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020060
Johannes Berg05c914f2008-09-11 00:01:58 +020061 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020062 if (ret)
63 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020064
Johannes Berg9bc383d2009-11-19 11:55:19 +010065 if (type == NL80211_IFTYPE_AP_VLAN &&
66 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000067 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010068 else if (type == NL80211_IFTYPE_STATION &&
69 params && params->use_4addr >= 0)
70 sdata->u.mgd.use_4addr = params->use_4addr;
71
Christian Lamparter85416a42010-10-02 13:17:07 +020072 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
73 struct ieee80211_local *local = sdata->local;
74
75 if (ieee80211_sdata_running(sdata)) {
Felix Fietkau31eba5b2013-05-28 13:01:53 +020076 u32 mask = MONITOR_FLAG_COOK_FRAMES |
77 MONITOR_FLAG_ACTIVE;
78
Christian Lamparter85416a42010-10-02 13:17:07 +020079 /*
Felix Fietkau31eba5b2013-05-28 13:01:53 +020080 * Prohibit MONITOR_FLAG_COOK_FRAMES and
81 * MONITOR_FLAG_ACTIVE to be changed while the
82 * interface is up.
Christian Lamparter85416a42010-10-02 13:17:07 +020083 * Else we would need to add a lot of cruft
84 * to update everything:
85 * cooked_mntrs, monitor and all fif_* counters
86 * reconfigure hardware
87 */
Felix Fietkau31eba5b2013-05-28 13:01:53 +020088 if ((*flags & mask) != (sdata->u.mntr_flags & mask))
Christian Lamparter85416a42010-10-02 13:17:07 +020089 return -EBUSY;
90
91 ieee80211_adjust_monitor_flags(sdata, -1);
92 sdata->u.mntr_flags = *flags;
93 ieee80211_adjust_monitor_flags(sdata, 1);
94
95 ieee80211_configure_filter(local);
96 } else {
97 /*
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
101 */
102 sdata->u.mntr_flags = *flags;
103 }
104 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200105
Johannes Berg42613db2007-09-28 21:52:27 +0200106 return 0;
107}
108
Johannes Bergf142c6b2012-06-18 20:07:15 +0200109static int ieee80211_start_p2p_device(struct wiphy *wiphy,
110 struct wireless_dev *wdev)
111{
Luciano Coelhob6a55012014-02-27 11:07:21 +0200112 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
113 int ret;
114
115 mutex_lock(&sdata->local->chanctx_mtx);
116 ret = ieee80211_check_combinations(sdata, NULL, 0, 0);
117 mutex_unlock(&sdata->local->chanctx_mtx);
118 if (ret < 0)
119 return ret;
120
Johannes Bergf142c6b2012-06-18 20:07:15 +0200121 return ieee80211_do_open(wdev, true);
122}
123
124static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
125 struct wireless_dev *wdev)
126{
127 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
128}
129
Simon Wunderlichb53be792011-11-18 14:20:44 +0100130static int ieee80211_set_noack_map(struct wiphy *wiphy,
131 struct net_device *dev,
132 u16 noack_map)
133{
134 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
135
136 sdata->noack_map = noack_map;
137 return 0;
138}
139
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100140static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200141 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100142 struct key_params *params)
143{
Johannes Berg26a58452010-08-27 12:35:55 +0200144 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200145 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100146 struct sta_info *sta = NULL;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200147 const struct ieee80211_cipher_scheme *cs = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100148 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200149 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100150
Johannes Berg26a58452010-08-27 12:35:55 +0200151 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200152 return -ENETDOWN;
153
Johannes Berg97359d12010-08-10 09:46:38 +0200154 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100155 switch (params->cipher) {
156 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100157 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200158 case WLAN_CIPHER_SUITE_WEP104:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200159 if (IS_ERR(local->wep_tx_tfm))
Johannes Berg97359d12010-08-10 09:46:38 +0200160 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200161 break;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200162 case WLAN_CIPHER_SUITE_CCMP:
163 case WLAN_CIPHER_SUITE_AES_CMAC:
164 case WLAN_CIPHER_SUITE_GCMP:
165 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100166 default:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200167 cs = ieee80211_cs_get(local, params->cipher, sdata->vif.type);
Johannes Berg97359d12010-08-10 09:46:38 +0200168 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100169 }
170
Johannes Berg97359d12010-08-10 09:46:38 +0200171 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200172 params->key, params->seq_len, params->seq,
173 cs);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100174 if (IS_ERR(key))
175 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100176
Johannes Berge31b8212010-10-05 19:39:30 +0200177 if (pairwise)
178 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
179
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200180 mutex_lock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200181
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100182 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700183 if (ieee80211_vif_is_mesh(&sdata->vif))
184 sta = sta_info_get(sdata, mac_addr);
185 else
186 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg1626e0f2013-01-11 14:34:25 +0100187 /*
188 * The ASSOC test makes sure the driver is ready to
189 * receive the key. When wpa_supplicant has roamed
190 * using FT, it attempts to set the key before
191 * association has completed, this rejects that attempt
192 * so it will set the key again after assocation.
193 *
194 * TODO: accept the key if we have a station entry and
195 * add it to the device after the station.
196 */
197 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg79cf2df2013-03-06 22:53:52 +0100198 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200199 err = -ENOENT;
200 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100201 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100202 }
203
Johannes Berge548c492012-09-04 17:08:23 +0200204 switch (sdata->vif.type) {
205 case NL80211_IFTYPE_STATION:
206 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
207 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
208 break;
209 case NL80211_IFTYPE_AP:
210 case NL80211_IFTYPE_AP_VLAN:
211 /* Keys without a station are used for TX only */
212 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
213 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
214 break;
215 case NL80211_IFTYPE_ADHOC:
216 /* no MFP (yet) */
217 break;
218 case NL80211_IFTYPE_MESH_POINT:
219#ifdef CONFIG_MAC80211_MESH
220 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
221 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
222 break;
223#endif
224 case NL80211_IFTYPE_WDS:
225 case NL80211_IFTYPE_MONITOR:
226 case NL80211_IFTYPE_P2P_DEVICE:
227 case NL80211_IFTYPE_UNSPECIFIED:
228 case NUM_NL80211_IFTYPES:
229 case NL80211_IFTYPE_P2P_CLIENT:
230 case NL80211_IFTYPE_P2P_GO:
231 /* shouldn't happen */
232 WARN_ON_ONCE(1);
233 break;
234 }
235
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200236 if (sta)
237 sta->cipher_scheme = cs;
238
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300239 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100240
Johannes Berg3b967662008-04-08 17:56:52 +0200241 out_unlock:
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200242 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200243
244 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100245}
246
247static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200248 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100249{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200250 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
251 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100252 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200253 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100254 int ret;
255
Johannes Berg5c0c3642011-05-12 14:31:49 +0200256 mutex_lock(&local->sta_mtx);
257 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200258
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100259 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200260 ret = -ENOENT;
261
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100262 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100263 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200264 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100265
Johannes Berg5c0c3642011-05-12 14:31:49 +0200266 if (pairwise)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200267 key = key_mtx_dereference(local, sta->ptk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200268 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200269 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200270 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200271 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100272
Johannes Berg5c0c3642011-05-12 14:31:49 +0200273 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200274 ret = -ENOENT;
275 goto out_unlock;
276 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100277
Johannes Berg3b8d9c22013-03-06 22:58:23 +0100278 ieee80211_key_free(key, true);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100279
Johannes Berg3b967662008-04-08 17:56:52 +0200280 ret = 0;
281 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200282 mutex_unlock(&local->key_mtx);
283 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200284
285 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100286}
287
Johannes Berg62da92f2007-12-19 02:03:31 +0100288static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200289 u8 key_idx, bool pairwise, const u8 *mac_addr,
290 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100291 void (*callback)(void *cookie,
292 struct key_params *params))
293{
Johannes Berg14db74b2008-07-29 13:22:52 +0200294 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100295 struct sta_info *sta = NULL;
296 u8 seq[6] = {0};
297 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200298 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200299 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100300 u32 iv32;
301 u16 iv16;
302 int err = -ENOENT;
303
Johannes Berg14db74b2008-07-29 13:22:52 +0200304 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
305
Johannes Berg3b967662008-04-08 17:56:52 +0200306 rcu_read_lock();
307
Johannes Berg62da92f2007-12-19 02:03:31 +0100308 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100309 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100310 if (!sta)
311 goto out;
312
Max Stepanov354e1592013-12-08 13:30:52 +0200313 if (pairwise && key_idx < NUM_DEFAULT_KEYS)
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200314 key = rcu_dereference(sta->ptk[key_idx]);
Max Stepanov31f1f4e2013-12-08 13:31:29 +0200315 else if (!pairwise &&
316 key_idx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200317 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100318 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200319 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100320
321 if (!key)
322 goto out;
323
324 memset(&params, 0, sizeof(params));
325
Johannes Berg97359d12010-08-10 09:46:38 +0200326 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100327
Johannes Berg97359d12010-08-10 09:46:38 +0200328 switch (key->conf.cipher) {
329 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700330 iv32 = key->u.tkip.tx.iv32;
331 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100332
Johannes Berg24487982009-04-23 18:52:52 +0200333 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
334 drv_get_tkip_seq(sdata->local,
335 key->conf.hw_key_idx,
336 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100337
338 seq[0] = iv16 & 0xff;
339 seq[1] = (iv16 >> 8) & 0xff;
340 seq[2] = iv32 & 0xff;
341 seq[3] = (iv32 >> 8) & 0xff;
342 seq[4] = (iv32 >> 16) & 0xff;
343 seq[5] = (iv32 >> 24) & 0xff;
344 params.seq = seq;
345 params.seq_len = 6;
346 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200347 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200348 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
349 seq[0] = pn64;
350 seq[1] = pn64 >> 8;
351 seq[2] = pn64 >> 16;
352 seq[3] = pn64 >> 24;
353 seq[4] = pn64 >> 32;
354 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100355 params.seq = seq;
356 params.seq_len = 6;
357 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200358 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200359 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
360 seq[0] = pn64;
361 seq[1] = pn64 >> 8;
362 seq[2] = pn64 >> 16;
363 seq[3] = pn64 >> 24;
364 seq[4] = pn64 >> 32;
365 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200366 params.seq = seq;
367 params.seq_len = 6;
368 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100369 }
370
371 params.key = key->conf.key;
372 params.key_len = key->conf.keylen;
373
374 callback(cookie, &params);
375 err = 0;
376
377 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200378 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100379 return err;
380}
381
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100382static int ieee80211_config_default_key(struct wiphy *wiphy,
383 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100384 u8 key_idx, bool uni,
385 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100386{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200387 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100388
Johannes Bergf7e01042010-12-09 19:49:02 +0100389 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100390
391 return 0;
392}
393
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200394static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
395 struct net_device *dev,
396 u8 key_idx)
397{
Johannes Berg66c52422010-07-22 13:58:51 +0200398 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200399
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200400 ieee80211_set_default_mgmt_key(sdata, key_idx);
401
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200402 return 0;
403}
404
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800405void sta_set_rate_info_tx(struct sta_info *sta,
406 const struct ieee80211_tx_rate *rate,
407 struct rate_info *rinfo)
408{
409 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100410 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800411 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100412 rinfo->mcs = rate->idx;
413 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
414 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
415 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
416 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
417 } else {
418 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200419 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
420 u16 brate;
421
Johannes Berg8bc83c22012-11-09 18:38:32 +0100422 sband = sta->local->hw.wiphy->bands[
423 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200424 brate = sband->bitrates[rate->idx].bitrate;
425 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Johannes Berg8bc83c22012-11-09 18:38:32 +0100426 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800427 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
428 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100429 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
430 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
431 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
432 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800433 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
434 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800435}
436
Saravana003e6762012-11-28 18:29:38 +0530437void sta_set_rate_info_rx(struct sta_info *sta, struct rate_info *rinfo)
438{
439 rinfo->flags = 0;
440
441 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
442 rinfo->flags |= RATE_INFO_FLAGS_MCS;
443 rinfo->mcs = sta->last_rx_rate_idx;
444 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
445 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
446 rinfo->nss = sta->last_rx_rate_vht_nss;
447 rinfo->mcs = sta->last_rx_rate_idx;
448 } else {
449 struct ieee80211_supported_band *sband;
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200450 int shift = ieee80211_vif_get_shift(&sta->sdata->vif);
451 u16 brate;
Saravana003e6762012-11-28 18:29:38 +0530452
453 sband = sta->local->hw.wiphy->bands[
454 ieee80211_get_sdata_band(sta->sdata)];
Simon Wunderlich2103dec2013-07-08 16:55:53 +0200455 brate = sband->bitrates[sta->last_rx_rate_idx].bitrate;
456 rinfo->legacy = DIV_ROUND_UP(brate, 1 << shift);
Saravana003e6762012-11-28 18:29:38 +0530457 }
458
459 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
460 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
461 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
462 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200463 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530464 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200465 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_80P80MHZ)
Saravana003e6762012-11-28 18:29:38 +0530466 rinfo->flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
Emmanuel Grumbach1b8d2422014-02-05 16:37:11 +0200467 if (sta->last_rx_rate_vht_flag & RX_VHT_FLAG_160MHZ)
Saravana003e6762012-11-28 18:29:38 +0530468 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
469}
470
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100471static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
472{
Johannes Bergd0709a62008-02-25 16:27:46 +0100473 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300474 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530475 struct timespec uptime;
Johannes Berg560d2682013-02-05 10:55:21 +0100476 u64 packets = 0;
Felix Fietkauef0621e2013-04-22 16:29:31 +0200477 int i, ac;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100478
Johannes Bergf5ea9122009-08-07 16:17:38 +0200479 sinfo->generation = sdata->local->sta_generation;
480
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100481 sinfo->filled = STATION_INFO_INACTIVE_TIME |
Johannes Berg560d2682013-02-05 10:55:21 +0100482 STATION_INFO_RX_BYTES64 |
483 STATION_INFO_TX_BYTES64 |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200484 STATION_INFO_RX_PACKETS |
485 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900486 STATION_INFO_TX_RETRIES |
487 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700488 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100489 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700490 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530491 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200492 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800493 STATION_INFO_STA_FLAGS |
494 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530495
496 do_posix_clock_monotonic_gettime(&uptime);
497 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100498
499 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
Johannes Berg560d2682013-02-05 10:55:21 +0100500 sinfo->tx_bytes = 0;
501 for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
502 sinfo->tx_bytes += sta->tx_bytes[ac];
503 packets += sta->tx_packets[ac];
504 }
505 sinfo->tx_packets = packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100506 sinfo->rx_bytes = sta->rx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200507 sinfo->rx_packets = sta->rx_packets;
Bruno Randolfb206b4ef2010-10-06 18:34:12 +0900508 sinfo->tx_retries = sta->tx_retry_count;
509 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700510 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800511 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100512
John W. Linville19deffb2009-12-08 17:10:13 -0500513 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
514 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900515 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300516 if (!local->ops->get_rssi ||
517 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
518 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900519 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100520 }
Felix Fietkauef0621e2013-04-22 16:29:31 +0200521 if (sta->chains) {
522 sinfo->filled |= STATION_INFO_CHAIN_SIGNAL |
523 STATION_INFO_CHAIN_SIGNAL_AVG;
524
525 sinfo->chains = sta->chains;
526 for (i = 0; i < ARRAY_SIZE(sinfo->chain_signal); i++) {
527 sinfo->chain_signal[i] = sta->chain_signal_last[i];
528 sinfo->chain_signal_avg[i] =
529 (s8) -ewma_read(&sta->chain_signal_avg[i]);
530 }
531 }
Henning Rogge420e7fa2008-12-11 22:04:19 +0100532
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800533 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Saravana003e6762012-11-28 18:29:38 +0530534 sta_set_rate_info_rx(sta, &sinfo->rxrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100535
Johannes Berg902acc72008-02-23 15:17:19 +0100536 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100537#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100538 sinfo->filled |= STATION_INFO_LLID |
539 STATION_INFO_PLID |
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100540 STATION_INFO_PLINK_STATE |
541 STATION_INFO_LOCAL_PM |
542 STATION_INFO_PEER_PM |
543 STATION_INFO_NONPEER_PM;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100544
Chun-Yeow Yeoh6f101ef2013-11-13 15:43:03 +0800545 sinfo->llid = sta->llid;
546 sinfo->plid = sta->plid;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100547 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700548 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
549 sinfo->filled |= STATION_INFO_T_OFFSET;
550 sinfo->t_offset = sta->t_offset;
551 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +0100552 sinfo->local_pm = sta->local_pm;
553 sinfo->peer_pm = sta->peer_pm;
554 sinfo->nonpeer_pm = sta->nonpeer_pm;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100555#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100556 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700557
558 sinfo->bss_param.flags = 0;
559 if (sdata->vif.bss_conf.use_cts_prot)
560 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
561 if (sdata->vif.bss_conf.use_short_preamble)
562 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
563 if (sdata->vif.bss_conf.use_short_slot)
564 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
565 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
566 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200567
568 sinfo->sta_flags.set = 0;
569 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
570 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
571 BIT(NL80211_STA_FLAG_WME) |
572 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100573 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
Johannes Bergd582cff2012-10-26 17:53:44 +0200574 BIT(NL80211_STA_FLAG_ASSOCIATED) |
Helmut Schaae4121562011-11-05 14:15:24 +0100575 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200576 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
577 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
578 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
579 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
580 if (test_sta_flag(sta, WLAN_STA_WME))
581 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
582 if (test_sta_flag(sta, WLAN_STA_MFP))
583 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
584 if (test_sta_flag(sta, WLAN_STA_AUTH))
585 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Johannes Bergd582cff2012-10-26 17:53:44 +0200586 if (test_sta_flag(sta, WLAN_STA_ASSOC))
587 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100588 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
589 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100590}
591
Ben Greearb1ab7922012-04-23 12:50:30 -0700592static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
593 "rx_packets", "rx_bytes", "wep_weak_iv_count",
594 "rx_duplicates", "rx_fragments", "rx_dropped",
595 "tx_packets", "tx_bytes", "tx_fragments",
596 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700597 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
598 "channel", "noise", "ch_time", "ch_time_busy",
599 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700600};
601#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
602
603static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
604 struct net_device *dev,
605 int sset)
606{
Ben Greeare3521142012-04-23 12:50:31 -0700607 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
608 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700609
Ben Greeare3521142012-04-23 12:50:31 -0700610 if (sset == ETH_SS_STATS)
611 rv += STA_STATS_LEN;
612
613 rv += drv_get_et_sset_count(sdata, sset);
614
615 if (rv == 0)
616 return -EOPNOTSUPP;
617 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700618}
619
620static void ieee80211_get_et_stats(struct wiphy *wiphy,
621 struct net_device *dev,
622 struct ethtool_stats *stats,
623 u64 *data)
624{
625 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200626 struct ieee80211_chanctx_conf *chanctx_conf;
627 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700628 struct sta_info *sta;
629 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700630 struct station_info sinfo;
631 struct survey_info survey;
632 int i, q;
633#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700634
635 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
636
637#define ADD_STA_STATS(sta) \
638 do { \
639 data[i++] += sta->rx_packets; \
640 data[i++] += sta->rx_bytes; \
641 data[i++] += sta->wep_weak_iv_count; \
642 data[i++] += sta->num_duplicates; \
643 data[i++] += sta->rx_fragments; \
644 data[i++] += sta->rx_dropped; \
645 \
Johannes Berg560d2682013-02-05 10:55:21 +0100646 data[i++] += sinfo.tx_packets; \
647 data[i++] += sinfo.tx_bytes; \
Ben Greearb1ab7922012-04-23 12:50:30 -0700648 data[i++] += sta->tx_fragments; \
649 data[i++] += sta->tx_filtered_count; \
650 data[i++] += sta->tx_retry_failed; \
651 data[i++] += sta->tx_retry_count; \
652 data[i++] += sta->beacon_loss_count; \
653 } while (0)
654
655 /* For Managed stations, find the single station based on BSSID
656 * and use that. For interface types, iterate through all available
657 * stations and add stats for any station that is assigned to this
658 * network device.
659 */
660
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300661 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700662
663 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
664 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700665
666 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
667 goto do_survey;
668
Johannes Berg560d2682013-02-05 10:55:21 +0100669 sinfo.filled = 0;
670 sta_set_sinfo(sta, &sinfo);
671
Ben Greear3073a7c2012-04-23 12:50:32 -0700672 i = 0;
673 ADD_STA_STATS(sta);
674
675 data[i++] = sta->sta_state;
676
Ben Greear3073a7c2012-04-23 12:50:32 -0700677
Joe Perches52042672012-05-30 13:25:54 -0700678 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700679 data[i] = 100000 *
680 cfg80211_calculate_bitrate(&sinfo.txrate);
681 i++;
Joe Perches52042672012-05-30 13:25:54 -0700682 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700683 data[i] = 100000 *
684 cfg80211_calculate_bitrate(&sinfo.rxrate);
685 i++;
686
Joe Perches52042672012-05-30 13:25:54 -0700687 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700688 data[i] = (u8)sinfo.signal_avg;
689 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700690 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300691 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700692 /* Make sure this station belongs to the proper dev */
693 if (sta->sdata->dev != dev)
694 continue;
695
Johannes Berge13bae42013-07-08 10:43:31 +0200696 sinfo.filled = 0;
697 sta_set_sinfo(sta, &sinfo);
Ben Greearb1ab7922012-04-23 12:50:30 -0700698 i = 0;
699 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700700 }
701 }
702
Ben Greear3073a7c2012-04-23 12:50:32 -0700703do_survey:
704 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
705 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200706 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700707
Johannes Berg55de9082012-07-26 17:24:39 +0200708 rcu_read_lock();
709 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
710 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100711 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200712 else
713 channel = NULL;
714 rcu_read_unlock();
715
716 if (channel) {
717 q = 0;
718 do {
719 survey.filled = 0;
720 if (drv_get_survey(local, q, &survey) != 0) {
721 survey.filled = 0;
722 break;
723 }
724 q++;
725 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700726 }
727
728 if (survey.filled)
729 data[i++] = survey.channel->center_freq;
730 else
731 data[i++] = 0;
732 if (survey.filled & SURVEY_INFO_NOISE_DBM)
733 data[i++] = (u8)survey.noise;
734 else
735 data[i++] = -1LL;
736 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
737 data[i++] = survey.channel_time;
738 else
739 data[i++] = -1LL;
740 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
741 data[i++] = survey.channel_time_busy;
742 else
743 data[i++] = -1LL;
744 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
745 data[i++] = survey.channel_time_ext_busy;
746 else
747 data[i++] = -1LL;
748 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
749 data[i++] = survey.channel_time_rx;
750 else
751 data[i++] = -1LL;
752 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
753 data[i++] = survey.channel_time_tx;
754 else
755 data[i++] = -1LL;
756
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300757 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700758
Ben Greear3073a7c2012-04-23 12:50:32 -0700759 if (WARN_ON(i != STA_STATS_LEN))
760 return;
761
Ben Greeare3521142012-04-23 12:50:31 -0700762 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700763}
764
765static void ieee80211_get_et_strings(struct wiphy *wiphy,
766 struct net_device *dev,
767 u32 sset, u8 *data)
768{
Ben Greeare3521142012-04-23 12:50:31 -0700769 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
770 int sz_sta_stats = 0;
771
Ben Greearb1ab7922012-04-23 12:50:30 -0700772 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700773 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Johannes Bergbd500af2013-05-06 21:09:46 +0200774 memcpy(data, ieee80211_gstrings_sta_stats, sz_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700775 }
Ben Greeare3521142012-04-23 12:50:31 -0700776 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700777}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100778
779static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
780 int idx, u8 *mac, struct station_info *sinfo)
781{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100782 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300783 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100784 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100785 int ret = -ENOENT;
786
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300787 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100788
Johannes Berg3b53fde82009-11-16 12:00:37 +0100789 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100790 if (sta) {
791 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200792 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100793 sta_set_sinfo(sta, sinfo);
794 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100795
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300796 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100797
Johannes Bergd0709a62008-02-25 16:27:46 +0100798 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100799}
800
Holger Schurig12897232010-04-19 10:23:57 +0200801static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
802 int idx, struct survey_info *survey)
803{
804 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
805
Holger Schurig12897232010-04-19 10:23:57 +0200806 return drv_get_survey(local, idx, survey);
807}
808
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100809static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100810 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100811{
Johannes Bergabe60632009-11-25 17:46:18 +0100812 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300813 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100814 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100815 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100816
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300817 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100818
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100819 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100820 if (sta) {
821 ret = 0;
822 sta_set_sinfo(sta, sinfo);
823 }
824
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300825 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100826
827 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100828}
829
Johannes Berge8c9bd52012-06-06 08:18:22 +0200830static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100831 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200832{
Johannes Berg55de9082012-07-26 17:24:39 +0200833 struct ieee80211_local *local = wiphy_priv(wiphy);
834 struct ieee80211_sub_if_data *sdata;
835 int ret = 0;
836
Johannes Berg4bf88532012-11-09 11:39:59 +0100837 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200838 return 0;
839
Johannes Berg34a37402013-12-18 09:43:33 +0100840 mutex_lock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200841 mutex_lock(&local->iflist_mtx);
842 if (local->use_chanctx) {
843 sdata = rcu_dereference_protected(
844 local->monitor_sdata,
845 lockdep_is_held(&local->iflist_mtx));
846 if (sdata) {
847 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100848 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200849 IEEE80211_CHANCTX_EXCLUSIVE);
850 }
851 } else if (local->open_count == local->monitors) {
Karl Beldan675a0b02013-03-25 16:26:57 +0100852 local->_oper_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200853 ieee80211_hw_config(local, 0);
854 }
855
Johannes Berg4bf88532012-11-09 11:39:59 +0100856 if (ret == 0)
857 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200858 mutex_unlock(&local->iflist_mtx);
Johannes Berg34a37402013-12-18 09:43:33 +0100859 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +0200860
861 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200862}
863
Arik Nemtsov02945822011-11-10 11:28:57 +0200864static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100865 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200866{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300867 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200868
869 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530870 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200871
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100872 old = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Arik Nemtsov02945822011-11-10 11:28:57 +0200873
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300874 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200875 if (!new)
876 return -ENOMEM;
877
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300878 new->len = resp_len;
879 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200880
881 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300882 if (old)
883 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200884
885 return 0;
886}
887
Luciano Coelho0ae07962013-12-08 09:42:25 +0200888static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
889 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100890{
891 struct beacon_data *new, *old;
892 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100893 int size, err;
894 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100895
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100896 old = sdata_dereference(sdata->u.ap.beacon, sdata);
897
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100898
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100899 /* Need to have a beacon head if we don't have one yet */
900 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100901 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100902
903 /* new or old head? */
904 if (params->head)
905 new_head_len = params->head_len;
906 else
907 new_head_len = old->head_len;
908
909 /* new or old tail? */
910 if (params->tail || !old)
911 /* params->tail_len will be zero for !params->tail */
912 new_tail_len = params->tail_len;
913 else
914 new_tail_len = old->tail_len;
915
916 size = sizeof(*new) + new_head_len + new_tail_len;
917
918 new = kzalloc(size, GFP_KERNEL);
919 if (!new)
920 return -ENOMEM;
921
922 /* start filling the new info now */
923
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100924 /*
925 * pointers go into the block we allocated,
926 * memory is | beacon_data | head | tail |
927 */
928 new->head = ((u8 *) new) + sizeof(*new);
929 new->tail = new->head + new_head_len;
930 new->head_len = new_head_len;
931 new->tail_len = new_tail_len;
932
933 /* copy in head */
934 if (params->head)
935 memcpy(new->head, params->head, new_head_len);
936 else
937 memcpy(new->head, old->head, new_head_len);
938
939 /* copy in optional tail */
940 if (params->tail)
941 memcpy(new->tail, params->tail, new_tail_len);
942 else
943 if (old)
944 memcpy(new->tail, old->tail, new_tail_len);
945
Johannes Berg88600202012-02-13 15:17:18 +0100946 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
947 params->probe_resp_len);
948 if (err < 0)
949 return err;
950 if (err == 0)
951 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100952
Eric Dumazetcf778b02012-01-12 04:41:32 +0000953 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100954
Johannes Berg88600202012-02-13 15:17:18 +0100955 if (old)
956 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100957
Johannes Berg88600202012-02-13 15:17:18 +0100958 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100959}
960
Johannes Berg88600202012-02-13 15:17:18 +0100961static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
962 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100963{
Johannes Berg88600202012-02-13 15:17:18 +0100964 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg34a37402013-12-18 09:43:33 +0100965 struct ieee80211_local *local = sdata->local;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100966 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100967 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100968 u32 changed = BSS_CHANGED_BEACON_INT |
969 BSS_CHANGED_BEACON_ENABLED |
970 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100971 BSS_CHANGED_SSID |
972 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100973 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200974
Simon Wunderlich7ca133b2013-11-21 18:19:50 +0100975 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100976 if (old)
977 return -EALREADY;
978
Johannes Berg04ecd252012-09-11 14:34:12 +0200979 /* TODO: make hostapd tell us what it wants */
980 sdata->smps_mode = IEEE80211_SMPS_OFF;
981 sdata->needed_rx_chains = sdata->local->rx_chains;
982
Johannes Berg34a37402013-12-18 09:43:33 +0100983 mutex_lock(&local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +0100984 err = ieee80211_vif_use_channel(sdata, &params->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200985 IEEE80211_CHANCTX_SHARED);
Michal Kazior4e141da2014-03-05 13:14:08 +0100986 if (!err)
987 ieee80211_vif_copy_chanctx_to_vlans(sdata, false);
Johannes Berg34a37402013-12-18 09:43:33 +0100988 mutex_unlock(&local->mtx);
Johannes Bergaa430da2012-05-16 23:50:18 +0200989 if (err)
990 return err;
991
Johannes Berg665c93a2011-11-04 11:18:11 +0100992 /*
993 * Apply control port protocol, this allows us to
994 * not encrypt dynamic WEP control frames.
995 */
996 sdata->control_port_protocol = params->crypto.control_port_ethertype;
997 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +0200998 sdata->encrypt_headroom = ieee80211_cs_headroom(sdata->local,
999 &params->crypto,
1000 sdata->vif.type);
1001
Johannes Berg665c93a2011-11-04 11:18:11 +01001002 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
1003 vlan->control_port_protocol =
1004 params->crypto.control_port_ethertype;
1005 vlan->control_port_no_encrypt =
1006 params->crypto.control_port_no_encrypt;
Max Stepanov2475b1cc2013-03-24 14:23:27 +02001007 vlan->encrypt_headroom =
1008 ieee80211_cs_headroom(sdata->local,
1009 &params->crypto,
1010 vlan->vif.type);
Johannes Berg665c93a2011-11-04 11:18:11 +01001011 }
1012
Johannes Berg88600202012-02-13 15:17:18 +01001013 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
1014 sdata->vif.bss_conf.dtim_period = params->dtim_period;
Johannes Bergd6a83222012-12-14 14:06:28 +01001015 sdata->vif.bss_conf.enable_beacon = true;
Johannes Berg88600202012-02-13 15:17:18 +01001016
1017 sdata->vif.bss_conf.ssid_len = params->ssid_len;
1018 if (params->ssid_len)
1019 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
1020 params->ssid_len);
1021 sdata->vif.bss_conf.hidden_ssid =
1022 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
1023
Janusz Dziedzic67baf662013-03-21 15:47:56 +01001024 memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
1025 sizeof(sdata->vif.bss_conf.p2p_noa_attr));
1026 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow =
1027 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
1028 if (params->p2p_opp_ps)
1029 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
1030 IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01001031
Johannes Berg88600202012-02-13 15:17:18 +01001032 err = ieee80211_assign_beacon(sdata, &params->beacon);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001033 if (err < 0) {
1034 ieee80211_vif_release_channel(sdata);
Johannes Berg88600202012-02-13 15:17:18 +01001035 return err;
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001036 }
Johannes Berg88600202012-02-13 15:17:18 +01001037 changed |= err;
1038
Johannes Berg10416382012-10-19 15:44:42 +02001039 err = drv_start_ap(sdata->local, sdata);
1040 if (err) {
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001041 old = sdata_dereference(sdata->u.ap.beacon, sdata);
1042
Johannes Berg10416382012-10-19 15:44:42 +02001043 if (old)
1044 kfree_rcu(old, rcu_head);
1045 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Emmanuel Grumbach0297ea12014-01-27 11:07:42 +02001046 ieee80211_vif_release_channel(sdata);
Johannes Berg10416382012-10-19 15:44:42 +02001047 return err;
1048 }
1049
Thomas Pedersen057d5f42013-12-19 10:25:15 -08001050 ieee80211_recalc_dtim(local, sdata);
Johannes Berg88600202012-02-13 15:17:18 +01001051 ieee80211_bss_info_change_notify(sdata, changed);
1052
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001053 netif_carrier_on(dev);
1054 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1055 netif_carrier_on(vlan->dev);
1056
Johannes Berg665c93a2011-11-04 11:18:11 +01001057 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001058}
1059
Johannes Berg88600202012-02-13 15:17:18 +01001060static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
1061 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001062{
Johannes Berg14db74b2008-07-29 13:22:52 +02001063 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001064 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +01001065 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001066
Johannes Berg14db74b2008-07-29 13:22:52 +02001067 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Michal Kaziordbd72852014-01-29 07:56:21 +01001068 sdata_assert_lock(sdata);
Johannes Berg14db74b2008-07-29 13:22:52 +02001069
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001070 /* don't allow changing the beacon while CSA is in place - offset
1071 * of channel switch counter may change
1072 */
1073 if (sdata->vif.csa_active)
1074 return -EBUSY;
1075
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001076 old = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001077 if (!old)
1078 return -ENOENT;
1079
Johannes Berg88600202012-02-13 15:17:18 +01001080 err = ieee80211_assign_beacon(sdata, params);
1081 if (err < 0)
1082 return err;
1083 ieee80211_bss_info_change_notify(sdata, err);
1084 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001085}
1086
Johannes Berg88600202012-02-13 15:17:18 +01001087static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001088{
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001089 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1090 struct ieee80211_sub_if_data *vlan;
1091 struct ieee80211_local *local = sdata->local;
1092 struct beacon_data *old_beacon;
1093 struct probe_resp *old_probe_resp;
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001094 struct cfg80211_chan_def chandef;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001095
Michal Kaziordbd72852014-01-29 07:56:21 +01001096 sdata_assert_lock(sdata);
1097
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001098 old_beacon = sdata_dereference(sdata->u.ap.beacon, sdata);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001099 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001100 return -ENOENT;
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01001101 old_probe_resp = sdata_dereference(sdata->u.ap.probe_resp, sdata);
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001102
Simon Wunderlich73da7d52013-07-11 16:09:06 +02001103 /* abort any running channel switch */
1104 sdata->vif.csa_active = false;
Simon Wunderlich1f3b8a22013-11-21 18:19:53 +01001105 kfree(sdata->u.ap.next_beacon);
1106 sdata->u.ap.next_beacon = NULL;
1107
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001108 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +02001109 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
1110 netif_carrier_off(vlan->dev);
1111 netif_carrier_off(dev);
1112
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001113 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001114 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001115 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1116 kfree_rcu(old_beacon, rcu_head);
1117 if (old_probe_resp)
1118 kfree_rcu(old_probe_resp, rcu_head);
Emmanuel Grumbach8ffcc702014-01-23 14:28:16 +02001119 sdata->u.ap.driver_smps_mode = IEEE80211_SMPS_OFF;
Johannes Berg88600202012-02-13 15:17:18 +01001120
Johannes Berge7162512013-12-04 23:18:37 +01001121 __sta_info_flush(sdata, true);
Johannes Berg7907c7d2013-12-04 23:47:09 +01001122 ieee80211_free_keys(sdata, true);
Johannes Berg75de9112012-12-14 14:56:03 +01001123
Johannes Bergd6a83222012-12-14 14:06:28 +01001124 sdata->vif.bss_conf.enable_beacon = false;
Marek Puzyniak0eabccd2013-04-10 13:47:45 +02001125 sdata->vif.bss_conf.ssid_len = 0;
Johannes Bergd6a83222012-12-14 14:06:28 +01001126 clear_bit(SDATA_STATE_OFFCHANNEL_BEACON_STOPPED, &sdata->state);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001127 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001128
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001129 if (sdata->wdev.cac_started) {
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001130 chandef = sdata->vif.bss_conf.chandef;
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001131 cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
Janusz Dziedzicd2859df2013-11-06 13:55:51 +01001132 cfg80211_cac_event(sdata->dev, &chandef,
1133 NL80211_RADAR_CAC_ABORTED,
Simon Wunderlicha6b368f2013-06-11 10:44:39 +02001134 GFP_KERNEL);
1135 }
1136
Johannes Berg10416382012-10-19 15:44:42 +02001137 drv_stop_ap(sdata->local, sdata);
1138
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001139 /* free all potentially still buffered bcast frames */
1140 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1141 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1142
Johannes Berg34a37402013-12-18 09:43:33 +01001143 mutex_lock(&local->mtx);
Michal Kazior4e141da2014-03-05 13:14:08 +01001144 ieee80211_vif_copy_chanctx_to_vlans(sdata, true);
Johannes Berg55de9082012-07-26 17:24:39 +02001145 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001146 mutex_unlock(&local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001147
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001148 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001149}
1150
Johannes Berg4fd69312007-12-19 02:03:35 +01001151/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1152struct iapp_layer2_update {
1153 u8 da[ETH_ALEN]; /* broadcast */
1154 u8 sa[ETH_ALEN]; /* STA addr */
1155 __be16 len; /* 6 */
1156 u8 dsap; /* 0 */
1157 u8 ssap; /* 0 */
1158 u8 control;
1159 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001160} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001161
1162static void ieee80211_send_layer2_update(struct sta_info *sta)
1163{
1164 struct iapp_layer2_update *msg;
1165 struct sk_buff *skb;
1166
1167 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1168 * bridge devices */
1169
1170 skb = dev_alloc_skb(sizeof(*msg));
1171 if (!skb)
1172 return;
1173 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1174
1175 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1176 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1177
Johannes Berge83e6542012-07-13 16:23:07 +02001178 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001179 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001180 msg->len = htons(6);
1181 msg->dsap = 0;
1182 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1183 msg->control = 0xaf; /* XID response lsb.1111F101.
1184 * F=0 (no poll command; unsolicited frame) */
1185 msg->xid_info[0] = 0x81; /* XID format identifier */
1186 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1187 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1188
Johannes Bergd0709a62008-02-25 16:27:46 +01001189 skb->dev = sta->sdata->dev;
1190 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001191 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001192 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001193}
1194
Johannes Bergd582cff2012-10-26 17:53:44 +02001195static int sta_apply_auth_flags(struct ieee80211_local *local,
1196 struct sta_info *sta,
1197 u32 mask, u32 set)
1198{
1199 int ret;
1200
1201 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1202 set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1203 !test_sta_flag(sta, WLAN_STA_AUTH)) {
1204 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1205 if (ret)
1206 return ret;
1207 }
1208
1209 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1210 set & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1211 !test_sta_flag(sta, WLAN_STA_ASSOC)) {
1212 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1213 if (ret)
1214 return ret;
1215 }
1216
1217 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1218 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
1219 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
1220 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1221 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
1222 else
1223 ret = 0;
1224 if (ret)
1225 return ret;
1226 }
1227
1228 if (mask & BIT(NL80211_STA_FLAG_ASSOCIATED) &&
1229 !(set & BIT(NL80211_STA_FLAG_ASSOCIATED)) &&
1230 test_sta_flag(sta, WLAN_STA_ASSOC)) {
1231 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
1232 if (ret)
1233 return ret;
1234 }
1235
1236 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1237 !(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1238 test_sta_flag(sta, WLAN_STA_AUTH)) {
1239 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
1240 if (ret)
1241 return ret;
1242 }
1243
1244 return 0;
1245}
1246
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001247static int sta_apply_parameters(struct ieee80211_local *local,
1248 struct sta_info *sta,
1249 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001250{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001251 int ret = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001252 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001253 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001254 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001255 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001256
Johannes Berg55de9082012-07-26 17:24:39 +02001257 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001258
Johannes Bergeccb8e82009-05-11 21:57:56 +03001259 mask = params->sta_flags_mask;
1260 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001261
Johannes Bergd582cff2012-10-26 17:53:44 +02001262 if (ieee80211_vif_is_mesh(&sdata->vif)) {
1263 /*
1264 * In mesh mode, ASSOCIATED isn't part of the nl80211
1265 * API but must follow AUTHENTICATED for driver state.
1266 */
1267 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1268 mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
1269 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
1270 set |= BIT(NL80211_STA_FLAG_ASSOCIATED);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001271 } else if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1272 /*
1273 * TDLS -- everything follows authorized, but
1274 * only becoming authorized is possible, not
1275 * going back
1276 */
1277 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
1278 set |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1279 BIT(NL80211_STA_FLAG_ASSOCIATED);
1280 mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED) |
1281 BIT(NL80211_STA_FLAG_ASSOCIATED);
1282 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001283 }
1284
Johannes Bergd582cff2012-10-26 17:53:44 +02001285 ret = sta_apply_auth_flags(local, sta, mask, set);
1286 if (ret)
1287 return ret;
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001288
Johannes Bergeccb8e82009-05-11 21:57:56 +03001289 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001290 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001291 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1292 else
1293 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001294 }
1295
1296 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001297 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001298 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001299 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001300 } else {
1301 clear_sta_flag(sta, WLAN_STA_WME);
1302 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001303 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001304 }
1305
1306 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001307 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001308 set_sta_flag(sta, WLAN_STA_MFP);
1309 else
1310 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001311 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001312
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001313 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001314 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001315 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1316 else
1317 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001318 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001319
Johannes Berg3b9ce802011-09-27 20:56:12 +02001320 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1321 sta->sta.uapsd_queues = params->uapsd_queues;
1322 sta->sta.max_sp = params->max_sp;
1323 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001324
Johannes Berg73651ee2008-02-25 16:27:47 +01001325 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001326 * cfg80211 validates this (1-2007) and allows setting the AID
1327 * only when creating a new station entry
1328 */
1329 if (params->aid)
1330 sta->sta.aid = params->aid;
1331
1332 /*
Johannes Bergba23d202012-12-27 17:32:09 +01001333 * Some of the following updates would be racy if called on an
1334 * existing station, via ieee80211_change_station(). However,
1335 * all such changes are rejected by cfg80211 except for updates
1336 * changing the supported rates on an existing but not yet used
1337 * TDLS peer.
Johannes Berg73651ee2008-02-25 16:27:47 +01001338 */
1339
Johannes Berg4fd69312007-12-19 02:03:35 +01001340 if (params->listen_interval >= 0)
1341 sta->listen_interval = params->listen_interval;
1342
1343 if (params->supported_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02001344 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
1345 sband, params->supported_rates,
1346 params->supported_rates_len,
1347 &sta->sta.supp_rates[band]);
Johannes Berg4fd69312007-12-19 02:03:35 +01001348 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001349
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001350 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001351 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Berge1a0c6b2013-02-07 11:47:44 +01001352 params->ht_capa, sta);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001353
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001354 if (params->vht_capa)
1355 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
Johannes Berg4a342152013-02-07 11:58:58 +01001356 params->vht_capa, sta);
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001357
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001358 if (params->opmode_notif_used) {
Marek Kwaczynskib1bce14a2014-02-03 14:44:44 +01001359 /* returned value is only needed for rc update, but the
1360 * rc isn't initialized here yet, so ignore it
1361 */
1362 __ieee80211_vht_handle_opmode(sdata, sta,
1363 params->opmode_notif,
1364 band, false);
1365 }
1366
Javier Cardona9c3990a2011-05-03 16:57:11 -07001367 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001368#ifdef CONFIG_MAC80211_MESH
Thomas Pedersen39886b62013-02-13 12:14:19 -08001369 u32 changed = 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001370
1371 if (params->sta_modify_mask & STATION_PARAM_APPLY_PLINK_STATE) {
Javier Cardona9c3990a2011-05-03 16:57:11 -07001372 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001373 case NL80211_PLINK_ESTAB:
Marco Porsch1617bab2013-01-07 16:04:49 +01001374 if (sta->plink_state != NL80211_PLINK_ESTAB)
1375 changed = mesh_plink_inc_estab_count(
1376 sdata);
1377 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001378
1379 ieee80211_mps_sta_status_update(sta);
Thomas Pedersen39886b62013-02-13 12:14:19 -08001380 changed |= ieee80211_mps_set_sta_local_pm(sta,
1381 sdata->u.mesh.mshcfg.power_mode);
Marco Porsch1617bab2013-01-07 16:04:49 +01001382 break;
1383 case NL80211_PLINK_LISTEN:
Javier Cardona57cf8042011-05-13 10:45:43 -07001384 case NL80211_PLINK_BLOCKED:
Marco Porsch1617bab2013-01-07 16:04:49 +01001385 case NL80211_PLINK_OPN_SNT:
1386 case NL80211_PLINK_OPN_RCVD:
1387 case NL80211_PLINK_CNF_RCVD:
1388 case NL80211_PLINK_HOLDING:
1389 if (sta->plink_state == NL80211_PLINK_ESTAB)
1390 changed = mesh_plink_dec_estab_count(
1391 sdata);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001392 sta->plink_state = params->plink_state;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001393
1394 ieee80211_mps_sta_status_update(sta);
Marco Porsch446075d2013-10-15 12:29:24 +02001395 changed |= ieee80211_mps_set_sta_local_pm(sta,
1396 NL80211_MESH_POWER_UNKNOWN);
Javier Cardona9c3990a2011-05-03 16:57:11 -07001397 break;
1398 default:
1399 /* nothing */
1400 break;
1401 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001402 }
1403
1404 switch (params->plink_action) {
1405 case NL80211_PLINK_ACTION_NO_ACTION:
1406 /* nothing */
1407 break;
1408 case NL80211_PLINK_ACTION_OPEN:
1409 changed |= mesh_plink_open(sta);
1410 break;
1411 case NL80211_PLINK_ACTION_BLOCK:
1412 changed |= mesh_plink_block(sta);
1413 break;
Marco Porsch1617bab2013-01-07 16:04:49 +01001414 }
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001415
1416 if (params->local_pm)
Thomas Pedersen39886b62013-02-13 12:14:19 -08001417 changed |=
1418 ieee80211_mps_set_sta_local_pm(sta,
1419 params->local_pm);
Javier Lopez6c751ef2013-11-06 10:04:29 -08001420 ieee80211_mbss_info_change_notify(sdata, changed);
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001421#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001422 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001423
1424 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001425}
1426
1427static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1428 u8 *mac, struct station_parameters *params)
1429{
Johannes Berg14db74b2008-07-29 13:22:52 +02001430 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001431 struct sta_info *sta;
1432 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001433 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001434 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001435
Johannes Berg4fd69312007-12-19 02:03:35 +01001436 if (params->vlan) {
1437 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1438
Johannes Berg05c914f2008-09-11 00:01:58 +02001439 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1440 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001441 return -EINVAL;
1442 } else
1443 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1444
Joe Perchesb203ca32012-05-08 18:56:52 +00001445 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001446 return -EINVAL;
1447
1448 if (is_multicast_ether_addr(mac))
1449 return -EINVAL;
1450
1451 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001452 if (!sta)
1453 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001454
Johannes Bergd582cff2012-10-26 17:53:44 +02001455 /*
1456 * defaults -- if userspace wants something else we'll
1457 * change it accordingly in sta_apply_parameters()
1458 */
Johannes Berg77ee7c82013-02-15 00:48:33 +01001459 if (!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER))) {
1460 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1461 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Arik Nemtsov0c4972c2014-05-01 10:17:27 +03001462 } else {
1463 sta->sta.tdls = true;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001464 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001465
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001466 err = sta_apply_parameters(local, sta, params);
1467 if (err) {
1468 sta_info_free(local, sta);
1469 return err;
1470 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001471
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001472 /*
Johannes Berg77ee7c82013-02-15 00:48:33 +01001473 * for TDLS, rate control should be initialized only when
1474 * rates are known and station is marked authorized
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001475 */
1476 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1477 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001478
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001479 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1480 sdata->vif.type == NL80211_IFTYPE_AP;
1481
Johannes Berg34e89502010-02-03 13:59:58 +01001482 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001483 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001484 rcu_read_unlock();
1485 return err;
1486 }
1487
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001488 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001489 ieee80211_send_layer2_update(sta);
1490
1491 rcu_read_unlock();
1492
Johannes Berg4fd69312007-12-19 02:03:35 +01001493 return 0;
1494}
1495
1496static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1497 u8 *mac)
1498{
Johannes Berg14db74b2008-07-29 13:22:52 +02001499 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001500
Johannes Berg14db74b2008-07-29 13:22:52 +02001501 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1502
Johannes Berg34e89502010-02-03 13:59:58 +01001503 if (mac)
1504 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001505
Johannes Bergb998e8b2012-12-13 23:07:46 +01001506 sta_info_flush(sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001507 return 0;
1508}
1509
1510static int ieee80211_change_station(struct wiphy *wiphy,
Johannes Berg77ee7c82013-02-15 00:48:33 +01001511 struct net_device *dev, u8 *mac,
Johannes Berg4fd69312007-12-19 02:03:35 +01001512 struct station_parameters *params)
1513{
Johannes Bergabe60632009-11-25 17:46:18 +01001514 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001515 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001516 struct sta_info *sta;
1517 struct ieee80211_sub_if_data *vlansdata;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001518 enum cfg80211_station_type statype;
Eliad Peller35b88622011-12-29 14:41:39 +02001519 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001520
Johannes Berg87be1e12011-12-14 12:20:29 +01001521 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001522
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001523 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001524 if (!sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001525 err = -ENOENT;
1526 goto out_err;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001527 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001528
Johannes Berg77ee7c82013-02-15 00:48:33 +01001529 switch (sdata->vif.type) {
1530 case NL80211_IFTYPE_MESH_POINT:
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001531 if (sdata->u.mesh.user_mpm)
Thomas Pederseneef941e2013-03-04 13:06:11 -08001532 statype = CFG80211_STA_MESH_PEER_USER;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001533 else
Thomas Pederseneef941e2013-03-04 13:06:11 -08001534 statype = CFG80211_STA_MESH_PEER_KERNEL;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001535 break;
1536 case NL80211_IFTYPE_ADHOC:
1537 statype = CFG80211_STA_IBSS;
1538 break;
1539 case NL80211_IFTYPE_STATION:
1540 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
1541 statype = CFG80211_STA_AP_STA;
1542 break;
1543 }
1544 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
1545 statype = CFG80211_STA_TDLS_PEER_ACTIVE;
1546 else
1547 statype = CFG80211_STA_TDLS_PEER_SETUP;
1548 break;
1549 case NL80211_IFTYPE_AP:
1550 case NL80211_IFTYPE_AP_VLAN:
1551 statype = CFG80211_STA_AP_CLIENT;
1552 break;
1553 default:
1554 err = -EOPNOTSUPP;
1555 goto out_err;
Johannes Bergbdd90d52011-12-14 12:20:27 +01001556 }
1557
Johannes Berg77ee7c82013-02-15 00:48:33 +01001558 err = cfg80211_check_station_change(wiphy, params, statype);
1559 if (err)
1560 goto out_err;
1561
Johannes Bergd0709a62008-02-25 16:27:46 +01001562 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001563 bool prev_4addr = false;
1564 bool new_4addr = false;
1565
Johannes Berg4fd69312007-12-19 02:03:35 +01001566 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1567
Johannes Berg9bc383d2009-11-19 11:55:19 +01001568 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001569 if (vlansdata->u.vlan.sta) {
Johannes Berg77ee7c82013-02-15 00:48:33 +01001570 err = -EBUSY;
1571 goto out_err;
Johannes Berg33054432009-11-20 10:09:14 +01001572 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001573
Eric Dumazetcf778b02012-01-12 04:41:32 +00001574 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001575 new_4addr = true;
1576 }
1577
1578 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1579 sta->sdata->u.vlan.sta) {
Monam Agarwal0c2bef462014-03-24 00:51:43 +05301580 RCU_INIT_POINTER(sta->sdata->u.vlan.sta, NULL);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001581 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001582 }
1583
Johannes Berg14db74b2008-07-29 13:22:52 +02001584 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001585
1586 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1587 prev_4addr != new_4addr) {
1588 if (new_4addr)
1589 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1590 else
1591 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1592 }
1593
Johannes Berg4fd69312007-12-19 02:03:35 +01001594 ieee80211_send_layer2_update(sta);
1595 }
1596
Eliad Peller35b88622011-12-29 14:41:39 +02001597 err = sta_apply_parameters(local, sta, params);
Johannes Berg77ee7c82013-02-15 00:48:33 +01001598 if (err)
1599 goto out_err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001600
Johannes Berg77ee7c82013-02-15 00:48:33 +01001601 /* When peer becomes authorized, init rate control as well */
1602 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) &&
1603 test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001604 rate_control_rate_init(sta);
1605
Johannes Berg87be1e12011-12-14 12:20:29 +01001606 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001607
Emmanuel Grumbach687da132013-10-01 16:45:43 +03001608 if ((sdata->vif.type == NL80211_IFTYPE_AP ||
1609 sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
1610 sta->known_smps_mode != sta->sdata->bss->req_smps &&
1611 test_sta_flag(sta, WLAN_STA_AUTHORIZED) &&
1612 sta_info_tx_streams(sta) != 1) {
1613 ht_dbg(sta->sdata,
1614 "%pM just authorized and MIMO capable - update SMPS\n",
1615 sta->sta.addr);
1616 ieee80211_send_smps_action(sta->sdata,
1617 sta->sdata->bss->req_smps,
1618 sta->sta.addr,
1619 sta->sdata->vif.bss_conf.bssid);
1620 }
1621
Jason Young808118c2011-03-10 16:43:19 -08001622 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001623 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001624 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001625 ieee80211_recalc_ps_vif(sdata);
1626 }
Johannes Berg77ee7c82013-02-15 00:48:33 +01001627
Johannes Berg4fd69312007-12-19 02:03:35 +01001628 return 0;
Johannes Berg77ee7c82013-02-15 00:48:33 +01001629out_err:
1630 mutex_unlock(&local->sta_mtx);
1631 return err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001632}
1633
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001634#ifdef CONFIG_MAC80211_MESH
1635static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1636 u8 *dst, u8 *next_hop)
1637{
Johannes Berg14db74b2008-07-29 13:22:52 +02001638 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001639 struct mesh_path *mpath;
1640 struct sta_info *sta;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001641
Johannes Berg14db74b2008-07-29 13:22:52 +02001642 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1643
Johannes Bergd0709a62008-02-25 16:27:46 +01001644 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001645 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001646 if (!sta) {
1647 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001648 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001649 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001650
Bob Copelandae76eef2013-03-29 09:38:39 -04001651 mpath = mesh_path_add(sdata, dst);
1652 if (IS_ERR(mpath)) {
Johannes Bergd0709a62008-02-25 16:27:46 +01001653 rcu_read_unlock();
Bob Copelandae76eef2013-03-29 09:38:39 -04001654 return PTR_ERR(mpath);
Johannes Bergd0709a62008-02-25 16:27:46 +01001655 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001656
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001657 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001658
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001659 rcu_read_unlock();
1660 return 0;
1661}
1662
1663static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergbf7cd942013-02-15 14:40:31 +01001664 u8 *dst)
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001665{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001666 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001667
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001668 if (dst)
Johannes Bergbf7cd942013-02-15 14:40:31 +01001669 return mesh_path_del(sdata, dst);
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001670
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001671 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001672 return 0;
1673}
1674
1675static int ieee80211_change_mpath(struct wiphy *wiphy,
1676 struct net_device *dev,
1677 u8 *dst, u8 *next_hop)
1678{
Johannes Berg14db74b2008-07-29 13:22:52 +02001679 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001680 struct mesh_path *mpath;
1681 struct sta_info *sta;
1682
Johannes Berg14db74b2008-07-29 13:22:52 +02001683 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1684
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001685 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001686
Johannes Bergabe60632009-11-25 17:46:18 +01001687 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001688 if (!sta) {
1689 rcu_read_unlock();
1690 return -ENOENT;
1691 }
1692
Johannes Bergbf7cd942013-02-15 14:40:31 +01001693 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001694 if (!mpath) {
1695 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001696 return -ENOENT;
1697 }
1698
1699 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001700
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001701 rcu_read_unlock();
1702 return 0;
1703}
1704
1705static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1706 struct mpath_info *pinfo)
1707{
Johannes Berga3836e02011-05-12 15:11:37 +02001708 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1709
1710 if (next_hop_sta)
1711 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001712 else
1713 memset(next_hop, 0, ETH_ALEN);
1714
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001715 memset(pinfo, 0, sizeof(*pinfo));
1716
Johannes Bergf5ea9122009-08-07 16:17:38 +02001717 pinfo->generation = mesh_paths_generation;
1718
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001719 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001720 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001721 MPATH_INFO_METRIC |
1722 MPATH_INFO_EXPTIME |
1723 MPATH_INFO_DISCOVERY_TIMEOUT |
1724 MPATH_INFO_DISCOVERY_RETRIES |
1725 MPATH_INFO_FLAGS;
1726
1727 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001728 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001729 pinfo->metric = mpath->metric;
1730 if (time_before(jiffies, mpath->exp_time))
1731 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1732 pinfo->discovery_timeout =
1733 jiffies_to_msecs(mpath->discovery_timeout);
1734 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001735 if (mpath->flags & MESH_PATH_ACTIVE)
1736 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1737 if (mpath->flags & MESH_PATH_RESOLVING)
1738 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001739 if (mpath->flags & MESH_PATH_SN_VALID)
1740 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001741 if (mpath->flags & MESH_PATH_FIXED)
1742 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001743 if (mpath->flags & MESH_PATH_RESOLVED)
1744 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001745}
1746
1747static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1748 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1749
1750{
Johannes Berg14db74b2008-07-29 13:22:52 +02001751 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001752 struct mesh_path *mpath;
1753
Johannes Berg14db74b2008-07-29 13:22:52 +02001754 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1755
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001756 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001757 mpath = mesh_path_lookup(sdata, dst);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001758 if (!mpath) {
1759 rcu_read_unlock();
1760 return -ENOENT;
1761 }
1762 memcpy(dst, mpath->dst, ETH_ALEN);
1763 mpath_set_pinfo(mpath, next_hop, pinfo);
1764 rcu_read_unlock();
1765 return 0;
1766}
1767
1768static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1769 int idx, u8 *dst, u8 *next_hop,
1770 struct mpath_info *pinfo)
1771{
Johannes Berg14db74b2008-07-29 13:22:52 +02001772 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001773 struct mesh_path *mpath;
1774
Johannes Berg14db74b2008-07-29 13:22:52 +02001775 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1776
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001777 rcu_read_lock();
Johannes Bergbf7cd942013-02-15 14:40:31 +01001778 mpath = mesh_path_lookup_by_idx(sdata, idx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001779 if (!mpath) {
1780 rcu_read_unlock();
1781 return -ENOENT;
1782 }
1783 memcpy(dst, mpath->dst, ETH_ALEN);
1784 mpath_set_pinfo(mpath, next_hop, pinfo);
1785 rcu_read_unlock();
1786 return 0;
1787}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001788
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001789static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001790 struct net_device *dev,
1791 struct mesh_config *conf)
1792{
1793 struct ieee80211_sub_if_data *sdata;
1794 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1795
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001796 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1797 return 0;
1798}
1799
1800static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1801{
1802 return (mask >> (parm-1)) & 0x1;
1803}
1804
Javier Cardonac80d5452010-12-16 17:37:49 -08001805static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1806 const struct mesh_setup *setup)
1807{
1808 u8 *new_ie;
1809 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001810 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1811 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001812
Javier Cardona581a8b02011-04-07 15:08:27 -07001813 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001814 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001815 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001816
Javier Cardona581a8b02011-04-07 15:08:27 -07001817 if (setup->ie_len) {
1818 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001819 GFP_KERNEL);
1820 if (!new_ie)
1821 return -ENOMEM;
1822 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001823 ifmsh->ie_len = setup->ie_len;
1824 ifmsh->ie = new_ie;
1825 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001826
1827 /* now copy the rest of the setup parameters */
1828 ifmsh->mesh_id_len = setup->mesh_id_len;
1829 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001830 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001831 ifmsh->mesh_pp_id = setup->path_sel_proto;
1832 ifmsh->mesh_pm_id = setup->path_metric;
Thomas Pedersena6dad6a2013-03-04 13:06:12 -08001833 ifmsh->user_mpm = setup->user_mpm;
Colleen Twitty0d4261a2013-05-08 11:46:00 -07001834 ifmsh->mesh_auth_id = setup->auth_id;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001835 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1836 if (setup->is_authenticated)
1837 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1838 if (setup->is_secure)
1839 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001840
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001841 /* mcast rate setting in Mesh Node */
1842 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1843 sizeof(setup->mcast_rate));
Ashok Nagarajanffb3cf32013-06-03 10:33:36 -07001844 sdata->vif.bss_conf.basic_rates = setup->basic_rates;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001845
Marco Porsch9bdbf042013-01-07 16:04:51 +01001846 sdata->vif.bss_conf.beacon_int = setup->beacon_interval;
1847 sdata->vif.bss_conf.dtim_period = setup->dtim_period;
1848
Javier Cardonac80d5452010-12-16 17:37:49 -08001849 return 0;
1850}
1851
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001852static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001853 struct net_device *dev, u32 mask,
1854 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001855{
1856 struct mesh_config *conf;
1857 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001858 struct ieee80211_if_mesh *ifmsh;
1859
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001860 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001861 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001862
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001863 /* Set the config options which we are interested in setting */
1864 conf = &(sdata->u.mesh.mshcfg);
1865 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1866 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1867 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1868 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1869 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1870 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1871 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1872 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1873 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1874 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1875 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1876 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001877 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001878 conf->element_ttl = nconf->element_ttl;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001879 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask)) {
1880 if (ifmsh->user_mpm)
1881 return -EBUSY;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001882 conf->auto_open_plinks = nconf->auto_open_plinks;
Thomas Pedersen146bb482013-03-04 13:06:14 -08001883 }
Javier Cardonad299a1f2012-03-31 11:31:33 -07001884 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1885 conf->dot11MeshNbrOffsetMaxNeighbor =
1886 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001887 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1888 conf->dot11MeshHWMPmaxPREQretries =
1889 nconf->dot11MeshHWMPmaxPREQretries;
1890 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1891 conf->path_refresh_time = nconf->path_refresh_time;
1892 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1893 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1894 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1895 conf->dot11MeshHWMPactivePathTimeout =
1896 nconf->dot11MeshHWMPactivePathTimeout;
1897 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1898 conf->dot11MeshHWMPpreqMinInterval =
1899 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001900 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1901 conf->dot11MeshHWMPperrMinInterval =
1902 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001903 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1904 mask))
1905 conf->dot11MeshHWMPnetDiameterTraversalTime =
1906 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001907 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1908 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1909 ieee80211_mesh_root_setup(ifmsh);
1910 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001911 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001912 /* our current gate announcement implementation rides on root
1913 * announcements, so require this ifmsh to also be a root node
1914 * */
1915 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001916 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1917 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001918 ieee80211_mesh_root_setup(ifmsh);
1919 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001920 conf->dot11MeshGateAnnouncementProtocol =
1921 nconf->dot11MeshGateAnnouncementProtocol;
1922 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001923 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001924 conf->dot11MeshHWMPRannInterval =
1925 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001926 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1927 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001928 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1929 /* our RSSI threshold implementation is supported only for
1930 * devices that report signal in dBm.
1931 */
1932 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1933 return -ENOTSUPP;
1934 conf->rssi_threshold = nconf->rssi_threshold;
1935 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001936 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1937 conf->ht_opmode = nconf->ht_opmode;
1938 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1939 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1940 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001941 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1942 conf->dot11MeshHWMPactivePathToRootTimeout =
1943 nconf->dot11MeshHWMPactivePathToRootTimeout;
1944 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1945 conf->dot11MeshHWMProotInterval =
1946 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001947 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1948 conf->dot11MeshHWMPconfirmationInterval =
1949 nconf->dot11MeshHWMPconfirmationInterval;
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001950 if (_chg_mesh_attr(NL80211_MESHCONF_POWER_MODE, mask)) {
1951 conf->power_mode = nconf->power_mode;
1952 ieee80211_mps_local_status_update(sdata);
1953 }
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001954 if (_chg_mesh_attr(NL80211_MESHCONF_AWAKE_WINDOW, mask))
Marco Porsch3f52b7e2013-01-30 18:14:08 +01001955 conf->dot11MeshAwakeWindowDuration =
1956 nconf->dot11MeshAwakeWindowDuration;
Colleen Twitty66de6712013-06-03 09:53:40 -07001957 if (_chg_mesh_attr(NL80211_MESHCONF_PLINK_TIMEOUT, mask))
1958 conf->plink_timeout = nconf->plink_timeout;
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001959 ieee80211_mbss_info_change_notify(sdata, BSS_CHANGED_BEACON);
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001960 return 0;
1961}
1962
Johannes Berg29cbe682010-12-03 09:20:44 +01001963static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1964 const struct mesh_config *conf,
1965 const struct mesh_setup *setup)
1966{
1967 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1968 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001969 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001970
Javier Cardonac80d5452010-12-16 17:37:49 -08001971 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1972 err = copy_mesh_setup(ifmsh, setup);
1973 if (err)
1974 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001975
Johannes Berg04ecd252012-09-11 14:34:12 +02001976 /* can mesh use other SMPS modes? */
1977 sdata->smps_mode = IEEE80211_SMPS_OFF;
1978 sdata->needed_rx_chains = sdata->local->rx_chains;
1979
Johannes Berg34a37402013-12-18 09:43:33 +01001980 mutex_lock(&sdata->local->mtx);
Johannes Berg4bf88532012-11-09 11:39:59 +01001981 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
Johannes Berg55de9082012-07-26 17:24:39 +02001982 IEEE80211_CHANCTX_SHARED);
Johannes Berg34a37402013-12-18 09:43:33 +01001983 mutex_unlock(&sdata->local->mtx);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001984 if (err)
1985 return err;
1986
Thomas Pedersen2b5e1962013-02-14 11:20:13 -08001987 return ieee80211_start_mesh(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001988}
1989
1990static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1991{
1992 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1993
1994 ieee80211_stop_mesh(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001995 mutex_lock(&sdata->local->mtx);
Johannes Berg55de9082012-07-26 17:24:39 +02001996 ieee80211_vif_release_channel(sdata);
Johannes Berg34a37402013-12-18 09:43:33 +01001997 mutex_unlock(&sdata->local->mtx);
Johannes Berg29cbe682010-12-03 09:20:44 +01001998
1999 return 0;
2000}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002001#endif
2002
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002003static int ieee80211_change_bss(struct wiphy *wiphy,
2004 struct net_device *dev,
2005 struct bss_parameters *params)
2006{
Johannes Berg55de9082012-07-26 17:24:39 +02002007 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2008 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002009 u32 changed = 0;
2010
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01002011 if (!sdata_dereference(sdata->u.ap.beacon, sdata))
Johannes Berg55de9082012-07-26 17:24:39 +02002012 return -ENOENT;
2013
2014 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002015
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002016 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002017 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002018 changed |= BSS_CHANGED_ERP_CTS_PROT;
2019 }
2020 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002021 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002022 params->use_short_preamble;
2023 changed |= BSS_CHANGED_ERP_PREAMBLE;
2024 }
Felix Fietkau43d35342010-01-15 03:00:48 +01002025
2026 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02002027 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01002028 sdata->vif.bss_conf.use_short_slot = true;
2029 changed |= BSS_CHANGED_ERP_SLOT;
2030 }
2031
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002032 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02002033 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002034 params->use_short_slot_time;
2035 changed |= BSS_CHANGED_ERP_SLOT;
2036 }
2037
Jouni Malinen90c97a02008-10-30 16:59:22 +02002038 if (params->basic_rates) {
Simon Wunderlich2103dec2013-07-08 16:55:53 +02002039 ieee80211_parse_bitrates(&sdata->vif.bss_conf.chandef,
2040 wiphy->bands[band],
2041 params->basic_rates,
2042 params->basic_rates_len,
2043 &sdata->vif.bss_conf.basic_rates);
Jouni Malinen90c97a02008-10-30 16:59:22 +02002044 changed |= BSS_CHANGED_BASIC_RATES;
2045 }
2046
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02002047 if (params->ap_isolate >= 0) {
2048 if (params->ap_isolate)
2049 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2050 else
2051 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
2052 }
2053
Helmut Schaa80d7e402010-11-19 12:40:26 +01002054 if (params->ht_opmode >= 0) {
2055 sdata->vif.bss_conf.ht_operation_mode =
2056 (u16) params->ht_opmode;
2057 changed |= BSS_CHANGED_HT;
2058 }
2059
Johannes Berg339afbf2012-11-14 15:21:17 +01002060 if (params->p2p_ctwindow >= 0) {
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002061 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2062 ~IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
2063 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2064 params->p2p_ctwindow & IEEE80211_P2P_OPPPS_CTWINDOW_MASK;
Johannes Berg339afbf2012-11-14 15:21:17 +01002065 changed |= BSS_CHANGED_P2P_PS;
2066 }
2067
Janusz Dziedzic67baf662013-03-21 15:47:56 +01002068 if (params->p2p_opp_ps > 0) {
2069 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow |=
2070 IEEE80211_P2P_OPPPS_ENABLE_BIT;
2071 changed |= BSS_CHANGED_P2P_PS;
2072 } else if (params->p2p_opp_ps == 0) {
2073 sdata->vif.bss_conf.p2p_noa_attr.oppps_ctwindow &=
2074 ~IEEE80211_P2P_OPPPS_ENABLE_BIT;
Johannes Berg339afbf2012-11-14 15:21:17 +01002075 changed |= BSS_CHANGED_P2P_PS;
2076 }
2077
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002078 ieee80211_bss_info_change_notify(sdata, changed);
2079
2080 return 0;
2081}
2082
Jouni Malinen31888482008-10-30 16:59:24 +02002083static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03002084 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02002085 struct ieee80211_txq_params *params)
2086{
2087 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03002088 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02002089 struct ieee80211_tx_queue_params p;
2090
2091 if (!local->ops->conf_tx)
2092 return -EOPNOTSUPP;
2093
Johannes Berg54bcbc62012-03-28 11:04:25 +02002094 if (local->hw.queues < IEEE80211_NUM_ACS)
2095 return -EOPNOTSUPP;
2096
Jouni Malinen31888482008-10-30 16:59:24 +02002097 memset(&p, 0, sizeof(p));
2098 p.aifs = params->aifs;
2099 p.cw_max = params->cwmax;
2100 p.cw_min = params->cwmin;
2101 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02002102
2103 /*
2104 * Setting tx queue params disables u-apsd because it's only
2105 * called in master mode.
2106 */
2107 p.uapsd = false;
2108
Johannes Berga3304b02012-03-28 11:04:24 +02002109 sdata->tx_conf[params->ac] = p;
2110 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07002111 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02002112 "failed to set TX queue parameters for AC %d\n",
2113 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02002114 return -EINVAL;
2115 }
2116
Johannes Berg7d257452012-07-06 17:37:43 +02002117 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
2118
Jouni Malinen31888482008-10-30 16:59:24 +02002119 return 0;
2120}
2121
Bob Copeland665af4f2009-01-19 11:20:53 -05002122#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02002123static int ieee80211_suspend(struct wiphy *wiphy,
2124 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05002125{
Johannes Bergeecc4802011-05-04 15:37:29 +02002126 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05002127}
2128
2129static int ieee80211_resume(struct wiphy *wiphy)
2130{
2131 return __ieee80211_resume(wiphy_priv(wiphy));
2132}
2133#else
2134#define ieee80211_suspend NULL
2135#define ieee80211_resume NULL
2136#endif
2137
Johannes Berg2a519312009-02-10 21:25:55 +01002138static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01002139 struct cfg80211_scan_request *req)
2140{
Johannes Bergfd014282012-06-18 19:17:03 +02002141 struct ieee80211_sub_if_data *sdata;
2142
2143 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01002144
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002145 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
2146 case NL80211_IFTYPE_STATION:
2147 case NL80211_IFTYPE_ADHOC:
2148 case NL80211_IFTYPE_MESH_POINT:
2149 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02002150 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002151 break;
2152 case NL80211_IFTYPE_P2P_GO:
2153 if (sdata->local->ops->hw_scan)
2154 break;
Johannes Berge9d77322011-02-01 15:35:36 +01002155 /*
2156 * FIXME: implement NoA while scanning in software,
2157 * for now fall through to allow scanning only when
2158 * beaconing hasn't been configured yet
2159 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002160 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02002161 /*
2162 * If the scan has been forced (and the driver supports
2163 * forcing), don't care about being beaconing already.
2164 * This will create problems to the attached stations (e.g. all
2165 * the frames sent while scanning on other channel will be
2166 * lost)
2167 */
2168 if (sdata->u.ap.beacon &&
2169 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
2170 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02002171 return -EOPNOTSUPP;
2172 break;
2173 default:
2174 return -EOPNOTSUPP;
2175 }
Johannes Berg2a519312009-02-10 21:25:55 +01002176
2177 return ieee80211_request_scan(sdata, req);
2178}
2179
Luciano Coelho79f460c2011-05-11 17:09:36 +03002180static int
2181ieee80211_sched_scan_start(struct wiphy *wiphy,
2182 struct net_device *dev,
2183 struct cfg80211_sched_scan_request *req)
2184{
2185 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2186
2187 if (!sdata->local->ops->sched_scan_start)
2188 return -EOPNOTSUPP;
2189
2190 return ieee80211_request_sched_scan_start(sdata, req);
2191}
2192
2193static int
Luciano Coelho85a99942011-05-12 16:28:29 +03002194ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03002195{
2196 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2197
2198 if (!sdata->local->ops->sched_scan_stop)
2199 return -EOPNOTSUPP;
2200
Luciano Coelho85a99942011-05-12 16:28:29 +03002201 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03002202}
2203
Jouni Malinen636a5d32009-03-19 13:39:22 +02002204static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
2205 struct cfg80211_auth_request *req)
2206{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002207 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002208}
2209
2210static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
2211 struct cfg80211_assoc_request *req)
2212{
Johannes Berg77fdaa12009-07-07 03:45:17 +02002213 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002214}
2215
2216static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002217 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002218{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002219 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002220}
2221
2222static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002223 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02002224{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01002225 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02002226}
2227
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002228static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
2229 struct cfg80211_ibss_params *params)
2230{
Johannes Berg55de9082012-07-26 17:24:39 +02002231 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002232}
2233
2234static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
2235{
Johannes Berg55de9082012-07-26 17:24:39 +02002236 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002237}
2238
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002239static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
2240 int rate[IEEE80211_NUM_BANDS])
2241{
2242 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2243
Cong Ding9887dbf2013-02-06 17:23:45 +01002244 memcpy(sdata->vif.bss_conf.mcast_rate, rate,
2245 sizeof(int) * IEEE80211_NUM_BANDS);
Antonio Quartulli391e53e2012-11-02 13:27:49 +01002246
2247 return 0;
2248}
2249
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002250static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
2251{
2252 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02002253 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002254
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002255 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2256 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2257
2258 if (err)
2259 return err;
2260 }
2261
Lukáš Turek310bc672009-12-21 22:50:48 +01002262 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2263 err = drv_set_coverage_class(local, wiphy->coverage_class);
2264
2265 if (err)
2266 return err;
2267 }
2268
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002269 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002270 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002271
Johannes Berg24487982009-04-23 18:52:52 +02002272 if (err)
2273 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002274 }
2275
Johannes Berg8bc83c22012-11-09 18:38:32 +01002276 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2277 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2278 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002279 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002280 }
2281 if (changed & WIPHY_PARAM_RETRY_LONG) {
2282 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2283 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002284 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002285 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002286 if (changed &
2287 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2288 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2289
2290 return 0;
2291}
2292
Johannes Berg7643a2c2009-06-02 13:01:39 +02002293static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002294 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002295 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002296{
2297 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002298 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002299
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002300 if (wdev) {
2301 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2302
2303 switch (type) {
2304 case NL80211_TX_POWER_AUTOMATIC:
2305 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2306 break;
2307 case NL80211_TX_POWER_LIMITED:
2308 case NL80211_TX_POWER_FIXED:
2309 if (mbm < 0 || (mbm % 100))
2310 return -EOPNOTSUPP;
2311 sdata->user_power_level = MBM_TO_DBM(mbm);
2312 break;
2313 }
2314
2315 ieee80211_recalc_txpower(sdata);
2316
2317 return 0;
2318 }
Johannes Berg55de9082012-07-26 17:24:39 +02002319
Johannes Berg7643a2c2009-06-02 13:01:39 +02002320 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002321 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002322 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002323 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002324 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002325 case NL80211_TX_POWER_FIXED:
2326 if (mbm < 0 || (mbm % 100))
2327 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002328 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002329 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002330 }
2331
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002332 mutex_lock(&local->iflist_mtx);
2333 list_for_each_entry(sdata, &local->interfaces, list)
2334 sdata->user_power_level = local->user_power_level;
2335 list_for_each_entry(sdata, &local->interfaces, list)
2336 ieee80211_recalc_txpower(sdata);
2337 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002338
2339 return 0;
2340}
2341
Johannes Bergc8442112012-10-24 10:17:18 +02002342static int ieee80211_get_tx_power(struct wiphy *wiphy,
2343 struct wireless_dev *wdev,
2344 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002345{
2346 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002347 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002348
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002349 if (!local->use_chanctx)
2350 *dbm = local->hw.conf.power_level;
2351 else
2352 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002353
Johannes Berg7643a2c2009-06-02 13:01:39 +02002354 return 0;
2355}
2356
Johannes Bergab737a42009-07-01 21:26:58 +02002357static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002358 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002359{
2360 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2361
2362 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2363
2364 return 0;
2365}
2366
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002367static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2368{
2369 struct ieee80211_local *local = wiphy_priv(wiphy);
2370
2371 drv_rfkill_poll(local);
2372}
2373
Johannes Bergaff89a92009-07-01 21:26:51 +02002374#ifdef CONFIG_NL80211_TESTMODE
David Spinadelfc73f112013-07-31 18:04:15 +03002375static int ieee80211_testmode_cmd(struct wiphy *wiphy,
2376 struct wireless_dev *wdev,
2377 void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002378{
2379 struct ieee80211_local *local = wiphy_priv(wiphy);
David Spinadel52981cd2013-07-31 18:06:22 +03002380 struct ieee80211_vif *vif = NULL;
Johannes Bergaff89a92009-07-01 21:26:51 +02002381
2382 if (!local->ops->testmode_cmd)
2383 return -EOPNOTSUPP;
2384
David Spinadel52981cd2013-07-31 18:06:22 +03002385 if (wdev) {
2386 struct ieee80211_sub_if_data *sdata;
2387
2388 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2389 if (sdata->flags & IEEE80211_SDATA_IN_DRIVER)
2390 vif = &sdata->vif;
2391 }
2392
2393 return local->ops->testmode_cmd(&local->hw, vif, data, len);
Johannes Bergaff89a92009-07-01 21:26:51 +02002394}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002395
2396static int ieee80211_testmode_dump(struct wiphy *wiphy,
2397 struct sk_buff *skb,
2398 struct netlink_callback *cb,
2399 void *data, int len)
2400{
2401 struct ieee80211_local *local = wiphy_priv(wiphy);
2402
2403 if (!local->ops->testmode_dump)
2404 return -EOPNOTSUPP;
2405
2406 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2407}
Johannes Bergaff89a92009-07-01 21:26:51 +02002408#endif
2409
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002410int __ieee80211_request_smps_ap(struct ieee80211_sub_if_data *sdata,
2411 enum ieee80211_smps_mode smps_mode)
2412{
2413 struct sta_info *sta;
2414 enum ieee80211_smps_mode old_req;
2415 int i;
2416
2417 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_AP))
2418 return -EINVAL;
2419
2420 if (sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
2421 return 0;
2422
2423 old_req = sdata->u.ap.req_smps;
2424 sdata->u.ap.req_smps = smps_mode;
2425
2426 /* AUTOMATIC doesn't mean much for AP - don't allow it */
2427 if (old_req == smps_mode ||
2428 smps_mode == IEEE80211_SMPS_AUTOMATIC)
2429 return 0;
2430
2431 /* If no associated stations, there's no need to do anything */
2432 if (!atomic_read(&sdata->u.ap.num_mcast_sta)) {
2433 sdata->smps_mode = smps_mode;
2434 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2435 return 0;
2436 }
2437
2438 ht_dbg(sdata,
2439 "SMSP %d requested in AP mode, sending Action frame to %d stations\n",
2440 smps_mode, atomic_read(&sdata->u.ap.num_mcast_sta));
2441
2442 mutex_lock(&sdata->local->sta_mtx);
2443 for (i = 0; i < STA_HASH_SIZE; i++) {
2444 for (sta = rcu_dereference_protected(sdata->local->sta_hash[i],
2445 lockdep_is_held(&sdata->local->sta_mtx));
2446 sta;
2447 sta = rcu_dereference_protected(sta->hnext,
2448 lockdep_is_held(&sdata->local->sta_mtx))) {
2449 /*
2450 * Only stations associated to our AP and
2451 * associated VLANs
2452 */
2453 if (sta->sdata->bss != &sdata->u.ap)
2454 continue;
2455
2456 /* This station doesn't support MIMO - skip it */
2457 if (sta_info_tx_streams(sta) == 1)
2458 continue;
2459
2460 /*
2461 * Don't wake up a STA just to send the action frame
2462 * unless we are getting more restrictive.
2463 */
2464 if (test_sta_flag(sta, WLAN_STA_PS_STA) &&
2465 !ieee80211_smps_is_restrictive(sta->known_smps_mode,
2466 smps_mode)) {
2467 ht_dbg(sdata,
2468 "Won't send SMPS to sleeping STA %pM\n",
2469 sta->sta.addr);
2470 continue;
2471 }
2472
2473 /*
2474 * If the STA is not authorized, wait until it gets
2475 * authorized and the action frame will be sent then.
2476 */
2477 if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
2478 continue;
2479
2480 ht_dbg(sdata, "Sending SMPS to %pM\n", sta->sta.addr);
2481 ieee80211_send_smps_action(sdata, smps_mode,
2482 sta->sta.addr,
2483 sdata->vif.bss_conf.bssid);
2484 }
2485 }
2486 mutex_unlock(&sdata->local->sta_mtx);
2487
2488 sdata->smps_mode = smps_mode;
2489 ieee80211_queue_work(&sdata->local->hw, &sdata->recalc_smps);
2490
2491 return 0;
2492}
2493
2494int __ieee80211_request_smps_mgd(struct ieee80211_sub_if_data *sdata,
2495 enum ieee80211_smps_mode smps_mode)
Johannes Berg0f782312009-12-01 13:37:02 +01002496{
2497 const u8 *ap;
2498 enum ieee80211_smps_mode old_req;
2499 int err;
2500
Johannes Berg8d61ffa2013-05-10 12:32:47 +02002501 lockdep_assert_held(&sdata->wdev.mtx);
Johannes Berg243e6df2011-04-19 20:44:04 +02002502
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002503 if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION))
2504 return -EINVAL;
2505
Johannes Berg0f782312009-12-01 13:37:02 +01002506 old_req = sdata->u.mgd.req_smps;
2507 sdata->u.mgd.req_smps = smps_mode;
2508
2509 if (old_req == smps_mode &&
2510 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2511 return 0;
2512
2513 /*
2514 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002515 * association, there's no need to do anything, just store
2516 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002517 */
2518 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002519 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002520 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002521
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002522 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002523
2524 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2525 if (sdata->u.mgd.powersave)
2526 smps_mode = IEEE80211_SMPS_DYNAMIC;
2527 else
2528 smps_mode = IEEE80211_SMPS_OFF;
2529 }
2530
2531 /* send SM PS frame to AP */
2532 err = ieee80211_send_smps_action(sdata, smps_mode,
2533 ap, ap);
2534 if (err)
2535 sdata->u.mgd.req_smps = old_req;
2536
2537 return err;
2538}
2539
Johannes Bergbc92afd2009-07-01 21:26:57 +02002540static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2541 bool enabled, int timeout)
2542{
2543 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2544 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002545
Bob Copeland2d3db212013-10-29 18:11:59 -04002546 if (sdata->vif.type != NL80211_IFTYPE_STATION)
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002547 return -EOPNOTSUPP;
2548
Johannes Bergbc92afd2009-07-01 21:26:57 +02002549 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2550 return -EOPNOTSUPP;
2551
2552 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002553 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002554 return 0;
2555
2556 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002557 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002558
Johannes Berg0f782312009-12-01 13:37:02 +01002559 /* no change, but if automatic follow powersave */
Johannes Berged405be2013-06-03 13:51:59 +02002560 sdata_lock(sdata);
Emmanuel Grumbach687da132013-10-01 16:45:43 +03002561 __ieee80211_request_smps_mgd(sdata, sdata->u.mgd.req_smps);
Johannes Berged405be2013-06-03 13:51:59 +02002562 sdata_unlock(sdata);
Johannes Berg0f782312009-12-01 13:37:02 +01002563
Johannes Bergbc92afd2009-07-01 21:26:57 +02002564 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2565 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2566
2567 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002568 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002569
2570 return 0;
2571}
2572
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002573static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2574 struct net_device *dev,
2575 s32 rssi_thold, u32 rssi_hyst)
2576{
2577 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002578 struct ieee80211_vif *vif = &sdata->vif;
2579 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2580
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002581 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2582 rssi_hyst == bss_conf->cqm_rssi_hyst)
2583 return 0;
2584
2585 bss_conf->cqm_rssi_thold = rssi_thold;
2586 bss_conf->cqm_rssi_hyst = rssi_hyst;
2587
2588 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002589 if (sdata->u.mgd.associated &&
2590 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002591 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2592
2593 return 0;
2594}
2595
Johannes Berg99303802009-07-01 21:26:59 +02002596static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2597 struct net_device *dev,
2598 const u8 *addr,
2599 const struct cfg80211_bitrate_mask *mask)
2600{
2601 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2602 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302603 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002604
Eliad Peller554a43d2012-06-12 12:41:15 +03002605 if (!ieee80211_sdata_running(sdata))
2606 return -ENETDOWN;
2607
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302608 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2609 ret = drv_set_bitrate_mask(local, sdata, mask);
2610 if (ret)
2611 return ret;
2612 }
Johannes Berg99303802009-07-01 21:26:59 +02002613
Simon Wunderlich19468412012-01-28 17:25:33 +01002614 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002615 struct ieee80211_supported_band *sband = wiphy->bands[i];
2616 int j;
2617
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002618 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Janusz Dziedzicd1e33e62013-12-05 10:02:15 +01002619 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].ht_mcs,
2620 sizeof(mask->control[i].ht_mcs));
Felix Fietkau2ffbe6d2013-04-16 13:38:42 +02002621
2622 sdata->rc_has_mcs_mask[i] = false;
2623 if (!sband)
2624 continue;
2625
2626 for (j = 0; j < IEEE80211_HT_MCS_MASK_LEN; j++)
2627 if (~sdata->rc_rateidx_mcs_mask[i][j]) {
2628 sdata->rc_has_mcs_mask[i] = true;
2629 break;
2630 }
Simon Wunderlich19468412012-01-28 17:25:33 +01002631 }
Johannes Berg99303802009-07-01 21:26:59 +02002632
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002633 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002634}
2635
Johannes Berg2eb278e2012-06-05 14:28:42 +02002636static int ieee80211_start_roc_work(struct ieee80211_local *local,
2637 struct ieee80211_sub_if_data *sdata,
2638 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002639 unsigned int duration, u64 *cookie,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002640 struct sk_buff *txskb,
2641 enum ieee80211_roc_type type)
Johannes Berg21f83582010-12-18 17:20:47 +01002642{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002643 struct ieee80211_roc_work *roc, *tmp;
2644 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002645 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002646
2647 lockdep_assert_held(&local->mtx);
2648
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002649 if (local->use_chanctx && !local->ops->remain_on_channel)
2650 return -EOPNOTSUPP;
2651
Johannes Berg2eb278e2012-06-05 14:28:42 +02002652 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2653 if (!roc)
2654 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002655
Ilan Peer2fae0622013-12-19 13:25:29 +02002656 /*
2657 * If the duration is zero, then the driver
2658 * wouldn't actually do anything. Set it to
2659 * 10 for now.
2660 *
2661 * TODO: cancel the off-channel operation
2662 * when we get the SKB's TX status and
2663 * the wait time was zero before.
2664 */
2665 if (!duration)
2666 duration = 10;
2667
Johannes Berg2eb278e2012-06-05 14:28:42 +02002668 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002669 roc->duration = duration;
2670 roc->req_duration = duration;
2671 roc->frame = txskb;
Ilan Peerd339d5c2013-02-12 09:34:13 +02002672 roc->type = type;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002673 roc->mgmt_tx_cookie = (unsigned long)txskb;
2674 roc->sdata = sdata;
2675 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2676 INIT_LIST_HEAD(&roc->dependents);
2677
Eliad Peller2f617432014-01-12 11:06:37 +02002678 /*
2679 * cookie is either the roc cookie (for normal roc)
2680 * or the SKB (for mgmt TX)
2681 */
2682 if (!txskb) {
2683 /* local->mtx protects this */
2684 local->roc_cookie_counter++;
2685 roc->cookie = local->roc_cookie_counter;
2686 /* wow, you wrapped 64 bits ... more likely a bug */
2687 if (WARN_ON(roc->cookie == 0)) {
2688 roc->cookie = 1;
2689 local->roc_cookie_counter++;
2690 }
2691 *cookie = roc->cookie;
2692 } else {
2693 *cookie = (unsigned long)txskb;
2694 }
2695
Johannes Berg2eb278e2012-06-05 14:28:42 +02002696 /* if there's one pending or we're scanning, queue this one */
Simon Wunderlich164eb022013-02-08 18:16:20 +01002697 if (!list_empty(&local->roc_list) ||
2698 local->scanning || local->radar_detect_enabled)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002699 goto out_check_combine;
2700
2701 /* if not HW assist, just queue & schedule work */
2702 if (!local->ops->remain_on_channel) {
2703 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2704 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002705 }
2706
Johannes Berg2eb278e2012-06-05 14:28:42 +02002707 /* otherwise actually kick it off here (for error handling) */
2708
Ilan Peerd339d5c2013-02-12 09:34:13 +02002709 ret = drv_remain_on_channel(local, sdata, channel, duration, type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002710 if (ret) {
2711 kfree(roc);
2712 return ret;
2713 }
2714
2715 roc->started = true;
2716 goto out_queue;
2717
2718 out_check_combine:
2719 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002720 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002721 continue;
2722
2723 /*
2724 * Extend this ROC if possible:
2725 *
2726 * If it hasn't started yet, just increase the duration
2727 * and add the new one to the list of dependents.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002728 * If the type of the new ROC has higher priority, modify the
2729 * type of the previous one to match that of the new one.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002730 */
2731 if (!tmp->started) {
2732 list_add_tail(&roc->list, &tmp->dependents);
2733 tmp->duration = max(tmp->duration, roc->duration);
Ilan Peerd339d5c2013-02-12 09:34:13 +02002734 tmp->type = max(tmp->type, roc->type);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002735 queued = true;
2736 break;
2737 }
2738
2739 /* If it has already started, it's more difficult ... */
2740 if (local->ops->remain_on_channel) {
2741 unsigned long j = jiffies;
2742
2743 /*
2744 * In the offloaded ROC case, if it hasn't begun, add
2745 * this new one to the dependent list to be handled
Ilan Peerd339d5c2013-02-12 09:34:13 +02002746 * when the master one begins. If it has begun,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002747 * check that there's still a minimum time left and
2748 * if so, start this one, transmitting the frame, but
Ilan Peerd339d5c2013-02-12 09:34:13 +02002749 * add it to the list directly after this one with
Johannes Berg2eb278e2012-06-05 14:28:42 +02002750 * a reduced time so we'll ask the driver to execute
2751 * it right after finishing the previous one, in the
2752 * hope that it'll also be executed right afterwards,
2753 * effectively extending the old one.
2754 * If there's no minimum time left, just add it to the
2755 * normal list.
Ilan Peerd339d5c2013-02-12 09:34:13 +02002756 * TODO: the ROC type is ignored here, assuming that it
2757 * is better to immediately use the current ROC.
Johannes Berg2eb278e2012-06-05 14:28:42 +02002758 */
2759 if (!tmp->hw_begun) {
2760 list_add_tail(&roc->list, &tmp->dependents);
2761 queued = true;
2762 break;
2763 }
2764
2765 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2766 tmp->hw_start_time +
2767 msecs_to_jiffies(tmp->duration))) {
2768 int new_dur;
2769
2770 ieee80211_handle_roc_started(roc);
2771
2772 new_dur = roc->duration -
2773 jiffies_to_msecs(tmp->hw_start_time +
2774 msecs_to_jiffies(
2775 tmp->duration) -
2776 j);
2777
2778 if (new_dur > 0) {
2779 /* add right after tmp */
2780 list_add(&roc->list, &tmp->list);
2781 } else {
2782 list_add_tail(&roc->list,
2783 &tmp->dependents);
2784 }
2785 queued = true;
2786 }
2787 } else if (del_timer_sync(&tmp->work.timer)) {
2788 unsigned long new_end;
2789
2790 /*
2791 * In the software ROC case, cancel the timer, if
2792 * that fails then the finish work is already
2793 * queued/pending and thus we queue the new ROC
2794 * normally, if that succeeds then we can extend
2795 * the timer duration and TX the frame (if any.)
2796 */
2797
2798 list_add_tail(&roc->list, &tmp->dependents);
2799 queued = true;
2800
2801 new_end = jiffies + msecs_to_jiffies(roc->duration);
2802
2803 /* ok, it was started & we canceled timer */
2804 if (time_after(new_end, tmp->work.timer.expires))
2805 mod_timer(&tmp->work.timer, new_end);
2806 else
2807 add_timer(&tmp->work.timer);
2808
2809 ieee80211_handle_roc_started(roc);
2810 }
2811 break;
2812 }
2813
2814 out_queue:
2815 if (!queued)
2816 list_add_tail(&roc->list, &local->roc_list);
2817
Johannes Berg2eb278e2012-06-05 14:28:42 +02002818 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002819}
2820
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002821static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002822 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002823 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002824 unsigned int duration,
2825 u64 *cookie)
2826{
Johannes Berg71bbc992012-06-15 15:30:18 +02002827 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002828 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002829 int ret;
2830
Johannes Berg2eb278e2012-06-05 14:28:42 +02002831 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002832 ret = ieee80211_start_roc_work(local, sdata, chan,
Ilan Peerd339d5c2013-02-12 09:34:13 +02002833 duration, cookie, NULL,
2834 IEEE80211_ROC_TYPE_NORMAL);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002835 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002836
Johannes Berg2eb278e2012-06-05 14:28:42 +02002837 return ret;
2838}
2839
2840static int ieee80211_cancel_roc(struct ieee80211_local *local,
2841 u64 cookie, bool mgmt_tx)
2842{
2843 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2844 int ret;
2845
2846 mutex_lock(&local->mtx);
2847 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002848 struct ieee80211_roc_work *dep, *tmp2;
2849
2850 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002851 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002852 continue;
2853 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2854 continue;
2855 /* found dependent item -- just remove it */
2856 list_del(&dep->list);
2857 mutex_unlock(&local->mtx);
2858
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002859 ieee80211_roc_notify_destroy(dep, true);
Johannes Berge979e332012-06-11 17:09:41 +02002860 return 0;
2861 }
2862
Johannes Berg50febf62012-10-26 16:13:06 +02002863 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002864 continue;
2865 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2866 continue;
2867
2868 found = roc;
2869 break;
2870 }
2871
2872 if (!found) {
2873 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002874 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002875 }
Johannes Berg21f83582010-12-18 17:20:47 +01002876
Johannes Berge979e332012-06-11 17:09:41 +02002877 /*
2878 * We found the item to cancel, so do that. Note that it
2879 * may have dependents, which we also cancel (and send
2880 * the expired signal for.) Not doing so would be quite
2881 * tricky here, but we may need to fix it later.
2882 */
2883
Johannes Berg2eb278e2012-06-05 14:28:42 +02002884 if (local->ops->remain_on_channel) {
2885 if (found->started) {
2886 ret = drv_cancel_remain_on_channel(local);
2887 if (WARN_ON_ONCE(ret)) {
2888 mutex_unlock(&local->mtx);
2889 return ret;
2890 }
2891 }
Johannes Berg21f83582010-12-18 17:20:47 +01002892
Johannes Berg2eb278e2012-06-05 14:28:42 +02002893 list_del(&found->list);
2894
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002895 if (found->started)
2896 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002897 mutex_unlock(&local->mtx);
2898
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002899 ieee80211_roc_notify_destroy(found, true);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002900 } else {
2901 /* work may be pending so use it all the time */
2902 found->abort = true;
2903 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2904
2905 mutex_unlock(&local->mtx);
2906
2907 /* work will clean up etc */
2908 flush_delayed_work(&found->work);
Johannes Berg3fbd45c2013-03-25 11:51:14 +01002909 WARN_ON(!found->to_be_freed);
2910 kfree(found);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002911 }
Johannes Berg21f83582010-12-18 17:20:47 +01002912
Johannes Berg21f83582010-12-18 17:20:47 +01002913 return 0;
2914}
2915
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002916static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002917 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002918 u64 cookie)
2919{
Johannes Berg71bbc992012-06-15 15:30:18 +02002920 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002921 struct ieee80211_local *local = sdata->local;
2922
Johannes Berg2eb278e2012-06-05 14:28:42 +02002923 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002924}
2925
Simon Wunderlich164eb022013-02-08 18:16:20 +01002926static int ieee80211_start_radar_detection(struct wiphy *wiphy,
2927 struct net_device *dev,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002928 struct cfg80211_chan_def *chandef,
2929 u32 cac_time_ms)
Simon Wunderlich164eb022013-02-08 18:16:20 +01002930{
2931 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2932 struct ieee80211_local *local = sdata->local;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002933 int err;
2934
Johannes Berg34a37402013-12-18 09:43:33 +01002935 mutex_lock(&local->mtx);
2936 if (!list_empty(&local->roc_list) || local->scanning) {
2937 err = -EBUSY;
2938 goto out_unlock;
2939 }
Simon Wunderlich164eb022013-02-08 18:16:20 +01002940
2941 /* whatever, but channel contexts should not complain about that one */
2942 sdata->smps_mode = IEEE80211_SMPS_OFF;
2943 sdata->needed_rx_chains = local->rx_chains;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002944
Simon Wunderlich164eb022013-02-08 18:16:20 +01002945 err = ieee80211_vif_use_channel(sdata, chandef,
2946 IEEE80211_CHANCTX_SHARED);
Simon Wunderlich164eb022013-02-08 18:16:20 +01002947 if (err)
Johannes Berg34a37402013-12-18 09:43:33 +01002948 goto out_unlock;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002949
Simon Wunderlich164eb022013-02-08 18:16:20 +01002950 ieee80211_queue_delayed_work(&sdata->local->hw,
Janusz Dziedzic31559f32014-02-21 19:46:13 +01002951 &sdata->dfs_cac_timer_work,
2952 msecs_to_jiffies(cac_time_ms));
Simon Wunderlich164eb022013-02-08 18:16:20 +01002953
Johannes Berg34a37402013-12-18 09:43:33 +01002954 out_unlock:
2955 mutex_unlock(&local->mtx);
2956 return err;
Simon Wunderlich164eb022013-02-08 18:16:20 +01002957}
2958
Simon Wunderlich73da7d52013-07-11 16:09:06 +02002959static struct cfg80211_beacon_data *
2960cfg80211_beacon_dup(struct cfg80211_beacon_data *beacon)
2961{
2962 struct cfg80211_beacon_data *new_beacon;
2963 u8 *pos;
2964 int len;
2965
2966 len = beacon->head_len + beacon->tail_len + beacon->beacon_ies_len +
2967 beacon->proberesp_ies_len + beacon->assocresp_ies_len +
2968 beacon->probe_resp_len;
2969
2970 new_beacon = kzalloc(sizeof(*new_beacon) + len, GFP_KERNEL);
2971 if (!new_beacon)
2972 return NULL;
2973
2974 pos = (u8 *)(new_beacon + 1);
2975 if (beacon->head_len) {
2976 new_beacon->head_len = beacon->head_len;
2977 new_beacon->head = pos;
2978 memcpy(pos, beacon->head, beacon->head_len);
2979 pos += beacon->head_len;
2980 }
2981 if (beacon->tail_len) {
2982 new_beacon->tail_len = beacon->tail_len;
2983 new_beacon->tail = pos;
2984 memcpy(pos, beacon->tail, beacon->tail_len);
2985 pos += beacon->tail_len;
2986 }
2987 if (beacon->beacon_ies_len) {
2988 new_beacon->beacon_ies_len = beacon->beacon_ies_len;
2989 new_beacon->beacon_ies = pos;
2990 memcpy(pos, beacon->beacon_ies, beacon->beacon_ies_len);
2991 pos += beacon->beacon_ies_len;
2992 }
2993 if (beacon->proberesp_ies_len) {
2994 new_beacon->proberesp_ies_len = beacon->proberesp_ies_len;
2995 new_beacon->proberesp_ies = pos;
2996 memcpy(pos, beacon->proberesp_ies, beacon->proberesp_ies_len);
2997 pos += beacon->proberesp_ies_len;
2998 }
2999 if (beacon->assocresp_ies_len) {
3000 new_beacon->assocresp_ies_len = beacon->assocresp_ies_len;
3001 new_beacon->assocresp_ies = pos;
3002 memcpy(pos, beacon->assocresp_ies, beacon->assocresp_ies_len);
3003 pos += beacon->assocresp_ies_len;
3004 }
3005 if (beacon->probe_resp_len) {
3006 new_beacon->probe_resp_len = beacon->probe_resp_len;
3007 beacon->probe_resp = pos;
3008 memcpy(pos, beacon->probe_resp, beacon->probe_resp_len);
3009 pos += beacon->probe_resp_len;
3010 }
3011
3012 return new_beacon;
3013}
3014
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003015void ieee80211_csa_finish(struct ieee80211_vif *vif)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003016{
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003017 struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
3018
3019 ieee80211_queue_work(&sdata->local->hw,
3020 &sdata->csa_finalize_work);
3021}
3022EXPORT_SYMBOL(ieee80211_csa_finish);
3023
3024static void ieee80211_csa_finalize(struct ieee80211_sub_if_data *sdata)
3025{
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003026 struct ieee80211_local *local = sdata->local;
Michal Kazior0951ebb2013-10-18 14:57:00 -07003027 int err, changed = 0;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003028
Michal Kaziordbd72852014-01-29 07:56:21 +01003029 sdata_assert_lock(sdata);
3030
Johannes Berg34a37402013-12-18 09:43:33 +01003031 mutex_lock(&local->mtx);
Michal Kaziorcc901de2014-01-29 07:56:20 +01003032 sdata->radar_required = sdata->csa_radar_required;
Luciano Coelho33787fc2013-11-11 20:34:54 +02003033 err = ieee80211_vif_change_channel(sdata, &changed);
Johannes Berg34a37402013-12-18 09:43:33 +01003034 mutex_unlock(&local->mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003035 if (WARN_ON(err < 0))
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003036 return;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003037
Arik Nemtsov7578d572013-09-01 17:15:51 +03003038 if (!local->use_chanctx) {
Luciano Coelho33787fc2013-11-11 20:34:54 +02003039 local->_oper_chandef = sdata->csa_chandef;
Arik Nemtsov7578d572013-09-01 17:15:51 +03003040 ieee80211_hw_config(local, 0);
3041 }
3042
Simon Wunderliche487eae2013-11-21 18:19:51 +01003043 sdata->vif.csa_active = false;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003044 switch (sdata->vif.type) {
3045 case NL80211_IFTYPE_AP:
3046 err = ieee80211_assign_beacon(sdata, sdata->u.ap.next_beacon);
Michal Kazior97518af12014-01-29 07:56:18 +01003047 kfree(sdata->u.ap.next_beacon);
3048 sdata->u.ap.next_beacon = NULL;
3049
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003050 if (err < 0)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003051 return;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003052 changed |= err;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003053 break;
3054 case NL80211_IFTYPE_ADHOC:
Michal Kaziorfaf046e2014-01-29 07:56:17 +01003055 err = ieee80211_ibss_finish_csa(sdata);
3056 if (err < 0)
3057 return;
3058 changed |= err;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003059 break;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003060#ifdef CONFIG_MAC80211_MESH
3061 case NL80211_IFTYPE_MESH_POINT:
3062 err = ieee80211_mesh_finish_csa(sdata);
3063 if (err < 0)
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003064 return;
Michal Kaziorfaf046e2014-01-29 07:56:17 +01003065 changed |= err;
Chun-Yeow Yeohb8456a12013-10-17 15:55:02 -07003066 break;
3067#endif
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003068 default:
3069 WARN_ON(1);
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003070 return;
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003071 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003072
Michal Kaziorfaf046e2014-01-29 07:56:17 +01003073 ieee80211_bss_info_change_notify(sdata, changed);
3074
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003075 ieee80211_wake_queues_by_reason(&sdata->local->hw,
3076 IEEE80211_MAX_QUEUE_MAP,
3077 IEEE80211_QUEUE_STOP_REASON_CSA);
3078
Luciano Coelho33787fc2013-11-11 20:34:54 +02003079 cfg80211_ch_switch_notify(sdata->dev, &sdata->csa_chandef);
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003080}
3081
3082void ieee80211_csa_finalize_work(struct work_struct *work)
3083{
3084 struct ieee80211_sub_if_data *sdata =
3085 container_of(work, struct ieee80211_sub_if_data,
3086 csa_finalize_work);
3087
3088 sdata_lock(sdata);
3089 /* AP might have been stopped while waiting for the lock. */
3090 if (!sdata->vif.csa_active)
3091 goto unlock;
3092
3093 if (!ieee80211_sdata_running(sdata))
3094 goto unlock;
3095
3096 ieee80211_csa_finalize(sdata);
Simon Wunderliche487eae2013-11-21 18:19:51 +01003097
3098unlock:
3099 sdata_unlock(sdata);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003100}
3101
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003102static int ieee80211_set_csa_beacon(struct ieee80211_sub_if_data *sdata,
3103 struct cfg80211_csa_settings *params,
3104 u32 *changed)
3105{
3106 int err;
3107
3108 switch (sdata->vif.type) {
3109 case NL80211_IFTYPE_AP:
3110 sdata->u.ap.next_beacon =
3111 cfg80211_beacon_dup(&params->beacon_after);
3112 if (!sdata->u.ap.next_beacon)
3113 return -ENOMEM;
3114
3115 /*
3116 * With a count of 0, we don't have to wait for any
3117 * TBTT before switching, so complete the CSA
3118 * immediately. In theory, with a count == 1 we
3119 * should delay the switch until just before the next
3120 * TBTT, but that would complicate things so we switch
3121 * immediately too. If we would delay the switch
3122 * until the next TBTT, we would have to set the probe
3123 * response here.
3124 *
3125 * TODO: A channel switch with count <= 1 without
3126 * sending a CSA action frame is kind of useless,
3127 * because the clients won't know we're changing
3128 * channels. The action frame must be implemented
3129 * either here or in the userspace.
3130 */
3131 if (params->count <= 1)
3132 break;
3133
3134 sdata->csa_counter_offset_beacon =
3135 params->counter_offset_beacon;
3136 sdata->csa_counter_offset_presp = params->counter_offset_presp;
3137 err = ieee80211_assign_beacon(sdata, &params->beacon_csa);
3138 if (err < 0) {
3139 kfree(sdata->u.ap.next_beacon);
3140 return err;
3141 }
3142 *changed |= err;
3143
3144 break;
3145 case NL80211_IFTYPE_ADHOC:
3146 if (!sdata->vif.bss_conf.ibss_joined)
3147 return -EINVAL;
3148
3149 if (params->chandef.width != sdata->u.ibss.chandef.width)
3150 return -EINVAL;
3151
3152 switch (params->chandef.width) {
3153 case NL80211_CHAN_WIDTH_40:
3154 if (cfg80211_get_chandef_type(&params->chandef) !=
3155 cfg80211_get_chandef_type(&sdata->u.ibss.chandef))
3156 return -EINVAL;
3157 case NL80211_CHAN_WIDTH_5:
3158 case NL80211_CHAN_WIDTH_10:
3159 case NL80211_CHAN_WIDTH_20_NOHT:
3160 case NL80211_CHAN_WIDTH_20:
3161 break;
3162 default:
3163 return -EINVAL;
3164 }
3165
3166 /* changes into another band are not supported */
3167 if (sdata->u.ibss.chandef.chan->band !=
3168 params->chandef.chan->band)
3169 return -EINVAL;
3170
3171 /* see comments in the NL80211_IFTYPE_AP block */
3172 if (params->count > 1) {
3173 err = ieee80211_ibss_csa_beacon(sdata, params);
3174 if (err < 0)
3175 return err;
3176 *changed |= err;
3177 }
3178
3179 ieee80211_send_action_csa(sdata, params);
3180
3181 break;
3182#ifdef CONFIG_MAC80211_MESH
3183 case NL80211_IFTYPE_MESH_POINT: {
3184 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
3185
3186 if (params->chandef.width != sdata->vif.bss_conf.chandef.width)
3187 return -EINVAL;
3188
3189 /* changes into another band are not supported */
3190 if (sdata->vif.bss_conf.chandef.chan->band !=
3191 params->chandef.chan->band)
3192 return -EINVAL;
3193
3194 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_NONE) {
3195 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_INIT;
3196 if (!ifmsh->pre_value)
3197 ifmsh->pre_value = 1;
3198 else
3199 ifmsh->pre_value++;
3200 }
3201
3202 /* see comments in the NL80211_IFTYPE_AP block */
3203 if (params->count > 1) {
3204 err = ieee80211_mesh_csa_beacon(sdata, params);
3205 if (err < 0) {
3206 ifmsh->csa_role = IEEE80211_MESH_CSA_ROLE_NONE;
3207 return err;
3208 }
3209 *changed |= err;
3210 }
3211
3212 if (ifmsh->csa_role == IEEE80211_MESH_CSA_ROLE_INIT)
3213 ieee80211_send_action_csa(sdata, params);
3214
3215 break;
3216 }
3217#endif
3218 default:
3219 return -EOPNOTSUPP;
3220 }
3221
3222 return 0;
3223}
3224
Luciano Coelho82a8e172013-12-13 21:13:50 +02003225int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
3226 struct cfg80211_csa_settings *params)
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003227{
3228 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3229 struct ieee80211_local *local = sdata->local;
Michal Kazior2b327132014-04-09 15:29:32 +02003230 struct ieee80211_chanctx_conf *conf;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003231 struct ieee80211_chanctx *chanctx;
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003232 int err, num_chanctx, changed = 0;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003233
Michal Kaziordbd72852014-01-29 07:56:21 +01003234 sdata_assert_lock(sdata);
Simon Wunderlich7ca133b2013-11-21 18:19:50 +01003235
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003236 if (!list_empty(&local->roc_list) || local->scanning)
3237 return -EBUSY;
3238
3239 if (sdata->wdev.cac_started)
3240 return -EBUSY;
3241
3242 if (cfg80211_chandef_identical(&params->chandef,
3243 &sdata->vif.bss_conf.chandef))
3244 return -EINVAL;
3245
Michal Kazior2b327132014-04-09 15:29:32 +02003246 mutex_lock(&local->chanctx_mtx);
3247 conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
3248 lockdep_is_held(&local->chanctx_mtx));
3249 if (!conf) {
3250 mutex_unlock(&local->chanctx_mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003251 return -EBUSY;
3252 }
3253
3254 /* don't handle for multi-VIF cases */
Michal Kazior2b327132014-04-09 15:29:32 +02003255 chanctx = container_of(conf, struct ieee80211_chanctx, conf);
Michal Kaziorc0166da2014-04-09 15:29:33 +02003256 if (ieee80211_chanctx_refcount(local, chanctx) > 1) {
Michal Kazior2b327132014-04-09 15:29:32 +02003257 mutex_unlock(&local->chanctx_mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003258 return -EBUSY;
3259 }
3260 num_chanctx = 0;
3261 list_for_each_entry_rcu(chanctx, &local->chanctx_list, list)
3262 num_chanctx++;
Michal Kazior2b327132014-04-09 15:29:32 +02003263 mutex_unlock(&local->chanctx_mtx);
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003264
3265 if (num_chanctx > 1)
3266 return -EBUSY;
3267
3268 /* don't allow another channel switch if one is already active. */
3269 if (sdata->vif.csa_active)
3270 return -EBUSY;
3271
Michal Kazior37fa2bd2014-02-28 15:59:06 +01003272 err = ieee80211_set_csa_beacon(sdata, params, &changed);
3273 if (err)
3274 return err;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003275
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003276 sdata->csa_radar_required = params->radar_required;
3277
3278 if (params->block_tx)
3279 ieee80211_stop_queues_by_reason(&local->hw,
3280 IEEE80211_MAX_QUEUE_MAP,
3281 IEEE80211_QUEUE_STOP_REASON_CSA);
3282
Luciano Coelho33787fc2013-11-11 20:34:54 +02003283 sdata->csa_chandef = params->chandef;
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003284 sdata->vif.csa_active = true;
3285
Luciano Coelho66e01cf2014-01-13 19:43:00 +02003286 if (changed) {
3287 ieee80211_bss_info_change_notify(sdata, changed);
3288 drv_channel_switch_beacon(sdata, &params->chandef);
3289 } else {
3290 /* if the beacon didn't change, we can finalize immediately */
3291 ieee80211_csa_finalize(sdata);
3292 }
Simon Wunderlich73da7d52013-07-11 16:09:06 +02003293
3294 return 0;
3295}
3296
Johannes Berg71bbc992012-06-15 15:30:18 +02003297static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003298 struct cfg80211_mgmt_tx_params *params,
3299 u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02003300{
Johannes Berg71bbc992012-06-15 15:30:18 +02003301 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02003302 struct ieee80211_local *local = sdata->local;
3303 struct sk_buff *skb;
3304 struct sta_info *sta;
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003305 const struct ieee80211_mgmt *mgmt = (void *)params->buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003306 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01003307 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003308 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01003309
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003310 if (params->dont_wait_for_ack)
Johannes Berge247bd902011-11-04 11:18:21 +01003311 flags = IEEE80211_TX_CTL_NO_ACK;
3312 else
3313 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
3314 IEEE80211_TX_CTL_REQ_TX_STATUS;
3315
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003316 if (params->no_cck)
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05303317 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
3318
Johannes Berg9d38d852010-06-09 17:20:33 +02003319 switch (sdata->vif.type) {
3320 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003321 if (!sdata->vif.bss_conf.ibss_joined)
3322 need_offchan = true;
3323 /* fall through */
3324#ifdef CONFIG_MAC80211_MESH
3325 case NL80211_IFTYPE_MESH_POINT:
3326 if (ieee80211_vif_is_mesh(&sdata->vif) &&
3327 !sdata->u.mesh.mesh_id_len)
3328 need_offchan = true;
3329 /* fall through */
3330#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02003331 case NL80211_IFTYPE_AP:
3332 case NL80211_IFTYPE_AP_VLAN:
3333 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003334 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
3335 !ieee80211_vif_is_mesh(&sdata->vif) &&
3336 !rcu_access_pointer(sdata->bss->beacon))
3337 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02003338 if (!ieee80211_is_action(mgmt->frame_control) ||
Thomas Pedersenac49e1a2013-06-20 23:50:58 -07003339 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC ||
Simon Wunderlichcd7760e2013-08-28 13:41:31 +02003340 mgmt->u.action.category == WLAN_CATEGORY_SELF_PROTECTED ||
3341 mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT)
Johannes Berg9d38d852010-06-09 17:20:33 +02003342 break;
3343 rcu_read_lock();
3344 sta = sta_info_get(sdata, mgmt->da);
3345 rcu_read_unlock();
3346 if (!sta)
3347 return -ENOLINK;
3348 break;
3349 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02003350 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02003351 if (!sdata->u.mgd.associated)
3352 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02003353 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02003354 case NL80211_IFTYPE_P2P_DEVICE:
3355 need_offchan = true;
3356 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02003357 default:
3358 return -EOPNOTSUPP;
3359 }
3360
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003361 /* configurations requiring offchan cannot work if no channel has been
3362 * specified
3363 */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003364 if (need_offchan && !params->chan)
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003365 return -EINVAL;
3366
Johannes Berg2eb278e2012-06-05 14:28:42 +02003367 mutex_lock(&local->mtx);
3368
3369 /* Check if the operating channel is the requested channel */
3370 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02003371 struct ieee80211_chanctx_conf *chanctx_conf;
3372
3373 rcu_read_lock();
3374 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3375
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003376 if (chanctx_conf) {
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003377 need_offchan = params->chan &&
3378 (params->chan !=
3379 chanctx_conf->def.chan);
3380 } else if (!params->chan) {
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003381 ret = -EINVAL;
3382 rcu_read_unlock();
3383 goto out_unlock;
3384 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003385 need_offchan = true;
Antonio Quartullif7aeb6f2013-06-11 14:20:00 +02003386 }
Johannes Berg55de9082012-07-26 17:24:39 +02003387 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02003388 }
3389
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003390 if (need_offchan && !params->offchan) {
Johannes Berg2eb278e2012-06-05 14:28:42 +02003391 ret = -EBUSY;
3392 goto out_unlock;
3393 }
3394
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003395 skb = dev_alloc_skb(local->hw.extra_tx_headroom + params->len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003396 if (!skb) {
3397 ret = -ENOMEM;
3398 goto out_unlock;
3399 }
Johannes Berg9d38d852010-06-09 17:20:33 +02003400 skb_reserve(skb, local->hw.extra_tx_headroom);
3401
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003402 memcpy(skb_put(skb, params->len), params->buf, params->len);
Johannes Berg9d38d852010-06-09 17:20:33 +02003403
3404 IEEE80211_SKB_CB(skb)->flags = flags;
3405
Johannes Berg2eb278e2012-06-05 14:28:42 +02003406 skb->dev = sdata->dev;
3407
3408 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02003409 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003410 ieee80211_tx_skb(sdata, skb);
3411 ret = 0;
3412 goto out_unlock;
3413 }
3414
Seth Forshee6c17b772013-02-11 11:21:07 -06003415 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN |
3416 IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
Johannes Berg2eb278e2012-06-05 14:28:42 +02003417 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02003418 IEEE80211_SKB_CB(skb)->hw_queue =
3419 local->hw.offchannel_tx_hw_queue;
3420
Johannes Berg2eb278e2012-06-05 14:28:42 +02003421 /* This will handle all kinds of coalescing and immediate TX */
Andrei Otcheretianskib176e622013-11-18 19:06:49 +02003422 ret = ieee80211_start_roc_work(local, sdata, params->chan,
3423 params->wait, cookie, skb,
Ilan Peerd339d5c2013-02-12 09:34:13 +02003424 IEEE80211_ROC_TYPE_MGMT_TX);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003425 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01003426 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02003427 out_unlock:
3428 mutex_unlock(&local->mtx);
3429 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02003430}
3431
Johannes Bergf30221e2010-11-25 10:02:30 +01003432static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003433 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01003434 u64 cookie)
3435{
Johannes Berg71bbc992012-06-15 15:30:18 +02003436 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01003437
Johannes Berg2eb278e2012-06-05 14:28:42 +02003438 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01003439}
3440
Johannes Berg7be50862010-10-13 12:06:24 +02003441static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02003442 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02003443 u16 frame_type, bool reg)
3444{
3445 struct ieee80211_local *local = wiphy_priv(wiphy);
3446
Will Hawkins6abe0562012-06-20 11:51:14 -04003447 switch (frame_type) {
Will Hawkins6abe0562012-06-20 11:51:14 -04003448 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
3449 if (reg)
3450 local->probe_req_reg++;
3451 else
3452 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02003453
Felix Fietkau35f51492012-10-31 15:50:34 +01003454 if (!local->open_count)
3455 break;
3456
Will Hawkins6abe0562012-06-20 11:51:14 -04003457 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
3458 break;
3459 default:
3460 break;
3461 }
Johannes Berg7be50862010-10-13 12:06:24 +02003462}
3463
Bruno Randolf15d96752010-11-10 12:50:56 +09003464static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
3465{
3466 struct ieee80211_local *local = wiphy_priv(wiphy);
3467
3468 if (local->started)
3469 return -EOPNOTSUPP;
3470
3471 return drv_set_antenna(local, tx_ant, rx_ant);
3472}
3473
3474static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
3475{
3476 struct ieee80211_local *local = wiphy_priv(wiphy);
3477
3478 return drv_get_antenna(local, tx_ant, rx_ant);
3479}
3480
John W. Linville38c09152011-03-07 16:19:18 -05003481static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
3482{
3483 struct ieee80211_local *local = wiphy_priv(wiphy);
3484
3485 return drv_set_ringparam(local, tx, rx);
3486}
3487
3488static void ieee80211_get_ringparam(struct wiphy *wiphy,
3489 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
3490{
3491 struct ieee80211_local *local = wiphy_priv(wiphy);
3492
3493 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
3494}
3495
Johannes Bergc68f4b82011-07-05 16:35:41 +02003496static int ieee80211_set_rekey_data(struct wiphy *wiphy,
3497 struct net_device *dev,
3498 struct cfg80211_gtk_rekey_data *data)
3499{
3500 struct ieee80211_local *local = wiphy_priv(wiphy);
3501 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3502
3503 if (!local->ops->set_rekey_data)
3504 return -EOPNOTSUPP;
3505
3506 drv_set_rekey_data(local, sdata, data);
3507
3508 return 0;
3509}
3510
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003511static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
3512{
3513 u8 *pos = (void *)skb_put(skb, 7);
3514
3515 *pos++ = WLAN_EID_EXT_CAPABILITY;
3516 *pos++ = 5; /* len */
3517 *pos++ = 0x0;
3518 *pos++ = 0x0;
3519 *pos++ = 0x0;
3520 *pos++ = 0x0;
3521 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
3522}
3523
3524static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
3525{
3526 struct ieee80211_local *local = sdata->local;
3527 u16 capab;
3528
3529 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003530 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003531 return capab;
3532
3533 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
3534 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
3535 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
3536 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
3537
3538 return capab;
3539}
3540
3541static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
3542 u8 *peer, u8 *bssid)
3543{
3544 struct ieee80211_tdls_lnkie *lnkid;
3545
3546 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
3547
3548 lnkid->ie_type = WLAN_EID_LINK_ID;
3549 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
3550
3551 memcpy(lnkid->bssid, bssid, ETH_ALEN);
3552 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
3553 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
3554}
3555
3556static int
3557ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
3558 u8 *peer, u8 action_code, u8 dialog_token,
3559 u16 status_code, struct sk_buff *skb)
3560{
3561 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003562 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003563 struct ieee80211_tdls_data *tf;
3564
3565 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
3566
3567 memcpy(tf->da, peer, ETH_ALEN);
3568 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
3569 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
3570 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
3571
3572 switch (action_code) {
3573 case WLAN_TDLS_SETUP_REQUEST:
3574 tf->category = WLAN_CATEGORY_TDLS;
3575 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
3576
3577 skb_put(skb, sizeof(tf->u.setup_req));
3578 tf->u.setup_req.dialog_token = dialog_token;
3579 tf->u.setup_req.capability =
3580 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3581
Johannes Berg55de9082012-07-26 17:24:39 +02003582 ieee80211_add_srates_ie(sdata, skb, false, band);
3583 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003584 ieee80211_tdls_add_ext_capab(skb);
3585 break;
3586 case WLAN_TDLS_SETUP_RESPONSE:
3587 tf->category = WLAN_CATEGORY_TDLS;
3588 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
3589
3590 skb_put(skb, sizeof(tf->u.setup_resp));
3591 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
3592 tf->u.setup_resp.dialog_token = dialog_token;
3593 tf->u.setup_resp.capability =
3594 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3595
Johannes Berg55de9082012-07-26 17:24:39 +02003596 ieee80211_add_srates_ie(sdata, skb, false, band);
3597 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003598 ieee80211_tdls_add_ext_capab(skb);
3599 break;
3600 case WLAN_TDLS_SETUP_CONFIRM:
3601 tf->category = WLAN_CATEGORY_TDLS;
3602 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
3603
3604 skb_put(skb, sizeof(tf->u.setup_cfm));
3605 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
3606 tf->u.setup_cfm.dialog_token = dialog_token;
3607 break;
3608 case WLAN_TDLS_TEARDOWN:
3609 tf->category = WLAN_CATEGORY_TDLS;
3610 tf->action_code = WLAN_TDLS_TEARDOWN;
3611
3612 skb_put(skb, sizeof(tf->u.teardown));
3613 tf->u.teardown.reason_code = cpu_to_le16(status_code);
3614 break;
3615 case WLAN_TDLS_DISCOVERY_REQUEST:
3616 tf->category = WLAN_CATEGORY_TDLS;
3617 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
3618
3619 skb_put(skb, sizeof(tf->u.discover_req));
3620 tf->u.discover_req.dialog_token = dialog_token;
3621 break;
3622 default:
3623 return -EINVAL;
3624 }
3625
3626 return 0;
3627}
3628
3629static int
3630ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
3631 u8 *peer, u8 action_code, u8 dialog_token,
3632 u16 status_code, struct sk_buff *skb)
3633{
3634 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02003635 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003636 struct ieee80211_mgmt *mgmt;
3637
3638 mgmt = (void *)skb_put(skb, 24);
3639 memset(mgmt, 0, 24);
3640 memcpy(mgmt->da, peer, ETH_ALEN);
3641 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
3642 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
3643
3644 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
3645 IEEE80211_STYPE_ACTION);
3646
3647 switch (action_code) {
3648 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3649 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
3650 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
3651 mgmt->u.action.u.tdls_discover_resp.action_code =
3652 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
3653 mgmt->u.action.u.tdls_discover_resp.dialog_token =
3654 dialog_token;
3655 mgmt->u.action.u.tdls_discover_resp.capability =
3656 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
3657
Johannes Berg55de9082012-07-26 17:24:39 +02003658 ieee80211_add_srates_ie(sdata, skb, false, band);
3659 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003660 ieee80211_tdls_add_ext_capab(skb);
3661 break;
3662 default:
3663 return -EINVAL;
3664 }
3665
3666 return 0;
3667}
3668
3669static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
3670 u8 *peer, u8 action_code, u8 dialog_token,
Sunil Dutt Undekaridf942e72014-02-20 16:22:09 +05303671 u16 status_code, u32 peer_capability,
3672 const u8 *extra_ies, size_t extra_ies_len)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003673{
3674 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3675 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003676 struct sk_buff *skb = NULL;
3677 bool send_direct;
3678 int ret;
3679
3680 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3681 return -ENOTSUPP;
3682
3683 /* make sure we are in managed mode, and associated */
3684 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
3685 !sdata->u.mgd.associated)
3686 return -EINVAL;
3687
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003688 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
3689 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003690
3691 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
3692 max(sizeof(struct ieee80211_mgmt),
3693 sizeof(struct ieee80211_tdls_data)) +
3694 50 + /* supported rates */
3695 7 + /* ext capab */
3696 extra_ies_len +
3697 sizeof(struct ieee80211_tdls_lnkie));
3698 if (!skb)
3699 return -ENOMEM;
3700
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003701 skb_reserve(skb, local->hw.extra_tx_headroom);
3702
3703 switch (action_code) {
3704 case WLAN_TDLS_SETUP_REQUEST:
3705 case WLAN_TDLS_SETUP_RESPONSE:
3706 case WLAN_TDLS_SETUP_CONFIRM:
3707 case WLAN_TDLS_TEARDOWN:
3708 case WLAN_TDLS_DISCOVERY_REQUEST:
3709 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
3710 action_code, dialog_token,
3711 status_code, skb);
3712 send_direct = false;
3713 break;
3714 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3715 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
3716 dialog_token, status_code,
3717 skb);
3718 send_direct = true;
3719 break;
3720 default:
3721 ret = -ENOTSUPP;
3722 break;
3723 }
3724
3725 if (ret < 0)
3726 goto fail;
3727
3728 if (extra_ies_len)
3729 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
3730
3731 /* the TDLS link IE is always added last */
3732 switch (action_code) {
3733 case WLAN_TDLS_SETUP_REQUEST:
3734 case WLAN_TDLS_SETUP_CONFIRM:
3735 case WLAN_TDLS_TEARDOWN:
3736 case WLAN_TDLS_DISCOVERY_REQUEST:
3737 /* we are the initiator */
3738 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
3739 sdata->u.mgd.bssid);
3740 break;
3741 case WLAN_TDLS_SETUP_RESPONSE:
3742 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
3743 /* we are the responder */
3744 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
3745 sdata->u.mgd.bssid);
3746 break;
3747 default:
3748 ret = -ENOTSUPP;
3749 goto fail;
3750 }
3751
3752 if (send_direct) {
3753 ieee80211_tx_skb(sdata, skb);
3754 return 0;
3755 }
3756
3757 /*
3758 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3759 * we should default to AC_VI.
3760 */
3761 switch (action_code) {
3762 case WLAN_TDLS_SETUP_REQUEST:
3763 case WLAN_TDLS_SETUP_RESPONSE:
3764 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3765 skb->priority = 2;
3766 break;
3767 default:
3768 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3769 skb->priority = 5;
3770 break;
3771 }
3772
3773 /* disable bottom halves when entering the Tx path */
3774 local_bh_disable();
3775 ret = ieee80211_subif_start_xmit(skb, dev);
3776 local_bh_enable();
3777
3778 return ret;
3779
3780fail:
3781 dev_kfree_skb(skb);
3782 return ret;
3783}
3784
3785static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3786 u8 *peer, enum nl80211_tdls_operation oper)
3787{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003788 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003789 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3790
3791 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3792 return -ENOTSUPP;
3793
3794 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3795 return -EINVAL;
3796
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003797 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003798
3799 switch (oper) {
3800 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003801 rcu_read_lock();
3802 sta = sta_info_get(sdata, peer);
3803 if (!sta) {
3804 rcu_read_unlock();
3805 return -ENOLINK;
3806 }
3807
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003808 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003809 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003810 break;
3811 case NL80211_TDLS_DISABLE_LINK:
3812 return sta_info_destroy_addr(sdata, peer);
3813 case NL80211_TDLS_TEARDOWN:
3814 case NL80211_TDLS_SETUP:
3815 case NL80211_TDLS_DISCOVERY_REQ:
3816 /* We don't support in-driver setup/teardown/discovery */
3817 return -ENOTSUPP;
3818 default:
3819 return -ENOTSUPP;
3820 }
3821
3822 return 0;
3823}
3824
Johannes Berg06500732011-11-04 11:18:16 +01003825static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3826 const u8 *peer, u64 *cookie)
3827{
3828 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3829 struct ieee80211_local *local = sdata->local;
3830 struct ieee80211_qos_hdr *nullfunc;
3831 struct sk_buff *skb;
3832 int size = sizeof(*nullfunc);
3833 __le16 fc;
3834 bool qos;
3835 struct ieee80211_tx_info *info;
3836 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003837 struct ieee80211_chanctx_conf *chanctx_conf;
3838 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003839
3840 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003841 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3842 if (WARN_ON(!chanctx_conf)) {
3843 rcu_read_unlock();
3844 return -EINVAL;
3845 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003846 band = chanctx_conf->def.chan->band;
Felix Fietkau03bb7f42013-09-29 21:39:33 +02003847 sta = sta_info_get_bss(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003848 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003849 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003850 } else {
3851 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003852 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003853 }
Johannes Berg06500732011-11-04 11:18:16 +01003854
3855 if (qos) {
3856 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3857 IEEE80211_STYPE_QOS_NULLFUNC |
3858 IEEE80211_FCTL_FROMDS);
3859 } else {
3860 size -= 2;
3861 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3862 IEEE80211_STYPE_NULLFUNC |
3863 IEEE80211_FCTL_FROMDS);
3864 }
3865
3866 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003867 if (!skb) {
3868 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003869 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003870 }
Johannes Berg06500732011-11-04 11:18:16 +01003871
3872 skb->dev = dev;
3873
3874 skb_reserve(skb, local->hw.extra_tx_headroom);
3875
3876 nullfunc = (void *) skb_put(skb, size);
3877 nullfunc->frame_control = fc;
3878 nullfunc->duration_id = 0;
3879 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3880 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3881 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3882 nullfunc->seq_ctrl = 0;
3883
3884 info = IEEE80211_SKB_CB(skb);
3885
3886 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3887 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3888
3889 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3890 skb->priority = 7;
3891 if (qos)
3892 nullfunc->qos_ctrl = cpu_to_le16(7);
3893
3894 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003895 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003896 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003897 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003898
3899 *cookie = (unsigned long) skb;
3900 return 0;
3901}
3902
Johannes Berg683b6d32012-11-08 21:25:48 +01003903static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3904 struct wireless_dev *wdev,
3905 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003906{
Johannes Berg55de9082012-07-26 17:24:39 +02003907 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Felix Fietkaucb601ff2013-02-23 19:02:14 +01003908 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg55de9082012-07-26 17:24:39 +02003909 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003910 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003911
Johannes Berg55de9082012-07-26 17:24:39 +02003912 rcu_read_lock();
Johannes Bergfeda3022013-02-28 09:59:22 +01003913 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3914 if (chanctx_conf) {
3915 *chandef = chanctx_conf->def;
3916 ret = 0;
3917 } else if (local->open_count > 0 &&
3918 local->open_count == local->monitors &&
3919 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
3920 if (local->use_chanctx)
3921 *chandef = local->monitor_chandef;
3922 else
Karl Beldan675a0b02013-03-25 16:26:57 +01003923 *chandef = local->_oper_chandef;
Johannes Berg683b6d32012-11-08 21:25:48 +01003924 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003925 }
3926 rcu_read_unlock();
3927
Johannes Berg683b6d32012-11-08 21:25:48 +01003928 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003929}
3930
Johannes Berg6d525632012-04-04 15:05:25 +02003931#ifdef CONFIG_PM
3932static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3933{
3934 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3935}
3936#endif
3937
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003938static int ieee80211_set_qos_map(struct wiphy *wiphy,
3939 struct net_device *dev,
3940 struct cfg80211_qos_map *qos_map)
3941{
3942 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3943 struct mac80211_qos_map *new_qos_map, *old_qos_map;
3944
3945 if (qos_map) {
3946 new_qos_map = kzalloc(sizeof(*new_qos_map), GFP_KERNEL);
3947 if (!new_qos_map)
3948 return -ENOMEM;
3949 memcpy(&new_qos_map->qos_map, qos_map, sizeof(*qos_map));
3950 } else {
3951 /* A NULL qos_map was passed to disable QoS mapping */
3952 new_qos_map = NULL;
3953 }
3954
Johannes Berg194ff522013-12-30 23:12:37 +01003955 old_qos_map = sdata_dereference(sdata->qos_map, sdata);
Kyeyoon Park32db6b52013-12-16 23:04:43 -08003956 rcu_assign_pointer(sdata->qos_map, new_qos_map);
3957 if (old_qos_map)
3958 kfree_rcu(old_qos_map, rcu_head);
3959
3960 return 0;
3961}
3962
Jouni Malinen3b1700b2014-04-28 11:22:25 +03003963static int ieee80211_set_ap_chanwidth(struct wiphy *wiphy,
3964 struct net_device *dev,
3965 struct cfg80211_chan_def *chandef)
3966{
3967 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3968 int ret;
3969 u32 changed = 0;
3970
3971 ret = ieee80211_vif_change_bandwidth(sdata, chandef, &changed);
3972 if (ret == 0)
3973 ieee80211_bss_info_change_notify(sdata, changed);
3974
3975 return ret;
3976}
3977
Johannes Berg8a47cea2014-01-20 23:55:44 +01003978const struct cfg80211_ops mac80211_config_ops = {
Jiri Bencf0706e82007-05-05 11:45:53 -07003979 .add_virtual_intf = ieee80211_add_iface,
3980 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003981 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003982 .start_p2p_device = ieee80211_start_p2p_device,
3983 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003984 .add_key = ieee80211_add_key,
3985 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003986 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003987 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003988 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003989 .start_ap = ieee80211_start_ap,
3990 .change_beacon = ieee80211_change_beacon,
3991 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003992 .add_station = ieee80211_add_station,
3993 .del_station = ieee80211_del_station,
3994 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003995 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003996 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003997 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003998#ifdef CONFIG_MAC80211_MESH
3999 .add_mpath = ieee80211_add_mpath,
4000 .del_mpath = ieee80211_del_mpath,
4001 .change_mpath = ieee80211_change_mpath,
4002 .get_mpath = ieee80211_get_mpath,
4003 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08004004 .update_mesh_config = ieee80211_update_mesh_config,
4005 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01004006 .join_mesh = ieee80211_join_mesh,
4007 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01004008#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03004009 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02004010 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02004011 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05004012 .suspend = ieee80211_suspend,
4013 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01004014 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03004015 .sched_scan_start = ieee80211_sched_scan_start,
4016 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02004017 .auth = ieee80211_auth,
4018 .assoc = ieee80211_assoc,
4019 .deauth = ieee80211_deauth,
4020 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02004021 .join_ibss = ieee80211_join_ibss,
4022 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01004023 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02004024 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02004025 .set_tx_power = ieee80211_set_tx_power,
4026 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02004027 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02004028 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02004029 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07004030 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02004031 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02004032 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01004033 .remain_on_channel = ieee80211_remain_on_channel,
4034 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f782010-08-12 15:38:38 +02004035 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01004036 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02004037 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02004038 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09004039 .set_antenna = ieee80211_set_antenna,
4040 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05004041 .set_ringparam = ieee80211_set_ringparam,
4042 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02004043 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03004044 .tdls_oper = ieee80211_tdls_oper,
4045 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01004046 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01004047 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02004048#ifdef CONFIG_PM
4049 .set_wakeup = ieee80211_set_wakeup,
4050#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07004051 .get_et_sset_count = ieee80211_get_et_sset_count,
4052 .get_et_stats = ieee80211_get_et_stats,
4053 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02004054 .get_channel = ieee80211_cfg_get_channel,
Simon Wunderlich164eb022013-02-08 18:16:20 +01004055 .start_radar_detection = ieee80211_start_radar_detection,
Simon Wunderlich73da7d52013-07-11 16:09:06 +02004056 .channel_switch = ieee80211_channel_switch,
Kyeyoon Park32db6b52013-12-16 23:04:43 -08004057 .set_qos_map = ieee80211_set_qos_map,
Jouni Malinen3b1700b2014-04-28 11:22:25 +03004058 .set_ap_chanwidth = ieee80211_set_ap_chanwidth,
Jiri Bencf0706e82007-05-05 11:45:53 -07004059};