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