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;
144 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
);
153 } else if (req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) { // passive scan
154 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
156 } else { // active scan
157 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
160 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
161 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
162 spin_unlock_irq(&pDevice
->lock
);
168 * Wireless Handler : get scan results
170 int iwctl_giwscan(struct net_device
*dev
, struct iw_request_info
*info
,
171 struct iw_point
*wrq
, char *extra
)
176 PSDevice pDevice
= netdev_priv(dev
);
177 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
179 PWLAN_IE_SSID pItemSSID
;
180 PWLAN_IE_SUPP_RATES pSuppRates
;
181 PWLAN_IE_SUPP_RATES pExtSuppRates
;
182 char *current_ev
= extra
;
183 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
184 char *current_val
= NULL
;
187 char buf
[MAX_WPA_IE_LEN
* 2 + 30];
189 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSCAN\n");
191 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
195 pBSS
= &(pMgmt
->sBSSList
[0]);
196 for (ii
= 0, jj
= 0; jj
< MAX_BSS_NUM
; jj
++) {
197 if (current_ev
>= end_buf
)
199 pBSS
= &(pMgmt
->sBSSList
[jj
]);
202 memset(&iwe
, 0, sizeof(iwe
));
204 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
205 memcpy(iwe
.u
.ap_addr
.sa_data
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
206 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
208 memset(&iwe
, 0, sizeof(iwe
));
209 iwe
.cmd
= SIOCGIWESSID
;
210 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
211 iwe
.u
.data
.length
= pItemSSID
->len
;
212 iwe
.u
.data
.flags
= 1;
213 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
215 memset(&iwe
, 0, sizeof(iwe
));
216 iwe
.cmd
= SIOCGIWMODE
;
217 if (WLAN_GET_CAP_INFO_ESS(pBSS
->wCapInfo
))
218 iwe
.u
.mode
= IW_MODE_INFRA
;
220 iwe
.u
.mode
= IW_MODE_ADHOC
;
221 iwe
.len
= IW_EV_UINT_LEN
;
222 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
224 pSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abySuppRates
;
225 pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abyExtSuppRates
;
226 memset(&iwe
, 0, sizeof(iwe
));
227 iwe
.cmd
= SIOCGIWFREQ
;
228 iwe
.u
.freq
.m
= pBSS
->uChannel
;
231 current_ev
= iwe_stream_add_event(info
, current_ev
,end_buf
, &iwe
, IW_EV_FREQ_LEN
);
233 int f
= (int)pBSS
->uChannel
- 1;
236 iwe
.u
.freq
.m
= frequency_list
[f
] * 100000;
239 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
241 memset(&iwe
, 0, sizeof(iwe
));
243 RFvRSSITodBm(pDevice
, (BYTE
)(pBSS
->uRSSI
), &ldBm
);
244 iwe
.u
.qual
.level
= ldBm
;
245 iwe
.u
.qual
.noise
= 0;
248 iwe
.u
.qual
.qual
= 100;
252 iwe
.u
.qual
.qual
= (40 - (-ldBm
- 50)) * 100 / 40;
253 iwe
.u
.qual
.updated
= 7;
255 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
257 memset(&iwe
, 0, sizeof(iwe
));
258 iwe
.cmd
= SIOCGIWENCODE
;
259 iwe
.u
.data
.length
= 0;
260 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS
->wCapInfo
))
261 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
263 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
264 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
266 memset(&iwe
, 0, sizeof(iwe
));
267 iwe
.cmd
= SIOCGIWRATE
;
268 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
269 current_val
= current_ev
+ IW_EV_LCP_LEN
;
271 for (kk
= 0; kk
< 12; kk
++) {
272 if (pSuppRates
->abyRates
[kk
] == 0)
274 // Bit rate given in 500 kb/s units (+ 0x80)
275 iwe
.u
.bitrate
.value
= ((pSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
276 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
278 for (kk
= 0; kk
< 8; kk
++) {
279 if (pExtSuppRates
->abyRates
[kk
] == 0)
281 // Bit rate given in 500 kb/s units (+ 0x80)
282 iwe
.u
.bitrate
.value
= ((pExtSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
283 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
286 if ((current_val
- current_ev
) > IW_EV_LCP_LEN
)
287 current_ev
= current_val
;
289 memset(&iwe
, 0, sizeof(iwe
));
290 iwe
.cmd
= IWEVCUSTOM
;
291 sprintf(buf
, "bcn_int=%d", pBSS
->wBeaconInterval
);
292 iwe
.u
.data
.length
= strlen(buf
);
293 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, buf
);
295 if ((pBSS
->wWPALen
> 0) && (pBSS
->wWPALen
<= MAX_WPA_IE_LEN
)) {
296 memset(&iwe
, 0, sizeof(iwe
));
298 iwe
.u
.data
.length
= pBSS
->wWPALen
;
299 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byWPAIE
);
302 if ((pBSS
->wRSNLen
> 0) && (pBSS
->wRSNLen
<= MAX_WPA_IE_LEN
)) {
303 memset(&iwe
, 0, sizeof(iwe
));
305 iwe
.u
.data
.length
= pBSS
->wRSNLen
;
306 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byRSNIE
);
310 wrq
->length
= current_ev
- extra
;
315 * Wireless Handler: set frequence or channel
317 int iwctl_siwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
318 struct iw_freq
*wrq
, char *extra
)
320 PSDevice pDevice
= netdev_priv(dev
);
323 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFREQ \n");
325 // If setting by frequency, convert to a channel
326 if ((wrq
->e
== 1) && (wrq
->m
>= (int)2.412e8
) &&
327 (wrq
->m
<= (int)2.487e8
)) {
328 int f
= wrq
->m
/ 100000;
330 while ((c
< 14) && (f
!= frequency_list
[c
]))
335 // Setting by channel number
336 if ((wrq
->m
> 14) || (wrq
->e
> 0)) {
339 int channel
= wrq
->m
;
340 if ((channel
< 1) || (channel
> 14)) {
341 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: New channel value of %d is invalid!\n", dev
->name
, wrq
->m
);
344 // Yes ! We can set it !!!
345 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set to channel = %d\n", channel
);
346 pDevice
->uChannel
= channel
;
353 * Wireless Handler: get frequence or channel
355 int iwctl_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
356 struct iw_freq
*wrq
, char *extra
)
358 PSDevice pDevice
= netdev_priv(dev
);
359 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
361 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFREQ \n");
363 #ifdef WEXT_USECHANNELS
364 wrq
->m
= (int)pMgmt
->uCurrChannel
;
368 int f
= (int)pMgmt
->uCurrChannel
- 1;
371 wrq
->m
= frequency_list
[f
] * 100000;
379 * Wireless Handler: set operation mode
381 int iwctl_siwmode(struct net_device
*dev
, struct iw_request_info
*info
,
382 __u32
*wmode
, char *extra
)
384 PSDevice pDevice
= netdev_priv(dev
);
385 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
388 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMODE \n");
390 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
&& pDevice
->bEnableHostapd
) {
391 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Can't set operation mode, hostapd is running \n");
397 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_IBSS_STA
) {
398 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
399 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
400 pDevice
->bCommit
= TRUE
;
402 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to ad-hoc \n");
406 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_ESS_STA
) {
407 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
408 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
409 pDevice
->bCommit
= TRUE
;
411 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to infrastructure \n");
415 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
419 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_AP
) {
420 pMgmt
->eConfigMode
= WMAC_CONFIG_AP
;
421 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
422 pDevice
->bCommit
= TRUE
;
424 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to Access Point \n");
428 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
439 * Wireless Handler: get operation mode
441 void iwctl_giwmode(struct net_device
*dev
, struct iw_request_info
*info
,
442 __u32
*wmode
, char *extra
)
444 PSDevice pDevice
= netdev_priv(dev
);
445 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
447 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWMODE \n");
448 // If not managed, assume it's ad-hoc
449 switch (pMgmt
->eConfigMode
) {
450 case WMAC_CONFIG_ESS_STA
:
451 *wmode
= IW_MODE_INFRA
;
453 case WMAC_CONFIG_IBSS_STA
:
454 *wmode
= IW_MODE_ADHOC
;
456 case WMAC_CONFIG_AUTO
:
457 *wmode
= IW_MODE_INFRA
;
460 *wmode
= IW_MODE_MASTER
;
463 *wmode
= IW_MODE_ADHOC
;
468 * Wireless Handler: get capability range
470 void iwctl_giwrange(struct net_device
*dev
, struct iw_request_info
*info
,
471 struct iw_point
*wrq
, char *extra
)
473 struct iw_range
*range
= (struct iw_range
*)extra
;
476 BYTE abySupportedRates
[13] = {
477 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
481 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRANGE\n");
483 wrq
->length
= sizeof(struct iw_range
);
484 memset(range
, 0, sizeof(struct iw_range
));
485 range
->min_nwid
= 0x0000;
486 range
->max_nwid
= 0x0000;
487 range
->num_channels
= 14;
488 // Should be based on cap_rid.country to give only
489 // what the current card support
491 for (i
= 0; i
< 14; i
++) {
492 range
->freq
[k
].i
= i
+ 1; // List index
493 range
->freq
[k
].m
= frequency_list
[i
] * 100000;
494 range
->freq
[k
++].e
= 1; // Values in table in MHz -> * 10^5 * 10
496 range
->num_frequency
= k
;
497 // Hum... Should put the right values there
498 range
->max_qual
.qual
= 100;
499 range
->max_qual
.level
= 0;
500 range
->max_qual
.noise
= 0;
501 range
->sensitivity
= 255;
503 for (i
= 0; i
< 13; i
++) {
504 range
->bitrate
[i
] = abySupportedRates
[i
] * 500000;
505 if (range
->bitrate
[i
] == 0)
508 range
->num_bitrates
= i
;
510 // Set an indication of the max TCP throughput
511 // in bit/s that we can expect using this interface.
512 // May be use for QoS stuff... Jean II
514 range
->throughput
= 5 * 1000 * 1000;
516 range
->throughput
= 1.5 * 1000 * 1000;
519 range
->max_rts
= 2312;
520 range
->min_frag
= 256;
521 range
->max_frag
= 2312;
523 // the encoding capabilities
524 range
->num_encoding_sizes
= 3;
526 range
->encoding_size
[0] = 5;
528 range
->encoding_size
[1] = 13;
529 // 256 bits for WPA-PSK
530 range
->encoding_size
[2] = 32;
531 // 4 keys are allowed
532 range
->max_encoding_tokens
= 4;
534 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
535 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
538 range
->max_pmp
= 1000000; // 1 secs
540 range
->max_pmt
= 1000000; // 1 secs
541 range
->pmp_flags
= IW_POWER_PERIOD
;
542 range
->pmt_flags
= IW_POWER_TIMEOUT
;
543 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_ALL_R
;
545 // Transmit Power - values are in mW
546 range
->txpower
[0] = 100;
547 range
->num_txpower
= 1;
548 range
->txpower_capa
= IW_TXPOW_MWATT
;
549 range
->we_version_source
= SUPPORTED_WIRELESS_EXT
;
550 range
->we_version_compiled
= WIRELESS_EXT
;
551 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
552 range
->retry_flags
= IW_RETRY_LIMIT
;
553 range
->r_time_flags
= IW_RETRY_LIFETIME
;
554 range
->min_retry
= 1;
555 range
->max_retry
= 65535;
556 range
->min_r_time
= 1024;
557 range
->max_r_time
= 65535 * 1024;
558 // Experimental measurements - boundary 11/5.5 Mb/s
559 // Note : with or without the (local->rssi), results
560 // are somewhat different. - Jean II
561 range
->avg_qual
.qual
= 6;
562 range
->avg_qual
.level
= 176; // -80 dBm
563 range
->avg_qual
.noise
= 0;
568 * Wireless Handler : set ap mac address
570 int iwctl_siwap(struct net_device
*dev
, struct iw_request_info
*info
,
571 struct sockaddr
*wrq
, char *extra
)
573 PSDevice pDevice
= netdev_priv(dev
);
574 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
576 BYTE ZeroBSSID
[WLAN_BSSID_LEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
578 PRINT_K(" SIOCSIWAP \n");
580 if (wrq
->sa_family
!= ARPHRD_ETHER
) {
583 memcpy(pMgmt
->abyDesireBSSID
, wrq
->sa_data
, 6);
585 if ((is_broadcast_ether_addr(pMgmt
->abyDesireBSSID
)) ||
586 (memcmp(pMgmt
->abyDesireBSSID
, ZeroBSSID
, 6) == 0)) {
587 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
590 // mike add: if desired AP is hidden ssid(there are
591 // two same BSSID in list), then ignore,because you
592 // don't known which one to be connect with??
595 unsigned uSameBssidNum
= 0;
596 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
597 if (pMgmt
->sBSSList
[ii
].bActive
&&
598 !compare_ether_addr(pMgmt
->sBSSList
[ii
].abyBSSID
,
599 pMgmt
->abyDesireBSSID
)) {
603 if (uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
604 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
609 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
610 pDevice
->bCommit
= TRUE
;
616 * Wireless Handler: get ap mac address
618 int iwctl_giwap(struct net_device
*dev
, struct iw_request_info
*info
,
619 struct sockaddr
*wrq
, char *extra
)
621 PSDevice pDevice
= netdev_priv(dev
);
622 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
624 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAP \n");
626 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
628 if ((pDevice
->bLinkPass
== FALSE
) && (pMgmt
->eCurrMode
!= WMAC_MODE_ESS_AP
))
629 memset(wrq
->sa_data
, 0, 6);
631 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)
632 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
634 wrq
->sa_family
= ARPHRD_ETHER
;
639 * Wireless Handler: get ap list
641 int iwctl_giwaplist(struct net_device
*dev
, struct iw_request_info
*info
,
642 struct iw_point
*wrq
, char *extra
)
647 struct sockaddr sock
[IW_MAX_AP
];
648 struct iw_quality qual
[IW_MAX_AP
];
649 PSDevice pDevice
= netdev_priv(dev
);
650 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
652 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAPLIST \n");
653 // Only super-user can see AP list
655 if (!capable(CAP_NET_ADMIN
)) {
661 PKnownBSS pBSS
= &(pMgmt
->sBSSList
[0]);
663 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
664 pBSS
= &(pMgmt
->sBSSList
[ii
]);
669 memcpy(sock
[jj
].sa_data
, pBSS
->abyBSSID
, 6);
670 sock
[jj
].sa_family
= ARPHRD_ETHER
;
671 qual
[jj
].level
= pBSS
->uRSSI
;
672 qual
[jj
].qual
= qual
[jj
].noise
= 0;
673 qual
[jj
].updated
= 2;
677 wrq
->flags
= 1; // Should be defined
679 memcpy(extra
, sock
, sizeof(struct sockaddr
) * jj
);
680 memcpy(extra
+ sizeof(struct sockaddr
) * jj
, qual
, sizeof(struct iw_quality
) * jj
);
686 * Wireless Handler: set essid
688 int iwctl_siwessid(struct net_device
*dev
, struct iw_request_info
*info
,
689 struct iw_point
*wrq
, char *extra
)
691 PSDevice pDevice
= netdev_priv(dev
);
692 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
693 PWLAN_IE_SSID pItemSSID
;
695 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
698 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWESSID :\n");
700 pDevice
->fWPA_Authened
= FALSE
;
701 // Check if we asked for `any'
702 if (wrq
->flags
== 0) {
703 // Just send an empty SSID list
704 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
705 memset(pMgmt
->abyDesireBSSID
, 0xFF,6);
706 PRINT_K("set essid to 'any' \n");
707 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
708 // Unknown desired AP, so here need not associate??
713 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
714 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
715 pItemSSID
->byElementID
= WLAN_EID_SSID
;
717 memcpy(pItemSSID
->abySSID
, extra
, wrq
->length
);
718 if (pItemSSID
->abySSID
[wrq
->length
- 1] == '\0') {
720 pItemSSID
->len
= wrq
->length
- 1;
722 pItemSSID
->len
= wrq
->length
;
724 PRINT_K("set essid to %s \n", pItemSSID
->abySSID
);
726 // mike: need clear desiredBSSID
727 if (pItemSSID
->len
==0) {
728 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
732 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
733 // Wext wil order another command of siwap to link
734 // with desired AP, so here need not associate??
735 if (pDevice
->bWPASuppWextEnabled
== TRUE
) {
736 /*******search if in hidden ssid mode ****/
737 PKnownBSS pCurr
= NULL
;
738 BYTE abyTmpDesireSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
740 unsigned uSameBssidNum
= 0;
742 memcpy(abyTmpDesireSSID
, pMgmt
->abyDesireSSID
, sizeof(abyTmpDesireSSID
));
743 pCurr
= BSSpSearchBSSList(pDevice
, NULL
,
745 pDevice
->eConfigPHYMode
);
748 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
749 vResetCommandTimer((void *)pDevice
);
750 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
751 bScheduleCommand((void *)pDevice
,
753 pMgmt
->abyDesireSSID
);
754 bScheduleCommand((void *)pDevice
,
756 pMgmt
->abyDesireSSID
);
757 } else { // mike: to find out if that desired SSID is a
758 // hidden-ssid AP, by means of judging if there
759 // are two same BSSID exist in list ?
760 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
761 if (pMgmt
->sBSSList
[ii
].bActive
&&
762 !compare_ether_addr(pMgmt
->sBSSList
[ii
].abyBSSID
,
767 if (uSameBssidNum
>= 2) { // hit: desired AP is in hidden ssid mode!!!
768 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
769 vResetCommandTimer((void *)pDevice
);
770 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
; // this scan type, you'll submit scan result!
771 bScheduleCommand((void *)pDevice
,
773 pMgmt
->abyDesireSSID
);
774 bScheduleCommand((void *)pDevice
,
776 pMgmt
->abyDesireSSID
);
783 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set essid = %s \n", pItemSSID
->abySSID
);
786 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
787 pDevice
->bCommit
= TRUE
;
793 * Wireless Handler: get essid
795 void iwctl_giwessid(struct net_device
*dev
, struct iw_request_info
*info
,
796 struct iw_point
*wrq
, char *extra
)
798 PSDevice pDevice
= netdev_priv(dev
);
799 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
800 PWLAN_IE_SSID pItemSSID
;
802 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWESSID \n");
804 // Note: if wrq->u.data.flags != 0, we should get the relevant
805 // SSID from the SSID list...
807 // Get the current SSID
808 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
809 memcpy(extra
, pItemSSID
->abySSID
, pItemSSID
->len
);
810 extra
[pItemSSID
->len
] = '\0';
812 wrq
->length
= pItemSSID
->len
;
813 wrq
->flags
= 1; // active
817 * Wireless Handler: set data rate
819 int iwctl_siwrate(struct net_device
*dev
, struct iw_request_info
*info
,
820 struct iw_param
*wrq
, char *extra
)
822 PSDevice pDevice
= netdev_priv(dev
);
826 BYTE abySupportedRates
[13] = {
827 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
831 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRATE \n");
832 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
837 // First: get a valid bit rate value
839 // Which type of value
840 if ((wrq
->value
< 13) && (wrq
->value
>= 0)) {
841 // Setting by rate index
842 // Find value in the magic rate table
845 // Setting by frequency value
846 u8 normvalue
= (u8
)(wrq
->value
/500000);
848 // Check if rate is valid
849 for (i
= 0; i
< 13; i
++) {
850 if (normvalue
== abySupportedRates
[i
]) {
856 // -1 designed the max rate (mostly auto mode)
857 if (wrq
->value
== -1) {
858 // Get the highest available rate
859 for (i
= 0; i
< 13; i
++) {
860 if (abySupportedRates
[i
] == 0)
867 // Check that it is valid
868 // brate is index of abySupportedRates[]
874 // Now, check if we want a fixed or auto value
875 if (wrq
->fixed
!= 0) {
878 pDevice
->bFixRate
= TRUE
;
879 if ((pDevice
->byBBType
== BB_TYPE_11B
) && (brate
> 3)) {
880 pDevice
->uConnectionRate
= 3;
882 pDevice
->uConnectionRate
= brate
;
883 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fixed to Rate %d \n", pDevice
->uConnectionRate
);
886 pDevice
->bFixRate
= FALSE
;
887 pDevice
->uConnectionRate
= 13;
894 * Wireless Handler: get data rate
896 void iwctl_giwrate(struct net_device
*dev
, struct iw_request_info
*info
,
897 struct iw_param
*wrq
, char *extra
)
899 PSDevice pDevice
= netdev_priv(dev
);
900 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
902 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRATE \n");
904 BYTE abySupportedRates
[13] = {
905 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
906 0x48, 0x60, 0x6C, 0x90
910 if (pDevice
->uConnectionRate
< 13) {
911 brate
= abySupportedRates
[pDevice
->uConnectionRate
];
913 if (pDevice
->byBBType
== BB_TYPE_11B
)
915 if (pDevice
->byBBType
== BB_TYPE_11G
)
917 if (pDevice
->byBBType
== BB_TYPE_11A
)
920 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
921 if (pDevice
->byBBType
== BB_TYPE_11B
)
923 if (pDevice
->byBBType
== BB_TYPE_11G
)
925 if (pDevice
->byBBType
== BB_TYPE_11A
)
928 if (pDevice
->uConnectionRate
== 13)
929 brate
= abySupportedRates
[pDevice
->wCurrentRate
];
930 wrq
->value
= brate
* 500000;
931 // If more than one rate, set auto
932 if (pDevice
->bFixRate
== TRUE
)
938 * Wireless Handler: set rts threshold
940 int iwctl_siwrts(struct net_device
*dev
, struct iw_param
*wrq
)
942 PSDevice pDevice
= netdev_priv(dev
);
944 if ((wrq
->value
< 0 || wrq
->value
> 2312) && !wrq
->disabled
)
947 else if (wrq
->disabled
)
948 pDevice
->wRTSThreshold
= 2312;
950 pDevice
->wRTSThreshold
= wrq
->value
;
956 * Wireless Handler: get rts
958 int iwctl_giwrts(struct net_device
*dev
, struct iw_request_info
*info
,
959 struct iw_param
*wrq
, char *extra
)
961 PSDevice pDevice
= netdev_priv(dev
);
963 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRTS \n");
964 wrq
->value
= pDevice
->wRTSThreshold
;
965 wrq
->disabled
= (wrq
->value
>= 2312);
971 * Wireless Handler: set fragment threshold
973 int iwctl_siwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
974 struct iw_param
*wrq
, char *extra
)
976 PSDevice pDevice
= netdev_priv(dev
);
978 int fthr
= wrq
->value
;
980 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFRAG \n");
984 if ((fthr
< 256) || (fthr
> 2312)) {
987 fthr
&= ~0x1; // Get an even value
988 pDevice
->wFragmentationThreshold
= (u16
)fthr
;
994 * Wireless Handler: get fragment threshold
996 int iwctl_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
997 struct iw_param
*wrq
, char *extra
)
999 PSDevice pDevice
= netdev_priv(dev
);
1001 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFRAG \n");
1002 wrq
->value
= pDevice
->wFragmentationThreshold
;
1003 wrq
->disabled
= (wrq
->value
>= 2312);
1009 * Wireless Handler: set retry threshold
1011 int iwctl_siwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1012 struct iw_param
*wrq
, char *extra
)
1014 PSDevice pDevice
= netdev_priv(dev
);
1017 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRETRY \n");
1019 if (wrq
->disabled
) {
1024 if (wrq
->flags
& IW_RETRY_LIMIT
) {
1025 if (wrq
->flags
& IW_RETRY_MAX
) {
1026 pDevice
->byLongRetryLimit
= wrq
->value
;
1027 } else if (wrq
->flags
& IW_RETRY_MIN
) {
1028 pDevice
->byShortRetryLimit
= wrq
->value
;
1030 // No modifier : set both
1031 pDevice
->byShortRetryLimit
= wrq
->value
;
1032 pDevice
->byLongRetryLimit
= wrq
->value
;
1035 if (wrq
->flags
& IW_RETRY_LIFETIME
)
1036 pDevice
->wMaxTransmitMSDULifetime
= wrq
->value
;
1041 * Wireless Handler: get retry threshold
1043 int iwctl_giwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1044 struct iw_param
*wrq
, char *extra
)
1046 PSDevice pDevice
= netdev_priv(dev
);
1047 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRETRY \n");
1048 wrq
->disabled
= 0; // Can't be disabled
1050 // Note: by default, display the min retry number
1051 if ((wrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1052 wrq
->flags
= IW_RETRY_LIFETIME
;
1053 wrq
->value
= (int)pDevice
->wMaxTransmitMSDULifetime
; // ms
1054 } else if ((wrq
->flags
& IW_RETRY_MAX
)) {
1055 wrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1056 wrq
->value
= (int)pDevice
->byLongRetryLimit
;
1058 wrq
->flags
= IW_RETRY_LIMIT
;
1059 wrq
->value
= (int)pDevice
->byShortRetryLimit
;
1060 if ((int)pDevice
->byShortRetryLimit
!= (int)pDevice
->byLongRetryLimit
)
1061 wrq
->flags
|= IW_RETRY_MIN
;
1067 * Wireless Handler: set encode mode
1069 int iwctl_siwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1070 struct iw_point
*wrq
, char *extra
)
1072 PSDevice pDevice
= netdev_priv(dev
);
1073 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1074 DWORD dwKeyIndex
= (DWORD
)(wrq
->flags
& IW_ENCODE_INDEX
);
1078 int index
= (wrq
->flags
& IW_ENCODE_INDEX
);
1080 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODE \n");
1082 // Check the size of the key
1083 if (wrq
->length
> WLAN_WEP232_KEYLEN
) {
1088 if (dwKeyIndex
> WLAN_WEP_NKEYS
) {
1096 // Send the key to the card
1097 if (wrq
->length
> 0) {
1098 if (wrq
->length
== WLAN_WEP232_KEYLEN
) {
1099 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 232 bit wep key\n");
1100 } else if (wrq
->length
== WLAN_WEP104_KEYLEN
) {
1101 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 104 bit wep key\n");
1102 } else if (wrq
->length
== WLAN_WEP40_KEYLEN
) {
1103 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 40 bit wep key, index= %d\n", (int)dwKeyIndex
);
1105 memset(pDevice
->abyKey
, 0, WLAN_WEP232_KEYLEN
);
1106 memcpy(pDevice
->abyKey
, extra
, wrq
->length
);
1108 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"abyKey: ");
1109 for (ii
= 0; ii
< wrq
->length
; ii
++)
1110 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pDevice
->abyKey
[ii
]);
1112 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1113 spin_lock_irq(&pDevice
->lock
);
1114 KeybSetDefaultKey(pDevice
,
1116 dwKeyIndex
| (1 << 31),
1120 spin_unlock_irq(&pDevice
->lock
);
1122 pDevice
->byKeyIndex
= (BYTE
)dwKeyIndex
;
1123 pDevice
->uKeyLength
= wrq
->length
;
1124 pDevice
->bTransmitKey
= TRUE
;
1125 pDevice
->bEncryptionEnable
= TRUE
;
1126 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1128 // Do we want to just set the transmit key index?
1130 pDevice
->byKeyIndex
= index
;
1131 } else if (!(wrq
->flags
& IW_ENCODE_MODE
)) {
1137 if (wrq
->flags
& IW_ENCODE_DISABLED
) {
1138 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disable WEP function\n");
1139 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1140 pDevice
->bEncryptionEnable
= FALSE
;
1141 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1142 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1143 spin_lock_irq(&pDevice
->lock
);
1144 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++)
1145 MACvDisableKeyEntry(pDevice
, uu
);
1146 spin_unlock_irq(&pDevice
->lock
);
1149 if (wrq
->flags
& IW_ENCODE_RESTRICTED
) {
1150 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & ShareKey System\n");
1151 pMgmt
->bShareKeyAlgorithm
= TRUE
;
1153 if (wrq
->flags
& IW_ENCODE_OPEN
) {
1154 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & Open System\n");
1155 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1158 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1159 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1164 int iwctl_giwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1165 struct iw_point
*wrq
, char *extra
)
1167 PSDevice pDevice
= netdev_priv(dev
);
1168 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1169 char abyKey
[WLAN_WEP232_KEYLEN
];
1171 unsigned index
= (unsigned)(wrq
->flags
& IW_ENCODE_INDEX
);
1172 PSKeyItem pKey
= NULL
;
1174 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODE\n");
1176 if (index
> WLAN_WEP_NKEYS
)
1178 if (index
< 1) { // get default key
1179 if (pDevice
->byKeyIndex
< WLAN_WEP_NKEYS
)
1180 index
= pDevice
->byKeyIndex
;
1187 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1188 // Check encryption mode
1189 wrq
->flags
= IW_ENCODE_NOKEY
;
1190 // Is WEP enabled ???
1191 if (pDevice
->bEncryptionEnable
)
1192 wrq
->flags
|= IW_ENCODE_ENABLED
;
1194 wrq
->flags
|= IW_ENCODE_DISABLED
;
1196 if (pMgmt
->bShareKeyAlgorithm
)
1197 wrq
->flags
|= IW_ENCODE_RESTRICTED
;
1199 wrq
->flags
|= IW_ENCODE_OPEN
;
1202 if ((index
== 0) && (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
||
1203 pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)) { // get wpa pairwise key
1204 if (KeybGetKey(&(pDevice
->sKey
), pMgmt
->abyCurrBSSID
, 0xffffffff, &pKey
)) {
1205 wrq
->length
= pKey
->uKeyLength
;
1206 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1207 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1209 } else if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, (BYTE
)index
, &pKey
)) {
1210 wrq
->length
= pKey
->uKeyLength
;
1211 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1212 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1215 wrq
->flags
|= index
+ 1;
1220 * Wireless Handler: set power mode
1222 int iwctl_siwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1223 struct iw_param
*wrq
, char *extra
)
1225 PSDevice pDevice
= netdev_priv(dev
);
1226 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1229 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER \n");
1231 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
1236 if (wrq
->disabled
) {
1237 pDevice
->ePSMode
= WMAC_POWER_CAM
;
1238 PSvDisablePowerSaving(pDevice
);
1241 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1242 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1243 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1245 } else if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_PERIOD
) {
1246 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1247 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1249 switch (wrq
->flags
& IW_POWER_MODE
) {
1250 case IW_POWER_UNICAST_R
:
1251 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_UNICAST_R \n");
1254 case IW_POWER_ALL_R
:
1255 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ALL_R \n");
1258 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ON \n");
1268 * Wireless Handler: get power mode
1270 int iwctl_giwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1271 struct iw_param
*wrq
, char *extra
)
1273 PSDevice pDevice
= netdev_priv(dev
);
1274 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1275 int mode
= pDevice
->ePSMode
;
1277 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPOWER \n");
1279 if ((wrq
->disabled
= (mode
== WMAC_POWER_CAM
)))
1282 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1283 wrq
->value
= (int)((pMgmt
->wListenInterval
* pMgmt
->wCurrBeaconPeriod
) << 10);
1284 wrq
->flags
= IW_POWER_TIMEOUT
;
1286 wrq
->value
= (int)((pMgmt
->wListenInterval
* pMgmt
->wCurrBeaconPeriod
) << 10);
1287 wrq
->flags
= IW_POWER_PERIOD
;
1289 wrq
->flags
|= IW_POWER_ALL_R
;
1294 * Wireless Handler: get Sensitivity
1296 int iwctl_giwsens(struct net_device
*dev
, struct iw_request_info
*info
,
1297 struct iw_param
*wrq
, char *extra
)
1299 PSDevice pDevice
= netdev_priv(dev
);
1302 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSENS \n");
1303 if (pDevice
->bLinkPass
== TRUE
) {
1304 RFvRSSITodBm(pDevice
, (BYTE
)(pDevice
->uCurrRSSI
), &ldBm
);
1309 wrq
->disabled
= (wrq
->value
== 0);
1314 #ifdef WPA_SUPPLICANT_DRIVER_WEXT_SUPPORT
1316 int iwctl_siwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1317 struct iw_param
*wrq
, char *extra
)
1319 PSDevice pDevice
= netdev_priv(dev
);
1320 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1322 static int wpa_version
= 0; // must be static to save the last value, einsn liu
1323 static int pairwise
= 0;
1325 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH \n");
1326 switch (wrq
->flags
& IW_AUTH_INDEX
) {
1327 case IW_AUTH_WPA_VERSION
:
1328 wpa_version
= wrq
->value
;
1329 if (wrq
->value
== IW_AUTH_WPA_VERSION_DISABLED
) {
1330 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1331 } else if (wrq
->value
== IW_AUTH_WPA_VERSION_WPA
) {
1332 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1334 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1337 case IW_AUTH_CIPHER_PAIRWISE
:
1338 pairwise
= wrq
->value
;
1339 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise
);
1340 if (pairwise
== IW_AUTH_CIPHER_CCMP
){
1341 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1342 } else if (pairwise
== IW_AUTH_CIPHER_TKIP
) {
1343 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1344 } else if (pairwise
== IW_AUTH_CIPHER_WEP40
||
1345 pairwise
== IW_AUTH_CIPHER_WEP104
) {
1346 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1347 } else if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1348 // do nothing, einsn liu
1350 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1353 case IW_AUTH_CIPHER_GROUP
:
1354 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq
->value
);
1355 if (wpa_version
== IW_AUTH_WPA_VERSION_DISABLED
)
1357 if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1358 if (wrq
->value
== IW_AUTH_CIPHER_CCMP
)
1359 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1361 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1364 case IW_AUTH_KEY_MGMT
:
1365 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version
,wrq
->value
);
1366 if (wpa_version
== IW_AUTH_WPA_VERSION_WPA2
){
1367 if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1368 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
1369 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
1370 } else if (wpa_version
== IW_AUTH_WPA_VERSION_WPA
) {
1371 if (wrq
->value
== 0){
1372 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
1373 } else if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1374 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
1376 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
1379 case IW_AUTH_TKIP_COUNTERMEASURES
:
1381 case IW_AUTH_DROP_UNENCRYPTED
:
1383 case IW_AUTH_80211_AUTH_ALG
:
1384 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq
->value
);
1385 if (wrq
->value
== IW_AUTH_ALG_OPEN_SYSTEM
)
1386 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1387 else if (wrq
->value
== IW_AUTH_ALG_SHARED_KEY
)
1388 pMgmt
->bShareKeyAlgorithm
= TRUE
;
1390 case IW_AUTH_WPA_ENABLED
:
1392 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1394 case IW_AUTH_ROAMING_CONTROL
:
1397 case IW_AUTH_PRIVACY_INVOKED
:
1398 pDevice
->bEncryptionEnable
= !!wrq
->value
;
1399 if (pDevice
->bEncryptionEnable
== FALSE
) {
1402 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1403 pMgmt
->bShareKeyAlgorithm
= FALSE
;
1404 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
1405 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1415 int iwctl_giwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1416 struct iw_param
*wrq
, char *extra
)
1421 int iwctl_siwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1422 struct iw_point
*wrq
, char *extra
)
1424 PSDevice pDevice
= netdev_priv(dev
);
1425 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1429 if ((wrq
->length
< 2) || (extra
[1] + 2 != wrq
->length
)) {
1433 if (wrq
->length
> MAX_WPA_IE_LEN
){
1437 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1438 if (copy_from_user(pMgmt
->abyWPAIE
, extra
, wrq
->length
)){
1442 pMgmt
->wWPAIELen
= wrq
->length
;
1444 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1445 pMgmt
->wWPAIELen
= 0;
1448 out
: // not completely ...not necessary in wpa_supplicant 0.5.8
1452 int iwctl_giwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1453 struct iw_point
*wrq
, char *extra
)
1455 PSDevice pDevice
= netdev_priv(dev
);
1456 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1458 int space
= wrq
->length
;
1461 if (pMgmt
->wWPAIELen
> 0) {
1462 wrq
->length
= pMgmt
->wWPAIELen
;
1463 if (pMgmt
->wWPAIELen
<= space
) {
1464 if (copy_to_user(extra
, pMgmt
->abyWPAIE
, pMgmt
->wWPAIELen
)) {
1474 int iwctl_siwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1475 struct iw_point
*wrq
, char *extra
)
1477 PSDevice pDevice
= netdev_priv(dev
);
1478 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1479 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1480 struct viawget_wpa_param
*param
=NULL
;
1486 u8 seq
[IW_ENCODE_SEQ_MAX_SIZE
];
1495 PRINT_K("SIOCSIWENCODEEXT...... \n");
1497 blen
= sizeof(*param
);
1498 buf
= kmalloc((int)blen
, (int)GFP_KERNEL
);
1501 memset(buf
, 0, blen
);
1502 param
= (struct viawget_wpa_param
*)buf
;
1506 case IW_ENCODE_ALG_NONE
:
1507 alg_name
= WPA_ALG_NONE
;
1509 case IW_ENCODE_ALG_WEP
:
1510 alg_name
= WPA_ALG_WEP
;
1512 case IW_ENCODE_ALG_TKIP
:
1513 alg_name
= WPA_ALG_TKIP
;
1515 case IW_ENCODE_ALG_CCMP
:
1516 alg_name
= WPA_ALG_CCMP
;
1519 PRINT_K("Unknown alg = %d\n",ext
->alg
);
1524 memcpy(addr
, ext
->addr
.sa_data
, ETH_ALEN
);
1526 key_idx
= (wrq
->flags
&IW_ENCODE_INDEX
) - 1;
1528 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1530 // recover seq,seq_len
1531 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1532 seq_len
=IW_ENCODE_SEQ_MAX_SIZE
;
1533 memcpy(seq
, ext
->rx_seq
, seq_len
);
1535 // recover key,key_len
1537 key_len
= ext
->key_len
;
1538 memcpy(key
, &ext
->key
[0], key_len
);
1540 memset(key_array
, 0, 64);
1542 memcpy(key_array
, key
, key_len
);
1543 if (key_len
== 32) {
1544 // notice ! the oder
1545 memcpy(&key_array
[16], &key
[24], 8);
1546 memcpy(&key_array
[24], &key
[16], 8);
1550 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1551 memcpy(param
->addr
, addr
, ETH_ALEN
);
1552 param
->u
.wpa_key
.alg_name
= (int)alg_name
;
1553 param
->u
.wpa_key
.set_tx
= set_tx
;
1554 param
->u
.wpa_key
.key_index
= key_idx
;
1555 param
->u
.wpa_key
.key_len
= key_len
;
1556 param
->u
.wpa_key
.key
= (u8
*)key_array
;
1557 param
->u
.wpa_key
.seq
= (u8
*)seq
;
1558 param
->u
.wpa_key
.seq_len
= seq_len
;
1560 /****set if current action is Network Manager count?? */
1561 /****this method is so foolish,but there is no other way??? */
1562 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
1563 if (param
->u
.wpa_key
.key_index
==0) {
1564 pDevice
->bwextstep0
= TRUE
;
1566 if ((pDevice
->bwextstep0
== TRUE
) && (param
->u
.wpa_key
.key_index
== 1)) {
1567 pDevice
->bwextstep0
= FALSE
;
1568 pDevice
->bwextstep1
= TRUE
;
1570 if ((pDevice
->bwextstep1
== TRUE
) && (param
->u
.wpa_key
.key_index
== 2)) {
1571 pDevice
->bwextstep1
= FALSE
;
1572 pDevice
->bwextstep2
= TRUE
;
1574 if ((pDevice
->bwextstep2
== TRUE
) && (param
->u
.wpa_key
.key_index
== 3)) {
1575 pDevice
->bwextstep2
= FALSE
;
1576 pDevice
->bwextstep3
= TRUE
;
1579 if (pDevice
->bwextstep3
== TRUE
) {
1580 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1581 pDevice
->bwextstep0
= FALSE
;
1582 pDevice
->bwextstep1
= FALSE
;
1583 pDevice
->bwextstep2
= FALSE
;
1584 pDevice
->bwextstep3
= FALSE
;
1585 pDevice
->bWPASuppWextEnabled
= TRUE
;
1586 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1587 KeyvInitTable(pDevice
, &pDevice
->sKey
);
1590 spin_lock_irq(&pDevice
->lock
);
1591 ret
= wpa_set_keys(pDevice
, param
, TRUE
);
1592 spin_unlock_irq(&pDevice
->lock
);
1599 int iwctl_giwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1600 struct iw_point
*wrq
, char *extra
)
1605 int iwctl_siwmlme(struct net_device
*dev
, struct iw_request_info
*info
,
1606 struct iw_point
*wrq
, char *extra
)
1608 PSDevice pDevice
= netdev_priv(dev
);
1609 PSMgmtObject pMgmt
= &(pDevice
->sMgmtObj
);
1610 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1613 if (memcmp(pMgmt
->abyCurrBSSID
, mlme
->addr
.sa_data
, ETH_ALEN
)) {
1618 case IW_MLME_DEAUTH
:
1619 case IW_MLME_DISASSOC
:
1620 if (pDevice
->bLinkPass
== TRUE
) {
1621 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1622 bScheduleCommand((void *)pDevice
, WLAN_CMD_DISASSOCIATE
,
1634 static const iw_handler iwctl_handler
[] = {
1635 (iw_handler
)NULL
, // SIOCSIWCOMMIT
1636 (iw_handler
)NULL
, // SIOCGIWNAME
1637 (iw_handler
)NULL
, // SIOCSIWNWID
1638 (iw_handler
)NULL
, // SIOCGIWNWID
1639 (iw_handler
)NULL
, // SIOCSIWFREQ
1640 (iw_handler
)NULL
, // SIOCGIWFREQ
1641 (iw_handler
)NULL
, // SIOCSIWMODE
1642 (iw_handler
)NULL
, // SIOCGIWMODE
1643 (iw_handler
)NULL
, // SIOCSIWSENS
1644 (iw_handler
)NULL
, // SIOCGIWSENS
1645 (iw_handler
)NULL
, // SIOCSIWRANGE
1646 (iw_handler
)iwctl_giwrange
, // SIOCGIWRANGE
1647 (iw_handler
)NULL
, // SIOCSIWPRIV
1648 (iw_handler
)NULL
, // SIOCGIWPRIV
1649 (iw_handler
)NULL
, // SIOCSIWSTATS
1650 (iw_handler
)NULL
, // SIOCGIWSTATS
1651 (iw_handler
)NULL
, // SIOCSIWSPY
1652 (iw_handler
)NULL
, // SIOCGIWSPY
1653 (iw_handler
)NULL
, // -- hole --
1654 (iw_handler
)NULL
, // -- hole --
1655 (iw_handler
)NULL
, // SIOCSIWAP
1656 (iw_handler
)NULL
, // SIOCGIWAP
1657 (iw_handler
)NULL
, // -- hole -- 0x16
1658 (iw_handler
)NULL
, // SIOCGIWAPLIST
1659 (iw_handler
)iwctl_siwscan
, // SIOCSIWSCAN
1660 (iw_handler
)iwctl_giwscan
, // SIOCGIWSCAN
1661 (iw_handler
)NULL
, // SIOCSIWESSID
1662 (iw_handler
)NULL
, // SIOCGIWESSID
1663 (iw_handler
)NULL
, // SIOCSIWNICKN
1664 (iw_handler
)NULL
, // SIOCGIWNICKN
1665 (iw_handler
)NULL
, // -- hole --
1666 (iw_handler
)NULL
, // -- hole --
1667 (iw_handler
)NULL
, // SIOCSIWRATE 0x20
1668 (iw_handler
)NULL
, // SIOCGIWRATE
1669 (iw_handler
)NULL
, // SIOCSIWRTS
1670 (iw_handler
)NULL
, // SIOCGIWRTS
1671 (iw_handler
)NULL
, // SIOCSIWFRAG
1672 (iw_handler
)NULL
, // SIOCGIWFRAG
1673 (iw_handler
)NULL
, // SIOCSIWTXPOW
1674 (iw_handler
)NULL
, // SIOCGIWTXPOW
1675 (iw_handler
)NULL
, // SIOCSIWRETRY
1676 (iw_handler
)NULL
, // SIOCGIWRETRY
1677 (iw_handler
)NULL
, // SIOCSIWENCODE
1678 (iw_handler
)NULL
, // SIOCGIWENCODE
1679 (iw_handler
)NULL
, // SIOCSIWPOWER
1680 (iw_handler
)NULL
, // SIOCGIWPOWER
1681 (iw_handler
)NULL
, // -- hole --
1682 (iw_handler
)NULL
, // -- hole --
1683 (iw_handler
)NULL
, // SIOCSIWGENIE
1684 (iw_handler
)NULL
, // SIOCGIWGENIE
1685 (iw_handler
)NULL
, // SIOCSIWAUTH
1686 (iw_handler
)NULL
, // SIOCGIWAUTH
1687 (iw_handler
)NULL
, // SIOCSIWENCODEEXT
1688 (iw_handler
)NULL
, // SIOCGIWENCODEEXT
1689 (iw_handler
)NULL
, // SIOCSIWPMKSA
1690 (iw_handler
)NULL
, // -- hole --
1693 static const iw_handler iwctl_private_handler
[] = {
1694 NULL
, // SIOCIWFIRSTPRIV
1697 struct iw_priv_args iwctl_private_args
[] = {
1698 { IOCTL_CMD_SET
, IW_PRIV_TYPE_CHAR
| 1024, 0, "set" },
1701 const struct iw_handler_def iwctl_handler_def
= {
1702 .get_wireless_stats
= &iwctl_get_wireless_stats
,
1703 .num_standard
= sizeof(iwctl_handler
) / sizeof(iw_handler
),
1705 .num_private_args
= 0,
1706 .standard
= (iw_handler
*)iwctl_handler
,
1708 .private_args
= NULL
,