2 * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 * Purpose: wireless ext & ioctl functions
42 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
47 #include <net/iw_handler.h>
49 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
50 #define SUPPORTED_WIRELESS_EXT 18
52 #define SUPPORTED_WIRELESS_EXT 17
55 static const long frequency_list
[] = {
56 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
57 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
58 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
59 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
60 5700, 5745, 5765, 5785, 5805, 5825
63 static int msglevel
= MSG_LEVEL_INFO
;
65 struct iw_statistics
*iwctl_get_wireless_stats(struct net_device
*dev
)
67 PSDevice pDevice
= netdev_priv(dev
);
70 pDevice
->wstats
.status
= pDevice
->eOPMode
;
71 if (pDevice
->scStatistic
.LinkQuality
> 100)
72 pDevice
->scStatistic
.LinkQuality
= 100;
73 pDevice
->wstats
.qual
.qual
=(BYTE
)pDevice
->scStatistic
.LinkQuality
;
74 RFvRSSITodBm(pDevice
, (BYTE
)(pDevice
->uCurrRSSI
), &ldBm
);
75 pDevice
->wstats
.qual
.level
= ldBm
;
76 pDevice
->wstats
.qual
.noise
= 0;
77 pDevice
->wstats
.qual
.updated
= 1;
78 pDevice
->wstats
.discard
.nwid
= 0;
79 pDevice
->wstats
.discard
.code
= 0;
80 pDevice
->wstats
.discard
.fragment
= 0;
81 pDevice
->wstats
.discard
.retries
= pDevice
->scStatistic
.dwTsrErr
;
82 pDevice
->wstats
.discard
.misc
= 0;
83 pDevice
->wstats
.miss
.beacon
= 0;
84 return &pDevice
->wstats
;
88 * Wireless Handler : get protocol name
90 int iwctl_giwname(struct net_device
*dev
, struct iw_request_info
*info
,
91 char *wrq
, char *extra
)
93 strcpy(wrq
, "802.11-a/b/g");
98 * Wireless Handler : set scan
100 int iwctl_siwscan(struct net_device
*dev
, struct iw_request_info
*info
,
101 struct iw_point
*wrq
, char *extra
)
103 PSDevice pDevice
= netdev_priv(dev
);
104 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
105 struct iw_scan_req
*req
= (struct iw_scan_req
*)extra
;
106 BYTE abyScanSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
107 PWLAN_IE_SSID pItemSSID
=NULL
;
109 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
112 PRINT_K(" SIOCSIWSCAN \n");
114 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
116 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
120 if (pDevice
->byReAssocCount
> 0) { //reject scan when re-associating!
121 //send scan event to wpa_Supplicant
122 union iwreq_data wrqu
;
123 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
124 memset(&wrqu
, 0, sizeof(wrqu
));
125 wireless_send_event(pDevice
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
129 spin_lock_irq(&pDevice
->lock
);
131 BSSvClearBSSList((void *)pDevice
, pDevice
->bLinkPass
);
133 //mike add: active scan OR passive scan OR desire_ssid scan
134 if (wrq
->length
== sizeof(struct iw_scan_req
)) {
135 if (wrq
->flags
& IW_SCAN_THIS_ESSID
) { //desire_ssid scan
136 memset(abyScanSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
137 pItemSSID
= (PWLAN_IE_SSID
)abyScanSSID
;
138 pItemSSID
->byElementID
= WLAN_EID_SSID
;
139 memcpy(pItemSSID
->abySSID
, req
->essid
, (int)req
->essid_len
);
140 if (pItemSSID
->abySSID
[req
->essid_len
- 1] == '\0') {
141 if (req
->essid_len
>0)
142 pItemSSID
->len
= req
->essid_len
- 1;
145 pItemSSID
->len
= req
->essid_len
;
146 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
147 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID
)abyScanSSID
)->abySSID
,
148 ((PWLAN_IE_SSID
)abyScanSSID
)->len
);
149 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, abyScanSSID
);
150 spin_unlock_irq(&pDevice
->lock
);
154 else if (req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) { //passive scan
155 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
159 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
162 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
163 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
164 spin_unlock_irq(&pDevice
->lock
);
170 * Wireless Handler : get scan results
172 int iwctl_giwscan(struct net_device
*dev
, struct iw_request_info
*info
,
173 struct iw_point
*wrq
, char *extra
)
178 PSDevice pDevice
= netdev_priv(dev
);
179 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
181 PWLAN_IE_SSID pItemSSID
;
182 PWLAN_IE_SUPP_RATES pSuppRates
;
183 PWLAN_IE_SUPP_RATES pExtSuppRates
;
184 char *current_ev
= extra
;
185 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
186 char *current_val
= NULL
;
189 char buf
[MAX_WPA_IE_LEN
* 2 + 30];
191 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSCAN\n");
193 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
197 pBSS
= &(pMgmt
->sBSSList
[0]);
198 for (ii
= 0, jj
= 0; jj
< MAX_BSS_NUM
; jj
++) {
199 if (current_ev
>= end_buf
)
201 pBSS
= &(pMgmt
->sBSSList
[jj
]);
204 memset(&iwe
, 0, sizeof(iwe
));
206 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
207 memcpy(iwe
.u
.ap_addr
.sa_data
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
208 current_ev
= iwe_stream_add_event(info
,current_ev
,end_buf
, &iwe
, IW_EV_ADDR_LEN
);
210 memset(&iwe
, 0, sizeof(iwe
));
211 iwe
.cmd
= SIOCGIWESSID
;
212 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
213 iwe
.u
.data
.length
= pItemSSID
->len
;
214 iwe
.u
.data
.flags
= 1;
215 current_ev
= iwe_stream_add_point(info
,current_ev
,end_buf
, &iwe
, pItemSSID
->abySSID
);
217 memset(&iwe
, 0, sizeof(iwe
));
218 iwe
.cmd
= SIOCGIWMODE
;
219 if (WLAN_GET_CAP_INFO_ESS(pBSS
->wCapInfo
)) {
220 iwe
.u
.mode
= IW_MODE_INFRA
;
223 iwe
.u
.mode
= IW_MODE_ADHOC
;
225 iwe
.len
= IW_EV_UINT_LEN
;
226 current_ev
= iwe_stream_add_event(info
,current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
228 pSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abySuppRates
;
229 pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abyExtSuppRates
;
230 memset(&iwe
, 0, sizeof(iwe
));
231 iwe
.cmd
= SIOCGIWFREQ
;
232 iwe
.u
.freq
.m
= pBSS
->uChannel
;
235 current_ev
= iwe_stream_add_event(info
,current_ev
,end_buf
, &iwe
, IW_EV_FREQ_LEN
);
237 int f
= (int)pBSS
->uChannel
- 1;
239 iwe
.u
.freq
.m
= frequency_list
[f
] * 100000;
242 current_ev
= iwe_stream_add_event(info
,current_ev
,end_buf
, &iwe
, IW_EV_FREQ_LEN
);
244 memset(&iwe
, 0, sizeof(iwe
));
246 RFvRSSITodBm(pDevice
, (BYTE
)(pBSS
->uRSSI
), &ldBm
);
247 iwe
.u
.qual
.level
= ldBm
;
248 iwe
.u
.qual
.noise
= 0;
251 iwe
.u
.qual
.qual
= 100;
252 }else if (-ldBm
> 90) {
255 iwe
.u
.qual
.qual
=(40-(-ldBm
-50))*100/40;
257 iwe
.u
.qual
.updated
=7;
259 current_ev
= iwe_stream_add_event(info
,current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
261 memset(&iwe
, 0, sizeof(iwe
));
262 iwe
.cmd
= SIOCGIWENCODE
;
263 iwe
.u
.data
.length
= 0;
264 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS
->wCapInfo
)) {
265 iwe
.u
.data
.flags
=IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
267 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
269 current_ev
= iwe_stream_add_point(info
,current_ev
,end_buf
, &iwe
, pItemSSID
->abySSID
);
271 memset(&iwe
, 0, sizeof(iwe
));
272 iwe
.cmd
= SIOCGIWRATE
;
273 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
274 current_val
= current_ev
+ IW_EV_LCP_LEN
;
276 for (kk
= 0 ; kk
< 12 ; kk
++) {
277 if (pSuppRates
->abyRates
[kk
] == 0)
279 // Bit rate given in 500 kb/s units (+ 0x80)
280 iwe
.u
.bitrate
.value
= ((pSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
281 current_val
= iwe_stream_add_value(info
,current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
283 for (kk
= 0 ; kk
< 8 ; kk
++) {
284 if (pExtSuppRates
->abyRates
[kk
] == 0)
286 // Bit rate given in 500 kb/s units (+ 0x80)
287 iwe
.u
.bitrate
.value
= ((pExtSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
288 current_val
= iwe_stream_add_value(info
,current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
291 if ((current_val
- current_ev
) > IW_EV_LCP_LEN
)
292 current_ev
= current_val
;
294 memset(&iwe
, 0, sizeof(iwe
));
295 iwe
.cmd
= IWEVCUSTOM
;
296 sprintf(buf
, "bcn_int=%d", pBSS
->wBeaconInterval
);
297 iwe
.u
.data
.length
= strlen(buf
);
298 current_ev
= iwe_stream_add_point(info
,current_ev
, end_buf
, &iwe
, buf
);
300 if ((pBSS
->wWPALen
> 0) && (pBSS
->wWPALen
<= MAX_WPA_IE_LEN
)) {
301 memset(&iwe
, 0, sizeof(iwe
));
303 iwe
.u
.data
.length
= pBSS
->wWPALen
;
304 current_ev
= iwe_stream_add_point(info
,current_ev
, end_buf
, &iwe
, pBSS
->byWPAIE
);
307 if ((pBSS
->wRSNLen
> 0) && (pBSS
->wRSNLen
<= MAX_WPA_IE_LEN
)) {
308 memset(&iwe
, 0, sizeof(iwe
));
310 iwe
.u
.data
.length
= pBSS
->wRSNLen
;
311 current_ev
= iwe_stream_add_point(info
,current_ev
, end_buf
, &iwe
, pBSS
->byRSNIE
);
316 wrq
->length
= current_ev
- extra
;
321 * Wireless Handler : set frequence or channel
323 int iwctl_siwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
324 struct iw_freq
*wrq
, char *extra
)
326 PSDevice pDevice
= netdev_priv(dev
);
329 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFREQ \n");
331 // If setting by frequency, convert to a channel
333 (wrq
->m
>= (int)2.412e8
) &&
334 (wrq
->m
<= (int)2.487e8
)) {
335 int f
= wrq
->m
/ 100000;
337 while ((c
< 14) && (f
!= frequency_list
[c
]))
342 // Setting by channel number
343 if ((wrq
->m
> 14) || (wrq
->e
> 0))
346 int channel
= wrq
->m
;
347 if ((channel
< 1) || (channel
> 14)) {
348 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: New channel value of %d is invalid!\n", dev
->name
, wrq
->m
);
351 // Yes ! We can set it !!!
352 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set to channel = %d\n", channel
);
353 pDevice
->uChannel
= channel
;
361 * Wireless Handler : get frequence or channel
363 int iwctl_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
364 struct iw_freq
*wrq
, char *extra
)
366 PSDevice pDevice
= netdev_priv(dev
);
367 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
369 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFREQ \n");
371 #ifdef WEXT_USECHANNELS
372 wrq
->m
= (int)pMgmt
->uCurrChannel
;
376 int f
= (int)pMgmt
->uCurrChannel
- 1;
379 wrq
->m
= frequency_list
[f
] * 100000;
387 * Wireless Handler : set operation mode
389 int iwctl_siwmode(struct net_device
*dev
, struct iw_request_info
*info
,
390 __u32
*wmode
, char *extra
)
392 PSDevice pDevice
= netdev_priv(dev
);
393 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
396 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMODE \n");
398 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
&& pDevice
->bEnableHostapd
) {
399 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Can't set operation mode, hostapd is running \n");
406 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_IBSS_STA
) {
407 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
408 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
409 pDevice
->bCommit
= TRUE
;
412 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to ad-hoc \n");
416 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_ESS_STA
) {
417 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
418 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
419 pDevice
->bCommit
= TRUE
;
422 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to infrastructure \n");
426 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
430 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_AP
) {
431 pMgmt
->eConfigMode
= WMAC_CONFIG_AP
;
432 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
433 pDevice
->bCommit
= TRUE
;
436 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to Access Point \n");
440 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
451 * Wireless Handler : get operation mode
453 void iwctl_giwmode(struct net_device
*dev
, struct iw_request_info
*info
,
454 __u32
*wmode
, char *extra
)
456 PSDevice pDevice
= netdev_priv(dev
);
457 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
460 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWMODE \n");
461 // If not managed, assume it's ad-hoc
462 switch (pMgmt
->eConfigMode
) {
463 case WMAC_CONFIG_ESS_STA
:
464 *wmode
= IW_MODE_INFRA
;
466 case WMAC_CONFIG_IBSS_STA
:
467 *wmode
= IW_MODE_ADHOC
;
469 case WMAC_CONFIG_AUTO
:
470 *wmode
= IW_MODE_INFRA
;
473 *wmode
= IW_MODE_MASTER
;
476 *wmode
= IW_MODE_ADHOC
;
481 * Wireless Handler : get capability range
483 void iwctl_giwrange(struct net_device
*dev
, struct iw_request_info
*info
,
484 struct iw_point
*wrq
, char *extra
)
486 struct iw_range
*range
= (struct iw_range
*)extra
;
489 BYTE abySupportedRates
[13] = {
490 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
494 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRANGE\n");
496 wrq
->length
= sizeof(struct iw_range
);
497 memset(range
, 0, sizeof(struct iw_range
));
498 range
->min_nwid
= 0x0000;
499 range
->max_nwid
= 0x0000;
500 range
->num_channels
= 14;
501 // Should be based on cap_rid.country to give only
502 // what the current card support
504 for (i
= 0; i
< 14; i
++) {
505 range
->freq
[k
].i
= i
+ 1; // List index
506 range
->freq
[k
].m
= frequency_list
[i
] * 100000;
507 range
->freq
[k
++].e
= 1; // Values in table in MHz -> * 10^5 * 10
509 range
->num_frequency
= k
;
510 // Hum... Should put the right values there
511 range
->max_qual
.qual
= 100;
512 range
->max_qual
.level
= 0;
513 range
->max_qual
.noise
= 0;
514 range
->sensitivity
= 255;
516 for (i
= 0 ; i
< 13 ; i
++) {
517 range
->bitrate
[i
] = abySupportedRates
[i
] * 500000;
518 if (range
->bitrate
[i
] == 0)
521 range
->num_bitrates
= i
;
523 // Set an indication of the max TCP throughput
524 // in bit/s that we can expect using this interface.
525 // May be use for QoS stuff... Jean II
527 range
->throughput
= 5 * 1000 * 1000;
529 range
->throughput
= 1.5 * 1000 * 1000;
532 range
->max_rts
= 2312;
533 range
->min_frag
= 256;
534 range
->max_frag
= 2312;
536 // the encoding capabilities
537 range
->num_encoding_sizes
= 3;
539 range
->encoding_size
[0] = 5;
541 range
->encoding_size
[1] = 13;
542 // 256 bits for WPA-PSK
543 range
->encoding_size
[2] = 32;
544 // 4 keys are allowed
545 range
->max_encoding_tokens
= 4;
547 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
548 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
551 range
->max_pmp
= 1000000;// 1 secs
553 range
->max_pmt
= 1000000;// 1 secs
554 range
->pmp_flags
= IW_POWER_PERIOD
;
555 range
->pmt_flags
= IW_POWER_TIMEOUT
;
556 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_ALL_R
;
558 // Transmit Power - values are in mW
559 range
->txpower
[0] = 100;
560 range
->num_txpower
= 1;
561 range
->txpower_capa
= IW_TXPOW_MWATT
;
562 range
->we_version_source
= SUPPORTED_WIRELESS_EXT
;
563 range
->we_version_compiled
= WIRELESS_EXT
;
564 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
565 range
->retry_flags
= IW_RETRY_LIMIT
;
566 range
->r_time_flags
= IW_RETRY_LIFETIME
;
567 range
->min_retry
= 1;
568 range
->max_retry
= 65535;
569 range
->min_r_time
= 1024;
570 range
->max_r_time
= 65535 * 1024;
571 // Experimental measurements - boundary 11/5.5 Mb/s
572 // Note : with or without the (local->rssi), results
573 // are somewhat different. - Jean II
574 range
->avg_qual
.qual
= 6;
575 range
->avg_qual
.level
= 176; // -80 dBm
576 range
->avg_qual
.noise
= 0;
581 * Wireless Handler : set ap mac address
583 int iwctl_siwap(struct net_device
*dev
, struct iw_request_info
*info
,
584 struct sockaddr
*wrq
, char *extra
)
586 PSDevice pDevice
= netdev_priv(dev
);
587 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
589 BYTE ZeroBSSID
[WLAN_BSSID_LEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
591 PRINT_K(" SIOCSIWAP \n");
593 if (wrq
->sa_family
!= ARPHRD_ETHER
)
596 memcpy(pMgmt
->abyDesireBSSID
, wrq
->sa_data
, 6);
598 if ((is_broadcast_ether_addr(pMgmt
->abyDesireBSSID
)) ||
599 (memcmp(pMgmt
->abyDesireBSSID
, ZeroBSSID
, 6) == 0)){
600 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
603 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
604 // then ignore,because you don't known which one to be connect with??
607 unsigned uSameBssidNum
= 0;
608 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
609 if (pMgmt
->sBSSList
[ii
].bActive
&&
610 !compare_ether_addr(pMgmt
->sBSSList
[ii
].abyBSSID
,
611 pMgmt
->abyDesireBSSID
)) {
615 if (uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
616 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
621 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
622 pDevice
->bCommit
= TRUE
;
629 * Wireless Handler : get ap mac address
631 int iwctl_giwap(struct net_device
*dev
, struct iw_request_info
*info
,
632 struct sockaddr
*wrq
, char *extra
)
634 PSDevice pDevice
= netdev_priv(dev
);
635 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
637 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAP \n");
639 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
641 if ((pDevice
->bLinkPass
== FALSE
) && (pMgmt
->eCurrMode
!= WMAC_MODE_ESS_AP
))
642 memset(wrq
->sa_data
, 0, 6);
644 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
645 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
648 wrq
->sa_family
= ARPHRD_ETHER
;
653 * Wireless Handler : get ap list
655 int iwctl_giwaplist(struct net_device
*dev
, struct iw_request_info
*info
,
656 struct iw_point
*wrq
, char *extra
)
661 struct sockaddr sock
[IW_MAX_AP
];
662 struct iw_quality qual
[IW_MAX_AP
];
663 PSDevice pDevice
= netdev_priv(dev
);
664 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
666 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAPLIST \n");
667 // Only super-user can see AP list
669 if (!capable(CAP_NET_ADMIN
)) {
675 PKnownBSS pBSS
= &(pMgmt
->sBSSList
[0]);
677 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
678 pBSS
= &(pMgmt
->sBSSList
[ii
]);
681 if ( jj
>= IW_MAX_AP
)
683 memcpy(sock
[jj
].sa_data
, pBSS
->abyBSSID
, 6);
684 sock
[jj
].sa_family
= ARPHRD_ETHER
;
685 qual
[jj
].level
= pBSS
->uRSSI
;
686 qual
[jj
].qual
= qual
[jj
].noise
= 0;
687 qual
[jj
].updated
= 2;
691 wrq
->flags
= 1; // Should be define'd
693 memcpy(extra
, sock
, sizeof(struct sockaddr
)*jj
);
694 memcpy(extra
+ sizeof(struct sockaddr
)*jj
, qual
, sizeof(struct iw_quality
)*jj
);
700 * Wireless Handler : set essid
702 int iwctl_siwessid(struct net_device
*dev
, struct iw_request_info
*info
,
703 struct iw_point
*wrq
, char *extra
)
705 PSDevice pDevice
= netdev_priv(dev
);
706 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
707 PWLAN_IE_SSID pItemSSID
;
709 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
712 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWESSID :\n");
714 pDevice
->fWPA_Authened
= FALSE
;
715 // Check if we asked for `any'
716 if (wrq
->flags
== 0) {
717 // Just send an empty SSID list
718 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
719 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
720 PRINT_K("set essid to 'any' \n");
721 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
722 //Unknown desired AP,so here need not associate??
727 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
728 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
729 pItemSSID
->byElementID
= WLAN_EID_SSID
;
731 memcpy(pItemSSID
->abySSID
, extra
, wrq
->length
);
732 if (pItemSSID
->abySSID
[wrq
->length
- 1] == '\0') {
734 pItemSSID
->len
= wrq
->length
- 1;
737 pItemSSID
->len
= wrq
->length
;
738 PRINT_K("set essid to %s \n",pItemSSID
->abySSID
);
740 //mike:need clear desiredBSSID
741 if (pItemSSID
->len
==0) {
742 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
746 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
747 //Wext wil order another command of siwap to link with desired AP,
748 //so here need not associate??
749 if (pDevice
->bWPASuppWextEnabled
== TRUE
) {
750 /*******search if in hidden ssid mode ****/
751 PKnownBSS pCurr
= NULL
;
752 BYTE abyTmpDesireSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
754 unsigned uSameBssidNum
= 0;
756 memcpy(abyTmpDesireSSID
,pMgmt
->abyDesireSSID
,sizeof(abyTmpDesireSSID
));
757 pCurr
= BSSpSearchBSSList(pDevice
, NULL
,
759 pDevice
->eConfigPHYMode
763 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
764 vResetCommandTimer((void *)pDevice
);
765 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
766 bScheduleCommand((void *)pDevice
,
768 pMgmt
->abyDesireSSID
);
769 bScheduleCommand((void *)pDevice
,
771 pMgmt
->abyDesireSSID
);
773 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
774 // by means of judging if there are two same BSSID exist in list ?
775 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
776 if (pMgmt
->sBSSList
[ii
].bActive
&&
777 !compare_ether_addr(pMgmt
->sBSSList
[ii
].abyBSSID
,
782 if (uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
783 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
784 vResetCommandTimer((void *)pDevice
);
785 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
; //this scan type,you'll submit scan result!
786 bScheduleCommand((void *)pDevice
,
788 pMgmt
->abyDesireSSID
);
789 bScheduleCommand((void *)pDevice
,
791 pMgmt
->abyDesireSSID
);
798 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set essid = %s \n", pItemSSID
->abySSID
);
801 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
802 pDevice
->bCommit
= TRUE
;
808 * Wireless Handler : get essid
810 void iwctl_giwessid(struct net_device
*dev
, struct iw_request_info
*info
,
811 struct iw_point
*wrq
, char *extra
)
813 PSDevice pDevice
= netdev_priv(dev
);
814 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
815 PWLAN_IE_SSID pItemSSID
;
817 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWESSID \n");
819 // Note : if wrq->u.data.flags != 0, we should
820 // get the relevant SSID from the SSID list...
822 // Get the current SSID
823 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
824 memcpy(extra
, pItemSSID
->abySSID
, pItemSSID
->len
);
825 extra
[pItemSSID
->len
] = '\0';
827 wrq
->length
= pItemSSID
->len
;
828 wrq
->flags
= 1; // active
832 * Wireless Handler : set data rate
834 int iwctl_siwrate(struct net_device
*dev
, struct iw_request_info
*info
,
835 struct iw_param
*wrq
, char *extra
)
837 PSDevice pDevice
= netdev_priv(dev
);
841 BYTE abySupportedRates
[13] = {
842 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
847 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRATE \n");
848 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
853 // First : get a valid bit rate value
855 // Which type of value
856 if ((wrq
->value
< 13) &&
858 // Setting by rate index
859 // Find value in the magic rate table
862 // Setting by frequency value
863 u8 normvalue
= (u8
) (wrq
->value
/500000);
865 // Check if rate is valid
866 for (i
= 0 ; i
< 13 ; i
++) {
867 if (normvalue
== abySupportedRates
[i
]) {
873 // -1 designed the max rate (mostly auto mode)
874 if (wrq
->value
== -1) {
875 // Get the highest available rate
876 for (i
= 0 ; i
< 13 ; i
++) {
877 if (abySupportedRates
[i
] == 0)
884 // Check that it is valid
885 // brate is index of abySupportedRates[]
891 // Now, check if we want a fixed or auto value
892 if (wrq
->fixed
!= 0) {
895 pDevice
->bFixRate
= TRUE
;
896 if ((pDevice
->byBBType
== BB_TYPE_11B
)&& (brate
> 3)) {
897 pDevice
->uConnectionRate
= 3;
900 pDevice
->uConnectionRate
= brate
;
901 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fixed to Rate %d \n", pDevice
->uConnectionRate
);
906 pDevice
->bFixRate
= FALSE
;
907 pDevice
->uConnectionRate
= 13;
914 * Wireless Handler : get data rate
916 void iwctl_giwrate(struct net_device
*dev
, struct iw_request_info
*info
,
917 struct iw_param
*wrq
, char *extra
)
919 PSDevice pDevice
= netdev_priv(dev
);
920 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
922 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRATE \n");
924 BYTE abySupportedRates
[13] = {
925 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
926 0x48, 0x60, 0x6C, 0x90
930 if (pDevice
->uConnectionRate
< 13) {
931 brate
= abySupportedRates
[pDevice
->uConnectionRate
];
933 if (pDevice
->byBBType
== BB_TYPE_11B
)
935 if (pDevice
->byBBType
== BB_TYPE_11G
)
937 if (pDevice
->byBBType
== BB_TYPE_11A
)
941 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
942 if (pDevice
->byBBType
== BB_TYPE_11B
)
944 if (pDevice
->byBBType
== BB_TYPE_11G
)
946 if (pDevice
->byBBType
== BB_TYPE_11A
)
949 if (pDevice
->uConnectionRate
== 13)
950 brate
= abySupportedRates
[pDevice
->wCurrentRate
];
951 wrq
->value
= brate
* 500000;
952 // If more than one rate, set auto
953 if (pDevice
->bFixRate
== TRUE
)
959 * Wireless Handler : set rts threshold
961 int iwctl_siwrts(struct net_device
*dev
, struct iw_param
*wrq
)
963 PSDevice pDevice
= netdev_priv(dev
);
965 if ((wrq
->value
< 0 || wrq
->value
> 2312) && !wrq
->disabled
)
968 else if (wrq
->disabled
)
969 pDevice
->wRTSThreshold
= 2312;
971 pDevice
->wRTSThreshold
= wrq
->value
;
977 * Wireless Handler : get rts
979 int iwctl_giwrts(struct net_device
*dev
, struct iw_request_info
*info
,
980 struct iw_param
*wrq
, char *extra
)
982 PSDevice pDevice
= netdev_priv(dev
);
984 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRTS \n");
985 wrq
->value
= pDevice
->wRTSThreshold
;
986 wrq
->disabled
= (wrq
->value
>= 2312);
993 * Wireless Handler : set fragment threshold
995 int iwctl_siwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
996 struct iw_param
*wrq
, char *extra
)
998 PSDevice pDevice
= netdev_priv(dev
);
1000 int fthr
= wrq
->value
;
1002 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFRAG \n");
1006 if ((fthr
< 256) || (fthr
> 2312)) {
1009 fthr
&= ~0x1; // Get an even value
1010 pDevice
->wFragmentationThreshold
= (u16
)fthr
;
1016 * Wireless Handler : get fragment threshold
1018 int iwctl_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1019 struct iw_param
*wrq
, char *extra
)
1021 PSDevice pDevice
= netdev_priv(dev
);
1023 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFRAG \n");
1024 wrq
->value
= pDevice
->wFragmentationThreshold
;
1025 wrq
->disabled
= (wrq
->value
>= 2312);
1032 * Wireless Handler : set retry threshold
1034 int iwctl_siwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1035 struct iw_param
*wrq
, char *extra
)
1037 PSDevice pDevice
= netdev_priv(dev
);
1040 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRETRY \n");
1042 if (wrq
->disabled
) {
1047 if (wrq
->flags
& IW_RETRY_LIMIT
) {
1048 if (wrq
->flags
& IW_RETRY_MAX
)
1049 pDevice
->byLongRetryLimit
= wrq
->value
;
1050 else if (wrq
->flags
& IW_RETRY_MIN
)
1051 pDevice
->byShortRetryLimit
= wrq
->value
;
1053 // No modifier : set both
1054 pDevice
->byShortRetryLimit
= wrq
->value
;
1055 pDevice
->byLongRetryLimit
= wrq
->value
;
1058 if (wrq
->flags
& IW_RETRY_LIFETIME
) {
1059 pDevice
->wMaxTransmitMSDULifetime
= wrq
->value
;
1065 * Wireless Handler : get retry threshold
1067 int iwctl_giwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1068 struct iw_param
*wrq
, char *extra
)
1070 PSDevice pDevice
= netdev_priv(dev
);
1071 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRETRY \n");
1072 wrq
->disabled
= 0; // Can't be disabled
1074 // Note : by default, display the min retry number
1075 if ((wrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1076 wrq
->flags
= IW_RETRY_LIFETIME
;
1077 wrq
->value
= (int)pDevice
->wMaxTransmitMSDULifetime
; //ms
1078 } else if ((wrq
->flags
& IW_RETRY_MAX
)) {
1079 wrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1080 wrq
->value
= (int)pDevice
->byLongRetryLimit
;
1082 wrq
->flags
= IW_RETRY_LIMIT
;
1083 wrq
->value
= (int)pDevice
->byShortRetryLimit
;
1084 if ((int)pDevice
->byShortRetryLimit
!= (int)pDevice
->byLongRetryLimit
)
1085 wrq
->flags
|= IW_RETRY_MIN
;
1092 * Wireless Handler : set encode mode
1094 int iwctl_siwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1095 struct iw_point
*wrq
, char *extra
)
1097 PSDevice pDevice
= netdev_priv(dev
);
1098 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1099 DWORD dwKeyIndex
= (DWORD
)(wrq
->flags
& IW_ENCODE_INDEX
);
1103 int index
= (wrq
->flags
& IW_ENCODE_INDEX
);
1105 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODE \n");
1107 // Check the size of the key
1108 if (wrq
->length
> WLAN_WEP232_KEYLEN
) {
1113 if (dwKeyIndex
> WLAN_WEP_NKEYS
) {
1121 // Send the key to the card
1122 if (wrq
->length
> 0) {
1124 if (wrq
->length
== WLAN_WEP232_KEYLEN
) {
1125 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 232 bit wep key\n");
1127 else if (wrq
->length
== WLAN_WEP104_KEYLEN
) {
1128 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 104 bit wep key\n");
1130 else if (wrq
->length
== WLAN_WEP40_KEYLEN
) {
1131 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 40 bit wep key, index= %d\n", (int)dwKeyIndex
);
1133 memset(pDevice
->abyKey
, 0, WLAN_WEP232_KEYLEN
);
1134 memcpy(pDevice
->abyKey
, extra
, wrq
->length
);
1136 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"abyKey: ");
1137 for (ii
= 0; ii
< wrq
->length
; ii
++) {
1138 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pDevice
->abyKey
[ii
]);
1141 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1142 spin_lock_irq(&pDevice
->lock
);
1143 KeybSetDefaultKey( pDevice
,
1145 dwKeyIndex
| (1 << 31),
1151 spin_unlock_irq(&pDevice
->lock
);
1153 pDevice
->byKeyIndex
= (BYTE
)dwKeyIndex
;
1154 pDevice
->uKeyLength
= wrq
->length
;
1155 pDevice
->bTransmitKey
= TRUE
;
1156 pDevice
->bEncryptionEnable
= TRUE
;
1157 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1159 // Do we want to just set the transmit key index ?
1161 pDevice
->byKeyIndex
= index
;
1162 } else if (!(wrq
->flags
& IW_ENCODE_MODE
)) {
1168 if (wrq
->flags
& IW_ENCODE_DISABLED
){
1170 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disable WEP function\n");
1171 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1172 pDevice
->bEncryptionEnable
= FALSE
;
1173 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1174 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1175 spin_lock_irq(&pDevice
->lock
);
1176 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++)
1177 MACvDisableKeyEntry(pDevice
, uu
);
1178 spin_unlock_irq(&pDevice
->lock
);
1181 if (wrq
->flags
& IW_ENCODE_RESTRICTED
) {
1182 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & ShareKey System\n");
1183 pMgmt
->bShareKeyAlgorithm
= TRUE
;
1185 if (wrq
->flags
& IW_ENCODE_OPEN
) {
1186 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & Open System\n");
1187 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1190 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1191 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
1196 int iwctl_giwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1197 struct iw_point
*wrq
, char *extra
)
1199 PSDevice pDevice
= netdev_priv(dev
);
1200 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1201 char abyKey
[WLAN_WEP232_KEYLEN
];
1203 unsigned index
= (unsigned)(wrq
->flags
& IW_ENCODE_INDEX
);
1204 PSKeyItem pKey
= NULL
;
1206 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODE\n");
1208 if (index
> WLAN_WEP_NKEYS
) {
1211 if (index
<1){//get default key
1212 if (pDevice
->byKeyIndex
<WLAN_WEP_NKEYS
){
1213 index
=pDevice
->byKeyIndex
;
1219 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1220 // Check encryption mode
1221 wrq
->flags
= IW_ENCODE_NOKEY
;
1222 // Is WEP enabled ???
1223 if (pDevice
->bEncryptionEnable
)
1224 wrq
->flags
|= IW_ENCODE_ENABLED
;
1226 wrq
->flags
|= IW_ENCODE_DISABLED
;
1228 if (pMgmt
->bShareKeyAlgorithm
)
1229 wrq
->flags
|= IW_ENCODE_RESTRICTED
;
1231 wrq
->flags
|= IW_ENCODE_OPEN
;
1234 if ((index
==0)&&(pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
||
1235 pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)){//get wpa pairwise key
1236 if (KeybGetKey(&(pDevice
->sKey
),pMgmt
->abyCurrBSSID
, 0xffffffff, &pKey
)){
1237 wrq
->length
= pKey
->uKeyLength
;
1238 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1239 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1241 }else if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, (BYTE
)index
, &pKey
)){
1242 wrq
->length
= pKey
->uKeyLength
;
1243 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1244 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1247 wrq
->flags
|= index
+1;
1252 * Wireless Handler : set power mode
1254 int iwctl_siwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1255 struct iw_param
*wrq
, char *extra
)
1257 PSDevice pDevice
= netdev_priv(dev
);
1258 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1261 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER \n");
1263 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
1268 if (wrq
->disabled
) {
1269 pDevice
->ePSMode
= WMAC_POWER_CAM
;
1270 PSvDisablePowerSaving(pDevice
);
1273 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1274 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1275 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1277 } else if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_PERIOD
) {
1278 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1279 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1281 switch (wrq
->flags
& IW_POWER_MODE
) {
1282 case IW_POWER_UNICAST_R
:
1283 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1286 case IW_POWER_ALL_R
:
1287 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ALL_R \n");
1290 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ON \n");
1300 * Wireless Handler : get power mode
1302 int iwctl_giwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1303 struct iw_param
*wrq
, char *extra
)
1305 PSDevice pDevice
= netdev_priv(dev
);
1306 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1307 int mode
= pDevice
->ePSMode
;
1309 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPOWER \n");
1311 if ((wrq
->disabled
= (mode
== WMAC_POWER_CAM
)))
1314 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1315 wrq
->value
= (int)((pMgmt
->wListenInterval
* pMgmt
->wCurrBeaconPeriod
) << 10);
1316 wrq
->flags
= IW_POWER_TIMEOUT
;
1318 wrq
->value
= (int)((pMgmt
->wListenInterval
* pMgmt
->wCurrBeaconPeriod
) << 10);
1319 wrq
->flags
= IW_POWER_PERIOD
;
1321 wrq
->flags
|= IW_POWER_ALL_R
;
1326 * Wireless Handler : get Sensitivity
1328 int iwctl_giwsens(struct net_device
*dev
, struct iw_request_info
*info
,
1329 struct iw_param
*wrq
, char *extra
)
1331 PSDevice pDevice
= netdev_priv(dev
);
1334 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSENS \n");
1335 if (pDevice
->bLinkPass
== TRUE
) {
1336 RFvRSSITodBm(pDevice
, (BYTE
)(pDevice
->uCurrRSSI
), &ldBm
);
1342 wrq
->disabled
= (wrq
->value
== 0);
1347 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1349 int iwctl_siwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1350 struct iw_param
*wrq
, char *extra
)
1352 PSDevice pDevice
= netdev_priv(dev
);
1353 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1355 static int wpa_version
= 0; //must be static to save the last value,einsn liu
1356 static int pairwise
= 0;
1358 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH \n");
1359 switch (wrq
->flags
& IW_AUTH_INDEX
) {
1360 case IW_AUTH_WPA_VERSION
:
1361 wpa_version
= wrq
->value
;
1362 if (wrq
->value
== IW_AUTH_WPA_VERSION_DISABLED
) {
1363 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1365 else if (wrq
->value
== IW_AUTH_WPA_VERSION_WPA
) {
1366 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1369 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1372 case IW_AUTH_CIPHER_PAIRWISE
:
1373 pairwise
= wrq
->value
;
1374 PRINT_K("iwctl_siwauth:set pairwise=%d\n",pairwise
);
1375 if (pairwise
== IW_AUTH_CIPHER_CCMP
){
1376 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1377 }else if (pairwise
== IW_AUTH_CIPHER_TKIP
){
1378 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1379 } else if (pairwise
== IW_AUTH_CIPHER_WEP40
||
1380 pairwise
== IW_AUTH_CIPHER_WEP104
) {
1381 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1382 }else if (pairwise
== IW_AUTH_CIPHER_NONE
){
1383 //do nothing,einsn liu
1384 }else pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1387 case IW_AUTH_CIPHER_GROUP
:
1388 PRINT_K("iwctl_siwauth:set GROUP=%d\n",wrq
->value
);
1389 if (wpa_version
== IW_AUTH_WPA_VERSION_DISABLED
)
1391 if (pairwise
== IW_AUTH_CIPHER_NONE
){
1392 if (wrq
->value
== IW_AUTH_CIPHER_CCMP
){
1393 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1395 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1399 case IW_AUTH_KEY_MGMT
:
1400 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n",wpa_version
,wrq
->value
);
1401 if (wpa_version
== IW_AUTH_WPA_VERSION_WPA2
){
1402 if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1403 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
1404 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
1405 }else if (wpa_version
== IW_AUTH_WPA_VERSION_WPA
){
1406 if (wrq
->value
== 0){
1407 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
1408 }else if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1409 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
1410 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
1413 case IW_AUTH_TKIP_COUNTERMEASURES
:
1415 case IW_AUTH_DROP_UNENCRYPTED
:
1417 case IW_AUTH_80211_AUTH_ALG
:
1418 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n",wrq
->value
);
1419 if (wrq
->value
==IW_AUTH_ALG_OPEN_SYSTEM
){
1420 pMgmt
->bShareKeyAlgorithm
=FALSE
;
1421 }else if (wrq
->value
==IW_AUTH_ALG_SHARED_KEY
){
1422 pMgmt
->bShareKeyAlgorithm
=TRUE
;
1425 case IW_AUTH_WPA_ENABLED
:
1427 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1429 case IW_AUTH_ROAMING_CONTROL
:
1432 case IW_AUTH_PRIVACY_INVOKED
:
1433 pDevice
->bEncryptionEnable
= !!wrq
->value
;
1434 if (pDevice
->bEncryptionEnable
== FALSE
){
1437 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1438 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1439 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
1440 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1450 int iwctl_giwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1451 struct iw_param
*wrq
, char *extra
)
1456 int iwctl_siwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1457 struct iw_point
*wrq
, char *extra
)
1459 PSDevice pDevice
= netdev_priv(dev
);
1460 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1464 if ((wrq
->length
< 2) || (extra
[1]+2 != wrq
->length
)) {
1468 if (wrq
->length
> MAX_WPA_IE_LEN
){
1472 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1473 if (copy_from_user(pMgmt
->abyWPAIE
, extra
, wrq
->length
)){
1477 pMgmt
->wWPAIELen
= wrq
->length
;
1479 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1480 pMgmt
->wWPAIELen
= 0;
1483 out
://not completely ...not necessary in wpa_supplicant 0.5.8
1487 int iwctl_giwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1488 struct iw_point
*wrq
, char *extra
)
1490 PSDevice pDevice
= netdev_priv(dev
);
1491 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1493 int space
= wrq
->length
;
1496 if (pMgmt
->wWPAIELen
> 0){
1497 wrq
->length
= pMgmt
->wWPAIELen
;
1498 if (pMgmt
->wWPAIELen
<= space
){
1499 if (copy_to_user(extra
, pMgmt
->abyWPAIE
, pMgmt
->wWPAIELen
)){
1508 int iwctl_siwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1509 struct iw_point
*wrq
, char *extra
)
1511 PSDevice pDevice
= netdev_priv(dev
);
1512 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1513 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1514 struct viawget_wpa_param
*param
=NULL
;
1520 u8 seq
[IW_ENCODE_SEQ_MAX_SIZE
];
1529 PRINT_K("SIOCSIWENCODEEXT...... \n");
1531 blen
= sizeof(*param
);
1532 buf
= kmalloc((int)blen
, (int)GFP_KERNEL
);
1535 memset(buf
, 0, blen
);
1536 param
= (struct viawget_wpa_param
*)buf
;
1540 case IW_ENCODE_ALG_NONE
:
1541 alg_name
= WPA_ALG_NONE
;
1543 case IW_ENCODE_ALG_WEP
:
1544 alg_name
= WPA_ALG_WEP
;
1546 case IW_ENCODE_ALG_TKIP
:
1547 alg_name
= WPA_ALG_TKIP
;
1549 case IW_ENCODE_ALG_CCMP
:
1550 alg_name
= WPA_ALG_CCMP
;
1553 PRINT_K("Unknown alg = %d\n",ext
->alg
);
1558 memcpy(addr
, ext
->addr
.sa_data
, ETH_ALEN
);
1560 key_idx
= (wrq
->flags
&IW_ENCODE_INDEX
) - 1;
1562 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1564 //recover seq,seq_len
1565 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1566 seq_len
=IW_ENCODE_SEQ_MAX_SIZE
;
1567 memcpy(seq
, ext
->rx_seq
, seq_len
);
1569 //recover key,key_len
1571 key_len
=ext
->key_len
;
1572 memcpy(key
, &ext
->key
[0], key_len
);
1574 memset(key_array
, 0, 64);
1576 memcpy(key_array
, key
, key_len
);
1577 if (key_len
== 32) {
1578 // notice ! the oder
1579 memcpy(&key_array
[16], &key
[24], 8);
1580 memcpy(&key_array
[24], &key
[16], 8);
1584 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1585 memcpy(param
->addr
, addr
, ETH_ALEN
);
1586 param
->u
.wpa_key
.alg_name
= (int)alg_name
;
1587 param
->u
.wpa_key
.set_tx
= set_tx
;
1588 param
->u
.wpa_key
.key_index
= key_idx
;
1589 param
->u
.wpa_key
.key_len
= key_len
;
1590 param
->u
.wpa_key
.key
= (u8
*)key_array
;
1591 param
->u
.wpa_key
.seq
= (u8
*)seq
;
1592 param
->u
.wpa_key
.seq_len
= seq_len
;
1594 //****set if current action is Network Manager count??
1595 //****this method is so foolish,but there is no other way???
1596 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
1597 if (param
->u
.wpa_key
.key_index
==0) {
1598 pDevice
->bwextstep0
= TRUE
;
1600 if ((pDevice
->bwextstep0
== TRUE
) && (param
->u
.wpa_key
.key_index
== 1)) {
1601 pDevice
->bwextstep0
= FALSE
;
1602 pDevice
->bwextstep1
= TRUE
;
1604 if ((pDevice
->bwextstep1
== TRUE
) && (param
->u
.wpa_key
.key_index
== 2)) {
1605 pDevice
->bwextstep1
= FALSE
;
1606 pDevice
->bwextstep2
= TRUE
;
1608 if ((pDevice
->bwextstep2
== TRUE
)&&(param
->u
.wpa_key
.key_index
== 3)) {
1609 pDevice
->bwextstep2
= FALSE
;
1610 pDevice
->bwextstep3
= TRUE
;
1613 if (pDevice
->bwextstep3
== TRUE
) {
1614 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1615 pDevice
->bwextstep0
= FALSE
;
1616 pDevice
->bwextstep1
= FALSE
;
1617 pDevice
->bwextstep2
= FALSE
;
1618 pDevice
->bwextstep3
= FALSE
;
1619 pDevice
->bWPASuppWextEnabled
= TRUE
;
1620 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
1621 KeyvInitTable(pDevice
,&pDevice
->sKey
);
1624 spin_lock_irq(&pDevice
->lock
);
1625 ret
= wpa_set_keys(pDevice
, param
, TRUE
);
1626 spin_unlock_irq(&pDevice
->lock
);
1633 int iwctl_giwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1634 struct iw_point
*wrq
, char *extra
)
1639 int iwctl_siwmlme(struct net_device
*dev
, struct iw_request_info
*info
,
1640 struct iw_point
*wrq
, char *extra
)
1642 PSDevice pDevice
= netdev_priv(dev
);
1643 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1644 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1647 if (memcmp(pMgmt
->abyCurrBSSID
, mlme
->addr
.sa_data
, ETH_ALEN
)){
1652 case IW_MLME_DEAUTH
:
1653 case IW_MLME_DISASSOC
:
1654 if (pDevice
->bLinkPass
== TRUE
){
1655 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1656 bScheduleCommand((void *)pDevice
,
1657 WLAN_CMD_DISASSOCIATE
,
1669 static const iw_handler iwctl_handler
[] = {
1670 (iw_handler
)NULL
, /* SIOCSIWCOMMIT */
1671 (iw_handler
)NULL
, // SIOCGIWNAME
1672 (iw_handler
)NULL
, // SIOCSIWNWID
1673 (iw_handler
)NULL
, // SIOCGIWNWID
1674 (iw_handler
)NULL
, // SIOCSIWFREQ
1675 (iw_handler
)NULL
, // SIOCGIWFREQ
1676 (iw_handler
)NULL
, // SIOCSIWMODE
1677 (iw_handler
)NULL
, // SIOCGIWMODE
1678 (iw_handler
)NULL
, // SIOCSIWSENS
1679 (iw_handler
)NULL
, // SIOCGIWSENS
1680 (iw_handler
)NULL
, // SIOCSIWRANGE
1681 (iw_handler
)iwctl_giwrange
, // SIOCGIWRANGE
1682 (iw_handler
)NULL
, // SIOCSIWPRIV
1683 (iw_handler
)NULL
, // SIOCGIWPRIV
1684 (iw_handler
)NULL
, // SIOCSIWSTATS
1685 (iw_handler
)NULL
, // SIOCGIWSTATS
1686 (iw_handler
)NULL
, // SIOCSIWSPY
1687 (iw_handler
)NULL
, // SIOCGIWSPY
1688 (iw_handler
)NULL
, // -- hole --
1689 (iw_handler
)NULL
, // -- hole --
1690 (iw_handler
)NULL
, // SIOCSIWAP
1691 (iw_handler
)NULL
, // SIOCGIWAP
1692 (iw_handler
)NULL
, // -- hole -- 0x16
1693 (iw_handler
)NULL
, // SIOCGIWAPLIST
1694 (iw_handler
)iwctl_siwscan
, // SIOCSIWSCAN
1695 (iw_handler
)iwctl_giwscan
, // SIOCGIWSCAN
1696 (iw_handler
)NULL
, // SIOCSIWESSID
1697 (iw_handler
)NULL
, // SIOCGIWESSID
1698 (iw_handler
)NULL
, // SIOCSIWNICKN
1699 (iw_handler
)NULL
, // SIOCGIWNICKN
1700 (iw_handler
)NULL
, // -- hole --
1701 (iw_handler
)NULL
, // -- hole --
1702 (iw_handler
)NULL
, // SIOCSIWRATE 0x20
1703 (iw_handler
)NULL
, // SIOCGIWRATE
1704 (iw_handler
)NULL
, // SIOCSIWRTS
1705 (iw_handler
)NULL
, // SIOCGIWRTS
1706 (iw_handler
)NULL
, // SIOCSIWFRAG
1707 (iw_handler
)NULL
, // SIOCGIWFRAG
1708 (iw_handler
)NULL
, // SIOCSIWTXPOW
1709 (iw_handler
)NULL
, // SIOCGIWTXPOW
1710 (iw_handler
)NULL
, // SIOCSIWRETRY
1711 (iw_handler
)NULL
, // SIOCGIWRETRY
1712 (iw_handler
)NULL
, // SIOCSIWENCODE
1713 (iw_handler
)NULL
, // SIOCGIWENCODE
1714 (iw_handler
)NULL
, // SIOCSIWPOWER
1715 (iw_handler
)NULL
, // SIOCGIWPOWER
1716 (iw_handler
)NULL
, // -- hole --
1717 (iw_handler
)NULL
, // -- hole --
1718 (iw_handler
)NULL
, // SIOCSIWGENIE
1719 (iw_handler
)NULL
, // SIOCGIWGENIE
1720 (iw_handler
)NULL
, // SIOCSIWAUTH
1721 (iw_handler
)NULL
, // SIOCGIWAUTH
1722 (iw_handler
)NULL
, // SIOCSIWENCODEEXT
1723 (iw_handler
)NULL
, // SIOCGIWENCODEEXT
1724 (iw_handler
)NULL
, // SIOCSIWPMKSA
1725 (iw_handler
)NULL
, // -- hole --
1728 static const iw_handler iwctl_private_handler
[] = {
1729 NULL
, // SIOCIWFIRSTPRIV
1732 struct iw_priv_args iwctl_private_args
[] = {
1734 IW_PRIV_TYPE_CHAR
| 1024, 0,
1738 const struct iw_handler_def iwctl_handler_def
= {
1739 .get_wireless_stats
= &iwctl_get_wireless_stats
,
1740 .num_standard
= sizeof(iwctl_handler
)/sizeof(iw_handler
),
1742 .num_private_args
= 0,
1743 .standard
= (iw_handler
*)iwctl_handler
,
1745 .private_args
= NULL
,