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
41 /*--------------------- Static Definitions -------------------------*/
42 //static int msglevel =MSG_LEVEL_DEBUG;
43 //static int msglevel =MSG_LEVEL_INFO;
45 /*--------------------- Static Classes ----------------------------*/
47 /*--------------------- Static Variables --------------------------*/
49 /*--------------------- Static Functions --------------------------*/
51 /*--------------------- Export Variables --------------------------*/
53 /*--------------------- Export Functions --------------------------*/
62 * pMgmtHandle - pointer to management object
63 * eOPMode - Opreation Mode
73 WMAC_CONFIG_MODE eOPMode
76 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
78 pMgmt
->eConfigMode
= eOPMode
;
89 * pMgmtHandle - pointer to management object
90 * wBeaconPeriod - Beacon Period
91 * wATIMWindow - ATIM window
92 * uChannel - channel number
100 VNTWIFIvSetIBSSParameter (
102 unsigned short wBeaconPeriod
,
103 unsigned short wATIMWindow
,
104 unsigned int uChannel
107 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
109 pMgmt
->wIBSSBeaconPeriod
= wBeaconPeriod
;
110 pMgmt
->wIBSSATIMWindow
= wATIMWindow
;
111 pMgmt
->uIBSSChannel
= uChannel
;
121 * pMgmtHandle - pointer to management object
125 * Return Value: current SSID pointer.
129 VNTWIFIpGetCurrentSSID (
133 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
134 return((PWLAN_IE_SSID
) pMgmt
->abyCurrSSID
);
140 * Get current link channel
144 * pMgmtHandle - pointer to management object
148 * Return Value: current Channel.
152 VNTWIFIpGetCurrentChannel (
156 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
157 if (pMgmtHandle
!= NULL
) {
158 return (pMgmt
->uCurrChannel
);
166 * Get current Assoc ID
170 * pMgmtHandle - pointer to management object
174 * Return Value: current Assoc ID
182 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
183 return(pMgmt
->wCurrAID
);
191 * This routine return max support rate of IES
200 * Return Value: max support rate
204 VNTWIFIbyGetMaxSupportRate (
205 PWLAN_IE_SUPP_RATES pSupportRateIEs
,
206 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
209 unsigned char byMaxSupportRate
= RATE_1M
;
210 unsigned char bySupportRate
= RATE_1M
;
213 if (pSupportRateIEs
) {
214 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
215 bySupportRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
216 if (bySupportRate
> byMaxSupportRate
) {
217 byMaxSupportRate
= bySupportRate
;
221 if (pExtSupportRateIEs
) {
222 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
223 bySupportRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
224 if (bySupportRate
> byMaxSupportRate
) {
225 byMaxSupportRate
= bySupportRate
;
230 return byMaxSupportRate
;
236 * This routine return data rate of ACK packtet
246 * Return Value: max support rate
250 VNTWIFIbyGetACKTxRate (
251 unsigned char byRxDataRate
,
252 PWLAN_IE_SUPP_RATES pSupportRateIEs
,
253 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
256 unsigned char byMaxAckRate
;
257 unsigned char byBasicRate
;
260 if (byRxDataRate
<= RATE_11M
) {
261 byMaxAckRate
= RATE_1M
;
263 // 24M is mandatory for 802.11a and 802.11g
264 byMaxAckRate
= RATE_24M
;
266 if (pSupportRateIEs
) {
267 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
268 if (pSupportRateIEs
->abyRates
[ii
] & 0x80) {
269 byBasicRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
270 if ((byBasicRate
<= byRxDataRate
) &&
271 (byBasicRate
> byMaxAckRate
)) {
272 byMaxAckRate
= byBasicRate
;
277 if (pExtSupportRateIEs
) {
278 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
279 if (pExtSupportRateIEs
->abyRates
[ii
] & 0x80) {
280 byBasicRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
281 if ((byBasicRate
<= byRxDataRate
) &&
282 (byBasicRate
> byMaxAckRate
)) {
283 byMaxAckRate
= byBasicRate
;
295 * Set Authentication Mode
299 * pMgmtHandle - pointer to management object
300 * eAuthMode - Authentication mode
308 VNTWIFIvSetAuthenticationMode (
310 WMAC_AUTHENTICATION_MODE eAuthMode
313 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
315 pMgmt
->eAuthenMode
= eAuthMode
;
316 if ((eAuthMode
== WMAC_AUTH_SHAREKEY
) ||
317 (eAuthMode
== WMAC_AUTH_AUTO
)) {
318 pMgmt
->bShareKeyAlgorithm
= true;
320 pMgmt
->bShareKeyAlgorithm
= false;
327 * Set Encryption Mode
331 * pMgmtHandle - pointer to management object
332 * eAuthMode - Authentication mode
340 VNTWIFIvSetEncryptionMode (
342 WMAC_ENCRYPTION_MODE eEncryptionMode
345 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
347 pMgmt
->eEncryptionMode
= eEncryptionMode
;
348 if ((eEncryptionMode
== WMAC_ENCRYPTION_WEPEnabled
) ||
349 (eEncryptionMode
== WMAC_ENCRYPTION_TKIPEnabled
) ||
350 (eEncryptionMode
== WMAC_ENCRYPTION_AESEnabled
) ) {
351 pMgmt
->bPrivacyInvoked
= true;
353 pMgmt
->bPrivacyInvoked
= false;
360 VNTWIFIbConfigPhyMode (
362 CARD_PHY_TYPE ePhyType
365 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
367 if ((ePhyType
!= PHY_TYPE_AUTO
) &&
368 (ePhyType
!= pMgmt
->eCurrentPHYMode
)) {
369 if (CARDbSetPhyParameter(pMgmt
->pAdapter
, ePhyType
, 0, 0, NULL
, NULL
)==true) {
370 pMgmt
->eCurrentPHYMode
= ePhyType
;
375 pMgmt
->eConfigPHYMode
= ePhyType
;
381 VNTWIFIbGetConfigPhyMode (
386 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
388 if ((pMgmt
!= NULL
) && (pePhyType
!= NULL
)) {
389 *(PCARD_PHY_TYPE
)pePhyType
= pMgmt
->eConfigPHYMode
;
396 * Clear BSS List Database except current assoc BSS
400 * pMgmtHandle - Management Object structure
401 * bLinkPass - Current Link status
404 * Return Value: None.
412 * Query BSS List in management database
416 * pMgmtHandle - Management Object structure
418 * puBSSCount - BSS count
419 * pvFirstBSS - pointer to first BSS
421 * Return Value: None.
426 VNTWIFIvQueryBSSList(void *pMgmtHandle
, unsigned int *puBSSCount
, void **pvFirstBSS
)
429 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
430 PKnownBSS pBSS
= NULL
;
431 unsigned int uCount
= 0;
435 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
436 pBSS
= &(pMgmt
->sBSSList
[ii
]);
437 if (!pBSS
->bActive
) {
440 if (*pvFirstBSS
== NULL
) {
441 *pvFirstBSS
= &(pMgmt
->sBSSList
[ii
]);
445 *puBSSCount
= uCount
;
458 PKnownBSS pBSS
= (PKnownBSS
) pvCurrentBSS
;
459 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
463 while (*pvNextBSS
== NULL
) {
465 if (pBSS
> &(pMgmt
->sBSSList
[MAX_BSS_NUM
])) {
468 if (pBSS
->bActive
== true) {
482 * Update Tx attemps, Tx failure counter in Node DB
492 VNTWIFIvUpdateNodeTxCounter(
494 unsigned char *pbyDestAddress
,
496 unsigned short wRate
,
497 unsigned char *pbyTxFailCount
500 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
501 unsigned int uNodeIndex
= 0;
504 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
505 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
506 if (BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
) == false) {
510 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxAttempts
++;
512 // transmit success, TxAttempts at least plus one
513 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[MAX_RATE
]++;
514 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[wRate
]++;
516 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFailures
++;
518 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxRetry
+= pbyTxFailCount
[MAX_RATE
];
519 for(ii
=0;ii
<MAX_RATE
;ii
++) {
520 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[ii
] += pbyTxFailCount
[ii
];
529 unsigned char *pbyDestAddress
,
530 unsigned short *pwTxDataRate
,
531 unsigned char *pbyACKRate
,
532 unsigned char *pbyCCKBasicRate
,
533 unsigned char *pbyOFDMBasicRate
536 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
537 unsigned int uNodeIndex
= 0;
538 unsigned short wTxDataRate
= RATE_1M
;
539 unsigned char byACKRate
= RATE_1M
;
540 unsigned char byCCKBasicRate
= RATE_1M
;
541 unsigned char byOFDMBasicRate
= RATE_24M
;
542 PWLAN_IE_SUPP_RATES pSupportRateIEs
= NULL
;
543 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
= NULL
;
546 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
547 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
548 // Adhoc Tx rate decided from node DB
549 if(BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
)) {
550 wTxDataRate
= (pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
);
551 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrSuppRates
);
552 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrExtSuppRates
);
554 if (pMgmt
->eCurrentPHYMode
!= PHY_TYPE_11A
) {
555 wTxDataRate
= RATE_2M
;
557 wTxDataRate
= RATE_24M
;
559 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
560 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
562 } else { // Infrastructure: rate decided from AP Node, index = 0
564 wTxDataRate
= (pMgmt
->sNodeDBTable
[0].wTxDataRate
);
566 printk(KERN_DEBUG
"GetTxRate:AP MAC is %pM,TxRate is %d\n",
567 pMgmt
->sNodeDBTable
[0].abyMACAddr
, wTxDataRate
);
571 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
572 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
574 byACKRate
= VNTWIFIbyGetACKTxRate( (unsigned char) wTxDataRate
,
578 if (byACKRate
> (unsigned char) wTxDataRate
) {
579 byACKRate
= (unsigned char) wTxDataRate
;
581 byCCKBasicRate
= VNTWIFIbyGetACKTxRate( RATE_11M
,
585 byOFDMBasicRate
= VNTWIFIbyGetACKTxRate(RATE_54M
,
589 *pwTxDataRate
= wTxDataRate
;
590 *pbyACKRate
= byACKRate
;
591 *pbyCCKBasicRate
= byCCKBasicRate
;
592 *pbyOFDMBasicRate
= byOFDMBasicRate
;
597 VNTWIFIbyGetKeyCypher(
602 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
604 if (bGroupKey
== true) {
605 return (pMgmt
->byCSSGK
);
607 return (pMgmt
->byCSSPK
);
615 void *pAdapterHandler,
620 PSMgmtObject pMgmt = NULL;
624 pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
626 *pMgmtHandler = NULL;
630 memset(pMgmt, 0, sizeof(SMgmtObject));
631 pMgmt->pAdapter = (void *) pAdapterHandler;
633 // should initial MAC address abyMACAddr
634 for(ii=0;ii<WLAN_BSSID_LEN;ii++) {
635 pMgmt->abyDesireBSSID[ii] = 0xFF;
637 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
638 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
639 pMgmt->byCSSPK = KEY_CTL_NONE;
640 pMgmt->byCSSGK = KEY_CTL_NONE;
641 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
643 pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
644 pMgmt->uCmdDequeueIdx = 0;
645 pMgmt->uCmdEnqueueIdx = 0;
646 pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
647 pMgmt->bCmdStop = false;
648 pMgmt->bCmdRunning = false;
650 *pMgmtHandler = pMgmt;
658 VNTWIFIbSetPMKIDCache (
660 unsigned long ulCount
,
664 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
666 if (ulCount
> MAX_PMKID_CACHE
) {
669 pMgmt
->gsPMKIDCache
.BSSIDInfoCount
= ulCount
;
670 memcpy(pMgmt
->gsPMKIDCache
.BSSIDInfo
, pPMKIDInfo
, (ulCount
*sizeof(PMKIDInfo
)));
677 VNTWIFIwGetMaxSupportRate(
681 unsigned short wRate
= RATE_54M
;
682 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
684 for(wRate
= RATE_54M
; wRate
> RATE_1M
; wRate
--) {
685 if (pMgmt
->sNodeDBTable
[0].wSuppRate
& (1<<wRate
)) {
689 if (pMgmt
->eCurrentPHYMode
== PHY_TYPE_11A
) {
703 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
705 pMgmt
->b11hEnable
= b11hEnable
;
709 VNTWIFIbMeasureReport(
713 unsigned char byReportMode
,
714 unsigned char byBasicMap
,
715 unsigned char byCCAFraction
,
716 unsigned char *pbyRPIs
719 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
720 unsigned char *pbyCurrentEID
= (unsigned char *) (pMgmt
->pCurrMeasureEIDRep
);
722 //spin_lock_irq(&pDevice->lock);
723 if ((pvMeasureEID
!= NULL
) &&
724 (pMgmt
->uLengthOfRepEIDs
< (WLAN_A3FR_MAXLEN
- sizeof(MEASEURE_REP
) - sizeof(WLAN_80211HDR_A3
) - 3))
726 pMgmt
->pCurrMeasureEIDRep
->byElementID
= WLAN_EID_MEASURE_REP
;
727 pMgmt
->pCurrMeasureEIDRep
->len
= 3;
728 pMgmt
->pCurrMeasureEIDRep
->byToken
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byToken
;
729 pMgmt
->pCurrMeasureEIDRep
->byMode
= byReportMode
;
730 pMgmt
->pCurrMeasureEIDRep
->byType
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byType
;
731 switch (pMgmt
->pCurrMeasureEIDRep
->byType
) {
732 case MEASURE_TYPE_BASIC
:
733 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_BASIC
);
734 memcpy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
),
735 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
736 sizeof(MEASEURE_REQ
));
737 pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
.byMap
= byBasicMap
;
739 case MEASURE_TYPE_CCA
:
740 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_CCA
);
741 memcpy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
),
742 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
743 sizeof(MEASEURE_REQ
));
744 pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
.byCCABusyFraction
= byCCAFraction
;
746 case MEASURE_TYPE_RPI
:
747 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_RPI
);
748 memcpy( &(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
),
749 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
750 sizeof(MEASEURE_REQ
));
751 memcpy(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
.abyRPIdensity
, pbyRPIs
, 8);
756 pbyCurrentEID
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
757 pMgmt
->uLengthOfRepEIDs
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
758 pMgmt
->pCurrMeasureEIDRep
= (PWLAN_IE_MEASURE_REP
) pbyCurrentEID
;
760 if (bEndOfReport
== true) {
761 IEEE11hbMSRRepTx(pMgmt
);
763 //spin_unlock_irq(&pDevice->lock);
769 VNTWIFIbChannelSwitch(
771 unsigned char byNewChannel
774 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
776 //spin_lock_irq(&pDevice->lock);
777 pMgmt
->uCurrChannel
= byNewChannel
;
778 pMgmt
->bSwitchChannel
= false;
779 //spin_unlock_irq(&pDevice->lock);
785 VNTWIFIbRadarPresent(
787 unsigned char byChannel
790 PSMgmtObject pMgmt = (PSMgmtObject) pMgmtObject;
791 if ((pMgmt->eCurrMode == WMAC_MODE_IBSS_STA) &&
792 (byChannel == (unsigned char) pMgmt->uCurrChannel) &&
793 (pMgmt->bSwitchChannel != true) &&
794 (pMgmt->b11hEnable == true)) {
795 if (!compare_ether_addr(pMgmt->abyIBSSDFSOwner, CARDpGetCurrentAddress(pMgmt->pAdapter))) {
796 pMgmt->byNewChannel = CARDbyAutoChannelSelect(pMgmt->pAdapter,(unsigned char) pMgmt->uCurrChannel);
797 pMgmt->bSwitchChannel = true;
799 BEACONbSendBeacon(pMgmt);
800 CARDbChannelSwitch(pMgmt->pAdapter, 0, pMgmt->byNewChannel, 10);