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 }
989 /* Using iwpriv sub-command feature */
991 WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */
992 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
997 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1001 WLAN_SUBCMD_MESH_SET_TTL,
1002 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1006 WLAN_SETNONE_GETONEINT,
1008 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1013 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1016 WLAN_SUBCMD_FWT_CLEANUP,
1018 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1021 WLAN_SUBCMD_FWT_TIME,
1023 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1026 WLAN_SUBCMD_MESH_GET_TTL,
1028 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
1031 WLAN_SETNONE_GETNONE,
1036 WLAN_SUBCMD_FWT_RESET,
1041 WLAN_SUBCMD_BT_RESET,
1046 WLAN_SET128CHAR_GET128CHAR,
1047 IW_PRIV_TYPE_CHAR | 128,
1048 IW_PRIV_TYPE_CHAR | 128,
1053 IW_PRIV_TYPE_CHAR | 128,
1054 IW_PRIV_TYPE_CHAR | 128,
1058 IW_PRIV_TYPE_CHAR | 128,
1059 IW_PRIV_TYPE_CHAR | 128,
1062 WLAN_SUBCMD_BT_LIST,
1063 IW_PRIV_TYPE_CHAR | 128,
1064 IW_PRIV_TYPE_CHAR | 128,
1066 /* FWT Management */
1068 WLAN_SUBCMD_FWT_ADD,
1069 IW_PRIV_TYPE_CHAR | 128,
1070 IW_PRIV_TYPE_CHAR | 128,
1073 WLAN_SUBCMD_FWT_DEL,
1074 IW_PRIV_TYPE_CHAR | 128,
1075 IW_PRIV_TYPE_CHAR | 128,
1078 WLAN_SUBCMD_FWT_LOOKUP,
1079 IW_PRIV_TYPE_CHAR | 128,
1080 IW_PRIV_TYPE_CHAR | 128,
1083 WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
1084 IW_PRIV_TYPE_CHAR | 128,
1085 IW_PRIV_TYPE_CHAR | 128,
1088 WLAN_SUBCMD_FWT_LIST,
1089 IW_PRIV_TYPE_CHAR | 128,
1090 IW_PRIV_TYPE_CHAR | 128,
1093 WLAN_SUBCMD_FWT_LIST_ROUTE,
1094 IW_PRIV_TYPE_CHAR | 128,
1095 IW_PRIV_TYPE_CHAR | 128,
1098 WLAN_SET_GET_SIXTEEN_INT,
1099 IW_PRIV_TYPE_INT | 16,
1100 IW_PRIV_TYPE_INT | 16,
1104 IW_PRIV_TYPE_INT | 16,
1105 IW_PRIV_TYPE_INT | 16,
1109 static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
1119 wlan_private *priv = dev->priv;
1120 wlan_adapter *adapter = priv->adapter;
1124 int stats_valid = 0;
1130 priv->wstats.status = adapter->mode;
1132 /* If we're not associated, all quality values are meaningless */
1133 if (adapter->connect_status != libertas_connected)
1136 /* Quality by RSSI */
1137 priv->wstats.qual.level =
1138 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
1139 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1141 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1142 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1144 priv->wstats.qual.noise =
1145 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1148 lbs_pr_debug(1, "Signal Level = %#x\n", priv->wstats.qual.level);
1149 lbs_pr_debug(1, "Noise = %#x\n", priv->wstats.qual.noise);
1151 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
1153 rssi_qual = rssi * POOR / 10;
1155 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
1157 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
1159 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
1162 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
1164 quality = rssi_qual;
1166 /* Quality by TX errors */
1167 priv->wstats.discard.retries = priv->stats.tx_errors;
1169 tx_retries = adapter->logmsg.retry;
1171 if (tx_retries > 75)
1172 tx_qual = (90 - tx_retries) * POOR / 15;
1173 else if (tx_retries > 70)
1174 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
1175 else if (tx_retries > 65)
1176 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
1177 else if (tx_retries > 50)
1178 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
1181 tx_qual = (50 - tx_retries) *
1182 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
1183 quality = min(quality, tx_qual);
1185 priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
1186 priv->wstats.discard.fragment = adapter->logmsg.fcserror;
1187 priv->wstats.discard.retries = tx_retries;
1188 priv->wstats.discard.misc = adapter->logmsg.ackfailure;
1190 /* Calculate quality */
1191 priv->wstats.qual.qual = max(quality, (u32)100);
1192 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1195 /* update stats asynchronously for future calls */
1196 libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
1198 libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
1202 priv->wstats.miss.beacon = 0;
1203 priv->wstats.discard.retries = 0;
1204 priv->wstats.qual.qual = 0;
1205 priv->wstats.qual.level = 0;
1206 priv->wstats.qual.noise = 0;
1207 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
1208 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
1209 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
1213 return &priv->wstats;
1218 static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
1219 struct iw_freq *fwrq, char *extra)
1222 wlan_private *priv = dev->priv;
1223 wlan_adapter *adapter = priv->adapter;
1224 int rc = -EINPROGRESS; /* Call commit handler */
1225 struct chan_freq_power *cfp;
1230 * If setting by frequency, convert to a channel
1234 long f = fwrq->m / 100000;
1237 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
1239 lbs_pr_debug(1, "Invalid freq=%ld\n", f);
1243 c = (int)cfp->channel;
1253 * Setting by channel number
1255 if (fwrq->m > 1000 || fwrq->e > 0) {
1258 int channel = fwrq->m;
1260 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, channel);
1264 if (adapter->mode == IW_MODE_ADHOC) {
1265 rc = changeadhocchannel(priv, channel);
1266 /* If station is WEP enabled, send the
1267 * command to set WEP in firmware
1269 if (adapter->secinfo.wep_enabled) {
1270 lbs_pr_debug(1, "set_freq: WEP enabled\n");
1271 ret = libertas_prepare_and_send_command(priv,
1274 cmd_option_waitforrsp,
1283 adapter->currentpacketfilter |=
1284 cmd_act_mac_wep_enable;
1286 libertas_set_mac_packet_filter(priv);
1299 * @brief use index to get the data rate
1301 * @param index The index of data rate
1302 * @return data rate or 0
1304 u32 libertas_index_to_data_rate(u8 index)
1306 if (index >= sizeof(libertas_wlan_data_rates))
1309 return libertas_wlan_data_rates[index];
1313 * @brief use rate to get the index
1315 * @param rate data rate
1316 * @return index or 0
1318 u8 libertas_data_rate_to_index(u32 rate)
1323 if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
1324 sizeof(libertas_wlan_data_rates))))
1325 return (ptr - libertas_wlan_data_rates);
1330 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
1331 struct iw_param *vwrq, char *extra)
1333 wlan_private *priv = dev->priv;
1334 wlan_adapter *adapter = priv->adapter;
1338 u8 rates[WLAN_SUPPORTED_RATES];
1343 lbs_pr_debug(1, "Vwrq->value = %d\n", vwrq->value);
1345 if (vwrq->value == -1) {
1346 action = cmd_act_set_tx_auto; // Auto
1347 adapter->is_datarate_auto = 1;
1348 adapter->datarate = 0;
1350 if (vwrq->value % 100000) {
1354 data_rate = vwrq->value / 500000;
1356 memset(rates, 0, sizeof(rates));
1357 get_active_data_rates(adapter, rates);
1360 lbs_pr_debug(1, "Rate=0x%X Wanted=0x%X\n", *rate,
1362 if ((*rate & 0x7f) == (data_rate & 0x7f))
1367 lbs_pr_alert( "The fixed data rate 0x%X is out "
1368 "of range.\n", data_rate);
1372 adapter->datarate = data_rate;
1373 action = cmd_act_set_tx_fix_rate;
1374 adapter->is_datarate_auto = 0;
1377 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
1378 action, cmd_option_waitforrsp, 0, NULL);
1384 static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1385 struct iw_param *vwrq, char *extra)
1387 wlan_private *priv = dev->priv;
1388 wlan_adapter *adapter = priv->adapter;
1392 if (adapter->is_datarate_auto) {
1398 vwrq->value = adapter->datarate * 500000;
1404 static int wlan_set_mode(struct net_device *dev,
1405 struct iw_request_info *info, u32 * uwrq, char *extra)
1408 wlan_private *priv = dev->priv;
1409 wlan_adapter *adapter = priv->adapter;
1410 struct assoc_request * assoc_req;
1414 if ( (*uwrq != IW_MODE_ADHOC)
1415 && (*uwrq != IW_MODE_INFRA)
1416 && (*uwrq != IW_MODE_AUTO)) {
1417 lbs_pr_debug(1, "Invalid mode: 0x%x\n", *uwrq);
1422 mutex_lock(&adapter->lock);
1423 assoc_req = wlan_get_association_request(adapter);
1426 wlan_cancel_association_work(priv);
1428 assoc_req->mode = *uwrq;
1429 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1430 wlan_postpone_association_work(priv);
1431 lbs_pr_debug(1, "Switching to mode: 0x%x\n", *uwrq);
1433 mutex_unlock(&adapter->lock);
1442 * @brief Get Encryption key
1444 * @param dev A pointer to net_device structure
1445 * @param info A pointer to iw_request_info structure
1446 * @param vwrq A pointer to iw_param structure
1447 * @param extra A pointer to extra data buf
1448 * @return 0 --success, otherwise fail
1450 static int wlan_get_encode(struct net_device *dev,
1451 struct iw_request_info *info,
1452 struct iw_point *dwrq, u8 * extra)
1454 wlan_private *priv = dev->priv;
1455 wlan_adapter *adapter = priv->adapter;
1456 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1460 lbs_pr_debug(1, "flags=0x%x index=%d length=%d wep_tx_keyidx=%d\n",
1461 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1465 /* Authentication method */
1466 switch (adapter->secinfo.auth_mode) {
1467 case IW_AUTH_ALG_OPEN_SYSTEM:
1468 dwrq->flags = IW_ENCODE_OPEN;
1471 case IW_AUTH_ALG_SHARED_KEY:
1472 case IW_AUTH_ALG_LEAP:
1473 dwrq->flags = IW_ENCODE_RESTRICTED;
1476 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1480 if ( adapter->secinfo.wep_enabled
1481 || adapter->secinfo.WPAenabled
1482 || adapter->secinfo.WPA2enabled) {
1483 dwrq->flags &= ~IW_ENCODE_DISABLED;
1485 dwrq->flags |= IW_ENCODE_DISABLED;
1488 memset(extra, 0, 16);
1490 mutex_lock(&adapter->lock);
1492 /* Default to returning current transmit key */
1494 index = adapter->wep_tx_keyidx;
1496 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
1497 memcpy(extra, adapter->wep_keys[index].key,
1498 adapter->wep_keys[index].len);
1499 dwrq->length = adapter->wep_keys[index].len;
1501 dwrq->flags |= (index + 1);
1502 /* Return WEP enabled */
1503 dwrq->flags &= ~IW_ENCODE_DISABLED;
1504 } else if ((adapter->secinfo.WPAenabled)
1505 || (adapter->secinfo.WPA2enabled)) {
1506 /* return WPA enabled */
1507 dwrq->flags &= ~IW_ENCODE_DISABLED;
1509 dwrq->flags |= IW_ENCODE_DISABLED;
1512 mutex_unlock(&adapter->lock);
1514 dwrq->flags |= IW_ENCODE_NOKEY;
1516 lbs_pr_debug(1, "key:%02x:%02x:%02x:%02x:%02x:%02x keylen=%d\n",
1517 extra[0], extra[1], extra[2],
1518 extra[3], extra[4], extra[5], dwrq->length);
1520 lbs_pr_debug(1, "Return flags=0x%x\n", dwrq->flags);
1527 * @brief Set Encryption key (internal)
1529 * @param priv A pointer to private card structure
1530 * @param key_material A pointer to key material
1531 * @param key_length length of key material
1532 * @param index key index to set
1533 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1534 * @return 0 --success, otherwise fail
1536 static int wlan_set_wep_key(struct assoc_request *assoc_req,
1537 const char *key_material,
1542 struct WLAN_802_11_KEY *pkey;
1546 /* Paranoid validation of key index */
1552 /* validate max key length */
1553 if (key_length > KEY_LEN_WEP_104) {
1558 pkey = &assoc_req->wep_keys[index];
1560 if (key_length > 0) {
1561 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
1562 pkey->type = KEY_TYPE_ID_WEP;
1564 /* Standardize the key length */
1565 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1566 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1567 memcpy(pkey->key, key_material, key_length);
1571 /* Ensure the chosen key is valid */
1573 lbs_pr_debug(1, "key not set, so cannot enable it\n");
1577 assoc_req->wep_tx_keyidx = index;
1580 assoc_req->secinfo.wep_enabled = 1;
1586 static int validate_key_index(u16 def_index, u16 raw_index,
1587 u16 *out_index, u16 *is_default)
1589 if (!out_index || !is_default)
1592 /* Verify index if present, otherwise use default TX key index */
1593 if (raw_index > 0) {
1596 *out_index = raw_index - 1;
1598 *out_index = def_index;
1604 static void disable_wep(struct assoc_request *assoc_req)
1608 /* Set Open System auth mode */
1609 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1611 /* Clear WEP keys and mark WEP as disabled */
1612 assoc_req->secinfo.wep_enabled = 0;
1613 for (i = 0; i < 4; i++)
1614 assoc_req->wep_keys[i].len = 0;
1616 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1617 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1621 * @brief Set Encryption key
1623 * @param dev A pointer to net_device structure
1624 * @param info A pointer to iw_request_info structure
1625 * @param vwrq A pointer to iw_param structure
1626 * @param extra A pointer to extra data buf
1627 * @return 0 --success, otherwise fail
1629 static int wlan_set_encode(struct net_device *dev,
1630 struct iw_request_info *info,
1631 struct iw_point *dwrq, char *extra)
1634 wlan_private *priv = dev->priv;
1635 wlan_adapter *adapter = priv->adapter;
1636 struct assoc_request * assoc_req;
1637 u16 is_default = 0, index = 0, set_tx_key = 0;
1641 mutex_lock(&adapter->lock);
1642 assoc_req = wlan_get_association_request(adapter);
1648 if (dwrq->flags & IW_ENCODE_DISABLED) {
1649 disable_wep (assoc_req);
1653 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1654 (dwrq->flags & IW_ENCODE_INDEX),
1655 &index, &is_default);
1661 /* If WEP isn't enabled, or if there is no key data but a valid
1662 * index, set the TX key.
1664 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1667 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1672 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1674 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1676 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1677 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1678 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1679 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1684 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1685 wlan_postpone_association_work(priv);
1687 wlan_cancel_association_work(priv);
1689 mutex_unlock(&adapter->lock);
1696 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1698 * @param dev A pointer to net_device structure
1699 * @param info A pointer to iw_request_info structure
1700 * @param vwrq A pointer to iw_param structure
1701 * @param extra A pointer to extra data buf
1702 * @return 0 on success, otherwise failure
1704 static int wlan_get_encodeext(struct net_device *dev,
1705 struct iw_request_info *info,
1706 struct iw_point *dwrq,
1710 wlan_private *priv = dev->priv;
1711 wlan_adapter *adapter = priv->adapter;
1712 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1713 int index, max_key_len;
1717 max_key_len = dwrq->length - sizeof(*ext);
1718 if (max_key_len < 0)
1721 index = dwrq->flags & IW_ENCODE_INDEX;
1723 if (index < 1 || index > 4)
1727 index = adapter->wep_tx_keyidx;
1730 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
1731 ext->alg != IW_ENCODE_ALG_WEP) {
1732 if (index != 0 || adapter->mode != IW_MODE_INFRA)
1736 dwrq->flags = index + 1;
1737 memset(ext, 0, sizeof(*ext));
1739 if ( !adapter->secinfo.wep_enabled
1740 && !adapter->secinfo.WPAenabled
1741 && !adapter->secinfo.WPA2enabled) {
1742 ext->alg = IW_ENCODE_ALG_NONE;
1744 dwrq->flags |= IW_ENCODE_DISABLED;
1748 if ( adapter->secinfo.wep_enabled
1749 && !adapter->secinfo.WPAenabled
1750 && !adapter->secinfo.WPA2enabled) {
1751 ext->alg = IW_ENCODE_ALG_WEP;
1752 ext->key_len = adapter->wep_keys[index].len;
1753 key = &adapter->wep_keys[index].key[0];
1754 } else if ( !adapter->secinfo.wep_enabled
1755 && (adapter->secinfo.WPAenabled ||
1756 adapter->secinfo.WPA2enabled)) {
1758 ext->alg = IW_ENCODE_ALG_TKIP;
1764 if (ext->key_len > max_key_len) {
1770 memcpy(ext->key, key, ext->key_len);
1772 dwrq->flags |= IW_ENCODE_NOKEY;
1773 dwrq->flags |= IW_ENCODE_ENABLED;
1783 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1785 * @param dev A pointer to net_device structure
1786 * @param info A pointer to iw_request_info structure
1787 * @param vwrq A pointer to iw_param structure
1788 * @param extra A pointer to extra data buf
1789 * @return 0 --success, otherwise fail
1791 static int wlan_set_encodeext(struct net_device *dev,
1792 struct iw_request_info *info,
1793 struct iw_point *dwrq,
1797 wlan_private *priv = dev->priv;
1798 wlan_adapter *adapter = priv->adapter;
1799 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1801 struct assoc_request * assoc_req;
1805 mutex_lock(&adapter->lock);
1806 assoc_req = wlan_get_association_request(adapter);
1812 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1813 disable_wep (assoc_req);
1814 } else if (alg == IW_ENCODE_ALG_WEP) {
1815 u16 is_default = 0, index, set_tx_key = 0;
1817 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1818 (dwrq->flags & IW_ENCODE_INDEX),
1819 &index, &is_default);
1823 /* If WEP isn't enabled, or if there is no key data but a valid
1824 * index, or if the set-TX-key flag was passed, set the TX key.
1826 if ( !assoc_req->secinfo.wep_enabled
1827 || (dwrq->length == 0 && !is_default)
1828 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1831 /* Copy key to driver */
1832 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
1837 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1838 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1839 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1840 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1843 /* Mark the various WEP bits as modified */
1844 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1846 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1848 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1850 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1851 struct WLAN_802_11_KEY * pkey;
1853 /* validate key length */
1854 if (((alg == IW_ENCODE_ALG_TKIP)
1855 && (ext->key_len != KEY_LEN_WPA_TKIP))
1856 || ((alg == IW_ENCODE_ALG_CCMP)
1857 && (ext->key_len != KEY_LEN_WPA_AES))) {
1858 lbs_pr_debug(1, "Invalid size %d for key of alg"
1866 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY)
1867 pkey = &assoc_req->wpa_mcast_key;
1869 pkey = &assoc_req->wpa_unicast_key;
1871 memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
1872 memcpy(pkey->key, ext->key, ext->key_len);
1873 pkey->len = ext->key_len;
1874 pkey->flags = KEY_INFO_WPA_ENABLED;
1876 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1877 pkey->flags |= KEY_INFO_WPA_MCAST;
1878 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1880 pkey->flags |= KEY_INFO_WPA_UNICAST;
1881 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1884 if (alg == IW_ENCODE_ALG_TKIP)
1885 pkey->type = KEY_TYPE_ID_TKIP;
1886 else if (alg == IW_ENCODE_ALG_CCMP)
1887 pkey->type = KEY_TYPE_ID_AES;
1889 /* If WPA isn't enabled yet, do that now */
1890 if ( assoc_req->secinfo.WPAenabled == 0
1891 && assoc_req->secinfo.WPA2enabled == 0) {
1892 assoc_req->secinfo.WPAenabled = 1;
1893 assoc_req->secinfo.WPA2enabled = 1;
1894 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1897 disable_wep (assoc_req);
1902 wlan_postpone_association_work(priv);
1904 wlan_cancel_association_work(priv);
1906 mutex_unlock(&adapter->lock);
1913 static int wlan_set_genie(struct net_device *dev,
1914 struct iw_request_info *info,
1915 struct iw_point *dwrq,
1918 wlan_private *priv = dev->priv;
1919 wlan_adapter *adapter = priv->adapter;
1921 struct assoc_request * assoc_req;
1925 mutex_lock(&adapter->lock);
1926 assoc_req = wlan_get_association_request(adapter);
1932 if (dwrq->length > MAX_WPA_IE_LEN ||
1933 (dwrq->length && extra == NULL)) {
1939 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1940 assoc_req->wpa_ie_len = dwrq->length;
1942 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1943 assoc_req->wpa_ie_len = 0;
1948 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1949 wlan_postpone_association_work(priv);
1951 wlan_cancel_association_work(priv);
1953 mutex_unlock(&adapter->lock);
1959 static int wlan_get_genie(struct net_device *dev,
1960 struct iw_request_info *info,
1961 struct iw_point *dwrq,
1964 wlan_private *priv = dev->priv;
1965 wlan_adapter *adapter = priv->adapter;
1969 if (adapter->wpa_ie_len == 0) {
1975 if (dwrq->length < adapter->wpa_ie_len) {
1980 dwrq->length = adapter->wpa_ie_len;
1981 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1988 static int wlan_set_auth(struct net_device *dev,
1989 struct iw_request_info *info,
1990 struct iw_param *dwrq,
1993 wlan_private *priv = dev->priv;
1994 wlan_adapter *adapter = priv->adapter;
1995 struct assoc_request * assoc_req;
2001 mutex_lock(&adapter->lock);
2002 assoc_req = wlan_get_association_request(adapter);
2008 switch (dwrq->flags & IW_AUTH_INDEX) {
2009 case IW_AUTH_TKIP_COUNTERMEASURES:
2010 case IW_AUTH_CIPHER_PAIRWISE:
2011 case IW_AUTH_CIPHER_GROUP:
2012 case IW_AUTH_KEY_MGMT:
2014 * libertas does not use these parameters
2018 case IW_AUTH_WPA_VERSION:
2019 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
2020 assoc_req->secinfo.WPAenabled = 0;
2021 assoc_req->secinfo.WPA2enabled = 0;
2023 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
2024 assoc_req->secinfo.WPAenabled = 1;
2025 assoc_req->secinfo.wep_enabled = 0;
2026 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2028 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
2029 assoc_req->secinfo.WPA2enabled = 1;
2030 assoc_req->secinfo.wep_enabled = 0;
2031 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2036 case IW_AUTH_DROP_UNENCRYPTED:
2038 adapter->currentpacketfilter |=
2039 cmd_act_mac_strict_protection_enable;
2041 adapter->currentpacketfilter &=
2042 ~cmd_act_mac_strict_protection_enable;
2047 case IW_AUTH_80211_AUTH_ALG:
2048 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
2049 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
2050 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
2051 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2052 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
2053 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
2060 case IW_AUTH_WPA_ENABLED:
2062 if (!assoc_req->secinfo.WPAenabled &&
2063 !assoc_req->secinfo.WPA2enabled) {
2064 assoc_req->secinfo.WPAenabled = 1;
2065 assoc_req->secinfo.WPA2enabled = 1;
2066 assoc_req->secinfo.wep_enabled = 0;
2067 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2070 assoc_req->secinfo.WPAenabled = 0;
2071 assoc_req->secinfo.WPA2enabled = 0;
2084 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2085 wlan_postpone_association_work(priv);
2086 } else if (ret != -EOPNOTSUPP) {
2087 wlan_cancel_association_work(priv);
2089 mutex_unlock(&adapter->lock);
2095 static int wlan_get_auth(struct net_device *dev,
2096 struct iw_request_info *info,
2097 struct iw_param *dwrq,
2100 wlan_private *priv = dev->priv;
2101 wlan_adapter *adapter = priv->adapter;
2105 switch (dwrq->flags & IW_AUTH_INDEX) {
2106 case IW_AUTH_WPA_VERSION:
2108 if (adapter->secinfo.WPAenabled)
2109 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
2110 if (adapter->secinfo.WPA2enabled)
2111 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
2113 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
2116 case IW_AUTH_DROP_UNENCRYPTED:
2118 if (adapter->currentpacketfilter &
2119 cmd_act_mac_strict_protection_enable)
2123 case IW_AUTH_80211_AUTH_ALG:
2124 dwrq->value = adapter->secinfo.auth_mode;
2127 case IW_AUTH_WPA_ENABLED:
2128 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
2142 static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
2143 struct iw_param *vwrq, char *extra)
2146 wlan_private *priv = dev->priv;
2147 wlan_adapter *adapter = priv->adapter;
2153 if (vwrq->disabled) {
2154 wlan_radio_ioctl(priv, RADIO_OFF);
2158 adapter->preamble = cmd_type_auto_preamble;
2160 wlan_radio_ioctl(priv, RADIO_ON);
2162 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
2163 dbm = (u16) mw_to_dbm(vwrq->value);
2165 dbm = (u16) vwrq->value;
2167 /* auto tx power control */
2169 if (vwrq->fixed == 0)
2172 lbs_pr_debug(1, "<1>TXPOWER SET %d dbm.\n", dbm);
2174 ret = libertas_prepare_and_send_command(priv,
2175 cmd_802_11_rf_tx_power,
2176 cmd_act_tx_power_opt_set_low,
2177 cmd_option_waitforrsp, 0, (void *)&dbm);
2183 static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
2184 struct iw_point *dwrq, char *extra)
2186 wlan_private *priv = dev->priv;
2187 wlan_adapter *adapter = priv->adapter;
2191 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2196 * Get the current SSID
2198 if (adapter->connect_status == libertas_connected) {
2199 memcpy(extra, adapter->curbssparams.ssid.ssid,
2200 adapter->curbssparams.ssid.ssidlength);
2201 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2203 memset(extra, 0, 32);
2204 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2207 * If none, we may want to get the one that was set
2210 /* To make the driver backward compatible with WPA supplicant v0.2.4 */
2211 if (dwrq->length == 32) /* check with WPA supplicant buffer size */
2212 dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
2215 dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
2217 dwrq->flags = 1; /* active */
2223 static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
2224 struct iw_point *dwrq, char *extra)
2226 wlan_private *priv = dev->priv;
2227 wlan_adapter *adapter = priv->adapter;
2229 struct WLAN_802_11_SSID ssid;
2230 struct assoc_request * assoc_req;
2231 int ssid_len = dwrq->length;
2236 * WE-20 and earlier NULL pad the end of the SSID and increment
2237 * SSID length so it can be used like a string. WE-21 and later don't,
2238 * but some userspace tools aren't able to cope with the change.
2240 if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
2243 /* Check the size of the string */
2244 if (ssid_len > IW_ESSID_MAX_SIZE) {
2249 memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
2251 if (!dwrq->flags || !ssid_len) {
2252 /* "any" SSID requested; leave SSID blank */
2254 /* Specific SSID requested */
2255 memcpy(&ssid.ssid, extra, ssid_len);
2256 ssid.ssidlength = ssid_len;
2259 lbs_pr_debug(1, "Requested new SSID = %s\n",
2260 (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
2263 mutex_lock(&adapter->lock);
2265 /* Get or create the current association request */
2266 assoc_req = wlan_get_association_request(adapter);
2270 /* Copy the SSID to the association request */
2271 memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
2272 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2273 wlan_postpone_association_work(priv);
2277 /* Cancel the association request if there was an error */
2279 wlan_cancel_association_work(priv);
2282 mutex_unlock(&adapter->lock);
2289 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2291 * @param dev A pointer to net_device structure
2292 * @param info A pointer to iw_request_info structure
2293 * @param awrq A pointer to iw_param structure
2294 * @param extra A pointer to extra data buf
2295 * @return 0 --success, otherwise fail
2297 static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
2298 struct sockaddr *awrq, char *extra)
2300 wlan_private *priv = dev->priv;
2301 wlan_adapter *adapter = priv->adapter;
2302 struct assoc_request * assoc_req;
2307 if (awrq->sa_family != ARPHRD_ETHER)
2310 lbs_pr_debug(1, "ASSOC: WAP: sa_data: " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
2312 mutex_lock(&adapter->lock);
2314 /* Get or create the current association request */
2315 assoc_req = wlan_get_association_request(adapter);
2317 wlan_cancel_association_work(priv);
2320 /* Copy the BSSID to the association request */
2321 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2322 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2323 wlan_postpone_association_work(priv);
2326 mutex_unlock(&adapter->lock);
2331 void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2339 mutex_lock(&adapter->lock);
2340 ver.l = adapter->fwreleasenumber;
2341 mutex_unlock(&adapter->lock);
2344 sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
2346 sprintf(fwver, "%u.%u.%u.p%u",
2347 ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
2349 snprintf(fwversion, maxlen, fwver);
2354 * iwconfig settable callbacks
2356 static const iw_handler wlan_handler[] = {
2357 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2358 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2359 (iw_handler) NULL, /* SIOCSIWNWID */
2360 (iw_handler) NULL, /* SIOCGIWNWID */
2361 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2362 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2363 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2364 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2365 (iw_handler) NULL, /* SIOCSIWSENS */
2366 (iw_handler) NULL, /* SIOCGIWSENS */
2367 (iw_handler) NULL, /* SIOCSIWRANGE */
2368 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2369 (iw_handler) NULL, /* SIOCSIWPRIV */
2370 (iw_handler) NULL, /* SIOCGIWPRIV */
2371 (iw_handler) NULL, /* SIOCSIWSTATS */
2372 (iw_handler) NULL, /* SIOCGIWSTATS */
2373 iw_handler_set_spy, /* SIOCSIWSPY */
2374 iw_handler_get_spy, /* SIOCGIWSPY */
2375 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2376 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2377 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2378 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2379 (iw_handler) NULL, /* SIOCSIWMLME */
2380 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2381 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2382 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2383 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2384 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2385 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2386 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2387 (iw_handler) NULL, /* -- hole -- */
2388 (iw_handler) NULL, /* -- hole -- */
2389 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2390 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2391 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2392 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2393 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2394 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2395 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2396 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2397 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2398 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2399 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2400 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2401 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2402 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2403 (iw_handler) NULL, /* -- hole -- */
2404 (iw_handler) NULL, /* -- hole -- */
2405 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2406 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2407 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2408 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2409 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2410 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2411 (iw_handler) NULL, /* SIOCSIWPMKSA */
2414 struct iw_handler_def libertas_handler_def = {
2415 .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
2416 .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
2417 .num_private_args = sizeof(wlan_private_args) /
2418 sizeof(struct iw_priv_args),
2419 .standard = (iw_handler *) wlan_handler,
2420 .private = (iw_handler *) wlan_private_handler,
2421 .private_args = (struct iw_priv_args *)wlan_private_args,
2422 .get_wireless_stats = wlan_get_wireless_stats,