Reactos
1#pragma once
2
3#ifndef DECLSPEC_EXPORT
4#define DECLSPEC_EXPORT __declspec(dllexport)
5#endif
6
7typedef 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
106DECLARE_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)
131DECLSPEC_IMPORT
132VOID
133NTAPI
134USBD_GetUSBDIVersion(
135 _Out_ PUSBD_VERSION_INFORMATION VersionInformation);
136
137DECLSPEC_IMPORT
138PUSB_INTERFACE_DESCRIPTOR
139NTAPI
140USBD_ParseConfigurationDescriptor(
141 _In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
142 _In_ UCHAR InterfaceNumber,
143 _In_ UCHAR AlternateSetting);
144
145DECLSPEC_IMPORT
146PURB
147NTAPI
148USBD_CreateConfigurationRequest(
149 _In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
150 _Out_ PUSHORT Siz);
151
152_IRQL_requires_max_(APC_LEVEL)
153DECLSPEC_IMPORT
154PUSB_COMMON_DESCRIPTOR
155NTAPI
156USBD_ParseDescriptors(
157 _In_ PVOID DescriptorBuffer,
158 _In_ ULONG TotalLength,
159 _In_ PVOID StartPosition,
160 _In_ LONG DescriptorType);
161
162_IRQL_requires_max_(APC_LEVEL)
163DECLSPEC_IMPORT
164PUSB_INTERFACE_DESCRIPTOR
165NTAPI
166USBD_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)
176DECLSPEC_IMPORT
177PURB
178NTAPI
179USBD_CreateConfigurationRequestEx(
180 _In_ PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
181 _In_ PUSBD_INTERFACE_LIST_ENTRY InterfaceList);
182
183_IRQL_requires_max_(PASSIVE_LEVEL)
184DECLSPEC_EXPORT
185ULONG
186NTAPI
187USBD_GetInterfaceLength(
188 _In_ PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
189 _In_ PUCHAR BufferEnd);
190
191_IRQL_requires_max_(PASSIVE_LEVEL)
192DECLSPEC_EXPORT
193VOID
194NTAPI
195USBD_RegisterHcFilter(
196 _In_ PDEVICE_OBJECT DeviceObject,
197 _In_ PDEVICE_OBJECT FilterDeviceObject);
198
199_IRQL_requires_max_(APC_LEVEL)
200DECLSPEC_EXPORT
201NTSTATUS
202NTAPI
203USBD_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
210DECLSPEC_EXPORT
211NTSTATUS
212NTAPI
213USBD_QueryBusTime(
214 _In_ PDEVICE_OBJECT RootHubPdo,
215 _Out_ PULONG CurrentFrame);
216
217#if (NTDDI_VERSION >= NTDDI_WINXP)
218
219_IRQL_requires_max_(DISPATCH_LEVEL)
220DECLSPEC_IMPORT
221ULONG
222NTAPI
223USBD_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)
233DECLSPEC_IMPORT
234USBD_STATUS
235NTAPI
236USBD_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/* UsbdEx lib */
244
245_Must_inspect_result_
246_IRQL_requires_(PASSIVE_LEVEL)
247NTSTATUS
248USBD_QueryUsbCapability(
249 _In_ USBD_HANDLE USBDHandle,
250 _In_ const GUID* CapabilityType,
251 _In_ ULONG OutputBufferLength,
252 _When_(OutputBufferLength == 0, _Pre_null_)
253 _When_(OutputBufferLength != 0 && ResultLength == NULL, _Out_writes_bytes_(OutputBufferLength))
254 _When_(OutputBufferLength != 0 && ResultLength != NULL, _Out_writes_bytes_to_opt_(OutputBufferLength, *ResultLength))
255 PUCHAR OutputBuffer,
256 _Out_opt_
257 _When_(ResultLength != NULL, _Deref_out_range_(<=,OutputBufferLength))
258 PULONG ResultLength
259);
260
261_IRQL_requires_max_(DISPATCH_LEVEL)
262VOID
263USBD_AssignUrbToIoStackLocation(
264 _In_ USBD_HANDLE USBDHandle,
265 _In_ PIO_STACK_LOCATION IoStackLocation,
266 _In_ PURB Urb
267);
268
269_Must_inspect_result_
270_IRQL_requires_(PASSIVE_LEVEL)
271NTSTATUS
272USBD_CreateHandle(
273 _In_ PDEVICE_OBJECT DeviceObject,
274 _In_ PDEVICE_OBJECT TargetDeviceObject,
275 _In_ ULONG USBDClientContractVersion,
276 _In_ ULONG PoolTag,
277 _Out_ USBD_HANDLE *USBDHandle
278);
279
280VOID
281USBD_CloseHandle(
282 _In_ USBD_HANDLE USBDHandle
283);
284
285_IRQL_requires_max_(DISPATCH_LEVEL)
286_Must_inspect_result_
287NTSTATUS
288USBD_UrbAllocate(
289 _In_ USBD_HANDLE USBDHandle,
290 _Outptr_result_bytebuffer_(sizeof(URB)) PURB *Urb
291);
292
293_IRQL_requires_max_(DISPATCH_LEVEL)
294_Must_inspect_result_
295NTSTATUS
296USBD_IsochUrbAllocate(
297 _In_ USBD_HANDLE USBDHandle,
298 _In_ ULONG NumberOfIsochPacket,
299 _Outptr_result_bytebuffer_(sizeof(struct _URB_ISOCH_TRANSFER)
300 + (NumberOfIsochPackets * sizeof(USBD_ISO_PACKET_DESCRIPTOR))
301 - sizeof(USBD_ISO_PACKET_DESCRIPTOR))
302 PURB *Urb
303);
304
305_IRQL_requires_max_(DISPATCH_LEVEL)
306VOID
307USBD_UrbFree(
308 _In_ USBD_HANDLE USBDHandle,
309 _In_ PURB Urb
310);
311
312#endif
313
314#endif /* ! _USBD_ */