blob: 192f213cf43e9d89745ff53485bf8060f9373c24 [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 Berg9607e6b662009-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 Randolfb206b4ef2010-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 Randolfb206b4ef2010-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
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100494/*
495 * This handles both adding a beacon and setting new beacon info
496 */
497static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
498 struct beacon_parameters *params)
499{
500 struct beacon_data *new, *old;
501 int new_head_len, new_tail_len;
502 int size;
503 int err = -EINVAL;
504
Johannes Berg40b275b2011-05-13 14:15:49 +0200505 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100506
507 /* head must not be zero-length */
508 if (params->head && !params->head_len)
509 return -EINVAL;
510
511 /*
512 * This is a kludge. beacon interval should really be part
513 * of the beacon information.
514 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200515 if (params->interval &&
516 (sdata->vif.bss_conf.beacon_int != params->interval)) {
517 sdata->vif.bss_conf.beacon_int = params->interval;
518 ieee80211_bss_info_change_notify(sdata,
519 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100520 }
521
522 /* Need to have a beacon head if we don't have one yet */
523 if (!params->head && !old)
524 return err;
525
526 /* sorry, no way to start beaconing without dtim period */
527 if (!params->dtim_period && !old)
528 return err;
529
530 /* new or old head? */
531 if (params->head)
532 new_head_len = params->head_len;
533 else
534 new_head_len = old->head_len;
535
536 /* new or old tail? */
537 if (params->tail || !old)
538 /* params->tail_len will be zero for !params->tail */
539 new_tail_len = params->tail_len;
540 else
541 new_tail_len = old->tail_len;
542
543 size = sizeof(*new) + new_head_len + new_tail_len;
544
545 new = kzalloc(size, GFP_KERNEL);
546 if (!new)
547 return -ENOMEM;
548
549 /* start filling the new info now */
550
551 /* new or old dtim period? */
552 if (params->dtim_period)
553 new->dtim_period = params->dtim_period;
554 else
555 new->dtim_period = old->dtim_period;
556
557 /*
558 * pointers go into the block we allocated,
559 * memory is | beacon_data | head | tail |
560 */
561 new->head = ((u8 *) new) + sizeof(*new);
562 new->tail = new->head + new_head_len;
563 new->head_len = new_head_len;
564 new->tail_len = new_tail_len;
565
566 /* copy in head */
567 if (params->head)
568 memcpy(new->head, params->head, new_head_len);
569 else
570 memcpy(new->head, old->head, new_head_len);
571
572 /* copy in optional tail */
573 if (params->tail)
574 memcpy(new->tail, params->tail, new_tail_len);
575 else
576 if (old)
577 memcpy(new->tail, old->tail, new_tail_len);
578
Johannes Berg19885c42010-02-05 11:45:06 +0100579 sdata->vif.bss_conf.dtim_period = new->dtim_period;
580
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000581 RCU_INIT_POINTER(sdata->u.ap.beacon, new);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100582
583 synchronize_rcu();
584
585 kfree(old);
586
Arik Nemtsov78274932011-09-04 11:11:32 +0300587 ieee80211_config_ap_ssid(sdata, params);
588
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200589 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
Arik Nemtsov78274932011-09-04 11:11:32 +0300590 BSS_CHANGED_BEACON |
591 BSS_CHANGED_SSID);
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200592 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100593}
594
595static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
596 struct beacon_parameters *params)
597{
Johannes Berg14db74b2008-07-29 13:22:52 +0200598 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100599 struct beacon_data *old;
Johannes Berg665c93a2011-11-04 11:18:11 +0100600 struct ieee80211_sub_if_data *vlan;
601 int ret;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100602
Johannes Berg14db74b2008-07-29 13:22:52 +0200603 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
604
Johannes Berg40b275b2011-05-13 14:15:49 +0200605 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100606 if (old)
607 return -EALREADY;
608
Johannes Berg665c93a2011-11-04 11:18:11 +0100609 ret = ieee80211_config_beacon(sdata, params);
610 if (ret)
611 return ret;
612
613 /*
614 * Apply control port protocol, this allows us to
615 * not encrypt dynamic WEP control frames.
616 */
617 sdata->control_port_protocol = params->crypto.control_port_ethertype;
618 sdata->control_port_no_encrypt = params->crypto.control_port_no_encrypt;
619 list_for_each_entry(vlan, &sdata->u.ap.vlans, u.vlan.list) {
620 vlan->control_port_protocol =
621 params->crypto.control_port_ethertype;
622 vlan->control_port_no_encrypt =
623 params->crypto.control_port_no_encrypt;
624 }
625
626 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100627}
628
629static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
630 struct beacon_parameters *params)
631{
Johannes Berg14db74b2008-07-29 13:22:52 +0200632 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100633 struct beacon_data *old;
634
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 -ENOENT;
640
641 return ieee80211_config_beacon(sdata, params);
642}
643
644static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
645{
Johannes Berg14db74b2008-07-29 13:22:52 +0200646 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100647 struct beacon_data *old;
648
Johannes Berg14db74b2008-07-29 13:22:52 +0200649 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
650
Johannes Berg40b275b2011-05-13 14:15:49 +0200651 old = rtnl_dereference(sdata->u.ap.beacon);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100652 if (!old)
653 return -ENOENT;
654
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000655 RCU_INIT_POINTER(sdata->u.ap.beacon, NULL);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100656 synchronize_rcu();
657 kfree(old);
658
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200659 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
660 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100661}
662
Johannes Berg4fd69312007-12-19 02:03:35 +0100663/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
664struct iapp_layer2_update {
665 u8 da[ETH_ALEN]; /* broadcast */
666 u8 sa[ETH_ALEN]; /* STA addr */
667 __be16 len; /* 6 */
668 u8 dsap; /* 0 */
669 u8 ssap; /* 0 */
670 u8 control;
671 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700672} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100673
674static void ieee80211_send_layer2_update(struct sta_info *sta)
675{
676 struct iapp_layer2_update *msg;
677 struct sk_buff *skb;
678
679 /* Send Level 2 Update Frame to update forwarding tables in layer 2
680 * bridge devices */
681
682 skb = dev_alloc_skb(sizeof(*msg));
683 if (!skb)
684 return;
685 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
686
687 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
688 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
689
690 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200691 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100692 msg->len = htons(6);
693 msg->dsap = 0;
694 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
695 msg->control = 0xaf; /* XID response lsb.1111F101.
696 * F=0 (no poll command; unsolicited frame) */
697 msg->xid_info[0] = 0x81; /* XID format identifier */
698 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
699 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
700
Johannes Bergd0709a62008-02-25 16:27:46 +0100701 skb->dev = sta->sdata->dev;
702 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100703 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400704 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100705}
706
707static void sta_apply_parameters(struct ieee80211_local *local,
708 struct sta_info *sta,
709 struct station_parameters *params)
710{
711 u32 rates;
712 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100713 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100714 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300715 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100716
Johannes Bergae5eb022008-10-14 16:58:37 +0200717 sband = local->hw.wiphy->bands[local->oper_channel->band];
718
Johannes Bergeccb8e82009-05-11 21:57:56 +0300719 mask = params->sta_flags_mask;
720 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100721
Johannes Bergeccb8e82009-05-11 21:57:56 +0300722 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300723 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200724 set_sta_flag(sta, WLAN_STA_AUTHORIZED);
725 else
726 clear_sta_flag(sta, WLAN_STA_AUTHORIZED);
Johannes Berg4fd69312007-12-19 02:03:35 +0100727 }
728
Johannes Bergeccb8e82009-05-11 21:57:56 +0300729 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300730 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200731 set_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
732 else
733 clear_sta_flag(sta, WLAN_STA_SHORT_PREAMBLE);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300734 }
735
736 if (mask & BIT(NL80211_STA_FLAG_WME)) {
Arik Nemtsov39df6002011-06-27 23:58:45 +0300737 if (set & BIT(NL80211_STA_FLAG_WME)) {
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200738 set_sta_flag(sta, WLAN_STA_WME);
Arik Nemtsov39df6002011-06-27 23:58:45 +0300739 sta->sta.wme = true;
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200740 } else {
741 clear_sta_flag(sta, WLAN_STA_WME);
742 sta->sta.wme = false;
Arik Nemtsov39df6002011-06-27 23:58:45 +0300743 }
Johannes Bergeccb8e82009-05-11 21:57:56 +0300744 }
745
746 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
Johannes Bergeccb8e82009-05-11 21:57:56 +0300747 if (set & BIT(NL80211_STA_FLAG_MFP))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200748 set_sta_flag(sta, WLAN_STA_MFP);
749 else
750 clear_sta_flag(sta, WLAN_STA_MFP);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300751 }
Javier Cardonab39c48f2011-04-07 15:08:30 -0700752
753 if (mask & BIT(NL80211_STA_FLAG_AUTHENTICATED)) {
Javier Cardonab39c48f2011-04-07 15:08:30 -0700754 if (set & BIT(NL80211_STA_FLAG_AUTHENTICATED))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200755 set_sta_flag(sta, WLAN_STA_AUTH);
756 else
757 clear_sta_flag(sta, WLAN_STA_AUTH);
Javier Cardonab39c48f2011-04-07 15:08:30 -0700758 }
Johannes Bergeccb8e82009-05-11 21:57:56 +0300759
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300760 if (mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300761 if (set & BIT(NL80211_STA_FLAG_TDLS_PEER))
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200762 set_sta_flag(sta, WLAN_STA_TDLS_PEER);
763 else
764 clear_sta_flag(sta, WLAN_STA_TDLS_PEER);
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300765 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100766
Johannes Berg3b9ce802011-09-27 20:56:12 +0200767 if (params->sta_modify_mask & STATION_PARAM_APPLY_UAPSD) {
768 sta->sta.uapsd_queues = params->uapsd_queues;
769 sta->sta.max_sp = params->max_sp;
770 }
Eliad Peller9533b4a2011-08-23 14:37:47 +0300771
Johannes Berg73651ee2008-02-25 16:27:47 +0100772 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200773 * cfg80211 validates this (1-2007) and allows setting the AID
774 * only when creating a new station entry
775 */
776 if (params->aid)
777 sta->sta.aid = params->aid;
778
779 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100780 * FIXME: updating the following information is racy when this
781 * function is called from ieee80211_change_station().
782 * However, all this information should be static so
783 * maybe we should just reject attemps to change it.
784 */
785
Johannes Berg4fd69312007-12-19 02:03:35 +0100786 if (params->listen_interval >= 0)
787 sta->listen_interval = params->listen_interval;
788
789 if (params->supported_rates) {
790 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100791
Johannes Berg4fd69312007-12-19 02:03:35 +0100792 for (i = 0; i < params->supported_rates_len; i++) {
793 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100794 for (j = 0; j < sband->n_bitrates; j++) {
795 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100796 rates |= BIT(j);
797 }
798 }
Johannes Berg323ce792008-09-11 02:45:11 +0200799 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100800 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100801
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200802 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200803 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
804 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200805 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300806
Javier Cardona9c3990a2011-05-03 16:57:11 -0700807 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -0400808#ifdef CONFIG_MAC80211_MESH
Javier Cardona9c3990a2011-05-03 16:57:11 -0700809 if (sdata->u.mesh.security & IEEE80211_MESH_SEC_SECURED)
810 switch (params->plink_state) {
Javier Cardona57cf8042011-05-13 10:45:43 -0700811 case NL80211_PLINK_LISTEN:
812 case NL80211_PLINK_ESTAB:
813 case NL80211_PLINK_BLOCKED:
Javier Cardona9c3990a2011-05-03 16:57:11 -0700814 sta->plink_state = params->plink_state;
815 break;
816 default:
817 /* nothing */
818 break;
819 }
820 else
821 switch (params->plink_action) {
822 case PLINK_ACTION_OPEN:
823 mesh_plink_open(sta);
824 break;
825 case PLINK_ACTION_BLOCK:
826 mesh_plink_block(sta);
827 break;
828 }
Yogesh Ashok Powar4daf50f2011-05-12 09:32:17 -0400829#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100830 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100831}
832
833static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
834 u8 *mac, struct station_parameters *params)
835{
Johannes Berg14db74b2008-07-29 13:22:52 +0200836 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100837 struct sta_info *sta;
838 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100839 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200840 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100841
Johannes Berg4fd69312007-12-19 02:03:35 +0100842 if (params->vlan) {
843 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
844
Johannes Berg05c914f2008-09-11 00:01:58 +0200845 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
846 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100847 return -EINVAL;
848 } else
849 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
850
Johannes Berg47846c92009-11-25 17:46:19 +0100851 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100852 return -EINVAL;
853
854 if (is_multicast_ether_addr(mac))
855 return -EINVAL;
856
Jouni Malinene3a4cc22011-10-23 22:36:04 +0300857 /* Only TDLS-supporting stations can add TDLS peers */
858 if ((params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
859 !((wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) &&
860 sdata->vif.type == NL80211_IFTYPE_STATION))
861 return -ENOTSUPP;
862
Johannes Berg03e44972008-02-27 09:56:40 +0100863 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100864 if (!sta)
865 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100866
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200867 set_sta_flag(sta, WLAN_STA_AUTH);
868 set_sta_flag(sta, WLAN_STA_ASSOC);
Johannes Berg4fd69312007-12-19 02:03:35 +0100869
870 sta_apply_parameters(local, sta, params);
871
Arik Nemtsovd64cf632011-11-07 23:24:39 +0200872 /*
873 * for TDLS, rate control should be initialized only when supported
874 * rates are known.
875 */
876 if (!test_sta_flag(sta, WLAN_STA_TDLS_PEER))
877 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100878
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200879 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
880 sdata->vif.type == NL80211_IFTYPE_AP;
881
Johannes Berg34e89502010-02-03 13:59:58 +0100882 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100883 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100884 rcu_read_unlock();
885 return err;
886 }
887
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200888 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100889 ieee80211_send_layer2_update(sta);
890
891 rcu_read_unlock();
892
Johannes Berg4fd69312007-12-19 02:03:35 +0100893 return 0;
894}
895
896static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
897 u8 *mac)
898{
Johannes Berg14db74b2008-07-29 13:22:52 +0200899 struct ieee80211_local *local = wiphy_priv(wiphy);
900 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100901
Johannes Berg14db74b2008-07-29 13:22:52 +0200902 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
903
Johannes Berg34e89502010-02-03 13:59:58 +0100904 if (mac)
905 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200906
Johannes Berg34e89502010-02-03 13:59:58 +0100907 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100908 return 0;
909}
910
911static int ieee80211_change_station(struct wiphy *wiphy,
912 struct net_device *dev,
913 u8 *mac,
914 struct station_parameters *params)
915{
Johannes Bergabe60632009-11-25 17:46:18 +0100916 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200917 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100918 struct sta_info *sta;
919 struct ieee80211_sub_if_data *vlansdata;
920
Johannes Berg98dd6a52008-04-10 15:36:09 +0200921 rcu_read_lock();
922
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100923 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200924 if (!sta) {
925 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100926 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200927 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100928
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300929 /* The TDLS bit cannot be toggled after the STA was added */
930 if ((params->sta_flags_mask & BIT(NL80211_STA_FLAG_TDLS_PEER)) &&
931 !!(params->sta_flags_set & BIT(NL80211_STA_FLAG_TDLS_PEER)) !=
Johannes Bergc2c98fd2011-09-29 16:04:36 +0200932 !!test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
Arik Nemtsov07ba55d2011-09-28 14:12:53 +0300933 rcu_read_unlock();
934 return -EINVAL;
935 }
936
Johannes Bergd0709a62008-02-25 16:27:46 +0100937 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100938 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
939
Johannes Berg05c914f2008-09-11 00:01:58 +0200940 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
941 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200942 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100943 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200944 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100945
Johannes Berg9bc383d2009-11-19 11:55:19 +0100946 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100947 if (vlansdata->u.vlan.sta) {
948 rcu_read_unlock();
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100949 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100950 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100951
Stephen Hemmingera9b3cd72011-08-01 16:19:00 +0000952 RCU_INIT_POINTER(vlansdata->u.vlan.sta, sta);
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100953 }
954
Johannes Berg14db74b2008-07-29 13:22:52 +0200955 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100956 ieee80211_send_layer2_update(sta);
957 }
958
959 sta_apply_parameters(local, sta, params);
960
Arik Nemtsovd64cf632011-11-07 23:24:39 +0200961 if (test_sta_flag(sta, WLAN_STA_TDLS_PEER) && params->supported_rates)
962 rate_control_rate_init(sta);
963
Johannes Berg98dd6a52008-04-10 15:36:09 +0200964 rcu_read_unlock();
965
Jason Young808118c2011-03-10 16:43:19 -0800966 if (sdata->vif.type == NL80211_IFTYPE_STATION &&
967 params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED))
968 ieee80211_recalc_ps(local, -1);
969
Johannes Berg4fd69312007-12-19 02:03:35 +0100970 return 0;
971}
972
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100973#ifdef CONFIG_MAC80211_MESH
974static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
975 u8 *dst, u8 *next_hop)
976{
Johannes Berg14db74b2008-07-29 13:22:52 +0200977 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100978 struct mesh_path *mpath;
979 struct sta_info *sta;
980 int err;
981
Johannes Berg14db74b2008-07-29 13:22:52 +0200982 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
983
Johannes Bergd0709a62008-02-25 16:27:46 +0100984 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100985 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100986 if (!sta) {
987 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100988 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100989 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100990
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200991 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100992 if (err) {
993 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100994 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100995 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100996
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200997 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100998 if (!mpath) {
999 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001000 return -ENXIO;
1001 }
1002 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001003
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001004 rcu_read_unlock();
1005 return 0;
1006}
1007
1008static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
1009 u8 *dst)
1010{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001011 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001012
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001013 if (dst)
1014 return mesh_path_del(dst, sdata);
1015
Javier Cardonaece1a2e2011-08-29 13:23:04 -07001016 mesh_path_flush_by_iface(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001017 return 0;
1018}
1019
1020static int ieee80211_change_mpath(struct wiphy *wiphy,
1021 struct net_device *dev,
1022 u8 *dst, u8 *next_hop)
1023{
Johannes Berg14db74b2008-07-29 13:22:52 +02001024 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001025 struct mesh_path *mpath;
1026 struct sta_info *sta;
1027
Johannes Berg14db74b2008-07-29 13:22:52 +02001028 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1029
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001030 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +01001031
Johannes Bergabe60632009-11-25 17:46:18 +01001032 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +01001033 if (!sta) {
1034 rcu_read_unlock();
1035 return -ENOENT;
1036 }
1037
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001038 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001039 if (!mpath) {
1040 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001041 return -ENOENT;
1042 }
1043
1044 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +01001045
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001046 rcu_read_unlock();
1047 return 0;
1048}
1049
1050static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
1051 struct mpath_info *pinfo)
1052{
Johannes Berga3836e02011-05-12 15:11:37 +02001053 struct sta_info *next_hop_sta = rcu_dereference(mpath->next_hop);
1054
1055 if (next_hop_sta)
1056 memcpy(next_hop, next_hop_sta->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001057 else
1058 memset(next_hop, 0, ETH_ALEN);
1059
Johannes Bergf5ea9122009-08-07 16:17:38 +02001060 pinfo->generation = mesh_paths_generation;
1061
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001062 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +00001063 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001064 MPATH_INFO_METRIC |
1065 MPATH_INFO_EXPTIME |
1066 MPATH_INFO_DISCOVERY_TIMEOUT |
1067 MPATH_INFO_DISCOVERY_RETRIES |
1068 MPATH_INFO_FLAGS;
1069
1070 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001071 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001072 pinfo->metric = mpath->metric;
1073 if (time_before(jiffies, mpath->exp_time))
1074 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
1075 pinfo->discovery_timeout =
1076 jiffies_to_msecs(mpath->discovery_timeout);
1077 pinfo->discovery_retries = mpath->discovery_retries;
1078 pinfo->flags = 0;
1079 if (mpath->flags & MESH_PATH_ACTIVE)
1080 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
1081 if (mpath->flags & MESH_PATH_RESOLVING)
1082 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +00001083 if (mpath->flags & MESH_PATH_SN_VALID)
1084 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001085 if (mpath->flags & MESH_PATH_FIXED)
1086 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
1087 if (mpath->flags & MESH_PATH_RESOLVING)
1088 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
1089
1090 pinfo->flags = mpath->flags;
1091}
1092
1093static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
1094 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
1095
1096{
Johannes Berg14db74b2008-07-29 13:22:52 +02001097 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001098 struct mesh_path *mpath;
1099
Johannes Berg14db74b2008-07-29 13:22:52 +02001100 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1101
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001102 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001103 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001104 if (!mpath) {
1105 rcu_read_unlock();
1106 return -ENOENT;
1107 }
1108 memcpy(dst, mpath->dst, ETH_ALEN);
1109 mpath_set_pinfo(mpath, next_hop, pinfo);
1110 rcu_read_unlock();
1111 return 0;
1112}
1113
1114static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
1115 int idx, u8 *dst, u8 *next_hop,
1116 struct mpath_info *pinfo)
1117{
Johannes Berg14db74b2008-07-29 13:22:52 +02001118 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001119 struct mesh_path *mpath;
1120
Johannes Berg14db74b2008-07-29 13:22:52 +02001121 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1122
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001123 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +12001124 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001125 if (!mpath) {
1126 rcu_read_unlock();
1127 return -ENOENT;
1128 }
1129 memcpy(dst, mpath->dst, ETH_ALEN);
1130 mpath_set_pinfo(mpath, next_hop, pinfo);
1131 rcu_read_unlock();
1132 return 0;
1133}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001134
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001135static int ieee80211_get_mesh_config(struct wiphy *wiphy,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001136 struct net_device *dev,
1137 struct mesh_config *conf)
1138{
1139 struct ieee80211_sub_if_data *sdata;
1140 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1141
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001142 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
1143 return 0;
1144}
1145
1146static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1147{
1148 return (mask >> (parm-1)) & 0x1;
1149}
1150
Javier Cardonac80d5452010-12-16 17:37:49 -08001151static int copy_mesh_setup(struct ieee80211_if_mesh *ifmsh,
1152 const struct mesh_setup *setup)
1153{
1154 u8 *new_ie;
1155 const u8 *old_ie;
1156
Javier Cardona581a8b02011-04-07 15:08:27 -07001157 /* allocate information elements */
Javier Cardonac80d5452010-12-16 17:37:49 -08001158 new_ie = NULL;
Javier Cardona581a8b02011-04-07 15:08:27 -07001159 old_ie = ifmsh->ie;
Javier Cardonac80d5452010-12-16 17:37:49 -08001160
Javier Cardona581a8b02011-04-07 15:08:27 -07001161 if (setup->ie_len) {
1162 new_ie = kmemdup(setup->ie, setup->ie_len,
Javier Cardonac80d5452010-12-16 17:37:49 -08001163 GFP_KERNEL);
1164 if (!new_ie)
1165 return -ENOMEM;
1166 }
Javier Cardona581a8b02011-04-07 15:08:27 -07001167 ifmsh->ie_len = setup->ie_len;
1168 ifmsh->ie = new_ie;
1169 kfree(old_ie);
Javier Cardonac80d5452010-12-16 17:37:49 -08001170
1171 /* now copy the rest of the setup parameters */
1172 ifmsh->mesh_id_len = setup->mesh_id_len;
1173 memcpy(ifmsh->mesh_id, setup->mesh_id, ifmsh->mesh_id_len);
1174 ifmsh->mesh_pp_id = setup->path_sel_proto;
1175 ifmsh->mesh_pm_id = setup->path_metric;
Javier Cardonab130e5c2011-05-03 16:57:07 -07001176 ifmsh->security = IEEE80211_MESH_SEC_NONE;
1177 if (setup->is_authenticated)
1178 ifmsh->security |= IEEE80211_MESH_SEC_AUTHED;
1179 if (setup->is_secure)
1180 ifmsh->security |= IEEE80211_MESH_SEC_SECURED;
Javier Cardonac80d5452010-12-16 17:37:49 -08001181
1182 return 0;
1183}
1184
Javier Cardona24bdd9f2010-12-16 17:37:48 -08001185static int ieee80211_update_mesh_config(struct wiphy *wiphy,
Johannes Berg29cbe682010-12-03 09:20:44 +01001186 struct net_device *dev, u32 mask,
1187 const struct mesh_config *nconf)
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001188{
1189 struct mesh_config *conf;
1190 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001191 struct ieee80211_if_mesh *ifmsh;
1192
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001193 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001194 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001195
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001196 /* Set the config options which we are interested in setting */
1197 conf = &(sdata->u.mesh.mshcfg);
1198 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1199 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1200 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1201 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1202 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1203 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1204 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1205 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1206 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1207 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1208 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1209 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001210 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1211 conf->dot11MeshTTL = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001212 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1213 conf->auto_open_plinks = nconf->auto_open_plinks;
1214 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1215 conf->dot11MeshHWMPmaxPREQretries =
1216 nconf->dot11MeshHWMPmaxPREQretries;
1217 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1218 conf->path_refresh_time = nconf->path_refresh_time;
1219 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1220 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1221 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1222 conf->dot11MeshHWMPactivePathTimeout =
1223 nconf->dot11MeshHWMPactivePathTimeout;
1224 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1225 conf->dot11MeshHWMPpreqMinInterval =
1226 nconf->dot11MeshHWMPpreqMinInterval;
1227 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1228 mask))
1229 conf->dot11MeshHWMPnetDiameterTraversalTime =
1230 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001231 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1232 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1233 ieee80211_mesh_root_setup(ifmsh);
1234 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001235 if (_chg_mesh_attr(NL80211_MESHCONF_GATE_ANNOUNCEMENTS, mask)) {
Thomas Pedersenc61336612011-08-25 10:36:14 -07001236 /* our current gate announcement implementation rides on root
1237 * announcements, so require this ifmsh to also be a root node
1238 * */
1239 if (nconf->dot11MeshGateAnnouncementProtocol &&
1240 !conf->dot11MeshHWMPRootMode) {
1241 conf->dot11MeshHWMPRootMode = 1;
1242 ieee80211_mesh_root_setup(ifmsh);
1243 }
Javier Cardona16dd7262011-08-09 16:45:11 -07001244 conf->dot11MeshGateAnnouncementProtocol =
1245 nconf->dot11MeshGateAnnouncementProtocol;
1246 }
Javier Cardona0507e152011-08-09 16:45:10 -07001247 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_RANN_INTERVAL, mask)) {
1248 conf->dot11MeshHWMPRannInterval =
1249 nconf->dot11MeshHWMPRannInterval;
1250 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001251 return 0;
1252}
1253
Johannes Berg29cbe682010-12-03 09:20:44 +01001254static int ieee80211_join_mesh(struct wiphy *wiphy, struct net_device *dev,
1255 const struct mesh_config *conf,
1256 const struct mesh_setup *setup)
1257{
1258 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1259 struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
Javier Cardonac80d5452010-12-16 17:37:49 -08001260 int err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001261
Javier Cardonac80d5452010-12-16 17:37:49 -08001262 memcpy(&ifmsh->mshcfg, conf, sizeof(struct mesh_config));
1263 err = copy_mesh_setup(ifmsh, setup);
1264 if (err)
1265 return err;
Johannes Berg29cbe682010-12-03 09:20:44 +01001266 ieee80211_start_mesh(sdata);
1267
1268 return 0;
1269}
1270
1271static int ieee80211_leave_mesh(struct wiphy *wiphy, struct net_device *dev)
1272{
1273 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1274
1275 ieee80211_stop_mesh(sdata);
1276
1277 return 0;
1278}
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001279#endif
1280
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001281static int ieee80211_change_bss(struct wiphy *wiphy,
1282 struct net_device *dev,
1283 struct bss_parameters *params)
1284{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001285 struct ieee80211_sub_if_data *sdata;
1286 u32 changed = 0;
1287
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001288 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1289
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001290 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001291 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001292 changed |= BSS_CHANGED_ERP_CTS_PROT;
1293 }
1294 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001295 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001296 params->use_short_preamble;
1297 changed |= BSS_CHANGED_ERP_PREAMBLE;
1298 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001299
1300 if (!sdata->vif.bss_conf.use_short_slot &&
1301 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1302 sdata->vif.bss_conf.use_short_slot = true;
1303 changed |= BSS_CHANGED_ERP_SLOT;
1304 }
1305
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001306 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001307 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001308 params->use_short_slot_time;
1309 changed |= BSS_CHANGED_ERP_SLOT;
1310 }
1311
Jouni Malinen90c97a02008-10-30 16:59:22 +02001312 if (params->basic_rates) {
1313 int i, j;
1314 u32 rates = 0;
1315 struct ieee80211_local *local = wiphy_priv(wiphy);
1316 struct ieee80211_supported_band *sband =
1317 wiphy->bands[local->oper_channel->band];
1318
1319 for (i = 0; i < params->basic_rates_len; i++) {
1320 int rate = (params->basic_rates[i] & 0x7f) * 5;
1321 for (j = 0; j < sband->n_bitrates; j++) {
1322 if (sband->bitrates[j].bitrate == rate)
1323 rates |= BIT(j);
1324 }
1325 }
1326 sdata->vif.bss_conf.basic_rates = rates;
1327 changed |= BSS_CHANGED_BASIC_RATES;
1328 }
1329
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001330 if (params->ap_isolate >= 0) {
1331 if (params->ap_isolate)
1332 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1333 else
1334 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1335 }
1336
Helmut Schaa80d7e402010-11-19 12:40:26 +01001337 if (params->ht_opmode >= 0) {
1338 sdata->vif.bss_conf.ht_operation_mode =
1339 (u16) params->ht_opmode;
1340 changed |= BSS_CHANGED_HT;
1341 }
1342
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001343 ieee80211_bss_info_change_notify(sdata, changed);
1344
1345 return 0;
1346}
1347
Jouni Malinen31888482008-10-30 16:59:24 +02001348static int ieee80211_set_txq_params(struct wiphy *wiphy,
Eliad Pellerf70f01c2011-09-25 20:06:53 +03001349 struct net_device *dev,
Jouni Malinen31888482008-10-30 16:59:24 +02001350 struct ieee80211_txq_params *params)
1351{
1352 struct ieee80211_local *local = wiphy_priv(wiphy);
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001353 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen31888482008-10-30 16:59:24 +02001354 struct ieee80211_tx_queue_params p;
1355
1356 if (!local->ops->conf_tx)
1357 return -EOPNOTSUPP;
1358
1359 memset(&p, 0, sizeof(p));
1360 p.aifs = params->aifs;
1361 p.cw_max = params->cwmax;
1362 p.cw_min = params->cwmin;
1363 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001364
1365 /*
1366 * Setting tx queue params disables u-apsd because it's only
1367 * called in master mode.
1368 */
1369 p.uapsd = false;
1370
Eliad Peller2683d652011-07-14 20:29:42 +03001371 if (params->queue >= local->hw.queues)
1372 return -EINVAL;
1373
Eliad Pellerf6f3def2011-09-25 20:06:54 +03001374 sdata->tx_conf[params->queue] = p;
1375 if (drv_conf_tx(local, sdata, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001376 wiphy_debug(local->hw.wiphy,
1377 "failed to set TX queue parameters for queue %d\n",
1378 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001379 return -EINVAL;
1380 }
1381
1382 return 0;
1383}
1384
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001385static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001386 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001387 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301388 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001389{
1390 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001391 struct ieee80211_sub_if_data *sdata = NULL;
Ben Greeareeabee72011-01-28 10:20:47 -08001392 struct ieee80211_channel *old_oper;
1393 enum nl80211_channel_type old_oper_type;
1394 enum nl80211_channel_type old_vif_oper_type= NL80211_CHAN_NO_HT;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001395
1396 if (netdev)
1397 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001398
Johannes Bergf444de02010-05-05 15:25:02 +02001399 switch (ieee80211_get_channel_mode(local, NULL)) {
1400 case CHAN_MODE_HOPPING:
1401 return -EBUSY;
1402 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001403 if (local->oper_channel != chan)
1404 return -EBUSY;
1405 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001406 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001407 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001408 case CHAN_MODE_UNDEFINED:
1409 break;
1410 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001411
Ben Greeareeabee72011-01-28 10:20:47 -08001412 if (sdata)
1413 old_vif_oper_type = sdata->vif.bss_conf.channel_type;
1414 old_oper_type = local->_oper_channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001415
Johannes Berg0aaffa92010-05-05 15:28:27 +02001416 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1417 return -EBUSY;
1418
Ben Greeareeabee72011-01-28 10:20:47 -08001419 old_oper = local->oper_channel;
1420 local->oper_channel = chan;
1421
1422 /* Update driver if changes were actually made. */
1423 if ((old_oper != local->oper_channel) ||
1424 (old_oper_type != local->_oper_channel_type))
1425 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1426
Johannes Bergef5af742011-10-18 13:39:14 +02001427 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR &&
Ben Greeareeabee72011-01-28 10:20:47 -08001428 old_vif_oper_type != sdata->vif.bss_conf.channel_type)
Johannes Berg0aaffa92010-05-05 15:28:27 +02001429 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1430
1431 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001432}
1433
Bob Copeland665af4f2009-01-19 11:20:53 -05001434#ifdef CONFIG_PM
Johannes Bergff1b6e62011-05-04 15:37:28 +02001435static int ieee80211_suspend(struct wiphy *wiphy,
1436 struct cfg80211_wowlan *wowlan)
Bob Copeland665af4f2009-01-19 11:20:53 -05001437{
Johannes Bergeecc4802011-05-04 15:37:29 +02001438 return __ieee80211_suspend(wiphy_priv(wiphy), wowlan);
Bob Copeland665af4f2009-01-19 11:20:53 -05001439}
1440
1441static int ieee80211_resume(struct wiphy *wiphy)
1442{
1443 return __ieee80211_resume(wiphy_priv(wiphy));
1444}
1445#else
1446#define ieee80211_suspend NULL
1447#define ieee80211_resume NULL
1448#endif
1449
Johannes Berg2a519312009-02-10 21:25:55 +01001450static int ieee80211_scan(struct wiphy *wiphy,
1451 struct net_device *dev,
1452 struct cfg80211_scan_request *req)
1453{
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001454 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg2a519312009-02-10 21:25:55 +01001455
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001456 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1457 case NL80211_IFTYPE_STATION:
1458 case NL80211_IFTYPE_ADHOC:
1459 case NL80211_IFTYPE_MESH_POINT:
1460 case NL80211_IFTYPE_P2P_CLIENT:
1461 break;
1462 case NL80211_IFTYPE_P2P_GO:
1463 if (sdata->local->ops->hw_scan)
1464 break;
Johannes Berge9d77322011-02-01 15:35:36 +01001465 /*
1466 * FIXME: implement NoA while scanning in software,
1467 * for now fall through to allow scanning only when
1468 * beaconing hasn't been configured yet
1469 */
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001470 case NL80211_IFTYPE_AP:
1471 if (sdata->u.ap.beacon)
1472 return -EOPNOTSUPP;
1473 break;
1474 default:
1475 return -EOPNOTSUPP;
1476 }
Johannes Berg2a519312009-02-10 21:25:55 +01001477
1478 return ieee80211_request_scan(sdata, req);
1479}
1480
Luciano Coelho79f460c2011-05-11 17:09:36 +03001481static int
1482ieee80211_sched_scan_start(struct wiphy *wiphy,
1483 struct net_device *dev,
1484 struct cfg80211_sched_scan_request *req)
1485{
1486 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1487
1488 if (!sdata->local->ops->sched_scan_start)
1489 return -EOPNOTSUPP;
1490
1491 return ieee80211_request_sched_scan_start(sdata, req);
1492}
1493
1494static int
Luciano Coelho85a99942011-05-12 16:28:29 +03001495ieee80211_sched_scan_stop(struct wiphy *wiphy, struct net_device *dev)
Luciano Coelho79f460c2011-05-11 17:09:36 +03001496{
1497 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1498
1499 if (!sdata->local->ops->sched_scan_stop)
1500 return -EOPNOTSUPP;
1501
Luciano Coelho85a99942011-05-12 16:28:29 +03001502 return ieee80211_request_sched_scan_stop(sdata);
Luciano Coelho79f460c2011-05-11 17:09:36 +03001503}
1504
Jouni Malinen636a5d32009-03-19 13:39:22 +02001505static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1506 struct cfg80211_auth_request *req)
1507{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001508 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001509}
1510
1511static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1512 struct cfg80211_assoc_request *req)
1513{
Johannes Bergf444de02010-05-05 15:25:02 +02001514 struct ieee80211_local *local = wiphy_priv(wiphy);
1515 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1516
1517 switch (ieee80211_get_channel_mode(local, sdata)) {
1518 case CHAN_MODE_HOPPING:
1519 return -EBUSY;
1520 case CHAN_MODE_FIXED:
1521 if (local->oper_channel == req->bss->channel)
1522 break;
1523 return -EBUSY;
1524 case CHAN_MODE_UNDEFINED:
1525 break;
1526 }
1527
Johannes Berg77fdaa12009-07-07 03:45:17 +02001528 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001529}
1530
1531static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001532 struct cfg80211_deauth_request *req,
1533 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001534{
Johannes Berg667503d2009-07-07 03:56:11 +02001535 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1536 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001537}
1538
1539static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001540 struct cfg80211_disassoc_request *req,
1541 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001542{
Johannes Berg667503d2009-07-07 03:56:11 +02001543 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1544 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001545}
1546
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001547static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1548 struct cfg80211_ibss_params *params)
1549{
Johannes Bergf444de02010-05-05 15:25:02 +02001550 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001551 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1552
Johannes Bergf444de02010-05-05 15:25:02 +02001553 switch (ieee80211_get_channel_mode(local, sdata)) {
1554 case CHAN_MODE_HOPPING:
1555 return -EBUSY;
1556 case CHAN_MODE_FIXED:
1557 if (!params->channel_fixed)
1558 return -EBUSY;
1559 if (local->oper_channel == params->channel)
1560 break;
1561 return -EBUSY;
1562 case CHAN_MODE_UNDEFINED:
1563 break;
1564 }
1565
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001566 return ieee80211_ibss_join(sdata, params);
1567}
1568
1569static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1570{
1571 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1572
1573 return ieee80211_ibss_leave(sdata);
1574}
1575
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001576static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1577{
1578 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001579 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001580
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001581 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1582 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1583
1584 if (err)
1585 return err;
1586 }
1587
Lukáš Turek310bc672009-12-21 22:50:48 +01001588 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1589 err = drv_set_coverage_class(local, wiphy->coverage_class);
1590
1591 if (err)
1592 return err;
1593 }
1594
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001595 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001596 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001597
Johannes Berg24487982009-04-23 18:52:52 +02001598 if (err)
1599 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001600 }
1601
1602 if (changed & WIPHY_PARAM_RETRY_SHORT)
1603 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1604 if (changed & WIPHY_PARAM_RETRY_LONG)
1605 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1606 if (changed &
1607 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1608 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1609
1610 return 0;
1611}
1612
Johannes Berg7643a2c2009-06-02 13:01:39 +02001613static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001614 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001615{
1616 struct ieee80211_local *local = wiphy_priv(wiphy);
1617 struct ieee80211_channel *chan = local->hw.conf.channel;
1618 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001619
1620 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001621 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001622 local->user_power_level = -1;
1623 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001624 case NL80211_TX_POWER_LIMITED:
1625 if (mbm < 0 || (mbm % 100))
1626 return -EOPNOTSUPP;
1627 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001628 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001629 case NL80211_TX_POWER_FIXED:
1630 if (mbm < 0 || (mbm % 100))
1631 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001632 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001633 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001634 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001635 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001636 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001637 }
1638
1639 ieee80211_hw_config(local, changes);
1640
1641 return 0;
1642}
1643
1644static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1645{
1646 struct ieee80211_local *local = wiphy_priv(wiphy);
1647
1648 *dbm = local->hw.conf.power_level;
1649
Johannes Berg7643a2c2009-06-02 13:01:39 +02001650 return 0;
1651}
1652
Johannes Bergab737a42009-07-01 21:26:58 +02001653static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02001654 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02001655{
1656 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1657
1658 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1659
1660 return 0;
1661}
1662
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001663static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1664{
1665 struct ieee80211_local *local = wiphy_priv(wiphy);
1666
1667 drv_rfkill_poll(local);
1668}
1669
Johannes Bergaff89a92009-07-01 21:26:51 +02001670#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001671static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001672{
1673 struct ieee80211_local *local = wiphy_priv(wiphy);
1674
1675 if (!local->ops->testmode_cmd)
1676 return -EOPNOTSUPP;
1677
1678 return local->ops->testmode_cmd(&local->hw, data, len);
1679}
Wey-Yi Guy71063f02011-05-20 09:05:54 -07001680
1681static int ieee80211_testmode_dump(struct wiphy *wiphy,
1682 struct sk_buff *skb,
1683 struct netlink_callback *cb,
1684 void *data, int len)
1685{
1686 struct ieee80211_local *local = wiphy_priv(wiphy);
1687
1688 if (!local->ops->testmode_dump)
1689 return -EOPNOTSUPP;
1690
1691 return local->ops->testmode_dump(&local->hw, skb, cb, data, len);
1692}
Johannes Bergaff89a92009-07-01 21:26:51 +02001693#endif
1694
Johannes Berg0f782312009-12-01 13:37:02 +01001695int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1696 enum ieee80211_smps_mode smps_mode)
1697{
1698 const u8 *ap;
1699 enum ieee80211_smps_mode old_req;
1700 int err;
1701
Johannes Berg243e6df2011-04-19 20:44:04 +02001702 lockdep_assert_held(&sdata->u.mgd.mtx);
1703
Johannes Berg0f782312009-12-01 13:37:02 +01001704 old_req = sdata->u.mgd.req_smps;
1705 sdata->u.mgd.req_smps = smps_mode;
1706
1707 if (old_req == smps_mode &&
1708 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1709 return 0;
1710
1711 /*
1712 * If not associated, or current association is not an HT
1713 * association, there's no need to send an action frame.
1714 */
1715 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001716 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001717 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02001718 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01001719 mutex_unlock(&sdata->local->iflist_mtx);
1720 return 0;
1721 }
1722
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001723 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001724
1725 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1726 if (sdata->u.mgd.powersave)
1727 smps_mode = IEEE80211_SMPS_DYNAMIC;
1728 else
1729 smps_mode = IEEE80211_SMPS_OFF;
1730 }
1731
1732 /* send SM PS frame to AP */
1733 err = ieee80211_send_smps_action(sdata, smps_mode,
1734 ap, ap);
1735 if (err)
1736 sdata->u.mgd.req_smps = old_req;
1737
1738 return err;
1739}
1740
Johannes Bergbc92afd2009-07-01 21:26:57 +02001741static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1742 bool enabled, int timeout)
1743{
1744 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1745 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001746
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001747 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1748 return -EOPNOTSUPP;
1749
Johannes Bergbc92afd2009-07-01 21:26:57 +02001750 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1751 return -EOPNOTSUPP;
1752
1753 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001754 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001755 return 0;
1756
1757 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001758 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001759
Johannes Berg0f782312009-12-01 13:37:02 +01001760 /* no change, but if automatic follow powersave */
1761 mutex_lock(&sdata->u.mgd.mtx);
1762 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1763 mutex_unlock(&sdata->u.mgd.mtx);
1764
Johannes Bergbc92afd2009-07-01 21:26:57 +02001765 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1766 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1767
1768 ieee80211_recalc_ps(local, -1);
1769
1770 return 0;
1771}
1772
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001773static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1774 struct net_device *dev,
1775 s32 rssi_thold, u32 rssi_hyst)
1776{
1777 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1779 struct ieee80211_vif *vif = &sdata->vif;
1780 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1781
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001782 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1783 rssi_hyst == bss_conf->cqm_rssi_hyst)
1784 return 0;
1785
1786 bss_conf->cqm_rssi_thold = rssi_thold;
1787 bss_conf->cqm_rssi_hyst = rssi_hyst;
1788
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001789 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1790 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1791 return -EOPNOTSUPP;
1792 return 0;
1793 }
1794
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001795 /* tell the driver upon association, unless already associated */
1796 if (sdata->u.mgd.associated)
1797 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1798
1799 return 0;
1800}
1801
Johannes Berg99303802009-07-01 21:26:59 +02001802static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1803 struct net_device *dev,
1804 const u8 *addr,
1805 const struct cfg80211_bitrate_mask *mask)
1806{
1807 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1808 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05301809 int i, ret;
Johannes Berg99303802009-07-01 21:26:59 +02001810
Sujith Manoharanbdbfd6b2011-04-27 16:56:51 +05301811 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
1812 ret = drv_set_bitrate_mask(local, sdata, mask);
1813 if (ret)
1814 return ret;
1815 }
Johannes Berg99303802009-07-01 21:26:59 +02001816
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001817 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1818 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001819
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001820 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001821}
1822
Johannes Berg21f83582010-12-18 17:20:47 +01001823static int ieee80211_remain_on_channel_hw(struct ieee80211_local *local,
1824 struct net_device *dev,
1825 struct ieee80211_channel *chan,
1826 enum nl80211_channel_type chantype,
1827 unsigned int duration, u64 *cookie)
1828{
1829 int ret;
1830 u32 random_cookie;
1831
1832 lockdep_assert_held(&local->mtx);
1833
1834 if (local->hw_roc_cookie)
1835 return -EBUSY;
1836 /* must be nonzero */
1837 random_cookie = random32() | 1;
1838
1839 *cookie = random_cookie;
1840 local->hw_roc_dev = dev;
1841 local->hw_roc_cookie = random_cookie;
1842 local->hw_roc_channel = chan;
1843 local->hw_roc_channel_type = chantype;
1844 local->hw_roc_duration = duration;
1845 ret = drv_remain_on_channel(local, chan, chantype, duration);
1846 if (ret) {
1847 local->hw_roc_channel = NULL;
1848 local->hw_roc_cookie = 0;
1849 }
1850
1851 return ret;
1852}
1853
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001854static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1855 struct net_device *dev,
1856 struct ieee80211_channel *chan,
1857 enum nl80211_channel_type channel_type,
1858 unsigned int duration,
1859 u64 *cookie)
1860{
1861 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg21f83582010-12-18 17:20:47 +01001862 struct ieee80211_local *local = sdata->local;
1863
1864 if (local->ops->remain_on_channel) {
1865 int ret;
1866
1867 mutex_lock(&local->mtx);
1868 ret = ieee80211_remain_on_channel_hw(local, dev,
1869 chan, channel_type,
1870 duration, cookie);
Johannes Berg90fc4b32010-12-18 17:20:48 +01001871 local->hw_roc_for_tx = false;
Johannes Berg21f83582010-12-18 17:20:47 +01001872 mutex_unlock(&local->mtx);
1873
1874 return ret;
1875 }
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001876
1877 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1878 duration, cookie);
1879}
1880
Johannes Berg21f83582010-12-18 17:20:47 +01001881static int ieee80211_cancel_remain_on_channel_hw(struct ieee80211_local *local,
1882 u64 cookie)
1883{
1884 int ret;
1885
1886 lockdep_assert_held(&local->mtx);
1887
1888 if (local->hw_roc_cookie != cookie)
1889 return -ENOENT;
1890
1891 ret = drv_cancel_remain_on_channel(local);
1892 if (ret)
1893 return ret;
1894
1895 local->hw_roc_cookie = 0;
1896 local->hw_roc_channel = NULL;
1897
1898 ieee80211_recalc_idle(local);
1899
1900 return 0;
1901}
1902
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001903static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1904 struct net_device *dev,
1905 u64 cookie)
1906{
1907 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg21f83582010-12-18 17:20:47 +01001908 struct ieee80211_local *local = sdata->local;
1909
1910 if (local->ops->cancel_remain_on_channel) {
1911 int ret;
1912
1913 mutex_lock(&local->mtx);
1914 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
1915 mutex_unlock(&local->mtx);
1916
1917 return ret;
1918 }
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001919
1920 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1921}
1922
Johannes Bergf30221e2010-11-25 10:02:30 +01001923static enum work_done_result
1924ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
1925{
1926 /*
1927 * Use the data embedded in the work struct for reporting
1928 * here so if the driver mangled the SKB before dropping
1929 * it (which is the only way we really should get here)
1930 * then we don't report mangled data.
1931 *
1932 * If there was no wait time, then by the time we get here
1933 * the driver will likely not have reported the status yet,
1934 * so in that case userspace will have to deal with it.
1935 */
1936
Johannes Berg28a1bcd2011-10-04 18:27:10 +02001937 if (wk->offchan_tx.wait && !wk->offchan_tx.status)
Johannes Bergf30221e2010-11-25 10:02:30 +01001938 cfg80211_mgmt_tx_status(wk->sdata->dev,
1939 (unsigned long) wk->offchan_tx.frame,
1940 wk->ie, wk->ie_len, false, GFP_KERNEL);
1941
1942 return WORK_DONE_DESTROY;
1943}
1944
Johannes Berg2e161f782010-08-12 15:38:38 +02001945static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001946 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f782010-08-12 15:38:38 +02001947 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001948 bool channel_type_valid, unsigned int wait,
Rajkumar Manoharane9f935e2011-09-25 14:53:30 +05301949 const u8 *buf, size_t len, bool no_cck,
Johannes Berge247bd902011-11-04 11:18:21 +01001950 bool dont_wait_for_ack, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001951{
Johannes Berg9d38d852010-06-09 17:20:33 +02001952 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1953 struct ieee80211_local *local = sdata->local;
1954 struct sk_buff *skb;
1955 struct sta_info *sta;
Johannes Bergf30221e2010-11-25 10:02:30 +01001956 struct ieee80211_work *wk;
Johannes Berg9d38d852010-06-09 17:20:33 +02001957 const struct ieee80211_mgmt *mgmt = (void *)buf;
Johannes Berge247bd902011-11-04 11:18:21 +01001958 u32 flags;
Johannes Bergf30221e2010-11-25 10:02:30 +01001959 bool is_offchan = false;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001960
Johannes Berge247bd902011-11-04 11:18:21 +01001961 if (dont_wait_for_ack)
1962 flags = IEEE80211_TX_CTL_NO_ACK;
1963 else
1964 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1965 IEEE80211_TX_CTL_REQ_TX_STATUS;
1966
Johannes Berg9d38d852010-06-09 17:20:33 +02001967 /* Check that we are on the requested channel for transmission */
1968 if (chan != local->tmp_channel &&
1969 chan != local->oper_channel)
Johannes Bergf30221e2010-11-25 10:02:30 +01001970 is_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02001971 if (channel_type_valid &&
1972 (channel_type != local->tmp_channel_type &&
1973 channel_type != local->_oper_channel_type))
Johannes Bergf30221e2010-11-25 10:02:30 +01001974 is_offchan = true;
1975
Johannes Berg21f83582010-12-18 17:20:47 +01001976 if (chan == local->hw_roc_channel) {
1977 /* TODO: check channel type? */
1978 is_offchan = false;
1979 flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
1980 }
1981
Rajkumar Manoharanaad14ce2011-09-25 14:53:31 +05301982 if (no_cck)
1983 flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
1984
Johannes Bergf30221e2010-11-25 10:02:30 +01001985 if (is_offchan && !offchan)
Johannes Berg9d38d852010-06-09 17:20:33 +02001986 return -EBUSY;
1987
1988 switch (sdata->vif.type) {
1989 case NL80211_IFTYPE_ADHOC:
Johannes Berg663fcaf2010-09-30 21:06:09 +02001990 case NL80211_IFTYPE_AP:
1991 case NL80211_IFTYPE_AP_VLAN:
1992 case NL80211_IFTYPE_P2P_GO:
Javier Cardonac7108a72010-12-16 17:37:50 -08001993 case NL80211_IFTYPE_MESH_POINT:
Johannes Berg663fcaf2010-09-30 21:06:09 +02001994 if (!ieee80211_is_action(mgmt->frame_control) ||
1995 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02001996 break;
1997 rcu_read_lock();
1998 sta = sta_info_get(sdata, mgmt->da);
1999 rcu_read_unlock();
2000 if (!sta)
2001 return -ENOLINK;
2002 break;
2003 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02002004 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg9d38d852010-06-09 17:20:33 +02002005 break;
2006 default:
2007 return -EOPNOTSUPP;
2008 }
2009
2010 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
2011 if (!skb)
2012 return -ENOMEM;
2013 skb_reserve(skb, local->hw.extra_tx_headroom);
2014
2015 memcpy(skb_put(skb, len), buf, len);
2016
2017 IEEE80211_SKB_CB(skb)->flags = flags;
2018
2019 skb->dev = sdata->dev;
Johannes Berg9d38d852010-06-09 17:20:33 +02002020
2021 *cookie = (unsigned long) skb;
Johannes Bergf30221e2010-11-25 10:02:30 +01002022
Johannes Berg90fc4b32010-12-18 17:20:48 +01002023 if (is_offchan && local->ops->remain_on_channel) {
2024 unsigned int duration;
2025 int ret;
2026
2027 mutex_lock(&local->mtx);
2028 /*
2029 * If the duration is zero, then the driver
2030 * wouldn't actually do anything. Set it to
2031 * 100 for now.
2032 *
2033 * TODO: cancel the off-channel operation
2034 * when we get the SKB's TX status and
2035 * the wait time was zero before.
2036 */
2037 duration = 100;
2038 if (wait)
2039 duration = wait;
2040 ret = ieee80211_remain_on_channel_hw(local, dev, chan,
2041 channel_type,
2042 duration, cookie);
2043 if (ret) {
2044 kfree_skb(skb);
2045 mutex_unlock(&local->mtx);
2046 return ret;
2047 }
2048
2049 local->hw_roc_for_tx = true;
2050 local->hw_roc_duration = wait;
2051
2052 /*
2053 * queue up frame for transmission after
2054 * ieee80211_ready_on_channel call
2055 */
2056
2057 /* modify cookie to prevent API mismatches */
2058 *cookie ^= 2;
2059 IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_TX_OFFCHAN;
2060 local->hw_roc_skb = skb;
Johannes Berg4334ec82011-02-02 16:58:06 +01002061 local->hw_roc_skb_for_status = skb;
Johannes Berg90fc4b32010-12-18 17:20:48 +01002062 mutex_unlock(&local->mtx);
2063
2064 return 0;
2065 }
2066
Johannes Bergf30221e2010-11-25 10:02:30 +01002067 /*
2068 * Can transmit right away if the channel was the
2069 * right one and there's no wait involved... If a
2070 * wait is involved, we might otherwise not be on
2071 * the right channel for long enough!
2072 */
2073 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
2074 ieee80211_tx_skb(sdata, skb);
2075 return 0;
2076 }
2077
2078 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
2079 if (!wk) {
2080 kfree_skb(skb);
2081 return -ENOMEM;
2082 }
2083
2084 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
2085 wk->chan = chan;
Ben Greear4d51e142011-02-07 13:44:34 -08002086 wk->chan_type = channel_type;
Johannes Bergf30221e2010-11-25 10:02:30 +01002087 wk->sdata = sdata;
2088 wk->done = ieee80211_offchan_tx_done;
2089 wk->offchan_tx.frame = skb;
2090 wk->offchan_tx.wait = wait;
2091 wk->ie_len = len;
2092 memcpy(wk->ie, buf, len);
2093
2094 ieee80211_add_work(wk);
Johannes Berg9d38d852010-06-09 17:20:33 +02002095 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02002096}
2097
Johannes Bergf30221e2010-11-25 10:02:30 +01002098static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
2099 struct net_device *dev,
2100 u64 cookie)
2101{
2102 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2103 struct ieee80211_local *local = sdata->local;
2104 struct ieee80211_work *wk;
2105 int ret = -ENOENT;
2106
2107 mutex_lock(&local->mtx);
Johannes Berg90fc4b32010-12-18 17:20:48 +01002108
2109 if (local->ops->cancel_remain_on_channel) {
2110 cookie ^= 2;
2111 ret = ieee80211_cancel_remain_on_channel_hw(local, cookie);
2112
2113 if (ret == 0) {
2114 kfree_skb(local->hw_roc_skb);
2115 local->hw_roc_skb = NULL;
Johannes Berg4334ec82011-02-02 16:58:06 +01002116 local->hw_roc_skb_for_status = NULL;
Johannes Berg90fc4b32010-12-18 17:20:48 +01002117 }
2118
2119 mutex_unlock(&local->mtx);
2120
2121 return ret;
2122 }
2123
Johannes Bergf30221e2010-11-25 10:02:30 +01002124 list_for_each_entry(wk, &local->work_list, list) {
2125 if (wk->sdata != sdata)
2126 continue;
2127
2128 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
2129 continue;
2130
2131 if (cookie != (unsigned long) wk->offchan_tx.frame)
2132 continue;
2133
2134 wk->timeout = jiffies;
2135
2136 ieee80211_queue_work(&local->hw, &local->work_work);
2137 ret = 0;
2138 break;
2139 }
2140 mutex_unlock(&local->mtx);
2141
2142 return ret;
2143}
2144
Johannes Berg7be50862010-10-13 12:06:24 +02002145static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
2146 struct net_device *dev,
2147 u16 frame_type, bool reg)
2148{
2149 struct ieee80211_local *local = wiphy_priv(wiphy);
2150
2151 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
2152 return;
2153
2154 if (reg)
2155 local->probe_req_reg++;
2156 else
2157 local->probe_req_reg--;
2158
2159 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
2160}
2161
Bruno Randolf15d96752010-11-10 12:50:56 +09002162static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
2163{
2164 struct ieee80211_local *local = wiphy_priv(wiphy);
2165
2166 if (local->started)
2167 return -EOPNOTSUPP;
2168
2169 return drv_set_antenna(local, tx_ant, rx_ant);
2170}
2171
2172static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
2173{
2174 struct ieee80211_local *local = wiphy_priv(wiphy);
2175
2176 return drv_get_antenna(local, tx_ant, rx_ant);
2177}
2178
John W. Linville38c09152011-03-07 16:19:18 -05002179static int ieee80211_set_ringparam(struct wiphy *wiphy, u32 tx, u32 rx)
2180{
2181 struct ieee80211_local *local = wiphy_priv(wiphy);
2182
2183 return drv_set_ringparam(local, tx, rx);
2184}
2185
2186static void ieee80211_get_ringparam(struct wiphy *wiphy,
2187 u32 *tx, u32 *tx_max, u32 *rx, u32 *rx_max)
2188{
2189 struct ieee80211_local *local = wiphy_priv(wiphy);
2190
2191 drv_get_ringparam(local, tx, tx_max, rx, rx_max);
2192}
2193
Johannes Bergc68f4b82011-07-05 16:35:41 +02002194static int ieee80211_set_rekey_data(struct wiphy *wiphy,
2195 struct net_device *dev,
2196 struct cfg80211_gtk_rekey_data *data)
2197{
2198 struct ieee80211_local *local = wiphy_priv(wiphy);
2199 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2200
2201 if (!local->ops->set_rekey_data)
2202 return -EOPNOTSUPP;
2203
2204 drv_set_rekey_data(local, sdata, data);
2205
2206 return 0;
2207}
2208
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002209static void ieee80211_tdls_add_ext_capab(struct sk_buff *skb)
2210{
2211 u8 *pos = (void *)skb_put(skb, 7);
2212
2213 *pos++ = WLAN_EID_EXT_CAPABILITY;
2214 *pos++ = 5; /* len */
2215 *pos++ = 0x0;
2216 *pos++ = 0x0;
2217 *pos++ = 0x0;
2218 *pos++ = 0x0;
2219 *pos++ = WLAN_EXT_CAPA5_TDLS_ENABLED;
2220}
2221
2222static u16 ieee80211_get_tdls_sta_capab(struct ieee80211_sub_if_data *sdata)
2223{
2224 struct ieee80211_local *local = sdata->local;
2225 u16 capab;
2226
2227 capab = 0;
2228 if (local->oper_channel->band != IEEE80211_BAND_2GHZ)
2229 return capab;
2230
2231 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_SLOT_INCAPABLE))
2232 capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
2233 if (!(local->hw.flags & IEEE80211_HW_2GHZ_SHORT_PREAMBLE_INCAPABLE))
2234 capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
2235
2236 return capab;
2237}
2238
2239static void ieee80211_tdls_add_link_ie(struct sk_buff *skb, u8 *src_addr,
2240 u8 *peer, u8 *bssid)
2241{
2242 struct ieee80211_tdls_lnkie *lnkid;
2243
2244 lnkid = (void *)skb_put(skb, sizeof(struct ieee80211_tdls_lnkie));
2245
2246 lnkid->ie_type = WLAN_EID_LINK_ID;
2247 lnkid->ie_len = sizeof(struct ieee80211_tdls_lnkie) - 2;
2248
2249 memcpy(lnkid->bssid, bssid, ETH_ALEN);
2250 memcpy(lnkid->init_sta, src_addr, ETH_ALEN);
2251 memcpy(lnkid->resp_sta, peer, ETH_ALEN);
2252}
2253
2254static int
2255ieee80211_prep_tdls_encap_data(struct wiphy *wiphy, struct net_device *dev,
2256 u8 *peer, u8 action_code, u8 dialog_token,
2257 u16 status_code, struct sk_buff *skb)
2258{
2259 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2260 struct ieee80211_tdls_data *tf;
2261
2262 tf = (void *)skb_put(skb, offsetof(struct ieee80211_tdls_data, u));
2263
2264 memcpy(tf->da, peer, ETH_ALEN);
2265 memcpy(tf->sa, sdata->vif.addr, ETH_ALEN);
2266 tf->ether_type = cpu_to_be16(ETH_P_TDLS);
2267 tf->payload_type = WLAN_TDLS_SNAP_RFTYPE;
2268
2269 switch (action_code) {
2270 case WLAN_TDLS_SETUP_REQUEST:
2271 tf->category = WLAN_CATEGORY_TDLS;
2272 tf->action_code = WLAN_TDLS_SETUP_REQUEST;
2273
2274 skb_put(skb, sizeof(tf->u.setup_req));
2275 tf->u.setup_req.dialog_token = dialog_token;
2276 tf->u.setup_req.capability =
2277 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2278
2279 ieee80211_add_srates_ie(&sdata->vif, skb);
2280 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2281 ieee80211_tdls_add_ext_capab(skb);
2282 break;
2283 case WLAN_TDLS_SETUP_RESPONSE:
2284 tf->category = WLAN_CATEGORY_TDLS;
2285 tf->action_code = WLAN_TDLS_SETUP_RESPONSE;
2286
2287 skb_put(skb, sizeof(tf->u.setup_resp));
2288 tf->u.setup_resp.status_code = cpu_to_le16(status_code);
2289 tf->u.setup_resp.dialog_token = dialog_token;
2290 tf->u.setup_resp.capability =
2291 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2292
2293 ieee80211_add_srates_ie(&sdata->vif, skb);
2294 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2295 ieee80211_tdls_add_ext_capab(skb);
2296 break;
2297 case WLAN_TDLS_SETUP_CONFIRM:
2298 tf->category = WLAN_CATEGORY_TDLS;
2299 tf->action_code = WLAN_TDLS_SETUP_CONFIRM;
2300
2301 skb_put(skb, sizeof(tf->u.setup_cfm));
2302 tf->u.setup_cfm.status_code = cpu_to_le16(status_code);
2303 tf->u.setup_cfm.dialog_token = dialog_token;
2304 break;
2305 case WLAN_TDLS_TEARDOWN:
2306 tf->category = WLAN_CATEGORY_TDLS;
2307 tf->action_code = WLAN_TDLS_TEARDOWN;
2308
2309 skb_put(skb, sizeof(tf->u.teardown));
2310 tf->u.teardown.reason_code = cpu_to_le16(status_code);
2311 break;
2312 case WLAN_TDLS_DISCOVERY_REQUEST:
2313 tf->category = WLAN_CATEGORY_TDLS;
2314 tf->action_code = WLAN_TDLS_DISCOVERY_REQUEST;
2315
2316 skb_put(skb, sizeof(tf->u.discover_req));
2317 tf->u.discover_req.dialog_token = dialog_token;
2318 break;
2319 default:
2320 return -EINVAL;
2321 }
2322
2323 return 0;
2324}
2325
2326static int
2327ieee80211_prep_tdls_direct(struct wiphy *wiphy, struct net_device *dev,
2328 u8 *peer, u8 action_code, u8 dialog_token,
2329 u16 status_code, struct sk_buff *skb)
2330{
2331 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2332 struct ieee80211_mgmt *mgmt;
2333
2334 mgmt = (void *)skb_put(skb, 24);
2335 memset(mgmt, 0, 24);
2336 memcpy(mgmt->da, peer, ETH_ALEN);
2337 memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
2338 memcpy(mgmt->bssid, sdata->u.mgd.bssid, ETH_ALEN);
2339
2340 mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
2341 IEEE80211_STYPE_ACTION);
2342
2343 switch (action_code) {
2344 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2345 skb_put(skb, 1 + sizeof(mgmt->u.action.u.tdls_discover_resp));
2346 mgmt->u.action.category = WLAN_CATEGORY_PUBLIC;
2347 mgmt->u.action.u.tdls_discover_resp.action_code =
2348 WLAN_PUB_ACTION_TDLS_DISCOVER_RES;
2349 mgmt->u.action.u.tdls_discover_resp.dialog_token =
2350 dialog_token;
2351 mgmt->u.action.u.tdls_discover_resp.capability =
2352 cpu_to_le16(ieee80211_get_tdls_sta_capab(sdata));
2353
2354 ieee80211_add_srates_ie(&sdata->vif, skb);
2355 ieee80211_add_ext_srates_ie(&sdata->vif, skb);
2356 ieee80211_tdls_add_ext_capab(skb);
2357 break;
2358 default:
2359 return -EINVAL;
2360 }
2361
2362 return 0;
2363}
2364
2365static int ieee80211_tdls_mgmt(struct wiphy *wiphy, struct net_device *dev,
2366 u8 *peer, u8 action_code, u8 dialog_token,
2367 u16 status_code, const u8 *extra_ies,
2368 size_t extra_ies_len)
2369{
2370 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2371 struct ieee80211_local *local = sdata->local;
2372 struct ieee80211_tx_info *info;
2373 struct sk_buff *skb = NULL;
2374 bool send_direct;
2375 int ret;
2376
2377 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2378 return -ENOTSUPP;
2379
2380 /* make sure we are in managed mode, and associated */
2381 if (sdata->vif.type != NL80211_IFTYPE_STATION ||
2382 !sdata->u.mgd.associated)
2383 return -EINVAL;
2384
2385#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2386 printk(KERN_DEBUG "TDLS mgmt action %d peer %pM\n", action_code, peer);
2387#endif
2388
2389 skb = dev_alloc_skb(local->hw.extra_tx_headroom +
2390 max(sizeof(struct ieee80211_mgmt),
2391 sizeof(struct ieee80211_tdls_data)) +
2392 50 + /* supported rates */
2393 7 + /* ext capab */
2394 extra_ies_len +
2395 sizeof(struct ieee80211_tdls_lnkie));
2396 if (!skb)
2397 return -ENOMEM;
2398
2399 info = IEEE80211_SKB_CB(skb);
2400 skb_reserve(skb, local->hw.extra_tx_headroom);
2401
2402 switch (action_code) {
2403 case WLAN_TDLS_SETUP_REQUEST:
2404 case WLAN_TDLS_SETUP_RESPONSE:
2405 case WLAN_TDLS_SETUP_CONFIRM:
2406 case WLAN_TDLS_TEARDOWN:
2407 case WLAN_TDLS_DISCOVERY_REQUEST:
2408 ret = ieee80211_prep_tdls_encap_data(wiphy, dev, peer,
2409 action_code, dialog_token,
2410 status_code, skb);
2411 send_direct = false;
2412 break;
2413 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2414 ret = ieee80211_prep_tdls_direct(wiphy, dev, peer, action_code,
2415 dialog_token, status_code,
2416 skb);
2417 send_direct = true;
2418 break;
2419 default:
2420 ret = -ENOTSUPP;
2421 break;
2422 }
2423
2424 if (ret < 0)
2425 goto fail;
2426
2427 if (extra_ies_len)
2428 memcpy(skb_put(skb, extra_ies_len), extra_ies, extra_ies_len);
2429
2430 /* the TDLS link IE is always added last */
2431 switch (action_code) {
2432 case WLAN_TDLS_SETUP_REQUEST:
2433 case WLAN_TDLS_SETUP_CONFIRM:
2434 case WLAN_TDLS_TEARDOWN:
2435 case WLAN_TDLS_DISCOVERY_REQUEST:
2436 /* we are the initiator */
2437 ieee80211_tdls_add_link_ie(skb, sdata->vif.addr, peer,
2438 sdata->u.mgd.bssid);
2439 break;
2440 case WLAN_TDLS_SETUP_RESPONSE:
2441 case WLAN_PUB_ACTION_TDLS_DISCOVER_RES:
2442 /* we are the responder */
2443 ieee80211_tdls_add_link_ie(skb, peer, sdata->vif.addr,
2444 sdata->u.mgd.bssid);
2445 break;
2446 default:
2447 ret = -ENOTSUPP;
2448 goto fail;
2449 }
2450
2451 if (send_direct) {
2452 ieee80211_tx_skb(sdata, skb);
2453 return 0;
2454 }
2455
2456 /*
2457 * According to 802.11z: Setup req/resp are sent in AC_BK, otherwise
2458 * we should default to AC_VI.
2459 */
2460 switch (action_code) {
2461 case WLAN_TDLS_SETUP_REQUEST:
2462 case WLAN_TDLS_SETUP_RESPONSE:
2463 skb_set_queue_mapping(skb, IEEE80211_AC_BK);
2464 skb->priority = 2;
2465 break;
2466 default:
2467 skb_set_queue_mapping(skb, IEEE80211_AC_VI);
2468 skb->priority = 5;
2469 break;
2470 }
2471
2472 /* disable bottom halves when entering the Tx path */
2473 local_bh_disable();
2474 ret = ieee80211_subif_start_xmit(skb, dev);
2475 local_bh_enable();
2476
2477 return ret;
2478
2479fail:
2480 dev_kfree_skb(skb);
2481 return ret;
2482}
2483
2484static int ieee80211_tdls_oper(struct wiphy *wiphy, struct net_device *dev,
2485 u8 *peer, enum nl80211_tdls_operation oper)
2486{
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002487 struct sta_info *sta;
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002488 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2489
2490 if (!(wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS))
2491 return -ENOTSUPP;
2492
2493 if (sdata->vif.type != NL80211_IFTYPE_STATION)
2494 return -EINVAL;
2495
2496#ifdef CONFIG_MAC80211_VERBOSE_TDLS_DEBUG
2497 printk(KERN_DEBUG "TDLS oper %d peer %pM\n", oper, peer);
2498#endif
2499
2500 switch (oper) {
2501 case NL80211_TDLS_ENABLE_LINK:
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002502 rcu_read_lock();
2503 sta = sta_info_get(sdata, peer);
2504 if (!sta) {
2505 rcu_read_unlock();
2506 return -ENOLINK;
2507 }
2508
Johannes Bergc2c98fd2011-09-29 16:04:36 +02002509 set_sta_flag(sta, WLAN_STA_TDLS_PEER_AUTH);
Arik Nemtsov941c93c2011-09-28 14:12:54 +03002510 rcu_read_unlock();
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002511 break;
2512 case NL80211_TDLS_DISABLE_LINK:
2513 return sta_info_destroy_addr(sdata, peer);
2514 case NL80211_TDLS_TEARDOWN:
2515 case NL80211_TDLS_SETUP:
2516 case NL80211_TDLS_DISCOVERY_REQ:
2517 /* We don't support in-driver setup/teardown/discovery */
2518 return -ENOTSUPP;
2519 default:
2520 return -ENOTSUPP;
2521 }
2522
2523 return 0;
2524}
2525
Johannes Berg06500732011-11-04 11:18:16 +01002526static int ieee80211_probe_client(struct wiphy *wiphy, struct net_device *dev,
2527 const u8 *peer, u64 *cookie)
2528{
2529 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2530 struct ieee80211_local *local = sdata->local;
2531 struct ieee80211_qos_hdr *nullfunc;
2532 struct sk_buff *skb;
2533 int size = sizeof(*nullfunc);
2534 __le16 fc;
2535 bool qos;
2536 struct ieee80211_tx_info *info;
2537 struct sta_info *sta;
2538
2539 rcu_read_lock();
2540 sta = sta_info_get(sdata, peer);
2541 if (sta)
2542 qos = test_sta_flag(sta, WLAN_STA_WME);
2543 rcu_read_unlock();
2544
2545 if (!sta)
2546 return -ENOLINK;
2547
2548 if (qos) {
2549 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2550 IEEE80211_STYPE_QOS_NULLFUNC |
2551 IEEE80211_FCTL_FROMDS);
2552 } else {
2553 size -= 2;
2554 fc = cpu_to_le16(IEEE80211_FTYPE_DATA |
2555 IEEE80211_STYPE_NULLFUNC |
2556 IEEE80211_FCTL_FROMDS);
2557 }
2558
2559 skb = dev_alloc_skb(local->hw.extra_tx_headroom + size);
2560 if (!skb)
2561 return -ENOMEM;
2562
2563 skb->dev = dev;
2564
2565 skb_reserve(skb, local->hw.extra_tx_headroom);
2566
2567 nullfunc = (void *) skb_put(skb, size);
2568 nullfunc->frame_control = fc;
2569 nullfunc->duration_id = 0;
2570 memcpy(nullfunc->addr1, sta->sta.addr, ETH_ALEN);
2571 memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
2572 memcpy(nullfunc->addr3, sdata->vif.addr, ETH_ALEN);
2573 nullfunc->seq_ctrl = 0;
2574
2575 info = IEEE80211_SKB_CB(skb);
2576
2577 info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
2578 IEEE80211_TX_INTFL_NL80211_FRAME_TX;
2579
2580 skb_set_queue_mapping(skb, IEEE80211_AC_VO);
2581 skb->priority = 7;
2582 if (qos)
2583 nullfunc->qos_ctrl = cpu_to_le16(7);
2584
2585 local_bh_disable();
2586 ieee80211_xmit(sdata, skb);
2587 local_bh_enable();
2588
2589 *cookie = (unsigned long) skb;
2590 return 0;
2591}
2592
Johannes Berge9998822011-11-09 10:30:21 +01002593static struct ieee80211_channel *
2594ieee80211_wiphy_get_channel(struct wiphy *wiphy)
2595{
2596 struct ieee80211_local *local = wiphy_priv(wiphy);
2597
2598 return local->oper_channel;
2599}
2600
Jiri Bencf0706e82007-05-05 11:45:53 -07002601struct cfg80211_ops mac80211_config_ops = {
2602 .add_virtual_intf = ieee80211_add_iface,
2603 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02002604 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01002605 .add_key = ieee80211_add_key,
2606 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01002607 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01002608 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02002609 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01002610 .add_beacon = ieee80211_add_beacon,
2611 .set_beacon = ieee80211_set_beacon,
2612 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01002613 .add_station = ieee80211_add_station,
2614 .del_station = ieee80211_del_station,
2615 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01002616 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002617 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02002618 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002619#ifdef CONFIG_MAC80211_MESH
2620 .add_mpath = ieee80211_add_mpath,
2621 .del_mpath = ieee80211_del_mpath,
2622 .change_mpath = ieee80211_change_mpath,
2623 .get_mpath = ieee80211_get_mpath,
2624 .dump_mpath = ieee80211_dump_mpath,
Javier Cardona24bdd9f2010-12-16 17:37:48 -08002625 .update_mesh_config = ieee80211_update_mesh_config,
2626 .get_mesh_config = ieee80211_get_mesh_config,
Johannes Berg29cbe682010-12-03 09:20:44 +01002627 .join_mesh = ieee80211_join_mesh,
2628 .leave_mesh = ieee80211_leave_mesh,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01002629#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03002630 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02002631 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02002632 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05002633 .suspend = ieee80211_suspend,
2634 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01002635 .scan = ieee80211_scan,
Luciano Coelho79f460c2011-05-11 17:09:36 +03002636 .sched_scan_start = ieee80211_sched_scan_start,
2637 .sched_scan_stop = ieee80211_sched_scan_stop,
Jouni Malinen636a5d32009-03-19 13:39:22 +02002638 .auth = ieee80211_auth,
2639 .assoc = ieee80211_assoc,
2640 .deauth = ieee80211_deauth,
2641 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02002642 .join_ibss = ieee80211_join_ibss,
2643 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02002644 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02002645 .set_tx_power = ieee80211_set_tx_power,
2646 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02002647 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02002648 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02002649 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Wey-Yi Guy71063f02011-05-20 09:05:54 -07002650 CFG80211_TESTMODE_DUMP(ieee80211_testmode_dump)
Johannes Bergbc92afd2009-07-01 21:26:57 +02002651 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02002652 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01002653 .remain_on_channel = ieee80211_remain_on_channel,
2654 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f782010-08-12 15:38:38 +02002655 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01002656 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02002657 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02002658 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09002659 .set_antenna = ieee80211_set_antenna,
2660 .get_antenna = ieee80211_get_antenna,
John W. Linville38c09152011-03-07 16:19:18 -05002661 .set_ringparam = ieee80211_set_ringparam,
2662 .get_ringparam = ieee80211_get_ringparam,
Johannes Bergc68f4b82011-07-05 16:35:41 +02002663 .set_rekey_data = ieee80211_set_rekey_data,
Arik Nemtsovdfe018b2011-09-28 14:12:52 +03002664 .tdls_oper = ieee80211_tdls_oper,
2665 .tdls_mgmt = ieee80211_tdls_mgmt,
Johannes Berg06500732011-11-04 11:18:16 +01002666 .probe_client = ieee80211_probe_client,
Johannes Berge9998822011-11-09 10:30:21 +01002667 .get_channel = ieee80211_wiphy_get_channel,
Jiri Bencf0706e82007-05-05 11:45:53 -07002668};