blob: 4a248fc8776634c9c7a94e5a7ad55997de072979 [file] [log] [blame]
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bergf9e10ce2010-12-03 09:20:42 +010023static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
Jiri Bencf0706e822007-05-05 11:45:53 -070027{
28 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010029 struct net_device *dev;
30 struct ieee80211_sub_if_data *sdata;
31 int err;
Jiri Bencf0706e822007-05-05 11:45:53 -070032
Johannes Berg05c914f2008-09-11 00:01:58 +020033 err = ieee80211_if_add(local, name, &dev, 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) {
38 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
39 sdata->u.mntr_flags = *flags;
40 }
41
42 return dev;
Jiri Bencf0706e822007-05-05 11:45:53 -070043}
44
Johannes Berg463d0182009-07-14 00:33:35 +020045static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
Jiri Bencf0706e822007-05-05 11:45:53 -070046{
Johannes Berg463d0182009-07-14 00:33:35 +020047 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
Jiri Bencf0706e822007-05-05 11:45:53 -070048
Johannes Berg75636522008-07-09 14:40:35 +020049 return 0;
Jiri Bencf0706e822007-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
Simon Wunderlichb53be792011-11-18 14:20:44 +0100105static int ieee80211_set_noack_map(struct wiphy *wiphy,
106 struct net_device *dev,
107 u16 noack_map)
108{
109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
110
111 sdata->noack_map = noack_map;
112 return 0;
113}
114
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100115static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200116 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100117 struct key_params *params)
118{
Johannes Berg26a58452010-08-27 12:35:55 +0200119 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100120 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100121 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200122 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100123
Johannes Berg26a58452010-08-27 12:35:55 +0200124 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200125 return -ENETDOWN;
126
Johannes Berg97359d12010-08-10 09:46:38 +0200127 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100128 switch (params->cipher) {
129 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100130 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200131 case WLAN_CIPHER_SUITE_WEP104:
132 if (IS_ERR(sdata->local->wep_tx_tfm))
133 return -EINVAL;
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200134 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100135 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200136 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100137 }
138
Johannes Berg97359d12010-08-10 09:46:38 +0200139 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
140 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100141 if (IS_ERR(key))
142 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100143
Johannes Berge31b8212010-10-05 19:39:30 +0200144 if (pairwise)
145 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
146
Johannes Bergad0e2b52010-06-01 10:19:19 +0200147 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200148
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100149 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700150 if (ieee80211_vif_is_mesh(&sdata->vif))
151 sta = sta_info_get(sdata, mac_addr);
152 else
153 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergbece87a2013-01-11 14:34:25 +0100154 /*
155 * The ASSOC test makes sure the driver is ready to
156 * receive the key. When wpa_supplicant has roamed
157 * using FT, it attempts to set the key before
158 * association has completed, this rejects that attempt
159 * so it will set the key again after assocation.
160 *
161 * TODO: accept the key if we have a station entry and
162 * add it to the device after the station.
163 */
164 if (!sta || !test_sta_flag(sta, WLAN_STA_ASSOC)) {
Johannes Berg3c978872013-03-06 22:53:52 +0100165 ieee80211_key_free_unused(key);
Johannes Berg3b967662008-04-08 17:56:52 +0200166 err = -ENOENT;
167 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100168 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100169 }
170
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300171 err = ieee80211_key_link(key, sdata, sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100172
Johannes Berg3b967662008-04-08 17:56:52 +0200173 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200174 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200175
176 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100177}
178
179static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200180 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100181{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200182 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
183 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100184 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200185 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100186 int ret;
187
Johannes Berg5c0c3642011-05-12 14:31:49 +0200188 mutex_lock(&local->sta_mtx);
189 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200190
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100191 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200192 ret = -ENOENT;
193
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100194 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100195 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200196 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100197
Johannes Berg5c0c3642011-05-12 14:31:49 +0200198 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200199 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200200 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200201 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200202 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200203 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100204
Johannes Berg5c0c3642011-05-12 14:31:49 +0200205 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200206 ret = -ENOENT;
207 goto out_unlock;
208 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100209
Johannes Berg5c0c3642011-05-12 14:31:49 +0200210 __ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100211
Johannes Berg3b967662008-04-08 17:56:52 +0200212 ret = 0;
213 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200214 mutex_unlock(&local->key_mtx);
215 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200216
217 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100218}
219
Johannes Berg62da92f2007-12-19 02:03:31 +0100220static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200221 u8 key_idx, bool pairwise, const u8 *mac_addr,
222 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100223 void (*callback)(void *cookie,
224 struct key_params *params))
225{
Johannes Berg14db74b2008-07-29 13:22:52 +0200226 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100227 struct sta_info *sta = NULL;
228 u8 seq[6] = {0};
229 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200230 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200231 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100232 u32 iv32;
233 u16 iv16;
234 int err = -ENOENT;
235
Johannes Berg14db74b2008-07-29 13:22:52 +0200236 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
237
Johannes Berg3b967662008-04-08 17:56:52 +0200238 rcu_read_lock();
239
Johannes Berg62da92f2007-12-19 02:03:31 +0100240 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100241 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100242 if (!sta)
243 goto out;
244
Johannes Berge31b8212010-10-05 19:39:30 +0200245 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200246 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200247 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200248 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100249 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200250 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100251
252 if (!key)
253 goto out;
254
255 memset(&params, 0, sizeof(params));
256
Johannes Berg97359d12010-08-10 09:46:38 +0200257 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100258
Johannes Berg97359d12010-08-10 09:46:38 +0200259 switch (key->conf.cipher) {
260 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700261 iv32 = key->u.tkip.tx.iv32;
262 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100263
Johannes Berg24487982009-04-23 18:52:52 +0200264 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
265 drv_get_tkip_seq(sdata->local,
266 key->conf.hw_key_idx,
267 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100268
269 seq[0] = iv16 & 0xff;
270 seq[1] = (iv16 >> 8) & 0xff;
271 seq[2] = iv32 & 0xff;
272 seq[3] = (iv32 >> 8) & 0xff;
273 seq[4] = (iv32 >> 16) & 0xff;
274 seq[5] = (iv32 >> 24) & 0xff;
275 params.seq = seq;
276 params.seq_len = 6;
277 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200278 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200279 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
280 seq[0] = pn64;
281 seq[1] = pn64 >> 8;
282 seq[2] = pn64 >> 16;
283 seq[3] = pn64 >> 24;
284 seq[4] = pn64 >> 32;
285 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100286 params.seq = seq;
287 params.seq_len = 6;
288 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200289 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200290 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
291 seq[0] = pn64;
292 seq[1] = pn64 >> 8;
293 seq[2] = pn64 >> 16;
294 seq[3] = pn64 >> 24;
295 seq[4] = pn64 >> 32;
296 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200297 params.seq = seq;
298 params.seq_len = 6;
299 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100300 }
301
302 params.key = key->conf.key;
303 params.key_len = key->conf.keylen;
304
305 callback(cookie, &params);
306 err = 0;
307
308 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200309 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100310 return err;
311}
312
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100313static int ieee80211_config_default_key(struct wiphy *wiphy,
314 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100315 u8 key_idx, bool uni,
316 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100317{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200318 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100319
Johannes Bergf7e01042010-12-09 19:49:02 +0100320 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100321
322 return 0;
323}
324
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200325static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
326 struct net_device *dev,
327 u8 key_idx)
328{
Johannes Berg66c52422010-07-22 13:58:51 +0200329 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200330
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200331 ieee80211_set_default_mgmt_key(sdata, key_idx);
332
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200333 return 0;
334}
335
Felix Fietkau3af63342011-02-27 22:08:01 +0100336static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
337{
338 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
339 struct ieee80211_supported_band *sband;
340 sband = sta->local->hw.wiphy->bands[
341 sta->local->hw.conf.channel->band];
342 rate->legacy = sband->bitrates[idx].bitrate;
343 } else
344 rate->mcs = idx;
345}
346
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800347void sta_set_rate_info_tx(struct sta_info *sta,
348 const struct ieee80211_tx_rate *rate,
349 struct rate_info *rinfo)
350{
351 rinfo->flags = 0;
352 if (rate->flags & IEEE80211_TX_RC_MCS)
353 rinfo->flags |= RATE_INFO_FLAGS_MCS;
354 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
355 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
356 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
357 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
358 rate_idx_to_bitrate(rinfo, sta, rate->idx);
359}
360
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100361static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
362{
Johannes Bergd0709a62008-02-25 16:27:46 +0100363 struct ieee80211_sub_if_data *sdata = sta->sdata;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530364 struct timespec uptime;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100365
Johannes Bergf5ea9122009-08-07 16:17:38 +0200366 sinfo->generation = sdata->local->sta_generation;
367
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100368 sinfo->filled = STATION_INFO_INACTIVE_TIME |
369 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100370 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200371 STATION_INFO_RX_PACKETS |
372 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900373 STATION_INFO_TX_RETRIES |
374 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700375 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100376 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700377 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530378 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200379 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800380 STATION_INFO_STA_FLAGS |
381 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530382
383 do_posix_clock_monotonic_gettime(&uptime);
384 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100385
386 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
387 sinfo->rx_bytes = sta->rx_bytes;
388 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200389 sinfo->rx_packets = sta->rx_packets;
390 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900391 sinfo->tx_retries = sta->tx_retry_count;
392 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700393 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800394 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100395
John W. Linville19deffb2009-12-08 17:10:13 -0500396 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
397 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900398 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Henning Rogge420e7fa2008-12-11 22:04:19 +0100399 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900400 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100401 }
402
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800403 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100404
Felix Fietkau3af63342011-02-27 22:08:01 +0100405 sinfo->rxrate.flags = 0;
406 if (sta->last_rx_rate_flag & RX_FLAG_HT)
407 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
408 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
409 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
410 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
411 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
412 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100413
Johannes Berg902acc72008-02-23 15:17:19 +0100414 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100415#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100416 sinfo->filled |= STATION_INFO_LLID |
417 STATION_INFO_PLID |
418 STATION_INFO_PLINK_STATE;
419
420 sinfo->llid = le16_to_cpu(sta->llid);
421 sinfo->plid = le16_to_cpu(sta->plid);
422 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100423#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100424 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700425
426 sinfo->bss_param.flags = 0;
427 if (sdata->vif.bss_conf.use_cts_prot)
428 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
429 if (sdata->vif.bss_conf.use_short_preamble)
430 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
431 if (sdata->vif.bss_conf.use_short_slot)
432 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
433 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
434 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200435
436 sinfo->sta_flags.set = 0;
437 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
438 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
439 BIT(NL80211_STA_FLAG_WME) |
440 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100441 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
442 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200443 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
444 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
445 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
446 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
447 if (test_sta_flag(sta, WLAN_STA_WME))
448 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
449 if (test_sta_flag(sta, WLAN_STA_MFP))
450 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
451 if (test_sta_flag(sta, WLAN_STA_AUTH))
452 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100453 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
454 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100455}
456
457
458static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
459 int idx, u8 *mac, struct station_info *sinfo)
460{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100461 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100462 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100463 int ret = -ENOENT;
464
465 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100466
Johannes Berg3b53fde82009-11-16 12:00:37 +0100467 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100468 if (sta) {
469 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200470 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100471 sta_set_sinfo(sta, sinfo);
472 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100473
Johannes Bergd0709a62008-02-25 16:27:46 +0100474 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100475
Johannes Bergd0709a62008-02-25 16:27:46 +0100476 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100477}
478
Holger Schurig12897232010-04-19 10:23:57 +0200479static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
480 int idx, struct survey_info *survey)
481{
482 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
483
Holger Schurig12897232010-04-19 10:23:57 +0200484 return drv_get_survey(local, idx, survey);
485}
486
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100487static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100488 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100489{
Johannes Bergabe60632009-11-25 17:46:18 +0100490 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100491 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100492 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100493
Johannes Bergd0709a62008-02-25 16:27:46 +0100494 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100495
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100496 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100497 if (sta) {
498 ret = 0;
499 sta_set_sinfo(sta, sinfo);
500 }
501
502 rcu_read_unlock();
503
504 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100505}
506
Arik Nemtsov02945822011-11-10 11:28:57 +0200507static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100508 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200509{
510 struct sk_buff *new, *old;
511
512 if (!resp || !resp_len)
Johannes Berg88600202012-02-13 15:17:18 +0100513 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200514
Arik Nemtsovf7248282011-11-19 10:51:26 +0200515 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200516
517 new = dev_alloc_skb(resp_len);
518 if (!new)
519 return -ENOMEM;
520
521 memcpy(skb_put(new, resp_len), resp, resp_len);
522
523 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Johannes Berg88600202012-02-13 15:17:18 +0100524 if (old) {
525 /* TODO: use call_rcu() */
526 synchronize_rcu();
Arik Nemtsov02945822011-11-10 11:28:57 +0200527 dev_kfree_skb(old);
Johannes Berg88600202012-02-13 15:17:18 +0100528 }
Arik Nemtsov02945822011-11-10 11:28:57 +0200529
530 return 0;
531}
532
Johannes Berg88600202012-02-13 15:17:18 +0100533static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
534 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100535{
536 struct beacon_data *new, *old;
537 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100538 int size, err;
539 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100540
Johannes Berg40b275b2011-05-13 14:15:49 +0200541 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100542
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100543 /* Need to have a beacon head if we don't have one yet */
544 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100545 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100546
547 /* new or old head? */
548 if (params->head)
549 new_head_len = params->head_len;
550 else
551 new_head_len = old->head_len;
552
553 /* new or old tail? */
554 if (params->tail || !old)
555 /* params->tail_len will be zero for !params->tail */
556 new_tail_len = params->tail_len;
557 else
558 new_tail_len = old->tail_len;
559
560 size = sizeof(*new) + new_head_len + new_tail_len;
561
562 new = kzalloc(size, GFP_KERNEL);
563 if (!new)
564 return -ENOMEM;
565
566 /* start filling the new info now */
567
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100568 /*
569 * pointers go into the block we allocated,
570 * memory is | beacon_data | head | tail |
571 */
572 new->head = ((u8 *) new) + sizeof(*new);
573 new->tail = new->head + new_head_len;
574 new->head_len = new_head_len;
575 new->tail_len = new_tail_len;
576
577 /* copy in head */
578 if (params->head)
579 memcpy(new->head, params->head, new_head_len);
580 else
581 memcpy(new->head, old->head, new_head_len);
582
583 /* copy in optional tail */
584 if (params->tail)
585 memcpy(new->tail, params->tail, new_tail_len);
586 else
587 if (old)
588 memcpy(new->tail, old->tail, new_tail_len);
589
Johannes Berg88600202012-02-13 15:17:18 +0100590 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
591 params->probe_resp_len);
592 if (err < 0)
593 return err;
594 if (err == 0)
595 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100596
Eric Dumazetcf778b02012-01-12 04:41:32 +0000597 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100598
Johannes Berg88600202012-02-13 15:17:18 +0100599 if (old)
600 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100601
Johannes Berg88600202012-02-13 15:17:18 +0100602 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100603}
604
Johannes Berg88600202012-02-13 15:17:18 +0100605static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
606 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100607{
Johannes Berg88600202012-02-13 15:17:18 +0100608 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100609 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100610 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100611 u32 changed = BSS_CHANGED_BEACON_INT |
612 BSS_CHANGED_BEACON_ENABLED |
613 BSS_CHANGED_BEACON |
614 BSS_CHANGED_SSID;
615 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200616
Johannes Berg40b275b2011-05-13 14:15:49 +0200617 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100618 if (old)
619 return -EALREADY;
620
Johannes Berg665c93a2011-11-04 11:18:11 +0100621 /*
622 * Apply control port protocol, this allows us to
623 * not encrypt dynamic WEP control frames.
624 */
625 sdata->control_port_protocol = params->crypto.control_port_ethertype;
626 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
627 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
628 vlan->control_port_protocol =
629 params->crypto.control_port_ethertype;
630 vlan->control_port_no_encrypt =
631 params->crypto.control_port_no_encrypt;
632 }
633
Johannes Berg88600202012-02-13 15:17:18 +0100634 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
635 sdata->vif.bss_conf.dtim_period = params->dtim_period;
636
637 sdata->vif.bss_conf.ssid_len = params->ssid_len;
638 if (params->ssid_len)
639 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
640 params->ssid_len);
641 sdata->vif.bss_conf.hidden_ssid =
642 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
643
644 err = ieee80211_assign_beacon(sdata, &params->beacon);
645 if (err < 0)
646 return err;
647 changed |= err;
648
649 ieee80211_bss_info_change_notify(sdata, changed);
650
Johannes Berg665c93a2011-11-04 11:18:11 +0100651 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100652}
653
Johannes Berg88600202012-02-13 15:17:18 +0100654static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
655 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100656{
Johannes Berg14db74b2008-07-29 13:22:52 +0200657 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100658 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100659 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100660
Johannes Berg14db74b2008-07-29 13:22:52 +0200661 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
662
Johannes Berg40b275b2011-05-13 14:15:49 +0200663 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100664 if (!old)
665 return -ENOENT;
666
Johannes Berg88600202012-02-13 15:17:18 +0100667 err = ieee80211_assign_beacon(sdata, params);
668 if (err < 0)
669 return err;
670 ieee80211_bss_info_change_notify(sdata, err);
671 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100672}
673
Johannes Berg88600202012-02-13 15:17:18 +0100674static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100675{
Johannes Berg14db74b2008-07-29 13:22:52 +0200676 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100677 struct beacon_data *old;
678
Johannes Berg14db74b2008-07-29 13:22:52 +0200679 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
680
Johannes Berg40b275b2011-05-13 14:15:49 +0200681 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100682 if (!old)
683 return -ENOENT;
684
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000685 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100686
687 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100688
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200689 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100690
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200691 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100692}
693
Johannes Berg4fd69312007-12-19 02:03:35 +0100694/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
695struct iapp_layer2_update {
696 u8 da[ETH_ALEN]; /* broadcast */
697 u8 sa[ETH_ALEN]; /* STA addr */
698 __be16 len; /* 6 */
699 u8 dsap; /* 0 */
700 u8 ssap; /* 0 */
701 u8 control;
702 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700703} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100704
705static void ieee80211_send_layer2_update(struct sta_info *sta)
706{
707 struct iapp_layer2_update *msg;
708 struct sk_buff *skb;
709
710 /* Send Level 2 Update Frame to update forwarding tables in layer 2
711 * bridge devices */
712
713 skb = dev_alloc_skb(sizeof(*msg));
714 if (!skb)
715 return;
716 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
717
718 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
719 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
720
721 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200722 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100723 msg->len = htons(6);
724 msg->dsap = 0;
725 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
726 msg->control = 0xaf; /* XID response lsb.1111F101.
727 * F=0 (no poll command; unsolicited frame) */
728 msg->xid_info[0] = 0x81; /* XID format identifier */
729 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
730 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
731
Johannes Bergd0709a62008-02-25 16:27:46 +0100732 skb->dev = sta->sdata->dev;
733 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100734 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400735 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100736}
737
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100738static int sta_apply_parameters(struct ieee80211_local *local,
739 struct sta_info *sta,
740 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100741{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100742 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +0100743 u32 rates;
744 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100745 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100746 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300747 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100748
Johannes Bergae5eb022008-10-14 16:58:37 +0200749 sband = local->hw.wiphy->bands[local->oper_channel->band];
750
Johannes Bergeccb8e82009-05-11 21:57:56 +0300751 mask = params->sta_flags_mask;
752 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100753
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100754 /*
755 * In mesh mode, we can clear AUTHENTICATED flag but must
756 * also make ASSOCIATED follow appropriately for the driver
757 * API. See also below, after AUTHORIZED changes.
758 */
759 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
760 /* cfg80211 should not allow this in non-mesh modes */
761 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
762 return -EINVAL;
763
764 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
765 !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +0100766 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100767 if (ret)
768 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +0100769 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100770 if (ret)
771 return ret;
772 }
773 }
774
Johannes Bergeccb8e82009-05-11 21:57:56 +0300775 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300776 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +0100777 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Berg543d1b92012-01-13 14:17:59 +0100778 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +0100779 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100780 if (ret)
781 return ret;
Johannes Berg4fd69312007-12-19 02:03:35 +0100782 }
783
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100784 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
785 /* cfg80211 should not allow this in non-mesh modes */
786 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
787 return -EINVAL;
788
789 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
790 test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +0100791 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100792 if (ret)
793 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +0100794 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100795 if (ret)
796 return ret;
797 }
798 }
799
800
Johannes Bergeccb8e82009-05-11 21:57:56 +0300801 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300802 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200803 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
804 else
805 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300806 }
807
808 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +0300809 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200810 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +0300811 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200812 } else {
813 clear_sta_flag(sta, WLAN_STA_WME);
814 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +0300815 }
Johannes Bergeccb8e82009-05-11 21:57:56 +0300816 }
817
818 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300819 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200820 set_sta_flag(sta, WLAN_STA_MFP);
821 else
822 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300823 }
Javier Cardonab39c48f2011-04-07 15:08:30 -0700824
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300825 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300826 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200827 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
828 else
829 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300830 }
Johannes Bergeccb8e82009-05-11 21:57:56 +0300831
Johannes Berg3b9ce802011-09-27 20:56:12 +0200832 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
833 sta->sta.uapsd_queues = params->uapsd_queues;
834 sta->sta.max_sp = params->max_sp;
835 }
Eliad Peller9533b4a2011-08-23 14:37:47 +0300836
Johannes Berg73651ee2008-02-25 16:27:47 +0100837 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200838 * cfg80211 validates this (1-2007) and allows setting the AID
839 * only when creating a new station entry
840 */
841 if (params->aid)
842 sta->sta.aid = params->aid;
843
844 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100845 * FIXME: updating the following information is racy when this
846 * function is called from ieee80211_change_station().
847 * However, all this information should be static so
848 * maybe we should just reject attemps to change it.
849 */
850
Johannes Berg4fd69312007-12-19 02:03:35 +0100851 if (params->listen_interval >= 0)
852 sta->listen_interval = params->listen_interval;
853
854 if (params->supported_rates) {
855 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100856
Johannes Berg4fd69312007-12-19 02:03:35 +0100857 for (i = 0; i < params->supported_rates_len; i++) {
858 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100859 for (j = 0; j < sband->n_bitrates; j++) {
860 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100861 rates |= BIT(j);
862 }
863 }
Johannes Berg323ce792008-09-11 02:45:11 +0200864 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100865 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100866
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200867 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -0800868 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +0200869 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200870 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300871
Javier Cardona9c3990a2011-05-03 16:57:11 -0700872 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -0400873#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -0700874 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
875 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700876 case NL80211_PLINK_LISTEN:
877 case NL80211_PLINK_ESTAB:
878 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -0700879 sta->plink_state = params->plink_state;
880 break;
881 default:
882 /* nothing */
883 break;
884 }
885 else
886 switch (params->plink_action) {
887 case PLINK_ACTION_OPEN:
888 mesh_plink_open(sta);
889 break;
890 case PLINK_ACTION_BLOCK:
891 mesh_plink_block(sta);
892 break;
893 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -0400894#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100895 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100896
897 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +0100898}
899
900static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
901 u8 *mac, struct station_parameters *params)
902{
Johannes Berg14db74b2008-07-29 13:22:52 +0200903 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100904 struct sta_info *sta;
905 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100906 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200907 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100908
Johannes Berg4fd69312007-12-19 02:03:35 +0100909 if (params->vlan) {
910 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
911
Johannes Berg05c914f2008-09-11 00:01:58 +0200912 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
913 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100914 return -EINVAL;
915 } else
916 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
917
Johannes Berg47846c92009-11-25 17:46:19 +0100918 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100919 return -EINVAL;
920
921 if (is_multicast_ether_addr(mac))
922 return -EINVAL;
923
924 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100925 if (!sta)
926 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100927
Johannes Berg83d5cc02012-01-12 09:31:10 +0100928 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
929 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +0100930
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100931 err = sta_apply_parameters(local, sta, params);
932 if (err) {
933 sta_info_free(local, sta);
934 return err;
935 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100936
Arik Nemtsovd64cf632011-11-07 23:24:39 +0200937 /*
938 * for TDLS, rate control should be initialized only when supported
939 * rates are known.
940 */
941 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
942 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100943
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200944 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
945 sdata->vif.type == NL80211_IFTYPE_AP;
946
Johannes Berg34e89502010-02-03 13:59:58 +0100947 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100948 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100949 rcu_read_unlock();
950 return err;
951 }
952
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200953 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100954 ieee80211_send_layer2_update(sta);
955
956 rcu_read_unlock();
957
Johannes Berg4fd69312007-12-19 02:03:35 +0100958 return 0;
959}
960
961static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
962 u8 *mac)
963{
Johannes Berg14db74b2008-07-29 13:22:52 +0200964 struct ieee80211_local *local = wiphy_priv(wiphy);
965 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100966
Johannes Berg14db74b2008-07-29 13:22:52 +0200967 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
968
Johannes Berg34e89502010-02-03 13:59:58 +0100969 if (mac)
970 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200971
Johannes Berg34e89502010-02-03 13:59:58 +0100972 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100973 return 0;
974}
975
976static int ieee80211_change_station(struct wiphy *wiphy,
977 struct net_device *dev,
978 u8 *mac,
979 struct station_parameters *params)
980{
Johannes Bergabe60632009-11-25 17:46:18 +0100981 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200982 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100983 struct sta_info *sta;
984 struct ieee80211_sub_if_data *vlansdata;
Eliad Peller35b88622011-12-29 14:41:39 +0200985 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +0100986
Johannes Berg87be1e12011-12-14 12:20:29 +0100987 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200988
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100989 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200990 if (!sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +0100991 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +0100992 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200993 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100994
Jouni Malinen95fcfd02013-02-14 19:10:54 +0000995 /* in station mode, some updates are only valid with TDLS */
Johannes Bergbdd90d52011-12-14 12:20:27 +0100996 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Jouni Malinen95fcfd02013-02-14 19:10:54 +0000997 (params->supported_rates || params->ht_capa || params->vht_capa ||
998 params->sta_modify_mask ||
999 (params->sta_flags_mask & BIT(NL80211_STA_FLAG_WME))) &&
Johannes Bergbdd90d52011-12-14 12:20:27 +01001000 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001001 mutex_unlock(&local->sta_mtx);
Johannes Bergbdd90d52011-12-14 12:20:27 +01001002 return -EINVAL;
1003 }
1004
Johannes Bergd0709a62008-02-25 16:27:46 +01001005 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +01001006 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1007
Johannes Berg05c914f2008-09-11 00:01:58 +02001008 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1009 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001010 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001011 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001012 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001013
Johannes Berg9bc383d2009-11-19 11:55:19 +01001014 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001015 if (vlansdata->u.vlan.sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001016 mutex_unlock(&local->sta_mtx);
Felix Fietkauf14543e2009-11-10 20:10:05 +01001017 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +01001018 }
Felix Fietkauf14543e2009-11-10 20:10:05 +01001019
Eric Dumazetcf778b02012-01-12 04:41:32 +00001020 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkauf14543e2009-11-10 20:10:05 +01001021 }
1022
Johannes Berg14db74b2008-07-29 13:22:52 +02001023 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001024 ieee80211_send_layer2_update(sta);
1025 }
1026
Eliad Peller35b88622011-12-29 14:41:39 +02001027 err = sta_apply_parameters(local, sta, params);
1028 if (err) {
1029 mutex_unlock(&local->sta_mtx);
1030 return err;
1031 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001032
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001033 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1034 rate_control_rate_init(sta);
1035
Johannes Berg87be1e12011-12-14 12:20:29 +01001036 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001037
Jason Young808118c2011-03-10 16:43:19 -08001038 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1039 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1040 ieee80211_recalc_ps(local, -1);
1041
Johannes Berg4fd69312007-12-19 02:03:35 +01001042 return 0;
1043}
1044
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001045#ifdef CONFIG_MAC80211_MESH
1046static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1047 u8 *dst, u8 *next_hop)
1048{
Johannes Berg14db74b2008-07-29 13:22:52 +02001049 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001050 struct mesh_path *mpath;
1051 struct sta_info *sta;
1052 int err;
1053
Johannes Berg14db74b2008-07-29 13:22:52 +02001054 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1055
Johannes Bergd0709a62008-02-25 16:27:46 +01001056 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001057 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001058 if (!sta) {
1059 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001060 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001061 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001062
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001063 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +01001064 if (err) {
1065 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001066 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001067 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001068
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001069 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001070 if (!mpath) {
1071 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001072 return -ENXIO;
1073 }
1074 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001075
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001076 rcu_read_unlock();
1077 return 0;
1078}
1079
1080static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1081 u8 *dst)
1082{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001083 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001084
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001085 if (dst)
1086 return mesh_path_del(dst, sdata);
1087
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001088 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001089 return 0;
1090}
1091
1092static int ieee80211_change_mpath(struct wiphy *wiphy,
1093 struct net_device *dev,
1094 u8 *dst, u8 *next_hop)
1095{
Johannes Berg14db74b2008-07-29 13:22:52 +02001096 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001097 struct mesh_path *mpath;
1098 struct sta_info *sta;
1099
Johannes Berg14db74b2008-07-29 13:22:52 +02001100 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1101
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001102 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001103
Johannes Bergabe60632009-11-25 17:46:18 +01001104 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001105 if (!sta) {
1106 rcu_read_unlock();
1107 return -ENOENT;
1108 }
1109
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001110 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001111 if (!mpath) {
1112 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001113 return -ENOENT;
1114 }
1115
1116 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001117
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001118 rcu_read_unlock();
1119 return 0;
1120}
1121
1122static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1123 struct mpath_info *pinfo)
1124{
Johannes Berga3836e02011-05-12 15:11:37 +02001125 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1126
1127 if (next_hop_sta)
1128 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001129 else
1130 memset(next_hop, 0, ETH_ALEN);
1131
Johannes Bergf5ea9122009-08-07 16:17:38 +02001132 pinfo->generation = mesh_paths_generation;
1133
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001134 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001135 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001136 MPATH_INFO_METRIC |
1137 MPATH_INFO_EXPTIME |
1138 MPATH_INFO_DISCOVERY_TIMEOUT |
1139 MPATH_INFO_DISCOVERY_RETRIES |
1140 MPATH_INFO_FLAGS;
1141
1142 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001143 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001144 pinfo->metric = mpath->metric;
1145 if (time_before(jiffies, mpath->exp_time))
1146 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1147 pinfo->discovery_timeout =
1148 jiffies_to_msecs(mpath->discovery_timeout);
1149 pinfo->discovery_retries = mpath->discovery_retries;
1150 pinfo->flags = 0;
1151 if (mpath->flags & MESH_PATH_ACTIVE)
1152 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1153 if (mpath->flags & MESH_PATH_RESOLVING)
1154 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001155 if (mpath->flags & MESH_PATH_SN_VALID)
1156 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001157 if (mpath->flags & MESH_PATH_FIXED)
1158 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1159 if (mpath->flags & MESH_PATH_RESOLVING)
1160 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1161
1162 pinfo->flags = mpath->flags;
1163}
1164
1165static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1166 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1167
1168{
Johannes Berg14db74b2008-07-29 13:22:52 +02001169 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001170 struct mesh_path *mpath;
1171
Johannes Berg14db74b2008-07-29 13:22:52 +02001172 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1173
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001174 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001175 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001176 if (!mpath) {
1177 rcu_read_unlock();
1178 return -ENOENT;
1179 }
1180 memcpy(dst, mpath->dst, ETH_ALEN);
1181 mpath_set_pinfo(mpath, next_hop, pinfo);
1182 rcu_read_unlock();
1183 return 0;
1184}
1185
1186static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1187 int idx, u8 *dst, u8 *next_hop,
1188 struct mpath_info *pinfo)
1189{
Johannes Berg14db74b2008-07-29 13:22:52 +02001190 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001191 struct mesh_path *mpath;
1192
Johannes Berg14db74b2008-07-29 13:22:52 +02001193 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1194
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001195 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001196 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001197 if (!mpath) {
1198 rcu_read_unlock();
1199 return -ENOENT;
1200 }
1201 memcpy(dst, mpath->dst, ETH_ALEN);
1202 mpath_set_pinfo(mpath, next_hop, pinfo);
1203 rcu_read_unlock();
1204 return 0;
1205}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001206
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001207static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001208 struct net_device *dev,
1209 struct mesh_config *conf)
1210{
1211 struct ieee80211_sub_if_data *sdata;
1212 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1213
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001214 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1215 return 0;
1216}
1217
1218static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1219{
1220 return (mask >> (parm-1)) & 0x1;
1221}
1222
Javier Cardonac80d5452010-12-16 17:37:49 -08001223static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1224 const struct mesh_setup *setup)
1225{
1226 u8 *new_ie;
1227 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001228 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1229 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001230
Javier Cardona581a8b02011-04-07 15:08:27 -07001231 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001232 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001233 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001234
Javier Cardona581a8b02011-04-07 15:08:27 -07001235 if (setup->ie_len) {
1236 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001237 GFP_KERNEL);
1238 if (!new_ie)
1239 return -ENOMEM;
1240 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001241 ifmsh->ie_len = setup->ie_len;
1242 ifmsh->ie = new_ie;
1243 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001244
1245 /* now copy the rest of the setup parameters */
1246 ifmsh->mesh_id_len = setup->mesh_id_len;
1247 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1248 ifmsh->mesh_pp_id = setup->path_sel_proto;
1249 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001250 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1251 if (setup->is_authenticated)
1252 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1253 if (setup->is_secure)
1254 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001255
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001256 /* mcast rate setting in Mesh Node */
1257 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1258 sizeof(setup->mcast_rate));
1259
Javier Cardonac80d5452010-12-16 17:37:49 -08001260 return 0;
1261}
1262
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001263static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001264 struct net_device *dev, u32 mask,
1265 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001266{
1267 struct mesh_config *conf;
1268 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001269 struct ieee80211_if_mesh *ifmsh;
1270
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001271 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001272 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001273
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001274 /* Set the config options which we are interested in setting */
1275 conf = &(sdata->u.mesh.mshcfg);
1276 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1277 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1278 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1279 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1280 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1281 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1282 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1283 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1284 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1285 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1286 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1287 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001288 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1289 conf->dot11MeshTTL = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001290 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1291 conf->auto_open_plinks = nconf->auto_open_plinks;
1292 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1293 conf->dot11MeshHWMPmaxPREQretries =
1294 nconf->dot11MeshHWMPmaxPREQretries;
1295 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1296 conf->path_refresh_time = nconf->path_refresh_time;
1297 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1298 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1299 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1300 conf->dot11MeshHWMPactivePathTimeout =
1301 nconf->dot11MeshHWMPactivePathTimeout;
1302 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1303 conf->dot11MeshHWMPpreqMinInterval =
1304 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001305 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1306 conf->dot11MeshHWMPperrMinInterval =
1307 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001308 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1309 mask))
1310 conf->dot11MeshHWMPnetDiameterTraversalTime =
1311 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001312 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1313 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1314 ieee80211_mesh_root_setup(ifmsh);
1315 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001316 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc6133662011-08-25 10:36:14 -07001317 /* our current gate announcement implementation rides on root
1318 * announcements, so require this ifmsh to also be a root node
1319 * */
1320 if (nconf->dot11MeshGateAnnouncementProtocol &&
1321 !conf->dot11MeshHWMPRootMode) {
1322 conf->dot11MeshHWMPRootMode = 1;
1323 ieee80211_mesh_root_setup(ifmsh);
1324 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001325 conf->dot11MeshGateAnnouncementProtocol =
1326 nconf->dot11MeshGateAnnouncementProtocol;
1327 }
Javier Cardona0507e152011-08-09 16:45:10 -07001328 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1329 conf->dot11MeshHWMPRannInterval =
1330 nconf->dot11MeshHWMPRannInterval;
1331 }
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001332 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1333 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001334 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1335 /* our RSSI threshold implementation is supported only for
1336 * devices that report signal in dBm.
1337 */
1338 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1339 return -ENOTSUPP;
1340 conf->rssi_threshold = nconf->rssi_threshold;
1341 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001342 return 0;
1343}
1344
Johannes Berg29cbe682010-12-03 09:20:44 +01001345static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1346 const struct mesh_config *conf,
1347 const struct mesh_setup *setup)
1348{
1349 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1350 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001351 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001352
Javier Cardonac80d5452010-12-16 17:37:49 -08001353 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1354 err = copy_mesh_setup(ifmsh, setup);
1355 if (err)
1356 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001357 ieee80211_start_mesh(sdata);
1358
1359 return 0;
1360}
1361
1362static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1363{
1364 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1365
1366 ieee80211_stop_mesh(sdata);
1367
1368 return 0;
1369}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001370#endif
1371
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001372static int ieee80211_change_bss(struct wiphy *wiphy,
1373 struct net_device *dev,
1374 struct bss_parameters *params)
1375{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001376 struct ieee80211_sub_if_data *sdata;
1377 u32 changed = 0;
1378
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001379 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1380
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001381 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001382 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001383 changed |= BSS_CHANGED_ERP_CTS_PROT;
1384 }
1385 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001386 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001387 params->use_short_preamble;
1388 changed |= BSS_CHANGED_ERP_PREAMBLE;
1389 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001390
1391 if (!sdata->vif.bss_conf.use_short_slot &&
1392 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1393 sdata->vif.bss_conf.use_short_slot = true;
1394 changed |= BSS_CHANGED_ERP_SLOT;
1395 }
1396
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001397 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001398 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001399 params->use_short_slot_time;
1400 changed |= BSS_CHANGED_ERP_SLOT;
1401 }
1402
Jouni Malinen90c97a02008-10-30 16:59:22 +02001403 if (params->basic_rates) {
1404 int i, j;
1405 u32 rates = 0;
1406 struct ieee80211_local *local = wiphy_priv(wiphy);
1407 struct ieee80211_supported_band *sband =
1408 wiphy->bands[local->oper_channel->band];
1409
1410 for (i = 0; i < params->basic_rates_len; i++) {
1411 int rate = (params->basic_rates[i] & 0x7f) * 5;
1412 for (j = 0; j < sband->n_bitrates; j++) {
1413 if (sband->bitrates[j].bitrate == rate)
1414 rates |= BIT(j);
1415 }
1416 }
1417 sdata->vif.bss_conf.basic_rates = rates;
1418 changed |= BSS_CHANGED_BASIC_RATES;
1419 }
1420
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001421 if (params->ap_isolate >= 0) {
1422 if (params->ap_isolate)
1423 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1424 else
1425 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1426 }
1427
Helmut Schaa80d7e402010-11-19 12:40:26 +01001428 if (params->ht_opmode >= 0) {
1429 sdata->vif.bss_conf.ht_operation_mode =
1430 (u16) params->ht_opmode;
1431 changed |= BSS_CHANGED_HT;
1432 }
1433
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001434 ieee80211_bss_info_change_notify(sdata, changed);
1435
1436 return 0;
1437}
1438
Jouni Malinen31888482008-10-30 16:59:24 +02001439static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001440 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001441 struct ieee80211_txq_params *params)
1442{
1443 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001444 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001445 struct ieee80211_tx_queue_params p;
1446
1447 if (!local->ops->conf_tx)
1448 return -EOPNOTSUPP;
1449
1450 memset(&p, 0, sizeof(p));
1451 p.aifs = params->aifs;
1452 p.cw_max = params->cwmax;
1453 p.cw_min = params->cwmin;
1454 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001455
1456 /*
1457 * Setting tx queue params disables u-apsd because it's only
1458 * called in master mode.
1459 */
1460 p.uapsd = false;
1461
Eliad Peller2683d652011-07-14 20:29:42 +03001462 if (params->queue >= local->hw.queues)
1463 return -EINVAL;
1464
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001465 sdata->tx_conf[params->queue] = p;
1466 if (drv_conf_tx(local, sdata, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001467 wiphy_debug(local->hw.wiphy,
1468 "failed to set TX queue parameters for queue %d\n",
1469 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001470 return -EINVAL;
1471 }
1472
1473 return 0;
1474}
1475
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001476static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001477 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001478 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301479 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001480{
1481 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001482 struct ieee80211_sub_if_data *sdata = NULL;
Ben Greeareeabee72011-01-28 10:20:47 -08001483 struct ieee80211_channel *old_oper;
1484 enum nl80211_channel_type old_oper_type;
1485 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001486
1487 if (netdev)
1488 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001489
Johannes Bergf444de02010-05-05 15:25:02 +02001490 switch (ieee80211_get_channel_mode(local, NULL)) {
1491 case CHAN_MODE_HOPPING:
1492 return -EBUSY;
1493 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001494 if (local->oper_channel != chan)
1495 return -EBUSY;
1496 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001497 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001498 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001499 case CHAN_MODE_UNDEFINED:
1500 break;
1501 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001502
Ben Greeareeabee72011-01-28 10:20:47 -08001503 if (sdata)
1504 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1505 old_oper_type = local->_oper_channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001506
Johannes Berg0aaffa92010-05-05 15:28:27 +02001507 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1508 return -EBUSY;
1509
Ben Greeareeabee72011-01-28 10:20:47 -08001510 old_oper = local->oper_channel;
1511 local->oper_channel = chan;
1512
1513 /* Update driver if changes were actually made. */
1514 if ((old_oper != local->oper_channel) ||
1515 (old_oper_type != local->_oper_channel_type))
1516 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1517
Johannes Bergef5af742011-10-18 13:39:14 +02001518 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
Ben Greeareeabee72011-01-28 10:20:47 -08001519 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
Johannes Berg0aaffa92010-05-05 15:28:27 +02001520 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1521
1522 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001523}
1524
Bob Copeland665af4f2009-01-19 11:20:53 -05001525#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001526static int ieee80211_suspend(struct wiphy *wiphy,
1527 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001528{
Johannes Bergeecc4802011-05-04 15:37:29 +02001529 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001530}
1531
1532static int ieee80211_resume(struct wiphy *wiphy)
1533{
1534 return __ieee80211_resume(wiphy_priv(wiphy));
1535}
1536#else
1537#define ieee80211_suspend NULL
1538#define ieee80211_resume NULL
1539#endif
1540
Johannes Berg2a519312009-02-10 21:25:55 +01001541static int ieee80211_scan(struct wiphy *wiphy,
1542 struct net_device *dev,
1543 struct cfg80211_scan_request *req)
1544{
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001545 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg2a519312009-02-10 21:25:55 +01001546
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001547 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1548 case NL80211_IFTYPE_STATION:
1549 case NL80211_IFTYPE_ADHOC:
1550 case NL80211_IFTYPE_MESH_POINT:
1551 case NL80211_IFTYPE_P2P_CLIENT:
1552 break;
1553 case NL80211_IFTYPE_P2P_GO:
1554 if (sdata->local->ops->hw_scan)
1555 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001556 /*
1557 * FIXME: implement NoA while scanning in software,
1558 * for now fall through to allow scanning only when
1559 * beaconing hasn't been configured yet
1560 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001561 case NL80211_IFTYPE_AP:
1562 if (sdata->u.ap.beacon)
1563 return -EOPNOTSUPP;
1564 break;
1565 default:
1566 return -EOPNOTSUPP;
1567 }
Johannes Berg2a519312009-02-10 21:25:55 +01001568
1569 return ieee80211_request_scan(sdata, req);
1570}
1571
Luciano Coelho79f460c2011-05-11 17:09:36 +03001572static int
1573ieee80211_sched_scan_start(struct wiphy *wiphy,
1574 struct net_device *dev,
1575 struct cfg80211_sched_scan_request *req)
1576{
1577 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1578
1579 if (!sdata->local->ops->sched_scan_start)
1580 return -EOPNOTSUPP;
1581
1582 return ieee80211_request_sched_scan_start(sdata, req);
1583}
1584
1585static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001586ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001587{
1588 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1589
1590 if (!sdata->local->ops->sched_scan_stop)
1591 return -EOPNOTSUPP;
1592
Luciano Coelho85a99942011-05-12 16:28:29 +03001593 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001594}
1595
Jouni Malinen636a5d32009-03-19 13:39:22 +02001596static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1597 struct cfg80211_auth_request *req)
1598{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001599 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001600}
1601
1602static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1603 struct cfg80211_assoc_request *req)
1604{
Johannes Bergf444de02010-05-05 15:25:02 +02001605 struct ieee80211_local *local = wiphy_priv(wiphy);
1606 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1607
1608 switch (ieee80211_get_channel_mode(local, sdata)) {
1609 case CHAN_MODE_HOPPING:
1610 return -EBUSY;
1611 case CHAN_MODE_FIXED:
1612 if (local->oper_channel == req->bss->channel)
1613 break;
1614 return -EBUSY;
1615 case CHAN_MODE_UNDEFINED:
1616 break;
1617 }
1618
Johannes Berg77fdaa12009-07-07 03:45:17 +02001619 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001620}
1621
1622static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001623 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001624{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001625 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001626}
1627
1628static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001629 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001630{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001631 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001632}
1633
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001634static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1635 struct cfg80211_ibss_params *params)
1636{
Johannes Bergf444de02010-05-05 15:25:02 +02001637 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001638 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1639
Johannes Bergf444de02010-05-05 15:25:02 +02001640 switch (ieee80211_get_channel_mode(local, sdata)) {
1641 case CHAN_MODE_HOPPING:
1642 return -EBUSY;
1643 case CHAN_MODE_FIXED:
1644 if (!params->channel_fixed)
1645 return -EBUSY;
1646 if (local->oper_channel == params->channel)
1647 break;
1648 return -EBUSY;
1649 case CHAN_MODE_UNDEFINED:
1650 break;
1651 }
1652
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001653 return ieee80211_ibss_join(sdata, params);
1654}
1655
1656static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1657{
1658 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1659
1660 return ieee80211_ibss_leave(sdata);
1661}
1662
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001663static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1664{
1665 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001666 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001667
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001668 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1669 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1670
1671 if (err)
1672 return err;
1673 }
1674
Lukáš Turek310bc672009-12-21 22:50:48 +01001675 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1676 err = drv_set_coverage_class(local, wiphy->coverage_class);
1677
1678 if (err)
1679 return err;
1680 }
1681
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001682 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001683 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001684
Johannes Berg24487982009-04-23 18:52:52 +02001685 if (err)
1686 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001687 }
1688
1689 if (changed & WIPHY_PARAM_RETRY_SHORT)
1690 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1691 if (changed & WIPHY_PARAM_RETRY_LONG)
1692 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1693 if (changed &
1694 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1695 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1696
1697 return 0;
1698}
1699
Johannes Berg7643a2c2009-06-02 13:01:39 +02001700static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001701 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001702{
1703 struct ieee80211_local *local = wiphy_priv(wiphy);
1704 struct ieee80211_channel *chan = local->hw.conf.channel;
1705 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001706
1707 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001708 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001709 local->user_power_level = -1;
1710 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001711 case NL80211_TX_POWER_LIMITED:
1712 if (mbm < 0 || (mbm % 100))
1713 return -EOPNOTSUPP;
1714 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001715 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001716 case NL80211_TX_POWER_FIXED:
1717 if (mbm < 0 || (mbm % 100))
1718 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001719 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001720 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001721 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001722 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001723 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001724 }
1725
1726 ieee80211_hw_config(local, changes);
1727
1728 return 0;
1729}
1730
1731static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1732{
1733 struct ieee80211_local *local = wiphy_priv(wiphy);
1734
1735 *dbm = local->hw.conf.power_level;
1736
Johannes Berg7643a2c2009-06-02 13:01:39 +02001737 return 0;
1738}
1739
Johannes Bergab737a42009-07-01 21:26:58 +02001740static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02001741 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02001742{
1743 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1744
1745 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1746
1747 return 0;
1748}
1749
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001750static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1751{
1752 struct ieee80211_local *local = wiphy_priv(wiphy);
1753
1754 drv_rfkill_poll(local);
1755}
1756
Johannes Bergaff89a92009-07-01 21:26:51 +02001757#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001758static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001759{
1760 struct ieee80211_local *local = wiphy_priv(wiphy);
1761
1762 if (!local->ops->testmode_cmd)
1763 return -EOPNOTSUPP;
1764
1765 return local->ops->testmode_cmd(&local->hw, data, len);
1766}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07001767
1768static int ieee80211_testmode_dump(struct wiphy *wiphy,
1769 struct sk_buff *skb,
1770 struct netlink_callback *cb,
1771 void *data, int len)
1772{
1773 struct ieee80211_local *local = wiphy_priv(wiphy);
1774
1775 if (!local->ops->testmode_dump)
1776 return -EOPNOTSUPP;
1777
1778 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1779}
Johannes Bergaff89a92009-07-01 21:26:51 +02001780#endif
1781
Johannes Berg0f782312009-12-01 13:37:02 +01001782int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1783 enum ieee80211_smps_mode smps_mode)
1784{
1785 const u8 *ap;
1786 enum ieee80211_smps_mode old_req;
1787 int err;
1788
Johannes Berg243e6df2011-04-19 20:44:04 +02001789 lockdep_assert_held(&sdata->u.mgd.mtx);
1790
Johannes Berg0f782312009-12-01 13:37:02 +01001791 old_req = sdata->u.mgd.req_smps;
1792 sdata->u.mgd.req_smps = smps_mode;
1793
1794 if (old_req == smps_mode &&
1795 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1796 return 0;
1797
1798 /*
1799 * If not associated, or current association is not an HT
1800 * association, there's no need to send an action frame.
1801 */
1802 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001803 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001804 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02001805 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01001806 mutex_unlock(&sdata->local->iflist_mtx);
1807 return 0;
1808 }
1809
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001810 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001811
1812 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1813 if (sdata->u.mgd.powersave)
1814 smps_mode = IEEE80211_SMPS_DYNAMIC;
1815 else
1816 smps_mode = IEEE80211_SMPS_OFF;
1817 }
1818
1819 /* send SM PS frame to AP */
1820 err = ieee80211_send_smps_action(sdata, smps_mode,
1821 ap, ap);
1822 if (err)
1823 sdata->u.mgd.req_smps = old_req;
1824
1825 return err;
1826}
1827
Johannes Bergbc92afd2009-07-01 21:26:57 +02001828static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1829 bool enabled, int timeout)
1830{
1831 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1832 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001833
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001834 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1835 return -EOPNOTSUPP;
1836
Johannes Bergbc92afd2009-07-01 21:26:57 +02001837 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1838 return -EOPNOTSUPP;
1839
1840 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001841 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001842 return 0;
1843
1844 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001845 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001846
Johannes Berg0f782312009-12-01 13:37:02 +01001847 /* no change, but if automatic follow powersave */
1848 mutex_lock(&sdata->u.mgd.mtx);
1849 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1850 mutex_unlock(&sdata->u.mgd.mtx);
1851
Johannes Bergbc92afd2009-07-01 21:26:57 +02001852 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1853 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1854
1855 ieee80211_recalc_ps(local, -1);
1856
1857 return 0;
1858}
1859
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001860static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1861 struct net_device *dev,
1862 s32 rssi_thold, u32 rssi_hyst)
1863{
1864 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001865 struct ieee80211_vif *vif = &sdata->vif;
1866 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1867
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001868 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1869 rssi_hyst == bss_conf->cqm_rssi_hyst)
1870 return 0;
1871
1872 bss_conf->cqm_rssi_thold = rssi_thold;
1873 bss_conf->cqm_rssi_hyst = rssi_hyst;
1874
1875 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01001876 if (sdata->u.mgd.associated &&
1877 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001878 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1879
1880 return 0;
1881}
1882
Johannes Berg99303802009-07-01 21:26:59 +02001883static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1884 struct net_device *dev,
1885 const u8 *addr,
1886 const struct cfg80211_bitrate_mask *mask)
1887{
1888 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1889 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05301890 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02001891
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05301892 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1893 ret = drv_set_bitrate_mask(local, sdata, mask);
1894 if (ret)
1895 return ret;
1896 }
Johannes Berg99303802009-07-01 21:26:59 +02001897
Simon Wunderlich19468412012-01-28 17:25:33 +01001898 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001899 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01001900 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
1901 sizeof(mask->control[i].mcs));
1902 }
Johannes Berg99303802009-07-01 21:26:59 +02001903
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001904 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001905}
1906
Johannes Berg21f83582010-12-18 17:20:47 +01001907static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
1908 struct net_device *dev,
1909 struct ieee80211_channel *chan,
1910 enum nl80211_channel_type chantype,
1911 unsigned int duration, u64 *cookie)
1912{
1913 int ret;
1914 u32 random_cookie;
1915
1916 lockdep_assert_held(&local->mtx);
1917
1918 if (local->hw_roc_cookie)
1919 return -EBUSY;
1920 /* must be nonzero */
1921 random_cookie = random32() | 1;
1922
1923 *cookie = random_cookie;
1924 local->hw_roc_dev = dev;
1925 local->hw_roc_cookie = random_cookie;
1926 local->hw_roc_channel = chan;
1927 local->hw_roc_channel_type = chantype;
1928 local->hw_roc_duration = duration;
1929 ret = drv_remain_on_channel(local, chan, chantype, duration);
1930 if (ret) {
1931 local->hw_roc_channel = NULL;
1932 local->hw_roc_cookie = 0;
1933 }
1934
1935 return ret;
1936}
1937
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001938static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1939 struct net_device *dev,
1940 struct ieee80211_channel *chan,
1941 enum nl80211_channel_type channel_type,
1942 unsigned int duration,
1943 u64 *cookie)
1944{
1945 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg21f83582010-12-18 17:20:47 +01001946 struct ieee80211_local *local = sdata->local;
1947
1948 if (local->ops->remain_on_channel) {
1949 int ret;
1950
1951 mutex_lock(&local->mtx);
1952 ret = ieee80211_remain_on_channel_hw(local, dev,
1953 chan, channel_type,
1954 duration, cookie);
Johannes Berg90fc4b32010-12-18 17:20:48 +01001955 local->hw_roc_for_tx = false;
Johannes Berg21f83582010-12-18 17:20:47 +01001956 mutex_unlock(&local->mtx);
1957
1958 return ret;
1959 }
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001960
1961 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1962 duration, cookie);
1963}
1964
Johannes Berg21f83582010-12-18 17:20:47 +01001965static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1966 u64 cookie)
1967{
1968 int ret;
1969
1970 lockdep_assert_held(&local->mtx);
1971
1972 if (local->hw_roc_cookie != cookie)
1973 return -ENOENT;
1974
1975 ret = drv_cancel_remain_on_channel(local);
1976 if (ret)
1977 return ret;
1978
1979 local->hw_roc_cookie = 0;
1980 local->hw_roc_channel = NULL;
1981
1982 ieee80211_recalc_idle(local);
1983
1984 return 0;
1985}
1986
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001987static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1988 struct net_device *dev,
1989 u64 cookie)
1990{
1991 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg21f83582010-12-18 17:20:47 +01001992 struct ieee80211_local *local = sdata->local;
1993
1994 if (local->ops->cancel_remain_on_channel) {
1995 int ret;
1996
1997 mutex_lock(&local->mtx);
1998 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
1999 mutex_unlock(&local->mtx);
2000
2001 return ret;
2002 }
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002003
2004 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
2005}
2006
Johannes Bergf30221e2010-11-25 10:02:30 +01002007static enum work_done_result
2008ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
2009{
2010 /*
2011 * Use the data embedded in the work struct for reporting
2012 * here so if the driver mangled the SKB before dropping
2013 * it (which is the only way we really should get here)
2014 * then we don't report mangled data.
2015 *
2016 * If there was no wait time, then by the time we get here
2017 * the driver will likely not have reported the status yet,
2018 * so in that case userspace will have to deal with it.
2019 */
2020
Johannes Berg28a1bcd2011-10-04 18:27:10 +02002021 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
Johannes Bergf30221e2010-11-25 10:02:30 +01002022 cfg80211_mgmt_tx_status(wk->sdata->dev,
2023 (unsigned long) wk->offchan_tx.frame,
Johannes Berg66e67e42012-01-20 13:55:27 +01002024 wk->data, wk->data_len, false, GFP_KERNEL);
Johannes Bergf30221e2010-11-25 10:02:30 +01002025
2026 return WORK_DONE_DESTROY;
2027}
2028
Johannes Berg2e161f72010-08-12 15:38:38 +02002029static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002030 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f72010-08-12 15:38:38 +02002031 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002032 bool channel_type_valid, unsigned int wait,
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05302033 const u8 *buf, size_t len, bool no_cck,
Johannes Berge247bd902011-11-04 11:18:21 +01002034 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002035{
Johannes Berg9d38d852010-06-09 17:20:33 +02002036 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2037 struct ieee80211_local *local = sdata->local;
2038 struct sk_buff *skb;
2039 struct sta_info *sta;
Johannes Bergf30221e2010-11-25 10:02:30 +01002040 struct ieee80211_work *wk;
Johannes Berg9d38d852010-06-09 17:20:33 +02002041 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berge247bd902011-11-04 11:18:21 +01002042 u32 flags;
Johannes Bergf30221e2010-11-25 10:02:30 +01002043 bool is_offchan = false;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002044
Johannes Berge247bd902011-11-04 11:18:21 +01002045 if (dont_wait_for_ack)
2046 flags = IEEE80211_TX_CTL_NO_ACK;
2047 else
2048 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2049 IEEE80211_TX_CTL_REQ_TX_STATUS;
2050
Johannes Berg9d38d852010-06-09 17:20:33 +02002051 /* Check that we are on the requested channel for transmission */
2052 if (chan != local->tmp_channel &&
2053 chan != local->oper_channel)
Johannes Bergf30221e2010-11-25 10:02:30 +01002054 is_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002055 if (channel_type_valid &&
2056 (channel_type != local->tmp_channel_type &&
2057 channel_type != local->_oper_channel_type))
Johannes Bergf30221e2010-11-25 10:02:30 +01002058 is_offchan = true;
2059
Johannes Berg21f83582010-12-18 17:20:47 +01002060 if (chan == local->hw_roc_channel) {
2061 /* TODO: check channel type? */
2062 is_offchan = false;
2063 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2064 }
2065
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302066 if (no_cck)
2067 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2068
Johannes Bergf30221e2010-11-25 10:02:30 +01002069 if (is_offchan && !offchan)
Johannes Berg9d38d852010-06-09 17:20:33 +02002070 return -EBUSY;
2071
2072 switch (sdata->vif.type) {
2073 case NL80211_IFTYPE_ADHOC:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002074 case NL80211_IFTYPE_AP:
2075 case NL80211_IFTYPE_AP_VLAN:
2076 case NL80211_IFTYPE_P2P_GO:
Javier Cardonac7108a72010-12-16 17:37:50 -08002077 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002078 if (!ieee80211_is_action(mgmt->frame_control) ||
2079 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002080 break;
2081 rcu_read_lock();
2082 sta = sta_info_get(sdata, mgmt->da);
2083 rcu_read_unlock();
2084 if (!sta)
2085 return -ENOLINK;
2086 break;
2087 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002088 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg9d38d852010-06-09 17:20:33 +02002089 break;
2090 default:
2091 return -EOPNOTSUPP;
2092 }
2093
2094 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2095 if (!skb)
2096 return -ENOMEM;
2097 skb_reserve(skb, local->hw.extra_tx_headroom);
2098
2099 memcpy(skb_put(skb, len), buf, len);
2100
2101 IEEE80211_SKB_CB(skb)->flags = flags;
2102
2103 skb->dev = sdata->dev;
Johannes Berg9d38d852010-06-09 17:20:33 +02002104
2105 *cookie = (unsigned long) skb;
Johannes Bergf30221e2010-11-25 10:02:30 +01002106
Johannes Berg90fc4b32010-12-18 17:20:48 +01002107 if (is_offchan && local->ops->remain_on_channel) {
2108 unsigned int duration;
2109 int ret;
2110
2111 mutex_lock(&local->mtx);
2112 /*
2113 * If the duration is zero, then the driver
2114 * wouldn't actually do anything. Set it to
2115 * 100 for now.
2116 *
2117 * TODO: cancel the off-channel operation
2118 * when we get the SKB's TX status and
2119 * the wait time was zero before.
2120 */
2121 duration = 100;
2122 if (wait)
2123 duration = wait;
2124 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2125 channel_type,
2126 duration, cookie);
2127 if (ret) {
2128 kfree_skb(skb);
2129 mutex_unlock(&local->mtx);
2130 return ret;
2131 }
2132
2133 local->hw_roc_for_tx = true;
2134 local->hw_roc_duration = wait;
2135
2136 /*
2137 * queue up frame for transmission after
2138 * ieee80211_ready_on_channel call
2139 */
2140
2141 /* modify cookie to prevent API mismatches */
2142 *cookie ^= 2;
2143 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2144 local->hw_roc_skb = skb;
Johannes Berg4334ec82011-02-02 16:58:06 +01002145 local->hw_roc_skb_for_status = skb;
Johannes Berg90fc4b32010-12-18 17:20:48 +01002146 mutex_unlock(&local->mtx);
2147
2148 return 0;
2149 }
2150
Johannes Bergf30221e2010-11-25 10:02:30 +01002151 /*
2152 * Can transmit right away if the channel was the
2153 * right one and there's no wait involved... If a
2154 * wait is involved, we might otherwise not be on
2155 * the right channel for long enough!
2156 */
2157 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2158 ieee80211_tx_skb(sdata, skb);
2159 return 0;
2160 }
2161
2162 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2163 if (!wk) {
2164 kfree_skb(skb);
2165 return -ENOMEM;
2166 }
2167
2168 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2169 wk->chan = chan;
Ben Greear4d51e142011-02-07 13:44:34 -08002170 wk->chan_type = channel_type;
Johannes Bergf30221e2010-11-25 10:02:30 +01002171 wk->sdata = sdata;
2172 wk->done = ieee80211_offchan_tx_done;
2173 wk->offchan_tx.frame = skb;
2174 wk->offchan_tx.wait = wait;
Johannes Berg66e67e42012-01-20 13:55:27 +01002175 wk->data_len = len;
2176 memcpy(wk->data, buf, len);
Johannes Bergf30221e2010-11-25 10:02:30 +01002177
2178 ieee80211_add_work(wk);
Johannes Berg9d38d852010-06-09 17:20:33 +02002179 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02002180}
2181
Johannes Bergf30221e2010-11-25 10:02:30 +01002182static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2183 struct net_device *dev,
2184 u64 cookie)
2185{
2186 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2187 struct ieee80211_local *local = sdata->local;
2188 struct ieee80211_work *wk;
2189 int ret = -ENOENT;
2190
2191 mutex_lock(&local->mtx);
Johannes Berg90fc4b32010-12-18 17:20:48 +01002192
2193 if (local->ops->cancel_remain_on_channel) {
2194 cookie ^= 2;
2195 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2196
2197 if (ret == 0) {
2198 kfree_skb(local->hw_roc_skb);
2199 local->hw_roc_skb = NULL;
Johannes Berg4334ec82011-02-02 16:58:06 +01002200 local->hw_roc_skb_for_status = NULL;
Johannes Berg90fc4b32010-12-18 17:20:48 +01002201 }
2202
2203 mutex_unlock(&local->mtx);
2204
2205 return ret;
2206 }
2207
Johannes Bergf30221e2010-11-25 10:02:30 +01002208 list_for_each_entry(wk, &local->work_list, list) {
2209 if (wk->sdata != sdata)
2210 continue;
2211
2212 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2213 continue;
2214
2215 if (cookie != (unsigned long) wk->offchan_tx.frame)
2216 continue;
2217
2218 wk->timeout = jiffies;
2219
2220 ieee80211_queue_work(&local->hw, &local->work_work);
2221 ret = 0;
2222 break;
2223 }
2224 mutex_unlock(&local->mtx);
2225
2226 return ret;
2227}
2228
Johannes Berg7be50862010-10-13 12:06:24 +02002229static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2230 struct net_device *dev,
2231 u16 frame_type, bool reg)
2232{
2233 struct ieee80211_local *local = wiphy_priv(wiphy);
2234
2235 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2236 return;
2237
2238 if (reg)
2239 local->probe_req_reg++;
2240 else
2241 local->probe_req_reg--;
2242
2243 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2244}
2245
Bruno Randolf15d96752010-11-10 12:50:56 +09002246static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2247{
2248 struct ieee80211_local *local = wiphy_priv(wiphy);
2249
2250 if (local->started)
2251 return -EOPNOTSUPP;
2252
2253 return drv_set_antenna(local, tx_ant, rx_ant);
2254}
2255
2256static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2257{
2258 struct ieee80211_local *local = wiphy_priv(wiphy);
2259
2260 return drv_get_antenna(local, tx_ant, rx_ant);
2261}
2262
John W. Linville38c09152011-03-07 16:19:18 -05002263static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2264{
2265 struct ieee80211_local *local = wiphy_priv(wiphy);
2266
2267 return drv_set_ringparam(local, tx, rx);
2268}
2269
2270static void ieee80211_get_ringparam(struct wiphy *wiphy,
2271 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2272{
2273 struct ieee80211_local *local = wiphy_priv(wiphy);
2274
2275 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2276}
2277
Johannes Bergc68f4b82011-07-05 16:35:41 +02002278static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2279 struct net_device *dev,
2280 struct cfg80211_gtk_rekey_data *data)
2281{
2282 struct ieee80211_local *local = wiphy_priv(wiphy);
2283 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2284
2285 if (!local->ops->set_rekey_data)
2286 return -EOPNOTSUPP;
2287
2288 drv_set_rekey_data(local, sdata, data);
2289
2290 return 0;
2291}
2292
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002293static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2294{
2295 u8 *pos = (void *)skb_put(skb, 7);
2296
2297 *pos++ = WLAN_EID_EXT_CAPABILITY;
2298 *pos++ = 5; /* len */
2299 *pos++ = 0x0;
2300 *pos++ = 0x0;
2301 *pos++ = 0x0;
2302 *pos++ = 0x0;
2303 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2304}
2305
2306static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2307{
2308 struct ieee80211_local *local = sdata->local;
2309 u16 capab;
2310
2311 capab = 0;
2312 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2313 return capab;
2314
2315 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2316 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2317 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2318 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2319
2320 return capab;
2321}
2322
2323static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2324 u8 *peer, u8 *bssid)
2325{
2326 struct ieee80211_tdls_lnkie *lnkid;
2327
2328 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2329
2330 lnkid->ie_type = WLAN_EID_LINK_ID;
2331 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2332
2333 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2334 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2335 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2336}
2337
2338static int
2339ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2340 u8 *peer, u8 action_code, u8 dialog_token,
2341 u16 status_code, struct sk_buff *skb)
2342{
2343 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2344 struct ieee80211_tdls_data *tf;
2345
2346 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2347
2348 memcpy(tf->da, peer, ETH_ALEN);
2349 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2350 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2351 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2352
2353 switch (action_code) {
2354 case WLAN_TDLS_SETUP_REQUEST:
2355 tf->category = WLAN_CATEGORY_TDLS;
2356 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2357
2358 skb_put(skb, sizeof(tf->u.setup_req));
2359 tf->u.setup_req.dialog_token = dialog_token;
2360 tf->u.setup_req.capability =
2361 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2362
2363 ieee80211_add_srates_ie(&sdata->vif, skb);
2364 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2365 ieee80211_tdls_add_ext_capab(skb);
2366 break;
2367 case WLAN_TDLS_SETUP_RESPONSE:
2368 tf->category = WLAN_CATEGORY_TDLS;
2369 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2370
2371 skb_put(skb, sizeof(tf->u.setup_resp));
2372 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2373 tf->u.setup_resp.dialog_token = dialog_token;
2374 tf->u.setup_resp.capability =
2375 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2376
2377 ieee80211_add_srates_ie(&sdata->vif, skb);
2378 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2379 ieee80211_tdls_add_ext_capab(skb);
2380 break;
2381 case WLAN_TDLS_SETUP_CONFIRM:
2382 tf->category = WLAN_CATEGORY_TDLS;
2383 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2384
2385 skb_put(skb, sizeof(tf->u.setup_cfm));
2386 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2387 tf->u.setup_cfm.dialog_token = dialog_token;
2388 break;
2389 case WLAN_TDLS_TEARDOWN:
2390 tf->category = WLAN_CATEGORY_TDLS;
2391 tf->action_code = WLAN_TDLS_TEARDOWN;
2392
2393 skb_put(skb, sizeof(tf->u.teardown));
2394 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2395 break;
2396 case WLAN_TDLS_DISCOVERY_REQUEST:
2397 tf->category = WLAN_CATEGORY_TDLS;
2398 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2399
2400 skb_put(skb, sizeof(tf->u.discover_req));
2401 tf->u.discover_req.dialog_token = dialog_token;
2402 break;
2403 default:
2404 return -EINVAL;
2405 }
2406
2407 return 0;
2408}
2409
2410static int
2411ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2412 u8 *peer, u8 action_code, u8 dialog_token,
2413 u16 status_code, struct sk_buff *skb)
2414{
2415 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2416 struct ieee80211_mgmt *mgmt;
2417
2418 mgmt = (void *)skb_put(skb, 24);
2419 memset(mgmt, 0, 24);
2420 memcpy(mgmt->da, peer, ETH_ALEN);
2421 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2422 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2423
2424 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2425 IEEE80211_STYPE_ACTION);
2426
2427 switch (action_code) {
2428 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2429 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2430 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2431 mgmt->u.action.u.tdls_discover_resp.action_code =
2432 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2433 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2434 dialog_token;
2435 mgmt->u.action.u.tdls_discover_resp.capability =
2436 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2437
2438 ieee80211_add_srates_ie(&sdata->vif, skb);
2439 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2440 ieee80211_tdls_add_ext_capab(skb);
2441 break;
2442 default:
2443 return -EINVAL;
2444 }
2445
2446 return 0;
2447}
2448
2449static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2450 u8 *peer, u8 action_code, u8 dialog_token,
Sunil Dutt3db727f2014-04-17 23:15:25 +05302451 u16 status_code, u32 peer_capability,
2452 const u8 *extra_ies, size_t extra_ies_len)
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002453{
2454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2455 struct ieee80211_local *local = sdata->local;
2456 struct ieee80211_tx_info *info;
2457 struct sk_buff *skb = NULL;
2458 bool send_direct;
2459 int ret;
2460
2461 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2462 return -ENOTSUPP;
2463
2464 /* make sure we are in managed mode, and associated */
2465 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2466 !sdata->u.mgd.associated)
2467 return -EINVAL;
2468
2469#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2470 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2471#endif
2472
2473 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2474 max(sizeof(struct ieee80211_mgmt),
2475 sizeof(struct ieee80211_tdls_data)) +
2476 50 + /* supported rates */
2477 7 + /* ext capab */
2478 extra_ies_len +
2479 sizeof(struct ieee80211_tdls_lnkie));
2480 if (!skb)
2481 return -ENOMEM;
2482
2483 info = IEEE80211_SKB_CB(skb);
2484 skb_reserve(skb, local->hw.extra_tx_headroom);
2485
2486 switch (action_code) {
2487 case WLAN_TDLS_SETUP_REQUEST:
2488 case WLAN_TDLS_SETUP_RESPONSE:
2489 case WLAN_TDLS_SETUP_CONFIRM:
2490 case WLAN_TDLS_TEARDOWN:
2491 case WLAN_TDLS_DISCOVERY_REQUEST:
2492 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2493 action_code, dialog_token,
2494 status_code, skb);
2495 send_direct = false;
2496 break;
2497 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2498 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2499 dialog_token, status_code,
2500 skb);
2501 send_direct = true;
2502 break;
2503 default:
2504 ret = -ENOTSUPP;
2505 break;
2506 }
2507
2508 if (ret < 0)
2509 goto fail;
2510
2511 if (extra_ies_len)
2512 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2513
2514 /* the TDLS link IE is always added last */
2515 switch (action_code) {
2516 case WLAN_TDLS_SETUP_REQUEST:
2517 case WLAN_TDLS_SETUP_CONFIRM:
2518 case WLAN_TDLS_TEARDOWN:
2519 case WLAN_TDLS_DISCOVERY_REQUEST:
2520 /* we are the initiator */
2521 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2522 sdata->u.mgd.bssid);
2523 break;
2524 case WLAN_TDLS_SETUP_RESPONSE:
2525 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2526 /* we are the responder */
2527 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2528 sdata->u.mgd.bssid);
2529 break;
2530 default:
2531 ret = -ENOTSUPP;
2532 goto fail;
2533 }
2534
2535 if (send_direct) {
2536 ieee80211_tx_skb(sdata, skb);
2537 return 0;
2538 }
2539
2540 /*
2541 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2542 * we should default to AC_VI.
2543 */
2544 switch (action_code) {
2545 case WLAN_TDLS_SETUP_REQUEST:
2546 case WLAN_TDLS_SETUP_RESPONSE:
2547 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2548 skb->priority = 2;
2549 break;
2550 default:
2551 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2552 skb->priority = 5;
2553 break;
2554 }
2555
2556 /* disable bottom halves when entering the Tx path */
2557 local_bh_disable();
2558 ret = ieee80211_subif_start_xmit(skb, dev);
2559 local_bh_enable();
2560
2561 return ret;
2562
2563fail:
2564 dev_kfree_skb(skb);
2565 return ret;
2566}
2567
2568static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2569 u8 *peer, enum nl80211_tdls_operation oper)
2570{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002571 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002572 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2573
2574 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2575 return -ENOTSUPP;
2576
2577 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2578 return -EINVAL;
2579
2580#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2581 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2582#endif
2583
2584 switch (oper) {
2585 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002586 rcu_read_lock();
2587 sta = sta_info_get(sdata, peer);
2588 if (!sta) {
2589 rcu_read_unlock();
2590 return -ENOLINK;
2591 }
2592
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002593 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002594 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002595 break;
2596 case NL80211_TDLS_DISABLE_LINK:
2597 return sta_info_destroy_addr(sdata, peer);
2598 case NL80211_TDLS_TEARDOWN:
2599 case NL80211_TDLS_SETUP:
2600 case NL80211_TDLS_DISCOVERY_REQ:
2601 /* We don't support in-driver setup/teardown/discovery */
2602 return -ENOTSUPP;
2603 default:
2604 return -ENOTSUPP;
2605 }
2606
2607 return 0;
2608}
2609
Johannes Berg06500732011-11-04 11:18:16 +01002610static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2611 const u8 *peer, u64 *cookie)
2612{
2613 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2614 struct ieee80211_local *local = sdata->local;
2615 struct ieee80211_qos_hdr *nullfunc;
2616 struct sk_buff *skb;
2617 int size = sizeof(*nullfunc);
2618 __le16 fc;
2619 bool qos;
2620 struct ieee80211_tx_info *info;
2621 struct sta_info *sta;
2622
2623 rcu_read_lock();
2624 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01002625 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01002626 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01002627 rcu_read_unlock();
2628 } else {
2629 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01002630 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01002631 }
Johannes Berg06500732011-11-04 11:18:16 +01002632
2633 if (qos) {
2634 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2635 IEEE80211_STYPE_QOS_NULLFUNC |
2636 IEEE80211_FCTL_FROMDS);
2637 } else {
2638 size -= 2;
2639 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2640 IEEE80211_STYPE_NULLFUNC |
2641 IEEE80211_FCTL_FROMDS);
2642 }
2643
2644 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2645 if (!skb)
2646 return -ENOMEM;
2647
2648 skb->dev = dev;
2649
2650 skb_reserve(skb, local->hw.extra_tx_headroom);
2651
2652 nullfunc = (void *) skb_put(skb, size);
2653 nullfunc->frame_control = fc;
2654 nullfunc->duration_id = 0;
2655 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2656 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2657 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2658 nullfunc->seq_ctrl = 0;
2659
2660 info = IEEE80211_SKB_CB(skb);
2661
2662 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2663 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2664
2665 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2666 skb->priority = 7;
2667 if (qos)
2668 nullfunc->qos_ctrl = cpu_to_le16(7);
2669
2670 local_bh_disable();
2671 ieee80211_xmit(sdata, skb);
2672 local_bh_enable();
2673
2674 *cookie = (unsigned long) skb;
2675 return 0;
2676}
2677
Johannes Berge9998822011-11-09 10:30:21 +01002678static struct ieee80211_channel *
2679ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2680{
2681 struct ieee80211_local *local = wiphy_priv(wiphy);
2682
2683 return local->oper_channel;
2684}
2685
Jiri Bencf0706e822007-05-05 11:45:53 -07002686struct cfg80211_ops mac80211_config_ops = {
2687 .add_virtual_intf = ieee80211_add_iface,
2688 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02002689 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01002690 .add_key = ieee80211_add_key,
2691 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01002692 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01002693 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +02002694 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01002695 .start_ap = ieee80211_start_ap,
2696 .change_beacon = ieee80211_change_beacon,
2697 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01002698 .add_station = ieee80211_add_station,
2699 .del_station = ieee80211_del_station,
2700 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01002701 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002702 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02002703 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002704#ifdef CONFIG_MAC80211_MESH
2705 .add_mpath = ieee80211_add_mpath,
2706 .del_mpath = ieee80211_del_mpath,
2707 .change_mpath = ieee80211_change_mpath,
2708 .get_mpath = ieee80211_get_mpath,
2709 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002710 .update_mesh_config = ieee80211_update_mesh_config,
2711 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01002712 .join_mesh = ieee80211_join_mesh,
2713 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002714#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002715 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02002716 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002717 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05002718 .suspend = ieee80211_suspend,
2719 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01002720 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03002721 .sched_scan_start = ieee80211_sched_scan_start,
2722 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02002723 .auth = ieee80211_auth,
2724 .assoc = ieee80211_assoc,
2725 .deauth = ieee80211_deauth,
2726 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002727 .join_ibss = ieee80211_join_ibss,
2728 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002729 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02002730 .set_tx_power = ieee80211_set_tx_power,
2731 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02002732 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002733 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02002734 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002735 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002736 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02002737 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002738 .remain_on_channel = ieee80211_remain_on_channel,
2739 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02002740 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01002741 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002742 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02002743 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09002744 .set_antenna = ieee80211_set_antenna,
2745 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05002746 .set_ringparam = ieee80211_set_ringparam,
2747 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02002748 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002749 .tdls_oper = ieee80211_tdls_oper,
2750 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01002751 .probe_client = ieee80211_probe_client,
Johannes Berge9998822011-11-09 10:30:21 +01002752 .get_channel = ieee80211_wiphy_get_channel,
Simon Wunderlichb53be792011-11-18 14:20:44 +01002753 .set_noack_map = ieee80211_set_noack_map,
Jiri Bencf0706e822007-05-05 11:45:53 -07002754};