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.

332 lines
12 KiB

  1. /***************************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. DEBUG.C
  5. Abstract:
  6. Debug routines
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  11. KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  12. IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  13. PURPOSE.
  14. Copyright (c) 1999 Microsoft Corporation. All Rights Reserved.
  15. Revision History:
  16. 6/6/99 : created
  17. Author:
  18. Tom Green
  19. ****************************************************************************/
  20. #include "precomp.h"
  21. #if DBG
  22. // this is for translating a code into an ASCII string
  23. typedef struct Code2Ascii
  24. {
  25. NDIS_OID Oid;
  26. PCHAR OidName;
  27. } Code2Ascii;
  28. static Code2Ascii OidList[] =
  29. {
  30. OID_GEN_SUPPORTED_LIST, "OID_GEN_SUPPORTED_LIST",
  31. OID_GEN_HARDWARE_STATUS, "OID_GEN_HARDWARE_STATUS",
  32. OID_GEN_MEDIA_SUPPORTED, "OID_GEN_MEDIA_SUPPORTED",
  33. OID_GEN_MEDIA_IN_USE, "OID_GEN_MEDIA_IN_USE",
  34. OID_GEN_MAXIMUM_LOOKAHEAD, "OID_GEN_MAXIMUM_LOOKAHEAD",
  35. OID_GEN_MAXIMUM_FRAME_SIZE, "OID_GEN_MAXIMUM_FRAME_SIZE",
  36. OID_GEN_LINK_SPEED, "OID_GEN_LINK_SPEED",
  37. OID_GEN_TRANSMIT_BUFFER_SPACE, "OID_GEN_TRANSMIT_BUFFER_SPACE",
  38. OID_GEN_RECEIVE_BUFFER_SPACE, "OID_GEN_RECEIVE_BUFFER_SPACE",
  39. OID_GEN_TRANSMIT_BLOCK_SIZE, "OID_GEN_TRANSMIT_BLOCK_SIZE",
  40. OID_GEN_RECEIVE_BLOCK_SIZE, "OID_GEN_RECEIVE_BLOCK_SIZE",
  41. OID_GEN_VENDOR_ID, "OID_GEN_VENDOR_ID",
  42. OID_GEN_VENDOR_DESCRIPTION, "OID_GEN_VENDOR_DESCRIPTION",
  43. OID_GEN_CURRENT_PACKET_FILTER, "OID_GEN_CURRENT_PACKET_FILTER",
  44. OID_GEN_TRANSPORT_HEADER_OFFSET, "OID_GEN_TRANSPORT_HEADER_OFFSET",
  45. OID_GEN_CURRENT_LOOKAHEAD, "OID_GEN_CURRENT_LOOKAHEAD",
  46. OID_GEN_DRIVER_VERSION, "OID_GEN_DRIVER_VERSION",
  47. OID_GEN_VENDOR_DRIVER_VERSION, "OID_GEN_VENDOR_DRIVER_VERSION",
  48. OID_GEN_MAXIMUM_TOTAL_SIZE, "OID_GEN_MAXIMUM_TOTAL_SIZE",
  49. OID_GEN_PROTOCOL_OPTIONS, "OID_GEN_PROTOCOL_OPTIONS",
  50. OID_GEN_MAC_OPTIONS, "OID_GEN_MAC_OPTIONS",
  51. OID_GEN_MEDIA_CONNECT_STATUS, "OID_GEN_MEDIA_CONNECT_STATUS",
  52. OID_GEN_MAXIMUM_SEND_PACKETS, "OID_GEN_MAXIMUM_SEND_PACKETS",
  53. OID_GEN_SUPPORTED_GUIDS, "OID_GEN_SUPPORTED_GUIDS",
  54. OID_GEN_XMIT_OK, "OID_GEN_XMIT_OK",
  55. OID_GEN_RCV_OK, "OID_GEN_RCV_OK",
  56. OID_GEN_XMIT_ERROR, "OID_GEN_XMIT_ERROR",
  57. OID_GEN_RCV_ERROR, "OID_GEN_RCV_ERROR",
  58. OID_GEN_RCV_NO_BUFFER, "OID_GEN_RCV_NO_BUFFER",
  59. OID_GEN_RCV_CRC_ERROR, "OID_GEN_RCV_CRC_ERROR",
  60. OID_GEN_TRANSMIT_QUEUE_LENGTH, "OID_GEN_TRANSMIT_QUEUE_LENGTH",
  61. OID_802_3_PERMANENT_ADDRESS, "OID_802_3_PERMANENT_ADDRESS",
  62. OID_802_3_CURRENT_ADDRESS, "OID_802_3_CURRENT_ADDRESS",
  63. OID_802_3_MULTICAST_LIST, "OID_802_3_MULTICAST_LIST",
  64. OID_802_3_MAXIMUM_LIST_SIZE, "OID_802_3_MAXIMUM_LIST_SIZE",
  65. OID_802_3_RCV_ERROR_ALIGNMENT, "OID_802_3_RCV_ERROR_ALIGNMENT",
  66. OID_802_3_XMIT_ONE_COLLISION, "OID_802_3_XMIT_ONE_COLLISION",
  67. OID_802_3_XMIT_MORE_COLLISIONS, "OID_802_3_XMIT_MORE_COLLISIONS",
  68. OID_802_3_XMIT_DEFERRED, "OID_802_3_XMIT_DEFERRED",
  69. OID_802_3_XMIT_MAX_COLLISIONS, "OID_802_3_XMIT_MAX_COLLISIONS",
  70. OID_802_3_RCV_OVERRUN, "OID_802_3_RCV_OVERRUN",
  71. OID_802_3_XMIT_UNDERRUN, "OID_802_3_XMIT_UNDERRUN",
  72. OID_802_3_XMIT_HEARTBEAT_FAILURE, "OID_802_3_XMIT_HEARTBEAT_FAILURE",
  73. OID_802_3_XMIT_TIMES_CRS_LOST, "OID_802_3_XMIT_TIMES_CRS_LOST",
  74. OID_802_3_XMIT_LATE_COLLISIONS, "OID_802_3_XMIT_LATE_COLLISIONS",
  75. OID_802_3_MAC_OPTIONS, "OID_802_3_MAC_OPTIONS",
  76. OID_TCP_TASK_OFFLOAD, "OID_TCP_TASK_OFFLOAD",
  77. OID_PNP_CAPABILITIES, "OID_PNP_CAPABILITIES",
  78. OID_PNP_SET_POWER, "OID_PNP_SET_POWER",
  79. OID_PNP_QUERY_POWER, "OID_PNP_QUERY_POWER",
  80. OID_PNP_ADD_WAKE_UP_PATTERN, "OID_PNP_ADD_WAKE_UP_PATTERN",
  81. OID_PNP_REMOVE_WAKE_UP_PATTERN, "OID_PNP_REMOVE_WAKE_UP_PATTERN",
  82. OID_PNP_ENABLE_WAKE_UP, "OID_PNP_ENABLE_WAKE_UP"
  83. };
  84. static UINT NumOid = sizeof(OidList) / sizeof(Code2Ascii);
  85. //
  86. // Debug level
  87. //
  88. UINT RndismpDebugFlags = DBG_LEVEL0 | DBG_LEVEL1; // | DBG_LEVEL2; // | DBG_DUMP; // | DBG_OID_LIST;
  89. /****************************************************************************/
  90. /* GetOidName */
  91. /****************************************************************************/
  92. /* */
  93. /* Routine Description: */
  94. /* */
  95. /* Returns string with OID name */
  96. /* */
  97. /* Arguments: */
  98. /* */
  99. /* Oid - OID to find */
  100. /* */
  101. /* Return: */
  102. /* */
  103. /* PCHAR */
  104. /* */
  105. /****************************************************************************/
  106. PCHAR
  107. GetOidName(IN NDIS_OID Oid)
  108. {
  109. UINT Index;
  110. // see if the matching Oid and string are in the list
  111. for(Index = 0; Index < NumOid; Index++)
  112. {
  113. if(Oid == OidList[Index].Oid)
  114. {
  115. return OidList[Index].OidName;
  116. }
  117. }
  118. DbgPrint("GetOidName: unknown OID %x\n", Oid);
  119. return "Unknown OID";
  120. } // GetOidName
  121. /****************************************************************************/
  122. /* DisplayOidList */
  123. /****************************************************************************/
  124. /* */
  125. /* Routine Description: */
  126. /* */
  127. /* Prints list of supported OIDs and whether they are supported in */
  128. /* the device or driver */
  129. /* */
  130. /* Arguments: */
  131. /* */
  132. /* Adapter - adapter object */
  133. /* */
  134. /* Return: */
  135. /* */
  136. /* VOID */
  137. /* */
  138. /****************************************************************************/
  139. VOID
  140. DisplayOidList(IN PRNDISMP_ADAPTER Adapter)
  141. {
  142. ASSERT(Adapter->SupportedOIDList);
  143. ASSERT(Adapter->OIDHandlerList);
  144. if(RndismpDebugFlags & DBG_OID_LIST)
  145. {
  146. UINT Index;
  147. for(Index = 0;Index < Adapter->NumOIDSupported;Index++)
  148. {
  149. if(Adapter->OIDHandlerList[Index] == DRIVER_SUPPORTED_OID)
  150. {
  151. DbgPrint("Support (%s) OID (%s)\n", "Driver",
  152. GetOidName(Adapter->SupportedOIDList[Index]));
  153. }
  154. else if(Adapter->OIDHandlerList[Index] ==
  155. DEVICE_SUPPORTED_OID)
  156. {
  157. DbgPrint("Support (%s) OID (%s)\n", "Device",
  158. GetOidName(Adapter->SupportedOIDList[Index]));
  159. }
  160. else
  161. {
  162. DbgPrint("Support (%s) OID (%s) (%08X)\n", "Unknown",
  163. GetOidName(Adapter->SupportedOIDList[Index]),
  164. Adapter->OIDHandlerList[Index]);
  165. }
  166. }
  167. }
  168. } // DisplayOidList
  169. #define BYTES_PER_LINE 16
  170. #define CHARS_PER_BYTE 3 // e.g. " 12"
  171. ULONG MaxHexDumpLength = 0xffff;
  172. VOID
  173. RndisPrintHexDump(PVOID Pointer,
  174. ULONG Length)
  175. {
  176. CHAR DumpArray[BYTES_PER_LINE*CHARS_PER_BYTE+1];
  177. PCHAR pBuf;
  178. PUCHAR pInBuf;
  179. ULONG i;
  180. pInBuf = (PUCHAR)Pointer;
  181. pBuf = DumpArray;
  182. Length = MIN(Length, MaxHexDumpLength);
  183. for (i = 0; i < Length; i++)
  184. {
  185. //
  186. // Are we at the end of a line?
  187. //
  188. if ((i > 0) && ((i & 0xf) == 0))
  189. {
  190. *pBuf = '\0';
  191. DbgPrint("%s\n", DumpArray);
  192. pBuf = &DumpArray[0];
  193. }
  194. //
  195. // Print the address if we are at the start of a new line.
  196. //
  197. if ((i & 0xf) == 0)
  198. {
  199. DbgPrint("%08x ", pInBuf);
  200. }
  201. //
  202. // Convert the current hex byte into a sequence of two chars.
  203. //
  204. *pBuf = ' ';
  205. pBuf++;
  206. *pBuf = ((*pInBuf) >> 4);
  207. *pBuf = ((*pBuf > 9)? (*pBuf - 10 + 'a') : (*pBuf + '0'));
  208. pBuf++;
  209. *pBuf = ((*pInBuf) & 0x0F);
  210. *pBuf = ((*pBuf > 9)? (*pBuf - 10 + 'a') : (*pBuf + '0'));
  211. pBuf++;
  212. pInBuf++;
  213. }
  214. if (Length > 0)
  215. {
  216. *pBuf = '\0';
  217. DbgPrint("%s\n", DumpArray);
  218. }
  219. }
  220. #define LOG_ENTRY_SIZE 128
  221. #define LOG_BUFFER_SIZE (2 * PAGE_SIZE)
  222. VOID
  223. RndisLogSendMessage(
  224. IN PRNDISMP_ADAPTER pAdapter,
  225. IN PRNDISMP_MESSAGE_FRAME pMsgFrame)
  226. {
  227. NDIS_STATUS Status;
  228. BOOLEAN bLockAcquired;
  229. PUCHAR pMsgData;
  230. ULONG CopyLength;
  231. PUCHAR pDst;
  232. bLockAcquired = TRUE;
  233. RNDISMP_ACQUIRE_ADAPTER_LOCK(pAdapter);
  234. do
  235. {
  236. if (pAdapter->pSendLogBuffer == NULL)
  237. {
  238. pAdapter->LogBufferSize = LOG_BUFFER_SIZE;
  239. Status = MemAlloc(&pAdapter->pSendLogBuffer, LOG_BUFFER_SIZE);
  240. if (Status != NDIS_STATUS_SUCCESS)
  241. {
  242. TRACE1(("Failed to alloc log buffer (%d bytes)\n", LOG_BUFFER_SIZE));
  243. break;
  244. }
  245. pAdapter->pSendLogWrite = pAdapter->pSendLogBuffer;
  246. }
  247. pDst = pAdapter->pSendLogWrite;
  248. pAdapter->pSendLogWrite += LOG_ENTRY_SIZE;
  249. if (pAdapter->pSendLogWrite >= pAdapter->pSendLogBuffer + pAdapter->LogBufferSize)
  250. {
  251. pAdapter->pSendLogWrite = pDst = pAdapter->pSendLogBuffer;
  252. }
  253. RNDISMP_RELEASE_ADAPTER_LOCK(pAdapter);
  254. bLockAcquired = FALSE;
  255. CopyLength = MIN(LOG_ENTRY_SIZE, RNDISMP_GET_MDL_LENGTH(pMsgFrame->pMessageMdl));
  256. pMsgData = RNDISMP_GET_MDL_ADDRESS(pMsgFrame->pMessageMdl);
  257. RtlFillMemory(pDst, LOG_ENTRY_SIZE, 0);
  258. RNDISMP_MOVE_MEM(pDst, pMsgData, CopyLength);
  259. }
  260. while (FALSE);
  261. if (bLockAcquired)
  262. {
  263. RNDISMP_RELEASE_ADAPTER_LOCK(pAdapter);
  264. }
  265. }
  266. #endif