blob: 97cf615eb36ade8340794dc0d00af900c61260ab [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg552bff02012-09-19 09:26:06 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
24 const char *name,
Johannes Berg84efbb82012-06-16 00:00:26 +020025 enum nl80211_iftype type,
26 u32 *flags,
27 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070028{
29 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020030 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010031 struct ieee80211_sub_if_data *sdata;
32 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070033
Johannes Berg84efbb82012-06-16 00:00:26 +020034 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010035 if (err)
36 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010037
Johannes Bergf9e10ce2010-12-03 09:20:42 +010038 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020039 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010040 sdata->u.mntr_flags = *flags;
41 }
42
Johannes Berg84efbb82012-06-16 00:00:26 +020043 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070044}
45
Johannes Berg84efbb82012-06-16 00:00:26 +020046static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070047{
Johannes Berg84efbb82012-06-16 00:00:26 +020048 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070049
Johannes Berg75636522008-07-09 14:40:35 +020050 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070051}
52
Johannes Berge36d56b2009-06-09 21:04:43 +020053static int ieee80211_change_iface(struct wiphy *wiphy,
54 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010055 enum nl80211_iftype type, u32 *flags,
56 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020057{
Johannes Berg9607e6b2009-12-23 13:15:31 +010058 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020060
Johannes Berg05c914f2008-09-11 00:01:58 +020061 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020062 if (ret)
63 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020064
Johannes Berg9bc383d2009-11-19 11:55:19 +010065 if (type == NL80211_IFTYPE_AP_VLAN &&
66 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000067 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010068 else if (type == NL80211_IFTYPE_STATION &&
69 params && params->use_4addr >= 0)
70 sdata->u.mgd.use_4addr = params->use_4addr;
71
Christian Lamparter85416a42010-10-02 13:17:07 +020072 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
73 struct ieee80211_local *local = sdata->local;
74
75 if (ieee80211_sdata_running(sdata)) {
76 /*
77 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
78 * changed while the interface is up.
79 * Else we would need to add a lot of cruft
80 * to update everything:
81 * cooked_mntrs, monitor and all fif_* counters
82 * reconfigure hardware
83 */
84 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
85 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
86 return -EBUSY;
87
88 ieee80211_adjust_monitor_flags(sdata, -1);
89 sdata->u.mntr_flags = *flags;
90 ieee80211_adjust_monitor_flags(sdata, 1);
91
92 ieee80211_configure_filter(local);
93 } else {
94 /*
95 * Because the interface is down, ieee80211_do_stop
96 * and ieee80211_do_open take care of "everything"
97 * mentioned in the comment above.
98 */
99 sdata->u.mntr_flags = *flags;
100 }
101 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200102
Johannes Berg42613db2007-09-28 21:52:27 +0200103 return 0;
104}
105
Johannes Bergf142c6b2012-06-18 20:07:15 +0200106static int ieee80211_start_p2p_device(struct wiphy *wiphy,
107 struct wireless_dev *wdev)
108{
109 return ieee80211_do_open(wdev, true);
110}
111
112static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
113 struct wireless_dev *wdev)
114{
115 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
116}
117
Simon Wunderlichb53be792011-11-18 14:20:44 +0100118static int ieee80211_set_noack_map(struct wiphy *wiphy,
119 struct net_device *dev,
120 u16 noack_map)
121{
122 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
123
124 sdata->noack_map = noack_map;
125 return 0;
126}
127
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100128static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200129 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100130 struct key_params *params)
131{
Johannes Berg26a58452010-08-27 12:35:55 +0200132 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100133 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100134 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200135 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100136
Johannes Berg26a58452010-08-27 12:35:55 +0200137 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200138 return -ENETDOWN;
139
Johannes Berg97359d12010-08-10 09:46:38 +0200140 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100141 switch (params->cipher) {
142 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100143 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200144 case WLAN_CIPHER_SUITE_WEP104:
145 if (IS_ERR(sdata->local->wep_tx_tfm))
146 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200147 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100148 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200149 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100150 }
151
Johannes Berg97359d12010-08-10 09:46:38 +0200152 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
153 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100154 if (IS_ERR(key))
155 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100156
Johannes Berge31b8212010-10-05 19:39:30 +0200157 if (pairwise)
158 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
159
Johannes Bergad0e2b52010-06-01 10:19:19 +0200160 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200161
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100162 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700163 if (ieee80211_vif_is_mesh(&sdata->vif))
164 sta = sta_info_get(sdata, mac_addr);
165 else
166 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100167 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700168 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200169 err = -ENOENT;
170 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100171 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100172 }
173
Johannes Berge548c492012-09-04 17:08:23 +0200174 switch (sdata->vif.type) {
175 case NL80211_IFTYPE_STATION:
176 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
177 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
178 break;
179 case NL80211_IFTYPE_AP:
180 case NL80211_IFTYPE_AP_VLAN:
181 /* Keys without a station are used for TX only */
182 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
183 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
184 break;
185 case NL80211_IFTYPE_ADHOC:
186 /* no MFP (yet) */
187 break;
188 case NL80211_IFTYPE_MESH_POINT:
189#ifdef CONFIG_MAC80211_MESH
190 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
191 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
192 break;
193#endif
194 case NL80211_IFTYPE_WDS:
195 case NL80211_IFTYPE_MONITOR:
196 case NL80211_IFTYPE_P2P_DEVICE:
197 case NL80211_IFTYPE_UNSPECIFIED:
198 case NUM_NL80211_IFTYPES:
199 case NL80211_IFTYPE_P2P_CLIENT:
200 case NL80211_IFTYPE_P2P_GO:
201 /* shouldn't happen */
202 WARN_ON_ONCE(1);
203 break;
204 }
205
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300206 err = ieee80211_key_link(key, sdata, sta);
207 if (err)
208 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100209
Johannes Berg3b967662008-04-08 17:56:52 +0200210 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200211 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200212
213 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100214}
215
216static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200217 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100218{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200219 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
220 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100221 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200222 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100223 int ret;
224
Johannes Berg5c0c3642011-05-12 14:31:49 +0200225 mutex_lock(&local->sta_mtx);
226 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200227
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100228 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200229 ret = -ENOENT;
230
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100231 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100232 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200233 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100234
Johannes Berg5c0c3642011-05-12 14:31:49 +0200235 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200236 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200237 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200238 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200239 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200240 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100241
Johannes Berg5c0c3642011-05-12 14:31:49 +0200242 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200243 ret = -ENOENT;
244 goto out_unlock;
245 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100246
Johannes Berg5c0c3642011-05-12 14:31:49 +0200247 __ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100248
Johannes Berg3b967662008-04-08 17:56:52 +0200249 ret = 0;
250 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200251 mutex_unlock(&local->key_mtx);
252 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200253
254 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100255}
256
Johannes Berg62da92f2007-12-19 02:03:31 +0100257static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200258 u8 key_idx, bool pairwise, const u8 *mac_addr,
259 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100260 void (*callback)(void *cookie,
261 struct key_params *params))
262{
Johannes Berg14db74b2008-07-29 13:22:52 +0200263 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100264 struct sta_info *sta = NULL;
265 u8 seq[6] = {0};
266 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200267 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200268 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100269 u32 iv32;
270 u16 iv16;
271 int err = -ENOENT;
272
Johannes Berg14db74b2008-07-29 13:22:52 +0200273 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
274
Johannes Berg3b967662008-04-08 17:56:52 +0200275 rcu_read_lock();
276
Johannes Berg62da92f2007-12-19 02:03:31 +0100277 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100278 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100279 if (!sta)
280 goto out;
281
Johannes Berge31b8212010-10-05 19:39:30 +0200282 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200283 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200284 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200285 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100286 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200287 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100288
289 if (!key)
290 goto out;
291
292 memset(&params, 0, sizeof(params));
293
Johannes Berg97359d12010-08-10 09:46:38 +0200294 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100295
Johannes Berg97359d12010-08-10 09:46:38 +0200296 switch (key->conf.cipher) {
297 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700298 iv32 = key->u.tkip.tx.iv32;
299 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100300
Johannes Berg24487982009-04-23 18:52:52 +0200301 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
302 drv_get_tkip_seq(sdata->local,
303 key->conf.hw_key_idx,
304 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100305
306 seq[0] = iv16 & 0xff;
307 seq[1] = (iv16 >> 8) & 0xff;
308 seq[2] = iv32 & 0xff;
309 seq[3] = (iv32 >> 8) & 0xff;
310 seq[4] = (iv32 >> 16) & 0xff;
311 seq[5] = (iv32 >> 24) & 0xff;
312 params.seq = seq;
313 params.seq_len = 6;
314 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200315 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200316 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
317 seq[0] = pn64;
318 seq[1] = pn64 >> 8;
319 seq[2] = pn64 >> 16;
320 seq[3] = pn64 >> 24;
321 seq[4] = pn64 >> 32;
322 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100323 params.seq = seq;
324 params.seq_len = 6;
325 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200326 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200327 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
328 seq[0] = pn64;
329 seq[1] = pn64 >> 8;
330 seq[2] = pn64 >> 16;
331 seq[3] = pn64 >> 24;
332 seq[4] = pn64 >> 32;
333 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200334 params.seq = seq;
335 params.seq_len = 6;
336 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100337 }
338
339 params.key = key->conf.key;
340 params.key_len = key->conf.keylen;
341
342 callback(cookie, &params);
343 err = 0;
344
345 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200346 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100347 return err;
348}
349
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100350static int ieee80211_config_default_key(struct wiphy *wiphy,
351 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100352 u8 key_idx, bool uni,
353 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100354{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200355 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100356
Johannes Bergf7e01042010-12-09 19:49:02 +0100357 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100358
359 return 0;
360}
361
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200362static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
363 struct net_device *dev,
364 u8 key_idx)
365{
Johannes Berg66c52422010-07-22 13:58:51 +0200366 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200367
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200368 ieee80211_set_default_mgmt_key(sdata, key_idx);
369
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200370 return 0;
371}
372
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800373void sta_set_rate_info_tx(struct sta_info *sta,
374 const struct ieee80211_tx_rate *rate,
375 struct rate_info *rinfo)
376{
377 rinfo->flags = 0;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100378 if (rate->flags & IEEE80211_TX_RC_MCS) {
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800379 rinfo->flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100380 rinfo->mcs = rate->idx;
381 } else if (rate->flags & IEEE80211_TX_RC_VHT_MCS) {
382 rinfo->flags |= RATE_INFO_FLAGS_VHT_MCS;
383 rinfo->mcs = ieee80211_rate_get_vht_mcs(rate);
384 rinfo->nss = ieee80211_rate_get_vht_nss(rate);
385 } else {
386 struct ieee80211_supported_band *sband;
387 sband = sta->local->hw.wiphy->bands[
388 ieee80211_get_sdata_band(sta->sdata)];
389 rinfo->legacy = sband->bitrates[rate->idx].bitrate;
390 }
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800391 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
392 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
Johannes Berg8bc83c22012-11-09 18:38:32 +0100393 if (rate->flags & IEEE80211_TX_RC_80_MHZ_WIDTH)
394 rinfo->flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
395 if (rate->flags & IEEE80211_TX_RC_160_MHZ_WIDTH)
396 rinfo->flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800397 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
398 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800399}
400
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100401static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
402{
Johannes Bergd0709a62008-02-25 16:27:46 +0100403 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300404 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530405 struct timespec uptime;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100406
Johannes Bergf5ea9122009-08-07 16:17:38 +0200407 sinfo->generation = sdata->local->sta_generation;
408
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100409 sinfo->filled = STATION_INFO_INACTIVE_TIME |
410 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100411 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200412 STATION_INFO_RX_PACKETS |
413 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900414 STATION_INFO_TX_RETRIES |
415 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700416 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100417 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700418 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530419 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200420 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800421 STATION_INFO_STA_FLAGS |
422 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530423
424 do_posix_clock_monotonic_gettime(&uptime);
425 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100426
427 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
428 sinfo->rx_bytes = sta->rx_bytes;
429 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200430 sinfo->rx_packets = sta->rx_packets;
431 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900432 sinfo->tx_retries = sta->tx_retry_count;
433 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700434 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800435 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100436
John W. Linville19deffb2009-12-08 17:10:13 -0500437 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
438 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900439 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300440 if (!local->ops->get_rssi ||
441 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
442 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900443 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100444 }
445
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800446 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100447
Felix Fietkau3af63342011-02-27 22:08:01 +0100448 sinfo->rxrate.flags = 0;
Johannes Berg56146182012-11-09 15:07:02 +0100449 if (sta->last_rx_rate_flag & RX_FLAG_HT) {
Felix Fietkau3af63342011-02-27 22:08:01 +0100450 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
Johannes Berg56146182012-11-09 15:07:02 +0100451 sinfo->rxrate.mcs = sta->last_rx_rate_idx;
452 } else if (sta->last_rx_rate_flag & RX_FLAG_VHT) {
453 sinfo->rxrate.flags |= RATE_INFO_FLAGS_VHT_MCS;
454 sinfo->rxrate.nss = sta->last_rx_rate_vht_nss;
455 sinfo->rxrate.mcs = sta->last_rx_rate_idx;
456 } else {
457 struct ieee80211_supported_band *sband;
458
459 sband = sta->local->hw.wiphy->bands[
460 ieee80211_get_sdata_band(sta->sdata)];
461 sinfo->rxrate.legacy =
462 sband->bitrates[sta->last_rx_rate_idx].bitrate;
463 }
464
Felix Fietkau3af63342011-02-27 22:08:01 +0100465 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
466 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
467 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
468 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
Johannes Berg56146182012-11-09 15:07:02 +0100469 if (sta->last_rx_rate_flag & RX_FLAG_80MHZ)
470 sinfo->rxrate.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
471 if (sta->last_rx_rate_flag & RX_FLAG_80P80MHZ)
472 sinfo->rxrate.flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
473 if (sta->last_rx_rate_flag & RX_FLAG_160MHZ)
474 sinfo->rxrate.flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
Henning Rogge420e7fa2008-12-11 22:04:19 +0100475
Johannes Berg902acc72008-02-23 15:17:19 +0100476 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100477#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100478 sinfo->filled |= STATION_INFO_LLID |
479 STATION_INFO_PLID |
480 STATION_INFO_PLINK_STATE;
481
482 sinfo->llid = le16_to_cpu(sta->llid);
483 sinfo->plid = le16_to_cpu(sta->plid);
484 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700485 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
486 sinfo->filled |= STATION_INFO_T_OFFSET;
487 sinfo->t_offset = sta->t_offset;
488 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100489#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100490 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700491
492 sinfo->bss_param.flags = 0;
493 if (sdata->vif.bss_conf.use_cts_prot)
494 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
495 if (sdata->vif.bss_conf.use_short_preamble)
496 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
497 if (sdata->vif.bss_conf.use_short_slot)
498 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
499 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
500 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200501
502 sinfo->sta_flags.set = 0;
503 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
504 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
505 BIT(NL80211_STA_FLAG_WME) |
506 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100507 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
508 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200509 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
510 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
511 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
512 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
513 if (test_sta_flag(sta, WLAN_STA_WME))
514 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
515 if (test_sta_flag(sta, WLAN_STA_MFP))
516 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
517 if (test_sta_flag(sta, WLAN_STA_AUTH))
518 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100519 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
520 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100521}
522
Ben Greearb1ab7922012-04-23 12:50:30 -0700523static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
524 "rx_packets", "rx_bytes", "wep_weak_iv_count",
525 "rx_duplicates", "rx_fragments", "rx_dropped",
526 "tx_packets", "tx_bytes", "tx_fragments",
527 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700528 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
529 "channel", "noise", "ch_time", "ch_time_busy",
530 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700531};
532#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
533
534static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
535 struct net_device *dev,
536 int sset)
537{
Ben Greeare3521142012-04-23 12:50:31 -0700538 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
539 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700540
Ben Greeare3521142012-04-23 12:50:31 -0700541 if (sset == ETH_SS_STATS)
542 rv += STA_STATS_LEN;
543
544 rv += drv_get_et_sset_count(sdata, sset);
545
546 if (rv == 0)
547 return -EOPNOTSUPP;
548 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700549}
550
551static void ieee80211_get_et_stats(struct wiphy *wiphy,
552 struct net_device *dev,
553 struct ethtool_stats *stats,
554 u64 *data)
555{
556 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +0200557 struct ieee80211_chanctx_conf *chanctx_conf;
558 struct ieee80211_channel *channel;
Ben Greearb1ab7922012-04-23 12:50:30 -0700559 struct sta_info *sta;
560 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700561 struct station_info sinfo;
562 struct survey_info survey;
563 int i, q;
564#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700565
566 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
567
568#define ADD_STA_STATS(sta) \
569 do { \
570 data[i++] += sta->rx_packets; \
571 data[i++] += sta->rx_bytes; \
572 data[i++] += sta->wep_weak_iv_count; \
573 data[i++] += sta->num_duplicates; \
574 data[i++] += sta->rx_fragments; \
575 data[i++] += sta->rx_dropped; \
576 \
577 data[i++] += sta->tx_packets; \
578 data[i++] += sta->tx_bytes; \
579 data[i++] += sta->tx_fragments; \
580 data[i++] += sta->tx_filtered_count; \
581 data[i++] += sta->tx_retry_failed; \
582 data[i++] += sta->tx_retry_count; \
583 data[i++] += sta->beacon_loss_count; \
584 } while (0)
585
586 /* For Managed stations, find the single station based on BSSID
587 * and use that. For interface types, iterate through all available
588 * stations and add stats for any station that is assigned to this
589 * network device.
590 */
591
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300592 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700593
594 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
595 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700596
597 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
598 goto do_survey;
599
600 i = 0;
601 ADD_STA_STATS(sta);
602
603 data[i++] = sta->sta_state;
604
605 sinfo.filled = 0;
606 sta_set_sinfo(sta, &sinfo);
607
Joe Perches52042672012-05-30 13:25:54 -0700608 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700609 data[i] = 100000 *
610 cfg80211_calculate_bitrate(&sinfo.txrate);
611 i++;
Joe Perches52042672012-05-30 13:25:54 -0700612 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700613 data[i] = 100000 *
614 cfg80211_calculate_bitrate(&sinfo.rxrate);
615 i++;
616
Joe Perches52042672012-05-30 13:25:54 -0700617 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700618 data[i] = (u8)sinfo.signal_avg;
619 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700620 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300621 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700622 /* Make sure this station belongs to the proper dev */
623 if (sta->sdata->dev != dev)
624 continue;
625
626 i = 0;
627 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700628 }
629 }
630
Ben Greear3073a7c2012-04-23 12:50:32 -0700631do_survey:
632 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
633 /* Get survey stats for current channel */
Johannes Berg55de9082012-07-26 17:24:39 +0200634 survey.filled = 0;
Ben Greear3073a7c2012-04-23 12:50:32 -0700635
Johannes Berg55de9082012-07-26 17:24:39 +0200636 rcu_read_lock();
637 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
638 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +0100639 channel = chanctx_conf->def.chan;
Johannes Berg55de9082012-07-26 17:24:39 +0200640 else
641 channel = NULL;
642 rcu_read_unlock();
643
644 if (channel) {
645 q = 0;
646 do {
647 survey.filled = 0;
648 if (drv_get_survey(local, q, &survey) != 0) {
649 survey.filled = 0;
650 break;
651 }
652 q++;
653 } while (channel != survey.channel);
Ben Greear3073a7c2012-04-23 12:50:32 -0700654 }
655
656 if (survey.filled)
657 data[i++] = survey.channel->center_freq;
658 else
659 data[i++] = 0;
660 if (survey.filled & SURVEY_INFO_NOISE_DBM)
661 data[i++] = (u8)survey.noise;
662 else
663 data[i++] = -1LL;
664 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
665 data[i++] = survey.channel_time;
666 else
667 data[i++] = -1LL;
668 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
669 data[i++] = survey.channel_time_busy;
670 else
671 data[i++] = -1LL;
672 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
673 data[i++] = survey.channel_time_ext_busy;
674 else
675 data[i++] = -1LL;
676 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
677 data[i++] = survey.channel_time_rx;
678 else
679 data[i++] = -1LL;
680 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
681 data[i++] = survey.channel_time_tx;
682 else
683 data[i++] = -1LL;
684
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300685 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700686
Ben Greear3073a7c2012-04-23 12:50:32 -0700687 if (WARN_ON(i != STA_STATS_LEN))
688 return;
689
Ben Greeare3521142012-04-23 12:50:31 -0700690 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700691}
692
693static void ieee80211_get_et_strings(struct wiphy *wiphy,
694 struct net_device *dev,
695 u32 sset, u8 *data)
696{
Ben Greeare3521142012-04-23 12:50:31 -0700697 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
698 int sz_sta_stats = 0;
699
Ben Greearb1ab7922012-04-23 12:50:30 -0700700 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700701 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700702 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
703 }
Ben Greeare3521142012-04-23 12:50:31 -0700704 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700705}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100706
707static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
708 int idx, u8 *mac, struct station_info *sinfo)
709{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100710 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300711 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100712 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100713 int ret = -ENOENT;
714
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300715 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100716
Johannes Berg3b53fde82009-11-16 12:00:37 +0100717 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100718 if (sta) {
719 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200720 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100721 sta_set_sinfo(sta, sinfo);
722 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100723
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300724 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100725
Johannes Bergd0709a62008-02-25 16:27:46 +0100726 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100727}
728
Holger Schurig12897232010-04-19 10:23:57 +0200729static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
730 int idx, struct survey_info *survey)
731{
732 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
733
Holger Schurig12897232010-04-19 10:23:57 +0200734 return drv_get_survey(local, idx, survey);
735}
736
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100737static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100738 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100739{
Johannes Bergabe60632009-11-25 17:46:18 +0100740 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300741 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100742 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100743 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100744
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300745 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100746
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100747 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100748 if (sta) {
749 ret = 0;
750 sta_set_sinfo(sta, sinfo);
751 }
752
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300753 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100754
755 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100756}
757
Johannes Berge8c9bd52012-06-06 08:18:22 +0200758static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
Johannes Berg683b6d32012-11-08 21:25:48 +0100759 struct cfg80211_chan_def *chandef)
Johannes Berge8c9bd52012-06-06 08:18:22 +0200760{
Johannes Berg55de9082012-07-26 17:24:39 +0200761 struct ieee80211_local *local = wiphy_priv(wiphy);
762 struct ieee80211_sub_if_data *sdata;
763 int ret = 0;
764
Johannes Berg4bf88532012-11-09 11:39:59 +0100765 if (cfg80211_chandef_identical(&local->monitor_chandef, chandef))
Johannes Berg55de9082012-07-26 17:24:39 +0200766 return 0;
767
768 mutex_lock(&local->iflist_mtx);
769 if (local->use_chanctx) {
770 sdata = rcu_dereference_protected(
771 local->monitor_sdata,
772 lockdep_is_held(&local->iflist_mtx));
773 if (sdata) {
774 ieee80211_vif_release_channel(sdata);
Johannes Berg4bf88532012-11-09 11:39:59 +0100775 ret = ieee80211_vif_use_channel(sdata, chandef,
Johannes Berg55de9082012-07-26 17:24:39 +0200776 IEEE80211_CHANCTX_EXCLUSIVE);
777 }
778 } else if (local->open_count == local->monitors) {
Johannes Berg683b6d32012-11-08 21:25:48 +0100779 local->_oper_channel = chandef->chan;
Johannes Berg4bf88532012-11-09 11:39:59 +0100780 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
Johannes Berg55de9082012-07-26 17:24:39 +0200781 ieee80211_hw_config(local, 0);
782 }
783
Johannes Berg4bf88532012-11-09 11:39:59 +0100784 if (ret == 0)
785 local->monitor_chandef = *chandef;
Johannes Berg55de9082012-07-26 17:24:39 +0200786 mutex_unlock(&local->iflist_mtx);
787
788 return ret;
Johannes Berge8c9bd52012-06-06 08:18:22 +0200789}
790
Arik Nemtsov02945822011-11-10 11:28:57 +0200791static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100792 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200793{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300794 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200795
796 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530797 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200798
Arik Nemtsovf7248282011-11-19 10:51:26 +0200799 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200800
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300801 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200802 if (!new)
803 return -ENOMEM;
804
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300805 new->len = resp_len;
806 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200807
808 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300809 if (old)
810 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200811
812 return 0;
813}
814
Johannes Berg88600202012-02-13 15:17:18 +0100815static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
816 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100817{
818 struct beacon_data *new, *old;
819 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100820 int size, err;
821 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100822
Johannes Berg40b275b2011-05-13 14:15:49 +0200823 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100824
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100825 /* Need to have a beacon head if we don't have one yet */
826 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100827 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100828
829 /* new or old head? */
830 if (params->head)
831 new_head_len = params->head_len;
832 else
833 new_head_len = old->head_len;
834
835 /* new or old tail? */
836 if (params->tail || !old)
837 /* params->tail_len will be zero for !params->tail */
838 new_tail_len = params->tail_len;
839 else
840 new_tail_len = old->tail_len;
841
842 size = sizeof(*new) + new_head_len + new_tail_len;
843
844 new = kzalloc(size, GFP_KERNEL);
845 if (!new)
846 return -ENOMEM;
847
848 /* start filling the new info now */
849
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100850 /*
851 * pointers go into the block we allocated,
852 * memory is | beacon_data | head | tail |
853 */
854 new->head = ((u8 *) new) + sizeof(*new);
855 new->tail = new->head + new_head_len;
856 new->head_len = new_head_len;
857 new->tail_len = new_tail_len;
858
859 /* copy in head */
860 if (params->head)
861 memcpy(new->head, params->head, new_head_len);
862 else
863 memcpy(new->head, old->head, new_head_len);
864
865 /* copy in optional tail */
866 if (params->tail)
867 memcpy(new->tail, params->tail, new_tail_len);
868 else
869 if (old)
870 memcpy(new->tail, old->tail, new_tail_len);
871
Johannes Berg88600202012-02-13 15:17:18 +0100872 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
873 params->probe_resp_len);
874 if (err < 0)
875 return err;
876 if (err == 0)
877 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100878
Eric Dumazetcf778b02012-01-12 04:41:32 +0000879 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100880
Johannes Berg88600202012-02-13 15:17:18 +0100881 if (old)
882 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100883
Johannes Berg88600202012-02-13 15:17:18 +0100884 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100885}
886
Johannes Berg88600202012-02-13 15:17:18 +0100887static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
888 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100889{
Johannes Berg88600202012-02-13 15:17:18 +0100890 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100891 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100892 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100893 u32 changed = BSS_CHANGED_BEACON_INT |
894 BSS_CHANGED_BEACON_ENABLED |
895 BSS_CHANGED_BEACON |
Johannes Berg339afbf2012-11-14 15:21:17 +0100896 BSS_CHANGED_SSID |
897 BSS_CHANGED_P2P_PS;
Johannes Berg88600202012-02-13 15:17:18 +0100898 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200899
Johannes Berg40b275b2011-05-13 14:15:49 +0200900 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100901 if (old)
902 return -EALREADY;
903
Johannes Berg04ecd252012-09-11 14:34:12 +0200904 /* TODO: make hostapd tell us what it wants */
905 sdata->smps_mode = IEEE80211_SMPS_OFF;
906 sdata->needed_rx_chains = sdata->local->rx_chains;
907
Johannes Berg4bf88532012-11-09 11:39:59 +0100908 err = ieee80211_vif_use_channel(sdata, &params->chandef,
909 IEEE80211_CHANCTX_SHARED);
Johannes Bergaa430da2012-05-16 23:50:18 +0200910 if (err)
911 return err;
912
Johannes Berg665c93a2011-11-04 11:18:11 +0100913 /*
914 * Apply control port protocol, this allows us to
915 * not encrypt dynamic WEP control frames.
916 */
917 sdata->control_port_protocol = params->crypto.control_port_ethertype;
918 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
919 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
920 vlan->control_port_protocol =
921 params->crypto.control_port_ethertype;
922 vlan->control_port_no_encrypt =
923 params->crypto.control_port_no_encrypt;
924 }
925
Johannes Berg88600202012-02-13 15:17:18 +0100926 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
927 sdata->vif.bss_conf.dtim_period = params->dtim_period;
928
929 sdata->vif.bss_conf.ssid_len = params->ssid_len;
930 if (params->ssid_len)
931 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
932 params->ssid_len);
933 sdata->vif.bss_conf.hidden_ssid =
934 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
935
Johannes Berg339afbf2012-11-14 15:21:17 +0100936 sdata->vif.bss_conf.p2p_ctwindow = params->p2p_ctwindow;
937 sdata->vif.bss_conf.p2p_oppps = params->p2p_opp_ps;
938
Johannes Berg88600202012-02-13 15:17:18 +0100939 err = ieee80211_assign_beacon(sdata, &params->beacon);
940 if (err < 0)
941 return err;
942 changed |= err;
943
Johannes Berg10416382012-10-19 15:44:42 +0200944 err = drv_start_ap(sdata->local, sdata);
945 if (err) {
946 old = rtnl_dereference(sdata->u.ap.beacon);
947 if (old)
948 kfree_rcu(old, rcu_head);
949 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
950 return err;
951 }
952
Johannes Berg88600202012-02-13 15:17:18 +0100953 ieee80211_bss_info_change_notify(sdata, changed);
954
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200955 netif_carrier_on(dev);
956 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
957 netif_carrier_on(vlan->dev);
958
Johannes Berg665c93a2011-11-04 11:18:11 +0100959 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100960}
961
Johannes Berg88600202012-02-13 15:17:18 +0100962static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
963 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100964{
Johannes Berg14db74b2008-07-29 13:22:52 +0200965 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100966 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100967 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100968
Johannes Berg14db74b2008-07-29 13:22:52 +0200969 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
970
Johannes Berg40b275b2011-05-13 14:15:49 +0200971 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100972 if (!old)
973 return -ENOENT;
974
Johannes Berg88600202012-02-13 15:17:18 +0100975 err = ieee80211_assign_beacon(sdata, params);
976 if (err < 0)
977 return err;
978 ieee80211_bss_info_change_notify(sdata, err);
979 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100980}
981
Johannes Berg88600202012-02-13 15:17:18 +0100982static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100983{
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200984 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
985 struct ieee80211_sub_if_data *vlan;
986 struct ieee80211_local *local = sdata->local;
987 struct beacon_data *old_beacon;
988 struct probe_resp *old_probe_resp;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100989
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200990 old_beacon = rtnl_dereference(sdata->u.ap.beacon);
991 if (!old_beacon)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100992 return -ENOENT;
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200993 old_probe_resp = rtnl_dereference(sdata->u.ap.probe_resp);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100994
Johannes Berg7b20b8e2012-10-25 19:02:42 +0200995 /* turn off carrier for this interface and dependent VLANs */
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200996 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
997 netif_carrier_off(vlan->dev);
998 netif_carrier_off(dev);
999
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001000 /* remove beacon and probe response */
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +00001001 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001002 RCU_INIT_POINTER(sdata->u.ap.probe_resp, NULL);
1003 kfree_rcu(old_beacon, rcu_head);
1004 if (old_probe_resp)
1005 kfree_rcu(old_probe_resp, rcu_head);
Johannes Berg88600202012-02-13 15:17:18 +01001006
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001007 sta_info_flush(local, sdata);
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001008 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +01001009
Johannes Berg10416382012-10-19 15:44:42 +02001010 drv_stop_ap(sdata->local, sdata);
1011
Johannes Berg7b20b8e2012-10-25 19:02:42 +02001012 /* free all potentially still buffered bcast frames */
1013 local->total_ps_buffered -= skb_queue_len(&sdata->u.ap.ps.bc_buf);
1014 skb_queue_purge(&sdata->u.ap.ps.bc_buf);
1015
Johannes Berg55de9082012-07-26 17:24:39 +02001016 ieee80211_vif_release_channel(sdata);
1017
Johannes Berg2d0ddec2009-04-23 16:13:26 +02001018 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001019}
1020
Johannes Berg4fd69312007-12-19 02:03:35 +01001021/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
1022struct iapp_layer2_update {
1023 u8 da[ETH_ALEN]; /* broadcast */
1024 u8 sa[ETH_ALEN]; /* STA addr */
1025 __be16 len; /* 6 */
1026 u8 dsap; /* 0 */
1027 u8 ssap; /* 0 */
1028 u8 control;
1029 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -07001030} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +01001031
1032static void ieee80211_send_layer2_update(struct sta_info *sta)
1033{
1034 struct iapp_layer2_update *msg;
1035 struct sk_buff *skb;
1036
1037 /* Send Level 2 Update Frame to update forwarding tables in layer 2
1038 * bridge devices */
1039
1040 skb = dev_alloc_skb(sizeof(*msg));
1041 if (!skb)
1042 return;
1043 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
1044
1045 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
1046 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
1047
Johannes Berge83e6542012-07-13 16:23:07 +02001048 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +02001049 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +01001050 msg->len = htons(6);
1051 msg->dsap = 0;
1052 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1053 msg->control = 0xaf; /* XID response lsb.1111F101.
1054 * F=0 (no poll command; unsolicited frame) */
1055 msg->xid_info[0] = 0x81; /* XID format identifier */
1056 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1057 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1058
Johannes Bergd0709a62008-02-25 16:27:46 +01001059 skb->dev = sta->sdata->dev;
1060 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001061 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001062 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001063}
1064
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001065static int sta_apply_parameters(struct ieee80211_local *local,
1066 struct sta_info *sta,
1067 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001068{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001069 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001070 u32 rates;
1071 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +01001072 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001073 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Berg55de9082012-07-26 17:24:39 +02001074 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001075 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001076
Johannes Berg55de9082012-07-26 17:24:39 +02001077 sband = local->hw.wiphy->bands[band];
Johannes Bergae5eb022008-10-14 16:58:37 +02001078
Johannes Bergeccb8e82009-05-11 21:57:56 +03001079 mask = params->sta_flags_mask;
1080 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001081
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001082 /*
1083 * In mesh mode, we can clear AUTHENTICATED flag but must
1084 * also make ASSOCIATED follow appropriately for the driver
1085 * API. See also below, after AUTHORIZED changes.
1086 */
1087 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1088 /* cfg80211 should not allow this in non-mesh modes */
1089 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1090 return -EINVAL;
1091
1092 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1093 !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001094 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001095 if (ret)
1096 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001097 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001098 if (ret)
1099 return ret;
1100 }
1101 }
1102
Johannes Bergeccb8e82009-05-11 21:57:56 +03001103 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001104 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001105 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Berg543d1b92012-01-13 14:17:59 +01001106 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001107 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001108 if (ret)
1109 return ret;
Johannes Berg4fd69312007-12-19 02:03:35 +01001110 }
1111
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001112 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1113 /* cfg80211 should not allow this in non-mesh modes */
1114 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1115 return -EINVAL;
1116
1117 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1118 test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001119 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001120 if (ret)
1121 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001122 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001123 if (ret)
1124 return ret;
1125 }
1126 }
1127
1128
Johannes Bergeccb8e82009-05-11 21:57:56 +03001129 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001130 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001131 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1132 else
1133 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001134 }
1135
1136 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001137 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001138 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001139 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001140 } else {
1141 clear_sta_flag(sta, WLAN_STA_WME);
1142 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001143 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001144 }
1145
1146 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001147 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001148 set_sta_flag(sta, WLAN_STA_MFP);
1149 else
1150 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001151 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001152
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001153 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001154 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001155 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1156 else
1157 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001158 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001159
Johannes Berg3b9ce802011-09-27 20:56:12 +02001160 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1161 sta->sta.uapsd_queues = params->uapsd_queues;
1162 sta->sta.max_sp = params->max_sp;
1163 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001164
Johannes Berg73651ee2008-02-25 16:27:47 +01001165 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001166 * cfg80211 validates this (1-2007) and allows setting the AID
1167 * only when creating a new station entry
1168 */
1169 if (params->aid)
1170 sta->sta.aid = params->aid;
1171
1172 /*
Johannes Berg73651ee2008-02-25 16:27:47 +01001173 * FIXME: updating the following information is racy when this
1174 * function is called from ieee80211_change_station().
1175 * However, all this information should be static so
1176 * maybe we should just reject attemps to change it.
1177 */
1178
Johannes Berg4fd69312007-12-19 02:03:35 +01001179 if (params->listen_interval >= 0)
1180 sta->listen_interval = params->listen_interval;
1181
1182 if (params->supported_rates) {
1183 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001184
Johannes Berg4fd69312007-12-19 02:03:35 +01001185 for (i = 0; i < params->supported_rates_len; i++) {
1186 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001187 for (j = 0; j < sband->n_bitrates; j++) {
1188 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001189 rates |= BIT(j);
1190 }
1191 }
Johannes Berg55de9082012-07-26 17:24:39 +02001192 sta->sta.supp_rates[band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001193 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001194
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001195 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001196 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +02001197 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001198 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001199
Mahesh Palivelaf461be3e2012-10-11 08:04:52 +00001200 if (params->vht_capa)
1201 ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
1202 params->vht_capa,
1203 &sta->sta.vht_cap);
1204
Javier Cardona9c3990a2011-05-03 16:57:11 -07001205 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001206#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -07001207 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
1208 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001209 case NL80211_PLINK_LISTEN:
1210 case NL80211_PLINK_ESTAB:
1211 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -07001212 sta->plink_state = params->plink_state;
1213 break;
1214 default:
1215 /* nothing */
1216 break;
1217 }
1218 else
1219 switch (params->plink_action) {
1220 case PLINK_ACTION_OPEN:
1221 mesh_plink_open(sta);
1222 break;
1223 case PLINK_ACTION_BLOCK:
1224 mesh_plink_block(sta);
1225 break;
1226 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001227#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001228 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001229
1230 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001231}
1232
1233static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1234 u8 *mac, struct station_parameters *params)
1235{
Johannes Berg14db74b2008-07-29 13:22:52 +02001236 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001237 struct sta_info *sta;
1238 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001239 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001240 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001241
Johannes Berg4fd69312007-12-19 02:03:35 +01001242 if (params->vlan) {
1243 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1244
Johannes Berg05c914f2008-09-11 00:01:58 +02001245 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1246 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001247 return -EINVAL;
1248 } else
1249 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1250
Joe Perchesb203ca32012-05-08 18:56:52 +00001251 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001252 return -EINVAL;
1253
1254 if (is_multicast_ether_addr(mac))
1255 return -EINVAL;
1256
1257 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001258 if (!sta)
1259 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001260
Johannes Berg83d5cc02012-01-12 09:31:10 +01001261 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1262 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +01001263
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001264 err = sta_apply_parameters(local, sta, params);
1265 if (err) {
1266 sta_info_free(local, sta);
1267 return err;
1268 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001269
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001270 /*
1271 * for TDLS, rate control should be initialized only when supported
1272 * rates are known.
1273 */
1274 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1275 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001276
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001277 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1278 sdata->vif.type == NL80211_IFTYPE_AP;
1279
Johannes Berg34e89502010-02-03 13:59:58 +01001280 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001281 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001282 rcu_read_unlock();
1283 return err;
1284 }
1285
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001286 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001287 ieee80211_send_layer2_update(sta);
1288
1289 rcu_read_unlock();
1290
Johannes Berg4fd69312007-12-19 02:03:35 +01001291 return 0;
1292}
1293
1294static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1295 u8 *mac)
1296{
Johannes Berg14db74b2008-07-29 13:22:52 +02001297 struct ieee80211_local *local = wiphy_priv(wiphy);
1298 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001299
Johannes Berg14db74b2008-07-29 13:22:52 +02001300 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1301
Johannes Berg34e89502010-02-03 13:59:58 +01001302 if (mac)
1303 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001304
Johannes Berg34e89502010-02-03 13:59:58 +01001305 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001306 return 0;
1307}
1308
1309static int ieee80211_change_station(struct wiphy *wiphy,
1310 struct net_device *dev,
1311 u8 *mac,
1312 struct station_parameters *params)
1313{
Johannes Bergabe60632009-11-25 17:46:18 +01001314 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001315 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001316 struct sta_info *sta;
1317 struct ieee80211_sub_if_data *vlansdata;
Eliad Peller35b88622011-12-29 14:41:39 +02001318 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001319
Johannes Berg87be1e12011-12-14 12:20:29 +01001320 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001321
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001322 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001323 if (!sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001324 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001325 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001326 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001327
Johannes Bergbdd90d52011-12-14 12:20:27 +01001328 /* in station mode, supported rates are only valid with TDLS */
1329 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1330 params->supported_rates &&
1331 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001332 mutex_unlock(&local->sta_mtx);
Johannes Bergbdd90d52011-12-14 12:20:27 +01001333 return -EINVAL;
1334 }
1335
Johannes Bergd0709a62008-02-25 16:27:46 +01001336 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001337 bool prev_4addr = false;
1338 bool new_4addr = false;
1339
Johannes Berg4fd69312007-12-19 02:03:35 +01001340 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1341
Johannes Berg05c914f2008-09-11 00:01:58 +02001342 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1343 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001344 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001345 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001346 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001347
Johannes Berg9bc383d2009-11-19 11:55:19 +01001348 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001349 if (vlansdata->u.vlan.sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001350 mutex_unlock(&local->sta_mtx);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001351 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +01001352 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001353
Eric Dumazetcf778b02012-01-12 04:41:32 +00001354 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001355 new_4addr = true;
1356 }
1357
1358 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1359 sta->sdata->u.vlan.sta) {
1360 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1361 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001362 }
1363
Johannes Berg14db74b2008-07-29 13:22:52 +02001364 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001365
1366 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1367 prev_4addr != new_4addr) {
1368 if (new_4addr)
1369 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1370 else
1371 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1372 }
1373
Johannes Berg4fd69312007-12-19 02:03:35 +01001374 ieee80211_send_layer2_update(sta);
1375 }
1376
Eliad Peller35b88622011-12-29 14:41:39 +02001377 err = sta_apply_parameters(local, sta, params);
1378 if (err) {
1379 mutex_unlock(&local->sta_mtx);
1380 return err;
1381 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001382
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001383 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1384 rate_control_rate_init(sta);
1385
Johannes Berg87be1e12011-12-14 12:20:29 +01001386 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001387
Jason Young808118c2011-03-10 16:43:19 -08001388 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001389 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001390 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001391 ieee80211_recalc_ps_vif(sdata);
1392 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001393 return 0;
1394}
1395
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001396#ifdef CONFIG_MAC80211_MESH
1397static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1398 u8 *dst, u8 *next_hop)
1399{
Johannes Berg14db74b2008-07-29 13:22:52 +02001400 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001401 struct mesh_path *mpath;
1402 struct sta_info *sta;
1403 int err;
1404
Johannes Berg14db74b2008-07-29 13:22:52 +02001405 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1406
Johannes Bergd0709a62008-02-25 16:27:46 +01001407 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001408 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001409 if (!sta) {
1410 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001411 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001412 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001413
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001414 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +01001415 if (err) {
1416 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001417 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001418 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001419
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001420 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001421 if (!mpath) {
1422 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001423 return -ENXIO;
1424 }
1425 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001426
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001427 rcu_read_unlock();
1428 return 0;
1429}
1430
1431static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1432 u8 *dst)
1433{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001434 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001435
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001436 if (dst)
1437 return mesh_path_del(dst, sdata);
1438
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001439 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001440 return 0;
1441}
1442
1443static int ieee80211_change_mpath(struct wiphy *wiphy,
1444 struct net_device *dev,
1445 u8 *dst, u8 *next_hop)
1446{
Johannes Berg14db74b2008-07-29 13:22:52 +02001447 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001448 struct mesh_path *mpath;
1449 struct sta_info *sta;
1450
Johannes Berg14db74b2008-07-29 13:22:52 +02001451 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1452
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001453 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001454
Johannes Bergabe60632009-11-25 17:46:18 +01001455 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001456 if (!sta) {
1457 rcu_read_unlock();
1458 return -ENOENT;
1459 }
1460
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001461 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001462 if (!mpath) {
1463 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001464 return -ENOENT;
1465 }
1466
1467 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001468
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001469 rcu_read_unlock();
1470 return 0;
1471}
1472
1473static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1474 struct mpath_info *pinfo)
1475{
Johannes Berga3836e02011-05-12 15:11:37 +02001476 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1477
1478 if (next_hop_sta)
1479 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001480 else
1481 memset(next_hop, 0, ETH_ALEN);
1482
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001483 memset(pinfo, 0, sizeof(*pinfo));
1484
Johannes Bergf5ea9122009-08-07 16:17:38 +02001485 pinfo->generation = mesh_paths_generation;
1486
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001487 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001488 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001489 MPATH_INFO_METRIC |
1490 MPATH_INFO_EXPTIME |
1491 MPATH_INFO_DISCOVERY_TIMEOUT |
1492 MPATH_INFO_DISCOVERY_RETRIES |
1493 MPATH_INFO_FLAGS;
1494
1495 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001496 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001497 pinfo->metric = mpath->metric;
1498 if (time_before(jiffies, mpath->exp_time))
1499 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1500 pinfo->discovery_timeout =
1501 jiffies_to_msecs(mpath->discovery_timeout);
1502 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001503 if (mpath->flags & MESH_PATH_ACTIVE)
1504 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1505 if (mpath->flags & MESH_PATH_RESOLVING)
1506 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001507 if (mpath->flags & MESH_PATH_SN_VALID)
1508 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001509 if (mpath->flags & MESH_PATH_FIXED)
1510 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001511 if (mpath->flags & MESH_PATH_RESOLVED)
1512 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001513}
1514
1515static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1516 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1517
1518{
Johannes Berg14db74b2008-07-29 13:22:52 +02001519 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001520 struct mesh_path *mpath;
1521
Johannes Berg14db74b2008-07-29 13:22:52 +02001522 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1523
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001524 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001525 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001526 if (!mpath) {
1527 rcu_read_unlock();
1528 return -ENOENT;
1529 }
1530 memcpy(dst, mpath->dst, ETH_ALEN);
1531 mpath_set_pinfo(mpath, next_hop, pinfo);
1532 rcu_read_unlock();
1533 return 0;
1534}
1535
1536static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1537 int idx, u8 *dst, u8 *next_hop,
1538 struct mpath_info *pinfo)
1539{
Johannes Berg14db74b2008-07-29 13:22:52 +02001540 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001541 struct mesh_path *mpath;
1542
Johannes Berg14db74b2008-07-29 13:22:52 +02001543 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1544
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001545 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001546 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001547 if (!mpath) {
1548 rcu_read_unlock();
1549 return -ENOENT;
1550 }
1551 memcpy(dst, mpath->dst, ETH_ALEN);
1552 mpath_set_pinfo(mpath, next_hop, pinfo);
1553 rcu_read_unlock();
1554 return 0;
1555}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001556
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001557static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001558 struct net_device *dev,
1559 struct mesh_config *conf)
1560{
1561 struct ieee80211_sub_if_data *sdata;
1562 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1563
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001564 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1565 return 0;
1566}
1567
1568static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1569{
1570 return (mask >> (parm-1)) & 0x1;
1571}
1572
Javier Cardonac80d5452010-12-16 17:37:49 -08001573static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1574 const struct mesh_setup *setup)
1575{
1576 u8 *new_ie;
1577 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001578 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1579 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001580
Javier Cardona581a8b02011-04-07 15:08:27 -07001581 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001582 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001583 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001584
Javier Cardona581a8b02011-04-07 15:08:27 -07001585 if (setup->ie_len) {
1586 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001587 GFP_KERNEL);
1588 if (!new_ie)
1589 return -ENOMEM;
1590 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001591 ifmsh->ie_len = setup->ie_len;
1592 ifmsh->ie = new_ie;
1593 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001594
1595 /* now copy the rest of the setup parameters */
1596 ifmsh->mesh_id_len = setup->mesh_id_len;
1597 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001598 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001599 ifmsh->mesh_pp_id = setup->path_sel_proto;
1600 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001601 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1602 if (setup->is_authenticated)
1603 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1604 if (setup->is_secure)
1605 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001606
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001607 /* mcast rate setting in Mesh Node */
1608 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1609 sizeof(setup->mcast_rate));
1610
Javier Cardonac80d5452010-12-16 17:37:49 -08001611 return 0;
1612}
1613
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001614static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001615 struct net_device *dev, u32 mask,
1616 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001617{
1618 struct mesh_config *conf;
1619 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001620 struct ieee80211_if_mesh *ifmsh;
1621
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001622 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001623 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001624
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001625 /* Set the config options which we are interested in setting */
1626 conf = &(sdata->u.mesh.mshcfg);
1627 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1628 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1629 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1630 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1631 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1632 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1633 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1634 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1635 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1636 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1637 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1638 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001639 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001640 conf->element_ttl = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001641 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1642 conf->auto_open_plinks = nconf->auto_open_plinks;
Javier Cardonad299a1f2012-03-31 11:31:33 -07001643 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1644 conf->dot11MeshNbrOffsetMaxNeighbor =
1645 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001646 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1647 conf->dot11MeshHWMPmaxPREQretries =
1648 nconf->dot11MeshHWMPmaxPREQretries;
1649 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1650 conf->path_refresh_time = nconf->path_refresh_time;
1651 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1652 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1653 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1654 conf->dot11MeshHWMPactivePathTimeout =
1655 nconf->dot11MeshHWMPactivePathTimeout;
1656 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1657 conf->dot11MeshHWMPpreqMinInterval =
1658 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001659 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1660 conf->dot11MeshHWMPperrMinInterval =
1661 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001662 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1663 mask))
1664 conf->dot11MeshHWMPnetDiameterTraversalTime =
1665 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001666 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1667 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1668 ieee80211_mesh_root_setup(ifmsh);
1669 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001670 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001671 /* our current gate announcement implementation rides on root
1672 * announcements, so require this ifmsh to also be a root node
1673 * */
1674 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001675 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1676 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001677 ieee80211_mesh_root_setup(ifmsh);
1678 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001679 conf->dot11MeshGateAnnouncementProtocol =
1680 nconf->dot11MeshGateAnnouncementProtocol;
1681 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001682 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001683 conf->dot11MeshHWMPRannInterval =
1684 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001685 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1686 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001687 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1688 /* our RSSI threshold implementation is supported only for
1689 * devices that report signal in dBm.
1690 */
1691 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1692 return -ENOTSUPP;
1693 conf->rssi_threshold = nconf->rssi_threshold;
1694 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001695 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1696 conf->ht_opmode = nconf->ht_opmode;
1697 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1698 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1699 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001700 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1701 conf->dot11MeshHWMPactivePathToRootTimeout =
1702 nconf->dot11MeshHWMPactivePathToRootTimeout;
1703 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1704 conf->dot11MeshHWMProotInterval =
1705 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001706 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1707 conf->dot11MeshHWMPconfirmationInterval =
1708 nconf->dot11MeshHWMPconfirmationInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001709 return 0;
1710}
1711
Johannes Berg29cbe682010-12-03 09:20:44 +01001712static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1713 const struct mesh_config *conf,
1714 const struct mesh_setup *setup)
1715{
1716 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1717 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001718 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001719
Javier Cardonac80d5452010-12-16 17:37:49 -08001720 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1721 err = copy_mesh_setup(ifmsh, setup);
1722 if (err)
1723 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001724
Johannes Berg04ecd252012-09-11 14:34:12 +02001725 /* can mesh use other SMPS modes? */
1726 sdata->smps_mode = IEEE80211_SMPS_OFF;
1727 sdata->needed_rx_chains = sdata->local->rx_chains;
1728
Johannes Berg4bf88532012-11-09 11:39:59 +01001729 err = ieee80211_vif_use_channel(sdata, &setup->chandef,
1730 IEEE80211_CHANCTX_SHARED);
Johannes Bergcc1d2802012-05-16 23:50:20 +02001731 if (err)
1732 return err;
1733
Johannes Berg29cbe682010-12-03 09:20:44 +01001734 ieee80211_start_mesh(sdata);
1735
1736 return 0;
1737}
1738
1739static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1740{
1741 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1742
1743 ieee80211_stop_mesh(sdata);
Johannes Berg55de9082012-07-26 17:24:39 +02001744 ieee80211_vif_release_channel(sdata);
Johannes Berg29cbe682010-12-03 09:20:44 +01001745
1746 return 0;
1747}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001748#endif
1749
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001750static int ieee80211_change_bss(struct wiphy *wiphy,
1751 struct net_device *dev,
1752 struct bss_parameters *params)
1753{
Johannes Berg55de9082012-07-26 17:24:39 +02001754 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1755 enum ieee80211_band band;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001756 u32 changed = 0;
1757
Johannes Berg55de9082012-07-26 17:24:39 +02001758 if (!rtnl_dereference(sdata->u.ap.beacon))
1759 return -ENOENT;
1760
1761 band = ieee80211_get_sdata_band(sdata);
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001762
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001763 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001764 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001765 changed |= BSS_CHANGED_ERP_CTS_PROT;
1766 }
1767 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001768 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001769 params->use_short_preamble;
1770 changed |= BSS_CHANGED_ERP_PREAMBLE;
1771 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001772
1773 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg55de9082012-07-26 17:24:39 +02001774 band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001775 sdata->vif.bss_conf.use_short_slot = true;
1776 changed |= BSS_CHANGED_ERP_SLOT;
1777 }
1778
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001779 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001780 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001781 params->use_short_slot_time;
1782 changed |= BSS_CHANGED_ERP_SLOT;
1783 }
1784
Jouni Malinen90c97a02008-10-30 16:59:22 +02001785 if (params->basic_rates) {
1786 int i, j;
1787 u32 rates = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02001788 struct ieee80211_supported_band *sband = wiphy->bands[band];
Jouni Malinen90c97a02008-10-30 16:59:22 +02001789
1790 for (i = 0; i < params->basic_rates_len; i++) {
1791 int rate = (params->basic_rates[i] & 0x7f) * 5;
1792 for (j = 0; j < sband->n_bitrates; j++) {
1793 if (sband->bitrates[j].bitrate == rate)
1794 rates |= BIT(j);
1795 }
1796 }
1797 sdata->vif.bss_conf.basic_rates = rates;
1798 changed |= BSS_CHANGED_BASIC_RATES;
1799 }
1800
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001801 if (params->ap_isolate >= 0) {
1802 if (params->ap_isolate)
1803 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1804 else
1805 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1806 }
1807
Helmut Schaa80d7e402010-11-19 12:40:26 +01001808 if (params->ht_opmode >= 0) {
1809 sdata->vif.bss_conf.ht_operation_mode =
1810 (u16) params->ht_opmode;
1811 changed |= BSS_CHANGED_HT;
1812 }
1813
Johannes Berg339afbf2012-11-14 15:21:17 +01001814 if (params->p2p_ctwindow >= 0) {
1815 sdata->vif.bss_conf.p2p_ctwindow = params->p2p_ctwindow;
1816 changed |= BSS_CHANGED_P2P_PS;
1817 }
1818
1819 if (params->p2p_opp_ps >= 0) {
1820 sdata->vif.bss_conf.p2p_oppps = params->p2p_opp_ps;
1821 changed |= BSS_CHANGED_P2P_PS;
1822 }
1823
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001824 ieee80211_bss_info_change_notify(sdata, changed);
1825
1826 return 0;
1827}
1828
Jouni Malinen31888482008-10-30 16:59:24 +02001829static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001830 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001831 struct ieee80211_txq_params *params)
1832{
1833 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001834 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001835 struct ieee80211_tx_queue_params p;
1836
1837 if (!local->ops->conf_tx)
1838 return -EOPNOTSUPP;
1839
Johannes Berg54bcbc62012-03-28 11:04:25 +02001840 if (local->hw.queues < IEEE80211_NUM_ACS)
1841 return -EOPNOTSUPP;
1842
Jouni Malinen31888482008-10-30 16:59:24 +02001843 memset(&p, 0, sizeof(p));
1844 p.aifs = params->aifs;
1845 p.cw_max = params->cwmax;
1846 p.cw_min = params->cwmin;
1847 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001848
1849 /*
1850 * Setting tx queue params disables u-apsd because it's only
1851 * called in master mode.
1852 */
1853 p.uapsd = false;
1854
Johannes Berga3304b02012-03-28 11:04:24 +02001855 sdata->tx_conf[params->ac] = p;
1856 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001857 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001858 "failed to set TX queue parameters for AC %d\n",
1859 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001860 return -EINVAL;
1861 }
1862
Johannes Berg7d257452012-07-06 17:37:43 +02001863 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1864
Jouni Malinen31888482008-10-30 16:59:24 +02001865 return 0;
1866}
1867
Bob Copeland665af4f2009-01-19 11:20:53 -05001868#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001869static int ieee80211_suspend(struct wiphy *wiphy,
1870 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001871{
Johannes Bergeecc4802011-05-04 15:37:29 +02001872 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001873}
1874
1875static int ieee80211_resume(struct wiphy *wiphy)
1876{
1877 return __ieee80211_resume(wiphy_priv(wiphy));
1878}
1879#else
1880#define ieee80211_suspend NULL
1881#define ieee80211_resume NULL
1882#endif
1883
Johannes Berg2a519312009-02-10 21:25:55 +01001884static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001885 struct cfg80211_scan_request *req)
1886{
Johannes Bergfd014282012-06-18 19:17:03 +02001887 struct ieee80211_sub_if_data *sdata;
1888
1889 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001890
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001891 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1892 case NL80211_IFTYPE_STATION:
1893 case NL80211_IFTYPE_ADHOC:
1894 case NL80211_IFTYPE_MESH_POINT:
1895 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001896 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001897 break;
1898 case NL80211_IFTYPE_P2P_GO:
1899 if (sdata->local->ops->hw_scan)
1900 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001901 /*
1902 * FIXME: implement NoA while scanning in software,
1903 * for now fall through to allow scanning only when
1904 * beaconing hasn't been configured yet
1905 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001906 case NL80211_IFTYPE_AP:
Antonio Quartulli5c95b942012-10-16 08:39:22 +02001907 /*
1908 * If the scan has been forced (and the driver supports
1909 * forcing), don't care about being beaconing already.
1910 * This will create problems to the attached stations (e.g. all
1911 * the frames sent while scanning on other channel will be
1912 * lost)
1913 */
1914 if (sdata->u.ap.beacon &&
1915 (!(wiphy->features & NL80211_FEATURE_AP_SCAN) ||
1916 !(req->flags & NL80211_SCAN_FLAG_AP)))
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001917 return -EOPNOTSUPP;
1918 break;
1919 default:
1920 return -EOPNOTSUPP;
1921 }
Johannes Berg2a519312009-02-10 21:25:55 +01001922
1923 return ieee80211_request_scan(sdata, req);
1924}
1925
Luciano Coelho79f460c2011-05-11 17:09:36 +03001926static int
1927ieee80211_sched_scan_start(struct wiphy *wiphy,
1928 struct net_device *dev,
1929 struct cfg80211_sched_scan_request *req)
1930{
1931 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1932
1933 if (!sdata->local->ops->sched_scan_start)
1934 return -EOPNOTSUPP;
1935
1936 return ieee80211_request_sched_scan_start(sdata, req);
1937}
1938
1939static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001940ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001941{
1942 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1943
1944 if (!sdata->local->ops->sched_scan_stop)
1945 return -EOPNOTSUPP;
1946
Luciano Coelho85a99942011-05-12 16:28:29 +03001947 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001948}
1949
Jouni Malinen636a5d32009-03-19 13:39:22 +02001950static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1951 struct cfg80211_auth_request *req)
1952{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001953 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001954}
1955
1956static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1957 struct cfg80211_assoc_request *req)
1958{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001959 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001960}
1961
1962static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001963 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001964{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001965 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001966}
1967
1968static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001969 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001970{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001971 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001972}
1973
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001974static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1975 struct cfg80211_ibss_params *params)
1976{
Johannes Berg55de9082012-07-26 17:24:39 +02001977 return ieee80211_ibss_join(IEEE80211_DEV_TO_SUB_IF(dev), params);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001978}
1979
1980static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1981{
Johannes Berg55de9082012-07-26 17:24:39 +02001982 return ieee80211_ibss_leave(IEEE80211_DEV_TO_SUB_IF(dev));
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001983}
1984
Antonio Quartulli391e53e2012-11-02 13:27:49 +01001985static int ieee80211_set_mcast_rate(struct wiphy *wiphy, struct net_device *dev,
1986 int rate[IEEE80211_NUM_BANDS])
1987{
1988 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1989
1990 memcpy(sdata->vif.bss_conf.mcast_rate, rate, sizeof(rate));
1991
1992 return 0;
1993}
1994
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001995static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1996{
1997 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001998 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001999
Arik Nemtsovf23a4782010-11-08 11:51:06 +02002000 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
2001 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
2002
2003 if (err)
2004 return err;
2005 }
2006
Lukáš Turek310bc672009-12-21 22:50:48 +01002007 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
2008 err = drv_set_coverage_class(local, wiphy->coverage_class);
2009
2010 if (err)
2011 return err;
2012 }
2013
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002014 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02002015 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002016
Johannes Berg24487982009-04-23 18:52:52 +02002017 if (err)
2018 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002019 }
2020
Johannes Berg8bc83c22012-11-09 18:38:32 +01002021 if (changed & WIPHY_PARAM_RETRY_SHORT) {
2022 if (wiphy->retry_short > IEEE80211_MAX_TX_RETRY)
2023 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002024 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002025 }
2026 if (changed & WIPHY_PARAM_RETRY_LONG) {
2027 if (wiphy->retry_long > IEEE80211_MAX_TX_RETRY)
2028 return -EINVAL;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002029 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
Johannes Berg8bc83c22012-11-09 18:38:32 +01002030 }
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002031 if (changed &
2032 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
2033 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
2034
2035 return 0;
2036}
2037
Johannes Berg7643a2c2009-06-02 13:01:39 +02002038static int ieee80211_set_tx_power(struct wiphy *wiphy,
Johannes Bergc8442112012-10-24 10:17:18 +02002039 struct wireless_dev *wdev,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002040 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002041{
2042 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002043 struct ieee80211_sub_if_data *sdata;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002044
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002045 if (wdev) {
2046 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
2047
2048 switch (type) {
2049 case NL80211_TX_POWER_AUTOMATIC:
2050 sdata->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
2051 break;
2052 case NL80211_TX_POWER_LIMITED:
2053 case NL80211_TX_POWER_FIXED:
2054 if (mbm < 0 || (mbm % 100))
2055 return -EOPNOTSUPP;
2056 sdata->user_power_level = MBM_TO_DBM(mbm);
2057 break;
2058 }
2059
2060 ieee80211_recalc_txpower(sdata);
2061
2062 return 0;
2063 }
Johannes Berg55de9082012-07-26 17:24:39 +02002064
Johannes Berg7643a2c2009-06-02 13:01:39 +02002065 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002066 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002067 local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002068 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002069 case NL80211_TX_POWER_LIMITED:
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002070 case NL80211_TX_POWER_FIXED:
2071 if (mbm < 0 || (mbm % 100))
2072 return -EOPNOTSUPP;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03002073 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002074 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002075 }
2076
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002077 mutex_lock(&local->iflist_mtx);
2078 list_for_each_entry(sdata, &local->interfaces, list)
2079 sdata->user_power_level = local->user_power_level;
2080 list_for_each_entry(sdata, &local->interfaces, list)
2081 ieee80211_recalc_txpower(sdata);
2082 mutex_unlock(&local->iflist_mtx);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002083
2084 return 0;
2085}
2086
Johannes Bergc8442112012-10-24 10:17:18 +02002087static int ieee80211_get_tx_power(struct wiphy *wiphy,
2088 struct wireless_dev *wdev,
2089 int *dbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02002090{
2091 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002092 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7643a2c2009-06-02 13:01:39 +02002093
Johannes Berg1ea6f9c2012-10-24 10:59:25 +02002094 if (!local->use_chanctx)
2095 *dbm = local->hw.conf.power_level;
2096 else
2097 *dbm = sdata->vif.bss_conf.txpower;
Johannes Berg7643a2c2009-06-02 13:01:39 +02002098
Johannes Berg7643a2c2009-06-02 13:01:39 +02002099 return 0;
2100}
2101
Johannes Bergab737a42009-07-01 21:26:58 +02002102static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002103 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002104{
2105 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2106
2107 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2108
2109 return 0;
2110}
2111
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002112static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2113{
2114 struct ieee80211_local *local = wiphy_priv(wiphy);
2115
2116 drv_rfkill_poll(local);
2117}
2118
Johannes Bergaff89a92009-07-01 21:26:51 +02002119#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002120static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002121{
2122 struct ieee80211_local *local = wiphy_priv(wiphy);
2123
2124 if (!local->ops->testmode_cmd)
2125 return -EOPNOTSUPP;
2126
2127 return local->ops->testmode_cmd(&local->hw, data, len);
2128}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002129
2130static int ieee80211_testmode_dump(struct wiphy *wiphy,
2131 struct sk_buff *skb,
2132 struct netlink_callback *cb,
2133 void *data, int len)
2134{
2135 struct ieee80211_local *local = wiphy_priv(wiphy);
2136
2137 if (!local->ops->testmode_dump)
2138 return -EOPNOTSUPP;
2139
2140 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2141}
Johannes Bergaff89a92009-07-01 21:26:51 +02002142#endif
2143
Johannes Berg0f782312009-12-01 13:37:02 +01002144int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2145 enum ieee80211_smps_mode smps_mode)
2146{
2147 const u8 *ap;
2148 enum ieee80211_smps_mode old_req;
2149 int err;
2150
Johannes Berg243e6df2011-04-19 20:44:04 +02002151 lockdep_assert_held(&sdata->u.mgd.mtx);
2152
Johannes Berg0f782312009-12-01 13:37:02 +01002153 old_req = sdata->u.mgd.req_smps;
2154 sdata->u.mgd.req_smps = smps_mode;
2155
2156 if (old_req == smps_mode &&
2157 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2158 return 0;
2159
2160 /*
2161 * If not associated, or current association is not an HT
Johannes Berg04ecd252012-09-11 14:34:12 +02002162 * association, there's no need to do anything, just store
2163 * the new value until we associate.
Johannes Berg0f782312009-12-01 13:37:02 +01002164 */
2165 if (!sdata->u.mgd.associated ||
Johannes Berg4bf88532012-11-09 11:39:59 +01002166 sdata->vif.bss_conf.chandef.width == NL80211_CHAN_WIDTH_20_NOHT)
Johannes Berg0f782312009-12-01 13:37:02 +01002167 return 0;
Johannes Berg0f782312009-12-01 13:37:02 +01002168
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002169 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002170
2171 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2172 if (sdata->u.mgd.powersave)
2173 smps_mode = IEEE80211_SMPS_DYNAMIC;
2174 else
2175 smps_mode = IEEE80211_SMPS_OFF;
2176 }
2177
2178 /* send SM PS frame to AP */
2179 err = ieee80211_send_smps_action(sdata, smps_mode,
2180 ap, ap);
2181 if (err)
2182 sdata->u.mgd.req_smps = old_req;
2183
2184 return err;
2185}
2186
Johannes Bergbc92afd2009-07-01 21:26:57 +02002187static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2188 bool enabled, int timeout)
2189{
2190 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2191 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002192
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002193 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2194 return -EOPNOTSUPP;
2195
Johannes Bergbc92afd2009-07-01 21:26:57 +02002196 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2197 return -EOPNOTSUPP;
2198
2199 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002200 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002201 return 0;
2202
2203 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002204 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002205
Johannes Berg0f782312009-12-01 13:37:02 +01002206 /* no change, but if automatic follow powersave */
2207 mutex_lock(&sdata->u.mgd.mtx);
2208 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2209 mutex_unlock(&sdata->u.mgd.mtx);
2210
Johannes Bergbc92afd2009-07-01 21:26:57 +02002211 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2212 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2213
2214 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002215 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002216
2217 return 0;
2218}
2219
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002220static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2221 struct net_device *dev,
2222 s32 rssi_thold, u32 rssi_hyst)
2223{
2224 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002225 struct ieee80211_vif *vif = &sdata->vif;
2226 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2227
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002228 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2229 rssi_hyst == bss_conf->cqm_rssi_hyst)
2230 return 0;
2231
2232 bss_conf->cqm_rssi_thold = rssi_thold;
2233 bss_conf->cqm_rssi_hyst = rssi_hyst;
2234
2235 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002236 if (sdata->u.mgd.associated &&
2237 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002238 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2239
2240 return 0;
2241}
2242
Johannes Berg99303802009-07-01 21:26:59 +02002243static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2244 struct net_device *dev,
2245 const u8 *addr,
2246 const struct cfg80211_bitrate_mask *mask)
2247{
2248 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2249 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302250 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002251
Eliad Peller554a43d2012-06-12 12:41:15 +03002252 if (!ieee80211_sdata_running(sdata))
2253 return -ENETDOWN;
2254
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302255 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2256 ret = drv_set_bitrate_mask(local, sdata, mask);
2257 if (ret)
2258 return ret;
2259 }
Johannes Berg99303802009-07-01 21:26:59 +02002260
Simon Wunderlich19468412012-01-28 17:25:33 +01002261 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002262 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002263 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2264 sizeof(mask->control[i].mcs));
2265 }
Johannes Berg99303802009-07-01 21:26:59 +02002266
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002267 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002268}
2269
Johannes Berg2eb278e2012-06-05 14:28:42 +02002270static int ieee80211_start_roc_work(struct ieee80211_local *local,
2271 struct ieee80211_sub_if_data *sdata,
2272 struct ieee80211_channel *channel,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002273 unsigned int duration, u64 *cookie,
2274 struct sk_buff *txskb)
Johannes Berg21f83582010-12-18 17:20:47 +01002275{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002276 struct ieee80211_roc_work *roc, *tmp;
2277 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002278 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002279
2280 lockdep_assert_held(&local->mtx);
2281
Johannes Bergfe57d9f2012-07-26 14:55:08 +02002282 if (local->use_chanctx && !local->ops->remain_on_channel)
2283 return -EOPNOTSUPP;
2284
Johannes Berg2eb278e2012-06-05 14:28:42 +02002285 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2286 if (!roc)
2287 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002288
Johannes Berg2eb278e2012-06-05 14:28:42 +02002289 roc->chan = channel;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002290 roc->duration = duration;
2291 roc->req_duration = duration;
2292 roc->frame = txskb;
2293 roc->mgmt_tx_cookie = (unsigned long)txskb;
2294 roc->sdata = sdata;
2295 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2296 INIT_LIST_HEAD(&roc->dependents);
2297
2298 /* if there's one pending or we're scanning, queue this one */
2299 if (!list_empty(&local->roc_list) || local->scanning)
2300 goto out_check_combine;
2301
2302 /* if not HW assist, just queue & schedule work */
2303 if (!local->ops->remain_on_channel) {
2304 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2305 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002306 }
2307
Johannes Berg2eb278e2012-06-05 14:28:42 +02002308 /* otherwise actually kick it off here (for error handling) */
2309
2310 /*
2311 * If the duration is zero, then the driver
2312 * wouldn't actually do anything. Set it to
2313 * 10 for now.
2314 *
2315 * TODO: cancel the off-channel operation
2316 * when we get the SKB's TX status and
2317 * the wait time was zero before.
2318 */
2319 if (!duration)
2320 duration = 10;
2321
Johannes Berg42d97a52012-11-08 18:31:02 +01002322 ret = drv_remain_on_channel(local, sdata, channel, duration);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002323 if (ret) {
2324 kfree(roc);
2325 return ret;
2326 }
2327
2328 roc->started = true;
2329 goto out_queue;
2330
2331 out_check_combine:
2332 list_for_each_entry(tmp, &local->roc_list, list) {
Johannes Berg42d97a52012-11-08 18:31:02 +01002333 if (tmp->chan != channel || tmp->sdata != sdata)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002334 continue;
2335
2336 /*
2337 * Extend this ROC if possible:
2338 *
2339 * If it hasn't started yet, just increase the duration
2340 * and add the new one to the list of dependents.
2341 */
2342 if (!tmp->started) {
2343 list_add_tail(&roc->list, &tmp->dependents);
2344 tmp->duration = max(tmp->duration, roc->duration);
2345 queued = true;
2346 break;
2347 }
2348
2349 /* If it has already started, it's more difficult ... */
2350 if (local->ops->remain_on_channel) {
2351 unsigned long j = jiffies;
2352
2353 /*
2354 * In the offloaded ROC case, if it hasn't begun, add
2355 * this new one to the dependent list to be handled
2356 * when the the master one begins. If it has begun,
2357 * check that there's still a minimum time left and
2358 * if so, start this one, transmitting the frame, but
2359 * add it to the list directly after this one with a
2360 * a reduced time so we'll ask the driver to execute
2361 * it right after finishing the previous one, in the
2362 * hope that it'll also be executed right afterwards,
2363 * effectively extending the old one.
2364 * If there's no minimum time left, just add it to the
2365 * normal list.
2366 */
2367 if (!tmp->hw_begun) {
2368 list_add_tail(&roc->list, &tmp->dependents);
2369 queued = true;
2370 break;
2371 }
2372
2373 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2374 tmp->hw_start_time +
2375 msecs_to_jiffies(tmp->duration))) {
2376 int new_dur;
2377
2378 ieee80211_handle_roc_started(roc);
2379
2380 new_dur = roc->duration -
2381 jiffies_to_msecs(tmp->hw_start_time +
2382 msecs_to_jiffies(
2383 tmp->duration) -
2384 j);
2385
2386 if (new_dur > 0) {
2387 /* add right after tmp */
2388 list_add(&roc->list, &tmp->list);
2389 } else {
2390 list_add_tail(&roc->list,
2391 &tmp->dependents);
2392 }
2393 queued = true;
2394 }
2395 } else if (del_timer_sync(&tmp->work.timer)) {
2396 unsigned long new_end;
2397
2398 /*
2399 * In the software ROC case, cancel the timer, if
2400 * that fails then the finish work is already
2401 * queued/pending and thus we queue the new ROC
2402 * normally, if that succeeds then we can extend
2403 * the timer duration and TX the frame (if any.)
2404 */
2405
2406 list_add_tail(&roc->list, &tmp->dependents);
2407 queued = true;
2408
2409 new_end = jiffies + msecs_to_jiffies(roc->duration);
2410
2411 /* ok, it was started & we canceled timer */
2412 if (time_after(new_end, tmp->work.timer.expires))
2413 mod_timer(&tmp->work.timer, new_end);
2414 else
2415 add_timer(&tmp->work.timer);
2416
2417 ieee80211_handle_roc_started(roc);
2418 }
2419 break;
2420 }
2421
2422 out_queue:
2423 if (!queued)
2424 list_add_tail(&roc->list, &local->roc_list);
2425
2426 /*
Johannes Berg50febf62012-10-26 16:13:06 +02002427 * cookie is either the roc cookie (for normal roc)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002428 * or the SKB (for mgmt TX)
2429 */
Johannes Berg50febf62012-10-26 16:13:06 +02002430 if (!txskb) {
2431 /* local->mtx protects this */
2432 local->roc_cookie_counter++;
2433 roc->cookie = local->roc_cookie_counter;
2434 /* wow, you wrapped 64 bits ... more likely a bug */
2435 if (WARN_ON(roc->cookie == 0)) {
2436 roc->cookie = 1;
2437 local->roc_cookie_counter++;
2438 }
2439 *cookie = roc->cookie;
2440 } else {
Johannes Berg2eb278e2012-06-05 14:28:42 +02002441 *cookie = (unsigned long)txskb;
Johannes Berg50febf62012-10-26 16:13:06 +02002442 }
Johannes Berg2eb278e2012-06-05 14:28:42 +02002443
2444 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002445}
2446
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002447static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002448 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002449 struct ieee80211_channel *chan,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002450 unsigned int duration,
2451 u64 *cookie)
2452{
Johannes Berg71bbc992012-06-15 15:30:18 +02002453 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002454 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002455 int ret;
2456
Johannes Berg2eb278e2012-06-05 14:28:42 +02002457 mutex_lock(&local->mtx);
Johannes Berg42d97a52012-11-08 18:31:02 +01002458 ret = ieee80211_start_roc_work(local, sdata, chan,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002459 duration, cookie, NULL);
2460 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002461
Johannes Berg2eb278e2012-06-05 14:28:42 +02002462 return ret;
2463}
2464
2465static int ieee80211_cancel_roc(struct ieee80211_local *local,
2466 u64 cookie, bool mgmt_tx)
2467{
2468 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2469 int ret;
2470
2471 mutex_lock(&local->mtx);
2472 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002473 struct ieee80211_roc_work *dep, *tmp2;
2474
2475 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
Johannes Berg50febf62012-10-26 16:13:06 +02002476 if (!mgmt_tx && dep->cookie != cookie)
Johannes Berge979e332012-06-11 17:09:41 +02002477 continue;
2478 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2479 continue;
2480 /* found dependent item -- just remove it */
2481 list_del(&dep->list);
2482 mutex_unlock(&local->mtx);
2483
2484 ieee80211_roc_notify_destroy(dep);
2485 return 0;
2486 }
2487
Johannes Berg50febf62012-10-26 16:13:06 +02002488 if (!mgmt_tx && roc->cookie != cookie)
Johannes Berg2eb278e2012-06-05 14:28:42 +02002489 continue;
2490 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2491 continue;
2492
2493 found = roc;
2494 break;
2495 }
2496
2497 if (!found) {
2498 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002499 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002500 }
Johannes Berg21f83582010-12-18 17:20:47 +01002501
Johannes Berge979e332012-06-11 17:09:41 +02002502 /*
2503 * We found the item to cancel, so do that. Note that it
2504 * may have dependents, which we also cancel (and send
2505 * the expired signal for.) Not doing so would be quite
2506 * tricky here, but we may need to fix it later.
2507 */
2508
Johannes Berg2eb278e2012-06-05 14:28:42 +02002509 if (local->ops->remain_on_channel) {
2510 if (found->started) {
2511 ret = drv_cancel_remain_on_channel(local);
2512 if (WARN_ON_ONCE(ret)) {
2513 mutex_unlock(&local->mtx);
2514 return ret;
2515 }
2516 }
Johannes Berg21f83582010-12-18 17:20:47 +01002517
Johannes Berg2eb278e2012-06-05 14:28:42 +02002518 list_del(&found->list);
2519
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002520 if (found->started)
2521 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002522 mutex_unlock(&local->mtx);
2523
2524 ieee80211_roc_notify_destroy(found);
2525 } else {
2526 /* work may be pending so use it all the time */
2527 found->abort = true;
2528 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2529
2530 mutex_unlock(&local->mtx);
2531
2532 /* work will clean up etc */
2533 flush_delayed_work(&found->work);
2534 }
Johannes Berg21f83582010-12-18 17:20:47 +01002535
Johannes Berg21f83582010-12-18 17:20:47 +01002536 return 0;
2537}
2538
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002539static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002540 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002541 u64 cookie)
2542{
Johannes Berg71bbc992012-06-15 15:30:18 +02002543 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002544 struct ieee80211_local *local = sdata->local;
2545
Johannes Berg2eb278e2012-06-05 14:28:42 +02002546 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002547}
2548
Johannes Berg71bbc992012-06-15 15:30:18 +02002549static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002550 struct ieee80211_channel *chan, bool offchan,
Johannes Berg42d97a52012-11-08 18:31:02 +01002551 unsigned int wait, const u8 *buf, size_t len,
2552 bool no_cck, bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002553{
Johannes Berg71bbc992012-06-15 15:30:18 +02002554 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002555 struct ieee80211_local *local = sdata->local;
2556 struct sk_buff *skb;
2557 struct sta_info *sta;
2558 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002559 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002560 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002561 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002562
Johannes Berge247bd902011-11-04 11:18:21 +01002563 if (dont_wait_for_ack)
2564 flags = IEEE80211_TX_CTL_NO_ACK;
2565 else
2566 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2567 IEEE80211_TX_CTL_REQ_TX_STATUS;
2568
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302569 if (no_cck)
2570 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2571
Johannes Berg9d38d852010-06-09 17:20:33 +02002572 switch (sdata->vif.type) {
2573 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002574 if (!sdata->vif.bss_conf.ibss_joined)
2575 need_offchan = true;
2576 /* fall through */
2577#ifdef CONFIG_MAC80211_MESH
2578 case NL80211_IFTYPE_MESH_POINT:
2579 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2580 !sdata->u.mesh.mesh_id_len)
2581 need_offchan = true;
2582 /* fall through */
2583#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002584 case NL80211_IFTYPE_AP:
2585 case NL80211_IFTYPE_AP_VLAN:
2586 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002587 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2588 !ieee80211_vif_is_mesh(&sdata->vif) &&
2589 !rcu_access_pointer(sdata->bss->beacon))
2590 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002591 if (!ieee80211_is_action(mgmt->frame_control) ||
2592 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002593 break;
2594 rcu_read_lock();
2595 sta = sta_info_get(sdata, mgmt->da);
2596 rcu_read_unlock();
2597 if (!sta)
2598 return -ENOLINK;
2599 break;
2600 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002601 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002602 if (!sdata->u.mgd.associated)
2603 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002604 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002605 case NL80211_IFTYPE_P2P_DEVICE:
2606 need_offchan = true;
2607 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002608 default:
2609 return -EOPNOTSUPP;
2610 }
2611
Johannes Berg2eb278e2012-06-05 14:28:42 +02002612 mutex_lock(&local->mtx);
2613
2614 /* Check if the operating channel is the requested channel */
2615 if (!need_offchan) {
Johannes Berg55de9082012-07-26 17:24:39 +02002616 struct ieee80211_chanctx_conf *chanctx_conf;
2617
2618 rcu_read_lock();
2619 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
2620
Johannes Berg42d97a52012-11-08 18:31:02 +01002621 if (chanctx_conf)
Johannes Berg4bf88532012-11-09 11:39:59 +01002622 need_offchan = chan != chanctx_conf->def.chan;
Johannes Berg42d97a52012-11-08 18:31:02 +01002623 else
Johannes Berg2eb278e2012-06-05 14:28:42 +02002624 need_offchan = true;
Johannes Berg55de9082012-07-26 17:24:39 +02002625 rcu_read_unlock();
Johannes Berg2eb278e2012-06-05 14:28:42 +02002626 }
2627
2628 if (need_offchan && !offchan) {
2629 ret = -EBUSY;
2630 goto out_unlock;
2631 }
2632
Johannes Berg9d38d852010-06-09 17:20:33 +02002633 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002634 if (!skb) {
2635 ret = -ENOMEM;
2636 goto out_unlock;
2637 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002638 skb_reserve(skb, local->hw.extra_tx_headroom);
2639
2640 memcpy(skb_put(skb, len), buf, len);
2641
2642 IEEE80211_SKB_CB(skb)->flags = flags;
2643
Johannes Berg2eb278e2012-06-05 14:28:42 +02002644 skb->dev = sdata->dev;
2645
2646 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002647 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002648 ieee80211_tx_skb(sdata, skb);
2649 ret = 0;
2650 goto out_unlock;
2651 }
2652
2653 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2654 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002655 IEEE80211_SKB_CB(skb)->hw_queue =
2656 local->hw.offchannel_tx_hw_queue;
2657
Johannes Berg2eb278e2012-06-05 14:28:42 +02002658 /* This will handle all kinds of coalescing and immediate TX */
Johannes Berg42d97a52012-11-08 18:31:02 +01002659 ret = ieee80211_start_roc_work(local, sdata, chan,
Johannes Berg2eb278e2012-06-05 14:28:42 +02002660 wait, cookie, skb);
2661 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002662 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002663 out_unlock:
2664 mutex_unlock(&local->mtx);
2665 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002666}
2667
Johannes Bergf30221e2010-11-25 10:02:30 +01002668static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002669 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002670 u64 cookie)
2671{
Johannes Berg71bbc992012-06-15 15:30:18 +02002672 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002673
Johannes Berg2eb278e2012-06-05 14:28:42 +02002674 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002675}
2676
Johannes Berg7be50862010-10-13 12:06:24 +02002677static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002678 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002679 u16 frame_type, bool reg)
2680{
2681 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002682 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002683
Will Hawkins6abe0562012-06-20 11:51:14 -04002684 switch (frame_type) {
2685 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2686 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2687 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002688
Will Hawkins6abe0562012-06-20 11:51:14 -04002689 if (reg)
2690 ifibss->auth_frame_registrations++;
2691 else
2692 ifibss->auth_frame_registrations--;
2693 }
2694 break;
2695 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2696 if (reg)
2697 local->probe_req_reg++;
2698 else
2699 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002700
Will Hawkins6abe0562012-06-20 11:51:14 -04002701 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2702 break;
2703 default:
2704 break;
2705 }
Johannes Berg7be50862010-10-13 12:06:24 +02002706}
2707
Bruno Randolf15d96752010-11-10 12:50:56 +09002708static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2709{
2710 struct ieee80211_local *local = wiphy_priv(wiphy);
2711
2712 if (local->started)
2713 return -EOPNOTSUPP;
2714
2715 return drv_set_antenna(local, tx_ant, rx_ant);
2716}
2717
2718static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2719{
2720 struct ieee80211_local *local = wiphy_priv(wiphy);
2721
2722 return drv_get_antenna(local, tx_ant, rx_ant);
2723}
2724
John W. Linville38c09152011-03-07 16:19:18 -05002725static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2726{
2727 struct ieee80211_local *local = wiphy_priv(wiphy);
2728
2729 return drv_set_ringparam(local, tx, rx);
2730}
2731
2732static void ieee80211_get_ringparam(struct wiphy *wiphy,
2733 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2734{
2735 struct ieee80211_local *local = wiphy_priv(wiphy);
2736
2737 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2738}
2739
Johannes Bergc68f4b82011-07-05 16:35:41 +02002740static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2741 struct net_device *dev,
2742 struct cfg80211_gtk_rekey_data *data)
2743{
2744 struct ieee80211_local *local = wiphy_priv(wiphy);
2745 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2746
2747 if (!local->ops->set_rekey_data)
2748 return -EOPNOTSUPP;
2749
2750 drv_set_rekey_data(local, sdata, data);
2751
2752 return 0;
2753}
2754
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002755static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2756{
2757 u8 *pos = (void *)skb_put(skb, 7);
2758
2759 *pos++ = WLAN_EID_EXT_CAPABILITY;
2760 *pos++ = 5; /* len */
2761 *pos++ = 0x0;
2762 *pos++ = 0x0;
2763 *pos++ = 0x0;
2764 *pos++ = 0x0;
2765 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2766}
2767
2768static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2769{
2770 struct ieee80211_local *local = sdata->local;
2771 u16 capab;
2772
2773 capab = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02002774 if (ieee80211_get_sdata_band(sdata) != IEEE80211_BAND_2GHZ)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002775 return capab;
2776
2777 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2778 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2779 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2780 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2781
2782 return capab;
2783}
2784
2785static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2786 u8 *peer, u8 *bssid)
2787{
2788 struct ieee80211_tdls_lnkie *lnkid;
2789
2790 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2791
2792 lnkid->ie_type = WLAN_EID_LINK_ID;
2793 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2794
2795 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2796 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2797 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2798}
2799
2800static int
2801ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2802 u8 *peer, u8 action_code, u8 dialog_token,
2803 u16 status_code, struct sk_buff *skb)
2804{
2805 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02002806 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002807 struct ieee80211_tdls_data *tf;
2808
2809 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2810
2811 memcpy(tf->da, peer, ETH_ALEN);
2812 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2813 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2814 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2815
2816 switch (action_code) {
2817 case WLAN_TDLS_SETUP_REQUEST:
2818 tf->category = WLAN_CATEGORY_TDLS;
2819 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2820
2821 skb_put(skb, sizeof(tf->u.setup_req));
2822 tf->u.setup_req.dialog_token = dialog_token;
2823 tf->u.setup_req.capability =
2824 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2825
Johannes Berg55de9082012-07-26 17:24:39 +02002826 ieee80211_add_srates_ie(sdata, skb, false, band);
2827 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002828 ieee80211_tdls_add_ext_capab(skb);
2829 break;
2830 case WLAN_TDLS_SETUP_RESPONSE:
2831 tf->category = WLAN_CATEGORY_TDLS;
2832 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2833
2834 skb_put(skb, sizeof(tf->u.setup_resp));
2835 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2836 tf->u.setup_resp.dialog_token = dialog_token;
2837 tf->u.setup_resp.capability =
2838 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2839
Johannes Berg55de9082012-07-26 17:24:39 +02002840 ieee80211_add_srates_ie(sdata, skb, false, band);
2841 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002842 ieee80211_tdls_add_ext_capab(skb);
2843 break;
2844 case WLAN_TDLS_SETUP_CONFIRM:
2845 tf->category = WLAN_CATEGORY_TDLS;
2846 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2847
2848 skb_put(skb, sizeof(tf->u.setup_cfm));
2849 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2850 tf->u.setup_cfm.dialog_token = dialog_token;
2851 break;
2852 case WLAN_TDLS_TEARDOWN:
2853 tf->category = WLAN_CATEGORY_TDLS;
2854 tf->action_code = WLAN_TDLS_TEARDOWN;
2855
2856 skb_put(skb, sizeof(tf->u.teardown));
2857 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2858 break;
2859 case WLAN_TDLS_DISCOVERY_REQUEST:
2860 tf->category = WLAN_CATEGORY_TDLS;
2861 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2862
2863 skb_put(skb, sizeof(tf->u.discover_req));
2864 tf->u.discover_req.dialog_token = dialog_token;
2865 break;
2866 default:
2867 return -EINVAL;
2868 }
2869
2870 return 0;
2871}
2872
2873static int
2874ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2875 u8 *peer, u8 action_code, u8 dialog_token,
2876 u16 status_code, struct sk_buff *skb)
2877{
2878 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg55de9082012-07-26 17:24:39 +02002879 enum ieee80211_band band = ieee80211_get_sdata_band(sdata);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002880 struct ieee80211_mgmt *mgmt;
2881
2882 mgmt = (void *)skb_put(skb, 24);
2883 memset(mgmt, 0, 24);
2884 memcpy(mgmt->da, peer, ETH_ALEN);
2885 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2886 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2887
2888 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2889 IEEE80211_STYPE_ACTION);
2890
2891 switch (action_code) {
2892 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2893 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2894 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2895 mgmt->u.action.u.tdls_discover_resp.action_code =
2896 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2897 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2898 dialog_token;
2899 mgmt->u.action.u.tdls_discover_resp.capability =
2900 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2901
Johannes Berg55de9082012-07-26 17:24:39 +02002902 ieee80211_add_srates_ie(sdata, skb, false, band);
2903 ieee80211_add_ext_srates_ie(sdata, skb, false, band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002904 ieee80211_tdls_add_ext_capab(skb);
2905 break;
2906 default:
2907 return -EINVAL;
2908 }
2909
2910 return 0;
2911}
2912
2913static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2914 u8 *peer, u8 action_code, u8 dialog_token,
2915 u16 status_code, const u8 *extra_ies,
2916 size_t extra_ies_len)
2917{
2918 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2919 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002920 struct sk_buff *skb = NULL;
2921 bool send_direct;
2922 int ret;
2923
2924 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2925 return -ENOTSUPP;
2926
2927 /* make sure we are in managed mode, and associated */
2928 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2929 !sdata->u.mgd.associated)
2930 return -EINVAL;
2931
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002932 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
2933 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002934
2935 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2936 max(sizeof(struct ieee80211_mgmt),
2937 sizeof(struct ieee80211_tdls_data)) +
2938 50 + /* supported rates */
2939 7 + /* ext capab */
2940 extra_ies_len +
2941 sizeof(struct ieee80211_tdls_lnkie));
2942 if (!skb)
2943 return -ENOMEM;
2944
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002945 skb_reserve(skb, local->hw.extra_tx_headroom);
2946
2947 switch (action_code) {
2948 case WLAN_TDLS_SETUP_REQUEST:
2949 case WLAN_TDLS_SETUP_RESPONSE:
2950 case WLAN_TDLS_SETUP_CONFIRM:
2951 case WLAN_TDLS_TEARDOWN:
2952 case WLAN_TDLS_DISCOVERY_REQUEST:
2953 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2954 action_code, dialog_token,
2955 status_code, skb);
2956 send_direct = false;
2957 break;
2958 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2959 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2960 dialog_token, status_code,
2961 skb);
2962 send_direct = true;
2963 break;
2964 default:
2965 ret = -ENOTSUPP;
2966 break;
2967 }
2968
2969 if (ret < 0)
2970 goto fail;
2971
2972 if (extra_ies_len)
2973 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2974
2975 /* the TDLS link IE is always added last */
2976 switch (action_code) {
2977 case WLAN_TDLS_SETUP_REQUEST:
2978 case WLAN_TDLS_SETUP_CONFIRM:
2979 case WLAN_TDLS_TEARDOWN:
2980 case WLAN_TDLS_DISCOVERY_REQUEST:
2981 /* we are the initiator */
2982 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2983 sdata->u.mgd.bssid);
2984 break;
2985 case WLAN_TDLS_SETUP_RESPONSE:
2986 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2987 /* we are the responder */
2988 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2989 sdata->u.mgd.bssid);
2990 break;
2991 default:
2992 ret = -ENOTSUPP;
2993 goto fail;
2994 }
2995
2996 if (send_direct) {
2997 ieee80211_tx_skb(sdata, skb);
2998 return 0;
2999 }
3000
3001 /*
3002 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
3003 * we should default to AC_VI.
3004 */
3005 switch (action_code) {
3006 case WLAN_TDLS_SETUP_REQUEST:
3007 case WLAN_TDLS_SETUP_RESPONSE:
3008 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
3009 skb->priority = 2;
3010 break;
3011 default:
3012 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
3013 skb->priority = 5;
3014 break;
3015 }
3016
3017 /* disable bottom halves when entering the Tx path */
3018 local_bh_disable();
3019 ret = ieee80211_subif_start_xmit(skb, dev);
3020 local_bh_enable();
3021
3022 return ret;
3023
3024fail:
3025 dev_kfree_skb(skb);
3026 return ret;
3027}
3028
3029static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
3030 u8 *peer, enum nl80211_tdls_operation oper)
3031{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003032 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003033 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3034
3035 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
3036 return -ENOTSUPP;
3037
3038 if (sdata->vif.type != NL80211_IFTYPE_STATION)
3039 return -EINVAL;
3040
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02003041 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003042
3043 switch (oper) {
3044 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003045 rcu_read_lock();
3046 sta = sta_info_get(sdata, peer);
3047 if (!sta) {
3048 rcu_read_unlock();
3049 return -ENOLINK;
3050 }
3051
Johannes Bergc2c98fd2011-09-29 16:04:36 +02003052 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03003053 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003054 break;
3055 case NL80211_TDLS_DISABLE_LINK:
3056 return sta_info_destroy_addr(sdata, peer);
3057 case NL80211_TDLS_TEARDOWN:
3058 case NL80211_TDLS_SETUP:
3059 case NL80211_TDLS_DISCOVERY_REQ:
3060 /* We don't support in-driver setup/teardown/discovery */
3061 return -ENOTSUPP;
3062 default:
3063 return -ENOTSUPP;
3064 }
3065
3066 return 0;
3067}
3068
Johannes Berg06500732011-11-04 11:18:16 +01003069static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
3070 const u8 *peer, u64 *cookie)
3071{
3072 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
3073 struct ieee80211_local *local = sdata->local;
3074 struct ieee80211_qos_hdr *nullfunc;
3075 struct sk_buff *skb;
3076 int size = sizeof(*nullfunc);
3077 __le16 fc;
3078 bool qos;
3079 struct ieee80211_tx_info *info;
3080 struct sta_info *sta;
Johannes Berg55de9082012-07-26 17:24:39 +02003081 struct ieee80211_chanctx_conf *chanctx_conf;
3082 enum ieee80211_band band;
Johannes Berg06500732011-11-04 11:18:16 +01003083
3084 rcu_read_lock();
Johannes Berg55de9082012-07-26 17:24:39 +02003085 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3086 if (WARN_ON(!chanctx_conf)) {
3087 rcu_read_unlock();
3088 return -EINVAL;
3089 }
Johannes Berg4bf88532012-11-09 11:39:59 +01003090 band = chanctx_conf->def.chan->band;
Johannes Berg06500732011-11-04 11:18:16 +01003091 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01003092 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01003093 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01003094 } else {
3095 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003096 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01003097 }
Johannes Berg06500732011-11-04 11:18:16 +01003098
3099 if (qos) {
3100 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3101 IEEE80211_STYPE_QOS_NULLFUNC |
3102 IEEE80211_FCTL_FROMDS);
3103 } else {
3104 size -= 2;
3105 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3106 IEEE80211_STYPE_NULLFUNC |
3107 IEEE80211_FCTL_FROMDS);
3108 }
3109
3110 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
Johannes Berg55de9082012-07-26 17:24:39 +02003111 if (!skb) {
3112 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003113 return -ENOMEM;
Johannes Berg55de9082012-07-26 17:24:39 +02003114 }
Johannes Berg06500732011-11-04 11:18:16 +01003115
3116 skb->dev = dev;
3117
3118 skb_reserve(skb, local->hw.extra_tx_headroom);
3119
3120 nullfunc = (void *) skb_put(skb, size);
3121 nullfunc->frame_control = fc;
3122 nullfunc->duration_id = 0;
3123 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3124 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3125 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3126 nullfunc->seq_ctrl = 0;
3127
3128 info = IEEE80211_SKB_CB(skb);
3129
3130 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3131 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3132
3133 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3134 skb->priority = 7;
3135 if (qos)
3136 nullfunc->qos_ctrl = cpu_to_le16(7);
3137
3138 local_bh_disable();
Johannes Berg55de9082012-07-26 17:24:39 +02003139 ieee80211_xmit(sdata, skb, band);
Johannes Berg06500732011-11-04 11:18:16 +01003140 local_bh_enable();
Johannes Berg55de9082012-07-26 17:24:39 +02003141 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01003142
3143 *cookie = (unsigned long) skb;
3144 return 0;
3145}
3146
Johannes Berg683b6d32012-11-08 21:25:48 +01003147static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
3148 struct wireless_dev *wdev,
3149 struct cfg80211_chan_def *chandef)
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003150{
Johannes Berg55de9082012-07-26 17:24:39 +02003151 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
3152 struct ieee80211_chanctx_conf *chanctx_conf;
Johannes Berg683b6d32012-11-08 21:25:48 +01003153 int ret = -ENODATA;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003154
Johannes Berg55de9082012-07-26 17:24:39 +02003155 rcu_read_lock();
3156 chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
3157 if (chanctx_conf) {
Johannes Berg4bf88532012-11-09 11:39:59 +01003158 *chandef = chanctx_conf->def;
Johannes Berg683b6d32012-11-08 21:25:48 +01003159 ret = 0;
Johannes Berg55de9082012-07-26 17:24:39 +02003160 }
3161 rcu_read_unlock();
3162
Johannes Berg683b6d32012-11-08 21:25:48 +01003163 return ret;
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003164}
3165
Johannes Berg6d525632012-04-04 15:05:25 +02003166#ifdef CONFIG_PM
3167static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3168{
3169 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3170}
3171#endif
3172
Jiri Bencf0706e82007-05-05 11:45:53 -07003173struct cfg80211_ops mac80211_config_ops = {
3174 .add_virtual_intf = ieee80211_add_iface,
3175 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003176 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003177 .start_p2p_device = ieee80211_start_p2p_device,
3178 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003179 .add_key = ieee80211_add_key,
3180 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003181 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003182 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003183 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003184 .start_ap = ieee80211_start_ap,
3185 .change_beacon = ieee80211_change_beacon,
3186 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003187 .add_station = ieee80211_add_station,
3188 .del_station = ieee80211_del_station,
3189 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003190 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003191 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003192 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003193#ifdef CONFIG_MAC80211_MESH
3194 .add_mpath = ieee80211_add_mpath,
3195 .del_mpath = ieee80211_del_mpath,
3196 .change_mpath = ieee80211_change_mpath,
3197 .get_mpath = ieee80211_get_mpath,
3198 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003199 .update_mesh_config = ieee80211_update_mesh_config,
3200 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003201 .join_mesh = ieee80211_join_mesh,
3202 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003203#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003204 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003205 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003206 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003207 .suspend = ieee80211_suspend,
3208 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003209 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003210 .sched_scan_start = ieee80211_sched_scan_start,
3211 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003212 .auth = ieee80211_auth,
3213 .assoc = ieee80211_assoc,
3214 .deauth = ieee80211_deauth,
3215 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003216 .join_ibss = ieee80211_join_ibss,
3217 .leave_ibss = ieee80211_leave_ibss,
Antonio Quartulli391e53e2012-11-02 13:27:49 +01003218 .set_mcast_rate = ieee80211_set_mcast_rate,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003219 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003220 .set_tx_power = ieee80211_set_tx_power,
3221 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003222 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003223 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003224 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003225 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003226 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003227 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003228 .remain_on_channel = ieee80211_remain_on_channel,
3229 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003230 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003231 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003232 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003233 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003234 .set_antenna = ieee80211_set_antenna,
3235 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003236 .set_ringparam = ieee80211_set_ringparam,
3237 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003238 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003239 .tdls_oper = ieee80211_tdls_oper,
3240 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003241 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003242 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003243#ifdef CONFIG_PM
3244 .set_wakeup = ieee80211_set_wakeup,
3245#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003246 .get_et_sset_count = ieee80211_get_et_sset_count,
3247 .get_et_stats = ieee80211_get_et_stats,
3248 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003249 .get_channel = ieee80211_cfg_get_channel,
Jiri Bencf0706e82007-05-05 11:45:53 -07003250};