usb 1.7.2 → 1.8.1-libusb.4

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 (188) hide show
  1. package/.gitmodules +1 -1
  2. package/Readme.md +2 -2
  3. package/binding.gyp +2 -2
  4. package/libusb/.private/pre-commit.sh +7 -1
  5. package/libusb/.travis.yml +49 -0
  6. package/libusb/AUTHORS +44 -3
  7. package/libusb/Brewfile +4 -0
  8. package/libusb/ChangeLog +74 -2
  9. package/libusb/README.md +32 -0
  10. package/libusb/TODO +1 -1
  11. package/libusb/Xcode/common.xcconfig +12 -0
  12. package/libusb/Xcode/config.h +25 -0
  13. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +959 -1
  14. package/libusb/android/README +4 -2
  15. package/libusb/android/config.h +75 -0
  16. package/libusb/appveyor.yml +41 -0
  17. package/libusb/appveyor_cygwin.bat +11 -0
  18. package/libusb/appveyor_minGW.bat +19 -0
  19. package/libusb/autogen.sh +1 -1
  20. package/libusb/bootstrap.sh +3 -16
  21. package/libusb/configure.ac +108 -80
  22. package/libusb/doc/doxygen.cfg.in +1785 -739
  23. package/libusb/examples/Makefile.am +1 -1
  24. package/libusb/examples/dpfp.c +3 -1
  25. package/libusb/examples/dpfp_threaded.c +23 -10
  26. package/libusb/examples/ezusb.c +3 -3
  27. package/libusb/examples/ezusb.h +2 -2
  28. package/libusb/examples/fxload.c +31 -9
  29. package/libusb/examples/hotplugtest.c +35 -7
  30. package/libusb/examples/listdevs.c +3 -1
  31. package/libusb/examples/sam3u_benchmark.c +3 -3
  32. package/libusb/examples/testlibusb.c +277 -0
  33. package/libusb/examples/xusb.c +40 -34
  34. package/libusb/libusb/Makefile.am +49 -23
  35. package/libusb/libusb/core.c +855 -457
  36. package/libusb/libusb/descriptor.c +72 -78
  37. package/libusb/libusb/hotplug.c +122 -76
  38. package/libusb/libusb/hotplug.h +42 -25
  39. package/libusb/libusb/io.c +625 -390
  40. package/libusb/libusb/libusb-1.0.def +12 -0
  41. package/libusb/libusb/libusb.h +218 -150
  42. package/libusb/libusb/libusbi.h +346 -176
  43. package/libusb/libusb/os/darwin_usb.c +604 -319
  44. package/libusb/libusb/os/darwin_usb.h +61 -20
  45. package/libusb/libusb/os/haiku_pollfs.cpp +367 -0
  46. package/libusb/libusb/os/haiku_usb.h +113 -0
  47. package/libusb/libusb/os/haiku_usb_backend.cpp +533 -0
  48. package/libusb/libusb/os/haiku_usb_raw.cpp +267 -0
  49. package/libusb/libusb/os/haiku_usb_raw.h +188 -0
  50. package/libusb/libusb/os/linux_netlink.c +186 -146
  51. package/libusb/libusb/os/linux_udev.c +36 -14
  52. package/libusb/libusb/os/linux_usbfs.c +426 -225
  53. package/libusb/libusb/os/linux_usbfs.h +5 -3
  54. package/libusb/libusb/os/netbsd_usb.c +21 -77
  55. package/libusb/libusb/os/openbsd_usb.c +32 -115
  56. package/libusb/libusb/os/poll_posix.c +38 -5
  57. package/libusb/libusb/os/poll_posix.h +3 -0
  58. package/libusb/libusb/os/poll_windows.c +277 -626
  59. package/libusb/libusb/os/poll_windows.h +11 -44
  60. package/libusb/libusb/os/sunos_usb.c +1695 -0
  61. package/libusb/libusb/os/sunos_usb.h +80 -0
  62. package/libusb/libusb/os/threads_posix.c +24 -26
  63. package/libusb/libusb/os/threads_posix.h +73 -21
  64. package/libusb/libusb/os/threads_windows.c +71 -157
  65. package/libusb/libusb/os/threads_windows.h +68 -44
  66. package/libusb/libusb/os/wince_usb.c +276 -420
  67. package/libusb/libusb/os/wince_usb.h +23 -28
  68. package/libusb/libusb/os/windows_common.h +78 -58
  69. package/libusb/libusb/os/windows_nt_common.c +1010 -0
  70. package/libusb/libusb/os/windows_nt_common.h +110 -0
  71. package/libusb/libusb/os/windows_nt_shared_types.h +147 -0
  72. package/libusb/libusb/os/windows_usbdk.c +830 -0
  73. package/libusb/libusb/os/windows_usbdk.h +103 -0
  74. package/libusb/libusb/os/windows_winusb.c +4391 -0
  75. package/libusb/libusb/os/windows_winusb.h +783 -0
  76. package/libusb/libusb/strerror.c +41 -7
  77. package/libusb/libusb/sync.c +41 -13
  78. package/libusb/libusb/version.h +1 -1
  79. package/libusb/libusb/version_nano.h +1 -1
  80. package/libusb/libusb-1.0.pc.in +1 -1
  81. package/libusb/msvc/appveyor.bat +27 -0
  82. package/libusb/msvc/config.h +5 -4
  83. package/libusb/msvc/ddk_build.cmd +87 -43
  84. package/libusb/msvc/fxload_2010.vcxproj +24 -104
  85. package/libusb/msvc/fxload_2012.vcxproj +24 -107
  86. package/libusb/msvc/fxload_2013.vcxproj +24 -107
  87. package/libusb/msvc/fxload_2015.vcxproj +91 -0
  88. package/libusb/msvc/fxload_2017.vcxproj +114 -0
  89. package/libusb/msvc/fxload_sources +1 -1
  90. package/libusb/msvc/getopt_2010.vcxproj +16 -75
  91. package/libusb/msvc/getopt_2012.vcxproj +16 -79
  92. package/libusb/msvc/getopt_2013.vcxproj +16 -79
  93. package/libusb/msvc/getopt_2015.vcxproj +73 -0
  94. package/libusb/msvc/getopt_2017.vcxproj +98 -0
  95. package/libusb/msvc/getopt_sources +6 -2
  96. package/libusb/msvc/hotplugtest_2010.vcxproj +18 -99
  97. package/libusb/msvc/hotplugtest_2012.vcxproj +18 -102
  98. package/libusb/msvc/hotplugtest_2013.vcxproj +18 -102
  99. package/libusb/msvc/hotplugtest_2015.vcxproj +83 -0
  100. package/libusb/msvc/hotplugtest_2017.vcxproj +106 -0
  101. package/libusb/msvc/hotplugtest_sources +1 -1
  102. package/libusb/msvc/libusb_2005.sln +20 -20
  103. package/libusb/msvc/libusb_2010.sln +57 -46
  104. package/libusb/msvc/libusb_2012.sln +57 -46
  105. package/libusb/msvc/libusb_2013.sln +57 -50
  106. package/libusb/msvc/libusb_2015.sln +59 -52
  107. package/libusb/msvc/libusb_2017.sln +186 -0
  108. package/libusb/msvc/libusb_dll.dsp +2 -2
  109. package/libusb/msvc/libusb_dll_2005.vcproj +30 -2
  110. package/libusb/msvc/libusb_dll_2010.vcxproj +26 -90
  111. package/libusb/msvc/libusb_dll_2012.vcxproj +28 -96
  112. package/libusb/msvc/libusb_dll_2013.vcxproj +28 -96
  113. package/libusb/msvc/libusb_dll_2015.vcxproj +107 -0
  114. package/libusb/msvc/libusb_dll_2017.vcxproj +134 -0
  115. package/libusb/msvc/libusb_dll_wince.vcproj +9 -1
  116. package/libusb/msvc/libusb_sources +10 -5
  117. package/libusb/msvc/libusb_static.dsp +2 -2
  118. package/libusb/msvc/libusb_static_2005.vcproj +32 -4
  119. package/libusb/msvc/libusb_static_2010.vcxproj +24 -83
  120. package/libusb/msvc/libusb_static_2012.vcxproj +25 -87
  121. package/libusb/msvc/libusb_static_2013.vcxproj +25 -87
  122. package/libusb/msvc/libusb_static_2015.vcxproj +98 -0
  123. package/libusb/msvc/libusb_static_2017.vcxproj +117 -0
  124. package/libusb/msvc/libusb_static_wince.vcproj +20 -26
  125. package/libusb/msvc/libusb_wince.sln +88 -88
  126. package/libusb/msvc/listdevs_2010.vcxproj +16 -99
  127. package/libusb/msvc/listdevs_2012.vcxproj +16 -102
  128. package/libusb/msvc/listdevs_2013.vcxproj +16 -102
  129. package/libusb/msvc/listdevs_2015.vcxproj +83 -0
  130. package/libusb/msvc/listdevs_2017.vcxproj +106 -0
  131. package/libusb/msvc/listdevs_sources +2 -1
  132. package/libusb/msvc/stress_2010.vcxproj +20 -101
  133. package/libusb/msvc/stress_2012.vcxproj +20 -104
  134. package/libusb/msvc/stress_2013.vcxproj +20 -104
  135. package/libusb/msvc/stress_2015.vcxproj +87 -0
  136. package/libusb/msvc/stress_2017.vcxproj +110 -0
  137. package/libusb/msvc/stress_sources +21 -0
  138. package/libusb/msvc/testlibusb_2010.vcxproj +82 -0
  139. package/libusb/msvc/testlibusb_2012.vcxproj +83 -0
  140. package/libusb/msvc/testlibusb_2013.vcxproj +83 -0
  141. package/libusb/msvc/testlibusb_2015.vcxproj +83 -0
  142. package/libusb/msvc/testlibusb_2017.vcxproj +106 -0
  143. package/libusb/msvc/testlibusb_sources +20 -0
  144. package/libusb/msvc/xusb_2010.vcxproj +17 -98
  145. package/libusb/msvc/xusb_2012.vcxproj +17 -101
  146. package/libusb/msvc/xusb_2013.vcxproj +17 -101
  147. package/libusb/msvc/xusb_2015.vcxproj +83 -0
  148. package/libusb/msvc/xusb_2017.vcxproj +106 -0
  149. package/libusb/msvc/xusb_sources +1 -1
  150. package/libusb/tests/stress.c +2 -2
  151. package/libusb/tests/testlib.c +0 -4
  152. package/libusb/travis-autogen.sh +39 -0
  153. package/libusb.gypi +13 -2
  154. package/package.json +20 -11
  155. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  156. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  157. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  158. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  159. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  160. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  161. package/prebuilds/linux-ia32/node.napi.node +0 -0
  162. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  163. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  164. package/prebuilds/win32-ia32/node.napi.node +0 -0
  165. package/prebuilds/win32-x64/node.napi.node +0 -0
  166. package/src/device.cc +1 -1
  167. package/usb.js +51 -5
  168. package/.github/workflows/prebuild.yml +0 -49
  169. package/libusb/INSTALL +0 -234
  170. package/libusb/README +0 -28
  171. package/libusb/libusb/os/windows_usb.c +0 -5347
  172. package/libusb/libusb/os/windows_usb.h +0 -971
  173. package/libusb/msvc/fxload_2010.vcxproj.filters +0 -25
  174. package/libusb/msvc/fxload_2012.vcxproj.filters +0 -25
  175. package/libusb/msvc/getopt_2010.vcxproj.filters +0 -26
  176. package/libusb/msvc/getopt_2012.vcxproj.filters +0 -26
  177. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +0 -14
  178. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +0 -14
  179. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +0 -81
  180. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +0 -84
  181. package/libusb/msvc/libusb_static_2010.vcxproj.filters +0 -74
  182. package/libusb/msvc/libusb_static_2012.vcxproj.filters +0 -74
  183. package/libusb/msvc/listdevs_2010.vcxproj.filters +0 -14
  184. package/libusb/msvc/listdevs_2012.vcxproj.filters +0 -14
  185. package/libusb/msvc/stress_2010.vcxproj.filters +0 -25
  186. package/libusb/msvc/stress_2012.vcxproj.filters +0 -25
  187. package/libusb/msvc/xusb_2010.vcxproj.filters +0 -14
  188. package/libusb/msvc/xusb_2012.vcxproj.filters +0 -14
@@ -19,6 +19,8 @@
19
19
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
  */
21
21
 
22
+ #include <config.h>
23
+
22
24
  #include <errno.h>
23
25
  #include <stdint.h>
24
26
  #include <stdlib.h>
@@ -33,7 +35,7 @@
33
35
  #define ENDPOINT_DESC_LENGTH 7
34
36
  #define ENDPOINT_AUDIO_DESC_LENGTH 9
35
37
 
36
- /** @defgroup desc USB descriptors
38
+ /** @defgroup libusb_desc USB descriptors
37
39
  * This page details how to examine the various standard USB descriptors
38
40
  * for detected devices
39
41
  */
@@ -60,7 +62,7 @@ int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
60
62
  if (host_endian) {
61
63
  memcpy(dp, sp, 2);
62
64
  } else {
63
- w = (sp[1] << 8) | sp[0];
65
+ w = (uint16_t)((sp[1] << 8) | sp[0]);
64
66
  *((uint16_t *)dp) = w;
65
67
  }
66
68
  sp += 2;
@@ -72,8 +74,8 @@ int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
72
74
  if (host_endian) {
73
75
  memcpy(dp, sp, 4);
74
76
  } else {
75
- d = (sp[3] << 24) | (sp[2] << 16) |
76
- (sp[1] << 8) | sp[0];
77
+ d = (uint32_t)((sp[3] << 24) | (sp[2] << 16) |
78
+ (sp[1] << 8) | sp[0]);
77
79
  *((uint32_t *)dp) = d;
78
80
  }
79
81
  sp += 4;
@@ -92,8 +94,7 @@ int usbi_parse_descriptor(const unsigned char *source, const char *descriptor,
92
94
 
93
95
  static void clear_endpoint(struct libusb_endpoint_descriptor *endpoint)
94
96
  {
95
- if (endpoint->extra)
96
- free((unsigned char *) endpoint->extra);
97
+ free((void *) endpoint->extra);
97
98
  }
98
99
 
99
100
  static int parse_endpoint(struct libusb_context *ctx,
@@ -167,13 +168,13 @@ static int parse_endpoint(struct libusb_context *ctx,
167
168
  /* Copy any unknown descriptors into a storage area for drivers */
168
169
  /* to later parse */
169
170
  len = (int)(buffer - begin);
170
- if (!len) {
171
+ if (len <= 0) {
171
172
  endpoint->extra = NULL;
172
173
  endpoint->extra_length = 0;
173
174
  return parsed;
174
175
  }
175
176
 
176
- extra = malloc(len);
177
+ extra = malloc((size_t)len);
177
178
  endpoint->extra = extra;
178
179
  if (!extra) {
179
180
  endpoint->extra_length = 0;
@@ -196,19 +197,17 @@ static void clear_interface(struct libusb_interface *usb_interface)
196
197
  struct libusb_interface_descriptor *ifp =
197
198
  (struct libusb_interface_descriptor *)
198
199
  usb_interface->altsetting + i;
199
- if (ifp->extra)
200
- free((void *) ifp->extra);
200
+ free((void *) ifp->extra);
201
201
  if (ifp->endpoint) {
202
202
  for (j = 0; j < ifp->bNumEndpoints; j++)
203
203
  clear_endpoint((struct libusb_endpoint_descriptor *)
204
- ifp->endpoint + j);
205
- free((void *) ifp->endpoint);
204
+ ifp->endpoint + j);
206
205
  }
206
+ free((void *) ifp->endpoint);
207
207
  }
208
- free((void *) usb_interface->altsetting);
209
- usb_interface->altsetting = NULL;
210
208
  }
211
-
209
+ free((void *) usb_interface->altsetting);
210
+ usb_interface->altsetting = NULL;
212
211
  }
213
212
 
214
213
  static int parse_interface(libusb_context *ctx,
@@ -220,7 +219,6 @@ static int parse_interface(libusb_context *ctx,
220
219
  int r;
221
220
  int parsed = 0;
222
221
  int interface_number = -1;
223
- size_t tmp;
224
222
  struct usb_descriptor_header header;
225
223
  struct libusb_interface_descriptor *ifp;
226
224
  unsigned char *begin;
@@ -232,7 +230,7 @@ static int parse_interface(libusb_context *ctx,
232
230
  (struct libusb_interface_descriptor *) usb_interface->altsetting;
233
231
  altsetting = usbi_reallocf(altsetting,
234
232
  sizeof(struct libusb_interface_descriptor) *
235
- (usb_interface->num_altsetting + 1));
233
+ ((size_t)usb_interface->num_altsetting + 1));
236
234
  if (!altsetting) {
237
235
  r = LIBUSB_ERROR_NO_MEM;
238
236
  goto err;
@@ -309,8 +307,8 @@ static int parse_interface(libusb_context *ctx,
309
307
  /* Copy any unknown descriptors into a storage area for */
310
308
  /* drivers to later parse */
311
309
  len = (int)(buffer - begin);
312
- if (len) {
313
- ifp->extra = malloc(len);
310
+ if (len > 0) {
311
+ ifp->extra = malloc((size_t)len);
314
312
  if (!ifp->extra) {
315
313
  r = LIBUSB_ERROR_NO_MEM;
316
314
  goto err;
@@ -321,15 +319,13 @@ static int parse_interface(libusb_context *ctx,
321
319
 
322
320
  if (ifp->bNumEndpoints > 0) {
323
321
  struct libusb_endpoint_descriptor *endpoint;
324
- tmp = ifp->bNumEndpoints * sizeof(struct libusb_endpoint_descriptor);
325
- endpoint = malloc(tmp);
322
+ endpoint = calloc(ifp->bNumEndpoints, sizeof(struct libusb_endpoint_descriptor));
326
323
  ifp->endpoint = endpoint;
327
324
  if (!endpoint) {
328
325
  r = LIBUSB_ERROR_NO_MEM;
329
326
  goto err;
330
327
  }
331
328
 
332
- memset(endpoint, 0, tmp);
333
329
  for (i = 0; i < ifp->bNumEndpoints; i++) {
334
330
  r = parse_endpoint(ctx, endpoint + i, buffer, size,
335
331
  host_endian);
@@ -337,7 +333,7 @@ static int parse_interface(libusb_context *ctx,
337
333
  goto err;
338
334
  if (r == 0) {
339
335
  ifp->bNumEndpoints = (uint8_t)i;
340
- break;;
336
+ break;
341
337
  }
342
338
 
343
339
  buffer += r;
@@ -362,15 +358,14 @@ err:
362
358
 
363
359
  static void clear_configuration(struct libusb_config_descriptor *config)
364
360
  {
361
+ int i;
365
362
  if (config->interface) {
366
- int i;
367
363
  for (i = 0; i < config->bNumInterfaces; i++)
368
364
  clear_interface((struct libusb_interface *)
369
- config->interface + i);
370
- free((void *) config->interface);
365
+ config->interface + i);
371
366
  }
372
- if (config->extra)
373
- free((void *) config->extra);
367
+ free((void *) config->interface);
368
+ free((void *) config->extra);
374
369
  }
375
370
 
376
371
  static int parse_configuration(struct libusb_context *ctx,
@@ -379,7 +374,6 @@ static int parse_configuration(struct libusb_context *ctx,
379
374
  {
380
375
  int i;
381
376
  int r;
382
- size_t tmp;
383
377
  struct usb_descriptor_header header;
384
378
  struct libusb_interface *usb_interface;
385
379
 
@@ -409,13 +403,11 @@ static int parse_configuration(struct libusb_context *ctx,
409
403
  return LIBUSB_ERROR_IO;
410
404
  }
411
405
 
412
- tmp = config->bNumInterfaces * sizeof(struct libusb_interface);
413
- usb_interface = malloc(tmp);
406
+ usb_interface = calloc(config->bNumInterfaces, sizeof(struct libusb_interface));
414
407
  config->interface = usb_interface;
415
- if (!config->interface)
408
+ if (!usb_interface)
416
409
  return LIBUSB_ERROR_NO_MEM;
417
410
 
418
- memset(usb_interface, 0, tmp);
419
411
  buffer += config->bLength;
420
412
  size -= config->bLength;
421
413
 
@@ -453,7 +445,7 @@ static int parse_configuration(struct libusb_context *ctx,
453
445
  (header.bDescriptorType == LIBUSB_DT_DEVICE))
454
446
  break;
455
447
 
456
- usbi_dbg("skipping descriptor 0x%x\n", header.bDescriptorType);
448
+ usbi_dbg("skipping descriptor 0x%x", header.bDescriptorType);
457
449
  buffer += header.bLength;
458
450
  size -= header.bLength;
459
451
  }
@@ -461,10 +453,10 @@ static int parse_configuration(struct libusb_context *ctx,
461
453
  /* Copy any unknown descriptors into a storage area for */
462
454
  /* drivers to later parse */
463
455
  len = (int)(buffer - begin);
464
- if (len) {
456
+ if (len > 0) {
465
457
  /* FIXME: We should realloc and append here */
466
458
  if (!config->extra_length) {
467
- config->extra = malloc(len);
459
+ config->extra = malloc((size_t)len);
468
460
  if (!config->extra) {
469
461
  r = LIBUSB_ERROR_NO_MEM;
470
462
  goto err;
@@ -500,7 +492,7 @@ static int raw_desc_to_config(struct libusb_context *ctx,
500
492
  {
501
493
  struct libusb_config_descriptor *_config = malloc(sizeof(*_config));
502
494
  int r;
503
-
495
+
504
496
  if (!_config)
505
497
  return LIBUSB_ERROR_NO_MEM;
506
498
 
@@ -512,7 +504,7 @@ static int raw_desc_to_config(struct libusb_context *ctx,
512
504
  } else if (r > 0) {
513
505
  usbi_warn(ctx, "still %d bytes of descriptor data left", r);
514
506
  }
515
-
507
+
516
508
  *config = _config;
517
509
  return LIBUSB_SUCCESS;
518
510
  }
@@ -521,7 +513,7 @@ int usbi_device_cache_descriptor(libusb_device *dev)
521
513
  {
522
514
  int r, host_endian = 0;
523
515
 
524
- r = usbi_backend->get_device_descriptor(dev, (unsigned char *) &dev->device_descriptor,
516
+ r = usbi_backend.get_device_descriptor(dev, (unsigned char *) &dev->device_descriptor,
525
517
  &host_endian);
526
518
  if (r < 0)
527
519
  return r;
@@ -536,7 +528,7 @@ int usbi_device_cache_descriptor(libusb_device *dev)
536
528
  return LIBUSB_SUCCESS;
537
529
  }
538
530
 
539
- /** \ingroup desc
531
+ /** \ingroup libusb_desc
540
532
  * Get the USB device descriptor for a given device.
541
533
  *
542
534
  * This is a non-blocking function; the device descriptor is cached in memory.
@@ -557,7 +549,7 @@ int API_EXPORTED libusb_get_device_descriptor(libusb_device *dev,
557
549
  return 0;
558
550
  }
559
551
 
560
- /** \ingroup desc
552
+ /** \ingroup libusb_desc
561
553
  * Get the USB configuration descriptor for the currently active configuration.
562
554
  * This is a non-blocking function which does not involve any requests being
563
555
  * sent to the device.
@@ -580,7 +572,7 @@ int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
580
572
  int host_endian = 0;
581
573
  int r;
582
574
 
583
- r = usbi_backend->get_active_config_descriptor(dev, tmp,
575
+ r = usbi_backend.get_active_config_descriptor(dev, tmp,
584
576
  LIBUSB_DT_CONFIG_SIZE, &host_endian);
585
577
  if (r < 0)
586
578
  return r;
@@ -595,7 +587,7 @@ int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
595
587
  if (!buf)
596
588
  return LIBUSB_ERROR_NO_MEM;
597
589
 
598
- r = usbi_backend->get_active_config_descriptor(dev, buf,
590
+ r = usbi_backend.get_active_config_descriptor(dev, buf,
599
591
  _config.wTotalLength, &host_endian);
600
592
  if (r >= 0)
601
593
  r = raw_desc_to_config(dev->ctx, buf, r, host_endian, config);
@@ -604,7 +596,7 @@ int API_EXPORTED libusb_get_active_config_descriptor(libusb_device *dev,
604
596
  return r;
605
597
  }
606
598
 
607
- /** \ingroup desc
599
+ /** \ingroup libusb_desc
608
600
  * Get a USB configuration descriptor based on its index.
609
601
  * This is a non-blocking function which does not involve any requests being
610
602
  * sent to the device.
@@ -633,7 +625,7 @@ int API_EXPORTED libusb_get_config_descriptor(libusb_device *dev,
633
625
  if (config_index >= dev->num_configurations)
634
626
  return LIBUSB_ERROR_NOT_FOUND;
635
627
 
636
- r = usbi_backend->get_config_descriptor(dev, config_index, tmp,
628
+ r = usbi_backend.get_config_descriptor(dev, config_index, tmp,
637
629
  LIBUSB_DT_CONFIG_SIZE, &host_endian);
638
630
  if (r < 0)
639
631
  return r;
@@ -648,7 +640,7 @@ int API_EXPORTED libusb_get_config_descriptor(libusb_device *dev,
648
640
  if (!buf)
649
641
  return LIBUSB_ERROR_NO_MEM;
650
642
 
651
- r = usbi_backend->get_config_descriptor(dev, config_index, buf,
643
+ r = usbi_backend.get_config_descriptor(dev, config_index, buf,
652
644
  _config.wTotalLength, &host_endian);
653
645
  if (r >= 0)
654
646
  r = raw_desc_to_config(dev->ctx, buf, r, host_endian, config);
@@ -671,7 +663,7 @@ int usbi_get_config_index_by_value(struct libusb_device *dev,
671
663
  for (i = 0; i < dev->num_configurations; i++) {
672
664
  unsigned char tmp[6];
673
665
  int host_endian;
674
- int r = usbi_backend->get_config_descriptor(dev, i, tmp, sizeof(tmp),
666
+ int r = usbi_backend.get_config_descriptor(dev, i, tmp, sizeof(tmp),
675
667
  &host_endian);
676
668
  if (r < 0) {
677
669
  *idx = -1;
@@ -687,7 +679,7 @@ int usbi_get_config_index_by_value(struct libusb_device *dev,
687
679
  return 0;
688
680
  }
689
681
 
690
- /** \ingroup desc
682
+ /** \ingroup libusb_desc
691
683
  * Get a USB configuration descriptor with a specific bConfigurationValue.
692
684
  * This is a non-blocking function which does not involve any requests being
693
685
  * sent to the device.
@@ -710,8 +702,8 @@ int API_EXPORTED libusb_get_config_descriptor_by_value(libusb_device *dev,
710
702
  int r, idx, host_endian;
711
703
  unsigned char *buf = NULL;
712
704
 
713
- if (usbi_backend->get_config_descriptor_by_value) {
714
- r = usbi_backend->get_config_descriptor_by_value(dev,
705
+ if (usbi_backend.get_config_descriptor_by_value) {
706
+ r = usbi_backend.get_config_descriptor_by_value(dev,
715
707
  bConfigurationValue, &buf, &host_endian);
716
708
  if (r < 0)
717
709
  return r;
@@ -727,7 +719,7 @@ int API_EXPORTED libusb_get_config_descriptor_by_value(libusb_device *dev,
727
719
  return libusb_get_config_descriptor(dev, (uint8_t) idx, config);
728
720
  }
729
721
 
730
- /** \ingroup desc
722
+ /** \ingroup libusb_desc
731
723
  * Free a configuration descriptor obtained from
732
724
  * libusb_get_active_config_descriptor() or libusb_get_config_descriptor().
733
725
  * It is safe to call this function with a NULL config parameter, in which
@@ -745,7 +737,7 @@ void API_EXPORTED libusb_free_config_descriptor(
745
737
  free(config);
746
738
  }
747
739
 
748
- /** \ingroup desc
740
+ /** \ingroup libusb_desc
749
741
  * Get an endpoints superspeed endpoint companion descriptor (if any)
750
742
  *
751
743
  * \param ctx the context to operate on, or NULL for the default context
@@ -795,7 +787,7 @@ int API_EXPORTED libusb_get_ss_endpoint_companion_descriptor(
795
787
  return LIBUSB_ERROR_NOT_FOUND;
796
788
  }
797
789
 
798
- /** \ingroup desc
790
+ /** \ingroup libusb_desc
799
791
  * Free a superspeed endpoint companion descriptor obtained from
800
792
  * libusb_get_ss_endpoint_companion_descriptor().
801
793
  * It is safe to call this function with a NULL ep_comp parameter, in which
@@ -888,18 +880,18 @@ static int parse_bos(struct libusb_context *ctx,
888
880
  return LIBUSB_SUCCESS;
889
881
  }
890
882
 
891
- /** \ingroup desc
883
+ /** \ingroup libusb_desc
892
884
  * Get a Binary Object Store (BOS) descriptor
893
885
  * This is a BLOCKING function, which will send requests to the device.
894
886
  *
895
- * \param handle the handle of an open libusb device
887
+ * \param dev_handle the handle of an open libusb device
896
888
  * \param bos output location for the BOS descriptor. Only valid if 0 was returned.
897
889
  * Must be freed with \ref libusb_free_bos_descriptor() after use.
898
890
  * \returns 0 on success
899
891
  * \returns LIBUSB_ERROR_NOT_FOUND if the device doesn't have a BOS descriptor
900
892
  * \returns another LIBUSB_ERROR code on error
901
893
  */
902
- int API_EXPORTED libusb_get_bos_descriptor(libusb_device_handle *handle,
894
+ int API_EXPORTED libusb_get_bos_descriptor(libusb_device_handle *dev_handle,
903
895
  struct libusb_bos_descriptor **bos)
904
896
  {
905
897
  struct libusb_bos_descriptor _bos;
@@ -910,15 +902,15 @@ int API_EXPORTED libusb_get_bos_descriptor(libusb_device_handle *handle,
910
902
 
911
903
  /* Read the BOS. This generates 2 requests on the bus,
912
904
  * one for the header, and one for the full BOS */
913
- r = libusb_get_descriptor(handle, LIBUSB_DT_BOS, 0, bos_header,
905
+ r = libusb_get_descriptor(dev_handle, LIBUSB_DT_BOS, 0, bos_header,
914
906
  LIBUSB_DT_BOS_SIZE);
915
907
  if (r < 0) {
916
908
  if (r != LIBUSB_ERROR_PIPE)
917
- usbi_err(handle->dev->ctx, "failed to read BOS (%d)", r);
909
+ usbi_err(HANDLE_CTX(dev_handle), "failed to read BOS (%d)", r);
918
910
  return r;
919
911
  }
920
912
  if (r < LIBUSB_DT_BOS_SIZE) {
921
- usbi_err(handle->dev->ctx, "short BOS read %d/%d",
913
+ usbi_err(HANDLE_CTX(dev_handle), "short BOS read %d/%d",
922
914
  r, LIBUSB_DT_BOS_SIZE);
923
915
  return LIBUSB_ERROR_IO;
924
916
  }
@@ -930,18 +922,18 @@ int API_EXPORTED libusb_get_bos_descriptor(libusb_device_handle *handle,
930
922
  if (bos_data == NULL)
931
923
  return LIBUSB_ERROR_NO_MEM;
932
924
 
933
- r = libusb_get_descriptor(handle, LIBUSB_DT_BOS, 0, bos_data,
925
+ r = libusb_get_descriptor(dev_handle, LIBUSB_DT_BOS, 0, bos_data,
934
926
  _bos.wTotalLength);
935
927
  if (r >= 0)
936
- r = parse_bos(handle->dev->ctx, bos, bos_data, r, host_endian);
928
+ r = parse_bos(HANDLE_CTX(dev_handle), bos, bos_data, r, host_endian);
937
929
  else
938
- usbi_err(handle->dev->ctx, "failed to read BOS (%d)", r);
930
+ usbi_err(HANDLE_CTX(dev_handle), "failed to read BOS (%d)", r);
939
931
 
940
932
  free(bos_data);
941
933
  return r;
942
934
  }
943
935
 
944
- /** \ingroup desc
936
+ /** \ingroup libusb_desc
945
937
  * Free a BOS descriptor obtained from libusb_get_bos_descriptor().
946
938
  * It is safe to call this function with a NULL bos parameter, in which
947
939
  * case the function simply returns.
@@ -960,7 +952,7 @@ void API_EXPORTED libusb_free_bos_descriptor(struct libusb_bos_descriptor *bos)
960
952
  free(bos);
961
953
  }
962
954
 
963
- /** \ingroup desc
955
+ /** \ingroup libusb_desc
964
956
  * Get an USB 2.0 Extension descriptor
965
957
  *
966
958
  * \param ctx the context to operate on, or NULL for the default context
@@ -1004,7 +996,7 @@ int API_EXPORTED libusb_get_usb_2_0_extension_descriptor(
1004
996
  return LIBUSB_SUCCESS;
1005
997
  }
1006
998
 
1007
- /** \ingroup desc
999
+ /** \ingroup libusb_desc
1008
1000
  * Free a USB 2.0 Extension descriptor obtained from
1009
1001
  * libusb_get_usb_2_0_extension_descriptor().
1010
1002
  * It is safe to call this function with a NULL usb_2_0_extension parameter,
@@ -1018,7 +1010,7 @@ void API_EXPORTED libusb_free_usb_2_0_extension_descriptor(
1018
1010
  free(usb_2_0_extension);
1019
1011
  }
1020
1012
 
1021
- /** \ingroup desc
1013
+ /** \ingroup libusb_desc
1022
1014
  * Get a SuperSpeed USB Device Capability descriptor
1023
1015
  *
1024
1016
  * \param ctx the context to operate on, or NULL for the default context
@@ -1062,13 +1054,14 @@ int API_EXPORTED libusb_get_ss_usb_device_capability_descriptor(
1062
1054
  return LIBUSB_SUCCESS;
1063
1055
  }
1064
1056
 
1065
- /** \ingroup desc
1057
+ /** \ingroup libusb_desc
1066
1058
  * Free a SuperSpeed USB Device Capability descriptor obtained from
1067
1059
  * libusb_get_ss_usb_device_capability_descriptor().
1068
1060
  * It is safe to call this function with a NULL ss_usb_device_cap
1069
1061
  * parameter, in which case the function simply returns.
1070
1062
  *
1071
- * \param ss_usb_device_cap the USB 2.0 Extension descriptor to free
1063
+ * \param ss_usb_device_cap the SuperSpeed USB Device Capability descriptor
1064
+ * to free
1072
1065
  */
1073
1066
  void API_EXPORTED libusb_free_ss_usb_device_capability_descriptor(
1074
1067
  struct libusb_ss_usb_device_capability_descriptor *ss_usb_device_cap)
@@ -1076,7 +1069,7 @@ void API_EXPORTED libusb_free_ss_usb_device_capability_descriptor(
1076
1069
  free(ss_usb_device_cap);
1077
1070
  }
1078
1071
 
1079
- /** \ingroup desc
1072
+ /** \ingroup libusb_desc
1080
1073
  * Get a Container ID descriptor
1081
1074
  *
1082
1075
  * \param ctx the context to operate on, or NULL for the default context
@@ -1119,13 +1112,13 @@ int API_EXPORTED libusb_get_container_id_descriptor(struct libusb_context *ctx,
1119
1112
  return LIBUSB_SUCCESS;
1120
1113
  }
1121
1114
 
1122
- /** \ingroup desc
1115
+ /** \ingroup libusb_desc
1123
1116
  * Free a Container ID descriptor obtained from
1124
1117
  * libusb_get_container_id_descriptor().
1125
1118
  * It is safe to call this function with a NULL container_id parameter,
1126
1119
  * in which case the function simply returns.
1127
1120
  *
1128
- * \param container_id the USB 2.0 Extension descriptor to free
1121
+ * \param container_id the Container ID descriptor to free
1129
1122
  */
1130
1123
  void API_EXPORTED libusb_free_container_id_descriptor(
1131
1124
  struct libusb_container_id_descriptor *container_id)
@@ -1133,19 +1126,19 @@ void API_EXPORTED libusb_free_container_id_descriptor(
1133
1126
  free(container_id);
1134
1127
  }
1135
1128
 
1136
- /** \ingroup desc
1129
+ /** \ingroup libusb_desc
1137
1130
  * Retrieve a string descriptor in C style ASCII.
1138
1131
  *
1139
1132
  * Wrapper around libusb_get_string_descriptor(). Uses the first language
1140
1133
  * supported by the device.
1141
1134
  *
1142
- * \param dev a device handle
1135
+ * \param dev_handle a device handle
1143
1136
  * \param desc_index the index of the descriptor to retrieve
1144
1137
  * \param data output buffer for ASCII string descriptor
1145
1138
  * \param length size of data buffer
1146
1139
  * \returns number of bytes returned in data, or LIBUSB_ERROR code on failure
1147
1140
  */
1148
- int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
1141
+ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev_handle,
1149
1142
  uint8_t desc_index, unsigned char *data, int length)
1150
1143
  {
1151
1144
  unsigned char tbuf[255]; /* Some devices choke on size > 255 */
@@ -1164,16 +1157,16 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
1164
1157
  if (desc_index == 0)
1165
1158
  return LIBUSB_ERROR_INVALID_PARAM;
1166
1159
 
1167
- r = libusb_get_string_descriptor(dev, 0, 0, tbuf, sizeof(tbuf));
1160
+ r = libusb_get_string_descriptor(dev_handle, 0, 0, tbuf, sizeof(tbuf));
1168
1161
  if (r < 0)
1169
1162
  return r;
1170
1163
 
1171
1164
  if (r < 4)
1172
1165
  return LIBUSB_ERROR_IO;
1173
1166
 
1174
- langid = tbuf[2] | (tbuf[3] << 8);
1167
+ langid = (uint16_t)(tbuf[2] | (tbuf[3] << 8));
1175
1168
 
1176
- r = libusb_get_string_descriptor(dev, desc_index, langid, tbuf,
1169
+ r = libusb_get_string_descriptor(dev_handle, desc_index, langid, tbuf,
1177
1170
  sizeof(tbuf));
1178
1171
  if (r < 0)
1179
1172
  return r;
@@ -1184,7 +1177,8 @@ int API_EXPORTED libusb_get_string_descriptor_ascii(libusb_device_handle *dev,
1184
1177
  if (tbuf[0] > r)
1185
1178
  return LIBUSB_ERROR_IO;
1186
1179
 
1187
- for (di = 0, si = 2; si < tbuf[0]; si += 2) {
1180
+ di = 0;
1181
+ for (si = 2; si < tbuf[0]; si += 2) {
1188
1182
  if (di >= (length - 1))
1189
1183
  break;
1190
1184