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.

622 lines
17 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. GUSB.H
  5. Abstract:
  6. This module contains the PUBLIC definitions for the
  7. helper lib that talks to the generic USB driver
  8. Environment:
  9. Kernel & user mode
  10. @@BEGIN_DDKSPLIT
  11. Revision History:
  12. Sept-01 : created by Kenneth Ray
  13. @@END_DDKSPLIT
  14. --*/
  15. #ifndef __GUSB_H_
  16. #define __GUSB_H_
  17. #ifndef __GUSB_H_KERNEL_
  18. #include <pshpack4.h>
  19. #include <wtypes.h>
  20. #include <windef.h>
  21. #include <basetyps.h>
  22. #include <setupapi.h>
  23. #include <usb.h>
  24. #endif //__GUSB_H_KERNEL_
  25. //////////////////////////////////////////////////////////////////
  26. //
  27. // Structures
  28. //
  29. //////////////////////////////////////////////////////////////////
  30. //
  31. // Used with GenUSB_GetCapabilities.
  32. //
  33. // This structure returns the size of standard descriptors so that
  34. //
  35. typedef struct _GENUSB_CAPABILITIES {
  36. USHORT DeviceDescriptorLength;
  37. USHORT ConfigurationInformationLength;
  38. USHORT ReservedFields[14]; // Don't use these fields
  39. } GENUSB_CAPABILITIES, *PGENUSB_CAPABILITIES;
  40. //
  41. // Used with GenUSB_DefaultControlRequest
  42. //
  43. // Returns the status of special reequest sent down to the device.
  44. //
  45. typedef struct _GENUSB_REQUEST_RESULTS {
  46. USBD_STATUS Status;
  47. USHORT Length;
  48. USHORT Reserved;
  49. // Pointer to the buffer to be transmitted or received.
  50. UCHAR Buffer[];
  51. } GENUSB_REQUEST_RESULTS, *PGENUSB_REQUEST_RESULTS;
  52. //
  53. // An array of pointers to all the descriptors in a interface descriptor
  54. // not including the interface descriptor itself.
  55. //
  56. typedef struct _GENUSB_INTERFACE_DESCRIPTOR_ARRAY {
  57. USB_INTERFACE_DESCRIPTOR Interface; // sizeof (9)
  58. UCHAR NumberEndpointDescriptors;
  59. UCHAR NumberOtherDescriptors;
  60. UCHAR Reserved;
  61. PUSB_ENDPOINT_DESCRIPTOR * EndpointDescriptors; // array of pointers to endpoint descriptors
  62. PUSB_COMMON_DESCRIPTOR * OtherDescriptors; // array of pointers to the other descriptors
  63. } GENUSB_INTERFACE_DESCRIPTOR_ARRAY, *PGENUSB_INTERFACE_DESCRIPTOR_ARRAY;
  64. //
  65. // An array of pointers to all the interface descriptors in a configuration
  66. // descriptor
  67. //
  68. typedef struct _GENUSB_CONFIGURATION_INFORMATION_ARRAY {
  69. UCHAR NumberInterfaces;
  70. USB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; // sizeof (9)
  71. UCHAR Reserved[2];
  72. GENUSB_INTERFACE_DESCRIPTOR_ARRAY Interfaces[];
  73. } GENUSB_CONFIGURATION_INFORMATION_ARRAY, *PGENUSB_CONFIGURATION_INFORMATION_ARRAY;
  74. //
  75. // per pipe settings
  76. //
  77. // These can be read and set with
  78. //
  79. // GenUSB_GetPipeProperties
  80. // GenUSB_SetPipeProperties
  81. //
  82. typedef struct _PGENUSB_PIPE_PROPERTIES {
  83. // Handle to this Pipe Properties
  84. // This field is set by GenUSB_GetPipeProperties, and should
  85. // be returned unchanged to GenUSB_SetPipeProperties.
  86. USHORT PipePropertyHandle;
  87. // Elliminate the problem of buffer overruns by truncating all requests to
  88. // read from the device to a multiple of maxpacket. This will prevent
  89. // there being a request down on the host controller, that cannot hold
  90. // an entire maxpacket. Genusb Truncates by default. (AKA FALSE)
  91. BOOLEAN NoTruncateToMaxPacket;
  92. // Direction bit. Although this information exists implicitely in the
  93. // endpoint address, duplicate it here to make things easier.
  94. // Set to TRUE for a in pipe, and false for an out pipe.
  95. BOOLEAN DirectionIn;
  96. // The default Timeout for a given Pipe in seconds (must be greater than 1)
  97. USHORT Timeout;
  98. USHORT ReservedFields[13];
  99. }GENUSB_PIPE_PROPERTIES, *PGENUSB_PIPE_PROPERTIES;
  100. #ifndef __GUSB_H_KERNEL_
  101. //
  102. // A structure that contains the information needed to open the generic USB
  103. // device driver.
  104. //
  105. // Returned as an array from GenUSB_FindKnownDevices
  106. //
  107. typedef struct _GENUSB_DEVICE {
  108. PSP_DEVICE_INTERFACE_DETAIL_DATA DetailData;
  109. } GENUSB_DEVICE, *PGENUSB_DEVICE;
  110. #endif // __GUSB_H_KERNEL_
  111. /////////////////////////////////////////////
  112. // Device Interface Registry Strings
  113. /////////////////////////////////////////////
  114. //
  115. // These values are used by the FIND_KNOWN_DEVICES_FILTER
  116. // to find out whether or not you want to use a givend device
  117. //
  118. #define GENUSB_REG_STRING_DEVICE_CLASS L"Device Class"
  119. #define GENUSB_REG_STRING_DEVICE_SUB_CLASS L"Device Sub Class"
  120. #define GENUSB_REG_STRING_DEVICE_PROTOCOL L"Device Protocol"
  121. #define GENUSB_REG_STRING_VID L"Vendor ID"
  122. #define GENUSB_REG_STRING_PID L"Product ID"
  123. #define GENUSB_REG_STRING_REV L"Revision"
  124. //////////////////////////////////////////////////////////////////
  125. //
  126. // Flags
  127. //
  128. //////////////////////////////////////////////////////////////////
  129. //
  130. // As defined in the USB spec chapter 9.
  131. //
  132. #define GENUSB_RECIPIENT_DEVICE 0
  133. #define GENUSB_RECIPIENT_INTERFACE 1
  134. #define GENUSB_RECIPIENT_ENDPOINT 2
  135. #define GENUSB_RECIPIENT_OTHER 3
  136. #ifndef __GUSB_H_KERNEL_
  137. //////////////////////////////////////////////////////////////////
  138. //
  139. // Exported Functions
  140. //
  141. //////////////////////////////////////////////////////////////////
  142. //
  143. // Used with GenUSB_FindKnownDevices
  144. //
  145. // GenUSB_FindKnownDevices calls this function for each device in the system
  146. // that has the GenUSB Device Interface. The filter function gets a handle
  147. // to the device interface registry key, so that it can see if this is a
  148. // device it wishes to use. See the registry values above.
  149. //
  150. // This filter should return TRUE for all devices that the client wants to use.
  151. //
  152. typedef
  153. BOOL
  154. (*GENUSB_FIND_KNOWN_DEVICES_FILTER) (
  155. IN HKEY Regkey,
  156. IN PVOID Context
  157. );
  158. /*++
  159. GenUSB_FindKnownDevices
  160. Routine Descriptor:
  161. find all the devices in the system that have the device interface
  162. guid for generic USB and return them in this array.
  163. This function allocates the memory and the caller must free it.
  164. Arguments:
  165. Filter - a pointer to the GENUSB_FIND_KNOWN_DEVICES_FILTER to filter the
  166. devices returned.
  167. Contect - a pointer to context data that the call wants passed into
  168. the filter function.
  169. Devices - returns a pointer to an array of PGENUSB_DEVICE structures
  170. to which the filter function returned TRUE.
  171. The call must free this memory.
  172. NumberDevices - the length of the Devices array.
  173. --*/
  174. BOOL __stdcall
  175. GenUSB_FindKnownDevices (
  176. IN GENUSB_FIND_KNOWN_DEVICES_FILTER Filter,
  177. IN PVOID Context,
  178. OUT PGENUSB_DEVICE * Devices, // A array of device interfaces.
  179. OUT PULONG NumberDevices // the length of this array.
  180. );
  181. /*++
  182. GenUSB_GetCapabilities
  183. Routine Description:
  184. Retrive the Capabilities from this devices.
  185. --*/
  186. BOOL __stdcall
  187. GenUSB_GetCapabilities (
  188. IN HANDLE GenUSBDeviceObject,
  189. OUT PGENUSB_CAPABILITIES Capabilities
  190. );
  191. /*++
  192. GenUSB_GetDeviceDescriptor
  193. Routine Description:
  194. Get the Device Descriptor for this USB device.
  195. Use (PGENUSB_CAPABILITIES)->DeviceDescriptorLength to find out the size.
  196. --*/
  197. BOOL __stdcall
  198. GenUSB_GetDeviceDescriptor (
  199. IN HANDLE GenUSBDeviceObject,
  200. OUT PUSB_DEVICE_DESCRIPTOR Descriptor,
  201. IN ULONG DescriptorLength
  202. );
  203. /*++
  204. GenUSB_GetConfigurationDescriptor
  205. Routine Description:
  206. Get the complete configuraiton descriptor for this device, including all
  207. of the follow on descriptors that the device returns for the configuration.
  208. Use (PGENUSB_CAPABILITIES)->ConfigurationInformationLength to find out
  209. the size.
  210. --*/
  211. BOOL __stdcall
  212. GenUSB_GetConfigurationInformation (
  213. IN HANDLE GenUSBDeviceObject,
  214. OUT PUSB_CONFIGURATION_DESCRIPTOR Descriptor,
  215. IN ULONG ConfigurationInformationLength
  216. );
  217. /*++
  218. GenUSB_GetStringDescriptor
  219. Routine Description:
  220. Retrieve any string descriptor from the device.
  221. Arguments
  222. Recipient: Use GENUSB_RECIPIENT_Xxx Flags to indicate which kind of
  223. string descriptor required.
  224. Index: See USB (Capter 9) specified string index.
  225. LanguageID: See USB (chapter 9) for information on using Language ID.
  226. Descriptor: Pointer to the caller allocated memory to receive the
  227. string descriptor.
  228. DescriptorLength: size in bytes of this buffer.
  229. --*/
  230. BOOL __stdcall
  231. GenUSB_GetStringDescriptor (
  232. IN HANDLE GenUSBDeviceObject,
  233. IN UCHAR Recipient,
  234. IN UCHAR Index,
  235. IN USHORT LanguageId,
  236. OUT PUCHAR Descriptor,
  237. IN USHORT DescriptorLength
  238. );
  239. /*++
  240. GenUSB_DefaultControlRequest
  241. Routine Description:
  242. Send a control request down the default pipe of the given USB device as
  243. devined in USB (Chapter 9.3).
  244. RequestType: bRequestType of the setup Data.
  245. Reqeust: bRrequest of the setup Data.
  246. Value: wValue of the setup Data.
  247. Index: wIndex of the setup Data.
  248. Result: a pointer to a GENUSB_REQUEST_RESULTS structure that will receive
  249. the result of this command to the device.
  250. BufferLength: the size in bytes of the Results stucture allocated.
  251. --*/
  252. BOOL __stdcall
  253. GenUSB_DefaultControlRequest (
  254. IN HANDLE GenUSBDeviceObject,
  255. IN UCHAR RequestType,
  256. IN UCHAR Request,
  257. IN USHORT Value,
  258. IN USHORT Index,
  259. IN OUT PGENUSB_REQUEST_RESULTS Result,
  260. IN USHORT BufferLength
  261. );
  262. /*++
  263. GenUSB_ParseDescriptor
  264. Routine Description:
  265. Parses a group of standard USB configuration descriptors (returned
  266. from a device) for a specific descriptor type.
  267. Arguments:
  268. DescriptorBuffer - pointer to a block of contiguous USB desscriptors
  269. TotalLength - size in bytes of the Descriptor buffer
  270. StartPosition - starting position in the buffer to begin parsing,
  271. this must point to the begining of a USB descriptor.
  272. DescriptorType - USB descritor type to locate. (Zero means the next one.)
  273. Return Value:
  274. pointer to a usb descriptor with a DescriptorType field matching the
  275. input parameter or NULL if not found.
  276. --*/
  277. PUSB_COMMON_DESCRIPTOR __stdcall
  278. GenUSB_ParseDescriptor(
  279. IN PVOID DescriptorBuffer,
  280. IN ULONG TotalLength,
  281. IN PVOID StartPosition,
  282. IN LONG DescriptorType
  283. );
  284. /*++
  285. GenUSB_ParseDescriptorToArray
  286. Routine Description:
  287. Parses a group of standard USB configuration descriptors (returned
  288. from a device) into an array of _GENUSB_INTERFACE_DESCRIPTOR_ARRAY
  289. for each interface found.
  290. The call must free this structure using
  291. GenUSB_FreeConfigurationDescriptorArray
  292. Arguments:
  293. ConfigurationDescriptor
  294. Return Value:
  295. Pointer to an allocated array.
  296. --*/
  297. PGENUSB_CONFIGURATION_INFORMATION_ARRAY __stdcall
  298. GenUSB_ParseDescriptorsToArray(
  299. IN PUSB_CONFIGURATION_DESCRIPTOR ConfigigurationInfomation
  300. );
  301. /*++
  302. GenUSB_FreeConfigurationDescriptorArray
  303. Routine Description:
  304. Frees the memory allocated by ParseDescriptorsToArray.
  305. Arguments:
  306. ConfigurationArray - the return of ParseDescriptorsToArray.
  307. Return Value:
  308. --*/
  309. void __stdcall
  310. GenUSB_FreeConfigurationDescriptorArray (
  311. PGENUSB_CONFIGURATION_INFORMATION_ARRAY ConfigurationArray
  312. );
  313. /*++
  314. GenUSB_SetConfiguration
  315. Routine Description:
  316. Configure a USB device by selecting an interface.
  317. Currently this function only allows for turning on the primary configuraion
  318. of a USB device. (This is so callers need not understand whether or not
  319. they are merely a part of a composite device.)
  320. Arguments:
  321. RequestedNumberInterfaces: Specifies the number of interfaces the caller
  322. wants to activate (and get handles for).
  323. This value is typically one.
  324. ReqeustedInterfaces[]: An array of interface descriptor structures listed
  325. out the interfaces that the caller wants to activate.
  326. The Generic USB driver searches on the configuration
  327. descriptor for entries in this list. Based on the
  328. matches found, it configures the device. The caller
  329. need not fill out all entries in a this structure
  330. to find a match on an interface. The caller must set
  331. any fields "left blank" to -1.
  332. FoundNumberInterfaces: Returns the number of interfaces found in the
  333. default configuration.
  334. FoundInterfaces: An array of all the now active interfaces on the device.
  335. --*/
  336. BOOL __stdcall
  337. GenUSB_SelectConfiguration (
  338. IN HANDLE GenUSBDeviceObject,
  339. IN UCHAR RequestedNumberInterfaces,
  340. IN USB_INTERFACE_DESCRIPTOR RequestedInterfaces[],
  341. OUT PUCHAR FoundNumberInterfaces,
  342. OUT USB_INTERFACE_DESCRIPTOR FoundInterfaces[]
  343. );
  344. BOOL __stdcall
  345. GenUSB_DeselectConfiguration (
  346. IN HANDLE GenUSBDeviceObject
  347. );
  348. /*++
  349. GenUSB_GetPipeInformation
  350. RoutineDescription:
  351. Return a USBD_PIPE_INFORMATION strucutre for a given pipe. (as specified
  352. by a given interface and endpoint)
  353. Arguments
  354. --*/
  355. BOOL __stdcall
  356. GenUSB_GetPipeInformation (
  357. IN HANDLE GenUSBDeviceObject,
  358. IN UCHAR InterfaceNumber,
  359. IN UCHAR EndpointAddress,
  360. OUT PUSBD_PIPE_INFORMATION PipeInformation
  361. );
  362. /*++
  363. GenUSB_GetPipeProperties
  364. RoutineDescription:
  365. Get the properties on this particular Pipe
  366. --*/
  367. BOOL __stdcall
  368. GenUSB_GetPipeProperties (
  369. IN HANDLE GenUSBDeviceObject,
  370. IN USBD_PIPE_HANDLE PipeHandle,
  371. IN PGENUSB_PIPE_PROPERTIES Properties
  372. );
  373. /*++
  374. GenUSB_SetPipeProperties
  375. RoutineDescription:
  376. Set the properties on this particular Pipe
  377. --*/
  378. BOOL __stdcall
  379. GenUSB_SetPipeProperties (
  380. IN HANDLE GenUSBDeviceObject,
  381. IN USBD_PIPE_HANDLE PipeHandle,
  382. IN PGENUSB_PIPE_PROPERTIES Properties
  383. );
  384. /*++
  385. GenUSB_ResetPipe
  386. RoutineDescription:
  387. Reset the pipe
  388. --*/
  389. BOOL __stdcall
  390. GenUSB_ResetPipe (
  391. IN HANDLE GenUSBDeviceObject,
  392. IN USBD_PIPE_HANDLE PipeHandle,
  393. // Reset USBD for this pipe (eg after a buffer overrun)
  394. IN BOOL ResetPipe,
  395. // Send a clear stall to the endpoint for this pipe
  396. IN BOOL ClearStall,
  397. // If you are using buffered reads / flush the pipe
  398. IN BOOL FlushData // Not yet implemented must be FALSE
  399. );
  400. /*++
  401. GenUSB_SetReadWritePipes
  402. Routine Description:
  403. Sets the pipes default for IRP_MJ_READ and IRP_MJ_WRITE to the generic USB
  404. driver
  405. Arguments:
  406. ReadPipe - the Pipe Handle (returned from GenUSB_GetPipeInformation)
  407. that corresponds to the specific read endpoint desired.
  408. Set to NULL if not using this value.
  409. WritePipe - the Pipe Handle (returned from GenUSB_GetPipeInformation)
  410. that corresponds to the specific write endpoint desired.
  411. Set to NULL if not using this value.
  412. --*/
  413. BOOL __stdcall
  414. GenUSB_SetReadWritePipes (
  415. IN HANDLE GenUSBDeviceObject,
  416. IN USBD_PIPE_HANDLE ReadPipe,
  417. IN USBD_PIPE_HANDLE WritePipe
  418. );
  419. /*++
  420. GenUSB_ReadPipe
  421. Routine Description:
  422. Read a chunk of data from a given interface and pipe on the device.
  423. Arguments:
  424. Pipe - the pipe handle to read from ( found from select config)
  425. ShortTransferOk - allow the USB protocol defined behavior of short
  426. transfers
  427. Buffer - the destination for the data
  428. RequestedBufferLength - how much data the caller wishes to retrieve
  429. ReturnedBufferLength - the amount of data actually read
  430. UrbStatus - the URB status code that the core usb stack returned for this
  431. transfer
  432. --*/
  433. BOOL __stdcall
  434. GenUSB_ReadPipe (
  435. IN HANDLE GenUSBDeviceObject,
  436. IN USBD_PIPE_HANDLE Pipe,
  437. IN BOOL ShortTransferOk,
  438. IN PVOID Buffer,
  439. IN ULONG RequestedBufferLength,
  440. OUT PULONG ReturnedBufferLength,
  441. OUT USBD_STATUS * UrbStatus
  442. );
  443. BOOL __stdcall
  444. GenUSB_WritePipe (
  445. IN HANDLE GenUSBDeviceObject,
  446. IN USBD_PIPE_HANDLE Pipe,
  447. IN BOOL ShortTransferOk,
  448. IN PVOID Buffer,
  449. IN ULONG RequestedBufferLength,
  450. OUT PULONG ReturnedBufferLength,
  451. OUT USBD_STATUS * UrbStatus
  452. );
  453. //
  454. // Set Idle
  455. // buffered read
  456. //
  457. // ????
  458. // overlapped read / write ioctls
  459. // Set Alternate Interfaces
  460. //
  461. #include <poppack.h>
  462. #endif //__GUSB_H_KERNEL_
  463. #endif // __GUSB_H_