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];
68 if (!rc->valid || !rc->CFP)
72 for (i = 0; i < rc->nrcfp; i++) {
73 if (rc->CFP[i].channel == channel) {
81 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
82 "cfp by band %d / channel %d\n", band, channel);
88 * @brief Find the channel frequency power info with specific frequency
90 * @param priv A pointer to struct lbs_private structure
91 * @param band it can be BAND_A, BAND_G or BAND_B
92 * @param freq the frequency for looking
93 * @return A pointer to struct chan_freq_power structure or NULL if not find.
95 static struct chan_freq_power *find_cfp_by_band_and_freq(
96 struct lbs_private *priv,
100 struct chan_freq_power *cfp = NULL;
101 struct region_channel *rc;
104 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
105 rc = &priv->region_channel[j];
107 if (!rc->valid || !rc->CFP)
109 if (rc->band != band)
111 for (i = 0; i < rc->nrcfp; i++) {
112 if (rc->CFP[i].freq == freq) {
120 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
121 "band %d / freq %d\n", band, freq);
127 * @brief Copy active data rates based on adapter mode and status
129 * @param priv A pointer to struct lbs_private structure
130 * @param rate The buf to return the active rates
132 static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
134 lbs_deb_enter(LBS_DEB_WEXT);
136 if ((priv->connect_status != LBS_CONNECTED) &&
137 (priv->mesh_connect_status != LBS_CONNECTED))
138 memcpy(rates, lbs_bg_rates, MAX_RATES);
140 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
142 lbs_deb_leave(LBS_DEB_WEXT);
145 static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
146 char *cwrq, char *extra)
149 lbs_deb_enter(LBS_DEB_WEXT);
151 /* We could add support for 802.11n here as needed. Jean II */
152 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
154 lbs_deb_leave(LBS_DEB_WEXT);
158 static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
159 struct iw_freq *fwrq, char *extra)
161 struct lbs_private *priv = dev->ml_priv;
162 struct chan_freq_power *cfp;
164 lbs_deb_enter(LBS_DEB_WEXT);
166 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
167 priv->curbssparams.channel);
170 if (priv->curbssparams.channel)
171 lbs_deb_wext("invalid channel %d\n",
172 priv->curbssparams.channel);
176 fwrq->m = (long)cfp->freq * 100000;
179 lbs_deb_wext("freq %u\n", fwrq->m);
180 lbs_deb_leave(LBS_DEB_WEXT);
184 static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
185 struct sockaddr *awrq, char *extra)
187 struct lbs_private *priv = dev->ml_priv;
189 lbs_deb_enter(LBS_DEB_WEXT);
191 if (priv->connect_status == LBS_CONNECTED) {
192 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
194 memset(awrq->sa_data, 0, ETH_ALEN);
196 awrq->sa_family = ARPHRD_ETHER;
198 lbs_deb_leave(LBS_DEB_WEXT);
202 static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
203 struct iw_point *dwrq, char *extra)
205 struct lbs_private *priv = dev->ml_priv;
207 lbs_deb_enter(LBS_DEB_WEXT);
210 * Check the size of the string
213 if (dwrq->length > 16) {
217 mutex_lock(&priv->lock);
218 memset(priv->nodename, 0, sizeof(priv->nodename));
219 memcpy(priv->nodename, extra, dwrq->length);
220 mutex_unlock(&priv->lock);
222 lbs_deb_leave(LBS_DEB_WEXT);
226 static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
227 struct iw_point *dwrq, char *extra)
229 struct lbs_private *priv = dev->ml_priv;
231 lbs_deb_enter(LBS_DEB_WEXT);
233 dwrq->length = strlen(priv->nodename);
234 memcpy(extra, priv->nodename, dwrq->length);
235 extra[dwrq->length] = '\0';
237 dwrq->flags = 1; /* active */
239 lbs_deb_leave(LBS_DEB_WEXT);
243 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
244 struct iw_point *dwrq, char *extra)
246 struct lbs_private *priv = dev->ml_priv;
248 lbs_deb_enter(LBS_DEB_WEXT);
250 /* Use nickname to indicate that mesh is on */
252 if (priv->mesh_connect_status == LBS_CONNECTED) {
253 strncpy(extra, "Mesh", 12);
255 dwrq->length = strlen(extra);
263 lbs_deb_leave(LBS_DEB_WEXT);
267 static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
268 struct iw_param *vwrq, char *extra)
271 struct lbs_private *priv = dev->ml_priv;
272 u32 val = vwrq->value;
274 lbs_deb_enter(LBS_DEB_WEXT);
277 val = MRVDRV_RTS_MAX_VALUE;
279 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
282 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
284 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
288 static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
289 struct iw_param *vwrq, char *extra)
291 struct lbs_private *priv = dev->ml_priv;
295 lbs_deb_enter(LBS_DEB_WEXT);
297 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
302 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
306 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
310 static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
311 struct iw_param *vwrq, char *extra)
313 struct lbs_private *priv = dev->ml_priv;
315 u32 val = vwrq->value;
317 lbs_deb_enter(LBS_DEB_WEXT);
320 val = MRVDRV_FRAG_MAX_VALUE;
322 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
325 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
327 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
331 static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
332 struct iw_param *vwrq, char *extra)
334 struct lbs_private *priv = dev->ml_priv;
338 lbs_deb_enter(LBS_DEB_WEXT);
340 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
345 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
346 || (val > MRVDRV_FRAG_MAX_VALUE));
350 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
354 static int lbs_get_mode(struct net_device *dev,
355 struct iw_request_info *info, u32 * uwrq, char *extra)
357 struct lbs_private *priv = dev->ml_priv;
359 lbs_deb_enter(LBS_DEB_WEXT);
363 lbs_deb_leave(LBS_DEB_WEXT);
367 static int mesh_wlan_get_mode(struct net_device *dev,
368 struct iw_request_info *info, u32 * uwrq,
371 lbs_deb_enter(LBS_DEB_WEXT);
373 *uwrq = IW_MODE_REPEAT;
375 lbs_deb_leave(LBS_DEB_WEXT);
379 static int lbs_get_txpow(struct net_device *dev,
380 struct iw_request_info *info,
381 struct iw_param *vwrq, char *extra)
383 struct lbs_private *priv = dev->ml_priv;
387 lbs_deb_enter(LBS_DEB_WEXT);
389 if (!priv->radio_on) {
390 lbs_deb_wext("tx power off\n");
396 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
400 lbs_deb_wext("tx power level %d dbm\n", curlevel);
401 priv->txpower_cur = curlevel;
403 vwrq->value = curlevel;
406 vwrq->flags = IW_TXPOW_DBM;
409 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
413 static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
414 struct iw_param *vwrq, char *extra)
416 struct lbs_private *priv = dev->ml_priv;
418 u16 slimit = 0, llimit = 0;
420 lbs_deb_enter(LBS_DEB_WEXT);
422 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
425 /* The MAC has a 4-bit Total_Tx_Count register
426 Total_Tx_Count = 1 + Tx_Retry_Count */
427 #define TX_RETRY_MIN 0
428 #define TX_RETRY_MAX 14
429 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
432 /* Add 1 to convert retry count to try count */
433 if (vwrq->flags & IW_RETRY_SHORT)
434 slimit = (u16) (vwrq->value + 1);
435 else if (vwrq->flags & IW_RETRY_LONG)
436 llimit = (u16) (vwrq->value + 1);
438 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
441 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
448 /* txretrycount follows the short retry limit */
449 priv->txretrycount = slimit;
450 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
457 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
461 static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
462 struct iw_param *vwrq, char *extra)
464 struct lbs_private *priv = dev->ml_priv;
468 lbs_deb_enter(LBS_DEB_WEXT);
472 if (vwrq->flags & IW_RETRY_LONG) {
473 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
477 /* Subtract 1 to convert try count to retry count */
478 vwrq->value = val - 1;
479 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
481 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
485 /* txretry count follows the short retry limit */
486 priv->txretrycount = val;
487 /* Subtract 1 to convert try count to retry count */
488 vwrq->value = val - 1;
489 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
493 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
497 static inline void sort_channels(struct iw_freq *freq, int num)
502 for (i = 0; i < num; i++)
503 for (j = i + 1; j < num; j++)
504 if (freq[i].i > freq[j].i) {
508 freq[i].i = freq[j].i;
509 freq[i].m = freq[j].m;
519 Infra G(12) A(8) B(4) G(12)
520 Adhoc A+B(12) A(8) B(4) B(4)
528 * @brief Get Range Info
530 * @param dev A pointer to net_device structure
531 * @param info A pointer to iw_request_info structure
532 * @param vwrq A pointer to iw_param structure
533 * @param extra A pointer to extra data buf
534 * @return 0 --success, otherwise fail
536 static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
537 struct iw_point *dwrq, char *extra)
540 struct lbs_private *priv = dev->ml_priv;
541 struct iw_range *range = (struct iw_range *)extra;
542 struct chan_freq_power *cfp;
543 u8 rates[MAX_RATES + 1];
545 lbs_deb_enter(LBS_DEB_WEXT);
547 dwrq->length = sizeof(struct iw_range);
548 memset(range, 0, sizeof(struct iw_range));
553 memset(rates, 0, sizeof(rates));
554 copy_active_data_rates(priv, rates);
555 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
556 for (i = 0; i < range->num_bitrates; i++)
557 range->bitrate[i] = rates[i] * 500000;
558 range->num_bitrates = i;
559 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
560 range->num_bitrates);
562 range->num_frequency = 0;
564 range->scan_capa = IW_SCAN_CAPA_ESSID;
566 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
567 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
568 cfp = priv->region_channel[j].CFP;
569 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
570 && priv->region_channel[j].valid
572 && (i < priv->region_channel[j].nrcfp); i++) {
573 range->freq[range->num_frequency].i =
575 range->freq[range->num_frequency].m =
576 (long)cfp->freq * 100000;
577 range->freq[range->num_frequency].e = 1;
579 range->num_frequency++;
583 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
584 IW_MAX_FREQUENCIES, range->num_frequency);
586 range->num_channels = range->num_frequency;
588 sort_channels(&range->freq[0], range->num_frequency);
591 * Set an indication of the max TCP throughput in bit/s that we can
592 * expect using this interface
595 range->throughput = 5000 * 1000;
597 range->throughput = 1500 * 1000;
599 range->min_rts = MRVDRV_RTS_MIN_VALUE;
600 range->max_rts = MRVDRV_RTS_MAX_VALUE;
601 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
602 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
604 range->encoding_size[0] = 5;
605 range->encoding_size[1] = 13;
606 range->num_encoding_sizes = 2;
607 range->max_encoding_tokens = 4;
610 * Right now we support only "iwconfig ethX power on|off"
612 range->pm_capa = IW_POWER_ON;
615 * Minimum version we recommend
617 range->we_version_source = 15;
620 * Version we are compiled with
622 range->we_version_compiled = WIRELESS_EXT;
624 range->retry_capa = IW_RETRY_LIMIT;
625 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
627 range->min_retry = TX_RETRY_MIN;
628 range->max_retry = TX_RETRY_MAX;
631 * Set the qual, level and noise range values
633 range->max_qual.qual = 100;
634 range->max_qual.level = 0;
635 range->max_qual.noise = 0;
636 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
638 range->avg_qual.qual = 70;
639 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
640 range->avg_qual.level = 0;
641 range->avg_qual.noise = 0;
642 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
644 range->sensitivity = 0;
646 /* Setup the supported power level ranges */
647 memset(range->txpower, 0, sizeof(range->txpower));
648 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
649 range->txpower[0] = priv->txpower_min;
650 range->txpower[1] = priv->txpower_max;
651 range->num_txpower = 2;
653 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
654 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
655 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
656 range->event_capa[1] = IW_EVENT_CAPA_K_1;
658 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
659 range->enc_capa = IW_ENC_CAPA_WPA
661 | IW_ENC_CAPA_CIPHER_TKIP
662 | IW_ENC_CAPA_CIPHER_CCMP;
665 lbs_deb_leave(LBS_DEB_WEXT);
669 static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
670 struct iw_param *vwrq, char *extra)
672 struct lbs_private *priv = dev->ml_priv;
675 lbs_deb_enter(LBS_DEB_WEXT);
677 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
684 /* PS is currently supported only in Infrastructure mode
685 * Remove this check if it is to be supported in IBSS mode also
688 if (vwrq->disabled) {
689 priv->psmode = LBS802_11POWERMODECAM;
690 if (priv->psstate != PS_STATE_FULL_POWER) {
691 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
697 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
699 "setting power timeout is not supported\n");
701 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
702 vwrq->value = vwrq->value / 1000;
703 if (!priv->enter_deep_sleep) {
704 lbs_pr_err("deep sleep feature is not implemented "
705 "for this interface driver\n");
709 if (priv->connect_status == LBS_CONNECTED) {
710 if ((priv->is_auto_deep_sleep_enabled) &&
711 (vwrq->value == -1000)) {
712 lbs_exit_auto_deep_sleep(priv);
715 lbs_pr_err("can't use deep sleep cmd in "
716 "connected state\n");
721 if ((vwrq->value < 0) && (vwrq->value != -1000)) {
722 lbs_pr_err("unknown option\n");
726 if (vwrq->value > 0) {
727 if (!priv->is_auto_deep_sleep_enabled) {
728 priv->is_activity_detected = 0;
729 priv->auto_deep_sleep_timeout = vwrq->value;
730 lbs_enter_auto_deep_sleep(priv);
732 priv->auto_deep_sleep_timeout = vwrq->value;
733 lbs_deb_debugfs("auto deep sleep: "
734 "already enabled\n");
738 if (priv->is_auto_deep_sleep_enabled) {
739 lbs_exit_auto_deep_sleep(priv);
740 /* Try to exit deep sleep if auto */
741 /*deep sleep disabled */
742 ret = lbs_set_deep_sleep(priv, 0);
744 if (vwrq->value == 0)
745 ret = lbs_set_deep_sleep(priv, 1);
746 else if (vwrq->value == -1000)
747 ret = lbs_set_deep_sleep(priv, 0);
752 if (priv->psmode != LBS802_11POWERMODECAM) {
756 priv->psmode = LBS802_11POWERMODEMAX_PSP;
758 if (priv->connect_status == LBS_CONNECTED) {
759 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
762 lbs_deb_leave(LBS_DEB_WEXT);
767 static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
768 struct iw_param *vwrq, char *extra)
770 struct lbs_private *priv = dev->ml_priv;
772 lbs_deb_enter(LBS_DEB_WEXT);
776 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
777 || priv->connect_status == LBS_DISCONNECTED;
779 lbs_deb_leave(LBS_DEB_WEXT);
783 static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
793 struct lbs_private *priv = dev->ml_priv;
797 int ret, stats_valid = 0;
800 struct cmd_ds_802_11_get_log log;
802 lbs_deb_enter(LBS_DEB_WEXT);
804 priv->wstats.status = priv->mode;
806 /* If we're not associated, all quality values are meaningless */
807 if ((priv->connect_status != LBS_CONNECTED) &&
808 (priv->mesh_connect_status != LBS_CONNECTED))
811 /* Quality by RSSI */
812 priv->wstats.qual.level =
813 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
814 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
816 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
817 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
819 priv->wstats.qual.noise =
820 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
823 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
824 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
826 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
828 rssi_qual = rssi * POOR / 10;
830 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
832 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
834 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
837 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
841 /* Quality by TX errors */
842 priv->wstats.discard.retries = dev->stats.tx_errors;
844 memset(&log, 0, sizeof(log));
845 log.hdr.size = cpu_to_le16(sizeof(log));
846 ret = lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
850 tx_retries = le32_to_cpu(log.retry);
853 tx_qual = (90 - tx_retries) * POOR / 15;
854 else if (tx_retries > 70)
855 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
856 else if (tx_retries > 65)
857 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
858 else if (tx_retries > 50)
859 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
862 tx_qual = (50 - tx_retries) *
863 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
864 quality = min(quality, tx_qual);
866 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
867 priv->wstats.discard.retries = tx_retries;
868 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
870 /* Calculate quality */
871 priv->wstats.qual.qual = min_t(u8, quality, 100);
872 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
875 /* update stats asynchronously for future calls */
876 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
879 lbs_pr_err("RSSI command failed\n");
882 priv->wstats.miss.beacon = 0;
883 priv->wstats.discard.retries = 0;
884 priv->wstats.qual.qual = 0;
885 priv->wstats.qual.level = 0;
886 priv->wstats.qual.noise = 0;
887 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
888 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
889 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
892 lbs_deb_leave(LBS_DEB_WEXT);
893 return &priv->wstats;
898 static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
899 struct iw_freq *fwrq, char *extra)
902 struct lbs_private *priv = dev->ml_priv;
903 struct chan_freq_power *cfp;
904 struct assoc_request * assoc_req;
906 lbs_deb_enter(LBS_DEB_WEXT);
908 mutex_lock(&priv->lock);
909 assoc_req = lbs_get_association_request(priv);
915 /* If setting by frequency, convert to a channel */
917 long f = fwrq->m / 100000;
919 cfp = find_cfp_by_band_and_freq(priv, 0, f);
921 lbs_deb_wext("invalid freq %ld\n", f);
926 fwrq->m = (int) cfp->channel;
929 /* Setting by channel number */
930 if (fwrq->m > 1000 || fwrq->e > 0) {
934 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
939 assoc_req->channel = fwrq->m;
944 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
945 lbs_postpone_association_work(priv);
947 lbs_cancel_association_work(priv);
949 mutex_unlock(&priv->lock);
951 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
955 static int lbs_mesh_set_freq(struct net_device *dev,
956 struct iw_request_info *info,
957 struct iw_freq *fwrq, char *extra)
959 struct lbs_private *priv = dev->ml_priv;
960 struct chan_freq_power *cfp;
963 lbs_deb_enter(LBS_DEB_WEXT);
965 /* If setting by frequency, convert to a channel */
967 long f = fwrq->m / 100000;
969 cfp = find_cfp_by_band_and_freq(priv, 0, f);
971 lbs_deb_wext("invalid freq %ld\n", f);
976 fwrq->m = (int) cfp->channel;
979 /* Setting by channel number */
980 if (fwrq->m > 1000 || fwrq->e > 0) {
984 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
989 if (fwrq->m != priv->curbssparams.channel) {
990 lbs_deb_wext("mesh channel change forces eth disconnect\n");
991 if (priv->mode == IW_MODE_INFRA)
992 lbs_cmd_80211_deauthenticate(priv,
993 priv->curbssparams.bssid,
994 WLAN_REASON_DEAUTH_LEAVING);
995 else if (priv->mode == IW_MODE_ADHOC)
996 lbs_adhoc_stop(priv);
998 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
999 lbs_update_channel(priv);
1003 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1007 static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
1008 struct iw_param *vwrq, char *extra)
1010 struct lbs_private *priv = dev->ml_priv;
1013 u8 rates[MAX_RATES + 1];
1015 lbs_deb_enter(LBS_DEB_WEXT);
1017 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
1018 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1020 if (vwrq->fixed && vwrq->value == -1)
1024 priv->enablehwauto = !vwrq->fixed;
1026 if (vwrq->value == -1)
1029 if (vwrq->value % 100000)
1032 new_rate = vwrq->value / 500000;
1033 priv->cur_rate = new_rate;
1034 /* the rest is only needed for lbs_set_data_rate() */
1035 memset(rates, 0, sizeof(rates));
1036 copy_active_data_rates(priv, rates);
1037 if (!memchr(rates, new_rate, sizeof(rates))) {
1038 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1042 if (priv->fwrelease < 0x09000000) {
1043 ret = lbs_set_power_adapt_cfg(priv, 0,
1044 POW_ADAPT_DEFAULT_P0,
1045 POW_ADAPT_DEFAULT_P1,
1046 POW_ADAPT_DEFAULT_P2);
1050 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1056 /* Try the newer command first (Firmware Spec 5.1 and above) */
1057 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1059 /* Fallback to older version */
1061 ret = lbs_set_data_rate(priv, new_rate);
1064 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1068 static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
1069 struct iw_param *vwrq, char *extra)
1071 struct lbs_private *priv = dev->ml_priv;
1073 lbs_deb_enter(LBS_DEB_WEXT);
1075 if (priv->connect_status == LBS_CONNECTED) {
1076 vwrq->value = priv->cur_rate * 500000;
1078 if (priv->enablehwauto)
1088 lbs_deb_leave(LBS_DEB_WEXT);
1092 static int lbs_set_mode(struct net_device *dev,
1093 struct iw_request_info *info, u32 * uwrq, char *extra)
1096 struct lbs_private *priv = dev->ml_priv;
1097 struct assoc_request * assoc_req;
1099 lbs_deb_enter(LBS_DEB_WEXT);
1101 if ( (*uwrq != IW_MODE_ADHOC)
1102 && (*uwrq != IW_MODE_INFRA)
1103 && (*uwrq != IW_MODE_AUTO)) {
1104 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1109 mutex_lock(&priv->lock);
1110 assoc_req = lbs_get_association_request(priv);
1113 lbs_cancel_association_work(priv);
1115 assoc_req->mode = *uwrq;
1116 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1117 lbs_postpone_association_work(priv);
1118 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1120 mutex_unlock(&priv->lock);
1123 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1129 * @brief Get Encryption key
1131 * @param dev A pointer to net_device structure
1132 * @param info A pointer to iw_request_info structure
1133 * @param vwrq A pointer to iw_param structure
1134 * @param extra A pointer to extra data buf
1135 * @return 0 --success, otherwise fail
1137 static int lbs_get_encode(struct net_device *dev,
1138 struct iw_request_info *info,
1139 struct iw_point *dwrq, u8 * extra)
1141 struct lbs_private *priv = dev->ml_priv;
1142 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1144 lbs_deb_enter(LBS_DEB_WEXT);
1146 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1147 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
1151 /* Authentication method */
1152 switch (priv->secinfo.auth_mode) {
1153 case IW_AUTH_ALG_OPEN_SYSTEM:
1154 dwrq->flags = IW_ENCODE_OPEN;
1157 case IW_AUTH_ALG_SHARED_KEY:
1158 case IW_AUTH_ALG_LEAP:
1159 dwrq->flags = IW_ENCODE_RESTRICTED;
1162 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1166 memset(extra, 0, 16);
1168 mutex_lock(&priv->lock);
1170 /* Default to returning current transmit key */
1172 index = priv->wep_tx_keyidx;
1174 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1175 memcpy(extra, priv->wep_keys[index].key,
1176 priv->wep_keys[index].len);
1177 dwrq->length = priv->wep_keys[index].len;
1179 dwrq->flags |= (index + 1);
1180 /* Return WEP enabled */
1181 dwrq->flags &= ~IW_ENCODE_DISABLED;
1182 } else if ((priv->secinfo.WPAenabled)
1183 || (priv->secinfo.WPA2enabled)) {
1184 /* return WPA enabled */
1185 dwrq->flags &= ~IW_ENCODE_DISABLED;
1186 dwrq->flags |= IW_ENCODE_NOKEY;
1188 dwrq->flags |= IW_ENCODE_DISABLED;
1191 mutex_unlock(&priv->lock);
1193 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
1194 extra[0], extra[1], extra[2],
1195 extra[3], extra[4], extra[5], dwrq->length);
1197 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1199 lbs_deb_leave(LBS_DEB_WEXT);
1204 * @brief Set Encryption key (internal)
1206 * @param priv A pointer to private card structure
1207 * @param key_material A pointer to key material
1208 * @param key_length length of key material
1209 * @param index key index to set
1210 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1211 * @return 0 --success, otherwise fail
1213 static int lbs_set_wep_key(struct assoc_request *assoc_req,
1214 const char *key_material,
1220 struct enc_key *pkey;
1222 lbs_deb_enter(LBS_DEB_WEXT);
1224 /* Paranoid validation of key index */
1230 /* validate max key length */
1231 if (key_length > KEY_LEN_WEP_104) {
1236 pkey = &assoc_req->wep_keys[index];
1238 if (key_length > 0) {
1239 memset(pkey, 0, sizeof(struct enc_key));
1240 pkey->type = KEY_TYPE_ID_WEP;
1242 /* Standardize the key length */
1243 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1244 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1245 memcpy(pkey->key, key_material, key_length);
1249 /* Ensure the chosen key is valid */
1251 lbs_deb_wext("key not set, so cannot enable it\n");
1255 assoc_req->wep_tx_keyidx = index;
1258 assoc_req->secinfo.wep_enabled = 1;
1261 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1265 static int validate_key_index(u16 def_index, u16 raw_index,
1266 u16 *out_index, u16 *is_default)
1268 if (!out_index || !is_default)
1271 /* Verify index if present, otherwise use default TX key index */
1272 if (raw_index > 0) {
1275 *out_index = raw_index - 1;
1277 *out_index = def_index;
1283 static void disable_wep(struct assoc_request *assoc_req)
1287 lbs_deb_enter(LBS_DEB_WEXT);
1289 /* Set Open System auth mode */
1290 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1292 /* Clear WEP keys and mark WEP as disabled */
1293 assoc_req->secinfo.wep_enabled = 0;
1294 for (i = 0; i < 4; i++)
1295 assoc_req->wep_keys[i].len = 0;
1297 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1298 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1300 lbs_deb_leave(LBS_DEB_WEXT);
1303 static void disable_wpa(struct assoc_request *assoc_req)
1305 lbs_deb_enter(LBS_DEB_WEXT);
1307 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
1308 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1309 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1311 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
1312 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1313 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1315 assoc_req->secinfo.WPAenabled = 0;
1316 assoc_req->secinfo.WPA2enabled = 0;
1317 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1319 lbs_deb_leave(LBS_DEB_WEXT);
1323 * @brief Set Encryption key
1325 * @param dev A pointer to net_device structure
1326 * @param info A pointer to iw_request_info structure
1327 * @param vwrq A pointer to iw_param structure
1328 * @param extra A pointer to extra data buf
1329 * @return 0 --success, otherwise fail
1331 static int lbs_set_encode(struct net_device *dev,
1332 struct iw_request_info *info,
1333 struct iw_point *dwrq, char *extra)
1336 struct lbs_private *priv = dev->ml_priv;
1337 struct assoc_request * assoc_req;
1338 u16 is_default = 0, index = 0, set_tx_key = 0;
1340 lbs_deb_enter(LBS_DEB_WEXT);
1342 mutex_lock(&priv->lock);
1343 assoc_req = lbs_get_association_request(priv);
1349 if (dwrq->flags & IW_ENCODE_DISABLED) {
1350 disable_wep (assoc_req);
1351 disable_wpa (assoc_req);
1355 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1356 (dwrq->flags & IW_ENCODE_INDEX),
1357 &index, &is_default);
1363 /* If WEP isn't enabled, or if there is no key data but a valid
1364 * index, set the TX key.
1366 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1369 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1374 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1376 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1378 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1379 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1380 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1381 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1386 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1387 lbs_postpone_association_work(priv);
1389 lbs_cancel_association_work(priv);
1391 mutex_unlock(&priv->lock);
1393 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1398 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1400 * @param dev A pointer to net_device structure
1401 * @param info A pointer to iw_request_info structure
1402 * @param vwrq A pointer to iw_param structure
1403 * @param extra A pointer to extra data buf
1404 * @return 0 on success, otherwise failure
1406 static int lbs_get_encodeext(struct net_device *dev,
1407 struct iw_request_info *info,
1408 struct iw_point *dwrq,
1412 struct lbs_private *priv = dev->ml_priv;
1413 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1414 int index, max_key_len;
1416 lbs_deb_enter(LBS_DEB_WEXT);
1418 max_key_len = dwrq->length - sizeof(*ext);
1419 if (max_key_len < 0)
1422 index = dwrq->flags & IW_ENCODE_INDEX;
1424 if (index < 1 || index > 4)
1428 index = priv->wep_tx_keyidx;
1431 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
1432 ext->alg != IW_ENCODE_ALG_WEP) {
1433 if (index != 0 || priv->mode != IW_MODE_INFRA)
1437 dwrq->flags = index + 1;
1438 memset(ext, 0, sizeof(*ext));
1440 if ( !priv->secinfo.wep_enabled
1441 && !priv->secinfo.WPAenabled
1442 && !priv->secinfo.WPA2enabled) {
1443 ext->alg = IW_ENCODE_ALG_NONE;
1445 dwrq->flags |= IW_ENCODE_DISABLED;
1449 if ( priv->secinfo.wep_enabled
1450 && !priv->secinfo.WPAenabled
1451 && !priv->secinfo.WPA2enabled) {
1453 ext->alg = IW_ENCODE_ALG_WEP;
1454 ext->key_len = priv->wep_keys[index].len;
1455 key = &priv->wep_keys[index].key[0];
1456 } else if ( !priv->secinfo.wep_enabled
1457 && (priv->secinfo.WPAenabled ||
1458 priv->secinfo.WPA2enabled)) {
1460 struct enc_key * pkey = NULL;
1462 if ( priv->wpa_mcast_key.len
1463 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1464 pkey = &priv->wpa_mcast_key;
1465 else if ( priv->wpa_unicast_key.len
1466 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1467 pkey = &priv->wpa_unicast_key;
1470 if (pkey->type == KEY_TYPE_ID_AES) {
1471 ext->alg = IW_ENCODE_ALG_CCMP;
1473 ext->alg = IW_ENCODE_ALG_TKIP;
1475 ext->key_len = pkey->len;
1476 key = &pkey->key[0];
1478 ext->alg = IW_ENCODE_ALG_TKIP;
1485 if (ext->key_len > max_key_len) {
1491 memcpy(ext->key, key, ext->key_len);
1493 dwrq->flags |= IW_ENCODE_NOKEY;
1494 dwrq->flags |= IW_ENCODE_ENABLED;
1499 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1504 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1506 * @param dev A pointer to net_device structure
1507 * @param info A pointer to iw_request_info structure
1508 * @param vwrq A pointer to iw_param structure
1509 * @param extra A pointer to extra data buf
1510 * @return 0 --success, otherwise fail
1512 static int lbs_set_encodeext(struct net_device *dev,
1513 struct iw_request_info *info,
1514 struct iw_point *dwrq,
1518 struct lbs_private *priv = dev->ml_priv;
1519 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1521 struct assoc_request * assoc_req;
1523 lbs_deb_enter(LBS_DEB_WEXT);
1525 mutex_lock(&priv->lock);
1526 assoc_req = lbs_get_association_request(priv);
1532 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1533 disable_wep (assoc_req);
1534 disable_wpa (assoc_req);
1535 } else if (alg == IW_ENCODE_ALG_WEP) {
1536 u16 is_default = 0, index, set_tx_key = 0;
1538 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1539 (dwrq->flags & IW_ENCODE_INDEX),
1540 &index, &is_default);
1544 /* If WEP isn't enabled, or if there is no key data but a valid
1545 * index, or if the set-TX-key flag was passed, set the TX key.
1547 if ( !assoc_req->secinfo.wep_enabled
1548 || (dwrq->length == 0 && !is_default)
1549 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1552 /* Copy key to driver */
1553 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
1558 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1559 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1560 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1561 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1564 /* Mark the various WEP bits as modified */
1565 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1567 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1569 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1570 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1571 struct enc_key * pkey;
1573 /* validate key length */
1574 if (((alg == IW_ENCODE_ALG_TKIP)
1575 && (ext->key_len != KEY_LEN_WPA_TKIP))
1576 || ((alg == IW_ENCODE_ALG_CCMP)
1577 && (ext->key_len != KEY_LEN_WPA_AES))) {
1578 lbs_deb_wext("invalid size %d for key of alg "
1586 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1587 pkey = &assoc_req->wpa_mcast_key;
1588 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1590 pkey = &assoc_req->wpa_unicast_key;
1591 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1594 memset(pkey, 0, sizeof (struct enc_key));
1595 memcpy(pkey->key, ext->key, ext->key_len);
1596 pkey->len = ext->key_len;
1598 pkey->flags |= KEY_INFO_WPA_ENABLED;
1600 /* Do this after zeroing key structure */
1601 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1602 pkey->flags |= KEY_INFO_WPA_MCAST;
1604 pkey->flags |= KEY_INFO_WPA_UNICAST;
1607 if (alg == IW_ENCODE_ALG_TKIP) {
1608 pkey->type = KEY_TYPE_ID_TKIP;
1609 } else if (alg == IW_ENCODE_ALG_CCMP) {
1610 pkey->type = KEY_TYPE_ID_AES;
1613 /* If WPA isn't enabled yet, do that now */
1614 if ( assoc_req->secinfo.WPAenabled == 0
1615 && assoc_req->secinfo.WPA2enabled == 0) {
1616 assoc_req->secinfo.WPAenabled = 1;
1617 assoc_req->secinfo.WPA2enabled = 1;
1618 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1621 /* Only disable wep if necessary: can't waste time here. */
1622 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1623 disable_wep(assoc_req);
1628 /* 802.1x and WPA rekeying must happen as quickly as possible,
1629 * especially during the 4-way handshake; thus if in
1630 * infrastructure mode, and either (a) 802.1x is enabled or
1631 * (b) WPA is being used, set the key right away.
1633 if (assoc_req->mode == IW_MODE_INFRA &&
1634 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1635 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1636 assoc_req->secinfo.WPAenabled ||
1637 assoc_req->secinfo.WPA2enabled)) {
1638 lbs_do_association_work(priv);
1640 lbs_postpone_association_work(priv);
1642 lbs_cancel_association_work(priv);
1644 mutex_unlock(&priv->lock);
1646 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1651 static int lbs_set_genie(struct net_device *dev,
1652 struct iw_request_info *info,
1653 struct iw_point *dwrq,
1656 struct lbs_private *priv = dev->ml_priv;
1658 struct assoc_request * assoc_req;
1660 lbs_deb_enter(LBS_DEB_WEXT);
1662 mutex_lock(&priv->lock);
1663 assoc_req = lbs_get_association_request(priv);
1669 if (dwrq->length > MAX_WPA_IE_LEN ||
1670 (dwrq->length && extra == NULL)) {
1676 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1677 assoc_req->wpa_ie_len = dwrq->length;
1679 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
1680 assoc_req->wpa_ie_len = 0;
1685 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1686 lbs_postpone_association_work(priv);
1688 lbs_cancel_association_work(priv);
1690 mutex_unlock(&priv->lock);
1692 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1696 static int lbs_get_genie(struct net_device *dev,
1697 struct iw_request_info *info,
1698 struct iw_point *dwrq,
1702 struct lbs_private *priv = dev->ml_priv;
1704 lbs_deb_enter(LBS_DEB_WEXT);
1706 if (priv->wpa_ie_len == 0) {
1711 if (dwrq->length < priv->wpa_ie_len) {
1716 dwrq->length = priv->wpa_ie_len;
1717 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
1720 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1725 static int lbs_set_auth(struct net_device *dev,
1726 struct iw_request_info *info,
1727 struct iw_param *dwrq,
1730 struct lbs_private *priv = dev->ml_priv;
1731 struct assoc_request * assoc_req;
1735 lbs_deb_enter(LBS_DEB_WEXT);
1737 mutex_lock(&priv->lock);
1738 assoc_req = lbs_get_association_request(priv);
1744 switch (dwrq->flags & IW_AUTH_INDEX) {
1745 case IW_AUTH_PRIVACY_INVOKED:
1746 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1747 case IW_AUTH_TKIP_COUNTERMEASURES:
1748 case IW_AUTH_CIPHER_PAIRWISE:
1749 case IW_AUTH_CIPHER_GROUP:
1750 case IW_AUTH_DROP_UNENCRYPTED:
1752 * libertas does not use these parameters
1756 case IW_AUTH_KEY_MGMT:
1757 assoc_req->secinfo.key_mgmt = dwrq->value;
1761 case IW_AUTH_WPA_VERSION:
1762 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1763 assoc_req->secinfo.WPAenabled = 0;
1764 assoc_req->secinfo.WPA2enabled = 0;
1765 disable_wpa (assoc_req);
1767 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1768 assoc_req->secinfo.WPAenabled = 1;
1769 assoc_req->secinfo.wep_enabled = 0;
1770 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1772 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1773 assoc_req->secinfo.WPA2enabled = 1;
1774 assoc_req->secinfo.wep_enabled = 0;
1775 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1780 case IW_AUTH_80211_AUTH_ALG:
1781 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1782 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1783 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1784 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1785 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1786 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1793 case IW_AUTH_WPA_ENABLED:
1795 if (!assoc_req->secinfo.WPAenabled &&
1796 !assoc_req->secinfo.WPA2enabled) {
1797 assoc_req->secinfo.WPAenabled = 1;
1798 assoc_req->secinfo.WPA2enabled = 1;
1799 assoc_req->secinfo.wep_enabled = 0;
1800 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1803 assoc_req->secinfo.WPAenabled = 0;
1804 assoc_req->secinfo.WPA2enabled = 0;
1805 disable_wpa (assoc_req);
1818 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1819 lbs_postpone_association_work(priv);
1820 } else if (ret != -EOPNOTSUPP) {
1821 lbs_cancel_association_work(priv);
1823 mutex_unlock(&priv->lock);
1825 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1829 static int lbs_get_auth(struct net_device *dev,
1830 struct iw_request_info *info,
1831 struct iw_param *dwrq,
1835 struct lbs_private *priv = dev->ml_priv;
1837 lbs_deb_enter(LBS_DEB_WEXT);
1839 switch (dwrq->flags & IW_AUTH_INDEX) {
1840 case IW_AUTH_KEY_MGMT:
1841 dwrq->value = priv->secinfo.key_mgmt;
1844 case IW_AUTH_WPA_VERSION:
1846 if (priv->secinfo.WPAenabled)
1847 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1848 if (priv->secinfo.WPA2enabled)
1849 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1851 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1854 case IW_AUTH_80211_AUTH_ALG:
1855 dwrq->value = priv->secinfo.auth_mode;
1858 case IW_AUTH_WPA_ENABLED:
1859 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
1867 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1872 static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
1873 struct iw_param *vwrq, char *extra)
1876 struct lbs_private *priv = dev->ml_priv;
1877 s16 dbm = (s16) vwrq->value;
1879 lbs_deb_enter(LBS_DEB_WEXT);
1881 if (vwrq->disabled) {
1882 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
1886 if (vwrq->fixed == 0) {
1887 /* User requests automatic tx power control, however there are
1888 * many auto tx settings. For now use firmware defaults until
1889 * we come up with a good way to expose these to the user. */
1890 if (priv->fwrelease < 0x09000000) {
1891 ret = lbs_set_power_adapt_cfg(priv, 1,
1892 POW_ADAPT_DEFAULT_P0,
1893 POW_ADAPT_DEFAULT_P1,
1894 POW_ADAPT_DEFAULT_P2);
1898 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1902 dbm = priv->txpower_max;
1904 /* Userspace check in iwrange if it should use dBm or mW,
1905 * therefore this should never happen... Jean II */
1906 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1911 /* Validate requested power level against firmware allowed
1913 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1918 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1922 if (priv->fwrelease < 0x09000000) {
1923 ret = lbs_set_power_adapt_cfg(priv, 0,
1924 POW_ADAPT_DEFAULT_P0,
1925 POW_ADAPT_DEFAULT_P1,
1926 POW_ADAPT_DEFAULT_P2);
1930 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1936 /* If the radio was off, turn it on */
1937 if (!priv->radio_on) {
1938 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1943 lbs_deb_wext("txpower set %d dBm\n", dbm);
1945 ret = lbs_set_tx_power(priv, dbm);
1948 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1952 static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
1953 struct iw_point *dwrq, char *extra)
1955 struct lbs_private *priv = dev->ml_priv;
1957 lbs_deb_enter(LBS_DEB_WEXT);
1960 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1965 * Get the current SSID
1967 if (priv->connect_status == LBS_CONNECTED) {
1968 memcpy(extra, priv->curbssparams.ssid,
1969 priv->curbssparams.ssid_len);
1970 extra[priv->curbssparams.ssid_len] = '\0';
1972 memset(extra, 0, 32);
1973 extra[priv->curbssparams.ssid_len] = '\0';
1976 * If none, we may want to get the one that was set
1979 dwrq->length = priv->curbssparams.ssid_len;
1981 dwrq->flags = 1; /* active */
1983 lbs_deb_leave(LBS_DEB_WEXT);
1987 static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
1988 struct iw_point *dwrq, char *extra)
1990 struct lbs_private *priv = dev->ml_priv;
1992 u8 ssid[IW_ESSID_MAX_SIZE];
1994 struct assoc_request * assoc_req;
1995 int in_ssid_len = dwrq->length;
1996 DECLARE_SSID_BUF(ssid_buf);
1998 lbs_deb_enter(LBS_DEB_WEXT);
2000 if (!priv->radio_on) {
2005 /* Check the size of the string */
2006 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
2011 memset(&ssid, 0, sizeof(ssid));
2013 if (!dwrq->flags || !in_ssid_len) {
2014 /* "any" SSID requested; leave SSID blank */
2016 /* Specific SSID requested */
2017 memcpy(&ssid, extra, in_ssid_len);
2018 ssid_len = in_ssid_len;
2022 lbs_deb_wext("requested any SSID\n");
2024 lbs_deb_wext("requested SSID '%s'\n",
2025 print_ssid(ssid_buf, ssid, ssid_len));
2029 mutex_lock(&priv->lock);
2031 /* Get or create the current association request */
2032 assoc_req = lbs_get_association_request(priv);
2036 /* Copy the SSID to the association request */
2037 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
2038 assoc_req->ssid_len = ssid_len;
2039 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2040 lbs_postpone_association_work(priv);
2044 /* Cancel the association request if there was an error */
2046 lbs_cancel_association_work(priv);
2049 mutex_unlock(&priv->lock);
2051 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2055 static int lbs_mesh_get_essid(struct net_device *dev,
2056 struct iw_request_info *info,
2057 struct iw_point *dwrq, char *extra)
2059 struct lbs_private *priv = dev->ml_priv;
2061 lbs_deb_enter(LBS_DEB_WEXT);
2063 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2065 dwrq->length = priv->mesh_ssid_len;
2067 dwrq->flags = 1; /* active */
2069 lbs_deb_leave(LBS_DEB_WEXT);
2073 static int lbs_mesh_set_essid(struct net_device *dev,
2074 struct iw_request_info *info,
2075 struct iw_point *dwrq, char *extra)
2077 struct lbs_private *priv = dev->ml_priv;
2080 lbs_deb_enter(LBS_DEB_WEXT);
2082 if (!priv->radio_on) {
2087 /* Check the size of the string */
2088 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2093 if (!dwrq->flags || !dwrq->length) {
2097 /* Specific SSID requested */
2098 memcpy(priv->mesh_ssid, extra, dwrq->length);
2099 priv->mesh_ssid_len = dwrq->length;
2102 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2103 priv->curbssparams.channel);
2105 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2110 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2112 * @param dev A pointer to net_device structure
2113 * @param info A pointer to iw_request_info structure
2114 * @param awrq A pointer to iw_param structure
2115 * @param extra A pointer to extra data buf
2116 * @return 0 --success, otherwise fail
2118 static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
2119 struct sockaddr *awrq, char *extra)
2121 struct lbs_private *priv = dev->ml_priv;
2122 struct assoc_request * assoc_req;
2125 lbs_deb_enter(LBS_DEB_WEXT);
2127 if (!priv->radio_on)
2130 if (awrq->sa_family != ARPHRD_ETHER)
2133 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
2135 mutex_lock(&priv->lock);
2137 /* Get or create the current association request */
2138 assoc_req = lbs_get_association_request(priv);
2140 lbs_cancel_association_work(priv);
2143 /* Copy the BSSID to the association request */
2144 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2145 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2146 lbs_postpone_association_work(priv);
2149 mutex_unlock(&priv->lock);
2155 * iwconfig settable callbacks
2157 static const iw_handler lbs_handler[] = {
2158 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2159 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2160 (iw_handler) NULL, /* SIOCSIWNWID */
2161 (iw_handler) NULL, /* SIOCGIWNWID */
2162 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2163 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2164 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2165 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
2166 (iw_handler) NULL, /* SIOCSIWSENS */
2167 (iw_handler) NULL, /* SIOCGIWSENS */
2168 (iw_handler) NULL, /* SIOCSIWRANGE */
2169 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2170 (iw_handler) NULL, /* SIOCSIWPRIV */
2171 (iw_handler) NULL, /* SIOCGIWPRIV */
2172 (iw_handler) NULL, /* SIOCSIWSTATS */
2173 (iw_handler) NULL, /* SIOCGIWSTATS */
2174 iw_handler_set_spy, /* SIOCSIWSPY */
2175 iw_handler_get_spy, /* SIOCGIWSPY */
2176 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2177 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2178 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2179 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
2180 (iw_handler) NULL, /* SIOCSIWMLME */
2181 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2182 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2183 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2184 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2185 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2186 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2187 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
2188 (iw_handler) NULL, /* -- hole -- */
2189 (iw_handler) NULL, /* -- hole -- */
2190 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2191 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2192 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2193 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2194 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2195 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2196 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2197 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2198 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2199 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2200 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2201 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2202 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2203 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2204 (iw_handler) NULL, /* -- hole -- */
2205 (iw_handler) NULL, /* -- hole -- */
2206 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2207 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2208 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2209 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2210 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2211 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2212 (iw_handler) NULL, /* SIOCSIWPMKSA */
2215 static const iw_handler mesh_wlan_handler[] = {
2216 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2217 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2218 (iw_handler) NULL, /* SIOCSIWNWID */
2219 (iw_handler) NULL, /* SIOCGIWNWID */
2220 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
2221 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2222 (iw_handler) NULL, /* SIOCSIWMODE */
2223 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2224 (iw_handler) NULL, /* SIOCSIWSENS */
2225 (iw_handler) NULL, /* SIOCGIWSENS */
2226 (iw_handler) NULL, /* SIOCSIWRANGE */
2227 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2228 (iw_handler) NULL, /* SIOCSIWPRIV */
2229 (iw_handler) NULL, /* SIOCGIWPRIV */
2230 (iw_handler) NULL, /* SIOCSIWSTATS */
2231 (iw_handler) NULL, /* SIOCGIWSTATS */
2232 iw_handler_set_spy, /* SIOCSIWSPY */
2233 iw_handler_get_spy, /* SIOCGIWSPY */
2234 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2235 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2236 (iw_handler) NULL, /* SIOCSIWAP */
2237 (iw_handler) NULL, /* SIOCGIWAP */
2238 (iw_handler) NULL, /* SIOCSIWMLME */
2239 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2240 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2241 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2242 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2243 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
2244 (iw_handler) NULL, /* SIOCSIWNICKN */
2245 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2246 (iw_handler) NULL, /* -- hole -- */
2247 (iw_handler) NULL, /* -- hole -- */
2248 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2249 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2250 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2251 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2252 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2253 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2254 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2255 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2256 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2257 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2258 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2259 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2260 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2261 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2262 (iw_handler) NULL, /* -- hole -- */
2263 (iw_handler) NULL, /* -- hole -- */
2264 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2265 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2266 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2267 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2268 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2269 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2270 (iw_handler) NULL, /* SIOCSIWPMKSA */
2272 struct iw_handler_def lbs_handler_def = {
2273 .num_standard = ARRAY_SIZE(lbs_handler),
2274 .standard = (iw_handler *) lbs_handler,
2275 .get_wireless_stats = lbs_get_wireless_stats,
2278 struct iw_handler_def mesh_handler_def = {
2279 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
2280 .standard = (iw_handler *) mesh_wlan_handler,
2281 .get_wireless_stats = lbs_get_wireless_stats,