1 /* 2 * fwdriverdebug.c 3 * 4 * Copyright(c) 1998 - 2009 Texas Instruments. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name Texas Instruments nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 35 /***************************************************************************/ 36 /* */ 37 /* MODULE: FW_debug.c */ 38 /* PURPOSE: FW debug implementation */ 39 /* */ 40 /***************************************************************************/ 41 #include "tidef.h" 42 #include "DrvMain.h" 43 #include "CmdQueue_api.h" 44 #include "debug.h" 45 #include "connDebug.h" 46 #include "siteMgrDebug.h" 47 #include "dataCtrlDbg.h" 48 #include "rsnDbg.h" 49 #include "osApi.h" 50 #include "report.h" 51 #include "qosMngrDbg.h" 52 #include "PowerMgrDebug.h" 53 #include "roamingMgrDebug.h" 54 #include "scanCncnDbg.h" 55 #include "ScanMngrDbg.h" 56 #include "scrDbg.h" 57 #include "SoftGeminiDbg.h" 58 #include "HealthMonitorDbg.h" 59 #include "smeDebug.h" 60 #include "TWDriver.h" 61 #include "CmdBld.h" 62 #include "commonTypes.h" 63 #include "siteHash.h" 64 #include "txCtrl.h" 65 #include "802_11Defs.h" 66 #include "fwdriverdebug.h" 67 #include "mlmeBuilder.h" 68 #include "Ethernet.h" 69 70 static TI_HANDLE dTimer; 71 static TI_HANDLE tmp_hMlme; 72 static TI_HANDLE tmp_hTWD; 73 static TI_HANDLE tmp_hTxCtrl; 74 static TI_BOOL SendFlag = 0; 75 static TI_BOOL bSendDataPkt; 76 static volatile TI_UINT32 numOfPackets; 77 static volatile TI_UINT8 infinitLoopFl = 0; 78 static TI_UINT32 packetsNum; 79 static TI_UINT32 packetLength; 80 81 typedef TI_STATUS (*TCmdCfgFuncB) (TI_HANDLE); 82 83 extern TI_STATUS cmdBld_CmdJoinBss (TI_HANDLE hCmdBld, TJoinBss *pJoinBssParams, void *fCb, TI_HANDLE hCb); 84 void sendMgmtPacket (TI_HANDLE hOs); 85 void sendDataPacket (TI_HANDLE hOs); 86 87 void FWDebugFunction(TI_HANDLE hDrvMain, 88 TI_HANDLE hOs, 89 TI_HANDLE hTWD, 90 TI_HANDLE hMlme, 91 TI_HANDLE hTxMgmtQ, 92 TI_HANDLE hTxCtrl, 93 unsigned long funcType, 94 void *pParam) 95 { 96 tmp_hMlme = hMlme; 97 tmp_hTWD = hTWD; 98 tmp_hTxCtrl = hTxCtrl; 99 100 switch (funcType) 101 { 102 case DBG_FW_PRINT_HELP: 103 printFWDbgFunctions(); 104 break; 105 case DBG_FW_SEND_GENERAL_TEST_CMD: 106 FW_debugSendGeneralTestCmd(hTWD, pParam); 107 break; 108 case DBG_FW_IBSS_CONNECTION: 109 FW_DebugSendJoinCommand(hTWD, hTxMgmtQ); 110 break; 111 case DBG_FW_SEND_MGMT_PACKET: 112 bSendDataPkt = TI_FALSE; 113 FW_DebugSendPacket(hDrvMain, hOs, hTxMgmtQ, pParam); 114 break; 115 case DBG_FW_SEND_DATA_PACKET: 116 bSendDataPkt = TI_TRUE; 117 FW_DebugSendPacket(hDrvMain, hOs, hTxMgmtQ, pParam); 118 break; 119 case DBG_FW_START_LOOPBACK: 120 FW_DebugStartLoopBack (hDrvMain, hTWD); 121 break; 122 case DBG_FW_STOP_LOOPBACK: 123 FW_DebugStopLoopBack (hDrvMain, hTWD); 124 break; 125 case DBG_FW_INFINIT_SEND: 126 FW_DebugInfinitSendPacket (hDrvMain, hTWD); 127 break; 128 129 case DBG_FW_GENERAL: 130 FW_DebugGeneral (hTWD, pParam); 131 break; 132 default: 133 break; 134 135 136 } 137 } 138 139 void printFWDbgFunctions(void) 140 { 141 WLAN_OS_REPORT((" FW Debug Functions \n")); 142 WLAN_OS_REPORT(("---------------------------------------------------\n")); 143 WLAN_OS_REPORT(("2200 - Print the FW Debug Help \n")); 144 WLAN_OS_REPORT(("2201 - Send General Test Command \n")); 145 WLAN_OS_REPORT(("2202 - create IBSS connection \n")); 146 WLAN_OS_REPORT(("2203[n] - Send n<=999 Packets \n")); 147 WLAN_OS_REPORT(("2205 - Start LoopBack \n")); 148 WLAN_OS_REPORT(("2206 - Stop LoopBack \n")); 149 } 150 151 152 void FW_debugSendGeneralTestCmd(TI_HANDLE hTWD, void *pParam) 153 { 154 TTwd *pTWD = (TTwd *)hTWD; 155 FWDebugTestCmdParamter_t Cfg; 156 unsigned char Len; 157 Len = *(unsigned char *)pParam; 158 159 os_memoryCopy(pTWD->hOs, Cfg.buf,(unsigned long*)pParam + sizeof(TI_UINT8),Len * 4 ); 160 161 Cfg.len = Len; 162 163 /* Set information element header */ 164 Cfg.EleHdr.id = CMD_TEST; 165 Cfg.EleHdr.len = sizeof(Cfg) - sizeof(EleHdrStruct); 166 167 cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_CONFIGURE, (void*)&Cfg, sizeof(Cfg), NULL, NULL, NULL); 168 } 169 170 void FW_DebugSendJoinCommand(TI_HANDLE hTWD, TI_HANDLE hTxMgmtQ) 171 { 172 TTwd *pTWD = (TTwd *)hTWD; 173 TCmdBld *pCmdBld = (TCmdBld *)(pTWD->hCmdBld); 174 TI_STATUS res; 175 TJoinBss JoinBss; 176 char ssid[10]; 177 unsigned char Bssid[6] = {0x0,0x12,0x43,0xad,0xe5,0x10}; 178 179 os_memoryCopy(pTWD->hOs,ssid,"ronit",5); 180 181 JoinBss.basicRateSet = DRV_RATE_2M; 182 JoinBss.radioBand = RADIO_BAND_2_4_GHZ; 183 JoinBss.pBSSID = Bssid; 184 185 JoinBss.bssType = BSS_INDEPENDENT; 186 JoinBss.pSSID =ssid; 187 JoinBss.ssidLength = 5; 188 JoinBss.channel = 1; 189 JoinBss.beaconInterval = 100; 190 JoinBss.dtimInterval = 2; 191 192 pCmdBld->hReport = pTWD->hReport; 193 pCmdBld->tDb.bss.BssId[0] = 0x0; 194 pCmdBld->tDb.bss.BssId[1] = 0x12; 195 pCmdBld->tDb.bss.BssId[2] = 0x43; 196 pCmdBld->tDb.bss.BssId[3] = 0xad; 197 pCmdBld->tDb.bss.BssId[4] = 0xe5; 198 pCmdBld->tDb.bss.BssId[5] = 0x10; 199 pCmdBld->tDb.bss.RadioChannel = 1; 200 201 txMgmtQ_SetConnState(hTxMgmtQ,TX_CONN_STATE_MGMT); 202 203 res = cmdBld_CmdJoinBss (pCmdBld, 204 &JoinBss, 205 NULL,//cmdBld_ConfigSeq, 206 NULL);//pTWD->hCmdBld 207 208 if (res) 209 { 210 os_printf("\n failed to make IBSS connection\n"); 211 } 212 213 os_printf("\n res = %d\n", res); 214 215 txMgmtQ_SetConnState(hTxMgmtQ, TX_CONN_STATE_MGMT); 216 217 } 218 219 220 void sendDataPacket (TI_HANDLE hOs) 221 { 222 TI_UINT32 i; 223 TTxCtrlBlk * pPktCtrlBlk; 224 TI_UINT8 * pPktBuf; 225 TEthernetHeader tEthHeader; 226 char SrcBssid[6] = {0x88,0x88,0x88,0x88,0x88,0x88}; 227 char DesBssid[6] = {0x22,0x22,0x22,0x22,0x22,0x22}; 228 229 /* Allocate a TxCtrlBlk for the Tx packet and save timestamp, length and packet handle */ 230 pPktCtrlBlk = TWD_txCtrlBlk_Alloc (tmp_hTWD); 231 pPktCtrlBlk->tTxDescriptor.startTime = os_timeStampMs (hOs); 232 pPktCtrlBlk->tTxDescriptor.length = (TI_UINT16)packetLength + ETHERNET_HDR_LEN; 233 pPktCtrlBlk->tTxDescriptor.tid = 0; 234 pPktCtrlBlk->tTxPktParams.uPktType = TX_PKT_TYPE_ETHER; 235 236 /* Allocate buffer with headroom for getting the IP header in a 4-byte aligned address */ 237 pPktBuf = txCtrl_AllocPacketBuffer (tmp_hTxCtrl, pPktCtrlBlk, packetLength + ETHERNET_HDR_LEN + 2); 238 239 /* Prepare Ethernet header */ 240 tEthHeader.type = HTOWLANS(ETHERTYPE_IP); 241 MAC_COPY (tEthHeader.src, SrcBssid); 242 MAC_COPY (tEthHeader.dst, DesBssid); 243 os_memoryCopy (hOs, pPktBuf + 2, &tEthHeader, ETHERNET_HDR_LEN); 244 245 /* Build BDL */ 246 BUILD_TX_TWO_BUF_PKT_BDL (pPktCtrlBlk, 247 pPktBuf + 2, 248 ETHERNET_HDR_LEN, 249 pPktBuf + 2 + ETHERNET_HDR_LEN, 250 packetLength) 251 252 /* Fill data buffer with incremented numbers */ 253 for (i = 0; i < packetLength; i++) 254 { 255 *(pPktBuf + 2 + ETHERNET_HDR_LEN + i) = i; 256 } 257 258 /* Send Ether packet to TxCtrl */ 259 txCtrl_XmitData (tmp_hTxCtrl, pPktCtrlBlk); 260 } 261 262 263 264 void sendMgmtPacket(TI_HANDLE hOs) 265 { 266 static TI_UINT8 aMsg[2000]; 267 TI_UINT32 i; 268 dot11MgmtSubType_e eMsgType = DE_AUTH; 269 270 for (i = 0; i < packetLength; i++) 271 { 272 aMsg[i] = i; 273 } 274 275 mlmeBuilder_sendFrame(tmp_hMlme, eMsgType, aMsg, packetLength, 0); 276 277 numOfPackets++; 278 if ((infinitLoopFl == 0) && (numOfPackets > packetsNum)) 279 { 280 os_timerStop(hOs, dTimer); 281 os_printf("\n *********** Last Packet was sent **********"); 282 os_timerDestroy(hOs, dTimer); 283 } 284 else 285 { 286 os_timerStart(hOs, dTimer, 1000); 287 } 288 } 289 290 void FW_DebugSendPacket(TI_HANDLE hDrvMain ,TI_HANDLE hOs, TI_HANDLE hTxMgmtQ, void *pParam) 291 { 292 void *fSendPkt; 293 294 if ( pParam == NULL ) 295 { 296 os_printf("\nFW_DebugSendPacket Error: received NULL parameter\n"); 297 return; 298 } 299 300 /* Open Tx path for all packet types */ 301 txMgmtQ_SetConnState (hTxMgmtQ, TX_CONN_STATE_MGMT); 302 txMgmtQ_SetConnState (hTxMgmtQ, TX_CONN_STATE_EAPOL); 303 txMgmtQ_SetConnState (hTxMgmtQ, TX_CONN_STATE_OPEN); 304 305 infinitLoopFl = 0; 306 numOfPackets = 1; 307 packetsNum = 1; 308 packetLength = *(TI_UINT32*)pParam; 309 os_printf("\nFW_DebugSendPacket: packetsNum = %d, packetLength = %d\n",packetsNum, packetLength); 310 fSendPkt = bSendDataPkt ? sendDataPacket : sendMgmtPacket; 311 dTimer = os_timerCreate(hOs, fSendPkt, hDrvMain); 312 os_timerStart(hOs, dTimer, 1000); 313 314 SendFlag = TI_TRUE; 315 } 316 317 void FW_DebugInfinitSendPacket(TI_HANDLE hDrvMain ,TI_HANDLE hOs) 318 { 319 infinitLoopFl = 1; 320 numOfPackets = 1; 321 322 dTimer = os_timerCreate(hOs, sendMgmtPacket, hDrvMain); 323 os_timerStart(hOs, dTimer, 1000); 324 SendFlag = TI_TRUE; 325 } 326 327 void FW_DebugStartLoopBack (TI_HANDLE hDrvMain, TI_HANDLE hTWD) 328 { 329 TTwd *pTWD = (TTwd *)hTWD; 330 TTestCmd Plt; 331 332 Plt.testCmdId = TEST_CMD_LOOPBACK_START; 333 os_printf("\n send loopback start command"); 334 cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_TEST, (char*)&Plt, sizeof(Plt), NULL, NULL, NULL); 335 } 336 337 338 void FW_DebugStopLoopBack (TI_HANDLE hDrvMain, TI_HANDLE hTWD) 339 { 340 TTwd *pTWD = (TTwd *)hTWD; 341 TTestCmd Plt; 342 343 Plt.testCmdId = TEST_CMD_LOOPBACK_STOP; 344 os_printf("\n send loopback stop command"); 345 cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_TEST, (char*)&Plt, sizeof(Plt), NULL, NULL, NULL); 346 } 347 348 349 void FW_DebugGeneral(TI_HANDLE hTWD, void *pParam) 350 { 351 TTwd *pTWD = (TTwd *)hTWD; 352 TI_UINT32 size = *((TI_UINT32*) pParam) + sizeof(TI_UINT32); 353 354 cmdQueue_SendCommand (pTWD->hCmdQueue, CMD_DEBUG, (char*)pParam, size, NULL, NULL, NULL); 355 } 356 357 358 /* 359 void FW_ComparePacket (char *buf) 360 { 361 char *ptemp; 362 int i; 363 364 if (SendFlag) 365 { 366 ptemp = CompBuf; 367 os_printf("\n print before compare save buf"); 368 os_printf("\n"); 369 for (i=0;i<Len;i++) { 370 os_printf(" 0x%02x ",*ptemp++); 371 if (i %5 == 0) { os_printf("\n"); 372 } 373 374 } 375 376 os_printf("\n print before compare recived packet"); 377 ptemp = buf; 378 os_printf("\n"); 379 for (i=0;i<Len;i++) { 380 os_printf(" 0x%02x ",*ptemp++); 381 if (i %5 == 0) { 382 } 383 384 } 385 386 387 if(memcmp(CompBuf,buf,Len)) 388 os_printf("\n LoopBack Packet failed"); 389 else 390 os_printf("\n LoopBack Packet success"); 391 392 SendFlag = TI_FALSE; 393 } 394 395 } 396 */ 397 398 399