support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / combo_mt66xx / mt6628 / wlan / mgmt / swcr.c
1 /*
2 ** $Id: //Department/DaVinci/BRANCHES/MT6620_WIFI_DRIVER_V2_3/mgmt/swcr.c#1 $
3 */
4
5 /*! \file   "swcr.c"
6     \brief
7
8 */
9
10
11
12 /*
13 ** $Log: swcr.c $
14  *
15  * 06 04 2012 tsaiyuan.hsu
16  * [WCXRP00001249] [ALPS.ICS] Daily build warning on "wlan/mgmt/swcr.c#1"
17  * resolve build waring for "WNM_UNIT_TEST not defined".
18  *
19  * 03 02 2012 terry.wu
20  * NULL
21  * Sync CFG80211 modification from branch 2,2.
22  *
23  * 01 05 2012 tsaiyuan.hsu
24  * [WCXRP00001157] [MT6620 Wi-Fi][FW][DRV] add timing measurement support for 802.11v
25  * add timing measurement support for 802.11v.
26  *
27  * 11 22 2011 tsaiyuan.hsu
28  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
29  * keep debug counter setting after wake up.
30  *
31  * 11 15 2011 cm.chang
32  * NULL
33  * Fix compiling warning
34  *
35  * 11 11 2011 tsaiyuan.hsu
36  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
37  * fix debug counters of rx in driver.
38  *
39  * 11 11 2011 tsaiyuan.hsu
40  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
41  * add debug counters of bb and ar for xlog.
42  *
43  * 11 10 2011 eddie.chen
44  * [WCXRP00001096] [MT6620 Wi-Fi][Driver/FW] Enhance the log function (xlog)
45  * Modify the QM xlog level and remove LOG_FUNC.
46  *
47  * 11 08 2011 tsaiyuan.hsu
48  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
49  * add debug counters, eCurPsProf, for PS.
50  *
51  * 11 07 2011 tsaiyuan.hsu
52  * [WCXRP00001083] [MT6620 Wi-Fi][DRV]] dump debug counter or frames when debugging is triggered
53  * add debug counters and periodically dump counters for debugging.
54  *
55  * 11 03 2011 wh.su
56  * [WCXRP00001078] [MT6620 Wi-Fi][Driver] Adding the mediatek log improment support : XLOG
57  * change the DBGLOG for "\n" and "\r\n". LABEL to LOUD for XLOG
58  *
59  * 08 31 2011 tsaiyuan.hsu
60  * [WCXRP00000931] [MT5931 Wi-Fi][DRV/FW] add swcr to disable roaming from driver
61  * remove obsolete code.
62  *
63  * 08 15 2011 tsaiyuan.hsu
64  * [WCXRP00000931] [MT5931 Wi-Fi][DRV/FW] add swcr to disable roaming from driver
65  * add swcr in driver reg, 0x9fxx0000, to disable roaming .
66  *
67  * 05 11 2011 eddie.chen
68  * [WCXRP00000709] [MT6620 Wi-Fi][Driver] Check free number before copying broadcast packet
69  * Fix dest type when GO packet copying.
70  *
71  * 05 09 2011 eddie.chen
72  * [WCXRP00000709] [MT6620 Wi-Fi][Driver] Check free number before copying broadcast packet
73  * Check free number before copying broadcast packet.
74  *
75  * 04 14 2011 eddie.chen
76  * [WCXRP00000603] [MT6620 Wi-Fi][DRV] Fix Klocwork warning
77  * Check the SW RFB free. Fix the compile warning..
78  *
79  * 04 12 2011 eddie.chen
80  * [WCXRP00000617] [MT6620 Wi-Fi][DRV/FW] Fix for sigma
81  * Fix the sta index in processing security frame
82  * Simple flow control for TC4 to avoid mgt frames for PS STA to occupy the TC4
83  * Add debug message.
84  *
85  * 03 28 2011 eddie.chen
86  * [WCXRP00000603] [MT6620 Wi-Fi][DRV] Fix Klocwork warning
87  * Fix Klockwork warning.
88  *
89  * 03 15 2011 eddie.chen
90  * [WCXRP00000554] [MT6620 Wi-Fi][DRV] Add sw control debug counter
91  * Add sw debug counter for QM.
92  *
93  * 01 11 2011 eddie.chen
94  * [WCXRP00000322] Add WMM IE in beacon,
95 Add per station flow control when STA is in PS
96
97  * Add swcr for test.
98  *
99 *
100 */
101
102
103 /*******************************************************************************
104 *                         C O M P I L E R   F L A G S
105 ********************************************************************************
106 */
107
108 /*******************************************************************************
109 *                    E X T E R N A L   R E F E R E N C E S
110 ********************************************************************************
111 */
112 #include "precomp.h"
113
114 #if CFG_SUPPORT_SWCR
115
116 #ifdef __GNUC__
117 #pragma GCC diagnostic ignored "-Wformat"
118 #endif
119 /*******************************************************************************
120 *                             D A T A   T Y P E S
121 ********************************************************************************
122 */
123
124 /*******************************************************************************
125 *                            P U B L I C   D A T A
126 ********************************************************************************
127 */
128 #if 0
129 extern SWCR_MAP_ENTRY_T g_arRlmArSwCrMap[];
130 SWCR_MOD_MAP_ENTRY_T g_arSwCrAllMaps[] = {
131     { SWCR_MAP_NUM(g_arRlmArSwCrMap), g_arRlmArSwCrMap},  /* 0x00nn */
132     {0,NULL}
133 };
134 #endif
135
136 VOID swCtrlCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
137 VOID swCtrlCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
138 VOID testPsCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
139 VOID testPsCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
140 void testWNMCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1);
141 VOID swCtrlSwCr(P_ADAPTER_T prAdapter, UINT_8 ucRead, UINT_16 u2Addr, UINT_32 *pu4Data);
142
143 /* Support Debug */
144 VOID swCrDebugCheck(P_ADAPTER_T  prAdapter, P_CMD_SW_DBG_CTRL_T prCmdSwCtrl);
145 VOID swCrDebugCheckTimeout(
146     IN P_ADAPTER_T prAdapter,
147     UINT_32 u4Param);
148 VOID swCrDebugQuery(
149     IN P_ADAPTER_T  prAdapter,
150     IN P_CMD_INFO_T prCmdInfo,
151     IN PUINT_8      pucEventBuf
152     );
153 VOID swCrDebugQueryTimeout(
154     IN P_ADAPTER_T  prAdapter,
155     IN P_CMD_INFO_T prCmdInfo);
156
157 UINT_32 g_au4SwCr[SWCR_CR_NUM]; /*: 0: command other: data */
158
159 /* JB mDNS Filter*/
160 UINT_32 g_u4mDNSRXFilter = 0; /* [31] 0: stop 1: start, [3] IPv6 [2] IPv4*/
161
162 static TIMER_T g_rSwcrDebugTimer;
163 static BOOLEAN g_fgSwcrDebugTimer = FALSE;
164 static UINT_32 g_u4SwcrDebugCheckTimeout = 0;
165 static ENUM_SWCR_DBG_TYPE_T g_ucSwcrDebugCheckType = 0;
166 static UINT_32 g_u4SwcrDebugFrameDumpType = 0;
167
168 /*******************************************************************************
169 *                           P R I V A T E   D A T A
170 ********************************************************************************
171 */
172 #define TEST_PS 1
173
174 const static PFN_CMD_RW_T g_arSwCtrlCmd[] ={
175     swCtrlCmdCategory0,
176     swCtrlCmdCategory1
177 #if TEST_PS
178     , testPsCmdCategory0
179     , testPsCmdCategory1
180 #endif
181 #if CFG_SUPPORT_802_11V
182 #if (CFG_SUPPORT_802_11V_TIMING_MEASUREMENT ==1) && (WNM_UNIT_TEST ==1)
183     , testWNMCmdCategory0
184 #endif
185 #endif
186 };
187
188
189 const PFN_SWCR_RW_T g_arSwCrModHandle[] = {
190     swCtrlSwCr,
191     NULL
192 };
193
194
195 /*******************************************************************************
196 *                                 M A C R O S
197 ********************************************************************************
198 */
199
200 enum {
201     SWCTRL_MAGIC,
202     SWCTRL_DEBUG,
203     SWCTRL_WIFI_VAR,
204     SWCTRL_ENABLE_INT,
205     SWCTRL_DISABLE_INT,
206     SWCTRL_TXM_INFO,
207     SWCTRL_RXM_INFO,
208     SWCTRL_DUMP_BSS,
209     SWCTRL_QM_INFO,
210     SWCTRL_DUMP_ALL_QUEUE_LEN,
211     SWCTRL_DUMP_MEM,
212     SWCTRL_TX_CTRL_INFO,
213     SWCTRL_DUMP_QUEUE,
214     SWCTRL_DUMP_QM_DBG_CNT,
215     SWCTRL_QM_DBG_CNT,
216     SWCTRL_RX_PKTS_DUMP,
217     SWCTRL_RX_MDNS_FILTER,
218     SWCTRL_CATA0_INDEX_NUM
219 };
220
221 enum {
222     SWCTRL_STA_INFO,
223     SWCTRL_DUMP_STA,
224     SWCTRL_STA_QUE_INFO,
225     SWCTRL_CATA1_INDEX_NUM
226 };
227
228 /* JB mDNS Filter*/
229 #define RX_MDNS_FILTER_START (1<<31)
230 #define RX_MDNS_FILTER_IPV4  (1<<2)
231 #define RX_MDNS_FILTER_IPV6  (1<<3)
232 typedef enum _ENUM_SWCR_RX_MDNS_FILTER_CMD_T {
233     SWCR_RX_MDNS_FILTER_CMD_STOP = 0,
234     SWCR_RX_MDNS_FILTER_CMD_START,
235     SWCR_RX_MDNS_FILTER_CMD_ADD,
236     SWCR_RX_MDNS_FILTER_CMD_REMOVE,
237     SWCR_RX_MDNS_FILTER_NUM
238 } ENUM_SWCR_RX_MDNS_FILTER_CMD_T;
239
240 #if TEST_PS
241 enum {
242     TEST_PS_MAGIC,
243     TEST_PS_SETUP_BSS,
244     TEST_PS_ENABLE_BEACON,
245     TEST_PS_TRIGGER_BMC,
246     TEST_PS_SEND_NULL,
247     TEST_PS_BUFFER_BMC,
248     TEST_PS_UPDATE_BEACON,
249     TEST_PS_CATA0_INDEX_NUM
250 };
251
252 enum {
253     TEST_PS_STA_PS,
254     TEST_PS_STA_ENTER_PS,
255     TEST_PS_STA_EXIT_PS,
256     TEST_PS_STA_TRIGGER_PSPOLL,
257     TEST_PS_STA_TRIGGER_FRAME,
258     TEST_PS_CATA1_INDEX_NUM
259 };
260 #endif
261
262 #if CFG_SUPPORT_802_11V
263 #if WNM_UNIT_TEST
264 enum {
265     TEST_WNM_TIMING_MEAS,
266     TEST_WNM_CATA0_INDEX_NUM
267 };
268 #endif
269 #endif
270
271
272 #define _SWCTRL_MAGIC 0x66201642
273
274 /*******************************************************************************
275 *                   F U N C T I O N   D E C L A R A T I O N S
276 ********************************************************************************
277 */
278
279
280 /*******************************************************************************
281 *                              F U N C T I O N S
282 ********************************************************************************
283 */
284
285 void dumpQueue(P_ADAPTER_T prAdapter)
286 {
287
288     P_TX_CTRL_T prTxCtrl;
289     P_QUE_MGT_T prQM;
290     P_GLUE_INFO_T           prGlueInfo;
291     UINT_32 i;
292     UINT_32 j;
293
294
295     DEBUGFUNC("dumpQueue");
296
297     prTxCtrl = &prAdapter->rTxCtrl;
298     prQM = &prAdapter->rQM;
299     prGlueInfo = prAdapter->prGlueInfo;
300
301     for(i = TC0_INDEX; i<=TC5_INDEX; i++) {
302         DBGLOG(SW4, INFO,( "TC %u\n",i));
303         DBGLOG(SW4, INFO,( "Max %u Free %u\n",
304                 prTxCtrl->rTc.aucMaxNumOfBuffer[i], prTxCtrl->rTc.aucFreeBufferCount[i]));
305
306         DBGLOG(SW4, INFO,("Average %u minReserved %u CurrentTcResource %u GuaranteedTcResource %u\n",
307            QM_GET_TX_QUEUE_LEN(prAdapter, i),
308            prQM->au4MinReservedTcResource[i],
309            prQM->au4CurrentTcResource[i],
310            prQM->au4GuaranteedTcResource[i]));
311
312      }
313
314
315     for(i = 0; i<NUM_OF_PER_STA_TX_QUEUES; i++) {
316         DBGLOG(SW4, INFO,( "TC %u HeadStaIdx %u ForwardCount %u\n",i, prQM->au4HeadStaRecIndex[i],prQM->au4ForwardCount[i]));
317     }
318
319       DBGLOG(SW4, INFO,( "BMC or unknown TxQueue Len %u\n",prQM->arTxQueue[0].u4NumElem));
320       DBGLOG(SW4, INFO,( "Pending %d\n",prGlueInfo->i4TxPendingFrameNum));
321       DBGLOG(SW4, INFO,( "Pending Security %d\n",prGlueInfo->i4TxPendingSecurityFrameNum));
322 #if defined(LINUX)
323    for(i=0;i<4;i++){
324        for(j=0;j<CFG_MAX_TXQ_NUM;j++){
325           DBGLOG(SW4, INFO,( "Pending Q[%u][%u] %d\n",i,j,prGlueInfo->ai4TxPendingFrameNumPerQueue[i][j]));
326         }
327     }
328 #endif
329
330    DBGLOG(SW4, INFO,( " rFreeSwRfbList %u\n", prAdapter->rRxCtrl.rFreeSwRfbList.u4NumElem));
331    DBGLOG(SW4, INFO,( " rReceivedRfbList %u\n", prAdapter->rRxCtrl.rReceivedRfbList.u4NumElem));
332    DBGLOG(SW4, INFO,( " rIndicatedRfbList %u\n", prAdapter->rRxCtrl.rIndicatedRfbList.u4NumElem));
333    DBGLOG(SW4, INFO,( " ucNumIndPacket %u\n", prAdapter->rRxCtrl.ucNumIndPacket));
334    DBGLOG(SW4, INFO,( " ucNumRetainedPacket %u\n", prAdapter->rRxCtrl.ucNumRetainedPacket));
335
336
337 }
338
339
340 void dumpSTA(P_ADAPTER_T prAdapter, P_STA_RECORD_T prStaRec)
341 {
342     UINT_8 ucWTEntry;
343     UINT_32 i;
344     P_BSS_INFO_T            prBssInfo;
345
346     DEBUGFUNC("dumpSTA");
347
348     ASSERT(prStaRec);
349     ucWTEntry = prStaRec->ucWTEntry;
350
351     prBssInfo = &prAdapter->rWifiVar.arBssInfo[prStaRec->ucNetTypeIndex];
352     ASSERT(prBssInfo);
353
354     DBGLOG(SW4, INFO,("Mac address: " MACSTR " Rcpi %u" "\n", MAC2STR(prStaRec->aucMacAddr),prStaRec->ucRCPI));
355
356     DBGLOG(SW4, INFO,("Idx %u Wtbl %u Used %u State %u Bss Phy 0x%x Sta DesiredPhy 0x%x\n",
357                 prStaRec->ucIndex, ucWTEntry,
358                 prStaRec->fgIsInUse,prStaRec->ucStaState,
359                 prBssInfo->ucPhyTypeSet,
360                 prStaRec->ucDesiredPhyTypeSet));
361
362     DBGLOG(SW4, INFO,("Sta Operation 0x%x  DesiredNontHtRateSet  0x%x Mcs 0x%x u2HtCapInfo 0x%x\n",
363                 prStaRec->u2OperationalRateSet,prStaRec->u2DesiredNonHTRateSet,prStaRec->ucMcsSet, prStaRec->u2HtCapInfo));
364
365
366     for(i = 0; i<NUM_OF_PER_STA_TX_QUEUES; i++) {
367         DBGLOG(SW4, INFO,( "TC %u Queue Len %u\n",i,prStaRec->arTxQueue[i].u4NumElem));
368    }
369
370     DBGLOG(SW4, INFO, ("BmpDeliveryAC %x\n",prStaRec->ucBmpDeliveryAC));
371     DBGLOG(SW4, INFO, ("BmpTriggerAC  %x\n",prStaRec->ucBmpTriggerAC));
372     DBGLOG(SW4, INFO, ("UapsdSpSupproted  %u\n",prStaRec->fgIsUapsdSupported));
373     DBGLOG(SW4, INFO, ("IsQoS  %u\n",prStaRec->fgIsQoS));
374     DBGLOG(SW4, INFO, ("AssocId %u\n",prStaRec->u2AssocId));
375
376     DBGLOG(SW4, INFO, ("fgIsInPS %u\n",prStaRec->fgIsInPS));
377     DBGLOG(SW4, INFO, ("ucFreeQuota %u\n",prStaRec->ucFreeQuota));
378     DBGLOG(SW4, INFO, ("ucFreeQuotaForDelivery %u\n",prStaRec->ucFreeQuotaForDelivery));
379     DBGLOG(SW4, INFO, ("ucFreeQuotaForNonDelivery %u\n",prStaRec->ucFreeQuotaForNonDelivery));
380
381
382 #if 0
383     DBGLOG(SW4, INFO, ("IsQmmSup  %u\n",prStaRec->fgIsWmmSupported));
384     DBGLOG(SW4, INFO, ("IsUapsdSup  %u\n",prStaRec->fgIsUapsdSupported));
385     DBGLOG(SW4, INFO, ("AvailabaleDeliverPkts  %u\n",prStaRec->ucAvailableDeliverPkts));
386     DBGLOG(SW4, INFO, ("BmpDeliverPktsAC  %u\n",prStaRec->u4BmpDeliverPktsAC));
387     DBGLOG(SW4, INFO, ("BmpBufferAC  %u\n",prStaRec->u4BmpBufferAC));
388     DBGLOG(SW4, INFO, ("BmpNonDeliverPktsAC  %u\n",prStaRec->u4BmpNonDeliverPktsAC));
389 #endif
390
391     for(i=0;i<CFG_RX_MAX_BA_TID_NUM;i++) {
392         if(prStaRec->aprRxReorderParamRefTbl[i]){
393             DBGLOG(SW4, INFO,("RxReorder fgIsValid: %u\n",prStaRec->aprRxReorderParamRefTbl[i]->fgIsValid));
394             DBGLOG(SW4, INFO,("RxReorder Tid: %u\n",prStaRec->aprRxReorderParamRefTbl[i]->ucTid));
395             DBGLOG(SW4, INFO,("RxReorder rReOrderQue Len: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->rReOrderQue.u4NumElem));
396             DBGLOG(SW4, INFO,("RxReorder WinStart: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->u2WinStart));
397             DBGLOG(SW4, INFO,("RxReorder WinEnd: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->u2WinEnd));
398             DBGLOG(SW4, INFO,("RxReorder WinSize: %u\n", prStaRec->aprRxReorderParamRefTbl[i]->u2WinSize));
399         }
400     }
401
402 }
403
404
405 VOID dumpBss(P_ADAPTER_T prAdapter, P_BSS_INFO_T prBssInfo)
406 {
407
408     DBGLOG(SW4, INFO, ("SSID %s\n",prBssInfo->aucSSID));
409     DBGLOG(SW4, INFO, ("OWN " MACSTR"\n",MAC2STR(prBssInfo->aucOwnMacAddr)));
410     DBGLOG(SW4, INFO, ("BSSID " MACSTR"\n",MAC2STR(prBssInfo->aucBSSID)));
411     DBGLOG(SW4, INFO, ("ucNetTypeIndex %u\n",prBssInfo->ucNetTypeIndex));
412     DBGLOG(SW4, INFO, ("eConnectionState %u\n",prBssInfo->eConnectionState));
413     DBGLOG(SW4, INFO, ("eCurrentOPMode %u\n",prBssInfo->eCurrentOPMode));
414     DBGLOG(SW4, INFO, ("fgIsQBSS %u\n",prBssInfo->fgIsQBSS));
415     DBGLOG(SW4, INFO, ("fgIsShortPreambleAllowed %u\n",prBssInfo->fgIsShortPreambleAllowed));
416     DBGLOG(SW4, INFO, ("fgUseShortPreamble %u\n",prBssInfo->fgUseShortPreamble));
417     DBGLOG(SW4, INFO, ("fgUseShortSlotTime %u\n",prBssInfo->fgUseShortSlotTime));
418     DBGLOG(SW4, INFO, ("ucNonHTBasicPhyType %x\n",prBssInfo->ucNonHTBasicPhyType));
419     DBGLOG(SW4, INFO, ("u2OperationalRateSet %x\n",prBssInfo->u2OperationalRateSet));
420     DBGLOG(SW4, INFO, ("u2BSSBasicRateSet %x\n",prBssInfo->u2BSSBasicRateSet));
421     DBGLOG(SW4, INFO, ("ucPhyTypeSet %x\n",prBssInfo->ucPhyTypeSet));
422     DBGLOG(SW4, INFO, ("rStaRecOfClientList %d\n",prBssInfo->rStaRecOfClientList.u4NumElem));
423     DBGLOG(SW4, INFO, ("u2CapInfo %x\n",prBssInfo->u2CapInfo));
424     DBGLOG(SW4, INFO, ("u2ATIMWindow %x\n",prBssInfo->u2ATIMWindow));
425     DBGLOG(SW4, INFO, ("u2AssocId %x\n",prBssInfo->u2AssocId));
426     DBGLOG(SW4, INFO, ("ucDTIMPeriod %x\n",prBssInfo->ucDTIMPeriod));
427     DBGLOG(SW4, INFO, ("ucDTIMCount %x\n",prBssInfo->ucDTIMCount));
428     DBGLOG(SW4, INFO, ("fgIsNetAbsent %x\n", prBssInfo->fgIsNetAbsent));
429     DBGLOG(SW4, INFO, ("eBand %d\n", prBssInfo->eBand));
430     DBGLOG(SW4, INFO, ("ucPrimaryChannel %d\n", prBssInfo->ucPrimaryChannel));
431     DBGLOG(SW4, INFO, ("ucHtOpInfo1 %d\n", prBssInfo->ucHtOpInfo1));
432     DBGLOG(SW4, INFO, ("ucHtOpInfo2 %d\n", prBssInfo->u2HtOpInfo2));
433     DBGLOG(SW4, INFO, ("ucHtOpInfo3 %d\n", prBssInfo->u2HtOpInfo3));
434     DBGLOG(SW4, INFO, ("fgErpProtectMode %d\n", prBssInfo->fgErpProtectMode));
435     DBGLOG(SW4, INFO, ("eHtProtectMode %d\n", prBssInfo->eHtProtectMode));
436     DBGLOG(SW4, INFO, ("eGfOperationMode %d\n", prBssInfo->eGfOperationMode));
437     DBGLOG(SW4, INFO, ("eRifsOperationMode %d\n", prBssInfo->eRifsOperationMode));
438     DBGLOG(SW4, INFO, ("fgObssErpProtectMode %d\n", prBssInfo->fgObssErpProtectMode));
439     DBGLOG(SW4, INFO, ("eObssHtProtectMode %d\n", prBssInfo->eObssHtProtectMode));
440     DBGLOG(SW4, INFO, ("eObssGfProtectMode %d\n", prBssInfo->eObssGfOperationMode));
441     DBGLOG(SW4, INFO, ("fgObssRifsOperationMode %d\n", prBssInfo->fgObssRifsOperationMode));
442     DBGLOG(SW4, INFO, ("fgAssoc40mBwAllowed %d\n", prBssInfo->fgAssoc40mBwAllowed));
443     DBGLOG(SW4, INFO, ("fg40mBwAllowed %d\n", prBssInfo->fg40mBwAllowed));
444     DBGLOG(SW4, INFO, ("eBssSCO %d\n", prBssInfo->eBssSCO));
445
446
447 }
448
449
450
451 VOID swCtrlCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
452 {
453     UINT_8 ucIndex,ucRead;
454     UINT_32 i;
455
456     DEBUGFUNC("swCtrlCmdCategory0");
457
458     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
459
460     i=0;
461
462     if(ucIndex>=SWCTRL_CATA0_INDEX_NUM) return;
463
464     if(ucRead == SWCR_WRITE) {
465         switch(ucIndex) {
466             case SWCTRL_DEBUG:
467 #if DBG
468                 aucDebugModule[ucOpt0] = (UINT_8)g_au4SwCr[1];
469 #endif
470                 break;
471             case SWCTRL_WIFI_VAR:
472                break;
473
474 #if QM_DEBUG_COUNTER
475            case SWCTRL_DUMP_QM_DBG_CNT:
476                 for(i=0;i<QM_DBG_CNT_NUM;i++) {
477                     prAdapter->rQM.au4QmDebugCounters[i] = 0;
478                 }
479                 break;
480            case SWCTRL_QM_DBG_CNT:
481                 prAdapter->rQM.au4QmDebugCounters[ucOpt0] = g_au4SwCr[1];
482
483                break;
484 #endif
485 #if CFG_RX_PKTS_DUMP
486            case SWCTRL_RX_PKTS_DUMP:
487                    //DBGLOG(SW4, INFO,("SWCTRL_RX_PKTS_DUMP: mask %x\n", g_au4SwCr[1]));
488                    prAdapter->rRxCtrl.u4RxPktsDumpTypeMask = g_au4SwCr[1];
489                    break;
490 #endif
491             case SWCTRL_RX_MDNS_FILTER:
492                 {
493                     UINT_32 u4rxfilter;
494                     BOOLEAN fgUpdate = FALSE;
495                     WLAN_STATUS rStatus = WLAN_STATUS_SUCCESS;
496
497                     if (ucOpt0 == SWCR_RX_MDNS_FILTER_CMD_STOP) {
498                         g_u4mDNSRXFilter &= ~(RX_MDNS_FILTER_START);
499
500                         u4rxfilter = prAdapter->u4OsPacketFilter;                                               
501                         fgUpdate = TRUE;
502                     }
503                     else if (ucOpt0 == SWCR_RX_MDNS_FILTER_CMD_START) {
504                         g_u4mDNSRXFilter |= (RX_MDNS_FILTER_START);
505
506                         u4rxfilter = prAdapter->u4OsPacketFilter;                                               
507                         if ((g_u4mDNSRXFilter & RX_MDNS_FILTER_IPV4) ||
508                             (g_u4mDNSRXFilter & RX_MDNS_FILTER_IPV6)) {                                             
509                             u4rxfilter |= PARAM_PACKET_FILTER_ALL_MULTICAST;
510                         }
511                         fgUpdate = TRUE;
512                     }
513                     else if (ucOpt0 == SWCR_RX_MDNS_FILTER_CMD_ADD) {
514                         if (ucOpt1 < 31) {
515                             g_u4mDNSRXFilter |= (1<<ucOpt1);
516                         }
517                     }
518                     else if (ucOpt0 == SWCR_RX_MDNS_FILTER_CMD_REMOVE) {
519                         if (ucOpt1 < 31) {
520                             g_u4mDNSRXFilter &= ~(1<<ucOpt1);
521                         }                                       
522                     }
523
524                     if (fgUpdate == TRUE) {
525                         rStatus = wlanSendSetQueryCmd (
526                             prAdapter,                  /* prAdapter */
527                             CMD_ID_SET_RX_FILTER,       /* ucCID */
528                             TRUE,                       /* fgSetQuery */
529                             FALSE,                      /* fgNeedResp */
530                             FALSE,                      /* fgIsOid */
531                             NULL,                       /* pfCmdDoneHandler */
532                             NULL,                       /* pfCmdTimeoutHandler */
533                             sizeof(UINT_32),            /* u4SetQueryInfoLen */
534                             (PUINT_8) &u4rxfilter,      /* pucInfoBuffer */
535                             NULL,                       /* pvSetQueryBuffer */
536                             0                           /* un4SetQueryBufferLen */                    
537                         );
538                     }
539 //DBGLOG(SW4, INFO,("SWCTRL_RX_MDNS_FILTER: g_u4mDNSRXFilter %x ucOpt0 %x ucOpt1 %x fgUpdate %x u4rxfilter %x, rStatus %x\n", 
540 //                                         g_u4mDNSRXFilter, ucOpt0, ucOpt1, fgUpdate, u4rxfilter, rStatus));
541                 }
542                 break;
543             default:
544                 break;
545         }
546     }
547     else {
548         switch(ucIndex) {
549             case SWCTRL_DEBUG:
550 #if DBG
551                 g_au4SwCr[1] = aucDebugModule[ucOpt0] ;
552 #endif
553                 break;
554             case SWCTRL_MAGIC:
555                 g_au4SwCr[1] = _SWCTRL_MAGIC ;
556                 DBGLOG(SW4, INFO,("BUILD TIME: %s %s\n", __DATE__, __TIME__));
557                 break;
558             case SWCTRL_QM_INFO:
559                     {
560                         P_QUE_MGT_T prQM = &prAdapter->rQM;
561                         switch(ucOpt0) {
562                             case 0:
563                                g_au4SwCr[1] = (QM_GET_TX_QUEUE_LEN(prAdapter, ucOpt1)) ;
564                                g_au4SwCr[2] = prQM->au4MinReservedTcResource[ucOpt1] ;
565                                g_au4SwCr[3] = prQM->au4CurrentTcResource[ucOpt1];
566                                g_au4SwCr[4] = prQM->au4GuaranteedTcResource[ucOpt1];
567                                 break;
568
569                             case 1:
570                                 g_au4SwCr[1] = prQM->au4ForwardCount[ucOpt1];
571                                 g_au4SwCr[2] = prQM->au4HeadStaRecIndex[ucOpt1];
572                                 break;
573
574                             case 2:
575                                 g_au4SwCr[1] = prQM->arTxQueue[ucOpt1].u4NumElem; /* only one */
576
577
578                                 break;
579                         }
580
581                     }
582             case SWCTRL_TX_CTRL_INFO:
583                     {
584                         P_TX_CTRL_T prTxCtrl;
585                         prTxCtrl = &prAdapter->rTxCtrl;
586                         switch(ucOpt0) {
587                                case 0:
588                                     g_au4SwCr[1] =  prAdapter->rTxCtrl.rTc.aucFreeBufferCount[ucOpt1];
589                                     g_au4SwCr[2] =  prAdapter->rTxCtrl.rTc.aucMaxNumOfBuffer[ucOpt1];
590                                     break;
591                         }
592
593                     }
594                     break;
595            case SWCTRL_DUMP_QUEUE:
596                     dumpQueue(prAdapter);
597
598                     break;
599 #if QM_DEBUG_COUNTER
600            case SWCTRL_DUMP_QM_DBG_CNT:
601                     for(i=0;i<QM_DBG_CNT_NUM;i++) {
602                         DBGLOG(SW4, INFO,("QM:DBG %u %u\n",i , prAdapter->rQM.au4QmDebugCounters[i]));
603                     }
604                     break;
605
606            case SWCTRL_QM_DBG_CNT:
607                     g_au4SwCr[1] = prAdapter->rQM.au4QmDebugCounters[ucOpt0];
608                     break;
609 #endif
610             case SWCTRL_DUMP_BSS:
611                     {
612                         dumpBss(prAdapter, &(prAdapter->rWifiVar.arBssInfo[ucOpt0])) ;
613                     }
614                     break;
615
616             default:
617                     break;
618         }
619
620     }
621 }
622
623
624 VOID swCtrlCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
625 {
626     UINT_8 ucIndex,ucRead;
627     UINT_8 ucWTEntry;
628     P_STA_RECORD_T prStaRec;
629
630     DEBUGFUNC("swCtrlCmdCategory1");
631
632     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
633
634     if(ucOpt0>=CFG_STA_REC_NUM) return;
635
636     //prStaRec = cnmGetStaRecByIndex (prAdapter, ucOpt0);
637     prStaRec = &prAdapter->arStaRec[ucOpt0];
638     ucWTEntry =  prStaRec->ucWTEntry;
639     if(ucRead == SWCR_WRITE) {
640     }
641     else {
642         /* Read */
643         switch(ucIndex) {
644             case SWCTRL_STA_QUE_INFO:
645                 {
646                     g_au4SwCr[1] = prStaRec->arTxQueue[ucOpt1].u4NumElem;
647                 }
648                 break;
649             case SWCTRL_STA_INFO:
650                 switch(ucOpt1) {
651                     case 0:
652                         g_au4SwCr[1] = prStaRec->fgIsInPS;
653                         break;
654                 }
655
656                 break;
657
658              case SWCTRL_DUMP_STA:
659                  {
660                      dumpSTA(prAdapter, prStaRec);
661                  }
662                  break;
663
664              default:
665
666                  break;
667         }
668     }
669
670
671 }
672
673 #if TEST_PS
674
675 VOID
676 testPsSendQoSNullFrame (
677     IN P_ADAPTER_T prAdapter,
678     IN P_STA_RECORD_T prStaRec,
679     IN UINT_8           ucUP,
680     IN UINT_8           ucNetTypeIndex,
681     IN BOOLEAN          fgBMC,
682     IN BOOLEAN          fgIsBurstEnd,
683     IN BOOLEAN          ucPacketType,
684     IN BOOLEAN          ucPsSessionID,
685     IN BOOLEAN          fgSetEOSP
686     )
687 {
688     P_MSDU_INFO_T prMsduInfo;
689     UINT_16 u2EstimatedFrameLen;
690     P_WLAN_MAC_HEADER_QOS_T prQoSNullFrame;
691
692
693     DEBUGFUNC("testPsSendQoSNullFrame");
694     DBGLOG(SW4, LOUD, ("\n"));
695
696     //4 <1> Allocate a PKT_INFO_T for Null Frame
697     /* Init with MGMT Header Length */
698     u2EstimatedFrameLen = MAC_TX_RESERVED_FIELD + \
699                           WLAN_MAC_HEADER_QOS_LEN;
700
701     /* Allocate a MSDU_INFO_T */
702     if ( (prMsduInfo = cnmMgtPktAlloc(prAdapter, u2EstimatedFrameLen)) == NULL) {
703         DBGLOG(SW4, WARN, ("No PKT_INFO_T for sending Null Frame.\n"));
704         return ;
705     }
706
707     //4 <2> Compose Null frame in MSDU_INfO_T.
708     bssComposeQoSNullFrame(prAdapter,
709             (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD),
710             prStaRec,
711             ucUP,
712             fgSetEOSP);
713
714
715     prMsduInfo->eSrc = TX_PACKET_MGMT;
716     //prMsduInfo->ucPacketType = HIF_TX_PACKET_TYPE_DATA;
717     prMsduInfo->ucPacketType = ucPacketType;
718     prMsduInfo->ucStaRecIndex = prStaRec->ucIndex;
719     prMsduInfo->ucNetworkType = ucNetTypeIndex;
720     prMsduInfo->ucMacHeaderLength = WLAN_MAC_HEADER_QOS_LEN;
721     prMsduInfo->fgIs802_1x = FALSE;
722     prMsduInfo->fgIs802_11 = TRUE;
723     prMsduInfo->u2FrameLength = WLAN_MAC_HEADER_QOS_LEN;
724     prMsduInfo->ucTxSeqNum = nicIncreaseTxSeqNum(prAdapter);
725     prMsduInfo->pfTxDoneHandler = NULL;
726     prMsduInfo->fgIsBasicRate = TRUE;
727     prMsduInfo->fgIsBurstEnd = fgIsBurstEnd;
728     prMsduInfo->ucUserPriority = ucUP;
729     prMsduInfo->ucPsSessionID = ucPsSessionID  /* 0~7 Test 7 means NOACK*/;
730
731     prQoSNullFrame = (P_WLAN_MAC_HEADER_QOS_T)(  (PUINT_8)((UINT_32)(prMsduInfo->prPacket) + MAC_TX_RESERVED_FIELD)   );
732
733     if(fgBMC) {
734         prQoSNullFrame->aucAddr1[0] = 0xfd;
735     }
736     else {
737         prQoSNullFrame->aucAddr1[5] = 0xdd;
738     }
739
740     //4 <4> Inform TXM  to send this Null frame.
741     nicTxEnqueueMsdu(prAdapter, prMsduInfo);
742
743 }
744
745
746
747 VOID
748 testPsSetupBss(
749     IN P_ADAPTER_T prAdapter,
750     IN UINT_8 ucNetworkTypeIndex
751     )
752 {
753     P_BSS_INFO_T prBssInfo;
754     UINT_8 _aucZeroMacAddr[] = NULL_MAC_ADDR;
755
756     DEBUGFUNC("testPsSetupBss()");
757     DBGLOG(SW4, INFO, ("index %d\n", ucNetworkTypeIndex));
758
759     prBssInfo = &(prAdapter->rWifiVar.arBssInfo[ucNetworkTypeIndex]);
760
761     //4 <1.2> Initiate PWR STATE
762     //SET_NET_PWR_STATE_IDLE(prAdapter, ucNetworkTypeIndex);
763
764
765     //4 <2> Initiate BSS_INFO_T - common part
766     BSS_INFO_INIT(prAdapter, ucNetworkTypeIndex);
767
768     prBssInfo->eConnectionState = PARAM_MEDIA_STATE_DISCONNECTED;
769     prBssInfo->eConnectionStateIndicated = PARAM_MEDIA_STATE_DISCONNECTED;
770     prBssInfo->eCurrentOPMode = OP_MODE_ACCESS_POINT;
771     prBssInfo->fgIsNetActive = TRUE;
772     prBssInfo->ucNetTypeIndex = (ucNetworkTypeIndex);
773     prBssInfo->ucReasonOfDisconnect = DISCONNECT_REASON_CODE_RESERVED;
774
775     prBssInfo->ucPhyTypeSet = PHY_TYPE_SET_802_11BG; /* Depend on eBand */
776     prBssInfo->ucConfigAdHocAPMode = AP_MODE_MIXED_11BG; /* Depend on eCurrentOPMode and ucPhyTypeSet */
777     prBssInfo->u2BSSBasicRateSet = RATE_SET_ERP;
778     prBssInfo->u2OperationalRateSet = RATE_SET_OFDM;
779     prBssInfo->fgErpProtectMode = FALSE;
780     prBssInfo->fgIsQBSS = TRUE;
781
782     //4 <1.5> Setup MIB for current BSS
783     prBssInfo->u2BeaconInterval = 100;
784     prBssInfo->ucDTIMPeriod = DOT11_DTIM_PERIOD_DEFAULT;
785     prBssInfo->u2ATIMWindow = 0;
786
787     prBssInfo->ucBeaconTimeoutCount = 0;
788
789
790     bssInitForAP (prAdapter,prBssInfo, TRUE);
791
792     COPY_MAC_ADDR(prBssInfo->aucBSSID, _aucZeroMacAddr);
793     LINK_INITIALIZE(&prBssInfo->rStaRecOfClientList);
794     prBssInfo->fgIsBeaconActivated = TRUE;
795     prBssInfo->ucHwDefaultFixedRateCode = RATE_CCK_1M_LONG;
796
797
798     COPY_MAC_ADDR(prBssInfo->aucOwnMacAddr, prAdapter->rWifiVar.aucMacAddress);
799
800     //4 <3> Initiate BSS_INFO_T - private part
801     /* TODO */
802     prBssInfo->eBand = BAND_2G4;
803     prBssInfo->ucPrimaryChannel = 1;
804     prBssInfo->prStaRecOfAP = (P_STA_RECORD_T)NULL;
805
806
807     //prBssInfo->fgErpProtectMode =  eErpProectMode;
808     //prBssInfo->eHtProtectMode = eHtProtectMode;
809     //prBssInfo->eGfOperationMode = eGfOperationMode;
810
811
812     //4 <4> Allocate MSDU_INFO_T for Beacon
813     prBssInfo->prBeacon = cnmMgtPktAlloc(prAdapter,
814             OFFSET_OF(WLAN_BEACON_FRAME_T, aucInfoElem[0]) + MAX_IE_LENGTH);
815
816     if (prBssInfo->prBeacon) {
817         prBssInfo->prBeacon->eSrc = TX_PACKET_MGMT;
818         prBssInfo->prBeacon->ucNetworkType = ucNetworkTypeIndex;
819     }
820     else {
821         DBGLOG(SW4, INFO, ("prBeacon allocation fail\n"));
822     }
823
824 #if 0
825     prBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC = PM_UAPSD_ALL;
826     prBssInfo->rPmProfSetupInfo.ucBmpTriggerAC = PM_UAPSD_ALL;
827     prBssInfo->rPmProfSetupInfo.ucUapsdSp = WMM_MAX_SP_LENGTH_2;
828 #else
829     prBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC = (UINT_8)prAdapter->u4UapsdAcBmp;
830     prBssInfo->rPmProfSetupInfo.ucBmpTriggerAC =(UINT_8) prAdapter->u4UapsdAcBmp;
831     prBssInfo->rPmProfSetupInfo.ucUapsdSp = (UINT_8)prAdapter->u4MaxSpLen;
832 #endif
833
834 #if 0
835     for(eAci = 0; eAci < WMM_AC_INDEX_NUM; eAci++){
836
837         prBssInfo->arACQueParms[eAci].fgIsACMSet = FALSE;
838         prBssInfo->arACQueParms[eAci].u2Aifsn = (UINT_16) eAci;
839         prBssInfo->arACQueParms[eAci].u2CWmin = 7;
840         prBssInfo->arACQueParms[eAci].u2CWmax = 31;
841         prBssInfo->arACQueParms[eAci].u2TxopLimit = eAci+1;
842         DBGLOG(SW4, INFO, ("MQM: eAci = %d, ACM = %d, Aifsn = %d, CWmin = %d, CWmax = %d, TxopLimit = %d\n",
843                    eAci,prBssInfo->arACQueParms[eAci].fgIsACMSet ,
844                    prBssInfo->arACQueParms[eAci].u2Aifsn,
845                    prBssInfo->arACQueParms[eAci].u2CWmin,
846                    prBssInfo->arACQueParms[eAci].u2CWmax,
847                    prBssInfo->arACQueParms[eAci].u2TxopLimit));
848
849     }
850 #endif
851
852
853     DBGLOG(SW4, INFO, ("[2] ucBmpDeliveryAC:0x%x, ucBmpTriggerAC:0x%x, ucUapsdSp:0x%x",
854             prBssInfo->rPmProfSetupInfo.ucBmpDeliveryAC,
855             prBssInfo->rPmProfSetupInfo.ucBmpTriggerAC,
856             prBssInfo->rPmProfSetupInfo.ucUapsdSp));
857
858     return;
859 }
860
861
862
863
864 VOID testPsCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
865 {
866     UINT_8 ucIndex,ucRead;
867     P_STA_RECORD_T prStaRec;
868
869     DEBUGFUNC("testPsCmdCategory0");
870     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
871
872     DBGLOG(SW4, LOUD, ("Read %u Index %u\n",ucRead,ucIndex));
873
874     prStaRec = cnmGetStaRecByIndex (prAdapter, 0);
875
876     if(ucIndex>=TEST_PS_CATA0_INDEX_NUM) return;
877
878     if(ucRead == SWCR_WRITE) {
879         switch(ucIndex) {
880             case TEST_PS_SETUP_BSS:
881                 testPsSetupBss(prAdapter, ucOpt0) ;
882                 break;
883
884             case TEST_PS_ENABLE_BEACON:
885                break;
886
887             case TEST_PS_TRIGGER_BMC:
888                 //txmForwardQueuedBmcPkts (ucOpt0);
889                 break;
890             case TEST_PS_SEND_NULL:
891                 {
892
893                     testPsSendQoSNullFrame (prAdapter,prStaRec,
894                             (UINT_8)(g_au4SwCr[1] & 0xFF), /* UP */
895                             ucOpt0,
896                             (BOOLEAN)((g_au4SwCr[1] >>8)& 0xFF), /* BMC*/
897                             (BOOLEAN)((g_au4SwCr[1] >>16)& 0xFF), /* BurstEnd*/
898                             (BOOLEAN)((g_au4SwCr[1] >>24)& 0xFF), /* Packet type*/
899                             (UINT_8)((g_au4SwCr[2] )& 0xFF), /* PS sesson ID 7: NOACK */
900                             FALSE                                  /* EOSP */
901                         );
902                 }
903                     break;
904             case TEST_PS_BUFFER_BMC:
905                 //g_aprBssInfo[ucOpt0]->fgApToBufferBMC = (g_au4SwCr[1] & 0xFF);
906                 break;
907             case TEST_PS_UPDATE_BEACON:
908                 bssUpdateBeaconContent(prAdapter, ucOpt0 /*networktype*/ );
909                 break;
910
911            default:
912                 break;
913         }
914     }
915     else {
916         switch(ucIndex) {
917
918             case TEST_PS_MAGIC:
919                 g_au4SwCr[1] = 0x88660011 ;
920                 break;
921
922         }
923     }
924 }
925
926 #endif //TEST_PS
927
928 #if TEST_PS
929
930 VOID testPsCmdCategory1(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
931 {
932     UINT_8 ucIndex,ucRead;
933     UINT_8 ucWTEntry;
934     P_STA_RECORD_T prStaRec;
935
936     DEBUGFUNC("testPsCmdCategory1");
937
938     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
939
940     if(ucOpt0>=CFG_STA_REC_NUM) return;
941
942     prStaRec = cnmGetStaRecByIndex (prAdapter, ucOpt0);
943     ucWTEntry =  prStaRec->ucWTEntry;
944     if(ucRead == SWCR_WRITE) {
945
946         switch(ucIndex) {
947             case TEST_PS_STA_PS:
948                 prStaRec->fgIsInPS = (BOOLEAN) (g_au4SwCr[1] & 0x1);
949                 prStaRec->fgIsQoS = (BOOLEAN) (g_au4SwCr[1] >>8 & 0xFF);
950                 prStaRec->fgIsUapsdSupported = (BOOLEAN) (g_au4SwCr[1] >>16 & 0xFF);
951                 prStaRec->ucBmpDeliveryAC = (BOOLEAN) (g_au4SwCr[1] >>24 & 0xFF);
952                 break;
953
954         }
955
956     }
957     else {
958         /* Read */
959         switch(ucIndex) {
960             default:
961                 break;
962         }
963     }
964
965
966 }
967
968 #endif //TEST_PS
969
970 #if CFG_SUPPORT_802_11V
971 #if (CFG_SUPPORT_802_11V_TIMING_MEASUREMENT ==1) && (WNM_UNIT_TEST ==1)
972 VOID testWNMCmdCategory0(P_ADAPTER_T prAdapter, UINT_8 ucCate, UINT_8 ucAction, UINT_8 ucOpt0,UINT_8 ucOpt1)
973 {
974     UINT_8 ucIndex,ucRead;
975     P_STA_RECORD_T prStaRec;
976
977     DEBUGFUNC("testWNMCmdCategory0");
978     SWCR_GET_RW_INDEX(ucAction,ucRead,ucIndex);
979
980     DBGLOG(SW4, INFO, ("Read %u Index %u\n",ucRead,ucIndex));
981
982     if(ucIndex>=TEST_WNM_CATA0_INDEX_NUM) return;
983
984     if(ucRead == SWCR_WRITE) {
985         switch(ucIndex) {
986             case TEST_WNM_TIMING_MEAS:
987                 wnmTimingMeasUnitTest1(prAdapter, ucOpt0) ;
988                 break;
989
990            default:
991                 break;
992         }
993     }
994 }
995 #endif //TEST_WNM
996 #endif //CFG_SUPPORT_802_11V
997
998 VOID swCtrlSwCr(P_ADAPTER_T prAdapter, UINT_8 ucRead, UINT_16 u2Addr, UINT_32 *pu4Data)
999 {
1000     /* According other register STAIDX */
1001     UINT_8      ucOffset;
1002     ucOffset = (u2Addr>>2) & 0x3F;
1003
1004     if(ucOffset>= SWCR_CR_NUM) return;
1005
1006     if(ucRead==SWCR_WRITE) {
1007         g_au4SwCr[ucOffset] = *pu4Data;
1008         if(ucOffset==0x0) {
1009             /* Commmand   [31:24]: Category */
1010             /* Commmand   [23:23]: 1(W) 0(R) */
1011             /* Commmand   [22:16]: Index */
1012             /* Commmand   [15:08]: Option0  */
1013             /* Commmand   [07:00]: Option1   */
1014             UINT_8 ucCate;
1015             UINT_32 u4Cmd;
1016             u4Cmd = g_au4SwCr[0];
1017             ucCate = (UINT_8)(u4Cmd >> 24) ;
1018             if(ucCate < sizeof(g_arSwCtrlCmd)/sizeof(g_arSwCtrlCmd[0])) {
1019                 if(g_arSwCtrlCmd[ucCate]!=NULL) {
1020                     g_arSwCtrlCmd[ucCate](prAdapter, ucCate, (UINT_8)(u4Cmd>>16 & 0xFF),(UINT_8)((u4Cmd>>8) & 0xFF), (UINT_8)(u4Cmd&0xFF));
1021                 }
1022             }
1023         }
1024     }
1025     else {
1026         *pu4Data = g_au4SwCr[ucOffset];
1027     }
1028 }
1029
1030 VOID swCrReadWriteCmd(P_ADAPTER_T prAdapter, UINT_8 ucRead, UINT_16 u2Addr, UINT_32 *pu4Data)
1031 {
1032     UINT_8 ucMod;
1033
1034     ucMod =  u2Addr >>8;
1035     /* Address [15:8] MOD ID */
1036     /* Address [7:0] OFFSET */
1037
1038     DEBUGFUNC("swCrReadWriteCmd");
1039     DBGLOG(SW4, INFO, ("%u addr 0x%x data 0x%x\n",ucRead,u2Addr,*pu4Data));
1040
1041     if(ucMod < (sizeof(g_arSwCrModHandle)/sizeof(g_arSwCrModHandle[0])) ) {
1042
1043         if(g_arSwCrModHandle[ucMod]!=NULL) {
1044          g_arSwCrModHandle[ucMod](prAdapter, ucRead, u2Addr, pu4Data);
1045         }
1046    } /* ucMod */
1047 }
1048
1049 /* Debug Support */
1050 VOID swCrFrameCheckEnable(P_ADAPTER_T  prAdapter, UINT_32 u4DumpType)
1051 {
1052           g_u4SwcrDebugFrameDumpType = u4DumpType;
1053           prAdapter->rRxCtrl.u4RxPktsDumpTypeMask = u4DumpType;   
1054 }
1055
1056 VOID swCrDebugInit(P_ADAPTER_T  prAdapter)
1057 {
1058           // frame dump
1059     if (g_u4SwcrDebugFrameDumpType) {
1060           swCrFrameCheckEnable(prAdapter, g_u4SwcrDebugFrameDumpType);
1061     }
1062
1063     // debug counter
1064     g_fgSwcrDebugTimer = FALSE;
1065
1066     cnmTimerInitTimer(prAdapter,
1067                       &g_rSwcrDebugTimer,
1068                       (PFN_MGMT_TIMEOUT_FUNC)swCrDebugCheckTimeout,
1069                       (UINT_32) NULL);
1070     
1071     if (g_u4SwcrDebugCheckTimeout) {
1072           swCrDebugCheckEnable(prAdapter, TRUE, g_ucSwcrDebugCheckType, g_u4SwcrDebugCheckTimeout);
1073     }        
1074 }
1075
1076 VOID swCrDebugUninit(P_ADAPTER_T  prAdapter)
1077 {
1078           cnmTimerStopTimer(prAdapter, &g_rSwcrDebugTimer);       
1079           
1080           g_fgSwcrDebugTimer = FALSE;
1081 }
1082
1083 VOID swCrDebugCheckEnable(P_ADAPTER_T  prAdapter, BOOLEAN fgIsEnable, UINT_8 ucType, UINT_32 u4Timeout)
1084 {
1085           if (fgIsEnable) {
1086                   g_ucSwcrDebugCheckType = ucType;
1087                   g_u4SwcrDebugCheckTimeout = u4Timeout;
1088                   if (g_fgSwcrDebugTimer == FALSE) {                                  
1089                       swCrDebugCheckTimeout(prAdapter, 0);
1090                   }
1091           }
1092           else {
1093                   cnmTimerStopTimer(prAdapter, &g_rSwcrDebugTimer);
1094                   g_u4SwcrDebugCheckTimeout = 0;
1095           }
1096           
1097           g_fgSwcrDebugTimer = fgIsEnable;
1098 }
1099
1100 VOID swCrDebugCheck(P_ADAPTER_T  prAdapter, P_CMD_SW_DBG_CTRL_T prCmdSwCtrl)
1101 {
1102     P_RX_CTRL_T prRxCtrl;
1103     P_TX_CTRL_T prTxCtrl;
1104
1105     ASSERT(prAdapter);
1106
1107     prTxCtrl = &prAdapter->rTxCtrl;
1108     prRxCtrl = &prAdapter->rRxCtrl;
1109
1110     // dump counters
1111     if (prCmdSwCtrl) {
1112           if (prCmdSwCtrl->u4Data == SWCR_DBG_TYPE_ALL) {
1113
1114             // TX Counter from fw
1115             DBGLOG(SW4, INFO,  ("TX0\n" \
1116                                "%08x %08x %08x %08x\n" \
1117                                "%08x %08x %08x %08x\n",
1118                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_CNT],
1119                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_BCN_CNT],
1120                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_FAILED_CNT],
1121                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_RETRY_CNT],
1122                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_AGING_TIMEOUT_CNT],
1123                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_PS_OVERFLOW_CNT],
1124                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_MGNT_DROP_CNT],
1125                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_TX_ERROR_CNT]));
1126 #if 1
1127             // TX Counter from drv
1128             DBGLOG(SW4, INFO,  ("TX1\n" \
1129                                "%08x %08x %08x %08x\n",
1130                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_INACTIVE_BSS_DROP),
1131                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_INACTIVE_STA_DROP),
1132                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_FORWARD_OVERFLOW_DROP),
1133                                (UINT_32)TX_GET_CNT(prTxCtrl, TX_AP_BORADCAST_DROP)));
1134 #endif
1135
1136             // RX Counter
1137             DBGLOG(SW4, INFO,  ("RX0\n" \
1138                                "%08x %08x %08x %08x\n" \
1139                                "%08x %08x %08x %08x\n" \
1140                                "%08x %08x %08x %08x\n" \
1141                                "%08x %08x %08x %08x\n",
1142                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_CNT],
1143                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_DROP_CNT],
1144                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_DUP_DROP_CNT],
1145                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_TYPE_ERROR_DROP_CNT],
1146                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_CLASS_ERROR_DROP_CNT],
1147                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_AMPDU_ERROR_DROP_CNT],
1148                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_STATUS_ERROR_DROP_CNT],
1149                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_FORMAT_ERROR_DROP_CNT],
1150                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_ICV_ERROR_DROP_CNT],
1151                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_KEY_ERROR_DROP_CNT],
1152                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_TKIP_ERROR_DROP_CNT],
1153                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_MIC_ERROR_DROP_CNT],
1154                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_BIP_ERROR_DROP_CNT],
1155                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_FCSERR_CNT],
1156                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_FIFOFULL_CNT],
1157                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_RX_PFDROP_CNT]));
1158
1159             DBGLOG(SW4, INFO,  ("RX1\n" \
1160                                "%08x %08x %08x %08x\n" \
1161                                "%08x %08x %08x %08x\n",
1162                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_MPDU_TOTAL_COUNT),
1163                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DATA_INDICATION_COUNT),
1164                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DATA_RETURNED_COUNT),
1165                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DATA_RETAINED_COUNT),
1166                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DROP_TOTAL_COUNT),
1167                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_TYPE_ERR_DROP_COUNT),
1168                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_CLASS_ERR_DROP_COUNT),
1169                                (UINT_32)RX_GET_CNT(prRxCtrl, RX_DST_NULL_DROP_COUNT)));
1170
1171             DBGLOG(SW4, INFO,  ("PWR\n" \
1172                                "%08x %08x %08x %08x\n" \
1173                                "%08x %08x %08x %08x\n",
1174                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_PS_POLL_CNT],
1175                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_TRIGGER_NULL_CNT],
1176                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_BCN_IND_CNT],
1177                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_BCN_TIMEOUT_CNT],
1178                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_PM_STATE0],
1179                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_PM_STATE1],
1180                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_CUR_PS_PROF0],
1181                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_PWR_CUR_PS_PROF1]));
1182
1183             DBGLOG(SW4, INFO,  ("ARM\n" \
1184                                "%08x %08x %08x %08x\n" \
1185                                "%08x %08x\n",
1186                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_AR_STA0_RATE],
1187                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_AR_STA0_BWGI],
1188                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_AR_STA0_RX_RATE_RCPI],
1189                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_ROAMING_ENABLE],
1190                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_ROAMING_ROAM_CNT],
1191                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_ROAMING_INT_CNT]));
1192
1193             DBGLOG(SW4, INFO,  ("BB\n" \
1194                                "%08x %08x %08x %08x\n" \
1195                                "%08x %08x %08x %08x\n",
1196                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_RX_MDRDY_CNT],
1197                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_RX_FCSERR_CNT],
1198                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_CCK_PD_CNT],
1199                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_OFDM_PD_CNT],
1200                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_CCK_SFDERR_CNT],
1201                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_CCK_SIGERR_CNT],
1202                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_OFDM_TAGERR_CNT],
1203                                prCmdSwCtrl->u4DebugCnt[SWCR_DBG_ALL_BB_OFDM_SIGERR_CNT]));
1204
1205         }
1206     }
1207
1208     // start the next check
1209           if (g_u4SwcrDebugCheckTimeout) {
1210                   cnmTimerStartTimer(prAdapter, &g_rSwcrDebugTimer, g_u4SwcrDebugCheckTimeout * MSEC_PER_SEC);
1211           }
1212 }
1213
1214 VOID swCrDebugCheckTimeout(
1215     IN P_ADAPTER_T prAdapter,
1216     UINT_32 u4Param)
1217 {
1218           CMD_SW_DBG_CTRL_T rCmdSwCtrl;
1219           WLAN_STATUS rStatus;
1220
1221     rCmdSwCtrl.u4Id = (0xb000<<16) + g_ucSwcrDebugCheckType;
1222     rCmdSwCtrl.u4Data = 0;
1223           rStatus = wlanSendSetQueryCmd (
1224                 prAdapter,                  /* prAdapter */
1225                 CMD_ID_SW_DBG_CTRL,       /* ucCID */
1226                 FALSE,                      /* fgSetQuery */
1227                 TRUE,                       /* fgNeedResp */
1228                 FALSE,                      /* fgIsOid */
1229                 swCrDebugQuery,             /* pfCmdDoneHandler */
1230                 swCrDebugQueryTimeout,      /* pfCmdTimeoutHandler */
1231                 sizeof(CMD_SW_DBG_CTRL_T),  /* u4SetQueryInfoLen */
1232                 (PUINT_8)&rCmdSwCtrl,       /* pucInfoBuffer */
1233                 NULL,                       /* pvSetQueryBuffer */
1234                 0                           /* u4SetQueryBufferLen */
1235                 );
1236
1237     ASSERT(rStatus == WLAN_STATUS_PENDING);
1238
1239     return;
1240 }
1241
1242 VOID swCrDebugQuery(
1243     IN P_ADAPTER_T  prAdapter,
1244     IN P_CMD_INFO_T prCmdInfo,
1245     IN PUINT_8      pucEventBuf
1246     )
1247 {
1248     ASSERT(prAdapter);
1249
1250     swCrDebugCheck(prAdapter, (P_CMD_SW_DBG_CTRL_T)(pucEventBuf));
1251 }
1252
1253 VOID swCrDebugQueryTimeout(
1254     IN P_ADAPTER_T  prAdapter,
1255     IN P_CMD_INFO_T prCmdInfo)
1256 {
1257           ASSERT(prAdapter);
1258
1259     swCrDebugCheck(prAdapter, NULL);
1260 }
1261
1262 #endif /* CFG_SUPPORT_SWCR */
1263
1264