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
48 /*--------------------- Static Definitions -------------------------*/
49 static int msglevel
=MSG_LEVEL_INFO
;
50 /*--------------------- Static Classes ----------------------------*/
52 /*--------------------- Static Variables --------------------------*/
54 /*--------------------- Static Functions --------------------------*/
56 /*--------------------- Export Variables --------------------------*/
58 /*--------------------- Export Functions --------------------------*/
63 * Description: Clear All Statistic Counter
67 * pStatistic - Pointer to Statistic Counter Data Structure
74 void STAvClearAllCounter (PSStatCounter pStatistic
)
77 memset(pStatistic
, 0, sizeof(SStatCounter
));
82 * Description: Update Isr Statistic Counter
86 * pStatistic - Pointer to Statistic Counter Data Structure
87 * wisr - Interrupt status
94 void STAvUpdateIsrStatCounter (PSStatCounter pStatistic
, BYTE byIsr0
, BYTE byIsr1
)
96 /**********************/
97 /* ABNORMAL interrupt */
98 /**********************/
99 // not any IMR bit invoke irq
101 pStatistic
->ISRStat
.dwIsrUnknown
++;
106 if (BITbIsBitOn(byIsr0
, ISR_ACTX
)) // ISR, bit0
107 pStatistic
->ISRStat
.dwIsrTx0OK
++; // TXDMA0 successful
109 if (BITbIsBitOn(byIsr0
, ISR_BNTX
)) // ISR, bit2
110 pStatistic
->ISRStat
.dwIsrBeaconTxOK
++; // BeaconTx successful
112 if (BITbIsBitOn(byIsr0
, ISR_RXDMA0
)) // ISR, bit3
113 pStatistic
->ISRStat
.dwIsrRx0OK
++; // Rx0 successful
115 if (BITbIsBitOn(byIsr0
, ISR_TBTT
)) // ISR, bit4
116 pStatistic
->ISRStat
.dwIsrTBTTInt
++; // TBTT successful
118 if (BITbIsBitOn(byIsr0
, ISR_SOFTTIMER
)) // ISR, bit6
119 pStatistic
->ISRStat
.dwIsrSTIMERInt
++;
121 if (BITbIsBitOn(byIsr0
, ISR_WATCHDOG
)) // ISR, bit7
122 pStatistic
->ISRStat
.dwIsrWatchDog
++;
125 if (BITbIsBitOn(byIsr1
, ISR_FETALERR
)) // ISR, bit8
126 pStatistic
->ISRStat
.dwIsrUnrecoverableError
++;
128 if (BITbIsBitOn(byIsr1
, ISR_SOFTINT
)) // ISR, bit9
129 pStatistic
->ISRStat
.dwIsrSoftInterrupt
++; // software interrupt
131 if (BITbIsBitOn(byIsr1
, ISR_MIBNEARFULL
)) // ISR, bit10
132 pStatistic
->ISRStat
.dwIsrMIBNearfull
++;
134 if (BITbIsBitOn(byIsr1
, ISR_RXNOBUF
)) // ISR, bit11
135 pStatistic
->ISRStat
.dwIsrRxNoBuf
++; // Rx No Buff
141 * Description: Update Rx Statistic Counter
145 * pStatistic - Pointer to Statistic Counter Data Structure
147 * byNewRSR - Rx Status
148 * pbyBuffer - Rx Buffer
149 * cbFrameLength - Rx Length
156 void STAvUpdateRDStatCounter (PSStatCounter pStatistic
,
157 BYTE byRSR
, BYTE byNewRSR
, BYTE byRxSts
, BYTE byRxRate
,
158 PBYTE pbyBuffer
, UINT cbFrameLength
)
161 PS802_11Header pHeader
= (PS802_11Header
)pbyBuffer
;
163 if (BITbIsBitOn(byRSR
, RSR_ADDROK
))
164 pStatistic
->dwRsrADDROk
++;
165 if (BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
166 pStatistic
->dwRsrCRCOk
++;
168 pStatistic
->ullRsrOK
++;
170 if (cbFrameLength
>= U_ETHER_ADDR_LEN
) {
171 // update counters in case that successful transmit
172 if (BITbIsBitOn(byRSR
, RSR_ADDRBROAD
)) {
173 pStatistic
->ullRxBroadcastFrames
++;
174 pStatistic
->ullRxBroadcastBytes
+= (ULONGLONG
)cbFrameLength
;
176 else if (BITbIsBitOn(byRSR
, RSR_ADDRMULTI
)) {
177 pStatistic
->ullRxMulticastFrames
++;
178 pStatistic
->ullRxMulticastBytes
+= (ULONGLONG
)cbFrameLength
;
181 pStatistic
->ullRxDirectedFrames
++;
182 pStatistic
->ullRxDirectedBytes
+= (ULONGLONG
)cbFrameLength
;
188 pStatistic
->CustomStat
.ullRsr11M
++;
189 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
190 pStatistic
->CustomStat
.ullRsr11MCRCOk
++;
192 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"11M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr11M
, (INT
)pStatistic
->CustomStat
.ullRsr11MCRCOk
, byRSR
);
194 else if(byRxRate
==11) {
195 pStatistic
->CustomStat
.ullRsr5M
++;
196 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
197 pStatistic
->CustomStat
.ullRsr5MCRCOk
++;
199 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr5M
, (INT
)pStatistic
->CustomStat
.ullRsr5MCRCOk
, byRSR
);
201 else if(byRxRate
==4) {
202 pStatistic
->CustomStat
.ullRsr2M
++;
203 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
204 pStatistic
->CustomStat
.ullRsr2MCRCOk
++;
206 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 2M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr2M
, (INT
)pStatistic
->CustomStat
.ullRsr2MCRCOk
, byRSR
);
208 else if(byRxRate
==2){
209 pStatistic
->CustomStat
.ullRsr1M
++;
210 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
211 pStatistic
->CustomStat
.ullRsr1MCRCOk
++;
213 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr1M
, (INT
)pStatistic
->CustomStat
.ullRsr1MCRCOk
, byRSR
);
215 else if(byRxRate
==12){
216 pStatistic
->CustomStat
.ullRsr6M
++;
217 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
218 pStatistic
->CustomStat
.ullRsr6MCRCOk
++;
220 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 6M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr6M
, (INT
)pStatistic
->CustomStat
.ullRsr6MCRCOk
);
222 else if(byRxRate
==18){
223 pStatistic
->CustomStat
.ullRsr9M
++;
224 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
225 pStatistic
->CustomStat
.ullRsr9MCRCOk
++;
227 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 9M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr9M
, (INT
)pStatistic
->CustomStat
.ullRsr9MCRCOk
);
229 else if(byRxRate
==24){
230 pStatistic
->CustomStat
.ullRsr12M
++;
231 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
232 pStatistic
->CustomStat
.ullRsr12MCRCOk
++;
234 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"12M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr12M
, (INT
)pStatistic
->CustomStat
.ullRsr12MCRCOk
);
236 else if(byRxRate
==36){
237 pStatistic
->CustomStat
.ullRsr18M
++;
238 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
239 pStatistic
->CustomStat
.ullRsr18MCRCOk
++;
241 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"18M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr18M
, (INT
)pStatistic
->CustomStat
.ullRsr18MCRCOk
);
243 else if(byRxRate
==48){
244 pStatistic
->CustomStat
.ullRsr24M
++;
245 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
246 pStatistic
->CustomStat
.ullRsr24MCRCOk
++;
248 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"24M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr24M
, (INT
)pStatistic
->CustomStat
.ullRsr24MCRCOk
);
250 else if(byRxRate
==72){
251 pStatistic
->CustomStat
.ullRsr36M
++;
252 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
253 pStatistic
->CustomStat
.ullRsr36MCRCOk
++;
255 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"36M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr36M
, (INT
)pStatistic
->CustomStat
.ullRsr36MCRCOk
);
257 else if(byRxRate
==96){
258 pStatistic
->CustomStat
.ullRsr48M
++;
259 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
260 pStatistic
->CustomStat
.ullRsr48MCRCOk
++;
262 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"48M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr48M
, (INT
)pStatistic
->CustomStat
.ullRsr48MCRCOk
);
264 else if(byRxRate
==108){
265 pStatistic
->CustomStat
.ullRsr54M
++;
266 if(BITbIsBitOn(byRSR
, RSR_CRCOK
)) {
267 pStatistic
->CustomStat
.ullRsr54MCRCOk
++;
269 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"54M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr54M
, (INT
)pStatistic
->CustomStat
.ullRsr54MCRCOk
);
272 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Unknown: Total[%d], CRCOK[%d]\n", (INT
)pStatistic
->dwRsrRxPacket
+1, (INT
)pStatistic
->dwRsrCRCOk
);
275 if (BITbIsBitOn(byRSR
, RSR_BSSIDOK
))
276 pStatistic
->dwRsrBSSIDOk
++;
278 if (BITbIsBitOn(byRSR
, RSR_BCNSSIDOK
))
279 pStatistic
->dwRsrBCNSSIDOk
++;
280 if (BITbIsBitOn(byRSR
, RSR_IVLDLEN
)) //invalid len (> 2312 byte)
281 pStatistic
->dwRsrLENErr
++;
282 if (BITbIsBitOn(byRSR
, RSR_IVLDTYP
)) //invalid packet type
283 pStatistic
->dwRsrTYPErr
++;
284 if (BITbIsBitOn(byRSR
, (RSR_IVLDTYP
| RSR_IVLDLEN
)) || BITbIsBitOff(byRSR
, RSR_CRCOK
))
285 pStatistic
->dwRsrErr
++;
287 if (BITbIsBitOn(byNewRSR
, NEWRSR_DECRYPTOK
))
288 pStatistic
->dwNewRsrDECRYPTOK
++;
289 if (BITbIsBitOn(byNewRSR
, NEWRSR_CFPIND
))
290 pStatistic
->dwNewRsrCFP
++;
291 if (BITbIsBitOn(byNewRSR
, NEWRSR_HWUTSF
))
292 pStatistic
->dwNewRsrUTSF
++;
293 if (BITbIsBitOn(byNewRSR
, NEWRSR_BCNHITAID
))
294 pStatistic
->dwNewRsrHITAID
++;
295 if (BITbIsBitOn(byNewRSR
, NEWRSR_BCNHITAID0
))
296 pStatistic
->dwNewRsrHITAID0
++;
298 // increase rx packet count
299 pStatistic
->dwRsrRxPacket
++;
300 pStatistic
->dwRsrRxOctet
+= cbFrameLength
;
303 if (IS_TYPE_DATA(pbyBuffer
)) {
304 pStatistic
->dwRsrRxData
++;
305 } else if (IS_TYPE_MGMT(pbyBuffer
)){
306 pStatistic
->dwRsrRxManage
++;
307 } else if (IS_TYPE_CONTROL(pbyBuffer
)){
308 pStatistic
->dwRsrRxControl
++;
311 if (BITbIsBitOn(byRSR
, RSR_ADDRBROAD
))
312 pStatistic
->dwRsrBroadcast
++;
313 else if (BITbIsBitOn(byRSR
, RSR_ADDRMULTI
))
314 pStatistic
->dwRsrMulticast
++;
316 pStatistic
->dwRsrDirected
++;
318 if (WLAN_GET_FC_MOREFRAG(pHeader
->wFrameCtl
))
319 pStatistic
->dwRsrRxFragment
++;
321 if (cbFrameLength
< MIN_PACKET_LEN
+ 4) {
322 pStatistic
->dwRsrRunt
++;
324 else if (cbFrameLength
== MIN_PACKET_LEN
+ 4) {
325 pStatistic
->dwRsrRxFrmLen64
++;
327 else if ((65 <= cbFrameLength
) && (cbFrameLength
<= 127)) {
328 pStatistic
->dwRsrRxFrmLen65_127
++;
330 else if ((128 <= cbFrameLength
) && (cbFrameLength
<= 255)) {
331 pStatistic
->dwRsrRxFrmLen128_255
++;
333 else if ((256 <= cbFrameLength
) && (cbFrameLength
<= 511)) {
334 pStatistic
->dwRsrRxFrmLen256_511
++;
336 else if ((512 <= cbFrameLength
) && (cbFrameLength
<= 1023)) {
337 pStatistic
->dwRsrRxFrmLen512_1023
++;
339 else if ((1024 <= cbFrameLength
) && (cbFrameLength
<= MAX_PACKET_LEN
+ 4)) {
340 pStatistic
->dwRsrRxFrmLen1024_1518
++;
341 } else if (cbFrameLength
> MAX_PACKET_LEN
+ 4) {
342 pStatistic
->dwRsrLong
++;
350 * Description: Update Rx Statistic Counter and copy Rx buffer
354 * pStatistic - Pointer to Statistic Counter Data Structure
356 * byNewRSR - Rx Status
357 * pbyBuffer - Rx Buffer
358 * cbFrameLength - Rx Length
367 STAvUpdateRDStatCounterEx (
368 PSStatCounter pStatistic
,
377 STAvUpdateRDStatCounter(
388 pStatistic
->dwCntRxFrmLength
= cbFrameLength
;
389 // rx pattern, we just see 10 bytes for sample
390 memcpy(pStatistic
->abyCntRxPattern
, (PBYTE
)pbyBuffer
, 10);
395 * Description: Update Tx Statistic Counter
399 * pStatistic - Pointer to Statistic Counter Data Structure
402 * pbyBuffer - Tx Buffer
403 * cbFrameLength - Tx Length
404 * uIdx - Index of Tx DMA
412 STAvUpdateTDStatCounter (
413 PSStatCounter pStatistic
,
420 // increase tx packet count
421 pStatistic
->dwTsrTxPacket
++;
423 byRetyCnt
= (byTSR
& 0xF0) >> 4;
424 if (byRetyCnt
!= 0) {
425 pStatistic
->dwTsrRetry
++;
426 pStatistic
->dwTsrTotalRetry
+= byRetyCnt
;
427 pStatistic
->dwTxFail
[byRate
]+= byRetyCnt
;
428 pStatistic
->dwTxFail
[MAX_RATE
] += byRetyCnt
;
430 if ( byRetyCnt
== 0x1)
431 pStatistic
->dwTsrOnceRetry
++;
433 pStatistic
->dwTsrMoreThanOnceRetry
++;
436 pStatistic
->dwTxRetryCount
[byRetyCnt
-1]++;
439 if (BITbIsAllBitsOff(byTSR
, (TSR_TMO
| TSR_RETRYTMO
))) {
441 #ifdef Calcu_LinkQual
443 pStatistic
->TxNoRetryOkCount
++;
445 pStatistic
->TxRetryOkCount
++;
448 pStatistic
->ullTsrOK
++;
449 pStatistic
->CustomStat
.ullTsrAllOK
++;
450 // update counters in case that successful transmit
451 pStatistic
->dwTxOk
[byRate
]++;
452 pStatistic
->dwTxOk
[MAX_RATE
]++;
454 if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_BROAD
) {
455 pStatistic
->ullTxBroadcastFrames
++;
456 pStatistic
->ullTxBroadcastBytes
+= pStatistic
->abyTxPktInfo
[byPktNum
].wLength
;
457 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_MULTI
) {
458 pStatistic
->ullTxMulticastFrames
++;
459 pStatistic
->ullTxMulticastBytes
+= pStatistic
->abyTxPktInfo
[byPktNum
].wLength
;
460 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_UNI
) {
461 pStatistic
->ullTxDirectedFrames
++;
462 pStatistic
->ullTxDirectedBytes
+= pStatistic
->abyTxPktInfo
[byPktNum
].wLength
;
467 #ifdef Calcu_LinkQual
468 pStatistic
->TxFailCount
++;
471 pStatistic
->dwTsrErr
++;
472 if (BITbIsBitOn(byTSR
, TSR_RETRYTMO
))
473 pStatistic
->dwTsrRetryTimeout
++;
474 if (BITbIsBitOn(byTSR
, TSR_TMO
))
475 pStatistic
->dwTsrTransmitTimeout
++;
478 if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_BROAD
) {
479 pStatistic
->dwTsrBroadcast
++;
480 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_MULTI
) {
481 pStatistic
->dwTsrMulticast
++;
482 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_UNI
) {
483 pStatistic
->dwTsrDirected
++;
490 * Description: Update 802.11 mib counter
494 * p802_11Counter - Pointer to 802.11 mib counter
495 * pStatistic - Pointer to Statistic Counter Data Structure
496 * dwCounter - hardware counter for 802.11 mib
504 STAvUpdate802_11Counter(
505 PSDot11Counters p802_11Counter
,
506 PSStatCounter pStatistic
,
513 //p802_11Counter->TransmittedFragmentCount
514 p802_11Counter
->MulticastTransmittedFrameCount
= (ULONGLONG
) (pStatistic
->dwTsrBroadcast
+
515 pStatistic
->dwTsrMulticast
);
516 p802_11Counter
->FailedCount
= (ULONGLONG
) (pStatistic
->dwTsrErr
);
517 p802_11Counter
->RetryCount
= (ULONGLONG
) (pStatistic
->dwTsrRetry
);
518 p802_11Counter
->MultipleRetryCount
= (ULONGLONG
) (pStatistic
->dwTsrMoreThanOnceRetry
);
519 //p802_11Counter->FrameDuplicateCount
520 p802_11Counter
->RTSSuccessCount
+= (ULONGLONG
) byRTSSuccess
;
521 p802_11Counter
->RTSFailureCount
+= (ULONGLONG
) byRTSFail
;
522 p802_11Counter
->ACKFailureCount
+= (ULONGLONG
) byACKFail
;
523 p802_11Counter
->FCSErrorCount
+= (ULONGLONG
) byFCSErr
;
524 //p802_11Counter->ReceivedFragmentCount
525 p802_11Counter
->MulticastReceivedFrameCount
= (ULONGLONG
) (pStatistic
->dwRsrBroadcast
+
526 pStatistic
->dwRsrMulticast
);
530 * Description: Clear 802.11 mib counter
534 * p802_11Counter - Pointer to 802.11 mib counter
542 STAvClear802_11Counter(PSDot11Counters p802_11Counter
)
544 // set memory to zero
545 memset(p802_11Counter
, 0, sizeof(SDot11Counters
));
549 * Description: Clear 802.11 mib counter
553 * pUsbCounter - Pointer to USB mib counter
554 * ntStatus - URB status
563 STAvUpdateUSBCounter(PSUSBCounter pUsbCounter
,
568 // if ( ntStatus == USBD_STATUS_CRC ) {
569 pUsbCounter
->dwCrc
++;