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
34 #if !defined(__VNTWIFI_H__)
37 #if !defined(__UMEM_H__)
42 #if !defined(__TBIT_H__)
45 #if !defined(__IEEE11h_H__)
48 #if !defined(__COUNTRY_H__)
51 #if !defined(__DEVICE_H__)
54 #if !defined(__WMGR_H__)
57 #if !defined(__DATARATE_H__)
62 /*--------------------- Static Definitions -------------------------*/
63 //static int msglevel =MSG_LEVEL_DEBUG;
64 //static int msglevel =MSG_LEVEL_INFO;
66 /*--------------------- Static Classes ----------------------------*/
68 /*--------------------- Static Variables --------------------------*/
70 /*--------------------- Static Functions --------------------------*/
72 /*--------------------- Export Variables --------------------------*/
74 /*--------------------- Export Functions --------------------------*/
83 * pMgmtHandle - pointer to management object
84 * eOPMode - Opreation Mode
94 IN WMAC_CONFIG_MODE eOPMode
97 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
99 pMgmt
->eConfigMode
= eOPMode
;
110 * pMgmtHandle - pointer to management object
111 * wBeaconPeriod - Beacon Period
112 * wATIMWindow - ATIM window
113 * uChannel - channel number
121 VNTWIFIvSetIBSSParameter (
122 IN PVOID pMgmtHandle
,
123 IN WORD wBeaconPeriod
,
128 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
130 pMgmt
->wIBSSBeaconPeriod
= wBeaconPeriod
;
131 pMgmt
->wIBSSATIMWindow
= wATIMWindow
;
132 pMgmt
->uIBSSChannel
= uChannel
;
142 * pMgmtHandle - pointer to management object
146 * Return Value: current SSID pointer.
150 VNTWIFIpGetCurrentSSID (
154 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
155 return((PWLAN_IE_SSID
) pMgmt
->abyCurrSSID
);
161 * Get current link channel
165 * pMgmtHandle - pointer to management object
169 * Return Value: current Channel.
173 VNTWIFIpGetCurrentChannel (
177 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
178 if (pMgmtHandle
!= NULL
) {
179 return (pMgmt
->uCurrChannel
);
187 * Get current Assoc ID
191 * pMgmtHandle - pointer to management object
195 * Return Value: current Assoc ID
203 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
204 return(pMgmt
->wCurrAID
);
212 * This routine return max support rate of IES
221 * Return Value: max support rate
225 VNTWIFIbyGetMaxSupportRate (
226 IN PWLAN_IE_SUPP_RATES pSupportRateIEs
,
227 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
230 BYTE byMaxSupportRate
= RATE_1M
;
231 BYTE bySupportRate
= RATE_1M
;
234 if (pSupportRateIEs
) {
235 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
236 bySupportRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
237 if (bySupportRate
> byMaxSupportRate
) {
238 byMaxSupportRate
= bySupportRate
;
242 if (pExtSupportRateIEs
) {
243 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
244 bySupportRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
245 if (bySupportRate
> byMaxSupportRate
) {
246 byMaxSupportRate
= bySupportRate
;
251 return byMaxSupportRate
;
257 * This routine return data rate of ACK packtet
267 * Return Value: max support rate
271 VNTWIFIbyGetACKTxRate (
272 IN BYTE byRxDataRate
,
273 IN PWLAN_IE_SUPP_RATES pSupportRateIEs
,
274 IN PWLAN_IE_SUPP_RATES pExtSupportRateIEs
281 if (byRxDataRate
<= RATE_11M
) {
282 byMaxAckRate
= RATE_1M
;
284 // 24M is mandatory for 802.11a and 802.11g
285 byMaxAckRate
= RATE_24M
;
287 if (pSupportRateIEs
) {
288 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
289 if (pSupportRateIEs
->abyRates
[ii
] & 0x80) {
290 byBasicRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
291 if ((byBasicRate
<= byRxDataRate
) &&
292 (byBasicRate
> byMaxAckRate
)) {
293 byMaxAckRate
= byBasicRate
;
298 if (pExtSupportRateIEs
) {
299 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
300 if (pExtSupportRateIEs
->abyRates
[ii
] & 0x80) {
301 byBasicRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
302 if ((byBasicRate
<= byRxDataRate
) &&
303 (byBasicRate
> byMaxAckRate
)) {
304 byMaxAckRate
= byBasicRate
;
316 * Set Authentication Mode
320 * pMgmtHandle - pointer to management object
321 * eAuthMode - Authentication mode
329 VNTWIFIvSetAuthenticationMode (
330 IN PVOID pMgmtHandle
,
331 IN WMAC_AUTHENTICATION_MODE eAuthMode
334 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
336 pMgmt
->eAuthenMode
= eAuthMode
;
337 if ((eAuthMode
== WMAC_AUTH_SHAREKEY
) ||
338 (eAuthMode
== WMAC_AUTH_AUTO
)) {
339 pMgmt
->bShareKeyAlgorithm
= TRUE
;
341 pMgmt
->bShareKeyAlgorithm
= FALSE
;
348 * Set Encryption Mode
352 * pMgmtHandle - pointer to management object
353 * eAuthMode - Authentication mode
361 VNTWIFIvSetEncryptionMode (
362 IN PVOID pMgmtHandle
,
363 IN WMAC_ENCRYPTION_MODE eEncryptionMode
366 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
368 pMgmt
->eEncryptionMode
= eEncryptionMode
;
369 if ((eEncryptionMode
== WMAC_ENCRYPTION_WEPEnabled
) ||
370 (eEncryptionMode
== WMAC_ENCRYPTION_TKIPEnabled
) ||
371 (eEncryptionMode
== WMAC_ENCRYPTION_AESEnabled
) ) {
372 pMgmt
->bPrivacyInvoked
= TRUE
;
374 pMgmt
->bPrivacyInvoked
= FALSE
;
381 VNTWIFIbConfigPhyMode (
382 IN PVOID pMgmtHandle
,
383 IN CARD_PHY_TYPE ePhyType
386 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
388 if ((ePhyType
!= PHY_TYPE_AUTO
) &&
389 (ePhyType
!= pMgmt
->eCurrentPHYMode
)) {
390 if (CARDbSetPhyParameter(pMgmt
->pAdapter
, ePhyType
, 0, 0, NULL
, NULL
)==TRUE
) {
391 pMgmt
->eCurrentPHYMode
= ePhyType
;
396 pMgmt
->eConfigPHYMode
= ePhyType
;
402 VNTWIFIbGetConfigPhyMode (
403 IN PVOID pMgmtHandle
,
407 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
409 if ((pMgmt
!= NULL
) && (pePhyType
!= NULL
)) {
410 *(PCARD_PHY_TYPE
)pePhyType
= pMgmt
->eConfigPHYMode
;
417 * Clear BSS List Database except current assoc BSS
421 * pMgmtHandle - Management Object structure
422 * bLinkPass - Current Link status
425 * Return Value: None.
433 * Query BSS List in management database
437 * pMgmtHandle - Management Object structure
439 * puBSSCount - BSS count
440 * pvFirstBSS - pointer to first BSS
442 * Return Value: None.
447 VNTWIFIvQueryBSSList (
448 IN PVOID pMgmtHandle
,
449 OUT PUINT puBSSCount
,
450 OUT PVOID
*pvFirstBSS
454 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
455 PKnownBSS pBSS
= NULL
;
460 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
461 pBSS
= &(pMgmt
->sBSSList
[ii
]);
462 if (!pBSS
->bActive
) {
465 if (*pvFirstBSS
== NULL
) {
466 *pvFirstBSS
= &(pMgmt
->sBSSList
[ii
]);
470 *puBSSCount
= uCount
;
478 IN PVOID pMgmtHandle
,
479 IN PVOID pvCurrentBSS
,
483 PKnownBSS pBSS
= (PKnownBSS
) pvCurrentBSS
;
484 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
488 while (*pvNextBSS
== NULL
) {
490 if (pBSS
> &(pMgmt
->sBSSList
[MAX_BSS_NUM
])) {
493 if (pBSS
->bActive
== TRUE
) {
507 * Update Tx attemps, Tx failure counter in Node DB
517 VNTWIFIvUpdateNodeTxCounter(
518 IN PVOID pMgmtHandle
,
519 IN PBYTE pbyDestAddress
,
522 IN PBYTE pbyTxFailCount
525 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
529 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
530 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
531 if (BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
) == FALSE
) {
535 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxAttempts
++;
537 // transmit success, TxAttempts at least plus one
538 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[MAX_RATE
]++;
539 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[wRate
]++;
541 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFailures
++;
543 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxRetry
+= pbyTxFailCount
[MAX_RATE
];
544 for(ii
=0;ii
<MAX_RATE
;ii
++) {
545 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[ii
] += pbyTxFailCount
[ii
];
553 IN PVOID pMgmtHandle
,
554 IN PBYTE pbyDestAddress
,
555 OUT PWORD pwTxDataRate
,
556 OUT PBYTE pbyACKRate
,
557 OUT PBYTE pbyCCKBasicRate
,
558 OUT PBYTE pbyOFDMBasicRate
561 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
563 WORD wTxDataRate
= RATE_1M
;
564 BYTE byACKRate
= RATE_1M
;
565 BYTE byCCKBasicRate
= RATE_1M
;
566 BYTE byOFDMBasicRate
= RATE_24M
;
567 PWLAN_IE_SUPP_RATES pSupportRateIEs
= NULL
;
568 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
= NULL
;
571 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
572 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
573 // Adhoc Tx rate decided from node DB
574 if(BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
)) {
575 wTxDataRate
= (pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
);
576 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrSuppRates
);
577 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrExtSuppRates
);
579 if (pMgmt
->eCurrentPHYMode
!= PHY_TYPE_11A
) {
580 wTxDataRate
= RATE_2M
;
582 wTxDataRate
= RATE_24M
;
584 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
585 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
587 } else { // Infrastructure: rate decided from AP Node, index = 0
589 wTxDataRate
= (pMgmt
->sNodeDBTable
[0].wTxDataRate
);
591 printk("GetTxRate:AP MAC is %02x:%02x:%02x:%02x:%02x:%02x,TxRate is %d\n",
592 pMgmt
->sNodeDBTable
[0].abyMACAddr
[0],pMgmt
->sNodeDBTable
[0].abyMACAddr
[1],
593 pMgmt
->sNodeDBTable
[0].abyMACAddr
[2],pMgmt
->sNodeDBTable
[0].abyMACAddr
[3],
594 pMgmt
->sNodeDBTable
[0].abyMACAddr
[4],pMgmt
->sNodeDBTable
[0].abyMACAddr
[5],wTxDataRate
);
598 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
599 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
601 byACKRate
= VNTWIFIbyGetACKTxRate( (BYTE
) wTxDataRate
,
605 if (byACKRate
> (BYTE
) wTxDataRate
) {
606 byACKRate
= (BYTE
) wTxDataRate
;
608 byCCKBasicRate
= VNTWIFIbyGetACKTxRate( RATE_11M
,
612 byOFDMBasicRate
= VNTWIFIbyGetACKTxRate(RATE_54M
,
616 *pwTxDataRate
= wTxDataRate
;
617 *pbyACKRate
= byACKRate
;
618 *pbyCCKBasicRate
= byCCKBasicRate
;
619 *pbyOFDMBasicRate
= byOFDMBasicRate
;
624 VNTWIFIbyGetKeyCypher(
625 IN PVOID pMgmtHandle
,
629 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
631 if (bGroupKey
== TRUE
) {
632 return (pMgmt
->byCSSGK
);
634 return (pMgmt
->byCSSPK
);
642 IN PVOID pAdapterHandler,
643 OUT PVOID *pMgmtHandler
647 PSMgmtObject pMgmt = NULL;
651 pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
653 *pMgmtHandler = NULL;
657 memset(pMgmt, 0, sizeof(SMgmtObject));
658 pMgmt->pAdapter = (PVOID) pAdapterHandler;
660 // should initial MAC address abyMACAddr
661 for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
662 pMgmt->abyDesireBSSID[ii] = 0xFF;
664 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
665 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
666 pMgmt->byCSSPK = KEY_CTL_NONE;
667 pMgmt->byCSSGK = KEY_CTL_NONE;
668 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
670 pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
671 pMgmt->uCmdDequeueIdx = 0;
672 pMgmt->uCmdEnqueueIdx = 0;
673 pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
674 pMgmt->bCmdStop = FALSE;
675 pMgmt->bCmdRunning = FALSE;
677 *pMgmtHandler = pMgmt;
685 VNTWIFIbSetPMKIDCache (
686 IN PVOID pMgmtObject
,
691 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
693 if (ulCount
> MAX_PMKID_CACHE
) {
696 pMgmt
->gsPMKIDCache
.BSSIDInfoCount
= ulCount
;
697 MEMvCopy(pMgmt
->gsPMKIDCache
.BSSIDInfo
, pPMKIDInfo
, (ulCount
*sizeof(PMKIDInfo
)));
704 VNTWIFIwGetMaxSupportRate(
708 WORD wRate
= RATE_54M
;
709 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
711 for(wRate
= RATE_54M
; wRate
> RATE_1M
; wRate
--) {
712 if (BITbIsBitOn(pMgmt
->sNodeDBTable
[0].wSuppRate
, (1<<wRate
))) {
716 if (pMgmt
->eCurrentPHYMode
== PHY_TYPE_11A
) {
726 IN PVOID pMgmtObject
,
730 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
732 pMgmt
->b11hEnable
= b11hEnable
;
736 VNTWIFIbMeasureReport(
737 IN PVOID pMgmtObject
,
738 IN BOOL bEndOfReport
,
739 IN PVOID pvMeasureEID
,
740 IN BYTE byReportMode
,
742 IN BYTE byCCAFraction
,
746 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
747 PBYTE pbyCurrentEID
= (PBYTE
) (pMgmt
->pCurrMeasureEIDRep
);
749 //spin_lock_irq(&pDevice->lock);
750 if ((pvMeasureEID
!= NULL
) &&
751 (pMgmt
->uLengthOfRepEIDs
< (WLAN_A3FR_MAXLEN
- sizeof(MEASEURE_REP
) - sizeof(WLAN_80211HDR_A3
) - 3))
753 pMgmt
->pCurrMeasureEIDRep
->byElementID
= WLAN_EID_MEASURE_REP
;
754 pMgmt
->pCurrMeasureEIDRep
->len
= 3;
755 pMgmt
->pCurrMeasureEIDRep
->byToken
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byToken
;
756 pMgmt
->pCurrMeasureEIDRep
->byMode
= byReportMode
;
757 pMgmt
->pCurrMeasureEIDRep
->byType
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byType
;
758 switch (pMgmt
->pCurrMeasureEIDRep
->byType
) {
759 case MEASURE_TYPE_BASIC
:
760 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_BASIC
);
761 MEMvCopy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
),
762 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
763 sizeof(MEASEURE_REQ
));
764 pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
.byMap
= byBasicMap
;
766 case MEASURE_TYPE_CCA
:
767 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_CCA
);
768 MEMvCopy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
),
769 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
770 sizeof(MEASEURE_REQ
));
771 pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
.byCCABusyFraction
= byCCAFraction
;
773 case MEASURE_TYPE_RPI
:
774 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_RPI
);
775 MEMvCopy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
),
776 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
777 sizeof(MEASEURE_REQ
));
778 MEMvCopy(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
.abyRPIdensity
, pbyRPIs
, 8);
783 pbyCurrentEID
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
784 pMgmt
->uLengthOfRepEIDs
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
785 pMgmt
->pCurrMeasureEIDRep
= (PWLAN_IE_MEASURE_REP
) pbyCurrentEID
;
787 if (bEndOfReport
== TRUE
) {
788 IEEE11hbMSRRepTx(pMgmt
);
790 //spin_unlock_irq(&pDevice->lock);
796 VNTWIFIbChannelSwitch(
797 IN PVOID pMgmtObject
,
801 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
803 //spin_lock_irq(&pDevice->lock);
804 pMgmt
->uCurrChannel
= byNewChannel
;
805 pMgmt
->bSwitchChannel
= FALSE
;
806 //spin_unlock_irq(&pDevice->lock);
812 VNTWIFIbRadarPresent(
813 IN PVOID pMgmtObject,
817 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
818 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
819 (byChannel == (BYTE) pMgmt->uCurrChannel) &&
820 (pMgmt->bSwitchChannel != TRUE) &&
821 (pMgmt->b11hEnable == TRUE)) {
822 if (IS_ETH_ADDRESS_EQUAL(pMgmt->abyIBSSDFSOwner, CARDpGetCurrentAddress(pMgmt->pAdapter))) {
823 pMgmt->byNewChannel = CARDbyAutoChannelSelect(pMgmt->pAdapter,(BYTE) pMgmt->uCurrChannel);
824 pMgmt->bSwitchChannel = TRUE;
826 BEACONbSendBeacon(pMgmt);
827 CARDbChannelSwitch(pMgmt->pAdapter, 0, pMgmt->byNewChannel, 10);