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/ieee80211.h>
13 #include <net/iw_handler.h>
26 static inline void lbs_postpone_association_work(struct lbs_private *priv)
28 if (priv->surpriseremoved)
30 cancel_delayed_work(&priv->assoc_work);
31 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
34 static inline void lbs_do_association_work(struct lbs_private *priv)
36 if (priv->surpriseremoved)
38 cancel_delayed_work(&priv->assoc_work);
39 queue_delayed_work(priv->work_thread, &priv->assoc_work, 0);
42 static inline void lbs_cancel_association_work(struct lbs_private *priv)
44 cancel_delayed_work(&priv->assoc_work);
45 kfree(priv->pending_assoc_req);
46 priv->pending_assoc_req = NULL;
51 * @brief Find the channel frequency power info with specific channel
53 * @param priv A pointer to struct lbs_private structure
54 * @param band it can be BAND_A, BAND_G or BAND_B
55 * @param channel the channel for looking
56 * @return A pointer to struct chan_freq_power structure or NULL if not find.
58 struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
59 struct lbs_private *priv,
63 struct chan_freq_power *cfp = NULL;
64 struct region_channel *rc;
67 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
68 rc = &priv->region_channel[j];
71 rc = &priv->universal_channel[j];
72 if (!rc->valid || !rc->CFP)
76 for (i = 0; i < rc->nrcfp; i++) {
77 if (rc->CFP[i].channel == channel) {
85 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
86 "cfp by band %d / channel %d\n", band, channel);
92 * @brief Find the channel frequency power info with specific frequency
94 * @param priv A pointer to struct lbs_private structure
95 * @param band it can be BAND_A, BAND_G or BAND_B
96 * @param freq the frequency for looking
97 * @return A pointer to struct chan_freq_power structure or NULL if not find.
99 static struct chan_freq_power *find_cfp_by_band_and_freq(
100 struct lbs_private *priv,
104 struct chan_freq_power *cfp = NULL;
105 struct region_channel *rc;
108 for (j = 0; !cfp && (j < ARRAY_SIZE(priv->region_channel)); j++) {
109 rc = &priv->region_channel[j];
112 rc = &priv->universal_channel[j];
113 if (!rc->valid || !rc->CFP)
115 if (rc->band != band)
117 for (i = 0; i < rc->nrcfp; i++) {
118 if (rc->CFP[i].freq == freq) {
126 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
127 "band %d / freq %d\n", band, freq);
133 * @brief Copy active data rates based on adapter mode and status
135 * @param priv A pointer to struct lbs_private structure
136 * @param rate The buf to return the active rates
138 static void copy_active_data_rates(struct lbs_private *priv, u8 *rates)
140 lbs_deb_enter(LBS_DEB_WEXT);
142 if ((priv->connect_status != LBS_CONNECTED) &&
143 (priv->mesh_connect_status != LBS_CONNECTED))
144 memcpy(rates, lbs_bg_rates, MAX_RATES);
146 memcpy(rates, priv->curbssparams.rates, MAX_RATES);
148 lbs_deb_leave(LBS_DEB_WEXT);
151 static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
152 char *cwrq, char *extra)
155 lbs_deb_enter(LBS_DEB_WEXT);
157 /* We could add support for 802.11n here as needed. Jean II */
158 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
160 lbs_deb_leave(LBS_DEB_WEXT);
164 static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
165 struct iw_freq *fwrq, char *extra)
167 struct lbs_private *priv = dev->priv;
168 struct chan_freq_power *cfp;
170 lbs_deb_enter(LBS_DEB_WEXT);
172 cfp = lbs_find_cfp_by_band_and_channel(priv, 0,
173 priv->curbssparams.channel);
176 if (priv->curbssparams.channel)
177 lbs_deb_wext("invalid channel %d\n",
178 priv->curbssparams.channel);
182 fwrq->m = (long)cfp->freq * 100000;
185 lbs_deb_wext("freq %u\n", fwrq->m);
186 lbs_deb_leave(LBS_DEB_WEXT);
190 static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
191 struct sockaddr *awrq, char *extra)
193 struct lbs_private *priv = dev->priv;
195 lbs_deb_enter(LBS_DEB_WEXT);
197 if (priv->connect_status == LBS_CONNECTED) {
198 memcpy(awrq->sa_data, priv->curbssparams.bssid, ETH_ALEN);
200 memset(awrq->sa_data, 0, ETH_ALEN);
202 awrq->sa_family = ARPHRD_ETHER;
204 lbs_deb_leave(LBS_DEB_WEXT);
208 static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
209 struct iw_point *dwrq, char *extra)
211 struct lbs_private *priv = dev->priv;
213 lbs_deb_enter(LBS_DEB_WEXT);
216 * Check the size of the string
219 if (dwrq->length > 16) {
223 mutex_lock(&priv->lock);
224 memset(priv->nodename, 0, sizeof(priv->nodename));
225 memcpy(priv->nodename, extra, dwrq->length);
226 mutex_unlock(&priv->lock);
228 lbs_deb_leave(LBS_DEB_WEXT);
232 static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
233 struct iw_point *dwrq, char *extra)
235 struct lbs_private *priv = dev->priv;
237 lbs_deb_enter(LBS_DEB_WEXT);
239 dwrq->length = strlen(priv->nodename);
240 memcpy(extra, priv->nodename, dwrq->length);
241 extra[dwrq->length] = '\0';
243 dwrq->flags = 1; /* active */
245 lbs_deb_leave(LBS_DEB_WEXT);
249 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
250 struct iw_point *dwrq, char *extra)
252 struct lbs_private *priv = dev->priv;
254 lbs_deb_enter(LBS_DEB_WEXT);
256 /* Use nickname to indicate that mesh is on */
258 if (priv->mesh_connect_status == LBS_CONNECTED) {
259 strncpy(extra, "Mesh", 12);
261 dwrq->length = strlen(extra);
269 lbs_deb_leave(LBS_DEB_WEXT);
273 static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
274 struct iw_param *vwrq, char *extra)
277 struct lbs_private *priv = dev->priv;
278 u32 val = vwrq->value;
280 lbs_deb_enter(LBS_DEB_WEXT);
283 val = MRVDRV_RTS_MAX_VALUE;
285 if (val > MRVDRV_RTS_MAX_VALUE) /* min rts value is 0 */
288 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, (u16) val);
290 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
294 static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
295 struct iw_param *vwrq, char *extra)
297 struct lbs_private *priv = dev->priv;
301 lbs_deb_enter(LBS_DEB_WEXT);
303 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_RTS_THRESHOLD, &val);
308 vwrq->disabled = val > MRVDRV_RTS_MAX_VALUE; /* min rts value is 0 */
312 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
316 static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
317 struct iw_param *vwrq, char *extra)
319 struct lbs_private *priv = dev->priv;
321 u32 val = vwrq->value;
323 lbs_deb_enter(LBS_DEB_WEXT);
326 val = MRVDRV_FRAG_MAX_VALUE;
328 if (val < MRVDRV_FRAG_MIN_VALUE || val > MRVDRV_FRAG_MAX_VALUE)
331 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, (u16) val);
333 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
337 static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
338 struct iw_param *vwrq, char *extra)
340 struct lbs_private *priv = dev->priv;
344 lbs_deb_enter(LBS_DEB_WEXT);
346 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_FRAG_THRESHOLD, &val);
351 vwrq->disabled = ((val < MRVDRV_FRAG_MIN_VALUE)
352 || (val > MRVDRV_FRAG_MAX_VALUE));
356 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
360 static int lbs_get_mode(struct net_device *dev,
361 struct iw_request_info *info, u32 * uwrq, char *extra)
363 struct lbs_private *priv = dev->priv;
365 lbs_deb_enter(LBS_DEB_WEXT);
369 lbs_deb_leave(LBS_DEB_WEXT);
373 static int mesh_wlan_get_mode(struct net_device *dev,
374 struct iw_request_info *info, u32 * uwrq,
377 lbs_deb_enter(LBS_DEB_WEXT);
379 *uwrq = IW_MODE_REPEAT;
381 lbs_deb_leave(LBS_DEB_WEXT);
385 static int lbs_get_txpow(struct net_device *dev,
386 struct iw_request_info *info,
387 struct iw_param *vwrq, char *extra)
389 struct lbs_private *priv = dev->priv;
393 lbs_deb_enter(LBS_DEB_WEXT);
395 if (!priv->radio_on) {
396 lbs_deb_wext("tx power off\n");
402 ret = lbs_get_tx_power(priv, &curlevel, NULL, NULL);
406 lbs_deb_wext("tx power level %d dbm\n", curlevel);
407 priv->txpower_cur = curlevel;
409 vwrq->value = curlevel;
412 vwrq->flags = IW_TXPOW_DBM;
415 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
419 static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
420 struct iw_param *vwrq, char *extra)
422 struct lbs_private *priv = dev->priv;
424 u16 slimit = 0, llimit = 0;
426 lbs_deb_enter(LBS_DEB_WEXT);
428 if ((vwrq->flags & IW_RETRY_TYPE) != IW_RETRY_LIMIT)
431 /* The MAC has a 4-bit Total_Tx_Count register
432 Total_Tx_Count = 1 + Tx_Retry_Count */
433 #define TX_RETRY_MIN 0
434 #define TX_RETRY_MAX 14
435 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
438 /* Add 1 to convert retry count to try count */
439 if (vwrq->flags & IW_RETRY_SHORT)
440 slimit = (u16) (vwrq->value + 1);
441 else if (vwrq->flags & IW_RETRY_LONG)
442 llimit = (u16) (vwrq->value + 1);
444 slimit = llimit = (u16) (vwrq->value + 1); /* set both */
447 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT,
454 /* txretrycount follows the short retry limit */
455 priv->txretrycount = slimit;
456 ret = lbs_set_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT,
463 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
467 static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
468 struct iw_param *vwrq, char *extra)
470 struct lbs_private *priv = dev->priv;
474 lbs_deb_enter(LBS_DEB_WEXT);
478 if (vwrq->flags & IW_RETRY_LONG) {
479 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_LONG_RETRY_LIMIT, &val);
483 /* Subtract 1 to convert try count to retry count */
484 vwrq->value = val - 1;
485 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_LONG;
487 ret = lbs_get_snmp_mib(priv, SNMP_MIB_OID_SHORT_RETRY_LIMIT, &val);
491 /* txretry count follows the short retry limit */
492 priv->txretrycount = val;
493 /* Subtract 1 to convert try count to retry count */
494 vwrq->value = val - 1;
495 vwrq->flags = IW_RETRY_LIMIT | IW_RETRY_SHORT;
499 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
503 static inline void sort_channels(struct iw_freq *freq, int num)
508 for (i = 0; i < num; i++)
509 for (j = i + 1; j < num; j++)
510 if (freq[i].i > freq[j].i) {
514 freq[i].i = freq[j].i;
515 freq[i].m = freq[j].m;
525 Infra G(12) A(8) B(4) G(12)
526 Adhoc A+B(12) A(8) B(4) B(4)
534 * @brief Get Range Info
536 * @param dev A pointer to net_device structure
537 * @param info A pointer to iw_request_info structure
538 * @param vwrq A pointer to iw_param structure
539 * @param extra A pointer to extra data buf
540 * @return 0 --success, otherwise fail
542 static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
543 struct iw_point *dwrq, char *extra)
546 struct lbs_private *priv = dev->priv;
547 struct iw_range *range = (struct iw_range *)extra;
548 struct chan_freq_power *cfp;
549 u8 rates[MAX_RATES + 1];
553 lbs_deb_enter(LBS_DEB_WEXT);
555 dwrq->length = sizeof(struct iw_range);
556 memset(range, 0, sizeof(struct iw_range));
561 memset(rates, 0, sizeof(rates));
562 copy_active_data_rates(priv, rates);
563 range->num_bitrates = strnlen(rates, IW_MAX_BITRATES);
564 for (i = 0; i < range->num_bitrates; i++)
565 range->bitrate[i] = rates[i] * 500000;
566 range->num_bitrates = i;
567 lbs_deb_wext("IW_MAX_BITRATES %d, num_bitrates %d\n", IW_MAX_BITRATES,
568 range->num_bitrates);
570 range->num_frequency = 0;
572 range->scan_capa = IW_SCAN_CAPA_ESSID;
574 if (priv->enable11d &&
575 (priv->connect_status == LBS_CONNECTED ||
576 priv->mesh_connect_status == LBS_CONNECTED)) {
580 struct parsed_region_chan_11d *parsed_region_chan =
581 &priv->parsed_region_chan;
583 if (parsed_region_chan == NULL) {
584 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
587 band = parsed_region_chan->band;
588 lbs_deb_wext("band %d, nr_char %d\n", band,
589 parsed_region_chan->nr_chan);
591 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
592 && (i < parsed_region_chan->nr_chan); i++) {
593 chan_no = parsed_region_chan->chanpwr[i].chan;
594 lbs_deb_wext("chan_no %d\n", chan_no);
595 range->freq[range->num_frequency].i = (long)chan_no;
596 range->freq[range->num_frequency].m =
597 (long)lbs_chan_2_freq(chan_no) * 100000;
598 range->freq[range->num_frequency].e = 1;
599 range->num_frequency++;
604 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
605 && (j < ARRAY_SIZE(priv->region_channel)); j++) {
606 cfp = priv->region_channel[j].CFP;
607 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
608 && priv->region_channel[j].valid
610 && (i < priv->region_channel[j].nrcfp); i++) {
611 range->freq[range->num_frequency].i =
613 range->freq[range->num_frequency].m =
614 (long)cfp->freq * 100000;
615 range->freq[range->num_frequency].e = 1;
617 range->num_frequency++;
622 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
623 IW_MAX_FREQUENCIES, range->num_frequency);
625 range->num_channels = range->num_frequency;
627 sort_channels(&range->freq[0], range->num_frequency);
630 * Set an indication of the max TCP throughput in bit/s that we can
631 * expect using this interface
634 range->throughput = 5000 * 1000;
636 range->throughput = 1500 * 1000;
638 range->min_rts = MRVDRV_RTS_MIN_VALUE;
639 range->max_rts = MRVDRV_RTS_MAX_VALUE;
640 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
641 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
643 range->encoding_size[0] = 5;
644 range->encoding_size[1] = 13;
645 range->num_encoding_sizes = 2;
646 range->max_encoding_tokens = 4;
649 * Right now we support only "iwconfig ethX power on|off"
651 range->pm_capa = IW_POWER_ON;
654 * Minimum version we recommend
656 range->we_version_source = 15;
659 * Version we are compiled with
661 range->we_version_compiled = WIRELESS_EXT;
663 range->retry_capa = IW_RETRY_LIMIT;
664 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
666 range->min_retry = TX_RETRY_MIN;
667 range->max_retry = TX_RETRY_MAX;
670 * Set the qual, level and noise range values
672 range->max_qual.qual = 100;
673 range->max_qual.level = 0;
674 range->max_qual.noise = 0;
675 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
677 range->avg_qual.qual = 70;
678 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
679 range->avg_qual.level = 0;
680 range->avg_qual.noise = 0;
681 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
683 range->sensitivity = 0;
685 /* Setup the supported power level ranges */
686 memset(range->txpower, 0, sizeof(range->txpower));
687 range->txpower_capa = IW_TXPOW_DBM | IW_TXPOW_RANGE;
688 range->txpower[0] = priv->txpower_min;
689 range->txpower[1] = priv->txpower_max;
690 range->num_txpower = 2;
692 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
693 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
694 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
695 range->event_capa[1] = IW_EVENT_CAPA_K_1;
697 if (priv->fwcapinfo & FW_CAPINFO_WPA) {
698 range->enc_capa = IW_ENC_CAPA_WPA
700 | IW_ENC_CAPA_CIPHER_TKIP
701 | IW_ENC_CAPA_CIPHER_CCMP;
705 lbs_deb_leave(LBS_DEB_WEXT);
709 static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
710 struct iw_param *vwrq, char *extra)
712 struct lbs_private *priv = dev->priv;
714 lbs_deb_enter(LBS_DEB_WEXT);
716 if (!priv->ps_supported) {
723 /* PS is currently supported only in Infrastructure mode
724 * Remove this check if it is to be supported in IBSS mode also
727 if (vwrq->disabled) {
728 priv->psmode = LBS802_11POWERMODECAM;
729 if (priv->psstate != PS_STATE_FULL_POWER) {
730 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
736 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
738 "setting power timeout is not supported\n");
740 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
741 lbs_deb_wext("setting power period not supported\n");
745 if (priv->psmode != LBS802_11POWERMODECAM) {
749 priv->psmode = LBS802_11POWERMODEMAX_PSP;
751 if (priv->connect_status == LBS_CONNECTED) {
752 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
755 lbs_deb_leave(LBS_DEB_WEXT);
759 static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
760 struct iw_param *vwrq, char *extra)
762 struct lbs_private *priv = dev->priv;
764 lbs_deb_enter(LBS_DEB_WEXT);
768 vwrq->disabled = priv->psmode == LBS802_11POWERMODECAM
769 || priv->connect_status == LBS_DISCONNECTED;
771 lbs_deb_leave(LBS_DEB_WEXT);
775 static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
785 struct lbs_private *priv = dev->priv;
792 struct cmd_ds_802_11_get_log log;
794 lbs_deb_enter(LBS_DEB_WEXT);
796 priv->wstats.status = priv->mode;
798 /* If we're not associated, all quality values are meaningless */
799 if ((priv->connect_status != LBS_CONNECTED) &&
800 (priv->mesh_connect_status != LBS_CONNECTED))
803 /* Quality by RSSI */
804 priv->wstats.qual.level =
805 CAL_RSSI(priv->SNR[TYPE_BEACON][TYPE_NOAVG],
806 priv->NF[TYPE_BEACON][TYPE_NOAVG]);
808 if (priv->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
809 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
811 priv->wstats.qual.noise =
812 CAL_NF(priv->NF[TYPE_BEACON][TYPE_NOAVG]);
815 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
816 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
818 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
820 rssi_qual = rssi * POOR / 10;
822 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
824 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
826 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
829 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
833 /* Quality by TX errors */
834 priv->wstats.discard.retries = priv->stats.tx_errors;
836 memset(&log, 0, sizeof(log));
837 log.hdr.size = cpu_to_le16(sizeof(log));
838 lbs_cmd_with_response(priv, CMD_802_11_GET_LOG, &log);
840 tx_retries = le32_to_cpu(log.retry);
843 tx_qual = (90 - tx_retries) * POOR / 15;
844 else if (tx_retries > 70)
845 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
846 else if (tx_retries > 65)
847 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
848 else if (tx_retries > 50)
849 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
852 tx_qual = (50 - tx_retries) *
853 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
854 quality = min(quality, tx_qual);
856 priv->wstats.discard.code = le32_to_cpu(log.wepundecryptable);
857 priv->wstats.discard.retries = tx_retries;
858 priv->wstats.discard.misc = le32_to_cpu(log.ackfailure);
860 /* Calculate quality */
861 priv->wstats.qual.qual = min_t(u8, quality, 100);
862 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
865 /* update stats asynchronously for future calls */
866 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
870 priv->wstats.miss.beacon = 0;
871 priv->wstats.discard.retries = 0;
872 priv->wstats.qual.qual = 0;
873 priv->wstats.qual.level = 0;
874 priv->wstats.qual.noise = 0;
875 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
876 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
877 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
880 lbs_deb_leave(LBS_DEB_WEXT);
881 return &priv->wstats;
886 static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
887 struct iw_freq *fwrq, char *extra)
890 struct lbs_private *priv = dev->priv;
891 struct chan_freq_power *cfp;
892 struct assoc_request * assoc_req;
894 lbs_deb_enter(LBS_DEB_WEXT);
896 mutex_lock(&priv->lock);
897 assoc_req = lbs_get_association_request(priv);
903 /* If setting by frequency, convert to a channel */
905 long f = fwrq->m / 100000;
907 cfp = find_cfp_by_band_and_freq(priv, 0, f);
909 lbs_deb_wext("invalid freq %ld\n", f);
914 fwrq->m = (int) cfp->channel;
917 /* Setting by channel number */
918 if (fwrq->m > 1000 || fwrq->e > 0) {
922 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
927 assoc_req->channel = fwrq->m;
932 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
933 lbs_postpone_association_work(priv);
935 lbs_cancel_association_work(priv);
937 mutex_unlock(&priv->lock);
939 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
943 static int lbs_mesh_set_freq(struct net_device *dev,
944 struct iw_request_info *info,
945 struct iw_freq *fwrq, char *extra)
947 struct lbs_private *priv = dev->priv;
948 struct chan_freq_power *cfp;
951 lbs_deb_enter(LBS_DEB_WEXT);
953 /* If setting by frequency, convert to a channel */
955 long f = fwrq->m / 100000;
957 cfp = find_cfp_by_band_and_freq(priv, 0, f);
959 lbs_deb_wext("invalid freq %ld\n", f);
964 fwrq->m = (int) cfp->channel;
967 /* Setting by channel number */
968 if (fwrq->m > 1000 || fwrq->e > 0) {
972 cfp = lbs_find_cfp_by_band_and_channel(priv, 0, fwrq->m);
977 if (fwrq->m != priv->curbssparams.channel) {
978 lbs_deb_wext("mesh channel change forces eth disconnect\n");
979 if (priv->mode == IW_MODE_INFRA)
980 lbs_cmd_80211_deauthenticate(priv,
981 priv->curbssparams.bssid,
982 WLAN_REASON_DEAUTH_LEAVING);
983 else if (priv->mode == IW_MODE_ADHOC)
984 lbs_adhoc_stop(priv);
986 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START, fwrq->m);
987 lbs_update_channel(priv);
991 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
995 static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
996 struct iw_param *vwrq, char *extra)
998 struct lbs_private *priv = dev->priv;
1001 u8 rates[MAX_RATES + 1];
1003 lbs_deb_enter(LBS_DEB_WEXT);
1004 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
1005 lbs_deb_wext("vwrq->fixed %d\n", vwrq->fixed);
1007 if (vwrq->fixed && vwrq->value == -1)
1011 priv->enablehwauto = !vwrq->fixed;
1013 if (vwrq->value == -1)
1016 if (vwrq->value % 100000)
1019 new_rate = vwrq->value / 500000;
1020 priv->cur_rate = new_rate;
1021 /* the rest is only needed for lbs_set_data_rate() */
1022 memset(rates, 0, sizeof(rates));
1023 copy_active_data_rates(priv, rates);
1024 if (!memchr(rates, new_rate, sizeof(rates))) {
1025 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1029 if (priv->fwrelease < 0x09000000) {
1030 ret = lbs_set_power_adapt_cfg(priv, 0,
1031 POW_ADAPT_DEFAULT_P0,
1032 POW_ADAPT_DEFAULT_P1,
1033 POW_ADAPT_DEFAULT_P2);
1037 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1043 /* Try the newer command first (Firmware Spec 5.1 and above) */
1044 ret = lbs_cmd_802_11_rate_adapt_rateset(priv, CMD_ACT_SET);
1046 /* Fallback to older version */
1048 ret = lbs_set_data_rate(priv, new_rate);
1051 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1055 static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
1056 struct iw_param *vwrq, char *extra)
1058 struct lbs_private *priv = dev->priv;
1060 lbs_deb_enter(LBS_DEB_WEXT);
1062 if (priv->connect_status == LBS_CONNECTED) {
1063 vwrq->value = priv->cur_rate * 500000;
1065 if (priv->enablehwauto)
1075 lbs_deb_leave(LBS_DEB_WEXT);
1079 static int lbs_set_mode(struct net_device *dev,
1080 struct iw_request_info *info, u32 * uwrq, char *extra)
1083 struct lbs_private *priv = dev->priv;
1084 struct assoc_request * assoc_req;
1086 lbs_deb_enter(LBS_DEB_WEXT);
1088 if ( (*uwrq != IW_MODE_ADHOC)
1089 && (*uwrq != IW_MODE_INFRA)
1090 && (*uwrq != IW_MODE_AUTO)) {
1091 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1096 mutex_lock(&priv->lock);
1097 assoc_req = lbs_get_association_request(priv);
1100 lbs_cancel_association_work(priv);
1102 assoc_req->mode = *uwrq;
1103 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1104 lbs_postpone_association_work(priv);
1105 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1107 mutex_unlock(&priv->lock);
1110 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1116 * @brief Get Encryption key
1118 * @param dev A pointer to net_device structure
1119 * @param info A pointer to iw_request_info structure
1120 * @param vwrq A pointer to iw_param structure
1121 * @param extra A pointer to extra data buf
1122 * @return 0 --success, otherwise fail
1124 static int lbs_get_encode(struct net_device *dev,
1125 struct iw_request_info *info,
1126 struct iw_point *dwrq, u8 * extra)
1128 struct lbs_private *priv = dev->priv;
1129 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1131 lbs_deb_enter(LBS_DEB_WEXT);
1133 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1134 dwrq->flags, index, dwrq->length, priv->wep_tx_keyidx);
1138 /* Authentication method */
1139 switch (priv->secinfo.auth_mode) {
1140 case IW_AUTH_ALG_OPEN_SYSTEM:
1141 dwrq->flags = IW_ENCODE_OPEN;
1144 case IW_AUTH_ALG_SHARED_KEY:
1145 case IW_AUTH_ALG_LEAP:
1146 dwrq->flags = IW_ENCODE_RESTRICTED;
1149 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1153 memset(extra, 0, 16);
1155 mutex_lock(&priv->lock);
1157 /* Default to returning current transmit key */
1159 index = priv->wep_tx_keyidx;
1161 if ((priv->wep_keys[index].len) && priv->secinfo.wep_enabled) {
1162 memcpy(extra, priv->wep_keys[index].key,
1163 priv->wep_keys[index].len);
1164 dwrq->length = priv->wep_keys[index].len;
1166 dwrq->flags |= (index + 1);
1167 /* Return WEP enabled */
1168 dwrq->flags &= ~IW_ENCODE_DISABLED;
1169 } else if ((priv->secinfo.WPAenabled)
1170 || (priv->secinfo.WPA2enabled)) {
1171 /* return WPA enabled */
1172 dwrq->flags &= ~IW_ENCODE_DISABLED;
1173 dwrq->flags |= IW_ENCODE_NOKEY;
1175 dwrq->flags |= IW_ENCODE_DISABLED;
1178 mutex_unlock(&priv->lock);
1180 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
1181 extra[0], extra[1], extra[2],
1182 extra[3], extra[4], extra[5], dwrq->length);
1184 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1186 lbs_deb_leave(LBS_DEB_WEXT);
1191 * @brief Set Encryption key (internal)
1193 * @param priv A pointer to private card structure
1194 * @param key_material A pointer to key material
1195 * @param key_length length of key material
1196 * @param index key index to set
1197 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1198 * @return 0 --success, otherwise fail
1200 static int lbs_set_wep_key(struct assoc_request *assoc_req,
1201 const char *key_material,
1207 struct enc_key *pkey;
1209 lbs_deb_enter(LBS_DEB_WEXT);
1211 /* Paranoid validation of key index */
1217 /* validate max key length */
1218 if (key_length > KEY_LEN_WEP_104) {
1223 pkey = &assoc_req->wep_keys[index];
1225 if (key_length > 0) {
1226 memset(pkey, 0, sizeof(struct enc_key));
1227 pkey->type = KEY_TYPE_ID_WEP;
1229 /* Standardize the key length */
1230 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1231 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1232 memcpy(pkey->key, key_material, key_length);
1236 /* Ensure the chosen key is valid */
1238 lbs_deb_wext("key not set, so cannot enable it\n");
1242 assoc_req->wep_tx_keyidx = index;
1245 assoc_req->secinfo.wep_enabled = 1;
1248 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1252 static int validate_key_index(u16 def_index, u16 raw_index,
1253 u16 *out_index, u16 *is_default)
1255 if (!out_index || !is_default)
1258 /* Verify index if present, otherwise use default TX key index */
1259 if (raw_index > 0) {
1262 *out_index = raw_index - 1;
1264 *out_index = def_index;
1270 static void disable_wep(struct assoc_request *assoc_req)
1274 lbs_deb_enter(LBS_DEB_WEXT);
1276 /* Set Open System auth mode */
1277 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1279 /* Clear WEP keys and mark WEP as disabled */
1280 assoc_req->secinfo.wep_enabled = 0;
1281 for (i = 0; i < 4; i++)
1282 assoc_req->wep_keys[i].len = 0;
1284 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1285 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1287 lbs_deb_leave(LBS_DEB_WEXT);
1290 static void disable_wpa(struct assoc_request *assoc_req)
1292 lbs_deb_enter(LBS_DEB_WEXT);
1294 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
1295 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1296 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1298 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
1299 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1300 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1302 assoc_req->secinfo.WPAenabled = 0;
1303 assoc_req->secinfo.WPA2enabled = 0;
1304 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1306 lbs_deb_leave(LBS_DEB_WEXT);
1310 * @brief Set Encryption key
1312 * @param dev A pointer to net_device structure
1313 * @param info A pointer to iw_request_info structure
1314 * @param vwrq A pointer to iw_param structure
1315 * @param extra A pointer to extra data buf
1316 * @return 0 --success, otherwise fail
1318 static int lbs_set_encode(struct net_device *dev,
1319 struct iw_request_info *info,
1320 struct iw_point *dwrq, char *extra)
1323 struct lbs_private *priv = dev->priv;
1324 struct assoc_request * assoc_req;
1325 u16 is_default = 0, index = 0, set_tx_key = 0;
1327 lbs_deb_enter(LBS_DEB_WEXT);
1329 mutex_lock(&priv->lock);
1330 assoc_req = lbs_get_association_request(priv);
1336 if (dwrq->flags & IW_ENCODE_DISABLED) {
1337 disable_wep (assoc_req);
1338 disable_wpa (assoc_req);
1342 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1343 (dwrq->flags & IW_ENCODE_INDEX),
1344 &index, &is_default);
1350 /* If WEP isn't enabled, or if there is no key data but a valid
1351 * index, set the TX key.
1353 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1356 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1361 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1363 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1365 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1366 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1367 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1368 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1373 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1374 lbs_postpone_association_work(priv);
1376 lbs_cancel_association_work(priv);
1378 mutex_unlock(&priv->lock);
1380 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1385 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1387 * @param dev A pointer to net_device structure
1388 * @param info A pointer to iw_request_info structure
1389 * @param vwrq A pointer to iw_param structure
1390 * @param extra A pointer to extra data buf
1391 * @return 0 on success, otherwise failure
1393 static int lbs_get_encodeext(struct net_device *dev,
1394 struct iw_request_info *info,
1395 struct iw_point *dwrq,
1399 struct lbs_private *priv = dev->priv;
1400 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1401 int index, max_key_len;
1403 lbs_deb_enter(LBS_DEB_WEXT);
1405 max_key_len = dwrq->length - sizeof(*ext);
1406 if (max_key_len < 0)
1409 index = dwrq->flags & IW_ENCODE_INDEX;
1411 if (index < 1 || index > 4)
1415 index = priv->wep_tx_keyidx;
1418 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
1419 ext->alg != IW_ENCODE_ALG_WEP) {
1420 if (index != 0 || priv->mode != IW_MODE_INFRA)
1424 dwrq->flags = index + 1;
1425 memset(ext, 0, sizeof(*ext));
1427 if ( !priv->secinfo.wep_enabled
1428 && !priv->secinfo.WPAenabled
1429 && !priv->secinfo.WPA2enabled) {
1430 ext->alg = IW_ENCODE_ALG_NONE;
1432 dwrq->flags |= IW_ENCODE_DISABLED;
1436 if ( priv->secinfo.wep_enabled
1437 && !priv->secinfo.WPAenabled
1438 && !priv->secinfo.WPA2enabled) {
1440 ext->alg = IW_ENCODE_ALG_WEP;
1441 ext->key_len = priv->wep_keys[index].len;
1442 key = &priv->wep_keys[index].key[0];
1443 } else if ( !priv->secinfo.wep_enabled
1444 && (priv->secinfo.WPAenabled ||
1445 priv->secinfo.WPA2enabled)) {
1447 struct enc_key * pkey = NULL;
1449 if ( priv->wpa_mcast_key.len
1450 && (priv->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1451 pkey = &priv->wpa_mcast_key;
1452 else if ( priv->wpa_unicast_key.len
1453 && (priv->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1454 pkey = &priv->wpa_unicast_key;
1457 if (pkey->type == KEY_TYPE_ID_AES) {
1458 ext->alg = IW_ENCODE_ALG_CCMP;
1460 ext->alg = IW_ENCODE_ALG_TKIP;
1462 ext->key_len = pkey->len;
1463 key = &pkey->key[0];
1465 ext->alg = IW_ENCODE_ALG_TKIP;
1472 if (ext->key_len > max_key_len) {
1478 memcpy(ext->key, key, ext->key_len);
1480 dwrq->flags |= IW_ENCODE_NOKEY;
1481 dwrq->flags |= IW_ENCODE_ENABLED;
1486 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1491 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1493 * @param dev A pointer to net_device structure
1494 * @param info A pointer to iw_request_info structure
1495 * @param vwrq A pointer to iw_param structure
1496 * @param extra A pointer to extra data buf
1497 * @return 0 --success, otherwise fail
1499 static int lbs_set_encodeext(struct net_device *dev,
1500 struct iw_request_info *info,
1501 struct iw_point *dwrq,
1505 struct lbs_private *priv = dev->priv;
1506 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1508 struct assoc_request * assoc_req;
1510 lbs_deb_enter(LBS_DEB_WEXT);
1512 mutex_lock(&priv->lock);
1513 assoc_req = lbs_get_association_request(priv);
1519 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1520 disable_wep (assoc_req);
1521 disable_wpa (assoc_req);
1522 } else if (alg == IW_ENCODE_ALG_WEP) {
1523 u16 is_default = 0, index, set_tx_key = 0;
1525 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1526 (dwrq->flags & IW_ENCODE_INDEX),
1527 &index, &is_default);
1531 /* If WEP isn't enabled, or if there is no key data but a valid
1532 * index, or if the set-TX-key flag was passed, set the TX key.
1534 if ( !assoc_req->secinfo.wep_enabled
1535 || (dwrq->length == 0 && !is_default)
1536 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1539 /* Copy key to driver */
1540 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
1545 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1546 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1547 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1548 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1551 /* Mark the various WEP bits as modified */
1552 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1554 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1556 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1557 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1558 struct enc_key * pkey;
1560 /* validate key length */
1561 if (((alg == IW_ENCODE_ALG_TKIP)
1562 && (ext->key_len != KEY_LEN_WPA_TKIP))
1563 || ((alg == IW_ENCODE_ALG_CCMP)
1564 && (ext->key_len != KEY_LEN_WPA_AES))) {
1565 lbs_deb_wext("invalid size %d for key of alg "
1573 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1574 pkey = &assoc_req->wpa_mcast_key;
1575 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1577 pkey = &assoc_req->wpa_unicast_key;
1578 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1581 memset(pkey, 0, sizeof (struct enc_key));
1582 memcpy(pkey->key, ext->key, ext->key_len);
1583 pkey->len = ext->key_len;
1585 pkey->flags |= KEY_INFO_WPA_ENABLED;
1587 /* Do this after zeroing key structure */
1588 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1589 pkey->flags |= KEY_INFO_WPA_MCAST;
1591 pkey->flags |= KEY_INFO_WPA_UNICAST;
1594 if (alg == IW_ENCODE_ALG_TKIP) {
1595 pkey->type = KEY_TYPE_ID_TKIP;
1596 } else if (alg == IW_ENCODE_ALG_CCMP) {
1597 pkey->type = KEY_TYPE_ID_AES;
1600 /* If WPA isn't enabled yet, do that now */
1601 if ( assoc_req->secinfo.WPAenabled == 0
1602 && assoc_req->secinfo.WPA2enabled == 0) {
1603 assoc_req->secinfo.WPAenabled = 1;
1604 assoc_req->secinfo.WPA2enabled = 1;
1605 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1608 /* Only disable wep if necessary: can't waste time here. */
1609 if (priv->mac_control & CMD_ACT_MAC_WEP_ENABLE)
1610 disable_wep(assoc_req);
1615 /* 802.1x and WPA rekeying must happen as quickly as possible,
1616 * especially during the 4-way handshake; thus if in
1617 * infrastructure mode, and either (a) 802.1x is enabled or
1618 * (b) WPA is being used, set the key right away.
1620 if (assoc_req->mode == IW_MODE_INFRA &&
1621 ((assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_802_1X) ||
1622 (assoc_req->secinfo.key_mgmt & IW_AUTH_KEY_MGMT_PSK) ||
1623 assoc_req->secinfo.WPAenabled ||
1624 assoc_req->secinfo.WPA2enabled)) {
1625 lbs_do_association_work(priv);
1627 lbs_postpone_association_work(priv);
1629 lbs_cancel_association_work(priv);
1631 mutex_unlock(&priv->lock);
1633 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1638 static int lbs_set_genie(struct net_device *dev,
1639 struct iw_request_info *info,
1640 struct iw_point *dwrq,
1643 struct lbs_private *priv = dev->priv;
1645 struct assoc_request * assoc_req;
1647 lbs_deb_enter(LBS_DEB_WEXT);
1649 mutex_lock(&priv->lock);
1650 assoc_req = lbs_get_association_request(priv);
1656 if (dwrq->length > MAX_WPA_IE_LEN ||
1657 (dwrq->length && extra == NULL)) {
1663 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1664 assoc_req->wpa_ie_len = dwrq->length;
1666 memset(&assoc_req->wpa_ie[0], 0, sizeof(priv->wpa_ie));
1667 assoc_req->wpa_ie_len = 0;
1672 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
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);
1683 static int lbs_get_genie(struct net_device *dev,
1684 struct iw_request_info *info,
1685 struct iw_point *dwrq,
1689 struct lbs_private *priv = dev->priv;
1691 lbs_deb_enter(LBS_DEB_WEXT);
1693 if (priv->wpa_ie_len == 0) {
1698 if (dwrq->length < priv->wpa_ie_len) {
1703 dwrq->length = priv->wpa_ie_len;
1704 memcpy(extra, &priv->wpa_ie[0], priv->wpa_ie_len);
1707 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1712 static int lbs_set_auth(struct net_device *dev,
1713 struct iw_request_info *info,
1714 struct iw_param *dwrq,
1717 struct lbs_private *priv = dev->priv;
1718 struct assoc_request * assoc_req;
1722 lbs_deb_enter(LBS_DEB_WEXT);
1724 mutex_lock(&priv->lock);
1725 assoc_req = lbs_get_association_request(priv);
1731 switch (dwrq->flags & IW_AUTH_INDEX) {
1732 case IW_AUTH_TKIP_COUNTERMEASURES:
1733 case IW_AUTH_CIPHER_PAIRWISE:
1734 case IW_AUTH_CIPHER_GROUP:
1735 case IW_AUTH_DROP_UNENCRYPTED:
1737 * libertas does not use these parameters
1741 case IW_AUTH_KEY_MGMT:
1742 assoc_req->secinfo.key_mgmt = dwrq->value;
1746 case IW_AUTH_WPA_VERSION:
1747 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1748 assoc_req->secinfo.WPAenabled = 0;
1749 assoc_req->secinfo.WPA2enabled = 0;
1750 disable_wpa (assoc_req);
1752 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1753 assoc_req->secinfo.WPAenabled = 1;
1754 assoc_req->secinfo.wep_enabled = 0;
1755 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1757 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1758 assoc_req->secinfo.WPA2enabled = 1;
1759 assoc_req->secinfo.wep_enabled = 0;
1760 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1765 case IW_AUTH_80211_AUTH_ALG:
1766 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1767 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1768 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1769 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1770 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1771 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1778 case IW_AUTH_WPA_ENABLED:
1780 if (!assoc_req->secinfo.WPAenabled &&
1781 !assoc_req->secinfo.WPA2enabled) {
1782 assoc_req->secinfo.WPAenabled = 1;
1783 assoc_req->secinfo.WPA2enabled = 1;
1784 assoc_req->secinfo.wep_enabled = 0;
1785 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1788 assoc_req->secinfo.WPAenabled = 0;
1789 assoc_req->secinfo.WPA2enabled = 0;
1790 disable_wpa (assoc_req);
1803 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1804 lbs_postpone_association_work(priv);
1805 } else if (ret != -EOPNOTSUPP) {
1806 lbs_cancel_association_work(priv);
1808 mutex_unlock(&priv->lock);
1810 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1814 static int lbs_get_auth(struct net_device *dev,
1815 struct iw_request_info *info,
1816 struct iw_param *dwrq,
1820 struct lbs_private *priv = dev->priv;
1822 lbs_deb_enter(LBS_DEB_WEXT);
1824 switch (dwrq->flags & IW_AUTH_INDEX) {
1825 case IW_AUTH_KEY_MGMT:
1826 dwrq->value = priv->secinfo.key_mgmt;
1829 case IW_AUTH_WPA_VERSION:
1831 if (priv->secinfo.WPAenabled)
1832 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1833 if (priv->secinfo.WPA2enabled)
1834 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1836 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1839 case IW_AUTH_80211_AUTH_ALG:
1840 dwrq->value = priv->secinfo.auth_mode;
1843 case IW_AUTH_WPA_ENABLED:
1844 if (priv->secinfo.WPAenabled && priv->secinfo.WPA2enabled)
1852 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1857 static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
1858 struct iw_param *vwrq, char *extra)
1861 struct lbs_private *priv = dev->priv;
1862 s16 dbm = (s16) vwrq->value;
1864 lbs_deb_enter(LBS_DEB_WEXT);
1866 if (vwrq->disabled) {
1867 lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 0);
1871 if (vwrq->fixed == 0) {
1872 /* User requests automatic tx power control, however there are
1873 * many auto tx settings. For now use firmware defaults until
1874 * we come up with a good way to expose these to the user. */
1875 if (priv->fwrelease < 0x09000000) {
1876 ret = lbs_set_power_adapt_cfg(priv, 1,
1877 POW_ADAPT_DEFAULT_P0,
1878 POW_ADAPT_DEFAULT_P1,
1879 POW_ADAPT_DEFAULT_P2);
1883 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1887 dbm = priv->txpower_max;
1889 /* Userspace check in iwrange if it should use dBm or mW,
1890 * therefore this should never happen... Jean II */
1891 if ((vwrq->flags & IW_TXPOW_TYPE) != IW_TXPOW_DBM) {
1896 /* Validate requested power level against firmware allowed
1898 if (priv->txpower_min && (dbm < priv->txpower_min)) {
1903 if (priv->txpower_max && (dbm > priv->txpower_max)) {
1907 if (priv->fwrelease < 0x09000000) {
1908 ret = lbs_set_power_adapt_cfg(priv, 0,
1909 POW_ADAPT_DEFAULT_P0,
1910 POW_ADAPT_DEFAULT_P1,
1911 POW_ADAPT_DEFAULT_P2);
1915 ret = lbs_set_tpc_cfg(priv, 0, TPC_DEFAULT_P0, TPC_DEFAULT_P1,
1921 /* If the radio was off, turn it on */
1922 if (!priv->radio_on) {
1923 ret = lbs_set_radio(priv, RADIO_PREAMBLE_AUTO, 1);
1928 lbs_deb_wext("txpower set %d dBm\n", dbm);
1930 ret = lbs_set_tx_power(priv, dbm);
1933 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1937 static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
1938 struct iw_point *dwrq, char *extra)
1940 struct lbs_private *priv = dev->priv;
1942 lbs_deb_enter(LBS_DEB_WEXT);
1945 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1950 * Get the current SSID
1952 if (priv->connect_status == LBS_CONNECTED) {
1953 memcpy(extra, priv->curbssparams.ssid,
1954 priv->curbssparams.ssid_len);
1955 extra[priv->curbssparams.ssid_len] = '\0';
1957 memset(extra, 0, 32);
1958 extra[priv->curbssparams.ssid_len] = '\0';
1961 * If none, we may want to get the one that was set
1964 dwrq->length = priv->curbssparams.ssid_len;
1966 dwrq->flags = 1; /* active */
1968 lbs_deb_leave(LBS_DEB_WEXT);
1972 static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
1973 struct iw_point *dwrq, char *extra)
1975 struct lbs_private *priv = dev->priv;
1977 u8 ssid[IW_ESSID_MAX_SIZE];
1979 struct assoc_request * assoc_req;
1980 int in_ssid_len = dwrq->length;
1981 DECLARE_SSID_BUF(ssid_buf);
1983 lbs_deb_enter(LBS_DEB_WEXT);
1985 if (!priv->radio_on) {
1990 /* Check the size of the string */
1991 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
1996 memset(&ssid, 0, sizeof(ssid));
1998 if (!dwrq->flags || !in_ssid_len) {
1999 /* "any" SSID requested; leave SSID blank */
2001 /* Specific SSID requested */
2002 memcpy(&ssid, extra, in_ssid_len);
2003 ssid_len = in_ssid_len;
2007 lbs_deb_wext("requested any SSID\n");
2009 lbs_deb_wext("requested SSID '%s'\n",
2010 print_ssid(ssid_buf, ssid, ssid_len));
2014 mutex_lock(&priv->lock);
2016 /* Get or create the current association request */
2017 assoc_req = lbs_get_association_request(priv);
2021 /* Copy the SSID to the association request */
2022 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
2023 assoc_req->ssid_len = ssid_len;
2024 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
2025 lbs_postpone_association_work(priv);
2029 /* Cancel the association request if there was an error */
2031 lbs_cancel_association_work(priv);
2034 mutex_unlock(&priv->lock);
2036 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2040 static int lbs_mesh_get_essid(struct net_device *dev,
2041 struct iw_request_info *info,
2042 struct iw_point *dwrq, char *extra)
2044 struct lbs_private *priv = dev->priv;
2046 lbs_deb_enter(LBS_DEB_WEXT);
2048 memcpy(extra, priv->mesh_ssid, priv->mesh_ssid_len);
2050 dwrq->length = priv->mesh_ssid_len;
2052 dwrq->flags = 1; /* active */
2054 lbs_deb_leave(LBS_DEB_WEXT);
2058 static int lbs_mesh_set_essid(struct net_device *dev,
2059 struct iw_request_info *info,
2060 struct iw_point *dwrq, char *extra)
2062 struct lbs_private *priv = dev->priv;
2065 lbs_deb_enter(LBS_DEB_WEXT);
2067 if (!priv->radio_on) {
2072 /* Check the size of the string */
2073 if (dwrq->length > IW_ESSID_MAX_SIZE) {
2078 if (!dwrq->flags || !dwrq->length) {
2082 /* Specific SSID requested */
2083 memcpy(priv->mesh_ssid, extra, dwrq->length);
2084 priv->mesh_ssid_len = dwrq->length;
2087 lbs_mesh_config(priv, CMD_ACT_MESH_CONFIG_START,
2088 priv->curbssparams.channel);
2090 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
2095 * @brief Connect to the AP or Ad-hoc Network with specific bssid
2097 * @param dev A pointer to net_device structure
2098 * @param info A pointer to iw_request_info structure
2099 * @param awrq A pointer to iw_param structure
2100 * @param extra A pointer to extra data buf
2101 * @return 0 --success, otherwise fail
2103 static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
2104 struct sockaddr *awrq, char *extra)
2106 struct lbs_private *priv = dev->priv;
2107 struct assoc_request * assoc_req;
2110 lbs_deb_enter(LBS_DEB_WEXT);
2112 if (!priv->radio_on)
2115 if (awrq->sa_family != ARPHRD_ETHER)
2118 lbs_deb_wext("ASSOC: WAP: sa_data %pM\n", awrq->sa_data);
2120 mutex_lock(&priv->lock);
2122 /* Get or create the current association request */
2123 assoc_req = lbs_get_association_request(priv);
2125 lbs_cancel_association_work(priv);
2128 /* Copy the BSSID to the association request */
2129 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2130 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2131 lbs_postpone_association_work(priv);
2134 mutex_unlock(&priv->lock);
2140 * iwconfig settable callbacks
2142 static const iw_handler lbs_handler[] = {
2143 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2144 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2145 (iw_handler) NULL, /* SIOCSIWNWID */
2146 (iw_handler) NULL, /* SIOCGIWNWID */
2147 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2148 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2149 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2150 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
2151 (iw_handler) NULL, /* SIOCSIWSENS */
2152 (iw_handler) NULL, /* SIOCGIWSENS */
2153 (iw_handler) NULL, /* SIOCSIWRANGE */
2154 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2155 (iw_handler) NULL, /* SIOCSIWPRIV */
2156 (iw_handler) NULL, /* SIOCGIWPRIV */
2157 (iw_handler) NULL, /* SIOCSIWSTATS */
2158 (iw_handler) NULL, /* SIOCGIWSTATS */
2159 iw_handler_set_spy, /* SIOCSIWSPY */
2160 iw_handler_get_spy, /* SIOCGIWSPY */
2161 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2162 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2163 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2164 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
2165 (iw_handler) NULL, /* SIOCSIWMLME */
2166 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2167 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2168 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2169 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2170 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2171 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2172 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
2173 (iw_handler) NULL, /* -- hole -- */
2174 (iw_handler) NULL, /* -- hole -- */
2175 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2176 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2177 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2178 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2179 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2180 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2181 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2182 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2183 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2184 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2185 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2186 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2187 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2188 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2189 (iw_handler) NULL, /* -- hole -- */
2190 (iw_handler) NULL, /* -- hole -- */
2191 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2192 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2193 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2194 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2195 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2196 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2197 (iw_handler) NULL, /* SIOCSIWPMKSA */
2200 static const iw_handler mesh_wlan_handler[] = {
2201 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2202 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2203 (iw_handler) NULL, /* SIOCSIWNWID */
2204 (iw_handler) NULL, /* SIOCGIWNWID */
2205 (iw_handler) lbs_mesh_set_freq, /* SIOCSIWFREQ */
2206 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2207 (iw_handler) NULL, /* SIOCSIWMODE */
2208 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2209 (iw_handler) NULL, /* SIOCSIWSENS */
2210 (iw_handler) NULL, /* SIOCGIWSENS */
2211 (iw_handler) NULL, /* SIOCSIWRANGE */
2212 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2213 (iw_handler) NULL, /* SIOCSIWPRIV */
2214 (iw_handler) NULL, /* SIOCGIWPRIV */
2215 (iw_handler) NULL, /* SIOCSIWSTATS */
2216 (iw_handler) NULL, /* SIOCGIWSTATS */
2217 iw_handler_set_spy, /* SIOCSIWSPY */
2218 iw_handler_get_spy, /* SIOCGIWSPY */
2219 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2220 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2221 (iw_handler) NULL, /* SIOCSIWAP */
2222 (iw_handler) NULL, /* SIOCGIWAP */
2223 (iw_handler) NULL, /* SIOCSIWMLME */
2224 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2225 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2226 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2227 (iw_handler) lbs_mesh_set_essid,/* SIOCSIWESSID */
2228 (iw_handler) lbs_mesh_get_essid,/* SIOCGIWESSID */
2229 (iw_handler) NULL, /* SIOCSIWNICKN */
2230 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2231 (iw_handler) NULL, /* -- hole -- */
2232 (iw_handler) NULL, /* -- hole -- */
2233 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2234 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2235 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2236 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2237 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2238 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2239 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2240 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2241 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2242 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2243 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2244 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2245 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2246 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2247 (iw_handler) NULL, /* -- hole -- */
2248 (iw_handler) NULL, /* -- hole -- */
2249 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2250 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2251 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2252 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2253 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2254 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2255 (iw_handler) NULL, /* SIOCSIWPMKSA */
2257 struct iw_handler_def lbs_handler_def = {
2258 .num_standard = ARRAY_SIZE(lbs_handler),
2259 .standard = (iw_handler *) lbs_handler,
2260 .get_wireless_stats = lbs_get_wireless_stats,
2263 struct iw_handler_def mesh_handler_def = {
2264 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
2265 .standard = (iw_handler *) mesh_wlan_handler,
2266 .get_wireless_stats = lbs_get_wireless_stats,