libusb 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +8 -0
- data/.travis.yml +10 -0
- data/.yardopts +6 -1
- data/Gemfile +16 -0
- data/{History.txt → History.md} +28 -16
- data/README.md +144 -0
- data/Rakefile +28 -24
- data/ext/extconf.rb +33 -0
- data/ext/libusbx-1.0.14/AUTHORS +50 -0
- data/ext/libusbx-1.0.14/COPYING +504 -0
- data/ext/libusbx-1.0.14/ChangeLog +139 -0
- data/ext/libusbx-1.0.14/INSTALL +234 -0
- data/ext/libusbx-1.0.14/Makefile.am +23 -0
- data/ext/libusbx-1.0.14/Makefile.in +803 -0
- data/ext/libusbx-1.0.14/NEWS +2 -0
- data/ext/libusbx-1.0.14/PORTING +94 -0
- data/ext/libusbx-1.0.14/README +28 -0
- data/ext/libusbx-1.0.14/THANKS +7 -0
- data/ext/libusbx-1.0.14/TODO +2 -0
- data/ext/libusbx-1.0.14/aclocal.m4 +9480 -0
- data/ext/libusbx-1.0.14/compile +143 -0
- data/ext/libusbx-1.0.14/config.guess +1501 -0
- data/ext/libusbx-1.0.14/config.h.in +116 -0
- data/ext/libusbx-1.0.14/config.sub +1705 -0
- data/ext/libusbx-1.0.14/configure +14818 -0
- data/ext/libusbx-1.0.14/configure.ac +230 -0
- data/ext/libusbx-1.0.14/depcomp +630 -0
- data/ext/libusbx-1.0.14/doc/Makefile.am +9 -0
- data/ext/libusbx-1.0.14/doc/Makefile.in +380 -0
- data/ext/libusbx-1.0.14/doc/doxygen.cfg.in +1288 -0
- data/ext/libusbx-1.0.14/examples/Makefile.am +18 -0
- data/ext/libusbx-1.0.14/examples/Makefile.in +596 -0
- data/ext/libusbx-1.0.14/examples/dpfp.c +506 -0
- data/ext/libusbx-1.0.14/examples/dpfp_threaded.c +544 -0
- data/ext/libusbx-1.0.14/examples/ezusb.c +616 -0
- data/ext/libusbx-1.0.14/examples/ezusb.h +107 -0
- data/ext/libusbx-1.0.14/examples/fxload.c +261 -0
- data/ext/libusbx-1.0.14/examples/getopt/getopt.c +1060 -0
- data/ext/libusbx-1.0.14/examples/getopt/getopt.h +180 -0
- data/ext/libusbx-1.0.14/examples/getopt/getopt1.c +188 -0
- data/ext/libusbx-1.0.14/examples/listdevs.c +63 -0
- data/ext/libusbx-1.0.14/examples/xusb.c +1036 -0
- data/ext/libusbx-1.0.14/install-sh +520 -0
- data/ext/libusbx-1.0.14/libusb-1.0.pc.in +11 -0
- data/ext/libusbx-1.0.14/libusb/Makefile.am +56 -0
- data/ext/libusbx-1.0.14/libusb/Makefile.in +721 -0
- data/ext/libusbx-1.0.14/libusb/core.c +1951 -0
- data/ext/libusbx-1.0.14/libusb/descriptor.c +731 -0
- data/ext/libusbx-1.0.14/libusb/io.c +2450 -0
- data/ext/libusbx-1.0.14/libusb/libusb-1.0.def +126 -0
- data/ext/libusbx-1.0.14/libusb/libusb-1.0.rc +59 -0
- data/ext/libusbx-1.0.14/libusb/libusb.h +1506 -0
- data/ext/libusbx-1.0.14/libusb/libusbi.h +910 -0
- data/ext/libusbx-1.0.14/libusb/os/darwin_usb.c +1807 -0
- data/ext/libusbx-1.0.14/libusb/os/darwin_usb.h +169 -0
- data/ext/libusbx-1.0.14/libusb/os/linux_usbfs.c +2569 -0
- data/ext/libusbx-1.0.14/libusb/os/linux_usbfs.h +149 -0
- data/ext/libusbx-1.0.14/libusb/os/openbsd_usb.c +727 -0
- data/ext/libusbx-1.0.14/libusb/os/poll_posix.h +10 -0
- data/ext/libusbx-1.0.14/libusb/os/poll_windows.c +747 -0
- data/ext/libusbx-1.0.14/libusb/os/poll_windows.h +114 -0
- data/ext/libusbx-1.0.14/libusb/os/threads_posix.c +80 -0
- data/ext/libusbx-1.0.14/libusb/os/threads_posix.h +50 -0
- data/ext/libusbx-1.0.14/libusb/os/threads_windows.c +211 -0
- data/ext/libusbx-1.0.14/libusb/os/threads_windows.h +87 -0
- data/ext/libusbx-1.0.14/libusb/os/windows_usb.c +4369 -0
- data/ext/libusbx-1.0.14/libusb/os/windows_usb.h +979 -0
- data/ext/libusbx-1.0.14/libusb/sync.c +321 -0
- data/ext/libusbx-1.0.14/libusb/version.h +18 -0
- data/ext/libusbx-1.0.14/libusb/version_nano.h +1 -0
- data/ext/libusbx-1.0.14/ltmain.sh +9636 -0
- data/ext/libusbx-1.0.14/missing +376 -0
- data/lib/libusb.rb +2 -3
- data/lib/libusb/call.rb +49 -7
- data/lib/libusb/compat.rb +15 -9
- data/lib/libusb/configuration.rb +15 -3
- data/lib/libusb/constants.rb +19 -6
- data/lib/libusb/context.rb +181 -3
- data/lib/libusb/dev_handle.rb +91 -40
- data/lib/libusb/endpoint.rb +41 -14
- data/lib/libusb/eventmachine.rb +183 -0
- data/lib/libusb/transfer.rb +21 -8
- data/lib/libusb/version_gem.rb +19 -0
- data/lib/libusb/{version.rb → version_struct.rb} +0 -0
- data/libusb.gemspec +31 -0
- data/test/test_libusb_compat.rb +1 -1
- data/test/test_libusb_compat_mass_storage.rb +2 -2
- data/test/test_libusb_descriptors.rb +1 -1
- data/test/test_libusb_event_machine.rb +118 -0
- data/test/test_libusb_iso_transfer.rb +6 -1
- data/test/test_libusb_mass_storage.rb +9 -3
- data/test/test_libusb_mass_storage2.rb +1 -1
- data/test/test_libusb_structs.rb +45 -0
- data/test/test_libusb_threads.rb +89 -0
- data/test/test_libusb_version.rb +4 -0
- metadata +109 -44
- data/.autotest +0 -23
- data/.gemtest +0 -0
- data/Manifest.txt +0 -3
- data/README.rdoc +0 -115
- data/test/test_libusb_keyboard.rb +0 -50
@@ -0,0 +1,126 @@
|
|
1
|
+
LIBRARY "libusb-1.0.dll"
|
2
|
+
EXPORTS
|
3
|
+
libusb_alloc_transfer
|
4
|
+
libusb_alloc_transfer@4 = libusb_alloc_transfer
|
5
|
+
libusb_attach_kernel_driver
|
6
|
+
libusb_attach_kernel_driver@8 = libusb_attach_kernel_driver
|
7
|
+
libusb_bulk_transfer
|
8
|
+
libusb_bulk_transfer@24 = libusb_bulk_transfer
|
9
|
+
libusb_cancel_transfer
|
10
|
+
libusb_cancel_transfer@4 = libusb_cancel_transfer
|
11
|
+
libusb_claim_interface
|
12
|
+
libusb_claim_interface@8 = libusb_claim_interface
|
13
|
+
libusb_clear_halt
|
14
|
+
libusb_clear_halt@8 = libusb_clear_halt
|
15
|
+
libusb_close
|
16
|
+
libusb_close@4 = libusb_close
|
17
|
+
libusb_control_transfer
|
18
|
+
libusb_control_transfer@32 = libusb_control_transfer
|
19
|
+
libusb_detach_kernel_driver
|
20
|
+
libusb_detach_kernel_driver@8 = libusb_detach_kernel_driver
|
21
|
+
libusb_error_name
|
22
|
+
libusb_error_name@4 = libusb_error_name
|
23
|
+
libusb_event_handler_active
|
24
|
+
libusb_event_handler_active@4 = libusb_event_handler_active
|
25
|
+
libusb_event_handling_ok
|
26
|
+
libusb_event_handling_ok@4 = libusb_event_handling_ok
|
27
|
+
libusb_exit
|
28
|
+
libusb_exit@4 = libusb_exit
|
29
|
+
libusb_free_config_descriptor
|
30
|
+
libusb_free_config_descriptor@4 = libusb_free_config_descriptor
|
31
|
+
libusb_free_device_list
|
32
|
+
libusb_free_device_list@8 = libusb_free_device_list
|
33
|
+
libusb_free_transfer
|
34
|
+
libusb_free_transfer@4 = libusb_free_transfer
|
35
|
+
libusb_get_active_config_descriptor
|
36
|
+
libusb_get_active_config_descriptor@8 = libusb_get_active_config_descriptor
|
37
|
+
libusb_get_bus_number
|
38
|
+
libusb_get_bus_number@4 = libusb_get_bus_number
|
39
|
+
libusb_get_config_descriptor
|
40
|
+
libusb_get_config_descriptor@12 = libusb_get_config_descriptor
|
41
|
+
libusb_get_config_descriptor_by_value
|
42
|
+
libusb_get_config_descriptor_by_value@12 = libusb_get_config_descriptor_by_value
|
43
|
+
libusb_get_configuration
|
44
|
+
libusb_get_configuration@8 = libusb_get_configuration
|
45
|
+
libusb_get_device
|
46
|
+
libusb_get_device@4 = libusb_get_device
|
47
|
+
libusb_get_device_address
|
48
|
+
libusb_get_device_address@4 = libusb_get_device_address
|
49
|
+
libusb_get_device_descriptor
|
50
|
+
libusb_get_device_descriptor@8 = libusb_get_device_descriptor
|
51
|
+
libusb_get_device_list
|
52
|
+
libusb_get_device_list@8 = libusb_get_device_list
|
53
|
+
libusb_get_device_speed
|
54
|
+
libusb_get_device_speed@4 = libusb_get_device_speed
|
55
|
+
libusb_get_max_iso_packet_size
|
56
|
+
libusb_get_max_iso_packet_size@8 = libusb_get_max_iso_packet_size
|
57
|
+
libusb_get_max_packet_size
|
58
|
+
libusb_get_max_packet_size@8 = libusb_get_max_packet_size
|
59
|
+
libusb_get_next_timeout
|
60
|
+
libusb_get_next_timeout@8 = libusb_get_next_timeout
|
61
|
+
libusb_get_parent
|
62
|
+
libusb_get_parent@4 = libusb_get_parent
|
63
|
+
libusb_get_pollfds
|
64
|
+
libusb_get_pollfds@4 = libusb_get_pollfds
|
65
|
+
libusb_get_port_number
|
66
|
+
libusb_get_port_number@4 = libusb_get_port_number
|
67
|
+
libusb_get_port_path
|
68
|
+
libusb_get_port_path@16 = libusb_get_port_path
|
69
|
+
libusb_get_string_descriptor_ascii
|
70
|
+
libusb_get_string_descriptor_ascii@16 = libusb_get_string_descriptor_ascii
|
71
|
+
libusb_get_version
|
72
|
+
libusb_get_version@0 = libusb_get_version
|
73
|
+
libusb_handle_events
|
74
|
+
libusb_handle_events@4 = libusb_handle_events
|
75
|
+
libusb_handle_events_completed
|
76
|
+
libusb_handle_events_completed@8 = libusb_handle_events_completed
|
77
|
+
libusb_handle_events_locked
|
78
|
+
libusb_handle_events_locked@8 = libusb_handle_events_locked
|
79
|
+
libusb_handle_events_timeout
|
80
|
+
libusb_handle_events_timeout@8 = libusb_handle_events_timeout
|
81
|
+
libusb_handle_events_timeout_completed
|
82
|
+
libusb_handle_events_timeout_completed@12 = libusb_handle_events_timeout_completed
|
83
|
+
libusb_has_capability
|
84
|
+
libusb_has_capability@4 = libusb_has_capability
|
85
|
+
libusb_init
|
86
|
+
libusb_init@4 = libusb_init
|
87
|
+
libusb_interrupt_transfer
|
88
|
+
libusb_interrupt_transfer@24 = libusb_interrupt_transfer
|
89
|
+
libusb_kernel_driver_active
|
90
|
+
libusb_kernel_driver_active@8 = libusb_kernel_driver_active
|
91
|
+
libusb_lock_event_waiters
|
92
|
+
libusb_lock_event_waiters@4 = libusb_lock_event_waiters
|
93
|
+
libusb_lock_events
|
94
|
+
libusb_lock_events@4 = libusb_lock_events
|
95
|
+
libusb_open
|
96
|
+
libusb_open@8 = libusb_open
|
97
|
+
libusb_open_device_with_vid_pid
|
98
|
+
libusb_open_device_with_vid_pid@12 = libusb_open_device_with_vid_pid
|
99
|
+
libusb_pollfds_handle_timeouts
|
100
|
+
libusb_pollfds_handle_timeouts@4 = libusb_pollfds_handle_timeouts
|
101
|
+
libusb_ref_device
|
102
|
+
libusb_ref_device@4 = libusb_ref_device
|
103
|
+
libusb_release_interface
|
104
|
+
libusb_release_interface@8 = libusb_release_interface
|
105
|
+
libusb_reset_device
|
106
|
+
libusb_reset_device@4 = libusb_reset_device
|
107
|
+
libusb_set_configuration
|
108
|
+
libusb_set_configuration@8 = libusb_set_configuration
|
109
|
+
libusb_set_debug
|
110
|
+
libusb_set_debug@8 = libusb_set_debug
|
111
|
+
libusb_set_interface_alt_setting
|
112
|
+
libusb_set_interface_alt_setting@12 = libusb_set_interface_alt_setting
|
113
|
+
libusb_set_pollfd_notifiers
|
114
|
+
libusb_set_pollfd_notifiers@16 = libusb_set_pollfd_notifiers
|
115
|
+
libusb_submit_transfer
|
116
|
+
libusb_submit_transfer@4 = libusb_submit_transfer
|
117
|
+
libusb_try_lock_events
|
118
|
+
libusb_try_lock_events@4 = libusb_try_lock_events
|
119
|
+
libusb_unlock_event_waiters
|
120
|
+
libusb_unlock_event_waiters@4 = libusb_unlock_event_waiters
|
121
|
+
libusb_unlock_events
|
122
|
+
libusb_unlock_events@4 = libusb_unlock_events
|
123
|
+
libusb_unref_device
|
124
|
+
libusb_unref_device@4 = libusb_unref_device
|
125
|
+
libusb_wait_for_event
|
126
|
+
libusb_wait_for_event@8 = libusb_wait_for_event
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/*
|
2
|
+
* For Windows: input this file to the Resoure Compiler to produce a binary
|
3
|
+
* .res file. This is then embedded in the resultant library (like any other
|
4
|
+
* compilation object).
|
5
|
+
* The information can then be queried using standard APIs and can also be
|
6
|
+
* viewed with utilities such as Windows Explorer.
|
7
|
+
*/
|
8
|
+
#include "winresrc.h"
|
9
|
+
|
10
|
+
#include "version.h"
|
11
|
+
#ifndef LIBUSB_VERSIONSTRING
|
12
|
+
#define LU_STR(s) #s
|
13
|
+
#define LU_XSTR(s) LU_STR(s)
|
14
|
+
#if LIBUSB_NANO > 0
|
15
|
+
#define LIBUSB_VERSIONSTRING \
|
16
|
+
LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
|
17
|
+
LU_XSTR(LIBUSB_MICRO) "." LU_XSTR(LIBUSB_NANO) LIBUSB_RC "\0"
|
18
|
+
#else
|
19
|
+
#define LIBUSB_VERSIONSTRING \
|
20
|
+
LU_XSTR(LIBUSB_MAJOR) "." LU_XSTR(LIBUSB_MINOR) "." \
|
21
|
+
LU_XSTR(LIBUSB_MICRO) LIBUSB_RC "\0"
|
22
|
+
#endif
|
23
|
+
#endif
|
24
|
+
|
25
|
+
VS_VERSION_INFO VERSIONINFO
|
26
|
+
FILEVERSION LIBUSB_MAJOR,LIBUSB_MINOR,LIBUSB_MICRO,LIBUSB_NANO
|
27
|
+
PRODUCTVERSION LIBUSB_MAJOR,LIBUSB_MINOR,LIBUSB_MICRO,LIBUSB_NANO
|
28
|
+
FILEFLAGSMASK 0x3fL
|
29
|
+
#ifdef _DEBUG
|
30
|
+
FILEFLAGS 0x1L
|
31
|
+
#else
|
32
|
+
FILEFLAGS 0x0L
|
33
|
+
#endif
|
34
|
+
FILEOS 0x40004L
|
35
|
+
FILETYPE 0x2L
|
36
|
+
FILESUBTYPE 0x0L
|
37
|
+
BEGIN
|
38
|
+
BLOCK "StringFileInfo"
|
39
|
+
BEGIN
|
40
|
+
BLOCK "040904b0"
|
41
|
+
BEGIN
|
42
|
+
VALUE "CompanyName", "libusbx.org\0"
|
43
|
+
VALUE "FileDescription", "C library for writing portable USB drivers in userspace\0"
|
44
|
+
VALUE "FileVersion", LIBUSB_VERSIONSTRING
|
45
|
+
VALUE "InternalName", "libusb\0"
|
46
|
+
VALUE "LegalCopyright", "See individual source files, GNU LGPL v2.1 or later.\0"
|
47
|
+
VALUE "LegalTrademarks", "http://www.gnu.org/licenses/lgpl-2.1.html\0"
|
48
|
+
VALUE "OriginalFilename", "libusb-1.0.dll\0"
|
49
|
+
VALUE "PrivateBuild", "\0"
|
50
|
+
VALUE "ProductName", "libusb-1.0\0"
|
51
|
+
VALUE "ProductVersion", LIBUSB_VERSIONSTRING
|
52
|
+
VALUE "SpecialBuild", "\0"
|
53
|
+
END
|
54
|
+
END
|
55
|
+
BLOCK "VarFileInfo"
|
56
|
+
BEGIN
|
57
|
+
VALUE "Translation", 0x409, 1200
|
58
|
+
END
|
59
|
+
END
|
@@ -0,0 +1,1506 @@
|
|
1
|
+
/*
|
2
|
+
* Public libusbx header file
|
3
|
+
* Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
4
|
+
* Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
|
5
|
+
* Copyright © 2012 Pete Batard <pete@akeo.ie>
|
6
|
+
* For more information, please visit: http://libusbx.org
|
7
|
+
*
|
8
|
+
* This library is free software; you can redistribute it and/or
|
9
|
+
* modify it under the terms of the GNU Lesser General Public
|
10
|
+
* License as published by the Free Software Foundation; either
|
11
|
+
* version 2.1 of the License, or (at your option) any later version.
|
12
|
+
*
|
13
|
+
* This library is distributed in the hope that it will be useful,
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
* Lesser General Public License for more details.
|
17
|
+
*
|
18
|
+
* You should have received a copy of the GNU Lesser General Public
|
19
|
+
* License along with this library; if not, write to the Free Software
|
20
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
*/
|
22
|
+
|
23
|
+
#ifndef LIBUSB_H
|
24
|
+
#define LIBUSB_H
|
25
|
+
|
26
|
+
#ifdef _MSC_VER
|
27
|
+
/* on MS environments, the inline keyword is available in C++ only */
|
28
|
+
#if !defined(__cplusplus)
|
29
|
+
#define inline __inline
|
30
|
+
#endif
|
31
|
+
/* ssize_t is also not available (copy/paste from MinGW) */
|
32
|
+
#ifndef _SSIZE_T_DEFINED
|
33
|
+
#define _SSIZE_T_DEFINED
|
34
|
+
#undef ssize_t
|
35
|
+
#ifdef _WIN64
|
36
|
+
typedef __int64 ssize_t;
|
37
|
+
#else
|
38
|
+
typedef int ssize_t;
|
39
|
+
#endif /* _WIN64 */
|
40
|
+
#endif /* _SSIZE_T_DEFINED */
|
41
|
+
#endif /* _MSC_VER */
|
42
|
+
|
43
|
+
/* stdint.h is also not usually available on MS */
|
44
|
+
#if defined(_MSC_VER) && (_MSC_VER < 1600) && (!defined(_STDINT)) && (!defined(_STDINT_H))
|
45
|
+
typedef unsigned __int8 uint8_t;
|
46
|
+
typedef unsigned __int16 uint16_t;
|
47
|
+
typedef unsigned __int32 uint32_t;
|
48
|
+
#else
|
49
|
+
#include <stdint.h>
|
50
|
+
#endif
|
51
|
+
|
52
|
+
#include <sys/types.h>
|
53
|
+
#include <time.h>
|
54
|
+
#include <limits.h>
|
55
|
+
|
56
|
+
#if defined(__linux) || defined(__APPLE__) || defined(__CYGWIN__)
|
57
|
+
#include <sys/time.h>
|
58
|
+
#endif
|
59
|
+
|
60
|
+
/* 'interface' might be defined as a macro on Windows, so we need to
|
61
|
+
* undefine it so as not to break the current libusbx API, because
|
62
|
+
* libusb_config_descriptor has an 'interface' member
|
63
|
+
* As this can be problematic if you include windows.h after libusb.h
|
64
|
+
* in your sources, we force windows.h to be included first. */
|
65
|
+
#if defined(_WIN32) || defined(__CYGWIN__)
|
66
|
+
#include <windows.h>
|
67
|
+
#if defined(interface)
|
68
|
+
#undef interface
|
69
|
+
#endif
|
70
|
+
#endif
|
71
|
+
|
72
|
+
/** \def LIBUSB_CALL
|
73
|
+
* \ingroup misc
|
74
|
+
* libusbx's Windows calling convention.
|
75
|
+
*
|
76
|
+
* Under Windows, the selection of available compilers and configurations
|
77
|
+
* means that, unlike other platforms, there is not <em>one true calling
|
78
|
+
* convention</em> (calling convention: the manner in which parameters are
|
79
|
+
* passed to funcions in the generated assembly code).
|
80
|
+
*
|
81
|
+
* Matching the Windows API itself, libusbx uses the WINAPI convention (which
|
82
|
+
* translates to the <tt>stdcall</tt> convention) and guarantees that the
|
83
|
+
* library is compiled in this way. The public header file also includes
|
84
|
+
* appropriate annotations so that your own software will use the right
|
85
|
+
* convention, even if another convention is being used by default within
|
86
|
+
* your codebase.
|
87
|
+
*
|
88
|
+
* The one consideration that you must apply in your software is to mark
|
89
|
+
* all functions which you use as libusbx callbacks with this LIBUSB_CALL
|
90
|
+
* annotation, so that they too get compiled for the correct calling
|
91
|
+
* convention.
|
92
|
+
*
|
93
|
+
* On non-Windows operating systems, this macro is defined as nothing. This
|
94
|
+
* means that you can apply it to your code without worrying about
|
95
|
+
* cross-platform compatibility.
|
96
|
+
*/
|
97
|
+
/* LIBUSB_CALL must be defined on both definition and declaration of libusbx
|
98
|
+
* functions. You'd think that declaration would be enough, but cygwin will
|
99
|
+
* complain about conflicting types unless both are marked this way.
|
100
|
+
* The placement of this macro is important too; it must appear after the
|
101
|
+
* return type, before the function name. See internal documentation for
|
102
|
+
* API_EXPORTED.
|
103
|
+
*/
|
104
|
+
#if defined(_WIN32) || defined(__CYGWIN__)
|
105
|
+
#define LIBUSB_CALL WINAPI
|
106
|
+
#else
|
107
|
+
#define LIBUSB_CALL
|
108
|
+
#endif
|
109
|
+
|
110
|
+
/** \def LIBUSBX_API_VERSION
|
111
|
+
* \ingroup misc
|
112
|
+
* libusbx's API version.
|
113
|
+
*
|
114
|
+
* Since version 1.0.13, to help with feature detection, libusbx defines
|
115
|
+
* a LIBUSBX_API_VERSION macro that gets increased every time there is a
|
116
|
+
* significant change to the API, such as the introduction of a new call,
|
117
|
+
* the definition of a new macro/enum member, or any other element that
|
118
|
+
* libusbx applications may want to detect at compilation time.
|
119
|
+
*
|
120
|
+
* The macro is typically used in an application as follows:
|
121
|
+
* \code
|
122
|
+
* #if defined(LIBUSBX_API_VERSION) && (LIBUSBX_API_VERSION >= 0x01001234)
|
123
|
+
* // Use one of the newer features from the libusbx API
|
124
|
+
* #endif
|
125
|
+
* \endcode
|
126
|
+
*
|
127
|
+
* Another feature of LIBUSBX_API_VERSION is that it can be used to detect
|
128
|
+
* whether you are compiling against the libusb or the libusbx library.
|
129
|
+
*
|
130
|
+
* Internally, LIBUSBX_API_VERSION is defined as follows:
|
131
|
+
* (libusbx major << 24) | (libusbx minor << 16) | (16 bit incremental)
|
132
|
+
*/
|
133
|
+
#define LIBUSBX_API_VERSION 0x010000FF
|
134
|
+
|
135
|
+
#ifdef __cplusplus
|
136
|
+
extern "C" {
|
137
|
+
#endif
|
138
|
+
|
139
|
+
/** \def libusb_cpu_to_le16
|
140
|
+
* \ingroup misc
|
141
|
+
* Convert a 16-bit value from host-endian to little-endian format. On
|
142
|
+
* little endian systems, this function does nothing. On big endian systems,
|
143
|
+
* the bytes are swapped.
|
144
|
+
* \param x the host-endian value to convert
|
145
|
+
* \returns the value in little-endian byte order
|
146
|
+
*/
|
147
|
+
static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
|
148
|
+
{
|
149
|
+
union {
|
150
|
+
uint8_t b8[2];
|
151
|
+
uint16_t b16;
|
152
|
+
} _tmp;
|
153
|
+
_tmp.b8[1] = x >> 8;
|
154
|
+
_tmp.b8[0] = x & 0xff;
|
155
|
+
return _tmp.b16;
|
156
|
+
}
|
157
|
+
|
158
|
+
/** \def libusb_le16_to_cpu
|
159
|
+
* \ingroup misc
|
160
|
+
* Convert a 16-bit value from little-endian to host-endian format. On
|
161
|
+
* little endian systems, this function does nothing. On big endian systems,
|
162
|
+
* the bytes are swapped.
|
163
|
+
* \param x the little-endian value to convert
|
164
|
+
* \returns the value in host-endian byte order
|
165
|
+
*/
|
166
|
+
#define libusb_le16_to_cpu libusb_cpu_to_le16
|
167
|
+
|
168
|
+
/* standard USB stuff */
|
169
|
+
|
170
|
+
/** \ingroup desc
|
171
|
+
* Device and/or Interface Class codes */
|
172
|
+
enum libusb_class_code {
|
173
|
+
/** In the context of a \ref libusb_device_descriptor "device descriptor",
|
174
|
+
* this bDeviceClass value indicates that each interface specifies its
|
175
|
+
* own class information and all interfaces operate independently.
|
176
|
+
*/
|
177
|
+
LIBUSB_CLASS_PER_INTERFACE = 0,
|
178
|
+
|
179
|
+
/** Audio class */
|
180
|
+
LIBUSB_CLASS_AUDIO = 1,
|
181
|
+
|
182
|
+
/** Communications class */
|
183
|
+
LIBUSB_CLASS_COMM = 2,
|
184
|
+
|
185
|
+
/** Human Interface Device class */
|
186
|
+
LIBUSB_CLASS_HID = 3,
|
187
|
+
|
188
|
+
/** Physical */
|
189
|
+
LIBUSB_CLASS_PHYSICAL = 5,
|
190
|
+
|
191
|
+
/** Printer class */
|
192
|
+
LIBUSB_CLASS_PRINTER = 7,
|
193
|
+
|
194
|
+
/** Image class */
|
195
|
+
LIBUSB_CLASS_PTP = 6, /* legacy name from libusb-0.1 usb.h */
|
196
|
+
LIBUSB_CLASS_IMAGE = 6,
|
197
|
+
|
198
|
+
/** Mass storage class */
|
199
|
+
LIBUSB_CLASS_MASS_STORAGE = 8,
|
200
|
+
|
201
|
+
/** Hub class */
|
202
|
+
LIBUSB_CLASS_HUB = 9,
|
203
|
+
|
204
|
+
/** Data class */
|
205
|
+
LIBUSB_CLASS_DATA = 10,
|
206
|
+
|
207
|
+
/** Smart Card */
|
208
|
+
LIBUSB_CLASS_SMART_CARD = 0x0b,
|
209
|
+
|
210
|
+
/** Content Security */
|
211
|
+
LIBUSB_CLASS_CONTENT_SECURITY = 0x0d,
|
212
|
+
|
213
|
+
/** Video */
|
214
|
+
LIBUSB_CLASS_VIDEO = 0x0e,
|
215
|
+
|
216
|
+
/** Personal Healthcare */
|
217
|
+
LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
|
218
|
+
|
219
|
+
/** Diagnostic Device */
|
220
|
+
LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
|
221
|
+
|
222
|
+
/** Wireless class */
|
223
|
+
LIBUSB_CLASS_WIRELESS = 0xe0,
|
224
|
+
|
225
|
+
/** Application class */
|
226
|
+
LIBUSB_CLASS_APPLICATION = 0xfe,
|
227
|
+
|
228
|
+
/** Class is vendor-specific */
|
229
|
+
LIBUSB_CLASS_VENDOR_SPEC = 0xff
|
230
|
+
};
|
231
|
+
|
232
|
+
/** \ingroup desc
|
233
|
+
* Descriptor types as defined by the USB specification. */
|
234
|
+
enum libusb_descriptor_type {
|
235
|
+
/** Device descriptor. See libusb_device_descriptor. */
|
236
|
+
LIBUSB_DT_DEVICE = 0x01,
|
237
|
+
|
238
|
+
/** Configuration descriptor. See libusb_config_descriptor. */
|
239
|
+
LIBUSB_DT_CONFIG = 0x02,
|
240
|
+
|
241
|
+
/** String descriptor */
|
242
|
+
LIBUSB_DT_STRING = 0x03,
|
243
|
+
|
244
|
+
/** Interface descriptor. See libusb_interface_descriptor. */
|
245
|
+
LIBUSB_DT_INTERFACE = 0x04,
|
246
|
+
|
247
|
+
/** Endpoint descriptor. See libusb_endpoint_descriptor. */
|
248
|
+
LIBUSB_DT_ENDPOINT = 0x05,
|
249
|
+
|
250
|
+
/** HID descriptor */
|
251
|
+
LIBUSB_DT_HID = 0x21,
|
252
|
+
|
253
|
+
/** HID report descriptor */
|
254
|
+
LIBUSB_DT_REPORT = 0x22,
|
255
|
+
|
256
|
+
/** Physical descriptor */
|
257
|
+
LIBUSB_DT_PHYSICAL = 0x23,
|
258
|
+
|
259
|
+
/** Hub descriptor */
|
260
|
+
LIBUSB_DT_HUB = 0x29,
|
261
|
+
|
262
|
+
/** SuperSpeed Hub descriptor */
|
263
|
+
LIBUSB_DT_SUPERSPEED_HUB = 0x2A,
|
264
|
+
};
|
265
|
+
|
266
|
+
/* Descriptor sizes per descriptor type */
|
267
|
+
#define LIBUSB_DT_DEVICE_SIZE 18
|
268
|
+
#define LIBUSB_DT_CONFIG_SIZE 9
|
269
|
+
#define LIBUSB_DT_INTERFACE_SIZE 9
|
270
|
+
#define LIBUSB_DT_ENDPOINT_SIZE 7
|
271
|
+
#define LIBUSB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
|
272
|
+
#define LIBUSB_DT_HUB_NONVAR_SIZE 7
|
273
|
+
|
274
|
+
#define LIBUSB_ENDPOINT_ADDRESS_MASK 0x0f /* in bEndpointAddress */
|
275
|
+
#define LIBUSB_ENDPOINT_DIR_MASK 0x80
|
276
|
+
|
277
|
+
/** \ingroup desc
|
278
|
+
* Endpoint direction. Values for bit 7 of the
|
279
|
+
* \ref libusb_endpoint_descriptor::bEndpointAddress "endpoint address" scheme.
|
280
|
+
*/
|
281
|
+
enum libusb_endpoint_direction {
|
282
|
+
/** In: device-to-host */
|
283
|
+
LIBUSB_ENDPOINT_IN = 0x80,
|
284
|
+
|
285
|
+
/** Out: host-to-device */
|
286
|
+
LIBUSB_ENDPOINT_OUT = 0x00
|
287
|
+
};
|
288
|
+
|
289
|
+
#define LIBUSB_TRANSFER_TYPE_MASK 0x03 /* in bmAttributes */
|
290
|
+
|
291
|
+
/** \ingroup desc
|
292
|
+
* Endpoint transfer type. Values for bits 0:1 of the
|
293
|
+
* \ref libusb_endpoint_descriptor::bmAttributes "endpoint attributes" field.
|
294
|
+
*/
|
295
|
+
enum libusb_transfer_type {
|
296
|
+
/** Control endpoint */
|
297
|
+
LIBUSB_TRANSFER_TYPE_CONTROL = 0,
|
298
|
+
|
299
|
+
/** Isochronous endpoint */
|
300
|
+
LIBUSB_TRANSFER_TYPE_ISOCHRONOUS = 1,
|
301
|
+
|
302
|
+
/** Bulk endpoint */
|
303
|
+
LIBUSB_TRANSFER_TYPE_BULK = 2,
|
304
|
+
|
305
|
+
/** Interrupt endpoint */
|
306
|
+
LIBUSB_TRANSFER_TYPE_INTERRUPT = 3
|
307
|
+
};
|
308
|
+
|
309
|
+
/** \ingroup misc
|
310
|
+
* Standard requests, as defined in table 9-5 of the USB 3.0 specifications */
|
311
|
+
enum libusb_standard_request {
|
312
|
+
/** Request status of the specific recipient */
|
313
|
+
LIBUSB_REQUEST_GET_STATUS = 0x00,
|
314
|
+
|
315
|
+
/** Clear or disable a specific feature */
|
316
|
+
LIBUSB_REQUEST_CLEAR_FEATURE = 0x01,
|
317
|
+
|
318
|
+
/* 0x02 is reserved */
|
319
|
+
|
320
|
+
/** Set or enable a specific feature */
|
321
|
+
LIBUSB_REQUEST_SET_FEATURE = 0x03,
|
322
|
+
|
323
|
+
/* 0x04 is reserved */
|
324
|
+
|
325
|
+
/** Set device address for all future accesses */
|
326
|
+
LIBUSB_REQUEST_SET_ADDRESS = 0x05,
|
327
|
+
|
328
|
+
/** Get the specified descriptor */
|
329
|
+
LIBUSB_REQUEST_GET_DESCRIPTOR = 0x06,
|
330
|
+
|
331
|
+
/** Used to update existing descriptors or add new descriptors */
|
332
|
+
LIBUSB_REQUEST_SET_DESCRIPTOR = 0x07,
|
333
|
+
|
334
|
+
/** Get the current device configuration value */
|
335
|
+
LIBUSB_REQUEST_GET_CONFIGURATION = 0x08,
|
336
|
+
|
337
|
+
/** Set device configuration */
|
338
|
+
LIBUSB_REQUEST_SET_CONFIGURATION = 0x09,
|
339
|
+
|
340
|
+
/** Return the selected alternate setting for the specified interface */
|
341
|
+
LIBUSB_REQUEST_GET_INTERFACE = 0x0A,
|
342
|
+
|
343
|
+
/** Select an alternate interface for the specified interface */
|
344
|
+
LIBUSB_REQUEST_SET_INTERFACE = 0x0B,
|
345
|
+
|
346
|
+
/** Set then report an endpoint's synchronization frame */
|
347
|
+
LIBUSB_REQUEST_SYNCH_FRAME = 0x0C,
|
348
|
+
|
349
|
+
/** Sets both the U1 and U2 Exit Latency */
|
350
|
+
LIBUSB_REQUEST_SET_SEL = 0x30,
|
351
|
+
|
352
|
+
/** Delay from the time a host transmits a packet to the time it is
|
353
|
+
* received by the device. */
|
354
|
+
LIBUSB_SET_ISOCH_DELAY = 0x31,
|
355
|
+
};
|
356
|
+
|
357
|
+
/** \ingroup misc
|
358
|
+
* Request type bits of the
|
359
|
+
* \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
|
360
|
+
* transfers. */
|
361
|
+
enum libusb_request_type {
|
362
|
+
/** Standard */
|
363
|
+
LIBUSB_REQUEST_TYPE_STANDARD = (0x00 << 5),
|
364
|
+
|
365
|
+
/** Class */
|
366
|
+
LIBUSB_REQUEST_TYPE_CLASS = (0x01 << 5),
|
367
|
+
|
368
|
+
/** Vendor */
|
369
|
+
LIBUSB_REQUEST_TYPE_VENDOR = (0x02 << 5),
|
370
|
+
|
371
|
+
/** Reserved */
|
372
|
+
LIBUSB_REQUEST_TYPE_RESERVED = (0x03 << 5)
|
373
|
+
};
|
374
|
+
|
375
|
+
/** \ingroup misc
|
376
|
+
* Recipient bits of the
|
377
|
+
* \ref libusb_control_setup::bmRequestType "bmRequestType" field in control
|
378
|
+
* transfers. Values 4 through 31 are reserved. */
|
379
|
+
enum libusb_request_recipient {
|
380
|
+
/** Device */
|
381
|
+
LIBUSB_RECIPIENT_DEVICE = 0x00,
|
382
|
+
|
383
|
+
/** Interface */
|
384
|
+
LIBUSB_RECIPIENT_INTERFACE = 0x01,
|
385
|
+
|
386
|
+
/** Endpoint */
|
387
|
+
LIBUSB_RECIPIENT_ENDPOINT = 0x02,
|
388
|
+
|
389
|
+
/** Other */
|
390
|
+
LIBUSB_RECIPIENT_OTHER = 0x03,
|
391
|
+
};
|
392
|
+
|
393
|
+
#define LIBUSB_ISO_SYNC_TYPE_MASK 0x0C
|
394
|
+
|
395
|
+
/** \ingroup desc
|
396
|
+
* Synchronization type for isochronous endpoints. Values for bits 2:3 of the
|
397
|
+
* \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
|
398
|
+
* libusb_endpoint_descriptor.
|
399
|
+
*/
|
400
|
+
enum libusb_iso_sync_type {
|
401
|
+
/** No synchronization */
|
402
|
+
LIBUSB_ISO_SYNC_TYPE_NONE = 0,
|
403
|
+
|
404
|
+
/** Asynchronous */
|
405
|
+
LIBUSB_ISO_SYNC_TYPE_ASYNC = 1,
|
406
|
+
|
407
|
+
/** Adaptive */
|
408
|
+
LIBUSB_ISO_SYNC_TYPE_ADAPTIVE = 2,
|
409
|
+
|
410
|
+
/** Synchronous */
|
411
|
+
LIBUSB_ISO_SYNC_TYPE_SYNC = 3
|
412
|
+
};
|
413
|
+
|
414
|
+
#define LIBUSB_ISO_USAGE_TYPE_MASK 0x30
|
415
|
+
|
416
|
+
/** \ingroup desc
|
417
|
+
* Usage type for isochronous endpoints. Values for bits 4:5 of the
|
418
|
+
* \ref libusb_endpoint_descriptor::bmAttributes "bmAttributes" field in
|
419
|
+
* libusb_endpoint_descriptor.
|
420
|
+
*/
|
421
|
+
enum libusb_iso_usage_type {
|
422
|
+
/** Data endpoint */
|
423
|
+
LIBUSB_ISO_USAGE_TYPE_DATA = 0,
|
424
|
+
|
425
|
+
/** Feedback endpoint */
|
426
|
+
LIBUSB_ISO_USAGE_TYPE_FEEDBACK = 1,
|
427
|
+
|
428
|
+
/** Implicit feedback Data endpoint */
|
429
|
+
LIBUSB_ISO_USAGE_TYPE_IMPLICIT = 2,
|
430
|
+
};
|
431
|
+
|
432
|
+
/** \ingroup desc
|
433
|
+
* A structure representing the standard USB device descriptor. This
|
434
|
+
* descriptor is documented in section 9.6.1 of the USB 3.0 specification.
|
435
|
+
* All multiple-byte fields are represented in host-endian format.
|
436
|
+
*/
|
437
|
+
struct libusb_device_descriptor {
|
438
|
+
/** Size of this descriptor (in bytes) */
|
439
|
+
uint8_t bLength;
|
440
|
+
|
441
|
+
/** Descriptor type. Will have value
|
442
|
+
* \ref libusb_descriptor_type::LIBUSB_DT_DEVICE LIBUSB_DT_DEVICE in this
|
443
|
+
* context. */
|
444
|
+
uint8_t bDescriptorType;
|
445
|
+
|
446
|
+
/** USB specification release number in binary-coded decimal. A value of
|
447
|
+
* 0x0200 indicates USB 2.0, 0x0110 indicates USB 1.1, etc. */
|
448
|
+
uint16_t bcdUSB;
|
449
|
+
|
450
|
+
/** USB-IF class code for the device. See \ref libusb_class_code. */
|
451
|
+
uint8_t bDeviceClass;
|
452
|
+
|
453
|
+
/** USB-IF subclass code for the device, qualified by the bDeviceClass
|
454
|
+
* value */
|
455
|
+
uint8_t bDeviceSubClass;
|
456
|
+
|
457
|
+
/** USB-IF protocol code for the device, qualified by the bDeviceClass and
|
458
|
+
* bDeviceSubClass values */
|
459
|
+
uint8_t bDeviceProtocol;
|
460
|
+
|
461
|
+
/** Maximum packet size for endpoint 0 */
|
462
|
+
uint8_t bMaxPacketSize0;
|
463
|
+
|
464
|
+
/** USB-IF vendor ID */
|
465
|
+
uint16_t idVendor;
|
466
|
+
|
467
|
+
/** USB-IF product ID */
|
468
|
+
uint16_t idProduct;
|
469
|
+
|
470
|
+
/** Device release number in binary-coded decimal */
|
471
|
+
uint16_t bcdDevice;
|
472
|
+
|
473
|
+
/** Index of string descriptor describing manufacturer */
|
474
|
+
uint8_t iManufacturer;
|
475
|
+
|
476
|
+
/** Index of string descriptor describing product */
|
477
|
+
uint8_t iProduct;
|
478
|
+
|
479
|
+
/** Index of string descriptor containing device serial number */
|
480
|
+
uint8_t iSerialNumber;
|
481
|
+
|
482
|
+
/** Number of possible configurations */
|
483
|
+
uint8_t bNumConfigurations;
|
484
|
+
};
|
485
|
+
|
486
|
+
/** \ingroup desc
|
487
|
+
* A structure representing the standard USB endpoint descriptor. This
|
488
|
+
* descriptor is documented in section 9.6.6 of the USB 3.0 specification.
|
489
|
+
* All multiple-byte fields are represented in host-endian format.
|
490
|
+
*/
|
491
|
+
struct libusb_endpoint_descriptor {
|
492
|
+
/** Size of this descriptor (in bytes) */
|
493
|
+
uint8_t bLength;
|
494
|
+
|
495
|
+
/** Descriptor type. Will have value
|
496
|
+
* \ref libusb_descriptor_type::LIBUSB_DT_ENDPOINT LIBUSB_DT_ENDPOINT in
|
497
|
+
* this context. */
|
498
|
+
uint8_t bDescriptorType;
|
499
|
+
|
500
|
+
/** The address of the endpoint described by this descriptor. Bits 0:3 are
|
501
|
+
* the endpoint number. Bits 4:6 are reserved. Bit 7 indicates direction,
|
502
|
+
* see \ref libusb_endpoint_direction.
|
503
|
+
*/
|
504
|
+
uint8_t bEndpointAddress;
|
505
|
+
|
506
|
+
/** Attributes which apply to the endpoint when it is configured using
|
507
|
+
* the bConfigurationValue. Bits 0:1 determine the transfer type and
|
508
|
+
* correspond to \ref libusb_transfer_type. Bits 2:3 are only used for
|
509
|
+
* isochronous endpoints and correspond to \ref libusb_iso_sync_type.
|
510
|
+
* Bits 4:5 are also only used for isochronous endpoints and correspond to
|
511
|
+
* \ref libusb_iso_usage_type. Bits 6:7 are reserved.
|
512
|
+
*/
|
513
|
+
uint8_t bmAttributes;
|
514
|
+
|
515
|
+
/** Maximum packet size this endpoint is capable of sending/receiving. */
|
516
|
+
uint16_t wMaxPacketSize;
|
517
|
+
|
518
|
+
/** Interval for polling endpoint for data transfers. */
|
519
|
+
uint8_t bInterval;
|
520
|
+
|
521
|
+
/** For audio devices only: the rate at which synchronization feedback
|
522
|
+
* is provided. */
|
523
|
+
uint8_t bRefresh;
|
524
|
+
|
525
|
+
/** For audio devices only: the address if the synch endpoint */
|
526
|
+
uint8_t bSynchAddress;
|
527
|
+
|
528
|
+
/** Extra descriptors. If libusbx encounters unknown endpoint descriptors,
|
529
|
+
* it will store them here, should you wish to parse them. */
|
530
|
+
const unsigned char *extra;
|
531
|
+
|
532
|
+
/** Length of the extra descriptors, in bytes. */
|
533
|
+
int extra_length;
|
534
|
+
};
|
535
|
+
|
536
|
+
/** \ingroup desc
|
537
|
+
* A structure representing the standard USB interface descriptor. This
|
538
|
+
* descriptor is documented in section 9.6.5 of the USB 3.0 specification.
|
539
|
+
* All multiple-byte fields are represented in host-endian format.
|
540
|
+
*/
|
541
|
+
struct libusb_interface_descriptor {
|
542
|
+
/** Size of this descriptor (in bytes) */
|
543
|
+
uint8_t bLength;
|
544
|
+
|
545
|
+
/** Descriptor type. Will have value
|
546
|
+
* \ref libusb_descriptor_type::LIBUSB_DT_INTERFACE LIBUSB_DT_INTERFACE
|
547
|
+
* in this context. */
|
548
|
+
uint8_t bDescriptorType;
|
549
|
+
|
550
|
+
/** Number of this interface */
|
551
|
+
uint8_t bInterfaceNumber;
|
552
|
+
|
553
|
+
/** Value used to select this alternate setting for this interface */
|
554
|
+
uint8_t bAlternateSetting;
|
555
|
+
|
556
|
+
/** Number of endpoints used by this interface (excluding the control
|
557
|
+
* endpoint). */
|
558
|
+
uint8_t bNumEndpoints;
|
559
|
+
|
560
|
+
/** USB-IF class code for this interface. See \ref libusb_class_code. */
|
561
|
+
uint8_t bInterfaceClass;
|
562
|
+
|
563
|
+
/** USB-IF subclass code for this interface, qualified by the
|
564
|
+
* bInterfaceClass value */
|
565
|
+
uint8_t bInterfaceSubClass;
|
566
|
+
|
567
|
+
/** USB-IF protocol code for this interface, qualified by the
|
568
|
+
* bInterfaceClass and bInterfaceSubClass values */
|
569
|
+
uint8_t bInterfaceProtocol;
|
570
|
+
|
571
|
+
/** Index of string descriptor describing this interface */
|
572
|
+
uint8_t iInterface;
|
573
|
+
|
574
|
+
/** Array of endpoint descriptors. This length of this array is determined
|
575
|
+
* by the bNumEndpoints field. */
|
576
|
+
const struct libusb_endpoint_descriptor *endpoint;
|
577
|
+
|
578
|
+
/** Extra descriptors. If libusbx encounters unknown interface descriptors,
|
579
|
+
* it will store them here, should you wish to parse them. */
|
580
|
+
const unsigned char *extra;
|
581
|
+
|
582
|
+
/** Length of the extra descriptors, in bytes. */
|
583
|
+
int extra_length;
|
584
|
+
};
|
585
|
+
|
586
|
+
/** \ingroup desc
|
587
|
+
* A collection of alternate settings for a particular USB interface.
|
588
|
+
*/
|
589
|
+
struct libusb_interface {
|
590
|
+
/** Array of interface descriptors. The length of this array is determined
|
591
|
+
* by the num_altsetting field. */
|
592
|
+
const struct libusb_interface_descriptor *altsetting;
|
593
|
+
|
594
|
+
/** The number of alternate settings that belong to this interface */
|
595
|
+
int num_altsetting;
|
596
|
+
};
|
597
|
+
|
598
|
+
/** \ingroup desc
|
599
|
+
* A structure representing the standard USB configuration descriptor. This
|
600
|
+
* descriptor is documented in section 9.6.3 of the USB 3.0 specification.
|
601
|
+
* All multiple-byte fields are represented in host-endian format.
|
602
|
+
*/
|
603
|
+
struct libusb_config_descriptor {
|
604
|
+
/** Size of this descriptor (in bytes) */
|
605
|
+
uint8_t bLength;
|
606
|
+
|
607
|
+
/** Descriptor type. Will have value
|
608
|
+
* \ref libusb_descriptor_type::LIBUSB_DT_CONFIG LIBUSB_DT_CONFIG
|
609
|
+
* in this context. */
|
610
|
+
uint8_t bDescriptorType;
|
611
|
+
|
612
|
+
/** Total length of data returned for this configuration */
|
613
|
+
uint16_t wTotalLength;
|
614
|
+
|
615
|
+
/** Number of interfaces supported by this configuration */
|
616
|
+
uint8_t bNumInterfaces;
|
617
|
+
|
618
|
+
/** Identifier value for this configuration */
|
619
|
+
uint8_t bConfigurationValue;
|
620
|
+
|
621
|
+
/** Index of string descriptor describing this configuration */
|
622
|
+
uint8_t iConfiguration;
|
623
|
+
|
624
|
+
/** Configuration characteristics */
|
625
|
+
uint8_t bmAttributes;
|
626
|
+
|
627
|
+
/** Maximum power consumption of the USB device from this bus in this
|
628
|
+
* configuration when the device is fully opreation. Expressed in units
|
629
|
+
* of 2 mA. */
|
630
|
+
uint8_t MaxPower;
|
631
|
+
|
632
|
+
/** Array of interfaces supported by this configuration. The length of
|
633
|
+
* this array is determined by the bNumInterfaces field. */
|
634
|
+
const struct libusb_interface *interface;
|
635
|
+
|
636
|
+
/** Extra descriptors. If libusbx encounters unknown configuration
|
637
|
+
* descriptors, it will store them here, should you wish to parse them. */
|
638
|
+
const unsigned char *extra;
|
639
|
+
|
640
|
+
/** Length of the extra descriptors, in bytes. */
|
641
|
+
int extra_length;
|
642
|
+
};
|
643
|
+
|
644
|
+
/** \ingroup asyncio
|
645
|
+
* Setup packet for control transfers. */
|
646
|
+
struct libusb_control_setup {
|
647
|
+
/** Request type. Bits 0:4 determine recipient, see
|
648
|
+
* \ref libusb_request_recipient. Bits 5:6 determine type, see
|
649
|
+
* \ref libusb_request_type. Bit 7 determines data transfer direction, see
|
650
|
+
* \ref libusb_endpoint_direction.
|
651
|
+
*/
|
652
|
+
uint8_t bmRequestType;
|
653
|
+
|
654
|
+
/** Request. If the type bits of bmRequestType are equal to
|
655
|
+
* \ref libusb_request_type::LIBUSB_REQUEST_TYPE_STANDARD
|
656
|
+
* "LIBUSB_REQUEST_TYPE_STANDARD" then this field refers to
|
657
|
+
* \ref libusb_standard_request. For other cases, use of this field is
|
658
|
+
* application-specific. */
|
659
|
+
uint8_t bRequest;
|
660
|
+
|
661
|
+
/** Value. Varies according to request */
|
662
|
+
uint16_t wValue;
|
663
|
+
|
664
|
+
/** Index. Varies according to request, typically used to pass an index
|
665
|
+
* or offset */
|
666
|
+
uint16_t wIndex;
|
667
|
+
|
668
|
+
/** Number of bytes to transfer */
|
669
|
+
uint16_t wLength;
|
670
|
+
};
|
671
|
+
|
672
|
+
#define LIBUSB_CONTROL_SETUP_SIZE (sizeof(struct libusb_control_setup))
|
673
|
+
|
674
|
+
/* libusbx */
|
675
|
+
|
676
|
+
struct libusb_context;
|
677
|
+
struct libusb_device;
|
678
|
+
struct libusb_device_handle;
|
679
|
+
|
680
|
+
/** \ingroup lib
|
681
|
+
* Structure providing the version of the libusbx runtime
|
682
|
+
*/
|
683
|
+
struct libusb_version {
|
684
|
+
/** Library major version. */
|
685
|
+
const uint16_t major;
|
686
|
+
|
687
|
+
/** Library minor version. */
|
688
|
+
const uint16_t minor;
|
689
|
+
|
690
|
+
/** Library micro version. */
|
691
|
+
const uint16_t micro;
|
692
|
+
|
693
|
+
/** Library nano version. */
|
694
|
+
const uint16_t nano;
|
695
|
+
|
696
|
+
/** Library release candidate suffix string, e.g. "-rc4". */
|
697
|
+
const char *rc;
|
698
|
+
|
699
|
+
/** For ABI compatibility only. */
|
700
|
+
const char* describe;
|
701
|
+
};
|
702
|
+
|
703
|
+
/** \ingroup lib
|
704
|
+
* Structure representing a libusbx session. The concept of individual libusbx
|
705
|
+
* sessions allows for your program to use two libraries (or dynamically
|
706
|
+
* load two modules) which both independently use libusb. This will prevent
|
707
|
+
* interference between the individual libusbx users - for example
|
708
|
+
* libusb_set_debug() will not affect the other user of the library, and
|
709
|
+
* libusb_exit() will not destroy resources that the other user is still
|
710
|
+
* using.
|
711
|
+
*
|
712
|
+
* Sessions are created by libusb_init() and destroyed through libusb_exit().
|
713
|
+
* If your application is guaranteed to only ever include a single libusbx
|
714
|
+
* user (i.e. you), you do not have to worry about contexts: pass NULL in
|
715
|
+
* every function call where a context is required. The default context
|
716
|
+
* will be used.
|
717
|
+
*
|
718
|
+
* For more information, see \ref contexts.
|
719
|
+
*/
|
720
|
+
typedef struct libusb_context libusb_context;
|
721
|
+
|
722
|
+
/** \ingroup dev
|
723
|
+
* Structure representing a USB device detected on the system. This is an
|
724
|
+
* opaque type for which you are only ever provided with a pointer, usually
|
725
|
+
* originating from libusb_get_device_list().
|
726
|
+
*
|
727
|
+
* Certain operations can be performed on a device, but in order to do any
|
728
|
+
* I/O you will have to first obtain a device handle using libusb_open().
|
729
|
+
*
|
730
|
+
* Devices are reference counted with libusb_device_ref() and
|
731
|
+
* libusb_device_unref(), and are freed when the reference count reaches 0.
|
732
|
+
* New devices presented by libusb_get_device_list() have a reference count of
|
733
|
+
* 1, and libusb_free_device_list() can optionally decrease the reference count
|
734
|
+
* on all devices in the list. libusb_open() adds another reference which is
|
735
|
+
* later destroyed by libusb_close().
|
736
|
+
*/
|
737
|
+
typedef struct libusb_device libusb_device;
|
738
|
+
|
739
|
+
|
740
|
+
/** \ingroup dev
|
741
|
+
* Structure representing a handle on a USB device. This is an opaque type for
|
742
|
+
* which you are only ever provided with a pointer, usually originating from
|
743
|
+
* libusb_open().
|
744
|
+
*
|
745
|
+
* A device handle is used to perform I/O and other operations. When finished
|
746
|
+
* with a device handle, you should call libusb_close().
|
747
|
+
*/
|
748
|
+
typedef struct libusb_device_handle libusb_device_handle;
|
749
|
+
|
750
|
+
/** \ingroup dev
|
751
|
+
* Speed codes. Indicates the speed at which the device is operating.
|
752
|
+
*/
|
753
|
+
enum libusb_speed {
|
754
|
+
/** The OS doesn't report or know the device speed. */
|
755
|
+
LIBUSB_SPEED_UNKNOWN = 0,
|
756
|
+
|
757
|
+
/** The device is operating at low speed (1.5MBit/s). */
|
758
|
+
LIBUSB_SPEED_LOW = 1,
|
759
|
+
|
760
|
+
/** The device is operating at full speed (12MBit/s). */
|
761
|
+
LIBUSB_SPEED_FULL = 2,
|
762
|
+
|
763
|
+
/** The device is operating at high speed (480MBit/s). */
|
764
|
+
LIBUSB_SPEED_HIGH = 3,
|
765
|
+
|
766
|
+
/** The device is operating at super speed (5000MBit/s). */
|
767
|
+
LIBUSB_SPEED_SUPER = 4,
|
768
|
+
};
|
769
|
+
|
770
|
+
/** \ingroup misc
|
771
|
+
* Error codes. Most libusbx functions return 0 on success or one of these
|
772
|
+
* codes on failure.
|
773
|
+
* You can call \ref libusb_error_name() to retrieve a string representation
|
774
|
+
* of an error code.
|
775
|
+
*/
|
776
|
+
enum libusb_error {
|
777
|
+
/** Success (no error) */
|
778
|
+
LIBUSB_SUCCESS = 0,
|
779
|
+
|
780
|
+
/** Input/output error */
|
781
|
+
LIBUSB_ERROR_IO = -1,
|
782
|
+
|
783
|
+
/** Invalid parameter */
|
784
|
+
LIBUSB_ERROR_INVALID_PARAM = -2,
|
785
|
+
|
786
|
+
/** Access denied (insufficient permissions) */
|
787
|
+
LIBUSB_ERROR_ACCESS = -3,
|
788
|
+
|
789
|
+
/** No such device (it may have been disconnected) */
|
790
|
+
LIBUSB_ERROR_NO_DEVICE = -4,
|
791
|
+
|
792
|
+
/** Entity not found */
|
793
|
+
LIBUSB_ERROR_NOT_FOUND = -5,
|
794
|
+
|
795
|
+
/** Resource busy */
|
796
|
+
LIBUSB_ERROR_BUSY = -6,
|
797
|
+
|
798
|
+
/** Operation timed out */
|
799
|
+
LIBUSB_ERROR_TIMEOUT = -7,
|
800
|
+
|
801
|
+
/** Overflow */
|
802
|
+
LIBUSB_ERROR_OVERFLOW = -8,
|
803
|
+
|
804
|
+
/** Pipe error */
|
805
|
+
LIBUSB_ERROR_PIPE = -9,
|
806
|
+
|
807
|
+
/** System call interrupted (perhaps due to signal) */
|
808
|
+
LIBUSB_ERROR_INTERRUPTED = -10,
|
809
|
+
|
810
|
+
/** Insufficient memory */
|
811
|
+
LIBUSB_ERROR_NO_MEM = -11,
|
812
|
+
|
813
|
+
/** Operation not supported or unimplemented on this platform */
|
814
|
+
LIBUSB_ERROR_NOT_SUPPORTED = -12,
|
815
|
+
|
816
|
+
/* NB! Remember to update libusb_error_name()
|
817
|
+
when adding new error codes here. */
|
818
|
+
|
819
|
+
/** Other error */
|
820
|
+
LIBUSB_ERROR_OTHER = -99,
|
821
|
+
};
|
822
|
+
|
823
|
+
/** \ingroup asyncio
|
824
|
+
* Transfer status codes */
|
825
|
+
enum libusb_transfer_status {
|
826
|
+
/** Transfer completed without error. Note that this does not indicate
|
827
|
+
* that the entire amount of requested data was transferred. */
|
828
|
+
LIBUSB_TRANSFER_COMPLETED,
|
829
|
+
|
830
|
+
/** Transfer failed */
|
831
|
+
LIBUSB_TRANSFER_ERROR,
|
832
|
+
|
833
|
+
/** Transfer timed out */
|
834
|
+
LIBUSB_TRANSFER_TIMED_OUT,
|
835
|
+
|
836
|
+
/** Transfer was cancelled */
|
837
|
+
LIBUSB_TRANSFER_CANCELLED,
|
838
|
+
|
839
|
+
/** For bulk/interrupt endpoints: halt condition detected (endpoint
|
840
|
+
* stalled). For control endpoints: control request not supported. */
|
841
|
+
LIBUSB_TRANSFER_STALL,
|
842
|
+
|
843
|
+
/** Device was disconnected */
|
844
|
+
LIBUSB_TRANSFER_NO_DEVICE,
|
845
|
+
|
846
|
+
/** Device sent more data than requested */
|
847
|
+
LIBUSB_TRANSFER_OVERFLOW,
|
848
|
+
|
849
|
+
/* NB! Remember to update libusb_error_name()
|
850
|
+
when adding new status codes here. */
|
851
|
+
};
|
852
|
+
|
853
|
+
/** \ingroup asyncio
|
854
|
+
* libusb_transfer.flags values */
|
855
|
+
enum libusb_transfer_flags {
|
856
|
+
/** Report short frames as errors */
|
857
|
+
LIBUSB_TRANSFER_SHORT_NOT_OK = 1<<0,
|
858
|
+
|
859
|
+
/** Automatically free() transfer buffer during libusb_free_transfer() */
|
860
|
+
LIBUSB_TRANSFER_FREE_BUFFER = 1<<1,
|
861
|
+
|
862
|
+
/** Automatically call libusb_free_transfer() after callback returns.
|
863
|
+
* If this flag is set, it is illegal to call libusb_free_transfer()
|
864
|
+
* from your transfer callback, as this will result in a double-free
|
865
|
+
* when this flag is acted upon. */
|
866
|
+
LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2,
|
867
|
+
|
868
|
+
/** Terminate transfers that are a multiple of the endpoint's
|
869
|
+
* wMaxPacketSize with an extra zero length packet. This is useful
|
870
|
+
* when a device protocol mandates that each logical request is
|
871
|
+
* terminated by an incomplete packet (i.e. the logical requests are
|
872
|
+
* not separated by other means).
|
873
|
+
*
|
874
|
+
* This flag only affects host-to-device transfers to bulk and interrupt
|
875
|
+
* endpoints. In other situations, it is ignored.
|
876
|
+
*
|
877
|
+
* This flag only affects transfers with a length that is a multiple of
|
878
|
+
* the endpoint's wMaxPacketSize. On transfers of other lengths, this
|
879
|
+
* flag has no effect. Therefore, if you are working with a device that
|
880
|
+
* needs a ZLP whenever the end of the logical request falls on a packet
|
881
|
+
* boundary, then it is sensible to set this flag on <em>every</em>
|
882
|
+
* transfer (you do not have to worry about only setting it on transfers
|
883
|
+
* that end on the boundary).
|
884
|
+
*
|
885
|
+
* This flag is currently only supported on Linux.
|
886
|
+
* On other systems, libusb_submit_transfer() will return
|
887
|
+
* LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag is set.
|
888
|
+
*
|
889
|
+
* Available since libusb-1.0.9.
|
890
|
+
*/
|
891
|
+
LIBUSB_TRANSFER_ADD_ZERO_PACKET = 1 << 3,
|
892
|
+
};
|
893
|
+
|
894
|
+
/** \ingroup asyncio
|
895
|
+
* Isochronous packet descriptor. */
|
896
|
+
struct libusb_iso_packet_descriptor {
|
897
|
+
/** Length of data to request in this packet */
|
898
|
+
unsigned int length;
|
899
|
+
|
900
|
+
/** Amount of data that was actually transferred */
|
901
|
+
unsigned int actual_length;
|
902
|
+
|
903
|
+
/** Status code for this packet */
|
904
|
+
enum libusb_transfer_status status;
|
905
|
+
};
|
906
|
+
|
907
|
+
struct libusb_transfer;
|
908
|
+
|
909
|
+
/** \ingroup asyncio
|
910
|
+
* Asynchronous transfer callback function type. When submitting asynchronous
|
911
|
+
* transfers, you pass a pointer to a callback function of this type via the
|
912
|
+
* \ref libusb_transfer::callback "callback" member of the libusb_transfer
|
913
|
+
* structure. libusbx will call this function later, when the transfer has
|
914
|
+
* completed or failed. See \ref asyncio for more information.
|
915
|
+
* \param transfer The libusb_transfer struct the callback function is being
|
916
|
+
* notified about.
|
917
|
+
*/
|
918
|
+
typedef void (LIBUSB_CALL *libusb_transfer_cb_fn)(struct libusb_transfer *transfer);
|
919
|
+
|
920
|
+
/** \ingroup asyncio
|
921
|
+
* The generic USB transfer structure. The user populates this structure and
|
922
|
+
* then submits it in order to request a transfer. After the transfer has
|
923
|
+
* completed, the library populates the transfer with the results and passes
|
924
|
+
* it back to the user.
|
925
|
+
*/
|
926
|
+
struct libusb_transfer {
|
927
|
+
/** Handle of the device that this transfer will be submitted to */
|
928
|
+
libusb_device_handle *dev_handle;
|
929
|
+
|
930
|
+
/** A bitwise OR combination of \ref libusb_transfer_flags. */
|
931
|
+
uint8_t flags;
|
932
|
+
|
933
|
+
/** Address of the endpoint where this transfer will be sent. */
|
934
|
+
unsigned char endpoint;
|
935
|
+
|
936
|
+
/** Type of the endpoint from \ref libusb_transfer_type */
|
937
|
+
unsigned char type;
|
938
|
+
|
939
|
+
/** Timeout for this transfer in millseconds. A value of 0 indicates no
|
940
|
+
* timeout. */
|
941
|
+
unsigned int timeout;
|
942
|
+
|
943
|
+
/** The status of the transfer. Read-only, and only for use within
|
944
|
+
* transfer callback function.
|
945
|
+
*
|
946
|
+
* If this is an isochronous transfer, this field may read COMPLETED even
|
947
|
+
* if there were errors in the frames. Use the
|
948
|
+
* \ref libusb_iso_packet_descriptor::status "status" field in each packet
|
949
|
+
* to determine if errors occurred. */
|
950
|
+
enum libusb_transfer_status status;
|
951
|
+
|
952
|
+
/** Length of the data buffer */
|
953
|
+
int length;
|
954
|
+
|
955
|
+
/** Actual length of data that was transferred. Read-only, and only for
|
956
|
+
* use within transfer callback function. Not valid for isochronous
|
957
|
+
* endpoint transfers. */
|
958
|
+
int actual_length;
|
959
|
+
|
960
|
+
/** Callback function. This will be invoked when the transfer completes,
|
961
|
+
* fails, or is cancelled. */
|
962
|
+
libusb_transfer_cb_fn callback;
|
963
|
+
|
964
|
+
/** User context data to pass to the callback function. */
|
965
|
+
void *user_data;
|
966
|
+
|
967
|
+
/** Data buffer */
|
968
|
+
unsigned char *buffer;
|
969
|
+
|
970
|
+
/** Number of isochronous packets. Only used for I/O with isochronous
|
971
|
+
* endpoints. */
|
972
|
+
int num_iso_packets;
|
973
|
+
|
974
|
+
/** Isochronous packet descriptors, for isochronous transfers only. */
|
975
|
+
struct libusb_iso_packet_descriptor iso_packet_desc
|
976
|
+
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
|
977
|
+
[] /* valid C99 code */
|
978
|
+
#else
|
979
|
+
[0] /* non-standard, but usually working code */
|
980
|
+
#endif
|
981
|
+
;
|
982
|
+
};
|
983
|
+
|
984
|
+
/** \ingroup misc
|
985
|
+
* Capabilities supported by this instance of libusb. Test if the loaded
|
986
|
+
* library supports a given capability by calling
|
987
|
+
* \ref libusb_has_capability().
|
988
|
+
*/
|
989
|
+
enum libusb_capability {
|
990
|
+
/** The libusb_has_capability() API is available. */
|
991
|
+
LIBUSB_CAP_HAS_CAPABILITY = 0,
|
992
|
+
};
|
993
|
+
|
994
|
+
/** \ingroup lib
|
995
|
+
* Log message levels.
|
996
|
+
* - LIBUSB_LOG_LEVEL_NONE (0) : no messages ever printed by the library (default)
|
997
|
+
* - LIBUSB_LOG_LEVEL_ERROR (1) : error messages are printed to stderr
|
998
|
+
* - LIBUSB_LOG_LEVEL_WARNING (2) : warning and error messages are printed to stderr
|
999
|
+
* - LIBUSB_LOG_LEVEL_INFO (3) : informational messages are printed to stdout, warning
|
1000
|
+
* and error messages are printed to stderr
|
1001
|
+
* - LIBUSB_LOG_LEVEL_DEBUG (4) : debug and informational messages are printed to stdout,
|
1002
|
+
* warnings and errors to stderr
|
1003
|
+
*/
|
1004
|
+
enum libusb_log_level {
|
1005
|
+
LIBUSB_LOG_LEVEL_NONE = 0,
|
1006
|
+
LIBUSB_LOG_LEVEL_ERROR,
|
1007
|
+
LIBUSB_LOG_LEVEL_WARNING,
|
1008
|
+
LIBUSB_LOG_LEVEL_INFO,
|
1009
|
+
LIBUSB_LOG_LEVEL_DEBUG,
|
1010
|
+
};
|
1011
|
+
|
1012
|
+
int LIBUSB_CALL libusb_init(libusb_context **ctx);
|
1013
|
+
void LIBUSB_CALL libusb_exit(libusb_context *ctx);
|
1014
|
+
void LIBUSB_CALL libusb_set_debug(libusb_context *ctx, int level);
|
1015
|
+
const struct libusb_version * LIBUSB_CALL libusb_get_version(void);
|
1016
|
+
int LIBUSB_CALL libusb_has_capability(uint32_t capability);
|
1017
|
+
const char * LIBUSB_CALL libusb_error_name(int errcode);
|
1018
|
+
|
1019
|
+
ssize_t LIBUSB_CALL libusb_get_device_list(libusb_context *ctx,
|
1020
|
+
libusb_device ***list);
|
1021
|
+
void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
|
1022
|
+
int unref_devices);
|
1023
|
+
libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
|
1024
|
+
void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
|
1025
|
+
|
1026
|
+
int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
|
1027
|
+
int *config);
|
1028
|
+
int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
|
1029
|
+
struct libusb_device_descriptor *desc);
|
1030
|
+
int LIBUSB_CALL libusb_get_active_config_descriptor(libusb_device *dev,
|
1031
|
+
struct libusb_config_descriptor **config);
|
1032
|
+
int LIBUSB_CALL libusb_get_config_descriptor(libusb_device *dev,
|
1033
|
+
uint8_t config_index, struct libusb_config_descriptor **config);
|
1034
|
+
int LIBUSB_CALL libusb_get_config_descriptor_by_value(libusb_device *dev,
|
1035
|
+
uint8_t bConfigurationValue, struct libusb_config_descriptor **config);
|
1036
|
+
void LIBUSB_CALL libusb_free_config_descriptor(
|
1037
|
+
struct libusb_config_descriptor *config);
|
1038
|
+
uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
|
1039
|
+
uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
|
1040
|
+
libusb_device * LIBUSB_CALL libusb_get_parent(libusb_device *dev);
|
1041
|
+
int LIBUSB_CALL libusb_get_port_path(libusb_context *ctx, libusb_device *dev, uint8_t* path, uint8_t path_length);
|
1042
|
+
uint8_t LIBUSB_CALL libusb_get_device_address(libusb_device *dev);
|
1043
|
+
int LIBUSB_CALL libusb_get_device_speed(libusb_device *dev);
|
1044
|
+
int LIBUSB_CALL libusb_get_max_packet_size(libusb_device *dev,
|
1045
|
+
unsigned char endpoint);
|
1046
|
+
int LIBUSB_CALL libusb_get_max_iso_packet_size(libusb_device *dev,
|
1047
|
+
unsigned char endpoint);
|
1048
|
+
|
1049
|
+
int LIBUSB_CALL libusb_open(libusb_device *dev, libusb_device_handle **handle);
|
1050
|
+
void LIBUSB_CALL libusb_close(libusb_device_handle *dev_handle);
|
1051
|
+
libusb_device * LIBUSB_CALL libusb_get_device(libusb_device_handle *dev_handle);
|
1052
|
+
|
1053
|
+
int LIBUSB_CALL libusb_set_configuration(libusb_device_handle *dev,
|
1054
|
+
int configuration);
|
1055
|
+
int LIBUSB_CALL libusb_claim_interface(libusb_device_handle *dev,
|
1056
|
+
int interface_number);
|
1057
|
+
int LIBUSB_CALL libusb_release_interface(libusb_device_handle *dev,
|
1058
|
+
int interface_number);
|
1059
|
+
|
1060
|
+
libusb_device_handle * LIBUSB_CALL libusb_open_device_with_vid_pid(
|
1061
|
+
libusb_context *ctx, uint16_t vendor_id, uint16_t product_id);
|
1062
|
+
|
1063
|
+
int LIBUSB_CALL libusb_set_interface_alt_setting(libusb_device_handle *dev,
|
1064
|
+
int interface_number, int alternate_setting);
|
1065
|
+
int LIBUSB_CALL libusb_clear_halt(libusb_device_handle *dev,
|
1066
|
+
unsigned char endpoint);
|
1067
|
+
int LIBUSB_CALL libusb_reset_device(libusb_device_handle *dev);
|
1068
|
+
|
1069
|
+
int LIBUSB_CALL libusb_kernel_driver_active(libusb_device_handle *dev,
|
1070
|
+
int interface_number);
|
1071
|
+
int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev,
|
1072
|
+
int interface_number);
|
1073
|
+
int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev,
|
1074
|
+
int interface_number);
|
1075
|
+
|
1076
|
+
/* async I/O */
|
1077
|
+
|
1078
|
+
/** \ingroup asyncio
|
1079
|
+
* Get the data section of a control transfer. This convenience function is here
|
1080
|
+
* to remind you that the data does not start until 8 bytes into the actual
|
1081
|
+
* buffer, as the setup packet comes first.
|
1082
|
+
*
|
1083
|
+
* Calling this function only makes sense from a transfer callback function,
|
1084
|
+
* or situations where you have already allocated a suitably sized buffer at
|
1085
|
+
* transfer->buffer.
|
1086
|
+
*
|
1087
|
+
* \param transfer a transfer
|
1088
|
+
* \returns pointer to the first byte of the data section
|
1089
|
+
*/
|
1090
|
+
static inline unsigned char *libusb_control_transfer_get_data(
|
1091
|
+
struct libusb_transfer *transfer)
|
1092
|
+
{
|
1093
|
+
return transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
|
1094
|
+
}
|
1095
|
+
|
1096
|
+
/** \ingroup asyncio
|
1097
|
+
* Get the control setup packet of a control transfer. This convenience
|
1098
|
+
* function is here to remind you that the control setup occupies the first
|
1099
|
+
* 8 bytes of the transfer data buffer.
|
1100
|
+
*
|
1101
|
+
* Calling this function only makes sense from a transfer callback function,
|
1102
|
+
* or situations where you have already allocated a suitably sized buffer at
|
1103
|
+
* transfer->buffer.
|
1104
|
+
*
|
1105
|
+
* \param transfer a transfer
|
1106
|
+
* \returns a casted pointer to the start of the transfer data buffer
|
1107
|
+
*/
|
1108
|
+
static inline struct libusb_control_setup *libusb_control_transfer_get_setup(
|
1109
|
+
struct libusb_transfer *transfer)
|
1110
|
+
{
|
1111
|
+
return (struct libusb_control_setup *) transfer->buffer;
|
1112
|
+
}
|
1113
|
+
|
1114
|
+
/** \ingroup asyncio
|
1115
|
+
* Helper function to populate the setup packet (first 8 bytes of the data
|
1116
|
+
* buffer) for a control transfer. The wIndex, wValue and wLength values should
|
1117
|
+
* be given in host-endian byte order.
|
1118
|
+
*
|
1119
|
+
* \param buffer buffer to output the setup packet into
|
1120
|
+
* \param bmRequestType see the
|
1121
|
+
* \ref libusb_control_setup::bmRequestType "bmRequestType" field of
|
1122
|
+
* \ref libusb_control_setup
|
1123
|
+
* \param bRequest see the
|
1124
|
+
* \ref libusb_control_setup::bRequest "bRequest" field of
|
1125
|
+
* \ref libusb_control_setup
|
1126
|
+
* \param wValue see the
|
1127
|
+
* \ref libusb_control_setup::wValue "wValue" field of
|
1128
|
+
* \ref libusb_control_setup
|
1129
|
+
* \param wIndex see the
|
1130
|
+
* \ref libusb_control_setup::wIndex "wIndex" field of
|
1131
|
+
* \ref libusb_control_setup
|
1132
|
+
* \param wLength see the
|
1133
|
+
* \ref libusb_control_setup::wLength "wLength" field of
|
1134
|
+
* \ref libusb_control_setup
|
1135
|
+
*/
|
1136
|
+
static inline void libusb_fill_control_setup(unsigned char *buffer,
|
1137
|
+
uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
|
1138
|
+
uint16_t wLength)
|
1139
|
+
{
|
1140
|
+
struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
|
1141
|
+
setup->bmRequestType = bmRequestType;
|
1142
|
+
setup->bRequest = bRequest;
|
1143
|
+
setup->wValue = libusb_cpu_to_le16(wValue);
|
1144
|
+
setup->wIndex = libusb_cpu_to_le16(wIndex);
|
1145
|
+
setup->wLength = libusb_cpu_to_le16(wLength);
|
1146
|
+
}
|
1147
|
+
|
1148
|
+
struct libusb_transfer * LIBUSB_CALL libusb_alloc_transfer(int iso_packets);
|
1149
|
+
int LIBUSB_CALL libusb_submit_transfer(struct libusb_transfer *transfer);
|
1150
|
+
int LIBUSB_CALL libusb_cancel_transfer(struct libusb_transfer *transfer);
|
1151
|
+
void LIBUSB_CALL libusb_free_transfer(struct libusb_transfer *transfer);
|
1152
|
+
|
1153
|
+
/** \ingroup asyncio
|
1154
|
+
* Helper function to populate the required \ref libusb_transfer fields
|
1155
|
+
* for a control transfer.
|
1156
|
+
*
|
1157
|
+
* If you pass a transfer buffer to this function, the first 8 bytes will
|
1158
|
+
* be interpreted as a control setup packet, and the wLength field will be
|
1159
|
+
* used to automatically populate the \ref libusb_transfer::length "length"
|
1160
|
+
* field of the transfer. Therefore the recommended approach is:
|
1161
|
+
* -# Allocate a suitably sized data buffer (including space for control setup)
|
1162
|
+
* -# Call libusb_fill_control_setup()
|
1163
|
+
* -# If this is a host-to-device transfer with a data stage, put the data
|
1164
|
+
* in place after the setup packet
|
1165
|
+
* -# Call this function
|
1166
|
+
* -# Call libusb_submit_transfer()
|
1167
|
+
*
|
1168
|
+
* It is also legal to pass a NULL buffer to this function, in which case this
|
1169
|
+
* function will not attempt to populate the length field. Remember that you
|
1170
|
+
* must then populate the buffer and length fields later.
|
1171
|
+
*
|
1172
|
+
* \param transfer the transfer to populate
|
1173
|
+
* \param dev_handle handle of the device that will handle the transfer
|
1174
|
+
* \param buffer data buffer. If provided, this function will interpret the
|
1175
|
+
* first 8 bytes as a setup packet and infer the transfer length from that.
|
1176
|
+
* \param callback callback function to be invoked on transfer completion
|
1177
|
+
* \param user_data user data to pass to callback function
|
1178
|
+
* \param timeout timeout for the transfer in milliseconds
|
1179
|
+
*/
|
1180
|
+
static inline void libusb_fill_control_transfer(
|
1181
|
+
struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
|
1182
|
+
unsigned char *buffer, libusb_transfer_cb_fn callback, void *user_data,
|
1183
|
+
unsigned int timeout)
|
1184
|
+
{
|
1185
|
+
struct libusb_control_setup *setup = (struct libusb_control_setup *) buffer;
|
1186
|
+
transfer->dev_handle = dev_handle;
|
1187
|
+
transfer->endpoint = 0;
|
1188
|
+
transfer->type = LIBUSB_TRANSFER_TYPE_CONTROL;
|
1189
|
+
transfer->timeout = timeout;
|
1190
|
+
transfer->buffer = buffer;
|
1191
|
+
if (setup)
|
1192
|
+
transfer->length = LIBUSB_CONTROL_SETUP_SIZE
|
1193
|
+
+ libusb_le16_to_cpu(setup->wLength);
|
1194
|
+
transfer->user_data = user_data;
|
1195
|
+
transfer->callback = callback;
|
1196
|
+
}
|
1197
|
+
|
1198
|
+
/** \ingroup asyncio
|
1199
|
+
* Helper function to populate the required \ref libusb_transfer fields
|
1200
|
+
* for a bulk transfer.
|
1201
|
+
*
|
1202
|
+
* \param transfer the transfer to populate
|
1203
|
+
* \param dev_handle handle of the device that will handle the transfer
|
1204
|
+
* \param endpoint address of the endpoint where this transfer will be sent
|
1205
|
+
* \param buffer data buffer
|
1206
|
+
* \param length length of data buffer
|
1207
|
+
* \param callback callback function to be invoked on transfer completion
|
1208
|
+
* \param user_data user data to pass to callback function
|
1209
|
+
* \param timeout timeout for the transfer in milliseconds
|
1210
|
+
*/
|
1211
|
+
static inline void libusb_fill_bulk_transfer(struct libusb_transfer *transfer,
|
1212
|
+
libusb_device_handle *dev_handle, unsigned char endpoint,
|
1213
|
+
unsigned char *buffer, int length, libusb_transfer_cb_fn callback,
|
1214
|
+
void *user_data, unsigned int timeout)
|
1215
|
+
{
|
1216
|
+
transfer->dev_handle = dev_handle;
|
1217
|
+
transfer->endpoint = endpoint;
|
1218
|
+
transfer->type = LIBUSB_TRANSFER_TYPE_BULK;
|
1219
|
+
transfer->timeout = timeout;
|
1220
|
+
transfer->buffer = buffer;
|
1221
|
+
transfer->length = length;
|
1222
|
+
transfer->user_data = user_data;
|
1223
|
+
transfer->callback = callback;
|
1224
|
+
}
|
1225
|
+
|
1226
|
+
/** \ingroup asyncio
|
1227
|
+
* Helper function to populate the required \ref libusb_transfer fields
|
1228
|
+
* for an interrupt transfer.
|
1229
|
+
*
|
1230
|
+
* \param transfer the transfer to populate
|
1231
|
+
* \param dev_handle handle of the device that will handle the transfer
|
1232
|
+
* \param endpoint address of the endpoint where this transfer will be sent
|
1233
|
+
* \param buffer data buffer
|
1234
|
+
* \param length length of data buffer
|
1235
|
+
* \param callback callback function to be invoked on transfer completion
|
1236
|
+
* \param user_data user data to pass to callback function
|
1237
|
+
* \param timeout timeout for the transfer in milliseconds
|
1238
|
+
*/
|
1239
|
+
static inline void libusb_fill_interrupt_transfer(
|
1240
|
+
struct libusb_transfer *transfer, libusb_device_handle *dev_handle,
|
1241
|
+
unsigned char endpoint, unsigned char *buffer, int length,
|
1242
|
+
libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
|
1243
|
+
{
|
1244
|
+
transfer->dev_handle = dev_handle;
|
1245
|
+
transfer->endpoint = endpoint;
|
1246
|
+
transfer->type = LIBUSB_TRANSFER_TYPE_INTERRUPT;
|
1247
|
+
transfer->timeout = timeout;
|
1248
|
+
transfer->buffer = buffer;
|
1249
|
+
transfer->length = length;
|
1250
|
+
transfer->user_data = user_data;
|
1251
|
+
transfer->callback = callback;
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
/** \ingroup asyncio
|
1255
|
+
* Helper function to populate the required \ref libusb_transfer fields
|
1256
|
+
* for an isochronous transfer.
|
1257
|
+
*
|
1258
|
+
* \param transfer the transfer to populate
|
1259
|
+
* \param dev_handle handle of the device that will handle the transfer
|
1260
|
+
* \param endpoint address of the endpoint where this transfer will be sent
|
1261
|
+
* \param buffer data buffer
|
1262
|
+
* \param length length of data buffer
|
1263
|
+
* \param num_iso_packets the number of isochronous packets
|
1264
|
+
* \param callback callback function to be invoked on transfer completion
|
1265
|
+
* \param user_data user data to pass to callback function
|
1266
|
+
* \param timeout timeout for the transfer in milliseconds
|
1267
|
+
*/
|
1268
|
+
static inline void libusb_fill_iso_transfer(struct libusb_transfer *transfer,
|
1269
|
+
libusb_device_handle *dev_handle, unsigned char endpoint,
|
1270
|
+
unsigned char *buffer, int length, int num_iso_packets,
|
1271
|
+
libusb_transfer_cb_fn callback, void *user_data, unsigned int timeout)
|
1272
|
+
{
|
1273
|
+
transfer->dev_handle = dev_handle;
|
1274
|
+
transfer->endpoint = endpoint;
|
1275
|
+
transfer->type = LIBUSB_TRANSFER_TYPE_ISOCHRONOUS;
|
1276
|
+
transfer->timeout = timeout;
|
1277
|
+
transfer->buffer = buffer;
|
1278
|
+
transfer->length = length;
|
1279
|
+
transfer->num_iso_packets = num_iso_packets;
|
1280
|
+
transfer->user_data = user_data;
|
1281
|
+
transfer->callback = callback;
|
1282
|
+
}
|
1283
|
+
|
1284
|
+
/** \ingroup asyncio
|
1285
|
+
* Convenience function to set the length of all packets in an isochronous
|
1286
|
+
* transfer, based on the num_iso_packets field in the transfer structure.
|
1287
|
+
*
|
1288
|
+
* \param transfer a transfer
|
1289
|
+
* \param length the length to set in each isochronous packet descriptor
|
1290
|
+
* \see libusb_get_max_packet_size()
|
1291
|
+
*/
|
1292
|
+
static inline void libusb_set_iso_packet_lengths(
|
1293
|
+
struct libusb_transfer *transfer, unsigned int length)
|
1294
|
+
{
|
1295
|
+
int i;
|
1296
|
+
for (i = 0; i < transfer->num_iso_packets; i++)
|
1297
|
+
transfer->iso_packet_desc[i].length = length;
|
1298
|
+
}
|
1299
|
+
|
1300
|
+
/** \ingroup asyncio
|
1301
|
+
* Convenience function to locate the position of an isochronous packet
|
1302
|
+
* within the buffer of an isochronous transfer.
|
1303
|
+
*
|
1304
|
+
* This is a thorough function which loops through all preceding packets,
|
1305
|
+
* accumulating their lengths to find the position of the specified packet.
|
1306
|
+
* Typically you will assign equal lengths to each packet in the transfer,
|
1307
|
+
* and hence the above method is sub-optimal. You may wish to use
|
1308
|
+
* libusb_get_iso_packet_buffer_simple() instead.
|
1309
|
+
*
|
1310
|
+
* \param transfer a transfer
|
1311
|
+
* \param packet the packet to return the address of
|
1312
|
+
* \returns the base address of the packet buffer inside the transfer buffer,
|
1313
|
+
* or NULL if the packet does not exist.
|
1314
|
+
* \see libusb_get_iso_packet_buffer_simple()
|
1315
|
+
*/
|
1316
|
+
static inline unsigned char *libusb_get_iso_packet_buffer(
|
1317
|
+
struct libusb_transfer *transfer, unsigned int packet)
|
1318
|
+
{
|
1319
|
+
int i;
|
1320
|
+
size_t offset = 0;
|
1321
|
+
int _packet;
|
1322
|
+
|
1323
|
+
/* oops..slight bug in the API. packet is an unsigned int, but we use
|
1324
|
+
* signed integers almost everywhere else. range-check and convert to
|
1325
|
+
* signed to avoid compiler warnings. FIXME for libusb-2. */
|
1326
|
+
if (packet > INT_MAX)
|
1327
|
+
return NULL;
|
1328
|
+
_packet = packet;
|
1329
|
+
|
1330
|
+
if (_packet >= transfer->num_iso_packets)
|
1331
|
+
return NULL;
|
1332
|
+
|
1333
|
+
for (i = 0; i < _packet; i++)
|
1334
|
+
offset += transfer->iso_packet_desc[i].length;
|
1335
|
+
|
1336
|
+
return transfer->buffer + offset;
|
1337
|
+
}
|
1338
|
+
|
1339
|
+
/** \ingroup asyncio
|
1340
|
+
* Convenience function to locate the position of an isochronous packet
|
1341
|
+
* within the buffer of an isochronous transfer, for transfers where each
|
1342
|
+
* packet is of identical size.
|
1343
|
+
*
|
1344
|
+
* This function relies on the assumption that every packet within the transfer
|
1345
|
+
* is of identical size to the first packet. Calculating the location of
|
1346
|
+
* the packet buffer is then just a simple calculation:
|
1347
|
+
* <tt>buffer + (packet_size * packet)</tt>
|
1348
|
+
*
|
1349
|
+
* Do not use this function on transfers other than those that have identical
|
1350
|
+
* packet lengths for each packet.
|
1351
|
+
*
|
1352
|
+
* \param transfer a transfer
|
1353
|
+
* \param packet the packet to return the address of
|
1354
|
+
* \returns the base address of the packet buffer inside the transfer buffer,
|
1355
|
+
* or NULL if the packet does not exist.
|
1356
|
+
* \see libusb_get_iso_packet_buffer()
|
1357
|
+
*/
|
1358
|
+
static inline unsigned char *libusb_get_iso_packet_buffer_simple(
|
1359
|
+
struct libusb_transfer *transfer, unsigned int packet)
|
1360
|
+
{
|
1361
|
+
int _packet;
|
1362
|
+
|
1363
|
+
/* oops..slight bug in the API. packet is an unsigned int, but we use
|
1364
|
+
* signed integers almost everywhere else. range-check and convert to
|
1365
|
+
* signed to avoid compiler warnings. FIXME for libusb-2. */
|
1366
|
+
if (packet > INT_MAX)
|
1367
|
+
return NULL;
|
1368
|
+
_packet = packet;
|
1369
|
+
|
1370
|
+
if (_packet >= transfer->num_iso_packets)
|
1371
|
+
return NULL;
|
1372
|
+
|
1373
|
+
return transfer->buffer + (transfer->iso_packet_desc[0].length * _packet);
|
1374
|
+
}
|
1375
|
+
|
1376
|
+
/* sync I/O */
|
1377
|
+
|
1378
|
+
int LIBUSB_CALL libusb_control_transfer(libusb_device_handle *dev_handle,
|
1379
|
+
uint8_t request_type, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
|
1380
|
+
unsigned char *data, uint16_t wLength, unsigned int timeout);
|
1381
|
+
|
1382
|
+
int LIBUSB_CALL libusb_bulk_transfer(libusb_device_handle *dev_handle,
|
1383
|
+
unsigned char endpoint, unsigned char *data, int length,
|
1384
|
+
int *actual_length, unsigned int timeout);
|
1385
|
+
|
1386
|
+
int LIBUSB_CALL libusb_interrupt_transfer(libusb_device_handle *dev_handle,
|
1387
|
+
unsigned char endpoint, unsigned char *data, int length,
|
1388
|
+
int *actual_length, unsigned int timeout);
|
1389
|
+
|
1390
|
+
/** \ingroup desc
|
1391
|
+
* Retrieve a descriptor from the default control pipe.
|
1392
|
+
* This is a convenience function which formulates the appropriate control
|
1393
|
+
* message to retrieve the descriptor.
|
1394
|
+
*
|
1395
|
+
* \param dev a device handle
|
1396
|
+
* \param desc_type the descriptor type, see \ref libusb_descriptor_type
|
1397
|
+
* \param desc_index the index of the descriptor to retrieve
|
1398
|
+
* \param data output buffer for descriptor
|
1399
|
+
* \param length size of data buffer
|
1400
|
+
* \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
|
1401
|
+
*/
|
1402
|
+
static inline int libusb_get_descriptor(libusb_device_handle *dev,
|
1403
|
+
uint8_t desc_type, uint8_t desc_index, unsigned char *data, int length)
|
1404
|
+
{
|
1405
|
+
return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
|
1406
|
+
LIBUSB_REQUEST_GET_DESCRIPTOR, (desc_type << 8) | desc_index, 0, data,
|
1407
|
+
(uint16_t) length, 1000);
|
1408
|
+
}
|
1409
|
+
|
1410
|
+
/** \ingroup desc
|
1411
|
+
* Retrieve a descriptor from a device.
|
1412
|
+
* This is a convenience function which formulates the appropriate control
|
1413
|
+
* message to retrieve the descriptor. The string returned is Unicode, as
|
1414
|
+
* detailed in the USB specifications.
|
1415
|
+
*
|
1416
|
+
* \param dev a device handle
|
1417
|
+
* \param desc_index the index of the descriptor to retrieve
|
1418
|
+
* \param langid the language ID for the string descriptor
|
1419
|
+
* \param data output buffer for descriptor
|
1420
|
+
* \param length size of data buffer
|
1421
|
+
* \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
|
1422
|
+
* \see libusb_get_string_descriptor_ascii()
|
1423
|
+
*/
|
1424
|
+
static inline int libusb_get_string_descriptor(libusb_device_handle *dev,
|
1425
|
+
uint8_t desc_index, uint16_t langid, unsigned char *data, int length)
|
1426
|
+
{
|
1427
|
+
return libusb_control_transfer(dev, LIBUSB_ENDPOINT_IN,
|
1428
|
+
LIBUSB_REQUEST_GET_DESCRIPTOR, (uint16_t)((LIBUSB_DT_STRING << 8) | desc_index),
|
1429
|
+
langid, data, (uint16_t) length, 1000);
|
1430
|
+
}
|
1431
|
+
|
1432
|
+
int LIBUSB_CALL libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
|
1433
|
+
uint8_t desc_index, unsigned char *data, int length);
|
1434
|
+
|
1435
|
+
/* polling and timeouts */
|
1436
|
+
|
1437
|
+
int LIBUSB_CALL libusb_try_lock_events(libusb_context *ctx);
|
1438
|
+
void LIBUSB_CALL libusb_lock_events(libusb_context *ctx);
|
1439
|
+
void LIBUSB_CALL libusb_unlock_events(libusb_context *ctx);
|
1440
|
+
int LIBUSB_CALL libusb_event_handling_ok(libusb_context *ctx);
|
1441
|
+
int LIBUSB_CALL libusb_event_handler_active(libusb_context *ctx);
|
1442
|
+
void LIBUSB_CALL libusb_lock_event_waiters(libusb_context *ctx);
|
1443
|
+
void LIBUSB_CALL libusb_unlock_event_waiters(libusb_context *ctx);
|
1444
|
+
int LIBUSB_CALL libusb_wait_for_event(libusb_context *ctx, struct timeval *tv);
|
1445
|
+
|
1446
|
+
int LIBUSB_CALL libusb_handle_events_timeout(libusb_context *ctx,
|
1447
|
+
struct timeval *tv);
|
1448
|
+
int LIBUSB_CALL libusb_handle_events_timeout_completed(libusb_context *ctx,
|
1449
|
+
struct timeval *tv, int *completed);
|
1450
|
+
int LIBUSB_CALL libusb_handle_events(libusb_context *ctx);
|
1451
|
+
int LIBUSB_CALL libusb_handle_events_completed(libusb_context *ctx, int *completed);
|
1452
|
+
int LIBUSB_CALL libusb_handle_events_locked(libusb_context *ctx,
|
1453
|
+
struct timeval *tv);
|
1454
|
+
int LIBUSB_CALL libusb_pollfds_handle_timeouts(libusb_context *ctx);
|
1455
|
+
int LIBUSB_CALL libusb_get_next_timeout(libusb_context *ctx,
|
1456
|
+
struct timeval *tv);
|
1457
|
+
|
1458
|
+
/** \ingroup poll
|
1459
|
+
* File descriptor for polling
|
1460
|
+
*/
|
1461
|
+
struct libusb_pollfd {
|
1462
|
+
/** Numeric file descriptor */
|
1463
|
+
int fd;
|
1464
|
+
|
1465
|
+
/** Event flags to poll for from <poll.h>. POLLIN indicates that you
|
1466
|
+
* should monitor this file descriptor for becoming ready to read from,
|
1467
|
+
* and POLLOUT indicates that you should monitor this file descriptor for
|
1468
|
+
* nonblocking write readiness. */
|
1469
|
+
short events;
|
1470
|
+
};
|
1471
|
+
|
1472
|
+
/** \ingroup poll
|
1473
|
+
* Callback function, invoked when a new file descriptor should be added
|
1474
|
+
* to the set of file descriptors monitored for events.
|
1475
|
+
* \param fd the new file descriptor
|
1476
|
+
* \param events events to monitor for, see \ref libusb_pollfd for a
|
1477
|
+
* description
|
1478
|
+
* \param user_data User data pointer specified in
|
1479
|
+
* libusb_set_pollfd_notifiers() call
|
1480
|
+
* \see libusb_set_pollfd_notifiers()
|
1481
|
+
*/
|
1482
|
+
typedef void (LIBUSB_CALL *libusb_pollfd_added_cb)(int fd, short events,
|
1483
|
+
void *user_data);
|
1484
|
+
|
1485
|
+
/** \ingroup poll
|
1486
|
+
* Callback function, invoked when a file descriptor should be removed from
|
1487
|
+
* the set of file descriptors being monitored for events. After returning
|
1488
|
+
* from this callback, do not use that file descriptor again.
|
1489
|
+
* \param fd the file descriptor to stop monitoring
|
1490
|
+
* \param user_data User data pointer specified in
|
1491
|
+
* libusb_set_pollfd_notifiers() call
|
1492
|
+
* \see libusb_set_pollfd_notifiers()
|
1493
|
+
*/
|
1494
|
+
typedef void (LIBUSB_CALL *libusb_pollfd_removed_cb)(int fd, void *user_data);
|
1495
|
+
|
1496
|
+
const struct libusb_pollfd ** LIBUSB_CALL libusb_get_pollfds(
|
1497
|
+
libusb_context *ctx);
|
1498
|
+
void LIBUSB_CALL libusb_set_pollfd_notifiers(libusb_context *ctx,
|
1499
|
+
libusb_pollfd_added_cb added_cb, libusb_pollfd_removed_cb removed_cb,
|
1500
|
+
void *user_data);
|
1501
|
+
|
1502
|
+
#ifdef __cplusplus
|
1503
|
+
}
|
1504
|
+
#endif
|
1505
|
+
|
1506
|
+
#endif
|