blob: 03fe6d1cff4214b0d9dde329a831ecb172ba3e42 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Jouni Malinen026331c2010-02-15 12:53:10 +02004 * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
Jiri Bencf0706e82007-05-05 11:45:53 -07005 *
6 * This file is GPLv2 as found in COPYING.
7 */
8
Johannes Berge8cbb4c2007-12-19 02:03:30 +01009#include <linux/ieee80211.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070010#include <linux/nl80211.h>
11#include <linux/rtnetlink.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Eric W. Biederman881d9662007-09-17 11:56:21 -070013#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010014#include <linux/rcupdate.h>
Arik Nemtsovdfe018b2011-09-28 14:12:52 +030015#include <linux/if_ether.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070016#include <net/cfg80211.h>
17#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020018#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040019#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040020#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010022
Johannes Berg84efbb82012-06-16 00:00:26 +020023static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070027{
28 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg84efbb82012-06-16 00:00:26 +020029 struct wireless_dev *wdev;
Michael Wu8cc9a732008-01-31 19:48:23 +010030 struct ieee80211_sub_if_data *sdata;
31 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070032
Johannes Berg84efbb82012-06-16 00:00:26 +020033 err = ieee80211_if_add(local, name, &wdev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010034 if (err)
35 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010036
Johannes Bergf9e10ce2010-12-03 09:20:42 +010037 if (type == NL80211_IFTYPE_MONITOR && flags) {
Johannes Berg84efbb82012-06-16 00:00:26 +020038 sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010039 sdata->u.mntr_flags = *flags;
40 }
41
Johannes Berg84efbb82012-06-16 00:00:26 +020042 return wdev;
Jiri Bencf0706e82007-05-05 11:45:53 -070043}
44
Johannes Berg84efbb82012-06-16 00:00:26 +020045static int ieee80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
Jiri Bencf0706e82007-05-05 11:45:53 -070046{
Johannes Berg84efbb82012-06-16 00:00:26 +020047 ieee80211_if_remove(IEEE80211_WDEV_TO_SUB_IF(wdev));
Jiri Bencf0706e82007-05-05 11:45:53 -070048
Johannes Berg75636522008-07-09 14:40:35 +020049 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070050}
51
Johannes Berge36d56b2009-06-09 21:04:43 +020052static int ieee80211_change_iface(struct wiphy *wiphy,
53 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010054 enum nl80211_iftype type, u32 *flags,
55 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020056{
Johannes Berg9607e6b2009-12-23 13:15:31 +010057 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020058 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020059
Johannes Berg05c914f2008-09-11 00:01:58 +020060 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020061 if (ret)
62 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020063
Johannes Berg9bc383d2009-11-19 11:55:19 +010064 if (type == NL80211_IFTYPE_AP_VLAN &&
65 params && params->use_4addr == 0)
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +000066 RCU_INIT_POINTER(sdata->u.vlan.sta, NULL);
Johannes Berg9bc383d2009-11-19 11:55:19 +010067 else if (type == NL80211_IFTYPE_STATION &&
68 params && params->use_4addr >= 0)
69 sdata->u.mgd.use_4addr = params->use_4addr;
70
Christian Lamparter85416a42010-10-02 13:17:07 +020071 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
72 struct ieee80211_local *local = sdata->local;
73
74 if (ieee80211_sdata_running(sdata)) {
75 /*
76 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
77 * changed while the interface is up.
78 * Else we would need to add a lot of cruft
79 * to update everything:
80 * cooked_mntrs, monitor and all fif_* counters
81 * reconfigure hardware
82 */
83 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
84 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
85 return -EBUSY;
86
87 ieee80211_adjust_monitor_flags(sdata, -1);
88 sdata->u.mntr_flags = *flags;
89 ieee80211_adjust_monitor_flags(sdata, 1);
90
91 ieee80211_configure_filter(local);
92 } else {
93 /*
94 * Because the interface is down, ieee80211_do_stop
95 * and ieee80211_do_open take care of "everything"
96 * mentioned in the comment above.
97 */
98 sdata->u.mntr_flags = *flags;
99 }
100 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200101
Johannes Berg42613db2007-09-28 21:52:27 +0200102 return 0;
103}
104
Johannes Bergf142c6b2012-06-18 20:07:15 +0200105static int ieee80211_start_p2p_device(struct wiphy *wiphy,
106 struct wireless_dev *wdev)
107{
108 return ieee80211_do_open(wdev, true);
109}
110
111static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
112 struct wireless_dev *wdev)
113{
114 ieee80211_sdata_stop(IEEE80211_WDEV_TO_SUB_IF(wdev));
115}
116
Simon Wunderlichb53be792011-11-18 14:20:44 +0100117static int ieee80211_set_noack_map(struct wiphy *wiphy,
118 struct net_device *dev,
119 u16 noack_map)
120{
121 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
122
123 sdata->noack_map = noack_map;
124 return 0;
125}
126
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100127static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200128 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100129 struct key_params *params)
130{
Johannes Berg26a58452010-08-27 12:35:55 +0200131 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100132 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100133 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200134 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100135
Johannes Berg26a58452010-08-27 12:35:55 +0200136 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200137 return -ENETDOWN;
138
Johannes Berg97359d12010-08-10 09:46:38 +0200139 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100140 switch (params->cipher) {
141 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100142 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200143 case WLAN_CIPHER_SUITE_WEP104:
144 if (IS_ERR(sdata->local->wep_tx_tfm))
145 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200146 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100147 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200148 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100149 }
150
Johannes Berg97359d12010-08-10 09:46:38 +0200151 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
152 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100153 if (IS_ERR(key))
154 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100155
Johannes Berge31b8212010-10-05 19:39:30 +0200156 if (pairwise)
157 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
158
Johannes Bergad0e2b52010-06-01 10:19:19 +0200159 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200160
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100161 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700162 if (ieee80211_vif_is_mesh(&sdata->vif))
163 sta = sta_info_get(sdata, mac_addr);
164 else
165 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100166 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700167 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200168 err = -ENOENT;
169 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100170 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100171 }
172
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300173 err = ieee80211_key_link(key, sdata, sta);
174 if (err)
175 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100176
Johannes Berg3b967662008-04-08 17:56:52 +0200177 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200178 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200179
180 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100181}
182
183static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200184 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100185{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200186 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
187 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100188 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200189 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100190 int ret;
191
Johannes Berg5c0c3642011-05-12 14:31:49 +0200192 mutex_lock(&local->sta_mtx);
193 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200194
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100195 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200196 ret = -ENOENT;
197
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100198 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100199 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200200 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100201
Johannes Berg5c0c3642011-05-12 14:31:49 +0200202 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200203 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200204 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200205 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200206 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200207 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100208
Johannes Berg5c0c3642011-05-12 14:31:49 +0200209 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200210 ret = -ENOENT;
211 goto out_unlock;
212 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100213
Johannes Berg5c0c3642011-05-12 14:31:49 +0200214 __ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100215
Johannes Berg3b967662008-04-08 17:56:52 +0200216 ret = 0;
217 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200218 mutex_unlock(&local->key_mtx);
219 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200220
221 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100222}
223
Johannes Berg62da92f2007-12-19 02:03:31 +0100224static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200225 u8 key_idx, bool pairwise, const u8 *mac_addr,
226 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100227 void (*callback)(void *cookie,
228 struct key_params *params))
229{
Johannes Berg14db74b2008-07-29 13:22:52 +0200230 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100231 struct sta_info *sta = NULL;
232 u8 seq[6] = {0};
233 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200234 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200235 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100236 u32 iv32;
237 u16 iv16;
238 int err = -ENOENT;
239
Johannes Berg14db74b2008-07-29 13:22:52 +0200240 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
241
Johannes Berg3b967662008-04-08 17:56:52 +0200242 rcu_read_lock();
243
Johannes Berg62da92f2007-12-19 02:03:31 +0100244 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100245 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100246 if (!sta)
247 goto out;
248
Johannes Berge31b8212010-10-05 19:39:30 +0200249 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200250 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200251 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200252 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100253 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200254 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100255
256 if (!key)
257 goto out;
258
259 memset(&params, 0, sizeof(params));
260
Johannes Berg97359d12010-08-10 09:46:38 +0200261 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100262
Johannes Berg97359d12010-08-10 09:46:38 +0200263 switch (key->conf.cipher) {
264 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700265 iv32 = key->u.tkip.tx.iv32;
266 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100267
Johannes Berg24487982009-04-23 18:52:52 +0200268 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
269 drv_get_tkip_seq(sdata->local,
270 key->conf.hw_key_idx,
271 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100272
273 seq[0] = iv16 & 0xff;
274 seq[1] = (iv16 >> 8) & 0xff;
275 seq[2] = iv32 & 0xff;
276 seq[3] = (iv32 >> 8) & 0xff;
277 seq[4] = (iv32 >> 16) & 0xff;
278 seq[5] = (iv32 >> 24) & 0xff;
279 params.seq = seq;
280 params.seq_len = 6;
281 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200282 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200283 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
284 seq[0] = pn64;
285 seq[1] = pn64 >> 8;
286 seq[2] = pn64 >> 16;
287 seq[3] = pn64 >> 24;
288 seq[4] = pn64 >> 32;
289 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100290 params.seq = seq;
291 params.seq_len = 6;
292 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200293 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200294 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
295 seq[0] = pn64;
296 seq[1] = pn64 >> 8;
297 seq[2] = pn64 >> 16;
298 seq[3] = pn64 >> 24;
299 seq[4] = pn64 >> 32;
300 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200301 params.seq = seq;
302 params.seq_len = 6;
303 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100304 }
305
306 params.key = key->conf.key;
307 params.key_len = key->conf.keylen;
308
309 callback(cookie, &params);
310 err = 0;
311
312 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200313 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100314 return err;
315}
316
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100317static int ieee80211_config_default_key(struct wiphy *wiphy,
318 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100319 u8 key_idx, bool uni,
320 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100321{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200322 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100323
Johannes Bergf7e01042010-12-09 19:49:02 +0100324 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100325
326 return 0;
327}
328
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200329static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
330 struct net_device *dev,
331 u8 key_idx)
332{
Johannes Berg66c52422010-07-22 13:58:51 +0200333 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200334
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200335 ieee80211_set_default_mgmt_key(sdata, key_idx);
336
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200337 return 0;
338}
339
Felix Fietkau3af63342011-02-27 22:08:01 +0100340static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
341{
342 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
343 struct ieee80211_supported_band *sband;
344 sband = sta->local->hw.wiphy->bands[
Johannes Berg679ef4e2012-07-23 14:29:21 +0200345 sta->local->oper_channel->band];
Felix Fietkau3af63342011-02-27 22:08:01 +0100346 rate->legacy = sband->bitrates[idx].bitrate;
347 } else
348 rate->mcs = idx;
349}
350
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800351void sta_set_rate_info_tx(struct sta_info *sta,
352 const struct ieee80211_tx_rate *rate,
353 struct rate_info *rinfo)
354{
355 rinfo->flags = 0;
356 if (rate->flags & IEEE80211_TX_RC_MCS)
357 rinfo->flags |= RATE_INFO_FLAGS_MCS;
358 if (rate->flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
359 rinfo->flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
360 if (rate->flags & IEEE80211_TX_RC_SHORT_GI)
361 rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
362 rate_idx_to_bitrate(rinfo, sta, rate->idx);
363}
364
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100365static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
366{
Johannes Bergd0709a62008-02-25 16:27:46 +0100367 struct ieee80211_sub_if_data *sdata = sta->sdata;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300368 struct ieee80211_local *local = sdata->local;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530369 struct timespec uptime;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100370
Johannes Bergf5ea9122009-08-07 16:17:38 +0200371 sinfo->generation = sdata->local->sta_generation;
372
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100373 sinfo->filled = STATION_INFO_INACTIVE_TIME |
374 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100375 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200376 STATION_INFO_RX_PACKETS |
377 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900378 STATION_INFO_TX_RETRIES |
379 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700380 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100381 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700382 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530383 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200384 STATION_INFO_CONNECTED_TIME |
Paul Stewarta85e1d52011-12-09 11:01:49 -0800385 STATION_INFO_STA_FLAGS |
386 STATION_INFO_BEACON_LOSS_COUNT;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530387
388 do_posix_clock_monotonic_gettime(&uptime);
389 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100390
391 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
392 sinfo->rx_bytes = sta->rx_bytes;
393 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200394 sinfo->rx_packets = sta->rx_packets;
395 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900396 sinfo->tx_retries = sta->tx_retry_count;
397 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700398 sinfo->rx_dropped_misc = sta->rx_dropped;
Paul Stewarta85e1d52011-12-09 11:01:49 -0800399 sinfo->beacon_loss_count = sta->beacon_loss_count;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100400
John W. Linville19deffb2009-12-08 17:10:13 -0500401 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
402 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900403 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300404 if (!local->ops->get_rssi ||
405 drv_get_rssi(local, sdata, &sta->sta, &sinfo->signal))
406 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900407 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100408 }
409
Thomas Pedersen6b62bf32012-03-05 15:31:48 -0800410 sta_set_rate_info_tx(sta, &sta->last_tx_rate, &sinfo->txrate);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100411
Felix Fietkau3af63342011-02-27 22:08:01 +0100412 sinfo->rxrate.flags = 0;
413 if (sta->last_rx_rate_flag & RX_FLAG_HT)
414 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
415 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
416 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
417 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
418 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
419 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100420
Johannes Berg902acc72008-02-23 15:17:19 +0100421 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100422#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100423 sinfo->filled |= STATION_INFO_LLID |
424 STATION_INFO_PLID |
425 STATION_INFO_PLINK_STATE;
426
427 sinfo->llid = le16_to_cpu(sta->llid);
428 sinfo->plid = le16_to_cpu(sta->plid);
429 sinfo->plink_state = sta->plink_state;
Javier Cardonad299a1f2012-03-31 11:31:33 -0700430 if (test_sta_flag(sta, WLAN_STA_TOFFSET_KNOWN)) {
431 sinfo->filled |= STATION_INFO_T_OFFSET;
432 sinfo->t_offset = sta->t_offset;
433 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100434#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100435 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700436
437 sinfo->bss_param.flags = 0;
438 if (sdata->vif.bss_conf.use_cts_prot)
439 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
440 if (sdata->vif.bss_conf.use_short_preamble)
441 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
442 if (sdata->vif.bss_conf.use_short_slot)
443 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
444 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
445 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200446
447 sinfo->sta_flags.set = 0;
448 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
449 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
450 BIT(NL80211_STA_FLAG_WME) |
451 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100452 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
453 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200454 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
455 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
456 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
457 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
458 if (test_sta_flag(sta, WLAN_STA_WME))
459 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
460 if (test_sta_flag(sta, WLAN_STA_MFP))
461 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
462 if (test_sta_flag(sta, WLAN_STA_AUTH))
463 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100464 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
465 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100466}
467
Ben Greearb1ab7922012-04-23 12:50:30 -0700468static const char ieee80211_gstrings_sta_stats[][ETH_GSTRING_LEN] = {
469 "rx_packets", "rx_bytes", "wep_weak_iv_count",
470 "rx_duplicates", "rx_fragments", "rx_dropped",
471 "tx_packets", "tx_bytes", "tx_fragments",
472 "tx_filtered", "tx_retry_failed", "tx_retries",
Ben Greear3073a7c2012-04-23 12:50:32 -0700473 "beacon_loss", "sta_state", "txrate", "rxrate", "signal",
474 "channel", "noise", "ch_time", "ch_time_busy",
475 "ch_time_ext_busy", "ch_time_rx", "ch_time_tx"
Ben Greearb1ab7922012-04-23 12:50:30 -0700476};
477#define STA_STATS_LEN ARRAY_SIZE(ieee80211_gstrings_sta_stats)
478
479static int ieee80211_get_et_sset_count(struct wiphy *wiphy,
480 struct net_device *dev,
481 int sset)
482{
Ben Greeare3521142012-04-23 12:50:31 -0700483 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
484 int rv = 0;
Ben Greearb1ab7922012-04-23 12:50:30 -0700485
Ben Greeare3521142012-04-23 12:50:31 -0700486 if (sset == ETH_SS_STATS)
487 rv += STA_STATS_LEN;
488
489 rv += drv_get_et_sset_count(sdata, sset);
490
491 if (rv == 0)
492 return -EOPNOTSUPP;
493 return rv;
Ben Greearb1ab7922012-04-23 12:50:30 -0700494}
495
496static void ieee80211_get_et_stats(struct wiphy *wiphy,
497 struct net_device *dev,
498 struct ethtool_stats *stats,
499 u64 *data)
500{
501 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
502 struct sta_info *sta;
503 struct ieee80211_local *local = sdata->local;
Ben Greear3073a7c2012-04-23 12:50:32 -0700504 struct station_info sinfo;
505 struct survey_info survey;
506 int i, q;
507#define STA_STATS_SURVEY_LEN 7
Ben Greearb1ab7922012-04-23 12:50:30 -0700508
509 memset(data, 0, sizeof(u64) * STA_STATS_LEN);
510
511#define ADD_STA_STATS(sta) \
512 do { \
513 data[i++] += sta->rx_packets; \
514 data[i++] += sta->rx_bytes; \
515 data[i++] += sta->wep_weak_iv_count; \
516 data[i++] += sta->num_duplicates; \
517 data[i++] += sta->rx_fragments; \
518 data[i++] += sta->rx_dropped; \
519 \
520 data[i++] += sta->tx_packets; \
521 data[i++] += sta->tx_bytes; \
522 data[i++] += sta->tx_fragments; \
523 data[i++] += sta->tx_filtered_count; \
524 data[i++] += sta->tx_retry_failed; \
525 data[i++] += sta->tx_retry_count; \
526 data[i++] += sta->beacon_loss_count; \
527 } while (0)
528
529 /* For Managed stations, find the single station based on BSSID
530 * and use that. For interface types, iterate through all available
531 * stations and add stats for any station that is assigned to this
532 * network device.
533 */
534
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300535 mutex_lock(&local->sta_mtx);
Ben Greearb1ab7922012-04-23 12:50:30 -0700536
537 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
538 sta = sta_info_get_bss(sdata, sdata->u.mgd.bssid);
Ben Greear3073a7c2012-04-23 12:50:32 -0700539
540 if (!(sta && !WARN_ON(sta->sdata->dev != dev)))
541 goto do_survey;
542
543 i = 0;
544 ADD_STA_STATS(sta);
545
546 data[i++] = sta->sta_state;
547
548 sinfo.filled = 0;
549 sta_set_sinfo(sta, &sinfo);
550
Joe Perches52042672012-05-30 13:25:54 -0700551 if (sinfo.filled & STATION_INFO_TX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700552 data[i] = 100000 *
553 cfg80211_calculate_bitrate(&sinfo.txrate);
554 i++;
Joe Perches52042672012-05-30 13:25:54 -0700555 if (sinfo.filled & STATION_INFO_RX_BITRATE)
Ben Greear3073a7c2012-04-23 12:50:32 -0700556 data[i] = 100000 *
557 cfg80211_calculate_bitrate(&sinfo.rxrate);
558 i++;
559
Joe Perches52042672012-05-30 13:25:54 -0700560 if (sinfo.filled & STATION_INFO_SIGNAL_AVG)
Ben Greear3073a7c2012-04-23 12:50:32 -0700561 data[i] = (u8)sinfo.signal_avg;
562 i++;
Ben Greearb1ab7922012-04-23 12:50:30 -0700563 } else {
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300564 list_for_each_entry(sta, &local->sta_list, list) {
Ben Greearb1ab7922012-04-23 12:50:30 -0700565 /* Make sure this station belongs to the proper dev */
566 if (sta->sdata->dev != dev)
567 continue;
568
569 i = 0;
570 ADD_STA_STATS(sta);
Ben Greearb1ab7922012-04-23 12:50:30 -0700571 }
572 }
573
Ben Greear3073a7c2012-04-23 12:50:32 -0700574do_survey:
575 i = STA_STATS_LEN - STA_STATS_SURVEY_LEN;
576 /* Get survey stats for current channel */
577 q = 0;
578 while (true) {
579 survey.filled = 0;
580 if (drv_get_survey(local, q, &survey) != 0) {
581 survey.filled = 0;
582 break;
583 }
584
585 if (survey.channel &&
586 (local->oper_channel->center_freq ==
587 survey.channel->center_freq))
588 break;
589 q++;
590 }
591
592 if (survey.filled)
593 data[i++] = survey.channel->center_freq;
594 else
595 data[i++] = 0;
596 if (survey.filled & SURVEY_INFO_NOISE_DBM)
597 data[i++] = (u8)survey.noise;
598 else
599 data[i++] = -1LL;
600 if (survey.filled & SURVEY_INFO_CHANNEL_TIME)
601 data[i++] = survey.channel_time;
602 else
603 data[i++] = -1LL;
604 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_BUSY)
605 data[i++] = survey.channel_time_busy;
606 else
607 data[i++] = -1LL;
608 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_EXT_BUSY)
609 data[i++] = survey.channel_time_ext_busy;
610 else
611 data[i++] = -1LL;
612 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_RX)
613 data[i++] = survey.channel_time_rx;
614 else
615 data[i++] = -1LL;
616 if (survey.filled & SURVEY_INFO_CHANNEL_TIME_TX)
617 data[i++] = survey.channel_time_tx;
618 else
619 data[i++] = -1LL;
620
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300621 mutex_unlock(&local->sta_mtx);
Ben Greeare3521142012-04-23 12:50:31 -0700622
Ben Greear3073a7c2012-04-23 12:50:32 -0700623 if (WARN_ON(i != STA_STATS_LEN))
624 return;
625
Ben Greeare3521142012-04-23 12:50:31 -0700626 drv_get_et_stats(sdata, stats, &(data[STA_STATS_LEN]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700627}
628
629static void ieee80211_get_et_strings(struct wiphy *wiphy,
630 struct net_device *dev,
631 u32 sset, u8 *data)
632{
Ben Greeare3521142012-04-23 12:50:31 -0700633 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
634 int sz_sta_stats = 0;
635
Ben Greearb1ab7922012-04-23 12:50:30 -0700636 if (sset == ETH_SS_STATS) {
Ben Greeare3521142012-04-23 12:50:31 -0700637 sz_sta_stats = sizeof(ieee80211_gstrings_sta_stats);
Ben Greearb1ab7922012-04-23 12:50:30 -0700638 memcpy(data, *ieee80211_gstrings_sta_stats, sz_sta_stats);
639 }
Ben Greeare3521142012-04-23 12:50:31 -0700640 drv_get_et_strings(sdata, sset, &(data[sz_sta_stats]));
Ben Greearb1ab7922012-04-23 12:50:30 -0700641}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100642
643static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
644 int idx, u8 *mac, struct station_info *sinfo)
645{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100646 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300647 struct ieee80211_local *local = sdata->local;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100648 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100649 int ret = -ENOENT;
650
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300651 mutex_lock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100652
Johannes Berg3b53fde82009-11-16 12:00:37 +0100653 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100654 if (sta) {
655 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200656 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100657 sta_set_sinfo(sta, sinfo);
658 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100659
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300660 mutex_unlock(&local->sta_mtx);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100661
Johannes Bergd0709a62008-02-25 16:27:46 +0100662 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100663}
664
Holger Schurig12897232010-04-19 10:23:57 +0200665static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
666 int idx, struct survey_info *survey)
667{
668 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
669
Holger Schurig12897232010-04-19 10:23:57 +0200670 return drv_get_survey(local, idx, survey);
671}
672
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100673static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100674 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100675{
Johannes Bergabe60632009-11-25 17:46:18 +0100676 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300677 struct ieee80211_local *local = sdata->local;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100678 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100679 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100680
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300681 mutex_lock(&local->sta_mtx);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100682
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100683 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100684 if (sta) {
685 ret = 0;
686 sta_set_sinfo(sta, sinfo);
687 }
688
Victor Goldenshtein66572cf2012-06-21 10:56:46 +0300689 mutex_unlock(&local->sta_mtx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100690
691 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100692}
693
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200694static int ieee80211_set_channel(struct wiphy *wiphy,
695 struct net_device *netdev,
696 struct ieee80211_channel *chan,
697 enum nl80211_channel_type channel_type)
698{
699 struct ieee80211_local *local = wiphy_priv(wiphy);
700 struct ieee80211_sub_if_data *sdata = NULL;
701
702 if (netdev)
703 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
704
705 switch (ieee80211_get_channel_mode(local, NULL)) {
706 case CHAN_MODE_HOPPING:
707 return -EBUSY;
708 case CHAN_MODE_FIXED:
Pontus Fuchsac4d82f2012-06-12 14:13:19 +0200709 if (local->oper_channel != chan ||
710 (!sdata && local->_oper_channel_type != channel_type))
Johannes Berg3d9e6e12012-05-16 23:50:16 +0200711 return -EBUSY;
712 if (!sdata && local->_oper_channel_type == channel_type)
713 return 0;
714 break;
715 case CHAN_MODE_UNDEFINED:
716 break;
717 }
718
719 if (!ieee80211_set_channel_type(local, sdata, channel_type))
720 return -EBUSY;
721
722 local->oper_channel = chan;
723
724 /* auto-detects changes */
725 ieee80211_hw_config(local, 0);
726
727 return 0;
728}
729
Johannes Berge8c9bd52012-06-06 08:18:22 +0200730static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
731 struct ieee80211_channel *chan,
732 enum nl80211_channel_type channel_type)
733{
734 return ieee80211_set_channel(wiphy, NULL, chan, channel_type);
735}
736
Arik Nemtsov02945822011-11-10 11:28:57 +0200737static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
Johannes Berg88600202012-02-13 15:17:18 +0100738 const u8 *resp, size_t resp_len)
Arik Nemtsov02945822011-11-10 11:28:57 +0200739{
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300740 struct probe_resp *new, *old;
Arik Nemtsov02945822011-11-10 11:28:57 +0200741
742 if (!resp || !resp_len)
Sujith Manoharanaba4e6f2012-08-22 14:21:07 +0530743 return 1;
Arik Nemtsov02945822011-11-10 11:28:57 +0200744
Arik Nemtsovf7248282011-11-19 10:51:26 +0200745 old = rtnl_dereference(sdata->u.ap.probe_resp);
Arik Nemtsov02945822011-11-10 11:28:57 +0200746
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300747 new = kzalloc(sizeof(struct probe_resp) + resp_len, GFP_KERNEL);
Arik Nemtsov02945822011-11-10 11:28:57 +0200748 if (!new)
749 return -ENOMEM;
750
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300751 new->len = resp_len;
752 memcpy(new->data, resp, resp_len);
Arik Nemtsov02945822011-11-10 11:28:57 +0200753
754 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
Eyal Shapiraaa7a0082012-08-06 14:26:16 +0300755 if (old)
756 kfree_rcu(old, rcu_head);
Arik Nemtsov02945822011-11-10 11:28:57 +0200757
758 return 0;
759}
760
Johannes Berg88600202012-02-13 15:17:18 +0100761static int ieee80211_assign_beacon(struct ieee80211_sub_if_data *sdata,
762 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100763{
764 struct beacon_data *new, *old;
765 int new_head_len, new_tail_len;
Johannes Berg88600202012-02-13 15:17:18 +0100766 int size, err;
767 u32 changed = BSS_CHANGED_BEACON;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100768
Johannes Berg40b275b2011-05-13 14:15:49 +0200769 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100770
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100771 /* Need to have a beacon head if we don't have one yet */
772 if (!params->head && !old)
Johannes Berg88600202012-02-13 15:17:18 +0100773 return -EINVAL;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100774
775 /* new or old head? */
776 if (params->head)
777 new_head_len = params->head_len;
778 else
779 new_head_len = old->head_len;
780
781 /* new or old tail? */
782 if (params->tail || !old)
783 /* params->tail_len will be zero for !params->tail */
784 new_tail_len = params->tail_len;
785 else
786 new_tail_len = old->tail_len;
787
788 size = sizeof(*new) + new_head_len + new_tail_len;
789
790 new = kzalloc(size, GFP_KERNEL);
791 if (!new)
792 return -ENOMEM;
793
794 /* start filling the new info now */
795
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100796 /*
797 * pointers go into the block we allocated,
798 * memory is | beacon_data | head | tail |
799 */
800 new->head = ((u8 *) new) + sizeof(*new);
801 new->tail = new->head + new_head_len;
802 new->head_len = new_head_len;
803 new->tail_len = new_tail_len;
804
805 /* copy in head */
806 if (params->head)
807 memcpy(new->head, params->head, new_head_len);
808 else
809 memcpy(new->head, old->head, new_head_len);
810
811 /* copy in optional tail */
812 if (params->tail)
813 memcpy(new->tail, params->tail, new_tail_len);
814 else
815 if (old)
816 memcpy(new->tail, old->tail, new_tail_len);
817
Johannes Berg88600202012-02-13 15:17:18 +0100818 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
819 params->probe_resp_len);
820 if (err < 0)
821 return err;
822 if (err == 0)
823 changed |= BSS_CHANGED_AP_PROBE_RESP;
Johannes Berg19885c42010-02-05 11:45:06 +0100824
Eric Dumazetcf778b02012-01-12 04:41:32 +0000825 rcu_assign_pointer(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100826
Johannes Berg88600202012-02-13 15:17:18 +0100827 if (old)
828 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100829
Johannes Berg88600202012-02-13 15:17:18 +0100830 return changed;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100831}
832
Johannes Berg88600202012-02-13 15:17:18 +0100833static int ieee80211_start_ap(struct wiphy *wiphy, struct net_device *dev,
834 struct cfg80211_ap_settings *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100835{
Johannes Berg88600202012-02-13 15:17:18 +0100836 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100837 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100838 struct ieee80211_sub_if_data *vlan;
Johannes Berg88600202012-02-13 15:17:18 +0100839 u32 changed = BSS_CHANGED_BEACON_INT |
840 BSS_CHANGED_BEACON_ENABLED |
841 BSS_CHANGED_BEACON |
842 BSS_CHANGED_SSID;
843 int err;
Johannes Berg14db74b2008-07-29 13:22:52 +0200844
Johannes Berg40b275b2011-05-13 14:15:49 +0200845 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100846 if (old)
847 return -EALREADY;
848
Johannes Bergaa430da2012-05-16 23:50:18 +0200849 err = ieee80211_set_channel(wiphy, dev, params->channel,
850 params->channel_type);
851 if (err)
852 return err;
853
Johannes Berg665c93a2011-11-04 11:18:11 +0100854 /*
855 * Apply control port protocol, this allows us to
856 * not encrypt dynamic WEP control frames.
857 */
858 sdata->control_port_protocol = params->crypto.control_port_ethertype;
859 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
860 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
861 vlan->control_port_protocol =
862 params->crypto.control_port_ethertype;
863 vlan->control_port_no_encrypt =
864 params->crypto.control_port_no_encrypt;
865 }
866
Johannes Berg88600202012-02-13 15:17:18 +0100867 sdata->vif.bss_conf.beacon_int = params->beacon_interval;
868 sdata->vif.bss_conf.dtim_period = params->dtim_period;
869
870 sdata->vif.bss_conf.ssid_len = params->ssid_len;
871 if (params->ssid_len)
872 memcpy(sdata->vif.bss_conf.ssid, params->ssid,
873 params->ssid_len);
874 sdata->vif.bss_conf.hidden_ssid =
875 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
876
877 err = ieee80211_assign_beacon(sdata, &params->beacon);
878 if (err < 0)
879 return err;
880 changed |= err;
881
882 ieee80211_bss_info_change_notify(sdata, changed);
883
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200884 netif_carrier_on(dev);
885 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
886 netif_carrier_on(vlan->dev);
887
Johannes Berg665c93a2011-11-04 11:18:11 +0100888 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100889}
890
Johannes Berg88600202012-02-13 15:17:18 +0100891static int ieee80211_change_beacon(struct wiphy *wiphy, struct net_device *dev,
892 struct cfg80211_beacon_data *params)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100893{
Johannes Berg14db74b2008-07-29 13:22:52 +0200894 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100895 struct beacon_data *old;
Johannes Berg88600202012-02-13 15:17:18 +0100896 int err;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100897
Johannes Berg14db74b2008-07-29 13:22:52 +0200898 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
899
Johannes Berg40b275b2011-05-13 14:15:49 +0200900 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100901 if (!old)
902 return -ENOENT;
903
Johannes Berg88600202012-02-13 15:17:18 +0100904 err = ieee80211_assign_beacon(sdata, params);
905 if (err < 0)
906 return err;
907 ieee80211_bss_info_change_notify(sdata, err);
908 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100909}
910
Johannes Berg88600202012-02-13 15:17:18 +0100911static int ieee80211_stop_ap(struct wiphy *wiphy, struct net_device *dev)
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100912{
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200913 struct ieee80211_sub_if_data *sdata, *vlan;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100914 struct beacon_data *old;
915
Johannes Berg14db74b2008-07-29 13:22:52 +0200916 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
917
Johannes Berg40b275b2011-05-13 14:15:49 +0200918 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100919 if (!old)
920 return -ENOENT;
921
Johannes Berg3edaf3e2012-04-03 10:24:00 +0200922 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list)
923 netif_carrier_off(vlan->dev);
924 netif_carrier_off(dev);
925
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000926 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg88600202012-02-13 15:17:18 +0100927
928 kfree_rcu(old, rcu_head);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100929
Eliad Peller99102bd2012-07-18 15:36:04 +0300930 sta_info_flush(sdata->local, sdata);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200931 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
Johannes Berg88600202012-02-13 15:17:18 +0100932
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200933 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100934}
935
Johannes Berg4fd69312007-12-19 02:03:35 +0100936/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
937struct iapp_layer2_update {
938 u8 da[ETH_ALEN]; /* broadcast */
939 u8 sa[ETH_ALEN]; /* STA addr */
940 __be16 len; /* 6 */
941 u8 dsap; /* 0 */
942 u8 ssap; /* 0 */
943 u8 control;
944 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700945} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100946
947static void ieee80211_send_layer2_update(struct sta_info *sta)
948{
949 struct iapp_layer2_update *msg;
950 struct sk_buff *skb;
951
952 /* Send Level 2 Update Frame to update forwarding tables in layer 2
953 * bridge devices */
954
955 skb = dev_alloc_skb(sizeof(*msg));
956 if (!skb)
957 return;
958 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
959
960 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
961 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
962
Johannes Berge83e6542012-07-13 16:23:07 +0200963 eth_broadcast_addr(msg->da);
Johannes Berg17741cd2008-09-11 00:02:02 +0200964 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100965 msg->len = htons(6);
966 msg->dsap = 0;
967 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
968 msg->control = 0xaf; /* XID response lsb.1111F101.
969 * F=0 (no poll command; unsolicited frame) */
970 msg->xid_info[0] = 0x81; /* XID format identifier */
971 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
972 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
973
Johannes Bergd0709a62008-02-25 16:27:46 +0100974 skb->dev = sta->sdata->dev;
975 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100976 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400977 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100978}
979
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100980static int sta_apply_parameters(struct ieee80211_local *local,
981 struct sta_info *sta,
982 struct station_parameters *params)
Johannes Berg4fd69312007-12-19 02:03:35 +0100983{
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100984 int ret = 0;
Johannes Berg4fd69312007-12-19 02:03:35 +0100985 u32 rates;
986 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100987 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100988 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300989 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100990
Johannes Bergae5eb022008-10-14 16:58:37 +0200991 sband = local->hw.wiphy->bands[local->oper_channel->band];
992
Johannes Bergeccb8e82009-05-11 21:57:56 +0300993 mask = params->sta_flags_mask;
994 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100995
Johannes Bergd9a7ddb2011-12-14 12:35:30 +0100996 /*
997 * In mesh mode, we can clear AUTHENTICATED flag but must
998 * also make ASSOCIATED follow appropriately for the driver
999 * API. See also below, after AUTHORIZED changes.
1000 */
1001 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1002 /* cfg80211 should not allow this in non-mesh modes */
1003 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1004 return -EINVAL;
1005
1006 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED) &&
1007 !test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001008 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001009 if (ret)
1010 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001011 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001012 if (ret)
1013 return ret;
1014 }
1015 }
1016
Johannes Bergeccb8e82009-05-11 21:57:56 +03001017 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001018 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001019 ret = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
Johannes Berg543d1b92012-01-13 14:17:59 +01001020 else if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
Johannes Berg83d5cc02012-01-12 09:31:10 +01001021 ret = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001022 if (ret)
1023 return ret;
Johannes Berg4fd69312007-12-19 02:03:35 +01001024 }
1025
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001026 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
1027 /* cfg80211 should not allow this in non-mesh modes */
1028 if (WARN_ON(!ieee80211_vif_is_mesh(&sdata->vif)))
1029 return -EINVAL;
1030
1031 if (!(set & BIT(NL80211_STA_FLAG_AUTHENTICATED)) &&
1032 test_sta_flag(sta, WLAN_STA_AUTH)) {
Johannes Berg83d5cc02012-01-12 09:31:10 +01001033 ret = sta_info_move_state(sta, IEEE80211_STA_AUTH);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001034 if (ret)
1035 return ret;
Johannes Berg83d5cc02012-01-12 09:31:10 +01001036 ret = sta_info_move_state(sta, IEEE80211_STA_NONE);
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001037 if (ret)
1038 return ret;
1039 }
1040 }
1041
1042
Johannes Bergeccb8e82009-05-11 21:57:56 +03001043 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001044 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001045 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
1046 else
1047 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001048 }
1049
1050 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +03001051 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001052 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +03001053 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001054 } else {
1055 clear_sta_flag(sta, WLAN_STA_WME);
1056 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +03001057 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001058 }
1059
1060 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +03001061 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001062 set_sta_flag(sta, WLAN_STA_MFP);
1063 else
1064 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +03001065 }
Javier Cardonab39c48f2011-04-07 15:08:30 -07001066
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001067 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001068 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +02001069 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
1070 else
1071 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +03001072 }
Johannes Bergeccb8e82009-05-11 21:57:56 +03001073
Johannes Berg3b9ce802011-09-27 20:56:12 +02001074 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
1075 sta->sta.uapsd_queues = params->uapsd_queues;
1076 sta->sta.max_sp = params->max_sp;
1077 }
Eliad Peller9533b4a2011-08-23 14:37:47 +03001078
Johannes Berg73651ee2008-02-25 16:27:47 +01001079 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +02001080 * cfg80211 validates this (1-2007) and allows setting the AID
1081 * only when creating a new station entry
1082 */
1083 if (params->aid)
1084 sta->sta.aid = params->aid;
1085
1086 /*
Johannes Berg73651ee2008-02-25 16:27:47 +01001087 * FIXME: updating the following information is racy when this
1088 * function is called from ieee80211_change_station().
1089 * However, all this information should be static so
1090 * maybe we should just reject attemps to change it.
1091 */
1092
Johannes Berg4fd69312007-12-19 02:03:35 +01001093 if (params->listen_interval >= 0)
1094 sta->listen_interval = params->listen_interval;
1095
1096 if (params->supported_rates) {
1097 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01001098
Johannes Berg4fd69312007-12-19 02:03:35 +01001099 for (i = 0; i < params->supported_rates_len; i++) {
1100 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +01001101 for (j = 0; j < sband->n_bitrates; j++) {
1102 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +01001103 rates |= BIT(j);
1104 }
1105 }
Johannes Berg323ce792008-09-11 02:45:11 +02001106 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +01001107 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001108
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001109 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -08001110 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +02001111 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +02001112 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +03001113
Javier Cardona9c3990a2011-05-03 16:57:11 -07001114 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001115#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -07001116 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
1117 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -07001118 case NL80211_PLINK_LISTEN:
1119 case NL80211_PLINK_ESTAB:
1120 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -07001121 sta->plink_state = params->plink_state;
1122 break;
1123 default:
1124 /* nothing */
1125 break;
1126 }
1127 else
1128 switch (params->plink_action) {
1129 case PLINK_ACTION_OPEN:
1130 mesh_plink_open(sta);
1131 break;
1132 case PLINK_ACTION_BLOCK:
1133 mesh_plink_block(sta);
1134 break;
1135 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -04001136#endif
Johannes Berg902acc72008-02-23 15:17:19 +01001137 }
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001138
1139 return 0;
Johannes Berg4fd69312007-12-19 02:03:35 +01001140}
1141
1142static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
1143 u8 *mac, struct station_parameters *params)
1144{
Johannes Berg14db74b2008-07-29 13:22:52 +02001145 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001146 struct sta_info *sta;
1147 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +01001148 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001149 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +01001150
Johannes Berg4fd69312007-12-19 02:03:35 +01001151 if (params->vlan) {
1152 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1153
Johannes Berg05c914f2008-09-11 00:01:58 +02001154 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1155 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +01001156 return -EINVAL;
1157 } else
1158 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1159
Joe Perchesb203ca32012-05-08 18:56:52 +00001160 if (ether_addr_equal(mac, sdata->vif.addr))
Johannes Berg03e44972008-02-27 09:56:40 +01001161 return -EINVAL;
1162
1163 if (is_multicast_ether_addr(mac))
1164 return -EINVAL;
1165
1166 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +01001167 if (!sta)
1168 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +01001169
Johannes Berg83d5cc02012-01-12 09:31:10 +01001170 sta_info_pre_move_state(sta, IEEE80211_STA_AUTH);
1171 sta_info_pre_move_state(sta, IEEE80211_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +01001172
Johannes Bergd9a7ddb2011-12-14 12:35:30 +01001173 err = sta_apply_parameters(local, sta, params);
1174 if (err) {
1175 sta_info_free(local, sta);
1176 return err;
1177 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001178
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001179 /*
1180 * for TDLS, rate control should be initialized only when supported
1181 * rates are known.
1182 */
1183 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
1184 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +01001185
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001186 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
1187 sdata->vif.type == NL80211_IFTYPE_AP;
1188
Johannes Berg34e89502010-02-03 13:59:58 +01001189 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +01001190 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +01001191 rcu_read_unlock();
1192 return err;
1193 }
1194
Jouni Malinenb8d476c2008-12-12 17:08:31 +02001195 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +01001196 ieee80211_send_layer2_update(sta);
1197
1198 rcu_read_unlock();
1199
Johannes Berg4fd69312007-12-19 02:03:35 +01001200 return 0;
1201}
1202
1203static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
1204 u8 *mac)
1205{
Johannes Berg14db74b2008-07-29 13:22:52 +02001206 struct ieee80211_local *local = wiphy_priv(wiphy);
1207 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +01001208
Johannes Berg14db74b2008-07-29 13:22:52 +02001209 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1210
Johannes Berg34e89502010-02-03 13:59:58 +01001211 if (mac)
1212 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001213
Johannes Berg34e89502010-02-03 13:59:58 +01001214 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +01001215 return 0;
1216}
1217
1218static int ieee80211_change_station(struct wiphy *wiphy,
1219 struct net_device *dev,
1220 u8 *mac,
1221 struct station_parameters *params)
1222{
Johannes Bergabe60632009-11-25 17:46:18 +01001223 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +02001224 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +01001225 struct sta_info *sta;
1226 struct ieee80211_sub_if_data *vlansdata;
Eliad Peller35b88622011-12-29 14:41:39 +02001227 int err;
Johannes Berg4fd69312007-12-19 02:03:35 +01001228
Johannes Berg87be1e12011-12-14 12:20:29 +01001229 mutex_lock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001230
Felix Fietkau0e5ded52010-01-08 18:10:58 +01001231 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001232 if (!sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001233 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001234 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001235 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001236
Johannes Bergbdd90d52011-12-14 12:20:27 +01001237 /* in station mode, supported rates are only valid with TDLS */
1238 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
1239 params->supported_rates &&
1240 !test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001241 mutex_unlock(&local->sta_mtx);
Johannes Bergbdd90d52011-12-14 12:20:27 +01001242 return -EINVAL;
1243 }
1244
Johannes Bergd0709a62008-02-25 16:27:46 +01001245 if (params->vlan && params->vlan != sta->sdata->dev) {
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001246 bool prev_4addr = false;
1247 bool new_4addr = false;
1248
Johannes Berg4fd69312007-12-19 02:03:35 +01001249 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
1250
Johannes Berg05c914f2008-09-11 00:01:58 +02001251 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
1252 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001253 mutex_unlock(&local->sta_mtx);
Johannes Berg4fd69312007-12-19 02:03:35 +01001254 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +02001255 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001256
Johannes Berg9bc383d2009-11-19 11:55:19 +01001257 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +01001258 if (vlansdata->u.vlan.sta) {
Johannes Berg87be1e12011-12-14 12:20:29 +01001259 mutex_unlock(&local->sta_mtx);
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001260 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +01001261 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001262
Eric Dumazetcf778b02012-01-12 04:41:32 +00001263 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001264 new_4addr = true;
1265 }
1266
1267 if (sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
1268 sta->sdata->u.vlan.sta) {
1269 rcu_assign_pointer(sta->sdata->u.vlan.sta, NULL);
1270 prev_4addr = true;
Felix Fietkauf14543ee2009-11-10 20:10:05 +01001271 }
1272
Johannes Berg14db74b2008-07-29 13:22:52 +02001273 sta->sdata = vlansdata;
Felix Fietkau7e3ed022012-04-23 19:49:03 +02001274
1275 if (sta->sta_state == IEEE80211_STA_AUTHORIZED &&
1276 prev_4addr != new_4addr) {
1277 if (new_4addr)
1278 atomic_dec(&sta->sdata->bss->num_mcast_sta);
1279 else
1280 atomic_inc(&sta->sdata->bss->num_mcast_sta);
1281 }
1282
Johannes Berg4fd69312007-12-19 02:03:35 +01001283 ieee80211_send_layer2_update(sta);
1284 }
1285
Eliad Peller35b88622011-12-29 14:41:39 +02001286 err = sta_apply_parameters(local, sta, params);
1287 if (err) {
1288 mutex_unlock(&local->sta_mtx);
1289 return err;
1290 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001291
Arik Nemtsovd64cf632011-11-07 23:24:39 +02001292 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
1293 rate_control_rate_init(sta);
1294
Johannes Berg87be1e12011-12-14 12:20:29 +01001295 mutex_unlock(&local->sta_mtx);
Johannes Berg98dd6a52008-04-10 15:36:09 +02001296
Jason Young808118c2011-03-10 16:43:19 -08001297 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
Eliad Pellerab095872012-07-27 12:33:22 +03001298 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Jason Young808118c2011-03-10 16:43:19 -08001299 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03001300 ieee80211_recalc_ps_vif(sdata);
1301 }
Johannes Berg4fd69312007-12-19 02:03:35 +01001302 return 0;
1303}
1304
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001305#ifdef CONFIG_MAC80211_MESH
1306static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1307 u8 *dst, u8 *next_hop)
1308{
Johannes Berg14db74b2008-07-29 13:22:52 +02001309 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001310 struct mesh_path *mpath;
1311 struct sta_info *sta;
1312 int err;
1313
Johannes Berg14db74b2008-07-29 13:22:52 +02001314 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1315
Johannes Bergd0709a62008-02-25 16:27:46 +01001316 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001317 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001318 if (!sta) {
1319 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001320 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001321 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001322
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001323 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +01001324 if (err) {
1325 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001326 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001327 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001328
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001329 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001330 if (!mpath) {
1331 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001332 return -ENXIO;
1333 }
1334 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001335
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001336 rcu_read_unlock();
1337 return 0;
1338}
1339
1340static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1341 u8 *dst)
1342{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001343 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001344
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001345 if (dst)
1346 return mesh_path_del(dst, sdata);
1347
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001348 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001349 return 0;
1350}
1351
1352static int ieee80211_change_mpath(struct wiphy *wiphy,
1353 struct net_device *dev,
1354 u8 *dst, u8 *next_hop)
1355{
Johannes Berg14db74b2008-07-29 13:22:52 +02001356 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001357 struct mesh_path *mpath;
1358 struct sta_info *sta;
1359
Johannes Berg14db74b2008-07-29 13:22:52 +02001360 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1361
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001362 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001363
Johannes Bergabe60632009-11-25 17:46:18 +01001364 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001365 if (!sta) {
1366 rcu_read_unlock();
1367 return -ENOENT;
1368 }
1369
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001370 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001371 if (!mpath) {
1372 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001373 return -ENOENT;
1374 }
1375
1376 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001377
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001378 rcu_read_unlock();
1379 return 0;
1380}
1381
1382static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1383 struct mpath_info *pinfo)
1384{
Johannes Berga3836e02011-05-12 15:11:37 +02001385 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1386
1387 if (next_hop_sta)
1388 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001389 else
1390 memset(next_hop, 0, ETH_ALEN);
1391
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001392 memset(pinfo, 0, sizeof(*pinfo));
1393
Johannes Bergf5ea9122009-08-07 16:17:38 +02001394 pinfo->generation = mesh_paths_generation;
1395
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001396 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001397 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001398 MPATH_INFO_METRIC |
1399 MPATH_INFO_EXPTIME |
1400 MPATH_INFO_DISCOVERY_TIMEOUT |
1401 MPATH_INFO_DISCOVERY_RETRIES |
1402 MPATH_INFO_FLAGS;
1403
1404 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001405 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001406 pinfo->metric = mpath->metric;
1407 if (time_before(jiffies, mpath->exp_time))
1408 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1409 pinfo->discovery_timeout =
1410 jiffies_to_msecs(mpath->discovery_timeout);
1411 pinfo->discovery_retries = mpath->discovery_retries;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001412 if (mpath->flags & MESH_PATH_ACTIVE)
1413 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1414 if (mpath->flags & MESH_PATH_RESOLVING)
1415 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001416 if (mpath->flags & MESH_PATH_SN_VALID)
1417 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001418 if (mpath->flags & MESH_PATH_FIXED)
1419 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
LEO Airwarosu Yoichi Shinoda7ce8c7a2012-08-27 22:28:16 +09001420 if (mpath->flags & MESH_PATH_RESOLVED)
1421 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVED;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001422}
1423
1424static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1425 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1426
1427{
Johannes Berg14db74b2008-07-29 13:22:52 +02001428 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001429 struct mesh_path *mpath;
1430
Johannes Berg14db74b2008-07-29 13:22:52 +02001431 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1432
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001433 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001434 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001435 if (!mpath) {
1436 rcu_read_unlock();
1437 return -ENOENT;
1438 }
1439 memcpy(dst, mpath->dst, ETH_ALEN);
1440 mpath_set_pinfo(mpath, next_hop, pinfo);
1441 rcu_read_unlock();
1442 return 0;
1443}
1444
1445static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1446 int idx, u8 *dst, u8 *next_hop,
1447 struct mpath_info *pinfo)
1448{
Johannes Berg14db74b2008-07-29 13:22:52 +02001449 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001450 struct mesh_path *mpath;
1451
Johannes Berg14db74b2008-07-29 13:22:52 +02001452 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1453
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001454 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001455 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001456 if (!mpath) {
1457 rcu_read_unlock();
1458 return -ENOENT;
1459 }
1460 memcpy(dst, mpath->dst, ETH_ALEN);
1461 mpath_set_pinfo(mpath, next_hop, pinfo);
1462 rcu_read_unlock();
1463 return 0;
1464}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001465
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001466static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001467 struct net_device *dev,
1468 struct mesh_config *conf)
1469{
1470 struct ieee80211_sub_if_data *sdata;
1471 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1472
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001473 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1474 return 0;
1475}
1476
1477static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1478{
1479 return (mask >> (parm-1)) & 0x1;
1480}
1481
Javier Cardonac80d5452010-12-16 17:37:49 -08001482static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1483 const struct mesh_setup *setup)
1484{
1485 u8 *new_ie;
1486 const u8 *old_ie;
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001487 struct ieee80211_sub_if_data *sdata = container_of(ifmsh,
1488 struct ieee80211_sub_if_data, u.mesh);
Javier Cardonac80d5452010-12-16 17:37:49 -08001489
Javier Cardona581a8b02011-04-07 15:08:27 -07001490 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001491 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001492 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001493
Javier Cardona581a8b02011-04-07 15:08:27 -07001494 if (setup->ie_len) {
1495 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001496 GFP_KERNEL);
1497 if (!new_ie)
1498 return -ENOMEM;
1499 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001500 ifmsh->ie_len = setup->ie_len;
1501 ifmsh->ie = new_ie;
1502 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001503
1504 /* now copy the rest of the setup parameters */
1505 ifmsh->mesh_id_len = setup->mesh_id_len;
1506 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
Javier Cardonad299a1f2012-03-31 11:31:33 -07001507 ifmsh->mesh_sp_id = setup->sync_method;
Javier Cardonac80d5452010-12-16 17:37:49 -08001508 ifmsh->mesh_pp_id = setup->path_sel_proto;
1509 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001510 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1511 if (setup->is_authenticated)
1512 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1513 if (setup->is_secure)
1514 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001515
Chun-Yeow Yeoh4bb62342011-11-24 17:15:20 -08001516 /* mcast rate setting in Mesh Node */
1517 memcpy(sdata->vif.bss_conf.mcast_rate, setup->mcast_rate,
1518 sizeof(setup->mcast_rate));
1519
Javier Cardonac80d5452010-12-16 17:37:49 -08001520 return 0;
1521}
1522
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001523static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001524 struct net_device *dev, u32 mask,
1525 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001526{
1527 struct mesh_config *conf;
1528 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001529 struct ieee80211_if_mesh *ifmsh;
1530
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001531 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001532 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001533
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001534 /* Set the config options which we are interested in setting */
1535 conf = &(sdata->u.mesh.mshcfg);
1536 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1537 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1538 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1539 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1540 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1541 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1542 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1543 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1544 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1545 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1546 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1547 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001548 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
Chun-Yeow Yeoh58886a92012-06-15 00:23:53 +08001549 conf->element_ttl = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001550 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1551 conf->auto_open_plinks = nconf->auto_open_plinks;
Javier Cardonad299a1f2012-03-31 11:31:33 -07001552 if (_chg_mesh_attr(NL80211_MESHCONF_SYNC_OFFSET_MAX_NEIGHBOR, mask))
1553 conf->dot11MeshNbrOffsetMaxNeighbor =
1554 nconf->dot11MeshNbrOffsetMaxNeighbor;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001555 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1556 conf->dot11MeshHWMPmaxPREQretries =
1557 nconf->dot11MeshHWMPmaxPREQretries;
1558 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1559 conf->path_refresh_time = nconf->path_refresh_time;
1560 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1561 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1562 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1563 conf->dot11MeshHWMPactivePathTimeout =
1564 nconf->dot11MeshHWMPactivePathTimeout;
1565 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1566 conf->dot11MeshHWMPpreqMinInterval =
1567 nconf->dot11MeshHWMPpreqMinInterval;
Thomas Pedersendca7e942011-11-24 17:15:24 -08001568 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PERR_MIN_INTERVAL, mask))
1569 conf->dot11MeshHWMPperrMinInterval =
1570 nconf->dot11MeshHWMPperrMinInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001571 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1572 mask))
1573 conf->dot11MeshHWMPnetDiameterTraversalTime =
1574 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001575 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1576 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1577 ieee80211_mesh_root_setup(ifmsh);
1578 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001579 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001580 /* our current gate announcement implementation rides on root
1581 * announcements, so require this ifmsh to also be a root node
1582 * */
1583 if (nconf->dot11MeshGateAnnouncementProtocol &&
Chun-Yeow Yeohdbb912c2012-06-14 02:06:09 +08001584 !(conf->dot11MeshHWMPRootMode > IEEE80211_ROOTMODE_ROOT)) {
1585 conf->dot11MeshHWMPRootMode = IEEE80211_PROACTIVE_RANN;
Thomas Pedersenc61336612011-08-25 10:36:14 -07001586 ieee80211_mesh_root_setup(ifmsh);
1587 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001588 conf->dot11MeshGateAnnouncementProtocol =
1589 nconf->dot11MeshGateAnnouncementProtocol;
1590 }
Chun-Yeow Yeoha4f606e2012-06-11 11:59:36 +08001591 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask))
Javier Cardona0507e152011-08-09 16:45:10 -07001592 conf->dot11MeshHWMPRannInterval =
1593 nconf->dot11MeshHWMPRannInterval;
Chun-Yeow Yeoh94f90652012-01-21 01:02:16 +08001594 if (_chg_mesh_attr(NL80211_MESHCONF_FORWARDING, mask))
1595 conf->dot11MeshForwarding = nconf->dot11MeshForwarding;
Ashok Nagarajan55335132012-02-28 17:04:08 -08001596 if (_chg_mesh_attr(NL80211_MESHCONF_RSSI_THRESHOLD, mask)) {
1597 /* our RSSI threshold implementation is supported only for
1598 * devices that report signal in dBm.
1599 */
1600 if (!(sdata->local->hw.flags & IEEE80211_HW_SIGNAL_DBM))
1601 return -ENOTSUPP;
1602 conf->rssi_threshold = nconf->rssi_threshold;
1603 }
Ashok Nagarajan70c33ea2012-04-30 14:20:32 -07001604 if (_chg_mesh_attr(NL80211_MESHCONF_HT_OPMODE, mask)) {
1605 conf->ht_opmode = nconf->ht_opmode;
1606 sdata->vif.bss_conf.ht_operation_mode = nconf->ht_opmode;
1607 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1608 }
Chun-Yeow Yeohac1073a2012-06-14 02:06:06 +08001609 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PATH_TO_ROOT_TIMEOUT, mask))
1610 conf->dot11MeshHWMPactivePathToRootTimeout =
1611 nconf->dot11MeshHWMPactivePathToRootTimeout;
1612 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOT_INTERVAL, mask))
1613 conf->dot11MeshHWMProotInterval =
1614 nconf->dot11MeshHWMProotInterval;
Chun-Yeow Yeoh728b19e2012-06-14 02:06:10 +08001615 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_CONFIRMATION_INTERVAL, mask))
1616 conf->dot11MeshHWMPconfirmationInterval =
1617 nconf->dot11MeshHWMPconfirmationInterval;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001618 return 0;
1619}
1620
Johannes Berg29cbe682010-12-03 09:20:44 +01001621static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1622 const struct mesh_config *conf,
1623 const struct mesh_setup *setup)
1624{
1625 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1626 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001627 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001628
Javier Cardonac80d5452010-12-16 17:37:49 -08001629 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1630 err = copy_mesh_setup(ifmsh, setup);
1631 if (err)
1632 return err;
Johannes Bergcc1d2802012-05-16 23:50:20 +02001633
1634 err = ieee80211_set_channel(wiphy, dev, setup->channel,
1635 setup->channel_type);
1636 if (err)
1637 return err;
1638
Johannes Berg29cbe682010-12-03 09:20:44 +01001639 ieee80211_start_mesh(sdata);
1640
1641 return 0;
1642}
1643
1644static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1645{
1646 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1647
1648 ieee80211_stop_mesh(sdata);
1649
1650 return 0;
1651}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001652#endif
1653
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001654static int ieee80211_change_bss(struct wiphy *wiphy,
1655 struct net_device *dev,
1656 struct bss_parameters *params)
1657{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001658 struct ieee80211_sub_if_data *sdata;
1659 u32 changed = 0;
1660
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001661 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1662
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001663 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001664 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001665 changed |= BSS_CHANGED_ERP_CTS_PROT;
1666 }
1667 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001668 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001669 params->use_short_preamble;
1670 changed |= BSS_CHANGED_ERP_PREAMBLE;
1671 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001672
1673 if (!sdata->vif.bss_conf.use_short_slot &&
Johannes Berg679ef4e2012-07-23 14:29:21 +02001674 sdata->local->oper_channel->band == IEEE80211_BAND_5GHZ) {
Felix Fietkau43d35342010-01-15 03:00:48 +01001675 sdata->vif.bss_conf.use_short_slot = true;
1676 changed |= BSS_CHANGED_ERP_SLOT;
1677 }
1678
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001679 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001680 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001681 params->use_short_slot_time;
1682 changed |= BSS_CHANGED_ERP_SLOT;
1683 }
1684
Jouni Malinen90c97a02008-10-30 16:59:22 +02001685 if (params->basic_rates) {
1686 int i, j;
1687 u32 rates = 0;
1688 struct ieee80211_local *local = wiphy_priv(wiphy);
1689 struct ieee80211_supported_band *sband =
1690 wiphy->bands[local->oper_channel->band];
1691
1692 for (i = 0; i < params->basic_rates_len; i++) {
1693 int rate = (params->basic_rates[i] & 0x7f) * 5;
1694 for (j = 0; j < sband->n_bitrates; j++) {
1695 if (sband->bitrates[j].bitrate == rate)
1696 rates |= BIT(j);
1697 }
1698 }
1699 sdata->vif.bss_conf.basic_rates = rates;
1700 changed |= BSS_CHANGED_BASIC_RATES;
1701 }
1702
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001703 if (params->ap_isolate >= 0) {
1704 if (params->ap_isolate)
1705 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1706 else
1707 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1708 }
1709
Helmut Schaa80d7e402010-11-19 12:40:26 +01001710 if (params->ht_opmode >= 0) {
1711 sdata->vif.bss_conf.ht_operation_mode =
1712 (u16) params->ht_opmode;
1713 changed |= BSS_CHANGED_HT;
1714 }
1715
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001716 ieee80211_bss_info_change_notify(sdata, changed);
1717
1718 return 0;
1719}
1720
Jouni Malinen31888482008-10-30 16:59:24 +02001721static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001722 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001723 struct ieee80211_txq_params *params)
1724{
1725 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001726 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001727 struct ieee80211_tx_queue_params p;
1728
1729 if (!local->ops->conf_tx)
1730 return -EOPNOTSUPP;
1731
Johannes Berg54bcbc62012-03-28 11:04:25 +02001732 if (local->hw.queues < IEEE80211_NUM_ACS)
1733 return -EOPNOTSUPP;
1734
Jouni Malinen31888482008-10-30 16:59:24 +02001735 memset(&p, 0, sizeof(p));
1736 p.aifs = params->aifs;
1737 p.cw_max = params->cwmax;
1738 p.cw_min = params->cwmin;
1739 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001740
1741 /*
1742 * Setting tx queue params disables u-apsd because it's only
1743 * called in master mode.
1744 */
1745 p.uapsd = false;
1746
Johannes Berga3304b02012-03-28 11:04:24 +02001747 sdata->tx_conf[params->ac] = p;
1748 if (drv_conf_tx(local, sdata, params->ac, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001749 wiphy_debug(local->hw.wiphy,
Johannes Berga3304b02012-03-28 11:04:24 +02001750 "failed to set TX queue parameters for AC %d\n",
1751 params->ac);
Jouni Malinen31888482008-10-30 16:59:24 +02001752 return -EINVAL;
1753 }
1754
Johannes Berg7d257452012-07-06 17:37:43 +02001755 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
1756
Jouni Malinen31888482008-10-30 16:59:24 +02001757 return 0;
1758}
1759
Bob Copeland665af4f2009-01-19 11:20:53 -05001760#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001761static int ieee80211_suspend(struct wiphy *wiphy,
1762 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001763{
Johannes Bergeecc4802011-05-04 15:37:29 +02001764 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001765}
1766
1767static int ieee80211_resume(struct wiphy *wiphy)
1768{
1769 return __ieee80211_resume(wiphy_priv(wiphy));
1770}
1771#else
1772#define ieee80211_suspend NULL
1773#define ieee80211_resume NULL
1774#endif
1775
Johannes Berg2a519312009-02-10 21:25:55 +01001776static int ieee80211_scan(struct wiphy *wiphy,
Johannes Berg2a519312009-02-10 21:25:55 +01001777 struct cfg80211_scan_request *req)
1778{
Johannes Bergfd014282012-06-18 19:17:03 +02001779 struct ieee80211_sub_if_data *sdata;
1780
1781 sdata = IEEE80211_WDEV_TO_SUB_IF(req->wdev);
Johannes Berg2a519312009-02-10 21:25:55 +01001782
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001783 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1784 case NL80211_IFTYPE_STATION:
1785 case NL80211_IFTYPE_ADHOC:
1786 case NL80211_IFTYPE_MESH_POINT:
1787 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Bergf142c6b2012-06-18 20:07:15 +02001788 case NL80211_IFTYPE_P2P_DEVICE:
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001789 break;
1790 case NL80211_IFTYPE_P2P_GO:
1791 if (sdata->local->ops->hw_scan)
1792 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001793 /*
1794 * FIXME: implement NoA while scanning in software,
1795 * for now fall through to allow scanning only when
1796 * beaconing hasn't been configured yet
1797 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001798 case NL80211_IFTYPE_AP:
1799 if (sdata->u.ap.beacon)
1800 return -EOPNOTSUPP;
1801 break;
1802 default:
1803 return -EOPNOTSUPP;
1804 }
Johannes Berg2a519312009-02-10 21:25:55 +01001805
1806 return ieee80211_request_scan(sdata, req);
1807}
1808
Luciano Coelho79f460c2011-05-11 17:09:36 +03001809static int
1810ieee80211_sched_scan_start(struct wiphy *wiphy,
1811 struct net_device *dev,
1812 struct cfg80211_sched_scan_request *req)
1813{
1814 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1815
1816 if (!sdata->local->ops->sched_scan_start)
1817 return -EOPNOTSUPP;
1818
1819 return ieee80211_request_sched_scan_start(sdata, req);
1820}
1821
1822static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001823ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001824{
1825 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1826
1827 if (!sdata->local->ops->sched_scan_stop)
1828 return -EOPNOTSUPP;
1829
Luciano Coelho85a99942011-05-12 16:28:29 +03001830 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001831}
1832
Jouni Malinen636a5d32009-03-19 13:39:22 +02001833static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1834 struct cfg80211_auth_request *req)
1835{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001836 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001837}
1838
1839static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1840 struct cfg80211_assoc_request *req)
1841{
Johannes Bergf444de02010-05-05 15:25:02 +02001842 struct ieee80211_local *local = wiphy_priv(wiphy);
1843 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1844
1845 switch (ieee80211_get_channel_mode(local, sdata)) {
1846 case CHAN_MODE_HOPPING:
1847 return -EBUSY;
1848 case CHAN_MODE_FIXED:
1849 if (local->oper_channel == req->bss->channel)
1850 break;
1851 return -EBUSY;
1852 case CHAN_MODE_UNDEFINED:
1853 break;
1854 }
1855
Johannes Berg77fdaa12009-07-07 03:45:17 +02001856 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001857}
1858
1859static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001860 struct cfg80211_deauth_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001861{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001862 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001863}
1864
1865static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001866 struct cfg80211_disassoc_request *req)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001867{
Johannes Berg63c9c5e2012-02-24 13:50:51 +01001868 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001869}
1870
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001871static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1872 struct cfg80211_ibss_params *params)
1873{
Johannes Bergf444de02010-05-05 15:25:02 +02001874 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001875 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1876
Johannes Bergf444de02010-05-05 15:25:02 +02001877 switch (ieee80211_get_channel_mode(local, sdata)) {
1878 case CHAN_MODE_HOPPING:
1879 return -EBUSY;
1880 case CHAN_MODE_FIXED:
1881 if (!params->channel_fixed)
1882 return -EBUSY;
1883 if (local->oper_channel == params->channel)
1884 break;
1885 return -EBUSY;
1886 case CHAN_MODE_UNDEFINED:
1887 break;
1888 }
1889
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001890 return ieee80211_ibss_join(sdata, params);
1891}
1892
1893static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1894{
1895 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1896
1897 return ieee80211_ibss_leave(sdata);
1898}
1899
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001900static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1901{
1902 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001903 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001904
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001905 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1906 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1907
1908 if (err)
1909 return err;
1910 }
1911
Lukáš Turek310bc672009-12-21 22:50:48 +01001912 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1913 err = drv_set_coverage_class(local, wiphy->coverage_class);
1914
1915 if (err)
1916 return err;
1917 }
1918
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001919 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001920 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001921
Johannes Berg24487982009-04-23 18:52:52 +02001922 if (err)
1923 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001924 }
1925
1926 if (changed & WIPHY_PARAM_RETRY_SHORT)
1927 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1928 if (changed & WIPHY_PARAM_RETRY_LONG)
1929 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1930 if (changed &
1931 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1932 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1933
1934 return 0;
1935}
1936
Johannes Berg7643a2c2009-06-02 13:01:39 +02001937static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001938 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001939{
1940 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg679ef4e2012-07-23 14:29:21 +02001941 struct ieee80211_channel *chan = local->oper_channel;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001942 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001943
1944 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001945 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001946 local->user_power_level = -1;
1947 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001948 case NL80211_TX_POWER_LIMITED:
1949 if (mbm < 0 || (mbm % 100))
1950 return -EOPNOTSUPP;
1951 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001952 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001953 case NL80211_TX_POWER_FIXED:
1954 if (mbm < 0 || (mbm % 100))
1955 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001956 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001957 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001958 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001959 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001960 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001961 }
1962
1963 ieee80211_hw_config(local, changes);
1964
1965 return 0;
1966}
1967
1968static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1969{
1970 struct ieee80211_local *local = wiphy_priv(wiphy);
1971
1972 *dbm = local->hw.conf.power_level;
1973
Johannes Berg7643a2c2009-06-02 13:01:39 +02001974 return 0;
1975}
1976
Johannes Bergab737a42009-07-01 21:26:58 +02001977static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02001978 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02001979{
1980 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1981
1982 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1983
1984 return 0;
1985}
1986
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001987static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1988{
1989 struct ieee80211_local *local = wiphy_priv(wiphy);
1990
1991 drv_rfkill_poll(local);
1992}
1993
Johannes Bergaff89a92009-07-01 21:26:51 +02001994#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001995static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001996{
1997 struct ieee80211_local *local = wiphy_priv(wiphy);
1998
1999 if (!local->ops->testmode_cmd)
2000 return -EOPNOTSUPP;
2001
2002 return local->ops->testmode_cmd(&local->hw, data, len);
2003}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002004
2005static int ieee80211_testmode_dump(struct wiphy *wiphy,
2006 struct sk_buff *skb,
2007 struct netlink_callback *cb,
2008 void *data, int len)
2009{
2010 struct ieee80211_local *local = wiphy_priv(wiphy);
2011
2012 if (!local->ops->testmode_dump)
2013 return -EOPNOTSUPP;
2014
2015 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
2016}
Johannes Bergaff89a92009-07-01 21:26:51 +02002017#endif
2018
Johannes Berg0f782312009-12-01 13:37:02 +01002019int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
2020 enum ieee80211_smps_mode smps_mode)
2021{
2022 const u8 *ap;
2023 enum ieee80211_smps_mode old_req;
2024 int err;
2025
Johannes Berg243e6df2011-04-19 20:44:04 +02002026 lockdep_assert_held(&sdata->u.mgd.mtx);
2027
Johannes Berg0f782312009-12-01 13:37:02 +01002028 old_req = sdata->u.mgd.req_smps;
2029 sdata->u.mgd.req_smps = smps_mode;
2030
2031 if (old_req == smps_mode &&
2032 smps_mode != IEEE80211_SMPS_AUTOMATIC)
2033 return 0;
2034
2035 /*
2036 * If not associated, or current association is not an HT
2037 * association, there's no need to send an action frame.
2038 */
2039 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02002040 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01002041 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02002042 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01002043 mutex_unlock(&sdata->local->iflist_mtx);
2044 return 0;
2045 }
2046
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01002047 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01002048
2049 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
2050 if (sdata->u.mgd.powersave)
2051 smps_mode = IEEE80211_SMPS_DYNAMIC;
2052 else
2053 smps_mode = IEEE80211_SMPS_OFF;
2054 }
2055
2056 /* send SM PS frame to AP */
2057 err = ieee80211_send_smps_action(sdata, smps_mode,
2058 ap, ap);
2059 if (err)
2060 sdata->u.mgd.req_smps = old_req;
2061
2062 return err;
2063}
2064
Johannes Bergbc92afd2009-07-01 21:26:57 +02002065static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
2066 bool enabled, int timeout)
2067{
2068 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2069 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002070
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01002071 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2072 return -EOPNOTSUPP;
2073
Johannes Bergbc92afd2009-07-01 21:26:57 +02002074 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
2075 return -EOPNOTSUPP;
2076
2077 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03002078 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002079 return 0;
2080
2081 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03002082 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02002083
Johannes Berg0f782312009-12-01 13:37:02 +01002084 /* no change, but if automatic follow powersave */
2085 mutex_lock(&sdata->u.mgd.mtx);
2086 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
2087 mutex_unlock(&sdata->u.mgd.mtx);
2088
Johannes Bergbc92afd2009-07-01 21:26:57 +02002089 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
2090 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
2091
2092 ieee80211_recalc_ps(local, -1);
Eliad Pellerab095872012-07-27 12:33:22 +03002093 ieee80211_recalc_ps_vif(sdata);
Johannes Bergbc92afd2009-07-01 21:26:57 +02002094
2095 return 0;
2096}
2097
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002098static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
2099 struct net_device *dev,
2100 s32 rssi_thold, u32 rssi_hyst)
2101{
2102 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002103 struct ieee80211_vif *vif = &sdata->vif;
2104 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
2105
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002106 if (rssi_thold == bss_conf->cqm_rssi_thold &&
2107 rssi_hyst == bss_conf->cqm_rssi_hyst)
2108 return 0;
2109
2110 bss_conf->cqm_rssi_thold = rssi_thold;
2111 bss_conf->cqm_rssi_hyst = rssi_hyst;
2112
2113 /* tell the driver upon association, unless already associated */
Johannes Bergea086352012-01-19 09:29:58 +01002114 if (sdata->u.mgd.associated &&
2115 sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002116 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
2117
2118 return 0;
2119}
2120
Johannes Berg99303802009-07-01 21:26:59 +02002121static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
2122 struct net_device *dev,
2123 const u8 *addr,
2124 const struct cfg80211_bitrate_mask *mask)
2125{
2126 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2127 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302128 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02002129
Eliad Peller554a43d2012-06-12 12:41:15 +03002130 if (!ieee80211_sdata_running(sdata))
2131 return -ENETDOWN;
2132
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05302133 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
2134 ret = drv_set_bitrate_mask(local, sdata, mask);
2135 if (ret)
2136 return ret;
2137 }
Johannes Berg99303802009-07-01 21:26:59 +02002138
Simon Wunderlich19468412012-01-28 17:25:33 +01002139 for (i = 0; i < IEEE80211_NUM_BANDS; i++) {
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002140 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Simon Wunderlich19468412012-01-28 17:25:33 +01002141 memcpy(sdata->rc_rateidx_mcs_mask[i], mask->control[i].mcs,
2142 sizeof(mask->control[i].mcs));
2143 }
Johannes Berg99303802009-07-01 21:26:59 +02002144
Jouni Malinen37eb0b12010-01-06 13:09:08 +02002145 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02002146}
2147
Johannes Berg2eb278e2012-06-05 14:28:42 +02002148static int ieee80211_start_roc_work(struct ieee80211_local *local,
2149 struct ieee80211_sub_if_data *sdata,
2150 struct ieee80211_channel *channel,
2151 enum nl80211_channel_type channel_type,
2152 unsigned int duration, u64 *cookie,
2153 struct sk_buff *txskb)
Johannes Berg21f83582010-12-18 17:20:47 +01002154{
Johannes Berg2eb278e2012-06-05 14:28:42 +02002155 struct ieee80211_roc_work *roc, *tmp;
2156 bool queued = false;
Johannes Berg21f83582010-12-18 17:20:47 +01002157 int ret;
Johannes Berg21f83582010-12-18 17:20:47 +01002158
2159 lockdep_assert_held(&local->mtx);
2160
Johannes Berg2eb278e2012-06-05 14:28:42 +02002161 roc = kzalloc(sizeof(*roc), GFP_KERNEL);
2162 if (!roc)
2163 return -ENOMEM;
Johannes Berg21f83582010-12-18 17:20:47 +01002164
Johannes Berg2eb278e2012-06-05 14:28:42 +02002165 roc->chan = channel;
2166 roc->chan_type = channel_type;
2167 roc->duration = duration;
2168 roc->req_duration = duration;
2169 roc->frame = txskb;
2170 roc->mgmt_tx_cookie = (unsigned long)txskb;
2171 roc->sdata = sdata;
2172 INIT_DELAYED_WORK(&roc->work, ieee80211_sw_roc_work);
2173 INIT_LIST_HEAD(&roc->dependents);
2174
2175 /* if there's one pending or we're scanning, queue this one */
2176 if (!list_empty(&local->roc_list) || local->scanning)
2177 goto out_check_combine;
2178
2179 /* if not HW assist, just queue & schedule work */
2180 if (!local->ops->remain_on_channel) {
2181 ieee80211_queue_delayed_work(&local->hw, &roc->work, 0);
2182 goto out_queue;
Johannes Berg21f83582010-12-18 17:20:47 +01002183 }
2184
Johannes Berg2eb278e2012-06-05 14:28:42 +02002185 /* otherwise actually kick it off here (for error handling) */
2186
2187 /*
2188 * If the duration is zero, then the driver
2189 * wouldn't actually do anything. Set it to
2190 * 10 for now.
2191 *
2192 * TODO: cancel the off-channel operation
2193 * when we get the SKB's TX status and
2194 * the wait time was zero before.
2195 */
2196 if (!duration)
2197 duration = 10;
2198
2199 ret = drv_remain_on_channel(local, channel, channel_type, duration);
2200 if (ret) {
2201 kfree(roc);
2202 return ret;
2203 }
2204
2205 roc->started = true;
2206 goto out_queue;
2207
2208 out_check_combine:
2209 list_for_each_entry(tmp, &local->roc_list, list) {
2210 if (tmp->chan != channel || tmp->chan_type != channel_type)
2211 continue;
2212
2213 /*
2214 * Extend this ROC if possible:
2215 *
2216 * If it hasn't started yet, just increase the duration
2217 * and add the new one to the list of dependents.
2218 */
2219 if (!tmp->started) {
2220 list_add_tail(&roc->list, &tmp->dependents);
2221 tmp->duration = max(tmp->duration, roc->duration);
2222 queued = true;
2223 break;
2224 }
2225
2226 /* If it has already started, it's more difficult ... */
2227 if (local->ops->remain_on_channel) {
2228 unsigned long j = jiffies;
2229
2230 /*
2231 * In the offloaded ROC case, if it hasn't begun, add
2232 * this new one to the dependent list to be handled
2233 * when the the master one begins. If it has begun,
2234 * check that there's still a minimum time left and
2235 * if so, start this one, transmitting the frame, but
2236 * add it to the list directly after this one with a
2237 * a reduced time so we'll ask the driver to execute
2238 * it right after finishing the previous one, in the
2239 * hope that it'll also be executed right afterwards,
2240 * effectively extending the old one.
2241 * If there's no minimum time left, just add it to the
2242 * normal list.
2243 */
2244 if (!tmp->hw_begun) {
2245 list_add_tail(&roc->list, &tmp->dependents);
2246 queued = true;
2247 break;
2248 }
2249
2250 if (time_before(j + IEEE80211_ROC_MIN_LEFT,
2251 tmp->hw_start_time +
2252 msecs_to_jiffies(tmp->duration))) {
2253 int new_dur;
2254
2255 ieee80211_handle_roc_started(roc);
2256
2257 new_dur = roc->duration -
2258 jiffies_to_msecs(tmp->hw_start_time +
2259 msecs_to_jiffies(
2260 tmp->duration) -
2261 j);
2262
2263 if (new_dur > 0) {
2264 /* add right after tmp */
2265 list_add(&roc->list, &tmp->list);
2266 } else {
2267 list_add_tail(&roc->list,
2268 &tmp->dependents);
2269 }
2270 queued = true;
2271 }
2272 } else if (del_timer_sync(&tmp->work.timer)) {
2273 unsigned long new_end;
2274
2275 /*
2276 * In the software ROC case, cancel the timer, if
2277 * that fails then the finish work is already
2278 * queued/pending and thus we queue the new ROC
2279 * normally, if that succeeds then we can extend
2280 * the timer duration and TX the frame (if any.)
2281 */
2282
2283 list_add_tail(&roc->list, &tmp->dependents);
2284 queued = true;
2285
2286 new_end = jiffies + msecs_to_jiffies(roc->duration);
2287
2288 /* ok, it was started & we canceled timer */
2289 if (time_after(new_end, tmp->work.timer.expires))
2290 mod_timer(&tmp->work.timer, new_end);
2291 else
2292 add_timer(&tmp->work.timer);
2293
2294 ieee80211_handle_roc_started(roc);
2295 }
2296 break;
2297 }
2298
2299 out_queue:
2300 if (!queued)
2301 list_add_tail(&roc->list, &local->roc_list);
2302
2303 /*
2304 * cookie is either the roc (for normal roc)
2305 * or the SKB (for mgmt TX)
2306 */
2307 if (txskb)
2308 *cookie = (unsigned long)txskb;
2309 else
2310 *cookie = (unsigned long)roc;
2311
2312 return 0;
Johannes Berg21f83582010-12-18 17:20:47 +01002313}
2314
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002315static int ieee80211_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002316 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002317 struct ieee80211_channel *chan,
2318 enum nl80211_channel_type channel_type,
2319 unsigned int duration,
2320 u64 *cookie)
2321{
Johannes Berg71bbc992012-06-15 15:30:18 +02002322 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002323 struct ieee80211_local *local = sdata->local;
Johannes Berg21f83582010-12-18 17:20:47 +01002324 int ret;
2325
Johannes Berg2eb278e2012-06-05 14:28:42 +02002326 mutex_lock(&local->mtx);
2327 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2328 duration, cookie, NULL);
2329 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002330
Johannes Berg2eb278e2012-06-05 14:28:42 +02002331 return ret;
2332}
2333
2334static int ieee80211_cancel_roc(struct ieee80211_local *local,
2335 u64 cookie, bool mgmt_tx)
2336{
2337 struct ieee80211_roc_work *roc, *tmp, *found = NULL;
2338 int ret;
2339
2340 mutex_lock(&local->mtx);
2341 list_for_each_entry_safe(roc, tmp, &local->roc_list, list) {
Johannes Berge979e332012-06-11 17:09:41 +02002342 struct ieee80211_roc_work *dep, *tmp2;
2343
2344 list_for_each_entry_safe(dep, tmp2, &roc->dependents, list) {
2345 if (!mgmt_tx && (unsigned long)dep != cookie)
2346 continue;
2347 else if (mgmt_tx && dep->mgmt_tx_cookie != cookie)
2348 continue;
2349 /* found dependent item -- just remove it */
2350 list_del(&dep->list);
2351 mutex_unlock(&local->mtx);
2352
2353 ieee80211_roc_notify_destroy(dep);
2354 return 0;
2355 }
2356
Johannes Berg2eb278e2012-06-05 14:28:42 +02002357 if (!mgmt_tx && (unsigned long)roc != cookie)
2358 continue;
2359 else if (mgmt_tx && roc->mgmt_tx_cookie != cookie)
2360 continue;
2361
2362 found = roc;
2363 break;
2364 }
2365
2366 if (!found) {
2367 mutex_unlock(&local->mtx);
Johannes Berg21f83582010-12-18 17:20:47 +01002368 return -ENOENT;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002369 }
Johannes Berg21f83582010-12-18 17:20:47 +01002370
Johannes Berge979e332012-06-11 17:09:41 +02002371 /*
2372 * We found the item to cancel, so do that. Note that it
2373 * may have dependents, which we also cancel (and send
2374 * the expired signal for.) Not doing so would be quite
2375 * tricky here, but we may need to fix it later.
2376 */
2377
Johannes Berg2eb278e2012-06-05 14:28:42 +02002378 if (local->ops->remain_on_channel) {
2379 if (found->started) {
2380 ret = drv_cancel_remain_on_channel(local);
2381 if (WARN_ON_ONCE(ret)) {
2382 mutex_unlock(&local->mtx);
2383 return ret;
2384 }
2385 }
Johannes Berg21f83582010-12-18 17:20:47 +01002386
Johannes Berg2eb278e2012-06-05 14:28:42 +02002387 list_del(&found->list);
2388
Johannes Berg0f6b3f52012-06-20 20:11:33 +02002389 if (found->started)
2390 ieee80211_start_next_roc(local);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002391 mutex_unlock(&local->mtx);
2392
2393 ieee80211_roc_notify_destroy(found);
2394 } else {
2395 /* work may be pending so use it all the time */
2396 found->abort = true;
2397 ieee80211_queue_delayed_work(&local->hw, &found->work, 0);
2398
2399 mutex_unlock(&local->mtx);
2400
2401 /* work will clean up etc */
2402 flush_delayed_work(&found->work);
2403 }
Johannes Berg21f83582010-12-18 17:20:47 +01002404
Johannes Berg21f83582010-12-18 17:20:47 +01002405 return 0;
2406}
2407
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002408static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002409 struct wireless_dev *wdev,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002410 u64 cookie)
2411{
Johannes Berg71bbc992012-06-15 15:30:18 +02002412 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg21f83582010-12-18 17:20:47 +01002413 struct ieee80211_local *local = sdata->local;
2414
Johannes Berg2eb278e2012-06-05 14:28:42 +02002415 return ieee80211_cancel_roc(local, cookie, false);
Johannes Bergf30221e2010-11-25 10:02:30 +01002416}
2417
Johannes Berg71bbc992012-06-15 15:30:18 +02002418static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002419 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f72010-08-12 15:38:38 +02002420 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002421 bool channel_type_valid, unsigned int wait,
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05302422 const u8 *buf, size_t len, bool no_cck,
Johannes Berge247bd902011-11-04 11:18:21 +01002423 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02002424{
Johannes Berg71bbc992012-06-15 15:30:18 +02002425 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg9d38d852010-06-09 17:20:33 +02002426 struct ieee80211_local *local = sdata->local;
2427 struct sk_buff *skb;
2428 struct sta_info *sta;
2429 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002430 bool need_offchan = false;
Johannes Berge247bd902011-11-04 11:18:21 +01002431 u32 flags;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002432 int ret;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01002433
Johannes Berge247bd902011-11-04 11:18:21 +01002434 if (dont_wait_for_ack)
2435 flags = IEEE80211_TX_CTL_NO_ACK;
2436 else
2437 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
2438 IEEE80211_TX_CTL_REQ_TX_STATUS;
2439
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302440 if (no_cck)
2441 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2442
Johannes Berg9d38d852010-06-09 17:20:33 +02002443 switch (sdata->vif.type) {
2444 case NL80211_IFTYPE_ADHOC:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002445 if (!sdata->vif.bss_conf.ibss_joined)
2446 need_offchan = true;
2447 /* fall through */
2448#ifdef CONFIG_MAC80211_MESH
2449 case NL80211_IFTYPE_MESH_POINT:
2450 if (ieee80211_vif_is_mesh(&sdata->vif) &&
2451 !sdata->u.mesh.mesh_id_len)
2452 need_offchan = true;
2453 /* fall through */
2454#endif
Johannes Berg663fcaf2010-09-30 21:06:09 +02002455 case NL80211_IFTYPE_AP:
2456 case NL80211_IFTYPE_AP_VLAN:
2457 case NL80211_IFTYPE_P2P_GO:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002458 if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
2459 !ieee80211_vif_is_mesh(&sdata->vif) &&
2460 !rcu_access_pointer(sdata->bss->beacon))
2461 need_offchan = true;
Johannes Berg663fcaf2010-09-30 21:06:09 +02002462 if (!ieee80211_is_action(mgmt->frame_control) ||
2463 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002464 break;
2465 rcu_read_lock();
2466 sta = sta_info_get(sdata, mgmt->da);
2467 rcu_read_unlock();
2468 if (!sta)
2469 return -ENOLINK;
2470 break;
2471 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002472 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg2eb278e2012-06-05 14:28:42 +02002473 if (!sdata->u.mgd.associated)
2474 need_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002475 break;
Johannes Bergf142c6b2012-06-18 20:07:15 +02002476 case NL80211_IFTYPE_P2P_DEVICE:
2477 need_offchan = true;
2478 break;
Johannes Berg9d38d852010-06-09 17:20:33 +02002479 default:
2480 return -EOPNOTSUPP;
2481 }
2482
Johannes Berg2eb278e2012-06-05 14:28:42 +02002483 mutex_lock(&local->mtx);
2484
2485 /* Check if the operating channel is the requested channel */
2486 if (!need_offchan) {
2487 need_offchan = chan != local->oper_channel;
2488 if (channel_type_valid &&
2489 channel_type != local->_oper_channel_type)
2490 need_offchan = true;
2491 }
2492
2493 if (need_offchan && !offchan) {
2494 ret = -EBUSY;
2495 goto out_unlock;
2496 }
2497
Johannes Berg9d38d852010-06-09 17:20:33 +02002498 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002499 if (!skb) {
2500 ret = -ENOMEM;
2501 goto out_unlock;
2502 }
Johannes Berg9d38d852010-06-09 17:20:33 +02002503 skb_reserve(skb, local->hw.extra_tx_headroom);
2504
2505 memcpy(skb_put(skb, len), buf, len);
2506
2507 IEEE80211_SKB_CB(skb)->flags = flags;
2508
Johannes Berg2eb278e2012-06-05 14:28:42 +02002509 skb->dev = sdata->dev;
2510
2511 if (!need_offchan) {
Nicolas Cavallari7f9f78a2012-07-16 18:36:52 +02002512 *cookie = (unsigned long) skb;
Johannes Berg2eb278e2012-06-05 14:28:42 +02002513 ieee80211_tx_skb(sdata, skb);
2514 ret = 0;
2515 goto out_unlock;
2516 }
2517
2518 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2519 if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
Johannes Berg3a25a8c2012-04-03 16:28:50 +02002520 IEEE80211_SKB_CB(skb)->hw_queue =
2521 local->hw.offchannel_tx_hw_queue;
2522
Johannes Berg2eb278e2012-06-05 14:28:42 +02002523 /* This will handle all kinds of coalescing and immediate TX */
2524 ret = ieee80211_start_roc_work(local, sdata, chan, channel_type,
2525 wait, cookie, skb);
2526 if (ret)
Johannes Bergf30221e2010-11-25 10:02:30 +01002527 kfree_skb(skb);
Johannes Berg2eb278e2012-06-05 14:28:42 +02002528 out_unlock:
2529 mutex_unlock(&local->mtx);
2530 return ret;
Jouni Malinen026331c2010-02-15 12:53:10 +02002531}
2532
Johannes Bergf30221e2010-11-25 10:02:30 +01002533static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002534 struct wireless_dev *wdev,
Johannes Bergf30221e2010-11-25 10:02:30 +01002535 u64 cookie)
2536{
Johannes Berg71bbc992012-06-15 15:30:18 +02002537 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergf30221e2010-11-25 10:02:30 +01002538
Johannes Berg2eb278e2012-06-05 14:28:42 +02002539 return ieee80211_cancel_roc(local, cookie, true);
Johannes Bergf30221e2010-11-25 10:02:30 +01002540}
2541
Johannes Berg7be50862010-10-13 12:06:24 +02002542static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
Johannes Berg71bbc992012-06-15 15:30:18 +02002543 struct wireless_dev *wdev,
Johannes Berg7be50862010-10-13 12:06:24 +02002544 u16 frame_type, bool reg)
2545{
2546 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg71bbc992012-06-15 15:30:18 +02002547 struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
Johannes Berg7be50862010-10-13 12:06:24 +02002548
Will Hawkins6abe0562012-06-20 11:51:14 -04002549 switch (frame_type) {
2550 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_AUTH:
2551 if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
2552 struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
Johannes Berg7be50862010-10-13 12:06:24 +02002553
Will Hawkins6abe0562012-06-20 11:51:14 -04002554 if (reg)
2555 ifibss->auth_frame_registrations++;
2556 else
2557 ifibss->auth_frame_registrations--;
2558 }
2559 break;
2560 case IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ:
2561 if (reg)
2562 local->probe_req_reg++;
2563 else
2564 local->probe_req_reg--;
Johannes Berg7be50862010-10-13 12:06:24 +02002565
Will Hawkins6abe0562012-06-20 11:51:14 -04002566 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2567 break;
2568 default:
2569 break;
2570 }
Johannes Berg7be50862010-10-13 12:06:24 +02002571}
2572
Bruno Randolf15d96752010-11-10 12:50:56 +09002573static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2574{
2575 struct ieee80211_local *local = wiphy_priv(wiphy);
2576
2577 if (local->started)
2578 return -EOPNOTSUPP;
2579
2580 return drv_set_antenna(local, tx_ant, rx_ant);
2581}
2582
2583static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2584{
2585 struct ieee80211_local *local = wiphy_priv(wiphy);
2586
2587 return drv_get_antenna(local, tx_ant, rx_ant);
2588}
2589
John W. Linville38c09152011-03-07 16:19:18 -05002590static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2591{
2592 struct ieee80211_local *local = wiphy_priv(wiphy);
2593
2594 return drv_set_ringparam(local, tx, rx);
2595}
2596
2597static void ieee80211_get_ringparam(struct wiphy *wiphy,
2598 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2599{
2600 struct ieee80211_local *local = wiphy_priv(wiphy);
2601
2602 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2603}
2604
Johannes Bergc68f4b82011-07-05 16:35:41 +02002605static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2606 struct net_device *dev,
2607 struct cfg80211_gtk_rekey_data *data)
2608{
2609 struct ieee80211_local *local = wiphy_priv(wiphy);
2610 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2611
2612 if (!local->ops->set_rekey_data)
2613 return -EOPNOTSUPP;
2614
2615 drv_set_rekey_data(local, sdata, data);
2616
2617 return 0;
2618}
2619
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002620static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2621{
2622 u8 *pos = (void *)skb_put(skb, 7);
2623
2624 *pos++ = WLAN_EID_EXT_CAPABILITY;
2625 *pos++ = 5; /* len */
2626 *pos++ = 0x0;
2627 *pos++ = 0x0;
2628 *pos++ = 0x0;
2629 *pos++ = 0x0;
2630 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2631}
2632
2633static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2634{
2635 struct ieee80211_local *local = sdata->local;
2636 u16 capab;
2637
2638 capab = 0;
2639 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2640 return capab;
2641
2642 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2643 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2644 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2645 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2646
2647 return capab;
2648}
2649
2650static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2651 u8 *peer, u8 *bssid)
2652{
2653 struct ieee80211_tdls_lnkie *lnkid;
2654
2655 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2656
2657 lnkid->ie_type = WLAN_EID_LINK_ID;
2658 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2659
2660 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2661 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2662 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2663}
2664
2665static int
2666ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2667 u8 *peer, u8 action_code, u8 dialog_token,
2668 u16 status_code, struct sk_buff *skb)
2669{
2670 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg6b778632012-07-23 14:53:27 +02002671 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002672 struct ieee80211_tdls_data *tf;
2673
2674 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2675
2676 memcpy(tf->da, peer, ETH_ALEN);
2677 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2678 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2679 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2680
2681 switch (action_code) {
2682 case WLAN_TDLS_SETUP_REQUEST:
2683 tf->category = WLAN_CATEGORY_TDLS;
2684 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2685
2686 skb_put(skb, sizeof(tf->u.setup_req));
2687 tf->u.setup_req.dialog_token = dialog_token;
2688 tf->u.setup_req.capability =
2689 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2690
Johannes Berg6b778632012-07-23 14:53:27 +02002691 ieee80211_add_srates_ie(sdata, skb, false,
2692 local->oper_channel->band);
2693 ieee80211_add_ext_srates_ie(sdata, skb, false,
2694 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002695 ieee80211_tdls_add_ext_capab(skb);
2696 break;
2697 case WLAN_TDLS_SETUP_RESPONSE:
2698 tf->category = WLAN_CATEGORY_TDLS;
2699 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2700
2701 skb_put(skb, sizeof(tf->u.setup_resp));
2702 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2703 tf->u.setup_resp.dialog_token = dialog_token;
2704 tf->u.setup_resp.capability =
2705 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2706
Johannes Berg6b778632012-07-23 14:53:27 +02002707 ieee80211_add_srates_ie(sdata, skb, false,
2708 local->oper_channel->band);
2709 ieee80211_add_ext_srates_ie(sdata, skb, false,
2710 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002711 ieee80211_tdls_add_ext_capab(skb);
2712 break;
2713 case WLAN_TDLS_SETUP_CONFIRM:
2714 tf->category = WLAN_CATEGORY_TDLS;
2715 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2716
2717 skb_put(skb, sizeof(tf->u.setup_cfm));
2718 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2719 tf->u.setup_cfm.dialog_token = dialog_token;
2720 break;
2721 case WLAN_TDLS_TEARDOWN:
2722 tf->category = WLAN_CATEGORY_TDLS;
2723 tf->action_code = WLAN_TDLS_TEARDOWN;
2724
2725 skb_put(skb, sizeof(tf->u.teardown));
2726 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2727 break;
2728 case WLAN_TDLS_DISCOVERY_REQUEST:
2729 tf->category = WLAN_CATEGORY_TDLS;
2730 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2731
2732 skb_put(skb, sizeof(tf->u.discover_req));
2733 tf->u.discover_req.dialog_token = dialog_token;
2734 break;
2735 default:
2736 return -EINVAL;
2737 }
2738
2739 return 0;
2740}
2741
2742static int
2743ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2744 u8 *peer, u8 action_code, u8 dialog_token,
2745 u16 status_code, struct sk_buff *skb)
2746{
2747 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg6b778632012-07-23 14:53:27 +02002748 struct ieee80211_local *local = sdata->local;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002749 struct ieee80211_mgmt *mgmt;
2750
2751 mgmt = (void *)skb_put(skb, 24);
2752 memset(mgmt, 0, 24);
2753 memcpy(mgmt->da, peer, ETH_ALEN);
2754 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2755 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2756
2757 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2758 IEEE80211_STYPE_ACTION);
2759
2760 switch (action_code) {
2761 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2762 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2763 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2764 mgmt->u.action.u.tdls_discover_resp.action_code =
2765 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2766 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2767 dialog_token;
2768 mgmt->u.action.u.tdls_discover_resp.capability =
2769 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2770
Johannes Berg6b778632012-07-23 14:53:27 +02002771 ieee80211_add_srates_ie(sdata, skb, false,
2772 local->oper_channel->band);
2773 ieee80211_add_ext_srates_ie(sdata, skb, false,
2774 local->oper_channel->band);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002775 ieee80211_tdls_add_ext_capab(skb);
2776 break;
2777 default:
2778 return -EINVAL;
2779 }
2780
2781 return 0;
2782}
2783
2784static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2785 u8 *peer, u8 action_code, u8 dialog_token,
2786 u16 status_code, const u8 *extra_ies,
2787 size_t extra_ies_len)
2788{
2789 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2790 struct ieee80211_local *local = sdata->local;
2791 struct ieee80211_tx_info *info;
2792 struct sk_buff *skb = NULL;
2793 bool send_direct;
2794 int ret;
2795
2796 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2797 return -ENOTSUPP;
2798
2799 /* make sure we are in managed mode, and associated */
2800 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2801 !sdata->u.mgd.associated)
2802 return -EINVAL;
2803
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002804 tdls_dbg(sdata, "TDLS mgmt action %d peer %pM\n",
2805 action_code, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002806
2807 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2808 max(sizeof(struct ieee80211_mgmt),
2809 sizeof(struct ieee80211_tdls_data)) +
2810 50 + /* supported rates */
2811 7 + /* ext capab */
2812 extra_ies_len +
2813 sizeof(struct ieee80211_tdls_lnkie));
2814 if (!skb)
2815 return -ENOMEM;
2816
2817 info = IEEE80211_SKB_CB(skb);
2818 skb_reserve(skb, local->hw.extra_tx_headroom);
2819
2820 switch (action_code) {
2821 case WLAN_TDLS_SETUP_REQUEST:
2822 case WLAN_TDLS_SETUP_RESPONSE:
2823 case WLAN_TDLS_SETUP_CONFIRM:
2824 case WLAN_TDLS_TEARDOWN:
2825 case WLAN_TDLS_DISCOVERY_REQUEST:
2826 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2827 action_code, dialog_token,
2828 status_code, skb);
2829 send_direct = false;
2830 break;
2831 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2832 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2833 dialog_token, status_code,
2834 skb);
2835 send_direct = true;
2836 break;
2837 default:
2838 ret = -ENOTSUPP;
2839 break;
2840 }
2841
2842 if (ret < 0)
2843 goto fail;
2844
2845 if (extra_ies_len)
2846 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2847
2848 /* the TDLS link IE is always added last */
2849 switch (action_code) {
2850 case WLAN_TDLS_SETUP_REQUEST:
2851 case WLAN_TDLS_SETUP_CONFIRM:
2852 case WLAN_TDLS_TEARDOWN:
2853 case WLAN_TDLS_DISCOVERY_REQUEST:
2854 /* we are the initiator */
2855 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2856 sdata->u.mgd.bssid);
2857 break;
2858 case WLAN_TDLS_SETUP_RESPONSE:
2859 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2860 /* we are the responder */
2861 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2862 sdata->u.mgd.bssid);
2863 break;
2864 default:
2865 ret = -ENOTSUPP;
2866 goto fail;
2867 }
2868
2869 if (send_direct) {
2870 ieee80211_tx_skb(sdata, skb);
2871 return 0;
2872 }
2873
2874 /*
2875 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2876 * we should default to AC_VI.
2877 */
2878 switch (action_code) {
2879 case WLAN_TDLS_SETUP_REQUEST:
2880 case WLAN_TDLS_SETUP_RESPONSE:
2881 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2882 skb->priority = 2;
2883 break;
2884 default:
2885 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2886 skb->priority = 5;
2887 break;
2888 }
2889
2890 /* disable bottom halves when entering the Tx path */
2891 local_bh_disable();
2892 ret = ieee80211_subif_start_xmit(skb, dev);
2893 local_bh_enable();
2894
2895 return ret;
2896
2897fail:
2898 dev_kfree_skb(skb);
2899 return ret;
2900}
2901
2902static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2903 u8 *peer, enum nl80211_tdls_operation oper)
2904{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002905 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002906 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2907
2908 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2909 return -ENOTSUPP;
2910
2911 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2912 return -EINVAL;
2913
Johannes Bergbdcbd8e2012-06-22 11:29:50 +02002914 tdls_dbg(sdata, "TDLS oper %d peer %pM\n", oper, peer);
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002915
2916 switch (oper) {
2917 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002918 rcu_read_lock();
2919 sta = sta_info_get(sdata, peer);
2920 if (!sta) {
2921 rcu_read_unlock();
2922 return -ENOLINK;
2923 }
2924
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002925 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002926 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002927 break;
2928 case NL80211_TDLS_DISABLE_LINK:
2929 return sta_info_destroy_addr(sdata, peer);
2930 case NL80211_TDLS_TEARDOWN:
2931 case NL80211_TDLS_SETUP:
2932 case NL80211_TDLS_DISCOVERY_REQ:
2933 /* We don't support in-driver setup/teardown/discovery */
2934 return -ENOTSUPP;
2935 default:
2936 return -ENOTSUPP;
2937 }
2938
2939 return 0;
2940}
2941
Johannes Berg06500732011-11-04 11:18:16 +01002942static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2943 const u8 *peer, u64 *cookie)
2944{
2945 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2946 struct ieee80211_local *local = sdata->local;
2947 struct ieee80211_qos_hdr *nullfunc;
2948 struct sk_buff *skb;
2949 int size = sizeof(*nullfunc);
2950 __le16 fc;
2951 bool qos;
2952 struct ieee80211_tx_info *info;
2953 struct sta_info *sta;
2954
2955 rcu_read_lock();
2956 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01002957 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01002958 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01002959 rcu_read_unlock();
2960 } else {
2961 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01002962 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01002963 }
Johannes Berg06500732011-11-04 11:18:16 +01002964
2965 if (qos) {
2966 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2967 IEEE80211_STYPE_QOS_NULLFUNC |
2968 IEEE80211_FCTL_FROMDS);
2969 } else {
2970 size -= 2;
2971 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2972 IEEE80211_STYPE_NULLFUNC |
2973 IEEE80211_FCTL_FROMDS);
2974 }
2975
2976 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2977 if (!skb)
2978 return -ENOMEM;
2979
2980 skb->dev = dev;
2981
2982 skb_reserve(skb, local->hw.extra_tx_headroom);
2983
2984 nullfunc = (void *) skb_put(skb, size);
2985 nullfunc->frame_control = fc;
2986 nullfunc->duration_id = 0;
2987 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2988 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2989 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2990 nullfunc->seq_ctrl = 0;
2991
2992 info = IEEE80211_SKB_CB(skb);
2993
2994 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2995 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2996
2997 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2998 skb->priority = 7;
2999 if (qos)
3000 nullfunc->qos_ctrl = cpu_to_le16(7);
3001
3002 local_bh_disable();
3003 ieee80211_xmit(sdata, skb);
3004 local_bh_enable();
3005
3006 *cookie = (unsigned long) skb;
3007 return 0;
3008}
3009
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003010static struct ieee80211_channel *
3011ieee80211_cfg_get_channel(struct wiphy *wiphy, struct wireless_dev *wdev,
3012 enum nl80211_channel_type *type)
3013{
3014 struct ieee80211_local *local = wiphy_priv(wiphy);
3015
3016 *type = local->_oper_channel_type;
3017 return local->oper_channel;
3018}
3019
Johannes Berg6d525632012-04-04 15:05:25 +02003020#ifdef CONFIG_PM
3021static void ieee80211_set_wakeup(struct wiphy *wiphy, bool enabled)
3022{
3023 drv_set_wakeup(wiphy_priv(wiphy), enabled);
3024}
3025#endif
3026
Jiri Bencf0706e82007-05-05 11:45:53 -07003027struct cfg80211_ops mac80211_config_ops = {
3028 .add_virtual_intf = ieee80211_add_iface,
3029 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02003030 .change_virtual_intf = ieee80211_change_iface,
Johannes Bergf142c6b2012-06-18 20:07:15 +02003031 .start_p2p_device = ieee80211_start_p2p_device,
3032 .stop_p2p_device = ieee80211_stop_p2p_device,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003033 .add_key = ieee80211_add_key,
3034 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01003035 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01003036 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02003037 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg88600202012-02-13 15:17:18 +01003038 .start_ap = ieee80211_start_ap,
3039 .change_beacon = ieee80211_change_beacon,
3040 .stop_ap = ieee80211_stop_ap,
Johannes Berg4fd69312007-12-19 02:03:35 +01003041 .add_station = ieee80211_add_station,
3042 .del_station = ieee80211_del_station,
3043 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01003044 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003045 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02003046 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003047#ifdef CONFIG_MAC80211_MESH
3048 .add_mpath = ieee80211_add_mpath,
3049 .del_mpath = ieee80211_del_mpath,
3050 .change_mpath = ieee80211_change_mpath,
3051 .get_mpath = ieee80211_get_mpath,
3052 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08003053 .update_mesh_config = ieee80211_update_mesh_config,
3054 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01003055 .join_mesh = ieee80211_join_mesh,
3056 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01003057#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03003058 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02003059 .set_txq_params = ieee80211_set_txq_params,
Johannes Berge8c9bd52012-06-06 08:18:22 +02003060 .set_monitor_channel = ieee80211_set_monitor_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05003061 .suspend = ieee80211_suspend,
3062 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01003063 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03003064 .sched_scan_start = ieee80211_sched_scan_start,
3065 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02003066 .auth = ieee80211_auth,
3067 .assoc = ieee80211_assoc,
3068 .deauth = ieee80211_deauth,
3069 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02003070 .join_ibss = ieee80211_join_ibss,
3071 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02003072 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02003073 .set_tx_power = ieee80211_set_tx_power,
3074 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02003075 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02003076 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02003077 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07003078 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02003079 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02003080 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01003081 .remain_on_channel = ieee80211_remain_on_channel,
3082 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02003083 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01003084 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02003085 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02003086 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09003087 .set_antenna = ieee80211_set_antenna,
3088 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05003089 .set_ringparam = ieee80211_set_ringparam,
3090 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02003091 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03003092 .tdls_oper = ieee80211_tdls_oper,
3093 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01003094 .probe_client = ieee80211_probe_client,
Simon Wunderlichb53be792011-11-18 14:20:44 +01003095 .set_noack_map = ieee80211_set_noack_map,
Johannes Berg6d525632012-04-04 15:05:25 +02003096#ifdef CONFIG_PM
3097 .set_wakeup = ieee80211_set_wakeup,
3098#endif
Ben Greearb1ab7922012-04-23 12:50:30 -07003099 .get_et_sset_count = ieee80211_get_et_sset_count,
3100 .get_et_stats = ieee80211_get_et_stats,
3101 .get_et_strings = ieee80211_get_et_strings,
Johannes Berg5b7ccaf2012-07-12 19:45:08 +02003102 .get_channel = ieee80211_cfg_get_channel,
Jiri Bencf0706e82007-05-05 11:45:53 -07003103};