comparison USBLib/Communication/LibUsb1/libusb1.cs @ 21:dcfec2be27c9

Added USBLib
author Ivo Smits <Ivo@UCIS.nl>
date Mon, 15 Apr 2013 01:04:59 +0200
parents
children 5b14fed54a89
comparison
equal deleted inserted replaced
20:c873e3dd73fe 21:dcfec2be27c9
1 using System;
2 using System.Runtime.InteropServices;
3 using System.Text;
4 using Microsoft.Win32.SafeHandles;
5 using ssize_t = System.IntPtr;
6
7 namespace UCIS.USBLib.Communication.LibUsb1 {
8 class libusb_context : SafeHandleZeroOrMinusOneIsInvalid {
9 public libusb_context() : base(true) { }
10 protected override bool ReleaseHandle() {
11 libusb1.libusb_exit(handle);
12 return true;
13 }
14 }
15 class libusb_device : SafeHandleZeroOrMinusOneIsInvalid {
16 public libusb_device() : base(true) { }
17 public libusb_device(IntPtr handle, Boolean ownsHandle) : base(ownsHandle) { SetHandle(handle); }
18 protected override bool ReleaseHandle() {
19 libusb1.libusb_unref_device(handle);
20 return true;
21 }
22 }
23 class libusb_device_handle : SafeHandleZeroOrMinusOneIsInvalid {
24 public libusb_device_handle() : base(true) { }
25 protected override bool ReleaseHandle() {
26 libusb1.libusb_close(handle);
27 return true;
28 }
29 }
30 unsafe static class libusb1 {
31 const CallingConvention LIBUSB1_CC = CallingConvention.Winapi;
32 const String LIBUSB1_DLL = "libusb-1.0.dll";
33 /* Device and/or Interface Class codes */
34 enum libusb_class_code {
35 /** In the context of a \ref libusb_device_descriptor "device descriptor",
36 * this bDeviceClass value indicates that each interface specifies its
37 * own class information and all interfaces operate independently.
38 */
39 LIBUSB_CLASS_PER_INTERFACE = 0,
40
41 /** Audio class */
42 LIBUSB_CLASS_AUDIO = 1,
43
44 /** Communications class */
45 LIBUSB_CLASS_COMM = 2,
46
47 /** Human Interface Device class */
48 LIBUSB_CLASS_HID = 3,
49
50 /** Physical */
51 LIBUSB_CLASS_PHYSICAL = 5,
52
53 /** Printer class */
54 LIBUSB_CLASS_PRINTER = 7,
55
56 /** Image class */
57 LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
58 LIBUSB_CLASS_IMAGE = 6,
59
60 /** Mass storage class */
61 LIBUSB_CLASS_MASS_STORAGE = 8,
62
63 /** Hub class */
64 LIBUSB_CLASS_HUB = 9,
65
66 /** Data class */
67 LIBUSB_CLASS_DATA = 10,
68
69 /** Smart Card */
70 LIBUSB_CLASS_SMART_CARD = 0x0b,
71
72 /** Content Security */
73 LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
74
75 /** Video */
76 LIBUSB_CLASS_VIDEO = 0x0e,
77
78 /** Personal Healthcare */
79 LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
80
81 /** Diagnostic Device */
82 LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
83
84 /** Wireless class */
85 LIBUSB_CLASS_WIRELESS = 0xe0,
86
87 /** Application class */
88 LIBUSB_CLASS_APPLICATION = 0xfe,
89
90 /** Class is vendor-specific */
91 LIBUSB_CLASS_VENDOR_SPEC = 0xff
92 }
93
94 /* Descriptor types as defined by the USB specification. */
95 enum libusb_descriptor_type {
96 /** Device descriptor. See libusb_device_descriptor. */
97 LIBUSB_DT_DEVICE = 0x01,
98
99 /** Configuration descriptor. See libusb_config_descriptor. */
100 LIBUSB_DT_CONFIG = 0x02,
101
102 /** String descriptor */
103 LIBUSB_DT_STRING = 0x03,
104
105 /** Interface descriptor. See libusb_interface_descriptor. */
106 LIBUSB_DT_INTERFACE = 0x04,
107
108 /** Endpoint descriptor. See libusb_endpoint_descriptor. */
109 LIBUSB_DT_ENDPOINT = 0x05,
110
111 /** HID descriptor */
112 LIBUSB_DT_HID = 0x21,
113
114 /** HID report descriptor */
115 LIBUSB_DT_REPORT = 0x22,
116
117 /** Physical descriptor */
118 LIBUSB_DT_PHYSICAL = 0x23,
119
120 /** Hub descriptor */
121 LIBUSB_DT_HUB = 0x29
122 }
123
124 /* Descriptor sizes per descriptor type */
125 const int LIBUSB_DT_DEVICE_SIZE = 18;
126 const int LIBUSB_DT_CONFIG_SIZE = 9;
127 const int LIBUSB_DT_INTERFACE_SIZE = 9;
128 const int LIBUSB_DT_ENDPOINT_SIZE = 7;
129 const int LIBUSB_DT_ENDPOINT_AUDIO_SIZE = 9; /* Audio extension */
130 const int LIBUSB_DT_HUB_NONVAR_SIZE = 7;
131
132 const int LIBUSB_ENDPOINT_ADDRESS_MASK = 0x0f; /* in bEndpointAddress */
133 const int LIBUSB_ENDPOINT_DIR_MASK = 0x80;
134
135 /* Endpoint direction. Values for bit 7 of the
136 * \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
137 */
138 enum libusb_endpoint_direction {
139 /** In: device-to-host */
140 LIBUSB_ENDPOINT_IN = 0x80,
141
142 /** Out: host-to-device */
143 LIBUSB_ENDPOINT_OUT = 0x00
144 }
145
146 const int LIBUSB_TRANSFER_TYPE_MASK = 0x03; /* in bmAttributes */
147
148 /* Endpoint transfer type. Values for bits 0:1 of the
149 * \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
150 */
151 enum libusb_transfer_type {
152 /** Control endpoint */
153 LIBUSB_TRANSFER_TYPE_CONTROL = 0,
154
155 /** Isochronous endpoint */
156 LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
157
158 /** Bulk endpoint */
159 LIBUSB_TRANSFER_TYPE_BULK = 2,
160
161 /** Interrupt endpoint */
162 LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
163 }
164
165 /* Standard requests, as defined in table 9-3 of the USB2 specifications */
166 enum libusb_standard_request {
167 /** Request status of the specific recipient */
168 LIBUSB_REQUEST_GET_STATUS = 0x00,
169
170 /** Clear or disable a specific feature */
171 LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
172
173 /* 0x02 is reserved */
174
175 /** Set or enable a specific feature */
176 LIBUSB_REQUEST_SET_FEATURE = 0x03,
177
178 /* 0x04 is reserved */
179
180 /** Set device address for all future accesses */
181 LIBUSB_REQUEST_SET_ADDRESS = 0x05,
182
183 /** Get the specified descriptor */
184 LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
185
186 /** Used to update existing descriptors or add new descriptors */
187 LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
188
189 /** Get the current device configuration value */
190 LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
191
192 /** Set device configuration */
193 LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
194
195 /** Return the selected alternate setting for the specified interface */
196 LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
197
198 /** Select an alternate interface for the specified interface */
199 LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
200
201 /** Set then report an endpoint's synchronization frame */
202 LIBUSB_REQUEST_SYNCH_FRAME = 0x0C
203 }
204
205 /* Request type bits of the
206 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
207 * transfers. */
208 enum libusb_request_type {
209 /** Standard */
210 LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
211
212 /** Class */
213 LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
214
215 /** Vendor */
216 LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
217
218 /** Reserved */
219 LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
220 }
221
222 /* Recipient bits of the
223 * \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
224 * transfers. Values 4 through 31 are reserved. */
225 enum libusb_request_recipient {
226 /** Device */
227 LIBUSB_RECIPIENT_DEVICE = 0x00,
228
229 /** Interface */
230 LIBUSB_RECIPIENT_INTERFACE = 0x01,
231
232 /** Endpoint */
233 LIBUSB_RECIPIENT_ENDPOINT = 0x02,
234
235 /** Other */
236 LIBUSB_RECIPIENT_OTHER = 0x03
237 }
238
239 const int LIBUSB_ISO_SYNC_TYPE_MASK = 0x0C;
240
241 /* Synchronization type for isochronous endpoints. Values for bits 2:3 of the
242 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
243 * libusb_endpoint_descriptor.
244 */
245 enum libusb_iso_sync_type {
246 /** No synchronization */
247 LIBUSB_ISO_SYNC_TYPE_NONE = 0,
248
249 /** Asynchronous */
250 LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
251
252 /** Adaptive */
253 LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
254
255 /** Synchronous */
256 LIBUSB_ISO_SYNC_TYPE_SYNC = 3
257 }
258 const int LIBUSB_ISO_USAGE_TYPE_MASK = 0x30;
259
260 /* Usage type for isochronous endpoints. Values for bits 4:5 of the
261 * \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
262 * libusb_endpoint_descriptor.
263 */
264 enum libusb_iso_usage_type {
265 /** Data endpoint */
266 LIBUSB_ISO_USAGE_TYPE_DATA = 0,
267
268 /** Feedback endpoint */
269 LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
270
271 /** Implicit feedback Data endpoint */
272 LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2
273 }
274
275 /* A structure representing the standard USB device descriptor. This
276 * descriptor is documented in section 9.6.1 of the USB 2.0 specification.
277 * All multiple-byte fields are represented in host-endian format.
278 */
279 [StructLayout(LayoutKind.Sequential, Pack = 1)]
280 public struct libusb_device_descriptor {
281 /** Size of this descriptor (in bytes) */
282 public Byte bLength;
283
284 /** Descriptor type. Will have value
285 * \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
286 * context. */
287 public Byte bDescriptorType;
288
289 /** USB specification release number in binary-coded decimal. A value of
290 * 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
291 public UInt16 bcdUSB;
292
293 /** USB-IF class code for the device. See \ref libusb_class_code. */
294 public Byte bDeviceClass;
295
296 /** USB-IF subclass code for the device, qualified by the bDeviceClass
297 * value */
298 public Byte bDeviceSubClass;
299
300 /** USB-IF protocol code for the device, qualified by the bDeviceClass and
301 * bDeviceSubClass values */
302 public Byte bDeviceProtocol;
303
304 /** Maximum packet size for endpoint 0 */
305 public Byte bMaxPacketSize0;
306
307 /** USB-IF vendor ID */
308 public UInt16 idVendor;
309
310 /** USB-IF product ID */
311 public UInt16 idProduct;
312
313 /** Device release number in binary-coded decimal */
314 public UInt16 bcdDevice;
315
316 /** Index of string descriptor describing manufacturer */
317 public Byte iManufacturer;
318
319 /** Index of string descriptor describing product */
320 public Byte iProduct;
321
322 /** Index of string descriptor containing device serial number */
323 public Byte iSerialNumber;
324
325 /** Number of possible configurations */
326 public Byte bNumConfigurations;
327 }
328
329 /* A structure representing the standard USB endpoint descriptor. This
330 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
331 * All multiple-byte fields are represented in host-endian format.
332 */
333 [StructLayout(LayoutKind.Sequential)]
334 struct libusb_endpoint_descriptor {
335 /** Size of this descriptor (in bytes) */
336 Byte bLength;
337
338 /** Descriptor type. Will have value
339 * \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
340 * this context. */
341 Byte bDescriptorType;
342
343 /** The address of the endpoint described by this descriptor. Bits 0:3 are
344 * the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
345 * see \ref libusb_endpoint_direction.
346 */
347 Byte bEndpointAddress;
348
349 /** Attributes which apply to the endpoint when it is configured using
350 * the bConfigurationValue. Bits 0:1 determine the transfer type and
351 * correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
352 * isochronous endpoints and correspond to \ref libusb_iso_sync_type.
353 * Bits 4:5 are also only used for isochronous endpoints and correspond to
354 * \ref libusb_iso_usage_type. Bits 6:7 are reserved.
355 */
356 Byte bmAttributes;
357
358 /** Maximum packet size this endpoint is capable of sending/receiving. */
359 UInt16 wMaxPacketSize;
360
361 /** Interval for polling endpoint for data transfers. */
362 Byte bInterval;
363
364 /** For audio devices only: the rate at which synchronization feedback
365 * is provided. */
366 Byte bRefresh;
367
368 /** For audio devices only: the address if the synch endpoint */
369 Byte bSynchAddress;
370
371 /** Extra descriptors. If libusb encounters unknown endpoint descriptors,
372 * it will store them here, should you wish to parse them. */
373 byte* extra;
374
375 /** Length of the extra descriptors, in bytes. */
376 int extra_length;
377 }
378
379 /* A structure representing the standard USB interface descriptor. This
380 * descriptor is documented in section 9.6.5 of the USB 2.0 specification.
381 * All multiple-byte fields are represented in host-endian format.
382 */
383 [StructLayout(LayoutKind.Sequential)]
384 struct libusb_interface_descriptor {
385 /** Size of this descriptor (in bytes) */
386 Byte bLength;
387
388 /** Descriptor type. Will have value
389 * \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
390 * in this context. */
391 Byte bDescriptorType;
392
393 /** Number of this interface */
394 Byte bInterfaceNumber;
395
396 /** Value used to select this alternate setting for this interface */
397 Byte bAlternateSetting;
398
399 /** Number of endpoints used by this interface (excluding the control
400 * endpoint). */
401 Byte bNumEndpoints;
402
403 /** USB-IF class code for this interface. See \ref libusb_class_code. */
404 Byte bInterfaceClass;
405
406 /** USB-IF subclass code for this interface, qualified by the
407 * bInterfaceClass value */
408 Byte bInterfaceSubClass;
409
410 /** USB-IF protocol code for this interface, qualified by the
411 * bInterfaceClass and bInterfaceSubClass values */
412 Byte bInterfaceProtocol;
413
414 /** Index of string descriptor describing this interface */
415 Byte iInterface;
416
417 /** Array of endpoint descriptors. This length of this array is determined
418 * by the bNumEndpoints field. */
419 libusb_endpoint_descriptor* endpoint;
420
421 /** Extra descriptors. If libusb encounters unknown interface descriptors,
422 * it will store them here, should you wish to parse them. */
423 Byte* extra;
424
425 /** Length of the extra descriptors, in bytes. */
426 int extra_length;
427 }
428
429 /* A collection of alternate settings for a particular USB interface.
430 */
431 [StructLayout(LayoutKind.Sequential)]
432 struct libusb_interface {
433 /** Array of interface descriptors. The length of this array is determined
434 * by the num_altsetting field. */
435 libusb_interface_descriptor* altsetting;
436
437 /** The number of alternate settings that belong to this interface */
438 int num_altsetting;
439 }
440
441 /* A structure representing the standard USB configuration descriptor. This
442 * descriptor is documented in section 9.6.3 of the USB 2.0 specification.
443 * All multiple-byte fields are represented in host-endian format.
444 */
445 struct libusb_config_descriptor {
446 /** Size of this descriptor (in bytes) */
447 Byte bLength;
448
449 /** Descriptor type. Will have value
450 * \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
451 * in this context. */
452 Byte bDescriptorType;
453
454 /** Total length of data returned for this configuration */
455 Byte wTotalLength;
456
457 /** Number of interfaces supported by this configuration */
458 Byte bNumInterfaces;
459
460 /** Identifier value for this configuration */
461 Byte bConfigurationValue;
462
463 /** Index of string descriptor describing this configuration */
464 Byte iConfiguration;
465
466 /** Configuration characteristics */
467 Byte bmAttributes;
468
469 /** Maximum power consumption of the USB device from this bus in this
470 * configuration when the device is fully opreation. Expressed in units
471 * of 2 mA. */
472 Byte MaxPower;
473
474 /** Array of interfaces supported by this configuration. The length of
475 * this array is determined by the bNumInterfaces field. */
476 libusb_interface* @interface;
477
478 /** Extra descriptors. If libusb encounters unknown configuration
479 * descriptors, it will store them here, should you wish to parse them. */
480 Byte* extra;
481
482 /** Length of the extra descriptors, in bytes. */
483 int extra_length;
484 }
485
486 /* Setup packet for control transfers. */
487 [StructLayout(LayoutKind.Sequential, Size = 8)]
488 struct libusb_control_setup {
489 /** Request type. Bits 0:4 determine recipient, see
490 * \ref libusb_request_recipient. Bits 5:6 determine type, see
491 * \ref libusb_request_type. Bit 7 determines data transfer direction, see
492 * \ref libusb_endpoint_direction.
493 */
494 Byte bmRequestType;
495
496 /** Request. If the type bits of bmRequestType are equal to
497 * \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
498 * "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
499 * \ref libusb_standard_request. For other cases, use of this field is
500 * application-specific. */
501 Byte bRequest;
502
503 /** Value. Varies according to request */
504 UInt16 wValue;
505
506 /** Index. Varies according to request, typically used to pass an index
507 * or offset */
508 UInt16 wIndex;
509
510 /** Number of bytes to transfer */
511 UInt16 wLength;
512 }
513
514 const int LIBUSB_CONTROL_SETUP_SIZE = 8; //sizeof(libusb_control_setup); // Marshal.SizeOf(typeof(libusb_control_setup));
515
516 /* Structure representing a libusb session. The concept of individual libusb
517 * sessions allows for your program to use two libraries (or dynamically
518 * load two modules) which both independently use libusb. This will prevent
519 * interference between the individual libusb users - for example
520 * libusb_set_debug() will not affect the other user of the library, and
521 * libusb_exit() will not destroy resources that the other user is still
522 * using.
523 *
524 * Sessions are created by libusb_init() and destroyed through libusb_exit().
525 * If your application is guaranteed to only ever include a single libusb
526 * user (i.e. you), you do not have to worry about contexts: pass NULL in
527 * every function call where a context is required. The default context
528 * will be used.
529 *
530 * For more information, see \ref contexts.
531 */
532
533 /* Structure representing a USB device detected on the system. This is an
534 * opaque type for which you are only ever provided with a pointer, usually
535 * originating from libusb_get_device_list().
536 *
537 * Certain operations can be performed on a device, but in order to do any
538 * I/O you will have to first obtain a device handle using libusb_open().
539 *
540 * Devices are reference counted with libusb_device_ref() and
541 * libusb_device_unref(), and are freed when the reference count reaches 0.
542 * New devices presented by libusb_get_device_list() have a reference count of
543 * 1, and libusb_free_device_list() can optionally decrease the reference count
544 * on all devices in the list. libusb_open() adds another reference which is
545 * later destroyed by libusb_close().
546 */
547
548 /* Structure representing a handle on a USB device. This is an opaque type for
549 * which you are only ever provided with a pointer, usually originating from
550 * libusb_open().
551 *
552 * A device handle is used to perform I/O and other operations. When finished
553 * with a device handle, you should call libusb_close().
554 */
555
556 /* Speed codes. Indicates the speed at which the device is operating. */
557 enum libusb_speed {
558 /** The OS doesn't report or know the device speed. */
559 LIBUSB_SPEED_UNKNOWN = 0,
560
561 /** The device is operating at low speed (1.5MBit/s). */
562 LIBUSB_SPEED_LOW = 1,
563
564 /** The device is operating at full speed (12MBit/s). */
565 LIBUSB_SPEED_FULL = 2,
566
567 /** The device is operating at high speed (480MBit/s). */
568 LIBUSB_SPEED_HIGH = 3,
569
570 /** The device is operating at super speed (5000MBit/s). */
571 LIBUSB_SPEED_SUPER = 4,
572 }
573
574 /* Error codes. Most libusb functions return 0 on success or one of these
575 * codes on failure.
576 * You can call \ref libusb_error_name() to retrieve a string representation
577 * of an error code.
578 */
579 enum libusb_error {
580 /** Success (no error) */
581 LIBUSB_SUCCESS = 0,
582
583 /** Input/output error */
584 LIBUSB_ERROR_IO = -1,
585
586 /** Invalid parameter */
587 LIBUSB_ERROR_INVALID_PARAM = -2,
588
589 /** Access denied (insufficient permissions) */
590 LIBUSB_ERROR_ACCESS = -3,
591
592 /** No such device (it may have been disconnected) */
593 LIBUSB_ERROR_NO_DEVICE = -4,
594
595 /** Entity not found */
596 LIBUSB_ERROR_NOT_FOUND = -5,
597
598 /** Resource busy */
599 LIBUSB_ERROR_BUSY = -6,
600
601 /** Operation timed out */
602 LIBUSB_ERROR_TIMEOUT = -7,
603
604 /** Overflow */
605 LIBUSB_ERROR_OVERFLOW = -8,
606
607 /** Pipe error */
608 LIBUSB_ERROR_PIPE = -9,
609
610 /** System call interrupted (perhaps due to signal) */
611 LIBUSB_ERROR_INTERRUPTED = -10,
612
613 /** Insufficient memory */
614 LIBUSB_ERROR_NO_MEM = -11,
615
616 /** Operation not supported or unimplemented on this platform */
617 LIBUSB_ERROR_NOT_SUPPORTED = -12,
618
619 /* NB! Remember to update libusb_error_name()
620 when adding new error codes here. */
621
622 /** Other error */
623 LIBUSB_ERROR_OTHER = -99
624 }
625
626 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
627 public static extern int libusb_init(out libusb_context ctx);
628 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
629 public static extern void libusb_exit(IntPtr ctx);
630 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
631 static extern void libusb_set_debug(libusb_context ctx, int level);
632 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
633 static extern Byte* libusb_error_name(int errcode);
634
635 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
636 public static extern ssize_t libusb_get_device_list(libusb_context ctx, out IntPtr* list); //libusb_device** list
637 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
638 public static extern void libusb_free_device_list(IntPtr* list, int unref_devices);
639 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
640 static extern libusb_device libusb_ref_device(libusb_device dev);
641 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
642 public static extern void libusb_unref_device(IntPtr dev);
643
644 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
645 static extern int libusb_get_configuration(libusb_device_handle dev, out int config);
646 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
647 public static extern int libusb_get_device_descriptor(libusb_device dev, out libusb_device_descriptor desc);
648 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
649 static extern int libusb_get_active_config_descriptor(libusb_device dev, libusb_config_descriptor** config);
650 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
651 static extern int libusb_get_config_descriptor(libusb_device dev, Byte config_index, libusb_config_descriptor** config);
652 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
653 static extern int libusb_get_config_descriptor_by_value(libusb_device dev, Byte bConfigurationValue, libusb_config_descriptor** config);
654 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
655 static extern void libusb_free_config_descriptor(libusb_config_descriptor* config);
656 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
657 public static extern Byte libusb_get_bus_number(libusb_device dev);
658 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
659 public static extern Byte libusb_get_device_address(libusb_device dev);
660 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
661 static extern int libusb_get_device_speed(libusb_device dev);
662 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
663 static extern int libusb_get_max_packet_size(libusb_device dev, Byte endpoint);
664 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
665 static extern int libusb_get_max_iso_packet_size(libusb_device dev, Byte endpoint);
666
667 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
668 public static extern int libusb_open(libusb_device dev, out libusb_device_handle handle);
669 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
670 public static extern void libusb_close(IntPtr dev_handle);
671 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
672 static extern libusb_device libusb_get_device(libusb_device_handle dev_handle);
673
674 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
675 public static extern int libusb_set_configuration(libusb_device_handle dev, int configuration);
676 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
677 public static extern int libusb_claim_interface(libusb_device_handle dev, int interface_number);
678 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
679 public static extern int libusb_release_interface(libusb_device_handle dev, int interface_number);
680
681 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
682 static extern libusb_device_handle libusb_open_device_with_vid_pid(libusb_context ctx, UInt16 vendor_id, UInt16 product_id);
683
684 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
685 static extern int libusb_set_interface_alt_setting(libusb_device_handle dev, int interface_number, int alternate_setting);
686 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
687 static extern int libusb_clear_halt(libusb_device_handle dev, Byte endpoint);
688 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
689 public static extern int libusb_reset_device(libusb_device_handle dev);
690
691 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
692 static extern int libusb_kernel_driver_active(libusb_device_handle dev, int interface_number);
693 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
694 public static extern int libusb_detach_kernel_driver(libusb_device_handle dev, int interface_number);
695 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
696 public static extern int libusb_attach_kernel_driver(libusb_device_handle dev, int interface_number);
697
698 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
699 public static extern int libusb_control_transfer(libusb_device_handle dev_handle,
700 Byte request_type, Byte bRequest, UInt16 wValue, UInt16 wIndex,
701 Byte* data, UInt16 wLength, UInt32 timeout);
702
703 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
704 public static extern int libusb_bulk_transfer(libusb_device_handle dev_handle,
705 Byte endpoint, Byte* data, int length,
706 out int actual_length, UInt32 timeout);
707
708 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
709 public static extern int libusb_interrupt_transfer(libusb_device_handle dev_handle,
710 Byte endpoint, Byte* data, int length,
711 out int actual_length, UInt32 timeout);
712
713 [DllImport(LIBUSB1_DLL, CallingConvention = LIBUSB1_CC)]
714 public static extern int libusb_get_string_descriptor_ascii(libusb_device_handle dev,
715 Byte desc_index, [MarshalAs(UnmanagedType.LPStr)] StringBuilder data, int length);
716 }
717 }