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/lib80211.h>
12 #include <net/iw_handler.h>
25 static inline void lbs_postpone_association_work(struct lbs_private *priv)
27 if (priv->surpriseremoved)
29 cancel_delayed_work(&priv->assoc_work);
30 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
33 static inline void lbs_do_association_work(struct lbs_private *priv)
35 if (priv->surpriseremoved)
37 cancel_delayed_work(&priv->assoc_work);
38 queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
41 static inline void lbs_cancel_association_work(struct lbs_private *priv)
43 cancel_delayed_work(&priv->assoc_work);
44 kfree(priv->pending_assoc_req);
45 priv->pending_assoc_req = NULL;
49 * @brief Find the channel frequency power info with specific channel
51 * @param priv A pointer to struct lbs_private structure
52 * @param band it can be BAND_A, BAND_G or BAND_B
53 * @param channel the channel for looking
54 * @return A pointer to struct chan_freq_power structure or NULL if not find.
56 struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
57 struct lbs_private *priv,
61 struct chan_freq_power *cfp = NULL;
62 struct region_channel *rc;
65 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
66 rc = &priv->region_channel[j];
69 rc = &priv->universal_channel[j];
70 if (!rc->valid || !rc->CFP)
74 for (i = 0; i < rc->nrcfp; i++) {
75 if (rc->CFP[i].channel == channel) {
83 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
84 "cfp by band %d / channel %d\n", band, channel);
90 * @brief Find the channel frequency power info with specific frequency
92 * @param priv A pointer to struct lbs_private structure
93 * @param band it can be BAND_A, BAND_G or BAND_B
94 * @param freq the frequency for looking
95 * @return A pointer to struct chan_freq_power structure or NULL if not find.
97 static struct chan_freq_power *find_cfp_by_band_and_freq(
98 struct lbs_private *priv,
102 struct chan_freq_power *cfp = NULL;
103 struct region_channel *rc;
106 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
107 rc = &priv->region_channel[j];
110 rc = &priv->universal_channel[j];
111 if (!rc->valid || !rc->CFP)
113 if (rc->band != band)
115 for (i = 0; i < rc->nrcfp; i++) {
116 if (rc->CFP[i].freq == freq) {
124 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
125 "band %d / freq %d\n", band, freq);
131 * @brief Copy active data rates based on adapter mode and status
133 * @param priv A pointer to struct lbs_private structure
134 * @param rate The buf to return the active rates
136 static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
138 lbs_deb_enter(LBS_DEB_WEXT);
140 if ((priv->connect_status != LBS_CONNECTED) &&
141 (priv->mesh_connect_status != LBS_CONNECTED))
142 memcpy(rates, lbs_bg_rates, MAX_RATES);
144 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
146 lbs_deb_leave(LBS_DEB_WEXT);
149 static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
150 char *cwrq, char *extra)
153 lbs_deb_enter(LBS_DEB_WEXT);
155 /* We could add support for 802.11n here as needed. Jean II */
156 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
158 lbs_deb_leave(LBS_DEB_WEXT);
162 static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
163 struct iw_freq *fwrq, char *extra)
165 struct lbs_private *priv = dev->ml_priv;
166 struct chan_freq_power *cfp;
168 lbs_deb_enter(LBS_DEB_WEXT);
170 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
171 priv->curbssparams.channel);
174 if (priv->curbssparams.channel)
175 lbs_deb_wext("invalid channel %d\n",
176 priv->curbssparams.channel);
180 fwrq->m = (long)cfp->freq * 100000;
183 lbs_deb_wext("freq %u\n", fwrq->m);
184 lbs_deb_leave(LBS_DEB_WEXT);
188 static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
189 struct sockaddr *awrq, char *extra)
191 struct lbs_private *priv = dev->ml_priv;
193 lbs_deb_enter(LBS_DEB_WEXT);
195 if (priv->connect_status == LBS_CONNECTED) {
196 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
198 memset(awrq->sa_data, 0, ETH_ALEN);
200 awrq->sa_family = ARPHRD_ETHER;
202 lbs_deb_leave(LBS_DEB_WEXT);
206 static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
207 struct iw_point *dwrq, char *extra)
209 struct lbs_private *priv = dev->ml_priv;
211 lbs_deb_enter(LBS_DEB_WEXT);
214 * Check the size of the string
217 if (dwrq->length > 16) {
221 mutex_lock(&priv->lock);
222 memset(priv->nodename, 0, sizeof(priv->nodename));
223 memcpy(priv->nodename, extra, dwrq->length);
224 mutex_unlock(&priv->lock);
226 lbs_deb_leave(LBS_DEB_WEXT);
230 static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
231 struct iw_point *dwrq, char *extra)
233 struct lbs_private *priv = dev->ml_priv;
235 lbs_deb_enter(LBS_DEB_WEXT);
237 dwrq->length = strlen(priv->nodename);
238 memcpy(extra, priv->nodename, dwrq->length);
239 extra[dwrq->length] = '\0';
241 dwrq->flags = 1; /* active */
243 lbs_deb_leave(LBS_DEB_WEXT);
247 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
248 struct iw_point *dwrq, char *extra)
250 struct lbs_private *priv = dev->ml_priv;
252 lbs_deb_enter(LBS_DEB_WEXT);
254 /* Use nickname to indicate that mesh is on */
256 if (priv->mesh_connect_status == LBS_CONNECTED) {
257 strncpy(extra, "Mesh", 12);
259 dwrq->length = strlen(extra);
267 lbs_deb_leave(LBS_DEB_WEXT);
271 static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
272 struct iw_param *vwrq, char *extra)
275 struct lbs_private *priv = dev->ml_priv;
276 u32 val = vwrq->value;
278 lbs_deb_enter(LBS_DEB_WEXT);
281 val = MRVDRV_RTS_MAX_VALUE;
283 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
286 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
288 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
292 static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
293 struct iw_param *vwrq, char *extra)
295 struct lbs_private *priv = dev->ml_priv;
299 lbs_deb_enter(LBS_DEB_WEXT);
301 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
306 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
310 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
314 static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
315 struct iw_param *vwrq, char *extra)
317 struct lbs_private *priv = dev->ml_priv;
319 u32 val = vwrq->value;
321 lbs_deb_enter(LBS_DEB_WEXT);
324 val = MRVDRV_FRAG_MAX_VALUE;
326 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
329 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
331 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
335 static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
336 struct iw_param *vwrq, char *extra)
338 struct lbs_private *priv = dev->ml_priv;
342 lbs_deb_enter(LBS_DEB_WEXT);
344 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
349 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
350 || (val > MRVDRV_FRAG_MAX_VALUE));
354 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
358 static int lbs_get_mode(struct net_device *dev,
359 struct iw_request_info *info, u32 * uwrq, char *extra)
361 struct lbs_private *priv = dev->ml_priv;
363 lbs_deb_enter(LBS_DEB_WEXT);
367 lbs_deb_leave(LBS_DEB_WEXT);
371 static int mesh_wlan_get_mode(struct net_device *dev,
372 struct iw_request_info *info, u32 * uwrq,
375 lbs_deb_enter(LBS_DEB_WEXT);
377 *uwrq = IW_MODE_REPEAT;
379 lbs_deb_leave(LBS_DEB_WEXT);
383 static int lbs_get_txpow(struct net_device *dev,
384 struct iw_request_info *info,
385 struct iw_param *vwrq, char *extra)
387 struct lbs_private *priv = dev->ml_priv;
391 lbs_deb_enter(LBS_DEB_WEXT);
393 if (!priv->radio_on) {
394 lbs_deb_wext("tx power off\n");
400 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
404 lbs_deb_wext("tx power level %d dbm\n", curlevel);
405 priv->txpower_cur = curlevel;
407 vwrq->value = curlevel;
410 vwrq->flags = IW_TXPOW_DBM;
413 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
417 static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
418 struct iw_param *vwrq, char *extra)
420 struct lbs_private *priv = dev->ml_priv;
422 u16 slimit = 0, llimit = 0;
424 lbs_deb_enter(LBS_DEB_WEXT);
426 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
429 /* The MAC has a 4-bit Total_Tx_Count register
430 Total_Tx_Count = 1 + Tx_Retry_Count */
431 #define TX_RETRY_MIN 0
432 #define TX_RETRY_MAX 14
433 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
436 /* Add 1 to convert retry count to try count */
437 if (vwrq->flags & IW_RETRY_SHORT)
438 slimit = (u16) (vwrq->value + 1);
439 else if (vwrq->flags & IW_RETRY_LONG)
440 llimit = (u16) (vwrq->value + 1);
442 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
445 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
452 /* txretrycount follows the short retry limit */
453 priv->txretrycount = slimit;
454 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
461 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
465 static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
466 struct iw_param *vwrq, char *extra)
468 struct lbs_private *priv = dev->ml_priv;
472 lbs_deb_enter(LBS_DEB_WEXT);
476 if (vwrq->flags & IW_RETRY_LONG) {
477 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
481 /* Subtract 1 to convert try count to retry count */
482 vwrq->value = val - 1;
483 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
485 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
489 /* txretry count follows the short retry limit */
490 priv->txretrycount = val;
491 /* Subtract 1 to convert try count to retry count */
492 vwrq->value = val - 1;
493 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
497 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
501 static inline void sort_channels(struct iw_freq *freq, int num)
506 for (i = 0; i < num; i++)
507 for (j = i + 1; j < num; j++)
508 if (freq[i].i > freq[j].i) {
512 freq[i].i = freq[j].i;
513 freq[i].m = freq[j].m;
523 Infra G(12) A(8) B(4) G(12)
524 Adhoc A+B(12) A(8) B(4) B(4)
532 * @brief Get Range Info
534 * @param dev A pointer to net_device structure
535 * @param info A pointer to iw_request_info structure
536 * @param vwrq A pointer to iw_param structure
537 * @param extra A pointer to extra data buf
538 * @return 0 --success, otherwise fail
540 static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
541 struct iw_point *dwrq, char *extra)
544 struct lbs_private *priv = dev->ml_priv;
545 struct iw_range *range = (struct iw_range *)extra;
546 struct chan_freq_power *cfp;
547 u8 rates[MAX_RATES + 1];
551 lbs_deb_enter(LBS_DEB_WEXT);
553 dwrq->length = sizeof(struct iw_range);
554 memset(range, 0, sizeof(struct iw_range));
559 memset(rates, 0, sizeof(rates));
560 copy_active_data_rates(priv, rates);
561 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
562 for (i = 0; i < range->num_bitrates; i++)
563 range->bitrate[i] = rates[i] * 500000;
564 range->num_bitrates = i;
565 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
566 range->num_bitrates);
568 range->num_frequency = 0;
570 range->scan_capa = IW_SCAN_CAPA_ESSID;
572 if (priv->enable11d &&
573 (priv->connect_status == LBS_CONNECTED ||
574 priv->mesh_connect_status == LBS_CONNECTED)) {
578 struct parsed_region_chan_11d *parsed_region_chan =
579 &priv->parsed_region_chan;
581 if (parsed_region_chan == NULL) {
582 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
585 band = parsed_region_chan->band;
586 lbs_deb_wext("band %d, nr_char %d\n", band,
587 parsed_region_chan->nr_chan);
589 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
590 && (i < parsed_region_chan->nr_chan); i++) {
591 chan_no = parsed_region_chan->chanpwr[i].chan;
592 lbs_deb_wext("chan_no %d\n", chan_no);
593 range->freq[range->num_frequency].i = (long)chan_no;
594 range->freq[range->num_frequency].m =
595 (long)lbs_chan_2_freq(chan_no) * 100000;
596 range->freq[range->num_frequency].e = 1;
597 range->num_frequency++;
602 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
603 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
604 cfp = priv->region_channel[j].CFP;
605 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
606 && priv->region_channel[j].valid
608 && (i < priv->region_channel[j].nrcfp); i++) {
609 range->freq[range->num_frequency].i =
611 range->freq[range->num_frequency].m =
612 (long)cfp->freq * 100000;
613 range->freq[range->num_frequency].e = 1;
615 range->num_frequency++;
620 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
621 IW_MAX_FREQUENCIES, range->num_frequency);
623 range->num_channels = range->num_frequency;
625 sort_channels(&range->freq[0], range->num_frequency);
628 * Set an indication of the max TCP throughput in bit/s that we can
629 * expect using this interface
632 range->throughput = 5000 * 1000;
634 range->throughput = 1500 * 1000;
636 range->min_rts = MRVDRV_RTS_MIN_VALUE;
637 range->max_rts = MRVDRV_RTS_MAX_VALUE;
638 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
639 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
641 range->encoding_size[0] = 5;
642 range->encoding_size[1] = 13;
643 range->num_encoding_sizes = 2;
644 range->max_encoding_tokens = 4;
647 * Right now we support only "iwconfig ethX power on|off"
649 range->pm_capa = IW_POWER_ON;
652 * Minimum version we recommend
654 range->we_version_source = 15;
657 * Version we are compiled with
659 range->we_version_compiled = WIRELESS_EXT;
661 range->retry_capa = IW_RETRY_LIMIT;
662 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
664 range->min_retry = TX_RETRY_MIN;
665 range->max_retry = TX_RETRY_MAX;
668 * Set the qual, level and noise range values
670 range->max_qual.qual = 100;
671 range->max_qual.level = 0;
672 range->max_qual.noise = 0;
673 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
675 range->avg_qual.qual = 70;
676 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
677 range->avg_qual.level = 0;
678 range->avg_qual.noise = 0;
679 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
681 range->sensitivity = 0;
683 /* Setup the supported power level ranges */
684 memset(range->txpower, 0, sizeof(range->txpower));
685 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
686 range->txpower[0] = priv->txpower_min;
687 range->txpower[1] = priv->txpower_max;
688 range->num_txpower = 2;
690 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
691 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
692 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
693 range->event_capa[1] = IW_EVENT_CAPA_K_1;
695 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
696 range->enc_capa = IW_ENC_CAPA_WPA
698 | IW_ENC_CAPA_CIPHER_TKIP
699 | IW_ENC_CAPA_CIPHER_CCMP;
703 lbs_deb_leave(LBS_DEB_WEXT);
707 static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
708 struct iw_param *vwrq, char *extra)
710 struct lbs_private *priv = dev->ml_priv;
713 lbs_deb_enter(LBS_DEB_WEXT);
715 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
722 /* PS is currently supported only in Infrastructure mode
723 * Remove this check if it is to be supported in IBSS mode also
726 if (vwrq->disabled) {
727 priv->psmode = LBS802_11POWERMODECAM;
728 if (priv->psstate != PS_STATE_FULL_POWER) {
729 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
735 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
737 "setting power timeout is not supported\n");
739 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
740 vwrq->value = vwrq->value / 1000;
741 if (!priv->enter_deep_sleep) {
742 lbs_pr_err("deep sleep feature is not implemented "
743 "for this interface driver\n");
747 if (priv->connect_status == LBS_CONNECTED) {
748 if ((priv->is_auto_deep_sleep_enabled) &&
749 (vwrq->value == -1000)) {
750 lbs_exit_auto_deep_sleep(priv);
753 lbs_pr_err("can't use deep sleep cmd in "
754 "connected state\n");
759 if ((vwrq->value < 0) && (vwrq->value != -1000)) {
760 lbs_pr_err("unknown option\n");
764 if (vwrq->value > 0) {
765 if (!priv->is_auto_deep_sleep_enabled) {
766 priv->is_activity_detected = 0;
767 priv->auto_deep_sleep_timeout = vwrq->value;
768 lbs_enter_auto_deep_sleep(priv);
770 priv->auto_deep_sleep_timeout = vwrq->value;
771 lbs_deb_debugfs("auto deep sleep: "
772 "already enabled\n");
776 if (priv->is_auto_deep_sleep_enabled) {
777 lbs_exit_auto_deep_sleep(priv);
778 /* Try to exit deep sleep if auto */
779 /*deep sleep disabled */
780 ret = lbs_set_deep_sleep(priv, 0);
782 if (vwrq->value == 0)
783 ret = lbs_set_deep_sleep(priv, 1);
784 else if (vwrq->value == -1000)
785 ret = lbs_set_deep_sleep(priv, 0);
790 if (priv->psmode != LBS802_11POWERMODECAM) {
794 priv->psmode = LBS802_11POWERMODEMAX_PSP;
796 if (priv->connect_status == LBS_CONNECTED) {
797 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
800 lbs_deb_leave(LBS_DEB_WEXT);
805 static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
806 struct iw_param *vwrq, char *extra)
808 struct lbs_private *priv = dev->ml_priv;
810 lbs_deb_enter(LBS_DEB_WEXT);
814 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
815 || priv->connect_status == LBS_DISCONNECTED;
817 lbs_deb_leave(LBS_DEB_WEXT);
821 static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
831 struct lbs_private *priv = dev->ml_priv;
835 int ret, stats_valid = 0;
838 struct cmd_ds_802_11_get_log log;
840 lbs_deb_enter(LBS_DEB_WEXT);
842 priv->wstats.status = priv->mode;
844 /* If we're not associated, all quality values are meaningless */
845 if ((priv->connect_status != LBS_CONNECTED) &&
846 (priv->mesh_connect_status != LBS_CONNECTED))
849 /* Quality by RSSI */
850 priv->wstats.qual.level =
851 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
852 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
854 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
855 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
857 priv->wstats.qual.noise =
858 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
861 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
862 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
864 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
866 rssi_qual = rssi * POOR / 10;
868 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
870 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
872 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
875 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
879 /* Quality by TX errors */
880 priv->wstats.discard.retries = dev->stats.tx_errors;
882 memset(&log, 0, sizeof(log));
883 log.hdr.size = cpu_to_le16(sizeof(log));
884 ret = lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
888 tx_retries = le32_to_cpu(log.retry);
891 tx_qual = (90 - tx_retries) * POOR / 15;
892 else if (tx_retries > 70)
893 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
894 else if (tx_retries > 65)
895 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
896 else if (tx_retries > 50)
897 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
900 tx_qual = (50 - tx_retries) *
901 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
902 quality = min(quality, tx_qual);
904 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
905 priv->wstats.discard.retries = tx_retries;
906 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
908 /* Calculate quality */
909 priv->wstats.qual.qual = min_t(u8, quality, 100);
910 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
913 /* update stats asynchronously for future calls */
914 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
917 lbs_pr_err("RSSI command failed\n");
920 priv->wstats.miss.beacon = 0;
921 priv->wstats.discard.retries = 0;
922 priv->wstats.qual.qual = 0;
923 priv->wstats.qual.level = 0;
924 priv->wstats.qual.noise = 0;
925 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
926 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
927 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
930 lbs_deb_leave(LBS_DEB_WEXT);
931 return &priv->wstats;
936 static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
937 struct iw_freq *fwrq, char *extra)
940 struct lbs_private *priv = dev->ml_priv;
941 struct chan_freq_power *cfp;
942 struct assoc_request * assoc_req;
944 lbs_deb_enter(LBS_DEB_WEXT);
946 mutex_lock(&priv->lock);
947 assoc_req = lbs_get_association_request(priv);
953 /* If setting by frequency, convert to a channel */
955 long f = fwrq->m / 100000;
957 cfp = find_cfp_by_band_and_freq(priv, 0, f);
959 lbs_deb_wext("invalid freq %ld\n", f);
964 fwrq->m = (int) cfp->channel;
967 /* Setting by channel number */
968 if (fwrq->m > 1000 || fwrq->e > 0) {
972 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
977 assoc_req->channel = fwrq->m;
982 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
983 lbs_postpone_association_work(priv);
985 lbs_cancel_association_work(priv);
987 mutex_unlock(&priv->lock);
989 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
993 static int lbs_mesh_set_freq(struct net_device *dev,
994 struct iw_request_info *info,
995 struct iw_freq *fwrq, char *extra)
997 struct lbs_private *priv = dev->ml_priv;
998 struct chan_freq_power *cfp;
1001 lbs_deb_enter(LBS_DEB_WEXT);
1003 /* If setting by frequency, convert to a channel */
1005 long f = fwrq->m / 100000;
1007 cfp = find_cfp_by_band_and_freq(priv, 0, f);
1009 lbs_deb_wext("invalid freq %ld\n", f);
1014 fwrq->m = (int) cfp->channel;
1017 /* Setting by channel number */
1018 if (fwrq->m > 1000 || fwrq->e > 0) {
1022 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
1027 if (fwrq->m != priv->curbssparams.channel) {
1028 lbs_deb_wext("mesh channel change forces eth disconnect\n");
1029 if (priv->mode == IW_MODE_INFRA)
1030 lbs_cmd_80211_deauthenticate(priv,
1031 priv->curbssparams.bssid,
1032 WLAN_REASON_DEAUTH_LEAVING);
1033 else if (priv->mode == IW_MODE_ADHOC)
1034 lbs_adhoc_stop(priv);
1036 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
1037 lbs_update_channel(priv);
1041 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1045 static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
1046 struct iw_param *vwrq, char *extra)
1048 struct lbs_private *priv = dev->ml_priv;
1051 u8 rates[MAX_RATES + 1];
1053 lbs_deb_enter(LBS_DEB_WEXT);
1055 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
1056 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1058 if (vwrq->fixed && vwrq->value == -1)
1062 priv->enablehwauto = !vwrq->fixed;
1064 if (vwrq->value == -1)
1067 if (vwrq->value % 100000)
1070 new_rate = vwrq->value / 500000;
1071 priv->cur_rate = new_rate;
1072 /* the rest is only needed for lbs_set_data_rate() */
1073 memset(rates, 0, sizeof(rates));
1074 copy_active_data_rates(priv, rates);
1075 if (!memchr(rates, new_rate, sizeof(rates))) {
1076 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1080 if (priv->fwrelease < 0x09000000) {
1081 ret = lbs_set_power_adapt_cfg(priv, 0,
1082 POW_ADAPT_DEFAULT_P0,
1083 POW_ADAPT_DEFAULT_P1,
1084 POW_ADAPT_DEFAULT_P2);
1088 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1094 /* Try the newer command first (Firmware Spec 5.1 and above) */
1095 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1097 /* Fallback to older version */
1099 ret = lbs_set_data_rate(priv, new_rate);
1102 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1106 static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
1107 struct iw_param *vwrq, char *extra)
1109 struct lbs_private *priv = dev->ml_priv;
1111 lbs_deb_enter(LBS_DEB_WEXT);
1113 if (priv->connect_status == LBS_CONNECTED) {
1114 vwrq->value = priv->cur_rate * 500000;
1116 if (priv->enablehwauto)
1126 lbs_deb_leave(LBS_DEB_WEXT);
1130 static int lbs_set_mode(struct net_device *dev,
1131 struct iw_request_info *info, u32 * uwrq, char *extra)
1134 struct lbs_private *priv = dev->ml_priv;
1135 struct assoc_request * assoc_req;
1137 lbs_deb_enter(LBS_DEB_WEXT);
1139 if ( (*uwrq != IW_MODE_ADHOC)
1140 && (*uwrq != IW_MODE_INFRA)
1141 && (*uwrq != IW_MODE_AUTO)) {
1142 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1147 mutex_lock(&priv->lock);
1148 assoc_req = lbs_get_association_request(priv);
1151 lbs_cancel_association_work(priv);
1153 assoc_req->mode = *uwrq;
1154 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1155 lbs_postpone_association_work(priv);
1156 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1158 mutex_unlock(&priv->lock);
1161 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1167 * @brief Get Encryption key
1169 * @param dev A pointer to net_device structure
1170 * @param info A pointer to iw_request_info structure
1171 * @param vwrq A pointer to iw_param structure
1172 * @param extra A pointer to extra data buf
1173 * @return 0 --success, otherwise fail
1175 static int lbs_get_encode(struct net_device *dev,
1176 struct iw_request_info *info,
1177 struct iw_point *dwrq, u8 * extra)
1179 struct lbs_private *priv = dev->ml_priv;
1180 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1182 lbs_deb_enter(LBS_DEB_WEXT);
1184 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1185 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
1189 /* Authentication method */
1190 switch (priv->secinfo.auth_mode) {
1191 case IW_AUTH_ALG_OPEN_SYSTEM:
1192 dwrq->flags = IW_ENCODE_OPEN;
1195 case IW_AUTH_ALG_SHARED_KEY:
1196 case IW_AUTH_ALG_LEAP:
1197 dwrq->flags = IW_ENCODE_RESTRICTED;
1200 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1204 memset(extra, 0, 16);
1206 mutex_lock(&priv->lock);
1208 /* Default to returning current transmit key */
1210 index = priv->wep_tx_keyidx;
1212 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1213 memcpy(extra, priv->wep_keys[index].key,
1214 priv->wep_keys[index].len);
1215 dwrq->length = priv->wep_keys[index].len;
1217 dwrq->flags |= (index + 1);
1218 /* Return WEP enabled */
1219 dwrq->flags &= ~IW_ENCODE_DISABLED;
1220 } else if ((priv->secinfo.WPAenabled)
1221 || (priv->secinfo.WPA2enabled)) {
1222 /* return WPA enabled */
1223 dwrq->flags &= ~IW_ENCODE_DISABLED;
1224 dwrq->flags |= IW_ENCODE_NOKEY;
1226 dwrq->flags |= IW_ENCODE_DISABLED;
1229 mutex_unlock(&priv->lock);
1231 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
1232 extra[0], extra[1], extra[2],
1233 extra[3], extra[4], extra[5], dwrq->length);
1235 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1237 lbs_deb_leave(LBS_DEB_WEXT);
1242 * @brief Set Encryption key (internal)
1244 * @param priv A pointer to private card structure
1245 * @param key_material A pointer to key material
1246 * @param key_length length of key material
1247 * @param index key index to set
1248 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1249 * @return 0 --success, otherwise fail
1251 static int lbs_set_wep_key(struct assoc_request *assoc_req,
1252 const char *key_material,
1258 struct enc_key *pkey;
1260 lbs_deb_enter(LBS_DEB_WEXT);
1262 /* Paranoid validation of key index */
1268 /* validate max key length */
1269 if (key_length > KEY_LEN_WEP_104) {
1274 pkey = &assoc_req->wep_keys[index];
1276 if (key_length > 0) {
1277 memset(pkey, 0, sizeof(struct enc_key));
1278 pkey->type = KEY_TYPE_ID_WEP;
1280 /* Standardize the key length */
1281 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1282 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1283 memcpy(pkey->key, key_material, key_length);
1287 /* Ensure the chosen key is valid */
1289 lbs_deb_wext("key not set, so cannot enable it\n");
1293 assoc_req->wep_tx_keyidx = index;
1296 assoc_req->secinfo.wep_enabled = 1;
1299 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1303 static int validate_key_index(u16 def_index, u16 raw_index,
1304 u16 *out_index, u16 *is_default)
1306 if (!out_index || !is_default)
1309 /* Verify index if present, otherwise use default TX key index */
1310 if (raw_index > 0) {
1313 *out_index = raw_index - 1;
1315 *out_index = def_index;
1321 static void disable_wep(struct assoc_request *assoc_req)
1325 lbs_deb_enter(LBS_DEB_WEXT);
1327 /* Set Open System auth mode */
1328 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1330 /* Clear WEP keys and mark WEP as disabled */
1331 assoc_req->secinfo.wep_enabled = 0;
1332 for (i = 0; i < 4; i++)
1333 assoc_req->wep_keys[i].len = 0;
1335 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1336 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1338 lbs_deb_leave(LBS_DEB_WEXT);
1341 static void disable_wpa(struct assoc_request *assoc_req)
1343 lbs_deb_enter(LBS_DEB_WEXT);
1345 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
1346 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1347 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1349 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
1350 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1351 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1353 assoc_req->secinfo.WPAenabled = 0;
1354 assoc_req->secinfo.WPA2enabled = 0;
1355 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1357 lbs_deb_leave(LBS_DEB_WEXT);
1361 * @brief Set Encryption key
1363 * @param dev A pointer to net_device structure
1364 * @param info A pointer to iw_request_info structure
1365 * @param vwrq A pointer to iw_param structure
1366 * @param extra A pointer to extra data buf
1367 * @return 0 --success, otherwise fail
1369 static int lbs_set_encode(struct net_device *dev,
1370 struct iw_request_info *info,
1371 struct iw_point *dwrq, char *extra)
1374 struct lbs_private *priv = dev->ml_priv;
1375 struct assoc_request * assoc_req;
1376 u16 is_default = 0, index = 0, set_tx_key = 0;
1378 lbs_deb_enter(LBS_DEB_WEXT);
1380 mutex_lock(&priv->lock);
1381 assoc_req = lbs_get_association_request(priv);
1387 if (dwrq->flags & IW_ENCODE_DISABLED) {
1388 disable_wep (assoc_req);
1389 disable_wpa (assoc_req);
1393 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1394 (dwrq->flags & IW_ENCODE_INDEX),
1395 &index, &is_default);
1401 /* If WEP isn't enabled, or if there is no key data but a valid
1402 * index, set the TX key.
1404 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1407 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1412 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1414 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1416 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1417 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1418 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1419 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1424 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1425 lbs_postpone_association_work(priv);
1427 lbs_cancel_association_work(priv);
1429 mutex_unlock(&priv->lock);
1431 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1436 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1438 * @param dev A pointer to net_device structure
1439 * @param info A pointer to iw_request_info structure
1440 * @param vwrq A pointer to iw_param structure
1441 * @param extra A pointer to extra data buf
1442 * @return 0 on success, otherwise failure
1444 static int lbs_get_encodeext(struct net_device *dev,
1445 struct iw_request_info *info,
1446 struct iw_point *dwrq,
1450 struct lbs_private *priv = dev->ml_priv;
1451 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1452 int index, max_key_len;
1454 lbs_deb_enter(LBS_DEB_WEXT);
1456 max_key_len = dwrq->length - sizeof(*ext);
1457 if (max_key_len < 0)
1460 index = dwrq->flags & IW_ENCODE_INDEX;
1462 if (index < 1 || index > 4)
1466 index = priv->wep_tx_keyidx;
1469 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
1470 ext->alg != IW_ENCODE_ALG_WEP) {
1471 if (index != 0 || priv->mode != IW_MODE_INFRA)
1475 dwrq->flags = index + 1;
1476 memset(ext, 0, sizeof(*ext));
1478 if ( !priv->secinfo.wep_enabled
1479 && !priv->secinfo.WPAenabled
1480 && !priv->secinfo.WPA2enabled) {
1481 ext->alg = IW_ENCODE_ALG_NONE;
1483 dwrq->flags |= IW_ENCODE_DISABLED;
1487 if ( priv->secinfo.wep_enabled
1488 && !priv->secinfo.WPAenabled
1489 && !priv->secinfo.WPA2enabled) {
1491 ext->alg = IW_ENCODE_ALG_WEP;
1492 ext->key_len = priv->wep_keys[index].len;
1493 key = &priv->wep_keys[index].key[0];
1494 } else if ( !priv->secinfo.wep_enabled
1495 && (priv->secinfo.WPAenabled ||
1496 priv->secinfo.WPA2enabled)) {
1498 struct enc_key * pkey = NULL;
1500 if ( priv->wpa_mcast_key.len
1501 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1502 pkey = &priv->wpa_mcast_key;
1503 else if ( priv->wpa_unicast_key.len
1504 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1505 pkey = &priv->wpa_unicast_key;
1508 if (pkey->type == KEY_TYPE_ID_AES) {
1509 ext->alg = IW_ENCODE_ALG_CCMP;
1511 ext->alg = IW_ENCODE_ALG_TKIP;
1513 ext->key_len = pkey->len;
1514 key = &pkey->key[0];
1516 ext->alg = IW_ENCODE_ALG_TKIP;
1523 if (ext->key_len > max_key_len) {
1529 memcpy(ext->key, key, ext->key_len);
1531 dwrq->flags |= IW_ENCODE_NOKEY;
1532 dwrq->flags |= IW_ENCODE_ENABLED;
1537 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1542 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1544 * @param dev A pointer to net_device structure
1545 * @param info A pointer to iw_request_info structure
1546 * @param vwrq A pointer to iw_param structure
1547 * @param extra A pointer to extra data buf
1548 * @return 0 --success, otherwise fail
1550 static int lbs_set_encodeext(struct net_device *dev,
1551 struct iw_request_info *info,
1552 struct iw_point *dwrq,
1556 struct lbs_private *priv = dev->ml_priv;
1557 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1559 struct assoc_request * assoc_req;
1561 lbs_deb_enter(LBS_DEB_WEXT);
1563 mutex_lock(&priv->lock);
1564 assoc_req = lbs_get_association_request(priv);
1570 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1571 disable_wep (assoc_req);
1572 disable_wpa (assoc_req);
1573 } else if (alg == IW_ENCODE_ALG_WEP) {
1574 u16 is_default = 0, index, set_tx_key = 0;
1576 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1577 (dwrq->flags & IW_ENCODE_INDEX),
1578 &index, &is_default);
1582 /* If WEP isn't enabled, or if there is no key data but a valid
1583 * index, or if the set-TX-key flag was passed, set the TX key.
1585 if ( !assoc_req->secinfo.wep_enabled
1586 || (dwrq->length == 0 && !is_default)
1587 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1590 /* Copy key to driver */
1591 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
1596 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1597 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1598 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1599 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1602 /* Mark the various WEP bits as modified */
1603 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1605 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1607 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1608 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1609 struct enc_key * pkey;
1611 /* validate key length */
1612 if (((alg == IW_ENCODE_ALG_TKIP)
1613 && (ext->key_len != KEY_LEN_WPA_TKIP))
1614 || ((alg == IW_ENCODE_ALG_CCMP)
1615 && (ext->key_len != KEY_LEN_WPA_AES))) {
1616 lbs_deb_wext("invalid size %d for key of alg "
1624 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1625 pkey = &assoc_req->wpa_mcast_key;
1626 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1628 pkey = &assoc_req->wpa_unicast_key;
1629 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1632 memset(pkey, 0, sizeof (struct enc_key));
1633 memcpy(pkey->key, ext->key, ext->key_len);
1634 pkey->len = ext->key_len;
1636 pkey->flags |= KEY_INFO_WPA_ENABLED;
1638 /* Do this after zeroing key structure */
1639 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1640 pkey->flags |= KEY_INFO_WPA_MCAST;
1642 pkey->flags |= KEY_INFO_WPA_UNICAST;
1645 if (alg == IW_ENCODE_ALG_TKIP) {
1646 pkey->type = KEY_TYPE_ID_TKIP;
1647 } else if (alg == IW_ENCODE_ALG_CCMP) {
1648 pkey->type = KEY_TYPE_ID_AES;
1651 /* If WPA isn't enabled yet, do that now */
1652 if ( assoc_req->secinfo.WPAenabled == 0
1653 && assoc_req->secinfo.WPA2enabled == 0) {
1654 assoc_req->secinfo.WPAenabled = 1;
1655 assoc_req->secinfo.WPA2enabled = 1;
1656 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1659 /* Only disable wep if necessary: can't waste time here. */
1660 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1661 disable_wep(assoc_req);
1666 /* 802.1x and WPA rekeying must happen as quickly as possible,
1667 * especially during the 4-way handshake; thus if in
1668 * infrastructure mode, and either (a) 802.1x is enabled or
1669 * (b) WPA is being used, set the key right away.
1671 if (assoc_req->mode == IW_MODE_INFRA &&
1672 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1673 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1674 assoc_req->secinfo.WPAenabled ||
1675 assoc_req->secinfo.WPA2enabled)) {
1676 lbs_do_association_work(priv);
1678 lbs_postpone_association_work(priv);
1680 lbs_cancel_association_work(priv);
1682 mutex_unlock(&priv->lock);
1684 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1689 static int lbs_set_genie(struct net_device *dev,
1690 struct iw_request_info *info,
1691 struct iw_point *dwrq,
1694 struct lbs_private *priv = dev->ml_priv;
1696 struct assoc_request * assoc_req;
1698 lbs_deb_enter(LBS_DEB_WEXT);
1700 mutex_lock(&priv->lock);
1701 assoc_req = lbs_get_association_request(priv);
1707 if (dwrq->length > MAX_WPA_IE_LEN ||
1708 (dwrq->length && extra == NULL)) {
1714 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1715 assoc_req->wpa_ie_len = dwrq->length;
1717 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
1718 assoc_req->wpa_ie_len = 0;
1723 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1724 lbs_postpone_association_work(priv);
1726 lbs_cancel_association_work(priv);
1728 mutex_unlock(&priv->lock);
1730 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1734 static int lbs_get_genie(struct net_device *dev,
1735 struct iw_request_info *info,
1736 struct iw_point *dwrq,
1740 struct lbs_private *priv = dev->ml_priv;
1742 lbs_deb_enter(LBS_DEB_WEXT);
1744 if (priv->wpa_ie_len == 0) {
1749 if (dwrq->length < priv->wpa_ie_len) {
1754 dwrq->length = priv->wpa_ie_len;
1755 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
1758 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1763 static int lbs_set_auth(struct net_device *dev,
1764 struct iw_request_info *info,
1765 struct iw_param *dwrq,
1768 struct lbs_private *priv = dev->ml_priv;
1769 struct assoc_request * assoc_req;
1773 lbs_deb_enter(LBS_DEB_WEXT);
1775 mutex_lock(&priv->lock);
1776 assoc_req = lbs_get_association_request(priv);
1782 switch (dwrq->flags & IW_AUTH_INDEX) {
1783 case IW_AUTH_PRIVACY_INVOKED:
1784 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1785 case IW_AUTH_TKIP_COUNTERMEASURES:
1786 case IW_AUTH_CIPHER_PAIRWISE:
1787 case IW_AUTH_CIPHER_GROUP:
1788 case IW_AUTH_DROP_UNENCRYPTED:
1790 * libertas does not use these parameters
1794 case IW_AUTH_KEY_MGMT:
1795 assoc_req->secinfo.key_mgmt = dwrq->value;
1799 case IW_AUTH_WPA_VERSION:
1800 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1801 assoc_req->secinfo.WPAenabled = 0;
1802 assoc_req->secinfo.WPA2enabled = 0;
1803 disable_wpa (assoc_req);
1805 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1806 assoc_req->secinfo.WPAenabled = 1;
1807 assoc_req->secinfo.wep_enabled = 0;
1808 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1810 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1811 assoc_req->secinfo.WPA2enabled = 1;
1812 assoc_req->secinfo.wep_enabled = 0;
1813 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1818 case IW_AUTH_80211_AUTH_ALG:
1819 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1820 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1821 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1822 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1823 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1824 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1831 case IW_AUTH_WPA_ENABLED:
1833 if (!assoc_req->secinfo.WPAenabled &&
1834 !assoc_req->secinfo.WPA2enabled) {
1835 assoc_req->secinfo.WPAenabled = 1;
1836 assoc_req->secinfo.WPA2enabled = 1;
1837 assoc_req->secinfo.wep_enabled = 0;
1838 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1841 assoc_req->secinfo.WPAenabled = 0;
1842 assoc_req->secinfo.WPA2enabled = 0;
1843 disable_wpa (assoc_req);
1856 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1857 lbs_postpone_association_work(priv);
1858 } else if (ret != -EOPNOTSUPP) {
1859 lbs_cancel_association_work(priv);
1861 mutex_unlock(&priv->lock);
1863 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1867 static int lbs_get_auth(struct net_device *dev,
1868 struct iw_request_info *info,
1869 struct iw_param *dwrq,
1873 struct lbs_private *priv = dev->ml_priv;
1875 lbs_deb_enter(LBS_DEB_WEXT);
1877 switch (dwrq->flags & IW_AUTH_INDEX) {
1878 case IW_AUTH_KEY_MGMT:
1879 dwrq->value = priv->secinfo.key_mgmt;
1882 case IW_AUTH_WPA_VERSION:
1884 if (priv->secinfo.WPAenabled)
1885 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1886 if (priv->secinfo.WPA2enabled)
1887 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1889 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1892 case IW_AUTH_80211_AUTH_ALG:
1893 dwrq->value = priv->secinfo.auth_mode;
1896 case IW_AUTH_WPA_ENABLED:
1897 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
1905 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1910 static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
1911 struct iw_param *vwrq, char *extra)
1914 struct lbs_private *priv = dev->ml_priv;
1915 s16 dbm = (s16) vwrq->value;
1917 lbs_deb_enter(LBS_DEB_WEXT);
1919 if (vwrq->disabled) {
1920 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
1924 if (vwrq->fixed == 0) {
1925 /* User requests automatic tx power control, however there are
1926 * many auto tx settings. For now use firmware defaults until
1927 * we come up with a good way to expose these to the user. */
1928 if (priv->fwrelease < 0x09000000) {
1929 ret = lbs_set_power_adapt_cfg(priv, 1,
1930 POW_ADAPT_DEFAULT_P0,
1931 POW_ADAPT_DEFAULT_P1,
1932 POW_ADAPT_DEFAULT_P2);
1936 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1940 dbm = priv->txpower_max;
1942 /* Userspace check in iwrange if it should use dBm or mW,
1943 * therefore this should never happen... Jean II */
1944 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1949 /* Validate requested power level against firmware allowed
1951 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1956 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1960 if (priv->fwrelease < 0x09000000) {
1961 ret = lbs_set_power_adapt_cfg(priv, 0,
1962 POW_ADAPT_DEFAULT_P0,
1963 POW_ADAPT_DEFAULT_P1,
1964 POW_ADAPT_DEFAULT_P2);
1968 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1974 /* If the radio was off, turn it on */
1975 if (!priv->radio_on) {
1976 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1981 lbs_deb_wext("txpower set %d dBm\n", dbm);
1983 ret = lbs_set_tx_power(priv, dbm);
1986 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1990 static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
1991 struct iw_point *dwrq, char *extra)
1993 struct lbs_private *priv = dev->ml_priv;
1995 lbs_deb_enter(LBS_DEB_WEXT);
1998 * Note : if dwrq->flags != 0, we should get the relevant SSID from
2003 * Get the current SSID
2005 if (priv->connect_status == LBS_CONNECTED) {
2006 memcpy(extra, priv->curbssparams.ssid,
2007 priv->curbssparams.ssid_len);
2008 extra[priv->curbssparams.ssid_len] = '\0';
2010 memset(extra, 0, 32);
2011 extra[priv->curbssparams.ssid_len] = '\0';
2014 * If none, we may want to get the one that was set
2017 dwrq->length = priv->curbssparams.ssid_len;
2019 dwrq->flags = 1; /* active */
2021 lbs_deb_leave(LBS_DEB_WEXT);
2025 static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
2026 struct iw_point *dwrq, char *extra)
2028 struct lbs_private *priv = dev->ml_priv;
2030 u8 ssid[IW_ESSID_MAX_SIZE];
2032 struct assoc_request * assoc_req;
2033 int in_ssid_len = dwrq->length;
2034 DECLARE_SSID_BUF(ssid_buf);
2036 lbs_deb_enter(LBS_DEB_WEXT);
2038 if (!priv->radio_on) {
2043 /* Check the size of the string */
2044 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
2049 memset(&ssid, 0, sizeof(ssid));
2051 if (!dwrq->flags || !in_ssid_len) {
2052 /* "any" SSID requested; leave SSID blank */
2054 /* Specific SSID requested */
2055 memcpy(&ssid, extra, in_ssid_len);
2056 ssid_len = in_ssid_len;
2060 lbs_deb_wext("requested any SSID\n");
2062 lbs_deb_wext("requested SSID '%s'\n",
2063 print_ssid(ssid_buf, ssid, ssid_len));
2067 mutex_lock(&priv->lock);
2069 /* Get or create the current association request */
2070 assoc_req = lbs_get_association_request(priv);
2074 /* Copy the SSID to the association request */
2075 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
2076 assoc_req->ssid_len = ssid_len;
2077 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2078 lbs_postpone_association_work(priv);
2082 /* Cancel the association request if there was an error */
2084 lbs_cancel_association_work(priv);
2087 mutex_unlock(&priv->lock);
2089 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2093 static int lbs_mesh_get_essid(struct net_device *dev,
2094 struct iw_request_info *info,
2095 struct iw_point *dwrq, char *extra)
2097 struct lbs_private *priv = dev->ml_priv;
2099 lbs_deb_enter(LBS_DEB_WEXT);
2101 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2103 dwrq->length = priv->mesh_ssid_len;
2105 dwrq->flags = 1; /* active */
2107 lbs_deb_leave(LBS_DEB_WEXT);
2111 static int lbs_mesh_set_essid(struct net_device *dev,
2112 struct iw_request_info *info,
2113 struct iw_point *dwrq, char *extra)
2115 struct lbs_private *priv = dev->ml_priv;
2118 lbs_deb_enter(LBS_DEB_WEXT);
2120 if (!priv->radio_on) {
2125 /* Check the size of the string */
2126 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2131 if (!dwrq->flags || !dwrq->length) {
2135 /* Specific SSID requested */
2136 memcpy(priv->mesh_ssid, extra, dwrq->length);
2137 priv->mesh_ssid_len = dwrq->length;
2140 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2141 priv->curbssparams.channel);
2143 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2148 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2150 * @param dev A pointer to net_device structure
2151 * @param info A pointer to iw_request_info structure
2152 * @param awrq A pointer to iw_param structure
2153 * @param extra A pointer to extra data buf
2154 * @return 0 --success, otherwise fail
2156 static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
2157 struct sockaddr *awrq, char *extra)
2159 struct lbs_private *priv = dev->ml_priv;
2160 struct assoc_request * assoc_req;
2163 lbs_deb_enter(LBS_DEB_WEXT);
2165 if (!priv->radio_on)
2168 if (awrq->sa_family != ARPHRD_ETHER)
2171 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
2173 mutex_lock(&priv->lock);
2175 /* Get or create the current association request */
2176 assoc_req = lbs_get_association_request(priv);
2178 lbs_cancel_association_work(priv);
2181 /* Copy the BSSID to the association request */
2182 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2183 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2184 lbs_postpone_association_work(priv);
2187 mutex_unlock(&priv->lock);
2193 * iwconfig settable callbacks
2195 static const iw_handler lbs_handler[] = {
2196 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2197 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2198 (iw_handler) NULL, /* SIOCSIWNWID */
2199 (iw_handler) NULL, /* SIOCGIWNWID */
2200 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2201 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2202 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2203 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
2204 (iw_handler) NULL, /* SIOCSIWSENS */
2205 (iw_handler) NULL, /* SIOCGIWSENS */
2206 (iw_handler) NULL, /* SIOCSIWRANGE */
2207 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2208 (iw_handler) NULL, /* SIOCSIWPRIV */
2209 (iw_handler) NULL, /* SIOCGIWPRIV */
2210 (iw_handler) NULL, /* SIOCSIWSTATS */
2211 (iw_handler) NULL, /* SIOCGIWSTATS */
2212 iw_handler_set_spy, /* SIOCSIWSPY */
2213 iw_handler_get_spy, /* SIOCGIWSPY */
2214 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2215 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2216 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2217 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
2218 (iw_handler) NULL, /* SIOCSIWMLME */
2219 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2220 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2221 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2222 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2223 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2224 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2225 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
2226 (iw_handler) NULL, /* -- hole -- */
2227 (iw_handler) NULL, /* -- hole -- */
2228 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2229 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2230 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2231 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2232 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2233 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2234 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2235 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2236 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2237 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2238 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2239 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2240 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2241 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2242 (iw_handler) NULL, /* -- hole -- */
2243 (iw_handler) NULL, /* -- hole -- */
2244 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2245 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2246 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2247 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2248 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2249 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2250 (iw_handler) NULL, /* SIOCSIWPMKSA */
2253 static const iw_handler mesh_wlan_handler[] = {
2254 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2255 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2256 (iw_handler) NULL, /* SIOCSIWNWID */
2257 (iw_handler) NULL, /* SIOCGIWNWID */
2258 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
2259 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2260 (iw_handler) NULL, /* SIOCSIWMODE */
2261 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2262 (iw_handler) NULL, /* SIOCSIWSENS */
2263 (iw_handler) NULL, /* SIOCGIWSENS */
2264 (iw_handler) NULL, /* SIOCSIWRANGE */
2265 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2266 (iw_handler) NULL, /* SIOCSIWPRIV */
2267 (iw_handler) NULL, /* SIOCGIWPRIV */
2268 (iw_handler) NULL, /* SIOCSIWSTATS */
2269 (iw_handler) NULL, /* SIOCGIWSTATS */
2270 iw_handler_set_spy, /* SIOCSIWSPY */
2271 iw_handler_get_spy, /* SIOCGIWSPY */
2272 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2273 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2274 (iw_handler) NULL, /* SIOCSIWAP */
2275 (iw_handler) NULL, /* SIOCGIWAP */
2276 (iw_handler) NULL, /* SIOCSIWMLME */
2277 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2278 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2279 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2280 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2281 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
2282 (iw_handler) NULL, /* SIOCSIWNICKN */
2283 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2284 (iw_handler) NULL, /* -- hole -- */
2285 (iw_handler) NULL, /* -- hole -- */
2286 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2287 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2288 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2289 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2290 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2291 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2292 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2293 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2294 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2295 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2296 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2297 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2298 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2299 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2300 (iw_handler) NULL, /* -- hole -- */
2301 (iw_handler) NULL, /* -- hole -- */
2302 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2303 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2304 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2305 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2306 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2307 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2308 (iw_handler) NULL, /* SIOCSIWPMKSA */
2310 struct iw_handler_def lbs_handler_def = {
2311 .num_standard = ARRAY_SIZE(lbs_handler),
2312 .standard = (iw_handler *) lbs_handler,
2313 .get_wireless_stats = lbs_get_wireless_stats,
2316 struct iw_handler_def mesh_handler_def = {
2317 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
2318 .standard = (iw_handler *) mesh_wlan_handler,
2319 .get_wireless_stats = lbs_get_wireless_stats,