libusb 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -2
  3. data/Gemfile +2 -0
  4. data/History.md +12 -0
  5. data/README.md +25 -14
  6. data/Rakefile +64 -109
  7. data/appveyor.yml +23 -0
  8. data/ext/extconf.rb +10 -12
  9. data/ext/libusb_recipe.rb +29 -0
  10. data/lib/libusb/call.rb +14 -11
  11. data/lib/libusb/compat.rb +9 -9
  12. data/lib/libusb/context.rb +16 -1
  13. data/lib/libusb/dependencies.rb +7 -0
  14. data/lib/libusb/dev_handle.rb +13 -3
  15. data/lib/libusb/eventmachine.rb +4 -4
  16. data/lib/libusb/transfer.rb +71 -10
  17. data/lib/libusb/version_gem.rb +1 -1
  18. data/libusb.gemspec +7 -5
  19. data/ports/archives/libusb-1.0.21.tar.bz2 +0 -0
  20. data/test/test_libusb_bulk_stream_transfer.rb +1 -1
  21. data/test/test_libusb_descriptors.rb +4 -4
  22. data/test/test_libusb_event_machine.rb +7 -7
  23. data/test/test_libusb_hotplug.rb +15 -3
  24. data/test/test_libusb_iso_transfer.rb +1 -1
  25. data/test/test_libusb_mass_storage.rb +19 -19
  26. data/test/test_libusb_mass_storage2.rb +1 -1
  27. data/test/test_libusb_structs.rb +13 -0
  28. data/test/test_libusb_threads.rb +2 -2
  29. data/wireshark-usb-sniffer.png +0 -0
  30. metadata +32 -156
  31. checksums.yaml.gz.sig +0 -0
  32. data.tar.gz.sig +0 -0
  33. data/ext/libusb-1.0.20/AUTHORS +0 -89
  34. data/ext/libusb-1.0.20/COPYING +0 -504
  35. data/ext/libusb-1.0.20/ChangeLog +0 -227
  36. data/ext/libusb-1.0.20/INSTALL +0 -234
  37. data/ext/libusb-1.0.20/Makefile.am +0 -28
  38. data/ext/libusb-1.0.20/Makefile.in +0 -897
  39. data/ext/libusb-1.0.20/NEWS +0 -2
  40. data/ext/libusb-1.0.20/PORTING +0 -94
  41. data/ext/libusb-1.0.20/README +0 -29
  42. data/ext/libusb-1.0.20/TODO +0 -2
  43. data/ext/libusb-1.0.20/Xcode/common.xcconfig +0 -49
  44. data/ext/libusb-1.0.20/Xcode/config.h +0 -28
  45. data/ext/libusb-1.0.20/Xcode/debug.xcconfig +0 -29
  46. data/ext/libusb-1.0.20/Xcode/libusb.xcconfig +0 -21
  47. data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +0 -865
  48. data/ext/libusb-1.0.20/Xcode/libusb_debug.xcconfig +0 -21
  49. data/ext/libusb-1.0.20/Xcode/libusb_release.xcconfig +0 -21
  50. data/ext/libusb-1.0.20/Xcode/release.xcconfig +0 -30
  51. data/ext/libusb-1.0.20/aclocal.m4 +0 -1193
  52. data/ext/libusb-1.0.20/android/README +0 -114
  53. data/ext/libusb-1.0.20/android/config.h +0 -81
  54. data/ext/libusb-1.0.20/android/jni/Android.mk +0 -23
  55. data/ext/libusb-1.0.20/android/jni/Application.mk +0 -24
  56. data/ext/libusb-1.0.20/android/jni/examples.mk +0 -134
  57. data/ext/libusb-1.0.20/android/jni/libusb.mk +0 -54
  58. data/ext/libusb-1.0.20/android/jni/tests.mk +0 -56
  59. data/ext/libusb-1.0.20/compile +0 -347
  60. data/ext/libusb-1.0.20/config.guess +0 -1421
  61. data/ext/libusb-1.0.20/config.h.in +0 -155
  62. data/ext/libusb-1.0.20/config.sub +0 -1807
  63. data/ext/libusb-1.0.20/configure +0 -15466
  64. data/ext/libusb-1.0.20/configure.ac +0 -326
  65. data/ext/libusb-1.0.20/depcomp +0 -791
  66. data/ext/libusb-1.0.20/doc/Makefile.am +0 -9
  67. data/ext/libusb-1.0.20/doc/Makefile.in +0 -456
  68. data/ext/libusb-1.0.20/doc/doxygen.cfg.in +0 -2334
  69. data/ext/libusb-1.0.20/examples/Makefile.am +0 -19
  70. data/ext/libusb-1.0.20/examples/Makefile.in +0 -713
  71. data/ext/libusb-1.0.20/examples/dpfp.c +0 -506
  72. data/ext/libusb-1.0.20/examples/dpfp_threaded.c +0 -549
  73. data/ext/libusb-1.0.20/examples/ezusb.c +0 -831
  74. data/ext/libusb-1.0.20/examples/ezusb.h +0 -120
  75. data/ext/libusb-1.0.20/examples/fxload.c +0 -308
  76. data/ext/libusb-1.0.20/examples/getopt/getopt.c +0 -1060
  77. data/ext/libusb-1.0.20/examples/getopt/getopt.h +0 -180
  78. data/ext/libusb-1.0.20/examples/getopt/getopt1.c +0 -188
  79. data/ext/libusb-1.0.20/examples/hotplugtest.c +0 -122
  80. data/ext/libusb-1.0.20/examples/listdevs.c +0 -71
  81. data/ext/libusb-1.0.20/examples/sam3u_benchmark.c +0 -193
  82. data/ext/libusb-1.0.20/examples/xusb.c +0 -1130
  83. data/ext/libusb-1.0.20/install-sh +0 -501
  84. data/ext/libusb-1.0.20/libusb-1.0.pc.in +0 -11
  85. data/ext/libusb-1.0.20/libusb/Makefile.am +0 -90
  86. data/ext/libusb-1.0.20/libusb/Makefile.in +0 -1053
  87. data/ext/libusb-1.0.20/libusb/core.c +0 -2452
  88. data/ext/libusb-1.0.20/libusb/descriptor.c +0 -1201
  89. data/ext/libusb-1.0.20/libusb/hotplug.c +0 -344
  90. data/ext/libusb-1.0.20/libusb/hotplug.h +0 -90
  91. data/ext/libusb-1.0.20/libusb/io.c +0 -2760
  92. data/ext/libusb-1.0.20/libusb/libusb-1.0.def +0 -168
  93. data/ext/libusb-1.0.20/libusb/libusb-1.0.rc +0 -61
  94. data/ext/libusb-1.0.20/libusb/libusb.h +0 -1999
  95. data/ext/libusb-1.0.20/libusb/libusbi.h +0 -1102
  96. data/ext/libusb-1.0.20/libusb/os/darwin_usb.c +0 -1969
  97. data/ext/libusb-1.0.20/libusb/os/darwin_usb.h +0 -158
  98. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +0 -5
  99. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +0 -810
  100. data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +0 -1193
  101. data/ext/libusb-1.0.20/libusb/os/haiku/compile +0 -347
  102. data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +0 -1421
  103. data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +0 -1807
  104. data/ext/libusb-1.0.20/libusb/os/haiku/configure +0 -17579
  105. data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +0 -8
  106. data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +0 -791
  107. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +0 -378
  108. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +0 -112
  109. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +0 -550
  110. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +0 -255
  111. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +0 -180
  112. data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +0 -501
  113. data/ext/libusb-1.0.20/libusb/os/haiku/ltmain.sh +0 -9655
  114. data/ext/libusb-1.0.20/libusb/os/haiku/m4/libtool.m4 +0 -7992
  115. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltoptions.m4 +0 -384
  116. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltsugar.m4 +0 -123
  117. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltversion.m4 +0 -23
  118. data/ext/libusb-1.0.20/libusb/os/haiku/m4/lt~obsolete.m4 +0 -98
  119. data/ext/libusb-1.0.20/libusb/os/haiku/missing +0 -215
  120. data/ext/libusb-1.0.20/libusb/os/linux_netlink.c +0 -369
  121. data/ext/libusb-1.0.20/libusb/os/linux_udev.c +0 -306
  122. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.c +0 -2692
  123. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.h +0 -192
  124. data/ext/libusb-1.0.20/libusb/os/netbsd_usb.c +0 -674
  125. data/ext/libusb-1.0.20/libusb/os/openbsd_usb.c +0 -768
  126. data/ext/libusb-1.0.20/libusb/os/poll_posix.c +0 -53
  127. data/ext/libusb-1.0.20/libusb/os/poll_posix.h +0 -11
  128. data/ext/libusb-1.0.20/libusb/os/poll_windows.c +0 -728
  129. data/ext/libusb-1.0.20/libusb/os/poll_windows.h +0 -131
  130. data/ext/libusb-1.0.20/libusb/os/threads_posix.c +0 -82
  131. data/ext/libusb-1.0.20/libusb/os/threads_posix.h +0 -50
  132. data/ext/libusb-1.0.20/libusb/os/threads_windows.c +0 -214
  133. data/ext/libusb-1.0.20/libusb/os/threads_windows.h +0 -87
  134. data/ext/libusb-1.0.20/libusb/os/wince_usb.c +0 -869
  135. data/ext/libusb-1.0.20/libusb/os/wince_usb.h +0 -131
  136. data/ext/libusb-1.0.20/libusb/os/windows_common.h +0 -108
  137. data/ext/libusb-1.0.20/libusb/os/windows_usb.c +0 -4643
  138. data/ext/libusb-1.0.20/libusb/os/windows_usb.h +0 -973
  139. data/ext/libusb-1.0.20/libusb/strerror.c +0 -202
  140. data/ext/libusb-1.0.20/libusb/sync.c +0 -308
  141. data/ext/libusb-1.0.20/libusb/version.h +0 -18
  142. data/ext/libusb-1.0.20/libusb/version_nano.h +0 -1
  143. data/ext/libusb-1.0.20/ltmain.sh +0 -9655
  144. data/ext/libusb-1.0.20/m4/libtool.m4 +0 -7992
  145. data/ext/libusb-1.0.20/m4/ltoptions.m4 +0 -384
  146. data/ext/libusb-1.0.20/m4/ltsugar.m4 +0 -123
  147. data/ext/libusb-1.0.20/m4/ltversion.m4 +0 -23
  148. data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +0 -98
  149. data/ext/libusb-1.0.20/missing +0 -215
  150. data/ext/libusb-1.0.20/tests/Makefile.am +0 -6
  151. data/ext/libusb-1.0.20/tests/Makefile.in +0 -596
  152. data/ext/libusb-1.0.20/tests/libusb_testlib.h +0 -107
  153. data/ext/libusb-1.0.20/tests/stress.c +0 -160
  154. data/ext/libusb-1.0.20/tests/testlib.c +0 -277
  155. metadata.gz.sig +0 -0
@@ -1,1102 +0,0 @@
1
- /*
2
- * Internal header for libusb
3
- * Copyright © 2007-2009 Daniel Drake <dsd@gentoo.org>
4
- * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with this library; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
- #ifndef LIBUSBI_H
22
- #define LIBUSBI_H
23
-
24
- #include <config.h>
25
-
26
- #include <stdlib.h>
27
-
28
- #include <stddef.h>
29
- #include <stdint.h>
30
- #include <time.h>
31
- #include <stdarg.h>
32
- #ifdef HAVE_POLL_H
33
- #include <poll.h>
34
- #endif
35
- #ifdef HAVE_MISSING_H
36
- #include <missing.h>
37
- #endif
38
-
39
- #include "libusb.h"
40
- #include "version.h"
41
-
42
- /* Inside the libusb code, mark all public functions as follows:
43
- * return_type API_EXPORTED function_name(params) { ... }
44
- * But if the function returns a pointer, mark it as follows:
45
- * DEFAULT_VISIBILITY return_type * LIBUSB_CALL function_name(params) { ... }
46
- * In the libusb public header, mark all declarations as:
47
- * return_type LIBUSB_CALL function_name(params);
48
- */
49
- #define API_EXPORTED LIBUSB_CALL DEFAULT_VISIBILITY
50
-
51
- #ifdef __cplusplus
52
- extern "C" {
53
- #endif
54
-
55
- #define DEVICE_DESC_LENGTH 18
56
-
57
- #define USB_MAXENDPOINTS 32
58
- #define USB_MAXINTERFACES 32
59
- #define USB_MAXCONFIG 8
60
-
61
- /* Backend specific capabilities */
62
- #define USBI_CAP_HAS_HID_ACCESS 0x00010000
63
- #define USBI_CAP_SUPPORTS_DETACH_KERNEL_DRIVER 0x00020000
64
-
65
- /* Maximum number of bytes in a log line */
66
- #define USBI_MAX_LOG_LEN 1024
67
- /* Terminator for log lines */
68
- #define USBI_LOG_LINE_END "\n"
69
-
70
- /* The following is used to silence warnings for unused variables */
71
- #define UNUSED(var) do { (void)(var); } while(0)
72
-
73
- #if !defined(ARRAYSIZE)
74
- #define ARRAYSIZE(array) (sizeof(array)/sizeof(array[0]))
75
- #endif
76
-
77
- struct list_head {
78
- struct list_head *prev, *next;
79
- };
80
-
81
- /* Get an entry from the list
82
- * ptr - the address of this list_head element in "type"
83
- * type - the data type that contains "member"
84
- * member - the list_head element in "type"
85
- */
86
- #define list_entry(ptr, type, member) \
87
- ((type *)((uintptr_t)(ptr) - (uintptr_t)offsetof(type, member)))
88
-
89
- #define list_first_entry(ptr, type, member) \
90
- list_entry((ptr)->next, type, member)
91
-
92
- /* Get each entry from a list
93
- * pos - A structure pointer has a "member" element
94
- * head - list head
95
- * member - the list_head element in "pos"
96
- * type - the type of the first parameter
97
- */
98
- #define list_for_each_entry(pos, head, member, type) \
99
- for (pos = list_entry((head)->next, type, member); \
100
- &pos->member != (head); \
101
- pos = list_entry(pos->member.next, type, member))
102
-
103
- #define list_for_each_entry_safe(pos, n, head, member, type) \
104
- for (pos = list_entry((head)->next, type, member), \
105
- n = list_entry(pos->member.next, type, member); \
106
- &pos->member != (head); \
107
- pos = n, n = list_entry(n->member.next, type, member))
108
-
109
- #define list_empty(entry) ((entry)->next == (entry))
110
-
111
- static inline void list_init(struct list_head *entry)
112
- {
113
- entry->prev = entry->next = entry;
114
- }
115
-
116
- static inline void list_add(struct list_head *entry, struct list_head *head)
117
- {
118
- entry->next = head->next;
119
- entry->prev = head;
120
-
121
- head->next->prev = entry;
122
- head->next = entry;
123
- }
124
-
125
- static inline void list_add_tail(struct list_head *entry,
126
- struct list_head *head)
127
- {
128
- entry->next = head;
129
- entry->prev = head->prev;
130
-
131
- head->prev->next = entry;
132
- head->prev = entry;
133
- }
134
-
135
- static inline void list_del(struct list_head *entry)
136
- {
137
- entry->next->prev = entry->prev;
138
- entry->prev->next = entry->next;
139
- entry->next = entry->prev = NULL;
140
- }
141
-
142
- static inline void *usbi_reallocf(void *ptr, size_t size)
143
- {
144
- void *ret = realloc(ptr, size);
145
- if (!ret)
146
- free(ptr);
147
- return ret;
148
- }
149
-
150
- #define container_of(ptr, type, member) ({ \
151
- const typeof( ((type *)0)->member ) *mptr = (ptr); \
152
- (type *)( (char *)mptr - offsetof(type,member) );})
153
-
154
- #ifndef MIN
155
- #define MIN(a, b) ((a) < (b) ? (a) : (b))
156
- #endif
157
- #ifndef MAX
158
- #define MAX(a, b) ((a) > (b) ? (a) : (b))
159
- #endif
160
-
161
- #define TIMESPEC_IS_SET(ts) ((ts)->tv_sec != 0 || (ts)->tv_nsec != 0)
162
-
163
- /* Some platforms don't have this define */
164
- #ifndef TIMESPEC_TO_TIMEVAL
165
- #define TIMESPEC_TO_TIMEVAL(tv, ts) \
166
- do { \
167
- (tv)->tv_sec = (ts)->tv_sec; \
168
- (tv)->tv_usec = (ts)->tv_nsec / 1000; \
169
- } while (0)
170
- #endif
171
-
172
- void usbi_log(struct libusb_context *ctx, enum libusb_log_level level,
173
- const char *function, const char *format, ...);
174
-
175
- void usbi_log_v(struct libusb_context *ctx, enum libusb_log_level level,
176
- const char *function, const char *format, va_list args);
177
-
178
- #if !defined(_MSC_VER) || _MSC_VER >= 1400
179
-
180
- #ifdef ENABLE_LOGGING
181
- #define _usbi_log(ctx, level, ...) usbi_log(ctx, level, __FUNCTION__, __VA_ARGS__)
182
- #define usbi_dbg(...) _usbi_log(NULL, LIBUSB_LOG_LEVEL_DEBUG, __VA_ARGS__)
183
- #else
184
- #define _usbi_log(ctx, level, ...) do { (void)(ctx); } while(0)
185
- #define usbi_dbg(...) do {} while(0)
186
- #endif
187
-
188
- #define usbi_info(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_INFO, __VA_ARGS__)
189
- #define usbi_warn(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_WARNING, __VA_ARGS__)
190
- #define usbi_err(ctx, ...) _usbi_log(ctx, LIBUSB_LOG_LEVEL_ERROR, __VA_ARGS__)
191
-
192
- #else /* !defined(_MSC_VER) || _MSC_VER >= 1400 */
193
-
194
- #ifdef ENABLE_LOGGING
195
- #define LOG_BODY(ctxt, level) \
196
- { \
197
- va_list args; \
198
- va_start (args, format); \
199
- usbi_log_v(ctxt, level, "", format, args); \
200
- va_end(args); \
201
- }
202
- #else
203
- #define LOG_BODY(ctxt, level) do { (void)(ctxt); } while(0)
204
- #endif
205
-
206
- static inline void usbi_info(struct libusb_context *ctx, const char *format,
207
- ...)
208
- LOG_BODY(ctx,LIBUSB_LOG_LEVEL_INFO)
209
- static inline void usbi_warn(struct libusb_context *ctx, const char *format,
210
- ...)
211
- LOG_BODY(ctx,LIBUSB_LOG_LEVEL_WARNING)
212
- static inline void usbi_err( struct libusb_context *ctx, const char *format,
213
- ...)
214
- LOG_BODY(ctx,LIBUSB_LOG_LEVEL_ERROR)
215
-
216
- static inline void usbi_dbg(const char *format, ...)
217
- LOG_BODY(NULL,LIBUSB_LOG_LEVEL_DEBUG)
218
-
219
- #endif /* !defined(_MSC_VER) || _MSC_VER >= 1400 */
220
-
221
- #define USBI_GET_CONTEXT(ctx) if (!(ctx)) (ctx) = usbi_default_context
222
- #define DEVICE_CTX(dev) ((dev)->ctx)
223
- #define HANDLE_CTX(handle) (DEVICE_CTX((handle)->dev))
224
- #define TRANSFER_CTX(transfer) (HANDLE_CTX((transfer)->dev_handle))
225
- #define ITRANSFER_CTX(transfer) \
226
- (TRANSFER_CTX(USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer)))
227
-
228
- #define IS_EPIN(ep) (0 != ((ep) & LIBUSB_ENDPOINT_IN))
229
- #define IS_EPOUT(ep) (!IS_EPIN(ep))
230
- #define IS_XFERIN(xfer) (0 != ((xfer)->endpoint & LIBUSB_ENDPOINT_IN))
231
- #define IS_XFEROUT(xfer) (!IS_XFERIN(xfer))
232
-
233
- /* Internal abstraction for thread synchronization */
234
- #if defined(THREADS_POSIX)
235
- #include "os/threads_posix.h"
236
- #elif defined(OS_WINDOWS) || defined(OS_WINCE)
237
- #include <os/threads_windows.h>
238
- #endif
239
-
240
- extern struct libusb_context *usbi_default_context;
241
-
242
- /* Forward declaration for use in context (fully defined inside poll abstraction) */
243
- struct pollfd;
244
-
245
- struct libusb_context {
246
- int debug;
247
- int debug_fixed;
248
-
249
- /* internal event pipe, used for signalling occurrence of an internal event. */
250
- int event_pipe[2];
251
-
252
- struct list_head usb_devs;
253
- usbi_mutex_t usb_devs_lock;
254
-
255
- /* A list of open handles. Backends are free to traverse this if required.
256
- */
257
- struct list_head open_devs;
258
- usbi_mutex_t open_devs_lock;
259
-
260
- /* A list of registered hotplug callbacks */
261
- struct list_head hotplug_cbs;
262
- usbi_mutex_t hotplug_cbs_lock;
263
-
264
- /* this is a list of in-flight transfer handles, sorted by timeout
265
- * expiration. URBs to timeout the soonest are placed at the beginning of
266
- * the list, URBs that will time out later are placed after, and urbs with
267
- * infinite timeout are always placed at the very end. */
268
- struct list_head flying_transfers;
269
- usbi_mutex_t flying_transfers_lock;
270
-
271
- /* user callbacks for pollfd changes */
272
- libusb_pollfd_added_cb fd_added_cb;
273
- libusb_pollfd_removed_cb fd_removed_cb;
274
- void *fd_cb_user_data;
275
-
276
- /* ensures that only one thread is handling events at any one time */
277
- usbi_mutex_t events_lock;
278
-
279
- /* used to see if there is an active thread doing event handling */
280
- int event_handler_active;
281
-
282
- /* used to wait for event completion in threads other than the one that is
283
- * event handling */
284
- usbi_mutex_t event_waiters_lock;
285
- usbi_cond_t event_waiters_cond;
286
-
287
- /* A lock to protect internal context event data. */
288
- usbi_mutex_t event_data_lock;
289
-
290
- /* A counter that is set when we want to interrupt and prevent event handling,
291
- * in order to safely close a device. Protected by event_data_lock. */
292
- unsigned int device_close;
293
-
294
- /* list and count of poll fds and an array of poll fd structures that is
295
- * (re)allocated as necessary prior to polling, and a flag to indicate
296
- * when the list of poll fds has changed since the last poll.
297
- * Protected by event_data_lock. */
298
- struct list_head ipollfds;
299
- struct pollfd *pollfds;
300
- POLL_NFDS_TYPE pollfds_cnt;
301
- unsigned int pollfds_modified;
302
-
303
- /* A list of pending hotplug messages. Protected by event_data_lock. */
304
- struct list_head hotplug_msgs;
305
-
306
- /* A list of pending completed transfers. Protected by event_data_lock. */
307
- struct list_head completed_transfers;
308
-
309
- #ifdef USBI_TIMERFD_AVAILABLE
310
- /* used for timeout handling, if supported by OS.
311
- * this timerfd is maintained to trigger on the next pending timeout */
312
- int timerfd;
313
- #endif
314
-
315
- struct list_head list;
316
- };
317
-
318
- /* Update the following macro if new event sources are added */
319
- #define usbi_pending_events(ctx) \
320
- ((ctx)->device_close || (ctx)->pollfds_modified \
321
- || !list_empty(&(ctx)->hotplug_msgs) || !list_empty(&(ctx)->completed_transfers))
322
-
323
- #ifdef USBI_TIMERFD_AVAILABLE
324
- #define usbi_using_timerfd(ctx) ((ctx)->timerfd >= 0)
325
- #else
326
- #define usbi_using_timerfd(ctx) (0)
327
- #endif
328
-
329
- struct libusb_device {
330
- /* lock protects refcnt, everything else is finalized at initialization
331
- * time */
332
- usbi_mutex_t lock;
333
- int refcnt;
334
-
335
- struct libusb_context *ctx;
336
-
337
- uint8_t bus_number;
338
- uint8_t port_number;
339
- struct libusb_device* parent_dev;
340
- uint8_t device_address;
341
- uint8_t num_configurations;
342
- enum libusb_speed speed;
343
-
344
- struct list_head list;
345
- unsigned long session_data;
346
-
347
- struct libusb_device_descriptor device_descriptor;
348
- int attached;
349
-
350
- unsigned char os_priv
351
- #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
352
- [] /* valid C99 code */
353
- #else
354
- [0] /* non-standard, but usually working code */
355
- #endif
356
- ;
357
- };
358
-
359
- struct libusb_device_handle {
360
- /* lock protects claimed_interfaces */
361
- usbi_mutex_t lock;
362
- unsigned long claimed_interfaces;
363
-
364
- struct list_head list;
365
- struct libusb_device *dev;
366
- int auto_detach_kernel_driver;
367
- unsigned char os_priv
368
- #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
369
- [] /* valid C99 code */
370
- #else
371
- [0] /* non-standard, but usually working code */
372
- #endif
373
- ;
374
- };
375
-
376
- enum {
377
- USBI_CLOCK_MONOTONIC,
378
- USBI_CLOCK_REALTIME
379
- };
380
-
381
- /* in-memory transfer layout:
382
- *
383
- * 1. struct usbi_transfer
384
- * 2. struct libusb_transfer (which includes iso packets) [variable size]
385
- * 3. os private data [variable size]
386
- *
387
- * from a libusb_transfer, you can get the usbi_transfer by rewinding the
388
- * appropriate number of bytes.
389
- * the usbi_transfer includes the number of allocated packets, so you can
390
- * determine the size of the transfer and hence the start and length of the
391
- * OS-private data.
392
- */
393
-
394
- struct usbi_transfer {
395
- int num_iso_packets;
396
- struct list_head list;
397
- struct list_head completed_list;
398
- struct timeval timeout;
399
- int transferred;
400
- uint32_t stream_id;
401
- uint8_t flags;
402
-
403
- /* this lock is held during libusb_submit_transfer() and
404
- * libusb_cancel_transfer() (allowing the OS backend to prevent duplicate
405
- * cancellation, submission-during-cancellation, etc). the OS backend
406
- * should also take this lock in the handle_events path, to prevent the user
407
- * cancelling the transfer from another thread while you are processing
408
- * its completion (presumably there would be races within your OS backend
409
- * if this were possible). */
410
- usbi_mutex_t lock;
411
-
412
- /* this lock should be held whenever viewing or modifying flags
413
- * relating to the transfer state */
414
- usbi_mutex_t flags_lock;
415
- };
416
-
417
- enum usbi_transfer_flags {
418
- /* The transfer has timed out */
419
- USBI_TRANSFER_TIMED_OUT = 1 << 0,
420
-
421
- /* Set by backend submit_transfer() if the OS handles timeout */
422
- USBI_TRANSFER_OS_HANDLES_TIMEOUT = 1 << 1,
423
-
424
- /* Cancellation was requested via libusb_cancel_transfer() */
425
- USBI_TRANSFER_CANCELLING = 1 << 2,
426
-
427
- /* Operation on the transfer failed because the device disappeared */
428
- USBI_TRANSFER_DEVICE_DISAPPEARED = 1 << 3,
429
-
430
- /* Transfer is currently being submitted */
431
- USBI_TRANSFER_SUBMITTING = 1 << 4,
432
-
433
- /* Transfer successfully submitted by backend */
434
- USBI_TRANSFER_IN_FLIGHT = 1 << 5,
435
-
436
- /* Completion handler has run */
437
- USBI_TRANSFER_COMPLETED = 1 << 6,
438
-
439
- /* The transfer timeout has been handled */
440
- USBI_TRANSFER_TIMEOUT_HANDLED = 1 << 7,
441
- };
442
-
443
- #define USBI_TRANSFER_TO_LIBUSB_TRANSFER(transfer) \
444
- ((struct libusb_transfer *)(((unsigned char *)(transfer)) \
445
- + sizeof(struct usbi_transfer)))
446
- #define LIBUSB_TRANSFER_TO_USBI_TRANSFER(transfer) \
447
- ((struct usbi_transfer *)(((unsigned char *)(transfer)) \
448
- - sizeof(struct usbi_transfer)))
449
-
450
- static inline void *usbi_transfer_get_os_priv(struct usbi_transfer *transfer)
451
- {
452
- return ((unsigned char *)transfer) + sizeof(struct usbi_transfer)
453
- + sizeof(struct libusb_transfer)
454
- + (transfer->num_iso_packets
455
- * sizeof(struct libusb_iso_packet_descriptor));
456
- }
457
-
458
- /* bus structures */
459
-
460
- /* All standard descriptors have these 2 fields in common */
461
- struct usb_descriptor_header {
462
- uint8_t bLength;
463
- uint8_t bDescriptorType;
464
- };
465
-
466
- /* shared data and functions */
467
-
468
- int usbi_io_init(struct libusb_context *ctx);
469
- void usbi_io_exit(struct libusb_context *ctx);
470
-
471
- struct libusb_device *usbi_alloc_device(struct libusb_context *ctx,
472
- unsigned long session_id);
473
- struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
474
- unsigned long session_id);
475
- int usbi_sanitize_device(struct libusb_device *dev);
476
- void usbi_handle_disconnect(struct libusb_device_handle *handle);
477
-
478
- int usbi_handle_transfer_completion(struct usbi_transfer *itransfer,
479
- enum libusb_transfer_status status);
480
- int usbi_handle_transfer_cancellation(struct usbi_transfer *transfer);
481
- void usbi_signal_transfer_completion(struct usbi_transfer *transfer);
482
-
483
- int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
484
- void *dest, int host_endian);
485
- int usbi_device_cache_descriptor(libusb_device *dev);
486
- int usbi_get_config_index_by_value(struct libusb_device *dev,
487
- uint8_t bConfigurationValue, int *idx);
488
-
489
- void usbi_connect_device (struct libusb_device *dev);
490
- void usbi_disconnect_device (struct libusb_device *dev);
491
-
492
- int usbi_signal_event(struct libusb_context *ctx);
493
- int usbi_clear_event(struct libusb_context *ctx);
494
-
495
- /* Internal abstraction for poll (needs struct usbi_transfer on Windows) */
496
- #if defined(OS_LINUX) || defined(OS_DARWIN) || defined(OS_OPENBSD) || defined(OS_NETBSD) || defined(OS_HAIKU)
497
- #include <unistd.h>
498
- #include "os/poll_posix.h"
499
- #elif defined(OS_WINDOWS) || defined(OS_WINCE)
500
- #include "os/poll_windows.h"
501
- #endif
502
-
503
- #if (defined(OS_WINDOWS) || defined(OS_WINCE)) && !defined(__GNUC__)
504
- #define snprintf _snprintf
505
- #define vsnprintf _vsnprintf
506
- int usbi_gettimeofday(struct timeval *tp, void *tzp);
507
- #define LIBUSB_GETTIMEOFDAY_WIN32
508
- #define HAVE_USBI_GETTIMEOFDAY
509
- #else
510
- #ifdef HAVE_GETTIMEOFDAY
511
- #define usbi_gettimeofday(tv, tz) gettimeofday((tv), (tz))
512
- #define HAVE_USBI_GETTIMEOFDAY
513
- #endif
514
- #endif
515
-
516
- struct usbi_pollfd {
517
- /* must come first */
518
- struct libusb_pollfd pollfd;
519
-
520
- struct list_head list;
521
- };
522
-
523
- int usbi_add_pollfd(struct libusb_context *ctx, int fd, short events);
524
- void usbi_remove_pollfd(struct libusb_context *ctx, int fd);
525
-
526
- /* device discovery */
527
-
528
- /* we traverse usbfs without knowing how many devices we are going to find.
529
- * so we create this discovered_devs model which is similar to a linked-list
530
- * which grows when required. it can be freed once discovery has completed,
531
- * eliminating the need for a list node in the libusb_device structure
532
- * itself. */
533
- struct discovered_devs {
534
- size_t len;
535
- size_t capacity;
536
- struct libusb_device *devices
537
- #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
538
- [] /* valid C99 code */
539
- #else
540
- [0] /* non-standard, but usually working code */
541
- #endif
542
- ;
543
- };
544
-
545
- struct discovered_devs *discovered_devs_append(
546
- struct discovered_devs *discdevs, struct libusb_device *dev);
547
-
548
- /* OS abstraction */
549
-
550
- /* This is the interface that OS backends need to implement.
551
- * All fields are mandatory, except ones explicitly noted as optional. */
552
- struct usbi_os_backend {
553
- /* A human-readable name for your backend, e.g. "Linux usbfs" */
554
- const char *name;
555
-
556
- /* Binary mask for backend specific capabilities */
557
- uint32_t caps;
558
-
559
- /* Perform initialization of your backend. You might use this function
560
- * to determine specific capabilities of the system, allocate required
561
- * data structures for later, etc.
562
- *
563
- * This function is called when a libusb user initializes the library
564
- * prior to use.
565
- *
566
- * Return 0 on success, or a LIBUSB_ERROR code on failure.
567
- */
568
- int (*init)(struct libusb_context *ctx);
569
-
570
- /* Deinitialization. Optional. This function should destroy anything
571
- * that was set up by init.
572
- *
573
- * This function is called when the user deinitializes the library.
574
- */
575
- void (*exit)(void);
576
-
577
- /* Enumerate all the USB devices on the system, returning them in a list
578
- * of discovered devices.
579
- *
580
- * Your implementation should enumerate all devices on the system,
581
- * regardless of whether they have been seen before or not.
582
- *
583
- * When you have found a device, compute a session ID for it. The session
584
- * ID should uniquely represent that particular device for that particular
585
- * connection session since boot (i.e. if you disconnect and reconnect a
586
- * device immediately after, it should be assigned a different session ID).
587
- * If your OS cannot provide a unique session ID as described above,
588
- * presenting a session ID of (bus_number << 8 | device_address) should
589
- * be sufficient. Bus numbers and device addresses wrap and get reused,
590
- * but that is an unlikely case.
591
- *
592
- * After computing a session ID for a device, call
593
- * usbi_get_device_by_session_id(). This function checks if libusb already
594
- * knows about the device, and if so, it provides you with a reference
595
- * to a libusb_device structure for it.
596
- *
597
- * If usbi_get_device_by_session_id() returns NULL, it is time to allocate
598
- * a new device structure for the device. Call usbi_alloc_device() to
599
- * obtain a new libusb_device structure with reference count 1. Populate
600
- * the bus_number and device_address attributes of the new device, and
601
- * perform any other internal backend initialization you need to do. At
602
- * this point, you should be ready to provide device descriptors and so
603
- * on through the get_*_descriptor functions. Finally, call
604
- * usbi_sanitize_device() to perform some final sanity checks on the
605
- * device. Assuming all of the above succeeded, we can now continue.
606
- * If any of the above failed, remember to unreference the device that
607
- * was returned by usbi_alloc_device().
608
- *
609
- * At this stage we have a populated libusb_device structure (either one
610
- * that was found earlier, or one that we have just allocated and
611
- * populated). This can now be added to the discovered devices list
612
- * using discovered_devs_append(). Note that discovered_devs_append()
613
- * may reallocate the list, returning a new location for it, and also
614
- * note that reallocation can fail. Your backend should handle these
615
- * error conditions appropriately.
616
- *
617
- * This function should not generate any bus I/O and should not block.
618
- * If I/O is required (e.g. reading the active configuration value), it is
619
- * OK to ignore these suggestions :)
620
- *
621
- * This function is executed when the user wishes to retrieve a list
622
- * of USB devices connected to the system.
623
- *
624
- * If the backend has hotplug support, this function is not used!
625
- *
626
- * Return 0 on success, or a LIBUSB_ERROR code on failure.
627
- */
628
- int (*get_device_list)(struct libusb_context *ctx,
629
- struct discovered_devs **discdevs);
630
-
631
- /* Apps which were written before hotplug support, may listen for
632
- * hotplug events on their own and call libusb_get_device_list on
633
- * device addition. In this case libusb_get_device_list will likely
634
- * return a list without the new device in there, as the hotplug
635
- * event thread will still be busy enumerating the device, which may
636
- * take a while, or may not even have seen the event yet.
637
- *
638
- * To avoid this libusb_get_device_list will call this optional
639
- * function for backends with hotplug support before copying
640
- * ctx->usb_devs to the user. In this function the backend should
641
- * ensure any pending hotplug events are fully processed before
642
- * returning.
643
- *
644
- * Optional, should be implemented by backends with hotplug support.
645
- */
646
- void (*hotplug_poll)(void);
647
-
648
- /* Open a device for I/O and other USB operations. The device handle
649
- * is preallocated for you, you can retrieve the device in question
650
- * through handle->dev.
651
- *
652
- * Your backend should allocate any internal resources required for I/O
653
- * and other operations so that those operations can happen (hopefully)
654
- * without hiccup. This is also a good place to inform libusb that it
655
- * should monitor certain file descriptors related to this device -
656
- * see the usbi_add_pollfd() function.
657
- *
658
- * This function should not generate any bus I/O and should not block.
659
- *
660
- * This function is called when the user attempts to obtain a device
661
- * handle for a device.
662
- *
663
- * Return:
664
- * - 0 on success
665
- * - LIBUSB_ERROR_ACCESS if the user has insufficient permissions
666
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since
667
- * discovery
668
- * - another LIBUSB_ERROR code on other failure
669
- *
670
- * Do not worry about freeing the handle on failed open, the upper layers
671
- * do this for you.
672
- */
673
- int (*open)(struct libusb_device_handle *handle);
674
-
675
- /* Close a device such that the handle cannot be used again. Your backend
676
- * should destroy any resources that were allocated in the open path.
677
- * This may also be a good place to call usbi_remove_pollfd() to inform
678
- * libusb of any file descriptors associated with this device that should
679
- * no longer be monitored.
680
- *
681
- * This function is called when the user closes a device handle.
682
- */
683
- void (*close)(struct libusb_device_handle *handle);
684
-
685
- /* Retrieve the device descriptor from a device.
686
- *
687
- * The descriptor should be retrieved from memory, NOT via bus I/O to the
688
- * device. This means that you may have to cache it in a private structure
689
- * during get_device_list enumeration. Alternatively, you may be able
690
- * to retrieve it from a kernel interface (some Linux setups can do this)
691
- * still without generating bus I/O.
692
- *
693
- * This function is expected to write DEVICE_DESC_LENGTH (18) bytes into
694
- * buffer, which is guaranteed to be big enough.
695
- *
696
- * This function is called when sanity-checking a device before adding
697
- * it to the list of discovered devices, and also when the user requests
698
- * to read the device descriptor.
699
- *
700
- * This function is expected to return the descriptor in bus-endian format
701
- * (LE). If it returns the multi-byte values in host-endian format,
702
- * set the host_endian output parameter to "1".
703
- *
704
- * Return 0 on success or a LIBUSB_ERROR code on failure.
705
- */
706
- int (*get_device_descriptor)(struct libusb_device *device,
707
- unsigned char *buffer, int *host_endian);
708
-
709
- /* Get the ACTIVE configuration descriptor for a device.
710
- *
711
- * The descriptor should be retrieved from memory, NOT via bus I/O to the
712
- * device. This means that you may have to cache it in a private structure
713
- * during get_device_list enumeration. You may also have to keep track
714
- * of which configuration is active when the user changes it.
715
- *
716
- * This function is expected to write len bytes of data into buffer, which
717
- * is guaranteed to be big enough. If you can only do a partial write,
718
- * return an error code.
719
- *
720
- * This function is expected to return the descriptor in bus-endian format
721
- * (LE). If it returns the multi-byte values in host-endian format,
722
- * set the host_endian output parameter to "1".
723
- *
724
- * Return:
725
- * - 0 on success
726
- * - LIBUSB_ERROR_NOT_FOUND if the device is in unconfigured state
727
- * - another LIBUSB_ERROR code on other failure
728
- */
729
- int (*get_active_config_descriptor)(struct libusb_device *device,
730
- unsigned char *buffer, size_t len, int *host_endian);
731
-
732
- /* Get a specific configuration descriptor for a device.
733
- *
734
- * The descriptor should be retrieved from memory, NOT via bus I/O to the
735
- * device. This means that you may have to cache it in a private structure
736
- * during get_device_list enumeration.
737
- *
738
- * The requested descriptor is expressed as a zero-based index (i.e. 0
739
- * indicates that we are requesting the first descriptor). The index does
740
- * not (necessarily) equal the bConfigurationValue of the configuration
741
- * being requested.
742
- *
743
- * This function is expected to write len bytes of data into buffer, which
744
- * is guaranteed to be big enough. If you can only do a partial write,
745
- * return an error code.
746
- *
747
- * This function is expected to return the descriptor in bus-endian format
748
- * (LE). If it returns the multi-byte values in host-endian format,
749
- * set the host_endian output parameter to "1".
750
- *
751
- * Return the length read on success or a LIBUSB_ERROR code on failure.
752
- */
753
- int (*get_config_descriptor)(struct libusb_device *device,
754
- uint8_t config_index, unsigned char *buffer, size_t len,
755
- int *host_endian);
756
-
757
- /* Like get_config_descriptor but then by bConfigurationValue instead
758
- * of by index.
759
- *
760
- * Optional, if not present the core will call get_config_descriptor
761
- * for all configs until it finds the desired bConfigurationValue.
762
- *
763
- * Returns a pointer to the raw-descriptor in *buffer, this memory
764
- * is valid as long as device is valid.
765
- *
766
- * Returns the length of the returned raw-descriptor on success,
767
- * or a LIBUSB_ERROR code on failure.
768
- */
769
- int (*get_config_descriptor_by_value)(struct libusb_device *device,
770
- uint8_t bConfigurationValue, unsigned char **buffer,
771
- int *host_endian);
772
-
773
- /* Get the bConfigurationValue for the active configuration for a device.
774
- * Optional. This should only be implemented if you can retrieve it from
775
- * cache (don't generate I/O).
776
- *
777
- * If you cannot retrieve this from cache, either do not implement this
778
- * function, or return LIBUSB_ERROR_NOT_SUPPORTED. This will cause
779
- * libusb to retrieve the information through a standard control transfer.
780
- *
781
- * This function must be non-blocking.
782
- * Return:
783
- * - 0 on success
784
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
785
- * was opened
786
- * - LIBUSB_ERROR_NOT_SUPPORTED if the value cannot be retrieved without
787
- * blocking
788
- * - another LIBUSB_ERROR code on other failure.
789
- */
790
- int (*get_configuration)(struct libusb_device_handle *handle, int *config);
791
-
792
- /* Set the active configuration for a device.
793
- *
794
- * A configuration value of -1 should put the device in unconfigured state.
795
- *
796
- * This function can block.
797
- *
798
- * Return:
799
- * - 0 on success
800
- * - LIBUSB_ERROR_NOT_FOUND if the configuration does not exist
801
- * - LIBUSB_ERROR_BUSY if interfaces are currently claimed (and hence
802
- * configuration cannot be changed)
803
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
804
- * was opened
805
- * - another LIBUSB_ERROR code on other failure.
806
- */
807
- int (*set_configuration)(struct libusb_device_handle *handle, int config);
808
-
809
- /* Claim an interface. When claimed, the application can then perform
810
- * I/O to an interface's endpoints.
811
- *
812
- * This function should not generate any bus I/O and should not block.
813
- * Interface claiming is a logical operation that simply ensures that
814
- * no other drivers/applications are using the interface, and after
815
- * claiming, no other drivers/applications can use the interface because
816
- * we now "own" it.
817
- *
818
- * Return:
819
- * - 0 on success
820
- * - LIBUSB_ERROR_NOT_FOUND if the interface does not exist
821
- * - LIBUSB_ERROR_BUSY if the interface is in use by another driver/app
822
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
823
- * was opened
824
- * - another LIBUSB_ERROR code on other failure
825
- */
826
- int (*claim_interface)(struct libusb_device_handle *handle, int interface_number);
827
-
828
- /* Release a previously claimed interface.
829
- *
830
- * This function should also generate a SET_INTERFACE control request,
831
- * resetting the alternate setting of that interface to 0. It's OK for
832
- * this function to block as a result.
833
- *
834
- * You will only ever be asked to release an interface which was
835
- * successfully claimed earlier.
836
- *
837
- * Return:
838
- * - 0 on success
839
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
840
- * was opened
841
- * - another LIBUSB_ERROR code on other failure
842
- */
843
- int (*release_interface)(struct libusb_device_handle *handle, int interface_number);
844
-
845
- /* Set the alternate setting for an interface.
846
- *
847
- * You will only ever be asked to set the alternate setting for an
848
- * interface which was successfully claimed earlier.
849
- *
850
- * It's OK for this function to block.
851
- *
852
- * Return:
853
- * - 0 on success
854
- * - LIBUSB_ERROR_NOT_FOUND if the alternate setting does not exist
855
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
856
- * was opened
857
- * - another LIBUSB_ERROR code on other failure
858
- */
859
- int (*set_interface_altsetting)(struct libusb_device_handle *handle,
860
- int interface_number, int altsetting);
861
-
862
- /* Clear a halt/stall condition on an endpoint.
863
- *
864
- * It's OK for this function to block.
865
- *
866
- * Return:
867
- * - 0 on success
868
- * - LIBUSB_ERROR_NOT_FOUND if the endpoint does not exist
869
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
870
- * was opened
871
- * - another LIBUSB_ERROR code on other failure
872
- */
873
- int (*clear_halt)(struct libusb_device_handle *handle,
874
- unsigned char endpoint);
875
-
876
- /* Perform a USB port reset to reinitialize a device.
877
- *
878
- * If possible, the handle should still be usable after the reset
879
- * completes, assuming that the device descriptors did not change during
880
- * reset and all previous interface state can be restored.
881
- *
882
- * If something changes, or you cannot easily locate/verify the resetted
883
- * device, return LIBUSB_ERROR_NOT_FOUND. This prompts the application
884
- * to close the old handle and re-enumerate the device.
885
- *
886
- * Return:
887
- * - 0 on success
888
- * - LIBUSB_ERROR_NOT_FOUND if re-enumeration is required, or if the device
889
- * has been disconnected since it was opened
890
- * - another LIBUSB_ERROR code on other failure
891
- */
892
- int (*reset_device)(struct libusb_device_handle *handle);
893
-
894
- /* Alloc num_streams usb3 bulk streams on the passed in endpoints */
895
- int (*alloc_streams)(struct libusb_device_handle *handle,
896
- uint32_t num_streams, unsigned char *endpoints, int num_endpoints);
897
-
898
- /* Free usb3 bulk streams allocated with alloc_streams */
899
- int (*free_streams)(struct libusb_device_handle *handle,
900
- unsigned char *endpoints, int num_endpoints);
901
-
902
- /* Determine if a kernel driver is active on an interface. Optional.
903
- *
904
- * The presence of a kernel driver on an interface indicates that any
905
- * calls to claim_interface would fail with the LIBUSB_ERROR_BUSY code.
906
- *
907
- * Return:
908
- * - 0 if no driver is active
909
- * - 1 if a driver is active
910
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
911
- * was opened
912
- * - another LIBUSB_ERROR code on other failure
913
- */
914
- int (*kernel_driver_active)(struct libusb_device_handle *handle,
915
- int interface_number);
916
-
917
- /* Detach a kernel driver from an interface. Optional.
918
- *
919
- * After detaching a kernel driver, the interface should be available
920
- * for claim.
921
- *
922
- * Return:
923
- * - 0 on success
924
- * - LIBUSB_ERROR_NOT_FOUND if no kernel driver was active
925
- * - LIBUSB_ERROR_INVALID_PARAM if the interface does not exist
926
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
927
- * was opened
928
- * - another LIBUSB_ERROR code on other failure
929
- */
930
- int (*detach_kernel_driver)(struct libusb_device_handle *handle,
931
- int interface_number);
932
-
933
- /* Attach a kernel driver to an interface. Optional.
934
- *
935
- * Reattach a kernel driver to the device.
936
- *
937
- * Return:
938
- * - 0 on success
939
- * - LIBUSB_ERROR_NOT_FOUND if no kernel driver was active
940
- * - LIBUSB_ERROR_INVALID_PARAM if the interface does not exist
941
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected since it
942
- * was opened
943
- * - LIBUSB_ERROR_BUSY if a program or driver has claimed the interface,
944
- * preventing reattachment
945
- * - another LIBUSB_ERROR code on other failure
946
- */
947
- int (*attach_kernel_driver)(struct libusb_device_handle *handle,
948
- int interface_number);
949
-
950
- /* Destroy a device. Optional.
951
- *
952
- * This function is called when the last reference to a device is
953
- * destroyed. It should free any resources allocated in the get_device_list
954
- * path.
955
- */
956
- void (*destroy_device)(struct libusb_device *dev);
957
-
958
- /* Submit a transfer. Your implementation should take the transfer,
959
- * morph it into whatever form your platform requires, and submit it
960
- * asynchronously.
961
- *
962
- * This function must not block.
963
- *
964
- * This function gets called with the flying_transfers_lock locked!
965
- *
966
- * Return:
967
- * - 0 on success
968
- * - LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
969
- * - another LIBUSB_ERROR code on other failure
970
- */
971
- int (*submit_transfer)(struct usbi_transfer *itransfer);
972
-
973
- /* Cancel a previously submitted transfer.
974
- *
975
- * This function must not block. The transfer cancellation must complete
976
- * later, resulting in a call to usbi_handle_transfer_cancellation()
977
- * from the context of handle_events.
978
- */
979
- int (*cancel_transfer)(struct usbi_transfer *itransfer);
980
-
981
- /* Clear a transfer as if it has completed or cancelled, but do not
982
- * report any completion/cancellation to the library. You should free
983
- * all private data from the transfer as if you were just about to report
984
- * completion or cancellation.
985
- *
986
- * This function might seem a bit out of place. It is used when libusb
987
- * detects a disconnected device - it calls this function for all pending
988
- * transfers before reporting completion (with the disconnect code) to
989
- * the user. Maybe we can improve upon this internal interface in future.
990
- */
991
- void (*clear_transfer_priv)(struct usbi_transfer *itransfer);
992
-
993
- /* Handle any pending events on file descriptors. Optional.
994
- *
995
- * Provide this function when file descriptors directly indicate device
996
- * or transfer activity. If your backend does not have such file descriptors,
997
- * implement the handle_transfer_completion function below.
998
- *
999
- * This involves monitoring any active transfers and processing their
1000
- * completion or cancellation.
1001
- *
1002
- * The function is passed an array of pollfd structures (size nfds)
1003
- * as a result of the poll() system call. The num_ready parameter
1004
- * indicates the number of file descriptors that have reported events
1005
- * (i.e. the poll() return value). This should be enough information
1006
- * for you to determine which actions need to be taken on the currently
1007
- * active transfers.
1008
- *
1009
- * For any cancelled transfers, call usbi_handle_transfer_cancellation().
1010
- * For completed transfers, call usbi_handle_transfer_completion().
1011
- * For control/bulk/interrupt transfers, populate the "transferred"
1012
- * element of the appropriate usbi_transfer structure before calling the
1013
- * above functions. For isochronous transfers, populate the status and
1014
- * transferred fields of the iso packet descriptors of the transfer.
1015
- *
1016
- * This function should also be able to detect disconnection of the
1017
- * device, reporting that situation with usbi_handle_disconnect().
1018
- *
1019
- * When processing an event related to a transfer, you probably want to
1020
- * take usbi_transfer.lock to prevent races. See the documentation for
1021
- * the usbi_transfer structure.
1022
- *
1023
- * Return 0 on success, or a LIBUSB_ERROR code on failure.
1024
- */
1025
- int (*handle_events)(struct libusb_context *ctx,
1026
- struct pollfd *fds, POLL_NFDS_TYPE nfds, int num_ready);
1027
-
1028
- /* Handle transfer completion. Optional.
1029
- *
1030
- * Provide this function when there are no file descriptors available
1031
- * that directly indicate device or transfer activity. If your backend does
1032
- * have such file descriptors, implement the handle_events function above.
1033
- *
1034
- * Your backend must tell the library when a transfer has completed by
1035
- * calling usbi_signal_transfer_completion(). You should store any private
1036
- * information about the transfer and its completion status in the transfer's
1037
- * private backend data.
1038
- *
1039
- * During event handling, this function will be called on each transfer for
1040
- * which usbi_signal_transfer_completion() was called.
1041
- *
1042
- * For any cancelled transfers, call usbi_handle_transfer_cancellation().
1043
- * For completed transfers, call usbi_handle_transfer_completion().
1044
- * For control/bulk/interrupt transfers, populate the "transferred"
1045
- * element of the appropriate usbi_transfer structure before calling the
1046
- * above functions. For isochronous transfers, populate the status and
1047
- * transferred fields of the iso packet descriptors of the transfer.
1048
- *
1049
- * Return 0 on success, or a LIBUSB_ERROR code on failure.
1050
- */
1051
- int (*handle_transfer_completion)(struct usbi_transfer *itransfer);
1052
-
1053
- /* Get time from specified clock. At least two clocks must be implemented
1054
- by the backend: USBI_CLOCK_REALTIME, and USBI_CLOCK_MONOTONIC.
1055
-
1056
- Description of clocks:
1057
- USBI_CLOCK_REALTIME : clock returns time since system epoch.
1058
- USBI_CLOCK_MONOTONIC: clock returns time since unspecified start
1059
- time (usually boot).
1060
- */
1061
- int (*clock_gettime)(int clkid, struct timespec *tp);
1062
-
1063
- #ifdef USBI_TIMERFD_AVAILABLE
1064
- /* clock ID of the clock that should be used for timerfd */
1065
- clockid_t (*get_timerfd_clockid)(void);
1066
- #endif
1067
-
1068
- /* Number of bytes to reserve for per-device private backend data.
1069
- * This private data area is accessible through the "os_priv" field of
1070
- * struct libusb_device. */
1071
- size_t device_priv_size;
1072
-
1073
- /* Number of bytes to reserve for per-handle private backend data.
1074
- * This private data area is accessible through the "os_priv" field of
1075
- * struct libusb_device. */
1076
- size_t device_handle_priv_size;
1077
-
1078
- /* Number of bytes to reserve for per-transfer private backend data.
1079
- * This private data area is accessible by calling
1080
- * usbi_transfer_get_os_priv() on the appropriate usbi_transfer instance.
1081
- */
1082
- size_t transfer_priv_size;
1083
- };
1084
-
1085
- extern const struct usbi_os_backend * const usbi_backend;
1086
-
1087
- extern const struct usbi_os_backend linux_usbfs_backend;
1088
- extern const struct usbi_os_backend darwin_backend;
1089
- extern const struct usbi_os_backend openbsd_backend;
1090
- extern const struct usbi_os_backend netbsd_backend;
1091
- extern const struct usbi_os_backend windows_backend;
1092
- extern const struct usbi_os_backend wince_backend;
1093
- extern const struct usbi_os_backend haiku_usb_raw_backend;
1094
-
1095
- extern struct list_head active_contexts_list;
1096
- extern usbi_mutex_static_t active_contexts_lock;
1097
-
1098
- #ifdef __cplusplus
1099
- }
1100
- #endif
1101
-
1102
- #endif