blob: d34c7c3dd762c2b485b424ba29d92601fba34801 [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>
Jiri Bencf0706e82007-05-05 11:45:53 -070015#include <net/cfg80211.h>
16#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020017#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040018#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040019#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010020#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010021
Johannes Bergf9e10ce2010-12-03 09:20:42 +010022static struct net_device *ieee80211_add_iface(struct wiphy *wiphy, char *name,
23 enum nl80211_iftype type,
24 u32 *flags,
25 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070026{
27 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010028 struct net_device *dev;
29 struct ieee80211_sub_if_data *sdata;
30 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070031
Johannes Berg05c914f2008-09-11 00:01:58 +020032 err = ieee80211_if_add(local, name, &dev, type, params);
Johannes Bergf9e10ce2010-12-03 09:20:42 +010033 if (err)
34 return ERR_PTR(err);
Michael Wu8cc9a732008-01-31 19:48:23 +010035
Johannes Bergf9e10ce2010-12-03 09:20:42 +010036 if (type == NL80211_IFTYPE_MONITOR && flags) {
37 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
38 sdata->u.mntr_flags = *flags;
39 }
40
41 return dev;
Jiri Bencf0706e82007-05-05 11:45:53 -070042}
43
Johannes Berg463d0182009-07-14 00:33:35 +020044static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
Jiri Bencf0706e82007-05-05 11:45:53 -070045{
Johannes Berg463d0182009-07-14 00:33:35 +020046 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
Jiri Bencf0706e82007-05-05 11:45:53 -070047
Johannes Berg75636522008-07-09 14:40:35 +020048 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070049}
50
Johannes Berge36d56b2009-06-09 21:04:43 +020051static int ieee80211_change_iface(struct wiphy *wiphy,
52 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010053 enum nl80211_iftype type, u32 *flags,
54 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020055{
Johannes Berg9607e6b2009-12-23 13:15:31 +010056 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020057 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020058
Johannes Berg05c914f2008-09-11 00:01:58 +020059 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020060 if (ret)
61 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020062
Johannes Berg902acc72008-02-23 15:17:19 +010063 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +020064 ieee80211_sdata_set_mesh_id(sdata,
65 params->mesh_id_len,
66 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010067
Johannes Berg9bc383d2009-11-19 11:55:19 +010068 if (type == NL80211_IFTYPE_AP_VLAN &&
69 params && params->use_4addr == 0)
70 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
71 else if (type == NL80211_IFTYPE_STATION &&
72 params && params->use_4addr >= 0)
73 sdata->u.mgd.use_4addr = params->use_4addr;
74
Christian Lamparter85416a42010-10-02 13:17:07 +020075 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags) {
76 struct ieee80211_local *local = sdata->local;
77
78 if (ieee80211_sdata_running(sdata)) {
79 /*
80 * Prohibit MONITOR_FLAG_COOK_FRAMES to be
81 * changed while the interface is up.
82 * Else we would need to add a lot of cruft
83 * to update everything:
84 * cooked_mntrs, monitor and all fif_* counters
85 * reconfigure hardware
86 */
87 if ((*flags & MONITOR_FLAG_COOK_FRAMES) !=
88 (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
89 return -EBUSY;
90
91 ieee80211_adjust_monitor_flags(sdata, -1);
92 sdata->u.mntr_flags = *flags;
93 ieee80211_adjust_monitor_flags(sdata, 1);
94
95 ieee80211_configure_filter(local);
96 } else {
97 /*
98 * Because the interface is down, ieee80211_do_stop
99 * and ieee80211_do_open take care of "everything"
100 * mentioned in the comment above.
101 */
102 sdata->u.mntr_flags = *flags;
103 }
104 }
Felix Fietkauf7917af2010-04-27 00:26:34 +0200105
Johannes Berg42613db2007-09-28 21:52:27 +0200106 return 0;
107}
108
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100109static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200110 u8 key_idx, bool pairwise, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100111 struct key_params *params)
112{
Johannes Berg26a58452010-08-27 12:35:55 +0200113 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100114 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100115 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200116 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100117
Johannes Berg26a58452010-08-27 12:35:55 +0200118 if (!ieee80211_sdata_running(sdata))
Johannes Bergad0e2b52010-06-01 10:19:19 +0200119 return -ENETDOWN;
120
Johannes Berg97359d12010-08-10 09:46:38 +0200121 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100122 switch (params->cipher) {
123 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100124 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +0200125 case WLAN_CIPHER_SUITE_WEP104:
126 if (IS_ERR(sdata->local->wep_tx_tfm))
127 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200128 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100129 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200130 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100131 }
132
Johannes Berg97359d12010-08-10 09:46:38 +0200133 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
134 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100135 if (IS_ERR(key))
136 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100137
Johannes Berge31b8212010-10-05 19:39:30 +0200138 if (pairwise)
139 key->conf.flags |= IEEE80211_KEY_FLAG_PAIRWISE;
140
Johannes Bergad0e2b52010-06-01 10:19:19 +0200141 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200142
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100143 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100144 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100145 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700146 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200147 err = -ENOENT;
148 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100149 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100150 }
151
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300152 err = ieee80211_key_link(key, sdata, sta);
153 if (err)
154 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100155
Johannes Berg3b967662008-04-08 17:56:52 +0200156 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200157 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200158
159 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100160}
161
162static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200163 u8 key_idx, bool pairwise, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100164{
165 struct ieee80211_sub_if_data *sdata;
166 struct sta_info *sta;
167 int ret;
168
169 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
170
Johannes Bergad0e2b52010-06-01 10:19:19 +0200171 mutex_lock(&sdata->local->sta_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 Berge31b8212010-10-05 19:39:30 +0200180 if (pairwise) {
181 if (sta->ptk) {
182 ieee80211_key_free(sdata->local, sta->ptk);
183 ret = 0;
184 }
185 } else {
186 if (sta->gtk[key_idx]) {
187 ieee80211_key_free(sdata->local,
188 sta->gtk[key_idx]);
189 ret = 0;
190 }
Johannes Berg3b967662008-04-08 17:56:52 +0200191 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100192
Johannes Berg3b967662008-04-08 17:56:52 +0200193 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100194 }
195
Johannes Berg3b967662008-04-08 17:56:52 +0200196 if (!sdata->keys[key_idx]) {
197 ret = -ENOENT;
198 goto out_unlock;
199 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100200
Jouni Malinen32162a42010-07-26 15:52:03 -0700201 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100202 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100203
Johannes Berg3b967662008-04-08 17:56:52 +0200204 ret = 0;
205 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200206 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200207
208 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100209}
210
Johannes Berg62da92f2007-12-19 02:03:31 +0100211static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berge31b8212010-10-05 19:39:30 +0200212 u8 key_idx, bool pairwise, const u8 *mac_addr,
213 void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100214 void (*callback)(void *cookie,
215 struct key_params *params))
216{
Johannes Berg14db74b2008-07-29 13:22:52 +0200217 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100218 struct sta_info *sta = NULL;
219 u8 seq[6] = {0};
220 struct key_params params;
Johannes Berge31b8212010-10-05 19:39:30 +0200221 struct ieee80211_key *key = NULL;
Johannes Berg62da92f2007-12-19 02:03:31 +0100222 u32 iv32;
223 u16 iv16;
224 int err = -ENOENT;
225
Johannes Berg14db74b2008-07-29 13:22:52 +0200226 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
227
Johannes Berg3b967662008-04-08 17:56:52 +0200228 rcu_read_lock();
229
Johannes Berg62da92f2007-12-19 02:03:31 +0100230 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100231 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100232 if (!sta)
233 goto out;
234
Johannes Berge31b8212010-10-05 19:39:30 +0200235 if (pairwise)
236 key = sta->ptk;
237 else if (key_idx < NUM_DEFAULT_KEYS)
238 key = sta->gtk[key_idx];
Johannes Berg62da92f2007-12-19 02:03:31 +0100239 } else
240 key = sdata->keys[key_idx];
241
242 if (!key)
243 goto out;
244
245 memset(&params, 0, sizeof(params));
246
Johannes Berg97359d12010-08-10 09:46:38 +0200247 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100248
Johannes Berg97359d12010-08-10 09:46:38 +0200249 switch (key->conf.cipher) {
250 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700251 iv32 = key->u.tkip.tx.iv32;
252 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100253
Johannes Berg24487982009-04-23 18:52:52 +0200254 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
255 drv_get_tkip_seq(sdata->local,
256 key->conf.hw_key_idx,
257 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100258
259 seq[0] = iv16 & 0xff;
260 seq[1] = (iv16 >> 8) & 0xff;
261 seq[2] = iv32 & 0xff;
262 seq[3] = (iv32 >> 8) & 0xff;
263 seq[4] = (iv32 >> 16) & 0xff;
264 seq[5] = (iv32 >> 24) & 0xff;
265 params.seq = seq;
266 params.seq_len = 6;
267 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200268 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg62da92f2007-12-19 02:03:31 +0100269 seq[0] = key->u.ccmp.tx_pn[5];
270 seq[1] = key->u.ccmp.tx_pn[4];
271 seq[2] = key->u.ccmp.tx_pn[3];
272 seq[3] = key->u.ccmp.tx_pn[2];
273 seq[4] = key->u.ccmp.tx_pn[1];
274 seq[5] = key->u.ccmp.tx_pn[0];
275 params.seq = seq;
276 params.seq_len = 6;
277 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200278 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200279 seq[0] = key->u.aes_cmac.tx_pn[5];
280 seq[1] = key->u.aes_cmac.tx_pn[4];
281 seq[2] = key->u.aes_cmac.tx_pn[3];
282 seq[3] = key->u.aes_cmac.tx_pn[2];
283 seq[4] = key->u.aes_cmac.tx_pn[1];
284 seq[5] = key->u.aes_cmac.tx_pn[0];
285 params.seq = seq;
286 params.seq_len = 6;
287 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100288 }
289
290 params.key = key->conf.key;
291 params.key_len = key->conf.keylen;
292
293 callback(cookie, &params);
294 err = 0;
295
296 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200297 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100298 return err;
299}
300
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100301static int ieee80211_config_default_key(struct wiphy *wiphy,
302 struct net_device *dev,
303 u8 key_idx)
304{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100306
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100307 ieee80211_set_default_key(sdata, key_idx);
308
309 return 0;
310}
311
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200312static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
313 struct net_device *dev,
314 u8 key_idx)
315{
Johannes Berg66c52422010-07-22 13:58:51 +0200316 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200317
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200318 ieee80211_set_default_mgmt_key(sdata, key_idx);
319
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200320 return 0;
321}
322
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100323static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
324{
Johannes Bergd0709a62008-02-25 16:27:46 +0100325 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100326
Johannes Bergf5ea9122009-08-07 16:17:38 +0200327 sinfo->generation = sdata->local->sta_generation;
328
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100329 sinfo->filled = STATION_INFO_INACTIVE_TIME |
330 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100331 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200332 STATION_INFO_RX_PACKETS |
333 STATION_INFO_TX_PACKETS |
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900334 STATION_INFO_TX_RETRIES |
335 STATION_INFO_TX_FAILED |
Ben Greear5a5c7312010-10-07 16:39:20 -0700336 STATION_INFO_TX_BITRATE |
337 STATION_INFO_RX_DROP_MISC;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100338
339 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
340 sinfo->rx_bytes = sta->rx_bytes;
341 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200342 sinfo->rx_packets = sta->rx_packets;
343 sinfo->tx_packets = sta->tx_packets;
Bruno Randolfb206b4e2010-10-06 18:34:12 +0900344 sinfo->tx_retries = sta->tx_retry_count;
345 sinfo->tx_failed = sta->tx_retry_failed;
Ben Greear5a5c7312010-10-07 16:39:20 -0700346 sinfo->rx_dropped_misc = sta->rx_dropped;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100347
John W. Linville19deffb2009-12-08 17:10:13 -0500348 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
349 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
John W. Linvilleccb14352010-11-24 16:18:36 -0500350 sinfo->filled |= STATION_INFO_SIGNAL;
Henning Rogge420e7fa2008-12-11 22:04:19 +0100351 sinfo->signal = (s8)sta->last_signal;
352 }
353
354 sinfo->txrate.flags = 0;
355 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
356 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
357 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
358 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
359 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
360 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
361
362 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
363 struct ieee80211_supported_band *sband;
364 sband = sta->local->hw.wiphy->bands[
365 sta->local->hw.conf.channel->band];
366 sinfo->txrate.legacy =
367 sband->bitrates[sta->last_tx_rate.idx].bitrate;
368 } else
369 sinfo->txrate.mcs = sta->last_tx_rate.idx;
370
Johannes Berg902acc72008-02-23 15:17:19 +0100371 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100372#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100373 sinfo->filled |= STATION_INFO_LLID |
374 STATION_INFO_PLID |
375 STATION_INFO_PLINK_STATE;
376
377 sinfo->llid = le16_to_cpu(sta->llid);
378 sinfo->plid = le16_to_cpu(sta->plid);
379 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100380#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100381 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100382}
383
384
385static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
386 int idx, u8 *mac, struct station_info *sinfo)
387{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100389 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100390 int ret = -ENOENT;
391
392 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100393
Johannes Berg3b53fde82009-11-16 12:00:37 +0100394 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100395 if (sta) {
396 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200397 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100398 sta_set_sinfo(sta, sinfo);
399 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100400
Johannes Bergd0709a62008-02-25 16:27:46 +0100401 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100402
Johannes Bergd0709a62008-02-25 16:27:46 +0100403 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100404}
405
Holger Schurig12897232010-04-19 10:23:57 +0200406static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
407 int idx, struct survey_info *survey)
408{
409 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
410
Holger Schurig12897232010-04-19 10:23:57 +0200411 return drv_get_survey(local, idx, survey);
412}
413
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100414static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100415 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100416{
Johannes Bergabe60632009-11-25 17:46:18 +0100417 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100418 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100419 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100420
Johannes Bergd0709a62008-02-25 16:27:46 +0100421 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100422
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100423 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100424 if (sta) {
425 ret = 0;
426 sta_set_sinfo(sta, sinfo);
427 }
428
429 rcu_read_unlock();
430
431 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100432}
433
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100434/*
435 * This handles both adding a beacon and setting new beacon info
436 */
437static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
438 struct beacon_parameters *params)
439{
440 struct beacon_data *new, *old;
441 int new_head_len, new_tail_len;
442 int size;
443 int err = -EINVAL;
444
445 old = sdata->u.ap.beacon;
446
447 /* head must not be zero-length */
448 if (params->head && !params->head_len)
449 return -EINVAL;
450
451 /*
452 * This is a kludge. beacon interval should really be part
453 * of the beacon information.
454 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200455 if (params->interval &&
456 (sdata->vif.bss_conf.beacon_int != params->interval)) {
457 sdata->vif.bss_conf.beacon_int = params->interval;
458 ieee80211_bss_info_change_notify(sdata,
459 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100460 }
461
462 /* Need to have a beacon head if we don't have one yet */
463 if (!params->head && !old)
464 return err;
465
466 /* sorry, no way to start beaconing without dtim period */
467 if (!params->dtim_period && !old)
468 return err;
469
470 /* new or old head? */
471 if (params->head)
472 new_head_len = params->head_len;
473 else
474 new_head_len = old->head_len;
475
476 /* new or old tail? */
477 if (params->tail || !old)
478 /* params->tail_len will be zero for !params->tail */
479 new_tail_len = params->tail_len;
480 else
481 new_tail_len = old->tail_len;
482
483 size = sizeof(*new) + new_head_len + new_tail_len;
484
485 new = kzalloc(size, GFP_KERNEL);
486 if (!new)
487 return -ENOMEM;
488
489 /* start filling the new info now */
490
491 /* new or old dtim period? */
492 if (params->dtim_period)
493 new->dtim_period = params->dtim_period;
494 else
495 new->dtim_period = old->dtim_period;
496
497 /*
498 * pointers go into the block we allocated,
499 * memory is | beacon_data | head | tail |
500 */
501 new->head = ((u8 *) new) + sizeof(*new);
502 new->tail = new->head + new_head_len;
503 new->head_len = new_head_len;
504 new->tail_len = new_tail_len;
505
506 /* copy in head */
507 if (params->head)
508 memcpy(new->head, params->head, new_head_len);
509 else
510 memcpy(new->head, old->head, new_head_len);
511
512 /* copy in optional tail */
513 if (params->tail)
514 memcpy(new->tail, params->tail, new_tail_len);
515 else
516 if (old)
517 memcpy(new->tail, old->tail, new_tail_len);
518
Johannes Berg19885c42010-02-05 11:45:06 +0100519 sdata->vif.bss_conf.dtim_period = new->dtim_period;
520
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100521 rcu_assign_pointer(sdata->u.ap.beacon, new);
522
523 synchronize_rcu();
524
525 kfree(old);
526
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200527 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
528 BSS_CHANGED_BEACON);
529 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100530}
531
532static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
533 struct beacon_parameters *params)
534{
Johannes Berg14db74b2008-07-29 13:22:52 +0200535 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100536 struct beacon_data *old;
537
Johannes Berg14db74b2008-07-29 13:22:52 +0200538 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
539
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100540 old = sdata->u.ap.beacon;
541
542 if (old)
543 return -EALREADY;
544
545 return ieee80211_config_beacon(sdata, params);
546}
547
548static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
549 struct beacon_parameters *params)
550{
Johannes Berg14db74b2008-07-29 13:22:52 +0200551 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100552 struct beacon_data *old;
553
Johannes Berg14db74b2008-07-29 13:22:52 +0200554 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
555
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100556 old = sdata->u.ap.beacon;
557
558 if (!old)
559 return -ENOENT;
560
561 return ieee80211_config_beacon(sdata, params);
562}
563
564static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
565{
Johannes Berg14db74b2008-07-29 13:22:52 +0200566 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100567 struct beacon_data *old;
568
Johannes Berg14db74b2008-07-29 13:22:52 +0200569 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
570
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100571 old = sdata->u.ap.beacon;
572
573 if (!old)
574 return -ENOENT;
575
576 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
577 synchronize_rcu();
578 kfree(old);
579
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200580 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
581 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100582}
583
Johannes Berg4fd69312007-12-19 02:03:35 +0100584/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
585struct iapp_layer2_update {
586 u8 da[ETH_ALEN]; /* broadcast */
587 u8 sa[ETH_ALEN]; /* STA addr */
588 __be16 len; /* 6 */
589 u8 dsap; /* 0 */
590 u8 ssap; /* 0 */
591 u8 control;
592 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700593} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100594
595static void ieee80211_send_layer2_update(struct sta_info *sta)
596{
597 struct iapp_layer2_update *msg;
598 struct sk_buff *skb;
599
600 /* Send Level 2 Update Frame to update forwarding tables in layer 2
601 * bridge devices */
602
603 skb = dev_alloc_skb(sizeof(*msg));
604 if (!skb)
605 return;
606 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
607
608 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
609 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
610
611 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200612 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100613 msg->len = htons(6);
614 msg->dsap = 0;
615 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
616 msg->control = 0xaf; /* XID response lsb.1111F101.
617 * F=0 (no poll command; unsolicited frame) */
618 msg->xid_info[0] = 0x81; /* XID format identifier */
619 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
620 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
621
Johannes Bergd0709a62008-02-25 16:27:46 +0100622 skb->dev = sta->sdata->dev;
623 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100624 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400625 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100626}
627
628static void sta_apply_parameters(struct ieee80211_local *local,
629 struct sta_info *sta,
630 struct station_parameters *params)
631{
Johannes Bergf5521b12010-09-14 22:06:53 +0200632 unsigned long flags;
Johannes Berg4fd69312007-12-19 02:03:35 +0100633 u32 rates;
634 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100635 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100636 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300637 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100638
Johannes Bergae5eb022008-10-14 16:58:37 +0200639 sband = local->hw.wiphy->bands[local->oper_channel->band];
640
Johannes Bergf5521b12010-09-14 22:06:53 +0200641 spin_lock_irqsave(&sta->flaglock, flags);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300642 mask = params->sta_flags_mask;
643 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100644
Johannes Bergeccb8e82009-05-11 21:57:56 +0300645 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100646 sta->flags &= ~WLAN_STA_AUTHORIZED;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300647 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg4fd69312007-12-19 02:03:35 +0100648 sta->flags |= WLAN_STA_AUTHORIZED;
Johannes Berg4fd69312007-12-19 02:03:35 +0100649 }
650
Johannes Bergeccb8e82009-05-11 21:57:56 +0300651 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
652 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
653 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
654 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
655 }
656
657 if (mask & BIT(NL80211_STA_FLAG_WME)) {
658 sta->flags &= ~WLAN_STA_WME;
659 if (set & BIT(NL80211_STA_FLAG_WME))
660 sta->flags |= WLAN_STA_WME;
661 }
662
663 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
664 sta->flags &= ~WLAN_STA_MFP;
665 if (set & BIT(NL80211_STA_FLAG_MFP))
666 sta->flags |= WLAN_STA_MFP;
667 }
Johannes Bergf5521b12010-09-14 22:06:53 +0200668 spin_unlock_irqrestore(&sta->flaglock, flags);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300669
Johannes Berg73651ee2008-02-25 16:27:47 +0100670 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200671 * cfg80211 validates this (1-2007) and allows setting the AID
672 * only when creating a new station entry
673 */
674 if (params->aid)
675 sta->sta.aid = params->aid;
676
677 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100678 * FIXME: updating the following information is racy when this
679 * function is called from ieee80211_change_station().
680 * However, all this information should be static so
681 * maybe we should just reject attemps to change it.
682 */
683
Johannes Berg4fd69312007-12-19 02:03:35 +0100684 if (params->listen_interval >= 0)
685 sta->listen_interval = params->listen_interval;
686
687 if (params->supported_rates) {
688 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100689
Johannes Berg4fd69312007-12-19 02:03:35 +0100690 for (i = 0; i < params->supported_rates_len; i++) {
691 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100692 for (j = 0; j < sband->n_bitrates; j++) {
693 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100694 rates |= BIT(j);
695 }
696 }
Johannes Berg323ce792008-09-11 02:45:11 +0200697 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100698 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100699
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200700 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200701 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
702 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200703 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +0300704
Johannes Berg902acc72008-02-23 15:17:19 +0100705 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100706 switch (params->plink_action) {
707 case PLINK_ACTION_OPEN:
708 mesh_plink_open(sta);
709 break;
710 case PLINK_ACTION_BLOCK:
711 mesh_plink_block(sta);
712 break;
713 }
Johannes Berg902acc72008-02-23 15:17:19 +0100714 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100715}
716
717static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
718 u8 *mac, struct station_parameters *params)
719{
Johannes Berg14db74b2008-07-29 13:22:52 +0200720 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100721 struct sta_info *sta;
722 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100723 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200724 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100725
Johannes Berg4fd69312007-12-19 02:03:35 +0100726 if (params->vlan) {
727 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
728
Johannes Berg05c914f2008-09-11 00:01:58 +0200729 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
730 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100731 return -EINVAL;
732 } else
733 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
734
Johannes Berg47846c92009-11-25 17:46:19 +0100735 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100736 return -EINVAL;
737
738 if (is_multicast_ether_addr(mac))
739 return -EINVAL;
740
741 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100742 if (!sta)
743 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100744
745 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
746
747 sta_apply_parameters(local, sta, params);
748
Johannes Berg4b7679a2008-09-18 18:14:18 +0200749 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100750
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200751 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
752 sdata->vif.type == NL80211_IFTYPE_AP;
753
Johannes Berg34e89502010-02-03 13:59:58 +0100754 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100755 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100756 rcu_read_unlock();
757 return err;
758 }
759
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200760 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100761 ieee80211_send_layer2_update(sta);
762
763 rcu_read_unlock();
764
Johannes Berg4fd69312007-12-19 02:03:35 +0100765 return 0;
766}
767
768static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
769 u8 *mac)
770{
Johannes Berg14db74b2008-07-29 13:22:52 +0200771 struct ieee80211_local *local = wiphy_priv(wiphy);
772 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100773
Johannes Berg14db74b2008-07-29 13:22:52 +0200774 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
775
Johannes Berg34e89502010-02-03 13:59:58 +0100776 if (mac)
777 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200778
Johannes Berg34e89502010-02-03 13:59:58 +0100779 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100780 return 0;
781}
782
783static int ieee80211_change_station(struct wiphy *wiphy,
784 struct net_device *dev,
785 u8 *mac,
786 struct station_parameters *params)
787{
Johannes Bergabe60632009-11-25 17:46:18 +0100788 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200789 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100790 struct sta_info *sta;
791 struct ieee80211_sub_if_data *vlansdata;
792
Johannes Berg98dd6a52008-04-10 15:36:09 +0200793 rcu_read_lock();
794
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100795 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200796 if (!sta) {
797 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100798 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200799 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100800
Johannes Bergd0709a62008-02-25 16:27:46 +0100801 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100802 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
803
Johannes Berg05c914f2008-09-11 00:01:58 +0200804 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
805 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200806 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100807 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200808 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100809
Johannes Berg9bc383d2009-11-19 11:55:19 +0100810 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100811 if (vlansdata->u.vlan.sta) {
812 rcu_read_unlock();
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100813 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100814 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100815
816 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
817 }
818
Johannes Berg14db74b2008-07-29 13:22:52 +0200819 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100820 ieee80211_send_layer2_update(sta);
821 }
822
823 sta_apply_parameters(local, sta, params);
824
Johannes Berg98dd6a52008-04-10 15:36:09 +0200825 rcu_read_unlock();
826
Johannes Berg4fd69312007-12-19 02:03:35 +0100827 return 0;
828}
829
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100830#ifdef CONFIG_MAC80211_MESH
831static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
832 u8 *dst, u8 *next_hop)
833{
Johannes Berg14db74b2008-07-29 13:22:52 +0200834 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100835 struct mesh_path *mpath;
836 struct sta_info *sta;
837 int err;
838
Johannes Berg14db74b2008-07-29 13:22:52 +0200839 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
840
Johannes Bergd0709a62008-02-25 16:27:46 +0100841 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100842 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100843 if (!sta) {
844 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100845 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100846 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100847
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200848 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100849 if (err) {
850 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100851 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100852 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100853
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200854 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100855 if (!mpath) {
856 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100857 return -ENXIO;
858 }
859 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100860
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100861 rcu_read_unlock();
862 return 0;
863}
864
865static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
866 u8 *dst)
867{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200868 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100869
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200870 if (dst)
871 return mesh_path_del(dst, sdata);
872
873 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100874 return 0;
875}
876
877static int ieee80211_change_mpath(struct wiphy *wiphy,
878 struct net_device *dev,
879 u8 *dst, u8 *next_hop)
880{
Johannes Berg14db74b2008-07-29 13:22:52 +0200881 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100882 struct mesh_path *mpath;
883 struct sta_info *sta;
884
Johannes Berg14db74b2008-07-29 13:22:52 +0200885 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
886
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100887 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100888
Johannes Bergabe60632009-11-25 17:46:18 +0100889 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100890 if (!sta) {
891 rcu_read_unlock();
892 return -ENOENT;
893 }
894
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200895 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100896 if (!mpath) {
897 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100898 return -ENOENT;
899 }
900
901 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100902
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100903 rcu_read_unlock();
904 return 0;
905}
906
907static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
908 struct mpath_info *pinfo)
909{
910 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200911 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100912 else
913 memset(next_hop, 0, ETH_ALEN);
914
Johannes Bergf5ea9122009-08-07 16:17:38 +0200915 pinfo->generation = mesh_paths_generation;
916
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100917 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +0000918 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100919 MPATH_INFO_METRIC |
920 MPATH_INFO_EXPTIME |
921 MPATH_INFO_DISCOVERY_TIMEOUT |
922 MPATH_INFO_DISCOVERY_RETRIES |
923 MPATH_INFO_FLAGS;
924
925 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000926 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100927 pinfo->metric = mpath->metric;
928 if (time_before(jiffies, mpath->exp_time))
929 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
930 pinfo->discovery_timeout =
931 jiffies_to_msecs(mpath->discovery_timeout);
932 pinfo->discovery_retries = mpath->discovery_retries;
933 pinfo->flags = 0;
934 if (mpath->flags & MESH_PATH_ACTIVE)
935 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
936 if (mpath->flags & MESH_PATH_RESOLVING)
937 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000938 if (mpath->flags & MESH_PATH_SN_VALID)
939 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100940 if (mpath->flags & MESH_PATH_FIXED)
941 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
942 if (mpath->flags & MESH_PATH_RESOLVING)
943 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
944
945 pinfo->flags = mpath->flags;
946}
947
948static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
949 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
950
951{
Johannes Berg14db74b2008-07-29 13:22:52 +0200952 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100953 struct mesh_path *mpath;
954
Johannes Berg14db74b2008-07-29 13:22:52 +0200955 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
956
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100957 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200958 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100959 if (!mpath) {
960 rcu_read_unlock();
961 return -ENOENT;
962 }
963 memcpy(dst, mpath->dst, ETH_ALEN);
964 mpath_set_pinfo(mpath, next_hop, pinfo);
965 rcu_read_unlock();
966 return 0;
967}
968
969static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
970 int idx, u8 *dst, u8 *next_hop,
971 struct mpath_info *pinfo)
972{
Johannes Berg14db74b2008-07-29 13:22:52 +0200973 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100974 struct mesh_path *mpath;
975
Johannes Berg14db74b2008-07-29 13:22:52 +0200976 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
977
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100978 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200979 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100980 if (!mpath) {
981 rcu_read_unlock();
982 return -ENOENT;
983 }
984 memcpy(dst, mpath->dst, ETH_ALEN);
985 mpath_set_pinfo(mpath, next_hop, pinfo);
986 rcu_read_unlock();
987 return 0;
988}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700989
990static int ieee80211_get_mesh_params(struct wiphy *wiphy,
991 struct net_device *dev,
992 struct mesh_config *conf)
993{
994 struct ieee80211_sub_if_data *sdata;
995 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
996
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700997 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
998 return 0;
999}
1000
1001static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
1002{
1003 return (mask >> (parm-1)) & 0x1;
1004}
1005
1006static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1007 struct net_device *dev,
1008 const struct mesh_config *nconf, u32 mask)
1009{
1010 struct mesh_config *conf;
1011 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +00001012 struct ieee80211_if_mesh *ifmsh;
1013
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001014 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +00001015 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001016
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001017 /* Set the config options which we are interested in setting */
1018 conf = &(sdata->u.mesh.mshcfg);
1019 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1020 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1021 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1022 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1023 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1024 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1025 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1026 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1027 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1028 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1029 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1030 conf->dot11MeshTTL = nconf->dot11MeshTTL;
Javier Cardona45904f22010-12-03 09:20:40 +01001031 if (_chg_mesh_attr(NL80211_MESHCONF_ELEMENT_TTL, mask))
1032 conf->dot11MeshTTL = nconf->element_ttl;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001033 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1034 conf->auto_open_plinks = nconf->auto_open_plinks;
1035 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1036 conf->dot11MeshHWMPmaxPREQretries =
1037 nconf->dot11MeshHWMPmaxPREQretries;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1039 conf->path_refresh_time = nconf->path_refresh_time;
1040 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1041 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1042 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1043 conf->dot11MeshHWMPactivePathTimeout =
1044 nconf->dot11MeshHWMPactivePathTimeout;
1045 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1046 conf->dot11MeshHWMPpreqMinInterval =
1047 nconf->dot11MeshHWMPpreqMinInterval;
1048 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1049 mask))
1050 conf->dot11MeshHWMPnetDiameterTraversalTime =
1051 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001052 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1053 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1054 ieee80211_mesh_root_setup(ifmsh);
1055 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001056 return 0;
1057}
1058
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001059#endif
1060
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001061static int ieee80211_change_bss(struct wiphy *wiphy,
1062 struct net_device *dev,
1063 struct bss_parameters *params)
1064{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001065 struct ieee80211_sub_if_data *sdata;
1066 u32 changed = 0;
1067
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001068 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1069
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001070 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001071 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001072 changed |= BSS_CHANGED_ERP_CTS_PROT;
1073 }
1074 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001075 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001076 params->use_short_preamble;
1077 changed |= BSS_CHANGED_ERP_PREAMBLE;
1078 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001079
1080 if (!sdata->vif.bss_conf.use_short_slot &&
1081 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1082 sdata->vif.bss_conf.use_short_slot = true;
1083 changed |= BSS_CHANGED_ERP_SLOT;
1084 }
1085
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001086 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001087 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001088 params->use_short_slot_time;
1089 changed |= BSS_CHANGED_ERP_SLOT;
1090 }
1091
Jouni Malinen90c97a02008-10-30 16:59:22 +02001092 if (params->basic_rates) {
1093 int i, j;
1094 u32 rates = 0;
1095 struct ieee80211_local *local = wiphy_priv(wiphy);
1096 struct ieee80211_supported_band *sband =
1097 wiphy->bands[local->oper_channel->band];
1098
1099 for (i = 0; i < params->basic_rates_len; i++) {
1100 int rate = (params->basic_rates[i] & 0x7f) * 5;
1101 for (j = 0; j < sband->n_bitrates; j++) {
1102 if (sband->bitrates[j].bitrate == rate)
1103 rates |= BIT(j);
1104 }
1105 }
1106 sdata->vif.bss_conf.basic_rates = rates;
1107 changed |= BSS_CHANGED_BASIC_RATES;
1108 }
1109
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001110 if (params->ap_isolate >= 0) {
1111 if (params->ap_isolate)
1112 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1113 else
1114 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1115 }
1116
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001117 ieee80211_bss_info_change_notify(sdata, changed);
1118
1119 return 0;
1120}
1121
Jouni Malinen31888482008-10-30 16:59:24 +02001122static int ieee80211_set_txq_params(struct wiphy *wiphy,
1123 struct ieee80211_txq_params *params)
1124{
1125 struct ieee80211_local *local = wiphy_priv(wiphy);
1126 struct ieee80211_tx_queue_params p;
1127
1128 if (!local->ops->conf_tx)
1129 return -EOPNOTSUPP;
1130
1131 memset(&p, 0, sizeof(p));
1132 p.aifs = params->aifs;
1133 p.cw_max = params->cwmax;
1134 p.cw_min = params->cwmin;
1135 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001136
1137 /*
1138 * Setting tx queue params disables u-apsd because it's only
1139 * called in master mode.
1140 */
1141 p.uapsd = false;
1142
Johannes Berg24487982009-04-23 18:52:52 +02001143 if (drv_conf_tx(local, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001144 wiphy_debug(local->hw.wiphy,
1145 "failed to set TX queue parameters for queue %d\n",
1146 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001147 return -EINVAL;
1148 }
1149
1150 return 0;
1151}
1152
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001153static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001154 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001155 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301156 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001157{
1158 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001159 struct ieee80211_sub_if_data *sdata = NULL;
1160
1161 if (netdev)
1162 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001163
Johannes Bergf444de02010-05-05 15:25:02 +02001164 switch (ieee80211_get_channel_mode(local, NULL)) {
1165 case CHAN_MODE_HOPPING:
1166 return -EBUSY;
1167 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001168 if (local->oper_channel != chan)
1169 return -EBUSY;
1170 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001171 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001172 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001173 case CHAN_MODE_UNDEFINED:
1174 break;
1175 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001176
1177 local->oper_channel = chan;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001178
Johannes Berg0aaffa92010-05-05 15:28:27 +02001179 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1180 return -EBUSY;
1181
1182 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1183 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1184 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1185
1186 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001187}
1188
Bob Copeland665af4f2009-01-19 11:20:53 -05001189#ifdef CONFIG_PM
1190static int ieee80211_suspend(struct wiphy *wiphy)
1191{
1192 return __ieee80211_suspend(wiphy_priv(wiphy));
1193}
1194
1195static int ieee80211_resume(struct wiphy *wiphy)
1196{
1197 return __ieee80211_resume(wiphy_priv(wiphy));
1198}
1199#else
1200#define ieee80211_suspend NULL
1201#define ieee80211_resume NULL
1202#endif
1203
Johannes Berg2a519312009-02-10 21:25:55 +01001204static int ieee80211_scan(struct wiphy *wiphy,
1205 struct net_device *dev,
1206 struct cfg80211_scan_request *req)
1207{
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001208 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg2a519312009-02-10 21:25:55 +01001209
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001210 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1211 case NL80211_IFTYPE_STATION:
1212 case NL80211_IFTYPE_ADHOC:
1213 case NL80211_IFTYPE_MESH_POINT:
1214 case NL80211_IFTYPE_P2P_CLIENT:
1215 break;
1216 case NL80211_IFTYPE_P2P_GO:
1217 if (sdata->local->ops->hw_scan)
1218 break;
1219 /* FIXME: implement NoA while scanning in software */
Johannes Berg2a519312009-02-10 21:25:55 +01001220 return -EOPNOTSUPP;
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001221 case NL80211_IFTYPE_AP:
1222 if (sdata->u.ap.beacon)
1223 return -EOPNOTSUPP;
1224 break;
1225 default:
1226 return -EOPNOTSUPP;
1227 }
Johannes Berg2a519312009-02-10 21:25:55 +01001228
1229 return ieee80211_request_scan(sdata, req);
1230}
1231
Jouni Malinen636a5d32009-03-19 13:39:22 +02001232static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1233 struct cfg80211_auth_request *req)
1234{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001235 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001236}
1237
1238static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1239 struct cfg80211_assoc_request *req)
1240{
Johannes Bergf444de02010-05-05 15:25:02 +02001241 struct ieee80211_local *local = wiphy_priv(wiphy);
1242 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1243
1244 switch (ieee80211_get_channel_mode(local, sdata)) {
1245 case CHAN_MODE_HOPPING:
1246 return -EBUSY;
1247 case CHAN_MODE_FIXED:
1248 if (local->oper_channel == req->bss->channel)
1249 break;
1250 return -EBUSY;
1251 case CHAN_MODE_UNDEFINED:
1252 break;
1253 }
1254
Johannes Berg77fdaa12009-07-07 03:45:17 +02001255 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001256}
1257
1258static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001259 struct cfg80211_deauth_request *req,
1260 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001261{
Johannes Berg667503dd2009-07-07 03:56:11 +02001262 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1263 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001264}
1265
1266static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001267 struct cfg80211_disassoc_request *req,
1268 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001269{
Johannes Berg667503dd2009-07-07 03:56:11 +02001270 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1271 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001272}
1273
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001274static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1275 struct cfg80211_ibss_params *params)
1276{
Johannes Bergf444de02010-05-05 15:25:02 +02001277 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001278 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1279
Johannes Bergf444de02010-05-05 15:25:02 +02001280 switch (ieee80211_get_channel_mode(local, sdata)) {
1281 case CHAN_MODE_HOPPING:
1282 return -EBUSY;
1283 case CHAN_MODE_FIXED:
1284 if (!params->channel_fixed)
1285 return -EBUSY;
1286 if (local->oper_channel == params->channel)
1287 break;
1288 return -EBUSY;
1289 case CHAN_MODE_UNDEFINED:
1290 break;
1291 }
1292
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001293 return ieee80211_ibss_join(sdata, params);
1294}
1295
1296static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1297{
1298 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1299
1300 return ieee80211_ibss_leave(sdata);
1301}
1302
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001303static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1304{
1305 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001306 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001307
Arik Nemtsovf23a4782010-11-08 11:51:06 +02001308 if (changed & WIPHY_PARAM_FRAG_THRESHOLD) {
1309 err = drv_set_frag_threshold(local, wiphy->frag_threshold);
1310
1311 if (err)
1312 return err;
1313 }
1314
Lukáš Turek310bc672009-12-21 22:50:48 +01001315 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1316 err = drv_set_coverage_class(local, wiphy->coverage_class);
1317
1318 if (err)
1319 return err;
1320 }
1321
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001322 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001323 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001324
Johannes Berg24487982009-04-23 18:52:52 +02001325 if (err)
1326 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001327 }
1328
1329 if (changed & WIPHY_PARAM_RETRY_SHORT)
1330 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1331 if (changed & WIPHY_PARAM_RETRY_LONG)
1332 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1333 if (changed &
1334 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1335 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1336
1337 return 0;
1338}
1339
Johannes Berg7643a2c2009-06-02 13:01:39 +02001340static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001341 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001342{
1343 struct ieee80211_local *local = wiphy_priv(wiphy);
1344 struct ieee80211_channel *chan = local->hw.conf.channel;
1345 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001346
1347 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001348 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001349 local->user_power_level = -1;
1350 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001351 case NL80211_TX_POWER_LIMITED:
1352 if (mbm < 0 || (mbm % 100))
1353 return -EOPNOTSUPP;
1354 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001355 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001356 case NL80211_TX_POWER_FIXED:
1357 if (mbm < 0 || (mbm % 100))
1358 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001359 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001360 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001361 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001362 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001363 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001364 }
1365
1366 ieee80211_hw_config(local, changes);
1367
1368 return 0;
1369}
1370
1371static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1372{
1373 struct ieee80211_local *local = wiphy_priv(wiphy);
1374
1375 *dbm = local->hw.conf.power_level;
1376
Johannes Berg7643a2c2009-06-02 13:01:39 +02001377 return 0;
1378}
1379
Johannes Bergab737a42009-07-01 21:26:58 +02001380static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg388ac772010-10-07 13:11:09 +02001381 const u8 *addr)
Johannes Bergab737a42009-07-01 21:26:58 +02001382{
1383 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1384
1385 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1386
1387 return 0;
1388}
1389
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001390static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1391{
1392 struct ieee80211_local *local = wiphy_priv(wiphy);
1393
1394 drv_rfkill_poll(local);
1395}
1396
Johannes Bergaff89a92009-07-01 21:26:51 +02001397#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001398static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001399{
1400 struct ieee80211_local *local = wiphy_priv(wiphy);
1401
1402 if (!local->ops->testmode_cmd)
1403 return -EOPNOTSUPP;
1404
1405 return local->ops->testmode_cmd(&local->hw, data, len);
1406}
1407#endif
1408
Johannes Berg0f782312009-12-01 13:37:02 +01001409int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1410 enum ieee80211_smps_mode smps_mode)
1411{
1412 const u8 *ap;
1413 enum ieee80211_smps_mode old_req;
1414 int err;
1415
1416 old_req = sdata->u.mgd.req_smps;
1417 sdata->u.mgd.req_smps = smps_mode;
1418
1419 if (old_req == smps_mode &&
1420 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1421 return 0;
1422
1423 /*
1424 * If not associated, or current association is not an HT
1425 * association, there's no need to send an action frame.
1426 */
1427 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001428 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001429 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02001430 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01001431 mutex_unlock(&sdata->local->iflist_mtx);
1432 return 0;
1433 }
1434
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001435 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001436
1437 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1438 if (sdata->u.mgd.powersave)
1439 smps_mode = IEEE80211_SMPS_DYNAMIC;
1440 else
1441 smps_mode = IEEE80211_SMPS_OFF;
1442 }
1443
1444 /* send SM PS frame to AP */
1445 err = ieee80211_send_smps_action(sdata, smps_mode,
1446 ap, ap);
1447 if (err)
1448 sdata->u.mgd.req_smps = old_req;
1449
1450 return err;
1451}
1452
Johannes Bergbc92afd2009-07-01 21:26:57 +02001453static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1454 bool enabled, int timeout)
1455{
1456 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1457 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001458
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001459 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1460 return -EOPNOTSUPP;
1461
Johannes Bergbc92afd2009-07-01 21:26:57 +02001462 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1463 return -EOPNOTSUPP;
1464
1465 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001466 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001467 return 0;
1468
1469 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001470 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001471
Johannes Berg0f782312009-12-01 13:37:02 +01001472 /* no change, but if automatic follow powersave */
1473 mutex_lock(&sdata->u.mgd.mtx);
1474 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1475 mutex_unlock(&sdata->u.mgd.mtx);
1476
Johannes Bergbc92afd2009-07-01 21:26:57 +02001477 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1478 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1479
1480 ieee80211_recalc_ps(local, -1);
1481
1482 return 0;
1483}
1484
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001485static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1486 struct net_device *dev,
1487 s32 rssi_thold, u32 rssi_hyst)
1488{
1489 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1490 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1491 struct ieee80211_vif *vif = &sdata->vif;
1492 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1493
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001494 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1495 rssi_hyst == bss_conf->cqm_rssi_hyst)
1496 return 0;
1497
1498 bss_conf->cqm_rssi_thold = rssi_thold;
1499 bss_conf->cqm_rssi_hyst = rssi_hyst;
1500
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001501 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1502 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1503 return -EOPNOTSUPP;
1504 return 0;
1505 }
1506
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001507 /* tell the driver upon association, unless already associated */
1508 if (sdata->u.mgd.associated)
1509 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1510
1511 return 0;
1512}
1513
Johannes Berg99303802009-07-01 21:26:59 +02001514static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1515 struct net_device *dev,
1516 const u8 *addr,
1517 const struct cfg80211_bitrate_mask *mask)
1518{
1519 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1520 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001521 int i;
Johannes Berg99303802009-07-01 21:26:59 +02001522
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001523 /*
1524 * This _could_ be supported by providing a hook for
1525 * drivers for this function, but at this point it
1526 * doesn't seem worth bothering.
1527 */
1528 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1529 return -EOPNOTSUPP;
1530
Johannes Berg99303802009-07-01 21:26:59 +02001531
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001532 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1533 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001534
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001535 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001536}
1537
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001538static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1539 struct net_device *dev,
1540 struct ieee80211_channel *chan,
1541 enum nl80211_channel_type channel_type,
1542 unsigned int duration,
1543 u64 *cookie)
1544{
1545 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1546
1547 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1548 duration, cookie);
1549}
1550
1551static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1552 struct net_device *dev,
1553 u64 cookie)
1554{
1555 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1556
1557 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1558}
1559
Johannes Bergf30221e2010-11-25 10:02:30 +01001560static enum work_done_result
1561ieee80211_offchan_tx_done(struct ieee80211_work *wk, struct sk_buff *skb)
1562{
1563 /*
1564 * Use the data embedded in the work struct for reporting
1565 * here so if the driver mangled the SKB before dropping
1566 * it (which is the only way we really should get here)
1567 * then we don't report mangled data.
1568 *
1569 * If there was no wait time, then by the time we get here
1570 * the driver will likely not have reported the status yet,
1571 * so in that case userspace will have to deal with it.
1572 */
1573
1574 if (wk->offchan_tx.wait && wk->offchan_tx.frame)
1575 cfg80211_mgmt_tx_status(wk->sdata->dev,
1576 (unsigned long) wk->offchan_tx.frame,
1577 wk->ie, wk->ie_len, false, GFP_KERNEL);
1578
1579 return WORK_DONE_DESTROY;
1580}
1581
Johannes Berg2e161f72010-08-12 15:38:38 +02001582static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001583 struct ieee80211_channel *chan, bool offchan,
Johannes Berg2e161f72010-08-12 15:38:38 +02001584 enum nl80211_channel_type channel_type,
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001585 bool channel_type_valid, unsigned int wait,
Johannes Berg2e161f72010-08-12 15:38:38 +02001586 const u8 *buf, size_t len, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001587{
Johannes Berg9d38d852010-06-09 17:20:33 +02001588 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1589 struct ieee80211_local *local = sdata->local;
1590 struct sk_buff *skb;
1591 struct sta_info *sta;
Johannes Bergf30221e2010-11-25 10:02:30 +01001592 struct ieee80211_work *wk;
Johannes Berg9d38d852010-06-09 17:20:33 +02001593 const struct ieee80211_mgmt *mgmt = (void *)buf;
1594 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1595 IEEE80211_TX_CTL_REQ_TX_STATUS;
Johannes Bergf30221e2010-11-25 10:02:30 +01001596 bool is_offchan = false;
Johannes Bergf7ca38d2010-11-25 10:02:29 +01001597
Johannes Berg9d38d852010-06-09 17:20:33 +02001598 /* Check that we are on the requested channel for transmission */
1599 if (chan != local->tmp_channel &&
1600 chan != local->oper_channel)
Johannes Bergf30221e2010-11-25 10:02:30 +01001601 is_offchan = true;
Johannes Berg9d38d852010-06-09 17:20:33 +02001602 if (channel_type_valid &&
1603 (channel_type != local->tmp_channel_type &&
1604 channel_type != local->_oper_channel_type))
Johannes Bergf30221e2010-11-25 10:02:30 +01001605 is_offchan = true;
1606
1607 if (is_offchan && !offchan)
Johannes Berg9d38d852010-06-09 17:20:33 +02001608 return -EBUSY;
1609
1610 switch (sdata->vif.type) {
1611 case NL80211_IFTYPE_ADHOC:
Johannes Berg663fcaf2010-09-30 21:06:09 +02001612 case NL80211_IFTYPE_AP:
1613 case NL80211_IFTYPE_AP_VLAN:
1614 case NL80211_IFTYPE_P2P_GO:
1615 if (!ieee80211_is_action(mgmt->frame_control) ||
1616 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02001617 break;
1618 rcu_read_lock();
1619 sta = sta_info_get(sdata, mgmt->da);
1620 rcu_read_unlock();
1621 if (!sta)
1622 return -ENOLINK;
1623 break;
1624 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02001625 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg9d38d852010-06-09 17:20:33 +02001626 break;
1627 default:
1628 return -EOPNOTSUPP;
1629 }
1630
1631 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1632 if (!skb)
1633 return -ENOMEM;
1634 skb_reserve(skb, local->hw.extra_tx_headroom);
1635
1636 memcpy(skb_put(skb, len), buf, len);
1637
1638 IEEE80211_SKB_CB(skb)->flags = flags;
1639
1640 skb->dev = sdata->dev;
Johannes Berg9d38d852010-06-09 17:20:33 +02001641
1642 *cookie = (unsigned long) skb;
Johannes Bergf30221e2010-11-25 10:02:30 +01001643
1644 /*
1645 * Can transmit right away if the channel was the
1646 * right one and there's no wait involved... If a
1647 * wait is involved, we might otherwise not be on
1648 * the right channel for long enough!
1649 */
1650 if (!is_offchan && !wait && !sdata->vif.bss_conf.idle) {
1651 ieee80211_tx_skb(sdata, skb);
1652 return 0;
1653 }
1654
1655 wk = kzalloc(sizeof(*wk) + len, GFP_KERNEL);
1656 if (!wk) {
1657 kfree_skb(skb);
1658 return -ENOMEM;
1659 }
1660
1661 wk->type = IEEE80211_WORK_OFFCHANNEL_TX;
1662 wk->chan = chan;
1663 wk->sdata = sdata;
1664 wk->done = ieee80211_offchan_tx_done;
1665 wk->offchan_tx.frame = skb;
1666 wk->offchan_tx.wait = wait;
1667 wk->ie_len = len;
1668 memcpy(wk->ie, buf, len);
1669
1670 ieee80211_add_work(wk);
Johannes Berg9d38d852010-06-09 17:20:33 +02001671 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02001672}
1673
Johannes Bergf30221e2010-11-25 10:02:30 +01001674static int ieee80211_mgmt_tx_cancel_wait(struct wiphy *wiphy,
1675 struct net_device *dev,
1676 u64 cookie)
1677{
1678 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1679 struct ieee80211_local *local = sdata->local;
1680 struct ieee80211_work *wk;
1681 int ret = -ENOENT;
1682
1683 mutex_lock(&local->mtx);
1684 list_for_each_entry(wk, &local->work_list, list) {
1685 if (wk->sdata != sdata)
1686 continue;
1687
1688 if (wk->type != IEEE80211_WORK_OFFCHANNEL_TX)
1689 continue;
1690
1691 if (cookie != (unsigned long) wk->offchan_tx.frame)
1692 continue;
1693
1694 wk->timeout = jiffies;
1695
1696 ieee80211_queue_work(&local->hw, &local->work_work);
1697 ret = 0;
1698 break;
1699 }
1700 mutex_unlock(&local->mtx);
1701
1702 return ret;
1703}
1704
Johannes Berg7be50862010-10-13 12:06:24 +02001705static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
1706 struct net_device *dev,
1707 u16 frame_type, bool reg)
1708{
1709 struct ieee80211_local *local = wiphy_priv(wiphy);
1710
1711 if (frame_type != (IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_REQ))
1712 return;
1713
1714 if (reg)
1715 local->probe_req_reg++;
1716 else
1717 local->probe_req_reg--;
1718
1719 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
1720}
1721
Bruno Randolf15d96752010-11-10 12:50:56 +09001722static int ieee80211_set_antenna(struct wiphy *wiphy, u32 tx_ant, u32 rx_ant)
1723{
1724 struct ieee80211_local *local = wiphy_priv(wiphy);
1725
1726 if (local->started)
1727 return -EOPNOTSUPP;
1728
1729 return drv_set_antenna(local, tx_ant, rx_ant);
1730}
1731
1732static int ieee80211_get_antenna(struct wiphy *wiphy, u32 *tx_ant, u32 *rx_ant)
1733{
1734 struct ieee80211_local *local = wiphy_priv(wiphy);
1735
1736 return drv_get_antenna(local, tx_ant, rx_ant);
1737}
1738
Jiri Bencf0706e82007-05-05 11:45:53 -07001739struct cfg80211_ops mac80211_config_ops = {
1740 .add_virtual_intf = ieee80211_add_iface,
1741 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001742 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001743 .add_key = ieee80211_add_key,
1744 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001745 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001746 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001747 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001748 .add_beacon = ieee80211_add_beacon,
1749 .set_beacon = ieee80211_set_beacon,
1750 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001751 .add_station = ieee80211_add_station,
1752 .del_station = ieee80211_del_station,
1753 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001754 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001755 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02001756 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001757#ifdef CONFIG_MAC80211_MESH
1758 .add_mpath = ieee80211_add_mpath,
1759 .del_mpath = ieee80211_del_mpath,
1760 .change_mpath = ieee80211_change_mpath,
1761 .get_mpath = ieee80211_get_mpath,
1762 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001763 .set_mesh_params = ieee80211_set_mesh_params,
1764 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001765#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001766 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001767 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001768 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001769 .suspend = ieee80211_suspend,
1770 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001771 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001772 .auth = ieee80211_auth,
1773 .assoc = ieee80211_assoc,
1774 .deauth = ieee80211_deauth,
1775 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001776 .join_ibss = ieee80211_join_ibss,
1777 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001778 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02001779 .set_tx_power = ieee80211_set_tx_power,
1780 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02001781 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001782 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02001783 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001784 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02001785 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001786 .remain_on_channel = ieee80211_remain_on_channel,
1787 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02001788 .mgmt_tx = ieee80211_mgmt_tx,
Johannes Bergf30221e2010-11-25 10:02:30 +01001789 .mgmt_tx_cancel_wait = ieee80211_mgmt_tx_cancel_wait,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001790 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Johannes Berg7be50862010-10-13 12:06:24 +02001791 .mgmt_frame_register = ieee80211_mgmt_frame_register,
Bruno Randolf15d96752010-11-10 12:50:56 +09001792 .set_antenna = ieee80211_set_antenna,
1793 .get_antenna = ieee80211_get_antenna,
Jiri Bencf0706e82007-05-05 11:45:53 -07001794};