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