wince_usb.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Windows CE backend for libusbx 1.0
  3. * Copyright © 2011-2013 RealVNC Ltd.
  4. * Portions taken from Windows backend, which is
  5. * Copyright © 2009-2010 Pete Batard <pbatard@gmail.com>
  6. * With contributions from Michael Plante, Orin Eman et al.
  7. * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
  8. * Major code testing contribution by Xiaofan Chen
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. */
  24. #pragma once
  25. #include "windows_common.h"
  26. #include <windows.h>
  27. #include "poll_windows.h"
  28. #define MAX_DEVICE_COUNT 256
  29. // This is a modified dump of the types in the ceusbkwrapper.h library header
  30. // with functions transformed into extern pointers.
  31. //
  32. // This backend dynamically loads ceusbkwrapper.dll and doesn't include
  33. // ceusbkwrapper.h directly to simplify the build process. The kernel
  34. // side wrapper driver is built using the platform image build tools,
  35. // which makes it difficult to reference directly from the libusbx build
  36. // system.
  37. struct UKW_DEVICE_PRIV;
  38. typedef struct UKW_DEVICE_PRIV *UKW_DEVICE;
  39. typedef UKW_DEVICE *PUKW_DEVICE, *LPUKW_DEVICE;
  40. typedef struct {
  41. UINT8 bLength;
  42. UINT8 bDescriptorType;
  43. UINT16 bcdUSB;
  44. UINT8 bDeviceClass;
  45. UINT8 bDeviceSubClass;
  46. UINT8 bDeviceProtocol;
  47. UINT8 bMaxPacketSize0;
  48. UINT16 idVendor;
  49. UINT16 idProduct;
  50. UINT16 bcdDevice;
  51. UINT8 iManufacturer;
  52. UINT8 iProduct;
  53. UINT8 iSerialNumber;
  54. UINT8 bNumConfigurations;
  55. } UKW_DEVICE_DESCRIPTOR, *PUKW_DEVICE_DESCRIPTOR, *LPUKW_DEVICE_DESCRIPTOR;
  56. typedef struct {
  57. UINT8 bmRequestType;
  58. UINT8 bRequest;
  59. UINT16 wValue;
  60. UINT16 wIndex;
  61. UINT16 wLength;
  62. } UKW_CONTROL_HEADER, *PUKW_CONTROL_HEADER, *LPUKW_CONTROL_HEADER;
  63. // Collection of flags which can be used when issuing transfer requests
  64. /* Indicates that the transfer direction is 'in' */
  65. #define UKW_TF_IN_TRANSFER 0x00000001
  66. /* Indicates that the transfer direction is 'out' */
  67. #define UKW_TF_OUT_TRANSFER 0x00000000
  68. /* Specifies that the transfer should complete as soon as possible,
  69. * even if no OVERLAPPED structure has been provided. */
  70. #define UKW_TF_NO_WAIT 0x00000100
  71. /* Indicates that transfers shorter than the buffer are ok */
  72. #define UKW_TF_SHORT_TRANSFER_OK 0x00000200
  73. #define UKW_TF_SEND_TO_DEVICE 0x00010000
  74. #define UKW_TF_SEND_TO_INTERFACE 0x00020000
  75. #define UKW_TF_SEND_TO_ENDPOINT 0x00040000
  76. /* Don't block when waiting for memory allocations */
  77. #define UKW_TF_DONT_BLOCK_FOR_MEM 0x00080000
  78. /* Value to use when dealing with configuration values, such as UkwGetConfigDescriptor,
  79. * to specify the currently active configuration for the device. */
  80. #define UKW_ACTIVE_CONFIGURATION -1
  81. DLL_DECLARE(WINAPI, HANDLE, UkwOpenDriver, ());
  82. DLL_DECLARE(WINAPI, BOOL, UkwGetDeviceList, (HANDLE, LPUKW_DEVICE, DWORD, LPDWORD));
  83. DLL_DECLARE(WINAPI, void, UkwReleaseDeviceList, (HANDLE, LPUKW_DEVICE, DWORD));
  84. DLL_DECLARE(WINAPI, BOOL, UkwGetDeviceAddress, (UKW_DEVICE, unsigned char*, unsigned char*, unsigned long*));
  85. DLL_DECLARE(WINAPI, BOOL, UkwGetDeviceDescriptor, (UKW_DEVICE, LPUKW_DEVICE_DESCRIPTOR));
  86. DLL_DECLARE(WINAPI, BOOL, UkwGetConfigDescriptor, (UKW_DEVICE, DWORD, LPVOID, DWORD, LPDWORD));
  87. DLL_DECLARE(WINAPI, void, UkwCloseDriver, (HANDLE));
  88. DLL_DECLARE(WINAPI, BOOL, UkwCancelTransfer, (UKW_DEVICE, LPOVERLAPPED, DWORD));
  89. DLL_DECLARE(WINAPI, BOOL, UkwIssueControlTransfer, (UKW_DEVICE, DWORD, LPUKW_CONTROL_HEADER, LPVOID, DWORD, LPDWORD, LPOVERLAPPED));
  90. DLL_DECLARE(WINAPI, BOOL, UkwClaimInterface, (UKW_DEVICE, DWORD));
  91. DLL_DECLARE(WINAPI, BOOL, UkwReleaseInterface, (UKW_DEVICE, DWORD));
  92. DLL_DECLARE(WINAPI, BOOL, UkwSetInterfaceAlternateSetting, (UKW_DEVICE, DWORD, DWORD));
  93. DLL_DECLARE(WINAPI, BOOL, UkwClearHaltHost, (UKW_DEVICE, UCHAR));
  94. DLL_DECLARE(WINAPI, BOOL, UkwClearHaltDevice, (UKW_DEVICE, UCHAR));
  95. DLL_DECLARE(WINAPI, BOOL, UkwGetConfig, (UKW_DEVICE, PUCHAR));
  96. DLL_DECLARE(WINAPI, BOOL, UkwSetConfig, (UKW_DEVICE, UCHAR));
  97. DLL_DECLARE(WINAPI, BOOL, UkwResetDevice, (UKW_DEVICE));
  98. DLL_DECLARE(WINAPI, BOOL, UkwKernelDriverActive, (UKW_DEVICE, DWORD, PBOOL));
  99. DLL_DECLARE(WINAPI, BOOL, UkwAttachKernelDriver, (UKW_DEVICE, DWORD));
  100. DLL_DECLARE(WINAPI, BOOL, UkwDetachKernelDriver, (UKW_DEVICE, DWORD));
  101. DLL_DECLARE(WINAPI, BOOL, UkwIssueBulkTransfer, (UKW_DEVICE, DWORD, UCHAR, LPVOID, DWORD, LPDWORD, LPOVERLAPPED));
  102. DLL_DECLARE(WINAPI, BOOL, UkwIsPipeHalted, (UKW_DEVICE, UCHAR, LPBOOL));
  103. // Used to determine if an endpoint status really is halted on a failed transfer.
  104. #define STATUS_HALT_FLAG 0x1
  105. struct wince_device_priv {
  106. UKW_DEVICE dev;
  107. UKW_DEVICE_DESCRIPTOR desc;
  108. };
  109. struct wince_device_handle_priv {
  110. // This member isn't used, but only exists to avoid an empty structure
  111. // for private data for the device handle.
  112. int reserved;
  113. };
  114. struct wince_transfer_priv {
  115. struct winfd pollable_fd;
  116. uint8_t interface_number;
  117. };