summaryrefslogtreecommitdiff
path: root/usb/driver/driver_api.h
blob: 5339a8168c43bfb243107601f08c8417b375137b (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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
/* libusb-win32, Generic Windows USB Library
 * Copyright (c) 2002-2005 Stephan Meyer <ste_meyer@web.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */


#ifndef __DRIVER_API_H__
#define __DRIVER_API_H__

enum
{
    LIBUSB_DEBUG_OFF,
    LIBUSB_DEBUG_ERR,
    LIBUSB_DEBUG_WRN,
    LIBUSB_DEBUG_MSG,

    LIBUSB_DEBUG_MAX = 0xff,
};


/* 64k */
#define LIBUSB_MAX_READ_WRITE 0x10000

#define LIBUSB_MAX_NUMBER_OF_DEVICES 256
#define LIBUSB_MAX_NUMBER_OF_CHILDREN 32

#define LIBUSB_IOCTL_SET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x801, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x802, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x803, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_SET_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x805, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_CLEAR_FEATURE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x806, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_STATUS CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x807, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_SET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x808, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_DESCRIPTOR CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x809, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_INTERRUPT_OR_BULK_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_VENDOR_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80C, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_VENDOR_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80D, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_RESET_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80E, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_ABORT_ENDPOINT CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x80F, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_RESET_DEVICE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x810, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_SET_DEBUG_LEVEL CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x811, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_VERSION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x812, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_ISOCHRONOUS_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x813, METHOD_IN_DIRECT, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_ISOCHRONOUS_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x814, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x815, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x816, METHOD_BUFFERED, FILE_ANY_ACCESS)

/////////////////////////////////////////////////////////////////////////////
// supported after 0.1.12.2
/////////////////////////////////////////////////////////////////////////////

// [trobinso] adds support for querying device properties
#define LIBUSB_IOCTL_GET_DEVICE_PROPERTY CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x900, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_CUSTOM_REG_PROPERTY CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x901, METHOD_BUFFERED, FILE_ANY_ACCESS)

/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// supported after 1.2.0.0
/////////////////////////////////////////////////////////////////////////////
#define LIBUSB_IOCTL_GET_CACHED_CONFIGURATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x902, METHOD_BUFFERED, FILE_ANY_ACCESS)
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// supported after 1.2.2.0
/////////////////////////////////////////////////////////////////////////////
#define LIBUSB_IOCTL_GET_OBJECT_NAME CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x8FF, METHOD_BUFFERED, FILE_ANY_ACCESS)
/////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////
// supported after 1.2.3.0
/////////////////////////////////////////////////////////////////////////////
#define LIBUSB_IOCTL_QUERY_DEVICE_INFORMATION CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x904, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_SET_PIPE_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x906, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_PIPE_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x907, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_SET_POWER_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x908, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_GET_POWER_POLICY CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x909, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_CONTROL_WRITE CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x90A, METHOD_IN_DIRECT, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_CONTROL_READ CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x90B, METHOD_OUT_DIRECT, FILE_ANY_ACCESS)

#define LIBUSB_IOCTL_FLUSH_PIPE CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x90C, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSBK_IOCTL_CLAIM_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x90D, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSBK_IOCTL_RELEASE_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x90E, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSBK_IOCTL_RELEASE_ALL_INTERFACES CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x90F, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSBK_IOCTL_SET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x910, METHOD_BUFFERED, FILE_ANY_ACCESS)

#define LIBUSBK_IOCTL_GET_INTERFACE CTL_CODE(FILE_DEVICE_UNKNOWN,\
        0x911, METHOD_BUFFERED, FILE_ANY_ACCESS)

/////////////////////////////////////////////////////////////////////////////
// supported after 1.2.4.8 (libusb0.sys only)
/////////////////////////////////////////////////////////////////////////////
#define LIBUSB_IOCTL_RESET_DEVICE_EX CTL_CODE(FILE_DEVICE_UNKNOWN,\
0x817, METHOD_BUFFERED, FILE_ANY_ACCESS)

#include <pshpack1.h>

enum LIBUSB0_TRANSFER_FLAGS
{
	TRANSFER_FLAGS_SHORT_NOT_OK = 1 << 0,
	TRANSFER_FLAGS_ISO_SET_START_FRAME = 1 << 30,
	TRANSFER_FLAGS_ISO_ADD_LATENCY = 1 << 31,
};

/*
typedef struct
{
    unsigned int timeout;
    union
    {
        struct
        {
            unsigned int configuration;
        } configuration;
        struct
        {
            unsigned int interface;
            unsigned int altsetting;
        } interface;
        struct
        {
            unsigned int endpoint;
            unsigned int packet_size;
	
			// TODO: max_transfer_size, short transfer not ok, use iso_start_frame
			unsigned int max_transfer_size;
			unsigned int transfer_flags;
			unsigned int iso_start_frame_latency;
        } endpoint;
        struct
        {
            unsigned int type;
            unsigned int recipient;
            unsigned int request;
            unsigned int value;
            unsigned int index;
        } vendor;
        struct
        {
            unsigned int recipient;
            unsigned int feature;
            unsigned int index;
        } feature;
        struct
        {
            unsigned int recipient;
            unsigned int index;
            unsigned int status;
        } status;
        struct
        {
            unsigned int type;
            unsigned int index;
            unsigned int language_id;
            unsigned int recipient;
        } descriptor;
        struct
        {
            unsigned int level;
        } debug;
        struct
        {
            unsigned int major;
            unsigned int minor;
            unsigned int micro;
            unsigned int nano;
			unsigned int mod_value;
        } version;
		struct
		{
			unsigned int property;
		} device_property;
		struct
		{
			unsigned int key_type;
			unsigned int name_offset;
			unsigned int value_offset;
			unsigned int value_length;
		} device_registry_key;
		struct
		{
			// 0 - device plug and play registry key pathname
			unsigned int objname_index;
		} objname;
    };
} libusb_request;
*/

#pragma warning(disable:4201)

typedef struct
{
	unsigned int interface_number;
	unsigned int altsetting_number;

	unsigned char intf_use_index:1;	// libusbK Only
	unsigned char altf_use_index:1;	// libusbK Only
	unsigned char:6;

	short interface_index;		// libusbK Only
	short altsetting_index;		// libusbK Only
}interface_request_t;

typedef struct
{
	unsigned int timeout;
	union
	{
		struct
		{
			unsigned int configuration;
		} configuration;

		interface_request_t intf;

		struct
		{
			unsigned int endpoint;
			unsigned int packet_size;

			// TODO: max_transfer_size, short transfer not ok, use iso_start_frame
			unsigned int max_transfer_size;
			unsigned int transfer_flags;
			unsigned int iso_start_frame_latency;
		} endpoint;
		struct
		{
			unsigned int type;
			unsigned int recipient;
			unsigned int request;
			unsigned int value;
			unsigned int index;
		} vendor;
		struct
		{
			unsigned int recipient;
			unsigned int feature;
			unsigned int index;
		} feature;
		struct
		{
			unsigned int recipient;
			unsigned int index;
			unsigned int status;
		} status;
		struct
		{
			unsigned int type;
			unsigned int index;
			unsigned int language_id;
			unsigned int recipient;
		} descriptor;
		struct
		{
			unsigned int level;
		} debug;
		struct
		{
			unsigned int major;
			unsigned int minor;
			unsigned int micro;
			unsigned int nano;
			unsigned int mod_value;
		} version;
		struct
		{
			unsigned int property;
		} device_property;
		struct
		{
			unsigned int key_type;
			unsigned int name_offset;
			unsigned int value_offset;
			unsigned int value_length;
		} device_registry_key;
		struct
		{
			// 0 - device plug and play registry key pathname
			unsigned int objname_index;
		} objname;
		struct
		{
			ULONG information_type;
		} query_device;
		struct
		{
			unsigned int interface_index;
			unsigned int pipe_id;
			unsigned int policy_type;
		} pipe_policy;
		struct
		{
			unsigned int policy_type;
		} power_policy;
		struct
		{
			unsigned int reset_type;
		} reset_ex;

		// WDF_USB_CONTROL_SETUP_PACKET control;
		struct
		{
			UCHAR   RequestType;
			UCHAR   Request;
			USHORT  Value;
			USHORT  Index;
			USHORT  Length;
		} control;
	};
} libusb_request;
#pragma warning(default:4201)

#include <poppack.h>

#endif