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.

383 lines
8.4 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. util.c
  5. Abstract:
  6. WinDbg Extension Api
  7. Author:
  8. Chris Robinson (crobins) Feburary 1999
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #include "usbhcdkd.h"
  15. VOID
  16. DumpUSBDescriptor(
  17. PVOID Descriptor
  18. )
  19. {
  20. PUSB_DEVICE_DESCRIPTOR dd = Descriptor;
  21. PUSB_COMMON_DESCRIPTOR cd = Descriptor;
  22. PUSB_INTERFACE_DESCRIPTOR id = Descriptor;
  23. PUSB_CONFIGURATION_DESCRIPTOR cf = Descriptor;
  24. PUSB_ENDPOINT_DESCRIPTOR ed = Descriptor;
  25. switch (cd->bDescriptorType) {
  26. case USB_CONFIGURATION_DESCRIPTOR_TYPE:
  27. dprintf("[CONFIGURATION DESCRIPTOR]\n");
  28. dprintf("bLength 0x%x\n", cf->bLength);
  29. dprintf("bDescriptorType 0x%x\n", cf->bDescriptorType);
  30. dprintf("wTotalLength 0x%x (%d)\n", cf->wTotalLength, cf->wTotalLength);
  31. dprintf("bNumInterfaces 0x%x\n", cf->bNumInterfaces);
  32. dprintf("bConfigurationValue 0x%x\n", cf->bConfigurationValue);
  33. dprintf("iConfiguration 0x%x\n", cf->iConfiguration);
  34. dprintf("bmAttributes 0x%x\n", cf->bmAttributes);
  35. dprintf("MaxPower 0x%x (%d)\n", cf->MaxPower, cf->MaxPower);
  36. break;
  37. case USB_INTERFACE_DESCRIPTOR_TYPE:
  38. dprintf("[INTERFACE DESCRIPTOR]\n");
  39. dprintf("bLength 0x%x\n", id->bLength);
  40. dprintf("bDescriptorType 0x%x\n", id->bDescriptorType);
  41. dprintf("bInterfaceNumber 0x%x\n", id->bInterfaceNumber);
  42. dprintf("bAlternateSetting 0x%x\n", id->bAlternateSetting);
  43. dprintf("bNumEndpoints 0x%x\n", id->bNumEndpoints);
  44. dprintf("bInterfaceClass 0x%x\n", id->bInterfaceClass);
  45. dprintf("bInterfaceSubClass 0x%x\n", id->bInterfaceSubClass);
  46. dprintf("bInterfaceProtocol 0x%x\n", id->bInterfaceProtocol);
  47. dprintf("iInterface 0x%x\n", id->iInterface);
  48. break;
  49. case USB_DEVICE_DESCRIPTOR_TYPE:
  50. dprintf("[DEVICE DESCRIPTOR]\n");
  51. dprintf("bLength 0x%x\n", dd->bLength);
  52. dprintf("bDescriptorType 0x%x\n", dd->bDescriptorType);
  53. dprintf("bcdUSB 0x%x\n", dd->bcdUSB);
  54. dprintf("bDeviceClass 0x%x\n", dd->bDeviceClass);
  55. dprintf("bDeviceSubClass 0x%x\n", dd->bDeviceSubClass);
  56. dprintf("bDeviceProtocol 0x%x\n", dd->bDeviceProtocol);
  57. dprintf("bMaxPacketSize0 0x%x\n", dd->bMaxPacketSize0);
  58. dprintf("idVendor 0x%x\n", dd->idVendor);
  59. dprintf("idProduct 0x%x\n", dd->idProduct);
  60. dprintf("bcdDevice 0x%x\n", dd->bcdDevice);
  61. dprintf("iManufacturer 0x%x\n", dd->iManufacturer);
  62. dprintf("iProduct 0x%x\n", dd->iProduct);
  63. dprintf("iSerialNumber 0x%x\n", dd->iSerialNumber);
  64. dprintf("bNumConfigurations 0x%x\n", dd->bNumConfigurations);
  65. break;
  66. case USB_ENDPOINT_DESCRIPTOR_TYPE:
  67. dprintf("[ENDPOINT DESCRIPTOR]\n");
  68. dprintf("bLength 0x%x\n", ed->bLength);
  69. dprintf("bDescriptorType 0x%x\n", ed->bDescriptorType);
  70. dprintf("bEndpointAddress 0x%x\n", ed->bEndpointAddress);
  71. dprintf("bmAttributes 0x%x\n", ed->bmAttributes);
  72. dprintf("wMaxPacketSize 0x%x\n", ed->wMaxPacketSize);
  73. dprintf("bInterval 0x%x\n", ed->bInterval);
  74. break;
  75. default:
  76. dprintf("[DESCRIPTOR ???]\n");
  77. }
  78. }
  79. VOID
  80. DumpUnicodeString(
  81. UNICODE_STRING uniString
  82. )
  83. {
  84. dprintf(">> Buffer: %08.8x, Length %d\n",
  85. uniString.Buffer, uniString.Length);
  86. }
  87. VOID
  88. Sig(
  89. ULONG Sig,
  90. PUCHAR p
  91. )
  92. {
  93. SIG s;
  94. dprintf(p);
  95. s.l = Sig;
  96. dprintf("Sig:%08.8x %c%c%c%c\n", Sig,
  97. s.c[0], s.c[1], s.c[2], s.c[3]);
  98. }
  99. CPPMOD
  100. ScanfMemLoc(
  101. PMEMLOC MemLoc,
  102. PCSTR args
  103. )
  104. {
  105. // UCHAR buffer[256];
  106. ULONG tmp1 = 0, tmp2 = 0;
  107. //buffer[0] = '\0';
  108. if (IsPtr64()) {
  109. //sscanf(args, "%lx %lx", &MemLoc->p64, buffer);
  110. } else {
  111. sscanf(args, "%lx %lx", &tmp1, &tmp2);
  112. *MemLoc = (ULONG64) tmp1;
  113. dprintf("tmp1 = %x tmp2 = %x\n", tmp1, tmp2);
  114. }
  115. }
  116. VOID
  117. PrintfMemLoc(
  118. PUCHAR Str1,
  119. MEMLOC MemLoc,
  120. PUCHAR Str2
  121. )
  122. {
  123. if (IsPtr64()) {
  124. ULONG tmp = (ULONG) MemLoc;
  125. ULONG tmp1 = (ULONG) (MemLoc>>32);
  126. #ifdef DEBUGIT
  127. dprintf("%s%08.8x%08.8x (64)%s", Str1, tmp1, tmp, Str2);
  128. #else
  129. dprintf("%s%08.8x%08.8x %s", Str1, tmp1, tmp, Str2);
  130. #endif
  131. } else {
  132. ULONG tmp = (ULONG) MemLoc;
  133. #ifdef DEBUGIT
  134. dprintf("%s%08.8x (32)%s", Str1, tmp, Str2);
  135. #else
  136. dprintf("%s%08.8x %s", Str1, tmp, Str2);
  137. #endif
  138. }
  139. }
  140. VOID
  141. BadMemLoc(
  142. ULONG MemLoc
  143. )
  144. {
  145. dprintf("could not read mem location %08.8x\n", MemLoc);
  146. }
  147. VOID
  148. BadSig(
  149. ULONG Sig,
  150. ULONG ExpectedSig
  151. )
  152. {
  153. dprintf("Bad Structure Signature %08.8x\n", Sig);
  154. }
  155. VOID
  156. UsbDumpFlags(
  157. ULONG Flags,
  158. PFLAG_TABLE FlagTable,
  159. ULONG NumEntries
  160. )
  161. {
  162. ULONG i;
  163. PFLAG_TABLE ft = FlagTable;
  164. for (i=0; i< NumEntries; i++) {
  165. if (ft->Mask & Flags) {
  166. dprintf ("\t> %s\n", ft->Name);
  167. }
  168. ft++;
  169. }
  170. }
  171. ULONG
  172. UsbFieldOffset(
  173. IN LPSTR Type,
  174. IN LPSTR Field
  175. )
  176. {
  177. ULONG offset;
  178. ULONG r;
  179. r = GetFieldOffset(Type, Field, &offset);
  180. #ifdef DEBUGIT
  181. dprintf("<UsbReadFieldPtr %x offset %x>", r, offset);
  182. #endif
  183. return offset;
  184. }
  185. MEMLOC
  186. UsbReadFieldPtr(
  187. IN ULONG64 Addr,
  188. IN LPSTR Type,
  189. IN LPSTR Field
  190. )
  191. {
  192. MEMLOC p;
  193. ULONG r;
  194. r = GetFieldValue(Addr, Type, Field, p);
  195. #ifdef DEBUGIT
  196. dprintf("<UsbReadFieldPtr %x>", r);
  197. #endif
  198. return p;
  199. }
  200. UCHAR
  201. UsbReadFieldUchar(
  202. IN ULONG64 Addr,
  203. IN LPSTR Type,
  204. IN LPSTR Field
  205. )
  206. {
  207. UCHAR ch;
  208. ULONG r;
  209. r = GetFieldValue(Addr, Type, Field, ch);
  210. #ifdef DEBUGIT
  211. dprintf("<UsbReadFieldUchar %x>", r);
  212. #endif
  213. return ch;
  214. }
  215. ULONG
  216. UsbReadFieldUlong(
  217. IN ULONG64 Addr,
  218. IN LPSTR Type,
  219. IN LPSTR Field
  220. )
  221. {
  222. ULONG l;
  223. ULONG r;
  224. r = GetFieldValue(Addr, Type, Field, l);
  225. #ifdef DEBUGIT
  226. dprintf("<UsbReadFieldUlong %x>", r);
  227. #endif
  228. return l;
  229. }
  230. USHORT
  231. UsbReadFieldUshort(
  232. IN ULONG64 Addr,
  233. IN LPSTR Type,
  234. IN LPSTR Field
  235. )
  236. {
  237. USHORT s;
  238. ULONG r;
  239. r = GetFieldValue(Addr, Type, Field, s);
  240. #ifdef DEBUGIT
  241. dprintf("<UsbReadFieldUshort %x>", r);
  242. #endif
  243. return s;
  244. }
  245. VOID
  246. UsbDumpStruc(
  247. MEMLOC MemLoc,
  248. PUCHAR Cs,
  249. PSTRUC_ENTRY FieldList,
  250. ULONG NumEntries
  251. )
  252. {
  253. ULONG i, l;
  254. UCHAR s[80];
  255. SIG sig;
  256. for (i=0; i< NumEntries; i++) {
  257. switch (FieldList->FieldType) {
  258. case FT_ULONG:
  259. dprintf("%s: 0x%08.8x\n",
  260. FieldList->FieldName,
  261. UsbReadFieldUlong(MemLoc, Cs, FieldList->FieldName));
  262. break;
  263. case FT_UCHAR:
  264. dprintf("%s: 0x%02.2x\n",
  265. FieldList->FieldName,
  266. UsbReadFieldUchar(MemLoc, Cs, FieldList->FieldName));
  267. break;
  268. case FT_USHORT:
  269. dprintf("%s: 0x%04.4x\n",
  270. FieldList->FieldName,
  271. UsbReadFieldUshort(MemLoc, Cs, FieldList->FieldName));
  272. break;
  273. case FT_PTR:
  274. sprintf(s, "%s: ", FieldList->FieldName);
  275. PrintfMemLoc(s,
  276. UsbReadFieldPtr(MemLoc, Cs, FieldList->FieldName),
  277. "\n");
  278. break;
  279. case FT_SIG:
  280. sig.l = UsbReadFieldUlong(MemLoc, Cs, FieldList->FieldName);
  281. Sig(sig.l, "");
  282. break;
  283. case FT_DEVSPEED:
  284. l = UsbReadFieldUlong(MemLoc, Cs, FieldList->FieldName);
  285. dprintf("%s: ",
  286. FieldList->FieldName);
  287. switch (l) {
  288. case UsbLowSpeed:
  289. dprintf("UsbLowSpeed\n");
  290. break;
  291. case UsbFullSpeed:
  292. dprintf("UsbFullSpeed\n");
  293. break;
  294. case UsbHighSpeed:
  295. dprintf("UsbHighSpeed\n");
  296. break;
  297. }
  298. break;
  299. }
  300. FieldList++;
  301. }
  302. }
  303. ULONG
  304. CheckSym()
  305. {
  306. MEMLOC m;
  307. //
  308. // Verify that we have the right symbols.
  309. //
  310. m = GetExpression ("usbport!USBPORT_MiniportDriverList");
  311. if (m == 0) {
  312. dprintf ("Incorrect symbols for USBPORT\n");
  313. return E_INVALIDARG;
  314. }
  315. return S_OK;
  316. }