blob: 5147152b926896fda78cb38e5aec7d95fa3385d4 [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 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;
39
40 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
41
Volker Braun139c3a02007-09-14 11:10:25 -040042 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
43 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
44 dev->name, idx);
45 return -EINVAL;
46 }
47
Johannes Berg628a1402007-09-26 17:53:17 +020048 if (remove) {
Johannes Bergdb4d1162008-02-25 16:27:45 +010049 if (is_broadcast_ether_addr(sta_addr)) {
50 key = sdata->keys[idx];
51 } else {
52 sta = sta_info_get(local, sta_addr);
Johannes Bergd0709a62008-02-25 16:27:46 +010053 if (!sta)
54 return -ENOENT;
Johannes Bergdb4d1162008-02-25 16:27:45 +010055 key = sta->key;
Jiri Bencf0706e82007-05-05 11:45:53 -070056 }
Johannes Bergdb4d1162008-02-25 16:27:45 +010057
58 if (!key)
Johannes Bergd0709a62008-02-25 16:27:46 +010059 return -ENOENT;
60
61 ieee80211_key_free(key);
62 return 0;
Johannes Bergdb4d1162008-02-25 16:27:45 +010063 } else {
64 key = ieee80211_key_alloc(alg, idx, key_len, _key);
65 if (!key)
66 return -ENOMEM;
67
Johannes Bergd0709a62008-02-25 16:27:46 +010068 sta = NULL;
69
Johannes Bergdb4d1162008-02-25 16:27:45 +010070 if (!is_broadcast_ether_addr(sta_addr)) {
71 set_tx_key = 0;
72 /*
73 * According to the standard, the key index of a
74 * pairwise key must be zero. However, some AP are
75 * broken when it comes to WEP key indices, so we
76 * work around this.
77 */
78 if (idx != 0 && alg != ALG_WEP) {
Johannes Bergd0709a62008-02-25 16:27:46 +010079 ieee80211_key_free(key);
80 return -EINVAL;
Johannes Bergdb4d1162008-02-25 16:27:45 +010081 }
82
83 sta = sta_info_get(local, sta_addr);
84 if (!sta) {
Johannes Bergd0709a62008-02-25 16:27:46 +010085 ieee80211_key_free(key);
86 return -ENOENT;
Johannes Bergdb4d1162008-02-25 16:27:45 +010087 }
88 }
89
90 ieee80211_key_link(key, sdata, sta);
91
92 if (set_tx_key || (!sta && !sdata->default_key && key))
93 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -070094 }
95
Johannes Bergd0709a62008-02-25 16:27:46 +010096 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -070097}
98
99static int ieee80211_ioctl_siwgenie(struct net_device *dev,
100 struct iw_request_info *info,
101 struct iw_point *data, char *extra)
102{
103 struct ieee80211_sub_if_data *sdata;
Jiri Bencf0706e82007-05-05 11:45:53 -0700104
105 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200106
107 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME)
108 return -EOPNOTSUPP;
109
Johannes Berg51fb61e2007-12-19 01:31:27 +0100110 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
111 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700112 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
113 if (ret)
114 return ret;
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400115 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700116 ieee80211_sta_req_auth(dev, &sdata->u.sta);
117 return 0;
118 }
119
Jiri Bencf0706e82007-05-05 11:45:53 -0700120 return -EOPNOTSUPP;
121}
122
Jiri Bencf0706e82007-05-05 11:45:53 -0700123static int ieee80211_ioctl_giwname(struct net_device *dev,
124 struct iw_request_info *info,
125 char *name, char *extra)
126{
Johannes Berg8318d782008-01-24 19:38:38 +0100127 strcpy(name, "IEEE 802.11");
Jiri Bencf0706e82007-05-05 11:45:53 -0700128
129 return 0;
130}
131
132
133static int ieee80211_ioctl_giwrange(struct net_device *dev,
134 struct iw_request_info *info,
135 struct iw_point *data, char *extra)
136{
137 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
138 struct iw_range *range = (struct iw_range *) extra;
Johannes Berg8318d782008-01-24 19:38:38 +0100139 enum ieee80211_band band;
Hong Liu333af2f2007-07-10 19:32:08 +0200140 int c = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700141
142 data->length = sizeof(struct iw_range);
143 memset(range, 0, sizeof(struct iw_range));
144
145 range->we_version_compiled = WIRELESS_EXT;
146 range->we_version_source = 21;
147 range->retry_capa = IW_RETRY_LIMIT;
148 range->retry_flags = IW_RETRY_LIMIT;
149 range->min_retry = 0;
150 range->max_retry = 255;
151 range->min_rts = 0;
152 range->max_rts = 2347;
153 range->min_frag = 256;
154 range->max_frag = 2346;
155
156 range->encoding_size[0] = 5;
157 range->encoding_size[1] = 13;
158 range->num_encoding_sizes = 2;
159 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
160
161 range->max_qual.qual = local->hw.max_signal;
162 range->max_qual.level = local->hw.max_rssi;
163 range->max_qual.noise = local->hw.max_noise;
164 range->max_qual.updated = local->wstats_flags;
165
166 range->avg_qual.qual = local->hw.max_signal/2;
167 range->avg_qual.level = 0;
168 range->avg_qual.noise = 0;
169 range->avg_qual.updated = local->wstats_flags;
170
171 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
172 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
173
Hong Liu333af2f2007-07-10 19:32:08 +0200174
Johannes Berg8318d782008-01-24 19:38:38 +0100175 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
176 int i;
177 struct ieee80211_supported_band *sband;
178
179 sband = local->hw.wiphy->bands[band];
180
181 if (!sband)
Hong Liu333af2f2007-07-10 19:32:08 +0200182 continue;
183
Johannes Berg8318d782008-01-24 19:38:38 +0100184 for (i = 0; i < sband->n_channels && c < IW_MAX_FREQUENCIES; i++) {
185 struct ieee80211_channel *chan = &sband->channels[i];
Hong Liu333af2f2007-07-10 19:32:08 +0200186
Johannes Berg8318d782008-01-24 19:38:38 +0100187 if (!(chan->flags & IEEE80211_CHAN_DISABLED)) {
188 range->freq[c].i =
189 ieee80211_frequency_to_channel(
190 chan->center_freq);
191 range->freq[c].m = chan->center_freq;
192 range->freq[c].e = 6;
Hong Liu333af2f2007-07-10 19:32:08 +0200193 c++;
194 }
Hong Liu333af2f2007-07-10 19:32:08 +0200195 }
196 }
197 range->num_channels = c;
198 range->num_frequency = c;
199
Jiri Bencf0706e82007-05-05 11:45:53 -0700200 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
201 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
202 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
203 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
204
Dan Williams374fdfb2007-12-12 10:25:07 -0500205 range->scan_capa |= IW_SCAN_CAPA_ESSID;
206
Jiri Bencf0706e82007-05-05 11:45:53 -0700207 return 0;
208}
209
210
Jiri Bencf0706e82007-05-05 11:45:53 -0700211static int ieee80211_ioctl_siwmode(struct net_device *dev,
212 struct iw_request_info *info,
213 __u32 *mode, char *extra)
214{
215 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
216 int type;
217
Johannes Berg51fb61e2007-12-19 01:31:27 +0100218 if (sdata->vif.type == IEEE80211_IF_TYPE_VLAN)
Jiri Bencf0706e82007-05-05 11:45:53 -0700219 return -EOPNOTSUPP;
220
221 switch (*mode) {
222 case IW_MODE_INFRA:
223 type = IEEE80211_IF_TYPE_STA;
224 break;
225 case IW_MODE_ADHOC:
226 type = IEEE80211_IF_TYPE_IBSS;
227 break;
228 case IW_MODE_MONITOR:
229 type = IEEE80211_IF_TYPE_MNTR;
230 break;
231 default:
232 return -EINVAL;
233 }
234
Johannes Berg51fb61e2007-12-19 01:31:27 +0100235 if (type == sdata->vif.type)
Jiri Bencf0706e82007-05-05 11:45:53 -0700236 return 0;
237 if (netif_running(dev))
238 return -EBUSY;
239
240 ieee80211_if_reinit(dev);
241 ieee80211_if_set_type(dev, type);
242
243 return 0;
244}
245
246
247static int ieee80211_ioctl_giwmode(struct net_device *dev,
248 struct iw_request_info *info,
249 __u32 *mode, char *extra)
250{
251 struct ieee80211_sub_if_data *sdata;
252
253 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100254 switch (sdata->vif.type) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700255 case IEEE80211_IF_TYPE_AP:
256 *mode = IW_MODE_MASTER;
257 break;
258 case IEEE80211_IF_TYPE_STA:
259 *mode = IW_MODE_INFRA;
260 break;
261 case IEEE80211_IF_TYPE_IBSS:
262 *mode = IW_MODE_ADHOC;
263 break;
264 case IEEE80211_IF_TYPE_MNTR:
265 *mode = IW_MODE_MONITOR;
266 break;
267 case IEEE80211_IF_TYPE_WDS:
268 *mode = IW_MODE_REPEAT;
269 break;
270 case IEEE80211_IF_TYPE_VLAN:
271 *mode = IW_MODE_SECOND; /* FIXME */
272 break;
273 default:
274 *mode = IW_MODE_AUTO;
275 break;
276 }
277 return 0;
278}
279
Johannes Berg8318d782008-01-24 19:38:38 +0100280int ieee80211_set_freq(struct ieee80211_local *local, int freqMHz)
Jiri Bencf0706e82007-05-05 11:45:53 -0700281{
Johannes Berg8318d782008-01-24 19:38:38 +0100282 int set = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700283 int ret = -EINVAL;
Johannes Berg8318d782008-01-24 19:38:38 +0100284 enum ieee80211_band band;
285 struct ieee80211_supported_band *sband;
286 int i;
Jiri Bencf0706e82007-05-05 11:45:53 -0700287
Johannes Berg8318d782008-01-24 19:38:38 +0100288 for (band = 0; band < IEEE80211_NUM_BANDS; band ++) {
289 sband = local->hw.wiphy->bands[band];
290
291 if (!sband)
Jiri Bencf0706e82007-05-05 11:45:53 -0700292 continue;
Johannes Berg8318d782008-01-24 19:38:38 +0100293
294 for (i = 0; i < sband->n_channels; i++) {
295 struct ieee80211_channel *chan = &sband->channels[i];
296
297 if (chan->flags & IEEE80211_CHAN_DISABLED)
298 continue;
299
300 if (chan->center_freq == freqMHz) {
Johannes Berg58a9ac12007-10-12 21:24:07 +0200301 set = 1;
Johannes Berg8318d782008-01-24 19:38:38 +0100302 local->oper_channel = chan;
Johannes Berg58a9ac12007-10-12 21:24:07 +0200303 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700304 }
305 }
Johannes Berg58a9ac12007-10-12 21:24:07 +0200306 if (set)
307 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700308 }
309
310 if (set) {
Zhu Yiece8edd2007-11-22 10:53:21 +0800311 if (local->sta_sw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700312 ret = 0;
313 else
314 ret = ieee80211_hw_config(local);
315
316 rate_control_clear(local);
317 }
318
319 return ret;
320}
321
322static int ieee80211_ioctl_siwfreq(struct net_device *dev,
323 struct iw_request_info *info,
324 struct iw_freq *freq, char *extra)
325{
326 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
327 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
328
Johannes Berg51fb61e2007-12-19 01:31:27 +0100329 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400330 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700331
332 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
333 if (freq->e == 0) {
334 if (freq->m < 0) {
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 |=
337 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700338 return 0;
339 } else
Johannes Berg8318d782008-01-24 19:38:38 +0100340 return ieee80211_set_freq(local,
341 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700342 } else {
343 int i, div = 1000000;
344 for (i = 0; i < freq->e; i++)
345 div /= 10;
346 if (div > 0)
Johannes Berg8318d782008-01-24 19:38:38 +0100347 return ieee80211_set_freq(local, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700348 else
349 return -EINVAL;
350 }
351}
352
353
354static int ieee80211_ioctl_giwfreq(struct net_device *dev,
355 struct iw_request_info *info,
356 struct iw_freq *freq, char *extra)
357{
358 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
359
Johannes Berg8318d782008-01-24 19:38:38 +0100360 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700361 freq->e = 6;
362
363 return 0;
364}
365
366
367static int ieee80211_ioctl_siwessid(struct net_device *dev,
368 struct iw_request_info *info,
369 struct iw_point *data, char *ssid)
370{
Jiri Bencf0706e82007-05-05 11:45:53 -0700371 struct ieee80211_sub_if_data *sdata;
372 size_t len = data->length;
373
374 /* iwconfig uses nul termination in SSID.. */
375 if (len > 0 && ssid[len - 1] == '\0')
376 len--;
377
378 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100379 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
380 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700381 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200382 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700383 if (len > IEEE80211_MAX_SSID_LEN)
384 return -EINVAL;
385 memcpy(sdata->u.sta.ssid, ssid, len);
386 sdata->u.sta.ssid_len = len;
387 return 0;
388 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400389 if (data->flags)
390 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
391 else
392 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700393 ret = ieee80211_sta_set_ssid(dev, ssid, len);
394 if (ret)
395 return ret;
396 ieee80211_sta_req_auth(dev, &sdata->u.sta);
397 return 0;
398 }
399
Johannes Berg51fb61e2007-12-19 01:31:27 +0100400 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700401 memcpy(sdata->u.ap.ssid, ssid, len);
402 memset(sdata->u.ap.ssid + len, 0,
403 IEEE80211_MAX_SSID_LEN - len);
404 sdata->u.ap.ssid_len = len;
405 return ieee80211_if_config(dev);
406 }
407 return -EOPNOTSUPP;
408}
409
410
411static int ieee80211_ioctl_giwessid(struct net_device *dev,
412 struct iw_request_info *info,
413 struct iw_point *data, char *ssid)
414{
415 size_t len;
416
417 struct ieee80211_sub_if_data *sdata;
418 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100419 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
420 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700421 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
422 if (res == 0) {
423 data->length = len;
424 data->flags = 1;
425 } else
426 data->flags = 0;
427 return res;
428 }
429
Johannes Berg51fb61e2007-12-19 01:31:27 +0100430 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700431 len = sdata->u.ap.ssid_len;
432 if (len > IW_ESSID_MAX_SIZE)
433 len = IW_ESSID_MAX_SIZE;
434 memcpy(ssid, sdata->u.ap.ssid, len);
435 data->length = len;
436 data->flags = 1;
437 return 0;
438 }
439 return -EOPNOTSUPP;
440}
441
442
443static int ieee80211_ioctl_siwap(struct net_device *dev,
444 struct iw_request_info *info,
445 struct sockaddr *ap_addr, char *extra)
446{
Jiri Bencf0706e82007-05-05 11:45:53 -0700447 struct ieee80211_sub_if_data *sdata;
448
449 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100450 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
451 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700452 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200453 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700454 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
455 ETH_ALEN);
456 return 0;
457 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400458 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
459 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
460 IEEE80211_STA_AUTO_CHANNEL_SEL;
461 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
462 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700463 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400464 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700465 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
466 if (ret)
467 return ret;
468 ieee80211_sta_req_auth(dev, &sdata->u.sta);
469 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100470 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700471 if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
472 ETH_ALEN) == 0)
473 return 0;
474 return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
475 }
476
477 return -EOPNOTSUPP;
478}
479
480
481static int ieee80211_ioctl_giwap(struct net_device *dev,
482 struct iw_request_info *info,
483 struct sockaddr *ap_addr, char *extra)
484{
485 struct ieee80211_sub_if_data *sdata;
486
487 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100488 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
489 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700490 ap_addr->sa_family = ARPHRD_ETHER;
491 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
492 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100493 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700494 ap_addr->sa_family = ARPHRD_ETHER;
495 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
496 return 0;
497 }
498
499 return -EOPNOTSUPP;
500}
501
502
503static int ieee80211_ioctl_siwscan(struct net_device *dev,
504 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400505 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700506{
Jiri Bencf0706e82007-05-05 11:45:53 -0700507 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400508 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700509 u8 *ssid = NULL;
510 size_t ssid_len = 0;
511
512 if (!netif_running(dev))
513 return -ENETDOWN;
514
Johannes Berg51fb61e2007-12-19 01:31:27 +0100515 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
516 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100517 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100518 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700519 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700520
521 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400522 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
523 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
524 req = (struct iw_scan_req *)extra;
525 ssid = req->essid;
526 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700527 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200528
Jiri Bencf0706e82007-05-05 11:45:53 -0700529 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
530}
531
532
533static int ieee80211_ioctl_giwscan(struct net_device *dev,
534 struct iw_request_info *info,
535 struct iw_point *data, char *extra)
536{
537 int res;
538 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800539
540 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700541 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800542
Jiri Bencf0706e82007-05-05 11:45:53 -0700543 res = ieee80211_sta_scan_results(dev, extra, data->length);
544 if (res >= 0) {
545 data->length = res;
546 return 0;
547 }
548 data->length = 0;
549 return res;
550}
551
552
Larry Finger1fd5e582007-07-10 19:32:10 +0200553static int ieee80211_ioctl_siwrate(struct net_device *dev,
554 struct iw_request_info *info,
555 struct iw_param *rate, char *extra)
556{
557 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100558 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200559 u32 target_rate = rate->value / 100000;
560 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100561 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200562
563 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
564 if (!sdata->bss)
565 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100566
567 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
568
Larry Finger1fd5e582007-07-10 19:32:10 +0200569 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
570 * target_rate = X, rate->fixed = 1 means only rate X
571 * target_rate = X, rate->fixed = 0 means all rates <= X */
572 sdata->bss->max_ratectrl_rateidx = -1;
573 sdata->bss->force_unicast_rateidx = -1;
574 if (rate->value < 0)
575 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100576
577 for (i=0; i< sband->n_bitrates; i++) {
578 struct ieee80211_rate *brate = &sband->bitrates[i];
579 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200580
Larry Finger1fd5e582007-07-10 19:32:10 +0200581 if (target_rate == this_rate) {
582 sdata->bss->max_ratectrl_rateidx = i;
583 if (rate->fixed)
584 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100585 err = 0;
586 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200587 }
588 }
Johannes Berg8318d782008-01-24 19:38:38 +0100589 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200590}
591
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700592static int ieee80211_ioctl_giwrate(struct net_device *dev,
593 struct iw_request_info *info,
594 struct iw_param *rate, char *extra)
595{
596 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
597 struct sta_info *sta;
598 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100599 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700600
601 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100602
Johannes Berg51fb61e2007-12-19 01:31:27 +0100603 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700604 sta = sta_info_get(local, sdata->u.sta.bssid);
605 else
606 return -EOPNOTSUPP;
607 if (!sta)
608 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100609
610 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
611
612 if (sta->txrate_idx < sband->n_bitrates)
613 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700614 else
615 rate->value = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100616 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100617
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700618 return 0;
619}
620
Michael Buesch61609bc2007-09-20 22:06:39 +0200621static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
622 struct iw_request_info *info,
623 union iwreq_data *data, char *extra)
624{
625 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
626 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100627 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200628
629 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
630 return -EINVAL;
631 if (data->txpower.flags & IW_TXPOW_RANGE)
632 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200633
Mattias Nissler6a432952007-10-24 23:30:36 +0200634 if (data->txpower.fixed) {
635 new_power_level = data->txpower.value;
636 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100637 /*
638 * Automatic power level. Use maximum power for the current
639 * channel. Should be part of rate control.
640 */
641 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200642 if (!chan)
643 return -EINVAL;
644
Johannes Berg8318d782008-01-24 19:38:38 +0100645 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200646 }
647
648 if (local->hw.conf.power_level != new_power_level) {
649 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200650 need_reconfig = 1;
651 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200652
Michael Buesch61609bc2007-09-20 22:06:39 +0200653 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
654 local->hw.conf.radio_enabled = !(data->txpower.disabled);
655 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100656 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200657 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200658
Michael Buesch61609bc2007-09-20 22:06:39 +0200659 if (need_reconfig) {
660 ieee80211_hw_config(local);
661 /* The return value of hw_config is not of big interest here,
662 * as it doesn't say that it failed because of _this_ config
663 * change or something else. Ignore it. */
664 }
665
666 return 0;
667}
668
Larry Fingerfe6aa302007-08-10 11:23:20 -0500669static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
670 struct iw_request_info *info,
671 union iwreq_data *data, char *extra)
672{
673 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
674
675 data->txpower.fixed = 1;
676 data->txpower.disabled = !(local->hw.conf.radio_enabled);
677 data->txpower.value = local->hw.conf.power_level;
678 data->txpower.flags = IW_TXPOW_DBM;
679
680 return 0;
681}
682
Jiri Bencf0706e82007-05-05 11:45:53 -0700683static int ieee80211_ioctl_siwrts(struct net_device *dev,
684 struct iw_request_info *info,
685 struct iw_param *rts, char *extra)
686{
687 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
688
689 if (rts->disabled)
690 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
691 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
692 return -EINVAL;
693 else
694 local->rts_threshold = rts->value;
695
696 /* If the wlan card performs RTS/CTS in hardware/firmware,
697 * configure it here */
698
699 if (local->ops->set_rts_threshold)
700 local->ops->set_rts_threshold(local_to_hw(local),
701 local->rts_threshold);
702
703 return 0;
704}
705
706static int ieee80211_ioctl_giwrts(struct net_device *dev,
707 struct iw_request_info *info,
708 struct iw_param *rts, char *extra)
709{
710 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
711
712 rts->value = local->rts_threshold;
713 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
714 rts->fixed = 1;
715
716 return 0;
717}
718
719
720static int ieee80211_ioctl_siwfrag(struct net_device *dev,
721 struct iw_request_info *info,
722 struct iw_param *frag, char *extra)
723{
724 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
725
726 if (frag->disabled)
727 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
728 else if (frag->value < 256 ||
729 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
730 return -EINVAL;
731 else {
732 /* Fragment length must be even, so strip LSB. */
733 local->fragmentation_threshold = frag->value & ~0x1;
734 }
735
736 /* If the wlan card performs fragmentation in hardware/firmware,
737 * configure it here */
738
739 if (local->ops->set_frag_threshold)
740 local->ops->set_frag_threshold(
741 local_to_hw(local),
742 local->fragmentation_threshold);
743
744 return 0;
745}
746
747static int ieee80211_ioctl_giwfrag(struct net_device *dev,
748 struct iw_request_info *info,
749 struct iw_param *frag, char *extra)
750{
751 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
752
753 frag->value = local->fragmentation_threshold;
754 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
755 frag->fixed = 1;
756
757 return 0;
758}
759
760
761static int ieee80211_ioctl_siwretry(struct net_device *dev,
762 struct iw_request_info *info,
763 struct iw_param *retry, char *extra)
764{
765 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
766
767 if (retry->disabled ||
768 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
769 return -EINVAL;
770
771 if (retry->flags & IW_RETRY_MAX)
772 local->long_retry_limit = retry->value;
773 else if (retry->flags & IW_RETRY_MIN)
774 local->short_retry_limit = retry->value;
775 else {
776 local->long_retry_limit = retry->value;
777 local->short_retry_limit = retry->value;
778 }
779
780 if (local->ops->set_retry_limit) {
781 return local->ops->set_retry_limit(
782 local_to_hw(local),
783 local->short_retry_limit,
784 local->long_retry_limit);
785 }
786
787 return 0;
788}
789
790
791static int ieee80211_ioctl_giwretry(struct net_device *dev,
792 struct iw_request_info *info,
793 struct iw_param *retry, char *extra)
794{
795 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
796
797 retry->disabled = 0;
798 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
799 /* first return min value, iwconfig will ask max value
800 * later if needed */
801 retry->flags |= IW_RETRY_LIMIT;
802 retry->value = local->short_retry_limit;
803 if (local->long_retry_limit != local->short_retry_limit)
804 retry->flags |= IW_RETRY_MIN;
805 return 0;
806 }
807 if (retry->flags & IW_RETRY_MAX) {
808 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
809 retry->value = local->long_retry_limit;
810 }
811
812 return 0;
813}
814
Jiri Bencf0706e82007-05-05 11:45:53 -0700815static int ieee80211_ioctl_siwmlme(struct net_device *dev,
816 struct iw_request_info *info,
817 struct iw_point *data, char *extra)
818{
819 struct ieee80211_sub_if_data *sdata;
820 struct iw_mlme *mlme = (struct iw_mlme *) extra;
821
822 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100823 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
824 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700825 return -EINVAL;
826
827 switch (mlme->cmd) {
828 case IW_MLME_DEAUTH:
829 /* TODO: mlme->addr.sa_data */
830 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
831 case IW_MLME_DISASSOC:
832 /* TODO: mlme->addr.sa_data */
833 return ieee80211_sta_disassociate(dev, mlme->reason_code);
834 default:
835 return -EOPNOTSUPP;
836 }
837}
838
839
840static int ieee80211_ioctl_siwencode(struct net_device *dev,
841 struct iw_request_info *info,
842 struct iw_point *erq, char *keybuf)
843{
844 struct ieee80211_sub_if_data *sdata;
845 int idx, i, alg = ALG_WEP;
846 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200847 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700848
849 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
850
851 idx = erq->flags & IW_ENCODE_INDEX;
852 if (idx == 0) {
853 if (sdata->default_key)
854 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
855 if (sdata->default_key == sdata->keys[i]) {
856 idx = i;
857 break;
858 }
859 }
860 } else if (idx < 1 || idx > 4)
861 return -EINVAL;
862 else
863 idx--;
864
865 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200866 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700867 else if (erq->length == 0) {
868 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400869 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700870 return 0;
871 }
872
873 return ieee80211_set_encryption(
874 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200875 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700876 !sdata->default_key,
877 keybuf, erq->length);
878}
879
880
881static int ieee80211_ioctl_giwencode(struct net_device *dev,
882 struct iw_request_info *info,
883 struct iw_point *erq, char *key)
884{
885 struct ieee80211_sub_if_data *sdata;
886 int idx, i;
887
888 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
889
890 idx = erq->flags & IW_ENCODE_INDEX;
891 if (idx < 1 || idx > 4) {
892 idx = -1;
893 if (!sdata->default_key)
894 idx = 0;
895 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
896 if (sdata->default_key == sdata->keys[i]) {
897 idx = i;
898 break;
899 }
900 }
901 if (idx < 0)
902 return -EINVAL;
903 } else
904 idx--;
905
906 erq->flags = idx + 1;
907
908 if (!sdata->keys[idx]) {
909 erq->length = 0;
910 erq->flags |= IW_ENCODE_DISABLED;
911 return 0;
912 }
913
Johannes Berg8f20fc22007-08-28 17:01:54 -0400914 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400915 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400916 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700917 erq->flags |= IW_ENCODE_ENABLED;
918
919 return 0;
920}
921
922static int ieee80211_ioctl_siwauth(struct net_device *dev,
923 struct iw_request_info *info,
924 struct iw_param *data, char *extra)
925{
Jiri Bencf0706e82007-05-05 11:45:53 -0700926 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
927 int ret = 0;
928
929 switch (data->flags & IW_AUTH_INDEX) {
930 case IW_AUTH_WPA_VERSION:
931 case IW_AUTH_CIPHER_PAIRWISE:
932 case IW_AUTH_CIPHER_GROUP:
933 case IW_AUTH_WPA_ENABLED:
934 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700935 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000936 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100937 case IW_AUTH_DROP_UNENCRYPTED:
938 sdata->drop_unencrypted = !!data->value;
939 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000940 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100941 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700942 ret = -EINVAL;
943 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000944 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700945 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000946 * Privacy invoked by wpa_supplicant, store the
947 * value and allow associating to a protected
948 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700949 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000950 if (data->value)
951 sdata->u.sta.flags |=
952 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700953 }
954 break;
955 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100956 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
957 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700958 sdata->u.sta.auth_algs = data->value;
959 else
960 ret = -EOPNOTSUPP;
961 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700962 default:
963 ret = -EOPNOTSUPP;
964 break;
965 }
966 return ret;
967}
968
969/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
970static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
971{
972 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
973 struct iw_statistics *wstats = &local->wstats;
974 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
975 struct sta_info *sta = NULL;
976
Johannes Berg51fb61e2007-12-19 01:31:27 +0100977 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
978 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700979 sta = sta_info_get(local, sdata->u.sta.bssid);
980 if (!sta) {
981 wstats->discard.fragment = 0;
982 wstats->discard.misc = 0;
983 wstats->qual.qual = 0;
984 wstats->qual.level = 0;
985 wstats->qual.noise = 0;
986 wstats->qual.updated = IW_QUAL_ALL_INVALID;
987 } else {
988 wstats->qual.level = sta->last_rssi;
989 wstats->qual.qual = sta->last_signal;
990 wstats->qual.noise = sta->last_noise;
991 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -0700992 }
993 return wstats;
994}
995
996static int ieee80211_ioctl_giwauth(struct net_device *dev,
997 struct iw_request_info *info,
998 struct iw_param *data, char *extra)
999{
1000 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1001 int ret = 0;
1002
1003 switch (data->flags & IW_AUTH_INDEX) {
1004 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +01001005 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
1006 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -07001007 data->value = sdata->u.sta.auth_algs;
1008 else
1009 ret = -EOPNOTSUPP;
1010 break;
1011 default:
1012 ret = -EOPNOTSUPP;
1013 break;
1014 }
1015 return ret;
1016}
1017
1018
1019static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1020 struct iw_request_info *info,
1021 struct iw_point *erq, char *extra)
1022{
1023 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1024 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001025 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001026
1027 switch (ext->alg) {
1028 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001029 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001030 break;
1031 case IW_ENCODE_ALG_WEP:
1032 alg = ALG_WEP;
1033 break;
1034 case IW_ENCODE_ALG_TKIP:
1035 alg = ALG_TKIP;
1036 break;
1037 case IW_ENCODE_ALG_CCMP:
1038 alg = ALG_CCMP;
1039 break;
1040 default:
1041 return -EOPNOTSUPP;
1042 }
1043
1044 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001045 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001046
1047 idx = erq->flags & IW_ENCODE_INDEX;
1048 if (idx < 1 || idx > 4) {
1049 idx = -1;
1050 if (!sdata->default_key)
1051 idx = 0;
1052 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1053 if (sdata->default_key == sdata->keys[i]) {
1054 idx = i;
1055 break;
1056 }
1057 }
1058 if (idx < 0)
1059 return -EINVAL;
1060 } else
1061 idx--;
1062
1063 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001064 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001065 ext->ext_flags &
1066 IW_ENCODE_EXT_SET_TX_KEY,
1067 ext->key, ext->key_len);
1068}
1069
1070
Jiri Bencf0706e82007-05-05 11:45:53 -07001071/* Structures to export the Wireless Handlers */
1072
1073static const iw_handler ieee80211_handler[] =
1074{
1075 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1076 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1077 (iw_handler) NULL, /* SIOCSIWNWID */
1078 (iw_handler) NULL, /* SIOCGIWNWID */
1079 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1080 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1081 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1082 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1083 (iw_handler) NULL, /* SIOCSIWSENS */
1084 (iw_handler) NULL, /* SIOCGIWSENS */
1085 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1086 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1087 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1088 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1089 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1090 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001091 (iw_handler) NULL, /* SIOCSIWSPY */
1092 (iw_handler) NULL, /* SIOCGIWSPY */
1093 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1094 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001095 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1096 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1097 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1098 (iw_handler) NULL, /* SIOCGIWAPLIST */
1099 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1100 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1101 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1102 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1103 (iw_handler) NULL, /* SIOCSIWNICKN */
1104 (iw_handler) NULL, /* SIOCGIWNICKN */
1105 (iw_handler) NULL, /* -- hole -- */
1106 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001107 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001108 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001109 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1110 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1111 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1112 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001113 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001114 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001115 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1116 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1117 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1118 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1119 (iw_handler) NULL, /* SIOCSIWPOWER */
1120 (iw_handler) NULL, /* SIOCGIWPOWER */
1121 (iw_handler) NULL, /* -- hole -- */
1122 (iw_handler) NULL, /* -- hole -- */
1123 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1124 (iw_handler) NULL, /* SIOCGIWGENIE */
1125 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1126 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1127 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1128 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1129 (iw_handler) NULL, /* SIOCSIWPMKSA */
1130 (iw_handler) NULL, /* -- hole -- */
1131};
1132
Jiri Bencf0706e82007-05-05 11:45:53 -07001133const struct iw_handler_def ieee80211_iw_handler_def =
1134{
1135 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001136 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001137 .get_wireless_stats = ieee80211_get_wireless_stats,
1138};