Home | History | Annotate | Download | only in os
      1 /*
      2 * windows UsbDk backend for libusb 1.0
      3 * Copyright  2014 Red Hat, Inc.
      4 
      5 * Authors:
      6 * Dmitry Fleytman <dmitry (at) daynix.com>
      7 * Pavel Gurvich <pavel (at) daynix.com>
      8 *
      9 * This library is free software; you can redistribute it and/or
     10 * modify it under the terms of the GNU Lesser General Public
     11 * License as published by the Free Software Foundation; either
     12 * version 2.1 of the License, or (at your option) any later version.
     13 *
     14 * This library is distributed in the hope that it will be useful,
     15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17 * Lesser General Public License for more details.
     18 *
     19 * You should have received a copy of the GNU Lesser General Public
     20 * License along with this library; if not, write to the Free Software
     21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     22 */
     23 
     24 #pragma once
     25 
     26 typedef struct tag_USB_DK_DEVICE_ID {
     27 	WCHAR DeviceID[MAX_DEVICE_ID_LEN];
     28 	WCHAR InstanceID[MAX_DEVICE_ID_LEN];
     29 } USB_DK_DEVICE_ID, *PUSB_DK_DEVICE_ID;
     30 
     31 static inline void UsbDkFillIDStruct(USB_DK_DEVICE_ID *ID, PCWCHAR DeviceID, PCWCHAR InstanceID)
     32 {
     33 	wcsncpy_s(ID->DeviceID, DeviceID, MAX_DEVICE_ID_LEN);
     34 	wcsncpy_s(ID->InstanceID, InstanceID, MAX_DEVICE_ID_LEN);
     35 }
     36 
     37 typedef struct tag_USB_DK_DEVICE_INFO {
     38 	USB_DK_DEVICE_ID ID;
     39 	ULONG64 FilterID;
     40 	ULONG64 Port;
     41 	ULONG64 Speed;
     42 	USB_DEVICE_DESCRIPTOR DeviceDescriptor;
     43 } USB_DK_DEVICE_INFO, *PUSB_DK_DEVICE_INFO;
     44 
     45 typedef struct tag_USB_DK_CONFIG_DESCRIPTOR_REQUEST {
     46 	USB_DK_DEVICE_ID ID;
     47 	ULONG64 Index;
     48 } USB_DK_CONFIG_DESCRIPTOR_REQUEST, *PUSB_DK_CONFIG_DESCRIPTOR_REQUEST;
     49 
     50 typedef struct tag_USB_DK_ISO_TRANSFER_RESULT {
     51 	ULONG64 ActualLength;
     52 	ULONG64 TransferResult;
     53 } USB_DK_ISO_TRANSFER_RESULT, *PUSB_DK_ISO_TRANSFER_RESULT;
     54 
     55 typedef struct tag_USB_DK_GEN_TRANSFER_RESULT {
     56 	ULONG64 BytesTransferred;
     57 	ULONG64 UsbdStatus; // USBD_STATUS code
     58 } USB_DK_GEN_TRANSFER_RESULT, *PUSB_DK_GEN_TRANSFER_RESULT;
     59 
     60 typedef struct tag_USB_DK_TRANSFER_RESULT {
     61 	USB_DK_GEN_TRANSFER_RESULT GenResult;
     62 	PVOID64 IsochronousResultsArray; // array of USB_DK_ISO_TRANSFER_RESULT
     63 } USB_DK_TRANSFER_RESULT, *PUSB_DK_TRANSFER_RESULT;
     64 
     65 typedef struct tag_USB_DK_TRANSFER_REQUEST {
     66 	ULONG64 EndpointAddress;
     67 	PVOID64 Buffer;
     68 	ULONG64 BufferLength;
     69 	ULONG64 TransferType;
     70 	ULONG64 IsochronousPacketsArraySize;
     71 	PVOID64 IsochronousPacketsArray;
     72 
     73 	USB_DK_TRANSFER_RESULT Result;
     74 } USB_DK_TRANSFER_REQUEST, *PUSB_DK_TRANSFER_REQUEST;
     75 
     76 typedef enum {
     77 	TransferFailure = 0,
     78 	TransferSuccess,
     79 	TransferSuccessAsync
     80 } TransferResult;
     81 
     82 typedef enum {
     83 	NoSpeed = 0,
     84 	LowSpeed,
     85 	FullSpeed,
     86 	HighSpeed,
     87 	SuperSpeed
     88 } USB_DK_DEVICE_SPEED;
     89 
     90 typedef enum {
     91 	ControlTransferType,
     92 	BulkTransferType,
     93 	IntertuptTransferType,
     94 	IsochronousTransferType
     95 } USB_DK_TRANSFER_TYPE;
     96 
     97 typedef BOOL (__cdecl *USBDK_GET_DEVICES_LIST)(
     98 	PUSB_DK_DEVICE_INFO *DeviceInfo,
     99 	PULONG DeviceNumber
    100 );
    101 typedef void (__cdecl *USBDK_RELEASE_DEVICES_LIST)(
    102 	PUSB_DK_DEVICE_INFO DeviceInfo
    103 );
    104 typedef HANDLE (__cdecl *USBDK_START_REDIRECT)(
    105 	PUSB_DK_DEVICE_ID DeviceId
    106 );
    107 typedef BOOL (__cdecl *USBDK_STOP_REDIRECT)(
    108 	HANDLE DeviceHandle
    109 );
    110 typedef BOOL (__cdecl *USBDK_GET_CONFIGURATION_DESCRIPTOR)(
    111 	PUSB_DK_CONFIG_DESCRIPTOR_REQUEST Request,
    112 	PUSB_CONFIGURATION_DESCRIPTOR *Descriptor,
    113 	PULONG Length
    114 );
    115 typedef void (__cdecl *USBDK_RELEASE_CONFIGURATION_DESCRIPTOR)(
    116 	PUSB_CONFIGURATION_DESCRIPTOR Descriptor
    117 );
    118 typedef TransferResult (__cdecl *USBDK_WRITE_PIPE)(
    119 	HANDLE DeviceHandle,
    120 	PUSB_DK_TRANSFER_REQUEST Request,
    121 	LPOVERLAPPED lpOverlapped
    122 );
    123 typedef TransferResult (__cdecl *USBDK_READ_PIPE)(
    124 	HANDLE DeviceHandle,
    125 	PUSB_DK_TRANSFER_REQUEST Request,
    126 	LPOVERLAPPED lpOverlapped
    127 );
    128 typedef BOOL (__cdecl *USBDK_ABORT_PIPE)(
    129 	HANDLE DeviceHandle,
    130 	ULONG64 PipeAddress
    131 );
    132 typedef BOOL (__cdecl *USBDK_RESET_PIPE)(
    133 	HANDLE DeviceHandle,
    134 	ULONG64 PipeAddress
    135 );
    136 typedef BOOL (__cdecl *USBDK_SET_ALTSETTING)(
    137 	HANDLE DeviceHandle,
    138 	ULONG64 InterfaceIdx,
    139 	ULONG64 AltSettingIdx
    140 );
    141 typedef BOOL (__cdecl *USBDK_RESET_DEVICE)(
    142 	HANDLE DeviceHandle
    143 );
    144 typedef HANDLE (__cdecl *USBDK_GET_REDIRECTOR_SYSTEM_HANDLE)(
    145 	HANDLE DeviceHandle
    146 );
    147