1c2c66affSColin Finck #pragma once 2c2c66affSColin Finck 3c2c66affSColin Finck #ifndef DECLSPEC_EXPORT 4c2c66affSColin Finck #define DECLSPEC_EXPORT __declspec(dllexport) 5c2c66affSColin Finck #endif 6c2c66affSColin Finck 7c2c66affSColin Finck typedef struct _USBD_INTERFACE_LIST_ENTRY { 8c2c66affSColin Finck PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor; 9c2c66affSColin Finck PUSBD_INTERFACE_INFORMATION Interface; 10c2c66affSColin Finck } USBD_INTERFACE_LIST_ENTRY, *PUSBD_INTERFACE_LIST_ENTRY; 11c2c66affSColin Finck 12c2c66affSColin Finck #define UsbBuildInterruptOrBulkTransferRequest(urb,length, pipeHandle, transferBuffer, transferBufferMDL, transferBufferLength, transferFlags, link) { \ 13c2c66affSColin Finck (urb)->UrbHeader.Function = URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER; \ 14c2c66affSColin Finck (urb)->UrbHeader.Length = (length); \ 15c2c66affSColin Finck (urb)->UrbBulkOrInterruptTransfer.PipeHandle = (pipeHandle); \ 16c2c66affSColin Finck (urb)->UrbBulkOrInterruptTransfer.TransferBufferLength = (transferBufferLength); \ 17c2c66affSColin Finck (urb)->UrbBulkOrInterruptTransfer.TransferBufferMDL = (transferBufferMDL); \ 18c2c66affSColin Finck (urb)->UrbBulkOrInterruptTransfer.TransferBuffer = (transferBuffer); \ 19c2c66affSColin Finck (urb)->UrbBulkOrInterruptTransfer.TransferFlags = (transferFlags); \ 20c2c66affSColin Finck (urb)->UrbBulkOrInterruptTransfer.UrbLink = (link); \ 21c2c66affSColin Finck } 22c2c66affSColin Finck 23c2c66affSColin Finck #define UsbBuildGetDescriptorRequest(urb, length, descriptorType, descriptorIndex, languageId, transferBuffer, transferBufferMDL, transferBufferLength, link) { \ 24c2c66affSColin Finck (urb)->UrbHeader.Function = URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE; \ 25c2c66affSColin Finck (urb)->UrbHeader.Length = (length); \ 26c2c66affSColin Finck (urb)->UrbControlDescriptorRequest.TransferBufferLength = (transferBufferLength); \ 27c2c66affSColin Finck (urb)->UrbControlDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \ 28c2c66affSColin Finck (urb)->UrbControlDescriptorRequest.TransferBuffer = (transferBuffer); \ 29c2c66affSColin Finck (urb)->UrbControlDescriptorRequest.DescriptorType = (descriptorType); \ 30c2c66affSColin Finck (urb)->UrbControlDescriptorRequest.Index = (descriptorIndex); \ 31c2c66affSColin Finck (urb)->UrbControlDescriptorRequest.LanguageId = (languageId); \ 32c2c66affSColin Finck (urb)->UrbControlDescriptorRequest.UrbLink = (link); \ 33c2c66affSColin Finck } 34c2c66affSColin Finck 35c2c66affSColin Finck #define UsbBuildGetStatusRequest(urb, op, index, transferBuffer, transferBufferMDL, link) { \ 36c2c66affSColin Finck (urb)->UrbHeader.Function = (op); \ 37c2c66affSColin Finck (urb)->UrbHeader.Length = sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST); \ 38c2c66affSColin Finck (urb)->UrbControlGetStatusRequest.TransferBufferLength = sizeof(USHORT); \ 39c2c66affSColin Finck (urb)->UrbControlGetStatusRequest.TransferBufferMDL = (transferBufferMDL); \ 40c2c66affSColin Finck (urb)->UrbControlGetStatusRequest.TransferBuffer = (transferBuffer); \ 41c2c66affSColin Finck (urb)->UrbControlGetStatusRequest.Index = (index); \ 42c2c66affSColin Finck (urb)->UrbControlGetStatusRequest.UrbLink = (link); \ 43c2c66affSColin Finck } 44c2c66affSColin Finck 45c2c66affSColin Finck #define UsbBuildFeatureRequest(urb, op, featureSelector, index, link) { \ 46c2c66affSColin Finck (urb)->UrbHeader.Function = (op); \ 47c2c66affSColin Finck (urb)->UrbHeader.Length = sizeof(struct _URB_CONTROL_FEATURE_REQUEST); \ 48c2c66affSColin Finck (urb)->UrbControlFeatureRequest.FeatureSelector = (featureSelector); \ 49c2c66affSColin Finck (urb)->UrbControlFeatureRequest.Index = (index); \ 50c2c66affSColin Finck (urb)->UrbControlFeatureRequest.UrbLink = (link); \ 51c2c66affSColin Finck } 52c2c66affSColin Finck 53c2c66affSColin Finck #define UsbBuildSelectConfigurationRequest(urb, length, configurationDescriptor) { \ 54c2c66affSColin Finck (urb)->UrbHeader.Function = URB_FUNCTION_SELECT_CONFIGURATION; \ 55c2c66affSColin Finck (urb)->UrbHeader.Length = (length); \ 56c2c66affSColin Finck (urb)->UrbSelectConfiguration.ConfigurationDescriptor = (configurationDescriptor); \ 57c2c66affSColin Finck } 58c2c66affSColin Finck 59c2c66affSColin Finck #define UsbBuildSelectInterfaceRequest(urb, length, configurationHandle, interfaceNumber, alternateSetting) { \ 60c2c66affSColin Finck (urb)->UrbHeader.Function = URB_FUNCTION_SELECT_INTERFACE; \ 61c2c66affSColin Finck (urb)->UrbHeader.Length = (length); \ 62c2c66affSColin Finck (urb)->UrbSelectInterface.Interface.AlternateSetting = (alternateSetting); \ 63c2c66affSColin Finck (urb)->UrbSelectInterface.Interface.InterfaceNumber = (interfaceNumber); \ 64c2c66affSColin Finck (urb)->UrbSelectInterface.Interface.Length = (length - sizeof(struct _URB_HEADER) - sizeof(USBD_CONFIGURATION_HANDLE)); \ 65c2c66affSColin Finck (urb)->UrbSelectInterface.ConfigurationHandle = (configurationHandle); \ 66c2c66affSColin Finck } 67c2c66affSColin Finck 68c2c66affSColin Finck #define UsbBuildVendorRequest(urb, cmd, length, transferFlags, reservedbits, request, value, index, transferBuffer, transferBufferMDL, transferBufferLength, link) { \ 69c2c66affSColin Finck (urb)->UrbHeader.Function = cmd; \ 70c2c66affSColin Finck (urb)->UrbHeader.Length = (length); \ 71c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.TransferBufferLength = (transferBufferLength); \ 72c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.TransferBufferMDL = (transferBufferMDL); \ 73c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.TransferBuffer = (transferBuffer); \ 74c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.RequestTypeReservedBits = (reservedbits); \ 75c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.Request = (request); \ 76c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.Value = (value); \ 77c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.Index = (index); \ 78c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.TransferFlags = (transferFlags); \ 79c2c66affSColin Finck (urb)->UrbControlVendorClassRequest.UrbLink = (link); \ 80c2c66affSColin Finck } 81c2c66affSColin Finck 82c2c66affSColin Finck #if (NTDDI_VERSION >= NTDDI_WINXP) 83c2c66affSColin Finck 84c2c66affSColin Finck #define UsbBuildOsFeatureDescriptorRequest(urb, length, interface, index, transferBuffer, transferBufferMDL, transferBufferLength, link) { \ 85c2c66affSColin Finck (urb)->UrbHeader.Function = URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR; \ 86c2c66affSColin Finck (urb)->UrbHeader.Length = (length); \ 87c2c66affSColin Finck (urb)->UrbOSFeatureDescriptorRequest.TransferBufferLength = (transferBufferLength); \ 88c2c66affSColin Finck (urb)->UrbOSFeatureDescriptorRequest.TransferBufferMDL = (transferBufferMDL); \ 89c2c66affSColin Finck (urb)->UrbOSFeatureDescriptorRequest.TransferBuffer = (transferBuffer); \ 90c2c66affSColin Finck (urb)->UrbOSFeatureDescriptorRequest.InterfaceNumber = (interface); \ 91c2c66affSColin Finck (urb)->UrbOSFeatureDescriptorRequest.MS_FeatureDescriptorIndex = (index); \ 92*d7d716a6SVictor Perevertkin (urb)->UrbOSFeatureDescriptorRequest.UrbLink = (link); \ 93c2c66affSColin Finck } 94c2c66affSColin Finck 95c2c66affSColin Finck #endif /* NTDDI_VERSION >= NTDDI_WINXP */ 96c2c66affSColin Finck 97*d7d716a6SVictor Perevertkin #if (NTDDI_VERSION >= NTDDI_VISTA) 98*d7d716a6SVictor Perevertkin 99*d7d716a6SVictor Perevertkin #define USBD_CLIENT_CONTRACT_VERSION_INVALID 0xFFFFFFFF 100*d7d716a6SVictor Perevertkin #define USBD_CLIENT_CONTRACT_VERSION_602 0x602 101*d7d716a6SVictor Perevertkin 102*d7d716a6SVictor Perevertkin #define USBD_INTERFACE_VERSION_600 0x600 103*d7d716a6SVictor Perevertkin #define USBD_INTERFACE_VERSION_602 0x602 104*d7d716a6SVictor Perevertkin #define USBD_INTERFACE_VERSION_603 0x603 105*d7d716a6SVictor Perevertkin 106*d7d716a6SVictor Perevertkin DECLARE_HANDLE(USBD_HANDLE); 107*d7d716a6SVictor Perevertkin 108*d7d716a6SVictor Perevertkin #endif // NTDDI_VISTA 109*d7d716a6SVictor Perevertkin 110c2c66affSColin Finck #define URB_STATUS(urb) ((urb)->UrbHeader.Status) 111c2c66affSColin Finck 112c2c66affSColin Finck #define GET_SELECT_CONFIGURATION_REQUEST_SIZE(totalInterfaces, totalPipes) \ 113c2c66affSColin Finck (sizeof(struct _URB_SELECT_CONFIGURATION) + \ 114c2c66affSColin Finck ((totalInterfaces-1) * sizeof(USBD_INTERFACE_INFORMATION)) + \ 115c2c66affSColin Finck ((totalPipes-totalInterfaces)*sizeof(USBD_PIPE_INFORMATION))) 116c2c66affSColin Finck 117c2c66affSColin Finck #define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes) \ 118c2c66affSColin Finck (sizeof(struct _URB_SELECT_INTERFACE) + \ 119c2c66affSColin Finck ((totalPipes-1)*sizeof(USBD_PIPE_INFORMATION))) 120c2c66affSColin Finck 121c2c66affSColin Finck #define GET_USBD_INTERFACE_SIZE(numEndpoints) \ 122c2c66affSColin Finck (sizeof(USBD_INTERFACE_INFORMATION) + \ 123c2c66affSColin Finck (sizeof(USBD_PIPE_INFORMATION)*(numEndpoints)) - sizeof(USBD_PIPE_INFORMATION)) 124c2c66affSColin Finck 125c2c66affSColin Finck #define GET_ISO_URB_SIZE(n) (sizeof(struct _URB_ISOCH_TRANSFER)+ \ 126c2c66affSColin Finck sizeof(USBD_ISO_PACKET_DESCRIPTOR)*n) 127c2c66affSColin Finck 128c2c66affSColin Finck #ifndef _USBD_ 129c2c66affSColin Finck 130c2c66affSColin Finck _IRQL_requires_max_(DISPATCH_LEVEL) 131c2c66affSColin Finck DECLSPEC_IMPORT 132c2c66affSColin Finck VOID 133c2c66affSColin Finck NTAPI 134c2c66affSColin Finck USBD_GetUSBDIVersion( 135c2c66affSColin Finck _Out_ PUSBD_VERSION_INFORMATION VersionInformation); 136c2c66affSColin Finck 137c2c66affSColin Finck DECLSPEC_IMPORT 138c2c66affSColin Finck PUSB_INTERFACE_DESCRIPTOR 139c2c66affSColin Finck NTAPI 140c2c66affSColin Finck USBD_ParseConfigurationDescriptor( 141c2c66affSColin Finck _In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 142c2c66affSColin Finck _In_ UCHAR InterfaceNumber, 143c2c66affSColin Finck _In_ UCHAR AlternateSetting); 144c2c66affSColin Finck 145c2c66affSColin Finck DECLSPEC_IMPORT 146c2c66affSColin Finck PURB 147c2c66affSColin Finck NTAPI 148c2c66affSColin Finck USBD_CreateConfigurationRequest( 149c2c66affSColin Finck _In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 150c2c66affSColin Finck _Out_ PUSHORT Siz); 151c2c66affSColin Finck 152c2c66affSColin Finck _IRQL_requires_max_(APC_LEVEL) 153c2c66affSColin Finck DECLSPEC_IMPORT 154c2c66affSColin Finck PUSB_COMMON_DESCRIPTOR 155c2c66affSColin Finck NTAPI 156c2c66affSColin Finck USBD_ParseDescriptors( 157c2c66affSColin Finck _In_ PVOID DescriptorBuffer, 158c2c66affSColin Finck _In_ ULONG TotalLength, 159c2c66affSColin Finck _In_ PVOID StartPosition, 160c2c66affSColin Finck _In_ LONG DescriptorType); 161c2c66affSColin Finck 162c2c66affSColin Finck _IRQL_requires_max_(APC_LEVEL) 163c2c66affSColin Finck DECLSPEC_IMPORT 164c2c66affSColin Finck PUSB_INTERFACE_DESCRIPTOR 165c2c66affSColin Finck NTAPI 166c2c66affSColin Finck USBD_ParseConfigurationDescriptorEx( 167c2c66affSColin Finck _In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 168c2c66affSColin Finck _In_ PVOID StartPosition, 169c2c66affSColin Finck _In_ LONG InterfaceNumber, 170c2c66affSColin Finck _In_ LONG AlternateSetting, 171c2c66affSColin Finck _In_ LONG InterfaceClass, 172c2c66affSColin Finck _In_ LONG InterfaceSubClass, 173c2c66affSColin Finck _In_ LONG InterfaceProtocol); 174c2c66affSColin Finck 175c2c66affSColin Finck _IRQL_requires_max_(DISPATCH_LEVEL) 176c2c66affSColin Finck DECLSPEC_IMPORT 177c2c66affSColin Finck PURB 178c2c66affSColin Finck NTAPI 179c2c66affSColin Finck USBD_CreateConfigurationRequestEx( 180c2c66affSColin Finck _In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor, 181c2c66affSColin Finck _In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList); 182c2c66affSColin Finck 183c2c66affSColin Finck _IRQL_requires_max_(PASSIVE_LEVEL) 184c2c66affSColin Finck DECLSPEC_EXPORT 185c2c66affSColin Finck ULONG 186c2c66affSColin Finck NTAPI 187c2c66affSColin Finck USBD_GetInterfaceLength( 188c2c66affSColin Finck _In_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor, 189c2c66affSColin Finck _In_ PUCHAR BufferEnd); 190c2c66affSColin Finck 191c2c66affSColin Finck _IRQL_requires_max_(PASSIVE_LEVEL) 192c2c66affSColin Finck DECLSPEC_EXPORT 193c2c66affSColin Finck VOID 194c2c66affSColin Finck NTAPI 195c2c66affSColin Finck USBD_RegisterHcFilter( 196c2c66affSColin Finck _In_ PDEVICE_OBJECT DeviceObject, 197c2c66affSColin Finck _In_ PDEVICE_OBJECT FilterDeviceObject); 198c2c66affSColin Finck 199c2c66affSColin Finck _IRQL_requires_max_(APC_LEVEL) 200c2c66affSColin Finck DECLSPEC_EXPORT 201c2c66affSColin Finck NTSTATUS 202c2c66affSColin Finck NTAPI 203c2c66affSColin Finck USBD_GetPdoRegistryParameter( 204c2c66affSColin Finck _In_ PDEVICE_OBJECT PhysicalDeviceObject, 205c2c66affSColin Finck _Inout_updates_bytes_(ParameterLength) PVOID Parameter, 206c2c66affSColin Finck _In_ ULONG ParameterLength, 207c2c66affSColin Finck _In_reads_bytes_(KeyNameLength) PWSTR KeyName, 208c2c66affSColin Finck _In_ ULONG KeyNameLength); 209c2c66affSColin Finck 210c2c66affSColin Finck DECLSPEC_EXPORT 211c2c66affSColin Finck NTSTATUS 212c2c66affSColin Finck NTAPI 213c2c66affSColin Finck USBD_QueryBusTime( 214c2c66affSColin Finck _In_ PDEVICE_OBJECT RootHubPdo, 215c2c66affSColin Finck _Out_ PULONG CurrentFrame); 216c2c66affSColin Finck 217c2c66affSColin Finck #if (NTDDI_VERSION >= NTDDI_WINXP) 218c2c66affSColin Finck 219c2c66affSColin Finck _IRQL_requires_max_(DISPATCH_LEVEL) 220c2c66affSColin Finck DECLSPEC_IMPORT 221c2c66affSColin Finck ULONG 222c2c66affSColin Finck NTAPI 223c2c66affSColin Finck USBD_CalculateUsbBandwidth( 224c2c66affSColin Finck _In_ ULONG MaxPacketSize, 225c2c66affSColin Finck _In_ UCHAR EndpointType, 226c2c66affSColin Finck _In_ BOOLEAN LowSpeed); 227c2c66affSColin Finck 228c2c66affSColin Finck #endif 229c2c66affSColin Finck 230c2c66affSColin Finck #if (NTDDI_VERSION >= NTDDI_VISTA) 231c2c66affSColin Finck 232c2c66affSColin Finck _IRQL_requires_max_(DISPATCH_LEVEL) 233c2c66affSColin Finck DECLSPEC_IMPORT 234c2c66affSColin Finck USBD_STATUS 235c2c66affSColin Finck NTAPI 236c2c66affSColin Finck USBD_ValidateConfigurationDescriptor( 237c2c66affSColin Finck _In_reads_bytes_(BufferLength) PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc, 238c2c66affSColin Finck _In_ ULONG BufferLength, 239c2c66affSColin Finck _In_ USHORT Level, 240c2c66affSColin Finck _Out_ PUCHAR *Offset, 241c2c66affSColin Finck _In_opt_ ULONG Tag); 242c2c66affSColin Finck 243c2c66affSColin Finck #endif 244c2c66affSColin Finck 245c2c66affSColin Finck #endif /* ! _USBD_ */ 246