blob: 4bbf5007799b53025d79eefe7889168e518d1ba8 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * mac80211 configuration hooks for cfg80211
3 *
Johannes Berg62da92f2007-12-19 02:03:31 +01004 * Copyright 2006, 2007 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>
Eric W. Biederman881d9662007-09-17 11:56:21 -070012#include <net/net_namespace.h>
Johannes Berg5dfdaf52007-12-19 02:03:33 +010013#include <linux/rcupdate.h>
Jiri Bencf0706e82007-05-05 11:45:53 -070014#include <net/cfg80211.h>
15#include "ieee80211_i.h"
Johannes Berg24487982009-04-23 18:52:52 +020016#include "driver-ops.h"
Michael Wue0eb6852007-09-18 17:29:21 -040017#include "cfg.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040018#include "rate.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010019#include "mesh.h"
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010020
Johannes Berg05c914f2008-09-11 00:01:58 +020021static bool nl80211_type_check(enum nl80211_iftype type)
Johannes Berg42613db2007-09-28 21:52:27 +020022{
23 switch (type) {
Johannes Berg42613db2007-09-28 21:52:27 +020024 case NL80211_IFTYPE_ADHOC:
Johannes Berg42613db2007-09-28 21:52:27 +020025 case NL80211_IFTYPE_STATION:
Johannes Berg42613db2007-09-28 21:52:27 +020026 case NL80211_IFTYPE_MONITOR:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010027#ifdef CONFIG_MAC80211_MESH
28 case NL80211_IFTYPE_MESH_POINT:
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010029#endif
Jouni Malinenfbf18922008-10-30 19:50:30 +020030 case NL80211_IFTYPE_AP:
31 case NL80211_IFTYPE_AP_VLAN:
Johannes Bergb4540482008-04-14 15:37:03 +020032 case NL80211_IFTYPE_WDS:
Johannes Berg05c914f2008-09-11 00:01:58 +020033 return true;
Johannes Berg42613db2007-09-28 21:52:27 +020034 default:
Johannes Berg05c914f2008-09-11 00:01:58 +020035 return false;
Johannes Berg42613db2007-09-28 21:52:27 +020036 }
37}
38
Jiri Bencf0706e82007-05-05 11:45:53 -070039static int ieee80211_add_iface(struct wiphy *wiphy, char *name,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010040 enum nl80211_iftype type, u32 *flags,
41 struct vif_params *params)
Jiri Bencf0706e82007-05-05 11:45:53 -070042{
43 struct ieee80211_local *local = wiphy_priv(wiphy);
Michael Wu8cc9a732008-01-31 19:48:23 +010044 struct net_device *dev;
45 struct ieee80211_sub_if_data *sdata;
46 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070047
Johannes Berg05c914f2008-09-11 00:01:58 +020048 if (!nl80211_type_check(type))
Jiri Bencf0706e82007-05-05 11:45:53 -070049 return -EINVAL;
Jiri Bencf0706e82007-05-05 11:45:53 -070050
Johannes Berg05c914f2008-09-11 00:01:58 +020051 err = ieee80211_if_add(local, name, &dev, type, params);
52 if (err || type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010053 return err;
54
55 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
56 sdata->u.mntr_flags = *flags;
57 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070058}
59
Johannes Berg463d0182009-07-14 00:33:35 +020060static int ieee80211_del_iface(struct wiphy *wiphy, struct net_device *dev)
Jiri Bencf0706e82007-05-05 11:45:53 -070061{
Johannes Berg463d0182009-07-14 00:33:35 +020062 ieee80211_if_remove(IEEE80211_DEV_TO_SUB_IF(dev));
Jiri Bencf0706e82007-05-05 11:45:53 -070063
Johannes Berg75636522008-07-09 14:40:35 +020064 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070065}
66
Johannes Berge36d56b2009-06-09 21:04:43 +020067static int ieee80211_change_iface(struct wiphy *wiphy,
68 struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +010069 enum nl80211_iftype type, u32 *flags,
70 struct vif_params *params)
Johannes Berg42613db2007-09-28 21:52:27 +020071{
Johannes Berg42613db2007-09-28 21:52:27 +020072 struct ieee80211_sub_if_data *sdata;
Johannes Bergf3947e22008-07-09 14:40:36 +020073 int ret;
Johannes Berg42613db2007-09-28 21:52:27 +020074
Johannes Berg05c914f2008-09-11 00:01:58 +020075 if (!nl80211_type_check(type))
Johannes Berg42613db2007-09-28 21:52:27 +020076 return -EINVAL;
77
78 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
79
Johannes Berg05c914f2008-09-11 00:01:58 +020080 ret = ieee80211_if_change_type(sdata, type);
Johannes Bergf3947e22008-07-09 14:40:36 +020081 if (ret)
82 return ret;
Johannes Berg42613db2007-09-28 21:52:27 +020083
Johannes Bergf8b25cd2008-09-16 20:22:21 +020084 if (netif_running(sdata->dev))
85 return -EBUSY;
86
Johannes Berg902acc72008-02-23 15:17:19 +010087 if (ieee80211_vif_is_mesh(&sdata->vif) && params->mesh_id_len)
Johannes Berg472dbc42008-09-11 00:01:49 +020088 ieee80211_sdata_set_mesh_id(sdata,
89 params->mesh_id_len,
90 params->mesh_id);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +010091
Johannes Berg05c914f2008-09-11 00:01:58 +020092 if (sdata->vif.type != NL80211_IFTYPE_MONITOR || !flags)
Michael Wu8cc9a732008-01-31 19:48:23 +010093 return 0;
94
95 sdata->u.mntr_flags = *flags;
Johannes Berg42613db2007-09-28 21:52:27 +020096 return 0;
97}
98
Johannes Berge8cbb4c2007-12-19 02:03:30 +010099static int ieee80211_add_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200100 u8 key_idx, const u8 *mac_addr,
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100101 struct key_params *params)
102{
103 struct ieee80211_sub_if_data *sdata;
104 struct sta_info *sta = NULL;
105 enum ieee80211_key_alg alg;
Johannes Bergdb4d1162008-02-25 16:27:45 +0100106 struct ieee80211_key *key;
Johannes Berg3b967662008-04-08 17:56:52 +0200107 int err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100108
109 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
110
111 switch (params->cipher) {
112 case WLAN_CIPHER_SUITE_WEP40:
113 case WLAN_CIPHER_SUITE_WEP104:
114 alg = ALG_WEP;
115 break;
116 case WLAN_CIPHER_SUITE_TKIP:
117 alg = ALG_TKIP;
118 break;
119 case WLAN_CIPHER_SUITE_CCMP:
120 alg = ALG_CCMP;
121 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200122 case WLAN_CIPHER_SUITE_AES_CMAC:
123 alg = ALG_AES_CMAC;
124 break;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100125 default:
126 return -EINVAL;
127 }
128
Jouni Malinenfaa8fdc2009-05-11 21:57:58 +0300129 key = ieee80211_key_alloc(alg, key_idx, params->key_len, params->key,
130 params->seq_len, params->seq);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100131 if (!key)
132 return -ENOMEM;
133
Johannes Berg3b967662008-04-08 17:56:52 +0200134 rcu_read_lock();
135
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100136 if (mac_addr) {
137 sta = sta_info_get(sdata->local, mac_addr);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100138 if (!sta) {
139 ieee80211_key_free(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 Bergdb4d1162008-02-25 16:27:45 +0100145 ieee80211_key_link(key, sdata, sta);
146
Johannes Berg3b967662008-04-08 17:56:52 +0200147 err = 0;
148 out_unlock:
149 rcu_read_unlock();
150
151 return err;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100152}
153
154static int ieee80211_del_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200155 u8 key_idx, const u8 *mac_addr)
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100156{
157 struct ieee80211_sub_if_data *sdata;
158 struct sta_info *sta;
159 int ret;
160
161 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
162
Johannes Berg3b967662008-04-08 17:56:52 +0200163 rcu_read_lock();
164
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100165 if (mac_addr) {
Johannes Berg3b967662008-04-08 17:56:52 +0200166 ret = -ENOENT;
167
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100168 sta = sta_info_get(sdata->local, mac_addr);
169 if (!sta)
Johannes Berg3b967662008-04-08 17:56:52 +0200170 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100171
Johannes Bergdb4d1162008-02-25 16:27:45 +0100172 if (sta->key) {
Johannes Bergd0709a62008-02-25 16:27:46 +0100173 ieee80211_key_free(sta->key);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100174 WARN_ON(sta->key);
Johannes Berg3b967662008-04-08 17:56:52 +0200175 ret = 0;
176 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100177
Johannes Berg3b967662008-04-08 17:56:52 +0200178 goto out_unlock;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100179 }
180
Johannes Berg3b967662008-04-08 17:56:52 +0200181 if (!sdata->keys[key_idx]) {
182 ret = -ENOENT;
183 goto out_unlock;
184 }
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100185
Johannes Bergd0709a62008-02-25 16:27:46 +0100186 ieee80211_key_free(sdata->keys[key_idx]);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100187 WARN_ON(sdata->keys[key_idx]);
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100188
Johannes Berg3b967662008-04-08 17:56:52 +0200189 ret = 0;
190 out_unlock:
191 rcu_read_unlock();
192
193 return ret;
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100194}
195
Johannes Berg62da92f2007-12-19 02:03:31 +0100196static int ieee80211_get_key(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg4e943902009-05-09 20:06:47 +0200197 u8 key_idx, const u8 *mac_addr, void *cookie,
Johannes Berg62da92f2007-12-19 02:03:31 +0100198 void (*callback)(void *cookie,
199 struct key_params *params))
200{
Johannes Berg14db74b2008-07-29 13:22:52 +0200201 struct ieee80211_sub_if_data *sdata;
Johannes Berg62da92f2007-12-19 02:03:31 +0100202 struct sta_info *sta = NULL;
203 u8 seq[6] = {0};
204 struct key_params params;
205 struct ieee80211_key *key;
206 u32 iv32;
207 u16 iv16;
208 int err = -ENOENT;
209
Johannes Berg14db74b2008-07-29 13:22:52 +0200210 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
211
Johannes Berg3b967662008-04-08 17:56:52 +0200212 rcu_read_lock();
213
Johannes Berg62da92f2007-12-19 02:03:31 +0100214 if (mac_addr) {
215 sta = sta_info_get(sdata->local, mac_addr);
216 if (!sta)
217 goto out;
218
219 key = sta->key;
220 } else
221 key = sdata->keys[key_idx];
222
223 if (!key)
224 goto out;
225
226 memset(&params, 0, sizeof(params));
227
228 switch (key->conf.alg) {
229 case ALG_TKIP:
230 params.cipher = WLAN_CIPHER_SUITE_TKIP;
231
Harvey Harrisonb0f76b32008-05-14 16:26:19 -0700232 iv32 = key->u.tkip.tx.iv32;
233 iv16 = key->u.tkip.tx.iv16;
Johannes Berg62da92f2007-12-19 02:03:31 +0100234
Johannes Berg24487982009-04-23 18:52:52 +0200235 if (key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
236 drv_get_tkip_seq(sdata->local,
237 key->conf.hw_key_idx,
238 &iv32, &iv16);
Johannes Berg62da92f2007-12-19 02:03:31 +0100239
240 seq[0] = iv16 & 0xff;
241 seq[1] = (iv16 >> 8) & 0xff;
242 seq[2] = iv32 & 0xff;
243 seq[3] = (iv32 >> 8) & 0xff;
244 seq[4] = (iv32 >> 16) & 0xff;
245 seq[5] = (iv32 >> 24) & 0xff;
246 params.seq = seq;
247 params.seq_len = 6;
248 break;
249 case ALG_CCMP:
250 params.cipher = WLAN_CIPHER_SUITE_CCMP;
251 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;
260 case ALG_WEP:
261 if (key->conf.keylen == 5)
262 params.cipher = WLAN_CIPHER_SUITE_WEP40;
263 else
264 params.cipher = WLAN_CIPHER_SUITE_WEP104;
265 break;
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200266 case ALG_AES_CMAC:
267 params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
268 seq[0] = key->u.aes_cmac.tx_pn[5];
269 seq[1] = key->u.aes_cmac.tx_pn[4];
270 seq[2] = key->u.aes_cmac.tx_pn[3];
271 seq[3] = key->u.aes_cmac.tx_pn[2];
272 seq[4] = key->u.aes_cmac.tx_pn[1];
273 seq[5] = key->u.aes_cmac.tx_pn[0];
274 params.seq = seq;
275 params.seq_len = 6;
276 break;
Johannes Berg62da92f2007-12-19 02:03:31 +0100277 }
278
279 params.key = key->conf.key;
280 params.key_len = key->conf.keylen;
281
282 callback(cookie, &params);
283 err = 0;
284
285 out:
Johannes Berg3b967662008-04-08 17:56:52 +0200286 rcu_read_unlock();
Johannes Berg62da92f2007-12-19 02:03:31 +0100287 return err;
288}
289
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100290static int ieee80211_config_default_key(struct wiphy *wiphy,
291 struct net_device *dev,
292 u8 key_idx)
293{
294 struct ieee80211_sub_if_data *sdata;
295
Johannes Berg3b967662008-04-08 17:56:52 +0200296 rcu_read_lock();
297
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100298 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
299 ieee80211_set_default_key(sdata, key_idx);
300
Johannes Berg3b967662008-04-08 17:56:52 +0200301 rcu_read_unlock();
302
Johannes Berge8cbb4c2007-12-19 02:03:30 +0100303 return 0;
304}
305
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +0200306static int ieee80211_config_default_mgmt_key(struct wiphy *wiphy,
307 struct net_device *dev,
308 u8 key_idx)
309{
310 struct ieee80211_sub_if_data *sdata;
311
312 rcu_read_lock();
313
314 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
315 ieee80211_set_default_mgmt_key(sdata, key_idx);
316
317 rcu_read_unlock();
318
319 return 0;
320}
321
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100322static void sta_set_sinfo(struct sta_info *sta, struct station_info *sinfo)
323{
Johannes Bergd0709a62008-02-25 16:27:46 +0100324 struct ieee80211_sub_if_data *sdata = sta->sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100325
326 sinfo->filled = STATION_INFO_INACTIVE_TIME |
327 STATION_INFO_RX_BYTES |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100328 STATION_INFO_TX_BYTES |
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200329 STATION_INFO_RX_PACKETS |
330 STATION_INFO_TX_PACKETS |
Henning Rogge420e7fa2008-12-11 22:04:19 +0100331 STATION_INFO_TX_BITRATE;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100332
333 sinfo->inactive_time = jiffies_to_msecs(jiffies - sta->last_rx);
334 sinfo->rx_bytes = sta->rx_bytes;
335 sinfo->tx_bytes = sta->tx_bytes;
Jouni Malinen98c8a60a2009-02-17 13:24:57 +0200336 sinfo->rx_packets = sta->rx_packets;
337 sinfo->tx_packets = sta->tx_packets;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100338
Henning Rogge420e7fa2008-12-11 22:04:19 +0100339 if (sta->local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
340 sinfo->filled |= STATION_INFO_SIGNAL;
341 sinfo->signal = (s8)sta->last_signal;
342 }
343
344 sinfo->txrate.flags = 0;
345 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)
346 sinfo->txrate.flags |= RATE_INFO_FLAGS_MCS;
347 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_40_MHZ_WIDTH)
348 sinfo->txrate.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
349 if (sta->last_tx_rate.flags & IEEE80211_TX_RC_SHORT_GI)
350 sinfo->txrate.flags |= RATE_INFO_FLAGS_SHORT_GI;
351
352 if (!(sta->last_tx_rate.flags & IEEE80211_TX_RC_MCS)) {
353 struct ieee80211_supported_band *sband;
354 sband = sta->local->hw.wiphy->bands[
355 sta->local->hw.conf.channel->band];
356 sinfo->txrate.legacy =
357 sband->bitrates[sta->last_tx_rate.idx].bitrate;
358 } else
359 sinfo->txrate.mcs = sta->last_tx_rate.idx;
360
Johannes Berg902acc72008-02-23 15:17:19 +0100361 if (ieee80211_vif_is_mesh(&sdata->vif)) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100362#ifdef CONFIG_MAC80211_MESH
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100363 sinfo->filled |= STATION_INFO_LLID |
364 STATION_INFO_PLID |
365 STATION_INFO_PLINK_STATE;
366
367 sinfo->llid = le16_to_cpu(sta->llid);
368 sinfo->plid = le16_to_cpu(sta->plid);
369 sinfo->plink_state = sta->plink_state;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100370#endif
Johannes Berg902acc72008-02-23 15:17:19 +0100371 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100372}
373
374
375static int ieee80211_dump_station(struct wiphy *wiphy, struct net_device *dev,
376 int idx, u8 *mac, struct station_info *sinfo)
377{
378 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
379 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100380 int ret = -ENOENT;
381
382 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100383
384 sta = sta_info_get_by_idx(local, idx, dev);
Johannes Bergd0709a62008-02-25 16:27:46 +0100385 if (sta) {
386 ret = 0;
Johannes Berg17741cd2008-09-11 00:02:02 +0200387 memcpy(mac, sta->sta.addr, ETH_ALEN);
Johannes Bergd0709a62008-02-25 16:27:46 +0100388 sta_set_sinfo(sta, sinfo);
389 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100390
Johannes Bergd0709a62008-02-25 16:27:46 +0100391 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100392
Johannes Bergd0709a62008-02-25 16:27:46 +0100393 return ret;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100394}
395
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100396static int ieee80211_get_station(struct wiphy *wiphy, struct net_device *dev,
Luis Carlos Cobo2ec600d2008-02-23 15:17:06 +0100397 u8 *mac, struct station_info *sinfo)
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100398{
399 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
400 struct sta_info *sta;
Johannes Bergd0709a62008-02-25 16:27:46 +0100401 int ret = -ENOENT;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100402
Johannes Bergd0709a62008-02-25 16:27:46 +0100403 rcu_read_lock();
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100404
405 /* XXX: verify sta->dev == dev */
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100406
Johannes Bergd0709a62008-02-25 16:27:46 +0100407 sta = sta_info_get(local, mac);
408 if (sta) {
409 ret = 0;
410 sta_set_sinfo(sta, sinfo);
411 }
412
413 rcu_read_unlock();
414
415 return ret;
Johannes Berg7bbdd2d2007-12-19 02:03:37 +0100416}
417
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100418/*
419 * This handles both adding a beacon and setting new beacon info
420 */
421static int ieee80211_config_beacon(struct ieee80211_sub_if_data *sdata,
422 struct beacon_parameters *params)
423{
424 struct beacon_data *new, *old;
425 int new_head_len, new_tail_len;
426 int size;
427 int err = -EINVAL;
428
429 old = sdata->u.ap.beacon;
430
431 /* head must not be zero-length */
432 if (params->head && !params->head_len)
433 return -EINVAL;
434
435 /*
436 * This is a kludge. beacon interval should really be part
437 * of the beacon information.
438 */
Johannes Berg57c4d7b2009-04-23 16:10:04 +0200439 if (params->interval &&
440 (sdata->vif.bss_conf.beacon_int != params->interval)) {
441 sdata->vif.bss_conf.beacon_int = params->interval;
442 ieee80211_bss_info_change_notify(sdata,
443 BSS_CHANGED_BEACON_INT);
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100444 }
445
446 /* Need to have a beacon head if we don't have one yet */
447 if (!params->head && !old)
448 return err;
449
450 /* sorry, no way to start beaconing without dtim period */
451 if (!params->dtim_period && !old)
452 return err;
453
454 /* new or old head? */
455 if (params->head)
456 new_head_len = params->head_len;
457 else
458 new_head_len = old->head_len;
459
460 /* new or old tail? */
461 if (params->tail || !old)
462 /* params->tail_len will be zero for !params->tail */
463 new_tail_len = params->tail_len;
464 else
465 new_tail_len = old->tail_len;
466
467 size = sizeof(*new) + new_head_len + new_tail_len;
468
469 new = kzalloc(size, GFP_KERNEL);
470 if (!new)
471 return -ENOMEM;
472
473 /* start filling the new info now */
474
475 /* new or old dtim period? */
476 if (params->dtim_period)
477 new->dtim_period = params->dtim_period;
478 else
479 new->dtim_period = old->dtim_period;
480
481 /*
482 * pointers go into the block we allocated,
483 * memory is | beacon_data | head | tail |
484 */
485 new->head = ((u8 *) new) + sizeof(*new);
486 new->tail = new->head + new_head_len;
487 new->head_len = new_head_len;
488 new->tail_len = new_tail_len;
489
490 /* copy in head */
491 if (params->head)
492 memcpy(new->head, params->head, new_head_len);
493 else
494 memcpy(new->head, old->head, new_head_len);
495
496 /* copy in optional tail */
497 if (params->tail)
498 memcpy(new->tail, params->tail, new_tail_len);
499 else
500 if (old)
501 memcpy(new->tail, old->tail, new_tail_len);
502
503 rcu_assign_pointer(sdata->u.ap.beacon, new);
504
505 synchronize_rcu();
506
507 kfree(old);
508
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200509 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED |
510 BSS_CHANGED_BEACON);
511 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100512}
513
514static int ieee80211_add_beacon(struct wiphy *wiphy, struct net_device *dev,
515 struct beacon_parameters *params)
516{
Johannes Berg14db74b2008-07-29 13:22:52 +0200517 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100518 struct beacon_data *old;
519
Johannes Berg14db74b2008-07-29 13:22:52 +0200520 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
521
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100522 old = sdata->u.ap.beacon;
523
524 if (old)
525 return -EALREADY;
526
527 return ieee80211_config_beacon(sdata, params);
528}
529
530static int ieee80211_set_beacon(struct wiphy *wiphy, struct net_device *dev,
531 struct beacon_parameters *params)
532{
Johannes Berg14db74b2008-07-29 13:22:52 +0200533 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100534 struct beacon_data *old;
535
Johannes Berg14db74b2008-07-29 13:22:52 +0200536 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
537
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100538 old = sdata->u.ap.beacon;
539
540 if (!old)
541 return -ENOENT;
542
543 return ieee80211_config_beacon(sdata, params);
544}
545
546static int ieee80211_del_beacon(struct wiphy *wiphy, struct net_device *dev)
547{
Johannes Berg14db74b2008-07-29 13:22:52 +0200548 struct ieee80211_sub_if_data *sdata;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100549 struct beacon_data *old;
550
Johannes Berg14db74b2008-07-29 13:22:52 +0200551 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
552
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100553 old = sdata->u.ap.beacon;
554
555 if (!old)
556 return -ENOENT;
557
558 rcu_assign_pointer(sdata->u.ap.beacon, NULL);
559 synchronize_rcu();
560 kfree(old);
561
Johannes Berg2d0ddec2009-04-23 16:13:26 +0200562 ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BEACON_ENABLED);
563 return 0;
Johannes Berg5dfdaf52007-12-19 02:03:33 +0100564}
565
Johannes Berg4fd69312007-12-19 02:03:35 +0100566/* Layer 2 Update frame (802.2 Type 1 LLC XID Update response) */
567struct iapp_layer2_update {
568 u8 da[ETH_ALEN]; /* broadcast */
569 u8 sa[ETH_ALEN]; /* STA addr */
570 __be16 len; /* 6 */
571 u8 dsap; /* 0 */
572 u8 ssap; /* 0 */
573 u8 control;
574 u8 xid_info[3];
575} __attribute__ ((packed));
576
577static void ieee80211_send_layer2_update(struct sta_info *sta)
578{
579 struct iapp_layer2_update *msg;
580 struct sk_buff *skb;
581
582 /* Send Level 2 Update Frame to update forwarding tables in layer 2
583 * bridge devices */
584
585 skb = dev_alloc_skb(sizeof(*msg));
586 if (!skb)
587 return;
588 msg = (struct iapp_layer2_update *)skb_put(skb, sizeof(*msg));
589
590 /* 802.2 Type 1 Logical Link Control (LLC) Exchange Identifier (XID)
591 * Update response frame; IEEE Std 802.2-1998, 5.4.1.2.1 */
592
593 memset(msg->da, 0xff, ETH_ALEN);
Johannes Berg17741cd2008-09-11 00:02:02 +0200594 memcpy(msg->sa, sta->sta.addr, ETH_ALEN);
Johannes Berg4fd69312007-12-19 02:03:35 +0100595 msg->len = htons(6);
596 msg->dsap = 0;
597 msg->ssap = 0x01; /* NULL LSAP, CR Bit: Response */
598 msg->control = 0xaf; /* XID response lsb.1111F101.
599 * F=0 (no poll command; unsolicited frame) */
600 msg->xid_info[0] = 0x81; /* XID format identifier */
601 msg->xid_info[1] = 1; /* LLC types/classes: Type 1 LLC */
602 msg->xid_info[2] = 0; /* XID sender's receive window size (RW) */
603
Johannes Bergd0709a62008-02-25 16:27:46 +0100604 skb->dev = sta->sdata->dev;
605 skb->protocol = eth_type_trans(skb, sta->sdata->dev);
Johannes Berg4fd69312007-12-19 02:03:35 +0100606 memset(skb->cb, 0, sizeof(skb->cb));
607 netif_rx(skb);
608}
609
610static void sta_apply_parameters(struct ieee80211_local *local,
611 struct sta_info *sta,
612 struct station_parameters *params)
613{
614 u32 rates;
615 int i, j;
Johannes Berg8318d782008-01-24 19:38:38 +0100616 struct ieee80211_supported_band *sband;
Johannes Bergd0709a62008-02-25 16:27:46 +0100617 struct ieee80211_sub_if_data *sdata = sta->sdata;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300618 u32 mask, set;
Johannes Berg4fd69312007-12-19 02:03:35 +0100619
Johannes Bergae5eb022008-10-14 16:58:37 +0200620 sband = local->hw.wiphy->bands[local->oper_channel->band];
621
Johannes Bergeccb8e82009-05-11 21:57:56 +0300622 spin_lock_bh(&sta->lock);
623 mask = params->sta_flags_mask;
624 set = params->sta_flags_set;
Johannes Berg73651ee2008-02-25 16:27:47 +0100625
Johannes Bergeccb8e82009-05-11 21:57:56 +0300626 if (mask & BIT(NL80211_STA_FLAG_AUTHORIZED)) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100627 sta->flags &= ~WLAN_STA_AUTHORIZED;
Johannes Bergeccb8e82009-05-11 21:57:56 +0300628 if (set & BIT(NL80211_STA_FLAG_AUTHORIZED))
Johannes Berg4fd69312007-12-19 02:03:35 +0100629 sta->flags |= WLAN_STA_AUTHORIZED;
Johannes Berg4fd69312007-12-19 02:03:35 +0100630 }
631
Johannes Bergeccb8e82009-05-11 21:57:56 +0300632 if (mask & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE)) {
633 sta->flags &= ~WLAN_STA_SHORT_PREAMBLE;
634 if (set & BIT(NL80211_STA_FLAG_SHORT_PREAMBLE))
635 sta->flags |= WLAN_STA_SHORT_PREAMBLE;
636 }
637
638 if (mask & BIT(NL80211_STA_FLAG_WME)) {
639 sta->flags &= ~WLAN_STA_WME;
640 if (set & BIT(NL80211_STA_FLAG_WME))
641 sta->flags |= WLAN_STA_WME;
642 }
643
644 if (mask & BIT(NL80211_STA_FLAG_MFP)) {
645 sta->flags &= ~WLAN_STA_MFP;
646 if (set & BIT(NL80211_STA_FLAG_MFP))
647 sta->flags |= WLAN_STA_MFP;
648 }
649 spin_unlock_bh(&sta->lock);
650
Johannes Berg73651ee2008-02-25 16:27:47 +0100651 /*
Johannes Berg51b50fb2009-05-24 16:42:30 +0200652 * cfg80211 validates this (1-2007) and allows setting the AID
653 * only when creating a new station entry
654 */
655 if (params->aid)
656 sta->sta.aid = params->aid;
657
658 /*
Johannes Berg73651ee2008-02-25 16:27:47 +0100659 * FIXME: updating the following information is racy when this
660 * function is called from ieee80211_change_station().
661 * However, all this information should be static so
662 * maybe we should just reject attemps to change it.
663 */
664
Johannes Berg4fd69312007-12-19 02:03:35 +0100665 if (params->listen_interval >= 0)
666 sta->listen_interval = params->listen_interval;
667
668 if (params->supported_rates) {
669 rates = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100670
Johannes Berg4fd69312007-12-19 02:03:35 +0100671 for (i = 0; i < params->supported_rates_len; i++) {
672 int rate = (params->supported_rates[i] & 0x7f) * 5;
Johannes Berg8318d782008-01-24 19:38:38 +0100673 for (j = 0; j < sband->n_bitrates; j++) {
674 if (sband->bitrates[j].bitrate == rate)
Johannes Berg4fd69312007-12-19 02:03:35 +0100675 rates |= BIT(j);
676 }
677 }
Johannes Berg323ce792008-09-11 02:45:11 +0200678 sta->sta.supp_rates[local->oper_channel->band] = rates;
Johannes Berg4fd69312007-12-19 02:03:35 +0100679 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100680
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200681 if (params->ht_capa)
Johannes Bergae5eb022008-10-14 16:58:37 +0200682 ieee80211_ht_cap_ie_to_sta_ht_cap(sband,
683 params->ht_capa,
Johannes Bergd9fe60d2008-10-09 12:13:49 +0200684 &sta->sta.ht_cap);
Jouni Malinen36aedc902008-08-25 11:58:58 +0300685
Johannes Berg902acc72008-02-23 15:17:19 +0100686 if (ieee80211_vif_is_mesh(&sdata->vif) && params->plink_action) {
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100687 switch (params->plink_action) {
688 case PLINK_ACTION_OPEN:
689 mesh_plink_open(sta);
690 break;
691 case PLINK_ACTION_BLOCK:
692 mesh_plink_block(sta);
693 break;
694 }
Johannes Berg902acc72008-02-23 15:17:19 +0100695 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100696}
697
698static int ieee80211_add_station(struct wiphy *wiphy, struct net_device *dev,
699 u8 *mac, struct station_parameters *params)
700{
Johannes Berg14db74b2008-07-29 13:22:52 +0200701 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100702 struct sta_info *sta;
703 struct ieee80211_sub_if_data *sdata;
Johannes Berg73651ee2008-02-25 16:27:47 +0100704 int err;
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200705 int layer2_update;
Johannes Berg4fd69312007-12-19 02:03:35 +0100706
Johannes Berg4fd69312007-12-19 02:03:35 +0100707 if (params->vlan) {
708 sdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
709
Johannes Berg05c914f2008-09-11 00:01:58 +0200710 if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
711 sdata->vif.type != NL80211_IFTYPE_AP)
Johannes Berg4fd69312007-12-19 02:03:35 +0100712 return -EINVAL;
713 } else
714 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
715
Johannes Berg03e44972008-02-27 09:56:40 +0100716 if (compare_ether_addr(mac, dev->dev_addr) == 0)
717 return -EINVAL;
718
719 if (is_multicast_ether_addr(mac))
720 return -EINVAL;
721
722 sta = sta_info_alloc(sdata, mac, GFP_KERNEL);
Johannes Berg73651ee2008-02-25 16:27:47 +0100723 if (!sta)
724 return -ENOMEM;
Johannes Berg4fd69312007-12-19 02:03:35 +0100725
726 sta->flags = WLAN_STA_AUTH | WLAN_STA_ASSOC;
727
728 sta_apply_parameters(local, sta, params);
729
Johannes Berg4b7679a2008-09-18 18:14:18 +0200730 rate_control_rate_init(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100731
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200732 layer2_update = sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
733 sdata->vif.type == NL80211_IFTYPE_AP;
734
Johannes Berg73651ee2008-02-25 16:27:47 +0100735 rcu_read_lock();
736
737 err = sta_info_insert(sta);
738 if (err) {
Johannes Berg93e5deb2008-04-01 15:21:00 +0200739 /* STA has been freed */
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200740 if (err == -EEXIST && layer2_update) {
741 /* Need to update layer 2 devices on reassociation */
742 sta = sta_info_get(local, mac);
743 if (sta)
744 ieee80211_send_layer2_update(sta);
745 }
Johannes Berg73651ee2008-02-25 16:27:47 +0100746 rcu_read_unlock();
747 return err;
748 }
749
Jouni Malinenb8d476c2008-12-12 17:08:31 +0200750 if (layer2_update)
Johannes Berg73651ee2008-02-25 16:27:47 +0100751 ieee80211_send_layer2_update(sta);
752
753 rcu_read_unlock();
754
Johannes Berg4fd69312007-12-19 02:03:35 +0100755 return 0;
756}
757
758static int ieee80211_del_station(struct wiphy *wiphy, struct net_device *dev,
759 u8 *mac)
760{
Johannes Berg14db74b2008-07-29 13:22:52 +0200761 struct ieee80211_local *local = wiphy_priv(wiphy);
762 struct ieee80211_sub_if_data *sdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100763 struct sta_info *sta;
764
Johannes Berg14db74b2008-07-29 13:22:52 +0200765 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
766
Johannes Berg4fd69312007-12-19 02:03:35 +0100767 if (mac) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200768 rcu_read_lock();
769
Johannes Berg4fd69312007-12-19 02:03:35 +0100770 /* XXX: get sta belonging to dev */
771 sta = sta_info_get(local, 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 sta_info_unlink(&sta);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200778 rcu_read_unlock();
779
Johannes Berg4f6fab42008-03-31 19:23:02 +0200780 sta_info_destroy(sta);
Johannes Berg4fd69312007-12-19 02:03:35 +0100781 } else
Johannes Bergd0709a62008-02-25 16:27:46 +0100782 sta_info_flush(local, sdata);
Johannes Berg4fd69312007-12-19 02:03:35 +0100783
784 return 0;
785}
786
787static int ieee80211_change_station(struct wiphy *wiphy,
788 struct net_device *dev,
789 u8 *mac,
790 struct station_parameters *params)
791{
Johannes Berg14db74b2008-07-29 13:22:52 +0200792 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg4fd69312007-12-19 02:03:35 +0100793 struct sta_info *sta;
794 struct ieee80211_sub_if_data *vlansdata;
795
Johannes Berg98dd6a52008-04-10 15:36:09 +0200796 rcu_read_lock();
797
Johannes Berg4fd69312007-12-19 02:03:35 +0100798 /* XXX: get sta belonging to dev */
799 sta = sta_info_get(local, mac);
Johannes Berg98dd6a52008-04-10 15:36:09 +0200800 if (!sta) {
801 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100802 return -ENOENT;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200803 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100804
Johannes Bergd0709a62008-02-25 16:27:46 +0100805 if (params->vlan && params->vlan != sta->sdata->dev) {
Johannes Berg4fd69312007-12-19 02:03:35 +0100806 vlansdata = IEEE80211_DEV_TO_SUB_IF(params->vlan);
807
Johannes Berg05c914f2008-09-11 00:01:58 +0200808 if (vlansdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
809 vlansdata->vif.type != NL80211_IFTYPE_AP) {
Johannes Berg98dd6a52008-04-10 15:36:09 +0200810 rcu_read_unlock();
Johannes Berg4fd69312007-12-19 02:03:35 +0100811 return -EINVAL;
Johannes Berg98dd6a52008-04-10 15:36:09 +0200812 }
Johannes Berg4fd69312007-12-19 02:03:35 +0100813
Johannes Berg14db74b2008-07-29 13:22:52 +0200814 sta->sdata = vlansdata;
Johannes Berg4fd69312007-12-19 02:03:35 +0100815 ieee80211_send_layer2_update(sta);
816 }
817
818 sta_apply_parameters(local, sta, params);
819
Johannes Berg98dd6a52008-04-10 15:36:09 +0200820 rcu_read_unlock();
821
Johannes Berg4fd69312007-12-19 02:03:35 +0100822 return 0;
823}
824
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100825#ifdef CONFIG_MAC80211_MESH
826static int ieee80211_add_mpath(struct wiphy *wiphy, struct net_device *dev,
827 u8 *dst, u8 *next_hop)
828{
Johannes Berg14db74b2008-07-29 13:22:52 +0200829 struct ieee80211_local *local = wiphy_priv(wiphy);
830 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100831 struct mesh_path *mpath;
832 struct sta_info *sta;
833 int err;
834
Johannes Berg14db74b2008-07-29 13:22:52 +0200835 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
836
Johannes Bergd0709a62008-02-25 16:27:46 +0100837 rcu_read_lock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100838 sta = sta_info_get(local, next_hop);
Johannes Bergd0709a62008-02-25 16:27:46 +0100839 if (!sta) {
840 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100841 return -ENOENT;
Johannes Bergd0709a62008-02-25 16:27:46 +0100842 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100843
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200844 err = mesh_path_add(dst, sdata);
Johannes Bergd0709a62008-02-25 16:27:46 +0100845 if (err) {
846 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100847 return err;
Johannes Bergd0709a62008-02-25 16:27:46 +0100848 }
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100849
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200850 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100851 if (!mpath) {
852 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100853 return -ENXIO;
854 }
855 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100856
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100857 rcu_read_unlock();
858 return 0;
859}
860
861static int ieee80211_del_mpath(struct wiphy *wiphy, struct net_device *dev,
862 u8 *dst)
863{
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200864 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100865
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200866 if (dst)
867 return mesh_path_del(dst, sdata);
868
869 mesh_path_flush(sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100870 return 0;
871}
872
873static int ieee80211_change_mpath(struct wiphy *wiphy,
874 struct net_device *dev,
875 u8 *dst, u8 *next_hop)
876{
Johannes Berg14db74b2008-07-29 13:22:52 +0200877 struct ieee80211_local *local = wiphy_priv(wiphy);
878 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100879 struct mesh_path *mpath;
880 struct sta_info *sta;
881
Johannes Berg14db74b2008-07-29 13:22:52 +0200882 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
883
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100884 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +0100885
886 sta = sta_info_get(local, next_hop);
887 if (!sta) {
888 rcu_read_unlock();
889 return -ENOENT;
890 }
891
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200892 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100893 if (!mpath) {
894 rcu_read_unlock();
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100895 return -ENOENT;
896 }
897
898 mesh_path_fix_nexthop(mpath, sta);
Johannes Bergd0709a62008-02-25 16:27:46 +0100899
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100900 rcu_read_unlock();
901 return 0;
902}
903
904static void mpath_set_pinfo(struct mesh_path *mpath, u8 *next_hop,
905 struct mpath_info *pinfo)
906{
907 if (mpath->next_hop)
Johannes Berg17741cd2008-09-11 00:02:02 +0200908 memcpy(next_hop, mpath->next_hop->sta.addr, ETH_ALEN);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100909 else
910 memset(next_hop, 0, ETH_ALEN);
911
912 pinfo->filled = MPATH_INFO_FRAME_QLEN |
913 MPATH_INFO_DSN |
914 MPATH_INFO_METRIC |
915 MPATH_INFO_EXPTIME |
916 MPATH_INFO_DISCOVERY_TIMEOUT |
917 MPATH_INFO_DISCOVERY_RETRIES |
918 MPATH_INFO_FLAGS;
919
920 pinfo->frame_qlen = mpath->frame_queue.qlen;
921 pinfo->dsn = mpath->dsn;
922 pinfo->metric = mpath->metric;
923 if (time_before(jiffies, mpath->exp_time))
924 pinfo->exptime = jiffies_to_msecs(mpath->exp_time - jiffies);
925 pinfo->discovery_timeout =
926 jiffies_to_msecs(mpath->discovery_timeout);
927 pinfo->discovery_retries = mpath->discovery_retries;
928 pinfo->flags = 0;
929 if (mpath->flags & MESH_PATH_ACTIVE)
930 pinfo->flags |= NL80211_MPATH_FLAG_ACTIVE;
931 if (mpath->flags & MESH_PATH_RESOLVING)
932 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
933 if (mpath->flags & MESH_PATH_DSN_VALID)
934 pinfo->flags |= NL80211_MPATH_FLAG_DSN_VALID;
935 if (mpath->flags & MESH_PATH_FIXED)
936 pinfo->flags |= NL80211_MPATH_FLAG_FIXED;
937 if (mpath->flags & MESH_PATH_RESOLVING)
938 pinfo->flags |= NL80211_MPATH_FLAG_RESOLVING;
939
940 pinfo->flags = mpath->flags;
941}
942
943static int ieee80211_get_mpath(struct wiphy *wiphy, struct net_device *dev,
944 u8 *dst, u8 *next_hop, struct mpath_info *pinfo)
945
946{
Johannes Berg14db74b2008-07-29 13:22:52 +0200947 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100948 struct mesh_path *mpath;
949
Johannes Berg14db74b2008-07-29 13:22:52 +0200950 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
951
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100952 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200953 mpath = mesh_path_lookup(dst, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100954 if (!mpath) {
955 rcu_read_unlock();
956 return -ENOENT;
957 }
958 memcpy(dst, mpath->dst, ETH_ALEN);
959 mpath_set_pinfo(mpath, next_hop, pinfo);
960 rcu_read_unlock();
961 return 0;
962}
963
964static int ieee80211_dump_mpath(struct wiphy *wiphy, struct net_device *dev,
965 int idx, u8 *dst, u8 *next_hop,
966 struct mpath_info *pinfo)
967{
Johannes Berg14db74b2008-07-29 13:22:52 +0200968 struct ieee80211_sub_if_data *sdata;
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100969 struct mesh_path *mpath;
970
Johannes Berg14db74b2008-07-29 13:22:52 +0200971 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
972
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100973 rcu_read_lock();
Jasper Bryant-Greenef698d852008-08-03 12:04:37 +1200974 mpath = mesh_path_lookup_by_idx(idx, sdata);
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +0100975 if (!mpath) {
976 rcu_read_unlock();
977 return -ENOENT;
978 }
979 memcpy(dst, mpath->dst, ETH_ALEN);
980 mpath_set_pinfo(mpath, next_hop, pinfo);
981 rcu_read_unlock();
982 return 0;
983}
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700984
985static int ieee80211_get_mesh_params(struct wiphy *wiphy,
986 struct net_device *dev,
987 struct mesh_config *conf)
988{
989 struct ieee80211_sub_if_data *sdata;
990 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
991
colin@cozybit.com93da9cc2008-10-21 12:03:48 -0700992 memcpy(conf, &(sdata->u.mesh.mshcfg), sizeof(struct mesh_config));
993 return 0;
994}
995
996static inline bool _chg_mesh_attr(enum nl80211_meshconf_params parm, u32 mask)
997{
998 return (mask >> (parm-1)) & 0x1;
999}
1000
1001static int ieee80211_set_mesh_params(struct wiphy *wiphy,
1002 struct net_device *dev,
1003 const struct mesh_config *nconf, u32 mask)
1004{
1005 struct mesh_config *conf;
1006 struct ieee80211_sub_if_data *sdata;
1007 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1008
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001009 /* Set the config options which we are interested in setting */
1010 conf = &(sdata->u.mesh.mshcfg);
1011 if (_chg_mesh_attr(NL80211_MESHCONF_RETRY_TIMEOUT, mask))
1012 conf->dot11MeshRetryTimeout = nconf->dot11MeshRetryTimeout;
1013 if (_chg_mesh_attr(NL80211_MESHCONF_CONFIRM_TIMEOUT, mask))
1014 conf->dot11MeshConfirmTimeout = nconf->dot11MeshConfirmTimeout;
1015 if (_chg_mesh_attr(NL80211_MESHCONF_HOLDING_TIMEOUT, mask))
1016 conf->dot11MeshHoldingTimeout = nconf->dot11MeshHoldingTimeout;
1017 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_PEER_LINKS, mask))
1018 conf->dot11MeshMaxPeerLinks = nconf->dot11MeshMaxPeerLinks;
1019 if (_chg_mesh_attr(NL80211_MESHCONF_MAX_RETRIES, mask))
1020 conf->dot11MeshMaxRetries = nconf->dot11MeshMaxRetries;
1021 if (_chg_mesh_attr(NL80211_MESHCONF_TTL, mask))
1022 conf->dot11MeshTTL = nconf->dot11MeshTTL;
1023 if (_chg_mesh_attr(NL80211_MESHCONF_AUTO_OPEN_PLINKS, mask))
1024 conf->auto_open_plinks = nconf->auto_open_plinks;
1025 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_MAX_PREQ_RETRIES, mask))
1026 conf->dot11MeshHWMPmaxPREQretries =
1027 nconf->dot11MeshHWMPmaxPREQretries;
1028 if (_chg_mesh_attr(NL80211_MESHCONF_PATH_REFRESH_TIME, mask))
1029 conf->path_refresh_time = nconf->path_refresh_time;
1030 if (_chg_mesh_attr(NL80211_MESHCONF_MIN_DISCOVERY_TIMEOUT, mask))
1031 conf->min_discovery_timeout = nconf->min_discovery_timeout;
1032 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_ACTIVE_PATH_TIMEOUT, mask))
1033 conf->dot11MeshHWMPactivePathTimeout =
1034 nconf->dot11MeshHWMPactivePathTimeout;
1035 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_PREQ_MIN_INTERVAL, mask))
1036 conf->dot11MeshHWMPpreqMinInterval =
1037 nconf->dot11MeshHWMPpreqMinInterval;
1038 if (_chg_mesh_attr(NL80211_MESHCONF_HWMP_NET_DIAM_TRVS_TIME,
1039 mask))
1040 conf->dot11MeshHWMPnetDiameterTraversalTime =
1041 nconf->dot11MeshHWMPnetDiameterTraversalTime;
1042 return 0;
1043}
1044
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001045#endif
1046
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001047static int ieee80211_change_bss(struct wiphy *wiphy,
1048 struct net_device *dev,
1049 struct bss_parameters *params)
1050{
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001051 struct ieee80211_sub_if_data *sdata;
1052 u32 changed = 0;
1053
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001054 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1055
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001056 if (params->use_cts_prot >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001057 sdata->vif.bss_conf.use_cts_prot = params->use_cts_prot;
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001058 changed |= BSS_CHANGED_ERP_CTS_PROT;
1059 }
1060 if (params->use_short_preamble >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001061 sdata->vif.bss_conf.use_short_preamble =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001062 params->use_short_preamble;
1063 changed |= BSS_CHANGED_ERP_PREAMBLE;
1064 }
1065 if (params->use_short_slot_time >= 0) {
Johannes Bergbda39332008-10-11 01:51:51 +02001066 sdata->vif.bss_conf.use_short_slot =
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001067 params->use_short_slot_time;
1068 changed |= BSS_CHANGED_ERP_SLOT;
1069 }
1070
Jouni Malinen90c97a02008-10-30 16:59:22 +02001071 if (params->basic_rates) {
1072 int i, j;
1073 u32 rates = 0;
1074 struct ieee80211_local *local = wiphy_priv(wiphy);
1075 struct ieee80211_supported_band *sband =
1076 wiphy->bands[local->oper_channel->band];
1077
1078 for (i = 0; i < params->basic_rates_len; i++) {
1079 int rate = (params->basic_rates[i] & 0x7f) * 5;
1080 for (j = 0; j < sband->n_bitrates; j++) {
1081 if (sband->bitrates[j].bitrate == rate)
1082 rates |= BIT(j);
1083 }
1084 }
1085 sdata->vif.bss_conf.basic_rates = rates;
1086 changed |= BSS_CHANGED_BASIC_RATES;
1087 }
1088
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001089 ieee80211_bss_info_change_notify(sdata, changed);
1090
1091 return 0;
1092}
1093
Jouni Malinen31888482008-10-30 16:59:24 +02001094static int ieee80211_set_txq_params(struct wiphy *wiphy,
1095 struct ieee80211_txq_params *params)
1096{
1097 struct ieee80211_local *local = wiphy_priv(wiphy);
1098 struct ieee80211_tx_queue_params p;
1099
1100 if (!local->ops->conf_tx)
1101 return -EOPNOTSUPP;
1102
1103 memset(&p, 0, sizeof(p));
1104 p.aifs = params->aifs;
1105 p.cw_max = params->cwmax;
1106 p.cw_min = params->cwmin;
1107 p.txop = params->txop;
Johannes Berg24487982009-04-23 18:52:52 +02001108 if (drv_conf_tx(local, params->queue, &p)) {
Jouni Malinen31888482008-10-30 16:59:24 +02001109 printk(KERN_DEBUG "%s: failed to set TX queue "
Johannes Berg0bffe402009-06-09 16:18:32 +02001110 "parameters for queue %d\n",
1111 wiphy_name(local->hw.wiphy), params->queue);
Jouni Malinen31888482008-10-30 16:59:24 +02001112 return -EINVAL;
1113 }
1114
1115 return 0;
1116}
1117
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001118static int ieee80211_set_channel(struct wiphy *wiphy,
1119 struct ieee80211_channel *chan,
Sujith094d05d2008-12-12 11:57:43 +05301120 enum nl80211_channel_type channel_type)
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001121{
1122 struct ieee80211_local *local = wiphy_priv(wiphy);
1123
1124 local->oper_channel = chan;
Sujith094d05d2008-12-12 11:57:43 +05301125 local->oper_channel_type = channel_type;
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001126
1127 return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
1128}
1129
Bob Copeland665af4f2009-01-19 11:20:53 -05001130#ifdef CONFIG_PM
1131static int ieee80211_suspend(struct wiphy *wiphy)
1132{
1133 return __ieee80211_suspend(wiphy_priv(wiphy));
1134}
1135
1136static int ieee80211_resume(struct wiphy *wiphy)
1137{
1138 return __ieee80211_resume(wiphy_priv(wiphy));
1139}
1140#else
1141#define ieee80211_suspend NULL
1142#define ieee80211_resume NULL
1143#endif
1144
Johannes Berg2a519312009-02-10 21:25:55 +01001145static int ieee80211_scan(struct wiphy *wiphy,
1146 struct net_device *dev,
1147 struct cfg80211_scan_request *req)
1148{
1149 struct ieee80211_sub_if_data *sdata;
1150
Johannes Berg2a519312009-02-10 21:25:55 +01001151 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1152
1153 if (sdata->vif.type != NL80211_IFTYPE_STATION &&
1154 sdata->vif.type != NL80211_IFTYPE_ADHOC &&
Jouni Malinen357303e2009-04-16 18:44:53 +03001155 sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
1156 (sdata->vif.type != NL80211_IFTYPE_AP || sdata->u.ap.beacon))
Johannes Berg2a519312009-02-10 21:25:55 +01001157 return -EOPNOTSUPP;
1158
1159 return ieee80211_request_scan(sdata, req);
1160}
1161
Jouni Malinen636a5d32009-03-19 13:39:22 +02001162static int ieee80211_auth(struct wiphy *wiphy, struct net_device *dev,
1163 struct cfg80211_auth_request *req)
1164{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001165 return ieee80211_mgd_auth(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001166}
1167
1168static int ieee80211_assoc(struct wiphy *wiphy, struct net_device *dev,
1169 struct cfg80211_assoc_request *req)
1170{
Johannes Berg77fdaa12009-07-07 03:45:17 +02001171 return ieee80211_mgd_assoc(IEEE80211_DEV_TO_SUB_IF(dev), req);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001172}
1173
1174static int ieee80211_deauth(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001175 struct cfg80211_deauth_request *req,
1176 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001177{
Johannes Berg667503dd2009-07-07 03:56:11 +02001178 return ieee80211_mgd_deauth(IEEE80211_DEV_TO_SUB_IF(dev),
1179 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001180}
1181
1182static int ieee80211_disassoc(struct wiphy *wiphy, struct net_device *dev,
Johannes Berg667503dd2009-07-07 03:56:11 +02001183 struct cfg80211_disassoc_request *req,
1184 void *cookie)
Jouni Malinen636a5d32009-03-19 13:39:22 +02001185{
Johannes Berg667503dd2009-07-07 03:56:11 +02001186 return ieee80211_mgd_disassoc(IEEE80211_DEV_TO_SUB_IF(dev),
1187 req, cookie);
Jouni Malinen636a5d32009-03-19 13:39:22 +02001188}
1189
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001190static int ieee80211_join_ibss(struct wiphy *wiphy, struct net_device *dev,
1191 struct cfg80211_ibss_params *params)
1192{
1193 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1194
1195 return ieee80211_ibss_join(sdata, params);
1196}
1197
1198static int ieee80211_leave_ibss(struct wiphy *wiphy, struct net_device *dev)
1199{
1200 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1201
1202 return ieee80211_ibss_leave(sdata);
1203}
1204
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001205static int ieee80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
1206{
1207 struct ieee80211_local *local = wiphy_priv(wiphy);
Johannes Berg24487982009-04-23 18:52:52 +02001208 int err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001209
1210 if (changed & WIPHY_PARAM_RTS_THRESHOLD) {
Johannes Berg24487982009-04-23 18:52:52 +02001211 err = drv_set_rts_threshold(local, wiphy->rts_threshold);
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001212
Johannes Berg24487982009-04-23 18:52:52 +02001213 if (err)
1214 return err;
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001215 }
1216
1217 if (changed & WIPHY_PARAM_RETRY_SHORT)
1218 local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
1219 if (changed & WIPHY_PARAM_RETRY_LONG)
1220 local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
1221 if (changed &
1222 (WIPHY_PARAM_RETRY_SHORT | WIPHY_PARAM_RETRY_LONG))
1223 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_RETRY_LIMITS);
1224
1225 return 0;
1226}
1227
Johannes Berg7643a2c2009-06-02 13:01:39 +02001228static int ieee80211_set_tx_power(struct wiphy *wiphy,
1229 enum tx_power_setting type, int dbm)
1230{
1231 struct ieee80211_local *local = wiphy_priv(wiphy);
1232 struct ieee80211_channel *chan = local->hw.conf.channel;
1233 u32 changes = 0;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001234
1235 switch (type) {
1236 case TX_POWER_AUTOMATIC:
1237 local->user_power_level = -1;
1238 break;
1239 case TX_POWER_LIMITED:
1240 if (dbm < 0)
1241 return -EINVAL;
1242 local->user_power_level = dbm;
1243 break;
1244 case TX_POWER_FIXED:
1245 if (dbm < 0)
1246 return -EINVAL;
1247 /* TODO: move to cfg80211 when it knows the channel */
1248 if (dbm > chan->max_power)
1249 return -EINVAL;
1250 local->user_power_level = dbm;
1251 break;
Johannes Berg7643a2c2009-06-02 13:01:39 +02001252 }
1253
1254 ieee80211_hw_config(local, changes);
1255
1256 return 0;
1257}
1258
1259static int ieee80211_get_tx_power(struct wiphy *wiphy, int *dbm)
1260{
1261 struct ieee80211_local *local = wiphy_priv(wiphy);
1262
1263 *dbm = local->hw.conf.power_level;
1264
Johannes Berg7643a2c2009-06-02 13:01:39 +02001265 return 0;
1266}
1267
Johannes Bergab737a42009-07-01 21:26:58 +02001268static int ieee80211_set_wds_peer(struct wiphy *wiphy, struct net_device *dev,
1269 u8 *addr)
1270{
1271 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1272
1273 memcpy(&sdata->u.wds.remote_addr, addr, ETH_ALEN);
1274
1275 return 0;
1276}
1277
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001278static void ieee80211_rfkill_poll(struct wiphy *wiphy)
1279{
1280 struct ieee80211_local *local = wiphy_priv(wiphy);
1281
1282 drv_rfkill_poll(local);
1283}
1284
Johannes Bergaff89a92009-07-01 21:26:51 +02001285#ifdef CONFIG_NL80211_TESTMODE
Johannes Berg99783e22009-07-07 03:54:43 +02001286static int ieee80211_testmode_cmd(struct wiphy *wiphy, void *data, int len)
Johannes Bergaff89a92009-07-01 21:26:51 +02001287{
1288 struct ieee80211_local *local = wiphy_priv(wiphy);
1289
1290 if (!local->ops->testmode_cmd)
1291 return -EOPNOTSUPP;
1292
1293 return local->ops->testmode_cmd(&local->hw, data, len);
1294}
1295#endif
1296
Johannes Bergbc92afd2009-07-01 21:26:57 +02001297static int ieee80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *dev,
1298 bool enabled, int timeout)
1299{
1300 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1301 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1302 struct ieee80211_conf *conf = &local->hw.conf;
1303
1304 if (!(local->hw.flags & IEEE80211_HW_SUPPORTS_PS))
1305 return -EOPNOTSUPP;
1306
1307 if (enabled == sdata->u.mgd.powersave &&
1308 timeout == conf->dynamic_ps_timeout)
1309 return 0;
1310
1311 sdata->u.mgd.powersave = enabled;
1312 conf->dynamic_ps_timeout = timeout;
1313
1314 if (local->hw.flags & IEEE80211_HW_SUPPORTS_DYNAMIC_PS)
1315 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
1316
1317 ieee80211_recalc_ps(local, -1);
1318
1319 return 0;
1320}
1321
Johannes Berg99303802009-07-01 21:26:59 +02001322static int ieee80211_set_bitrate_mask(struct wiphy *wiphy,
1323 struct net_device *dev,
1324 const u8 *addr,
1325 const struct cfg80211_bitrate_mask *mask)
1326{
1327 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1328 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1329 int i, err = -EINVAL;
1330 u32 target_rate;
1331 struct ieee80211_supported_band *sband;
1332
1333 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
1334
1335 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
1336 * target_rate = X, rate->fixed = 1 means only rate X
1337 * target_rate = X, rate->fixed = 0 means all rates <= X */
1338 sdata->max_ratectrl_rateidx = -1;
1339 sdata->force_unicast_rateidx = -1;
1340
1341 if (mask->fixed)
1342 target_rate = mask->fixed / 100;
1343 else if (mask->maxrate)
1344 target_rate = mask->maxrate / 100;
1345 else
1346 return 0;
1347
1348 for (i=0; i< sband->n_bitrates; i++) {
1349 struct ieee80211_rate *brate = &sband->bitrates[i];
1350 int this_rate = brate->bitrate;
1351
1352 if (target_rate == this_rate) {
1353 sdata->max_ratectrl_rateidx = i;
1354 if (mask->fixed)
1355 sdata->force_unicast_rateidx = i;
1356 err = 0;
1357 break;
1358 }
1359 }
1360
1361 return err;
1362}
1363
Jiri Bencf0706e82007-05-05 11:45:53 -07001364struct cfg80211_ops mac80211_config_ops = {
1365 .add_virtual_intf = ieee80211_add_iface,
1366 .del_virtual_intf = ieee80211_del_iface,
Johannes Berg42613db2007-09-28 21:52:27 +02001367 .change_virtual_intf = ieee80211_change_iface,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001368 .add_key = ieee80211_add_key,
1369 .del_key = ieee80211_del_key,
Johannes Berg62da92f2007-12-19 02:03:31 +01001370 .get_key = ieee80211_get_key,
Johannes Berge8cbb4c2007-12-19 02:03:30 +01001371 .set_default_key = ieee80211_config_default_key,
Jouni Malinen3cfcf6ac2009-01-08 13:32:02 +02001372 .set_default_mgmt_key = ieee80211_config_default_mgmt_key,
Johannes Berg5dfdaf52007-12-19 02:03:33 +01001373 .add_beacon = ieee80211_add_beacon,
1374 .set_beacon = ieee80211_set_beacon,
1375 .del_beacon = ieee80211_del_beacon,
Johannes Berg4fd69312007-12-19 02:03:35 +01001376 .add_station = ieee80211_add_station,
1377 .del_station = ieee80211_del_station,
1378 .change_station = ieee80211_change_station,
Johannes Berg7bbdd2d2007-12-19 02:03:37 +01001379 .get_station = ieee80211_get_station,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001380 .dump_station = ieee80211_dump_station,
1381#ifdef CONFIG_MAC80211_MESH
1382 .add_mpath = ieee80211_add_mpath,
1383 .del_mpath = ieee80211_del_mpath,
1384 .change_mpath = ieee80211_change_mpath,
1385 .get_mpath = ieee80211_get_mpath,
1386 .dump_mpath = ieee80211_dump_mpath,
colin@cozybit.com93da9cc2008-10-21 12:03:48 -07001387 .set_mesh_params = ieee80211_set_mesh_params,
1388 .get_mesh_params = ieee80211_get_mesh_params,
Luis Carlos Coboc5dd9c22008-02-23 15:17:17 +01001389#endif
Jouni Malinen9f1ba902008-08-07 20:07:01 +03001390 .change_bss = ieee80211_change_bss,
Jouni Malinen31888482008-10-30 16:59:24 +02001391 .set_txq_params = ieee80211_set_txq_params,
Jouni Malinen72bdcf32008-11-26 16:15:24 +02001392 .set_channel = ieee80211_set_channel,
Bob Copeland665af4f2009-01-19 11:20:53 -05001393 .suspend = ieee80211_suspend,
1394 .resume = ieee80211_resume,
Johannes Berg2a519312009-02-10 21:25:55 +01001395 .scan = ieee80211_scan,
Jouni Malinen636a5d32009-03-19 13:39:22 +02001396 .auth = ieee80211_auth,
1397 .assoc = ieee80211_assoc,
1398 .deauth = ieee80211_deauth,
1399 .disassoc = ieee80211_disassoc,
Johannes Bergaf8cdcd2009-04-19 21:25:43 +02001400 .join_ibss = ieee80211_join_ibss,
1401 .leave_ibss = ieee80211_leave_ibss,
Jouni Malinenb9a5f8ca2009-04-20 18:39:05 +02001402 .set_wiphy_params = ieee80211_set_wiphy_params,
Johannes Berg7643a2c2009-06-02 13:01:39 +02001403 .set_tx_power = ieee80211_set_tx_power,
1404 .get_tx_power = ieee80211_get_tx_power,
Johannes Bergab737a42009-07-01 21:26:58 +02001405 .set_wds_peer = ieee80211_set_wds_peer,
Johannes Berg1f87f7d2009-06-02 13:01:41 +02001406 .rfkill_poll = ieee80211_rfkill_poll,
Johannes Bergaff89a92009-07-01 21:26:51 +02001407 CFG80211_TESTMODE_CMD(ieee80211_testmode_cmd)
Johannes Bergbc92afd2009-07-01 21:26:57 +02001408 .set_power_mgmt = ieee80211_set_power_mgmt,
Johannes Berg99303802009-07-01 21:26:59 +02001409 .set_bitrate_mask = ieee80211_set_bitrate_mask,
Jiri Bencf0706e82007-05-05 11:45:53 -07001410};