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