-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathlibusb_unix.inc
302 lines (265 loc) · 7.82 KB
/
libusb_unix.inc
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
Interface
{$LINKLIB c}
{$LINKLIB usb}
{
Automatically converted by H2Pas 0.99.15 from usb.h
The following command line parameters were used:
-d
-l
usb
-o
libusb.pp
-p
-v
usb.h
}
{ global Linux constants }
Const PATH_MAX = 4096;
{ Pointers to basic pascal types, inserted by h2pas conversion program.}
Type
PLongint = ^Longint;
PSmallInt = ^SmallInt;
PByte = ^Byte;
PWord = ^Word;
PDWord = ^DWord;
PDouble = ^Double;
{$PACKRECORDS C}
{
USB spec information
This is all stuff grabbed from various USB specs and is pretty much
not subject to change
}
{
Device and/or Interface Class codes
}
{ for DeviceClass }
Const
USB_CLASS_PER_INTERFACE = 0;
USB_CLASS_AUDIO = 1;
USB_CLASS_COMM = 2;
USB_CLASS_HID = 3;
USB_CLASS_PRINTER = 7;
USB_CLASS_MASS_STORAGE = 8;
USB_CLASS_HUB = 9;
USB_CLASS_DATA = 10;
USB_CLASS_VENDOR_SPEC = $ff;
{
Descriptor types
}
USB_DT_DEVICE = $01;
USB_DT_CONFIG = $02;
USB_DT_STRING = $03;
USB_DT_INTERFACE = $04;
USB_DT_ENDPOINT = $05;
USB_DT_HID = $21;
USB_DT_REPORT = $22;
USB_DT_PHYSICAL = $23;
USB_DT_HUB = $29;
{
Descriptor sizes per descriptor type
}
USB_DT_DEVICE_SIZE = 18;
USB_DT_CONFIG_SIZE = 9;
USB_DT_INTERFACE_SIZE = 9;
USB_DT_ENDPOINT_SIZE = 7;
{ Audio extension }
USB_DT_ENDPOINT_AUDIO_SIZE = 9;
USB_DT_HUB_NONVAR_SIZE = 7;
{ All standard descriptors have these 2 fields in common }
Type
PUSBDescriptorHeader = ^USBDescriptorHeader;
USBDescriptorHeader = record
bLength : Byte;
bDescriptorType : Byte;
End;
{ String descriptor }
PUSBStringDescriptor = ^USBStringDescriptor;
USBStringDescriptor = record
bLength : Byte;
bDescriptorType : Byte;
wData : Array[0..0] of Word;
End;
{ HID descriptor }
Pusb_hid_descriptor = ^usb_hid_descriptor;
usb_hid_descriptor = record
bLength : Byte;
bDescriptorType : Byte;
bcdHID : Word;
bCountryCode : Byte;
bNumDescriptors : Byte;
End;
{ Endpoint descriptor }
Const
USB_MAXENDPOINTS = 32;
{ Extra descriptors }
Type
PUSBEndpointDescriptor = ^USBEndpointDescriptor;
USBEndpointDescriptor = record
bLength : Byte;
bDescriptorType : Byte;
bEndpointAddress : Byte;
bmAttributes : Byte;
wMaxPacketSize : Word;
bInterval : Byte;
bRefresh : Byte;
bSynchAddress : Byte;
extra : Pbyte;
extralen : Longint;
End;
{ in bEndpointAddress }
Const
USB_ENDPOINT_ADDRESS_MASK = $0f;
USB_ENDPOINT_DIR_MASK = $80;
{ in bmAttributes }
USB_ENDPOINT_TYPE_MASK = $03;
USB_ENDPOINT_TYPE_CONTROL = 0;
USB_ENDPOINT_TYPE_ISOCHRONOUS = 1;
USB_ENDPOINT_TYPE_BULK = 2;
USB_ENDPOINT_TYPE_INTERRUPT = 3;
{ Interface descriptor }
USB_MAXINTERFACES = 32;
{ Extra descriptors }
Type
PUSBInterfaceDescriptor = ^USBInterfaceDescriptor;
USBInterfaceDescriptor = record
bLength : Byte;
bDescriptorType : Byte;
bInterfaceNumber : Byte;
bAlternateSetting : Byte;
bNumEndpoints : Byte;
bInterfaceClass : Byte;
bInterfaceSubClass : Byte;
bInterfaceProtocol : Byte;
iInterface : Byte;
endpoint : PUSBEndpointDescriptor;
extra : Pbyte;
extralen : Longint;
End;
{ Hard limit }
Const
USB_MAXALTSETTING = 128;
Type
PUSB_Interface = ^USB_Interface;
USB_Interface = record
altsetting : PUSBInterfaceDescriptor;
num_altsetting : Longint;
End;
{ Configuration descriptor information.. }
Const
USB_MAXCONFIG = 8;
{ Extra descriptors }
Type
PUSBConfigDescriptor = ^USBConfigDescriptor;
USBConfigDescriptor = record
bLength : Byte;
bDescriptorType : Byte;
wTotalLength : Word;
bNumInterfaces : Byte;
bConfigurationValue : Byte;
iConfiguration : Byte;
bmAttributes : Byte;
MaxPower : Byte;
TheInterface : PUSB_Interface;
extra : Pbyte;
extralen : Longint;
End;
{ Device descriptor }
PUSBDeviceDescriptor = ^USBDeviceDescriptor;
USBDeviceDescriptor = record
bLength : Byte;
bDescriptorType : Byte;
bcdUSB : Word;
bDeviceClass : Byte;
bDeviceSubClass : Byte;
bDeviceProtocol : Byte;
bMaxPacketSize0 : Byte;
idVendor : Word;
idProduct : Word;
bcdDevice : Word;
iManufacturer : Byte;
iProduct : Byte;
iSerialNumber : Byte;
bNumConfigurations : Byte;
End;
{
Standard requests
}
Const
USB_REQ_GET_STATUS = $00;
USB_REQ_CLEAR_FEATURE = $01;
{ 0x02 is reserved }
USB_REQ_SET_FEATURE = $03;
{ 0x04 is reserved }
USB_REQ_SET_ADDRESS = $05;
USB_REQ_GET_DESCRIPTOR = $06;
USB_REQ_SET_DESCRIPTOR = $07;
USB_REQ_GET_CONFIGURATION = $08;
USB_REQ_SET_CONFIGURATION = $09;
USB_REQ_GET_INTERFACE = $0A;
USB_REQ_SET_INTERFACE = $0B;
USB_REQ_SYNCH_FRAME = $0C;
USB_TYPE_STANDARD = $00 shl 5;
USB_TYPE_CLASS = $01 shl 5;
USB_TYPE_VENDOR = $02 shl 5;
USB_TYPE_RESERVED = $03 shl 5;
USB_RECIP_DEVICE = $00;
USB_RECIP_INTERFACE = $01;
USB_RECIP_ENDPOINT = $02;
USB_RECIP_OTHER = $03;
{
Various libusb API related stuff
}
USB_ENDPOINT_IN = $80;
USB_ENDPOINT_OUT = $00;
{ Error codes }
USB_ERROR_BEGIN = 500000;
Type PUSBBus = ^USBBus;
PUSBDevice = ^USBDevice;
USBDevice = record
next : PUSBDevice;
prev : PUSBDevice;
filename : Array[0..(PATH_MAX + 1)-1] of Char;
bus : PUSBBus;
descriptor : USBDeviceDescriptor;
config : PUSBConfigDescriptor;
dev : pointer;
End;
{ PUSBBus = ^USBBus;}
USBBus = record
next : PUSBBus;
prev : PUSBBus;
dirname : Array[0..(PATH_MAX + 1)-1] of Char;
devices : PUSBDevice;
location : Longword;
root_dev : PUSBDevice;
End;
PUSBDevHandle = ^TUSBDevHandle;
TUSBDevHandle = record
End;
{ Variables }
Var USBBusses : PUSBBus; cvar; external;
{ Function prototypes }
Function usb_open(dev:PUSBDevice):PUSBDevHandle; cdecl; external;
Function usb_close(dev:PUSBDevHandle):Longint; cdecl; external;
Function usb_get_string(var dev:PUSBDevHandle; index:LongInt; langid:LongInt; buf:pchar; buflen:Longword):LongInt;cdecl; external;
Function usb_get_string_simple(var dev:PUSBDevHandle; index:LongInt; buf:pchar; buflen:Longword):LongInt;cdecl; external;
Function usb_bulk_write(dev:PUSBDevHandle; ep:Longint; bytes:PChar; size:Longint; timeout:Longint):Longint; cdecl; external;
Function usb_bulk_read(dev:PUSBDevHandle; ep:Longint; bytes:PChar; size:Longint; timeout:Longint):Longint; cdecl; external;
Function usb_control_msg(dev:PUSBDevHandle; requestType:Longint; request:Longint; value:Longint; index:Longint;
bytes:PChar; size:Longint; timeout:Longint):Longint; cdecl; external;
Function usb_set_configuration(dev:PUSBDevHandle; configuration:Longint):Longint; cdecl; external;
Function usb_claim_interface(dev:PUSBDevHandle; TheInterface:Longint):Longint; cdecl; external;
Function usb_release_interface(dev:PUSBDevHandle; TheInterface:Longint):Longint; cdecl; external;
Function usb_set_altinterface(dev:PUSBDevHandle; alternate:Longint):Longint; cdecl; external;
Function usb_resetep(dev:PUSBDevHandle; ep:dword):Longint; cdecl; external;
Function usb_clear_halt(dev:PUSBDevHandle; ep:dword):Longint; cdecl; external;
Function usb_reset(dev:PUSBDevHandle):Longint; cdecl; external;
Function usb_strerror:PChar; cdecl; external;
Procedure usb_init; cdecl; external;
Procedure usb_set_debug(level:Longint); cdecl; external;
Function usb_find_busses:Longint; cdecl; external;
Function usb_find_devices:Longint; cdecl; external;
Function usb_device(Dev:PUSBDevHandle):PUSBDevice; cdecl; external;
Function usb_get_busses : PUSBBus; cdecl; external;
Implementation
End.