blob: 7551db3f3abc7c75a993154092e96fcb6438e11f [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 &&
528 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700529 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700530
531 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400532 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
533 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
534 req = (struct iw_scan_req *)extra;
535 ssid = req->essid;
536 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700537 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200538
Jiri Bencf0706e82007-05-05 11:45:53 -0700539 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
540}
541
542
543static int ieee80211_ioctl_giwscan(struct net_device *dev,
544 struct iw_request_info *info,
545 struct iw_point *data, char *extra)
546{
547 int res;
548 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800549
550 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700551 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800552
Jiri Bencf0706e82007-05-05 11:45:53 -0700553 res = ieee80211_sta_scan_results(dev, extra, data->length);
554 if (res >= 0) {
555 data->length = res;
556 return 0;
557 }
558 data->length = 0;
559 return res;
560}
561
562
Larry Finger1fd5e582007-07-10 19:32:10 +0200563static int ieee80211_ioctl_siwrate(struct net_device *dev,
564 struct iw_request_info *info,
565 struct iw_param *rate, char *extra)
566{
567 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100568 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200569 u32 target_rate = rate->value / 100000;
570 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100571 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200572
573 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
574 if (!sdata->bss)
575 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100576
577 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
578
Larry Finger1fd5e582007-07-10 19:32:10 +0200579 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
580 * target_rate = X, rate->fixed = 1 means only rate X
581 * target_rate = X, rate->fixed = 0 means all rates <= X */
582 sdata->bss->max_ratectrl_rateidx = -1;
583 sdata->bss->force_unicast_rateidx = -1;
584 if (rate->value < 0)
585 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100586
587 for (i=0; i< sband->n_bitrates; i++) {
588 struct ieee80211_rate *brate = &sband->bitrates[i];
589 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200590
Larry Finger1fd5e582007-07-10 19:32:10 +0200591 if (target_rate == this_rate) {
592 sdata->bss->max_ratectrl_rateidx = i;
593 if (rate->fixed)
594 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100595 err = 0;
596 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200597 }
598 }
Johannes Berg8318d782008-01-24 19:38:38 +0100599 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200600}
601
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700602static int ieee80211_ioctl_giwrate(struct net_device *dev,
603 struct iw_request_info *info,
604 struct iw_param *rate, char *extra)
605{
606 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
607 struct sta_info *sta;
608 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100609 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700610
611 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100612
Johannes Berg51fb61e2007-12-19 01:31:27 +0100613 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700614 sta = sta_info_get(local, sdata->u.sta.bssid);
615 else
616 return -EOPNOTSUPP;
617 if (!sta)
618 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100619
620 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
621
622 if (sta->txrate_idx < sband->n_bitrates)
623 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700624 else
625 rate->value = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100626 rate->value *= 100000;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700627 sta_info_put(sta);
628 return 0;
629}
630
Michael Buesch61609bc2007-09-20 22:06:39 +0200631static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
632 struct iw_request_info *info,
633 union iwreq_data *data, char *extra)
634{
635 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
636 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100637 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200638
639 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
640 return -EINVAL;
641 if (data->txpower.flags & IW_TXPOW_RANGE)
642 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200643
Mattias Nissler6a432952007-10-24 23:30:36 +0200644 if (data->txpower.fixed) {
645 new_power_level = data->txpower.value;
646 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100647 /*
648 * Automatic power level. Use maximum power for the current
649 * channel. Should be part of rate control.
650 */
651 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200652 if (!chan)
653 return -EINVAL;
654
Johannes Berg8318d782008-01-24 19:38:38 +0100655 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200656 }
657
658 if (local->hw.conf.power_level != new_power_level) {
659 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200660 need_reconfig = 1;
661 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200662
Michael Buesch61609bc2007-09-20 22:06:39 +0200663 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
664 local->hw.conf.radio_enabled = !(data->txpower.disabled);
665 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100666 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200667 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200668
Michael Buesch61609bc2007-09-20 22:06:39 +0200669 if (need_reconfig) {
670 ieee80211_hw_config(local);
671 /* The return value of hw_config is not of big interest here,
672 * as it doesn't say that it failed because of _this_ config
673 * change or something else. Ignore it. */
674 }
675
676 return 0;
677}
678
Larry Fingerfe6aa302007-08-10 11:23:20 -0500679static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
680 struct iw_request_info *info,
681 union iwreq_data *data, char *extra)
682{
683 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
684
685 data->txpower.fixed = 1;
686 data->txpower.disabled = !(local->hw.conf.radio_enabled);
687 data->txpower.value = local->hw.conf.power_level;
688 data->txpower.flags = IW_TXPOW_DBM;
689
690 return 0;
691}
692
Jiri Bencf0706e82007-05-05 11:45:53 -0700693static int ieee80211_ioctl_siwrts(struct net_device *dev,
694 struct iw_request_info *info,
695 struct iw_param *rts, char *extra)
696{
697 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
698
699 if (rts->disabled)
700 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
701 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
702 return -EINVAL;
703 else
704 local->rts_threshold = rts->value;
705
706 /* If the wlan card performs RTS/CTS in hardware/firmware,
707 * configure it here */
708
709 if (local->ops->set_rts_threshold)
710 local->ops->set_rts_threshold(local_to_hw(local),
711 local->rts_threshold);
712
713 return 0;
714}
715
716static int ieee80211_ioctl_giwrts(struct net_device *dev,
717 struct iw_request_info *info,
718 struct iw_param *rts, char *extra)
719{
720 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
721
722 rts->value = local->rts_threshold;
723 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
724 rts->fixed = 1;
725
726 return 0;
727}
728
729
730static int ieee80211_ioctl_siwfrag(struct net_device *dev,
731 struct iw_request_info *info,
732 struct iw_param *frag, char *extra)
733{
734 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
735
736 if (frag->disabled)
737 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
738 else if (frag->value < 256 ||
739 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
740 return -EINVAL;
741 else {
742 /* Fragment length must be even, so strip LSB. */
743 local->fragmentation_threshold = frag->value & ~0x1;
744 }
745
746 /* If the wlan card performs fragmentation in hardware/firmware,
747 * configure it here */
748
749 if (local->ops->set_frag_threshold)
750 local->ops->set_frag_threshold(
751 local_to_hw(local),
752 local->fragmentation_threshold);
753
754 return 0;
755}
756
757static int ieee80211_ioctl_giwfrag(struct net_device *dev,
758 struct iw_request_info *info,
759 struct iw_param *frag, char *extra)
760{
761 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
762
763 frag->value = local->fragmentation_threshold;
764 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
765 frag->fixed = 1;
766
767 return 0;
768}
769
770
771static int ieee80211_ioctl_siwretry(struct net_device *dev,
772 struct iw_request_info *info,
773 struct iw_param *retry, char *extra)
774{
775 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
776
777 if (retry->disabled ||
778 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
779 return -EINVAL;
780
781 if (retry->flags & IW_RETRY_MAX)
782 local->long_retry_limit = retry->value;
783 else if (retry->flags & IW_RETRY_MIN)
784 local->short_retry_limit = retry->value;
785 else {
786 local->long_retry_limit = retry->value;
787 local->short_retry_limit = retry->value;
788 }
789
790 if (local->ops->set_retry_limit) {
791 return local->ops->set_retry_limit(
792 local_to_hw(local),
793 local->short_retry_limit,
794 local->long_retry_limit);
795 }
796
797 return 0;
798}
799
800
801static int ieee80211_ioctl_giwretry(struct net_device *dev,
802 struct iw_request_info *info,
803 struct iw_param *retry, char *extra)
804{
805 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
806
807 retry->disabled = 0;
808 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
809 /* first return min value, iwconfig will ask max value
810 * later if needed */
811 retry->flags |= IW_RETRY_LIMIT;
812 retry->value = local->short_retry_limit;
813 if (local->long_retry_limit != local->short_retry_limit)
814 retry->flags |= IW_RETRY_MIN;
815 return 0;
816 }
817 if (retry->flags & IW_RETRY_MAX) {
818 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
819 retry->value = local->long_retry_limit;
820 }
821
822 return 0;
823}
824
Jiri Bencf0706e82007-05-05 11:45:53 -0700825static int ieee80211_ioctl_siwmlme(struct net_device *dev,
826 struct iw_request_info *info,
827 struct iw_point *data, char *extra)
828{
829 struct ieee80211_sub_if_data *sdata;
830 struct iw_mlme *mlme = (struct iw_mlme *) extra;
831
832 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100833 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
834 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700835 return -EINVAL;
836
837 switch (mlme->cmd) {
838 case IW_MLME_DEAUTH:
839 /* TODO: mlme->addr.sa_data */
840 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
841 case IW_MLME_DISASSOC:
842 /* TODO: mlme->addr.sa_data */
843 return ieee80211_sta_disassociate(dev, mlme->reason_code);
844 default:
845 return -EOPNOTSUPP;
846 }
847}
848
849
850static int ieee80211_ioctl_siwencode(struct net_device *dev,
851 struct iw_request_info *info,
852 struct iw_point *erq, char *keybuf)
853{
854 struct ieee80211_sub_if_data *sdata;
855 int idx, i, alg = ALG_WEP;
856 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200857 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700858
859 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
860
861 idx = erq->flags & IW_ENCODE_INDEX;
862 if (idx == 0) {
863 if (sdata->default_key)
864 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
865 if (sdata->default_key == sdata->keys[i]) {
866 idx = i;
867 break;
868 }
869 }
870 } else if (idx < 1 || idx > 4)
871 return -EINVAL;
872 else
873 idx--;
874
875 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200876 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700877 else if (erq->length == 0) {
878 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400879 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700880 return 0;
881 }
882
883 return ieee80211_set_encryption(
884 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200885 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700886 !sdata->default_key,
887 keybuf, erq->length);
888}
889
890
891static int ieee80211_ioctl_giwencode(struct net_device *dev,
892 struct iw_request_info *info,
893 struct iw_point *erq, char *key)
894{
895 struct ieee80211_sub_if_data *sdata;
896 int idx, i;
897
898 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
899
900 idx = erq->flags & IW_ENCODE_INDEX;
901 if (idx < 1 || idx > 4) {
902 idx = -1;
903 if (!sdata->default_key)
904 idx = 0;
905 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
906 if (sdata->default_key == sdata->keys[i]) {
907 idx = i;
908 break;
909 }
910 }
911 if (idx < 0)
912 return -EINVAL;
913 } else
914 idx--;
915
916 erq->flags = idx + 1;
917
918 if (!sdata->keys[idx]) {
919 erq->length = 0;
920 erq->flags |= IW_ENCODE_DISABLED;
921 return 0;
922 }
923
Johannes Berg8f20fc22007-08-28 17:01:54 -0400924 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400925 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400926 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700927 erq->flags |= IW_ENCODE_ENABLED;
928
929 return 0;
930}
931
932static int ieee80211_ioctl_siwauth(struct net_device *dev,
933 struct iw_request_info *info,
934 struct iw_param *data, char *extra)
935{
Jiri Bencf0706e82007-05-05 11:45:53 -0700936 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
937 int ret = 0;
938
939 switch (data->flags & IW_AUTH_INDEX) {
940 case IW_AUTH_WPA_VERSION:
941 case IW_AUTH_CIPHER_PAIRWISE:
942 case IW_AUTH_CIPHER_GROUP:
943 case IW_AUTH_WPA_ENABLED:
944 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700945 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000946 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100947 case IW_AUTH_DROP_UNENCRYPTED:
948 sdata->drop_unencrypted = !!data->value;
949 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000950 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100951 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700952 ret = -EINVAL;
953 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000954 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700955 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000956 * Privacy invoked by wpa_supplicant, store the
957 * value and allow associating to a protected
958 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700959 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000960 if (data->value)
961 sdata->u.sta.flags |=
962 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700963 }
964 break;
965 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100966 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
967 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700968 sdata->u.sta.auth_algs = data->value;
969 else
970 ret = -EOPNOTSUPP;
971 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700972 default:
973 ret = -EOPNOTSUPP;
974 break;
975 }
976 return ret;
977}
978
979/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
980static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
981{
982 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
983 struct iw_statistics *wstats = &local->wstats;
984 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
985 struct sta_info *sta = NULL;
986
Johannes Berg51fb61e2007-12-19 01:31:27 +0100987 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
988 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700989 sta = sta_info_get(local, sdata->u.sta.bssid);
990 if (!sta) {
991 wstats->discard.fragment = 0;
992 wstats->discard.misc = 0;
993 wstats->qual.qual = 0;
994 wstats->qual.level = 0;
995 wstats->qual.noise = 0;
996 wstats->qual.updated = IW_QUAL_ALL_INVALID;
997 } else {
998 wstats->qual.level = sta->last_rssi;
999 wstats->qual.qual = sta->last_signal;
1000 wstats->qual.noise = sta->last_noise;
1001 wstats->qual.updated = local->wstats_flags;
1002 sta_info_put(sta);
1003 }
1004 return wstats;
1005}
1006
1007static int ieee80211_ioctl_giwauth(struct net_device *dev,
1008 struct iw_request_info *info,
1009 struct iw_param *data, char *extra)
1010{
1011 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1012 int ret = 0;
1013
1014 switch (data->flags & IW_AUTH_INDEX) {
1015 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001016 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1017 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001018 data->value = sdata->u.sta.auth_algs;
1019 else
1020 ret = -EOPNOTSUPP;
1021 break;
1022 default:
1023 ret = -EOPNOTSUPP;
1024 break;
1025 }
1026 return ret;
1027}
1028
1029
1030static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1031 struct iw_request_info *info,
1032 struct iw_point *erq, char *extra)
1033{
1034 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1035 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001036 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001037
1038 switch (ext->alg) {
1039 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001040 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001041 break;
1042 case IW_ENCODE_ALG_WEP:
1043 alg = ALG_WEP;
1044 break;
1045 case IW_ENCODE_ALG_TKIP:
1046 alg = ALG_TKIP;
1047 break;
1048 case IW_ENCODE_ALG_CCMP:
1049 alg = ALG_CCMP;
1050 break;
1051 default:
1052 return -EOPNOTSUPP;
1053 }
1054
1055 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001056 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001057
1058 idx = erq->flags & IW_ENCODE_INDEX;
1059 if (idx < 1 || idx > 4) {
1060 idx = -1;
1061 if (!sdata->default_key)
1062 idx = 0;
1063 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1064 if (sdata->default_key == sdata->keys[i]) {
1065 idx = i;
1066 break;
1067 }
1068 }
1069 if (idx < 0)
1070 return -EINVAL;
1071 } else
1072 idx--;
1073
1074 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001075 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001076 ext->ext_flags &
1077 IW_ENCODE_EXT_SET_TX_KEY,
1078 ext->key, ext->key_len);
1079}
1080
1081
Jiri Bencf0706e82007-05-05 11:45:53 -07001082/* Structures to export the Wireless Handlers */
1083
1084static const iw_handler ieee80211_handler[] =
1085{
1086 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1087 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1088 (iw_handler) NULL, /* SIOCSIWNWID */
1089 (iw_handler) NULL, /* SIOCGIWNWID */
1090 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1091 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1092 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1093 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1094 (iw_handler) NULL, /* SIOCSIWSENS */
1095 (iw_handler) NULL, /* SIOCGIWSENS */
1096 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1097 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1098 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1099 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1100 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1101 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001102 (iw_handler) NULL, /* SIOCSIWSPY */
1103 (iw_handler) NULL, /* SIOCGIWSPY */
1104 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1105 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001106 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1107 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1108 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1109 (iw_handler) NULL, /* SIOCGIWAPLIST */
1110 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1111 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1112 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1113 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1114 (iw_handler) NULL, /* SIOCSIWNICKN */
1115 (iw_handler) NULL, /* SIOCGIWNICKN */
1116 (iw_handler) NULL, /* -- hole -- */
1117 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001118 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001119 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001120 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1121 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1122 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1123 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001124 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001125 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001126 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1127 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1128 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1129 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1130 (iw_handler) NULL, /* SIOCSIWPOWER */
1131 (iw_handler) NULL, /* SIOCGIWPOWER */
1132 (iw_handler) NULL, /* -- hole -- */
1133 (iw_handler) NULL, /* -- hole -- */
1134 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1135 (iw_handler) NULL, /* SIOCGIWGENIE */
1136 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1137 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1138 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1139 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1140 (iw_handler) NULL, /* SIOCSIWPMKSA */
1141 (iw_handler) NULL, /* -- hole -- */
1142};
1143
Jiri Bencf0706e82007-05-05 11:45:53 -07001144const struct iw_handler_def ieee80211_iw_handler_def =
1145{
1146 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001147 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001148 .get_wireless_stats = ieee80211_get_wireless_stats,
1149};