blob: e8404212ad57ecdfda2df597a9725c73278627b4 [file] [log] [blame]
Jiri Bencf0706e82007-05-05 11:45:53 -07001/*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005-2006, Devicescape Software, Inc.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/netdevice.h>
13#include <linux/types.h>
14#include <linux/slab.h>
15#include <linux/skbuff.h>
16#include <linux/etherdevice.h>
17#include <linux/if_arp.h>
18#include <linux/wireless.h>
19#include <net/iw_handler.h>
20#include <asm/uaccess.h>
21
22#include <net/mac80211.h>
23#include "ieee80211_i.h"
Johannes Berg2c8dccc2008-04-08 15:14:40 -040024#include "led.h"
25#include "rate.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070026#include "wpa.h"
27#include "aes_ccm.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070028
Johannes Bergb708e612007-09-14 11:10:25 -040029
Jiri Bencf0706e82007-05-05 11:45:53 -070030static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
Johannes Berg628a1402007-09-26 17:53:17 +020031 int idx, int alg, int remove,
32 int set_tx_key, const u8 *_key,
33 size_t key_len)
Jiri Bencf0706e82007-05-05 11:45:53 -070034{
35 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Bergd0709a62008-02-25 16:27:46 +010036 struct sta_info *sta;
Johannes Berg11a843b2007-08-28 17:01:55 -040037 struct ieee80211_key *key;
Jiri Bencf0706e82007-05-05 11:45:53 -070038 struct ieee80211_sub_if_data *sdata;
Johannes Berg3b967662008-04-08 17:56:52 +020039 int err;
Jiri Bencf0706e82007-05-05 11:45:53 -070040
41 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
42
Volker Braun139c3a02007-09-14 11:10:25 -040043 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
44 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
45 dev->name, idx);
46 return -EINVAL;
47 }
48
Johannes Berg628a1402007-09-26 17:53:17 +020049 if (remove) {
Johannes Berg3b967662008-04-08 17:56:52 +020050 rcu_read_lock();
51
52 err = 0;
53
Johannes Bergdb4d1162008-02-25 16:27:45 +010054 if (is_broadcast_ether_addr(sta_addr)) {
55 key = sdata->keys[idx];
56 } else {
57 sta = sta_info_get(local, sta_addr);
Johannes Berg3b967662008-04-08 17:56:52 +020058 if (!sta) {
59 err = -ENOENT;
60 goto out_unlock;
61 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010062 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070063 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010064
Johannes Bergd0709a62008-02-25 16:27:46 +010065 ieee80211_key_free(key);
Johannes Bergdb4d1162008-02-25 16:27:45 +010066 } else {
67 key = ieee80211_key_alloc(alg, idx, key_len, _key);
68 if (!key)
69 return -ENOMEM;
70
Johannes Bergd0709a62008-02-25 16:27:46 +010071 sta = NULL;
Johannes Berg3b967662008-04-08 17:56:52 +020072 err = 0;
73
74 rcu_read_lock();
Johannes Bergd0709a62008-02-25 16:27:46 +010075
Johannes Bergdb4d1162008-02-25 16:27:45 +010076 if (!is_broadcast_ether_addr(sta_addr)) {
77 set_tx_key = 0;
78 /*
79 * According to the standard, the key index of a
80 * pairwise key must be zero. However, some AP are
81 * broken when it comes to WEP key indices, so we
82 * work around this.
83 */
84 if (idx != 0 && alg != ALG_WEP) {
Johannes Bergd0709a62008-02-25 16:27:46 +010085 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020086 err = -EINVAL;
87 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010088 }
89
90 sta = sta_info_get(local, sta_addr);
91 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010092 ieee80211_key_free(key);
Johannes Berg3b967662008-04-08 17:56:52 +020093 err = -ENOENT;
94 goto out_unlock;
Johannes Bergdb4d1162008-02-25 16:27:45 +010095 }
96 }
97
Emmanuel Grumbach23976ef2008-06-28 02:50:13 +030098 if (alg == ALG_WEP &&
99 key_len != LEN_WEP40 && key_len != LEN_WEP104) {
100 ieee80211_key_free(key);
101 err = -EINVAL;
102 goto out_unlock;
103 }
104
Johannes Bergdb4d1162008-02-25 16:27:45 +0100105 ieee80211_key_link(key, sdata, sta);
106
107 if (set_tx_key || (!sta && !sdata->default_key && key))
108 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700109 }
110
Johannes Berg3b967662008-04-08 17:56:52 +0200111 out_unlock:
112 rcu_read_unlock();
113
114 return err;
Jiri Bencf0706e82007-05-05 11:45:53 -0700115}
116
117static int ieee80211_ioctl_siwgenie(struct net_device *dev,
118 struct iw_request_info *info,
119 struct iw_point *data, char *extra)
120{
121 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -0700122
123 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200124
125 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
126 return -EOPNOTSUPP;
127
Johannes Berg51fb61e2007-12-19 01:31:27 +0100128 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
129 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700130 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
131 if (ret)
132 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400133 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700134 ieee80211_sta_req_auth(dev, &sdata->u.sta);
135 return 0;
136 }
137
Jiri Bencf0706e82007-05-05 11:45:53 -0700138 return -EOPNOTSUPP;
139}
140
Jiri Bencf0706e82007-05-05 11:45:53 -0700141static int ieee80211_ioctl_giwname(struct net_device *dev,
142 struct iw_request_info *info,
143 char *name, char *extra)
144{
Johannes Berg8318d782008-01-24 19:38:38 +0100145 strcpy(name, "IEEE 802.11");
Jiri Bencf0706e82007-05-05 11:45:53 -0700146
147 return 0;
148}
149
150
151static int ieee80211_ioctl_giwrange(struct net_device *dev,
152 struct iw_request_info *info,
153 struct iw_point *data, char *extra)
154{
155 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
156 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100157 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200158 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700159
160 data->length = sizeof(struct iw_range);
161 memset(range, 0, sizeof(struct iw_range));
162
163 range->we_version_compiled = WIRELESS_EXT;
164 range->we_version_source = 21;
165 range->retry_capa = IW_RETRY_LIMIT;
166 range->retry_flags = IW_RETRY_LIMIT;
167 range->min_retry = 0;
168 range->max_retry = 255;
169 range->min_rts = 0;
170 range->max_rts = 2347;
171 range->min_frag = 256;
172 range->max_frag = 2346;
173
174 range->encoding_size[0] = 5;
175 range->encoding_size[1] = 13;
176 range->num_encoding_sizes = 2;
177 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
178
179 range->max_qual.qual = local->hw.max_signal;
180 range->max_qual.level = local->hw.max_rssi;
181 range->max_qual.noise = local->hw.max_noise;
182 range->max_qual.updated = local->wstats_flags;
183
184 range->avg_qual.qual = local->hw.max_signal/2;
185 range->avg_qual.level = 0;
186 range->avg_qual.noise = 0;
187 range->avg_qual.updated = local->wstats_flags;
188
189 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
190 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
191
Hong Liu333af2f2007-07-10 19:32:08 +0200192
Johannes Berg8318d782008-01-24 19:38:38 +0100193 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
194 int i;
195 struct ieee80211_supported_band *sband;
196
197 sband = local->hw.wiphy->bands[band];
198
199 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200200 continue;
201
Johannes Berg8318d782008-01-24 19:38:38 +0100202 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
203 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200204
Johannes Berg8318d782008-01-24 19:38:38 +0100205 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
206 range->freq[c].i =
207 ieee80211_frequency_to_channel(
208 chan->center_freq);
209 range->freq[c].m = chan->center_freq;
210 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200211 c++;
212 }
Hong Liu333af2f2007-07-10 19:32:08 +0200213 }
214 }
215 range->num_channels = c;
216 range->num_frequency = c;
217
Jiri Bencf0706e82007-05-05 11:45:53 -0700218 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
Jiri Bencf0706e82007-05-05 11:45:53 -0700219 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
220 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
221
Dan Williams374fdfb2007-12-12 10:25:07 -0500222 range->scan_capa |= IW_SCAN_CAPA_ESSID;
223
Jiri Bencf0706e82007-05-05 11:45:53 -0700224 return 0;
225}
226
227
Jiri Bencf0706e82007-05-05 11:45:53 -0700228static int ieee80211_ioctl_siwmode(struct net_device *dev,
229 struct iw_request_info *info,
230 __u32 *mode, char *extra)
231{
232 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
233 int type;
234
Johannes Berg51fb61e2007-12-19 01:31:27 +0100235 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700236 return -EOPNOTSUPP;
237
238 switch (*mode) {
239 case IW_MODE_INFRA:
240 type = IEEE80211_IF_TYPE_STA;
241 break;
242 case IW_MODE_ADHOC:
243 type = IEEE80211_IF_TYPE_IBSS;
244 break;
Johannes Bergb4540482008-04-14 15:37:03 +0200245 case IW_MODE_REPEAT:
246 type = IEEE80211_IF_TYPE_WDS;
247 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700248 case IW_MODE_MONITOR:
249 type = IEEE80211_IF_TYPE_MNTR;
250 break;
251 default:
252 return -EINVAL;
253 }
254
Johannes Berg51fb61e2007-12-19 01:31:27 +0100255 if (type == sdata->vif.type)
Jiri Bencf0706e82007-05-05 11:45:53 -0700256 return 0;
257 if (netif_running(dev))
258 return -EBUSY;
259
260 ieee80211_if_reinit(dev);
261 ieee80211_if_set_type(dev, type);
262
263 return 0;
264}
265
266
267static int ieee80211_ioctl_giwmode(struct net_device *dev,
268 struct iw_request_info *info,
269 __u32 *mode, char *extra)
270{
271 struct ieee80211_sub_if_data *sdata;
272
273 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100274 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700275 case IEEE80211_IF_TYPE_AP:
276 *mode = IW_MODE_MASTER;
277 break;
278 case IEEE80211_IF_TYPE_STA:
279 *mode = IW_MODE_INFRA;
280 break;
281 case IEEE80211_IF_TYPE_IBSS:
282 *mode = IW_MODE_ADHOC;
283 break;
284 case IEEE80211_IF_TYPE_MNTR:
285 *mode = IW_MODE_MONITOR;
286 break;
287 case IEEE80211_IF_TYPE_WDS:
288 *mode = IW_MODE_REPEAT;
289 break;
290 case IEEE80211_IF_TYPE_VLAN:
291 *mode = IW_MODE_SECOND; /* FIXME */
292 break;
293 default:
294 *mode = IW_MODE_AUTO;
295 break;
296 }
297 return 0;
298}
299
Assaf Kraussbe038b32008-06-05 19:55:21 +0300300int ieee80211_set_freq(struct net_device *dev, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700301{
Jiri Bencf0706e82007-05-05 11:45:53 -0700302 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100303 struct ieee80211_channel *chan;
Assaf Kraussbe038b32008-06-05 19:55:21 +0300304 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
305 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Jiri Bencf0706e82007-05-05 11:45:53 -0700306
Johannes Berge048c6e2008-03-16 18:35:56 +0100307 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100308
Johannes Berge048c6e2008-03-16 18:35:56 +0100309 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
Assaf Kraussbe038b32008-06-05 19:55:21 +0300310 if (sdata->vif.type == IEEE80211_IF_TYPE_IBSS &&
311 chan->flags & IEEE80211_CHAN_NO_IBSS) {
312 printk(KERN_DEBUG "%s: IBSS not allowed on frequency "
313 "%d MHz\n", dev->name, chan->center_freq);
314 return ret;
315 }
Johannes Berge048c6e2008-03-16 18:35:56 +0100316 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100317
Mohamed Abbas675ef582008-03-20 08:14:29 -0700318 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700319 ret = 0;
320 else
321 ret = ieee80211_hw_config(local);
322
323 rate_control_clear(local);
324 }
325
326 return ret;
327}
328
329static int ieee80211_ioctl_siwfreq(struct net_device *dev,
330 struct iw_request_info *info,
331 struct iw_freq *freq, char *extra)
332{
Jiri Bencf0706e82007-05-05 11:45:53 -0700333 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
334
Johannes Berg51fb61e2007-12-19 01:31:27 +0100335 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400336 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700337
338 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
339 if (freq->e == 0) {
340 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100341 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400342 sdata->u.sta.flags |=
343 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700344 return 0;
345 } else
Assaf Kraussbe038b32008-06-05 19:55:21 +0300346 return ieee80211_set_freq(dev,
Johannes Berg8318d782008-01-24 19:38:38 +0100347 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700348 } else {
349 int i, div = 1000000;
350 for (i = 0; i < freq->e; i++)
351 div /= 10;
352 if (div > 0)
Assaf Kraussbe038b32008-06-05 19:55:21 +0300353 return ieee80211_set_freq(dev, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700354 else
355 return -EINVAL;
356 }
357}
358
359
360static int ieee80211_ioctl_giwfreq(struct net_device *dev,
361 struct iw_request_info *info,
362 struct iw_freq *freq, char *extra)
363{
364 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
365
Johannes Berg8318d782008-01-24 19:38:38 +0100366 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700367 freq->e = 6;
368
369 return 0;
370}
371
372
373static int ieee80211_ioctl_siwessid(struct net_device *dev,
374 struct iw_request_info *info,
375 struct iw_point *data, char *ssid)
376{
Jiri Bencf0706e82007-05-05 11:45:53 -0700377 struct ieee80211_sub_if_data *sdata;
378 size_t len = data->length;
379
380 /* iwconfig uses nul termination in SSID.. */
381 if (len > 0 && ssid[len - 1] == '\0')
382 len--;
383
384 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100385 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
386 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700387 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200388 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700389 if (len > IEEE80211_MAX_SSID_LEN)
390 return -EINVAL;
391 memcpy(sdata->u.sta.ssid, ssid, len);
392 sdata->u.sta.ssid_len = len;
393 return 0;
394 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400395 if (data->flags)
396 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
397 else
398 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700399 ret = ieee80211_sta_set_ssid(dev, ssid, len);
400 if (ret)
401 return ret;
402 ieee80211_sta_req_auth(dev, &sdata->u.sta);
403 return 0;
404 }
405
Johannes Berg51fb61e2007-12-19 01:31:27 +0100406 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700407 memcpy(sdata->u.ap.ssid, ssid, len);
408 memset(sdata->u.ap.ssid + len, 0,
409 IEEE80211_MAX_SSID_LEN - len);
410 sdata->u.ap.ssid_len = len;
411 return ieee80211_if_config(dev);
412 }
413 return -EOPNOTSUPP;
414}
415
416
417static int ieee80211_ioctl_giwessid(struct net_device *dev,
418 struct iw_request_info *info,
419 struct iw_point *data, char *ssid)
420{
421 size_t len;
422
423 struct ieee80211_sub_if_data *sdata;
424 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100425 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
426 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700427 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
428 if (res == 0) {
429 data->length = len;
430 data->flags = 1;
431 } else
432 data->flags = 0;
433 return res;
434 }
435
Johannes Berg51fb61e2007-12-19 01:31:27 +0100436 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700437 len = sdata->u.ap.ssid_len;
438 if (len > IW_ESSID_MAX_SIZE)
439 len = IW_ESSID_MAX_SIZE;
440 memcpy(ssid, sdata->u.ap.ssid, len);
441 data->length = len;
442 data->flags = 1;
443 return 0;
444 }
445 return -EOPNOTSUPP;
446}
447
448
449static int ieee80211_ioctl_siwap(struct net_device *dev,
450 struct iw_request_info *info,
451 struct sockaddr *ap_addr, char *extra)
452{
Jiri Bencf0706e82007-05-05 11:45:53 -0700453 struct ieee80211_sub_if_data *sdata;
454
455 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100456 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
457 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700458 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200459 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700460 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
461 ETH_ALEN);
462 return 0;
463 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400464 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
465 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
466 IEEE80211_STA_AUTO_CHANNEL_SEL;
467 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
468 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700469 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400470 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700471 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
472 if (ret)
473 return ret;
474 ieee80211_sta_req_auth(dev, &sdata->u.sta);
475 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100476 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100477 /*
478 * If it is necessary to update the WDS peer address
479 * while the interface is running, then we need to do
480 * more work here, namely if it is running we need to
481 * add a new and remove the old STA entry, this is
482 * normally handled by _open() and _stop().
483 */
484 if (netif_running(dev))
485 return -EBUSY;
486
487 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
488 ETH_ALEN);
489
490 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700491 }
492
493 return -EOPNOTSUPP;
494}
495
496
497static int ieee80211_ioctl_giwap(struct net_device *dev,
498 struct iw_request_info *info,
499 struct sockaddr *ap_addr, char *extra)
500{
501 struct ieee80211_sub_if_data *sdata;
502
503 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100504 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
505 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Abhijeet Kolekar5c5f9662008-06-12 09:47:16 +0800506 if (sdata->u.sta.state == IEEE80211_ASSOCIATED ||
507 sdata->u.sta.state == IEEE80211_IBSS_JOINED) {
Abhijeet Kolekard4231ca2008-05-23 10:15:26 -0700508 ap_addr->sa_family = ARPHRD_ETHER;
509 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
510 return 0;
511 } else {
512 memset(&ap_addr->sa_data, 0, ETH_ALEN);
513 return 0;
514 }
Johannes Berg51fb61e2007-12-19 01:31:27 +0100515 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700516 ap_addr->sa_family = ARPHRD_ETHER;
517 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
518 return 0;
519 }
520
521 return -EOPNOTSUPP;
522}
523
524
525static int ieee80211_ioctl_siwscan(struct net_device *dev,
526 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400527 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700528{
Jiri Bencf0706e82007-05-05 11:45:53 -0700529 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400530 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700531 u8 *ssid = NULL;
532 size_t ssid_len = 0;
533
534 if (!netif_running(dev))
535 return -ENETDOWN;
536
Johannes Berg51fb61e2007-12-19 01:31:27 +0100537 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
538 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100539 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100540 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700541 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700542
543 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400544 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
545 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
546 req = (struct iw_scan_req *)extra;
547 ssid = req->essid;
548 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700549 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200550
Jiri Bencf0706e82007-05-05 11:45:53 -0700551 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
552}
553
554
555static int ieee80211_ioctl_giwscan(struct net_device *dev,
556 struct iw_request_info *info,
557 struct iw_point *data, char *extra)
558{
559 int res;
560 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800561
562 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700563 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800564
Jiri Bencf0706e82007-05-05 11:45:53 -0700565 res = ieee80211_sta_scan_results(dev, extra, data->length);
566 if (res >= 0) {
567 data->length = res;
568 return 0;
569 }
570 data->length = 0;
571 return res;
572}
573
574
Larry Finger1fd5e582007-07-10 19:32:10 +0200575static int ieee80211_ioctl_siwrate(struct net_device *dev,
576 struct iw_request_info *info,
577 struct iw_param *rate, char *extra)
578{
579 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100580 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200581 u32 target_rate = rate->value / 100000;
582 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100583 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200584
585 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
586 if (!sdata->bss)
587 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100588
589 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
590
Larry Finger1fd5e582007-07-10 19:32:10 +0200591 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
592 * target_rate = X, rate->fixed = 1 means only rate X
593 * target_rate = X, rate->fixed = 0 means all rates <= X */
594 sdata->bss->max_ratectrl_rateidx = -1;
595 sdata->bss->force_unicast_rateidx = -1;
596 if (rate->value < 0)
597 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100598
599 for (i=0; i< sband->n_bitrates; i++) {
600 struct ieee80211_rate *brate = &sband->bitrates[i];
601 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200602
Larry Finger1fd5e582007-07-10 19:32:10 +0200603 if (target_rate == this_rate) {
604 sdata->bss->max_ratectrl_rateidx = i;
605 if (rate->fixed)
606 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100607 err = 0;
608 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200609 }
610 }
Johannes Berg8318d782008-01-24 19:38:38 +0100611 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200612}
613
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700614static int ieee80211_ioctl_giwrate(struct net_device *dev,
615 struct iw_request_info *info,
616 struct iw_param *rate, char *extra)
617{
618 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
619 struct sta_info *sta;
620 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100621 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700622
623 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100624
Johannes Berg380a9422008-04-04 23:40:35 +0200625 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700626 return -EOPNOTSUPP;
Johannes Berg8318d782008-01-24 19:38:38 +0100627
628 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
629
Johannes Berg380a9422008-04-04 23:40:35 +0200630 rcu_read_lock();
631
632 sta = sta_info_get(local, sdata->u.sta.bssid);
633
634 if (sta && sta->txrate_idx < sband->n_bitrates)
Johannes Berg8318d782008-01-24 19:38:38 +0100635 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700636 else
637 rate->value = 0;
Johannes Berg380a9422008-04-04 23:40:35 +0200638
639 rcu_read_unlock();
640
641 if (!sta)
642 return -ENODEV;
643
Johannes Berg8318d782008-01-24 19:38:38 +0100644 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100645
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700646 return 0;
647}
648
Michael Buesch61609bc2007-09-20 22:06:39 +0200649static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
650 struct iw_request_info *info,
651 union iwreq_data *data, char *extra)
652{
653 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
654 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100655 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200656
657 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
658 return -EINVAL;
659 if (data->txpower.flags & IW_TXPOW_RANGE)
660 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200661
Mattias Nissler6a432952007-10-24 23:30:36 +0200662 if (data->txpower.fixed) {
663 new_power_level = data->txpower.value;
664 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100665 /*
666 * Automatic power level. Use maximum power for the current
667 * channel. Should be part of rate control.
668 */
669 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200670 if (!chan)
671 return -EINVAL;
672
Johannes Berg8318d782008-01-24 19:38:38 +0100673 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200674 }
675
676 if (local->hw.conf.power_level != new_power_level) {
677 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200678 need_reconfig = 1;
679 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200680
Michael Buesch61609bc2007-09-20 22:06:39 +0200681 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
682 local->hw.conf.radio_enabled = !(data->txpower.disabled);
683 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100684 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200685 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200686
Michael Buesch61609bc2007-09-20 22:06:39 +0200687 if (need_reconfig) {
688 ieee80211_hw_config(local);
689 /* The return value of hw_config is not of big interest here,
690 * as it doesn't say that it failed because of _this_ config
691 * change or something else. Ignore it. */
692 }
693
694 return 0;
695}
696
Larry Fingerfe6aa302007-08-10 11:23:20 -0500697static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
698 struct iw_request_info *info,
699 union iwreq_data *data, char *extra)
700{
701 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
702
703 data->txpower.fixed = 1;
704 data->txpower.disabled = !(local->hw.conf.radio_enabled);
705 data->txpower.value = local->hw.conf.power_level;
706 data->txpower.flags = IW_TXPOW_DBM;
707
708 return 0;
709}
710
Jiri Bencf0706e82007-05-05 11:45:53 -0700711static int ieee80211_ioctl_siwrts(struct net_device *dev,
712 struct iw_request_info *info,
713 struct iw_param *rts, char *extra)
714{
715 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
716
717 if (rts->disabled)
718 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
719 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
720 return -EINVAL;
721 else
722 local->rts_threshold = rts->value;
723
724 /* If the wlan card performs RTS/CTS in hardware/firmware,
725 * configure it here */
726
727 if (local->ops->set_rts_threshold)
728 local->ops->set_rts_threshold(local_to_hw(local),
729 local->rts_threshold);
730
731 return 0;
732}
733
734static int ieee80211_ioctl_giwrts(struct net_device *dev,
735 struct iw_request_info *info,
736 struct iw_param *rts, char *extra)
737{
738 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
739
740 rts->value = local->rts_threshold;
741 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
742 rts->fixed = 1;
743
744 return 0;
745}
746
747
748static int ieee80211_ioctl_siwfrag(struct net_device *dev,
749 struct iw_request_info *info,
750 struct iw_param *frag, char *extra)
751{
752 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
753
754 if (frag->disabled)
755 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
756 else if (frag->value < 256 ||
757 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
758 return -EINVAL;
759 else {
760 /* Fragment length must be even, so strip LSB. */
761 local->fragmentation_threshold = frag->value & ~0x1;
762 }
763
764 /* If the wlan card performs fragmentation in hardware/firmware,
765 * configure it here */
766
767 if (local->ops->set_frag_threshold)
768 local->ops->set_frag_threshold(
769 local_to_hw(local),
770 local->fragmentation_threshold);
771
772 return 0;
773}
774
775static int ieee80211_ioctl_giwfrag(struct net_device *dev,
776 struct iw_request_info *info,
777 struct iw_param *frag, char *extra)
778{
779 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
780
781 frag->value = local->fragmentation_threshold;
782 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
783 frag->fixed = 1;
784
785 return 0;
786}
787
788
789static int ieee80211_ioctl_siwretry(struct net_device *dev,
790 struct iw_request_info *info,
791 struct iw_param *retry, char *extra)
792{
793 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
794
795 if (retry->disabled ||
796 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
797 return -EINVAL;
798
799 if (retry->flags & IW_RETRY_MAX)
800 local->long_retry_limit = retry->value;
801 else if (retry->flags & IW_RETRY_MIN)
802 local->short_retry_limit = retry->value;
803 else {
804 local->long_retry_limit = retry->value;
805 local->short_retry_limit = retry->value;
806 }
807
808 if (local->ops->set_retry_limit) {
809 return local->ops->set_retry_limit(
810 local_to_hw(local),
811 local->short_retry_limit,
812 local->long_retry_limit);
813 }
814
815 return 0;
816}
817
818
819static int ieee80211_ioctl_giwretry(struct net_device *dev,
820 struct iw_request_info *info,
821 struct iw_param *retry, char *extra)
822{
823 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
824
825 retry->disabled = 0;
826 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
827 /* first return min value, iwconfig will ask max value
828 * later if needed */
829 retry->flags |= IW_RETRY_LIMIT;
830 retry->value = local->short_retry_limit;
831 if (local->long_retry_limit != local->short_retry_limit)
832 retry->flags |= IW_RETRY_MIN;
833 return 0;
834 }
835 if (retry->flags & IW_RETRY_MAX) {
836 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
837 retry->value = local->long_retry_limit;
838 }
839
840 return 0;
841}
842
Jiri Bencf0706e82007-05-05 11:45:53 -0700843static int ieee80211_ioctl_siwmlme(struct net_device *dev,
844 struct iw_request_info *info,
845 struct iw_point *data, char *extra)
846{
847 struct ieee80211_sub_if_data *sdata;
848 struct iw_mlme *mlme = (struct iw_mlme *) extra;
849
850 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100851 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
852 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700853 return -EINVAL;
854
855 switch (mlme->cmd) {
856 case IW_MLME_DEAUTH:
857 /* TODO: mlme->addr.sa_data */
858 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
859 case IW_MLME_DISASSOC:
860 /* TODO: mlme->addr.sa_data */
861 return ieee80211_sta_disassociate(dev, mlme->reason_code);
862 default:
863 return -EOPNOTSUPP;
864 }
865}
866
867
868static int ieee80211_ioctl_siwencode(struct net_device *dev,
869 struct iw_request_info *info,
870 struct iw_point *erq, char *keybuf)
871{
872 struct ieee80211_sub_if_data *sdata;
873 int idx, i, alg = ALG_WEP;
874 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200875 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700876
877 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
878
879 idx = erq->flags & IW_ENCODE_INDEX;
880 if (idx == 0) {
881 if (sdata->default_key)
882 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
883 if (sdata->default_key == sdata->keys[i]) {
884 idx = i;
885 break;
886 }
887 }
888 } else if (idx < 1 || idx > 4)
889 return -EINVAL;
890 else
891 idx--;
892
893 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200894 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700895 else if (erq->length == 0) {
896 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400897 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700898 return 0;
899 }
900
901 return ieee80211_set_encryption(
902 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200903 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700904 !sdata->default_key,
905 keybuf, erq->length);
906}
907
908
909static int ieee80211_ioctl_giwencode(struct net_device *dev,
910 struct iw_request_info *info,
911 struct iw_point *erq, char *key)
912{
913 struct ieee80211_sub_if_data *sdata;
914 int idx, i;
915
916 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
917
918 idx = erq->flags & IW_ENCODE_INDEX;
919 if (idx < 1 || idx > 4) {
920 idx = -1;
921 if (!sdata->default_key)
922 idx = 0;
923 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
924 if (sdata->default_key == sdata->keys[i]) {
925 idx = i;
926 break;
927 }
928 }
929 if (idx < 0)
930 return -EINVAL;
931 } else
932 idx--;
933
934 erq->flags = idx + 1;
935
936 if (!sdata->keys[idx]) {
937 erq->length = 0;
938 erq->flags |= IW_ENCODE_DISABLED;
939 return 0;
940 }
941
Johannes Berg8f20fc22007-08-28 17:01:54 -0400942 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400943 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400944 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700945 erq->flags |= IW_ENCODE_ENABLED;
946
947 return 0;
948}
949
950static int ieee80211_ioctl_siwauth(struct net_device *dev,
951 struct iw_request_info *info,
952 struct iw_param *data, char *extra)
953{
Jiri Bencf0706e82007-05-05 11:45:53 -0700954 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
955 int ret = 0;
956
957 switch (data->flags & IW_AUTH_INDEX) {
958 case IW_AUTH_WPA_VERSION:
959 case IW_AUTH_CIPHER_PAIRWISE:
960 case IW_AUTH_CIPHER_GROUP:
961 case IW_AUTH_WPA_ENABLED:
962 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700963 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000964 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100965 case IW_AUTH_DROP_UNENCRYPTED:
966 sdata->drop_unencrypted = !!data->value;
967 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000968 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100969 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700970 ret = -EINVAL;
971 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000972 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700973 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000974 * Privacy invoked by wpa_supplicant, store the
975 * value and allow associating to a protected
976 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700977 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000978 if (data->value)
979 sdata->u.sta.flags |=
980 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700981 }
982 break;
983 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100984 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
985 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700986 sdata->u.sta.auth_algs = data->value;
987 else
988 ret = -EOPNOTSUPP;
989 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700990 default:
991 ret = -EOPNOTSUPP;
992 break;
993 }
994 return ret;
995}
996
997/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
998static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
999{
1000 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
1001 struct iw_statistics *wstats = &local->wstats;
1002 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1003 struct sta_info *sta = NULL;
1004
Johannes Berg98dd6a52008-04-10 15:36:09 +02001005 rcu_read_lock();
1006
Johannes Berg51fb61e2007-12-19 01:31:27 +01001007 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1008 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001009 sta = sta_info_get(local, sdata->u.sta.bssid);
1010 if (!sta) {
1011 wstats->discard.fragment = 0;
1012 wstats->discard.misc = 0;
1013 wstats->qual.qual = 0;
1014 wstats->qual.level = 0;
1015 wstats->qual.noise = 0;
1016 wstats->qual.updated = IW_QUAL_ALL_INVALID;
1017 } else {
1018 wstats->qual.level = sta->last_rssi;
1019 wstats->qual.qual = sta->last_signal;
1020 wstats->qual.noise = sta->last_noise;
1021 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -07001022 }
Johannes Berg98dd6a52008-04-10 15:36:09 +02001023
1024 rcu_read_unlock();
1025
Jiri Bencf0706e82007-05-05 11:45:53 -07001026 return wstats;
1027}
1028
1029static int ieee80211_ioctl_giwauth(struct net_device *dev,
1030 struct iw_request_info *info,
1031 struct iw_param *data, char *extra)
1032{
1033 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1034 int ret = 0;
1035
1036 switch (data->flags & IW_AUTH_INDEX) {
1037 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001038 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1039 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001040 data->value = sdata->u.sta.auth_algs;
1041 else
1042 ret = -EOPNOTSUPP;
1043 break;
1044 default:
1045 ret = -EOPNOTSUPP;
1046 break;
1047 }
1048 return ret;
1049}
1050
1051
1052static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1053 struct iw_request_info *info,
1054 struct iw_point *erq, char *extra)
1055{
1056 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1057 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001058 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001059
1060 switch (ext->alg) {
1061 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001062 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001063 break;
1064 case IW_ENCODE_ALG_WEP:
1065 alg = ALG_WEP;
1066 break;
1067 case IW_ENCODE_ALG_TKIP:
1068 alg = ALG_TKIP;
1069 break;
1070 case IW_ENCODE_ALG_CCMP:
1071 alg = ALG_CCMP;
1072 break;
1073 default:
1074 return -EOPNOTSUPP;
1075 }
1076
1077 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001078 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001079
1080 idx = erq->flags & IW_ENCODE_INDEX;
1081 if (idx < 1 || idx > 4) {
1082 idx = -1;
1083 if (!sdata->default_key)
1084 idx = 0;
1085 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1086 if (sdata->default_key == sdata->keys[i]) {
1087 idx = i;
1088 break;
1089 }
1090 }
1091 if (idx < 0)
1092 return -EINVAL;
1093 } else
1094 idx--;
1095
1096 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001097 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001098 ext->ext_flags &
1099 IW_ENCODE_EXT_SET_TX_KEY,
1100 ext->key, ext->key_len);
1101}
1102
1103
Jiri Bencf0706e82007-05-05 11:45:53 -07001104/* Structures to export the Wireless Handlers */
1105
1106static const iw_handler ieee80211_handler[] =
1107{
1108 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1109 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1110 (iw_handler) NULL, /* SIOCSIWNWID */
1111 (iw_handler) NULL, /* SIOCGIWNWID */
1112 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1113 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1114 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1115 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1116 (iw_handler) NULL, /* SIOCSIWSENS */
1117 (iw_handler) NULL, /* SIOCGIWSENS */
1118 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1119 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1120 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1121 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1122 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1123 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001124 (iw_handler) NULL, /* SIOCSIWSPY */
1125 (iw_handler) NULL, /* SIOCGIWSPY */
1126 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1127 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001128 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1129 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1130 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1131 (iw_handler) NULL, /* SIOCGIWAPLIST */
1132 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1133 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1134 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1135 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1136 (iw_handler) NULL, /* SIOCSIWNICKN */
1137 (iw_handler) NULL, /* SIOCGIWNICKN */
1138 (iw_handler) NULL, /* -- hole -- */
1139 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001140 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001141 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001142 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1143 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1144 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1145 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001146 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001147 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001148 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1149 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1150 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1151 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1152 (iw_handler) NULL, /* SIOCSIWPOWER */
1153 (iw_handler) NULL, /* SIOCGIWPOWER */
1154 (iw_handler) NULL, /* -- hole -- */
1155 (iw_handler) NULL, /* -- hole -- */
1156 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1157 (iw_handler) NULL, /* SIOCGIWGENIE */
1158 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1159 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1160 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1161 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1162 (iw_handler) NULL, /* SIOCSIWPMKSA */
1163 (iw_handler) NULL, /* -- hole -- */
1164};
1165
Jiri Bencf0706e82007-05-05 11:45:53 -07001166const struct iw_handler_def ieee80211_iw_handler_def =
1167{
1168 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001169 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001170 .get_wireless_stats = ieee80211_get_wireless_stats,
1171};