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
, BYTE byIsr0
, BYTE byIsr1
)
95 /**********************/
96 /* ABNORMAL interrupt */
97 /**********************/
98 // not any IMR bit invoke irq
100 pStatistic
->ISRStat
.dwIsrUnknown
++;
105 if (byIsr0
& ISR_ACTX
) // ISR, bit0
106 pStatistic
->ISRStat
.dwIsrTx0OK
++; // TXDMA0 successful
108 if (byIsr0
& ISR_BNTX
) // ISR, bit2
109 pStatistic
->ISRStat
.dwIsrBeaconTxOK
++; // BeaconTx successful
111 if (byIsr0
& ISR_RXDMA0
) // ISR, bit3
112 pStatistic
->ISRStat
.dwIsrRx0OK
++; // Rx0 successful
114 if (byIsr0
& ISR_TBTT
) // ISR, bit4
115 pStatistic
->ISRStat
.dwIsrTBTTInt
++; // TBTT successful
117 if (byIsr0
& ISR_SOFTTIMER
) // ISR, bit6
118 pStatistic
->ISRStat
.dwIsrSTIMERInt
++;
120 if (byIsr0
& ISR_WATCHDOG
) // ISR, bit7
121 pStatistic
->ISRStat
.dwIsrWatchDog
++;
124 if (byIsr1
& ISR_FETALERR
) // ISR, bit8
125 pStatistic
->ISRStat
.dwIsrUnrecoverableError
++;
127 if (byIsr1
& ISR_SOFTINT
) // ISR, bit9
128 pStatistic
->ISRStat
.dwIsrSoftInterrupt
++; // software interrupt
130 if (byIsr1
& ISR_MIBNEARFULL
) // ISR, bit10
131 pStatistic
->ISRStat
.dwIsrMIBNearfull
++;
133 if (byIsr1
& ISR_RXNOBUF
) // ISR, bit11
134 pStatistic
->ISRStat
.dwIsrRxNoBuf
++; // Rx No Buff
140 * Description: Update Rx Statistic Counter
144 * pStatistic - Pointer to Statistic Counter Data Structure
146 * byNewRSR - Rx Status
147 * pbyBuffer - Rx Buffer
148 * cbFrameLength - Rx Length
155 void STAvUpdateRDStatCounter (PSStatCounter pStatistic
,
156 BYTE byRSR
, BYTE byNewRSR
, BYTE byRxSts
, BYTE byRxRate
,
157 PBYTE pbyBuffer
, UINT cbFrameLength
)
160 PS802_11Header pHeader
= (PS802_11Header
)pbyBuffer
;
162 if (byRSR
& RSR_ADDROK
)
163 pStatistic
->dwRsrADDROk
++;
164 if (byRSR
& RSR_CRCOK
) {
165 pStatistic
->dwRsrCRCOk
++;
166 pStatistic
->ullRsrOK
++;
168 if (cbFrameLength
>= ETH_ALEN
) {
169 /* update counters in case of successful transmission */
170 if (byRSR
& RSR_ADDRBROAD
) {
171 pStatistic
->ullRxBroadcastFrames
++;
172 pStatistic
->ullRxBroadcastBytes
+= (ULONGLONG
)cbFrameLength
;
174 else if (byRSR
& RSR_ADDRMULTI
) {
175 pStatistic
->ullRxMulticastFrames
++;
176 pStatistic
->ullRxMulticastBytes
+= (ULONGLONG
)cbFrameLength
;
179 pStatistic
->ullRxDirectedFrames
++;
180 pStatistic
->ullRxDirectedBytes
+= (ULONGLONG
)cbFrameLength
;
186 pStatistic
->CustomStat
.ullRsr11M
++;
187 if(byRSR
& RSR_CRCOK
) {
188 pStatistic
->CustomStat
.ullRsr11MCRCOk
++;
190 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"11M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr11M
, (INT
)pStatistic
->CustomStat
.ullRsr11MCRCOk
, byRSR
);
192 else if(byRxRate
==11) {
193 pStatistic
->CustomStat
.ullRsr5M
++;
194 if(byRSR
& RSR_CRCOK
) {
195 pStatistic
->CustomStat
.ullRsr5MCRCOk
++;
197 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 5M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr5M
, (INT
)pStatistic
->CustomStat
.ullRsr5MCRCOk
, byRSR
);
199 else if(byRxRate
==4) {
200 pStatistic
->CustomStat
.ullRsr2M
++;
201 if(byRSR
& RSR_CRCOK
) {
202 pStatistic
->CustomStat
.ullRsr2MCRCOk
++;
204 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 2M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr2M
, (INT
)pStatistic
->CustomStat
.ullRsr2MCRCOk
, byRSR
);
206 else if(byRxRate
==2){
207 pStatistic
->CustomStat
.ullRsr1M
++;
208 if(byRSR
& RSR_CRCOK
) {
209 pStatistic
->CustomStat
.ullRsr1MCRCOk
++;
211 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 1M: ALL[%d], OK[%d]:[%02x]\n", (INT
)pStatistic
->CustomStat
.ullRsr1M
, (INT
)pStatistic
->CustomStat
.ullRsr1MCRCOk
, byRSR
);
213 else if(byRxRate
==12){
214 pStatistic
->CustomStat
.ullRsr6M
++;
215 if(byRSR
& RSR_CRCOK
) {
216 pStatistic
->CustomStat
.ullRsr6MCRCOk
++;
218 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 6M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr6M
, (INT
)pStatistic
->CustomStat
.ullRsr6MCRCOk
);
220 else if(byRxRate
==18){
221 pStatistic
->CustomStat
.ullRsr9M
++;
222 if(byRSR
& RSR_CRCOK
) {
223 pStatistic
->CustomStat
.ullRsr9MCRCOk
++;
225 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
" 9M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr9M
, (INT
)pStatistic
->CustomStat
.ullRsr9MCRCOk
);
227 else if(byRxRate
==24){
228 pStatistic
->CustomStat
.ullRsr12M
++;
229 if(byRSR
& RSR_CRCOK
) {
230 pStatistic
->CustomStat
.ullRsr12MCRCOk
++;
232 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"12M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr12M
, (INT
)pStatistic
->CustomStat
.ullRsr12MCRCOk
);
234 else if(byRxRate
==36){
235 pStatistic
->CustomStat
.ullRsr18M
++;
236 if(byRSR
& RSR_CRCOK
) {
237 pStatistic
->CustomStat
.ullRsr18MCRCOk
++;
239 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"18M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr18M
, (INT
)pStatistic
->CustomStat
.ullRsr18MCRCOk
);
241 else if(byRxRate
==48){
242 pStatistic
->CustomStat
.ullRsr24M
++;
243 if(byRSR
& RSR_CRCOK
) {
244 pStatistic
->CustomStat
.ullRsr24MCRCOk
++;
246 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"24M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr24M
, (INT
)pStatistic
->CustomStat
.ullRsr24MCRCOk
);
248 else if(byRxRate
==72){
249 pStatistic
->CustomStat
.ullRsr36M
++;
250 if(byRSR
& RSR_CRCOK
) {
251 pStatistic
->CustomStat
.ullRsr36MCRCOk
++;
253 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"36M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr36M
, (INT
)pStatistic
->CustomStat
.ullRsr36MCRCOk
);
255 else if(byRxRate
==96){
256 pStatistic
->CustomStat
.ullRsr48M
++;
257 if(byRSR
& RSR_CRCOK
) {
258 pStatistic
->CustomStat
.ullRsr48MCRCOk
++;
260 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"48M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr48M
, (INT
)pStatistic
->CustomStat
.ullRsr48MCRCOk
);
262 else if(byRxRate
==108){
263 pStatistic
->CustomStat
.ullRsr54M
++;
264 if(byRSR
& RSR_CRCOK
) {
265 pStatistic
->CustomStat
.ullRsr54MCRCOk
++;
267 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"54M: ALL[%d], OK[%d]\n", (INT
)pStatistic
->CustomStat
.ullRsr54M
, (INT
)pStatistic
->CustomStat
.ullRsr54MCRCOk
);
270 DBG_PRT(MSG_LEVEL_DEBUG
, KERN_INFO
"Unknown: Total[%d], CRCOK[%d]\n", (INT
)pStatistic
->dwRsrRxPacket
+1, (INT
)pStatistic
->dwRsrCRCOk
);
273 if (byRSR
& RSR_BSSIDOK
)
274 pStatistic
->dwRsrBSSIDOk
++;
276 if (byRSR
& RSR_BCNSSIDOK
)
277 pStatistic
->dwRsrBCNSSIDOk
++;
278 if (byRSR
& RSR_IVLDLEN
) //invalid len (> 2312 byte)
279 pStatistic
->dwRsrLENErr
++;
280 if (byRSR
& RSR_IVLDTYP
) //invalid packet type
281 pStatistic
->dwRsrTYPErr
++;
282 if ((byRSR
& (RSR_IVLDTYP
| RSR_IVLDLEN
)) || !(byRSR
& RSR_CRCOK
))
283 pStatistic
->dwRsrErr
++;
285 if (byNewRSR
& NEWRSR_DECRYPTOK
)
286 pStatistic
->dwNewRsrDECRYPTOK
++;
287 if (byNewRSR
& NEWRSR_CFPIND
)
288 pStatistic
->dwNewRsrCFP
++;
289 if (byNewRSR
& NEWRSR_HWUTSF
)
290 pStatistic
->dwNewRsrUTSF
++;
291 if (byNewRSR
& NEWRSR_BCNHITAID
)
292 pStatistic
->dwNewRsrHITAID
++;
293 if (byNewRSR
& NEWRSR_BCNHITAID0
)
294 pStatistic
->dwNewRsrHITAID0
++;
296 // increase rx packet count
297 pStatistic
->dwRsrRxPacket
++;
298 pStatistic
->dwRsrRxOctet
+= cbFrameLength
;
301 if (IS_TYPE_DATA(pbyBuffer
)) {
302 pStatistic
->dwRsrRxData
++;
303 } else if (IS_TYPE_MGMT(pbyBuffer
)){
304 pStatistic
->dwRsrRxManage
++;
305 } else if (IS_TYPE_CONTROL(pbyBuffer
)){
306 pStatistic
->dwRsrRxControl
++;
309 if (byRSR
& RSR_ADDRBROAD
)
310 pStatistic
->dwRsrBroadcast
++;
311 else if (byRSR
& RSR_ADDRMULTI
)
312 pStatistic
->dwRsrMulticast
++;
314 pStatistic
->dwRsrDirected
++;
316 if (WLAN_GET_FC_MOREFRAG(pHeader
->wFrameCtl
))
317 pStatistic
->dwRsrRxFragment
++;
319 if (cbFrameLength
< MIN_PACKET_LEN
+ 4) {
320 pStatistic
->dwRsrRunt
++;
322 else if (cbFrameLength
== MIN_PACKET_LEN
+ 4) {
323 pStatistic
->dwRsrRxFrmLen64
++;
325 else if ((65 <= cbFrameLength
) && (cbFrameLength
<= 127)) {
326 pStatistic
->dwRsrRxFrmLen65_127
++;
328 else if ((128 <= cbFrameLength
) && (cbFrameLength
<= 255)) {
329 pStatistic
->dwRsrRxFrmLen128_255
++;
331 else if ((256 <= cbFrameLength
) && (cbFrameLength
<= 511)) {
332 pStatistic
->dwRsrRxFrmLen256_511
++;
334 else if ((512 <= cbFrameLength
) && (cbFrameLength
<= 1023)) {
335 pStatistic
->dwRsrRxFrmLen512_1023
++;
337 else if ((1024 <= cbFrameLength
) && (cbFrameLength
<= MAX_PACKET_LEN
+ 4)) {
338 pStatistic
->dwRsrRxFrmLen1024_1518
++;
339 } else if (cbFrameLength
> MAX_PACKET_LEN
+ 4) {
340 pStatistic
->dwRsrLong
++;
348 * Description: Update Rx Statistic Counter and copy Rx buffer
352 * pStatistic - Pointer to Statistic Counter Data Structure
354 * byNewRSR - Rx Status
355 * pbyBuffer - Rx Buffer
356 * cbFrameLength - Rx Length
365 STAvUpdateRDStatCounterEx (
366 PSStatCounter pStatistic
,
375 STAvUpdateRDStatCounter(
386 pStatistic
->dwCntRxFrmLength
= cbFrameLength
;
387 // rx pattern, we just see 10 bytes for sample
388 memcpy(pStatistic
->abyCntRxPattern
, (PBYTE
)pbyBuffer
, 10);
393 * Description: Update Tx Statistic Counter
397 * pStatistic - Pointer to Statistic Counter Data Structure
400 * pbyBuffer - Tx Buffer
401 * cbFrameLength - Tx Length
402 * uIdx - Index of Tx DMA
410 STAvUpdateTDStatCounter (
411 PSStatCounter pStatistic
,
418 // increase tx packet count
419 pStatistic
->dwTsrTxPacket
++;
421 byRetyCnt
= (byTSR
& 0xF0) >> 4;
422 if (byRetyCnt
!= 0) {
423 pStatistic
->dwTsrRetry
++;
424 pStatistic
->dwTsrTotalRetry
+= byRetyCnt
;
425 pStatistic
->dwTxFail
[byRate
]+= byRetyCnt
;
426 pStatistic
->dwTxFail
[MAX_RATE
] += byRetyCnt
;
428 if ( byRetyCnt
== 0x1)
429 pStatistic
->dwTsrOnceRetry
++;
431 pStatistic
->dwTsrMoreThanOnceRetry
++;
434 pStatistic
->dwTxRetryCount
[byRetyCnt
-1]++;
437 if ( !(byTSR
& (TSR_TMO
| TSR_RETRYTMO
))) {
439 #ifdef Calcu_LinkQual
441 pStatistic
->TxNoRetryOkCount
++;
443 pStatistic
->TxRetryOkCount
++;
446 pStatistic
->ullTsrOK
++;
447 pStatistic
->CustomStat
.ullTsrAllOK
++;
448 // update counters in case that successful transmit
449 pStatistic
->dwTxOk
[byRate
]++;
450 pStatistic
->dwTxOk
[MAX_RATE
]++;
452 if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_BROAD
) {
453 pStatistic
->ullTxBroadcastFrames
++;
454 pStatistic
->ullTxBroadcastBytes
+= pStatistic
->abyTxPktInfo
[byPktNum
].wLength
;
455 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_MULTI
) {
456 pStatistic
->ullTxMulticastFrames
++;
457 pStatistic
->ullTxMulticastBytes
+= pStatistic
->abyTxPktInfo
[byPktNum
].wLength
;
458 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_UNI
) {
459 pStatistic
->ullTxDirectedFrames
++;
460 pStatistic
->ullTxDirectedBytes
+= pStatistic
->abyTxPktInfo
[byPktNum
].wLength
;
465 #ifdef Calcu_LinkQual
466 pStatistic
->TxFailCount
++;
469 pStatistic
->dwTsrErr
++;
470 if (byTSR
& TSR_RETRYTMO
)
471 pStatistic
->dwTsrRetryTimeout
++;
473 pStatistic
->dwTsrTransmitTimeout
++;
476 if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_BROAD
) {
477 pStatistic
->dwTsrBroadcast
++;
478 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_MULTI
) {
479 pStatistic
->dwTsrMulticast
++;
480 } else if ( pStatistic
->abyTxPktInfo
[byPktNum
].byBroadMultiUni
== TX_PKT_UNI
) {
481 pStatistic
->dwTsrDirected
++;
488 * Description: Update 802.11 mib counter
492 * p802_11Counter - Pointer to 802.11 mib counter
493 * pStatistic - Pointer to Statistic Counter Data Structure
494 * dwCounter - hardware counter for 802.11 mib
502 STAvUpdate802_11Counter(
503 PSDot11Counters p802_11Counter
,
504 PSStatCounter pStatistic
,
511 //p802_11Counter->TransmittedFragmentCount
512 p802_11Counter
->MulticastTransmittedFrameCount
= (ULONGLONG
) (pStatistic
->dwTsrBroadcast
+
513 pStatistic
->dwTsrMulticast
);
514 p802_11Counter
->FailedCount
= (ULONGLONG
) (pStatistic
->dwTsrErr
);
515 p802_11Counter
->RetryCount
= (ULONGLONG
) (pStatistic
->dwTsrRetry
);
516 p802_11Counter
->MultipleRetryCount
= (ULONGLONG
) (pStatistic
->dwTsrMoreThanOnceRetry
);
517 //p802_11Counter->FrameDuplicateCount
518 p802_11Counter
->RTSSuccessCount
+= (ULONGLONG
) byRTSSuccess
;
519 p802_11Counter
->RTSFailureCount
+= (ULONGLONG
) byRTSFail
;
520 p802_11Counter
->ACKFailureCount
+= (ULONGLONG
) byACKFail
;
521 p802_11Counter
->FCSErrorCount
+= (ULONGLONG
) byFCSErr
;
522 //p802_11Counter->ReceivedFragmentCount
523 p802_11Counter
->MulticastReceivedFrameCount
= (ULONGLONG
) (pStatistic
->dwRsrBroadcast
+
524 pStatistic
->dwRsrMulticast
);
528 * Description: Clear 802.11 mib counter
532 * p802_11Counter - Pointer to 802.11 mib counter
540 STAvClear802_11Counter(PSDot11Counters p802_11Counter
)
542 // set memory to zero
543 memset(p802_11Counter
, 0, sizeof(SDot11Counters
));
547 * Description: Clear 802.11 mib counter
551 * pUsbCounter - Pointer to USB mib counter
552 * ntStatus - URB status
561 STAvUpdateUSBCounter(PSUSBCounter pUsbCounter
,
566 // if ( ntStatus == USBD_STATUS_CRC ) {
567 pUsbCounter
->dwCrc
++;