[PATCH] hostap update
[deliverable/linux.git] / drivers / net / wireless / hostap / hostap_ioctl.c
CommitLineData
ff1d2767
JM
1/* ioctl() (mostly Linux Wireless Extensions) routines for Host AP driver */
2
3#ifdef in_atomic
4/* Get kernel_locked() for in_atomic() */
5#include <linux/smp_lock.h>
6#endif
7#include <linux/ethtool.h>
8
9
10static struct iw_statistics *hostap_get_wireless_stats(struct net_device *dev)
11{
12 struct hostap_interface *iface;
13 local_info_t *local;
14 struct iw_statistics *wstats;
15
16 iface = netdev_priv(dev);
17 local = iface->local;
18
19 /* Why are we doing that ? Jean II */
20 if (iface->type != HOSTAP_INTERFACE_MAIN)
21 return NULL;
22
23 wstats = &local->wstats;
24
25 wstats->status = 0;
26 wstats->discard.code =
27 local->comm_tallies.rx_discards_wep_undecryptable;
28 wstats->discard.misc =
29 local->comm_tallies.rx_fcs_errors +
30 local->comm_tallies.rx_discards_no_buffer +
31 local->comm_tallies.tx_discards_wrong_sa;
32
33 wstats->discard.retries =
34 local->comm_tallies.tx_retry_limit_exceeded;
35 wstats->discard.fragment =
36 local->comm_tallies.rx_message_in_bad_msg_fragments;
37
38 if (local->iw_mode != IW_MODE_MASTER &&
39 local->iw_mode != IW_MODE_REPEAT) {
40 int update = 1;
41#ifdef in_atomic
42 /* RID reading might sleep and it must not be called in
43 * interrupt context or while atomic. However, this
44 * function seems to be called while atomic (at least in Linux
45 * 2.5.59). Update signal quality values only if in suitable
46 * context. Otherwise, previous values read from tick timer
47 * will be used. */
48 if (in_atomic())
49 update = 0;
50#endif /* in_atomic */
51
52 if (update && prism2_update_comms_qual(dev) == 0)
53 wstats->qual.updated = 7;
54
55 wstats->qual.qual = local->comms_qual;
56 wstats->qual.level = local->avg_signal;
57 wstats->qual.noise = local->avg_noise;
58 } else {
59 wstats->qual.qual = 0;
60 wstats->qual.level = 0;
61 wstats->qual.noise = 0;
62 wstats->qual.updated = 0;
63 }
64
65 return wstats;
66}
67
68
69static int prism2_get_datarates(struct net_device *dev, u8 *rates)
70{
71 struct hostap_interface *iface;
72 local_info_t *local;
73 u8 buf[12];
74 int len;
75 u16 val;
76
77 iface = netdev_priv(dev);
78 local = iface->local;
79
80 len = local->func->get_rid(dev, HFA384X_RID_SUPPORTEDDATARATES, buf,
81 sizeof(buf), 0);
82 if (len < 2)
83 return 0;
84
85 val = le16_to_cpu(*(u16 *) buf); /* string length */
86
87 if (len - 2 < val || val > 10)
88 return 0;
89
90 memcpy(rates, buf + 2, val);
91 return val;
92}
93
94
95static int prism2_get_name(struct net_device *dev,
96 struct iw_request_info *info,
97 char *name, char *extra)
98{
99 u8 rates[10];
100 int len, i, over2 = 0;
101
102 len = prism2_get_datarates(dev, rates);
103
104 for (i = 0; i < len; i++) {
105 if (rates[i] == 0x0b || rates[i] == 0x16) {
106 over2 = 1;
107 break;
108 }
109 }
110
111 strcpy(name, over2 ? "IEEE 802.11b" : "IEEE 802.11-DS");
112
113 return 0;
114}
115
116
117static void prism2_crypt_delayed_deinit(local_info_t *local,
118 struct prism2_crypt_data **crypt)
119{
120 struct prism2_crypt_data *tmp;
121 unsigned long flags;
122
123 tmp = *crypt;
124 *crypt = NULL;
125
126 if (tmp == NULL)
127 return;
128
129 /* must not run ops->deinit() while there may be pending encrypt or
130 * decrypt operations. Use a list of delayed deinits to avoid needing
131 * locking. */
132
133 spin_lock_irqsave(&local->lock, flags);
134 list_add(&tmp->list, &local->crypt_deinit_list);
135 if (!timer_pending(&local->crypt_deinit_timer)) {
136 local->crypt_deinit_timer.expires = jiffies + HZ;
137 add_timer(&local->crypt_deinit_timer);
138 }
139 spin_unlock_irqrestore(&local->lock, flags);
140}
141
142
143static int prism2_ioctl_siwencode(struct net_device *dev,
144 struct iw_request_info *info,
145 struct iw_point *erq, char *keybuf)
146{
147 struct hostap_interface *iface;
148 local_info_t *local;
149 int i;
150 struct prism2_crypt_data **crypt;
151
152 iface = netdev_priv(dev);
153 local = iface->local;
154
155 i = erq->flags & IW_ENCODE_INDEX;
156 if (i < 1 || i > 4)
157 i = local->tx_keyidx;
158 else
159 i--;
160 if (i < 0 || i >= WEP_KEYS)
161 return -EINVAL;
162
163 crypt = &local->crypt[i];
164
165 if (erq->flags & IW_ENCODE_DISABLED) {
166 if (*crypt)
167 prism2_crypt_delayed_deinit(local, crypt);
168 goto done;
169 }
170
171 if (*crypt != NULL && (*crypt)->ops != NULL &&
172 strcmp((*crypt)->ops->name, "WEP") != 0) {
173 /* changing to use WEP; deinit previously used algorithm */
174 prism2_crypt_delayed_deinit(local, crypt);
175 }
176
177 if (*crypt == NULL) {
178 struct prism2_crypt_data *new_crypt;
179
180 /* take WEP into use */
181 new_crypt = (struct prism2_crypt_data *)
182 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
183 if (new_crypt == NULL)
184 return -ENOMEM;
185 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
186 new_crypt->ops = hostap_get_crypto_ops("WEP");
187 if (!new_crypt->ops) {
188 request_module("hostap_crypt_wep");
189 new_crypt->ops = hostap_get_crypto_ops("WEP");
190 }
191 if (new_crypt->ops)
192 new_crypt->priv = new_crypt->ops->init(i);
193 if (!new_crypt->ops || !new_crypt->priv) {
194 kfree(new_crypt);
195 new_crypt = NULL;
196
197 printk(KERN_WARNING "%s: could not initialize WEP: "
198 "load module hostap_crypt_wep.o\n",
199 dev->name);
200 return -EOPNOTSUPP;
201 }
202 *crypt = new_crypt;
203 }
204
205 if (erq->length > 0) {
206 int len = erq->length <= 5 ? 5 : 13;
207 int first = 1, j;
208 if (len > erq->length)
209 memset(keybuf + erq->length, 0, len - erq->length);
210 (*crypt)->ops->set_key(keybuf, len, NULL, (*crypt)->priv);
211 for (j = 0; j < WEP_KEYS; j++) {
212 if (j != i && local->crypt[j]) {
213 first = 0;
214 break;
215 }
216 }
217 if (first)
218 local->tx_keyidx = i;
219 } else {
220 /* No key data - just set the default TX key index */
221 local->tx_keyidx = i;
222 }
223
224 done:
225 local->open_wep = erq->flags & IW_ENCODE_OPEN;
226
227 if (hostap_set_encryption(local)) {
228 printk(KERN_DEBUG "%s: set_encryption failed\n", dev->name);
229 return -EINVAL;
230 }
231
232 /* Do not reset port0 if card is in Managed mode since resetting will
233 * generate new IEEE 802.11 authentication which may end up in looping
234 * with IEEE 802.1X. Prism2 documentation seem to require port reset
235 * after WEP configuration. However, keys are apparently changed at
236 * least in Managed mode. */
237 if (local->iw_mode != IW_MODE_INFRA && local->func->reset_port(dev)) {
238 printk(KERN_DEBUG "%s: reset_port failed\n", dev->name);
239 return -EINVAL;
240 }
241
242 return 0;
243}
244
245
246static int prism2_ioctl_giwencode(struct net_device *dev,
247 struct iw_request_info *info,
248 struct iw_point *erq, char *key)
249{
250 struct hostap_interface *iface;
251 local_info_t *local;
252 int i, len;
253 u16 val;
254 struct prism2_crypt_data *crypt;
255
256 iface = netdev_priv(dev);
257 local = iface->local;
258
259 i = erq->flags & IW_ENCODE_INDEX;
260 if (i < 1 || i > 4)
261 i = local->tx_keyidx;
262 else
263 i--;
264 if (i < 0 || i >= WEP_KEYS)
265 return -EINVAL;
266
267 crypt = local->crypt[i];
268 erq->flags = i + 1;
269
270 if (crypt == NULL || crypt->ops == NULL) {
271 erq->length = 0;
272 erq->flags |= IW_ENCODE_DISABLED;
273 return 0;
274 }
275
276 if (strcmp(crypt->ops->name, "WEP") != 0) {
277 /* only WEP is supported with wireless extensions, so just
278 * report that encryption is used */
279 erq->length = 0;
280 erq->flags |= IW_ENCODE_ENABLED;
281 return 0;
282 }
283
284 /* Reads from HFA384X_RID_CNFDEFAULTKEY* return bogus values, so show
285 * the keys from driver buffer */
286 len = crypt->ops->get_key(key, WEP_KEY_LEN, NULL, crypt->priv);
287 erq->length = (len >= 0 ? len : 0);
288
289 if (local->func->get_rid(dev, HFA384X_RID_CNFWEPFLAGS, &val, 2, 1) < 0)
290 {
291 printk("CNFWEPFLAGS reading failed\n");
292 return -EOPNOTSUPP;
293 }
294 le16_to_cpus(&val);
295 if (val & HFA384X_WEPFLAGS_PRIVACYINVOKED)
296 erq->flags |= IW_ENCODE_ENABLED;
297 else
298 erq->flags |= IW_ENCODE_DISABLED;
299 if (val & HFA384X_WEPFLAGS_EXCLUDEUNENCRYPTED)
300 erq->flags |= IW_ENCODE_RESTRICTED;
301 else
302 erq->flags |= IW_ENCODE_OPEN;
303
304 return 0;
305}
306
307
308static int hostap_set_rate(struct net_device *dev)
309{
310 struct hostap_interface *iface;
311 local_info_t *local;
312 int ret, basic_rates;
313
314 iface = netdev_priv(dev);
315 local = iface->local;
316
317 basic_rates = local->basic_rates & local->tx_rate_control;
318 if (!basic_rates || basic_rates != local->basic_rates) {
319 printk(KERN_INFO "%s: updating basic rate set automatically "
320 "to match with the new supported rate set\n",
321 dev->name);
322 if (!basic_rates)
323 basic_rates = local->tx_rate_control;
324
325 local->basic_rates = basic_rates;
326 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
327 basic_rates))
328 printk(KERN_WARNING "%s: failed to set "
329 "cnfBasicRates\n", dev->name);
330 }
331
332 ret = (hostap_set_word(dev, HFA384X_RID_TXRATECONTROL,
333 local->tx_rate_control) ||
334 hostap_set_word(dev, HFA384X_RID_CNFSUPPORTEDRATES,
335 local->tx_rate_control) ||
336 local->func->reset_port(dev));
337
338 if (ret) {
339 printk(KERN_WARNING "%s: TXRateControl/cnfSupportedRates "
340 "setting to 0x%x failed\n",
341 dev->name, local->tx_rate_control);
342 }
343
344 /* Update TX rate configuration for all STAs based on new operational
345 * rate set. */
346 hostap_update_rates(local);
347
348 return ret;
349}
350
351
352static int prism2_ioctl_siwrate(struct net_device *dev,
353 struct iw_request_info *info,
354 struct iw_param *rrq, char *extra)
355{
356 struct hostap_interface *iface;
357 local_info_t *local;
358
359 iface = netdev_priv(dev);
360 local = iface->local;
361
362 if (rrq->fixed) {
363 switch (rrq->value) {
364 case 11000000:
365 local->tx_rate_control = HFA384X_RATES_11MBPS;
366 break;
367 case 5500000:
368 local->tx_rate_control = HFA384X_RATES_5MBPS;
369 break;
370 case 2000000:
371 local->tx_rate_control = HFA384X_RATES_2MBPS;
372 break;
373 case 1000000:
374 local->tx_rate_control = HFA384X_RATES_1MBPS;
375 break;
376 default:
377 local->tx_rate_control = HFA384X_RATES_1MBPS |
378 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
379 HFA384X_RATES_11MBPS;
380 break;
381 }
382 } else {
383 switch (rrq->value) {
384 case 11000000:
385 local->tx_rate_control = HFA384X_RATES_1MBPS |
386 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
387 HFA384X_RATES_11MBPS;
388 break;
389 case 5500000:
390 local->tx_rate_control = HFA384X_RATES_1MBPS |
391 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS;
392 break;
393 case 2000000:
394 local->tx_rate_control = HFA384X_RATES_1MBPS |
395 HFA384X_RATES_2MBPS;
396 break;
397 case 1000000:
398 local->tx_rate_control = HFA384X_RATES_1MBPS;
399 break;
400 default:
401 local->tx_rate_control = HFA384X_RATES_1MBPS |
402 HFA384X_RATES_2MBPS | HFA384X_RATES_5MBPS |
403 HFA384X_RATES_11MBPS;
404 break;
405 }
406 }
407
408 return hostap_set_rate(dev);
409}
410
411
412static int prism2_ioctl_giwrate(struct net_device *dev,
413 struct iw_request_info *info,
414 struct iw_param *rrq, char *extra)
415{
416 u16 val;
417 struct hostap_interface *iface;
418 local_info_t *local;
419 int ret = 0;
420
421 iface = netdev_priv(dev);
422 local = iface->local;
423
424 if (local->func->get_rid(dev, HFA384X_RID_TXRATECONTROL, &val, 2, 1) <
425 0)
426 return -EINVAL;
427
428 if ((val & 0x1) && (val > 1))
429 rrq->fixed = 0;
430 else
431 rrq->fixed = 1;
432
433 if (local->iw_mode == IW_MODE_MASTER && local->ap != NULL &&
434 !local->fw_tx_rate_control) {
435 /* HFA384X_RID_CURRENTTXRATE seems to always be 2 Mbps in
436 * Host AP mode, so use the recorded TX rate of the last sent
437 * frame */
438 rrq->value = local->ap->last_tx_rate > 0 ?
439 local->ap->last_tx_rate * 100000 : 11000000;
440 return 0;
441 }
442
443 if (local->func->get_rid(dev, HFA384X_RID_CURRENTTXRATE, &val, 2, 1) <
444 0)
445 return -EINVAL;
446
447 switch (val) {
448 case HFA384X_RATES_1MBPS:
449 rrq->value = 1000000;
450 break;
451 case HFA384X_RATES_2MBPS:
452 rrq->value = 2000000;
453 break;
454 case HFA384X_RATES_5MBPS:
455 rrq->value = 5500000;
456 break;
457 case HFA384X_RATES_11MBPS:
458 rrq->value = 11000000;
459 break;
460 default:
461 /* should not happen */
462 rrq->value = 11000000;
463 ret = -EINVAL;
464 break;
465 }
466
467 return ret;
468}
469
470
471static int prism2_ioctl_siwsens(struct net_device *dev,
472 struct iw_request_info *info,
473 struct iw_param *sens, char *extra)
474{
475 struct hostap_interface *iface;
476 local_info_t *local;
477
478 iface = netdev_priv(dev);
479 local = iface->local;
480
481 /* Set the desired AP density */
482 if (sens->value < 1 || sens->value > 3)
483 return -EINVAL;
484
485 if (hostap_set_word(dev, HFA384X_RID_CNFSYSTEMSCALE, sens->value) ||
486 local->func->reset_port(dev))
487 return -EINVAL;
488
489 return 0;
490}
491
492static int prism2_ioctl_giwsens(struct net_device *dev,
493 struct iw_request_info *info,
494 struct iw_param *sens, char *extra)
495{
496 struct hostap_interface *iface;
497 local_info_t *local;
498 u16 val;
499
500 iface = netdev_priv(dev);
501 local = iface->local;
502
503 /* Get the current AP density */
504 if (local->func->get_rid(dev, HFA384X_RID_CNFSYSTEMSCALE, &val, 2, 1) <
505 0)
506 return -EINVAL;
507
508 sens->value = __le16_to_cpu(val);
509 sens->fixed = 1;
510
511 return 0;
512}
513
514
515/* Deprecated in new wireless extension API */
516static int prism2_ioctl_giwaplist(struct net_device *dev,
517 struct iw_request_info *info,
518 struct iw_point *data, char *extra)
519{
520 struct hostap_interface *iface;
521 local_info_t *local;
522 struct sockaddr *addr;
523 struct iw_quality *qual;
524
525 iface = netdev_priv(dev);
526 local = iface->local;
527
528 if (local->iw_mode != IW_MODE_MASTER) {
529 printk(KERN_DEBUG "SIOCGIWAPLIST is currently only supported "
530 "in Host AP mode\n");
531 data->length = 0;
532 return -EOPNOTSUPP;
533 }
534
535 addr = kmalloc(sizeof(struct sockaddr) * IW_MAX_AP, GFP_KERNEL);
536 qual = kmalloc(sizeof(struct iw_quality) * IW_MAX_AP, GFP_KERNEL);
537 if (addr == NULL || qual == NULL) {
538 kfree(addr);
539 kfree(qual);
540 data->length = 0;
541 return -ENOMEM;
542 }
543
544 data->length = prism2_ap_get_sta_qual(local, addr, qual, IW_MAX_AP, 1);
545
546 memcpy(extra, &addr, sizeof(struct sockaddr) * data->length);
547 data->flags = 1; /* has quality information */
548 memcpy(extra + sizeof(struct sockaddr) * data->length, &qual,
549 sizeof(struct iw_quality) * data->length);
550
551 kfree(addr);
552 kfree(qual);
553
554 return 0;
555}
556
557
558static int prism2_ioctl_siwrts(struct net_device *dev,
559 struct iw_request_info *info,
560 struct iw_param *rts, char *extra)
561{
562 struct hostap_interface *iface;
563 local_info_t *local;
564 u16 val;
565
566 iface = netdev_priv(dev);
567 local = iface->local;
568
569 if (rts->disabled)
570 val = __constant_cpu_to_le16(2347);
571 else if (rts->value < 0 || rts->value > 2347)
572 return -EINVAL;
573 else
574 val = __cpu_to_le16(rts->value);
575
576 if (local->func->set_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2) ||
577 local->func->reset_port(dev))
578 return -EINVAL;
579
580 local->rts_threshold = rts->value;
581
582 return 0;
583}
584
585static int prism2_ioctl_giwrts(struct net_device *dev,
586 struct iw_request_info *info,
587 struct iw_param *rts, char *extra)
588{
589 struct hostap_interface *iface;
590 local_info_t *local;
591 u16 val;
592
593 iface = netdev_priv(dev);
594 local = iface->local;
595
596 if (local->func->get_rid(dev, HFA384X_RID_RTSTHRESHOLD, &val, 2, 1) <
597 0)
598 return -EINVAL;
599
600 rts->value = __le16_to_cpu(val);
601 rts->disabled = (rts->value == 2347);
602 rts->fixed = 1;
603
604 return 0;
605}
606
607
608static int prism2_ioctl_siwfrag(struct net_device *dev,
609 struct iw_request_info *info,
610 struct iw_param *rts, char *extra)
611{
612 struct hostap_interface *iface;
613 local_info_t *local;
614 u16 val;
615
616 iface = netdev_priv(dev);
617 local = iface->local;
618
619 if (rts->disabled)
620 val = __constant_cpu_to_le16(2346);
621 else if (rts->value < 256 || rts->value > 2346)
622 return -EINVAL;
623 else
624 val = __cpu_to_le16(rts->value & ~0x1); /* even numbers only */
625
626 local->fragm_threshold = rts->value & ~0x1;
627 if (local->func->set_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD, &val,
628 2)
629 || local->func->reset_port(dev))
630 return -EINVAL;
631
632 return 0;
633}
634
635static int prism2_ioctl_giwfrag(struct net_device *dev,
636 struct iw_request_info *info,
637 struct iw_param *rts, char *extra)
638{
639 struct hostap_interface *iface;
640 local_info_t *local;
641 u16 val;
642
643 iface = netdev_priv(dev);
644 local = iface->local;
645
646 if (local->func->get_rid(dev, HFA384X_RID_FRAGMENTATIONTHRESHOLD,
647 &val, 2, 1) < 0)
648 return -EINVAL;
649
650 rts->value = __le16_to_cpu(val);
651 rts->disabled = (rts->value == 2346);
652 rts->fixed = 1;
653
654 return 0;
655}
656
657
658#ifndef PRISM2_NO_STATION_MODES
659static int hostap_join_ap(struct net_device *dev)
660{
661 struct hostap_interface *iface;
662 local_info_t *local;
663 struct hfa384x_join_request req;
664 unsigned long flags;
665 int i;
2e4fd068 666 struct hfa384x_hostscan_result *entry;
ff1d2767
JM
667
668 iface = netdev_priv(dev);
669 local = iface->local;
670
671 memcpy(req.bssid, local->preferred_ap, ETH_ALEN);
672 req.channel = 0;
673
674 spin_lock_irqsave(&local->lock, flags);
675 for (i = 0; i < local->last_scan_results_count; i++) {
676 if (!local->last_scan_results)
677 break;
678 entry = &local->last_scan_results[i];
679 if (memcmp(local->preferred_ap, entry->bssid, ETH_ALEN) == 0) {
680 req.channel = entry->chid;
681 break;
682 }
683 }
684 spin_unlock_irqrestore(&local->lock, flags);
685
686 if (local->func->set_rid(dev, HFA384X_RID_JOINREQUEST, &req,
687 sizeof(req))) {
688 printk(KERN_DEBUG "%s: JoinRequest " MACSTR
689 " failed\n",
690 dev->name, MAC2STR(local->preferred_ap));
691 return -1;
692 }
693
694 printk(KERN_DEBUG "%s: Trying to join BSSID " MACSTR "\n",
695 dev->name, MAC2STR(local->preferred_ap));
696
697 return 0;
698}
699#endif /* PRISM2_NO_STATION_MODES */
700
701
702static int prism2_ioctl_siwap(struct net_device *dev,
703 struct iw_request_info *info,
704 struct sockaddr *ap_addr, char *extra)
705{
706#ifdef PRISM2_NO_STATION_MODES
707 return -EOPNOTSUPP;
708#else /* PRISM2_NO_STATION_MODES */
709 struct hostap_interface *iface;
710 local_info_t *local;
711
712 iface = netdev_priv(dev);
713 local = iface->local;
714
715 memcpy(local->preferred_ap, &ap_addr->sa_data, ETH_ALEN);
716
717 if (local->host_roaming == 1 && local->iw_mode == IW_MODE_INFRA) {
718 struct hfa384x_scan_request scan_req;
719 memset(&scan_req, 0, sizeof(scan_req));
720 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
721 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
722 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST,
723 &scan_req, sizeof(scan_req))) {
724 printk(KERN_DEBUG "%s: ScanResults request failed - "
725 "preferred AP delayed to next unsolicited "
726 "scan\n", dev->name);
727 }
728 } else if (local->host_roaming == 2 &&
729 local->iw_mode == IW_MODE_INFRA) {
730 if (hostap_join_ap(dev))
731 return -EINVAL;
732 } else {
733 printk(KERN_DEBUG "%s: Preferred AP (SIOCSIWAP) is used only "
734 "in Managed mode when host_roaming is enabled\n",
735 dev->name);
736 }
737
738 return 0;
739#endif /* PRISM2_NO_STATION_MODES */
740}
741
742static int prism2_ioctl_giwap(struct net_device *dev,
743 struct iw_request_info *info,
744 struct sockaddr *ap_addr, char *extra)
745{
746 struct hostap_interface *iface;
747 local_info_t *local;
748
749 iface = netdev_priv(dev);
750 local = iface->local;
751
752 ap_addr->sa_family = ARPHRD_ETHER;
753 switch (iface->type) {
754 case HOSTAP_INTERFACE_AP:
755 memcpy(&ap_addr->sa_data, dev->dev_addr, ETH_ALEN);
756 break;
757 case HOSTAP_INTERFACE_STA:
758 memcpy(&ap_addr->sa_data, local->assoc_ap_addr, ETH_ALEN);
759 break;
760 case HOSTAP_INTERFACE_WDS:
761 memcpy(&ap_addr->sa_data, iface->u.wds.remote_addr, ETH_ALEN);
762 break;
763 default:
764 if (local->func->get_rid(dev, HFA384X_RID_CURRENTBSSID,
765 &ap_addr->sa_data, ETH_ALEN, 1) < 0)
766 return -EOPNOTSUPP;
767
768 /* local->bssid is also updated in LinkStatus handler when in
769 * station mode */
770 memcpy(local->bssid, &ap_addr->sa_data, ETH_ALEN);
771 break;
772 }
773
774 return 0;
775}
776
777
778static int prism2_ioctl_siwnickn(struct net_device *dev,
779 struct iw_request_info *info,
780 struct iw_point *data, char *nickname)
781{
782 struct hostap_interface *iface;
783 local_info_t *local;
784
785 iface = netdev_priv(dev);
786 local = iface->local;
787
788 memset(local->name, 0, sizeof(local->name));
789 memcpy(local->name, nickname, data->length);
790 local->name_set = 1;
791
792 if (hostap_set_string(dev, HFA384X_RID_CNFOWNNAME, local->name) ||
793 local->func->reset_port(dev))
794 return -EINVAL;
795
796 return 0;
797}
798
799static int prism2_ioctl_giwnickn(struct net_device *dev,
800 struct iw_request_info *info,
801 struct iw_point *data, char *nickname)
802{
803 struct hostap_interface *iface;
804 local_info_t *local;
805 int len;
806 char name[MAX_NAME_LEN + 3];
807 u16 val;
808
809 iface = netdev_priv(dev);
810 local = iface->local;
811
812 len = local->func->get_rid(dev, HFA384X_RID_CNFOWNNAME,
813 &name, MAX_NAME_LEN + 2, 0);
814 val = __le16_to_cpu(*(u16 *) name);
815 if (len > MAX_NAME_LEN + 2 || len < 0 || val > MAX_NAME_LEN)
816 return -EOPNOTSUPP;
817
818 name[val + 2] = '\0';
819 data->length = val + 1;
820 memcpy(nickname, name + 2, val + 1);
821
822 return 0;
823}
824
825
826static int prism2_ioctl_siwfreq(struct net_device *dev,
827 struct iw_request_info *info,
828 struct iw_freq *freq, char *extra)
829{
830 struct hostap_interface *iface;
831 local_info_t *local;
832
833 iface = netdev_priv(dev);
834 local = iface->local;
835
836 /* freq => chan. */
837 if (freq->e == 1 &&
838 freq->m / 100000 >= freq_list[0] &&
839 freq->m / 100000 <= freq_list[FREQ_COUNT - 1]) {
840 int ch;
841 int fr = freq->m / 100000;
842 for (ch = 0; ch < FREQ_COUNT; ch++) {
843 if (fr == freq_list[ch]) {
844 freq->e = 0;
845 freq->m = ch + 1;
846 break;
847 }
848 }
849 }
850
851 if (freq->e != 0 || freq->m < 1 || freq->m > FREQ_COUNT ||
852 !(local->channel_mask & (1 << (freq->m - 1))))
853 return -EINVAL;
854
855 local->channel = freq->m; /* channel is used in prism2_setup_rids() */
856 if (hostap_set_word(dev, HFA384X_RID_CNFOWNCHANNEL, local->channel) ||
857 local->func->reset_port(dev))
858 return -EINVAL;
859
860 return 0;
861}
862
863static int prism2_ioctl_giwfreq(struct net_device *dev,
864 struct iw_request_info *info,
865 struct iw_freq *freq, char *extra)
866{
867 struct hostap_interface *iface;
868 local_info_t *local;
869 u16 val;
870
871 iface = netdev_priv(dev);
872 local = iface->local;
873
874 if (local->func->get_rid(dev, HFA384X_RID_CURRENTCHANNEL, &val, 2, 1) <
875 0)
876 return -EINVAL;
877
878 le16_to_cpus(&val);
879 if (val < 1 || val > FREQ_COUNT)
880 return -EINVAL;
881
882 freq->m = freq_list[val - 1] * 100000;
883 freq->e = 1;
884
885 return 0;
886}
887
888
889static void hostap_monitor_set_type(local_info_t *local)
890{
891 struct net_device *dev = local->ddev;
892
893 if (dev == NULL)
894 return;
895
896 if (local->monitor_type == PRISM2_MONITOR_PRISM ||
897 local->monitor_type == PRISM2_MONITOR_CAPHDR) {
898 dev->type = ARPHRD_IEEE80211_PRISM;
899 dev->hard_header_parse =
900 hostap_80211_prism_header_parse;
901 } else {
902 dev->type = ARPHRD_IEEE80211;
903 dev->hard_header_parse = hostap_80211_header_parse;
904 }
905}
906
907
908static int prism2_ioctl_siwessid(struct net_device *dev,
909 struct iw_request_info *info,
910 struct iw_point *data, char *ssid)
911{
912 struct hostap_interface *iface;
913 local_info_t *local;
914
915 iface = netdev_priv(dev);
916 local = iface->local;
917
918 if (iface->type == HOSTAP_INTERFACE_WDS)
919 return -EOPNOTSUPP;
920
921 if (data->flags == 0)
922 ssid[0] = '\0'; /* ANY */
923
924 if (local->iw_mode == IW_MODE_MASTER && ssid[0] == '\0') {
925 /* Setting SSID to empty string seems to kill the card in
926 * Host AP mode */
927 printk(KERN_DEBUG "%s: Host AP mode does not support "
928 "'Any' essid\n", dev->name);
929 return -EINVAL;
930 }
931
932 memcpy(local->essid, ssid, data->length);
933 local->essid[data->length] = '\0';
934
935 if ((!local->fw_ap &&
936 hostap_set_string(dev, HFA384X_RID_CNFDESIREDSSID, local->essid))
937 || hostap_set_string(dev, HFA384X_RID_CNFOWNSSID, local->essid) ||
938 local->func->reset_port(dev))
939 return -EINVAL;
940
941 return 0;
942}
943
944static int prism2_ioctl_giwessid(struct net_device *dev,
945 struct iw_request_info *info,
946 struct iw_point *data, char *essid)
947{
948 struct hostap_interface *iface;
949 local_info_t *local;
950 u16 val;
951
952 iface = netdev_priv(dev);
953 local = iface->local;
954
955 if (iface->type == HOSTAP_INTERFACE_WDS)
956 return -EOPNOTSUPP;
957
958 data->flags = 1; /* active */
959 if (local->iw_mode == IW_MODE_MASTER) {
960 data->length = strlen(local->essid);
961 memcpy(essid, local->essid, IW_ESSID_MAX_SIZE);
962 } else {
963 int len;
964 char ssid[MAX_SSID_LEN + 2];
965 memset(ssid, 0, sizeof(ssid));
966 len = local->func->get_rid(dev, HFA384X_RID_CURRENTSSID,
967 &ssid, MAX_SSID_LEN + 2, 0);
968 val = __le16_to_cpu(*(u16 *) ssid);
969 if (len > MAX_SSID_LEN + 2 || len < 0 || val > MAX_SSID_LEN) {
970 return -EOPNOTSUPP;
971 }
972 data->length = val;
973 memcpy(essid, ssid + 2, IW_ESSID_MAX_SIZE);
974 }
975
976 return 0;
977}
978
979
980static int prism2_ioctl_giwrange(struct net_device *dev,
981 struct iw_request_info *info,
982 struct iw_point *data, char *extra)
983{
984 struct hostap_interface *iface;
985 local_info_t *local;
986 struct iw_range *range = (struct iw_range *) extra;
987 u8 rates[10];
988 u16 val;
989 int i, len, over2;
990
991 iface = netdev_priv(dev);
992 local = iface->local;
993
994 data->length = sizeof(struct iw_range);
995 memset(range, 0, sizeof(struct iw_range));
996
997 /* TODO: could fill num_txpower and txpower array with
998 * something; however, there are 128 different values.. */
999
1000 range->txpower_capa = IW_TXPOW_DBM;
1001
1002 if (local->iw_mode == IW_MODE_INFRA || local->iw_mode == IW_MODE_ADHOC)
1003 {
1004 range->min_pmp = 1 * 1024;
1005 range->max_pmp = 65535 * 1024;
1006 range->min_pmt = 1 * 1024;
1007 range->max_pmt = 1000 * 1024;
1008 range->pmp_flags = IW_POWER_PERIOD;
1009 range->pmt_flags = IW_POWER_TIMEOUT;
1010 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT |
1011 IW_POWER_UNICAST_R | IW_POWER_ALL_R;
1012 }
1013
1014 range->we_version_compiled = WIRELESS_EXT;
1015 range->we_version_source = 18;
1016
1017 range->retry_capa = IW_RETRY_LIMIT;
1018 range->retry_flags = IW_RETRY_LIMIT;
1019 range->min_retry = 0;
1020 range->max_retry = 255;
1021
1022 range->num_channels = FREQ_COUNT;
1023
1024 val = 0;
1025 for (i = 0; i < FREQ_COUNT; i++) {
1026 if (local->channel_mask & (1 << i)) {
1027 range->freq[val].i = i + 1;
1028 range->freq[val].m = freq_list[i] * 100000;
1029 range->freq[val].e = 1;
1030 val++;
1031 }
1032 if (val == IW_MAX_FREQUENCIES)
1033 break;
1034 }
1035 range->num_frequency = val;
1036
1037 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1)) {
1038 range->max_qual.qual = 70; /* what is correct max? This was not
1039 * documented exactly. At least
1040 * 69 has been observed. */
1041 range->max_qual.level = 0; /* dB */
1042 range->max_qual.noise = 0; /* dB */
1043
1044 /* What would be suitable values for "average/typical" qual? */
1045 range->avg_qual.qual = 20;
1046 range->avg_qual.level = -60;
1047 range->avg_qual.noise = -95;
1048 } else {
1049 range->max_qual.qual = 92; /* 0 .. 92 */
1050 range->max_qual.level = 154; /* 27 .. 154 */
1051 range->max_qual.noise = 154; /* 27 .. 154 */
1052 }
1053 range->sensitivity = 3;
1054
1055 range->max_encoding_tokens = WEP_KEYS;
1056 range->num_encoding_sizes = 2;
1057 range->encoding_size[0] = 5;
1058 range->encoding_size[1] = 13;
1059
1060 over2 = 0;
1061 len = prism2_get_datarates(dev, rates);
1062 range->num_bitrates = 0;
1063 for (i = 0; i < len; i++) {
1064 if (range->num_bitrates < IW_MAX_BITRATES) {
1065 range->bitrate[range->num_bitrates] =
1066 rates[i] * 500000;
1067 range->num_bitrates++;
1068 }
1069 if (rates[i] == 0x0b || rates[i] == 0x16)
1070 over2 = 1;
1071 }
1072 /* estimated maximum TCP throughput values (bps) */
1073 range->throughput = over2 ? 5500000 : 1500000;
1074
1075 range->min_rts = 0;
1076 range->max_rts = 2347;
1077 range->min_frag = 256;
1078 range->max_frag = 2346;
1079
1080 /* Event capability (kernel + driver) */
1081 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
1082 IW_EVENT_CAPA_MASK(SIOCGIWTHRSPY) |
1083 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
1084 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
1085 range->event_capa[1] = IW_EVENT_CAPA_K_1;
1086 range->event_capa[4] = (IW_EVENT_CAPA_MASK(IWEVTXDROP) |
1087 IW_EVENT_CAPA_MASK(IWEVCUSTOM) |
1088 IW_EVENT_CAPA_MASK(IWEVREGISTERED) |
1089 IW_EVENT_CAPA_MASK(IWEVEXPIRED));
1090
1091 range->enc_capa = IW_ENC_CAPA_WPA | IW_ENC_CAPA_WPA2 |
1092 IW_ENC_CAPA_CIPHER_TKIP | IW_ENC_CAPA_CIPHER_CCMP;
1093
1094 return 0;
1095}
1096
1097
1098static int hostap_monitor_mode_enable(local_info_t *local)
1099{
1100 struct net_device *dev = local->dev;
1101
1102 printk(KERN_DEBUG "Enabling monitor mode\n");
1103 hostap_monitor_set_type(local);
1104
1105 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1106 HFA384X_PORTTYPE_PSEUDO_IBSS)) {
1107 printk(KERN_DEBUG "Port type setting for monitor mode "
1108 "failed\n");
1109 return -EOPNOTSUPP;
1110 }
1111
1112 /* Host decrypt is needed to get the IV and ICV fields;
1113 * however, monitor mode seems to remove WEP flag from frame
1114 * control field */
1115 if (hostap_set_word(dev, HFA384X_RID_CNFWEPFLAGS,
1116 HFA384X_WEPFLAGS_HOSTENCRYPT |
1117 HFA384X_WEPFLAGS_HOSTDECRYPT)) {
1118 printk(KERN_DEBUG "WEP flags setting failed\n");
1119 return -EOPNOTSUPP;
1120 }
1121
1122 if (local->func->reset_port(dev) ||
1123 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1124 (HFA384X_TEST_MONITOR << 8),
1125 0, NULL, NULL)) {
1126 printk(KERN_DEBUG "Setting monitor mode failed\n");
1127 return -EOPNOTSUPP;
1128 }
1129
1130 return 0;
1131}
1132
1133
1134static int hostap_monitor_mode_disable(local_info_t *local)
1135{
1136 struct net_device *dev = local->ddev;
1137
1138 if (dev == NULL)
1139 return -1;
1140
1141 printk(KERN_DEBUG "%s: Disabling monitor mode\n", dev->name);
1142 dev->type = ARPHRD_ETHER;
1143 dev->hard_header_parse = local->saved_eth_header_parse;
1144 if (local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1145 (HFA384X_TEST_STOP << 8),
1146 0, NULL, NULL))
1147 return -1;
1148 return hostap_set_encryption(local);
1149}
1150
1151
1152static int prism2_ioctl_siwmode(struct net_device *dev,
1153 struct iw_request_info *info,
1154 __u32 *mode, char *extra)
1155{
1156 struct hostap_interface *iface;
1157 local_info_t *local;
1158 int double_reset = 0;
1159
1160 iface = netdev_priv(dev);
1161 local = iface->local;
1162
1163 if (*mode != IW_MODE_ADHOC && *mode != IW_MODE_INFRA &&
1164 *mode != IW_MODE_MASTER && *mode != IW_MODE_REPEAT &&
1165 *mode != IW_MODE_MONITOR)
1166 return -EOPNOTSUPP;
1167
1168#ifdef PRISM2_NO_STATION_MODES
1169 if (*mode == IW_MODE_ADHOC || *mode == IW_MODE_INFRA)
1170 return -EOPNOTSUPP;
1171#endif /* PRISM2_NO_STATION_MODES */
1172
1173 if (*mode == local->iw_mode)
1174 return 0;
1175
1176 if (*mode == IW_MODE_MASTER && local->essid[0] == '\0') {
1177 printk(KERN_WARNING "%s: empty SSID not allowed in Master "
1178 "mode\n", dev->name);
1179 return -EINVAL;
1180 }
1181
1182 if (local->iw_mode == IW_MODE_MONITOR)
1183 hostap_monitor_mode_disable(local);
1184
1185 if (local->iw_mode == IW_MODE_ADHOC && *mode == IW_MODE_MASTER) {
1186 /* There seems to be a firmware bug in at least STA f/w v1.5.6
1187 * that leaves beacon frames to use IBSS type when moving from
1188 * IBSS to Host AP mode. Doing double Port0 reset seems to be
1189 * enough to workaround this. */
1190 double_reset = 1;
1191 }
1192
1193 printk(KERN_DEBUG "prism2: %s: operating mode changed "
1194 "%d -> %d\n", dev->name, local->iw_mode, *mode);
1195 local->iw_mode = *mode;
1196
1197 if (local->iw_mode == IW_MODE_MONITOR)
1198 hostap_monitor_mode_enable(local);
1199 else if (local->iw_mode == IW_MODE_MASTER && !local->host_encrypt &&
1200 !local->fw_encrypt_ok) {
1201 printk(KERN_DEBUG "%s: defaulting to host-based encryption as "
1202 "a workaround for firmware bug in Host AP mode WEP\n",
1203 dev->name);
1204 local->host_encrypt = 1;
1205 }
1206
1207 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
1208 hostap_get_porttype(local)))
1209 return -EOPNOTSUPP;
1210
1211 if (local->func->reset_port(dev))
1212 return -EINVAL;
1213 if (double_reset && local->func->reset_port(dev))
1214 return -EINVAL;
1215
1216 if (local->iw_mode != IW_MODE_INFRA && local->iw_mode != IW_MODE_ADHOC)
1217 {
1218 /* netif_carrier is used only in client modes for now, so make
1219 * sure carrier is on when moving to non-client modes. */
1220 netif_carrier_on(local->dev);
1221 netif_carrier_on(local->ddev);
1222 }
1223 return 0;
1224}
1225
1226
1227static int prism2_ioctl_giwmode(struct net_device *dev,
1228 struct iw_request_info *info,
1229 __u32 *mode, char *extra)
1230{
1231 struct hostap_interface *iface;
1232 local_info_t *local;
1233
1234 iface = netdev_priv(dev);
1235 local = iface->local;
1236
1237 switch (iface->type) {
1238 case HOSTAP_INTERFACE_STA:
1239 *mode = IW_MODE_INFRA;
1240 break;
1241 case HOSTAP_INTERFACE_WDS:
1242 *mode = IW_MODE_REPEAT;
1243 break;
1244 default:
1245 *mode = local->iw_mode;
1246 break;
1247 }
1248 return 0;
1249}
1250
1251
1252static int prism2_ioctl_siwpower(struct net_device *dev,
1253 struct iw_request_info *info,
1254 struct iw_param *wrq, char *extra)
1255{
1256#ifdef PRISM2_NO_STATION_MODES
1257 return -EOPNOTSUPP;
1258#else /* PRISM2_NO_STATION_MODES */
1259 int ret = 0;
1260
1261 if (wrq->disabled)
1262 return hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 0);
1263
1264 switch (wrq->flags & IW_POWER_MODE) {
1265 case IW_POWER_UNICAST_R:
1266 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 0);
1267 if (ret)
1268 return ret;
1269 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1270 if (ret)
1271 return ret;
1272 break;
1273 case IW_POWER_ALL_R:
1274 ret = hostap_set_word(dev, HFA384X_RID_CNFMULTICASTRECEIVE, 1);
1275 if (ret)
1276 return ret;
1277 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1278 if (ret)
1279 return ret;
1280 break;
1281 case IW_POWER_ON:
1282 break;
1283 default:
1284 return -EINVAL;
1285 }
1286
1287 if (wrq->flags & IW_POWER_TIMEOUT) {
1288 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1289 if (ret)
1290 return ret;
1291 ret = hostap_set_word(dev, HFA384X_RID_CNFPMHOLDOVERDURATION,
1292 wrq->value / 1024);
1293 if (ret)
1294 return ret;
1295 }
1296 if (wrq->flags & IW_POWER_PERIOD) {
1297 ret = hostap_set_word(dev, HFA384X_RID_CNFPMENABLED, 1);
1298 if (ret)
1299 return ret;
1300 ret = hostap_set_word(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1301 wrq->value / 1024);
1302 if (ret)
1303 return ret;
1304 }
1305
1306 return ret;
1307#endif /* PRISM2_NO_STATION_MODES */
1308}
1309
1310
1311static int prism2_ioctl_giwpower(struct net_device *dev,
1312 struct iw_request_info *info,
1313 struct iw_param *rrq, char *extra)
1314{
1315#ifdef PRISM2_NO_STATION_MODES
1316 return -EOPNOTSUPP;
1317#else /* PRISM2_NO_STATION_MODES */
1318 struct hostap_interface *iface;
1319 local_info_t *local;
1320 u16 enable, mcast;
1321
1322 iface = netdev_priv(dev);
1323 local = iface->local;
1324
1325 if (local->func->get_rid(dev, HFA384X_RID_CNFPMENABLED, &enable, 2, 1)
1326 < 0)
1327 return -EINVAL;
1328
1329 if (!__le16_to_cpu(enable)) {
1330 rrq->disabled = 1;
1331 return 0;
1332 }
1333
1334 rrq->disabled = 0;
1335
1336 if ((rrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
1337 u16 timeout;
1338 if (local->func->get_rid(dev,
1339 HFA384X_RID_CNFPMHOLDOVERDURATION,
1340 &timeout, 2, 1) < 0)
1341 return -EINVAL;
1342
1343 rrq->flags = IW_POWER_TIMEOUT;
1344 rrq->value = __le16_to_cpu(timeout) * 1024;
1345 } else {
1346 u16 period;
1347 if (local->func->get_rid(dev, HFA384X_RID_CNFMAXSLEEPDURATION,
1348 &period, 2, 1) < 0)
1349 return -EINVAL;
1350
1351 rrq->flags = IW_POWER_PERIOD;
1352 rrq->value = __le16_to_cpu(period) * 1024;
1353 }
1354
1355 if (local->func->get_rid(dev, HFA384X_RID_CNFMULTICASTRECEIVE, &mcast,
1356 2, 1) < 0)
1357 return -EINVAL;
1358
1359 if (__le16_to_cpu(mcast))
1360 rrq->flags |= IW_POWER_ALL_R;
1361 else
1362 rrq->flags |= IW_POWER_UNICAST_R;
1363
1364 return 0;
1365#endif /* PRISM2_NO_STATION_MODES */
1366}
1367
1368
1369static int prism2_ioctl_siwretry(struct net_device *dev,
1370 struct iw_request_info *info,
1371 struct iw_param *rrq, char *extra)
1372{
1373 struct hostap_interface *iface;
1374 local_info_t *local;
1375
1376 iface = netdev_priv(dev);
1377 local = iface->local;
1378
1379 if (rrq->disabled)
1380 return -EINVAL;
1381
1382 /* setting retry limits is not supported with the current station
1383 * firmware code; simulate this with alternative retry count for now */
1384 if (rrq->flags == IW_RETRY_LIMIT) {
1385 if (rrq->value < 0) {
1386 /* disable manual retry count setting and use firmware
1387 * defaults */
1388 local->manual_retry_count = -1;
1389 local->tx_control &= ~HFA384X_TX_CTRL_ALT_RTRY;
1390 } else {
1391 if (hostap_set_word(dev, HFA384X_RID_CNFALTRETRYCOUNT,
1392 rrq->value)) {
1393 printk(KERN_DEBUG "%s: Alternate retry count "
1394 "setting to %d failed\n",
1395 dev->name, rrq->value);
1396 return -EOPNOTSUPP;
1397 }
1398
1399 local->manual_retry_count = rrq->value;
1400 local->tx_control |= HFA384X_TX_CTRL_ALT_RTRY;
1401 }
1402 return 0;
1403 }
1404
1405 return -EOPNOTSUPP;
1406
1407#if 0
1408 /* what could be done, if firmware would support this.. */
1409
1410 if (rrq->flags & IW_RETRY_LIMIT) {
1411 if (rrq->flags & IW_RETRY_MAX)
1412 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1413 else if (rrq->flags & IW_RETRY_MIN)
1414 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1415 else {
1416 HFA384X_RID_LONGRETRYLIMIT = rrq->value;
1417 HFA384X_RID_SHORTRETRYLIMIT = rrq->value;
1418 }
1419
1420 }
1421
1422 if (rrq->flags & IW_RETRY_LIFETIME) {
1423 HFA384X_RID_MAXTRANSMITLIFETIME = rrq->value / 1024;
1424 }
1425
1426 return 0;
1427#endif /* 0 */
1428}
1429
1430static int prism2_ioctl_giwretry(struct net_device *dev,
1431 struct iw_request_info *info,
1432 struct iw_param *rrq, char *extra)
1433{
1434 struct hostap_interface *iface;
1435 local_info_t *local;
1436 u16 shortretry, longretry, lifetime, altretry;
1437
1438 iface = netdev_priv(dev);
1439 local = iface->local;
1440
1441 if (local->func->get_rid(dev, HFA384X_RID_SHORTRETRYLIMIT, &shortretry,
1442 2, 1) < 0 ||
1443 local->func->get_rid(dev, HFA384X_RID_LONGRETRYLIMIT, &longretry,
1444 2, 1) < 0 ||
1445 local->func->get_rid(dev, HFA384X_RID_MAXTRANSMITLIFETIME,
1446 &lifetime, 2, 1) < 0)
1447 return -EINVAL;
1448
1449 le16_to_cpus(&shortretry);
1450 le16_to_cpus(&longretry);
1451 le16_to_cpus(&lifetime);
1452
1453 rrq->disabled = 0;
1454
1455 if ((rrq->flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
1456 rrq->flags = IW_RETRY_LIFETIME;
1457 rrq->value = lifetime * 1024;
1458 } else {
1459 if (local->manual_retry_count >= 0) {
1460 rrq->flags = IW_RETRY_LIMIT;
1461 if (local->func->get_rid(dev,
1462 HFA384X_RID_CNFALTRETRYCOUNT,
1463 &altretry, 2, 1) >= 0)
1464 rrq->value = le16_to_cpu(altretry);
1465 else
1466 rrq->value = local->manual_retry_count;
1467 } else if ((rrq->flags & IW_RETRY_MAX)) {
1468 rrq->flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
1469 rrq->value = longretry;
1470 } else {
1471 rrq->flags = IW_RETRY_LIMIT;
1472 rrq->value = shortretry;
1473 if (shortretry != longretry)
1474 rrq->flags |= IW_RETRY_MIN;
1475 }
1476 }
1477 return 0;
1478}
1479
1480
1481/* Note! This TX power controlling is experimental and should not be used in
1482 * production use. It just sets raw power register and does not use any kind of
1483 * feedback information from the measured TX power (CR58). This is now
1484 * commented out to make sure that it is not used by accident. TX power
1485 * configuration will be enabled again after proper algorithm using feedback
1486 * has been implemented. */
1487
1488#ifdef RAW_TXPOWER_SETTING
1489/* Map HFA386x's CR31 to and from dBm with some sort of ad hoc mapping..
1490 * This version assumes following mapping:
1491 * CR31 is 7-bit value with -64 to +63 range.
1492 * -64 is mapped into +20dBm and +63 into -43dBm.
1493 * This is certainly not an exact mapping for every card, but at least
1494 * increasing dBm value should correspond to increasing TX power.
1495 */
1496
1497static int prism2_txpower_hfa386x_to_dBm(u16 val)
1498{
1499 signed char tmp;
1500
1501 if (val > 255)
1502 val = 255;
1503
1504 tmp = val;
1505 tmp >>= 2;
1506
1507 return -12 - tmp;
1508}
1509
1510static u16 prism2_txpower_dBm_to_hfa386x(int val)
1511{
1512 signed char tmp;
1513
1514 if (val > 20)
1515 return 128;
1516 else if (val < -43)
1517 return 127;
1518
1519 tmp = val;
1520 tmp = -12 - tmp;
1521 tmp <<= 2;
1522
1523 return (unsigned char) tmp;
1524}
1525#endif /* RAW_TXPOWER_SETTING */
1526
1527
1528static int prism2_ioctl_siwtxpow(struct net_device *dev,
1529 struct iw_request_info *info,
1530 struct iw_param *rrq, char *extra)
1531{
1532 struct hostap_interface *iface;
1533 local_info_t *local;
1534#ifdef RAW_TXPOWER_SETTING
1535 char *tmp;
1536#endif
1537 u16 val;
1538 int ret = 0;
1539
1540 iface = netdev_priv(dev);
1541 local = iface->local;
1542
1543 if (rrq->disabled) {
1544 if (local->txpower_type != PRISM2_TXPOWER_OFF) {
1545 val = 0xff; /* use all standby and sleep modes */
1546 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1547 HFA386X_CR_A_D_TEST_MODES2,
1548 &val, NULL);
1549 printk(KERN_DEBUG "%s: Turning radio off: %s\n",
1550 dev->name, ret ? "failed" : "OK");
1551 local->txpower_type = PRISM2_TXPOWER_OFF;
1552 }
1553 return (ret ? -EOPNOTSUPP : 0);
1554 }
1555
1556 if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1557 val = 0; /* disable all standby and sleep modes */
1558 ret = local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1559 HFA386X_CR_A_D_TEST_MODES2, &val, NULL);
1560 printk(KERN_DEBUG "%s: Turning radio on: %s\n",
1561 dev->name, ret ? "failed" : "OK");
1562 local->txpower_type = PRISM2_TXPOWER_UNKNOWN;
1563 }
1564
1565#ifdef RAW_TXPOWER_SETTING
1566 if (!rrq->fixed && local->txpower_type != PRISM2_TXPOWER_AUTO) {
1567 printk(KERN_DEBUG "Setting ALC on\n");
1568 val = HFA384X_TEST_CFG_BIT_ALC;
1569 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1570 (HFA384X_TEST_CFG_BITS << 8), 1, &val, NULL);
1571 local->txpower_type = PRISM2_TXPOWER_AUTO;
1572 return 0;
1573 }
1574
1575 if (local->txpower_type != PRISM2_TXPOWER_FIXED) {
1576 printk(KERN_DEBUG "Setting ALC off\n");
1577 val = HFA384X_TEST_CFG_BIT_ALC;
1578 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
1579 (HFA384X_TEST_CFG_BITS << 8), 0, &val, NULL);
1580 local->txpower_type = PRISM2_TXPOWER_FIXED;
1581 }
1582
1583 if (rrq->flags == IW_TXPOW_DBM)
1584 tmp = "dBm";
1585 else if (rrq->flags == IW_TXPOW_MWATT)
1586 tmp = "mW";
1587 else
1588 tmp = "UNKNOWN";
1589 printk(KERN_DEBUG "Setting TX power to %d %s\n", rrq->value, tmp);
1590
1591 if (rrq->flags != IW_TXPOW_DBM) {
1592 printk("SIOCSIWTXPOW with mW is not supported; use dBm\n");
1593 return -EOPNOTSUPP;
1594 }
1595
1596 local->txpower = rrq->value;
1597 val = prism2_txpower_dBm_to_hfa386x(local->txpower);
1598 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF,
1599 HFA386X_CR_MANUAL_TX_POWER, &val, NULL))
1600 ret = -EOPNOTSUPP;
1601#else /* RAW_TXPOWER_SETTING */
1602 if (rrq->fixed)
1603 ret = -EOPNOTSUPP;
1604#endif /* RAW_TXPOWER_SETTING */
1605
1606 return ret;
1607}
1608
1609static int prism2_ioctl_giwtxpow(struct net_device *dev,
1610 struct iw_request_info *info,
1611 struct iw_param *rrq, char *extra)
1612{
1613#ifdef RAW_TXPOWER_SETTING
1614 struct hostap_interface *iface;
1615 local_info_t *local;
1616 u16 resp0;
1617
1618 iface = netdev_priv(dev);
1619 local = iface->local;
1620
1621 rrq->flags = IW_TXPOW_DBM;
1622 rrq->disabled = 0;
1623 rrq->fixed = 0;
1624
1625 if (local->txpower_type == PRISM2_TXPOWER_AUTO) {
1626 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF,
1627 HFA386X_CR_MANUAL_TX_POWER,
1628 NULL, &resp0) == 0) {
1629 rrq->value = prism2_txpower_hfa386x_to_dBm(resp0);
1630 } else {
1631 /* Could not get real txpower; guess 15 dBm */
1632 rrq->value = 15;
1633 }
1634 } else if (local->txpower_type == PRISM2_TXPOWER_OFF) {
1635 rrq->value = 0;
1636 rrq->disabled = 1;
1637 } else if (local->txpower_type == PRISM2_TXPOWER_FIXED) {
1638 rrq->value = local->txpower;
1639 rrq->fixed = 1;
1640 } else {
1641 printk("SIOCGIWTXPOW - unknown txpower_type=%d\n",
1642 local->txpower_type);
1643 }
1644 return 0;
1645#else /* RAW_TXPOWER_SETTING */
1646 return -EOPNOTSUPP;
1647#endif /* RAW_TXPOWER_SETTING */
1648}
1649
1650
1651#ifndef PRISM2_NO_STATION_MODES
1652
1653/* HostScan request works with and without host_roaming mode. In addition, it
1654 * does not break current association. However, it requires newer station
1655 * firmware version (>= 1.3.1) than scan request. */
1656static int prism2_request_hostscan(struct net_device *dev,
1657 u8 *ssid, u8 ssid_len)
1658{
1659 struct hostap_interface *iface;
1660 local_info_t *local;
1661 struct hfa384x_hostscan_request scan_req;
1662
1663 iface = netdev_priv(dev);
1664 local = iface->local;
1665
1666 memset(&scan_req, 0, sizeof(scan_req));
72ca9c61
JM
1667 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1668 local->scan_channel_mask);
ff1d2767
JM
1669 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1670 if (ssid) {
1671 if (ssid_len > 32)
1672 return -EINVAL;
1673 scan_req.target_ssid_len = cpu_to_le16(ssid_len);
1674 memcpy(scan_req.target_ssid, ssid, ssid_len);
1675 }
1676
1677 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
1678 sizeof(scan_req))) {
1679 printk(KERN_DEBUG "%s: HOSTSCAN failed\n", dev->name);
1680 return -EINVAL;
1681 }
1682 return 0;
1683}
1684
1685
1686static int prism2_request_scan(struct net_device *dev)
1687{
1688 struct hostap_interface *iface;
1689 local_info_t *local;
1690 struct hfa384x_scan_request scan_req;
1691 int ret = 0;
1692
1693 iface = netdev_priv(dev);
1694 local = iface->local;
1695
1696 memset(&scan_req, 0, sizeof(scan_req));
72ca9c61
JM
1697 scan_req.channel_list = cpu_to_le16(local->channel_mask &
1698 local->scan_channel_mask);
ff1d2767
JM
1699 scan_req.txrate = __constant_cpu_to_le16(HFA384X_RATES_1MBPS);
1700
1701 /* FIX:
1702 * It seems to be enough to set roaming mode for a short moment to
1703 * host-based and then setup scanrequest data and return the mode to
1704 * firmware-based.
1705 *
1706 * Master mode would need to drop to Managed mode for a short while
1707 * to make scanning work.. Or sweep through the different channels and
1708 * use passive scan based on beacons. */
1709
1710 if (!local->host_roaming)
1711 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1712 HFA384X_ROAMING_HOST);
1713
1714 if (local->func->set_rid(dev, HFA384X_RID_SCANREQUEST, &scan_req,
1715 sizeof(scan_req))) {
1716 printk(KERN_DEBUG "SCANREQUEST failed\n");
1717 ret = -EINVAL;
1718 }
1719
1720 if (!local->host_roaming)
1721 hostap_set_word(dev, HFA384X_RID_CNFROAMINGMODE,
1722 HFA384X_ROAMING_FIRMWARE);
1723
1724 return 0;
1725}
1726
1727#else /* !PRISM2_NO_STATION_MODES */
1728
1729static inline int prism2_request_hostscan(struct net_device *dev,
1730 u8 *ssid, u8 ssid_len)
1731{
1732 return -EOPNOTSUPP;
1733}
1734
1735
1736static inline int prism2_request_scan(struct net_device *dev)
1737{
1738 return -EOPNOTSUPP;
1739}
1740
1741#endif /* !PRISM2_NO_STATION_MODES */
1742
1743
1744static int prism2_ioctl_siwscan(struct net_device *dev,
1745 struct iw_request_info *info,
1746 struct iw_point *data, char *extra)
1747{
1748 struct hostap_interface *iface;
1749 local_info_t *local;
1750 int ret;
1751 u8 *ssid = NULL, ssid_len = 0;
1752 struct iw_scan_req *req = (struct iw_scan_req *) extra;
1753
1754 iface = netdev_priv(dev);
1755 local = iface->local;
1756
1757 if (data->length < sizeof(struct iw_scan_req))
1758 req = NULL;
1759
1760 if (local->iw_mode == IW_MODE_MASTER) {
1761 /* In master mode, we just return the results of our local
1762 * tables, so we don't need to start anything...
1763 * Jean II */
1764 data->length = 0;
1765 return 0;
1766 }
1767
1768 if (!local->dev_enabled)
1769 return -ENETDOWN;
1770
1771 if (req && data->flags & IW_SCAN_THIS_ESSID) {
1772 ssid = req->essid;
1773 ssid_len = req->essid_len;
1774
1775 if (ssid_len &&
1776 ((local->iw_mode != IW_MODE_INFRA &&
1777 local->iw_mode != IW_MODE_ADHOC) ||
1778 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1))))
1779 return -EOPNOTSUPP;
1780 }
1781
1782 if (local->sta_fw_ver >= PRISM2_FW_VER(1,3,1))
1783 ret = prism2_request_hostscan(dev, ssid, ssid_len);
1784 else
1785 ret = prism2_request_scan(dev);
1786
1787 if (ret == 0)
1788 local->scan_timestamp = jiffies;
1789
1790 /* Could inquire F101, F103 or wait for SIOCGIWSCAN and read RID */
1791
1792 return ret;
1793}
1794
1795
1796#ifndef PRISM2_NO_STATION_MODES
1797static char * __prism2_translate_scan(local_info_t *local,
2e4fd068
JM
1798 struct hfa384x_hostscan_result *scan,
1799 struct hostap_bss_info *bss,
ff1d2767
JM
1800 char *current_ev, char *end_buf)
1801{
1802 int i, chan;
1803 struct iw_event iwe;
1804 char *current_val;
1805 u16 capabilities;
1806 u8 *pos;
2e4fd068 1807 u8 *ssid, *bssid;
ff1d2767
JM
1808 size_t ssid_len;
1809 char *buf;
1810
1811 if (bss) {
1812 ssid = bss->ssid;
1813 ssid_len = bss->ssid_len;
2e4fd068 1814 bssid = bss->bssid;
ff1d2767 1815 } else {
2e4fd068
JM
1816 ssid = scan->ssid;
1817 ssid_len = le16_to_cpu(scan->ssid_len);
1818 bssid = scan->bssid;
ff1d2767
JM
1819 }
1820 if (ssid_len > 32)
1821 ssid_len = 32;
1822
1823 /* First entry *MUST* be the AP MAC address */
1824 memset(&iwe, 0, sizeof(iwe));
1825 iwe.cmd = SIOCGIWAP;
1826 iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
1827 memcpy(iwe.u.ap_addr.sa_data, bssid, ETH_ALEN);
1828 /* FIX:
1829 * I do not know how this is possible, but iwe_stream_add_event
1830 * seems to re-order memcpy execution so that len is set only
1831 * after copying.. Pre-setting len here "fixes" this, but real
1832 * problems should be solved (after which these iwe.len
1833 * settings could be removed from this function). */
1834 iwe.len = IW_EV_ADDR_LEN;
1835 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1836 IW_EV_ADDR_LEN);
1837
1838 /* Other entries will be displayed in the order we give them */
1839
1840 memset(&iwe, 0, sizeof(iwe));
1841 iwe.cmd = SIOCGIWESSID;
1842 iwe.u.data.length = ssid_len;
1843 iwe.u.data.flags = 1;
1844 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1845 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, ssid);
1846
1847 memset(&iwe, 0, sizeof(iwe));
1848 iwe.cmd = SIOCGIWMODE;
1849 if (bss) {
1850 capabilities = bss->capab_info;
1851 } else {
2e4fd068 1852 capabilities = le16_to_cpu(scan->capability);
ff1d2767
JM
1853 }
1854 if (capabilities & (WLAN_CAPABILITY_ESS |
1855 WLAN_CAPABILITY_IBSS)) {
1856 if (capabilities & WLAN_CAPABILITY_ESS)
1857 iwe.u.mode = IW_MODE_MASTER;
1858 else
1859 iwe.u.mode = IW_MODE_ADHOC;
1860 iwe.len = IW_EV_UINT_LEN;
1861 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1862 IW_EV_UINT_LEN);
1863 }
1864
1865 memset(&iwe, 0, sizeof(iwe));
1866 iwe.cmd = SIOCGIWFREQ;
2e4fd068
JM
1867 if (scan) {
1868 chan = scan->chid;
ff1d2767
JM
1869 } else if (bss) {
1870 chan = bss->chan;
1871 } else {
1872 chan = 0;
1873 }
1874
1875 if (chan > 0) {
1876 iwe.u.freq.m = freq_list[le16_to_cpu(chan - 1)] * 100000;
1877 iwe.u.freq.e = 1;
1878 iwe.len = IW_EV_FREQ_LEN;
1879 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1880 IW_EV_FREQ_LEN);
1881 }
1882
2e4fd068 1883 if (scan) {
ff1d2767
JM
1884 memset(&iwe, 0, sizeof(iwe));
1885 iwe.cmd = IWEVQUAL;
2e4fd068
JM
1886 if (local->last_scan_type == PRISM2_HOSTSCAN) {
1887 iwe.u.qual.level = le16_to_cpu(scan->sl);
1888 iwe.u.qual.noise = le16_to_cpu(scan->anl);
ff1d2767
JM
1889 } else {
1890 iwe.u.qual.level =
1891 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->sl));
1892 iwe.u.qual.noise =
1893 HFA384X_LEVEL_TO_dBm(le16_to_cpu(scan->anl));
1894 }
1895 iwe.len = IW_EV_QUAL_LEN;
1896 current_ev = iwe_stream_add_event(current_ev, end_buf, &iwe,
1897 IW_EV_QUAL_LEN);
1898 }
1899
1900 memset(&iwe, 0, sizeof(iwe));
1901 iwe.cmd = SIOCGIWENCODE;
1902 if (capabilities & WLAN_CAPABILITY_PRIVACY)
1903 iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
1904 else
1905 iwe.u.data.flags = IW_ENCODE_DISABLED;
1906 iwe.u.data.length = 0;
1907 iwe.len = IW_EV_POINT_LEN + iwe.u.data.length;
1908 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe, "");
1909
1910 /* TODO: add SuppRates into BSS table */
2e4fd068 1911 if (scan) {
ff1d2767
JM
1912 memset(&iwe, 0, sizeof(iwe));
1913 iwe.cmd = SIOCGIWRATE;
1914 current_val = current_ev + IW_EV_LCP_LEN;
2e4fd068 1915 pos = scan->sup_rates;
ff1d2767
JM
1916 for (i = 0; i < sizeof(scan->sup_rates); i++) {
1917 if (pos[i] == 0)
1918 break;
1919 /* Bit rate given in 500 kb/s units (+ 0x80) */
1920 iwe.u.bitrate.value = ((pos[i] & 0x7f) * 500000);
1921 current_val = iwe_stream_add_value(
1922 current_ev, current_val, end_buf, &iwe,
1923 IW_EV_PARAM_LEN);
1924 }
1925 /* Check if we added any event */
1926 if ((current_val - current_ev) > IW_EV_LCP_LEN)
1927 current_ev = current_val;
1928 }
1929
1930 /* TODO: add BeaconInt,resp_rate,atim into BSS table */
1931 buf = kmalloc(MAX_WPA_IE_LEN * 2 + 30, GFP_KERNEL);
2e4fd068 1932 if (buf && scan) {
ff1d2767
JM
1933 memset(&iwe, 0, sizeof(iwe));
1934 iwe.cmd = IWEVCUSTOM;
2e4fd068 1935 sprintf(buf, "bcn_int=%d", le16_to_cpu(scan->beacon_interval));
ff1d2767
JM
1936 iwe.u.data.length = strlen(buf);
1937 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1938 buf);
1939
1940 memset(&iwe, 0, sizeof(iwe));
1941 iwe.cmd = IWEVCUSTOM;
2e4fd068 1942 sprintf(buf, "resp_rate=%d", le16_to_cpu(scan->rate));
ff1d2767
JM
1943 iwe.u.data.length = strlen(buf);
1944 current_ev = iwe_stream_add_point(current_ev, end_buf, &iwe,
1945 buf);
1946
2e4fd068
JM
1947 if (local->last_scan_type == PRISM2_HOSTSCAN &&
1948 (capabilities & WLAN_CAPABILITY_IBSS)) {
ff1d2767
JM
1949 memset(&iwe, 0, sizeof(iwe));
1950 iwe.cmd = IWEVCUSTOM;
2e4fd068 1951 sprintf(buf, "atim=%d", le16_to_cpu(scan->atim));
ff1d2767
JM
1952 iwe.u.data.length = strlen(buf);
1953 current_ev = iwe_stream_add_point(current_ev, end_buf,
1954 &iwe, buf);
1955 }
1956 }
1957 kfree(buf);
1958
1959 if (bss && bss->wpa_ie_len > 0 && bss->wpa_ie_len <= MAX_WPA_IE_LEN) {
1960 memset(&iwe, 0, sizeof(iwe));
1961 iwe.cmd = IWEVGENIE;
1962 iwe.u.data.length = bss->wpa_ie_len;
1963 current_ev = iwe_stream_add_point(
1964 current_ev, end_buf, &iwe, bss->wpa_ie);
1965 }
1966
1967 if (bss && bss->rsn_ie_len > 0 && bss->rsn_ie_len <= MAX_WPA_IE_LEN) {
1968 memset(&iwe, 0, sizeof(iwe));
1969 iwe.cmd = IWEVGENIE;
1970 iwe.u.data.length = bss->rsn_ie_len;
1971 current_ev = iwe_stream_add_point(
1972 current_ev, end_buf, &iwe, bss->rsn_ie);
1973 }
1974
1975 return current_ev;
1976}
1977
1978
1979/* Translate scan data returned from the card to a card independant
1980 * format that the Wireless Tools will understand - Jean II */
1981static inline int prism2_translate_scan(local_info_t *local,
1982 char *buffer, int buflen)
1983{
2e4fd068
JM
1984 struct hfa384x_hostscan_result *scan;
1985 int entry, hostscan;
ff1d2767
JM
1986 char *current_ev = buffer;
1987 char *end_buf = buffer + buflen;
ff1d2767
JM
1988 struct list_head *ptr;
1989
1990 spin_lock_bh(&local->lock);
1991
1992 list_for_each(ptr, &local->bss_list) {
1993 struct hostap_bss_info *bss;
1994 bss = list_entry(ptr, struct hostap_bss_info, list);
1995 bss->included = 0;
1996 }
1997
1998 hostscan = local->last_scan_type == PRISM2_HOSTSCAN;
2e4fd068 1999 for (entry = 0; entry < local->last_scan_results_count; entry++) {
ff1d2767
JM
2000 int found = 0;
2001 scan = &local->last_scan_results[entry];
ff1d2767
JM
2002
2003 /* Report every SSID if the AP is using multiple SSIDs. If no
2004 * BSS record is found (e.g., when WPA mode is disabled),
2005 * report the AP once. */
2006 list_for_each(ptr, &local->bss_list) {
2007 struct hostap_bss_info *bss;
2008 bss = list_entry(ptr, struct hostap_bss_info, list);
2e4fd068 2009 if (memcmp(bss->bssid, scan->bssid, ETH_ALEN) == 0) {
ff1d2767
JM
2010 bss->included = 1;
2011 current_ev = __prism2_translate_scan(
2e4fd068 2012 local, scan, bss, current_ev, end_buf);
ff1d2767
JM
2013 found++;
2014 }
2015 }
2016 if (!found) {
2017 current_ev = __prism2_translate_scan(
2e4fd068 2018 local, scan, NULL, current_ev, end_buf);
ff1d2767
JM
2019 }
2020 /* Check if there is space for one more entry */
2021 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2022 /* Ask user space to try again with a bigger buffer */
2023 spin_unlock_bh(&local->lock);
2024 return -E2BIG;
2025 }
2026 }
2027
2028 /* Prism2 firmware has limits (32 at least in some versions) for number
2029 * of BSSes in scan results. Extend this limit by using local BSS list.
2030 */
2031 list_for_each(ptr, &local->bss_list) {
2032 struct hostap_bss_info *bss;
2033 bss = list_entry(ptr, struct hostap_bss_info, list);
2034 if (bss->included)
2035 continue;
2e4fd068
JM
2036 current_ev = __prism2_translate_scan(local, NULL, bss,
2037 current_ev, end_buf);
ff1d2767
JM
2038 /* Check if there is space for one more entry */
2039 if ((end_buf - current_ev) <= IW_EV_ADDR_LEN) {
2040 /* Ask user space to try again with a bigger buffer */
2041 spin_unlock_bh(&local->lock);
2042 return -E2BIG;
2043 }
2044 }
2045
2046 spin_unlock_bh(&local->lock);
2047
2048 return current_ev - buffer;
2049}
2050#endif /* PRISM2_NO_STATION_MODES */
2051
2052
2053static inline int prism2_ioctl_giwscan_sta(struct net_device *dev,
2054 struct iw_request_info *info,
2055 struct iw_point *data, char *extra)
2056{
2057#ifdef PRISM2_NO_STATION_MODES
2058 return -EOPNOTSUPP;
2059#else /* PRISM2_NO_STATION_MODES */
2060 struct hostap_interface *iface;
2061 local_info_t *local;
2062 int res;
2063
2064 iface = netdev_priv(dev);
2065 local = iface->local;
2066
2067 /* Wait until the scan is finished. We can probably do better
2068 * than that - Jean II */
2069 if (local->scan_timestamp &&
2070 time_before(jiffies, local->scan_timestamp + 3 * HZ)) {
2071 /* Important note : we don't want to block the caller
2072 * until results are ready for various reasons.
2073 * First, managing wait queues is complex and racy
2074 * (there may be multiple simultaneous callers).
2075 * Second, we grab some rtnetlink lock before comming
2076 * here (in dev_ioctl()).
2077 * Third, the caller can wait on the Wireless Event
2078 * - Jean II */
2079 return -EAGAIN;
2080 }
2081 local->scan_timestamp = 0;
2082
2083 res = prism2_translate_scan(local, extra, data->length);
2084
2085 if (res >= 0) {
2086 data->length = res;
2087 return 0;
2088 } else {
2089 data->length = 0;
2090 return res;
2091 }
2092#endif /* PRISM2_NO_STATION_MODES */
2093}
2094
2095
2096static int prism2_ioctl_giwscan(struct net_device *dev,
2097 struct iw_request_info *info,
2098 struct iw_point *data, char *extra)
2099{
2100 struct hostap_interface *iface;
2101 local_info_t *local;
2102 int res;
2103
2104 iface = netdev_priv(dev);
2105 local = iface->local;
2106
2107 if (local->iw_mode == IW_MODE_MASTER) {
2108 /* In MASTER mode, it doesn't make sense to go around
2109 * scanning the frequencies and make the stations we serve
2110 * wait when what the user is really interested about is the
2111 * list of stations and access points we are talking to.
2112 * So, just extract results from our cache...
2113 * Jean II */
2114
2115 /* Translate to WE format */
2116 res = prism2_ap_translate_scan(dev, extra);
2117 if (res >= 0) {
2118 printk(KERN_DEBUG "Scan result translation succeeded "
2119 "(length=%d)\n", res);
2120 data->length = res;
2121 return 0;
2122 } else {
2123 printk(KERN_DEBUG
2124 "Scan result translation failed (res=%d)\n",
2125 res);
2126 data->length = 0;
2127 return res;
2128 }
2129 } else {
2130 /* Station mode */
2131 return prism2_ioctl_giwscan_sta(dev, info, data, extra);
2132 }
2133}
2134
2135
2136static const struct iw_priv_args prism2_priv[] = {
2137 { PRISM2_IOCTL_MONITOR,
2138 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor" },
2139 { PRISM2_IOCTL_READMIF,
2140 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2141 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "readmif" },
2142 { PRISM2_IOCTL_WRITEMIF,
2143 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 2, 0, "writemif" },
2144 { PRISM2_IOCTL_RESET,
2145 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "reset" },
2146 { PRISM2_IOCTL_INQUIRE,
2147 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "inquire" },
2148 { PRISM2_IOCTL_SET_RID_WORD,
2149 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "set_rid_word" },
2150 { PRISM2_IOCTL_MACCMD,
2151 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "maccmd" },
2152 { PRISM2_IOCTL_WDS_ADD,
2153 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_add" },
2154 { PRISM2_IOCTL_WDS_DEL,
2155 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "wds_del" },
2156 { PRISM2_IOCTL_ADDMAC,
2157 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "addmac" },
2158 { PRISM2_IOCTL_DELMAC,
2159 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "delmac" },
2160 { PRISM2_IOCTL_KICKMAC,
2161 IW_PRIV_TYPE_ADDR | IW_PRIV_SIZE_FIXED | 1, 0, "kickmac" },
2162 /* --- raw access to sub-ioctls --- */
2163 { PRISM2_IOCTL_PRISM2_PARAM,
2164 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "prism2_param" },
2165 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2166 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
2167 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprism2_param" },
2168 /* --- sub-ioctls handlers --- */
2169 { PRISM2_IOCTL_PRISM2_PARAM,
2170 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "" },
2171 { PRISM2_IOCTL_GET_PRISM2_PARAM,
2172 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "" },
2173 /* --- sub-ioctls definitions --- */
2174 { PRISM2_PARAM_TXRATECTRL,
2175 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "txratectrl" },
2176 { PRISM2_PARAM_TXRATECTRL,
2177 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettxratectrl" },
2178 { PRISM2_PARAM_BEACON_INT,
2179 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "beacon_int" },
2180 { PRISM2_PARAM_BEACON_INT,
2181 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbeacon_int" },
2182#ifndef PRISM2_NO_STATION_MODES
2183 { PRISM2_PARAM_PSEUDO_IBSS,
2184 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "pseudo_ibss" },
2185 { PRISM2_PARAM_PSEUDO_IBSS,
2186 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getpseudo_ibss" },
2187#endif /* PRISM2_NO_STATION_MODES */
2188 { PRISM2_PARAM_ALC,
2189 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "alc" },
2190 { PRISM2_PARAM_ALC,
2191 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getalc" },
2192 { PRISM2_PARAM_DUMP,
2193 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dump" },
2194 { PRISM2_PARAM_DUMP,
2195 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdump" },
2196 { PRISM2_PARAM_OTHER_AP_POLICY,
2197 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "other_ap_policy" },
2198 { PRISM2_PARAM_OTHER_AP_POLICY,
2199 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getother_ap_pol" },
2200 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2201 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_inactivity" },
2202 { PRISM2_PARAM_AP_MAX_INACTIVITY,
2203 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_inactivi" },
2204 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2205 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bridge_packets" },
2206 { PRISM2_PARAM_AP_BRIDGE_PACKETS,
2207 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbridge_packe" },
2208 { PRISM2_PARAM_DTIM_PERIOD,
2209 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "dtim_period" },
2210 { PRISM2_PARAM_DTIM_PERIOD,
2211 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdtim_period" },
2212 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2213 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "nullfunc_ack" },
2214 { PRISM2_PARAM_AP_NULLFUNC_ACK,
2215 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getnullfunc_ack" },
2216 { PRISM2_PARAM_MAX_WDS,
2217 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "max_wds" },
2218 { PRISM2_PARAM_MAX_WDS,
2219 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmax_wds" },
2220 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2221 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "autom_ap_wds" },
2222 { PRISM2_PARAM_AP_AUTOM_AP_WDS,
2223 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getautom_ap_wds" },
2224 { PRISM2_PARAM_AP_AUTH_ALGS,
2225 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_auth_algs" },
2226 { PRISM2_PARAM_AP_AUTH_ALGS,
2227 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_auth_algs" },
2228 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2229 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "allow_fcserr" },
2230 { PRISM2_PARAM_MONITOR_ALLOW_FCSERR,
2231 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getallow_fcserr" },
2232 { PRISM2_PARAM_HOST_ENCRYPT,
2233 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_encrypt" },
2234 { PRISM2_PARAM_HOST_ENCRYPT,
2235 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_encrypt" },
2236 { PRISM2_PARAM_HOST_DECRYPT,
2237 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_decrypt" },
2238 { PRISM2_PARAM_HOST_DECRYPT,
2239 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_decrypt" },
2240 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2241 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_rx" },
2242 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX,
2243 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_rx" },
2244 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2245 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "busmaster_tx" },
2246 { PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX,
2247 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbusmaster_tx" },
2248#ifndef PRISM2_NO_STATION_MODES
2249 { PRISM2_PARAM_HOST_ROAMING,
2250 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "host_roaming" },
2251 { PRISM2_PARAM_HOST_ROAMING,
2252 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethost_roaming" },
2253#endif /* PRISM2_NO_STATION_MODES */
2254 { PRISM2_PARAM_BCRX_STA_KEY,
2255 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "bcrx_sta_key" },
2256 { PRISM2_PARAM_BCRX_STA_KEY,
2257 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbcrx_sta_key" },
2258 { PRISM2_PARAM_IEEE_802_1X,
2259 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ieee_802_1x" },
2260 { PRISM2_PARAM_IEEE_802_1X,
2261 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getieee_802_1x" },
2262 { PRISM2_PARAM_ANTSEL_TX,
2263 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_tx" },
2264 { PRISM2_PARAM_ANTSEL_TX,
2265 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_tx" },
2266 { PRISM2_PARAM_ANTSEL_RX,
2267 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "antsel_rx" },
2268 { PRISM2_PARAM_ANTSEL_RX,
2269 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getantsel_rx" },
2270 { PRISM2_PARAM_MONITOR_TYPE,
2271 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "monitor_type" },
2272 { PRISM2_PARAM_MONITOR_TYPE,
2273 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getmonitor_type" },
2274 { PRISM2_PARAM_WDS_TYPE,
2275 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wds_type" },
2276 { PRISM2_PARAM_WDS_TYPE,
2277 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwds_type" },
2278 { PRISM2_PARAM_HOSTSCAN,
2279 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostscan" },
2280 { PRISM2_PARAM_HOSTSCAN,
2281 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostscan" },
2282 { PRISM2_PARAM_AP_SCAN,
2283 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "ap_scan" },
2284 { PRISM2_PARAM_AP_SCAN,
2285 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getap_scan" },
2286 { PRISM2_PARAM_ENH_SEC,
2287 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "enh_sec" },
2288 { PRISM2_PARAM_ENH_SEC,
2289 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getenh_sec" },
2290#ifdef PRISM2_IO_DEBUG
2291 { PRISM2_PARAM_IO_DEBUG,
2292 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "io_debug" },
2293 { PRISM2_PARAM_IO_DEBUG,
2294 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getio_debug" },
2295#endif /* PRISM2_IO_DEBUG */
2296 { PRISM2_PARAM_BASIC_RATES,
2297 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "basic_rates" },
2298 { PRISM2_PARAM_BASIC_RATES,
2299 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getbasic_rates" },
2300 { PRISM2_PARAM_OPER_RATES,
2301 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "oper_rates" },
2302 { PRISM2_PARAM_OPER_RATES,
2303 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getoper_rates" },
2304 { PRISM2_PARAM_HOSTAPD,
2305 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd" },
2306 { PRISM2_PARAM_HOSTAPD,
2307 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd" },
2308 { PRISM2_PARAM_HOSTAPD_STA,
2309 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "hostapd_sta" },
2310 { PRISM2_PARAM_HOSTAPD_STA,
2311 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gethostapd_sta" },
2312 { PRISM2_PARAM_WPA,
2313 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "wpa" },
2314 { PRISM2_PARAM_WPA,
2315 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getwpa" },
2316 { PRISM2_PARAM_PRIVACY_INVOKED,
2317 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "privacy_invoked" },
2318 { PRISM2_PARAM_PRIVACY_INVOKED,
2319 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getprivacy_invo" },
2320 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2321 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "tkip_countermea" },
2322 { PRISM2_PARAM_TKIP_COUNTERMEASURES,
2323 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "gettkip_counter" },
2324 { PRISM2_PARAM_DROP_UNENCRYPTED,
2325 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "drop_unencrypte" },
2326 { PRISM2_PARAM_DROP_UNENCRYPTED,
2327 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getdrop_unencry" },
72ca9c61
JM
2328 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2329 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "scan_channels" },
2330 { PRISM2_PARAM_SCAN_CHANNEL_MASK,
2331 0, IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, "getscan_channel" },
ff1d2767
JM
2332};
2333
2334
2335static int prism2_ioctl_priv_inquire(struct net_device *dev, int *i)
2336{
2337 struct hostap_interface *iface;
2338 local_info_t *local;
2339
2340 iface = netdev_priv(dev);
2341 local = iface->local;
2342
2343 if (local->func->cmd(dev, HFA384X_CMDCODE_INQUIRE, *i, NULL, NULL))
2344 return -EOPNOTSUPP;
2345
2346 return 0;
2347}
2348
2349
2350static int prism2_ioctl_priv_prism2_param(struct net_device *dev,
2351 struct iw_request_info *info,
2352 void *wrqu, char *extra)
2353{
2354 struct hostap_interface *iface;
2355 local_info_t *local;
2356 int *i = (int *) extra;
2357 int param = *i;
2358 int value = *(i + 1);
2359 int ret = 0;
2360 u16 val;
2361
2362 iface = netdev_priv(dev);
2363 local = iface->local;
2364
2365 switch (param) {
2366 case PRISM2_PARAM_TXRATECTRL:
2367 local->fw_tx_rate_control = value;
2368 break;
2369
2370 case PRISM2_PARAM_BEACON_INT:
2371 if (hostap_set_word(dev, HFA384X_RID_CNFBEACONINT, value) ||
2372 local->func->reset_port(dev))
2373 ret = -EINVAL;
2374 else
2375 local->beacon_int = value;
2376 break;
2377
2378#ifndef PRISM2_NO_STATION_MODES
2379 case PRISM2_PARAM_PSEUDO_IBSS:
2380 if (value == local->pseudo_adhoc)
2381 break;
2382
2383 if (value != 0 && value != 1) {
2384 ret = -EINVAL;
2385 break;
2386 }
2387
2388 printk(KERN_DEBUG "prism2: %s: pseudo IBSS change %d -> %d\n",
2389 dev->name, local->pseudo_adhoc, value);
2390 local->pseudo_adhoc = value;
2391 if (local->iw_mode != IW_MODE_ADHOC)
2392 break;
2393
2394 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2395 hostap_get_porttype(local))) {
2396 ret = -EOPNOTSUPP;
2397 break;
2398 }
2399
2400 if (local->func->reset_port(dev))
2401 ret = -EINVAL;
2402 break;
2403#endif /* PRISM2_NO_STATION_MODES */
2404
2405 case PRISM2_PARAM_ALC:
2406 printk(KERN_DEBUG "%s: %s ALC\n", dev->name,
2407 value == 0 ? "Disabling" : "Enabling");
2408 val = HFA384X_TEST_CFG_BIT_ALC;
2409 local->func->cmd(dev, HFA384X_CMDCODE_TEST |
2410 (HFA384X_TEST_CFG_BITS << 8),
2411 value == 0 ? 0 : 1, &val, NULL);
2412 break;
2413
2414 case PRISM2_PARAM_DUMP:
2415 local->frame_dump = value;
2416 break;
2417
2418 case PRISM2_PARAM_OTHER_AP_POLICY:
2419 if (value < 0 || value > 3) {
2420 ret = -EINVAL;
2421 break;
2422 }
2423 if (local->ap != NULL)
2424 local->ap->ap_policy = value;
2425 break;
2426
2427 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2428 if (value < 0 || value > 7 * 24 * 60 * 60) {
2429 ret = -EINVAL;
2430 break;
2431 }
2432 if (local->ap != NULL)
2433 local->ap->max_inactivity = value * HZ;
2434 break;
2435
2436 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2437 if (local->ap != NULL)
2438 local->ap->bridge_packets = value;
2439 break;
2440
2441 case PRISM2_PARAM_DTIM_PERIOD:
2442 if (value < 0 || value > 65535) {
2443 ret = -EINVAL;
2444 break;
2445 }
2446 if (hostap_set_word(dev, HFA384X_RID_CNFOWNDTIMPERIOD, value)
2447 || local->func->reset_port(dev))
2448 ret = -EINVAL;
2449 else
2450 local->dtim_period = value;
2451 break;
2452
2453 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2454 if (local->ap != NULL)
2455 local->ap->nullfunc_ack = value;
2456 break;
2457
2458 case PRISM2_PARAM_MAX_WDS:
2459 local->wds_max_connections = value;
2460 break;
2461
2462 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2463 if (local->ap != NULL) {
2464 if (!local->ap->autom_ap_wds && value) {
2465 /* add WDS link to all APs in STA table */
2466 hostap_add_wds_links(local);
2467 }
2468 local->ap->autom_ap_wds = value;
2469 }
2470 break;
2471
2472 case PRISM2_PARAM_AP_AUTH_ALGS:
2473 local->auth_algs = value;
2474 if (hostap_set_auth_algs(local))
2475 ret = -EINVAL;
2476 break;
2477
2478 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2479 local->monitor_allow_fcserr = value;
2480 break;
2481
2482 case PRISM2_PARAM_HOST_ENCRYPT:
2483 local->host_encrypt = value;
2484 if (hostap_set_encryption(local) ||
2485 local->func->reset_port(dev))
2486 ret = -EINVAL;
2487 break;
2488
2489 case PRISM2_PARAM_HOST_DECRYPT:
2490 local->host_decrypt = value;
2491 if (hostap_set_encryption(local) ||
2492 local->func->reset_port(dev))
2493 ret = -EINVAL;
2494 break;
2495
2496 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2497 local->bus_master_threshold_rx = value;
2498 break;
2499
2500 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2501 local->bus_master_threshold_tx = value;
2502 break;
2503
2504#ifndef PRISM2_NO_STATION_MODES
2505 case PRISM2_PARAM_HOST_ROAMING:
2506 if (value < 0 || value > 2) {
2507 ret = -EINVAL;
2508 break;
2509 }
2510 local->host_roaming = value;
2511 if (hostap_set_roaming(local) || local->func->reset_port(dev))
2512 ret = -EINVAL;
2513 break;
2514#endif /* PRISM2_NO_STATION_MODES */
2515
2516 case PRISM2_PARAM_BCRX_STA_KEY:
2517 local->bcrx_sta_key = value;
2518 break;
2519
2520 case PRISM2_PARAM_IEEE_802_1X:
2521 local->ieee_802_1x = value;
2522 break;
2523
2524 case PRISM2_PARAM_ANTSEL_TX:
2525 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2526 ret = -EINVAL;
2527 break;
2528 }
2529 local->antsel_tx = value;
2530 hostap_set_antsel(local);
2531 break;
2532
2533 case PRISM2_PARAM_ANTSEL_RX:
2534 if (value < 0 || value > HOSTAP_ANTSEL_HIGH) {
2535 ret = -EINVAL;
2536 break;
2537 }
2538 local->antsel_rx = value;
2539 hostap_set_antsel(local);
2540 break;
2541
2542 case PRISM2_PARAM_MONITOR_TYPE:
2543 if (value != PRISM2_MONITOR_80211 &&
2544 value != PRISM2_MONITOR_CAPHDR &&
2545 value != PRISM2_MONITOR_PRISM) {
2546 ret = -EINVAL;
2547 break;
2548 }
2549 local->monitor_type = value;
2550 if (local->iw_mode == IW_MODE_MONITOR)
2551 hostap_monitor_set_type(local);
2552 break;
2553
2554 case PRISM2_PARAM_WDS_TYPE:
2555 local->wds_type = value;
2556 break;
2557
2558 case PRISM2_PARAM_HOSTSCAN:
2559 {
2560 struct hfa384x_hostscan_request scan_req;
2561 u16 rate;
2562
2563 memset(&scan_req, 0, sizeof(scan_req));
2564 scan_req.channel_list = __constant_cpu_to_le16(0x3fff);
2565 switch (value) {
2566 case 1: rate = HFA384X_RATES_1MBPS; break;
2567 case 2: rate = HFA384X_RATES_2MBPS; break;
2568 case 3: rate = HFA384X_RATES_5MBPS; break;
2569 case 4: rate = HFA384X_RATES_11MBPS; break;
2570 default: rate = HFA384X_RATES_1MBPS; break;
2571 }
2572 scan_req.txrate = cpu_to_le16(rate);
2573 /* leave SSID empty to accept all SSIDs */
2574
2575 if (local->iw_mode == IW_MODE_MASTER) {
2576 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2577 HFA384X_PORTTYPE_BSS) ||
2578 local->func->reset_port(dev))
2579 printk(KERN_DEBUG "Leaving Host AP mode "
2580 "for HostScan failed\n");
2581 }
2582
2583 if (local->func->set_rid(dev, HFA384X_RID_HOSTSCAN, &scan_req,
2584 sizeof(scan_req))) {
2585 printk(KERN_DEBUG "HOSTSCAN failed\n");
2586 ret = -EINVAL;
2587 }
2588 if (local->iw_mode == IW_MODE_MASTER) {
2589 wait_queue_t __wait;
2590 init_waitqueue_entry(&__wait, current);
2591 add_wait_queue(&local->hostscan_wq, &__wait);
2592 set_current_state(TASK_INTERRUPTIBLE);
2593 schedule_timeout(HZ);
2594 if (signal_pending(current))
2595 ret = -EINTR;
2596 set_current_state(TASK_RUNNING);
2597 remove_wait_queue(&local->hostscan_wq, &__wait);
2598
2599 if (hostap_set_word(dev, HFA384X_RID_CNFPORTTYPE,
2600 HFA384X_PORTTYPE_HOSTAP) ||
2601 local->func->reset_port(dev))
2602 printk(KERN_DEBUG "Returning to Host AP mode "
2603 "after HostScan failed\n");
2604 }
2605 break;
2606 }
2607
2608 case PRISM2_PARAM_AP_SCAN:
2609 local->passive_scan_interval = value;
2610 if (timer_pending(&local->passive_scan_timer))
2611 del_timer(&local->passive_scan_timer);
2612 if (value > 0) {
2613 local->passive_scan_timer.expires = jiffies +
2614 local->passive_scan_interval * HZ;
2615 add_timer(&local->passive_scan_timer);
2616 }
2617 break;
2618
2619 case PRISM2_PARAM_ENH_SEC:
2620 if (value < 0 || value > 3) {
2621 ret = -EINVAL;
2622 break;
2623 }
2624 local->enh_sec = value;
2625 if (hostap_set_word(dev, HFA384X_RID_CNFENHSECURITY,
2626 local->enh_sec) ||
2627 local->func->reset_port(dev)) {
2628 printk(KERN_INFO "%s: cnfEnhSecurity requires STA f/w "
2629 "1.6.3 or newer\n", dev->name);
2630 ret = -EOPNOTSUPP;
2631 }
2632 break;
2633
2634#ifdef PRISM2_IO_DEBUG
2635 case PRISM2_PARAM_IO_DEBUG:
2636 local->io_debug_enabled = value;
2637 break;
2638#endif /* PRISM2_IO_DEBUG */
2639
2640 case PRISM2_PARAM_BASIC_RATES:
2641 if ((value & local->tx_rate_control) != value || value == 0) {
2642 printk(KERN_INFO "%s: invalid basic rate set - basic "
2643 "rates must be in supported rate set\n",
2644 dev->name);
2645 ret = -EINVAL;
2646 break;
2647 }
2648 local->basic_rates = value;
2649 if (hostap_set_word(dev, HFA384X_RID_CNFBASICRATES,
2650 local->basic_rates) ||
2651 local->func->reset_port(dev))
2652 ret = -EINVAL;
2653 break;
2654
2655 case PRISM2_PARAM_OPER_RATES:
2656 local->tx_rate_control = value;
2657 if (hostap_set_rate(dev))
2658 ret = -EINVAL;
2659 break;
2660
2661 case PRISM2_PARAM_HOSTAPD:
2662 ret = hostap_set_hostapd(local, value, 1);
2663 break;
2664
2665 case PRISM2_PARAM_HOSTAPD_STA:
2666 ret = hostap_set_hostapd_sta(local, value, 1);
2667 break;
2668
2669 case PRISM2_PARAM_WPA:
2670 local->wpa = value;
2671 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2672 ret = -EOPNOTSUPP;
2673 else if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
2674 value ? 1 : 0))
2675 ret = -EINVAL;
2676 break;
2677
2678 case PRISM2_PARAM_PRIVACY_INVOKED:
2679 local->privacy_invoked = value;
2680 if (hostap_set_encryption(local) ||
2681 local->func->reset_port(dev))
2682 ret = -EINVAL;
2683 break;
2684
2685 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2686 local->tkip_countermeasures = value;
2687 break;
2688
2689 case PRISM2_PARAM_DROP_UNENCRYPTED:
2690 local->drop_unencrypted = value;
2691 break;
2692
72ca9c61
JM
2693 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2694 local->scan_channel_mask = value;
2695 break;
2696
ff1d2767
JM
2697 default:
2698 printk(KERN_DEBUG "%s: prism2_param: unknown param %d\n",
2699 dev->name, param);
2700 ret = -EOPNOTSUPP;
2701 break;
2702 }
2703
2704 return ret;
2705}
2706
2707
2708static int prism2_ioctl_priv_get_prism2_param(struct net_device *dev,
2709 struct iw_request_info *info,
2710 void *wrqu, char *extra)
2711{
2712 struct hostap_interface *iface;
2713 local_info_t *local;
2714 int *param = (int *) extra;
2715 int ret = 0;
2716
2717 iface = netdev_priv(dev);
2718 local = iface->local;
2719
2720 switch (*param) {
2721 case PRISM2_PARAM_TXRATECTRL:
2722 *param = local->fw_tx_rate_control;
2723 break;
2724
2725 case PRISM2_PARAM_BEACON_INT:
2726 *param = local->beacon_int;
2727 break;
2728
2729 case PRISM2_PARAM_PSEUDO_IBSS:
2730 *param = local->pseudo_adhoc;
2731 break;
2732
2733 case PRISM2_PARAM_ALC:
2734 ret = -EOPNOTSUPP; /* FIX */
2735 break;
2736
2737 case PRISM2_PARAM_DUMP:
2738 *param = local->frame_dump;
2739 break;
2740
2741 case PRISM2_PARAM_OTHER_AP_POLICY:
2742 if (local->ap != NULL)
2743 *param = local->ap->ap_policy;
2744 else
2745 ret = -EOPNOTSUPP;
2746 break;
2747
2748 case PRISM2_PARAM_AP_MAX_INACTIVITY:
2749 if (local->ap != NULL)
2750 *param = local->ap->max_inactivity / HZ;
2751 else
2752 ret = -EOPNOTSUPP;
2753 break;
2754
2755 case PRISM2_PARAM_AP_BRIDGE_PACKETS:
2756 if (local->ap != NULL)
2757 *param = local->ap->bridge_packets;
2758 else
2759 ret = -EOPNOTSUPP;
2760 break;
2761
2762 case PRISM2_PARAM_DTIM_PERIOD:
2763 *param = local->dtim_period;
2764 break;
2765
2766 case PRISM2_PARAM_AP_NULLFUNC_ACK:
2767 if (local->ap != NULL)
2768 *param = local->ap->nullfunc_ack;
2769 else
2770 ret = -EOPNOTSUPP;
2771 break;
2772
2773 case PRISM2_PARAM_MAX_WDS:
2774 *param = local->wds_max_connections;
2775 break;
2776
2777 case PRISM2_PARAM_AP_AUTOM_AP_WDS:
2778 if (local->ap != NULL)
2779 *param = local->ap->autom_ap_wds;
2780 else
2781 ret = -EOPNOTSUPP;
2782 break;
2783
2784 case PRISM2_PARAM_AP_AUTH_ALGS:
2785 *param = local->auth_algs;
2786 break;
2787
2788 case PRISM2_PARAM_MONITOR_ALLOW_FCSERR:
2789 *param = local->monitor_allow_fcserr;
2790 break;
2791
2792 case PRISM2_PARAM_HOST_ENCRYPT:
2793 *param = local->host_encrypt;
2794 break;
2795
2796 case PRISM2_PARAM_HOST_DECRYPT:
2797 *param = local->host_decrypt;
2798 break;
2799
2800 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_RX:
2801 *param = local->bus_master_threshold_rx;
2802 break;
2803
2804 case PRISM2_PARAM_BUS_MASTER_THRESHOLD_TX:
2805 *param = local->bus_master_threshold_tx;
2806 break;
2807
2808 case PRISM2_PARAM_HOST_ROAMING:
2809 *param = local->host_roaming;
2810 break;
2811
2812 case PRISM2_PARAM_BCRX_STA_KEY:
2813 *param = local->bcrx_sta_key;
2814 break;
2815
2816 case PRISM2_PARAM_IEEE_802_1X:
2817 *param = local->ieee_802_1x;
2818 break;
2819
2820 case PRISM2_PARAM_ANTSEL_TX:
2821 *param = local->antsel_tx;
2822 break;
2823
2824 case PRISM2_PARAM_ANTSEL_RX:
2825 *param = local->antsel_rx;
2826 break;
2827
2828 case PRISM2_PARAM_MONITOR_TYPE:
2829 *param = local->monitor_type;
2830 break;
2831
2832 case PRISM2_PARAM_WDS_TYPE:
2833 *param = local->wds_type;
2834 break;
2835
2836 case PRISM2_PARAM_HOSTSCAN:
2837 ret = -EOPNOTSUPP;
2838 break;
2839
2840 case PRISM2_PARAM_AP_SCAN:
2841 *param = local->passive_scan_interval;
2842 break;
2843
2844 case PRISM2_PARAM_ENH_SEC:
2845 *param = local->enh_sec;
2846 break;
2847
2848#ifdef PRISM2_IO_DEBUG
2849 case PRISM2_PARAM_IO_DEBUG:
2850 *param = local->io_debug_enabled;
2851 break;
2852#endif /* PRISM2_IO_DEBUG */
2853
2854 case PRISM2_PARAM_BASIC_RATES:
2855 *param = local->basic_rates;
2856 break;
2857
2858 case PRISM2_PARAM_OPER_RATES:
2859 *param = local->tx_rate_control;
2860 break;
2861
2862 case PRISM2_PARAM_HOSTAPD:
2863 *param = local->hostapd;
2864 break;
2865
2866 case PRISM2_PARAM_HOSTAPD_STA:
2867 *param = local->hostapd_sta;
2868 break;
2869
2870 case PRISM2_PARAM_WPA:
2871 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
2872 ret = -EOPNOTSUPP;
2873 *param = local->wpa;
2874 break;
2875
2876 case PRISM2_PARAM_PRIVACY_INVOKED:
2877 *param = local->privacy_invoked;
2878 break;
2879
2880 case PRISM2_PARAM_TKIP_COUNTERMEASURES:
2881 *param = local->tkip_countermeasures;
2882 break;
2883
2884 case PRISM2_PARAM_DROP_UNENCRYPTED:
2885 *param = local->drop_unencrypted;
2886 break;
2887
72ca9c61
JM
2888 case PRISM2_PARAM_SCAN_CHANNEL_MASK:
2889 *param = local->scan_channel_mask;
2890 break;
2891
ff1d2767
JM
2892 default:
2893 printk(KERN_DEBUG "%s: get_prism2_param: unknown param %d\n",
2894 dev->name, *param);
2895 ret = -EOPNOTSUPP;
2896 break;
2897 }
2898
2899 return ret;
2900}
2901
2902
2903static int prism2_ioctl_priv_readmif(struct net_device *dev,
2904 struct iw_request_info *info,
2905 void *wrqu, char *extra)
2906{
2907 struct hostap_interface *iface;
2908 local_info_t *local;
2909 u16 resp0;
2910
2911 iface = netdev_priv(dev);
2912 local = iface->local;
2913
2914 if (local->func->cmd(dev, HFA384X_CMDCODE_READMIF, *extra, NULL,
2915 &resp0))
2916 return -EOPNOTSUPP;
2917 else
2918 *extra = resp0;
2919
2920 return 0;
2921}
2922
2923
2924static int prism2_ioctl_priv_writemif(struct net_device *dev,
2925 struct iw_request_info *info,
2926 void *wrqu, char *extra)
2927{
2928 struct hostap_interface *iface;
2929 local_info_t *local;
2930 u16 cr, val;
2931
2932 iface = netdev_priv(dev);
2933 local = iface->local;
2934
2935 cr = *extra;
2936 val = *(extra + 1);
2937 if (local->func->cmd(dev, HFA384X_CMDCODE_WRITEMIF, cr, &val, NULL))
2938 return -EOPNOTSUPP;
2939
2940 return 0;
2941}
2942
2943
2944static int prism2_ioctl_priv_monitor(struct net_device *dev, int *i)
2945{
2946 struct hostap_interface *iface;
2947 local_info_t *local;
2948 int ret = 0;
2949 u32 mode;
2950
2951 iface = netdev_priv(dev);
2952 local = iface->local;
2953
2954 printk(KERN_DEBUG "%s: process %d (%s) used deprecated iwpriv monitor "
2955 "- update software to use iwconfig mode monitor\n",
2956 dev->name, current->pid, current->comm);
2957
2958 /* Backward compatibility code - this can be removed at some point */
2959
2960 if (*i == 0) {
2961 /* Disable monitor mode - old mode was not saved, so go to
2962 * Master mode */
2963 mode = IW_MODE_MASTER;
2964 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2965 } else if (*i == 1) {
2966 /* netlink socket mode is not supported anymore since it did
2967 * not separate different devices from each other and was not
2968 * best method for delivering large amount of packets to
2969 * user space */
2970 ret = -EOPNOTSUPP;
2971 } else if (*i == 2 || *i == 3) {
2972 switch (*i) {
2973 case 2:
2974 local->monitor_type = PRISM2_MONITOR_80211;
2975 break;
2976 case 3:
2977 local->monitor_type = PRISM2_MONITOR_PRISM;
2978 break;
2979 }
2980 mode = IW_MODE_MONITOR;
2981 ret = prism2_ioctl_siwmode(dev, NULL, &mode, NULL);
2982 hostap_monitor_mode_enable(local);
2983 } else
2984 ret = -EINVAL;
2985
2986 return ret;
2987}
2988
2989
2990static int prism2_ioctl_priv_reset(struct net_device *dev, int *i)
2991{
2992 struct hostap_interface *iface;
2993 local_info_t *local;
2994
2995 iface = netdev_priv(dev);
2996 local = iface->local;
2997
2998 printk(KERN_DEBUG "%s: manual reset request(%d)\n", dev->name, *i);
2999 switch (*i) {
3000 case 0:
3001 /* Disable and enable card */
3002 local->func->hw_shutdown(dev, 1);
3003 local->func->hw_config(dev, 0);
3004 break;
3005
3006 case 1:
3007 /* COR sreset */
3008 local->func->hw_reset(dev);
3009 break;
3010
3011 case 2:
3012 /* Disable and enable port 0 */
3013 local->func->reset_port(dev);
3014 break;
3015
3016 case 3:
3017 prism2_sta_deauth(local, WLAN_REASON_DEAUTH_LEAVING);
3018 if (local->func->cmd(dev, HFA384X_CMDCODE_DISABLE, 0, NULL,
3019 NULL))
3020 return -EINVAL;
3021 break;
3022
3023 case 4:
3024 if (local->func->cmd(dev, HFA384X_CMDCODE_ENABLE, 0, NULL,
3025 NULL))
3026 return -EINVAL;
3027 break;
3028
3029 default:
3030 printk(KERN_DEBUG "Unknown reset request %d\n", *i);
3031 return -EOPNOTSUPP;
3032 }
3033
3034 return 0;
3035}
3036
3037
3038static int prism2_ioctl_priv_set_rid_word(struct net_device *dev, int *i)
3039{
3040 int rid = *i;
3041 int value = *(i + 1);
3042
3043 printk(KERN_DEBUG "%s: Set RID[0x%X] = %d\n", dev->name, rid, value);
3044
3045 if (hostap_set_word(dev, rid, value))
3046 return -EINVAL;
3047
3048 return 0;
3049}
3050
3051
3052#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
3053static int ap_mac_cmd_ioctl(local_info_t *local, int *cmd)
3054{
3055 int ret = 0;
3056
3057 switch (*cmd) {
3058 case AP_MAC_CMD_POLICY_OPEN:
3059 local->ap->mac_restrictions.policy = MAC_POLICY_OPEN;
3060 break;
3061 case AP_MAC_CMD_POLICY_ALLOW:
3062 local->ap->mac_restrictions.policy = MAC_POLICY_ALLOW;
3063 break;
3064 case AP_MAC_CMD_POLICY_DENY:
3065 local->ap->mac_restrictions.policy = MAC_POLICY_DENY;
3066 break;
3067 case AP_MAC_CMD_FLUSH:
3068 ap_control_flush_macs(&local->ap->mac_restrictions);
3069 break;
3070 case AP_MAC_CMD_KICKALL:
3071 ap_control_kickall(local->ap);
3072 hostap_deauth_all_stas(local->dev, local->ap, 0);
3073 break;
3074 default:
3075 ret = -EOPNOTSUPP;
3076 break;
3077 }
3078
3079 return ret;
3080}
3081#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
3082
3083
3084#ifdef PRISM2_DOWNLOAD_SUPPORT
3085static int prism2_ioctl_priv_download(local_info_t *local, struct iw_point *p)
3086{
3087 struct prism2_download_param *param;
3088 int ret = 0;
3089
3090 if (p->length < sizeof(struct prism2_download_param) ||
3091 p->length > 1024 || !p->pointer)
3092 return -EINVAL;
3093
3094 param = (struct prism2_download_param *)
3095 kmalloc(p->length, GFP_KERNEL);
3096 if (param == NULL)
3097 return -ENOMEM;
3098
3099 if (copy_from_user(param, p->pointer, p->length)) {
3100 ret = -EFAULT;
3101 goto out;
3102 }
3103
3104 if (p->length < sizeof(struct prism2_download_param) +
3105 param->num_areas * sizeof(struct prism2_download_area)) {
3106 ret = -EINVAL;
3107 goto out;
3108 }
3109
3110 ret = local->func->download(local, param);
3111
3112 out:
3113 if (param != NULL)
3114 kfree(param);
3115
3116 return ret;
3117}
3118#endif /* PRISM2_DOWNLOAD_SUPPORT */
3119
3120
3121static int prism2_set_genericelement(struct net_device *dev, u8 *elem,
3122 size_t len)
3123{
3124 struct hostap_interface *iface = dev->priv;
3125 local_info_t *local = iface->local;
3126 u8 *buf;
3127
3128 /*
3129 * Add 16-bit length in the beginning of the buffer because Prism2 RID
3130 * includes it.
3131 */
3132 buf = kmalloc(len + 2, GFP_KERNEL);
3133 if (buf == NULL)
3134 return -ENOMEM;
3135
3136 *((u16 *) buf) = cpu_to_le16(len);
3137 memcpy(buf + 2, elem, len);
3138
3139 kfree(local->generic_elem);
3140 local->generic_elem = buf;
3141 local->generic_elem_len = len + 2;
3142
3143 return local->func->set_rid(local->dev, HFA384X_RID_GENERICELEMENT,
3144 buf, len + 2);
3145}
3146
3147
3148static int prism2_ioctl_siwauth(struct net_device *dev,
3149 struct iw_request_info *info,
3150 struct iw_param *data, char *extra)
3151{
3152 struct hostap_interface *iface = dev->priv;
3153 local_info_t *local = iface->local;
3154
3155 switch (data->flags & IW_AUTH_INDEX) {
3156 case IW_AUTH_WPA_VERSION:
3157 case IW_AUTH_CIPHER_PAIRWISE:
3158 case IW_AUTH_CIPHER_GROUP:
3159 case IW_AUTH_KEY_MGMT:
3160 /*
3161 * Host AP driver does not use these parameters and allows
3162 * wpa_supplicant to control them internally.
3163 */
3164 break;
3165 case IW_AUTH_TKIP_COUNTERMEASURES:
3166 local->tkip_countermeasures = data->value;
3167 break;
3168 case IW_AUTH_DROP_UNENCRYPTED:
3169 local->drop_unencrypted = data->value;
3170 break;
3171 case IW_AUTH_80211_AUTH_ALG:
3172 local->auth_algs = data->value;
3173 break;
3174 case IW_AUTH_WPA_ENABLED:
3175 if (data->value == 0) {
3176 local->wpa = 0;
3177 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3178 break;
3179 prism2_set_genericelement(dev, "", 0);
3180 local->host_roaming = 0;
3181 local->privacy_invoked = 0;
3182 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE,
3183 0) ||
3184 hostap_set_roaming(local) ||
3185 hostap_set_encryption(local) ||
3186 local->func->reset_port(dev))
3187 return -EINVAL;
3188 break;
3189 }
3190 if (local->sta_fw_ver < PRISM2_FW_VER(1,7,0))
3191 return -EOPNOTSUPP;
3192 local->host_roaming = 2;
3193 local->privacy_invoked = 1;
3194 local->wpa = 1;
3195 if (hostap_set_word(dev, HFA384X_RID_SSNHANDLINGMODE, 1) ||
3196 hostap_set_roaming(local) ||
3197 hostap_set_encryption(local) ||
3198 local->func->reset_port(dev))
3199 return -EINVAL;
3200 break;
3201 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3202 local->ieee_802_1x = data->value;
3203 break;
3204 case IW_AUTH_PRIVACY_INVOKED:
3205 local->privacy_invoked = data->value;
3206 break;
3207 default:
3208 return -EOPNOTSUPP;
3209 }
3210 return 0;
3211}
3212
3213
3214static int prism2_ioctl_giwauth(struct net_device *dev,
3215 struct iw_request_info *info,
3216 struct iw_param *data, char *extra)
3217{
3218 struct hostap_interface *iface = dev->priv;
3219 local_info_t *local = iface->local;
3220
3221 switch (data->flags & IW_AUTH_INDEX) {
3222 case IW_AUTH_WPA_VERSION:
3223 case IW_AUTH_CIPHER_PAIRWISE:
3224 case IW_AUTH_CIPHER_GROUP:
3225 case IW_AUTH_KEY_MGMT:
3226 /*
3227 * Host AP driver does not use these parameters and allows
3228 * wpa_supplicant to control them internally.
3229 */
3230 return -EOPNOTSUPP;
3231 case IW_AUTH_TKIP_COUNTERMEASURES:
3232 data->value = local->tkip_countermeasures;
3233 break;
3234 case IW_AUTH_DROP_UNENCRYPTED:
3235 data->value = local->drop_unencrypted;
3236 break;
3237 case IW_AUTH_80211_AUTH_ALG:
3238 data->value = local->auth_algs;
3239 break;
3240 case IW_AUTH_WPA_ENABLED:
3241 data->value = local->wpa;
3242 break;
3243 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
3244 data->value = local->ieee_802_1x;
3245 break;
3246 default:
3247 return -EOPNOTSUPP;
3248 }
3249 return 0;
3250}
3251
3252
3253static int prism2_ioctl_siwencodeext(struct net_device *dev,
3254 struct iw_request_info *info,
3255 struct iw_point *erq, char *extra)
3256{
3257 struct hostap_interface *iface = dev->priv;
3258 local_info_t *local = iface->local;
3259 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3260 int i, ret = 0;
3261 struct hostap_crypto_ops *ops;
3262 struct prism2_crypt_data **crypt;
3263 void *sta_ptr;
3264 u8 *addr;
3265 const char *alg, *module;
3266
3267 i = erq->flags & IW_ENCODE_INDEX;
3268 if (i > WEP_KEYS)
3269 return -EINVAL;
3270 if (i < 1 || i > WEP_KEYS)
3271 i = local->tx_keyidx;
3272 else
3273 i--;
3274 if (i < 0 || i >= WEP_KEYS)
3275 return -EINVAL;
3276
3277 addr = ext->addr.sa_data;
3278 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3279 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3280 sta_ptr = NULL;
3281 crypt = &local->crypt[i];
3282 } else {
3283 if (i != 0)
3284 return -EINVAL;
3285 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3286 if (sta_ptr == NULL) {
3287 if (local->iw_mode == IW_MODE_INFRA) {
3288 /*
3289 * TODO: add STA entry for the current AP so
3290 * that unicast key can be used. For now, this
3291 * is emulated by using default key idx 0.
3292 */
3293 i = 0;
3294 crypt = &local->crypt[i];
3295 } else
3296 return -EINVAL;
3297 }
3298 }
3299
3300 if ((erq->flags & IW_ENCODE_DISABLED) ||
3301 ext->alg == IW_ENCODE_ALG_NONE) {
3302 if (*crypt)
3303 prism2_crypt_delayed_deinit(local, crypt);
3304 goto done;
3305 }
3306
3307 switch (ext->alg) {
3308 case IW_ENCODE_ALG_WEP:
3309 alg = "WEP";
3310 module = "hostap_crypt_wep";
3311 break;
3312 case IW_ENCODE_ALG_TKIP:
3313 alg = "TKIP";
3314 module = "hostap_crypt_tkip";
3315 break;
3316 case IW_ENCODE_ALG_CCMP:
3317 alg = "CCMP";
3318 module = "hostap_crypt_ccmp";
3319 break;
3320 default:
3321 printk(KERN_DEBUG "%s: unsupported algorithm %d\n",
3322 local->dev->name, ext->alg);
3323 ret = -EOPNOTSUPP;
3324 goto done;
3325 }
3326
3327 ops = hostap_get_crypto_ops(alg);
3328 if (ops == NULL) {
3329 request_module(module);
3330 ops = hostap_get_crypto_ops(alg);
3331 }
3332 if (ops == NULL) {
3333 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3334 local->dev->name, alg);
3335 ret = -EOPNOTSUPP;
3336 goto done;
3337 }
3338
3339 if (sta_ptr || ext->alg != IW_ENCODE_ALG_WEP) {
3340 /*
3341 * Per station encryption and other than WEP algorithms
3342 * require host-based encryption, so force them on
3343 * automatically.
3344 */
3345 local->host_decrypt = local->host_encrypt = 1;
3346 }
3347
3348 if (*crypt == NULL || (*crypt)->ops != ops) {
3349 struct prism2_crypt_data *new_crypt;
3350
3351 prism2_crypt_delayed_deinit(local, crypt);
3352
3353 new_crypt = (struct prism2_crypt_data *)
3354 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
3355 if (new_crypt == NULL) {
3356 ret = -ENOMEM;
3357 goto done;
3358 }
3359 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
3360 new_crypt->ops = ops;
3361 new_crypt->priv = new_crypt->ops->init(i);
3362 if (new_crypt->priv == NULL) {
3363 kfree(new_crypt);
3364 ret = -EINVAL;
3365 goto done;
3366 }
3367
3368 *crypt = new_crypt;
3369 }
3370
3371 /*
3372 * TODO: if ext_flags does not have IW_ENCODE_EXT_RX_SEQ_VALID, the
3373 * existing seq# should not be changed.
3374 * TODO: if ext_flags has IW_ENCODE_EXT_TX_SEQ_VALID, next TX seq#
3375 * should be changed to something else than zero.
3376 */
3377 if ((!(ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) || ext->key_len > 0)
3378 && (*crypt)->ops->set_key &&
3379 (*crypt)->ops->set_key(ext->key, ext->key_len, ext->rx_seq,
3380 (*crypt)->priv) < 0) {
3381 printk(KERN_DEBUG "%s: key setting failed\n",
3382 local->dev->name);
3383 ret = -EINVAL;
3384 goto done;
3385 }
3386
3387 if (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY) {
3388 if (!sta_ptr)
3389 local->tx_keyidx = i;
3390 else if (i) {
3391 ret = -EINVAL;
3392 goto done;
3393 }
3394 }
3395
3396
3397 if (sta_ptr == NULL && ext->key_len > 0) {
3398 int first = 1, j;
3399 for (j = 0; j < WEP_KEYS; j++) {
3400 if (j != i && local->crypt[j]) {
3401 first = 0;
3402 break;
3403 }
3404 }
3405 if (first)
3406 local->tx_keyidx = i;
3407 }
3408
3409 done:
3410 if (sta_ptr)
3411 hostap_handle_sta_release(sta_ptr);
3412
3413 local->open_wep = erq->flags & IW_ENCODE_OPEN;
3414
3415 /*
3416 * Do not reset port0 if card is in Managed mode since resetting will
3417 * generate new IEEE 802.11 authentication which may end up in looping
3418 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3419 * after WEP configuration. However, keys are apparently changed at
3420 * least in Managed mode.
3421 */
3422 if (ret == 0 &&
3423 (hostap_set_encryption(local) ||
3424 (local->iw_mode != IW_MODE_INFRA &&
3425 local->func->reset_port(local->dev))))
3426 ret = -EINVAL;
3427
3428 return ret;
3429}
3430
3431
3432static int prism2_ioctl_giwencodeext(struct net_device *dev,
3433 struct iw_request_info *info,
3434 struct iw_point *erq, char *extra)
3435{
3436 struct hostap_interface *iface = dev->priv;
3437 local_info_t *local = iface->local;
3438 struct prism2_crypt_data **crypt;
3439 void *sta_ptr;
3440 int max_key_len, i;
3441 struct iw_encode_ext *ext = (struct iw_encode_ext *) extra;
3442 u8 *addr;
3443
3444 max_key_len = erq->length - sizeof(*ext);
3445 if (max_key_len < 0)
3446 return -EINVAL;
3447
3448 i = erq->flags & IW_ENCODE_INDEX;
3449 if (i < 1 || i > WEP_KEYS)
3450 i = local->tx_keyidx;
3451 else
3452 i--;
3453
3454 addr = ext->addr.sa_data;
3455 if (addr[0] == 0xff && addr[1] == 0xff && addr[2] == 0xff &&
3456 addr[3] == 0xff && addr[4] == 0xff && addr[5] == 0xff) {
3457 sta_ptr = NULL;
3458 crypt = &local->crypt[i];
3459 } else {
3460 i = 0;
3461 sta_ptr = ap_crypt_get_ptrs(local->ap, addr, 0, &crypt);
3462 if (sta_ptr == NULL)
3463 return -EINVAL;
3464 }
3465 erq->flags = i + 1;
3466 memset(ext, 0, sizeof(*ext));
3467
3468 if (*crypt == NULL || (*crypt)->ops == NULL) {
3469 ext->alg = IW_ENCODE_ALG_NONE;
3470 ext->key_len = 0;
3471 erq->flags |= IW_ENCODE_DISABLED;
3472 } else {
3473 if (strcmp((*crypt)->ops->name, "WEP") == 0)
3474 ext->alg = IW_ENCODE_ALG_WEP;
3475 else if (strcmp((*crypt)->ops->name, "TKIP") == 0)
3476 ext->alg = IW_ENCODE_ALG_TKIP;
3477 else if (strcmp((*crypt)->ops->name, "CCMP") == 0)
3478 ext->alg = IW_ENCODE_ALG_CCMP;
3479 else
3480 return -EINVAL;
3481
3482 if ((*crypt)->ops->get_key) {
3483 ext->key_len =
3484 (*crypt)->ops->get_key(ext->key,
3485 max_key_len,
3486 ext->tx_seq,
3487 (*crypt)->priv);
3488 if (ext->key_len &&
3489 (ext->alg == IW_ENCODE_ALG_TKIP ||
3490 ext->alg == IW_ENCODE_ALG_CCMP))
3491 ext->ext_flags |= IW_ENCODE_EXT_TX_SEQ_VALID;
3492 }
3493 }
3494
3495 if (sta_ptr)
3496 hostap_handle_sta_release(sta_ptr);
3497
3498 return 0;
3499}
3500
3501
3502static int prism2_ioctl_set_encryption(local_info_t *local,
3503 struct prism2_hostapd_param *param,
3504 int param_len)
3505{
3506 int ret = 0;
3507 struct hostap_crypto_ops *ops;
3508 struct prism2_crypt_data **crypt;
3509 void *sta_ptr;
3510
3511 param->u.crypt.err = 0;
3512 param->u.crypt.alg[HOSTAP_CRYPT_ALG_NAME_LEN - 1] = '\0';
3513
3514 if (param_len !=
3515 (int) ((char *) param->u.crypt.key - (char *) param) +
3516 param->u.crypt.key_len)
3517 return -EINVAL;
3518
3519 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3520 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3521 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3522 if (param->u.crypt.idx >= WEP_KEYS)
3523 return -EINVAL;
3524 sta_ptr = NULL;
3525 crypt = &local->crypt[param->u.crypt.idx];
3526 } else {
3527 if (param->u.crypt.idx)
3528 return -EINVAL;
3529 sta_ptr = ap_crypt_get_ptrs(
3530 local->ap, param->sta_addr,
3531 (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_PERMANENT),
3532 &crypt);
3533
3534 if (sta_ptr == NULL) {
3535 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3536 return -EINVAL;
3537 }
3538 }
3539
3540 if (strcmp(param->u.crypt.alg, "none") == 0) {
3541 if (crypt)
3542 prism2_crypt_delayed_deinit(local, crypt);
3543 goto done;
3544 }
3545
3546 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3547 if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
3548 request_module("hostap_crypt_wep");
3549 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3550 } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
3551 request_module("hostap_crypt_tkip");
3552 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3553 } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
3554 request_module("hostap_crypt_ccmp");
3555 ops = hostap_get_crypto_ops(param->u.crypt.alg);
3556 }
3557 if (ops == NULL) {
3558 printk(KERN_DEBUG "%s: unknown crypto alg '%s'\n",
3559 local->dev->name, param->u.crypt.alg);
3560 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ALG;
3561 ret = -EINVAL;
3562 goto done;
3563 }
3564
3565 /* station based encryption and other than WEP algorithms require
3566 * host-based encryption, so force them on automatically */
3567 local->host_decrypt = local->host_encrypt = 1;
3568
3569 if (*crypt == NULL || (*crypt)->ops != ops) {
3570 struct prism2_crypt_data *new_crypt;
3571
3572 prism2_crypt_delayed_deinit(local, crypt);
3573
3574 new_crypt = (struct prism2_crypt_data *)
3575 kmalloc(sizeof(struct prism2_crypt_data), GFP_KERNEL);
3576 if (new_crypt == NULL) {
3577 ret = -ENOMEM;
3578 goto done;
3579 }
3580 memset(new_crypt, 0, sizeof(struct prism2_crypt_data));
3581 new_crypt->ops = ops;
3582 new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
3583 if (new_crypt->priv == NULL) {
3584 kfree(new_crypt);
3585 param->u.crypt.err =
3586 HOSTAP_CRYPT_ERR_CRYPT_INIT_FAILED;
3587 ret = -EINVAL;
3588 goto done;
3589 }
3590
3591 *crypt = new_crypt;
3592 }
3593
3594 if ((!(param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) ||
3595 param->u.crypt.key_len > 0) && (*crypt)->ops->set_key &&
3596 (*crypt)->ops->set_key(param->u.crypt.key,
3597 param->u.crypt.key_len, param->u.crypt.seq,
3598 (*crypt)->priv) < 0) {
3599 printk(KERN_DEBUG "%s: key setting failed\n",
3600 local->dev->name);
3601 param->u.crypt.err = HOSTAP_CRYPT_ERR_KEY_SET_FAILED;
3602 ret = -EINVAL;
3603 goto done;
3604 }
3605
3606 if (param->u.crypt.flags & HOSTAP_CRYPT_FLAG_SET_TX_KEY) {
3607 if (!sta_ptr)
3608 local->tx_keyidx = param->u.crypt.idx;
3609 else if (param->u.crypt.idx) {
3610 printk(KERN_DEBUG "%s: TX key idx setting failed\n",
3611 local->dev->name);
3612 param->u.crypt.err =
3613 HOSTAP_CRYPT_ERR_TX_KEY_SET_FAILED;
3614 ret = -EINVAL;
3615 goto done;
3616 }
3617 }
3618
3619 done:
3620 if (sta_ptr)
3621 hostap_handle_sta_release(sta_ptr);
3622
3623 /* Do not reset port0 if card is in Managed mode since resetting will
3624 * generate new IEEE 802.11 authentication which may end up in looping
3625 * with IEEE 802.1X. Prism2 documentation seem to require port reset
3626 * after WEP configuration. However, keys are apparently changed at
3627 * least in Managed mode. */
3628 if (ret == 0 &&
3629 (hostap_set_encryption(local) ||
3630 (local->iw_mode != IW_MODE_INFRA &&
3631 local->func->reset_port(local->dev)))) {
3632 param->u.crypt.err = HOSTAP_CRYPT_ERR_CARD_CONF_FAILED;
3633 return -EINVAL;
3634 }
3635
3636 return ret;
3637}
3638
3639
3640static int prism2_ioctl_get_encryption(local_info_t *local,
3641 struct prism2_hostapd_param *param,
3642 int param_len)
3643{
3644 struct prism2_crypt_data **crypt;
3645 void *sta_ptr;
3646 int max_key_len;
3647
3648 param->u.crypt.err = 0;
3649
3650 max_key_len = param_len -
3651 (int) ((char *) param->u.crypt.key - (char *) param);
3652 if (max_key_len < 0)
3653 return -EINVAL;
3654
3655 if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
3656 param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
3657 param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
3658 sta_ptr = NULL;
3659 if (param->u.crypt.idx >= WEP_KEYS)
3660 param->u.crypt.idx = local->tx_keyidx;
3661 crypt = &local->crypt[param->u.crypt.idx];
3662 } else {
3663 param->u.crypt.idx = 0;
3664 sta_ptr = ap_crypt_get_ptrs(local->ap, param->sta_addr, 0,
3665 &crypt);
3666
3667 if (sta_ptr == NULL) {
3668 param->u.crypt.err = HOSTAP_CRYPT_ERR_UNKNOWN_ADDR;
3669 return -EINVAL;
3670 }
3671 }
3672
3673 if (*crypt == NULL || (*crypt)->ops == NULL) {
3674 memcpy(param->u.crypt.alg, "none", 5);
3675 param->u.crypt.key_len = 0;
3676 param->u.crypt.idx = 0xff;
3677 } else {
3678 strncpy(param->u.crypt.alg, (*crypt)->ops->name,
3679 HOSTAP_CRYPT_ALG_NAME_LEN);
3680 param->u.crypt.key_len = 0;
3681
3682 memset(param->u.crypt.seq, 0, 8);
3683 if ((*crypt)->ops->get_key) {
3684 param->u.crypt.key_len =
3685 (*crypt)->ops->get_key(param->u.crypt.key,
3686 max_key_len,
3687 param->u.crypt.seq,
3688 (*crypt)->priv);
3689 }
3690 }
3691
3692 if (sta_ptr)
3693 hostap_handle_sta_release(sta_ptr);
3694
3695 return 0;
3696}
3697
3698
3699static int prism2_ioctl_get_rid(local_info_t *local,
3700 struct prism2_hostapd_param *param,
3701 int param_len)
3702{
3703 int max_len, res;
3704
3705 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3706 if (max_len < 0)
3707 return -EINVAL;
3708
3709 res = local->func->get_rid(local->dev, param->u.rid.rid,
3710 param->u.rid.data, param->u.rid.len, 0);
3711 if (res >= 0) {
3712 param->u.rid.len = res;
3713 return 0;
3714 }
3715
3716 return res;
3717}
3718
3719
3720static int prism2_ioctl_set_rid(local_info_t *local,
3721 struct prism2_hostapd_param *param,
3722 int param_len)
3723{
3724 int max_len;
3725
3726 max_len = param_len - PRISM2_HOSTAPD_RID_HDR_LEN;
3727 if (max_len < 0 || max_len < param->u.rid.len)
3728 return -EINVAL;
3729
3730 return local->func->set_rid(local->dev, param->u.rid.rid,
3731 param->u.rid.data, param->u.rid.len);
3732}
3733
3734
3735static int prism2_ioctl_set_assoc_ap_addr(local_info_t *local,
3736 struct prism2_hostapd_param *param,
3737 int param_len)
3738{
3739 printk(KERN_DEBUG "%ssta: associated as client with AP " MACSTR "\n",
3740 local->dev->name, MAC2STR(param->sta_addr));
3741 memcpy(local->assoc_ap_addr, param->sta_addr, ETH_ALEN);
3742 return 0;
3743}
3744
3745
3746static int prism2_ioctl_siwgenie(struct net_device *dev,
3747 struct iw_request_info *info,
3748 struct iw_point *data, char *extra)
3749{
3750 return prism2_set_genericelement(dev, extra, data->length);
3751}
3752
3753
3754static int prism2_ioctl_giwgenie(struct net_device *dev,
3755 struct iw_request_info *info,
3756 struct iw_point *data, char *extra)
3757{
3758 struct hostap_interface *iface = dev->priv;
3759 local_info_t *local = iface->local;
3760 int len = local->generic_elem_len - 2;
3761
3762 if (len <= 0 || local->generic_elem == NULL) {
3763 data->length = 0;
3764 return 0;
3765 }
3766
3767 if (data->length < len)
3768 return -E2BIG;
3769
3770 data->length = len;
3771 memcpy(extra, local->generic_elem + 2, len);
3772
3773 return 0;
3774}
3775
3776
3777static int prism2_ioctl_set_generic_element(local_info_t *local,
3778 struct prism2_hostapd_param *param,
3779 int param_len)
3780{
3781 int max_len, len;
3782
3783 len = param->u.generic_elem.len;
3784 max_len = param_len - PRISM2_HOSTAPD_GENERIC_ELEMENT_HDR_LEN;
3785 if (max_len < 0 || max_len < len)
3786 return -EINVAL;
3787
3788 return prism2_set_genericelement(local->dev,
3789 param->u.generic_elem.data, len);
3790}
3791
3792
3793static int prism2_ioctl_siwmlme(struct net_device *dev,
3794 struct iw_request_info *info,
3795 struct iw_point *data, char *extra)
3796{
3797 struct hostap_interface *iface = dev->priv;
3798 local_info_t *local = iface->local;
3799 struct iw_mlme *mlme = (struct iw_mlme *) extra;
3800 u16 reason;
3801
3802 reason = cpu_to_le16(mlme->reason_code);
3803
3804 switch (mlme->cmd) {
3805 case IW_MLME_DEAUTH:
3806 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3807 WLAN_FC_STYPE_DEAUTH,
3808 (u8 *) &reason, 2);
3809 case IW_MLME_DISASSOC:
3810 return prism2_sta_send_mgmt(local, mlme->addr.sa_data,
3811 WLAN_FC_STYPE_DISASSOC,
3812 (u8 *) &reason, 2);
3813 default:
3814 return -EOPNOTSUPP;
3815 }
3816}
3817
3818
3819static int prism2_ioctl_mlme(local_info_t *local,
3820 struct prism2_hostapd_param *param)
3821{
3822 u16 reason;
3823
3824 reason = cpu_to_le16(param->u.mlme.reason_code);
3825 switch (param->u.mlme.cmd) {
3826 case MLME_STA_DEAUTH:
3827 return prism2_sta_send_mgmt(local, param->sta_addr,
3828 WLAN_FC_STYPE_DEAUTH,
3829 (u8 *) &reason, 2);
3830 case MLME_STA_DISASSOC:
3831 return prism2_sta_send_mgmt(local, param->sta_addr,
3832 WLAN_FC_STYPE_DISASSOC,
3833 (u8 *) &reason, 2);
3834 default:
3835 return -EOPNOTSUPP;
3836 }
3837}
3838
3839
3840static int prism2_ioctl_scan_req(local_info_t *local,
3841 struct prism2_hostapd_param *param)
3842{
3843#ifndef PRISM2_NO_STATION_MODES
3844 if ((local->iw_mode != IW_MODE_INFRA &&
3845 local->iw_mode != IW_MODE_ADHOC) ||
3846 (local->sta_fw_ver < PRISM2_FW_VER(1,3,1)))
3847 return -EOPNOTSUPP;
3848
3849 if (!local->dev_enabled)
3850 return -ENETDOWN;
3851
3852 return prism2_request_hostscan(local->dev, param->u.scan_req.ssid,
3853 param->u.scan_req.ssid_len);
3854#else /* PRISM2_NO_STATION_MODES */
3855 return -EOPNOTSUPP;
3856#endif /* PRISM2_NO_STATION_MODES */
3857}
3858
3859
3860static int prism2_ioctl_priv_hostapd(local_info_t *local, struct iw_point *p)
3861{
3862 struct prism2_hostapd_param *param;
3863 int ret = 0;
3864 int ap_ioctl = 0;
3865
3866 if (p->length < sizeof(struct prism2_hostapd_param) ||
3867 p->length > PRISM2_HOSTAPD_MAX_BUF_SIZE || !p->pointer)
3868 return -EINVAL;
3869
3870 param = (struct prism2_hostapd_param *) kmalloc(p->length, GFP_KERNEL);
3871 if (param == NULL)
3872 return -ENOMEM;
3873
3874 if (copy_from_user(param, p->pointer, p->length)) {
3875 ret = -EFAULT;
3876 goto out;
3877 }
3878
3879 switch (param->cmd) {
3880 case PRISM2_SET_ENCRYPTION:
3881 ret = prism2_ioctl_set_encryption(local, param, p->length);
3882 break;
3883 case PRISM2_GET_ENCRYPTION:
3884 ret = prism2_ioctl_get_encryption(local, param, p->length);
3885 break;
3886 case PRISM2_HOSTAPD_GET_RID:
3887 ret = prism2_ioctl_get_rid(local, param, p->length);
3888 break;
3889 case PRISM2_HOSTAPD_SET_RID:
3890 ret = prism2_ioctl_set_rid(local, param, p->length);
3891 break;
3892 case PRISM2_HOSTAPD_SET_ASSOC_AP_ADDR:
3893 ret = prism2_ioctl_set_assoc_ap_addr(local, param, p->length);
3894 break;
3895 case PRISM2_HOSTAPD_SET_GENERIC_ELEMENT:
3896 ret = prism2_ioctl_set_generic_element(local, param,
3897 p->length);
3898 break;
3899 case PRISM2_HOSTAPD_MLME:
3900 ret = prism2_ioctl_mlme(local, param);
3901 break;
3902 case PRISM2_HOSTAPD_SCAN_REQ:
3903 ret = prism2_ioctl_scan_req(local, param);
3904 break;
3905 default:
3906 ret = prism2_hostapd(local->ap, param);
3907 ap_ioctl = 1;
3908 break;
3909 }
3910
3911 if (ret == 1 || !ap_ioctl) {
3912 if (copy_to_user(p->pointer, param, p->length)) {
3913 ret = -EFAULT;
3914 goto out;
3915 } else if (ap_ioctl)
3916 ret = 0;
3917 }
3918
3919 out:
3920 if (param != NULL)
3921 kfree(param);
3922
3923 return ret;
3924}
3925
3926
3927static void prism2_get_drvinfo(struct net_device *dev,
3928 struct ethtool_drvinfo *info)
3929{
3930 struct hostap_interface *iface;
3931 local_info_t *local;
3932
3933 iface = netdev_priv(dev);
3934 local = iface->local;
3935
3936 strncpy(info->driver, "hostap", sizeof(info->driver) - 1);
3937 strncpy(info->version, PRISM2_VERSION,
3938 sizeof(info->version) - 1);
3939 snprintf(info->fw_version, sizeof(info->fw_version) - 1,
3940 "%d.%d.%d", (local->sta_fw_ver >> 16) & 0xff,
3941 (local->sta_fw_ver >> 8) & 0xff,
3942 local->sta_fw_ver & 0xff);
3943}
3944
3945static struct ethtool_ops prism2_ethtool_ops = {
3946 .get_drvinfo = prism2_get_drvinfo
3947};
3948
3949
3950/* Structures to export the Wireless Handlers */
3951
3952static const iw_handler prism2_handler[] =
3953{
3954 (iw_handler) NULL, /* SIOCSIWCOMMIT */
3955 (iw_handler) prism2_get_name, /* SIOCGIWNAME */
3956 (iw_handler) NULL, /* SIOCSIWNWID */
3957 (iw_handler) NULL, /* SIOCGIWNWID */
3958 (iw_handler) prism2_ioctl_siwfreq, /* SIOCSIWFREQ */
3959 (iw_handler) prism2_ioctl_giwfreq, /* SIOCGIWFREQ */
3960 (iw_handler) prism2_ioctl_siwmode, /* SIOCSIWMODE */
3961 (iw_handler) prism2_ioctl_giwmode, /* SIOCGIWMODE */
3962 (iw_handler) prism2_ioctl_siwsens, /* SIOCSIWSENS */
3963 (iw_handler) prism2_ioctl_giwsens, /* SIOCGIWSENS */
3964 (iw_handler) NULL /* not used */, /* SIOCSIWRANGE */
3965 (iw_handler) prism2_ioctl_giwrange, /* SIOCGIWRANGE */
3966 (iw_handler) NULL /* not used */, /* SIOCSIWPRIV */
3967 (iw_handler) NULL /* kernel code */, /* SIOCGIWPRIV */
3968 (iw_handler) NULL /* not used */, /* SIOCSIWSTATS */
3969 (iw_handler) NULL /* kernel code */, /* SIOCGIWSTATS */
3970 iw_handler_set_spy, /* SIOCSIWSPY */
3971 iw_handler_get_spy, /* SIOCGIWSPY */
3972 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
3973 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
3974 (iw_handler) prism2_ioctl_siwap, /* SIOCSIWAP */
3975 (iw_handler) prism2_ioctl_giwap, /* SIOCGIWAP */
3976 (iw_handler) prism2_ioctl_siwmlme, /* SIOCSIWMLME */
3977 (iw_handler) prism2_ioctl_giwaplist, /* SIOCGIWAPLIST */
3978 (iw_handler) prism2_ioctl_siwscan, /* SIOCSIWSCAN */
3979 (iw_handler) prism2_ioctl_giwscan, /* SIOCGIWSCAN */
3980 (iw_handler) prism2_ioctl_siwessid, /* SIOCSIWESSID */
3981 (iw_handler) prism2_ioctl_giwessid, /* SIOCGIWESSID */
3982 (iw_handler) prism2_ioctl_siwnickn, /* SIOCSIWNICKN */
3983 (iw_handler) prism2_ioctl_giwnickn, /* SIOCGIWNICKN */
3984 (iw_handler) NULL, /* -- hole -- */
3985 (iw_handler) NULL, /* -- hole -- */
3986 (iw_handler) prism2_ioctl_siwrate, /* SIOCSIWRATE */
3987 (iw_handler) prism2_ioctl_giwrate, /* SIOCGIWRATE */
3988 (iw_handler) prism2_ioctl_siwrts, /* SIOCSIWRTS */
3989 (iw_handler) prism2_ioctl_giwrts, /* SIOCGIWRTS */
3990 (iw_handler) prism2_ioctl_siwfrag, /* SIOCSIWFRAG */
3991 (iw_handler) prism2_ioctl_giwfrag, /* SIOCGIWFRAG */
3992 (iw_handler) prism2_ioctl_siwtxpow, /* SIOCSIWTXPOW */
3993 (iw_handler) prism2_ioctl_giwtxpow, /* SIOCGIWTXPOW */
3994 (iw_handler) prism2_ioctl_siwretry, /* SIOCSIWRETRY */
3995 (iw_handler) prism2_ioctl_giwretry, /* SIOCGIWRETRY */
3996 (iw_handler) prism2_ioctl_siwencode, /* SIOCSIWENCODE */
3997 (iw_handler) prism2_ioctl_giwencode, /* SIOCGIWENCODE */
3998 (iw_handler) prism2_ioctl_siwpower, /* SIOCSIWPOWER */
3999 (iw_handler) prism2_ioctl_giwpower, /* SIOCGIWPOWER */
4000 (iw_handler) NULL, /* -- hole -- */
4001 (iw_handler) NULL, /* -- hole -- */
4002 (iw_handler) prism2_ioctl_siwgenie, /* SIOCSIWGENIE */
4003 (iw_handler) prism2_ioctl_giwgenie, /* SIOCGIWGENIE */
4004 (iw_handler) prism2_ioctl_siwauth, /* SIOCSIWAUTH */
4005 (iw_handler) prism2_ioctl_giwauth, /* SIOCGIWAUTH */
4006 (iw_handler) prism2_ioctl_siwencodeext, /* SIOCSIWENCODEEXT */
4007 (iw_handler) prism2_ioctl_giwencodeext, /* SIOCGIWENCODEEXT */
4008 (iw_handler) NULL, /* SIOCSIWPMKSA */
4009 (iw_handler) NULL, /* -- hole -- */
4010};
4011
4012static const iw_handler prism2_private_handler[] =
4013{ /* SIOCIWFIRSTPRIV + */
4014 (iw_handler) prism2_ioctl_priv_prism2_param, /* 0 */
4015 (iw_handler) prism2_ioctl_priv_get_prism2_param, /* 1 */
4016 (iw_handler) prism2_ioctl_priv_writemif, /* 2 */
4017 (iw_handler) prism2_ioctl_priv_readmif, /* 3 */
4018};
4019
4020static const struct iw_handler_def hostap_iw_handler_def =
4021{
4022 .num_standard = sizeof(prism2_handler) / sizeof(iw_handler),
4023 .num_private = sizeof(prism2_private_handler) / sizeof(iw_handler),
4024 .num_private_args = sizeof(prism2_priv) / sizeof(struct iw_priv_args),
4025 .standard = (iw_handler *) prism2_handler,
4026 .private = (iw_handler *) prism2_private_handler,
4027 .private_args = (struct iw_priv_args *) prism2_priv,
4028 .get_wireless_stats = hostap_get_wireless_stats,
4029};
4030
4031
4032int hostap_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
4033{
4034 struct iwreq *wrq = (struct iwreq *) ifr;
4035 struct hostap_interface *iface;
4036 local_info_t *local;
4037 int ret = 0;
4038
4039 iface = netdev_priv(dev);
4040 local = iface->local;
4041
4042 switch (cmd) {
4043 /* Private ioctls (iwpriv) that have not yet been converted
4044 * into new wireless extensions API */
4045
4046 case PRISM2_IOCTL_INQUIRE:
4047 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4048 else ret = prism2_ioctl_priv_inquire(dev, (int *) wrq->u.name);
4049 break;
4050
4051 case PRISM2_IOCTL_MONITOR:
4052 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4053 else ret = prism2_ioctl_priv_monitor(dev, (int *) wrq->u.name);
4054 break;
4055
4056 case PRISM2_IOCTL_RESET:
4057 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4058 else ret = prism2_ioctl_priv_reset(dev, (int *) wrq->u.name);
4059 break;
4060
4061 case PRISM2_IOCTL_WDS_ADD:
4062 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4063 else ret = prism2_wds_add(local, wrq->u.ap_addr.sa_data, 1);
4064 break;
4065
4066 case PRISM2_IOCTL_WDS_DEL:
4067 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4068 else ret = prism2_wds_del(local, wrq->u.ap_addr.sa_data, 1, 0);
4069 break;
4070
4071 case PRISM2_IOCTL_SET_RID_WORD:
4072 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4073 else ret = prism2_ioctl_priv_set_rid_word(dev,
4074 (int *) wrq->u.name);
4075 break;
4076
4077#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
4078 case PRISM2_IOCTL_MACCMD:
4079 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4080 else ret = ap_mac_cmd_ioctl(local, (int *) wrq->u.name);
4081 break;
4082
4083 case PRISM2_IOCTL_ADDMAC:
4084 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4085 else ret = ap_control_add_mac(&local->ap->mac_restrictions,
4086 wrq->u.ap_addr.sa_data);
4087 break;
4088 case PRISM2_IOCTL_DELMAC:
4089 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4090 else ret = ap_control_del_mac(&local->ap->mac_restrictions,
4091 wrq->u.ap_addr.sa_data);
4092 break;
4093 case PRISM2_IOCTL_KICKMAC:
4094 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4095 else ret = ap_control_kick_mac(local->ap, local->dev,
4096 wrq->u.ap_addr.sa_data);
4097 break;
4098#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
4099
4100
4101 /* Private ioctls that are not used with iwpriv;
4102 * in SIOCDEVPRIVATE range */
4103
4104#ifdef PRISM2_DOWNLOAD_SUPPORT
4105 case PRISM2_IOCTL_DOWNLOAD:
4106 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4107 else ret = prism2_ioctl_priv_download(local, &wrq->u.data);
4108 break;
4109#endif /* PRISM2_DOWNLOAD_SUPPORT */
4110
4111 case PRISM2_IOCTL_HOSTAPD:
4112 if (!capable(CAP_NET_ADMIN)) ret = -EPERM;
4113 else ret = prism2_ioctl_priv_hostapd(local, &wrq->u.data);
4114 break;
4115
4116 default:
4117 ret = -EOPNOTSUPP;
4118 break;
4119 }
4120
4121 return ret;
4122}
This page took 0.181294 seconds and 5 git commands to generate.