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
45 static const long frequency_list
[] = {
46 2412, 2417, 2422, 2427, 2432, 2437, 2442, 2447, 2452, 2457, 2462, 2467, 2472, 2484,
47 4915, 4920, 4925, 4935, 4940, 4945, 4960, 4980,
48 5035, 5040, 5045, 5055, 5060, 5080, 5170, 5180, 5190, 5200, 5210, 5220, 5230, 5240,
49 5260, 5280, 5300, 5320, 5500, 5520, 5540, 5560, 5580, 5600, 5620, 5640, 5660, 5680,
50 5700, 5745, 5765, 5785, 5805, 5825
53 static int msglevel
= MSG_LEVEL_INFO
;
55 struct iw_statistics
*iwctl_get_wireless_stats(struct net_device
*dev
)
57 struct vnt_private
*pDevice
= netdev_priv(dev
);
60 pDevice
->wstats
.status
= pDevice
->op_mode
;
61 RFvRSSITodBm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
62 pDevice
->wstats
.qual
.level
= ldBm
;
63 pDevice
->wstats
.qual
.noise
= 0;
64 pDevice
->wstats
.qual
.updated
= 1;
65 pDevice
->wstats
.discard
.nwid
= 0;
66 pDevice
->wstats
.discard
.code
= 0;
67 pDevice
->wstats
.discard
.fragment
= 0;
68 pDevice
->wstats
.discard
.misc
= 0;
69 pDevice
->wstats
.miss
.beacon
= 0;
70 return &pDevice
->wstats
;
74 * Wireless Handler: get protocol name
76 int iwctl_giwname(struct net_device
*dev
, struct iw_request_info
*info
,
77 union iwreq_data
*wrqu
, char *extra
)
79 strcpy(wrqu
->name
, "802.11-a/b/g");
84 * Wireless Handler: set scan
86 int iwctl_siwscan(struct net_device
*dev
, struct iw_request_info
*info
,
87 union iwreq_data
*wrqu
, char *extra
)
89 struct vnt_private
*pDevice
= netdev_priv(dev
);
90 struct iw_point
*wrq
= &wrqu
->data
;
91 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
92 struct iw_scan_req
*req
= (struct iw_scan_req
*)extra
;
93 u8 abyScanSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
94 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_irq(&pDevice
->lock
);
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
);
140 spin_unlock_irq(&pDevice
->lock
);
143 } else if (req
->scan_type
== IW_SCAN_TYPE_PASSIVE
) { // passive scan
144 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
146 } else { // active scan
147 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
150 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
;
151 bScheduleCommand((void *)pDevice
, WLAN_CMD_BSSID_SCAN
, NULL
);
152 spin_unlock_irq(&pDevice
->lock
);
158 * Wireless Handler : get scan results
160 int iwctl_giwscan(struct net_device
*dev
, struct iw_request_info
*info
,
161 union iwreq_data
*wrqu
, char *extra
)
163 struct iw_point
*wrq
= &wrqu
->data
;
167 struct vnt_private
*pDevice
= netdev_priv(dev
);
168 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
170 PWLAN_IE_SSID pItemSSID
;
171 PWLAN_IE_SUPP_RATES pSuppRates
;
172 PWLAN_IE_SUPP_RATES pExtSuppRates
;
173 char *current_ev
= extra
;
174 char *end_buf
= extra
+ IW_SCAN_MAX_DATA
;
175 char *current_val
= NULL
;
179 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSCAN\n");
184 if (pMgmt
->eScanState
== WMAC_IS_SCANNING
) {
188 pBSS
= &(pMgmt
->sBSSList
[0]);
189 for (ii
= 0, jj
= 0; jj
< MAX_BSS_NUM
; jj
++) {
190 if (current_ev
>= end_buf
)
192 pBSS
= &(pMgmt
->sBSSList
[jj
]);
195 memset(&iwe
, 0, sizeof(iwe
));
197 iwe
.u
.ap_addr
.sa_family
= ARPHRD_ETHER
;
198 memcpy(iwe
.u
.ap_addr
.sa_data
, pBSS
->abyBSSID
, WLAN_BSSID_LEN
);
199 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_ADDR_LEN
);
201 memset(&iwe
, 0, sizeof(iwe
));
202 iwe
.cmd
= SIOCGIWESSID
;
203 pItemSSID
= (PWLAN_IE_SSID
)pBSS
->abySSID
;
204 iwe
.u
.data
.length
= pItemSSID
->len
;
205 iwe
.u
.data
.flags
= 1;
206 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
208 memset(&iwe
, 0, sizeof(iwe
));
209 iwe
.cmd
= SIOCGIWMODE
;
210 if (WLAN_GET_CAP_INFO_ESS(pBSS
->wCapInfo
))
211 iwe
.u
.mode
= IW_MODE_INFRA
;
213 iwe
.u
.mode
= IW_MODE_ADHOC
;
214 iwe
.len
= IW_EV_UINT_LEN
;
215 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_UINT_LEN
);
217 pSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abySuppRates
;
218 pExtSuppRates
= (PWLAN_IE_SUPP_RATES
)pBSS
->abyExtSuppRates
;
219 memset(&iwe
, 0, sizeof(iwe
));
220 iwe
.cmd
= SIOCGIWFREQ
;
221 iwe
.u
.freq
.m
= pBSS
->uChannel
;
224 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
226 int f
= (int)pBSS
->uChannel
- 1;
229 iwe
.u
.freq
.m
= frequency_list
[f
] * 100000;
232 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_FREQ_LEN
);
234 memset(&iwe
, 0, sizeof(iwe
));
236 RFvRSSITodBm(pDevice
, (u8
)(pBSS
->uRSSI
), &ldBm
);
237 iwe
.u
.qual
.level
= ldBm
;
238 iwe
.u
.qual
.noise
= 0;
241 iwe
.u
.qual
.qual
= 100;
245 iwe
.u
.qual
.qual
= (40 - (-ldBm
- 50)) * 100 / 40;
246 iwe
.u
.qual
.updated
= 7;
248 current_ev
= iwe_stream_add_event(info
, current_ev
, end_buf
, &iwe
, IW_EV_QUAL_LEN
);
250 memset(&iwe
, 0, sizeof(iwe
));
251 iwe
.cmd
= SIOCGIWENCODE
;
252 iwe
.u
.data
.length
= 0;
253 if (WLAN_GET_CAP_INFO_PRIVACY(pBSS
->wCapInfo
))
254 iwe
.u
.data
.flags
= IW_ENCODE_ENABLED
| IW_ENCODE_NOKEY
;
256 iwe
.u
.data
.flags
= IW_ENCODE_DISABLED
;
257 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pItemSSID
->abySSID
);
259 memset(&iwe
, 0, sizeof(iwe
));
260 iwe
.cmd
= SIOCGIWRATE
;
261 iwe
.u
.bitrate
.fixed
= iwe
.u
.bitrate
.disabled
= 0;
262 current_val
= current_ev
+ IW_EV_LCP_LEN
;
264 for (kk
= 0; kk
< 12; kk
++) {
265 if (pSuppRates
->abyRates
[kk
] == 0)
267 // Bit rate given in 500 kb/s units (+ 0x80)
268 iwe
.u
.bitrate
.value
= ((pSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
269 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
271 for (kk
= 0; kk
< 8; kk
++) {
272 if (pExtSuppRates
->abyRates
[kk
] == 0)
274 // Bit rate given in 500 kb/s units (+ 0x80)
275 iwe
.u
.bitrate
.value
= ((pExtSuppRates
->abyRates
[kk
] & 0x7f) * 500000);
276 current_val
= iwe_stream_add_value(info
, current_ev
, current_val
, end_buf
, &iwe
, IW_EV_PARAM_LEN
);
279 if ((current_val
- current_ev
) > IW_EV_LCP_LEN
)
280 current_ev
= current_val
;
282 if ((pBSS
->wWPALen
> 0) && (pBSS
->wWPALen
<= MAX_WPA_IE_LEN
)) {
283 memset(&iwe
, 0, sizeof(iwe
));
285 iwe
.u
.data
.length
= pBSS
->wWPALen
;
286 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byWPAIE
);
289 if ((pBSS
->wRSNLen
> 0) && (pBSS
->wRSNLen
<= MAX_WPA_IE_LEN
)) {
290 memset(&iwe
, 0, sizeof(iwe
));
292 iwe
.u
.data
.length
= pBSS
->wRSNLen
;
293 current_ev
= iwe_stream_add_point(info
, current_ev
, end_buf
, &iwe
, pBSS
->byRSNIE
);
297 wrq
->length
= current_ev
- extra
;
302 * Wireless Handler: set frequence or channel
304 int iwctl_siwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
305 union iwreq_data
*wrqu
, char *extra
)
307 struct vnt_private
*pDevice
= netdev_priv(dev
);
308 struct iw_freq
*wrq
= &wrqu
->freq
;
311 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFREQ\n");
313 // If setting by frequency, convert to a channel
314 if ((wrq
->e
== 1) && (wrq
->m
>= (int)2.412e8
) &&
315 (wrq
->m
<= (int)2.487e8
)) {
316 int f
= wrq
->m
/ 100000;
318 while ((c
< 14) && (f
!= frequency_list
[c
]))
323 // Setting by channel number
324 if ((wrq
->m
> 14) || (wrq
->e
> 0)) {
327 int channel
= wrq
->m
;
328 if ((channel
< 1) || (channel
> 14)) {
329 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%s: New channel value of %d is invalid!\n", dev
->name
, wrq
->m
);
332 // Yes ! We can set it !!!
333 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" Set to channel = %d\n", channel
);
334 pDevice
->uChannel
= channel
;
341 * Wireless Handler: get frequence or channel
343 int iwctl_giwfreq(struct net_device
*dev
, struct iw_request_info
*info
,
344 union iwreq_data
*wrqu
, char *extra
)
346 struct vnt_private
*pDevice
= netdev_priv(dev
);
347 struct iw_freq
*wrq
= &wrqu
->freq
;
348 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
350 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFREQ\n");
355 #ifdef WEXT_USECHANNELS
356 wrq
->m
= (int)pMgmt
->uCurrChannel
;
360 int f
= (int)pMgmt
->uCurrChannel
- 1;
363 wrq
->m
= frequency_list
[f
] * 100000;
371 * Wireless Handler: set operation mode
373 int iwctl_siwmode(struct net_device
*dev
, struct iw_request_info
*info
,
374 union iwreq_data
*wrqu
, char *extra
)
376 struct vnt_private
*pDevice
= netdev_priv(dev
);
377 __u32
*wmode
= &wrqu
->mode
;
378 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
381 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMODE\n");
386 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
&& pDevice
->bEnableHostapd
) {
387 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
388 "Can't set operation mode, hostapd is running\n");
394 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_IBSS_STA
) {
395 pMgmt
->eConfigMode
= WMAC_CONFIG_IBSS_STA
;
396 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
397 pDevice
->bCommit
= true;
399 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to ad-hoc\n");
403 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_ESS_STA
) {
404 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
405 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
406 pDevice
->bCommit
= true;
408 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to infrastructure\n");
412 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
416 if (pMgmt
->eConfigMode
!= WMAC_CONFIG_AP
) {
417 pMgmt
->eConfigMode
= WMAC_CONFIG_AP
;
418 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
419 pDevice
->bCommit
= true;
421 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set mode to Access Point\n");
425 pMgmt
->eConfigMode
= WMAC_CONFIG_ESS_STA
;
432 if (pDevice
->bCommit
) {
433 if (pMgmt
->eConfigMode
== WMAC_CONFIG_AP
) {
434 netif_stop_queue(pDevice
->dev
);
435 spin_lock_irq(&pDevice
->lock
);
436 bScheduleCommand((void *) pDevice
,
437 WLAN_CMD_RUN_AP
, NULL
);
438 spin_unlock_irq(&pDevice
->lock
);
440 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
441 "Commit the settings\n");
443 if (pDevice
->bLinkPass
&&
444 memcmp(pMgmt
->abyCurrSSID
,
445 pMgmt
->abyDesireSSID
,
446 WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
)) {
447 bScheduleCommand((void *) pDevice
,
448 WLAN_CMD_DISASSOCIATE
, NULL
);
450 pDevice
->bLinkPass
= false;
451 pMgmt
->eCurrState
= WMAC_STATE_IDLE
;
452 memset(pMgmt
->abyCurrBSSID
, 0, 6);
455 ControlvMaskByte(pDevice
,
456 MESSAGE_REQUEST_MACREG
, MAC_REG_PAPEDELAY
,
457 LEDSTS_STS
, LEDSTS_SLOW
);
459 netif_stop_queue(pDevice
->dev
);
461 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
463 if (!pDevice
->bWPASuppWextEnabled
)
464 bScheduleCommand((void *) pDevice
,
466 pMgmt
->abyDesireSSID
);
468 bScheduleCommand((void *) pDevice
,
472 pDevice
->bCommit
= false;
479 * Wireless Handler: get operation mode
481 int iwctl_giwmode(struct net_device
*dev
, struct iw_request_info
*info
,
482 union iwreq_data
*wrqu
, char *extra
)
484 struct vnt_private
*pDevice
= netdev_priv(dev
);
485 __u32
*wmode
= &wrqu
->mode
;
486 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
488 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWMODE\n");
493 // If not managed, assume it's ad-hoc
494 switch (pMgmt
->eConfigMode
) {
495 case WMAC_CONFIG_ESS_STA
:
496 *wmode
= IW_MODE_INFRA
;
498 case WMAC_CONFIG_IBSS_STA
:
499 *wmode
= IW_MODE_ADHOC
;
501 case WMAC_CONFIG_AUTO
:
502 *wmode
= IW_MODE_INFRA
;
505 *wmode
= IW_MODE_MASTER
;
508 *wmode
= IW_MODE_ADHOC
;
515 * Wireless Handler: get capability range
517 int iwctl_giwrange(struct net_device
*dev
, struct iw_request_info
*info
,
518 union iwreq_data
*wrqu
, char *extra
)
520 struct iw_point
*wrq
= &wrqu
->data
;
521 struct iw_range
*range
= (struct iw_range
*)extra
;
524 u8 abySupportedRates
[13] = {
525 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
529 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRANGE\n");
531 wrq
->length
= sizeof(struct iw_range
);
532 memset(range
, 0, sizeof(struct iw_range
));
533 range
->min_nwid
= 0x0000;
534 range
->max_nwid
= 0x0000;
535 range
->num_channels
= 14;
536 // Should be based on cap_rid.country to give only
537 // what the current card support
539 for (i
= 0; i
< 14; i
++) {
540 range
->freq
[k
].i
= i
+ 1; // List index
541 range
->freq
[k
].m
= frequency_list
[i
] * 100000;
542 range
->freq
[k
++].e
= 1; // Values in table in MHz -> * 10^5 * 10
544 range
->num_frequency
= k
;
545 // Hum... Should put the right values there
546 range
->max_qual
.qual
= 100;
547 range
->max_qual
.level
= 0;
548 range
->max_qual
.noise
= 0;
549 range
->sensitivity
= 255;
551 for (i
= 0; i
< 13; i
++) {
552 range
->bitrate
[i
] = abySupportedRates
[i
] * 500000;
553 if (range
->bitrate
[i
] == 0)
556 range
->num_bitrates
= i
;
558 // Set an indication of the max TCP throughput
559 // in bit/s that we can expect using this interface.
560 // May be use for QoS stuff... Jean II
562 range
->throughput
= 5 * 1000 * 1000;
564 range
->throughput
= 1.5 * 1000 * 1000;
567 range
->max_rts
= 2312;
568 range
->min_frag
= 256;
569 range
->max_frag
= 2312;
571 // the encoding capabilities
572 range
->num_encoding_sizes
= 3;
574 range
->encoding_size
[0] = 5;
576 range
->encoding_size
[1] = 13;
577 // 256 bits for WPA-PSK
578 range
->encoding_size
[2] = 32;
579 // 4 keys are allowed
580 range
->max_encoding_tokens
= 4;
582 range
->enc_capa
= IW_ENC_CAPA_WPA
| IW_ENC_CAPA_WPA2
|
583 IW_ENC_CAPA_CIPHER_TKIP
| IW_ENC_CAPA_CIPHER_CCMP
;
586 range
->max_pmp
= 1000000; // 1 secs
588 range
->max_pmt
= 1000000; // 1 secs
589 range
->pmp_flags
= IW_POWER_PERIOD
;
590 range
->pmt_flags
= IW_POWER_TIMEOUT
;
591 range
->pm_capa
= IW_POWER_PERIOD
| IW_POWER_TIMEOUT
| IW_POWER_ALL_R
;
593 // Transmit Power - values are in mW
594 range
->txpower
[0] = 100;
595 range
->num_txpower
= 1;
596 range
->txpower_capa
= IW_TXPOW_MWATT
;
597 range
->we_version_source
= WIRELESS_EXT
;
598 range
->we_version_compiled
= WIRELESS_EXT
;
599 range
->retry_capa
= IW_RETRY_LIMIT
| IW_RETRY_LIFETIME
;
600 range
->retry_flags
= IW_RETRY_LIMIT
;
601 range
->r_time_flags
= IW_RETRY_LIFETIME
;
602 range
->min_retry
= 1;
603 range
->max_retry
= 65535;
604 range
->min_r_time
= 1024;
605 range
->max_r_time
= 65535 * 1024;
606 // Experimental measurements - boundary 11/5.5 Mb/s
607 // Note : with or without the (local->rssi), results
608 // are somewhat different. - Jean II
609 range
->avg_qual
.qual
= 6;
610 range
->avg_qual
.level
= 176; // -80 dBm
611 range
->avg_qual
.noise
= 0;
618 * Wireless Handler : set ap mac address
620 int iwctl_siwap(struct net_device
*dev
, struct iw_request_info
*info
,
621 union iwreq_data
*wrqu
, char *extra
)
623 struct vnt_private
*pDevice
= netdev_priv(dev
);
624 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
625 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
627 u8 ZeroBSSID
[WLAN_BSSID_LEN
] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
629 PRINT_K(" SIOCSIWAP\n");
634 if (wrq
->sa_family
!= ARPHRD_ETHER
) {
637 memcpy(pMgmt
->abyDesireBSSID
, wrq
->sa_data
, 6);
639 if ((is_broadcast_ether_addr(pMgmt
->abyDesireBSSID
)) ||
640 (memcmp(pMgmt
->abyDesireBSSID
, ZeroBSSID
, 6) == 0)) {
641 PRINT_K("SIOCSIWAP:invalid desired BSSID return!\n");
644 // mike add: if desired AP is hidden ssid(there are
645 // two same BSSID in list), then ignore,because you
646 // don't known which one to be connect with??
649 unsigned uSameBssidNum
= 0;
650 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
651 if (pMgmt
->sBSSList
[ii
].bActive
&&
652 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
653 pMgmt
->abyDesireBSSID
)) {
657 if (uSameBssidNum
>= 2) { //hit: desired AP is in hidden ssid mode!!!
658 PRINT_K("SIOCSIWAP:ignore for desired AP in hidden mode\n");
663 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
664 pDevice
->bCommit
= true;
670 * Wireless Handler: get ap mac address
672 int iwctl_giwap(struct net_device
*dev
, struct iw_request_info
*info
,
673 union iwreq_data
*wrqu
, char *extra
)
675 struct vnt_private
*pDevice
= netdev_priv(dev
);
676 struct sockaddr
*wrq
= &wrqu
->ap_addr
;
677 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
679 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAP\n");
684 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
686 if ((pDevice
->bLinkPass
== false) && (pMgmt
->eCurrMode
!= WMAC_MODE_ESS_AP
))
687 memset(wrq
->sa_data
, 0, 6);
689 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)
690 memcpy(wrq
->sa_data
, pMgmt
->abyCurrBSSID
, 6);
692 wrq
->sa_family
= ARPHRD_ETHER
;
697 * Wireless Handler: get ap list
699 int iwctl_giwaplist(struct net_device
*dev
, struct iw_request_info
*info
,
700 union iwreq_data
*wrqu
, char *extra
)
702 struct iw_point
*wrq
= &wrqu
->data
;
703 struct sockaddr
*sock
;
704 struct iw_quality
*qual
;
705 struct vnt_private
*pDevice
= netdev_priv(dev
);
706 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
707 PKnownBSS pBSS
= &pMgmt
->sBSSList
[0];
711 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWAPLIST\n");
712 /* Only super-user can see AP list */
717 if (!capable(CAP_NET_ADMIN
))
723 sock
= kcalloc(IW_MAX_AP
, sizeof(struct sockaddr
), GFP_KERNEL
);
726 qual
= kcalloc(IW_MAX_AP
, sizeof(struct iw_quality
), GFP_KERNEL
);
732 for (ii
= 0, jj
= 0; ii
< MAX_BSS_NUM
; ii
++) {
733 if (!pBSS
[ii
].bActive
)
737 memcpy(sock
[jj
].sa_data
, pBSS
[ii
].abyBSSID
, 6);
738 sock
[jj
].sa_family
= ARPHRD_ETHER
;
739 qual
[jj
].level
= pBSS
[ii
].uRSSI
;
740 qual
[jj
].qual
= qual
[jj
].noise
= 0;
741 qual
[jj
].updated
= 2;
745 wrq
->flags
= 1; /* Should be defined */
747 memcpy(extra
, sock
, sizeof(struct sockaddr
) * jj
);
748 memcpy(extra
+ sizeof(struct sockaddr
) * jj
, qual
,
749 sizeof(struct iw_quality
) * jj
);
758 * Wireless Handler: set essid
760 int iwctl_siwessid(struct net_device
*dev
, struct iw_request_info
*info
,
761 union iwreq_data
*wrqu
, char *extra
)
763 struct vnt_private
*pDevice
= netdev_priv(dev
);
764 struct iw_point
*wrq
= &wrqu
->essid
;
765 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
766 PWLAN_IE_SSID pItemSSID
;
771 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
774 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWESSID :\n");
776 pDevice
->fWPA_Authened
= false;
777 // Check if we asked for `any'
778 if (wrq
->flags
== 0) {
779 // Just send an empty SSID list
780 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
781 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
782 PRINT_K("set essid to 'any'\n");
783 // Unknown desired AP, so here need not associate??
787 memset(pMgmt
->abyDesireSSID
, 0, WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1);
788 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyDesireSSID
;
789 pItemSSID
->byElementID
= WLAN_EID_SSID
;
791 memcpy(pItemSSID
->abySSID
, extra
, wrq
->length
);
792 if (pItemSSID
->abySSID
[wrq
->length
] == '\0') {
794 pItemSSID
->len
= wrq
->length
;
796 pItemSSID
->len
= wrq
->length
;
798 PRINT_K("set essid to %s\n", pItemSSID
->abySSID
);
800 // mike: need clear desiredBSSID
801 if (pItemSSID
->len
== 0) {
802 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
806 // Wext wil order another command of siwap to link
807 // with desired AP, so here need not associate??
808 if (pDevice
->bWPASuppWextEnabled
== true) {
809 /*******search if in hidden ssid mode ****/
810 PKnownBSS pCurr
= NULL
;
811 u8 abyTmpDesireSSID
[WLAN_IEHDR_LEN
+ WLAN_SSID_MAXLEN
+ 1];
813 unsigned uSameBssidNum
= 0;
815 memcpy(abyTmpDesireSSID
, pMgmt
->abyDesireSSID
, sizeof(abyTmpDesireSSID
));
816 pCurr
= BSSpSearchBSSList(pDevice
, NULL
,
818 pDevice
->eConfigPHYMode
);
821 PRINT_K("SIOCSIWESSID:hidden ssid site survey before associate.......\n");
822 vResetCommandTimer((void *)pDevice
);
823 pMgmt
->eScanType
= WMAC_SCAN_ACTIVE
;
824 bScheduleCommand((void *)pDevice
,
826 pMgmt
->abyDesireSSID
);
827 bScheduleCommand((void *)pDevice
,
829 pMgmt
->abyDesireSSID
);
830 } else { // mike: to find out if that desired SSID is a
831 // hidden-ssid AP, by means of judging if there
832 // are two same BSSID exist in list ?
833 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
834 if (pMgmt
->sBSSList
[ii
].bActive
&&
835 ether_addr_equal(pMgmt
->sBSSList
[ii
].abyBSSID
,
840 if (uSameBssidNum
>= 2) { // hit: desired AP is in hidden ssid mode!!!
841 PRINT_K("SIOCSIWESSID:hidden ssid directly associate.......\n");
842 vResetCommandTimer((void *)pDevice
);
843 pMgmt
->eScanType
= WMAC_SCAN_PASSIVE
; // this scan type, you'll submit scan result!
844 bScheduleCommand((void *)pDevice
,
846 pMgmt
->abyDesireSSID
);
847 bScheduleCommand((void *)pDevice
,
849 pMgmt
->abyDesireSSID
);
855 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"set essid = %s\n", pItemSSID
->abySSID
);
858 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
)
859 pDevice
->bCommit
= true;
865 * Wireless Handler: get essid
867 int iwctl_giwessid(struct net_device
*dev
, struct iw_request_info
*info
,
868 union iwreq_data
*wrqu
, char *extra
)
870 struct vnt_private
*pDevice
= netdev_priv(dev
);
871 struct iw_point
*wrq
= &wrqu
->essid
;
872 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
873 PWLAN_IE_SSID pItemSSID
;
875 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWESSID\n");
880 // Note: if wrq->u.data.flags != 0, we should get the relevant
881 // SSID from the SSID list...
883 // Get the current SSID
884 pItemSSID
= (PWLAN_IE_SSID
)pMgmt
->abyCurrSSID
;
885 memcpy(extra
, pItemSSID
->abySSID
, pItemSSID
->len
);
886 extra
[pItemSSID
->len
] = '\0';
888 wrq
->length
= pItemSSID
->len
;
889 wrq
->flags
= 1; // active
895 * Wireless Handler: set data rate
897 int iwctl_siwrate(struct net_device
*dev
, struct iw_request_info
*info
,
898 union iwreq_data
*wrqu
, char *extra
)
900 struct vnt_private
*pDevice
= netdev_priv(dev
);
901 struct iw_param
*wrq
= &wrqu
->bitrate
;
905 u8 abySupportedRates
[13] = {
906 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30, 0x48,
910 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRATE\n");
911 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
916 // First: get a valid bit rate value
918 // Which type of value
919 if ((wrq
->value
< 13) && (wrq
->value
>= 0)) {
920 // Setting by rate index
921 // Find value in the magic rate table
924 // Setting by frequency value
925 u8 normvalue
= (u8
)(wrq
->value
/500000);
927 // Check if rate is valid
928 for (i
= 0; i
< 13; i
++) {
929 if (normvalue
== abySupportedRates
[i
]) {
935 // -1 designed the max rate (mostly auto mode)
936 if (wrq
->value
== -1) {
937 // Get the highest available rate
938 for (i
= 0; i
< 13; i
++) {
939 if (abySupportedRates
[i
] == 0)
946 // Check that it is valid
947 // brate is index of abySupportedRates[]
953 // Now, check if we want a fixed or auto value
954 if (wrq
->fixed
!= 0) {
957 pDevice
->bFixRate
= true;
958 if ((pDevice
->byBBType
== BB_TYPE_11B
) && (brate
> 3)) {
959 pDevice
->uConnectionRate
= 3;
961 pDevice
->uConnectionRate
= brate
;
962 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Fixed to Rate %d\n", pDevice
->uConnectionRate
);
965 pDevice
->bFixRate
= false;
966 pDevice
->uConnectionRate
= 13;
973 * Wireless Handler: get data rate
975 int iwctl_giwrate(struct net_device
*dev
, struct iw_request_info
*info
,
976 union iwreq_data
*wrqu
, char *extra
)
978 struct vnt_private
*pDevice
= netdev_priv(dev
);
979 struct iw_param
*wrq
= &wrqu
->bitrate
;
980 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
982 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRATE\n");
988 u8 abySupportedRates
[13] = {
989 0x02, 0x04, 0x0B, 0x16, 0x0c, 0x12, 0x18, 0x24, 0x30,
990 0x48, 0x60, 0x6C, 0x90
994 if (pDevice
->uConnectionRate
< 13) {
995 brate
= abySupportedRates
[pDevice
->uConnectionRate
];
997 if (pDevice
->byBBType
== BB_TYPE_11B
)
999 if (pDevice
->byBBType
== BB_TYPE_11G
)
1001 if (pDevice
->byBBType
== BB_TYPE_11A
)
1004 if (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
) {
1005 if (pDevice
->byBBType
== BB_TYPE_11B
)
1007 if (pDevice
->byBBType
== BB_TYPE_11G
)
1009 if (pDevice
->byBBType
== BB_TYPE_11A
)
1012 if (pDevice
->uConnectionRate
== 13)
1013 brate
= abySupportedRates
[pDevice
->wCurrentRate
];
1014 wrq
->value
= brate
* 500000;
1015 // If more than one rate, set auto
1016 if (pDevice
->bFixRate
== true)
1024 * Wireless Handler: set rts threshold
1026 int iwctl_siwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1027 union iwreq_data
*wrqu
, char *extra
)
1029 struct vnt_private
*pDevice
= netdev_priv(dev
);
1030 struct iw_param
*wrq
= &wrqu
->rts
;
1032 if ((wrq
->value
< 0 || wrq
->value
> 2312) && !wrq
->disabled
)
1035 else if (wrq
->disabled
)
1036 pDevice
->wRTSThreshold
= 2312;
1038 pDevice
->wRTSThreshold
= wrq
->value
;
1044 * Wireless Handler: get rts
1046 int iwctl_giwrts(struct net_device
*dev
, struct iw_request_info
*info
,
1047 union iwreq_data
*wrqu
, char *extra
)
1049 struct vnt_private
*pDevice
= netdev_priv(dev
);
1050 struct iw_param
*wrq
= &wrqu
->rts
;
1052 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRTS\n");
1053 wrq
->value
= pDevice
->wRTSThreshold
;
1054 wrq
->disabled
= (wrq
->value
>= 2312);
1060 * Wireless Handler: set fragment threshold
1062 int iwctl_siwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1063 union iwreq_data
*wrqu
, char *extra
)
1065 struct vnt_private
*pDevice
= netdev_priv(dev
);
1066 struct iw_param
*wrq
= &wrqu
->frag
;
1068 int fthr
= wrq
->value
;
1070 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWFRAG\n");
1074 if ((fthr
< 256) || (fthr
> 2312)) {
1077 fthr
&= ~0x1; // Get an even value
1078 pDevice
->wFragmentationThreshold
= (u16
)fthr
;
1084 * Wireless Handler: get fragment threshold
1086 int iwctl_giwfrag(struct net_device
*dev
, struct iw_request_info
*info
,
1087 union iwreq_data
*wrqu
, char *extra
)
1089 struct vnt_private
*pDevice
= netdev_priv(dev
);
1090 struct iw_param
*wrq
= &wrqu
->frag
;
1092 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWFRAG\n");
1093 wrq
->value
= pDevice
->wFragmentationThreshold
;
1094 wrq
->disabled
= (wrq
->value
>= 2312);
1100 * Wireless Handler: set retry threshold
1102 int iwctl_siwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1103 union iwreq_data
*wrqu
, char *extra
)
1105 struct vnt_private
*pDevice
= netdev_priv(dev
);
1106 struct iw_param
*wrq
= &wrqu
->retry
;
1109 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWRETRY\n");
1111 if (wrq
->disabled
) {
1116 if (wrq
->flags
& IW_RETRY_LIMIT
) {
1117 if (wrq
->flags
& IW_RETRY_MAX
) {
1118 pDevice
->byLongRetryLimit
= wrq
->value
;
1119 } else if (wrq
->flags
& IW_RETRY_MIN
) {
1120 pDevice
->byShortRetryLimit
= wrq
->value
;
1122 // No modifier : set both
1123 pDevice
->byShortRetryLimit
= wrq
->value
;
1124 pDevice
->byLongRetryLimit
= wrq
->value
;
1127 if (wrq
->flags
& IW_RETRY_LIFETIME
)
1128 pDevice
->wMaxTransmitMSDULifetime
= wrq
->value
;
1133 * Wireless Handler: get retry threshold
1135 int iwctl_giwretry(struct net_device
*dev
, struct iw_request_info
*info
,
1136 union iwreq_data
*wrqu
, char *extra
)
1138 struct vnt_private
*pDevice
= netdev_priv(dev
);
1139 struct iw_param
*wrq
= &wrqu
->retry
;
1140 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWRETRY\n");
1141 wrq
->disabled
= 0; // Can't be disabled
1143 // Note: by default, display the min retry number
1144 if ((wrq
->flags
& IW_RETRY_TYPE
) == IW_RETRY_LIFETIME
) {
1145 wrq
->flags
= IW_RETRY_LIFETIME
;
1146 wrq
->value
= (int)pDevice
->wMaxTransmitMSDULifetime
; // ms
1147 } else if ((wrq
->flags
& IW_RETRY_MAX
)) {
1148 wrq
->flags
= IW_RETRY_LIMIT
| IW_RETRY_MAX
;
1149 wrq
->value
= (int)pDevice
->byLongRetryLimit
;
1151 wrq
->flags
= IW_RETRY_LIMIT
;
1152 wrq
->value
= (int)pDevice
->byShortRetryLimit
;
1153 if ((int)pDevice
->byShortRetryLimit
!= (int)pDevice
->byLongRetryLimit
)
1154 wrq
->flags
|= IW_RETRY_MIN
;
1160 * Wireless Handler: set encode mode
1162 int iwctl_siwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1163 union iwreq_data
*wrqu
, char *extra
)
1165 struct vnt_private
*pDevice
= netdev_priv(dev
);
1166 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1167 struct iw_point
*wrq
= &wrqu
->encoding
;
1168 u32 dwKeyIndex
= (u32
)(wrq
->flags
& IW_ENCODE_INDEX
);
1172 int index
= (wrq
->flags
& IW_ENCODE_INDEX
);
1174 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWENCODE\n");
1179 // Check the size of the key
1180 if (wrq
->length
> WLAN_WEP232_KEYLEN
) {
1185 if (dwKeyIndex
> WLAN_WEP_NKEYS
) {
1193 // Send the key to the card
1194 if (wrq
->length
> 0) {
1195 if (wrq
->length
== WLAN_WEP232_KEYLEN
) {
1196 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 232 bit wep key\n");
1197 } else if (wrq
->length
== WLAN_WEP104_KEYLEN
) {
1198 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 104 bit wep key\n");
1199 } else if (wrq
->length
== WLAN_WEP40_KEYLEN
) {
1200 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Set 40 bit wep key, index= %d\n", (int)dwKeyIndex
);
1202 memset(pDevice
->abyKey
, 0, WLAN_WEP232_KEYLEN
);
1203 memcpy(pDevice
->abyKey
, extra
, wrq
->length
);
1205 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"abyKey: ");
1206 for (ii
= 0; ii
< wrq
->length
; ii
++)
1207 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"%02x ", pDevice
->abyKey
[ii
]);
1209 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1210 KeybSetDefaultKey(pDevice
,
1212 dwKeyIndex
| (1 << 31),
1217 pDevice
->byKeyIndex
= (u8
)dwKeyIndex
;
1218 pDevice
->uKeyLength
= wrq
->length
;
1219 pDevice
->bTransmitKey
= true;
1220 pDevice
->bEncryptionEnable
= true;
1221 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1223 // Do we want to just set the transmit key index?
1225 pDevice
->byKeyIndex
= index
;
1226 } else if (!(wrq
->flags
& IW_ENCODE_MODE
)) {
1232 if (wrq
->flags
& IW_ENCODE_DISABLED
) {
1233 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Disable WEP function\n");
1234 pMgmt
->bShareKeyAlgorithm
= false;
1235 pDevice
->bEncryptionEnable
= false;
1236 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1237 if (pDevice
->flags
& DEVICE_FLAGS_OPENED
) {
1238 for (uu
= 0; uu
< MAX_KEY_TABLE
; uu
++)
1239 MACvDisableKeyEntry(pDevice
, uu
);
1242 if (wrq
->flags
& IW_ENCODE_RESTRICTED
) {
1243 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & ShareKey System\n");
1244 pMgmt
->bShareKeyAlgorithm
= true;
1246 if (wrq
->flags
& IW_ENCODE_OPEN
) {
1247 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Enable WEP & Open System\n");
1248 pMgmt
->bShareKeyAlgorithm
= false;
1251 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1256 int iwctl_giwencode(struct net_device
*dev
, struct iw_request_info
*info
,
1257 union iwreq_data
*wrqu
, char *extra
)
1259 struct vnt_private
*pDevice
= netdev_priv(dev
);
1260 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1261 struct iw_point
*wrq
= &wrqu
->encoding
;
1262 char abyKey
[WLAN_WEP232_KEYLEN
];
1264 unsigned index
= (unsigned)(wrq
->flags
& IW_ENCODE_INDEX
);
1265 PSKeyItem pKey
= NULL
;
1267 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWENCODE\n");
1272 if (index
> WLAN_WEP_NKEYS
)
1274 if (index
< 1) { // get default key
1275 if (pDevice
->byKeyIndex
< WLAN_WEP_NKEYS
)
1276 index
= pDevice
->byKeyIndex
;
1283 memset(abyKey
, 0, WLAN_WEP232_KEYLEN
);
1284 // Check encryption mode
1285 wrq
->flags
= IW_ENCODE_NOKEY
;
1286 // Is WEP enabled ???
1287 if (pDevice
->bEncryptionEnable
)
1288 wrq
->flags
|= IW_ENCODE_ENABLED
;
1290 wrq
->flags
|= IW_ENCODE_DISABLED
;
1292 if (pMgmt
->bShareKeyAlgorithm
)
1293 wrq
->flags
|= IW_ENCODE_RESTRICTED
;
1295 wrq
->flags
|= IW_ENCODE_OPEN
;
1298 if ((index
== 0) && (pDevice
->eEncryptionStatus
== Ndis802_11Encryption2Enabled
||
1299 pDevice
->eEncryptionStatus
== Ndis802_11Encryption3Enabled
)) { // get wpa pairwise key
1300 if (KeybGetKey(&(pDevice
->sKey
), pMgmt
->abyCurrBSSID
, 0xffffffff, &pKey
)) {
1301 wrq
->length
= pKey
->uKeyLength
;
1302 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1303 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1305 } else if (KeybGetKey(&(pDevice
->sKey
), pDevice
->abyBroadcastAddr
, (u8
)index
, &pKey
)) {
1306 wrq
->length
= pKey
->uKeyLength
;
1307 memcpy(abyKey
, pKey
->abyKey
, pKey
->uKeyLength
);
1308 memcpy(extra
, abyKey
, WLAN_WEP232_KEYLEN
);
1311 wrq
->flags
|= index
+ 1;
1316 * Wireless Handler: set power mode
1318 int iwctl_siwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1319 union iwreq_data
*wrqu
, char *extra
)
1321 struct vnt_private
*pDevice
= netdev_priv(dev
);
1322 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1323 struct iw_param
*wrq
= &wrqu
->power
;
1326 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER\n");
1331 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
)) {
1336 if (wrq
->disabled
) {
1337 pDevice
->ePSMode
= WMAC_POWER_CAM
;
1338 PSvDisablePowerSaving(pDevice
);
1341 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1342 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1343 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1345 } else if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_PERIOD
) {
1346 pDevice
->ePSMode
= WMAC_POWER_FAST
;
1347 PSvEnablePowerSaving((void *)pDevice
, pMgmt
->wListenInterval
);
1350 switch (wrq
->flags
& IW_POWER_MODE
) {
1351 case IW_POWER_UNICAST_R
:
1352 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_UNICAST_R\n");
1355 case IW_POWER_ALL_R
:
1356 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ALL_R\n");
1359 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWPOWER: IW_POWER_ON\n");
1369 * Wireless Handler: get power mode
1371 int iwctl_giwpower(struct net_device
*dev
, struct iw_request_info
*info
,
1372 union iwreq_data
*wrqu
, char *extra
)
1374 struct vnt_private
*pDevice
= netdev_priv(dev
);
1375 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1376 struct iw_param
*wrq
= &wrqu
->power
;
1377 int mode
= pDevice
->ePSMode
;
1379 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWPOWER\n");
1384 wrq
->disabled
= (mode
== WMAC_POWER_CAM
);
1388 if ((wrq
->flags
& IW_POWER_TYPE
) == IW_POWER_TIMEOUT
) {
1389 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1390 pMgmt
->wCurrBeaconPeriod
) / 100);
1391 wrq
->flags
= IW_POWER_TIMEOUT
;
1393 wrq
->value
= (int)((pMgmt
->wListenInterval
*
1394 pMgmt
->wCurrBeaconPeriod
) / 100);
1395 wrq
->flags
= IW_POWER_PERIOD
;
1398 wrq
->flags
|= IW_POWER_ALL_R
;
1403 * Wireless Handler: get Sensitivity
1405 int iwctl_giwsens(struct net_device
*dev
, struct iw_request_info
*info
,
1406 union iwreq_data
*wrqu
, char *extra
)
1408 struct vnt_private
*pDevice
= netdev_priv(dev
);
1409 struct iw_param
*wrq
= &wrqu
->sens
;
1412 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCGIWSENS\n");
1413 if (pDevice
->bLinkPass
== true) {
1414 RFvRSSITodBm(pDevice
, (u8
)(pDevice
->uCurrRSSI
), &ldBm
);
1419 wrq
->disabled
= (wrq
->value
== 0);
1424 int iwctl_siwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1425 union iwreq_data
*wrqu
, char *extra
)
1427 struct vnt_private
*pDevice
= netdev_priv(dev
);
1428 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1429 struct iw_param
*wrq
= &wrqu
->param
;
1431 static int wpa_version
= 0; // must be static to save the last value, einsn liu
1432 static int pairwise
= 0;
1437 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWAUTH\n");
1438 switch (wrq
->flags
& IW_AUTH_INDEX
) {
1439 case IW_AUTH_WPA_VERSION
:
1440 wpa_version
= wrq
->value
;
1441 if (wrq
->value
== IW_AUTH_WPA_VERSION_DISABLED
) {
1442 PRINT_K("iwctl_siwauth:set WPADEV to disable at 1??????\n");
1443 } else if (wrq
->value
== IW_AUTH_WPA_VERSION_WPA
) {
1444 PRINT_K("iwctl_siwauth:set WPADEV to WPA1******\n");
1446 PRINT_K("iwctl_siwauth:set WPADEV to WPA2******\n");
1449 case IW_AUTH_CIPHER_PAIRWISE
:
1450 pairwise
= wrq
->value
;
1451 PRINT_K("iwctl_siwauth:set pairwise=%d\n", pairwise
);
1452 if (pairwise
== IW_AUTH_CIPHER_CCMP
) {
1453 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1454 } else if (pairwise
== IW_AUTH_CIPHER_TKIP
) {
1455 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1456 } else if (pairwise
== IW_AUTH_CIPHER_WEP40
||
1457 pairwise
== IW_AUTH_CIPHER_WEP104
) {
1458 pDevice
->eEncryptionStatus
= Ndis802_11Encryption1Enabled
;
1459 } else if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1460 // do nothing, einsn liu
1462 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1465 case IW_AUTH_CIPHER_GROUP
:
1466 PRINT_K("iwctl_siwauth:set GROUP=%d\n", wrq
->value
);
1467 if (wpa_version
== IW_AUTH_WPA_VERSION_DISABLED
)
1469 if (pairwise
== IW_AUTH_CIPHER_NONE
) {
1470 if (wrq
->value
== IW_AUTH_CIPHER_CCMP
)
1471 pDevice
->eEncryptionStatus
= Ndis802_11Encryption3Enabled
;
1473 pDevice
->eEncryptionStatus
= Ndis802_11Encryption2Enabled
;
1476 case IW_AUTH_KEY_MGMT
:
1477 PRINT_K("iwctl_siwauth(wpa_version=%d):set KEY_MGMT=%d\n", wpa_version
, wrq
->value
);
1478 if (wpa_version
== IW_AUTH_WPA_VERSION_WPA2
) {
1479 if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1480 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2PSK
;
1481 else pMgmt
->eAuthenMode
= WMAC_AUTH_WPA2
;
1482 } else if (wpa_version
== IW_AUTH_WPA_VERSION_WPA
) {
1483 if (wrq
->value
== 0) {
1484 pMgmt
->eAuthenMode
= WMAC_AUTH_WPANONE
;
1485 } else if (wrq
->value
== IW_AUTH_KEY_MGMT_PSK
)
1486 pMgmt
->eAuthenMode
= WMAC_AUTH_WPAPSK
;
1488 pMgmt
->eAuthenMode
= WMAC_AUTH_WPA
;
1491 case IW_AUTH_TKIP_COUNTERMEASURES
:
1493 case IW_AUTH_DROP_UNENCRYPTED
:
1495 case IW_AUTH_80211_AUTH_ALG
:
1496 PRINT_K("iwctl_siwauth:set AUTH_ALG=%d\n", wrq
->value
);
1497 if (wrq
->value
== IW_AUTH_ALG_OPEN_SYSTEM
)
1498 pMgmt
->bShareKeyAlgorithm
= false;
1499 else if (wrq
->value
== IW_AUTH_ALG_SHARED_KEY
)
1500 pMgmt
->bShareKeyAlgorithm
= true;
1502 case IW_AUTH_WPA_ENABLED
:
1504 case IW_AUTH_RX_UNENCRYPTED_EAPOL
:
1506 case IW_AUTH_ROAMING_CONTROL
:
1509 case IW_AUTH_PRIVACY_INVOKED
:
1510 pDevice
->bEncryptionEnable
= !!wrq
->value
;
1511 if (pDevice
->bEncryptionEnable
== false) {
1514 pDevice
->eEncryptionStatus
= Ndis802_11EncryptionDisabled
;
1515 pMgmt
->bShareKeyAlgorithm
= false;
1516 pMgmt
->eAuthenMode
= WMAC_AUTH_OPEN
;
1517 PRINT_K("iwctl_siwauth:set WPADEV to disaable at 2?????\n");
1521 PRINT_K("iwctl_siwauth: not supported %x\n", wrq
->flags
);
1528 int iwctl_giwauth(struct net_device
*dev
, struct iw_request_info
*info
,
1529 union iwreq_data
*wrqu
, char *extra
)
1534 int iwctl_siwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1535 union iwreq_data
*wrqu
, char *extra
)
1537 struct vnt_private
*pDevice
= netdev_priv(dev
);
1538 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1539 struct iw_point
*wrq
= &wrqu
->data
;
1546 if ((wrq
->length
< 2) || (extra
[1] + 2 != wrq
->length
)) {
1550 if (wrq
->length
> MAX_WPA_IE_LEN
) {
1554 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1556 memcpy(pMgmt
->abyWPAIE
, extra
, wrq
->length
);
1557 pMgmt
->wWPAIELen
= wrq
->length
;
1559 memset(pMgmt
->abyWPAIE
, 0, MAX_WPA_IE_LEN
);
1560 pMgmt
->wWPAIELen
= 0;
1563 out
: // not completely ...not necessary in wpa_supplicant 0.5.8
1567 int iwctl_giwgenie(struct net_device
*dev
, struct iw_request_info
*info
,
1568 union iwreq_data
*wrqu
, char *extra
)
1570 struct vnt_private
*pDevice
= netdev_priv(dev
);
1571 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1572 struct iw_point
*wrq
= &wrqu
->data
;
1574 int space
= wrq
->length
;
1580 if (pMgmt
->wWPAIELen
> 0) {
1581 wrq
->length
= pMgmt
->wWPAIELen
;
1583 if (pMgmt
->wWPAIELen
<= space
)
1584 memcpy(extra
, pMgmt
->abyWPAIE
, pMgmt
->wWPAIELen
);
1591 int iwctl_siwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1592 union iwreq_data
*wrqu
, char *extra
)
1594 struct vnt_private
*pDevice
= netdev_priv(dev
);
1595 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1596 struct iw_point
*wrq
= &wrqu
->encoding
;
1597 struct iw_encode_ext
*ext
= (struct iw_encode_ext
*)extra
;
1598 struct viawget_wpa_param
*param
= NULL
;
1604 u8 seq
[IW_ENCODE_SEQ_MAX_SIZE
];
1612 PRINT_K("SIOCSIWENCODEEXT......\n");
1617 if (!(pDevice
->flags
& DEVICE_FLAGS_OPENED
))
1620 buf
= kzalloc(sizeof(struct viawget_wpa_param
), GFP_KERNEL
);
1624 param
= (struct viawget_wpa_param
*)buf
;
1628 case IW_ENCODE_ALG_NONE
:
1629 alg_name
= WPA_ALG_NONE
;
1631 case IW_ENCODE_ALG_WEP
:
1632 alg_name
= WPA_ALG_WEP
;
1634 case IW_ENCODE_ALG_TKIP
:
1635 alg_name
= WPA_ALG_TKIP
;
1637 case IW_ENCODE_ALG_CCMP
:
1638 alg_name
= WPA_ALG_CCMP
;
1641 PRINT_K("Unknown alg = %d\n", ext
->alg
);
1646 memcpy(addr
, ext
->addr
.sa_data
, ETH_ALEN
);
1648 key_idx
= (wrq
->flags
&IW_ENCODE_INDEX
) - 1;
1650 if (ext
->ext_flags
& IW_ENCODE_EXT_SET_TX_KEY
)
1652 // recover seq,seq_len
1653 if (ext
->ext_flags
& IW_ENCODE_EXT_RX_SEQ_VALID
) {
1654 seq_len
= IW_ENCODE_SEQ_MAX_SIZE
;
1655 memcpy(seq
, ext
->rx_seq
, seq_len
);
1657 // recover key,key_len
1659 key_len
= ext
->key_len
;
1660 memcpy(key
, &ext
->key
[0], key_len
);
1662 memset(key_array
, 0, 64);
1664 memcpy(key_array
, key
, key_len
);
1665 if (key_len
== 32) {
1666 // notice ! the oder
1667 memcpy(&key_array
[16], &key
[24], 8);
1668 memcpy(&key_array
[24], &key
[16], 8);
1672 /**************Translate iw_encode_ext to viawget_wpa_param****************/
1673 memcpy(param
->addr
, addr
, ETH_ALEN
);
1674 param
->u
.wpa_key
.alg_name
= (int)alg_name
;
1675 param
->u
.wpa_key
.set_tx
= set_tx
;
1676 param
->u
.wpa_key
.key_index
= key_idx
;
1677 param
->u
.wpa_key
.key_len
= key_len
;
1678 param
->u
.wpa_key
.key
= (u8
*)key_array
;
1679 param
->u
.wpa_key
.seq
= (u8
*)seq
;
1680 param
->u
.wpa_key
.seq_len
= seq_len
;
1682 /****set if current action is Network Manager count?? */
1683 /****this method is so foolish,but there is no other way??? */
1684 if (param
->u
.wpa_key
.alg_name
== WPA_ALG_NONE
) {
1685 if (param
->u
.wpa_key
.key_index
== 0) {
1686 pDevice
->bwextstep0
= true;
1688 if ((pDevice
->bwextstep0
== true) && (param
->u
.wpa_key
.key_index
== 1)) {
1689 pDevice
->bwextstep0
= false;
1690 pDevice
->bwextstep1
= true;
1692 if ((pDevice
->bwextstep1
== true) && (param
->u
.wpa_key
.key_index
== 2)) {
1693 pDevice
->bwextstep1
= false;
1694 pDevice
->bwextstep2
= true;
1696 if ((pDevice
->bwextstep2
== true) && (param
->u
.wpa_key
.key_index
== 3)) {
1697 pDevice
->bwextstep2
= false;
1698 pDevice
->bwextstep3
= true;
1701 if (pDevice
->bwextstep3
== true) {
1702 PRINT_K("SIOCSIWENCODEEXT:Enable WPA WEXT SUPPORT!!!!!\n");
1703 pDevice
->bwextstep0
= false;
1704 pDevice
->bwextstep1
= false;
1705 pDevice
->bwextstep2
= false;
1706 pDevice
->bwextstep3
= false;
1707 pDevice
->bWPASuppWextEnabled
= true;
1708 memset(pMgmt
->abyDesireBSSID
, 0xFF, 6);
1709 KeyvInitTable(pDevice
, &pDevice
->sKey
);
1712 ret
= wpa_set_keys(pDevice
, param
);
1719 int iwctl_giwencodeext(struct net_device
*dev
, struct iw_request_info
*info
,
1720 union iwreq_data
*wrqu
, char *extra
)
1725 int iwctl_siwmlme(struct net_device
*dev
, struct iw_request_info
*info
,
1726 union iwreq_data
*wrqu
, char *extra
)
1728 struct vnt_private
*pDevice
= netdev_priv(dev
);
1729 struct vnt_manager
*pMgmt
= &pDevice
->vnt_mgmt
;
1730 struct iw_mlme
*mlme
= (struct iw_mlme
*)extra
;
1733 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" SIOCSIWMLME\n");
1738 if (memcmp(pMgmt
->abyCurrBSSID
, mlme
->addr
.sa_data
, ETH_ALEN
)) {
1742 switch (mlme
->cmd
) {
1743 case IW_MLME_DEAUTH
:
1744 case IW_MLME_DISASSOC
:
1745 if (pDevice
->bLinkPass
== true) {
1746 PRINT_K("iwctl_siwmlme--->send DISASSOCIATE\n");
1747 bScheduleCommand((void *)pDevice
, WLAN_CMD_DISASSOCIATE
,
1757 static int iwctl_config_commit(struct net_device
*dev
,
1758 struct iw_request_info
*info
, union iwreq_data
*wrqu
, char *extra
)
1760 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"SIOCSIWCOMMIT\n");
1765 static const iw_handler iwctl_handler
[] = {
1766 IW_HANDLER(SIOCSIWCOMMIT
, iwctl_config_commit
),
1767 IW_HANDLER(SIOCGIWNAME
, iwctl_giwname
),
1768 IW_HANDLER(SIOCSIWFREQ
, iwctl_siwfreq
),
1769 IW_HANDLER(SIOCGIWFREQ
, iwctl_giwfreq
),
1770 IW_HANDLER(SIOCSIWMODE
, iwctl_siwmode
),
1771 IW_HANDLER(SIOCGIWMODE
, iwctl_giwmode
),
1772 IW_HANDLER(SIOCGIWSENS
, iwctl_giwsens
),
1773 IW_HANDLER(SIOCGIWRANGE
, iwctl_giwrange
),
1774 IW_HANDLER(SIOCSIWAP
, iwctl_siwap
),
1775 IW_HANDLER(SIOCGIWAP
, iwctl_giwap
),
1776 IW_HANDLER(SIOCSIWMLME
, iwctl_siwmlme
),
1777 IW_HANDLER(SIOCGIWAPLIST
, iwctl_giwaplist
),
1778 IW_HANDLER(SIOCSIWSCAN
, iwctl_siwscan
),
1779 IW_HANDLER(SIOCGIWSCAN
, iwctl_giwscan
),
1780 IW_HANDLER(SIOCSIWESSID
, iwctl_siwessid
),
1781 IW_HANDLER(SIOCGIWESSID
, iwctl_giwessid
),
1782 IW_HANDLER(SIOCSIWRATE
, iwctl_siwrate
),
1783 IW_HANDLER(SIOCGIWRATE
, iwctl_giwrate
),
1784 IW_HANDLER(SIOCSIWRTS
, iwctl_siwrts
),
1785 IW_HANDLER(SIOCGIWRTS
, iwctl_giwrts
),
1786 IW_HANDLER(SIOCSIWFRAG
, iwctl_siwfrag
),
1787 IW_HANDLER(SIOCGIWFRAG
, iwctl_giwfrag
),
1788 IW_HANDLER(SIOCSIWRETRY
, iwctl_siwretry
),
1789 IW_HANDLER(SIOCGIWRETRY
, iwctl_giwretry
),
1790 IW_HANDLER(SIOCSIWENCODE
, iwctl_siwencode
),
1791 IW_HANDLER(SIOCGIWENCODE
, iwctl_giwencode
),
1792 IW_HANDLER(SIOCSIWPOWER
, iwctl_siwpower
),
1793 IW_HANDLER(SIOCGIWPOWER
, iwctl_giwpower
),
1794 IW_HANDLER(SIOCSIWGENIE
, iwctl_siwgenie
),
1795 IW_HANDLER(SIOCGIWGENIE
, iwctl_giwgenie
),
1796 IW_HANDLER(SIOCSIWAUTH
, iwctl_siwauth
),
1797 IW_HANDLER(SIOCGIWAUTH
, iwctl_giwauth
),
1798 IW_HANDLER(SIOCSIWENCODEEXT
, iwctl_siwencodeext
),
1799 IW_HANDLER(SIOCGIWENCODEEXT
, iwctl_giwencodeext
)
1802 static const iw_handler iwctl_private_handler
[] = {
1803 NULL
, // SIOCIWFIRSTPRIV
1806 const struct iw_handler_def iwctl_handler_def
= {
1807 .get_wireless_stats
= &iwctl_get_wireless_stats
,
1808 .num_standard
= ARRAY_SIZE(iwctl_handler
),
1810 .num_private_args
= 0,
1811 .standard
= iwctl_handler
,
1813 .private_args
= NULL
,