[PATCH] mac80211: remove generic IE for AP interfaces
[deliverable/linux.git] / net / mac80211 / ieee80211_ioctl.c
1 /*
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"
24 #include "ieee80211_rate.h"
25 #include "wpa.h"
26 #include "aes_ccm.h"
27
28
29 static int ieee80211_set_encryption(struct net_device *dev, u8 *sta_addr,
30 int idx, int alg, int set_tx_key,
31 const u8 *_key, size_t key_len)
32 {
33 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
34 int ret = 0;
35 struct sta_info *sta;
36 struct ieee80211_key *key;
37 struct ieee80211_sub_if_data *sdata;
38
39 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
40
41 if (idx < 0 || idx >= NUM_DEFAULT_KEYS) {
42 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
43 dev->name, idx);
44 return -EINVAL;
45 }
46
47 if (is_broadcast_ether_addr(sta_addr)) {
48 sta = NULL;
49 key = sdata->keys[idx];
50 } else {
51 set_tx_key = 0;
52 /*
53 * According to the standard, the key index of a pairwise
54 * key must be zero. However, some AP are broken when it
55 * comes to WEP key indices, so we work around this.
56 */
57 if (idx != 0 && alg != ALG_WEP) {
58 printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
59 "individual key\n", dev->name);
60 return -EINVAL;
61 }
62
63 sta = sta_info_get(local, sta_addr);
64 if (!sta) {
65 #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
66 DECLARE_MAC_BUF(mac);
67 printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
68 "%s\n",
69 dev->name, print_mac(mac, sta_addr));
70 #endif /* CONFIG_MAC80211_VERBOSE_DEBUG */
71
72 return -ENOENT;
73 }
74
75 key = sta->key;
76 }
77
78 if (alg == ALG_NONE) {
79 ieee80211_key_free(key);
80 key = NULL;
81 } else {
82 /*
83 * Automatically frees any old key if present.
84 */
85 key = ieee80211_key_alloc(sdata, sta, alg, idx, key_len, _key);
86 if (!key) {
87 ret = -ENOMEM;
88 goto err_out;
89 }
90 }
91
92 if (set_tx_key || (!sta && !sdata->default_key && key))
93 ieee80211_set_default_key(sdata, idx);
94
95 ret = 0;
96 err_out:
97 if (sta)
98 sta_info_put(sta);
99 return ret;
100 }
101
102 static int ieee80211_ioctl_siwgenie(struct net_device *dev,
103 struct iw_request_info *info,
104 struct iw_point *data, char *extra)
105 {
106 struct ieee80211_sub_if_data *sdata;
107 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
108
109 if (local->user_space_mlme)
110 return -EOPNOTSUPP;
111
112 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
113 if (sdata->type == IEEE80211_IF_TYPE_STA ||
114 sdata->type == IEEE80211_IF_TYPE_IBSS) {
115 int ret = ieee80211_sta_set_extra_ie(dev, extra, data->length);
116 if (ret)
117 return ret;
118 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
119 ieee80211_sta_req_auth(dev, &sdata->u.sta);
120 return 0;
121 }
122
123 return -EOPNOTSUPP;
124 }
125
126 static int ieee80211_ioctl_giwname(struct net_device *dev,
127 struct iw_request_info *info,
128 char *name, char *extra)
129 {
130 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
131
132 switch (local->hw.conf.phymode) {
133 case MODE_IEEE80211A:
134 strcpy(name, "IEEE 802.11a");
135 break;
136 case MODE_IEEE80211B:
137 strcpy(name, "IEEE 802.11b");
138 break;
139 case MODE_IEEE80211G:
140 strcpy(name, "IEEE 802.11g");
141 break;
142 default:
143 strcpy(name, "IEEE 802.11");
144 break;
145 }
146
147 return 0;
148 }
149
150
151 static int ieee80211_ioctl_giwrange(struct net_device *dev,
152 struct iw_request_info *info,
153 struct iw_point *data, char *extra)
154 {
155 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
156 struct iw_range *range = (struct iw_range *) extra;
157 struct ieee80211_hw_mode *mode = NULL;
158 int c = 0;
159
160 data->length = sizeof(struct iw_range);
161 memset(range, 0, sizeof(struct iw_range));
162
163 range->we_version_compiled = WIRELESS_EXT;
164 range->we_version_source = 21;
165 range->retry_capa = IW_RETRY_LIMIT;
166 range->retry_flags = IW_RETRY_LIMIT;
167 range->min_retry = 0;
168 range->max_retry = 255;
169 range->min_rts = 0;
170 range->max_rts = 2347;
171 range->min_frag = 256;
172 range->max_frag = 2346;
173
174 range->encoding_size[0] = 5;
175 range->encoding_size[1] = 13;
176 range->num_encoding_sizes = 2;
177 range->max_encoding_tokens = NUM_DEFAULT_KEYS;
178
179 range->max_qual.qual = local->hw.max_signal;
180 range->max_qual.level = local->hw.max_rssi;
181 range->max_qual.noise = local->hw.max_noise;
182 range->max_qual.updated = local->wstats_flags;
183
184 range->avg_qual.qual = local->hw.max_signal/2;
185 range->avg_qual.level = 0;
186 range->avg_qual.noise = 0;
187 range->avg_qual.updated = local->wstats_flags;
188
189 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
190 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
191
192 list_for_each_entry(mode, &local->modes_list, list) {
193 int i = 0;
194
195 if (!(local->enabled_modes & (1 << mode->mode)) ||
196 (local->hw_modes & local->enabled_modes &
197 (1 << MODE_IEEE80211G) && mode->mode == MODE_IEEE80211B))
198 continue;
199
200 while (i < mode->num_channels && c < IW_MAX_FREQUENCIES) {
201 struct ieee80211_channel *chan = &mode->channels[i];
202
203 if (chan->flag & IEEE80211_CHAN_W_SCAN) {
204 range->freq[c].i = chan->chan;
205 range->freq[c].m = chan->freq * 100000;
206 range->freq[c].e = 1;
207 c++;
208 }
209 i++;
210 }
211 }
212 range->num_channels = c;
213 range->num_frequency = c;
214
215 IW_EVENT_CAPA_SET_KERNEL(range->event_capa);
216 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWTHRSPY);
217 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWAP);
218 IW_EVENT_CAPA_SET(range->event_capa, SIOCGIWSCAN);
219
220 return 0;
221 }
222
223
224 static int ieee80211_ioctl_siwmode(struct net_device *dev,
225 struct iw_request_info *info,
226 __u32 *mode, char *extra)
227 {
228 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
229 int type;
230
231 if (sdata->type == IEEE80211_IF_TYPE_VLAN)
232 return -EOPNOTSUPP;
233
234 switch (*mode) {
235 case IW_MODE_INFRA:
236 type = IEEE80211_IF_TYPE_STA;
237 break;
238 case IW_MODE_ADHOC:
239 type = IEEE80211_IF_TYPE_IBSS;
240 break;
241 case IW_MODE_MONITOR:
242 type = IEEE80211_IF_TYPE_MNTR;
243 break;
244 default:
245 return -EINVAL;
246 }
247
248 if (type == sdata->type)
249 return 0;
250 if (netif_running(dev))
251 return -EBUSY;
252
253 ieee80211_if_reinit(dev);
254 ieee80211_if_set_type(dev, type);
255
256 return 0;
257 }
258
259
260 static int ieee80211_ioctl_giwmode(struct net_device *dev,
261 struct iw_request_info *info,
262 __u32 *mode, char *extra)
263 {
264 struct ieee80211_sub_if_data *sdata;
265
266 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
267 switch (sdata->type) {
268 case IEEE80211_IF_TYPE_AP:
269 *mode = IW_MODE_MASTER;
270 break;
271 case IEEE80211_IF_TYPE_STA:
272 *mode = IW_MODE_INFRA;
273 break;
274 case IEEE80211_IF_TYPE_IBSS:
275 *mode = IW_MODE_ADHOC;
276 break;
277 case IEEE80211_IF_TYPE_MNTR:
278 *mode = IW_MODE_MONITOR;
279 break;
280 case IEEE80211_IF_TYPE_WDS:
281 *mode = IW_MODE_REPEAT;
282 break;
283 case IEEE80211_IF_TYPE_VLAN:
284 *mode = IW_MODE_SECOND; /* FIXME */
285 break;
286 default:
287 *mode = IW_MODE_AUTO;
288 break;
289 }
290 return 0;
291 }
292
293 int ieee80211_set_channel(struct ieee80211_local *local, int channel, int freq)
294 {
295 struct ieee80211_hw_mode *mode;
296 int c, set = 0;
297 int ret = -EINVAL;
298
299 list_for_each_entry(mode, &local->modes_list, list) {
300 if (!(local->enabled_modes & (1 << mode->mode)))
301 continue;
302 for (c = 0; c < mode->num_channels; c++) {
303 struct ieee80211_channel *chan = &mode->channels[c];
304 if (chan->flag & IEEE80211_CHAN_W_SCAN &&
305 ((chan->chan == channel) || (chan->freq == freq))) {
306 local->oper_channel = chan;
307 local->oper_hw_mode = mode;
308 set++;
309 }
310 }
311 }
312
313 if (set) {
314 if (local->sta_scanning)
315 ret = 0;
316 else
317 ret = ieee80211_hw_config(local);
318
319 rate_control_clear(local);
320 }
321
322 return ret;
323 }
324
325 static int ieee80211_ioctl_siwfreq(struct net_device *dev,
326 struct iw_request_info *info,
327 struct iw_freq *freq, char *extra)
328 {
329 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
330 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
331
332 if (sdata->type == IEEE80211_IF_TYPE_STA)
333 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_CHANNEL_SEL;
334
335 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
336 if (freq->e == 0) {
337 if (freq->m < 0) {
338 if (sdata->type == IEEE80211_IF_TYPE_STA)
339 sdata->u.sta.flags |=
340 IEEE80211_STA_AUTO_CHANNEL_SEL;
341 return 0;
342 } else
343 return ieee80211_set_channel(local, freq->m, -1);
344 } else {
345 int i, div = 1000000;
346 for (i = 0; i < freq->e; i++)
347 div /= 10;
348 if (div > 0)
349 return ieee80211_set_channel(local, -1, freq->m / div);
350 else
351 return -EINVAL;
352 }
353 }
354
355
356 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
357 struct iw_request_info *info,
358 struct iw_freq *freq, char *extra)
359 {
360 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
361
362 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
363 * driver for the current channel with firmware-based management */
364
365 freq->m = local->hw.conf.freq;
366 freq->e = 6;
367
368 return 0;
369 }
370
371
372 static int ieee80211_ioctl_siwessid(struct net_device *dev,
373 struct iw_request_info *info,
374 struct iw_point *data, char *ssid)
375 {
376 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
377 struct ieee80211_sub_if_data *sdata;
378 size_t len = data->length;
379
380 /* iwconfig uses nul termination in SSID.. */
381 if (len > 0 && ssid[len - 1] == '\0')
382 len--;
383
384 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
385 if (sdata->type == IEEE80211_IF_TYPE_STA ||
386 sdata->type == IEEE80211_IF_TYPE_IBSS) {
387 int ret;
388 if (local->user_space_mlme) {
389 if (len > IEEE80211_MAX_SSID_LEN)
390 return -EINVAL;
391 memcpy(sdata->u.sta.ssid, ssid, len);
392 sdata->u.sta.ssid_len = len;
393 return 0;
394 }
395 if (data->flags)
396 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_SSID_SEL;
397 else
398 sdata->u.sta.flags |= IEEE80211_STA_AUTO_SSID_SEL;
399 ret = ieee80211_sta_set_ssid(dev, ssid, len);
400 if (ret)
401 return ret;
402 ieee80211_sta_req_auth(dev, &sdata->u.sta);
403 return 0;
404 }
405
406 if (sdata->type == IEEE80211_IF_TYPE_AP) {
407 memcpy(sdata->u.ap.ssid, ssid, len);
408 memset(sdata->u.ap.ssid + len, 0,
409 IEEE80211_MAX_SSID_LEN - len);
410 sdata->u.ap.ssid_len = len;
411 return ieee80211_if_config(dev);
412 }
413 return -EOPNOTSUPP;
414 }
415
416
417 static int ieee80211_ioctl_giwessid(struct net_device *dev,
418 struct iw_request_info *info,
419 struct iw_point *data, char *ssid)
420 {
421 size_t len;
422
423 struct ieee80211_sub_if_data *sdata;
424 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
425 if (sdata->type == IEEE80211_IF_TYPE_STA ||
426 sdata->type == IEEE80211_IF_TYPE_IBSS) {
427 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
428 if (res == 0) {
429 data->length = len;
430 data->flags = 1;
431 } else
432 data->flags = 0;
433 return res;
434 }
435
436 if (sdata->type == IEEE80211_IF_TYPE_AP) {
437 len = sdata->u.ap.ssid_len;
438 if (len > IW_ESSID_MAX_SIZE)
439 len = IW_ESSID_MAX_SIZE;
440 memcpy(ssid, sdata->u.ap.ssid, len);
441 data->length = len;
442 data->flags = 1;
443 return 0;
444 }
445 return -EOPNOTSUPP;
446 }
447
448
449 static int ieee80211_ioctl_siwap(struct net_device *dev,
450 struct iw_request_info *info,
451 struct sockaddr *ap_addr, char *extra)
452 {
453 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
454 struct ieee80211_sub_if_data *sdata;
455
456 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
457 if (sdata->type == IEEE80211_IF_TYPE_STA ||
458 sdata->type == IEEE80211_IF_TYPE_IBSS) {
459 int ret;
460 if (local->user_space_mlme) {
461 memcpy(sdata->u.sta.bssid, (u8 *) &ap_addr->sa_data,
462 ETH_ALEN);
463 return 0;
464 }
465 if (is_zero_ether_addr((u8 *) &ap_addr->sa_data))
466 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL |
467 IEEE80211_STA_AUTO_CHANNEL_SEL;
468 else if (is_broadcast_ether_addr((u8 *) &ap_addr->sa_data))
469 sdata->u.sta.flags |= IEEE80211_STA_AUTO_BSSID_SEL;
470 else
471 sdata->u.sta.flags &= ~IEEE80211_STA_AUTO_BSSID_SEL;
472 ret = ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
473 if (ret)
474 return ret;
475 ieee80211_sta_req_auth(dev, &sdata->u.sta);
476 return 0;
477 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
478 if (memcmp(sdata->u.wds.remote_addr, (u8 *) &ap_addr->sa_data,
479 ETH_ALEN) == 0)
480 return 0;
481 return ieee80211_if_update_wds(dev, (u8 *) &ap_addr->sa_data);
482 }
483
484 return -EOPNOTSUPP;
485 }
486
487
488 static int ieee80211_ioctl_giwap(struct net_device *dev,
489 struct iw_request_info *info,
490 struct sockaddr *ap_addr, char *extra)
491 {
492 struct ieee80211_sub_if_data *sdata;
493
494 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
495 if (sdata->type == IEEE80211_IF_TYPE_STA ||
496 sdata->type == IEEE80211_IF_TYPE_IBSS) {
497 ap_addr->sa_family = ARPHRD_ETHER;
498 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
499 return 0;
500 } else if (sdata->type == IEEE80211_IF_TYPE_WDS) {
501 ap_addr->sa_family = ARPHRD_ETHER;
502 memcpy(&ap_addr->sa_data, sdata->u.wds.remote_addr, ETH_ALEN);
503 return 0;
504 }
505
506 return -EOPNOTSUPP;
507 }
508
509
510 static int ieee80211_ioctl_siwscan(struct net_device *dev,
511 struct iw_request_info *info,
512 struct iw_point *data, char *extra)
513 {
514 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
515 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
516 u8 *ssid = NULL;
517 size_t ssid_len = 0;
518
519 if (!netif_running(dev))
520 return -ENETDOWN;
521
522 switch (sdata->type) {
523 case IEEE80211_IF_TYPE_STA:
524 case IEEE80211_IF_TYPE_IBSS:
525 if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
526 ssid = sdata->u.sta.ssid;
527 ssid_len = sdata->u.sta.ssid_len;
528 }
529 break;
530 case IEEE80211_IF_TYPE_AP:
531 if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
532 ssid = sdata->u.ap.ssid;
533 ssid_len = sdata->u.ap.ssid_len;
534 }
535 break;
536 default:
537 return -EOPNOTSUPP;
538 }
539
540 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
541 }
542
543
544 static int ieee80211_ioctl_giwscan(struct net_device *dev,
545 struct iw_request_info *info,
546 struct iw_point *data, char *extra)
547 {
548 int res;
549 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
550 if (local->sta_scanning)
551 return -EAGAIN;
552 res = ieee80211_sta_scan_results(dev, extra, data->length);
553 if (res >= 0) {
554 data->length = res;
555 return 0;
556 }
557 data->length = 0;
558 return res;
559 }
560
561
562 static int ieee80211_ioctl_siwrate(struct net_device *dev,
563 struct iw_request_info *info,
564 struct iw_param *rate, char *extra)
565 {
566 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
567 struct ieee80211_hw_mode *mode;
568 int i;
569 u32 target_rate = rate->value / 100000;
570 struct ieee80211_sub_if_data *sdata;
571
572 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
573 if (!sdata->bss)
574 return -ENODEV;
575 mode = local->oper_hw_mode;
576 /* target_rate = -1, rate->fixed = 0 means auto only, so use all rates
577 * target_rate = X, rate->fixed = 1 means only rate X
578 * target_rate = X, rate->fixed = 0 means all rates <= X */
579 sdata->bss->max_ratectrl_rateidx = -1;
580 sdata->bss->force_unicast_rateidx = -1;
581 if (rate->value < 0)
582 return 0;
583 for (i=0; i< mode->num_rates; i++) {
584 struct ieee80211_rate *rates = &mode->rates[i];
585 int this_rate = rates->rate;
586
587 if (target_rate == this_rate) {
588 sdata->bss->max_ratectrl_rateidx = i;
589 if (rate->fixed)
590 sdata->bss->force_unicast_rateidx = i;
591 break;
592 }
593 }
594 return 0;
595 }
596
597 static int ieee80211_ioctl_giwrate(struct net_device *dev,
598 struct iw_request_info *info,
599 struct iw_param *rate, char *extra)
600 {
601 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
602 struct sta_info *sta;
603 struct ieee80211_sub_if_data *sdata;
604
605 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
606 if (sdata->type == IEEE80211_IF_TYPE_STA)
607 sta = sta_info_get(local, sdata->u.sta.bssid);
608 else
609 return -EOPNOTSUPP;
610 if (!sta)
611 return -ENODEV;
612 if (sta->txrate < local->oper_hw_mode->num_rates)
613 rate->value = local->oper_hw_mode->rates[sta->txrate].rate * 100000;
614 else
615 rate->value = 0;
616 sta_info_put(sta);
617 return 0;
618 }
619
620 static int ieee80211_ioctl_siwtxpower(struct net_device *dev,
621 struct iw_request_info *info,
622 union iwreq_data *data, char *extra)
623 {
624 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
625 bool need_reconfig = 0;
626
627 if ((data->txpower.flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM)
628 return -EINVAL;
629 if (data->txpower.flags & IW_TXPOW_RANGE)
630 return -EINVAL;
631 if (!data->txpower.fixed)
632 return -EINVAL;
633
634 if (local->hw.conf.power_level != data->txpower.value) {
635 local->hw.conf.power_level = data->txpower.value;
636 need_reconfig = 1;
637 }
638 if (local->hw.conf.radio_enabled != !(data->txpower.disabled)) {
639 local->hw.conf.radio_enabled = !(data->txpower.disabled);
640 need_reconfig = 1;
641 }
642 if (need_reconfig) {
643 ieee80211_hw_config(local);
644 /* The return value of hw_config is not of big interest here,
645 * as it doesn't say that it failed because of _this_ config
646 * change or something else. Ignore it. */
647 }
648
649 return 0;
650 }
651
652 static int ieee80211_ioctl_giwtxpower(struct net_device *dev,
653 struct iw_request_info *info,
654 union iwreq_data *data, char *extra)
655 {
656 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
657
658 data->txpower.fixed = 1;
659 data->txpower.disabled = !(local->hw.conf.radio_enabled);
660 data->txpower.value = local->hw.conf.power_level;
661 data->txpower.flags = IW_TXPOW_DBM;
662
663 return 0;
664 }
665
666 static int ieee80211_ioctl_siwrts(struct net_device *dev,
667 struct iw_request_info *info,
668 struct iw_param *rts, char *extra)
669 {
670 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
671
672 if (rts->disabled)
673 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
674 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
675 return -EINVAL;
676 else
677 local->rts_threshold = rts->value;
678
679 /* If the wlan card performs RTS/CTS in hardware/firmware,
680 * configure it here */
681
682 if (local->ops->set_rts_threshold)
683 local->ops->set_rts_threshold(local_to_hw(local),
684 local->rts_threshold);
685
686 return 0;
687 }
688
689 static int ieee80211_ioctl_giwrts(struct net_device *dev,
690 struct iw_request_info *info,
691 struct iw_param *rts, char *extra)
692 {
693 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
694
695 rts->value = local->rts_threshold;
696 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
697 rts->fixed = 1;
698
699 return 0;
700 }
701
702
703 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
704 struct iw_request_info *info,
705 struct iw_param *frag, char *extra)
706 {
707 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
708
709 if (frag->disabled)
710 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
711 else if (frag->value < 256 ||
712 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
713 return -EINVAL;
714 else {
715 /* Fragment length must be even, so strip LSB. */
716 local->fragmentation_threshold = frag->value & ~0x1;
717 }
718
719 /* If the wlan card performs fragmentation in hardware/firmware,
720 * configure it here */
721
722 if (local->ops->set_frag_threshold)
723 local->ops->set_frag_threshold(
724 local_to_hw(local),
725 local->fragmentation_threshold);
726
727 return 0;
728 }
729
730 static int ieee80211_ioctl_giwfrag(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 frag->value = local->fragmentation_threshold;
737 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
738 frag->fixed = 1;
739
740 return 0;
741 }
742
743
744 static int ieee80211_ioctl_siwretry(struct net_device *dev,
745 struct iw_request_info *info,
746 struct iw_param *retry, char *extra)
747 {
748 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
749
750 if (retry->disabled ||
751 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
752 return -EINVAL;
753
754 if (retry->flags & IW_RETRY_MAX)
755 local->long_retry_limit = retry->value;
756 else if (retry->flags & IW_RETRY_MIN)
757 local->short_retry_limit = retry->value;
758 else {
759 local->long_retry_limit = retry->value;
760 local->short_retry_limit = retry->value;
761 }
762
763 if (local->ops->set_retry_limit) {
764 return local->ops->set_retry_limit(
765 local_to_hw(local),
766 local->short_retry_limit,
767 local->long_retry_limit);
768 }
769
770 return 0;
771 }
772
773
774 static int ieee80211_ioctl_giwretry(struct net_device *dev,
775 struct iw_request_info *info,
776 struct iw_param *retry, char *extra)
777 {
778 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
779
780 retry->disabled = 0;
781 if (retry->flags == 0 || retry->flags & IW_RETRY_MIN) {
782 /* first return min value, iwconfig will ask max value
783 * later if needed */
784 retry->flags |= IW_RETRY_LIMIT;
785 retry->value = local->short_retry_limit;
786 if (local->long_retry_limit != local->short_retry_limit)
787 retry->flags |= IW_RETRY_MIN;
788 return 0;
789 }
790 if (retry->flags & IW_RETRY_MAX) {
791 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
792 retry->value = local->long_retry_limit;
793 }
794
795 return 0;
796 }
797
798 static int ieee80211_ioctl_siwmlme(struct net_device *dev,
799 struct iw_request_info *info,
800 struct iw_point *data, char *extra)
801 {
802 struct ieee80211_sub_if_data *sdata;
803 struct iw_mlme *mlme = (struct iw_mlme *) extra;
804
805 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
806 if (sdata->type != IEEE80211_IF_TYPE_STA &&
807 sdata->type != IEEE80211_IF_TYPE_IBSS)
808 return -EINVAL;
809
810 switch (mlme->cmd) {
811 case IW_MLME_DEAUTH:
812 /* TODO: mlme->addr.sa_data */
813 return ieee80211_sta_deauthenticate(dev, mlme->reason_code);
814 case IW_MLME_DISASSOC:
815 /* TODO: mlme->addr.sa_data */
816 return ieee80211_sta_disassociate(dev, mlme->reason_code);
817 default:
818 return -EOPNOTSUPP;
819 }
820 }
821
822
823 static int ieee80211_ioctl_siwencode(struct net_device *dev,
824 struct iw_request_info *info,
825 struct iw_point *erq, char *keybuf)
826 {
827 struct ieee80211_sub_if_data *sdata;
828 int idx, i, alg = ALG_WEP;
829 u8 bcaddr[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
830
831 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
832
833 idx = erq->flags & IW_ENCODE_INDEX;
834 if (idx == 0) {
835 if (sdata->default_key)
836 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
837 if (sdata->default_key == sdata->keys[i]) {
838 idx = i;
839 break;
840 }
841 }
842 } else if (idx < 1 || idx > 4)
843 return -EINVAL;
844 else
845 idx--;
846
847 if (erq->flags & IW_ENCODE_DISABLED)
848 alg = ALG_NONE;
849 else if (erq->length == 0) {
850 /* No key data - just set the default TX key index */
851 ieee80211_set_default_key(sdata, idx);
852 return 0;
853 }
854
855 return ieee80211_set_encryption(
856 dev, bcaddr,
857 idx, alg,
858 !sdata->default_key,
859 keybuf, erq->length);
860 }
861
862
863 static int ieee80211_ioctl_giwencode(struct net_device *dev,
864 struct iw_request_info *info,
865 struct iw_point *erq, char *key)
866 {
867 struct ieee80211_sub_if_data *sdata;
868 int idx, i;
869
870 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
871
872 idx = erq->flags & IW_ENCODE_INDEX;
873 if (idx < 1 || idx > 4) {
874 idx = -1;
875 if (!sdata->default_key)
876 idx = 0;
877 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
878 if (sdata->default_key == sdata->keys[i]) {
879 idx = i;
880 break;
881 }
882 }
883 if (idx < 0)
884 return -EINVAL;
885 } else
886 idx--;
887
888 erq->flags = idx + 1;
889
890 if (!sdata->keys[idx]) {
891 erq->length = 0;
892 erq->flags |= IW_ENCODE_DISABLED;
893 return 0;
894 }
895
896 memcpy(key, sdata->keys[idx]->conf.key,
897 min_t(int, erq->length, sdata->keys[idx]->conf.keylen));
898 erq->length = sdata->keys[idx]->conf.keylen;
899 erq->flags |= IW_ENCODE_ENABLED;
900
901 return 0;
902 }
903
904 static int ieee80211_ioctl_siwauth(struct net_device *dev,
905 struct iw_request_info *info,
906 struct iw_param *data, char *extra)
907 {
908 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
909 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
910 int ret = 0;
911
912 switch (data->flags & IW_AUTH_INDEX) {
913 case IW_AUTH_WPA_VERSION:
914 case IW_AUTH_CIPHER_PAIRWISE:
915 case IW_AUTH_CIPHER_GROUP:
916 case IW_AUTH_WPA_ENABLED:
917 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
918 break;
919 case IW_AUTH_KEY_MGMT:
920 if (sdata->type != IEEE80211_IF_TYPE_STA)
921 ret = -EINVAL;
922 else {
923 /*
924 * Key management was set by wpa_supplicant,
925 * we only need this to associate to a network
926 * that has privacy enabled regardless of not
927 * having a key.
928 */
929 sdata->u.sta.key_management_enabled = !!data->value;
930 }
931 break;
932 case IW_AUTH_80211_AUTH_ALG:
933 if (sdata->type == IEEE80211_IF_TYPE_STA ||
934 sdata->type == IEEE80211_IF_TYPE_IBSS)
935 sdata->u.sta.auth_algs = data->value;
936 else
937 ret = -EOPNOTSUPP;
938 break;
939 case IW_AUTH_PRIVACY_INVOKED:
940 if (local->ops->set_privacy_invoked)
941 ret = local->ops->set_privacy_invoked(
942 local_to_hw(local), data->value);
943 break;
944 default:
945 ret = -EOPNOTSUPP;
946 break;
947 }
948 return ret;
949 }
950
951 /* Get wireless statistics. Called by /proc/net/wireless and by SIOCGIWSTATS */
952 static struct iw_statistics *ieee80211_get_wireless_stats(struct net_device *dev)
953 {
954 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
955 struct iw_statistics *wstats = &local->wstats;
956 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
957 struct sta_info *sta = NULL;
958
959 if (sdata->type == IEEE80211_IF_TYPE_STA ||
960 sdata->type == IEEE80211_IF_TYPE_IBSS)
961 sta = sta_info_get(local, sdata->u.sta.bssid);
962 if (!sta) {
963 wstats->discard.fragment = 0;
964 wstats->discard.misc = 0;
965 wstats->qual.qual = 0;
966 wstats->qual.level = 0;
967 wstats->qual.noise = 0;
968 wstats->qual.updated = IW_QUAL_ALL_INVALID;
969 } else {
970 wstats->qual.level = sta->last_rssi;
971 wstats->qual.qual = sta->last_signal;
972 wstats->qual.noise = sta->last_noise;
973 wstats->qual.updated = local->wstats_flags;
974 sta_info_put(sta);
975 }
976 return wstats;
977 }
978
979 static int ieee80211_ioctl_giwauth(struct net_device *dev,
980 struct iw_request_info *info,
981 struct iw_param *data, char *extra)
982 {
983 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
984 int ret = 0;
985
986 switch (data->flags & IW_AUTH_INDEX) {
987 case IW_AUTH_80211_AUTH_ALG:
988 if (sdata->type == IEEE80211_IF_TYPE_STA ||
989 sdata->type == IEEE80211_IF_TYPE_IBSS)
990 data->value = sdata->u.sta.auth_algs;
991 else
992 ret = -EOPNOTSUPP;
993 break;
994 default:
995 ret = -EOPNOTSUPP;
996 break;
997 }
998 return ret;
999 }
1000
1001
1002 static int ieee80211_ioctl_siwencodeext(struct net_device *dev,
1003 struct iw_request_info *info,
1004 struct iw_point *erq, char *extra)
1005 {
1006 struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1007 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
1008 int alg, idx, i;
1009
1010 switch (ext->alg) {
1011 case IW_ENCODE_ALG_NONE:
1012 alg = ALG_NONE;
1013 break;
1014 case IW_ENCODE_ALG_WEP:
1015 alg = ALG_WEP;
1016 break;
1017 case IW_ENCODE_ALG_TKIP:
1018 alg = ALG_TKIP;
1019 break;
1020 case IW_ENCODE_ALG_CCMP:
1021 alg = ALG_CCMP;
1022 break;
1023 default:
1024 return -EOPNOTSUPP;
1025 }
1026
1027 if (erq->flags & IW_ENCODE_DISABLED)
1028 alg = ALG_NONE;
1029
1030 idx = erq->flags & IW_ENCODE_INDEX;
1031 if (idx < 1 || idx > 4) {
1032 idx = -1;
1033 if (!sdata->default_key)
1034 idx = 0;
1035 else for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
1036 if (sdata->default_key == sdata->keys[i]) {
1037 idx = i;
1038 break;
1039 }
1040 }
1041 if (idx < 0)
1042 return -EINVAL;
1043 } else
1044 idx--;
1045
1046 return ieee80211_set_encryption(dev, ext->addr.sa_data, idx, alg,
1047 ext->ext_flags &
1048 IW_ENCODE_EXT_SET_TX_KEY,
1049 ext->key, ext->key_len);
1050 }
1051
1052
1053 /* Structures to export the Wireless Handlers */
1054
1055 static const iw_handler ieee80211_handler[] =
1056 {
1057 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1058 (iw_handler) ieee80211_ioctl_giwname, /* SIOCGIWNAME */
1059 (iw_handler) NULL, /* SIOCSIWNWID */
1060 (iw_handler) NULL, /* SIOCGIWNWID */
1061 (iw_handler) ieee80211_ioctl_siwfreq, /* SIOCSIWFREQ */
1062 (iw_handler) ieee80211_ioctl_giwfreq, /* SIOCGIWFREQ */
1063 (iw_handler) ieee80211_ioctl_siwmode, /* SIOCSIWMODE */
1064 (iw_handler) ieee80211_ioctl_giwmode, /* SIOCGIWMODE */
1065 (iw_handler) NULL, /* SIOCSIWSENS */
1066 (iw_handler) NULL, /* SIOCGIWSENS */
1067 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
1068 (iw_handler) ieee80211_ioctl_giwrange, /* SIOCGIWRANGE */
1069 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
1070 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
1071 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
1072 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
1073 (iw_handler) NULL, /* SIOCSIWSPY */
1074 (iw_handler) NULL, /* SIOCGIWSPY */
1075 (iw_handler) NULL, /* SIOCSIWTHRSPY */
1076 (iw_handler) NULL, /* SIOCGIWTHRSPY */
1077 (iw_handler) ieee80211_ioctl_siwap, /* SIOCSIWAP */
1078 (iw_handler) ieee80211_ioctl_giwap, /* SIOCGIWAP */
1079 (iw_handler) ieee80211_ioctl_siwmlme, /* SIOCSIWMLME */
1080 (iw_handler) NULL, /* SIOCGIWAPLIST */
1081 (iw_handler) ieee80211_ioctl_siwscan, /* SIOCSIWSCAN */
1082 (iw_handler) ieee80211_ioctl_giwscan, /* SIOCGIWSCAN */
1083 (iw_handler) ieee80211_ioctl_siwessid, /* SIOCSIWESSID */
1084 (iw_handler) ieee80211_ioctl_giwessid, /* SIOCGIWESSID */
1085 (iw_handler) NULL, /* SIOCSIWNICKN */
1086 (iw_handler) NULL, /* SIOCGIWNICKN */
1087 (iw_handler) NULL, /* -- hole -- */
1088 (iw_handler) NULL, /* -- hole -- */
1089 (iw_handler) ieee80211_ioctl_siwrate, /* SIOCSIWRATE */
1090 (iw_handler) ieee80211_ioctl_giwrate, /* SIOCGIWRATE */
1091 (iw_handler) ieee80211_ioctl_siwrts, /* SIOCSIWRTS */
1092 (iw_handler) ieee80211_ioctl_giwrts, /* SIOCGIWRTS */
1093 (iw_handler) ieee80211_ioctl_siwfrag, /* SIOCSIWFRAG */
1094 (iw_handler) ieee80211_ioctl_giwfrag, /* SIOCGIWFRAG */
1095 (iw_handler) ieee80211_ioctl_siwtxpower, /* SIOCSIWTXPOW */
1096 (iw_handler) ieee80211_ioctl_giwtxpower, /* SIOCGIWTXPOW */
1097 (iw_handler) ieee80211_ioctl_siwretry, /* SIOCSIWRETRY */
1098 (iw_handler) ieee80211_ioctl_giwretry, /* SIOCGIWRETRY */
1099 (iw_handler) ieee80211_ioctl_siwencode, /* SIOCSIWENCODE */
1100 (iw_handler) ieee80211_ioctl_giwencode, /* SIOCGIWENCODE */
1101 (iw_handler) NULL, /* SIOCSIWPOWER */
1102 (iw_handler) NULL, /* SIOCGIWPOWER */
1103 (iw_handler) NULL, /* -- hole -- */
1104 (iw_handler) NULL, /* -- hole -- */
1105 (iw_handler) ieee80211_ioctl_siwgenie, /* SIOCSIWGENIE */
1106 (iw_handler) NULL, /* SIOCGIWGENIE */
1107 (iw_handler) ieee80211_ioctl_siwauth, /* SIOCSIWAUTH */
1108 (iw_handler) ieee80211_ioctl_giwauth, /* SIOCGIWAUTH */
1109 (iw_handler) ieee80211_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
1110 (iw_handler) NULL, /* SIOCGIWENCODEEXT */
1111 (iw_handler) NULL, /* SIOCSIWPMKSA */
1112 (iw_handler) NULL, /* -- hole -- */
1113 };
1114
1115 const struct iw_handler_def ieee80211_iw_handler_def =
1116 {
1117 .num_standard = ARRAY_SIZE(ieee80211_handler),
1118 .standard = (iw_handler *) ieee80211_handler,
1119 .get_wireless_stats = ieee80211_get_wireless_stats,
1120 };
This page took 0.102176 seconds and 5 git commands to generate.