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,
157 BYTE byRxSts, BYTE byRxRate,
158 PBYTE pbyBuffer, unsigned int cbFrameLength)
161 PS802_11Header pHeader = (PS802_11Header)pbyBuffer;
163 if (byRSR & RSR_ADDROK)
164 pStatistic->dwRsrADDROk++;
165 if (byRSR & RSR_CRCOK) {
166 pStatistic->dwRsrCRCOk++;
167 pStatistic->ullRsrOK++;
169 if (cbFrameLength >= ETH_ALEN) {
170 /* update counters in case of successful transmission */
171 if (byRSR & RSR_ADDRBROAD) {
172 pStatistic->ullRxBroadcastFrames++;
173 pStatistic->ullRxBroadcastBytes +=
174 (unsigned long long) cbFrameLength;
176 else if (byRSR & RSR_ADDRMULTI) {
177 pStatistic->ullRxMulticastFrames++;
178 pStatistic->ullRxMulticastBytes +=
179 (unsigned long long) cbFrameLength;
182 pStatistic->ullRxDirectedFrames++;
183 pStatistic->ullRxDirectedBytes +=
184 (unsigned long long) cbFrameLength;
190 pStatistic->CustomStat.ullRsr11M++;
191 if(byRSR & RSR_CRCOK) {
192 pStatistic->CustomStat.ullRsr11MCRCOk++;
194 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "11M: ALL[%d], OK[%d]:[%02x]\n",
195 (signed int) pStatistic->CustomStat.ullRsr11M,
196 (signed int) pStatistic->CustomStat.ullRsr11MCRCOk, byRSR);
198 else if(byRxRate==11) {
199 pStatistic->CustomStat.ullRsr5M++;
200 if(byRSR & RSR_CRCOK) {
201 pStatistic->CustomStat.ullRsr5MCRCOk++;
203 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 5M: ALL[%d], OK[%d]:[%02x]\n",
204 (signed int) pStatistic->CustomStat.ullRsr5M,
205 (signed int) pStatistic->CustomStat.ullRsr5MCRCOk, byRSR);
207 else if(byRxRate==4) {
208 pStatistic->CustomStat.ullRsr2M++;
209 if(byRSR & RSR_CRCOK) {
210 pStatistic->CustomStat.ullRsr2MCRCOk++;
212 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 2M: ALL[%d], OK[%d]:[%02x]\n",
213 (signed int) pStatistic->CustomStat.ullRsr2M,
214 (signed int) pStatistic->CustomStat.ullRsr2MCRCOk, byRSR);
216 else if(byRxRate==2){
217 pStatistic->CustomStat.ullRsr1M++;
218 if(byRSR & RSR_CRCOK) {
219 pStatistic->CustomStat.ullRsr1MCRCOk++;
221 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 1M: ALL[%d], OK[%d]:[%02x]\n",
222 (signed int) pStatistic->CustomStat.ullRsr1M,
223 (signed int) pStatistic->CustomStat.ullRsr1MCRCOk, byRSR);
225 else if(byRxRate==12){
226 pStatistic->CustomStat.ullRsr6M++;
227 if(byRSR & RSR_CRCOK) {
228 pStatistic->CustomStat.ullRsr6MCRCOk++;
230 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 6M: ALL[%d], OK[%d]\n",
231 (signed int) pStatistic->CustomStat.ullRsr6M,
232 (signed int) pStatistic->CustomStat.ullRsr6MCRCOk);
234 else if(byRxRate==18){
235 pStatistic->CustomStat.ullRsr9M++;
236 if(byRSR & RSR_CRCOK) {
237 pStatistic->CustomStat.ullRsr9MCRCOk++;
239 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " 9M: ALL[%d], OK[%d]\n",
240 (signed int) pStatistic->CustomStat.ullRsr9M,
241 (signed int) pStatistic->CustomStat.ullRsr9MCRCOk);
243 else if(byRxRate==24){
244 pStatistic->CustomStat.ullRsr12M++;
245 if(byRSR & RSR_CRCOK) {
246 pStatistic->CustomStat.ullRsr12MCRCOk++;
248 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "12M: ALL[%d], OK[%d]\n",
249 (signed int) pStatistic->CustomStat.ullRsr12M,
250 (signed int) pStatistic->CustomStat.ullRsr12MCRCOk);
252 else if(byRxRate==36){
253 pStatistic->CustomStat.ullRsr18M++;
254 if(byRSR & RSR_CRCOK) {
255 pStatistic->CustomStat.ullRsr18MCRCOk++;
257 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "18M: ALL[%d], OK[%d]\n",
258 (signed int) pStatistic->CustomStat.ullRsr18M,
259 (signed int) pStatistic->CustomStat.ullRsr18MCRCOk);
261 else if(byRxRate==48){
262 pStatistic->CustomStat.ullRsr24M++;
263 if(byRSR & RSR_CRCOK) {
264 pStatistic->CustomStat.ullRsr24MCRCOk++;
266 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "24M: ALL[%d], OK[%d]\n",
267 (signed int) pStatistic->CustomStat.ullRsr24M,
268 (signed int) pStatistic->CustomStat.ullRsr24MCRCOk);
270 else if(byRxRate==72){
271 pStatistic->CustomStat.ullRsr36M++;
272 if(byRSR & RSR_CRCOK) {
273 pStatistic->CustomStat.ullRsr36MCRCOk++;
275 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "36M: ALL[%d], OK[%d]\n",
276 (signed int) pStatistic->CustomStat.ullRsr36M,
277 (signed int) pStatistic->CustomStat.ullRsr36MCRCOk);
279 else if(byRxRate==96){
280 pStatistic->CustomStat.ullRsr48M++;
281 if(byRSR & RSR_CRCOK) {
282 pStatistic->CustomStat.ullRsr48MCRCOk++;
284 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "48M: ALL[%d], OK[%d]\n",
285 (signed int) pStatistic->CustomStat.ullRsr48M,
286 (signed int) pStatistic->CustomStat.ullRsr48MCRCOk);
288 else if(byRxRate==108){
289 pStatistic->CustomStat.ullRsr54M++;
290 if(byRSR & RSR_CRCOK) {
291 pStatistic->CustomStat.ullRsr54MCRCOk++;
293 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "54M: ALL[%d], OK[%d]\n",
294 (signed int) pStatistic->CustomStat.ullRsr54M,
295 (signed int) pStatistic->CustomStat.ullRsr54MCRCOk);
298 DBG_PRT(MSG_LEVEL_DEBUG,
299 KERN_INFO "Unknown: Total[%d], CRCOK[%d]\n",
300 (signed int) pStatistic->dwRsrRxPacket+1,
301 (signed int)pStatistic->dwRsrCRCOk);
304 if (byRSR & RSR_BSSIDOK)
305 pStatistic->dwRsrBSSIDOk++;
307 if (byRSR & RSR_BCNSSIDOK)
308 pStatistic->dwRsrBCNSSIDOk++;
309 if (byRSR & RSR_IVLDLEN) //invalid len (> 2312 byte)
310 pStatistic->dwRsrLENErr++;
311 if (byRSR & RSR_IVLDTYP) //invalid packet type
312 pStatistic->dwRsrTYPErr++;
313 if ((byRSR & (RSR_IVLDTYP | RSR_IVLDLEN)) || !(byRSR & RSR_CRCOK))
314 pStatistic->dwRsrErr++;
316 if (byNewRSR & NEWRSR_DECRYPTOK)
317 pStatistic->dwNewRsrDECRYPTOK++;
318 if (byNewRSR & NEWRSR_CFPIND)
319 pStatistic->dwNewRsrCFP++;
320 if (byNewRSR & NEWRSR_HWUTSF)
321 pStatistic->dwNewRsrUTSF++;
322 if (byNewRSR & NEWRSR_BCNHITAID)
323 pStatistic->dwNewRsrHITAID++;
324 if (byNewRSR & NEWRSR_BCNHITAID0)
325 pStatistic->dwNewRsrHITAID0++;
327 // increase rx packet count
328 pStatistic->dwRsrRxPacket++;
329 pStatistic->dwRsrRxOctet += cbFrameLength;
332 if (IS_TYPE_DATA(pbyBuffer)) {
333 pStatistic->dwRsrRxData++;
334 } else if (IS_TYPE_MGMT(pbyBuffer)){
335 pStatistic->dwRsrRxManage++;
336 } else if (IS_TYPE_CONTROL(pbyBuffer)){
337 pStatistic->dwRsrRxControl++;
340 if (byRSR & RSR_ADDRBROAD)
341 pStatistic->dwRsrBroadcast++;
342 else if (byRSR & RSR_ADDRMULTI)
343 pStatistic->dwRsrMulticast++;
345 pStatistic->dwRsrDirected++;
347 if (WLAN_GET_FC_MOREFRAG(pHeader->wFrameCtl))
348 pStatistic->dwRsrRxFragment++;
350 if (cbFrameLength < ETH_ZLEN + 4) {
351 pStatistic->dwRsrRunt++;
352 } else if (cbFrameLength == ETH_ZLEN + 4) {
353 pStatistic->dwRsrRxFrmLen64++;
355 else if ((65 <= cbFrameLength) && (cbFrameLength <= 127)) {
356 pStatistic->dwRsrRxFrmLen65_127++;
358 else if ((128 <= cbFrameLength) && (cbFrameLength <= 255)) {
359 pStatistic->dwRsrRxFrmLen128_255++;
361 else if ((256 <= cbFrameLength) && (cbFrameLength <= 511)) {
362 pStatistic->dwRsrRxFrmLen256_511++;
364 else if ((512 <= cbFrameLength) && (cbFrameLength <= 1023)) {
365 pStatistic->dwRsrRxFrmLen512_1023++;
366 } else if ((1024 <= cbFrameLength) &&
367 (cbFrameLength <= ETH_FRAME_LEN + 4)) {
368 pStatistic->dwRsrRxFrmLen1024_1518++;
369 } else if (cbFrameLength > ETH_FRAME_LEN + 4) {
370 pStatistic->dwRsrLong++;
375 * Description: Update Rx Statistic Counter and copy Rx buffer
379 * pStatistic - Pointer to Statistic Counter Data Structure
381 * byNewRSR - Rx Status
382 * pbyBuffer - Rx Buffer
383 * cbFrameLength - Rx Length
392 STAvUpdateRDStatCounterEx (
393 PSStatCounter pStatistic,
399 unsigned int cbFrameLength
402 STAvUpdateRDStatCounter(
413 pStatistic->dwCntRxFrmLength = cbFrameLength;
414 // rx pattern, we just see 10 bytes for sample
415 memcpy(pStatistic->abyCntRxPattern, (PBYTE)pbyBuffer, 10);
420 * Description: Update Tx Statistic Counter
424 * pStatistic - Pointer to Statistic Counter Data Structure
427 * pbyBuffer - Tx Buffer
428 * cbFrameLength - Tx Length
429 * uIdx - Index of Tx DMA
437 STAvUpdateTDStatCounter (
438 PSStatCounter pStatistic,
445 // increase tx packet count
446 pStatistic->dwTsrTxPacket++;
448 byRetyCnt = (byTSR & 0xF0) >> 4;
449 if (byRetyCnt != 0) {
450 pStatistic->dwTsrRetry++;
451 pStatistic->dwTsrTotalRetry += byRetyCnt;
452 pStatistic->dwTxFail[byRate]+= byRetyCnt;
453 pStatistic->dwTxFail[MAX_RATE] += byRetyCnt;
455 if ( byRetyCnt == 0x1)
456 pStatistic->dwTsrOnceRetry++;
458 pStatistic->dwTsrMoreThanOnceRetry++;
461 pStatistic->dwTxRetryCount[byRetyCnt-1]++;
464 if ( !(byTSR & (TSR_TMO | TSR_RETRYTMO))) {
467 pStatistic->TxNoRetryOkCount ++;
469 pStatistic->TxRetryOkCount ++;
471 pStatistic->ullTsrOK++;
472 pStatistic->CustomStat.ullTsrAllOK++;
473 // update counters in case that successful transmit
474 pStatistic->dwTxOk[byRate]++;
475 pStatistic->dwTxOk[MAX_RATE]++;
477 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
478 pStatistic->ullTxBroadcastFrames++;
479 pStatistic->ullTxBroadcastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
480 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
481 pStatistic->ullTxMulticastFrames++;
482 pStatistic->ullTxMulticastBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
483 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
484 pStatistic->ullTxDirectedFrames++;
485 pStatistic->ullTxDirectedBytes += pStatistic->abyTxPktInfo[byPktNum].wLength;
490 pStatistic->TxFailCount ++;
492 pStatistic->dwTsrErr++;
493 if (byTSR & TSR_RETRYTMO)
494 pStatistic->dwTsrRetryTimeout++;
496 pStatistic->dwTsrTransmitTimeout++;
499 if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_BROAD ) {
500 pStatistic->dwTsrBroadcast++;
501 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_MULTI ) {
502 pStatistic->dwTsrMulticast++;
503 } else if ( pStatistic->abyTxPktInfo[byPktNum].byBroadMultiUni == TX_PKT_UNI ) {
504 pStatistic->dwTsrDirected++;
511 * Description: Update 802.11 mib counter
515 * p802_11Counter - Pointer to 802.11 mib counter
516 * pStatistic - Pointer to Statistic Counter Data Structure
517 * dwCounter - hardware counter for 802.11 mib
525 STAvUpdate802_11Counter(
526 PSDot11Counters p802_11Counter,
527 PSStatCounter pStatistic,
534 //p802_11Counter->TransmittedFragmentCount
535 p802_11Counter->MulticastTransmittedFrameCount =
536 (unsigned long long) (pStatistic->dwTsrBroadcast +
537 pStatistic->dwTsrMulticast);
538 p802_11Counter->FailedCount = (unsigned long long) (pStatistic->dwTsrErr);
539 p802_11Counter->RetryCount = (unsigned long long) (pStatistic->dwTsrRetry);
540 p802_11Counter->MultipleRetryCount =
541 (unsigned long long) (pStatistic->dwTsrMoreThanOnceRetry);
542 //p802_11Counter->FrameDuplicateCount
543 p802_11Counter->RTSSuccessCount += (unsigned long long) byRTSSuccess;
544 p802_11Counter->RTSFailureCount += (unsigned long long) byRTSFail;
545 p802_11Counter->ACKFailureCount += (unsigned long long) byACKFail;
546 p802_11Counter->FCSErrorCount += (unsigned long long) byFCSErr;
547 //p802_11Counter->ReceivedFragmentCount
548 p802_11Counter->MulticastReceivedFrameCount =
549 (unsigned long long) (pStatistic->dwRsrBroadcast +
550 pStatistic->dwRsrMulticast);
554 * Description: Clear 802.11 mib counter
558 * p802_11Counter - Pointer to 802.11 mib counter
566 STAvClear802_11Counter(PSDot11Counters p802_11Counter)
568 // set memory to zero
569 memset(p802_11Counter, 0, sizeof(SDot11Counters));
573 * Description: Clear 802.11 mib counter
577 * pUsbCounter - Pointer to USB mib counter
578 * ntStatus - URB status
586 void STAvUpdateUSBCounter(PSUSBCounter pUsbCounter, int ntStatus)
589 // if ( ntStatus == USBD_STATUS_CRC ) {
590 pUsbCounter->dwCrc++;