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.

339 lines
8.9 KiB

  1. /*++
  2. Module Name:
  3. INFO.C
  4. Abstract:
  5. This source file contains routines for exercising the I82930.SYS
  6. test driver.
  7. Environment:
  8. user mode
  9. Copyright (c) 1996-1998 Microsoft Corporation. All Rights Reserved.
  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. --*/
  15. //*****************************************************************************
  16. // I N C L U D E S
  17. //*****************************************************************************
  18. #include <windows.h>
  19. #include <basetyps.h>
  20. #include <setupapi.h>
  21. #include <stdio.h>
  22. #include <devioctl.h>
  23. #include <string.h>
  24. #include <initguid.h>
  25. #include <usbdi.h>
  26. #include "ioctl.h"
  27. #pragma intrinsic(strlen, strcpy)
  28. //*****************************************************************************
  29. // T Y P E D E F S
  30. //*****************************************************************************
  31. typedef struct _DEVICENODE
  32. {
  33. struct _DEVICENODE *Next;
  34. CHAR DevicePath[0];
  35. } DEVICENODE, *PDEVICENODE;
  36. //*****************************************************************************
  37. // F U N C T I O N P R O T O T Y P E S
  38. //*****************************************************************************
  39. PDEVICENODE
  40. EnumDevices (
  41. LPGUID Guid
  42. );
  43. VOID ShowDeviceInfo (
  44. PCHAR DevicePath
  45. );
  46. VOID ShowInterfaceInfo (
  47. PUSBD_INTERFACE_INFORMATION InterfaceInfo
  48. );
  49. PCHAR
  50. GetPipeType (
  51. USBD_PIPE_TYPE PipeType
  52. );
  53. PCHAR
  54. GetPipeDirection (
  55. UCHAR EndpointAddress
  56. );
  57. //*****************************************************************************
  58. //
  59. // main()
  60. //
  61. //*****************************************************************************
  62. int _cdecl
  63. main(
  64. int argc,
  65. char *argv[]
  66. )
  67. {
  68. PDEVICENODE deviceNode;
  69. PDEVICENODE deviceNodeNext;
  70. deviceNode = EnumDevices((LPGUID)&GUID_CLASS_I82930);
  71. while (deviceNode)
  72. {
  73. ShowDeviceInfo(deviceNode->DevicePath);
  74. deviceNodeNext = deviceNode->Next;
  75. GlobalFree(deviceNode);
  76. deviceNode = deviceNodeNext;
  77. }
  78. return 0;
  79. }
  80. //*****************************************************************************
  81. //
  82. // EnumDevices()
  83. //
  84. //*****************************************************************************
  85. PDEVICENODE
  86. EnumDevices (
  87. LPGUID Guid
  88. )
  89. {
  90. HDEVINFO deviceInfo;
  91. SP_DEVICE_INTERFACE_DATA deviceInfoData;
  92. PSP_DEVICE_INTERFACE_DETAIL_DATA deviceDetailData;
  93. ULONG index;
  94. ULONG requiredLength;
  95. PDEVICENODE deviceNode;
  96. PDEVICENODE deviceNodeHead;
  97. deviceNodeHead = NULL;
  98. deviceInfo = SetupDiGetClassDevs(Guid,
  99. NULL,
  100. NULL,
  101. (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE));
  102. deviceInfoData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
  103. for (index=0;
  104. SetupDiEnumDeviceInterfaces(deviceInfo,
  105. 0,
  106. Guid,
  107. index,
  108. &deviceInfoData);
  109. index++)
  110. {
  111. SetupDiGetDeviceInterfaceDetail(deviceInfo,
  112. &deviceInfoData,
  113. NULL,
  114. 0,
  115. &requiredLength,
  116. NULL);
  117. deviceDetailData = GlobalAlloc(GPTR, requiredLength);
  118. deviceDetailData->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
  119. SetupDiGetDeviceInterfaceDetail(deviceInfo,
  120. &deviceInfoData,
  121. deviceDetailData,
  122. requiredLength,
  123. &requiredLength,
  124. NULL);
  125. requiredLength = sizeof(DEVICENODE) +
  126. strlen(deviceDetailData->DevicePath) + 1;
  127. deviceNode = GlobalAlloc(GPTR, requiredLength);
  128. strcpy(deviceNode->DevicePath, deviceDetailData->DevicePath);
  129. deviceNode->Next = deviceNodeHead;
  130. deviceNodeHead = deviceNode;
  131. GlobalFree(deviceDetailData);
  132. }
  133. SetupDiDestroyDeviceInfoList(deviceInfo);
  134. return deviceNodeHead;
  135. }
  136. //*****************************************************************************
  137. //
  138. // ShowDeviceInfo()
  139. //
  140. //*****************************************************************************
  141. VOID ShowDeviceInfo (
  142. PCHAR DevicePath
  143. )
  144. {
  145. HANDLE devHandle;
  146. BOOL success;
  147. int size;
  148. int nBytes;
  149. PUSBD_INTERFACE_INFORMATION interfaceInfo;
  150. devHandle = CreateFile(DevicePath,
  151. GENERIC_WRITE | GENERIC_READ,
  152. FILE_SHARE_WRITE | FILE_SHARE_READ,
  153. NULL,
  154. OPEN_EXISTING,
  155. 0,
  156. NULL);
  157. if (devHandle == INVALID_HANDLE_VALUE)
  158. {
  159. printf("Unable to open device:%s\n", DevicePath);
  160. return;
  161. }
  162. else
  163. {
  164. printf("Device: %s\n", DevicePath);
  165. }
  166. size = sizeof(USBD_INTERFACE_INFORMATION) -
  167. sizeof(USBD_PIPE_INFORMATION);
  168. interfaceInfo = GlobalAlloc(GPTR, size);
  169. success = DeviceIoControl(devHandle,
  170. IOCTL_I82930_GET_PIPE_INFORMATION,
  171. NULL,
  172. 0,
  173. interfaceInfo,
  174. size,
  175. &nBytes,
  176. NULL);
  177. if (success)
  178. {
  179. size = interfaceInfo->Length;
  180. interfaceInfo = GlobalReAlloc(interfaceInfo,
  181. size,
  182. GMEM_MOVEABLE | GMEM_ZEROINIT);
  183. success = DeviceIoControl(devHandle,
  184. IOCTL_I82930_GET_PIPE_INFORMATION,
  185. NULL,
  186. 0,
  187. interfaceInfo,
  188. size,
  189. &nBytes,
  190. NULL);
  191. if (success)
  192. {
  193. ShowInterfaceInfo(interfaceInfo);
  194. }
  195. }
  196. printf("\n");
  197. GlobalFree(interfaceInfo);
  198. CloseHandle(devHandle);
  199. }
  200. //*****************************************************************************
  201. //
  202. // ShowInterfaceInfo()
  203. //
  204. //*****************************************************************************
  205. VOID ShowInterfaceInfo (
  206. PUSBD_INTERFACE_INFORMATION InterfaceInfo
  207. )
  208. {
  209. ULONG i;
  210. printf("*** Number Of Pipes %02.2d\n",
  211. InterfaceInfo->NumberOfPipes);
  212. for (i=0; i<InterfaceInfo->NumberOfPipes; i++)
  213. {
  214. PUSBD_PIPE_INFORMATION pipeInfo;
  215. pipeInfo = &InterfaceInfo->Pipes[i];
  216. printf("PIPE%02d :: EP address (0x%02.2x)-(%s %s) Max Packet = %02.2d bytes [%d ms]\n",
  217. i,
  218. pipeInfo->EndpointAddress,
  219. GetPipeType(pipeInfo->PipeType),
  220. GetPipeDirection(pipeInfo->EndpointAddress),
  221. pipeInfo->MaximumPacketSize,
  222. pipeInfo->PipeType == UsbdPipeTypeInterrupt ?
  223. pipeInfo->Interval : 0
  224. );
  225. printf(" MaximumTransferSize = 0x%x\n",
  226. pipeInfo->MaximumTransferSize);
  227. }
  228. }
  229. //*****************************************************************************
  230. //
  231. // GetPipeType()
  232. //
  233. //*****************************************************************************
  234. PCHAR
  235. GetPipeType (
  236. USBD_PIPE_TYPE PipeType
  237. )
  238. {
  239. switch (PipeType)
  240. {
  241. case UsbdPipeTypeControl:
  242. return "Control ";
  243. case UsbdPipeTypeIsochronous:
  244. return "Iso ";
  245. case UsbdPipeTypeBulk:
  246. return "Bulk ";
  247. case UsbdPipeTypeInterrupt:
  248. return "Interrupt";
  249. default:
  250. return "??? ";
  251. }
  252. }
  253. //*****************************************************************************
  254. //
  255. // GetPipeDirection()
  256. //
  257. //*****************************************************************************
  258. PCHAR
  259. GetPipeDirection (
  260. UCHAR EndpointAddress
  261. )
  262. {
  263. if (USB_ENDPOINT_DIRECTION_IN(EndpointAddress))
  264. {
  265. return "in ";
  266. }
  267. else
  268. {
  269. return "out";
  270. }
  271. }