libusb 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
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,202 +0,0 @@
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
-
20
- #include <config.h>
21
-
22
- #include <locale.h>
23
- #include <stdlib.h>
24
- #include <string.h>
25
- #if defined(HAVE_STRINGS_H)
26
- #include <strings.h>
27
- #endif
28
-
29
- #include "libusbi.h"
30
-
31
- #if defined(_MSC_VER)
32
- #define strncasecmp _strnicmp
33
- #endif
34
-
35
- static size_t usbi_locale = 0;
36
-
37
- /** \ingroup misc
38
- * How to add a new \ref libusb_strerror() translation:
39
- * <ol>
40
- * <li> Download the latest \c strerror.c from:<br>
41
- * https://raw.github.com/libusb/libusb/master/libusb/sterror.c </li>
42
- * <li> Open the file in an UTF-8 capable editor </li>
43
- * <li> Add the 2 letter <a href="http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes">ISO 639-1</a>
44
- * code for your locale at the end of \c usbi_locale_supported[]<br>
45
- * Eg. for Chinese, you would add "zh" so that:
46
- * \code... usbi_locale_supported[] = { "en", "nl", "fr" };\endcode
47
- * becomes:
48
- * \code... usbi_locale_supported[] = { "en", "nl", "fr", "zh" };\endcode </li>
49
- * <li> Copy the <tt>{ / * English (en) * / ... }</tt> section and add it at the end of \c usbi_localized_errors<br>
50
- * Eg. for Chinese, the last section of \c usbi_localized_errors could look like:
51
- * \code
52
- * }, { / * Chinese (zh) * /
53
- * "Success",
54
- * ...
55
- * "Other error",
56
- * }
57
- * };\endcode </li>
58
- * <li> Translate each of the English messages from the section you copied into your language </li>
59
- * <li> Save the file (in UTF-8 format) and send it to \c libusb-devel\@lists.sourceforge.net </li>
60
- * </ol>
61
- */
62
-
63
- static const char* usbi_locale_supported[] = { "en", "nl", "fr", "ru" };
64
- static const char* usbi_localized_errors[ARRAYSIZE(usbi_locale_supported)][LIBUSB_ERROR_COUNT] = {
65
- { /* English (en) */
66
- "Success",
67
- "Input/Output Error",
68
- "Invalid parameter",
69
- "Access denied (insufficient permissions)",
70
- "No such device (it may have been disconnected)",
71
- "Entity not found",
72
- "Resource busy",
73
- "Operation timed out",
74
- "Overflow",
75
- "Pipe error",
76
- "System call interrupted (perhaps due to signal)",
77
- "Insufficient memory",
78
- "Operation not supported or unimplemented on this platform",
79
- "Other error",
80
- }, { /* Dutch (nl) */
81
- "Gelukt",
82
- "Invoer-/uitvoerfout",
83
- "Ongeldig argument",
84
- "Toegang geweigerd (onvoldoende toegangsrechten)",
85
- "Apparaat bestaat niet (verbinding met apparaat verbroken?)",
86
- "Niet gevonden",
87
- "Apparaat of hulpbron is bezig",
88
- "Bewerking verlopen",
89
- "Waarde is te groot",
90
- "Gebroken pijp",
91
- "Onderbroken systeemaanroep",
92
- "Onvoldoende geheugen beschikbaar",
93
- "Bewerking wordt niet ondersteund",
94
- "Andere fout",
95
- }, { /* French (fr) */
96
- "Succès",
97
- "Erreur d'entrée/sortie",
98
- "Paramètre invalide",
99
- "Accès refusé (permissions insuffisantes)",
100
- "Périphérique introuvable (peut-être déconnecté)",
101
- "Elément introuvable",
102
- "Resource déjà occupée",
103
- "Operation expirée",
104
- "Débordement",
105
- "Erreur de pipe",
106
- "Appel système abandonné (peut-être à cause d’un signal)",
107
- "Mémoire insuffisante",
108
- "Opération non supportée or non implémentée sur cette plateforme",
109
- "Autre erreur",
110
- }, { /* Russian (ru) */
111
- "Успех",
112
- "Ошибка ввода/вывода",
113
- "Неверный параметр",
114
- "Доступ запрещён (не хватает прав)",
115
- "Устройство отсутствует (возможно, оно было отсоединено)",
116
- "Элемент не найден",
117
- "Ресурс занят",
118
- "Истекло время ожидания операции",
119
- "Переполнение",
120
- "Ошибка канала",
121
- "Системный вызов прерван (возможно, сигналом)",
122
- "Память исчерпана",
123
- "Операция не поддерживается данной платформой",
124
- "Неизвестная ошибка"
125
- }
126
- };
127
-
128
- /** \ingroup misc
129
- * Set the language, and only the language, not the encoding! used for
130
- * translatable libusb messages.
131
- *
132
- * This takes a locale string in the default setlocale format: lang[-region]
133
- * or lang[_country_region][.codeset]. Only the lang part of the string is
134
- * used, and only 2 letter ISO 639-1 codes are accepted for it, such as "de".
135
- * The optional region, country_region or codeset parts are ignored. This
136
- * means that functions which return translatable strings will NOT honor the
137
- * specified encoding.
138
- * All strings returned are encoded as UTF-8 strings.
139
- *
140
- * If libusb_setlocale() is not called, all messages will be in English.
141
- *
142
- * The following functions return translatable strings: libusb_strerror().
143
- * Note that the libusb log messages controlled through libusb_set_debug()
144
- * are not translated, they are always in English.
145
- *
146
- * For POSIX UTF-8 environments if you want libusb to follow the standard
147
- * locale settings, call libusb_setlocale(setlocale(LC_MESSAGES, NULL)),
148
- * after your app has done its locale setup.
149
- *
150
- * \param locale locale-string in the form of lang[_country_region][.codeset]
151
- * or lang[-region], where lang is a 2 letter ISO 639-1 code
152
- * \returns LIBUSB_SUCCESS on success
153
- * \returns LIBUSB_ERROR_INVALID_PARAM if the locale doesn't meet the requirements
154
- * \returns LIBUSB_ERROR_NOT_FOUND if the requested language is not supported
155
- * \returns a LIBUSB_ERROR code on other errors
156
- */
157
-
158
- int API_EXPORTED libusb_setlocale(const char *locale)
159
- {
160
- size_t i;
161
-
162
- if ( (locale == NULL) || (strlen(locale) < 2)
163
- || ((strlen(locale) > 2) && (locale[2] != '-') && (locale[2] != '_') && (locale[2] != '.')) )
164
- return LIBUSB_ERROR_INVALID_PARAM;
165
-
166
- for (i=0; i<ARRAYSIZE(usbi_locale_supported); i++) {
167
- if (strncasecmp(usbi_locale_supported[i], locale, 2) == 0)
168
- break;
169
- }
170
- if (i >= ARRAYSIZE(usbi_locale_supported)) {
171
- return LIBUSB_ERROR_NOT_FOUND;
172
- }
173
-
174
- usbi_locale = i;
175
-
176
- return LIBUSB_SUCCESS;
177
- }
178
-
179
- /** \ingroup misc
180
- * Returns a constant string with a short description of the given error code,
181
- * this description is intended for displaying to the end user and will be in
182
- * the language set by libusb_setlocale().
183
- *
184
- * The returned string is encoded in UTF-8.
185
- *
186
- * The messages always start with a capital letter and end without any dot.
187
- * The caller must not free() the returned string.
188
- *
189
- * \param errcode the error code whose description is desired
190
- * \returns a short description of the error code in UTF-8 encoding
191
- */
192
- DEFAULT_VISIBILITY const char* LIBUSB_CALL libusb_strerror(enum libusb_error errcode)
193
- {
194
- int errcode_index = -errcode;
195
-
196
- if ((errcode_index < 0) || (errcode_index >= LIBUSB_ERROR_COUNT)) {
197
- /* "Other Error", which should always be our last message, is returned */
198
- errcode_index = LIBUSB_ERROR_COUNT - 1;
199
- }
200
-
201
- return usbi_localized_errors[usbi_locale][errcode_index];
202
- }
@@ -1,308 +0,0 @@
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
-
22
- #include <errno.h>
23
- #include <stdint.h>
24
- #include <stdlib.h>
25
- #include <string.h>
26
-
27
- #include "libusbi.h"
28
-
29
- /**
30
- * @defgroup syncio Synchronous device I/O
31
- *
32
- * This page documents libusb's synchronous (blocking) API for USB device I/O.
33
- * This interface is easy to use but has some limitations. More advanced users
34
- * may wish to consider using the \ref asyncio "asynchronous I/O API" instead.
35
- */
36
-
37
- static void LIBUSB_CALL sync_transfer_cb(struct libusb_transfer *transfer)
38
- {
39
- int *completed = transfer->user_data;
40
- *completed = 1;
41
- usbi_dbg("actual_length=%d", transfer->actual_length);
42
- /* caller interprets result and frees transfer */
43
- }
44
-
45
- static void sync_transfer_wait_for_completion(struct libusb_transfer *transfer)
46
- {
47
- int r, *completed = transfer->user_data;
48
- struct libusb_context *ctx = HANDLE_CTX(transfer->dev_handle);
49
-
50
- while (!*completed) {
51
- r = libusb_handle_events_completed(ctx, completed);
52
- if (r < 0) {
53
- if (r == LIBUSB_ERROR_INTERRUPTED)
54
- continue;
55
- usbi_err(ctx, "libusb_handle_events failed: %s, cancelling transfer and retrying",
56
- libusb_error_name(r));
57
- libusb_cancel_transfer(transfer);
58
- continue;
59
- }
60
- }
61
- }
62
-
63
- /** \ingroup syncio
64
- * Perform a USB control transfer.
65
- *
66
- * The direction of the transfer is inferred from the bmRequestType field of
67
- * the setup packet.
68
- *
69
- * The wValue, wIndex and wLength fields values should be given in host-endian
70
- * byte order.
71
- *
72
- * \param dev_handle a handle for the device to communicate with
73
- * \param bmRequestType the request type field for the setup packet
74
- * \param bRequest the request field for the setup packet
75
- * \param wValue the value field for the setup packet
76
- * \param wIndex the index field for the setup packet
77
- * \param data a suitably-sized data buffer for either input or output
78
- * (depending on direction bits within bmRequestType)
79
- * \param wLength the length field for the setup packet. The data buffer should
80
- * be at least this size.
81
- * \param timeout timeout (in millseconds) that this function should wait
82
- * before giving up due to no response being received. For an unlimited
83
- * timeout, use value 0.
84
- * \returns on success, the number of bytes actually transferred
85
- * \returns LIBUSB_ERROR_TIMEOUT if the transfer timed out
86
- * \returns LIBUSB_ERROR_PIPE if the control request was not supported by the
87
- * device
88
- * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
89
- * \returns another LIBUSB_ERROR code on other failures
90
- */
91
- int API_EXPORTED libusb_control_transfer(libusb_device_handle *dev_handle,
92
- uint8_t bmRequestType, uint8_t bRequest, uint16_t wValue, uint16_t wIndex,
93
- unsigned char *data, uint16_t wLength, unsigned int timeout)
94
- {
95
- struct libusb_transfer *transfer = libusb_alloc_transfer(0);
96
- unsigned char *buffer;
97
- int completed = 0;
98
- int r;
99
-
100
- if (!transfer)
101
- return LIBUSB_ERROR_NO_MEM;
102
-
103
- buffer = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + wLength);
104
- if (!buffer) {
105
- libusb_free_transfer(transfer);
106
- return LIBUSB_ERROR_NO_MEM;
107
- }
108
-
109
- libusb_fill_control_setup(buffer, bmRequestType, bRequest, wValue, wIndex,
110
- wLength);
111
- if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_OUT)
112
- memcpy(buffer + LIBUSB_CONTROL_SETUP_SIZE, data, wLength);
113
-
114
- libusb_fill_control_transfer(transfer, dev_handle, buffer,
115
- sync_transfer_cb, &completed, timeout);
116
- transfer->flags = LIBUSB_TRANSFER_FREE_BUFFER;
117
- r = libusb_submit_transfer(transfer);
118
- if (r < 0) {
119
- libusb_free_transfer(transfer);
120
- return r;
121
- }
122
-
123
- sync_transfer_wait_for_completion(transfer);
124
-
125
- if ((bmRequestType & LIBUSB_ENDPOINT_DIR_MASK) == LIBUSB_ENDPOINT_IN)
126
- memcpy(data, libusb_control_transfer_get_data(transfer),
127
- transfer->actual_length);
128
-
129
- switch (transfer->status) {
130
- case LIBUSB_TRANSFER_COMPLETED:
131
- r = transfer->actual_length;
132
- break;
133
- case LIBUSB_TRANSFER_TIMED_OUT:
134
- r = LIBUSB_ERROR_TIMEOUT;
135
- break;
136
- case LIBUSB_TRANSFER_STALL:
137
- r = LIBUSB_ERROR_PIPE;
138
- break;
139
- case LIBUSB_TRANSFER_NO_DEVICE:
140
- r = LIBUSB_ERROR_NO_DEVICE;
141
- break;
142
- case LIBUSB_TRANSFER_OVERFLOW:
143
- r = LIBUSB_ERROR_OVERFLOW;
144
- break;
145
- case LIBUSB_TRANSFER_ERROR:
146
- case LIBUSB_TRANSFER_CANCELLED:
147
- r = LIBUSB_ERROR_IO;
148
- break;
149
- default:
150
- usbi_warn(HANDLE_CTX(dev_handle),
151
- "unrecognised status code %d", transfer->status);
152
- r = LIBUSB_ERROR_OTHER;
153
- }
154
-
155
- libusb_free_transfer(transfer);
156
- return r;
157
- }
158
-
159
- static int do_sync_bulk_transfer(struct libusb_device_handle *dev_handle,
160
- unsigned char endpoint, unsigned char *buffer, int length,
161
- int *transferred, unsigned int timeout, unsigned char type)
162
- {
163
- struct libusb_transfer *transfer = libusb_alloc_transfer(0);
164
- int completed = 0;
165
- int r;
166
-
167
- if (!transfer)
168
- return LIBUSB_ERROR_NO_MEM;
169
-
170
- libusb_fill_bulk_transfer(transfer, dev_handle, endpoint, buffer, length,
171
- sync_transfer_cb, &completed, timeout);
172
- transfer->type = type;
173
-
174
- r = libusb_submit_transfer(transfer);
175
- if (r < 0) {
176
- libusb_free_transfer(transfer);
177
- return r;
178
- }
179
-
180
- sync_transfer_wait_for_completion(transfer);
181
-
182
- *transferred = transfer->actual_length;
183
- switch (transfer->status) {
184
- case LIBUSB_TRANSFER_COMPLETED:
185
- r = 0;
186
- break;
187
- case LIBUSB_TRANSFER_TIMED_OUT:
188
- r = LIBUSB_ERROR_TIMEOUT;
189
- break;
190
- case LIBUSB_TRANSFER_STALL:
191
- r = LIBUSB_ERROR_PIPE;
192
- break;
193
- case LIBUSB_TRANSFER_OVERFLOW:
194
- r = LIBUSB_ERROR_OVERFLOW;
195
- break;
196
- case LIBUSB_TRANSFER_NO_DEVICE:
197
- r = LIBUSB_ERROR_NO_DEVICE;
198
- break;
199
- case LIBUSB_TRANSFER_ERROR:
200
- case LIBUSB_TRANSFER_CANCELLED:
201
- r = LIBUSB_ERROR_IO;
202
- break;
203
- default:
204
- usbi_warn(HANDLE_CTX(dev_handle),
205
- "unrecognised status code %d", transfer->status);
206
- r = LIBUSB_ERROR_OTHER;
207
- }
208
-
209
- libusb_free_transfer(transfer);
210
- return r;
211
- }
212
-
213
- /** \ingroup syncio
214
- * Perform a USB bulk transfer. The direction of the transfer is inferred from
215
- * the direction bits of the endpoint address.
216
- *
217
- * For bulk reads, the <tt>length</tt> field indicates the maximum length of
218
- * data you are expecting to receive. If less data arrives than expected,
219
- * this function will return that data, so be sure to check the
220
- * <tt>transferred</tt> output parameter.
221
- *
222
- * You should also check the <tt>transferred</tt> parameter for bulk writes.
223
- * Not all of the data may have been written.
224
- *
225
- * Also check <tt>transferred</tt> when dealing with a timeout error code.
226
- * libusb may have to split your transfer into a number of chunks to satisfy
227
- * underlying O/S requirements, meaning that the timeout may expire after
228
- * the first few chunks have completed. libusb is careful not to lose any data
229
- * that may have been transferred; do not assume that timeout conditions
230
- * indicate a complete lack of I/O.
231
- *
232
- * \param dev_handle a handle for the device to communicate with
233
- * \param endpoint the address of a valid endpoint to communicate with
234
- * \param data a suitably-sized data buffer for either input or output
235
- * (depending on endpoint)
236
- * \param length for bulk writes, the number of bytes from data to be sent. for
237
- * bulk reads, the maximum number of bytes to receive into the data buffer.
238
- * \param transferred output location for the number of bytes actually
239
- * transferred.
240
- * \param timeout timeout (in millseconds) that this function should wait
241
- * before giving up due to no response being received. For an unlimited
242
- * timeout, use value 0.
243
- *
244
- * \returns 0 on success (and populates <tt>transferred</tt>)
245
- * \returns LIBUSB_ERROR_TIMEOUT if the transfer timed out (and populates
246
- * <tt>transferred</tt>)
247
- * \returns LIBUSB_ERROR_PIPE if the endpoint halted
248
- * \returns LIBUSB_ERROR_OVERFLOW if the device offered more data, see
249
- * \ref packetoverflow
250
- * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
251
- * \returns another LIBUSB_ERROR code on other failures
252
- */
253
- int API_EXPORTED libusb_bulk_transfer(struct libusb_device_handle *dev_handle,
254
- unsigned char endpoint, unsigned char *data, int length, int *transferred,
255
- unsigned int timeout)
256
- {
257
- return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
258
- transferred, timeout, LIBUSB_TRANSFER_TYPE_BULK);
259
- }
260
-
261
- /** \ingroup syncio
262
- * Perform a USB interrupt transfer. The direction of the transfer is inferred
263
- * from the direction bits of the endpoint address.
264
- *
265
- * For interrupt reads, the <tt>length</tt> field indicates the maximum length
266
- * of data you are expecting to receive. If less data arrives than expected,
267
- * this function will return that data, so be sure to check the
268
- * <tt>transferred</tt> output parameter.
269
- *
270
- * You should also check the <tt>transferred</tt> parameter for interrupt
271
- * writes. Not all of the data may have been written.
272
- *
273
- * Also check <tt>transferred</tt> when dealing with a timeout error code.
274
- * libusb may have to split your transfer into a number of chunks to satisfy
275
- * underlying O/S requirements, meaning that the timeout may expire after
276
- * the first few chunks have completed. libusb is careful not to lose any data
277
- * that may have been transferred; do not assume that timeout conditions
278
- * indicate a complete lack of I/O.
279
- *
280
- * The default endpoint bInterval value is used as the polling interval.
281
- *
282
- * \param dev_handle a handle for the device to communicate with
283
- * \param endpoint the address of a valid endpoint to communicate with
284
- * \param data a suitably-sized data buffer for either input or output
285
- * (depending on endpoint)
286
- * \param length for bulk writes, the number of bytes from data to be sent. for
287
- * bulk reads, the maximum number of bytes to receive into the data buffer.
288
- * \param transferred output location for the number of bytes actually
289
- * transferred.
290
- * \param timeout timeout (in millseconds) that this function should wait
291
- * before giving up due to no response being received. For an unlimited
292
- * timeout, use value 0.
293
- *
294
- * \returns 0 on success (and populates <tt>transferred</tt>)
295
- * \returns LIBUSB_ERROR_TIMEOUT if the transfer timed out
296
- * \returns LIBUSB_ERROR_PIPE if the endpoint halted
297
- * \returns LIBUSB_ERROR_OVERFLOW if the device offered more data, see
298
- * \ref packetoverflow
299
- * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected
300
- * \returns another LIBUSB_ERROR code on other error
301
- */
302
- int API_EXPORTED libusb_interrupt_transfer(
303
- struct libusb_device_handle *dev_handle, unsigned char endpoint,
304
- unsigned char *data, int length, int *transferred, unsigned int timeout)
305
- {
306
- return do_sync_bulk_transfer(dev_handle, endpoint, data, length,
307
- transferred, timeout, LIBUSB_TRANSFER_TYPE_INTERRUPT);
308
- }