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>
25 * @brief Convert mw value to dbm value
27 * @param mw the value of mw
28 * @return the value of dbm
30 static int mw_to_dbm(int mw)
71 * @brief Find the channel frequency power info with specific channel
73 * @param adapter A pointer to wlan_adapter structure
74 * @param band it can be BAND_A, BAND_G or BAND_B
75 * @param channel the channel for looking
76 * @return A pointer to struct chan_freq_power structure or NULL if not find.
78 struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
81 struct chan_freq_power *cfp = NULL;
82 struct region_channel *rc;
83 int count = sizeof(adapter->region_channel) /
84 sizeof(adapter->region_channel[0]);
87 for (j = 0; !cfp && (j < count); j++) {
88 rc = &adapter->region_channel[j];
90 if (adapter->enable11d)
91 rc = &adapter->universal_channel[j];
92 if (!rc->valid || !rc->CFP)
96 for (i = 0; i < rc->nrcfp; i++) {
97 if (rc->CFP[i].channel == channel) {
105 lbs_pr_debug(1, "libertas_find_cfp_by_band_and_channel(): cannot find "
106 "cfp by band %d & channel %d\n", band, channel);
112 * @brief Find the channel frequency power info with specific frequency
114 * @param adapter A pointer to wlan_adapter structure
115 * @param band it can be BAND_A, BAND_G or BAND_B
116 * @param freq the frequency for looking
117 * @return A pointer to struct chan_freq_power structure or NULL if not find.
119 static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
122 struct chan_freq_power *cfp = NULL;
123 struct region_channel *rc;
124 int count = sizeof(adapter->region_channel) /
125 sizeof(adapter->region_channel[0]);
128 for (j = 0; !cfp && (j < count); j++) {
129 rc = &adapter->region_channel[j];
131 if (adapter->enable11d)
132 rc = &adapter->universal_channel[j];
133 if (!rc->valid || !rc->CFP)
135 if (rc->band != band)
137 for (i = 0; i < rc->nrcfp; i++) {
138 if (rc->CFP[i].freq == freq) {
146 lbs_pr_debug(1, "find_cfp_by_band_and_freql(): cannot find cfp by "
147 "band %d & freq %d\n", band, freq);
152 static int updatecurrentchannel(wlan_private * priv)
157 ** the channel in f/w could be out of sync, get the current channel
159 ret = libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
160 cmd_opt_802_11_rf_channel_get,
161 cmd_option_waitforrsp, 0, NULL);
163 lbs_pr_debug(1, "Current channel = %d\n",
164 priv->adapter->curbssparams.channel);
169 static int setcurrentchannel(wlan_private * priv, int channel)
171 lbs_pr_debug(1, "Set channel = %d\n", channel);
174 ** Current channel is not set to adhocchannel requested, set channel
176 return (libertas_prepare_and_send_command(priv, cmd_802_11_rf_channel,
177 cmd_opt_802_11_rf_channel_set,
178 cmd_option_waitforrsp, 0, &channel));
181 static int changeadhocchannel(wlan_private * priv, int channel)
184 wlan_adapter *adapter = priv->adapter;
186 adapter->adhocchannel = channel;
188 updatecurrentchannel(priv);
190 if (adapter->curbssparams.channel == adapter->adhocchannel) {
191 /* adhocchannel is set to the current channel already */
196 lbs_pr_debug(1, "Updating channel from %d to %d\n",
197 adapter->curbssparams.channel, adapter->adhocchannel);
199 setcurrentchannel(priv, adapter->adhocchannel);
201 updatecurrentchannel(priv);
203 if (adapter->curbssparams.channel != adapter->adhocchannel) {
204 lbs_pr_debug(1, "failed to updated channel to %d, channel = %d\n",
205 adapter->adhocchannel, adapter->curbssparams.channel);
210 if (adapter->connect_status == libertas_connected) {
212 struct WLAN_802_11_SSID curadhocssid;
214 lbs_pr_debug(1, "channel Changed while in an IBSS\n");
216 /* Copy the current ssid */
217 memcpy(&curadhocssid, &adapter->curbssparams.ssid,
218 sizeof(struct WLAN_802_11_SSID));
220 /* Exit Adhoc mode */
221 lbs_pr_debug(1, "In changeadhocchannel(): Sending Adhoc Stop\n");
222 ret = libertas_stop_adhoc_network(priv);
228 /* Scan for the network, do not save previous results. Stale
229 * scan data will cause us to join a non-existant adhoc network
231 libertas_send_specific_SSID_scan(priv, &curadhocssid, 0);
233 // find out the BSSID that matches the current SSID
234 i = libertas_find_SSID_in_list(adapter, &curadhocssid, NULL,
238 lbs_pr_debug(1, "SSID found at %d in List,"
240 libertas_join_adhoc_network(priv, &adapter->scantable[i]);
242 // else send START command
243 lbs_pr_debug(1, "SSID not found in list, "
244 "so creating adhoc with ssid = %s\n",
246 libertas_start_adhoc_network(priv, &curadhocssid);
247 } // end of else (START command)
255 * @brief Set Radio On/OFF
257 * @param priv A pointer to wlan_private structure
258 * @option Radio Option
259 * @return 0 --success, otherwise fail
261 int wlan_radio_ioctl(wlan_private * priv, u8 option)
264 wlan_adapter *adapter = priv->adapter;
268 if (adapter->radioon != option) {
269 lbs_pr_debug(1, "Switching %s the Radio\n", option ? "On" : "Off");
270 adapter->radioon = option;
272 ret = libertas_prepare_and_send_command(priv,
273 cmd_802_11_radio_control,
275 cmd_option_waitforrsp, 0, NULL);
285 * @param dest A pointer to Dest Buf
286 * @param src A pointer to Src Buf
287 * @param len The len of Src Buf
288 * @return Number of rates copyed
290 static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
294 for (i = 0; i < len && src[i]; i++, pos++) {
295 if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
304 * @brief Get active data rates
306 * @param adapter A pointer to wlan_adapter structure
307 * @param rate The buf to return the active rates
308 * @return The number of rates
310 static int get_active_data_rates(wlan_adapter * adapter,
317 if (adapter->connect_status != libertas_connected) {
318 if (adapter->mode == IW_MODE_INFRA) {
319 lbs_pr_debug(1, "Infra\n");
320 k = copyrates(rates, k, libertas_supported_rates,
321 sizeof(libertas_supported_rates));
323 lbs_pr_debug(1, "Adhoc G\n");
324 k = copyrates(rates, k, libertas_adhoc_rates_g,
325 sizeof(libertas_adhoc_rates_g));
328 k = copyrates(rates, 0, adapter->curbssparams.datarates,
329 adapter->curbssparams.numofrates);
337 static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
338 char *cwrq, char *extra)
341 char comm[6] = { "COMM-" };
342 char mrvl[6] = { "MRVL-" };
349 cp = strstr(libertas_driver_version, comm);
350 if (cp == libertas_driver_version) //skip leading "COMM-"
351 cp = libertas_driver_version + strlen(comm);
353 cp = libertas_driver_version;
357 while (cnt < 16 && (*cp != '-')) {
358 *cwrq++ = toupper(*cp++);
368 static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
369 struct iw_freq *fwrq, char *extra)
371 wlan_private *priv = dev->priv;
372 wlan_adapter *adapter = priv->adapter;
373 struct chan_freq_power *cfp;
377 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
378 adapter->curbssparams.channel);
381 if (adapter->curbssparams.channel)
382 lbs_pr_debug(1, "Invalid channel=%d\n",
383 adapter->curbssparams.channel);
387 fwrq->m = (long)cfp->freq * 100000;
390 lbs_pr_debug(1, "freq=%u\n", fwrq->m);
396 static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
397 struct sockaddr *awrq, char *extra)
399 wlan_private *priv = dev->priv;
400 wlan_adapter *adapter = priv->adapter;
404 if (adapter->connect_status == libertas_connected) {
405 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
407 memset(awrq->sa_data, 0, ETH_ALEN);
409 awrq->sa_family = ARPHRD_ETHER;
415 static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
416 struct iw_point *dwrq, char *extra)
418 wlan_private *priv = dev->priv;
419 wlan_adapter *adapter = priv->adapter;
424 * Check the size of the string
427 if (dwrq->length > 16) {
431 mutex_lock(&adapter->lock);
432 memset(adapter->nodename, 0, sizeof(adapter->nodename));
433 memcpy(adapter->nodename, extra, dwrq->length);
434 mutex_unlock(&adapter->lock);
440 static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
441 struct iw_point *dwrq, char *extra)
443 wlan_private *priv = dev->priv;
444 wlan_adapter *adapter = priv->adapter;
449 * Get the Nick Name saved
452 mutex_lock(&adapter->lock);
453 strncpy(extra, adapter->nodename, 16);
454 mutex_unlock(&adapter->lock);
459 * If none, we may want to get the one that was set
465 dwrq->length = strlen(extra) + 1;
471 static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
472 struct iw_param *vwrq, char *extra)
475 wlan_private *priv = dev->priv;
476 wlan_adapter *adapter = priv->adapter;
477 int rthr = vwrq->value;
481 if (vwrq->disabled) {
482 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
484 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
486 adapter->rtsthsd = rthr;
489 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
490 cmd_act_set, cmd_option_waitforrsp,
491 OID_802_11_RTS_THRESHOLD, &rthr);
497 static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
498 struct iw_param *vwrq, char *extra)
501 wlan_private *priv = dev->priv;
502 wlan_adapter *adapter = priv->adapter;
506 adapter->rtsthsd = 0;
507 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
508 cmd_act_get, cmd_option_waitforrsp,
509 OID_802_11_RTS_THRESHOLD, NULL);
515 vwrq->value = adapter->rtsthsd;
516 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
517 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
524 static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
525 struct iw_param *vwrq, char *extra)
528 int fthr = vwrq->value;
529 wlan_private *priv = dev->priv;
530 wlan_adapter *adapter = priv->adapter;
534 if (vwrq->disabled) {
535 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
537 if (fthr < MRVDRV_FRAG_MIN_VALUE
538 || fthr > MRVDRV_FRAG_MAX_VALUE)
540 adapter->fragthsd = fthr;
543 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
544 cmd_act_set, cmd_option_waitforrsp,
545 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
550 static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
551 struct iw_param *vwrq, char *extra)
554 wlan_private *priv = dev->priv;
555 wlan_adapter *adapter = priv->adapter;
559 adapter->fragthsd = 0;
560 ret = libertas_prepare_and_send_command(priv,
562 cmd_act_get, cmd_option_waitforrsp,
563 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
569 vwrq->value = adapter->fragthsd;
570 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
571 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
578 static int wlan_get_mode(struct net_device *dev,
579 struct iw_request_info *info, u32 * uwrq, char *extra)
581 wlan_private *priv = dev->priv;
582 wlan_adapter *adapter = priv->adapter;
586 *uwrq = adapter->mode;
592 static int wlan_get_txpow(struct net_device *dev,
593 struct iw_request_info *info,
594 struct iw_param *vwrq, char *extra)
597 wlan_private *priv = dev->priv;
598 wlan_adapter *adapter = priv->adapter;
602 ret = libertas_prepare_and_send_command(priv,
603 cmd_802_11_rf_tx_power,
604 cmd_act_tx_power_opt_get,
605 cmd_option_waitforrsp, 0, NULL);
612 lbs_pr_debug(1, "TXPOWER GET %d dbm.\n", adapter->txpowerlevel);
613 vwrq->value = adapter->txpowerlevel;
615 if (adapter->radioon) {
617 vwrq->flags = IW_TXPOW_DBM;
626 static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
627 struct iw_param *vwrq, char *extra)
630 wlan_private *priv = dev->priv;
631 wlan_adapter *adapter = priv->adapter;
635 if (vwrq->flags == IW_RETRY_LIMIT) {
636 /* The MAC has a 4-bit Total_Tx_Count register
637 Total_Tx_Count = 1 + Tx_Retry_Count */
638 #define TX_RETRY_MIN 0
639 #define TX_RETRY_MAX 14
640 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
643 /* Adding 1 to convert retry count to try count */
644 adapter->txretrycount = vwrq->value + 1;
646 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
648 cmd_option_waitforrsp,
649 OID_802_11_TX_RETRYCOUNT, NULL);
663 static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
664 struct iw_param *vwrq, char *extra)
666 wlan_private *priv = dev->priv;
667 wlan_adapter *adapter = priv->adapter;
671 adapter->txretrycount = 0;
672 ret = libertas_prepare_and_send_command(priv,
674 cmd_act_get, cmd_option_waitforrsp,
675 OID_802_11_TX_RETRYCOUNT, NULL);
682 vwrq->flags = IW_RETRY_LIMIT;
683 /* Subtract 1 to convert try count to retry count */
684 vwrq->value = adapter->txretrycount - 1;
691 static inline void sort_channels(struct iw_freq *freq, int num)
696 for (i = 0; i < num; i++)
697 for (j = i + 1; j < num; j++)
698 if (freq[i].i > freq[j].i) {
702 freq[i].i = freq[j].i;
703 freq[i].m = freq[j].m;
713 Infra G(12) A(8) B(4) G(12)
714 Adhoc A+B(12) A(8) B(4) B(4)
722 * @brief Get Range Info
724 * @param dev A pointer to net_device structure
725 * @param info A pointer to iw_request_info structure
726 * @param vwrq A pointer to iw_param structure
727 * @param extra A pointer to extra data buf
728 * @return 0 --success, otherwise fail
730 static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
731 struct iw_point *dwrq, char *extra)
734 wlan_private *priv = dev->priv;
735 wlan_adapter *adapter = priv->adapter;
736 struct iw_range *range = (struct iw_range *)extra;
737 struct chan_freq_power *cfp;
738 u8 rates[WLAN_SUPPORTED_RATES];
744 dwrq->length = sizeof(struct iw_range);
745 memset(range, 0, sizeof(struct iw_range));
750 memset(rates, 0, sizeof(rates));
751 range->num_bitrates = get_active_data_rates(adapter, rates);
753 for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
755 range->bitrate[i] = (rates[i] & 0x7f) * 500000;
757 range->num_bitrates = i;
758 lbs_pr_debug(1, "IW_MAX_BITRATES=%d num_bitrates=%d\n", IW_MAX_BITRATES,
759 range->num_bitrates);
761 range->num_frequency = 0;
762 if (priv->adapter->enable11d &&
763 adapter->connect_status == libertas_connected) {
767 struct parsed_region_chan_11d *parsed_region_chan =
768 &adapter->parsed_region_chan;
770 if (parsed_region_chan == NULL) {
771 lbs_pr_debug(1, "11D:parsed_region_chan is NULL\n");
775 band = parsed_region_chan->band;
776 lbs_pr_debug(1, "band=%d NoOfChan=%d\n", band,
777 parsed_region_chan->nr_chan);
779 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
780 && (i < parsed_region_chan->nr_chan); i++) {
781 chan_no = parsed_region_chan->chanpwr[i].chan;
782 lbs_pr_debug(1, "chan_no=%d\n", chan_no);
783 range->freq[range->num_frequency].i = (long)chan_no;
784 range->freq[range->num_frequency].m =
785 (long)libertas_chan_2_freq(chan_no, band) * 100000;
786 range->freq[range->num_frequency].e = 1;
787 range->num_frequency++;
792 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
793 && (j < sizeof(adapter->region_channel)
794 / sizeof(adapter->region_channel[0])); j++) {
795 cfp = adapter->region_channel[j].CFP;
796 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
797 && adapter->region_channel[j].valid
799 && (i < adapter->region_channel[j].nrcfp); i++) {
800 range->freq[range->num_frequency].i =
802 range->freq[range->num_frequency].m =
803 (long)cfp->freq * 100000;
804 range->freq[range->num_frequency].e = 1;
806 range->num_frequency++;
811 lbs_pr_debug(1, "IW_MAX_FREQUENCIES=%d num_frequency=%d\n",
812 IW_MAX_FREQUENCIES, range->num_frequency);
814 range->num_channels = range->num_frequency;
816 sort_channels(&range->freq[0], range->num_frequency);
819 * Set an indication of the max TCP throughput in bit/s that we can
820 * expect using this interface
823 range->throughput = 5000 * 1000;
825 range->throughput = 1500 * 1000;
827 range->min_rts = MRVDRV_RTS_MIN_VALUE;
828 range->max_rts = MRVDRV_RTS_MAX_VALUE;
829 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
830 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
832 range->encoding_size[0] = 5;
833 range->encoding_size[1] = 13;
834 range->num_encoding_sizes = 2;
835 range->max_encoding_tokens = 4;
837 range->min_pmp = 1000000;
838 range->max_pmp = 120000000;
839 range->min_pmt = 1000;
840 range->max_pmt = 1000000;
841 range->pmp_flags = IW_POWER_PERIOD;
842 range->pmt_flags = IW_POWER_TIMEOUT;
843 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
846 * Minimum version we recommend
848 range->we_version_source = 15;
851 * Version we are compiled with
853 range->we_version_compiled = WIRELESS_EXT;
855 range->retry_capa = IW_RETRY_LIMIT;
856 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
858 range->min_retry = TX_RETRY_MIN;
859 range->max_retry = TX_RETRY_MAX;
862 * Set the qual, level and noise range values
864 range->max_qual.qual = 100;
865 range->max_qual.level = 0;
866 range->max_qual.noise = 0;
867 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
869 range->avg_qual.qual = 70;
870 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
871 range->avg_qual.level = 0;
872 range->avg_qual.noise = 0;
873 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
875 range->sensitivity = 0;
878 * Setup the supported power level ranges
880 memset(range->txpower, 0, sizeof(range->txpower));
881 range->txpower[0] = 5;
882 range->txpower[1] = 7;
883 range->txpower[2] = 9;
884 range->txpower[3] = 11;
885 range->txpower[4] = 13;
886 range->txpower[5] = 15;
887 range->txpower[6] = 17;
888 range->txpower[7] = 19;
890 range->num_txpower = 8;
891 range->txpower_capa = IW_TXPOW_DBM;
892 range->txpower_capa |= IW_TXPOW_RANGE;
894 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
895 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
896 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
897 range->event_capa[1] = IW_EVENT_CAPA_K_1;
899 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
900 range->enc_capa = IW_ENC_CAPA_WPA
902 | IW_ENC_CAPA_CIPHER_TKIP
903 | IW_ENC_CAPA_CIPHER_CCMP;
910 static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
911 struct iw_param *vwrq, char *extra)
913 wlan_private *priv = dev->priv;
914 wlan_adapter *adapter = priv->adapter;
918 /* PS is currently supported only in Infrastructure mode
919 * Remove this check if it is to be supported in IBSS mode also
922 if (vwrq->disabled) {
923 adapter->psmode = wlan802_11powermodecam;
924 if (adapter->psstate != PS_STATE_FULL_POWER) {
925 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
931 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
933 "Setting power timeout command is not supported\n");
935 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
936 lbs_pr_debug(1, "Setting power period command is not supported\n");
940 if (adapter->psmode != wlan802_11powermodecam) {
944 adapter->psmode = wlan802_11powermodemax_psp;
946 if (adapter->connect_status == libertas_connected) {
947 libertas_ps_sleep(priv, cmd_option_waitforrsp);
954 static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
955 struct iw_param *vwrq, char *extra)
957 wlan_private *priv = dev->priv;
958 wlan_adapter *adapter = priv->adapter;
963 mode = adapter->psmode;
965 if ((vwrq->disabled = (mode == wlan802_11powermodecam))
966 || adapter->connect_status == libertas_disconnected) {
978 * iwpriv settable callbacks
981 static const iw_handler wlan_private_handler[] = {
982 NULL, /* SIOCIWFIRSTPRIV */
985 static const struct iw_priv_args wlan_private_args[] = {
987 * { cmd, set_args, get_args, name }
991 IW_PRIV_TYPE_CHAR | 8,
992 IW_PRIV_TYPE_CHAR | 8,
997 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
998 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1002 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1003 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1007 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1008 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1012 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1013 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1017 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1018 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1022 WLAN_SUBCMD_SET_PRESCAN,
1023 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1024 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1027 WLAN_SETONEINT_GETONEINT,
1028 IW_PRIV_TYPE_INT | 1,
1029 IW_PRIV_TYPE_INT | 1,
1032 WLAN_BEACON_INTERVAL,
1033 IW_PRIV_TYPE_INT | 1,
1034 IW_PRIV_TYPE_INT | 1,
1038 IW_PRIV_TYPE_INT | 1,
1039 IW_PRIV_TYPE_INT | 1,
1043 IW_PRIV_TYPE_INT | 1,
1044 IW_PRIV_TYPE_INT | 1,
1047 WLAN_NULLPKTINTERVAL,
1048 IW_PRIV_TYPE_INT | 1,
1049 IW_PRIV_TYPE_INT | 1,
1051 /* Using iwpriv sub-command feature */
1053 WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */
1054 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1059 WLAN_SUBCMD_SETRXANTENNA,
1060 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1064 WLAN_SUBCMD_SETTXANTENNA,
1065 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1069 WLANSETENCRYPTIONMODE,
1070 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1076 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1080 WLAN_SET_LISTEN_INTERVAL,
1081 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1085 WLAN_SET_MULTIPLE_DTIM,
1086 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1090 WLAN_SET_ATIM_WINDOW,
1091 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1096 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1101 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1106 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1111 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1116 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1120 WLAN_SUBCMD_MESH_SET_TTL,
1121 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1125 WLAN_SETNONE_GETONEINT,
1127 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1132 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1135 WLAN_GET_LISTEN_INTERVAL,
1137 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1140 WLAN_GET_MULTIPLE_DTIM,
1142 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1147 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1152 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1157 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1162 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1167 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1170 WLAN_SUBCMD_FWT_CLEANUP,
1172 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1175 WLAN_SUBCMD_FWT_TIME,
1177 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1180 WLAN_SUBCMD_MESH_GET_TTL,
1182 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1185 WLAN_SETNONE_GETTWELVE_CHAR,
1187 IW_PRIV_TYPE_CHAR | 12,
1190 WLAN_SUBCMD_GETRXANTENNA,
1192 IW_PRIV_TYPE_CHAR | 12,
1195 WLAN_SUBCMD_GETTXANTENNA,
1197 IW_PRIV_TYPE_CHAR | 12,
1202 IW_PRIV_TYPE_CHAR | 12,
1205 WLAN_SETNONE_GETNONE,
1240 WLAN_SUBCMD_FWT_RESET,
1245 WLAN_SUBCMD_BT_RESET,
1250 WLAN_SET128CHAR_GET128CHAR,
1251 IW_PRIV_TYPE_CHAR | 128,
1252 IW_PRIV_TYPE_CHAR | 128,
1257 IW_PRIV_TYPE_CHAR | 128,
1258 IW_PRIV_TYPE_CHAR | 128,
1262 IW_PRIV_TYPE_CHAR | 128,
1263 IW_PRIV_TYPE_CHAR | 128,
1266 WLAN_SUBCMD_BT_LIST,
1267 IW_PRIV_TYPE_CHAR | 128,
1268 IW_PRIV_TYPE_CHAR | 128,
1270 /* FWT Management */
1272 WLAN_SUBCMD_FWT_ADD,
1273 IW_PRIV_TYPE_CHAR | 128,
1274 IW_PRIV_TYPE_CHAR | 128,
1277 WLAN_SUBCMD_FWT_DEL,
1278 IW_PRIV_TYPE_CHAR | 128,
1279 IW_PRIV_TYPE_CHAR | 128,
1282 WLAN_SUBCMD_FWT_LOOKUP,
1283 IW_PRIV_TYPE_CHAR | 128,
1284 IW_PRIV_TYPE_CHAR | 128,
1287 WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
1288 IW_PRIV_TYPE_CHAR | 128,
1289 IW_PRIV_TYPE_CHAR | 128,
1292 WLAN_SUBCMD_FWT_LIST,
1293 IW_PRIV_TYPE_CHAR | 128,
1294 IW_PRIV_TYPE_CHAR | 128,
1297 WLAN_SUBCMD_FWT_LIST_ROUTE,
1298 IW_PRIV_TYPE_CHAR | 128,
1299 IW_PRIV_TYPE_CHAR | 128,
1303 IW_PRIV_TYPE_CHAR | 128,
1304 IW_PRIV_TYPE_CHAR | 128,
1307 WLAN_GET_ADHOC_STATUS,
1308 IW_PRIV_TYPE_CHAR | 128,
1309 IW_PRIV_TYPE_CHAR | 128,
1312 WLAN_SETNONE_GETWORDCHAR,
1314 IW_PRIV_TYPE_CHAR | 128,
1319 IW_PRIV_TYPE_CHAR | GETLOG_BUFSIZE,
1322 WLAN_SET_GET_SIXTEEN_INT,
1323 IW_PRIV_TYPE_INT | 16,
1324 IW_PRIV_TYPE_INT | 16,
1328 IW_PRIV_TYPE_INT | 16,
1329 IW_PRIV_TYPE_INT | 16,
1333 IW_PRIV_TYPE_INT | 16,
1334 IW_PRIV_TYPE_INT | 16,
1338 IW_PRIV_TYPE_INT | 16,
1339 IW_PRIV_TYPE_INT | 16,
1343 IW_PRIV_TYPE_INT | 16,
1344 IW_PRIV_TYPE_INT | 16,
1348 IW_PRIV_TYPE_INT | 16,
1349 IW_PRIV_TYPE_INT | 16,
1353 IW_PRIV_TYPE_INT | 16,
1354 IW_PRIV_TYPE_INT | 16,
1358 IW_PRIV_TYPE_INT | 16,
1359 IW_PRIV_TYPE_INT | 16,
1362 WLAN_INACTIVITY_TIMEOUT,
1363 IW_PRIV_TYPE_INT | 16,
1364 IW_PRIV_TYPE_INT | 16,
1368 IW_PRIV_TYPE_INT | 16,
1369 IW_PRIV_TYPE_INT | 16,
1373 IW_PRIV_TYPE_INT | 16,
1374 IW_PRIV_TYPE_INT | 16,
1378 IW_PRIV_TYPE_INT | 16,
1379 IW_PRIV_TYPE_INT | 16,
1383 static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
1393 wlan_private *priv = dev->priv;
1394 wlan_adapter *adapter = priv->adapter;
1398 int stats_valid = 0;
1404 priv->wstats.status = adapter->mode;
1406 /* If we're not associated, all quality values are meaningless */
1407 if (adapter->connect_status != libertas_connected)
1410 /* Quality by RSSI */
1411 priv->wstats.qual.level =
1412 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
1413 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1415 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1416 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1418 priv->wstats.qual.noise =
1419 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1422 lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
1423 lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
1425 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
1427 rssi_qual = rssi * POOR / 10;
1429 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
1431 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
1433 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
1436 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
1438 quality = rssi_qual;
1440 /* Quality by TX errors */
1441 priv->wstats.discard.retries = priv->stats.tx_errors;
1443 tx_retries = adapter->logmsg.retry;
1445 if (tx_retries > 75)
1446 tx_qual = (90 - tx_retries) * POOR / 15;
1447 else if (tx_retries > 70)
1448 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
1449 else if (tx_retries > 65)
1450 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
1451 else if (tx_retries > 50)
1452 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
1455 tx_qual = (50 - tx_retries) *
1456 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
1457 quality = min(quality, tx_qual);
1459 priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
1460 priv->wstats.discard.fragment = adapter->logmsg.fcserror;
1461 priv->wstats.discard.retries = tx_retries;
1462 priv->wstats.discard.misc = adapter->logmsg.ackfailure;
1464 /* Calculate quality */
1465 priv->wstats.qual.qual = max(quality, (u32)100);
1466 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1469 /* update stats asynchronously for future calls */
1470 libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
1472 libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
1476 priv->wstats.miss.beacon = 0;
1477 priv->wstats.discard.retries = 0;
1478 priv->wstats.qual.qual = 0;
1479 priv->wstats.qual.level = 0;
1480 priv->wstats.qual.noise = 0;
1481 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
1482 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
1483 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
1487 return &priv->wstats;
1492 static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
1493 struct iw_freq *fwrq, char *extra)
1496 wlan_private *priv = dev->priv;
1497 wlan_adapter *adapter = priv->adapter;
1498 int rc = -EINPROGRESS; /* Call commit handler */
1499 struct chan_freq_power *cfp;
1504 * If setting by frequency, convert to a channel
1508 long f = fwrq->m / 100000;
1511 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
1513 lbs_pr_debug(1, "Invalid freq=%ld\n", f);
1517 c = (int)cfp->channel;
1527 * Setting by channel number
1529 if (fwrq->m > 1000 || fwrq->e > 0) {
1532 int channel = fwrq->m;
1534 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel);
1538 if (adapter->mode == IW_MODE_ADHOC) {
1539 rc = changeadhocchannel(priv, channel);
1540 /* If station is WEP enabled, send the
1541 * command to set WEP in firmware
1543 if (adapter->secinfo.wep_enabled) {
1544 lbs_pr_debug(1, "set_freq: WEP enabled\n");
1545 ret = libertas_prepare_and_send_command(priv,
1548 cmd_option_waitforrsp,
1557 adapter->currentpacketfilter |=
1558 cmd_act_mac_wep_enable;
1560 libertas_set_mac_packet_filter(priv);
1573 * @brief use index to get the data rate
1575 * @param index The index of data rate
1576 * @return data rate or 0
1578 u32 libertas_index_to_data_rate(u8 index)
1580 if (index >= sizeof(libertas_wlan_data_rates))
1583 return libertas_wlan_data_rates[index];
1587 * @brief use rate to get the index
1589 * @param rate data rate
1590 * @return index or 0
1592 u8 libertas_data_rate_to_index(u32 rate)
1597 if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
1598 sizeof(libertas_wlan_data_rates))))
1599 return (ptr - libertas_wlan_data_rates);
1604 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
1605 struct iw_param *vwrq, char *extra)
1607 wlan_private *priv = dev->priv;
1608 wlan_adapter *adapter = priv->adapter;
1612 u8 rates[WLAN_SUPPORTED_RATES];
1617 lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
1619 if (vwrq->value == -1) {
1620 action = cmd_act_set_tx_auto; // Auto
1621 adapter->is_datarate_auto = 1;
1622 adapter->datarate = 0;
1624 if (vwrq->value % 100000) {
1628 data_rate = vwrq->value / 500000;
1630 memset(rates, 0, sizeof(rates));
1631 get_active_data_rates(adapter, rates);
1634 lbs_pr_debug(1, "Rate=0x%X Wanted=0x%X\n", *rate,
1636 if ((*rate & 0x7f) == (data_rate & 0x7f))
1641 lbs_pr_alert( "The fixed data rate 0x%X is out "
1642 "of range.\n", data_rate);
1646 adapter->datarate = data_rate;
1647 action = cmd_act_set_tx_fix_rate;
1648 adapter->is_datarate_auto = 0;
1651 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
1652 action, cmd_option_waitforrsp, 0, NULL);
1658 static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1659 struct iw_param *vwrq, char *extra)
1661 wlan_private *priv = dev->priv;
1662 wlan_adapter *adapter = priv->adapter;
1666 if (adapter->is_datarate_auto) {
1672 vwrq->value = adapter->datarate * 500000;
1678 static int wlan_set_mode(struct net_device *dev,
1679 struct iw_request_info *info, u32 * uwrq, char *extra)
1682 wlan_private *priv = dev->priv;
1683 wlan_adapter *adapter = priv->adapter;
1684 struct assoc_request * assoc_req;
1688 if ( (*uwrq != IW_MODE_ADHOC)
1689 && (*uwrq != IW_MODE_INFRA)
1690 && (*uwrq != IW_MODE_AUTO)) {
1691 lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq);
1696 mutex_lock(&adapter->lock);
1697 assoc_req = wlan_get_association_request(adapter);
1700 wlan_cancel_association_work(priv);
1702 assoc_req->mode = *uwrq;
1703 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1704 wlan_postpone_association_work(priv);
1705 lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq);
1707 mutex_unlock(&adapter->lock);
1716 * @brief Get Encryption key
1718 * @param dev A pointer to net_device structure
1719 * @param info A pointer to iw_request_info structure
1720 * @param vwrq A pointer to iw_param structure
1721 * @param extra A pointer to extra data buf
1722 * @return 0 --success, otherwise fail
1724 static int wlan_get_encode(struct net_device *dev,
1725 struct iw_request_info *info,
1726 struct iw_point *dwrq, u8 * extra)
1728 wlan_private *priv = dev->priv;
1729 wlan_adapter *adapter = priv->adapter;
1730 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1734 lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
1735 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1739 /* Authentication method */
1740 switch (adapter->secinfo.auth_mode) {
1741 case IW_AUTH_ALG_OPEN_SYSTEM:
1742 dwrq->flags = IW_ENCODE_OPEN;
1745 case IW_AUTH_ALG_SHARED_KEY:
1746 case IW_AUTH_ALG_LEAP:
1747 dwrq->flags = IW_ENCODE_RESTRICTED;
1750 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1754 if ( adapter->secinfo.wep_enabled
1755 || adapter->secinfo.WPAenabled
1756 || adapter->secinfo.WPA2enabled) {
1757 dwrq->flags &= ~IW_ENCODE_DISABLED;
1759 dwrq->flags |= IW_ENCODE_DISABLED;
1762 memset(extra, 0, 16);
1764 mutex_lock(&adapter->lock);
1766 /* Default to returning current transmit key */
1768 index = adapter->wep_tx_keyidx;
1770 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
1771 memcpy(extra, adapter->wep_keys[index].key,
1772 adapter->wep_keys[index].len);
1773 dwrq->length = adapter->wep_keys[index].len;
1775 dwrq->flags |= (index + 1);
1776 /* Return WEP enabled */
1777 dwrq->flags &= ~IW_ENCODE_DISABLED;
1778 } else if ((adapter->secinfo.WPAenabled)
1779 || (adapter->secinfo.WPA2enabled)) {
1780 /* return WPA enabled */
1781 dwrq->flags &= ~IW_ENCODE_DISABLED;
1783 dwrq->flags |= IW_ENCODE_DISABLED;
1786 mutex_unlock(&adapter->lock);
1788 dwrq->flags |= IW_ENCODE_NOKEY;
1790 lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
1791 extra[0], extra[1], extra[2],
1792 extra[3], extra[4], extra[5], dwrq->length);
1794 lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
1801 * @brief Set Encryption key (internal)
1803 * @param priv A pointer to private card structure
1804 * @param key_material A pointer to key material
1805 * @param key_length length of key material
1806 * @param index key index to set
1807 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1808 * @return 0 --success, otherwise fail
1810 static int wlan_set_wep_key(struct assoc_request *assoc_req,
1811 const char *key_material,
1816 struct WLAN_802_11_KEY *pkey;
1820 /* Paranoid validation of key index */
1826 /* validate max key length */
1827 if (key_length > KEY_LEN_WEP_104) {
1832 pkey = &assoc_req->wep_keys[index];
1834 if (key_length > 0) {
1835 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
1836 pkey->type = KEY_TYPE_ID_WEP;
1838 /* Standardize the key length */
1839 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1840 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1841 memcpy(pkey->key, key_material, key_length);
1845 /* Ensure the chosen key is valid */
1847 lbs_pr_debug(1, "key not set, so cannot enable it\n");
1851 assoc_req->wep_tx_keyidx = index;
1854 assoc_req->secinfo.wep_enabled = 1;
1860 static int validate_key_index(u16 def_index, u16 raw_index,
1861 u16 *out_index, u16 *is_default)
1863 if (!out_index || !is_default)
1866 /* Verify index if present, otherwise use default TX key index */
1867 if (raw_index > 0) {
1870 *out_index = raw_index - 1;
1872 *out_index = def_index;
1878 static void disable_wep(struct assoc_request *assoc_req)
1882 /* Set Open System auth mode */
1883 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1885 /* Clear WEP keys and mark WEP as disabled */
1886 assoc_req->secinfo.wep_enabled = 0;
1887 for (i = 0; i < 4; i++)
1888 assoc_req->wep_keys[i].len = 0;
1890 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1891 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1895 * @brief Set Encryption key
1897 * @param dev A pointer to net_device structure
1898 * @param info A pointer to iw_request_info structure
1899 * @param vwrq A pointer to iw_param structure
1900 * @param extra A pointer to extra data buf
1901 * @return 0 --success, otherwise fail
1903 static int wlan_set_encode(struct net_device *dev,
1904 struct iw_request_info *info,
1905 struct iw_point *dwrq, char *extra)
1908 wlan_private *priv = dev->priv;
1909 wlan_adapter *adapter = priv->adapter;
1910 struct assoc_request * assoc_req;
1911 u16 is_default = 0, index = 0, set_tx_key = 0;
1915 mutex_lock(&adapter->lock);
1916 assoc_req = wlan_get_association_request(adapter);
1922 if (dwrq->flags & IW_ENCODE_DISABLED) {
1923 disable_wep (assoc_req);
1927 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1928 (dwrq->flags & IW_ENCODE_INDEX),
1929 &index, &is_default);
1935 /* If WEP isn't enabled, or if there is no key data but a valid
1936 * index, set the TX key.
1938 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1941 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1946 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1948 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1950 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1951 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1952 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1953 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1958 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1959 wlan_postpone_association_work(priv);
1961 wlan_cancel_association_work(priv);
1963 mutex_unlock(&adapter->lock);
1970 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1972 * @param dev A pointer to net_device structure
1973 * @param info A pointer to iw_request_info structure
1974 * @param vwrq A pointer to iw_param structure
1975 * @param extra A pointer to extra data buf
1976 * @return 0 on success, otherwise failure
1978 static int wlan_get_encodeext(struct net_device *dev,
1979 struct iw_request_info *info,
1980 struct iw_point *dwrq,
1984 wlan_private *priv = dev->priv;
1985 wlan_adapter *adapter = priv->adapter;
1986 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1987 int index, max_key_len;
1991 max_key_len = dwrq->length - sizeof(*ext);
1992 if (max_key_len < 0)
1995 index = dwrq->flags & IW_ENCODE_INDEX;
1997 if (index < 1 || index > 4)
2001 index = adapter->wep_tx_keyidx;
2004 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
2005 ext->alg != IW_ENCODE_ALG_WEP) {
2006 if (index != 0 || adapter->mode != IW_MODE_INFRA)
2010 dwrq->flags = index + 1;
2011 memset(ext, 0, sizeof(*ext));
2013 if ( !adapter->secinfo.wep_enabled
2014 && !adapter->secinfo.WPAenabled
2015 && !adapter->secinfo.WPA2enabled) {
2016 ext->alg = IW_ENCODE_ALG_NONE;
2018 dwrq->flags |= IW_ENCODE_DISABLED;
2022 if ( adapter->secinfo.wep_enabled
2023 && !adapter->secinfo.WPAenabled
2024 && !adapter->secinfo.WPA2enabled) {
2025 ext->alg = IW_ENCODE_ALG_WEP;
2026 ext->key_len = adapter->wep_keys[index].len;
2027 key = &adapter->wep_keys[index].key[0];
2028 } else if ( !adapter->secinfo.wep_enabled
2029 && (adapter->secinfo.WPAenabled ||
2030 adapter->secinfo.WPA2enabled)) {
2032 ext->alg = IW_ENCODE_ALG_TKIP;
2038 if (ext->key_len > max_key_len) {
2044 memcpy(ext->key, key, ext->key_len);
2046 dwrq->flags |= IW_ENCODE_NOKEY;
2047 dwrq->flags |= IW_ENCODE_ENABLED;
2057 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
2059 * @param dev A pointer to net_device structure
2060 * @param info A pointer to iw_request_info structure
2061 * @param vwrq A pointer to iw_param structure
2062 * @param extra A pointer to extra data buf
2063 * @return 0 --success, otherwise fail
2065 static int wlan_set_encodeext(struct net_device *dev,
2066 struct iw_request_info *info,
2067 struct iw_point *dwrq,
2071 wlan_private *priv = dev->priv;
2072 wlan_adapter *adapter = priv->adapter;
2073 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
2075 struct assoc_request * assoc_req;
2079 mutex_lock(&adapter->lock);
2080 assoc_req = wlan_get_association_request(adapter);
2086 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
2087 disable_wep (assoc_req);
2088 } else if (alg == IW_ENCODE_ALG_WEP) {
2089 u16 is_default = 0, index, set_tx_key = 0;
2091 ret = validate_key_index(assoc_req->wep_tx_keyidx,
2092 (dwrq->flags & IW_ENCODE_INDEX),
2093 &index, &is_default);
2097 /* If WEP isn't enabled, or if there is no key data but a valid
2098 * index, or if the set-TX-key flag was passed, set the TX key.
2100 if ( !assoc_req->secinfo.wep_enabled
2101 || (dwrq->length == 0 && !is_default)
2102 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
2105 /* Copy key to driver */
2106 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
2111 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
2112 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2113 } else if (dwrq->flags & IW_ENCODE_OPEN) {
2114 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2117 /* Mark the various WEP bits as modified */
2118 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2120 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
2122 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
2124 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
2125 struct WLAN_802_11_KEY * pkey;
2127 /* validate key length */
2128 if (((alg == IW_ENCODE_ALG_TKIP)
2129 && (ext->key_len != KEY_LEN_WPA_TKIP))
2130 || ((alg == IW_ENCODE_ALG_CCMP)
2131 && (ext->key_len != KEY_LEN_WPA_AES))) {
2132 lbs_pr_debug(1, "Invalid size %d for key of alg"
2140 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
2141 pkey = &assoc_req->wpa_mcast_key;
2143 pkey = &assoc_req->wpa_unicast_key;
2145 memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
2146 memcpy(pkey->key, ext->key, ext->key_len);
2147 pkey->len = ext->key_len;
2148 pkey->flags = KEY_INFO_WPA_ENABLED;
2150 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
2151 pkey->flags |= KEY_INFO_WPA_MCAST;
2152 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
2154 pkey->flags |= KEY_INFO_WPA_UNICAST;
2155 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
2158 if (alg == IW_ENCODE_ALG_TKIP)
2159 pkey->type = KEY_TYPE_ID_TKIP;
2160 else if (alg == IW_ENCODE_ALG_CCMP)
2161 pkey->type = KEY_TYPE_ID_AES;
2163 /* If WPA isn't enabled yet, do that now */
2164 if ( assoc_req->secinfo.WPAenabled == 0
2165 && assoc_req->secinfo.WPA2enabled == 0) {
2166 assoc_req->secinfo.WPAenabled = 1;
2167 assoc_req->secinfo.WPA2enabled = 1;
2168 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2171 disable_wep (assoc_req);
2176 wlan_postpone_association_work(priv);
2178 wlan_cancel_association_work(priv);
2180 mutex_unlock(&adapter->lock);
2187 static int wlan_set_genie(struct net_device *dev,
2188 struct iw_request_info *info,
2189 struct iw_point *dwrq,
2192 wlan_private *priv = dev->priv;
2193 wlan_adapter *adapter = priv->adapter;
2195 struct assoc_request * assoc_req;
2199 mutex_lock(&adapter->lock);
2200 assoc_req = wlan_get_association_request(adapter);
2206 if (dwrq->length > MAX_WPA_IE_LEN ||
2207 (dwrq->length && extra == NULL)) {
2213 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
2214 assoc_req->wpa_ie_len = dwrq->length;
2216 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
2217 assoc_req->wpa_ie_len = 0;
2222 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
2223 wlan_postpone_association_work(priv);
2225 wlan_cancel_association_work(priv);
2227 mutex_unlock(&adapter->lock);
2233 static int wlan_get_genie(struct net_device *dev,
2234 struct iw_request_info *info,
2235 struct iw_point *dwrq,
2238 wlan_private *priv = dev->priv;
2239 wlan_adapter *adapter = priv->adapter;
2243 if (adapter->wpa_ie_len == 0) {
2249 if (dwrq->length < adapter->wpa_ie_len) {
2254 dwrq->length = adapter->wpa_ie_len;
2255 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
2262 static int wlan_set_auth(struct net_device *dev,
2263 struct iw_request_info *info,
2264 struct iw_param *dwrq,
2267 wlan_private *priv = dev->priv;
2268 wlan_adapter *adapter = priv->adapter;
2269 struct assoc_request * assoc_req;
2275 mutex_lock(&adapter->lock);
2276 assoc_req = wlan_get_association_request(adapter);
2282 switch (dwrq->flags & IW_AUTH_INDEX) {
2283 case IW_AUTH_TKIP_COUNTERMEASURES:
2284 case IW_AUTH_CIPHER_PAIRWISE:
2285 case IW_AUTH_CIPHER_GROUP:
2286 case IW_AUTH_KEY_MGMT:
2288 * libertas does not use these parameters
2292 case IW_AUTH_WPA_VERSION:
2293 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
2294 assoc_req->secinfo.WPAenabled = 0;
2295 assoc_req->secinfo.WPA2enabled = 0;
2297 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
2298 assoc_req->secinfo.WPAenabled = 1;
2299 assoc_req->secinfo.wep_enabled = 0;
2300 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2302 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
2303 assoc_req->secinfo.WPA2enabled = 1;
2304 assoc_req->secinfo.wep_enabled = 0;
2305 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2310 case IW_AUTH_DROP_UNENCRYPTED:
2312 adapter->currentpacketfilter |=
2313 cmd_act_mac_strict_protection_enable;
2315 adapter->currentpacketfilter &=
2316 ~cmd_act_mac_strict_protection_enable;
2321 case IW_AUTH_80211_AUTH_ALG:
2322 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
2323 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2324 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
2325 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2326 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
2327 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
2334 case IW_AUTH_WPA_ENABLED:
2336 if (!assoc_req->secinfo.WPAenabled &&
2337 !assoc_req->secinfo.WPA2enabled) {
2338 assoc_req->secinfo.WPAenabled = 1;
2339 assoc_req->secinfo.WPA2enabled = 1;
2340 assoc_req->secinfo.wep_enabled = 0;
2341 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2344 assoc_req->secinfo.WPAenabled = 0;
2345 assoc_req->secinfo.WPA2enabled = 0;
2358 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2359 wlan_postpone_association_work(priv);
2360 } else if (ret != -EOPNOTSUPP) {
2361 wlan_cancel_association_work(priv);
2363 mutex_unlock(&adapter->lock);
2369 static int wlan_get_auth(struct net_device *dev,
2370 struct iw_request_info *info,
2371 struct iw_param *dwrq,
2374 wlan_private *priv = dev->priv;
2375 wlan_adapter *adapter = priv->adapter;
2379 switch (dwrq->flags & IW_AUTH_INDEX) {
2380 case IW_AUTH_WPA_VERSION:
2382 if (adapter->secinfo.WPAenabled)
2383 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
2384 if (adapter->secinfo.WPA2enabled)
2385 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
2387 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
2390 case IW_AUTH_DROP_UNENCRYPTED:
2392 if (adapter->currentpacketfilter &
2393 cmd_act_mac_strict_protection_enable)
2397 case IW_AUTH_80211_AUTH_ALG:
2398 dwrq->value = adapter->secinfo.auth_mode;
2401 case IW_AUTH_WPA_ENABLED:
2402 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
2416 static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
2417 struct iw_param *vwrq, char *extra)
2420 wlan_private *priv = dev->priv;
2421 wlan_adapter *adapter = priv->adapter;
2427 if (vwrq->disabled) {
2428 wlan_radio_ioctl(priv, RADIO_OFF);
2432 adapter->preamble = cmd_type_auto_preamble;
2434 wlan_radio_ioctl(priv, RADIO_ON);
2436 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
2437 dbm = (u16) mw_to_dbm(vwrq->value);
2439 dbm = (u16) vwrq->value;
2441 /* auto tx power control */
2443 if (vwrq->fixed == 0)
2446 lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
2448 ret = libertas_prepare_and_send_command(priv,
2449 cmd_802_11_rf_tx_power,
2450 cmd_act_tx_power_opt_set_low,
2451 cmd_option_waitforrsp, 0, (void *)&dbm);
2457 static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
2458 struct iw_point *dwrq, char *extra)
2460 wlan_private *priv = dev->priv;
2461 wlan_adapter *adapter = priv->adapter;
2465 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2470 * Get the current SSID
2472 if (adapter->connect_status == libertas_connected) {
2473 memcpy(extra, adapter->curbssparams.ssid.ssid,
2474 adapter->curbssparams.ssid.ssidlength);
2475 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2477 memset(extra, 0, 32);
2478 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2481 * If none, we may want to get the one that was set
2484 /* To make the driver backward compatible with WPA supplicant v0.2.4 */
2485 if (dwrq->length == 32) /* check with WPA supplicant buffer size */
2486 dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
2489 dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
2491 dwrq->flags = 1; /* active */
2497 static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
2498 struct iw_point *dwrq, char *extra)
2500 wlan_private *priv = dev->priv;
2501 wlan_adapter *adapter = priv->adapter;
2503 struct WLAN_802_11_SSID ssid;
2504 struct assoc_request * assoc_req;
2505 int ssid_len = dwrq->length;
2510 * WE-20 and earlier NULL pad the end of the SSID and increment
2511 * SSID length so it can be used like a string. WE-21 and later don't,
2512 * but some userspace tools aren't able to cope with the change.
2514 if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
2517 /* Check the size of the string */
2518 if (ssid_len > IW_ESSID_MAX_SIZE) {
2523 memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
2525 if (!dwrq->flags || !ssid_len) {
2526 /* "any" SSID requested; leave SSID blank */
2528 /* Specific SSID requested */
2529 memcpy(&ssid.ssid, extra, ssid_len);
2530 ssid.ssidlength = ssid_len;
2533 lbs_pr_debug(1, "Requested new SSID = %s\n",
2534 (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
2537 mutex_lock(&adapter->lock);
2539 /* Get or create the current association request */
2540 assoc_req = wlan_get_association_request(adapter);
2544 /* Copy the SSID to the association request */
2545 memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
2546 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2547 wlan_postpone_association_work(priv);
2551 /* Cancel the association request if there was an error */
2553 wlan_cancel_association_work(priv);
2556 mutex_unlock(&adapter->lock);
2563 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2565 * @param dev A pointer to net_device structure
2566 * @param info A pointer to iw_request_info structure
2567 * @param awrq A pointer to iw_param structure
2568 * @param extra A pointer to extra data buf
2569 * @return 0 --success, otherwise fail
2571 static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
2572 struct sockaddr *awrq, char *extra)
2574 wlan_private *priv = dev->priv;
2575 wlan_adapter *adapter = priv->adapter;
2576 struct assoc_request * assoc_req;
2581 if (awrq->sa_family != ARPHRD_ETHER)
2584 lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
2586 mutex_lock(&adapter->lock);
2588 /* Get or create the current association request */
2589 assoc_req = wlan_get_association_request(adapter);
2591 wlan_cancel_association_work(priv);
2594 /* Copy the BSSID to the association request */
2595 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2596 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2597 wlan_postpone_association_work(priv);
2600 mutex_unlock(&adapter->lock);
2605 void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2613 mutex_lock(&adapter->lock);
2614 ver.l = adapter->fwreleasenumber;
2615 mutex_unlock(&adapter->lock);
2618 sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
2620 sprintf(fwver, "%u.%u.%u.p%u",
2621 ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
2623 snprintf(fwversion, maxlen, fwver);
2628 * iwconfig settable callbacks
2630 static const iw_handler wlan_handler[] = {
2631 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2632 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2633 (iw_handler) NULL, /* SIOCSIWNWID */
2634 (iw_handler) NULL, /* SIOCGIWNWID */
2635 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2636 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2637 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2638 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2639 (iw_handler) NULL, /* SIOCSIWSENS */
2640 (iw_handler) NULL, /* SIOCGIWSENS */
2641 (iw_handler) NULL, /* SIOCSIWRANGE */
2642 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2643 (iw_handler) NULL, /* SIOCSIWPRIV */
2644 (iw_handler) NULL, /* SIOCGIWPRIV */
2645 (iw_handler) NULL, /* SIOCSIWSTATS */
2646 (iw_handler) NULL, /* SIOCGIWSTATS */
2647 iw_handler_set_spy, /* SIOCSIWSPY */
2648 iw_handler_get_spy, /* SIOCGIWSPY */
2649 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2650 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2651 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2652 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2653 (iw_handler) NULL, /* SIOCSIWMLME */
2654 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2655 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2656 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2657 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2658 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2659 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2660 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2661 (iw_handler) NULL, /* -- hole -- */
2662 (iw_handler) NULL, /* -- hole -- */
2663 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2664 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2665 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2666 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2667 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2668 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2669 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2670 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2671 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2672 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2673 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2674 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2675 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2676 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2677 (iw_handler) NULL, /* -- hole -- */
2678 (iw_handler) NULL, /* -- hole -- */
2679 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2680 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2681 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2682 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2683 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2684 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2685 (iw_handler) NULL, /* SIOCSIWPMKSA */
2688 struct iw_handler_def libertas_handler_def = {
2689 .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
2690 .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
2691 .num_private_args = sizeof(wlan_private_args) /
2692 sizeof(struct iw_priv_args),
2693 .standard = (iw_handler *) wlan_handler,
2694 .private = (iw_handler *) wlan_private_handler,
2695 .private_args = (struct iw_priv_args *)wlan_private_args,
2696 .get_wireless_stats = wlan_get_wireless_stats,