blob: 00e31b488adce3716961a1f7839c02a348059836 [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 Berg84efbb82012-06-16 00:00:26 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070027{
28 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020029 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010030 struct ieee80211_sub_if_data *sdata;
31 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070032
Johannes Berg84efbb82012-06-16 00:00:26 +020033 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010034 if (err)
35 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010036
Johannes Bergf9e10ce2010-12-03 09:20:42 +010037 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020038 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010039 sdata->u.mntr_flags = *flags;
40 }
41
Johannes Berg84efbb82012-06-16 00:00:26 +020042 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070043}
44
Johannes Berg84efbb82012-06-16 00:00:26 +020045static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070046{
Johannes Berg84efbb82012-06-16 00:00:26 +020047 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070048
Johannes Berg75636522008-07-09 14:40:35 +020049 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070050}
51
Johannes Berge36d56b2009-06-09 21:04:43 +020052static int ieee80211_change_iface(struct wiphy *wiphy,
53 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010054 enum nl80211_iftype type, u32 *flags,
55 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020056{
Johannes Berg9607e6b2009-12-23 13:15:31 +010057 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020058 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020059
Johannes Berg05c914f2008-09-11 00:01:58 +020060 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020061 if (ret)
62 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020063
Johannes Berg9bc383d2009-11-19 11:55:19 +010064 if (type == NL80211_IFTYPE_AP_VLAN &&
65 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000066 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010067 else if (type == NL80211_IFTYPE_STATION &&
68 params && params->use_4addr >= 0)
69 sdata->u.mgd.use_4addr = params->use_4addr;
70
Christian Lamparter85416a42010-10-02 13:17:07 +020071 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
72 struct ieee80211_local *local = sdata->local;
73
74 if (ieee80211_sdata_running(sdata)) {
75 /*
76 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
77 * changed while the interface is up.
78 * Else we would need to add a lot of cruft
79 * to update everything:
80 * cooked_mntrs, monitor and all fif_* counters
81 * reconfigure hardware
82 */
83 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
84 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
85 return -EBUSY;
86
87 ieee80211_adjust_monitor_flags(sdata, -1);
88 sdata->u.mntr_flags = *flags;
89 ieee80211_adjust_monitor_flags(sdata, 1);
90
91 ieee80211_configure_filter(local);
92 } else {
93 /*
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
97 */
98 sdata->u.mntr_flags = *flags;
99 }
100 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200101
Johannes Berg42613db2007-09-28 21:52:27 +0200102 return 0;
103}
104
Johannes Bergf142c6b2012-06-18 20:07:15 +0200105static int ieee80211_start_p2p_device(struct wiphy *wiphy,
106 struct wireless_dev *wdev)
107{
108 return ieee80211_do_open(wdev, true);
109}
110
111static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
112 struct wireless_dev *wdev)
113{
114 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
115}
116
Simon Wunderlichb53be792011-11-18 14:20:44 +0100117static int ieee80211_set_noack_map(struct wiphy *wiphy,
118 struct net_device *dev,
119 u16 noack_map)
120{
121 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
122
123 sdata->noack_map = noack_map;
124 return 0;
125}
126
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100127static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200128 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100129 struct key_params *params)
130{
Johannes Berg26a58452010-08-27 12:35:55 +0200131 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100132 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100133 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200134 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100135
Johannes Berg26a58452010-08-27 12:35:55 +0200136 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200137 return -ENETDOWN;
138
Johannes Berg97359d12010-08-10 09:46:38 +0200139 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100140 switch (params->cipher) {
141 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100142 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200143 case WLAN_CIPHER_SUITE_WEP104:
144 if (IS_ERR(sdata->local->wep_tx_tfm))
145 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200146 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100147 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200148 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100149 }
150
Johannes Berg97359d12010-08-10 09:46:38 +0200151 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
152 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100153 if (IS_ERR(key))
154 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100155
Johannes Berge31b8212010-10-05 19:39:30 +0200156 if (pairwise)
157 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
158
Johannes Bergad0e2b52010-06-01 10:19:19 +0200159 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200160
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100161 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700162 if (ieee80211_vif_is_mesh(&sdata->vif))
163 sta = sta_info_get(sdata, mac_addr);
164 else
165 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100166 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700167 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200168 err = -ENOENT;
169 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100170 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100171 }
172
Johannes Berge548c492012-09-04 17:08:23 +0200173 switch (sdata->vif.type) {
174 case NL80211_IFTYPE_STATION:
175 if (sdata->u.mgd.mfp != IEEE80211_MFP_DISABLED)
176 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
177 break;
178 case NL80211_IFTYPE_AP:
179 case NL80211_IFTYPE_AP_VLAN:
180 /* Keys without a station are used for TX only */
181 if (key->sta && test_sta_flag(key->sta, WLAN_STA_MFP))
182 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
183 break;
184 case NL80211_IFTYPE_ADHOC:
185 /* no MFP (yet) */
186 break;
187 case NL80211_IFTYPE_MESH_POINT:
188#ifdef CONFIG_MAC80211_MESH
189 if (sdata->u.mesh.security != IEEE80211_MESH_SEC_NONE)
190 key->conf.flags |= IEEE80211_KEY_FLAG_RX_MGMT;
191 break;
192#endif
193 case NL80211_IFTYPE_WDS:
194 case NL80211_IFTYPE_MONITOR:
195 case NL80211_IFTYPE_P2P_DEVICE:
196 case NL80211_IFTYPE_UNSPECIFIED:
197 case NUM_NL80211_IFTYPES:
198 case NL80211_IFTYPE_P2P_CLIENT:
199 case NL80211_IFTYPE_P2P_GO:
200 /* shouldn't happen */
201 WARN_ON_ONCE(1);
202 break;
203 }
204
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300205 err = ieee80211_key_link(key, sdata, sta);
206 if (err)
207 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100208
Johannes Berg3b967662008-04-08 17:56:52 +0200209 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200210 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200211
212 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100213}
214
215static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200216 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100217{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200218 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
219 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100220 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200221 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100222 int ret;
223
Johannes Berg5c0c3642011-05-12 14:31:49 +0200224 mutex_lock(&local->sta_mtx);
225 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200226
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100227 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200228 ret = -ENOENT;
229
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100230 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100231 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200232 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100233
Johannes Berg5c0c3642011-05-12 14:31:49 +0200234 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200235 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200236 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200237 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200238 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200239 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100240
Johannes Berg5c0c3642011-05-12 14:31:49 +0200241 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200242 ret = -ENOENT;
243 goto out_unlock;
244 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100245
Johannes Berg5c0c3642011-05-12 14:31:49 +0200246 __ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100247
Johannes Berg3b967662008-04-08 17:56:52 +0200248 ret = 0;
249 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200250 mutex_unlock(&local->key_mtx);
251 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200252
253 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100254}
255
Johannes Berg62da92f2007-12-19 02:03:31 +0100256static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200257 u8 key_idx, bool pairwise, const u8 *mac_addr,
258 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100259 void (*callback)(void *cookie,
260 struct key_params *params))
261{
Johannes Berg14db74b2008-07-29 13:22:52 +0200262 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100263 struct sta_info *sta = NULL;
264 u8 seq[6] = {0};
265 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200266 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200267 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100268 u32 iv32;
269 u16 iv16;
270 int err = -ENOENT;
271
Johannes Berg14db74b2008-07-29 13:22:52 +0200272 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
273
Johannes Berg3b967662008-04-08 17:56:52 +0200274 rcu_read_lock();
275
Johannes Berg62da92f2007-12-19 02:03:31 +0100276 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100277 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100278 if (!sta)
279 goto out;
280
Johannes Berge31b8212010-10-05 19:39:30 +0200281 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200282 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200283 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200284 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100285 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200286 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100287
288 if (!key)
289 goto out;
290
291 memset(&params, 0, sizeof(params));
292
Johannes Berg97359d12010-08-10 09:46:38 +0200293 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100294
Johannes Berg97359d12010-08-10 09:46:38 +0200295 switch (key->conf.cipher) {
296 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700297 iv32 = key->u.tkip.tx.iv32;
298 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100299
Johannes Berg24487982009-04-23 18:52:52 +0200300 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
301 drv_get_tkip_seq(sdata->local,
302 key->conf.hw_key_idx,
303 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100304
305 seq[0] = iv16 & 0xff;
306 seq[1] = (iv16 >> 8) & 0xff;
307 seq[2] = iv32 & 0xff;
308 seq[3] = (iv32 >> 8) & 0xff;
309 seq[4] = (iv32 >> 16) & 0xff;
310 seq[5] = (iv32 >> 24) & 0xff;
311 params.seq = seq;
312 params.seq_len = 6;
313 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200314 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200315 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
316 seq[0] = pn64;
317 seq[1] = pn64 >> 8;
318 seq[2] = pn64 >> 16;
319 seq[3] = pn64 >> 24;
320 seq[4] = pn64 >> 32;
321 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100322 params.seq = seq;
323 params.seq_len = 6;
324 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200325 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200326 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
327 seq[0] = pn64;
328 seq[1] = pn64 >> 8;
329 seq[2] = pn64 >> 16;
330 seq[3] = pn64 >> 24;
331 seq[4] = pn64 >> 32;
332 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200333 params.seq = seq;
334 params.seq_len = 6;
335 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100336 }
337
338 params.key = key->conf.key;
339 params.key_len = key->conf.keylen;
340
341 callback(cookie, &params);
342 err = 0;
343
344 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200345 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100346 return err;
347}
348
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100349static int ieee80211_config_default_key(struct wiphy *wiphy,
350 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100351 u8 key_idx, bool uni,
352 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100353{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200354 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100355
Johannes Bergf7e01042010-12-09 19:49:02 +0100356 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100357
358 return 0;
359}
360
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200361static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
362 struct net_device *dev,
363 u8 key_idx)
364{
Johannes Berg66c52422010-07-22 13:58:51 +0200365 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200366
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200367 ieee80211_set_default_mgmt_key(sdata, key_idx);
368
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200369 return 0;
370}
371
Felix Fietkau3af63342011-02-27 22:08:01 +0100372static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
373{
374 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
375 struct ieee80211_supported_band *sband;
376 sband = sta->local->hw.wiphy->bands[
Johannes Berg679ef4e2012-07-23 14:29:21 +0200377 sta->local->oper_channel->band];
Felix Fietkau3af63342011-02-27 22:08:01 +0100378 rate->legacy = sband->bitrates[idx].bitrate;
379 } else
380 rate->mcs = idx;
381}
382
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800383void sta_set_rate_info_tx(struct sta_info *sta,
384 const struct ieee80211_tx_rate *rate,
385 struct rate_info *rinfo)
386{
387 rinfo->flags = 0;
388 if (rate->flags & IEEE80211_TX_RC_MCS)
389 rinfo->flags |= RATE_INFO_FLAGS_MCS;
390 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
391 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
392 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
393 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
394 rate_idx_to_bitrate(rinfo, sta, rate->idx);
395}
396
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100397static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
398{
Johannes Bergd0709a62008-02-25 16:27:46 +0100399 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300400 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530401 struct timespec uptime;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100402
Johannes Bergf5ea9122009-08-07 16:17:38 +0200403 sinfo->generation = sdata->local->sta_generation;
404
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100405 sinfo->filled = STATION_INFO_INACTIVE_TIME |
406 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100407 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200408 STATION_INFO_RX_PACKETS |
409 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900410 STATION_INFO_TX_RETRIES |
411 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700412 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100413 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700414 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530415 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200416 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800417 STATION_INFO_STA_FLAGS |
418 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530419
420 do_posix_clock_monotonic_gettime(&uptime);
421 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100422
423 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
424 sinfo->rx_bytes = sta->rx_bytes;
425 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200426 sinfo->rx_packets = sta->rx_packets;
427 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900428 sinfo->tx_retries = sta->tx_retry_count;
429 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700430 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800431 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100432
John W. Linville19deffb2009-12-08 17:10:13 -0500433 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
434 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900435 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300436 if (!local->ops->get_rssi ||
437 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
438 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900439 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100440 }
441
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800442 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100443
Felix Fietkau3af63342011-02-27 22:08:01 +0100444 sinfo->rxrate.flags = 0;
445 if (sta->last_rx_rate_flag & RX_FLAG_HT)
446 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
447 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
448 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
449 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
450 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
451 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100452
Johannes Berg902acc72008-02-23 15:17:19 +0100453 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100454#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100455 sinfo->filled |= STATION_INFO_LLID |
456 STATION_INFO_PLID |
457 STATION_INFO_PLINK_STATE;
458
459 sinfo->llid = le16_to_cpu(sta->llid);
460 sinfo->plid = le16_to_cpu(sta->plid);
461 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700462 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
463 sinfo->filled |= STATION_INFO_T_OFFSET;
464 sinfo->t_offset = sta->t_offset;
465 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100466#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100467 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700468
469 sinfo->bss_param.flags = 0;
470 if (sdata->vif.bss_conf.use_cts_prot)
471 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
472 if (sdata->vif.bss_conf.use_short_preamble)
473 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
474 if (sdata->vif.bss_conf.use_short_slot)
475 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
476 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
477 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200478
479 sinfo->sta_flags.set = 0;
480 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
481 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
482 BIT(NL80211_STA_FLAG_WME) |
483 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100484 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
485 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200486 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
487 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
488 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
489 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
490 if (test_sta_flag(sta, WLAN_STA_WME))
491 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
492 if (test_sta_flag(sta, WLAN_STA_MFP))
493 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
494 if (test_sta_flag(sta, WLAN_STA_AUTH))
495 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100496 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
497 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100498}
499
Ben Greearb1ab7922012-04-23 12:50:30 -0700500static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
501 "rx_packets", "rx_bytes", "wep_weak_iv_count",
502 "rx_duplicates", "rx_fragments", "rx_dropped",
503 "tx_packets", "tx_bytes", "tx_fragments",
504 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700505 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
506 "channel", "noise", "ch_time", "ch_time_busy",
507 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700508};
509#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
510
511static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
512 struct net_device *dev,
513 int sset)
514{
Ben Greeare3521142012-04-23 12:50:31 -0700515 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
516 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700517
Ben Greeare3521142012-04-23 12:50:31 -0700518 if (sset == ETH_SS_STATS)
519 rv += STA_STATS_LEN;
520
521 rv += drv_get_et_sset_count(sdata, sset);
522
523 if (rv == 0)
524 return -EOPNOTSUPP;
525 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700526}
527
528static void ieee80211_get_et_stats(struct wiphy *wiphy,
529 struct net_device *dev,
530 struct ethtool_stats *stats,
531 u64 *data)
532{
533 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
534 struct sta_info *sta;
535 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700536 struct station_info sinfo;
537 struct survey_info survey;
538 int i, q;
539#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700540
541 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
542
543#define ADD_STA_STATS(sta) \
544 do { \
545 data[i++] += sta->rx_packets; \
546 data[i++] += sta->rx_bytes; \
547 data[i++] += sta->wep_weak_iv_count; \
548 data[i++] += sta->num_duplicates; \
549 data[i++] += sta->rx_fragments; \
550 data[i++] += sta->rx_dropped; \
551 \
552 data[i++] += sta->tx_packets; \
553 data[i++] += sta->tx_bytes; \
554 data[i++] += sta->tx_fragments; \
555 data[i++] += sta->tx_filtered_count; \
556 data[i++] += sta->tx_retry_failed; \
557 data[i++] += sta->tx_retry_count; \
558 data[i++] += sta->beacon_loss_count; \
559 } while (0)
560
561 /* For Managed stations, find the single station based on BSSID
562 * and use that. For interface types, iterate through all available
563 * stations and add stats for any station that is assigned to this
564 * network device.
565 */
566
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300567 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700568
569 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
570 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700571
572 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
573 goto do_survey;
574
575 i = 0;
576 ADD_STA_STATS(sta);
577
578 data[i++] = sta->sta_state;
579
580 sinfo.filled = 0;
581 sta_set_sinfo(sta, &sinfo);
582
Joe Perches52042672012-05-30 13:25:54 -0700583 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700584 data[i] = 100000 *
585 cfg80211_calculate_bitrate(&sinfo.txrate);
586 i++;
Joe Perches52042672012-05-30 13:25:54 -0700587 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700588 data[i] = 100000 *
589 cfg80211_calculate_bitrate(&sinfo.rxrate);
590 i++;
591
Joe Perches52042672012-05-30 13:25:54 -0700592 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700593 data[i] = (u8)sinfo.signal_avg;
594 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700595 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300596 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700597 /* Make sure this station belongs to the proper dev */
598 if (sta->sdata->dev != dev)
599 continue;
600
601 i = 0;
602 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700603 }
604 }
605
Ben Greear3073a7c2012-04-23 12:50:32 -0700606do_survey:
607 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
608 /* Get survey stats for current channel */
609 q = 0;
610 while (true) {
611 survey.filled = 0;
612 if (drv_get_survey(local, q, &survey) != 0) {
613 survey.filled = 0;
614 break;
615 }
616
617 if (survey.channel &&
618 (local->oper_channel->center_freq ==
619 survey.channel->center_freq))
620 break;
621 q++;
622 }
623
624 if (survey.filled)
625 data[i++] = survey.channel->center_freq;
626 else
627 data[i++] = 0;
628 if (survey.filled & SURVEY_INFO_NOISE_DBM)
629 data[i++] = (u8)survey.noise;
630 else
631 data[i++] = -1LL;
632 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
633 data[i++] = survey.channel_time;
634 else
635 data[i++] = -1LL;
636 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
637 data[i++] = survey.channel_time_busy;
638 else
639 data[i++] = -1LL;
640 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
641 data[i++] = survey.channel_time_ext_busy;
642 else
643 data[i++] = -1LL;
644 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
645 data[i++] = survey.channel_time_rx;
646 else
647 data[i++] = -1LL;
648 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
649 data[i++] = survey.channel_time_tx;
650 else
651 data[i++] = -1LL;
652
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300653 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700654
Ben Greear3073a7c2012-04-23 12:50:32 -0700655 if (WARN_ON(i != STA_STATS_LEN))
656 return;
657
Ben Greeare3521142012-04-23 12:50:31 -0700658 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700659}
660
661static void ieee80211_get_et_strings(struct wiphy *wiphy,
662 struct net_device *dev,
663 u32 sset, u8 *data)
664{
Ben Greeare3521142012-04-23 12:50:31 -0700665 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
666 int sz_sta_stats = 0;
667
Ben Greearb1ab7922012-04-23 12:50:30 -0700668 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700669 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700670 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
671 }
Ben Greeare3521142012-04-23 12:50:31 -0700672 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700673}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100674
675static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
676 int idx, u8 *mac, struct station_info *sinfo)
677{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100678 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300679 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100680 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100681 int ret = -ENOENT;
682
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300683 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100684
Johannes Berg3b53fde82009-11-16 12:00:37 +0100685 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100686 if (sta) {
687 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200688 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100689 sta_set_sinfo(sta, sinfo);
690 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100691
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300692 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100693
Johannes Bergd0709a62008-02-25 16:27:46 +0100694 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100695}
696
Holger Schurig12897232010-04-19 10:23:57 +0200697static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
698 int idx, struct survey_info *survey)
699{
700 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
701
Holger Schurig12897232010-04-19 10:23:57 +0200702 return drv_get_survey(local, idx, survey);
703}
704
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100705static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100706 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100707{
Johannes Bergabe60632009-11-25 17:46:18 +0100708 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300709 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100710 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100711 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100712
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300713 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100714
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100715 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100716 if (sta) {
717 ret = 0;
718 sta_set_sinfo(sta, sinfo);
719 }
720
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300721 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100722
723 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100724}
725
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200726static int ieee80211_set_channel(struct wiphy *wiphy,
727 struct net_device *netdev,
728 struct ieee80211_channel *chan,
729 enum nl80211_channel_type channel_type)
730{
731 struct ieee80211_local *local = wiphy_priv(wiphy);
732 struct ieee80211_sub_if_data *sdata = NULL;
733
734 if (netdev)
735 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
736
737 switch (ieee80211_get_channel_mode(local, NULL)) {
738 case CHAN_MODE_HOPPING:
739 return -EBUSY;
740 case CHAN_MODE_FIXED:
Pontus Fuchsac4d82f2012-06-12 14:13:19 +0200741 if (local->oper_channel != chan ||
742 (!sdata && local->_oper_channel_type != channel_type))
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200743 return -EBUSY;
744 if (!sdata && local->_oper_channel_type == channel_type)
745 return 0;
746 break;
747 case CHAN_MODE_UNDEFINED:
748 break;
749 }
750
751 if (!ieee80211_set_channel_type(local, sdata, channel_type))
752 return -EBUSY;
753
754 local->oper_channel = chan;
755
756 /* auto-detects changes */
757 ieee80211_hw_config(local, 0);
758
759 return 0;
760}
761
Johannes Berge8c9bd52012-06-06 08:18:22 +0200762static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
763 struct ieee80211_channel *chan,
764 enum nl80211_channel_type channel_type)
765{
766 return ieee80211_set_channel(wiphy, NULL, chan, channel_type);
767}
768
Arik Nemtsov02945822011-11-10 11:28:57 +0200769static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100770 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200771{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300772 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200773
774 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530775 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200776
Arik Nemtsovf7248282011-11-19 10:51:26 +0200777 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200778
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300779 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200780 if (!new)
781 return -ENOMEM;
782
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300783 new->len = resp_len;
784 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200785
786 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300787 if (old)
788 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200789
790 return 0;
791}
792
Johannes Berg88600202012-02-13 15:17:18 +0100793static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
794 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100795{
796 struct beacon_data *new, *old;
797 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100798 int size, err;
799 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100800
Johannes Berg40b275b2011-05-13 14:15:49 +0200801 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100802
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100803 /* Need to have a beacon head if we don't have one yet */
804 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100805 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100806
807 /* new or old head? */
808 if (params->head)
809 new_head_len = params->head_len;
810 else
811 new_head_len = old->head_len;
812
813 /* new or old tail? */
814 if (params->tail || !old)
815 /* params->tail_len will be zero for !params->tail */
816 new_tail_len = params->tail_len;
817 else
818 new_tail_len = old->tail_len;
819
820 size = sizeof(*new) + new_head_len + new_tail_len;
821
822 new = kzalloc(size, GFP_KERNEL);
823 if (!new)
824 return -ENOMEM;
825
826 /* start filling the new info now */
827
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100828 /*
829 * pointers go into the block we allocated,
830 * memory is | beacon_data | head | tail |
831 */
832 new->head = ((u8 *) new) + sizeof(*new);
833 new->tail = new->head + new_head_len;
834 new->head_len = new_head_len;
835 new->tail_len = new_tail_len;
836
837 /* copy in head */
838 if (params->head)
839 memcpy(new->head, params->head, new_head_len);
840 else
841 memcpy(new->head, old->head, new_head_len);
842
843 /* copy in optional tail */
844 if (params->tail)
845 memcpy(new->tail, params->tail, new_tail_len);
846 else
847 if (old)
848 memcpy(new->tail, old->tail, new_tail_len);
849
Johannes Berg88600202012-02-13 15:17:18 +0100850 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
851 params->probe_resp_len);
852 if (err < 0)
853 return err;
854 if (err == 0)
855 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100856
Eric Dumazetcf778b02012-01-12 04:41:32 +0000857 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100858
Johannes Berg88600202012-02-13 15:17:18 +0100859 if (old)
860 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100861
Johannes Berg88600202012-02-13 15:17:18 +0100862 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100863}
864
Johannes Berg88600202012-02-13 15:17:18 +0100865static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
866 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100867{
Johannes Berg88600202012-02-13 15:17:18 +0100868 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100869 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100870 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100871 u32 changed = BSS_CHANGED_BEACON_INT |
872 BSS_CHANGED_BEACON_ENABLED |
873 BSS_CHANGED_BEACON |
874 BSS_CHANGED_SSID;
875 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200876
Johannes Berg40b275b2011-05-13 14:15:49 +0200877 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100878 if (old)
879 return -EALREADY;
880
Johannes Bergaa430da2012-05-16 23:50:18 +0200881 err = ieee80211_set_channel(wiphy, dev, params->channel,
882 params->channel_type);
883 if (err)
884 return err;
885
Johannes Berg665c93a2011-11-04 11:18:11 +0100886 /*
887 * Apply control port protocol, this allows us to
888 * not encrypt dynamic WEP control frames.
889 */
890 sdata->control_port_protocol = params->crypto.control_port_ethertype;
891 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
892 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
893 vlan->control_port_protocol =
894 params->crypto.control_port_ethertype;
895 vlan->control_port_no_encrypt =
896 params->crypto.control_port_no_encrypt;
897 }
898
Johannes Berg88600202012-02-13 15:17:18 +0100899 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
900 sdata->vif.bss_conf.dtim_period = params->dtim_period;
901
902 sdata->vif.bss_conf.ssid_len = params->ssid_len;
903 if (params->ssid_len)
904 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
905 params->ssid_len);
906 sdata->vif.bss_conf.hidden_ssid =
907 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
908
909 err = ieee80211_assign_beacon(sdata, &params->beacon);
910 if (err < 0)
911 return err;
912 changed |= err;
913
914 ieee80211_bss_info_change_notify(sdata, changed);
915
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200916 netif_carrier_on(dev);
917 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
918 netif_carrier_on(vlan->dev);
919
Johannes Berg665c93a2011-11-04 11:18:11 +0100920 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100921}
922
Johannes Berg88600202012-02-13 15:17:18 +0100923static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
924 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100925{
Johannes Berg14db74b2008-07-29 13:22:52 +0200926 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100927 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100928 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100929
Johannes Berg14db74b2008-07-29 13:22:52 +0200930 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
931
Johannes Berg40b275b2011-05-13 14:15:49 +0200932 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100933 if (!old)
934 return -ENOENT;
935
Johannes Berg88600202012-02-13 15:17:18 +0100936 err = ieee80211_assign_beacon(sdata, params);
937 if (err < 0)
938 return err;
939 ieee80211_bss_info_change_notify(sdata, err);
940 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100941}
942
Johannes Berg88600202012-02-13 15:17:18 +0100943static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100944{
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200945 struct ieee80211_sub_if_data *sdata, *vlan;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100946 struct beacon_data *old;
947
Johannes Berg14db74b2008-07-29 13:22:52 +0200948 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
949
Johannes Berg40b275b2011-05-13 14:15:49 +0200950 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100951 if (!old)
952 return -ENOENT;
953
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200954 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
955 netif_carrier_off(vlan->dev);
956 netif_carrier_off(dev);
957
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000958 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100959
960 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100961
Eliad Peller99102bd2012-07-18 15:36:04 +0300962 sta_info_flush(sdata->local, sdata);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200963 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100964
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200965 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100966}
967
Johannes Berg4fd69312007-12-19 02:03:35 +0100968/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
969struct iapp_layer2_update {
970 u8 da[ETH_ALEN]; /* broadcast */
971 u8 sa[ETH_ALEN]; /* STA addr */
972 __be16 len; /* 6 */
973 u8 dsap; /* 0 */
974 u8 ssap; /* 0 */
975 u8 control;
976 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700977} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100978
979static void ieee80211_send_layer2_update(struct sta_info *sta)
980{
981 struct iapp_layer2_update *msg;
982 struct sk_buff *skb;
983
984 /* Send Level 2 Update Frame to update forwarding tables in layer 2
985 * bridge devices */
986
987 skb = dev_alloc_skb(sizeof(*msg));
988 if (!skb)
989 return;
990 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
991
992 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
993 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
994
Johannes Berge83e6542012-07-13 16:23:07 +0200995 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200996 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100997 msg->len = htons(6);
998 msg->dsap = 0;
999 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
1000 msg->control = 0xaf; /* XID response lsb.1111F101.
1001 * F=0 (no poll command; unsolicited frame) */
1002 msg->xid_info[0] = 0x81; /* XID format identifier */
1003 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
1004 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
1005
Johannes Bergd0709a62008-02-25 16:27:46 +01001006 skb->dev = sta->sdata->dev;
1007 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +01001008 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -04001009 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +01001010}
1011
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001012static int sta_apply_parameters(struct ieee80211_local *local,
1013 struct sta_info *sta,
1014 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +01001015{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001016 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001017 u32 rates;
1018 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +01001019 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +01001020 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +03001021 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +01001022
Johannes Bergae5eb022008-10-14 16:58:37 +02001023 sband = local->hw.wiphy->bands[local->oper_channel->band];
1024
Johannes Bergeccb8e82009-05-11 21:57:56 +03001025 mask = params->sta_flags_mask;
1026 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +01001027
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001028 /*
1029 * In mesh mode, we can clear AUTHENTICATED flag but must
1030 * also make ASSOCIATED follow appropriately for the driver
1031 * API. See also below, after AUTHORIZED changes.
1032 */
1033 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1034 /* cfg80211 should not allow this in non-mesh modes */
1035 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1036 return -EINVAL;
1037
1038 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1039 !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001040 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001041 if (ret)
1042 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001043 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001044 if (ret)
1045 return ret;
1046 }
1047 }
1048
Johannes Bergeccb8e82009-05-11 21:57:56 +03001049 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001050 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001051 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Berg543d1b92012-01-13 14:17:59 +01001052 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001053 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001054 if (ret)
1055 return ret;
Johannes Berg4fd69312007-12-19 02:03:35 +01001056 }
1057
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001058 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1059 /* cfg80211 should not allow this in non-mesh modes */
1060 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1061 return -EINVAL;
1062
1063 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1064 test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001065 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001066 if (ret)
1067 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001068 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001069 if (ret)
1070 return ret;
1071 }
1072 }
1073
1074
Johannes Bergeccb8e82009-05-11 21:57:56 +03001075 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001076 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001077 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1078 else
1079 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001080 }
1081
1082 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001083 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001084 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001085 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001086 } else {
1087 clear_sta_flag(sta, WLAN_STA_WME);
1088 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001089 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001090 }
1091
1092 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001093 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001094 set_sta_flag(sta, WLAN_STA_MFP);
1095 else
1096 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001097 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001098
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001099 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001100 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001101 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1102 else
1103 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001104 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001105
Johannes Berg3b9ce802011-09-27 20:56:12 +02001106 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1107 sta->sta.uapsd_queues = params->uapsd_queues;
1108 sta->sta.max_sp = params->max_sp;
1109 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001110
Johannes Berg73651ee2008-02-25 16:27:47 +01001111 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001112 * cfg80211 validates this (1-2007) and allows setting the AID
1113 * only when creating a new station entry
1114 */
1115 if (params->aid)
1116 sta->sta.aid = params->aid;
1117
1118 /*
Johannes Berg73651ee2008-02-25 16:27:47 +01001119 * FIXME: updating the following information is racy when this
1120 * function is called from ieee80211_change_station().
1121 * However, all this information should be static so
1122 * maybe we should just reject attemps to change it.
1123 */
1124
Johannes Berg4fd69312007-12-19 02:03:35 +01001125 if (params->listen_interval >= 0)
1126 sta->listen_interval = params->listen_interval;
1127
1128 if (params->supported_rates) {
1129 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001130
Johannes Berg4fd69312007-12-19 02:03:35 +01001131 for (i = 0; i < params->supported_rates_len; i++) {
1132 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001133 for (j = 0; j < sband->n_bitrates; j++) {
1134 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001135 rates |= BIT(j);
1136 }
1137 }
Johannes Berg323ce792008-09-11 02:45:11 +02001138 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001139 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001140
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001141 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001142 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +02001143 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001144 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001145
Javier Cardona9c3990a2011-05-03 16:57:11 -07001146 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001147#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -07001148 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
1149 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001150 case NL80211_PLINK_LISTEN:
1151 case NL80211_PLINK_ESTAB:
1152 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -07001153 sta->plink_state = params->plink_state;
1154 break;
1155 default:
1156 /* nothing */
1157 break;
1158 }
1159 else
1160 switch (params->plink_action) {
1161 case PLINK_ACTION_OPEN:
1162 mesh_plink_open(sta);
1163 break;
1164 case PLINK_ACTION_BLOCK:
1165 mesh_plink_block(sta);
1166 break;
1167 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001168#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001169 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001170
1171 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001172}
1173
1174static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1175 u8 *mac, struct station_parameters *params)
1176{
Johannes Berg14db74b2008-07-29 13:22:52 +02001177 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001178 struct sta_info *sta;
1179 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001180 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001181 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001182
Johannes Berg4fd69312007-12-19 02:03:35 +01001183 if (params->vlan) {
1184 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1185
Johannes Berg05c914f2008-09-11 00:01:58 +02001186 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1187 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001188 return -EINVAL;
1189 } else
1190 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1191
Joe Perchesb203ca32012-05-08 18:56:52 +00001192 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001193 return -EINVAL;
1194
1195 if (is_multicast_ether_addr(mac))
1196 return -EINVAL;
1197
1198 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001199 if (!sta)
1200 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001201
Johannes Berg83d5cc02012-01-12 09:31:10 +01001202 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1203 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +01001204
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001205 err = sta_apply_parameters(local, sta, params);
1206 if (err) {
1207 sta_info_free(local, sta);
1208 return err;
1209 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001210
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001211 /*
1212 * for TDLS, rate control should be initialized only when supported
1213 * rates are known.
1214 */
1215 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1216 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001217
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001218 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1219 sdata->vif.type == NL80211_IFTYPE_AP;
1220
Johannes Berg34e89502010-02-03 13:59:58 +01001221 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001222 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001223 rcu_read_unlock();
1224 return err;
1225 }
1226
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001227 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001228 ieee80211_send_layer2_update(sta);
1229
1230 rcu_read_unlock();
1231
Johannes Berg4fd69312007-12-19 02:03:35 +01001232 return 0;
1233}
1234
1235static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1236 u8 *mac)
1237{
Johannes Berg14db74b2008-07-29 13:22:52 +02001238 struct ieee80211_local *local = wiphy_priv(wiphy);
1239 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001240
Johannes Berg14db74b2008-07-29 13:22:52 +02001241 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1242
Johannes Berg34e89502010-02-03 13:59:58 +01001243 if (mac)
1244 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001245
Johannes Berg34e89502010-02-03 13:59:58 +01001246 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001247 return 0;
1248}
1249
1250static int ieee80211_change_station(struct wiphy *wiphy,
1251 struct net_device *dev,
1252 u8 *mac,
1253 struct station_parameters *params)
1254{
Johannes Bergabe60632009-11-25 17:46:18 +01001255 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001256 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001257 struct sta_info *sta;
1258 struct ieee80211_sub_if_data *vlansdata;
Eliad Peller35b88622011-12-29 14:41:39 +02001259 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001260
Johannes Berg87be1e12011-12-14 12:20:29 +01001261 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001262
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001263 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001264 if (!sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001265 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001266 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001267 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001268
Johannes Bergbdd90d52011-12-14 12:20:27 +01001269 /* in station mode, supported rates are only valid with TDLS */
1270 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1271 params->supported_rates &&
1272 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001273 mutex_unlock(&local->sta_mtx);
Johannes Bergbdd90d52011-12-14 12:20:27 +01001274 return -EINVAL;
1275 }
1276
Johannes Bergd0709a62008-02-25 16:27:46 +01001277 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001278 bool prev_4addr = false;
1279 bool new_4addr = false;
1280
Johannes Berg4fd69312007-12-19 02:03:35 +01001281 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1282
Johannes Berg05c914f2008-09-11 00:01:58 +02001283 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1284 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001285 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001286 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001287 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001288
Johannes Berg9bc383d2009-11-19 11:55:19 +01001289 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001290 if (vlansdata->u.vlan.sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001291 mutex_unlock(&local->sta_mtx);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001292 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +01001293 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001294
Eric Dumazetcf778b02012-01-12 04:41:32 +00001295 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001296 new_4addr = true;
1297 }
1298
1299 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1300 sta->sdata->u.vlan.sta) {
1301 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1302 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001303 }
1304
Johannes Berg14db74b2008-07-29 13:22:52 +02001305 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001306
1307 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1308 prev_4addr != new_4addr) {
1309 if (new_4addr)
1310 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1311 else
1312 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1313 }
1314
Johannes Berg4fd69312007-12-19 02:03:35 +01001315 ieee80211_send_layer2_update(sta);
1316 }
1317
Eliad Peller35b88622011-12-29 14:41:39 +02001318 err = sta_apply_parameters(local, sta, params);
1319 if (err) {
1320 mutex_unlock(&local->sta_mtx);
1321 return err;
1322 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001323
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001324 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1325 rate_control_rate_init(sta);
1326
Johannes Berg87be1e12011-12-14 12:20:29 +01001327 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001328
Jason Young808118c2011-03-10 16:43:19 -08001329 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001330 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001331 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001332 ieee80211_recalc_ps_vif(sdata);
1333 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001334 return 0;
1335}
1336
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001337#ifdef CONFIG_MAC80211_MESH
1338static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1339 u8 *dst, u8 *next_hop)
1340{
Johannes Berg14db74b2008-07-29 13:22:52 +02001341 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001342 struct mesh_path *mpath;
1343 struct sta_info *sta;
1344 int err;
1345
Johannes Berg14db74b2008-07-29 13:22:52 +02001346 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1347
Johannes Bergd0709a62008-02-25 16:27:46 +01001348 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001349 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001350 if (!sta) {
1351 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001352 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001353 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001354
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001355 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +01001356 if (err) {
1357 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001358 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001359 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001360
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001361 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001362 if (!mpath) {
1363 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001364 return -ENXIO;
1365 }
1366 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001367
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001368 rcu_read_unlock();
1369 return 0;
1370}
1371
1372static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1373 u8 *dst)
1374{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001375 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001376
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001377 if (dst)
1378 return mesh_path_del(dst, sdata);
1379
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001380 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001381 return 0;
1382}
1383
1384static int ieee80211_change_mpath(struct wiphy *wiphy,
1385 struct net_device *dev,
1386 u8 *dst, u8 *next_hop)
1387{
Johannes Berg14db74b2008-07-29 13:22:52 +02001388 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001389 struct mesh_path *mpath;
1390 struct sta_info *sta;
1391
Johannes Berg14db74b2008-07-29 13:22:52 +02001392 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1393
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001394 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001395
Johannes Bergabe60632009-11-25 17:46:18 +01001396 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001397 if (!sta) {
1398 rcu_read_unlock();
1399 return -ENOENT;
1400 }
1401
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001402 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001403 if (!mpath) {
1404 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001405 return -ENOENT;
1406 }
1407
1408 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001409
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001410 rcu_read_unlock();
1411 return 0;
1412}
1413
1414static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1415 struct mpath_info *pinfo)
1416{
Johannes Berga3836e02011-05-12 15:11:37 +02001417 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1418
1419 if (next_hop_sta)
1420 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001421 else
1422 memset(next_hop, 0, ETH_ALEN);
1423
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001424 memset(pinfo, 0, sizeof(*pinfo));
1425
Johannes Bergf5ea9122009-08-07 16:17:38 +02001426 pinfo->generation = mesh_paths_generation;
1427
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001428 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001429 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001430 MPATH_INFO_METRIC |
1431 MPATH_INFO_EXPTIME |
1432 MPATH_INFO_DISCOVERY_TIMEOUT |
1433 MPATH_INFO_DISCOVERY_RETRIES |
1434 MPATH_INFO_FLAGS;
1435
1436 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001437 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001438 pinfo->metric = mpath->metric;
1439 if (time_before(jiffies, mpath->exp_time))
1440 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1441 pinfo->discovery_timeout =
1442 jiffies_to_msecs(mpath->discovery_timeout);
1443 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001444 if (mpath->flags & MESH_PATH_ACTIVE)
1445 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1446 if (mpath->flags & MESH_PATH_RESOLVING)
1447 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001448 if (mpath->flags & MESH_PATH_SN_VALID)
1449 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001450 if (mpath->flags & MESH_PATH_FIXED)
1451 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001452 if (mpath->flags & MESH_PATH_RESOLVED)
1453 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001454}
1455
1456static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1457 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1458
1459{
Johannes Berg14db74b2008-07-29 13:22:52 +02001460 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001461 struct mesh_path *mpath;
1462
Johannes Berg14db74b2008-07-29 13:22:52 +02001463 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1464
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001465 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001466 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001467 if (!mpath) {
1468 rcu_read_unlock();
1469 return -ENOENT;
1470 }
1471 memcpy(dst, mpath->dst, ETH_ALEN);
1472 mpath_set_pinfo(mpath, next_hop, pinfo);
1473 rcu_read_unlock();
1474 return 0;
1475}
1476
1477static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1478 int idx, u8 *dst, u8 *next_hop,
1479 struct mpath_info *pinfo)
1480{
Johannes Berg14db74b2008-07-29 13:22:52 +02001481 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001482 struct mesh_path *mpath;
1483
Johannes Berg14db74b2008-07-29 13:22:52 +02001484 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1485
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001486 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001487 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001488 if (!mpath) {
1489 rcu_read_unlock();
1490 return -ENOENT;
1491 }
1492 memcpy(dst, mpath->dst, ETH_ALEN);
1493 mpath_set_pinfo(mpath, next_hop, pinfo);
1494 rcu_read_unlock();
1495 return 0;
1496}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001497
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001498static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001499 struct net_device *dev,
1500 struct mesh_config *conf)
1501{
1502 struct ieee80211_sub_if_data *sdata;
1503 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1504
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001505 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1506 return 0;
1507}
1508
1509static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1510{
1511 return (mask >> (parm-1)) & 0x1;
1512}
1513
Javier Cardonac80d5452010-12-16 17:37:49 -08001514static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1515 const struct mesh_setup *setup)
1516{
1517 u8 *new_ie;
1518 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001519 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1520 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001521
Javier Cardona581a8b02011-04-07 15:08:27 -07001522 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001523 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001524 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001525
Javier Cardona581a8b02011-04-07 15:08:27 -07001526 if (setup->ie_len) {
1527 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001528 GFP_KERNEL);
1529 if (!new_ie)
1530 return -ENOMEM;
1531 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001532 ifmsh->ie_len = setup->ie_len;
1533 ifmsh->ie = new_ie;
1534 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001535
1536 /* now copy the rest of the setup parameters */
1537 ifmsh->mesh_id_len = setup->mesh_id_len;
1538 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001539 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001540 ifmsh->mesh_pp_id = setup->path_sel_proto;
1541 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001542 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1543 if (setup->is_authenticated)
1544 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1545 if (setup->is_secure)
1546 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001547
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001548 /* mcast rate setting in Mesh Node */
1549 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1550 sizeof(setup->mcast_rate));
1551
Javier Cardonac80d5452010-12-16 17:37:49 -08001552 return 0;
1553}
1554
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001555static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001556 struct net_device *dev, u32 mask,
1557 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001558{
1559 struct mesh_config *conf;
1560 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001561 struct ieee80211_if_mesh *ifmsh;
1562
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001563 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001564 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001565
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001566 /* Set the config options which we are interested in setting */
1567 conf = &(sdata->u.mesh.mshcfg);
1568 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1569 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1570 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1571 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1572 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1573 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1574 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1575 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1576 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1577 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1578 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1579 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001580 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001581 conf->element_ttl = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001582 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1583 conf->auto_open_plinks = nconf->auto_open_plinks;
Javier Cardonad299a1f2012-03-31 11:31:33 -07001584 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1585 conf->dot11MeshNbrOffsetMaxNeighbor =
1586 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001587 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1588 conf->dot11MeshHWMPmaxPREQretries =
1589 nconf->dot11MeshHWMPmaxPREQretries;
1590 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1591 conf->path_refresh_time = nconf->path_refresh_time;
1592 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1593 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1594 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1595 conf->dot11MeshHWMPactivePathTimeout =
1596 nconf->dot11MeshHWMPactivePathTimeout;
1597 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1598 conf->dot11MeshHWMPpreqMinInterval =
1599 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001600 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1601 conf->dot11MeshHWMPperrMinInterval =
1602 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001603 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1604 mask))
1605 conf->dot11MeshHWMPnetDiameterTraversalTime =
1606 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001607 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1608 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1609 ieee80211_mesh_root_setup(ifmsh);
1610 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001611 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001612 /* our current gate announcement implementation rides on root
1613 * announcements, so require this ifmsh to also be a root node
1614 * */
1615 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001616 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1617 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001618 ieee80211_mesh_root_setup(ifmsh);
1619 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001620 conf->dot11MeshGateAnnouncementProtocol =
1621 nconf->dot11MeshGateAnnouncementProtocol;
1622 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001623 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001624 conf->dot11MeshHWMPRannInterval =
1625 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001626 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1627 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001628 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1629 /* our RSSI threshold implementation is supported only for
1630 * devices that report signal in dBm.
1631 */
1632 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1633 return -ENOTSUPP;
1634 conf->rssi_threshold = nconf->rssi_threshold;
1635 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001636 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1637 conf->ht_opmode = nconf->ht_opmode;
1638 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1639 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1640 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001641 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1642 conf->dot11MeshHWMPactivePathToRootTimeout =
1643 nconf->dot11MeshHWMPactivePathToRootTimeout;
1644 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1645 conf->dot11MeshHWMProotInterval =
1646 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001647 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1648 conf->dot11MeshHWMPconfirmationInterval =
1649 nconf->dot11MeshHWMPconfirmationInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001650 return 0;
1651}
1652
Johannes Berg29cbe682010-12-03 09:20:44 +01001653static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1654 const struct mesh_config *conf,
1655 const struct mesh_setup *setup)
1656{
1657 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1658 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001659 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001660
Javier Cardonac80d5452010-12-16 17:37:49 -08001661 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1662 err = copy_mesh_setup(ifmsh, setup);
1663 if (err)
1664 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001665
1666 err = ieee80211_set_channel(wiphy, dev, setup->channel,
1667 setup->channel_type);
1668 if (err)
1669 return err;
1670
Johannes Berg29cbe682010-12-03 09:20:44 +01001671 ieee80211_start_mesh(sdata);
1672
1673 return 0;
1674}
1675
1676static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1677{
1678 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1679
1680 ieee80211_stop_mesh(sdata);
1681
1682 return 0;
1683}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001684#endif
1685
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001686static int ieee80211_change_bss(struct wiphy *wiphy,
1687 struct net_device *dev,
1688 struct bss_parameters *params)
1689{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001690 struct ieee80211_sub_if_data *sdata;
1691 u32 changed = 0;
1692
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001693 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1694
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001695 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001696 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001697 changed |= BSS_CHANGED_ERP_CTS_PROT;
1698 }
1699 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001700 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001701 params->use_short_preamble;
1702 changed |= BSS_CHANGED_ERP_PREAMBLE;
1703 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001704
1705 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg679ef4e2012-07-23 14:29:21 +02001706 sdata->local->oper_channel->band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001707 sdata->vif.bss_conf.use_short_slot = true;
1708 changed |= BSS_CHANGED_ERP_SLOT;
1709 }
1710
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001711 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001712 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001713 params->use_short_slot_time;
1714 changed |= BSS_CHANGED_ERP_SLOT;
1715 }
1716
Jouni Malinen90c97a02008-10-30 16:59:22 +02001717 if (params->basic_rates) {
1718 int i, j;
1719 u32 rates = 0;
1720 struct ieee80211_local *local = wiphy_priv(wiphy);
1721 struct ieee80211_supported_band *sband =
1722 wiphy->bands[local->oper_channel->band];
1723
1724 for (i = 0; i < params->basic_rates_len; i++) {
1725 int rate = (params->basic_rates[i] & 0x7f) * 5;
1726 for (j = 0; j < sband->n_bitrates; j++) {
1727 if (sband->bitrates[j].bitrate == rate)
1728 rates |= BIT(j);
1729 }
1730 }
1731 sdata->vif.bss_conf.basic_rates = rates;
1732 changed |= BSS_CHANGED_BASIC_RATES;
1733 }
1734
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001735 if (params->ap_isolate >= 0) {
1736 if (params->ap_isolate)
1737 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1738 else
1739 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1740 }
1741
Helmut Schaa80d7e402010-11-19 12:40:26 +01001742 if (params->ht_opmode >= 0) {
1743 sdata->vif.bss_conf.ht_operation_mode =
1744 (u16) params->ht_opmode;
1745 changed |= BSS_CHANGED_HT;
1746 }
1747
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001748 ieee80211_bss_info_change_notify(sdata, changed);
1749
1750 return 0;
1751}
1752
Jouni Malinen31888482008-10-30 16:59:24 +02001753static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001754 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001755 struct ieee80211_txq_params *params)
1756{
1757 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001758 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001759 struct ieee80211_tx_queue_params p;
1760
1761 if (!local->ops->conf_tx)
1762 return -EOPNOTSUPP;
1763
Johannes Berg54bcbc62012-03-28 11:04:25 +02001764 if (local->hw.queues < IEEE80211_NUM_ACS)
1765 return -EOPNOTSUPP;
1766
Jouni Malinen31888482008-10-30 16:59:24 +02001767 memset(&p, 0, sizeof(p));
1768 p.aifs = params->aifs;
1769 p.cw_max = params->cwmax;
1770 p.cw_min = params->cwmin;
1771 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001772
1773 /*
1774 * Setting tx queue params disables u-apsd because it's only
1775 * called in master mode.
1776 */
1777 p.uapsd = false;
1778
Johannes Berga3304b02012-03-28 11:04:24 +02001779 sdata->tx_conf[params->ac] = p;
1780 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001781 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001782 "failed to set TX queue parameters for AC %d\n",
1783 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001784 return -EINVAL;
1785 }
1786
Johannes Berg7d257452012-07-06 17:37:43 +02001787 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1788
Jouni Malinen31888482008-10-30 16:59:24 +02001789 return 0;
1790}
1791
Bob Copeland665af4f2009-01-19 11:20:53 -05001792#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001793static int ieee80211_suspend(struct wiphy *wiphy,
1794 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001795{
Johannes Bergeecc4802011-05-04 15:37:29 +02001796 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001797}
1798
1799static int ieee80211_resume(struct wiphy *wiphy)
1800{
1801 return __ieee80211_resume(wiphy_priv(wiphy));
1802}
1803#else
1804#define ieee80211_suspend NULL
1805#define ieee80211_resume NULL
1806#endif
1807
Johannes Berg2a519312009-02-10 21:25:55 +01001808static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001809 struct cfg80211_scan_request *req)
1810{
Johannes Bergfd014282012-06-18 19:17:03 +02001811 struct ieee80211_sub_if_data *sdata;
1812
1813 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001814
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001815 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1816 case NL80211_IFTYPE_STATION:
1817 case NL80211_IFTYPE_ADHOC:
1818 case NL80211_IFTYPE_MESH_POINT:
1819 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001820 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001821 break;
1822 case NL80211_IFTYPE_P2P_GO:
1823 if (sdata->local->ops->hw_scan)
1824 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001825 /*
1826 * FIXME: implement NoA while scanning in software,
1827 * for now fall through to allow scanning only when
1828 * beaconing hasn't been configured yet
1829 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001830 case NL80211_IFTYPE_AP:
1831 if (sdata->u.ap.beacon)
1832 return -EOPNOTSUPP;
1833 break;
1834 default:
1835 return -EOPNOTSUPP;
1836 }
Johannes Berg2a519312009-02-10 21:25:55 +01001837
1838 return ieee80211_request_scan(sdata, req);
1839}
1840
Luciano Coelho79f460c2011-05-11 17:09:36 +03001841static int
1842ieee80211_sched_scan_start(struct wiphy *wiphy,
1843 struct net_device *dev,
1844 struct cfg80211_sched_scan_request *req)
1845{
1846 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1847
1848 if (!sdata->local->ops->sched_scan_start)
1849 return -EOPNOTSUPP;
1850
1851 return ieee80211_request_sched_scan_start(sdata, req);
1852}
1853
1854static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001855ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001856{
1857 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1858
1859 if (!sdata->local->ops->sched_scan_stop)
1860 return -EOPNOTSUPP;
1861
Luciano Coelho85a99942011-05-12 16:28:29 +03001862 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001863}
1864
Jouni Malinen636a5d32009-03-19 13:39:22 +02001865static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1866 struct cfg80211_auth_request *req)
1867{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001868 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001869}
1870
1871static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1872 struct cfg80211_assoc_request *req)
1873{
Johannes Bergf444de02010-05-05 15:25:02 +02001874 struct ieee80211_local *local = wiphy_priv(wiphy);
1875 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1876
1877 switch (ieee80211_get_channel_mode(local, sdata)) {
1878 case CHAN_MODE_HOPPING:
1879 return -EBUSY;
1880 case CHAN_MODE_FIXED:
1881 if (local->oper_channel == req->bss->channel)
1882 break;
1883 return -EBUSY;
1884 case CHAN_MODE_UNDEFINED:
1885 break;
1886 }
1887
Johannes Berg77fdaa12009-07-07 03:45:17 +02001888 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001889}
1890
1891static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001892 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001893{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001894 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001895}
1896
1897static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001898 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001899{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001900 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001901}
1902
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001903static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1904 struct cfg80211_ibss_params *params)
1905{
Johannes Bergf444de02010-05-05 15:25:02 +02001906 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001907 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1908
Johannes Bergf444de02010-05-05 15:25:02 +02001909 switch (ieee80211_get_channel_mode(local, sdata)) {
1910 case CHAN_MODE_HOPPING:
1911 return -EBUSY;
1912 case CHAN_MODE_FIXED:
1913 if (!params->channel_fixed)
1914 return -EBUSY;
1915 if (local->oper_channel == params->channel)
1916 break;
1917 return -EBUSY;
1918 case CHAN_MODE_UNDEFINED:
1919 break;
1920 }
1921
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001922 return ieee80211_ibss_join(sdata, params);
1923}
1924
1925static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1926{
1927 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1928
1929 return ieee80211_ibss_leave(sdata);
1930}
1931
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001932static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1933{
1934 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001935 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001936
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001937 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1938 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1939
1940 if (err)
1941 return err;
1942 }
1943
Lukáš Turek310bc672009-12-21 22:50:48 +01001944 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1945 err = drv_set_coverage_class(local, wiphy->coverage_class);
1946
1947 if (err)
1948 return err;
1949 }
1950
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001951 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001952 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001953
Johannes Berg24487982009-04-23 18:52:52 +02001954 if (err)
1955 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001956 }
1957
1958 if (changed & WIPHY_PARAM_RETRY_SHORT)
1959 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1960 if (changed & WIPHY_PARAM_RETRY_LONG)
1961 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1962 if (changed &
1963 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1964 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1965
1966 return 0;
1967}
1968
Johannes Berg7643a2c2009-06-02 13:01:39 +02001969static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001970 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001971{
1972 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg679ef4e2012-07-23 14:29:21 +02001973 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001974 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001975
1976 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001977 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001978 local->user_power_level = -1;
1979 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001980 case NL80211_TX_POWER_LIMITED:
1981 if (mbm < 0 || (mbm % 100))
1982 return -EOPNOTSUPP;
1983 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001984 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001985 case NL80211_TX_POWER_FIXED:
1986 if (mbm < 0 || (mbm % 100))
1987 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001988 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001989 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001990 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001991 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001992 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001993 }
1994
1995 ieee80211_hw_config(local, changes);
1996
1997 return 0;
1998}
1999
2000static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
2001{
2002 struct ieee80211_local *local = wiphy_priv(wiphy);
2003
2004 *dbm = local->hw.conf.power_level;
2005
Johannes Berg7643a2c2009-06-02 13:01:39 +02002006 return 0;
2007}
2008
Johannes Bergab737a42009-07-01 21:26:58 +02002009static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02002010 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02002011{
2012 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2013
2014 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
2015
2016 return 0;
2017}
2018
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002019static void ieee80211_rfkill_poll(struct wiphy *wiphy)
2020{
2021 struct ieee80211_local *local = wiphy_priv(wiphy);
2022
2023 drv_rfkill_poll(local);
2024}
2025
Johannes Bergaff89a92009-07-01 21:26:51 +02002026#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02002027static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02002028{
2029 struct ieee80211_local *local = wiphy_priv(wiphy);
2030
2031 if (!local->ops->testmode_cmd)
2032 return -EOPNOTSUPP;
2033
2034 return local->ops->testmode_cmd(&local->hw, data, len);
2035}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002036
2037static int ieee80211_testmode_dump(struct wiphy *wiphy,
2038 struct sk_buff *skb,
2039 struct netlink_callback *cb,
2040 void *data, int len)
2041{
2042 struct ieee80211_local *local = wiphy_priv(wiphy);
2043
2044 if (!local->ops->testmode_dump)
2045 return -EOPNOTSUPP;
2046
2047 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2048}
Johannes Bergaff89a92009-07-01 21:26:51 +02002049#endif
2050
Johannes Berg0f782312009-12-01 13:37:02 +01002051int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2052 enum ieee80211_smps_mode smps_mode)
2053{
2054 const u8 *ap;
2055 enum ieee80211_smps_mode old_req;
2056 int err;
2057
Johannes Berg243e6df2011-04-19 20:44:04 +02002058 lockdep_assert_held(&sdata->u.mgd.mtx);
2059
Johannes Berg0f782312009-12-01 13:37:02 +01002060 old_req = sdata->u.mgd.req_smps;
2061 sdata->u.mgd.req_smps = smps_mode;
2062
2063 if (old_req == smps_mode &&
2064 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2065 return 0;
2066
2067 /*
2068 * If not associated, or current association is not an HT
2069 * association, there's no need to send an action frame.
2070 */
2071 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02002072 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01002073 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02002074 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01002075 mutex_unlock(&sdata->local->iflist_mtx);
2076 return 0;
2077 }
2078
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002079 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002080
2081 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2082 if (sdata->u.mgd.powersave)
2083 smps_mode = IEEE80211_SMPS_DYNAMIC;
2084 else
2085 smps_mode = IEEE80211_SMPS_OFF;
2086 }
2087
2088 /* send SM PS frame to AP */
2089 err = ieee80211_send_smps_action(sdata, smps_mode,
2090 ap, ap);
2091 if (err)
2092 sdata->u.mgd.req_smps = old_req;
2093
2094 return err;
2095}
2096
Johannes Bergbc92afd2009-07-01 21:26:57 +02002097static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2098 bool enabled, int timeout)
2099{
2100 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2101 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002102
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002103 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2104 return -EOPNOTSUPP;
2105
Johannes Bergbc92afd2009-07-01 21:26:57 +02002106 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2107 return -EOPNOTSUPP;
2108
2109 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002110 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002111 return 0;
2112
2113 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002114 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002115
Johannes Berg0f782312009-12-01 13:37:02 +01002116 /* no change, but if automatic follow powersave */
2117 mutex_lock(&sdata->u.mgd.mtx);
2118 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2119 mutex_unlock(&sdata->u.mgd.mtx);
2120
Johannes Bergbc92afd2009-07-01 21:26:57 +02002121 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2122 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2123
2124 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002125 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002126
2127 return 0;
2128}
2129
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002130static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2131 struct net_device *dev,
2132 s32 rssi_thold, u32 rssi_hyst)
2133{
2134 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002135 struct ieee80211_vif *vif = &sdata->vif;
2136 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2137
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002138 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2139 rssi_hyst == bss_conf->cqm_rssi_hyst)
2140 return 0;
2141
2142 bss_conf->cqm_rssi_thold = rssi_thold;
2143 bss_conf->cqm_rssi_hyst = rssi_hyst;
2144
2145 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002146 if (sdata->u.mgd.associated &&
2147 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002148 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2149
2150 return 0;
2151}
2152
Johannes Berg99303802009-07-01 21:26:59 +02002153static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2154 struct net_device *dev,
2155 const u8 *addr,
2156 const struct cfg80211_bitrate_mask *mask)
2157{
2158 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2159 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302160 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002161
Eliad Peller554a43d2012-06-12 12:41:15 +03002162 if (!ieee80211_sdata_running(sdata))
2163 return -ENETDOWN;
2164
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302165 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2166 ret = drv_set_bitrate_mask(local, sdata, mask);
2167 if (ret)
2168 return ret;
2169 }
Johannes Berg99303802009-07-01 21:26:59 +02002170
Simon Wunderlich19468412012-01-28 17:25:33 +01002171 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002172 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002173 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2174 sizeof(mask->control[i].mcs));
2175 }
Johannes Berg99303802009-07-01 21:26:59 +02002176
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002177 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002178}
2179
Johannes Berg2eb278e2012-06-05 14:28:42 +02002180static int ieee80211_start_roc_work(struct ieee80211_local *local,
2181 struct ieee80211_sub_if_data *sdata,
2182 struct ieee80211_channel *channel,
2183 enum nl80211_channel_type channel_type,
2184 unsigned int duration, u64 *cookie,
2185 struct sk_buff *txskb)
Johannes Berg21f83582010-12-18 17:20:47 +01002186{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002187 struct ieee80211_roc_work *roc, *tmp;
2188 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002189 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002190
2191 lockdep_assert_held(&local->mtx);
2192
Johannes Berg2eb278e2012-06-05 14:28:42 +02002193 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2194 if (!roc)
2195 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002196
Johannes Berg2eb278e2012-06-05 14:28:42 +02002197 roc->chan = channel;
2198 roc->chan_type = channel_type;
2199 roc->duration = duration;
2200 roc->req_duration = duration;
2201 roc->frame = txskb;
2202 roc->mgmt_tx_cookie = (unsigned long)txskb;
2203 roc->sdata = sdata;
2204 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2205 INIT_LIST_HEAD(&roc->dependents);
2206
2207 /* if there's one pending or we're scanning, queue this one */
2208 if (!list_empty(&local->roc_list) || local->scanning)
2209 goto out_check_combine;
2210
2211 /* if not HW assist, just queue & schedule work */
2212 if (!local->ops->remain_on_channel) {
2213 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2214 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002215 }
2216
Johannes Berg2eb278e2012-06-05 14:28:42 +02002217 /* otherwise actually kick it off here (for error handling) */
2218
2219 /*
2220 * If the duration is zero, then the driver
2221 * wouldn't actually do anything. Set it to
2222 * 10 for now.
2223 *
2224 * TODO: cancel the off-channel operation
2225 * when we get the SKB's TX status and
2226 * the wait time was zero before.
2227 */
2228 if (!duration)
2229 duration = 10;
2230
2231 ret = drv_remain_on_channel(local, channel, channel_type, duration);
2232 if (ret) {
2233 kfree(roc);
2234 return ret;
2235 }
2236
2237 roc->started = true;
2238 goto out_queue;
2239
2240 out_check_combine:
2241 list_for_each_entry(tmp, &local->roc_list, list) {
2242 if (tmp->chan != channel || tmp->chan_type != channel_type)
2243 continue;
2244
2245 /*
2246 * Extend this ROC if possible:
2247 *
2248 * If it hasn't started yet, just increase the duration
2249 * and add the new one to the list of dependents.
2250 */
2251 if (!tmp->started) {
2252 list_add_tail(&roc->list, &tmp->dependents);
2253 tmp->duration = max(tmp->duration, roc->duration);
2254 queued = true;
2255 break;
2256 }
2257
2258 /* If it has already started, it's more difficult ... */
2259 if (local->ops->remain_on_channel) {
2260 unsigned long j = jiffies;
2261
2262 /*
2263 * In the offloaded ROC case, if it hasn't begun, add
2264 * this new one to the dependent list to be handled
2265 * when the the master one begins. If it has begun,
2266 * check that there's still a minimum time left and
2267 * if so, start this one, transmitting the frame, but
2268 * add it to the list directly after this one with a
2269 * a reduced time so we'll ask the driver to execute
2270 * it right after finishing the previous one, in the
2271 * hope that it'll also be executed right afterwards,
2272 * effectively extending the old one.
2273 * If there's no minimum time left, just add it to the
2274 * normal list.
2275 */
2276 if (!tmp->hw_begun) {
2277 list_add_tail(&roc->list, &tmp->dependents);
2278 queued = true;
2279 break;
2280 }
2281
2282 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2283 tmp->hw_start_time +
2284 msecs_to_jiffies(tmp->duration))) {
2285 int new_dur;
2286
2287 ieee80211_handle_roc_started(roc);
2288
2289 new_dur = roc->duration -
2290 jiffies_to_msecs(tmp->hw_start_time +
2291 msecs_to_jiffies(
2292 tmp->duration) -
2293 j);
2294
2295 if (new_dur > 0) {
2296 /* add right after tmp */
2297 list_add(&roc->list, &tmp->list);
2298 } else {
2299 list_add_tail(&roc->list,
2300 &tmp->dependents);
2301 }
2302 queued = true;
2303 }
2304 } else if (del_timer_sync(&tmp->work.timer)) {
2305 unsigned long new_end;
2306
2307 /*
2308 * In the software ROC case, cancel the timer, if
2309 * that fails then the finish work is already
2310 * queued/pending and thus we queue the new ROC
2311 * normally, if that succeeds then we can extend
2312 * the timer duration and TX the frame (if any.)
2313 */
2314
2315 list_add_tail(&roc->list, &tmp->dependents);
2316 queued = true;
2317
2318 new_end = jiffies + msecs_to_jiffies(roc->duration);
2319
2320 /* ok, it was started & we canceled timer */
2321 if (time_after(new_end, tmp->work.timer.expires))
2322 mod_timer(&tmp->work.timer, new_end);
2323 else
2324 add_timer(&tmp->work.timer);
2325
2326 ieee80211_handle_roc_started(roc);
2327 }
2328 break;
2329 }
2330
2331 out_queue:
2332 if (!queued)
2333 list_add_tail(&roc->list, &local->roc_list);
2334
2335 /*
2336 * cookie is either the roc (for normal roc)
2337 * or the SKB (for mgmt TX)
2338 */
2339 if (txskb)
2340 *cookie = (unsigned long)txskb;
2341 else
2342 *cookie = (unsigned long)roc;
2343
2344 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002345}
2346
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002347static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002348 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002349 struct ieee80211_channel *chan,
2350 enum nl80211_channel_type channel_type,
2351 unsigned int duration,
2352 u64 *cookie)
2353{
Johannes Berg71bbc992012-06-15 15:30:18 +02002354 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002355 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002356 int ret;
2357
Johannes Berg2eb278e2012-06-05 14:28:42 +02002358 mutex_lock(&local->mtx);
2359 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2360 duration, cookie, NULL);
2361 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002362
Johannes Berg2eb278e2012-06-05 14:28:42 +02002363 return ret;
2364}
2365
2366static int ieee80211_cancel_roc(struct ieee80211_local *local,
2367 u64 cookie, bool mgmt_tx)
2368{
2369 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2370 int ret;
2371
2372 mutex_lock(&local->mtx);
2373 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002374 struct ieee80211_roc_work *dep, *tmp2;
2375
2376 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2377 if (!mgmt_tx && (unsigned long)dep != cookie)
2378 continue;
2379 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2380 continue;
2381 /* found dependent item -- just remove it */
2382 list_del(&dep->list);
2383 mutex_unlock(&local->mtx);
2384
2385 ieee80211_roc_notify_destroy(dep);
2386 return 0;
2387 }
2388
Johannes Berg2eb278e2012-06-05 14:28:42 +02002389 if (!mgmt_tx && (unsigned long)roc != cookie)
2390 continue;
2391 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2392 continue;
2393
2394 found = roc;
2395 break;
2396 }
2397
2398 if (!found) {
2399 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002400 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002401 }
Johannes Berg21f83582010-12-18 17:20:47 +01002402
Johannes Berge979e332012-06-11 17:09:41 +02002403 /*
2404 * We found the item to cancel, so do that. Note that it
2405 * may have dependents, which we also cancel (and send
2406 * the expired signal for.) Not doing so would be quite
2407 * tricky here, but we may need to fix it later.
2408 */
2409
Johannes Berg2eb278e2012-06-05 14:28:42 +02002410 if (local->ops->remain_on_channel) {
2411 if (found->started) {
2412 ret = drv_cancel_remain_on_channel(local);
2413 if (WARN_ON_ONCE(ret)) {
2414 mutex_unlock(&local->mtx);
2415 return ret;
2416 }
2417 }
Johannes Berg21f83582010-12-18 17:20:47 +01002418
Johannes Berg2eb278e2012-06-05 14:28:42 +02002419 list_del(&found->list);
2420
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002421 if (found->started)
2422 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002423 mutex_unlock(&local->mtx);
2424
2425 ieee80211_roc_notify_destroy(found);
2426 } else {
2427 /* work may be pending so use it all the time */
2428 found->abort = true;
2429 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2430
2431 mutex_unlock(&local->mtx);
2432
2433 /* work will clean up etc */
2434 flush_delayed_work(&found->work);
2435 }
Johannes Berg21f83582010-12-18 17:20:47 +01002436
Johannes Berg21f83582010-12-18 17:20:47 +01002437 return 0;
2438}
2439
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002440static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002441 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002442 u64 cookie)
2443{
Johannes Berg71bbc992012-06-15 15:30:18 +02002444 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002445 struct ieee80211_local *local = sdata->local;
2446
Johannes Berg2eb278e2012-06-05 14:28:42 +02002447 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002448}
2449
Johannes Berg71bbc992012-06-15 15:30:18 +02002450static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002451 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f72010-08-12 15:38:38 +02002452 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002453 bool channel_type_valid, unsigned int wait,
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05302454 const u8 *buf, size_t len, bool no_cck,
Johannes Berge247bd902011-11-04 11:18:21 +01002455 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002456{
Johannes Berg71bbc992012-06-15 15:30:18 +02002457 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002458 struct ieee80211_local *local = sdata->local;
2459 struct sk_buff *skb;
2460 struct sta_info *sta;
2461 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002462 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002463 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002464 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002465
Johannes Berge247bd902011-11-04 11:18:21 +01002466 if (dont_wait_for_ack)
2467 flags = IEEE80211_TX_CTL_NO_ACK;
2468 else
2469 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2470 IEEE80211_TX_CTL_REQ_TX_STATUS;
2471
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302472 if (no_cck)
2473 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2474
Johannes Berg9d38d852010-06-09 17:20:33 +02002475 switch (sdata->vif.type) {
2476 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002477 if (!sdata->vif.bss_conf.ibss_joined)
2478 need_offchan = true;
2479 /* fall through */
2480#ifdef CONFIG_MAC80211_MESH
2481 case NL80211_IFTYPE_MESH_POINT:
2482 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2483 !sdata->u.mesh.mesh_id_len)
2484 need_offchan = true;
2485 /* fall through */
2486#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002487 case NL80211_IFTYPE_AP:
2488 case NL80211_IFTYPE_AP_VLAN:
2489 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002490 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2491 !ieee80211_vif_is_mesh(&sdata->vif) &&
2492 !rcu_access_pointer(sdata->bss->beacon))
2493 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002494 if (!ieee80211_is_action(mgmt->frame_control) ||
2495 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002496 break;
2497 rcu_read_lock();
2498 sta = sta_info_get(sdata, mgmt->da);
2499 rcu_read_unlock();
2500 if (!sta)
2501 return -ENOLINK;
2502 break;
2503 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002504 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002505 if (!sdata->u.mgd.associated)
2506 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002507 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002508 case NL80211_IFTYPE_P2P_DEVICE:
2509 need_offchan = true;
2510 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002511 default:
2512 return -EOPNOTSUPP;
2513 }
2514
Johannes Berg2eb278e2012-06-05 14:28:42 +02002515 mutex_lock(&local->mtx);
2516
2517 /* Check if the operating channel is the requested channel */
2518 if (!need_offchan) {
2519 need_offchan = chan != local->oper_channel;
2520 if (channel_type_valid &&
2521 channel_type != local->_oper_channel_type)
2522 need_offchan = true;
2523 }
2524
2525 if (need_offchan && !offchan) {
2526 ret = -EBUSY;
2527 goto out_unlock;
2528 }
2529
Johannes Berg9d38d852010-06-09 17:20:33 +02002530 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002531 if (!skb) {
2532 ret = -ENOMEM;
2533 goto out_unlock;
2534 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002535 skb_reserve(skb, local->hw.extra_tx_headroom);
2536
2537 memcpy(skb_put(skb, len), buf, len);
2538
2539 IEEE80211_SKB_CB(skb)->flags = flags;
2540
Johannes Berg2eb278e2012-06-05 14:28:42 +02002541 skb->dev = sdata->dev;
2542
2543 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002544 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002545 ieee80211_tx_skb(sdata, skb);
2546 ret = 0;
2547 goto out_unlock;
2548 }
2549
2550 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2551 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002552 IEEE80211_SKB_CB(skb)->hw_queue =
2553 local->hw.offchannel_tx_hw_queue;
2554
Johannes Berg2eb278e2012-06-05 14:28:42 +02002555 /* This will handle all kinds of coalescing and immediate TX */
2556 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2557 wait, cookie, skb);
2558 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002559 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002560 out_unlock:
2561 mutex_unlock(&local->mtx);
2562 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002563}
2564
Johannes Bergf30221e2010-11-25 10:02:30 +01002565static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002566 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002567 u64 cookie)
2568{
Johannes Berg71bbc992012-06-15 15:30:18 +02002569 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002570
Johannes Berg2eb278e2012-06-05 14:28:42 +02002571 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002572}
2573
Johannes Berg7be50862010-10-13 12:06:24 +02002574static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002575 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002576 u16 frame_type, bool reg)
2577{
2578 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002579 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002580
Will Hawkins6abe0562012-06-20 11:51:14 -04002581 switch (frame_type) {
2582 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2583 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2584 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002585
Will Hawkins6abe0562012-06-20 11:51:14 -04002586 if (reg)
2587 ifibss->auth_frame_registrations++;
2588 else
2589 ifibss->auth_frame_registrations--;
2590 }
2591 break;
2592 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2593 if (reg)
2594 local->probe_req_reg++;
2595 else
2596 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002597
Will Hawkins6abe0562012-06-20 11:51:14 -04002598 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2599 break;
2600 default:
2601 break;
2602 }
Johannes Berg7be50862010-10-13 12:06:24 +02002603}
2604
Bruno Randolf15d96752010-11-10 12:50:56 +09002605static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2606{
2607 struct ieee80211_local *local = wiphy_priv(wiphy);
2608
2609 if (local->started)
2610 return -EOPNOTSUPP;
2611
2612 return drv_set_antenna(local, tx_ant, rx_ant);
2613}
2614
2615static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2616{
2617 struct ieee80211_local *local = wiphy_priv(wiphy);
2618
2619 return drv_get_antenna(local, tx_ant, rx_ant);
2620}
2621
John W. Linville38c09152011-03-07 16:19:18 -05002622static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2623{
2624 struct ieee80211_local *local = wiphy_priv(wiphy);
2625
2626 return drv_set_ringparam(local, tx, rx);
2627}
2628
2629static void ieee80211_get_ringparam(struct wiphy *wiphy,
2630 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2631{
2632 struct ieee80211_local *local = wiphy_priv(wiphy);
2633
2634 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2635}
2636
Johannes Bergc68f4b82011-07-05 16:35:41 +02002637static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2638 struct net_device *dev,
2639 struct cfg80211_gtk_rekey_data *data)
2640{
2641 struct ieee80211_local *local = wiphy_priv(wiphy);
2642 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2643
2644 if (!local->ops->set_rekey_data)
2645 return -EOPNOTSUPP;
2646
2647 drv_set_rekey_data(local, sdata, data);
2648
2649 return 0;
2650}
2651
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002652static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2653{
2654 u8 *pos = (void *)skb_put(skb, 7);
2655
2656 *pos++ = WLAN_EID_EXT_CAPABILITY;
2657 *pos++ = 5; /* len */
2658 *pos++ = 0x0;
2659 *pos++ = 0x0;
2660 *pos++ = 0x0;
2661 *pos++ = 0x0;
2662 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2663}
2664
2665static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2666{
2667 struct ieee80211_local *local = sdata->local;
2668 u16 capab;
2669
2670 capab = 0;
2671 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2672 return capab;
2673
2674 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2675 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2676 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2677 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2678
2679 return capab;
2680}
2681
2682static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2683 u8 *peer, u8 *bssid)
2684{
2685 struct ieee80211_tdls_lnkie *lnkid;
2686
2687 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2688
2689 lnkid->ie_type = WLAN_EID_LINK_ID;
2690 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2691
2692 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2693 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2694 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2695}
2696
2697static int
2698ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2699 u8 *peer, u8 action_code, u8 dialog_token,
2700 u16 status_code, struct sk_buff *skb)
2701{
2702 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg6b778632012-07-23 14:53:27 +02002703 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002704 struct ieee80211_tdls_data *tf;
2705
2706 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2707
2708 memcpy(tf->da, peer, ETH_ALEN);
2709 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2710 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2711 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2712
2713 switch (action_code) {
2714 case WLAN_TDLS_SETUP_REQUEST:
2715 tf->category = WLAN_CATEGORY_TDLS;
2716 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2717
2718 skb_put(skb, sizeof(tf->u.setup_req));
2719 tf->u.setup_req.dialog_token = dialog_token;
2720 tf->u.setup_req.capability =
2721 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2722
Johannes Berg6b778632012-07-23 14:53:27 +02002723 ieee80211_add_srates_ie(sdata, skb, false,
2724 local->oper_channel->band);
2725 ieee80211_add_ext_srates_ie(sdata, skb, false,
2726 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002727 ieee80211_tdls_add_ext_capab(skb);
2728 break;
2729 case WLAN_TDLS_SETUP_RESPONSE:
2730 tf->category = WLAN_CATEGORY_TDLS;
2731 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2732
2733 skb_put(skb, sizeof(tf->u.setup_resp));
2734 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2735 tf->u.setup_resp.dialog_token = dialog_token;
2736 tf->u.setup_resp.capability =
2737 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2738
Johannes Berg6b778632012-07-23 14:53:27 +02002739 ieee80211_add_srates_ie(sdata, skb, false,
2740 local->oper_channel->band);
2741 ieee80211_add_ext_srates_ie(sdata, skb, false,
2742 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002743 ieee80211_tdls_add_ext_capab(skb);
2744 break;
2745 case WLAN_TDLS_SETUP_CONFIRM:
2746 tf->category = WLAN_CATEGORY_TDLS;
2747 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2748
2749 skb_put(skb, sizeof(tf->u.setup_cfm));
2750 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2751 tf->u.setup_cfm.dialog_token = dialog_token;
2752 break;
2753 case WLAN_TDLS_TEARDOWN:
2754 tf->category = WLAN_CATEGORY_TDLS;
2755 tf->action_code = WLAN_TDLS_TEARDOWN;
2756
2757 skb_put(skb, sizeof(tf->u.teardown));
2758 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2759 break;
2760 case WLAN_TDLS_DISCOVERY_REQUEST:
2761 tf->category = WLAN_CATEGORY_TDLS;
2762 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2763
2764 skb_put(skb, sizeof(tf->u.discover_req));
2765 tf->u.discover_req.dialog_token = dialog_token;
2766 break;
2767 default:
2768 return -EINVAL;
2769 }
2770
2771 return 0;
2772}
2773
2774static int
2775ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2776 u8 *peer, u8 action_code, u8 dialog_token,
2777 u16 status_code, struct sk_buff *skb)
2778{
2779 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg6b778632012-07-23 14:53:27 +02002780 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002781 struct ieee80211_mgmt *mgmt;
2782
2783 mgmt = (void *)skb_put(skb, 24);
2784 memset(mgmt, 0, 24);
2785 memcpy(mgmt->da, peer, ETH_ALEN);
2786 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2787 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2788
2789 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2790 IEEE80211_STYPE_ACTION);
2791
2792 switch (action_code) {
2793 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2794 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2795 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2796 mgmt->u.action.u.tdls_discover_resp.action_code =
2797 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2798 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2799 dialog_token;
2800 mgmt->u.action.u.tdls_discover_resp.capability =
2801 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2802
Johannes Berg6b778632012-07-23 14:53:27 +02002803 ieee80211_add_srates_ie(sdata, skb, false,
2804 local->oper_channel->band);
2805 ieee80211_add_ext_srates_ie(sdata, skb, false,
2806 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002807 ieee80211_tdls_add_ext_capab(skb);
2808 break;
2809 default:
2810 return -EINVAL;
2811 }
2812
2813 return 0;
2814}
2815
2816static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2817 u8 *peer, u8 action_code, u8 dialog_token,
2818 u16 status_code, const u8 *extra_ies,
2819 size_t extra_ies_len)
2820{
2821 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2822 struct ieee80211_local *local = sdata->local;
2823 struct ieee80211_tx_info *info;
2824 struct sk_buff *skb = NULL;
2825 bool send_direct;
2826 int ret;
2827
2828 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2829 return -ENOTSUPP;
2830
2831 /* make sure we are in managed mode, and associated */
2832 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2833 !sdata->u.mgd.associated)
2834 return -EINVAL;
2835
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002836 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
2837 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002838
2839 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2840 max(sizeof(struct ieee80211_mgmt),
2841 sizeof(struct ieee80211_tdls_data)) +
2842 50 + /* supported rates */
2843 7 + /* ext capab */
2844 extra_ies_len +
2845 sizeof(struct ieee80211_tdls_lnkie));
2846 if (!skb)
2847 return -ENOMEM;
2848
2849 info = IEEE80211_SKB_CB(skb);
2850 skb_reserve(skb, local->hw.extra_tx_headroom);
2851
2852 switch (action_code) {
2853 case WLAN_TDLS_SETUP_REQUEST:
2854 case WLAN_TDLS_SETUP_RESPONSE:
2855 case WLAN_TDLS_SETUP_CONFIRM:
2856 case WLAN_TDLS_TEARDOWN:
2857 case WLAN_TDLS_DISCOVERY_REQUEST:
2858 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2859 action_code, dialog_token,
2860 status_code, skb);
2861 send_direct = false;
2862 break;
2863 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2864 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2865 dialog_token, status_code,
2866 skb);
2867 send_direct = true;
2868 break;
2869 default:
2870 ret = -ENOTSUPP;
2871 break;
2872 }
2873
2874 if (ret < 0)
2875 goto fail;
2876
2877 if (extra_ies_len)
2878 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2879
2880 /* the TDLS link IE is always added last */
2881 switch (action_code) {
2882 case WLAN_TDLS_SETUP_REQUEST:
2883 case WLAN_TDLS_SETUP_CONFIRM:
2884 case WLAN_TDLS_TEARDOWN:
2885 case WLAN_TDLS_DISCOVERY_REQUEST:
2886 /* we are the initiator */
2887 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2888 sdata->u.mgd.bssid);
2889 break;
2890 case WLAN_TDLS_SETUP_RESPONSE:
2891 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2892 /* we are the responder */
2893 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2894 sdata->u.mgd.bssid);
2895 break;
2896 default:
2897 ret = -ENOTSUPP;
2898 goto fail;
2899 }
2900
2901 if (send_direct) {
2902 ieee80211_tx_skb(sdata, skb);
2903 return 0;
2904 }
2905
2906 /*
2907 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2908 * we should default to AC_VI.
2909 */
2910 switch (action_code) {
2911 case WLAN_TDLS_SETUP_REQUEST:
2912 case WLAN_TDLS_SETUP_RESPONSE:
2913 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2914 skb->priority = 2;
2915 break;
2916 default:
2917 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2918 skb->priority = 5;
2919 break;
2920 }
2921
2922 /* disable bottom halves when entering the Tx path */
2923 local_bh_disable();
2924 ret = ieee80211_subif_start_xmit(skb, dev);
2925 local_bh_enable();
2926
2927 return ret;
2928
2929fail:
2930 dev_kfree_skb(skb);
2931 return ret;
2932}
2933
2934static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2935 u8 *peer, enum nl80211_tdls_operation oper)
2936{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002937 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002938 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2939
2940 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2941 return -ENOTSUPP;
2942
2943 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2944 return -EINVAL;
2945
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002946 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002947
2948 switch (oper) {
2949 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002950 rcu_read_lock();
2951 sta = sta_info_get(sdata, peer);
2952 if (!sta) {
2953 rcu_read_unlock();
2954 return -ENOLINK;
2955 }
2956
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002957 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002958 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002959 break;
2960 case NL80211_TDLS_DISABLE_LINK:
2961 return sta_info_destroy_addr(sdata, peer);
2962 case NL80211_TDLS_TEARDOWN:
2963 case NL80211_TDLS_SETUP:
2964 case NL80211_TDLS_DISCOVERY_REQ:
2965 /* We don't support in-driver setup/teardown/discovery */
2966 return -ENOTSUPP;
2967 default:
2968 return -ENOTSUPP;
2969 }
2970
2971 return 0;
2972}
2973
Johannes Berg06500732011-11-04 11:18:16 +01002974static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2975 const u8 *peer, u64 *cookie)
2976{
2977 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2978 struct ieee80211_local *local = sdata->local;
2979 struct ieee80211_qos_hdr *nullfunc;
2980 struct sk_buff *skb;
2981 int size = sizeof(*nullfunc);
2982 __le16 fc;
2983 bool qos;
2984 struct ieee80211_tx_info *info;
2985 struct sta_info *sta;
2986
2987 rcu_read_lock();
2988 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01002989 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01002990 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01002991 rcu_read_unlock();
2992 } else {
2993 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01002994 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01002995 }
Johannes Berg06500732011-11-04 11:18:16 +01002996
2997 if (qos) {
2998 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2999 IEEE80211_STYPE_QOS_NULLFUNC |
3000 IEEE80211_FCTL_FROMDS);
3001 } else {
3002 size -= 2;
3003 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
3004 IEEE80211_STYPE_NULLFUNC |
3005 IEEE80211_FCTL_FROMDS);
3006 }
3007
3008 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
3009 if (!skb)
3010 return -ENOMEM;
3011
3012 skb->dev = dev;
3013
3014 skb_reserve(skb, local->hw.extra_tx_headroom);
3015
3016 nullfunc = (void *) skb_put(skb, size);
3017 nullfunc->frame_control = fc;
3018 nullfunc->duration_id = 0;
3019 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
3020 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
3021 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
3022 nullfunc->seq_ctrl = 0;
3023
3024 info = IEEE80211_SKB_CB(skb);
3025
3026 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
3027 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
3028
3029 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
3030 skb->priority = 7;
3031 if (qos)
3032 nullfunc->qos_ctrl = cpu_to_le16(7);
3033
3034 local_bh_disable();
3035 ieee80211_xmit(sdata, skb);
3036 local_bh_enable();
3037
3038 *cookie = (unsigned long) skb;
3039 return 0;
3040}
3041
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003042static struct ieee80211_channel *
3043ieee80211_cfg_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
3044 enum nl80211_channel_type *type)
3045{
3046 struct ieee80211_local *local = wiphy_priv(wiphy);
3047
3048 *type = local->_oper_channel_type;
3049 return local->oper_channel;
3050}
3051
Johannes Berg6d525632012-04-04 15:05:25 +02003052#ifdef CONFIG_PM
3053static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3054{
3055 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3056}
3057#endif
3058
Jiri Bencf0706e82007-05-05 11:45:53 -07003059struct cfg80211_ops mac80211_config_ops = {
3060 .add_virtual_intf = ieee80211_add_iface,
3061 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003062 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003063 .start_p2p_device = ieee80211_start_p2p_device,
3064 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003065 .add_key = ieee80211_add_key,
3066 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003067 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003068 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003069 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003070 .start_ap = ieee80211_start_ap,
3071 .change_beacon = ieee80211_change_beacon,
3072 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003073 .add_station = ieee80211_add_station,
3074 .del_station = ieee80211_del_station,
3075 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003076 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003077 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003078 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003079#ifdef CONFIG_MAC80211_MESH
3080 .add_mpath = ieee80211_add_mpath,
3081 .del_mpath = ieee80211_del_mpath,
3082 .change_mpath = ieee80211_change_mpath,
3083 .get_mpath = ieee80211_get_mpath,
3084 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003085 .update_mesh_config = ieee80211_update_mesh_config,
3086 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003087 .join_mesh = ieee80211_join_mesh,
3088 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003089#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003090 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003091 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003092 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003093 .suspend = ieee80211_suspend,
3094 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003095 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003096 .sched_scan_start = ieee80211_sched_scan_start,
3097 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003098 .auth = ieee80211_auth,
3099 .assoc = ieee80211_assoc,
3100 .deauth = ieee80211_deauth,
3101 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003102 .join_ibss = ieee80211_join_ibss,
3103 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003104 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003105 .set_tx_power = ieee80211_set_tx_power,
3106 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003107 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003108 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003109 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003110 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003111 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003112 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003113 .remain_on_channel = ieee80211_remain_on_channel,
3114 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003115 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003116 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003117 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003118 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003119 .set_antenna = ieee80211_set_antenna,
3120 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003121 .set_ringparam = ieee80211_set_ringparam,
3122 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003123 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003124 .tdls_oper = ieee80211_tdls_oper,
3125 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003126 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003127 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003128#ifdef CONFIG_PM
3129 .set_wakeup = ieee80211_set_wakeup,
3130#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003131 .get_et_sset_count = ieee80211_get_et_sset_count,
3132 .get_et_stats = ieee80211_get_et_stats,
3133 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003134 .get_channel = ieee80211_cfg_get_channel,
Jiri Bencf0706e82007-05-05 11:45:53 -07003135};