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;
85 return &pDevice
->wstats
;
89 * Wireless Handler : get protocol name
92 int iwctl_giwname(struct net_device
*dev
,
93 struct iw_request_info
*info
,
97 strcpy(wrq
, "802.11-a/b/g");
102 * Wireless Handler : set scan
105 int iwctl_siwscan(struct net_device
*dev
,
106 struct iw_request_info
*info
,
107 struct iw_point
*wrq
,
110 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
111 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
112 struct iw_scan_req
*req
= (struct iw_scan_req
*)extra
;
113 BYTE abyScanSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
114 PWLAN_IE_SSID pItemSSID
=NULL
;
116 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
119 PRINT_K(" SIOCSIWSCAN \n");
121 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
123 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
127 if(pDevice
->byReAssocCount
> 0) { //reject scan when re-associating!
128 //send scan event to wpa_Supplicant
129 union iwreq_data wrqu
;
130 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
131 memset(&wrqu
, 0, sizeof(wrqu
));
132 wireless_send_event(pDevice
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
136 spin_lock_irq(&pDevice
->lock
);
138 BSSvClearBSSList((void *) pDevice
, pDevice
->bLinkPass
);
140 //mike add: active scan OR passive scan OR desire_ssid scan
141 if(wrq
->length
== sizeof(struct iw_scan_req
)) {
142 if (wrq
->flags
& IW_SCAN_THIS_ESSID
) { //desire_ssid scan
143 memset(abyScanSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
144 pItemSSID
= (PWLAN_IE_SSID
)abyScanSSID
;
145 pItemSSID
->byElementID
= WLAN_EID_SSID
;
146 memcpy(pItemSSID
->abySSID
, req
->essid
, (int)req
->essid_len
);
147 if (pItemSSID
->abySSID
[req
->essid_len
- 1] == '\0') {
149 pItemSSID
->len
= req
->essid_len
- 1;
152 pItemSSID
->len
= req
->essid_len
;
153 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
154 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n",((PWLAN_IE_SSID
)abyScanSSID
)->abySSID
,
155 ((PWLAN_IE_SSID
)abyScanSSID
)->len
);
156 bScheduleCommand((void *) pDevice
, WLAN_CMD_BSSID_SCAN
, abyScanSSID
);
157 spin_unlock_irq(&pDevice
->lock
);
161 else if(req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) { //passive scan
162 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
166 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
169 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
170 bScheduleCommand((void *) pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
171 spin_unlock_irq(&pDevice
->lock
);
177 * Wireless Handler : get scan results
180 int iwctl_giwscan(struct net_device
*dev
,
181 struct iw_request_info
*info
,
182 struct iw_point
*wrq
,
186 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
187 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
189 PWLAN_IE_SSID pItemSSID
;
190 PWLAN_IE_SUPP_RATES pSuppRates
, pExtSuppRates
;
191 char *current_ev
= extra
;
192 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
193 char *current_val
= NULL
;
196 char buf
[MAX_WPA_IE_LEN
* 2 + 30];
198 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSCAN\n");
200 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
204 pBSS
= &(pMgmt
->sBSSList
[0]);
205 for (ii
= 0, jj
= 0; jj
< MAX_BSS_NUM
; jj
++) {
206 if (current_ev
>= end_buf
)
208 pBSS
= &(pMgmt
->sBSSList
[jj
]);
211 memset(&iwe
, 0, sizeof(iwe
));
213 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
214 memcpy(iwe
.u
.ap_addr
.sa_data
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
215 current_ev
= iwe_stream_add_event(info
,current_ev
,end_buf
, &iwe
, IW_EV_ADDR_LEN
);
217 memset(&iwe
, 0, sizeof(iwe
));
218 iwe
.cmd
= SIOCGIWESSID
;
219 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
220 iwe
.u
.data
.length
= pItemSSID
->len
;
221 iwe
.u
.data
.flags
= 1;
222 current_ev
= iwe_stream_add_point(info
,current_ev
,end_buf
, &iwe
, pItemSSID
->abySSID
);
224 memset(&iwe
, 0, sizeof(iwe
));
225 iwe
.cmd
= SIOCGIWMODE
;
226 if (WLAN_GET_CAP_INFO_ESS(pBSS
->wCapInfo
)) {
227 iwe
.u
.mode
= IW_MODE_INFRA
;
230 iwe
.u
.mode
= IW_MODE_ADHOC
;
232 iwe
.len
= IW_EV_UINT_LEN
;
233 current_ev
= iwe_stream_add_event(info
,current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
235 pSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abySuppRates
;
236 pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abyExtSuppRates
;
237 memset(&iwe
, 0, sizeof(iwe
));
238 iwe
.cmd
= SIOCGIWFREQ
;
239 iwe
.u
.freq
.m
= pBSS
->uChannel
;
242 current_ev
= iwe_stream_add_event(info
,current_ev
,end_buf
, &iwe
, IW_EV_FREQ_LEN
);
244 int f
= (int)pBSS
->uChannel
- 1;
246 iwe
.u
.freq
.m
= frequency_list
[f
] * 100000;
249 current_ev
= iwe_stream_add_event(info
,current_ev
,end_buf
, &iwe
, IW_EV_FREQ_LEN
);
251 memset(&iwe
, 0, sizeof(iwe
));
253 RFvRSSITodBm(pDevice
, (BYTE
)(pBSS
->uRSSI
), &ldBm
);
254 iwe
.u
.qual
.level
= ldBm
;
255 iwe
.u
.qual
.noise
= 0;
258 iwe
.u
.qual
.qual
= 100;
259 }else if(-ldBm
> 90) {
262 iwe
.u
.qual
.qual
=(40-(-ldBm
-50))*100/40;
264 iwe
.u
.qual
.updated
=7;
266 current_ev
= iwe_stream_add_event(info
,current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
268 memset(&iwe
, 0, sizeof(iwe
));
269 iwe
.cmd
= SIOCGIWENCODE
;
270 iwe
.u
.data
.length
= 0;
271 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS
->wCapInfo
)) {
272 iwe
.u
.data
.flags
=IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
274 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
276 current_ev
= iwe_stream_add_point(info
,current_ev
,end_buf
, &iwe
, pItemSSID
->abySSID
);
278 memset(&iwe
, 0, sizeof(iwe
));
279 iwe
.cmd
= SIOCGIWRATE
;
280 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
281 current_val
= current_ev
+ IW_EV_LCP_LEN
;
283 for (kk
= 0 ; kk
< 12 ; kk
++) {
284 if (pSuppRates
->abyRates
[kk
] == 0)
286 // Bit rate given in 500 kb/s units (+ 0x80)
287 iwe
.u
.bitrate
.value
= ((pSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
288 current_val
= iwe_stream_add_value(info
,current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
290 for (kk
= 0 ; kk
< 8 ; kk
++) {
291 if (pExtSuppRates
->abyRates
[kk
] == 0)
293 // Bit rate given in 500 kb/s units (+ 0x80)
294 iwe
.u
.bitrate
.value
= ((pExtSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
295 current_val
= iwe_stream_add_value(info
,current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
298 if((current_val
- current_ev
) > IW_EV_LCP_LEN
)
299 current_ev
= current_val
;
301 memset(&iwe
, 0, sizeof(iwe
));
302 iwe
.cmd
= IWEVCUSTOM
;
303 sprintf(buf
, "bcn_int=%d", pBSS
->wBeaconInterval
);
304 iwe
.u
.data
.length
= strlen(buf
);
305 current_ev
= iwe_stream_add_point(info
,current_ev
, end_buf
, &iwe
, buf
);
307 if ((pBSS
->wWPALen
> 0) && (pBSS
->wWPALen
<= MAX_WPA_IE_LEN
)) {
308 memset(&iwe
, 0, sizeof(iwe
));
310 iwe
.u
.data
.length
= pBSS
->wWPALen
;
311 current_ev
= iwe_stream_add_point(info
,current_ev
, end_buf
, &iwe
, pBSS
->byWPAIE
);
314 if ((pBSS
->wRSNLen
> 0) && (pBSS
->wRSNLen
<= MAX_WPA_IE_LEN
)) {
315 memset(&iwe
, 0, sizeof(iwe
));
317 iwe
.u
.data
.length
= pBSS
->wRSNLen
;
318 current_ev
= iwe_stream_add_point(info
,current_ev
, end_buf
, &iwe
, pBSS
->byRSNIE
);
324 wrq
->length
= current_ev
- extra
;
331 * Wireless Handler : set frequence or channel
334 int iwctl_siwfreq(struct net_device
*dev
,
335 struct iw_request_info
*info
,
339 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
342 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFREQ \n");
344 // If setting by frequency, convert to a channel
346 (wrq
->m
>= (int) 2.412e8
) &&
347 (wrq
->m
<= (int) 2.487e8
)) {
348 int f
= wrq
->m
/ 100000;
350 while((c
< 14) && (f
!= frequency_list
[c
]))
355 // Setting by channel number
356 if((wrq
->m
> 14) || (wrq
->e
> 0))
359 int channel
= wrq
->m
;
360 if((channel
< 1) || (channel
> 14)) {
361 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: New channel value of %d is invalid!\n", dev
->name
, wrq
->m
);
364 // Yes ! We can set it !!!
365 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set to channel = %d\n", channel
);
366 pDevice
->uChannel
= channel
;
374 * Wireless Handler : get frequence or channel
377 int iwctl_giwfreq(struct net_device
*dev
,
378 struct iw_request_info
*info
,
382 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
383 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
385 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFREQ \n");
387 #ifdef WEXT_USECHANNELS
388 wrq
->m
= (int)pMgmt
->uCurrChannel
;
392 int f
= (int)pMgmt
->uCurrChannel
- 1;
395 wrq
->m
= frequency_list
[f
] * 100000;
404 * Wireless Handler : set operation mode
407 int iwctl_siwmode(struct net_device
*dev
,
408 struct iw_request_info
*info
,
412 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
413 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
416 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMODE \n");
418 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
&& pDevice
->bEnableHostapd
) {
419 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Can't set operation mode, hostapd is running \n");
426 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_IBSS_STA
) {
427 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
428 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
429 pDevice
->bCommit
= TRUE
;
432 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to ad-hoc \n");
436 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_ESS_STA
) {
437 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
438 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
439 pDevice
->bCommit
= TRUE
;
442 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to infrastructure \n");
446 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
450 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_AP
) {
451 pMgmt
->eConfigMode
= WMAC_CONFIG_AP
;
452 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
453 pDevice
->bCommit
= TRUE
;
456 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to Access Point \n");
460 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
471 * Wireless Handler : get operation mode
474 int iwctl_giwmode(struct net_device
*dev
,
475 struct iw_request_info
*info
,
479 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
480 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
483 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWMODE \n");
484 // If not managed, assume it's ad-hoc
485 switch (pMgmt
->eConfigMode
) {
486 case WMAC_CONFIG_ESS_STA
:
487 *wmode
= IW_MODE_INFRA
;
489 case WMAC_CONFIG_IBSS_STA
:
490 *wmode
= IW_MODE_ADHOC
;
492 case WMAC_CONFIG_AUTO
:
493 *wmode
= IW_MODE_INFRA
;
496 *wmode
= IW_MODE_MASTER
;
499 *wmode
= IW_MODE_ADHOC
;
507 * Wireless Handler : get capability range
510 int iwctl_giwrange(struct net_device
*dev
,
511 struct iw_request_info
*info
,
512 struct iw_point
*wrq
,
515 struct iw_range
*range
= (struct iw_range
*) extra
;
517 BYTE abySupportedRates
[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
519 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRANGE\n");
521 wrq
->length
= sizeof(struct iw_range
);
522 memset(range
, 0, sizeof(struct iw_range
));
523 range
->min_nwid
= 0x0000;
524 range
->max_nwid
= 0x0000;
525 range
->num_channels
= 14;
526 // Should be based on cap_rid.country to give only
527 // what the current card support
529 for (i
= 0; i
< 14; i
++) {
530 range
->freq
[k
].i
= i
+ 1; // List index
531 range
->freq
[k
].m
= frequency_list
[i
] * 100000;
532 range
->freq
[k
++].e
= 1; // Values in table in MHz -> * 10^5 * 10
534 range
->num_frequency
= k
;
535 // Hum... Should put the right values there
536 range
->max_qual
.qual
= 100;
537 range
->max_qual
.level
= 0;
538 range
->max_qual
.noise
= 0;
539 range
->sensitivity
= 255;
541 for (i
= 0 ; i
< 13 ; i
++) {
542 range
->bitrate
[i
] = abySupportedRates
[i
] * 500000;
543 if(range
->bitrate
[i
] == 0)
546 range
->num_bitrates
= i
;
548 // Set an indication of the max TCP throughput
549 // in bit/s that we can expect using this interface.
550 // May be use for QoS stuff... Jean II
552 range
->throughput
= 5 * 1000 * 1000;
554 range
->throughput
= 1.5 * 1000 * 1000;
557 range
->max_rts
= 2312;
558 range
->min_frag
= 256;
559 range
->max_frag
= 2312;
562 // the encoding capabilities
563 range
->num_encoding_sizes
= 3;
565 range
->encoding_size
[0] = 5;
567 range
->encoding_size
[1] = 13;
568 // 256 bits for WPA-PSK
569 range
->encoding_size
[2] = 32;
570 // 4 keys are allowed
571 range
->max_encoding_tokens
= 4;
573 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
574 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
577 range
->max_pmp
= 1000000;// 1 secs
579 range
->max_pmt
= 1000000;// 1 secs
580 range
->pmp_flags
= IW_POWER_PERIOD
;
581 range
->pmt_flags
= IW_POWER_TIMEOUT
;
582 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_ALL_R
;
584 // Transmit Power - values are in mW
586 range
->txpower
[0] = 100;
587 range
->num_txpower
= 1;
588 range
->txpower_capa
= IW_TXPOW_MWATT
;
589 range
->we_version_source
= SUPPORTED_WIRELESS_EXT
;
590 range
->we_version_compiled
= WIRELESS_EXT
;
591 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
592 range
->retry_flags
= IW_RETRY_LIMIT
;
593 range
->r_time_flags
= IW_RETRY_LIFETIME
;
594 range
->min_retry
= 1;
595 range
->max_retry
= 65535;
596 range
->min_r_time
= 1024;
597 range
->max_r_time
= 65535 * 1024;
598 // Experimental measurements - boundary 11/5.5 Mb/s
599 // Note : with or without the (local->rssi), results
600 // are somewhat different. - Jean II
601 range
->avg_qual
.qual
= 6;
602 range
->avg_qual
.level
= 176; // -80 dBm
603 range
->avg_qual
.noise
= 0;
612 * Wireless Handler : set ap mac address
615 int iwctl_siwap(struct net_device
*dev
,
616 struct iw_request_info
*info
,
617 struct sockaddr
*wrq
,
620 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
621 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
623 BYTE ZeroBSSID
[WLAN_BSSID_LEN
]={0x00,0x00,0x00,0x00,0x00,0x00};
625 PRINT_K(" SIOCSIWAP \n");
627 if (wrq
->sa_family
!= ARPHRD_ETHER
)
630 memcpy(pMgmt
->abyDesireBSSID
, wrq
->sa_data
, 6);
633 if ((is_broadcast_ether_addr(pMgmt
->abyDesireBSSID
)) ||
634 (memcmp(pMgmt
->abyDesireBSSID
, ZeroBSSID
, 6) == 0)){
635 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
638 //mike add: if desired AP is hidden ssid(there are two same BSSID in list),
639 // then ignore,because you don't known which one to be connect with??
641 unsigned int ii
, uSameBssidNum
= 0;
642 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
643 if (pMgmt
->sBSSList
[ii
].bActive
&&
644 !compare_ether_addr(pMgmt
->sBSSList
[ii
].abyBSSID
,
645 pMgmt
->abyDesireBSSID
)) {
649 if(uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
650 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
655 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
656 pDevice
->bCommit
= TRUE
;
663 * Wireless Handler : get ap mac address
666 int iwctl_giwap(struct net_device
*dev
,
667 struct iw_request_info
*info
,
668 struct sockaddr
*wrq
,
671 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
672 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
675 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAP \n");
677 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
679 if ((pDevice
->bLinkPass
== FALSE
) && (pMgmt
->eCurrMode
!= WMAC_MODE_ESS_AP
))
680 memset(wrq
->sa_data
, 0, 6);
682 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
683 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
686 wrq
->sa_family
= ARPHRD_ETHER
;
694 * Wireless Handler : get ap list
697 int iwctl_giwaplist(struct net_device
*dev
,
698 struct iw_request_info
*info
,
699 struct iw_point
*wrq
,
703 struct sockaddr sock
[IW_MAX_AP
];
704 struct iw_quality qual
[IW_MAX_AP
];
705 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
706 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
709 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAPLIST \n");
710 // Only super-user can see AP list
712 if (!capable(CAP_NET_ADMIN
)) {
719 PKnownBSS pBSS
= &(pMgmt
->sBSSList
[0]);
721 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
722 pBSS
= &(pMgmt
->sBSSList
[ii
]);
725 if ( jj
>= IW_MAX_AP
)
727 memcpy(sock
[jj
].sa_data
, pBSS
->abyBSSID
, 6);
728 sock
[jj
].sa_family
= ARPHRD_ETHER
;
729 qual
[jj
].level
= pBSS
->uRSSI
;
730 qual
[jj
].qual
= qual
[jj
].noise
= 0;
731 qual
[jj
].updated
= 2;
735 wrq
->flags
= 1; // Should be define'd
737 memcpy(extra
, sock
, sizeof(struct sockaddr
)*jj
);
738 memcpy(extra
+ sizeof(struct sockaddr
)*jj
, qual
, sizeof(struct iw_quality
)*jj
);
746 * Wireless Handler : set essid
749 int iwctl_siwessid(struct net_device
*dev
,
750 struct iw_request_info
*info
,
751 struct iw_point
*wrq
,
754 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
755 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
756 PWLAN_IE_SSID pItemSSID
;
758 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
761 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWESSID :\n");
763 pDevice
->fWPA_Authened
= FALSE
;
764 // Check if we asked for `any'
765 if(wrq
->flags
== 0) {
766 // Just send an empty SSID list
767 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
768 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
769 PRINT_K("set essid to 'any' \n");
770 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
771 //Unknown desired AP,so here need not associate??
776 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
777 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
778 pItemSSID
->byElementID
= WLAN_EID_SSID
;
780 memcpy(pItemSSID
->abySSID
, extra
, wrq
->length
);
781 if (pItemSSID
->abySSID
[wrq
->length
- 1] == '\0') {
783 pItemSSID
->len
= wrq
->length
- 1;
786 pItemSSID
->len
= wrq
->length
;
787 PRINT_K("set essid to %s \n",pItemSSID
->abySSID
);
789 //mike:need clear desiredBSSID
790 if(pItemSSID
->len
==0) {
791 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
795 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
796 //Wext wil order another command of siwap to link with desired AP,
797 //so here need not associate??
798 if(pDevice
->bWPASuppWextEnabled
== TRUE
) {
799 /*******search if in hidden ssid mode ****/
801 PKnownBSS pCurr
= NULL
;
802 BYTE abyTmpDesireSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
803 unsigned int ii
, uSameBssidNum
= 0;
805 memcpy(abyTmpDesireSSID
,pMgmt
->abyDesireSSID
,sizeof(abyTmpDesireSSID
));
806 pCurr
= BSSpSearchBSSList(pDevice
,
809 pDevice
->eConfigPHYMode
813 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
814 vResetCommandTimer((void *) pDevice
);
815 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
816 bScheduleCommand((void *) pDevice
,
818 pMgmt
->abyDesireSSID
);
819 bScheduleCommand((void *) pDevice
,
821 pMgmt
->abyDesireSSID
);
823 else { //mike:to find out if that desired SSID is a hidden-ssid AP ,
824 // by means of judging if there are two same BSSID exist in list ?
825 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
826 if (pMgmt
->sBSSList
[ii
].bActive
&&
827 !compare_ether_addr(pMgmt
->sBSSList
[ii
].abyBSSID
,
832 if(uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
833 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
834 vResetCommandTimer((void *) pDevice
);
835 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
; //this scan type,you'll submit scan result!
836 bScheduleCommand((void *) pDevice
,
838 pMgmt
->abyDesireSSID
);
839 bScheduleCommand((void *) pDevice
,
841 pMgmt
->abyDesireSSID
);
849 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set essid = %s \n", pItemSSID
->abySSID
);
852 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
853 pDevice
->bCommit
= TRUE
;
862 * Wireless Handler : get essid
865 int iwctl_giwessid(struct net_device
*dev
,
866 struct iw_request_info
*info
,
867 struct iw_point
*wrq
,
871 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
872 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
873 PWLAN_IE_SSID pItemSSID
;
875 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWESSID \n");
877 // Note : if wrq->u.data.flags != 0, we should
878 // get the relevant SSID from the SSID list...
880 // Get the current SSID
881 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
882 memcpy(extra
, pItemSSID
->abySSID
, pItemSSID
->len
);
883 extra
[pItemSSID
->len
] = '\0';
885 wrq
->length
= pItemSSID
->len
;
886 wrq
->flags
= 1; // active
892 * Wireless Handler : set data rate
895 int iwctl_siwrate(struct net_device
*dev
,
896 struct iw_request_info
*info
,
897 struct iw_param
*wrq
,
900 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
904 BYTE abySupportedRates
[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
907 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRATE \n");
908 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
913 // First : get a valid bit rate value
915 // Which type of value
916 if((wrq
->value
< 13) &&
918 // Setting by rate index
919 // Find value in the magic rate table
922 // Setting by frequency value
923 u8 normvalue
= (u8
) (wrq
->value
/500000);
925 // Check if rate is valid
926 for (i
= 0 ; i
< 13 ; i
++) {
927 if(normvalue
== abySupportedRates
[i
]) {
933 // -1 designed the max rate (mostly auto mode)
934 if(wrq
->value
== -1) {
935 // Get the highest available rate
936 for (i
= 0 ; i
< 13 ; i
++) {
937 if(abySupportedRates
[i
] == 0)
944 // Check that it is valid
945 // brate is index of abySupportedRates[]
951 // Now, check if we want a fixed or auto value
952 if(wrq
->fixed
!= 0) {
955 pDevice
->bFixRate
= TRUE
;
956 if ((pDevice
->byBBType
== BB_TYPE_11B
)&& (brate
> 3)) {
957 pDevice
->uConnectionRate
= 3;
960 pDevice
->uConnectionRate
= brate
;
961 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fixed to Rate %d \n", pDevice
->uConnectionRate
);
966 pDevice
->bFixRate
= FALSE
;
967 pDevice
->uConnectionRate
= 13;
974 * Wireless Handler : get data rate
977 int iwctl_giwrate(struct net_device
*dev
,
978 struct iw_request_info
*info
,
979 struct iw_param
*wrq
,
982 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
983 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
985 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRATE \n");
987 BYTE abySupportedRates
[13]= {0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48, 0x60, 0x6C, 0x90};
989 if (pDevice
->uConnectionRate
< 13) {
990 brate
= abySupportedRates
[pDevice
->uConnectionRate
];
992 if (pDevice
->byBBType
== BB_TYPE_11B
)
994 if (pDevice
->byBBType
== BB_TYPE_11G
)
996 if (pDevice
->byBBType
== BB_TYPE_11A
)
1000 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
1001 if (pDevice
->byBBType
== BB_TYPE_11B
)
1003 if (pDevice
->byBBType
== BB_TYPE_11G
)
1005 if (pDevice
->byBBType
== BB_TYPE_11A
)
1008 if (pDevice
->uConnectionRate
== 13)
1009 brate
= abySupportedRates
[pDevice
->wCurrentRate
];
1010 wrq
->value
= brate
* 500000;
1011 // If more than one rate, set auto
1012 if (pDevice
->bFixRate
== TRUE
)
1023 * Wireless Handler : set rts threshold
1026 int iwctl_siwrts(struct net_device
*dev
,
1027 struct iw_request_info
*info
,
1028 struct iw_param
*wrq
,
1031 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1034 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRTS \n");
1037 int rthr
= wrq
->value
;
1040 if((rthr
< 0) || (rthr
> 2312)) {
1043 pDevice
->wRTSThreshold
= rthr
;
1051 * Wireless Handler : get rts
1054 int iwctl_giwrts(struct net_device
*dev
,
1055 struct iw_request_info
*info
,
1056 struct iw_param
*wrq
,
1059 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1061 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRTS \n");
1062 wrq
->value
= pDevice
->wRTSThreshold
;
1063 wrq
->disabled
= (wrq
->value
>= 2312);
1070 * Wireless Handler : set fragment threshold
1073 int iwctl_siwfrag(struct net_device
*dev
,
1074 struct iw_request_info
*info
,
1075 struct iw_param
*wrq
,
1078 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1080 int fthr
= wrq
->value
;
1083 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFRAG \n");
1088 if((fthr
< 256) || (fthr
> 2312)) {
1091 fthr
&= ~0x1; // Get an even value
1092 pDevice
->wFragmentationThreshold
= (u16
)fthr
;
1099 * Wireless Handler : get fragment threshold
1102 int iwctl_giwfrag(struct net_device
*dev
,
1103 struct iw_request_info
*info
,
1104 struct iw_param
*wrq
,
1107 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1109 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFRAG \n");
1110 wrq
->value
= pDevice
->wFragmentationThreshold
;
1111 wrq
->disabled
= (wrq
->value
>= 2312);
1120 * Wireless Handler : set retry threshold
1122 int iwctl_siwretry(struct net_device
*dev
,
1123 struct iw_request_info
*info
,
1124 struct iw_param
*wrq
,
1127 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1131 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRETRY \n");
1133 if (wrq
->disabled
) {
1138 if (wrq
->flags
& IW_RETRY_LIMIT
) {
1139 if(wrq
->flags
& IW_RETRY_MAX
)
1140 pDevice
->byLongRetryLimit
= wrq
->value
;
1141 else if (wrq
->flags
& IW_RETRY_MIN
)
1142 pDevice
->byShortRetryLimit
= wrq
->value
;
1144 // No modifier : set both
1145 pDevice
->byShortRetryLimit
= wrq
->value
;
1146 pDevice
->byLongRetryLimit
= wrq
->value
;
1149 if (wrq
->flags
& IW_RETRY_LIFETIME
) {
1150 pDevice
->wMaxTransmitMSDULifetime
= wrq
->value
;
1158 * Wireless Handler : get retry threshold
1160 int iwctl_giwretry(struct net_device
*dev
,
1161 struct iw_request_info
*info
,
1162 struct iw_param
*wrq
,
1165 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1166 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRETRY \n");
1167 wrq
->disabled
= 0; // Can't be disabled
1169 // Note : by default, display the min retry number
1170 if((wrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1171 wrq
->flags
= IW_RETRY_LIFETIME
;
1172 wrq
->value
= (int)pDevice
->wMaxTransmitMSDULifetime
; //ms
1173 } else if((wrq
->flags
& IW_RETRY_MAX
)) {
1174 wrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1175 wrq
->value
= (int)pDevice
->byLongRetryLimit
;
1177 wrq
->flags
= IW_RETRY_LIMIT
;
1178 wrq
->value
= (int)pDevice
->byShortRetryLimit
;
1179 if((int)pDevice
->byShortRetryLimit
!= (int)pDevice
->byLongRetryLimit
)
1180 wrq
->flags
|= IW_RETRY_MIN
;
1189 * Wireless Handler : set encode mode
1191 int iwctl_siwencode(struct net_device
*dev
,
1192 struct iw_request_info
*info
,
1193 struct iw_point
*wrq
,
1196 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1197 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1198 DWORD dwKeyIndex
= (DWORD
)(wrq
->flags
& IW_ENCODE_INDEX
);
1200 int index
= (wrq
->flags
& IW_ENCODE_INDEX
);
1203 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODE \n");
1205 // Check the size of the key
1206 if (wrq
->length
> WLAN_WEP232_KEYLEN
) {
1211 if (dwKeyIndex
> WLAN_WEP_NKEYS
) {
1219 // Send the key to the card
1220 if (wrq
->length
> 0) {
1222 if (wrq
->length
== WLAN_WEP232_KEYLEN
) {
1223 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 232 bit wep key\n");
1225 else if (wrq
->length
== WLAN_WEP104_KEYLEN
) {
1226 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 104 bit wep key\n");
1228 else if (wrq
->length
== WLAN_WEP40_KEYLEN
) {
1229 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 40 bit wep key, index= %d\n", (int)dwKeyIndex
);
1231 memset(pDevice
->abyKey
, 0, WLAN_WEP232_KEYLEN
);
1232 memcpy(pDevice
->abyKey
, extra
, wrq
->length
);
1234 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"abyKey: ");
1235 for (ii
= 0; ii
< wrq
->length
; ii
++) {
1236 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pDevice
->abyKey
[ii
]);
1239 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1240 spin_lock_irq(&pDevice
->lock
);
1241 KeybSetDefaultKey( pDevice
,
1243 dwKeyIndex
| (1 << 31),
1249 spin_unlock_irq(&pDevice
->lock
);
1251 pDevice
->byKeyIndex
= (BYTE
)dwKeyIndex
;
1252 pDevice
->uKeyLength
= wrq
->length
;
1253 pDevice
->bTransmitKey
= TRUE
;
1254 pDevice
->bEncryptionEnable
= TRUE
;
1255 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1257 // Do we want to just set the transmit key index ?
1259 pDevice
->byKeyIndex
= index
;
1260 } else if (!(wrq
->flags
& IW_ENCODE_MODE
)) {
1266 if(wrq
->flags
& IW_ENCODE_DISABLED
){
1268 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disable WEP function\n");
1269 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1270 pDevice
->bEncryptionEnable
= FALSE
;
1271 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1272 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1273 spin_lock_irq(&pDevice
->lock
);
1274 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++)
1275 MACvDisableKeyEntry(pDevice
, uu
);
1276 spin_unlock_irq(&pDevice
->lock
);
1279 if(wrq
->flags
& IW_ENCODE_RESTRICTED
) {
1280 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & ShareKey System\n");
1281 pMgmt
->bShareKeyAlgorithm
= TRUE
;
1283 if(wrq
->flags
& IW_ENCODE_OPEN
) {
1284 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & Open System\n");
1285 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1288 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1289 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
1295 int iwctl_giwencode(struct net_device
*dev
,
1296 struct iw_request_info
*info
,
1297 struct iw_point
*wrq
,
1300 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1301 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1302 char abyKey
[WLAN_WEP232_KEYLEN
];
1304 unsigned int index
= (unsigned int)(wrq
->flags
& IW_ENCODE_INDEX
);
1305 PSKeyItem pKey
= NULL
;
1307 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODE\n");
1309 if (index
> WLAN_WEP_NKEYS
) {
1312 if(index
<1){//get default key
1313 if(pDevice
->byKeyIndex
<WLAN_WEP_NKEYS
){
1314 index
=pDevice
->byKeyIndex
;
1320 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1321 // Check encryption mode
1322 wrq
->flags
= IW_ENCODE_NOKEY
;
1323 // Is WEP enabled ???
1324 if (pDevice
->bEncryptionEnable
)
1325 wrq
->flags
|= IW_ENCODE_ENABLED
;
1327 wrq
->flags
|= IW_ENCODE_DISABLED
;
1329 if (pMgmt
->bShareKeyAlgorithm
)
1330 wrq
->flags
|= IW_ENCODE_RESTRICTED
;
1332 wrq
->flags
|= IW_ENCODE_OPEN
;
1335 if((index
==0)&&(pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
||
1336 pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)){//get wpa pairwise key
1337 if (KeybGetKey(&(pDevice
->sKey
),pMgmt
->abyCurrBSSID
, 0xffffffff, &pKey
)){
1338 wrq
->length
= pKey
->uKeyLength
;
1339 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1340 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1342 }else if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, (BYTE
)index
, &pKey
)){
1343 wrq
->length
= pKey
->uKeyLength
;
1344 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1345 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1348 wrq
->flags
|= index
+1;
1355 * Wireless Handler : set power mode
1357 int iwctl_siwpower(struct net_device
*dev
,
1358 struct iw_request_info
*info
,
1359 struct iw_param
*wrq
,
1362 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1363 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1366 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER \n");
1368 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
1373 if (wrq
->disabled
) {
1374 pDevice
->ePSMode
= WMAC_POWER_CAM
;
1375 PSvDisablePowerSaving(pDevice
);
1378 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1379 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1380 PSvEnablePowerSaving((void *) pDevice
, pMgmt
->wListenInterval
);
1382 } else if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_PERIOD
) {
1383 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1384 PSvEnablePowerSaving((void *) pDevice
, pMgmt
->wListenInterval
);
1386 switch (wrq
->flags
& IW_POWER_MODE
) {
1387 case IW_POWER_UNICAST_R
:
1388 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1391 case IW_POWER_ALL_R
:
1392 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ALL_R \n");
1395 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ON \n");
1405 * Wireless Handler : get power mode
1407 int iwctl_giwpower(struct net_device
*dev
,
1408 struct iw_request_info
*info
,
1409 struct iw_param
*wrq
,
1412 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1413 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1414 int mode
= pDevice
->ePSMode
;
1417 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPOWER \n");
1420 if ((wrq
->disabled
= (mode
== WMAC_POWER_CAM
)))
1423 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1424 wrq
->value
= (int)((pMgmt
->wListenInterval
* pMgmt
->wCurrBeaconPeriod
) << 10);
1425 wrq
->flags
= IW_POWER_TIMEOUT
;
1427 wrq
->value
= (int)((pMgmt
->wListenInterval
* pMgmt
->wCurrBeaconPeriod
) << 10);
1428 wrq
->flags
= IW_POWER_PERIOD
;
1430 wrq
->flags
|= IW_POWER_ALL_R
;
1437 * Wireless Handler : get Sensitivity
1439 int iwctl_giwsens(struct net_device
*dev
,
1440 struct iw_request_info
*info
,
1441 struct iw_param
*wrq
,
1444 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1447 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSENS \n");
1448 if (pDevice
->bLinkPass
== TRUE
) {
1449 RFvRSSITodBm(pDevice
, (BYTE
)(pDevice
->uCurrRSSI
), &ldBm
);
1455 wrq
->disabled
= (wrq
->value
== 0);
1462 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1464 int iwctl_siwauth(struct net_device
*dev
,
1465 struct iw_request_info
*info
,
1466 struct iw_param
*wrq
,
1469 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1470 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1472 static int wpa_version
=0; //must be static to save the last value,einsn liu
1473 static int pairwise
=0;
1475 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH \n");
1476 switch (wrq
->flags
& IW_AUTH_INDEX
) {
1477 case IW_AUTH_WPA_VERSION
:
1478 wpa_version
= wrq
->value
;
1479 if(wrq
->value
== IW_AUTH_WPA_VERSION_DISABLED
) {
1480 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1482 else if(wrq
->value
== IW_AUTH_WPA_VERSION_WPA
) {
1483 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1486 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1489 case IW_AUTH_CIPHER_PAIRWISE
:
1490 pairwise
= wrq
->value
;
1491 PRINT_K("iwctl_siwauth:set pairwise=%d\n",pairwise
);
1492 if(pairwise
== IW_AUTH_CIPHER_CCMP
){
1493 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1494 }else if(pairwise
== IW_AUTH_CIPHER_TKIP
){
1495 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1496 } else if (pairwise
== IW_AUTH_CIPHER_WEP40
||
1497 pairwise
== IW_AUTH_CIPHER_WEP104
) {
1498 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1499 }else if(pairwise
== IW_AUTH_CIPHER_NONE
){
1500 //do nothing,einsn liu
1501 }else pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1504 case IW_AUTH_CIPHER_GROUP
:
1505 PRINT_K("iwctl_siwauth:set GROUP=%d\n",wrq
->value
);
1506 if(wpa_version
== IW_AUTH_WPA_VERSION_DISABLED
)
1508 if(pairwise
== IW_AUTH_CIPHER_NONE
){
1509 if(wrq
->value
== IW_AUTH_CIPHER_CCMP
){
1510 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1512 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1516 case IW_AUTH_KEY_MGMT
:
1517 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n",wpa_version
,wrq
->value
);
1518 if(wpa_version
== IW_AUTH_WPA_VERSION_WPA2
){
1519 if(wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1520 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
1521 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
1522 }else if(wpa_version
== IW_AUTH_WPA_VERSION_WPA
){
1523 if(wrq
->value
== 0){
1524 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
1525 }else if(wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1526 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
1527 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
1531 case IW_AUTH_TKIP_COUNTERMEASURES
:
1533 case IW_AUTH_DROP_UNENCRYPTED
:
1535 case IW_AUTH_80211_AUTH_ALG
:
1536 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n",wrq
->value
);
1537 if(wrq
->value
==IW_AUTH_ALG_OPEN_SYSTEM
){
1538 pMgmt
->bShareKeyAlgorithm
=FALSE
;
1539 }else if(wrq
->value
==IW_AUTH_ALG_SHARED_KEY
){
1540 pMgmt
->bShareKeyAlgorithm
=TRUE
;
1543 case IW_AUTH_WPA_ENABLED
:
1545 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1547 case IW_AUTH_ROAMING_CONTROL
:
1550 case IW_AUTH_PRIVACY_INVOKED
:
1551 pDevice
->bEncryptionEnable
= !!wrq
->value
;
1552 if(pDevice
->bEncryptionEnable
== FALSE
){
1555 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1556 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1557 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
1558 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1570 int iwctl_giwauth(struct net_device
*dev
,
1571 struct iw_request_info
*info
,
1572 struct iw_param
*wrq
,
1580 int iwctl_siwgenie(struct net_device
*dev
,
1581 struct iw_request_info
*info
,
1582 struct iw_point
*wrq
,
1585 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1586 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1590 if ((wrq
->length
< 2) || (extra
[1]+2 != wrq
->length
)) {
1594 if(wrq
->length
> MAX_WPA_IE_LEN
){
1598 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1599 if(copy_from_user(pMgmt
->abyWPAIE
, extra
, wrq
->length
)){
1603 pMgmt
->wWPAIELen
= wrq
->length
;
1605 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1606 pMgmt
->wWPAIELen
= 0;
1609 out
://not completely ...not necessary in wpa_supplicant 0.5.8
1613 int iwctl_giwgenie(struct net_device
*dev
,
1614 struct iw_request_info
*info
,
1615 struct iw_point
*wrq
,
1618 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1619 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1621 int space
= wrq
->length
;
1624 if(pMgmt
->wWPAIELen
> 0){
1625 wrq
->length
= pMgmt
->wWPAIELen
;
1626 if(pMgmt
->wWPAIELen
<= space
){
1627 if(copy_to_user(extra
, pMgmt
->abyWPAIE
, pMgmt
->wWPAIELen
)){
1638 int iwctl_siwencodeext(struct net_device
*dev
,
1639 struct iw_request_info
*info
,
1640 struct iw_point
*wrq
,
1643 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1644 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1645 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1646 struct viawget_wpa_param
*param
=NULL
;
1650 int key_idx
, set_tx
=0;
1651 u8 seq
[IW_ENCODE_SEQ_MAX_SIZE
];
1653 size_t seq_len
=0,key_len
=0;
1659 PRINT_K("SIOCSIWENCODEEXT...... \n");
1661 blen
= sizeof(*param
);
1662 buf
= kmalloc((int)blen
, (int)GFP_KERNEL
);
1665 memset(buf
, 0, blen
);
1666 param
= (struct viawget_wpa_param
*) buf
;
1670 case IW_ENCODE_ALG_NONE
:
1671 alg_name
= WPA_ALG_NONE
;
1673 case IW_ENCODE_ALG_WEP
:
1674 alg_name
= WPA_ALG_WEP
;
1676 case IW_ENCODE_ALG_TKIP
:
1677 alg_name
= WPA_ALG_TKIP
;
1679 case IW_ENCODE_ALG_CCMP
:
1680 alg_name
= WPA_ALG_CCMP
;
1683 PRINT_K("Unknown alg = %d\n",ext
->alg
);
1688 memcpy(addr
, ext
->addr
.sa_data
, ETH_ALEN
);
1690 key_idx
= (wrq
->flags
&IW_ENCODE_INDEX
) - 1;
1692 if(ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1694 //recover seq,seq_len
1695 if(ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1696 seq_len
=IW_ENCODE_SEQ_MAX_SIZE
;
1697 memcpy(seq
, ext
->rx_seq
, seq_len
);
1699 //recover key,key_len
1701 key_len
=ext
->key_len
;
1702 memcpy(key
, &ext
->key
[0], key_len
);
1705 memset(key_array
, 0, 64);
1707 memcpy(key_array
, key
, key_len
);
1708 if (key_len
== 32) {
1709 // notice ! the oder
1710 memcpy(&key_array
[16], &key
[24], 8);
1711 memcpy(&key_array
[24], &key
[16], 8);
1715 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1716 memcpy(param
->addr
, addr
, ETH_ALEN
);
1717 param
->u
.wpa_key
.alg_name
= (int)alg_name
;
1718 param
->u
.wpa_key
.set_tx
= set_tx
;
1719 param
->u
.wpa_key
.key_index
= key_idx
;
1720 param
->u
.wpa_key
.key_len
= key_len
;
1721 param
->u
.wpa_key
.key
= (u8
*)key_array
;
1722 param
->u
.wpa_key
.seq
= (u8
*)seq
;
1723 param
->u
.wpa_key
.seq_len
= seq_len
;
1725 //****set if current action is Network Manager count??
1726 //****this method is so foolish,but there is no other way???
1727 if(param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
1728 if(param
->u
.wpa_key
.key_index
==0) {
1729 pDevice
->bwextstep0
= TRUE
;
1731 if((pDevice
->bwextstep0
= TRUE
)&&(param
->u
.wpa_key
.key_index
==1)) {
1732 pDevice
->bwextstep0
= FALSE
;
1733 pDevice
->bwextstep1
= TRUE
;
1735 if((pDevice
->bwextstep1
= TRUE
)&&(param
->u
.wpa_key
.key_index
==2)) {
1736 pDevice
->bwextstep1
= FALSE
;
1737 pDevice
->bwextstep2
= TRUE
;
1739 if((pDevice
->bwextstep2
= TRUE
)&&(param
->u
.wpa_key
.key_index
==3)) {
1740 pDevice
->bwextstep2
= FALSE
;
1741 pDevice
->bwextstep3
= TRUE
;
1744 if(pDevice
->bwextstep3
== TRUE
) {
1745 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1746 pDevice
->bwextstep0
= FALSE
;
1747 pDevice
->bwextstep1
= FALSE
;
1748 pDevice
->bwextstep2
= FALSE
;
1749 pDevice
->bwextstep3
= FALSE
;
1750 pDevice
->bWPASuppWextEnabled
= TRUE
;
1751 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
1752 KeyvInitTable(pDevice
,&pDevice
->sKey
);
1756 spin_lock_irq(&pDevice
->lock
);
1757 ret
= wpa_set_keys(pDevice
, param
, TRUE
);
1758 spin_unlock_irq(&pDevice
->lock
);
1767 int iwctl_giwencodeext(struct net_device
*dev
,
1768 struct iw_request_info
*info
,
1769 struct iw_point
*wrq
,
1775 int iwctl_siwmlme(struct net_device
*dev
,
1776 struct iw_request_info
* info
,
1777 struct iw_point
*wrq
,
1780 PSDevice pDevice
= (PSDevice
)netdev_priv(dev
);
1781 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1782 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1785 if(memcmp(pMgmt
->abyCurrBSSID
, mlme
->addr
.sa_data
, ETH_ALEN
)){
1790 case IW_MLME_DEAUTH
:
1791 case IW_MLME_DISASSOC
:
1792 if(pDevice
->bLinkPass
== TRUE
){
1793 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1794 bScheduleCommand((void *) pDevice
,
1795 WLAN_CMD_DISASSOCIATE
,
1809 static const iw_handler iwctl_handler
[] =
1811 (iw_handler
) NULL
, /* SIOCSIWCOMMIT */
1812 (iw_handler
) NULL
, // SIOCGIWNAME
1813 (iw_handler
) NULL
, // SIOCSIWNWID
1814 (iw_handler
) NULL
, // SIOCGIWNWID
1815 (iw_handler
) NULL
, // SIOCSIWFREQ
1816 (iw_handler
) NULL
, // SIOCGIWFREQ
1817 (iw_handler
) NULL
, // SIOCSIWMODE
1818 (iw_handler
) NULL
, // SIOCGIWMODE
1819 (iw_handler
) NULL
, // SIOCSIWSENS
1820 (iw_handler
) NULL
, // SIOCGIWSENS
1821 (iw_handler
) NULL
, // SIOCSIWRANGE
1822 (iw_handler
) iwctl_giwrange
, // SIOCGIWRANGE
1823 (iw_handler
) NULL
, // SIOCSIWPRIV
1824 (iw_handler
) NULL
, // SIOCGIWPRIV
1825 (iw_handler
) NULL
, // SIOCSIWSTATS
1826 (iw_handler
) NULL
, // SIOCGIWSTATS
1827 (iw_handler
) NULL
, // SIOCSIWSPY
1828 (iw_handler
) NULL
, // SIOCGIWSPY
1829 (iw_handler
) NULL
, // -- hole --
1830 (iw_handler
) NULL
, // -- hole --
1831 (iw_handler
) NULL
, // SIOCSIWAP
1832 (iw_handler
) NULL
, // SIOCGIWAP
1833 (iw_handler
) NULL
, // -- hole -- 0x16
1834 (iw_handler
) NULL
, // SIOCGIWAPLIST
1835 (iw_handler
) iwctl_siwscan
, // SIOCSIWSCAN
1836 (iw_handler
) iwctl_giwscan
, // SIOCGIWSCAN
1837 (iw_handler
) NULL
, // SIOCSIWESSID
1838 (iw_handler
) NULL
, // SIOCGIWESSID
1839 (iw_handler
) NULL
, // SIOCSIWNICKN
1840 (iw_handler
) NULL
, // SIOCGIWNICKN
1841 (iw_handler
) NULL
, // -- hole --
1842 (iw_handler
) NULL
, // -- hole --
1843 (iw_handler
) NULL
, // SIOCSIWRATE 0x20
1844 (iw_handler
) NULL
, // SIOCGIWRATE
1845 (iw_handler
) NULL
, // SIOCSIWRTS
1846 (iw_handler
) NULL
, // SIOCGIWRTS
1847 (iw_handler
) NULL
, // SIOCSIWFRAG
1848 (iw_handler
) NULL
, // SIOCGIWFRAG
1849 (iw_handler
) NULL
, // SIOCSIWTXPOW
1850 (iw_handler
) NULL
, // SIOCGIWTXPOW
1851 (iw_handler
) NULL
, // SIOCSIWRETRY
1852 (iw_handler
) NULL
, // SIOCGIWRETRY
1853 (iw_handler
) NULL
, // SIOCSIWENCODE
1854 (iw_handler
) NULL
, // SIOCGIWENCODE
1855 (iw_handler
) NULL
, // SIOCSIWPOWER
1856 (iw_handler
) NULL
, // SIOCGIWPOWER
1857 (iw_handler
) NULL
, // -- hole --
1858 (iw_handler
) NULL
, // -- hole --
1859 (iw_handler
) NULL
, // SIOCSIWGENIE
1860 (iw_handler
) NULL
, // SIOCGIWGENIE
1861 (iw_handler
) NULL
, // SIOCSIWAUTH
1862 (iw_handler
) NULL
, // SIOCGIWAUTH
1863 (iw_handler
) NULL
, // SIOCSIWENCODEEXT
1864 (iw_handler
) NULL
, // SIOCGIWENCODEEXT
1865 (iw_handler
) NULL
, // SIOCSIWPMKSA
1866 (iw_handler
) NULL
, // -- hole --
1870 static const iw_handler iwctl_private_handler
[] =
1872 NULL
, // SIOCIWFIRSTPRIV
1876 struct iw_priv_args iwctl_private_args
[] = {
1878 IW_PRIV_TYPE_CHAR
| 1024, 0,
1884 const struct iw_handler_def iwctl_handler_def
=
1886 .get_wireless_stats
= &iwctl_get_wireless_stats
,
1887 .num_standard
= sizeof(iwctl_handler
)/sizeof(iw_handler
),
1889 .num_private_args
= 0,
1890 .standard
= (iw_handler
*) iwctl_handler
,
1892 .private_args
= NULL
,