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.

313 lines
11 KiB

  1. /*
  2. *************************************************************************
  3. * File: DEBUG.C
  4. *
  5. * Module: USBCCGP.SYS
  6. * USB Common Class Generic Parent driver.
  7. *
  8. * Copyright (c) 1998 Microsoft Corporation
  9. *
  10. *
  11. * Author: ervinp
  12. *
  13. *************************************************************************
  14. */
  15. #include <wdm.h>
  16. #include <usbdi.h>
  17. #include <usbdlib.h>
  18. #include <usbioctl.h>
  19. #include "usbccgp.h"
  20. #include "debug.h"
  21. #if DBG
  22. BOOLEAN dbgTrapOnWarn = FALSE;
  23. BOOLEAN dbgVerbose = FALSE;
  24. BOOLEAN dbgShowIsochProgress = FALSE;
  25. VOID DbgLogIrpMajor(ULONG_PTR irpPtr, ULONG majorFunc, ULONG isForParentFdo, ULONG isComplete, ULONG status)
  26. {
  27. if (dbgVerbose){
  28. char *funcName;
  29. switch (majorFunc){
  30. #undef MAKE_CASE
  31. #define MAKE_CASE(fnc) case fnc: funcName = #fnc; break;
  32. MAKE_CASE(IRP_MJ_CREATE)
  33. MAKE_CASE(IRP_MJ_CREATE_NAMED_PIPE)
  34. MAKE_CASE(IRP_MJ_CLOSE)
  35. MAKE_CASE(IRP_MJ_READ)
  36. MAKE_CASE(IRP_MJ_WRITE)
  37. MAKE_CASE(IRP_MJ_QUERY_INFORMATION)
  38. MAKE_CASE(IRP_MJ_SET_INFORMATION)
  39. MAKE_CASE(IRP_MJ_QUERY_EA)
  40. MAKE_CASE(IRP_MJ_SET_EA)
  41. MAKE_CASE(IRP_MJ_FLUSH_BUFFERS)
  42. MAKE_CASE(IRP_MJ_QUERY_VOLUME_INFORMATION)
  43. MAKE_CASE(IRP_MJ_SET_VOLUME_INFORMATION)
  44. MAKE_CASE(IRP_MJ_DIRECTORY_CONTROL)
  45. MAKE_CASE(IRP_MJ_FILE_SYSTEM_CONTROL)
  46. MAKE_CASE(IRP_MJ_DEVICE_CONTROL)
  47. MAKE_CASE(IRP_MJ_INTERNAL_DEVICE_CONTROL)
  48. MAKE_CASE(IRP_MJ_SHUTDOWN)
  49. MAKE_CASE(IRP_MJ_LOCK_CONTROL)
  50. MAKE_CASE(IRP_MJ_CLEANUP)
  51. MAKE_CASE(IRP_MJ_CREATE_MAILSLOT)
  52. MAKE_CASE(IRP_MJ_QUERY_SECURITY)
  53. MAKE_CASE(IRP_MJ_SET_SECURITY)
  54. MAKE_CASE(IRP_MJ_POWER)
  55. MAKE_CASE(IRP_MJ_SYSTEM_CONTROL)
  56. MAKE_CASE(IRP_MJ_DEVICE_CHANGE)
  57. MAKE_CASE(IRP_MJ_QUERY_QUOTA)
  58. MAKE_CASE(IRP_MJ_SET_QUOTA)
  59. MAKE_CASE(IRP_MJ_PNP)
  60. default: funcName = "????"; break;
  61. }
  62. if (isComplete){
  63. DBGOUT(("< %s for %s status=%xh %s (irp=%ph)",
  64. funcName,
  65. isForParentFdo ? "parent" : "function",
  66. status,
  67. NT_SUCCESS(status) ? "" : "<** ERROR **>",
  68. irpPtr));
  69. }
  70. else {
  71. DBGOUT(("> %s for %s (irp=%ph)",
  72. funcName,
  73. isForParentFdo ? "parent" : "function",
  74. irpPtr));
  75. }
  76. }
  77. }
  78. VOID DbgLogPnpIrp(ULONG_PTR irpPtr, ULONG minorFunc, ULONG isForParentFdo, ULONG isComplete, ULONG status)
  79. {
  80. char *funcName;
  81. switch (minorFunc){
  82. #undef MAKE_CASE
  83. #define MAKE_CASE(fnc) case fnc: funcName = #fnc; break;
  84. MAKE_CASE(IRP_MN_START_DEVICE)
  85. MAKE_CASE(IRP_MN_QUERY_REMOVE_DEVICE)
  86. MAKE_CASE(IRP_MN_REMOVE_DEVICE)
  87. MAKE_CASE(IRP_MN_CANCEL_REMOVE_DEVICE)
  88. MAKE_CASE(IRP_MN_STOP_DEVICE)
  89. MAKE_CASE(IRP_MN_QUERY_STOP_DEVICE)
  90. MAKE_CASE(IRP_MN_CANCEL_STOP_DEVICE)
  91. MAKE_CASE(IRP_MN_QUERY_DEVICE_RELATIONS)
  92. MAKE_CASE(IRP_MN_QUERY_INTERFACE)
  93. MAKE_CASE(IRP_MN_QUERY_CAPABILITIES)
  94. MAKE_CASE(IRP_MN_QUERY_RESOURCES)
  95. MAKE_CASE(IRP_MN_QUERY_RESOURCE_REQUIREMENTS)
  96. MAKE_CASE(IRP_MN_QUERY_DEVICE_TEXT)
  97. MAKE_CASE(IRP_MN_READ_CONFIG)
  98. MAKE_CASE(IRP_MN_WRITE_CONFIG)
  99. MAKE_CASE(IRP_MN_EJECT)
  100. MAKE_CASE(IRP_MN_SET_LOCK)
  101. MAKE_CASE(IRP_MN_QUERY_ID)
  102. MAKE_CASE(IRP_MN_QUERY_PNP_DEVICE_STATE)
  103. MAKE_CASE(IRP_MN_QUERY_BUS_INFORMATION)
  104. default: funcName = "????"; break;
  105. }
  106. if (dbgVerbose){
  107. if (isComplete){
  108. DBGOUT((" < %s for %s status=%xh (irp=%ph)",
  109. funcName,
  110. isForParentFdo ? "parent" : "function",
  111. status,
  112. irpPtr));
  113. }
  114. else {
  115. DBGOUT((" > %s for %s (irp=%ph)",
  116. funcName,
  117. isForParentFdo ? "parent" : "function",
  118. irpPtr));
  119. }
  120. }
  121. }
  122. VOID DbgLogIoctl(ULONG ioControlCode, ULONG status)
  123. {
  124. if (dbgVerbose){
  125. PCHAR ioctlStr;
  126. switch (ioControlCode){
  127. #undef MAKE_CASE
  128. #define MAKE_CASE(ioctl) case ioctl: ioctlStr = #ioctl; break;
  129. MAKE_CASE(IOCTL_INTERNAL_USB_SUBMIT_URB)
  130. MAKE_CASE(IOCTL_INTERNAL_USB_RESET_PORT)
  131. MAKE_CASE(IOCTL_INTERNAL_USB_GET_ROOTHUB_PDO)
  132. MAKE_CASE(IOCTL_INTERNAL_USB_GET_PORT_STATUS)
  133. MAKE_CASE(IOCTL_INTERNAL_USB_ENABLE_PORT)
  134. MAKE_CASE(IOCTL_INTERNAL_USB_GET_HUB_COUNT)
  135. MAKE_CASE(IOCTL_INTERNAL_USB_CYCLE_PORT)
  136. MAKE_CASE(IOCTL_INTERNAL_USB_GET_HUB_NAME)
  137. MAKE_CASE(IOCTL_INTERNAL_USB_GET_BUS_INFO)
  138. MAKE_CASE(IOCTL_INTERNAL_USB_GET_CONTROLLER_NAME)
  139. default: ioctlStr = "???"; break;
  140. }
  141. DBGOUT((" IOCTL: %s (%xh) status=%xh", ioctlStr, ioControlCode, status));
  142. }
  143. }
  144. PUCHAR DbgGetUrbName(ULONG urbFunc)
  145. {
  146. PUCHAR urbName;
  147. switch (urbFunc){
  148. #undef MAKE_CASE
  149. #define MAKE_CASE(func) case func: urbName = #func; break;
  150. MAKE_CASE(URB_FUNCTION_SELECT_CONFIGURATION)
  151. MAKE_CASE(URB_FUNCTION_SELECT_INTERFACE)
  152. MAKE_CASE(URB_FUNCTION_ABORT_PIPE)
  153. MAKE_CASE(URB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL)
  154. MAKE_CASE(URB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL)
  155. MAKE_CASE(URB_FUNCTION_GET_FRAME_LENGTH)
  156. MAKE_CASE(URB_FUNCTION_SET_FRAME_LENGTH)
  157. MAKE_CASE(URB_FUNCTION_GET_CURRENT_FRAME_NUMBER)
  158. MAKE_CASE(URB_FUNCTION_CONTROL_TRANSFER)
  159. MAKE_CASE(URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER)
  160. MAKE_CASE(URB_FUNCTION_ISOCH_TRANSFER)
  161. MAKE_CASE(URB_FUNCTION_RESET_PIPE)
  162. MAKE_CASE(URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE)
  163. MAKE_CASE(URB_FUNCTION_GET_DESCRIPTOR_FROM_ENDPOINT)
  164. MAKE_CASE(URB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE)
  165. MAKE_CASE(URB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE)
  166. MAKE_CASE(URB_FUNCTION_SET_DESCRIPTOR_TO_ENDPOINT)
  167. MAKE_CASE(URB_FUNCTION_SET_DESCRIPTOR_TO_INTERFACE)
  168. MAKE_CASE(URB_FUNCTION_SET_FEATURE_TO_DEVICE)
  169. MAKE_CASE(URB_FUNCTION_SET_FEATURE_TO_INTERFACE)
  170. MAKE_CASE(URB_FUNCTION_SET_FEATURE_TO_ENDPOINT)
  171. MAKE_CASE(URB_FUNCTION_SET_FEATURE_TO_OTHER)
  172. MAKE_CASE(URB_FUNCTION_CLEAR_FEATURE_TO_DEVICE)
  173. MAKE_CASE(URB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE)
  174. MAKE_CASE(URB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT)
  175. MAKE_CASE(URB_FUNCTION_CLEAR_FEATURE_TO_OTHER)
  176. MAKE_CASE(URB_FUNCTION_GET_STATUS_FROM_DEVICE)
  177. MAKE_CASE(URB_FUNCTION_GET_STATUS_FROM_INTERFACE)
  178. MAKE_CASE(URB_FUNCTION_GET_STATUS_FROM_ENDPOINT)
  179. MAKE_CASE(URB_FUNCTION_GET_STATUS_FROM_OTHER)
  180. MAKE_CASE(URB_FUNCTION_RESERVED0)
  181. MAKE_CASE(URB_FUNCTION_VENDOR_DEVICE)
  182. MAKE_CASE(URB_FUNCTION_VENDOR_INTERFACE)
  183. MAKE_CASE(URB_FUNCTION_VENDOR_ENDPOINT)
  184. MAKE_CASE(URB_FUNCTION_VENDOR_OTHER)
  185. MAKE_CASE(URB_FUNCTION_CLASS_DEVICE)
  186. MAKE_CASE(URB_FUNCTION_CLASS_INTERFACE)
  187. MAKE_CASE(URB_FUNCTION_CLASS_ENDPOINT)
  188. MAKE_CASE(URB_FUNCTION_CLASS_OTHER)
  189. MAKE_CASE(URB_FUNCTION_RESERVED)
  190. MAKE_CASE(URB_FUNCTION_GET_CONFIGURATION)
  191. MAKE_CASE(URB_FUNCTION_GET_INTERFACE)
  192. default: urbName = NULL; break;
  193. }
  194. return urbName;
  195. }
  196. VOID DbgLogUrb(PURB urb)
  197. {
  198. if (dbgVerbose){
  199. PCHAR urbStr = DbgGetUrbName(urb->UrbHeader.Function);
  200. if (urbStr){
  201. DBGOUT((" URB: %s (%ph)", urbStr, urb));
  202. }
  203. else {
  204. DBGOUT((" URB: func=%xh (%ph)", (ULONG)urb->UrbHeader.Function, urb));
  205. }
  206. }
  207. }
  208. VOID DbgDumpBytes(PUCHAR msg, PVOID bufPtr, ULONG len)
  209. {
  210. PUCHAR buf = bufPtr;
  211. #define PRNT(ch) ((((ch) < ' ') || ((ch) > '~')) ? '.' : (ch))
  212. if (dbgVerbose){
  213. ULONG i;
  214. DbgPrint("%s (len %xh @ %p): \r\n", msg, len, buf);
  215. for (i = 0; i < len; i += 0x10){
  216. if (i && !(i & 0x007f)){
  217. DbgPrint("\r\n");
  218. }
  219. DbgPrint(" ");
  220. if (len-i >= 16){
  221. PUCHAR ptr = buf+i;
  222. DbgPrint("%02x %02x %02x %02x %02x %02x %02x %02x "
  223. "%02x %02x %02x %02x %02x %02x %02x %02x "
  224. " "
  225. "%c%c%c%c%c%c%c%c %c%c%c%c%c%c%c%c",
  226. ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7],
  227. ptr[8], ptr[9], ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15],
  228. PRNT(ptr[0]), PRNT(ptr[1]), PRNT(ptr[2]), PRNT(ptr[3]),
  229. PRNT(ptr[4]), PRNT(ptr[5]), PRNT(ptr[6]), PRNT(ptr[7]),
  230. PRNT(ptr[8]), PRNT(ptr[9]), PRNT(ptr[10]), PRNT(ptr[11]),
  231. PRNT(ptr[12]), PRNT(ptr[13]), PRNT(ptr[14]), PRNT(ptr[15])
  232. );
  233. }
  234. else {
  235. ULONG j;
  236. for (j = 0; j < 16; j++){
  237. if (j == 8) DbgPrint(" ");
  238. if (i+j < len){
  239. DbgPrint("%02x ", (ULONG)buf[i+j]);
  240. }
  241. else {
  242. DbgPrint(" ");
  243. }
  244. }
  245. DbgPrint(" ");
  246. for (j = 0; j < 16; j++){
  247. if (j == 8) DbgPrint(" ");
  248. if (i+j < len){
  249. UCHAR ch = buf[i+j];
  250. DbgPrint("%c", PRNT(ch));
  251. }
  252. else {
  253. // DbgPrint(" ");
  254. }
  255. }
  256. }
  257. DbgPrint("\r\n");
  258. }
  259. }
  260. }
  261. VOID DbgShowIsochProgress()
  262. {
  263. if (dbgShowIsochProgress){
  264. DbgPrint(".");
  265. }
  266. }
  267. #endif