[PATCH] libertas: remove 8021xauthalgs private ioctl
[linux-2.6] / drivers / net / wireless / libertas / wext.c
1 /**
2   * This file contains ioctl functions
3   */
4 #include <linux/ctype.h>
5 #include <linux/delay.h>
6 #include <linux/if.h>
7 #include <linux/if_arp.h>
8 #include <linux/wireless.h>
9 #include <linux/bitops.h>
10
11 #include <net/ieee80211.h>
12 #include <net/iw_handler.h>
13
14 #include "host.h"
15 #include "radiotap.h"
16 #include "decl.h"
17 #include "defs.h"
18 #include "dev.h"
19 #include "join.h"
20 #include "version.h"
21 #include "wext.h"
22 #include "assoc.h"
23
24
25 /**
26  *  @brief Convert mw value to dbm value
27  *
28  *  @param mw      the value of mw
29  *  @return        the value of dbm
30  */
31 static int mw_to_dbm(int mw)
32 {
33         if (mw < 2)
34                 return 0;
35         else if (mw < 3)
36                 return 3;
37         else if (mw < 4)
38                 return 5;
39         else if (mw < 6)
40                 return 7;
41         else if (mw < 7)
42                 return 8;
43         else if (mw < 8)
44                 return 9;
45         else if (mw < 10)
46                 return 10;
47         else if (mw < 13)
48                 return 11;
49         else if (mw < 16)
50                 return 12;
51         else if (mw < 20)
52                 return 13;
53         else if (mw < 25)
54                 return 14;
55         else if (mw < 32)
56                 return 15;
57         else if (mw < 40)
58                 return 16;
59         else if (mw < 50)
60                 return 17;
61         else if (mw < 63)
62                 return 18;
63         else if (mw < 79)
64                 return 19;
65         else if (mw < 100)
66                 return 20;
67         else
68                 return 21;
69 }
70
71 /**
72  *  @brief Find the channel frequency power info with specific channel
73  *
74  *  @param adapter      A pointer to wlan_adapter structure
75  *  @param band         it can be BAND_A, BAND_G or BAND_B
76  *  @param channel      the channel for looking
77  *  @return             A pointer to struct chan_freq_power structure or NULL if not find.
78  */
79 struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
80                                                  u8 band, u16 channel)
81 {
82         struct chan_freq_power *cfp = NULL;
83         struct region_channel *rc;
84         int count = sizeof(adapter->region_channel) /
85             sizeof(adapter->region_channel[0]);
86         int i, j;
87
88         for (j = 0; !cfp && (j < count); j++) {
89                 rc = &adapter->region_channel[j];
90
91                 if (adapter->enable11d)
92                         rc = &adapter->universal_channel[j];
93                 if (!rc->valid || !rc->CFP)
94                         continue;
95                 if (rc->band != band)
96                         continue;
97                 for (i = 0; i < rc->nrcfp; i++) {
98                         if (rc->CFP[i].channel == channel) {
99                                 cfp = &rc->CFP[i];
100                                 break;
101                         }
102                 }
103         }
104
105         if (!cfp && channel)
106                 lbs_pr_debug(1, "libertas_find_cfp_by_band_and_channel(): cannot find "
107                        "cfp by band %d & channel %d\n", band, channel);
108
109         return cfp;
110 }
111
112 /**
113  *  @brief Find the channel frequency power info with specific frequency
114  *
115  *  @param adapter      A pointer to wlan_adapter structure
116  *  @param band         it can be BAND_A, BAND_G or BAND_B
117  *  @param freq         the frequency for looking
118  *  @return             A pointer to struct chan_freq_power structure or NULL if not find.
119  */
120 static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
121                                                      u8 band, u32 freq)
122 {
123         struct chan_freq_power *cfp = NULL;
124         struct region_channel *rc;
125         int count = sizeof(adapter->region_channel) /
126             sizeof(adapter->region_channel[0]);
127         int i, j;
128
129         for (j = 0; !cfp && (j < count); j++) {
130                 rc = &adapter->region_channel[j];
131
132                 if (adapter->enable11d)
133                         rc = &adapter->universal_channel[j];
134                 if (!rc->valid || !rc->CFP)
135                         continue;
136                 if (rc->band != band)
137                         continue;
138                 for (i = 0; i < rc->nrcfp; i++) {
139                         if (rc->CFP[i].freq == freq) {
140                                 cfp = &rc->CFP[i];
141                                 break;
142                         }
143                 }
144         }
145
146         if (!cfp && freq)
147                 lbs_pr_debug(1, "find_cfp_by_band_and_freql(): cannot find cfp by "
148                        "band %d & freq %d\n", band, freq);
149
150         return cfp;
151 }
152
153 static int updatecurrentchannel(wlan_private * priv)
154 {
155         int ret;
156
157         /*
158          ** the channel in f/w could be out of sync, get the current channel
159          */
160         ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
161                                     cmd_opt_802_11_rf_channel_get,
162                                     cmd_option_waitforrsp, 0, NULL);
163
164         lbs_pr_debug(1, "Current channel = %d\n",
165                priv->adapter->curbssparams.channel);
166
167         return ret;
168 }
169
170 static int setcurrentchannel(wlan_private * priv, int channel)
171 {
172         lbs_pr_debug(1, "Set channel = %d\n", channel);
173
174         /*
175          **  Current channel is not set to adhocchannel requested, set channel
176          */
177         return (libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
178                                       cmd_opt_802_11_rf_channel_set,
179                                       cmd_option_waitforrsp, 0, &channel));
180 }
181
182 static int changeadhocchannel(wlan_private * priv, int channel)
183 {
184         int ret = 0;
185         wlan_adapter *adapter = priv->adapter;
186
187         adapter->adhocchannel = channel;
188
189         updatecurrentchannel(priv);
190
191         if (adapter->curbssparams.channel == adapter->adhocchannel) {
192                 /* adhocchannel is set to the current channel already */
193                 LEAVE();
194                 return 0;
195         }
196
197         lbs_pr_debug(1, "Updating channel from %d to %d\n",
198                adapter->curbssparams.channel, adapter->adhocchannel);
199
200         setcurrentchannel(priv, adapter->adhocchannel);
201
202         updatecurrentchannel(priv);
203
204         if (adapter->curbssparams.channel != adapter->adhocchannel) {
205                 lbs_pr_debug(1, "failed to updated channel to %d, channel = %d\n",
206                        adapter->adhocchannel, adapter->curbssparams.channel);
207                 LEAVE();
208                 return -1;
209         }
210
211         if (adapter->connect_status == libertas_connected) {
212                 int i;
213                 struct WLAN_802_11_SSID curadhocssid;
214
215                 lbs_pr_debug(1, "channel Changed while in an IBSS\n");
216
217                 /* Copy the current ssid */
218                 memcpy(&curadhocssid, &adapter->curbssparams.ssid,
219                        sizeof(struct WLAN_802_11_SSID));
220
221                 /* Exit Adhoc mode */
222                 lbs_pr_debug(1, "In changeadhocchannel(): Sending Adhoc Stop\n");
223                 ret = libertas_stop_adhoc_network(priv);
224
225                 if (ret) {
226                         LEAVE();
227                         return ret;
228                 }
229                 /* Scan for the network, do not save previous results.  Stale
230                  *   scan data will cause us to join a non-existant adhoc network
231                  */
232                 libertas_send_specific_SSID_scan(priv, &curadhocssid, 0);
233
234                 // find out the BSSID that matches the current SSID
235                 i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
236                                    wlan802_11ibss);
237
238                 if (i >= 0) {
239                         lbs_pr_debug(1, "SSID found at %d in List,"
240                                "so join\n", i);
241                         libertas_join_adhoc_network(priv, &adapter->scantable[i]);
242                 } else {
243                         // else send START command
244                         lbs_pr_debug(1, "SSID not found in list, "
245                                "so creating adhoc with ssid = %s\n",
246                                curadhocssid.ssid);
247                         libertas_start_adhoc_network(priv, &curadhocssid);
248                 }               // end of else (START command)
249         }
250
251         LEAVE();
252         return 0;
253 }
254
255 /**
256  *  @brief Set Radio On/OFF
257  *
258  *  @param priv                 A pointer to wlan_private structure
259  *  @option                     Radio Option
260  *  @return                     0 --success, otherwise fail
261  */
262 int wlan_radio_ioctl(wlan_private * priv, u8 option)
263 {
264         int ret = 0;
265         wlan_adapter *adapter = priv->adapter;
266
267         ENTER();
268
269         if (adapter->radioon != option) {
270                 lbs_pr_debug(1, "Switching %s the Radio\n", option ? "On" : "Off");
271                 adapter->radioon = option;
272
273                 ret = libertas_prepare_and_send_command(priv,
274                                             cmd_802_11_radio_control,
275                                             cmd_act_set,
276                                             cmd_option_waitforrsp, 0, NULL);
277         }
278
279         LEAVE();
280         return ret;
281 }
282
283 /**
284  *  @brief Copy rates
285  *
286  *  @param dest                 A pointer to Dest Buf
287  *  @param src                  A pointer to Src Buf
288  *  @param len                  The len of Src Buf
289  *  @return                     Number of rates copyed
290  */
291 static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
292 {
293         int i;
294
295         for (i = 0; i < len && src[i]; i++, pos++) {
296                 if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
297                         break;
298                 dest[pos] = src[i];
299         }
300
301         return pos;
302 }
303
304 /**
305  *  @brief Get active data rates
306  *
307  *  @param adapter              A pointer to wlan_adapter structure
308  *  @param rate                 The buf to return the active rates
309  *  @return                     The number of rates
310  */
311 static int get_active_data_rates(wlan_adapter * adapter,
312                                  u8* rates)
313 {
314         int k = 0;
315
316         ENTER();
317
318         if (adapter->connect_status != libertas_connected) {
319                 if (adapter->inframode == wlan802_11infrastructure) {
320                         //Infra. mode
321                         lbs_pr_debug(1, "Infra\n");
322                         k = copyrates(rates, k, libertas_supported_rates,
323                                       sizeof(libertas_supported_rates));
324                 } else {
325                         //ad-hoc mode
326                         lbs_pr_debug(1, "Adhoc G\n");
327                         k = copyrates(rates, k, libertas_adhoc_rates_g,
328                                       sizeof(libertas_adhoc_rates_g));
329                 }
330         } else {
331                 k = copyrates(rates, 0, adapter->curbssparams.datarates,
332                               adapter->curbssparams.numofrates);
333         }
334
335         LEAVE();
336
337         return k;
338 }
339
340 static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
341                          char *cwrq, char *extra)
342 {
343         const char *cp;
344         char comm[6] = { "COMM-" };
345         char mrvl[6] = { "MRVL-" };
346         int cnt;
347
348         ENTER();
349
350         strcpy(cwrq, mrvl);
351
352         cp = strstr(libertas_driver_version, comm);
353         if (cp == libertas_driver_version)      //skip leading "COMM-"
354                 cp = libertas_driver_version + strlen(comm);
355         else
356                 cp = libertas_driver_version;
357
358         cnt = strlen(mrvl);
359         cwrq += cnt;
360         while (cnt < 16 && (*cp != '-')) {
361                 *cwrq++ = toupper(*cp++);
362                 cnt++;
363         }
364         *cwrq = '\0';
365
366         LEAVE();
367
368         return 0;
369 }
370
371 static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
372                          struct iw_freq *fwrq, char *extra)
373 {
374         wlan_private *priv = dev->priv;
375         wlan_adapter *adapter = priv->adapter;
376         struct chan_freq_power *cfp;
377
378         ENTER();
379
380         cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
381                                            adapter->curbssparams.channel);
382
383         if (!cfp) {
384                 if (adapter->curbssparams.channel)
385                         lbs_pr_debug(1, "Invalid channel=%d\n",
386                                adapter->curbssparams.channel);
387                 return -EINVAL;
388         }
389
390         fwrq->m = (long)cfp->freq * 100000;
391         fwrq->e = 1;
392
393         lbs_pr_debug(1, "freq=%u\n", fwrq->m);
394
395         LEAVE();
396         return 0;
397 }
398
399 static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
400                         struct sockaddr *awrq, char *extra)
401 {
402         wlan_private *priv = dev->priv;
403         wlan_adapter *adapter = priv->adapter;
404
405         ENTER();
406
407         if (adapter->connect_status == libertas_connected) {
408                 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
409         } else {
410                 memset(awrq->sa_data, 0, ETH_ALEN);
411         }
412         awrq->sa_family = ARPHRD_ETHER;
413
414         LEAVE();
415         return 0;
416 }
417
418 static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
419                          struct iw_point *dwrq, char *extra)
420 {
421         wlan_private *priv = dev->priv;
422         wlan_adapter *adapter = priv->adapter;
423
424         ENTER();
425
426         /*
427          * Check the size of the string
428          */
429
430         if (dwrq->length > 16) {
431                 return -E2BIG;
432         }
433
434         mutex_lock(&adapter->lock);
435         memset(adapter->nodename, 0, sizeof(adapter->nodename));
436         memcpy(adapter->nodename, extra, dwrq->length);
437         mutex_unlock(&adapter->lock);
438
439         LEAVE();
440         return 0;
441 }
442
443 static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
444                          struct iw_point *dwrq, char *extra)
445 {
446         wlan_private *priv = dev->priv;
447         wlan_adapter *adapter = priv->adapter;
448
449         ENTER();
450
451         /*
452          * Get the Nick Name saved
453          */
454
455         mutex_lock(&adapter->lock);
456         strncpy(extra, adapter->nodename, 16);
457         mutex_unlock(&adapter->lock);
458
459         extra[16] = '\0';
460
461         /*
462          * If none, we may want to get the one that was set
463          */
464
465         /*
466          * Push it out !
467          */
468         dwrq->length = strlen(extra) + 1;
469
470         LEAVE();
471         return 0;
472 }
473
474 static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
475                         struct iw_param *vwrq, char *extra)
476 {
477         int ret = 0;
478         wlan_private *priv = dev->priv;
479         wlan_adapter *adapter = priv->adapter;
480         int rthr = vwrq->value;
481
482         ENTER();
483
484         if (vwrq->disabled) {
485                 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
486         } else {
487                 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
488                         return -EINVAL;
489                 adapter->rtsthsd = rthr;
490         }
491
492         ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
493                                     cmd_act_set, cmd_option_waitforrsp,
494                                     OID_802_11_RTS_THRESHOLD, &rthr);
495
496         LEAVE();
497         return ret;
498 }
499
500 static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
501                         struct iw_param *vwrq, char *extra)
502 {
503         int ret = 0;
504         wlan_private *priv = dev->priv;
505         wlan_adapter *adapter = priv->adapter;
506
507         ENTER();
508
509         adapter->rtsthsd = 0;
510         ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
511                                     cmd_act_get, cmd_option_waitforrsp,
512                                     OID_802_11_RTS_THRESHOLD, NULL);
513         if (ret) {
514                 LEAVE();
515                 return ret;
516         }
517
518         vwrq->value = adapter->rtsthsd;
519         vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
520                           || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
521         vwrq->fixed = 1;
522
523         LEAVE();
524         return 0;
525 }
526
527 static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
528                          struct iw_param *vwrq, char *extra)
529 {
530         int ret = 0;
531         int fthr = vwrq->value;
532         wlan_private *priv = dev->priv;
533         wlan_adapter *adapter = priv->adapter;
534
535         ENTER();
536
537         if (vwrq->disabled) {
538                 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
539         } else {
540                 if (fthr < MRVDRV_FRAG_MIN_VALUE
541                     || fthr > MRVDRV_FRAG_MAX_VALUE)
542                         return -EINVAL;
543                 adapter->fragthsd = fthr;
544         }
545
546         ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
547                                     cmd_act_set, cmd_option_waitforrsp,
548                                     OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
549         LEAVE();
550         return ret;
551 }
552
553 static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
554                          struct iw_param *vwrq, char *extra)
555 {
556         int ret = 0;
557         wlan_private *priv = dev->priv;
558         wlan_adapter *adapter = priv->adapter;
559
560         ENTER();
561
562         adapter->fragthsd = 0;
563         ret = libertas_prepare_and_send_command(priv,
564                                     cmd_802_11_snmp_mib,
565                                     cmd_act_get, cmd_option_waitforrsp,
566                                     OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
567         if (ret) {
568                 LEAVE();
569                 return ret;
570         }
571
572         vwrq->value = adapter->fragthsd;
573         vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
574                           || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
575         vwrq->fixed = 1;
576
577         LEAVE();
578         return ret;
579 }
580
581 static int wlan_get_mode(struct net_device *dev,
582                          struct iw_request_info *info, u32 * uwrq, char *extra)
583 {
584         wlan_private *priv = dev->priv;
585         wlan_adapter *adapter = priv->adapter;
586
587         ENTER();
588
589         switch (adapter->inframode) {
590         case wlan802_11ibss:
591                 *uwrq = IW_MODE_ADHOC;
592                 break;
593
594         case wlan802_11infrastructure:
595                 *uwrq = IW_MODE_INFRA;
596                 break;
597
598         default:
599         case wlan802_11autounknown:
600                 *uwrq = IW_MODE_AUTO;
601                 break;
602         }
603
604         LEAVE();
605         return 0;
606 }
607
608 static int wlan_get_txpow(struct net_device *dev,
609                           struct iw_request_info *info,
610                           struct iw_param *vwrq, char *extra)
611 {
612         int ret = 0;
613         wlan_private *priv = dev->priv;
614         wlan_adapter *adapter = priv->adapter;
615
616         ENTER();
617
618         ret = libertas_prepare_and_send_command(priv,
619                                     cmd_802_11_rf_tx_power,
620                                     cmd_act_tx_power_opt_get,
621                                     cmd_option_waitforrsp, 0, NULL);
622
623         if (ret) {
624                 LEAVE();
625                 return ret;
626         }
627
628         lbs_pr_debug(1, "TXPOWER GET %d dbm.\n", adapter->txpowerlevel);
629         vwrq->value = adapter->txpowerlevel;
630         vwrq->fixed = 1;
631         if (adapter->radioon) {
632                 vwrq->disabled = 0;
633                 vwrq->flags = IW_TXPOW_DBM;
634         } else {
635                 vwrq->disabled = 1;
636         }
637
638         LEAVE();
639         return 0;
640 }
641
642 static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
643                           struct iw_param *vwrq, char *extra)
644 {
645         int ret = 0;
646         wlan_private *priv = dev->priv;
647         wlan_adapter *adapter = priv->adapter;
648
649         ENTER();
650
651         if (vwrq->flags == IW_RETRY_LIMIT) {
652                 /* The MAC has a 4-bit Total_Tx_Count register
653                    Total_Tx_Count = 1 + Tx_Retry_Count */
654 #define TX_RETRY_MIN 0
655 #define TX_RETRY_MAX 14
656                 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
657                         return -EINVAL;
658
659                 /* Adding 1 to convert retry count to try count */
660                 adapter->txretrycount = vwrq->value + 1;
661
662                 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
663                                             cmd_act_set,
664                                             cmd_option_waitforrsp,
665                                             OID_802_11_TX_RETRYCOUNT, NULL);
666
667                 if (ret) {
668                         LEAVE();
669                         return ret;
670                 }
671         } else {
672                 return -EOPNOTSUPP;
673         }
674
675         LEAVE();
676         return 0;
677 }
678
679 static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
680                           struct iw_param *vwrq, char *extra)
681 {
682         wlan_private *priv = dev->priv;
683         wlan_adapter *adapter = priv->adapter;
684         int ret = 0;
685
686         ENTER();
687         adapter->txretrycount = 0;
688         ret = libertas_prepare_and_send_command(priv,
689                                     cmd_802_11_snmp_mib,
690                                     cmd_act_get, cmd_option_waitforrsp,
691                                     OID_802_11_TX_RETRYCOUNT, NULL);
692         if (ret) {
693                 LEAVE();
694                 return ret;
695         }
696         vwrq->disabled = 0;
697         if (!vwrq->flags) {
698                 vwrq->flags = IW_RETRY_LIMIT;
699                 /* Subtract 1 to convert try count to retry count */
700                 vwrq->value = adapter->txretrycount - 1;
701         }
702
703         LEAVE();
704         return 0;
705 }
706
707 static inline void sort_channels(struct iw_freq *freq, int num)
708 {
709         int i, j;
710         struct iw_freq temp;
711
712         for (i = 0; i < num; i++)
713                 for (j = i + 1; j < num; j++)
714                         if (freq[i].i > freq[j].i) {
715                                 temp.i = freq[i].i;
716                                 temp.m = freq[i].m;
717
718                                 freq[i].i = freq[j].i;
719                                 freq[i].m = freq[j].m;
720
721                                 freq[j].i = temp.i;
722                                 freq[j].m = temp.m;
723                         }
724 }
725
726 /* data rate listing
727         MULTI_BANDS:
728                 abg             a       b       b/g
729    Infra        G(12)           A(8)    B(4)    G(12)
730    Adhoc        A+B(12)         A(8)    B(4)    B(4)
731
732         non-MULTI_BANDS:
733                                         b       b/g
734    Infra                                B(4)    G(12)
735    Adhoc                                B(4)    B(4)
736  */
737 /**
738  *  @brief Get Range Info
739  *
740  *  @param dev                  A pointer to net_device structure
741  *  @param info                 A pointer to iw_request_info structure
742  *  @param vwrq                 A pointer to iw_param structure
743  *  @param extra                A pointer to extra data buf
744  *  @return                     0 --success, otherwise fail
745  */
746 static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
747                           struct iw_point *dwrq, char *extra)
748 {
749         int i, j;
750         wlan_private *priv = dev->priv;
751         wlan_adapter *adapter = priv->adapter;
752         struct iw_range *range = (struct iw_range *)extra;
753         struct chan_freq_power *cfp;
754         u8 rates[WLAN_SUPPORTED_RATES];
755
756         u8 flag = 0;
757
758         ENTER();
759
760         dwrq->length = sizeof(struct iw_range);
761         memset(range, 0, sizeof(struct iw_range));
762
763         range->min_nwid = 0;
764         range->max_nwid = 0;
765
766         memset(rates, 0, sizeof(rates));
767         range->num_bitrates = get_active_data_rates(adapter, rates);
768
769         for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
770              i++) {
771                 range->bitrate[i] = (rates[i] & 0x7f) * 500000;
772         }
773         range->num_bitrates = i;
774         lbs_pr_debug(1, "IW_MAX_BITRATES=%d num_bitrates=%d\n", IW_MAX_BITRATES,
775                range->num_bitrates);
776
777         range->num_frequency = 0;
778         if (priv->adapter->enable11d &&
779             adapter->connect_status == libertas_connected) {
780                 u8 chan_no;
781                 u8 band;
782
783                 struct parsed_region_chan_11d *parsed_region_chan =
784                     &adapter->parsed_region_chan;
785
786                 if (parsed_region_chan == NULL) {
787                         lbs_pr_debug(1, "11D:parsed_region_chan is NULL\n");
788                         LEAVE();
789                         return 0;
790                 }
791                 band = parsed_region_chan->band;
792                 lbs_pr_debug(1, "band=%d NoOfChan=%d\n", band,
793                        parsed_region_chan->nr_chan);
794
795                 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
796                      && (i < parsed_region_chan->nr_chan); i++) {
797                         chan_no = parsed_region_chan->chanpwr[i].chan;
798                         lbs_pr_debug(1, "chan_no=%d\n", chan_no);
799                         range->freq[range->num_frequency].i = (long)chan_no;
800                         range->freq[range->num_frequency].m =
801                             (long)libertas_chan_2_freq(chan_no, band) * 100000;
802                         range->freq[range->num_frequency].e = 1;
803                         range->num_frequency++;
804                 }
805                 flag = 1;
806         }
807         if (!flag) {
808                 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
809                      && (j < sizeof(adapter->region_channel)
810                          / sizeof(adapter->region_channel[0])); j++) {
811                         cfp = adapter->region_channel[j].CFP;
812                         for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
813                              && adapter->region_channel[j].valid
814                              && cfp
815                              && (i < adapter->region_channel[j].nrcfp); i++) {
816                                 range->freq[range->num_frequency].i =
817                                     (long)cfp->channel;
818                                 range->freq[range->num_frequency].m =
819                                     (long)cfp->freq * 100000;
820                                 range->freq[range->num_frequency].e = 1;
821                                 cfp++;
822                                 range->num_frequency++;
823                         }
824                 }
825         }
826
827         lbs_pr_debug(1, "IW_MAX_FREQUENCIES=%d num_frequency=%d\n",
828                IW_MAX_FREQUENCIES, range->num_frequency);
829
830         range->num_channels = range->num_frequency;
831
832         sort_channels(&range->freq[0], range->num_frequency);
833
834         /*
835          * Set an indication of the max TCP throughput in bit/s that we can
836          * expect using this interface
837          */
838         if (i > 2)
839                 range->throughput = 5000 * 1000;
840         else
841                 range->throughput = 1500 * 1000;
842
843         range->min_rts = MRVDRV_RTS_MIN_VALUE;
844         range->max_rts = MRVDRV_RTS_MAX_VALUE;
845         range->min_frag = MRVDRV_FRAG_MIN_VALUE;
846         range->max_frag = MRVDRV_FRAG_MAX_VALUE;
847
848         range->encoding_size[0] = 5;
849         range->encoding_size[1] = 13;
850         range->num_encoding_sizes = 2;
851         range->max_encoding_tokens = 4;
852
853         range->min_pmp = 1000000;
854         range->max_pmp = 120000000;
855         range->min_pmt = 1000;
856         range->max_pmt = 1000000;
857         range->pmp_flags = IW_POWER_PERIOD;
858         range->pmt_flags = IW_POWER_TIMEOUT;
859         range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
860
861         /*
862          * Minimum version we recommend
863          */
864         range->we_version_source = 15;
865
866         /*
867          * Version we are compiled with
868          */
869         range->we_version_compiled = WIRELESS_EXT;
870
871         range->retry_capa = IW_RETRY_LIMIT;
872         range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
873
874         range->min_retry = TX_RETRY_MIN;
875         range->max_retry = TX_RETRY_MAX;
876
877         /*
878          * Set the qual, level and noise range values
879          */
880         range->max_qual.qual = 100;
881         range->max_qual.level = 0;
882         range->max_qual.noise = 0;
883         range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
884
885         range->avg_qual.qual = 70;
886         /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
887         range->avg_qual.level = 0;
888         range->avg_qual.noise = 0;
889         range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
890
891         range->sensitivity = 0;
892
893         /*
894          * Setup the supported power level ranges
895          */
896         memset(range->txpower, 0, sizeof(range->txpower));
897         range->txpower[0] = 5;
898         range->txpower[1] = 7;
899         range->txpower[2] = 9;
900         range->txpower[3] = 11;
901         range->txpower[4] = 13;
902         range->txpower[5] = 15;
903         range->txpower[6] = 17;
904         range->txpower[7] = 19;
905
906         range->num_txpower = 8;
907         range->txpower_capa = IW_TXPOW_DBM;
908         range->txpower_capa |= IW_TXPOW_RANGE;
909
910         range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
911                                 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
912                                 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
913         range->event_capa[1] = IW_EVENT_CAPA_K_1;
914
915         if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
916                 range->enc_capa =   IW_ENC_CAPA_WPA
917                                   | IW_ENC_CAPA_WPA2
918                                   | IW_ENC_CAPA_CIPHER_TKIP
919                                   | IW_ENC_CAPA_CIPHER_CCMP;
920         }
921
922         LEAVE();
923         return 0;
924 }
925
926 static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
927                           struct iw_param *vwrq, char *extra)
928 {
929         wlan_private *priv = dev->priv;
930         wlan_adapter *adapter = priv->adapter;
931
932         ENTER();
933
934         /* PS is currently supported only in Infrastructure mode
935          * Remove this check if it is to be supported in IBSS mode also
936          */
937
938         if (vwrq->disabled) {
939                 adapter->psmode = wlan802_11powermodecam;
940                 if (adapter->psstate != PS_STATE_FULL_POWER) {
941                         libertas_ps_wakeup(priv, cmd_option_waitforrsp);
942                 }
943
944                 return 0;
945         }
946
947         if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
948                 lbs_pr_debug(1,
949                        "Setting power timeout command is not supported\n");
950                 return -EINVAL;
951         } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
952                 lbs_pr_debug(1, "Setting power period command is not supported\n");
953                 return -EINVAL;
954         }
955
956         if (adapter->psmode != wlan802_11powermodecam) {
957                 return 0;
958         }
959
960         adapter->psmode = wlan802_11powermodemax_psp;
961
962         if (adapter->connect_status == libertas_connected) {
963                 libertas_ps_sleep(priv, cmd_option_waitforrsp);
964         }
965
966         LEAVE();
967         return 0;
968 }
969
970 static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
971                           struct iw_param *vwrq, char *extra)
972 {
973         wlan_private *priv = dev->priv;
974         wlan_adapter *adapter = priv->adapter;
975         int mode;
976
977         ENTER();
978
979         mode = adapter->psmode;
980
981         if ((vwrq->disabled = (mode == wlan802_11powermodecam))
982             || adapter->connect_status == libertas_disconnected) {
983                 LEAVE();
984                 return 0;
985         }
986
987         vwrq->value = 0;
988
989         LEAVE();
990         return 0;
991 }
992
993 /*
994  * iwpriv settable callbacks
995  */
996
997 static const iw_handler wlan_private_handler[] = {
998         NULL,                   /* SIOCIWFIRSTPRIV */
999 };
1000
1001 static const struct iw_priv_args wlan_private_args[] = {
1002         /*
1003          * { cmd, set_args, get_args, name }
1004          */
1005         {
1006          WLANSCAN_TYPE,
1007          IW_PRIV_TYPE_CHAR | 8,
1008          IW_PRIV_TYPE_CHAR | 8,
1009          "scantype"},
1010
1011         {
1012          WLAN_SETINT_GETINT,
1013          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1014          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1015          ""},
1016         {
1017          WLANNF,
1018          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1019          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1020          "getNF"},
1021         {
1022          WLANRSSI,
1023          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1024          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1025          "getRSSI"},
1026         {
1027          WLANENABLE11D,
1028          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1029          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1030          "enable11d"},
1031         {
1032          WLANADHOCGRATE,
1033          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1034          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1035          "adhocgrate"},
1036
1037         {
1038          WLAN_SUBCMD_SET_PRESCAN,
1039          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1040          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1041          "prescan"},
1042         {
1043          WLAN_SETONEINT_GETONEINT,
1044          IW_PRIV_TYPE_INT | 1,
1045          IW_PRIV_TYPE_INT | 1,
1046          ""},
1047         {
1048          WLAN_BEACON_INTERVAL,
1049          IW_PRIV_TYPE_INT | 1,
1050          IW_PRIV_TYPE_INT | 1,
1051          "bcninterval"},
1052         {
1053          WLAN_LISTENINTRVL,
1054          IW_PRIV_TYPE_INT | 1,
1055          IW_PRIV_TYPE_INT | 1,
1056          "lolisteninter"},
1057         {
1058          WLAN_TXCONTROL,
1059          IW_PRIV_TYPE_INT | 1,
1060          IW_PRIV_TYPE_INT | 1,
1061          "txcontrol"},
1062         {
1063          WLAN_NULLPKTINTERVAL,
1064          IW_PRIV_TYPE_INT | 1,
1065          IW_PRIV_TYPE_INT | 1,
1066          "psnullinterval"},
1067         /* Using iwpriv sub-command feature */
1068         {
1069          WLAN_SETONEINT_GETNONE,        /* IOCTL: 24 */
1070          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1071          IW_PRIV_TYPE_NONE,
1072          ""},
1073
1074         {
1075          WLAN_SUBCMD_SETRXANTENNA,
1076          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1077          IW_PRIV_TYPE_NONE,
1078          "setrxant"},
1079         {
1080          WLAN_SUBCMD_SETTXANTENNA,
1081          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1082          IW_PRIV_TYPE_NONE,
1083          "settxant"},
1084         {
1085          WLANSETAUTHALG,
1086          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1087          IW_PRIV_TYPE_NONE,
1088          "authalgs",
1089          },
1090         {
1091          WLANSETENCRYPTIONMODE,
1092          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1093          IW_PRIV_TYPE_NONE,
1094          "encryptionmode",
1095          },
1096         {
1097          WLANSETREGION,
1098          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1099          IW_PRIV_TYPE_NONE,
1100          "setregioncode"},
1101         {
1102          WLAN_SET_LISTEN_INTERVAL,
1103          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1104          IW_PRIV_TYPE_NONE,
1105          "setlisteninter"},
1106         {
1107          WLAN_SET_MULTIPLE_DTIM,
1108          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1109          IW_PRIV_TYPE_NONE,
1110          "setmultipledtim"},
1111         {
1112          WLAN_SET_ATIM_WINDOW,
1113          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1114          IW_PRIV_TYPE_NONE,
1115          "atimwindow"},
1116         {
1117          WLANSETBCNAVG,
1118          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1119          IW_PRIV_TYPE_NONE,
1120          "setbcnavg"},
1121         {
1122          WLANSETDATAAVG,
1123          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1124          IW_PRIV_TYPE_NONE,
1125          "setdataavg"},
1126         {
1127          WLAN_SET_LINKMODE,
1128          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1129          IW_PRIV_TYPE_NONE,
1130          "linkmode"},
1131         {
1132          WLAN_SET_RADIOMODE,
1133          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1134          IW_PRIV_TYPE_NONE,
1135          "radiomode"},
1136         {
1137          WLAN_SET_DEBUGMODE,
1138          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1139          IW_PRIV_TYPE_NONE,
1140          "debugmode"},
1141         {
1142          WLAN_SUBCMD_MESH_SET_TTL,
1143          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1144          IW_PRIV_TYPE_NONE,
1145          "mesh_set_ttl"},
1146         {
1147          WLAN_SETNONE_GETONEINT,
1148          IW_PRIV_TYPE_NONE,
1149          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1150          ""},
1151         {
1152          WLANGETREGION,
1153          IW_PRIV_TYPE_NONE,
1154          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1155          "getregioncode"},
1156         {
1157          WLAN_GET_LISTEN_INTERVAL,
1158          IW_PRIV_TYPE_NONE,
1159          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1160          "getlisteninter"},
1161         {
1162          WLAN_GET_MULTIPLE_DTIM,
1163          IW_PRIV_TYPE_NONE,
1164          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1165          "getmultipledtim"},
1166         {
1167          WLAN_GET_TX_RATE,
1168          IW_PRIV_TYPE_NONE,
1169          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1170          "gettxrate"},
1171         {
1172          WLANGETBCNAVG,
1173          IW_PRIV_TYPE_NONE,
1174          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1175          "getbcnavg"},
1176         {
1177          WLAN_GET_LINKMODE,
1178          IW_PRIV_TYPE_NONE,
1179          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1180          "get_linkmode"},
1181         {
1182          WLAN_GET_RADIOMODE,
1183          IW_PRIV_TYPE_NONE,
1184          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1185          "get_radiomode"},
1186         {
1187          WLAN_GET_DEBUGMODE,
1188          IW_PRIV_TYPE_NONE,
1189          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1190          "get_debugmode"},
1191         {
1192          WLAN_SUBCMD_FWT_CLEANUP,
1193          IW_PRIV_TYPE_NONE,
1194          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1195          "fwt_cleanup"},
1196         {
1197          WLAN_SUBCMD_FWT_TIME,
1198          IW_PRIV_TYPE_NONE,
1199          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1200          "fwt_time"},
1201         {
1202          WLAN_SUBCMD_MESH_GET_TTL,
1203          IW_PRIV_TYPE_NONE,
1204          IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1205          "mesh_get_ttl"},
1206         {
1207          WLAN_SETNONE_GETTWELVE_CHAR,
1208          IW_PRIV_TYPE_NONE,
1209          IW_PRIV_TYPE_CHAR | 12,
1210          ""},
1211         {
1212          WLAN_SUBCMD_GETRXANTENNA,
1213          IW_PRIV_TYPE_NONE,
1214          IW_PRIV_TYPE_CHAR | 12,
1215          "getrxant"},
1216         {
1217          WLAN_SUBCMD_GETTXANTENNA,
1218          IW_PRIV_TYPE_NONE,
1219          IW_PRIV_TYPE_CHAR | 12,
1220          "gettxant"},
1221         {
1222          WLAN_GET_TSF,
1223          IW_PRIV_TYPE_NONE,
1224          IW_PRIV_TYPE_CHAR | 12,
1225          "gettsf"},
1226         {
1227          WLAN_SETNONE_GETNONE,
1228          IW_PRIV_TYPE_NONE,
1229          IW_PRIV_TYPE_NONE,
1230          ""},
1231         {
1232          WLANDEAUTH,
1233          IW_PRIV_TYPE_NONE,
1234          IW_PRIV_TYPE_NONE,
1235          "deauth"},
1236         {
1237          WLANADHOCSTOP,
1238          IW_PRIV_TYPE_NONE,
1239          IW_PRIV_TYPE_NONE,
1240          "adhocstop"},
1241         {
1242          WLANRADIOON,
1243          IW_PRIV_TYPE_NONE,
1244          IW_PRIV_TYPE_NONE,
1245          "radioon"},
1246         {
1247          WLANRADIOOFF,
1248          IW_PRIV_TYPE_NONE,
1249          IW_PRIV_TYPE_NONE,
1250          "radiooff"},
1251         {
1252          WLANWLANIDLEON,
1253          IW_PRIV_TYPE_NONE,
1254          IW_PRIV_TYPE_NONE,
1255          "wlanidle-on"},
1256         {
1257          WLANWLANIDLEOFF,
1258          IW_PRIV_TYPE_NONE,
1259          IW_PRIV_TYPE_NONE,
1260          "wlanidle-off"},
1261         {
1262          WLAN_SUBCMD_FWT_RESET,
1263          IW_PRIV_TYPE_NONE,
1264          IW_PRIV_TYPE_NONE,
1265          "fwt_reset"},
1266         {
1267          WLAN_SUBCMD_BT_RESET,
1268          IW_PRIV_TYPE_NONE,
1269          IW_PRIV_TYPE_NONE,
1270          "bt_reset"},
1271         {
1272          WLAN_SET128CHAR_GET128CHAR,
1273          IW_PRIV_TYPE_CHAR | 128,
1274          IW_PRIV_TYPE_CHAR | 128,
1275          ""},
1276         /* BT Management */
1277         {
1278          WLAN_SUBCMD_BT_ADD,
1279          IW_PRIV_TYPE_CHAR | 128,
1280          IW_PRIV_TYPE_CHAR | 128,
1281          "bt_add"},
1282         {
1283          WLAN_SUBCMD_BT_DEL,
1284          IW_PRIV_TYPE_CHAR | 128,
1285          IW_PRIV_TYPE_CHAR | 128,
1286          "bt_del"},
1287         {
1288          WLAN_SUBCMD_BT_LIST,
1289          IW_PRIV_TYPE_CHAR | 128,
1290          IW_PRIV_TYPE_CHAR | 128,
1291          "bt_list"},
1292         /* FWT Management */
1293         {
1294          WLAN_SUBCMD_FWT_ADD,
1295          IW_PRIV_TYPE_CHAR | 128,
1296          IW_PRIV_TYPE_CHAR | 128,
1297          "fwt_add"},
1298         {
1299          WLAN_SUBCMD_FWT_DEL,
1300          IW_PRIV_TYPE_CHAR | 128,
1301          IW_PRIV_TYPE_CHAR | 128,
1302          "fwt_del"},
1303         {
1304          WLAN_SUBCMD_FWT_LOOKUP,
1305          IW_PRIV_TYPE_CHAR | 128,
1306          IW_PRIV_TYPE_CHAR | 128,
1307          "fwt_lookup"},
1308         {
1309          WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
1310          IW_PRIV_TYPE_CHAR | 128,
1311          IW_PRIV_TYPE_CHAR | 128,
1312          "fwt_list_neigh"},
1313         {
1314          WLAN_SUBCMD_FWT_LIST,
1315          IW_PRIV_TYPE_CHAR | 128,
1316          IW_PRIV_TYPE_CHAR | 128,
1317          "fwt_list"},
1318         {
1319          WLAN_SUBCMD_FWT_LIST_ROUTE,
1320          IW_PRIV_TYPE_CHAR | 128,
1321          IW_PRIV_TYPE_CHAR | 128,
1322          "fwt_list_route"},
1323         {
1324          WLANSCAN_MODE,
1325          IW_PRIV_TYPE_CHAR | 128,
1326          IW_PRIV_TYPE_CHAR | 128,
1327          "scanmode"},
1328         {
1329          WLAN_GET_ADHOC_STATUS,
1330          IW_PRIV_TYPE_CHAR | 128,
1331          IW_PRIV_TYPE_CHAR | 128,
1332          "getadhocstatus"},
1333         {
1334          WLAN_SETNONE_GETWORDCHAR,
1335          IW_PRIV_TYPE_NONE,
1336          IW_PRIV_TYPE_CHAR | 128,
1337          ""},
1338         {
1339          WLANSETWPAIE,
1340          IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | 24,
1341          IW_PRIV_TYPE_NONE,
1342          "setwpaie"},
1343         {
1344          WLANGETLOG,
1345          IW_PRIV_TYPE_NONE,
1346          IW_PRIV_TYPE_CHAR | GETLOG_BUFSIZE,
1347          "getlog"},
1348         {
1349          WLAN_SET_GET_SIXTEEN_INT,
1350          IW_PRIV_TYPE_INT | 16,
1351          IW_PRIV_TYPE_INT | 16,
1352          ""},
1353         {
1354          WLAN_TPCCFG,
1355          IW_PRIV_TYPE_INT | 16,
1356          IW_PRIV_TYPE_INT | 16,
1357          "tpccfg"},
1358         {
1359          WLAN_POWERCFG,
1360          IW_PRIV_TYPE_INT | 16,
1361          IW_PRIV_TYPE_INT | 16,
1362          "powercfg"},
1363         {
1364          WLAN_AUTO_FREQ_SET,
1365          IW_PRIV_TYPE_INT | 16,
1366          IW_PRIV_TYPE_INT | 16,
1367          "setafc"},
1368         {
1369          WLAN_AUTO_FREQ_GET,
1370          IW_PRIV_TYPE_INT | 16,
1371          IW_PRIV_TYPE_INT | 16,
1372          "getafc"},
1373         {
1374          WLAN_SCANPROBES,
1375          IW_PRIV_TYPE_INT | 16,
1376          IW_PRIV_TYPE_INT | 16,
1377          "scanprobes"},
1378         {
1379          WLAN_LED_GPIO_CTRL,
1380          IW_PRIV_TYPE_INT | 16,
1381          IW_PRIV_TYPE_INT | 16,
1382          "ledgpio"},
1383         {
1384          WLAN_ADAPT_RATESET,
1385          IW_PRIV_TYPE_INT | 16,
1386          IW_PRIV_TYPE_INT | 16,
1387          "rateadapt"},
1388         {
1389          WLAN_INACTIVITY_TIMEOUT,
1390          IW_PRIV_TYPE_INT | 16,
1391          IW_PRIV_TYPE_INT | 16,
1392          "inactivityto"},
1393         {
1394          WLANSNR,
1395          IW_PRIV_TYPE_INT | 16,
1396          IW_PRIV_TYPE_INT | 16,
1397          "getSNR"},
1398         {
1399          WLAN_GET_RATE,
1400          IW_PRIV_TYPE_INT | 16,
1401          IW_PRIV_TYPE_INT | 16,
1402          "getrate"},
1403         {
1404          WLAN_GET_RXINFO,
1405          IW_PRIV_TYPE_INT | 16,
1406          IW_PRIV_TYPE_INT | 16,
1407          "getrxinfo"},
1408 };
1409
1410 static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
1411 {
1412         enum {
1413                 POOR = 30,
1414                 FAIR = 60,
1415                 GOOD = 80,
1416                 VERY_GOOD = 90,
1417                 EXCELLENT = 95,
1418                 PERFECT = 100
1419         };
1420         wlan_private *priv = dev->priv;
1421         wlan_adapter *adapter = priv->adapter;
1422         u32 rssi_qual;
1423         u32 tx_qual;
1424         u32 quality = 0;
1425         int stats_valid = 0;
1426         u8 rssi;
1427         u32 tx_retries;
1428
1429         ENTER();
1430
1431         priv->wstats.status = adapter->inframode;
1432
1433         /* If we're not associated, all quality values are meaningless */
1434         if (adapter->connect_status != libertas_connected)
1435                 goto out;
1436
1437         /* Quality by RSSI */
1438         priv->wstats.qual.level =
1439             CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
1440              adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1441
1442         if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1443                 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1444         } else {
1445                 priv->wstats.qual.noise =
1446                     CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1447         }
1448
1449         lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
1450         lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
1451
1452         rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
1453         if (rssi < 15)
1454                 rssi_qual = rssi * POOR / 10;
1455         else if (rssi < 20)
1456                 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
1457         else if (rssi < 30)
1458                 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
1459         else if (rssi < 40)
1460                 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
1461                     10 + GOOD;
1462         else
1463                 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
1464                     10 + VERY_GOOD;
1465         quality = rssi_qual;
1466
1467         /* Quality by TX errors */
1468         priv->wstats.discard.retries = priv->stats.tx_errors;
1469
1470         tx_retries = adapter->logmsg.retry;
1471
1472         if (tx_retries > 75)
1473                 tx_qual = (90 - tx_retries) * POOR / 15;
1474         else if (tx_retries > 70)
1475                 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
1476         else if (tx_retries > 65)
1477                 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
1478         else if (tx_retries > 50)
1479                 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
1480                     15 + GOOD;
1481         else
1482                 tx_qual = (50 - tx_retries) *
1483                     (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
1484         quality = min(quality, tx_qual);
1485
1486         priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
1487         priv->wstats.discard.fragment = adapter->logmsg.fcserror;
1488         priv->wstats.discard.retries = tx_retries;
1489         priv->wstats.discard.misc = adapter->logmsg.ackfailure;
1490
1491         /* Calculate quality */
1492         priv->wstats.qual.qual = max(quality, (u32)100);
1493         priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1494         stats_valid = 1;
1495
1496         /* update stats asynchronously for future calls */
1497         libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
1498                                         0, 0, NULL);
1499         libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
1500                                         0, 0, NULL);
1501 out:
1502         if (!stats_valid) {
1503                 priv->wstats.miss.beacon = 0;
1504                 priv->wstats.discard.retries = 0;
1505                 priv->wstats.qual.qual = 0;
1506                 priv->wstats.qual.level = 0;
1507                 priv->wstats.qual.noise = 0;
1508                 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
1509                 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
1510                     IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
1511         }
1512
1513         LEAVE ();
1514         return &priv->wstats;
1515
1516
1517 }
1518
1519 static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
1520                   struct iw_freq *fwrq, char *extra)
1521 {
1522         int ret = 0;
1523         wlan_private *priv = dev->priv;
1524         wlan_adapter *adapter = priv->adapter;
1525         int rc = -EINPROGRESS;  /* Call commit handler */
1526         struct chan_freq_power *cfp;
1527
1528         ENTER();
1529
1530         /*
1531          * If setting by frequency, convert to a channel
1532          */
1533         if (fwrq->e == 1) {
1534
1535                 long f = fwrq->m / 100000;
1536                 int c = 0;
1537
1538                 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
1539                 if (!cfp) {
1540                         lbs_pr_debug(1, "Invalid freq=%ld\n", f);
1541                         return -EINVAL;
1542                 }
1543
1544                 c = (int)cfp->channel;
1545
1546                 if (c < 0)
1547                         return -EINVAL;
1548
1549                 fwrq->e = 0;
1550                 fwrq->m = c;
1551         }
1552
1553         /*
1554          * Setting by channel number
1555          */
1556         if (fwrq->m > 1000 || fwrq->e > 0) {
1557                 rc = -EOPNOTSUPP;
1558         } else {
1559                 int channel = fwrq->m;
1560
1561                 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel);
1562                 if (!cfp) {
1563                         rc = -EINVAL;
1564                 } else {
1565                         if (adapter->inframode == wlan802_11ibss) {
1566                                 rc = changeadhocchannel(priv, channel);
1567                                 /*  If station is WEP enabled, send the
1568                                  *  command to set WEP in firmware
1569                                  */
1570                                 if (adapter->secinfo.WEPstatus ==
1571                                     wlan802_11WEPenabled) {
1572                                         lbs_pr_debug(1, "set_freq: WEP enabled\n");
1573                                         ret = libertas_prepare_and_send_command(priv,
1574                                                                     cmd_802_11_set_wep,
1575                                                                     cmd_act_add,
1576                                                                     cmd_option_waitforrsp,
1577                                                                     0,
1578                                                                     NULL);
1579
1580                                         if (ret) {
1581                                                 LEAVE();
1582                                                 return ret;
1583                                         }
1584
1585                                         adapter->currentpacketfilter |=
1586                                             cmd_act_mac_wep_enable;
1587
1588                                         libertas_set_mac_packet_filter(priv);
1589                                 }
1590                         } else {
1591                                 rc = -EOPNOTSUPP;
1592                         }
1593                 }
1594         }
1595
1596         LEAVE();
1597         return rc;
1598 }
1599
1600 /**
1601  *  @brief use index to get the data rate
1602  *
1603  *  @param index                The index of data rate
1604  *  @return                     data rate or 0
1605  */
1606 u32 libertas_index_to_data_rate(u8 index)
1607 {
1608         if (index >= sizeof(libertas_wlan_data_rates))
1609                 index = 0;
1610
1611         return libertas_wlan_data_rates[index];
1612 }
1613
1614 /**
1615  *  @brief use rate to get the index
1616  *
1617  *  @param rate                 data rate
1618  *  @return                     index or 0
1619  */
1620 u8 libertas_data_rate_to_index(u32 rate)
1621 {
1622         u8 *ptr;
1623
1624         if (rate)
1625                 if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
1626                                   sizeof(libertas_wlan_data_rates))))
1627                         return (ptr - libertas_wlan_data_rates);
1628
1629         return 0;
1630 }
1631
1632 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
1633                   struct iw_param *vwrq, char *extra)
1634 {
1635         wlan_private *priv = dev->priv;
1636         wlan_adapter *adapter = priv->adapter;
1637         u32 data_rate;
1638         u16 action;
1639         int ret = 0;
1640         u8 rates[WLAN_SUPPORTED_RATES];
1641         u8 *rate;
1642
1643         ENTER();
1644
1645         lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
1646
1647         if (vwrq->value == -1) {
1648                 action = cmd_act_set_tx_auto;   // Auto
1649                 adapter->is_datarate_auto = 1;
1650                 adapter->datarate = 0;
1651         } else {
1652                 if (vwrq->value % 100000) {
1653                         return -EINVAL;
1654                 }
1655
1656                 data_rate = vwrq->value / 500000;
1657
1658                 memset(rates, 0, sizeof(rates));
1659                 get_active_data_rates(adapter, rates);
1660                 rate = rates;
1661                 while (*rate) {
1662                         lbs_pr_debug(1, "Rate=0x%X  Wanted=0x%X\n", *rate,
1663                                data_rate);
1664                         if ((*rate & 0x7f) == (data_rate & 0x7f))
1665                                 break;
1666                         rate++;
1667                 }
1668                 if (!*rate) {
1669                         lbs_pr_alert( "The fixed data rate 0x%X is out "
1670                                "of range.\n", data_rate);
1671                         return -EINVAL;
1672                 }
1673
1674                 adapter->datarate = data_rate;
1675                 action = cmd_act_set_tx_fix_rate;
1676                 adapter->is_datarate_auto = 0;
1677         }
1678
1679         ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
1680                                     action, cmd_option_waitforrsp, 0, NULL);
1681
1682         LEAVE();
1683         return ret;
1684 }
1685
1686 static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1687                   struct iw_param *vwrq, char *extra)
1688 {
1689         wlan_private *priv = dev->priv;
1690         wlan_adapter *adapter = priv->adapter;
1691
1692         ENTER();
1693
1694         if (adapter->is_datarate_auto) {
1695                 vwrq->fixed = 0;
1696         } else {
1697                 vwrq->fixed = 1;
1698         }
1699
1700         vwrq->value = adapter->datarate * 500000;
1701
1702         LEAVE();
1703         return 0;
1704 }
1705
1706 static int wlan_set_mode(struct net_device *dev,
1707                   struct iw_request_info *info, u32 * uwrq, char *extra)
1708 {
1709         int ret = 0;
1710         wlan_private *priv = dev->priv;
1711         wlan_adapter *adapter = priv->adapter;
1712         struct assoc_request * assoc_req;
1713         enum WLAN_802_11_NETWORK_INFRASTRUCTURE new_mode;
1714
1715         ENTER();
1716
1717         switch (*uwrq) {
1718         case IW_MODE_ADHOC:
1719                 lbs_pr_debug(1, "Wanted mode is ad-hoc: current datarate=%#x\n",
1720                        adapter->datarate);
1721                 new_mode = wlan802_11ibss;
1722                 adapter->adhocchannel = DEFAULT_AD_HOC_CHANNEL;
1723                 break;
1724
1725         case IW_MODE_INFRA:
1726                 lbs_pr_debug(1, "Wanted mode is Infrastructure\n");
1727                 new_mode = wlan802_11infrastructure;
1728                 break;
1729
1730         case IW_MODE_AUTO:
1731                 lbs_pr_debug(1, "Wanted mode is Auto\n");
1732                 new_mode = wlan802_11autounknown;
1733                 break;
1734
1735         default:
1736                 lbs_pr_debug(1, "Wanted mode is Unknown: 0x%x\n", *uwrq);
1737                 return -EINVAL;
1738         }
1739
1740         mutex_lock(&adapter->lock);
1741         assoc_req = wlan_get_association_request(adapter);
1742         if (!assoc_req) {
1743                 ret = -ENOMEM;
1744         } else {
1745                 assoc_req->mode = new_mode;
1746         }
1747
1748         if (ret == 0) {
1749                 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1750                 wlan_postpone_association_work(priv);
1751         } else {
1752                 wlan_cancel_association_work(priv);
1753         }
1754         mutex_unlock(&adapter->lock);
1755
1756         LEAVE();
1757         return ret;
1758 }
1759
1760
1761 /**
1762  *  @brief Get Encryption key
1763  *
1764  *  @param dev                  A pointer to net_device structure
1765  *  @param info                 A pointer to iw_request_info structure
1766  *  @param vwrq                 A pointer to iw_param structure
1767  *  @param extra                A pointer to extra data buf
1768  *  @return                     0 --success, otherwise fail
1769  */
1770 static int wlan_get_encode(struct net_device *dev,
1771                            struct iw_request_info *info,
1772                            struct iw_point *dwrq, u8 * extra)
1773 {
1774         wlan_private *priv = dev->priv;
1775         wlan_adapter *adapter = priv->adapter;
1776         int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1777
1778         ENTER();
1779
1780         lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
1781                dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1782
1783         dwrq->flags = 0;
1784
1785         /* Authentication method */
1786         switch (adapter->secinfo.authmode) {
1787         case wlan802_11authmodeopen:
1788                 dwrq->flags = IW_ENCODE_OPEN;
1789                 break;
1790
1791         case wlan802_11authmodeshared:
1792         case wlan802_11authmodenetworkEAP:
1793                 dwrq->flags = IW_ENCODE_RESTRICTED;
1794                 break;
1795         default:
1796                 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1797                 break;
1798         }
1799
1800         if ((adapter->secinfo.WEPstatus == wlan802_11WEPenabled)
1801             || adapter->secinfo.WPAenabled || adapter->secinfo.WPA2enabled) {
1802                 dwrq->flags &= ~IW_ENCODE_DISABLED;
1803         } else {
1804                 dwrq->flags |= IW_ENCODE_DISABLED;
1805         }
1806
1807         memset(extra, 0, 16);
1808
1809         mutex_lock(&adapter->lock);
1810
1811         /* Default to returning current transmit key */
1812         if (index < 0)
1813                 index = adapter->wep_tx_keyidx;
1814
1815         if ((adapter->wep_keys[index].len) &&
1816             (adapter->secinfo.WEPstatus == wlan802_11WEPenabled)) {
1817                 memcpy(extra, adapter->wep_keys[index].key,
1818                        adapter->wep_keys[index].len);
1819                 dwrq->length = adapter->wep_keys[index].len;
1820
1821                 dwrq->flags |= (index + 1);
1822                 /* Return WEP enabled */
1823                 dwrq->flags &= ~IW_ENCODE_DISABLED;
1824         } else if ((adapter->secinfo.WPAenabled)
1825                    || (adapter->secinfo.WPA2enabled)) {
1826                 /* return WPA enabled */
1827                 dwrq->flags &= ~IW_ENCODE_DISABLED;
1828         } else {
1829                 dwrq->flags |= IW_ENCODE_DISABLED;
1830         }
1831
1832         mutex_unlock(&adapter->lock);
1833
1834         dwrq->flags |= IW_ENCODE_NOKEY;
1835
1836         lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
1837                extra[0], extra[1], extra[2],
1838                extra[3], extra[4], extra[5], dwrq->length);
1839
1840         lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
1841
1842         LEAVE();
1843         return 0;
1844 }
1845
1846 /**
1847  *  @brief Set Encryption key (internal)
1848  *
1849  *  @param priv                 A pointer to private card structure
1850  *  @param key_material         A pointer to key material
1851  *  @param key_length           length of key material
1852  *  @param index                key index to set
1853  *  @param set_tx_key           Force set TX key (1 = yes, 0 = no)
1854  *  @return                     0 --success, otherwise fail
1855  */
1856 static int wlan_set_wep_key(struct assoc_request *assoc_req,
1857                             const char *key_material,
1858                             u16 key_length,
1859                             u16 index,
1860                             int set_tx_key)
1861 {
1862         struct WLAN_802_11_KEY *pkey;
1863
1864         ENTER();
1865
1866         /* Paranoid validation of key index */
1867         if (index > 3) {
1868                 LEAVE();
1869                 return -EINVAL;
1870         }
1871
1872         /* validate max key length */
1873         if (key_length > KEY_LEN_WEP_104) {
1874                 LEAVE();
1875                 return -EINVAL;
1876         }
1877
1878         pkey = &assoc_req->wep_keys[index];
1879
1880         if (key_length > 0) {
1881                 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
1882                 pkey->type = KEY_TYPE_ID_WEP;
1883
1884                 /* Standardize the key length */
1885                 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1886                                 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1887                 memcpy(pkey->key, key_material, key_length);
1888         }
1889
1890         if (set_tx_key) {
1891                 /* Ensure the chosen key is valid */
1892                 if (!pkey->len) {
1893                         lbs_pr_debug(1, "key not set, so cannot enable it\n");
1894                         LEAVE();
1895                         return -EINVAL;
1896                 }
1897                 assoc_req->wep_tx_keyidx = index;
1898         }
1899
1900         assoc_req->secinfo.WEPstatus = wlan802_11WEPenabled;
1901
1902         LEAVE();
1903         return 0;
1904 }
1905
1906 static int validate_key_index(u16 def_index, u16 raw_index,
1907                               u16 *out_index, u16 *is_default)
1908 {
1909         if (!out_index || !is_default)
1910                 return -EINVAL;
1911
1912         /* Verify index if present, otherwise use default TX key index */
1913         if (raw_index > 0) {
1914                 if (raw_index > 4)
1915                         return -EINVAL;
1916                 *out_index = raw_index - 1;
1917         } else {
1918                 *out_index = def_index;
1919                 *is_default = 1;
1920         }
1921         return 0;
1922 }
1923
1924 static void disable_wep(struct assoc_request *assoc_req)
1925 {
1926         int i;
1927
1928         /* Set Open System auth mode */
1929         assoc_req->secinfo.authmode = wlan802_11authmodeopen;
1930
1931         /* Clear WEP keys and mark WEP as disabled */
1932         assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
1933         for (i = 0; i < 4; i++)
1934                 assoc_req->wep_keys[i].len = 0;
1935
1936         set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1937         set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1938 }
1939
1940 /**
1941  *  @brief Set Encryption key
1942  *
1943  *  @param dev                  A pointer to net_device structure
1944  *  @param info                 A pointer to iw_request_info structure
1945  *  @param vwrq                 A pointer to iw_param structure
1946  *  @param extra                A pointer to extra data buf
1947  *  @return                     0 --success, otherwise fail
1948  */
1949 static int wlan_set_encode(struct net_device *dev,
1950                     struct iw_request_info *info,
1951                     struct iw_point *dwrq, char *extra)
1952 {
1953         int ret = 0;
1954         wlan_private *priv = dev->priv;
1955         wlan_adapter *adapter = priv->adapter;
1956         struct assoc_request * assoc_req;
1957         u16 is_default = 0, index = 0, set_tx_key = 0;
1958
1959         ENTER();
1960
1961         mutex_lock(&adapter->lock);
1962         assoc_req = wlan_get_association_request(adapter);
1963         if (!assoc_req) {
1964                 ret = -ENOMEM;
1965                 goto out;
1966         }
1967
1968         if (dwrq->flags & IW_ENCODE_DISABLED) {
1969                 disable_wep (assoc_req);
1970                 goto out;
1971         }
1972
1973         ret = validate_key_index(assoc_req->wep_tx_keyidx,
1974                                  (dwrq->flags & IW_ENCODE_INDEX),
1975                                  &index, &is_default);
1976         if (ret) {
1977                 ret = -EINVAL;
1978                 goto out;
1979         }
1980
1981         /* If WEP isn't enabled, or if there is no key data but a valid
1982          * index, set the TX key.
1983          */
1984         if ((assoc_req->secinfo.WEPstatus != wlan802_11WEPenabled)
1985             || (dwrq->length == 0 && !is_default))
1986                 set_tx_key = 1;
1987
1988         ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1989         if (ret)
1990                 goto out;
1991
1992         if (dwrq->length)
1993                 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1994         if (set_tx_key)
1995                 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1996
1997         if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1998                 assoc_req->secinfo.authmode = wlan802_11authmodeshared;
1999         } else if (dwrq->flags & IW_ENCODE_OPEN) {
2000                 assoc_req->secinfo.authmode = wlan802_11authmodeopen;
2001         }
2002
2003 out:
2004         if (ret == 0) {
2005                 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2006                 wlan_postpone_association_work(priv);
2007         } else {
2008                 wlan_cancel_association_work(priv);
2009         }
2010         mutex_unlock(&adapter->lock);
2011
2012         LEAVE();
2013         return ret;
2014 }
2015
2016 /**
2017  *  @brief Get Extended Encryption key (WPA/802.1x and WEP)
2018  *
2019  *  @param dev                  A pointer to net_device structure
2020  *  @param info                 A pointer to iw_request_info structure
2021  *  @param vwrq                 A pointer to iw_param structure
2022  *  @param extra                A pointer to extra data buf
2023  *  @return                     0 on success, otherwise failure
2024  */
2025 static int wlan_get_encodeext(struct net_device *dev,
2026                               struct iw_request_info *info,
2027                               struct iw_point *dwrq,
2028                               char *extra)
2029 {
2030         int ret = -EINVAL;
2031         wlan_private *priv = dev->priv;
2032         wlan_adapter *adapter = priv->adapter;
2033         struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2034         int index, max_key_len;
2035
2036         ENTER();
2037
2038         max_key_len = dwrq->length - sizeof(*ext);
2039         if (max_key_len < 0)
2040                 goto out;
2041
2042         index = dwrq->flags & IW_ENCODE_INDEX;
2043         if (index) {
2044                 if (index < 1 || index > 4)
2045                         goto out;
2046                 index--;
2047         } else {
2048                 index = adapter->wep_tx_keyidx;
2049         }
2050
2051         if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
2052             ext->alg != IW_ENCODE_ALG_WEP) {
2053                 if (index != 0 || adapter->inframode != wlan802_11infrastructure)
2054                         goto out;
2055         }
2056
2057         dwrq->flags = index + 1;
2058         memset(ext, 0, sizeof(*ext));
2059
2060         if ((adapter->secinfo.WEPstatus == wlan802_11WEPdisabled)
2061             && !adapter->secinfo.WPAenabled && !adapter->secinfo.WPA2enabled) {
2062                 ext->alg = IW_ENCODE_ALG_NONE;
2063                 ext->key_len = 0;
2064                 dwrq->flags |= IW_ENCODE_DISABLED;
2065         } else {
2066                 u8 *key = NULL;
2067
2068                 if ((adapter->secinfo.WEPstatus == wlan802_11WEPenabled)
2069                     && !adapter->secinfo.WPAenabled
2070                     && !adapter->secinfo.WPA2enabled) {
2071                         ext->alg = IW_ENCODE_ALG_WEP;
2072                         ext->key_len = adapter->wep_keys[index].len;
2073                         key = &adapter->wep_keys[index].key[0];
2074                 } else if ((adapter->secinfo.WEPstatus == wlan802_11WEPdisabled) &&
2075                            (adapter->secinfo.WPAenabled ||
2076                             adapter->secinfo.WPA2enabled)) {
2077                         /* WPA */
2078                         ext->alg = IW_ENCODE_ALG_TKIP;
2079                         ext->key_len = 0;
2080                 } else {
2081                         goto out;
2082                 }
2083
2084                 if (ext->key_len > max_key_len) {
2085                         ret = -E2BIG;
2086                         goto out;
2087                 }
2088
2089                 if (ext->key_len)
2090                         memcpy(ext->key, key, ext->key_len);
2091                 else
2092                         dwrq->flags |= IW_ENCODE_NOKEY;
2093                 dwrq->flags |= IW_ENCODE_ENABLED;
2094         }
2095         ret = 0;
2096
2097 out:
2098         LEAVE();
2099         return ret;
2100 }
2101
2102 /**
2103  *  @brief Set Encryption key Extended (WPA/802.1x and WEP)
2104  *
2105  *  @param dev                  A pointer to net_device structure
2106  *  @param info                 A pointer to iw_request_info structure
2107  *  @param vwrq                 A pointer to iw_param structure
2108  *  @param extra                A pointer to extra data buf
2109  *  @return                     0 --success, otherwise fail
2110  */
2111 static int wlan_set_encodeext(struct net_device *dev,
2112                               struct iw_request_info *info,
2113                               struct iw_point *dwrq,
2114                               char *extra)
2115 {
2116         int ret = 0;
2117         wlan_private *priv = dev->priv;
2118         wlan_adapter *adapter = priv->adapter;
2119         struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2120         int alg = ext->alg;
2121         struct assoc_request * assoc_req;
2122
2123         ENTER();
2124
2125         mutex_lock(&adapter->lock);
2126         assoc_req = wlan_get_association_request(adapter);
2127         if (!assoc_req) {
2128                 ret = -ENOMEM;
2129                 goto out;
2130         }
2131
2132         if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
2133                 disable_wep (assoc_req);
2134         } else if (alg == IW_ENCODE_ALG_WEP) {
2135                 u16 is_default = 0, index, set_tx_key = 0;
2136
2137                 ret = validate_key_index(assoc_req->wep_tx_keyidx,
2138                                          (dwrq->flags & IW_ENCODE_INDEX),
2139                                          &index, &is_default);
2140                 if (ret)
2141                         goto out;
2142
2143                 /* If WEP isn't enabled, or if there is no key data but a valid
2144                  * index, or if the set-TX-key flag was passed, set the TX key.
2145                  */
2146                 if ((assoc_req->secinfo.WEPstatus != wlan802_11WEPenabled)
2147                     || (dwrq->length == 0 && !is_default)
2148                     || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
2149                         set_tx_key = 1;
2150
2151                 /* Copy key to driver */
2152                 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
2153                                         set_tx_key);
2154                 if (ret)
2155                         goto out;
2156
2157                 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
2158                         assoc_req->secinfo.authmode =
2159                             wlan802_11authmodeshared;
2160                 } else if (dwrq->flags & IW_ENCODE_OPEN) {
2161                         assoc_req->secinfo.authmode =
2162                             wlan802_11authmodeopen;
2163                 }
2164
2165                 /* Mark the various WEP bits as modified */
2166                 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2167                 if (dwrq->length)
2168                         set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
2169                 if (set_tx_key)
2170                         set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
2171
2172         } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
2173                 struct WLAN_802_11_KEY * pkey;
2174
2175                 /* validate key length */
2176                 if (((alg == IW_ENCODE_ALG_TKIP)
2177                         && (ext->key_len != KEY_LEN_WPA_TKIP))
2178                     || ((alg == IW_ENCODE_ALG_CCMP)
2179                         && (ext->key_len != KEY_LEN_WPA_AES))) {
2180                                 lbs_pr_debug(1, "Invalid size %d for key of alg"
2181                                        "type %d.\n",
2182                                        ext->key_len,
2183                                        alg);
2184                                 ret = -EINVAL;
2185                                 goto out;
2186                 }
2187
2188                 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2189                         pkey = &assoc_req->wpa_mcast_key;
2190                 else
2191                         pkey = &assoc_req->wpa_unicast_key;
2192
2193                 memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
2194                 memcpy(pkey->key, ext->key, ext->key_len);
2195                 pkey->len = ext->key_len;
2196                 pkey->flags = KEY_INFO_WPA_ENABLED;
2197
2198                 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
2199                         pkey->flags |= KEY_INFO_WPA_MCAST;
2200                         set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
2201                 } else {
2202                         pkey->flags |= KEY_INFO_WPA_UNICAST;
2203                         set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
2204                 }
2205
2206                 if (alg == IW_ENCODE_ALG_TKIP)
2207                         pkey->type = KEY_TYPE_ID_TKIP;
2208                 else if (alg == IW_ENCODE_ALG_CCMP)
2209                         pkey->type = KEY_TYPE_ID_AES;
2210
2211                 /* If WPA isn't enabled yet, do that now */
2212                 if (   assoc_req->secinfo.WPAenabled == 0
2213                     && assoc_req->secinfo.WPA2enabled == 0) {
2214                         assoc_req->secinfo.WPAenabled = 1;
2215                         assoc_req->secinfo.WPA2enabled = 1;
2216                         set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2217                 }
2218
2219                 disable_wep (assoc_req);
2220         }
2221
2222 out:
2223         if (ret == 0) {
2224                 wlan_postpone_association_work(priv);
2225         } else {
2226                 wlan_cancel_association_work(priv);
2227         }
2228         mutex_unlock(&adapter->lock);
2229
2230         LEAVE();
2231         return ret;
2232 }
2233
2234
2235 static int wlan_set_genie(struct net_device *dev,
2236                           struct iw_request_info *info,
2237                           struct iw_point *dwrq,
2238                           char *extra)
2239 {
2240         wlan_private *priv = dev->priv;
2241         wlan_adapter *adapter = priv->adapter;
2242         int ret = 0;
2243         struct assoc_request * assoc_req;
2244
2245         ENTER();
2246
2247         mutex_lock(&adapter->lock);
2248         assoc_req = wlan_get_association_request(adapter);
2249         if (!assoc_req) {
2250                 ret = -ENOMEM;
2251                 goto out;
2252         }
2253
2254         if (dwrq->length > MAX_WPA_IE_LEN ||
2255             (dwrq->length && extra == NULL)) {
2256                 ret = -EINVAL;
2257                 goto out;
2258         }
2259
2260         if (dwrq->length) {
2261                 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
2262                 assoc_req->wpa_ie_len = dwrq->length;
2263         } else {
2264                 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
2265                 assoc_req->wpa_ie_len = 0;
2266         }
2267
2268 out:
2269         if (ret == 0) {
2270                 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
2271                 wlan_postpone_association_work(priv);
2272         } else {
2273                 wlan_cancel_association_work(priv);
2274         }
2275         mutex_unlock(&adapter->lock);
2276
2277         LEAVE();
2278         return ret;
2279 }
2280
2281 static int wlan_get_genie(struct net_device *dev,
2282                           struct iw_request_info *info,
2283                           struct iw_point *dwrq,
2284                           char *extra)
2285 {
2286         wlan_private *priv = dev->priv;
2287         wlan_adapter *adapter = priv->adapter;
2288
2289         ENTER();
2290
2291         if (adapter->wpa_ie_len == 0) {
2292                 dwrq->length = 0;
2293                 LEAVE();
2294                 return 0;
2295         }
2296
2297         if (dwrq->length < adapter->wpa_ie_len) {
2298                 LEAVE();
2299                 return -E2BIG;
2300         }
2301
2302         dwrq->length = adapter->wpa_ie_len;
2303         memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
2304
2305         LEAVE();
2306         return 0;
2307 }
2308
2309
2310 static int wlan_set_auth(struct net_device *dev,
2311                          struct iw_request_info *info,
2312                          struct iw_param *dwrq,
2313                          char *extra)
2314 {
2315         wlan_private *priv = dev->priv;
2316         wlan_adapter *adapter = priv->adapter;
2317         struct assoc_request * assoc_req;
2318         int ret = 0;
2319         int updated = 0;
2320
2321         ENTER();
2322
2323         mutex_lock(&adapter->lock);
2324         assoc_req = wlan_get_association_request(adapter);
2325         if (!assoc_req) {
2326                 ret = -ENOMEM;
2327                 goto out;
2328         }
2329
2330         switch (dwrq->flags & IW_AUTH_INDEX) {
2331         case IW_AUTH_TKIP_COUNTERMEASURES:
2332         case IW_AUTH_CIPHER_PAIRWISE:
2333         case IW_AUTH_CIPHER_GROUP:
2334         case IW_AUTH_KEY_MGMT:
2335                 /*
2336                  * libertas does not use these parameters
2337                  */
2338                 break;
2339
2340         case IW_AUTH_WPA_VERSION:
2341                 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
2342                         assoc_req->secinfo.WPAenabled = 0;
2343                         assoc_req->secinfo.WPA2enabled = 0;
2344                 }
2345                 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
2346                         assoc_req->secinfo.WPAenabled = 1;
2347                         assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
2348                         assoc_req->secinfo.authmode =
2349                             wlan802_11authmodeopen;
2350                 }
2351                 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
2352                         assoc_req->secinfo.WPA2enabled = 1;
2353                         assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
2354                         assoc_req->secinfo.authmode =
2355                             wlan802_11authmodeopen;
2356                 }
2357                 updated = 1;
2358                 break;
2359
2360         case IW_AUTH_DROP_UNENCRYPTED:
2361                 if (dwrq->value) {
2362                         adapter->currentpacketfilter |=
2363                             cmd_act_mac_strict_protection_enable;
2364                 } else {
2365                         adapter->currentpacketfilter &=
2366                             ~cmd_act_mac_strict_protection_enable;
2367                 }
2368                 updated = 1;
2369                 break;
2370
2371         case IW_AUTH_80211_AUTH_ALG:
2372                 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
2373                         assoc_req->secinfo.authmode =
2374                             wlan802_11authmodeshared;
2375                 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
2376                         assoc_req->secinfo.authmode =
2377                             wlan802_11authmodeopen;
2378                 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
2379                         assoc_req->secinfo.authmode =
2380                             wlan802_11authmodenetworkEAP;
2381                 } else {
2382                         ret = -EINVAL;
2383                 }
2384                 updated = 1;
2385                 break;
2386
2387         case IW_AUTH_WPA_ENABLED:
2388                 if (dwrq->value) {
2389                         if (!assoc_req->secinfo.WPAenabled &&
2390                             !assoc_req->secinfo.WPA2enabled) {
2391                                 assoc_req->secinfo.WPAenabled = 1;
2392                                 assoc_req->secinfo.WPA2enabled = 1;
2393                                 assoc_req->secinfo.WEPstatus = wlan802_11WEPdisabled;
2394                                 assoc_req->secinfo.authmode =
2395                                     wlan802_11authmodeopen;
2396                         }
2397                 } else {
2398                         assoc_req->secinfo.WPAenabled = 0;
2399                         assoc_req->secinfo.WPA2enabled = 0;
2400                 }
2401                 updated = 1;
2402                 break;
2403
2404         default:
2405                 ret = -EOPNOTSUPP;
2406                 break;
2407         }
2408
2409 out:
2410         if (ret == 0) {
2411                 if (updated)
2412                         set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2413                 wlan_postpone_association_work(priv);
2414         } else if (ret != -EOPNOTSUPP) {
2415                 wlan_cancel_association_work(priv);
2416         }
2417         mutex_unlock(&adapter->lock);
2418
2419         LEAVE();
2420         return ret;
2421 }
2422
2423 static int wlan_get_auth(struct net_device *dev,
2424                          struct iw_request_info *info,
2425                          struct iw_param *dwrq,
2426                          char *extra)
2427 {
2428         wlan_private *priv = dev->priv;
2429         wlan_adapter *adapter = priv->adapter;
2430
2431         ENTER();
2432
2433         switch (dwrq->flags & IW_AUTH_INDEX) {
2434         case IW_AUTH_WPA_VERSION:
2435                 dwrq->value = 0;
2436                 if (adapter->secinfo.WPAenabled)
2437                         dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
2438                 if (adapter->secinfo.WPA2enabled)
2439                         dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
2440                 if (!dwrq->value)
2441                         dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
2442                 break;
2443
2444         case IW_AUTH_DROP_UNENCRYPTED:
2445                 dwrq->value = 0;
2446                 if (adapter->currentpacketfilter &
2447                     cmd_act_mac_strict_protection_enable)
2448                         dwrq->value = 1;
2449                 break;
2450
2451         case IW_AUTH_80211_AUTH_ALG:
2452                 switch (adapter->secinfo.authmode) {
2453                 case wlan802_11authmodeshared:
2454                         dwrq->value = IW_AUTH_ALG_SHARED_KEY;
2455                         break;
2456                 case wlan802_11authmodeopen:
2457                         dwrq->value = IW_AUTH_ALG_OPEN_SYSTEM;
2458                         break;
2459                 case wlan802_11authmodenetworkEAP:
2460                         dwrq->value = IW_AUTH_ALG_LEAP;
2461                         break;
2462                 default:
2463                         break;
2464                 }
2465                 break;
2466
2467         case IW_AUTH_WPA_ENABLED:
2468                 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
2469                         dwrq->value = 1;
2470                 break;
2471
2472         default:
2473                 LEAVE();
2474                 return -EOPNOTSUPP;
2475         }
2476
2477         LEAVE();
2478         return 0;
2479 }
2480
2481
2482 static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
2483                    struct iw_param *vwrq, char *extra)
2484 {
2485         int ret = 0;
2486         wlan_private *priv = dev->priv;
2487         wlan_adapter *adapter = priv->adapter;
2488
2489         u16 dbm;
2490
2491         ENTER();
2492
2493         if (vwrq->disabled) {
2494                 wlan_radio_ioctl(priv, RADIO_OFF);
2495                 return 0;
2496         }
2497
2498         adapter->preamble = cmd_type_auto_preamble;
2499
2500         wlan_radio_ioctl(priv, RADIO_ON);
2501
2502         if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
2503                 dbm = (u16) mw_to_dbm(vwrq->value);
2504         } else
2505                 dbm = (u16) vwrq->value;
2506
2507         /* auto tx power control */
2508
2509         if (vwrq->fixed == 0)
2510                 dbm = 0xffff;
2511
2512         lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
2513
2514         ret = libertas_prepare_and_send_command(priv,
2515                                     cmd_802_11_rf_tx_power,
2516                                     cmd_act_tx_power_opt_set_low,
2517                                     cmd_option_waitforrsp, 0, (void *)&dbm);
2518
2519         LEAVE();
2520         return ret;
2521 }
2522
2523 static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
2524                    struct iw_point *dwrq, char *extra)
2525 {
2526         wlan_private *priv = dev->priv;
2527         wlan_adapter *adapter = priv->adapter;
2528
2529         ENTER();
2530         /*
2531          * Note : if dwrq->flags != 0, we should get the relevant SSID from
2532          * the SSID list...
2533          */
2534
2535         /*
2536          * Get the current SSID
2537          */
2538         if (adapter->connect_status == libertas_connected) {
2539                 memcpy(extra, adapter->curbssparams.ssid.ssid,
2540                        adapter->curbssparams.ssid.ssidlength);
2541                 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2542         } else {
2543                 memset(extra, 0, 32);
2544                 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2545         }
2546         /*
2547          * If none, we may want to get the one that was set
2548          */
2549
2550         /* To make the driver backward compatible with WPA supplicant v0.2.4 */
2551         if (dwrq->length == 32) /* check with WPA supplicant buffer size */
2552                 dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
2553                                    IW_ESSID_MAX_SIZE);
2554         else
2555                 dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
2556
2557         dwrq->flags = 1;        /* active */
2558
2559         LEAVE();
2560         return 0;
2561 }
2562
2563 static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
2564                    struct iw_point *dwrq, char *extra)
2565 {
2566         wlan_private *priv = dev->priv;
2567         wlan_adapter *adapter = priv->adapter;
2568         int ret = 0;
2569         struct WLAN_802_11_SSID ssid;
2570         struct assoc_request * assoc_req;
2571         int ssid_len = dwrq->length;
2572
2573         ENTER();
2574
2575         /*
2576          * WE-20 and earlier NULL pad the end of the SSID and increment
2577          * SSID length so it can be used like a string.  WE-21 and later don't,
2578          * but some userspace tools aren't able to cope with the change.
2579          */
2580         if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
2581                 ssid_len--;
2582
2583         /* Check the size of the string */
2584         if (ssid_len > IW_ESSID_MAX_SIZE) {
2585                 ret = -E2BIG;
2586                 goto out;
2587         }
2588
2589         memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
2590
2591         if (!dwrq->flags || !ssid_len) {
2592                 /* "any" SSID requested; leave SSID blank */
2593         } else {
2594                 /* Specific SSID requested */
2595                 memcpy(&ssid.ssid, extra, ssid_len);
2596                 ssid.ssidlength = ssid_len;
2597         }
2598
2599         lbs_pr_debug(1, "Requested new SSID = %s\n",
2600                (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
2601
2602 out:
2603         mutex_lock(&adapter->lock);
2604         if (ret == 0) {
2605                 /* Get or create the current association request */
2606                 assoc_req = wlan_get_association_request(adapter);
2607                 if (!assoc_req) {
2608                         ret = -ENOMEM;
2609                 } else {
2610                         /* Copy the SSID to the association request */
2611                         memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
2612                         set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2613                         wlan_postpone_association_work(priv);
2614                 }
2615         }
2616
2617         /* Cancel the association request if there was an error */
2618         if (ret != 0) {
2619                 wlan_cancel_association_work(priv);
2620         }
2621
2622         mutex_unlock(&adapter->lock);
2623
2624         LEAVE();
2625         return ret;
2626 }
2627
2628 /**
2629  *  @brief Connect to the AP or Ad-hoc Network with specific bssid
2630  *
2631  *  @param dev          A pointer to net_device structure
2632  *  @param info         A pointer to iw_request_info structure
2633  *  @param awrq         A pointer to iw_param structure
2634  *  @param extra        A pointer to extra data buf
2635  *  @return             0 --success, otherwise fail
2636  */
2637 static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
2638                  struct sockaddr *awrq, char *extra)
2639 {
2640         wlan_private *priv = dev->priv;
2641         wlan_adapter *adapter = priv->adapter;
2642         struct assoc_request * assoc_req;
2643         int ret = 0;
2644
2645         ENTER();
2646
2647         if (awrq->sa_family != ARPHRD_ETHER)
2648                 return -EINVAL;
2649
2650         lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
2651
2652         mutex_lock(&adapter->lock);
2653
2654         /* Get or create the current association request */
2655         assoc_req = wlan_get_association_request(adapter);
2656         if (!assoc_req) {
2657                 wlan_cancel_association_work(priv);
2658                 ret = -ENOMEM;
2659         } else {
2660                 /* Copy the BSSID to the association request */
2661                 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2662                 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2663                 wlan_postpone_association_work(priv);
2664         }
2665
2666         mutex_unlock(&adapter->lock);
2667
2668         return ret;
2669 }
2670
2671 void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2672 {
2673         union {
2674                 u32 l;
2675                 u8 c[4];
2676         } ver;
2677         char fwver[32];
2678
2679         mutex_lock(&adapter->lock);
2680         ver.l = adapter->fwreleasenumber;
2681         mutex_unlock(&adapter->lock);
2682
2683         if (ver.c[3] == 0)
2684                 sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
2685         else
2686                 sprintf(fwver, "%u.%u.%u.p%u",
2687                         ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
2688
2689         snprintf(fwversion, maxlen, fwver);
2690 }
2691
2692
2693 /*
2694  * iwconfig settable callbacks
2695  */
2696 static const iw_handler wlan_handler[] = {
2697         (iw_handler) NULL,      /* SIOCSIWCOMMIT */
2698         (iw_handler) wlan_get_name,     /* SIOCGIWNAME */
2699         (iw_handler) NULL,      /* SIOCSIWNWID */
2700         (iw_handler) NULL,      /* SIOCGIWNWID */
2701         (iw_handler) wlan_set_freq,     /* SIOCSIWFREQ */
2702         (iw_handler) wlan_get_freq,     /* SIOCGIWFREQ */
2703         (iw_handler) wlan_set_mode,     /* SIOCSIWMODE */
2704         (iw_handler) wlan_get_mode,     /* SIOCGIWMODE */
2705         (iw_handler) NULL,      /* SIOCSIWSENS */
2706         (iw_handler) NULL,      /* SIOCGIWSENS */
2707         (iw_handler) NULL,      /* SIOCSIWRANGE */
2708         (iw_handler) wlan_get_range,    /* SIOCGIWRANGE */
2709         (iw_handler) NULL,      /* SIOCSIWPRIV */
2710         (iw_handler) NULL,      /* SIOCGIWPRIV */
2711         (iw_handler) NULL,      /* SIOCSIWSTATS */
2712         (iw_handler) NULL,      /* SIOCGIWSTATS */
2713         iw_handler_set_spy,     /* SIOCSIWSPY */
2714         iw_handler_get_spy,     /* SIOCGIWSPY */
2715         iw_handler_set_thrspy,  /* SIOCSIWTHRSPY */
2716         iw_handler_get_thrspy,  /* SIOCGIWTHRSPY */
2717         (iw_handler) wlan_set_wap,      /* SIOCSIWAP */
2718         (iw_handler) wlan_get_wap,      /* SIOCGIWAP */
2719         (iw_handler) NULL,      /* SIOCSIWMLME */
2720         (iw_handler) NULL,      /* SIOCGIWAPLIST - deprecated */
2721         (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2722         (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2723         (iw_handler) wlan_set_essid,    /* SIOCSIWESSID */
2724         (iw_handler) wlan_get_essid,    /* SIOCGIWESSID */
2725         (iw_handler) wlan_set_nick,     /* SIOCSIWNICKN */
2726         (iw_handler) wlan_get_nick,     /* SIOCGIWNICKN */
2727         (iw_handler) NULL,      /* -- hole -- */
2728         (iw_handler) NULL,      /* -- hole -- */
2729         (iw_handler) wlan_set_rate,     /* SIOCSIWRATE */
2730         (iw_handler) wlan_get_rate,     /* SIOCGIWRATE */
2731         (iw_handler) wlan_set_rts,      /* SIOCSIWRTS */
2732         (iw_handler) wlan_get_rts,      /* SIOCGIWRTS */
2733         (iw_handler) wlan_set_frag,     /* SIOCSIWFRAG */
2734         (iw_handler) wlan_get_frag,     /* SIOCGIWFRAG */
2735         (iw_handler) wlan_set_txpow,    /* SIOCSIWTXPOW */
2736         (iw_handler) wlan_get_txpow,    /* SIOCGIWTXPOW */
2737         (iw_handler) wlan_set_retry,    /* SIOCSIWRETRY */
2738         (iw_handler) wlan_get_retry,    /* SIOCGIWRETRY */
2739         (iw_handler) wlan_set_encode,   /* SIOCSIWENCODE */
2740         (iw_handler) wlan_get_encode,   /* SIOCGIWENCODE */
2741         (iw_handler) wlan_set_power,    /* SIOCSIWPOWER */
2742         (iw_handler) wlan_get_power,    /* SIOCGIWPOWER */
2743         (iw_handler) NULL,      /* -- hole -- */
2744         (iw_handler) NULL,      /* -- hole -- */
2745         (iw_handler) wlan_set_genie,    /* SIOCSIWGENIE */
2746         (iw_handler) wlan_get_genie,    /* SIOCGIWGENIE */
2747         (iw_handler) wlan_set_auth,     /* SIOCSIWAUTH */
2748         (iw_handler) wlan_get_auth,     /* SIOCGIWAUTH */
2749         (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2750         (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2751         (iw_handler) NULL,              /* SIOCSIWPMKSA */
2752 };
2753
2754 struct iw_handler_def libertas_handler_def = {
2755         .num_standard   = sizeof(wlan_handler) / sizeof(iw_handler),
2756         .num_private    = sizeof(wlan_private_handler) / sizeof(iw_handler),
2757         .num_private_args = sizeof(wlan_private_args) /
2758                 sizeof(struct iw_priv_args),
2759         .standard       = (iw_handler *) wlan_handler,
2760         .private        = (iw_handler *) wlan_private_handler,
2761         .private_args   = (struct iw_priv_args *)wlan_private_args,
2762         .get_wireless_stats = wlan_get_wireless_stats,
2763 };