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>
24 static inline void lbs_postpone_association_work(struct lbs_private *priv)
26 if (priv->surpriseremoved)
28 cancel_delayed_work(&priv->assoc_work);
29 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
32 static inline void lbs_cancel_association_work(struct lbs_private *priv)
34 cancel_delayed_work(&priv->assoc_work);
35 kfree(priv->pending_assoc_req);
36 priv->pending_assoc_req = NULL;
41 * @brief Find the channel frequency power info with specific channel
43 * @param priv A pointer to struct lbs_private structure
44 * @param band it can be BAND_A, BAND_G or BAND_B
45 * @param channel the channel for looking
46 * @return A pointer to struct chan_freq_power structure or NULL if not find.
48 struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
49 struct lbs_private *priv,
53 struct chan_freq_power *cfp = NULL;
54 struct region_channel *rc;
57 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
58 rc = &priv->region_channel[j];
61 rc = &priv->universal_channel[j];
62 if (!rc->valid || !rc->CFP)
66 for (i = 0; i < rc->nrcfp; i++) {
67 if (rc->CFP[i].channel == channel) {
75 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
76 "cfp by band %d / channel %d\n", band, channel);
82 * @brief Find the channel frequency power info with specific frequency
84 * @param priv A pointer to struct lbs_private structure
85 * @param band it can be BAND_A, BAND_G or BAND_B
86 * @param freq the frequency for looking
87 * @return A pointer to struct chan_freq_power structure or NULL if not find.
89 static struct chan_freq_power *find_cfp_by_band_and_freq(
90 struct lbs_private *priv,
94 struct chan_freq_power *cfp = NULL;
95 struct region_channel *rc;
98 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
99 rc = &priv->region_channel[j];
102 rc = &priv->universal_channel[j];
103 if (!rc->valid || !rc->CFP)
105 if (rc->band != band)
107 for (i = 0; i < rc->nrcfp; i++) {
108 if (rc->CFP[i].freq == freq) {
116 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
117 "band %d / freq %d\n", band, freq);
124 * @brief Set Radio On/OFF
126 * @param priv A pointer to struct lbs_private structure
127 * @option Radio Option
128 * @return 0 --success, otherwise fail
130 static int lbs_radio_ioctl(struct lbs_private *priv, u8 option)
134 lbs_deb_enter(LBS_DEB_WEXT);
136 if (priv->radioon != option) {
137 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
138 priv->radioon = option;
140 ret = lbs_prepare_and_send_command(priv,
141 CMD_802_11_RADIO_CONTROL,
143 CMD_OPTION_WAITFORRSP, 0, NULL);
146 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
151 * @brief Copy active data rates based on adapter mode and status
153 * @param priv A pointer to struct lbs_private structure
154 * @param rate The buf to return the active rates
156 static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
158 lbs_deb_enter(LBS_DEB_WEXT);
160 if ((priv->connect_status != LBS_CONNECTED) &&
161 (priv->mesh_connect_status != LBS_CONNECTED))
162 memcpy(rates, lbs_bg_rates, MAX_RATES);
164 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
166 lbs_deb_leave(LBS_DEB_WEXT);
169 static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
170 char *cwrq, char *extra)
173 lbs_deb_enter(LBS_DEB_WEXT);
175 /* We could add support for 802.11n here as needed. Jean II */
176 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
178 lbs_deb_leave(LBS_DEB_WEXT);
182 static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
183 struct iw_freq *fwrq, char *extra)
185 struct lbs_private *priv = dev->priv;
186 struct chan_freq_power *cfp;
188 lbs_deb_enter(LBS_DEB_WEXT);
190 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
191 priv->curbssparams.channel);
194 if (priv->curbssparams.channel)
195 lbs_deb_wext("invalid channel %d\n",
196 priv->curbssparams.channel);
200 fwrq->m = (long)cfp->freq * 100000;
203 lbs_deb_wext("freq %u\n", fwrq->m);
204 lbs_deb_leave(LBS_DEB_WEXT);
208 static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
209 struct sockaddr *awrq, char *extra)
211 struct lbs_private *priv = dev->priv;
213 lbs_deb_enter(LBS_DEB_WEXT);
215 if (priv->connect_status == LBS_CONNECTED) {
216 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
218 memset(awrq->sa_data, 0, ETH_ALEN);
220 awrq->sa_family = ARPHRD_ETHER;
222 lbs_deb_leave(LBS_DEB_WEXT);
226 static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
227 struct iw_point *dwrq, char *extra)
229 struct lbs_private *priv = dev->priv;
231 lbs_deb_enter(LBS_DEB_WEXT);
234 * Check the size of the string
237 if (dwrq->length > 16) {
241 mutex_lock(&priv->lock);
242 memset(priv->nodename, 0, sizeof(priv->nodename));
243 memcpy(priv->nodename, extra, dwrq->length);
244 mutex_unlock(&priv->lock);
246 lbs_deb_leave(LBS_DEB_WEXT);
250 static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
251 struct iw_point *dwrq, char *extra)
253 struct lbs_private *priv = dev->priv;
255 lbs_deb_enter(LBS_DEB_WEXT);
257 dwrq->length = strlen(priv->nodename);
258 memcpy(extra, priv->nodename, dwrq->length);
259 extra[dwrq->length] = '\0';
261 dwrq->flags = 1; /* active */
263 lbs_deb_leave(LBS_DEB_WEXT);
267 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
268 struct iw_point *dwrq, char *extra)
270 struct lbs_private *priv = dev->priv;
272 lbs_deb_enter(LBS_DEB_WEXT);
274 /* Use nickname to indicate that mesh is on */
276 if (priv->mesh_connect_status == LBS_CONNECTED) {
277 strncpy(extra, "Mesh", 12);
279 dwrq->length = strlen(extra);
287 lbs_deb_leave(LBS_DEB_WEXT);
291 static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
292 struct iw_param *vwrq, char *extra)
295 struct lbs_private *priv = dev->priv;
296 u32 rthr = vwrq->value;
298 lbs_deb_enter(LBS_DEB_WEXT);
300 if (vwrq->disabled) {
301 priv->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
303 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
305 priv->rtsthsd = rthr;
308 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
309 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
310 OID_802_11_RTS_THRESHOLD, &rthr);
312 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
316 static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
317 struct iw_param *vwrq, char *extra)
320 struct lbs_private *priv = dev->priv;
322 lbs_deb_enter(LBS_DEB_WEXT);
325 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
326 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
327 OID_802_11_RTS_THRESHOLD, NULL);
331 vwrq->value = priv->rtsthsd;
332 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
333 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
337 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
341 static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
342 struct iw_param *vwrq, char *extra)
345 u32 fthr = vwrq->value;
346 struct lbs_private *priv = dev->priv;
348 lbs_deb_enter(LBS_DEB_WEXT);
350 if (vwrq->disabled) {
351 priv->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
353 if (fthr < MRVDRV_FRAG_MIN_VALUE
354 || fthr > MRVDRV_FRAG_MAX_VALUE)
356 priv->fragthsd = fthr;
359 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
360 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
361 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
363 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
367 static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
368 struct iw_param *vwrq, char *extra)
371 struct lbs_private *priv = dev->priv;
373 lbs_deb_enter(LBS_DEB_WEXT);
376 ret = lbs_prepare_and_send_command(priv,
378 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
379 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
383 vwrq->value = priv->fragthsd;
384 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
385 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
389 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
393 static int lbs_get_mode(struct net_device *dev,
394 struct iw_request_info *info, u32 * uwrq, char *extra)
396 struct lbs_private *priv = dev->priv;
398 lbs_deb_enter(LBS_DEB_WEXT);
402 lbs_deb_leave(LBS_DEB_WEXT);
406 static int mesh_wlan_get_mode(struct net_device *dev,
407 struct iw_request_info *info, u32 * uwrq,
410 lbs_deb_enter(LBS_DEB_WEXT);
412 *uwrq = IW_MODE_REPEAT ;
414 lbs_deb_leave(LBS_DEB_WEXT);
418 static int lbs_get_txpow(struct net_device *dev,
419 struct iw_request_info *info,
420 struct iw_param *vwrq, char *extra)
423 struct lbs_private *priv = dev->priv;
425 lbs_deb_enter(LBS_DEB_WEXT);
427 ret = lbs_prepare_and_send_command(priv,
428 CMD_802_11_RF_TX_POWER,
429 CMD_ACT_TX_POWER_OPT_GET,
430 CMD_OPTION_WAITFORRSP, 0, NULL);
435 lbs_deb_wext("tx power level %d dbm\n", priv->txpowerlevel);
436 vwrq->value = priv->txpowerlevel;
440 vwrq->flags = IW_TXPOW_DBM;
446 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
450 static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
451 struct iw_param *vwrq, char *extra)
454 struct lbs_private *priv = dev->priv;
456 lbs_deb_enter(LBS_DEB_WEXT);
458 if (vwrq->flags == IW_RETRY_LIMIT) {
459 /* The MAC has a 4-bit Total_Tx_Count register
460 Total_Tx_Count = 1 + Tx_Retry_Count */
461 #define TX_RETRY_MIN 0
462 #define TX_RETRY_MAX 14
463 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
466 /* Adding 1 to convert retry count to try count */
467 priv->txretrycount = vwrq->value + 1;
469 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
471 CMD_OPTION_WAITFORRSP,
472 OID_802_11_TX_RETRYCOUNT, NULL);
481 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
485 static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
486 struct iw_param *vwrq, char *extra)
488 struct lbs_private *priv = dev->priv;
491 lbs_deb_enter(LBS_DEB_WEXT);
493 priv->txretrycount = 0;
494 ret = lbs_prepare_and_send_command(priv,
496 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
497 OID_802_11_TX_RETRYCOUNT, NULL);
503 vwrq->flags = IW_RETRY_LIMIT;
504 /* Subtract 1 to convert try count to retry count */
505 vwrq->value = priv->txretrycount - 1;
509 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
513 static inline void sort_channels(struct iw_freq *freq, int num)
518 for (i = 0; i < num; i++)
519 for (j = i + 1; j < num; j++)
520 if (freq[i].i > freq[j].i) {
524 freq[i].i = freq[j].i;
525 freq[i].m = freq[j].m;
535 Infra G(12) A(8) B(4) G(12)
536 Adhoc A+B(12) A(8) B(4) B(4)
544 * @brief Get Range Info
546 * @param dev A pointer to net_device structure
547 * @param info A pointer to iw_request_info structure
548 * @param vwrq A pointer to iw_param structure
549 * @param extra A pointer to extra data buf
550 * @return 0 --success, otherwise fail
552 static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
553 struct iw_point *dwrq, char *extra)
556 struct lbs_private *priv = dev->priv;
557 struct iw_range *range = (struct iw_range *)extra;
558 struct chan_freq_power *cfp;
559 u8 rates[MAX_RATES + 1];
563 lbs_deb_enter(LBS_DEB_WEXT);
565 dwrq->length = sizeof(struct iw_range);
566 memset(range, 0, sizeof(struct iw_range));
571 memset(rates, 0, sizeof(rates));
572 copy_active_data_rates(priv, rates);
573 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
574 for (i = 0; i < range->num_bitrates; i++)
575 range->bitrate[i] = rates[i] * 500000;
576 range->num_bitrates = i;
577 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
578 range->num_bitrates);
580 range->num_frequency = 0;
581 if (priv->enable11d &&
582 (priv->connect_status == LBS_CONNECTED ||
583 priv->mesh_connect_status == LBS_CONNECTED)) {
587 struct parsed_region_chan_11d *parsed_region_chan =
588 &priv->parsed_region_chan;
590 if (parsed_region_chan == NULL) {
591 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
594 band = parsed_region_chan->band;
595 lbs_deb_wext("band %d, nr_char %d\n", band,
596 parsed_region_chan->nr_chan);
598 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
599 && (i < parsed_region_chan->nr_chan); i++) {
600 chan_no = parsed_region_chan->chanpwr[i].chan;
601 lbs_deb_wext("chan_no %d\n", chan_no);
602 range->freq[range->num_frequency].i = (long)chan_no;
603 range->freq[range->num_frequency].m =
604 (long)lbs_chan_2_freq(chan_no, band) * 100000;
605 range->freq[range->num_frequency].e = 1;
606 range->num_frequency++;
611 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
612 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
613 cfp = priv->region_channel[j].CFP;
614 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
615 && priv->region_channel[j].valid
617 && (i < priv->region_channel[j].nrcfp); i++) {
618 range->freq[range->num_frequency].i =
620 range->freq[range->num_frequency].m =
621 (long)cfp->freq * 100000;
622 range->freq[range->num_frequency].e = 1;
624 range->num_frequency++;
629 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
630 IW_MAX_FREQUENCIES, range->num_frequency);
632 range->num_channels = range->num_frequency;
634 sort_channels(&range->freq[0], range->num_frequency);
637 * Set an indication of the max TCP throughput in bit/s that we can
638 * expect using this interface
641 range->throughput = 5000 * 1000;
643 range->throughput = 1500 * 1000;
645 range->min_rts = MRVDRV_RTS_MIN_VALUE;
646 range->max_rts = MRVDRV_RTS_MAX_VALUE;
647 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
648 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
650 range->encoding_size[0] = 5;
651 range->encoding_size[1] = 13;
652 range->num_encoding_sizes = 2;
653 range->max_encoding_tokens = 4;
655 range->min_pmp = 1000000;
656 range->max_pmp = 120000000;
657 range->min_pmt = 1000;
658 range->max_pmt = 1000000;
659 range->pmp_flags = IW_POWER_PERIOD;
660 range->pmt_flags = IW_POWER_TIMEOUT;
661 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
664 * Minimum version we recommend
666 range->we_version_source = 15;
669 * Version we are compiled with
671 range->we_version_compiled = WIRELESS_EXT;
673 range->retry_capa = IW_RETRY_LIMIT;
674 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
676 range->min_retry = TX_RETRY_MIN;
677 range->max_retry = TX_RETRY_MAX;
680 * Set the qual, level and noise range values
682 range->max_qual.qual = 100;
683 range->max_qual.level = 0;
684 range->max_qual.noise = 0;
685 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
687 range->avg_qual.qual = 70;
688 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
689 range->avg_qual.level = 0;
690 range->avg_qual.noise = 0;
691 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
693 range->sensitivity = 0;
696 * Setup the supported power level ranges
698 memset(range->txpower, 0, sizeof(range->txpower));
699 range->txpower[0] = 5;
700 range->txpower[1] = 7;
701 range->txpower[2] = 9;
702 range->txpower[3] = 11;
703 range->txpower[4] = 13;
704 range->txpower[5] = 15;
705 range->txpower[6] = 17;
706 range->txpower[7] = 19;
708 range->num_txpower = 8;
709 range->txpower_capa = IW_TXPOW_DBM;
710 range->txpower_capa |= IW_TXPOW_RANGE;
712 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
713 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
714 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
715 range->event_capa[1] = IW_EVENT_CAPA_K_1;
717 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
718 range->enc_capa = IW_ENC_CAPA_WPA
720 | IW_ENC_CAPA_CIPHER_TKIP
721 | IW_ENC_CAPA_CIPHER_CCMP;
725 lbs_deb_leave(LBS_DEB_WEXT);
729 static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
730 struct iw_param *vwrq, char *extra)
732 struct lbs_private *priv = dev->priv;
734 lbs_deb_enter(LBS_DEB_WEXT);
736 /* PS is currently supported only in Infrastructure mode
737 * Remove this check if it is to be supported in IBSS mode also
740 if (vwrq->disabled) {
741 priv->psmode = LBS802_11POWERMODECAM;
742 if (priv->psstate != PS_STATE_FULL_POWER) {
743 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
749 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
751 "setting power timeout is not supported\n");
753 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
754 lbs_deb_wext("setting power period not supported\n");
758 if (priv->psmode != LBS802_11POWERMODECAM) {
762 priv->psmode = LBS802_11POWERMODEMAX_PSP;
764 if (priv->connect_status == LBS_CONNECTED) {
765 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
768 lbs_deb_leave(LBS_DEB_WEXT);
772 static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
773 struct iw_param *vwrq, char *extra)
775 struct lbs_private *priv = dev->priv;
778 lbs_deb_enter(LBS_DEB_WEXT);
782 if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
783 || priv->connect_status == LBS_DISCONNECTED)
791 lbs_deb_leave(LBS_DEB_WEXT);
795 static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
805 struct lbs_private *priv = dev->priv;
813 lbs_deb_enter(LBS_DEB_WEXT);
815 priv->wstats.status = priv->mode;
817 /* If we're not associated, all quality values are meaningless */
818 if ((priv->connect_status != LBS_CONNECTED) &&
819 (priv->mesh_connect_status != LBS_CONNECTED))
822 /* Quality by RSSI */
823 priv->wstats.qual.level =
824 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
825 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
827 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
828 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
830 priv->wstats.qual.noise =
831 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
834 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
835 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
837 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
839 rssi_qual = rssi * POOR / 10;
841 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
843 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
845 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
848 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
852 /* Quality by TX errors */
853 priv->wstats.discard.retries = priv->stats.tx_errors;
855 tx_retries = le32_to_cpu(priv->logmsg.retry);
858 tx_qual = (90 - tx_retries) * POOR / 15;
859 else if (tx_retries > 70)
860 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
861 else if (tx_retries > 65)
862 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
863 else if (tx_retries > 50)
864 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
867 tx_qual = (50 - tx_retries) *
868 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
869 quality = min(quality, tx_qual);
871 priv->wstats.discard.code = le32_to_cpu(priv->logmsg.wepundecryptable);
872 priv->wstats.discard.fragment = le32_to_cpu(priv->logmsg.rxfrag);
873 priv->wstats.discard.retries = tx_retries;
874 priv->wstats.discard.misc = le32_to_cpu(priv->logmsg.ackfailure);
876 /* Calculate quality */
877 priv->wstats.qual.qual = min_t(u8, quality, 100);
878 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
881 /* update stats asynchronously for future calls */
882 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
884 lbs_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
888 priv->wstats.miss.beacon = 0;
889 priv->wstats.discard.retries = 0;
890 priv->wstats.qual.qual = 0;
891 priv->wstats.qual.level = 0;
892 priv->wstats.qual.noise = 0;
893 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
894 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
895 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
898 lbs_deb_leave(LBS_DEB_WEXT);
899 return &priv->wstats;
904 static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
905 struct iw_freq *fwrq, char *extra)
908 struct lbs_private *priv = dev->priv;
909 struct chan_freq_power *cfp;
910 struct assoc_request * assoc_req;
912 lbs_deb_enter(LBS_DEB_WEXT);
914 mutex_lock(&priv->lock);
915 assoc_req = lbs_get_association_request(priv);
921 /* If setting by frequency, convert to a channel */
923 long f = fwrq->m / 100000;
925 cfp = find_cfp_by_band_and_freq(priv, 0, f);
927 lbs_deb_wext("invalid freq %ld\n", f);
932 fwrq->m = (int) cfp->channel;
935 /* Setting by channel number */
936 if (fwrq->m > 1000 || fwrq->e > 0) {
940 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
945 assoc_req->channel = fwrq->m;
950 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
951 lbs_postpone_association_work(priv);
953 lbs_cancel_association_work(priv);
955 mutex_unlock(&priv->lock);
957 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
961 static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
962 struct iw_param *vwrq, char *extra)
964 struct lbs_private *priv = dev->priv;
968 u8 rates[MAX_RATES + 1];
970 lbs_deb_enter(LBS_DEB_WEXT);
971 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
974 if (vwrq->value == -1) {
975 action = CMD_ACT_SET_TX_AUTO;
979 if (vwrq->value % 100000)
982 memset(rates, 0, sizeof(rates));
983 copy_active_data_rates(priv, rates);
984 new_rate = vwrq->value / 500000;
985 if (!memchr(rates, new_rate, sizeof(rates))) {
986 lbs_pr_alert("fixed data rate 0x%X out of range\n",
991 priv->cur_rate = new_rate;
992 action = CMD_ACT_SET_TX_FIX_RATE;
996 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
997 action, CMD_OPTION_WAITFORRSP, 0, NULL);
1000 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1004 static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
1005 struct iw_param *vwrq, char *extra)
1007 struct lbs_private *priv = dev->priv;
1009 lbs_deb_enter(LBS_DEB_WEXT);
1011 if (priv->connect_status == LBS_CONNECTED) {
1012 vwrq->value = priv->cur_rate * 500000;
1014 if (priv->auto_rate)
1024 lbs_deb_leave(LBS_DEB_WEXT);
1028 static int lbs_set_mode(struct net_device *dev,
1029 struct iw_request_info *info, u32 * uwrq, char *extra)
1032 struct lbs_private *priv = dev->priv;
1033 struct assoc_request * assoc_req;
1035 lbs_deb_enter(LBS_DEB_WEXT);
1037 if ( (*uwrq != IW_MODE_ADHOC)
1038 && (*uwrq != IW_MODE_INFRA)
1039 && (*uwrq != IW_MODE_AUTO)) {
1040 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1045 mutex_lock(&priv->lock);
1046 assoc_req = lbs_get_association_request(priv);
1049 lbs_cancel_association_work(priv);
1051 assoc_req->mode = *uwrq;
1052 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1053 lbs_postpone_association_work(priv);
1054 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1056 mutex_unlock(&priv->lock);
1059 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1065 * @brief Get Encryption key
1067 * @param dev A pointer to net_device structure
1068 * @param info A pointer to iw_request_info structure
1069 * @param vwrq A pointer to iw_param structure
1070 * @param extra A pointer to extra data buf
1071 * @return 0 --success, otherwise fail
1073 static int lbs_get_encode(struct net_device *dev,
1074 struct iw_request_info *info,
1075 struct iw_point *dwrq, u8 * extra)
1077 struct lbs_private *priv = dev->priv;
1078 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1080 lbs_deb_enter(LBS_DEB_WEXT);
1082 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1083 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
1087 /* Authentication method */
1088 switch (priv->secinfo.auth_mode) {
1089 case IW_AUTH_ALG_OPEN_SYSTEM:
1090 dwrq->flags = IW_ENCODE_OPEN;
1093 case IW_AUTH_ALG_SHARED_KEY:
1094 case IW_AUTH_ALG_LEAP:
1095 dwrq->flags = IW_ENCODE_RESTRICTED;
1098 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1102 memset(extra, 0, 16);
1104 mutex_lock(&priv->lock);
1106 /* Default to returning current transmit key */
1108 index = priv->wep_tx_keyidx;
1110 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1111 memcpy(extra, priv->wep_keys[index].key,
1112 priv->wep_keys[index].len);
1113 dwrq->length = priv->wep_keys[index].len;
1115 dwrq->flags |= (index + 1);
1116 /* Return WEP enabled */
1117 dwrq->flags &= ~IW_ENCODE_DISABLED;
1118 } else if ((priv->secinfo.WPAenabled)
1119 || (priv->secinfo.WPA2enabled)) {
1120 /* return WPA enabled */
1121 dwrq->flags &= ~IW_ENCODE_DISABLED;
1122 dwrq->flags |= IW_ENCODE_NOKEY;
1124 dwrq->flags |= IW_ENCODE_DISABLED;
1127 mutex_unlock(&priv->lock);
1129 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
1130 extra[0], extra[1], extra[2],
1131 extra[3], extra[4], extra[5], dwrq->length);
1133 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1135 lbs_deb_leave(LBS_DEB_WEXT);
1140 * @brief Set Encryption key (internal)
1142 * @param priv A pointer to private card structure
1143 * @param key_material A pointer to key material
1144 * @param key_length length of key material
1145 * @param index key index to set
1146 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1147 * @return 0 --success, otherwise fail
1149 static int lbs_set_wep_key(struct assoc_request *assoc_req,
1150 const char *key_material,
1156 struct enc_key *pkey;
1158 lbs_deb_enter(LBS_DEB_WEXT);
1160 /* Paranoid validation of key index */
1166 /* validate max key length */
1167 if (key_length > KEY_LEN_WEP_104) {
1172 pkey = &assoc_req->wep_keys[index];
1174 if (key_length > 0) {
1175 memset(pkey, 0, sizeof(struct enc_key));
1176 pkey->type = KEY_TYPE_ID_WEP;
1178 /* Standardize the key length */
1179 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1180 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1181 memcpy(pkey->key, key_material, key_length);
1185 /* Ensure the chosen key is valid */
1187 lbs_deb_wext("key not set, so cannot enable it\n");
1191 assoc_req->wep_tx_keyidx = index;
1194 assoc_req->secinfo.wep_enabled = 1;
1197 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1201 static int validate_key_index(u16 def_index, u16 raw_index,
1202 u16 *out_index, u16 *is_default)
1204 if (!out_index || !is_default)
1207 /* Verify index if present, otherwise use default TX key index */
1208 if (raw_index > 0) {
1211 *out_index = raw_index - 1;
1213 *out_index = def_index;
1219 static void disable_wep(struct assoc_request *assoc_req)
1223 lbs_deb_enter(LBS_DEB_WEXT);
1225 /* Set Open System auth mode */
1226 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1228 /* Clear WEP keys and mark WEP as disabled */
1229 assoc_req->secinfo.wep_enabled = 0;
1230 for (i = 0; i < 4; i++)
1231 assoc_req->wep_keys[i].len = 0;
1233 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1234 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1236 lbs_deb_leave(LBS_DEB_WEXT);
1239 static void disable_wpa(struct assoc_request *assoc_req)
1241 lbs_deb_enter(LBS_DEB_WEXT);
1243 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
1244 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1245 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1247 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
1248 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1249 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1251 assoc_req->secinfo.WPAenabled = 0;
1252 assoc_req->secinfo.WPA2enabled = 0;
1253 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1255 lbs_deb_leave(LBS_DEB_WEXT);
1259 * @brief Set Encryption key
1261 * @param dev A pointer to net_device structure
1262 * @param info A pointer to iw_request_info structure
1263 * @param vwrq A pointer to iw_param structure
1264 * @param extra A pointer to extra data buf
1265 * @return 0 --success, otherwise fail
1267 static int lbs_set_encode(struct net_device *dev,
1268 struct iw_request_info *info,
1269 struct iw_point *dwrq, char *extra)
1272 struct lbs_private *priv = dev->priv;
1273 struct assoc_request * assoc_req;
1274 u16 is_default = 0, index = 0, set_tx_key = 0;
1276 lbs_deb_enter(LBS_DEB_WEXT);
1278 mutex_lock(&priv->lock);
1279 assoc_req = lbs_get_association_request(priv);
1285 if (dwrq->flags & IW_ENCODE_DISABLED) {
1286 disable_wep (assoc_req);
1287 disable_wpa (assoc_req);
1291 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1292 (dwrq->flags & IW_ENCODE_INDEX),
1293 &index, &is_default);
1299 /* If WEP isn't enabled, or if there is no key data but a valid
1300 * index, set the TX key.
1302 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1305 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1310 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1312 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1314 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1315 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1316 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1317 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1322 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1323 lbs_postpone_association_work(priv);
1325 lbs_cancel_association_work(priv);
1327 mutex_unlock(&priv->lock);
1329 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1334 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1336 * @param dev A pointer to net_device structure
1337 * @param info A pointer to iw_request_info structure
1338 * @param vwrq A pointer to iw_param structure
1339 * @param extra A pointer to extra data buf
1340 * @return 0 on success, otherwise failure
1342 static int lbs_get_encodeext(struct net_device *dev,
1343 struct iw_request_info *info,
1344 struct iw_point *dwrq,
1348 struct lbs_private *priv = dev->priv;
1349 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1350 int index, max_key_len;
1352 lbs_deb_enter(LBS_DEB_WEXT);
1354 max_key_len = dwrq->length - sizeof(*ext);
1355 if (max_key_len < 0)
1358 index = dwrq->flags & IW_ENCODE_INDEX;
1360 if (index < 1 || index > 4)
1364 index = priv->wep_tx_keyidx;
1367 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
1368 ext->alg != IW_ENCODE_ALG_WEP) {
1369 if (index != 0 || priv->mode != IW_MODE_INFRA)
1373 dwrq->flags = index + 1;
1374 memset(ext, 0, sizeof(*ext));
1376 if ( !priv->secinfo.wep_enabled
1377 && !priv->secinfo.WPAenabled
1378 && !priv->secinfo.WPA2enabled) {
1379 ext->alg = IW_ENCODE_ALG_NONE;
1381 dwrq->flags |= IW_ENCODE_DISABLED;
1385 if ( priv->secinfo.wep_enabled
1386 && !priv->secinfo.WPAenabled
1387 && !priv->secinfo.WPA2enabled) {
1389 ext->alg = IW_ENCODE_ALG_WEP;
1390 ext->key_len = priv->wep_keys[index].len;
1391 key = &priv->wep_keys[index].key[0];
1392 } else if ( !priv->secinfo.wep_enabled
1393 && (priv->secinfo.WPAenabled ||
1394 priv->secinfo.WPA2enabled)) {
1396 struct enc_key * pkey = NULL;
1398 if ( priv->wpa_mcast_key.len
1399 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1400 pkey = &priv->wpa_mcast_key;
1401 else if ( priv->wpa_unicast_key.len
1402 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1403 pkey = &priv->wpa_unicast_key;
1406 if (pkey->type == KEY_TYPE_ID_AES) {
1407 ext->alg = IW_ENCODE_ALG_CCMP;
1409 ext->alg = IW_ENCODE_ALG_TKIP;
1411 ext->key_len = pkey->len;
1412 key = &pkey->key[0];
1414 ext->alg = IW_ENCODE_ALG_TKIP;
1421 if (ext->key_len > max_key_len) {
1427 memcpy(ext->key, key, ext->key_len);
1429 dwrq->flags |= IW_ENCODE_NOKEY;
1430 dwrq->flags |= IW_ENCODE_ENABLED;
1435 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1440 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1442 * @param dev A pointer to net_device structure
1443 * @param info A pointer to iw_request_info structure
1444 * @param vwrq A pointer to iw_param structure
1445 * @param extra A pointer to extra data buf
1446 * @return 0 --success, otherwise fail
1448 static int lbs_set_encodeext(struct net_device *dev,
1449 struct iw_request_info *info,
1450 struct iw_point *dwrq,
1454 struct lbs_private *priv = dev->priv;
1455 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1457 struct assoc_request * assoc_req;
1459 lbs_deb_enter(LBS_DEB_WEXT);
1461 mutex_lock(&priv->lock);
1462 assoc_req = lbs_get_association_request(priv);
1468 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1469 disable_wep (assoc_req);
1470 disable_wpa (assoc_req);
1471 } else if (alg == IW_ENCODE_ALG_WEP) {
1472 u16 is_default = 0, index, set_tx_key = 0;
1474 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1475 (dwrq->flags & IW_ENCODE_INDEX),
1476 &index, &is_default);
1480 /* If WEP isn't enabled, or if there is no key data but a valid
1481 * index, or if the set-TX-key flag was passed, set the TX key.
1483 if ( !assoc_req->secinfo.wep_enabled
1484 || (dwrq->length == 0 && !is_default)
1485 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1488 /* Copy key to driver */
1489 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
1494 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1495 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1496 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1497 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1500 /* Mark the various WEP bits as modified */
1501 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1503 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1505 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1506 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1507 struct enc_key * pkey;
1509 /* validate key length */
1510 if (((alg == IW_ENCODE_ALG_TKIP)
1511 && (ext->key_len != KEY_LEN_WPA_TKIP))
1512 || ((alg == IW_ENCODE_ALG_CCMP)
1513 && (ext->key_len != KEY_LEN_WPA_AES))) {
1514 lbs_deb_wext("invalid size %d for key of alg "
1522 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1523 pkey = &assoc_req->wpa_mcast_key;
1524 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1526 pkey = &assoc_req->wpa_unicast_key;
1527 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1530 memset(pkey, 0, sizeof (struct enc_key));
1531 memcpy(pkey->key, ext->key, ext->key_len);
1532 pkey->len = ext->key_len;
1534 pkey->flags |= KEY_INFO_WPA_ENABLED;
1536 /* Do this after zeroing key structure */
1537 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1538 pkey->flags |= KEY_INFO_WPA_MCAST;
1540 pkey->flags |= KEY_INFO_WPA_UNICAST;
1543 if (alg == IW_ENCODE_ALG_TKIP) {
1544 pkey->type = KEY_TYPE_ID_TKIP;
1545 } else if (alg == IW_ENCODE_ALG_CCMP) {
1546 pkey->type = KEY_TYPE_ID_AES;
1549 /* If WPA isn't enabled yet, do that now */
1550 if ( assoc_req->secinfo.WPAenabled == 0
1551 && assoc_req->secinfo.WPA2enabled == 0) {
1552 assoc_req->secinfo.WPAenabled = 1;
1553 assoc_req->secinfo.WPA2enabled = 1;
1554 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1557 disable_wep (assoc_req);
1562 lbs_postpone_association_work(priv);
1564 lbs_cancel_association_work(priv);
1566 mutex_unlock(&priv->lock);
1568 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1573 static int lbs_set_genie(struct net_device *dev,
1574 struct iw_request_info *info,
1575 struct iw_point *dwrq,
1578 struct lbs_private *priv = dev->priv;
1580 struct assoc_request * assoc_req;
1582 lbs_deb_enter(LBS_DEB_WEXT);
1584 mutex_lock(&priv->lock);
1585 assoc_req = lbs_get_association_request(priv);
1591 if (dwrq->length > MAX_WPA_IE_LEN ||
1592 (dwrq->length && extra == NULL)) {
1598 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1599 assoc_req->wpa_ie_len = dwrq->length;
1601 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
1602 assoc_req->wpa_ie_len = 0;
1607 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1608 lbs_postpone_association_work(priv);
1610 lbs_cancel_association_work(priv);
1612 mutex_unlock(&priv->lock);
1614 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1618 static int lbs_get_genie(struct net_device *dev,
1619 struct iw_request_info *info,
1620 struct iw_point *dwrq,
1624 struct lbs_private *priv = dev->priv;
1626 lbs_deb_enter(LBS_DEB_WEXT);
1628 if (priv->wpa_ie_len == 0) {
1633 if (dwrq->length < priv->wpa_ie_len) {
1638 dwrq->length = priv->wpa_ie_len;
1639 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
1642 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1647 static int lbs_set_auth(struct net_device *dev,
1648 struct iw_request_info *info,
1649 struct iw_param *dwrq,
1652 struct lbs_private *priv = dev->priv;
1653 struct assoc_request * assoc_req;
1657 lbs_deb_enter(LBS_DEB_WEXT);
1659 mutex_lock(&priv->lock);
1660 assoc_req = lbs_get_association_request(priv);
1666 switch (dwrq->flags & IW_AUTH_INDEX) {
1667 case IW_AUTH_TKIP_COUNTERMEASURES:
1668 case IW_AUTH_CIPHER_PAIRWISE:
1669 case IW_AUTH_CIPHER_GROUP:
1670 case IW_AUTH_KEY_MGMT:
1671 case IW_AUTH_DROP_UNENCRYPTED:
1673 * libertas does not use these parameters
1677 case IW_AUTH_WPA_VERSION:
1678 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1679 assoc_req->secinfo.WPAenabled = 0;
1680 assoc_req->secinfo.WPA2enabled = 0;
1681 disable_wpa (assoc_req);
1683 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1684 assoc_req->secinfo.WPAenabled = 1;
1685 assoc_req->secinfo.wep_enabled = 0;
1686 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1688 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1689 assoc_req->secinfo.WPA2enabled = 1;
1690 assoc_req->secinfo.wep_enabled = 0;
1691 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1696 case IW_AUTH_80211_AUTH_ALG:
1697 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1698 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1699 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1700 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1701 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1702 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1709 case IW_AUTH_WPA_ENABLED:
1711 if (!assoc_req->secinfo.WPAenabled &&
1712 !assoc_req->secinfo.WPA2enabled) {
1713 assoc_req->secinfo.WPAenabled = 1;
1714 assoc_req->secinfo.WPA2enabled = 1;
1715 assoc_req->secinfo.wep_enabled = 0;
1716 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1719 assoc_req->secinfo.WPAenabled = 0;
1720 assoc_req->secinfo.WPA2enabled = 0;
1721 disable_wpa (assoc_req);
1734 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1735 lbs_postpone_association_work(priv);
1736 } else if (ret != -EOPNOTSUPP) {
1737 lbs_cancel_association_work(priv);
1739 mutex_unlock(&priv->lock);
1741 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1745 static int lbs_get_auth(struct net_device *dev,
1746 struct iw_request_info *info,
1747 struct iw_param *dwrq,
1751 struct lbs_private *priv = dev->priv;
1753 lbs_deb_enter(LBS_DEB_WEXT);
1755 switch (dwrq->flags & IW_AUTH_INDEX) {
1756 case IW_AUTH_WPA_VERSION:
1758 if (priv->secinfo.WPAenabled)
1759 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1760 if (priv->secinfo.WPA2enabled)
1761 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1763 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1766 case IW_AUTH_80211_AUTH_ALG:
1767 dwrq->value = priv->secinfo.auth_mode;
1770 case IW_AUTH_WPA_ENABLED:
1771 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
1779 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1784 static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
1785 struct iw_param *vwrq, char *extra)
1788 struct lbs_private *priv = dev->priv;
1792 lbs_deb_enter(LBS_DEB_WEXT);
1794 if (vwrq->disabled) {
1795 lbs_radio_ioctl(priv, RADIO_OFF);
1799 priv->preamble = CMD_TYPE_AUTO_PREAMBLE;
1801 lbs_radio_ioctl(priv, RADIO_ON);
1803 /* Userspace check in iwrange if it should use dBm or mW,
1804 * therefore this should never happen... Jean II */
1805 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
1808 dbm = (u16) vwrq->value;
1810 /* auto tx power control */
1812 if (vwrq->fixed == 0)
1815 lbs_deb_wext("txpower set %d dbm\n", dbm);
1817 ret = lbs_prepare_and_send_command(priv,
1818 CMD_802_11_RF_TX_POWER,
1819 CMD_ACT_TX_POWER_OPT_SET_LOW,
1820 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
1822 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1826 static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
1827 struct iw_point *dwrq, char *extra)
1829 struct lbs_private *priv = dev->priv;
1831 lbs_deb_enter(LBS_DEB_WEXT);
1834 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1839 * Get the current SSID
1841 if (priv->connect_status == LBS_CONNECTED) {
1842 memcpy(extra, priv->curbssparams.ssid,
1843 priv->curbssparams.ssid_len);
1844 extra[priv->curbssparams.ssid_len] = '\0';
1846 memset(extra, 0, 32);
1847 extra[priv->curbssparams.ssid_len] = '\0';
1850 * If none, we may want to get the one that was set
1853 dwrq->length = priv->curbssparams.ssid_len;
1855 dwrq->flags = 1; /* active */
1857 lbs_deb_leave(LBS_DEB_WEXT);
1861 static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
1862 struct iw_point *dwrq, char *extra)
1864 struct lbs_private *priv = dev->priv;
1866 u8 ssid[IW_ESSID_MAX_SIZE];
1868 struct assoc_request * assoc_req;
1869 int in_ssid_len = dwrq->length;
1871 lbs_deb_enter(LBS_DEB_WEXT);
1873 /* Check the size of the string */
1874 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
1879 memset(&ssid, 0, sizeof(ssid));
1881 if (!dwrq->flags || !in_ssid_len) {
1882 /* "any" SSID requested; leave SSID blank */
1884 /* Specific SSID requested */
1885 memcpy(&ssid, extra, in_ssid_len);
1886 ssid_len = in_ssid_len;
1890 lbs_deb_wext("requested any SSID\n");
1892 lbs_deb_wext("requested SSID '%s'\n",
1893 escape_essid(ssid, ssid_len));
1897 mutex_lock(&priv->lock);
1899 /* Get or create the current association request */
1900 assoc_req = lbs_get_association_request(priv);
1904 /* Copy the SSID to the association request */
1905 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1906 assoc_req->ssid_len = ssid_len;
1907 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
1908 lbs_postpone_association_work(priv);
1912 /* Cancel the association request if there was an error */
1914 lbs_cancel_association_work(priv);
1917 mutex_unlock(&priv->lock);
1919 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1924 * @brief Connect to the AP or Ad-hoc Network with specific bssid
1926 * @param dev A pointer to net_device structure
1927 * @param info A pointer to iw_request_info structure
1928 * @param awrq A pointer to iw_param structure
1929 * @param extra A pointer to extra data buf
1930 * @return 0 --success, otherwise fail
1932 static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
1933 struct sockaddr *awrq, char *extra)
1935 struct lbs_private *priv = dev->priv;
1936 struct assoc_request * assoc_req;
1938 DECLARE_MAC_BUF(mac);
1940 lbs_deb_enter(LBS_DEB_WEXT);
1942 if (awrq->sa_family != ARPHRD_ETHER)
1945 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
1947 mutex_lock(&priv->lock);
1949 /* Get or create the current association request */
1950 assoc_req = lbs_get_association_request(priv);
1952 lbs_cancel_association_work(priv);
1955 /* Copy the BSSID to the association request */
1956 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
1957 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
1958 lbs_postpone_association_work(priv);
1961 mutex_unlock(&priv->lock);
1966 void lbs_get_fwversion(struct lbs_private *priv, char *fwversion, int maxlen)
1970 mutex_lock(&priv->lock);
1972 if (priv->fwreleasenumber[3] == 0)
1973 sprintf(fwver, "%u.%u.%u",
1974 priv->fwreleasenumber[2],
1975 priv->fwreleasenumber[1],
1976 priv->fwreleasenumber[0]);
1978 sprintf(fwver, "%u.%u.%u.p%u",
1979 priv->fwreleasenumber[2],
1980 priv->fwreleasenumber[1],
1981 priv->fwreleasenumber[0],
1982 priv->fwreleasenumber[3]);
1984 mutex_unlock(&priv->lock);
1985 snprintf(fwversion, maxlen, fwver);
1990 * iwconfig settable callbacks
1992 static const iw_handler lbs_handler[] = {
1993 (iw_handler) NULL, /* SIOCSIWCOMMIT */
1994 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
1995 (iw_handler) NULL, /* SIOCSIWNWID */
1996 (iw_handler) NULL, /* SIOCGIWNWID */
1997 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
1998 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
1999 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2000 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
2001 (iw_handler) NULL, /* SIOCSIWSENS */
2002 (iw_handler) NULL, /* SIOCGIWSENS */
2003 (iw_handler) NULL, /* SIOCSIWRANGE */
2004 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2005 (iw_handler) NULL, /* SIOCSIWPRIV */
2006 (iw_handler) NULL, /* SIOCGIWPRIV */
2007 (iw_handler) NULL, /* SIOCSIWSTATS */
2008 (iw_handler) NULL, /* SIOCGIWSTATS */
2009 iw_handler_set_spy, /* SIOCSIWSPY */
2010 iw_handler_get_spy, /* SIOCGIWSPY */
2011 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2012 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2013 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2014 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
2015 (iw_handler) NULL, /* SIOCSIWMLME */
2016 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2017 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2018 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2019 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2020 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2021 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2022 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
2023 (iw_handler) NULL, /* -- hole -- */
2024 (iw_handler) NULL, /* -- hole -- */
2025 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2026 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2027 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2028 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2029 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2030 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2031 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2032 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2033 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2034 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2035 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2036 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2037 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2038 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2039 (iw_handler) NULL, /* -- hole -- */
2040 (iw_handler) NULL, /* -- hole -- */
2041 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2042 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2043 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2044 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2045 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2046 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2047 (iw_handler) NULL, /* SIOCSIWPMKSA */
2050 static const iw_handler mesh_wlan_handler[] = {
2051 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2052 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2053 (iw_handler) NULL, /* SIOCSIWNWID */
2054 (iw_handler) NULL, /* SIOCGIWNWID */
2055 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2056 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2057 (iw_handler) NULL, /* SIOCSIWMODE */
2058 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2059 (iw_handler) NULL, /* SIOCSIWSENS */
2060 (iw_handler) NULL, /* SIOCGIWSENS */
2061 (iw_handler) NULL, /* SIOCSIWRANGE */
2062 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2063 (iw_handler) NULL, /* SIOCSIWPRIV */
2064 (iw_handler) NULL, /* SIOCGIWPRIV */
2065 (iw_handler) NULL, /* SIOCSIWSTATS */
2066 (iw_handler) NULL, /* SIOCGIWSTATS */
2067 iw_handler_set_spy, /* SIOCSIWSPY */
2068 iw_handler_get_spy, /* SIOCGIWSPY */
2069 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2070 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2071 (iw_handler) NULL, /* SIOCSIWAP */
2072 (iw_handler) NULL, /* SIOCGIWAP */
2073 (iw_handler) NULL, /* SIOCSIWMLME */
2074 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2075 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2076 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2077 (iw_handler) NULL, /* SIOCSIWESSID */
2078 (iw_handler) NULL, /* SIOCGIWESSID */
2079 (iw_handler) NULL, /* SIOCSIWNICKN */
2080 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2081 (iw_handler) NULL, /* -- hole -- */
2082 (iw_handler) NULL, /* -- hole -- */
2083 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2084 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2085 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2086 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2087 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2088 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2089 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2090 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2091 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2092 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2093 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2094 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2095 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2096 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2097 (iw_handler) NULL, /* -- hole -- */
2098 (iw_handler) NULL, /* -- hole -- */
2099 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2100 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2101 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2102 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2103 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2104 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2105 (iw_handler) NULL, /* SIOCSIWPMKSA */
2107 struct iw_handler_def lbs_handler_def = {
2108 .num_standard = ARRAY_SIZE(lbs_handler),
2109 .standard = (iw_handler *) lbs_handler,
2110 .get_wireless_stats = lbs_get_wireless_stats,
2113 struct iw_handler_def mesh_handler_def = {
2114 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
2115 .standard = (iw_handler *) mesh_wlan_handler,
2116 .get_wireless_stats = lbs_get_wireless_stats,