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.

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