usb 1.7.2-prebuild

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 (183) hide show
  1. package/.github/workflows/prebuild.yml +62 -0
  2. package/.gitmodules +3 -0
  3. package/LICENSE +7 -0
  4. package/Readme.md +339 -0
  5. package/binding.gyp +90 -0
  6. package/libusb/.gitattributes +11 -0
  7. package/libusb/.private/README.txt +5 -0
  8. package/libusb/.private/bd.cmd +89 -0
  9. package/libusb/.private/bm.sh +54 -0
  10. package/libusb/.private/bwince.cmd +57 -0
  11. package/libusb/.private/post-rewrite.sh +28 -0
  12. package/libusb/.private/pre-commit.sh +42 -0
  13. package/libusb/.private/wbs.txt +61 -0
  14. package/libusb/.private/wbs_wince.txt +42 -0
  15. package/libusb/AUTHORS +78 -0
  16. package/libusb/COPYING +504 -0
  17. package/libusb/ChangeLog +211 -0
  18. package/libusb/INSTALL +234 -0
  19. package/libusb/INSTALL_WIN.txt +73 -0
  20. package/libusb/Makefile.am +28 -0
  21. package/libusb/NEWS +2 -0
  22. package/libusb/PORTING +94 -0
  23. package/libusb/README +28 -0
  24. package/libusb/README.git +41 -0
  25. package/libusb/TODO +2 -0
  26. package/libusb/Xcode/common.xcconfig +49 -0
  27. package/libusb/Xcode/debug.xcconfig +29 -0
  28. package/libusb/Xcode/libusb.xcconfig +21 -0
  29. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +1 -0
  30. package/libusb/Xcode/libusb_debug.xcconfig +21 -0
  31. package/libusb/Xcode/libusb_release.xcconfig +21 -0
  32. package/libusb/Xcode/release.xcconfig +30 -0
  33. package/libusb/android/README +114 -0
  34. package/libusb/android/jni/Android.mk +23 -0
  35. package/libusb/android/jni/Application.mk +24 -0
  36. package/libusb/android/jni/examples.mk +134 -0
  37. package/libusb/android/jni/libusb.mk +54 -0
  38. package/libusb/android/jni/tests.mk +56 -0
  39. package/libusb/autogen.sh +8 -0
  40. package/libusb/bootstrap.sh +19 -0
  41. package/libusb/configure.ac +304 -0
  42. package/libusb/doc/Makefile.am +9 -0
  43. package/libusb/doc/doxygen.cfg.in +1288 -0
  44. package/libusb/doc/libusb.png +0 -0
  45. package/libusb/examples/Makefile.am +19 -0
  46. package/libusb/examples/dpfp.c +506 -0
  47. package/libusb/examples/dpfp_threaded.c +544 -0
  48. package/libusb/examples/ezusb.c +831 -0
  49. package/libusb/examples/ezusb.h +120 -0
  50. package/libusb/examples/fxload.c +287 -0
  51. package/libusb/examples/getopt/getopt.c +1060 -0
  52. package/libusb/examples/getopt/getopt.h +180 -0
  53. package/libusb/examples/getopt/getopt1.c +188 -0
  54. package/libusb/examples/hotplugtest.c +104 -0
  55. package/libusb/examples/listdevs.c +71 -0
  56. package/libusb/examples/sam3u_benchmark.c +193 -0
  57. package/libusb/examples/xusb.c +1129 -0
  58. package/libusb/libusb/Makefile.am +75 -0
  59. package/libusb/libusb/core.c +2342 -0
  60. package/libusb/libusb/descriptor.c +1199 -0
  61. package/libusb/libusb/hotplug.c +327 -0
  62. package/libusb/libusb/hotplug.h +82 -0
  63. package/libusb/libusb/io.c +2631 -0
  64. package/libusb/libusb/libusb-1.0.def +166 -0
  65. package/libusb/libusb/libusb-1.0.rc +61 -0
  66. package/libusb/libusb/libusb.h +1998 -0
  67. package/libusb/libusb/libusbi.h +1040 -0
  68. package/libusb/libusb/os/darwin_usb.c +2009 -0
  69. package/libusb/libusb/os/darwin_usb.h +162 -0
  70. package/libusb/libusb/os/linux_netlink.c +369 -0
  71. package/libusb/libusb/os/linux_udev.c +307 -0
  72. package/libusb/libusb/os/linux_usbfs.c +2695 -0
  73. package/libusb/libusb/os/linux_usbfs.h +192 -0
  74. package/libusb/libusb/os/netbsd_usb.c +738 -0
  75. package/libusb/libusb/os/openbsd_usb.c +832 -0
  76. package/libusb/libusb/os/poll_posix.c +51 -0
  77. package/libusb/libusb/os/poll_posix.h +11 -0
  78. package/libusb/libusb/os/poll_windows.c +796 -0
  79. package/libusb/libusb/os/poll_windows.h +131 -0
  80. package/libusb/libusb/os/threads_posix.c +82 -0
  81. package/libusb/libusb/os/threads_posix.h +50 -0
  82. package/libusb/libusb/os/threads_windows.c +212 -0
  83. package/libusb/libusb/os/threads_windows.h +87 -0
  84. package/libusb/libusb/os/wince_usb.c +1032 -0
  85. package/libusb/libusb/os/wince_usb.h +131 -0
  86. package/libusb/libusb/os/windows_common.h +108 -0
  87. package/libusb/libusb/os/windows_usb.c +5347 -0
  88. package/libusb/libusb/os/windows_usb.h +971 -0
  89. package/libusb/libusb/strerror.c +199 -0
  90. package/libusb/libusb/sync.c +307 -0
  91. package/libusb/libusb/version.h +18 -0
  92. package/libusb/libusb/version_nano.h +1 -0
  93. package/libusb/libusb-1.0.pc.in +11 -0
  94. package/libusb/msvc/config.h +50 -0
  95. package/libusb/msvc/ddk_build.cmd +175 -0
  96. package/libusb/msvc/errno.h +102 -0
  97. package/libusb/msvc/fxload_2010.vcxproj +170 -0
  98. package/libusb/msvc/fxload_2010.vcxproj.filters +25 -0
  99. package/libusb/msvc/fxload_2012.vcxproj +174 -0
  100. package/libusb/msvc/fxload_2012.vcxproj.filters +25 -0
  101. package/libusb/msvc/fxload_2013.vcxproj +174 -0
  102. package/libusb/msvc/fxload_sources +23 -0
  103. package/libusb/msvc/getopt_2005.vcproj +288 -0
  104. package/libusb/msvc/getopt_2010.vcxproj +131 -0
  105. package/libusb/msvc/getopt_2010.vcxproj.filters +26 -0
  106. package/libusb/msvc/getopt_2012.vcxproj +136 -0
  107. package/libusb/msvc/getopt_2012.vcxproj.filters +26 -0
  108. package/libusb/msvc/getopt_2013.vcxproj +136 -0
  109. package/libusb/msvc/getopt_sources +20 -0
  110. package/libusb/msvc/hotplugtest_2010.vcxproj +163 -0
  111. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +14 -0
  112. package/libusb/msvc/hotplugtest_2012.vcxproj +167 -0
  113. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +14 -0
  114. package/libusb/msvc/hotplugtest_2013.vcxproj +167 -0
  115. package/libusb/msvc/hotplugtest_sources +20 -0
  116. package/libusb/msvc/inttypes.h +295 -0
  117. package/libusb/msvc/libusb.dsw +71 -0
  118. package/libusb/msvc/libusb_2005.sln +95 -0
  119. package/libusb/msvc/libusb_2010.sln +94 -0
  120. package/libusb/msvc/libusb_2012.sln +94 -0
  121. package/libusb/msvc/libusb_2013.sln +100 -0
  122. package/libusb/msvc/libusb_2015.sln +100 -0
  123. package/libusb/msvc/libusb_dll.dsp +194 -0
  124. package/libusb/msvc/libusb_dll_2005.vcproj +436 -0
  125. package/libusb/msvc/libusb_dll_2010.vcxproj +170 -0
  126. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +81 -0
  127. package/libusb/msvc/libusb_dll_2012.vcxproj +175 -0
  128. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +84 -0
  129. package/libusb/msvc/libusb_dll_2013.vcxproj +175 -0
  130. package/libusb/msvc/libusb_dll_wince.vcproj +1243 -0
  131. package/libusb/msvc/libusb_sources +38 -0
  132. package/libusb/msvc/libusb_static.dsp +174 -0
  133. package/libusb/msvc/libusb_static_2005.vcproj +362 -0
  134. package/libusb/msvc/libusb_static_2010.vcxproj +156 -0
  135. package/libusb/msvc/libusb_static_2010.vcxproj.filters +74 -0
  136. package/libusb/msvc/libusb_static_2012.vcxproj +160 -0
  137. package/libusb/msvc/libusb_static_2012.vcxproj.filters +74 -0
  138. package/libusb/msvc/libusb_static_2013.vcxproj +160 -0
  139. package/libusb/msvc/libusb_static_wince.vcproj +1185 -0
  140. package/libusb/msvc/libusb_wince.sln +246 -0
  141. package/libusb/msvc/listdevs.dsp +103 -0
  142. package/libusb/msvc/listdevs_2005.vcproj +360 -0
  143. package/libusb/msvc/listdevs_2010.vcxproj +165 -0
  144. package/libusb/msvc/listdevs_2010.vcxproj.filters +14 -0
  145. package/libusb/msvc/listdevs_2012.vcxproj +169 -0
  146. package/libusb/msvc/listdevs_2012.vcxproj.filters +14 -0
  147. package/libusb/msvc/listdevs_2013.vcxproj +169 -0
  148. package/libusb/msvc/listdevs_sources +19 -0
  149. package/libusb/msvc/listdevs_wince.vcproj +1120 -0
  150. package/libusb/msvc/missing.c +80 -0
  151. package/libusb/msvc/missing.h +32 -0
  152. package/libusb/msvc/stdint.h +256 -0
  153. package/libusb/msvc/stress_2005.vcproj +390 -0
  154. package/libusb/msvc/stress_2010.vcxproj +167 -0
  155. package/libusb/msvc/stress_2010.vcxproj.filters +25 -0
  156. package/libusb/msvc/stress_2012.vcxproj +171 -0
  157. package/libusb/msvc/stress_2012.vcxproj.filters +25 -0
  158. package/libusb/msvc/stress_2013.vcxproj +171 -0
  159. package/libusb/msvc/stress_wince.vcproj +1128 -0
  160. package/libusb/msvc/xusb.dsp +102 -0
  161. package/libusb/msvc/xusb_2005.vcproj +344 -0
  162. package/libusb/msvc/xusb_2010.vcxproj +163 -0
  163. package/libusb/msvc/xusb_2010.vcxproj.filters +14 -0
  164. package/libusb/msvc/xusb_2012.vcxproj +167 -0
  165. package/libusb/msvc/xusb_2012.vcxproj.filters +14 -0
  166. package/libusb/msvc/xusb_2013.vcxproj +167 -0
  167. package/libusb/msvc/xusb_sources +20 -0
  168. package/libusb/msvc/xusb_wince.vcproj +1120 -0
  169. package/libusb/tests/Makefile.am +6 -0
  170. package/libusb/tests/libusb_testlib.h +107 -0
  171. package/libusb/tests/stress.c +160 -0
  172. package/libusb/tests/testlib.c +281 -0
  173. package/libusb.gypi +136 -0
  174. package/libusb_config/config.h +1 -0
  175. package/package.json +69 -0
  176. package/src/device.cc +412 -0
  177. package/src/helpers.h +64 -0
  178. package/src/node_usb.cc +319 -0
  179. package/src/node_usb.h +120 -0
  180. package/src/transfer.cc +148 -0
  181. package/src/uv_async_queue.h +33 -0
  182. package/test/usb.coffee +191 -0
  183. package/usb.js +524 -0
@@ -0,0 +1,199 @@
1
+ /*
2
+ * libusb strerror code
3
+ * Copyright © 2013 Hans de Goede <hdegoede@redhat.com>
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+ #include "config.h"
20
+
21
+ #include <locale.h>
22
+ #include <stdlib.h>
23
+ #include <string.h>
24
+
25
+ #include "libusb.h"
26
+ #include "libusbi.h"
27
+
28
+ #if defined(_MSC_VER)
29
+ #define strncasecmp _strnicmp
30
+ #endif
31
+
32
+ static size_t usbi_locale = 0;
33
+
34
+ /** \ingroup misc
35
+ * How to add a new \ref libusb_strerror() translation:
36
+ * <ol>
37
+ * <li> Download the latest \c strerror.c from:<br>
38
+ * https://raw.github.com/libusb/libusb/master/libusb/sterror.c </li>
39
+ * <li> Open the file in an UTF-8 capable editor </li>
40
+ * <li> Add the 2 letter <a href="http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1</a>
41
+ * code for your locale at the end of \c usbi_locale_supported[]<br>
42
+ * Eg. for Chinese, you would add "zh" so that:
43
+ * \code... usbi_locale_supported[] = { "en", "nl", "fr" };\endcode
44
+ * becomes:
45
+ * \code... usbi_locale_supported[] = { "en", "nl", "fr", "zh" };\endcode </li>
46
+ * <li> Copy the <tt>{ / * English (en) * / ... }</tt> section and add it at the end of \c usbi_localized_errors<br>
47
+ * Eg. for Chinese, the last section of \c usbi_localized_errors could look like:
48
+ * \code
49
+ * }, { / * Chinese (zh) * /
50
+ * "Success",
51
+ * ...
52
+ * "Other error",
53
+ * }
54
+ * };\endcode </li>
55
+ * <li> Translate each of the English messages from the section you copied into your language </li>
56
+ * <li> Save the file (in UTF-8 format) and send it to \c libusb-devel\@lists.sourceforge.net </li>
57
+ * </ol>
58
+ */
59
+
60
+ static const char* usbi_locale_supported[] = { "en", "nl", "fr", "ru" };
61
+ static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUSB_ERROR_COUNT] = {
62
+ { /* English (en) */
63
+ "Success",
64
+ "Input/Output Error",
65
+ "Invalid parameter",
66
+ "Access denied (insufficient permissions)",
67
+ "No such device (it may have been disconnected)",
68
+ "Entity not found",
69
+ "Resource busy",
70
+ "Operation timed out",
71
+ "Overflow",
72
+ "Pipe error",
73
+ "System call interrupted (perhaps due to signal)",
74
+ "Insufficient memory",
75
+ "Operation not supported or unimplemented on this platform",
76
+ "Other error",
77
+ }, { /* Dutch (nl) */
78
+ "Gelukt",
79
+ "Invoer-/uitvoerfout",
80
+ "Ongeldig argument",
81
+ "Toegang geweigerd (onvoldoende toegangsrechten)",
82
+ "Apparaat bestaat niet (verbinding met apparaat verbroken?)",
83
+ "Niet gevonden",
84
+ "Apparaat of hulpbron is bezig",
85
+ "Bewerking verlopen",
86
+ "Waarde is te groot",
87
+ "Gebroken pijp",
88
+ "Onderbroken systeemaanroep",
89
+ "Onvoldoende geheugen beschikbaar",
90
+ "Bewerking wordt niet ondersteund",
91
+ "Andere fout",
92
+ }, { /* French (fr) */
93
+ "Succès",
94
+ "Erreur d'entrée/sortie",
95
+ "Paramètre invalide",
96
+ "Accès refusé (permissions insuffisantes)",
97
+ "Périphérique introuvable (peut-être déconnecté)",
98
+ "Elément introuvable",
99
+ "Resource déjà occupée",
100
+ "Operation expirée",
101
+ "Débordement",
102
+ "Erreur de pipe",
103
+ "Appel système abandonné (peut-être à cause d’un signal)",
104
+ "Mémoire insuffisante",
105
+ "Opération non supportée or non implémentée sur cette plateforme",
106
+ "Autre erreur",
107
+ }, { /* Russian (ru) */
108
+ "Успех",
109
+ "Ошибка ввода/вывода",
110
+ "Неверный параметр",
111
+ "Доступ запрещён (не хватает прав)",
112
+ "Устройство отсутствует (возможно, оно было отсоединено)",
113
+ "Элемент не найден",
114
+ "Ресурс занят",
115
+ "Истекло время ожидания операции",
116
+ "Переполнение",
117
+ "Ошибка канала",
118
+ "Системный вызов прерван (возможно, сигналом)",
119
+ "Память исчерпана",
120
+ "Операция не поддерживается данной платформой",
121
+ "Неизвестная ошибка"
122
+ }
123
+ };
124
+
125
+ /** \ingroup misc
126
+ * Set the language, and only the language, not the encoding! used for
127
+ * translatable libusb messages.
128
+ *
129
+ * This takes a locale string in the default setlocale format: lang[-region]
130
+ * or lang[_country_region][.codeset]. Only the lang part of the string is
131
+ * used, and only 2 letter ISO 639-1 codes are accepted for it, such as "de".
132
+ * The optional region, country_region or codeset parts are ignored. This
133
+ * means that functions which return translatable strings will NOT honor the
134
+ * specified encoding.
135
+ * All strings returned are encoded as UTF-8 strings.
136
+ *
137
+ * If libusb_setlocale() is not called, all messages will be in English.
138
+ *
139
+ * The following functions return translatable strings: libusb_strerror().
140
+ * Note that the libusb log messages controlled through libusb_set_debug()
141
+ * are not translated, they are always in English.
142
+ *
143
+ * For POSIX UTF-8 environments if you want libusb to follow the standard
144
+ * locale settings, call libusb_setlocale(setlocale(LC_MESSAGES, NULL)),
145
+ * after your app has done its locale setup.
146
+ *
147
+ * \param locale locale-string in the form of lang[_country_region][.codeset]
148
+ * or lang[-region], where lang is a 2 letter ISO 639-1 code
149
+ * \returns LIBUSB_SUCCESS on success
150
+ * \returns LIBUSB_ERROR_INVALID_PARAM if the locale doesn't meet the requirements
151
+ * \returns LIBUSB_ERROR_NOT_FOUND if the requested language is not supported
152
+ * \returns a LIBUSB_ERROR code on other errors
153
+ */
154
+
155
+ int API_EXPORTED libusb_setlocale(const char *locale)
156
+ {
157
+ size_t i;
158
+
159
+ if ( (locale == NULL) || (strlen(locale) < 2)
160
+ || ((strlen(locale) > 2) && (locale[2] != '-') && (locale[2] != '_') && (locale[2] != '.')) )
161
+ return LIBUSB_ERROR_INVALID_PARAM;
162
+
163
+ for (i=0; i<ARRAYSIZE(usbi_locale_supported); i++) {
164
+ if (strncasecmp(usbi_locale_supported[i], locale, 2) == 0)
165
+ break;
166
+ }
167
+ if (i >= ARRAYSIZE(usbi_locale_supported)) {
168
+ return LIBUSB_ERROR_NOT_FOUND;
169
+ }
170
+
171
+ usbi_locale = i;
172
+
173
+ return LIBUSB_SUCCESS;
174
+ }
175
+
176
+ /** \ingroup misc
177
+ * Returns a constant string with a short description of the given error code,
178
+ * this description is intended for displaying to the end user and will be in
179
+ * the language set by libusb_setlocale().
180
+ *
181
+ * The returned string is encoded in UTF-8.
182
+ *
183
+ * The messages always start with a capital letter and end without any dot.
184
+ * The caller must not free() the returned string.
185
+ *
186
+ * \param errcode the error code whose description is desired
187
+ * \returns a short description of the error code in UTF-8 encoding
188
+ */
189
+ DEFAULT_VISIBILITY const char* LIBUSB_CALL libusb_strerror(enum libusb_error errcode)
190
+ {
191
+ int errcode_index = -errcode;
192
+
193
+ if ((errcode_index < 0) || (errcode_index >= LIBUSB_ERROR_COUNT)) {
194
+ /* "Other Error", which should always be our last message, is returned */
195
+ errcode_index = LIBUSB_ERROR_COUNT - 1;
196
+ }
197
+
198
+ return usbi_localized_errors[usbi_locale][errcode_index];
199
+ }
@@ -0,0 +1,307 @@
1
+ /*
2
+ * Synchronous I/O functions for libusb
3
+ * Copyright © 2007-2008 Daniel Drake <dsd@gentoo.org>
4
+ *
5
+ * This library is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU Lesser General Public
7
+ * License as published by the Free Software Foundation; either
8
+ * version 2.1 of the License, or (at your option) any later version.
9
+ *
10
+ * This library is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ * Lesser General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU Lesser General Public
16
+ * License along with this library; if not, write to the Free Software
17
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
+ */
19
+
20
+ #include "config.h"
21
+ #include <errno.h>
22
+ #include <stdint.h>
23
+ #include <stdlib.h>
24
+ #include <string.h>
25
+
26
+ #include "libusbi.h"
27
+
28
+ /**
29
+ * @defgroup syncio Synchronous device I/O
30
+ *
31
+ * This page documents libusb's synchronous (blocking) API for USB device I/O.
32
+ * This interface is easy to use but has some limitations. More advanced users
33
+ * may wish to consider using the \ref asyncio "asynchronous I/O API" instead.
34
+ */
35
+
36
+ static void LIBUSB_CALL sync_transfer_cb(struct libusb_transfer *transfer)
37
+ {
38
+ int *completed = transfer->user_data;
39
+ *completed = 1;
40
+ usbi_dbg("actual_length=%d", transfer->actual_length);
41
+ /* caller interprets result and frees transfer */
42
+ }
43
+
44
+ static void sync_transfer_wait_for_completion(struct libusb_transfer *transfer)
45
+ {
46
+ int r, *completed = transfer->user_data;
47
+ struct libusb_context *ctx = HANDLE_CTX(transfer->dev_handle);
48
+
49
+ while (!*completed) {
50
+ r = libusb_handle_events_completed(ctx, completed);
51
+ if (r < 0) {
52
+ if (r == LIBUSB_ERROR_INTERRUPTED)
53
+ continue;
54
+ usbi_err(ctx, "libusb_handle_events failed: %s, cancelling transfer and retrying",
55
+ libusb_error_name(r));
56
+ libusb_cancel_transfer(transfer);
57
+ continue;
58
+ }
59
+ }
60
+ }
61
+
62
+ /** \ingroup syncio
63
+ * Perform a USB control transfer.
64
+ *
65
+ * The direction of the transfer is inferred from the bmRequestType field of
66
+ * the setup packet.
67
+ *
68
+ * The wValue, wIndex and wLength fields values should be given in host-endian
69
+ * byte order.
70
+ *
71
+ * \param dev_handle a handle for the device to communicate with
72
+ * \param bmRequestType the request type field for the setup packet
73
+ * \param bRequest the request field for the setup packet
74
+ * \param wValue the value field for the setup packet
75
+ * \param wIndex the index field for the setup packet
76
+ * \param data a suitably-sized data buffer for either input or output
77
+ * (depending on direction bits within bmRequestType)
78
+ * \param wLength the length field for the setup packet. The data buffer should
79
+ * be at least this size.
80
+ * \param timeout timeout (in millseconds) that this function should wait
81
+ * before giving up due to no response being received. For an unlimited
82
+ * timeout, use value 0.
83
+ * \returns on success, the number of bytes actually transferred
84
+ * \returns LIBUSB_ERROR_TIMEOUT if the transfer timed out
85
+ * \returns LIBUSB_ERROR_PIPE if the control request was not supported by the
86
+ * device
87
+ * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
88
+ * \returns another LIBUSB_ERROR code on other failures
89
+ */
90
+ int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
91
+ uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
92
+ unsigned char *data, uint16_t wLength, unsigned int timeout)
93
+ {
94
+ struct libusb_transfer *transfer = libusb_alloc_transfer(0);
95
+ unsigned char *buffer;
96
+ int completed = 0;
97
+ int r;
98
+
99
+ if (!transfer)
100
+ return LIBUSB_ERROR_NO_MEM;
101
+
102
+ buffer = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + wLength);
103
+ if (!buffer) {
104
+ libusb_free_transfer(transfer);
105
+ return LIBUSB_ERROR_NO_MEM;
106
+ }
107
+
108
+ libusb_fill_control_setup(buffer, bmRequestType, bRequest, wValue, wIndex,
109
+ wLength);
110
+ if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
111
+ memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, wLength);
112
+
113
+ libusb_fill_control_transfer(transfer, dev_handle, buffer,
114
+ sync_transfer_cb, &completed, timeout);
115
+ transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER;
116
+ r = libusb_submit_transfer(transfer);
117
+ if (r < 0) {
118
+ libusb_free_transfer(transfer);
119
+ return r;
120
+ }
121
+
122
+ sync_transfer_wait_for_completion(transfer);
123
+
124
+ if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
125
+ memcpy(data, libusb_control_transfer_get_data(transfer),
126
+ transfer->actual_length);
127
+
128
+ switch (transfer->status) {
129
+ case LIBUSB_TRANSFER_COMPLETED:
130
+ r = transfer->actual_length;
131
+ break;
132
+ case LIBUSB_TRANSFER_TIMED_OUT:
133
+ r = LIBUSB_ERROR_TIMEOUT;
134
+ break;
135
+ case LIBUSB_TRANSFER_STALL:
136
+ r = LIBUSB_ERROR_PIPE;
137
+ break;
138
+ case LIBUSB_TRANSFER_NO_DEVICE:
139
+ r = LIBUSB_ERROR_NO_DEVICE;
140
+ break;
141
+ case LIBUSB_TRANSFER_OVERFLOW:
142
+ r = LIBUSB_ERROR_OVERFLOW;
143
+ break;
144
+ case LIBUSB_TRANSFER_ERROR:
145
+ case LIBUSB_TRANSFER_CANCELLED:
146
+ r = LIBUSB_ERROR_IO;
147
+ break;
148
+ default:
149
+ usbi_warn(HANDLE_CTX(dev_handle),
150
+ "unrecognised status code %d", transfer->status);
151
+ r = LIBUSB_ERROR_OTHER;
152
+ }
153
+
154
+ libusb_free_transfer(transfer);
155
+ return r;
156
+ }
157
+
158
+ static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
159
+ unsigned char endpoint, unsigned char *buffer, int length,
160
+ int *transferred, unsigned int timeout, unsigned char type)
161
+ {
162
+ struct libusb_transfer *transfer = libusb_alloc_transfer(0);
163
+ int completed = 0;
164
+ int r;
165
+
166
+ if (!transfer)
167
+ return LIBUSB_ERROR_NO_MEM;
168
+
169
+ libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, length,
170
+ sync_transfer_cb, &completed, timeout);
171
+ transfer->type = type;
172
+
173
+ r = libusb_submit_transfer(transfer);
174
+ if (r < 0) {
175
+ libusb_free_transfer(transfer);
176
+ return r;
177
+ }
178
+
179
+ sync_transfer_wait_for_completion(transfer);
180
+
181
+ *transferred = transfer->actual_length;
182
+ switch (transfer->status) {
183
+ case LIBUSB_TRANSFER_COMPLETED:
184
+ r = 0;
185
+ break;
186
+ case LIBUSB_TRANSFER_TIMED_OUT:
187
+ r = LIBUSB_ERROR_TIMEOUT;
188
+ break;
189
+ case LIBUSB_TRANSFER_STALL:
190
+ r = LIBUSB_ERROR_PIPE;
191
+ break;
192
+ case LIBUSB_TRANSFER_OVERFLOW:
193
+ r = LIBUSB_ERROR_OVERFLOW;
194
+ break;
195
+ case LIBUSB_TRANSFER_NO_DEVICE:
196
+ r = LIBUSB_ERROR_NO_DEVICE;
197
+ break;
198
+ case LIBUSB_TRANSFER_ERROR:
199
+ case LIBUSB_TRANSFER_CANCELLED:
200
+ r = LIBUSB_ERROR_IO;
201
+ break;
202
+ default:
203
+ usbi_warn(HANDLE_CTX(dev_handle),
204
+ "unrecognised status code %d", transfer->status);
205
+ r = LIBUSB_ERROR_OTHER;
206
+ }
207
+
208
+ libusb_free_transfer(transfer);
209
+ return r;
210
+ }
211
+
212
+ /** \ingroup syncio
213
+ * Perform a USB bulk transfer. The direction of the transfer is inferred from
214
+ * the direction bits of the endpoint address.
215
+ *
216
+ * For bulk reads, the <tt>length</tt> field indicates the maximum length of
217
+ * data you are expecting to receive. If less data arrives than expected,
218
+ * this function will return that data, so be sure to check the
219
+ * <tt>transferred</tt> output parameter.
220
+ *
221
+ * You should also check the <tt>transferred</tt> parameter for bulk writes.
222
+ * Not all of the data may have been written.
223
+ *
224
+ * Also check <tt>transferred</tt> when dealing with a timeout error code.
225
+ * libusb may have to split your transfer into a number of chunks to satisfy
226
+ * underlying O/S requirements, meaning that the timeout may expire after
227
+ * the first few chunks have completed. libusb is careful not to lose any data
228
+ * that may have been transferred; do not assume that timeout conditions
229
+ * indicate a complete lack of I/O.
230
+ *
231
+ * \param dev_handle a handle for the device to communicate with
232
+ * \param endpoint the address of a valid endpoint to communicate with
233
+ * \param data a suitably-sized data buffer for either input or output
234
+ * (depending on endpoint)
235
+ * \param length for bulk writes, the number of bytes from data to be sent. for
236
+ * bulk reads, the maximum number of bytes to receive into the data buffer.
237
+ * \param transferred output location for the number of bytes actually
238
+ * transferred.
239
+ * \param timeout timeout (in millseconds) that this function should wait
240
+ * before giving up due to no response being received. For an unlimited
241
+ * timeout, use value 0.
242
+ *
243
+ * \returns 0 on success (and populates <tt>transferred</tt>)
244
+ * \returns LIBUSB_ERROR_TIMEOUT if the transfer timed out (and populates
245
+ * <tt>transferred</tt>)
246
+ * \returns LIBUSB_ERROR_PIPE if the endpoint halted
247
+ * \returns LIBUSB_ERROR_OVERFLOW if the device offered more data, see
248
+ * \ref packetoverflow
249
+ * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
250
+ * \returns another LIBUSB_ERROR code on other failures
251
+ */
252
+ int API_EXPORTED libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
253
+ unsigned char endpoint, unsigned char *data, int length, int *transferred,
254
+ unsigned int timeout)
255
+ {
256
+ return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
257
+ transferred, timeout, LIBUSB_TRANSFER_TYPE_BULK);
258
+ }
259
+
260
+ /** \ingroup syncio
261
+ * Perform a USB interrupt transfer. The direction of the transfer is inferred
262
+ * from the direction bits of the endpoint address.
263
+ *
264
+ * For interrupt reads, the <tt>length</tt> field indicates the maximum length
265
+ * of data you are expecting to receive. If less data arrives than expected,
266
+ * this function will return that data, so be sure to check the
267
+ * <tt>transferred</tt> output parameter.
268
+ *
269
+ * You should also check the <tt>transferred</tt> parameter for interrupt
270
+ * writes. Not all of the data may have been written.
271
+ *
272
+ * Also check <tt>transferred</tt> when dealing with a timeout error code.
273
+ * libusb may have to split your transfer into a number of chunks to satisfy
274
+ * underlying O/S requirements, meaning that the timeout may expire after
275
+ * the first few chunks have completed. libusb is careful not to lose any data
276
+ * that may have been transferred; do not assume that timeout conditions
277
+ * indicate a complete lack of I/O.
278
+ *
279
+ * The default endpoint bInterval value is used as the polling interval.
280
+ *
281
+ * \param dev_handle a handle for the device to communicate with
282
+ * \param endpoint the address of a valid endpoint to communicate with
283
+ * \param data a suitably-sized data buffer for either input or output
284
+ * (depending on endpoint)
285
+ * \param length for bulk writes, the number of bytes from data to be sent. for
286
+ * bulk reads, the maximum number of bytes to receive into the data buffer.
287
+ * \param transferred output location for the number of bytes actually
288
+ * transferred.
289
+ * \param timeout timeout (in millseconds) that this function should wait
290
+ * before giving up due to no response being received. For an unlimited
291
+ * timeout, use value 0.
292
+ *
293
+ * \returns 0 on success (and populates <tt>transferred</tt>)
294
+ * \returns LIBUSB_ERROR_TIMEOUT if the transfer timed out
295
+ * \returns LIBUSB_ERROR_PIPE if the endpoint halted
296
+ * \returns LIBUSB_ERROR_OVERFLOW if the device offered more data, see
297
+ * \ref packetoverflow
298
+ * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
299
+ * \returns another LIBUSB_ERROR code on other error
300
+ */
301
+ int API_EXPORTED libusb_interrupt_transfer(
302
+ struct libusb_device_handle *dev_handle, unsigned char endpoint,
303
+ unsigned char *data, int length, int *transferred, unsigned int timeout)
304
+ {
305
+ return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
306
+ transferred, timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);
307
+ }
@@ -0,0 +1,18 @@
1
+ /* This file is parsed by m4 and windres and RC.EXE so please keep it simple. */
2
+ #include "version_nano.h"
3
+ #ifndef LIBUSB_MAJOR
4
+ #define LIBUSB_MAJOR 1
5
+ #endif
6
+ #ifndef LIBUSB_MINOR
7
+ #define LIBUSB_MINOR 0
8
+ #endif
9
+ #ifndef LIBUSB_MICRO
10
+ #define LIBUSB_MICRO 19
11
+ #endif
12
+ #ifndef LIBUSB_NANO
13
+ #define LIBUSB_NANO 0
14
+ #endif
15
+ /* LIBUSB_RC is the release candidate suffix. Should normally be empty. */
16
+ #ifndef LIBUSB_RC
17
+ #define LIBUSB_RC ""
18
+ #endif
@@ -0,0 +1 @@
1
+ #define LIBUSB_NANO 10914
@@ -0,0 +1,11 @@
1
+ prefix=@prefix@
2
+ exec_prefix=@exec_prefix@
3
+ libdir=@libdir@
4
+ includedir=@includedir@
5
+
6
+ Name: libusb-1.0
7
+ Description: C API for USB device access from Linux, Mac OS X, Windows and OpenBSD/NetBSD userspace
8
+ Version: @VERSION@
9
+ Libs: -L${libdir} -lusb-1.0
10
+ Libs.private: @LIBS@
11
+ Cflags: -I${includedir}/libusb-1.0
@@ -0,0 +1,50 @@
1
+ /* config.h. Manual config for MSVC. */
2
+
3
+ #ifndef _MSC_VER
4
+ #warn "msvc/config.h shouldn't be included for your development environment."
5
+ #error "Please make sure the msvc/ directory is removed from your build path."
6
+ #endif
7
+
8
+ /* Visual Studio 2015 and later defines timespec */
9
+ #if defined(_MSC_VER) && (_MSC_VER >= 1900)
10
+ #define _TIMESPEC_DEFINED 1
11
+ #endif
12
+
13
+ /* Disable: warning C4200: nonstandard extension used : zero-sized array in struct/union */
14
+ #pragma warning(disable:4200)
15
+ /* Disable: warning C6258: Using TerminateThread does not allow proper thread clean up */
16
+ #pragma warning(disable: 6258)
17
+ /* Disable: warning C4996: 'GetVersionA': was declared deprecated */
18
+ #pragma warning(disable: 4996)
19
+
20
+ #if defined(_PREFAST_)
21
+ /* Disable "Banned API" errors when using the MS's WDK OACR/Prefast */
22
+ #pragma warning(disable:28719)
23
+ /* Disable "The function 'InitializeCriticalSection' must be called from within a try/except block" */
24
+ #pragma warning(disable:28125)
25
+ #endif
26
+
27
+ /* Default visibility */
28
+ #define DEFAULT_VISIBILITY /**/
29
+
30
+ /* Enable global message logging */
31
+ #define ENABLE_LOGGING 1
32
+
33
+ /* Uncomment to start with debug message logging enabled */
34
+ // #define ENABLE_DEBUG_LOGGING 1
35
+
36
+ /* Uncomment to enabling logging to system log */
37
+ // #define USE_SYSTEM_LOGGING_FACILITY
38
+
39
+ /* type of second poll() argument */
40
+ #define POLL_NFDS_TYPE unsigned int
41
+
42
+ /* Windows/WinCE backend */
43
+ #if defined(_WIN32_WCE)
44
+ #define OS_WINCE 1
45
+ #define HAVE_MISSING_H
46
+ #else
47
+ #define OS_WINDOWS 1
48
+ #define HAVE_SIGNAL_H 1
49
+ #define HAVE_SYS_TYPES_H 1
50
+ #endif