1 /**************************************************************************** 2 **+-----------------------------------------------------------------------+** 3 **| |** 4 **| Copyright(c) 1998 - 2008 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 #ifdef TI_DBG 37 38 #include "FwEvent_api.h" 39 #include "whalParams.h" 40 #include "DebugTraceXfer_api.h" 41 #include "report.h" 42 #include "whalBus_Defs.h" 43 #include "TNETWIF.h" 44 #include "utils.h" 45 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB) 46 #include "memMngrEx.h" 47 #endif 48 #include "whalCommon.h" 49 50 51 52 /***************************************************************************** 53 ** UDP Packet Build ** 54 *****************************************************************************/ 55 #define Ether_Type 0x0800 /* For IP Protocol */ 56 57 /* This is an Ethernet Version 2 frame: 14 Byte */ 58 typedef struct { 59 UINT8 ether_dst[6]; 60 UINT8 ether_src[6]; 61 UINT16 ether_Type; 62 } etherHeader; 63 64 65 #define IP_Version 0x45 /* IP Ver - 4 Length Of IP Header 5 UINT32 (20 Byte) */ 66 #define IP_TimeToLive 128 /* limit the number of Router Hops */ 67 #define IP_Protocol 0x11 /* UDP protocol */ 68 69 /* This is an IP frame: 20 Byte */ 70 typedef struct 71 { 72 UINT8 IpVer; 73 UINT8 TypeOfService; 74 UINT16 Totallen; 75 UINT16 Indentification; 76 UINT16 FragOffset; 77 UINT8 TimeToLive; 78 UINT8 protocol; 79 UINT16 csum; 80 UINT8 src[4]; 81 UINT8 dst[4]; 82 } ipstruct; 83 84 #define Source_Port 0 85 #define Destination_Port 5555 86 87 /* This is a UDP frame: 8 Byte */ 88 typedef struct { 89 UINT16 src_port; 90 UINT16 dst_port; 91 UINT16 UDP_len; 92 UINT16 UDP_Csum; 93 } UDPStruct; 94 95 /* This is a Trace Frame:*/ 96 #pragma pack(1) 97 typedef struct { 98 etherHeader Ether_Header; 99 ipstruct IP_Header; 100 UDPStruct UDP_Header; 101 } TraceFrame; 102 #pragma pack() 103 104 /***************************************************************************** 105 ** Structures ** 106 *****************************************************************************/ 107 typedef enum 108 { 109 DEBUG_TRACE_STATE_IDLE, 110 DEBUG_TRACE_STATE_READ_BUF, 111 DEBUG_TRACE_STATE_ACK_EVENT 112 } debugTraceState_e; 113 /* 114 * DebugTraceXfer: The Debug Trace Object 115 */ 116 typedef struct 117 { 118 TraceFrame FrameHeader; /* Do Not Change Place */ 119 120 /* use a struct to read buffers from the bus - used for extra bytes reserving */ 121 PADDING (UINT32 debugWords[TRACE_BUFFER_MAX_SIZE * 2]) /* *2 for the 2 buffers */ 122 123 BOOL bDoPrint; 124 BOOL bUdpSend; 125 BOOL bSync; /* indicate if we are in Synch bus or not */ 126 127 UINT32 TraceBufferSize; 128 129 UINT32 BufferOffset[2]; /* holds the offset of Buffer A and Buffer B */ 130 UINT8 currBuffer; /* switch between 0 and 1 according to the buffer used */ 131 132 debugTraceState_e state; 133 TI_STATUS returnValue; 134 135 TI_HANDLE hOs; 136 TI_HANDLE hReport; 137 TI_HANDLE hFwEvent; 138 TI_HANDLE hMemMgr; 139 TI_HANDLE hTNETWIF; 140 } DebugTrace_t; 141 142 /**************************************************************************** 143 * static function declaration 144 ****************************************************************************/ 145 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB) 146 static void debugTrace_BuildFrame(DebugTrace_t *pDebugTrace, UINT8* MacAddress); 147 #endif 148 static void debugTrace_StateMachine(TI_HANDLE hDebugTrace,UINT8 module_id ,TI_STATUS status); 149 150 /**************************************************************************** 151 * debugTrace_Create() 152 ***************************************************************************** 153 * DESCRIPTION: Create 154 * 155 * INPUTS: 156 * 157 * RETURNS: 158 * 159 *****************************************************************************/ 160 TI_HANDLE debugTrace_Create(TI_HANDLE hOs) 161 { 162 DebugTrace_t *pDebugTrace; 163 164 pDebugTrace = os_memoryAlloc(hOs, sizeof(DebugTrace_t)); 165 if (pDebugTrace == NULL) 166 { 167 WLAN_OS_REPORT(("debugTrace_Create: Error Creating Trace Buffer \n")); 168 return NULL; 169 } 170 171 os_memoryZero(hOs, pDebugTrace, sizeof(DebugTrace_t)); 172 173 pDebugTrace->hOs = hOs; 174 175 return((TI_HANDLE)pDebugTrace); 176 } 177 178 /**************************************************************************** 179 * debugTrace_Destroy() 180 ***************************************************************************** 181 * DESCRIPTION: Destroy 182 * 183 * INPUTS: 184 * 185 * RETURNS: 186 * 187 *****************************************************************************/ 188 void debugTrace_Destroy(TI_HANDLE hDebugTrace) 189 { 190 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 191 192 if (pDebugTrace) 193 { 194 os_memoryFree(pDebugTrace->hOs, pDebugTrace, sizeof(DebugTrace_t)); 195 } 196 } 197 198 /**************************************************************************** 199 * debugTrace_Config() 200 ***************************************************************************** 201 * DESCRIPTION: Config 202 * 203 * INPUTS: 204 * 205 * RETURNS: 206 * 207 *****************************************************************************/ 208 void debugTrace_Config(TI_HANDLE hDebugTrace, TI_HANDLE hWhalParams, TI_HANDLE hReport, 209 TI_HANDLE hMemMgr, TI_HANDLE hTNETWIF, TI_HANDLE hFwEvent) 210 { 211 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 212 213 pDebugTrace->hReport = hReport; 214 pDebugTrace->hMemMgr = hMemMgr; 215 pDebugTrace->hTNETWIF = hTNETWIF; 216 pDebugTrace->hFwEvent = hFwEvent; 217 218 /* next 2 parameters are TRUE & FALSE by default but can be changed in run time */ 219 pDebugTrace->bUdpSend = FALSE; 220 pDebugTrace->bDoPrint = TRUE; 221 pDebugTrace->TraceBufferSize = whal_ParamsGetTraceBufferSize(hWhalParams); 222 pDebugTrace->currBuffer = 0; 223 224 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB) 225 /* Build Frame to be send to the OS */ 226 debugTrace_BuildFrame(pDebugTrace, whal_ParamsGetSrcMac(hWhalParams)); 227 #endif 228 229 /* Enable Trace Interrupts - actual interrupts will be raised only after init phase */ 230 FwEvent_Enable(pDebugTrace->hFwEvent, ACX_INTR_TRACE_A); 231 FwEvent_Enable(pDebugTrace->hFwEvent, ACX_INTR_TRACE_B); 232 } 233 234 /**************************************************************************** 235 * debugTrace_ConfigHw() 236 ***************************************************************************** 237 * DESCRIPTION: Initialize the address to read the buffer from the FW 238 * 239 * INPUTS: hDebugTrace - Debug Trace object 240 * 241 * RETURNS: 242 * 243 *****************************************************************************/ 244 void debugTrace_ConfigHw(TI_HANDLE hDebugTrace,UINT32 TraceAddA, UINT32 TraceAddB) 245 { 246 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 247 248 pDebugTrace->BufferOffset[0] = TraceAddA; 249 pDebugTrace->BufferOffset[1] = TraceAddB; 250 251 WLAN_REPORT_INIT(pDebugTrace->hReport, HAL_HW_CTRL_MODULE_LOG, 252 ("debugTrace_ConfigHw: Buffer A offSet =0x%x, Buffer B offSet =0x%x, TraceBufferSize = %d \n" 253 ,pDebugTrace->BufferOffset[0], pDebugTrace->BufferOffset[1],pDebugTrace->TraceBufferSize)); 254 255 } 256 257 /**************************************************************************** 258 * debugTrace_Event() 259 ***************************************************************************** 260 * DESCRIPTION: Called upon an interrupt of debug trace kind. 261 * 262 * INPUTS: hDebugTrace - Debug Trace object 263 * 264 * RETURNS: 265 * 266 *****************************************************************************/ 267 TI_STATUS debugTrace_Event(TI_HANDLE hDebugTrace) 268 { 269 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 270 271 WLAN_REPORT_INFORMATION(pDebugTrace->hReport, HAL_HW_CTRL_MODULE_LOG, 272 (" debugTrace_Event: Reading from Buffer %d \n",pDebugTrace->currBuffer)); 273 274 /* assume that we are in synch bus until otherwise is proven */ 275 pDebugTrace->bSync = TRUE; 276 277 debugTrace_StateMachine(pDebugTrace,0,(TI_STATUS)0); 278 279 return pDebugTrace->returnValue; 280 } 281 282 283 /**************************************************************************** 284 * debugTrace_StateMachine() 285 **************************************************************************** 286 * DESCRIPTION: Manage the Debug trace state machine 287 * 288 * The SM is running one event at a time (buffer A or B) . 289 * The order of the states is always the same: IDLE --> READ_BUF --> ACK_EVENT 290 * The difference is whether we are using Synch or Asynch API. 291 * In the Synch case (SDIO) we are looping in the while-loop till we return to IDLE, and we return 292 * to FwEvent module a TNETWIF_OK status. 293 * In the Asynch case we use the SM CB to return to the SM after each Asynch call 294 * (In that case the return status is TNETWIF_PENDING, and we are waiting for the CB). 295 * In the Asynch case the FwEvent module gets TNETWIF_PENDING in return, and waits for 296 * the FwEvent_EventComplete() call in order to move the FwEvent SM. 297 * 298 * INPUTS: hFwEvent - The object 299 * module_id - not used (for CB API only) 300 * status - not used (for CB API only) 301 * 302 * OUTPUT: None 303 * 304 * RETURNS: TNETWIF_PENDING in case of Async and TNETWIF_OK on Sync 305 ****************************************************************************/ 306 static void debugTrace_StateMachine(TI_HANDLE hDebugTrace,UINT8 module_id ,TI_STATUS status) 307 { 308 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 309 310 pDebugTrace->returnValue = OK; 311 312 while(pDebugTrace->returnValue != TNETWIF_PENDING) 313 { 314 switch(pDebugTrace->state) 315 { 316 case DEBUG_TRACE_STATE_IDLE: 317 318 pDebugTrace->returnValue = TNETWIF_ReadMemOpt (pDebugTrace->hTNETWIF, 319 pDebugTrace->BufferOffset[pDebugTrace->currBuffer], 320 PADREAD (pDebugTrace->debugWords), 321 pDebugTrace->TraceBufferSize, 322 FW_EVENT_MODULE_ID, 323 debugTrace_StateMachine, 324 pDebugTrace); 325 326 pDebugTrace->state = DEBUG_TRACE_STATE_READ_BUF; 327 328 break; 329 330 case DEBUG_TRACE_STATE_READ_BUF: 331 /* Now, handle the buffer */ 332 /* Print on every Trace */ 333 if(pDebugTrace->bDoPrint) 334 { 335 debugTrace_Print(pDebugTrace); 336 } 337 338 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB) 339 /* Handle The Trace */ 340 if(pDebugTrace->bUdpSend) 341 { 342 debugTrace_handleBuffer(hDebugTrace); 343 } 344 #endif 345 346 /*Trigger the FW when finishing handle the event */ 347 pDebugTrace->returnValue = TNETWIF_WriteRegOpt(pDebugTrace->hTNETWIF, ACX_REG_INTERRUPT_TRIG, INTR_TRIG_DEBUG_ACK, 348 FW_EVENT_MODULE_ID,debugTrace_StateMachine,pDebugTrace); 349 350 pDebugTrace->state = DEBUG_TRACE_STATE_ACK_EVENT; 351 352 break; 353 354 case DEBUG_TRACE_STATE_ACK_EVENT: 355 356 /* Handling of the event is done. Now switch to the next buffer for the next time */ 357 pDebugTrace->currBuffer = (++pDebugTrace->currBuffer) & 0x1; /* &0x1 is %2 */ 358 359 if (FALSE == pDebugTrace->bSync ) 360 { 361 /* Async bus - call FwEvent for notifying the completion */ 362 FwEvent_EventComplete(pDebugTrace->hFwEvent, TNETWIF_OK); 363 } 364 else /* This is the Sync case and we return TNETWIF_OK */ 365 { 366 pDebugTrace->returnValue = TNETWIF_OK; 367 } 368 /* Exit SM */ 369 pDebugTrace->state = DEBUG_TRACE_STATE_IDLE; 370 return; 371 372 /* break; */ 373 374 default: 375 WLAN_REPORT_ERROR(pDebugTrace->hReport, HAL_HW_CTRL_MODULE_LOG, 376 ("debugTrace_StateMachine: unKnown state !!!\n")); 377 378 break; 379 } 380 } 381 /* if we are here - we got TNETWIF_PENDING, so we are in Async mode */ 382 pDebugTrace->bSync = FALSE; 383 384 if (pDebugTrace->returnValue == TNETWIF_ERROR) 385 { 386 WLAN_REPORT_ERROR(pDebugTrace->hReport, HAL_HW_CTRL_MODULE_LOG, 387 ("debugTrace_StateMachine: rc = TNETWIF_ERROR in state %d \n",pDebugTrace->state)); 388 } 389 } 390 391 /**************************************************************************** 392 * debugTrace_Disable() 393 ***************************************************************************** 394 * DESCRIPTION: disable receiving interrupts of this kind (debug trace) 395 * 396 * INPUTS: hDebugTrace - Debug Trace object 397 * 398 * RETURNS: 399 * 400 *****************************************************************************/ 401 void debugTrace_Disable(TI_HANDLE hDebugTrace) 402 { 403 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 404 405 FwEvent_Disable(pDebugTrace->hFwEvent, ACX_INTR_TRACE_A); 406 FwEvent_Disable(pDebugTrace->hFwEvent, ACX_INTR_TRACE_B); 407 408 WLAN_REPORT_INFORMATION(pDebugTrace->hReport, HAL_HW_CTRL_MODULE_LOG, 409 ("whal_DebugTrace_t_Disable: Trace Disable \n")); 410 411 } 412 413 /**************************************************************************** 414 * debugTrace_Enable() 415 ***************************************************************************** 416 * DESCRIPTION: Enables receiving interrupts of this kind (debug trace) 417 * 418 * INPUTS: hDebugTrace - Debug Trace object 419 * 420 * RETURNS: 421 * 422 *****************************************************************************/ 423 void debugTrace_Enable(TI_HANDLE hDebugTrace) 424 { 425 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 426 427 FwEvent_Enable(pDebugTrace->hFwEvent, ACX_INTR_TRACE_A); 428 FwEvent_Enable(pDebugTrace->hFwEvent, ACX_INTR_TRACE_B); 429 430 WLAN_REPORT_INFORMATION(pDebugTrace->hReport, HAL_CTRL_MODULE_LOG, 431 ("whal_DebugTrace_tEnable: Trace Enable \n")); 432 } 433 434 /**************************************************************************** 435 * debugTrace_Print() 436 ***************************************************************************** 437 * DESCRIPTION: Print the current buffer 438 * 439 * INPUTS: hDebugTrace - Debug Trace object 440 * 441 * RETURNS: 442 * 443 *****************************************************************************/ 444 void debugTrace_Print(TI_HANDLE hDebugTrace) 445 { 446 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 447 448 UINT32 index; 449 450 WLAN_OS_REPORT(("Trace buffer size = %d\n",pDebugTrace->TraceBufferSize)); 451 452 for(index = 0; index < pDebugTrace->TraceBufferSize / 4 ; index+=2) 453 { 454 WLAN_OS_REPORT(("0x%08X 0x%08X\n", 455 pDebugTrace->debugWords[index], 456 pDebugTrace->debugWords[index+1])); 457 } 458 } 459 460 /**************************************************************************** 461 * debugTrace_EnablePrint() 462 ***************************************************************************** 463 * DESCRIPTION: enable printing on each interrupt 464 * 465 * INPUTS: hDebugTrace - Debug Trace object 466 * 467 * RETURNS: 468 * 469 *****************************************************************************/ 470 void debugTrace_EnablePrint(TI_HANDLE hDebugTrace) 471 { 472 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 473 474 pDebugTrace->bDoPrint = TRUE; 475 476 WLAN_OS_REPORT(("whal_DebugTrace_t_EnablePrint: Print Enabled \n")); 477 478 } 479 480 /**************************************************************************** 481 * debugTrace_DisablePrint() 482 ***************************************************************************** 483 * DESCRIPTION: disable printing on each interrupt 484 * 485 * INPUTS: hDebugTrace - Debug Trace object 486 * 487 * RETURNS: 488 * 489 *****************************************************************************/ 490 void debugTrace_DisablePrint(TI_HANDLE hDebugTrace) 491 { 492 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 493 494 pDebugTrace->bDoPrint = FALSE; 495 496 WLAN_OS_REPORT(("whal_DebugTrace_t_DisablePrint: Print Disabled \n")); 497 498 } 499 500 /**************************************************************************** 501 * debugTrace_UdpEnable() 502 ***************************************************************************** 503 * DESCRIPTION: enable sending udp on each interrupt 504 * 505 * INPUTS: hDebugTrace - Debug Trace object 506 * 507 * RETURNS: 508 * 509 *****************************************************************************/ 510 void debugTrace_UdpEnable(TI_HANDLE hDebugTrace) 511 { 512 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 513 514 pDebugTrace->bUdpSend = TRUE; 515 516 WLAN_OS_REPORT(("whal_DebugTrace_t_UdpEnable: Enable UDP trace send\n")); 517 } 518 519 /**************************************************************************** 520 * debugTrace_UdpDisable() 521 ***************************************************************************** 522 * DESCRIPTION: disable sending udp on each interrupt 523 * 524 * INPUTS: hDebugTrace - Debug Trace object 525 * 526 * RETURNS: 527 * 528 *****************************************************************************/ 529 void debugTrace_UdpDisable(TI_HANDLE hDebugTrace) 530 { 531 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 532 533 pDebugTrace->bUdpSend = FALSE; 534 535 WLAN_OS_REPORT(("whal_DebugTrace_t_UdpEnable: Disable UDP trace send\n")); 536 537 } 538 539 #if !defined(GWSI_DRIVER) && !defined(GWSI_LIB) 540 /**************************************************************************** 541 * debugTrace_handleBuffer() 542 ***************************************************************************** 543 * DESCRIPTION: 544 * 545 * INPUTS: hDebugTrace - Debug Trace object 546 * 547 * RETURNS: 548 * 549 *****************************************************************************/ 550 void debugTrace_handleBuffer(TI_HANDLE hDebugTrace) 551 { 552 DebugTrace_t *pDebugTrace = (DebugTrace_t *)hDebugTrace; 553 mem_MSDU_T *pMsdu; 554 mem_BD_T *pBd; 555 UINT8 *srcDataPtr; 556 int Stt; 557 int AcxMpduLen; 558 559 /* The Msdu Len should be The IP total Length + the Ethernet header length */ 560 AcxMpduLen = wlan_ntohs(pDebugTrace->FrameHeader.IP_Header.Totallen) 561 + sizeof(pDebugTrace->FrameHeader.Ether_Header); 562 563 /* 564 * allocate host msdu 565 */ 566 Stt = wlan_memMngrAllocMSDU(pDebugTrace->hMemMgr, &pMsdu, AcxMpduLen, TRACE_BUFFER_MODULE); 567 if (Stt != OK) 568 { 569 WLAN_REPORT_ERROR(pDebugTrace->hReport, HAL_HW_DATA_MODULE_LOG, 570 ("whal_DebugTrace_t_handleBuffer: wlan_memMngrAllocMSDU error\n")); 571 return ; 572 } 573 574 /* set the lastBDPtr */ 575 pBd = pMsdu->firstBDPtr; 576 while (pBd->nextBDPtr != NULL) 577 pBd = pBd->nextBDPtr; 578 579 pMsdu->lastBDPtr = pBd; 580 581 /* Get the Address of the Data filed in the Msdu */ 582 srcDataPtr = (UINT8 *)memMgr_MsduHdrAddr(pMsdu); 583 584 /* Copy the Frame Header */ 585 os_memoryCopy(pDebugTrace->hOs, srcDataPtr, &pDebugTrace->FrameHeader, sizeof(pDebugTrace->FrameHeader)); 586 587 /* Copy the Trace Data */ 588 os_memoryCopy(pDebugTrace->hOs, srcDataPtr + sizeof(pDebugTrace->FrameHeader), pDebugTrace->debugWords, pDebugTrace->TraceBufferSize); 589 590 memMgr_BufLength(pMsdu->firstBDPtr) = AcxMpduLen; 591 592 pMsdu->dataLen = AcxMpduLen; 593 594 /* send the packet to the OS */ 595 os_receivePacket(pDebugTrace->hOs, pMsdu, (UINT16)pMsdu->dataLen); 596 } 597 598 /**************************************************************************** 599 * debugTrace_BuildFrame() 600 ***************************************************************************** 601 * DESCRIPTION: Build the Trace Frame to be send to the OS 602 * 603 * INPUTS: pDebugTrace - Debug Trace object 604 * MacAddress - for the Ethernet Header 605 * RETURNS: 606 * 607 *****************************************************************************/ 608 static void debugTrace_BuildFrame(DebugTrace_t *pDebugTrace, UINT8* MacAddress) 609 { 610 TraceFrame *Frame = &pDebugTrace->FrameHeader; 611 UINT32 i; 612 UINT16 local_csum = 0; 613 UINT16 *pShortData = (UINT16 *)&Frame->IP_Header; 614 615 /* 616 * Calculate each Frame Length 617 */ 618 /* UDP length should Be !024 of Trace Buffet Size + 8 Byte of UDP header 1032) */ 619 Frame->UDP_Header.UDP_len = wlan_htons(pDebugTrace->TraceBufferSize + sizeof(Frame->UDP_Header)); 620 621 /* IP length should Be UDP length + IP header */ 622 Frame->IP_Header.Totallen = wlan_htons(wlan_htons(Frame->UDP_Header.UDP_len) + sizeof(Frame->IP_Header)); 623 624 /* 625 * initialize the Ethernet Header 626 */ 627 os_memoryCopy(pDebugTrace->hOs, (UINT8 *)Frame->Ether_Header.ether_dst, 628 MacAddress, 6); 629 630 Frame->Ether_Header.ether_Type = wlan_htons (Ether_Type); 631 632 /* 633 * initialize the IP Header 634 */ 635 Frame->IP_Header.IpVer = IP_Version; 636 637 Frame->IP_Header.TimeToLive = IP_TimeToLive; 638 639 Frame->IP_Header.protocol = IP_Protocol; 640 641 /* Set the Local host IP */ 642 Frame->IP_Header.dst[0] = Frame->IP_Header.src[0] = 127; 643 Frame->IP_Header.dst[1] = Frame->IP_Header.src[1] = 0 ; 644 Frame->IP_Header.dst[2] = Frame->IP_Header.src[2] = 0; 645 Frame->IP_Header.dst[3] = Frame->IP_Header.src[3] = 1; 646 647 /* calculate check sum on words of 16 bits */ 648 for (i=0; i<sizeof(Frame->IP_Header)/2; i++) 649 local_csum += pShortData[i]; 650 651 Frame->IP_Header.csum = 0xFFFF - local_csum; 652 653 /* 654 * initialize the UDP Header 655 */ 656 Frame->UDP_Header.src_port = wlan_htons( Source_Port ); 657 Frame->UDP_Header.dst_port = wlan_htons( Destination_Port ); 658 } 659 #endif /* !defined(GWSI_DRIVER) && !defined(GWSI_LIB) */ 660 661 #endif /* TI_DBG */ 662 663