summaryrefslogtreecommitdiff
path: root/usb/driver/usbdlib_gcc.h
blob: 5dec851acd0c421462eae994679621eed6eefe12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310

#ifndef __USBDLIB_H
#define __USBDLIB_H

#if __GNUC__ >=3
#pragma GCC system_header
#endif

#ifdef __cplusplus
extern "C"
{
#endif

#pragma pack(push,4)


    typedef struct _USBD_INTERFACE_LIST_ENTRY
    {
        PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
        PUSBD_INTERFACE_INFORMATION Interface;
    } USBD_INTERFACE_LIST_ENTRY, *PUSBD_INTERFACE_LIST_ENTRY;


#define URB_STATUS(urb) ((urb)->UrbHeader.Status)

#define GET_SELECT_CONFIGURATION_REQUEST_SIZE(totalInterfaces, totalPipes) \
             (sizeof(struct _URB_SELECT_CONFIGURATION) \
             + ((totalInterfaces - 1) * sizeof(USBD_INTERFACE_INFORMATION)) \
             + ((totalPipes - 1) * sizeof(USBD_PIPE_INFORMATION)))

#define GET_SELECT_INTERFACE_REQUEST_SIZE(totalPipes) \
             (sizeof(struct _URB_SELECT_INTERFACE) \
             + ((totalPipes - 1) * sizeof(USBD_PIPE_INFORMATION)))

#define GET_USBD_INTERFACE_SIZE(numEndpoints) \
             (sizeof(USBD_INTERFACE_INFORMATION) \
             + (sizeof(USBD_PIPE_INFORMATION)*(numEndpoints)) \
             - sizeof(USBD_PIPE_INFORMATION))

#define GET_ISO_URB_SIZE(n) (sizeof(struct _URB_ISOCH_TRANSFER) \
             + sizeof(USBD_ISO_PACKET_DESCRIPTOR) * n)


#define UsbBuildInterruptOrBulkTransferRequest(urb, \
                                               length, \
                                               pipeHandle, \
                                               transferBuffer, \
                                               transferBufferMDL, \
                                               transferBufferLength, \
                                               transferFlags, \
                                               link) { \
            (urb)->UrbHeader.Function = \
                   URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER; \
            (urb)->UrbHeader.Length = (length); \
            (urb)->UrbBulkOrInterruptTransfer.PipeHandle = (pipeHandle); \
            (urb)->UrbBulkOrInterruptTransfer.TransferBufferLength = \
                   (transferBufferLength); \
            (urb)->UrbBulkOrInterruptTransfer.TransferBufferMDL = \
                   (transferBufferMDL); \
            (urb)->UrbBulkOrInterruptTransfer.TransferBuffer = \
                   (transferBuffer); \
            (urb)->UrbBulkOrInterruptTransfer.TransferFlags = \
                   (transferFlags); \
            (urb)->UrbBulkOrInterruptTransfer.UrbLink = (link); }


#define UsbBuildGetDescriptorRequest(urb, \
                                     length, \
                                     descriptorType, \
                                     descriptorIndex, \
                                     languageId, \
                                     transferBuffer, \
                                     transferBufferMDL, \
                                     transferBufferLength, \
                                     link) { \
            (urb)->UrbHeader.Function =  \
                   URB_FUNCTION_GET_DESCRIPTOR_FROM_DEVICE; \
            (urb)->UrbHeader.Length = (length); \
            (urb)->UrbControlDescriptorRequest.TransferBufferLength = \
                   (transferBufferLength); \
            (urb)->UrbControlDescriptorRequest.TransferBufferMDL = \
                   (transferBufferMDL); \
            (urb)->UrbControlDescriptorRequest.TransferBuffer = \
                   (transferBuffer); \
            (urb)->UrbControlDescriptorRequest.DescriptorType = \
                   (descriptorType); \
            (urb)->UrbControlDescriptorRequest.Index = (descriptorIndex); \
            (urb)->UrbControlDescriptorRequest.LanguageId = (languageId); \
            (urb)->UrbControlDescriptorRequest.UrbLink = (link); }



#define UsbBuildGetStatusRequest(urb, \
                                 op, \
                                 index, \
                                 transferBuffer, \
                                 transferBufferMDL, \
                                 link) { \
            (urb)->UrbHeader.Function =  (op); \
            (urb)->UrbHeader.Length = \
                   sizeof(struct _URB_CONTROL_GET_STATUS_REQUEST); \
            (urb)->UrbControlGetStatusRequest.TransferBufferLength = \
                   sizeof(USHORT); \
            (urb)->UrbControlGetStatusRequest.TransferBufferMDL = \
                   (transferBufferMDL); \
            (urb)->UrbControlGetStatusRequest.TransferBuffer = \
                   (transferBuffer); \
            (urb)->UrbControlGetStatusRequest.Index = (index); \
            (urb)->UrbControlGetStatusRequest.UrbLink = (link); }


#define UsbBuildFeatureRequest(urb, \
                               op, \
                               featureSelector, \
                               index, \
                               link) { \
            (urb)->UrbHeader.Function =  (op); \
            (urb)->UrbHeader.Length = \
                   sizeof(struct _URB_CONTROL_FEATURE_REQUEST); \
            (urb)->UrbControlFeatureRequest.FeatureSelector = \
                   (featureSelector); \
            (urb)->UrbControlFeatureRequest.Index = (index); \
            (urb)->UrbControlFeatureRequest.UrbLink = (link); }



#define UsbBuildSelectConfigurationRequest(urb, \
                                         length, \
                                         configurationDescriptor) { \
            (urb)->UrbHeader.Function =  URB_FUNCTION_SELECT_CONFIGURATION; \
            (urb)->UrbHeader.Length = (length); \
            (urb)->UrbSelectConfiguration.ConfigurationDescriptor = \
                   (configurationDescriptor); }

#define UsbBuildSelectInterfaceRequest(urb, \
                                      length, \
                                      configurationHandle, \
                                      interfaceNumber, \
                                      alternateSetting) { \
            (urb)->UrbHeader.Function =  URB_FUNCTION_SELECT_INTERFACE; \
            (urb)->UrbHeader.Length = (length); \
            (urb)->UrbSelectInterface.Interface.AlternateSetting = \
                   (alternateSetting); \
            (urb)->UrbSelectInterface.Interface.InterfaceNumber = \
                   (interfaceNumber); \
            (urb)->UrbSelectInterface.ConfigurationHandle = \
                   (configurationHandle); }


#define UsbBuildVendorRequest(urb, \
                              cmd, \
                              length, \
                              transferFlags, \
                              reservedbits, \
                              request, \
                              value, \
                              index, \
                              transferBuffer, \
                              transferBufferMDL, \
                              transferBufferLength, \
                              link) { \
            (urb)->UrbHeader.Function =  cmd; \
            (urb)->UrbHeader.Length = (length); \
            (urb)->UrbControlVendorClassRequest.TransferBufferLength = \
                   (transferBufferLength); \
            (urb)->UrbControlVendorClassRequest.TransferBufferMDL = \
                   (transferBufferMDL); \
            (urb)->UrbControlVendorClassRequest.TransferBuffer = \
                   (transferBuffer); \
            (urb)->UrbControlVendorClassRequest.RequestTypeReservedBits = \
                   (reservedbits); \
            (urb)->UrbControlVendorClassRequest.Request = (request); \
            (urb)->UrbControlVendorClassRequest.Value = (value); \
            (urb)->UrbControlVendorClassRequest.Index = (index); \
            (urb)->UrbControlVendorClassRequest.TransferFlags = \
                   (transferFlags); \
            (urb)->UrbControlVendorClassRequest.UrbLink = (link); }


#define UsbBuildOsFeatureDescriptorRequest(urb, \
                              length, \
                              interface, \
                              index, \
                              transferBuffer, \
                              transferBufferMDL, \
                              transferBufferLength, \
                              link) { \
            (urb)->UrbHeader.Function = \
                   URB_FUNCTION_GET_MS_FEATURE_DESCRIPTOR; \
            (urb)->UrbHeader.Length = (length); \
            (urb)->UrbOSFeatureDescriptorRequest.TransferBufferLength = \
                   (transferBufferLength); \
            (urb)->UrbOSFeatureDescriptorRequest.TransferBufferMDL = \
                   (transferBufferMDL); \
            (urb)->UrbOSFeatureDescriptorRequest.TransferBuffer = \
                   (transferBuffer); \
            (urb)->UrbOSFeatureDescriptorRequest.InterfaceNumber = \
                   (interface); \
            (urb)->UrbOSFeatureDescriptorRequest.MS_FeatureDescriptorIndex = \
                   (index); \
            (urb)->UrbOSFeatureDescriptorRequest.UrbLink = (link); }


    VOID
    DDKAPI
    USBD_Debug_LogEntry(
        IN CHAR *Name,
        IN ULONG Info1,
        IN ULONG Info2,
        IN ULONG Info3
    );

    VOID
    DDKAPI
    USBD_GetUSBDIVersion(
        PUSBD_VERSION_INFORMATION VersionInformation
    );


    PUSB_INTERFACE_DESCRIPTOR
    DDKAPI
    USBD_ParseConfigurationDescriptor(
        IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
        IN UCHAR InterfaceNumber,
        IN UCHAR AlternateSetting
    );

    PURB
    DDKAPI
    USBD_CreateConfigurationRequest(
        IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
        IN OUT PUSHORT Siz
    );

    PUSB_COMMON_DESCRIPTOR
    DDKAPI
    USBD_ParseDescriptors(
        IN PVOID DescriptorBuffer,
        IN ULONG TotalLength,
        IN PVOID StartPosition,
        IN LONG DescriptorType
    );

    PUSB_INTERFACE_DESCRIPTOR
    DDKAPI
    USBD_ParseConfigurationDescriptorEx(
        IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
        IN PVOID StartPosition,
        IN LONG InterfaceNumber,
        IN LONG AlternateSetting,
        IN LONG InterfaceClass,
        IN LONG InterfaceSubClass,
        IN LONG InterfaceProtocol
    );

    PURB
    DDKAPI
    USBD_CreateConfigurationRequestEx(
        IN PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor,
        IN PUSBD_INTERFACE_LIST_ENTRY InterfaceList
    );

    ULONG
    DDKAPI
    USBD_GetInterfaceLength(
        IN PUSB_INTERFACE_DESCRIPTOR InterfaceDescriptor,
        IN PUCHAR BufferEnd
    );

    VOID
    DDKAPI
    USBD_RegisterHcFilter(
        PDEVICE_OBJECT DeviceObject,
        PDEVICE_OBJECT FilterDeviceObject
    );

    NTSTATUS
    DDKAPI
    USBD_GetPdoRegistryParameter(
        IN PDEVICE_OBJECT PhysicalDeviceObject,
        IN OUT PVOID Parameter,
        IN ULONG ParameterLength,
        IN PWCHAR KeyName,
        IN ULONG KeyNameLength
    );

    NTSTATUS
    DDKAPI
    USBD_QueryBusTime(
        IN PDEVICE_OBJECT RootHubPdo,
        IN PULONG CurrentFrame
    );

    ULONG
    DDKAPI
    USBD_CalculateUsbBandwidth(
        ULONG MaxPacketSize,
        UCHAR EndpointType,
        BOOLEAN LowSpeed
    );


#pragma pack(pop)

#ifdef __cplusplus
}
#endif

#endif /* __USBDLIB_H */