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.
22 * Purpose: export functions for vntwifi lib
28 * Author: Yiching Chen
43 /*--------------------- Static Definitions -------------------------*/
44 //static int msglevel =MSG_LEVEL_DEBUG;
45 //static int msglevel =MSG_LEVEL_INFO;
47 /*--------------------- Static Classes ----------------------------*/
49 /*--------------------- Static Variables --------------------------*/
51 /*--------------------- Static Functions --------------------------*/
53 /*--------------------- Export Variables --------------------------*/
55 /*--------------------- Export Functions --------------------------*/
64 * pMgmtHandle - pointer to management object
65 * eOPMode - Opreation Mode
75 IN WMAC_CONFIG_MODE eOPMode
78 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
80 pMgmt
->eConfigMode
= eOPMode
;
91 * pMgmtHandle - pointer to management object
92 * wBeaconPeriod - Beacon Period
93 * wATIMWindow - ATIM window
94 * uChannel - channel number
102 VNTWIFIvSetIBSSParameter (
103 IN PVOID pMgmtHandle
,
104 IN WORD wBeaconPeriod
,
109 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
111 pMgmt
->wIBSSBeaconPeriod
= wBeaconPeriod
;
112 pMgmt
->wIBSSATIMWindow
= wATIMWindow
;
113 pMgmt
->uIBSSChannel
= uChannel
;
123 * pMgmtHandle - pointer to management object
127 * Return Value: current SSID pointer.
131 VNTWIFIpGetCurrentSSID (
135 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
136 return((PWLAN_IE_SSID
) pMgmt
->abyCurrSSID
);
142 * Get current link channel
146 * pMgmtHandle - pointer to management object
150 * Return Value: current Channel.
154 VNTWIFIpGetCurrentChannel (
158 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
159 if (pMgmtHandle
!= NULL
) {
160 return (pMgmt
->uCurrChannel
);
168 * Get current Assoc ID
172 * pMgmtHandle - pointer to management object
176 * Return Value: current Assoc ID
184 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
185 return(pMgmt
->wCurrAID
);
193 * This routine return max support rate of IES
202 * Return Value: max support rate
206 VNTWIFIbyGetMaxSupportRate (
207 IN PWLAN_IE_SUPP_RATES pSupportRateIEs
,
208 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
211 BYTE byMaxSupportRate
= RATE_1M
;
212 BYTE bySupportRate
= RATE_1M
;
215 if (pSupportRateIEs
) {
216 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
217 bySupportRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
218 if (bySupportRate
> byMaxSupportRate
) {
219 byMaxSupportRate
= bySupportRate
;
223 if (pExtSupportRateIEs
) {
224 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
225 bySupportRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
226 if (bySupportRate
> byMaxSupportRate
) {
227 byMaxSupportRate
= bySupportRate
;
232 return byMaxSupportRate
;
238 * This routine return data rate of ACK packtet
248 * Return Value: max support rate
252 VNTWIFIbyGetACKTxRate (
253 IN BYTE byRxDataRate
,
254 IN PWLAN_IE_SUPP_RATES pSupportRateIEs
,
255 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
262 if (byRxDataRate
<= RATE_11M
) {
263 byMaxAckRate
= RATE_1M
;
265 // 24M is mandatory for 802.11a and 802.11g
266 byMaxAckRate
= RATE_24M
;
268 if (pSupportRateIEs
) {
269 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
270 if (pSupportRateIEs
->abyRates
[ii
] & 0x80) {
271 byBasicRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
272 if ((byBasicRate
<= byRxDataRate
) &&
273 (byBasicRate
> byMaxAckRate
)) {
274 byMaxAckRate
= byBasicRate
;
279 if (pExtSupportRateIEs
) {
280 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
281 if (pExtSupportRateIEs
->abyRates
[ii
] & 0x80) {
282 byBasicRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
283 if ((byBasicRate
<= byRxDataRate
) &&
284 (byBasicRate
> byMaxAckRate
)) {
285 byMaxAckRate
= byBasicRate
;
297 * Set Authentication Mode
301 * pMgmtHandle - pointer to management object
302 * eAuthMode - Authentication mode
310 VNTWIFIvSetAuthenticationMode (
311 IN PVOID pMgmtHandle
,
312 IN WMAC_AUTHENTICATION_MODE eAuthMode
315 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
317 pMgmt
->eAuthenMode
= eAuthMode
;
318 if ((eAuthMode
== WMAC_AUTH_SHAREKEY
) ||
319 (eAuthMode
== WMAC_AUTH_AUTO
)) {
320 pMgmt
->bShareKeyAlgorithm
= TRUE
;
322 pMgmt
->bShareKeyAlgorithm
= FALSE
;
329 * Set Encryption Mode
333 * pMgmtHandle - pointer to management object
334 * eAuthMode - Authentication mode
342 VNTWIFIvSetEncryptionMode (
343 IN PVOID pMgmtHandle
,
344 IN WMAC_ENCRYPTION_MODE eEncryptionMode
347 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
349 pMgmt
->eEncryptionMode
= eEncryptionMode
;
350 if ((eEncryptionMode
== WMAC_ENCRYPTION_WEPEnabled
) ||
351 (eEncryptionMode
== WMAC_ENCRYPTION_TKIPEnabled
) ||
352 (eEncryptionMode
== WMAC_ENCRYPTION_AESEnabled
) ) {
353 pMgmt
->bPrivacyInvoked
= TRUE
;
355 pMgmt
->bPrivacyInvoked
= FALSE
;
362 VNTWIFIbConfigPhyMode (
363 IN PVOID pMgmtHandle
,
364 IN CARD_PHY_TYPE ePhyType
367 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
369 if ((ePhyType
!= PHY_TYPE_AUTO
) &&
370 (ePhyType
!= pMgmt
->eCurrentPHYMode
)) {
371 if (CARDbSetPhyParameter(pMgmt
->pAdapter
, ePhyType
, 0, 0, NULL
, NULL
)==TRUE
) {
372 pMgmt
->eCurrentPHYMode
= ePhyType
;
377 pMgmt
->eConfigPHYMode
= ePhyType
;
383 VNTWIFIbGetConfigPhyMode (
384 IN PVOID pMgmtHandle
,
388 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
390 if ((pMgmt
!= NULL
) && (pePhyType
!= NULL
)) {
391 *(PCARD_PHY_TYPE
)pePhyType
= pMgmt
->eConfigPHYMode
;
398 * Clear BSS List Database except current assoc BSS
402 * pMgmtHandle - Management Object structure
403 * bLinkPass - Current Link status
406 * Return Value: None.
414 * Query BSS List in management database
418 * pMgmtHandle - Management Object structure
420 * puBSSCount - BSS count
421 * pvFirstBSS - pointer to first BSS
423 * Return Value: None.
428 VNTWIFIvQueryBSSList (
429 IN PVOID pMgmtHandle
,
430 OUT PUINT puBSSCount
,
431 OUT PVOID
*pvFirstBSS
435 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
436 PKnownBSS pBSS
= NULL
;
441 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
442 pBSS
= &(pMgmt
->sBSSList
[ii
]);
443 if (!pBSS
->bActive
) {
446 if (*pvFirstBSS
== NULL
) {
447 *pvFirstBSS
= &(pMgmt
->sBSSList
[ii
]);
451 *puBSSCount
= uCount
;
459 IN PVOID pMgmtHandle
,
460 IN PVOID pvCurrentBSS
,
464 PKnownBSS pBSS
= (PKnownBSS
) pvCurrentBSS
;
465 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
469 while (*pvNextBSS
== NULL
) {
471 if (pBSS
> &(pMgmt
->sBSSList
[MAX_BSS_NUM
])) {
474 if (pBSS
->bActive
== TRUE
) {
488 * Update Tx attemps, Tx failure counter in Node DB
498 VNTWIFIvUpdateNodeTxCounter(
499 IN PVOID pMgmtHandle
,
500 IN PBYTE pbyDestAddress
,
503 IN PBYTE pbyTxFailCount
506 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
510 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
511 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
512 if (BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
) == FALSE
) {
516 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxAttempts
++;
518 // transmit success, TxAttempts at least plus one
519 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[MAX_RATE
]++;
520 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[wRate
]++;
522 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFailures
++;
524 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxRetry
+= pbyTxFailCount
[MAX_RATE
];
525 for(ii
=0;ii
<MAX_RATE
;ii
++) {
526 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[ii
] += pbyTxFailCount
[ii
];
534 IN PVOID pMgmtHandle
,
535 IN PBYTE pbyDestAddress
,
536 OUT PWORD pwTxDataRate
,
537 OUT PBYTE pbyACKRate
,
538 OUT PBYTE pbyCCKBasicRate
,
539 OUT PBYTE pbyOFDMBasicRate
542 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
544 WORD wTxDataRate
= RATE_1M
;
545 BYTE byACKRate
= RATE_1M
;
546 BYTE byCCKBasicRate
= RATE_1M
;
547 BYTE byOFDMBasicRate
= RATE_24M
;
548 PWLAN_IE_SUPP_RATES pSupportRateIEs
= NULL
;
549 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
= NULL
;
552 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
553 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
554 // Adhoc Tx rate decided from node DB
555 if(BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
)) {
556 wTxDataRate
= (pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
);
557 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrSuppRates
);
558 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrExtSuppRates
);
560 if (pMgmt
->eCurrentPHYMode
!= PHY_TYPE_11A
) {
561 wTxDataRate
= RATE_2M
;
563 wTxDataRate
= RATE_24M
;
565 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
566 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
568 } else { // Infrastructure: rate decided from AP Node, index = 0
570 wTxDataRate
= (pMgmt
->sNodeDBTable
[0].wTxDataRate
);
572 printk("GetTxRate:AP MAC is %02x:%02x:%02x:%02x:%02x:%02x,TxRate is %d\n",
573 pMgmt
->sNodeDBTable
[0].abyMACAddr
[0],pMgmt
->sNodeDBTable
[0].abyMACAddr
[1],
574 pMgmt
->sNodeDBTable
[0].abyMACAddr
[2],pMgmt
->sNodeDBTable
[0].abyMACAddr
[3],
575 pMgmt
->sNodeDBTable
[0].abyMACAddr
[4],pMgmt
->sNodeDBTable
[0].abyMACAddr
[5],wTxDataRate
);
579 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
580 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
582 byACKRate
= VNTWIFIbyGetACKTxRate( (BYTE
) wTxDataRate
,
586 if (byACKRate
> (BYTE
) wTxDataRate
) {
587 byACKRate
= (BYTE
) wTxDataRate
;
589 byCCKBasicRate
= VNTWIFIbyGetACKTxRate( RATE_11M
,
593 byOFDMBasicRate
= VNTWIFIbyGetACKTxRate(RATE_54M
,
597 *pwTxDataRate
= wTxDataRate
;
598 *pbyACKRate
= byACKRate
;
599 *pbyCCKBasicRate
= byCCKBasicRate
;
600 *pbyOFDMBasicRate
= byOFDMBasicRate
;
605 VNTWIFIbyGetKeyCypher(
606 IN PVOID pMgmtHandle
,
610 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
612 if (bGroupKey
== TRUE
) {
613 return (pMgmt
->byCSSGK
);
615 return (pMgmt
->byCSSPK
);
623 IN PVOID pAdapterHandler,
624 OUT PVOID *pMgmtHandler
628 PSMgmtObject pMgmt = NULL;
632 pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
634 *pMgmtHandler = NULL;
638 memset(pMgmt, 0, sizeof(SMgmtObject));
639 pMgmt->pAdapter = (PVOID) pAdapterHandler;
641 // should initial MAC address abyMACAddr
642 for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
643 pMgmt->abyDesireBSSID[ii] = 0xFF;
645 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
646 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
647 pMgmt->byCSSPK = KEY_CTL_NONE;
648 pMgmt->byCSSGK = KEY_CTL_NONE;
649 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
651 pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
652 pMgmt->uCmdDequeueIdx = 0;
653 pMgmt->uCmdEnqueueIdx = 0;
654 pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
655 pMgmt->bCmdStop = FALSE;
656 pMgmt->bCmdRunning = FALSE;
658 *pMgmtHandler = pMgmt;
666 VNTWIFIbSetPMKIDCache (
667 IN PVOID pMgmtObject
,
672 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
674 if (ulCount
> MAX_PMKID_CACHE
) {
677 pMgmt
->gsPMKIDCache
.BSSIDInfoCount
= ulCount
;
678 memcpy(pMgmt
->gsPMKIDCache
.BSSIDInfo
, pPMKIDInfo
, (ulCount
*sizeof(PMKIDInfo
)));
685 VNTWIFIwGetMaxSupportRate(
689 WORD wRate
= RATE_54M
;
690 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
692 for(wRate
= RATE_54M
; wRate
> RATE_1M
; wRate
--) {
693 if (pMgmt
->sNodeDBTable
[0].wSuppRate
& (1<<wRate
)) {
697 if (pMgmt
->eCurrentPHYMode
== PHY_TYPE_11A
) {
707 IN PVOID pMgmtObject
,
711 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
713 pMgmt
->b11hEnable
= b11hEnable
;
717 VNTWIFIbMeasureReport(
718 IN PVOID pMgmtObject
,
719 IN BOOL bEndOfReport
,
720 IN PVOID pvMeasureEID
,
721 IN BYTE byReportMode
,
723 IN BYTE byCCAFraction
,
727 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
728 PBYTE pbyCurrentEID
= (PBYTE
) (pMgmt
->pCurrMeasureEIDRep
);
730 //spin_lock_irq(&pDevice->lock);
731 if ((pvMeasureEID
!= NULL
) &&
732 (pMgmt
->uLengthOfRepEIDs
< (WLAN_A3FR_MAXLEN
- sizeof(MEASEURE_REP
) - sizeof(WLAN_80211HDR_A3
) - 3))
734 pMgmt
->pCurrMeasureEIDRep
->byElementID
= WLAN_EID_MEASURE_REP
;
735 pMgmt
->pCurrMeasureEIDRep
->len
= 3;
736 pMgmt
->pCurrMeasureEIDRep
->byToken
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byToken
;
737 pMgmt
->pCurrMeasureEIDRep
->byMode
= byReportMode
;
738 pMgmt
->pCurrMeasureEIDRep
->byType
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byType
;
739 switch (pMgmt
->pCurrMeasureEIDRep
->byType
) {
740 case MEASURE_TYPE_BASIC
:
741 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_BASIC
);
742 memcpy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
),
743 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
744 sizeof(MEASEURE_REQ
));
745 pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
.byMap
= byBasicMap
;
747 case MEASURE_TYPE_CCA
:
748 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_CCA
);
749 memcpy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
),
750 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
751 sizeof(MEASEURE_REQ
));
752 pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
.byCCABusyFraction
= byCCAFraction
;
754 case MEASURE_TYPE_RPI
:
755 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_RPI
);
756 memcpy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
),
757 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
758 sizeof(MEASEURE_REQ
));
759 memcpy(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
.abyRPIdensity
, pbyRPIs
, 8);
764 pbyCurrentEID
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
765 pMgmt
->uLengthOfRepEIDs
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
766 pMgmt
->pCurrMeasureEIDRep
= (PWLAN_IE_MEASURE_REP
) pbyCurrentEID
;
768 if (bEndOfReport
== TRUE
) {
769 IEEE11hbMSRRepTx(pMgmt
);
771 //spin_unlock_irq(&pDevice->lock);
777 VNTWIFIbChannelSwitch(
778 IN PVOID pMgmtObject
,
782 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
784 //spin_lock_irq(&pDevice->lock);
785 pMgmt
->uCurrChannel
= byNewChannel
;
786 pMgmt
->bSwitchChannel
= FALSE
;
787 //spin_unlock_irq(&pDevice->lock);
793 VNTWIFIbRadarPresent(
794 IN PVOID pMgmtObject,
798 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
799 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
800 (byChannel == (BYTE) pMgmt->uCurrChannel) &&
801 (pMgmt->bSwitchChannel != TRUE) &&
802 (pMgmt->b11hEnable == TRUE)) {
803 if (IS_ETH_ADDRESS_EQUAL(pMgmt->abyIBSSDFSOwner, CARDpGetCurrentAddress(pMgmt->pAdapter))) {
804 pMgmt->byNewChannel = CARDbyAutoChannelSelect(pMgmt->pAdapter,(BYTE) pMgmt->uCurrChannel);
805 pMgmt->bSwitchChannel = TRUE;
807 BEACONbSendBeacon(pMgmt);
808 CARDbChannelSwitch(pMgmt->pAdapter, 0, pMgmt->byNewChannel, 10);