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 * the rates supported by the card
27 static u8 libertas_wlan_data_rates[WLAN_SUPPORTED_RATES] =
28 { 0x02, 0x04, 0x0B, 0x16, 0x00, 0x0C, 0x12,
29 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x00
33 * @brief Convert mw value to dbm value
35 * @param mw the value of mw
36 * @return the value of dbm
38 static int mw_to_dbm(int mw)
79 * @brief Find the channel frequency power info with specific channel
81 * @param adapter A pointer to wlan_adapter structure
82 * @param band it can be BAND_A, BAND_G or BAND_B
83 * @param channel the channel for looking
84 * @return A pointer to struct chan_freq_power structure or NULL if not find.
86 struct chan_freq_power *libertas_find_cfp_by_band_and_channel(wlan_adapter * adapter,
89 struct chan_freq_power *cfp = NULL;
90 struct region_channel *rc;
91 int count = sizeof(adapter->region_channel) /
92 sizeof(adapter->region_channel[0]);
95 for (j = 0; !cfp && (j < count); j++) {
96 rc = &adapter->region_channel[j];
98 if (adapter->enable11d)
99 rc = &adapter->universal_channel[j];
100 if (!rc->valid || !rc->CFP)
102 if (rc->band != band)
104 for (i = 0; i < rc->nrcfp; i++) {
105 if (rc->CFP[i].channel == channel) {
113 lbs_deb_wext("libertas_find_cfp_by_band_and_channel: can't find "
114 "cfp by band %d / channel %d\n", band, channel);
120 * @brief Find the channel frequency power info with specific frequency
122 * @param adapter A pointer to wlan_adapter structure
123 * @param band it can be BAND_A, BAND_G or BAND_B
124 * @param freq the frequency for looking
125 * @return A pointer to struct chan_freq_power structure or NULL if not find.
127 static struct chan_freq_power *find_cfp_by_band_and_freq(wlan_adapter * adapter,
130 struct chan_freq_power *cfp = NULL;
131 struct region_channel *rc;
132 int count = sizeof(adapter->region_channel) /
133 sizeof(adapter->region_channel[0]);
136 for (j = 0; !cfp && (j < count); j++) {
137 rc = &adapter->region_channel[j];
139 if (adapter->enable11d)
140 rc = &adapter->universal_channel[j];
141 if (!rc->valid || !rc->CFP)
143 if (rc->band != band)
145 for (i = 0; i < rc->nrcfp; i++) {
146 if (rc->CFP[i].freq == freq) {
154 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
155 "band %d / freq %d\n", band, freq);
162 * @brief Set Radio On/OFF
164 * @param priv A pointer to wlan_private structure
165 * @option Radio Option
166 * @return 0 --success, otherwise fail
168 int wlan_radio_ioctl(wlan_private * priv, u8 option)
171 wlan_adapter *adapter = priv->adapter;
173 lbs_deb_enter(LBS_DEB_WEXT);
175 if (adapter->radioon != option) {
176 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
177 adapter->radioon = option;
179 ret = libertas_prepare_and_send_command(priv,
180 cmd_802_11_radio_control,
182 cmd_option_waitforrsp, 0, NULL);
185 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
192 * @param dest A pointer to Dest Buf
193 * @param src A pointer to Src Buf
194 * @param len The len of Src Buf
195 * @return Number of rates copyed
197 static inline int copyrates(u8 * dest, int pos, u8 * src, int len)
201 for (i = 0; i < len && src[i]; i++, pos++) {
202 if (pos >= sizeof(u8) * WLAN_SUPPORTED_RATES)
211 * @brief Get active data rates
213 * @param adapter A pointer to wlan_adapter structure
214 * @param rate The buf to return the active rates
215 * @return The number of rates
217 static int get_active_data_rates(wlan_adapter * adapter,
222 lbs_deb_enter(LBS_DEB_WEXT);
224 if (adapter->connect_status != libertas_connected) {
225 if (adapter->mode == IW_MODE_INFRA) {
226 lbs_deb_wext("infra\n");
227 k = copyrates(rates, k, libertas_supported_rates,
228 sizeof(libertas_supported_rates));
230 lbs_deb_wext("Adhoc G\n");
231 k = copyrates(rates, k, libertas_adhoc_rates_g,
232 sizeof(libertas_adhoc_rates_g));
235 k = copyrates(rates, 0, adapter->curbssparams.datarates,
236 adapter->curbssparams.numofrates);
239 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", k);
243 static int wlan_get_name(struct net_device *dev, struct iw_request_info *info,
244 char *cwrq, char *extra)
247 char comm[6] = { "COMM-" };
248 char mrvl[6] = { "MRVL-" };
251 lbs_deb_enter(LBS_DEB_WEXT);
255 cp = strstr(libertas_driver_version, comm);
256 if (cp == libertas_driver_version) //skip leading "COMM-"
257 cp = libertas_driver_version + strlen(comm);
259 cp = libertas_driver_version;
263 while (cnt < 16 && (*cp != '-')) {
264 *cwrq++ = toupper(*cp++);
269 lbs_deb_leave(LBS_DEB_WEXT);
273 static int wlan_get_freq(struct net_device *dev, struct iw_request_info *info,
274 struct iw_freq *fwrq, char *extra)
276 wlan_private *priv = dev->priv;
277 wlan_adapter *adapter = priv->adapter;
278 struct chan_freq_power *cfp;
280 lbs_deb_enter(LBS_DEB_WEXT);
282 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0,
283 adapter->curbssparams.channel);
286 if (adapter->curbssparams.channel)
287 lbs_deb_wext("invalid channel %d\n",
288 adapter->curbssparams.channel);
292 fwrq->m = (long)cfp->freq * 100000;
295 lbs_deb_wext("freq %u\n", fwrq->m);
296 lbs_deb_leave(LBS_DEB_WEXT);
300 static int wlan_get_wap(struct net_device *dev, struct iw_request_info *info,
301 struct sockaddr *awrq, char *extra)
303 wlan_private *priv = dev->priv;
304 wlan_adapter *adapter = priv->adapter;
306 lbs_deb_enter(LBS_DEB_WEXT);
308 if (adapter->connect_status == libertas_connected) {
309 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
311 memset(awrq->sa_data, 0, ETH_ALEN);
313 awrq->sa_family = ARPHRD_ETHER;
315 lbs_deb_leave(LBS_DEB_WEXT);
319 static int wlan_set_nick(struct net_device *dev, struct iw_request_info *info,
320 struct iw_point *dwrq, char *extra)
322 wlan_private *priv = dev->priv;
323 wlan_adapter *adapter = priv->adapter;
325 lbs_deb_enter(LBS_DEB_WEXT);
328 * Check the size of the string
331 if (dwrq->length > 16) {
335 mutex_lock(&adapter->lock);
336 memset(adapter->nodename, 0, sizeof(adapter->nodename));
337 memcpy(adapter->nodename, extra, dwrq->length);
338 mutex_unlock(&adapter->lock);
340 lbs_deb_leave(LBS_DEB_WEXT);
344 static int wlan_get_nick(struct net_device *dev, struct iw_request_info *info,
345 struct iw_point *dwrq, char *extra)
347 wlan_private *priv = dev->priv;
348 wlan_adapter *adapter = priv->adapter;
350 lbs_deb_enter(LBS_DEB_WEXT);
353 * Get the Nick Name saved
356 mutex_lock(&adapter->lock);
357 strncpy(extra, adapter->nodename, 16);
358 mutex_unlock(&adapter->lock);
363 * If none, we may want to get the one that was set
369 dwrq->length = strlen(extra) + 1;
371 lbs_deb_leave(LBS_DEB_WEXT);
375 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
376 struct iw_point *dwrq, char *extra)
378 wlan_private *priv = dev->priv;
379 wlan_adapter *adapter = priv->adapter;
381 lbs_deb_enter(LBS_DEB_WEXT);
383 /* Use nickname to indicate that mesh is on */
385 if (adapter->connect_status == libertas_connected) {
386 strncpy(extra, "Mesh", 12);
388 dwrq->length = strlen(extra) + 1;
396 lbs_deb_leave(LBS_DEB_WEXT);
399 static int wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
400 struct iw_param *vwrq, char *extra)
403 wlan_private *priv = dev->priv;
404 wlan_adapter *adapter = priv->adapter;
405 u32 rthr = vwrq->value;
407 lbs_deb_enter(LBS_DEB_WEXT);
409 if (vwrq->disabled) {
410 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
412 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
414 adapter->rtsthsd = rthr;
417 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
418 cmd_act_set, cmd_option_waitforrsp,
419 OID_802_11_RTS_THRESHOLD, &rthr);
421 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
425 static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
426 struct iw_param *vwrq, char *extra)
429 wlan_private *priv = dev->priv;
430 wlan_adapter *adapter = priv->adapter;
432 lbs_deb_enter(LBS_DEB_WEXT);
434 adapter->rtsthsd = 0;
435 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
436 cmd_act_get, cmd_option_waitforrsp,
437 OID_802_11_RTS_THRESHOLD, NULL);
441 vwrq->value = adapter->rtsthsd;
442 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
443 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
447 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
451 static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
452 struct iw_param *vwrq, char *extra)
455 u32 fthr = vwrq->value;
456 wlan_private *priv = dev->priv;
457 wlan_adapter *adapter = priv->adapter;
459 lbs_deb_enter(LBS_DEB_WEXT);
461 if (vwrq->disabled) {
462 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
464 if (fthr < MRVDRV_FRAG_MIN_VALUE
465 || fthr > MRVDRV_FRAG_MAX_VALUE)
467 adapter->fragthsd = fthr;
470 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
471 cmd_act_set, cmd_option_waitforrsp,
472 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
474 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
478 static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
479 struct iw_param *vwrq, char *extra)
482 wlan_private *priv = dev->priv;
483 wlan_adapter *adapter = priv->adapter;
485 lbs_deb_enter(LBS_DEB_WEXT);
487 adapter->fragthsd = 0;
488 ret = libertas_prepare_and_send_command(priv,
490 cmd_act_get, cmd_option_waitforrsp,
491 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
495 vwrq->value = adapter->fragthsd;
496 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
497 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
501 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
505 static int wlan_get_mode(struct net_device *dev,
506 struct iw_request_info *info, u32 * uwrq, char *extra)
508 wlan_private *priv = dev->priv;
509 wlan_adapter *adapter = priv->adapter;
511 lbs_deb_enter(LBS_DEB_WEXT);
513 *uwrq = adapter->mode;
515 lbs_deb_leave(LBS_DEB_WEXT);
519 static int mesh_wlan_get_mode(struct net_device *dev,
520 struct iw_request_info *info, u32 * uwrq,
523 lbs_deb_enter(LBS_DEB_WEXT);
525 *uwrq = IW_MODE_REPEAT ;
527 lbs_deb_leave(LBS_DEB_WEXT);
531 static int wlan_get_txpow(struct net_device *dev,
532 struct iw_request_info *info,
533 struct iw_param *vwrq, char *extra)
536 wlan_private *priv = dev->priv;
537 wlan_adapter *adapter = priv->adapter;
539 lbs_deb_enter(LBS_DEB_WEXT);
541 ret = libertas_prepare_and_send_command(priv,
542 cmd_802_11_rf_tx_power,
543 cmd_act_tx_power_opt_get,
544 cmd_option_waitforrsp, 0, NULL);
549 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
550 vwrq->value = adapter->txpowerlevel;
552 if (adapter->radioon) {
554 vwrq->flags = IW_TXPOW_DBM;
560 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
564 static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
565 struct iw_param *vwrq, char *extra)
568 wlan_private *priv = dev->priv;
569 wlan_adapter *adapter = priv->adapter;
571 lbs_deb_enter(LBS_DEB_WEXT);
573 if (vwrq->flags == IW_RETRY_LIMIT) {
574 /* The MAC has a 4-bit Total_Tx_Count register
575 Total_Tx_Count = 1 + Tx_Retry_Count */
576 #define TX_RETRY_MIN 0
577 #define TX_RETRY_MAX 14
578 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
581 /* Adding 1 to convert retry count to try count */
582 adapter->txretrycount = vwrq->value + 1;
584 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
586 cmd_option_waitforrsp,
587 OID_802_11_TX_RETRYCOUNT, NULL);
596 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
600 static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
601 struct iw_param *vwrq, char *extra)
603 wlan_private *priv = dev->priv;
604 wlan_adapter *adapter = priv->adapter;
607 lbs_deb_enter(LBS_DEB_WEXT);
609 adapter->txretrycount = 0;
610 ret = libertas_prepare_and_send_command(priv,
612 cmd_act_get, cmd_option_waitforrsp,
613 OID_802_11_TX_RETRYCOUNT, NULL);
619 vwrq->flags = IW_RETRY_LIMIT;
620 /* Subtract 1 to convert try count to retry count */
621 vwrq->value = adapter->txretrycount - 1;
625 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
629 static inline void sort_channels(struct iw_freq *freq, int num)
634 for (i = 0; i < num; i++)
635 for (j = i + 1; j < num; j++)
636 if (freq[i].i > freq[j].i) {
640 freq[i].i = freq[j].i;
641 freq[i].m = freq[j].m;
651 Infra G(12) A(8) B(4) G(12)
652 Adhoc A+B(12) A(8) B(4) B(4)
660 * @brief Get Range Info
662 * @param dev A pointer to net_device structure
663 * @param info A pointer to iw_request_info structure
664 * @param vwrq A pointer to iw_param structure
665 * @param extra A pointer to extra data buf
666 * @return 0 --success, otherwise fail
668 static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
669 struct iw_point *dwrq, char *extra)
672 wlan_private *priv = dev->priv;
673 wlan_adapter *adapter = priv->adapter;
674 struct iw_range *range = (struct iw_range *)extra;
675 struct chan_freq_power *cfp;
676 u8 rates[WLAN_SUPPORTED_RATES];
680 lbs_deb_enter(LBS_DEB_WEXT);
682 dwrq->length = sizeof(struct iw_range);
683 memset(range, 0, sizeof(struct iw_range));
688 memset(rates, 0, sizeof(rates));
689 range->num_bitrates = get_active_data_rates(adapter, rates);
691 for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
693 range->bitrate[i] = (rates[i] & 0x7f) * 500000;
695 range->num_bitrates = i;
696 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
697 range->num_bitrates);
699 range->num_frequency = 0;
700 if (priv->adapter->enable11d &&
701 adapter->connect_status == libertas_connected) {
705 struct parsed_region_chan_11d *parsed_region_chan =
706 &adapter->parsed_region_chan;
708 if (parsed_region_chan == NULL) {
709 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
712 band = parsed_region_chan->band;
713 lbs_deb_wext("band %d, nr_char %d\n", band,
714 parsed_region_chan->nr_chan);
716 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
717 && (i < parsed_region_chan->nr_chan); i++) {
718 chan_no = parsed_region_chan->chanpwr[i].chan;
719 lbs_deb_wext("chan_no %d\n", chan_no);
720 range->freq[range->num_frequency].i = (long)chan_no;
721 range->freq[range->num_frequency].m =
722 (long)libertas_chan_2_freq(chan_no, band) * 100000;
723 range->freq[range->num_frequency].e = 1;
724 range->num_frequency++;
729 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
730 && (j < sizeof(adapter->region_channel)
731 / sizeof(adapter->region_channel[0])); j++) {
732 cfp = adapter->region_channel[j].CFP;
733 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
734 && adapter->region_channel[j].valid
736 && (i < adapter->region_channel[j].nrcfp); i++) {
737 range->freq[range->num_frequency].i =
739 range->freq[range->num_frequency].m =
740 (long)cfp->freq * 100000;
741 range->freq[range->num_frequency].e = 1;
743 range->num_frequency++;
748 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
749 IW_MAX_FREQUENCIES, range->num_frequency);
751 range->num_channels = range->num_frequency;
753 sort_channels(&range->freq[0], range->num_frequency);
756 * Set an indication of the max TCP throughput in bit/s that we can
757 * expect using this interface
760 range->throughput = 5000 * 1000;
762 range->throughput = 1500 * 1000;
764 range->min_rts = MRVDRV_RTS_MIN_VALUE;
765 range->max_rts = MRVDRV_RTS_MAX_VALUE;
766 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
767 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
769 range->encoding_size[0] = 5;
770 range->encoding_size[1] = 13;
771 range->num_encoding_sizes = 2;
772 range->max_encoding_tokens = 4;
774 range->min_pmp = 1000000;
775 range->max_pmp = 120000000;
776 range->min_pmt = 1000;
777 range->max_pmt = 1000000;
778 range->pmp_flags = IW_POWER_PERIOD;
779 range->pmt_flags = IW_POWER_TIMEOUT;
780 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
783 * Minimum version we recommend
785 range->we_version_source = 15;
788 * Version we are compiled with
790 range->we_version_compiled = WIRELESS_EXT;
792 range->retry_capa = IW_RETRY_LIMIT;
793 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
795 range->min_retry = TX_RETRY_MIN;
796 range->max_retry = TX_RETRY_MAX;
799 * Set the qual, level and noise range values
801 range->max_qual.qual = 100;
802 range->max_qual.level = 0;
803 range->max_qual.noise = 0;
804 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
806 range->avg_qual.qual = 70;
807 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
808 range->avg_qual.level = 0;
809 range->avg_qual.noise = 0;
810 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
812 range->sensitivity = 0;
815 * Setup the supported power level ranges
817 memset(range->txpower, 0, sizeof(range->txpower));
818 range->txpower[0] = 5;
819 range->txpower[1] = 7;
820 range->txpower[2] = 9;
821 range->txpower[3] = 11;
822 range->txpower[4] = 13;
823 range->txpower[5] = 15;
824 range->txpower[6] = 17;
825 range->txpower[7] = 19;
827 range->num_txpower = 8;
828 range->txpower_capa = IW_TXPOW_DBM;
829 range->txpower_capa |= IW_TXPOW_RANGE;
831 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
832 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
833 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
834 range->event_capa[1] = IW_EVENT_CAPA_K_1;
836 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
837 range->enc_capa = IW_ENC_CAPA_WPA
839 | IW_ENC_CAPA_CIPHER_TKIP
840 | IW_ENC_CAPA_CIPHER_CCMP;
844 lbs_deb_leave(LBS_DEB_WEXT);
848 static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
849 struct iw_param *vwrq, char *extra)
851 wlan_private *priv = dev->priv;
852 wlan_adapter *adapter = priv->adapter;
854 lbs_deb_enter(LBS_DEB_WEXT);
856 /* PS is currently supported only in Infrastructure mode
857 * Remove this check if it is to be supported in IBSS mode also
860 if (vwrq->disabled) {
861 adapter->psmode = wlan802_11powermodecam;
862 if (adapter->psstate != PS_STATE_FULL_POWER) {
863 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
869 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
871 "setting power timeout is not supported\n");
873 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
874 lbs_deb_wext("setting power period not supported\n");
878 if (adapter->psmode != wlan802_11powermodecam) {
882 adapter->psmode = wlan802_11powermodemax_psp;
884 if (adapter->connect_status == libertas_connected) {
885 libertas_ps_sleep(priv, cmd_option_waitforrsp);
888 lbs_deb_leave(LBS_DEB_WEXT);
892 static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
893 struct iw_param *vwrq, char *extra)
895 wlan_private *priv = dev->priv;
896 wlan_adapter *adapter = priv->adapter;
899 lbs_deb_enter(LBS_DEB_WEXT);
901 mode = adapter->psmode;
903 if ((vwrq->disabled = (mode == wlan802_11powermodecam))
904 || adapter->connect_status == libertas_disconnected)
912 lbs_deb_leave(LBS_DEB_WEXT);
916 static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
926 wlan_private *priv = dev->priv;
927 wlan_adapter *adapter = priv->adapter;
935 lbs_deb_enter(LBS_DEB_WEXT);
937 priv->wstats.status = adapter->mode;
939 /* If we're not associated, all quality values are meaningless */
940 if (adapter->connect_status != libertas_connected)
943 /* Quality by RSSI */
944 priv->wstats.qual.level =
945 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
946 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
948 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
949 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
951 priv->wstats.qual.noise =
952 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
955 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
956 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
958 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
960 rssi_qual = rssi * POOR / 10;
962 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
964 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
966 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
969 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
973 /* Quality by TX errors */
974 priv->wstats.discard.retries = priv->stats.tx_errors;
976 tx_retries = le16_to_cpu(adapter->logmsg.retry);
979 tx_qual = (90 - tx_retries) * POOR / 15;
980 else if (tx_retries > 70)
981 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
982 else if (tx_retries > 65)
983 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
984 else if (tx_retries > 50)
985 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
988 tx_qual = (50 - tx_retries) *
989 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
990 quality = min(quality, tx_qual);
992 priv->wstats.discard.code = le16_to_cpu(adapter->logmsg.wepundecryptable);
993 priv->wstats.discard.fragment = le16_to_cpu(adapter->logmsg.rxfrag);
994 priv->wstats.discard.retries = tx_retries;
995 priv->wstats.discard.misc = le16_to_cpu(adapter->logmsg.ackfailure);
997 /* Calculate quality */
998 priv->wstats.qual.qual = max(quality, (u32)100);
999 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1002 /* update stats asynchronously for future calls */
1003 libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
1005 libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
1009 priv->wstats.miss.beacon = 0;
1010 priv->wstats.discard.retries = 0;
1011 priv->wstats.qual.qual = 0;
1012 priv->wstats.qual.level = 0;
1013 priv->wstats.qual.noise = 0;
1014 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
1015 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
1016 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
1019 lbs_deb_leave(LBS_DEB_WEXT);
1020 return &priv->wstats;
1025 static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
1026 struct iw_freq *fwrq, char *extra)
1029 wlan_private *priv = dev->priv;
1030 wlan_adapter *adapter = priv->adapter;
1031 struct chan_freq_power *cfp;
1032 struct assoc_request * assoc_req;
1034 lbs_deb_enter(LBS_DEB_WEXT);
1036 mutex_lock(&adapter->lock);
1037 assoc_req = wlan_get_association_request(adapter);
1043 /* If setting by frequency, convert to a channel */
1045 long f = fwrq->m / 100000;
1047 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
1049 lbs_deb_wext("invalid freq %ld\n", f);
1054 fwrq->m = (int) cfp->channel;
1057 /* Setting by channel number */
1058 if (fwrq->m > 1000 || fwrq->e > 0) {
1062 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
1067 assoc_req->channel = fwrq->m;
1072 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
1073 wlan_postpone_association_work(priv);
1075 wlan_cancel_association_work(priv);
1077 mutex_unlock(&adapter->lock);
1079 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1084 * @brief use index to get the data rate
1086 * @param index The index of data rate
1087 * @return data rate or 0
1089 u32 libertas_index_to_data_rate(u8 index)
1091 if (index >= sizeof(libertas_wlan_data_rates))
1094 return libertas_wlan_data_rates[index];
1098 * @brief use rate to get the index
1100 * @param rate data rate
1101 * @return index or 0
1103 u8 libertas_data_rate_to_index(u32 rate)
1108 if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
1109 sizeof(libertas_wlan_data_rates))))
1110 return (ptr - libertas_wlan_data_rates);
1115 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
1116 struct iw_param *vwrq, char *extra)
1118 wlan_private *priv = dev->priv;
1119 wlan_adapter *adapter = priv->adapter;
1123 u8 rates[WLAN_SUPPORTED_RATES];
1126 lbs_deb_enter(LBS_DEB_WEXT);
1128 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
1130 if (vwrq->value == -1) {
1131 action = cmd_act_set_tx_auto; // Auto
1132 adapter->is_datarate_auto = 1;
1133 adapter->datarate = 0;
1135 if (vwrq->value % 100000) {
1139 data_rate = vwrq->value / 500000;
1141 memset(rates, 0, sizeof(rates));
1142 get_active_data_rates(adapter, rates);
1145 lbs_deb_wext("rate=0x%X, wanted data_rate 0x%X\n", *rate,
1147 if ((*rate & 0x7f) == (data_rate & 0x7f))
1152 lbs_pr_alert("fixed data rate 0x%X out "
1153 "of range\n", data_rate);
1157 adapter->datarate = data_rate;
1158 action = cmd_act_set_tx_fix_rate;
1159 adapter->is_datarate_auto = 0;
1162 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
1163 action, cmd_option_waitforrsp, 0, NULL);
1165 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1169 static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1170 struct iw_param *vwrq, char *extra)
1172 wlan_private *priv = dev->priv;
1173 wlan_adapter *adapter = priv->adapter;
1175 lbs_deb_enter(LBS_DEB_WEXT);
1177 if (adapter->is_datarate_auto) {
1183 vwrq->value = adapter->datarate * 500000;
1185 lbs_deb_leave(LBS_DEB_WEXT);
1189 static int wlan_set_mode(struct net_device *dev,
1190 struct iw_request_info *info, u32 * uwrq, char *extra)
1193 wlan_private *priv = dev->priv;
1194 wlan_adapter *adapter = priv->adapter;
1195 struct assoc_request * assoc_req;
1197 lbs_deb_enter(LBS_DEB_WEXT);
1199 if ( (*uwrq != IW_MODE_ADHOC)
1200 && (*uwrq != IW_MODE_INFRA)
1201 && (*uwrq != IW_MODE_AUTO)) {
1202 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1207 mutex_lock(&adapter->lock);
1208 assoc_req = wlan_get_association_request(adapter);
1211 wlan_cancel_association_work(priv);
1213 assoc_req->mode = *uwrq;
1214 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1215 wlan_postpone_association_work(priv);
1216 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1218 mutex_unlock(&adapter->lock);
1221 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1227 * @brief Get Encryption key
1229 * @param dev A pointer to net_device structure
1230 * @param info A pointer to iw_request_info structure
1231 * @param vwrq A pointer to iw_param structure
1232 * @param extra A pointer to extra data buf
1233 * @return 0 --success, otherwise fail
1235 static int wlan_get_encode(struct net_device *dev,
1236 struct iw_request_info *info,
1237 struct iw_point *dwrq, u8 * extra)
1239 wlan_private *priv = dev->priv;
1240 wlan_adapter *adapter = priv->adapter;
1241 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1243 lbs_deb_enter(LBS_DEB_WEXT);
1245 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1246 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1250 /* Authentication method */
1251 switch (adapter->secinfo.auth_mode) {
1252 case IW_AUTH_ALG_OPEN_SYSTEM:
1253 dwrq->flags = IW_ENCODE_OPEN;
1256 case IW_AUTH_ALG_SHARED_KEY:
1257 case IW_AUTH_ALG_LEAP:
1258 dwrq->flags = IW_ENCODE_RESTRICTED;
1261 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1265 if ( adapter->secinfo.wep_enabled
1266 || adapter->secinfo.WPAenabled
1267 || adapter->secinfo.WPA2enabled) {
1268 dwrq->flags &= ~IW_ENCODE_DISABLED;
1270 dwrq->flags |= IW_ENCODE_DISABLED;
1273 memset(extra, 0, 16);
1275 mutex_lock(&adapter->lock);
1277 /* Default to returning current transmit key */
1279 index = adapter->wep_tx_keyidx;
1281 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
1282 memcpy(extra, adapter->wep_keys[index].key,
1283 adapter->wep_keys[index].len);
1284 dwrq->length = adapter->wep_keys[index].len;
1286 dwrq->flags |= (index + 1);
1287 /* Return WEP enabled */
1288 dwrq->flags &= ~IW_ENCODE_DISABLED;
1289 } else if ((adapter->secinfo.WPAenabled)
1290 || (adapter->secinfo.WPA2enabled)) {
1291 /* return WPA enabled */
1292 dwrq->flags &= ~IW_ENCODE_DISABLED;
1294 dwrq->flags |= IW_ENCODE_DISABLED;
1297 mutex_unlock(&adapter->lock);
1299 dwrq->flags |= IW_ENCODE_NOKEY;
1301 lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
1302 extra[0], extra[1], extra[2],
1303 extra[3], extra[4], extra[5], dwrq->length);
1305 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1307 lbs_deb_leave(LBS_DEB_WEXT);
1312 * @brief Set Encryption key (internal)
1314 * @param priv A pointer to private card structure
1315 * @param key_material A pointer to key material
1316 * @param key_length length of key material
1317 * @param index key index to set
1318 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1319 * @return 0 --success, otherwise fail
1321 static int wlan_set_wep_key(struct assoc_request *assoc_req,
1322 const char *key_material,
1328 struct WLAN_802_11_KEY *pkey;
1330 lbs_deb_enter(LBS_DEB_WEXT);
1332 /* Paranoid validation of key index */
1338 /* validate max key length */
1339 if (key_length > KEY_LEN_WEP_104) {
1344 pkey = &assoc_req->wep_keys[index];
1346 if (key_length > 0) {
1347 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
1348 pkey->type = KEY_TYPE_ID_WEP;
1350 /* Standardize the key length */
1351 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1352 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1353 memcpy(pkey->key, key_material, key_length);
1357 /* Ensure the chosen key is valid */
1359 lbs_deb_wext("key not set, so cannot enable it\n");
1363 assoc_req->wep_tx_keyidx = index;
1366 assoc_req->secinfo.wep_enabled = 1;
1369 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1373 static int validate_key_index(u16 def_index, u16 raw_index,
1374 u16 *out_index, u16 *is_default)
1376 if (!out_index || !is_default)
1379 /* Verify index if present, otherwise use default TX key index */
1380 if (raw_index > 0) {
1383 *out_index = raw_index - 1;
1385 *out_index = def_index;
1391 static void disable_wep(struct assoc_request *assoc_req)
1395 lbs_deb_enter(LBS_DEB_WEXT);
1397 /* Set Open System auth mode */
1398 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1400 /* Clear WEP keys and mark WEP as disabled */
1401 assoc_req->secinfo.wep_enabled = 0;
1402 for (i = 0; i < 4; i++)
1403 assoc_req->wep_keys[i].len = 0;
1405 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1406 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1408 lbs_deb_leave(LBS_DEB_WEXT);
1411 static void disable_wpa(struct assoc_request *assoc_req)
1413 lbs_deb_enter(LBS_DEB_WEXT);
1415 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct WLAN_802_11_KEY));
1416 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1417 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1419 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct WLAN_802_11_KEY));
1420 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1421 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1423 assoc_req->secinfo.WPAenabled = 0;
1424 assoc_req->secinfo.WPA2enabled = 0;
1425 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1427 lbs_deb_leave(LBS_DEB_WEXT);
1431 * @brief Set Encryption key
1433 * @param dev A pointer to net_device structure
1434 * @param info A pointer to iw_request_info structure
1435 * @param vwrq A pointer to iw_param structure
1436 * @param extra A pointer to extra data buf
1437 * @return 0 --success, otherwise fail
1439 static int wlan_set_encode(struct net_device *dev,
1440 struct iw_request_info *info,
1441 struct iw_point *dwrq, char *extra)
1444 wlan_private *priv = dev->priv;
1445 wlan_adapter *adapter = priv->adapter;
1446 struct assoc_request * assoc_req;
1447 u16 is_default = 0, index = 0, set_tx_key = 0;
1449 lbs_deb_enter(LBS_DEB_WEXT);
1451 mutex_lock(&adapter->lock);
1452 assoc_req = wlan_get_association_request(adapter);
1458 if (dwrq->flags & IW_ENCODE_DISABLED) {
1459 disable_wep (assoc_req);
1460 disable_wpa (assoc_req);
1464 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1465 (dwrq->flags & IW_ENCODE_INDEX),
1466 &index, &is_default);
1472 /* If WEP isn't enabled, or if there is no key data but a valid
1473 * index, set the TX key.
1475 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1478 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1483 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1485 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1487 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1488 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1489 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1490 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1495 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1496 wlan_postpone_association_work(priv);
1498 wlan_cancel_association_work(priv);
1500 mutex_unlock(&adapter->lock);
1502 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1507 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1509 * @param dev A pointer to net_device structure
1510 * @param info A pointer to iw_request_info structure
1511 * @param vwrq A pointer to iw_param structure
1512 * @param extra A pointer to extra data buf
1513 * @return 0 on success, otherwise failure
1515 static int wlan_get_encodeext(struct net_device *dev,
1516 struct iw_request_info *info,
1517 struct iw_point *dwrq,
1521 wlan_private *priv = dev->priv;
1522 wlan_adapter *adapter = priv->adapter;
1523 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1524 int index, max_key_len;
1526 lbs_deb_enter(LBS_DEB_WEXT);
1528 max_key_len = dwrq->length - sizeof(*ext);
1529 if (max_key_len < 0)
1532 index = dwrq->flags & IW_ENCODE_INDEX;
1534 if (index < 1 || index > 4)
1538 index = adapter->wep_tx_keyidx;
1541 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
1542 ext->alg != IW_ENCODE_ALG_WEP) {
1543 if (index != 0 || adapter->mode != IW_MODE_INFRA)
1547 dwrq->flags = index + 1;
1548 memset(ext, 0, sizeof(*ext));
1550 if ( !adapter->secinfo.wep_enabled
1551 && !adapter->secinfo.WPAenabled
1552 && !adapter->secinfo.WPA2enabled) {
1553 ext->alg = IW_ENCODE_ALG_NONE;
1555 dwrq->flags |= IW_ENCODE_DISABLED;
1559 if ( adapter->secinfo.wep_enabled
1560 && !adapter->secinfo.WPAenabled
1561 && !adapter->secinfo.WPA2enabled) {
1563 ext->alg = IW_ENCODE_ALG_WEP;
1564 ext->key_len = adapter->wep_keys[index].len;
1565 key = &adapter->wep_keys[index].key[0];
1566 } else if ( !adapter->secinfo.wep_enabled
1567 && (adapter->secinfo.WPAenabled ||
1568 adapter->secinfo.WPA2enabled)) {
1570 struct WLAN_802_11_KEY * pkey = NULL;
1572 if ( adapter->wpa_mcast_key.len
1573 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1574 pkey = &adapter->wpa_mcast_key;
1575 else if ( adapter->wpa_unicast_key.len
1576 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1577 pkey = &adapter->wpa_unicast_key;
1580 if (pkey->type == KEY_TYPE_ID_AES) {
1581 ext->alg = IW_ENCODE_ALG_CCMP;
1583 ext->alg = IW_ENCODE_ALG_TKIP;
1585 ext->key_len = pkey->len;
1586 key = &pkey->key[0];
1588 ext->alg = IW_ENCODE_ALG_TKIP;
1595 if (ext->key_len > max_key_len) {
1601 memcpy(ext->key, key, ext->key_len);
1603 dwrq->flags |= IW_ENCODE_NOKEY;
1604 dwrq->flags |= IW_ENCODE_ENABLED;
1609 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1614 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1616 * @param dev A pointer to net_device structure
1617 * @param info A pointer to iw_request_info structure
1618 * @param vwrq A pointer to iw_param structure
1619 * @param extra A pointer to extra data buf
1620 * @return 0 --success, otherwise fail
1622 static int wlan_set_encodeext(struct net_device *dev,
1623 struct iw_request_info *info,
1624 struct iw_point *dwrq,
1628 wlan_private *priv = dev->priv;
1629 wlan_adapter *adapter = priv->adapter;
1630 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1632 struct assoc_request * assoc_req;
1634 lbs_deb_enter(LBS_DEB_WEXT);
1636 mutex_lock(&adapter->lock);
1637 assoc_req = wlan_get_association_request(adapter);
1643 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1644 disable_wep (assoc_req);
1645 disable_wpa (assoc_req);
1646 } else if (alg == IW_ENCODE_ALG_WEP) {
1647 u16 is_default = 0, index, set_tx_key = 0;
1649 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1650 (dwrq->flags & IW_ENCODE_INDEX),
1651 &index, &is_default);
1655 /* If WEP isn't enabled, or if there is no key data but a valid
1656 * index, or if the set-TX-key flag was passed, set the TX key.
1658 if ( !assoc_req->secinfo.wep_enabled
1659 || (dwrq->length == 0 && !is_default)
1660 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1663 /* Copy key to driver */
1664 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
1669 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1670 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1671 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1672 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1675 /* Mark the various WEP bits as modified */
1676 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1678 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1680 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1681 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1682 struct WLAN_802_11_KEY * pkey;
1684 /* validate key length */
1685 if (((alg == IW_ENCODE_ALG_TKIP)
1686 && (ext->key_len != KEY_LEN_WPA_TKIP))
1687 || ((alg == IW_ENCODE_ALG_CCMP)
1688 && (ext->key_len != KEY_LEN_WPA_AES))) {
1689 lbs_deb_wext("invalid size %d for key of alg"
1697 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1698 pkey = &assoc_req->wpa_mcast_key;
1699 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1701 pkey = &assoc_req->wpa_unicast_key;
1702 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1705 memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
1706 memcpy(pkey->key, ext->key, ext->key_len);
1707 pkey->len = ext->key_len;
1709 pkey->flags |= KEY_INFO_WPA_ENABLED;
1711 /* Do this after zeroing key structure */
1712 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1713 pkey->flags |= KEY_INFO_WPA_MCAST;
1715 pkey->flags |= KEY_INFO_WPA_UNICAST;
1718 if (alg == IW_ENCODE_ALG_TKIP) {
1719 pkey->type = KEY_TYPE_ID_TKIP;
1720 } else if (alg == IW_ENCODE_ALG_CCMP) {
1721 pkey->type = KEY_TYPE_ID_AES;
1724 /* If WPA isn't enabled yet, do that now */
1725 if ( assoc_req->secinfo.WPAenabled == 0
1726 && assoc_req->secinfo.WPA2enabled == 0) {
1727 assoc_req->secinfo.WPAenabled = 1;
1728 assoc_req->secinfo.WPA2enabled = 1;
1729 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1732 disable_wep (assoc_req);
1737 wlan_postpone_association_work(priv);
1739 wlan_cancel_association_work(priv);
1741 mutex_unlock(&adapter->lock);
1743 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1748 static int wlan_set_genie(struct net_device *dev,
1749 struct iw_request_info *info,
1750 struct iw_point *dwrq,
1753 wlan_private *priv = dev->priv;
1754 wlan_adapter *adapter = priv->adapter;
1756 struct assoc_request * assoc_req;
1758 lbs_deb_enter(LBS_DEB_WEXT);
1760 mutex_lock(&adapter->lock);
1761 assoc_req = wlan_get_association_request(adapter);
1767 if (dwrq->length > MAX_WPA_IE_LEN ||
1768 (dwrq->length && extra == NULL)) {
1774 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1775 assoc_req->wpa_ie_len = dwrq->length;
1777 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1778 assoc_req->wpa_ie_len = 0;
1783 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1784 wlan_postpone_association_work(priv);
1786 wlan_cancel_association_work(priv);
1788 mutex_unlock(&adapter->lock);
1790 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1794 static int wlan_get_genie(struct net_device *dev,
1795 struct iw_request_info *info,
1796 struct iw_point *dwrq,
1800 wlan_private *priv = dev->priv;
1801 wlan_adapter *adapter = priv->adapter;
1803 lbs_deb_enter(LBS_DEB_WEXT);
1805 if (adapter->wpa_ie_len == 0) {
1810 if (dwrq->length < adapter->wpa_ie_len) {
1815 dwrq->length = adapter->wpa_ie_len;
1816 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1819 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1824 static int wlan_set_auth(struct net_device *dev,
1825 struct iw_request_info *info,
1826 struct iw_param *dwrq,
1829 wlan_private *priv = dev->priv;
1830 wlan_adapter *adapter = priv->adapter;
1831 struct assoc_request * assoc_req;
1835 lbs_deb_enter(LBS_DEB_WEXT);
1837 mutex_lock(&adapter->lock);
1838 assoc_req = wlan_get_association_request(adapter);
1844 switch (dwrq->flags & IW_AUTH_INDEX) {
1845 case IW_AUTH_TKIP_COUNTERMEASURES:
1846 case IW_AUTH_CIPHER_PAIRWISE:
1847 case IW_AUTH_CIPHER_GROUP:
1848 case IW_AUTH_KEY_MGMT:
1849 case IW_AUTH_DROP_UNENCRYPTED:
1851 * libertas does not use these parameters
1855 case IW_AUTH_WPA_VERSION:
1856 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1857 assoc_req->secinfo.WPAenabled = 0;
1858 assoc_req->secinfo.WPA2enabled = 0;
1859 disable_wpa (assoc_req);
1861 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1862 assoc_req->secinfo.WPAenabled = 1;
1863 assoc_req->secinfo.wep_enabled = 0;
1864 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1866 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1867 assoc_req->secinfo.WPA2enabled = 1;
1868 assoc_req->secinfo.wep_enabled = 0;
1869 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1874 case IW_AUTH_80211_AUTH_ALG:
1875 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1876 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1877 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1878 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1879 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1880 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1887 case IW_AUTH_WPA_ENABLED:
1889 if (!assoc_req->secinfo.WPAenabled &&
1890 !assoc_req->secinfo.WPA2enabled) {
1891 assoc_req->secinfo.WPAenabled = 1;
1892 assoc_req->secinfo.WPA2enabled = 1;
1893 assoc_req->secinfo.wep_enabled = 0;
1894 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1897 assoc_req->secinfo.WPAenabled = 0;
1898 assoc_req->secinfo.WPA2enabled = 0;
1899 disable_wpa (assoc_req);
1912 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1913 wlan_postpone_association_work(priv);
1914 } else if (ret != -EOPNOTSUPP) {
1915 wlan_cancel_association_work(priv);
1917 mutex_unlock(&adapter->lock);
1919 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1923 static int wlan_get_auth(struct net_device *dev,
1924 struct iw_request_info *info,
1925 struct iw_param *dwrq,
1929 wlan_private *priv = dev->priv;
1930 wlan_adapter *adapter = priv->adapter;
1932 lbs_deb_enter(LBS_DEB_WEXT);
1934 switch (dwrq->flags & IW_AUTH_INDEX) {
1935 case IW_AUTH_WPA_VERSION:
1937 if (adapter->secinfo.WPAenabled)
1938 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1939 if (adapter->secinfo.WPA2enabled)
1940 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1942 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1945 case IW_AUTH_80211_AUTH_ALG:
1946 dwrq->value = adapter->secinfo.auth_mode;
1949 case IW_AUTH_WPA_ENABLED:
1950 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
1958 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1963 static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
1964 struct iw_param *vwrq, char *extra)
1967 wlan_private *priv = dev->priv;
1968 wlan_adapter *adapter = priv->adapter;
1972 lbs_deb_enter(LBS_DEB_WEXT);
1974 if (vwrq->disabled) {
1975 wlan_radio_ioctl(priv, RADIO_OFF);
1979 adapter->preamble = cmd_type_auto_preamble;
1981 wlan_radio_ioctl(priv, RADIO_ON);
1983 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
1984 dbm = (u16) mw_to_dbm(vwrq->value);
1986 dbm = (u16) vwrq->value;
1988 /* auto tx power control */
1990 if (vwrq->fixed == 0)
1993 lbs_deb_wext("txpower set %d dbm\n", dbm);
1995 ret = libertas_prepare_and_send_command(priv,
1996 cmd_802_11_rf_tx_power,
1997 cmd_act_tx_power_opt_set_low,
1998 cmd_option_waitforrsp, 0, (void *)&dbm);
2000 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2004 static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
2005 struct iw_point *dwrq, char *extra)
2007 wlan_private *priv = dev->priv;
2008 wlan_adapter *adapter = priv->adapter;
2010 lbs_deb_enter(LBS_DEB_WEXT);
2013 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2018 * Get the current SSID
2020 if (adapter->connect_status == libertas_connected) {
2021 memcpy(extra, adapter->curbssparams.ssid,
2022 adapter->curbssparams.ssid_len);
2023 extra[adapter->curbssparams.ssid_len] = '\0';
2025 memset(extra, 0, 32);
2026 extra[adapter->curbssparams.ssid_len] = '\0';
2029 * If none, we may want to get the one that was set
2032 /* To make the driver backward compatible with WPA supplicant v0.2.4 */
2033 if (dwrq->length == 32) /* check with WPA supplicant buffer size */
2034 dwrq->length = min_t(size_t, adapter->curbssparams.ssid_len,
2037 dwrq->length = adapter->curbssparams.ssid_len + 1;
2039 dwrq->flags = 1; /* active */
2041 lbs_deb_leave(LBS_DEB_WEXT);
2045 static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
2046 struct iw_point *dwrq, char *extra)
2048 wlan_private *priv = dev->priv;
2049 wlan_adapter *adapter = priv->adapter;
2051 u8 ssid[IW_ESSID_MAX_SIZE];
2053 struct assoc_request * assoc_req;
2054 int in_ssid_len = dwrq->length;
2056 lbs_deb_enter(LBS_DEB_WEXT);
2059 * WE-20 and earlier NULL pad the end of the SSID and increment
2060 * SSID length so it can be used like a string. WE-21 and later don't,
2061 * but some userspace tools aren't able to cope with the change.
2063 if ((in_ssid_len > 0) && (extra[in_ssid_len - 1] == '\0'))
2066 /* Check the size of the string */
2067 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
2072 memset(&ssid, 0, sizeof(ssid));
2074 if (!dwrq->flags || !in_ssid_len) {
2075 /* "any" SSID requested; leave SSID blank */
2077 /* Specific SSID requested */
2078 memcpy(&ssid, extra, in_ssid_len);
2079 ssid_len = in_ssid_len;
2083 lbs_deb_wext("requested any SSID\n");
2085 lbs_deb_wext("requested SSID '%s'\n",
2086 escape_essid(ssid, ssid_len));
2090 mutex_lock(&adapter->lock);
2092 /* Get or create the current association request */
2093 assoc_req = wlan_get_association_request(adapter);
2097 /* Copy the SSID to the association request */
2098 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
2099 assoc_req->ssid_len = ssid_len;
2100 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2101 wlan_postpone_association_work(priv);
2105 /* Cancel the association request if there was an error */
2107 wlan_cancel_association_work(priv);
2110 mutex_unlock(&adapter->lock);
2112 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2117 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2119 * @param dev A pointer to net_device structure
2120 * @param info A pointer to iw_request_info structure
2121 * @param awrq A pointer to iw_param structure
2122 * @param extra A pointer to extra data buf
2123 * @return 0 --success, otherwise fail
2125 static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
2126 struct sockaddr *awrq, char *extra)
2128 wlan_private *priv = dev->priv;
2129 wlan_adapter *adapter = priv->adapter;
2130 struct assoc_request * assoc_req;
2133 lbs_deb_enter(LBS_DEB_WEXT);
2135 if (awrq->sa_family != ARPHRD_ETHER)
2138 lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
2140 mutex_lock(&adapter->lock);
2142 /* Get or create the current association request */
2143 assoc_req = wlan_get_association_request(adapter);
2145 wlan_cancel_association_work(priv);
2148 /* Copy the BSSID to the association request */
2149 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2150 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2151 wlan_postpone_association_work(priv);
2154 mutex_unlock(&adapter->lock);
2159 void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2163 mutex_lock(&adapter->lock);
2165 if (adapter->fwreleasenumber[3] == 0)
2166 sprintf(fwver, "%u.%u.%u",
2167 adapter->fwreleasenumber[2],
2168 adapter->fwreleasenumber[1],
2169 adapter->fwreleasenumber[0]);
2171 sprintf(fwver, "%u.%u.%u.p%u",
2172 adapter->fwreleasenumber[2],
2173 adapter->fwreleasenumber[1],
2174 adapter->fwreleasenumber[0],
2175 adapter->fwreleasenumber[3]);
2177 mutex_unlock(&adapter->lock);
2178 snprintf(fwversion, maxlen, fwver);
2183 * iwconfig settable callbacks
2185 static const iw_handler wlan_handler[] = {
2186 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2187 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2188 (iw_handler) NULL, /* SIOCSIWNWID */
2189 (iw_handler) NULL, /* SIOCGIWNWID */
2190 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2191 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2192 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2193 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2194 (iw_handler) NULL, /* SIOCSIWSENS */
2195 (iw_handler) NULL, /* SIOCGIWSENS */
2196 (iw_handler) NULL, /* SIOCSIWRANGE */
2197 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2198 (iw_handler) NULL, /* SIOCSIWPRIV */
2199 (iw_handler) NULL, /* SIOCGIWPRIV */
2200 (iw_handler) NULL, /* SIOCSIWSTATS */
2201 (iw_handler) NULL, /* SIOCGIWSTATS */
2202 iw_handler_set_spy, /* SIOCSIWSPY */
2203 iw_handler_get_spy, /* SIOCGIWSPY */
2204 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2205 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2206 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2207 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2208 (iw_handler) NULL, /* SIOCSIWMLME */
2209 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2210 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2211 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2212 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2213 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2214 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2215 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2216 (iw_handler) NULL, /* -- hole -- */
2217 (iw_handler) NULL, /* -- hole -- */
2218 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2219 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2220 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2221 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2222 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2223 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2224 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2225 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2226 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2227 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2228 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2229 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2230 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2231 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2232 (iw_handler) NULL, /* -- hole -- */
2233 (iw_handler) NULL, /* -- hole -- */
2234 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2235 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2236 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2237 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2238 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2239 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2240 (iw_handler) NULL, /* SIOCSIWPMKSA */
2243 static const iw_handler mesh_wlan_handler[] = {
2244 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2245 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2246 (iw_handler) NULL, /* SIOCSIWNWID */
2247 (iw_handler) NULL, /* SIOCGIWNWID */
2248 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2249 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2250 (iw_handler) NULL, /* SIOCSIWMODE */
2251 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2252 (iw_handler) NULL, /* SIOCSIWSENS */
2253 (iw_handler) NULL, /* SIOCGIWSENS */
2254 (iw_handler) NULL, /* SIOCSIWRANGE */
2255 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2256 (iw_handler) NULL, /* SIOCSIWPRIV */
2257 (iw_handler) NULL, /* SIOCGIWPRIV */
2258 (iw_handler) NULL, /* SIOCSIWSTATS */
2259 (iw_handler) NULL, /* SIOCGIWSTATS */
2260 iw_handler_set_spy, /* SIOCSIWSPY */
2261 iw_handler_get_spy, /* SIOCGIWSPY */
2262 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2263 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2264 (iw_handler) NULL, /* SIOCSIWAP */
2265 (iw_handler) NULL, /* SIOCGIWAP */
2266 (iw_handler) NULL, /* SIOCSIWMLME */
2267 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2268 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2269 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2270 (iw_handler) NULL, /* SIOCSIWESSID */
2271 (iw_handler) NULL, /* SIOCGIWESSID */
2272 (iw_handler) NULL, /* SIOCSIWNICKN */
2273 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2274 (iw_handler) NULL, /* -- hole -- */
2275 (iw_handler) NULL, /* -- hole -- */
2276 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2277 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2278 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2279 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2280 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2281 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2282 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2283 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2284 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2285 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2286 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2287 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2288 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2289 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2290 (iw_handler) NULL, /* -- hole -- */
2291 (iw_handler) NULL, /* -- hole -- */
2292 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2293 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2294 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2295 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2296 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2297 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2298 (iw_handler) NULL, /* SIOCSIWPMKSA */
2300 struct iw_handler_def libertas_handler_def = {
2301 .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
2302 .standard = (iw_handler *) wlan_handler,
2303 .get_wireless_stats = wlan_get_wireless_stats,
2306 struct iw_handler_def mesh_handler_def = {
2307 .num_standard = sizeof(mesh_wlan_handler) / sizeof(iw_handler),
2308 .standard = (iw_handler *) mesh_wlan_handler,
2309 .get_wireless_stats = wlan_get_wireless_stats,