1*8a978a17SVictor Perevertkin // 2*8a978a17SVictor Perevertkin // Copyright (C) Microsoft. All rights reserved. 3*8a978a17SVictor Perevertkin // 4*8a978a17SVictor Perevertkin #pragma once 5*8a978a17SVictor Perevertkin 6*8a978a17SVictor Perevertkin #include <WinUsb.h> 7*8a978a17SVictor Perevertkin 8*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SELECT_CONFIGURATION 0x0000 9*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SELECT_INTERFACE 0x0001 10*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_ABORT_PIPE 0x0002 11*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_TAKE_FRAME_LENGTH_CONTROL 0x0003 12*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_RELEASE_FRAME_LENGTH_CONTROL 0x0004 13*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_FRAME_LENGTH 0x0005 14*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SET_FRAME_LENGTH 0x0006 15*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_CURRENT_FRAME_NUMBER 0x0007 16*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_CONTROL_TRANSFER 0x0008 17*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER 0x0009 18*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_ISOCH_TRANSFER 0x000A 19*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE 0x000B 20*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SET_DESCRIPTOR_TO_DEVICE 0x000C 21*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SET_FEATURE_TO_DEVICE 0x000D 22*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SET_FEATURE_TO_INTERFACE 0x000E 23*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SET_FEATURE_TO_ENDPOINT 0x000F 24*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_CLEAR_FEATURE_TO_DEVICE 0x0010 25*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_CLEAR_FEATURE_TO_INTERFACE 0x0011 26*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_CLEAR_FEATURE_TO_ENDPOINT 0x0012 27*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_STATUS_FROM_DEVICE 0x0013 28*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_STATUS_FROM_INTERFACE 0x0014 29*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_STATUS_FROM_ENDPOINT 0x0015 30*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_RESERVED_0X0016 0x0016 31*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_VENDOR_DEVICE 0x0017 32*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_VENDOR_INTERFACE 0x0018 33*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_VENDOR_ENDPOINT 0x0019 34*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_CLASS_DEVICE 0x001A 35*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_CLASS_INTERFACE 0x001B 36*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_CLASS_ENDPOINT 0x001C 37*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_RESERVE_0X001D 0x001D 38*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SYNC_RESET_PIPE_AND_CLEAR_STALL 0x001E 39*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_INTERFACE 0x0027 40*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_DESCRIPTOR_FROM_INTERFACE 0x0028 41*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_RESET_PORT 0x0029 42*8a978a17SVictor Perevertkin 43*8a978a17SVictor Perevertkin // 44*8a978a17SVictor Perevertkin //These are specific to user-mode (WinUsb) and have no km counterpart 45*8a978a17SVictor Perevertkin // 46*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_QUERY_PIPE 0x0101 //in km this is done as a part of Interface info 47*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SET_PIPE_POLICY 0x0102 48*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_PIPE_POLICY 0x0103 49*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_SET_INTERFACE_POWER_POLICY 0x0104 50*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_INTERFACE_POWER_POLICY 0x0105 51*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_ENABLE_INTERFACE_IDLE 0x0106 52*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_DISABLE_INTERFACE_IDLE 0x0107 53*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_FLUSH_PIPE 0x0108 54*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_ASSOCIATED_INTERFACE 0x0109 55*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_DEVICE_INFORMATION 0x010A 56*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_GET_DESCRIPTOR 0x010B //WinUsb has a common function for all descriptors 57*8a978a17SVictor Perevertkin #define UMURB_FUNCTION_RELEASE_ASSOCIATED_INTERFACE 0x010C 58*8a978a17SVictor Perevertkin 59*8a978a17SVictor Perevertkin struct _UMURB_HEADER 60*8a978a17SVictor Perevertkin { 61*8a978a17SVictor Perevertkin // 62*8a978a17SVictor Perevertkin // Fields filled in by client driver 63*8a978a17SVictor Perevertkin // 64*8a978a17SVictor Perevertkin IN USHORT Length; 65*8a978a17SVictor Perevertkin IN USHORT Function; 66*8a978a17SVictor Perevertkin IN WINUSB_INTERFACE_HANDLE InterfaceHandle; 67*8a978a17SVictor Perevertkin 68*8a978a17SVictor Perevertkin OUT DWORD Status; //obtained using GetLastError(); 69*8a978a17SVictor Perevertkin }; 70*8a978a17SVictor Perevertkin 71*8a978a17SVictor Perevertkin typedef _UMURB_HEADER* PUMURB_HEADER; 72*8a978a17SVictor Perevertkin 73*8a978a17SVictor Perevertkin struct _UMURB_PIPE_REQUEST { 74*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; // function code indicates get or set. 75*8a978a17SVictor Perevertkin IN UCHAR PipeID; 76*8a978a17SVictor Perevertkin IN ULONG Reserved; 77*8a978a17SVictor Perevertkin }; 78*8a978a17SVictor Perevertkin 79*8a978a17SVictor Perevertkin struct _UMURB_SELECT_INTERFACE { 80*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; // function code indicates get or set. 81*8a978a17SVictor Perevertkin IN UCHAR AlternateSetting; 82*8a978a17SVictor Perevertkin }; 83*8a978a17SVictor Perevertkin 84*8a978a17SVictor Perevertkin struct _UMURB_CONTROL_TRANSFER { 85*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; // function code indicates get or set. 86*8a978a17SVictor Perevertkin IN UCHAR Reserved; //maybe use for PipeID 87*8a978a17SVictor Perevertkin IN OUT PVOID TransferBuffer; 88*8a978a17SVictor Perevertkin IN OUT ULONG TransferBufferLength; 89*8a978a17SVictor Perevertkin IN WINUSB_SETUP_PACKET SetupPacket; 90*8a978a17SVictor Perevertkin }; 91*8a978a17SVictor Perevertkin 92*8a978a17SVictor Perevertkin struct _UMURB_BULK_OR_INTERRUPT_TRANSFER { 93*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; // function code indicates get or set. 94*8a978a17SVictor Perevertkin IN UCHAR PipeID; 95*8a978a17SVictor Perevertkin IN BOOL InPipe; //in km this is determined based on the pipe, 96*8a978a17SVictor Perevertkin //but WinUsb has two different functions 97*8a978a17SVictor Perevertkin //since host can't store pipe type and it would be expensive to discover it 98*8a978a17SVictor Perevertkin //with every transfer, it is better if direction is sent in as a parameter 99*8a978a17SVictor Perevertkin IN OUT ULONG TransferBufferLength; 100*8a978a17SVictor Perevertkin IN OUT PVOID TransferBuffer; 101*8a978a17SVictor Perevertkin }; 102*8a978a17SVictor Perevertkin 103*8a978a17SVictor Perevertkin struct _UMURB_CONTROL_DESCRIPTOR_REQUEST { 104*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; // function code indicates get or set. 105*8a978a17SVictor Perevertkin IN PVOID Reserved; 106*8a978a17SVictor Perevertkin IN ULONG Reserved0; 107*8a978a17SVictor Perevertkin IN OUT ULONG TransferBufferLength; 108*8a978a17SVictor Perevertkin OUT PVOID TransferBuffer; 109*8a978a17SVictor Perevertkin IN UCHAR Index; 110*8a978a17SVictor Perevertkin IN UCHAR DescriptorType; 111*8a978a17SVictor Perevertkin IN USHORT LanguageId; 112*8a978a17SVictor Perevertkin IN USHORT Reserved2; 113*8a978a17SVictor Perevertkin }; 114*8a978a17SVictor Perevertkin 115*8a978a17SVictor Perevertkin struct _UMURB_PIPE_POLICY_REQUEST 116*8a978a17SVictor Perevertkin { 117*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; 118*8a978a17SVictor Perevertkin IN UCHAR PipeID; 119*8a978a17SVictor Perevertkin IN ULONG PolicyType; 120*8a978a17SVictor Perevertkin IN OUT ULONG ValueLength; 121*8a978a17SVictor Perevertkin IN OUT PVOID Value; 122*8a978a17SVictor Perevertkin }; 123*8a978a17SVictor Perevertkin 124*8a978a17SVictor Perevertkin struct _UMURB_INTERFACE_POLICY_REQUEST 125*8a978a17SVictor Perevertkin { 126*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; 127*8a978a17SVictor Perevertkin IN ULONG PolicyType; 128*8a978a17SVictor Perevertkin IN OUT ULONG ValueLength; 129*8a978a17SVictor Perevertkin IN OUT PVOID Value; 130*8a978a17SVictor Perevertkin }; 131*8a978a17SVictor Perevertkin 132*8a978a17SVictor Perevertkin struct _UMURB_QUERY_PIPE 133*8a978a17SVictor Perevertkin { 134*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; 135*8a978a17SVictor Perevertkin IN UCHAR AlternateSetting; 136*8a978a17SVictor Perevertkin IN UCHAR PipeID; 137*8a978a17SVictor Perevertkin OUT WINUSB_PIPE_INFORMATION PipeInformation; 138*8a978a17SVictor Perevertkin }; 139*8a978a17SVictor Perevertkin 140*8a978a17SVictor Perevertkin struct _UMURB_CONTROL_GET_INTERFACE_REQUEST { 141*8a978a17SVictor Perevertkin struct _UMURB_HEADER Hdr; // function code indicates get or set. 142*8a978a17SVictor Perevertkin IN UCHAR InterfaceIndex; 143*8a978a17SVictor Perevertkin }; 144*8a978a17SVictor Perevertkin 145*8a978a17SVictor Perevertkin struct _UMURB_GET_ASSOCIATED_INTERFACE { 146*8a978a17SVictor Perevertkin IN struct _UMURB_HEADER Hdr; 147*8a978a17SVictor Perevertkin IN UCHAR InterfaceIndex; 148*8a978a17SVictor Perevertkin OUT WINUSB_INTERFACE_HANDLE InterfaceHandle; 149*8a978a17SVictor Perevertkin }; 150*8a978a17SVictor Perevertkin 151*8a978a17SVictor Perevertkin struct _UMURB_INTERFACE_INFORMATION { 152*8a978a17SVictor Perevertkin IN struct _UMURB_HEADER Hdr; 153*8a978a17SVictor Perevertkin IN UCHAR AlternateSetting; 154*8a978a17SVictor Perevertkin OUT USB_INTERFACE_DESCRIPTOR UsbInterfaceDescriptor; 155*8a978a17SVictor Perevertkin }; 156*8a978a17SVictor Perevertkin 157*8a978a17SVictor Perevertkin struct _UMURB_DEVICE_INFORMATION { 158*8a978a17SVictor Perevertkin IN struct _UMURB_HEADER Hdr; 159*8a978a17SVictor Perevertkin IN ULONG InformationType; 160*8a978a17SVictor Perevertkin IN OUT ULONG BufferLength; 161*8a978a17SVictor Perevertkin OUT PVOID Buffer; 162*8a978a17SVictor Perevertkin }; 163*8a978a17SVictor Perevertkin 164*8a978a17SVictor Perevertkin struct _UMURB_DESCRIPTOR_REQUEST { 165*8a978a17SVictor Perevertkin IN struct _UMURB_HEADER Hdr; 166*8a978a17SVictor Perevertkin IN UCHAR DescriptorType; 167*8a978a17SVictor Perevertkin IN UCHAR Index; 168*8a978a17SVictor Perevertkin IN USHORT LanguageID; 169*8a978a17SVictor Perevertkin IN OUT ULONG BufferLength; 170*8a978a17SVictor Perevertkin OUT PVOID Buffer; 171*8a978a17SVictor Perevertkin }; 172*8a978a17SVictor Perevertkin 173*8a978a17SVictor Perevertkin typedef struct _UMURB { 174*8a978a17SVictor Perevertkin union { 175*8a978a17SVictor Perevertkin struct _UMURB_HEADER 176*8a978a17SVictor Perevertkin UmUrbHeader; 177*8a978a17SVictor Perevertkin 178*8a978a17SVictor Perevertkin struct _UMURB_SELECT_INTERFACE 179*8a978a17SVictor Perevertkin UmUrbSelectInterface; 180*8a978a17SVictor Perevertkin 181*8a978a17SVictor Perevertkin 182*8a978a17SVictor Perevertkin 183*8a978a17SVictor Perevertkin 184*8a978a17SVictor Perevertkin 185*8a978a17SVictor Perevertkin 186*8a978a17SVictor Perevertkin struct _UMURB_PIPE_REQUEST 187*8a978a17SVictor Perevertkin UmUrbPipeRequest; 188*8a978a17SVictor Perevertkin 189*8a978a17SVictor Perevertkin 190*8a978a17SVictor Perevertkin 191*8a978a17SVictor Perevertkin 192*8a978a17SVictor Perevertkin 193*8a978a17SVictor Perevertkin 194*8a978a17SVictor Perevertkin 195*8a978a17SVictor Perevertkin 196*8a978a17SVictor Perevertkin 197*8a978a17SVictor Perevertkin 198*8a978a17SVictor Perevertkin 199*8a978a17SVictor Perevertkin 200*8a978a17SVictor Perevertkin struct _UMURB_CONTROL_TRANSFER 201*8a978a17SVictor Perevertkin UmUrbControlTransfer; 202*8a978a17SVictor Perevertkin 203*8a978a17SVictor Perevertkin struct _UMURB_BULK_OR_INTERRUPT_TRANSFER 204*8a978a17SVictor Perevertkin UmUrbBulkOrInterruptTransfer; 205*8a978a17SVictor Perevertkin 206*8a978a17SVictor Perevertkin // for standard control transfers on the default pipe 207*8a978a17SVictor Perevertkin struct _UMURB_CONTROL_DESCRIPTOR_REQUEST 208*8a978a17SVictor Perevertkin UmUrbControlDescriptorRequest; 209*8a978a17SVictor Perevertkin 210*8a978a17SVictor Perevertkin 211*8a978a17SVictor Perevertkin 212*8a978a17SVictor Perevertkin 213*8a978a17SVictor Perevertkin 214*8a978a17SVictor Perevertkin 215*8a978a17SVictor Perevertkin 216*8a978a17SVictor Perevertkin 217*8a978a17SVictor Perevertkin 218*8a978a17SVictor Perevertkin 219*8a978a17SVictor Perevertkin struct _UMURB_CONTROL_GET_INTERFACE_REQUEST 220*8a978a17SVictor Perevertkin UmUrbControlGetInterfaceRequest; 221*8a978a17SVictor Perevertkin 222*8a978a17SVictor Perevertkin 223*8a978a17SVictor Perevertkin 224*8a978a17SVictor Perevertkin 225*8a978a17SVictor Perevertkin 226*8a978a17SVictor Perevertkin 227*8a978a17SVictor Perevertkin 228*8a978a17SVictor Perevertkin 229*8a978a17SVictor Perevertkin 230*8a978a17SVictor Perevertkin 231*8a978a17SVictor Perevertkin 232*8a978a17SVictor Perevertkin 233*8a978a17SVictor Perevertkin struct _UMURB_INTERFACE_POLICY_REQUEST 234*8a978a17SVictor Perevertkin UmUrbInterfacePolicyRequest; 235*8a978a17SVictor Perevertkin struct _UMURB_PIPE_POLICY_REQUEST 236*8a978a17SVictor Perevertkin UmUrbPipePolicyRequest; 237*8a978a17SVictor Perevertkin struct _UMURB_QUERY_PIPE 238*8a978a17SVictor Perevertkin UmUrbQueryPipe; 239*8a978a17SVictor Perevertkin struct _UMURB_GET_ASSOCIATED_INTERFACE 240*8a978a17SVictor Perevertkin UmUrbGetAssociatedInterface; 241*8a978a17SVictor Perevertkin struct _UMURB_INTERFACE_INFORMATION 242*8a978a17SVictor Perevertkin UmUrbInterfaceInformation; 243*8a978a17SVictor Perevertkin struct _UMURB_DEVICE_INFORMATION 244*8a978a17SVictor Perevertkin UmUrbDeviceInformation; 245*8a978a17SVictor Perevertkin struct _UMURB_DESCRIPTOR_REQUEST 246*8a978a17SVictor Perevertkin UmUrbDescriptorRequest; 247*8a978a17SVictor Perevertkin }; 248*8a978a17SVictor Perevertkin } UMURB, *PUMURB; 249*8a978a17SVictor Perevertkin 250*8a978a17SVictor Perevertkin 251*8a978a17SVictor Perevertkin #define FILE_DEVICE_UMDF ((ULONG)(0x8002)) 252*8a978a17SVictor Perevertkin 253*8a978a17SVictor Perevertkin // 254*8a978a17SVictor Perevertkin // Device IO Control 255*8a978a17SVictor Perevertkin // 256*8a978a17SVictor Perevertkin #define UMDF_IOCTL_CODE(id) \ 257*8a978a17SVictor Perevertkin CTL_CODE(FILE_DEVICE_UMDF, (id), METHOD_BUFFERED, FILE_READ_ACCESS|FILE_WRITE_ACCESS) 258*8a978a17SVictor Perevertkin 259*8a978a17SVictor Perevertkin #define IOCTL_INETRNAL_USB_SUBMIT_UMURB UMDF_IOCTL_CODE(0x100) 260*8a978a17SVictor Perevertkin 261