summaryrefslogtreecommitdiff
path: root/libusb/os/windows_usb.h
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-01-30 21:45:15 +0000
committerPete Batard <pbatard@gmail.com>2010-01-30 21:45:15 +0000
commit76eef888a1925838d59330ddc34956674b89bd7b (patch)
tree804b12d00c8f3b01ba88330fe47cad34026b8360 /libusb/os/windows_usb.h
parentc1f00180ff0f2eac5bb190a4a98a7a04b440413e (diff)
downloadlibusb-76eef888a1925838d59330ddc34956674b89bd7b.tar.gz
r127: merged concurrency branch with master (native improved concurrency handling for Windows files) [c119->c137]:
c119: concurrency handling: - use semaphore in init/exit (Orin Eman) - use separate thread for timer and remove the need for affinity restoration - minor code readability improvements (moved GUIDs to .h) c120: removed unneeded disabling of APIs in winusb_exit & hid_exit c121: changed CreateThread to _beginthreadex, so CRT works properly when mem is low (Michael Plante) c122: made name of named-semaphore unique across the system per-process (Michael Plante) c123: allow timer thread to quit gracefully, and cleanup many of the handles (Michael Plante) c124: fixed concurrent_usage if init fails (Michael Plante) c125: drop PulseEvent in timer thread and use semaphore for response (Orin Eman). c126: removed pthread dependency in windows_compat.c c127: fixed missing reset of timer_request when event has already been handled c128: additional fixes for timer thread: - closed timer_mutex handles, and fixed volatile warning regarding interlocked ops (Michael Plante) - missing ResetEvent and possible missing request handling fix (Orin Eman) - additional fixes c129: use of spinlocks and critical sections in windows_compat.c for mutexes (Orin Eman, Michael Plante) c130: fixed missing spinlock in exit_polling c131: made spinlock static, changed to LONG, and casted off volatile in InterlockedExchange calls (Michael Plante) c132: additional security checks when entering critical sections in windows_compat.c c133: brought latest master commits to the concurrency branch [r119 -> r122] c134: fixed unfortunate inverted comparison introduced in c132 c135: fixed timer thread warnings with MinGW c136: brought latest master commits to the concurrency branch [r123 -> r126] c137: removed pthread.h and sched.h includes from windows_usb.c
Diffstat (limited to 'libusb/os/windows_usb.h')
-rw-r--r--libusb/os/windows_usb.h49
1 files changed, 33 insertions, 16 deletions
diff --git a/libusb/os/windows_usb.h b/libusb/os/windows_usb.h
index 6921882..e2801db 100644
--- a/libusb/os/windows_usb.h
+++ b/libusb/os/windows_usb.h
@@ -62,6 +62,7 @@ extern char *_strdup(const char *strSource);
#define safe_strdup _strdup
#define safe_sprintf _snprintf
#define safe_unref_device(dev) do {if (dev != NULL) {libusb_unref_device(dev); dev = NULL;}} while(0)
+#define wchar_to_utf8_ms(wstr, str, strlen) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, strlen, NULL, NULL)
inline void upperize(char* str) {
size_t i;
if (str == NULL) return;
@@ -74,25 +75,45 @@ inline void upperize(char* str) {
#define MAX_USB_STRING_LENGTH 128
#define MAX_HID_REPORT_SIZE 1024
#define MAX_HID_DESCRIPTOR_SIZE 256
-
+#define MAX_GUID_STRING_LENGTH 40
#define MAX_PATH_LENGTH 128
#define MAX_KEY_LENGTH 256
+#define MAX_TIMER_SEMAPHORES 128
#define ERR_BUFFER_SIZE 256
-#define GUID_STRING_LENGTH 40
// Handle code for HID interface that have been claimed ("dibs")
#define INTERFACE_CLAIMED ((HANDLE)0xD1B5)
// Additional return code for HID operations that completed synchronously
#define LIBUSB_COMPLETED (LIBUSB_SUCCESS + 1)
-#define wchar_to_utf8_ms(wstr, str, strlen) WideCharToMultiByte(CP_UTF8, 0, wstr, -1, str, strlen, NULL, NULL)
+// http://msdn.microsoft.com/en-us/library/bb663109.aspx
+// http://msdn.microsoft.com/en-us/library/bb663093.aspx
+#if !defined(GUID_DEVINTERFACE_USB_HOST_CONTROLLER)
+const GUID GUID_DEVINTERFACE_USB_HOST_CONTROLLER = { 0x3ABF6F2D, 0x71C4, 0x462A, {0x8A, 0x92, 0x1E, 0x68, 0x61, 0xE6, 0xAF, 0x27} };
+#endif
+#if !defined(GUID_DEVINTERFACE_USB_DEVICE)
+const GUID GUID_DEVINTERFACE_USB_DEVICE = { 0xA5DCBF10, 0x6530, 0x11D2, {0x90, 0x1F, 0x00, 0xC0, 0x4F, 0xB9, 0x51, 0xED} };
+#endif
+
+
+/*
+ * Multiple USB API backend support
+ */
+#define USB_API_UNSUPPORTED 0
+#define USB_API_COMPOSITE 1
+#define USB_API_WINUSB 2
+#define USB_API_HID 3
+#define USB_API_MAX 4
+
+const GUID CLASS_GUID_UNSUPPORTED = { 0x00000000, 0x0000, 0x0000, {0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x57, 0xDA} };
+const GUID CLASS_GUID_HID = { 0x745A17A0, 0x74D3, 0x11D0, {0xB6, 0xFE, 0x00, 0xA0, 0xC9, 0x0F, 0x57, 0xDA} };
+const GUID CLASS_GUID_LIBUSB_WINUSB = { 0x78A1C341, 0x4539, 0x11D3, {0xB8, 0x8D, 0x00, 0xC0, 0x4F, 0xAD, 0x51, 0x71} };
+const GUID CLASS_GUID_COMPOSITE = { 0x36FC9E60, 0xC465, 0x11cF, {0x80, 0x56, 0x44, 0x45, 0x53, 0x54, 0x00, 0x00} };
-// This is used to support multiple kernel drivers and USB APIs in Windows.
struct windows_usb_api_backend {
- const char *name; // A human-readable name for your backend, e.g. "WinUSB"
- const char *driver_name; // Driver's name, without .sys, e.g. "usbccgp"
- const GUID *class_guid; // The Class GUID (for fallback in case the driver name cannot be read)
const uint8_t id;
+ const GUID *class_guid; // The Class GUID (for fallback in case the driver name cannot be read)
+ const char *driver_name; // Driver name, without .sys, e.g. "usbccgp"
int (*init)(struct libusb_context *ctx);
int (*exit)(void);
int (*open)(struct libusb_device_handle *dev_handle);
@@ -109,11 +130,6 @@ struct windows_usb_api_backend {
int (*abort_transfers)(struct usbi_transfer *itransfer);
};
-#define USB_API_TEMPLATE 0
-#define USB_API_COMPOSITE 1
-#define USB_API_WINUSB 2
-#define USB_API_HID 3
-#define USB_API_MAX 4
extern const struct windows_usb_api_backend usb_api_backend[USB_API_MAX];
#define PRINT_UNSUPPORTED_API(fname) \
@@ -127,6 +143,7 @@ enum windows_version {
WINDOWS_VISTA_AND_LATER,
};
+
/*
* private structures definition
* with inline pseudo constructors/destructors
@@ -219,7 +236,7 @@ static inline void windows_device_priv_init(struct windows_device_priv* p) {
p->parent_dev = NULL;
p->connection_index = 0;
p->path = NULL;
- p->apib = &usb_api_backend[USB_API_TEMPLATE];
+ p->apib = &usb_api_backend[USB_API_UNSUPPORTED];
p->composite_api_flags = 0;
p->hid = NULL;
p->active_config = 0;
@@ -227,7 +244,7 @@ static inline void windows_device_priv_init(struct windows_device_priv* p) {
memset(&(p->dev_descriptor), 0, sizeof(USB_DEVICE_DESCRIPTOR));
for (i=0; i<USB_MAXINTERFACES; i++) {
p->usb_interface[i].path = NULL;
- p->usb_interface[i].apib = &usb_api_backend[USB_API_TEMPLATE];
+ p->usb_interface[i].apib = &usb_api_backend[USB_API_UNSUPPORTED];
p->usb_interface[i].nb_endpoints = 0;
p->usb_interface[i].endpoint = NULL;
}
@@ -254,7 +271,7 @@ static inline struct windows_device_priv *__device_priv(struct libusb_device *de
struct interface_handle_t {
HANDLE dev_handle; // WinUSB needs an extra handle for the file
- HANDLE api_handle; // used by the API to communicate with the device
+ HANDLE api_handle; // used by the API to communicate with the device
};
struct windows_device_handle_priv {
@@ -388,7 +405,7 @@ CMAPI CONFIGRET WINAPI CM_Get_Device_IDW(
#endif /* UNICODE */
#define IOCTL_USB_GET_HUB_CAPABILITIES_EX \
- CTL_CODE( FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES_EX, METHOD_BUFFERED, FILE_ANY_ACCESS)
+ CTL_CODE( FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES_EX, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define IOCTL_USB_GET_HUB_CAPABILITIES \
CTL_CODE(FILE_DEVICE_USB, USB_GET_HUB_CAPABILITIES, METHOD_BUFFERED, FILE_ANY_ACCESS)