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