2 * This file contains ioctl functions
4 #include <linux/ctype.h>
5 #include <linux/delay.h>
7 #include <linux/if_arp.h>
8 #include <linux/wireless.h>
9 #include <linux/bitops.h>
11 #include <net/ieee80211.h>
12 #include <net/iw_handler.h>
26 * @brief Convert mw value to dbm value
28 * @param mw the value of mw
29 * @return the value of dbm
31 static int mw_to_dbm(int mw)
72 * @brief Find the channel frequency power info with specific channel
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.
79 struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
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]);
88 for (j = 0; !cfp && (j < count); j++) {
89 rc = &adapter->region_channel[j];
91 if (adapter->enable11d)
92 rc = &adapter->universal_channel[j];
93 if (!rc->valid || !rc->CFP)
97 for (i = 0; i < rc->nrcfp; i++) {
98 if (rc->CFP[i].channel == 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);
113 * @brief Find the channel frequency power info with specific frequency
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.
120 static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
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]);
129 for (j = 0; !cfp && (j < count); j++) {
130 rc = &adapter->region_channel[j];
132 if (adapter->enable11d)
133 rc = &adapter->universal_channel[j];
134 if (!rc->valid || !rc->CFP)
136 if (rc->band != band)
138 for (i = 0; i < rc->nrcfp; i++) {
139 if (rc->CFP[i].freq == freq) {
147 lbs_pr_debug(1, "find_cfp_by_band_and_freql(): cannot find cfp by "
148 "band %d & freq %d\n", band, freq);
153 static int updatecurrentchannel(wlan_private * priv)
158 ** the channel in f/w could be out of sync, get the current channel
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);
164 lbs_pr_debug(1, "Current channel = %d\n",
165 priv->adapter->curbssparams.channel);
170 static int setcurrentchannel(wlan_private * priv, int channel)
172 lbs_pr_debug(1, "Set channel = %d\n", channel);
175 ** Current channel is not set to adhocchannel requested, set channel
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));
182 static int changeadhocchannel(wlan_private * priv, int channel)
185 wlan_adapter *adapter = priv->adapter;
187 adapter->adhocchannel = channel;
189 updatecurrentchannel(priv);
191 if (adapter->curbssparams.channel == adapter->adhocchannel) {
192 /* adhocchannel is set to the current channel already */
197 lbs_pr_debug(1, "Updating channel from %d to %d\n",
198 adapter->curbssparams.channel, adapter->adhocchannel);
200 setcurrentchannel(priv, adapter->adhocchannel);
202 updatecurrentchannel(priv);
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);
211 if (adapter->connect_status == libertas_connected) {
213 struct WLAN_802_11_SSID curadhocssid;
215 lbs_pr_debug(1, "channel Changed while in an IBSS\n");
217 /* Copy the current ssid */
218 memcpy(&curadhocssid, &adapter->curbssparams.ssid,
219 sizeof(struct WLAN_802_11_SSID));
221 /* Exit Adhoc mode */
222 lbs_pr_debug(1, "In changeadhocchannel(): Sending Adhoc Stop\n");
223 ret = libertas_stop_adhoc_network(priv);
229 /* Scan for the network, do not save previous results. Stale
230 * scan data will cause us to join a non-existant adhoc network
232 libertas_send_specific_SSID_scan(priv, &curadhocssid, 0);
234 // find out the BSSID that matches the current SSID
235 i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
239 lbs_pr_debug(1, "SSID found at %d in List,"
241 libertas_join_adhoc_network(priv, &adapter->scantable[i]);
243 // else send START command
244 lbs_pr_debug(1, "SSID not found in list, "
245 "so creating adhoc with ssid = %s\n",
247 libertas_start_adhoc_network(priv, &curadhocssid);
248 } // end of else (START command)
256 * @brief Set Radio On/OFF
258 * @param priv A pointer to wlan_private structure
259 * @option Radio Option
260 * @return 0 --success, otherwise fail
262 int wlan_radio_ioctl(wlan_private * priv, u8 option)
265 wlan_adapter *adapter = priv->adapter;
269 if (adapter->radioon != option) {
270 lbs_pr_debug(1, "Switching %s the Radio\n", option ? "On" : "Off");
271 adapter->radioon = option;
273 ret = libertas_prepare_and_send_command(priv,
274 cmd_802_11_radio_control,
276 cmd_option_waitforrsp, 0, NULL);
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
291 static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
295 for (i = 0; i < len && src[i]; i++, pos++) {
296 if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
305 * @brief Get active data rates
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
311 static int get_active_data_rates(wlan_adapter * adapter,
318 if (adapter->connect_status != libertas_connected) {
319 if (adapter->mode == IW_MODE_INFRA) {
320 lbs_pr_debug(1, "Infra\n");
321 k = copyrates(rates, k, libertas_supported_rates,
322 sizeof(libertas_supported_rates));
324 lbs_pr_debug(1, "Adhoc G\n");
325 k = copyrates(rates, k, libertas_adhoc_rates_g,
326 sizeof(libertas_adhoc_rates_g));
329 k = copyrates(rates, 0, adapter->curbssparams.datarates,
330 adapter->curbssparams.numofrates);
338 static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
339 char *cwrq, char *extra)
342 char comm[6] = { "COMM-" };
343 char mrvl[6] = { "MRVL-" };
350 cp = strstr(libertas_driver_version, comm);
351 if (cp == libertas_driver_version) //skip leading "COMM-"
352 cp = libertas_driver_version + strlen(comm);
354 cp = libertas_driver_version;
358 while (cnt < 16 && (*cp != '-')) {
359 *cwrq++ = toupper(*cp++);
369 static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
370 struct iw_freq *fwrq, char *extra)
372 wlan_private *priv = dev->priv;
373 wlan_adapter *adapter = priv->adapter;
374 struct chan_freq_power *cfp;
378 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
379 adapter->curbssparams.channel);
382 if (adapter->curbssparams.channel)
383 lbs_pr_debug(1, "Invalid channel=%d\n",
384 adapter->curbssparams.channel);
388 fwrq->m = (long)cfp->freq * 100000;
391 lbs_pr_debug(1, "freq=%u\n", fwrq->m);
397 static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
398 struct sockaddr *awrq, char *extra)
400 wlan_private *priv = dev->priv;
401 wlan_adapter *adapter = priv->adapter;
405 if (adapter->connect_status == libertas_connected) {
406 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
408 memset(awrq->sa_data, 0, ETH_ALEN);
410 awrq->sa_family = ARPHRD_ETHER;
416 static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
417 struct iw_point *dwrq, char *extra)
419 wlan_private *priv = dev->priv;
420 wlan_adapter *adapter = priv->adapter;
425 * Check the size of the string
428 if (dwrq->length > 16) {
432 mutex_lock(&adapter->lock);
433 memset(adapter->nodename, 0, sizeof(adapter->nodename));
434 memcpy(adapter->nodename, extra, dwrq->length);
435 mutex_unlock(&adapter->lock);
441 static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
442 struct iw_point *dwrq, char *extra)
444 wlan_private *priv = dev->priv;
445 wlan_adapter *adapter = priv->adapter;
450 * Get the Nick Name saved
453 mutex_lock(&adapter->lock);
454 strncpy(extra, adapter->nodename, 16);
455 mutex_unlock(&adapter->lock);
460 * If none, we may want to get the one that was set
466 dwrq->length = strlen(extra) + 1;
472 static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
473 struct iw_param *vwrq, char *extra)
476 wlan_private *priv = dev->priv;
477 wlan_adapter *adapter = priv->adapter;
478 int rthr = vwrq->value;
482 if (vwrq->disabled) {
483 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
485 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
487 adapter->rtsthsd = rthr;
490 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
491 cmd_act_set, cmd_option_waitforrsp,
492 OID_802_11_RTS_THRESHOLD, &rthr);
498 static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
499 struct iw_param *vwrq, char *extra)
502 wlan_private *priv = dev->priv;
503 wlan_adapter *adapter = priv->adapter;
507 adapter->rtsthsd = 0;
508 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
509 cmd_act_get, cmd_option_waitforrsp,
510 OID_802_11_RTS_THRESHOLD, NULL);
516 vwrq->value = adapter->rtsthsd;
517 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
518 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
525 static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
526 struct iw_param *vwrq, char *extra)
529 int fthr = vwrq->value;
530 wlan_private *priv = dev->priv;
531 wlan_adapter *adapter = priv->adapter;
535 if (vwrq->disabled) {
536 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
538 if (fthr < MRVDRV_FRAG_MIN_VALUE
539 || fthr > MRVDRV_FRAG_MAX_VALUE)
541 adapter->fragthsd = fthr;
544 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
545 cmd_act_set, cmd_option_waitforrsp,
546 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
551 static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
552 struct iw_param *vwrq, char *extra)
555 wlan_private *priv = dev->priv;
556 wlan_adapter *adapter = priv->adapter;
560 adapter->fragthsd = 0;
561 ret = libertas_prepare_and_send_command(priv,
563 cmd_act_get, cmd_option_waitforrsp,
564 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
570 vwrq->value = adapter->fragthsd;
571 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
572 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
579 static int wlan_get_mode(struct net_device *dev,
580 struct iw_request_info *info, u32 * uwrq, char *extra)
582 wlan_private *priv = dev->priv;
583 wlan_adapter *adapter = priv->adapter;
587 *uwrq = adapter->mode;
593 static int wlan_get_txpow(struct net_device *dev,
594 struct iw_request_info *info,
595 struct iw_param *vwrq, char *extra)
598 wlan_private *priv = dev->priv;
599 wlan_adapter *adapter = priv->adapter;
603 ret = libertas_prepare_and_send_command(priv,
604 cmd_802_11_rf_tx_power,
605 cmd_act_tx_power_opt_get,
606 cmd_option_waitforrsp, 0, NULL);
613 lbs_pr_debug(1, "TXPOWER GET %d dbm.\n", adapter->txpowerlevel);
614 vwrq->value = adapter->txpowerlevel;
616 if (adapter->radioon) {
618 vwrq->flags = IW_TXPOW_DBM;
627 static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
628 struct iw_param *vwrq, char *extra)
631 wlan_private *priv = dev->priv;
632 wlan_adapter *adapter = priv->adapter;
636 if (vwrq->flags == IW_RETRY_LIMIT) {
637 /* The MAC has a 4-bit Total_Tx_Count register
638 Total_Tx_Count = 1 + Tx_Retry_Count */
639 #define TX_RETRY_MIN 0
640 #define TX_RETRY_MAX 14
641 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
644 /* Adding 1 to convert retry count to try count */
645 adapter->txretrycount = vwrq->value + 1;
647 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
649 cmd_option_waitforrsp,
650 OID_802_11_TX_RETRYCOUNT, NULL);
664 static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
665 struct iw_param *vwrq, char *extra)
667 wlan_private *priv = dev->priv;
668 wlan_adapter *adapter = priv->adapter;
672 adapter->txretrycount = 0;
673 ret = libertas_prepare_and_send_command(priv,
675 cmd_act_get, cmd_option_waitforrsp,
676 OID_802_11_TX_RETRYCOUNT, NULL);
683 vwrq->flags = IW_RETRY_LIMIT;
684 /* Subtract 1 to convert try count to retry count */
685 vwrq->value = adapter->txretrycount - 1;
692 static inline void sort_channels(struct iw_freq *freq, int num)
697 for (i = 0; i < num; i++)
698 for (j = i + 1; j < num; j++)
699 if (freq[i].i > freq[j].i) {
703 freq[i].i = freq[j].i;
704 freq[i].m = freq[j].m;
714 Infra G(12) A(8) B(4) G(12)
715 Adhoc A+B(12) A(8) B(4) B(4)
723 * @brief Get Range Info
725 * @param dev A pointer to net_device structure
726 * @param info A pointer to iw_request_info structure
727 * @param vwrq A pointer to iw_param structure
728 * @param extra A pointer to extra data buf
729 * @return 0 --success, otherwise fail
731 static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
732 struct iw_point *dwrq, char *extra)
735 wlan_private *priv = dev->priv;
736 wlan_adapter *adapter = priv->adapter;
737 struct iw_range *range = (struct iw_range *)extra;
738 struct chan_freq_power *cfp;
739 u8 rates[WLAN_SUPPORTED_RATES];
745 dwrq->length = sizeof(struct iw_range);
746 memset(range, 0, sizeof(struct iw_range));
751 memset(rates, 0, sizeof(rates));
752 range->num_bitrates = get_active_data_rates(adapter, rates);
754 for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
756 range->bitrate[i] = (rates[i] & 0x7f) * 500000;
758 range->num_bitrates = i;
759 lbs_pr_debug(1, "IW_MAX_BITRATES=%d num_bitrates=%d\n", IW_MAX_BITRATES,
760 range->num_bitrates);
762 range->num_frequency = 0;
763 if (priv->adapter->enable11d &&
764 adapter->connect_status == libertas_connected) {
768 struct parsed_region_chan_11d *parsed_region_chan =
769 &adapter->parsed_region_chan;
771 if (parsed_region_chan == NULL) {
772 lbs_pr_debug(1, "11D:parsed_region_chan is NULL\n");
776 band = parsed_region_chan->band;
777 lbs_pr_debug(1, "band=%d NoOfChan=%d\n", band,
778 parsed_region_chan->nr_chan);
780 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
781 && (i < parsed_region_chan->nr_chan); i++) {
782 chan_no = parsed_region_chan->chanpwr[i].chan;
783 lbs_pr_debug(1, "chan_no=%d\n", chan_no);
784 range->freq[range->num_frequency].i = (long)chan_no;
785 range->freq[range->num_frequency].m =
786 (long)libertas_chan_2_freq(chan_no, band) * 100000;
787 range->freq[range->num_frequency].e = 1;
788 range->num_frequency++;
793 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
794 && (j < sizeof(adapter->region_channel)
795 / sizeof(adapter->region_channel[0])); j++) {
796 cfp = adapter->region_channel[j].CFP;
797 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
798 && adapter->region_channel[j].valid
800 && (i < adapter->region_channel[j].nrcfp); i++) {
801 range->freq[range->num_frequency].i =
803 range->freq[range->num_frequency].m =
804 (long)cfp->freq * 100000;
805 range->freq[range->num_frequency].e = 1;
807 range->num_frequency++;
812 lbs_pr_debug(1, "IW_MAX_FREQUENCIES=%d num_frequency=%d\n",
813 IW_MAX_FREQUENCIES, range->num_frequency);
815 range->num_channels = range->num_frequency;
817 sort_channels(&range->freq[0], range->num_frequency);
820 * Set an indication of the max TCP throughput in bit/s that we can
821 * expect using this interface
824 range->throughput = 5000 * 1000;
826 range->throughput = 1500 * 1000;
828 range->min_rts = MRVDRV_RTS_MIN_VALUE;
829 range->max_rts = MRVDRV_RTS_MAX_VALUE;
830 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
831 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
833 range->encoding_size[0] = 5;
834 range->encoding_size[1] = 13;
835 range->num_encoding_sizes = 2;
836 range->max_encoding_tokens = 4;
838 range->min_pmp = 1000000;
839 range->max_pmp = 120000000;
840 range->min_pmt = 1000;
841 range->max_pmt = 1000000;
842 range->pmp_flags = IW_POWER_PERIOD;
843 range->pmt_flags = IW_POWER_TIMEOUT;
844 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
847 * Minimum version we recommend
849 range->we_version_source = 15;
852 * Version we are compiled with
854 range->we_version_compiled = WIRELESS_EXT;
856 range->retry_capa = IW_RETRY_LIMIT;
857 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
859 range->min_retry = TX_RETRY_MIN;
860 range->max_retry = TX_RETRY_MAX;
863 * Set the qual, level and noise range values
865 range->max_qual.qual = 100;
866 range->max_qual.level = 0;
867 range->max_qual.noise = 0;
868 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
870 range->avg_qual.qual = 70;
871 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
872 range->avg_qual.level = 0;
873 range->avg_qual.noise = 0;
874 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
876 range->sensitivity = 0;
879 * Setup the supported power level ranges
881 memset(range->txpower, 0, sizeof(range->txpower));
882 range->txpower[0] = 5;
883 range->txpower[1] = 7;
884 range->txpower[2] = 9;
885 range->txpower[3] = 11;
886 range->txpower[4] = 13;
887 range->txpower[5] = 15;
888 range->txpower[6] = 17;
889 range->txpower[7] = 19;
891 range->num_txpower = 8;
892 range->txpower_capa = IW_TXPOW_DBM;
893 range->txpower_capa |= IW_TXPOW_RANGE;
895 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
896 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
897 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
898 range->event_capa[1] = IW_EVENT_CAPA_K_1;
900 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
901 range->enc_capa = IW_ENC_CAPA_WPA
903 | IW_ENC_CAPA_CIPHER_TKIP
904 | IW_ENC_CAPA_CIPHER_CCMP;
911 static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
912 struct iw_param *vwrq, char *extra)
914 wlan_private *priv = dev->priv;
915 wlan_adapter *adapter = priv->adapter;
919 /* PS is currently supported only in Infrastructure mode
920 * Remove this check if it is to be supported in IBSS mode also
923 if (vwrq->disabled) {
924 adapter->psmode = wlan802_11powermodecam;
925 if (adapter->psstate != PS_STATE_FULL_POWER) {
926 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
932 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
934 "Setting power timeout command is not supported\n");
936 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
937 lbs_pr_debug(1, "Setting power period command is not supported\n");
941 if (adapter->psmode != wlan802_11powermodecam) {
945 adapter->psmode = wlan802_11powermodemax_psp;
947 if (adapter->connect_status == libertas_connected) {
948 libertas_ps_sleep(priv, cmd_option_waitforrsp);
955 static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
956 struct iw_param *vwrq, char *extra)
958 wlan_private *priv = dev->priv;
959 wlan_adapter *adapter = priv->adapter;
964 mode = adapter->psmode;
966 if ((vwrq->disabled = (mode == wlan802_11powermodecam))
967 || adapter->connect_status == libertas_disconnected) {
979 * iwpriv settable callbacks
982 static const iw_handler wlan_private_handler[] = {
983 NULL, /* SIOCIWFIRSTPRIV */
986 static const struct iw_priv_args wlan_private_args[] = {
988 * { cmd, set_args, get_args, name }
992 IW_PRIV_TYPE_CHAR | 8,
993 IW_PRIV_TYPE_CHAR | 8,
998 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
999 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1003 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1004 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1008 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1009 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1013 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1014 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1018 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1019 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1023 WLAN_SUBCMD_SET_PRESCAN,
1024 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1025 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1028 WLAN_SETONEINT_GETONEINT,
1029 IW_PRIV_TYPE_INT | 1,
1030 IW_PRIV_TYPE_INT | 1,
1033 WLAN_BEACON_INTERVAL,
1034 IW_PRIV_TYPE_INT | 1,
1035 IW_PRIV_TYPE_INT | 1,
1039 IW_PRIV_TYPE_INT | 1,
1040 IW_PRIV_TYPE_INT | 1,
1044 IW_PRIV_TYPE_INT | 1,
1045 IW_PRIV_TYPE_INT | 1,
1048 WLAN_NULLPKTINTERVAL,
1049 IW_PRIV_TYPE_INT | 1,
1050 IW_PRIV_TYPE_INT | 1,
1052 /* Using iwpriv sub-command feature */
1054 WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */
1055 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1060 WLAN_SUBCMD_SETRXANTENNA,
1061 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1065 WLAN_SUBCMD_SETTXANTENNA,
1066 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1070 WLANSETENCRYPTIONMODE,
1071 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1077 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1081 WLAN_SET_LISTEN_INTERVAL,
1082 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1086 WLAN_SET_MULTIPLE_DTIM,
1087 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1091 WLAN_SET_ATIM_WINDOW,
1092 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1097 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1102 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1107 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1112 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1117 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1121 WLAN_SUBCMD_MESH_SET_TTL,
1122 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1126 WLAN_SETNONE_GETONEINT,
1128 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1133 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1136 WLAN_GET_LISTEN_INTERVAL,
1138 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1141 WLAN_GET_MULTIPLE_DTIM,
1143 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1148 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1153 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1158 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1163 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1168 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1171 WLAN_SUBCMD_FWT_CLEANUP,
1173 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1176 WLAN_SUBCMD_FWT_TIME,
1178 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1181 WLAN_SUBCMD_MESH_GET_TTL,
1183 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1186 WLAN_SETNONE_GETTWELVE_CHAR,
1188 IW_PRIV_TYPE_CHAR | 12,
1191 WLAN_SUBCMD_GETRXANTENNA,
1193 IW_PRIV_TYPE_CHAR | 12,
1196 WLAN_SUBCMD_GETTXANTENNA,
1198 IW_PRIV_TYPE_CHAR | 12,
1203 IW_PRIV_TYPE_CHAR | 12,
1206 WLAN_SETNONE_GETNONE,
1241 WLAN_SUBCMD_FWT_RESET,
1246 WLAN_SUBCMD_BT_RESET,
1251 WLAN_SET128CHAR_GET128CHAR,
1252 IW_PRIV_TYPE_CHAR | 128,
1253 IW_PRIV_TYPE_CHAR | 128,
1258 IW_PRIV_TYPE_CHAR | 128,
1259 IW_PRIV_TYPE_CHAR | 128,
1263 IW_PRIV_TYPE_CHAR | 128,
1264 IW_PRIV_TYPE_CHAR | 128,
1267 WLAN_SUBCMD_BT_LIST,
1268 IW_PRIV_TYPE_CHAR | 128,
1269 IW_PRIV_TYPE_CHAR | 128,
1271 /* FWT Management */
1273 WLAN_SUBCMD_FWT_ADD,
1274 IW_PRIV_TYPE_CHAR | 128,
1275 IW_PRIV_TYPE_CHAR | 128,
1278 WLAN_SUBCMD_FWT_DEL,
1279 IW_PRIV_TYPE_CHAR | 128,
1280 IW_PRIV_TYPE_CHAR | 128,
1283 WLAN_SUBCMD_FWT_LOOKUP,
1284 IW_PRIV_TYPE_CHAR | 128,
1285 IW_PRIV_TYPE_CHAR | 128,
1288 WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
1289 IW_PRIV_TYPE_CHAR | 128,
1290 IW_PRIV_TYPE_CHAR | 128,
1293 WLAN_SUBCMD_FWT_LIST,
1294 IW_PRIV_TYPE_CHAR | 128,
1295 IW_PRIV_TYPE_CHAR | 128,
1298 WLAN_SUBCMD_FWT_LIST_ROUTE,
1299 IW_PRIV_TYPE_CHAR | 128,
1300 IW_PRIV_TYPE_CHAR | 128,
1304 IW_PRIV_TYPE_CHAR | 128,
1305 IW_PRIV_TYPE_CHAR | 128,
1308 WLAN_GET_ADHOC_STATUS,
1309 IW_PRIV_TYPE_CHAR | 128,
1310 IW_PRIV_TYPE_CHAR | 128,
1313 WLAN_SETNONE_GETWORDCHAR,
1315 IW_PRIV_TYPE_CHAR | 128,
1320 IW_PRIV_TYPE_CHAR | GETLOG_BUFSIZE,
1323 WLAN_SET_GET_SIXTEEN_INT,
1324 IW_PRIV_TYPE_INT | 16,
1325 IW_PRIV_TYPE_INT | 16,
1329 IW_PRIV_TYPE_INT | 16,
1330 IW_PRIV_TYPE_INT | 16,
1334 IW_PRIV_TYPE_INT | 16,
1335 IW_PRIV_TYPE_INT | 16,
1339 IW_PRIV_TYPE_INT | 16,
1340 IW_PRIV_TYPE_INT | 16,
1344 IW_PRIV_TYPE_INT | 16,
1345 IW_PRIV_TYPE_INT | 16,
1349 IW_PRIV_TYPE_INT | 16,
1350 IW_PRIV_TYPE_INT | 16,
1354 IW_PRIV_TYPE_INT | 16,
1355 IW_PRIV_TYPE_INT | 16,
1359 IW_PRIV_TYPE_INT | 16,
1360 IW_PRIV_TYPE_INT | 16,
1363 WLAN_INACTIVITY_TIMEOUT,
1364 IW_PRIV_TYPE_INT | 16,
1365 IW_PRIV_TYPE_INT | 16,
1369 IW_PRIV_TYPE_INT | 16,
1370 IW_PRIV_TYPE_INT | 16,
1374 IW_PRIV_TYPE_INT | 16,
1375 IW_PRIV_TYPE_INT | 16,
1379 IW_PRIV_TYPE_INT | 16,
1380 IW_PRIV_TYPE_INT | 16,
1384 static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
1394 wlan_private *priv = dev->priv;
1395 wlan_adapter *adapter = priv->adapter;
1399 int stats_valid = 0;
1405 priv->wstats.status = adapter->mode;
1407 /* If we're not associated, all quality values are meaningless */
1408 if (adapter->connect_status != libertas_connected)
1411 /* Quality by RSSI */
1412 priv->wstats.qual.level =
1413 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
1414 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1416 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1417 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1419 priv->wstats.qual.noise =
1420 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1423 lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
1424 lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
1426 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
1428 rssi_qual = rssi * POOR / 10;
1430 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
1432 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
1434 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
1437 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
1439 quality = rssi_qual;
1441 /* Quality by TX errors */
1442 priv->wstats.discard.retries = priv->stats.tx_errors;
1444 tx_retries = adapter->logmsg.retry;
1446 if (tx_retries > 75)
1447 tx_qual = (90 - tx_retries) * POOR / 15;
1448 else if (tx_retries > 70)
1449 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
1450 else if (tx_retries > 65)
1451 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
1452 else if (tx_retries > 50)
1453 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
1456 tx_qual = (50 - tx_retries) *
1457 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
1458 quality = min(quality, tx_qual);
1460 priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
1461 priv->wstats.discard.fragment = adapter->logmsg.fcserror;
1462 priv->wstats.discard.retries = tx_retries;
1463 priv->wstats.discard.misc = adapter->logmsg.ackfailure;
1465 /* Calculate quality */
1466 priv->wstats.qual.qual = max(quality, (u32)100);
1467 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1470 /* update stats asynchronously for future calls */
1471 libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
1473 libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
1477 priv->wstats.miss.beacon = 0;
1478 priv->wstats.discard.retries = 0;
1479 priv->wstats.qual.qual = 0;
1480 priv->wstats.qual.level = 0;
1481 priv->wstats.qual.noise = 0;
1482 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
1483 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
1484 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
1488 return &priv->wstats;
1493 static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
1494 struct iw_freq *fwrq, char *extra)
1497 wlan_private *priv = dev->priv;
1498 wlan_adapter *adapter = priv->adapter;
1499 int rc = -EINPROGRESS; /* Call commit handler */
1500 struct chan_freq_power *cfp;
1505 * If setting by frequency, convert to a channel
1509 long f = fwrq->m / 100000;
1512 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
1514 lbs_pr_debug(1, "Invalid freq=%ld\n", f);
1518 c = (int)cfp->channel;
1528 * Setting by channel number
1530 if (fwrq->m > 1000 || fwrq->e > 0) {
1533 int channel = fwrq->m;
1535 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel);
1539 if (adapter->mode == IW_MODE_ADHOC) {
1540 rc = changeadhocchannel(priv, channel);
1541 /* If station is WEP enabled, send the
1542 * command to set WEP in firmware
1544 if (adapter->secinfo.wep_enabled) {
1545 lbs_pr_debug(1, "set_freq: WEP enabled\n");
1546 ret = libertas_prepare_and_send_command(priv,
1549 cmd_option_waitforrsp,
1558 adapter->currentpacketfilter |=
1559 cmd_act_mac_wep_enable;
1561 libertas_set_mac_packet_filter(priv);
1574 * @brief use index to get the data rate
1576 * @param index The index of data rate
1577 * @return data rate or 0
1579 u32 libertas_index_to_data_rate(u8 index)
1581 if (index >= sizeof(libertas_wlan_data_rates))
1584 return libertas_wlan_data_rates[index];
1588 * @brief use rate to get the index
1590 * @param rate data rate
1591 * @return index or 0
1593 u8 libertas_data_rate_to_index(u32 rate)
1598 if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
1599 sizeof(libertas_wlan_data_rates))))
1600 return (ptr - libertas_wlan_data_rates);
1605 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
1606 struct iw_param *vwrq, char *extra)
1608 wlan_private *priv = dev->priv;
1609 wlan_adapter *adapter = priv->adapter;
1613 u8 rates[WLAN_SUPPORTED_RATES];
1618 lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
1620 if (vwrq->value == -1) {
1621 action = cmd_act_set_tx_auto; // Auto
1622 adapter->is_datarate_auto = 1;
1623 adapter->datarate = 0;
1625 if (vwrq->value % 100000) {
1629 data_rate = vwrq->value / 500000;
1631 memset(rates, 0, sizeof(rates));
1632 get_active_data_rates(adapter, rates);
1635 lbs_pr_debug(1, "Rate=0x%X Wanted=0x%X\n", *rate,
1637 if ((*rate & 0x7f) == (data_rate & 0x7f))
1642 lbs_pr_alert( "The fixed data rate 0x%X is out "
1643 "of range.\n", data_rate);
1647 adapter->datarate = data_rate;
1648 action = cmd_act_set_tx_fix_rate;
1649 adapter->is_datarate_auto = 0;
1652 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
1653 action, cmd_option_waitforrsp, 0, NULL);
1659 static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1660 struct iw_param *vwrq, char *extra)
1662 wlan_private *priv = dev->priv;
1663 wlan_adapter *adapter = priv->adapter;
1667 if (adapter->is_datarate_auto) {
1673 vwrq->value = adapter->datarate * 500000;
1679 static int wlan_set_mode(struct net_device *dev,
1680 struct iw_request_info *info, u32 * uwrq, char *extra)
1683 wlan_private *priv = dev->priv;
1684 wlan_adapter *adapter = priv->adapter;
1685 struct assoc_request * assoc_req;
1689 if ( (*uwrq != IW_MODE_ADHOC)
1690 && (*uwrq != IW_MODE_INFRA)
1691 && (*uwrq != IW_MODE_AUTO)) {
1692 lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq);
1697 mutex_lock(&adapter->lock);
1698 assoc_req = wlan_get_association_request(adapter);
1701 wlan_cancel_association_work(priv);
1703 assoc_req->mode = *uwrq;
1704 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1705 wlan_postpone_association_work(priv);
1706 lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq);
1708 mutex_unlock(&adapter->lock);
1717 * @brief Get Encryption key
1719 * @param dev A pointer to net_device structure
1720 * @param info A pointer to iw_request_info structure
1721 * @param vwrq A pointer to iw_param structure
1722 * @param extra A pointer to extra data buf
1723 * @return 0 --success, otherwise fail
1725 static int wlan_get_encode(struct net_device *dev,
1726 struct iw_request_info *info,
1727 struct iw_point *dwrq, u8 * extra)
1729 wlan_private *priv = dev->priv;
1730 wlan_adapter *adapter = priv->adapter;
1731 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1735 lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
1736 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1740 /* Authentication method */
1741 switch (adapter->secinfo.auth_mode) {
1742 case IW_AUTH_ALG_OPEN_SYSTEM:
1743 dwrq->flags = IW_ENCODE_OPEN;
1746 case IW_AUTH_ALG_SHARED_KEY:
1747 case IW_AUTH_ALG_LEAP:
1748 dwrq->flags = IW_ENCODE_RESTRICTED;
1751 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1755 if ( adapter->secinfo.wep_enabled
1756 || adapter->secinfo.WPAenabled
1757 || adapter->secinfo.WPA2enabled) {
1758 dwrq->flags &= ~IW_ENCODE_DISABLED;
1760 dwrq->flags |= IW_ENCODE_DISABLED;
1763 memset(extra, 0, 16);
1765 mutex_lock(&adapter->lock);
1767 /* Default to returning current transmit key */
1769 index = adapter->wep_tx_keyidx;
1771 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
1772 memcpy(extra, adapter->wep_keys[index].key,
1773 adapter->wep_keys[index].len);
1774 dwrq->length = adapter->wep_keys[index].len;
1776 dwrq->flags |= (index + 1);
1777 /* Return WEP enabled */
1778 dwrq->flags &= ~IW_ENCODE_DISABLED;
1779 } else if ((adapter->secinfo.WPAenabled)
1780 || (adapter->secinfo.WPA2enabled)) {
1781 /* return WPA enabled */
1782 dwrq->flags &= ~IW_ENCODE_DISABLED;
1784 dwrq->flags |= IW_ENCODE_DISABLED;
1787 mutex_unlock(&adapter->lock);
1789 dwrq->flags |= IW_ENCODE_NOKEY;
1791 lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
1792 extra[0], extra[1], extra[2],
1793 extra[3], extra[4], extra[5], dwrq->length);
1795 lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
1802 * @brief Set Encryption key (internal)
1804 * @param priv A pointer to private card structure
1805 * @param key_material A pointer to key material
1806 * @param key_length length of key material
1807 * @param index key index to set
1808 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1809 * @return 0 --success, otherwise fail
1811 static int wlan_set_wep_key(struct assoc_request *assoc_req,
1812 const char *key_material,
1817 struct WLAN_802_11_KEY *pkey;
1821 /* Paranoid validation of key index */
1827 /* validate max key length */
1828 if (key_length > KEY_LEN_WEP_104) {
1833 pkey = &assoc_req->wep_keys[index];
1835 if (key_length > 0) {
1836 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
1837 pkey->type = KEY_TYPE_ID_WEP;
1839 /* Standardize the key length */
1840 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1841 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1842 memcpy(pkey->key, key_material, key_length);
1846 /* Ensure the chosen key is valid */
1848 lbs_pr_debug(1, "key not set, so cannot enable it\n");
1852 assoc_req->wep_tx_keyidx = index;
1855 assoc_req->secinfo.wep_enabled = 1;
1861 static int validate_key_index(u16 def_index, u16 raw_index,
1862 u16 *out_index, u16 *is_default)
1864 if (!out_index || !is_default)
1867 /* Verify index if present, otherwise use default TX key index */
1868 if (raw_index > 0) {
1871 *out_index = raw_index - 1;
1873 *out_index = def_index;
1879 static void disable_wep(struct assoc_request *assoc_req)
1883 /* Set Open System auth mode */
1884 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1886 /* Clear WEP keys and mark WEP as disabled */
1887 assoc_req->secinfo.wep_enabled = 0;
1888 for (i = 0; i < 4; i++)
1889 assoc_req->wep_keys[i].len = 0;
1891 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1892 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1896 * @brief Set Encryption key
1898 * @param dev A pointer to net_device structure
1899 * @param info A pointer to iw_request_info structure
1900 * @param vwrq A pointer to iw_param structure
1901 * @param extra A pointer to extra data buf
1902 * @return 0 --success, otherwise fail
1904 static int wlan_set_encode(struct net_device *dev,
1905 struct iw_request_info *info,
1906 struct iw_point *dwrq, char *extra)
1909 wlan_private *priv = dev->priv;
1910 wlan_adapter *adapter = priv->adapter;
1911 struct assoc_request * assoc_req;
1912 u16 is_default = 0, index = 0, set_tx_key = 0;
1916 mutex_lock(&adapter->lock);
1917 assoc_req = wlan_get_association_request(adapter);
1923 if (dwrq->flags & IW_ENCODE_DISABLED) {
1924 disable_wep (assoc_req);
1928 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1929 (dwrq->flags & IW_ENCODE_INDEX),
1930 &index, &is_default);
1936 /* If WEP isn't enabled, or if there is no key data but a valid
1937 * index, set the TX key.
1939 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1942 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1947 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1949 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1951 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1952 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1953 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1954 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1959 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1960 wlan_postpone_association_work(priv);
1962 wlan_cancel_association_work(priv);
1964 mutex_unlock(&adapter->lock);
1971 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1973 * @param dev A pointer to net_device structure
1974 * @param info A pointer to iw_request_info structure
1975 * @param vwrq A pointer to iw_param structure
1976 * @param extra A pointer to extra data buf
1977 * @return 0 on success, otherwise failure
1979 static int wlan_get_encodeext(struct net_device *dev,
1980 struct iw_request_info *info,
1981 struct iw_point *dwrq,
1985 wlan_private *priv = dev->priv;
1986 wlan_adapter *adapter = priv->adapter;
1987 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1988 int index, max_key_len;
1992 max_key_len = dwrq->length - sizeof(*ext);
1993 if (max_key_len < 0)
1996 index = dwrq->flags & IW_ENCODE_INDEX;
1998 if (index < 1 || index > 4)
2002 index = adapter->wep_tx_keyidx;
2005 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
2006 ext->alg != IW_ENCODE_ALG_WEP) {
2007 if (index != 0 || adapter->mode != IW_MODE_INFRA)
2011 dwrq->flags = index + 1;
2012 memset(ext, 0, sizeof(*ext));
2014 if ( !adapter->secinfo.wep_enabled
2015 && !adapter->secinfo.WPAenabled
2016 && !adapter->secinfo.WPA2enabled) {
2017 ext->alg = IW_ENCODE_ALG_NONE;
2019 dwrq->flags |= IW_ENCODE_DISABLED;
2023 if ( adapter->secinfo.wep_enabled
2024 && !adapter->secinfo.WPAenabled
2025 && !adapter->secinfo.WPA2enabled) {
2026 ext->alg = IW_ENCODE_ALG_WEP;
2027 ext->key_len = adapter->wep_keys[index].len;
2028 key = &adapter->wep_keys[index].key[0];
2029 } else if ( !adapter->secinfo.wep_enabled
2030 && (adapter->secinfo.WPAenabled ||
2031 adapter->secinfo.WPA2enabled)) {
2033 ext->alg = IW_ENCODE_ALG_TKIP;
2039 if (ext->key_len > max_key_len) {
2045 memcpy(ext->key, key, ext->key_len);
2047 dwrq->flags |= IW_ENCODE_NOKEY;
2048 dwrq->flags |= IW_ENCODE_ENABLED;
2058 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
2060 * @param dev A pointer to net_device structure
2061 * @param info A pointer to iw_request_info structure
2062 * @param vwrq A pointer to iw_param structure
2063 * @param extra A pointer to extra data buf
2064 * @return 0 --success, otherwise fail
2066 static int wlan_set_encodeext(struct net_device *dev,
2067 struct iw_request_info *info,
2068 struct iw_point *dwrq,
2072 wlan_private *priv = dev->priv;
2073 wlan_adapter *adapter = priv->adapter;
2074 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2076 struct assoc_request * assoc_req;
2080 mutex_lock(&adapter->lock);
2081 assoc_req = wlan_get_association_request(adapter);
2087 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
2088 disable_wep (assoc_req);
2089 } else if (alg == IW_ENCODE_ALG_WEP) {
2090 u16 is_default = 0, index, set_tx_key = 0;
2092 ret = validate_key_index(assoc_req->wep_tx_keyidx,
2093 (dwrq->flags & IW_ENCODE_INDEX),
2094 &index, &is_default);
2098 /* If WEP isn't enabled, or if there is no key data but a valid
2099 * index, or if the set-TX-key flag was passed, set the TX key.
2101 if ( !assoc_req->secinfo.wep_enabled
2102 || (dwrq->length == 0 && !is_default)
2103 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
2106 /* Copy key to driver */
2107 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
2112 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
2113 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2114 } else if (dwrq->flags & IW_ENCODE_OPEN) {
2115 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2118 /* Mark the various WEP bits as modified */
2119 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2121 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
2123 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
2125 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
2126 struct WLAN_802_11_KEY * pkey;
2128 /* validate key length */
2129 if (((alg == IW_ENCODE_ALG_TKIP)
2130 && (ext->key_len != KEY_LEN_WPA_TKIP))
2131 || ((alg == IW_ENCODE_ALG_CCMP)
2132 && (ext->key_len != KEY_LEN_WPA_AES))) {
2133 lbs_pr_debug(1, "Invalid size %d for key of alg"
2141 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2142 pkey = &assoc_req->wpa_mcast_key;
2144 pkey = &assoc_req->wpa_unicast_key;
2146 memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
2147 memcpy(pkey->key, ext->key, ext->key_len);
2148 pkey->len = ext->key_len;
2149 pkey->flags = KEY_INFO_WPA_ENABLED;
2151 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
2152 pkey->flags |= KEY_INFO_WPA_MCAST;
2153 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
2155 pkey->flags |= KEY_INFO_WPA_UNICAST;
2156 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
2159 if (alg == IW_ENCODE_ALG_TKIP)
2160 pkey->type = KEY_TYPE_ID_TKIP;
2161 else if (alg == IW_ENCODE_ALG_CCMP)
2162 pkey->type = KEY_TYPE_ID_AES;
2164 /* If WPA isn't enabled yet, do that now */
2165 if ( assoc_req->secinfo.WPAenabled == 0
2166 && assoc_req->secinfo.WPA2enabled == 0) {
2167 assoc_req->secinfo.WPAenabled = 1;
2168 assoc_req->secinfo.WPA2enabled = 1;
2169 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2172 disable_wep (assoc_req);
2177 wlan_postpone_association_work(priv);
2179 wlan_cancel_association_work(priv);
2181 mutex_unlock(&adapter->lock);
2188 static int wlan_set_genie(struct net_device *dev,
2189 struct iw_request_info *info,
2190 struct iw_point *dwrq,
2193 wlan_private *priv = dev->priv;
2194 wlan_adapter *adapter = priv->adapter;
2196 struct assoc_request * assoc_req;
2200 mutex_lock(&adapter->lock);
2201 assoc_req = wlan_get_association_request(adapter);
2207 if (dwrq->length > MAX_WPA_IE_LEN ||
2208 (dwrq->length && extra == NULL)) {
2214 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
2215 assoc_req->wpa_ie_len = dwrq->length;
2217 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
2218 assoc_req->wpa_ie_len = 0;
2223 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
2224 wlan_postpone_association_work(priv);
2226 wlan_cancel_association_work(priv);
2228 mutex_unlock(&adapter->lock);
2234 static int wlan_get_genie(struct net_device *dev,
2235 struct iw_request_info *info,
2236 struct iw_point *dwrq,
2239 wlan_private *priv = dev->priv;
2240 wlan_adapter *adapter = priv->adapter;
2244 if (adapter->wpa_ie_len == 0) {
2250 if (dwrq->length < adapter->wpa_ie_len) {
2255 dwrq->length = adapter->wpa_ie_len;
2256 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
2263 static int wlan_set_auth(struct net_device *dev,
2264 struct iw_request_info *info,
2265 struct iw_param *dwrq,
2268 wlan_private *priv = dev->priv;
2269 wlan_adapter *adapter = priv->adapter;
2270 struct assoc_request * assoc_req;
2276 mutex_lock(&adapter->lock);
2277 assoc_req = wlan_get_association_request(adapter);
2283 switch (dwrq->flags & IW_AUTH_INDEX) {
2284 case IW_AUTH_TKIP_COUNTERMEASURES:
2285 case IW_AUTH_CIPHER_PAIRWISE:
2286 case IW_AUTH_CIPHER_GROUP:
2287 case IW_AUTH_KEY_MGMT:
2289 * libertas does not use these parameters
2293 case IW_AUTH_WPA_VERSION:
2294 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
2295 assoc_req->secinfo.WPAenabled = 0;
2296 assoc_req->secinfo.WPA2enabled = 0;
2298 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
2299 assoc_req->secinfo.WPAenabled = 1;
2300 assoc_req->secinfo.wep_enabled = 0;
2301 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2303 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
2304 assoc_req->secinfo.WPA2enabled = 1;
2305 assoc_req->secinfo.wep_enabled = 0;
2306 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2311 case IW_AUTH_DROP_UNENCRYPTED:
2313 adapter->currentpacketfilter |=
2314 cmd_act_mac_strict_protection_enable;
2316 adapter->currentpacketfilter &=
2317 ~cmd_act_mac_strict_protection_enable;
2322 case IW_AUTH_80211_AUTH_ALG:
2323 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
2324 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2325 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
2326 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2327 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
2328 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
2335 case IW_AUTH_WPA_ENABLED:
2337 if (!assoc_req->secinfo.WPAenabled &&
2338 !assoc_req->secinfo.WPA2enabled) {
2339 assoc_req->secinfo.WPAenabled = 1;
2340 assoc_req->secinfo.WPA2enabled = 1;
2341 assoc_req->secinfo.wep_enabled = 0;
2342 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2345 assoc_req->secinfo.WPAenabled = 0;
2346 assoc_req->secinfo.WPA2enabled = 0;
2359 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2360 wlan_postpone_association_work(priv);
2361 } else if (ret != -EOPNOTSUPP) {
2362 wlan_cancel_association_work(priv);
2364 mutex_unlock(&adapter->lock);
2370 static int wlan_get_auth(struct net_device *dev,
2371 struct iw_request_info *info,
2372 struct iw_param *dwrq,
2375 wlan_private *priv = dev->priv;
2376 wlan_adapter *adapter = priv->adapter;
2380 switch (dwrq->flags & IW_AUTH_INDEX) {
2381 case IW_AUTH_WPA_VERSION:
2383 if (adapter->secinfo.WPAenabled)
2384 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
2385 if (adapter->secinfo.WPA2enabled)
2386 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
2388 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
2391 case IW_AUTH_DROP_UNENCRYPTED:
2393 if (adapter->currentpacketfilter &
2394 cmd_act_mac_strict_protection_enable)
2398 case IW_AUTH_80211_AUTH_ALG:
2399 dwrq->value = adapter->secinfo.auth_mode;
2402 case IW_AUTH_WPA_ENABLED:
2403 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
2417 static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
2418 struct iw_param *vwrq, char *extra)
2421 wlan_private *priv = dev->priv;
2422 wlan_adapter *adapter = priv->adapter;
2428 if (vwrq->disabled) {
2429 wlan_radio_ioctl(priv, RADIO_OFF);
2433 adapter->preamble = cmd_type_auto_preamble;
2435 wlan_radio_ioctl(priv, RADIO_ON);
2437 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
2438 dbm = (u16) mw_to_dbm(vwrq->value);
2440 dbm = (u16) vwrq->value;
2442 /* auto tx power control */
2444 if (vwrq->fixed == 0)
2447 lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
2449 ret = libertas_prepare_and_send_command(priv,
2450 cmd_802_11_rf_tx_power,
2451 cmd_act_tx_power_opt_set_low,
2452 cmd_option_waitforrsp, 0, (void *)&dbm);
2458 static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
2459 struct iw_point *dwrq, char *extra)
2461 wlan_private *priv = dev->priv;
2462 wlan_adapter *adapter = priv->adapter;
2466 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2471 * Get the current SSID
2473 if (adapter->connect_status == libertas_connected) {
2474 memcpy(extra, adapter->curbssparams.ssid.ssid,
2475 adapter->curbssparams.ssid.ssidlength);
2476 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2478 memset(extra, 0, 32);
2479 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2482 * If none, we may want to get the one that was set
2485 /* To make the driver backward compatible with WPA supplicant v0.2.4 */
2486 if (dwrq->length == 32) /* check with WPA supplicant buffer size */
2487 dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
2490 dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
2492 dwrq->flags = 1; /* active */
2498 static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
2499 struct iw_point *dwrq, char *extra)
2501 wlan_private *priv = dev->priv;
2502 wlan_adapter *adapter = priv->adapter;
2504 struct WLAN_802_11_SSID ssid;
2505 struct assoc_request * assoc_req;
2506 int ssid_len = dwrq->length;
2511 * WE-20 and earlier NULL pad the end of the SSID and increment
2512 * SSID length so it can be used like a string. WE-21 and later don't,
2513 * but some userspace tools aren't able to cope with the change.
2515 if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
2518 /* Check the size of the string */
2519 if (ssid_len > IW_ESSID_MAX_SIZE) {
2524 memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
2526 if (!dwrq->flags || !ssid_len) {
2527 /* "any" SSID requested; leave SSID blank */
2529 /* Specific SSID requested */
2530 memcpy(&ssid.ssid, extra, ssid_len);
2531 ssid.ssidlength = ssid_len;
2534 lbs_pr_debug(1, "Requested new SSID = %s\n",
2535 (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
2538 mutex_lock(&adapter->lock);
2540 /* Get or create the current association request */
2541 assoc_req = wlan_get_association_request(adapter);
2545 /* Copy the SSID to the association request */
2546 memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
2547 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2548 wlan_postpone_association_work(priv);
2552 /* Cancel the association request if there was an error */
2554 wlan_cancel_association_work(priv);
2557 mutex_unlock(&adapter->lock);
2564 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2566 * @param dev A pointer to net_device structure
2567 * @param info A pointer to iw_request_info structure
2568 * @param awrq A pointer to iw_param structure
2569 * @param extra A pointer to extra data buf
2570 * @return 0 --success, otherwise fail
2572 static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
2573 struct sockaddr *awrq, char *extra)
2575 wlan_private *priv = dev->priv;
2576 wlan_adapter *adapter = priv->adapter;
2577 struct assoc_request * assoc_req;
2582 if (awrq->sa_family != ARPHRD_ETHER)
2585 lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
2587 mutex_lock(&adapter->lock);
2589 /* Get or create the current association request */
2590 assoc_req = wlan_get_association_request(adapter);
2592 wlan_cancel_association_work(priv);
2595 /* Copy the BSSID to the association request */
2596 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2597 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2598 wlan_postpone_association_work(priv);
2601 mutex_unlock(&adapter->lock);
2606 void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2614 mutex_lock(&adapter->lock);
2615 ver.l = adapter->fwreleasenumber;
2616 mutex_unlock(&adapter->lock);
2619 sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
2621 sprintf(fwver, "%u.%u.%u.p%u",
2622 ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
2624 snprintf(fwversion, maxlen, fwver);
2629 * iwconfig settable callbacks
2631 static const iw_handler wlan_handler[] = {
2632 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2633 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2634 (iw_handler) NULL, /* SIOCSIWNWID */
2635 (iw_handler) NULL, /* SIOCGIWNWID */
2636 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2637 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2638 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2639 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2640 (iw_handler) NULL, /* SIOCSIWSENS */
2641 (iw_handler) NULL, /* SIOCGIWSENS */
2642 (iw_handler) NULL, /* SIOCSIWRANGE */
2643 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2644 (iw_handler) NULL, /* SIOCSIWPRIV */
2645 (iw_handler) NULL, /* SIOCGIWPRIV */
2646 (iw_handler) NULL, /* SIOCSIWSTATS */
2647 (iw_handler) NULL, /* SIOCGIWSTATS */
2648 iw_handler_set_spy, /* SIOCSIWSPY */
2649 iw_handler_get_spy, /* SIOCGIWSPY */
2650 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2651 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2652 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2653 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2654 (iw_handler) NULL, /* SIOCSIWMLME */
2655 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2656 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2657 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2658 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2659 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2660 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2661 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2662 (iw_handler) NULL, /* -- hole -- */
2663 (iw_handler) NULL, /* -- hole -- */
2664 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2665 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2666 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2667 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2668 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2669 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2670 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2671 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2672 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2673 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2674 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2675 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2676 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2677 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2678 (iw_handler) NULL, /* -- hole -- */
2679 (iw_handler) NULL, /* -- hole -- */
2680 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2681 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2682 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2683 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2684 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2685 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2686 (iw_handler) NULL, /* SIOCSIWPMKSA */
2689 struct iw_handler_def libertas_handler_def = {
2690 .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
2691 .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
2692 .num_private_args = sizeof(wlan_private_args) /
2693 sizeof(struct iw_priv_args),
2694 .standard = (iw_handler *) wlan_handler,
2695 .private = (iw_handler *) wlan_private_handler,
2696 .private_args = (struct iw_priv_args *)wlan_private_args,
2697 .get_wireless_stats = wlan_get_wireless_stats,