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;
48 void lbs_send_disconnect_notification(struct lbs_private *priv)
50 union iwreq_data wrqu;
52 memset(wrqu.ap_addr.sa_data, 0x00, ETH_ALEN);
53 wrqu.ap_addr.sa_family = ARPHRD_ETHER;
54 wireless_send_event(priv->dev, SIOCGIWAP, &wrqu, NULL);
57 void lbs_send_iwevcustom_event(struct lbs_private *priv, s8 *str)
59 union iwreq_data iwrq;
62 lbs_deb_enter(LBS_DEB_WEXT);
64 memset(&iwrq, 0, sizeof(union iwreq_data));
65 memset(buf, 0, sizeof(buf));
67 snprintf(buf, sizeof(buf) - 1, "%s", str);
69 iwrq.data.length = strlen(buf) + 1 + IW_EV_LCP_LEN;
71 /* Send Event to upper layer */
72 lbs_deb_wext("event indication string %s\n", (char *)buf);
73 lbs_deb_wext("event indication length %d\n", iwrq.data.length);
74 lbs_deb_wext("sending wireless event IWEVCUSTOM for %s\n", str);
76 wireless_send_event(priv->dev, IWEVCUSTOM, &iwrq, buf);
78 lbs_deb_leave(LBS_DEB_WEXT);
82 * @brief Find the channel frequency power info with specific channel
84 * @param priv A pointer to struct lbs_private structure
85 * @param band it can be BAND_A, BAND_G or BAND_B
86 * @param channel the channel for looking
87 * @return A pointer to struct chan_freq_power structure or NULL if not find.
89 struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
90 struct lbs_private *priv,
94 struct chan_freq_power *cfp = NULL;
95 struct region_channel *rc;
98 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
99 rc = &priv->region_channel[j];
101 if (!rc->valid || !rc->CFP)
103 if (rc->band != band)
105 for (i = 0; i < rc->nrcfp; i++) {
106 if (rc->CFP[i].channel == channel) {
114 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
115 "cfp by band %d / channel %d\n", band, channel);
121 * @brief Find the channel frequency power info with specific frequency
123 * @param priv A pointer to struct lbs_private structure
124 * @param band it can be BAND_A, BAND_G or BAND_B
125 * @param freq the frequency for looking
126 * @return A pointer to struct chan_freq_power structure or NULL if not find.
128 static struct chan_freq_power *find_cfp_by_band_and_freq(
129 struct lbs_private *priv,
133 struct chan_freq_power *cfp = NULL;
134 struct region_channel *rc;
137 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
138 rc = &priv->region_channel[j];
140 if (!rc->valid || !rc->CFP)
142 if (rc->band != band)
144 for (i = 0; i < rc->nrcfp; i++) {
145 if (rc->CFP[i].freq == freq) {
153 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
154 "band %d / freq %d\n", band, freq);
160 * @brief Copy active data rates based on adapter mode and status
162 * @param priv A pointer to struct lbs_private structure
163 * @param rate The buf to return the active rates
165 static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
167 lbs_deb_enter(LBS_DEB_WEXT);
169 if ((priv->connect_status != LBS_CONNECTED) &&
170 (priv->mesh_connect_status != LBS_CONNECTED))
171 memcpy(rates, lbs_bg_rates, MAX_RATES);
173 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
175 lbs_deb_leave(LBS_DEB_WEXT);
178 static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
179 char *cwrq, char *extra)
182 lbs_deb_enter(LBS_DEB_WEXT);
184 /* We could add support for 802.11n here as needed. Jean II */
185 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
187 lbs_deb_leave(LBS_DEB_WEXT);
191 static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
192 struct iw_freq *fwrq, char *extra)
194 struct lbs_private *priv = dev->ml_priv;
195 struct chan_freq_power *cfp;
197 lbs_deb_enter(LBS_DEB_WEXT);
199 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
204 lbs_deb_wext("invalid channel %d\n",
209 fwrq->m = (long)cfp->freq * 100000;
212 lbs_deb_wext("freq %u\n", fwrq->m);
213 lbs_deb_leave(LBS_DEB_WEXT);
217 static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
218 struct sockaddr *awrq, char *extra)
220 struct lbs_private *priv = dev->ml_priv;
222 lbs_deb_enter(LBS_DEB_WEXT);
224 if (priv->connect_status == LBS_CONNECTED) {
225 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
227 memset(awrq->sa_data, 0, ETH_ALEN);
229 awrq->sa_family = ARPHRD_ETHER;
231 lbs_deb_leave(LBS_DEB_WEXT);
235 static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
236 struct iw_point *dwrq, char *extra)
238 struct lbs_private *priv = dev->ml_priv;
240 lbs_deb_enter(LBS_DEB_WEXT);
243 * Check the size of the string
246 if (dwrq->length > 16) {
250 mutex_lock(&priv->lock);
251 memset(priv->nodename, 0, sizeof(priv->nodename));
252 memcpy(priv->nodename, extra, dwrq->length);
253 mutex_unlock(&priv->lock);
255 lbs_deb_leave(LBS_DEB_WEXT);
259 static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
260 struct iw_point *dwrq, char *extra)
262 struct lbs_private *priv = dev->ml_priv;
264 lbs_deb_enter(LBS_DEB_WEXT);
266 dwrq->length = strlen(priv->nodename);
267 memcpy(extra, priv->nodename, dwrq->length);
268 extra[dwrq->length] = '\0';
270 dwrq->flags = 1; /* active */
272 lbs_deb_leave(LBS_DEB_WEXT);
276 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
277 struct iw_point *dwrq, char *extra)
279 struct lbs_private *priv = dev->ml_priv;
281 lbs_deb_enter(LBS_DEB_WEXT);
283 /* Use nickname to indicate that mesh is on */
285 if (priv->mesh_connect_status == LBS_CONNECTED) {
286 strncpy(extra, "Mesh", 12);
288 dwrq->length = strlen(extra);
296 lbs_deb_leave(LBS_DEB_WEXT);
300 static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
301 struct iw_param *vwrq, char *extra)
304 struct lbs_private *priv = dev->ml_priv;
305 u32 val = vwrq->value;
307 lbs_deb_enter(LBS_DEB_WEXT);
310 val = MRVDRV_RTS_MAX_VALUE;
312 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
315 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
317 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
321 static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
322 struct iw_param *vwrq, char *extra)
324 struct lbs_private *priv = dev->ml_priv;
328 lbs_deb_enter(LBS_DEB_WEXT);
330 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
335 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
339 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
343 static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
344 struct iw_param *vwrq, char *extra)
346 struct lbs_private *priv = dev->ml_priv;
348 u32 val = vwrq->value;
350 lbs_deb_enter(LBS_DEB_WEXT);
353 val = MRVDRV_FRAG_MAX_VALUE;
355 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
358 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
360 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
364 static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
365 struct iw_param *vwrq, char *extra)
367 struct lbs_private *priv = dev->ml_priv;
371 lbs_deb_enter(LBS_DEB_WEXT);
373 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
378 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
379 || (val > MRVDRV_FRAG_MAX_VALUE));
383 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
387 static int lbs_get_mode(struct net_device *dev,
388 struct iw_request_info *info, u32 * uwrq, char *extra)
390 struct lbs_private *priv = dev->ml_priv;
392 lbs_deb_enter(LBS_DEB_WEXT);
396 lbs_deb_leave(LBS_DEB_WEXT);
400 static int mesh_wlan_get_mode(struct net_device *dev,
401 struct iw_request_info *info, u32 * uwrq,
404 lbs_deb_enter(LBS_DEB_WEXT);
406 *uwrq = IW_MODE_REPEAT;
408 lbs_deb_leave(LBS_DEB_WEXT);
412 static int lbs_get_txpow(struct net_device *dev,
413 struct iw_request_info *info,
414 struct iw_param *vwrq, char *extra)
416 struct lbs_private *priv = dev->ml_priv;
420 lbs_deb_enter(LBS_DEB_WEXT);
422 if (!priv->radio_on) {
423 lbs_deb_wext("tx power off\n");
429 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
433 lbs_deb_wext("tx power level %d dbm\n", curlevel);
434 priv->txpower_cur = curlevel;
436 vwrq->value = curlevel;
439 vwrq->flags = IW_TXPOW_DBM;
442 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
446 static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
447 struct iw_param *vwrq, char *extra)
449 struct lbs_private *priv = dev->ml_priv;
451 u16 slimit = 0, llimit = 0;
453 lbs_deb_enter(LBS_DEB_WEXT);
455 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
458 /* The MAC has a 4-bit Total_Tx_Count register
459 Total_Tx_Count = 1 + Tx_Retry_Count */
460 #define TX_RETRY_MIN 0
461 #define TX_RETRY_MAX 14
462 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
465 /* Add 1 to convert retry count to try count */
466 if (vwrq->flags & IW_RETRY_SHORT)
467 slimit = (u16) (vwrq->value + 1);
468 else if (vwrq->flags & IW_RETRY_LONG)
469 llimit = (u16) (vwrq->value + 1);
471 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
474 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
481 /* txretrycount follows the short retry limit */
482 priv->txretrycount = slimit;
483 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
490 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
494 static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
495 struct iw_param *vwrq, char *extra)
497 struct lbs_private *priv = dev->ml_priv;
501 lbs_deb_enter(LBS_DEB_WEXT);
505 if (vwrq->flags & IW_RETRY_LONG) {
506 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
510 /* Subtract 1 to convert try count to retry count */
511 vwrq->value = val - 1;
512 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
514 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
518 /* txretry count follows the short retry limit */
519 priv->txretrycount = val;
520 /* Subtract 1 to convert try count to retry count */
521 vwrq->value = val - 1;
522 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
526 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
530 static inline void sort_channels(struct iw_freq *freq, int num)
535 for (i = 0; i < num; i++)
536 for (j = i + 1; j < num; j++)
537 if (freq[i].i > freq[j].i) {
541 freq[i].i = freq[j].i;
542 freq[i].m = freq[j].m;
552 Infra G(12) A(8) B(4) G(12)
553 Adhoc A+B(12) A(8) B(4) B(4)
561 * @brief Get Range Info
563 * @param dev A pointer to net_device structure
564 * @param info A pointer to iw_request_info structure
565 * @param vwrq A pointer to iw_param structure
566 * @param extra A pointer to extra data buf
567 * @return 0 --success, otherwise fail
569 static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
570 struct iw_point *dwrq, char *extra)
573 struct lbs_private *priv = dev->ml_priv;
574 struct iw_range *range = (struct iw_range *)extra;
575 struct chan_freq_power *cfp;
576 u8 rates[MAX_RATES + 1];
578 lbs_deb_enter(LBS_DEB_WEXT);
580 dwrq->length = sizeof(struct iw_range);
581 memset(range, 0, sizeof(struct iw_range));
586 memset(rates, 0, sizeof(rates));
587 copy_active_data_rates(priv, rates);
588 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
589 for (i = 0; i < range->num_bitrates; i++)
590 range->bitrate[i] = rates[i] * 500000;
591 range->num_bitrates = i;
592 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
593 range->num_bitrates);
595 range->num_frequency = 0;
597 range->scan_capa = IW_SCAN_CAPA_ESSID;
599 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
600 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
601 cfp = priv->region_channel[j].CFP;
602 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
603 && priv->region_channel[j].valid
605 && (i < priv->region_channel[j].nrcfp); i++) {
606 range->freq[range->num_frequency].i =
608 range->freq[range->num_frequency].m =
609 (long)cfp->freq * 100000;
610 range->freq[range->num_frequency].e = 1;
612 range->num_frequency++;
616 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
617 IW_MAX_FREQUENCIES, range->num_frequency);
619 range->num_channels = range->num_frequency;
621 sort_channels(&range->freq[0], range->num_frequency);
624 * Set an indication of the max TCP throughput in bit/s that we can
625 * expect using this interface
628 range->throughput = 5000 * 1000;
630 range->throughput = 1500 * 1000;
632 range->min_rts = MRVDRV_RTS_MIN_VALUE;
633 range->max_rts = MRVDRV_RTS_MAX_VALUE;
634 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
635 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
637 range->encoding_size[0] = 5;
638 range->encoding_size[1] = 13;
639 range->num_encoding_sizes = 2;
640 range->max_encoding_tokens = 4;
643 * Right now we support only "iwconfig ethX power on|off"
645 range->pm_capa = IW_POWER_ON;
648 * Minimum version we recommend
650 range->we_version_source = 15;
653 * Version we are compiled with
655 range->we_version_compiled = WIRELESS_EXT;
657 range->retry_capa = IW_RETRY_LIMIT;
658 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
660 range->min_retry = TX_RETRY_MIN;
661 range->max_retry = TX_RETRY_MAX;
664 * Set the qual, level and noise range values
666 range->max_qual.qual = 100;
667 range->max_qual.level = 0;
668 range->max_qual.noise = 0;
669 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
671 range->avg_qual.qual = 70;
672 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
673 range->avg_qual.level = 0;
674 range->avg_qual.noise = 0;
675 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
677 range->sensitivity = 0;
679 /* Setup the supported power level ranges */
680 memset(range->txpower, 0, sizeof(range->txpower));
681 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
682 range->txpower[0] = priv->txpower_min;
683 range->txpower[1] = priv->txpower_max;
684 range->num_txpower = 2;
686 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
687 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
688 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
689 range->event_capa[1] = IW_EVENT_CAPA_K_1;
691 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
692 range->enc_capa = IW_ENC_CAPA_WPA
694 | IW_ENC_CAPA_CIPHER_TKIP
695 | IW_ENC_CAPA_CIPHER_CCMP;
698 lbs_deb_leave(LBS_DEB_WEXT);
702 static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
703 struct iw_param *vwrq, char *extra)
705 struct lbs_private *priv = dev->ml_priv;
708 lbs_deb_enter(LBS_DEB_WEXT);
710 if (!(priv->fwcapinfo & FW_CAPINFO_PS)) {
717 /* PS is currently supported only in Infrastructure mode
718 * Remove this check if it is to be supported in IBSS mode also
721 if (vwrq->disabled) {
722 priv->psmode = LBS802_11POWERMODECAM;
723 if (priv->psstate != PS_STATE_FULL_POWER) {
724 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
730 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
732 "setting power timeout is not supported\n");
734 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
735 vwrq->value = vwrq->value / 1000;
736 if (!priv->enter_deep_sleep) {
737 lbs_pr_err("deep sleep feature is not implemented "
738 "for this interface driver\n");
742 if (priv->connect_status == LBS_CONNECTED) {
743 if ((priv->is_auto_deep_sleep_enabled) &&
744 (vwrq->value == -1000)) {
745 lbs_exit_auto_deep_sleep(priv);
748 lbs_pr_err("can't use deep sleep cmd in "
749 "connected state\n");
754 if ((vwrq->value < 0) && (vwrq->value != -1000)) {
755 lbs_pr_err("unknown option\n");
759 if (vwrq->value > 0) {
760 if (!priv->is_auto_deep_sleep_enabled) {
761 priv->is_activity_detected = 0;
762 priv->auto_deep_sleep_timeout = vwrq->value;
763 lbs_enter_auto_deep_sleep(priv);
765 priv->auto_deep_sleep_timeout = vwrq->value;
766 lbs_deb_debugfs("auto deep sleep: "
767 "already enabled\n");
771 if (priv->is_auto_deep_sleep_enabled) {
772 lbs_exit_auto_deep_sleep(priv);
773 /* Try to exit deep sleep if auto */
774 /*deep sleep disabled */
775 ret = lbs_set_deep_sleep(priv, 0);
777 if (vwrq->value == 0)
778 ret = lbs_set_deep_sleep(priv, 1);
779 else if (vwrq->value == -1000)
780 ret = lbs_set_deep_sleep(priv, 0);
785 if (priv->psmode != LBS802_11POWERMODECAM) {
789 priv->psmode = LBS802_11POWERMODEMAX_PSP;
791 if (priv->connect_status == LBS_CONNECTED) {
792 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
795 lbs_deb_leave(LBS_DEB_WEXT);
800 static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
801 struct iw_param *vwrq, char *extra)
803 struct lbs_private *priv = dev->ml_priv;
805 lbs_deb_enter(LBS_DEB_WEXT);
809 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
810 || priv->connect_status == LBS_DISCONNECTED;
812 lbs_deb_leave(LBS_DEB_WEXT);
816 static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
826 struct lbs_private *priv = dev->ml_priv;
830 int ret, stats_valid = 0;
833 struct cmd_ds_802_11_get_log log;
835 lbs_deb_enter(LBS_DEB_WEXT);
837 priv->wstats.status = priv->mode;
839 /* If we're not associated, all quality values are meaningless */
840 if ((priv->connect_status != LBS_CONNECTED) &&
841 (priv->mesh_connect_status != LBS_CONNECTED))
844 /* Quality by RSSI */
845 priv->wstats.qual.level =
846 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
847 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
849 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
850 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
852 priv->wstats.qual.noise =
853 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
856 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
857 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
859 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
861 rssi_qual = rssi * POOR / 10;
863 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
865 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
867 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
870 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
874 /* Quality by TX errors */
875 priv->wstats.discard.retries = dev->stats.tx_errors;
877 memset(&log, 0, sizeof(log));
878 log.hdr.size = cpu_to_le16(sizeof(log));
879 ret = lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
883 tx_retries = le32_to_cpu(log.retry);
886 tx_qual = (90 - tx_retries) * POOR / 15;
887 else if (tx_retries > 70)
888 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
889 else if (tx_retries > 65)
890 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
891 else if (tx_retries > 50)
892 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
895 tx_qual = (50 - tx_retries) *
896 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
897 quality = min(quality, tx_qual);
899 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
900 priv->wstats.discard.retries = tx_retries;
901 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
903 /* Calculate quality */
904 priv->wstats.qual.qual = min_t(u8, quality, 100);
905 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
908 /* update stats asynchronously for future calls */
909 ret = lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
912 lbs_pr_err("RSSI command failed\n");
915 priv->wstats.miss.beacon = 0;
916 priv->wstats.discard.retries = 0;
917 priv->wstats.qual.qual = 0;
918 priv->wstats.qual.level = 0;
919 priv->wstats.qual.noise = 0;
920 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
921 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
922 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
925 lbs_deb_leave(LBS_DEB_WEXT);
926 return &priv->wstats;
931 static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
932 struct iw_freq *fwrq, char *extra)
935 struct lbs_private *priv = dev->ml_priv;
936 struct chan_freq_power *cfp;
937 struct assoc_request * assoc_req;
939 lbs_deb_enter(LBS_DEB_WEXT);
941 mutex_lock(&priv->lock);
942 assoc_req = lbs_get_association_request(priv);
948 /* If setting by frequency, convert to a channel */
950 long f = fwrq->m / 100000;
952 cfp = find_cfp_by_band_and_freq(priv, 0, f);
954 lbs_deb_wext("invalid freq %ld\n", f);
959 fwrq->m = (int) cfp->channel;
962 /* Setting by channel number */
963 if (fwrq->m > 1000 || fwrq->e > 0) {
967 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
972 assoc_req->channel = fwrq->m;
977 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
978 lbs_postpone_association_work(priv);
980 lbs_cancel_association_work(priv);
982 mutex_unlock(&priv->lock);
984 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
988 static int lbs_mesh_set_freq(struct net_device *dev,
989 struct iw_request_info *info,
990 struct iw_freq *fwrq, char *extra)
992 struct lbs_private *priv = dev->ml_priv;
993 struct chan_freq_power *cfp;
996 lbs_deb_enter(LBS_DEB_WEXT);
998 /* If setting by frequency, convert to a channel */
1000 long f = fwrq->m / 100000;
1002 cfp = find_cfp_by_band_and_freq(priv, 0, f);
1004 lbs_deb_wext("invalid freq %ld\n", f);
1009 fwrq->m = (int) cfp->channel;
1012 /* Setting by channel number */
1013 if (fwrq->m > 1000 || fwrq->e > 0) {
1017 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
1022 if (fwrq->m != priv->channel) {
1023 lbs_deb_wext("mesh channel change forces eth disconnect\n");
1024 if (priv->mode == IW_MODE_INFRA)
1025 lbs_cmd_80211_deauthenticate(priv,
1026 priv->curbssparams.bssid,
1027 WLAN_REASON_DEAUTH_LEAVING);
1028 else if (priv->mode == IW_MODE_ADHOC)
1029 lbs_adhoc_stop(priv);
1031 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
1032 lbs_update_channel(priv);
1036 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1040 static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
1041 struct iw_param *vwrq, char *extra)
1043 struct lbs_private *priv = dev->ml_priv;
1046 u8 rates[MAX_RATES + 1];
1048 lbs_deb_enter(LBS_DEB_WEXT);
1050 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
1051 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1053 if (vwrq->fixed && vwrq->value == -1)
1057 priv->enablehwauto = !vwrq->fixed;
1059 if (vwrq->value == -1)
1062 if (vwrq->value % 100000)
1065 new_rate = vwrq->value / 500000;
1066 priv->cur_rate = new_rate;
1067 /* the rest is only needed for lbs_set_data_rate() */
1068 memset(rates, 0, sizeof(rates));
1069 copy_active_data_rates(priv, rates);
1070 if (!memchr(rates, new_rate, sizeof(rates))) {
1071 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1075 if (priv->fwrelease < 0x09000000) {
1076 ret = lbs_set_power_adapt_cfg(priv, 0,
1077 POW_ADAPT_DEFAULT_P0,
1078 POW_ADAPT_DEFAULT_P1,
1079 POW_ADAPT_DEFAULT_P2);
1083 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1089 /* Try the newer command first (Firmware Spec 5.1 and above) */
1090 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1092 /* Fallback to older version */
1094 ret = lbs_set_data_rate(priv, new_rate);
1097 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1101 static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
1102 struct iw_param *vwrq, char *extra)
1104 struct lbs_private *priv = dev->ml_priv;
1106 lbs_deb_enter(LBS_DEB_WEXT);
1108 if (priv->connect_status == LBS_CONNECTED) {
1109 vwrq->value = priv->cur_rate * 500000;
1111 if (priv->enablehwauto)
1121 lbs_deb_leave(LBS_DEB_WEXT);
1125 static int lbs_set_mode(struct net_device *dev,
1126 struct iw_request_info *info, u32 * uwrq, char *extra)
1129 struct lbs_private *priv = dev->ml_priv;
1130 struct assoc_request * assoc_req;
1132 lbs_deb_enter(LBS_DEB_WEXT);
1134 if ( (*uwrq != IW_MODE_ADHOC)
1135 && (*uwrq != IW_MODE_INFRA)
1136 && (*uwrq != IW_MODE_AUTO)) {
1137 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1142 mutex_lock(&priv->lock);
1143 assoc_req = lbs_get_association_request(priv);
1146 lbs_cancel_association_work(priv);
1148 assoc_req->mode = *uwrq;
1149 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1150 lbs_postpone_association_work(priv);
1151 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1153 mutex_unlock(&priv->lock);
1156 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1162 * @brief Get Encryption key
1164 * @param dev A pointer to net_device structure
1165 * @param info A pointer to iw_request_info structure
1166 * @param vwrq A pointer to iw_param structure
1167 * @param extra A pointer to extra data buf
1168 * @return 0 --success, otherwise fail
1170 static int lbs_get_encode(struct net_device *dev,
1171 struct iw_request_info *info,
1172 struct iw_point *dwrq, u8 * extra)
1174 struct lbs_private *priv = dev->ml_priv;
1175 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1177 lbs_deb_enter(LBS_DEB_WEXT);
1179 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1180 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
1184 /* Authentication method */
1185 switch (priv->secinfo.auth_mode) {
1186 case IW_AUTH_ALG_OPEN_SYSTEM:
1187 dwrq->flags = IW_ENCODE_OPEN;
1190 case IW_AUTH_ALG_SHARED_KEY:
1191 case IW_AUTH_ALG_LEAP:
1192 dwrq->flags = IW_ENCODE_RESTRICTED;
1195 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1199 memset(extra, 0, 16);
1201 mutex_lock(&priv->lock);
1203 /* Default to returning current transmit key */
1205 index = priv->wep_tx_keyidx;
1207 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1208 memcpy(extra, priv->wep_keys[index].key,
1209 priv->wep_keys[index].len);
1210 dwrq->length = priv->wep_keys[index].len;
1212 dwrq->flags |= (index + 1);
1213 /* Return WEP enabled */
1214 dwrq->flags &= ~IW_ENCODE_DISABLED;
1215 } else if ((priv->secinfo.WPAenabled)
1216 || (priv->secinfo.WPA2enabled)) {
1217 /* return WPA enabled */
1218 dwrq->flags &= ~IW_ENCODE_DISABLED;
1219 dwrq->flags |= IW_ENCODE_NOKEY;
1221 dwrq->flags |= IW_ENCODE_DISABLED;
1224 mutex_unlock(&priv->lock);
1226 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
1227 extra[0], extra[1], extra[2],
1228 extra[3], extra[4], extra[5], dwrq->length);
1230 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1232 lbs_deb_leave(LBS_DEB_WEXT);
1237 * @brief Set Encryption key (internal)
1239 * @param priv A pointer to private card structure
1240 * @param key_material A pointer to key material
1241 * @param key_length length of key material
1242 * @param index key index to set
1243 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1244 * @return 0 --success, otherwise fail
1246 static int lbs_set_wep_key(struct assoc_request *assoc_req,
1247 const char *key_material,
1253 struct enc_key *pkey;
1255 lbs_deb_enter(LBS_DEB_WEXT);
1257 /* Paranoid validation of key index */
1263 /* validate max key length */
1264 if (key_length > KEY_LEN_WEP_104) {
1269 pkey = &assoc_req->wep_keys[index];
1271 if (key_length > 0) {
1272 memset(pkey, 0, sizeof(struct enc_key));
1273 pkey->type = KEY_TYPE_ID_WEP;
1275 /* Standardize the key length */
1276 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1277 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1278 memcpy(pkey->key, key_material, key_length);
1282 /* Ensure the chosen key is valid */
1284 lbs_deb_wext("key not set, so cannot enable it\n");
1288 assoc_req->wep_tx_keyidx = index;
1291 assoc_req->secinfo.wep_enabled = 1;
1294 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1298 static int validate_key_index(u16 def_index, u16 raw_index,
1299 u16 *out_index, u16 *is_default)
1301 if (!out_index || !is_default)
1304 /* Verify index if present, otherwise use default TX key index */
1305 if (raw_index > 0) {
1308 *out_index = raw_index - 1;
1310 *out_index = def_index;
1316 static void disable_wep(struct assoc_request *assoc_req)
1320 lbs_deb_enter(LBS_DEB_WEXT);
1322 /* Set Open System auth mode */
1323 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1325 /* Clear WEP keys and mark WEP as disabled */
1326 assoc_req->secinfo.wep_enabled = 0;
1327 for (i = 0; i < 4; i++)
1328 assoc_req->wep_keys[i].len = 0;
1330 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1331 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1333 lbs_deb_leave(LBS_DEB_WEXT);
1336 static void disable_wpa(struct assoc_request *assoc_req)
1338 lbs_deb_enter(LBS_DEB_WEXT);
1340 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
1341 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1342 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1344 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
1345 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1346 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1348 assoc_req->secinfo.WPAenabled = 0;
1349 assoc_req->secinfo.WPA2enabled = 0;
1350 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1352 lbs_deb_leave(LBS_DEB_WEXT);
1356 * @brief Set Encryption key
1358 * @param dev A pointer to net_device structure
1359 * @param info A pointer to iw_request_info structure
1360 * @param vwrq A pointer to iw_param structure
1361 * @param extra A pointer to extra data buf
1362 * @return 0 --success, otherwise fail
1364 static int lbs_set_encode(struct net_device *dev,
1365 struct iw_request_info *info,
1366 struct iw_point *dwrq, char *extra)
1369 struct lbs_private *priv = dev->ml_priv;
1370 struct assoc_request * assoc_req;
1371 u16 is_default = 0, index = 0, set_tx_key = 0;
1373 lbs_deb_enter(LBS_DEB_WEXT);
1375 mutex_lock(&priv->lock);
1376 assoc_req = lbs_get_association_request(priv);
1382 if (dwrq->flags & IW_ENCODE_DISABLED) {
1383 disable_wep (assoc_req);
1384 disable_wpa (assoc_req);
1388 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1389 (dwrq->flags & IW_ENCODE_INDEX),
1390 &index, &is_default);
1396 /* If WEP isn't enabled, or if there is no key data but a valid
1397 * index, set the TX key.
1399 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1402 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1407 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1409 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1411 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1412 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1413 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1414 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1419 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1420 lbs_postpone_association_work(priv);
1422 lbs_cancel_association_work(priv);
1424 mutex_unlock(&priv->lock);
1426 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1431 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1433 * @param dev A pointer to net_device structure
1434 * @param info A pointer to iw_request_info structure
1435 * @param vwrq A pointer to iw_param structure
1436 * @param extra A pointer to extra data buf
1437 * @return 0 on success, otherwise failure
1439 static int lbs_get_encodeext(struct net_device *dev,
1440 struct iw_request_info *info,
1441 struct iw_point *dwrq,
1445 struct lbs_private *priv = dev->ml_priv;
1446 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1447 int index, max_key_len;
1449 lbs_deb_enter(LBS_DEB_WEXT);
1451 max_key_len = dwrq->length - sizeof(*ext);
1452 if (max_key_len < 0)
1455 index = dwrq->flags & IW_ENCODE_INDEX;
1457 if (index < 1 || index > 4)
1461 index = priv->wep_tx_keyidx;
1464 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
1465 ext->alg != IW_ENCODE_ALG_WEP) {
1466 if (index != 0 || priv->mode != IW_MODE_INFRA)
1470 dwrq->flags = index + 1;
1471 memset(ext, 0, sizeof(*ext));
1473 if ( !priv->secinfo.wep_enabled
1474 && !priv->secinfo.WPAenabled
1475 && !priv->secinfo.WPA2enabled) {
1476 ext->alg = IW_ENCODE_ALG_NONE;
1478 dwrq->flags |= IW_ENCODE_DISABLED;
1482 if ( priv->secinfo.wep_enabled
1483 && !priv->secinfo.WPAenabled
1484 && !priv->secinfo.WPA2enabled) {
1486 ext->alg = IW_ENCODE_ALG_WEP;
1487 ext->key_len = priv->wep_keys[index].len;
1488 key = &priv->wep_keys[index].key[0];
1489 } else if ( !priv->secinfo.wep_enabled
1490 && (priv->secinfo.WPAenabled ||
1491 priv->secinfo.WPA2enabled)) {
1493 struct enc_key * pkey = NULL;
1495 if ( priv->wpa_mcast_key.len
1496 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1497 pkey = &priv->wpa_mcast_key;
1498 else if ( priv->wpa_unicast_key.len
1499 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1500 pkey = &priv->wpa_unicast_key;
1503 if (pkey->type == KEY_TYPE_ID_AES) {
1504 ext->alg = IW_ENCODE_ALG_CCMP;
1506 ext->alg = IW_ENCODE_ALG_TKIP;
1508 ext->key_len = pkey->len;
1509 key = &pkey->key[0];
1511 ext->alg = IW_ENCODE_ALG_TKIP;
1518 if (ext->key_len > max_key_len) {
1524 memcpy(ext->key, key, ext->key_len);
1526 dwrq->flags |= IW_ENCODE_NOKEY;
1527 dwrq->flags |= IW_ENCODE_ENABLED;
1532 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1537 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1539 * @param dev A pointer to net_device structure
1540 * @param info A pointer to iw_request_info structure
1541 * @param vwrq A pointer to iw_param structure
1542 * @param extra A pointer to extra data buf
1543 * @return 0 --success, otherwise fail
1545 static int lbs_set_encodeext(struct net_device *dev,
1546 struct iw_request_info *info,
1547 struct iw_point *dwrq,
1551 struct lbs_private *priv = dev->ml_priv;
1552 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1554 struct assoc_request * assoc_req;
1556 lbs_deb_enter(LBS_DEB_WEXT);
1558 mutex_lock(&priv->lock);
1559 assoc_req = lbs_get_association_request(priv);
1565 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1566 disable_wep (assoc_req);
1567 disable_wpa (assoc_req);
1568 } else if (alg == IW_ENCODE_ALG_WEP) {
1569 u16 is_default = 0, index, set_tx_key = 0;
1571 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1572 (dwrq->flags & IW_ENCODE_INDEX),
1573 &index, &is_default);
1577 /* If WEP isn't enabled, or if there is no key data but a valid
1578 * index, or if the set-TX-key flag was passed, set the TX key.
1580 if ( !assoc_req->secinfo.wep_enabled
1581 || (dwrq->length == 0 && !is_default)
1582 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1585 /* Copy key to driver */
1586 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
1591 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1592 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1593 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1594 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1597 /* Mark the various WEP bits as modified */
1598 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1600 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1602 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1603 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1604 struct enc_key * pkey;
1606 /* validate key length */
1607 if (((alg == IW_ENCODE_ALG_TKIP)
1608 && (ext->key_len != KEY_LEN_WPA_TKIP))
1609 || ((alg == IW_ENCODE_ALG_CCMP)
1610 && (ext->key_len != KEY_LEN_WPA_AES))) {
1611 lbs_deb_wext("invalid size %d for key of alg "
1619 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1620 pkey = &assoc_req->wpa_mcast_key;
1621 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1623 pkey = &assoc_req->wpa_unicast_key;
1624 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1627 memset(pkey, 0, sizeof (struct enc_key));
1628 memcpy(pkey->key, ext->key, ext->key_len);
1629 pkey->len = ext->key_len;
1631 pkey->flags |= KEY_INFO_WPA_ENABLED;
1633 /* Do this after zeroing key structure */
1634 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1635 pkey->flags |= KEY_INFO_WPA_MCAST;
1637 pkey->flags |= KEY_INFO_WPA_UNICAST;
1640 if (alg == IW_ENCODE_ALG_TKIP) {
1641 pkey->type = KEY_TYPE_ID_TKIP;
1642 } else if (alg == IW_ENCODE_ALG_CCMP) {
1643 pkey->type = KEY_TYPE_ID_AES;
1646 /* If WPA isn't enabled yet, do that now */
1647 if ( assoc_req->secinfo.WPAenabled == 0
1648 && assoc_req->secinfo.WPA2enabled == 0) {
1649 assoc_req->secinfo.WPAenabled = 1;
1650 assoc_req->secinfo.WPA2enabled = 1;
1651 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1654 /* Only disable wep if necessary: can't waste time here. */
1655 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1656 disable_wep(assoc_req);
1661 /* 802.1x and WPA rekeying must happen as quickly as possible,
1662 * especially during the 4-way handshake; thus if in
1663 * infrastructure mode, and either (a) 802.1x is enabled or
1664 * (b) WPA is being used, set the key right away.
1666 if (assoc_req->mode == IW_MODE_INFRA &&
1667 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1668 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1669 assoc_req->secinfo.WPAenabled ||
1670 assoc_req->secinfo.WPA2enabled)) {
1671 lbs_do_association_work(priv);
1673 lbs_postpone_association_work(priv);
1675 lbs_cancel_association_work(priv);
1677 mutex_unlock(&priv->lock);
1679 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1684 static int lbs_set_genie(struct net_device *dev,
1685 struct iw_request_info *info,
1686 struct iw_point *dwrq,
1689 struct lbs_private *priv = dev->ml_priv;
1691 struct assoc_request * assoc_req;
1693 lbs_deb_enter(LBS_DEB_WEXT);
1695 mutex_lock(&priv->lock);
1696 assoc_req = lbs_get_association_request(priv);
1702 if (dwrq->length > MAX_WPA_IE_LEN ||
1703 (dwrq->length && extra == NULL)) {
1709 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1710 assoc_req->wpa_ie_len = dwrq->length;
1712 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
1713 assoc_req->wpa_ie_len = 0;
1718 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1719 lbs_postpone_association_work(priv);
1721 lbs_cancel_association_work(priv);
1723 mutex_unlock(&priv->lock);
1725 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1729 static int lbs_get_genie(struct net_device *dev,
1730 struct iw_request_info *info,
1731 struct iw_point *dwrq,
1735 struct lbs_private *priv = dev->ml_priv;
1737 lbs_deb_enter(LBS_DEB_WEXT);
1739 if (priv->wpa_ie_len == 0) {
1744 if (dwrq->length < priv->wpa_ie_len) {
1749 dwrq->length = priv->wpa_ie_len;
1750 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
1753 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1758 static int lbs_set_auth(struct net_device *dev,
1759 struct iw_request_info *info,
1760 struct iw_param *dwrq,
1763 struct lbs_private *priv = dev->ml_priv;
1764 struct assoc_request * assoc_req;
1768 lbs_deb_enter(LBS_DEB_WEXT);
1770 mutex_lock(&priv->lock);
1771 assoc_req = lbs_get_association_request(priv);
1777 switch (dwrq->flags & IW_AUTH_INDEX) {
1778 case IW_AUTH_PRIVACY_INVOKED:
1779 case IW_AUTH_RX_UNENCRYPTED_EAPOL:
1780 case IW_AUTH_TKIP_COUNTERMEASURES:
1781 case IW_AUTH_CIPHER_PAIRWISE:
1782 case IW_AUTH_CIPHER_GROUP:
1783 case IW_AUTH_DROP_UNENCRYPTED:
1785 * libertas does not use these parameters
1789 case IW_AUTH_KEY_MGMT:
1790 assoc_req->secinfo.key_mgmt = dwrq->value;
1794 case IW_AUTH_WPA_VERSION:
1795 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1796 assoc_req->secinfo.WPAenabled = 0;
1797 assoc_req->secinfo.WPA2enabled = 0;
1798 disable_wpa (assoc_req);
1800 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1801 assoc_req->secinfo.WPAenabled = 1;
1802 assoc_req->secinfo.wep_enabled = 0;
1803 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1805 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1806 assoc_req->secinfo.WPA2enabled = 1;
1807 assoc_req->secinfo.wep_enabled = 0;
1808 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1813 case IW_AUTH_80211_AUTH_ALG:
1814 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1815 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1816 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1817 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1818 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1819 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1826 case IW_AUTH_WPA_ENABLED:
1828 if (!assoc_req->secinfo.WPAenabled &&
1829 !assoc_req->secinfo.WPA2enabled) {
1830 assoc_req->secinfo.WPAenabled = 1;
1831 assoc_req->secinfo.WPA2enabled = 1;
1832 assoc_req->secinfo.wep_enabled = 0;
1833 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1836 assoc_req->secinfo.WPAenabled = 0;
1837 assoc_req->secinfo.WPA2enabled = 0;
1838 disable_wpa (assoc_req);
1851 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1852 lbs_postpone_association_work(priv);
1853 } else if (ret != -EOPNOTSUPP) {
1854 lbs_cancel_association_work(priv);
1856 mutex_unlock(&priv->lock);
1858 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1862 static int lbs_get_auth(struct net_device *dev,
1863 struct iw_request_info *info,
1864 struct iw_param *dwrq,
1868 struct lbs_private *priv = dev->ml_priv;
1870 lbs_deb_enter(LBS_DEB_WEXT);
1872 switch (dwrq->flags & IW_AUTH_INDEX) {
1873 case IW_AUTH_KEY_MGMT:
1874 dwrq->value = priv->secinfo.key_mgmt;
1877 case IW_AUTH_WPA_VERSION:
1879 if (priv->secinfo.WPAenabled)
1880 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1881 if (priv->secinfo.WPA2enabled)
1882 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1884 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1887 case IW_AUTH_80211_AUTH_ALG:
1888 dwrq->value = priv->secinfo.auth_mode;
1891 case IW_AUTH_WPA_ENABLED:
1892 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
1900 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1905 static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
1906 struct iw_param *vwrq, char *extra)
1909 struct lbs_private *priv = dev->ml_priv;
1910 s16 dbm = (s16) vwrq->value;
1912 lbs_deb_enter(LBS_DEB_WEXT);
1914 if (vwrq->disabled) {
1915 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
1919 if (vwrq->fixed == 0) {
1920 /* User requests automatic tx power control, however there are
1921 * many auto tx settings. For now use firmware defaults until
1922 * we come up with a good way to expose these to the user. */
1923 if (priv->fwrelease < 0x09000000) {
1924 ret = lbs_set_power_adapt_cfg(priv, 1,
1925 POW_ADAPT_DEFAULT_P0,
1926 POW_ADAPT_DEFAULT_P1,
1927 POW_ADAPT_DEFAULT_P2);
1931 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1935 dbm = priv->txpower_max;
1937 /* Userspace check in iwrange if it should use dBm or mW,
1938 * therefore this should never happen... Jean II */
1939 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1944 /* Validate requested power level against firmware allowed
1946 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1951 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1955 if (priv->fwrelease < 0x09000000) {
1956 ret = lbs_set_power_adapt_cfg(priv, 0,
1957 POW_ADAPT_DEFAULT_P0,
1958 POW_ADAPT_DEFAULT_P1,
1959 POW_ADAPT_DEFAULT_P2);
1963 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1969 /* If the radio was off, turn it on */
1970 if (!priv->radio_on) {
1971 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1976 lbs_deb_wext("txpower set %d dBm\n", dbm);
1978 ret = lbs_set_tx_power(priv, dbm);
1981 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1985 static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
1986 struct iw_point *dwrq, char *extra)
1988 struct lbs_private *priv = dev->ml_priv;
1990 lbs_deb_enter(LBS_DEB_WEXT);
1993 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1998 * Get the current SSID
2000 if (priv->connect_status == LBS_CONNECTED) {
2001 memcpy(extra, priv->curbssparams.ssid,
2002 priv->curbssparams.ssid_len);
2003 extra[priv->curbssparams.ssid_len] = '\0';
2005 memset(extra, 0, 32);
2006 extra[priv->curbssparams.ssid_len] = '\0';
2009 * If none, we may want to get the one that was set
2012 dwrq->length = priv->curbssparams.ssid_len;
2014 dwrq->flags = 1; /* active */
2016 lbs_deb_leave(LBS_DEB_WEXT);
2020 static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
2021 struct iw_point *dwrq, char *extra)
2023 struct lbs_private *priv = dev->ml_priv;
2025 u8 ssid[IEEE80211_MAX_SSID_LEN];
2027 struct assoc_request * assoc_req;
2028 int in_ssid_len = dwrq->length;
2029 DECLARE_SSID_BUF(ssid_buf);
2031 lbs_deb_enter(LBS_DEB_WEXT);
2033 if (!priv->radio_on) {
2038 /* Check the size of the string */
2039 if (in_ssid_len > IEEE80211_MAX_SSID_LEN) {
2044 memset(&ssid, 0, sizeof(ssid));
2046 if (!dwrq->flags || !in_ssid_len) {
2047 /* "any" SSID requested; leave SSID blank */
2049 /* Specific SSID requested */
2050 memcpy(&ssid, extra, in_ssid_len);
2051 ssid_len = in_ssid_len;
2055 lbs_deb_wext("requested any SSID\n");
2057 lbs_deb_wext("requested SSID '%s'\n",
2058 print_ssid(ssid_buf, ssid, ssid_len));
2062 mutex_lock(&priv->lock);
2064 /* Get or create the current association request */
2065 assoc_req = lbs_get_association_request(priv);
2069 /* Copy the SSID to the association request */
2070 memcpy(&assoc_req->ssid, &ssid, IEEE80211_MAX_SSID_LEN);
2071 assoc_req->ssid_len = ssid_len;
2072 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2073 lbs_postpone_association_work(priv);
2077 /* Cancel the association request if there was an error */
2079 lbs_cancel_association_work(priv);
2082 mutex_unlock(&priv->lock);
2084 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2088 static int lbs_mesh_get_essid(struct net_device *dev,
2089 struct iw_request_info *info,
2090 struct iw_point *dwrq, char *extra)
2092 struct lbs_private *priv = dev->ml_priv;
2094 lbs_deb_enter(LBS_DEB_WEXT);
2096 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2098 dwrq->length = priv->mesh_ssid_len;
2100 dwrq->flags = 1; /* active */
2102 lbs_deb_leave(LBS_DEB_WEXT);
2106 static int lbs_mesh_set_essid(struct net_device *dev,
2107 struct iw_request_info *info,
2108 struct iw_point *dwrq, char *extra)
2110 struct lbs_private *priv = dev->ml_priv;
2113 lbs_deb_enter(LBS_DEB_WEXT);
2115 if (!priv->radio_on) {
2120 /* Check the size of the string */
2121 if (dwrq->length > IEEE80211_MAX_SSID_LEN) {
2126 if (!dwrq->flags || !dwrq->length) {
2130 /* Specific SSID requested */
2131 memcpy(priv->mesh_ssid, extra, dwrq->length);
2132 priv->mesh_ssid_len = dwrq->length;
2135 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2138 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2143 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2145 * @param dev A pointer to net_device structure
2146 * @param info A pointer to iw_request_info structure
2147 * @param awrq A pointer to iw_param structure
2148 * @param extra A pointer to extra data buf
2149 * @return 0 --success, otherwise fail
2151 static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
2152 struct sockaddr *awrq, char *extra)
2154 struct lbs_private *priv = dev->ml_priv;
2155 struct assoc_request * assoc_req;
2158 lbs_deb_enter(LBS_DEB_WEXT);
2160 if (!priv->radio_on)
2163 if (awrq->sa_family != ARPHRD_ETHER)
2166 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
2168 mutex_lock(&priv->lock);
2170 /* Get or create the current association request */
2171 assoc_req = lbs_get_association_request(priv);
2173 lbs_cancel_association_work(priv);
2176 /* Copy the BSSID to the association request */
2177 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2178 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2179 lbs_postpone_association_work(priv);
2182 mutex_unlock(&priv->lock);
2188 * iwconfig settable callbacks
2190 static const iw_handler lbs_handler[] = {
2191 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2192 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2193 (iw_handler) NULL, /* SIOCSIWNWID */
2194 (iw_handler) NULL, /* SIOCGIWNWID */
2195 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2196 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2197 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2198 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
2199 (iw_handler) NULL, /* SIOCSIWSENS */
2200 (iw_handler) NULL, /* SIOCGIWSENS */
2201 (iw_handler) NULL, /* SIOCSIWRANGE */
2202 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2203 (iw_handler) NULL, /* SIOCSIWPRIV */
2204 (iw_handler) NULL, /* SIOCGIWPRIV */
2205 (iw_handler) NULL, /* SIOCSIWSTATS */
2206 (iw_handler) NULL, /* SIOCGIWSTATS */
2207 iw_handler_set_spy, /* SIOCSIWSPY */
2208 iw_handler_get_spy, /* SIOCGIWSPY */
2209 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2210 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2211 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2212 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
2213 (iw_handler) NULL, /* SIOCSIWMLME */
2214 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2215 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2216 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2217 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2218 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2219 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2220 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
2221 (iw_handler) NULL, /* -- hole -- */
2222 (iw_handler) NULL, /* -- hole -- */
2223 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2224 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2225 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2226 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2227 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2228 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2229 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2230 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2231 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2232 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2233 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2234 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2235 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2236 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2237 (iw_handler) NULL, /* -- hole -- */
2238 (iw_handler) NULL, /* -- hole -- */
2239 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2240 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2241 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2242 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2243 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2244 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2245 (iw_handler) NULL, /* SIOCSIWPMKSA */
2248 static const iw_handler mesh_wlan_handler[] = {
2249 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2250 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2251 (iw_handler) NULL, /* SIOCSIWNWID */
2252 (iw_handler) NULL, /* SIOCGIWNWID */
2253 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
2254 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2255 (iw_handler) NULL, /* SIOCSIWMODE */
2256 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2257 (iw_handler) NULL, /* SIOCSIWSENS */
2258 (iw_handler) NULL, /* SIOCGIWSENS */
2259 (iw_handler) NULL, /* SIOCSIWRANGE */
2260 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2261 (iw_handler) NULL, /* SIOCSIWPRIV */
2262 (iw_handler) NULL, /* SIOCGIWPRIV */
2263 (iw_handler) NULL, /* SIOCSIWSTATS */
2264 (iw_handler) NULL, /* SIOCGIWSTATS */
2265 iw_handler_set_spy, /* SIOCSIWSPY */
2266 iw_handler_get_spy, /* SIOCGIWSPY */
2267 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2268 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2269 (iw_handler) NULL, /* SIOCSIWAP */
2270 (iw_handler) NULL, /* SIOCGIWAP */
2271 (iw_handler) NULL, /* SIOCSIWMLME */
2272 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2273 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2274 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2275 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2276 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
2277 (iw_handler) NULL, /* SIOCSIWNICKN */
2278 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2279 (iw_handler) NULL, /* -- hole -- */
2280 (iw_handler) NULL, /* -- hole -- */
2281 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2282 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2283 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2284 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2285 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2286 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2287 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2288 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2289 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2290 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2291 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2292 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2293 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2294 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2295 (iw_handler) NULL, /* -- hole -- */
2296 (iw_handler) NULL, /* -- hole -- */
2297 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2298 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2299 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2300 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2301 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2302 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2303 (iw_handler) NULL, /* SIOCSIWPMKSA */
2305 struct iw_handler_def lbs_handler_def = {
2306 .num_standard = ARRAY_SIZE(lbs_handler),
2307 .standard = (iw_handler *) lbs_handler,
2308 .get_wireless_stats = lbs_get_wireless_stats,
2311 struct iw_handler_def mesh_handler_def = {
2312 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
2313 .standard = (iw_handler *) mesh_wlan_handler,
2314 .get_wireless_stats = lbs_get_wireless_stats,