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 -------------------------*/
43 /*--------------------- Static Classes ----------------------------*/
45 /*--------------------- Static Variables --------------------------*/
47 /*--------------------- Static Functions --------------------------*/
49 /*--------------------- Export Variables --------------------------*/
51 /*--------------------- Export Functions --------------------------*/
60 * pMgmtHandle - pointer to management object
61 * eOPMode - Operation Mode
71 WMAC_CONFIG_MODE eOPMode
74 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
76 pMgmt
->eConfigMode
= eOPMode
;
86 * pMgmtHandle - pointer to management object
87 * wBeaconPeriod - Beacon Period
88 * wATIMWindow - ATIM window
89 * uChannel - channel number
97 VNTWIFIvSetIBSSParameter(
99 unsigned short wBeaconPeriod
,
100 unsigned short wATIMWindow
,
101 unsigned int uChannel
104 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
106 pMgmt
->wIBSSBeaconPeriod
= wBeaconPeriod
;
107 pMgmt
->wIBSSATIMWindow
= wATIMWindow
;
108 pMgmt
->uIBSSChannel
= uChannel
;
118 * pMgmtHandle - pointer to management object
122 * Return Value: current SSID pointer.
126 VNTWIFIpGetCurrentSSID(
130 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
131 return (PWLAN_IE_SSID
) pMgmt
->abyCurrSSID
;
137 * Get current link channel
141 * pMgmtHandle - pointer to management object
145 * Return Value: current Channel.
149 VNTWIFIpGetCurrentChannel(
153 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
154 if (pMgmtHandle
!= NULL
)
155 return pMgmt
->uCurrChannel
;
163 * Get current Assoc ID
167 * pMgmtHandle - pointer to management object
171 * Return Value: current Assoc ID
179 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
180 return pMgmt
->wCurrAID
;
186 * This routine return max support rate of IES
195 * Return Value: max support rate
199 VNTWIFIbyGetMaxSupportRate(
200 PWLAN_IE_SUPP_RATES pSupportRateIEs
,
201 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
204 unsigned char byMaxSupportRate
= RATE_1M
;
205 unsigned char bySupportRate
= RATE_1M
;
208 if (pSupportRateIEs
) {
209 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
210 bySupportRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
211 if (bySupportRate
> byMaxSupportRate
)
212 byMaxSupportRate
= bySupportRate
;
216 if (pExtSupportRateIEs
) {
217 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
218 bySupportRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
219 if (bySupportRate
> byMaxSupportRate
)
220 byMaxSupportRate
= bySupportRate
;
225 return byMaxSupportRate
;
231 * This routine return data rate of ACK packtet
241 * Return Value: max support rate
245 VNTWIFIbyGetACKTxRate(
246 unsigned char byRxDataRate
,
247 PWLAN_IE_SUPP_RATES pSupportRateIEs
,
248 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
251 unsigned char byMaxAckRate
;
252 unsigned char byBasicRate
;
255 if (byRxDataRate
<= RATE_11M
) {
256 byMaxAckRate
= RATE_1M
;
258 // 24M is mandatory for 802.11a and 802.11g
259 byMaxAckRate
= RATE_24M
;
261 if (pSupportRateIEs
) {
262 for (ii
= 0; ii
< pSupportRateIEs
->len
; ii
++) {
263 if (pSupportRateIEs
->abyRates
[ii
] & 0x80) {
264 byBasicRate
= DATARATEbyGetRateIdx(pSupportRateIEs
->abyRates
[ii
]);
265 if ((byBasicRate
<= byRxDataRate
) &&
266 (byBasicRate
> byMaxAckRate
)) {
267 byMaxAckRate
= byBasicRate
;
272 if (pExtSupportRateIEs
) {
273 for (ii
= 0; ii
< pExtSupportRateIEs
->len
; ii
++) {
274 if (pExtSupportRateIEs
->abyRates
[ii
] & 0x80) {
275 byBasicRate
= DATARATEbyGetRateIdx(pExtSupportRateIEs
->abyRates
[ii
]);
276 if ((byBasicRate
<= byRxDataRate
) &&
277 (byBasicRate
> byMaxAckRate
)) {
278 byMaxAckRate
= byBasicRate
;
290 * Set Authentication Mode
294 * pMgmtHandle - pointer to management object
295 * eAuthMode - Authentication mode
303 VNTWIFIvSetAuthenticationMode(
305 WMAC_AUTHENTICATION_MODE eAuthMode
308 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
310 pMgmt
->eAuthenMode
= eAuthMode
;
311 if ((eAuthMode
== WMAC_AUTH_SHAREKEY
) ||
312 (eAuthMode
== WMAC_AUTH_AUTO
)) {
313 pMgmt
->bShareKeyAlgorithm
= true;
315 pMgmt
->bShareKeyAlgorithm
= false;
322 * Set Encryption Mode
326 * pMgmtHandle - pointer to management object
327 * eAuthMode - Authentication mode
335 VNTWIFIvSetEncryptionMode(
337 WMAC_ENCRYPTION_MODE eEncryptionMode
340 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
342 pMgmt
->eEncryptionMode
= eEncryptionMode
;
343 if ((eEncryptionMode
== WMAC_ENCRYPTION_WEPEnabled
) ||
344 (eEncryptionMode
== WMAC_ENCRYPTION_TKIPEnabled
) ||
345 (eEncryptionMode
== WMAC_ENCRYPTION_AESEnabled
)) {
346 pMgmt
->bPrivacyInvoked
= true;
348 pMgmt
->bPrivacyInvoked
= false;
353 VNTWIFIbConfigPhyMode(
355 CARD_PHY_TYPE ePhyType
358 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
360 if ((ePhyType
!= PHY_TYPE_AUTO
) &&
361 (ePhyType
!= pMgmt
->eCurrentPHYMode
)) {
362 if (CARDbSetPhyParameter(pMgmt
->pAdapter
, ePhyType
, 0, 0, NULL
, NULL
) == true)
363 pMgmt
->eCurrentPHYMode
= ePhyType
;
367 pMgmt
->eConfigPHYMode
= ePhyType
;
372 VNTWIFIbGetConfigPhyMode(
377 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
379 if ((pMgmt
!= NULL
) && (pePhyType
!= NULL
))
380 *(PCARD_PHY_TYPE
)pePhyType
= pMgmt
->eConfigPHYMode
;
386 * Clear BSS List Database except current assoc BSS
390 * pMgmtHandle - Management Object structure
391 * bLinkPass - Current Link status
394 * Return Value: None.
401 * Query BSS List in management database
405 * pMgmtHandle - Management Object structure
407 * puBSSCount - BSS count
408 * pvFirstBSS - pointer to first BSS
410 * Return Value: None.
415 VNTWIFIvQueryBSSList(void *pMgmtHandle
, unsigned int *puBSSCount
, void **pvFirstBSS
)
418 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
419 PKnownBSS pBSS
= NULL
;
420 unsigned int uCount
= 0;
424 for (ii
= 0; ii
< MAX_BSS_NUM
; ii
++) {
425 pBSS
= &(pMgmt
->sBSSList
[ii
]);
429 if (*pvFirstBSS
== NULL
)
430 *pvFirstBSS
= &(pMgmt
->sBSSList
[ii
]);
434 *puBSSCount
= uCount
;
444 PKnownBSS pBSS
= (PKnownBSS
) pvCurrentBSS
;
445 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
449 while (*pvNextBSS
== NULL
) {
451 if (pBSS
> &(pMgmt
->sBSSList
[MAX_BSS_NUM
]))
454 if (pBSS
->bActive
== true) {
464 * Update Tx attemps, Tx failure counter in Node DB
474 VNTWIFIvUpdateNodeTxCounter(
476 unsigned char *pbyDestAddress
,
478 unsigned short wRate
,
479 unsigned char *pbyTxFailCount
482 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
483 unsigned int uNodeIndex
= 0;
486 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
487 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
488 if (BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
) == false)
492 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxAttempts
++;
494 // transmit success, TxAttempts at least plus one
495 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[MAX_RATE
]++;
496 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxOk
[wRate
]++;
498 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFailures
++;
500 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxRetry
+= pbyTxFailCount
[MAX_RATE
];
501 for (ii
= 0; ii
< MAX_RATE
; ii
++)
502 pMgmt
->sNodeDBTable
[uNodeIndex
].uTxFail
[ii
] += pbyTxFailCount
[ii
];
510 unsigned char *pbyDestAddress
,
511 unsigned short *pwTxDataRate
,
512 unsigned char *pbyACKRate
,
513 unsigned char *pbyCCKBasicRate
,
514 unsigned char *pbyOFDMBasicRate
517 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
518 unsigned int uNodeIndex
= 0;
519 unsigned short wTxDataRate
= RATE_1M
;
520 unsigned char byACKRate
= RATE_1M
;
521 unsigned char byCCKBasicRate
= RATE_1M
;
522 unsigned char byOFDMBasicRate
= RATE_24M
;
523 PWLAN_IE_SUPP_RATES pSupportRateIEs
= NULL
;
524 PWLAN_IE_SUPP_RATES pExtSupportRateIEs
= NULL
;
526 if ((pMgmt
->eCurrMode
== WMAC_MODE_IBSS_STA
) ||
527 (pMgmt
->eCurrMode
== WMAC_MODE_ESS_AP
)) {
528 // Adhoc Tx rate decided from node DB
529 if (BSSDBbIsSTAInNodeDB(pMgmt
, pbyDestAddress
, &uNodeIndex
)) {
530 wTxDataRate
= (pMgmt
->sNodeDBTable
[uNodeIndex
].wTxDataRate
);
531 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrSuppRates
);
532 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) (pMgmt
->sNodeDBTable
[uNodeIndex
].abyCurrExtSuppRates
);
534 if (pMgmt
->eCurrentPHYMode
!= PHY_TYPE_11A
)
535 wTxDataRate
= RATE_2M
;
537 wTxDataRate
= RATE_24M
;
539 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
540 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
542 } else { // Infrastructure: rate decided from AP Node, index = 0
544 wTxDataRate
= (pMgmt
->sNodeDBTable
[0].wTxDataRate
);
546 printk(KERN_DEBUG
"GetTxRate:AP MAC is %pM,TxRate is %d\n",
547 pMgmt
->sNodeDBTable
[0].abyMACAddr
, wTxDataRate
);
550 pSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrSuppRates
;
551 pExtSupportRateIEs
= (PWLAN_IE_SUPP_RATES
) pMgmt
->abyCurrExtSuppRates
;
553 byACKRate
= VNTWIFIbyGetACKTxRate((unsigned char) wTxDataRate
,
557 if (byACKRate
> (unsigned char) wTxDataRate
)
558 byACKRate
= (unsigned char) wTxDataRate
;
560 byCCKBasicRate
= VNTWIFIbyGetACKTxRate(RATE_11M
,
564 byOFDMBasicRate
= VNTWIFIbyGetACKTxRate(RATE_54M
,
568 *pwTxDataRate
= wTxDataRate
;
569 *pbyACKRate
= byACKRate
;
570 *pbyCCKBasicRate
= byCCKBasicRate
;
571 *pbyOFDMBasicRate
= byOFDMBasicRate
;
576 VNTWIFIbyGetKeyCypher(
581 PSMgmtObject pMgmt
= (PSMgmtObject
)pMgmtHandle
;
584 return pMgmt
->byCSSGK
;
586 return pMgmt
->byCSSPK
;
590 VNTWIFIbSetPMKIDCache(
592 unsigned long ulCount
,
596 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
598 if (ulCount
> MAX_PMKID_CACHE
)
601 pMgmt
->gsPMKIDCache
.BSSIDInfoCount
= ulCount
;
602 memcpy(pMgmt
->gsPMKIDCache
.BSSIDInfo
, pPMKIDInfo
, (ulCount
*sizeof(PMKIDInfo
)));
607 VNTWIFIwGetMaxSupportRate(
611 unsigned short wRate
= RATE_54M
;
612 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
614 for (wRate
= RATE_54M
; wRate
> RATE_1M
; wRate
--) {
615 if (pMgmt
->sNodeDBTable
[0].wSuppRate
& (1<<wRate
))
619 if (pMgmt
->eCurrentPHYMode
== PHY_TYPE_11A
)
631 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
633 pMgmt
->b11hEnable
= b11hEnable
;
637 VNTWIFIbMeasureReport(
641 unsigned char byReportMode
,
642 unsigned char byBasicMap
,
643 unsigned char byCCAFraction
,
644 unsigned char *pbyRPIs
647 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
648 unsigned char *pbyCurrentEID
= (unsigned char *)(pMgmt
->pCurrMeasureEIDRep
);
650 if ((pvMeasureEID
!= NULL
) &&
651 (pMgmt
->uLengthOfRepEIDs
< (WLAN_A3FR_MAXLEN
- sizeof(MEASEURE_REP
) - sizeof(WLAN_80211HDR_A3
) - 3))
653 pMgmt
->pCurrMeasureEIDRep
->byElementID
= WLAN_EID_MEASURE_REP
;
654 pMgmt
->pCurrMeasureEIDRep
->len
= 3;
655 pMgmt
->pCurrMeasureEIDRep
->byToken
= ((PWLAN_IE_MEASURE_REQ
)pvMeasureEID
)->byToken
;
656 pMgmt
->pCurrMeasureEIDRep
->byMode
= byReportMode
;
657 pMgmt
->pCurrMeasureEIDRep
->byType
= ((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->byType
;
658 switch (pMgmt
->pCurrMeasureEIDRep
->byType
) {
659 case MEASURE_TYPE_BASIC
:
660 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_BASIC
);
661 memcpy(&(pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
),
662 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
663 sizeof(MEASEURE_REQ
));
664 pMgmt
->pCurrMeasureEIDRep
->sRep
.sBasic
.byMap
= byBasicMap
;
666 case MEASURE_TYPE_CCA
:
667 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_CCA
);
668 memcpy(&(pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
),
669 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
670 sizeof(MEASEURE_REQ
));
671 pMgmt
->pCurrMeasureEIDRep
->sRep
.sCCA
.byCCABusyFraction
= byCCAFraction
;
673 case MEASURE_TYPE_RPI
:
674 pMgmt
->pCurrMeasureEIDRep
->len
+= sizeof(MEASEURE_REP_RPI
);
675 memcpy(&(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
),
676 &(((PWLAN_IE_MEASURE_REQ
) pvMeasureEID
)->sReq
),
677 sizeof(MEASEURE_REQ
));
678 memcpy(pMgmt
->pCurrMeasureEIDRep
->sRep
.sRPI
.abyRPIdensity
, pbyRPIs
, 8);
683 pbyCurrentEID
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
684 pMgmt
->uLengthOfRepEIDs
+= (2 + pMgmt
->pCurrMeasureEIDRep
->len
);
685 pMgmt
->pCurrMeasureEIDRep
= (PWLAN_IE_MEASURE_REP
) pbyCurrentEID
;
688 IEEE11hbMSRRepTx(pMgmt
);
695 VNTWIFIbChannelSwitch(
697 unsigned char byNewChannel
700 PSMgmtObject pMgmt
= (PSMgmtObject
) pMgmtObject
;
702 pMgmt
->uCurrChannel
= byNewChannel
;
703 pMgmt
->bSwitchChannel
= false;