blob: 2577c45069e5d779373646dc0c760164914ad0d5 [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 Bergf9e10ce2010-12-03 09:20:42 +010023static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
24 enum nl80211_iftype type,
25 u32 *flags,
26 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070027{
28 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010029 struct net_device *dev;
30 struct ieee80211_sub_if_data *sdata;
31 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070032
Johannes Berg05c914f2008-09-11 00:01:58 +020033 err = ieee80211_if_add(local, name, &dev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010034 if (err)
35 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010036
Johannes Bergf9e10ce2010-12-03 09:20:42 +010037 if (type == NL80211_IFTYPE_MONITOR && flags) {
38 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
39 sdata->u.mntr_flags = *flags;
40 }
41
42 return dev;
Jiri Bencf0706e82007-05-05 11:45:53 -070043}
44
Johannes Berg463d0182009-07-14 00:33:35 +020045static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
Jiri Bencf0706e82007-05-05 11:45:53 -070046{
Johannes Berg463d0182009-07-14 00:33:35 +020047 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
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 Berge8cbb4c2007-12-19 02:03:30 +0100105static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200106 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100107 struct key_params *params)
108{
Johannes Berg26a58452010-08-27 12:35:55 +0200109 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100110 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100111 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200112 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100113
Johannes Berg26a58452010-08-27 12:35:55 +0200114 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200115 return -ENETDOWN;
116
Johannes Berg97359d12010-08-10 09:46:38 +0200117 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100118 switch (params->cipher) {
119 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100120 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200121 case WLAN_CIPHER_SUITE_WEP104:
122 if (IS_ERR(sdata->local->wep_tx_tfm))
123 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200124 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100125 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200126 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100127 }
128
Johannes Berg97359d12010-08-10 09:46:38 +0200129 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
130 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100131 if (IS_ERR(key))
132 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100133
Johannes Berge31b8212010-10-05 19:39:30 +0200134 if (pairwise)
135 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
136
Johannes Bergad0e2b52010-06-01 10:19:19 +0200137 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200138
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100139 if (mac_addr) {
Thomas Pedersenff973af2011-05-03 16:57:12 -0700140 if (ieee80211_vif_is_mesh(&sdata->vif))
141 sta = sta_info_get(sdata, mac_addr);
142 else
143 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100144 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700145 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200146 err = -ENOENT;
147 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100148 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100149 }
150
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300151 err = ieee80211_key_link(key, sdata, sta);
152 if (err)
153 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100154
Johannes Berg3b967662008-04-08 17:56:52 +0200155 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200156 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200157
158 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100159}
160
161static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200162 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100163{
Johannes Berg5c0c3642011-05-12 14:31:49 +0200164 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
165 struct ieee80211_local *local = sdata->local;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100166 struct sta_info *sta;
Johannes Berg5c0c3642011-05-12 14:31:49 +0200167 struct ieee80211_key *key = NULL;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100168 int ret;
169
Johannes Berg5c0c3642011-05-12 14:31:49 +0200170 mutex_lock(&local->sta_mtx);
171 mutex_lock(&local->key_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200172
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100173 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200174 ret = -ENOENT;
175
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100176 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100177 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200178 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100179
Johannes Berg5c0c3642011-05-12 14:31:49 +0200180 if (pairwise)
Johannes Berg40b275b2011-05-13 14:15:49 +0200181 key = key_mtx_dereference(local, sta->ptk);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200182 else
Johannes Berg40b275b2011-05-13 14:15:49 +0200183 key = key_mtx_dereference(local, sta->gtk[key_idx]);
Johannes Berg5c0c3642011-05-12 14:31:49 +0200184 } else
Johannes Berg40b275b2011-05-13 14:15:49 +0200185 key = key_mtx_dereference(local, sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100186
Johannes Berg5c0c3642011-05-12 14:31:49 +0200187 if (!key) {
Johannes Berg3b967662008-04-08 17:56:52 +0200188 ret = -ENOENT;
189 goto out_unlock;
190 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100191
Johannes Berg5c0c3642011-05-12 14:31:49 +0200192 __ieee80211_key_free(key);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100193
Johannes Berg3b967662008-04-08 17:56:52 +0200194 ret = 0;
195 out_unlock:
Johannes Berg5c0c3642011-05-12 14:31:49 +0200196 mutex_unlock(&local->key_mtx);
197 mutex_unlock(&local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200198
199 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100200}
201
Johannes Berg62da92f2007-12-19 02:03:31 +0100202static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200203 u8 key_idx, bool pairwise, const u8 *mac_addr,
204 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100205 void (*callback)(void *cookie,
206 struct key_params *params))
207{
Johannes Berg14db74b2008-07-29 13:22:52 +0200208 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100209 struct sta_info *sta = NULL;
210 u8 seq[6] = {0};
211 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200212 struct ieee80211_key *key = NULL;
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200213 u64 pn64;
Johannes Berg62da92f2007-12-19 02:03:31 +0100214 u32 iv32;
215 u16 iv16;
216 int err = -ENOENT;
217
Johannes Berg14db74b2008-07-29 13:22:52 +0200218 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
219
Johannes Berg3b967662008-04-08 17:56:52 +0200220 rcu_read_lock();
221
Johannes Berg62da92f2007-12-19 02:03:31 +0100222 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100223 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100224 if (!sta)
225 goto out;
226
Johannes Berge31b8212010-10-05 19:39:30 +0200227 if (pairwise)
Johannes Berga3836e02011-05-12 15:11:37 +0200228 key = rcu_dereference(sta->ptk);
Johannes Berge31b8212010-10-05 19:39:30 +0200229 else if (key_idx < NUM_DEFAULT_KEYS)
Johannes Berga3836e02011-05-12 15:11:37 +0200230 key = rcu_dereference(sta->gtk[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100231 } else
Johannes Berga3836e02011-05-12 15:11:37 +0200232 key = rcu_dereference(sdata->keys[key_idx]);
Johannes Berg62da92f2007-12-19 02:03:31 +0100233
234 if (!key)
235 goto out;
236
237 memset(&params, 0, sizeof(params));
238
Johannes Berg97359d12010-08-10 09:46:38 +0200239 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100240
Johannes Berg97359d12010-08-10 09:46:38 +0200241 switch (key->conf.cipher) {
242 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700243 iv32 = key->u.tkip.tx.iv32;
244 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100245
Johannes Berg24487982009-04-23 18:52:52 +0200246 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
247 drv_get_tkip_seq(sdata->local,
248 key->conf.hw_key_idx,
249 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100250
251 seq[0] = iv16 & 0xff;
252 seq[1] = (iv16 >> 8) & 0xff;
253 seq[2] = iv32 & 0xff;
254 seq[3] = (iv32 >> 8) & 0xff;
255 seq[4] = (iv32 >> 16) & 0xff;
256 seq[5] = (iv32 >> 24) & 0xff;
257 params.seq = seq;
258 params.seq_len = 6;
259 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200260 case WLAN_CIPHER_SUITE_CCMP:
Johannes Bergaba83a0b2011-07-06 21:59:39 +0200261 pn64 = atomic64_read(&key->u.ccmp.tx_pn);
262 seq[0] = pn64;
263 seq[1] = pn64 >> 8;
264 seq[2] = pn64 >> 16;
265 seq[3] = pn64 >> 24;
266 seq[4] = pn64 >> 32;
267 seq[5] = pn64 >> 40;
Johannes Berg62da92f2007-12-19 02:03:31 +0100268 params.seq = seq;
269 params.seq_len = 6;
270 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200271 case WLAN_CIPHER_SUITE_AES_CMAC:
Johannes Berg75396ae2011-07-06 22:00:35 +0200272 pn64 = atomic64_read(&key->u.aes_cmac.tx_pn);
273 seq[0] = pn64;
274 seq[1] = pn64 >> 8;
275 seq[2] = pn64 >> 16;
276 seq[3] = pn64 >> 24;
277 seq[4] = pn64 >> 32;
278 seq[5] = pn64 >> 40;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200279 params.seq = seq;
280 params.seq_len = 6;
281 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100282 }
283
284 params.key = key->conf.key;
285 params.key_len = key->conf.keylen;
286
287 callback(cookie, &params);
288 err = 0;
289
290 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200291 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100292 return err;
293}
294
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100295static int ieee80211_config_default_key(struct wiphy *wiphy,
296 struct net_device *dev,
Johannes Bergdbd2fd62010-12-09 19:58:59 +0100297 u8 key_idx, bool uni,
298 bool multi)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100299{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200300 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100301
Johannes Bergf7e01042010-12-09 19:49:02 +0100302 ieee80211_set_default_key(sdata, key_idx, uni, multi);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100303
304 return 0;
305}
306
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200307static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
308 struct net_device *dev,
309 u8 key_idx)
310{
Johannes Berg66c52422010-07-22 13:58:51 +0200311 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200312
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200313 ieee80211_set_default_mgmt_key(sdata, key_idx);
314
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200315 return 0;
316}
317
Felix Fietkau3af63342011-02-27 22:08:01 +0100318static void rate_idx_to_bitrate(struct rate_info *rate, struct sta_info *sta, int idx)
319{
320 if (!(rate->flags & RATE_INFO_FLAGS_MCS)) {
321 struct ieee80211_supported_band *sband;
322 sband = sta->local->hw.wiphy->bands[
323 sta->local->hw.conf.channel->band];
324 rate->legacy = sband->bitrates[idx].bitrate;
325 } else
326 rate->mcs = idx;
327}
328
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100329static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
330{
Johannes Bergd0709a62008-02-25 16:27:46 +0100331 struct ieee80211_sub_if_data *sdata = sta->sdata;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530332 struct timespec uptime;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100333
Johannes Bergf5ea9122009-08-07 16:17:38 +0200334 sinfo->generation = sdata->local->sta_generation;
335
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100336 sinfo->filled = STATION_INFO_INACTIVE_TIME |
337 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100338 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200339 STATION_INFO_RX_PACKETS |
340 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900341 STATION_INFO_TX_RETRIES |
342 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700343 STATION_INFO_TX_BITRATE |
Felix Fietkau3af63342011-02-27 22:08:01 +0100344 STATION_INFO_RX_BITRATE |
Paul Stewartf4263c92011-03-31 09:25:41 -0700345 STATION_INFO_RX_DROP_MISC |
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530346 STATION_INFO_BSS_PARAM |
Helmut Schaa7a724762011-10-13 16:30:40 +0200347 STATION_INFO_CONNECTED_TIME |
348 STATION_INFO_STA_FLAGS;
Mohammed Shafi Shajakhanebe27c92011-04-08 21:24:24 +0530349
350 do_posix_clock_monotonic_gettime(&uptime);
351 sinfo->connected_time = uptime.tv_sec - sta->last_connected;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100352
353 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
354 sinfo->rx_bytes = sta->rx_bytes;
355 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200356 sinfo->rx_packets = sta->rx_packets;
357 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900358 sinfo->tx_retries = sta->tx_retry_count;
359 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700360 sinfo->rx_dropped_misc = sta->rx_dropped;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100361
John W. Linville19deffb2009-12-08 17:10:13 -0500362 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
363 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Bruno Randolf541a45a2010-12-02 19:12:43 +0900364 sinfo->filled |= STATION_INFO_SIGNAL | STATION_INFO_SIGNAL_AVG;
Henning Rogge420e7fa2008-12-11 22:04:19 +0100365 sinfo->signal = (s8)sta->last_signal;
Bruno Randolf541a45a2010-12-02 19:12:43 +0900366 sinfo->signal_avg = (s8) -ewma_read(&sta->avg_signal);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100367 }
368
369 sinfo->txrate.flags = 0;
370 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
371 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
372 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
373 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
374 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
375 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
Felix Fietkau3af63342011-02-27 22:08:01 +0100376 rate_idx_to_bitrate(&sinfo->txrate, sta, sta->last_tx_rate.idx);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100377
Felix Fietkau3af63342011-02-27 22:08:01 +0100378 sinfo->rxrate.flags = 0;
379 if (sta->last_rx_rate_flag & RX_FLAG_HT)
380 sinfo->rxrate.flags |= RATE_INFO_FLAGS_MCS;
381 if (sta->last_rx_rate_flag & RX_FLAG_40MHZ)
382 sinfo->rxrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
383 if (sta->last_rx_rate_flag & RX_FLAG_SHORT_GI)
384 sinfo->rxrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
385 rate_idx_to_bitrate(&sinfo->rxrate, sta, sta->last_rx_rate_idx);
Henning Rogge420e7fa2008-12-11 22:04:19 +0100386
Johannes Berg902acc72008-02-23 15:17:19 +0100387 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100388#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100389 sinfo->filled |= STATION_INFO_LLID |
390 STATION_INFO_PLID |
391 STATION_INFO_PLINK_STATE;
392
393 sinfo->llid = le16_to_cpu(sta->llid);
394 sinfo->plid = le16_to_cpu(sta->plid);
395 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100396#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100397 }
Paul Stewartf4263c92011-03-31 09:25:41 -0700398
399 sinfo->bss_param.flags = 0;
400 if (sdata->vif.bss_conf.use_cts_prot)
401 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_CTS_PROT;
402 if (sdata->vif.bss_conf.use_short_preamble)
403 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_PREAMBLE;
404 if (sdata->vif.bss_conf.use_short_slot)
405 sinfo->bss_param.flags |= BSS_PARAM_FLAGS_SHORT_SLOT_TIME;
406 sinfo->bss_param.dtim_period = sdata->local->hw.conf.ps_dtim_period;
407 sinfo->bss_param.beacon_interval = sdata->vif.bss_conf.beacon_int;
Helmut Schaa7a724762011-10-13 16:30:40 +0200408
409 sinfo->sta_flags.set = 0;
410 sinfo->sta_flags.mask = BIT(NL80211_STA_FLAG_AUTHORIZED) |
411 BIT(NL80211_STA_FLAG_SHORT_PREAMBLE) |
412 BIT(NL80211_STA_FLAG_WME) |
413 BIT(NL80211_STA_FLAG_MFP) |
Helmut Schaae4121562011-11-05 14:15:24 +0100414 BIT(NL80211_STA_FLAG_AUTHENTICATED) |
415 BIT(NL80211_STA_FLAG_TDLS_PEER);
Helmut Schaa7a724762011-10-13 16:30:40 +0200416 if (test_sta_flag(sta, WLAN_STA_AUTHORIZED))
417 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHORIZED);
418 if (test_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE))
419 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
420 if (test_sta_flag(sta, WLAN_STA_WME))
421 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_WME);
422 if (test_sta_flag(sta, WLAN_STA_MFP))
423 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_MFP);
424 if (test_sta_flag(sta, WLAN_STA_AUTH))
425 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
Helmut Schaae4121562011-11-05 14:15:24 +0100426 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER))
427 sinfo->sta_flags.set |= BIT(NL80211_STA_FLAG_TDLS_PEER);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100428}
429
430
431static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
432 int idx, u8 *mac, struct station_info *sinfo)
433{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100434 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100435 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100436 int ret = -ENOENT;
437
438 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100439
Johannes Berg3b53fde82009-11-16 12:00:37 +0100440 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100441 if (sta) {
442 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200443 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100444 sta_set_sinfo(sta, sinfo);
445 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100446
Johannes Bergd0709a62008-02-25 16:27:46 +0100447 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100448
Johannes Bergd0709a62008-02-25 16:27:46 +0100449 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100450}
451
Holger Schurig12897232010-04-19 10:23:57 +0200452static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
453 int idx, struct survey_info *survey)
454{
455 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
456
Holger Schurig12897232010-04-19 10:23:57 +0200457 return drv_get_survey(local, idx, survey);
458}
459
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100460static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100461 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100462{
Johannes Bergabe60632009-11-25 17:46:18 +0100463 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100464 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100465 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100466
Johannes Bergd0709a62008-02-25 16:27:46 +0100467 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100468
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100469 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100470 if (sta) {
471 ret = 0;
472 sta_set_sinfo(sta, sinfo);
473 }
474
475 rcu_read_unlock();
476
477 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100478}
479
Arik Nemtsov78274932011-09-04 11:11:32 +0300480static void ieee80211_config_ap_ssid(struct ieee80211_sub_if_data *sdata,
481 struct beacon_parameters *params)
482{
483 struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
484
485 bss_conf->ssid_len = params->ssid_len;
486
487 if (params->ssid_len)
488 memcpy(bss_conf->ssid, params->ssid, params->ssid_len);
489
490 bss_conf->hidden_ssid =
491 (params->hidden_ssid != NL80211_HIDDEN_SSID_NOT_IN_USE);
492}
493
Arik Nemtsov02945822011-11-10 11:28:57 +0200494static int ieee80211_set_probe_resp(struct ieee80211_sub_if_data *sdata,
495 u8 *resp, size_t resp_len)
496{
497 struct sk_buff *new, *old;
498
499 if (!resp || !resp_len)
500 return -EINVAL;
501
502 old = sdata->u.ap.probe_resp;
503
504 new = dev_alloc_skb(resp_len);
505 if (!new)
506 return -ENOMEM;
507
508 memcpy(skb_put(new, resp_len), resp, resp_len);
509
510 rcu_assign_pointer(sdata->u.ap.probe_resp, new);
511 synchronize_rcu();
512
513 if (old)
514 dev_kfree_skb(old);
515
516 return 0;
517}
518
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100519/*
520 * This handles both adding a beacon and setting new beacon info
521 */
522static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
523 struct beacon_parameters *params)
524{
525 struct beacon_data *new, *old;
526 int new_head_len, new_tail_len;
527 int size;
528 int err = -EINVAL;
Arik Nemtsov02945822011-11-10 11:28:57 +0200529 u32 changed = 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100530
Johannes Berg40b275b2011-05-13 14:15:49 +0200531 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100532
533 /* head must not be zero-length */
534 if (params->head && !params->head_len)
535 return -EINVAL;
536
537 /*
538 * This is a kludge. beacon interval should really be part
539 * of the beacon information.
540 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200541 if (params->interval &&
542 (sdata->vif.bss_conf.beacon_int != params->interval)) {
543 sdata->vif.bss_conf.beacon_int = params->interval;
544 ieee80211_bss_info_change_notify(sdata,
545 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100546 }
547
548 /* Need to have a beacon head if we don't have one yet */
549 if (!params->head && !old)
550 return err;
551
552 /* sorry, no way to start beaconing without dtim period */
553 if (!params->dtim_period && !old)
554 return err;
555
556 /* new or old head? */
557 if (params->head)
558 new_head_len = params->head_len;
559 else
560 new_head_len = old->head_len;
561
562 /* new or old tail? */
563 if (params->tail || !old)
564 /* params->tail_len will be zero for !params->tail */
565 new_tail_len = params->tail_len;
566 else
567 new_tail_len = old->tail_len;
568
569 size = sizeof(*new) + new_head_len + new_tail_len;
570
571 new = kzalloc(size, GFP_KERNEL);
572 if (!new)
573 return -ENOMEM;
574
575 /* start filling the new info now */
576
577 /* new or old dtim period? */
578 if (params->dtim_period)
579 new->dtim_period = params->dtim_period;
580 else
581 new->dtim_period = old->dtim_period;
582
583 /*
584 * pointers go into the block we allocated,
585 * memory is | beacon_data | head | tail |
586 */
587 new->head = ((u8 *) new) + sizeof(*new);
588 new->tail = new->head + new_head_len;
589 new->head_len = new_head_len;
590 new->tail_len = new_tail_len;
591
592 /* copy in head */
593 if (params->head)
594 memcpy(new->head, params->head, new_head_len);
595 else
596 memcpy(new->head, old->head, new_head_len);
597
598 /* copy in optional tail */
599 if (params->tail)
600 memcpy(new->tail, params->tail, new_tail_len);
601 else
602 if (old)
603 memcpy(new->tail, old->tail, new_tail_len);
604
Johannes Berg19885c42010-02-05 11:45:06 +0100605 sdata->vif.bss_conf.dtim_period = new->dtim_period;
606
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000607 RCU_INIT_POINTER(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100608
609 synchronize_rcu();
610
611 kfree(old);
612
Arik Nemtsov02945822011-11-10 11:28:57 +0200613 err = ieee80211_set_probe_resp(sdata, params->probe_resp,
614 params->probe_resp_len);
615 if (!err)
616 changed |= BSS_CHANGED_AP_PROBE_RESP;
Arik Nemtsov78274932011-09-04 11:11:32 +0300617
Arik Nemtsov02945822011-11-10 11:28:57 +0200618 ieee80211_config_ap_ssid(sdata, params);
619 changed |= BSS_CHANGED_BEACON_ENABLED |
620 BSS_CHANGED_BEACON |
621 BSS_CHANGED_SSID;
622
623 ieee80211_bss_info_change_notify(sdata, changed);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200624 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100625}
626
627static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
628 struct beacon_parameters *params)
629{
Johannes Berg14db74b2008-07-29 13:22:52 +0200630 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100631 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100632 struct ieee80211_sub_if_data *vlan;
633 int ret;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100634
Johannes Berg14db74b2008-07-29 13:22:52 +0200635 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
636
Johannes Berg40b275b2011-05-13 14:15:49 +0200637 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100638 if (old)
639 return -EALREADY;
640
Johannes Berg665c93a2011-11-04 11:18:11 +0100641 ret = ieee80211_config_beacon(sdata, params);
642 if (ret)
643 return ret;
644
645 /*
646 * Apply control port protocol, this allows us to
647 * not encrypt dynamic WEP control frames.
648 */
649 sdata->control_port_protocol = params->crypto.control_port_ethertype;
650 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
651 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
652 vlan->control_port_protocol =
653 params->crypto.control_port_ethertype;
654 vlan->control_port_no_encrypt =
655 params->crypto.control_port_no_encrypt;
656 }
657
658 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100659}
660
661static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
662 struct beacon_parameters *params)
663{
Johannes Berg14db74b2008-07-29 13:22:52 +0200664 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100665 struct beacon_data *old;
666
Johannes Berg14db74b2008-07-29 13:22:52 +0200667 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
668
Johannes Berg40b275b2011-05-13 14:15:49 +0200669 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100670 if (!old)
671 return -ENOENT;
672
673 return ieee80211_config_beacon(sdata, params);
674}
675
676static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
677{
Johannes Berg14db74b2008-07-29 13:22:52 +0200678 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100679 struct beacon_data *old;
680
Johannes Berg14db74b2008-07-29 13:22:52 +0200681 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
682
Johannes Berg40b275b2011-05-13 14:15:49 +0200683 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100684 if (!old)
685 return -ENOENT;
686
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000687 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100688 synchronize_rcu();
689 kfree(old);
690
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200691 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
692 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100693}
694
Johannes Berg4fd69312007-12-19 02:03:35 +0100695/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
696struct iapp_layer2_update {
697 u8 da[ETH_ALEN]; /* broadcast */
698 u8 sa[ETH_ALEN]; /* STA addr */
699 __be16 len; /* 6 */
700 u8 dsap; /* 0 */
701 u8 ssap; /* 0 */
702 u8 control;
703 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700704} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100705
706static void ieee80211_send_layer2_update(struct sta_info *sta)
707{
708 struct iapp_layer2_update *msg;
709 struct sk_buff *skb;
710
711 /* Send Level 2 Update Frame to update forwarding tables in layer 2
712 * bridge devices */
713
714 skb = dev_alloc_skb(sizeof(*msg));
715 if (!skb)
716 return;
717 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
718
719 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
720 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
721
722 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200723 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100724 msg->len = htons(6);
725 msg->dsap = 0;
726 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
727 msg->control = 0xaf; /* XID response lsb.1111F101.
728 * F=0 (no poll command; unsolicited frame) */
729 msg->xid_info[0] = 0x81; /* XID format identifier */
730 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
731 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
732
Johannes Bergd0709a62008-02-25 16:27:46 +0100733 skb->dev = sta->sdata->dev;
734 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100735 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400736 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100737}
738
739static void sta_apply_parameters(struct ieee80211_local *local,
740 struct sta_info *sta,
741 struct station_parameters *params)
742{
743 u32 rates;
744 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100745 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100746 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300747 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100748
Johannes Bergae5eb022008-10-14 16:58:37 +0200749 sband = local->hw.wiphy->bands[local->oper_channel->band];
750
Johannes Bergeccb8e82009-05-11 21:57:56 +0300751 mask = params->sta_flags_mask;
752 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100753
Johannes Bergeccb8e82009-05-11 21:57:56 +0300754 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300755 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200756 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
757 else
758 clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
Johannes Berg4fd69312007-12-19 02:03:35 +0100759 }
760
Johannes Bergeccb8e82009-05-11 21:57:56 +0300761 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300762 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200763 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
764 else
765 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300766 }
767
768 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +0300769 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200770 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +0300771 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200772 } else {
773 clear_sta_flag(sta, WLAN_STA_WME);
774 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +0300775 }
Johannes Bergeccb8e82009-05-11 21:57:56 +0300776 }
777
778 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300779 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200780 set_sta_flag(sta, WLAN_STA_MFP);
781 else
782 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300783 }
Javier Cardonab39c48f2011-04-07 15:08:30 -0700784
785 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
Javier Cardonab39c48f2011-04-07 15:08:30 -0700786 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200787 set_sta_flag(sta, WLAN_STA_AUTH);
788 else
789 clear_sta_flag(sta, WLAN_STA_AUTH);
Javier Cardonab39c48f2011-04-07 15:08:30 -0700790 }
Johannes Bergeccb8e82009-05-11 21:57:56 +0300791
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300792 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300793 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200794 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
795 else
796 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300797 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100798
Johannes Berg3b9ce802011-09-27 20:56:12 +0200799 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
800 sta->sta.uapsd_queues = params->uapsd_queues;
801 sta->sta.max_sp = params->max_sp;
802 }
Eliad Peller9533b4a2011-08-23 14:37:47 +0300803
Johannes Berg73651ee2008-02-25 16:27:47 +0100804 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200805 * cfg80211 validates this (1-2007) and allows setting the AID
806 * only when creating a new station entry
807 */
808 if (params->aid)
809 sta->sta.aid = params->aid;
810
811 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100812 * FIXME: updating the following information is racy when this
813 * function is called from ieee80211_change_station().
814 * However, all this information should be static so
815 * maybe we should just reject attemps to change it.
816 */
817
Johannes Berg4fd69312007-12-19 02:03:35 +0100818 if (params->listen_interval >= 0)
819 sta->listen_interval = params->listen_interval;
820
821 if (params->supported_rates) {
822 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100823
Johannes Berg4fd69312007-12-19 02:03:35 +0100824 for (i = 0; i < params->supported_rates_len; i++) {
825 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100826 for (j = 0; j < sband->n_bitrates; j++) {
827 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100828 rates |= BIT(j);
829 }
830 }
Johannes Berg323ce792008-09-11 02:45:11 +0200831 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100832 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100833
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200834 if (params->ht_capa)
Ben Greearef96a8422011-11-18 11:32:00 -0800835 ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
Johannes Bergae5eb022008-10-14 16:58:37 +0200836 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200837 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300838
Javier Cardona9c3990a2011-05-03 16:57:11 -0700839 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -0400840#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -0700841 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
842 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700843 case NL80211_PLINK_LISTEN:
844 case NL80211_PLINK_ESTAB:
845 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -0700846 sta->plink_state = params->plink_state;
847 break;
848 default:
849 /* nothing */
850 break;
851 }
852 else
853 switch (params->plink_action) {
854 case PLINK_ACTION_OPEN:
855 mesh_plink_open(sta);
856 break;
857 case PLINK_ACTION_BLOCK:
858 mesh_plink_block(sta);
859 break;
860 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -0400861#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100862 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100863}
864
865static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
866 u8 *mac, struct station_parameters *params)
867{
Johannes Berg14db74b2008-07-29 13:22:52 +0200868 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100869 struct sta_info *sta;
870 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100871 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200872 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100873
Johannes Berg4fd69312007-12-19 02:03:35 +0100874 if (params->vlan) {
875 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
876
Johannes Berg05c914f2008-09-11 00:01:58 +0200877 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
878 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100879 return -EINVAL;
880 } else
881 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
882
Johannes Berg47846c92009-11-25 17:46:19 +0100883 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100884 return -EINVAL;
885
886 if (is_multicast_ether_addr(mac))
887 return -EINVAL;
888
Jouni Malinene3a4cc22011-10-23 22:36:04 +0300889 /* Only TDLS-supporting stations can add TDLS peers */
890 if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
891 !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
892 sdata->vif.type == NL80211_IFTYPE_STATION))
893 return -ENOTSUPP;
894
Johannes Berg03e44972008-02-27 09:56:40 +0100895 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100896 if (!sta)
897 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100898
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200899 set_sta_flag(sta, WLAN_STA_AUTH);
900 set_sta_flag(sta, WLAN_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +0100901
902 sta_apply_parameters(local, sta, params);
903
Arik Nemtsovd64cf632011-11-07 23:24:39 +0200904 /*
905 * for TDLS, rate control should be initialized only when supported
906 * rates are known.
907 */
908 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
909 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100910
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200911 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
912 sdata->vif.type == NL80211_IFTYPE_AP;
913
Johannes Berg34e89502010-02-03 13:59:58 +0100914 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100915 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100916 rcu_read_unlock();
917 return err;
918 }
919
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200920 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100921 ieee80211_send_layer2_update(sta);
922
923 rcu_read_unlock();
924
Johannes Berg4fd69312007-12-19 02:03:35 +0100925 return 0;
926}
927
928static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
929 u8 *mac)
930{
Johannes Berg14db74b2008-07-29 13:22:52 +0200931 struct ieee80211_local *local = wiphy_priv(wiphy);
932 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100933
Johannes Berg14db74b2008-07-29 13:22:52 +0200934 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
935
Johannes Berg34e89502010-02-03 13:59:58 +0100936 if (mac)
937 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200938
Johannes Berg34e89502010-02-03 13:59:58 +0100939 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100940 return 0;
941}
942
943static int ieee80211_change_station(struct wiphy *wiphy,
944 struct net_device *dev,
945 u8 *mac,
946 struct station_parameters *params)
947{
Johannes Bergabe60632009-11-25 17:46:18 +0100948 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200949 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100950 struct sta_info *sta;
951 struct ieee80211_sub_if_data *vlansdata;
952
Johannes Berg98dd6a52008-04-10 15:36:09 +0200953 rcu_read_lock();
954
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100955 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200956 if (!sta) {
957 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100958 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200959 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100960
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300961 /* The TDLS bit cannot be toggled after the STA was added */
962 if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
963 !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200964 !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300965 rcu_read_unlock();
966 return -EINVAL;
967 }
968
Johannes Bergd0709a62008-02-25 16:27:46 +0100969 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100970 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
971
Johannes Berg05c914f2008-09-11 00:01:58 +0200972 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
973 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200974 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100975 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200976 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100977
Johannes Berg9bc383d2009-11-19 11:55:19 +0100978 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100979 if (vlansdata->u.vlan.sta) {
980 rcu_read_unlock();
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100981 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100982 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100983
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000984 RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100985 }
986
Johannes Berg14db74b2008-07-29 13:22:52 +0200987 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100988 ieee80211_send_layer2_update(sta);
989 }
990
991 sta_apply_parameters(local, sta, params);
992
Arik Nemtsovd64cf632011-11-07 23:24:39 +0200993 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
994 rate_control_rate_init(sta);
995
Johannes Berg98dd6a52008-04-10 15:36:09 +0200996 rcu_read_unlock();
997
Jason Young808118c2011-03-10 16:43:19 -0800998 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
999 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
1000 ieee80211_recalc_ps(local, -1);
1001
Johannes Berg4fd69312007-12-19 02:03:35 +01001002 return 0;
1003}
1004
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001005#ifdef CONFIG_MAC80211_MESH
1006static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
1007 u8 *dst, u8 *next_hop)
1008{
Johannes Berg14db74b2008-07-29 13:22:52 +02001009 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001010 struct mesh_path *mpath;
1011 struct sta_info *sta;
1012 int err;
1013
Johannes Berg14db74b2008-07-29 13:22:52 +02001014 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1015
Johannes Bergd0709a62008-02-25 16:27:46 +01001016 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +01001017 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001018 if (!sta) {
1019 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001020 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +01001021 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001022
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001023 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +01001024 if (err) {
1025 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001026 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +01001027 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001028
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001029 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001030 if (!mpath) {
1031 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001032 return -ENXIO;
1033 }
1034 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001035
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001036 rcu_read_unlock();
1037 return 0;
1038}
1039
1040static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1041 u8 *dst)
1042{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001043 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001044
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001045 if (dst)
1046 return mesh_path_del(dst, sdata);
1047
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001048 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001049 return 0;
1050}
1051
1052static int ieee80211_change_mpath(struct wiphy *wiphy,
1053 struct net_device *dev,
1054 u8 *dst, u8 *next_hop)
1055{
Johannes Berg14db74b2008-07-29 13:22:52 +02001056 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001057 struct mesh_path *mpath;
1058 struct sta_info *sta;
1059
Johannes Berg14db74b2008-07-29 13:22:52 +02001060 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1061
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001062 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001063
Johannes Bergabe60632009-11-25 17:46:18 +01001064 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001065 if (!sta) {
1066 rcu_read_unlock();
1067 return -ENOENT;
1068 }
1069
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001070 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001071 if (!mpath) {
1072 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001073 return -ENOENT;
1074 }
1075
1076 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001077
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001078 rcu_read_unlock();
1079 return 0;
1080}
1081
1082static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1083 struct mpath_info *pinfo)
1084{
Johannes Berga3836e02011-05-12 15:11:37 +02001085 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1086
1087 if (next_hop_sta)
1088 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001089 else
1090 memset(next_hop, 0, ETH_ALEN);
1091
Johannes Bergf5ea9122009-08-07 16:17:38 +02001092 pinfo->generation = mesh_paths_generation;
1093
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001094 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001095 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001096 MPATH_INFO_METRIC |
1097 MPATH_INFO_EXPTIME |
1098 MPATH_INFO_DISCOVERY_TIMEOUT |
1099 MPATH_INFO_DISCOVERY_RETRIES |
1100 MPATH_INFO_FLAGS;
1101
1102 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001103 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001104 pinfo->metric = mpath->metric;
1105 if (time_before(jiffies, mpath->exp_time))
1106 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1107 pinfo->discovery_timeout =
1108 jiffies_to_msecs(mpath->discovery_timeout);
1109 pinfo->discovery_retries = mpath->discovery_retries;
1110 pinfo->flags = 0;
1111 if (mpath->flags & MESH_PATH_ACTIVE)
1112 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1113 if (mpath->flags & MESH_PATH_RESOLVING)
1114 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001115 if (mpath->flags & MESH_PATH_SN_VALID)
1116 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001117 if (mpath->flags & MESH_PATH_FIXED)
1118 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1119 if (mpath->flags & MESH_PATH_RESOLVING)
1120 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1121
1122 pinfo->flags = mpath->flags;
1123}
1124
1125static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1126 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1127
1128{
Johannes Berg14db74b2008-07-29 13:22:52 +02001129 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001130 struct mesh_path *mpath;
1131
Johannes Berg14db74b2008-07-29 13:22:52 +02001132 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1133
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001134 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001135 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001136 if (!mpath) {
1137 rcu_read_unlock();
1138 return -ENOENT;
1139 }
1140 memcpy(dst, mpath->dst, ETH_ALEN);
1141 mpath_set_pinfo(mpath, next_hop, pinfo);
1142 rcu_read_unlock();
1143 return 0;
1144}
1145
1146static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1147 int idx, u8 *dst, u8 *next_hop,
1148 struct mpath_info *pinfo)
1149{
Johannes Berg14db74b2008-07-29 13:22:52 +02001150 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001151 struct mesh_path *mpath;
1152
Johannes Berg14db74b2008-07-29 13:22:52 +02001153 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1154
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001155 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001156 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001157 if (!mpath) {
1158 rcu_read_unlock();
1159 return -ENOENT;
1160 }
1161 memcpy(dst, mpath->dst, ETH_ALEN);
1162 mpath_set_pinfo(mpath, next_hop, pinfo);
1163 rcu_read_unlock();
1164 return 0;
1165}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001166
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001167static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001168 struct net_device *dev,
1169 struct mesh_config *conf)
1170{
1171 struct ieee80211_sub_if_data *sdata;
1172 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1173
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001174 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1175 return 0;
1176}
1177
1178static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1179{
1180 return (mask >> (parm-1)) & 0x1;
1181}
1182
Javier Cardonac80d5452010-12-16 17:37:49 -08001183static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1184 const struct mesh_setup *setup)
1185{
1186 u8 *new_ie;
1187 const u8 *old_ie;
1188
Javier Cardona581a8b02011-04-07 15:08:27 -07001189 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001190 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001191 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001192
Javier Cardona581a8b02011-04-07 15:08:27 -07001193 if (setup->ie_len) {
1194 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001195 GFP_KERNEL);
1196 if (!new_ie)
1197 return -ENOMEM;
1198 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001199 ifmsh->ie_len = setup->ie_len;
1200 ifmsh->ie = new_ie;
1201 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001202
1203 /* now copy the rest of the setup parameters */
1204 ifmsh->mesh_id_len = setup->mesh_id_len;
1205 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1206 ifmsh->mesh_pp_id = setup->path_sel_proto;
1207 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001208 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1209 if (setup->is_authenticated)
1210 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1211 if (setup->is_secure)
1212 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001213
1214 return 0;
1215}
1216
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001217static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001218 struct net_device *dev, u32 mask,
1219 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001220{
1221 struct mesh_config *conf;
1222 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001223 struct ieee80211_if_mesh *ifmsh;
1224
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001225 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001226 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001227
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001228 /* Set the config options which we are interested in setting */
1229 conf = &(sdata->u.mesh.mshcfg);
1230 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1231 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1232 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1233 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1234 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1235 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1236 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1237 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1238 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1239 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1240 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1241 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001242 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1243 conf->dot11MeshTTL = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001244 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1245 conf->auto_open_plinks = nconf->auto_open_plinks;
1246 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1247 conf->dot11MeshHWMPmaxPREQretries =
1248 nconf->dot11MeshHWMPmaxPREQretries;
1249 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1250 conf->path_refresh_time = nconf->path_refresh_time;
1251 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1252 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1253 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1254 conf->dot11MeshHWMPactivePathTimeout =
1255 nconf->dot11MeshHWMPactivePathTimeout;
1256 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1257 conf->dot11MeshHWMPpreqMinInterval =
1258 nconf->dot11MeshHWMPpreqMinInterval;
1259 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1260 mask))
1261 conf->dot11MeshHWMPnetDiameterTraversalTime =
1262 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001263 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1264 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1265 ieee80211_mesh_root_setup(ifmsh);
1266 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001267 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc6133662011-08-25 10:36:14 -07001268 /* our current gate announcement implementation rides on root
1269 * announcements, so require this ifmsh to also be a root node
1270 * */
1271 if (nconf->dot11MeshGateAnnouncementProtocol &&
1272 !conf->dot11MeshHWMPRootMode) {
1273 conf->dot11MeshHWMPRootMode = 1;
1274 ieee80211_mesh_root_setup(ifmsh);
1275 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001276 conf->dot11MeshGateAnnouncementProtocol =
1277 nconf->dot11MeshGateAnnouncementProtocol;
1278 }
Javier Cardona0507e152011-08-09 16:45:10 -07001279 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1280 conf->dot11MeshHWMPRannInterval =
1281 nconf->dot11MeshHWMPRannInterval;
1282 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001283 return 0;
1284}
1285
Johannes Berg29cbe682010-12-03 09:20:44 +01001286static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1287 const struct mesh_config *conf,
1288 const struct mesh_setup *setup)
1289{
1290 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1291 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001292 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001293
Javier Cardonac80d5452010-12-16 17:37:49 -08001294 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1295 err = copy_mesh_setup(ifmsh, setup);
1296 if (err)
1297 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001298 ieee80211_start_mesh(sdata);
1299
1300 return 0;
1301}
1302
1303static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1304{
1305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1306
1307 ieee80211_stop_mesh(sdata);
1308
1309 return 0;
1310}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001311#endif
1312
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001313static int ieee80211_change_bss(struct wiphy *wiphy,
1314 struct net_device *dev,
1315 struct bss_parameters *params)
1316{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001317 struct ieee80211_sub_if_data *sdata;
1318 u32 changed = 0;
1319
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001320 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1321
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001322 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001323 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001324 changed |= BSS_CHANGED_ERP_CTS_PROT;
1325 }
1326 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001327 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001328 params->use_short_preamble;
1329 changed |= BSS_CHANGED_ERP_PREAMBLE;
1330 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001331
1332 if (!sdata->vif.bss_conf.use_short_slot &&
1333 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1334 sdata->vif.bss_conf.use_short_slot = true;
1335 changed |= BSS_CHANGED_ERP_SLOT;
1336 }
1337
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001338 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001339 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001340 params->use_short_slot_time;
1341 changed |= BSS_CHANGED_ERP_SLOT;
1342 }
1343
Jouni Malinen90c97a02008-10-30 16:59:22 +02001344 if (params->basic_rates) {
1345 int i, j;
1346 u32 rates = 0;
1347 struct ieee80211_local *local = wiphy_priv(wiphy);
1348 struct ieee80211_supported_band *sband =
1349 wiphy->bands[local->oper_channel->band];
1350
1351 for (i = 0; i < params->basic_rates_len; i++) {
1352 int rate = (params->basic_rates[i] & 0x7f) * 5;
1353 for (j = 0; j < sband->n_bitrates; j++) {
1354 if (sband->bitrates[j].bitrate == rate)
1355 rates |= BIT(j);
1356 }
1357 }
1358 sdata->vif.bss_conf.basic_rates = rates;
1359 changed |= BSS_CHANGED_BASIC_RATES;
1360 }
1361
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001362 if (params->ap_isolate >= 0) {
1363 if (params->ap_isolate)
1364 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1365 else
1366 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1367 }
1368
Helmut Schaa80d7e402010-11-19 12:40:26 +01001369 if (params->ht_opmode >= 0) {
1370 sdata->vif.bss_conf.ht_operation_mode =
1371 (u16) params->ht_opmode;
1372 changed |= BSS_CHANGED_HT;
1373 }
1374
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001375 ieee80211_bss_info_change_notify(sdata, changed);
1376
1377 return 0;
1378}
1379
Jouni Malinen31888482008-10-30 16:59:24 +02001380static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001381 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001382 struct ieee80211_txq_params *params)
1383{
1384 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001385 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001386 struct ieee80211_tx_queue_params p;
1387
1388 if (!local->ops->conf_tx)
1389 return -EOPNOTSUPP;
1390
1391 memset(&p, 0, sizeof(p));
1392 p.aifs = params->aifs;
1393 p.cw_max = params->cwmax;
1394 p.cw_min = params->cwmin;
1395 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001396
1397 /*
1398 * Setting tx queue params disables u-apsd because it's only
1399 * called in master mode.
1400 */
1401 p.uapsd = false;
1402
Eliad Peller2683d652011-07-14 20:29:42 +03001403 if (params->queue >= local->hw.queues)
1404 return -EINVAL;
1405
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001406 sdata->tx_conf[params->queue] = p;
1407 if (drv_conf_tx(local, sdata, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001408 wiphy_debug(local->hw.wiphy,
1409 "failed to set TX queue parameters for queue %d\n",
1410 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001411 return -EINVAL;
1412 }
1413
1414 return 0;
1415}
1416
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001417static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001418 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001419 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301420 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001421{
1422 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001423 struct ieee80211_sub_if_data *sdata = NULL;
Ben Greeareeabee72011-01-28 10:20:47 -08001424 struct ieee80211_channel *old_oper;
1425 enum nl80211_channel_type old_oper_type;
1426 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001427
1428 if (netdev)
1429 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001430
Johannes Bergf444de02010-05-05 15:25:02 +02001431 switch (ieee80211_get_channel_mode(local, NULL)) {
1432 case CHAN_MODE_HOPPING:
1433 return -EBUSY;
1434 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001435 if (local->oper_channel != chan)
1436 return -EBUSY;
1437 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001438 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001439 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001440 case CHAN_MODE_UNDEFINED:
1441 break;
1442 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001443
Ben Greeareeabee72011-01-28 10:20:47 -08001444 if (sdata)
1445 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1446 old_oper_type = local->_oper_channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001447
Johannes Berg0aaffa92010-05-05 15:28:27 +02001448 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1449 return -EBUSY;
1450
Ben Greeareeabee72011-01-28 10:20:47 -08001451 old_oper = local->oper_channel;
1452 local->oper_channel = chan;
1453
1454 /* Update driver if changes were actually made. */
1455 if ((old_oper != local->oper_channel) ||
1456 (old_oper_type != local->_oper_channel_type))
1457 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1458
Johannes Bergef5af742011-10-18 13:39:14 +02001459 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
Ben Greeareeabee72011-01-28 10:20:47 -08001460 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
Johannes Berg0aaffa92010-05-05 15:28:27 +02001461 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1462
1463 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001464}
1465
Bob Copeland665af4f2009-01-19 11:20:53 -05001466#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001467static int ieee80211_suspend(struct wiphy *wiphy,
1468 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001469{
Johannes Bergeecc4802011-05-04 15:37:29 +02001470 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001471}
1472
1473static int ieee80211_resume(struct wiphy *wiphy)
1474{
1475 return __ieee80211_resume(wiphy_priv(wiphy));
1476}
1477#else
1478#define ieee80211_suspend NULL
1479#define ieee80211_resume NULL
1480#endif
1481
Johannes Berg2a519312009-02-10 21:25:55 +01001482static int ieee80211_scan(struct wiphy *wiphy,
1483 struct net_device *dev,
1484 struct cfg80211_scan_request *req)
1485{
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001486 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg2a519312009-02-10 21:25:55 +01001487
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001488 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1489 case NL80211_IFTYPE_STATION:
1490 case NL80211_IFTYPE_ADHOC:
1491 case NL80211_IFTYPE_MESH_POINT:
1492 case NL80211_IFTYPE_P2P_CLIENT:
1493 break;
1494 case NL80211_IFTYPE_P2P_GO:
1495 if (sdata->local->ops->hw_scan)
1496 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001497 /*
1498 * FIXME: implement NoA while scanning in software,
1499 * for now fall through to allow scanning only when
1500 * beaconing hasn't been configured yet
1501 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001502 case NL80211_IFTYPE_AP:
1503 if (sdata->u.ap.beacon)
1504 return -EOPNOTSUPP;
1505 break;
1506 default:
1507 return -EOPNOTSUPP;
1508 }
Johannes Berg2a519312009-02-10 21:25:55 +01001509
1510 return ieee80211_request_scan(sdata, req);
1511}
1512
Luciano Coelho79f460c2011-05-11 17:09:36 +03001513static int
1514ieee80211_sched_scan_start(struct wiphy *wiphy,
1515 struct net_device *dev,
1516 struct cfg80211_sched_scan_request *req)
1517{
1518 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1519
1520 if (!sdata->local->ops->sched_scan_start)
1521 return -EOPNOTSUPP;
1522
1523 return ieee80211_request_sched_scan_start(sdata, req);
1524}
1525
1526static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001527ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001528{
1529 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1530
1531 if (!sdata->local->ops->sched_scan_stop)
1532 return -EOPNOTSUPP;
1533
Luciano Coelho85a99942011-05-12 16:28:29 +03001534 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001535}
1536
Jouni Malinen636a5d32009-03-19 13:39:22 +02001537static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1538 struct cfg80211_auth_request *req)
1539{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001540 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001541}
1542
1543static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1544 struct cfg80211_assoc_request *req)
1545{
Johannes Bergf444de02010-05-05 15:25:02 +02001546 struct ieee80211_local *local = wiphy_priv(wiphy);
1547 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1548
1549 switch (ieee80211_get_channel_mode(local, sdata)) {
1550 case CHAN_MODE_HOPPING:
1551 return -EBUSY;
1552 case CHAN_MODE_FIXED:
1553 if (local->oper_channel == req->bss->channel)
1554 break;
1555 return -EBUSY;
1556 case CHAN_MODE_UNDEFINED:
1557 break;
1558 }
1559
Johannes Berg77fdaa12009-07-07 03:45:17 +02001560 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001561}
1562
1563static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001564 struct cfg80211_deauth_request *req,
1565 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001566{
Johannes Berg667503d2009-07-07 03:56:11 +02001567 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1568 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001569}
1570
1571static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001572 struct cfg80211_disassoc_request *req,
1573 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001574{
Johannes Berg667503d2009-07-07 03:56:11 +02001575 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1576 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001577}
1578
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001579static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1580 struct cfg80211_ibss_params *params)
1581{
Johannes Bergf444de02010-05-05 15:25:02 +02001582 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001583 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1584
Johannes Bergf444de02010-05-05 15:25:02 +02001585 switch (ieee80211_get_channel_mode(local, sdata)) {
1586 case CHAN_MODE_HOPPING:
1587 return -EBUSY;
1588 case CHAN_MODE_FIXED:
1589 if (!params->channel_fixed)
1590 return -EBUSY;
1591 if (local->oper_channel == params->channel)
1592 break;
1593 return -EBUSY;
1594 case CHAN_MODE_UNDEFINED:
1595 break;
1596 }
1597
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001598 return ieee80211_ibss_join(sdata, params);
1599}
1600
1601static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1602{
1603 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1604
1605 return ieee80211_ibss_leave(sdata);
1606}
1607
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001608static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1609{
1610 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001611 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001612
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001613 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1614 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1615
1616 if (err)
1617 return err;
1618 }
1619
Lukáš Turek310bc672009-12-21 22:50:48 +01001620 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1621 err = drv_set_coverage_class(local, wiphy->coverage_class);
1622
1623 if (err)
1624 return err;
1625 }
1626
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001627 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001628 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001629
Johannes Berg24487982009-04-23 18:52:52 +02001630 if (err)
1631 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001632 }
1633
1634 if (changed & WIPHY_PARAM_RETRY_SHORT)
1635 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1636 if (changed & WIPHY_PARAM_RETRY_LONG)
1637 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1638 if (changed &
1639 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1640 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1641
1642 return 0;
1643}
1644
Johannes Berg7643a2c2009-06-02 13:01:39 +02001645static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001646 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001647{
1648 struct ieee80211_local *local = wiphy_priv(wiphy);
1649 struct ieee80211_channel *chan = local->hw.conf.channel;
1650 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001651
1652 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001653 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001654 local->user_power_level = -1;
1655 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001656 case NL80211_TX_POWER_LIMITED:
1657 if (mbm < 0 || (mbm % 100))
1658 return -EOPNOTSUPP;
1659 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001660 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001661 case NL80211_TX_POWER_FIXED:
1662 if (mbm < 0 || (mbm % 100))
1663 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001664 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001665 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001666 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001667 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001668 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001669 }
1670
1671 ieee80211_hw_config(local, changes);
1672
1673 return 0;
1674}
1675
1676static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1677{
1678 struct ieee80211_local *local = wiphy_priv(wiphy);
1679
1680 *dbm = local->hw.conf.power_level;
1681
Johannes Berg7643a2c2009-06-02 13:01:39 +02001682 return 0;
1683}
1684
Johannes Bergab737a42009-07-01 21:26:58 +02001685static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02001686 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02001687{
1688 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1689
1690 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1691
1692 return 0;
1693}
1694
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001695static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1696{
1697 struct ieee80211_local *local = wiphy_priv(wiphy);
1698
1699 drv_rfkill_poll(local);
1700}
1701
Johannes Bergaff89a92009-07-01 21:26:51 +02001702#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001703static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001704{
1705 struct ieee80211_local *local = wiphy_priv(wiphy);
1706
1707 if (!local->ops->testmode_cmd)
1708 return -EOPNOTSUPP;
1709
1710 return local->ops->testmode_cmd(&local->hw, data, len);
1711}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07001712
1713static int ieee80211_testmode_dump(struct wiphy *wiphy,
1714 struct sk_buff *skb,
1715 struct netlink_callback *cb,
1716 void *data, int len)
1717{
1718 struct ieee80211_local *local = wiphy_priv(wiphy);
1719
1720 if (!local->ops->testmode_dump)
1721 return -EOPNOTSUPP;
1722
1723 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1724}
Johannes Bergaff89a92009-07-01 21:26:51 +02001725#endif
1726
Johannes Berg0f782312009-12-01 13:37:02 +01001727int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1728 enum ieee80211_smps_mode smps_mode)
1729{
1730 const u8 *ap;
1731 enum ieee80211_smps_mode old_req;
1732 int err;
1733
Johannes Berg243e6df2011-04-19 20:44:04 +02001734 lockdep_assert_held(&sdata->u.mgd.mtx);
1735
Johannes Berg0f782312009-12-01 13:37:02 +01001736 old_req = sdata->u.mgd.req_smps;
1737 sdata->u.mgd.req_smps = smps_mode;
1738
1739 if (old_req == smps_mode &&
1740 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1741 return 0;
1742
1743 /*
1744 * If not associated, or current association is not an HT
1745 * association, there's no need to send an action frame.
1746 */
1747 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001748 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001749 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02001750 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01001751 mutex_unlock(&sdata->local->iflist_mtx);
1752 return 0;
1753 }
1754
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001755 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001756
1757 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1758 if (sdata->u.mgd.powersave)
1759 smps_mode = IEEE80211_SMPS_DYNAMIC;
1760 else
1761 smps_mode = IEEE80211_SMPS_OFF;
1762 }
1763
1764 /* send SM PS frame to AP */
1765 err = ieee80211_send_smps_action(sdata, smps_mode,
1766 ap, ap);
1767 if (err)
1768 sdata->u.mgd.req_smps = old_req;
1769
1770 return err;
1771}
1772
Johannes Bergbc92afd2009-07-01 21:26:57 +02001773static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1774 bool enabled, int timeout)
1775{
1776 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1777 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001778
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001779 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1780 return -EOPNOTSUPP;
1781
Johannes Bergbc92afd2009-07-01 21:26:57 +02001782 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1783 return -EOPNOTSUPP;
1784
1785 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001786 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001787 return 0;
1788
1789 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001790 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001791
Johannes Berg0f782312009-12-01 13:37:02 +01001792 /* no change, but if automatic follow powersave */
1793 mutex_lock(&sdata->u.mgd.mtx);
1794 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1795 mutex_unlock(&sdata->u.mgd.mtx);
1796
Johannes Bergbc92afd2009-07-01 21:26:57 +02001797 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1798 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1799
1800 ieee80211_recalc_ps(local, -1);
1801
1802 return 0;
1803}
1804
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001805static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1806 struct net_device *dev,
1807 s32 rssi_thold, u32 rssi_hyst)
1808{
1809 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1810 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1811 struct ieee80211_vif *vif = &sdata->vif;
1812 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1813
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001814 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1815 rssi_hyst == bss_conf->cqm_rssi_hyst)
1816 return 0;
1817
1818 bss_conf->cqm_rssi_thold = rssi_thold;
1819 bss_conf->cqm_rssi_hyst = rssi_hyst;
1820
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001821 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1822 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1823 return -EOPNOTSUPP;
1824 return 0;
1825 }
1826
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001827 /* tell the driver upon association, unless already associated */
1828 if (sdata->u.mgd.associated)
1829 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1830
1831 return 0;
1832}
1833
Johannes Berg99303802009-07-01 21:26:59 +02001834static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1835 struct net_device *dev,
1836 const u8 *addr,
1837 const struct cfg80211_bitrate_mask *mask)
1838{
1839 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1840 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05301841 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02001842
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05301843 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1844 ret = drv_set_bitrate_mask(local, sdata, mask);
1845 if (ret)
1846 return ret;
1847 }
Johannes Berg99303802009-07-01 21:26:59 +02001848
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001849 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1850 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001851
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001852 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001853}
1854
Johannes Berg21f83582010-12-18 17:20:47 +01001855static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
1856 struct net_device *dev,
1857 struct ieee80211_channel *chan,
1858 enum nl80211_channel_type chantype,
1859 unsigned int duration, u64 *cookie)
1860{
1861 int ret;
1862 u32 random_cookie;
1863
1864 lockdep_assert_held(&local->mtx);
1865
1866 if (local->hw_roc_cookie)
1867 return -EBUSY;
1868 /* must be nonzero */
1869 random_cookie = random32() | 1;
1870
1871 *cookie = random_cookie;
1872 local->hw_roc_dev = dev;
1873 local->hw_roc_cookie = random_cookie;
1874 local->hw_roc_channel = chan;
1875 local->hw_roc_channel_type = chantype;
1876 local->hw_roc_duration = duration;
1877 ret = drv_remain_on_channel(local, chan, chantype, duration);
1878 if (ret) {
1879 local->hw_roc_channel = NULL;
1880 local->hw_roc_cookie = 0;
1881 }
1882
1883 return ret;
1884}
1885
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001886static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1887 struct net_device *dev,
1888 struct ieee80211_channel *chan,
1889 enum nl80211_channel_type channel_type,
1890 unsigned int duration,
1891 u64 *cookie)
1892{
1893 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg21f83582010-12-18 17:20:47 +01001894 struct ieee80211_local *local = sdata->local;
1895
1896 if (local->ops->remain_on_channel) {
1897 int ret;
1898
1899 mutex_lock(&local->mtx);
1900 ret = ieee80211_remain_on_channel_hw(local, dev,
1901 chan, channel_type,
1902 duration, cookie);
Johannes Berg90fc4b32010-12-18 17:20:48 +01001903 local->hw_roc_for_tx = false;
Johannes Berg21f83582010-12-18 17:20:47 +01001904 mutex_unlock(&local->mtx);
1905
1906 return ret;
1907 }
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001908
1909 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1910 duration, cookie);
1911}
1912
Johannes Berg21f83582010-12-18 17:20:47 +01001913static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1914 u64 cookie)
1915{
1916 int ret;
1917
1918 lockdep_assert_held(&local->mtx);
1919
1920 if (local->hw_roc_cookie != cookie)
1921 return -ENOENT;
1922
1923 ret = drv_cancel_remain_on_channel(local);
1924 if (ret)
1925 return ret;
1926
1927 local->hw_roc_cookie = 0;
1928 local->hw_roc_channel = NULL;
1929
1930 ieee80211_recalc_idle(local);
1931
1932 return 0;
1933}
1934
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001935static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1936 struct net_device *dev,
1937 u64 cookie)
1938{
1939 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg21f83582010-12-18 17:20:47 +01001940 struct ieee80211_local *local = sdata->local;
1941
1942 if (local->ops->cancel_remain_on_channel) {
1943 int ret;
1944
1945 mutex_lock(&local->mtx);
1946 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
1947 mutex_unlock(&local->mtx);
1948
1949 return ret;
1950 }
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001951
1952 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1953}
1954
Johannes Bergf30221e2010-11-25 10:02:30 +01001955static enum work_done_result
1956ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
1957{
1958 /*
1959 * Use the data embedded in the work struct for reporting
1960 * here so if the driver mangled the SKB before dropping
1961 * it (which is the only way we really should get here)
1962 * then we don't report mangled data.
1963 *
1964 * If there was no wait time, then by the time we get here
1965 * the driver will likely not have reported the status yet,
1966 * so in that case userspace will have to deal with it.
1967 */
1968
Johannes Berg28a1bcd2011-10-04 18:27:10 +02001969 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
Johannes Bergf30221e2010-11-25 10:02:30 +01001970 cfg80211_mgmt_tx_status(wk->sdata->dev,
1971 (unsigned long) wk->offchan_tx.frame,
1972 wk->ie, wk->ie_len, false, GFP_KERNEL);
1973
1974 return WORK_DONE_DESTROY;
1975}
1976
Johannes Berg2e161f72010-08-12 15:38:38 +02001977static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001978 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f72010-08-12 15:38:38 +02001979 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001980 bool channel_type_valid, unsigned int wait,
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05301981 const u8 *buf, size_t len, bool no_cck,
Johannes Berge247bd902011-11-04 11:18:21 +01001982 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001983{
Johannes Berg9d38d852010-06-09 17:20:33 +02001984 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1985 struct ieee80211_local *local = sdata->local;
1986 struct sk_buff *skb;
1987 struct sta_info *sta;
Johannes Bergf30221e2010-11-25 10:02:30 +01001988 struct ieee80211_work *wk;
Johannes Berg9d38d852010-06-09 17:20:33 +02001989 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berge247bd902011-11-04 11:18:21 +01001990 u32 flags;
Johannes Bergf30221e2010-11-25 10:02:30 +01001991 bool is_offchan = false;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001992
Johannes Berge247bd902011-11-04 11:18:21 +01001993 if (dont_wait_for_ack)
1994 flags = IEEE80211_TX_CTL_NO_ACK;
1995 else
1996 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1997 IEEE80211_TX_CTL_REQ_TX_STATUS;
1998
Johannes Berg9d38d852010-06-09 17:20:33 +02001999 /* Check that we are on the requested channel for transmission */
2000 if (chan != local->tmp_channel &&
2001 chan != local->oper_channel)
Johannes Bergf30221e2010-11-25 10:02:30 +01002002 is_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02002003 if (channel_type_valid &&
2004 (channel_type != local->tmp_channel_type &&
2005 channel_type != local->_oper_channel_type))
Johannes Bergf30221e2010-11-25 10:02:30 +01002006 is_offchan = true;
2007
Johannes Berg21f83582010-12-18 17:20:47 +01002008 if (chan == local->hw_roc_channel) {
2009 /* TODO: check channel type? */
2010 is_offchan = false;
2011 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2012 }
2013
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05302014 if (no_cck)
2015 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
2016
Johannes Bergf30221e2010-11-25 10:02:30 +01002017 if (is_offchan && !offchan)
Johannes Berg9d38d852010-06-09 17:20:33 +02002018 return -EBUSY;
2019
2020 switch (sdata->vif.type) {
2021 case NL80211_IFTYPE_ADHOC:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002022 case NL80211_IFTYPE_AP:
2023 case NL80211_IFTYPE_AP_VLAN:
2024 case NL80211_IFTYPE_P2P_GO:
Javier Cardonac7108a72010-12-16 17:37:50 -08002025 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002026 if (!ieee80211_is_action(mgmt->frame_control) ||
2027 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02002028 break;
2029 rcu_read_lock();
2030 sta = sta_info_get(sdata, mgmt->da);
2031 rcu_read_unlock();
2032 if (!sta)
2033 return -ENOLINK;
2034 break;
2035 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002036 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg9d38d852010-06-09 17:20:33 +02002037 break;
2038 default:
2039 return -EOPNOTSUPP;
2040 }
2041
2042 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2043 if (!skb)
2044 return -ENOMEM;
2045 skb_reserve(skb, local->hw.extra_tx_headroom);
2046
2047 memcpy(skb_put(skb, len), buf, len);
2048
2049 IEEE80211_SKB_CB(skb)->flags = flags;
2050
2051 skb->dev = sdata->dev;
Johannes Berg9d38d852010-06-09 17:20:33 +02002052
2053 *cookie = (unsigned long) skb;
Johannes Bergf30221e2010-11-25 10:02:30 +01002054
Johannes Berg90fc4b32010-12-18 17:20:48 +01002055 if (is_offchan && local->ops->remain_on_channel) {
2056 unsigned int duration;
2057 int ret;
2058
2059 mutex_lock(&local->mtx);
2060 /*
2061 * If the duration is zero, then the driver
2062 * wouldn't actually do anything. Set it to
2063 * 100 for now.
2064 *
2065 * TODO: cancel the off-channel operation
2066 * when we get the SKB's TX status and
2067 * the wait time was zero before.
2068 */
2069 duration = 100;
2070 if (wait)
2071 duration = wait;
2072 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2073 channel_type,
2074 duration, cookie);
2075 if (ret) {
2076 kfree_skb(skb);
2077 mutex_unlock(&local->mtx);
2078 return ret;
2079 }
2080
2081 local->hw_roc_for_tx = true;
2082 local->hw_roc_duration = wait;
2083
2084 /*
2085 * queue up frame for transmission after
2086 * ieee80211_ready_on_channel call
2087 */
2088
2089 /* modify cookie to prevent API mismatches */
2090 *cookie ^= 2;
2091 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2092 local->hw_roc_skb = skb;
Johannes Berg4334ec82011-02-02 16:58:06 +01002093 local->hw_roc_skb_for_status = skb;
Johannes Berg90fc4b32010-12-18 17:20:48 +01002094 mutex_unlock(&local->mtx);
2095
2096 return 0;
2097 }
2098
Johannes Bergf30221e2010-11-25 10:02:30 +01002099 /*
2100 * Can transmit right away if the channel was the
2101 * right one and there's no wait involved... If a
2102 * wait is involved, we might otherwise not be on
2103 * the right channel for long enough!
2104 */
2105 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2106 ieee80211_tx_skb(sdata, skb);
2107 return 0;
2108 }
2109
2110 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2111 if (!wk) {
2112 kfree_skb(skb);
2113 return -ENOMEM;
2114 }
2115
2116 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2117 wk->chan = chan;
Ben Greear4d51e142011-02-07 13:44:34 -08002118 wk->chan_type = channel_type;
Johannes Bergf30221e2010-11-25 10:02:30 +01002119 wk->sdata = sdata;
2120 wk->done = ieee80211_offchan_tx_done;
2121 wk->offchan_tx.frame = skb;
2122 wk->offchan_tx.wait = wait;
2123 wk->ie_len = len;
2124 memcpy(wk->ie, buf, len);
2125
2126 ieee80211_add_work(wk);
Johannes Berg9d38d852010-06-09 17:20:33 +02002127 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02002128}
2129
Johannes Bergf30221e2010-11-25 10:02:30 +01002130static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2131 struct net_device *dev,
2132 u64 cookie)
2133{
2134 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2135 struct ieee80211_local *local = sdata->local;
2136 struct ieee80211_work *wk;
2137 int ret = -ENOENT;
2138
2139 mutex_lock(&local->mtx);
Johannes Berg90fc4b32010-12-18 17:20:48 +01002140
2141 if (local->ops->cancel_remain_on_channel) {
2142 cookie ^= 2;
2143 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2144
2145 if (ret == 0) {
2146 kfree_skb(local->hw_roc_skb);
2147 local->hw_roc_skb = NULL;
Johannes Berg4334ec82011-02-02 16:58:06 +01002148 local->hw_roc_skb_for_status = NULL;
Johannes Berg90fc4b32010-12-18 17:20:48 +01002149 }
2150
2151 mutex_unlock(&local->mtx);
2152
2153 return ret;
2154 }
2155
Johannes Bergf30221e2010-11-25 10:02:30 +01002156 list_for_each_entry(wk, &local->work_list, list) {
2157 if (wk->sdata != sdata)
2158 continue;
2159
2160 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2161 continue;
2162
2163 if (cookie != (unsigned long) wk->offchan_tx.frame)
2164 continue;
2165
2166 wk->timeout = jiffies;
2167
2168 ieee80211_queue_work(&local->hw, &local->work_work);
2169 ret = 0;
2170 break;
2171 }
2172 mutex_unlock(&local->mtx);
2173
2174 return ret;
2175}
2176
Johannes Berg7be50862010-10-13 12:06:24 +02002177static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2178 struct net_device *dev,
2179 u16 frame_type, bool reg)
2180{
2181 struct ieee80211_local *local = wiphy_priv(wiphy);
2182
2183 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2184 return;
2185
2186 if (reg)
2187 local->probe_req_reg++;
2188 else
2189 local->probe_req_reg--;
2190
2191 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2192}
2193
Bruno Randolf15d96752010-11-10 12:50:56 +09002194static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2195{
2196 struct ieee80211_local *local = wiphy_priv(wiphy);
2197
2198 if (local->started)
2199 return -EOPNOTSUPP;
2200
2201 return drv_set_antenna(local, tx_ant, rx_ant);
2202}
2203
2204static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2205{
2206 struct ieee80211_local *local = wiphy_priv(wiphy);
2207
2208 return drv_get_antenna(local, tx_ant, rx_ant);
2209}
2210
John W. Linville38c09152011-03-07 16:19:18 -05002211static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2212{
2213 struct ieee80211_local *local = wiphy_priv(wiphy);
2214
2215 return drv_set_ringparam(local, tx, rx);
2216}
2217
2218static void ieee80211_get_ringparam(struct wiphy *wiphy,
2219 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2220{
2221 struct ieee80211_local *local = wiphy_priv(wiphy);
2222
2223 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2224}
2225
Johannes Bergc68f4b82011-07-05 16:35:41 +02002226static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2227 struct net_device *dev,
2228 struct cfg80211_gtk_rekey_data *data)
2229{
2230 struct ieee80211_local *local = wiphy_priv(wiphy);
2231 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2232
2233 if (!local->ops->set_rekey_data)
2234 return -EOPNOTSUPP;
2235
2236 drv_set_rekey_data(local, sdata, data);
2237
2238 return 0;
2239}
2240
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002241static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2242{
2243 u8 *pos = (void *)skb_put(skb, 7);
2244
2245 *pos++ = WLAN_EID_EXT_CAPABILITY;
2246 *pos++ = 5; /* len */
2247 *pos++ = 0x0;
2248 *pos++ = 0x0;
2249 *pos++ = 0x0;
2250 *pos++ = 0x0;
2251 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2252}
2253
2254static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2255{
2256 struct ieee80211_local *local = sdata->local;
2257 u16 capab;
2258
2259 capab = 0;
2260 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2261 return capab;
2262
2263 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2264 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2265 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2266 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2267
2268 return capab;
2269}
2270
2271static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2272 u8 *peer, u8 *bssid)
2273{
2274 struct ieee80211_tdls_lnkie *lnkid;
2275
2276 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2277
2278 lnkid->ie_type = WLAN_EID_LINK_ID;
2279 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2280
2281 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2282 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2283 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2284}
2285
2286static int
2287ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2288 u8 *peer, u8 action_code, u8 dialog_token,
2289 u16 status_code, struct sk_buff *skb)
2290{
2291 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2292 struct ieee80211_tdls_data *tf;
2293
2294 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2295
2296 memcpy(tf->da, peer, ETH_ALEN);
2297 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2298 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2299 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2300
2301 switch (action_code) {
2302 case WLAN_TDLS_SETUP_REQUEST:
2303 tf->category = WLAN_CATEGORY_TDLS;
2304 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2305
2306 skb_put(skb, sizeof(tf->u.setup_req));
2307 tf->u.setup_req.dialog_token = dialog_token;
2308 tf->u.setup_req.capability =
2309 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2310
2311 ieee80211_add_srates_ie(&sdata->vif, skb);
2312 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2313 ieee80211_tdls_add_ext_capab(skb);
2314 break;
2315 case WLAN_TDLS_SETUP_RESPONSE:
2316 tf->category = WLAN_CATEGORY_TDLS;
2317 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2318
2319 skb_put(skb, sizeof(tf->u.setup_resp));
2320 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2321 tf->u.setup_resp.dialog_token = dialog_token;
2322 tf->u.setup_resp.capability =
2323 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2324
2325 ieee80211_add_srates_ie(&sdata->vif, skb);
2326 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2327 ieee80211_tdls_add_ext_capab(skb);
2328 break;
2329 case WLAN_TDLS_SETUP_CONFIRM:
2330 tf->category = WLAN_CATEGORY_TDLS;
2331 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2332
2333 skb_put(skb, sizeof(tf->u.setup_cfm));
2334 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2335 tf->u.setup_cfm.dialog_token = dialog_token;
2336 break;
2337 case WLAN_TDLS_TEARDOWN:
2338 tf->category = WLAN_CATEGORY_TDLS;
2339 tf->action_code = WLAN_TDLS_TEARDOWN;
2340
2341 skb_put(skb, sizeof(tf->u.teardown));
2342 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2343 break;
2344 case WLAN_TDLS_DISCOVERY_REQUEST:
2345 tf->category = WLAN_CATEGORY_TDLS;
2346 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2347
2348 skb_put(skb, sizeof(tf->u.discover_req));
2349 tf->u.discover_req.dialog_token = dialog_token;
2350 break;
2351 default:
2352 return -EINVAL;
2353 }
2354
2355 return 0;
2356}
2357
2358static int
2359ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2360 u8 *peer, u8 action_code, u8 dialog_token,
2361 u16 status_code, struct sk_buff *skb)
2362{
2363 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2364 struct ieee80211_mgmt *mgmt;
2365
2366 mgmt = (void *)skb_put(skb, 24);
2367 memset(mgmt, 0, 24);
2368 memcpy(mgmt->da, peer, ETH_ALEN);
2369 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2370 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2371
2372 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2373 IEEE80211_STYPE_ACTION);
2374
2375 switch (action_code) {
2376 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2377 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2378 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2379 mgmt->u.action.u.tdls_discover_resp.action_code =
2380 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2381 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2382 dialog_token;
2383 mgmt->u.action.u.tdls_discover_resp.capability =
2384 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2385
2386 ieee80211_add_srates_ie(&sdata->vif, skb);
2387 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2388 ieee80211_tdls_add_ext_capab(skb);
2389 break;
2390 default:
2391 return -EINVAL;
2392 }
2393
2394 return 0;
2395}
2396
2397static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2398 u8 *peer, u8 action_code, u8 dialog_token,
2399 u16 status_code, const u8 *extra_ies,
2400 size_t extra_ies_len)
2401{
2402 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2403 struct ieee80211_local *local = sdata->local;
2404 struct ieee80211_tx_info *info;
2405 struct sk_buff *skb = NULL;
2406 bool send_direct;
2407 int ret;
2408
2409 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2410 return -ENOTSUPP;
2411
2412 /* make sure we are in managed mode, and associated */
2413 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2414 !sdata->u.mgd.associated)
2415 return -EINVAL;
2416
2417#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2418 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2419#endif
2420
2421 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2422 max(sizeof(struct ieee80211_mgmt),
2423 sizeof(struct ieee80211_tdls_data)) +
2424 50 + /* supported rates */
2425 7 + /* ext capab */
2426 extra_ies_len +
2427 sizeof(struct ieee80211_tdls_lnkie));
2428 if (!skb)
2429 return -ENOMEM;
2430
2431 info = IEEE80211_SKB_CB(skb);
2432 skb_reserve(skb, local->hw.extra_tx_headroom);
2433
2434 switch (action_code) {
2435 case WLAN_TDLS_SETUP_REQUEST:
2436 case WLAN_TDLS_SETUP_RESPONSE:
2437 case WLAN_TDLS_SETUP_CONFIRM:
2438 case WLAN_TDLS_TEARDOWN:
2439 case WLAN_TDLS_DISCOVERY_REQUEST:
2440 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2441 action_code, dialog_token,
2442 status_code, skb);
2443 send_direct = false;
2444 break;
2445 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2446 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2447 dialog_token, status_code,
2448 skb);
2449 send_direct = true;
2450 break;
2451 default:
2452 ret = -ENOTSUPP;
2453 break;
2454 }
2455
2456 if (ret < 0)
2457 goto fail;
2458
2459 if (extra_ies_len)
2460 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2461
2462 /* the TDLS link IE is always added last */
2463 switch (action_code) {
2464 case WLAN_TDLS_SETUP_REQUEST:
2465 case WLAN_TDLS_SETUP_CONFIRM:
2466 case WLAN_TDLS_TEARDOWN:
2467 case WLAN_TDLS_DISCOVERY_REQUEST:
2468 /* we are the initiator */
2469 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2470 sdata->u.mgd.bssid);
2471 break;
2472 case WLAN_TDLS_SETUP_RESPONSE:
2473 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2474 /* we are the responder */
2475 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2476 sdata->u.mgd.bssid);
2477 break;
2478 default:
2479 ret = -ENOTSUPP;
2480 goto fail;
2481 }
2482
2483 if (send_direct) {
2484 ieee80211_tx_skb(sdata, skb);
2485 return 0;
2486 }
2487
2488 /*
2489 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2490 * we should default to AC_VI.
2491 */
2492 switch (action_code) {
2493 case WLAN_TDLS_SETUP_REQUEST:
2494 case WLAN_TDLS_SETUP_RESPONSE:
2495 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2496 skb->priority = 2;
2497 break;
2498 default:
2499 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2500 skb->priority = 5;
2501 break;
2502 }
2503
2504 /* disable bottom halves when entering the Tx path */
2505 local_bh_disable();
2506 ret = ieee80211_subif_start_xmit(skb, dev);
2507 local_bh_enable();
2508
2509 return ret;
2510
2511fail:
2512 dev_kfree_skb(skb);
2513 return ret;
2514}
2515
2516static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2517 u8 *peer, enum nl80211_tdls_operation oper)
2518{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002519 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002520 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2521
2522 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2523 return -ENOTSUPP;
2524
2525 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2526 return -EINVAL;
2527
2528#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2529 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2530#endif
2531
2532 switch (oper) {
2533 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002534 rcu_read_lock();
2535 sta = sta_info_get(sdata, peer);
2536 if (!sta) {
2537 rcu_read_unlock();
2538 return -ENOLINK;
2539 }
2540
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002541 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002542 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002543 break;
2544 case NL80211_TDLS_DISABLE_LINK:
2545 return sta_info_destroy_addr(sdata, peer);
2546 case NL80211_TDLS_TEARDOWN:
2547 case NL80211_TDLS_SETUP:
2548 case NL80211_TDLS_DISCOVERY_REQ:
2549 /* We don't support in-driver setup/teardown/discovery */
2550 return -ENOTSUPP;
2551 default:
2552 return -ENOTSUPP;
2553 }
2554
2555 return 0;
2556}
2557
Johannes Berg06500732011-11-04 11:18:16 +01002558static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2559 const u8 *peer, u64 *cookie)
2560{
2561 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2562 struct ieee80211_local *local = sdata->local;
2563 struct ieee80211_qos_hdr *nullfunc;
2564 struct sk_buff *skb;
2565 int size = sizeof(*nullfunc);
2566 __le16 fc;
2567 bool qos;
2568 struct ieee80211_tx_info *info;
2569 struct sta_info *sta;
2570
2571 rcu_read_lock();
2572 sta = sta_info_get(sdata, peer);
Johannes Bergb4487c22011-11-11 20:22:30 +01002573 if (sta) {
Johannes Berg06500732011-11-04 11:18:16 +01002574 qos = test_sta_flag(sta, WLAN_STA_WME);
Johannes Bergb4487c22011-11-11 20:22:30 +01002575 rcu_read_unlock();
2576 } else {
2577 rcu_read_unlock();
Johannes Berg06500732011-11-04 11:18:16 +01002578 return -ENOLINK;
Johannes Bergb4487c22011-11-11 20:22:30 +01002579 }
Johannes Berg06500732011-11-04 11:18:16 +01002580
2581 if (qos) {
2582 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2583 IEEE80211_STYPE_QOS_NULLFUNC |
2584 IEEE80211_FCTL_FROMDS);
2585 } else {
2586 size -= 2;
2587 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2588 IEEE80211_STYPE_NULLFUNC |
2589 IEEE80211_FCTL_FROMDS);
2590 }
2591
2592 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2593 if (!skb)
2594 return -ENOMEM;
2595
2596 skb->dev = dev;
2597
2598 skb_reserve(skb, local->hw.extra_tx_headroom);
2599
2600 nullfunc = (void *) skb_put(skb, size);
2601 nullfunc->frame_control = fc;
2602 nullfunc->duration_id = 0;
2603 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2604 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2605 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2606 nullfunc->seq_ctrl = 0;
2607
2608 info = IEEE80211_SKB_CB(skb);
2609
2610 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2611 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2612
2613 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2614 skb->priority = 7;
2615 if (qos)
2616 nullfunc->qos_ctrl = cpu_to_le16(7);
2617
2618 local_bh_disable();
2619 ieee80211_xmit(sdata, skb);
2620 local_bh_enable();
2621
2622 *cookie = (unsigned long) skb;
2623 return 0;
2624}
2625
Johannes Berge9998822011-11-09 10:30:21 +01002626static struct ieee80211_channel *
2627ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2628{
2629 struct ieee80211_local *local = wiphy_priv(wiphy);
2630
2631 return local->oper_channel;
2632}
2633
Jiri Bencf0706e82007-05-05 11:45:53 -07002634struct cfg80211_ops mac80211_config_ops = {
2635 .add_virtual_intf = ieee80211_add_iface,
2636 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02002637 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01002638 .add_key = ieee80211_add_key,
2639 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01002640 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01002641 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002642 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01002643 .add_beacon = ieee80211_add_beacon,
2644 .set_beacon = ieee80211_set_beacon,
2645 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01002646 .add_station = ieee80211_add_station,
2647 .del_station = ieee80211_del_station,
2648 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01002649 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002650 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02002651 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002652#ifdef CONFIG_MAC80211_MESH
2653 .add_mpath = ieee80211_add_mpath,
2654 .del_mpath = ieee80211_del_mpath,
2655 .change_mpath = ieee80211_change_mpath,
2656 .get_mpath = ieee80211_get_mpath,
2657 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002658 .update_mesh_config = ieee80211_update_mesh_config,
2659 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01002660 .join_mesh = ieee80211_join_mesh,
2661 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002662#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002663 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02002664 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002665 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05002666 .suspend = ieee80211_suspend,
2667 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01002668 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03002669 .sched_scan_start = ieee80211_sched_scan_start,
2670 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02002671 .auth = ieee80211_auth,
2672 .assoc = ieee80211_assoc,
2673 .deauth = ieee80211_deauth,
2674 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002675 .join_ibss = ieee80211_join_ibss,
2676 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002677 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02002678 .set_tx_power = ieee80211_set_tx_power,
2679 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02002680 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002681 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02002682 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002683 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002684 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02002685 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002686 .remain_on_channel = ieee80211_remain_on_channel,
2687 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02002688 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01002689 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002690 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02002691 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09002692 .set_antenna = ieee80211_set_antenna,
2693 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05002694 .set_ringparam = ieee80211_set_ringparam,
2695 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02002696 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002697 .tdls_oper = ieee80211_tdls_oper,
2698 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01002699 .probe_client = ieee80211_probe_client,
Johannes Berge9998822011-11-09 10:30:21 +01002700 .get_channel = ieee80211_wiphy_get_channel,
Jiri Bencf0706e82007-05-05 11:45:53 -07002701};