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 wlan_set_rts(struct net_device *dev, struct iw_request_info *info,
376 struct iw_param *vwrq, char *extra)
379 wlan_private *priv = dev->priv;
380 wlan_adapter *adapter = priv->adapter;
381 int rthr = vwrq->value;
383 lbs_deb_enter(LBS_DEB_WEXT);
385 if (vwrq->disabled) {
386 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
388 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
390 adapter->rtsthsd = rthr;
393 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
394 cmd_act_set, cmd_option_waitforrsp,
395 OID_802_11_RTS_THRESHOLD, &rthr);
397 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
401 static int wlan_get_rts(struct net_device *dev, struct iw_request_info *info,
402 struct iw_param *vwrq, char *extra)
405 wlan_private *priv = dev->priv;
406 wlan_adapter *adapter = priv->adapter;
408 lbs_deb_enter(LBS_DEB_WEXT);
410 adapter->rtsthsd = 0;
411 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
412 cmd_act_get, cmd_option_waitforrsp,
413 OID_802_11_RTS_THRESHOLD, NULL);
417 vwrq->value = adapter->rtsthsd;
418 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
419 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
423 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
427 static int wlan_set_frag(struct net_device *dev, struct iw_request_info *info,
428 struct iw_param *vwrq, char *extra)
431 int fthr = vwrq->value;
432 wlan_private *priv = dev->priv;
433 wlan_adapter *adapter = priv->adapter;
435 lbs_deb_enter(LBS_DEB_WEXT);
437 if (vwrq->disabled) {
438 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
440 if (fthr < MRVDRV_FRAG_MIN_VALUE
441 || fthr > MRVDRV_FRAG_MAX_VALUE)
443 adapter->fragthsd = fthr;
446 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
447 cmd_act_set, cmd_option_waitforrsp,
448 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
450 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
454 static int wlan_get_frag(struct net_device *dev, struct iw_request_info *info,
455 struct iw_param *vwrq, char *extra)
458 wlan_private *priv = dev->priv;
459 wlan_adapter *adapter = priv->adapter;
461 lbs_deb_enter(LBS_DEB_WEXT);
463 adapter->fragthsd = 0;
464 ret = libertas_prepare_and_send_command(priv,
466 cmd_act_get, cmd_option_waitforrsp,
467 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
471 vwrq->value = adapter->fragthsd;
472 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
473 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
477 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
481 static int wlan_get_mode(struct net_device *dev,
482 struct iw_request_info *info, u32 * uwrq, char *extra)
484 wlan_private *priv = dev->priv;
485 wlan_adapter *adapter = priv->adapter;
487 lbs_deb_enter(LBS_DEB_WEXT);
489 *uwrq = adapter->mode;
491 lbs_deb_leave(LBS_DEB_WEXT);
495 static int wlan_get_txpow(struct net_device *dev,
496 struct iw_request_info *info,
497 struct iw_param *vwrq, char *extra)
500 wlan_private *priv = dev->priv;
501 wlan_adapter *adapter = priv->adapter;
503 lbs_deb_enter(LBS_DEB_WEXT);
505 ret = libertas_prepare_and_send_command(priv,
506 cmd_802_11_rf_tx_power,
507 cmd_act_tx_power_opt_get,
508 cmd_option_waitforrsp, 0, NULL);
513 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
514 vwrq->value = adapter->txpowerlevel;
516 if (adapter->radioon) {
518 vwrq->flags = IW_TXPOW_DBM;
524 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
528 static int wlan_set_retry(struct net_device *dev, struct iw_request_info *info,
529 struct iw_param *vwrq, char *extra)
532 wlan_private *priv = dev->priv;
533 wlan_adapter *adapter = priv->adapter;
535 lbs_deb_enter(LBS_DEB_WEXT);
537 if (vwrq->flags == IW_RETRY_LIMIT) {
538 /* The MAC has a 4-bit Total_Tx_Count register
539 Total_Tx_Count = 1 + Tx_Retry_Count */
540 #define TX_RETRY_MIN 0
541 #define TX_RETRY_MAX 14
542 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
545 /* Adding 1 to convert retry count to try count */
546 adapter->txretrycount = vwrq->value + 1;
548 ret = libertas_prepare_and_send_command(priv, cmd_802_11_snmp_mib,
550 cmd_option_waitforrsp,
551 OID_802_11_TX_RETRYCOUNT, NULL);
560 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
564 static int wlan_get_retry(struct net_device *dev, struct iw_request_info *info,
565 struct iw_param *vwrq, char *extra)
567 wlan_private *priv = dev->priv;
568 wlan_adapter *adapter = priv->adapter;
571 lbs_deb_enter(LBS_DEB_WEXT);
573 adapter->txretrycount = 0;
574 ret = libertas_prepare_and_send_command(priv,
576 cmd_act_get, cmd_option_waitforrsp,
577 OID_802_11_TX_RETRYCOUNT, NULL);
583 vwrq->flags = IW_RETRY_LIMIT;
584 /* Subtract 1 to convert try count to retry count */
585 vwrq->value = adapter->txretrycount - 1;
589 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
593 static inline void sort_channels(struct iw_freq *freq, int num)
598 for (i = 0; i < num; i++)
599 for (j = i + 1; j < num; j++)
600 if (freq[i].i > freq[j].i) {
604 freq[i].i = freq[j].i;
605 freq[i].m = freq[j].m;
615 Infra G(12) A(8) B(4) G(12)
616 Adhoc A+B(12) A(8) B(4) B(4)
624 * @brief Get Range Info
626 * @param dev A pointer to net_device structure
627 * @param info A pointer to iw_request_info structure
628 * @param vwrq A pointer to iw_param structure
629 * @param extra A pointer to extra data buf
630 * @return 0 --success, otherwise fail
632 static int wlan_get_range(struct net_device *dev, struct iw_request_info *info,
633 struct iw_point *dwrq, char *extra)
636 wlan_private *priv = dev->priv;
637 wlan_adapter *adapter = priv->adapter;
638 struct iw_range *range = (struct iw_range *)extra;
639 struct chan_freq_power *cfp;
640 u8 rates[WLAN_SUPPORTED_RATES];
644 lbs_deb_enter(LBS_DEB_WEXT);
646 dwrq->length = sizeof(struct iw_range);
647 memset(range, 0, sizeof(struct iw_range));
652 memset(rates, 0, sizeof(rates));
653 range->num_bitrates = get_active_data_rates(adapter, rates);
655 for (i = 0; i < min_t(__u8, range->num_bitrates, IW_MAX_BITRATES) && rates[i];
657 range->bitrate[i] = (rates[i] & 0x7f) * 500000;
659 range->num_bitrates = i;
660 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
661 range->num_bitrates);
663 range->num_frequency = 0;
664 if (priv->adapter->enable11d &&
665 adapter->connect_status == libertas_connected) {
669 struct parsed_region_chan_11d *parsed_region_chan =
670 &adapter->parsed_region_chan;
672 if (parsed_region_chan == NULL) {
673 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
676 band = parsed_region_chan->band;
677 lbs_deb_wext("band %d, nr_char %d\n", band,
678 parsed_region_chan->nr_chan);
680 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
681 && (i < parsed_region_chan->nr_chan); i++) {
682 chan_no = parsed_region_chan->chanpwr[i].chan;
683 lbs_deb_wext("chan_no %d\n", chan_no);
684 range->freq[range->num_frequency].i = (long)chan_no;
685 range->freq[range->num_frequency].m =
686 (long)libertas_chan_2_freq(chan_no, band) * 100000;
687 range->freq[range->num_frequency].e = 1;
688 range->num_frequency++;
693 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
694 && (j < sizeof(adapter->region_channel)
695 / sizeof(adapter->region_channel[0])); j++) {
696 cfp = adapter->region_channel[j].CFP;
697 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
698 && adapter->region_channel[j].valid
700 && (i < adapter->region_channel[j].nrcfp); i++) {
701 range->freq[range->num_frequency].i =
703 range->freq[range->num_frequency].m =
704 (long)cfp->freq * 100000;
705 range->freq[range->num_frequency].e = 1;
707 range->num_frequency++;
712 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
713 IW_MAX_FREQUENCIES, range->num_frequency);
715 range->num_channels = range->num_frequency;
717 sort_channels(&range->freq[0], range->num_frequency);
720 * Set an indication of the max TCP throughput in bit/s that we can
721 * expect using this interface
724 range->throughput = 5000 * 1000;
726 range->throughput = 1500 * 1000;
728 range->min_rts = MRVDRV_RTS_MIN_VALUE;
729 range->max_rts = MRVDRV_RTS_MAX_VALUE;
730 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
731 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
733 range->encoding_size[0] = 5;
734 range->encoding_size[1] = 13;
735 range->num_encoding_sizes = 2;
736 range->max_encoding_tokens = 4;
738 range->min_pmp = 1000000;
739 range->max_pmp = 120000000;
740 range->min_pmt = 1000;
741 range->max_pmt = 1000000;
742 range->pmp_flags = IW_POWER_PERIOD;
743 range->pmt_flags = IW_POWER_TIMEOUT;
744 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
747 * Minimum version we recommend
749 range->we_version_source = 15;
752 * Version we are compiled with
754 range->we_version_compiled = WIRELESS_EXT;
756 range->retry_capa = IW_RETRY_LIMIT;
757 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
759 range->min_retry = TX_RETRY_MIN;
760 range->max_retry = TX_RETRY_MAX;
763 * Set the qual, level and noise range values
765 range->max_qual.qual = 100;
766 range->max_qual.level = 0;
767 range->max_qual.noise = 0;
768 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
770 range->avg_qual.qual = 70;
771 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
772 range->avg_qual.level = 0;
773 range->avg_qual.noise = 0;
774 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
776 range->sensitivity = 0;
779 * Setup the supported power level ranges
781 memset(range->txpower, 0, sizeof(range->txpower));
782 range->txpower[0] = 5;
783 range->txpower[1] = 7;
784 range->txpower[2] = 9;
785 range->txpower[3] = 11;
786 range->txpower[4] = 13;
787 range->txpower[5] = 15;
788 range->txpower[6] = 17;
789 range->txpower[7] = 19;
791 range->num_txpower = 8;
792 range->txpower_capa = IW_TXPOW_DBM;
793 range->txpower_capa |= IW_TXPOW_RANGE;
795 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
796 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
797 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
798 range->event_capa[1] = IW_EVENT_CAPA_K_1;
800 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
801 range->enc_capa = IW_ENC_CAPA_WPA
803 | IW_ENC_CAPA_CIPHER_TKIP
804 | IW_ENC_CAPA_CIPHER_CCMP;
808 lbs_deb_leave(LBS_DEB_WEXT);
812 static int wlan_set_power(struct net_device *dev, struct iw_request_info *info,
813 struct iw_param *vwrq, char *extra)
815 wlan_private *priv = dev->priv;
816 wlan_adapter *adapter = priv->adapter;
818 lbs_deb_enter(LBS_DEB_WEXT);
820 /* PS is currently supported only in Infrastructure mode
821 * Remove this check if it is to be supported in IBSS mode also
824 if (vwrq->disabled) {
825 adapter->psmode = wlan802_11powermodecam;
826 if (adapter->psstate != PS_STATE_FULL_POWER) {
827 libertas_ps_wakeup(priv, cmd_option_waitforrsp);
833 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
835 "setting power timeout is not supported\n");
837 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
838 lbs_deb_wext("setting power period not supported\n");
842 if (adapter->psmode != wlan802_11powermodecam) {
846 adapter->psmode = wlan802_11powermodemax_psp;
848 if (adapter->connect_status == libertas_connected) {
849 libertas_ps_sleep(priv, cmd_option_waitforrsp);
852 lbs_deb_leave(LBS_DEB_WEXT);
856 static int wlan_get_power(struct net_device *dev, struct iw_request_info *info,
857 struct iw_param *vwrq, char *extra)
859 wlan_private *priv = dev->priv;
860 wlan_adapter *adapter = priv->adapter;
863 lbs_deb_enter(LBS_DEB_WEXT);
865 mode = adapter->psmode;
867 if ((vwrq->disabled = (mode == wlan802_11powermodecam))
868 || adapter->connect_status == libertas_disconnected)
876 lbs_deb_leave(LBS_DEB_WEXT);
881 * iwpriv settable callbacks
884 static const iw_handler wlan_private_handler[] = {
885 NULL, /* SIOCIWFIRSTPRIV */
888 static const struct iw_priv_args wlan_private_args[] = {
890 * { cmd, set_args, get_args, name }
892 /* Using iwpriv sub-command feature */
894 WLAN_SETONEINT_GETNONE, /* IOCTL: 24 */
895 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
900 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
904 WLAN_SUBCMD_MESH_SET_TTL,
905 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
909 WLAN_SETNONE_GETONEINT,
911 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
916 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
919 WLAN_SUBCMD_FWT_CLEANUP,
921 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
924 WLAN_SUBCMD_FWT_TIME,
926 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
929 WLAN_SUBCMD_MESH_GET_TTL,
931 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
934 WLAN_SETNONE_GETNONE,
939 WLAN_SUBCMD_FWT_RESET,
944 WLAN_SUBCMD_BT_RESET,
949 WLAN_SET128CHAR_GET128CHAR,
950 IW_PRIV_TYPE_CHAR | 128,
951 IW_PRIV_TYPE_CHAR | 128,
956 IW_PRIV_TYPE_CHAR | 128,
957 IW_PRIV_TYPE_CHAR | 128,
961 IW_PRIV_TYPE_CHAR | 128,
962 IW_PRIV_TYPE_CHAR | 128,
966 IW_PRIV_TYPE_CHAR | 128,
967 IW_PRIV_TYPE_CHAR | 128,
970 WLAN_SUBCMD_BT_SET_INVERT,
971 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
975 WLAN_SUBCMD_BT_GET_INVERT,
977 IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
982 IW_PRIV_TYPE_CHAR | 128,
983 IW_PRIV_TYPE_CHAR | 128,
987 IW_PRIV_TYPE_CHAR | 128,
988 IW_PRIV_TYPE_CHAR | 128,
991 WLAN_SUBCMD_FWT_LOOKUP,
992 IW_PRIV_TYPE_CHAR | 128,
993 IW_PRIV_TYPE_CHAR | 128,
996 WLAN_SUBCMD_FWT_LIST_NEIGHBOR,
997 IW_PRIV_TYPE_CHAR | 128,
998 IW_PRIV_TYPE_CHAR | 128,
1001 WLAN_SUBCMD_FWT_LIST,
1002 IW_PRIV_TYPE_CHAR | 128,
1003 IW_PRIV_TYPE_CHAR | 128,
1006 WLAN_SUBCMD_FWT_LIST_ROUTE,
1007 IW_PRIV_TYPE_CHAR | 128,
1008 IW_PRIV_TYPE_CHAR | 128,
1011 WLAN_SET_GET_SIXTEEN_INT,
1012 IW_PRIV_TYPE_INT | 16,
1013 IW_PRIV_TYPE_INT | 16,
1017 IW_PRIV_TYPE_INT | 16,
1018 IW_PRIV_TYPE_INT | 16,
1022 static struct iw_statistics *wlan_get_wireless_stats(struct net_device *dev)
1032 wlan_private *priv = dev->priv;
1033 wlan_adapter *adapter = priv->adapter;
1037 int stats_valid = 0;
1041 lbs_deb_enter(LBS_DEB_WEXT);
1043 priv->wstats.status = adapter->mode;
1045 /* If we're not associated, all quality values are meaningless */
1046 if (adapter->connect_status != libertas_connected)
1049 /* Quality by RSSI */
1050 priv->wstats.qual.level =
1051 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
1052 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1054 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
1055 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
1057 priv->wstats.qual.noise =
1058 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
1061 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
1062 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
1064 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
1066 rssi_qual = rssi * POOR / 10;
1068 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
1070 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
1072 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
1075 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
1077 quality = rssi_qual;
1079 /* Quality by TX errors */
1080 priv->wstats.discard.retries = priv->stats.tx_errors;
1082 tx_retries = adapter->logmsg.retry;
1084 if (tx_retries > 75)
1085 tx_qual = (90 - tx_retries) * POOR / 15;
1086 else if (tx_retries > 70)
1087 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
1088 else if (tx_retries > 65)
1089 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
1090 else if (tx_retries > 50)
1091 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
1094 tx_qual = (50 - tx_retries) *
1095 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
1096 quality = min(quality, tx_qual);
1098 priv->wstats.discard.code = adapter->logmsg.wepundecryptable;
1099 priv->wstats.discard.fragment = adapter->logmsg.rxfrag;
1100 priv->wstats.discard.retries = tx_retries;
1101 priv->wstats.discard.misc = adapter->logmsg.ackfailure;
1103 /* Calculate quality */
1104 priv->wstats.qual.qual = max(quality, (u32)100);
1105 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
1108 /* update stats asynchronously for future calls */
1109 libertas_prepare_and_send_command(priv, cmd_802_11_rssi, 0,
1111 libertas_prepare_and_send_command(priv, cmd_802_11_get_log, 0,
1115 priv->wstats.miss.beacon = 0;
1116 priv->wstats.discard.retries = 0;
1117 priv->wstats.qual.qual = 0;
1118 priv->wstats.qual.level = 0;
1119 priv->wstats.qual.noise = 0;
1120 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
1121 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
1122 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
1125 lbs_deb_leave(LBS_DEB_WEXT);
1126 return &priv->wstats;
1131 static int wlan_set_freq(struct net_device *dev, struct iw_request_info *info,
1132 struct iw_freq *fwrq, char *extra)
1135 wlan_private *priv = dev->priv;
1136 wlan_adapter *adapter = priv->adapter;
1137 struct chan_freq_power *cfp;
1138 struct assoc_request * assoc_req;
1140 lbs_deb_enter(LBS_DEB_WEXT);
1142 mutex_lock(&adapter->lock);
1143 assoc_req = wlan_get_association_request(adapter);
1149 /* If setting by frequency, convert to a channel */
1151 long f = fwrq->m / 100000;
1153 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
1155 lbs_deb_wext("invalid freq %ld\n", f);
1160 fwrq->m = (int) cfp->channel;
1163 /* Setting by channel number */
1164 if (fwrq->m > 1000 || fwrq->e > 0) {
1168 cfp = libertas_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
1173 assoc_req->channel = fwrq->m;
1178 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
1179 wlan_postpone_association_work(priv);
1181 wlan_cancel_association_work(priv);
1183 mutex_unlock(&adapter->lock);
1185 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1190 * @brief use index to get the data rate
1192 * @param index The index of data rate
1193 * @return data rate or 0
1195 u32 libertas_index_to_data_rate(u8 index)
1197 if (index >= sizeof(libertas_wlan_data_rates))
1200 return libertas_wlan_data_rates[index];
1204 * @brief use rate to get the index
1206 * @param rate data rate
1207 * @return index or 0
1209 u8 libertas_data_rate_to_index(u32 rate)
1214 if ((ptr = memchr(libertas_wlan_data_rates, (u8) rate,
1215 sizeof(libertas_wlan_data_rates))))
1216 return (ptr - libertas_wlan_data_rates);
1221 static int wlan_set_rate(struct net_device *dev, struct iw_request_info *info,
1222 struct iw_param *vwrq, char *extra)
1224 wlan_private *priv = dev->priv;
1225 wlan_adapter *adapter = priv->adapter;
1229 u8 rates[WLAN_SUPPORTED_RATES];
1232 lbs_deb_enter(LBS_DEB_WEXT);
1234 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
1236 if (vwrq->value == -1) {
1237 action = cmd_act_set_tx_auto; // Auto
1238 adapter->is_datarate_auto = 1;
1239 adapter->datarate = 0;
1241 if (vwrq->value % 100000) {
1245 data_rate = vwrq->value / 500000;
1247 memset(rates, 0, sizeof(rates));
1248 get_active_data_rates(adapter, rates);
1251 lbs_deb_wext("rate=0x%X, wanted data_rate 0x%X\n", *rate,
1253 if ((*rate & 0x7f) == (data_rate & 0x7f))
1258 lbs_pr_alert("fixed data rate 0x%X out "
1259 "of range\n", data_rate);
1263 adapter->datarate = data_rate;
1264 action = cmd_act_set_tx_fix_rate;
1265 adapter->is_datarate_auto = 0;
1268 ret = libertas_prepare_and_send_command(priv, cmd_802_11_data_rate,
1269 action, cmd_option_waitforrsp, 0, NULL);
1271 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1275 static int wlan_get_rate(struct net_device *dev, struct iw_request_info *info,
1276 struct iw_param *vwrq, char *extra)
1278 wlan_private *priv = dev->priv;
1279 wlan_adapter *adapter = priv->adapter;
1281 lbs_deb_enter(LBS_DEB_WEXT);
1283 if (adapter->is_datarate_auto) {
1289 vwrq->value = adapter->datarate * 500000;
1291 lbs_deb_leave(LBS_DEB_WEXT);
1295 static int wlan_set_mode(struct net_device *dev,
1296 struct iw_request_info *info, u32 * uwrq, char *extra)
1299 wlan_private *priv = dev->priv;
1300 wlan_adapter *adapter = priv->adapter;
1301 struct assoc_request * assoc_req;
1303 lbs_deb_enter(LBS_DEB_WEXT);
1305 if ( (*uwrq != IW_MODE_ADHOC)
1306 && (*uwrq != IW_MODE_INFRA)
1307 && (*uwrq != IW_MODE_AUTO)) {
1308 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1313 mutex_lock(&adapter->lock);
1314 assoc_req = wlan_get_association_request(adapter);
1317 wlan_cancel_association_work(priv);
1319 assoc_req->mode = *uwrq;
1320 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1321 wlan_postpone_association_work(priv);
1322 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1324 mutex_unlock(&adapter->lock);
1327 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1333 * @brief Get Encryption key
1335 * @param dev A pointer to net_device structure
1336 * @param info A pointer to iw_request_info structure
1337 * @param vwrq A pointer to iw_param structure
1338 * @param extra A pointer to extra data buf
1339 * @return 0 --success, otherwise fail
1341 static int wlan_get_encode(struct net_device *dev,
1342 struct iw_request_info *info,
1343 struct iw_point *dwrq, u8 * extra)
1345 wlan_private *priv = dev->priv;
1346 wlan_adapter *adapter = priv->adapter;
1347 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1349 lbs_deb_enter(LBS_DEB_WEXT);
1351 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1352 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1356 /* Authentication method */
1357 switch (adapter->secinfo.auth_mode) {
1358 case IW_AUTH_ALG_OPEN_SYSTEM:
1359 dwrq->flags = IW_ENCODE_OPEN;
1362 case IW_AUTH_ALG_SHARED_KEY:
1363 case IW_AUTH_ALG_LEAP:
1364 dwrq->flags = IW_ENCODE_RESTRICTED;
1367 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1371 if ( adapter->secinfo.wep_enabled
1372 || adapter->secinfo.WPAenabled
1373 || adapter->secinfo.WPA2enabled) {
1374 dwrq->flags &= ~IW_ENCODE_DISABLED;
1376 dwrq->flags |= IW_ENCODE_DISABLED;
1379 memset(extra, 0, 16);
1381 mutex_lock(&adapter->lock);
1383 /* Default to returning current transmit key */
1385 index = adapter->wep_tx_keyidx;
1387 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
1388 memcpy(extra, adapter->wep_keys[index].key,
1389 adapter->wep_keys[index].len);
1390 dwrq->length = adapter->wep_keys[index].len;
1392 dwrq->flags |= (index + 1);
1393 /* Return WEP enabled */
1394 dwrq->flags &= ~IW_ENCODE_DISABLED;
1395 } else if ((adapter->secinfo.WPAenabled)
1396 || (adapter->secinfo.WPA2enabled)) {
1397 /* return WPA enabled */
1398 dwrq->flags &= ~IW_ENCODE_DISABLED;
1400 dwrq->flags |= IW_ENCODE_DISABLED;
1403 mutex_unlock(&adapter->lock);
1405 dwrq->flags |= IW_ENCODE_NOKEY;
1407 lbs_deb_wext("key: " MAC_FMT ", keylen %d\n",
1408 extra[0], extra[1], extra[2],
1409 extra[3], extra[4], extra[5], dwrq->length);
1411 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1413 lbs_deb_leave(LBS_DEB_WEXT);
1418 * @brief Set Encryption key (internal)
1420 * @param priv A pointer to private card structure
1421 * @param key_material A pointer to key material
1422 * @param key_length length of key material
1423 * @param index key index to set
1424 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1425 * @return 0 --success, otherwise fail
1427 static int wlan_set_wep_key(struct assoc_request *assoc_req,
1428 const char *key_material,
1434 struct WLAN_802_11_KEY *pkey;
1436 lbs_deb_enter(LBS_DEB_WEXT);
1438 /* Paranoid validation of key index */
1444 /* validate max key length */
1445 if (key_length > KEY_LEN_WEP_104) {
1450 pkey = &assoc_req->wep_keys[index];
1452 if (key_length > 0) {
1453 memset(pkey, 0, sizeof(struct WLAN_802_11_KEY));
1454 pkey->type = KEY_TYPE_ID_WEP;
1456 /* Standardize the key length */
1457 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1458 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1459 memcpy(pkey->key, key_material, key_length);
1463 /* Ensure the chosen key is valid */
1465 lbs_deb_wext("key not set, so cannot enable it\n");
1469 assoc_req->wep_tx_keyidx = index;
1472 assoc_req->secinfo.wep_enabled = 1;
1475 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1479 static int validate_key_index(u16 def_index, u16 raw_index,
1480 u16 *out_index, u16 *is_default)
1482 if (!out_index || !is_default)
1485 /* Verify index if present, otherwise use default TX key index */
1486 if (raw_index > 0) {
1489 *out_index = raw_index - 1;
1491 *out_index = def_index;
1497 static void disable_wep(struct assoc_request *assoc_req)
1501 lbs_deb_enter(LBS_DEB_WEXT);
1503 /* Set Open System auth mode */
1504 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1506 /* Clear WEP keys and mark WEP as disabled */
1507 assoc_req->secinfo.wep_enabled = 0;
1508 for (i = 0; i < 4; i++)
1509 assoc_req->wep_keys[i].len = 0;
1511 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1512 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1514 lbs_deb_leave(LBS_DEB_WEXT);
1517 static void disable_wpa(struct assoc_request *assoc_req)
1519 lbs_deb_enter(LBS_DEB_WEXT);
1521 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct WLAN_802_11_KEY));
1522 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1523 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1525 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct WLAN_802_11_KEY));
1526 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1527 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1529 assoc_req->secinfo.WPAenabled = 0;
1530 assoc_req->secinfo.WPA2enabled = 0;
1531 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1533 lbs_deb_leave(LBS_DEB_WEXT);
1537 * @brief Set Encryption key
1539 * @param dev A pointer to net_device structure
1540 * @param info A pointer to iw_request_info structure
1541 * @param vwrq A pointer to iw_param structure
1542 * @param extra A pointer to extra data buf
1543 * @return 0 --success, otherwise fail
1545 static int wlan_set_encode(struct net_device *dev,
1546 struct iw_request_info *info,
1547 struct iw_point *dwrq, char *extra)
1550 wlan_private *priv = dev->priv;
1551 wlan_adapter *adapter = priv->adapter;
1552 struct assoc_request * assoc_req;
1553 u16 is_default = 0, index = 0, set_tx_key = 0;
1555 lbs_deb_enter(LBS_DEB_WEXT);
1557 mutex_lock(&adapter->lock);
1558 assoc_req = wlan_get_association_request(adapter);
1564 if (dwrq->flags & IW_ENCODE_DISABLED) {
1565 disable_wep (assoc_req);
1566 disable_wpa (assoc_req);
1570 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1571 (dwrq->flags & IW_ENCODE_INDEX),
1572 &index, &is_default);
1578 /* If WEP isn't enabled, or if there is no key data but a valid
1579 * index, set the TX key.
1581 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1584 ret = wlan_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1589 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1591 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1593 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1594 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1595 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1596 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1601 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1602 wlan_postpone_association_work(priv);
1604 wlan_cancel_association_work(priv);
1606 mutex_unlock(&adapter->lock);
1608 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1613 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1615 * @param dev A pointer to net_device structure
1616 * @param info A pointer to iw_request_info structure
1617 * @param vwrq A pointer to iw_param structure
1618 * @param extra A pointer to extra data buf
1619 * @return 0 on success, otherwise failure
1621 static int wlan_get_encodeext(struct net_device *dev,
1622 struct iw_request_info *info,
1623 struct iw_point *dwrq,
1627 wlan_private *priv = dev->priv;
1628 wlan_adapter *adapter = priv->adapter;
1629 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1630 int index, max_key_len;
1632 lbs_deb_enter(LBS_DEB_WEXT);
1634 max_key_len = dwrq->length - sizeof(*ext);
1635 if (max_key_len < 0)
1638 index = dwrq->flags & IW_ENCODE_INDEX;
1640 if (index < 1 || index > 4)
1644 index = adapter->wep_tx_keyidx;
1647 if (!ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY &&
1648 ext->alg != IW_ENCODE_ALG_WEP) {
1649 if (index != 0 || adapter->mode != IW_MODE_INFRA)
1653 dwrq->flags = index + 1;
1654 memset(ext, 0, sizeof(*ext));
1656 if ( !adapter->secinfo.wep_enabled
1657 && !adapter->secinfo.WPAenabled
1658 && !adapter->secinfo.WPA2enabled) {
1659 ext->alg = IW_ENCODE_ALG_NONE;
1661 dwrq->flags |= IW_ENCODE_DISABLED;
1665 if ( adapter->secinfo.wep_enabled
1666 && !adapter->secinfo.WPAenabled
1667 && !adapter->secinfo.WPA2enabled) {
1669 ext->alg = IW_ENCODE_ALG_WEP;
1670 ext->key_len = adapter->wep_keys[index].len;
1671 key = &adapter->wep_keys[index].key[0];
1672 } else if ( !adapter->secinfo.wep_enabled
1673 && (adapter->secinfo.WPAenabled ||
1674 adapter->secinfo.WPA2enabled)) {
1676 struct WLAN_802_11_KEY * pkey = NULL;
1678 if ( adapter->wpa_mcast_key.len
1679 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1680 pkey = &adapter->wpa_mcast_key;
1681 else if ( adapter->wpa_unicast_key.len
1682 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1683 pkey = &adapter->wpa_unicast_key;
1686 if (pkey->type == KEY_TYPE_ID_AES) {
1687 ext->alg = IW_ENCODE_ALG_CCMP;
1689 ext->alg = IW_ENCODE_ALG_TKIP;
1691 ext->key_len = pkey->len;
1692 key = &pkey->key[0];
1694 ext->alg = IW_ENCODE_ALG_TKIP;
1701 if (ext->key_len > max_key_len) {
1707 memcpy(ext->key, key, ext->key_len);
1709 dwrq->flags |= IW_ENCODE_NOKEY;
1710 dwrq->flags |= IW_ENCODE_ENABLED;
1715 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1720 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1722 * @param dev A pointer to net_device structure
1723 * @param info A pointer to iw_request_info structure
1724 * @param vwrq A pointer to iw_param structure
1725 * @param extra A pointer to extra data buf
1726 * @return 0 --success, otherwise fail
1728 static int wlan_set_encodeext(struct net_device *dev,
1729 struct iw_request_info *info,
1730 struct iw_point *dwrq,
1734 wlan_private *priv = dev->priv;
1735 wlan_adapter *adapter = priv->adapter;
1736 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1738 struct assoc_request * assoc_req;
1740 lbs_deb_enter(LBS_DEB_WEXT);
1742 mutex_lock(&adapter->lock);
1743 assoc_req = wlan_get_association_request(adapter);
1749 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1750 disable_wep (assoc_req);
1751 disable_wpa (assoc_req);
1752 } else if (alg == IW_ENCODE_ALG_WEP) {
1753 u16 is_default = 0, index, set_tx_key = 0;
1755 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1756 (dwrq->flags & IW_ENCODE_INDEX),
1757 &index, &is_default);
1761 /* If WEP isn't enabled, or if there is no key data but a valid
1762 * index, or if the set-TX-key flag was passed, set the TX key.
1764 if ( !assoc_req->secinfo.wep_enabled
1765 || (dwrq->length == 0 && !is_default)
1766 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1769 /* Copy key to driver */
1770 ret = wlan_set_wep_key (assoc_req, ext->key, ext->key_len, index,
1775 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1776 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1777 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1778 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1781 /* Mark the various WEP bits as modified */
1782 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1784 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1786 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1787 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1788 struct WLAN_802_11_KEY * pkey;
1790 /* validate key length */
1791 if (((alg == IW_ENCODE_ALG_TKIP)
1792 && (ext->key_len != KEY_LEN_WPA_TKIP))
1793 || ((alg == IW_ENCODE_ALG_CCMP)
1794 && (ext->key_len != KEY_LEN_WPA_AES))) {
1795 lbs_deb_wext("invalid size %d for key of alg"
1803 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1804 pkey = &assoc_req->wpa_mcast_key;
1805 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1807 pkey = &assoc_req->wpa_unicast_key;
1808 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1811 memset(pkey, 0, sizeof (struct WLAN_802_11_KEY));
1812 memcpy(pkey->key, ext->key, ext->key_len);
1813 pkey->len = ext->key_len;
1815 pkey->flags |= KEY_INFO_WPA_ENABLED;
1817 /* Do this after zeroing key structure */
1818 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1819 pkey->flags |= KEY_INFO_WPA_MCAST;
1821 pkey->flags |= KEY_INFO_WPA_UNICAST;
1824 if (alg == IW_ENCODE_ALG_TKIP) {
1825 pkey->type = KEY_TYPE_ID_TKIP;
1826 } else if (alg == IW_ENCODE_ALG_CCMP) {
1827 pkey->type = KEY_TYPE_ID_AES;
1833 /* If WPA isn't enabled yet, do that now */
1834 if ( assoc_req->secinfo.WPAenabled == 0
1835 && assoc_req->secinfo.WPA2enabled == 0) {
1836 assoc_req->secinfo.WPAenabled = 1;
1837 assoc_req->secinfo.WPA2enabled = 1;
1838 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1841 disable_wep (assoc_req);
1846 wlan_postpone_association_work(priv);
1848 wlan_cancel_association_work(priv);
1850 mutex_unlock(&adapter->lock);
1852 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1857 static int wlan_set_genie(struct net_device *dev,
1858 struct iw_request_info *info,
1859 struct iw_point *dwrq,
1862 wlan_private *priv = dev->priv;
1863 wlan_adapter *adapter = priv->adapter;
1865 struct assoc_request * assoc_req;
1867 lbs_deb_enter(LBS_DEB_WEXT);
1869 mutex_lock(&adapter->lock);
1870 assoc_req = wlan_get_association_request(adapter);
1876 if (dwrq->length > MAX_WPA_IE_LEN ||
1877 (dwrq->length && extra == NULL)) {
1883 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1884 assoc_req->wpa_ie_len = dwrq->length;
1886 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1887 assoc_req->wpa_ie_len = 0;
1892 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1893 wlan_postpone_association_work(priv);
1895 wlan_cancel_association_work(priv);
1897 mutex_unlock(&adapter->lock);
1899 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1903 static int wlan_get_genie(struct net_device *dev,
1904 struct iw_request_info *info,
1905 struct iw_point *dwrq,
1909 wlan_private *priv = dev->priv;
1910 wlan_adapter *adapter = priv->adapter;
1912 lbs_deb_enter(LBS_DEB_WEXT);
1914 if (adapter->wpa_ie_len == 0) {
1919 if (dwrq->length < adapter->wpa_ie_len) {
1924 dwrq->length = adapter->wpa_ie_len;
1925 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1928 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1933 static int wlan_set_auth(struct net_device *dev,
1934 struct iw_request_info *info,
1935 struct iw_param *dwrq,
1938 wlan_private *priv = dev->priv;
1939 wlan_adapter *adapter = priv->adapter;
1940 struct assoc_request * assoc_req;
1944 lbs_deb_enter(LBS_DEB_WEXT);
1946 mutex_lock(&adapter->lock);
1947 assoc_req = wlan_get_association_request(adapter);
1953 switch (dwrq->flags & IW_AUTH_INDEX) {
1954 case IW_AUTH_TKIP_COUNTERMEASURES:
1955 case IW_AUTH_CIPHER_PAIRWISE:
1956 case IW_AUTH_CIPHER_GROUP:
1957 case IW_AUTH_KEY_MGMT:
1958 case IW_AUTH_DROP_UNENCRYPTED:
1960 * libertas does not use these parameters
1964 case IW_AUTH_WPA_VERSION:
1965 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1966 assoc_req->secinfo.WPAenabled = 0;
1967 assoc_req->secinfo.WPA2enabled = 0;
1968 disable_wpa (assoc_req);
1970 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1971 assoc_req->secinfo.WPAenabled = 1;
1972 assoc_req->secinfo.wep_enabled = 0;
1973 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1975 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1976 assoc_req->secinfo.WPA2enabled = 1;
1977 assoc_req->secinfo.wep_enabled = 0;
1978 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1983 case IW_AUTH_80211_AUTH_ALG:
1984 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1985 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1986 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1987 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1988 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1989 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1996 case IW_AUTH_WPA_ENABLED:
1998 if (!assoc_req->secinfo.WPAenabled &&
1999 !assoc_req->secinfo.WPA2enabled) {
2000 assoc_req->secinfo.WPAenabled = 1;
2001 assoc_req->secinfo.WPA2enabled = 1;
2002 assoc_req->secinfo.wep_enabled = 0;
2003 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
2006 assoc_req->secinfo.WPAenabled = 0;
2007 assoc_req->secinfo.WPA2enabled = 0;
2008 disable_wpa (assoc_req);
2021 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
2022 wlan_postpone_association_work(priv);
2023 } else if (ret != -EOPNOTSUPP) {
2024 wlan_cancel_association_work(priv);
2026 mutex_unlock(&adapter->lock);
2028 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2032 static int wlan_get_auth(struct net_device *dev,
2033 struct iw_request_info *info,
2034 struct iw_param *dwrq,
2038 wlan_private *priv = dev->priv;
2039 wlan_adapter *adapter = priv->adapter;
2041 lbs_deb_enter(LBS_DEB_WEXT);
2043 switch (dwrq->flags & IW_AUTH_INDEX) {
2044 case IW_AUTH_WPA_VERSION:
2046 if (adapter->secinfo.WPAenabled)
2047 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
2048 if (adapter->secinfo.WPA2enabled)
2049 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
2051 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
2054 case IW_AUTH_80211_AUTH_ALG:
2055 dwrq->value = adapter->secinfo.auth_mode;
2058 case IW_AUTH_WPA_ENABLED:
2059 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
2067 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2072 static int wlan_set_txpow(struct net_device *dev, struct iw_request_info *info,
2073 struct iw_param *vwrq, char *extra)
2076 wlan_private *priv = dev->priv;
2077 wlan_adapter *adapter = priv->adapter;
2081 lbs_deb_enter(LBS_DEB_WEXT);
2083 if (vwrq->disabled) {
2084 wlan_radio_ioctl(priv, RADIO_OFF);
2088 adapter->preamble = cmd_type_auto_preamble;
2090 wlan_radio_ioctl(priv, RADIO_ON);
2092 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
2093 dbm = (u16) mw_to_dbm(vwrq->value);
2095 dbm = (u16) vwrq->value;
2097 /* auto tx power control */
2099 if (vwrq->fixed == 0)
2102 lbs_deb_wext("txpower set %d dbm\n", dbm);
2104 ret = libertas_prepare_and_send_command(priv,
2105 cmd_802_11_rf_tx_power,
2106 cmd_act_tx_power_opt_set_low,
2107 cmd_option_waitforrsp, 0, (void *)&dbm);
2109 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2113 static int wlan_get_essid(struct net_device *dev, struct iw_request_info *info,
2114 struct iw_point *dwrq, char *extra)
2116 wlan_private *priv = dev->priv;
2117 wlan_adapter *adapter = priv->adapter;
2119 lbs_deb_enter(LBS_DEB_WEXT);
2122 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2127 * Get the current SSID
2129 if (adapter->connect_status == libertas_connected) {
2130 memcpy(extra, adapter->curbssparams.ssid.ssid,
2131 adapter->curbssparams.ssid.ssidlength);
2132 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2134 memset(extra, 0, 32);
2135 extra[adapter->curbssparams.ssid.ssidlength] = '\0';
2138 * If none, we may want to get the one that was set
2141 /* To make the driver backward compatible with WPA supplicant v0.2.4 */
2142 if (dwrq->length == 32) /* check with WPA supplicant buffer size */
2143 dwrq->length = min_t(size_t, adapter->curbssparams.ssid.ssidlength,
2146 dwrq->length = adapter->curbssparams.ssid.ssidlength + 1;
2148 dwrq->flags = 1; /* active */
2150 lbs_deb_leave(LBS_DEB_WEXT);
2154 static int wlan_set_essid(struct net_device *dev, struct iw_request_info *info,
2155 struct iw_point *dwrq, char *extra)
2157 wlan_private *priv = dev->priv;
2158 wlan_adapter *adapter = priv->adapter;
2160 struct WLAN_802_11_SSID ssid;
2161 struct assoc_request * assoc_req;
2162 int ssid_len = dwrq->length;
2164 lbs_deb_enter(LBS_DEB_WEXT);
2167 * WE-20 and earlier NULL pad the end of the SSID and increment
2168 * SSID length so it can be used like a string. WE-21 and later don't,
2169 * but some userspace tools aren't able to cope with the change.
2171 if ((ssid_len > 0) && (extra[ssid_len - 1] == '\0'))
2174 /* Check the size of the string */
2175 if (ssid_len > IW_ESSID_MAX_SIZE) {
2180 memset(&ssid, 0, sizeof(struct WLAN_802_11_SSID));
2182 if (!dwrq->flags || !ssid_len) {
2183 /* "any" SSID requested; leave SSID blank */
2185 /* Specific SSID requested */
2186 memcpy(&ssid.ssid, extra, ssid_len);
2187 ssid.ssidlength = ssid_len;
2190 lbs_deb_wext("requested new SSID '%s'\n",
2191 (ssid.ssidlength > 0) ? (char *)ssid.ssid : "any");
2194 mutex_lock(&adapter->lock);
2196 /* Get or create the current association request */
2197 assoc_req = wlan_get_association_request(adapter);
2201 /* Copy the SSID to the association request */
2202 memcpy(&assoc_req->ssid, &ssid, sizeof(struct WLAN_802_11_SSID));
2203 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2204 wlan_postpone_association_work(priv);
2208 /* Cancel the association request if there was an error */
2210 wlan_cancel_association_work(priv);
2213 mutex_unlock(&adapter->lock);
2215 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2220 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2222 * @param dev A pointer to net_device structure
2223 * @param info A pointer to iw_request_info structure
2224 * @param awrq A pointer to iw_param structure
2225 * @param extra A pointer to extra data buf
2226 * @return 0 --success, otherwise fail
2228 static int wlan_set_wap(struct net_device *dev, struct iw_request_info *info,
2229 struct sockaddr *awrq, char *extra)
2231 wlan_private *priv = dev->priv;
2232 wlan_adapter *adapter = priv->adapter;
2233 struct assoc_request * assoc_req;
2236 lbs_deb_enter(LBS_DEB_WEXT);
2238 if (awrq->sa_family != ARPHRD_ETHER)
2241 lbs_deb_wext("ASSOC: WAP: sa_data " MAC_FMT "\n", MAC_ARG(awrq->sa_data));
2243 mutex_lock(&adapter->lock);
2245 /* Get or create the current association request */
2246 assoc_req = wlan_get_association_request(adapter);
2248 wlan_cancel_association_work(priv);
2251 /* Copy the BSSID to the association request */
2252 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2253 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2254 wlan_postpone_association_work(priv);
2257 mutex_unlock(&adapter->lock);
2262 void libertas_get_fwversion(wlan_adapter * adapter, char *fwversion, int maxlen)
2270 mutex_lock(&adapter->lock);
2271 ver.l = adapter->fwreleasenumber;
2272 mutex_unlock(&adapter->lock);
2275 sprintf(fwver, "%u.%u.%u", ver.c[2], ver.c[1], ver.c[0]);
2277 sprintf(fwver, "%u.%u.%u.p%u",
2278 ver.c[2], ver.c[1], ver.c[0], ver.c[3]);
2280 snprintf(fwversion, maxlen, fwver);
2285 * iwconfig settable callbacks
2287 static const iw_handler wlan_handler[] = {
2288 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2289 (iw_handler) wlan_get_name, /* SIOCGIWNAME */
2290 (iw_handler) NULL, /* SIOCSIWNWID */
2291 (iw_handler) NULL, /* SIOCGIWNWID */
2292 (iw_handler) wlan_set_freq, /* SIOCSIWFREQ */
2293 (iw_handler) wlan_get_freq, /* SIOCGIWFREQ */
2294 (iw_handler) wlan_set_mode, /* SIOCSIWMODE */
2295 (iw_handler) wlan_get_mode, /* SIOCGIWMODE */
2296 (iw_handler) NULL, /* SIOCSIWSENS */
2297 (iw_handler) NULL, /* SIOCGIWSENS */
2298 (iw_handler) NULL, /* SIOCSIWRANGE */
2299 (iw_handler) wlan_get_range, /* SIOCGIWRANGE */
2300 (iw_handler) NULL, /* SIOCSIWPRIV */
2301 (iw_handler) NULL, /* SIOCGIWPRIV */
2302 (iw_handler) NULL, /* SIOCSIWSTATS */
2303 (iw_handler) NULL, /* SIOCGIWSTATS */
2304 iw_handler_set_spy, /* SIOCSIWSPY */
2305 iw_handler_get_spy, /* SIOCGIWSPY */
2306 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2307 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2308 (iw_handler) wlan_set_wap, /* SIOCSIWAP */
2309 (iw_handler) wlan_get_wap, /* SIOCGIWAP */
2310 (iw_handler) NULL, /* SIOCSIWMLME */
2311 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2312 (iw_handler) libertas_set_scan, /* SIOCSIWSCAN */
2313 (iw_handler) libertas_get_scan, /* SIOCGIWSCAN */
2314 (iw_handler) wlan_set_essid, /* SIOCSIWESSID */
2315 (iw_handler) wlan_get_essid, /* SIOCGIWESSID */
2316 (iw_handler) wlan_set_nick, /* SIOCSIWNICKN */
2317 (iw_handler) wlan_get_nick, /* SIOCGIWNICKN */
2318 (iw_handler) NULL, /* -- hole -- */
2319 (iw_handler) NULL, /* -- hole -- */
2320 (iw_handler) wlan_set_rate, /* SIOCSIWRATE */
2321 (iw_handler) wlan_get_rate, /* SIOCGIWRATE */
2322 (iw_handler) wlan_set_rts, /* SIOCSIWRTS */
2323 (iw_handler) wlan_get_rts, /* SIOCGIWRTS */
2324 (iw_handler) wlan_set_frag, /* SIOCSIWFRAG */
2325 (iw_handler) wlan_get_frag, /* SIOCGIWFRAG */
2326 (iw_handler) wlan_set_txpow, /* SIOCSIWTXPOW */
2327 (iw_handler) wlan_get_txpow, /* SIOCGIWTXPOW */
2328 (iw_handler) wlan_set_retry, /* SIOCSIWRETRY */
2329 (iw_handler) wlan_get_retry, /* SIOCGIWRETRY */
2330 (iw_handler) wlan_set_encode, /* SIOCSIWENCODE */
2331 (iw_handler) wlan_get_encode, /* SIOCGIWENCODE */
2332 (iw_handler) wlan_set_power, /* SIOCSIWPOWER */
2333 (iw_handler) wlan_get_power, /* SIOCGIWPOWER */
2334 (iw_handler) NULL, /* -- hole -- */
2335 (iw_handler) NULL, /* -- hole -- */
2336 (iw_handler) wlan_set_genie, /* SIOCSIWGENIE */
2337 (iw_handler) wlan_get_genie, /* SIOCGIWGENIE */
2338 (iw_handler) wlan_set_auth, /* SIOCSIWAUTH */
2339 (iw_handler) wlan_get_auth, /* SIOCGIWAUTH */
2340 (iw_handler) wlan_set_encodeext,/* SIOCSIWENCODEEXT */
2341 (iw_handler) wlan_get_encodeext,/* SIOCGIWENCODEEXT */
2342 (iw_handler) NULL, /* SIOCSIWPMKSA */
2345 struct iw_handler_def libertas_handler_def = {
2346 .num_standard = sizeof(wlan_handler) / sizeof(iw_handler),
2347 .num_private = sizeof(wlan_private_handler) / sizeof(iw_handler),
2348 .num_private_args = sizeof(wlan_private_args) /
2349 sizeof(struct iw_priv_args),
2350 .standard = (iw_handler *) wlan_handler,
2351 .private = (iw_handler *) wlan_private_handler,
2352 .private_args = (struct iw_priv_args *)wlan_private_args,
2353 .get_wireless_stats = wlan_get_wireless_stats,