a44b02e8ee7efe8ffe2c138e244e8cc1193e1502
[openwrt.git] / openwrt / target / linux / package / ieee80211-dscape / src / ieee80211_ioctl.c
1 /*
2 * Copyright 2002-2005, Instant802 Networks, Inc.
3 * Copyright 2005, 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/config.h>
11 #include <linux/version.h>
12 #include <linux/module.h>
13 #include <linux/init.h>
14 #include <linux/netdevice.h>
15 #include <linux/types.h>
16 #include <linux/slab.h>
17 #include <linux/skbuff.h>
18 #include <linux/if_arp.h>
19 #include <linux/wireless.h>
20 #include <net/iw_handler.h>
21 #include <asm/uaccess.h>
22
23 #include <net/ieee80211.h>
24 #include <net/ieee80211_mgmt.h>
25 #include "ieee80211_i.h"
26 #include "hostapd_ioctl.h"
27 #include "rate_control.h"
28 #include "wpa.h"
29 #include "aes_ccm.h"
30
31
32 static int ieee80211_regdom = 0x10; /* FCC */
33 MODULE_PARM(ieee80211_regdom, "i");
34 MODULE_PARM_DESC(ieee80211_regdom, "IEEE 802.11 regulatory domain; 64=MKK");
35
36 /*
37 * If firmware is upgraded by the vendor, additional channels can be used based
38 * on the new Japanese regulatory rules. This is indicated by setting
39 * ieee80211_japan_5ghz module parameter to one when loading the 80211 kernel
40 * module.
41 */
42 static int ieee80211_japan_5ghz /* = 0 */;
43 MODULE_PARM(ieee80211_japan_5ghz, "i");
44 MODULE_PARM_DESC(ieee80211_japan_5ghz, "Vendor-updated firmware for 5 GHz");
45
46
47 static int ieee80211_ioctl_set_beacon(struct net_device *dev,
48 struct prism2_hostapd_param *param,
49 int param_len,
50 int flag)
51 {
52 struct ieee80211_sub_if_data *sdata;
53 struct ieee80211_if_norm *norm;
54 u8 **b_head, **b_tail;
55 int *b_head_len, *b_tail_len;
56 int len;
57
58 len = ((char *) param->u.beacon.data - (char *) param) +
59 param->u.beacon.head_len + param->u.beacon.tail_len;
60
61 if (param_len > len)
62 param_len = len;
63 else if (param_len != len)
64 return -EINVAL;
65
66 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
67 if (sdata->type != IEEE80211_SUB_IF_TYPE_NORM)
68 return -EINVAL;
69 norm = &sdata->u.norm;
70
71 switch (flag) {
72 case 0:
73 b_head = &norm->beacon_head;
74 b_tail = &norm->beacon_tail;
75 b_head_len = &norm->beacon_head_len;
76 b_tail_len = &norm->beacon_tail_len;
77 break;
78 default:
79 printk(KERN_DEBUG "%s: unknown beacon flag %d\n",
80 dev->name, flag);
81 return -EINVAL;
82 }
83
84 kfree(*b_head);
85 kfree(*b_tail);
86 *b_head = NULL;
87 *b_tail = NULL;
88
89 *b_head_len = param->u.beacon.head_len;
90 *b_tail_len = param->u.beacon.tail_len;
91
92 *b_head = kmalloc(*b_head_len, GFP_KERNEL);
93 if (*b_head)
94 memcpy(*b_head, param->u.beacon.data, *b_head_len);
95 else {
96 printk(KERN_DEBUG "%s: failed to allocate beacon_head\n",
97 dev->name);
98 return -ENOMEM;
99 }
100
101 if (*b_tail_len > 0) {
102 *b_tail = kmalloc(*b_tail_len, GFP_KERNEL);
103 if (*b_tail)
104 memcpy(*b_tail, param->u.beacon.data + (*b_head_len),
105 (*b_tail_len));
106 else {
107 printk(KERN_DEBUG "%s: failed to allocate "
108 "beacon_tail\n", dev->name);
109 return -ENOMEM;
110 }
111 }
112
113 return 0;
114 }
115
116
117 static int ieee80211_ioctl_get_hw_features(struct net_device *dev,
118 struct prism2_hostapd_param *param,
119 int param_len)
120 {
121 struct ieee80211_local *local = dev->priv;
122 u8 *pos = param->u.hw_features.data;
123 int left = param_len - (pos - (u8 *) param);
124 int mode, i;
125 struct hostapd_ioctl_hw_modes_hdr *hdr;
126 struct ieee80211_rate_data *rate;
127 struct ieee80211_channel_data *chan;
128
129 param->u.hw_features.flags = 0;
130 if (local->hw->data_nullfunc_ack)
131 param->u.hw_features.flags |= HOSTAP_HW_FLAG_NULLFUNC_OK;
132
133 param->u.hw_features.num_modes = local->hw->num_modes;
134 for (mode = 0; mode < local->hw->num_modes; mode++) {
135 int clen, rlen;
136 struct ieee80211_hw_modes *m = &local->hw->modes[mode];
137 clen = m->num_channels * sizeof(struct ieee80211_channel_data);
138 rlen = m->num_rates * sizeof(struct ieee80211_rate_data);
139 if (left < sizeof(*hdr) + clen + rlen)
140 return -E2BIG;
141 left -= sizeof(*hdr) + clen + rlen;
142
143 hdr = (struct hostapd_ioctl_hw_modes_hdr *) pos;
144 hdr->mode = m->mode;
145 hdr->num_channels = m->num_channels;
146 hdr->num_rates = m->num_rates;
147
148 pos = (u8 *) (hdr + 1);
149 chan = (struct ieee80211_channel_data *) pos;
150 for (i = 0; i < m->num_channels; i++) {
151 chan[i].chan = m->channels[i].chan;
152 chan[i].freq = m->channels[i].freq;
153 chan[i].flag = m->channels[i].flag;
154 }
155 pos += clen;
156
157 rate = (struct ieee80211_rate_data *) pos;
158 for (i = 0; i < m->num_rates; i++) {
159 rate[i].rate = m->rates[i].rate;
160 rate[i].flags = m->rates[i].flags;
161 }
162 pos += rlen;
163 }
164
165 return 0;
166 }
167
168
169 static int ieee80211_ioctl_scan(struct net_device *dev,
170 struct prism2_hostapd_param *param)
171 {
172 struct ieee80211_local *local = dev->priv;
173
174 if (local->hw->passive_scan == NULL)
175 return -EOPNOTSUPP;
176
177 if ((param->u.scan.now == 1) && (local->scan.in_scan == 1))
178 return -EBUSY;
179
180 if (param->u.scan.our_mode_only >= 0)
181 local->scan.our_mode_only = param->u.scan.our_mode_only;
182 if (param->u.scan.interval >= 0)
183 local->scan.interval = param->u.scan.interval;
184 if (param->u.scan.listen >= 0)
185 local->scan.time = param->u.scan.listen;
186 if (param->u.scan.channel > 0)
187 local->scan.channel = param->u.scan.channel;
188 if (param->u.scan.now == 1) {
189 local->scan.in_scan = 0;
190 mod_timer(&local->scan.timer, jiffies);
191 }
192
193 param->u.scan.our_mode_only = local->scan.our_mode_only;
194 param->u.scan.interval = local->scan.interval;
195 param->u.scan.listen = local->scan.time;
196 if (local->scan.in_scan == 1)
197 param->u.scan.last_rx = -1;
198 else {
199 param->u.scan.last_rx = local->scan.rx_packets;
200 local->scan.rx_packets = -1;
201 }
202 param->u.scan.channel = local->hw->modes[local->scan.mode_idx].
203 channels[local->scan.chan_idx].chan;
204
205 return 0;
206 }
207
208
209 static int ieee80211_ioctl_flush(struct net_device *dev,
210 struct prism2_hostapd_param *param)
211 {
212 struct ieee80211_local *local = dev->priv;
213 sta_info_flush(local, NULL);
214 return 0;
215 }
216
217
218
219
220 static int ieee80211_ioctl_add_sta(struct net_device *dev,
221 struct prism2_hostapd_param *param)
222 {
223 struct ieee80211_local *local = dev->priv;
224 struct sta_info *sta;
225 u32 rates;
226 int i, j;
227 struct ieee80211_sub_if_data *sdata;
228 int add_key_entry = 1;
229
230 sta = sta_info_get(local, param->sta_addr);
231
232 if (sta == NULL) {
233 sta = sta_info_add(local, dev, param->sta_addr);
234 if (sta == NULL)
235 return -ENOMEM;
236 }
237
238 if (sta->dev != dev) {
239 /* Binding STA to a new interface, so remove all references to
240 * the old BSS. */
241 sta_info_remove_aid_ptr(sta);
242 }
243
244 /* TODO
245 * We "steal" the device in case someone owns it
246 * This will hurt WDS links and such when we have a
247 * WDS link and a client associating from the same station
248 */
249 sta->dev = dev;
250 sdata = IEEE80211_DEV_TO_SUB_IF(sta->dev);
251
252 sta->flags |= WLAN_STA_AUTH | WLAN_STA_ASSOC;
253 sta->aid = param->u.add_sta.aid;
254 if (sta->aid > MAX_AID_TABLE_SIZE)
255 sta->aid = 0;
256 if (sta->aid > 0 && sdata->bss)
257 sdata->bss->sta_aid[sta->aid - 1] = sta;
258 if (sdata->bss && sta->aid > sdata->bss->max_aid)
259 sdata->bss->max_aid = sta->aid;
260
261 rates = 0;
262 for (i = 0; i < sizeof(param->u.add_sta.supp_rates); i++) {
263 int rate = (param->u.add_sta.supp_rates[i] & 0x7f) * 5;
264 if (local->conf.phymode == MODE_ATHEROS_TURBO ||
265 local->conf.phymode == MODE_ATHEROS_TURBOG)
266 rate *= 2;
267 for (j = 0; j < local->num_curr_rates; j++) {
268 if (local->curr_rates[j].rate == rate)
269 rates |= BIT(j);
270 }
271
272 }
273 sta->supp_rates = rates;
274
275 rate_control_rate_init(local, sta);
276
277
278
279 if (param->u.add_sta.wds_flags & 0x01)
280 sta->flags |= WLAN_STA_WDS;
281 else
282 sta->flags &= ~WLAN_STA_WDS;
283
284 if (add_key_entry && sta->key == NULL && sdata->default_key == NULL &&
285 local->hw->set_key) {
286 struct ieee80211_key_conf conf;
287 /* Add key cache entry with NULL key type because this may used
288 * for TX filtering. */
289 memset(&conf, 0, sizeof(conf));
290 conf.hw_key_idx = HW_KEY_IDX_INVALID;
291 conf.alg = ALG_NULL;
292 conf.force_sw_encrypt = 1;
293 if (local->hw->set_key(dev, SET_KEY, sta->addr, &conf,
294 sta->aid)) {
295 sta->key_idx_compression = HW_KEY_IDX_INVALID;
296 } else {
297 sta->key_idx_compression = conf.hw_key_idx;
298 }
299 }
300
301 sta_info_release(local, sta);
302
303 return 0;
304 }
305
306
307 static int ieee80211_ioctl_remove_sta(struct net_device *dev,
308 struct prism2_hostapd_param *param)
309 {
310 struct ieee80211_local *local = dev->priv;
311 struct sta_info *sta;
312
313 sta = sta_info_get(local, param->sta_addr);
314 if (sta) {
315 sta_info_release(local, sta);
316 sta_info_free(local, sta, 1);
317 }
318
319 return sta ? 0 : -ENOENT;
320 }
321
322
323 static int ieee80211_ioctl_get_dot11counterstable(struct net_device *dev,
324 struct prism2_hostapd_param *param)
325 {
326 struct ieee80211_local *local = dev->priv;
327 struct ieee80211_low_level_stats stats;
328
329 memset(&stats, 0, sizeof(stats));
330 if (local->hw->get_stats)
331 local->hw->get_stats(dev, &stats);
332 param->u.dot11CountersTable.dot11TransmittedFragmentCount =
333 local->dot11TransmittedFragmentCount;
334 param->u.dot11CountersTable.dot11MulticastTransmittedFrameCount =
335 local->dot11MulticastTransmittedFrameCount;
336 param->u.dot11CountersTable.dot11ReceivedFragmentCount =
337 local->dot11ReceivedFragmentCount;
338 param->u.dot11CountersTable.dot11MulticastReceivedFrameCount =
339 local->dot11MulticastReceivedFrameCount;
340 param->u.dot11CountersTable.dot11TransmittedFrameCount =
341 local->dot11TransmittedFrameCount;
342 param->u.dot11CountersTable.dot11FCSErrorCount =
343 stats.dot11FCSErrorCount;
344 param->u.dot11CountersTable.dot11ACKFailureCount =
345 stats.dot11ACKFailureCount;
346 param->u.dot11CountersTable.dot11RTSFailureCount =
347 stats.dot11RTSFailureCount;
348 param->u.dot11CountersTable.dot11RTSSuccessCount =
349 stats.dot11RTSSuccessCount;
350
351 return 0;
352 }
353
354 static int ieee80211_ioctl_get_info_sta(struct net_device *dev,
355 struct prism2_hostapd_param *param)
356 {
357 struct ieee80211_local *local = dev->priv;
358 struct sta_info *sta;
359
360 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
361 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
362 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
363 struct ieee80211_sub_if_data *sdata;
364 struct net_device_stats *stats;
365
366 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
367 stats = ieee80211_dev_stats(sdata->master);
368 param->u.get_info_sta.rx_bytes = stats->rx_bytes;
369 param->u.get_info_sta.tx_bytes = stats->tx_bytes;
370 /* go through all STAs and get STA with lowest max. rate */
371 param->u.get_info_sta.current_tx_rate =
372 local->curr_rates[sta_info_min_txrate_get(local)].rate;
373 return 0;
374 }
375
376 sta = sta_info_get(local, param->sta_addr);
377
378 if (!sta)
379 return -ENOENT;
380
381 param->u.get_info_sta.inactive_msec =
382 jiffies_to_msecs(jiffies - sta->last_rx);
383 param->u.get_info_sta.rx_packets = sta->rx_packets;
384 param->u.get_info_sta.tx_packets = sta->tx_packets;
385 param->u.get_info_sta.rx_bytes = sta->rx_bytes;
386 param->u.get_info_sta.tx_bytes = sta->tx_bytes;
387 param->u.get_info_sta.channel_use = sta->channel_use;
388 param->u.get_info_sta.flags = sta->flags;
389 if (sta->txrate >= 0 && sta->txrate < local->num_curr_rates)
390 param->u.get_info_sta.current_tx_rate =
391 local->curr_rates[sta->txrate].rate;
392 param->u.get_info_sta.num_ps_buf_frames =
393 skb_queue_len(&sta->ps_tx_buf);
394 param->u.get_info_sta.tx_retry_failed = sta->tx_retry_failed;
395 param->u.get_info_sta.tx_retry_count = sta->tx_retry_count;
396 param->u.get_info_sta.last_rssi = sta->last_rssi;
397 param->u.get_info_sta.last_ack_rssi = sta->last_ack_rssi[2];
398
399 sta_info_release(local, sta);
400
401 return 0;
402 }
403
404
405 static int ieee80211_ioctl_set_flags_sta(struct net_device *dev,
406 struct prism2_hostapd_param *param)
407 {
408 struct ieee80211_local *local = dev->priv;
409 struct sta_info *sta;
410
411 sta = sta_info_get(local, param->sta_addr);
412 if (sta) {
413 sta->flags |= param->u.set_flags_sta.flags_or;
414 sta->flags &= param->u.set_flags_sta.flags_and;
415 if (local->hw->set_port_auth &&
416 (param->u.set_flags_sta.flags_or & WLAN_STA_AUTHORIZED) &&
417 local->hw->set_port_auth(local->mdev, sta->addr, 1))
418 printk(KERN_DEBUG "%s: failed to set low-level driver "
419 "PAE state (authorized) for " MACSTR "\n",
420 dev->name, MAC2STR(sta->addr));
421 if (local->hw->set_port_auth &&
422 !(param->u.set_flags_sta.flags_and & WLAN_STA_AUTHORIZED)
423 && local->hw->set_port_auth(local->mdev, sta->addr, 0))
424 printk(KERN_DEBUG "%s: failed to set low-level driver "
425 "PAE state (unauthorized) for " MACSTR "\n",
426 dev->name, MAC2STR(sta->addr));
427 sta_info_release(local, sta);
428 }
429
430 return sta ? 0 : -ENOENT;
431 }
432
433
434 int ieee80211_set_hw_encryption(struct net_device *dev,
435 struct sta_info *sta, u8 addr[ETH_ALEN],
436 struct ieee80211_key *key)
437 {
438 struct ieee80211_key_conf *keyconf = NULL;
439 struct ieee80211_local *local = dev->priv;
440 int rc = 0;
441
442 /* default to sw encryption; this will be cleared by low-level
443 * driver if the hw supports requested encryption */
444 if (key)
445 key->force_sw_encrypt = 1;
446
447 if (key && local->hw->set_key &&
448 (!local->conf.sw_encrypt || !local->conf.sw_decrypt) &&
449 (keyconf = ieee80211_key_data2conf(local, key)) != NULL) {
450 if (local->hw->set_key(dev, SET_KEY, addr,
451 keyconf, sta ? sta->aid : 0)) {
452 rc = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
453 key->force_sw_encrypt = 1;
454 key->hw_key_idx = HW_KEY_IDX_INVALID;
455 } else {
456 key->force_sw_encrypt =
457 keyconf->force_sw_encrypt;
458 key->hw_key_idx =
459 keyconf->hw_key_idx;
460
461 }
462 }
463 kfree(keyconf);
464
465 return rc;
466 }
467
468
469 static int ieee80211_ioctl_set_encryption(struct net_device *dev,
470 struct prism2_hostapd_param *param,
471 int param_len)
472 {
473 struct ieee80211_local *local = dev->priv;
474 int alg, ret = 0;
475 struct sta_info *sta;
476 struct ieee80211_key **key;
477 int set_tx_key = 0, try_hwaccel = 1;
478 struct ieee80211_key_conf *keyconf;
479 struct ieee80211_sub_if_data *sdata;
480
481 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
482
483 param->u.crypt.err = 0;
484 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
485
486 if (param_len <
487 (int) ((char *) param->u.crypt.key - (char *) param) +
488 param->u.crypt.key_len) {
489 printk(KERN_DEBUG "%s: set_encrypt - invalid param_lem\n",
490 dev->name);
491 return -EINVAL;
492 }
493
494 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
495 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
496 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
497 sta = NULL;
498 if (param->u.crypt.idx >= NUM_DEFAULT_KEYS) {
499 printk(KERN_DEBUG "%s: set_encrypt - invalid idx=%d\n",
500 dev->name, param->u.crypt.idx);
501 return -EINVAL;
502 }
503 key = &sdata->keys[param->u.crypt.idx];
504 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY)
505 set_tx_key = 1;
506
507 /* Disable hwaccel for default keys when the interface is not
508 * the default one.
509 * TODO: consider adding hwaccel support for these; at least
510 * Atheros key cache should be able to handle this since AP is
511 * only transmitting frames with default keys. */
512 /* FIX: hw key cache can be used when only one virtual
513 * STA is associated with each AP. If more than one STA
514 * is associated to the same AP, software encryption
515 * must be used. This should be done automatically
516 * based on configured station devices. For the time
517 * being, this can be only set at compile time. */
518 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
519 if (0 /* FIX: more than one STA per AP */)
520 try_hwaccel = 0;
521 } else
522 if (sdata->type != IEEE80211_SUB_IF_TYPE_NORM ||
523 dev != local->wdev)
524 try_hwaccel = 0;
525 } else {
526 if (param->u.crypt.idx != 0) {
527 printk(KERN_DEBUG "%s: set_encrypt - non-zero idx for "
528 "individual key\n", dev->name);
529 return -EINVAL;
530 }
531
532 sta = sta_info_get(local, param->sta_addr);
533 if (sta == NULL) {
534 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
535 #ifdef CONFIG_IEEE80211_VERBOSE_DEBUG
536 printk(KERN_DEBUG "%s: set_encrypt - unknown addr "
537 MACSTR "\n",
538 dev->name, MAC2STR(param->sta_addr));
539 #endif /* CONFIG_IEEE80211_VERBOSE_DEBUG */
540
541 return -ENOENT;
542 }
543
544 key = &sta->key;
545 }
546
547 if (strcmp(param->u.crypt.alg, "none") == 0) {
548 alg = ALG_NONE;
549 } else if (strcmp(param->u.crypt.alg, "WEP") == 0) {
550 alg = ALG_WEP;
551 } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
552 if (param->u.crypt.key_len != ALG_TKIP_KEY_LEN) {
553 printk(KERN_DEBUG "%s: set_encrypt - invalid TKIP key "
554 "length %d\n", dev->name,
555 param->u.crypt.key_len);
556 ret = -EINVAL;
557 goto done;
558 }
559 alg = ALG_TKIP;
560 } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
561 if (param->u.crypt.key_len != ALG_CCMP_KEY_LEN) {
562 printk(KERN_DEBUG "%s: set_encrypt - invalid CCMP key "
563 "length %d\n", dev->name,
564 param->u.crypt.key_len);
565 ret = -EINVAL;
566 goto done;
567 }
568 alg = ALG_CCMP;
569 } else {
570 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
571 printk(KERN_DEBUG "%s: set_encrypt - unknown alg\n",
572 dev->name);
573 ret = -EINVAL;
574 goto done;
575 }
576
577 /* FIX:
578 * Cannot configure default hwaccel keys with WEP algorithm, if
579 * any of the virtual interfaces is using static WEP
580 * configuration because hwaccel would otherwise try to decrypt
581 * these frames.
582 *
583 * For now, just disable WEP hwaccel for broadcast when there is
584 * possibility of conflict with default keys. This can maybe later be
585 * optimized by using non-default keys (at least with Atheros ar521x).
586 */
587 if (!sta && alg == ALG_WEP && !local->default_wep_only &&
588 local->conf.mode != IW_MODE_ADHOC &&
589 local->conf.mode != IW_MODE_INFRA) {
590 try_hwaccel = 0;
591 }
592
593 if (local->hw->device_hides_wep) {
594 /* Software encryption cannot be used with devices that hide
595 * encryption from the host system, so always try to use
596 * hardware acceleration with such devices. */
597 try_hwaccel = 1;
598 }
599
600 if (local->hw->no_tkip_wmm_hwaccel && alg == ALG_TKIP) {
601 if (sta && (sta->flags & WLAN_STA_WME)) {
602 /* Hardware does not support hwaccel with TKIP when using WMM.
603 */
604 try_hwaccel = 0;
605 }
606 else if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
607 sta = sta_info_get(local, sdata->u.sta.bssid);
608 if (sta) {
609 if (sta->flags & WLAN_STA_WME) {
610 try_hwaccel = 0;
611 }
612 sta_info_release(local, sta);
613 sta = NULL;
614 }
615 }
616 }
617
618
619 if (alg == ALG_NONE) {
620 keyconf = NULL;
621 if (try_hwaccel && *key && local->hw->set_key &&
622 (keyconf = ieee80211_key_data2conf(local, *key)) != NULL &&
623 local->hw->set_key(dev, DISABLE_KEY, param->sta_addr,
624 keyconf, sta ? sta->aid : 0)) {
625 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
626 printk(KERN_DEBUG "%s: set_encrypt - low-level disable"
627 " failed\n", dev->name);
628 ret = -EINVAL;
629 }
630 kfree(keyconf);
631
632 if (sdata->default_key == *key)
633 sdata->default_key = NULL;
634 kfree(*key);
635 *key = NULL;
636 } else {
637 if (*key == NULL || (*key)->keylen < param->u.crypt.key_len) {
638 kfree(*key);
639 *key = kmalloc(sizeof(struct ieee80211_key) +
640 param->u.crypt.key_len, GFP_ATOMIC);
641 if (*key == NULL) {
642 ret = -ENOMEM;
643 goto done;
644 }
645 }
646 memset(*key, 0, sizeof(struct ieee80211_key) +
647 param->u.crypt.key_len);
648 /* default to sw encryption; low-level driver sets these if the
649 * requested encryption is supported */
650 (*key)->hw_key_idx = HW_KEY_IDX_INVALID;
651 (*key)->force_sw_encrypt = 1;
652
653 (*key)->alg = alg;
654 (*key)->keyidx = param->u.crypt.idx;
655 (*key)->keylen = param->u.crypt.key_len;
656 memcpy((*key)->key, param->u.crypt.key,
657 param->u.crypt.key_len);
658 if (set_tx_key)
659 (*key)->default_tx_key = 1;
660
661 if (alg == ALG_CCMP) {
662 /* Initialize AES key state here as an optimization
663 * so that it does not need to be initialized for every
664 * packet. */
665 ieee80211_aes_key_setup_encrypt(
666 (*key)->u.ccmp.aes_state, (*key)->key);
667 }
668
669 if (try_hwaccel &&
670 (alg == ALG_WEP || alg == ALG_TKIP || alg == ALG_CCMP))
671 param->u.crypt.err = ieee80211_set_hw_encryption(
672 dev, sta, param->sta_addr, *key);
673 }
674
675 if (set_tx_key || (sta == NULL && sdata->default_key == NULL)) {
676 sdata->default_key = *key;
677 if (local->hw->set_key_idx &&
678 local->hw->set_key_idx(dev, param->u.crypt.idx))
679 printk(KERN_DEBUG "%s: failed to set TX key idx for "
680 "low-level driver\n", dev->name);
681 }
682
683 done:
684 if (sta)
685 sta_info_release(local, sta);
686
687 return ret;
688 }
689
690 static int ieee80211_ioctl_get_encryption(struct net_device *dev,
691 struct prism2_hostapd_param *param,
692 int param_len)
693 {
694 struct ieee80211_local *local = dev->priv;
695 int ret = 0;
696 struct sta_info *sta;
697 struct ieee80211_key **key;
698 int max_key_len;
699 struct ieee80211_sub_if_data *sdata;
700 u8 *pos;
701
702 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
703
704 param->u.crypt.err = 0;
705
706 max_key_len = param_len -
707 (int) ((char *) param->u.crypt.key - (char *) param);
708 if (max_key_len < 0)
709 return -EINVAL;
710
711 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
712 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
713 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
714 sta = NULL;
715 if (param->u.crypt.idx > NUM_DEFAULT_KEYS) {
716 param->u.crypt.idx = sdata->default_key ?
717 sdata->default_key->keyidx : 0;
718 return 0;
719 } else
720 key = &sdata->keys[param->u.crypt.idx];
721 } else {
722 sta = sta_info_get(local, param->sta_addr);
723 if (sta == NULL) {
724 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
725 return -EINVAL;
726 }
727
728 key = &sta->key;
729 }
730
731
732 memset(param->u.crypt.seq_counter, 0, HOSTAP_SEQ_COUNTER_SIZE);
733 if (*key == NULL) {
734 memcpy(param->u.crypt.alg, "none", 5);
735 param->u.crypt.key_len = 0;
736 param->u.crypt.idx = 0xff;
737 } else {
738 switch ((*key)->alg) {
739 case ALG_WEP:
740 memcpy(param->u.crypt.alg, "WEP", 4);
741 break;
742 case ALG_TKIP:
743 {
744 u32 iv32;
745 u16 iv16;
746
747 memcpy(param->u.crypt.alg, "TKIP", 5);
748 if (local->hw->get_sequence_counter) {
749 /* Get transmit counter from low level driver */
750 if (local->hw->get_sequence_counter(dev,
751 param->sta_addr,
752 (*key)->keyidx,
753 IEEE80211_SEQ_COUNTER_TX,
754 &iv32,
755 &iv16)) {
756 /* Error getting value from device */
757 return -EIO;
758 }
759 } else {
760 /* Get it from our own local data */
761 iv32 = (*key)->u.tkip.iv32;
762 iv16 = (*key)->u.tkip.iv16;
763 }
764 pos = param->u.crypt.seq_counter;
765 *pos++ = iv16 & 0xff;
766 *pos++ = (iv16 >> 8) & 0xff;
767 *pos++ = iv32 & 0xff;
768 *pos++ = (iv32 >> 8) & 0xff;
769 *pos++ = (iv32 >> 16) & 0xff;
770 *pos++ = (iv32 >> 24) & 0xff;
771 break;
772 }
773 case ALG_CCMP:
774 {
775 u8 *pn;
776 memcpy(param->u.crypt.alg, "CCMP", 5);
777 pos = param->u.crypt.seq_counter;
778 pn = (*key)->u.ccmp.tx_pn;
779 *pos++ = pn[5];
780 *pos++ = pn[4];
781 *pos++ = pn[3];
782 *pos++ = pn[2];
783 *pos++ = pn[1];
784 *pos++ = pn[0];
785 break;
786 }
787 default:
788 memcpy(param->u.crypt.alg, "unknown", 8);
789 break;
790 }
791
792 if (max_key_len < (*key)->keylen)
793 ret = -E2BIG;
794 else {
795 param->u.crypt.key_len = (*key)->keylen;
796 memcpy(param->u.crypt.key, (*key)->key,
797 (*key)->keylen);
798 }
799 }
800
801 if (sta)
802 sta_info_release(local, sta);
803
804 return ret;
805 }
806
807
808 #ifdef CONFIG_HOSTAPD_WPA_TESTING
809 static int ieee80211_ioctl_wpa_trigger(struct net_device *dev,
810 struct prism2_hostapd_param *param)
811 {
812 struct ieee80211_local *local = dev->priv;
813 struct sta_info *sta;
814
815 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
816 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
817 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
818 local->wpa_trigger = param->u.wpa_trigger.trigger;
819 return 0;
820 }
821
822 sta = sta_info_get(local, param->sta_addr);
823 if (sta == NULL) {
824 printk(KERN_DEBUG "%s: wpa_trigger - unknown addr\n",
825 dev->name);
826 return -EINVAL;
827 }
828
829 sta->wpa_trigger = param->u.wpa_trigger.trigger;
830
831 sta_info_release(local, sta);
832 return 0;
833 }
834 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
835
836
837 static int ieee80211_ioctl_set_rate_sets(struct net_device *dev,
838 struct prism2_hostapd_param *param,
839 int param_len)
840 {
841 struct ieee80211_local *local = dev->priv;
842 u16 *pos = (u16 *) param->u.set_rate_sets.data;
843 int left = param_len - ((u8 *) pos - (u8 *) param);
844 int i, mode, num_supp, num_basic, *supp, *basic, *prev;
845
846 mode = param->u.set_rate_sets.mode;
847 num_supp = param->u.set_rate_sets.num_supported_rates;
848 num_basic = param->u.set_rate_sets.num_basic_rates;
849
850 if (left < (num_supp + num_basic) * 2) {
851 printk(KERN_WARNING "%s: invalid length in hostapd set rate "
852 "sets ioctl (%d != %d)\n", dev->name, left,
853 (num_supp + num_basic) * 2);
854 return -EINVAL;
855 }
856
857 supp = (int *) kmalloc((num_supp + 1) * sizeof(int), GFP_KERNEL);
858 basic = (int *) kmalloc((num_basic + 1) * sizeof(int), GFP_KERNEL);
859
860 if (!supp || !basic) {
861 kfree(supp);
862 kfree(basic);
863 return -ENOMEM;
864 }
865
866 for (i = 0; i < num_supp; i++)
867 supp[i] = *pos++;
868 supp[i] = -1;
869
870 for (i = 0; i < num_basic; i++)
871 basic[i] = *pos++;
872 basic[i] = -1;
873
874 if (num_supp == 0) {
875 kfree(supp);
876 supp = NULL;
877 }
878
879 if (num_basic == 0) {
880 kfree(basic);
881 basic = NULL;
882 }
883
884 prev = local->supp_rates[mode];
885 local->supp_rates[mode] = supp;
886 kfree(prev);
887
888 prev = local->basic_rates[mode];
889 local->basic_rates[mode] = basic;
890 kfree(prev);
891
892 if (mode == local->conf.phymode) {
893 /* TODO: should update STA TX rates and remove STAs if they
894 * do not have any remaining supported rates after the change
895 */
896 ieee80211_prepare_rates(dev);
897 }
898
899 return 0;
900 }
901
902
903 static int ieee80211_ioctl_add_if(struct net_device *dev,
904 struct prism2_hostapd_param *param,
905 int param_len)
906 {
907 u8 *pos = param->u.if_info.data;
908 int left = param_len - ((u8 *) pos - (u8 *) param);
909
910 if (param->u.if_info.type == HOSTAP_IF_WDS) {
911 struct ieee80211_if_wds iwds;
912 struct hostapd_if_wds *wds =
913 (struct hostapd_if_wds *) param->u.if_info.data;
914
915 if (left < sizeof(struct ieee80211_if_wds))
916 return -EPROTO;
917
918 memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
919
920 return ieee80211_if_add_wds(dev, param->u.if_info.name,
921 &iwds, 1);
922 } else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
923 struct hostapd_if_vlan *vlan = (struct hostapd_if_vlan *) pos;
924 struct ieee80211_if_vlan ivlan;
925
926 if (left < sizeof(struct hostapd_if_vlan))
927 return -EPROTO;
928
929 ivlan.id = vlan->id;
930
931 return ieee80211_if_add_vlan(dev, param->u.if_info.name,
932 &ivlan, 1);
933 } else if (param->u.if_info.type == HOSTAP_IF_BSS) {
934 struct hostapd_if_bss *bss =
935 (struct hostapd_if_bss *) param->u.if_info.data;
936
937 if (left < sizeof(struct hostapd_if_bss))
938 return -EPROTO;
939
940 return ieee80211_if_add_norm(dev, param->u.if_info.name,
941 bss->bssid, 1);
942 } else if (param->u.if_info.type == HOSTAP_IF_STA) {
943 #if 0
944 struct hostapd_if_sta *sta =
945 (struct hostapd_if_sta *) param->u.if_info.data;
946 #endif
947
948 if (left < sizeof(struct hostapd_if_sta))
949 return -EPROTO;
950
951 return ieee80211_if_add_sta(dev, param->u.if_info.name, 1);
952 } else
953 return -EINVAL;
954
955 return 0;
956 }
957
958
959 static int ieee80211_ioctl_remove_if(struct net_device *dev,
960 struct prism2_hostapd_param *param)
961 {
962 if (param->u.if_info.type == HOSTAP_IF_WDS) {
963 return ieee80211_if_remove_wds(dev, param->u.if_info.name, 1);
964 } else if (param->u.if_info.type == HOSTAP_IF_VLAN) {
965 return ieee80211_if_remove_vlan(dev, param->u.if_info.name, 1);
966 } else if (param->u.if_info.type == HOSTAP_IF_BSS) {
967 return ieee80211_if_remove_norm(dev, param->u.if_info.name, 1);
968 } else if (param->u.if_info.type == HOSTAP_IF_STA) {
969 return ieee80211_if_remove_sta(dev, param->u.if_info.name, 1);
970 } else {
971 return -EINVAL;
972 }
973 }
974
975
976 static int ieee80211_ioctl_update_if(struct net_device *dev,
977 struct prism2_hostapd_param *param,
978 int param_len)
979 {
980 u8 *pos = param->u.if_info.data;
981 int left = param_len - ((u8 *) pos - (u8 *) param);
982
983 if (param->u.if_info.type == HOSTAP_IF_WDS) {
984 struct ieee80211_if_wds iwds;
985 struct hostapd_if_wds *wds =
986 (struct hostapd_if_wds *) param->u.if_info.data;
987
988 if (left < sizeof(struct ieee80211_if_wds))
989 return -EPROTO;
990
991 memcpy(iwds.remote_addr, wds->remote_addr, ETH_ALEN);
992
993 return ieee80211_if_update_wds(dev, param->u.if_info.name,
994 &iwds, 1);
995 } else {
996 return -EOPNOTSUPP;
997 }
998 }
999
1000
1001 static int ieee80211_ioctl_flush_ifs(struct net_device *dev,
1002 struct prism2_hostapd_param *param)
1003 {
1004 return ieee80211_if_flush(dev, 1);
1005 }
1006
1007
1008 static int ieee80211_ioctl_scan_req(struct net_device *dev,
1009 struct prism2_hostapd_param *param,
1010 int param_len)
1011 {
1012 u8 *pos = param->u.scan_req.ssid;
1013 int left = param_len - ((u8 *) pos - (u8 *) param);
1014 int len = param->u.scan_req.ssid_len;
1015
1016 if (left < len || len > IEEE80211_MAX_SSID_LEN)
1017 return -EINVAL;
1018
1019 return ieee80211_sta_req_scan(dev, pos, len);
1020 }
1021
1022
1023 static int ieee80211_ioctl_sta_get_state(struct net_device *dev,
1024 struct prism2_hostapd_param *param)
1025 {
1026 struct ieee80211_sub_if_data *sdata;
1027
1028 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1029 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
1030 return -EINVAL;
1031 param->u.sta_get_state.state = sdata->u.sta.state;
1032 return 0;
1033 }
1034
1035
1036 static int ieee80211_ioctl_mlme(struct net_device *dev,
1037 struct prism2_hostapd_param *param)
1038 {
1039 struct ieee80211_sub_if_data *sdata;
1040
1041 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1042 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
1043 return -EINVAL;
1044 switch (param->u.mlme.cmd) {
1045 case MLME_STA_DEAUTH:
1046 ieee80211_sta_deauthenticate(dev, param->u.mlme.reason_code);
1047 break;
1048 case MLME_STA_DISASSOC:
1049 ieee80211_sta_disassociate(dev, param->u.mlme.reason_code);
1050 break;
1051 }
1052 return 0;
1053 }
1054
1055
1056 static int ieee80211_ioctl_get_load_stats(struct net_device *dev,
1057 struct prism2_hostapd_param *param)
1058 {
1059 struct ieee80211_local *local = dev->priv;
1060
1061 param->u.get_load_stats.channel_use = local->channel_use;
1062 /* if (param->u.get_load_stats.flags & LOAD_STATS_CLEAR)
1063 local->channel_use = 0; */ /* now it's not raw counter */
1064
1065 return 0;
1066 }
1067
1068
1069 static int ieee80211_ioctl_set_sta_vlan(struct net_device *dev,
1070 struct prism2_hostapd_param *param)
1071 {
1072 struct ieee80211_local *local = dev->priv;
1073 struct sta_info *sta;
1074
1075 sta = sta_info_get(local, param->sta_addr);
1076 if (sta) {
1077 struct net_device *new_vlan_dev;
1078 new_vlan_dev =
1079 dev_get_by_name(param->u.set_sta_vlan.vlan_name);
1080 if (new_vlan_dev) {
1081 #if 0
1082 printk("%s: Station " MACSTR " moved to vlan: %s\n",
1083 dev->name, MAC2STR(param->sta_addr),
1084 new_vlan_dev->name);
1085 #endif
1086 sta->dev = new_vlan_dev;
1087 sta->vlan_id = param->u.set_sta_vlan.vlan_id;
1088 dev_put(new_vlan_dev);
1089 }
1090 sta_info_release(local, sta);
1091 }
1092
1093 return sta ? 0 : -ENOENT;
1094 }
1095
1096
1097 static int
1098 ieee80211_ioctl_set_generic_info_elem(struct net_device *dev,
1099 struct prism2_hostapd_param *param,
1100 int param_len)
1101 {
1102 struct ieee80211_local *local = dev->priv;
1103 u8 *pos = param->u.set_generic_info_elem.data;
1104 int left = param_len - ((u8 *) pos - (u8 *) param);
1105 int len = param->u.set_generic_info_elem.len;
1106
1107 if (left < len)
1108 return -EINVAL;
1109
1110 {
1111 struct ieee80211_sub_if_data *sdata;
1112 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1113 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
1114 return ieee80211_sta_set_extra_ie(dev, pos, len);
1115 }
1116 kfree(local->conf.generic_elem);
1117 local->conf.generic_elem = kmalloc(len, GFP_KERNEL);
1118 if (local->conf.generic_elem == NULL)
1119 return -ENOMEM;
1120 memcpy(local->conf.generic_elem, pos, len);
1121 local->conf.generic_elem_len = len;
1122
1123 return ieee80211_hw_config(dev);
1124 }
1125
1126
1127 static int ieee80211_ioctl_set_regulatory_domain(struct net_device *dev,
1128 struct prism2_hostapd_param *param)
1129 {
1130 struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
1131 conf->regulatory_domain = param->u.set_regulatory_domain.rd;
1132 return 0;
1133 }
1134
1135
1136 static int ieee80211_ioctl_set_adm_status(struct net_device *dev,
1137 int val)
1138 {
1139 struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
1140 conf->adm_status = val;
1141 return ieee80211_hw_config(dev);
1142 }
1143
1144 static int
1145 ieee80211_ioctl_set_tx_queue_params(struct net_device *dev,
1146 struct prism2_hostapd_param *param)
1147 {
1148 struct ieee80211_local *local = dev->priv;
1149 struct ieee80211_tx_queue_params qparam;
1150
1151 if (!local->hw->conf_tx) {
1152 printk(KERN_DEBUG "%s: low-level driver does not support TX "
1153 "queue configuration\n", dev->name);
1154 return -EOPNOTSUPP;
1155 }
1156
1157 memset(&qparam, 0, sizeof(qparam));
1158 qparam.aifs = param->u.tx_queue_params.aifs;
1159 qparam.cw_min = param->u.tx_queue_params.cw_min;
1160 qparam.cw_max = param->u.tx_queue_params.cw_max;
1161 qparam.burst_time = param->u.tx_queue_params.burst_time;
1162
1163 return local->hw->conf_tx(dev, param->u.tx_queue_params.queue,
1164 &qparam);
1165 }
1166
1167
1168 static int ieee80211_ioctl_get_tx_stats(struct net_device *dev,
1169 struct prism2_hostapd_param *param)
1170 {
1171 struct ieee80211_local *local = dev->priv;
1172 struct ieee80211_tx_queue_stats stats;
1173 int ret, i;
1174
1175 if (!local->hw->get_tx_stats)
1176 return -EOPNOTSUPP;
1177
1178 memset(&stats, 0, sizeof(stats));
1179 ret = local->hw->get_tx_stats(dev, &stats);
1180 if (ret)
1181 return ret;
1182
1183 for (i = 0; i < 4; i++) {
1184 param->u.get_tx_stats.data[i].len = stats.data[i].len;
1185 param->u.get_tx_stats.data[i].limit = stats.data[i].limit;
1186 param->u.get_tx_stats.data[i].count = stats.data[i].count;
1187 }
1188
1189 return 0;
1190 }
1191
1192
1193 static int ieee80211_ioctl_set_bss(struct net_device *dev,
1194 struct prism2_hostapd_param *param)
1195 {
1196 struct ieee80211_local *local = dev->priv;
1197 struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
1198 int i, bss_count;
1199 int new_count = param->u.set_bss.bss_count;
1200 struct net_device **bss_devs, **prev;
1201 struct net_device **sta_devs, **prev_sta_devs;
1202
1203 bss_count = 0;
1204 for (i = 0; i < conf->bss_count; i++) {
1205 if (local->bss_devs[i])
1206 bss_count++;
1207 }
1208
1209 if (new_count < bss_count) {
1210 printk(KERN_DEBUG "%s: invalid BSS count %d (in use: %d)\n",
1211 dev->name, new_count, bss_count);
1212 return -EINVAL;
1213 }
1214
1215 bss_devs = kmalloc(new_count * sizeof(struct net_device *),
1216 GFP_KERNEL);
1217 if (bss_devs == NULL)
1218 return -ENOMEM;
1219 sta_devs = kmalloc(new_count * sizeof(struct net_device *),
1220 GFP_KERNEL);
1221 if (sta_devs == NULL) {
1222 kfree(bss_devs);
1223 return -ENOMEM;
1224 }
1225
1226 spin_lock_bh(&local->sub_if_lock);
1227 memcpy(bss_devs, local->bss_devs,
1228 bss_count * sizeof(struct net_device *));
1229 memset(&bss_devs[bss_count], 0,
1230 (new_count - bss_count) * sizeof(struct net_device *));
1231
1232 memcpy(conf->bssid_mask, param->u.set_bss.bssid_mask, ETH_ALEN);
1233
1234 prev = local->bss_devs;
1235 local->bss_devs = bss_devs;
1236 conf->bss_count = new_count;
1237
1238 memcpy(sta_devs, local->sta_devs,
1239 bss_count * sizeof(struct net_device *));
1240 memset(&sta_devs[bss_count], 0,
1241 (new_count - bss_count) * sizeof(struct net_device *));
1242 prev_sta_devs = local->sta_devs;
1243 local->sta_devs = sta_devs;
1244
1245 spin_unlock_bh(&local->sub_if_lock);
1246 kfree(prev);
1247 kfree(prev_sta_devs);
1248
1249 return ieee80211_hw_config(dev);
1250 }
1251
1252
1253 static int ieee80211_ioctl_set_channel_flag(struct net_device *dev,
1254 struct prism2_hostapd_param *param)
1255 {
1256 struct ieee80211_local *local = dev->priv;
1257 struct ieee80211_hw_modes *mode = NULL;
1258 struct ieee80211_channel *chan = NULL;
1259 int i;
1260
1261 for (i = 0; i < local->hw->num_modes; i++) {
1262 mode = &local->hw->modes[i];
1263 if (mode->mode == param->u.set_channel_flag.mode)
1264 break;
1265 mode = NULL;
1266 }
1267
1268 if (!mode)
1269 return -ENOENT;
1270
1271 for (i = 0; i < mode->num_channels; i++) {
1272 chan = &mode->channels[i];
1273 if (chan->chan == param->u.set_channel_flag.chan)
1274 break;
1275 chan = NULL;
1276 }
1277
1278 if (!chan)
1279 return -ENOENT;
1280
1281 chan->flag = param->u.set_channel_flag.flag;
1282 chan->power_level = param->u.set_channel_flag.power_level;
1283 chan->antenna_max = param->u.set_channel_flag.antenna_max;
1284
1285 return 0;
1286 }
1287
1288
1289 static int ieee80211_ioctl_set_quiet_params(struct net_device *dev,
1290 struct prism2_hostapd_param *param)
1291 {
1292 struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev);
1293 conf->quiet_duration = param->u.quiet.duration;
1294 conf->quiet_offset = param->u.quiet.offset;
1295 conf->quiet_period = param->u.quiet.period;
1296 return 0;
1297 }
1298
1299
1300 static int ieee80211_ioctl_set_radar_params(struct net_device *dev,
1301 struct prism2_hostapd_param *param)
1302 {
1303 /* struct ieee80211_conf *conf = ieee80211_get_hw_conf(dev); */
1304 return 0;
1305 }
1306
1307
1308 static int ieee80211_ioctl_priv_hostapd(struct net_device *dev,
1309 struct iw_point *p)
1310 {
1311 struct prism2_hostapd_param *param;
1312 int ret = 0;
1313
1314 if (p->length < sizeof(struct prism2_hostapd_param) ||
1315 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer) {
1316 printk(KERN_DEBUG "%s: hostapd ioctl: ptr=%p len=%d min=%d "
1317 "max=%d\n", dev->name, p->pointer, p->length,
1318 (int)sizeof(struct prism2_hostapd_param),
1319 PRISM2_HOSTAPD_MAX_BUF_SIZE);
1320 return -EINVAL;
1321 }
1322
1323 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
1324 if (param == NULL)
1325 return -ENOMEM;
1326
1327 if (copy_from_user(param, p->pointer, p->length)) {
1328 ret = -EFAULT;
1329 goto out;
1330 }
1331
1332 switch (param->cmd) {
1333 case PRISM2_HOSTAPD_FLUSH:
1334 ret = ieee80211_ioctl_flush(dev, param);
1335 break;
1336 case PRISM2_HOSTAPD_ADD_STA:
1337 ret = ieee80211_ioctl_add_sta(dev, param);
1338 break;
1339 case PRISM2_HOSTAPD_REMOVE_STA:
1340 ret = ieee80211_ioctl_remove_sta(dev, param);
1341 break;
1342 case PRISM2_HOSTAPD_GET_INFO_STA:
1343 ret = ieee80211_ioctl_get_info_sta(dev, param);
1344 break;
1345 case PRISM2_SET_ENCRYPTION:
1346 ret = ieee80211_ioctl_set_encryption(dev, param, p->length);
1347 break;
1348 case PRISM2_GET_ENCRYPTION:
1349 ret = ieee80211_ioctl_get_encryption(dev, param, p->length);
1350 break;
1351 case PRISM2_HOSTAPD_SET_FLAGS_STA:
1352 ret = ieee80211_ioctl_set_flags_sta(dev, param);
1353 break;
1354 case PRISM2_HOSTAPD_SET_BEACON:
1355 ret = ieee80211_ioctl_set_beacon(dev, param, p->length, 0);
1356 break;
1357 case PRISM2_HOSTAPD_GET_HW_FEATURES:
1358 ret = ieee80211_ioctl_get_hw_features(dev, param, p->length);
1359 break;
1360 case PRISM2_HOSTAPD_SCAN:
1361 ret = ieee80211_ioctl_scan(dev, param);
1362 break;
1363 #ifdef CONFIG_HOSTAPD_WPA_TESTING
1364 case PRISM2_HOSTAPD_WPA_TRIGGER:
1365 ret = ieee80211_ioctl_wpa_trigger(dev, param);
1366 break;
1367 #endif /* CONFIG_HOSTAPD_WPA_TESTING */
1368 case PRISM2_HOSTAPD_SET_RATE_SETS:
1369 ret = ieee80211_ioctl_set_rate_sets(dev, param, p->length);
1370 break;
1371 case PRISM2_HOSTAPD_ADD_IF:
1372 ret = ieee80211_ioctl_add_if(dev, param, p->length);
1373 break;
1374 case PRISM2_HOSTAPD_REMOVE_IF:
1375 ret = ieee80211_ioctl_remove_if(dev, param);
1376 break;
1377 case PRISM2_HOSTAPD_GET_DOT11COUNTERSTABLE:
1378 ret = ieee80211_ioctl_get_dot11counterstable(dev, param);
1379 break;
1380 case PRISM2_HOSTAPD_GET_LOAD_STATS:
1381 ret = ieee80211_ioctl_get_load_stats(dev, param);
1382 break;
1383 case PRISM2_HOSTAPD_SET_STA_VLAN:
1384 ret = ieee80211_ioctl_set_sta_vlan(dev, param);
1385 break;
1386 case PRISM2_HOSTAPD_SET_GENERIC_INFO_ELEM:
1387 ret = ieee80211_ioctl_set_generic_info_elem(dev, param,
1388 p->length);
1389 break;
1390 case PRISM2_HOSTAPD_SET_CHANNEL_FLAG:
1391 ret = ieee80211_ioctl_set_channel_flag(dev, param);
1392 break;
1393 case PRISM2_HOSTAPD_SET_REGULATORY_DOMAIN:
1394 ret = ieee80211_ioctl_set_regulatory_domain(dev, param);
1395 break;
1396 case PRISM2_HOSTAPD_SET_TX_QUEUE_PARAMS:
1397 ret = ieee80211_ioctl_set_tx_queue_params(dev, param);
1398 break;
1399 case PRISM2_HOSTAPD_SET_BSS:
1400 ret = ieee80211_ioctl_set_bss(dev, param);
1401 break;
1402 case PRISM2_HOSTAPD_GET_TX_STATS:
1403 ret = ieee80211_ioctl_get_tx_stats(dev, param);
1404 break;
1405 case PRISM2_HOSTAPD_UPDATE_IF:
1406 ret = ieee80211_ioctl_update_if(dev, param, p->length);
1407 break;
1408 case PRISM2_HOSTAPD_SCAN_REQ:
1409 ret = ieee80211_ioctl_scan_req(dev, param, p->length);
1410 break;
1411 case PRISM2_STA_GET_STATE:
1412 ret = ieee80211_ioctl_sta_get_state(dev, param);
1413 break;
1414 case PRISM2_HOSTAPD_MLME:
1415 ret = ieee80211_ioctl_mlme(dev, param);
1416 break;
1417 case PRISM2_HOSTAPD_FLUSH_IFS:
1418 ret = ieee80211_ioctl_flush_ifs(dev, param);
1419 break;
1420 case PRISM2_HOSTAPD_SET_RADAR_PARAMS:
1421 ret = ieee80211_ioctl_set_radar_params(dev, param);
1422 break;
1423 case PRISM2_HOSTAPD_SET_QUIET_PARAMS:
1424 ret = ieee80211_ioctl_set_quiet_params(dev, param);
1425 break;
1426 default:
1427 ret = -EOPNOTSUPP;
1428 break;
1429 }
1430
1431 if (copy_to_user(p->pointer, param, p->length))
1432 ret = -EFAULT;
1433
1434 out:
1435 kfree(param);
1436
1437 return ret;
1438 }
1439
1440
1441 static int ieee80211_ioctl_giwname(struct net_device *dev,
1442 struct iw_request_info *info,
1443 char *name, char *extra)
1444 {
1445 struct ieee80211_local *local = dev->priv;
1446
1447 switch (local->conf.phymode) {
1448 case MODE_IEEE80211A:
1449 strcpy(name, "IEEE 802.11a");
1450 break;
1451 case MODE_IEEE80211B:
1452 strcpy(name, "IEEE 802.11b");
1453 break;
1454 case MODE_IEEE80211G:
1455 strcpy(name, "IEEE 802.11g");
1456 break;
1457 case MODE_ATHEROS_TURBO:
1458 strcpy(name, "5GHz Turbo");
1459 break;
1460 default:
1461 strcpy(name, "IEEE 802.11");
1462 break;
1463 }
1464
1465 return 0;
1466 }
1467
1468
1469 static int ieee80211_ioctl_giwrange(struct net_device *dev,
1470 struct iw_request_info *info,
1471 struct iw_point *data, char *extra)
1472 {
1473 struct iw_range *range = (struct iw_range *) extra;
1474
1475 data->length = sizeof(struct iw_range);
1476 memset(range, 0, sizeof(struct iw_range));
1477
1478 range->we_version_compiled = WIRELESS_EXT;
1479 range->we_version_source = 14;
1480 range->retry_capa = IW_RETRY_LIMIT;
1481 range->retry_flags = IW_RETRY_LIMIT;
1482 range->min_retry = 0;
1483 range->max_retry = 255;
1484 range->min_rts = 0;
1485 range->max_rts = 2347;
1486 range->min_frag = 256;
1487 range->max_frag = 2346;
1488
1489 return 0;
1490 }
1491
1492
1493 struct ieee80211_channel_range {
1494 short start_freq;
1495 short end_freq;
1496 unsigned char power_level;
1497 unsigned char antenna_max;
1498 };
1499
1500 static const struct ieee80211_channel_range ieee80211_fcc_channels[] = {
1501 { 2412, 2462, 27, 6 } /* IEEE 802.11b/g, channels 1..11 */,
1502 { 5180, 5240, 17, 6 } /* IEEE 802.11a, channels 36..48 */,
1503 { 5260, 5320, 23, 6 } /* IEEE 802.11a, channels 52..64 */,
1504 { 5745, 5825, 30, 6 } /* IEEE 802.11a, channels 149..165, outdoor */,
1505 { 0 }
1506 };
1507
1508 static const struct ieee80211_channel_range ieee80211_mkk_channels[] = {
1509 { 2412, 2472, 20, 6 } /* IEEE 802.11b/g, channels 1..13 */,
1510 { 5170, 5240, 20, 6 } /* IEEE 802.11a, channels 34..48 */,
1511 { 5260, 5320, 20, 6 } /* IEEE 802.11a, channels 52..64 */,
1512 { 0 }
1513 };
1514
1515
1516 static const struct ieee80211_channel_range *channel_range =
1517 ieee80211_fcc_channels;
1518
1519
1520 static void ieee80211_unmask_channel(struct net_device *dev, int mode,
1521 struct ieee80211_channel *chan)
1522 {
1523 int i;
1524
1525 chan->flag = 0;
1526
1527 if (ieee80211_regdom == 64 &&
1528 (mode == MODE_ATHEROS_TURBO || mode == MODE_ATHEROS_TURBOG)) {
1529 /* Do not allow Turbo modes in Japan. */
1530 return;
1531 }
1532
1533 for (i = 0; channel_range[i].start_freq; i++) {
1534 const struct ieee80211_channel_range *r = &channel_range[i];
1535 if (r->start_freq <= chan->freq && r->end_freq >= chan->freq) {
1536 if (ieee80211_regdom == 64 && !ieee80211_japan_5ghz &&
1537 chan->freq >= 5260 && chan->freq <= 5320) {
1538 /*
1539 * Skip new channels in Japan since the
1540 * firmware was not marked having been upgraded
1541 * by the vendor.
1542 */
1543 continue;
1544 }
1545
1546 if (ieee80211_regdom == 0x10 &&
1547 (chan->freq == 5190 || chan->freq == 5210 ||
1548 chan->freq == 5230)) {
1549 /* Skip MKK channels when in FCC domain. */
1550 continue;
1551 }
1552
1553 chan->flag |= IEEE80211_CHAN_W_SCAN |
1554 IEEE80211_CHAN_W_ACTIVE_SCAN |
1555 IEEE80211_CHAN_W_IBSS;
1556 chan->power_level = r->power_level;
1557 chan->antenna_max = r->antenna_max;
1558
1559 if (ieee80211_regdom == 64 &&
1560 (chan->freq == 5170 || chan->freq == 5190 ||
1561 chan->freq == 5210 || chan->freq == 5230)) {
1562 /*
1563 * New regulatory rules in Japan have backwards
1564 * compatibility with old channels in 5.15-5.25
1565 * GHz band, but the station is not allowed to
1566 * use active scan on these old channels.
1567 */
1568 chan->flag &= ~IEEE80211_CHAN_W_ACTIVE_SCAN;
1569 }
1570
1571 if (ieee80211_regdom == 64 &&
1572 (chan->freq == 5260 || chan->freq == 5280 ||
1573 chan->freq == 5300 || chan->freq == 5320)) {
1574 /*
1575 * IBSS is not allowed on 5.25-5.35 GHz band
1576 * due to radar detection requirements.
1577 */
1578 chan->flag &= ~IEEE80211_CHAN_W_IBSS;
1579 }
1580
1581 break;
1582 }
1583 }
1584 }
1585
1586
1587 static int ieee80211_unmask_channels(struct net_device *dev)
1588 {
1589 struct ieee80211_local *local = dev->priv;
1590 int m, c;
1591
1592 for (m = 0; m < local->hw->num_modes; m++) {
1593 struct ieee80211_hw_modes *mode = &local->hw->modes[m];
1594 for (c = 0; c < mode->num_channels; c++) {
1595 ieee80211_unmask_channel(dev, mode->mode,
1596 &mode->channels[c]);
1597 }
1598 }
1599 return 0;
1600 }
1601
1602
1603 static int ieee80211_init_client(struct net_device *dev)
1604 {
1605 if (ieee80211_regdom == 0x40)
1606 channel_range = ieee80211_mkk_channels;
1607 ieee80211_unmask_channels(dev);
1608 ieee80211_ioctl_set_adm_status(dev, 1);
1609 return 0;
1610 }
1611
1612
1613 static int ieee80211_is_client_mode(int iw_mode)
1614 {
1615 return (iw_mode == IW_MODE_INFRA || iw_mode == IW_MODE_ADHOC);
1616 }
1617
1618
1619 static int ieee80211_ioctl_siwmode(struct net_device *dev,
1620 struct iw_request_info *info,
1621 __u32 *mode, char *extra)
1622 {
1623 struct ieee80211_local *local = dev->priv;
1624
1625 if (!ieee80211_is_client_mode(local->conf.mode) &&
1626 ieee80211_is_client_mode(*mode)) {
1627 ieee80211_init_client(dev);
1628 }
1629 if (local->conf.mode != *mode) {
1630 struct ieee80211_sub_if_data *sdata =
1631 IEEE80211_DEV_TO_SUB_IF(dev);
1632 sta_info_flush(local, NULL);
1633 if (local->conf.mode == IW_MODE_ADHOC &&
1634 sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
1635 /* Clear drop_unencrypted when leaving adhoc mode since
1636 * only adhoc mode is using automatic setting for this
1637 * in 80211.o. */
1638 sdata->drop_unencrypted = 0;
1639 }
1640 if (*mode == IW_MODE_MASTER) {
1641 /* AP mode does not currently use ACM bits to limit
1642 * TX, so clear the bitfield here. */
1643 local->wmm_acm = 0;
1644 }
1645 }
1646 local->conf.mode = *mode;
1647 return ieee80211_hw_config(dev);
1648 }
1649
1650
1651 static int ieee80211_ioctl_giwmode(struct net_device *dev,
1652 struct iw_request_info *info,
1653 __u32 *mode, char *extra)
1654 {
1655 struct ieee80211_local *local = dev->priv;
1656 struct ieee80211_sub_if_data *sdata;
1657
1658 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1659 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
1660 if (local->conf.mode == IW_MODE_ADHOC)
1661 *mode = IW_MODE_ADHOC;
1662 else
1663 *mode = IW_MODE_INFRA;
1664 } else
1665 *mode = local->conf.mode;
1666 return 0;
1667 }
1668
1669
1670 int ieee80211_ioctl_siwfreq(struct net_device *dev,
1671 struct iw_request_info *info,
1672 struct iw_freq *freq, char *extra)
1673 {
1674 struct ieee80211_local *local = dev->priv;
1675 int m, c, nfreq, set = 0;
1676
1677 /* freq->e == 0: freq->m = channel; otherwise freq = m * 10^e */
1678 if (freq->e == 0)
1679 nfreq = -1;
1680 else {
1681 int i, div = 1000000;
1682 for (i = 0; i < freq->e; i++)
1683 div /= 10;
1684 if (div > 0)
1685 nfreq = freq->m / div;
1686 else
1687 return -EINVAL;
1688 }
1689
1690 for (m = 0; m < local->hw->num_modes; m++) {
1691 struct ieee80211_hw_modes *mode = &local->hw->modes[m];
1692 for (c = 0; c < mode->num_channels; c++) {
1693 struct ieee80211_channel *chan = &mode->channels[c];
1694 if (chan->flag & IEEE80211_CHAN_W_SCAN &&
1695 ((freq->e == 0 && chan->chan == freq->m) ||
1696 (freq->e > 0 && nfreq == chan->freq)) &&
1697 (local->hw_modes & (1 << mode->mode))) {
1698 /* Use next_mode as the mode preference to
1699 * resolve non-unique channel numbers. */
1700 if (set && mode->mode != local->next_mode)
1701 continue;
1702
1703 local->conf.channel = chan->chan;
1704 local->conf.channel_val = chan->val;
1705 local->conf.power_level = chan->power_level;
1706 local->conf.freq = chan->freq;
1707 local->conf.phymode = mode->mode;
1708 local->conf.antenna_max = chan->antenna_max;
1709 set++;
1710 }
1711 }
1712 }
1713
1714 if (set) {
1715 local->sta_scanning = 0; /* Abort possible scan */
1716 return ieee80211_hw_config(dev);
1717 }
1718
1719 return -EINVAL;
1720 }
1721
1722
1723 static int ieee80211_ioctl_giwfreq(struct net_device *dev,
1724 struct iw_request_info *info,
1725 struct iw_freq *freq, char *extra)
1726 {
1727 struct ieee80211_local *local = dev->priv;
1728
1729 /* TODO: in station mode (Managed/Ad-hoc) might need to poll low-level
1730 * driver for the current channel with firmware-based management */
1731
1732 freq->m = local->conf.freq;
1733 freq->e = 6;
1734
1735 return 0;
1736 }
1737
1738
1739 static int ieee80211_ioctl_siwessid(struct net_device *dev,
1740 struct iw_request_info *info,
1741 struct iw_point *data, char *ssid)
1742 {
1743 struct ieee80211_local *local = dev->priv;
1744 struct ieee80211_sub_if_data *sdata;
1745 size_t len = data->length;
1746
1747 /* iwconfig uses nul termination in SSID.. */
1748 if (len > 0 && ssid[len - 1] == '\0')
1749 len--;
1750
1751 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1752 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA)
1753 return ieee80211_sta_set_ssid(dev, ssid, len);
1754
1755 kfree(local->conf.ssid);
1756 local->conf.ssid = kmalloc(len + 1, GFP_KERNEL);
1757 if (local->conf.ssid == NULL)
1758 return -ENOMEM;
1759 memcpy(local->conf.ssid, ssid, len);
1760 local->conf.ssid[len] = '\0';
1761 local->conf.ssid_len = len;
1762 return ieee80211_hw_config(dev);
1763 }
1764
1765
1766 static int ieee80211_ioctl_giwessid(struct net_device *dev,
1767 struct iw_request_info *info,
1768 struct iw_point *data, char *ssid)
1769 {
1770 struct ieee80211_local *local = dev->priv;
1771 size_t len;
1772
1773 struct ieee80211_sub_if_data *sdata;
1774 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1775 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
1776 int res = ieee80211_sta_get_ssid(dev, ssid, &len);
1777 if (res == 0)
1778 data->length = len;
1779 return res;
1780 }
1781
1782 len = local->conf.ssid_len;
1783 if (len > IW_ESSID_MAX_SIZE)
1784 len = IW_ESSID_MAX_SIZE;
1785 memcpy(ssid, local->conf.ssid, len);
1786 data->length = len;
1787 return 0;
1788 }
1789
1790
1791 static int ieee80211_ioctl_siwap(struct net_device *dev,
1792 struct iw_request_info *info,
1793 struct sockaddr *ap_addr, char *extra)
1794 {
1795 struct ieee80211_local *local = dev->priv;
1796 struct ieee80211_sub_if_data *sdata;
1797
1798 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1799 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
1800 int changed_bssid = 0;
1801 if (memcmp(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
1802 ETH_ALEN) != 0)
1803 changed_bssid = 1;
1804 memcpy(local->conf.client_bssid, (u8 *) &ap_addr->sa_data,
1805 ETH_ALEN);
1806 if (changed_bssid && ieee80211_hw_config(dev)) {
1807 printk(KERN_DEBUG "%s: Failed to config new BSSID to "
1808 "the low-level driver\n", dev->name);
1809 }
1810 return ieee80211_sta_set_bssid(dev, (u8 *) &ap_addr->sa_data);
1811 }
1812
1813 return -EOPNOTSUPP;
1814 }
1815
1816
1817 static int ieee80211_ioctl_giwap(struct net_device *dev,
1818 struct iw_request_info *info,
1819 struct sockaddr *ap_addr, char *extra)
1820 {
1821 struct ieee80211_sub_if_data *sdata;
1822
1823 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
1824 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
1825 ap_addr->sa_family = ARPHRD_ETHER;
1826 memcpy(&ap_addr->sa_data, sdata->u.sta.bssid, ETH_ALEN);
1827 return 0;
1828 }
1829
1830 return -EOPNOTSUPP;
1831 }
1832
1833
1834 static int ieee80211_ioctl_siwscan(struct net_device *dev,
1835 struct iw_request_info *info,
1836 struct iw_point *data, char *extra)
1837 {
1838 struct ieee80211_local *local = dev->priv;
1839 u8 *ssid = NULL;
1840 size_t ssid_len = 0;
1841
1842 if (local->scan_flags & IEEE80211_SCAN_MATCH_SSID) {
1843 ssid = local->conf.ssid;
1844 ssid_len = local->conf.ssid_len;
1845 }
1846 return ieee80211_sta_req_scan(dev, ssid, ssid_len);
1847 }
1848
1849
1850 static int ieee80211_ioctl_giwscan(struct net_device *dev,
1851 struct iw_request_info *info,
1852 struct iw_point *data, char *extra)
1853 {
1854 int res;
1855 struct ieee80211_local *local = dev->priv;
1856 if (local->sta_scanning)
1857 return -EAGAIN;
1858 res = ieee80211_sta_scan_results(dev, extra, IW_SCAN_MAX_DATA);
1859 if (res >= 0) {
1860 data->length = res;
1861 return 0;
1862 }
1863 data->length = 0;
1864 return res;
1865 }
1866
1867
1868 static int ieee80211_ioctl_siwrts(struct net_device *dev,
1869 struct iw_request_info *info,
1870 struct iw_param *rts, char *extra)
1871 {
1872 struct ieee80211_local *local = dev->priv;
1873
1874 if (rts->disabled)
1875 local->rts_threshold = IEEE80211_MAX_RTS_THRESHOLD;
1876 else if (rts->value < 0 || rts->value > IEEE80211_MAX_RTS_THRESHOLD)
1877 return -EINVAL;
1878 else
1879 local->rts_threshold = rts->value;
1880
1881 /* If the wlan card performs RTS/CTS in hardware/firmware,
1882 * configure it here */
1883
1884 if (local->hw->set_rts_threshold) {
1885 local->hw->set_rts_threshold(dev, local->rts_threshold);
1886 }
1887
1888 return 0;
1889 }
1890
1891 static int ieee80211_ioctl_giwrts(struct net_device *dev,
1892 struct iw_request_info *info,
1893 struct iw_param *rts, char *extra)
1894 {
1895 struct ieee80211_local *local = dev->priv;
1896
1897 rts->value = local->rts_threshold;
1898 rts->disabled = (rts->value >= IEEE80211_MAX_RTS_THRESHOLD);
1899 rts->fixed = 1;
1900
1901 return 0;
1902 }
1903
1904
1905 static int ieee80211_ioctl_siwfrag(struct net_device *dev,
1906 struct iw_request_info *info,
1907 struct iw_param *frag, char *extra)
1908 {
1909 struct ieee80211_local *local = dev->priv;
1910
1911 if (frag->disabled)
1912 local->fragmentation_threshold = IEEE80211_MAX_FRAG_THRESHOLD;
1913 else if (frag->value < 256 ||
1914 frag->value > IEEE80211_MAX_FRAG_THRESHOLD)
1915 return -EINVAL;
1916 else {
1917 /* Fragment length must be even, so strip LSB. */
1918 local->fragmentation_threshold = frag->value & ~0x1;
1919 }
1920
1921 /* If the wlan card performs fragmentation in hardware/firmware,
1922 * configure it here */
1923
1924 if (local->hw->set_frag_threshold) {
1925 local->hw->set_frag_threshold(
1926 dev, local->fragmentation_threshold);
1927 }
1928
1929 return 0;
1930 }
1931
1932 static int ieee80211_ioctl_giwfrag(struct net_device *dev,
1933 struct iw_request_info *info,
1934 struct iw_param *frag, char *extra)
1935 {
1936 struct ieee80211_local *local = dev->priv;
1937
1938 frag->value = local->fragmentation_threshold;
1939 frag->disabled = (frag->value >= IEEE80211_MAX_RTS_THRESHOLD);
1940 frag->fixed = 1;
1941
1942 return 0;
1943 }
1944
1945
1946 static int ieee80211_ioctl_siwretry(struct net_device *dev,
1947 struct iw_request_info *info,
1948 struct iw_param *retry, char *extra)
1949 {
1950 struct ieee80211_local *local = dev->priv;
1951
1952 if (retry->disabled ||
1953 (retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
1954 return -EINVAL;
1955
1956 if (retry->flags & IW_RETRY_MAX)
1957 local->long_retry_limit = retry->value;
1958 else if (retry->flags & IW_RETRY_MIN)
1959 local->short_retry_limit = retry->value;
1960 else {
1961 local->long_retry_limit = retry->value;
1962 local->short_retry_limit = retry->value;
1963 }
1964
1965 if (local->hw->set_retry_limit) {
1966 return local->hw->set_retry_limit(
1967 dev, local->short_retry_limit,
1968 local->long_retry_limit);
1969 }
1970
1971 return 0;
1972 }
1973
1974
1975 static int ieee80211_ioctl_giwretry(struct net_device *dev,
1976 struct iw_request_info *info,
1977 struct iw_param *retry, char *extra)
1978 {
1979 struct ieee80211_local *local = dev->priv;
1980
1981 retry->disabled = 0;
1982 if ((retry->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
1983 return -EINVAL;
1984 if (retry->flags & IW_RETRY_MAX) {
1985 retry->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1986 retry->value = local->long_retry_limit;
1987 } else {
1988 retry->flags = IW_RETRY_LIMIT;
1989 retry->value = local->short_retry_limit;
1990 if (local->long_retry_limit != local->short_retry_limit)
1991 retry->flags |= IW_RETRY_MIN;
1992 }
1993
1994 return 0;
1995 }
1996
1997
1998 static void ieee80211_ioctl_unmask_channels(struct ieee80211_local *local)
1999 {
2000 int m, c;
2001
2002 for (m = 0; m < local->hw->num_modes; m++) {
2003 struct ieee80211_hw_modes *mode = &local->hw->modes[m];
2004 for (c = 0; c < mode->num_channels; c++) {
2005 struct ieee80211_channel *chan = &mode->channels[c];
2006 chan->flag |= IEEE80211_CHAN_W_SCAN;
2007 }
2008 }
2009 }
2010
2011
2012 static int ieee80211_ioctl_test_mode(struct net_device *dev, int mode)
2013 {
2014 struct ieee80211_local *local = dev->priv;
2015 int ret = -EOPNOTSUPP;
2016
2017 if (mode == IEEE80211_TEST_UNMASK_CHANNELS) {
2018 ieee80211_ioctl_unmask_channels(local);
2019 ret = 0;
2020 }
2021
2022 if (local->hw->test_mode)
2023 ret = local->hw->test_mode(dev, mode);
2024
2025 return ret;
2026 }
2027
2028
2029 static int ieee80211_ioctl_clear_keys(struct net_device *dev)
2030 {
2031 struct ieee80211_local *local = dev->priv;
2032 struct ieee80211_key_conf key;
2033 struct list_head *ptr;
2034 int i;
2035 u8 addr[ETH_ALEN];
2036 struct ieee80211_key_conf *keyconf;
2037
2038 memset(addr, 0xff, ETH_ALEN);
2039 list_for_each(ptr, &local->sub_if_list) {
2040 struct ieee80211_sub_if_data *sdata =
2041 list_entry(ptr, struct ieee80211_sub_if_data, list);
2042 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2043 keyconf = NULL;
2044 if (sdata->keys[i] &&
2045 !sdata->keys[i]->force_sw_encrypt &&
2046 local->hw->set_key &&
2047 (keyconf = ieee80211_key_data2conf(local,
2048 sdata->keys[i]))
2049 != NULL)
2050 local->hw->set_key(dev, DISABLE_KEY, addr,
2051 keyconf, 0);
2052 kfree(keyconf);
2053 kfree(sdata->keys[i]);
2054 sdata->keys[i] = NULL;
2055 }
2056 sdata->default_key = NULL;
2057 }
2058
2059 spin_lock_bh(&local->sta_lock);
2060 list_for_each(ptr, &local->sta_list) {
2061 struct sta_info *sta =
2062 list_entry(ptr, struct sta_info, list);
2063 keyconf = NULL;
2064 if (sta->key && !sta->key->force_sw_encrypt &&
2065 local->hw->set_key &&
2066 (keyconf = ieee80211_key_data2conf(local, sta->key))
2067 != NULL)
2068 local->hw->set_key(dev, DISABLE_KEY, sta->addr,
2069 keyconf, sta->aid);
2070 kfree(keyconf);
2071 kfree(sta->key);
2072 sta->key = NULL;
2073 }
2074 spin_unlock_bh(&local->sta_lock);
2075
2076
2077 memset(&key, 0, sizeof(key));
2078 if (local->hw->set_key &&
2079 local->hw->set_key(dev, REMOVE_ALL_KEYS, NULL,
2080 &key, 0))
2081 printk(KERN_DEBUG "%s: failed to remove hwaccel keys\n",
2082 dev->name);
2083
2084 return 0;
2085 }
2086
2087
2088 static int
2089 ieee80211_ioctl_force_unicast_rate(struct net_device *dev,
2090 struct ieee80211_sub_if_data *sdata,
2091 int rate)
2092 {
2093 struct ieee80211_local *local = dev->priv;
2094 int i;
2095
2096 if (sdata->type != IEEE80211_SUB_IF_TYPE_NORM)
2097 return -ENOENT;
2098
2099 if (rate == 0) {
2100 sdata->u.norm.force_unicast_rateidx = -1;
2101 return 0;
2102 }
2103
2104 for (i = 0; i < local->num_curr_rates; i++) {
2105 if (local->curr_rates[i].rate == rate) {
2106 sdata->u.norm.force_unicast_rateidx = i;
2107 return 0;
2108 }
2109 }
2110 return -EINVAL;
2111 }
2112
2113
2114 static int
2115 ieee80211_ioctl_max_ratectrl_rate(struct net_device *dev,
2116 struct ieee80211_sub_if_data *sdata,
2117 int rate)
2118 {
2119 struct ieee80211_local *local = dev->priv;
2120 int i;
2121
2122 if (sdata->type != IEEE80211_SUB_IF_TYPE_NORM)
2123 return -ENOENT;
2124
2125 if (rate == 0) {
2126 sdata->u.norm.max_ratectrl_rateidx = -1;
2127 return 0;
2128 }
2129
2130 for (i = 0; i < local->num_curr_rates; i++) {
2131 if (local->curr_rates[i].rate == rate) {
2132 sdata->u.norm.max_ratectrl_rateidx = i;
2133 return 0;
2134 }
2135 }
2136 return -EINVAL;
2137 }
2138
2139
2140 static void ieee80211_key_enable_hwaccel(struct ieee80211_local *local,
2141 struct ieee80211_key *key)
2142 {
2143 struct ieee80211_key_conf *keyconf;
2144 u8 addr[ETH_ALEN];
2145
2146 if (key == NULL || key->alg != ALG_WEP || !key->force_sw_encrypt ||
2147 local->hw->device_hides_wep)
2148 return;
2149
2150 memset(addr, 0xff, ETH_ALEN);
2151 keyconf = ieee80211_key_data2conf(local, key);
2152 if (keyconf && local->hw->set_key &&
2153 local->hw->set_key(local->mdev, SET_KEY, addr, keyconf, 0) == 0) {
2154 key->force_sw_encrypt = keyconf->force_sw_encrypt;
2155 key->hw_key_idx = keyconf->hw_key_idx;
2156 }
2157 kfree(keyconf);
2158 }
2159
2160
2161 static void ieee80211_key_disable_hwaccel(struct ieee80211_local *local,
2162 struct ieee80211_key *key)
2163 {
2164 struct ieee80211_key_conf *keyconf;
2165 u8 addr[ETH_ALEN];
2166
2167 if (key == NULL || key->alg != ALG_WEP || key->force_sw_encrypt ||
2168 local->hw->device_hides_wep)
2169 return;
2170
2171 memset(addr, 0xff, ETH_ALEN);
2172 keyconf = ieee80211_key_data2conf(local, key);
2173 if (keyconf && local->hw->set_key)
2174 local->hw->set_key(local->mdev, DISABLE_KEY, addr, keyconf, 0);
2175 kfree(keyconf);
2176 key->force_sw_encrypt = 1;
2177 }
2178
2179
2180 static int ieee80211_ioctl_default_wep_only(struct ieee80211_local *local,
2181 int value)
2182 {
2183 int i;
2184 struct list_head *ptr;
2185
2186 local->default_wep_only = value;
2187 list_for_each(ptr, &local->sub_if_list) {
2188 struct ieee80211_sub_if_data *sdata =
2189 list_entry(ptr, struct ieee80211_sub_if_data, list);
2190 for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
2191 if (value) {
2192 ieee80211_key_enable_hwaccel(local,
2193 sdata->keys[i]);
2194 } else {
2195 ieee80211_key_disable_hwaccel(local,
2196 sdata->keys[i]);
2197 }
2198 }
2199 }
2200
2201 return 0;
2202 }
2203
2204
2205 static int ieee80211_ioctl_prism2_param(struct net_device *dev,
2206 struct iw_request_info *info,
2207 void *wrqu, char *extra)
2208 {
2209 struct ieee80211_local *local = dev->priv;
2210 struct ieee80211_sub_if_data *sdata;
2211 int *i = (int *) extra;
2212 int param = *i;
2213 int value = *(i + 1);
2214 int ret = 0;
2215
2216 if (!capable(CAP_NET_ADMIN))
2217 return -EPERM;
2218
2219 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2220
2221 switch (param) {
2222 case PRISM2_PARAM_HOST_ENCRYPT:
2223 case PRISM2_PARAM_HOST_DECRYPT:
2224 /* TODO: implement these; return success now to prevent
2225 * hostapd from aborting */
2226 break;
2227
2228 case PRISM2_PARAM_BEACON_INT:
2229 local->conf.beacon_int = value;
2230 if (ieee80211_hw_config(dev))
2231 ret = -EINVAL;
2232 break;
2233
2234 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2235 local->bridge_packets = value;
2236 break;
2237
2238 case PRISM2_PARAM_AP_AUTH_ALGS:
2239 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
2240 sdata->u.sta.auth_algs = value;
2241 } else
2242 ret = -EOPNOTSUPP;
2243 break;
2244
2245 case PRISM2_PARAM_DTIM_PERIOD:
2246 if (value < 1)
2247 ret = -EINVAL;
2248 else if (sdata->type != IEEE80211_SUB_IF_TYPE_NORM)
2249 ret = -ENOENT;
2250 else
2251 sdata->u.norm.dtim_period = value;
2252 break;
2253
2254 case PRISM2_PARAM_IEEE_802_1X:
2255 sdata->ieee802_1x = value;
2256 if (local->hw->set_ieee8021x &&
2257 local->hw->set_ieee8021x(dev, value))
2258 printk(KERN_DEBUG "%s: failed to set IEEE 802.1X (%d) "
2259 "for low-level driver\n", dev->name, value);
2260 break;
2261
2262 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
2263 local->cts_protect_erp_frames = value;
2264 break;
2265
2266 case PRISM2_PARAM_DROP_UNENCRYPTED:
2267 sdata->drop_unencrypted = value;
2268 break;
2269
2270 case PRISM2_PARAM_PREAMBLE:
2271 local->short_preamble = value;
2272 break;
2273
2274 case PRISM2_PARAM_RATE_LIMIT_BURST:
2275 local->rate_limit_burst = value;
2276 local->rate_limit_bucket = value;
2277 break;
2278
2279 case PRISM2_PARAM_RATE_LIMIT:
2280 /* number of packets (tokens) allowed per second */
2281 if (!local->rate_limit && value) {
2282 if (!local->rate_limit_burst) local->rate_limit_burst =
2283 value;
2284 local->rate_limit_bucket = local->rate_limit_burst;
2285 local->rate_limit_timer.expires = jiffies + HZ;
2286 add_timer(&local->rate_limit_timer);
2287 } else if (local->rate_limit && !value) {
2288 del_timer_sync(&local->rate_limit_timer);
2289 }
2290 local->rate_limit = value;
2291 break;
2292
2293 case PRISM2_PARAM_STAT_TIME:
2294 if (!local->stat_time && value) {
2295 local->stat_timer.expires = jiffies + HZ * value / 100;
2296 add_timer(&local->stat_timer);
2297 } else if (local->stat_time && !value) {
2298 del_timer_sync(&local->stat_timer);
2299 }
2300 local->stat_time = value;
2301 break;
2302 case PRISM2_PARAM_SHORT_SLOT_TIME:
2303 local->conf.short_slot_time = value;
2304 if (ieee80211_hw_config(dev))
2305 ret = -EINVAL;
2306 break;
2307
2308 case PRISM2_PARAM_PRIVACY_INVOKED:
2309 if (local->hw->set_privacy_invoked)
2310 ret = local->hw->set_privacy_invoked(dev, value);
2311 break;
2312
2313 case PRISM2_PARAM_TEST_MODE:
2314 ret = ieee80211_ioctl_test_mode(dev, value);
2315 break;
2316
2317 case PRISM2_PARAM_NEXT_MODE:
2318 local->next_mode = value;
2319 break;
2320
2321 case PRISM2_PARAM_CLEAR_KEYS:
2322 ret = ieee80211_ioctl_clear_keys(dev);
2323 break;
2324
2325 case PRISM2_PARAM_ADM_STATUS:
2326 ret = ieee80211_ioctl_set_adm_status(dev, value);
2327 break;
2328
2329 case PRISM2_PARAM_ANTENNA_SEL:
2330 local->conf.antenna_sel = value;
2331 if (ieee80211_hw_config(dev))
2332 ret = -EINVAL;
2333 break;
2334
2335 case PRISM2_PARAM_CALIB_INT:
2336 local->conf.calib_int = value;
2337 if (ieee80211_hw_config(dev))
2338 ret = -EINVAL;
2339 break;
2340
2341 case PRISM2_PARAM_ANTENNA_MODE:
2342 local->conf.antenna_mode = value;
2343 if (ieee80211_hw_config(dev))
2344 ret = -EINVAL;
2345 break;
2346
2347 case PRISM2_PARAM_BROADCAST_SSID:
2348 if ((value < 0) || (value > 1))
2349 ret = -EINVAL;
2350 else
2351 local->conf.ssid_hidden = value;
2352 break;
2353
2354 case PRISM2_PARAM_STA_ANTENNA_SEL:
2355 local->sta_antenna_sel = value;
2356 break;
2357
2358 case PRISM2_PARAM_FORCE_UNICAST_RATE:
2359 ret = ieee80211_ioctl_force_unicast_rate(dev, sdata, value);
2360 break;
2361
2362 case PRISM2_PARAM_MAX_RATECTRL_RATE:
2363 ret = ieee80211_ioctl_max_ratectrl_rate(dev, sdata, value);
2364 break;
2365
2366 case PRISM2_PARAM_RATE_CTRL_NUM_UP:
2367 local->rate_ctrl_num_up = value;
2368 break;
2369
2370 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
2371 local->rate_ctrl_num_down = value;
2372 break;
2373
2374 case PRISM2_PARAM_TX_POWER_REDUCTION:
2375 if (value < 0)
2376 ret = -EINVAL;
2377 else
2378 local->conf.tx_power_reduction = value;
2379 break;
2380
2381 case PRISM2_PARAM_EAPOL:
2382 sdata->eapol = value;
2383 break;
2384
2385 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
2386 local->key_tx_rx_threshold = value;
2387 break;
2388
2389 case PRISM2_PARAM_KEY_INDEX:
2390 if (value < 0 || value >= NUM_DEFAULT_KEYS)
2391 ret = -EINVAL;
2392 else if (sdata->keys[value] == NULL)
2393 ret = -ENOENT;
2394 else
2395 sdata->default_key = sdata->keys[value];
2396 break;
2397
2398 case PRISM2_PARAM_DEFAULT_WEP_ONLY:
2399 ret = ieee80211_ioctl_default_wep_only(local, value);
2400 break;
2401
2402 case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
2403 local->wifi_wme_noack_test = value;
2404 break;
2405
2406
2407
2408 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
2409 local->allow_broadcast_always = value;
2410 break;
2411
2412 case PRISM2_PARAM_SCAN_FLAGS:
2413 local->scan_flags = value;
2414 break;
2415
2416 case PRISM2_PARAM_MIXED_CELL:
2417 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2418 ret = -EINVAL;
2419 else
2420 sdata->u.sta.mixed_cell = !!value;
2421 break;
2422
2423 case PRISM2_PARAM_KEY_MGMT:
2424 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2425 ret = -EINVAL;
2426 else
2427 sdata->u.sta.key_mgmt = value;
2428 break;
2429
2430 case PRISM2_PARAM_HW_MODES:
2431 local->hw_modes = value;
2432 break;
2433
2434 case PRISM2_PARAM_CREATE_IBSS:
2435 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2436 ret = -EINVAL;
2437 else
2438 sdata->u.sta.create_ibss = !!value;
2439 break;
2440 case PRISM2_PARAM_WMM_ENABLED:
2441 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2442 ret = -EINVAL;
2443 else
2444 sdata->u.sta.wmm_enabled = !!value;
2445 break;
2446 case PRISM2_PARAM_RADAR_DETECT:
2447 local->conf.radar_detect = value;
2448 break;
2449 case PRISM2_PARAM_SPECTRUM_MGMT:
2450 local->conf.spect_mgmt = value;
2451 break;
2452 default:
2453 ret = -EOPNOTSUPP;
2454 break;
2455 }
2456
2457 return ret;
2458 }
2459
2460
2461 static int ieee80211_ioctl_get_prism2_param(struct net_device *dev,
2462 struct iw_request_info *info,
2463 void *wrqu, char *extra)
2464 {
2465 struct ieee80211_local *local = dev->priv;
2466 struct ieee80211_sub_if_data *sdata;
2467 int *param = (int *) extra;
2468 int ret = 0;
2469
2470 sdata = IEEE80211_DEV_TO_SUB_IF(dev);
2471
2472 switch (*param) {
2473 case PRISM2_PARAM_BEACON_INT:
2474 *param = local->conf.beacon_int;
2475 break;
2476
2477 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2478 *param = local->bridge_packets;
2479 break;
2480
2481 case PRISM2_PARAM_AP_AUTH_ALGS:
2482 if (sdata->type == IEEE80211_SUB_IF_TYPE_STA) {
2483 *param = sdata->u.sta.auth_algs;
2484 } else
2485 ret = -EOPNOTSUPP;
2486 break;
2487
2488 case PRISM2_PARAM_DTIM_PERIOD:
2489 if (sdata->type != IEEE80211_SUB_IF_TYPE_NORM)
2490 ret = -ENOENT;
2491 else
2492 *param = sdata->u.norm.dtim_period;
2493 break;
2494
2495 case PRISM2_PARAM_IEEE_802_1X:
2496 *param = sdata->ieee802_1x;
2497 break;
2498
2499 case PRISM2_PARAM_CTS_PROTECT_ERP_FRAMES:
2500 *param = local->cts_protect_erp_frames;
2501 break;
2502
2503 case PRISM2_PARAM_DROP_UNENCRYPTED:
2504 *param = sdata->drop_unencrypted;
2505 break;
2506
2507 case PRISM2_PARAM_PREAMBLE:
2508 *param = local->short_preamble;
2509 break;
2510
2511 case PRISM2_PARAM_RATE_LIMIT_BURST:
2512 *param = local->rate_limit_burst;
2513 break;
2514
2515 case PRISM2_PARAM_RATE_LIMIT:
2516 *param = local->rate_limit;
2517 break;
2518
2519 case PRISM2_PARAM_STAT_TIME:
2520 *param = local->stat_time;
2521 break;
2522 case PRISM2_PARAM_SHORT_SLOT_TIME:
2523 *param = local->conf.short_slot_time;
2524 break;
2525
2526 case PRISM2_PARAM_NEXT_MODE:
2527 *param = local->next_mode;
2528 break;
2529
2530 case PRISM2_PARAM_ANTENNA_SEL:
2531 *param = local->conf.antenna_sel;
2532 break;
2533
2534 case PRISM2_PARAM_CALIB_INT:
2535 *param = local->conf.calib_int;
2536 break;
2537
2538 case PRISM2_PARAM_ANTENNA_MODE:
2539 *param = local->conf.antenna_mode;
2540 break;
2541
2542 case PRISM2_PARAM_BROADCAST_SSID:
2543 *param = local->conf.ssid_hidden;
2544 break;
2545
2546 case PRISM2_PARAM_STA_ANTENNA_SEL:
2547 *param = local->sta_antenna_sel;
2548 break;
2549
2550 case PRISM2_PARAM_RATE_CTRL_NUM_UP:
2551 *param = local->rate_ctrl_num_up;
2552 break;
2553
2554 case PRISM2_PARAM_RATE_CTRL_NUM_DOWN:
2555 *param = local->rate_ctrl_num_down;
2556 break;
2557
2558 case PRISM2_PARAM_TX_POWER_REDUCTION:
2559 *param = local->conf.tx_power_reduction;
2560 break;
2561
2562 case PRISM2_PARAM_EAPOL:
2563 *param = sdata->eapol;
2564 break;
2565
2566 case PRISM2_PARAM_KEY_TX_RX_THRESHOLD:
2567 *param = local->key_tx_rx_threshold;
2568 break;
2569
2570 case PRISM2_PARAM_KEY_INDEX:
2571 if (sdata->default_key == NULL)
2572 ret = -ENOENT;
2573 else if (sdata->default_key == sdata->keys[0])
2574 *param = 0;
2575 else if (sdata->default_key == sdata->keys[1])
2576 *param = 1;
2577 else if (sdata->default_key == sdata->keys[2])
2578 *param = 2;
2579 else if (sdata->default_key == sdata->keys[3])
2580 *param = 3;
2581 else
2582 ret = -ENOENT;
2583 break;
2584
2585 case PRISM2_PARAM_DEFAULT_WEP_ONLY:
2586 *param = local->default_wep_only;
2587 break;
2588
2589 case PRISM2_PARAM_WIFI_WME_NOACK_TEST:
2590 *param = local->wifi_wme_noack_test;
2591 break;
2592
2593
2594
2595 case PRISM2_PARAM_ALLOW_BROADCAST_ALWAYS:
2596 *param = local->allow_broadcast_always;
2597 break;
2598
2599 case PRISM2_PARAM_SCAN_FLAGS:
2600 *param = local->scan_flags;
2601 break;
2602
2603 case PRISM2_PARAM_HW_MODES:
2604 *param = local->hw_modes;
2605 break;
2606
2607 case PRISM2_PARAM_CREATE_IBSS:
2608 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2609 ret = -EINVAL;
2610 else
2611 *param = !!sdata->u.sta.create_ibss;
2612 break;
2613
2614 case PRISM2_PARAM_MIXED_CELL:
2615 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2616 ret = -EINVAL;
2617 else
2618 *param = !!sdata->u.sta.mixed_cell;
2619 break;
2620
2621 case PRISM2_PARAM_KEY_MGMT:
2622 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2623 ret = -EINVAL;
2624 else
2625 *param = sdata->u.sta.key_mgmt;
2626 break;
2627 case PRISM2_PARAM_WMM_ENABLED:
2628 if (sdata->type != IEEE80211_SUB_IF_TYPE_STA)
2629 ret = -EINVAL;
2630 else
2631 *param = !!sdata->u.sta.wmm_enabled;
2632 break;
2633
2634 default:
2635 ret = -EOPNOTSUPP;
2636 break;
2637 }
2638
2639 return ret;
2640 }
2641
2642
2643 static int ieee80211_ioctl_test_param(struct net_device *dev,
2644 struct iw_request_info *info,
2645 void *wrqu, char *extra)
2646 {
2647 struct ieee80211_local *local = dev->priv;
2648 int *i = (int *) extra;
2649 int param = *i;
2650 int value = *(i + 1);
2651
2652 if (!capable(CAP_NET_ADMIN))
2653 return -EPERM;
2654
2655 if (local->hw->test_param)
2656 return local->hw->test_param(local->mdev, param, value);
2657
2658 return -EOPNOTSUPP;
2659 }
2660
2661
2662 static const struct iw_priv_args ieee80211_ioctl_priv[] = {
2663 { PRISM2_IOCTL_PRISM2_PARAM,
2664 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "param" },
2665 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2666 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2667 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "get_param" },
2668 { PRISM2_IOCTL_TEST_PARAM,
2669 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "test_param" },
2670 };
2671
2672
2673 static int ieee80211_ioctl_giwpriv(struct net_device *dev,
2674 struct iw_point *data)
2675 {
2676
2677 if (!data->pointer ||
2678 !access_ok(VERIFY_WRITE, data->pointer,
2679 sizeof(ieee80211_ioctl_priv)))
2680 return -EINVAL;
2681
2682 data->length = sizeof(ieee80211_ioctl_priv) /
2683 sizeof(ieee80211_ioctl_priv[0]);
2684 if (copy_to_user(data->pointer, ieee80211_ioctl_priv,
2685 sizeof(ieee80211_ioctl_priv)))
2686 return -EINVAL;
2687 return 0;
2688 }
2689
2690
2691 int ieee80211_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
2692 {
2693 struct iwreq *wrq = (struct iwreq *) rq;
2694 int ret = 0;
2695 char ssid[IW_ESSID_MAX_SIZE + 1];
2696
2697 switch (cmd) {
2698 case SIOCGIWNAME:
2699 ret = ieee80211_ioctl_giwname(dev, NULL, (char *) &wrq->u,
2700 NULL);
2701 break;
2702 case SIOCSIWESSID:
2703 if (!wrq->u.essid.pointer)
2704 ret = -EINVAL;
2705 else if (wrq->u.essid.length > IW_ESSID_MAX_SIZE)
2706 ret = -E2BIG;
2707 else {
2708 if (copy_from_user(ssid, wrq->u.essid.pointer,
2709 wrq->u.essid.length)) {
2710 ret = -EFAULT;
2711 break;
2712 }
2713 ret = ieee80211_ioctl_siwessid(dev, NULL,
2714 &wrq->u.essid, ssid);
2715 }
2716 break;
2717 case SIOCGIWESSID:
2718 if (!wrq->u.essid.pointer) {
2719 ret = -EINVAL;
2720 } else {
2721 memset(ssid, 0, IW_ESSID_MAX_SIZE + 1);
2722 ret = ieee80211_ioctl_giwessid(dev, NULL,
2723 &wrq->u.essid, ssid);
2724 if (copy_to_user(wrq->u.essid.pointer, ssid,
2725 wrq->u.essid.length)) {
2726 ret = -EFAULT;
2727 break;
2728 }
2729 }
2730 break;
2731
2732 case SIOCGIWRANGE:
2733 {
2734 struct iw_range range;
2735 if (!access_ok(VERIFY_WRITE, wrq->u.data.pointer,
2736 sizeof(range))) {
2737 ret = -EFAULT;
2738 break;
2739 }
2740 ret = ieee80211_ioctl_giwrange(dev, NULL, &wrq->u.data,
2741 (char *) &range);
2742 if (ret)
2743 break;
2744 if (copy_to_user(wrq->u.data.pointer, &range, sizeof(range)))
2745 ret = -EFAULT;
2746 break;
2747 }
2748
2749 case SIOCSIWAP:
2750 ret = ieee80211_ioctl_siwap(dev, NULL, &wrq->u.ap_addr, NULL);
2751 break;
2752 case SIOCGIWAP:
2753 ret = ieee80211_ioctl_giwap(dev, NULL, &wrq->u.ap_addr, NULL);
2754 break;
2755 case SIOCSIWSCAN:
2756 ret = ieee80211_ioctl_siwscan(dev, NULL, &wrq->u.data, NULL);
2757 break;
2758 case SIOCGIWSCAN:
2759 {
2760 char *buf = kmalloc(IW_SCAN_MAX_DATA, GFP_KERNEL);
2761 if (buf == NULL) {
2762 ret = -ENOMEM;
2763 break;
2764 }
2765 ret = ieee80211_ioctl_giwscan(dev, NULL, &wrq->u.data, buf);
2766 if (ret == 0 &&
2767 copy_to_user(wrq->u.data.pointer, buf, wrq->u.data.length))
2768 ret = -EFAULT;
2769 kfree(buf);
2770 break;
2771 }
2772
2773 case SIOCSIWFREQ:
2774 ret = ieee80211_ioctl_siwfreq(dev, NULL, &wrq->u.freq, NULL);
2775 break;
2776 case SIOCGIWFREQ:
2777 ret = ieee80211_ioctl_giwfreq(dev, NULL, &wrq->u.freq, NULL);
2778 break;
2779 case SIOCSIWMODE:
2780 ret = ieee80211_ioctl_siwmode(dev, NULL, &wrq->u.mode, NULL);
2781 break;
2782 case SIOCGIWMODE:
2783 ret = ieee80211_ioctl_giwmode(dev, NULL, &wrq->u.mode, NULL);
2784 break;
2785
2786 case SIOCSIWRTS:
2787 ret = ieee80211_ioctl_siwrts(dev, NULL, &wrq->u.rts, NULL);
2788 break;
2789 case SIOCGIWRTS:
2790 ret = ieee80211_ioctl_giwrts(dev, NULL, &wrq->u.rts, NULL);
2791 break;
2792
2793 case SIOCSIWFRAG:
2794 ret = ieee80211_ioctl_siwfrag(dev, NULL, &wrq->u.frag, NULL);
2795 break;
2796 case SIOCGIWFRAG:
2797 ret = ieee80211_ioctl_giwfrag(dev, NULL, &wrq->u.frag, NULL);
2798 break;
2799
2800 case SIOCSIWRETRY:
2801 ret = ieee80211_ioctl_siwretry(dev, NULL, &wrq->u.retry, NULL);
2802 break;
2803 case SIOCGIWRETRY:
2804 ret = ieee80211_ioctl_giwretry(dev, NULL, &wrq->u.retry, NULL);
2805 break;
2806
2807 case PRISM2_IOCTL_PRISM2_PARAM:
2808 ret = ieee80211_ioctl_prism2_param(dev, NULL, &wrq->u,
2809 (char *) &wrq->u);
2810 break;
2811 case PRISM2_IOCTL_GET_PRISM2_PARAM:
2812 ret = ieee80211_ioctl_get_prism2_param(dev, NULL, &wrq->u,
2813 (char *) &wrq->u);
2814 break;
2815 case PRISM2_IOCTL_TEST_PARAM:
2816 ret = ieee80211_ioctl_test_param(dev, NULL, &wrq->u,
2817 (char *) &wrq->u);
2818 break;
2819 case PRISM2_IOCTL_HOSTAPD:
2820 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
2821 else ret = ieee80211_ioctl_priv_hostapd(dev, &wrq->u.data);
2822 break;
2823 case SIOCGIWPRIV:
2824 ret = ieee80211_ioctl_giwpriv(dev, &wrq->u.data);
2825 break;
2826 default:
2827 ret = -EOPNOTSUPP;
2828 break;
2829 }
2830
2831 return ret;
2832 }
This page took 0.177969 seconds and 3 git commands to generate.