summaryrefslogtreecommitdiff
path: root/wl1271/Test/fwdriverdebug.c
blob: c7f1ba326be40dc80408c3b45b693e3bce8aa8a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
/*
 * fwdriverdebug.c
 *
 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved.      
 * All rights reserved.                                                  
 *                                                                       
 * Redistribution and use in source and binary forms, with or without    
 * modification, are permitted provided that the following conditions    
 * are met:                                                              
 *                                                                       
 *  * Redistributions of source code must retain the above copyright     
 *    notice, this list of conditions and the following disclaimer.      
 *  * Redistributions in binary form must reproduce the above copyright  
 *    notice, this list of conditions and the following disclaimer in    
 *    the documentation and/or other materials provided with the         
 *    distribution.                                                      
 *  * Neither the name Texas Instruments nor the names of its            
 *    contributors may be used to endorse or promote products derived    
 *    from this software without specific prior written permission.      
 *                                                                       
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS   
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT     
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT  
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT      
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT   
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


/***************************************************************************/
/*                                                                         */
/*    MODULE:   FW_debug.c                                                 */
/*    PURPOSE:  FW debug implementation                                    */
/*                                                                         */
/***************************************************************************/
#include "tidef.h"
#include "DrvMain.h"
#include "CmdQueue_api.h"
#include "debug.h"
#include "connDebug.h"
#include "siteMgrDebug.h"
#include "dataCtrlDbg.h"
#include "rsnDbg.h"
#include "osApi.h"
#include "report.h"
#include "qosMngrDbg.h"
#include "PowerMgrDebug.h"
#include "roamingMgrDebug.h"
#include "scanCncnDbg.h"
#include "ScanMngrDbg.h"
#include "scrDbg.h"
#include "SoftGeminiDbg.h"
#include "HealthMonitorDbg.h"
#include "smeDebug.h"
#include "TWDriver.h"
#include "CmdBld.h"
#include "commonTypes.h"
#include "siteHash.h"
#include "txCtrl.h"
#include "802_11Defs.h"
#include "fwdriverdebug.h"
#include "mlmeBuilder.h"
#include "Ethernet.h"

static TI_HANDLE dTimer;
static TI_HANDLE tmp_hMlme;
static TI_HANDLE tmp_hTWD;
static TI_HANDLE tmp_hTxCtrl;
static TI_BOOL SendFlag = 0;
static TI_BOOL bSendDataPkt;
static volatile TI_UINT32 numOfPackets;
static volatile TI_UINT8 infinitLoopFl = 0;
static TI_UINT32 packetsNum;
static TI_UINT32 packetLength;

typedef TI_STATUS (*TCmdCfgFuncB) (TI_HANDLE);

extern TI_STATUS cmdBld_CmdJoinBss (TI_HANDLE hCmdBld, TJoinBss *pJoinBssParams, void *fCb, TI_HANDLE hCb);
void sendMgmtPacket (TI_HANDLE hOs);
void sendDataPacket (TI_HANDLE hOs);

void FWDebugFunction(TI_HANDLE hDrvMain, 
					 TI_HANDLE hOs, 
					 TI_HANDLE hTWD, 
					 TI_HANDLE hMlme, 
					 TI_HANDLE hTxMgmtQ,
					 TI_HANDLE hTxCtrl,
					 unsigned long funcType, 
					 void *pParam)
{
	tmp_hMlme   = hMlme;
    tmp_hTWD    = hTWD;
    tmp_hTxCtrl = hTxCtrl;

	switch (funcType)
	{
	case DBG_FW_PRINT_HELP:
		 printFWDbgFunctions();
		 break;
	case DBG_FW_SEND_GENERAL_TEST_CMD:
		 FW_debugSendGeneralTestCmd(hTWD, pParam);
		 break;
	case DBG_FW_IBSS_CONNECTION:
		 FW_DebugSendJoinCommand(hTWD, hTxMgmtQ);
		 break;
	case DBG_FW_SEND_MGMT_PACKET:
         bSendDataPkt = TI_FALSE;
		 FW_DebugSendPacket(hDrvMain, hOs, hTxMgmtQ, pParam);
		 break;
    case DBG_FW_SEND_DATA_PACKET: 
         bSendDataPkt = TI_TRUE;
		 FW_DebugSendPacket(hDrvMain, hOs, hTxMgmtQ, pParam);
		 break;
	case DBG_FW_START_LOOPBACK:
		 FW_DebugStartLoopBack (hDrvMain, hTWD);
		 break;
	case DBG_FW_STOP_LOOPBACK:
		 FW_DebugStopLoopBack (hDrvMain, hTWD);
		 break;
	case DBG_FW_INFINIT_SEND:
		 FW_DebugInfinitSendPacket (hDrvMain, hTWD);
		 break;

	case DBG_FW_GENERAL:
		 FW_DebugGeneral (hTWD, pParam);
		 break;
	default:
		break;


 }
}

void printFWDbgFunctions(void)
{
    WLAN_OS_REPORT(("    FW Debug Functions     	          	\n"));
    WLAN_OS_REPORT(("---------------------------------------------------\n"));
    WLAN_OS_REPORT(("2200 		- Print the FW Debug Help		\n"));
    WLAN_OS_REPORT(("2201 		- Send General Test Command 	\n"));
    WLAN_OS_REPORT(("2202 		- create IBSS connection   	 	\n"));
    WLAN_OS_REPORT(("2203[n] 	- Send n<=999 Packets           \n"));
    WLAN_OS_REPORT(("2205 		- Start LoopBack            	\n"));
    WLAN_OS_REPORT(("2206 		- Stop LoopBack             	\n"));
}


void FW_debugSendGeneralTestCmd(TI_HANDLE hTWD, void *pParam)
{
	TTwd     *pTWD = (TTwd *)hTWD;
	FWDebugTestCmdParamter_t Cfg;
	unsigned char Len;
	Len = *(unsigned char *)pParam;
	
	os_memoryCopy(pTWD->hOs, Cfg.buf,(unsigned long*)pParam + sizeof(TI_UINT8),Len * 4 );
  
	Cfg.len = Len;
	
	/* Set information element header */
	Cfg.EleHdr.id = CMD_TEST;
	Cfg.EleHdr.len = sizeof(Cfg) - sizeof(EleHdrStruct);
	  
    cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_CONFIGURE, (void*)&Cfg, sizeof(Cfg), NULL, NULL, NULL);
}

void FW_DebugSendJoinCommand(TI_HANDLE hTWD, TI_HANDLE hTxMgmtQ)
{
	TTwd     *pTWD = (TTwd *)hTWD;
	TCmdBld  *pCmdBld = (TCmdBld *)(pTWD->hCmdBld);
	TI_STATUS res;
	TJoinBss  JoinBss;
	char ssid[10];
	unsigned char Bssid[6] = {0x0,0x12,0x43,0xad,0xe5,0x10};

	os_memoryCopy(pTWD->hOs,ssid,"ronit",5);
  
	JoinBss.basicRateSet = DRV_RATE_2M;
	JoinBss.radioBand = RADIO_BAND_2_4_GHZ;
	JoinBss.pBSSID = Bssid;
	
	JoinBss.bssType = BSS_INDEPENDENT;
	JoinBss.pSSID =ssid;
	JoinBss.ssidLength = 5;
	JoinBss.channel = 1;
	JoinBss.beaconInterval = 100;
	JoinBss.dtimInterval = 2;
  
	pCmdBld->hReport = pTWD->hReport;
	pCmdBld->tDb.bss.BssId[0] = 0x0;
	pCmdBld->tDb.bss.BssId[1] = 0x12;
	pCmdBld->tDb.bss.BssId[2] = 0x43;
	pCmdBld->tDb.bss.BssId[3] = 0xad;
	pCmdBld->tDb.bss.BssId[4] = 0xe5;
	pCmdBld->tDb.bss.BssId[5] = 0x10;
	pCmdBld->tDb.bss.RadioChannel = 1;
   
	txMgmtQ_SetConnState(hTxMgmtQ,TX_CONN_STATE_MGMT);
  
	res = cmdBld_CmdJoinBss  (pCmdBld, 
							  &JoinBss, 
							  NULL,//cmdBld_ConfigSeq, 
							  NULL);//pTWD->hCmdBld
  
	if (res)
	{
		os_printf("\n failed to make IBSS connection\n");
	}
  
	os_printf("\n res = %d\n", res);
   
	txMgmtQ_SetConnState(hTxMgmtQ, TX_CONN_STATE_MGMT);

}


void sendDataPacket (TI_HANDLE hOs)
{
    TI_UINT32       i;
	TTxCtrlBlk *    pPktCtrlBlk;
    TI_UINT8 *      pPktBuf;
    TEthernetHeader tEthHeader;
	char SrcBssid[6] = {0x88,0x88,0x88,0x88,0x88,0x88};
	char DesBssid[6] = {0x22,0x22,0x22,0x22,0x22,0x22};

	/* Allocate a TxCtrlBlk for the Tx packet and save timestamp, length and packet handle */
    pPktCtrlBlk = TWD_txCtrlBlk_Alloc (tmp_hTWD);
    pPktCtrlBlk->tTxDescriptor.startTime = os_timeStampMs (hOs);
    pPktCtrlBlk->tTxDescriptor.length    = (TI_UINT16)packetLength + ETHERNET_HDR_LEN;
    pPktCtrlBlk->tTxDescriptor.tid       = 0;
    pPktCtrlBlk->tTxPktParams.uPktType   = TX_PKT_TYPE_ETHER;

    /* Allocate buffer with headroom for getting the IP header in a 4-byte aligned address */
    pPktBuf = txCtrl_AllocPacketBuffer (tmp_hTxCtrl, pPktCtrlBlk, packetLength + ETHERNET_HDR_LEN + 2);

    /* Prepare Ethernet header */
    tEthHeader.type = HTOWLANS(ETHERTYPE_IP);
    MAC_COPY (tEthHeader.src, SrcBssid);
    MAC_COPY (tEthHeader.dst, DesBssid);
    os_memoryCopy (hOs, pPktBuf + 2, &tEthHeader, ETHERNET_HDR_LEN);

    /* Build BDL */
    BUILD_TX_TWO_BUF_PKT_BDL (pPktCtrlBlk, 
                              pPktBuf + 2, 
                              ETHERNET_HDR_LEN, 
                              pPktBuf + 2 + ETHERNET_HDR_LEN, 
                              packetLength)

    /* Fill data buffer with incremented numbers */
    for (i = 0; i < packetLength; i++) 
    {
        *(pPktBuf + 2 + ETHERNET_HDR_LEN + i) = i;
    }

    /* Send Ether packet to TxCtrl */
    txCtrl_XmitData (tmp_hTxCtrl, pPktCtrlBlk);
}



void sendMgmtPacket(TI_HANDLE hOs)
{
    static TI_UINT8     aMsg[2000];
    TI_UINT32           i;
    dot11MgmtSubType_e  eMsgType = DE_AUTH;
    
    for (i = 0; i < packetLength; i++) 
    {
        aMsg[i] = i;
    }

    mlmeBuilder_sendFrame(tmp_hMlme, eMsgType, aMsg, packetLength, 0);
    
    numOfPackets++;
    if ((infinitLoopFl == 0) && (numOfPackets > packetsNum))
    {      
        os_timerStop(hOs, dTimer);
        os_printf("\n *********** Last Packet was sent **********");
        os_timerDestroy(hOs, dTimer);
    }
    else
    {
        os_timerStart(hOs, dTimer, 1000); 
    }
}

void FW_DebugSendPacket(TI_HANDLE hDrvMain ,TI_HANDLE hOs, TI_HANDLE hTxMgmtQ, void *pParam)
{
    void *fSendPkt;

	if ( pParam == NULL )
	{
        os_printf("\nFW_DebugSendPacket Error: received NULL parameter\n");
		return;
	}

    /* Open Tx path for all packet types */
    txMgmtQ_SetConnState (hTxMgmtQ, TX_CONN_STATE_MGMT);
    txMgmtQ_SetConnState (hTxMgmtQ, TX_CONN_STATE_EAPOL);
    txMgmtQ_SetConnState (hTxMgmtQ, TX_CONN_STATE_OPEN);

	infinitLoopFl	= 0;
	numOfPackets 	= 1;
	packetsNum 		= 1;
	packetLength    = *(TI_UINT32*)pParam;
    os_printf("\nFW_DebugSendPacket: packetsNum = %d, packetLength = %d\n",packetsNum, packetLength);
    fSendPkt = bSendDataPkt ? sendDataPacket : sendMgmtPacket;
    dTimer = os_timerCreate(hOs, fSendPkt, hDrvMain);
    os_timerStart(hOs, dTimer, 1000);       
    
    SendFlag = TI_TRUE;   
}

void FW_DebugInfinitSendPacket(TI_HANDLE hDrvMain ,TI_HANDLE hOs)
{
	infinitLoopFl = 1;
	numOfPackets = 1;

    dTimer = os_timerCreate(hOs, sendMgmtPacket, hDrvMain); 
    os_timerStart(hOs, dTimer, 1000);        
    SendFlag = TI_TRUE;   
}

void FW_DebugStartLoopBack (TI_HANDLE hDrvMain, TI_HANDLE hTWD)
{    
	TTwd     *pTWD = (TTwd *)hTWD;
	TTestCmd     Plt;
	  
	Plt.testCmdId = TEST_CMD_LOOPBACK_START;
	os_printf("\n send loopback start command");  
	cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_TEST, (char*)&Plt, sizeof(Plt), NULL, NULL, NULL);
}


void FW_DebugStopLoopBack (TI_HANDLE hDrvMain, TI_HANDLE hTWD)
{    
	TTwd     *pTWD = (TTwd *)hTWD;
	TTestCmd     Plt;
		
	Plt.testCmdId = TEST_CMD_LOOPBACK_STOP;
	os_printf("\n send loopback stop command");
	cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_TEST, (char*)&Plt, sizeof(Plt), NULL, NULL, NULL);  
}


void FW_DebugGeneral(TI_HANDLE hTWD, void *pParam)
{
	TTwd     *pTWD = (TTwd *)hTWD;
	TI_UINT32 size = *((TI_UINT32*) pParam) + sizeof(TI_UINT32);

	cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_DEBUG, (char*)pParam, size, NULL, NULL, NULL);
}


/*
void FW_ComparePacket (char *buf)
 {
 char *ptemp;
 int i;

   if (SendFlag)
   {
       ptemp = CompBuf;
       os_printf("\n print before compare save buf");
       os_printf("\n");
       for (i=0;i<Len;i++) {
           os_printf(" 0x%02x  ",*ptemp++);
           if (i %5 == 0) { os_printf("\n");
           }

       }

       os_printf("\n print before compare recived packet");
       ptemp = buf;
       os_printf("\n");
       for (i=0;i<Len;i++) {
           os_printf(" 0x%02x  ",*ptemp++);
           if (i %5 == 0) { 
           }

       }


     if(memcmp(CompBuf,buf,Len))
       os_printf("\n LoopBack Packet failed");
      else
      os_printf("\n LoopBack Packet success");

      SendFlag = TI_FALSE;
   }

 }
*/