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.
21 * Purpose: Implement MIB Data Structure
28 * STAvClearAllCounter - Clear All MIB Counter
29 * STAvUpdateIstStatCounter - Update ISR statistic counter
30 * STAvUpdateRDStatCounter - Update Rx statistic counter
31 * STAvUpdateRDStatCounterEx - Update Rx statistic counter and copy rcv data
32 * STAvUpdateTDStatCounter - Update Tx statistic counter
33 * STAvUpdateTDStatCounterEx - Update Tx statistic counter and copy tx data
34 * STAvUpdate802_11Counter - Update 802.11 mib counter
41 #if !defined(__UPC_H__)
44 #if !defined(__MAC_H__)
47 #if !defined(__TBIT_H__)
50 #if !defined(__TETHER_H__)
53 #if !defined(__MIB_H__)
56 #if !defined(__WCTL_H__)
59 #if !defined(__UMEM_H__)
62 #if !defined(__BASEBAND_H__)
66 /*--------------------- Static Definitions -------------------------*/
67 static int msglevel =MSG_LEVEL_INFO;
68 /*--------------------- Static Classes ----------------------------*/
70 /*--------------------- Static Variables --------------------------*/
72 /*--------------------- Static Functions --------------------------*/
74 /*--------------------- Export Variables --------------------------*/
76 /*--------------------- Export Functions --------------------------*/
81 * Description: Clear All Statistic Counter
85 * pStatistic - Pointer to Statistic Counter Data Structure
92 void STAvClearAllCounter (PSStatCounter pStatistic)
95 ZERO_MEMORY(pStatistic, sizeof(SStatCounter));
100 * Description: Update Isr Statistic Counter
104 * pStatistic - Pointer to Statistic Counter Data Structure
105 * wisr - Interrupt status
112 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic, BYTE byIsr0, BYTE byIsr1)
114 /**********************/
115 /* ABNORMAL interrupt */
116 /**********************/
117 // not any IMR bit invoke irq
119 pStatistic->ISRStat.dwIsrUnknown++;
124 if (BITbIsBitOn(byIsr0, ISR_ACTX)) // ISR, bit0
125 pStatistic->ISRStat.dwIsrTx0OK++; // TXDMA0 successful
127 if (BITbIsBitOn(byIsr0, ISR_BNTX)) // ISR, bit2
128 pStatistic->ISRStat.dwIsrBeaconTxOK++; // BeaconTx successful
130 if (BITbIsBitOn(byIsr0, ISR_RXDMA0)) // ISR, bit3
131 pStatistic->ISRStat.dwIsrRx0OK++; // Rx0 successful
133 if (BITbIsBitOn(byIsr0, ISR_TBTT)) // ISR, bit4
134 pStatistic->ISRStat.dwIsrTBTTInt++; // TBTT successful
136 if (BITbIsBitOn(byIsr0, ISR_SOFTTIMER)) // ISR, bit6
137 pStatistic->ISRStat.dwIsrSTIMERInt++;
139 if (BITbIsBitOn(byIsr0, ISR_WATCHDOG)) // ISR, bit7
140 pStatistic->ISRStat.dwIsrWatchDog++;
143 if (BITbIsBitOn(byIsr1, ISR_FETALERR)) // ISR, bit8
144 pStatistic->ISRStat.dwIsrUnrecoverableError++;
146 if (BITbIsBitOn(byIsr1, ISR_SOFTINT)) // ISR, bit9
147 pStatistic->ISRStat.dwIsrSoftInterrupt++; // software interrupt
149 if (BITbIsBitOn(byIsr1, ISR_MIBNEARFULL)) // ISR, bit10
150 pStatistic->ISRStat.dwIsrMIBNearfull++;
152 if (BITbIsBitOn(byIsr1, ISR_RXNOBUF)) // ISR, bit11
153 pStatistic->ISRStat.dwIsrRxNoBuf++; // Rx No Buff
159 * Description: Update Rx Statistic Counter
163 * pStatistic - Pointer to Statistic Counter Data Structure
165 * byNewRSR - Rx Status
166 * pbyBuffer - Rx Buffer
167 * cbFrameLength - Rx Length
174 void STAvUpdateRDStatCounter (PSStatCounter pStatistic,
175 BYTE byRSR, BYTE byNewRSR, BYTE byRxSts, BYTE byRxRate,
176 PBYTE pbyBuffer, UINT cbFrameLength)
179 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
181 if (BITbIsBitOn(byRSR, RSR_ADDROK))
182 pStatistic->dwRsrADDROk++;
183 if (BITbIsBitOn(byRSR, RSR_CRCOK)) {
184 pStatistic->dwRsrCRCOk++;
186 pStatistic->ullRsrOK++;
188 if (cbFrameLength >= U_ETHER_ADDR_LEN) {
189 // update counters in case that successful transmit
190 if (BITbIsBitOn(byRSR, RSR_ADDRBROAD)) {
191 pStatistic->ullRxBroadcastFrames++;
192 pStatistic->ullRxBroadcastBytes += (ULONGLONG)cbFrameLength;
194 else if (BITbIsBitOn(byRSR, RSR_ADDRMULTI)) {
195 pStatistic->ullRxMulticastFrames++;
196 pStatistic->ullRxMulticastBytes += (ULONGLONG)cbFrameLength;
199 pStatistic->ullRxDirectedFrames++;
200 pStatistic->ullRxDirectedBytes += (ULONGLONG)cbFrameLength;
206 pStatistic->CustomStat.ullRsr11M++;
207 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
208 pStatistic->CustomStat.ullRsr11MCRCOk++;
210 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"11M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr11M, (INT)pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
212 else if(byRxRate==11) {
213 pStatistic->CustomStat.ullRsr5M++;
214 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
215 pStatistic->CustomStat.ullRsr5MCRCOk++;
217 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr5M, (INT)pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
219 else if(byRxRate==4) {
220 pStatistic->CustomStat.ullRsr2M++;
221 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
222 pStatistic->CustomStat.ullRsr2MCRCOk++;
224 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 2M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr2M, (INT)pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
226 else if(byRxRate==2){
227 pStatistic->CustomStat.ullRsr1M++;
228 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
229 pStatistic->CustomStat.ullRsr1MCRCOk++;
231 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT)pStatistic->CustomStat.ullRsr1M, (INT)pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
233 else if(byRxRate==12){
234 pStatistic->CustomStat.ullRsr6M++;
235 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
236 pStatistic->CustomStat.ullRsr6MCRCOk++;
238 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 6M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr6M, (INT)pStatistic->CustomStat.ullRsr6MCRCOk);
240 else if(byRxRate==18){
241 pStatistic->CustomStat.ullRsr9M++;
242 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
243 pStatistic->CustomStat.ullRsr9MCRCOk++;
245 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO" 9M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr9M, (INT)pStatistic->CustomStat.ullRsr9MCRCOk);
247 else if(byRxRate==24){
248 pStatistic->CustomStat.ullRsr12M++;
249 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
250 pStatistic->CustomStat.ullRsr12MCRCOk++;
252 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"12M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr12M, (INT)pStatistic->CustomStat.ullRsr12MCRCOk);
254 else if(byRxRate==36){
255 pStatistic->CustomStat.ullRsr18M++;
256 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
257 pStatistic->CustomStat.ullRsr18MCRCOk++;
259 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"18M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr18M, (INT)pStatistic->CustomStat.ullRsr18MCRCOk);
261 else if(byRxRate==48){
262 pStatistic->CustomStat.ullRsr24M++;
263 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
264 pStatistic->CustomStat.ullRsr24MCRCOk++;
266 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"24M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr24M, (INT)pStatistic->CustomStat.ullRsr24MCRCOk);
268 else if(byRxRate==72){
269 pStatistic->CustomStat.ullRsr36M++;
270 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
271 pStatistic->CustomStat.ullRsr36MCRCOk++;
273 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"36M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr36M, (INT)pStatistic->CustomStat.ullRsr36MCRCOk);
275 else if(byRxRate==96){
276 pStatistic->CustomStat.ullRsr48M++;
277 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
278 pStatistic->CustomStat.ullRsr48MCRCOk++;
280 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"48M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr48M, (INT)pStatistic->CustomStat.ullRsr48MCRCOk);
282 else if(byRxRate==108){
283 pStatistic->CustomStat.ullRsr54M++;
284 if(BITbIsBitOn(byRSR, RSR_CRCOK)) {
285 pStatistic->CustomStat.ullRsr54MCRCOk++;
287 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"54M: ALL[%d], OK[%d]\n", (INT)pStatistic->CustomStat.ullRsr54M, (INT)pStatistic->CustomStat.ullRsr54MCRCOk);
290 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO"Unknown: Total[%d], CRCOK[%d]\n", (INT)pStatistic->dwRsrRxPacket+1, (INT)pStatistic->dwRsrCRCOk);
293 if (BITbIsBitOn(byRSR, RSR_BSSIDOK))
294 pStatistic->dwRsrBSSIDOk++;
296 if (BITbIsBitOn(byRSR, RSR_BCNSSIDOK))
297 pStatistic->dwRsrBCNSSIDOk++;
298 if (BITbIsBitOn(byRSR, RSR_IVLDLEN)) //invalid len (> 2312 byte)
299 pStatistic->dwRsrLENErr++;
300 if (BITbIsBitOn(byRSR, RSR_IVLDTYP)) //invalid packet type
301 pStatistic->dwRsrTYPErr++;
302 if (BITbIsBitOn(byRSR, (RSR_IVLDTYP | RSR_IVLDLEN)) || BITbIsBitOff(byRSR, RSR_CRCOK))
303 pStatistic->dwRsrErr++;
305 if (BITbIsBitOn(byNewRSR, NEWRSR_DECRYPTOK))
306 pStatistic->dwNewRsrDECRYPTOK++;
307 if (BITbIsBitOn(byNewRSR, NEWRSR_CFPIND))
308 pStatistic->dwNewRsrCFP++;
309 if (BITbIsBitOn(byNewRSR, NEWRSR_HWUTSF))
310 pStatistic->dwNewRsrUTSF++;
311 if (BITbIsBitOn(byNewRSR, NEWRSR_BCNHITAID))
312 pStatistic->dwNewRsrHITAID++;
313 if (BITbIsBitOn(byNewRSR, NEWRSR_BCNHITAID0))
314 pStatistic->dwNewRsrHITAID0++;
316 // increase rx packet count
317 pStatistic->dwRsrRxPacket++;
318 pStatistic->dwRsrRxOctet += cbFrameLength;
321 if (IS_TYPE_DATA(pbyBuffer)) {
322 pStatistic->dwRsrRxData++;
323 } else if (IS_TYPE_MGMT(pbyBuffer)){
324 pStatistic->dwRsrRxManage++;
325 } else if (IS_TYPE_CONTROL(pbyBuffer)){
326 pStatistic->dwRsrRxControl++;
329 if (BITbIsBitOn(byRSR, RSR_ADDRBROAD))
330 pStatistic->dwRsrBroadcast++;
331 else if (BITbIsBitOn(byRSR, RSR_ADDRMULTI))
332 pStatistic->dwRsrMulticast++;
334 pStatistic->dwRsrDirected++;
336 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
337 pStatistic->dwRsrRxFragment++;
339 if (cbFrameLength < MIN_PACKET_LEN + 4) {
340 pStatistic->dwRsrRunt++;
342 else if (cbFrameLength == MIN_PACKET_LEN + 4) {
343 pStatistic->dwRsrRxFrmLen64++;
345 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
346 pStatistic->dwRsrRxFrmLen65_127++;
348 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
349 pStatistic->dwRsrRxFrmLen128_255++;
351 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
352 pStatistic->dwRsrRxFrmLen256_511++;
354 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
355 pStatistic->dwRsrRxFrmLen512_1023++;
357 else if ((1024 <= cbFrameLength) && (cbFrameLength <= MAX_PACKET_LEN + 4)) {
358 pStatistic->dwRsrRxFrmLen1024_1518++;
359 } else if (cbFrameLength > MAX_PACKET_LEN + 4) {
360 pStatistic->dwRsrLong++;
368 * Description: Update Rx Statistic Counter and copy Rx buffer
372 * pStatistic - Pointer to Statistic Counter Data Structure
374 * byNewRSR - Rx Status
375 * pbyBuffer - Rx Buffer
376 * cbFrameLength - Rx Length
385 STAvUpdateRDStatCounterEx (
386 PSStatCounter pStatistic,
395 STAvUpdateRDStatCounter(
406 pStatistic->dwCntRxFrmLength = cbFrameLength;
407 // rx pattern, we just see 10 bytes for sample
408 MEMvCopy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
413 * Description: Update Tx Statistic Counter
417 * pStatistic - Pointer to Statistic Counter Data Structure
420 * pbyBuffer - Tx Buffer
421 * cbFrameLength - Tx Length
422 * uIdx - Index of Tx DMA
430 STAvUpdateTDStatCounter (
431 PSStatCounter pStatistic,
438 // increase tx packet count
439 pStatistic->dwTsrTxPacket++;
441 byRetyCnt = (byTSR & 0xF0) >> 4;
442 if (byRetyCnt != 0) {
443 pStatistic->dwTsrRetry++;
444 pStatistic->dwTsrTotalRetry += byRetyCnt;
445 pStatistic->dwTxFail[byRate]+= byRetyCnt;
446 pStatistic->dwTxFail[MAX_RATE] += byRetyCnt;
448 if ( byRetyCnt == 0x1)
449 pStatistic->dwTsrOnceRetry++;
451 pStatistic->dwTsrMoreThanOnceRetry++;
454 pStatistic->dwTxRetryCount[byRetyCnt-1]++;
457 if (BITbIsAllBitsOff(byTSR, (TSR_TMO | TSR_RETRYTMO))) {
459 #ifdef Calcu_LinkQual
461 pStatistic->TxNoRetryOkCount ++;
463 pStatistic->TxRetryOkCount ++;
466 pStatistic->ullTsrOK++;
467 pStatistic->CustomStat.ullTsrAllOK++;
468 // update counters in case that successful transmit
469 pStatistic->dwTxOk[byRate]++;
470 pStatistic->dwTxOk[MAX_RATE]++;
472 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
473 pStatistic->ullTxBroadcastFrames++;
474 pStatistic->ullTxBroadcastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
475 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
476 pStatistic->ullTxMulticastFrames++;
477 pStatistic->ullTxMulticastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
478 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
479 pStatistic->ullTxDirectedFrames++;
480 pStatistic->ullTxDirectedBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
485 #ifdef Calcu_LinkQual
486 pStatistic->TxFailCount ++;
489 pStatistic->dwTsrErr++;
490 if (BITbIsBitOn(byTSR, TSR_RETRYTMO))
491 pStatistic->dwTsrRetryTimeout++;
492 if (BITbIsBitOn(byTSR, TSR_TMO))
493 pStatistic->dwTsrTransmitTimeout++;
496 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
497 pStatistic->dwTsrBroadcast++;
498 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
499 pStatistic->dwTsrMulticast++;
500 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
501 pStatistic->dwTsrDirected++;
508 * Description: Update 802.11 mib counter
512 * p802_11Counter - Pointer to 802.11 mib counter
513 * pStatistic - Pointer to Statistic Counter Data Structure
514 * dwCounter - hardware counter for 802.11 mib
522 STAvUpdate802_11Counter(
523 PSDot11Counters p802_11Counter,
524 PSStatCounter pStatistic,
531 //p802_11Counter->TransmittedFragmentCount
532 p802_11Counter->MulticastTransmittedFrameCount = (ULONGLONG) (pStatistic->dwTsrBroadcast +
533 pStatistic->dwTsrMulticast);
534 p802_11Counter->FailedCount = (ULONGLONG) (pStatistic->dwTsrErr);
535 p802_11Counter->RetryCount = (ULONGLONG) (pStatistic->dwTsrRetry);
536 p802_11Counter->MultipleRetryCount = (ULONGLONG) (pStatistic->dwTsrMoreThanOnceRetry);
537 //p802_11Counter->FrameDuplicateCount
538 p802_11Counter->RTSSuccessCount += (ULONGLONG) byRTSSuccess;
539 p802_11Counter->RTSFailureCount += (ULONGLONG) byRTSFail;
540 p802_11Counter->ACKFailureCount += (ULONGLONG) byACKFail;
541 p802_11Counter->FCSErrorCount += (ULONGLONG) byFCSErr;
542 //p802_11Counter->ReceivedFragmentCount
543 p802_11Counter->MulticastReceivedFrameCount = (ULONGLONG) (pStatistic->dwRsrBroadcast +
544 pStatistic->dwRsrMulticast);
548 * Description: Clear 802.11 mib counter
552 * p802_11Counter - Pointer to 802.11 mib counter
560 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
562 // set memory to zero
563 ZERO_MEMORY(p802_11Counter, sizeof(SDot11Counters));
567 * Description: Clear 802.11 mib counter
571 * pUsbCounter - Pointer to USB mib counter
572 * ntStatus - URB status
581 STAvUpdateUSBCounter(PSUSBCounter pUsbCounter,
586 // if ( ntStatus == USBD_STATUS_CRC ) {
587 pUsbCounter->dwCrc++;