blob: 38e2d83e15f4014dddb1b175ca558392016616e7 [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"
Ivo van Doorncdcb0062008-01-07 19:45:24 +010024#include "ieee80211_led.h"
Jiri Bencf0706e82007-05-05 11:45:53 -070025#include "ieee80211_rate.h"
26#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 Bergdb4d1162008-02-25 16:27:45 +010036 int ret;
37 struct sta_info *sta = NULL;
Johannes Berg11a843b2007-08-28 17:01:55 -040038 struct ieee80211_key *key;
Jiri Bencf0706e82007-05-05 11:45:53 -070039 struct ieee80211_sub_if_data *sdata;
40
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 Bergdb4d1162008-02-25 16:27:45 +010050 if (is_broadcast_ether_addr(sta_addr)) {
51 key = sdata->keys[idx];
52 } else {
53 sta = sta_info_get(local, sta_addr);
54 if (!sta) {
55 ret = -ENOENT;
56 key = NULL;
57 goto err_out;
58 }
59
60 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070061 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010062
63 if (!key)
64 ret = -ENOENT;
65 else
66 ret = 0;
67 } else {
68 key = ieee80211_key_alloc(alg, idx, key_len, _key);
69 if (!key)
70 return -ENOMEM;
71
72 if (!is_broadcast_ether_addr(sta_addr)) {
73 set_tx_key = 0;
74 /*
75 * According to the standard, the key index of a
76 * pairwise key must be zero. However, some AP are
77 * broken when it comes to WEP key indices, so we
78 * work around this.
79 */
80 if (idx != 0 && alg != ALG_WEP) {
81 ret = -EINVAL;
82 goto err_out;
83 }
84
85 sta = sta_info_get(local, sta_addr);
86 if (!sta) {
87 ret = -ENOENT;
88 goto err_out;
89 }
90 }
91
92 ieee80211_key_link(key, sdata, sta);
93
94 if (set_tx_key || (!sta && !sdata->default_key && key))
95 ieee80211_set_default_key(sdata, idx);
96
97 /* don't free key later */
98 key = NULL;
99
100 ret = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700101 }
102
Johannes Berg11a843b2007-08-28 17:01:55 -0400103 err_out:
Jiri Bencf0706e82007-05-05 11:45:53 -0700104 if (sta)
105 sta_info_put(sta);
Johannes Bergdb4d1162008-02-25 16:27:45 +0100106 ieee80211_key_free(key);
Jiri Bencf0706e82007-05-05 11:45:53 -0700107 return ret;
108}
109
110static int ieee80211_ioctl_siwgenie(struct net_device *dev,
111 struct iw_request_info *info,
112 struct iw_point *data, char *extra)
113{
114 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -0700115
116 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200117
118 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
119 return -EOPNOTSUPP;
120
Johannes Berg51fb61e2007-12-19 01:31:27 +0100121 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
122 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700123 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
124 if (ret)
125 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400126 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700127 ieee80211_sta_req_auth(dev, &sdata->u.sta);
128 return 0;
129 }
130
Jiri Bencf0706e82007-05-05 11:45:53 -0700131 return -EOPNOTSUPP;
132}
133
Jiri Bencf0706e82007-05-05 11:45:53 -0700134static int ieee80211_ioctl_giwname(struct net_device *dev,
135 struct iw_request_info *info,
136 char *name, char *extra)
137{
Johannes Berg8318d782008-01-24 19:38:38 +0100138 strcpy(name, "IEEE 802.11");
Jiri Bencf0706e82007-05-05 11:45:53 -0700139
140 return 0;
141}
142
143
144static int ieee80211_ioctl_giwrange(struct net_device *dev,
145 struct iw_request_info *info,
146 struct iw_point *data, char *extra)
147{
148 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
149 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100150 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200151 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700152
153 data->length = sizeof(struct iw_range);
154 memset(range, 0, sizeof(struct iw_range));
155
156 range->we_version_compiled = WIRELESS_EXT;
157 range->we_version_source = 21;
158 range->retry_capa = IW_RETRY_LIMIT;
159 range->retry_flags = IW_RETRY_LIMIT;
160 range->min_retry = 0;
161 range->max_retry = 255;
162 range->min_rts = 0;
163 range->max_rts = 2347;
164 range->min_frag = 256;
165 range->max_frag = 2346;
166
167 range->encoding_size[0] = 5;
168 range->encoding_size[1] = 13;
169 range->num_encoding_sizes = 2;
170 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
171
172 range->max_qual.qual = local->hw.max_signal;
173 range->max_qual.level = local->hw.max_rssi;
174 range->max_qual.noise = local->hw.max_noise;
175 range->max_qual.updated = local->wstats_flags;
176
177 range->avg_qual.qual = local->hw.max_signal/2;
178 range->avg_qual.level = 0;
179 range->avg_qual.noise = 0;
180 range->avg_qual.updated = local->wstats_flags;
181
182 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
183 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
184
Hong Liu333af2f2007-07-10 19:32:08 +0200185
Johannes Berg8318d782008-01-24 19:38:38 +0100186 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
187 int i;
188 struct ieee80211_supported_band *sband;
189
190 sband = local->hw.wiphy->bands[band];
191
192 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200193 continue;
194
Johannes Berg8318d782008-01-24 19:38:38 +0100195 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
196 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200197
Johannes Berg8318d782008-01-24 19:38:38 +0100198 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
199 range->freq[c].i =
200 ieee80211_frequency_to_channel(
201 chan->center_freq);
202 range->freq[c].m = chan->center_freq;
203 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200204 c++;
205 }
Hong Liu333af2f2007-07-10 19:32:08 +0200206 }
207 }
208 range->num_channels = c;
209 range->num_frequency = c;
210
Jiri Bencf0706e82007-05-05 11:45:53 -0700211 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
212 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
213 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
214 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
215
Dan Williams374fdfb2007-12-12 10:25:07 -0500216 range->scan_capa |= IW_SCAN_CAPA_ESSID;
217
Jiri Bencf0706e82007-05-05 11:45:53 -0700218 return 0;
219}
220
221
Jiri Bencf0706e82007-05-05 11:45:53 -0700222static int ieee80211_ioctl_siwmode(struct net_device *dev,
223 struct iw_request_info *info,
224 __u32 *mode, char *extra)
225{
226 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
227 int type;
228
Johannes Berg51fb61e2007-12-19 01:31:27 +0100229 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700230 return -EOPNOTSUPP;
231
232 switch (*mode) {
233 case IW_MODE_INFRA:
234 type = IEEE80211_IF_TYPE_STA;
235 break;
236 case IW_MODE_ADHOC:
237 type = IEEE80211_IF_TYPE_IBSS;
238 break;
239 case IW_MODE_MONITOR:
240 type = IEEE80211_IF_TYPE_MNTR;
241 break;
242 default:
243 return -EINVAL;
244 }
245
Johannes Berg51fb61e2007-12-19 01:31:27 +0100246 if (type == sdata->vif.type)
Jiri Bencf0706e82007-05-05 11:45:53 -0700247 return 0;
248 if (netif_running(dev))
249 return -EBUSY;
250
251 ieee80211_if_reinit(dev);
252 ieee80211_if_set_type(dev, type);
253
254 return 0;
255}
256
257
258static int ieee80211_ioctl_giwmode(struct net_device *dev,
259 struct iw_request_info *info,
260 __u32 *mode, char *extra)
261{
262 struct ieee80211_sub_if_data *sdata;
263
264 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100265 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700266 case IEEE80211_IF_TYPE_AP:
267 *mode = IW_MODE_MASTER;
268 break;
269 case IEEE80211_IF_TYPE_STA:
270 *mode = IW_MODE_INFRA;
271 break;
272 case IEEE80211_IF_TYPE_IBSS:
273 *mode = IW_MODE_ADHOC;
274 break;
275 case IEEE80211_IF_TYPE_MNTR:
276 *mode = IW_MODE_MONITOR;
277 break;
278 case IEEE80211_IF_TYPE_WDS:
279 *mode = IW_MODE_REPEAT;
280 break;
281 case IEEE80211_IF_TYPE_VLAN:
282 *mode = IW_MODE_SECOND; /* FIXME */
283 break;
284 default:
285 *mode = IW_MODE_AUTO;
286 break;
287 }
288 return 0;
289}
290
Johannes Berg8318d782008-01-24 19:38:38 +0100291int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700292{
Johannes Berg8318d782008-01-24 19:38:38 +0100293 int set = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700294 int ret = -EINVAL;
Johannes Berg8318d782008-01-24 19:38:38 +0100295 enum ieee80211_band band;
296 struct ieee80211_supported_band *sband;
297 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700298
Johannes Berg8318d782008-01-24 19:38:38 +0100299 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
300 sband = local->hw.wiphy->bands[band];
301
302 if (!sband)
Jiri Bencf0706e82007-05-05 11:45:53 -0700303 continue;
Johannes Berg8318d782008-01-24 19:38:38 +0100304
305 for (i = 0; i < sband->n_channels; i++) {
306 struct ieee80211_channel *chan = &sband->channels[i];
307
308 if (chan->flags & IEEE80211_CHAN_DISABLED)
309 continue;
310
311 if (chan->center_freq == freqMHz) {
Johannes Berg58a9ac12007-10-12 21:24:07 +0200312 set = 1;
Johannes Berg8318d782008-01-24 19:38:38 +0100313 local->oper_channel = chan;
Johannes Berg58a9ac12007-10-12 21:24:07 +0200314 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700315 }
316 }
Johannes Berg58a9ac12007-10-12 21:24:07 +0200317 if (set)
318 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700319 }
320
321 if (set) {
Zhu Yiece8edd2007-11-22 10:53:21 +0800322 if (local->sta_sw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700323 ret = 0;
324 else
325 ret = ieee80211_hw_config(local);
326
327 rate_control_clear(local);
328 }
329
330 return ret;
331}
332
333static int ieee80211_ioctl_siwfreq(struct net_device *dev,
334 struct iw_request_info *info,
335 struct iw_freq *freq, char *extra)
336{
337 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
338 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
339
Johannes Berg51fb61e2007-12-19 01:31:27 +0100340 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400341 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700342
343 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
344 if (freq->e == 0) {
345 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100346 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400347 sdata->u.sta.flags |=
348 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700349 return 0;
350 } else
Johannes Berg8318d782008-01-24 19:38:38 +0100351 return ieee80211_set_freq(local,
352 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700353 } else {
354 int i, div = 1000000;
355 for (i = 0; i < freq->e; i++)
356 div /= 10;
357 if (div > 0)
Johannes Berg8318d782008-01-24 19:38:38 +0100358 return ieee80211_set_freq(local, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700359 else
360 return -EINVAL;
361 }
362}
363
364
365static int ieee80211_ioctl_giwfreq(struct net_device *dev,
366 struct iw_request_info *info,
367 struct iw_freq *freq, char *extra)
368{
369 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
370
Johannes Berg8318d782008-01-24 19:38:38 +0100371 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700372 freq->e = 6;
373
374 return 0;
375}
376
377
378static int ieee80211_ioctl_siwessid(struct net_device *dev,
379 struct iw_request_info *info,
380 struct iw_point *data, char *ssid)
381{
Jiri Bencf0706e82007-05-05 11:45:53 -0700382 struct ieee80211_sub_if_data *sdata;
383 size_t len = data->length;
384
385 /* iwconfig uses nul termination in SSID.. */
386 if (len > 0 && ssid[len - 1] == '\0')
387 len--;
388
389 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100390 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
391 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700392 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200393 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700394 if (len > IEEE80211_MAX_SSID_LEN)
395 return -EINVAL;
396 memcpy(sdata->u.sta.ssid, ssid, len);
397 sdata->u.sta.ssid_len = len;
398 return 0;
399 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400400 if (data->flags)
401 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
402 else
403 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700404 ret = ieee80211_sta_set_ssid(dev, ssid, len);
405 if (ret)
406 return ret;
407 ieee80211_sta_req_auth(dev, &sdata->u.sta);
408 return 0;
409 }
410
Johannes Berg51fb61e2007-12-19 01:31:27 +0100411 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700412 memcpy(sdata->u.ap.ssid, ssid, len);
413 memset(sdata->u.ap.ssid + len, 0,
414 IEEE80211_MAX_SSID_LEN - len);
415 sdata->u.ap.ssid_len = len;
416 return ieee80211_if_config(dev);
417 }
418 return -EOPNOTSUPP;
419}
420
421
422static int ieee80211_ioctl_giwessid(struct net_device *dev,
423 struct iw_request_info *info,
424 struct iw_point *data, char *ssid)
425{
426 size_t len;
427
428 struct ieee80211_sub_if_data *sdata;
429 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100430 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
431 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700432 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
433 if (res == 0) {
434 data->length = len;
435 data->flags = 1;
436 } else
437 data->flags = 0;
438 return res;
439 }
440
Johannes Berg51fb61e2007-12-19 01:31:27 +0100441 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700442 len = sdata->u.ap.ssid_len;
443 if (len > IW_ESSID_MAX_SIZE)
444 len = IW_ESSID_MAX_SIZE;
445 memcpy(ssid, sdata->u.ap.ssid, len);
446 data->length = len;
447 data->flags = 1;
448 return 0;
449 }
450 return -EOPNOTSUPP;
451}
452
453
454static int ieee80211_ioctl_siwap(struct net_device *dev,
455 struct iw_request_info *info,
456 struct sockaddr *ap_addr, char *extra)
457{
Jiri Bencf0706e82007-05-05 11:45:53 -0700458 struct ieee80211_sub_if_data *sdata;
459
460 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100461 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
462 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700463 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200464 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700465 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
466 ETH_ALEN);
467 return 0;
468 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400469 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
470 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
471 IEEE80211_STA_AUTO_CHANNEL_SEL;
472 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
473 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700474 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400475 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700476 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
477 if (ret)
478 return ret;
479 ieee80211_sta_req_auth(dev, &sdata->u.sta);
480 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100481 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700482 if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
483 ETH_ALEN) == 0)
484 return 0;
485 return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
486 }
487
488 return -EOPNOTSUPP;
489}
490
491
492static int ieee80211_ioctl_giwap(struct net_device *dev,
493 struct iw_request_info *info,
494 struct sockaddr *ap_addr, char *extra)
495{
496 struct ieee80211_sub_if_data *sdata;
497
498 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100499 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
500 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700501 ap_addr->sa_family = ARPHRD_ETHER;
502 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
503 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100504 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700505 ap_addr->sa_family = ARPHRD_ETHER;
506 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
507 return 0;
508 }
509
510 return -EOPNOTSUPP;
511}
512
513
514static int ieee80211_ioctl_siwscan(struct net_device *dev,
515 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400516 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700517{
Jiri Bencf0706e82007-05-05 11:45:53 -0700518 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400519 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700520 u8 *ssid = NULL;
521 size_t ssid_len = 0;
522
523 if (!netif_running(dev))
524 return -ENETDOWN;
525
Johannes Berg51fb61e2007-12-19 01:31:27 +0100526 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
527 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100528 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100529 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700530 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700531
532 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400533 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
534 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
535 req = (struct iw_scan_req *)extra;
536 ssid = req->essid;
537 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700538 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200539
Jiri Bencf0706e82007-05-05 11:45:53 -0700540 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
541}
542
543
544static int ieee80211_ioctl_giwscan(struct net_device *dev,
545 struct iw_request_info *info,
546 struct iw_point *data, char *extra)
547{
548 int res;
549 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800550
551 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700552 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800553
Jiri Bencf0706e82007-05-05 11:45:53 -0700554 res = ieee80211_sta_scan_results(dev, extra, data->length);
555 if (res >= 0) {
556 data->length = res;
557 return 0;
558 }
559 data->length = 0;
560 return res;
561}
562
563
Larry Finger1fd5e582007-07-10 19:32:10 +0200564static int ieee80211_ioctl_siwrate(struct net_device *dev,
565 struct iw_request_info *info,
566 struct iw_param *rate, char *extra)
567{
568 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100569 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200570 u32 target_rate = rate->value / 100000;
571 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100572 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200573
574 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
575 if (!sdata->bss)
576 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100577
578 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
579
Larry Finger1fd5e582007-07-10 19:32:10 +0200580 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
581 * target_rate = X, rate->fixed = 1 means only rate X
582 * target_rate = X, rate->fixed = 0 means all rates <= X */
583 sdata->bss->max_ratectrl_rateidx = -1;
584 sdata->bss->force_unicast_rateidx = -1;
585 if (rate->value < 0)
586 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100587
588 for (i=0; i< sband->n_bitrates; i++) {
589 struct ieee80211_rate *brate = &sband->bitrates[i];
590 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200591
Larry Finger1fd5e582007-07-10 19:32:10 +0200592 if (target_rate == this_rate) {
593 sdata->bss->max_ratectrl_rateidx = i;
594 if (rate->fixed)
595 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100596 err = 0;
597 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200598 }
599 }
Johannes Berg8318d782008-01-24 19:38:38 +0100600 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200601}
602
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700603static int ieee80211_ioctl_giwrate(struct net_device *dev,
604 struct iw_request_info *info,
605 struct iw_param *rate, char *extra)
606{
607 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
608 struct sta_info *sta;
609 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100610 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700611
612 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100613
Johannes Berg51fb61e2007-12-19 01:31:27 +0100614 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700615 sta = sta_info_get(local, sdata->u.sta.bssid);
616 else
617 return -EOPNOTSUPP;
618 if (!sta)
619 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100620
621 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
622
623 if (sta->txrate_idx < sband->n_bitrates)
624 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700625 else
626 rate->value = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100627 rate->value *= 100000;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700628 sta_info_put(sta);
629 return 0;
630}
631
Michael Buesch61609bc2007-09-20 22:06:39 +0200632static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
633 struct iw_request_info *info,
634 union iwreq_data *data, char *extra)
635{
636 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
637 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100638 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200639
640 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
641 return -EINVAL;
642 if (data->txpower.flags & IW_TXPOW_RANGE)
643 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200644
Mattias Nissler6a432952007-10-24 23:30:36 +0200645 if (data->txpower.fixed) {
646 new_power_level = data->txpower.value;
647 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100648 /*
649 * Automatic power level. Use maximum power for the current
650 * channel. Should be part of rate control.
651 */
652 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200653 if (!chan)
654 return -EINVAL;
655
Johannes Berg8318d782008-01-24 19:38:38 +0100656 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200657 }
658
659 if (local->hw.conf.power_level != new_power_level) {
660 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200661 need_reconfig = 1;
662 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200663
Michael Buesch61609bc2007-09-20 22:06:39 +0200664 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
665 local->hw.conf.radio_enabled = !(data->txpower.disabled);
666 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100667 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200668 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200669
Michael Buesch61609bc2007-09-20 22:06:39 +0200670 if (need_reconfig) {
671 ieee80211_hw_config(local);
672 /* The return value of hw_config is not of big interest here,
673 * as it doesn't say that it failed because of _this_ config
674 * change or something else. Ignore it. */
675 }
676
677 return 0;
678}
679
Larry Fingerfe6aa302007-08-10 11:23:20 -0500680static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
681 struct iw_request_info *info,
682 union iwreq_data *data, char *extra)
683{
684 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
685
686 data->txpower.fixed = 1;
687 data->txpower.disabled = !(local->hw.conf.radio_enabled);
688 data->txpower.value = local->hw.conf.power_level;
689 data->txpower.flags = IW_TXPOW_DBM;
690
691 return 0;
692}
693
Jiri Bencf0706e82007-05-05 11:45:53 -0700694static int ieee80211_ioctl_siwrts(struct net_device *dev,
695 struct iw_request_info *info,
696 struct iw_param *rts, char *extra)
697{
698 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
699
700 if (rts->disabled)
701 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
702 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
703 return -EINVAL;
704 else
705 local->rts_threshold = rts->value;
706
707 /* If the wlan card performs RTS/CTS in hardware/firmware,
708 * configure it here */
709
710 if (local->ops->set_rts_threshold)
711 local->ops->set_rts_threshold(local_to_hw(local),
712 local->rts_threshold);
713
714 return 0;
715}
716
717static int ieee80211_ioctl_giwrts(struct net_device *dev,
718 struct iw_request_info *info,
719 struct iw_param *rts, char *extra)
720{
721 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
722
723 rts->value = local->rts_threshold;
724 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
725 rts->fixed = 1;
726
727 return 0;
728}
729
730
731static int ieee80211_ioctl_siwfrag(struct net_device *dev,
732 struct iw_request_info *info,
733 struct iw_param *frag, char *extra)
734{
735 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
736
737 if (frag->disabled)
738 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
739 else if (frag->value < 256 ||
740 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
741 return -EINVAL;
742 else {
743 /* Fragment length must be even, so strip LSB. */
744 local->fragmentation_threshold = frag->value & ~0x1;
745 }
746
747 /* If the wlan card performs fragmentation in hardware/firmware,
748 * configure it here */
749
750 if (local->ops->set_frag_threshold)
751 local->ops->set_frag_threshold(
752 local_to_hw(local),
753 local->fragmentation_threshold);
754
755 return 0;
756}
757
758static int ieee80211_ioctl_giwfrag(struct net_device *dev,
759 struct iw_request_info *info,
760 struct iw_param *frag, char *extra)
761{
762 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
763
764 frag->value = local->fragmentation_threshold;
765 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
766 frag->fixed = 1;
767
768 return 0;
769}
770
771
772static int ieee80211_ioctl_siwretry(struct net_device *dev,
773 struct iw_request_info *info,
774 struct iw_param *retry, char *extra)
775{
776 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
777
778 if (retry->disabled ||
779 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
780 return -EINVAL;
781
782 if (retry->flags & IW_RETRY_MAX)
783 local->long_retry_limit = retry->value;
784 else if (retry->flags & IW_RETRY_MIN)
785 local->short_retry_limit = retry->value;
786 else {
787 local->long_retry_limit = retry->value;
788 local->short_retry_limit = retry->value;
789 }
790
791 if (local->ops->set_retry_limit) {
792 return local->ops->set_retry_limit(
793 local_to_hw(local),
794 local->short_retry_limit,
795 local->long_retry_limit);
796 }
797
798 return 0;
799}
800
801
802static int ieee80211_ioctl_giwretry(struct net_device *dev,
803 struct iw_request_info *info,
804 struct iw_param *retry, char *extra)
805{
806 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
807
808 retry->disabled = 0;
809 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
810 /* first return min value, iwconfig will ask max value
811 * later if needed */
812 retry->flags |= IW_RETRY_LIMIT;
813 retry->value = local->short_retry_limit;
814 if (local->long_retry_limit != local->short_retry_limit)
815 retry->flags |= IW_RETRY_MIN;
816 return 0;
817 }
818 if (retry->flags & IW_RETRY_MAX) {
819 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
820 retry->value = local->long_retry_limit;
821 }
822
823 return 0;
824}
825
Jiri Bencf0706e82007-05-05 11:45:53 -0700826static int ieee80211_ioctl_siwmlme(struct net_device *dev,
827 struct iw_request_info *info,
828 struct iw_point *data, char *extra)
829{
830 struct ieee80211_sub_if_data *sdata;
831 struct iw_mlme *mlme = (struct iw_mlme *) extra;
832
833 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100834 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
835 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700836 return -EINVAL;
837
838 switch (mlme->cmd) {
839 case IW_MLME_DEAUTH:
840 /* TODO: mlme->addr.sa_data */
841 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
842 case IW_MLME_DISASSOC:
843 /* TODO: mlme->addr.sa_data */
844 return ieee80211_sta_disassociate(dev, mlme->reason_code);
845 default:
846 return -EOPNOTSUPP;
847 }
848}
849
850
851static int ieee80211_ioctl_siwencode(struct net_device *dev,
852 struct iw_request_info *info,
853 struct iw_point *erq, char *keybuf)
854{
855 struct ieee80211_sub_if_data *sdata;
856 int idx, i, alg = ALG_WEP;
857 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200858 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700859
860 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
861
862 idx = erq->flags & IW_ENCODE_INDEX;
863 if (idx == 0) {
864 if (sdata->default_key)
865 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
866 if (sdata->default_key == sdata->keys[i]) {
867 idx = i;
868 break;
869 }
870 }
871 } else if (idx < 1 || idx > 4)
872 return -EINVAL;
873 else
874 idx--;
875
876 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200877 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700878 else if (erq->length == 0) {
879 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400880 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700881 return 0;
882 }
883
884 return ieee80211_set_encryption(
885 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200886 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700887 !sdata->default_key,
888 keybuf, erq->length);
889}
890
891
892static int ieee80211_ioctl_giwencode(struct net_device *dev,
893 struct iw_request_info *info,
894 struct iw_point *erq, char *key)
895{
896 struct ieee80211_sub_if_data *sdata;
897 int idx, i;
898
899 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
900
901 idx = erq->flags & IW_ENCODE_INDEX;
902 if (idx < 1 || idx > 4) {
903 idx = -1;
904 if (!sdata->default_key)
905 idx = 0;
906 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
907 if (sdata->default_key == sdata->keys[i]) {
908 idx = i;
909 break;
910 }
911 }
912 if (idx < 0)
913 return -EINVAL;
914 } else
915 idx--;
916
917 erq->flags = idx + 1;
918
919 if (!sdata->keys[idx]) {
920 erq->length = 0;
921 erq->flags |= IW_ENCODE_DISABLED;
922 return 0;
923 }
924
Johannes Berg8f20fc22007-08-28 17:01:54 -0400925 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400926 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400927 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700928 erq->flags |= IW_ENCODE_ENABLED;
929
930 return 0;
931}
932
933static int ieee80211_ioctl_siwauth(struct net_device *dev,
934 struct iw_request_info *info,
935 struct iw_param *data, char *extra)
936{
Jiri Bencf0706e82007-05-05 11:45:53 -0700937 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
938 int ret = 0;
939
940 switch (data->flags & IW_AUTH_INDEX) {
941 case IW_AUTH_WPA_VERSION:
942 case IW_AUTH_CIPHER_PAIRWISE:
943 case IW_AUTH_CIPHER_GROUP:
944 case IW_AUTH_WPA_ENABLED:
945 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700946 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000947 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100948 case IW_AUTH_DROP_UNENCRYPTED:
949 sdata->drop_unencrypted = !!data->value;
950 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000951 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100952 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700953 ret = -EINVAL;
954 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000955 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700956 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000957 * Privacy invoked by wpa_supplicant, store the
958 * value and allow associating to a protected
959 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700960 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000961 if (data->value)
962 sdata->u.sta.flags |=
963 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700964 }
965 break;
966 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100967 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
968 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700969 sdata->u.sta.auth_algs = data->value;
970 else
971 ret = -EOPNOTSUPP;
972 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700973 default:
974 ret = -EOPNOTSUPP;
975 break;
976 }
977 return ret;
978}
979
980/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
981static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
982{
983 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
984 struct iw_statistics *wstats = &local->wstats;
985 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
986 struct sta_info *sta = NULL;
987
Johannes Berg51fb61e2007-12-19 01:31:27 +0100988 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
989 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700990 sta = sta_info_get(local, sdata->u.sta.bssid);
991 if (!sta) {
992 wstats->discard.fragment = 0;
993 wstats->discard.misc = 0;
994 wstats->qual.qual = 0;
995 wstats->qual.level = 0;
996 wstats->qual.noise = 0;
997 wstats->qual.updated = IW_QUAL_ALL_INVALID;
998 } else {
999 wstats->qual.level = sta->last_rssi;
1000 wstats->qual.qual = sta->last_signal;
1001 wstats->qual.noise = sta->last_noise;
1002 wstats->qual.updated = local->wstats_flags;
1003 sta_info_put(sta);
1004 }
1005 return wstats;
1006}
1007
1008static int ieee80211_ioctl_giwauth(struct net_device *dev,
1009 struct iw_request_info *info,
1010 struct iw_param *data, char *extra)
1011{
1012 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1013 int ret = 0;
1014
1015 switch (data->flags & IW_AUTH_INDEX) {
1016 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001017 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1018 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001019 data->value = sdata->u.sta.auth_algs;
1020 else
1021 ret = -EOPNOTSUPP;
1022 break;
1023 default:
1024 ret = -EOPNOTSUPP;
1025 break;
1026 }
1027 return ret;
1028}
1029
1030
1031static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1032 struct iw_request_info *info,
1033 struct iw_point *erq, char *extra)
1034{
1035 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1036 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001037 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001038
1039 switch (ext->alg) {
1040 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001041 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001042 break;
1043 case IW_ENCODE_ALG_WEP:
1044 alg = ALG_WEP;
1045 break;
1046 case IW_ENCODE_ALG_TKIP:
1047 alg = ALG_TKIP;
1048 break;
1049 case IW_ENCODE_ALG_CCMP:
1050 alg = ALG_CCMP;
1051 break;
1052 default:
1053 return -EOPNOTSUPP;
1054 }
1055
1056 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001057 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001058
1059 idx = erq->flags & IW_ENCODE_INDEX;
1060 if (idx < 1 || idx > 4) {
1061 idx = -1;
1062 if (!sdata->default_key)
1063 idx = 0;
1064 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1065 if (sdata->default_key == sdata->keys[i]) {
1066 idx = i;
1067 break;
1068 }
1069 }
1070 if (idx < 0)
1071 return -EINVAL;
1072 } else
1073 idx--;
1074
1075 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001076 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001077 ext->ext_flags &
1078 IW_ENCODE_EXT_SET_TX_KEY,
1079 ext->key, ext->key_len);
1080}
1081
1082
Jiri Bencf0706e82007-05-05 11:45:53 -07001083/* Structures to export the Wireless Handlers */
1084
1085static const iw_handler ieee80211_handler[] =
1086{
1087 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1088 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1089 (iw_handler) NULL, /* SIOCSIWNWID */
1090 (iw_handler) NULL, /* SIOCGIWNWID */
1091 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1092 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1093 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1094 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1095 (iw_handler) NULL, /* SIOCSIWSENS */
1096 (iw_handler) NULL, /* SIOCGIWSENS */
1097 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1098 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1099 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1100 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1101 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1102 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001103 (iw_handler) NULL, /* SIOCSIWSPY */
1104 (iw_handler) NULL, /* SIOCGIWSPY */
1105 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1106 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001107 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1108 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1109 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1110 (iw_handler) NULL, /* SIOCGIWAPLIST */
1111 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1112 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1113 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1114 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1115 (iw_handler) NULL, /* SIOCSIWNICKN */
1116 (iw_handler) NULL, /* SIOCGIWNICKN */
1117 (iw_handler) NULL, /* -- hole -- */
1118 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001119 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001120 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001121 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1122 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1123 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1124 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001125 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001126 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001127 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1128 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1129 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1130 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1131 (iw_handler) NULL, /* SIOCSIWPOWER */
1132 (iw_handler) NULL, /* SIOCGIWPOWER */
1133 (iw_handler) NULL, /* -- hole -- */
1134 (iw_handler) NULL, /* -- hole -- */
1135 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1136 (iw_handler) NULL, /* SIOCGIWGENIE */
1137 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1138 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1139 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1140 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1141 (iw_handler) NULL, /* SIOCSIWPMKSA */
1142 (iw_handler) NULL, /* -- hole -- */
1143};
1144
Jiri Bencf0706e82007-05-05 11:45:53 -07001145const struct iw_handler_def ieee80211_iw_handler_def =
1146{
1147 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001148 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001149 .get_wireless_stats = ieee80211_get_wireless_stats,
1150};