Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

235 lines
4.4 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. pktext.c
  5. Abstract:
  6. This file contains the generic routines
  7. for debugging NBF packet structures.
  8. Author:
  9. Chaitanya Kodeboyina
  10. Environment:
  11. User Mode
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. #include "pktext.h"
  16. //
  17. // Exported Functions
  18. //
  19. DECLARE_API( pkts )
  20. /*++
  21. Routine Description:
  22. Print a list of packets given the
  23. head LIST_ENTRY.
  24. Arguments:
  25. args - Address of the list entry, &
  26. Detail of debug information
  27. Return Value:
  28. None
  29. --*/
  30. {
  31. ULONG proxyPtr;
  32. ULONG printDetail;
  33. // Get list-head address & debug print level
  34. printDetail = SUMM_INFO;
  35. if (*args)
  36. {
  37. sscanf(args, "%x %lu", &proxyPtr, &printDetail);
  38. }
  39. PrintPacketList(NULL, proxyPtr, printDetail);
  40. }
  41. DECLARE_API( pkt )
  42. /*++
  43. Routine Description:
  44. Print the NBF Packet at a location
  45. Arguments:
  46. args -
  47. Pointer to the NBF Packet
  48. Detail of debug information
  49. Return Value:
  50. None
  51. --*/
  52. {
  53. TP_PACKET Packet;
  54. ULONG printDetail;
  55. ULONG proxyPtr;
  56. // Get the detail of debug information needed
  57. printDetail = NORM_SHAL;
  58. if (*args)
  59. {
  60. sscanf(args, "%x %lu", &proxyPtr, &printDetail);
  61. }
  62. // Get the NBF Packet
  63. if (ReadPacket(&Packet, proxyPtr) != 0)
  64. return;
  65. // Print this Packet
  66. PrintPacket(&Packet, proxyPtr, printDetail);
  67. }
  68. //
  69. // Global Helper Functions
  70. //
  71. VOID
  72. PrintPacketList(PVOID ListEntryPointer, ULONG ListEntryProxy, ULONG printDetail)
  73. {
  74. TP_PACKET Packet;
  75. LIST_ENTRY PacketList;
  76. PLIST_ENTRY PacketListPtr;
  77. PLIST_ENTRY PacketListProxy;
  78. PLIST_ENTRY p, q;
  79. ULONG proxyPtr;
  80. ULONG numPkts;
  81. ULONG bytesRead;
  82. // Get list-head address & debug print level
  83. proxyPtr = ListEntryProxy;
  84. if (ListEntryPointer == NULL)
  85. {
  86. // Read the list entry of NBF packets
  87. if (!ReadMemory(proxyPtr, &PacketList, sizeof(LIST_ENTRY), &bytesRead))
  88. {
  89. dprintf("%s @ %08x: Could not read structure\n",
  90. "Packet ListEntry", proxyPtr);
  91. return;
  92. }
  93. PacketListPtr = &PacketList;
  94. }
  95. else
  96. {
  97. PacketListPtr = ListEntryPointer;
  98. }
  99. // Traverse the doubly linked list
  100. dprintf("Packets:\n");
  101. PacketListProxy = (PLIST_ENTRY)proxyPtr;
  102. numPkts = 0;
  103. p = PacketListPtr->Flink;
  104. while (p != PacketListProxy)
  105. {
  106. // Another Packet
  107. numPkts++;
  108. // Get Packet Ptr
  109. proxyPtr = (ULONG) CONTAINING_RECORD (p, TP_PACKET, Linkage);
  110. // Get NBF Packet
  111. if (ReadPacket(&Packet, proxyPtr) != 0)
  112. break;
  113. // Print the Packet
  114. PrintPacket(&Packet, proxyPtr, printDetail);
  115. // Go to the next one
  116. p = Packet.Linkage.Flink;
  117. // Free the Packet
  118. FreePacket(&Packet);
  119. }
  120. if (p == PacketListProxy)
  121. {
  122. dprintf("Number of Packets: %lu\n", numPkts);
  123. }
  124. }
  125. //
  126. // Local Helper Functions
  127. //
  128. UINT
  129. ReadPacket(PTP_PACKET pPkt, ULONG proxyPtr)
  130. {
  131. ULONG bytesRead;
  132. // Read the current NBF packet
  133. if (!ReadMemory(proxyPtr, pPkt, sizeof(TP_PACKET), &bytesRead))
  134. {
  135. dprintf("%s @ %08x: Could not read structure\n",
  136. "Packet", proxyPtr);
  137. return -1;
  138. }
  139. return 0;
  140. }
  141. UINT
  142. PrintPacket(PTP_PACKET pPkt, ULONG proxyPtr, ULONG printDetail)
  143. {
  144. // Is this a valid NBF packet ?
  145. if (pPkt->Type != NBF_PACKET_SIGNATURE)
  146. {
  147. dprintf("%s @ %08x: Could not match signature\n",
  148. "Packet", proxyPtr);
  149. return -1;
  150. }
  151. // What detail do we print at ?
  152. if (printDetail > MAX_DETAIL)
  153. printDetail = MAX_DETAIL;
  154. // Print Information at reqd detail
  155. FieldInPacket(proxyPtr, NULL, printDetail);
  156. return 0;
  157. }
  158. VOID
  159. FieldInPacket(ULONG structAddr, CHAR *fieldName, ULONG printDetail)
  160. {
  161. TP_PACKET Packet;
  162. if (ReadPacket(&Packet, structAddr) == 0)
  163. {
  164. PrintFields(&Packet, structAddr, fieldName, printDetail, &PacketInfo);
  165. }
  166. }
  167. UINT
  168. FreePacket(PTP_PACKET pPkt)
  169. {
  170. return 0;
  171. }