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
47 /*--------------------- Static Definitions -------------------------*/
48 static int msglevel
=MSG_LEVEL_INFO
;
49 /*--------------------- Static Classes ----------------------------*/
51 /*--------------------- Static Variables --------------------------*/
53 /*--------------------- Static Functions --------------------------*/
55 /*--------------------- Export Variables --------------------------*/
57 /*--------------------- Export Functions --------------------------*/
62 * Description: Clear All Statistic Counter
66 * pStatistic - Pointer to Statistic Counter Data Structure
73 void STAvClearAllCounter (PSStatCounter pStatistic
)
76 memset(pStatistic
, 0, sizeof(SStatCounter
));
81 * Description: Update Isr Statistic Counter
85 * pStatistic - Pointer to Statistic Counter Data Structure
86 * wisr - Interrupt status
93 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic
, DWORD dwIsr
)
95 /**********************/
96 /* ABNORMAL interrupt */
97 /**********************/
98 // not any IMR bit invoke irq
101 pStatistic
->ISRStat
.dwIsrUnknown
++;
106 if (dwIsr
& ISR_TXDMA0
) // ISR, bit0
107 pStatistic
->ISRStat
.dwIsrTx0OK
++; // TXDMA0 successful
109 if (dwIsr
& ISR_AC0DMA
) // ISR, bit1
110 pStatistic
->ISRStat
.dwIsrAC0TxOK
++; // AC0DMA successful
112 if (dwIsr
& ISR_BNTX
) // ISR, bit2
113 pStatistic
->ISRStat
.dwIsrBeaconTxOK
++; // BeaconTx successful
115 if (dwIsr
& ISR_RXDMA0
) // ISR, bit3
116 pStatistic
->ISRStat
.dwIsrRx0OK
++; // Rx0 successful
118 if (dwIsr
& ISR_TBTT
) // ISR, bit4
119 pStatistic
->ISRStat
.dwIsrTBTTInt
++; // TBTT successful
121 if (dwIsr
& ISR_SOFTTIMER
) // ISR, bit6
122 pStatistic
->ISRStat
.dwIsrSTIMERInt
++;
124 if (dwIsr
& ISR_WATCHDOG
) // ISR, bit7
125 pStatistic
->ISRStat
.dwIsrWatchDog
++;
127 if (dwIsr
& ISR_FETALERR
) // ISR, bit8
128 pStatistic
->ISRStat
.dwIsrUnrecoverableError
++;
130 if (dwIsr
& ISR_SOFTINT
) // ISR, bit9
131 pStatistic
->ISRStat
.dwIsrSoftInterrupt
++; // software interrupt
133 if (dwIsr
& ISR_MIBNEARFULL
) // ISR, bit10
134 pStatistic
->ISRStat
.dwIsrMIBNearfull
++;
136 if (dwIsr
& ISR_RXNOBUF
) // ISR, bit11
137 pStatistic
->ISRStat
.dwIsrRxNoBuf
++; // Rx No Buff
139 if (dwIsr
& ISR_RXDMA1
) // ISR, bit12
140 pStatistic
->ISRStat
.dwIsrRx1OK
++; // Rx1 successful
142 // if (dwIsr & ISR_ATIMTX) // ISR, bit13
143 // pStatistic->ISRStat.dwIsrATIMTxOK++; // ATIMTX successful
145 // if (dwIsr & ISR_SYNCTX) // ISR, bit14
146 // pStatistic->ISRStat.dwIsrSYNCTxOK++; // SYNCTX successful
148 // if (dwIsr & ISR_CFPEND) // ISR, bit18
149 // pStatistic->ISRStat.dwIsrCFPEnd++;
151 // if (dwIsr & ISR_ATIMEND) // ISR, bit19
152 // pStatistic->ISRStat.dwIsrATIMEnd++;
154 // if (dwIsr & ISR_SYNCFLUSHOK) // ISR, bit20
155 // pStatistic->ISRStat.dwIsrSYNCFlushOK++;
157 if (dwIsr
& ISR_SOFTTIMER1
) // ISR, bit21
158 pStatistic
->ISRStat
.dwIsrSTIMER1Int
++;
164 * Description: Update Rx Statistic Counter
168 * pStatistic - Pointer to Statistic Counter Data Structure
170 * byNewRSR - Rx Status
171 * pbyBuffer - Rx Buffer
172 * cbFrameLength - Rx Length
179 void STAvUpdateRDStatCounter (PSStatCounter pStatistic
,
180 BYTE byRSR
, BYTE byNewRSR
, BYTE byRxRate
,
181 PBYTE pbyBuffer
, UINT cbFrameLength
)
184 PS802_11Header pHeader
= (PS802_11Header
)pbyBuffer
;
186 if (byRSR
& RSR_ADDROK
)
187 pStatistic
->dwRsrADDROk
++;
188 if (byRSR
& RSR_CRCOK
) {
189 pStatistic
->dwRsrCRCOk
++;
191 pStatistic
->ullRsrOK
++;
193 if (cbFrameLength
>= U_ETHER_ADDR_LEN
) {
194 // update counters in case that successful transmit
195 if (byRSR
& RSR_ADDRBROAD
) {
196 pStatistic
->ullRxBroadcastFrames
++;
197 pStatistic
->ullRxBroadcastBytes
+= (ULONGLONG
)cbFrameLength
;
199 else if (byRSR
& RSR_ADDRMULTI
) {
200 pStatistic
->ullRxMulticastFrames
++;
201 pStatistic
->ullRxMulticastBytes
+= (ULONGLONG
)cbFrameLength
;
204 pStatistic
->ullRxDirectedFrames
++;
205 pStatistic
->ullRxDirectedBytes
+= (ULONGLONG
)cbFrameLength
;
211 pStatistic
->CustomStat
.ullRsr11M
++;
212 if(byRSR
& RSR_CRCOK
) {
213 pStatistic
->CustomStat
.ullRsr11MCRCOk
++;
215 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"11M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr11M
, (INT
)pStatistic
->CustomStat
.ullRsr11MCRCOk
, byRSR
);
217 else if(byRxRate
==11) {
218 pStatistic
->CustomStat
.ullRsr5M
++;
219 if(byRSR
& RSR_CRCOK
) {
220 pStatistic
->CustomStat
.ullRsr5MCRCOk
++;
222 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr5M
, (INT
)pStatistic
->CustomStat
.ullRsr5MCRCOk
, byRSR
);
224 else if(byRxRate
==4) {
225 pStatistic
->CustomStat
.ullRsr2M
++;
226 if(byRSR
& RSR_CRCOK
) {
227 pStatistic
->CustomStat
.ullRsr2MCRCOk
++;
229 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 2M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr2M
, (INT
)pStatistic
->CustomStat
.ullRsr2MCRCOk
, byRSR
);
231 else if(byRxRate
==2){
232 pStatistic
->CustomStat
.ullRsr1M
++;
233 if(byRSR
& RSR_CRCOK
) {
234 pStatistic
->CustomStat
.ullRsr1MCRCOk
++;
236 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr1M
, (INT
)pStatistic
->CustomStat
.ullRsr1MCRCOk
, byRSR
);
238 else if(byRxRate
==12){
239 pStatistic
->CustomStat
.ullRsr6M
++;
240 if(byRSR
& RSR_CRCOK
) {
241 pStatistic
->CustomStat
.ullRsr6MCRCOk
++;
243 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 6M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr6M
, (INT
)pStatistic
->CustomStat
.ullRsr6MCRCOk
);
245 else if(byRxRate
==18){
246 pStatistic
->CustomStat
.ullRsr9M
++;
247 if(byRSR
& RSR_CRCOK
) {
248 pStatistic
->CustomStat
.ullRsr9MCRCOk
++;
250 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 9M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr9M
, (INT
)pStatistic
->CustomStat
.ullRsr9MCRCOk
);
252 else if(byRxRate
==24){
253 pStatistic
->CustomStat
.ullRsr12M
++;
254 if(byRSR
& RSR_CRCOK
) {
255 pStatistic
->CustomStat
.ullRsr12MCRCOk
++;
257 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"12M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr12M
, (INT
)pStatistic
->CustomStat
.ullRsr12MCRCOk
);
259 else if(byRxRate
==36){
260 pStatistic
->CustomStat
.ullRsr18M
++;
261 if(byRSR
& RSR_CRCOK
) {
262 pStatistic
->CustomStat
.ullRsr18MCRCOk
++;
264 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"18M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr18M
, (INT
)pStatistic
->CustomStat
.ullRsr18MCRCOk
);
266 else if(byRxRate
==48){
267 pStatistic
->CustomStat
.ullRsr24M
++;
268 if(byRSR
& RSR_CRCOK
) {
269 pStatistic
->CustomStat
.ullRsr24MCRCOk
++;
271 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"24M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr24M
, (INT
)pStatistic
->CustomStat
.ullRsr24MCRCOk
);
273 else if(byRxRate
==72){
274 pStatistic
->CustomStat
.ullRsr36M
++;
275 if(byRSR
& RSR_CRCOK
) {
276 pStatistic
->CustomStat
.ullRsr36MCRCOk
++;
278 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"36M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr36M
, (INT
)pStatistic
->CustomStat
.ullRsr36MCRCOk
);
280 else if(byRxRate
==96){
281 pStatistic
->CustomStat
.ullRsr48M
++;
282 if(byRSR
& RSR_CRCOK
) {
283 pStatistic
->CustomStat
.ullRsr48MCRCOk
++;
285 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"48M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr48M
, (INT
)pStatistic
->CustomStat
.ullRsr48MCRCOk
);
287 else if(byRxRate
==108){
288 pStatistic
->CustomStat
.ullRsr54M
++;
289 if(byRSR
& RSR_CRCOK
) {
290 pStatistic
->CustomStat
.ullRsr54MCRCOk
++;
292 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"54M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr54M
, (INT
)pStatistic
->CustomStat
.ullRsr54MCRCOk
);
295 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Unknown: Total[%d], CRCOK[%d]\n", (INT
)pStatistic
->dwRsrRxPacket
+1, (INT
)pStatistic
->dwRsrCRCOk
);
298 if (byRSR
& RSR_BSSIDOK
)
299 pStatistic
->dwRsrBSSIDOk
++;
301 if (byRSR
& RSR_BCNSSIDOK
)
302 pStatistic
->dwRsrBCNSSIDOk
++;
303 if (byRSR
& RSR_IVLDLEN
) //invalid len (> 2312 byte)
304 pStatistic
->dwRsrLENErr
++;
305 if (byRSR
& RSR_IVLDTYP
) //invalid packet type
306 pStatistic
->dwRsrTYPErr
++;
307 if (byRSR
& (RSR_IVLDTYP
| RSR_IVLDLEN
))
308 pStatistic
->dwRsrErr
++;
310 if (byNewRSR
& NEWRSR_DECRYPTOK
)
311 pStatistic
->dwNewRsrDECRYPTOK
++;
312 if (byNewRSR
& NEWRSR_CFPIND
)
313 pStatistic
->dwNewRsrCFP
++;
314 if (byNewRSR
& NEWRSR_HWUTSF
)
315 pStatistic
->dwNewRsrUTSF
++;
316 if (byNewRSR
& NEWRSR_BCNHITAID
)
317 pStatistic
->dwNewRsrHITAID
++;
318 if (byNewRSR
& NEWRSR_BCNHITAID0
)
319 pStatistic
->dwNewRsrHITAID0
++;
321 // increase rx packet count
322 pStatistic
->dwRsrRxPacket
++;
323 pStatistic
->dwRsrRxOctet
+= cbFrameLength
;
326 if (IS_TYPE_DATA(pbyBuffer
)) {
327 pStatistic
->dwRsrRxData
++;
328 } else if (IS_TYPE_MGMT(pbyBuffer
)){
329 pStatistic
->dwRsrRxManage
++;
330 } else if (IS_TYPE_CONTROL(pbyBuffer
)){
331 pStatistic
->dwRsrRxControl
++;
334 if (byRSR
& RSR_ADDRBROAD
)
335 pStatistic
->dwRsrBroadcast
++;
336 else if (byRSR
& RSR_ADDRMULTI
)
337 pStatistic
->dwRsrMulticast
++;
339 pStatistic
->dwRsrDirected
++;
341 if (WLAN_GET_FC_MOREFRAG(pHeader
->wFrameCtl
))
342 pStatistic
->dwRsrRxFragment
++;
344 if (cbFrameLength
< MIN_PACKET_LEN
+ 4) {
345 pStatistic
->dwRsrRunt
++;
347 else if (cbFrameLength
== MIN_PACKET_LEN
+ 4) {
348 pStatistic
->dwRsrRxFrmLen64
++;
350 else if ((65 <= cbFrameLength
) && (cbFrameLength
<= 127)) {
351 pStatistic
->dwRsrRxFrmLen65_127
++;
353 else if ((128 <= cbFrameLength
) && (cbFrameLength
<= 255)) {
354 pStatistic
->dwRsrRxFrmLen128_255
++;
356 else if ((256 <= cbFrameLength
) && (cbFrameLength
<= 511)) {
357 pStatistic
->dwRsrRxFrmLen256_511
++;
359 else if ((512 <= cbFrameLength
) && (cbFrameLength
<= 1023)) {
360 pStatistic
->dwRsrRxFrmLen512_1023
++;
362 else if ((1024 <= cbFrameLength
) && (cbFrameLength
<= MAX_PACKET_LEN
+ 4)) {
363 pStatistic
->dwRsrRxFrmLen1024_1518
++;
364 } else if (cbFrameLength
> MAX_PACKET_LEN
+ 4) {
365 pStatistic
->dwRsrLong
++;
373 * Description: Update Rx Statistic Counter and copy Rx buffer
377 * pStatistic - Pointer to Statistic Counter Data Structure
379 * byNewRSR - Rx Status
380 * pbyBuffer - Rx Buffer
381 * cbFrameLength - Rx Length
390 STAvUpdateRDStatCounterEx (
391 PSStatCounter pStatistic
,
399 STAvUpdateRDStatCounter(
409 pStatistic
->dwCntRxFrmLength
= cbFrameLength
;
410 // rx pattern, we just see 10 bytes for sample
411 memcpy(pStatistic
->abyCntRxPattern
, (PBYTE
)pbyBuffer
, 10);
416 * Description: Update Tx Statistic Counter
420 * pStatistic - Pointer to Statistic Counter Data Structure
423 * pbyBuffer - Tx Buffer
424 * cbFrameLength - Tx Length
425 * uIdx - Index of Tx DMA
433 STAvUpdateTDStatCounter (
434 PSStatCounter pStatistic
,
442 PWLAN_80211HDR_A4 pHeader
;
444 BYTE byTSR0_NCR
= byTSR0
& TSR0_NCR
;
448 pHeader
= (PWLAN_80211HDR_A4
) pbyBuffer
;
449 if (WLAN_GET_FC_TODS(pHeader
->wFrameCtl
) == 0) {
450 pbyDestAddr
= &(pHeader
->abyAddr1
[0]);
453 pbyDestAddr
= &(pHeader
->abyAddr3
[0]);
455 // increase tx packet count
456 pStatistic
->dwTsrTxPacket
[uIdx
]++;
457 pStatistic
->dwTsrTxOctet
[uIdx
] += cbFrameLength
;
459 if (byTSR0_NCR
!= 0) {
460 pStatistic
->dwTsrRetry
[uIdx
]++;
461 pStatistic
->dwTsrTotalRetry
[uIdx
] += byTSR0_NCR
;
464 pStatistic
->dwTsrOnceRetry
[uIdx
]++;
466 pStatistic
->dwTsrMoreThanOnceRetry
[uIdx
]++;
469 if ((byTSR1
&(TSR1_TERR
|TSR1_RETRYTMO
|TSR1_TMO
|ACK_DATA
)) == 0) {
470 pStatistic
->ullTsrOK
[uIdx
]++;
471 pStatistic
->CustomStat
.ullTsrAllOK
=
472 (pStatistic
->ullTsrOK
[TYPE_AC0DMA
] + pStatistic
->ullTsrOK
[TYPE_TXDMA0
]);
473 // update counters in case that successful transmit
474 if (IS_BROADCAST_ADDRESS(pbyDestAddr
)) {
475 pStatistic
->ullTxBroadcastFrames
[uIdx
]++;
476 pStatistic
->ullTxBroadcastBytes
[uIdx
] += (ULONGLONG
)cbFrameLength
;
478 else if (IS_MULTICAST_ADDRESS(pbyDestAddr
)) {
479 pStatistic
->ullTxMulticastFrames
[uIdx
]++;
480 pStatistic
->ullTxMulticastBytes
[uIdx
] += (ULONGLONG
)cbFrameLength
;
483 pStatistic
->ullTxDirectedFrames
[uIdx
]++;
484 pStatistic
->ullTxDirectedBytes
[uIdx
] += (ULONGLONG
)cbFrameLength
;
488 if (byTSR1
& TSR1_TERR
)
489 pStatistic
->dwTsrErr
[uIdx
]++;
490 if (byTSR1
& TSR1_RETRYTMO
)
491 pStatistic
->dwTsrRetryTimeout
[uIdx
]++;
492 if (byTSR1
& TSR1_TMO
)
493 pStatistic
->dwTsrTransmitTimeout
[uIdx
]++;
494 if (byTSR1
& ACK_DATA
)
495 pStatistic
->dwTsrACKData
[uIdx
]++;
498 if (IS_BROADCAST_ADDRESS(pbyDestAddr
))
499 pStatistic
->dwTsrBroadcast
[uIdx
]++;
500 else if (IS_MULTICAST_ADDRESS(pbyDestAddr
))
501 pStatistic
->dwTsrMulticast
[uIdx
]++;
503 pStatistic
->dwTsrDirected
[uIdx
]++;
509 * Description: Update Tx Statistic Counter and copy Tx buffer
513 * pStatistic - Pointer to Statistic Counter Data Structure
514 * pbyBuffer - Tx Buffer
515 * cbFrameLength - Tx Length
523 STAvUpdateTDStatCounterEx (
524 PSStatCounter pStatistic
,
531 uPktLength
= (UINT
)cbFrameLength
;
534 pStatistic
->dwCntTxBufLength
= uPktLength
;
535 // tx pattern, we just see 16 bytes for sample
536 memcpy(pStatistic
->abyCntTxPattern
, pbyBuffer
, 16);
541 * Description: Update 802.11 mib counter
545 * p802_11Counter - Pointer to 802.11 mib counter
546 * pStatistic - Pointer to Statistic Counter Data Structure
547 * dwCounter - hardware counter for 802.11 mib
555 STAvUpdate802_11Counter(
556 PSDot11Counters p802_11Counter
,
557 PSStatCounter pStatistic
,
561 //p802_11Counter->TransmittedFragmentCount
562 p802_11Counter
->MulticastTransmittedFrameCount
= (ULONGLONG
) (pStatistic
->dwTsrBroadcast
[TYPE_AC0DMA
] +
563 pStatistic
->dwTsrBroadcast
[TYPE_TXDMA0
] +
564 pStatistic
->dwTsrMulticast
[TYPE_AC0DMA
] +
565 pStatistic
->dwTsrMulticast
[TYPE_TXDMA0
]);
566 p802_11Counter
->FailedCount
= (ULONGLONG
) (pStatistic
->dwTsrErr
[TYPE_AC0DMA
] + pStatistic
->dwTsrErr
[TYPE_TXDMA0
]);
567 p802_11Counter
->RetryCount
= (ULONGLONG
) (pStatistic
->dwTsrRetry
[TYPE_AC0DMA
] + pStatistic
->dwTsrRetry
[TYPE_TXDMA0
]);
568 p802_11Counter
->MultipleRetryCount
= (ULONGLONG
) (pStatistic
->dwTsrMoreThanOnceRetry
[TYPE_AC0DMA
] +
569 pStatistic
->dwTsrMoreThanOnceRetry
[TYPE_TXDMA0
]);
570 //p802_11Counter->FrameDuplicateCount
571 p802_11Counter
->RTSSuccessCount
+= (ULONGLONG
) (dwCounter
& 0x000000ff);
572 p802_11Counter
->RTSFailureCount
+= (ULONGLONG
) ((dwCounter
& 0x0000ff00) >> 8);
573 p802_11Counter
->ACKFailureCount
+= (ULONGLONG
) ((dwCounter
& 0x00ff0000) >> 16);
574 p802_11Counter
->FCSErrorCount
+= (ULONGLONG
) ((dwCounter
& 0xff000000) >> 24);
575 //p802_11Counter->ReceivedFragmentCount
576 p802_11Counter
->MulticastReceivedFrameCount
= (ULONGLONG
) (pStatistic
->dwRsrBroadcast
+
577 pStatistic
->dwRsrMulticast
);
581 * Description: Clear 802.11 mib counter
585 * p802_11Counter - Pointer to 802.11 mib counter
593 STAvClear802_11Counter(PSDot11Counters p802_11Counter
)
595 // set memory to zero
596 memset(p802_11Counter
, 0, sizeof(SDot11Counters
));