blob: 5af23d31872692ee9961a5667646aa1260c9c510 [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{
Jiri Bencf0706e82007-05-05 11:45:53 -0700282 int ret = -EINVAL;
Johannes Berge048c6e2008-03-16 18:35:56 +0100283 struct ieee80211_channel *chan;
Jiri Bencf0706e82007-05-05 11:45:53 -0700284
Johannes Berge048c6e2008-03-16 18:35:56 +0100285 chan = ieee80211_get_channel(local->hw.wiphy, freqMHz);
Johannes Berg8318d782008-01-24 19:38:38 +0100286
Johannes Berge048c6e2008-03-16 18:35:56 +0100287 if (chan && !(chan->flags & IEEE80211_CHAN_DISABLED)) {
288 local->oper_channel = chan;
Johannes Berg8318d782008-01-24 19:38:38 +0100289
Mohamed Abbas675ef582008-03-20 08:14:29 -0700290 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700291 ret = 0;
292 else
293 ret = ieee80211_hw_config(local);
294
295 rate_control_clear(local);
296 }
297
298 return ret;
299}
300
301static int ieee80211_ioctl_siwfreq(struct net_device *dev,
302 struct iw_request_info *info,
303 struct iw_freq *freq, char *extra)
304{
305 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
306 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
307
Johannes Berg51fb61e2007-12-19 01:31:27 +0100308 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400309 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700310
311 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
312 if (freq->e == 0) {
313 if (freq->m < 0) {
Johannes Berg51fb61e2007-12-19 01:31:27 +0100314 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400315 sdata->u.sta.flags |=
316 IEEE80211_STA_AUTO_CHANNEL_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700317 return 0;
318 } else
Johannes Berg8318d782008-01-24 19:38:38 +0100319 return ieee80211_set_freq(local,
320 ieee80211_channel_to_frequency(freq->m));
Jiri Bencf0706e82007-05-05 11:45:53 -0700321 } else {
322 int i, div = 1000000;
323 for (i = 0; i < freq->e; i++)
324 div /= 10;
325 if (div > 0)
Johannes Berg8318d782008-01-24 19:38:38 +0100326 return ieee80211_set_freq(local, freq->m / div);
Jiri Bencf0706e82007-05-05 11:45:53 -0700327 else
328 return -EINVAL;
329 }
330}
331
332
333static int ieee80211_ioctl_giwfreq(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
Johannes Berg8318d782008-01-24 19:38:38 +0100339 freq->m = local->hw.conf.channel->center_freq;
Jiri Bencf0706e82007-05-05 11:45:53 -0700340 freq->e = 6;
341
342 return 0;
343}
344
345
346static int ieee80211_ioctl_siwessid(struct net_device *dev,
347 struct iw_request_info *info,
348 struct iw_point *data, char *ssid)
349{
Jiri Bencf0706e82007-05-05 11:45:53 -0700350 struct ieee80211_sub_if_data *sdata;
351 size_t len = data->length;
352
353 /* iwconfig uses nul termination in SSID.. */
354 if (len > 0 && ssid[len - 1] == '\0')
355 len--;
356
357 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100358 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
359 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700360 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200361 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700362 if (len > IEEE80211_MAX_SSID_LEN)
363 return -EINVAL;
364 memcpy(sdata->u.sta.ssid, ssid, len);
365 sdata->u.sta.ssid_len = len;
366 return 0;
367 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400368 if (data->flags)
369 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
370 else
371 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700372 ret = ieee80211_sta_set_ssid(dev, ssid, len);
373 if (ret)
374 return ret;
375 ieee80211_sta_req_auth(dev, &sdata->u.sta);
376 return 0;
377 }
378
Johannes Berg51fb61e2007-12-19 01:31:27 +0100379 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700380 memcpy(sdata->u.ap.ssid, ssid, len);
381 memset(sdata->u.ap.ssid + len, 0,
382 IEEE80211_MAX_SSID_LEN - len);
383 sdata->u.ap.ssid_len = len;
384 return ieee80211_if_config(dev);
385 }
386 return -EOPNOTSUPP;
387}
388
389
390static int ieee80211_ioctl_giwessid(struct net_device *dev,
391 struct iw_request_info *info,
392 struct iw_point *data, char *ssid)
393{
394 size_t len;
395
396 struct ieee80211_sub_if_data *sdata;
397 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100398 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
399 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700400 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
401 if (res == 0) {
402 data->length = len;
403 data->flags = 1;
404 } else
405 data->flags = 0;
406 return res;
407 }
408
Johannes Berg51fb61e2007-12-19 01:31:27 +0100409 if (sdata->vif.type == IEEE80211_IF_TYPE_AP) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700410 len = sdata->u.ap.ssid_len;
411 if (len > IW_ESSID_MAX_SIZE)
412 len = IW_ESSID_MAX_SIZE;
413 memcpy(ssid, sdata->u.ap.ssid, len);
414 data->length = len;
415 data->flags = 1;
416 return 0;
417 }
418 return -EOPNOTSUPP;
419}
420
421
422static int ieee80211_ioctl_siwap(struct net_device *dev,
423 struct iw_request_info *info,
424 struct sockaddr *ap_addr, char *extra)
425{
Jiri Bencf0706e82007-05-05 11:45:53 -0700426 struct ieee80211_sub_if_data *sdata;
427
428 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100429 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
430 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700431 int ret;
Johannes Bergddd3d2b2007-09-26 17:53:20 +0200432 if (sdata->flags & IEEE80211_SDATA_USERSPACE_MLME) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700433 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
434 ETH_ALEN);
435 return 0;
436 }
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400437 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
438 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
439 IEEE80211_STA_AUTO_CHANNEL_SEL;
440 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
441 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700442 else
Jiri Slabyd6f2da52007-08-28 17:01:54 -0400443 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700444 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
445 if (ret)
446 return ret;
447 ieee80211_sta_req_auth(dev, &sdata->u.sta);
448 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100449 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Johannes Berg44213b52008-02-25 16:27:49 +0100450 /*
451 * If it is necessary to update the WDS peer address
452 * while the interface is running, then we need to do
453 * more work here, namely if it is running we need to
454 * add a new and remove the old STA entry, this is
455 * normally handled by _open() and _stop().
456 */
457 if (netif_running(dev))
458 return -EBUSY;
459
460 memcpy(&sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
461 ETH_ALEN);
462
463 return 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700464 }
465
466 return -EOPNOTSUPP;
467}
468
469
470static int ieee80211_ioctl_giwap(struct net_device *dev,
471 struct iw_request_info *info,
472 struct sockaddr *ap_addr, char *extra)
473{
474 struct ieee80211_sub_if_data *sdata;
475
476 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100477 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
478 sdata->vif.type == IEEE80211_IF_TYPE_IBSS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700479 ap_addr->sa_family = ARPHRD_ETHER;
480 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
481 return 0;
Johannes Berg51fb61e2007-12-19 01:31:27 +0100482 } else if (sdata->vif.type == IEEE80211_IF_TYPE_WDS) {
Jiri Bencf0706e82007-05-05 11:45:53 -0700483 ap_addr->sa_family = ARPHRD_ETHER;
484 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
485 return 0;
486 }
487
488 return -EOPNOTSUPP;
489}
490
491
492static int ieee80211_ioctl_siwscan(struct net_device *dev,
493 struct iw_request_info *info,
Bill Moss107acb22007-10-10 16:23:55 -0400494 union iwreq_data *wrqu, char *extra)
Jiri Bencf0706e82007-05-05 11:45:53 -0700495{
Jiri Bencf0706e82007-05-05 11:45:53 -0700496 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Bill Moss107acb22007-10-10 16:23:55 -0400497 struct iw_scan_req *req = NULL;
Jiri Bencf0706e82007-05-05 11:45:53 -0700498 u8 *ssid = NULL;
499 size_t ssid_len = 0;
500
501 if (!netif_running(dev))
502 return -ENETDOWN;
503
Johannes Berg51fb61e2007-12-19 01:31:27 +0100504 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
505 sdata->vif.type != IEEE80211_IF_TYPE_IBSS &&
Luis Carlos Coboee385852008-02-23 15:17:11 +0100506 sdata->vif.type != IEEE80211_IF_TYPE_MESH_POINT &&
Johannes Berg51fb61e2007-12-19 01:31:27 +0100507 sdata->vif.type != IEEE80211_IF_TYPE_AP)
John W. Linvilled114f392007-10-17 21:16:16 -0700508 return -EOPNOTSUPP;
John W. Linvilled114f392007-10-17 21:16:16 -0700509
510 /* if SSID was specified explicitly then use that */
Bill Moss107acb22007-10-10 16:23:55 -0400511 if (wrqu->data.length == sizeof(struct iw_scan_req) &&
512 wrqu->data.flags & IW_SCAN_THIS_ESSID) {
513 req = (struct iw_scan_req *)extra;
514 ssid = req->essid;
515 ssid_len = req->essid_len;
Jiri Bencf0706e82007-05-05 11:45:53 -0700516 }
Daniel Drakef27b62d2007-07-27 15:43:24 +0200517
Jiri Bencf0706e82007-05-05 11:45:53 -0700518 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
519}
520
521
522static int ieee80211_ioctl_giwscan(struct net_device *dev,
523 struct iw_request_info *info,
524 struct iw_point *data, char *extra)
525{
526 int res;
527 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Zhu Yiece8edd2007-11-22 10:53:21 +0800528
529 if (local->sta_sw_scanning || local->sta_hw_scanning)
Jiri Bencf0706e82007-05-05 11:45:53 -0700530 return -EAGAIN;
Zhu Yiece8edd2007-11-22 10:53:21 +0800531
Jiri Bencf0706e82007-05-05 11:45:53 -0700532 res = ieee80211_sta_scan_results(dev, extra, data->length);
533 if (res >= 0) {
534 data->length = res;
535 return 0;
536 }
537 data->length = 0;
538 return res;
539}
540
541
Larry Finger1fd5e582007-07-10 19:32:10 +0200542static int ieee80211_ioctl_siwrate(struct net_device *dev,
543 struct iw_request_info *info,
544 struct iw_param *rate, char *extra)
545{
546 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
Johannes Berg8318d782008-01-24 19:38:38 +0100547 int i, err = -EINVAL;
Larry Finger1fd5e582007-07-10 19:32:10 +0200548 u32 target_rate = rate->value / 100000;
549 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100550 struct ieee80211_supported_band *sband;
Larry Finger1fd5e582007-07-10 19:32:10 +0200551
552 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
553 if (!sdata->bss)
554 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100555
556 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
557
Larry Finger1fd5e582007-07-10 19:32:10 +0200558 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
559 * target_rate = X, rate->fixed = 1 means only rate X
560 * target_rate = X, rate->fixed = 0 means all rates <= X */
561 sdata->bss->max_ratectrl_rateidx = -1;
562 sdata->bss->force_unicast_rateidx = -1;
563 if (rate->value < 0)
564 return 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100565
566 for (i=0; i< sband->n_bitrates; i++) {
567 struct ieee80211_rate *brate = &sband->bitrates[i];
568 int this_rate = brate->bitrate;
Larry Finger1fd5e582007-07-10 19:32:10 +0200569
Larry Finger1fd5e582007-07-10 19:32:10 +0200570 if (target_rate == this_rate) {
571 sdata->bss->max_ratectrl_rateidx = i;
572 if (rate->fixed)
573 sdata->bss->force_unicast_rateidx = i;
Johannes Berg8318d782008-01-24 19:38:38 +0100574 err = 0;
575 break;
Larry Finger1fd5e582007-07-10 19:32:10 +0200576 }
577 }
Johannes Berg8318d782008-01-24 19:38:38 +0100578 return err;
Larry Finger1fd5e582007-07-10 19:32:10 +0200579}
580
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700581static int ieee80211_ioctl_giwrate(struct net_device *dev,
582 struct iw_request_info *info,
583 struct iw_param *rate, char *extra)
584{
585 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
586 struct sta_info *sta;
587 struct ieee80211_sub_if_data *sdata;
Johannes Berg8318d782008-01-24 19:38:38 +0100588 struct ieee80211_supported_band *sband;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700589
590 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg8318d782008-01-24 19:38:38 +0100591
Johannes Berg51fb61e2007-12-19 01:31:27 +0100592 if (sdata->vif.type == IEEE80211_IF_TYPE_STA)
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700593 sta = sta_info_get(local, sdata->u.sta.bssid);
594 else
595 return -EOPNOTSUPP;
596 if (!sta)
597 return -ENODEV;
Johannes Berg8318d782008-01-24 19:38:38 +0100598
599 sband = local->hw.wiphy->bands[local->hw.conf.channel->band];
600
601 if (sta->txrate_idx < sband->n_bitrates)
602 rate->value = sband->bitrates[sta->txrate_idx].bitrate;
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700603 else
604 rate->value = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100605 rate->value *= 100000;
Johannes Bergd0709a62008-02-25 16:27:46 +0100606
Larry Fingerb3d88ad2007-06-10 17:57:33 -0700607 return 0;
608}
609
Michael Buesch61609bc2007-09-20 22:06:39 +0200610static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
611 struct iw_request_info *info,
612 union iwreq_data *data, char *extra)
613{
614 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
615 bool need_reconfig = 0;
Johannes Berg8318d782008-01-24 19:38:38 +0100616 int new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200617
618 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
619 return -EINVAL;
620 if (data->txpower.flags & IW_TXPOW_RANGE)
621 return -EINVAL;
Michael Buesch61609bc2007-09-20 22:06:39 +0200622
Mattias Nissler6a432952007-10-24 23:30:36 +0200623 if (data->txpower.fixed) {
624 new_power_level = data->txpower.value;
625 } else {
Johannes Berg8318d782008-01-24 19:38:38 +0100626 /*
627 * Automatic power level. Use maximum power for the current
628 * channel. Should be part of rate control.
629 */
630 struct ieee80211_channel* chan = local->hw.conf.channel;
Mattias Nissler6a432952007-10-24 23:30:36 +0200631 if (!chan)
632 return -EINVAL;
633
Johannes Berg8318d782008-01-24 19:38:38 +0100634 new_power_level = chan->max_power;
Mattias Nissler6a432952007-10-24 23:30:36 +0200635 }
636
637 if (local->hw.conf.power_level != new_power_level) {
638 local->hw.conf.power_level = new_power_level;
Michael Buesch61609bc2007-09-20 22:06:39 +0200639 need_reconfig = 1;
640 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200641
Michael Buesch61609bc2007-09-20 22:06:39 +0200642 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
643 local->hw.conf.radio_enabled = !(data->txpower.disabled);
644 need_reconfig = 1;
Ivo van Doorncdcb0062008-01-07 19:45:24 +0100645 ieee80211_led_radio(local, local->hw.conf.radio_enabled);
Michael Buesch61609bc2007-09-20 22:06:39 +0200646 }
Mattias Nissler6a432952007-10-24 23:30:36 +0200647
Michael Buesch61609bc2007-09-20 22:06:39 +0200648 if (need_reconfig) {
649 ieee80211_hw_config(local);
650 /* The return value of hw_config is not of big interest here,
651 * as it doesn't say that it failed because of _this_ config
652 * change or something else. Ignore it. */
653 }
654
655 return 0;
656}
657
Larry Fingerfe6aa302007-08-10 11:23:20 -0500658static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
659 struct iw_request_info *info,
660 union iwreq_data *data, char *extra)
661{
662 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
663
664 data->txpower.fixed = 1;
665 data->txpower.disabled = !(local->hw.conf.radio_enabled);
666 data->txpower.value = local->hw.conf.power_level;
667 data->txpower.flags = IW_TXPOW_DBM;
668
669 return 0;
670}
671
Jiri Bencf0706e82007-05-05 11:45:53 -0700672static int ieee80211_ioctl_siwrts(struct net_device *dev,
673 struct iw_request_info *info,
674 struct iw_param *rts, char *extra)
675{
676 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
677
678 if (rts->disabled)
679 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
680 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
681 return -EINVAL;
682 else
683 local->rts_threshold = rts->value;
684
685 /* If the wlan card performs RTS/CTS in hardware/firmware,
686 * configure it here */
687
688 if (local->ops->set_rts_threshold)
689 local->ops->set_rts_threshold(local_to_hw(local),
690 local->rts_threshold);
691
692 return 0;
693}
694
695static int ieee80211_ioctl_giwrts(struct net_device *dev,
696 struct iw_request_info *info,
697 struct iw_param *rts, char *extra)
698{
699 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
700
701 rts->value = local->rts_threshold;
702 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
703 rts->fixed = 1;
704
705 return 0;
706}
707
708
709static int ieee80211_ioctl_siwfrag(struct net_device *dev,
710 struct iw_request_info *info,
711 struct iw_param *frag, char *extra)
712{
713 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
714
715 if (frag->disabled)
716 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
717 else if (frag->value < 256 ||
718 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
719 return -EINVAL;
720 else {
721 /* Fragment length must be even, so strip LSB. */
722 local->fragmentation_threshold = frag->value & ~0x1;
723 }
724
725 /* If the wlan card performs fragmentation in hardware/firmware,
726 * configure it here */
727
728 if (local->ops->set_frag_threshold)
729 local->ops->set_frag_threshold(
730 local_to_hw(local),
731 local->fragmentation_threshold);
732
733 return 0;
734}
735
736static int ieee80211_ioctl_giwfrag(struct net_device *dev,
737 struct iw_request_info *info,
738 struct iw_param *frag, char *extra)
739{
740 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
741
742 frag->value = local->fragmentation_threshold;
743 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
744 frag->fixed = 1;
745
746 return 0;
747}
748
749
750static int ieee80211_ioctl_siwretry(struct net_device *dev,
751 struct iw_request_info *info,
752 struct iw_param *retry, char *extra)
753{
754 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
755
756 if (retry->disabled ||
757 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
758 return -EINVAL;
759
760 if (retry->flags & IW_RETRY_MAX)
761 local->long_retry_limit = retry->value;
762 else if (retry->flags & IW_RETRY_MIN)
763 local->short_retry_limit = retry->value;
764 else {
765 local->long_retry_limit = retry->value;
766 local->short_retry_limit = retry->value;
767 }
768
769 if (local->ops->set_retry_limit) {
770 return local->ops->set_retry_limit(
771 local_to_hw(local),
772 local->short_retry_limit,
773 local->long_retry_limit);
774 }
775
776 return 0;
777}
778
779
780static int ieee80211_ioctl_giwretry(struct net_device *dev,
781 struct iw_request_info *info,
782 struct iw_param *retry, char *extra)
783{
784 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
785
786 retry->disabled = 0;
787 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
788 /* first return min value, iwconfig will ask max value
789 * later if needed */
790 retry->flags |= IW_RETRY_LIMIT;
791 retry->value = local->short_retry_limit;
792 if (local->long_retry_limit != local->short_retry_limit)
793 retry->flags |= IW_RETRY_MIN;
794 return 0;
795 }
796 if (retry->flags & IW_RETRY_MAX) {
797 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
798 retry->value = local->long_retry_limit;
799 }
800
801 return 0;
802}
803
Jiri Bencf0706e82007-05-05 11:45:53 -0700804static int ieee80211_ioctl_siwmlme(struct net_device *dev,
805 struct iw_request_info *info,
806 struct iw_point *data, char *extra)
807{
808 struct ieee80211_sub_if_data *sdata;
809 struct iw_mlme *mlme = (struct iw_mlme *) extra;
810
811 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
Johannes Berg51fb61e2007-12-19 01:31:27 +0100812 if (sdata->vif.type != IEEE80211_IF_TYPE_STA &&
813 sdata->vif.type != IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700814 return -EINVAL;
815
816 switch (mlme->cmd) {
817 case IW_MLME_DEAUTH:
818 /* TODO: mlme->addr.sa_data */
819 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
820 case IW_MLME_DISASSOC:
821 /* TODO: mlme->addr.sa_data */
822 return ieee80211_sta_disassociate(dev, mlme->reason_code);
823 default:
824 return -EOPNOTSUPP;
825 }
826}
827
828
829static int ieee80211_ioctl_siwencode(struct net_device *dev,
830 struct iw_request_info *info,
831 struct iw_point *erq, char *keybuf)
832{
833 struct ieee80211_sub_if_data *sdata;
834 int idx, i, alg = ALG_WEP;
835 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
Johannes Berg628a1402007-09-26 17:53:17 +0200836 int remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -0700837
838 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
839
840 idx = erq->flags & IW_ENCODE_INDEX;
841 if (idx == 0) {
842 if (sdata->default_key)
843 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
844 if (sdata->default_key == sdata->keys[i]) {
845 idx = i;
846 break;
847 }
848 }
849 } else if (idx < 1 || idx > 4)
850 return -EINVAL;
851 else
852 idx--;
853
854 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +0200855 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -0700856 else if (erq->length == 0) {
857 /* No key data - just set the default TX key index */
Johannes Berg11a843b2007-08-28 17:01:55 -0400858 ieee80211_set_default_key(sdata, idx);
Jiri Bencf0706e82007-05-05 11:45:53 -0700859 return 0;
860 }
861
862 return ieee80211_set_encryption(
863 dev, bcaddr,
Johannes Berg628a1402007-09-26 17:53:17 +0200864 idx, alg, remove,
Jiri Bencf0706e82007-05-05 11:45:53 -0700865 !sdata->default_key,
866 keybuf, erq->length);
867}
868
869
870static int ieee80211_ioctl_giwencode(struct net_device *dev,
871 struct iw_request_info *info,
872 struct iw_point *erq, char *key)
873{
874 struct ieee80211_sub_if_data *sdata;
875 int idx, i;
876
877 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
878
879 idx = erq->flags & IW_ENCODE_INDEX;
880 if (idx < 1 || idx > 4) {
881 idx = -1;
882 if (!sdata->default_key)
883 idx = 0;
884 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
885 if (sdata->default_key == sdata->keys[i]) {
886 idx = i;
887 break;
888 }
889 }
890 if (idx < 0)
891 return -EINVAL;
892 } else
893 idx--;
894
895 erq->flags = idx + 1;
896
897 if (!sdata->keys[idx]) {
898 erq->length = 0;
899 erq->flags |= IW_ENCODE_DISABLED;
900 return 0;
901 }
902
Johannes Berg8f20fc22007-08-28 17:01:54 -0400903 memcpy(key, sdata->keys[idx]->conf.key,
Johannes Berg11a843b2007-08-28 17:01:55 -0400904 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
Johannes Berg8f20fc22007-08-28 17:01:54 -0400905 erq->length = sdata->keys[idx]->conf.keylen;
Jiri Bencf0706e82007-05-05 11:45:53 -0700906 erq->flags |= IW_ENCODE_ENABLED;
907
908 return 0;
909}
910
911static int ieee80211_ioctl_siwauth(struct net_device *dev,
912 struct iw_request_info *info,
913 struct iw_param *data, char *extra)
914{
Jiri Bencf0706e82007-05-05 11:45:53 -0700915 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
916 int ret = 0;
917
918 switch (data->flags & IW_AUTH_INDEX) {
919 case IW_AUTH_WPA_VERSION:
920 case IW_AUTH_CIPHER_PAIRWISE:
921 case IW_AUTH_CIPHER_GROUP:
922 case IW_AUTH_WPA_ENABLED:
923 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
Jiri Bencf0706e82007-05-05 11:45:53 -0700924 case IW_AUTH_KEY_MGMT:
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000925 break;
Johannes Bergb1357a82007-11-28 11:04:21 +0100926 case IW_AUTH_DROP_UNENCRYPTED:
927 sdata->drop_unencrypted = !!data->value;
928 break;
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000929 case IW_AUTH_PRIVACY_INVOKED:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100930 if (sdata->vif.type != IEEE80211_IF_TYPE_STA)
Jiri Bencf0706e82007-05-05 11:45:53 -0700931 ret = -EINVAL;
932 else {
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000933 sdata->u.sta.flags &= ~IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700934 /*
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000935 * Privacy invoked by wpa_supplicant, store the
936 * value and allow associating to a protected
937 * network without having a key up front.
Jiri Bencf0706e82007-05-05 11:45:53 -0700938 */
Johannes Berg5b98b1f2007-11-03 13:11:10 +0000939 if (data->value)
940 sdata->u.sta.flags |=
941 IEEE80211_STA_PRIVACY_INVOKED;
Jiri Bencf0706e82007-05-05 11:45:53 -0700942 }
943 break;
944 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100945 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
946 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700947 sdata->u.sta.auth_algs = data->value;
948 else
949 ret = -EOPNOTSUPP;
950 break;
Jiri Bencf0706e82007-05-05 11:45:53 -0700951 default:
952 ret = -EOPNOTSUPP;
953 break;
954 }
955 return ret;
956}
957
958/* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
959static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
960{
961 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
962 struct iw_statistics *wstats = &local->wstats;
963 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
964 struct sta_info *sta = NULL;
965
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 sta = sta_info_get(local, sdata->u.sta.bssid);
969 if (!sta) {
970 wstats->discard.fragment = 0;
971 wstats->discard.misc = 0;
972 wstats->qual.qual = 0;
973 wstats->qual.level = 0;
974 wstats->qual.noise = 0;
975 wstats->qual.updated = IW_QUAL_ALL_INVALID;
976 } else {
977 wstats->qual.level = sta->last_rssi;
978 wstats->qual.qual = sta->last_signal;
979 wstats->qual.noise = sta->last_noise;
980 wstats->qual.updated = local->wstats_flags;
Jiri Bencf0706e82007-05-05 11:45:53 -0700981 }
982 return wstats;
983}
984
985static int ieee80211_ioctl_giwauth(struct net_device *dev,
986 struct iw_request_info *info,
987 struct iw_param *data, char *extra)
988{
989 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
990 int ret = 0;
991
992 switch (data->flags & IW_AUTH_INDEX) {
993 case IW_AUTH_80211_AUTH_ALG:
Johannes Berg51fb61e2007-12-19 01:31:27 +0100994 if (sdata->vif.type == IEEE80211_IF_TYPE_STA ||
995 sdata->vif.type == IEEE80211_IF_TYPE_IBSS)
Jiri Bencf0706e82007-05-05 11:45:53 -0700996 data->value = sdata->u.sta.auth_algs;
997 else
998 ret = -EOPNOTSUPP;
999 break;
1000 default:
1001 ret = -EOPNOTSUPP;
1002 break;
1003 }
1004 return ret;
1005}
1006
1007
1008static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1009 struct iw_request_info *info,
1010 struct iw_point *erq, char *extra)
1011{
1012 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1013 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
Johannes Berg628a1402007-09-26 17:53:17 +02001014 int uninitialized_var(alg), idx, i, remove = 0;
Jiri Bencf0706e82007-05-05 11:45:53 -07001015
1016 switch (ext->alg) {
1017 case IW_ENCODE_ALG_NONE:
Johannes Berg628a1402007-09-26 17:53:17 +02001018 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001019 break;
1020 case IW_ENCODE_ALG_WEP:
1021 alg = ALG_WEP;
1022 break;
1023 case IW_ENCODE_ALG_TKIP:
1024 alg = ALG_TKIP;
1025 break;
1026 case IW_ENCODE_ALG_CCMP:
1027 alg = ALG_CCMP;
1028 break;
1029 default:
1030 return -EOPNOTSUPP;
1031 }
1032
1033 if (erq->flags & IW_ENCODE_DISABLED)
Johannes Berg628a1402007-09-26 17:53:17 +02001034 remove = 1;
Jiri Bencf0706e82007-05-05 11:45:53 -07001035
1036 idx = erq->flags & IW_ENCODE_INDEX;
1037 if (idx < 1 || idx > 4) {
1038 idx = -1;
1039 if (!sdata->default_key)
1040 idx = 0;
1041 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1042 if (sdata->default_key == sdata->keys[i]) {
1043 idx = i;
1044 break;
1045 }
1046 }
1047 if (idx < 0)
1048 return -EINVAL;
1049 } else
1050 idx--;
1051
1052 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
Johannes Berg628a1402007-09-26 17:53:17 +02001053 remove,
Jiri Bencf0706e82007-05-05 11:45:53 -07001054 ext->ext_flags &
1055 IW_ENCODE_EXT_SET_TX_KEY,
1056 ext->key, ext->key_len);
1057}
1058
1059
Jiri Bencf0706e82007-05-05 11:45:53 -07001060/* Structures to export the Wireless Handlers */
1061
1062static const iw_handler ieee80211_handler[] =
1063{
1064 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1065 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1066 (iw_handler) NULL, /* SIOCSIWNWID */
1067 (iw_handler) NULL, /* SIOCGIWNWID */
1068 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1069 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1070 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1071 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1072 (iw_handler) NULL, /* SIOCSIWSENS */
1073 (iw_handler) NULL, /* SIOCGIWSENS */
1074 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1075 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1076 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1077 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1078 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1079 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
Johannes Berg5d4ecd92007-09-14 11:10:24 -04001080 (iw_handler) NULL, /* SIOCSIWSPY */
1081 (iw_handler) NULL, /* SIOCGIWSPY */
1082 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1083 (iw_handler) NULL, /* SIOCGIWTHRSPY */
Jiri Bencf0706e82007-05-05 11:45:53 -07001084 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1085 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1086 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1087 (iw_handler) NULL, /* SIOCGIWAPLIST */
1088 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1089 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1090 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1091 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1092 (iw_handler) NULL, /* SIOCSIWNICKN */
1093 (iw_handler) NULL, /* SIOCGIWNICKN */
1094 (iw_handler) NULL, /* -- hole -- */
1095 (iw_handler) NULL, /* -- hole -- */
Larry Finger1fd5e582007-07-10 19:32:10 +02001096 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
Larry Fingerb3d88ad2007-06-10 17:57:33 -07001097 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
Jiri Bencf0706e82007-05-05 11:45:53 -07001098 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1099 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1100 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1101 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
Michael Buesch61609bc2007-09-20 22:06:39 +02001102 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
Larry Fingerfe6aa302007-08-10 11:23:20 -05001103 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
Jiri Bencf0706e82007-05-05 11:45:53 -07001104 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1105 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1106 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1107 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1108 (iw_handler) NULL, /* SIOCSIWPOWER */
1109 (iw_handler) NULL, /* SIOCGIWPOWER */
1110 (iw_handler) NULL, /* -- hole -- */
1111 (iw_handler) NULL, /* -- hole -- */
1112 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1113 (iw_handler) NULL, /* SIOCGIWGENIE */
1114 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1115 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1116 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1117 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1118 (iw_handler) NULL, /* SIOCSIWPMKSA */
1119 (iw_handler) NULL, /* -- hole -- */
1120};
1121
Jiri Bencf0706e82007-05-05 11:45:53 -07001122const struct iw_handler_def ieee80211_iw_handler_def =
1123{
1124 .num_standard = ARRAY_SIZE(ieee80211_handler),
Jiri Bencf0706e82007-05-05 11:45:53 -07001125 .standard = (iw_handler *) ieee80211_handler,
Jiri Bencf0706e82007-05-05 11:45:53 -07001126 .get_wireless_stats = ieee80211_get_wireless_stats,
1127};