2 * This file contains ioctl functions
4 #include <linux/ctype.h>
5 #include <linux/delay.h>
7 #include <linux/if_arp.h>
8 #include <linux/wireless.h>
9 #include <linux/bitops.h>
11 #include <net/ieee80211.h>
12 #include <net/iw_handler.h>
24 static inline void lbs_postpone_association_work(struct lbs_private *priv)
26 if (priv->adapter->surpriseremoved)
28 cancel_delayed_work(&priv->assoc_work);
29 queue_delayed_work(priv->work_thread, &priv->assoc_work, HZ / 2);
32 static inline void lbs_cancel_association_work(struct lbs_private *priv)
34 cancel_delayed_work(&priv->assoc_work);
35 kfree(priv->adapter->pending_assoc_req);
36 priv->adapter->pending_assoc_req = NULL;
41 * @brief Find the channel frequency power info with specific channel
43 * @param adapter A pointer to struct lbs_adapter structure
44 * @param band it can be BAND_A, BAND_G or BAND_B
45 * @param channel the channel for looking
46 * @return A pointer to struct chan_freq_power structure or NULL if not find.
48 struct chan_freq_power *lbs_find_cfp_by_band_and_channel(
49 struct lbs_adapter *adapter,
53 struct chan_freq_power *cfp = NULL;
54 struct region_channel *rc;
57 for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
58 rc = &adapter->region_channel[j];
60 if (adapter->enable11d)
61 rc = &adapter->universal_channel[j];
62 if (!rc->valid || !rc->CFP)
66 for (i = 0; i < rc->nrcfp; i++) {
67 if (rc->CFP[i].channel == channel) {
75 lbs_deb_wext("lbs_find_cfp_by_band_and_channel: can't find "
76 "cfp by band %d / channel %d\n", band, channel);
82 * @brief Find the channel frequency power info with specific frequency
84 * @param adapter A pointer to struct lbs_adapter structure
85 * @param band it can be BAND_A, BAND_G or BAND_B
86 * @param freq the frequency for looking
87 * @return A pointer to struct chan_freq_power structure or NULL if not find.
89 static struct chan_freq_power *find_cfp_by_band_and_freq(
90 struct lbs_adapter *adapter,
94 struct chan_freq_power *cfp = NULL;
95 struct region_channel *rc;
98 for (j = 0; !cfp && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
99 rc = &adapter->region_channel[j];
101 if (adapter->enable11d)
102 rc = &adapter->universal_channel[j];
103 if (!rc->valid || !rc->CFP)
105 if (rc->band != band)
107 for (i = 0; i < rc->nrcfp; i++) {
108 if (rc->CFP[i].freq == freq) {
116 lbs_deb_wext("find_cfp_by_band_and_freql: can't find cfp by "
117 "band %d / freq %d\n", band, freq);
124 * @brief Set Radio On/OFF
126 * @param priv A pointer to struct lbs_private structure
127 * @option Radio Option
128 * @return 0 --success, otherwise fail
130 static int lbs_radio_ioctl(struct lbs_private *priv, u8 option)
133 struct lbs_adapter *adapter = priv->adapter;
135 lbs_deb_enter(LBS_DEB_WEXT);
137 if (adapter->radioon != option) {
138 lbs_deb_wext("switching radio %s\n", option ? "on" : "off");
139 adapter->radioon = option;
141 ret = lbs_prepare_and_send_command(priv,
142 CMD_802_11_RADIO_CONTROL,
144 CMD_OPTION_WAITFORRSP, 0, NULL);
147 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
152 * @brief Copy active data rates based on adapter mode and status
154 * @param adapter A pointer to struct lbs_adapter structure
155 * @param rate The buf to return the active rates
157 static void copy_active_data_rates(struct lbs_adapter *adapter, u8 *rates)
159 lbs_deb_enter(LBS_DEB_WEXT);
161 if ((adapter->connect_status != LBS_CONNECTED) &&
162 (adapter->mesh_connect_status != LBS_CONNECTED))
163 memcpy(rates, lbs_bg_rates, MAX_RATES);
165 memcpy(rates, adapter->curbssparams.rates, MAX_RATES);
167 lbs_deb_leave(LBS_DEB_WEXT);
170 static int lbs_get_name(struct net_device *dev, struct iw_request_info *info,
171 char *cwrq, char *extra)
174 lbs_deb_enter(LBS_DEB_WEXT);
176 /* We could add support for 802.11n here as needed. Jean II */
177 snprintf(cwrq, IFNAMSIZ, "IEEE 802.11b/g");
179 lbs_deb_leave(LBS_DEB_WEXT);
183 static int lbs_get_freq(struct net_device *dev, struct iw_request_info *info,
184 struct iw_freq *fwrq, char *extra)
186 struct lbs_private *priv = dev->priv;
187 struct lbs_adapter *adapter = priv->adapter;
188 struct chan_freq_power *cfp;
190 lbs_deb_enter(LBS_DEB_WEXT);
192 cfp = lbs_find_cfp_by_band_and_channel(adapter, 0,
193 adapter->curbssparams.channel);
196 if (adapter->curbssparams.channel)
197 lbs_deb_wext("invalid channel %d\n",
198 adapter->curbssparams.channel);
202 fwrq->m = (long)cfp->freq * 100000;
205 lbs_deb_wext("freq %u\n", fwrq->m);
206 lbs_deb_leave(LBS_DEB_WEXT);
210 static int lbs_get_wap(struct net_device *dev, struct iw_request_info *info,
211 struct sockaddr *awrq, char *extra)
213 struct lbs_private *priv = dev->priv;
214 struct lbs_adapter *adapter = priv->adapter;
216 lbs_deb_enter(LBS_DEB_WEXT);
218 if (adapter->connect_status == LBS_CONNECTED) {
219 memcpy(awrq->sa_data, adapter->curbssparams.bssid, ETH_ALEN);
221 memset(awrq->sa_data, 0, ETH_ALEN);
223 awrq->sa_family = ARPHRD_ETHER;
225 lbs_deb_leave(LBS_DEB_WEXT);
229 static int lbs_set_nick(struct net_device *dev, struct iw_request_info *info,
230 struct iw_point *dwrq, char *extra)
232 struct lbs_private *priv = dev->priv;
233 struct lbs_adapter *adapter = priv->adapter;
235 lbs_deb_enter(LBS_DEB_WEXT);
238 * Check the size of the string
241 if (dwrq->length > 16) {
245 mutex_lock(&adapter->lock);
246 memset(adapter->nodename, 0, sizeof(adapter->nodename));
247 memcpy(adapter->nodename, extra, dwrq->length);
248 mutex_unlock(&adapter->lock);
250 lbs_deb_leave(LBS_DEB_WEXT);
254 static int lbs_get_nick(struct net_device *dev, struct iw_request_info *info,
255 struct iw_point *dwrq, char *extra)
257 struct lbs_private *priv = dev->priv;
258 struct lbs_adapter *adapter = priv->adapter;
260 lbs_deb_enter(LBS_DEB_WEXT);
262 dwrq->length = strlen(adapter->nodename);
263 memcpy(extra, adapter->nodename, dwrq->length);
264 extra[dwrq->length] = '\0';
266 dwrq->flags = 1; /* active */
268 lbs_deb_leave(LBS_DEB_WEXT);
272 static int mesh_get_nick(struct net_device *dev, struct iw_request_info *info,
273 struct iw_point *dwrq, char *extra)
275 struct lbs_private *priv = dev->priv;
276 struct lbs_adapter *adapter = priv->adapter;
278 lbs_deb_enter(LBS_DEB_WEXT);
280 /* Use nickname to indicate that mesh is on */
282 if (adapter->mesh_connect_status == LBS_CONNECTED) {
283 strncpy(extra, "Mesh", 12);
285 dwrq->length = strlen(extra);
293 lbs_deb_leave(LBS_DEB_WEXT);
297 static int lbs_set_rts(struct net_device *dev, struct iw_request_info *info,
298 struct iw_param *vwrq, char *extra)
301 struct lbs_private *priv = dev->priv;
302 struct lbs_adapter *adapter = priv->adapter;
303 u32 rthr = vwrq->value;
305 lbs_deb_enter(LBS_DEB_WEXT);
307 if (vwrq->disabled) {
308 adapter->rtsthsd = rthr = MRVDRV_RTS_MAX_VALUE;
310 if (rthr < MRVDRV_RTS_MIN_VALUE || rthr > MRVDRV_RTS_MAX_VALUE)
312 adapter->rtsthsd = rthr;
315 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
316 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
317 OID_802_11_RTS_THRESHOLD, &rthr);
319 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
323 static int lbs_get_rts(struct net_device *dev, struct iw_request_info *info,
324 struct iw_param *vwrq, char *extra)
327 struct lbs_private *priv = dev->priv;
328 struct lbs_adapter *adapter = priv->adapter;
330 lbs_deb_enter(LBS_DEB_WEXT);
332 adapter->rtsthsd = 0;
333 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
334 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
335 OID_802_11_RTS_THRESHOLD, NULL);
339 vwrq->value = adapter->rtsthsd;
340 vwrq->disabled = ((vwrq->value < MRVDRV_RTS_MIN_VALUE)
341 || (vwrq->value > MRVDRV_RTS_MAX_VALUE));
345 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
349 static int lbs_set_frag(struct net_device *dev, struct iw_request_info *info,
350 struct iw_param *vwrq, char *extra)
353 u32 fthr = vwrq->value;
354 struct lbs_private *priv = dev->priv;
355 struct lbs_adapter *adapter = priv->adapter;
357 lbs_deb_enter(LBS_DEB_WEXT);
359 if (vwrq->disabled) {
360 adapter->fragthsd = fthr = MRVDRV_FRAG_MAX_VALUE;
362 if (fthr < MRVDRV_FRAG_MIN_VALUE
363 || fthr > MRVDRV_FRAG_MAX_VALUE)
365 adapter->fragthsd = fthr;
368 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
369 CMD_ACT_SET, CMD_OPTION_WAITFORRSP,
370 OID_802_11_FRAGMENTATION_THRESHOLD, &fthr);
372 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
376 static int lbs_get_frag(struct net_device *dev, struct iw_request_info *info,
377 struct iw_param *vwrq, char *extra)
380 struct lbs_private *priv = dev->priv;
381 struct lbs_adapter *adapter = priv->adapter;
383 lbs_deb_enter(LBS_DEB_WEXT);
385 adapter->fragthsd = 0;
386 ret = lbs_prepare_and_send_command(priv,
388 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
389 OID_802_11_FRAGMENTATION_THRESHOLD, NULL);
393 vwrq->value = adapter->fragthsd;
394 vwrq->disabled = ((vwrq->value < MRVDRV_FRAG_MIN_VALUE)
395 || (vwrq->value > MRVDRV_FRAG_MAX_VALUE));
399 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
403 static int lbs_get_mode(struct net_device *dev,
404 struct iw_request_info *info, u32 * uwrq, char *extra)
406 struct lbs_private *priv = dev->priv;
407 struct lbs_adapter *adapter = priv->adapter;
409 lbs_deb_enter(LBS_DEB_WEXT);
411 *uwrq = adapter->mode;
413 lbs_deb_leave(LBS_DEB_WEXT);
417 static int mesh_wlan_get_mode(struct net_device *dev,
418 struct iw_request_info *info, u32 * uwrq,
421 lbs_deb_enter(LBS_DEB_WEXT);
423 *uwrq = IW_MODE_REPEAT ;
425 lbs_deb_leave(LBS_DEB_WEXT);
429 static int lbs_get_txpow(struct net_device *dev,
430 struct iw_request_info *info,
431 struct iw_param *vwrq, char *extra)
434 struct lbs_private *priv = dev->priv;
435 struct lbs_adapter *adapter = priv->adapter;
437 lbs_deb_enter(LBS_DEB_WEXT);
439 ret = lbs_prepare_and_send_command(priv,
440 CMD_802_11_RF_TX_POWER,
441 CMD_ACT_TX_POWER_OPT_GET,
442 CMD_OPTION_WAITFORRSP, 0, NULL);
447 lbs_deb_wext("tx power level %d dbm\n", adapter->txpowerlevel);
448 vwrq->value = adapter->txpowerlevel;
450 if (adapter->radioon) {
452 vwrq->flags = IW_TXPOW_DBM;
458 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
462 static int lbs_set_retry(struct net_device *dev, struct iw_request_info *info,
463 struct iw_param *vwrq, char *extra)
466 struct lbs_private *priv = dev->priv;
467 struct lbs_adapter *adapter = priv->adapter;
469 lbs_deb_enter(LBS_DEB_WEXT);
471 if (vwrq->flags == IW_RETRY_LIMIT) {
472 /* The MAC has a 4-bit Total_Tx_Count register
473 Total_Tx_Count = 1 + Tx_Retry_Count */
474 #define TX_RETRY_MIN 0
475 #define TX_RETRY_MAX 14
476 if (vwrq->value < TX_RETRY_MIN || vwrq->value > TX_RETRY_MAX)
479 /* Adding 1 to convert retry count to try count */
480 adapter->txretrycount = vwrq->value + 1;
482 ret = lbs_prepare_and_send_command(priv, CMD_802_11_SNMP_MIB,
484 CMD_OPTION_WAITFORRSP,
485 OID_802_11_TX_RETRYCOUNT, NULL);
494 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
498 static int lbs_get_retry(struct net_device *dev, struct iw_request_info *info,
499 struct iw_param *vwrq, char *extra)
501 struct lbs_private *priv = dev->priv;
502 struct lbs_adapter *adapter = priv->adapter;
505 lbs_deb_enter(LBS_DEB_WEXT);
507 adapter->txretrycount = 0;
508 ret = lbs_prepare_and_send_command(priv,
510 CMD_ACT_GET, CMD_OPTION_WAITFORRSP,
511 OID_802_11_TX_RETRYCOUNT, NULL);
517 vwrq->flags = IW_RETRY_LIMIT;
518 /* Subtract 1 to convert try count to retry count */
519 vwrq->value = adapter->txretrycount - 1;
523 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
527 static inline void sort_channels(struct iw_freq *freq, int num)
532 for (i = 0; i < num; i++)
533 for (j = i + 1; j < num; j++)
534 if (freq[i].i > freq[j].i) {
538 freq[i].i = freq[j].i;
539 freq[i].m = freq[j].m;
549 Infra G(12) A(8) B(4) G(12)
550 Adhoc A+B(12) A(8) B(4) B(4)
558 * @brief Get Range Info
560 * @param dev A pointer to net_device structure
561 * @param info A pointer to iw_request_info structure
562 * @param vwrq A pointer to iw_param structure
563 * @param extra A pointer to extra data buf
564 * @return 0 --success, otherwise fail
566 static int lbs_get_range(struct net_device *dev, struct iw_request_info *info,
567 struct iw_point *dwrq, char *extra)
570 struct lbs_private *priv = dev->priv;
571 struct lbs_adapter *adapter = priv->adapter;
572 struct iw_range *range = (struct iw_range *)extra;
573 struct chan_freq_power *cfp;
574 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(adapter, 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;
596 if (priv->adapter->enable11d &&
597 (adapter->connect_status == LBS_CONNECTED ||
598 adapter->mesh_connect_status == LBS_CONNECTED)) {
602 struct parsed_region_chan_11d *parsed_region_chan =
603 &adapter->parsed_region_chan;
605 if (parsed_region_chan == NULL) {
606 lbs_deb_wext("11d: parsed_region_chan is NULL\n");
609 band = parsed_region_chan->band;
610 lbs_deb_wext("band %d, nr_char %d\n", band,
611 parsed_region_chan->nr_chan);
613 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
614 && (i < parsed_region_chan->nr_chan); i++) {
615 chan_no = parsed_region_chan->chanpwr[i].chan;
616 lbs_deb_wext("chan_no %d\n", chan_no);
617 range->freq[range->num_frequency].i = (long)chan_no;
618 range->freq[range->num_frequency].m =
619 (long)lbs_chan_2_freq(chan_no, band) * 100000;
620 range->freq[range->num_frequency].e = 1;
621 range->num_frequency++;
626 for (j = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
627 && (j < ARRAY_SIZE(adapter->region_channel)); j++) {
628 cfp = adapter->region_channel[j].CFP;
629 for (i = 0; (range->num_frequency < IW_MAX_FREQUENCIES)
630 && adapter->region_channel[j].valid
632 && (i < adapter->region_channel[j].nrcfp); i++) {
633 range->freq[range->num_frequency].i =
635 range->freq[range->num_frequency].m =
636 (long)cfp->freq * 100000;
637 range->freq[range->num_frequency].e = 1;
639 range->num_frequency++;
644 lbs_deb_wext("IW_MAX_FREQUENCIES %d, num_frequency %d\n",
645 IW_MAX_FREQUENCIES, range->num_frequency);
647 range->num_channels = range->num_frequency;
649 sort_channels(&range->freq[0], range->num_frequency);
652 * Set an indication of the max TCP throughput in bit/s that we can
653 * expect using this interface
656 range->throughput = 5000 * 1000;
658 range->throughput = 1500 * 1000;
660 range->min_rts = MRVDRV_RTS_MIN_VALUE;
661 range->max_rts = MRVDRV_RTS_MAX_VALUE;
662 range->min_frag = MRVDRV_FRAG_MIN_VALUE;
663 range->max_frag = MRVDRV_FRAG_MAX_VALUE;
665 range->encoding_size[0] = 5;
666 range->encoding_size[1] = 13;
667 range->num_encoding_sizes = 2;
668 range->max_encoding_tokens = 4;
670 range->min_pmp = 1000000;
671 range->max_pmp = 120000000;
672 range->min_pmt = 1000;
673 range->max_pmt = 1000000;
674 range->pmp_flags = IW_POWER_PERIOD;
675 range->pmt_flags = IW_POWER_TIMEOUT;
676 range->pm_capa = IW_POWER_PERIOD | IW_POWER_TIMEOUT | IW_POWER_ALL_R;
679 * Minimum version we recommend
681 range->we_version_source = 15;
684 * Version we are compiled with
686 range->we_version_compiled = WIRELESS_EXT;
688 range->retry_capa = IW_RETRY_LIMIT;
689 range->retry_flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
691 range->min_retry = TX_RETRY_MIN;
692 range->max_retry = TX_RETRY_MAX;
695 * Set the qual, level and noise range values
697 range->max_qual.qual = 100;
698 range->max_qual.level = 0;
699 range->max_qual.noise = 0;
700 range->max_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
702 range->avg_qual.qual = 70;
703 /* TODO: Find real 'good' to 'bad' threshold value for RSSI */
704 range->avg_qual.level = 0;
705 range->avg_qual.noise = 0;
706 range->avg_qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
708 range->sensitivity = 0;
711 * Setup the supported power level ranges
713 memset(range->txpower, 0, sizeof(range->txpower));
714 range->txpower[0] = 5;
715 range->txpower[1] = 7;
716 range->txpower[2] = 9;
717 range->txpower[3] = 11;
718 range->txpower[4] = 13;
719 range->txpower[5] = 15;
720 range->txpower[6] = 17;
721 range->txpower[7] = 19;
723 range->num_txpower = 8;
724 range->txpower_capa = IW_TXPOW_DBM;
725 range->txpower_capa |= IW_TXPOW_RANGE;
727 range->event_capa[0] = (IW_EVENT_CAPA_K_0 |
728 IW_EVENT_CAPA_MASK(SIOCGIWAP) |
729 IW_EVENT_CAPA_MASK(SIOCGIWSCAN));
730 range->event_capa[1] = IW_EVENT_CAPA_K_1;
732 if (adapter->fwcapinfo & FW_CAPINFO_WPA) {
733 range->enc_capa = IW_ENC_CAPA_WPA
735 | IW_ENC_CAPA_CIPHER_TKIP
736 | IW_ENC_CAPA_CIPHER_CCMP;
740 lbs_deb_leave(LBS_DEB_WEXT);
744 static int lbs_set_power(struct net_device *dev, struct iw_request_info *info,
745 struct iw_param *vwrq, char *extra)
747 struct lbs_private *priv = dev->priv;
748 struct lbs_adapter *adapter = priv->adapter;
750 lbs_deb_enter(LBS_DEB_WEXT);
752 /* PS is currently supported only in Infrastructure mode
753 * Remove this check if it is to be supported in IBSS mode also
756 if (vwrq->disabled) {
757 adapter->psmode = LBS802_11POWERMODECAM;
758 if (adapter->psstate != PS_STATE_FULL_POWER) {
759 lbs_ps_wakeup(priv, CMD_OPTION_WAITFORRSP);
765 if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_TIMEOUT) {
767 "setting power timeout is not supported\n");
769 } else if ((vwrq->flags & IW_POWER_TYPE) == IW_POWER_PERIOD) {
770 lbs_deb_wext("setting power period not supported\n");
774 if (adapter->psmode != LBS802_11POWERMODECAM) {
778 adapter->psmode = LBS802_11POWERMODEMAX_PSP;
780 if (adapter->connect_status == LBS_CONNECTED) {
781 lbs_ps_sleep(priv, CMD_OPTION_WAITFORRSP);
784 lbs_deb_leave(LBS_DEB_WEXT);
788 static int lbs_get_power(struct net_device *dev, struct iw_request_info *info,
789 struct iw_param *vwrq, char *extra)
791 struct lbs_private *priv = dev->priv;
792 struct lbs_adapter *adapter = priv->adapter;
795 lbs_deb_enter(LBS_DEB_WEXT);
797 mode = adapter->psmode;
799 if ((vwrq->disabled = (mode == LBS802_11POWERMODECAM))
800 || adapter->connect_status == LBS_DISCONNECTED)
808 lbs_deb_leave(LBS_DEB_WEXT);
812 static struct iw_statistics *lbs_get_wireless_stats(struct net_device *dev)
822 struct lbs_private *priv = dev->priv;
823 struct lbs_adapter *adapter = priv->adapter;
831 lbs_deb_enter(LBS_DEB_WEXT);
833 priv->wstats.status = adapter->mode;
835 /* If we're not associated, all quality values are meaningless */
836 if ((adapter->connect_status != LBS_CONNECTED) &&
837 (adapter->mesh_connect_status != LBS_CONNECTED))
840 /* Quality by RSSI */
841 priv->wstats.qual.level =
842 CAL_RSSI(adapter->SNR[TYPE_BEACON][TYPE_NOAVG],
843 adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
845 if (adapter->NF[TYPE_BEACON][TYPE_NOAVG] == 0) {
846 priv->wstats.qual.noise = MRVDRV_NF_DEFAULT_SCAN_VALUE;
848 priv->wstats.qual.noise =
849 CAL_NF(adapter->NF[TYPE_BEACON][TYPE_NOAVG]);
852 lbs_deb_wext("signal level %#x\n", priv->wstats.qual.level);
853 lbs_deb_wext("noise %#x\n", priv->wstats.qual.noise);
855 rssi = priv->wstats.qual.level - priv->wstats.qual.noise;
857 rssi_qual = rssi * POOR / 10;
859 rssi_qual = (rssi - 15) * (FAIR - POOR) / 5 + POOR;
861 rssi_qual = (rssi - 20) * (GOOD - FAIR) / 5 + FAIR;
863 rssi_qual = (rssi - 30) * (VERY_GOOD - GOOD) /
866 rssi_qual = (rssi - 40) * (PERFECT - VERY_GOOD) /
870 /* Quality by TX errors */
871 priv->wstats.discard.retries = priv->stats.tx_errors;
873 tx_retries = le32_to_cpu(adapter->logmsg.retry);
876 tx_qual = (90 - tx_retries) * POOR / 15;
877 else if (tx_retries > 70)
878 tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
879 else if (tx_retries > 65)
880 tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
881 else if (tx_retries > 50)
882 tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
885 tx_qual = (50 - tx_retries) *
886 (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
887 quality = min(quality, tx_qual);
889 priv->wstats.discard.code = le32_to_cpu(adapter->logmsg.wepundecryptable);
890 priv->wstats.discard.fragment = le32_to_cpu(adapter->logmsg.rxfrag);
891 priv->wstats.discard.retries = tx_retries;
892 priv->wstats.discard.misc = le32_to_cpu(adapter->logmsg.ackfailure);
894 /* Calculate quality */
895 priv->wstats.qual.qual = min_t(u8, quality, 100);
896 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED | IW_QUAL_DBM;
899 /* update stats asynchronously for future calls */
900 lbs_prepare_and_send_command(priv, CMD_802_11_RSSI, 0,
902 lbs_prepare_and_send_command(priv, CMD_802_11_GET_LOG, 0,
906 priv->wstats.miss.beacon = 0;
907 priv->wstats.discard.retries = 0;
908 priv->wstats.qual.qual = 0;
909 priv->wstats.qual.level = 0;
910 priv->wstats.qual.noise = 0;
911 priv->wstats.qual.updated = IW_QUAL_ALL_UPDATED;
912 priv->wstats.qual.updated |= IW_QUAL_NOISE_INVALID |
913 IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
916 lbs_deb_leave(LBS_DEB_WEXT);
917 return &priv->wstats;
922 static int lbs_set_freq(struct net_device *dev, struct iw_request_info *info,
923 struct iw_freq *fwrq, char *extra)
926 struct lbs_private *priv = dev->priv;
927 struct lbs_adapter *adapter = priv->adapter;
928 struct chan_freq_power *cfp;
929 struct assoc_request * assoc_req;
931 lbs_deb_enter(LBS_DEB_WEXT);
933 mutex_lock(&adapter->lock);
934 assoc_req = lbs_get_association_request(adapter);
940 /* If setting by frequency, convert to a channel */
942 long f = fwrq->m / 100000;
944 cfp = find_cfp_by_band_and_freq(adapter, 0, f);
946 lbs_deb_wext("invalid freq %ld\n", f);
951 fwrq->m = (int) cfp->channel;
954 /* Setting by channel number */
955 if (fwrq->m > 1000 || fwrq->e > 0) {
959 cfp = lbs_find_cfp_by_band_and_channel(adapter, 0, fwrq->m);
964 assoc_req->channel = fwrq->m;
969 set_bit(ASSOC_FLAG_CHANNEL, &assoc_req->flags);
970 lbs_postpone_association_work(priv);
972 lbs_cancel_association_work(priv);
974 mutex_unlock(&adapter->lock);
976 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
980 static int lbs_set_rate(struct net_device *dev, struct iw_request_info *info,
981 struct iw_param *vwrq, char *extra)
983 struct lbs_private *priv = dev->priv;
984 struct lbs_adapter *adapter = priv->adapter;
988 u8 rates[MAX_RATES + 1];
990 lbs_deb_enter(LBS_DEB_WEXT);
991 lbs_deb_wext("vwrq->value %d\n", vwrq->value);
994 if (vwrq->value == -1) {
995 action = CMD_ACT_SET_TX_AUTO;
996 adapter->auto_rate = 1;
997 adapter->cur_rate = 0;
999 if (vwrq->value % 100000)
1002 memset(rates, 0, sizeof(rates));
1003 copy_active_data_rates(adapter, rates);
1004 new_rate = vwrq->value / 500000;
1005 if (!memchr(rates, new_rate, sizeof(rates))) {
1006 lbs_pr_alert("fixed data rate 0x%X out of range\n",
1011 adapter->cur_rate = new_rate;
1012 action = CMD_ACT_SET_TX_FIX_RATE;
1013 adapter->auto_rate = 0;
1016 ret = lbs_prepare_and_send_command(priv, CMD_802_11_DATA_RATE,
1017 action, CMD_OPTION_WAITFORRSP, 0, NULL);
1020 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1024 static int lbs_get_rate(struct net_device *dev, struct iw_request_info *info,
1025 struct iw_param *vwrq, char *extra)
1027 struct lbs_private *priv = dev->priv;
1028 struct lbs_adapter *adapter = priv->adapter;
1030 lbs_deb_enter(LBS_DEB_WEXT);
1032 if (adapter->connect_status == LBS_CONNECTED) {
1033 vwrq->value = adapter->cur_rate * 500000;
1035 if (adapter->auto_rate)
1045 lbs_deb_leave(LBS_DEB_WEXT);
1049 static int lbs_set_mode(struct net_device *dev,
1050 struct iw_request_info *info, u32 * uwrq, char *extra)
1053 struct lbs_private *priv = dev->priv;
1054 struct lbs_adapter *adapter = priv->adapter;
1055 struct assoc_request * assoc_req;
1057 lbs_deb_enter(LBS_DEB_WEXT);
1059 if ( (*uwrq != IW_MODE_ADHOC)
1060 && (*uwrq != IW_MODE_INFRA)
1061 && (*uwrq != IW_MODE_AUTO)) {
1062 lbs_deb_wext("Invalid mode: 0x%x\n", *uwrq);
1067 mutex_lock(&adapter->lock);
1068 assoc_req = lbs_get_association_request(adapter);
1071 lbs_cancel_association_work(priv);
1073 assoc_req->mode = *uwrq;
1074 set_bit(ASSOC_FLAG_MODE, &assoc_req->flags);
1075 lbs_postpone_association_work(priv);
1076 lbs_deb_wext("Switching to mode: 0x%x\n", *uwrq);
1078 mutex_unlock(&adapter->lock);
1081 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1087 * @brief Get Encryption key
1089 * @param dev A pointer to net_device structure
1090 * @param info A pointer to iw_request_info structure
1091 * @param vwrq A pointer to iw_param structure
1092 * @param extra A pointer to extra data buf
1093 * @return 0 --success, otherwise fail
1095 static int lbs_get_encode(struct net_device *dev,
1096 struct iw_request_info *info,
1097 struct iw_point *dwrq, u8 * extra)
1099 struct lbs_private *priv = dev->priv;
1100 struct lbs_adapter *adapter = priv->adapter;
1101 int index = (dwrq->flags & IW_ENCODE_INDEX) - 1;
1103 lbs_deb_enter(LBS_DEB_WEXT);
1105 lbs_deb_wext("flags 0x%x, index %d, length %d, wep_tx_keyidx %d\n",
1106 dwrq->flags, index, dwrq->length, adapter->wep_tx_keyidx);
1110 /* Authentication method */
1111 switch (adapter->secinfo.auth_mode) {
1112 case IW_AUTH_ALG_OPEN_SYSTEM:
1113 dwrq->flags = IW_ENCODE_OPEN;
1116 case IW_AUTH_ALG_SHARED_KEY:
1117 case IW_AUTH_ALG_LEAP:
1118 dwrq->flags = IW_ENCODE_RESTRICTED;
1121 dwrq->flags = IW_ENCODE_DISABLED | IW_ENCODE_OPEN;
1125 if ( adapter->secinfo.wep_enabled
1126 || adapter->secinfo.WPAenabled
1127 || adapter->secinfo.WPA2enabled) {
1128 dwrq->flags &= ~IW_ENCODE_DISABLED;
1130 dwrq->flags |= IW_ENCODE_DISABLED;
1133 memset(extra, 0, 16);
1135 mutex_lock(&adapter->lock);
1137 /* Default to returning current transmit key */
1139 index = adapter->wep_tx_keyidx;
1141 if ((adapter->wep_keys[index].len) && adapter->secinfo.wep_enabled) {
1142 memcpy(extra, adapter->wep_keys[index].key,
1143 adapter->wep_keys[index].len);
1144 dwrq->length = adapter->wep_keys[index].len;
1146 dwrq->flags |= (index + 1);
1147 /* Return WEP enabled */
1148 dwrq->flags &= ~IW_ENCODE_DISABLED;
1149 } else if ((adapter->secinfo.WPAenabled)
1150 || (adapter->secinfo.WPA2enabled)) {
1151 /* return WPA enabled */
1152 dwrq->flags &= ~IW_ENCODE_DISABLED;
1154 dwrq->flags |= IW_ENCODE_DISABLED;
1157 mutex_unlock(&adapter->lock);
1159 dwrq->flags |= IW_ENCODE_NOKEY;
1161 lbs_deb_wext("key: %02x:%02x:%02x:%02x:%02x:%02x, keylen %d\n",
1162 extra[0], extra[1], extra[2],
1163 extra[3], extra[4], extra[5], dwrq->length);
1165 lbs_deb_wext("return flags 0x%x\n", dwrq->flags);
1167 lbs_deb_leave(LBS_DEB_WEXT);
1172 * @brief Set Encryption key (internal)
1174 * @param priv A pointer to private card structure
1175 * @param key_material A pointer to key material
1176 * @param key_length length of key material
1177 * @param index key index to set
1178 * @param set_tx_key Force set TX key (1 = yes, 0 = no)
1179 * @return 0 --success, otherwise fail
1181 static int lbs_set_wep_key(struct assoc_request *assoc_req,
1182 const char *key_material,
1188 struct enc_key *pkey;
1190 lbs_deb_enter(LBS_DEB_WEXT);
1192 /* Paranoid validation of key index */
1198 /* validate max key length */
1199 if (key_length > KEY_LEN_WEP_104) {
1204 pkey = &assoc_req->wep_keys[index];
1206 if (key_length > 0) {
1207 memset(pkey, 0, sizeof(struct enc_key));
1208 pkey->type = KEY_TYPE_ID_WEP;
1210 /* Standardize the key length */
1211 pkey->len = (key_length > KEY_LEN_WEP_40) ?
1212 KEY_LEN_WEP_104 : KEY_LEN_WEP_40;
1213 memcpy(pkey->key, key_material, key_length);
1217 /* Ensure the chosen key is valid */
1219 lbs_deb_wext("key not set, so cannot enable it\n");
1223 assoc_req->wep_tx_keyidx = index;
1226 assoc_req->secinfo.wep_enabled = 1;
1229 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1233 static int validate_key_index(u16 def_index, u16 raw_index,
1234 u16 *out_index, u16 *is_default)
1236 if (!out_index || !is_default)
1239 /* Verify index if present, otherwise use default TX key index */
1240 if (raw_index > 0) {
1243 *out_index = raw_index - 1;
1245 *out_index = def_index;
1251 static void disable_wep(struct assoc_request *assoc_req)
1255 lbs_deb_enter(LBS_DEB_WEXT);
1257 /* Set Open System auth mode */
1258 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1260 /* Clear WEP keys and mark WEP as disabled */
1261 assoc_req->secinfo.wep_enabled = 0;
1262 for (i = 0; i < 4; i++)
1263 assoc_req->wep_keys[i].len = 0;
1265 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1266 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1268 lbs_deb_leave(LBS_DEB_WEXT);
1271 static void disable_wpa(struct assoc_request *assoc_req)
1273 lbs_deb_enter(LBS_DEB_WEXT);
1275 memset(&assoc_req->wpa_mcast_key, 0, sizeof (struct enc_key));
1276 assoc_req->wpa_mcast_key.flags = KEY_INFO_WPA_MCAST;
1277 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1279 memset(&assoc_req->wpa_unicast_key, 0, sizeof (struct enc_key));
1280 assoc_req->wpa_unicast_key.flags = KEY_INFO_WPA_UNICAST;
1281 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1283 assoc_req->secinfo.WPAenabled = 0;
1284 assoc_req->secinfo.WPA2enabled = 0;
1285 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1287 lbs_deb_leave(LBS_DEB_WEXT);
1291 * @brief Set Encryption key
1293 * @param dev A pointer to net_device structure
1294 * @param info A pointer to iw_request_info structure
1295 * @param vwrq A pointer to iw_param structure
1296 * @param extra A pointer to extra data buf
1297 * @return 0 --success, otherwise fail
1299 static int lbs_set_encode(struct net_device *dev,
1300 struct iw_request_info *info,
1301 struct iw_point *dwrq, char *extra)
1304 struct lbs_private *priv = dev->priv;
1305 struct lbs_adapter *adapter = priv->adapter;
1306 struct assoc_request * assoc_req;
1307 u16 is_default = 0, index = 0, set_tx_key = 0;
1309 lbs_deb_enter(LBS_DEB_WEXT);
1311 mutex_lock(&adapter->lock);
1312 assoc_req = lbs_get_association_request(adapter);
1318 if (dwrq->flags & IW_ENCODE_DISABLED) {
1319 disable_wep (assoc_req);
1320 disable_wpa (assoc_req);
1324 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1325 (dwrq->flags & IW_ENCODE_INDEX),
1326 &index, &is_default);
1332 /* If WEP isn't enabled, or if there is no key data but a valid
1333 * index, set the TX key.
1335 if (!assoc_req->secinfo.wep_enabled || (dwrq->length == 0 && !is_default))
1338 ret = lbs_set_wep_key(assoc_req, extra, dwrq->length, index, set_tx_key);
1343 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1345 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1347 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1348 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1349 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1350 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1355 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1356 lbs_postpone_association_work(priv);
1358 lbs_cancel_association_work(priv);
1360 mutex_unlock(&adapter->lock);
1362 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1367 * @brief Get Extended Encryption key (WPA/802.1x and WEP)
1369 * @param dev A pointer to net_device structure
1370 * @param info A pointer to iw_request_info structure
1371 * @param vwrq A pointer to iw_param structure
1372 * @param extra A pointer to extra data buf
1373 * @return 0 on success, otherwise failure
1375 static int lbs_get_encodeext(struct net_device *dev,
1376 struct iw_request_info *info,
1377 struct iw_point *dwrq,
1381 struct lbs_private *priv = dev->priv;
1382 struct lbs_adapter *adapter = priv->adapter;
1383 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1384 int index, max_key_len;
1386 lbs_deb_enter(LBS_DEB_WEXT);
1388 max_key_len = dwrq->length - sizeof(*ext);
1389 if (max_key_len < 0)
1392 index = dwrq->flags & IW_ENCODE_INDEX;
1394 if (index < 1 || index > 4)
1398 index = adapter->wep_tx_keyidx;
1401 if (!(ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) &&
1402 ext->alg != IW_ENCODE_ALG_WEP) {
1403 if (index != 0 || adapter->mode != IW_MODE_INFRA)
1407 dwrq->flags = index + 1;
1408 memset(ext, 0, sizeof(*ext));
1410 if ( !adapter->secinfo.wep_enabled
1411 && !adapter->secinfo.WPAenabled
1412 && !adapter->secinfo.WPA2enabled) {
1413 ext->alg = IW_ENCODE_ALG_NONE;
1415 dwrq->flags |= IW_ENCODE_DISABLED;
1419 if ( adapter->secinfo.wep_enabled
1420 && !adapter->secinfo.WPAenabled
1421 && !adapter->secinfo.WPA2enabled) {
1423 ext->alg = IW_ENCODE_ALG_WEP;
1424 ext->key_len = adapter->wep_keys[index].len;
1425 key = &adapter->wep_keys[index].key[0];
1426 } else if ( !adapter->secinfo.wep_enabled
1427 && (adapter->secinfo.WPAenabled ||
1428 adapter->secinfo.WPA2enabled)) {
1430 struct enc_key * pkey = NULL;
1432 if ( adapter->wpa_mcast_key.len
1433 && (adapter->wpa_mcast_key.flags & KEY_INFO_WPA_ENABLED))
1434 pkey = &adapter->wpa_mcast_key;
1435 else if ( adapter->wpa_unicast_key.len
1436 && (adapter->wpa_unicast_key.flags & KEY_INFO_WPA_ENABLED))
1437 pkey = &adapter->wpa_unicast_key;
1440 if (pkey->type == KEY_TYPE_ID_AES) {
1441 ext->alg = IW_ENCODE_ALG_CCMP;
1443 ext->alg = IW_ENCODE_ALG_TKIP;
1445 ext->key_len = pkey->len;
1446 key = &pkey->key[0];
1448 ext->alg = IW_ENCODE_ALG_TKIP;
1455 if (ext->key_len > max_key_len) {
1461 memcpy(ext->key, key, ext->key_len);
1463 dwrq->flags |= IW_ENCODE_NOKEY;
1464 dwrq->flags |= IW_ENCODE_ENABLED;
1469 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1474 * @brief Set Encryption key Extended (WPA/802.1x and WEP)
1476 * @param dev A pointer to net_device structure
1477 * @param info A pointer to iw_request_info structure
1478 * @param vwrq A pointer to iw_param structure
1479 * @param extra A pointer to extra data buf
1480 * @return 0 --success, otherwise fail
1482 static int lbs_set_encodeext(struct net_device *dev,
1483 struct iw_request_info *info,
1484 struct iw_point *dwrq,
1488 struct lbs_private *priv = dev->priv;
1489 struct lbs_adapter *adapter = priv->adapter;
1490 struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
1492 struct assoc_request * assoc_req;
1494 lbs_deb_enter(LBS_DEB_WEXT);
1496 mutex_lock(&adapter->lock);
1497 assoc_req = lbs_get_association_request(adapter);
1503 if ((alg == IW_ENCODE_ALG_NONE) || (dwrq->flags & IW_ENCODE_DISABLED)) {
1504 disable_wep (assoc_req);
1505 disable_wpa (assoc_req);
1506 } else if (alg == IW_ENCODE_ALG_WEP) {
1507 u16 is_default = 0, index, set_tx_key = 0;
1509 ret = validate_key_index(assoc_req->wep_tx_keyidx,
1510 (dwrq->flags & IW_ENCODE_INDEX),
1511 &index, &is_default);
1515 /* If WEP isn't enabled, or if there is no key data but a valid
1516 * index, or if the set-TX-key flag was passed, set the TX key.
1518 if ( !assoc_req->secinfo.wep_enabled
1519 || (dwrq->length == 0 && !is_default)
1520 || (ext->ext_flags & IW_ENCODE_EXT_SET_TX_KEY))
1523 /* Copy key to driver */
1524 ret = lbs_set_wep_key(assoc_req, ext->key, ext->key_len, index,
1529 if (dwrq->flags & IW_ENCODE_RESTRICTED) {
1530 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1531 } else if (dwrq->flags & IW_ENCODE_OPEN) {
1532 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1535 /* Mark the various WEP bits as modified */
1536 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1538 set_bit(ASSOC_FLAG_WEP_KEYS, &assoc_req->flags);
1540 set_bit(ASSOC_FLAG_WEP_TX_KEYIDX, &assoc_req->flags);
1541 } else if ((alg == IW_ENCODE_ALG_TKIP) || (alg == IW_ENCODE_ALG_CCMP)) {
1542 struct enc_key * pkey;
1544 /* validate key length */
1545 if (((alg == IW_ENCODE_ALG_TKIP)
1546 && (ext->key_len != KEY_LEN_WPA_TKIP))
1547 || ((alg == IW_ENCODE_ALG_CCMP)
1548 && (ext->key_len != KEY_LEN_WPA_AES))) {
1549 lbs_deb_wext("invalid size %d for key of alg "
1557 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1558 pkey = &assoc_req->wpa_mcast_key;
1559 set_bit(ASSOC_FLAG_WPA_MCAST_KEY, &assoc_req->flags);
1561 pkey = &assoc_req->wpa_unicast_key;
1562 set_bit(ASSOC_FLAG_WPA_UCAST_KEY, &assoc_req->flags);
1565 memset(pkey, 0, sizeof (struct enc_key));
1566 memcpy(pkey->key, ext->key, ext->key_len);
1567 pkey->len = ext->key_len;
1569 pkey->flags |= KEY_INFO_WPA_ENABLED;
1571 /* Do this after zeroing key structure */
1572 if (ext->ext_flags & IW_ENCODE_EXT_GROUP_KEY) {
1573 pkey->flags |= KEY_INFO_WPA_MCAST;
1575 pkey->flags |= KEY_INFO_WPA_UNICAST;
1578 if (alg == IW_ENCODE_ALG_TKIP) {
1579 pkey->type = KEY_TYPE_ID_TKIP;
1580 } else if (alg == IW_ENCODE_ALG_CCMP) {
1581 pkey->type = KEY_TYPE_ID_AES;
1584 /* If WPA isn't enabled yet, do that now */
1585 if ( assoc_req->secinfo.WPAenabled == 0
1586 && assoc_req->secinfo.WPA2enabled == 0) {
1587 assoc_req->secinfo.WPAenabled = 1;
1588 assoc_req->secinfo.WPA2enabled = 1;
1589 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1592 disable_wep (assoc_req);
1597 lbs_postpone_association_work(priv);
1599 lbs_cancel_association_work(priv);
1601 mutex_unlock(&adapter->lock);
1603 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1608 static int lbs_set_genie(struct net_device *dev,
1609 struct iw_request_info *info,
1610 struct iw_point *dwrq,
1613 struct lbs_private *priv = dev->priv;
1614 struct lbs_adapter *adapter = priv->adapter;
1616 struct assoc_request * assoc_req;
1618 lbs_deb_enter(LBS_DEB_WEXT);
1620 mutex_lock(&adapter->lock);
1621 assoc_req = lbs_get_association_request(adapter);
1627 if (dwrq->length > MAX_WPA_IE_LEN ||
1628 (dwrq->length && extra == NULL)) {
1634 memcpy(&assoc_req->wpa_ie[0], extra, dwrq->length);
1635 assoc_req->wpa_ie_len = dwrq->length;
1637 memset(&assoc_req->wpa_ie[0], 0, sizeof(adapter->wpa_ie));
1638 assoc_req->wpa_ie_len = 0;
1643 set_bit(ASSOC_FLAG_WPA_IE, &assoc_req->flags);
1644 lbs_postpone_association_work(priv);
1646 lbs_cancel_association_work(priv);
1648 mutex_unlock(&adapter->lock);
1650 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1654 static int lbs_get_genie(struct net_device *dev,
1655 struct iw_request_info *info,
1656 struct iw_point *dwrq,
1660 struct lbs_private *priv = dev->priv;
1661 struct lbs_adapter *adapter = priv->adapter;
1663 lbs_deb_enter(LBS_DEB_WEXT);
1665 if (adapter->wpa_ie_len == 0) {
1670 if (dwrq->length < adapter->wpa_ie_len) {
1675 dwrq->length = adapter->wpa_ie_len;
1676 memcpy(extra, &adapter->wpa_ie[0], adapter->wpa_ie_len);
1679 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1684 static int lbs_set_auth(struct net_device *dev,
1685 struct iw_request_info *info,
1686 struct iw_param *dwrq,
1689 struct lbs_private *priv = dev->priv;
1690 struct lbs_adapter *adapter = priv->adapter;
1691 struct assoc_request * assoc_req;
1695 lbs_deb_enter(LBS_DEB_WEXT);
1697 mutex_lock(&adapter->lock);
1698 assoc_req = lbs_get_association_request(adapter);
1704 switch (dwrq->flags & IW_AUTH_INDEX) {
1705 case IW_AUTH_TKIP_COUNTERMEASURES:
1706 case IW_AUTH_CIPHER_PAIRWISE:
1707 case IW_AUTH_CIPHER_GROUP:
1708 case IW_AUTH_KEY_MGMT:
1709 case IW_AUTH_DROP_UNENCRYPTED:
1711 * libertas does not use these parameters
1715 case IW_AUTH_WPA_VERSION:
1716 if (dwrq->value & IW_AUTH_WPA_VERSION_DISABLED) {
1717 assoc_req->secinfo.WPAenabled = 0;
1718 assoc_req->secinfo.WPA2enabled = 0;
1719 disable_wpa (assoc_req);
1721 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA) {
1722 assoc_req->secinfo.WPAenabled = 1;
1723 assoc_req->secinfo.wep_enabled = 0;
1724 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1726 if (dwrq->value & IW_AUTH_WPA_VERSION_WPA2) {
1727 assoc_req->secinfo.WPA2enabled = 1;
1728 assoc_req->secinfo.wep_enabled = 0;
1729 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1734 case IW_AUTH_80211_AUTH_ALG:
1735 if (dwrq->value & IW_AUTH_ALG_SHARED_KEY) {
1736 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_SHARED_KEY;
1737 } else if (dwrq->value & IW_AUTH_ALG_OPEN_SYSTEM) {
1738 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1739 } else if (dwrq->value & IW_AUTH_ALG_LEAP) {
1740 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_LEAP;
1747 case IW_AUTH_WPA_ENABLED:
1749 if (!assoc_req->secinfo.WPAenabled &&
1750 !assoc_req->secinfo.WPA2enabled) {
1751 assoc_req->secinfo.WPAenabled = 1;
1752 assoc_req->secinfo.WPA2enabled = 1;
1753 assoc_req->secinfo.wep_enabled = 0;
1754 assoc_req->secinfo.auth_mode = IW_AUTH_ALG_OPEN_SYSTEM;
1757 assoc_req->secinfo.WPAenabled = 0;
1758 assoc_req->secinfo.WPA2enabled = 0;
1759 disable_wpa (assoc_req);
1772 set_bit(ASSOC_FLAG_SECINFO, &assoc_req->flags);
1773 lbs_postpone_association_work(priv);
1774 } else if (ret != -EOPNOTSUPP) {
1775 lbs_cancel_association_work(priv);
1777 mutex_unlock(&adapter->lock);
1779 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1783 static int lbs_get_auth(struct net_device *dev,
1784 struct iw_request_info *info,
1785 struct iw_param *dwrq,
1789 struct lbs_private *priv = dev->priv;
1790 struct lbs_adapter *adapter = priv->adapter;
1792 lbs_deb_enter(LBS_DEB_WEXT);
1794 switch (dwrq->flags & IW_AUTH_INDEX) {
1795 case IW_AUTH_WPA_VERSION:
1797 if (adapter->secinfo.WPAenabled)
1798 dwrq->value |= IW_AUTH_WPA_VERSION_WPA;
1799 if (adapter->secinfo.WPA2enabled)
1800 dwrq->value |= IW_AUTH_WPA_VERSION_WPA2;
1802 dwrq->value |= IW_AUTH_WPA_VERSION_DISABLED;
1805 case IW_AUTH_80211_AUTH_ALG:
1806 dwrq->value = adapter->secinfo.auth_mode;
1809 case IW_AUTH_WPA_ENABLED:
1810 if (adapter->secinfo.WPAenabled && adapter->secinfo.WPA2enabled)
1818 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1823 static int lbs_set_txpow(struct net_device *dev, struct iw_request_info *info,
1824 struct iw_param *vwrq, char *extra)
1827 struct lbs_private *priv = dev->priv;
1828 struct lbs_adapter *adapter = priv->adapter;
1832 lbs_deb_enter(LBS_DEB_WEXT);
1834 if (vwrq->disabled) {
1835 lbs_radio_ioctl(priv, RADIO_OFF);
1839 adapter->preamble = CMD_TYPE_AUTO_PREAMBLE;
1841 lbs_radio_ioctl(priv, RADIO_ON);
1843 /* Userspace check in iwrange if it should use dBm or mW,
1844 * therefore this should never happen... Jean II */
1845 if ((vwrq->flags & IW_TXPOW_TYPE) == IW_TXPOW_MWATT) {
1848 dbm = (u16) vwrq->value;
1850 /* auto tx power control */
1852 if (vwrq->fixed == 0)
1855 lbs_deb_wext("txpower set %d dbm\n", dbm);
1857 ret = lbs_prepare_and_send_command(priv,
1858 CMD_802_11_RF_TX_POWER,
1859 CMD_ACT_TX_POWER_OPT_SET_LOW,
1860 CMD_OPTION_WAITFORRSP, 0, (void *)&dbm);
1862 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1866 static int lbs_get_essid(struct net_device *dev, struct iw_request_info *info,
1867 struct iw_point *dwrq, char *extra)
1869 struct lbs_private *priv = dev->priv;
1870 struct lbs_adapter *adapter = priv->adapter;
1872 lbs_deb_enter(LBS_DEB_WEXT);
1875 * Note : if dwrq->flags != 0, we should get the relevant SSID from
1880 * Get the current SSID
1882 if (adapter->connect_status == LBS_CONNECTED) {
1883 memcpy(extra, adapter->curbssparams.ssid,
1884 adapter->curbssparams.ssid_len);
1885 extra[adapter->curbssparams.ssid_len] = '\0';
1887 memset(extra, 0, 32);
1888 extra[adapter->curbssparams.ssid_len] = '\0';
1891 * If none, we may want to get the one that was set
1894 dwrq->length = adapter->curbssparams.ssid_len;
1896 dwrq->flags = 1; /* active */
1898 lbs_deb_leave(LBS_DEB_WEXT);
1902 static int lbs_set_essid(struct net_device *dev, struct iw_request_info *info,
1903 struct iw_point *dwrq, char *extra)
1905 struct lbs_private *priv = dev->priv;
1906 struct lbs_adapter *adapter = priv->adapter;
1908 u8 ssid[IW_ESSID_MAX_SIZE];
1910 struct assoc_request * assoc_req;
1911 int in_ssid_len = dwrq->length;
1913 lbs_deb_enter(LBS_DEB_WEXT);
1915 /* Check the size of the string */
1916 if (in_ssid_len > IW_ESSID_MAX_SIZE) {
1921 memset(&ssid, 0, sizeof(ssid));
1923 if (!dwrq->flags || !in_ssid_len) {
1924 /* "any" SSID requested; leave SSID blank */
1926 /* Specific SSID requested */
1927 memcpy(&ssid, extra, in_ssid_len);
1928 ssid_len = in_ssid_len;
1932 lbs_deb_wext("requested any SSID\n");
1934 lbs_deb_wext("requested SSID '%s'\n",
1935 escape_essid(ssid, ssid_len));
1939 mutex_lock(&adapter->lock);
1941 /* Get or create the current association request */
1942 assoc_req = lbs_get_association_request(adapter);
1946 /* Copy the SSID to the association request */
1947 memcpy(&assoc_req->ssid, &ssid, IW_ESSID_MAX_SIZE);
1948 assoc_req->ssid_len = ssid_len;
1949 set_bit(ASSOC_FLAG_SSID, &assoc_req->flags);
1950 lbs_postpone_association_work(priv);
1954 /* Cancel the association request if there was an error */
1956 lbs_cancel_association_work(priv);
1959 mutex_unlock(&adapter->lock);
1961 lbs_deb_leave_args(LBS_DEB_WEXT, "ret %d", ret);
1966 * @brief Connect to the AP or Ad-hoc Network with specific bssid
1968 * @param dev A pointer to net_device structure
1969 * @param info A pointer to iw_request_info structure
1970 * @param awrq A pointer to iw_param structure
1971 * @param extra A pointer to extra data buf
1972 * @return 0 --success, otherwise fail
1974 static int lbs_set_wap(struct net_device *dev, struct iw_request_info *info,
1975 struct sockaddr *awrq, char *extra)
1977 struct lbs_private *priv = dev->priv;
1978 struct lbs_adapter *adapter = priv->adapter;
1979 struct assoc_request * assoc_req;
1981 DECLARE_MAC_BUF(mac);
1983 lbs_deb_enter(LBS_DEB_WEXT);
1985 if (awrq->sa_family != ARPHRD_ETHER)
1988 lbs_deb_wext("ASSOC: WAP: sa_data %s\n", print_mac(mac, awrq->sa_data));
1990 mutex_lock(&adapter->lock);
1992 /* Get or create the current association request */
1993 assoc_req = lbs_get_association_request(adapter);
1995 lbs_cancel_association_work(priv);
1998 /* Copy the BSSID to the association request */
1999 memcpy(&assoc_req->bssid, awrq->sa_data, ETH_ALEN);
2000 set_bit(ASSOC_FLAG_BSSID, &assoc_req->flags);
2001 lbs_postpone_association_work(priv);
2004 mutex_unlock(&adapter->lock);
2009 void lbs_get_fwversion(struct lbs_adapter *adapter, char *fwversion, int maxlen)
2013 mutex_lock(&adapter->lock);
2015 if (adapter->fwreleasenumber[3] == 0)
2016 sprintf(fwver, "%u.%u.%u",
2017 adapter->fwreleasenumber[2],
2018 adapter->fwreleasenumber[1],
2019 adapter->fwreleasenumber[0]);
2021 sprintf(fwver, "%u.%u.%u.p%u",
2022 adapter->fwreleasenumber[2],
2023 adapter->fwreleasenumber[1],
2024 adapter->fwreleasenumber[0],
2025 adapter->fwreleasenumber[3]);
2027 mutex_unlock(&adapter->lock);
2028 snprintf(fwversion, maxlen, fwver);
2033 * iwconfig settable callbacks
2035 static const iw_handler lbs_handler[] = {
2036 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2037 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2038 (iw_handler) NULL, /* SIOCSIWNWID */
2039 (iw_handler) NULL, /* SIOCGIWNWID */
2040 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2041 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2042 (iw_handler) lbs_set_mode, /* SIOCSIWMODE */
2043 (iw_handler) lbs_get_mode, /* SIOCGIWMODE */
2044 (iw_handler) NULL, /* SIOCSIWSENS */
2045 (iw_handler) NULL, /* SIOCGIWSENS */
2046 (iw_handler) NULL, /* SIOCSIWRANGE */
2047 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2048 (iw_handler) NULL, /* SIOCSIWPRIV */
2049 (iw_handler) NULL, /* SIOCGIWPRIV */
2050 (iw_handler) NULL, /* SIOCSIWSTATS */
2051 (iw_handler) NULL, /* SIOCGIWSTATS */
2052 iw_handler_set_spy, /* SIOCSIWSPY */
2053 iw_handler_get_spy, /* SIOCGIWSPY */
2054 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2055 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2056 (iw_handler) lbs_set_wap, /* SIOCSIWAP */
2057 (iw_handler) lbs_get_wap, /* SIOCGIWAP */
2058 (iw_handler) NULL, /* SIOCSIWMLME */
2059 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2060 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2061 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2062 (iw_handler) lbs_set_essid, /* SIOCSIWESSID */
2063 (iw_handler) lbs_get_essid, /* SIOCGIWESSID */
2064 (iw_handler) lbs_set_nick, /* SIOCSIWNICKN */
2065 (iw_handler) lbs_get_nick, /* SIOCGIWNICKN */
2066 (iw_handler) NULL, /* -- hole -- */
2067 (iw_handler) NULL, /* -- hole -- */
2068 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2069 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2070 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2071 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2072 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2073 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2074 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2075 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2076 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2077 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2078 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2079 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2080 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2081 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2082 (iw_handler) NULL, /* -- hole -- */
2083 (iw_handler) NULL, /* -- hole -- */
2084 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2085 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2086 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2087 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2088 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2089 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2090 (iw_handler) NULL, /* SIOCSIWPMKSA */
2093 static const iw_handler mesh_wlan_handler[] = {
2094 (iw_handler) NULL, /* SIOCSIWCOMMIT */
2095 (iw_handler) lbs_get_name, /* SIOCGIWNAME */
2096 (iw_handler) NULL, /* SIOCSIWNWID */
2097 (iw_handler) NULL, /* SIOCGIWNWID */
2098 (iw_handler) lbs_set_freq, /* SIOCSIWFREQ */
2099 (iw_handler) lbs_get_freq, /* SIOCGIWFREQ */
2100 (iw_handler) NULL, /* SIOCSIWMODE */
2101 (iw_handler) mesh_wlan_get_mode, /* SIOCGIWMODE */
2102 (iw_handler) NULL, /* SIOCSIWSENS */
2103 (iw_handler) NULL, /* SIOCGIWSENS */
2104 (iw_handler) NULL, /* SIOCSIWRANGE */
2105 (iw_handler) lbs_get_range, /* SIOCGIWRANGE */
2106 (iw_handler) NULL, /* SIOCSIWPRIV */
2107 (iw_handler) NULL, /* SIOCGIWPRIV */
2108 (iw_handler) NULL, /* SIOCSIWSTATS */
2109 (iw_handler) NULL, /* SIOCGIWSTATS */
2110 iw_handler_set_spy, /* SIOCSIWSPY */
2111 iw_handler_get_spy, /* SIOCGIWSPY */
2112 iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
2113 iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
2114 (iw_handler) NULL, /* SIOCSIWAP */
2115 (iw_handler) NULL, /* SIOCGIWAP */
2116 (iw_handler) NULL, /* SIOCSIWMLME */
2117 (iw_handler) NULL, /* SIOCGIWAPLIST - deprecated */
2118 (iw_handler) lbs_set_scan, /* SIOCSIWSCAN */
2119 (iw_handler) lbs_get_scan, /* SIOCGIWSCAN */
2120 (iw_handler) NULL, /* SIOCSIWESSID */
2121 (iw_handler) NULL, /* SIOCGIWESSID */
2122 (iw_handler) NULL, /* SIOCSIWNICKN */
2123 (iw_handler) mesh_get_nick, /* SIOCGIWNICKN */
2124 (iw_handler) NULL, /* -- hole -- */
2125 (iw_handler) NULL, /* -- hole -- */
2126 (iw_handler) lbs_set_rate, /* SIOCSIWRATE */
2127 (iw_handler) lbs_get_rate, /* SIOCGIWRATE */
2128 (iw_handler) lbs_set_rts, /* SIOCSIWRTS */
2129 (iw_handler) lbs_get_rts, /* SIOCGIWRTS */
2130 (iw_handler) lbs_set_frag, /* SIOCSIWFRAG */
2131 (iw_handler) lbs_get_frag, /* SIOCGIWFRAG */
2132 (iw_handler) lbs_set_txpow, /* SIOCSIWTXPOW */
2133 (iw_handler) lbs_get_txpow, /* SIOCGIWTXPOW */
2134 (iw_handler) lbs_set_retry, /* SIOCSIWRETRY */
2135 (iw_handler) lbs_get_retry, /* SIOCGIWRETRY */
2136 (iw_handler) lbs_set_encode, /* SIOCSIWENCODE */
2137 (iw_handler) lbs_get_encode, /* SIOCGIWENCODE */
2138 (iw_handler) lbs_set_power, /* SIOCSIWPOWER */
2139 (iw_handler) lbs_get_power, /* SIOCGIWPOWER */
2140 (iw_handler) NULL, /* -- hole -- */
2141 (iw_handler) NULL, /* -- hole -- */
2142 (iw_handler) lbs_set_genie, /* SIOCSIWGENIE */
2143 (iw_handler) lbs_get_genie, /* SIOCGIWGENIE */
2144 (iw_handler) lbs_set_auth, /* SIOCSIWAUTH */
2145 (iw_handler) lbs_get_auth, /* SIOCGIWAUTH */
2146 (iw_handler) lbs_set_encodeext,/* SIOCSIWENCODEEXT */
2147 (iw_handler) lbs_get_encodeext,/* SIOCGIWENCODEEXT */
2148 (iw_handler) NULL, /* SIOCSIWPMKSA */
2150 struct iw_handler_def lbs_handler_def = {
2151 .num_standard = ARRAY_SIZE(lbs_handler),
2152 .standard = (iw_handler *) lbs_handler,
2153 .get_wireless_stats = lbs_get_wireless_stats,
2156 struct iw_handler_def mesh_handler_def = {
2157 .num_standard = ARRAY_SIZE(mesh_wlan_handler),
2158 .standard = (iw_handler *) mesh_wlan_handler,
2159 .get_wireless_stats = lbs_get_wireless_stats,