blob: 7371f676cf412e54481751d36bf757f42dfa5134 [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
Felix Fietkau3af63342011-02-27 22:08:01 +0100373static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
374{
375 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
376 struct ieee80211_supported_band *sband;
377 sband = sta->local->hw.wiphy->bands[
Johannes Berg679ef4e2012-07-23 14:29:21 +0200378 sta->local->oper_channel->band];
Felix Fietkau3af63342011-02-27 22:08:01 +0100379 rate->legacy = sband->bitrates[idx].bitrate;
380 } else
381 rate->mcs = idx;
382}
383
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800384void sta_set_rate_info_tx(struct sta_info *sta,
385 const struct ieee80211_tx_rate *rate,
386 struct rate_info *rinfo)
387{
388 rinfo->flags = 0;
389 if (rate->flags & IEEE80211_TX_RC_MCS)
390 rinfo->flags |= RATE_INFO_FLAGS_MCS;
391 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
392 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
393 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
394 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
395 rate_idx_to_bitrate(rinfo, sta, rate->idx);
396}
397
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100398static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
399{
Johannes Bergd0709a62008-02-25 16:27:46 +0100400 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300401 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530402 struct timespec uptime;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100403
Johannes Bergf5ea9122009-08-07 16:17:38 +0200404 sinfo->generation = sdata->local->sta_generation;
405
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100406 sinfo->filled = STATION_INFO_INACTIVE_TIME |
407 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100408 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200409 STATION_INFO_RX_PACKETS |
410 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900411 STATION_INFO_TX_RETRIES |
412 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700413 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100414 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700415 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530416 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200417 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800418 STATION_INFO_STA_FLAGS |
419 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530420
421 do_posix_clock_monotonic_gettime(&uptime);
422 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100423
424 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
425 sinfo->rx_bytes = sta->rx_bytes;
426 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200427 sinfo->rx_packets = sta->rx_packets;
428 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900429 sinfo->tx_retries = sta->tx_retry_count;
430 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700431 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800432 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100433
John W. Linville19deffb2009-12-08 17:10:13 -0500434 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
435 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900436 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300437 if (!local->ops->get_rssi ||
438 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
439 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900440 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100441 }
442
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800443 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100444
Felix Fietkau3af63342011-02-27 22:08:01 +0100445 sinfo->rxrate.flags = 0;
446 if (sta->last_rx_rate_flag & RX_FLAG_HT)
447 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
448 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
449 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
450 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
451 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
452 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100453
Johannes Berg902acc72008-02-23 15:17:19 +0100454 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100455#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100456 sinfo->filled |= STATION_INFO_LLID |
457 STATION_INFO_PLID |
458 STATION_INFO_PLINK_STATE;
459
460 sinfo->llid = le16_to_cpu(sta->llid);
461 sinfo->plid = le16_to_cpu(sta->plid);
462 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700463 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
464 sinfo->filled |= STATION_INFO_T_OFFSET;
465 sinfo->t_offset = sta->t_offset;
466 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100467#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100468 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700469
470 sinfo->bss_param.flags = 0;
471 if (sdata->vif.bss_conf.use_cts_prot)
472 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
473 if (sdata->vif.bss_conf.use_short_preamble)
474 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
475 if (sdata->vif.bss_conf.use_short_slot)
476 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
477 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
478 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200479
480 sinfo->sta_flags.set = 0;
481 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
482 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
483 BIT(NL80211_STA_FLAG_WME) |
484 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100485 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
486 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200487 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
488 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
489 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
490 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
491 if (test_sta_flag(sta, WLAN_STA_WME))
492 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
493 if (test_sta_flag(sta, WLAN_STA_MFP))
494 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
495 if (test_sta_flag(sta, WLAN_STA_AUTH))
496 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100497 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
498 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100499}
500
Ben Greearb1ab7922012-04-23 12:50:30 -0700501static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
502 "rx_packets", "rx_bytes", "wep_weak_iv_count",
503 "rx_duplicates", "rx_fragments", "rx_dropped",
504 "tx_packets", "tx_bytes", "tx_fragments",
505 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700506 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
507 "channel", "noise", "ch_time", "ch_time_busy",
508 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700509};
510#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
511
512static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
513 struct net_device *dev,
514 int sset)
515{
Ben Greeare3521142012-04-23 12:50:31 -0700516 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
517 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700518
Ben Greeare3521142012-04-23 12:50:31 -0700519 if (sset == ETH_SS_STATS)
520 rv += STA_STATS_LEN;
521
522 rv += drv_get_et_sset_count(sdata, sset);
523
524 if (rv == 0)
525 return -EOPNOTSUPP;
526 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700527}
528
529static void ieee80211_get_et_stats(struct wiphy *wiphy,
530 struct net_device *dev,
531 struct ethtool_stats *stats,
532 u64 *data)
533{
534 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
535 struct sta_info *sta;
536 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700537 struct station_info sinfo;
538 struct survey_info survey;
539 int i, q;
540#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700541
542 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
543
544#define ADD_STA_STATS(sta) \
545 do { \
546 data[i++] += sta->rx_packets; \
547 data[i++] += sta->rx_bytes; \
548 data[i++] += sta->wep_weak_iv_count; \
549 data[i++] += sta->num_duplicates; \
550 data[i++] += sta->rx_fragments; \
551 data[i++] += sta->rx_dropped; \
552 \
553 data[i++] += sta->tx_packets; \
554 data[i++] += sta->tx_bytes; \
555 data[i++] += sta->tx_fragments; \
556 data[i++] += sta->tx_filtered_count; \
557 data[i++] += sta->tx_retry_failed; \
558 data[i++] += sta->tx_retry_count; \
559 data[i++] += sta->beacon_loss_count; \
560 } while (0)
561
562 /* For Managed stations, find the single station based on BSSID
563 * and use that. For interface types, iterate through all available
564 * stations and add stats for any station that is assigned to this
565 * network device.
566 */
567
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300568 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700569
570 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
571 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700572
573 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
574 goto do_survey;
575
576 i = 0;
577 ADD_STA_STATS(sta);
578
579 data[i++] = sta->sta_state;
580
581 sinfo.filled = 0;
582 sta_set_sinfo(sta, &sinfo);
583
Joe Perches52042672012-05-30 13:25:54 -0700584 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700585 data[i] = 100000 *
586 cfg80211_calculate_bitrate(&sinfo.txrate);
587 i++;
Joe Perches52042672012-05-30 13:25:54 -0700588 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700589 data[i] = 100000 *
590 cfg80211_calculate_bitrate(&sinfo.rxrate);
591 i++;
592
Joe Perches52042672012-05-30 13:25:54 -0700593 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700594 data[i] = (u8)sinfo.signal_avg;
595 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700596 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300597 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700598 /* Make sure this station belongs to the proper dev */
599 if (sta->sdata->dev != dev)
600 continue;
601
602 i = 0;
603 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700604 }
605 }
606
Ben Greear3073a7c2012-04-23 12:50:32 -0700607do_survey:
608 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
609 /* Get survey stats for current channel */
610 q = 0;
611 while (true) {
612 survey.filled = 0;
613 if (drv_get_survey(local, q, &survey) != 0) {
614 survey.filled = 0;
615 break;
616 }
617
618 if (survey.channel &&
619 (local->oper_channel->center_freq ==
620 survey.channel->center_freq))
621 break;
622 q++;
623 }
624
625 if (survey.filled)
626 data[i++] = survey.channel->center_freq;
627 else
628 data[i++] = 0;
629 if (survey.filled & SURVEY_INFO_NOISE_DBM)
630 data[i++] = (u8)survey.noise;
631 else
632 data[i++] = -1LL;
633 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
634 data[i++] = survey.channel_time;
635 else
636 data[i++] = -1LL;
637 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
638 data[i++] = survey.channel_time_busy;
639 else
640 data[i++] = -1LL;
641 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
642 data[i++] = survey.channel_time_ext_busy;
643 else
644 data[i++] = -1LL;
645 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
646 data[i++] = survey.channel_time_rx;
647 else
648 data[i++] = -1LL;
649 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
650 data[i++] = survey.channel_time_tx;
651 else
652 data[i++] = -1LL;
653
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300654 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700655
Ben Greear3073a7c2012-04-23 12:50:32 -0700656 if (WARN_ON(i != STA_STATS_LEN))
657 return;
658
Ben Greeare3521142012-04-23 12:50:31 -0700659 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700660}
661
662static void ieee80211_get_et_strings(struct wiphy *wiphy,
663 struct net_device *dev,
664 u32 sset, u8 *data)
665{
Ben Greeare3521142012-04-23 12:50:31 -0700666 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
667 int sz_sta_stats = 0;
668
Ben Greearb1ab7922012-04-23 12:50:30 -0700669 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700670 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700671 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
672 }
Ben Greeare3521142012-04-23 12:50:31 -0700673 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700674}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100675
676static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
677 int idx, u8 *mac, struct station_info *sinfo)
678{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100679 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300680 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100681 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100682 int ret = -ENOENT;
683
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300684 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100685
Johannes Berg3b53fde82009-11-16 12:00:37 +0100686 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100687 if (sta) {
688 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200689 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100690 sta_set_sinfo(sta, sinfo);
691 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100692
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300693 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100694
Johannes Bergd0709a62008-02-25 16:27:46 +0100695 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100696}
697
Holger Schurig12897232010-04-19 10:23:57 +0200698static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
699 int idx, struct survey_info *survey)
700{
701 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
702
Holger Schurig12897232010-04-19 10:23:57 +0200703 return drv_get_survey(local, idx, survey);
704}
705
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100706static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100707 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100708{
Johannes Bergabe60632009-11-25 17:46:18 +0100709 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300710 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100711 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100712 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100713
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300714 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100715
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100716 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100717 if (sta) {
718 ret = 0;
719 sta_set_sinfo(sta, sinfo);
720 }
721
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300722 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100723
724 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100725}
726
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200727static int ieee80211_set_channel(struct wiphy *wiphy,
728 struct net_device *netdev,
729 struct ieee80211_channel *chan,
730 enum nl80211_channel_type channel_type)
731{
732 struct ieee80211_local *local = wiphy_priv(wiphy);
733 struct ieee80211_sub_if_data *sdata = NULL;
734
735 if (netdev)
736 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
737
738 switch (ieee80211_get_channel_mode(local, NULL)) {
739 case CHAN_MODE_HOPPING:
740 return -EBUSY;
741 case CHAN_MODE_FIXED:
Pontus Fuchsac4d82f2012-06-12 14:13:19 +0200742 if (local->oper_channel != chan ||
743 (!sdata && local->_oper_channel_type != channel_type))
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200744 return -EBUSY;
745 if (!sdata && local->_oper_channel_type == channel_type)
746 return 0;
747 break;
748 case CHAN_MODE_UNDEFINED:
749 break;
750 }
751
752 if (!ieee80211_set_channel_type(local, sdata, channel_type))
753 return -EBUSY;
754
755 local->oper_channel = chan;
756
757 /* auto-detects changes */
758 ieee80211_hw_config(local, 0);
759
760 return 0;
761}
762
Johannes Berge8c9bd52012-06-06 08:18:22 +0200763static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
764 struct ieee80211_channel *chan,
765 enum nl80211_channel_type channel_type)
766{
767 return ieee80211_set_channel(wiphy, NULL, chan, channel_type);
768}
769
Arik Nemtsov02945822011-11-10 11:28:57 +0200770static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100771 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200772{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300773 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200774
775 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530776 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200777
Arik Nemtsovf7248282011-11-19 10:51:26 +0200778 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200779
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300780 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200781 if (!new)
782 return -ENOMEM;
783
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300784 new->len = resp_len;
785 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200786
787 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300788 if (old)
789 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200790
791 return 0;
792}
793
Johannes Berg88600202012-02-13 15:17:18 +0100794static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
795 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100796{
797 struct beacon_data *new, *old;
798 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100799 int size, err;
800 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100801
Johannes Berg40b275b2011-05-13 14:15:49 +0200802 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100803
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100804 /* Need to have a beacon head if we don't have one yet */
805 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100806 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100807
808 /* new or old head? */
809 if (params->head)
810 new_head_len = params->head_len;
811 else
812 new_head_len = old->head_len;
813
814 /* new or old tail? */
815 if (params->tail || !old)
816 /* params->tail_len will be zero for !params->tail */
817 new_tail_len = params->tail_len;
818 else
819 new_tail_len = old->tail_len;
820
821 size = sizeof(*new) + new_head_len + new_tail_len;
822
823 new = kzalloc(size, GFP_KERNEL);
824 if (!new)
825 return -ENOMEM;
826
827 /* start filling the new info now */
828
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100829 /*
830 * pointers go into the block we allocated,
831 * memory is | beacon_data | head | tail |
832 */
833 new->head = ((u8 *) new) + sizeof(*new);
834 new->tail = new->head + new_head_len;
835 new->head_len = new_head_len;
836 new->tail_len = new_tail_len;
837
838 /* copy in head */
839 if (params->head)
840 memcpy(new->head, params->head, new_head_len);
841 else
842 memcpy(new->head, old->head, new_head_len);
843
844 /* copy in optional tail */
845 if (params->tail)
846 memcpy(new->tail, params->tail, new_tail_len);
847 else
848 if (old)
849 memcpy(new->tail, old->tail, new_tail_len);
850
Johannes Berg88600202012-02-13 15:17:18 +0100851 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
852 params->probe_resp_len);
853 if (err < 0)
854 return err;
855 if (err == 0)
856 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100857
Eric Dumazetcf778b02012-01-12 04:41:32 +0000858 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100859
Johannes Berg88600202012-02-13 15:17:18 +0100860 if (old)
861 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100862
Johannes Berg88600202012-02-13 15:17:18 +0100863 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100864}
865
Johannes Berg88600202012-02-13 15:17:18 +0100866static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
867 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100868{
Johannes Berg88600202012-02-13 15:17:18 +0100869 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100870 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100871 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100872 u32 changed = BSS_CHANGED_BEACON_INT |
873 BSS_CHANGED_BEACON_ENABLED |
874 BSS_CHANGED_BEACON |
875 BSS_CHANGED_SSID;
876 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200877
Johannes Berg40b275b2011-05-13 14:15:49 +0200878 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100879 if (old)
880 return -EALREADY;
881
Johannes Bergaa430da2012-05-16 23:50:18 +0200882 err = ieee80211_set_channel(wiphy, dev, params->channel,
883 params->channel_type);
884 if (err)
885 return err;
886
Johannes Berg665c93a2011-11-04 11:18:11 +0100887 /*
888 * Apply control port protocol, this allows us to
889 * not encrypt dynamic WEP control frames.
890 */
891 sdata->control_port_protocol = params->crypto.control_port_ethertype;
892 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
893 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
894 vlan->control_port_protocol =
895 params->crypto.control_port_ethertype;
896 vlan->control_port_no_encrypt =
897 params->crypto.control_port_no_encrypt;
898 }
899
Johannes Berg88600202012-02-13 15:17:18 +0100900 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
901 sdata->vif.bss_conf.dtim_period = params->dtim_period;
902
903 sdata->vif.bss_conf.ssid_len = params->ssid_len;
904 if (params->ssid_len)
905 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
906 params->ssid_len);
907 sdata->vif.bss_conf.hidden_ssid =
908 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
909
910 err = ieee80211_assign_beacon(sdata, &params->beacon);
911 if (err < 0)
912 return err;
913 changed |= err;
914
915 ieee80211_bss_info_change_notify(sdata, changed);
916
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200917 netif_carrier_on(dev);
918 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
919 netif_carrier_on(vlan->dev);
920
Johannes Berg665c93a2011-11-04 11:18:11 +0100921 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100922}
923
Johannes Berg88600202012-02-13 15:17:18 +0100924static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
925 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100926{
Johannes Berg14db74b2008-07-29 13:22:52 +0200927 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100928 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100929 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100930
Johannes Berg14db74b2008-07-29 13:22:52 +0200931 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
932
Johannes Berg40b275b2011-05-13 14:15:49 +0200933 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100934 if (!old)
935 return -ENOENT;
936
Johannes Berg88600202012-02-13 15:17:18 +0100937 err = ieee80211_assign_beacon(sdata, params);
938 if (err < 0)
939 return err;
940 ieee80211_bss_info_change_notify(sdata, err);
941 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100942}
943
Johannes Berg88600202012-02-13 15:17:18 +0100944static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100945{
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200946 struct ieee80211_sub_if_data *sdata, *vlan;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100947 struct beacon_data *old;
948
Johannes Berg14db74b2008-07-29 13:22:52 +0200949 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
950
Johannes Berg40b275b2011-05-13 14:15:49 +0200951 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100952 if (!old)
953 return -ENOENT;
954
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200955 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
956 netif_carrier_off(vlan->dev);
957 netif_carrier_off(dev);
958
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000959 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100960
961 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100962
Eliad Peller99102bd2012-07-18 15:36:04 +0300963 sta_info_flush(sdata->local, sdata);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200964 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100965
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200966 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100967}
968
Johannes Berg4fd69312007-12-19 02:03:35 +0100969/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
970struct iapp_layer2_update {
971 u8 da[ETH_ALEN]; /* broadcast */
972 u8 sa[ETH_ALEN]; /* STA addr */
973 __be16 len; /* 6 */
974 u8 dsap; /* 0 */
975 u8 ssap; /* 0 */
976 u8 control;
977 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700978} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100979
980static void ieee80211_send_layer2_update(struct sta_info *sta)
981{
982 struct iapp_layer2_update *msg;
983 struct sk_buff *skb;
984
985 /* Send Level 2 Update Frame to update forwarding tables in layer 2
986 * bridge devices */
987
988 skb = dev_alloc_skb(sizeof(*msg));
989 if (!skb)
990 return;
991 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
992
993 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
994 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
995
Johannes Berge83e6542012-07-13 16:23:07 +0200996 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200997 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100998 msg->len = htons(6);
999 msg->dsap = 0;
1000 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1001 msg->control = 0xaf; /* XID response lsb.1111F101.
1002 * F=0 (no poll command; unsolicited frame) */
1003 msg->xid_info[0] = 0x81; /* XID format identifier */
1004 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1005 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1006
Johannes Bergd0709a62008-02-25 16:27:46 +01001007 skb->dev = sta->sdata->dev;
1008 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001009 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001010 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001011}
1012
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001013static int sta_apply_parameters(struct ieee80211_local *local,
1014 struct sta_info *sta,
1015 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001016{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001017 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001018 u32 rates;
1019 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +01001020 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001021 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +03001022 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001023
Johannes Bergae5eb022008-10-14 16:58:37 +02001024 sband = local->hw.wiphy->bands[local->oper_channel->band];
1025
Johannes Bergeccb8e82009-05-11 21:57:56 +03001026 mask = params->sta_flags_mask;
1027 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001028
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001029 /*
1030 * In mesh mode, we can clear AUTHENTICATED flag but must
1031 * also make ASSOCIATED follow appropriately for the driver
1032 * API. See also below, after AUTHORIZED changes.
1033 */
1034 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1035 /* cfg80211 should not allow this in non-mesh modes */
1036 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1037 return -EINVAL;
1038
1039 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1040 !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001041 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001042 if (ret)
1043 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001044 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001045 if (ret)
1046 return ret;
1047 }
1048 }
1049
Johannes Bergeccb8e82009-05-11 21:57:56 +03001050 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001051 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001052 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Berg543d1b92012-01-13 14:17:59 +01001053 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001054 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001055 if (ret)
1056 return ret;
Johannes Berg4fd69312007-12-19 02:03:35 +01001057 }
1058
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001059 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1060 /* cfg80211 should not allow this in non-mesh modes */
1061 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1062 return -EINVAL;
1063
1064 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1065 test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001066 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001067 if (ret)
1068 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001069 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001070 if (ret)
1071 return ret;
1072 }
1073 }
1074
1075
Johannes Bergeccb8e82009-05-11 21:57:56 +03001076 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001077 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001078 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1079 else
1080 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001081 }
1082
1083 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001084 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001085 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001086 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001087 } else {
1088 clear_sta_flag(sta, WLAN_STA_WME);
1089 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001090 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001091 }
1092
1093 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001094 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001095 set_sta_flag(sta, WLAN_STA_MFP);
1096 else
1097 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001098 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001099
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001100 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001101 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001102 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1103 else
1104 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001105 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001106
Johannes Berg3b9ce802011-09-27 20:56:12 +02001107 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1108 sta->sta.uapsd_queues = params->uapsd_queues;
1109 sta->sta.max_sp = params->max_sp;
1110 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001111
Johannes Berg73651ee2008-02-25 16:27:47 +01001112 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001113 * cfg80211 validates this (1-2007) and allows setting the AID
1114 * only when creating a new station entry
1115 */
1116 if (params->aid)
1117 sta->sta.aid = params->aid;
1118
1119 /*
Johannes Berg73651ee2008-02-25 16:27:47 +01001120 * FIXME: updating the following information is racy when this
1121 * function is called from ieee80211_change_station().
1122 * However, all this information should be static so
1123 * maybe we should just reject attemps to change it.
1124 */
1125
Johannes Berg4fd69312007-12-19 02:03:35 +01001126 if (params->listen_interval >= 0)
1127 sta->listen_interval = params->listen_interval;
1128
1129 if (params->supported_rates) {
1130 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001131
Johannes Berg4fd69312007-12-19 02:03:35 +01001132 for (i = 0; i < params->supported_rates_len; i++) {
1133 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001134 for (j = 0; j < sband->n_bitrates; j++) {
1135 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001136 rates |= BIT(j);
1137 }
1138 }
Johannes Berg323ce792008-09-11 02:45:11 +02001139 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001140 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001141
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001142 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001143 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +02001144 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001145 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001146
Javier Cardona9c3990a2011-05-03 16:57:11 -07001147 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001148#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -07001149 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
1150 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001151 case NL80211_PLINK_LISTEN:
1152 case NL80211_PLINK_ESTAB:
1153 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -07001154 sta->plink_state = params->plink_state;
1155 break;
1156 default:
1157 /* nothing */
1158 break;
1159 }
1160 else
1161 switch (params->plink_action) {
1162 case PLINK_ACTION_OPEN:
1163 mesh_plink_open(sta);
1164 break;
1165 case PLINK_ACTION_BLOCK:
1166 mesh_plink_block(sta);
1167 break;
1168 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001169#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001170 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001171
1172 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001173}
1174
1175static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1176 u8 *mac, struct station_parameters *params)
1177{
Johannes Berg14db74b2008-07-29 13:22:52 +02001178 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001179 struct sta_info *sta;
1180 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001181 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001182 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001183
Johannes Berg4fd69312007-12-19 02:03:35 +01001184 if (params->vlan) {
1185 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1186
Johannes Berg05c914f2008-09-11 00:01:58 +02001187 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1188 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001189 return -EINVAL;
1190 } else
1191 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1192
Joe Perchesb203ca32012-05-08 18:56:52 +00001193 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001194 return -EINVAL;
1195
1196 if (is_multicast_ether_addr(mac))
1197 return -EINVAL;
1198
1199 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001200 if (!sta)
1201 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001202
Johannes Berg83d5cc02012-01-12 09:31:10 +01001203 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1204 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +01001205
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001206 err = sta_apply_parameters(local, sta, params);
1207 if (err) {
1208 sta_info_free(local, sta);
1209 return err;
1210 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001211
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001212 /*
1213 * for TDLS, rate control should be initialized only when supported
1214 * rates are known.
1215 */
1216 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1217 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001218
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001219 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1220 sdata->vif.type == NL80211_IFTYPE_AP;
1221
Johannes Berg34e89502010-02-03 13:59:58 +01001222 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001223 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001224 rcu_read_unlock();
1225 return err;
1226 }
1227
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001228 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001229 ieee80211_send_layer2_update(sta);
1230
1231 rcu_read_unlock();
1232
Johannes Berg4fd69312007-12-19 02:03:35 +01001233 return 0;
1234}
1235
1236static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1237 u8 *mac)
1238{
Johannes Berg14db74b2008-07-29 13:22:52 +02001239 struct ieee80211_local *local = wiphy_priv(wiphy);
1240 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001241
Johannes Berg14db74b2008-07-29 13:22:52 +02001242 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1243
Johannes Berg34e89502010-02-03 13:59:58 +01001244 if (mac)
1245 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001246
Johannes Berg34e89502010-02-03 13:59:58 +01001247 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001248 return 0;
1249}
1250
1251static int ieee80211_change_station(struct wiphy *wiphy,
1252 struct net_device *dev,
1253 u8 *mac,
1254 struct station_parameters *params)
1255{
Johannes Bergabe60632009-11-25 17:46:18 +01001256 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001257 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001258 struct sta_info *sta;
1259 struct ieee80211_sub_if_data *vlansdata;
Eliad Peller35b88622011-12-29 14:41:39 +02001260 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001261
Johannes Berg87be1e12011-12-14 12:20:29 +01001262 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001263
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001264 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001265 if (!sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001266 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001267 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001268 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001269
Johannes Bergbdd90d52011-12-14 12:20:27 +01001270 /* in station mode, supported rates are only valid with TDLS */
1271 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1272 params->supported_rates &&
1273 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001274 mutex_unlock(&local->sta_mtx);
Johannes Bergbdd90d52011-12-14 12:20:27 +01001275 return -EINVAL;
1276 }
1277
Johannes Bergd0709a62008-02-25 16:27:46 +01001278 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001279 bool prev_4addr = false;
1280 bool new_4addr = false;
1281
Johannes Berg4fd69312007-12-19 02:03:35 +01001282 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1283
Johannes Berg05c914f2008-09-11 00:01:58 +02001284 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1285 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001286 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001287 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001288 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001289
Johannes Berg9bc383d2009-11-19 11:55:19 +01001290 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001291 if (vlansdata->u.vlan.sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001292 mutex_unlock(&local->sta_mtx);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001293 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +01001294 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001295
Eric Dumazetcf778b02012-01-12 04:41:32 +00001296 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001297 new_4addr = true;
1298 }
1299
1300 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1301 sta->sdata->u.vlan.sta) {
1302 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1303 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001304 }
1305
Johannes Berg14db74b2008-07-29 13:22:52 +02001306 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001307
1308 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1309 prev_4addr != new_4addr) {
1310 if (new_4addr)
1311 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1312 else
1313 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1314 }
1315
Johannes Berg4fd69312007-12-19 02:03:35 +01001316 ieee80211_send_layer2_update(sta);
1317 }
1318
Eliad Peller35b88622011-12-29 14:41:39 +02001319 err = sta_apply_parameters(local, sta, params);
1320 if (err) {
1321 mutex_unlock(&local->sta_mtx);
1322 return err;
1323 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001324
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001325 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1326 rate_control_rate_init(sta);
1327
Johannes Berg87be1e12011-12-14 12:20:29 +01001328 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001329
Jason Young808118c2011-03-10 16:43:19 -08001330 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001331 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001332 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001333 ieee80211_recalc_ps_vif(sdata);
1334 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001335 return 0;
1336}
1337
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001338#ifdef CONFIG_MAC80211_MESH
1339static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1340 u8 *dst, u8 *next_hop)
1341{
Johannes Berg14db74b2008-07-29 13:22:52 +02001342 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001343 struct mesh_path *mpath;
1344 struct sta_info *sta;
1345 int err;
1346
Johannes Berg14db74b2008-07-29 13:22:52 +02001347 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1348
Johannes Bergd0709a62008-02-25 16:27:46 +01001349 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001350 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001351 if (!sta) {
1352 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001353 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001354 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001355
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001356 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +01001357 if (err) {
1358 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001359 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001360 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001361
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001362 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001363 if (!mpath) {
1364 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001365 return -ENXIO;
1366 }
1367 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001368
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001369 rcu_read_unlock();
1370 return 0;
1371}
1372
1373static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1374 u8 *dst)
1375{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001376 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001377
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001378 if (dst)
1379 return mesh_path_del(dst, sdata);
1380
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001381 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001382 return 0;
1383}
1384
1385static int ieee80211_change_mpath(struct wiphy *wiphy,
1386 struct net_device *dev,
1387 u8 *dst, u8 *next_hop)
1388{
Johannes Berg14db74b2008-07-29 13:22:52 +02001389 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001390 struct mesh_path *mpath;
1391 struct sta_info *sta;
1392
Johannes Berg14db74b2008-07-29 13:22:52 +02001393 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1394
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001395 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001396
Johannes Bergabe60632009-11-25 17:46:18 +01001397 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001398 if (!sta) {
1399 rcu_read_unlock();
1400 return -ENOENT;
1401 }
1402
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001403 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001404 if (!mpath) {
1405 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001406 return -ENOENT;
1407 }
1408
1409 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001410
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001411 rcu_read_unlock();
1412 return 0;
1413}
1414
1415static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1416 struct mpath_info *pinfo)
1417{
Johannes Berga3836e02011-05-12 15:11:37 +02001418 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1419
1420 if (next_hop_sta)
1421 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001422 else
1423 memset(next_hop, 0, ETH_ALEN);
1424
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001425 memset(pinfo, 0, sizeof(*pinfo));
1426
Johannes Bergf5ea9122009-08-07 16:17:38 +02001427 pinfo->generation = mesh_paths_generation;
1428
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001429 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001430 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001431 MPATH_INFO_METRIC |
1432 MPATH_INFO_EXPTIME |
1433 MPATH_INFO_DISCOVERY_TIMEOUT |
1434 MPATH_INFO_DISCOVERY_RETRIES |
1435 MPATH_INFO_FLAGS;
1436
1437 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001438 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001439 pinfo->metric = mpath->metric;
1440 if (time_before(jiffies, mpath->exp_time))
1441 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1442 pinfo->discovery_timeout =
1443 jiffies_to_msecs(mpath->discovery_timeout);
1444 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001445 if (mpath->flags & MESH_PATH_ACTIVE)
1446 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1447 if (mpath->flags & MESH_PATH_RESOLVING)
1448 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001449 if (mpath->flags & MESH_PATH_SN_VALID)
1450 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001451 if (mpath->flags & MESH_PATH_FIXED)
1452 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001453 if (mpath->flags & MESH_PATH_RESOLVED)
1454 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001455}
1456
1457static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1458 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1459
1460{
Johannes Berg14db74b2008-07-29 13:22:52 +02001461 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001462 struct mesh_path *mpath;
1463
Johannes Berg14db74b2008-07-29 13:22:52 +02001464 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1465
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001466 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001467 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001468 if (!mpath) {
1469 rcu_read_unlock();
1470 return -ENOENT;
1471 }
1472 memcpy(dst, mpath->dst, ETH_ALEN);
1473 mpath_set_pinfo(mpath, next_hop, pinfo);
1474 rcu_read_unlock();
1475 return 0;
1476}
1477
1478static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1479 int idx, u8 *dst, u8 *next_hop,
1480 struct mpath_info *pinfo)
1481{
Johannes Berg14db74b2008-07-29 13:22:52 +02001482 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001483 struct mesh_path *mpath;
1484
Johannes Berg14db74b2008-07-29 13:22:52 +02001485 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1486
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001487 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001488 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001489 if (!mpath) {
1490 rcu_read_unlock();
1491 return -ENOENT;
1492 }
1493 memcpy(dst, mpath->dst, ETH_ALEN);
1494 mpath_set_pinfo(mpath, next_hop, pinfo);
1495 rcu_read_unlock();
1496 return 0;
1497}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001498
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001499static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001500 struct net_device *dev,
1501 struct mesh_config *conf)
1502{
1503 struct ieee80211_sub_if_data *sdata;
1504 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1505
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001506 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1507 return 0;
1508}
1509
1510static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1511{
1512 return (mask >> (parm-1)) & 0x1;
1513}
1514
Javier Cardonac80d5452010-12-16 17:37:49 -08001515static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1516 const struct mesh_setup *setup)
1517{
1518 u8 *new_ie;
1519 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001520 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1521 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001522
Javier Cardona581a8b02011-04-07 15:08:27 -07001523 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001524 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001525 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001526
Javier Cardona581a8b02011-04-07 15:08:27 -07001527 if (setup->ie_len) {
1528 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001529 GFP_KERNEL);
1530 if (!new_ie)
1531 return -ENOMEM;
1532 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001533 ifmsh->ie_len = setup->ie_len;
1534 ifmsh->ie = new_ie;
1535 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001536
1537 /* now copy the rest of the setup parameters */
1538 ifmsh->mesh_id_len = setup->mesh_id_len;
1539 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001540 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001541 ifmsh->mesh_pp_id = setup->path_sel_proto;
1542 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001543 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1544 if (setup->is_authenticated)
1545 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1546 if (setup->is_secure)
1547 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001548
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001549 /* mcast rate setting in Mesh Node */
1550 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1551 sizeof(setup->mcast_rate));
1552
Javier Cardonac80d5452010-12-16 17:37:49 -08001553 return 0;
1554}
1555
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001556static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001557 struct net_device *dev, u32 mask,
1558 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001559{
1560 struct mesh_config *conf;
1561 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001562 struct ieee80211_if_mesh *ifmsh;
1563
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001564 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001565 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001566
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001567 /* Set the config options which we are interested in setting */
1568 conf = &(sdata->u.mesh.mshcfg);
1569 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1570 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1571 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1572 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1573 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1574 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1575 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1576 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1577 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1578 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1579 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1580 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001581 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001582 conf->element_ttl = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001583 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1584 conf->auto_open_plinks = nconf->auto_open_plinks;
Javier Cardonad299a1f2012-03-31 11:31:33 -07001585 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1586 conf->dot11MeshNbrOffsetMaxNeighbor =
1587 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001588 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1589 conf->dot11MeshHWMPmaxPREQretries =
1590 nconf->dot11MeshHWMPmaxPREQretries;
1591 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1592 conf->path_refresh_time = nconf->path_refresh_time;
1593 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1594 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1595 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1596 conf->dot11MeshHWMPactivePathTimeout =
1597 nconf->dot11MeshHWMPactivePathTimeout;
1598 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1599 conf->dot11MeshHWMPpreqMinInterval =
1600 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001601 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1602 conf->dot11MeshHWMPperrMinInterval =
1603 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001604 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1605 mask))
1606 conf->dot11MeshHWMPnetDiameterTraversalTime =
1607 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001608 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1609 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1610 ieee80211_mesh_root_setup(ifmsh);
1611 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001612 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001613 /* our current gate announcement implementation rides on root
1614 * announcements, so require this ifmsh to also be a root node
1615 * */
1616 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001617 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1618 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001619 ieee80211_mesh_root_setup(ifmsh);
1620 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001621 conf->dot11MeshGateAnnouncementProtocol =
1622 nconf->dot11MeshGateAnnouncementProtocol;
1623 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001624 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001625 conf->dot11MeshHWMPRannInterval =
1626 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001627 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1628 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001629 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1630 /* our RSSI threshold implementation is supported only for
1631 * devices that report signal in dBm.
1632 */
1633 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1634 return -ENOTSUPP;
1635 conf->rssi_threshold = nconf->rssi_threshold;
1636 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001637 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1638 conf->ht_opmode = nconf->ht_opmode;
1639 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1640 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1641 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001642 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1643 conf->dot11MeshHWMPactivePathToRootTimeout =
1644 nconf->dot11MeshHWMPactivePathToRootTimeout;
1645 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1646 conf->dot11MeshHWMProotInterval =
1647 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001648 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1649 conf->dot11MeshHWMPconfirmationInterval =
1650 nconf->dot11MeshHWMPconfirmationInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001651 return 0;
1652}
1653
Johannes Berg29cbe682010-12-03 09:20:44 +01001654static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1655 const struct mesh_config *conf,
1656 const struct mesh_setup *setup)
1657{
1658 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1659 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001660 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001661
Javier Cardonac80d5452010-12-16 17:37:49 -08001662 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1663 err = copy_mesh_setup(ifmsh, setup);
1664 if (err)
1665 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001666
1667 err = ieee80211_set_channel(wiphy, dev, setup->channel,
1668 setup->channel_type);
1669 if (err)
1670 return err;
1671
Johannes Berg29cbe682010-12-03 09:20:44 +01001672 ieee80211_start_mesh(sdata);
1673
1674 return 0;
1675}
1676
1677static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1678{
1679 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1680
1681 ieee80211_stop_mesh(sdata);
1682
1683 return 0;
1684}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001685#endif
1686
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001687static int ieee80211_change_bss(struct wiphy *wiphy,
1688 struct net_device *dev,
1689 struct bss_parameters *params)
1690{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001691 struct ieee80211_sub_if_data *sdata;
1692 u32 changed = 0;
1693
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001694 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1695
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001696 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001697 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001698 changed |= BSS_CHANGED_ERP_CTS_PROT;
1699 }
1700 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001701 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001702 params->use_short_preamble;
1703 changed |= BSS_CHANGED_ERP_PREAMBLE;
1704 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001705
1706 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg679ef4e2012-07-23 14:29:21 +02001707 sdata->local->oper_channel->band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001708 sdata->vif.bss_conf.use_short_slot = true;
1709 changed |= BSS_CHANGED_ERP_SLOT;
1710 }
1711
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001712 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001713 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001714 params->use_short_slot_time;
1715 changed |= BSS_CHANGED_ERP_SLOT;
1716 }
1717
Jouni Malinen90c97a02008-10-30 16:59:22 +02001718 if (params->basic_rates) {
1719 int i, j;
1720 u32 rates = 0;
1721 struct ieee80211_local *local = wiphy_priv(wiphy);
1722 struct ieee80211_supported_band *sband =
1723 wiphy->bands[local->oper_channel->band];
1724
1725 for (i = 0; i < params->basic_rates_len; i++) {
1726 int rate = (params->basic_rates[i] & 0x7f) * 5;
1727 for (j = 0; j < sband->n_bitrates; j++) {
1728 if (sband->bitrates[j].bitrate == rate)
1729 rates |= BIT(j);
1730 }
1731 }
1732 sdata->vif.bss_conf.basic_rates = rates;
1733 changed |= BSS_CHANGED_BASIC_RATES;
1734 }
1735
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001736 if (params->ap_isolate >= 0) {
1737 if (params->ap_isolate)
1738 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1739 else
1740 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1741 }
1742
Helmut Schaa80d7e402010-11-19 12:40:26 +01001743 if (params->ht_opmode >= 0) {
1744 sdata->vif.bss_conf.ht_operation_mode =
1745 (u16) params->ht_opmode;
1746 changed |= BSS_CHANGED_HT;
1747 }
1748
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001749 ieee80211_bss_info_change_notify(sdata, changed);
1750
1751 return 0;
1752}
1753
Jouni Malinen31888482008-10-30 16:59:24 +02001754static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001755 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001756 struct ieee80211_txq_params *params)
1757{
1758 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001759 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001760 struct ieee80211_tx_queue_params p;
1761
1762 if (!local->ops->conf_tx)
1763 return -EOPNOTSUPP;
1764
Johannes Berg54bcbc62012-03-28 11:04:25 +02001765 if (local->hw.queues < IEEE80211_NUM_ACS)
1766 return -EOPNOTSUPP;
1767
Jouni Malinen31888482008-10-30 16:59:24 +02001768 memset(&p, 0, sizeof(p));
1769 p.aifs = params->aifs;
1770 p.cw_max = params->cwmax;
1771 p.cw_min = params->cwmin;
1772 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001773
1774 /*
1775 * Setting tx queue params disables u-apsd because it's only
1776 * called in master mode.
1777 */
1778 p.uapsd = false;
1779
Johannes Berga3304b02012-03-28 11:04:24 +02001780 sdata->tx_conf[params->ac] = p;
1781 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001782 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001783 "failed to set TX queue parameters for AC %d\n",
1784 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001785 return -EINVAL;
1786 }
1787
Johannes Berg7d257452012-07-06 17:37:43 +02001788 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1789
Jouni Malinen31888482008-10-30 16:59:24 +02001790 return 0;
1791}
1792
Bob Copeland665af4f2009-01-19 11:20:53 -05001793#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001794static int ieee80211_suspend(struct wiphy *wiphy,
1795 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001796{
Johannes Bergeecc4802011-05-04 15:37:29 +02001797 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001798}
1799
1800static int ieee80211_resume(struct wiphy *wiphy)
1801{
1802 return __ieee80211_resume(wiphy_priv(wiphy));
1803}
1804#else
1805#define ieee80211_suspend NULL
1806#define ieee80211_resume NULL
1807#endif
1808
Johannes Berg2a519312009-02-10 21:25:55 +01001809static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001810 struct cfg80211_scan_request *req)
1811{
Johannes Bergfd014282012-06-18 19:17:03 +02001812 struct ieee80211_sub_if_data *sdata;
1813
1814 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001815
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001816 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1817 case NL80211_IFTYPE_STATION:
1818 case NL80211_IFTYPE_ADHOC:
1819 case NL80211_IFTYPE_MESH_POINT:
1820 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001821 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001822 break;
1823 case NL80211_IFTYPE_P2P_GO:
1824 if (sdata->local->ops->hw_scan)
1825 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001826 /*
1827 * FIXME: implement NoA while scanning in software,
1828 * for now fall through to allow scanning only when
1829 * beaconing hasn't been configured yet
1830 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001831 case NL80211_IFTYPE_AP:
1832 if (sdata->u.ap.beacon)
1833 return -EOPNOTSUPP;
1834 break;
1835 default:
1836 return -EOPNOTSUPP;
1837 }
Johannes Berg2a519312009-02-10 21:25:55 +01001838
1839 return ieee80211_request_scan(sdata, req);
1840}
1841
Luciano Coelho79f460c2011-05-11 17:09:36 +03001842static int
1843ieee80211_sched_scan_start(struct wiphy *wiphy,
1844 struct net_device *dev,
1845 struct cfg80211_sched_scan_request *req)
1846{
1847 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1848
1849 if (!sdata->local->ops->sched_scan_start)
1850 return -EOPNOTSUPP;
1851
1852 return ieee80211_request_sched_scan_start(sdata, req);
1853}
1854
1855static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001856ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001857{
1858 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1859
1860 if (!sdata->local->ops->sched_scan_stop)
1861 return -EOPNOTSUPP;
1862
Luciano Coelho85a99942011-05-12 16:28:29 +03001863 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001864}
1865
Jouni Malinen636a5d32009-03-19 13:39:22 +02001866static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1867 struct cfg80211_auth_request *req)
1868{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001869 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001870}
1871
1872static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1873 struct cfg80211_assoc_request *req)
1874{
Johannes Bergf444de02010-05-05 15:25:02 +02001875 struct ieee80211_local *local = wiphy_priv(wiphy);
1876 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1877
1878 switch (ieee80211_get_channel_mode(local, sdata)) {
1879 case CHAN_MODE_HOPPING:
1880 return -EBUSY;
1881 case CHAN_MODE_FIXED:
1882 if (local->oper_channel == req->bss->channel)
1883 break;
1884 return -EBUSY;
1885 case CHAN_MODE_UNDEFINED:
1886 break;
1887 }
1888
Johannes Berg77fdaa12009-07-07 03:45:17 +02001889 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001890}
1891
1892static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001893 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001894{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001895 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001896}
1897
1898static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001899 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001900{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001901 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001902}
1903
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001904static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1905 struct cfg80211_ibss_params *params)
1906{
Johannes Bergf444de02010-05-05 15:25:02 +02001907 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001908 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1909
Johannes Bergf444de02010-05-05 15:25:02 +02001910 switch (ieee80211_get_channel_mode(local, sdata)) {
1911 case CHAN_MODE_HOPPING:
1912 return -EBUSY;
1913 case CHAN_MODE_FIXED:
1914 if (!params->channel_fixed)
1915 return -EBUSY;
1916 if (local->oper_channel == params->channel)
1917 break;
1918 return -EBUSY;
1919 case CHAN_MODE_UNDEFINED:
1920 break;
1921 }
1922
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001923 return ieee80211_ibss_join(sdata, params);
1924}
1925
1926static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1927{
1928 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1929
1930 return ieee80211_ibss_leave(sdata);
1931}
1932
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001933static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1934{
1935 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001936 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001937
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001938 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1939 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1940
1941 if (err)
1942 return err;
1943 }
1944
Lukáš Turek310bc672009-12-21 22:50:48 +01001945 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1946 err = drv_set_coverage_class(local, wiphy->coverage_class);
1947
1948 if (err)
1949 return err;
1950 }
1951
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001952 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001953 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001954
Johannes Berg24487982009-04-23 18:52:52 +02001955 if (err)
1956 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001957 }
1958
1959 if (changed & WIPHY_PARAM_RETRY_SHORT)
1960 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1961 if (changed & WIPHY_PARAM_RETRY_LONG)
1962 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1963 if (changed &
1964 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1965 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1966
1967 return 0;
1968}
1969
Johannes Berg7643a2c2009-06-02 13:01:39 +02001970static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001971 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001972{
1973 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg679ef4e2012-07-23 14:29:21 +02001974 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001975 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001976
1977 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001978 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001979 local->user_power_level = -1;
1980 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001981 case NL80211_TX_POWER_LIMITED:
1982 if (mbm < 0 || (mbm % 100))
1983 return -EOPNOTSUPP;
1984 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001985 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001986 case NL80211_TX_POWER_FIXED:
1987 if (mbm < 0 || (mbm % 100))
1988 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001989 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001990 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001991 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001992 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001993 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001994 }
1995
1996 ieee80211_hw_config(local, changes);
1997
1998 return 0;
1999}
2000
2001static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
2002{
2003 struct ieee80211_local *local = wiphy_priv(wiphy);
2004
2005 *dbm = local->hw.conf.power_level;
2006
Johannes Berg7643a2c2009-06-02 13:01:39 +02002007 return 0;
2008}
2009
Johannes Bergab737a42009-07-01 21:26:58 +02002010static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002011 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002012{
2013 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2014
2015 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2016
2017 return 0;
2018}
2019
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002020static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2021{
2022 struct ieee80211_local *local = wiphy_priv(wiphy);
2023
2024 drv_rfkill_poll(local);
2025}
2026
Johannes Bergaff89a92009-07-01 21:26:51 +02002027#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002028static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002029{
2030 struct ieee80211_local *local = wiphy_priv(wiphy);
2031
2032 if (!local->ops->testmode_cmd)
2033 return -EOPNOTSUPP;
2034
2035 return local->ops->testmode_cmd(&local->hw, data, len);
2036}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002037
2038static int ieee80211_testmode_dump(struct wiphy *wiphy,
2039 struct sk_buff *skb,
2040 struct netlink_callback *cb,
2041 void *data, int len)
2042{
2043 struct ieee80211_local *local = wiphy_priv(wiphy);
2044
2045 if (!local->ops->testmode_dump)
2046 return -EOPNOTSUPP;
2047
2048 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2049}
Johannes Bergaff89a92009-07-01 21:26:51 +02002050#endif
2051
Johannes Berg0f782312009-12-01 13:37:02 +01002052int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2053 enum ieee80211_smps_mode smps_mode)
2054{
2055 const u8 *ap;
2056 enum ieee80211_smps_mode old_req;
2057 int err;
2058
Johannes Berg243e6df2011-04-19 20:44:04 +02002059 lockdep_assert_held(&sdata->u.mgd.mtx);
2060
Johannes Berg0f782312009-12-01 13:37:02 +01002061 old_req = sdata->u.mgd.req_smps;
2062 sdata->u.mgd.req_smps = smps_mode;
2063
2064 if (old_req == smps_mode &&
2065 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2066 return 0;
2067
2068 /*
2069 * If not associated, or current association is not an HT
2070 * association, there's no need to send an action frame.
2071 */
2072 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02002073 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg025e6be2010-10-05 10:41:47 +02002074 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01002075 return 0;
2076 }
2077
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002078 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002079
2080 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2081 if (sdata->u.mgd.powersave)
2082 smps_mode = IEEE80211_SMPS_DYNAMIC;
2083 else
2084 smps_mode = IEEE80211_SMPS_OFF;
2085 }
2086
2087 /* send SM PS frame to AP */
2088 err = ieee80211_send_smps_action(sdata, smps_mode,
2089 ap, ap);
2090 if (err)
2091 sdata->u.mgd.req_smps = old_req;
2092
2093 return err;
2094}
2095
Johannes Bergbc92afd2009-07-01 21:26:57 +02002096static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2097 bool enabled, int timeout)
2098{
2099 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2100 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002101
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002102 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2103 return -EOPNOTSUPP;
2104
Johannes Bergbc92afd2009-07-01 21:26:57 +02002105 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2106 return -EOPNOTSUPP;
2107
2108 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002109 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002110 return 0;
2111
2112 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002113 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002114
Johannes Berg0f782312009-12-01 13:37:02 +01002115 /* no change, but if automatic follow powersave */
2116 mutex_lock(&sdata->u.mgd.mtx);
2117 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2118 mutex_unlock(&sdata->u.mgd.mtx);
2119
Johannes Bergbc92afd2009-07-01 21:26:57 +02002120 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2121 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2122
2123 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002124 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002125
2126 return 0;
2127}
2128
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002129static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2130 struct net_device *dev,
2131 s32 rssi_thold, u32 rssi_hyst)
2132{
2133 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002134 struct ieee80211_vif *vif = &sdata->vif;
2135 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2136
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002137 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2138 rssi_hyst == bss_conf->cqm_rssi_hyst)
2139 return 0;
2140
2141 bss_conf->cqm_rssi_thold = rssi_thold;
2142 bss_conf->cqm_rssi_hyst = rssi_hyst;
2143
2144 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002145 if (sdata->u.mgd.associated &&
2146 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002147 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2148
2149 return 0;
2150}
2151
Johannes Berg99303802009-07-01 21:26:59 +02002152static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2153 struct net_device *dev,
2154 const u8 *addr,
2155 const struct cfg80211_bitrate_mask *mask)
2156{
2157 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2158 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302159 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002160
Eliad Peller554a43d2012-06-12 12:41:15 +03002161 if (!ieee80211_sdata_running(sdata))
2162 return -ENETDOWN;
2163
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302164 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2165 ret = drv_set_bitrate_mask(local, sdata, mask);
2166 if (ret)
2167 return ret;
2168 }
Johannes Berg99303802009-07-01 21:26:59 +02002169
Simon Wunderlich19468412012-01-28 17:25:33 +01002170 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002171 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002172 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2173 sizeof(mask->control[i].mcs));
2174 }
Johannes Berg99303802009-07-01 21:26:59 +02002175
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002176 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002177}
2178
Johannes Berg2eb278e2012-06-05 14:28:42 +02002179static int ieee80211_start_roc_work(struct ieee80211_local *local,
2180 struct ieee80211_sub_if_data *sdata,
2181 struct ieee80211_channel *channel,
2182 enum nl80211_channel_type channel_type,
2183 unsigned int duration, u64 *cookie,
2184 struct sk_buff *txskb)
Johannes Berg21f83582010-12-18 17:20:47 +01002185{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002186 struct ieee80211_roc_work *roc, *tmp;
2187 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002188 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002189
2190 lockdep_assert_held(&local->mtx);
2191
Johannes Berg2eb278e2012-06-05 14:28:42 +02002192 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2193 if (!roc)
2194 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002195
Johannes Berg2eb278e2012-06-05 14:28:42 +02002196 roc->chan = channel;
2197 roc->chan_type = channel_type;
2198 roc->duration = duration;
2199 roc->req_duration = duration;
2200 roc->frame = txskb;
2201 roc->mgmt_tx_cookie = (unsigned long)txskb;
2202 roc->sdata = sdata;
2203 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2204 INIT_LIST_HEAD(&roc->dependents);
2205
2206 /* if there's one pending or we're scanning, queue this one */
2207 if (!list_empty(&local->roc_list) || local->scanning)
2208 goto out_check_combine;
2209
2210 /* if not HW assist, just queue & schedule work */
2211 if (!local->ops->remain_on_channel) {
2212 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2213 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002214 }
2215
Johannes Berg2eb278e2012-06-05 14:28:42 +02002216 /* otherwise actually kick it off here (for error handling) */
2217
2218 /*
2219 * If the duration is zero, then the driver
2220 * wouldn't actually do anything. Set it to
2221 * 10 for now.
2222 *
2223 * TODO: cancel the off-channel operation
2224 * when we get the SKB's TX status and
2225 * the wait time was zero before.
2226 */
2227 if (!duration)
2228 duration = 10;
2229
2230 ret = drv_remain_on_channel(local, channel, channel_type, duration);
2231 if (ret) {
2232 kfree(roc);
2233 return ret;
2234 }
2235
2236 roc->started = true;
2237 goto out_queue;
2238
2239 out_check_combine:
2240 list_for_each_entry(tmp, &local->roc_list, list) {
2241 if (tmp->chan != channel || tmp->chan_type != channel_type)
2242 continue;
2243
2244 /*
2245 * Extend this ROC if possible:
2246 *
2247 * If it hasn't started yet, just increase the duration
2248 * and add the new one to the list of dependents.
2249 */
2250 if (!tmp->started) {
2251 list_add_tail(&roc->list, &tmp->dependents);
2252 tmp->duration = max(tmp->duration, roc->duration);
2253 queued = true;
2254 break;
2255 }
2256
2257 /* If it has already started, it's more difficult ... */
2258 if (local->ops->remain_on_channel) {
2259 unsigned long j = jiffies;
2260
2261 /*
2262 * In the offloaded ROC case, if it hasn't begun, add
2263 * this new one to the dependent list to be handled
2264 * when the the master one begins. If it has begun,
2265 * check that there's still a minimum time left and
2266 * if so, start this one, transmitting the frame, but
2267 * add it to the list directly after this one with a
2268 * a reduced time so we'll ask the driver to execute
2269 * it right after finishing the previous one, in the
2270 * hope that it'll also be executed right afterwards,
2271 * effectively extending the old one.
2272 * If there's no minimum time left, just add it to the
2273 * normal list.
2274 */
2275 if (!tmp->hw_begun) {
2276 list_add_tail(&roc->list, &tmp->dependents);
2277 queued = true;
2278 break;
2279 }
2280
2281 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2282 tmp->hw_start_time +
2283 msecs_to_jiffies(tmp->duration))) {
2284 int new_dur;
2285
2286 ieee80211_handle_roc_started(roc);
2287
2288 new_dur = roc->duration -
2289 jiffies_to_msecs(tmp->hw_start_time +
2290 msecs_to_jiffies(
2291 tmp->duration) -
2292 j);
2293
2294 if (new_dur > 0) {
2295 /* add right after tmp */
2296 list_add(&roc->list, &tmp->list);
2297 } else {
2298 list_add_tail(&roc->list,
2299 &tmp->dependents);
2300 }
2301 queued = true;
2302 }
2303 } else if (del_timer_sync(&tmp->work.timer)) {
2304 unsigned long new_end;
2305
2306 /*
2307 * In the software ROC case, cancel the timer, if
2308 * that fails then the finish work is already
2309 * queued/pending and thus we queue the new ROC
2310 * normally, if that succeeds then we can extend
2311 * the timer duration and TX the frame (if any.)
2312 */
2313
2314 list_add_tail(&roc->list, &tmp->dependents);
2315 queued = true;
2316
2317 new_end = jiffies + msecs_to_jiffies(roc->duration);
2318
2319 /* ok, it was started & we canceled timer */
2320 if (time_after(new_end, tmp->work.timer.expires))
2321 mod_timer(&tmp->work.timer, new_end);
2322 else
2323 add_timer(&tmp->work.timer);
2324
2325 ieee80211_handle_roc_started(roc);
2326 }
2327 break;
2328 }
2329
2330 out_queue:
2331 if (!queued)
2332 list_add_tail(&roc->list, &local->roc_list);
2333
2334 /*
2335 * cookie is either the roc (for normal roc)
2336 * or the SKB (for mgmt TX)
2337 */
2338 if (txskb)
2339 *cookie = (unsigned long)txskb;
2340 else
2341 *cookie = (unsigned long)roc;
2342
2343 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002344}
2345
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002346static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002347 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002348 struct ieee80211_channel *chan,
2349 enum nl80211_channel_type channel_type,
2350 unsigned int duration,
2351 u64 *cookie)
2352{
Johannes Berg71bbc992012-06-15 15:30:18 +02002353 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002354 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002355 int ret;
2356
Johannes Berg2eb278e2012-06-05 14:28:42 +02002357 mutex_lock(&local->mtx);
2358 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2359 duration, cookie, NULL);
2360 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002361
Johannes Berg2eb278e2012-06-05 14:28:42 +02002362 return ret;
2363}
2364
2365static int ieee80211_cancel_roc(struct ieee80211_local *local,
2366 u64 cookie, bool mgmt_tx)
2367{
2368 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2369 int ret;
2370
2371 mutex_lock(&local->mtx);
2372 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002373 struct ieee80211_roc_work *dep, *tmp2;
2374
2375 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2376 if (!mgmt_tx && (unsigned long)dep != cookie)
2377 continue;
2378 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2379 continue;
2380 /* found dependent item -- just remove it */
2381 list_del(&dep->list);
2382 mutex_unlock(&local->mtx);
2383
2384 ieee80211_roc_notify_destroy(dep);
2385 return 0;
2386 }
2387
Johannes Berg2eb278e2012-06-05 14:28:42 +02002388 if (!mgmt_tx && (unsigned long)roc != cookie)
2389 continue;
2390 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2391 continue;
2392
2393 found = roc;
2394 break;
2395 }
2396
2397 if (!found) {
2398 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002399 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002400 }
Johannes Berg21f83582010-12-18 17:20:47 +01002401
Johannes Berge979e332012-06-11 17:09:41 +02002402 /*
2403 * We found the item to cancel, so do that. Note that it
2404 * may have dependents, which we also cancel (and send
2405 * the expired signal for.) Not doing so would be quite
2406 * tricky here, but we may need to fix it later.
2407 */
2408
Johannes Berg2eb278e2012-06-05 14:28:42 +02002409 if (local->ops->remain_on_channel) {
2410 if (found->started) {
2411 ret = drv_cancel_remain_on_channel(local);
2412 if (WARN_ON_ONCE(ret)) {
2413 mutex_unlock(&local->mtx);
2414 return ret;
2415 }
2416 }
Johannes Berg21f83582010-12-18 17:20:47 +01002417
Johannes Berg2eb278e2012-06-05 14:28:42 +02002418 list_del(&found->list);
2419
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002420 if (found->started)
2421 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002422 mutex_unlock(&local->mtx);
2423
2424 ieee80211_roc_notify_destroy(found);
2425 } else {
2426 /* work may be pending so use it all the time */
2427 found->abort = true;
2428 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2429
2430 mutex_unlock(&local->mtx);
2431
2432 /* work will clean up etc */
2433 flush_delayed_work(&found->work);
2434 }
Johannes Berg21f83582010-12-18 17:20:47 +01002435
Johannes Berg21f83582010-12-18 17:20:47 +01002436 return 0;
2437}
2438
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002439static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002440 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002441 u64 cookie)
2442{
Johannes Berg71bbc992012-06-15 15:30:18 +02002443 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002444 struct ieee80211_local *local = sdata->local;
2445
Johannes Berg2eb278e2012-06-05 14:28:42 +02002446 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002447}
2448
Johannes Berg71bbc992012-06-15 15:30:18 +02002449static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002450 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f72010-08-12 15:38:38 +02002451 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002452 bool channel_type_valid, unsigned int wait,
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05302453 const u8 *buf, size_t len, bool no_cck,
Johannes Berge247bd902011-11-04 11:18:21 +01002454 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002455{
Johannes Berg71bbc992012-06-15 15:30:18 +02002456 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002457 struct ieee80211_local *local = sdata->local;
2458 struct sk_buff *skb;
2459 struct sta_info *sta;
2460 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002461 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002462 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002463 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002464
Johannes Berge247bd902011-11-04 11:18:21 +01002465 if (dont_wait_for_ack)
2466 flags = IEEE80211_TX_CTL_NO_ACK;
2467 else
2468 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2469 IEEE80211_TX_CTL_REQ_TX_STATUS;
2470
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302471 if (no_cck)
2472 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2473
Johannes Berg9d38d852010-06-09 17:20:33 +02002474 switch (sdata->vif.type) {
2475 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002476 if (!sdata->vif.bss_conf.ibss_joined)
2477 need_offchan = true;
2478 /* fall through */
2479#ifdef CONFIG_MAC80211_MESH
2480 case NL80211_IFTYPE_MESH_POINT:
2481 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2482 !sdata->u.mesh.mesh_id_len)
2483 need_offchan = true;
2484 /* fall through */
2485#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002486 case NL80211_IFTYPE_AP:
2487 case NL80211_IFTYPE_AP_VLAN:
2488 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002489 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2490 !ieee80211_vif_is_mesh(&sdata->vif) &&
2491 !rcu_access_pointer(sdata->bss->beacon))
2492 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002493 if (!ieee80211_is_action(mgmt->frame_control) ||
2494 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002495 break;
2496 rcu_read_lock();
2497 sta = sta_info_get(sdata, mgmt->da);
2498 rcu_read_unlock();
2499 if (!sta)
2500 return -ENOLINK;
2501 break;
2502 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002503 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002504 if (!sdata->u.mgd.associated)
2505 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002506 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002507 case NL80211_IFTYPE_P2P_DEVICE:
2508 need_offchan = true;
2509 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002510 default:
2511 return -EOPNOTSUPP;
2512 }
2513
Johannes Berg2eb278e2012-06-05 14:28:42 +02002514 mutex_lock(&local->mtx);
2515
2516 /* Check if the operating channel is the requested channel */
2517 if (!need_offchan) {
2518 need_offchan = chan != local->oper_channel;
2519 if (channel_type_valid &&
2520 channel_type != local->_oper_channel_type)
2521 need_offchan = true;
2522 }
2523
2524 if (need_offchan && !offchan) {
2525 ret = -EBUSY;
2526 goto out_unlock;
2527 }
2528
Johannes Berg9d38d852010-06-09 17:20:33 +02002529 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002530 if (!skb) {
2531 ret = -ENOMEM;
2532 goto out_unlock;
2533 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002534 skb_reserve(skb, local->hw.extra_tx_headroom);
2535
2536 memcpy(skb_put(skb, len), buf, len);
2537
2538 IEEE80211_SKB_CB(skb)->flags = flags;
2539
Johannes Berg2eb278e2012-06-05 14:28:42 +02002540 skb->dev = sdata->dev;
2541
2542 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002543 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002544 ieee80211_tx_skb(sdata, skb);
2545 ret = 0;
2546 goto out_unlock;
2547 }
2548
2549 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2550 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002551 IEEE80211_SKB_CB(skb)->hw_queue =
2552 local->hw.offchannel_tx_hw_queue;
2553
Johannes Berg2eb278e2012-06-05 14:28:42 +02002554 /* This will handle all kinds of coalescing and immediate TX */
2555 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2556 wait, cookie, skb);
2557 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002558 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002559 out_unlock:
2560 mutex_unlock(&local->mtx);
2561 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002562}
2563
Johannes Bergf30221e2010-11-25 10:02:30 +01002564static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002565 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002566 u64 cookie)
2567{
Johannes Berg71bbc992012-06-15 15:30:18 +02002568 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002569
Johannes Berg2eb278e2012-06-05 14:28:42 +02002570 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002571}
2572
Johannes Berg7be50862010-10-13 12:06:24 +02002573static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002574 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002575 u16 frame_type, bool reg)
2576{
2577 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002578 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002579
Will Hawkins6abe0562012-06-20 11:51:14 -04002580 switch (frame_type) {
2581 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2582 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2583 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002584
Will Hawkins6abe0562012-06-20 11:51:14 -04002585 if (reg)
2586 ifibss->auth_frame_registrations++;
2587 else
2588 ifibss->auth_frame_registrations--;
2589 }
2590 break;
2591 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2592 if (reg)
2593 local->probe_req_reg++;
2594 else
2595 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002596
Felix Fietkau35f51492012-10-31 15:50:34 +01002597 if (!local->open_count)
2598 break;
2599
Will Hawkins6abe0562012-06-20 11:51:14 -04002600 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2601 break;
2602 default:
2603 break;
2604 }
Johannes Berg7be50862010-10-13 12:06:24 +02002605}
2606
Bruno Randolf15d96752010-11-10 12:50:56 +09002607static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2608{
2609 struct ieee80211_local *local = wiphy_priv(wiphy);
2610
2611 if (local->started)
2612 return -EOPNOTSUPP;
2613
2614 return drv_set_antenna(local, tx_ant, rx_ant);
2615}
2616
2617static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2618{
2619 struct ieee80211_local *local = wiphy_priv(wiphy);
2620
2621 return drv_get_antenna(local, tx_ant, rx_ant);
2622}
2623
John W. Linville38c09152011-03-07 16:19:18 -05002624static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2625{
2626 struct ieee80211_local *local = wiphy_priv(wiphy);
2627
2628 return drv_set_ringparam(local, tx, rx);
2629}
2630
2631static void ieee80211_get_ringparam(struct wiphy *wiphy,
2632 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2633{
2634 struct ieee80211_local *local = wiphy_priv(wiphy);
2635
2636 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2637}
2638
Johannes Bergc68f4b82011-07-05 16:35:41 +02002639static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2640 struct net_device *dev,
2641 struct cfg80211_gtk_rekey_data *data)
2642{
2643 struct ieee80211_local *local = wiphy_priv(wiphy);
2644 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2645
2646 if (!local->ops->set_rekey_data)
2647 return -EOPNOTSUPP;
2648
2649 drv_set_rekey_data(local, sdata, data);
2650
2651 return 0;
2652}
2653
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002654static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2655{
2656 u8 *pos = (void *)skb_put(skb, 7);
2657
2658 *pos++ = WLAN_EID_EXT_CAPABILITY;
2659 *pos++ = 5; /* len */
2660 *pos++ = 0x0;
2661 *pos++ = 0x0;
2662 *pos++ = 0x0;
2663 *pos++ = 0x0;
2664 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2665}
2666
2667static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2668{
2669 struct ieee80211_local *local = sdata->local;
2670 u16 capab;
2671
2672 capab = 0;
2673 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2674 return capab;
2675
2676 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2677 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2678 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2679 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2680
2681 return capab;
2682}
2683
2684static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2685 u8 *peer, u8 *bssid)
2686{
2687 struct ieee80211_tdls_lnkie *lnkid;
2688
2689 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2690
2691 lnkid->ie_type = WLAN_EID_LINK_ID;
2692 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2693
2694 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2695 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2696 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2697}
2698
2699static int
2700ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2701 u8 *peer, u8 action_code, u8 dialog_token,
2702 u16 status_code, struct sk_buff *skb)
2703{
2704 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg6b778632012-07-23 14:53:27 +02002705 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002706 struct ieee80211_tdls_data *tf;
2707
2708 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2709
2710 memcpy(tf->da, peer, ETH_ALEN);
2711 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2712 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2713 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2714
2715 switch (action_code) {
2716 case WLAN_TDLS_SETUP_REQUEST:
2717 tf->category = WLAN_CATEGORY_TDLS;
2718 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2719
2720 skb_put(skb, sizeof(tf->u.setup_req));
2721 tf->u.setup_req.dialog_token = dialog_token;
2722 tf->u.setup_req.capability =
2723 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2724
Johannes Berg6b778632012-07-23 14:53:27 +02002725 ieee80211_add_srates_ie(sdata, skb, false,
2726 local->oper_channel->band);
2727 ieee80211_add_ext_srates_ie(sdata, skb, false,
2728 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002729 ieee80211_tdls_add_ext_capab(skb);
2730 break;
2731 case WLAN_TDLS_SETUP_RESPONSE:
2732 tf->category = WLAN_CATEGORY_TDLS;
2733 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2734
2735 skb_put(skb, sizeof(tf->u.setup_resp));
2736 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2737 tf->u.setup_resp.dialog_token = dialog_token;
2738 tf->u.setup_resp.capability =
2739 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2740
Johannes Berg6b778632012-07-23 14:53:27 +02002741 ieee80211_add_srates_ie(sdata, skb, false,
2742 local->oper_channel->band);
2743 ieee80211_add_ext_srates_ie(sdata, skb, false,
2744 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002745 ieee80211_tdls_add_ext_capab(skb);
2746 break;
2747 case WLAN_TDLS_SETUP_CONFIRM:
2748 tf->category = WLAN_CATEGORY_TDLS;
2749 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2750
2751 skb_put(skb, sizeof(tf->u.setup_cfm));
2752 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2753 tf->u.setup_cfm.dialog_token = dialog_token;
2754 break;
2755 case WLAN_TDLS_TEARDOWN:
2756 tf->category = WLAN_CATEGORY_TDLS;
2757 tf->action_code = WLAN_TDLS_TEARDOWN;
2758
2759 skb_put(skb, sizeof(tf->u.teardown));
2760 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2761 break;
2762 case WLAN_TDLS_DISCOVERY_REQUEST:
2763 tf->category = WLAN_CATEGORY_TDLS;
2764 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2765
2766 skb_put(skb, sizeof(tf->u.discover_req));
2767 tf->u.discover_req.dialog_token = dialog_token;
2768 break;
2769 default:
2770 return -EINVAL;
2771 }
2772
2773 return 0;
2774}
2775
2776static int
2777ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2778 u8 *peer, u8 action_code, u8 dialog_token,
2779 u16 status_code, struct sk_buff *skb)
2780{
2781 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg6b778632012-07-23 14:53:27 +02002782 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002783 struct ieee80211_mgmt *mgmt;
2784
2785 mgmt = (void *)skb_put(skb, 24);
2786 memset(mgmt, 0, 24);
2787 memcpy(mgmt->da, peer, ETH_ALEN);
2788 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2789 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2790
2791 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2792 IEEE80211_STYPE_ACTION);
2793
2794 switch (action_code) {
2795 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2796 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2797 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2798 mgmt->u.action.u.tdls_discover_resp.action_code =
2799 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2800 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2801 dialog_token;
2802 mgmt->u.action.u.tdls_discover_resp.capability =
2803 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2804
Johannes Berg6b778632012-07-23 14:53:27 +02002805 ieee80211_add_srates_ie(sdata, skb, false,
2806 local->oper_channel->band);
2807 ieee80211_add_ext_srates_ie(sdata, skb, false,
2808 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002809 ieee80211_tdls_add_ext_capab(skb);
2810 break;
2811 default:
2812 return -EINVAL;
2813 }
2814
2815 return 0;
2816}
2817
2818static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2819 u8 *peer, u8 action_code, u8 dialog_token,
2820 u16 status_code, const u8 *extra_ies,
2821 size_t extra_ies_len)
2822{
2823 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2824 struct ieee80211_local *local = sdata->local;
2825 struct ieee80211_tx_info *info;
2826 struct sk_buff *skb = NULL;
2827 bool send_direct;
2828 int ret;
2829
2830 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2831 return -ENOTSUPP;
2832
2833 /* make sure we are in managed mode, and associated */
2834 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2835 !sdata->u.mgd.associated)
2836 return -EINVAL;
2837
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002838 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
2839 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002840
2841 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2842 max(sizeof(struct ieee80211_mgmt),
2843 sizeof(struct ieee80211_tdls_data)) +
2844 50 + /* supported rates */
2845 7 + /* ext capab */
2846 extra_ies_len +
2847 sizeof(struct ieee80211_tdls_lnkie));
2848 if (!skb)
2849 return -ENOMEM;
2850
2851 info = IEEE80211_SKB_CB(skb);
2852 skb_reserve(skb, local->hw.extra_tx_headroom);
2853
2854 switch (action_code) {
2855 case WLAN_TDLS_SETUP_REQUEST:
2856 case WLAN_TDLS_SETUP_RESPONSE:
2857 case WLAN_TDLS_SETUP_CONFIRM:
2858 case WLAN_TDLS_TEARDOWN:
2859 case WLAN_TDLS_DISCOVERY_REQUEST:
2860 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2861 action_code, dialog_token,
2862 status_code, skb);
2863 send_direct = false;
2864 break;
2865 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2866 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2867 dialog_token, status_code,
2868 skb);
2869 send_direct = true;
2870 break;
2871 default:
2872 ret = -ENOTSUPP;
2873 break;
2874 }
2875
2876 if (ret < 0)
2877 goto fail;
2878
2879 if (extra_ies_len)
2880 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2881
2882 /* the TDLS link IE is always added last */
2883 switch (action_code) {
2884 case WLAN_TDLS_SETUP_REQUEST:
2885 case WLAN_TDLS_SETUP_CONFIRM:
2886 case WLAN_TDLS_TEARDOWN:
2887 case WLAN_TDLS_DISCOVERY_REQUEST:
2888 /* we are the initiator */
2889 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2890 sdata->u.mgd.bssid);
2891 break;
2892 case WLAN_TDLS_SETUP_RESPONSE:
2893 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2894 /* we are the responder */
2895 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2896 sdata->u.mgd.bssid);
2897 break;
2898 default:
2899 ret = -ENOTSUPP;
2900 goto fail;
2901 }
2902
2903 if (send_direct) {
2904 ieee80211_tx_skb(sdata, skb);
2905 return 0;
2906 }
2907
2908 /*
2909 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2910 * we should default to AC_VI.
2911 */
2912 switch (action_code) {
2913 case WLAN_TDLS_SETUP_REQUEST:
2914 case WLAN_TDLS_SETUP_RESPONSE:
2915 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2916 skb->priority = 2;
2917 break;
2918 default:
2919 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2920 skb->priority = 5;
2921 break;
2922 }
2923
2924 /* disable bottom halves when entering the Tx path */
2925 local_bh_disable();
2926 ret = ieee80211_subif_start_xmit(skb, dev);
2927 local_bh_enable();
2928
2929 return ret;
2930
2931fail:
2932 dev_kfree_skb(skb);
2933 return ret;
2934}
2935
2936static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2937 u8 *peer, enum nl80211_tdls_operation oper)
2938{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002939 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002940 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2941
2942 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2943 return -ENOTSUPP;
2944
2945 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2946 return -EINVAL;
2947
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002948 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002949
2950 switch (oper) {
2951 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002952 rcu_read_lock();
2953 sta = sta_info_get(sdata, peer);
2954 if (!sta) {
2955 rcu_read_unlock();
2956 return -ENOLINK;
2957 }
2958
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002959 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002960 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002961 break;
2962 case NL80211_TDLS_DISABLE_LINK:
2963 return sta_info_destroy_addr(sdata, peer);
2964 case NL80211_TDLS_TEARDOWN:
2965 case NL80211_TDLS_SETUP:
2966 case NL80211_TDLS_DISCOVERY_REQ:
2967 /* We don't support in-driver setup/teardown/discovery */
2968 return -ENOTSUPP;
2969 default:
2970 return -ENOTSUPP;
2971 }
2972
2973 return 0;
2974}
2975
Johannes Berg06500732011-11-04 11:18:16 +01002976static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2977 const u8 *peer, u64 *cookie)
2978{
2979 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2980 struct ieee80211_local *local = sdata->local;
2981 struct ieee80211_qos_hdr *nullfunc;
2982 struct sk_buff *skb;
2983 int size = sizeof(*nullfunc);
2984 __le16 fc;
2985 bool qos;
2986 struct ieee80211_tx_info *info;
2987 struct sta_info *sta;
2988
2989 rcu_read_lock();
2990 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01002991 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01002992 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01002993 rcu_read_unlock();
2994 } else {
2995 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01002996 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01002997 }
Johannes Berg06500732011-11-04 11:18:16 +01002998
2999 if (qos) {
3000 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3001 IEEE80211_STYPE_QOS_NULLFUNC |
3002 IEEE80211_FCTL_FROMDS);
3003 } else {
3004 size -= 2;
3005 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3006 IEEE80211_STYPE_NULLFUNC |
3007 IEEE80211_FCTL_FROMDS);
3008 }
3009
3010 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3011 if (!skb)
3012 return -ENOMEM;
3013
3014 skb->dev = dev;
3015
3016 skb_reserve(skb, local->hw.extra_tx_headroom);
3017
3018 nullfunc = (void *) skb_put(skb, size);
3019 nullfunc->frame_control = fc;
3020 nullfunc->duration_id = 0;
3021 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3022 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3023 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3024 nullfunc->seq_ctrl = 0;
3025
3026 info = IEEE80211_SKB_CB(skb);
3027
3028 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3029 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3030
3031 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3032 skb->priority = 7;
3033 if (qos)
3034 nullfunc->qos_ctrl = cpu_to_le16(7);
3035
3036 local_bh_disable();
3037 ieee80211_xmit(sdata, skb);
3038 local_bh_enable();
3039
3040 *cookie = (unsigned long) skb;
3041 return 0;
3042}
3043
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003044static struct ieee80211_channel *
3045ieee80211_cfg_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
3046 enum nl80211_channel_type *type)
3047{
3048 struct ieee80211_local *local = wiphy_priv(wiphy);
3049
3050 *type = local->_oper_channel_type;
3051 return local->oper_channel;
3052}
3053
Johannes Berg6d525632012-04-04 15:05:25 +02003054#ifdef CONFIG_PM
3055static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3056{
3057 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3058}
3059#endif
3060
Jiri Bencf0706e82007-05-05 11:45:53 -07003061struct cfg80211_ops mac80211_config_ops = {
3062 .add_virtual_intf = ieee80211_add_iface,
3063 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003064 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003065 .start_p2p_device = ieee80211_start_p2p_device,
3066 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003067 .add_key = ieee80211_add_key,
3068 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003069 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003070 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003071 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003072 .start_ap = ieee80211_start_ap,
3073 .change_beacon = ieee80211_change_beacon,
3074 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003075 .add_station = ieee80211_add_station,
3076 .del_station = ieee80211_del_station,
3077 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003078 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003079 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003080 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003081#ifdef CONFIG_MAC80211_MESH
3082 .add_mpath = ieee80211_add_mpath,
3083 .del_mpath = ieee80211_del_mpath,
3084 .change_mpath = ieee80211_change_mpath,
3085 .get_mpath = ieee80211_get_mpath,
3086 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003087 .update_mesh_config = ieee80211_update_mesh_config,
3088 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003089 .join_mesh = ieee80211_join_mesh,
3090 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003091#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003092 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003093 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003094 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003095 .suspend = ieee80211_suspend,
3096 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003097 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003098 .sched_scan_start = ieee80211_sched_scan_start,
3099 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003100 .auth = ieee80211_auth,
3101 .assoc = ieee80211_assoc,
3102 .deauth = ieee80211_deauth,
3103 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003104 .join_ibss = ieee80211_join_ibss,
3105 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003106 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003107 .set_tx_power = ieee80211_set_tx_power,
3108 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003109 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003110 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003111 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003112 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003113 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003114 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003115 .remain_on_channel = ieee80211_remain_on_channel,
3116 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003117 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003118 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003119 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003120 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003121 .set_antenna = ieee80211_set_antenna,
3122 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003123 .set_ringparam = ieee80211_set_ringparam,
3124 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003125 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003126 .tdls_oper = ieee80211_tdls_oper,
3127 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003128 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003129 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003130#ifdef CONFIG_PM
3131 .set_wakeup = ieee80211_set_wakeup,
3132#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003133 .get_et_sset_count = ieee80211_get_et_sset_count,
3134 .get_et_stats = ieee80211_get_et_stats,
3135 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003136 .get_channel = ieee80211_cfg_get_channel,
Jiri Bencf0706e82007-05-05 11:45:53 -07003137};