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 - Operation Mode
73 WMAC_CONFIG_MODE eOPMode
76 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
78 pMgmt
->eConfigMode
= eOPMode
;
88 * pMgmtHandle - pointer to management object
89 * wBeaconPeriod - Beacon Period
90 * wATIMWindow - ATIM window
91 * uChannel - channel number
99 VNTWIFIvSetIBSSParameter(
101 unsigned short wBeaconPeriod
,
102 unsigned short wATIMWindow
,
103 unsigned int uChannel
106 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
108 pMgmt
->wIBSSBeaconPeriod
= wBeaconPeriod
;
109 pMgmt
->wIBSSATIMWindow
= wATIMWindow
;
110 pMgmt
->uIBSSChannel
= uChannel
;
120 * pMgmtHandle - pointer to management object
124 * Return Value: current SSID pointer.
128 VNTWIFIpGetCurrentSSID(
132 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
133 return (PWLAN_IE_SSID
) pMgmt
->abyCurrSSID
;
139 * Get current link channel
143 * pMgmtHandle - pointer to management object
147 * Return Value: current Channel.
151 VNTWIFIpGetCurrentChannel(
155 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
156 if (pMgmtHandle
!= NULL
) {
157 return pMgmt
->uCurrChannel
;
165 * Get current Assoc ID
169 * pMgmtHandle - pointer to management object
173 * Return Value: current Assoc ID
181 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
182 return pMgmt
->wCurrAID
;
188 * This routine return max support rate of IES
197 * Return Value: max support rate
201 VNTWIFIbyGetMaxSupportRate(
202 PWLAN_IE_SUPP_RATES pSupportRateIEs
,
203 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
206 unsigned char byMaxSupportRate
= RATE_1M
;
207 unsigned char bySupportRate
= RATE_1M
;
210 if (pSupportRateIEs
) {
211 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
212 bySupportRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
213 if (bySupportRate
> byMaxSupportRate
) {
214 byMaxSupportRate
= bySupportRate
;
218 if (pExtSupportRateIEs
) {
219 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
220 bySupportRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
221 if (bySupportRate
> byMaxSupportRate
) {
222 byMaxSupportRate
= bySupportRate
;
227 return byMaxSupportRate
;
233 * This routine return data rate of ACK packtet
243 * Return Value: max support rate
247 VNTWIFIbyGetACKTxRate(
248 unsigned char byRxDataRate
,
249 PWLAN_IE_SUPP_RATES pSupportRateIEs
,
250 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
253 unsigned char byMaxAckRate
;
254 unsigned char byBasicRate
;
257 if (byRxDataRate
<= RATE_11M
) {
258 byMaxAckRate
= RATE_1M
;
260 // 24M is mandatory for 802.11a and 802.11g
261 byMaxAckRate
= RATE_24M
;
263 if (pSupportRateIEs
) {
264 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
265 if (pSupportRateIEs
->abyRates
[ii
] & 0x80) {
266 byBasicRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
267 if ((byBasicRate
<= byRxDataRate
) &&
268 (byBasicRate
> byMaxAckRate
)) {
269 byMaxAckRate
= byBasicRate
;
274 if (pExtSupportRateIEs
) {
275 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
276 if (pExtSupportRateIEs
->abyRates
[ii
] & 0x80) {
277 byBasicRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
278 if ((byBasicRate
<= byRxDataRate
) &&
279 (byBasicRate
> byMaxAckRate
)) {
280 byMaxAckRate
= byBasicRate
;
292 * Set Authentication Mode
296 * pMgmtHandle - pointer to management object
297 * eAuthMode - Authentication mode
305 VNTWIFIvSetAuthenticationMode(
307 WMAC_AUTHENTICATION_MODE eAuthMode
310 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
312 pMgmt
->eAuthenMode
= eAuthMode
;
313 if ((eAuthMode
== WMAC_AUTH_SHAREKEY
) ||
314 (eAuthMode
== WMAC_AUTH_AUTO
)) {
315 pMgmt
->bShareKeyAlgorithm
= true;
317 pMgmt
->bShareKeyAlgorithm
= false;
324 * Set Encryption Mode
328 * pMgmtHandle - pointer to management object
329 * eAuthMode - Authentication mode
337 VNTWIFIvSetEncryptionMode(
339 WMAC_ENCRYPTION_MODE eEncryptionMode
342 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
344 pMgmt
->eEncryptionMode
= eEncryptionMode
;
345 if ((eEncryptionMode
== WMAC_ENCRYPTION_WEPEnabled
) ||
346 (eEncryptionMode
== WMAC_ENCRYPTION_TKIPEnabled
) ||
347 (eEncryptionMode
== WMAC_ENCRYPTION_AESEnabled
)) {
348 pMgmt
->bPrivacyInvoked
= true;
350 pMgmt
->bPrivacyInvoked
= false;
355 VNTWIFIbConfigPhyMode(
357 CARD_PHY_TYPE ePhyType
360 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
362 if ((ePhyType
!= PHY_TYPE_AUTO
) &&
363 (ePhyType
!= pMgmt
->eCurrentPHYMode
)) {
364 if (CARDbSetPhyParameter(pMgmt
->pAdapter
, ePhyType
, 0, 0, NULL
, NULL
) == true) {
365 pMgmt
->eCurrentPHYMode
= ePhyType
;
370 pMgmt
->eConfigPHYMode
= ePhyType
;
375 VNTWIFIbGetConfigPhyMode(
380 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
382 if ((pMgmt
!= NULL
) && (pePhyType
!= NULL
)) {
383 *(PCARD_PHY_TYPE
)pePhyType
= pMgmt
->eConfigPHYMode
;
390 * Clear BSS List Database except current assoc BSS
394 * pMgmtHandle - Management Object structure
395 * bLinkPass - Current Link status
398 * Return Value: None.
405 * Query BSS List in management database
409 * pMgmtHandle - Management Object structure
411 * puBSSCount - BSS count
412 * pvFirstBSS - pointer to first BSS
414 * Return Value: None.
419 VNTWIFIvQueryBSSList(void *pMgmtHandle
, unsigned int *puBSSCount
, void **pvFirstBSS
)
422 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
423 PKnownBSS pBSS
= NULL
;
424 unsigned int uCount
= 0;
428 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
429 pBSS
= &(pMgmt
->sBSSList
[ii
]);
430 if (!pBSS
->bActive
) {
433 if (*pvFirstBSS
== NULL
) {
434 *pvFirstBSS
= &(pMgmt
->sBSSList
[ii
]);
438 *puBSSCount
= uCount
;
448 PKnownBSS pBSS
= (PKnownBSS
) pvCurrentBSS
;
449 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
453 while (*pvNextBSS
== NULL
) {
455 if (pBSS
> &(pMgmt
->sBSSList
[MAX_BSS_NUM
])) {
458 if (pBSS
->bActive
== true) {
468 * Update Tx attemps, Tx failure counter in Node DB
478 VNTWIFIvUpdateNodeTxCounter(
480 unsigned char *pbyDestAddress
,
482 unsigned short wRate
,
483 unsigned char *pbyTxFailCount
486 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
487 unsigned int uNodeIndex
= 0;
490 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
491 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
492 if (BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
) == false) {
496 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxAttempts
++;
498 // transmit success, TxAttempts at least plus one
499 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[MAX_RATE
]++;
500 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[wRate
]++;
502 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFailures
++;
504 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxRetry
+= pbyTxFailCount
[MAX_RATE
];
505 for (ii
= 0; ii
< MAX_RATE
; ii
++) {
506 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[ii
] += pbyTxFailCount
[ii
];
514 unsigned char *pbyDestAddress
,
515 unsigned short *pwTxDataRate
,
516 unsigned char *pbyACKRate
,
517 unsigned char *pbyCCKBasicRate
,
518 unsigned char *pbyOFDMBasicRate
521 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
522 unsigned int uNodeIndex
= 0;
523 unsigned short wTxDataRate
= RATE_1M
;
524 unsigned char byACKRate
= RATE_1M
;
525 unsigned char byCCKBasicRate
= RATE_1M
;
526 unsigned char byOFDMBasicRate
= RATE_24M
;
527 PWLAN_IE_SUPP_RATES pSupportRateIEs
= NULL
;
528 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
= NULL
;
530 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
531 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
532 // Adhoc Tx rate decided from node DB
533 if (BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
)) {
534 wTxDataRate
= (pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
);
535 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrSuppRates
);
536 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrExtSuppRates
);
538 if (pMgmt
->eCurrentPHYMode
!= PHY_TYPE_11A
) {
539 wTxDataRate
= RATE_2M
;
541 wTxDataRate
= RATE_24M
;
543 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
544 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
546 } else { // Infrastructure: rate decided from AP Node, index = 0
548 wTxDataRate
= (pMgmt
->sNodeDBTable
[0].wTxDataRate
);
550 printk(KERN_DEBUG
"GetTxRate:AP MAC is %pM,TxRate is %d\n",
551 pMgmt
->sNodeDBTable
[0].abyMACAddr
, wTxDataRate
);
554 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
555 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
557 byACKRate
= VNTWIFIbyGetACKTxRate((unsigned char) wTxDataRate
,
561 if (byACKRate
> (unsigned char) wTxDataRate
) {
562 byACKRate
= (unsigned char) wTxDataRate
;
564 byCCKBasicRate
= VNTWIFIbyGetACKTxRate(RATE_11M
,
568 byOFDMBasicRate
= VNTWIFIbyGetACKTxRate(RATE_54M
,
572 *pwTxDataRate
= wTxDataRate
;
573 *pbyACKRate
= byACKRate
;
574 *pbyCCKBasicRate
= byCCKBasicRate
;
575 *pbyOFDMBasicRate
= byOFDMBasicRate
;
580 VNTWIFIbyGetKeyCypher(
585 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
588 return pMgmt
->byCSSGK
;
590 return pMgmt
->byCSSPK
;
597 void *pAdapterHandler,
600 PSMgmtObject pMgmt = NULL;
603 pMgmt = (PSMgmtObject)kmalloc(sizeof(SMgmtObject), (int)GFP_ATOMIC);
605 *pMgmtHandler = NULL;
609 memset(pMgmt, 0, sizeof(SMgmtObject));
610 pMgmt->pAdapter = (void *) pAdapterHandler;
612 // should initial MAC address abyMACAddr
613 for (ii=0; ii<WLAN_BSSID_LEN; ii++) {
614 pMgmt->abyDesireBSSID[ii] = 0xFF;
616 pMgmt->pbyPSPacketPool = &pMgmt->byPSPacketPool[0];
617 pMgmt->pbyMgmtPacketPool = &pMgmt->byMgmtPacketPool[0];
618 pMgmt->byCSSPK = KEY_CTL_NONE;
619 pMgmt->byCSSGK = KEY_CTL_NONE;
620 pMgmt->wIBSSBeaconPeriod = DEFAULT_IBSS_BI;
622 pMgmt->cbFreeCmdQueue = CMD_Q_SIZE;
623 pMgmt->uCmdDequeueIdx = 0;
624 pMgmt->uCmdEnqueueIdx = 0;
625 pMgmt->eCommandState = WLAN_CMD_STATE_IDLE;
626 pMgmt->bCmdStop = false;
627 pMgmt->bCmdRunning = false;
629 *pMgmtHandler = pMgmt;
635 VNTWIFIbSetPMKIDCache(
637 unsigned long ulCount
,
641 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
643 if (ulCount
> MAX_PMKID_CACHE
) {
646 pMgmt
->gsPMKIDCache
.BSSIDInfoCount
= ulCount
;
647 memcpy(pMgmt
->gsPMKIDCache
.BSSIDInfo
, pPMKIDInfo
, (ulCount
*sizeof(PMKIDInfo
)));
652 VNTWIFIwGetMaxSupportRate(
656 unsigned short wRate
= RATE_54M
;
657 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
659 for (wRate
= RATE_54M
; wRate
> RATE_1M
; wRate
--) {
660 if (pMgmt
->sNodeDBTable
[0].wSuppRate
& (1<<wRate
)) {
664 if (pMgmt
->eCurrentPHYMode
== PHY_TYPE_11A
) {
677 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
679 pMgmt
->b11hEnable
= b11hEnable
;
683 VNTWIFIbMeasureReport(
687 unsigned char byReportMode
,
688 unsigned char byBasicMap
,
689 unsigned char byCCAFraction
,
690 unsigned char *pbyRPIs
693 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
694 unsigned char *pbyCurrentEID
= (unsigned char *)(pMgmt
->pCurrMeasureEIDRep
);
696 //spin_lock_irq(&pDevice->lock);
697 if ((pvMeasureEID
!= NULL
) &&
698 (pMgmt
->uLengthOfRepEIDs
< (WLAN_A3FR_MAXLEN
- sizeof(MEASEURE_REP
) - sizeof(WLAN_80211HDR_A3
) - 3))
700 pMgmt
->pCurrMeasureEIDRep
->byElementID
= WLAN_EID_MEASURE_REP
;
701 pMgmt
->pCurrMeasureEIDRep
->len
= 3;
702 pMgmt
->pCurrMeasureEIDRep
->byToken
= ((PWLAN_IE_MEASURE_REQ
)pvMeasureEID
)->byToken
;
703 pMgmt
->pCurrMeasureEIDRep
->byMode
= byReportMode
;
704 pMgmt
->pCurrMeasureEIDRep
->byType
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byType
;
705 switch (pMgmt
->pCurrMeasureEIDRep
->byType
) {
706 case MEASURE_TYPE_BASIC
:
707 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_BASIC
);
708 memcpy(&(pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
),
709 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
710 sizeof(MEASEURE_REQ
));
711 pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
.byMap
= byBasicMap
;
713 case MEASURE_TYPE_CCA
:
714 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_CCA
);
715 memcpy(&(pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
),
716 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
717 sizeof(MEASEURE_REQ
));
718 pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
.byCCABusyFraction
= byCCAFraction
;
720 case MEASURE_TYPE_RPI
:
721 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_RPI
);
722 memcpy(&(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
),
723 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
724 sizeof(MEASEURE_REQ
));
725 memcpy(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
.abyRPIdensity
, pbyRPIs
, 8);
730 pbyCurrentEID
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
731 pMgmt
->uLengthOfRepEIDs
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
732 pMgmt
->pCurrMeasureEIDRep
= (PWLAN_IE_MEASURE_REP
) pbyCurrentEID
;
735 IEEE11hbMSRRepTx(pMgmt
);
737 //spin_unlock_irq(&pDevice->lock);
742 VNTWIFIbChannelSwitch(
744 unsigned char byNewChannel
747 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
749 //spin_lock_irq(&pDevice->lock);
750 pMgmt
->uCurrChannel
= byNewChannel
;
751 pMgmt
->bSwitchChannel
= false;
752 //spin_unlock_irq(&pDevice->lock);