blob: 94bf550bd4c9ebec756bff41e42c926792e73af5 [file] [log] [blame]
Jiri Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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 Bencf0706e822007-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
Jiri Bencf0706e822007-05-05 11:45:53 -070022static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010023 enum nl80211_iftype type, u32 *flags,
24 struct vif_params *params)
Jiri Bencf0706e822007-05-05 11:45:53 -070025{
26 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010027 struct net_device *dev;
28 struct ieee80211_sub_if_data *sdata;
29 int err;
Jiri Bencf0706e822007-05-05 11:45:53 -070030
Johannes Berg05c914f2008-09-11 00:01:58 +020031 err = ieee80211_if_add(local, name, &dev, type, params);
32 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010033 return err;
34
35 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
36 sdata->u.mntr_flags = *flags;
37 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -070038}
39
Johannes Berg463d0182009-07-14 00:33:35 +020040static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
Jiri Bencf0706e822007-05-05 11:45:53 -070041{
Johannes Berg463d0182009-07-14 00:33:35 +020042 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
Jiri Bencf0706e822007-05-05 11:45:53 -070043
Johannes Berg75636522008-07-09 14:40:35 +020044 return 0;
Jiri Bencf0706e822007-05-05 11:45:53 -070045}
46
Johannes Berge36d56b2009-06-09 21:04:43 +020047static int ieee80211_change_iface(struct wiphy *wiphy,
48 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010049 enum nl80211_iftype type, u32 *flags,
50 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020051{
Johannes Berg9607e6b2009-12-23 13:15:31 +010052 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergf3947e22008-07-09 14:40:36 +020053 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020054
Johannes Berg05c914f2008-09-11 00:01:58 +020055 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020056 if (ret)
57 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020058
Johannes Berg902acc72008-02-23 15:17:19 +010059 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +020060 ieee80211_sdata_set_mesh_id(sdata,
61 params->mesh_id_len,
62 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010063
Johannes Berg9bc383d2009-11-19 11:55:19 +010064 if (type == NL80211_IFTYPE_AP_VLAN &&
65 params && params->use_4addr == 0)
66 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
67 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 Berg4e943902009-05-09 20:06:47 +0200106 u8 key_idx, 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 Malinen3cfcf6a2009-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 Bergad0e2b52010-06-01 10:19:19 +0200134 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200135
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100136 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100137 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100138 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700139 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200140 err = -ENOENT;
141 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100142 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100143 }
144
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300145 err = ieee80211_key_link(key, sdata, sta);
146 if (err)
147 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100148
Johannes Berg3b967662008-04-08 17:56:52 +0200149 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200150 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200151
152 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100153}
154
155static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200156 u8 key_idx, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100157{
158 struct ieee80211_sub_if_data *sdata;
159 struct sta_info *sta;
160 int ret;
161
162 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
163
Johannes Bergad0e2b52010-06-01 10:19:19 +0200164 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200165
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100166 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200167 ret = -ENOENT;
168
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100169 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100170 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200171 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100172
Johannes Bergdb4d1162008-02-25 16:27:45 +0100173 if (sta->key) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700174 ieee80211_key_free(sdata->local, sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100175 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200176 ret = 0;
177 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100178
Johannes Berg3b967662008-04-08 17:56:52 +0200179 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100180 }
181
Johannes Berg3b967662008-04-08 17:56:52 +0200182 if (!sdata->keys[key_idx]) {
183 ret = -ENOENT;
184 goto out_unlock;
185 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100186
Jouni Malinen32162a42010-07-26 15:52:03 -0700187 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100188 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100189
Johannes Berg3b967662008-04-08 17:56:52 +0200190 ret = 0;
191 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200192 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200193
194 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100195}
196
Johannes Berg62da92f2007-12-19 02:03:31 +0100197static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200198 u8 key_idx, const u8 *mac_addr, void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100199 void (*callback)(void *cookie,
200 struct key_params *params))
201{
Johannes Berg14db74b2008-07-29 13:22:52 +0200202 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100203 struct sta_info *sta = NULL;
204 u8 seq[6] = {0};
205 struct key_params params;
206 struct ieee80211_key *key;
207 u32 iv32;
208 u16 iv16;
209 int err = -ENOENT;
210
Johannes Berg14db74b2008-07-29 13:22:52 +0200211 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
212
Johannes Berg3b967662008-04-08 17:56:52 +0200213 rcu_read_lock();
214
Johannes Berg62da92f2007-12-19 02:03:31 +0100215 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100216 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100217 if (!sta)
218 goto out;
219
220 key = sta->key;
221 } else
222 key = sdata->keys[key_idx];
223
224 if (!key)
225 goto out;
226
227 memset(&params, 0, sizeof(params));
228
Johannes Berg97359d12010-08-10 09:46:38 +0200229 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100230
Johannes Berg97359d12010-08-10 09:46:38 +0200231 switch (key->conf.cipher) {
232 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700233 iv32 = key->u.tkip.tx.iv32;
234 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100235
Johannes Berg24487982009-04-23 18:52:52 +0200236 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
237 drv_get_tkip_seq(sdata->local,
238 key->conf.hw_key_idx,
239 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100240
241 seq[0] = iv16 & 0xff;
242 seq[1] = (iv16 >> 8) & 0xff;
243 seq[2] = iv32 & 0xff;
244 seq[3] = (iv32 >> 8) & 0xff;
245 seq[4] = (iv32 >> 16) & 0xff;
246 seq[5] = (iv32 >> 24) & 0xff;
247 params.seq = seq;
248 params.seq_len = 6;
249 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200250 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg62da92f2007-12-19 02:03:31 +0100251 seq[0] = key->u.ccmp.tx_pn[5];
252 seq[1] = key->u.ccmp.tx_pn[4];
253 seq[2] = key->u.ccmp.tx_pn[3];
254 seq[3] = key->u.ccmp.tx_pn[2];
255 seq[4] = key->u.ccmp.tx_pn[1];
256 seq[5] = key->u.ccmp.tx_pn[0];
257 params.seq = seq;
258 params.seq_len = 6;
259 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200260 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200261 seq[0] = key->u.aes_cmac.tx_pn[5];
262 seq[1] = key->u.aes_cmac.tx_pn[4];
263 seq[2] = key->u.aes_cmac.tx_pn[3];
264 seq[3] = key->u.aes_cmac.tx_pn[2];
265 seq[4] = key->u.aes_cmac.tx_pn[1];
266 seq[5] = key->u.aes_cmac.tx_pn[0];
267 params.seq = seq;
268 params.seq_len = 6;
269 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100270 }
271
272 params.key = key->conf.key;
273 params.key_len = key->conf.keylen;
274
275 callback(cookie, &params);
276 err = 0;
277
278 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200279 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100280 return err;
281}
282
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100283static int ieee80211_config_default_key(struct wiphy *wiphy,
284 struct net_device *dev,
285 u8 key_idx)
286{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200287 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100288
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100289 ieee80211_set_default_key(sdata, key_idx);
290
291 return 0;
292}
293
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200294static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
295 struct net_device *dev,
296 u8 key_idx)
297{
Johannes Berg66c52422010-07-22 13:58:51 +0200298 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200299
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200300 ieee80211_set_default_mgmt_key(sdata, key_idx);
301
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +0200302 return 0;
303}
304
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100305static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
306{
Johannes Bergd0709a62008-02-25 16:27:46 +0100307 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100308
Johannes Bergf5ea9122009-08-07 16:17:38 +0200309 sinfo->generation = sdata->local->sta_generation;
310
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100311 sinfo->filled = STATION_INFO_INACTIVE_TIME |
312 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100313 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200314 STATION_INFO_RX_PACKETS |
315 STATION_INFO_TX_PACKETS |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100316 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100317
318 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
319 sinfo->rx_bytes = sta->rx_bytes;
320 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200321 sinfo->rx_packets = sta->rx_packets;
322 sinfo->tx_packets = sta->tx_packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100323
John W. Linville19deffb2009-12-08 17:10:13 -0500324 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
325 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Henning Rogge420e7fa2008-12-11 22:04:19 +0100326 sinfo->filled |= STATION_INFO_SIGNAL;
327 sinfo->signal = (s8)sta->last_signal;
328 }
329
330 sinfo->txrate.flags = 0;
331 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
332 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
333 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
334 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
335 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
336 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
337
338 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
339 struct ieee80211_supported_band *sband;
340 sband = sta->local->hw.wiphy->bands[
341 sta->local->hw.conf.channel->band];
342 sinfo->txrate.legacy =
343 sband->bitrates[sta->last_tx_rate.idx].bitrate;
344 } else
345 sinfo->txrate.mcs = sta->last_tx_rate.idx;
346
Johannes Berg902acc72008-02-23 15:17:19 +0100347 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100348#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100349 sinfo->filled |= STATION_INFO_LLID |
350 STATION_INFO_PLID |
351 STATION_INFO_PLINK_STATE;
352
353 sinfo->llid = le16_to_cpu(sta->llid);
354 sinfo->plid = le16_to_cpu(sta->plid);
355 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100356#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100357 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100358}
359
360
361static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
362 int idx, u8 *mac, struct station_info *sinfo)
363{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100364 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100365 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100366 int ret = -ENOENT;
367
368 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100369
Johannes Berg3b53fde82009-11-16 12:00:37 +0100370 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100371 if (sta) {
372 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200373 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100374 sta_set_sinfo(sta, sinfo);
375 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100376
Johannes Bergd0709a62008-02-25 16:27:46 +0100377 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100378
Johannes Bergd0709a62008-02-25 16:27:46 +0100379 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100380}
381
Holger Schurig12897232010-04-19 10:23:57 +0200382static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
383 int idx, struct survey_info *survey)
384{
385 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
386
Holger Schurig12897232010-04-19 10:23:57 +0200387 return drv_get_survey(local, idx, survey);
388}
389
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100390static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100391 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100392{
Johannes Bergabe60632009-11-25 17:46:18 +0100393 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100394 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100395 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100396
Johannes Bergd0709a62008-02-25 16:27:46 +0100397 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100398
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100399 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100400 if (sta) {
401 ret = 0;
402 sta_set_sinfo(sta, sinfo);
403 }
404
405 rcu_read_unlock();
406
407 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100408}
409
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100410/*
411 * This handles both adding a beacon and setting new beacon info
412 */
413static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
414 struct beacon_parameters *params)
415{
416 struct beacon_data *new, *old;
417 int new_head_len, new_tail_len;
418 int size;
419 int err = -EINVAL;
420
421 old = sdata->u.ap.beacon;
422
423 /* head must not be zero-length */
424 if (params->head && !params->head_len)
425 return -EINVAL;
426
427 /*
428 * This is a kludge. beacon interval should really be part
429 * of the beacon information.
430 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200431 if (params->interval &&
432 (sdata->vif.bss_conf.beacon_int != params->interval)) {
433 sdata->vif.bss_conf.beacon_int = params->interval;
434 ieee80211_bss_info_change_notify(sdata,
435 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100436 }
437
438 /* Need to have a beacon head if we don't have one yet */
439 if (!params->head && !old)
440 return err;
441
442 /* sorry, no way to start beaconing without dtim period */
443 if (!params->dtim_period && !old)
444 return err;
445
446 /* new or old head? */
447 if (params->head)
448 new_head_len = params->head_len;
449 else
450 new_head_len = old->head_len;
451
452 /* new or old tail? */
453 if (params->tail || !old)
454 /* params->tail_len will be zero for !params->tail */
455 new_tail_len = params->tail_len;
456 else
457 new_tail_len = old->tail_len;
458
459 size = sizeof(*new) + new_head_len + new_tail_len;
460
461 new = kzalloc(size, GFP_KERNEL);
462 if (!new)
463 return -ENOMEM;
464
465 /* start filling the new info now */
466
467 /* new or old dtim period? */
468 if (params->dtim_period)
469 new->dtim_period = params->dtim_period;
470 else
471 new->dtim_period = old->dtim_period;
472
473 /*
474 * pointers go into the block we allocated,
475 * memory is | beacon_data | head | tail |
476 */
477 new->head = ((u8 *) new) + sizeof(*new);
478 new->tail = new->head + new_head_len;
479 new->head_len = new_head_len;
480 new->tail_len = new_tail_len;
481
482 /* copy in head */
483 if (params->head)
484 memcpy(new->head, params->head, new_head_len);
485 else
486 memcpy(new->head, old->head, new_head_len);
487
488 /* copy in optional tail */
489 if (params->tail)
490 memcpy(new->tail, params->tail, new_tail_len);
491 else
492 if (old)
493 memcpy(new->tail, old->tail, new_tail_len);
494
Johannes Berg19885c42010-02-05 11:45:06 +0100495 sdata->vif.bss_conf.dtim_period = new->dtim_period;
496
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100497 rcu_assign_pointer(sdata->u.ap.beacon, new);
498
499 synchronize_rcu();
500
501 kfree(old);
502
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200503 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
504 BSS_CHANGED_BEACON);
505 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100506}
507
508static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
509 struct beacon_parameters *params)
510{
Johannes Berg14db74b2008-07-29 13:22:52 +0200511 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100512 struct beacon_data *old;
513
Johannes Berg14db74b2008-07-29 13:22:52 +0200514 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
515
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100516 old = sdata->u.ap.beacon;
517
518 if (old)
519 return -EALREADY;
520
521 return ieee80211_config_beacon(sdata, params);
522}
523
524static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
525 struct beacon_parameters *params)
526{
Johannes Berg14db74b2008-07-29 13:22:52 +0200527 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100528 struct beacon_data *old;
529
Johannes Berg14db74b2008-07-29 13:22:52 +0200530 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
531
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100532 old = sdata->u.ap.beacon;
533
534 if (!old)
535 return -ENOENT;
536
537 return ieee80211_config_beacon(sdata, params);
538}
539
540static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
541{
Johannes Berg14db74b2008-07-29 13:22:52 +0200542 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100543 struct beacon_data *old;
544
Johannes Berg14db74b2008-07-29 13:22:52 +0200545 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
546
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100547 old = sdata->u.ap.beacon;
548
549 if (!old)
550 return -ENOENT;
551
552 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
553 synchronize_rcu();
554 kfree(old);
555
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200556 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
557 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100558}
559
Johannes Berg4fd69312007-12-19 02:03:35 +0100560/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
561struct iapp_layer2_update {
562 u8 da[ETH_ALEN]; /* broadcast */
563 u8 sa[ETH_ALEN]; /* STA addr */
564 __be16 len; /* 6 */
565 u8 dsap; /* 0 */
566 u8 ssap; /* 0 */
567 u8 control;
568 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700569} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100570
571static void ieee80211_send_layer2_update(struct sta_info *sta)
572{
573 struct iapp_layer2_update *msg;
574 struct sk_buff *skb;
575
576 /* Send Level 2 Update Frame to update forwarding tables in layer 2
577 * bridge devices */
578
579 skb = dev_alloc_skb(sizeof(*msg));
580 if (!skb)
581 return;
582 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
583
584 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
585 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
586
587 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200588 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100589 msg->len = htons(6);
590 msg->dsap = 0;
591 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
592 msg->control = 0xaf; /* XID response lsb.1111F101.
593 * F=0 (no poll command; unsolicited frame) */
594 msg->xid_info[0] = 0x81; /* XID format identifier */
595 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
596 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
597
Johannes Bergd0709a62008-02-25 16:27:46 +0100598 skb->dev = sta->sdata->dev;
599 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100600 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400601 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100602}
603
604static void sta_apply_parameters(struct ieee80211_local *local,
605 struct sta_info *sta,
606 struct station_parameters *params)
607{
Johannes Bergf5521b12010-09-14 22:06:53 +0200608 unsigned long flags;
Johannes Berg4fd69312007-12-19 02:03:35 +0100609 u32 rates;
610 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100611 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100612 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300613 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100614
Johannes Bergae5eb022008-10-14 16:58:37 +0200615 sband = local->hw.wiphy->bands[local->oper_channel->band];
616
Johannes Bergf5521b12010-09-14 22:06:53 +0200617 spin_lock_irqsave(&sta->flaglock, flags);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300618 mask = params->sta_flags_mask;
619 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100620
Johannes Bergeccb8e82009-05-11 21:57:56 +0300621 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100622 sta->flags &= ~WLAN_STA_AUTHORIZED;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300623 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg4fd69312007-12-19 02:03:35 +0100624 sta->flags |= WLAN_STA_AUTHORIZED;
Johannes Berg4fd69312007-12-19 02:03:35 +0100625 }
626
Johannes Bergeccb8e82009-05-11 21:57:56 +0300627 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
628 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
629 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
630 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
631 }
632
633 if (mask & BIT(NL80211_STA_FLAG_WME)) {
634 sta->flags &= ~WLAN_STA_WME;
635 if (set & BIT(NL80211_STA_FLAG_WME))
636 sta->flags |= WLAN_STA_WME;
637 }
638
639 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
640 sta->flags &= ~WLAN_STA_MFP;
641 if (set & BIT(NL80211_STA_FLAG_MFP))
642 sta->flags |= WLAN_STA_MFP;
643 }
Johannes Bergf5521b12010-09-14 22:06:53 +0200644 spin_unlock_irqrestore(&sta->flaglock, flags);
Johannes Bergeccb8e82009-05-11 21:57:56 +0300645
Johannes Berg73651ee2008-02-25 16:27:47 +0100646 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200647 * cfg80211 validates this (1-2007) and allows setting the AID
648 * only when creating a new station entry
649 */
650 if (params->aid)
651 sta->sta.aid = params->aid;
652
653 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100654 * FIXME: updating the following information is racy when this
655 * function is called from ieee80211_change_station().
656 * However, all this information should be static so
657 * maybe we should just reject attemps to change it.
658 */
659
Johannes Berg4fd69312007-12-19 02:03:35 +0100660 if (params->listen_interval >= 0)
661 sta->listen_interval = params->listen_interval;
662
663 if (params->supported_rates) {
664 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100665
Johannes Berg4fd69312007-12-19 02:03:35 +0100666 for (i = 0; i < params->supported_rates_len; i++) {
667 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100668 for (j = 0; j < sband->n_bitrates; j++) {
669 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100670 rates |= BIT(j);
671 }
672 }
Johannes Berg323ce792008-09-11 02:45:11 +0200673 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100674 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100675
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200676 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200677 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
678 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200679 &sta->sta.ht_cap);
Jouni Malinen36aedc92008-08-25 11:58:58 +0300680
Johannes Berg902acc72008-02-23 15:17:19 +0100681 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100682 switch (params->plink_action) {
683 case PLINK_ACTION_OPEN:
684 mesh_plink_open(sta);
685 break;
686 case PLINK_ACTION_BLOCK:
687 mesh_plink_block(sta);
688 break;
689 }
Johannes Berg902acc72008-02-23 15:17:19 +0100690 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100691}
692
693static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
694 u8 *mac, struct station_parameters *params)
695{
Johannes Berg14db74b2008-07-29 13:22:52 +0200696 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100697 struct sta_info *sta;
698 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100699 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200700 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100701
Johannes Berg4fd69312007-12-19 02:03:35 +0100702 if (params->vlan) {
703 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
704
Johannes Berg05c914f2008-09-11 00:01:58 +0200705 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
706 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100707 return -EINVAL;
708 } else
709 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
710
Johannes Berg47846c92009-11-25 17:46:19 +0100711 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100712 return -EINVAL;
713
714 if (is_multicast_ether_addr(mac))
715 return -EINVAL;
716
717 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100718 if (!sta)
719 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100720
721 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
722
723 sta_apply_parameters(local, sta, params);
724
Johannes Berg4b7679a2008-09-18 18:14:18 +0200725 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100726
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200727 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
728 sdata->vif.type == NL80211_IFTYPE_AP;
729
Johannes Berg34e89502010-02-03 13:59:58 +0100730 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100731 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100732 rcu_read_unlock();
733 return err;
734 }
735
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200736 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100737 ieee80211_send_layer2_update(sta);
738
739 rcu_read_unlock();
740
Johannes Berg4fd69312007-12-19 02:03:35 +0100741 return 0;
742}
743
744static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
745 u8 *mac)
746{
Johannes Berg14db74b2008-07-29 13:22:52 +0200747 struct ieee80211_local *local = wiphy_priv(wiphy);
748 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100749
Johannes Berg14db74b2008-07-29 13:22:52 +0200750 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
751
Johannes Berg34e89502010-02-03 13:59:58 +0100752 if (mac)
753 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200754
Johannes Berg34e89502010-02-03 13:59:58 +0100755 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100756 return 0;
757}
758
759static int ieee80211_change_station(struct wiphy *wiphy,
760 struct net_device *dev,
761 u8 *mac,
762 struct station_parameters *params)
763{
Johannes Bergabe60632009-11-25 17:46:18 +0100764 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200765 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100766 struct sta_info *sta;
767 struct ieee80211_sub_if_data *vlansdata;
768
Johannes Berg98dd6a52008-04-10 15:36:09 +0200769 rcu_read_lock();
770
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100771 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200772 if (!sta) {
773 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100774 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200775 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100776
Johannes Bergd0709a62008-02-25 16:27:46 +0100777 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100778 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
779
Johannes Berg05c914f2008-09-11 00:01:58 +0200780 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
781 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200782 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100783 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200784 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100785
Johannes Berg9bc383d2009-11-19 11:55:19 +0100786 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100787 if (vlansdata->u.vlan.sta) {
788 rcu_read_unlock();
Felix Fietkauf14543e2009-11-10 20:10:05 +0100789 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100790 }
Felix Fietkauf14543e2009-11-10 20:10:05 +0100791
792 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
793 }
794
Johannes Berg14db74b2008-07-29 13:22:52 +0200795 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100796 ieee80211_send_layer2_update(sta);
797 }
798
799 sta_apply_parameters(local, sta, params);
800
Johannes Berg98dd6a52008-04-10 15:36:09 +0200801 rcu_read_unlock();
802
Johannes Berg4fd69312007-12-19 02:03:35 +0100803 return 0;
804}
805
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100806#ifdef CONFIG_MAC80211_MESH
807static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
808 u8 *dst, u8 *next_hop)
809{
Johannes Berg14db74b2008-07-29 13:22:52 +0200810 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100811 struct mesh_path *mpath;
812 struct sta_info *sta;
813 int err;
814
Johannes Berg14db74b2008-07-29 13:22:52 +0200815 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
816
Johannes Bergd0709a62008-02-25 16:27:46 +0100817 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100818 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100819 if (!sta) {
820 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100821 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100822 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100823
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200824 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100825 if (err) {
826 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100827 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100828 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100829
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200830 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100831 if (!mpath) {
832 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100833 return -ENXIO;
834 }
835 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100836
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100837 rcu_read_unlock();
838 return 0;
839}
840
841static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
842 u8 *dst)
843{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200844 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100845
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200846 if (dst)
847 return mesh_path_del(dst, sdata);
848
849 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100850 return 0;
851}
852
853static int ieee80211_change_mpath(struct wiphy *wiphy,
854 struct net_device *dev,
855 u8 *dst, u8 *next_hop)
856{
Johannes Berg14db74b2008-07-29 13:22:52 +0200857 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100858 struct mesh_path *mpath;
859 struct sta_info *sta;
860
Johannes Berg14db74b2008-07-29 13:22:52 +0200861 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
862
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100863 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100864
Johannes Bergabe60632009-11-25 17:46:18 +0100865 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100866 if (!sta) {
867 rcu_read_unlock();
868 return -ENOENT;
869 }
870
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200871 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100872 if (!mpath) {
873 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100874 return -ENOENT;
875 }
876
877 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100878
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100879 rcu_read_unlock();
880 return 0;
881}
882
883static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
884 struct mpath_info *pinfo)
885{
886 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200887 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100888 else
889 memset(next_hop, 0, ETH_ALEN);
890
Johannes Bergf5ea9122009-08-07 16:17:38 +0200891 pinfo->generation = mesh_paths_generation;
892
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100893 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +0000894 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100895 MPATH_INFO_METRIC |
896 MPATH_INFO_EXPTIME |
897 MPATH_INFO_DISCOVERY_TIMEOUT |
898 MPATH_INFO_DISCOVERY_RETRIES |
899 MPATH_INFO_FLAGS;
900
901 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000902 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100903 pinfo->metric = mpath->metric;
904 if (time_before(jiffies, mpath->exp_time))
905 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
906 pinfo->discovery_timeout =
907 jiffies_to_msecs(mpath->discovery_timeout);
908 pinfo->discovery_retries = mpath->discovery_retries;
909 pinfo->flags = 0;
910 if (mpath->flags & MESH_PATH_ACTIVE)
911 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
912 if (mpath->flags & MESH_PATH_RESOLVING)
913 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000914 if (mpath->flags & MESH_PATH_SN_VALID)
915 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100916 if (mpath->flags & MESH_PATH_FIXED)
917 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
918 if (mpath->flags & MESH_PATH_RESOLVING)
919 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
920
921 pinfo->flags = mpath->flags;
922}
923
924static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
925 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
926
927{
Johannes Berg14db74b2008-07-29 13:22:52 +0200928 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100929 struct mesh_path *mpath;
930
Johannes Berg14db74b2008-07-29 13:22:52 +0200931 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
932
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100933 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200934 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100935 if (!mpath) {
936 rcu_read_unlock();
937 return -ENOENT;
938 }
939 memcpy(dst, mpath->dst, ETH_ALEN);
940 mpath_set_pinfo(mpath, next_hop, pinfo);
941 rcu_read_unlock();
942 return 0;
943}
944
945static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
946 int idx, u8 *dst, u8 *next_hop,
947 struct mpath_info *pinfo)
948{
Johannes Berg14db74b2008-07-29 13:22:52 +0200949 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100950 struct mesh_path *mpath;
951
Johannes Berg14db74b2008-07-29 13:22:52 +0200952 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
953
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100954 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200955 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100956 if (!mpath) {
957 rcu_read_unlock();
958 return -ENOENT;
959 }
960 memcpy(dst, mpath->dst, ETH_ALEN);
961 mpath_set_pinfo(mpath, next_hop, pinfo);
962 rcu_read_unlock();
963 return 0;
964}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700965
966static int ieee80211_get_mesh_params(struct wiphy *wiphy,
967 struct net_device *dev,
968 struct mesh_config *conf)
969{
970 struct ieee80211_sub_if_data *sdata;
971 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
972
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700973 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
974 return 0;
975}
976
977static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
978{
979 return (mask >> (parm-1)) & 0x1;
980}
981
982static int ieee80211_set_mesh_params(struct wiphy *wiphy,
983 struct net_device *dev,
984 const struct mesh_config *nconf, u32 mask)
985{
986 struct mesh_config *conf;
987 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +0000988 struct ieee80211_if_mesh *ifmsh;
989
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700990 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +0000991 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700992
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700993 /* Set the config options which we are interested in setting */
994 conf = &(sdata->u.mesh.mshcfg);
995 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
996 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
997 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
998 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
999 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1000 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1001 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1002 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1003 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1004 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1005 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1006 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1007 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1008 conf->auto_open_plinks = nconf->auto_open_plinks;
1009 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1010 conf->dot11MeshHWMPmaxPREQretries =
1011 nconf->dot11MeshHWMPmaxPREQretries;
1012 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1013 conf->path_refresh_time = nconf->path_refresh_time;
1014 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1015 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1016 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1017 conf->dot11MeshHWMPactivePathTimeout =
1018 nconf->dot11MeshHWMPactivePathTimeout;
1019 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1020 conf->dot11MeshHWMPpreqMinInterval =
1021 nconf->dot11MeshHWMPpreqMinInterval;
1022 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1023 mask))
1024 conf->dot11MeshHWMPnetDiameterTraversalTime =
1025 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001026 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1027 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1028 ieee80211_mesh_root_setup(ifmsh);
1029 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001030 return 0;
1031}
1032
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001033#endif
1034
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001035static int ieee80211_change_bss(struct wiphy *wiphy,
1036 struct net_device *dev,
1037 struct bss_parameters *params)
1038{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001039 struct ieee80211_sub_if_data *sdata;
1040 u32 changed = 0;
1041
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001042 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1043
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001044 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001045 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001046 changed |= BSS_CHANGED_ERP_CTS_PROT;
1047 }
1048 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001049 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001050 params->use_short_preamble;
1051 changed |= BSS_CHANGED_ERP_PREAMBLE;
1052 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001053
1054 if (!sdata->vif.bss_conf.use_short_slot &&
1055 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1056 sdata->vif.bss_conf.use_short_slot = true;
1057 changed |= BSS_CHANGED_ERP_SLOT;
1058 }
1059
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001060 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001061 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001062 params->use_short_slot_time;
1063 changed |= BSS_CHANGED_ERP_SLOT;
1064 }
1065
Jouni Malinen90c97a02008-10-30 16:59:22 +02001066 if (params->basic_rates) {
1067 int i, j;
1068 u32 rates = 0;
1069 struct ieee80211_local *local = wiphy_priv(wiphy);
1070 struct ieee80211_supported_band *sband =
1071 wiphy->bands[local->oper_channel->band];
1072
1073 for (i = 0; i < params->basic_rates_len; i++) {
1074 int rate = (params->basic_rates[i] & 0x7f) * 5;
1075 for (j = 0; j < sband->n_bitrates; j++) {
1076 if (sband->bitrates[j].bitrate == rate)
1077 rates |= BIT(j);
1078 }
1079 }
1080 sdata->vif.bss_conf.basic_rates = rates;
1081 changed |= BSS_CHANGED_BASIC_RATES;
1082 }
1083
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001084 if (params->ap_isolate >= 0) {
1085 if (params->ap_isolate)
1086 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1087 else
1088 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1089 }
1090
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001091 ieee80211_bss_info_change_notify(sdata, changed);
1092
1093 return 0;
1094}
1095
Jouni Malinen31888482008-10-30 16:59:24 +02001096static int ieee80211_set_txq_params(struct wiphy *wiphy,
1097 struct ieee80211_txq_params *params)
1098{
1099 struct ieee80211_local *local = wiphy_priv(wiphy);
1100 struct ieee80211_tx_queue_params p;
1101
1102 if (!local->ops->conf_tx)
1103 return -EOPNOTSUPP;
1104
1105 memset(&p, 0, sizeof(p));
1106 p.aifs = params->aifs;
1107 p.cw_max = params->cwmax;
1108 p.cw_min = params->cwmin;
1109 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001110
1111 /*
1112 * Setting tx queue params disables u-apsd because it's only
1113 * called in master mode.
1114 */
1115 p.uapsd = false;
1116
Johannes Berg24487982009-04-23 18:52:52 +02001117 if (drv_conf_tx(local, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001118 wiphy_debug(local->hw.wiphy,
1119 "failed to set TX queue parameters for queue %d\n",
1120 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001121 return -EINVAL;
1122 }
1123
1124 return 0;
1125}
1126
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001127static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001128 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001129 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301130 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001131{
1132 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001133 struct ieee80211_sub_if_data *sdata = NULL;
1134
1135 if (netdev)
1136 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001137
Johannes Bergf444de02010-05-05 15:25:02 +02001138 switch (ieee80211_get_channel_mode(local, NULL)) {
1139 case CHAN_MODE_HOPPING:
1140 return -EBUSY;
1141 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001142 if (local->oper_channel != chan)
1143 return -EBUSY;
1144 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001145 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001146 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001147 case CHAN_MODE_UNDEFINED:
1148 break;
1149 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001150
1151 local->oper_channel = chan;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001152
Johannes Berg0aaffa92010-05-05 15:28:27 +02001153 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1154 return -EBUSY;
1155
1156 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1157 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1158 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1159
1160 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001161}
1162
Bob Copeland665af4f2009-01-19 11:20:53 -05001163#ifdef CONFIG_PM
1164static int ieee80211_suspend(struct wiphy *wiphy)
1165{
1166 return __ieee80211_suspend(wiphy_priv(wiphy));
1167}
1168
1169static int ieee80211_resume(struct wiphy *wiphy)
1170{
1171 return __ieee80211_resume(wiphy_priv(wiphy));
1172}
1173#else
1174#define ieee80211_suspend NULL
1175#define ieee80211_resume NULL
1176#endif
1177
Johannes Berg2a519312009-02-10 21:25:55 +01001178static int ieee80211_scan(struct wiphy *wiphy,
1179 struct net_device *dev,
1180 struct cfg80211_scan_request *req)
1181{
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001182 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg2a519312009-02-10 21:25:55 +01001183
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001184 switch (ieee80211_vif_type_p2p(&sdata->vif)) {
1185 case NL80211_IFTYPE_STATION:
1186 case NL80211_IFTYPE_ADHOC:
1187 case NL80211_IFTYPE_MESH_POINT:
1188 case NL80211_IFTYPE_P2P_CLIENT:
1189 break;
1190 case NL80211_IFTYPE_P2P_GO:
1191 if (sdata->local->ops->hw_scan)
1192 break;
1193 /* FIXME: implement NoA while scanning in software */
Johannes Berg2a519312009-02-10 21:25:55 +01001194 return -EOPNOTSUPP;
Johannes Berg2ca27bc2010-09-16 14:58:23 +02001195 case NL80211_IFTYPE_AP:
1196 if (sdata->u.ap.beacon)
1197 return -EOPNOTSUPP;
1198 break;
1199 default:
1200 return -EOPNOTSUPP;
1201 }
Johannes Berg2a519312009-02-10 21:25:55 +01001202
1203 return ieee80211_request_scan(sdata, req);
1204}
1205
Jouni Malinen636a5d32009-03-19 13:39:22 +02001206static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1207 struct cfg80211_auth_request *req)
1208{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001209 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001210}
1211
1212static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1213 struct cfg80211_assoc_request *req)
1214{
Johannes Bergf444de02010-05-05 15:25:02 +02001215 struct ieee80211_local *local = wiphy_priv(wiphy);
1216 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1217
1218 switch (ieee80211_get_channel_mode(local, sdata)) {
1219 case CHAN_MODE_HOPPING:
1220 return -EBUSY;
1221 case CHAN_MODE_FIXED:
1222 if (local->oper_channel == req->bss->channel)
1223 break;
1224 return -EBUSY;
1225 case CHAN_MODE_UNDEFINED:
1226 break;
1227 }
1228
Johannes Berg77fdaa12009-07-07 03:45:17 +02001229 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001230}
1231
1232static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001233 struct cfg80211_deauth_request *req,
1234 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001235{
Johannes Berg667503d2009-07-07 03:56:11 +02001236 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1237 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001238}
1239
1240static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503d2009-07-07 03:56:11 +02001241 struct cfg80211_disassoc_request *req,
1242 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001243{
Johannes Berg667503d2009-07-07 03:56:11 +02001244 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1245 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001246}
1247
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001248static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1249 struct cfg80211_ibss_params *params)
1250{
Johannes Bergf444de02010-05-05 15:25:02 +02001251 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001252 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1253
Johannes Bergf444de02010-05-05 15:25:02 +02001254 switch (ieee80211_get_channel_mode(local, sdata)) {
1255 case CHAN_MODE_HOPPING:
1256 return -EBUSY;
1257 case CHAN_MODE_FIXED:
1258 if (!params->channel_fixed)
1259 return -EBUSY;
1260 if (local->oper_channel == params->channel)
1261 break;
1262 return -EBUSY;
1263 case CHAN_MODE_UNDEFINED:
1264 break;
1265 }
1266
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001267 return ieee80211_ibss_join(sdata, params);
1268}
1269
1270static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1271{
1272 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1273
1274 return ieee80211_ibss_leave(sdata);
1275}
1276
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001277static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1278{
1279 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001280 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001281
Lukáš Turek310bc672009-12-21 22:50:48 +01001282 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1283 err = drv_set_coverage_class(local, wiphy->coverage_class);
1284
1285 if (err)
1286 return err;
1287 }
1288
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001289 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001290 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001291
Johannes Berg24487982009-04-23 18:52:52 +02001292 if (err)
1293 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001294 }
1295
1296 if (changed & WIPHY_PARAM_RETRY_SHORT)
1297 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1298 if (changed & WIPHY_PARAM_RETRY_LONG)
1299 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1300 if (changed &
1301 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1302 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1303
1304 return 0;
1305}
1306
Johannes Berg7643a2c2009-06-02 13:01:39 +02001307static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001308 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001309{
1310 struct ieee80211_local *local = wiphy_priv(wiphy);
1311 struct ieee80211_channel *chan = local->hw.conf.channel;
1312 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001313
1314 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001315 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001316 local->user_power_level = -1;
1317 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001318 case NL80211_TX_POWER_LIMITED:
1319 if (mbm < 0 || (mbm % 100))
1320 return -EOPNOTSUPP;
1321 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001322 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001323 case NL80211_TX_POWER_FIXED:
1324 if (mbm < 0 || (mbm % 100))
1325 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001326 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001327 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001328 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001329 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001330 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001331 }
1332
1333 ieee80211_hw_config(local, changes);
1334
1335 return 0;
1336}
1337
1338static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1339{
1340 struct ieee80211_local *local = wiphy_priv(wiphy);
1341
1342 *dbm = local->hw.conf.power_level;
1343
Johannes Berg7643a2c2009-06-02 13:01:39 +02001344 return 0;
1345}
1346
Johannes Bergab737a42009-07-01 21:26:58 +02001347static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1348 u8 *addr)
1349{
1350 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1351
1352 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1353
1354 return 0;
1355}
1356
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001357static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1358{
1359 struct ieee80211_local *local = wiphy_priv(wiphy);
1360
1361 drv_rfkill_poll(local);
1362}
1363
Johannes Bergaff89a92009-07-01 21:26:51 +02001364#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001365static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001366{
1367 struct ieee80211_local *local = wiphy_priv(wiphy);
1368
1369 if (!local->ops->testmode_cmd)
1370 return -EOPNOTSUPP;
1371
1372 return local->ops->testmode_cmd(&local->hw, data, len);
1373}
1374#endif
1375
Johannes Berg0f782312009-12-01 13:37:02 +01001376int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1377 enum ieee80211_smps_mode smps_mode)
1378{
1379 const u8 *ap;
1380 enum ieee80211_smps_mode old_req;
1381 int err;
1382
1383 old_req = sdata->u.mgd.req_smps;
1384 sdata->u.mgd.req_smps = smps_mode;
1385
1386 if (old_req == smps_mode &&
1387 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1388 return 0;
1389
1390 /*
1391 * If not associated, or current association is not an HT
1392 * association, there's no need to send an action frame.
1393 */
1394 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001395 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001396 mutex_lock(&sdata->local->iflist_mtx);
Johannes Berg025e6be2010-10-05 10:41:47 +02001397 ieee80211_recalc_smps(sdata->local);
Johannes Berg0f782312009-12-01 13:37:02 +01001398 mutex_unlock(&sdata->local->iflist_mtx);
1399 return 0;
1400 }
1401
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001402 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001403
1404 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1405 if (sdata->u.mgd.powersave)
1406 smps_mode = IEEE80211_SMPS_DYNAMIC;
1407 else
1408 smps_mode = IEEE80211_SMPS_OFF;
1409 }
1410
1411 /* send SM PS frame to AP */
1412 err = ieee80211_send_smps_action(sdata, smps_mode,
1413 ap, ap);
1414 if (err)
1415 sdata->u.mgd.req_smps = old_req;
1416
1417 return err;
1418}
1419
Johannes Bergbc92afd2009-07-01 21:26:57 +02001420static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1421 bool enabled, int timeout)
1422{
1423 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1424 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001425
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001426 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1427 return -EOPNOTSUPP;
1428
Johannes Bergbc92afd2009-07-01 21:26:57 +02001429 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1430 return -EOPNOTSUPP;
1431
1432 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001433 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001434 return 0;
1435
1436 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001437 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001438
Johannes Berg0f782312009-12-01 13:37:02 +01001439 /* no change, but if automatic follow powersave */
1440 mutex_lock(&sdata->u.mgd.mtx);
1441 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1442 mutex_unlock(&sdata->u.mgd.mtx);
1443
Johannes Bergbc92afd2009-07-01 21:26:57 +02001444 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1445 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1446
1447 ieee80211_recalc_ps(local, -1);
1448
1449 return 0;
1450}
1451
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001452static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1453 struct net_device *dev,
1454 s32 rssi_thold, u32 rssi_hyst)
1455{
1456 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1457 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1458 struct ieee80211_vif *vif = &sdata->vif;
1459 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1460
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001461 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1462 rssi_hyst == bss_conf->cqm_rssi_hyst)
1463 return 0;
1464
1465 bss_conf->cqm_rssi_thold = rssi_thold;
1466 bss_conf->cqm_rssi_hyst = rssi_hyst;
1467
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001468 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1469 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1470 return -EOPNOTSUPP;
1471 return 0;
1472 }
1473
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001474 /* tell the driver upon association, unless already associated */
1475 if (sdata->u.mgd.associated)
1476 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1477
1478 return 0;
1479}
1480
Johannes Berg99303802009-07-01 21:26:59 +02001481static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1482 struct net_device *dev,
1483 const u8 *addr,
1484 const struct cfg80211_bitrate_mask *mask)
1485{
1486 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1487 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001488 int i;
Johannes Berg99303802009-07-01 21:26:59 +02001489
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001490 /*
1491 * This _could_ be supported by providing a hook for
1492 * drivers for this function, but at this point it
1493 * doesn't seem worth bothering.
1494 */
1495 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1496 return -EOPNOTSUPP;
1497
Johannes Berg99303802009-07-01 21:26:59 +02001498
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001499 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1500 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001501
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001502 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001503}
1504
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001505static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1506 struct net_device *dev,
1507 struct ieee80211_channel *chan,
1508 enum nl80211_channel_type channel_type,
1509 unsigned int duration,
1510 u64 *cookie)
1511{
1512 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1513
1514 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1515 duration, cookie);
1516}
1517
1518static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1519 struct net_device *dev,
1520 u64 cookie)
1521{
1522 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1523
1524 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1525}
1526
Johannes Berg2e161f72010-08-12 15:38:38 +02001527static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1528 struct ieee80211_channel *chan,
1529 enum nl80211_channel_type channel_type,
1530 bool channel_type_valid,
1531 const u8 *buf, size_t len, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001532{
Johannes Berg9d38d852010-06-09 17:20:33 +02001533 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1534 struct ieee80211_local *local = sdata->local;
1535 struct sk_buff *skb;
1536 struct sta_info *sta;
1537 const struct ieee80211_mgmt *mgmt = (void *)buf;
1538 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1539 IEEE80211_TX_CTL_REQ_TX_STATUS;
1540
1541 /* Check that we are on the requested channel for transmission */
1542 if (chan != local->tmp_channel &&
1543 chan != local->oper_channel)
1544 return -EBUSY;
1545 if (channel_type_valid &&
1546 (channel_type != local->tmp_channel_type &&
1547 channel_type != local->_oper_channel_type))
1548 return -EBUSY;
1549
1550 switch (sdata->vif.type) {
1551 case NL80211_IFTYPE_ADHOC:
Johannes Berg663fcaf2010-09-30 21:06:09 +02001552 case NL80211_IFTYPE_AP:
1553 case NL80211_IFTYPE_AP_VLAN:
1554 case NL80211_IFTYPE_P2P_GO:
1555 if (!ieee80211_is_action(mgmt->frame_control) ||
1556 mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
Johannes Berg9d38d852010-06-09 17:20:33 +02001557 break;
1558 rcu_read_lock();
1559 sta = sta_info_get(sdata, mgmt->da);
1560 rcu_read_unlock();
1561 if (!sta)
1562 return -ENOLINK;
1563 break;
1564 case NL80211_IFTYPE_STATION:
Johannes Berg663fcaf2010-09-30 21:06:09 +02001565 case NL80211_IFTYPE_P2P_CLIENT:
Johannes Berg9d38d852010-06-09 17:20:33 +02001566 break;
1567 default:
1568 return -EOPNOTSUPP;
1569 }
1570
1571 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1572 if (!skb)
1573 return -ENOMEM;
1574 skb_reserve(skb, local->hw.extra_tx_headroom);
1575
1576 memcpy(skb_put(skb, len), buf, len);
1577
1578 IEEE80211_SKB_CB(skb)->flags = flags;
1579
1580 skb->dev = sdata->dev;
1581 ieee80211_tx_skb(sdata, skb);
1582
1583 *cookie = (unsigned long) skb;
1584 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02001585}
1586
Jiri Bencf0706e822007-05-05 11:45:53 -07001587struct cfg80211_ops mac80211_config_ops = {
1588 .add_virtual_intf = ieee80211_add_iface,
1589 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001590 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001591 .add_key = ieee80211_add_key,
1592 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001593 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001594 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6a2009-01-08 13:32:02 +02001595 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001596 .add_beacon = ieee80211_add_beacon,
1597 .set_beacon = ieee80211_set_beacon,
1598 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001599 .add_station = ieee80211_add_station,
1600 .del_station = ieee80211_del_station,
1601 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001602 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001603 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02001604 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001605#ifdef CONFIG_MAC80211_MESH
1606 .add_mpath = ieee80211_add_mpath,
1607 .del_mpath = ieee80211_del_mpath,
1608 .change_mpath = ieee80211_change_mpath,
1609 .get_mpath = ieee80211_get_mpath,
1610 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001611 .set_mesh_params = ieee80211_set_mesh_params,
1612 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001613#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001614 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001615 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001616 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001617 .suspend = ieee80211_suspend,
1618 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001619 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001620 .auth = ieee80211_auth,
1621 .assoc = ieee80211_assoc,
1622 .deauth = ieee80211_deauth,
1623 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001624 .join_ibss = ieee80211_join_ibss,
1625 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001626 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02001627 .set_tx_power = ieee80211_set_tx_power,
1628 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02001629 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001630 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02001631 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001632 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02001633 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001634 .remain_on_channel = ieee80211_remain_on_channel,
1635 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02001636 .mgmt_tx = ieee80211_mgmt_tx,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001637 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Jiri Bencf0706e822007-05-05 11:45:53 -07001638};