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
44 static const long frequency_list
[] = {
45 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
46 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
47 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
48 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
49 5700, 5745, 5765, 5785, 5805, 5825
52 static int msglevel
= MSG_LEVEL_INFO
;
54 struct iw_statistics
*iwctl_get_wireless_stats(struct net_device
*dev
)
56 struct vnt_private
*pDevice
= netdev_priv(dev
);
59 pDevice
->wstats
.status
= pDevice
->op_mode
;
60 vnt_rf_rssi_to_dbm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
61 pDevice
->wstats
.qual
.level
= ldBm
;
62 pDevice
->wstats
.qual
.noise
= 0;
63 pDevice
->wstats
.qual
.updated
= 1;
64 pDevice
->wstats
.discard
.nwid
= 0;
65 pDevice
->wstats
.discard
.code
= 0;
66 pDevice
->wstats
.discard
.fragment
= 0;
67 pDevice
->wstats
.discard
.misc
= 0;
68 pDevice
->wstats
.miss
.beacon
= 0;
69 return &pDevice
->wstats
;
73 * Wireless Handler: get protocol name
75 int iwctl_giwname(struct net_device
*dev
, struct iw_request_info
*info
,
76 union iwreq_data
*wrqu
, char *extra
)
78 strcpy(wrqu
->name
, "802.11-a/b/g");
83 * Wireless Handler: set scan
85 int iwctl_siwscan(struct net_device
*dev
, struct iw_request_info
*info
,
86 union iwreq_data
*wrqu
, char *extra
)
88 struct vnt_private
*pDevice
= netdev_priv(dev
);
89 struct iw_point
*wrq
= &wrqu
->data
;
90 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
91 struct iw_scan_req
*req
= (struct iw_scan_req
*)extra
;
92 u8 abyScanSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
93 PWLAN_IE_SSID pItemSSID
= NULL
;
96 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
99 PRINT_K(" SIOCSIWSCAN\n");
104 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
106 PRINT_K("SIOCSIWSCAN(overlap??)-->In scanning...\n");
110 if (pDevice
->byReAssocCount
> 0) { // reject scan when re-associating!
111 // send scan event to wpa_Supplicant
112 union iwreq_data wrqu
;
113 PRINT_K("wireless_send_event--->SIOCGIWSCAN(scan done)\n");
114 memset(&wrqu
, 0, sizeof(wrqu
));
115 wireless_send_event(pDevice
->dev
, SIOCGIWSCAN
, &wrqu
, NULL
);
119 spin_lock_irqsave(&pDevice
->lock
, flags
);
121 BSSvClearBSSList((void *)pDevice
, pDevice
->bLinkPass
);
123 // mike add: active scan OR passive scan OR desire_ssid scan
124 if (wrq
->length
== sizeof(struct iw_scan_req
)) {
125 if (wrq
->flags
& IW_SCAN_THIS_ESSID
) { // desire_ssid scan
126 memset(abyScanSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
127 pItemSSID
= (PWLAN_IE_SSID
)abyScanSSID
;
128 pItemSSID
->byElementID
= WLAN_EID_SSID
;
129 memcpy(pItemSSID
->abySSID
, req
->essid
, (int)req
->essid_len
);
130 if (pItemSSID
->abySSID
[req
->essid_len
] == '\0') {
131 if (req
->essid_len
> 0)
132 pItemSSID
->len
= req
->essid_len
;
134 pItemSSID
->len
= req
->essid_len
;
136 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
137 PRINT_K("SIOCSIWSCAN:[desired_ssid=%s,len=%d]\n", ((PWLAN_IE_SSID
)abyScanSSID
)->abySSID
,
138 ((PWLAN_IE_SSID
)abyScanSSID
)->len
);
139 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, abyScanSSID
);
141 spin_unlock_irqrestore(&pDevice
->lock
, flags
);
144 } else if (req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) { // passive scan
145 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
147 } else { // active scan
148 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
151 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
152 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
154 spin_unlock_irqrestore(&pDevice
->lock
, flags
);
160 * Wireless Handler : get scan results
162 int iwctl_giwscan(struct net_device
*dev
, struct iw_request_info
*info
,
163 union iwreq_data
*wrqu
, char *extra
)
165 struct iw_point
*wrq
= &wrqu
->data
;
169 struct vnt_private
*pDevice
= netdev_priv(dev
);
170 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
172 PWLAN_IE_SSID pItemSSID
;
173 PWLAN_IE_SUPP_RATES pSuppRates
;
174 PWLAN_IE_SUPP_RATES pExtSuppRates
;
175 char *current_ev
= extra
;
176 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
177 char *current_val
= NULL
;
181 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSCAN\n");
186 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
190 pBSS
= &(pMgmt
->sBSSList
[0]);
191 for (ii
= 0, jj
= 0; jj
< MAX_BSS_NUM
; jj
++) {
192 if (current_ev
>= end_buf
)
194 pBSS
= &(pMgmt
->sBSSList
[jj
]);
197 memset(&iwe
, 0, sizeof(iwe
));
199 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
200 memcpy(iwe
.u
.ap_addr
.sa_data
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
201 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
203 memset(&iwe
, 0, sizeof(iwe
));
204 iwe
.cmd
= SIOCGIWESSID
;
205 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
206 iwe
.u
.data
.length
= pItemSSID
->len
;
207 iwe
.u
.data
.flags
= 1;
208 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
210 memset(&iwe
, 0, sizeof(iwe
));
211 iwe
.cmd
= SIOCGIWMODE
;
212 if (WLAN_GET_CAP_INFO_ESS(pBSS
->wCapInfo
))
213 iwe
.u
.mode
= IW_MODE_INFRA
;
215 iwe
.u
.mode
= IW_MODE_ADHOC
;
216 iwe
.len
= IW_EV_UINT_LEN
;
217 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
219 pSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abySuppRates
;
220 pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abyExtSuppRates
;
221 memset(&iwe
, 0, sizeof(iwe
));
222 iwe
.cmd
= SIOCGIWFREQ
;
223 iwe
.u
.freq
.m
= pBSS
->uChannel
;
226 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
228 int f
= (int)pBSS
->uChannel
- 1;
231 iwe
.u
.freq
.m
= frequency_list
[f
] * 100000;
234 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
236 memset(&iwe
, 0, sizeof(iwe
));
238 vnt_rf_rssi_to_dbm(pDevice
, (u8
)(pBSS
->uRSSI
), &ldBm
);
239 iwe
.u
.qual
.level
= ldBm
;
240 iwe
.u
.qual
.noise
= 0;
243 iwe
.u
.qual
.qual
= 100;
247 iwe
.u
.qual
.qual
= (40 - (-ldBm
- 50)) * 100 / 40;
248 iwe
.u
.qual
.updated
= 7;
250 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
252 memset(&iwe
, 0, sizeof(iwe
));
253 iwe
.cmd
= SIOCGIWENCODE
;
254 iwe
.u
.data
.length
= 0;
255 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS
->wCapInfo
))
256 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
258 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
259 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
261 memset(&iwe
, 0, sizeof(iwe
));
262 iwe
.cmd
= SIOCGIWRATE
;
263 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
264 current_val
= current_ev
+ IW_EV_LCP_LEN
;
266 for (kk
= 0; kk
< 12; kk
++) {
267 if (pSuppRates
->abyRates
[kk
] == 0)
269 // Bit rate given in 500 kb/s units (+ 0x80)
270 iwe
.u
.bitrate
.value
= ((pSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
271 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
273 for (kk
= 0; kk
< 8; kk
++) {
274 if (pExtSuppRates
->abyRates
[kk
] == 0)
276 // Bit rate given in 500 kb/s units (+ 0x80)
277 iwe
.u
.bitrate
.value
= ((pExtSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
278 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
281 if ((current_val
- current_ev
) > IW_EV_LCP_LEN
)
282 current_ev
= current_val
;
284 if ((pBSS
->wWPALen
> 0) && (pBSS
->wWPALen
<= MAX_WPA_IE_LEN
)) {
285 memset(&iwe
, 0, sizeof(iwe
));
287 iwe
.u
.data
.length
= pBSS
->wWPALen
;
288 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byWPAIE
);
291 if ((pBSS
->wRSNLen
> 0) && (pBSS
->wRSNLen
<= MAX_WPA_IE_LEN
)) {
292 memset(&iwe
, 0, sizeof(iwe
));
294 iwe
.u
.data
.length
= pBSS
->wRSNLen
;
295 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byRSNIE
);
299 wrq
->length
= current_ev
- extra
;
304 * Wireless Handler: set frequence or channel
306 int iwctl_siwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
307 union iwreq_data
*wrqu
, char *extra
)
309 struct vnt_private
*pDevice
= netdev_priv(dev
);
310 struct iw_freq
*wrq
= &wrqu
->freq
;
313 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFREQ\n");
315 // If setting by frequency, convert to a channel
316 if ((wrq
->e
== 1) && (wrq
->m
>= (int)2.412e8
) &&
317 (wrq
->m
<= (int)2.487e8
)) {
318 int f
= wrq
->m
/ 100000;
320 while ((c
< 14) && (f
!= frequency_list
[c
]))
325 // Setting by channel number
326 if ((wrq
->m
> 14) || (wrq
->e
> 0)) {
329 int channel
= wrq
->m
;
330 if ((channel
< 1) || (channel
> 14)) {
331 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: New channel value of %d is invalid!\n", dev
->name
, wrq
->m
);
334 // Yes ! We can set it !!!
335 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set to channel = %d\n", channel
);
336 pDevice
->uChannel
= channel
;
343 * Wireless Handler: get frequence or channel
345 int iwctl_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
346 union iwreq_data
*wrqu
, char *extra
)
348 struct vnt_private
*pDevice
= netdev_priv(dev
);
349 struct iw_freq
*wrq
= &wrqu
->freq
;
350 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
352 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFREQ\n");
357 #ifdef WEXT_USECHANNELS
358 wrq
->m
= (int)pMgmt
->uCurrChannel
;
362 int f
= (int)pMgmt
->uCurrChannel
- 1;
365 wrq
->m
= frequency_list
[f
] * 100000;
373 * Wireless Handler: set operation mode
375 int iwctl_siwmode(struct net_device
*dev
, struct iw_request_info
*info
,
376 union iwreq_data
*wrqu
, char *extra
)
378 struct vnt_private
*pDevice
= netdev_priv(dev
);
379 __u32
*wmode
= &wrqu
->mode
;
380 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
384 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMODE\n");
391 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_IBSS_STA
) {
392 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
393 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
394 pDevice
->bCommit
= true;
396 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to ad-hoc\n");
400 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_ESS_STA
) {
401 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
402 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
403 pDevice
->bCommit
= true;
405 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to infrastructure\n");
412 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
419 if (pDevice
->bCommit
) {
420 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
421 netif_stop_queue(pDevice
->dev
);
423 spin_lock_irqsave(&pDevice
->lock
, flags
);
425 bScheduleCommand((void *) pDevice
,
426 WLAN_CMD_RUN_AP
, NULL
);
428 spin_unlock_irqrestore(&pDevice
->lock
, flags
);
430 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
431 "Commit the settings\n");
433 if (pDevice
->bLinkPass
&&
434 memcmp(pMgmt
->abyCurrSSID
,
435 pMgmt
->abyDesireSSID
,
436 WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
)) {
437 bScheduleCommand((void *) pDevice
,
438 WLAN_CMD_DISASSOCIATE
, NULL
);
440 pDevice
->bLinkPass
= false;
441 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
442 memset(pMgmt
->abyCurrBSSID
, 0, 6);
445 vnt_mac_set_led(pDevice
, LEDSTS_STS
, LEDSTS_SLOW
);
447 netif_stop_queue(pDevice
->dev
);
449 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
451 if (!pDevice
->bWPASuppWextEnabled
)
452 bScheduleCommand((void *) pDevice
,
454 pMgmt
->abyDesireSSID
);
456 bScheduleCommand((void *) pDevice
,
460 pDevice
->bCommit
= false;
467 * Wireless Handler: get operation mode
469 int iwctl_giwmode(struct net_device
*dev
, struct iw_request_info
*info
,
470 union iwreq_data
*wrqu
, char *extra
)
472 struct vnt_private
*pDevice
= netdev_priv(dev
);
473 __u32
*wmode
= &wrqu
->mode
;
474 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
476 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWMODE\n");
481 // If not managed, assume it's ad-hoc
482 switch (pMgmt
->eConfigMode
) {
483 case WMAC_CONFIG_ESS_STA
:
484 *wmode
= IW_MODE_INFRA
;
486 case WMAC_CONFIG_IBSS_STA
:
487 *wmode
= IW_MODE_ADHOC
;
489 case WMAC_CONFIG_AUTO
:
490 *wmode
= IW_MODE_INFRA
;
493 *wmode
= IW_MODE_MASTER
;
496 *wmode
= IW_MODE_ADHOC
;
503 * Wireless Handler: get capability range
505 int iwctl_giwrange(struct net_device
*dev
, struct iw_request_info
*info
,
506 union iwreq_data
*wrqu
, char *extra
)
508 struct iw_point
*wrq
= &wrqu
->data
;
509 struct iw_range
*range
= (struct iw_range
*)extra
;
512 u8 abySupportedRates
[13] = {
513 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
517 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRANGE\n");
519 wrq
->length
= sizeof(struct iw_range
);
520 memset(range
, 0, sizeof(struct iw_range
));
521 range
->min_nwid
= 0x0000;
522 range
->max_nwid
= 0x0000;
523 range
->num_channels
= 14;
524 // Should be based on cap_rid.country to give only
525 // what the current card support
527 for (i
= 0; i
< 14; i
++) {
528 range
->freq
[k
].i
= i
+ 1; // List index
529 range
->freq
[k
].m
= frequency_list
[i
] * 100000;
530 range
->freq
[k
++].e
= 1; // Values in table in MHz -> * 10^5 * 10
532 range
->num_frequency
= k
;
533 // Hum... Should put the right values there
534 range
->max_qual
.qual
= 100;
535 range
->max_qual
.level
= 0;
536 range
->max_qual
.noise
= 0;
537 range
->sensitivity
= 255;
539 for (i
= 0; i
< 13; i
++) {
540 range
->bitrate
[i
] = abySupportedRates
[i
] * 500000;
541 if (range
->bitrate
[i
] == 0)
544 range
->num_bitrates
= i
;
546 // Set an indication of the max TCP throughput
547 // in bit/s that we can expect using this interface.
548 // May be use for QoS stuff... Jean II
550 range
->throughput
= 5 * 1000 * 1000;
552 range
->throughput
= 1.5 * 1000 * 1000;
555 range
->max_rts
= 2312;
556 range
->min_frag
= 256;
557 range
->max_frag
= 2312;
559 // the encoding capabilities
560 range
->num_encoding_sizes
= 3;
562 range
->encoding_size
[0] = 5;
564 range
->encoding_size
[1] = 13;
565 // 256 bits for WPA-PSK
566 range
->encoding_size
[2] = 32;
567 // 4 keys are allowed
568 range
->max_encoding_tokens
= 4;
570 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
571 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
574 range
->max_pmp
= 1000000; // 1 secs
576 range
->max_pmt
= 1000000; // 1 secs
577 range
->pmp_flags
= IW_POWER_PERIOD
;
578 range
->pmt_flags
= IW_POWER_TIMEOUT
;
579 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_ALL_R
;
581 // Transmit Power - values are in mW
582 range
->txpower
[0] = 100;
583 range
->num_txpower
= 1;
584 range
->txpower_capa
= IW_TXPOW_MWATT
;
585 range
->we_version_source
= WIRELESS_EXT
;
586 range
->we_version_compiled
= WIRELESS_EXT
;
587 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
588 range
->retry_flags
= IW_RETRY_LIMIT
;
589 range
->r_time_flags
= IW_RETRY_LIFETIME
;
590 range
->min_retry
= 1;
591 range
->max_retry
= 65535;
592 range
->min_r_time
= 1024;
593 range
->max_r_time
= 65535 * 1024;
594 // Experimental measurements - boundary 11/5.5 Mb/s
595 // Note : with or without the (local->rssi), results
596 // are somewhat different. - Jean II
597 range
->avg_qual
.qual
= 6;
598 range
->avg_qual
.level
= 176; // -80 dBm
599 range
->avg_qual
.noise
= 0;
606 * Wireless Handler : set ap mac address
608 int iwctl_siwap(struct net_device
*dev
, struct iw_request_info
*info
,
609 union iwreq_data
*wrqu
, char *extra
)
611 struct vnt_private
*pDevice
= netdev_priv(dev
);
612 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
613 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
615 u8 ZeroBSSID
[WLAN_BSSID_LEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
617 PRINT_K(" SIOCSIWAP\n");
622 if (wrq
->sa_family
!= ARPHRD_ETHER
) {
625 memcpy(pMgmt
->abyDesireBSSID
, wrq
->sa_data
, 6);
627 if ((is_broadcast_ether_addr(pMgmt
->abyDesireBSSID
)) ||
628 (memcmp(pMgmt
->abyDesireBSSID
, ZeroBSSID
, 6) == 0)) {
629 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
632 // mike add: if desired AP is hidden ssid(there are
633 // two same BSSID in list), then ignore,because you
634 // don't known which one to be connect with??
637 unsigned uSameBssidNum
= 0;
638 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
639 if (pMgmt
->sBSSList
[ii
].bActive
&&
640 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
641 pMgmt
->abyDesireBSSID
)) {
645 if (uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
646 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
651 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
652 pDevice
->bCommit
= true;
658 * Wireless Handler: get ap mac address
660 int iwctl_giwap(struct net_device
*dev
, struct iw_request_info
*info
,
661 union iwreq_data
*wrqu
, char *extra
)
663 struct vnt_private
*pDevice
= netdev_priv(dev
);
664 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
665 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
667 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAP\n");
672 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
674 if ((pDevice
->bLinkPass
== false) && (pMgmt
->eCurrMode
!= WMAC_MODE_ESS_AP
))
675 memset(wrq
->sa_data
, 0, 6);
677 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)
678 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
680 wrq
->sa_family
= ARPHRD_ETHER
;
685 * Wireless Handler: get ap list
687 int iwctl_giwaplist(struct net_device
*dev
, struct iw_request_info
*info
,
688 union iwreq_data
*wrqu
, char *extra
)
690 struct iw_point
*wrq
= &wrqu
->data
;
691 struct sockaddr
*sock
;
692 struct iw_quality
*qual
;
693 struct vnt_private
*pDevice
= netdev_priv(dev
);
694 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
695 PKnownBSS pBSS
= &pMgmt
->sBSSList
[0];
699 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAPLIST\n");
700 /* Only super-user can see AP list */
705 if (!capable(CAP_NET_ADMIN
))
711 sock
= kcalloc(IW_MAX_AP
, sizeof(struct sockaddr
), GFP_KERNEL
);
714 qual
= kcalloc(IW_MAX_AP
, sizeof(struct iw_quality
), GFP_KERNEL
);
720 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
721 if (!pBSS
[ii
].bActive
)
725 memcpy(sock
[jj
].sa_data
, pBSS
[ii
].abyBSSID
, 6);
726 sock
[jj
].sa_family
= ARPHRD_ETHER
;
727 qual
[jj
].level
= pBSS
[ii
].uRSSI
;
728 qual
[jj
].qual
= qual
[jj
].noise
= 0;
729 qual
[jj
].updated
= 2;
733 wrq
->flags
= 1; /* Should be defined */
735 memcpy(extra
, sock
, sizeof(struct sockaddr
) * jj
);
736 memcpy(extra
+ sizeof(struct sockaddr
) * jj
, qual
,
737 sizeof(struct iw_quality
) * jj
);
746 * Wireless Handler: set essid
748 int iwctl_siwessid(struct net_device
*dev
, struct iw_request_info
*info
,
749 union iwreq_data
*wrqu
, char *extra
)
751 struct vnt_private
*pDevice
= netdev_priv(dev
);
752 struct iw_point
*wrq
= &wrqu
->essid
;
753 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
754 PWLAN_IE_SSID pItemSSID
;
759 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
762 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWESSID :\n");
764 pDevice
->fWPA_Authened
= false;
765 // Check if we asked for `any'
766 if (wrq
->flags
== 0) {
767 // Just send an empty SSID list
768 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
769 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
770 PRINT_K("set essid to 'any'\n");
771 // Unknown desired AP, so here need not associate??
775 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
776 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
777 pItemSSID
->byElementID
= WLAN_EID_SSID
;
779 memcpy(pItemSSID
->abySSID
, extra
, wrq
->length
);
780 if (pItemSSID
->abySSID
[wrq
->length
] == '\0') {
782 pItemSSID
->len
= wrq
->length
;
784 pItemSSID
->len
= wrq
->length
;
786 PRINT_K("set essid to %s\n", pItemSSID
->abySSID
);
788 // mike: need clear desiredBSSID
789 if (pItemSSID
->len
== 0) {
790 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
794 // Wext wil order another command of siwap to link
795 // with desired AP, so here need not associate??
796 if (pDevice
->bWPASuppWextEnabled
== true) {
797 /*******search if in hidden ssid mode ****/
798 PKnownBSS pCurr
= NULL
;
799 u8 abyTmpDesireSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
801 unsigned uSameBssidNum
= 0;
803 memcpy(abyTmpDesireSSID
, pMgmt
->abyDesireSSID
, sizeof(abyTmpDesireSSID
));
804 pCurr
= BSSpSearchBSSList(pDevice
, NULL
,
806 pDevice
->eConfigPHYMode
);
809 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
810 vResetCommandTimer((void *)pDevice
);
811 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
812 bScheduleCommand((void *)pDevice
,
814 pMgmt
->abyDesireSSID
);
815 bScheduleCommand((void *)pDevice
,
817 pMgmt
->abyDesireSSID
);
818 } else { // mike: to find out if that desired SSID is a
819 // hidden-ssid AP, by means of judging if there
820 // are two same BSSID exist in list ?
821 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
822 if (pMgmt
->sBSSList
[ii
].bActive
&&
823 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
828 if (uSameBssidNum
>= 2) { // hit: desired AP is in hidden ssid mode!!!
829 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
830 vResetCommandTimer((void *)pDevice
);
831 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
; // this scan type, you'll submit scan result!
832 bScheduleCommand((void *)pDevice
,
834 pMgmt
->abyDesireSSID
);
835 bScheduleCommand((void *)pDevice
,
837 pMgmt
->abyDesireSSID
);
843 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set essid = %s\n", pItemSSID
->abySSID
);
846 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
847 pDevice
->bCommit
= true;
853 * Wireless Handler: get essid
855 int iwctl_giwessid(struct net_device
*dev
, struct iw_request_info
*info
,
856 union iwreq_data
*wrqu
, char *extra
)
858 struct vnt_private
*pDevice
= netdev_priv(dev
);
859 struct iw_point
*wrq
= &wrqu
->essid
;
860 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
861 PWLAN_IE_SSID pItemSSID
;
863 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWESSID\n");
868 // Note: if wrq->u.data.flags != 0, we should get the relevant
869 // SSID from the SSID list...
871 // Get the current SSID
872 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
873 memcpy(extra
, pItemSSID
->abySSID
, pItemSSID
->len
);
874 extra
[pItemSSID
->len
] = '\0';
876 wrq
->length
= pItemSSID
->len
;
877 wrq
->flags
= 1; // active
883 * Wireless Handler: set data rate
885 int iwctl_siwrate(struct net_device
*dev
, struct iw_request_info
*info
,
886 union iwreq_data
*wrqu
, char *extra
)
888 struct vnt_private
*pDevice
= netdev_priv(dev
);
889 struct iw_param
*wrq
= &wrqu
->bitrate
;
893 u8 abySupportedRates
[13] = {
894 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
898 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRATE\n");
899 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
904 // First: get a valid bit rate value
906 // Which type of value
907 if ((wrq
->value
< 13) && (wrq
->value
>= 0)) {
908 // Setting by rate index
909 // Find value in the magic rate table
912 // Setting by frequency value
913 u8 normvalue
= (u8
)(wrq
->value
/500000);
915 // Check if rate is valid
916 for (i
= 0; i
< 13; i
++) {
917 if (normvalue
== abySupportedRates
[i
]) {
923 // -1 designed the max rate (mostly auto mode)
924 if (wrq
->value
== -1) {
925 // Get the highest available rate
926 for (i
= 0; i
< 13; i
++) {
927 if (abySupportedRates
[i
] == 0)
934 // Check that it is valid
935 // brate is index of abySupportedRates[]
941 // Now, check if we want a fixed or auto value
942 if (wrq
->fixed
!= 0) {
945 pDevice
->bFixRate
= true;
946 if ((pDevice
->byBBType
== BB_TYPE_11B
) && (brate
> 3)) {
947 pDevice
->uConnectionRate
= 3;
949 pDevice
->uConnectionRate
= brate
;
950 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fixed to Rate %d\n", pDevice
->uConnectionRate
);
953 pDevice
->bFixRate
= false;
954 pDevice
->uConnectionRate
= 13;
961 * Wireless Handler: get data rate
963 int iwctl_giwrate(struct net_device
*dev
, struct iw_request_info
*info
,
964 union iwreq_data
*wrqu
, char *extra
)
966 struct vnt_private
*pDevice
= netdev_priv(dev
);
967 struct iw_param
*wrq
= &wrqu
->bitrate
;
968 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
970 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRATE\n");
976 u8 abySupportedRates
[13] = {
977 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
978 0x48, 0x60, 0x6C, 0x90
982 if (pDevice
->uConnectionRate
< 13) {
983 brate
= abySupportedRates
[pDevice
->uConnectionRate
];
985 if (pDevice
->byBBType
== BB_TYPE_11B
)
987 if (pDevice
->byBBType
== BB_TYPE_11G
)
989 if (pDevice
->byBBType
== BB_TYPE_11A
)
992 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
993 if (pDevice
->byBBType
== BB_TYPE_11B
)
995 if (pDevice
->byBBType
== BB_TYPE_11G
)
997 if (pDevice
->byBBType
== BB_TYPE_11A
)
1000 if (pDevice
->uConnectionRate
== 13)
1001 brate
= abySupportedRates
[pDevice
->wCurrentRate
];
1002 wrq
->value
= brate
* 500000;
1003 // If more than one rate, set auto
1004 if (pDevice
->bFixRate
== true)
1012 * Wireless Handler: set rts threshold
1014 int iwctl_siwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1015 union iwreq_data
*wrqu
, char *extra
)
1017 struct vnt_private
*pDevice
= netdev_priv(dev
);
1018 struct iw_param
*wrq
= &wrqu
->rts
;
1020 if ((wrq
->value
< 0 || wrq
->value
> 2312) && !wrq
->disabled
)
1023 else if (wrq
->disabled
)
1024 pDevice
->wRTSThreshold
= 2312;
1026 pDevice
->wRTSThreshold
= wrq
->value
;
1032 * Wireless Handler: get rts
1034 int iwctl_giwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1035 union iwreq_data
*wrqu
, char *extra
)
1037 struct vnt_private
*pDevice
= netdev_priv(dev
);
1038 struct iw_param
*wrq
= &wrqu
->rts
;
1040 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRTS\n");
1041 wrq
->value
= pDevice
->wRTSThreshold
;
1042 wrq
->disabled
= (wrq
->value
>= 2312);
1048 * Wireless Handler: set fragment threshold
1050 int iwctl_siwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1051 union iwreq_data
*wrqu
, char *extra
)
1053 struct vnt_private
*pDevice
= netdev_priv(dev
);
1054 struct iw_param
*wrq
= &wrqu
->frag
;
1056 int fthr
= wrq
->value
;
1058 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFRAG\n");
1062 if ((fthr
< 256) || (fthr
> 2312)) {
1065 fthr
&= ~0x1; // Get an even value
1066 pDevice
->wFragmentationThreshold
= (u16
)fthr
;
1072 * Wireless Handler: get fragment threshold
1074 int iwctl_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1075 union iwreq_data
*wrqu
, char *extra
)
1077 struct vnt_private
*pDevice
= netdev_priv(dev
);
1078 struct iw_param
*wrq
= &wrqu
->frag
;
1080 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFRAG\n");
1081 wrq
->value
= pDevice
->wFragmentationThreshold
;
1082 wrq
->disabled
= (wrq
->value
>= 2312);
1088 * Wireless Handler: set retry threshold
1090 int iwctl_siwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1091 union iwreq_data
*wrqu
, char *extra
)
1093 struct vnt_private
*pDevice
= netdev_priv(dev
);
1094 struct iw_param
*wrq
= &wrqu
->retry
;
1097 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRETRY\n");
1099 if (wrq
->disabled
) {
1104 if (wrq
->flags
& IW_RETRY_LIMIT
) {
1105 if (wrq
->flags
& IW_RETRY_MAX
) {
1106 pDevice
->byLongRetryLimit
= wrq
->value
;
1107 } else if (wrq
->flags
& IW_RETRY_MIN
) {
1108 pDevice
->byShortRetryLimit
= wrq
->value
;
1110 // No modifier : set both
1111 pDevice
->byShortRetryLimit
= wrq
->value
;
1112 pDevice
->byLongRetryLimit
= wrq
->value
;
1115 if (wrq
->flags
& IW_RETRY_LIFETIME
)
1116 pDevice
->wMaxTransmitMSDULifetime
= wrq
->value
;
1121 * Wireless Handler: get retry threshold
1123 int iwctl_giwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1124 union iwreq_data
*wrqu
, char *extra
)
1126 struct vnt_private
*pDevice
= netdev_priv(dev
);
1127 struct iw_param
*wrq
= &wrqu
->retry
;
1128 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRETRY\n");
1129 wrq
->disabled
= 0; // Can't be disabled
1131 // Note: by default, display the min retry number
1132 if ((wrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1133 wrq
->flags
= IW_RETRY_LIFETIME
;
1134 wrq
->value
= (int)pDevice
->wMaxTransmitMSDULifetime
; // ms
1135 } else if ((wrq
->flags
& IW_RETRY_MAX
)) {
1136 wrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1137 wrq
->value
= (int)pDevice
->byLongRetryLimit
;
1139 wrq
->flags
= IW_RETRY_LIMIT
;
1140 wrq
->value
= (int)pDevice
->byShortRetryLimit
;
1141 if ((int)pDevice
->byShortRetryLimit
!= (int)pDevice
->byLongRetryLimit
)
1142 wrq
->flags
|= IW_RETRY_MIN
;
1148 * Wireless Handler: set encode mode
1150 int iwctl_siwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1151 union iwreq_data
*wrqu
, char *extra
)
1153 struct vnt_private
*pDevice
= netdev_priv(dev
);
1154 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1155 struct iw_point
*wrq
= &wrqu
->encoding
;
1156 u32 dwKeyIndex
= (u32
)(wrq
->flags
& IW_ENCODE_INDEX
);
1160 int index
= (wrq
->flags
& IW_ENCODE_INDEX
);
1162 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODE\n");
1167 // Check the size of the key
1168 if (wrq
->length
> WLAN_WEP232_KEYLEN
) {
1173 if (dwKeyIndex
> WLAN_WEP_NKEYS
) {
1181 // Send the key to the card
1182 if (wrq
->length
> 0) {
1183 if (wrq
->length
== WLAN_WEP232_KEYLEN
) {
1184 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 232 bit wep key\n");
1185 } else if (wrq
->length
== WLAN_WEP104_KEYLEN
) {
1186 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 104 bit wep key\n");
1187 } else if (wrq
->length
== WLAN_WEP40_KEYLEN
) {
1188 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 40 bit wep key, index= %d\n", (int)dwKeyIndex
);
1190 memset(pDevice
->abyKey
, 0, WLAN_WEP232_KEYLEN
);
1191 memcpy(pDevice
->abyKey
, extra
, wrq
->length
);
1193 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"abyKey: ");
1194 for (ii
= 0; ii
< wrq
->length
; ii
++)
1195 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pDevice
->abyKey
[ii
]);
1197 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1198 KeybSetDefaultKey(pDevice
,
1200 dwKeyIndex
| (1 << 31),
1205 pDevice
->byKeyIndex
= (u8
)dwKeyIndex
;
1206 pDevice
->uKeyLength
= wrq
->length
;
1207 pDevice
->bTransmitKey
= true;
1208 pDevice
->bEncryptionEnable
= true;
1209 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1211 // Do we want to just set the transmit key index?
1213 pDevice
->byKeyIndex
= index
;
1214 } else if (!(wrq
->flags
& IW_ENCODE_MODE
)) {
1220 if (wrq
->flags
& IW_ENCODE_DISABLED
) {
1221 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disable WEP function\n");
1222 pMgmt
->bShareKeyAlgorithm
= false;
1223 pDevice
->bEncryptionEnable
= false;
1224 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1225 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1226 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++)
1227 MACvDisableKeyEntry(pDevice
, uu
);
1230 if (wrq
->flags
& IW_ENCODE_RESTRICTED
) {
1231 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & ShareKey System\n");
1232 pMgmt
->bShareKeyAlgorithm
= true;
1234 if (wrq
->flags
& IW_ENCODE_OPEN
) {
1235 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & Open System\n");
1236 pMgmt
->bShareKeyAlgorithm
= false;
1239 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1244 int iwctl_giwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1245 union iwreq_data
*wrqu
, char *extra
)
1247 struct vnt_private
*pDevice
= netdev_priv(dev
);
1248 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1249 struct iw_point
*wrq
= &wrqu
->encoding
;
1250 char abyKey
[WLAN_WEP232_KEYLEN
];
1252 unsigned index
= (unsigned)(wrq
->flags
& IW_ENCODE_INDEX
);
1253 PSKeyItem pKey
= NULL
;
1255 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODE\n");
1260 if (index
> WLAN_WEP_NKEYS
)
1262 if (index
< 1) { // get default key
1263 if (pDevice
->byKeyIndex
< WLAN_WEP_NKEYS
)
1264 index
= pDevice
->byKeyIndex
;
1271 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1272 // Check encryption mode
1273 wrq
->flags
= IW_ENCODE_NOKEY
;
1274 // Is WEP enabled ???
1275 if (pDevice
->bEncryptionEnable
)
1276 wrq
->flags
|= IW_ENCODE_ENABLED
;
1278 wrq
->flags
|= IW_ENCODE_DISABLED
;
1280 if (pMgmt
->bShareKeyAlgorithm
)
1281 wrq
->flags
|= IW_ENCODE_RESTRICTED
;
1283 wrq
->flags
|= IW_ENCODE_OPEN
;
1286 if ((index
== 0) && (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
||
1287 pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)) { // get wpa pairwise key
1288 if (KeybGetKey(&(pDevice
->sKey
), pMgmt
->abyCurrBSSID
, 0xffffffff, &pKey
)) {
1289 wrq
->length
= pKey
->uKeyLength
;
1290 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1291 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1293 } else if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, (u8
)index
, &pKey
)) {
1294 wrq
->length
= pKey
->uKeyLength
;
1295 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1296 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1299 wrq
->flags
|= index
+ 1;
1304 * Wireless Handler: set power mode
1306 int iwctl_siwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1307 union iwreq_data
*wrqu
, char *extra
)
1309 struct vnt_private
*pDevice
= netdev_priv(dev
);
1310 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1311 struct iw_param
*wrq
= &wrqu
->power
;
1314 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER\n");
1319 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
1324 if (wrq
->disabled
) {
1325 pDevice
->ePSMode
= WMAC_POWER_CAM
;
1326 PSvDisablePowerSaving(pDevice
);
1329 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1330 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1331 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1333 } else if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_PERIOD
) {
1334 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1335 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1338 switch (wrq
->flags
& IW_POWER_MODE
) {
1339 case IW_POWER_UNICAST_R
:
1340 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1343 case IW_POWER_ALL_R
:
1344 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ALL_R\n");
1347 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ON\n");
1357 * Wireless Handler: get power mode
1359 int iwctl_giwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1360 union iwreq_data
*wrqu
, char *extra
)
1362 struct vnt_private
*pDevice
= netdev_priv(dev
);
1363 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1364 struct iw_param
*wrq
= &wrqu
->power
;
1365 int mode
= pDevice
->ePSMode
;
1367 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPOWER\n");
1372 wrq
->disabled
= (mode
== WMAC_POWER_CAM
);
1376 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1377 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1378 pMgmt
->wCurrBeaconPeriod
) / 100);
1379 wrq
->flags
= IW_POWER_TIMEOUT
;
1381 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1382 pMgmt
->wCurrBeaconPeriod
) / 100);
1383 wrq
->flags
= IW_POWER_PERIOD
;
1386 wrq
->flags
|= IW_POWER_ALL_R
;
1391 * Wireless Handler: get Sensitivity
1393 int iwctl_giwsens(struct net_device
*dev
, struct iw_request_info
*info
,
1394 union iwreq_data
*wrqu
, char *extra
)
1396 struct vnt_private
*pDevice
= netdev_priv(dev
);
1397 struct iw_param
*wrq
= &wrqu
->sens
;
1400 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSENS\n");
1401 if (pDevice
->bLinkPass
== true) {
1402 vnt_rf_rssi_to_dbm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
1407 wrq
->disabled
= (wrq
->value
== 0);
1412 int iwctl_siwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1413 union iwreq_data
*wrqu
, char *extra
)
1415 struct vnt_private
*pDevice
= netdev_priv(dev
);
1416 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1417 struct iw_param
*wrq
= &wrqu
->param
;
1419 static int wpa_version
= 0; // must be static to save the last value, einsn liu
1420 static int pairwise
= 0;
1425 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH\n");
1426 switch (wrq
->flags
& IW_AUTH_INDEX
) {
1427 case IW_AUTH_WPA_VERSION
:
1428 wpa_version
= wrq
->value
;
1429 if (wrq
->value
== IW_AUTH_WPA_VERSION_DISABLED
) {
1430 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1431 } else if (wrq
->value
== IW_AUTH_WPA_VERSION_WPA
) {
1432 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1434 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1437 case IW_AUTH_CIPHER_PAIRWISE
:
1438 pairwise
= wrq
->value
;
1439 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise
);
1440 if (pairwise
== IW_AUTH_CIPHER_CCMP
) {
1441 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1442 } else if (pairwise
== IW_AUTH_CIPHER_TKIP
) {
1443 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1444 } else if (pairwise
== IW_AUTH_CIPHER_WEP40
||
1445 pairwise
== IW_AUTH_CIPHER_WEP104
) {
1446 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1447 } else if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1448 // do nothing, einsn liu
1450 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1453 case IW_AUTH_CIPHER_GROUP
:
1454 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq
->value
);
1455 if (wpa_version
== IW_AUTH_WPA_VERSION_DISABLED
)
1457 if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1458 if (wrq
->value
== IW_AUTH_CIPHER_CCMP
)
1459 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1461 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1464 case IW_AUTH_KEY_MGMT
:
1465 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version
, wrq
->value
);
1466 if (wpa_version
== IW_AUTH_WPA_VERSION_WPA2
) {
1467 if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1468 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
1469 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
1470 } else if (wpa_version
== IW_AUTH_WPA_VERSION_WPA
) {
1471 if (wrq
->value
== 0) {
1472 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
1473 } else if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1474 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
1476 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
1479 case IW_AUTH_TKIP_COUNTERMEASURES
:
1481 case IW_AUTH_DROP_UNENCRYPTED
:
1483 case IW_AUTH_80211_AUTH_ALG
:
1484 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq
->value
);
1485 if (wrq
->value
== IW_AUTH_ALG_OPEN_SYSTEM
)
1486 pMgmt
->bShareKeyAlgorithm
= false;
1487 else if (wrq
->value
== IW_AUTH_ALG_SHARED_KEY
)
1488 pMgmt
->bShareKeyAlgorithm
= true;
1490 case IW_AUTH_WPA_ENABLED
:
1492 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1494 case IW_AUTH_ROAMING_CONTROL
:
1497 case IW_AUTH_PRIVACY_INVOKED
:
1498 pDevice
->bEncryptionEnable
= !!wrq
->value
;
1499 if (pDevice
->bEncryptionEnable
== false) {
1502 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1503 pMgmt
->bShareKeyAlgorithm
= false;
1504 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
1505 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1509 PRINT_K("iwctl_siwauth: not supported %x\n", wrq
->flags
);
1516 int iwctl_giwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1517 union iwreq_data
*wrqu
, char *extra
)
1522 int iwctl_siwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1523 union iwreq_data
*wrqu
, char *extra
)
1525 struct vnt_private
*pDevice
= netdev_priv(dev
);
1526 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1527 struct iw_point
*wrq
= &wrqu
->data
;
1534 if ((wrq
->length
< 2) || (extra
[1] + 2 != wrq
->length
)) {
1538 if (wrq
->length
> MAX_WPA_IE_LEN
) {
1542 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1544 memcpy(pMgmt
->abyWPAIE
, extra
, wrq
->length
);
1545 pMgmt
->wWPAIELen
= wrq
->length
;
1547 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1548 pMgmt
->wWPAIELen
= 0;
1551 out
: // not completely ...not necessary in wpa_supplicant 0.5.8
1555 int iwctl_giwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1556 union iwreq_data
*wrqu
, char *extra
)
1558 struct vnt_private
*pDevice
= netdev_priv(dev
);
1559 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1560 struct iw_point
*wrq
= &wrqu
->data
;
1562 int space
= wrq
->length
;
1568 if (pMgmt
->wWPAIELen
> 0) {
1569 wrq
->length
= pMgmt
->wWPAIELen
;
1571 if (pMgmt
->wWPAIELen
<= space
)
1572 memcpy(extra
, pMgmt
->abyWPAIE
, pMgmt
->wWPAIELen
);
1579 int iwctl_siwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1580 union iwreq_data
*wrqu
, char *extra
)
1582 struct vnt_private
*pDevice
= netdev_priv(dev
);
1583 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1584 struct iw_point
*wrq
= &wrqu
->encoding
;
1585 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1586 struct viawget_wpa_param
*param
= NULL
;
1592 u8 seq
[IW_ENCODE_SEQ_MAX_SIZE
];
1600 PRINT_K("SIOCSIWENCODEEXT......\n");
1605 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
1608 buf
= kzalloc(sizeof(struct viawget_wpa_param
), GFP_KERNEL
);
1612 param
= (struct viawget_wpa_param
*)buf
;
1616 case IW_ENCODE_ALG_NONE
:
1617 alg_name
= WPA_ALG_NONE
;
1619 case IW_ENCODE_ALG_WEP
:
1620 alg_name
= WPA_ALG_WEP
;
1622 case IW_ENCODE_ALG_TKIP
:
1623 alg_name
= WPA_ALG_TKIP
;
1625 case IW_ENCODE_ALG_CCMP
:
1626 alg_name
= WPA_ALG_CCMP
;
1629 PRINT_K("Unknown alg = %d\n", ext
->alg
);
1634 memcpy(addr
, ext
->addr
.sa_data
, ETH_ALEN
);
1636 key_idx
= (wrq
->flags
&IW_ENCODE_INDEX
) - 1;
1638 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1640 // recover seq,seq_len
1641 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1642 seq_len
= IW_ENCODE_SEQ_MAX_SIZE
;
1643 memcpy(seq
, ext
->rx_seq
, seq_len
);
1645 // recover key,key_len
1647 key_len
= ext
->key_len
;
1648 memcpy(key
, &ext
->key
[0], key_len
);
1650 memset(key_array
, 0, 64);
1652 memcpy(key_array
, key
, key_len
);
1653 if (key_len
== 32) {
1654 // notice ! the oder
1655 memcpy(&key_array
[16], &key
[24], 8);
1656 memcpy(&key_array
[24], &key
[16], 8);
1660 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1661 memcpy(param
->addr
, addr
, ETH_ALEN
);
1662 param
->u
.wpa_key
.alg_name
= (int)alg_name
;
1663 param
->u
.wpa_key
.set_tx
= set_tx
;
1664 param
->u
.wpa_key
.key_index
= key_idx
;
1665 param
->u
.wpa_key
.key_len
= key_len
;
1666 param
->u
.wpa_key
.key
= (u8
*)key_array
;
1667 param
->u
.wpa_key
.seq
= (u8
*)seq
;
1668 param
->u
.wpa_key
.seq_len
= seq_len
;
1670 /****set if current action is Network Manager count?? */
1671 /****this method is so foolish,but there is no other way??? */
1672 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
1673 if (param
->u
.wpa_key
.key_index
== 0) {
1674 pDevice
->bwextstep0
= true;
1676 if ((pDevice
->bwextstep0
== true) && (param
->u
.wpa_key
.key_index
== 1)) {
1677 pDevice
->bwextstep0
= false;
1678 pDevice
->bwextstep1
= true;
1680 if ((pDevice
->bwextstep1
== true) && (param
->u
.wpa_key
.key_index
== 2)) {
1681 pDevice
->bwextstep1
= false;
1682 pDevice
->bwextstep2
= true;
1684 if ((pDevice
->bwextstep2
== true) && (param
->u
.wpa_key
.key_index
== 3)) {
1685 pDevice
->bwextstep2
= false;
1686 pDevice
->bwextstep3
= true;
1689 if (pDevice
->bwextstep3
== true) {
1690 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1691 pDevice
->bwextstep0
= false;
1692 pDevice
->bwextstep1
= false;
1693 pDevice
->bwextstep2
= false;
1694 pDevice
->bwextstep3
= false;
1695 pDevice
->bWPASuppWextEnabled
= true;
1696 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1697 KeyvInitTable(pDevice
, &pDevice
->sKey
);
1700 ret
= wpa_set_keys(pDevice
, param
);
1707 int iwctl_giwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1708 union iwreq_data
*wrqu
, char *extra
)
1713 int iwctl_siwmlme(struct net_device
*dev
, struct iw_request_info
*info
,
1714 union iwreq_data
*wrqu
, char *extra
)
1716 struct vnt_private
*pDevice
= netdev_priv(dev
);
1717 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1718 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1721 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME\n");
1726 if (memcmp(pMgmt
->abyCurrBSSID
, mlme
->addr
.sa_data
, ETH_ALEN
)) {
1730 switch (mlme
->cmd
) {
1731 case IW_MLME_DEAUTH
:
1732 case IW_MLME_DISASSOC
:
1733 if (pDevice
->bLinkPass
== true) {
1734 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1735 bScheduleCommand((void *)pDevice
, WLAN_CMD_DISASSOCIATE
,
1745 static int iwctl_config_commit(struct net_device
*dev
,
1746 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1748 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"SIOCSIWCOMMIT\n");
1753 static const iw_handler iwctl_handler
[] = {
1754 IW_HANDLER(SIOCSIWCOMMIT
, iwctl_config_commit
),
1755 IW_HANDLER(SIOCGIWNAME
, iwctl_giwname
),
1756 IW_HANDLER(SIOCSIWFREQ
, iwctl_siwfreq
),
1757 IW_HANDLER(SIOCGIWFREQ
, iwctl_giwfreq
),
1758 IW_HANDLER(SIOCSIWMODE
, iwctl_siwmode
),
1759 IW_HANDLER(SIOCGIWMODE
, iwctl_giwmode
),
1760 IW_HANDLER(SIOCGIWSENS
, iwctl_giwsens
),
1761 IW_HANDLER(SIOCGIWRANGE
, iwctl_giwrange
),
1762 IW_HANDLER(SIOCSIWAP
, iwctl_siwap
),
1763 IW_HANDLER(SIOCGIWAP
, iwctl_giwap
),
1764 IW_HANDLER(SIOCSIWMLME
, iwctl_siwmlme
),
1765 IW_HANDLER(SIOCGIWAPLIST
, iwctl_giwaplist
),
1766 IW_HANDLER(SIOCSIWSCAN
, iwctl_siwscan
),
1767 IW_HANDLER(SIOCGIWSCAN
, iwctl_giwscan
),
1768 IW_HANDLER(SIOCSIWESSID
, iwctl_siwessid
),
1769 IW_HANDLER(SIOCGIWESSID
, iwctl_giwessid
),
1770 IW_HANDLER(SIOCSIWRATE
, iwctl_siwrate
),
1771 IW_HANDLER(SIOCGIWRATE
, iwctl_giwrate
),
1772 IW_HANDLER(SIOCSIWRTS
, iwctl_siwrts
),
1773 IW_HANDLER(SIOCGIWRTS
, iwctl_giwrts
),
1774 IW_HANDLER(SIOCSIWFRAG
, iwctl_siwfrag
),
1775 IW_HANDLER(SIOCGIWFRAG
, iwctl_giwfrag
),
1776 IW_HANDLER(SIOCSIWRETRY
, iwctl_siwretry
),
1777 IW_HANDLER(SIOCGIWRETRY
, iwctl_giwretry
),
1778 IW_HANDLER(SIOCSIWENCODE
, iwctl_siwencode
),
1779 IW_HANDLER(SIOCGIWENCODE
, iwctl_giwencode
),
1780 IW_HANDLER(SIOCSIWPOWER
, iwctl_siwpower
),
1781 IW_HANDLER(SIOCGIWPOWER
, iwctl_giwpower
),
1782 IW_HANDLER(SIOCSIWGENIE
, iwctl_siwgenie
),
1783 IW_HANDLER(SIOCGIWGENIE
, iwctl_giwgenie
),
1784 IW_HANDLER(SIOCSIWAUTH
, iwctl_siwauth
),
1785 IW_HANDLER(SIOCGIWAUTH
, iwctl_giwauth
),
1786 IW_HANDLER(SIOCSIWENCODEEXT
, iwctl_siwencodeext
),
1787 IW_HANDLER(SIOCGIWENCODEEXT
, iwctl_giwencodeext
)
1790 static const iw_handler iwctl_private_handler
[] = {
1791 NULL
, // SIOCIWFIRSTPRIV
1794 const struct iw_handler_def iwctl_handler_def
= {
1795 .get_wireless_stats
= &iwctl_get_wireless_stats
,
1796 .num_standard
= ARRAY_SIZE(iwctl_handler
),
1798 .num_private_args
= 0,
1799 .standard
= iwctl_handler
,
1801 .private_args
= NULL
,