blob: f149b4eb28d9acfe5efe47ea58c3fcc97b0522ff [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
Jiri Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-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 Bencf0706e82007-05-05 11:45:53 -070041{
Johannes Berg463d0182009-07-14 00:33:35 +020042 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
Jiri Bencf0706e82007-05-05 11:45:53 -070043
Johannes Berg75636522008-07-09 14:40:35 +020044 return 0;
Jiri Bencf0706e82007-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 Berg9607e6b2009-12-23 13:15:31 +010055 if (ieee80211_sdata_running(sdata))
Johannes Bergc1f9a762009-11-01 19:25:40 +010056 return -EBUSY;
57
Johannes Berg05c914f2008-09-11 00:01:58 +020058 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020059 if (ret)
60 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020061
Johannes Berg902acc72008-02-23 15:17:19 +010062 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +020063 ieee80211_sdata_set_mesh_id(sdata,
64 params->mesh_id_len,
65 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010066
Johannes Berg9bc383d2009-11-19 11:55:19 +010067 if (type == NL80211_IFTYPE_AP_VLAN &&
68 params && params->use_4addr == 0)
69 rcu_assign_pointer(sdata->u.vlan.sta, NULL);
70 else if (type == NL80211_IFTYPE_STATION &&
71 params && params->use_4addr >= 0)
72 sdata->u.mgd.use_4addr = params->use_4addr;
73
Felix Fietkauf7917af2010-04-27 00:26:34 +020074 if (sdata->vif.type == NL80211_IFTYPE_MONITOR && flags)
75 sdata->u.mntr_flags = *flags;
76
Johannes Berg42613db2007-09-28 21:52:27 +020077 return 0;
78}
79
Johannes Berge8cbb4c2007-12-19 02:03:30 +010080static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +020081 u8 key_idx, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +010082 struct key_params *params)
83{
84 struct ieee80211_sub_if_data *sdata;
85 struct sta_info *sta = NULL;
Johannes Bergdb4d1162008-02-25 16:27:45 +010086 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +020087 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +010088
Johannes Bergad0e2b52010-06-01 10:19:19 +020089 if (!netif_running(dev))
90 return -ENETDOWN;
91
Johannes Berge8cbb4c2007-12-19 02:03:30 +010092 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
93
Johannes Berg97359d12010-08-10 09:46:38 +020094 /* reject WEP and TKIP keys if WEP failed to initialize */
Johannes Berge8cbb4c2007-12-19 02:03:30 +010095 switch (params->cipher) {
96 case WLAN_CIPHER_SUITE_WEP40:
Johannes Berge8cbb4c2007-12-19 02:03:30 +010097 case WLAN_CIPHER_SUITE_TKIP:
Johannes Berg97359d12010-08-10 09:46:38 +020098 case WLAN_CIPHER_SUITE_WEP104:
99 if (IS_ERR(sdata->local->wep_tx_tfm))
100 return -EINVAL;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200101 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100102 default:
Johannes Berg97359d12010-08-10 09:46:38 +0200103 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100104 }
105
Johannes Berg97359d12010-08-10 09:46:38 +0200106 key = ieee80211_key_alloc(params->cipher, key_idx, params->key_len,
107 params->key, params->seq_len, params->seq);
Ben Hutchings1ac62ba2010-08-01 17:37:03 +0100108 if (IS_ERR(key))
109 return PTR_ERR(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100110
Johannes Bergad0e2b52010-06-01 10:19:19 +0200111 mutex_lock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200112
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100113 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100114 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100115 if (!sta) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700116 ieee80211_key_free(sdata->local, key);
Johannes Berg3b967662008-04-08 17:56:52 +0200117 err = -ENOENT;
118 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100119 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100120 }
121
Johannes Berg3ffc2a92010-08-27 14:26:52 +0300122 err = ieee80211_key_link(key, sdata, sta);
123 if (err)
124 ieee80211_key_free(sdata->local, key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100125
Johannes Berg3b967662008-04-08 17:56:52 +0200126 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200127 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200128
129 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100130}
131
132static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200133 u8 key_idx, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100134{
135 struct ieee80211_sub_if_data *sdata;
136 struct sta_info *sta;
137 int ret;
138
139 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
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) {
Johannes Berg3b967662008-04-08 17:56:52 +0200144 ret = -ENOENT;
145
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100146 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100147 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200148 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100149
Johannes Bergdb4d1162008-02-25 16:27:45 +0100150 if (sta->key) {
Jouni Malinen32162a42010-07-26 15:52:03 -0700151 ieee80211_key_free(sdata->local, sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100152 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200153 ret = 0;
154 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100155
Johannes Berg3b967662008-04-08 17:56:52 +0200156 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100157 }
158
Johannes Berg3b967662008-04-08 17:56:52 +0200159 if (!sdata->keys[key_idx]) {
160 ret = -ENOENT;
161 goto out_unlock;
162 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100163
Jouni Malinen32162a42010-07-26 15:52:03 -0700164 ieee80211_key_free(sdata->local, sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100165 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100166
Johannes Berg3b967662008-04-08 17:56:52 +0200167 ret = 0;
168 out_unlock:
Johannes Bergad0e2b52010-06-01 10:19:19 +0200169 mutex_unlock(&sdata->local->sta_mtx);
Johannes Berg3b967662008-04-08 17:56:52 +0200170
171 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100172}
173
Johannes Berg62da92f2007-12-19 02:03:31 +0100174static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200175 u8 key_idx, const u8 *mac_addr, void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100176 void (*callback)(void *cookie,
177 struct key_params *params))
178{
Johannes Berg14db74b2008-07-29 13:22:52 +0200179 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100180 struct sta_info *sta = NULL;
181 u8 seq[6] = {0};
182 struct key_params params;
183 struct ieee80211_key *key;
184 u32 iv32;
185 u16 iv16;
186 int err = -ENOENT;
187
Johannes Berg14db74b2008-07-29 13:22:52 +0200188 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
189
Johannes Berg3b967662008-04-08 17:56:52 +0200190 rcu_read_lock();
191
Johannes Berg62da92f2007-12-19 02:03:31 +0100192 if (mac_addr) {
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100193 sta = sta_info_get_bss(sdata, mac_addr);
Johannes Berg62da92f2007-12-19 02:03:31 +0100194 if (!sta)
195 goto out;
196
197 key = sta->key;
198 } else
199 key = sdata->keys[key_idx];
200
201 if (!key)
202 goto out;
203
204 memset(&params, 0, sizeof(params));
205
Johannes Berg97359d12010-08-10 09:46:38 +0200206 params.cipher = key->conf.cipher;
Johannes Berg62da92f2007-12-19 02:03:31 +0100207
Johannes Berg97359d12010-08-10 09:46:38 +0200208 switch (key->conf.cipher) {
209 case WLAN_CIPHER_SUITE_TKIP:
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700210 iv32 = key->u.tkip.tx.iv32;
211 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100212
Johannes Berg24487982009-04-23 18:52:52 +0200213 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
214 drv_get_tkip_seq(sdata->local,
215 key->conf.hw_key_idx,
216 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100217
218 seq[0] = iv16 & 0xff;
219 seq[1] = (iv16 >> 8) & 0xff;
220 seq[2] = iv32 & 0xff;
221 seq[3] = (iv32 >> 8) & 0xff;
222 seq[4] = (iv32 >> 16) & 0xff;
223 seq[5] = (iv32 >> 24) & 0xff;
224 params.seq = seq;
225 params.seq_len = 6;
226 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200227 case WLAN_CIPHER_SUITE_CCMP:
Johannes Berg62da92f2007-12-19 02:03:31 +0100228 seq[0] = key->u.ccmp.tx_pn[5];
229 seq[1] = key->u.ccmp.tx_pn[4];
230 seq[2] = key->u.ccmp.tx_pn[3];
231 seq[3] = key->u.ccmp.tx_pn[2];
232 seq[4] = key->u.ccmp.tx_pn[1];
233 seq[5] = key->u.ccmp.tx_pn[0];
234 params.seq = seq;
235 params.seq_len = 6;
236 break;
Johannes Berg97359d12010-08-10 09:46:38 +0200237 case WLAN_CIPHER_SUITE_AES_CMAC:
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200238 seq[0] = key->u.aes_cmac.tx_pn[5];
239 seq[1] = key->u.aes_cmac.tx_pn[4];
240 seq[2] = key->u.aes_cmac.tx_pn[3];
241 seq[3] = key->u.aes_cmac.tx_pn[2];
242 seq[4] = key->u.aes_cmac.tx_pn[1];
243 seq[5] = key->u.aes_cmac.tx_pn[0];
244 params.seq = seq;
245 params.seq_len = 6;
246 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100247 }
248
249 params.key = key->conf.key;
250 params.key_len = key->conf.keylen;
251
252 callback(cookie, &params);
253 err = 0;
254
255 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200256 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100257 return err;
258}
259
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100260static int ieee80211_config_default_key(struct wiphy *wiphy,
261 struct net_device *dev,
262 u8 key_idx)
263{
Johannes Bergad0e2b52010-06-01 10:19:19 +0200264 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100265
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100266 ieee80211_set_default_key(sdata, key_idx);
267
268 return 0;
269}
270
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200271static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
272 struct net_device *dev,
273 u8 key_idx)
274{
Johannes Berg66c52422010-07-22 13:58:51 +0200275 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200276
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200277 ieee80211_set_default_mgmt_key(sdata, key_idx);
278
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200279 return 0;
280}
281
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100282static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
283{
Johannes Bergd0709a62008-02-25 16:27:46 +0100284 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100285
Johannes Bergf5ea9122009-08-07 16:17:38 +0200286 sinfo->generation = sdata->local->sta_generation;
287
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100288 sinfo->filled = STATION_INFO_INACTIVE_TIME |
289 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100290 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200291 STATION_INFO_RX_PACKETS |
292 STATION_INFO_TX_PACKETS |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100293 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100294
295 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
296 sinfo->rx_bytes = sta->rx_bytes;
297 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200298 sinfo->rx_packets = sta->rx_packets;
299 sinfo->tx_packets = sta->tx_packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100300
John W. Linville19deffb2009-12-08 17:10:13 -0500301 if ((sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) ||
302 (sta->local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)) {
Henning Rogge420e7fa2008-12-11 22:04:19 +0100303 sinfo->filled |= STATION_INFO_SIGNAL;
304 sinfo->signal = (s8)sta->last_signal;
305 }
306
307 sinfo->txrate.flags = 0;
308 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
309 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
310 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
311 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
312 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
313 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
314
315 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
316 struct ieee80211_supported_band *sband;
317 sband = sta->local->hw.wiphy->bands[
318 sta->local->hw.conf.channel->band];
319 sinfo->txrate.legacy =
320 sband->bitrates[sta->last_tx_rate.idx].bitrate;
321 } else
322 sinfo->txrate.mcs = sta->last_tx_rate.idx;
323
Johannes Berg902acc72008-02-23 15:17:19 +0100324 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100325#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100326 sinfo->filled |= STATION_INFO_LLID |
327 STATION_INFO_PLID |
328 STATION_INFO_PLINK_STATE;
329
330 sinfo->llid = le16_to_cpu(sta->llid);
331 sinfo->plid = le16_to_cpu(sta->plid);
332 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100333#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100334 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100335}
336
337
338static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
339 int idx, u8 *mac, struct station_info *sinfo)
340{
Johannes Berg3b53fde82009-11-16 12:00:37 +0100341 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100342 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100343 int ret = -ENOENT;
344
345 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100346
Johannes Berg3b53fde82009-11-16 12:00:37 +0100347 sta = sta_info_get_by_idx(sdata, idx);
Johannes Bergd0709a62008-02-25 16:27:46 +0100348 if (sta) {
349 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200350 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100351 sta_set_sinfo(sta, sinfo);
352 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100353
Johannes Bergd0709a62008-02-25 16:27:46 +0100354 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100355
Johannes Bergd0709a62008-02-25 16:27:46 +0100356 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100357}
358
Holger Schurig12897232010-04-19 10:23:57 +0200359static int ieee80211_dump_survey(struct wiphy *wiphy, struct net_device *dev,
360 int idx, struct survey_info *survey)
361{
362 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
363
Holger Schurig12897232010-04-19 10:23:57 +0200364 return drv_get_survey(local, idx, survey);
365}
366
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100367static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100368 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100369{
Johannes Bergabe60632009-11-25 17:46:18 +0100370 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100371 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100372 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100373
Johannes Bergd0709a62008-02-25 16:27:46 +0100374 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100375
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100376 sta = sta_info_get_bss(sdata, mac);
Johannes Bergd0709a62008-02-25 16:27:46 +0100377 if (sta) {
378 ret = 0;
379 sta_set_sinfo(sta, sinfo);
380 }
381
382 rcu_read_unlock();
383
384 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100385}
386
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100387/*
388 * This handles both adding a beacon and setting new beacon info
389 */
390static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
391 struct beacon_parameters *params)
392{
393 struct beacon_data *new, *old;
394 int new_head_len, new_tail_len;
395 int size;
396 int err = -EINVAL;
397
398 old = sdata->u.ap.beacon;
399
400 /* head must not be zero-length */
401 if (params->head && !params->head_len)
402 return -EINVAL;
403
404 /*
405 * This is a kludge. beacon interval should really be part
406 * of the beacon information.
407 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200408 if (params->interval &&
409 (sdata->vif.bss_conf.beacon_int != params->interval)) {
410 sdata->vif.bss_conf.beacon_int = params->interval;
411 ieee80211_bss_info_change_notify(sdata,
412 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100413 }
414
415 /* Need to have a beacon head if we don't have one yet */
416 if (!params->head && !old)
417 return err;
418
419 /* sorry, no way to start beaconing without dtim period */
420 if (!params->dtim_period && !old)
421 return err;
422
423 /* new or old head? */
424 if (params->head)
425 new_head_len = params->head_len;
426 else
427 new_head_len = old->head_len;
428
429 /* new or old tail? */
430 if (params->tail || !old)
431 /* params->tail_len will be zero for !params->tail */
432 new_tail_len = params->tail_len;
433 else
434 new_tail_len = old->tail_len;
435
436 size = sizeof(*new) + new_head_len + new_tail_len;
437
438 new = kzalloc(size, GFP_KERNEL);
439 if (!new)
440 return -ENOMEM;
441
442 /* start filling the new info now */
443
444 /* new or old dtim period? */
445 if (params->dtim_period)
446 new->dtim_period = params->dtim_period;
447 else
448 new->dtim_period = old->dtim_period;
449
450 /*
451 * pointers go into the block we allocated,
452 * memory is | beacon_data | head | tail |
453 */
454 new->head = ((u8 *) new) + sizeof(*new);
455 new->tail = new->head + new_head_len;
456 new->head_len = new_head_len;
457 new->tail_len = new_tail_len;
458
459 /* copy in head */
460 if (params->head)
461 memcpy(new->head, params->head, new_head_len);
462 else
463 memcpy(new->head, old->head, new_head_len);
464
465 /* copy in optional tail */
466 if (params->tail)
467 memcpy(new->tail, params->tail, new_tail_len);
468 else
469 if (old)
470 memcpy(new->tail, old->tail, new_tail_len);
471
Johannes Berg19885c42010-02-05 11:45:06 +0100472 sdata->vif.bss_conf.dtim_period = new->dtim_period;
473
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100474 rcu_assign_pointer(sdata->u.ap.beacon, new);
475
476 synchronize_rcu();
477
478 kfree(old);
479
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200480 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
481 BSS_CHANGED_BEACON);
482 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100483}
484
485static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
486 struct beacon_parameters *params)
487{
Johannes Berg14db74b2008-07-29 13:22:52 +0200488 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100489 struct beacon_data *old;
490
Johannes Berg14db74b2008-07-29 13:22:52 +0200491 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
492
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100493 old = sdata->u.ap.beacon;
494
495 if (old)
496 return -EALREADY;
497
498 return ieee80211_config_beacon(sdata, params);
499}
500
501static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
502 struct beacon_parameters *params)
503{
Johannes Berg14db74b2008-07-29 13:22:52 +0200504 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100505 struct beacon_data *old;
506
Johannes Berg14db74b2008-07-29 13:22:52 +0200507 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
508
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100509 old = sdata->u.ap.beacon;
510
511 if (!old)
512 return -ENOENT;
513
514 return ieee80211_config_beacon(sdata, params);
515}
516
517static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
518{
Johannes Berg14db74b2008-07-29 13:22:52 +0200519 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100520 struct beacon_data *old;
521
Johannes Berg14db74b2008-07-29 13:22:52 +0200522 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
523
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100524 old = sdata->u.ap.beacon;
525
526 if (!old)
527 return -ENOENT;
528
529 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
530 synchronize_rcu();
531 kfree(old);
532
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200533 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
534 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100535}
536
Johannes Berg4fd69312007-12-19 02:03:35 +0100537/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
538struct iapp_layer2_update {
539 u8 da[ETH_ALEN]; /* broadcast */
540 u8 sa[ETH_ALEN]; /* STA addr */
541 __be16 len; /* 6 */
542 u8 dsap; /* 0 */
543 u8 ssap; /* 0 */
544 u8 control;
545 u8 xid_info[3];
Eric Dumazetbc105022010-06-03 03:21:52 -0700546} __packed;
Johannes Berg4fd69312007-12-19 02:03:35 +0100547
548static void ieee80211_send_layer2_update(struct sta_info *sta)
549{
550 struct iapp_layer2_update *msg;
551 struct sk_buff *skb;
552
553 /* Send Level 2 Update Frame to update forwarding tables in layer 2
554 * bridge devices */
555
556 skb = dev_alloc_skb(sizeof(*msg));
557 if (!skb)
558 return;
559 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
560
561 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
562 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
563
564 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200565 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100566 msg->len = htons(6);
567 msg->dsap = 0;
568 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
569 msg->control = 0xaf; /* XID response lsb.1111F101.
570 * F=0 (no poll command; unsolicited frame) */
571 msg->xid_info[0] = 0x81; /* XID format identifier */
572 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
573 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
574
Johannes Bergd0709a62008-02-25 16:27:46 +0100575 skb->dev = sta->sdata->dev;
576 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100577 memset(skb->cb, 0, sizeof(skb->cb));
John W. Linville06ee1c22010-07-19 11:52:59 -0400578 netif_rx_ni(skb);
Johannes Berg4fd69312007-12-19 02:03:35 +0100579}
580
581static void sta_apply_parameters(struct ieee80211_local *local,
582 struct sta_info *sta,
583 struct station_parameters *params)
584{
585 u32 rates;
586 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100587 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100588 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300589 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100590
Johannes Bergae5eb022008-10-14 16:58:37 +0200591 sband = local->hw.wiphy->bands[local->oper_channel->band];
592
Johannes Bergeccb8e82009-05-11 21:57:56 +0300593 spin_lock_bh(&sta->lock);
594 mask = params->sta_flags_mask;
595 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100596
Johannes Bergeccb8e82009-05-11 21:57:56 +0300597 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100598 sta->flags &= ~WLAN_STA_AUTHORIZED;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300599 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg4fd69312007-12-19 02:03:35 +0100600 sta->flags |= WLAN_STA_AUTHORIZED;
Johannes Berg4fd69312007-12-19 02:03:35 +0100601 }
602
Johannes Bergeccb8e82009-05-11 21:57:56 +0300603 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
604 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
605 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
606 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
607 }
608
609 if (mask & BIT(NL80211_STA_FLAG_WME)) {
610 sta->flags &= ~WLAN_STA_WME;
611 if (set & BIT(NL80211_STA_FLAG_WME))
612 sta->flags |= WLAN_STA_WME;
613 }
614
615 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
616 sta->flags &= ~WLAN_STA_MFP;
617 if (set & BIT(NL80211_STA_FLAG_MFP))
618 sta->flags |= WLAN_STA_MFP;
619 }
620 spin_unlock_bh(&sta->lock);
621
Johannes Berg73651ee2008-02-25 16:27:47 +0100622 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200623 * cfg80211 validates this (1-2007) and allows setting the AID
624 * only when creating a new station entry
625 */
626 if (params->aid)
627 sta->sta.aid = params->aid;
628
629 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100630 * FIXME: updating the following information is racy when this
631 * function is called from ieee80211_change_station().
632 * However, all this information should be static so
633 * maybe we should just reject attemps to change it.
634 */
635
Johannes Berg4fd69312007-12-19 02:03:35 +0100636 if (params->listen_interval >= 0)
637 sta->listen_interval = params->listen_interval;
638
639 if (params->supported_rates) {
640 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100641
Johannes Berg4fd69312007-12-19 02:03:35 +0100642 for (i = 0; i < params->supported_rates_len; i++) {
643 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100644 for (j = 0; j < sband->n_bitrates; j++) {
645 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100646 rates |= BIT(j);
647 }
648 }
Johannes Berg323ce792008-09-11 02:45:11 +0200649 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100650 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100651
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200652 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200653 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
654 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200655 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +0300656
Johannes Berg902acc72008-02-23 15:17:19 +0100657 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100658 switch (params->plink_action) {
659 case PLINK_ACTION_OPEN:
660 mesh_plink_open(sta);
661 break;
662 case PLINK_ACTION_BLOCK:
663 mesh_plink_block(sta);
664 break;
665 }
Johannes Berg902acc72008-02-23 15:17:19 +0100666 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100667}
668
669static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
670 u8 *mac, struct station_parameters *params)
671{
Johannes Berg14db74b2008-07-29 13:22:52 +0200672 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100673 struct sta_info *sta;
674 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100675 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200676 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100677
Johannes Berg4fd69312007-12-19 02:03:35 +0100678 if (params->vlan) {
679 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
680
Johannes Berg05c914f2008-09-11 00:01:58 +0200681 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
682 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100683 return -EINVAL;
684 } else
685 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
686
Johannes Berg47846c92009-11-25 17:46:19 +0100687 if (compare_ether_addr(mac, sdata->vif.addr) == 0)
Johannes Berg03e44972008-02-27 09:56:40 +0100688 return -EINVAL;
689
690 if (is_multicast_ether_addr(mac))
691 return -EINVAL;
692
693 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100694 if (!sta)
695 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100696
697 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
698
699 sta_apply_parameters(local, sta, params);
700
Johannes Berg4b7679a2008-09-18 18:14:18 +0200701 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100702
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200703 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
704 sdata->vif.type == NL80211_IFTYPE_AP;
705
Johannes Berg34e89502010-02-03 13:59:58 +0100706 err = sta_info_insert_rcu(sta);
Johannes Berg73651ee2008-02-25 16:27:47 +0100707 if (err) {
Johannes Berg73651ee2008-02-25 16:27:47 +0100708 rcu_read_unlock();
709 return err;
710 }
711
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200712 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100713 ieee80211_send_layer2_update(sta);
714
715 rcu_read_unlock();
716
Johannes Berg4fd69312007-12-19 02:03:35 +0100717 return 0;
718}
719
720static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
721 u8 *mac)
722{
Johannes Berg14db74b2008-07-29 13:22:52 +0200723 struct ieee80211_local *local = wiphy_priv(wiphy);
724 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100725
Johannes Berg14db74b2008-07-29 13:22:52 +0200726 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
727
Johannes Berg34e89502010-02-03 13:59:58 +0100728 if (mac)
729 return sta_info_destroy_addr_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200730
Johannes Berg34e89502010-02-03 13:59:58 +0100731 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100732 return 0;
733}
734
735static int ieee80211_change_station(struct wiphy *wiphy,
736 struct net_device *dev,
737 u8 *mac,
738 struct station_parameters *params)
739{
Johannes Bergabe60632009-11-25 17:46:18 +0100740 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg14db74b2008-07-29 13:22:52 +0200741 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100742 struct sta_info *sta;
743 struct ieee80211_sub_if_data *vlansdata;
744
Johannes Berg98dd6a52008-04-10 15:36:09 +0200745 rcu_read_lock();
746
Felix Fietkau0e5ded52010-01-08 18:10:58 +0100747 sta = sta_info_get_bss(sdata, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200748 if (!sta) {
749 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100750 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200751 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100752
Johannes Bergd0709a62008-02-25 16:27:46 +0100753 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100754 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
755
Johannes Berg05c914f2008-09-11 00:01:58 +0200756 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
757 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200758 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100759 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200760 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100761
Johannes Berg9bc383d2009-11-19 11:55:19 +0100762 if (params->vlan->ieee80211_ptr->use_4addr) {
Johannes Berg33054432009-11-20 10:09:14 +0100763 if (vlansdata->u.vlan.sta) {
764 rcu_read_unlock();
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100765 return -EBUSY;
Johannes Berg33054432009-11-20 10:09:14 +0100766 }
Felix Fietkauf14543ee2009-11-10 20:10:05 +0100767
768 rcu_assign_pointer(vlansdata->u.vlan.sta, sta);
769 }
770
Johannes Berg14db74b2008-07-29 13:22:52 +0200771 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100772 ieee80211_send_layer2_update(sta);
773 }
774
775 sta_apply_parameters(local, sta, params);
776
Johannes Berg98dd6a52008-04-10 15:36:09 +0200777 rcu_read_unlock();
778
Johannes Berg4fd69312007-12-19 02:03:35 +0100779 return 0;
780}
781
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100782#ifdef CONFIG_MAC80211_MESH
783static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
784 u8 *dst, u8 *next_hop)
785{
Johannes Berg14db74b2008-07-29 13:22:52 +0200786 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100787 struct mesh_path *mpath;
788 struct sta_info *sta;
789 int err;
790
Johannes Berg14db74b2008-07-29 13:22:52 +0200791 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
792
Johannes Bergd0709a62008-02-25 16:27:46 +0100793 rcu_read_lock();
Johannes Bergabe60632009-11-25 17:46:18 +0100794 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100795 if (!sta) {
796 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100797 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100798 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100799
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200800 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100801 if (err) {
802 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100803 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100804 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100805
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200806 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100807 if (!mpath) {
808 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100809 return -ENXIO;
810 }
811 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100812
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100813 rcu_read_unlock();
814 return 0;
815}
816
817static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
818 u8 *dst)
819{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200820 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100821
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200822 if (dst)
823 return mesh_path_del(dst, sdata);
824
825 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100826 return 0;
827}
828
829static int ieee80211_change_mpath(struct wiphy *wiphy,
830 struct net_device *dev,
831 u8 *dst, u8 *next_hop)
832{
Johannes Berg14db74b2008-07-29 13:22:52 +0200833 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100834 struct mesh_path *mpath;
835 struct sta_info *sta;
836
Johannes Berg14db74b2008-07-29 13:22:52 +0200837 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
838
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100839 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100840
Johannes Bergabe60632009-11-25 17:46:18 +0100841 sta = sta_info_get(sdata, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100842 if (!sta) {
843 rcu_read_unlock();
844 return -ENOENT;
845 }
846
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200847 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100848 if (!mpath) {
849 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100850 return -ENOENT;
851 }
852
853 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100854
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100855 rcu_read_unlock();
856 return 0;
857}
858
859static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
860 struct mpath_info *pinfo)
861{
862 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200863 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100864 else
865 memset(next_hop, 0, ETH_ALEN);
866
Johannes Bergf5ea9122009-08-07 16:17:38 +0200867 pinfo->generation = mesh_paths_generation;
868
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100869 pinfo->filled = MPATH_INFO_FRAME_QLEN |
Rui Paulod19b3bf2009-11-09 23:46:55 +0000870 MPATH_INFO_SN |
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100871 MPATH_INFO_METRIC |
872 MPATH_INFO_EXPTIME |
873 MPATH_INFO_DISCOVERY_TIMEOUT |
874 MPATH_INFO_DISCOVERY_RETRIES |
875 MPATH_INFO_FLAGS;
876
877 pinfo->frame_qlen = mpath->frame_queue.qlen;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000878 pinfo->sn = mpath->sn;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100879 pinfo->metric = mpath->metric;
880 if (time_before(jiffies, mpath->exp_time))
881 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
882 pinfo->discovery_timeout =
883 jiffies_to_msecs(mpath->discovery_timeout);
884 pinfo->discovery_retries = mpath->discovery_retries;
885 pinfo->flags = 0;
886 if (mpath->flags & MESH_PATH_ACTIVE)
887 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
888 if (mpath->flags & MESH_PATH_RESOLVING)
889 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
Rui Paulod19b3bf2009-11-09 23:46:55 +0000890 if (mpath->flags & MESH_PATH_SN_VALID)
891 pinfo->flags |= NL80211_MPATH_FLAG_SN_VALID;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100892 if (mpath->flags & MESH_PATH_FIXED)
893 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
894 if (mpath->flags & MESH_PATH_RESOLVING)
895 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
896
897 pinfo->flags = mpath->flags;
898}
899
900static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
901 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
902
903{
Johannes Berg14db74b2008-07-29 13:22:52 +0200904 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100905 struct mesh_path *mpath;
906
Johannes Berg14db74b2008-07-29 13:22:52 +0200907 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
908
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100909 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200910 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100911 if (!mpath) {
912 rcu_read_unlock();
913 return -ENOENT;
914 }
915 memcpy(dst, mpath->dst, ETH_ALEN);
916 mpath_set_pinfo(mpath, next_hop, pinfo);
917 rcu_read_unlock();
918 return 0;
919}
920
921static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
922 int idx, u8 *dst, u8 *next_hop,
923 struct mpath_info *pinfo)
924{
Johannes Berg14db74b2008-07-29 13:22:52 +0200925 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100926 struct mesh_path *mpath;
927
Johannes Berg14db74b2008-07-29 13:22:52 +0200928 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
929
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100930 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200931 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100932 if (!mpath) {
933 rcu_read_unlock();
934 return -ENOENT;
935 }
936 memcpy(dst, mpath->dst, ETH_ALEN);
937 mpath_set_pinfo(mpath, next_hop, pinfo);
938 rcu_read_unlock();
939 return 0;
940}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700941
942static int ieee80211_get_mesh_params(struct wiphy *wiphy,
943 struct net_device *dev,
944 struct mesh_config *conf)
945{
946 struct ieee80211_sub_if_data *sdata;
947 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
948
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700949 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
950 return 0;
951}
952
953static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
954{
955 return (mask >> (parm-1)) & 0x1;
956}
957
958static int ieee80211_set_mesh_params(struct wiphy *wiphy,
959 struct net_device *dev,
960 const struct mesh_config *nconf, u32 mask)
961{
962 struct mesh_config *conf;
963 struct ieee80211_sub_if_data *sdata;
Rui Paulo63c57232009-11-09 23:46:57 +0000964 struct ieee80211_if_mesh *ifmsh;
965
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700966 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Rui Paulo63c57232009-11-09 23:46:57 +0000967 ifmsh = &sdata->u.mesh;
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700968
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700969 /* Set the config options which we are interested in setting */
970 conf = &(sdata->u.mesh.mshcfg);
971 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
972 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
973 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
974 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
975 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
976 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
977 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
978 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
979 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
980 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
981 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
982 conf->dot11MeshTTL = nconf->dot11MeshTTL;
983 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
984 conf->auto_open_plinks = nconf->auto_open_plinks;
985 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
986 conf->dot11MeshHWMPmaxPREQretries =
987 nconf->dot11MeshHWMPmaxPREQretries;
988 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
989 conf->path_refresh_time = nconf->path_refresh_time;
990 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
991 conf->min_discovery_timeout = nconf->min_discovery_timeout;
992 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
993 conf->dot11MeshHWMPactivePathTimeout =
994 nconf->dot11MeshHWMPactivePathTimeout;
995 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
996 conf->dot11MeshHWMPpreqMinInterval =
997 nconf->dot11MeshHWMPpreqMinInterval;
998 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
999 mask))
1000 conf->dot11MeshHWMPnetDiameterTraversalTime =
1001 nconf->dot11MeshHWMPnetDiameterTraversalTime;
Rui Paulo63c57232009-11-09 23:46:57 +00001002 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ROOTMODE, mask)) {
1003 conf->dot11MeshHWMPRootMode = nconf->dot11MeshHWMPRootMode;
1004 ieee80211_mesh_root_setup(ifmsh);
1005 }
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001006 return 0;
1007}
1008
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001009#endif
1010
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001011static int ieee80211_change_bss(struct wiphy *wiphy,
1012 struct net_device *dev,
1013 struct bss_parameters *params)
1014{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001015 struct ieee80211_sub_if_data *sdata;
1016 u32 changed = 0;
1017
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001018 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1019
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001020 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001021 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001022 changed |= BSS_CHANGED_ERP_CTS_PROT;
1023 }
1024 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001025 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001026 params->use_short_preamble;
1027 changed |= BSS_CHANGED_ERP_PREAMBLE;
1028 }
Felix Fietkau43d35342010-01-15 03:00:48 +01001029
1030 if (!sdata->vif.bss_conf.use_short_slot &&
1031 sdata->local->hw.conf.channel->band == IEEE80211_BAND_5GHZ) {
1032 sdata->vif.bss_conf.use_short_slot = true;
1033 changed |= BSS_CHANGED_ERP_SLOT;
1034 }
1035
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001036 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001037 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001038 params->use_short_slot_time;
1039 changed |= BSS_CHANGED_ERP_SLOT;
1040 }
1041
Jouni Malinen90c97a02008-10-30 16:59:22 +02001042 if (params->basic_rates) {
1043 int i, j;
1044 u32 rates = 0;
1045 struct ieee80211_local *local = wiphy_priv(wiphy);
1046 struct ieee80211_supported_band *sband =
1047 wiphy->bands[local->oper_channel->band];
1048
1049 for (i = 0; i < params->basic_rates_len; i++) {
1050 int rate = (params->basic_rates[i] & 0x7f) * 5;
1051 for (j = 0; j < sband->n_bitrates; j++) {
1052 if (sband->bitrates[j].bitrate == rate)
1053 rates |= BIT(j);
1054 }
1055 }
1056 sdata->vif.bss_conf.basic_rates = rates;
1057 changed |= BSS_CHANGED_BASIC_RATES;
1058 }
1059
Felix Fietkau7b7b5e52010-04-27 01:23:36 +02001060 if (params->ap_isolate >= 0) {
1061 if (params->ap_isolate)
1062 sdata->flags |= IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1063 else
1064 sdata->flags &= ~IEEE80211_SDATA_DONT_BRIDGE_PACKETS;
1065 }
1066
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001067 ieee80211_bss_info_change_notify(sdata, changed);
1068
1069 return 0;
1070}
1071
Jouni Malinen31888482008-10-30 16:59:24 +02001072static int ieee80211_set_txq_params(struct wiphy *wiphy,
1073 struct ieee80211_txq_params *params)
1074{
1075 struct ieee80211_local *local = wiphy_priv(wiphy);
1076 struct ieee80211_tx_queue_params p;
1077
1078 if (!local->ops->conf_tx)
1079 return -EOPNOTSUPP;
1080
1081 memset(&p, 0, sizeof(p));
1082 p.aifs = params->aifs;
1083 p.cw_max = params->cwmax;
1084 p.cw_min = params->cwmin;
1085 p.txop = params->txop;
Kalle Valoab133152010-01-12 10:42:31 +02001086
1087 /*
1088 * Setting tx queue params disables u-apsd because it's only
1089 * called in master mode.
1090 */
1091 p.uapsd = false;
1092
Johannes Berg24487982009-04-23 18:52:52 +02001093 if (drv_conf_tx(local, params->queue, &p)) {
Joe Perches0fb9a9e2010-08-20 16:25:38 -07001094 wiphy_debug(local->hw.wiphy,
1095 "failed to set TX queue parameters for queue %d\n",
1096 params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001097 return -EINVAL;
1098 }
1099
1100 return 0;
1101}
1102
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001103static int ieee80211_set_channel(struct wiphy *wiphy,
Johannes Bergf444de02010-05-05 15:25:02 +02001104 struct net_device *netdev,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001105 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301106 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001107{
1108 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg0aaffa92010-05-05 15:28:27 +02001109 struct ieee80211_sub_if_data *sdata = NULL;
1110
1111 if (netdev)
1112 sdata = IEEE80211_DEV_TO_SUB_IF(netdev);
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001113
Johannes Bergf444de02010-05-05 15:25:02 +02001114 switch (ieee80211_get_channel_mode(local, NULL)) {
1115 case CHAN_MODE_HOPPING:
1116 return -EBUSY;
1117 case CHAN_MODE_FIXED:
Johannes Berg0aaffa92010-05-05 15:28:27 +02001118 if (local->oper_channel != chan)
1119 return -EBUSY;
1120 if (!sdata && local->_oper_channel_type == channel_type)
Johannes Bergf444de02010-05-05 15:25:02 +02001121 return 0;
Johannes Berg0aaffa92010-05-05 15:28:27 +02001122 break;
Johannes Bergf444de02010-05-05 15:25:02 +02001123 case CHAN_MODE_UNDEFINED:
1124 break;
1125 }
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001126
1127 local->oper_channel = chan;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001128
Johannes Berg0aaffa92010-05-05 15:28:27 +02001129 if (!ieee80211_set_channel_type(local, sdata, channel_type))
1130 return -EBUSY;
1131
1132 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1133 if (sdata && sdata->vif.type != NL80211_IFTYPE_MONITOR)
1134 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_HT);
1135
1136 return 0;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001137}
1138
Bob Copeland665af4f2009-01-19 11:20:53 -05001139#ifdef CONFIG_PM
1140static int ieee80211_suspend(struct wiphy *wiphy)
1141{
1142 return __ieee80211_suspend(wiphy_priv(wiphy));
1143}
1144
1145static int ieee80211_resume(struct wiphy *wiphy)
1146{
1147 return __ieee80211_resume(wiphy_priv(wiphy));
1148}
1149#else
1150#define ieee80211_suspend NULL
1151#define ieee80211_resume NULL
1152#endif
1153
Johannes Berg2a519312009-02-10 21:25:55 +01001154static int ieee80211_scan(struct wiphy *wiphy,
1155 struct net_device *dev,
1156 struct cfg80211_scan_request *req)
1157{
1158 struct ieee80211_sub_if_data *sdata;
1159
Johannes Berg2a519312009-02-10 21:25:55 +01001160 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1161
1162 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1163 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Jouni Malinen357303e2009-04-16 18:44:53 +03001164 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1165 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
Johannes Berg2a519312009-02-10 21:25:55 +01001166 return -EOPNOTSUPP;
1167
1168 return ieee80211_request_scan(sdata, req);
1169}
1170
Jouni Malinen636a5d32009-03-19 13:39:22 +02001171static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1172 struct cfg80211_auth_request *req)
1173{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001174 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001175}
1176
1177static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1178 struct cfg80211_assoc_request *req)
1179{
Johannes Bergf444de02010-05-05 15:25:02 +02001180 struct ieee80211_local *local = wiphy_priv(wiphy);
1181 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1182
1183 switch (ieee80211_get_channel_mode(local, sdata)) {
1184 case CHAN_MODE_HOPPING:
1185 return -EBUSY;
1186 case CHAN_MODE_FIXED:
1187 if (local->oper_channel == req->bss->channel)
1188 break;
1189 return -EBUSY;
1190 case CHAN_MODE_UNDEFINED:
1191 break;
1192 }
1193
Johannes Berg77fdaa12009-07-07 03:45:17 +02001194 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001195}
1196
1197static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001198 struct cfg80211_deauth_request *req,
1199 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001200{
Johannes Berg667503dd2009-07-07 03:56:11 +02001201 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1202 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001203}
1204
1205static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001206 struct cfg80211_disassoc_request *req,
1207 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001208{
Johannes Berg667503dd2009-07-07 03:56:11 +02001209 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1210 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001211}
1212
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001213static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1214 struct cfg80211_ibss_params *params)
1215{
Johannes Bergf444de02010-05-05 15:25:02 +02001216 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001217 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1218
Johannes Bergf444de02010-05-05 15:25:02 +02001219 switch (ieee80211_get_channel_mode(local, sdata)) {
1220 case CHAN_MODE_HOPPING:
1221 return -EBUSY;
1222 case CHAN_MODE_FIXED:
1223 if (!params->channel_fixed)
1224 return -EBUSY;
1225 if (local->oper_channel == params->channel)
1226 break;
1227 return -EBUSY;
1228 case CHAN_MODE_UNDEFINED:
1229 break;
1230 }
1231
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001232 return ieee80211_ibss_join(sdata, params);
1233}
1234
1235static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1236{
1237 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1238
1239 return ieee80211_ibss_leave(sdata);
1240}
1241
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001242static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1243{
1244 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001245 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001246
Lukáš Turek310bc672009-12-21 22:50:48 +01001247 if (changed & WIPHY_PARAM_COVERAGE_CLASS) {
1248 err = drv_set_coverage_class(local, wiphy->coverage_class);
1249
1250 if (err)
1251 return err;
1252 }
1253
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001254 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001255 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001256
Johannes Berg24487982009-04-23 18:52:52 +02001257 if (err)
1258 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001259 }
1260
1261 if (changed & WIPHY_PARAM_RETRY_SHORT)
1262 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1263 if (changed & WIPHY_PARAM_RETRY_LONG)
1264 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1265 if (changed &
1266 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1267 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1268
1269 return 0;
1270}
1271
Johannes Berg7643a2c2009-06-02 13:01:39 +02001272static int ieee80211_set_tx_power(struct wiphy *wiphy,
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001273 enum nl80211_tx_power_setting type, int mbm)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001274{
1275 struct ieee80211_local *local = wiphy_priv(wiphy);
1276 struct ieee80211_channel *chan = local->hw.conf.channel;
1277 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001278
1279 switch (type) {
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001280 case NL80211_TX_POWER_AUTOMATIC:
Johannes Berg7643a2c2009-06-02 13:01:39 +02001281 local->user_power_level = -1;
1282 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001283 case NL80211_TX_POWER_LIMITED:
1284 if (mbm < 0 || (mbm % 100))
1285 return -EOPNOTSUPP;
1286 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001287 break;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001288 case NL80211_TX_POWER_FIXED:
1289 if (mbm < 0 || (mbm % 100))
1290 return -EOPNOTSUPP;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001291 /* TODO: move to cfg80211 when it knows the channel */
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001292 if (MBM_TO_DBM(mbm) > chan->max_power)
Johannes Berg7643a2c2009-06-02 13:01:39 +02001293 return -EINVAL;
Juuso Oikarinenfa61cf72010-06-23 12:12:37 +03001294 local->user_power_level = MBM_TO_DBM(mbm);
Johannes Berg7643a2c2009-06-02 13:01:39 +02001295 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001296 }
1297
1298 ieee80211_hw_config(local, changes);
1299
1300 return 0;
1301}
1302
1303static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1304{
1305 struct ieee80211_local *local = wiphy_priv(wiphy);
1306
1307 *dbm = local->hw.conf.power_level;
1308
Johannes Berg7643a2c2009-06-02 13:01:39 +02001309 return 0;
1310}
1311
Johannes Bergab737a42009-07-01 21:26:58 +02001312static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1313 u8 *addr)
1314{
1315 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1316
1317 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1318
1319 return 0;
1320}
1321
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001322static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1323{
1324 struct ieee80211_local *local = wiphy_priv(wiphy);
1325
1326 drv_rfkill_poll(local);
1327}
1328
Johannes Bergaff89a92009-07-01 21:26:51 +02001329#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001330static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001331{
1332 struct ieee80211_local *local = wiphy_priv(wiphy);
1333
1334 if (!local->ops->testmode_cmd)
1335 return -EOPNOTSUPP;
1336
1337 return local->ops->testmode_cmd(&local->hw, data, len);
1338}
1339#endif
1340
Johannes Berg0f782312009-12-01 13:37:02 +01001341int __ieee80211_request_smps(struct ieee80211_sub_if_data *sdata,
1342 enum ieee80211_smps_mode smps_mode)
1343{
1344 const u8 *ap;
1345 enum ieee80211_smps_mode old_req;
1346 int err;
1347
1348 old_req = sdata->u.mgd.req_smps;
1349 sdata->u.mgd.req_smps = smps_mode;
1350
1351 if (old_req == smps_mode &&
1352 smps_mode != IEEE80211_SMPS_AUTOMATIC)
1353 return 0;
1354
1355 /*
1356 * If not associated, or current association is not an HT
1357 * association, there's no need to send an action frame.
1358 */
1359 if (!sdata->u.mgd.associated ||
Johannes Berg0aaffa92010-05-05 15:28:27 +02001360 sdata->vif.bss_conf.channel_type == NL80211_CHAN_NO_HT) {
Johannes Berg0f782312009-12-01 13:37:02 +01001361 mutex_lock(&sdata->local->iflist_mtx);
1362 ieee80211_recalc_smps(sdata->local, sdata);
1363 mutex_unlock(&sdata->local->iflist_mtx);
1364 return 0;
1365 }
1366
Johannes Berg0c1ad2c2009-12-23 13:15:39 +01001367 ap = sdata->u.mgd.associated->bssid;
Johannes Berg0f782312009-12-01 13:37:02 +01001368
1369 if (smps_mode == IEEE80211_SMPS_AUTOMATIC) {
1370 if (sdata->u.mgd.powersave)
1371 smps_mode = IEEE80211_SMPS_DYNAMIC;
1372 else
1373 smps_mode = IEEE80211_SMPS_OFF;
1374 }
1375
1376 /* send SM PS frame to AP */
1377 err = ieee80211_send_smps_action(sdata, smps_mode,
1378 ap, ap);
1379 if (err)
1380 sdata->u.mgd.req_smps = old_req;
1381
1382 return err;
1383}
1384
Johannes Bergbc92afd2009-07-01 21:26:57 +02001385static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1386 bool enabled, int timeout)
1387{
1388 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1389 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergbc92afd2009-07-01 21:26:57 +02001390
Benoit Papillaulte5de30c2010-01-15 12:21:37 +01001391 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1392 return -EOPNOTSUPP;
1393
Johannes Bergbc92afd2009-07-01 21:26:57 +02001394 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1395 return -EOPNOTSUPP;
1396
1397 if (enabled == sdata->u.mgd.powersave &&
Juuso Oikarinenff616382010-06-09 09:51:52 +03001398 timeout == local->dynamic_ps_forced_timeout)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001399 return 0;
1400
1401 sdata->u.mgd.powersave = enabled;
Juuso Oikarinenff616382010-06-09 09:51:52 +03001402 local->dynamic_ps_forced_timeout = timeout;
Johannes Bergbc92afd2009-07-01 21:26:57 +02001403
Johannes Berg0f782312009-12-01 13:37:02 +01001404 /* no change, but if automatic follow powersave */
1405 mutex_lock(&sdata->u.mgd.mtx);
1406 __ieee80211_request_smps(sdata, sdata->u.mgd.req_smps);
1407 mutex_unlock(&sdata->u.mgd.mtx);
1408
Johannes Bergbc92afd2009-07-01 21:26:57 +02001409 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1410 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1411
1412 ieee80211_recalc_ps(local, -1);
1413
1414 return 0;
1415}
1416
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001417static int ieee80211_set_cqm_rssi_config(struct wiphy *wiphy,
1418 struct net_device *dev,
1419 s32 rssi_thold, u32 rssi_hyst)
1420{
1421 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1422 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1423 struct ieee80211_vif *vif = &sdata->vif;
1424 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1425
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001426 if (rssi_thold == bss_conf->cqm_rssi_thold &&
1427 rssi_hyst == bss_conf->cqm_rssi_hyst)
1428 return 0;
1429
1430 bss_conf->cqm_rssi_thold = rssi_thold;
1431 bss_conf->cqm_rssi_hyst = rssi_hyst;
1432
Jouni Malinen17e4ec12010-03-29 23:28:30 -07001433 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_CQM_RSSI)) {
1434 if (sdata->vif.type != NL80211_IFTYPE_STATION)
1435 return -EOPNOTSUPP;
1436 return 0;
1437 }
1438
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001439 /* tell the driver upon association, unless already associated */
1440 if (sdata->u.mgd.associated)
1441 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_CQM);
1442
1443 return 0;
1444}
1445
Johannes Berg99303802009-07-01 21:26:59 +02001446static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1447 struct net_device *dev,
1448 const u8 *addr,
1449 const struct cfg80211_bitrate_mask *mask)
1450{
1451 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1452 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001453 int i;
Johannes Berg99303802009-07-01 21:26:59 +02001454
Johannes Berg2c7e6bc2009-12-04 09:26:38 +01001455 /*
1456 * This _could_ be supported by providing a hook for
1457 * drivers for this function, but at this point it
1458 * doesn't seem worth bothering.
1459 */
1460 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL)
1461 return -EOPNOTSUPP;
1462
Johannes Berg99303802009-07-01 21:26:59 +02001463
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001464 for (i = 0; i < IEEE80211_NUM_BANDS; i++)
1465 sdata->rc_rateidx_mask[i] = mask->control[i].legacy;
Johannes Berg99303802009-07-01 21:26:59 +02001466
Jouni Malinen37eb0b12010-01-06 13:09:08 +02001467 return 0;
Johannes Berg99303802009-07-01 21:26:59 +02001468}
1469
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001470static int ieee80211_remain_on_channel(struct wiphy *wiphy,
1471 struct net_device *dev,
1472 struct ieee80211_channel *chan,
1473 enum nl80211_channel_type channel_type,
1474 unsigned int duration,
1475 u64 *cookie)
1476{
1477 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1478
1479 return ieee80211_wk_remain_on_channel(sdata, chan, channel_type,
1480 duration, cookie);
1481}
1482
1483static int ieee80211_cancel_remain_on_channel(struct wiphy *wiphy,
1484 struct net_device *dev,
1485 u64 cookie)
1486{
1487 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1488
1489 return ieee80211_wk_cancel_remain_on_channel(sdata, cookie);
1490}
1491
Johannes Berg2e161f72010-08-12 15:38:38 +02001492static int ieee80211_mgmt_tx(struct wiphy *wiphy, struct net_device *dev,
1493 struct ieee80211_channel *chan,
1494 enum nl80211_channel_type channel_type,
1495 bool channel_type_valid,
1496 const u8 *buf, size_t len, u64 *cookie)
Jouni Malinen026331c2010-02-15 12:53:10 +02001497{
Johannes Berg9d38d852010-06-09 17:20:33 +02001498 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1499 struct ieee80211_local *local = sdata->local;
1500 struct sk_buff *skb;
1501 struct sta_info *sta;
1502 const struct ieee80211_mgmt *mgmt = (void *)buf;
1503 u32 flags = IEEE80211_TX_INTFL_NL80211_FRAME_TX |
1504 IEEE80211_TX_CTL_REQ_TX_STATUS;
1505
1506 /* Check that we are on the requested channel for transmission */
1507 if (chan != local->tmp_channel &&
1508 chan != local->oper_channel)
1509 return -EBUSY;
1510 if (channel_type_valid &&
1511 (channel_type != local->tmp_channel_type &&
1512 channel_type != local->_oper_channel_type))
1513 return -EBUSY;
1514
1515 switch (sdata->vif.type) {
1516 case NL80211_IFTYPE_ADHOC:
1517 if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC)
1518 break;
1519 rcu_read_lock();
1520 sta = sta_info_get(sdata, mgmt->da);
1521 rcu_read_unlock();
1522 if (!sta)
1523 return -ENOLINK;
1524 break;
1525 case NL80211_IFTYPE_STATION:
Johannes Berg9d38d852010-06-09 17:20:33 +02001526 break;
1527 default:
1528 return -EOPNOTSUPP;
1529 }
1530
1531 skb = dev_alloc_skb(local->hw.extra_tx_headroom + len);
1532 if (!skb)
1533 return -ENOMEM;
1534 skb_reserve(skb, local->hw.extra_tx_headroom);
1535
1536 memcpy(skb_put(skb, len), buf, len);
1537
1538 IEEE80211_SKB_CB(skb)->flags = flags;
1539
1540 skb->dev = sdata->dev;
1541 ieee80211_tx_skb(sdata, skb);
1542
1543 *cookie = (unsigned long) skb;
1544 return 0;
Jouni Malinen026331c2010-02-15 12:53:10 +02001545}
1546
Jiri Bencf0706e82007-05-05 11:45:53 -07001547struct cfg80211_ops mac80211_config_ops = {
1548 .add_virtual_intf = ieee80211_add_iface,
1549 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001550 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001551 .add_key = ieee80211_add_key,
1552 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001553 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001554 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001555 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001556 .add_beacon = ieee80211_add_beacon,
1557 .set_beacon = ieee80211_set_beacon,
1558 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001559 .add_station = ieee80211_add_station,
1560 .del_station = ieee80211_del_station,
1561 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001562 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001563 .dump_station = ieee80211_dump_station,
Holger Schurig12897232010-04-19 10:23:57 +02001564 .dump_survey = ieee80211_dump_survey,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001565#ifdef CONFIG_MAC80211_MESH
1566 .add_mpath = ieee80211_add_mpath,
1567 .del_mpath = ieee80211_del_mpath,
1568 .change_mpath = ieee80211_change_mpath,
1569 .get_mpath = ieee80211_get_mpath,
1570 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001571 .set_mesh_params = ieee80211_set_mesh_params,
1572 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001573#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001574 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001575 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001576 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001577 .suspend = ieee80211_suspend,
1578 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001579 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001580 .auth = ieee80211_auth,
1581 .assoc = ieee80211_assoc,
1582 .deauth = ieee80211_deauth,
1583 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001584 .join_ibss = ieee80211_join_ibss,
1585 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001586 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02001587 .set_tx_power = ieee80211_set_tx_power,
1588 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02001589 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001590 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02001591 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001592 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02001593 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Johannes Bergb8bc4b02009-12-23 13:15:42 +01001594 .remain_on_channel = ieee80211_remain_on_channel,
1595 .cancel_remain_on_channel = ieee80211_cancel_remain_on_channel,
Johannes Berg2e161f72010-08-12 15:38:38 +02001596 .mgmt_tx = ieee80211_mgmt_tx,
Juuso Oikarinena97c13c2010-03-23 09:02:34 +02001597 .set_cqm_rssi_config = ieee80211_set_cqm_rssi_config,
Jiri Bencf0706e82007-05-05 11:45:53 -07001598};