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