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