blob: a752c7341d62a5f33f3e1f5373b5ab41cb08af92 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg84efbb82012-06-16 00:00:26 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070027{
28 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020029 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010030 struct ieee80211_sub_if_data *sdata;
31 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070032
Johannes Berg84efbb82012-06-16 00:00:26 +020033 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010034 if (err)
35 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010036
Johannes Bergf9e10ce2010-12-03 09:20:42 +010037 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020038 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010039 sdata->u.mntr_flags = *flags;
40 }
41
Johannes Berg84efbb82012-06-16 00:00:26 +020042 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070043}
44
Johannes Berg84efbb82012-06-16 00:00:26 +020045static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070046{
Johannes Berg84efbb82012-06-16 00:00:26 +020047 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070048
Johannes Berg75636522008-07-09 14:40:35 +020049 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070050}
51
Johannes Berge36d56b2009-06-09 21:04:43 +020052static int ieee80211_change_iface(struct wiphy *wiphy,
53 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010054 enum nl80211_iftype type, u32 *flags,
55 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020056{
Johannes Berg9607e6b2009-12-23 13:15:31 +010057 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020058 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020059
Johannes Berg05c914f2008-09-11 00:01:58 +020060 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020061 if (ret)
62 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020063
Johannes Berg9bc383d2009-11-19 11:55:19 +010064 if (type == NL80211_IFTYPE_AP_VLAN &&
65 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000066 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010067 else if (type == NL80211_IFTYPE_STATION &&
68 params && params->use_4addr >= 0)
69 sdata->u.mgd.use_4addr = params->use_4addr;
70
Christian Lamparter85416a42010-10-02 13:17:07 +020071 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
72 struct ieee80211_local *local = sdata->local;
73
74 if (ieee80211_sdata_running(sdata)) {
75 /*
76 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
77 * changed while the interface is up.
78 * Else we would need to add a lot of cruft
79 * to update everything:
80 * cooked_mntrs, monitor and all fif_* counters
81 * reconfigure hardware
82 */
83 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
84 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
85 return -EBUSY;
86
87 ieee80211_adjust_monitor_flags(sdata, -1);
88 sdata->u.mntr_flags = *flags;
89 ieee80211_adjust_monitor_flags(sdata, 1);
90
91 ieee80211_configure_filter(local);
92 } else {
93 /*
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
97 */
98 sdata->u.mntr_flags = *flags;
99 }
100 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200101
Johannes Berg42613db2007-09-28 21:52:27 +0200102 return 0;
103}
104
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 Malinen3cfcf6ac2009-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 Bergdb4d1162008-02-25 16:27:45 +0100154 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700155 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200156 err = -ENOENT;
157 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100158 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100159 }
160
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300161 err = ieee80211_key_link(key, sdata, sta);
162 if (err)
163 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100164
Johannes Berg3b967662008-04-08 17:56:52 +0200165 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200166 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200167
168 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100169}
170
171static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200172 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100173{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200174 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
175 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100176 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200177 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100178 int ret;
179
Johannes Berg5c0c3642011-05-12 14:31:49 +0200180 mutex_lock(&local->sta_mtx);
181 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200182
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100183 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200184 ret = -ENOENT;
185
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100186 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100187 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200188 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100189
Johannes Berg5c0c3642011-05-12 14:31:49 +0200190 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200191 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200192 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200193 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200194 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200195 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100196
Johannes Berg5c0c3642011-05-12 14:31:49 +0200197 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200198 ret = -ENOENT;
199 goto out_unlock;
200 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100201
Johannes Berg5c0c3642011-05-12 14:31:49 +0200202 __ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100203
Johannes Berg3b967662008-04-08 17:56:52 +0200204 ret = 0;
205 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200206 mutex_unlock(&local->key_mtx);
207 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200208
209 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100210}
211
Johannes Berg62da92f2007-12-19 02:03:31 +0100212static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200213 u8 key_idx, bool pairwise, const u8 *mac_addr,
214 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100215 void (*callback)(void *cookie,
216 struct key_params *params))
217{
Johannes Berg14db74b2008-07-29 13:22:52 +0200218 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100219 struct sta_info *sta = NULL;
220 u8 seq[6] = {0};
221 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200222 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200223 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100224 u32 iv32;
225 u16 iv16;
226 int err = -ENOENT;
227
Johannes Berg14db74b2008-07-29 13:22:52 +0200228 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
229
Johannes Berg3b967662008-04-08 17:56:52 +0200230 rcu_read_lock();
231
Johannes Berg62da92f2007-12-19 02:03:31 +0100232 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100233 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100234 if (!sta)
235 goto out;
236
Johannes Berge31b8212010-10-05 19:39:30 +0200237 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200238 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200239 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200240 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100241 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200242 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100243
244 if (!key)
245 goto out;
246
247 memset(&params, 0, sizeof(params));
248
Johannes Berg97359d12010-08-10 09:46:38 +0200249 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100250
Johannes Berg97359d12010-08-10 09:46:38 +0200251 switch (key->conf.cipher) {
252 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700253 iv32 = key->u.tkip.tx.iv32;
254 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100255
Johannes Berg24487982009-04-23 18:52:52 +0200256 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
257 drv_get_tkip_seq(sdata->local,
258 key->conf.hw_key_idx,
259 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100260
261 seq[0] = iv16 & 0xff;
262 seq[1] = (iv16 >> 8) & 0xff;
263 seq[2] = iv32 & 0xff;
264 seq[3] = (iv32 >> 8) & 0xff;
265 seq[4] = (iv32 >> 16) & 0xff;
266 seq[5] = (iv32 >> 24) & 0xff;
267 params.seq = seq;
268 params.seq_len = 6;
269 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200270 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200271 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
272 seq[0] = pn64;
273 seq[1] = pn64 >> 8;
274 seq[2] = pn64 >> 16;
275 seq[3] = pn64 >> 24;
276 seq[4] = pn64 >> 32;
277 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100278 params.seq = seq;
279 params.seq_len = 6;
280 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200281 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200282 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
283 seq[0] = pn64;
284 seq[1] = pn64 >> 8;
285 seq[2] = pn64 >> 16;
286 seq[3] = pn64 >> 24;
287 seq[4] = pn64 >> 32;
288 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200289 params.seq = seq;
290 params.seq_len = 6;
291 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100292 }
293
294 params.key = key->conf.key;
295 params.key_len = key->conf.keylen;
296
297 callback(cookie, &params);
298 err = 0;
299
300 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200301 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100302 return err;
303}
304
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100305static int ieee80211_config_default_key(struct wiphy *wiphy,
306 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100307 u8 key_idx, bool uni,
308 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100309{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200310 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100311
Johannes Bergf7e01042010-12-09 19:49:02 +0100312 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100313
314 return 0;
315}
316
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200317static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
318 struct net_device *dev,
319 u8 key_idx)
320{
Johannes Berg66c52422010-07-22 13:58:51 +0200321 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200322
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200323 ieee80211_set_default_mgmt_key(sdata, key_idx);
324
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200325 return 0;
326}
327
Felix Fietkau3af63342011-02-27 22:08:01 +0100328static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
329{
330 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
331 struct ieee80211_supported_band *sband;
332 sband = sta->local->hw.wiphy->bands[
333 sta->local->hw.conf.channel->band];
334 rate->legacy = sband->bitrates[idx].bitrate;
335 } else
336 rate->mcs = idx;
337}
338
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800339void sta_set_rate_info_tx(struct sta_info *sta,
340 const struct ieee80211_tx_rate *rate,
341 struct rate_info *rinfo)
342{
343 rinfo->flags = 0;
344 if (rate->flags & IEEE80211_TX_RC_MCS)
345 rinfo->flags |= RATE_INFO_FLAGS_MCS;
346 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
347 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
348 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
349 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
350 rate_idx_to_bitrate(rinfo, sta, rate->idx);
351}
352
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100353static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
354{
Johannes Bergd0709a62008-02-25 16:27:46 +0100355 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300356 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530357 struct timespec uptime;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100358
Johannes Bergf5ea9122009-08-07 16:17:38 +0200359 sinfo->generation = sdata->local->sta_generation;
360
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100361 sinfo->filled = STATION_INFO_INACTIVE_TIME |
362 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100363 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200364 STATION_INFO_RX_PACKETS |
365 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900366 STATION_INFO_TX_RETRIES |
367 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700368 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100369 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700370 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530371 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200372 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800373 STATION_INFO_STA_FLAGS |
374 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530375
376 do_posix_clock_monotonic_gettime(&uptime);
377 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100378
379 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
380 sinfo->rx_bytes = sta->rx_bytes;
381 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200382 sinfo->rx_packets = sta->rx_packets;
383 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900384 sinfo->tx_retries = sta->tx_retry_count;
385 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700386 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800387 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100388
John W. Linville19deffb2009-12-08 17:10:13 -0500389 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
390 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900391 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300392 if (!local->ops->get_rssi ||
393 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
394 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900395 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100396 }
397
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800398 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100399
Felix Fietkau3af63342011-02-27 22:08:01 +0100400 sinfo->rxrate.flags = 0;
401 if (sta->last_rx_rate_flag & RX_FLAG_HT)
402 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
403 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
404 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
405 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
406 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
407 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100408
Johannes Berg902acc72008-02-23 15:17:19 +0100409 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100410#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100411 sinfo->filled |= STATION_INFO_LLID |
412 STATION_INFO_PLID |
413 STATION_INFO_PLINK_STATE;
414
415 sinfo->llid = le16_to_cpu(sta->llid);
416 sinfo->plid = le16_to_cpu(sta->plid);
417 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700418 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
419 sinfo->filled |= STATION_INFO_T_OFFSET;
420 sinfo->t_offset = sta->t_offset;
421 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100422#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100423 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700424
425 sinfo->bss_param.flags = 0;
426 if (sdata->vif.bss_conf.use_cts_prot)
427 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
428 if (sdata->vif.bss_conf.use_short_preamble)
429 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
430 if (sdata->vif.bss_conf.use_short_slot)
431 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
432 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
433 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200434
435 sinfo->sta_flags.set = 0;
436 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
437 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
438 BIT(NL80211_STA_FLAG_WME) |
439 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100440 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
441 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200442 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
443 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
444 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
445 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
446 if (test_sta_flag(sta, WLAN_STA_WME))
447 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
448 if (test_sta_flag(sta, WLAN_STA_MFP))
449 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
450 if (test_sta_flag(sta, WLAN_STA_AUTH))
451 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100452 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
453 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100454}
455
Ben Greearb1ab7922012-04-23 12:50:30 -0700456static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
457 "rx_packets", "rx_bytes", "wep_weak_iv_count",
458 "rx_duplicates", "rx_fragments", "rx_dropped",
459 "tx_packets", "tx_bytes", "tx_fragments",
460 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700461 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
462 "channel", "noise", "ch_time", "ch_time_busy",
463 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700464};
465#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
466
467static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
468 struct net_device *dev,
469 int sset)
470{
Ben Greeare3521142012-04-23 12:50:31 -0700471 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
472 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700473
Ben Greeare3521142012-04-23 12:50:31 -0700474 if (sset == ETH_SS_STATS)
475 rv += STA_STATS_LEN;
476
477 rv += drv_get_et_sset_count(sdata, sset);
478
479 if (rv == 0)
480 return -EOPNOTSUPP;
481 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700482}
483
484static void ieee80211_get_et_stats(struct wiphy *wiphy,
485 struct net_device *dev,
486 struct ethtool_stats *stats,
487 u64 *data)
488{
489 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
490 struct sta_info *sta;
491 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700492 struct station_info sinfo;
493 struct survey_info survey;
494 int i, q;
495#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700496
497 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
498
499#define ADD_STA_STATS(sta) \
500 do { \
501 data[i++] += sta->rx_packets; \
502 data[i++] += sta->rx_bytes; \
503 data[i++] += sta->wep_weak_iv_count; \
504 data[i++] += sta->num_duplicates; \
505 data[i++] += sta->rx_fragments; \
506 data[i++] += sta->rx_dropped; \
507 \
508 data[i++] += sta->tx_packets; \
509 data[i++] += sta->tx_bytes; \
510 data[i++] += sta->tx_fragments; \
511 data[i++] += sta->tx_filtered_count; \
512 data[i++] += sta->tx_retry_failed; \
513 data[i++] += sta->tx_retry_count; \
514 data[i++] += sta->beacon_loss_count; \
515 } while (0)
516
517 /* For Managed stations, find the single station based on BSSID
518 * and use that. For interface types, iterate through all available
519 * stations and add stats for any station that is assigned to this
520 * network device.
521 */
522
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300523 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700524
525 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
526 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700527
528 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
529 goto do_survey;
530
531 i = 0;
532 ADD_STA_STATS(sta);
533
534 data[i++] = sta->sta_state;
535
536 sinfo.filled = 0;
537 sta_set_sinfo(sta, &sinfo);
538
Joe Perches52042672012-05-30 13:25:54 -0700539 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700540 data[i] = 100000 *
541 cfg80211_calculate_bitrate(&sinfo.txrate);
542 i++;
Joe Perches52042672012-05-30 13:25:54 -0700543 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700544 data[i] = 100000 *
545 cfg80211_calculate_bitrate(&sinfo.rxrate);
546 i++;
547
Joe Perches52042672012-05-30 13:25:54 -0700548 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700549 data[i] = (u8)sinfo.signal_avg;
550 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700551 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300552 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700553 /* Make sure this station belongs to the proper dev */
554 if (sta->sdata->dev != dev)
555 continue;
556
557 i = 0;
558 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700559 }
560 }
561
Ben Greear3073a7c2012-04-23 12:50:32 -0700562do_survey:
563 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
564 /* Get survey stats for current channel */
565 q = 0;
566 while (true) {
567 survey.filled = 0;
568 if (drv_get_survey(local, q, &survey) != 0) {
569 survey.filled = 0;
570 break;
571 }
572
573 if (survey.channel &&
574 (local->oper_channel->center_freq ==
575 survey.channel->center_freq))
576 break;
577 q++;
578 }
579
580 if (survey.filled)
581 data[i++] = survey.channel->center_freq;
582 else
583 data[i++] = 0;
584 if (survey.filled & SURVEY_INFO_NOISE_DBM)
585 data[i++] = (u8)survey.noise;
586 else
587 data[i++] = -1LL;
588 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
589 data[i++] = survey.channel_time;
590 else
591 data[i++] = -1LL;
592 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
593 data[i++] = survey.channel_time_busy;
594 else
595 data[i++] = -1LL;
596 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
597 data[i++] = survey.channel_time_ext_busy;
598 else
599 data[i++] = -1LL;
600 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
601 data[i++] = survey.channel_time_rx;
602 else
603 data[i++] = -1LL;
604 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
605 data[i++] = survey.channel_time_tx;
606 else
607 data[i++] = -1LL;
608
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300609 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700610
Ben Greear3073a7c2012-04-23 12:50:32 -0700611 if (WARN_ON(i != STA_STATS_LEN))
612 return;
613
Ben Greeare3521142012-04-23 12:50:31 -0700614 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700615}
616
617static void ieee80211_get_et_strings(struct wiphy *wiphy,
618 struct net_device *dev,
619 u32 sset, u8 *data)
620{
Ben Greeare3521142012-04-23 12:50:31 -0700621 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
622 int sz_sta_stats = 0;
623
Ben Greearb1ab7922012-04-23 12:50:30 -0700624 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700625 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700626 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
627 }
Ben Greeare3521142012-04-23 12:50:31 -0700628 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700629}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100630
631static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
632 int idx, u8 *mac, struct station_info *sinfo)
633{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100634 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300635 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100636 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100637 int ret = -ENOENT;
638
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300639 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100640
Johannes Berg3b53fde82009-11-16 12:00:37 +0100641 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100642 if (sta) {
643 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200644 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100645 sta_set_sinfo(sta, sinfo);
646 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100647
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300648 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100649
Johannes Bergd0709a62008-02-25 16:27:46 +0100650 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100651}
652
Holger Schurig12897232010-04-19 10:23:57 +0200653static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
654 int idx, struct survey_info *survey)
655{
656 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
657
Holger Schurig12897232010-04-19 10:23:57 +0200658 return drv_get_survey(local, idx, survey);
659}
660
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100661static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100662 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100663{
Johannes Bergabe60632009-11-25 17:46:18 +0100664 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300665 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100666 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100667 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100668
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300669 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100670
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100671 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100672 if (sta) {
673 ret = 0;
674 sta_set_sinfo(sta, sinfo);
675 }
676
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300677 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100678
679 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100680}
681
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200682static int ieee80211_set_channel(struct wiphy *wiphy,
683 struct net_device *netdev,
684 struct ieee80211_channel *chan,
685 enum nl80211_channel_type channel_type)
686{
687 struct ieee80211_local *local = wiphy_priv(wiphy);
688 struct ieee80211_sub_if_data *sdata = NULL;
689
690 if (netdev)
691 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
692
693 switch (ieee80211_get_channel_mode(local, NULL)) {
694 case CHAN_MODE_HOPPING:
695 return -EBUSY;
696 case CHAN_MODE_FIXED:
Pontus Fuchsac4d82f2012-06-12 14:13:19 +0200697 if (local->oper_channel != chan ||
698 (!sdata && local->_oper_channel_type != channel_type))
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200699 return -EBUSY;
700 if (!sdata && local->_oper_channel_type == channel_type)
701 return 0;
702 break;
703 case CHAN_MODE_UNDEFINED:
704 break;
705 }
706
707 if (!ieee80211_set_channel_type(local, sdata, channel_type))
708 return -EBUSY;
709
710 local->oper_channel = chan;
711
712 /* auto-detects changes */
713 ieee80211_hw_config(local, 0);
714
715 return 0;
716}
717
Johannes Berge8c9bd52012-06-06 08:18:22 +0200718static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
719 struct ieee80211_channel *chan,
720 enum nl80211_channel_type channel_type)
721{
722 return ieee80211_set_channel(wiphy, NULL, chan, channel_type);
723}
724
Arik Nemtsov02945822011-11-10 11:28:57 +0200725static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100726 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200727{
728 struct sk_buff *new, *old;
729
730 if (!resp || !resp_len)
Johannes Berg88600202012-02-13 15:17:18 +0100731 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200732
Arik Nemtsovf7248282011-11-19 10:51:26 +0200733 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200734
735 new = dev_alloc_skb(resp_len);
736 if (!new)
737 return -ENOMEM;
738
739 memcpy(skb_put(new, resp_len), resp, resp_len);
740
741 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Johannes Berg88600202012-02-13 15:17:18 +0100742 if (old) {
743 /* TODO: use call_rcu() */
744 synchronize_rcu();
Arik Nemtsov02945822011-11-10 11:28:57 +0200745 dev_kfree_skb(old);
Johannes Berg88600202012-02-13 15:17:18 +0100746 }
Arik Nemtsov02945822011-11-10 11:28:57 +0200747
748 return 0;
749}
750
Johannes Berg88600202012-02-13 15:17:18 +0100751static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
752 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100753{
754 struct beacon_data *new, *old;
755 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100756 int size, err;
757 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100758
Johannes Berg40b275b2011-05-13 14:15:49 +0200759 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100760
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100761 /* Need to have a beacon head if we don't have one yet */
762 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100763 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100764
765 /* new or old head? */
766 if (params->head)
767 new_head_len = params->head_len;
768 else
769 new_head_len = old->head_len;
770
771 /* new or old tail? */
772 if (params->tail || !old)
773 /* params->tail_len will be zero for !params->tail */
774 new_tail_len = params->tail_len;
775 else
776 new_tail_len = old->tail_len;
777
778 size = sizeof(*new) + new_head_len + new_tail_len;
779
780 new = kzalloc(size, GFP_KERNEL);
781 if (!new)
782 return -ENOMEM;
783
784 /* start filling the new info now */
785
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100786 /*
787 * pointers go into the block we allocated,
788 * memory is | beacon_data | head | tail |
789 */
790 new->head = ((u8 *) new) + sizeof(*new);
791 new->tail = new->head + new_head_len;
792 new->head_len = new_head_len;
793 new->tail_len = new_tail_len;
794
795 /* copy in head */
796 if (params->head)
797 memcpy(new->head, params->head, new_head_len);
798 else
799 memcpy(new->head, old->head, new_head_len);
800
801 /* copy in optional tail */
802 if (params->tail)
803 memcpy(new->tail, params->tail, new_tail_len);
804 else
805 if (old)
806 memcpy(new->tail, old->tail, new_tail_len);
807
Johannes Berg88600202012-02-13 15:17:18 +0100808 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
809 params->probe_resp_len);
810 if (err < 0)
811 return err;
812 if (err == 0)
813 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100814
Eric Dumazetcf778b02012-01-12 04:41:32 +0000815 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100816
Johannes Berg88600202012-02-13 15:17:18 +0100817 if (old)
818 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100819
Johannes Berg88600202012-02-13 15:17:18 +0100820 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100821}
822
Johannes Berg88600202012-02-13 15:17:18 +0100823static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
824 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100825{
Johannes Berg88600202012-02-13 15:17:18 +0100826 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100827 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100828 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100829 u32 changed = BSS_CHANGED_BEACON_INT |
830 BSS_CHANGED_BEACON_ENABLED |
831 BSS_CHANGED_BEACON |
832 BSS_CHANGED_SSID;
833 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200834
Johannes Berg40b275b2011-05-13 14:15:49 +0200835 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100836 if (old)
837 return -EALREADY;
838
Johannes Bergaa430da2012-05-16 23:50:18 +0200839 err = ieee80211_set_channel(wiphy, dev, params->channel,
840 params->channel_type);
841 if (err)
842 return err;
843
Johannes Berg665c93a2011-11-04 11:18:11 +0100844 /*
845 * Apply control port protocol, this allows us to
846 * not encrypt dynamic WEP control frames.
847 */
848 sdata->control_port_protocol = params->crypto.control_port_ethertype;
849 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
850 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
851 vlan->control_port_protocol =
852 params->crypto.control_port_ethertype;
853 vlan->control_port_no_encrypt =
854 params->crypto.control_port_no_encrypt;
855 }
856
Johannes Berg88600202012-02-13 15:17:18 +0100857 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
858 sdata->vif.bss_conf.dtim_period = params->dtim_period;
859
860 sdata->vif.bss_conf.ssid_len = params->ssid_len;
861 if (params->ssid_len)
862 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
863 params->ssid_len);
864 sdata->vif.bss_conf.hidden_ssid =
865 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
866
867 err = ieee80211_assign_beacon(sdata, &params->beacon);
868 if (err < 0)
869 return err;
870 changed |= err;
871
872 ieee80211_bss_info_change_notify(sdata, changed);
873
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200874 netif_carrier_on(dev);
875 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
876 netif_carrier_on(vlan->dev);
877
Johannes Berg665c93a2011-11-04 11:18:11 +0100878 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100879}
880
Johannes Berg88600202012-02-13 15:17:18 +0100881static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
882 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100883{
Johannes Berg14db74b2008-07-29 13:22:52 +0200884 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100885 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100886 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100887
Johannes Berg14db74b2008-07-29 13:22:52 +0200888 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
889
Johannes Berg40b275b2011-05-13 14:15:49 +0200890 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100891 if (!old)
892 return -ENOENT;
893
Johannes Berg88600202012-02-13 15:17:18 +0100894 err = ieee80211_assign_beacon(sdata, params);
895 if (err < 0)
896 return err;
897 ieee80211_bss_info_change_notify(sdata, err);
898 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100899}
900
Johannes Berg88600202012-02-13 15:17:18 +0100901static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100902{
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200903 struct ieee80211_sub_if_data *sdata, *vlan;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100904 struct beacon_data *old;
905
Johannes Berg14db74b2008-07-29 13:22:52 +0200906 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
907
Johannes Berg40b275b2011-05-13 14:15:49 +0200908 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100909 if (!old)
910 return -ENOENT;
911
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200912 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
913 netif_carrier_off(vlan->dev);
914 netif_carrier_off(dev);
915
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000916 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100917
918 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100919
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200920 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100921
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200922 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100923}
924
Johannes Berg4fd69312007-12-19 02:03:35 +0100925/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
926struct iapp_layer2_update {
927 u8 da[ETH_ALEN]; /* broadcast */
928 u8 sa[ETH_ALEN]; /* STA addr */
929 __be16 len; /* 6 */
930 u8 dsap; /* 0 */
931 u8 ssap; /* 0 */
932 u8 control;
933 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700934} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100935
936static void ieee80211_send_layer2_update(struct sta_info *sta)
937{
938 struct iapp_layer2_update *msg;
939 struct sk_buff *skb;
940
941 /* Send Level 2 Update Frame to update forwarding tables in layer 2
942 * bridge devices */
943
944 skb = dev_alloc_skb(sizeof(*msg));
945 if (!skb)
946 return;
947 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
948
949 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
950 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
951
952 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200953 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100954 msg->len = htons(6);
955 msg->dsap = 0;
956 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
957 msg->control = 0xaf; /* XID response lsb.1111F101.
958 * F=0 (no poll command; unsolicited frame) */
959 msg->xid_info[0] = 0x81; /* XID format identifier */
960 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
961 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
962
Johannes Bergd0709a62008-02-25 16:27:46 +0100963 skb->dev = sta->sdata->dev;
964 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100965 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400966 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100967}
968
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100969static int sta_apply_parameters(struct ieee80211_local *local,
970 struct sta_info *sta,
971 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100972{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100973 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +0100974 u32 rates;
975 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100976 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100977 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300978 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100979
Johannes Bergae5eb022008-10-14 16:58:37 +0200980 sband = local->hw.wiphy->bands[local->oper_channel->band];
981
Johannes Bergeccb8e82009-05-11 21:57:56 +0300982 mask = params->sta_flags_mask;
983 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100984
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100985 /*
986 * In mesh mode, we can clear AUTHENTICATED flag but must
987 * also make ASSOCIATED follow appropriately for the driver
988 * API. See also below, after AUTHORIZED changes.
989 */
990 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
991 /* cfg80211 should not allow this in non-mesh modes */
992 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
993 return -EINVAL;
994
995 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
996 !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +0100997 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100998 if (ret)
999 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001000 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001001 if (ret)
1002 return ret;
1003 }
1004 }
1005
Johannes Bergeccb8e82009-05-11 21:57:56 +03001006 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001007 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001008 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Berg543d1b92012-01-13 14:17:59 +01001009 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001010 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001011 if (ret)
1012 return ret;
Johannes Berg4fd69312007-12-19 02:03:35 +01001013 }
1014
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001015 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1016 /* cfg80211 should not allow this in non-mesh modes */
1017 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1018 return -EINVAL;
1019
1020 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1021 test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001022 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001023 if (ret)
1024 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001025 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001026 if (ret)
1027 return ret;
1028 }
1029 }
1030
1031
Johannes Bergeccb8e82009-05-11 21:57:56 +03001032 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001033 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001034 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1035 else
1036 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001037 }
1038
1039 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001040 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001041 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001042 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001043 } else {
1044 clear_sta_flag(sta, WLAN_STA_WME);
1045 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001046 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001047 }
1048
1049 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001050 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001051 set_sta_flag(sta, WLAN_STA_MFP);
1052 else
1053 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001054 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001055
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001056 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001057 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001058 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1059 else
1060 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001061 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001062
Johannes Berg3b9ce802011-09-27 20:56:12 +02001063 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1064 sta->sta.uapsd_queues = params->uapsd_queues;
1065 sta->sta.max_sp = params->max_sp;
1066 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001067
Johannes Berg73651ee2008-02-25 16:27:47 +01001068 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001069 * cfg80211 validates this (1-2007) and allows setting the AID
1070 * only when creating a new station entry
1071 */
1072 if (params->aid)
1073 sta->sta.aid = params->aid;
1074
1075 /*
Johannes Berg73651ee2008-02-25 16:27:47 +01001076 * FIXME: updating the following information is racy when this
1077 * function is called from ieee80211_change_station().
1078 * However, all this information should be static so
1079 * maybe we should just reject attemps to change it.
1080 */
1081
Johannes Berg4fd69312007-12-19 02:03:35 +01001082 if (params->listen_interval >= 0)
1083 sta->listen_interval = params->listen_interval;
1084
1085 if (params->supported_rates) {
1086 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001087
Johannes Berg4fd69312007-12-19 02:03:35 +01001088 for (i = 0; i < params->supported_rates_len; i++) {
1089 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001090 for (j = 0; j < sband->n_bitrates; j++) {
1091 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001092 rates |= BIT(j);
1093 }
1094 }
Johannes Berg323ce792008-09-11 02:45:11 +02001095 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001096 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001097
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001098 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001099 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +02001100 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001101 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +03001102
Javier Cardona9c3990a2011-05-03 16:57:11 -07001103 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001104#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -07001105 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
1106 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001107 case NL80211_PLINK_LISTEN:
1108 case NL80211_PLINK_ESTAB:
1109 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -07001110 sta->plink_state = params->plink_state;
1111 break;
1112 default:
1113 /* nothing */
1114 break;
1115 }
1116 else
1117 switch (params->plink_action) {
1118 case PLINK_ACTION_OPEN:
1119 mesh_plink_open(sta);
1120 break;
1121 case PLINK_ACTION_BLOCK:
1122 mesh_plink_block(sta);
1123 break;
1124 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001125#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001126 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001127
1128 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001129}
1130
1131static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1132 u8 *mac, struct station_parameters *params)
1133{
Johannes Berg14db74b2008-07-29 13:22:52 +02001134 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001135 struct sta_info *sta;
1136 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001137 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001138 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001139
Johannes Berg4fd69312007-12-19 02:03:35 +01001140 if (params->vlan) {
1141 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1142
Johannes Berg05c914f2008-09-11 00:01:58 +02001143 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1144 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001145 return -EINVAL;
1146 } else
1147 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1148
Joe Perchesb203ca32012-05-08 18:56:52 +00001149 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001150 return -EINVAL;
1151
1152 if (is_multicast_ether_addr(mac))
1153 return -EINVAL;
1154
1155 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001156 if (!sta)
1157 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001158
Johannes Berg83d5cc02012-01-12 09:31:10 +01001159 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1160 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +01001161
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001162 err = sta_apply_parameters(local, sta, params);
1163 if (err) {
1164 sta_info_free(local, sta);
1165 return err;
1166 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001167
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001168 /*
1169 * for TDLS, rate control should be initialized only when supported
1170 * rates are known.
1171 */
1172 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1173 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001174
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001175 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1176 sdata->vif.type == NL80211_IFTYPE_AP;
1177
Johannes Berg34e89502010-02-03 13:59:58 +01001178 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001179 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001180 rcu_read_unlock();
1181 return err;
1182 }
1183
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001184 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001185 ieee80211_send_layer2_update(sta);
1186
1187 rcu_read_unlock();
1188
Johannes Berg4fd69312007-12-19 02:03:35 +01001189 return 0;
1190}
1191
1192static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1193 u8 *mac)
1194{
Johannes Berg14db74b2008-07-29 13:22:52 +02001195 struct ieee80211_local *local = wiphy_priv(wiphy);
1196 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001197
Johannes Berg14db74b2008-07-29 13:22:52 +02001198 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1199
Johannes Berg34e89502010-02-03 13:59:58 +01001200 if (mac)
1201 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001202
Johannes Berg34e89502010-02-03 13:59:58 +01001203 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001204 return 0;
1205}
1206
1207static int ieee80211_change_station(struct wiphy *wiphy,
1208 struct net_device *dev,
1209 u8 *mac,
1210 struct station_parameters *params)
1211{
Johannes Bergabe60632009-11-25 17:46:18 +01001212 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001213 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001214 struct sta_info *sta;
1215 struct ieee80211_sub_if_data *vlansdata;
Eliad Peller35b88622011-12-29 14:41:39 +02001216 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001217
Johannes Berg87be1e12011-12-14 12:20:29 +01001218 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001219
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001220 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001221 if (!sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001222 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001223 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001224 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001225
Johannes Bergbdd90d52011-12-14 12:20:27 +01001226 /* in station mode, supported rates are only valid with TDLS */
1227 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1228 params->supported_rates &&
1229 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001230 mutex_unlock(&local->sta_mtx);
Johannes Bergbdd90d52011-12-14 12:20:27 +01001231 return -EINVAL;
1232 }
1233
Johannes Bergd0709a62008-02-25 16:27:46 +01001234 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001235 bool prev_4addr = false;
1236 bool new_4addr = false;
1237
Johannes Berg4fd69312007-12-19 02:03:35 +01001238 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1239
Johannes Berg05c914f2008-09-11 00:01:58 +02001240 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1241 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001242 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001243 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001244 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001245
Johannes Berg9bc383d2009-11-19 11:55:19 +01001246 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001247 if (vlansdata->u.vlan.sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001248 mutex_unlock(&local->sta_mtx);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001249 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +01001250 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001251
Eric Dumazetcf778b02012-01-12 04:41:32 +00001252 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001253 new_4addr = true;
1254 }
1255
1256 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1257 sta->sdata->u.vlan.sta) {
1258 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1259 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001260 }
1261
Johannes Berg14db74b2008-07-29 13:22:52 +02001262 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001263
1264 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1265 prev_4addr != new_4addr) {
1266 if (new_4addr)
1267 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1268 else
1269 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1270 }
1271
Johannes Berg4fd69312007-12-19 02:03:35 +01001272 ieee80211_send_layer2_update(sta);
1273 }
1274
Eliad Peller35b88622011-12-29 14:41:39 +02001275 err = sta_apply_parameters(local, sta, params);
1276 if (err) {
1277 mutex_unlock(&local->sta_mtx);
1278 return err;
1279 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001280
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001281 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1282 rate_control_rate_init(sta);
1283
Johannes Berg87be1e12011-12-14 12:20:29 +01001284 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001285
Jason Young808118c2011-03-10 16:43:19 -08001286 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1287 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1288 ieee80211_recalc_ps(local, -1);
1289
Johannes Berg4fd69312007-12-19 02:03:35 +01001290 return 0;
1291}
1292
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001293#ifdef CONFIG_MAC80211_MESH
1294static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1295 u8 *dst, u8 *next_hop)
1296{
Johannes Berg14db74b2008-07-29 13:22:52 +02001297 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001298 struct mesh_path *mpath;
1299 struct sta_info *sta;
1300 int err;
1301
Johannes Berg14db74b2008-07-29 13:22:52 +02001302 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1303
Johannes Bergd0709a62008-02-25 16:27:46 +01001304 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001305 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001306 if (!sta) {
1307 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001308 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001309 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001310
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001311 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +01001312 if (err) {
1313 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001314 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001315 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001316
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001317 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001318 if (!mpath) {
1319 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001320 return -ENXIO;
1321 }
1322 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001323
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001324 rcu_read_unlock();
1325 return 0;
1326}
1327
1328static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1329 u8 *dst)
1330{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001331 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001332
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001333 if (dst)
1334 return mesh_path_del(dst, sdata);
1335
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001336 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001337 return 0;
1338}
1339
1340static int ieee80211_change_mpath(struct wiphy *wiphy,
1341 struct net_device *dev,
1342 u8 *dst, u8 *next_hop)
1343{
Johannes Berg14db74b2008-07-29 13:22:52 +02001344 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001345 struct mesh_path *mpath;
1346 struct sta_info *sta;
1347
Johannes Berg14db74b2008-07-29 13:22:52 +02001348 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1349
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001350 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001351
Johannes Bergabe60632009-11-25 17:46:18 +01001352 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001353 if (!sta) {
1354 rcu_read_unlock();
1355 return -ENOENT;
1356 }
1357
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001358 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001359 if (!mpath) {
1360 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001361 return -ENOENT;
1362 }
1363
1364 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001365
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001366 rcu_read_unlock();
1367 return 0;
1368}
1369
1370static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1371 struct mpath_info *pinfo)
1372{
Johannes Berga3836e02011-05-12 15:11:37 +02001373 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1374
1375 if (next_hop_sta)
1376 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001377 else
1378 memset(next_hop, 0, ETH_ALEN);
1379
Johannes Bergf5ea9122009-08-07 16:17:38 +02001380 pinfo->generation = mesh_paths_generation;
1381
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001382 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001383 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001384 MPATH_INFO_METRIC |
1385 MPATH_INFO_EXPTIME |
1386 MPATH_INFO_DISCOVERY_TIMEOUT |
1387 MPATH_INFO_DISCOVERY_RETRIES |
1388 MPATH_INFO_FLAGS;
1389
1390 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001391 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001392 pinfo->metric = mpath->metric;
1393 if (time_before(jiffies, mpath->exp_time))
1394 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1395 pinfo->discovery_timeout =
1396 jiffies_to_msecs(mpath->discovery_timeout);
1397 pinfo->discovery_retries = mpath->discovery_retries;
1398 pinfo->flags = 0;
1399 if (mpath->flags & MESH_PATH_ACTIVE)
1400 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1401 if (mpath->flags & MESH_PATH_RESOLVING)
1402 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001403 if (mpath->flags & MESH_PATH_SN_VALID)
1404 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001405 if (mpath->flags & MESH_PATH_FIXED)
1406 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1407 if (mpath->flags & MESH_PATH_RESOLVING)
1408 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1409
1410 pinfo->flags = mpath->flags;
1411}
1412
1413static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1414 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1415
1416{
Johannes Berg14db74b2008-07-29 13:22:52 +02001417 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001418 struct mesh_path *mpath;
1419
Johannes Berg14db74b2008-07-29 13:22:52 +02001420 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1421
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001422 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001423 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001424 if (!mpath) {
1425 rcu_read_unlock();
1426 return -ENOENT;
1427 }
1428 memcpy(dst, mpath->dst, ETH_ALEN);
1429 mpath_set_pinfo(mpath, next_hop, pinfo);
1430 rcu_read_unlock();
1431 return 0;
1432}
1433
1434static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1435 int idx, u8 *dst, u8 *next_hop,
1436 struct mpath_info *pinfo)
1437{
Johannes Berg14db74b2008-07-29 13:22:52 +02001438 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001439 struct mesh_path *mpath;
1440
Johannes Berg14db74b2008-07-29 13:22:52 +02001441 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1442
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001443 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001444 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001445 if (!mpath) {
1446 rcu_read_unlock();
1447 return -ENOENT;
1448 }
1449 memcpy(dst, mpath->dst, ETH_ALEN);
1450 mpath_set_pinfo(mpath, next_hop, pinfo);
1451 rcu_read_unlock();
1452 return 0;
1453}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001454
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001455static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001456 struct net_device *dev,
1457 struct mesh_config *conf)
1458{
1459 struct ieee80211_sub_if_data *sdata;
1460 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1461
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001462 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1463 return 0;
1464}
1465
1466static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1467{
1468 return (mask >> (parm-1)) & 0x1;
1469}
1470
Javier Cardonac80d5452010-12-16 17:37:49 -08001471static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1472 const struct mesh_setup *setup)
1473{
1474 u8 *new_ie;
1475 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001476 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1477 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001478
Javier Cardona581a8b02011-04-07 15:08:27 -07001479 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001480 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001481 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001482
Javier Cardona581a8b02011-04-07 15:08:27 -07001483 if (setup->ie_len) {
1484 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001485 GFP_KERNEL);
1486 if (!new_ie)
1487 return -ENOMEM;
1488 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001489 ifmsh->ie_len = setup->ie_len;
1490 ifmsh->ie = new_ie;
1491 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001492
1493 /* now copy the rest of the setup parameters */
1494 ifmsh->mesh_id_len = setup->mesh_id_len;
1495 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001496 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001497 ifmsh->mesh_pp_id = setup->path_sel_proto;
1498 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001499 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1500 if (setup->is_authenticated)
1501 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1502 if (setup->is_secure)
1503 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001504
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001505 /* mcast rate setting in Mesh Node */
1506 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1507 sizeof(setup->mcast_rate));
1508
Javier Cardonac80d5452010-12-16 17:37:49 -08001509 return 0;
1510}
1511
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001512static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001513 struct net_device *dev, u32 mask,
1514 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001515{
1516 struct mesh_config *conf;
1517 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001518 struct ieee80211_if_mesh *ifmsh;
1519
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001520 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001521 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001522
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001523 /* Set the config options which we are interested in setting */
1524 conf = &(sdata->u.mesh.mshcfg);
1525 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1526 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1527 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1528 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1529 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1530 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1531 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1532 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1533 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1534 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1535 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1536 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001537 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001538 conf->element_ttl = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001539 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1540 conf->auto_open_plinks = nconf->auto_open_plinks;
Javier Cardonad299a1f2012-03-31 11:31:33 -07001541 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1542 conf->dot11MeshNbrOffsetMaxNeighbor =
1543 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001544 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1545 conf->dot11MeshHWMPmaxPREQretries =
1546 nconf->dot11MeshHWMPmaxPREQretries;
1547 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1548 conf->path_refresh_time = nconf->path_refresh_time;
1549 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1550 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1551 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1552 conf->dot11MeshHWMPactivePathTimeout =
1553 nconf->dot11MeshHWMPactivePathTimeout;
1554 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1555 conf->dot11MeshHWMPpreqMinInterval =
1556 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001557 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1558 conf->dot11MeshHWMPperrMinInterval =
1559 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001560 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1561 mask))
1562 conf->dot11MeshHWMPnetDiameterTraversalTime =
1563 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001564 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1565 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1566 ieee80211_mesh_root_setup(ifmsh);
1567 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001568 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001569 /* our current gate announcement implementation rides on root
1570 * announcements, so require this ifmsh to also be a root node
1571 * */
1572 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001573 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1574 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001575 ieee80211_mesh_root_setup(ifmsh);
1576 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001577 conf->dot11MeshGateAnnouncementProtocol =
1578 nconf->dot11MeshGateAnnouncementProtocol;
1579 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001580 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001581 conf->dot11MeshHWMPRannInterval =
1582 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001583 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1584 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001585 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1586 /* our RSSI threshold implementation is supported only for
1587 * devices that report signal in dBm.
1588 */
1589 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1590 return -ENOTSUPP;
1591 conf->rssi_threshold = nconf->rssi_threshold;
1592 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001593 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1594 conf->ht_opmode = nconf->ht_opmode;
1595 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1596 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1597 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001598 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1599 conf->dot11MeshHWMPactivePathToRootTimeout =
1600 nconf->dot11MeshHWMPactivePathToRootTimeout;
1601 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1602 conf->dot11MeshHWMProotInterval =
1603 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001604 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1605 conf->dot11MeshHWMPconfirmationInterval =
1606 nconf->dot11MeshHWMPconfirmationInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001607 return 0;
1608}
1609
Johannes Berg29cbe682010-12-03 09:20:44 +01001610static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1611 const struct mesh_config *conf,
1612 const struct mesh_setup *setup)
1613{
1614 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1615 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001616 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001617
Javier Cardonac80d5452010-12-16 17:37:49 -08001618 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1619 err = copy_mesh_setup(ifmsh, setup);
1620 if (err)
1621 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001622
1623 err = ieee80211_set_channel(wiphy, dev, setup->channel,
1624 setup->channel_type);
1625 if (err)
1626 return err;
1627
Johannes Berg29cbe682010-12-03 09:20:44 +01001628 ieee80211_start_mesh(sdata);
1629
1630 return 0;
1631}
1632
1633static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1634{
1635 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1636
1637 ieee80211_stop_mesh(sdata);
1638
1639 return 0;
1640}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001641#endif
1642
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001643static int ieee80211_change_bss(struct wiphy *wiphy,
1644 struct net_device *dev,
1645 struct bss_parameters *params)
1646{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001647 struct ieee80211_sub_if_data *sdata;
1648 u32 changed = 0;
1649
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001650 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1651
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001652 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001653 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001654 changed |= BSS_CHANGED_ERP_CTS_PROT;
1655 }
1656 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001657 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001658 params->use_short_preamble;
1659 changed |= BSS_CHANGED_ERP_PREAMBLE;
1660 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001661
1662 if (!sdata->vif.bss_conf.use_short_slot &&
1663 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1664 sdata->vif.bss_conf.use_short_slot = true;
1665 changed |= BSS_CHANGED_ERP_SLOT;
1666 }
1667
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001668 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001669 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001670 params->use_short_slot_time;
1671 changed |= BSS_CHANGED_ERP_SLOT;
1672 }
1673
Jouni Malinen90c97a02008-10-30 16:59:22 +02001674 if (params->basic_rates) {
1675 int i, j;
1676 u32 rates = 0;
1677 struct ieee80211_local *local = wiphy_priv(wiphy);
1678 struct ieee80211_supported_band *sband =
1679 wiphy->bands[local->oper_channel->band];
1680
1681 for (i = 0; i < params->basic_rates_len; i++) {
1682 int rate = (params->basic_rates[i] & 0x7f) * 5;
1683 for (j = 0; j < sband->n_bitrates; j++) {
1684 if (sband->bitrates[j].bitrate == rate)
1685 rates |= BIT(j);
1686 }
1687 }
1688 sdata->vif.bss_conf.basic_rates = rates;
1689 changed |= BSS_CHANGED_BASIC_RATES;
1690 }
1691
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001692 if (params->ap_isolate >= 0) {
1693 if (params->ap_isolate)
1694 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1695 else
1696 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1697 }
1698
Helmut Schaa80d7e402010-11-19 12:40:26 +01001699 if (params->ht_opmode >= 0) {
1700 sdata->vif.bss_conf.ht_operation_mode =
1701 (u16) params->ht_opmode;
1702 changed |= BSS_CHANGED_HT;
1703 }
1704
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001705 ieee80211_bss_info_change_notify(sdata, changed);
1706
1707 return 0;
1708}
1709
Jouni Malinen31888482008-10-30 16:59:24 +02001710static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001711 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001712 struct ieee80211_txq_params *params)
1713{
1714 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001715 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001716 struct ieee80211_tx_queue_params p;
1717
1718 if (!local->ops->conf_tx)
1719 return -EOPNOTSUPP;
1720
Johannes Berg54bcbc62012-03-28 11:04:25 +02001721 if (local->hw.queues < IEEE80211_NUM_ACS)
1722 return -EOPNOTSUPP;
1723
Jouni Malinen31888482008-10-30 16:59:24 +02001724 memset(&p, 0, sizeof(p));
1725 p.aifs = params->aifs;
1726 p.cw_max = params->cwmax;
1727 p.cw_min = params->cwmin;
1728 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001729
1730 /*
1731 * Setting tx queue params disables u-apsd because it's only
1732 * called in master mode.
1733 */
1734 p.uapsd = false;
1735
Johannes Berga3304b02012-03-28 11:04:24 +02001736 sdata->tx_conf[params->ac] = p;
1737 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001738 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001739 "failed to set TX queue parameters for AC %d\n",
1740 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001741 return -EINVAL;
1742 }
1743
Johannes Berg7d257452012-07-06 17:37:43 +02001744 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1745
Jouni Malinen31888482008-10-30 16:59:24 +02001746 return 0;
1747}
1748
Bob Copeland665af4f2009-01-19 11:20:53 -05001749#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001750static int ieee80211_suspend(struct wiphy *wiphy,
1751 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001752{
Johannes Bergeecc4802011-05-04 15:37:29 +02001753 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001754}
1755
1756static int ieee80211_resume(struct wiphy *wiphy)
1757{
1758 return __ieee80211_resume(wiphy_priv(wiphy));
1759}
1760#else
1761#define ieee80211_suspend NULL
1762#define ieee80211_resume NULL
1763#endif
1764
Johannes Berg2a519312009-02-10 21:25:55 +01001765static int ieee80211_scan(struct wiphy *wiphy,
1766 struct net_device *dev,
1767 struct cfg80211_scan_request *req)
1768{
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001769 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg2a519312009-02-10 21:25:55 +01001770
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001771 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1772 case NL80211_IFTYPE_STATION:
1773 case NL80211_IFTYPE_ADHOC:
1774 case NL80211_IFTYPE_MESH_POINT:
1775 case NL80211_IFTYPE_P2P_CLIENT:
1776 break;
1777 case NL80211_IFTYPE_P2P_GO:
1778 if (sdata->local->ops->hw_scan)
1779 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001780 /*
1781 * FIXME: implement NoA while scanning in software,
1782 * for now fall through to allow scanning only when
1783 * beaconing hasn't been configured yet
1784 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001785 case NL80211_IFTYPE_AP:
1786 if (sdata->u.ap.beacon)
1787 return -EOPNOTSUPP;
1788 break;
1789 default:
1790 return -EOPNOTSUPP;
1791 }
Johannes Berg2a519312009-02-10 21:25:55 +01001792
1793 return ieee80211_request_scan(sdata, req);
1794}
1795
Luciano Coelho79f460c2011-05-11 17:09:36 +03001796static int
1797ieee80211_sched_scan_start(struct wiphy *wiphy,
1798 struct net_device *dev,
1799 struct cfg80211_sched_scan_request *req)
1800{
1801 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1802
1803 if (!sdata->local->ops->sched_scan_start)
1804 return -EOPNOTSUPP;
1805
1806 return ieee80211_request_sched_scan_start(sdata, req);
1807}
1808
1809static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001810ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001811{
1812 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1813
1814 if (!sdata->local->ops->sched_scan_stop)
1815 return -EOPNOTSUPP;
1816
Luciano Coelho85a99942011-05-12 16:28:29 +03001817 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001818}
1819
Jouni Malinen636a5d32009-03-19 13:39:22 +02001820static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1821 struct cfg80211_auth_request *req)
1822{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001823 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001824}
1825
1826static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1827 struct cfg80211_assoc_request *req)
1828{
Johannes Bergf444de02010-05-05 15:25:02 +02001829 struct ieee80211_local *local = wiphy_priv(wiphy);
1830 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1831
1832 switch (ieee80211_get_channel_mode(local, sdata)) {
1833 case CHAN_MODE_HOPPING:
1834 return -EBUSY;
1835 case CHAN_MODE_FIXED:
1836 if (local->oper_channel == req->bss->channel)
1837 break;
1838 return -EBUSY;
1839 case CHAN_MODE_UNDEFINED:
1840 break;
1841 }
1842
Johannes Berg77fdaa12009-07-07 03:45:17 +02001843 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001844}
1845
1846static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001847 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001848{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001849 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001850}
1851
1852static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001853 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001854{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001855 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001856}
1857
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001858static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1859 struct cfg80211_ibss_params *params)
1860{
Johannes Bergf444de02010-05-05 15:25:02 +02001861 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001862 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1863
Johannes Bergf444de02010-05-05 15:25:02 +02001864 switch (ieee80211_get_channel_mode(local, sdata)) {
1865 case CHAN_MODE_HOPPING:
1866 return -EBUSY;
1867 case CHAN_MODE_FIXED:
1868 if (!params->channel_fixed)
1869 return -EBUSY;
1870 if (local->oper_channel == params->channel)
1871 break;
1872 return -EBUSY;
1873 case CHAN_MODE_UNDEFINED:
1874 break;
1875 }
1876
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001877 return ieee80211_ibss_join(sdata, params);
1878}
1879
1880static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1881{
1882 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1883
1884 return ieee80211_ibss_leave(sdata);
1885}
1886
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001887static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1888{
1889 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001890 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001891
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001892 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1893 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1894
1895 if (err)
1896 return err;
1897 }
1898
Lukáš Turek310bc672009-12-21 22:50:48 +01001899 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1900 err = drv_set_coverage_class(local, wiphy->coverage_class);
1901
1902 if (err)
1903 return err;
1904 }
1905
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001906 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001907 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001908
Johannes Berg24487982009-04-23 18:52:52 +02001909 if (err)
1910 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001911 }
1912
1913 if (changed & WIPHY_PARAM_RETRY_SHORT)
1914 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1915 if (changed & WIPHY_PARAM_RETRY_LONG)
1916 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1917 if (changed &
1918 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1919 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1920
1921 return 0;
1922}
1923
Johannes Berg7643a2c2009-06-02 13:01:39 +02001924static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001925 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001926{
1927 struct ieee80211_local *local = wiphy_priv(wiphy);
1928 struct ieee80211_channel *chan = local->hw.conf.channel;
1929 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001930
1931 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001932 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001933 local->user_power_level = -1;
1934 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001935 case NL80211_TX_POWER_LIMITED:
1936 if (mbm < 0 || (mbm % 100))
1937 return -EOPNOTSUPP;
1938 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001939 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001940 case NL80211_TX_POWER_FIXED:
1941 if (mbm < 0 || (mbm % 100))
1942 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001943 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001944 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001945 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001946 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001947 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001948 }
1949
1950 ieee80211_hw_config(local, changes);
1951
1952 return 0;
1953}
1954
1955static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1956{
1957 struct ieee80211_local *local = wiphy_priv(wiphy);
1958
1959 *dbm = local->hw.conf.power_level;
1960
Johannes Berg7643a2c2009-06-02 13:01:39 +02001961 return 0;
1962}
1963
Johannes Bergab737a42009-07-01 21:26:58 +02001964static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02001965 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02001966{
1967 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1968
1969 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1970
1971 return 0;
1972}
1973
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001974static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1975{
1976 struct ieee80211_local *local = wiphy_priv(wiphy);
1977
1978 drv_rfkill_poll(local);
1979}
1980
Johannes Bergaff89a92009-07-01 21:26:51 +02001981#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001982static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001983{
1984 struct ieee80211_local *local = wiphy_priv(wiphy);
1985
1986 if (!local->ops->testmode_cmd)
1987 return -EOPNOTSUPP;
1988
1989 return local->ops->testmode_cmd(&local->hw, data, len);
1990}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07001991
1992static int ieee80211_testmode_dump(struct wiphy *wiphy,
1993 struct sk_buff *skb,
1994 struct netlink_callback *cb,
1995 void *data, int len)
1996{
1997 struct ieee80211_local *local = wiphy_priv(wiphy);
1998
1999 if (!local->ops->testmode_dump)
2000 return -EOPNOTSUPP;
2001
2002 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2003}
Johannes Bergaff89a92009-07-01 21:26:51 +02002004#endif
2005
Johannes Berg0f782312009-12-01 13:37:02 +01002006int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2007 enum ieee80211_smps_mode smps_mode)
2008{
2009 const u8 *ap;
2010 enum ieee80211_smps_mode old_req;
2011 int err;
2012
Johannes Berg243e6df2011-04-19 20:44:04 +02002013 lockdep_assert_held(&sdata->u.mgd.mtx);
2014
Johannes Berg0f782312009-12-01 13:37:02 +01002015 old_req = sdata->u.mgd.req_smps;
2016 sdata->u.mgd.req_smps = smps_mode;
2017
2018 if (old_req == smps_mode &&
2019 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2020 return 0;
2021
2022 /*
2023 * If not associated, or current association is not an HT
2024 * association, there's no need to send an action frame.
2025 */
2026 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02002027 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01002028 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02002029 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01002030 mutex_unlock(&sdata->local->iflist_mtx);
2031 return 0;
2032 }
2033
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002034 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002035
2036 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2037 if (sdata->u.mgd.powersave)
2038 smps_mode = IEEE80211_SMPS_DYNAMIC;
2039 else
2040 smps_mode = IEEE80211_SMPS_OFF;
2041 }
2042
2043 /* send SM PS frame to AP */
2044 err = ieee80211_send_smps_action(sdata, smps_mode,
2045 ap, ap);
2046 if (err)
2047 sdata->u.mgd.req_smps = old_req;
2048
2049 return err;
2050}
2051
Johannes Bergbc92afd2009-07-01 21:26:57 +02002052static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2053 bool enabled, int timeout)
2054{
2055 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2056 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002057
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002058 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2059 return -EOPNOTSUPP;
2060
Johannes Bergbc92afd2009-07-01 21:26:57 +02002061 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2062 return -EOPNOTSUPP;
2063
2064 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002065 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002066 return 0;
2067
2068 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002069 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002070
Johannes Berg0f782312009-12-01 13:37:02 +01002071 /* no change, but if automatic follow powersave */
2072 mutex_lock(&sdata->u.mgd.mtx);
2073 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2074 mutex_unlock(&sdata->u.mgd.mtx);
2075
Johannes Bergbc92afd2009-07-01 21:26:57 +02002076 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2077 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2078
2079 ieee80211_recalc_ps(local, -1);
2080
2081 return 0;
2082}
2083
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002084static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2085 struct net_device *dev,
2086 s32 rssi_thold, u32 rssi_hyst)
2087{
2088 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002089 struct ieee80211_vif *vif = &sdata->vif;
2090 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2091
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002092 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2093 rssi_hyst == bss_conf->cqm_rssi_hyst)
2094 return 0;
2095
2096 bss_conf->cqm_rssi_thold = rssi_thold;
2097 bss_conf->cqm_rssi_hyst = rssi_hyst;
2098
2099 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002100 if (sdata->u.mgd.associated &&
2101 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002102 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2103
2104 return 0;
2105}
2106
Johannes Berg99303802009-07-01 21:26:59 +02002107static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2108 struct net_device *dev,
2109 const u8 *addr,
2110 const struct cfg80211_bitrate_mask *mask)
2111{
2112 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2113 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302114 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002115
Eliad Peller554a43d2012-06-12 12:41:15 +03002116 if (!ieee80211_sdata_running(sdata))
2117 return -ENETDOWN;
2118
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302119 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2120 ret = drv_set_bitrate_mask(local, sdata, mask);
2121 if (ret)
2122 return ret;
2123 }
Johannes Berg99303802009-07-01 21:26:59 +02002124
Simon Wunderlich19468412012-01-28 17:25:33 +01002125 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002126 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002127 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2128 sizeof(mask->control[i].mcs));
2129 }
Johannes Berg99303802009-07-01 21:26:59 +02002130
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002131 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002132}
2133
Johannes Berg2eb278e2012-06-05 14:28:42 +02002134static int ieee80211_start_roc_work(struct ieee80211_local *local,
2135 struct ieee80211_sub_if_data *sdata,
2136 struct ieee80211_channel *channel,
2137 enum nl80211_channel_type channel_type,
2138 unsigned int duration, u64 *cookie,
2139 struct sk_buff *txskb)
Johannes Berg21f83582010-12-18 17:20:47 +01002140{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002141 struct ieee80211_roc_work *roc, *tmp;
2142 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002143 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002144
2145 lockdep_assert_held(&local->mtx);
2146
Johannes Berg2eb278e2012-06-05 14:28:42 +02002147 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2148 if (!roc)
2149 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002150
Johannes Berg2eb278e2012-06-05 14:28:42 +02002151 roc->chan = channel;
2152 roc->chan_type = channel_type;
2153 roc->duration = duration;
2154 roc->req_duration = duration;
2155 roc->frame = txskb;
2156 roc->mgmt_tx_cookie = (unsigned long)txskb;
2157 roc->sdata = sdata;
2158 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2159 INIT_LIST_HEAD(&roc->dependents);
2160
2161 /* if there's one pending or we're scanning, queue this one */
2162 if (!list_empty(&local->roc_list) || local->scanning)
2163 goto out_check_combine;
2164
2165 /* if not HW assist, just queue & schedule work */
2166 if (!local->ops->remain_on_channel) {
2167 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2168 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002169 }
2170
Johannes Berg2eb278e2012-06-05 14:28:42 +02002171 /* otherwise actually kick it off here (for error handling) */
2172
2173 /*
2174 * If the duration is zero, then the driver
2175 * wouldn't actually do anything. Set it to
2176 * 10 for now.
2177 *
2178 * TODO: cancel the off-channel operation
2179 * when we get the SKB's TX status and
2180 * the wait time was zero before.
2181 */
2182 if (!duration)
2183 duration = 10;
2184
2185 ret = drv_remain_on_channel(local, channel, channel_type, duration);
2186 if (ret) {
2187 kfree(roc);
2188 return ret;
2189 }
2190
2191 roc->started = true;
2192 goto out_queue;
2193
2194 out_check_combine:
2195 list_for_each_entry(tmp, &local->roc_list, list) {
2196 if (tmp->chan != channel || tmp->chan_type != channel_type)
2197 continue;
2198
2199 /*
2200 * Extend this ROC if possible:
2201 *
2202 * If it hasn't started yet, just increase the duration
2203 * and add the new one to the list of dependents.
2204 */
2205 if (!tmp->started) {
2206 list_add_tail(&roc->list, &tmp->dependents);
2207 tmp->duration = max(tmp->duration, roc->duration);
2208 queued = true;
2209 break;
2210 }
2211
2212 /* If it has already started, it's more difficult ... */
2213 if (local->ops->remain_on_channel) {
2214 unsigned long j = jiffies;
2215
2216 /*
2217 * In the offloaded ROC case, if it hasn't begun, add
2218 * this new one to the dependent list to be handled
2219 * when the the master one begins. If it has begun,
2220 * check that there's still a minimum time left and
2221 * if so, start this one, transmitting the frame, but
2222 * add it to the list directly after this one with a
2223 * a reduced time so we'll ask the driver to execute
2224 * it right after finishing the previous one, in the
2225 * hope that it'll also be executed right afterwards,
2226 * effectively extending the old one.
2227 * If there's no minimum time left, just add it to the
2228 * normal list.
2229 */
2230 if (!tmp->hw_begun) {
2231 list_add_tail(&roc->list, &tmp->dependents);
2232 queued = true;
2233 break;
2234 }
2235
2236 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2237 tmp->hw_start_time +
2238 msecs_to_jiffies(tmp->duration))) {
2239 int new_dur;
2240
2241 ieee80211_handle_roc_started(roc);
2242
2243 new_dur = roc->duration -
2244 jiffies_to_msecs(tmp->hw_start_time +
2245 msecs_to_jiffies(
2246 tmp->duration) -
2247 j);
2248
2249 if (new_dur > 0) {
2250 /* add right after tmp */
2251 list_add(&roc->list, &tmp->list);
2252 } else {
2253 list_add_tail(&roc->list,
2254 &tmp->dependents);
2255 }
2256 queued = true;
2257 }
2258 } else if (del_timer_sync(&tmp->work.timer)) {
2259 unsigned long new_end;
2260
2261 /*
2262 * In the software ROC case, cancel the timer, if
2263 * that fails then the finish work is already
2264 * queued/pending and thus we queue the new ROC
2265 * normally, if that succeeds then we can extend
2266 * the timer duration and TX the frame (if any.)
2267 */
2268
2269 list_add_tail(&roc->list, &tmp->dependents);
2270 queued = true;
2271
2272 new_end = jiffies + msecs_to_jiffies(roc->duration);
2273
2274 /* ok, it was started & we canceled timer */
2275 if (time_after(new_end, tmp->work.timer.expires))
2276 mod_timer(&tmp->work.timer, new_end);
2277 else
2278 add_timer(&tmp->work.timer);
2279
2280 ieee80211_handle_roc_started(roc);
2281 }
2282 break;
2283 }
2284
2285 out_queue:
2286 if (!queued)
2287 list_add_tail(&roc->list, &local->roc_list);
2288
2289 /*
2290 * cookie is either the roc (for normal roc)
2291 * or the SKB (for mgmt TX)
2292 */
2293 if (txskb)
2294 *cookie = (unsigned long)txskb;
2295 else
2296 *cookie = (unsigned long)roc;
2297
2298 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002299}
2300
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002301static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002302 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002303 struct ieee80211_channel *chan,
2304 enum nl80211_channel_type channel_type,
2305 unsigned int duration,
2306 u64 *cookie)
2307{
Johannes Berg71bbc992012-06-15 15:30:18 +02002308 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002309 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002310 int ret;
2311
Johannes Berg2eb278e2012-06-05 14:28:42 +02002312 mutex_lock(&local->mtx);
2313 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2314 duration, cookie, NULL);
2315 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002316
Johannes Berg2eb278e2012-06-05 14:28:42 +02002317 return ret;
2318}
2319
2320static int ieee80211_cancel_roc(struct ieee80211_local *local,
2321 u64 cookie, bool mgmt_tx)
2322{
2323 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2324 int ret;
2325
2326 mutex_lock(&local->mtx);
2327 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002328 struct ieee80211_roc_work *dep, *tmp2;
2329
2330 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2331 if (!mgmt_tx && (unsigned long)dep != cookie)
2332 continue;
2333 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2334 continue;
2335 /* found dependent item -- just remove it */
2336 list_del(&dep->list);
2337 mutex_unlock(&local->mtx);
2338
2339 ieee80211_roc_notify_destroy(dep);
2340 return 0;
2341 }
2342
Johannes Berg2eb278e2012-06-05 14:28:42 +02002343 if (!mgmt_tx && (unsigned long)roc != cookie)
2344 continue;
2345 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2346 continue;
2347
2348 found = roc;
2349 break;
2350 }
2351
2352 if (!found) {
2353 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002354 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002355 }
Johannes Berg21f83582010-12-18 17:20:47 +01002356
Johannes Berge979e332012-06-11 17:09:41 +02002357 /*
2358 * We found the item to cancel, so do that. Note that it
2359 * may have dependents, which we also cancel (and send
2360 * the expired signal for.) Not doing so would be quite
2361 * tricky here, but we may need to fix it later.
2362 */
2363
Johannes Berg2eb278e2012-06-05 14:28:42 +02002364 if (local->ops->remain_on_channel) {
2365 if (found->started) {
2366 ret = drv_cancel_remain_on_channel(local);
2367 if (WARN_ON_ONCE(ret)) {
2368 mutex_unlock(&local->mtx);
2369 return ret;
2370 }
2371 }
Johannes Berg21f83582010-12-18 17:20:47 +01002372
Johannes Berg2eb278e2012-06-05 14:28:42 +02002373 list_del(&found->list);
2374
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002375 if (found->started)
2376 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002377 mutex_unlock(&local->mtx);
2378
2379 ieee80211_roc_notify_destroy(found);
2380 } else {
2381 /* work may be pending so use it all the time */
2382 found->abort = true;
2383 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2384
2385 mutex_unlock(&local->mtx);
2386
2387 /* work will clean up etc */
2388 flush_delayed_work(&found->work);
2389 }
Johannes Berg21f83582010-12-18 17:20:47 +01002390
Johannes Berg21f83582010-12-18 17:20:47 +01002391 return 0;
2392}
2393
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002394static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002395 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002396 u64 cookie)
2397{
Johannes Berg71bbc992012-06-15 15:30:18 +02002398 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002399 struct ieee80211_local *local = sdata->local;
2400
Johannes Berg2eb278e2012-06-05 14:28:42 +02002401 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002402}
2403
Johannes Berg71bbc992012-06-15 15:30:18 +02002404static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002405 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f72010-08-12 15:38:38 +02002406 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002407 bool channel_type_valid, unsigned int wait,
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05302408 const u8 *buf, size_t len, bool no_cck,
Johannes Berge247bd902011-11-04 11:18:21 +01002409 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002410{
Johannes Berg71bbc992012-06-15 15:30:18 +02002411 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002412 struct ieee80211_local *local = sdata->local;
2413 struct sk_buff *skb;
2414 struct sta_info *sta;
2415 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002416 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002417 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002418 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002419
Johannes Berge247bd902011-11-04 11:18:21 +01002420 if (dont_wait_for_ack)
2421 flags = IEEE80211_TX_CTL_NO_ACK;
2422 else
2423 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2424 IEEE80211_TX_CTL_REQ_TX_STATUS;
2425
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302426 if (no_cck)
2427 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2428
Johannes Berg9d38d852010-06-09 17:20:33 +02002429 switch (sdata->vif.type) {
2430 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002431 if (!sdata->vif.bss_conf.ibss_joined)
2432 need_offchan = true;
2433 /* fall through */
2434#ifdef CONFIG_MAC80211_MESH
2435 case NL80211_IFTYPE_MESH_POINT:
2436 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2437 !sdata->u.mesh.mesh_id_len)
2438 need_offchan = true;
2439 /* fall through */
2440#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002441 case NL80211_IFTYPE_AP:
2442 case NL80211_IFTYPE_AP_VLAN:
2443 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002444 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2445 !ieee80211_vif_is_mesh(&sdata->vif) &&
2446 !rcu_access_pointer(sdata->bss->beacon))
2447 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002448 if (!ieee80211_is_action(mgmt->frame_control) ||
2449 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002450 break;
2451 rcu_read_lock();
2452 sta = sta_info_get(sdata, mgmt->da);
2453 rcu_read_unlock();
2454 if (!sta)
2455 return -ENOLINK;
2456 break;
2457 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002458 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002459 if (!sdata->u.mgd.associated)
2460 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002461 break;
2462 default:
2463 return -EOPNOTSUPP;
2464 }
2465
Johannes Berg2eb278e2012-06-05 14:28:42 +02002466 mutex_lock(&local->mtx);
2467
2468 /* Check if the operating channel is the requested channel */
2469 if (!need_offchan) {
2470 need_offchan = chan != local->oper_channel;
2471 if (channel_type_valid &&
2472 channel_type != local->_oper_channel_type)
2473 need_offchan = true;
2474 }
2475
2476 if (need_offchan && !offchan) {
2477 ret = -EBUSY;
2478 goto out_unlock;
2479 }
2480
Johannes Berg9d38d852010-06-09 17:20:33 +02002481 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002482 if (!skb) {
2483 ret = -ENOMEM;
2484 goto out_unlock;
2485 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002486 skb_reserve(skb, local->hw.extra_tx_headroom);
2487
2488 memcpy(skb_put(skb, len), buf, len);
2489
2490 IEEE80211_SKB_CB(skb)->flags = flags;
2491
Johannes Berg2eb278e2012-06-05 14:28:42 +02002492 skb->dev = sdata->dev;
2493
2494 if (!need_offchan) {
2495 ieee80211_tx_skb(sdata, skb);
2496 ret = 0;
2497 goto out_unlock;
2498 }
2499
2500 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2501 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002502 IEEE80211_SKB_CB(skb)->hw_queue =
2503 local->hw.offchannel_tx_hw_queue;
2504
Johannes Berg2eb278e2012-06-05 14:28:42 +02002505 /* This will handle all kinds of coalescing and immediate TX */
2506 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2507 wait, cookie, skb);
2508 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002509 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002510 out_unlock:
2511 mutex_unlock(&local->mtx);
2512 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002513}
2514
Johannes Bergf30221e2010-11-25 10:02:30 +01002515static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002516 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002517 u64 cookie)
2518{
Johannes Berg71bbc992012-06-15 15:30:18 +02002519 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002520
Johannes Berg2eb278e2012-06-05 14:28:42 +02002521 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002522}
2523
Johannes Berg7be50862010-10-13 12:06:24 +02002524static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002525 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002526 u16 frame_type, bool reg)
2527{
2528 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002529 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002530
Will Hawkins6abe0562012-06-20 11:51:14 -04002531 switch (frame_type) {
2532 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2533 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2534 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002535
Will Hawkins6abe0562012-06-20 11:51:14 -04002536 if (reg)
2537 ifibss->auth_frame_registrations++;
2538 else
2539 ifibss->auth_frame_registrations--;
2540 }
2541 break;
2542 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2543 if (reg)
2544 local->probe_req_reg++;
2545 else
2546 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002547
Will Hawkins6abe0562012-06-20 11:51:14 -04002548 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2549 break;
2550 default:
2551 break;
2552 }
Johannes Berg7be50862010-10-13 12:06:24 +02002553}
2554
Bruno Randolf15d96752010-11-10 12:50:56 +09002555static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2556{
2557 struct ieee80211_local *local = wiphy_priv(wiphy);
2558
2559 if (local->started)
2560 return -EOPNOTSUPP;
2561
2562 return drv_set_antenna(local, tx_ant, rx_ant);
2563}
2564
2565static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2566{
2567 struct ieee80211_local *local = wiphy_priv(wiphy);
2568
2569 return drv_get_antenna(local, tx_ant, rx_ant);
2570}
2571
John W. Linville38c09152011-03-07 16:19:18 -05002572static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2573{
2574 struct ieee80211_local *local = wiphy_priv(wiphy);
2575
2576 return drv_set_ringparam(local, tx, rx);
2577}
2578
2579static void ieee80211_get_ringparam(struct wiphy *wiphy,
2580 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2581{
2582 struct ieee80211_local *local = wiphy_priv(wiphy);
2583
2584 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2585}
2586
Johannes Bergc68f4b82011-07-05 16:35:41 +02002587static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2588 struct net_device *dev,
2589 struct cfg80211_gtk_rekey_data *data)
2590{
2591 struct ieee80211_local *local = wiphy_priv(wiphy);
2592 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2593
2594 if (!local->ops->set_rekey_data)
2595 return -EOPNOTSUPP;
2596
2597 drv_set_rekey_data(local, sdata, data);
2598
2599 return 0;
2600}
2601
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002602static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2603{
2604 u8 *pos = (void *)skb_put(skb, 7);
2605
2606 *pos++ = WLAN_EID_EXT_CAPABILITY;
2607 *pos++ = 5; /* len */
2608 *pos++ = 0x0;
2609 *pos++ = 0x0;
2610 *pos++ = 0x0;
2611 *pos++ = 0x0;
2612 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2613}
2614
2615static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2616{
2617 struct ieee80211_local *local = sdata->local;
2618 u16 capab;
2619
2620 capab = 0;
2621 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2622 return capab;
2623
2624 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2625 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2626 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2627 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2628
2629 return capab;
2630}
2631
2632static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2633 u8 *peer, u8 *bssid)
2634{
2635 struct ieee80211_tdls_lnkie *lnkid;
2636
2637 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2638
2639 lnkid->ie_type = WLAN_EID_LINK_ID;
2640 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2641
2642 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2643 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2644 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2645}
2646
2647static int
2648ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2649 u8 *peer, u8 action_code, u8 dialog_token,
2650 u16 status_code, struct sk_buff *skb)
2651{
2652 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2653 struct ieee80211_tdls_data *tf;
2654
2655 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2656
2657 memcpy(tf->da, peer, ETH_ALEN);
2658 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2659 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2660 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2661
2662 switch (action_code) {
2663 case WLAN_TDLS_SETUP_REQUEST:
2664 tf->category = WLAN_CATEGORY_TDLS;
2665 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2666
2667 skb_put(skb, sizeof(tf->u.setup_req));
2668 tf->u.setup_req.dialog_token = dialog_token;
2669 tf->u.setup_req.capability =
2670 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2671
Johannes Bergfc8a7322012-06-28 10:33:25 +02002672 ieee80211_add_srates_ie(sdata, skb, false);
2673 ieee80211_add_ext_srates_ie(sdata, skb, false);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002674 ieee80211_tdls_add_ext_capab(skb);
2675 break;
2676 case WLAN_TDLS_SETUP_RESPONSE:
2677 tf->category = WLAN_CATEGORY_TDLS;
2678 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2679
2680 skb_put(skb, sizeof(tf->u.setup_resp));
2681 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2682 tf->u.setup_resp.dialog_token = dialog_token;
2683 tf->u.setup_resp.capability =
2684 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2685
Johannes Bergfc8a7322012-06-28 10:33:25 +02002686 ieee80211_add_srates_ie(sdata, skb, false);
2687 ieee80211_add_ext_srates_ie(sdata, skb, false);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002688 ieee80211_tdls_add_ext_capab(skb);
2689 break;
2690 case WLAN_TDLS_SETUP_CONFIRM:
2691 tf->category = WLAN_CATEGORY_TDLS;
2692 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2693
2694 skb_put(skb, sizeof(tf->u.setup_cfm));
2695 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2696 tf->u.setup_cfm.dialog_token = dialog_token;
2697 break;
2698 case WLAN_TDLS_TEARDOWN:
2699 tf->category = WLAN_CATEGORY_TDLS;
2700 tf->action_code = WLAN_TDLS_TEARDOWN;
2701
2702 skb_put(skb, sizeof(tf->u.teardown));
2703 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2704 break;
2705 case WLAN_TDLS_DISCOVERY_REQUEST:
2706 tf->category = WLAN_CATEGORY_TDLS;
2707 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2708
2709 skb_put(skb, sizeof(tf->u.discover_req));
2710 tf->u.discover_req.dialog_token = dialog_token;
2711 break;
2712 default:
2713 return -EINVAL;
2714 }
2715
2716 return 0;
2717}
2718
2719static int
2720ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2721 u8 *peer, u8 action_code, u8 dialog_token,
2722 u16 status_code, struct sk_buff *skb)
2723{
2724 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2725 struct ieee80211_mgmt *mgmt;
2726
2727 mgmt = (void *)skb_put(skb, 24);
2728 memset(mgmt, 0, 24);
2729 memcpy(mgmt->da, peer, ETH_ALEN);
2730 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2731 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2732
2733 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2734 IEEE80211_STYPE_ACTION);
2735
2736 switch (action_code) {
2737 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2738 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2739 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2740 mgmt->u.action.u.tdls_discover_resp.action_code =
2741 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2742 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2743 dialog_token;
2744 mgmt->u.action.u.tdls_discover_resp.capability =
2745 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2746
Johannes Bergfc8a7322012-06-28 10:33:25 +02002747 ieee80211_add_srates_ie(sdata, skb, false);
2748 ieee80211_add_ext_srates_ie(sdata, skb, false);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002749 ieee80211_tdls_add_ext_capab(skb);
2750 break;
2751 default:
2752 return -EINVAL;
2753 }
2754
2755 return 0;
2756}
2757
2758static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2759 u8 *peer, u8 action_code, u8 dialog_token,
2760 u16 status_code, const u8 *extra_ies,
2761 size_t extra_ies_len)
2762{
2763 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2764 struct ieee80211_local *local = sdata->local;
2765 struct ieee80211_tx_info *info;
2766 struct sk_buff *skb = NULL;
2767 bool send_direct;
2768 int ret;
2769
2770 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2771 return -ENOTSUPP;
2772
2773 /* make sure we are in managed mode, and associated */
2774 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2775 !sdata->u.mgd.associated)
2776 return -EINVAL;
2777
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002778 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
2779 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002780
2781 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2782 max(sizeof(struct ieee80211_mgmt),
2783 sizeof(struct ieee80211_tdls_data)) +
2784 50 + /* supported rates */
2785 7 + /* ext capab */
2786 extra_ies_len +
2787 sizeof(struct ieee80211_tdls_lnkie));
2788 if (!skb)
2789 return -ENOMEM;
2790
2791 info = IEEE80211_SKB_CB(skb);
2792 skb_reserve(skb, local->hw.extra_tx_headroom);
2793
2794 switch (action_code) {
2795 case WLAN_TDLS_SETUP_REQUEST:
2796 case WLAN_TDLS_SETUP_RESPONSE:
2797 case WLAN_TDLS_SETUP_CONFIRM:
2798 case WLAN_TDLS_TEARDOWN:
2799 case WLAN_TDLS_DISCOVERY_REQUEST:
2800 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2801 action_code, dialog_token,
2802 status_code, skb);
2803 send_direct = false;
2804 break;
2805 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2806 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2807 dialog_token, status_code,
2808 skb);
2809 send_direct = true;
2810 break;
2811 default:
2812 ret = -ENOTSUPP;
2813 break;
2814 }
2815
2816 if (ret < 0)
2817 goto fail;
2818
2819 if (extra_ies_len)
2820 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2821
2822 /* the TDLS link IE is always added last */
2823 switch (action_code) {
2824 case WLAN_TDLS_SETUP_REQUEST:
2825 case WLAN_TDLS_SETUP_CONFIRM:
2826 case WLAN_TDLS_TEARDOWN:
2827 case WLAN_TDLS_DISCOVERY_REQUEST:
2828 /* we are the initiator */
2829 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2830 sdata->u.mgd.bssid);
2831 break;
2832 case WLAN_TDLS_SETUP_RESPONSE:
2833 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2834 /* we are the responder */
2835 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2836 sdata->u.mgd.bssid);
2837 break;
2838 default:
2839 ret = -ENOTSUPP;
2840 goto fail;
2841 }
2842
2843 if (send_direct) {
2844 ieee80211_tx_skb(sdata, skb);
2845 return 0;
2846 }
2847
2848 /*
2849 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2850 * we should default to AC_VI.
2851 */
2852 switch (action_code) {
2853 case WLAN_TDLS_SETUP_REQUEST:
2854 case WLAN_TDLS_SETUP_RESPONSE:
2855 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2856 skb->priority = 2;
2857 break;
2858 default:
2859 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2860 skb->priority = 5;
2861 break;
2862 }
2863
2864 /* disable bottom halves when entering the Tx path */
2865 local_bh_disable();
2866 ret = ieee80211_subif_start_xmit(skb, dev);
2867 local_bh_enable();
2868
2869 return ret;
2870
2871fail:
2872 dev_kfree_skb(skb);
2873 return ret;
2874}
2875
2876static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2877 u8 *peer, enum nl80211_tdls_operation oper)
2878{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002879 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002880 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2881
2882 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2883 return -ENOTSUPP;
2884
2885 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2886 return -EINVAL;
2887
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002888 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002889
2890 switch (oper) {
2891 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002892 rcu_read_lock();
2893 sta = sta_info_get(sdata, peer);
2894 if (!sta) {
2895 rcu_read_unlock();
2896 return -ENOLINK;
2897 }
2898
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002899 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002900 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002901 break;
2902 case NL80211_TDLS_DISABLE_LINK:
2903 return sta_info_destroy_addr(sdata, peer);
2904 case NL80211_TDLS_TEARDOWN:
2905 case NL80211_TDLS_SETUP:
2906 case NL80211_TDLS_DISCOVERY_REQ:
2907 /* We don't support in-driver setup/teardown/discovery */
2908 return -ENOTSUPP;
2909 default:
2910 return -ENOTSUPP;
2911 }
2912
2913 return 0;
2914}
2915
Johannes Berg06500732011-11-04 11:18:16 +01002916static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2917 const u8 *peer, u64 *cookie)
2918{
2919 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2920 struct ieee80211_local *local = sdata->local;
2921 struct ieee80211_qos_hdr *nullfunc;
2922 struct sk_buff *skb;
2923 int size = sizeof(*nullfunc);
2924 __le16 fc;
2925 bool qos;
2926 struct ieee80211_tx_info *info;
2927 struct sta_info *sta;
2928
2929 rcu_read_lock();
2930 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01002931 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01002932 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01002933 rcu_read_unlock();
2934 } else {
2935 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01002936 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01002937 }
Johannes Berg06500732011-11-04 11:18:16 +01002938
2939 if (qos) {
2940 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2941 IEEE80211_STYPE_QOS_NULLFUNC |
2942 IEEE80211_FCTL_FROMDS);
2943 } else {
2944 size -= 2;
2945 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2946 IEEE80211_STYPE_NULLFUNC |
2947 IEEE80211_FCTL_FROMDS);
2948 }
2949
2950 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2951 if (!skb)
2952 return -ENOMEM;
2953
2954 skb->dev = dev;
2955
2956 skb_reserve(skb, local->hw.extra_tx_headroom);
2957
2958 nullfunc = (void *) skb_put(skb, size);
2959 nullfunc->frame_control = fc;
2960 nullfunc->duration_id = 0;
2961 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2962 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2963 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2964 nullfunc->seq_ctrl = 0;
2965
2966 info = IEEE80211_SKB_CB(skb);
2967
2968 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2969 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2970
2971 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2972 skb->priority = 7;
2973 if (qos)
2974 nullfunc->qos_ctrl = cpu_to_le16(7);
2975
2976 local_bh_disable();
2977 ieee80211_xmit(sdata, skb);
2978 local_bh_enable();
2979
2980 *cookie = (unsigned long) skb;
2981 return 0;
2982}
2983
Michal Kazior870d37f2012-06-29 12:47:02 +02002984static void ieee80211_set_monitor_enabled(struct wiphy *wiphy, bool enabled)
2985{
2986 struct ieee80211_local *local = wiphy_priv(wiphy);
2987
2988 if (enabled)
2989 WARN_ON(ieee80211_add_virtual_monitor(local));
2990 else
2991 ieee80211_del_virtual_monitor(local);
2992}
2993
Johannes Berg6d525632012-04-04 15:05:25 +02002994#ifdef CONFIG_PM
2995static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
2996{
2997 drv_set_wakeup(wiphy_priv(wiphy), enabled);
2998}
2999#endif
3000
Jiri Bencf0706e82007-05-05 11:45:53 -07003001struct cfg80211_ops mac80211_config_ops = {
3002 .add_virtual_intf = ieee80211_add_iface,
3003 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003004 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003005 .add_key = ieee80211_add_key,
3006 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003007 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003008 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003009 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003010 .start_ap = ieee80211_start_ap,
3011 .change_beacon = ieee80211_change_beacon,
3012 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003013 .add_station = ieee80211_add_station,
3014 .del_station = ieee80211_del_station,
3015 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003016 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003017 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003018 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003019#ifdef CONFIG_MAC80211_MESH
3020 .add_mpath = ieee80211_add_mpath,
3021 .del_mpath = ieee80211_del_mpath,
3022 .change_mpath = ieee80211_change_mpath,
3023 .get_mpath = ieee80211_get_mpath,
3024 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003025 .update_mesh_config = ieee80211_update_mesh_config,
3026 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003027 .join_mesh = ieee80211_join_mesh,
3028 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003029#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003030 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003031 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003032 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003033 .suspend = ieee80211_suspend,
3034 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003035 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003036 .sched_scan_start = ieee80211_sched_scan_start,
3037 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003038 .auth = ieee80211_auth,
3039 .assoc = ieee80211_assoc,
3040 .deauth = ieee80211_deauth,
3041 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003042 .join_ibss = ieee80211_join_ibss,
3043 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003044 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003045 .set_tx_power = ieee80211_set_tx_power,
3046 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003047 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003048 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003049 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003050 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003051 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003052 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003053 .remain_on_channel = ieee80211_remain_on_channel,
3054 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003055 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003056 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003057 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003058 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003059 .set_antenna = ieee80211_set_antenna,
3060 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003061 .set_ringparam = ieee80211_set_ringparam,
3062 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003063 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003064 .tdls_oper = ieee80211_tdls_oper,
3065 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003066 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003067 .set_noack_map = ieee80211_set_noack_map,
Michal Kazior870d37f2012-06-29 12:47:02 +02003068 .set_monitor_enabled = ieee80211_set_monitor_enabled,
Johannes Berg6d525632012-04-04 15:05:25 +02003069#ifdef CONFIG_PM
3070 .set_wakeup = ieee80211_set_wakeup,
3071#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003072 .get_et_sset_count = ieee80211_get_et_sset_count,
3073 .get_et_stats = ieee80211_get_et_stats,
3074 .get_et_strings = ieee80211_get_et_strings,
Jiri Bencf0706e82007-05-05 11:45:53 -07003075};