Source code of Windows XP (NT5)
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.

355 lines
10 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. USBHUB.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Kenneth D. Ray (kenray) June 1997
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. typedef union _USBHUB_FLAGS {
  15. struct {
  16. ULONG FullListing : 1;
  17. ULONG Reserved : 31;
  18. };
  19. ULONG Flags;
  20. } USBHUB_FLAGS;
  21. #define PRINT_FLAGS(value, flag) \
  22. if ((value) & (flag)) { \
  23. dprintf (#flag " "); \
  24. }
  25. #define ENTRY(x) { x, #x }
  26. extern VOID USBD_DeviceDescriptor (PCHAR Comment, ULONG64 Desc);
  27. extern VOID USBD_InterfaceDescriptor (PCHAR Comment, ULONG64 Desc);
  28. void USBHUB_DumpHub (ULONG64, USBHUB_FLAGS);
  29. void USBHUB_DumpHubHub (ULONG64, USBHUB_FLAGS);
  30. void USBHUB_DumpHubPort (ULONG64, USBHUB_FLAGS);
  31. void USBHUB_DumpHubParent (ULONG64, USBHUB_FLAGS);
  32. void USBHUB_DumpHubFunction (ULONG64, USBHUB_FLAGS);
  33. VOID
  34. DevExtUsbhub(
  35. ULONG64 MemLocPtr
  36. )
  37. /*++
  38. Routine Description:
  39. Dumps a hub device extension
  40. Arguments:
  41. args - Address flags
  42. Return Value:
  43. None
  44. --*/
  45. {
  46. ULONG result;
  47. USBHUB_FLAGS flags;
  48. flags.Flags = 1;
  49. dprintf ("Dump Hub Device Extension: %p %x \n", MemLocPtr, flags.Flags);
  50. //
  51. // Get the extension
  52. //
  53. if (InitTypeRead (MemLocPtr, usbhub!_DEVICE_EXTENSION_HEADER)) {
  54. dprintf ("Could not read Hub Extension\n");
  55. return;
  56. }
  57. USBHUB_DumpHub (MemLocPtr, flags);
  58. return;
  59. }
  60. void
  61. USBHUB_DumpHub (
  62. ULONG64 MemLoc,
  63. USBHUB_FLAGS Flags
  64. )
  65. {
  66. ULONG ExtensionType;
  67. if (GetFieldValue(MemLoc, "usbhub!_DEVICE_EXTENSION_HEADER", "ExtensionType", ExtensionType)) {
  68. return;
  69. }
  70. switch (ExtensionType) {
  71. case EXTENSION_TYPE_HUB:
  72. if (InitTypeRead (MemLoc, usbhub!_DEVICE_EXTENSION_HUB)) {
  73. dprintf ("Could not read _DEVICE_EXTENSION_HUB at %p\n", MemLoc);
  74. return;
  75. }
  76. USBHUB_DumpHubHub (MemLoc, Flags);
  77. break;
  78. case EXTENSION_TYPE_PORT:
  79. if (InitTypeRead(MemLoc, usbhub!_DEVICE_EXTENSION_PORT)) {
  80. dprintf ("Could not read _DEVICE_EXTENSION_PORT\n");
  81. return;
  82. }
  83. USBHUB_DumpHubPort (MemLoc, Flags);
  84. break;
  85. case EXTENSION_TYPE_PARENT:
  86. if (InitTypeRead (MemLoc, usbhub!_DEVICE_EXTENSION_PARENT)) {
  87. dprintf ("Could not read PDEVICE_EXTENSION_PARENT\n");
  88. return;
  89. }
  90. USBHUB_DumpHubParent (MemLoc, Flags);
  91. break;
  92. case EXTENSION_TYPE_FUNCTION:
  93. if (InitTypeRead(MemLoc, usbhub!_DEVICE_EXTENSION_FUNCTION)) {
  94. dprintf ("Could not read PDEVICE_EXTENSION_FUNCTION\n");
  95. return;
  96. }
  97. USBHUB_DumpHubFunction (MemLoc, Flags);
  98. break;
  99. }
  100. return ;
  101. }
  102. void
  103. USBHUB_DumpHubHub (
  104. ULONG64 MemLoc,
  105. USBHUB_FLAGS Flags
  106. )
  107. {
  108. ULONG i;
  109. // PDEVICE_EXTENSION_HUB Hub,
  110. // USB_HUB_DESCRIPTOR hubDesc;
  111. // PORT_DATA portData [32];
  112. ULONG HubFlags, bNumberOfPorts, SizeOfPortData;
  113. ULONG64 PortData;
  114. ULONG64 HubDescriptor;
  115. if (InitTypeRead (MemLoc, usbhub!_DEVICE_EXTENSION_HUB)) {
  116. dprintf ("Could not read DEVICE_EXTENSION_HUB at %p\n", MemLoc);
  117. return;
  118. }
  119. dprintf ("\nHUB HUB\n");
  120. dprintf ("FDO %x PDO %x TOS %x RootHub %x HcdTos %x\n",
  121. (ULONG) ReadField(FunctionalDeviceObject),
  122. (ULONG) ReadField(PhysicalDeviceObject),
  123. (ULONG) ReadField(TopOfStackDeviceObject),
  124. (ULONG) ReadField(RootHubPdo),
  125. (ULONG) ReadField(TopOfHcdStackDeviceObject));
  126. dprintf ("FLG: ");
  127. HubFlags = (ULONG) ReadField(HubFlags);
  128. PRINT_FLAGS (HubFlags, HUBFLAG_NEED_CLEANUP);
  129. PRINT_FLAGS (HubFlags, HUBFLAG_ENABLED_FOR_WAKEUP);
  130. PRINT_FLAGS (HubFlags, HUBFLAG_DEVICE_STOPPING);
  131. PRINT_FLAGS (HubFlags, HUBFLAG_HUB_FAILURE);
  132. PRINT_FLAGS (HubFlags, HUBFLAG_SUPPORT_WAKEUP);
  133. dprintf ("\nStatus: ");
  134. PRINT_FLAGS ((ULONG) ReadField(HubState.HubStatus), HUB_STATUS_LOCAL_POWER);
  135. PRINT_FLAGS ((ULONG) ReadField(HubState.HubStatus), HUB_STATUS_OVER_CURRENT);
  136. dprintf ("\n");
  137. dprintf ("HubChange %x\n", (ULONG) ReadField(HubState.HubChange));
  138. dprintf ("IRP %p Buffer %p len %x Desc %p \n"
  139. "PowerIrp %p PendingWake %p #PortWake %x \n",
  140. ReadField(Irp),
  141. ReadField(TransferBuffer),
  142. (ULONG) ReadField(TransferBufferLength),
  143. HubDescriptor = ReadField(HubDescriptor),
  144. ReadField(PowerIrp),
  145. ReadField(PendingWakeIrp),
  146. (ULONG) ReadField(NumberPortWakeIrps));
  147. PortData = ReadField(PortData);
  148. if (GetFieldValue(HubDescriptor,
  149. "usbhub!_USB_HUB_DESCRIPTOR",
  150. "bNumberOfPorts",
  151. bNumberOfPorts)) {
  152. dprintf ("Could not read Hub Descriptor\n");
  153. goto NO_HUB_DESC;
  154. }
  155. dprintf ("PortData %p size %x \n", PortData, bNumberOfPorts);
  156. SizeOfPortData = GetTypeSize("usbhub!_PORT_DATA");
  157. for (i = 0; i < bNumberOfPorts; i++) {
  158. ULONG PortStatus;
  159. if (InitTypeRead(PortData + SizeOfPortData*i,usbhub!_PORT_DATA)) {
  160. dprintf ("was not able to obtain the port list\n");
  161. break;
  162. }
  163. dprintf ("Port %x change %x Status %x",
  164. (ULONG) ReadField(DeviceObject),
  165. (ULONG) ReadField(PortState.PortChange),
  166. PortStatus = (ULONG) ReadField(PortState.PortStatus));
  167. dprintf ("\n ");
  168. PRINT_FLAGS (PortStatus, PORT_STATUS_CONNECT);
  169. PRINT_FLAGS (PortStatus, PORT_STATUS_ENABLE);
  170. PRINT_FLAGS (PortStatus, PORT_STATUS_SUSPEND);
  171. PRINT_FLAGS (PortStatus, PORT_STATUS_OVER_CURRENT);
  172. PRINT_FLAGS (PortStatus, PORT_STATUS_RESET);
  173. PRINT_FLAGS (PortStatus, PORT_STATUS_POWER);
  174. PRINT_FLAGS (PortStatus, PORT_STATUS_LOW_SPEED);
  175. dprintf ("\n");
  176. }
  177. InitTypeRead (MemLoc, usbhub!_DEVICE_EXTENSION_HUB);
  178. NO_HUB_DESC:
  179. dprintf ("Config Handle %x ConfigDesc %x\n",
  180. (ULONG) ReadField(Configuration),
  181. (ULONG) ReadField(ConfigurationDescriptor));
  182. dprintf ("PowerTable ");
  183. for (i = 0; i < PowerSystemMaximum; i++) {
  184. UCHAR Dev[40];
  185. sprintf(Dev,"DeviceState[%d]",i);
  186. dprintf ("%x ", (ULONG) GetShortField(0, Dev,0));
  187. }
  188. dprintf ("Current %x\n", (ULONG) ReadField(CurrentPowerState));
  189. dprintf ("Pending Req %x ErrorCount %x \n",
  190. (ULONG) ReadField(PendingRequestCount),
  191. (ULONG) ReadField(ErrorCount));
  192. dprintf ("DeviceDesc %p PipInfo %p Urb %p\n",
  193. ReadField(DeviceDescriptor),
  194. ReadField(PipeInformation),
  195. ReadField(Urb));
  196. dprintf ("\n");
  197. }
  198. void
  199. USBHUB_DumpHubPort (
  200. ULONG64 MemLoc,
  201. USBHUB_FLAGS Flags
  202. )
  203. {
  204. struct { ULONG Value; PCHAR Name; } PdoFlags[] = {
  205. ENTRY (PORTPDO_DEVICE_IS_HUB),
  206. ENTRY (PORTPDO_DEVICE_IS_PARENT),
  207. ENTRY (PORTPDO_DEVICE_ENUM_ERROR),
  208. // ENTRY (PORTPDO_SUPPORT_NON_COMP
  209. ENTRY (PORTPDO_REMOTE_WAKEUP_SUPPORTED),
  210. ENTRY (PORTPDO_REMOTE_WAKEUP_ENABLED),
  211. ENTRY (PORTPDO_DELETED_PDO),
  212. ENTRY (PORTPDO_DELETE_PENDING),
  213. ENTRY (PORTPDO_NEED_RESET),
  214. ENTRY (PORTPDO_STARTED),
  215. ENTRY (PORTPDO_WANT_POWER_FEATURE),
  216. ENTRY (PORTPDO_SYM_LINK),
  217. ENTRY (PORTPDO_DEVICE_FAILED),
  218. ENTRY (PORTPDO_USB_SUSPEND)
  219. // ENTRY (PORTPDO_OVERCURRENT
  220. };
  221. ULONG i, j;
  222. ULONG PortPdoFlags;
  223. WCHAR UniqueIdString[8]={0};
  224. if (InitTypeRead(MemLoc, usbhub!_DEVICE_EXTENSION_PORT)) {
  225. return;
  226. }
  227. dprintf ("\nHUB PORT\n");
  228. dprintf ("Port PDO: %p \n", ReadField(PortPhysicalDeviceObject));
  229. dprintf ("Hub DeviceExtension: %p \n", ReadField(DeviceExtensionHub));
  230. dprintf ("PortNum %x, SerialNumberBuffer %x Length %x\n",
  231. (ULONG) ReadField(PortNumber),
  232. (ULONG) ReadField(SerialNumberBuffer),
  233. (ULONG) ReadField(SerialNumberBufferLength));
  234. dprintf ("DeviceData %x, DevicePowerState %x\n",
  235. (ULONG) ReadField(DeviceData),
  236. (ULONG) ReadField(DeviceState));
  237. dprintf ("WaitWaitIrp %x HackFlags %x\n",
  238. (ULONG) ReadField(WaitWakeIrp),
  239. (ULONG) ReadField(DeviceHackFlags));
  240. GetFieldValue(MemLoc, "usbhub!_DEVICE_EXTENSION_PORT", "UniqueIdString", UniqueIdString);
  241. dprintf ("UId String %ws SymLinkName Len %x MaxLen %x Buffer %p\n",
  242. UniqueIdString,
  243. (ULONG) ReadField(SymbolicLinkName.Length),
  244. (ULONG) ReadField(SymbolicLinkName.MaximumLength),
  245. (ULONG) ReadField(SymbolicLinkName.Buffer));
  246. if (Flags.FullListing) {
  247. USBD_DeviceDescriptor ("Device Descriptor", ReadField(DeviceDescriptor));
  248. USBD_DeviceDescriptor ("Old Dev Descriptor", ReadField(OldDeviceDescriptor));
  249. USBD_InterfaceDescriptor ("Interface Descriptor", ReadField(InterfaceDescriptor));
  250. } else {
  251. dprintf ("DevDesc %p Old DevD %p IntefaceD %p\n",
  252. ReadField(DeviceDescriptor),
  253. ReadField(OldDeviceDescriptor),
  254. ReadField(InterfaceDescriptor));
  255. }
  256. dprintf (" Port PDO Flags: %x ", PortPdoFlags = (ULONG) ReadField(PortPdoFlags));
  257. for (j = 0, i = 0; i < (sizeof PdoFlags / sizeof PdoFlags[1]); i++) {
  258. if (PdoFlags[i].Value & PortPdoFlags) {
  259. if (0 == j) {
  260. dprintf ("\n ");
  261. }
  262. j ^= 1;
  263. dprintf ("%s ", PdoFlags[i].Name);
  264. }
  265. }
  266. dprintf ("\n\n");
  267. }
  268. void
  269. USBHUB_DumpHubParent (
  270. ULONG64 MemLoc,
  271. USBHUB_FLAGS Flags
  272. )
  273. {
  274. UNREFERENCED_PARAMETER (MemLoc);
  275. UNREFERENCED_PARAMETER (Flags);
  276. dprintf ("Hub parent\n");
  277. }
  278. void
  279. USBHUB_DumpHubFunction (
  280. ULONG64 MemLoc,
  281. USBHUB_FLAGS Flags
  282. )
  283. {
  284. UNREFERENCED_PARAMETER (MemLoc);
  285. UNREFERENCED_PARAMETER (Flags);
  286. dprintf ("Hub parent\n");
  287. }