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