[DDK]
[reactos.git] / reactos / include / ddk / usbdlib.h
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 #define URB_STATUS(urb) ((urb)->UrbHeader.Status)
98
99 #define GET_SELECT_CONFIGURATION_REQUEST_SIZE(totalInterfaces, totalPipes) \
100 (sizeof(struct _URB_SELECT_CONFIGURATION) + \
101 ((totalInterfaces-1) * sizeof(USBD_INTERFACE_INFORMATION)) + \
102 ((totalPipes-totalInterfaces)*sizeof(USBD_PIPE_INFORMATION)))
103
104 #define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes) \
105 (sizeof(struct _URB_SELECT_INTERFACE) + \
106 ((totalPipes-1)*sizeof(USBD_PIPE_INFORMATION)))
107
108 #define GET_USBD_INTERFACE_SIZE(numEndpoints) \
109 (sizeof(USBD_INTERFACE_INFORMATION) + \
110 (sizeof(USBD_PIPE_INFORMATION)*(numEndpoints)) - sizeof(USBD_PIPE_INFORMATION))
111
112 #define GET_ISO_URB_SIZE(n) (sizeof(struct _URB_ISOCH_TRANSFER)+ \
113 sizeof(USBD_ISO_PACKET_DESCRIPTOR)*n)
114
115 #ifndef _USBD_
116
117 DECLSPEC_IMPORT
118 VOID
119 NTAPI
120 USBD_GetUSBDIVersion(
121 OUT PUSBD_VERSION_INFORMATION VersionInformation);
122
123 DECLSPEC_IMPORT
124 PUSB_INTERFACE_DESCRIPTOR
125 NTAPI
126 USBD_ParseConfigurationDescriptor(
127 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
128 IN UCHAR InterfaceNumber,
129 IN UCHAR AlternateSetting);
130
131 DECLSPEC_IMPORT
132 PURB
133 NTAPI
134 USBD_CreateConfigurationRequest(
135 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
136 OUT PUSHORT Siz);
137
138 DECLSPEC_IMPORT
139 PUSB_COMMON_DESCRIPTOR
140 NTAPI
141 USBD_ParseDescriptors(
142 IN PVOID DescriptorBuffer,
143 IN ULONG TotalLength,
144 IN PVOID StartPosition,
145 IN LONG DescriptorType);
146
147 DECLSPEC_IMPORT
148 PUSB_INTERFACE_DESCRIPTOR
149 NTAPI
150 USBD_ParseConfigurationDescriptorEx(
151 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
152 IN PVOID StartPosition,
153 IN LONG InterfaceNumber,
154 IN LONG AlternateSetting,
155 IN LONG InterfaceClass,
156 IN LONG InterfaceSubClass,
157 IN LONG InterfaceProtocol);
158
159 DECLSPEC_IMPORT
160 PURB
161 NTAPI
162 USBD_CreateConfigurationRequestEx(
163 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
164 IN PUSBD_INTERFACE_LIST_ENTRY InterfaceList);
165
166 DECLSPEC_EXPORT
167 ULONG
168 NTAPI
169 USBD_GetInterfaceLength(
170 IN PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
171 IN PUCHAR BufferEnd);
172
173 DECLSPEC_EXPORT
174 VOID
175 NTAPI
176 USBD_RegisterHcFilter(
177 IN PDEVICE_OBJECT DeviceObject,
178 IN PDEVICE_OBJECT FilterDeviceObject);
179
180 DECLSPEC_EXPORT
181 NTSTATUS
182 NTAPI
183 USBD_GetPdoRegistryParameter(
184 IN PDEVICE_OBJECT PhysicalDeviceObject,
185 IN OUT PVOID Parameter,
186 IN ULONG ParameterLength,
187 IN PWSTR KeyName,
188 IN ULONG KeyNameLength);
189
190 DECLSPEC_EXPORT
191 NTSTATUS
192 NTAPI
193 USBD_QueryBusTime(
194 IN PDEVICE_OBJECT RootHubPdo,
195 OUT PULONG CurrentFrame);
196
197 #if (NTDDI_VERSION >= NTDDI_WINXP)
198
199 DECLSPEC_IMPORT
200 ULONG
201 NTAPI
202 USBD_CalculateUsbBandwidth(
203 IN ULONG MaxPacketSize,
204 IN UCHAR EndpointType,
205 IN BOOLEAN LowSpeed);
206
207 #endif
208
209 #if (NTDDI_VERSION >= NTDDI_VISTA)
210
211 DECLSPEC_IMPORT
212 USBD_STATUS
213 NTAPI
214 USBD_ValidateConfigurationDescriptor(
215 IN PUSB_CONFIGURATION_DESCRIPTOR ConfigDesc,
216 IN ULONG BufferLength,
217 IN USHORT Level,
218 OUT PUCHAR *Offset,
219 IN ULONG Tag OPTIONAL);
220
221 #endif
222
223 #endif /* ! _USBD_ */
224