PageRenderTime 51ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/libusbK/includes/libusbk.h

http://usb-travis.googlecode.com/
C Header | 2101 lines | 734 code | 422 blank | 945 comment | 5 complexity | 55180e509fbf0ff0065de404f6a34b43 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /*! \file libusbk.h
  2. * \brief functions for usb device communication.
  3. *
  4. * \note
  5. * This is the \b main libusbK USB user include file.
  6. */
  7. #ifndef _LIBUSBK_H__
  8. #define _LIBUSBK_H__
  9. #include "lusbk_shared.h"
  10. ///////////////////////////////////////////////////////////////////////
  11. // L I B U S B K PUBLIC STRUCTS, DEFINES, AND ENUMS //////////////////
  12. ///////////////////////////////////////////////////////////////////////
  13. #ifndef _LIBUSBK_LIBK_TYPES
  14. /*! \addtogroup libk
  15. * @{
  16. */
  17. #define _in
  18. #define _inopt
  19. #define _out
  20. #define _outopt
  21. #define _ref
  22. #define _refopt
  23. //! UsbK base function pointer, See \ref LibK_GetProcAddress.
  24. typedef INT_PTR (FAR WINAPI* KPROC)();
  25. //! Indicates that a function is an exported API call.
  26. #if defined(DYNAMIC_DLL)
  27. #define KUSB_EXP
  28. #else
  29. #define KUSB_EXP
  30. #endif
  31. //! Indicates the calling convention. This is always WINAPI (stdcall) by default.
  32. #if !defined(KUSB_API)
  33. #define KUSB_API WINAPI
  34. #endif
  35. #pragma warning(disable:4201)
  36. #if _MSC_VER >= 1200
  37. #pragma warning(push)
  38. #endif
  39. #pragma warning (disable:4201)
  40. #pragma warning(disable:4214) // named type definition in parentheses
  41. //! User defined handle context space, see \ref LibK_GetContext.
  42. typedef INT_PTR KLIB_USER_CONTEXT;
  43. //! KUSB control setup packet.
  44. /*!
  45. * This union structure is identical in size to a \ref WINUSB_SETUP_PACKET,
  46. * but provides additional field accessors. (see \ref libusbk.h for structure details)
  47. */
  48. typedef union _KUSB_SETUP_PACKET
  49. {
  50. UCHAR Bytes[8];
  51. USHORT Words[4];
  52. struct
  53. {
  54. //! Request value
  55. struct
  56. {
  57. UCHAR Recipient: 2;
  58. UCHAR Reserved: 3;
  59. UCHAR Type: 2;
  60. UCHAR Dir: 1;
  61. } BmRequest;
  62. //! Request type value
  63. UCHAR Request;
  64. //! wValue
  65. USHORT Value;
  66. //! wIndex
  67. USHORT Index;
  68. //! wLength ushort value
  69. USHORT Length;
  70. };
  71. struct
  72. {
  73. struct
  74. {
  75. UCHAR b0: 1;
  76. UCHAR b1: 1;
  77. UCHAR b2: 1;
  78. UCHAR b3: 1;
  79. UCHAR b4: 1;
  80. UCHAR b5: 1;
  81. UCHAR b6: 1;
  82. UCHAR b7: 1;
  83. } BmRequestBits;
  84. struct
  85. {
  86. UCHAR b0: 1;
  87. UCHAR b1: 1;
  88. UCHAR b2: 1;
  89. UCHAR b3: 1;
  90. UCHAR b4: 1;
  91. UCHAR b5: 1;
  92. UCHAR b6: 1;
  93. UCHAR b7: 1;
  94. } RequestBits;
  95. UCHAR ValueLo;
  96. UCHAR ValueHi;
  97. UCHAR IndexLo;
  98. UCHAR IndexHi;
  99. UCHAR LengthLo;
  100. UCHAR LengthHi;
  101. };
  102. } KUSB_SETUP_PACKET;
  103. // setup packet is eight bytes -- defined by spec
  104. C_ASSERT(sizeof(KUSB_SETUP_PACKET) == 8);
  105. #if _MSC_VER >= 1200
  106. #pragma warning(pop)
  107. #endif
  108. //! Base handle type for all library handles, See \ref KLIB_HANDLE_TYPE.
  109. typedef void* KLIB_HANDLE;
  110. //! Opaque UsbK handle, see \ref UsbK_Init.
  111. typedef KLIB_HANDLE KUSB_HANDLE;
  112. //! Opaque LstK handle, see \ref LstK_Init.
  113. typedef KLIB_HANDLE KLST_HANDLE;
  114. //! Opaque HotK handle, see \ref HotK_Init.
  115. typedef KLIB_HANDLE KHOT_HANDLE;
  116. //! Opaque OvlK handle, see \ref OvlK_Acquire.
  117. typedef KLIB_HANDLE KOVL_HANDLE;
  118. //! Opaque OvlPoolK handle, see \ref OvlK_Init.
  119. typedef KLIB_HANDLE KOVL_POOL_HANDLE;
  120. //! Opaque StmK handle, see \ref StmK_Init.
  121. typedef KLIB_HANDLE KSTM_HANDLE;
  122. //! Handle type enumeration.
  123. typedef enum _KLIB_HANDLE_TYPE
  124. {
  125. //! Hot plug handle. \ref KHOT_HANDLE
  126. KLIB_HANDLE_TYPE_HOTK,
  127. //! USB handle. \ref KUSB_HANDLE
  128. KLIB_HANDLE_TYPE_USBK,
  129. //! Shared USB handle. \ref KUSB_HANDLE
  130. KLIB_HANDLE_TYPE_USBSHAREDK,
  131. //! Device list handle. \ref KLST_HANDLE
  132. KLIB_HANDLE_TYPE_LSTK,
  133. //! Device info handle. \ref KLST_DEVINFO_HANDLE
  134. KLIB_HANDLE_TYPE_LSTINFOK,
  135. //! Overlapped handle. \ref KOVL_HANDLE
  136. KLIB_HANDLE_TYPE_OVLK,
  137. //! Overlapped pool handle. \ref KOVL_POOL_HANDLE
  138. KLIB_HANDLE_TYPE_OVLPOOLK,
  139. //! Pipe stream handle. \ref KSTM_HANDLE
  140. KLIB_HANDLE_TYPE_STMK,
  141. //! Max handle type count.
  142. KLIB_HANDLE_TYPE_COUNT
  143. } KLIB_HANDLE_TYPE;
  144. //! Function typedef for \ref LibK_SetCleanupCallback.
  145. typedef INT KUSB_API KLIB_HANDLE_CLEANUP_CB (_in KLIB_HANDLE Handle, _in KLIB_HANDLE_TYPE HandleType, _in KLIB_USER_CONTEXT UserContext);
  146. //! libusbK verson information structure.
  147. typedef struct _KLIB_VERSION
  148. {
  149. //! Major version number.
  150. INT Major;
  151. //! Minor version number.
  152. INT Minor;
  153. //! Micro version number.
  154. INT Micro;
  155. //! Nano version number.
  156. INT Nano;
  157. } KLIB_VERSION;
  158. //! Pointer to a \copybrief KLIB_VERSION
  159. typedef KLIB_VERSION* PKLIB_VERSION;
  160. /*! @} */
  161. #endif
  162. #ifndef _LIBUSBK_ISOK_TYPES
  163. /*! \addtogroup isok
  164. * @{
  165. */
  166. //! Callback function typedef for \ref IsoK_EnumPackets
  167. typedef BOOL KUSB_API KISO_ENUM_PACKETS_CB (_in UINT PacketIndex, _in PKISO_PACKET IsoPacket, _in PVOID UserState);
  168. /*! @} */
  169. #endif
  170. #ifndef _LIBUSBK_LSTK_TYPES
  171. /*! \addtogroup lstk
  172. * @{
  173. */
  174. //! Allocated length for all strings in a \ref KLST_DEVINFO structure.
  175. #define KLST_STRING_MAX_LEN 256
  176. //! Device list sync flags.
  177. /*!
  178. * These sync flags are also use by the hot plug module to indicate device
  179. * arrival/removal notifications:
  180. * - \b DeviceArrival = KLST_SYNC_FLAG_ADDED
  181. * - \b DeviceRemoval = KLST_SYNC_FLAG_REMOVED
  182. */
  183. typedef enum _KLST_SYNC_FLAG
  184. {
  185. //! Cleared/invalid state.
  186. KLST_SYNC_FLAG_NONE = 0L,
  187. //! Unchanged state,
  188. KLST_SYNC_FLAG_UNCHANGED = 0x0001,
  189. //! Added (Arrival) state,
  190. KLST_SYNC_FLAG_ADDED = 0x0002,
  191. //! Removed (Unplugged) state,
  192. KLST_SYNC_FLAG_REMOVED = 0x0004,
  193. //! Connect changed state.
  194. KLST_SYNC_FLAG_CONNECT_CHANGE = 0x0008,
  195. //! All states.
  196. KLST_SYNC_FLAG_MASK = 0x000F,
  197. } KLST_SYNC_FLAG;
  198. //! Common usb device information structure
  199. typedef struct _KLST_DEV_COMMON_INFO
  200. {
  201. //! VendorID parsed from \ref KLST_DEVINFO::DeviceID
  202. INT Vid;
  203. //! ProductID parsed from \ref KLST_DEVINFO::DeviceID
  204. INT Pid;
  205. //! Composite interface number parsed from \ref KLST_DEVINFO::DeviceID. Set to \b -1 for devices that do not have the composite parent driver.
  206. INT MI;
  207. // An ID that uniquely identifies a USB device.
  208. CHAR InstanceID[KLST_STRING_MAX_LEN];
  209. } KLST_DEV_COMMON_INFO;
  210. //! Pointer to a \c KLST_DEV_COMMON_INFO structure.
  211. typedef KLST_DEV_COMMON_INFO* PKLST_DEV_COMMON_INFO;
  212. //! Semi-opaque device information structure of a device list.
  213. /*!
  214. *
  215. * \attention This structure is semi-opaque.
  216. *
  217. */
  218. typedef struct _KLST_DEVINFO
  219. {
  220. //! Common usb device information
  221. KLST_DEV_COMMON_INFO Common;
  222. //! Driver id this device element is using
  223. INT DriverID;
  224. //! Device interface GUID
  225. CHAR DeviceInterfaceGUID[KLST_STRING_MAX_LEN];
  226. //! Device instance ID.
  227. /*!
  228. * A Device instance ID has the following format:
  229. * [enumerator]\[enumerator-specific-device-ID]\[instance-specific-ID]
  230. * - [enumerator]
  231. * - For USB device, the enumerator is always \c USB
  232. * - [enumerator-specific-device-ID]
  233. * - Contains the vendor and product id (VID_xxxx&PID_xxxx)
  234. * - If present, contains the usbccgp (windows composite device layer) interface number (MI_xx)
  235. * - [instance-specific-ID]
  236. * - If the device is composite, contains a unique interface ID generated by Windows.
  237. * - If the device is not composite and has a serial number, contains the devices serial number.
  238. * - If the device does not have a serial number, contains a unique ID generated by Windows.
  239. */
  240. CHAR DeviceID[KLST_STRING_MAX_LEN];
  241. //! Class GUID.
  242. CHAR ClassGUID[KLST_STRING_MAX_LEN];
  243. //! Manufacturer name as specified in the INF file.
  244. CHAR Mfg[KLST_STRING_MAX_LEN];
  245. //! Device description as specified in the INF file.
  246. CHAR DeviceDesc[KLST_STRING_MAX_LEN];
  247. //! Driver service name.
  248. CHAR Service[KLST_STRING_MAX_LEN];
  249. //! Unique identifier.
  250. CHAR SymbolicLink[KLST_STRING_MAX_LEN];
  251. //! physical device filename used with the Windows \c CreateFile()
  252. CHAR DevicePath[KLST_STRING_MAX_LEN];
  253. //! libusb-win32 filter index id.
  254. INT LUsb0FilterIndex;
  255. //! Indicates the devices connection state.
  256. BOOL Connected;
  257. //! Synchronization flags. (internal use only)
  258. KLST_SYNC_FLAG SyncFlags;
  259. INT BusNumber;
  260. INT DeviceAddress;
  261. //! If the the device is serialized, represents the string value of \ref USB_DEVICE_DESCRIPTOR::iSerialNumber. For Devices without a \b iSerialNumber, represents the unique \b InstanceID assigned by \b Windows.
  262. CHAR SerialNumber[KLST_STRING_MAX_LEN];
  263. } KLST_DEVINFO;
  264. //! Pointer to a \ref KLST_DEVINFO structure. (semi-opaque)
  265. typedef KLST_DEVINFO* KLST_DEVINFO_HANDLE;
  266. //! Device list initialization flags.
  267. typedef enum _KLST_FLAG
  268. {
  269. //! No flags (or 0)
  270. KLST_FLAG_NONE = 0L,
  271. //! Enable listings for the raw device interface GUID \b only. {A5DCBF10-6530-11D2-901F-00C04FB951ED}
  272. KLST_FLAG_INCLUDE_RAWGUID = 0x0001,
  273. //! List all libusbK devices including those not currently connected.
  274. KLST_FLAG_INCLUDE_DISCONNECT = 0x0002,
  275. } KLST_FLAG;
  276. //! Device list/hot-plug pattern match structure.
  277. /*!
  278. * \fixedstruct{1024}
  279. *
  280. * These ansi char strings are used to specify which devices should be included in a device list.
  281. * All strings file pattern match strings allowing asterisk or question mark chars as wildcards.
  282. *
  283. */
  284. typedef struct _KLST_PATTERN_MATCH
  285. {
  286. //! Pattern match a device instance id.
  287. CHAR DeviceID[KLST_STRING_MAX_LEN];
  288. //! Pattern match a device interface guid.
  289. CHAR DeviceInterfaceGUID[KLST_STRING_MAX_LEN];
  290. //! Pattern match a symbolic link.
  291. CHAR ClassGUID[KLST_STRING_MAX_LEN];
  292. //! fixed structure padding.
  293. UCHAR z_F_i_x_e_d[1024 - KLST_STRING_MAX_LEN * 3];
  294. } KLST_PATTERN_MATCH;
  295. C_ASSERT(sizeof(KLST_PATTERN_MATCH) == 1024);
  296. //! Pointer to a \ref KLST_PATTERN_MATCH structure.
  297. typedef KLST_PATTERN_MATCH* PKLST_PATTERN_MATCH;
  298. //! Device list enumeration function callback typedef.
  299. /*!
  300. *
  301. * \param DeviceList
  302. * The device list \c DeviceInfo belongs to
  303. *
  304. * \param DeviceInfo
  305. * Device information
  306. *
  307. * \param Context
  308. * User context that was passed into \ref LstK_Enumerate
  309. *
  310. * Use this typedef as a prototype for an enumeration function with \ref LstK_Enumerate.
  311. *
  312. */
  313. typedef BOOL KUSB_API KLST_ENUM_DEVINFO_CB (
  314. _in KLST_HANDLE DeviceList,
  315. _in KLST_DEVINFO_HANDLE DeviceInfo,
  316. _in PVOID Context);
  317. /*! @} */
  318. #endif
  319. #ifndef __USB_H__
  320. #include <pshpack1.h>
  321. /*! \addtogroup libk
  322. * @{
  323. */
  324. //! Maximum value that can be added to the current start frame.
  325. #define USBD_ISO_START_FRAME_RANGE 1024
  326. //! bmRequest.Dir
  327. typedef enum _BMREQUEST_DIR
  328. {
  329. BMREQUEST_DIR_HOST_TO_DEVICE = 0,
  330. BMREQUEST_DIR_DEVICE_TO_HOST = 1,
  331. } BMREQUEST_DIR;
  332. //! bmRequest.Type
  333. typedef enum _BMREQUEST_TYPE
  334. {
  335. //! Standard request. See \ref USB_REQUEST_ENUM
  336. BMREQUEST_TYPE_STANDARD = 0,
  337. //! Class-specific request.
  338. BMREQUEST_TYPE_CLASS = 1,
  339. //! Vendor-specific request
  340. BMREQUEST_TYPE_VENDOR = 2,
  341. } BMREQUEST_TYPE;
  342. //! bmRequest.Recipient
  343. typedef enum _BMREQUEST_RECIPIENT
  344. {
  345. //! Request is for a device.
  346. BMREQUEST_RECIPIENT_DEVICE = 0,
  347. //! Request is for an interface of a device.
  348. BMREQUEST_RECIPIENT_INTERFACE = 1,
  349. //! Request is for an endpoint of a device.
  350. BMREQUEST_RECIPIENT_ENDPOINT = 2,
  351. //! Request is for a vendor-specific purpose.
  352. BMREQUEST_RECIPIENT_OTHER = 3,
  353. } BMREQUEST_RECIPIENT;
  354. //! Maximum length (in bytes) of a usb string. USB strings are always stored in wide-char format.
  355. #define MAXIMUM_USB_STRING_LENGTH 255
  356. //! Values for the bits returned by the \ref USB_REQUEST_GET_STATUS request.
  357. typedef enum _USB_GETSTATUS
  358. {
  359. //! Device is self powered
  360. USB_GETSTATUS_SELF_POWERED = 0x01,
  361. //! Device can wake the system from a low power/sleeping state.
  362. USB_GETSTATUS_REMOTE_WAKEUP_ENABLED = 0x02
  363. } USB_GETSTATUS;
  364. //! Standard USB descriptor types. For more information, see section 9-5 of the USB 3.0 specifications.
  365. typedef enum _USB_DESCRIPTOR_TYPE
  366. {
  367. //! Device descriptor type.
  368. USB_DESCRIPTOR_TYPE_DEVICE = 0x01,
  369. //! Configuration descriptor type.
  370. USB_DESCRIPTOR_TYPE_CONFIGURATION = 0x02,
  371. //! String descriptor type.
  372. USB_DESCRIPTOR_TYPE_STRING = 0x03,
  373. //! Interface descriptor type.
  374. USB_DESCRIPTOR_TYPE_INTERFACE = 0x04,
  375. //! Endpoint descriptor type.
  376. USB_DESCRIPTOR_TYPE_ENDPOINT = 0x05,
  377. //! Device qualifier descriptor type.
  378. USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER = 0x06,
  379. //! Config power descriptor type.
  380. USB_DESCRIPTOR_TYPE_CONFIG_POWER = 0x07,
  381. //! Interface power descriptor type.
  382. USB_DESCRIPTOR_TYPE_INTERFACE_POWER = 0x08,
  383. //! Interface association descriptor type.
  384. USB_DESCRIPTOR_TYPE_INTERFACE_ASSOCIATION = 0x0B,
  385. } USB_DESCRIPTOR_TYPE;
  386. //! Makes \c wValue for a \ref USB_REQUEST_GET_DESCRIPTOR or \ref USB_REQUEST_SET_DESCRIPTOR request.
  387. #define USB_DESCRIPTOR_MAKE_TYPE_AND_INDEX(d, i) \
  388. ((USHORT)((USHORT)d<<8 | i))
  389. //! Endpoint type mask for the \c bmAttributes field of a \ref USB_ENDPOINT_DESCRIPTOR
  390. #define USB_ENDPOINT_TYPE_MASK 0x03
  391. //! Indicates a control endpoint
  392. #define USB_ENDPOINT_TYPE_CONTROL 0x00
  393. //! Indicates an isochronous endpoint
  394. #define USB_ENDPOINT_TYPE_ISOCHRONOUS 0x01
  395. //! Indicates a bulk endpoint
  396. #define USB_ENDPOINT_TYPE_BULK 0x02
  397. //! Indicates an interrupt endpoint
  398. #define USB_ENDPOINT_TYPE_INTERRUPT 0x03
  399. //! Config power mask for the \c bmAttributes field of a \ref USB_CONFIGURATION_DESCRIPTOR
  400. #define USB_CONFIG_POWERED_MASK 0xc0
  401. //! Values used in the \c bmAttributes field of a \ref USB_CONFIGURATION_DESCRIPTOR
  402. enum USB_CONFIG_BM_ATTRIBUTE_ENUM
  403. {
  404. //! The device is powered by it's host.
  405. USB_CONFIG_BUS_POWERED = 0x80,
  406. //! The device has an external power source.
  407. USB_CONFIG_SELF_POWERED = 0x40,
  408. //! The device is capable of waking the the host from a low power/sleeping state.
  409. USB_CONFIG_REMOTE_WAKEUP = 0x20,
  410. };
  411. //! Endpoint direction mask for the \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR
  412. #define USB_ENDPOINT_DIRECTION_MASK 0x80
  413. //! Endpoint address mask for the \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR
  414. #define USB_ENDPOINT_ADDRESS_MASK 0x0F
  415. //! Tests the \c bEndpointAddress direction bit. TRUE if the endpoint address is an OUT endpoint. (HostToDevice, PC Write)
  416. /*!
  417. * \param addr \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR
  418. */
  419. #define USB_ENDPOINT_DIRECTION_OUT(addr) (!((addr) & USB_ENDPOINT_DIRECTION_MASK))
  420. //! Tests the \c bEndpointAddress direction bit. TRUE if the endpoint address is an IN endpoint. (DeviceToHost, PC Read)
  421. /*!
  422. * \param addr \c bEndpointAddress field of a \ref USB_ENDPOINT_DESCRIPTOR
  423. */
  424. #define USB_ENDPOINT_DIRECTION_IN(addr) ((addr) & USB_ENDPOINT_DIRECTION_MASK)
  425. //! USB defined request codes
  426. /*
  427. * see Chapter 9 of the USB 2.0 specification for
  428. * more information.
  429. *
  430. * These are the correct values based on the USB 2.0 specification.
  431. */
  432. enum USB_REQUEST_ENUM
  433. {
  434. //! Request status of the specific recipient
  435. USB_REQUEST_GET_STATUS = 0x00,
  436. //! Clear or disable a specific feature
  437. USB_REQUEST_CLEAR_FEATURE = 0x01,
  438. //! Set or enable a specific feature
  439. USB_REQUEST_SET_FEATURE = 0x03,
  440. //! Set device address for all future accesses
  441. USB_REQUEST_SET_ADDRESS = 0x05,
  442. //! Get the specified descriptor
  443. USB_REQUEST_GET_DESCRIPTOR = 0x06,
  444. //! Update existing descriptors or add new descriptors
  445. USB_REQUEST_SET_DESCRIPTOR = 0x07,
  446. //! Get the current device configuration value
  447. USB_REQUEST_GET_CONFIGURATION = 0x08,
  448. //! Set device configuration
  449. USB_REQUEST_SET_CONFIGURATION = 0x09,
  450. //! Return the selected alternate setting for the specified interface
  451. USB_REQUEST_GET_INTERFACE = 0x0A,
  452. //! Select an alternate interface for the specified interface
  453. USB_REQUEST_SET_INTERFACE = 0x0B,
  454. //! Set then report an endpoint's synchronization frame
  455. USB_REQUEST_SYNC_FRAME = 0x0C,
  456. };
  457. //! USB defined class codes
  458. /*!
  459. * see http://www.usb.org/developers/defined_class for more information.
  460. *
  461. */
  462. enum USB_DEVICE_CLASS_ENUM
  463. {
  464. //! Reserved class
  465. USB_DEVICE_CLASS_RESERVED = 0x00,
  466. //! Audio class
  467. USB_DEVICE_CLASS_AUDIO = 0x01,
  468. //! Communications class
  469. USB_DEVICE_CLASS_COMMUNICATIONS = 0x02,
  470. //! Human Interface Device class
  471. USB_DEVICE_CLASS_HUMAN_INTERFACE = 0x03,
  472. //! Imaging class
  473. USB_DEVICE_CLASS_IMAGING = 0x06,
  474. //! Printer class
  475. USB_DEVICE_CLASS_PRINTER = 0x07,
  476. //! Mass storage class
  477. USB_DEVICE_CLASS_STORAGE = 0x08,
  478. //! Hub class
  479. USB_DEVICE_CLASS_HUB = 0x09,
  480. //! vendor-specific class
  481. USB_DEVICE_CLASS_VENDOR_SPECIFIC = 0xFF,
  482. };
  483. //! A structure representing the standard USB device descriptor.
  484. /*!
  485. * This descriptor is documented in section 9.6.1 of the USB 2.0 specification.
  486. * All multiple-byte fields are represented in host-endian format.
  487. */
  488. typedef struct _USB_DEVICE_DESCRIPTOR
  489. {
  490. //! Size of this descriptor (in bytes)
  491. UCHAR bLength;
  492. //! Descriptor type
  493. UCHAR bDescriptorType;
  494. //! USB specification release number in binary-coded decimal.
  495. /*!
  496. * A value of 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc.
  497. */
  498. USHORT bcdUSB;
  499. //! USB-IF class code for the device
  500. UCHAR bDeviceClass;
  501. //! USB-IF subclass code for the device
  502. UCHAR bDeviceSubClass;
  503. //! USB-IF protocol code for the device
  504. UCHAR bDeviceProtocol;
  505. //! Maximum packet size for control endpoint 0
  506. UCHAR bMaxPacketSize0;
  507. //! USB-IF vendor ID
  508. USHORT idVendor;
  509. //! USB-IF product ID
  510. USHORT idProduct;
  511. //! Device release number in binary-coded decimal
  512. USHORT bcdDevice;
  513. //! Index of string descriptor describing manufacturer
  514. UCHAR iManufacturer;
  515. //! Index of string descriptor describing product
  516. UCHAR iProduct;
  517. //! Index of string descriptor containing device serial number
  518. UCHAR iSerialNumber;
  519. //! Number of possible configurations
  520. UCHAR bNumConfigurations;
  521. } USB_DEVICE_DESCRIPTOR;
  522. //! pointer to a \c USB_DEVICE_DESCRIPTOR
  523. typedef USB_DEVICE_DESCRIPTOR* PUSB_DEVICE_DESCRIPTOR;
  524. //! A structure representing the standard USB endpoint descriptor.
  525. /*!
  526. * This descriptor is documented in section 9.6.3 of the USB 2.0 specification.
  527. * All multiple-byte fields are represented in host-endian format.
  528. */
  529. typedef struct _USB_ENDPOINT_DESCRIPTOR
  530. {
  531. //! Size of this descriptor (in bytes)
  532. UCHAR bLength;
  533. //! Descriptor type
  534. UCHAR bDescriptorType;
  535. //! The address of the endpoint described by this descriptor.
  536. /*!
  537. * - Bits 0:3 are the endpoint number
  538. * - Bits 4:6 are reserved
  539. * - Bit 7 indicates direction
  540. */
  541. UCHAR bEndpointAddress;
  542. //! Attributes which apply to the endpoint when it is configured using the bConfigurationValue.
  543. /*!
  544. * - Bits 0:1 determine the transfer type.
  545. * - Bits 2:3 are only used for isochronous endpoints and refer to sync type.
  546. * - Bits 4:5 are also only used for isochronous endpoints and refer to usage type.
  547. * - Bits 6:7 are reserved.
  548. */
  549. UCHAR bmAttributes;
  550. //! Maximum packet size this endpoint is capable of sending/receiving.
  551. USHORT wMaxPacketSize;
  552. //! Interval for polling endpoint for data transfers.
  553. UCHAR bInterval;
  554. } USB_ENDPOINT_DESCRIPTOR;
  555. //! pointer to a \c USB_ENDPOINT_DESCRIPTOR
  556. typedef USB_ENDPOINT_DESCRIPTOR* PUSB_ENDPOINT_DESCRIPTOR;
  557. //! A structure representing the standard USB configuration descriptor.
  558. /*
  559. *
  560. * This descriptor is documented in section 9.6.3 of the USB 2.0 specification.
  561. * All multiple-byte fields are represented in host-endian format.
  562. *
  563. */
  564. typedef struct _USB_CONFIGURATION_DESCRIPTOR
  565. {
  566. //! Size of this descriptor (in bytes)
  567. UCHAR bLength;
  568. //! Descriptor type
  569. UCHAR bDescriptorType;
  570. //! Total length of data returned for this configuration
  571. USHORT wTotalLength;
  572. //! Number of interfaces supported by this configuration
  573. UCHAR bNumInterfaces;
  574. //! Identifier value for this configuration
  575. UCHAR bConfigurationValue;
  576. //! Index of string descriptor describing this configuration
  577. UCHAR iConfiguration;
  578. //! Configuration characteristics
  579. UCHAR bmAttributes;
  580. //! Maximum power consumption of the USB device from this bus in this configuration when the device is fully operation.
  581. /*!
  582. * Expressed in units of 2 mA.
  583. */
  584. UCHAR MaxPower;
  585. } USB_CONFIGURATION_DESCRIPTOR;
  586. //! pointer to a \c USB_CONFIGURATION_DESCRIPTOR
  587. typedef USB_CONFIGURATION_DESCRIPTOR* PUSB_CONFIGURATION_DESCRIPTOR;
  588. //! A structure representing the standard USB interface descriptor.
  589. /*!
  590. * This descriptor is documented in section 9.6.5 of the USB 2.0 specification.
  591. * All multiple-byte fields are represented in host-endian format.
  592. */
  593. typedef struct _USB_INTERFACE_DESCRIPTOR
  594. {
  595. //! Size of this descriptor (in bytes)
  596. UCHAR bLength;
  597. //! Descriptor type
  598. UCHAR bDescriptorType;
  599. //! Number of this interface
  600. UCHAR bInterfaceNumber;
  601. //! Value used to select this alternate setting for this interface
  602. UCHAR bAlternateSetting;
  603. //! Number of endpoints used by this interface (excluding the control endpoint)
  604. UCHAR bNumEndpoints;
  605. //! USB-IF class code for this interface
  606. UCHAR bInterfaceClass;
  607. //! USB-IF subclass code for this interface
  608. UCHAR bInterfaceSubClass;
  609. //! USB-IF protocol code for this interface
  610. UCHAR bInterfaceProtocol;
  611. //! Index of string descriptor describing this interface
  612. UCHAR iInterface;
  613. } USB_INTERFACE_DESCRIPTOR;
  614. //! pointer to a \c USB_INTERFACE_DESCRIPTOR
  615. typedef USB_INTERFACE_DESCRIPTOR* PUSB_INTERFACE_DESCRIPTOR;
  616. //! A structure representing the standard USB string descriptor.
  617. /*!
  618. * This descriptor is documented in section 9.6.5 of the USB 2.0 specification.
  619. * All multiple-byte fields are represented in host-endian format.
  620. */
  621. typedef struct _USB_STRING_DESCRIPTOR
  622. {
  623. //! Size of this descriptor (in bytes)
  624. UCHAR bLength;
  625. //! Descriptor type
  626. UCHAR bDescriptorType;
  627. //! Content of the string
  628. WCHAR bString[1];
  629. } USB_STRING_DESCRIPTOR;
  630. //! pointer to a \c USB_STRING_DESCRIPTOR
  631. typedef USB_STRING_DESCRIPTOR* PUSB_STRING_DESCRIPTOR;
  632. //! A structure representing the common USB descriptor.
  633. typedef struct _USB_COMMON_DESCRIPTOR
  634. {
  635. //! Size of this descriptor (in bytes)
  636. UCHAR bLength;
  637. //! Descriptor type
  638. UCHAR bDescriptorType;
  639. } USB_COMMON_DESCRIPTOR;
  640. //! pointer to a \c USB_COMMON_DESCRIPTOR
  641. typedef USB_COMMON_DESCRIPTOR* PUSB_COMMON_DESCRIPTOR;
  642. #if _MSC_VER >= 1200
  643. #pragma warning(push)
  644. #endif
  645. #pragma warning (disable:4201)
  646. #pragma warning(disable:4214) // named type definition in parentheses
  647. //! Allows hardware manufacturers to define groupings of interfaces.
  648. /*!
  649. *
  650. * The ECN specifies a USB descriptor, called the Interface Association
  651. * Descriptor (IAD).
  652. *
  653. * The Universal Serial Bus Specification, revision 2.0, does not support
  654. * grouping more than one interface of a composite device within a single
  655. * function. However, the USB Device Working Group (DWG) created USB device
  656. * classes that allow for functions with multiple interfaces, and the USB
  657. * Implementor's Forum issued an Engineering Change Notification (ECN) that
  658. * defines a mechanism for grouping interfaces.
  659. *
  660. */
  661. typedef struct _USB_INTERFACE_ASSOCIATION_DESCRIPTOR
  662. {
  663. //! Size of this descriptor (in bytes)
  664. UCHAR bLength;
  665. //! Descriptor type
  666. UCHAR bDescriptorType;
  667. //! First interface number of the set of interfaces that follow this descriptor
  668. UCHAR bFirstInterface;
  669. //! The Number of interfaces follow this descriptor that are considered "associated"
  670. UCHAR bInterfaceCount;
  671. //! \c bInterfaceClass used for this associated interfaces
  672. UCHAR bFunctionClass;
  673. //! \c bInterfaceSubClass used for the associated interfaces
  674. UCHAR bFunctionSubClass;
  675. //! \c bInterfaceProtocol used for the associated interfaces
  676. UCHAR bFunctionProtocol;
  677. //! Index of string descriptor describing the associated interfaces
  678. UCHAR iFunction;
  679. } USB_INTERFACE_ASSOCIATION_DESCRIPTOR;
  680. //! pointer to a \c USB_INTERFACE_ASSOCIATION_DESCRIPTOR
  681. typedef USB_INTERFACE_ASSOCIATION_DESCRIPTOR* PUSB_INTERFACE_ASSOCIATION_DESCRIPTOR;
  682. #if _MSC_VER >= 1200
  683. #pragma warning(pop)
  684. #endif
  685. /*! @} */
  686. #include <poppack.h>
  687. #endif // __USB_H__
  688. #ifndef _LIBUSBK_LIBK_TYPES
  689. /*! \addtogroup libk
  690. * @{
  691. */
  692. //! Usb handle specific properties that can be retrieved with \ref UsbK_GetProperty.
  693. typedef enum _KUSB_PROPERTY
  694. {
  695. //! Get the internal device file handle used for operations such as GetOverlappedResult or DeviceIoControl.
  696. KUSB_PROPERTY_DEVICE_FILE_HANDLE,
  697. KUSB_PROPERTY_COUNT
  698. } KUSB_PROPERTY;
  699. //! Supported driver id enumeration.
  700. typedef enum _KUSB_DRVID
  701. {
  702. //! libusbK.sys driver ID
  703. KUSB_DRVID_LIBUSBK,
  704. //! libusb0.sys driver ID
  705. KUSB_DRVID_LIBUSB0,
  706. //! WinUSB.sys driver ID
  707. KUSB_DRVID_WINUSB,
  708. //! libusb0.sys filter driver ID
  709. KUSB_DRVID_LIBUSB0_FILTER,
  710. //! Supported driver count
  711. KUSB_DRVID_COUNT
  712. } KUSB_DRVID;
  713. //! Supported function id enumeration.
  714. typedef enum _KUSB_FNID
  715. {
  716. //! \ref UsbK_Init dynamic driver function id.
  717. KUSB_FNID_Init,
  718. //! \ref UsbK_Free dynamic driver function id.
  719. KUSB_FNID_Free,
  720. //! \ref UsbK_ClaimInterface dynamic driver function id.
  721. KUSB_FNID_ClaimInterface,
  722. //! \ref UsbK_ReleaseInterface dynamic driver function id.
  723. KUSB_FNID_ReleaseInterface,
  724. //! \ref UsbK_SetAltInterface dynamic driver function id.
  725. KUSB_FNID_SetAltInterface,
  726. //! \ref UsbK_GetAltInterface dynamic driver function id.
  727. KUSB_FNID_GetAltInterface,
  728. //! \ref UsbK_GetDescriptor dynamic driver function id.
  729. KUSB_FNID_GetDescriptor,
  730. //! \ref UsbK_ControlTransfer dynamic driver function id.
  731. KUSB_FNID_ControlTransfer,
  732. //! \ref UsbK_SetPowerPolicy dynamic driver function id.
  733. KUSB_FNID_SetPowerPolicy,
  734. //! \ref UsbK_GetPowerPolicy dynamic driver function id.
  735. KUSB_FNID_GetPowerPolicy,
  736. //! \ref UsbK_SetConfiguration dynamic driver function id.
  737. KUSB_FNID_SetConfiguration,
  738. //! \ref UsbK_GetConfiguration dynamic driver function id.
  739. KUSB_FNID_GetConfiguration,
  740. //! \ref UsbK_ResetDevice dynamic driver function id.
  741. KUSB_FNID_ResetDevice,
  742. //! \ref UsbK_Initialize dynamic driver function id.
  743. KUSB_FNID_Initialize,
  744. //! \ref UsbK_SelectInterface dynamic driver function id.
  745. KUSB_FNID_SelectInterface,
  746. //! \ref UsbK_GetAssociatedInterface dynamic driver function id.
  747. KUSB_FNID_GetAssociatedInterface,
  748. //! \ref UsbK_Clone dynamic driver function id.
  749. KUSB_FNID_Clone,
  750. //! \ref UsbK_QueryInterfaceSettings dynamic driver function id.
  751. KUSB_FNID_QueryInterfaceSettings,
  752. //! \ref UsbK_QueryDeviceInformation dynamic driver function id.
  753. KUSB_FNID_QueryDeviceInformation,
  754. //! \ref UsbK_SetCurrentAlternateSetting dynamic driver function id.
  755. KUSB_FNID_SetCurrentAlternateSetting,
  756. //! \ref UsbK_GetCurrentAlternateSetting dynamic driver function id.
  757. KUSB_FNID_GetCurrentAlternateSetting,
  758. //! \ref UsbK_QueryPipe dynamic driver function id.
  759. KUSB_FNID_QueryPipe,
  760. //! \ref UsbK_SetPipePolicy dynamic driver function id.
  761. KUSB_FNID_SetPipePolicy,
  762. //! \ref UsbK_GetPipePolicy dynamic driver function id.
  763. KUSB_FNID_GetPipePolicy,
  764. //! \ref UsbK_ReadPipe dynamic driver function id.
  765. KUSB_FNID_ReadPipe,
  766. //! \ref UsbK_WritePipe dynamic driver function id.
  767. KUSB_FNID_WritePipe,
  768. //! \ref UsbK_ResetPipe dynamic driver function id.
  769. KUSB_FNID_ResetPipe,
  770. //! \ref UsbK_AbortPipe dynamic driver function id.
  771. KUSB_FNID_AbortPipe,
  772. //! \ref UsbK_FlushPipe dynamic driver function id.
  773. KUSB_FNID_FlushPipe,
  774. //! \ref UsbK_IsoReadPipe dynamic driver function id.
  775. KUSB_FNID_IsoReadPipe,
  776. //! \ref UsbK_IsoWritePipe dynamic driver function id.
  777. KUSB_FNID_IsoWritePipe,
  778. //! \ref UsbK_GetCurrentFrameNumber dynamic driver function id.
  779. KUSB_FNID_GetCurrentFrameNumber,
  780. //! \ref UsbK_GetOverlappedResult dynamic driver function id.
  781. KUSB_FNID_GetOverlappedResult,
  782. //! \ref UsbK_GetProperty dynamic driver function id.
  783. KUSB_FNID_GetProperty,
  784. //! Supported function count
  785. KUSB_FNID_COUNT,
  786. } KUSB_FNID;
  787. typedef BOOL KUSB_API KUSB_Init (
  788. _out KUSB_HANDLE* InterfaceHandle,
  789. _in KLST_DEVINFO_HANDLE DevInfo);
  790. typedef BOOL KUSB_API KUSB_Free (
  791. _in KUSB_HANDLE InterfaceHandle);
  792. typedef BOOL KUSB_API KUSB_ClaimInterface (
  793. _in KUSB_HANDLE InterfaceHandle,
  794. _in UCHAR NumberOrIndex,
  795. _in BOOL IsIndex);
  796. typedef BOOL KUSB_API KUSB_ReleaseInterface (
  797. _in KUSB_HANDLE InterfaceHandle,
  798. _in UCHAR NumberOrIndex,
  799. _in BOOL IsIndex);
  800. typedef BOOL KUSB_API KUSB_SetAltInterface (
  801. _in KUSB_HANDLE InterfaceHandle,
  802. _in UCHAR NumberOrIndex,
  803. _in BOOL IsIndex,
  804. _in UCHAR AltSettingNumber);
  805. typedef BOOL KUSB_API KUSB_GetAltInterface (
  806. _in KUSB_HANDLE InterfaceHandle,
  807. _in UCHAR NumberOrIndex,
  808. _in BOOL IsIndex,
  809. _out PUCHAR AltSettingNumber);
  810. typedef BOOL KUSB_API KUSB_GetDescriptor (
  811. _in KUSB_HANDLE InterfaceHandle,
  812. _in UCHAR DescriptorType,
  813. _in UCHAR Index,
  814. _in USHORT LanguageID,
  815. _out PUCHAR Buffer,
  816. _in UINT BufferLength,
  817. _outopt PUINT LengthTransferred);
  818. typedef BOOL KUSB_API KUSB_ControlTransfer (
  819. _in KUSB_HANDLE InterfaceHandle,
  820. _in WINUSB_SETUP_PACKET SetupPacket,
  821. _refopt PUCHAR Buffer,
  822. _in UINT BufferLength,
  823. _outopt PUINT LengthTransferred,
  824. _inopt LPOVERLAPPED Overlapped);
  825. typedef BOOL KUSB_API KUSB_SetPowerPolicy (
  826. _in KUSB_HANDLE InterfaceHandle,
  827. _in UINT PolicyType,
  828. _in UINT ValueLength,
  829. _in PVOID Value);
  830. typedef BOOL KUSB_API KUSB_GetPowerPolicy (
  831. _in KUSB_HANDLE InterfaceHandle,
  832. _in UINT PolicyType,
  833. _ref PUINT ValueLength,
  834. _out PVOID Value);
  835. typedef BOOL KUSB_API KUSB_SetConfiguration (
  836. _in KUSB_HANDLE InterfaceHandle,
  837. _in UCHAR ConfigurationNumber);
  838. typedef BOOL KUSB_API KUSB_GetConfiguration (
  839. _in KUSB_HANDLE InterfaceHandle,
  840. _out PUCHAR ConfigurationNumber);
  841. typedef BOOL KUSB_API KUSB_ResetDevice (
  842. _in KUSB_HANDLE InterfaceHandle);
  843. typedef BOOL KUSB_API KUSB_Initialize (
  844. _in HANDLE DeviceHandle,
  845. _out KUSB_HANDLE* InterfaceHandle);
  846. typedef BOOL KUSB_API KUSB_SelectInterface (
  847. _in KUSB_HANDLE InterfaceHandle,
  848. _in UCHAR NumberOrIndex,
  849. _in BOOL IsIndex);
  850. typedef BOOL KUSB_API KUSB_GetAssociatedInterface (
  851. _in KUSB_HANDLE InterfaceHandle,
  852. _in UCHAR AssociatedInterfaceIndex,
  853. _out KUSB_HANDLE* AssociatedInterfaceHandle);
  854. typedef BOOL KUSB_API KUSB_Clone (
  855. _in KUSB_HANDLE InterfaceHandle,
  856. _out KUSB_HANDLE* DstInterfaceHandle);
  857. typedef BOOL KUSB_API KUSB_QueryInterfaceSettings (
  858. _in KUSB_HANDLE InterfaceHandle,
  859. _in UCHAR AltSettingIndex,
  860. _out PUSB_INTERFACE_DESCRIPTOR UsbAltInterfaceDescriptor);
  861. typedef BOOL KUSB_API KUSB_QueryDeviceInformation (
  862. _in KUSB_HANDLE InterfaceHandle,
  863. _in UINT InformationType,
  864. _ref PUINT BufferLength,
  865. _ref PVOID Buffer);
  866. typedef BOOL KUSB_API KUSB_SetCurrentAlternateSetting (
  867. _in KUSB_HANDLE InterfaceHandle,
  868. _in UCHAR AltSettingNumber);
  869. typedef BOOL KUSB_API KUSB_GetCurrentAlternateSetting (
  870. _in KUSB_HANDLE InterfaceHandle,
  871. _out PUCHAR AltSettingNumber);
  872. typedef BOOL KUSB_API KUSB_QueryPipe (
  873. _in KUSB_HANDLE InterfaceHandle,
  874. _in UCHAR AltSettingNumber,
  875. _in UCHAR PipeIndex,
  876. _out PWINUSB_PIPE_INFORMATION PipeInformation);
  877. typedef BOOL KUSB_API KUSB_SetPipePolicy (
  878. _in KUSB_HANDLE InterfaceHandle,
  879. _in UCHAR PipeID,
  880. _in UINT PolicyType,
  881. _in UINT ValueLength,
  882. _in PVOID Value);
  883. typedef BOOL KUSB_API KUSB_GetPipePolicy (
  884. _in KUSB_HANDLE InterfaceHandle,
  885. _in UCHAR PipeID,
  886. _in UINT PolicyType,
  887. _ref PUINT ValueLength,
  888. _out PVOID Value);
  889. typedef BOOL KUSB_API KUSB_ReadPipe (
  890. _in KUSB_HANDLE InterfaceHandle,
  891. _in UCHAR PipeID,
  892. _out PUCHAR Buffer,
  893. _in UINT BufferLength,
  894. _outopt PUINT LengthTransferred,
  895. _inopt LPOVERLAPPED Overlapped);
  896. typedef BOOL KUSB_API KUSB_WritePipe (
  897. _in KUSB_HANDLE InterfaceHandle,
  898. _in UCHAR PipeID,
  899. _in PUCHAR Buffer,
  900. _in UINT BufferLength,
  901. _outopt PUINT LengthTransferred,
  902. _inopt LPOVERLAPPED Overlapped);
  903. typedef BOOL KUSB_API KUSB_ResetPipe (
  904. _in KUSB_HANDLE InterfaceHandle,
  905. _in UCHAR PipeID);
  906. typedef BOOL KUSB_API KUSB_AbortPipe (
  907. _in KUSB_HANDLE InterfaceHandle,
  908. _in UCHAR PipeID);
  909. typedef BOOL KUSB_API KUSB_FlushPipe (
  910. _in KUSB_HANDLE InterfaceHandle,
  911. _in UCHAR PipeID);
  912. typedef BOOL KUSB_API KUSB_IsoReadPipe (
  913. _in KUSB_HANDLE InterfaceHandle,
  914. _in UCHAR PipeID,
  915. _out PUCHAR Buffer,
  916. _in UINT BufferLength,
  917. _in LPOVERLAPPED Overlapped,
  918. _refopt PKISO_CONTEXT IsoContext);
  919. typedef BOOL KUSB_API KUSB_IsoWritePipe (
  920. _in KUSB_HANDLE InterfaceHandle,
  921. _in UCHAR PipeID,
  922. _in PUCHAR Buffer,
  923. _in UINT BufferLength,
  924. _in LPOVERLAPPED Overlapped,
  925. _refopt PKISO_CONTEXT IsoContext);
  926. typedef BOOL KUSB_API KUSB_GetCurrentFrameNumber (
  927. _in KUSB_HANDLE InterfaceHandle,
  928. _out PUINT FrameNumber);
  929. typedef BOOL KUSB_API KUSB_GetOverlappedResult (
  930. _in KUSB_HANDLE InterfaceHandle,
  931. _in LPOVERLAPPED Overlapped,
  932. _out PUINT lpNumberOfBytesTransferred,
  933. _in BOOL bWait);
  934. typedef BOOL KUSB_API KUSB_GetProperty (
  935. _in KUSB_HANDLE InterfaceHandle,
  936. _in KUSB_PROPERTY PropertyType,
  937. _ref PUINT PropertySize,
  938. _out PVOID Value);
  939. //! USB core driver API information structure.
  940. /*!
  941. * This structure is part of \ref KUSB_DRIVER_API and contains
  942. * driver and user specific information.
  943. *
  944. */
  945. typedef struct _KUSB_DRIVER_API_INFO
  946. {
  947. //! \readonly Driver id of the driver api.
  948. INT DriverID;
  949. //! \readonly Number of valid functions contained in the driver API.
  950. INT FunctionCount;
  951. } KUSB_DRIVER_API_INFO;
  952. //! Driver API function set structure.
  953. /*
  954. * Contains the driver specific USB core function pointer set.
  955. *
  956. * \note
  957. * This structure has a fixed 512 byte structure size.
  958. */
  959. typedef struct _KUSB_DRIVER_API
  960. {
  961. //! Driver API information.
  962. KUSB_DRIVER_API_INFO Info;
  963. /*! \fn BOOL KUSB_API Init (_out KUSB_HANDLE* InterfaceHandle, _in KLST_DEVINFO_HANDLE DevInfo)
  964. * \memberof KUSB_DRIVER_API
  965. * \copydoc UsbK_Init
  966. */
  967. KUSB_Init* Init;
  968. /*! \fn BOOL KUSB_API Free (_in KUSB_HANDLE InterfaceHandle)
  969. * \memberof KUSB_DRIVER_API
  970. * \copydoc UsbK_Free
  971. */
  972. KUSB_Free* Free;
  973. /*! \fn BOOL KUSB_API ClaimInterface (_in KUSB_HANDLE InterfaceHandle, _in UCHAR NumberOrIndex, _in BOOL IsIndex)
  974. * \memberof KUSB_DRIVER_API
  975. * \copydoc UsbK_ClaimInterface
  976. */
  977. KUSB_ClaimInterface* ClaimInterface;
  978. /*! \fn BOOL KUSB_API ReleaseInterface (_in KUSB_HANDLE InterfaceHandle, _in UCHAR NumberOrIndex, _in BOOL IsIndex)
  979. * \memberof KUSB_DRIVER_API
  980. * \copydoc UsbK_ReleaseInterface
  981. */
  982. KUSB_ReleaseInterface* ReleaseInterface;
  983. /*! \fn BOOL KUSB_API SetAltInterface (_in KUSB_HANDLE InterfaceHandle, _in UCHAR NumberOrIndex, _in BOOL IsIndex, _in UCHAR AltSettingNumber)
  984. * \memberof KUSB_DRIVER_API
  985. * \copydoc UsbK_SetAltInterface
  986. */
  987. KUSB_SetAltInterface* SetAltInterface;
  988. /*! \fn BOOL KUSB_API GetAltInterface (_in KUSB_HANDLE InterfaceHandle, _in UCHAR NumberOrIndex, _in BOOL IsIndex, _out PUCHAR AltSettingNumber)
  989. * \memberof KUSB_DRIVER_API
  990. * \copydoc UsbK_GetAltInterface
  991. */
  992. KUSB_GetAltInterface* GetAltInterface;
  993. /*! \fn BOOL KUSB_API GetDescriptor (_in KUSB_HANDLE InterfaceHandle, _in UCHAR DescriptorType, _in UCHAR Index, _in USHORT LanguageID, _out PUCHAR Buffer, _in UINT BufferLength, _outopt PUINT LengthTransferred)
  994. * \memberof KUSB_DRIVER_API
  995. * \copydoc UsbK_GetDescriptor
  996. */
  997. KUSB_GetDescriptor* GetDescriptor;
  998. /*! \fn BOOL KUSB_API ControlTransfer (_in KUSB_HANDLE InterfaceHandle, _in WINUSB_SETUP_PACKET SetupPacket, _refopt PUCHAR Buffer, _in UINT BufferLength, _outopt PUINT LengthTransferred, _inopt LPOVERLAPPED Overlapped)
  999. * \memberof KUSB_DRIVER_API
  1000. * \copydoc UsbK_ControlTransfer
  1001. */
  1002. KUSB_ControlTransfer* ControlTransfer;
  1003. /*! \fn BOOL KUSB_API SetPowerPolicy (_in KUSB_HANDLE InterfaceHandle, _in UINT PolicyType, _in UINT ValueLength, _in PVOID Value)
  1004. * \memberof KUSB_DRIVER_API
  1005. * \copydoc UsbK_SetPowerPolicy
  1006. */
  1007. KUSB_SetPowerPolicy* SetPowerPolicy;
  1008. /*! \fn BOOL KUSB_API GetPowerPolicy (_in KUSB_HANDLE InterfaceHandle, _in UINT PolicyType, _ref PUINT ValueLength, _out PVOID Value)
  1009. * \memberof KUSB_DRIVER_API
  1010. * \copydoc UsbK_GetPowerPolicy
  1011. */
  1012. KUSB_GetPowerPolicy* GetPowerPolicy;
  1013. /*! \fn BOOL KUSB_API SetConfiguration (_in KUSB_HANDLE InterfaceHandle, _in UCHAR ConfigurationNumber)
  1014. * \memberof KUSB_DRIVER_API
  1015. * \copydoc UsbK_SetConfiguration
  1016. */
  1017. KUSB_SetConfiguration* SetConfiguration;
  1018. /*! \fn BOOL KUSB_API GetConfiguration (_in KUSB_HANDLE InterfaceHandle, _out PUCHAR ConfigurationNumber)
  1019. * \memberof KUSB_DRIVER_API
  1020. * \copydoc UsbK_GetConfiguration
  1021. */
  1022. KUSB_GetConfiguration* GetConfiguration;
  1023. /*! \fn BOOL KUSB_API ResetDevice (_in KUSB_HANDLE InterfaceHandle)
  1024. * \memberof KUSB_DRIVER_API
  1025. * \copydoc UsbK_ResetDevice
  1026. */
  1027. KUSB_ResetDevice* ResetDevice;
  1028. /*! \fn BOOL KUSB_API Initialize (_in HANDLE DeviceHandle, _out KUSB_HANDLE* InterfaceHandle)
  1029. * \memberof KUSB_DRIVER_API
  1030. * \copydoc UsbK_Initialize
  1031. */
  1032. KUSB_Initialize* Initialize;
  1033. /*! \fn BOOL KUSB_API SelectInterface (_in KUSB_HANDLE InterfaceHandle, _in UCHAR NumberOrIndex, _in BOOL IsIndex)
  1034. * \memberof KUSB_DRIVER_API
  1035. * \copydoc UsbK_SelectInterface
  1036. */
  1037. KUSB_SelectInterface* SelectInterface;
  1038. /*! \fn BOOL KUSB_API GetAssociatedInterface (_in KUSB_HANDLE InterfaceHandle, _in UCHAR AssociatedInterfaceIndex, _out KUSB_HANDLE* AssociatedInterfaceHandle)
  1039. * \memberof KUSB_DRIVER_API
  1040. * \copydoc UsbK_GetAssociatedInterface
  1041. */
  1042. KUSB_GetAssociatedInterface* GetAssociatedInterface;
  1043. /*! \fn BOOL KUSB_API Clone (_in KUSB_HANDLE InterfaceHandle, _out KUSB_HANDLE* DstInterfaceHandle)
  1044. * \memberof KUSB_DRIVER_API
  1045. * \copydoc UsbK_Clone
  1046. */
  1047. KUSB_Clone* Clone;
  1048. /*! \fn BOOL KUSB_API QueryInterfaceSettings (_in KUSB_HANDLE InterfaceHandle, _in UCHAR AltSettingIndex, _out PUSB_INTERFACE_DESCRIPTOR UsbAltInterfaceDescriptor)
  1049. * \memberof KUSB_DRIVER_API
  1050. * \copydoc UsbK_QueryInterfaceSettings
  1051. */
  1052. KUSB_QueryInterfaceSettings* QueryInterfaceSettings;
  1053. /*! \fn BOOL KUSB_API QueryDeviceInformation (_in KUSB_HANDLE InterfaceHandle, _in UINT InformationType, _ref PUINT BufferLength, _ref PVOID Buffer)
  1054. * \memberof KUSB_DRIVER_API
  1055. * \copydoc UsbK_QueryDeviceInformation
  1056. */
  1057. KUSB_QueryDeviceInformation* QueryDeviceInformation;
  1058. /*! \fn BOOL KUSB_API SetCurrentAlternateSetting (_in KUSB_HANDLE InterfaceHandle, _in UCHAR AltSettingNumber)
  1059. * \memberof KUSB_DRIVER_API
  1060. * \copydoc UsbK_SetCurrentAlternateSetting
  1061. */
  1062. KUSB_SetCurrentAlternateSetting* SetCurrentAlternateSetting;
  1063. /*! \fn BOOL KUSB_API GetCurrentAlternateSetting (_in KUSB_HANDLE InterfaceHandle, _out PUCHAR AltSettingNumber)
  1064. * \memberof KUSB_DRIVER_API
  1065. * \copydoc UsbK_GetCurrentAlternateSetting
  1066. */
  1067. KUSB_GetCurrentAlternateSetting* GetCurrentAlternateSetting;
  1068. /*! \fn BOOL KUSB_API QueryPipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR AltSettingNumber, _in UCHAR PipeIndex, _out PWINUSB_PIPE_INFORMATION PipeInformation)
  1069. * \memberof KUSB_DRIVER_API
  1070. * \copydoc UsbK_QueryPipe
  1071. */
  1072. KUSB_QueryPipe* QueryPipe;
  1073. /*! \fn BOOL KUSB_API SetPipePolicy (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID, _in UINT PolicyType, _in UINT ValueLength, _in PVOID Value)
  1074. * \memberof KUSB_DRIVER_API
  1075. * \copydoc UsbK_SetPipePolicy
  1076. */
  1077. KUSB_SetPipePolicy* SetPipePolicy;
  1078. /*! \fn BOOL KUSB_API GetPipePolicy (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID, _in UINT PolicyType, _ref PUINT ValueLength, _out PVOID Value)
  1079. * \memberof KUSB_DRIVER_API
  1080. * \copydoc UsbK_GetPipePolicy
  1081. */
  1082. KUSB_GetPipePolicy* GetPipePolicy;
  1083. /*! \fn BOOL KUSB_API ReadPipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID, _out PUCHAR Buffer, _in UINT BufferLength, _outopt PUINT LengthTransferred, _inopt LPOVERLAPPED Overlapped)
  1084. * \memberof KUSB_DRIVER_API
  1085. * \copydoc UsbK_ReadPipe
  1086. */
  1087. KUSB_ReadPipe* ReadPipe;
  1088. /*! \fn BOOL KUSB_API WritePipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID, _in PUCHAR Buffer, _in UINT BufferLength, _outopt PUINT LengthTransferred, _inopt LPOVERLAPPED Overlapped)
  1089. * \memberof KUSB_DRIVER_API
  1090. * \copydoc UsbK_WritePipe
  1091. */
  1092. KUSB_WritePipe* WritePipe;
  1093. /*! \fn BOOL KUSB_API ResetPipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID)
  1094. * \memberof KUSB_DRIVER_API
  1095. * \copydoc UsbK_ResetPipe
  1096. */
  1097. KUSB_ResetPipe* ResetPipe;
  1098. /*! \fn BOOL KUSB_API AbortPipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID)
  1099. * \memberof KUSB_DRIVER_API
  1100. * \copydoc UsbK_AbortPipe
  1101. */
  1102. KUSB_AbortPipe* AbortPipe;
  1103. /*! \fn BOOL KUSB_API FlushPipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID)
  1104. * \memberof KUSB_DRIVER_API
  1105. * \copydoc UsbK_FlushPipe
  1106. */
  1107. KUSB_FlushPipe* FlushPipe;
  1108. /*! \fn BOOL KUSB_API IsoReadPipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID, _out PUCHAR Buffer, _in UINT BufferLength, _in LPOVERLAPPED Overlapped, _refopt PKISO_CONTEXT IsoContext)
  1109. * \memberof KUSB_DRIVER_API
  1110. * \copydoc UsbK_IsoReadPipe
  1111. */
  1112. KUSB_IsoReadPipe* IsoReadPipe;
  1113. /*! \fn BOOL KUSB_API IsoWritePipe (_in KUSB_HANDLE InterfaceHandle, _in UCHAR PipeID, _in PUCHAR Buffer, _in UINT BufferLength, _in LPOVERLAPPED Overlapped, _refopt PKISO_CONTEXT IsoContext)
  1114. * \memberof KUSB_DRIVER_API
  1115. * \copydoc UsbK_IsoWritePipe
  1116. */
  1117. KUSB_IsoWritePipe* IsoWritePipe;
  1118. /*! \fn BOOL KUSB_API GetCurrentFrameNumber (_in KUSB_HANDLE InterfaceHandle, _out PUINT FrameNumber)
  1119. * \memberof KUSB_DRIVER_API
  1120. * \copydoc UsbK_GetCurrentFrameNumber
  1121. */
  1122. KUSB_GetCurrentFrameNumber* GetCurrentFrameNumber;
  1123. /*! \fn BOOL KUSB_API GetOverlappedResult (_in KUSB_HANDLE InterfaceHandle, _in LPOVERLAPPED Overlapped, _out PUINT lpNumberOfBytesTransferred, _in BOOL bWait)
  1124. * \memberof KUSB_DRIVER_API
  1125. * \copydoc UsbK_GetOverlappedResult
  1126. */
  1127. KUSB_GetOverlappedResult* GetOverlappedResult;
  1128. /*! \fn BOOL KUSB_API GetProperty (_in KUSB_HANDLE InterfaceHandle, _in KUSB_PROPERTY PropertyType, _ref PUINT PropertySize, _out PVOID Value)
  1129. * \memberof KUSB_DRIVER_API
  1130. * \copydoc UsbK_GetProperty
  1131. */
  1132. KUSB_GetProperty* GetProperty;
  1133. //! fixed structure padding.
  1134. UCHAR z_F_i_x_e_d[512 - sizeof(KUSB_DRIVER_API_INFO) - sizeof(UINT_PTR) * KUSB_FNID_COUNT];
  1135. } KUSB_DRIVER_API;
  1136. typedef KUSB_DRIVER_API* PKUSB_DRIVER_API;
  1137. C_ASSERT(sizeof(KUSB_DRIVER_API) == 512);
  1138. /**@}*/
  1139. #endif
  1140. #ifndef _LIBUSBK_HOTK_TYPES
  1141. /*! \addtogroup hotk
  1142. * @{
  1143. */
  1144. //! Hot plug config flags.
  1145. typedef enum _KHOT_FLAG
  1146. {
  1147. //! No flags (or 0)
  1148. KHOT_FLAG_NONE,
  1149. //! Notify all devices which match upon a succuessful call to \ref HotK_Init.
  1150. KHOT_FLAG_PLUG_ALL_ON_INIT = 0x0001,
  1151. //! Allow other \ref KHOT_HANDLE instances to consume this match.
  1152. KHOT_FLAG_PASS_DUPE_INSTANCE = 0x0002,
  1153. //! If a \c UserHwnd is specified, use \c PostMessage instead of \c SendMessage.
  1154. KHOT_FLAG_POST_USER_MESSAGE = 0x0004,
  1155. } KHOT_FLAG;
  1156. typedef VOID KUSB_API KHOT_PLUG_CB(
  1157. _in KHOT_HANDLE HotHandle,
  1158. _in KLST_DEVINFO_HANDLE DeviceInfo,
  1159. _in KLST_SYNC_FLAG PlugType);
  1160. //! Hot plug parameter structure.
  1161. /*!
  1162. * \fixedstruct{2048}
  1163. *
  1164. * This structure is intially passed as a parameter to \ref HotK_Init.
  1165. *
  1166. */
  1167. typedef struct _KHOT_PARAMS
  1168. {
  1169. //! Hot plug event window handle to send/post messages when notifications occur.
  1170. HWND UserHwnd;
  1171. //! WM_USER message start offset used when sending/posting messages, See details.
  1172. /*!
  1173. * \attention The \ref hotk will send UserMessage+1 for arrival notifications and UserMessage+0 for removal notifications.
  1174. *
  1175. * - WPARAM = \ref KHOT_HANDLE
  1176. * - LPARAM = \ref KLST_DEVINFO_HANDLE
  1177. */
  1178. UINT UserMessage;
  1179. //! Additional init/config parameters
  1180. KHOT_FLAG Flags;
  1181. //! File pattern matches for restricting notifcations to a single/group or all supported usb devices.
  1182. KLST_PATTERN_MATCH PatternMatch;
  1183. //! Hot plug event callback function invoked when notifications occur.
  1184. /*! \fn VOID KUSB_API OnHotPlug (_in KHOT_HANDLE HotHandle, _in KLST_DEVINFO_HANDLE DeviceInfo, _in KLST_SYNC_FLAG PlugType)
  1185. * \memberof KHOT_PARAMS
  1186. */
  1187. KHOT_PLUG_CB* OnHotPlug;
  1188. //! fixed structure padding.
  1189. UCHAR z_F_i_x_e_d[2048 - sizeof(KLST_PATTERN_MATCH) - sizeof(UINT_PTR) * 2 - sizeof(UINT) * 2];
  1190. } KHOT_PARAMS;
  1191. C_ASSERT(sizeof(KHOT_PARAMS) == 2048);
  1192. //! Pointer to a \ref KHOT_PARAMS structure.
  1193. typedef KHOT_PARAMS* PKHOT_PARAMS;
  1194. /**@}*/
  1195. #endif
  1196. #ifndef _LIBUSBK_OVLK_TYPES
  1197. /*! \addtogroup ovlk
  1198. * @{
  1199. */
  1200. //! \c WaitFlags used by \ref OvlK_Wait.
  1201. /*!
  1202. *
  1203. */
  1204. typedef enum _KOVL_WAIT_FLAG
  1205. {
  1206. //! Do not perform any additional actions upon exiting \ref OvlK_Wait.
  1207. KOVL_WAIT_FLAG_NONE = 0L,
  1208. //! If the i/o operation completes successfully, release the OverlappedK back to it's pool.
  1209. KOVL_WAIT_FLAG_RELEASE_ON_SUCCESS = 0x0001,
  1210. //! If the i/o operation fails, release the OverlappedK back to it's pool.
  1211. KOVL_WAIT_FLAG_RELEASE_ON_FAIL = 0x0002,
  1212. //! If the i/o operation fails or completes successfully, release the OverlappedK back to its pool. Perform no actions if it times-out.
  1213. KOVL_WAIT_FLAG_RELEASE_ON_SUCCESS_FAIL = 0x0003,
  1214. //! If the i/o operation times-out cancel it, but do not release the OverlappedK back to its pool.
  1215. KOVL_WAIT_FLAG_CANCEL_ON_TIMEOUT = 0x0004,
  1216. //! If the i/o operation times-out, cancel it and release the OverlappedK back to its pool.
  1217. KOVL_WAIT_FLAG_RELEASE_ON_TIMEOUT = 0x000C,
  1218. //! Always release the OverlappedK back to its pool. If the operation timed-out, cancel it before releasing back to its pool.
  1219. KOVL_WAIT_FLAG_RELEASE_ALWAYS = 0x000F,
  1220. //! Uses alterable wait functions. See http://msdn.microsoft.com/en-us/library/windows/desktop/ms687036%28v=vs.85%29.aspx
  1221. KOVL_WAIT_FLAG_ALERTABLE = 0x0010,
  1222. } KOVL_WAIT_FLAG;
  1223. //! \c Overlapped pool config flags.
  1224. /*!
  1225. * \attention Currently not used.
  1226. */
  1227. typedef enum _KOVL_POOL_FLAG
  1228. {
  1229. KOVL_POOL_FLAG_NONE = 0L,
  1230. } KOVL_POOL_FLAG;
  1231. /**@}*/
  1232. #endif
  1233. #ifndef _LIBUSBK_STMK_TYPES
  1234. /*! \addtogroup stmk
  1235. * @{
  1236. */
  1237. //! Stream config flags.
  1238. /*!
  1239. * \attention Currently not used.
  1240. */
  1241. typedef enum _KSTM_FLAG
  1242. {
  1243. //! None
  1244. KSTM_FLAG_NONE = 0L,
  1245. KSTM_FLAG_NO_PARTIAL_XFERS = 0x00100000,
  1246. KSTM_FLAG_USE_TIMEOUT = 0x80000000,
  1247. KSTM_FLAG_TIMEOUT_MASK = 0x0001FFFF
  1248. } KSTM_FLAG;
  1249. //! Stream config flags.
  1250. /*!
  1251. * \attention Currently not used.
  1252. */
  1253. typedef enum _KSTM_COMPLETE_RESULT
  1254. {
  1255. //! Valid
  1256. KSTM_COMPLETE_RESULT_VALID = 0L,
  1257. //! Invalid
  1258. KSTM_COMPLETE_RESULT_INVALID,
  1259. } KSTM_COMPLETE_RESULT;
  1260. //! Stream transfer context structure.
  1261. /*!
  1262. * This structure is passed into the stream callback functions.
  1263. * The stream transfer context list is allocated upon a successful call to \ref StmK_Init. There is one
  1264. * transfer context for each transfer. (0 to \c MaxPendingTransfers).
  1265. *
  1266. */
  1267. typedef struct _KSTM_XFER_CONTEXT
  1268. {
  1269. //! Internal stream buffer.
  1270. PUCHAR Buffer;
  1271. //! Size of internal stream buffer.
  1272. INT BufferSize;
  1273. //! Number of bytes to write or number of bytes read.
  1274. INT TransferLength;
  1275. //! User defined state.
  1276. PVOID UserState;
  1277. } KSTM_XFER_CONTEXT;
  1278. //! Pointer to a \ref KSTM_XFER_CONTEXT structure.
  1279. typedef KSTM_XFER_CONTEXT* PKSTM_XFER_CONTEXT;
  1280. //! Stream information structure.
  1281. /*!
  1282. * This structure is passed into the stream callback functions.
  1283. * The stream context is allocated upon a successful call to \ref StmK_Init. There is only one
  1284. * stream context per stream.
  1285. *
  1286. */
  1287. typedef struct _KSTM_INFO
  1288. {
  1289. //! \ref KUSB_HANDLE this stream uses.
  1290. KUSB_HANDLE UsbHandle;
  1291. //! This parameter corresponds to the bEndpointAddress field in the endpoint descriptor.
  1292. UCHAR PipeID;
  1293. //! Maximum transfer read/write request allowed pending.
  1294. INT MaxPendingTransfers;
  1295. //! Maximum transfer sage size.
  1296. INT MaxTransferSize;
  1297. //! Maximum number of I/O request allowed pending.
  1298. INT MaxPendingIO;
  1299. //! Populated with the endpoint descriptor for the specified \c PipeID.
  1300. USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
  1301. //! Populated with the driver api for the specified \c UsbHandle.
  1302. KUSB_DRIVER_API DriverAPI;
  1303. //! Populated with the device file handle for the specified \c UsbHandle.
  1304. HANDLE DeviceHandle;
  1305. //! Stream handle.
  1306. KSTM_HANDLE StreamHandle;
  1307. //! Stream info user defined state.
  1308. PVOID UserState;
  1309. } KSTM_INFO;
  1310. //! Pointer to a \ref KSTM_INFO structure.
  1311. typedef KSTM_INFO* PKSTM_INFO;
  1312. //! Function definition for an optional user-defined callback; executed when a transfer error occurs.
  1313. /*! \fn INT KUSB_API KSTM_ERROR_CB(_in PKSTM_INFO StreamInfo, _in PKSTM_XFER_CONTEXT XferContext, _in INT XferContextIndex, _in INT ErrorCode)
  1314. * \memberof KSTM_CALLBACK
  1315. */
  1316. typedef INT KUSB_API KSTM_ERROR_CB(_in PKSTM_INFO StreamInfo, _in PKSTM_XFER_CONTEXT XferContext, _in INT XferContextIndex, _in INT ErrorCode);
  1317. //! Function definition for an optional user-defined callback; executed to submit a transfer.
  1318. /*! …

Large files files are truncated, but you can click here to view the full file