usb 2.12.1 → 2.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (222) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +1 -1
  3. package/dist/index.js +6 -2
  4. package/dist/index.js.map +1 -1
  5. package/dist/usb/bindings.js +1 -1
  6. package/dist/usb/bindings.js.map +1 -1
  7. package/dist/usb/capability.js.map +1 -1
  8. package/dist/usb/device.js.map +1 -1
  9. package/dist/usb/endpoint.d.ts +1 -0
  10. package/dist/usb/endpoint.js +2 -2
  11. package/dist/usb/endpoint.js.map +1 -1
  12. package/dist/usb/index.js.map +1 -1
  13. package/dist/usb/interface.js +2 -2
  14. package/dist/usb/interface.js.map +1 -1
  15. package/dist/webusb/index.d.ts +2 -2
  16. package/dist/webusb/index.js.map +1 -1
  17. package/dist/webusb/webusb-device.js +10 -10
  18. package/dist/webusb/webusb-device.js.map +1 -1
  19. package/libusb/.codespellrc +3 -0
  20. package/libusb/.private/appveyor_build.sh +5 -1
  21. package/libusb/.private/ci-build.sh +26 -1
  22. package/libusb/.private/ci-container-build.sh +2 -5
  23. package/libusb/.private/wbs.txt +5 -8
  24. package/libusb/AUTHORS +22 -0
  25. package/libusb/ChangeLog +19 -2
  26. package/libusb/HACKING +25 -0
  27. package/libusb/INSTALL_WIN.txt +11 -10
  28. package/libusb/NEWS +2 -2
  29. package/libusb/README +3 -2
  30. package/libusb/README.git +1 -1
  31. package/libusb/Xcode/common.xcconfig +8 -1
  32. package/libusb/Xcode/config.h +0 -6
  33. package/libusb/Xcode/debug.xcconfig +4 -1
  34. package/libusb/Xcode/libusb.xcconfig +1 -1
  35. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +60 -30
  36. package/libusb/Xcode/libusb_debug.xcconfig +1 -1
  37. package/libusb/Xcode/libusb_release.xcconfig +1 -1
  38. package/libusb/Xcode/release.xcconfig +1 -1
  39. package/libusb/appveyor.yml +33 -9
  40. package/libusb/configure.ac +68 -37
  41. package/libusb/examples/dpfp.c +2 -2
  42. package/libusb/examples/fxload.c +2 -2
  43. package/libusb/examples/hotplugtest.c +28 -13
  44. package/libusb/examples/listdevs.c +1 -1
  45. package/libusb/examples/sam3u_benchmark.c +1 -1
  46. package/libusb/examples/testlibusb.c +1 -1
  47. package/libusb/examples/xusb.c +74 -19
  48. package/libusb/libusb/Makefile.am +11 -1
  49. package/libusb/libusb/core.c +364 -186
  50. package/libusb/libusb/descriptor.c +276 -16
  51. package/libusb/libusb/hotplug.c +5 -4
  52. package/libusb/libusb/io.c +72 -61
  53. package/libusb/libusb/libusb-1.0.def +14 -1
  54. package/libusb/libusb/libusb.h +245 -76
  55. package/libusb/libusb/libusbi.h +35 -13
  56. package/libusb/libusb/os/darwin_usb.c +542 -279
  57. package/libusb/libusb/os/darwin_usb.h +44 -115
  58. package/libusb/libusb/os/emscripten_webusb.cpp +870 -0
  59. package/libusb/libusb/os/events_posix.c +40 -0
  60. package/libusb/libusb/os/events_posix.h +3 -0
  61. package/libusb/libusb/os/linux_usbfs.c +27 -16
  62. package/libusb/libusb/os/netbsd_usb.c +36 -36
  63. package/libusb/libusb/os/openbsd_usb.c +34 -34
  64. package/libusb/libusb/os/sunos_usb.c +25 -15
  65. package/libusb/libusb/os/threads_posix.c +1 -5
  66. package/libusb/libusb/os/windows_common.c +13 -5
  67. package/libusb/libusb/os/windows_common.h +8 -0
  68. package/libusb/libusb/os/windows_winusb.c +366 -174
  69. package/libusb/libusb/os/windows_winusb.h +13 -9
  70. package/libusb/libusb/strerror.c +5 -5
  71. package/libusb/libusb/sync.c +24 -19
  72. package/libusb/libusb/version.h +1 -1
  73. package/libusb/libusb/version_nano.h +1 -1
  74. package/libusb/msvc/Base.props +60 -0
  75. package/libusb/msvc/Configuration.Application.props +7 -0
  76. package/libusb/msvc/Configuration.Base.props +47 -0
  77. package/libusb/msvc/Configuration.DynamicLibrary.props +21 -0
  78. package/libusb/msvc/Configuration.StaticLibrary.props +7 -0
  79. package/libusb/msvc/ProjectConfigurations.Base.props +69 -0
  80. package/libusb/msvc/build_all.ps1 +17 -0
  81. package/libusb/msvc/config.h +2 -2
  82. package/libusb/msvc/dpfp.vcxproj +33 -0
  83. package/libusb/msvc/dpfp_threaded.vcxproj +38 -0
  84. package/libusb/msvc/fxload.vcxproj +46 -0
  85. package/libusb/msvc/getopt.vcxproj +33 -0
  86. package/libusb/msvc/hotplugtest.vcxproj +32 -0
  87. package/libusb/msvc/init_context.vcxproj +35 -0
  88. package/libusb/msvc/libusb.sln +542 -0
  89. package/libusb/msvc/libusb_dll.vcxproj +61 -0
  90. package/libusb/msvc/libusb_static.vcxproj +49 -0
  91. package/libusb/msvc/listdevs.vcxproj +32 -0
  92. package/libusb/msvc/sam3u_benchmark.vcxproj +33 -0
  93. package/libusb/msvc/set_option.vcxproj +35 -0
  94. package/libusb/msvc/stress.vcxproj +35 -0
  95. package/libusb/msvc/stress_mt.vcxproj +33 -0
  96. package/libusb/msvc/testlibusb.vcxproj +32 -0
  97. package/libusb/msvc/xusb.vcxproj +38 -0
  98. package/libusb/tests/Makefile.am +25 -3
  99. package/libusb/tests/init_context.c +153 -0
  100. package/libusb/tests/macos.c +130 -0
  101. package/libusb/tests/set_option.c +253 -0
  102. package/libusb/tests/stress.c +17 -14
  103. package/libusb/tests/stress_mt.c +265 -0
  104. package/libusb/tests/testlib.c +1 -1
  105. package/libusb/tests/umockdev.c +9 -9
  106. package/libusb/tests/webusb-test-shim/index.js +12 -0
  107. package/libusb/tests/webusb-test-shim/package-lock.json +50 -0
  108. package/libusb/tests/webusb-test-shim/package.json +10 -0
  109. package/package.json +7 -7
  110. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  111. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  112. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  113. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  114. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  115. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  116. package/prebuilds/linux-ia32/node.napi.node +0 -0
  117. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  118. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  119. package/prebuilds/win32-arm64/node.napi.node +0 -0
  120. package/prebuilds/win32-ia32/node.napi.node +0 -0
  121. package/prebuilds/win32-x64/node.napi.node +0 -0
  122. package/src/device.cc +15 -5
  123. package/libusb/msvc/dpfp_2013.vcxproj +0 -87
  124. package/libusb/msvc/dpfp_2013.vcxproj.filters +0 -26
  125. package/libusb/msvc/dpfp_2015.vcxproj +0 -87
  126. package/libusb/msvc/dpfp_2015.vcxproj.filters +0 -26
  127. package/libusb/msvc/dpfp_2017.vcxproj +0 -106
  128. package/libusb/msvc/dpfp_2017.vcxproj.filters +0 -26
  129. package/libusb/msvc/dpfp_2019.vcxproj +0 -106
  130. package/libusb/msvc/dpfp_2019.vcxproj.filters +0 -26
  131. package/libusb/msvc/dpfp_threaded_2013.vcxproj +0 -87
  132. package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +0 -26
  133. package/libusb/msvc/dpfp_threaded_2015.vcxproj +0 -87
  134. package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +0 -26
  135. package/libusb/msvc/dpfp_threaded_2017.vcxproj +0 -106
  136. package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +0 -26
  137. package/libusb/msvc/dpfp_threaded_2019.vcxproj +0 -106
  138. package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +0 -26
  139. package/libusb/msvc/fxload_2013.vcxproj +0 -94
  140. package/libusb/msvc/fxload_2013.vcxproj.filters +0 -35
  141. package/libusb/msvc/fxload_2015.vcxproj +0 -94
  142. package/libusb/msvc/fxload_2015.vcxproj.filters +0 -35
  143. package/libusb/msvc/fxload_2017.vcxproj +0 -113
  144. package/libusb/msvc/fxload_2017.vcxproj.filters +0 -35
  145. package/libusb/msvc/fxload_2019.vcxproj +0 -113
  146. package/libusb/msvc/fxload_2019.vcxproj.filters +0 -35
  147. package/libusb/msvc/getopt_2013.vcxproj +0 -72
  148. package/libusb/msvc/getopt_2013.vcxproj.filters +0 -26
  149. package/libusb/msvc/getopt_2015.vcxproj +0 -73
  150. package/libusb/msvc/getopt_2015.vcxproj.filters +0 -26
  151. package/libusb/msvc/getopt_2017.vcxproj +0 -92
  152. package/libusb/msvc/getopt_2017.vcxproj.filters +0 -26
  153. package/libusb/msvc/getopt_2019.vcxproj +0 -92
  154. package/libusb/msvc/getopt_2019.vcxproj.filters +0 -26
  155. package/libusb/msvc/hotplugtest_2013.vcxproj +0 -86
  156. package/libusb/msvc/hotplugtest_2013.vcxproj.filters +0 -23
  157. package/libusb/msvc/hotplugtest_2015.vcxproj +0 -86
  158. package/libusb/msvc/hotplugtest_2015.vcxproj.filters +0 -23
  159. package/libusb/msvc/hotplugtest_2017.vcxproj +0 -105
  160. package/libusb/msvc/hotplugtest_2017.vcxproj.filters +0 -23
  161. package/libusb/msvc/hotplugtest_2019.vcxproj +0 -105
  162. package/libusb/msvc/hotplugtest_2019.vcxproj.filters +0 -23
  163. package/libusb/msvc/libusb_2013.sln +0 -137
  164. package/libusb/msvc/libusb_2015.sln +0 -137
  165. package/libusb/msvc/libusb_2017.sln +0 -240
  166. package/libusb/msvc/libusb_2019.sln +0 -240
  167. package/libusb/msvc/libusb_dll_2013.vcxproj +0 -104
  168. package/libusb/msvc/libusb_dll_2013.vcxproj.filters +0 -94
  169. package/libusb/msvc/libusb_dll_2015.vcxproj +0 -105
  170. package/libusb/msvc/libusb_dll_2015.vcxproj.filters +0 -94
  171. package/libusb/msvc/libusb_dll_2017.vcxproj +0 -124
  172. package/libusb/msvc/libusb_dll_2017.vcxproj.filters +0 -94
  173. package/libusb/msvc/libusb_dll_2019.vcxproj +0 -124
  174. package/libusb/msvc/libusb_dll_2019.vcxproj.filters +0 -94
  175. package/libusb/msvc/libusb_static_2013.vcxproj +0 -94
  176. package/libusb/msvc/libusb_static_2013.vcxproj.filters +0 -80
  177. package/libusb/msvc/libusb_static_2015.vcxproj +0 -95
  178. package/libusb/msvc/libusb_static_2015.vcxproj.filters +0 -80
  179. package/libusb/msvc/libusb_static_2017.vcxproj +0 -114
  180. package/libusb/msvc/libusb_static_2017.vcxproj.filters +0 -80
  181. package/libusb/msvc/libusb_static_2019.vcxproj +0 -114
  182. package/libusb/msvc/libusb_static_2019.vcxproj.filters +0 -80
  183. package/libusb/msvc/listdevs_2013.vcxproj +0 -86
  184. package/libusb/msvc/listdevs_2013.vcxproj.filters +0 -23
  185. package/libusb/msvc/listdevs_2015.vcxproj +0 -86
  186. package/libusb/msvc/listdevs_2015.vcxproj.filters +0 -23
  187. package/libusb/msvc/listdevs_2017.vcxproj +0 -105
  188. package/libusb/msvc/listdevs_2017.vcxproj.filters +0 -23
  189. package/libusb/msvc/listdevs_2019.vcxproj +0 -105
  190. package/libusb/msvc/listdevs_2019.vcxproj.filters +0 -23
  191. package/libusb/msvc/sam3u_benchmark_2013.vcxproj +0 -87
  192. package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +0 -26
  193. package/libusb/msvc/sam3u_benchmark_2015.vcxproj +0 -87
  194. package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +0 -26
  195. package/libusb/msvc/sam3u_benchmark_2017.vcxproj +0 -106
  196. package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +0 -26
  197. package/libusb/msvc/sam3u_benchmark_2019.vcxproj +0 -106
  198. package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +0 -26
  199. package/libusb/msvc/stress_2013.vcxproj +0 -89
  200. package/libusb/msvc/stress_2013.vcxproj.filters +0 -32
  201. package/libusb/msvc/stress_2015.vcxproj +0 -89
  202. package/libusb/msvc/stress_2015.vcxproj.filters +0 -32
  203. package/libusb/msvc/stress_2017.vcxproj +0 -108
  204. package/libusb/msvc/stress_2017.vcxproj.filters +0 -32
  205. package/libusb/msvc/stress_2019.vcxproj +0 -108
  206. package/libusb/msvc/stress_2019.vcxproj.filters +0 -32
  207. package/libusb/msvc/testlibusb_2013.vcxproj +0 -86
  208. package/libusb/msvc/testlibusb_2013.vcxproj.filters +0 -23
  209. package/libusb/msvc/testlibusb_2015.vcxproj +0 -86
  210. package/libusb/msvc/testlibusb_2015.vcxproj.filters +0 -23
  211. package/libusb/msvc/testlibusb_2017.vcxproj +0 -105
  212. package/libusb/msvc/testlibusb_2017.vcxproj.filters +0 -23
  213. package/libusb/msvc/testlibusb_2019.vcxproj +0 -105
  214. package/libusb/msvc/testlibusb_2019.vcxproj.filters +0 -23
  215. package/libusb/msvc/xusb_2013.vcxproj +0 -86
  216. package/libusb/msvc/xusb_2013.vcxproj.filters +0 -23
  217. package/libusb/msvc/xusb_2015.vcxproj +0 -86
  218. package/libusb/msvc/xusb_2015.vcxproj.filters +0 -23
  219. package/libusb/msvc/xusb_2017.vcxproj +0 -105
  220. package/libusb/msvc/xusb_2017.vcxproj.filters +0 -23
  221. package/libusb/msvc/xusb_2019.vcxproj +0 -105
  222. package/libusb/msvc/xusb_2019.vcxproj.filters +0 -23
@@ -167,7 +167,7 @@ obsd_get_device_list(struct libusb_context * ctx,
167
167
  dev = usbi_alloc_device(ctx, session_id);
168
168
  if (dev == NULL) {
169
169
  close(fd);
170
- return (LIBUSB_ERROR_NO_MEM);
170
+ return LIBUSB_ERROR_NO_MEM;
171
171
  }
172
172
 
173
173
  dev->bus_number = di.udi_bus;
@@ -205,7 +205,7 @@ obsd_get_device_list(struct libusb_context * ctx,
205
205
  ddd = discovered_devs_append(*discdevs, dev);
206
206
  if (ddd == NULL) {
207
207
  close(fd);
208
- return (LIBUSB_ERROR_NO_MEM);
208
+ return LIBUSB_ERROR_NO_MEM;
209
209
  }
210
210
  libusb_unref_device(dev);
211
211
 
@@ -216,7 +216,7 @@ obsd_get_device_list(struct libusb_context * ctx,
216
216
  close(fd);
217
217
  }
218
218
 
219
- return (LIBUSB_SUCCESS);
219
+ return LIBUSB_SUCCESS;
220
220
  }
221
221
 
222
222
  int
@@ -241,7 +241,7 @@ obsd_open(struct libusb_device_handle *handle)
241
241
  usbi_dbg(HANDLE_CTX(handle), "open %s: fd %d", devnode, dpriv->fd);
242
242
  }
243
243
 
244
- return (LIBUSB_SUCCESS);
244
+ return LIBUSB_SUCCESS;
245
245
  }
246
246
 
247
247
  void
@@ -269,7 +269,7 @@ obsd_get_active_config_descriptor(struct libusb_device *dev,
269
269
 
270
270
  memcpy(buf, dpriv->cdesc, len);
271
271
 
272
- return ((int)len);
272
+ return (int)len;
273
273
  }
274
274
 
275
275
  int
@@ -297,7 +297,7 @@ obsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
297
297
  }
298
298
  close(fd);
299
299
 
300
- return ((int)len);
300
+ return (int)len;
301
301
  }
302
302
 
303
303
  int
@@ -309,7 +309,7 @@ obsd_get_configuration(struct libusb_device_handle *handle, uint8_t *config)
309
309
 
310
310
  usbi_dbg(HANDLE_CTX(handle), "bConfigurationValue %u", *config);
311
311
 
312
- return (LIBUSB_SUCCESS);
312
+ return LIBUSB_SUCCESS;
313
313
  }
314
314
 
315
315
  int
@@ -318,7 +318,7 @@ obsd_set_configuration(struct libusb_device_handle *handle, int config)
318
318
  struct device_priv *dpriv = usbi_get_device_priv(handle->dev);
319
319
 
320
320
  if (dpriv->devname == NULL)
321
- return (LIBUSB_ERROR_NOT_SUPPORTED);
321
+ return LIBUSB_ERROR_NOT_SUPPORTED;
322
322
 
323
323
  usbi_dbg(HANDLE_CTX(handle), "bConfigurationValue %d", config);
324
324
 
@@ -339,7 +339,7 @@ obsd_claim_interface(struct libusb_device_handle *handle, uint8_t iface)
339
339
  for (i = 0; i < USB_MAX_ENDPOINTS; i++)
340
340
  hpriv->endpoints[i] = -1;
341
341
 
342
- return (LIBUSB_SUCCESS);
342
+ return LIBUSB_SUCCESS;
343
343
  }
344
344
 
345
345
  int
@@ -354,7 +354,7 @@ obsd_release_interface(struct libusb_device_handle *handle, uint8_t iface)
354
354
  if (hpriv->endpoints[i] >= 0)
355
355
  close(hpriv->endpoints[i]);
356
356
 
357
- return (LIBUSB_SUCCESS);
357
+ return LIBUSB_SUCCESS;
358
358
  }
359
359
 
360
360
  int
@@ -365,7 +365,7 @@ obsd_set_interface_altsetting(struct libusb_device_handle *handle, uint8_t iface
365
365
  struct usb_alt_interface intf;
366
366
 
367
367
  if (dpriv->devname == NULL)
368
- return (LIBUSB_ERROR_NOT_SUPPORTED);
368
+ return LIBUSB_ERROR_NOT_SUPPORTED;
369
369
 
370
370
  usbi_dbg(HANDLE_CTX(handle), "iface %u, setting %u", iface, altsetting);
371
371
 
@@ -377,7 +377,7 @@ obsd_set_interface_altsetting(struct libusb_device_handle *handle, uint8_t iface
377
377
  if (ioctl(dpriv->fd, USB_SET_ALTINTERFACE, &intf) < 0)
378
378
  return _errno_to_libusb(errno);
379
379
 
380
- return (LIBUSB_SUCCESS);
380
+ return LIBUSB_SUCCESS;
381
381
  }
382
382
 
383
383
  int
@@ -405,7 +405,7 @@ obsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
405
405
  }
406
406
  close(fd);
407
407
 
408
- return (LIBUSB_SUCCESS);
408
+ return LIBUSB_SUCCESS;
409
409
  }
410
410
 
411
411
  void
@@ -456,11 +456,11 @@ obsd_submit_transfer(struct usbi_transfer *itransfer)
456
456
  }
457
457
 
458
458
  if (err)
459
- return (err);
459
+ return err;
460
460
 
461
461
  usbi_signal_transfer_completion(itransfer);
462
462
 
463
- return (LIBUSB_SUCCESS);
463
+ return LIBUSB_SUCCESS;
464
464
  }
465
465
 
466
466
  int
@@ -470,7 +470,7 @@ obsd_cancel_transfer(struct usbi_transfer *itransfer)
470
470
 
471
471
  usbi_dbg(ITRANSFER_CTX(itransfer), " ");
472
472
 
473
- return (LIBUSB_ERROR_NOT_SUPPORTED);
473
+ return LIBUSB_ERROR_NOT_SUPPORTED;
474
474
  }
475
475
 
476
476
  int
@@ -486,18 +486,18 @@ _errno_to_libusb(int err)
486
486
 
487
487
  switch (err) {
488
488
  case EIO:
489
- return (LIBUSB_ERROR_IO);
489
+ return LIBUSB_ERROR_IO;
490
490
  case EACCES:
491
- return (LIBUSB_ERROR_ACCESS);
491
+ return LIBUSB_ERROR_ACCESS;
492
492
  case ENOENT:
493
- return (LIBUSB_ERROR_NO_DEVICE);
493
+ return LIBUSB_ERROR_NO_DEVICE;
494
494
  case ENOMEM:
495
- return (LIBUSB_ERROR_NO_MEM);
495
+ return LIBUSB_ERROR_NO_MEM;
496
496
  case ETIMEDOUT:
497
- return (LIBUSB_ERROR_TIMEOUT);
497
+ return LIBUSB_ERROR_TIMEOUT;
498
498
  }
499
499
 
500
- return (LIBUSB_ERROR_OTHER);
500
+ return LIBUSB_ERROR_OTHER;
501
501
  }
502
502
 
503
503
  int
@@ -528,7 +528,7 @@ _cache_active_config_descriptor(struct libusb_device *dev)
528
528
  len = UGETW(udc.udc_desc.wTotalLength);
529
529
  buf = malloc((size_t)len);
530
530
  if (buf == NULL)
531
- return (LIBUSB_ERROR_NO_MEM);
531
+ return LIBUSB_ERROR_NO_MEM;
532
532
 
533
533
  udf.udf_bus = dev->bus_number;
534
534
  udf.udf_addr = dev->device_address;
@@ -550,7 +550,7 @@ _cache_active_config_descriptor(struct libusb_device *dev)
550
550
  free(dpriv->cdesc);
551
551
  dpriv->cdesc = buf;
552
552
 
553
- return (LIBUSB_SUCCESS);
553
+ return LIBUSB_SUCCESS;
554
554
  }
555
555
 
556
556
  int
@@ -594,17 +594,17 @@ _sync_control_transfer(struct usbi_transfer *itransfer)
594
594
  if ((fd = _bus_open(transfer->dev_handle->dev->bus_number)) < 0)
595
595
  return _errno_to_libusb(errno);
596
596
 
597
- if ((ioctl(fd, USB_REQUEST, &req)) < 0) {
597
+ if (ioctl(fd, USB_REQUEST, &req) < 0) {
598
598
  err = errno;
599
599
  close(fd);
600
600
  return _errno_to_libusb(err);
601
601
  }
602
602
  close(fd);
603
603
  } else {
604
- if ((ioctl(dpriv->fd, USB_SET_TIMEOUT, &transfer->timeout)) < 0)
604
+ if (ioctl(dpriv->fd, USB_SET_TIMEOUT, &transfer->timeout) < 0)
605
605
  return _errno_to_libusb(errno);
606
606
 
607
- if ((ioctl(dpriv->fd, USB_DO_REQUEST, &req)) < 0)
607
+ if (ioctl(dpriv->fd, USB_DO_REQUEST, &req) < 0)
608
608
  return _errno_to_libusb(errno);
609
609
  }
610
610
 
@@ -612,7 +612,7 @@ _sync_control_transfer(struct usbi_transfer *itransfer)
612
612
 
613
613
  usbi_dbg(ITRANSFER_CTX(itransfer), "transferred %d", itransfer->transferred);
614
614
 
615
- return (0);
615
+ return 0;
616
616
  }
617
617
 
618
618
  int
@@ -640,12 +640,12 @@ _access_endpoint(struct libusb_transfer *transfer)
640
640
  /* We may need to read/write to the same endpoint later. */
641
641
  if (((fd = open(devnode, O_RDWR)) < 0) && (errno == ENXIO))
642
642
  if ((fd = open(devnode, mode)) < 0)
643
- return (-1);
643
+ return -1;
644
644
 
645
645
  hpriv->endpoints[endpt] = fd;
646
646
  }
647
647
 
648
- return (hpriv->endpoints[endpt]);
648
+ return hpriv->endpoints[endpt];
649
649
  }
650
650
 
651
651
  int
@@ -659,7 +659,7 @@ _sync_gen_transfer(struct usbi_transfer *itransfer)
659
659
  dpriv = usbi_get_device_priv(transfer->dev_handle->dev);
660
660
 
661
661
  if (dpriv->devname == NULL)
662
- return (LIBUSB_ERROR_NOT_SUPPORTED);
662
+ return LIBUSB_ERROR_NOT_SUPPORTED;
663
663
 
664
664
  /*
665
665
  * Bulk, Interrupt or Isochronous transfer depends on the
@@ -668,12 +668,12 @@ _sync_gen_transfer(struct usbi_transfer *itransfer)
668
668
  if ((fd = _access_endpoint(transfer)) < 0)
669
669
  return _errno_to_libusb(errno);
670
670
 
671
- if ((ioctl(fd, USB_SET_TIMEOUT, &transfer->timeout)) < 0)
671
+ if (ioctl(fd, USB_SET_TIMEOUT, &transfer->timeout) < 0)
672
672
  return _errno_to_libusb(errno);
673
673
 
674
674
  if (IS_XFERIN(transfer)) {
675
675
  if ((transfer->flags & LIBUSB_TRANSFER_SHORT_NOT_OK) == 0)
676
- if ((ioctl(fd, USB_SET_SHORT_XFER, &nr)) < 0)
676
+ if (ioctl(fd, USB_SET_SHORT_XFER, &nr) < 0)
677
677
  return _errno_to_libusb(errno);
678
678
 
679
679
  nr = read(fd, transfer->buffer, transfer->length);
@@ -686,7 +686,7 @@ _sync_gen_transfer(struct usbi_transfer *itransfer)
686
686
 
687
687
  itransfer->transferred = nr;
688
688
 
689
- return (0);
689
+ return 0;
690
690
  }
691
691
 
692
692
  int
@@ -1,6 +1,6 @@
1
1
  /*
2
- *
3
2
  * Copyright (c) 2016, Oracle and/or its affiliates.
3
+ * Copyright 2023 Oxide Computer Company
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
6
6
  * modify it under the terms of the GNU Lesser General Public
@@ -82,7 +82,7 @@ static int sunos_usb_ioctl(struct libusb_device *dev, int cmd);
82
82
 
83
83
  static int sunos_get_link(di_devlink_t devlink, void *arg)
84
84
  {
85
- walk_link_t *larg = (walk_link_t *)arg;
85
+ walk_link_t *link_arg = (walk_link_t *)arg;
86
86
  const char *p;
87
87
  const char *q;
88
88
 
@@ -112,21 +112,21 @@ static int sunos_get_link(di_devlink_t devlink, void *arg)
112
112
  static int sunos_physpath_to_devlink(
113
113
  const char *node_path, const char *match, char **link_path)
114
114
  {
115
- walk_link_t larg;
115
+ walk_link_t link_arg;
116
116
  di_devlink_handle_t hdl;
117
117
 
118
118
  *link_path = NULL;
119
- larg.linkpp = link_path;
119
+ link_arg.linkpp = link_path;
120
120
  if ((hdl = di_devlink_init(NULL, 0)) == NULL) {
121
121
  usbi_dbg(NULL, "di_devlink_init failure");
122
122
  return (-1);
123
123
  }
124
124
 
125
- larg.len = strlen(node_path);
126
- larg.path = (char *)node_path;
125
+ link_arg.len = strlen(node_path);
126
+ link_arg.path = (char *)node_path;
127
127
 
128
128
  (void) di_devlink_walk(hdl, match, NULL, DI_PRIMARY_LINK,
129
- (void *)&larg, sunos_get_link);
129
+ (void *)&link_arg, sunos_get_link);
130
130
 
131
131
  (void) di_devlink_fini(&hdl);
132
132
 
@@ -624,7 +624,7 @@ sunos_add_devices(di_devlink_t link, void *arg)
624
624
  }
625
625
  if (usbi_sanitize_device(dev) < 0) {
626
626
  libusb_unref_device(dev);
627
- usbi_dbg(NULL, "sanatize failed: ");
627
+ usbi_dbg(NULL, "sanitize failed: ");
628
628
  return (DI_WALK_TERMINATE);
629
629
  }
630
630
  } else {
@@ -831,7 +831,7 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl,
831
831
  {
832
832
  char filename[PATH_MAX + 1], statfilename[PATH_MAX + 1];
833
833
  char cfg_num[16], alt_num[16];
834
- int fd, fdstat, mode;
834
+ int fd, fdstat, mode, e;
835
835
  uint8_t ifc = 0;
836
836
  uint8_t ep_index;
837
837
  sunos_dev_handle_priv_t *hpriv;
@@ -870,11 +870,22 @@ sunos_check_device_and_status_open(struct libusb_device_handle *hdl,
870
870
  bzero(alt_num, sizeof(alt_num));
871
871
  }
872
872
 
873
- (void) snprintf(filename, PATH_MAX, "%s/%sif%d%s%s%d",
873
+ e = snprintf(filename, sizeof (filename), "%s/%sif%d%s%s%d",
874
874
  hpriv->dpriv->ugenpath, cfg_num, ifc, alt_num,
875
- (ep_addr & LIBUSB_ENDPOINT_DIR_MASK) ? "in" :
876
- "out", (ep_addr & LIBUSB_ENDPOINT_ADDRESS_MASK));
877
- (void) snprintf(statfilename, PATH_MAX, "%sstat", filename);
875
+ (ep_addr & LIBUSB_ENDPOINT_DIR_MASK) ? "in" : "out",
876
+ ep_addr & LIBUSB_ENDPOINT_ADDRESS_MASK);
877
+ if (e < 0 || e >= (int)sizeof (filename)) {
878
+ usbi_dbg(HANDLE_CTX(hdl),
879
+ "path buffer overflow for endpoint 0x%02x", ep_addr);
880
+ return (EINVAL);
881
+ }
882
+
883
+ e = snprintf(statfilename, sizeof (statfilename), "%sstat", filename);
884
+ if (e < 0 || e >= (int)sizeof (statfilename)) {
885
+ usbi_dbg(HANDLE_CTX(hdl),
886
+ "path buffer overflow for endpoint 0x%02x stat", ep_addr);
887
+ return (EINVAL);
888
+ }
878
889
 
879
890
  /*
880
891
  * In case configuration has been switched, the xfer endpoint needs
@@ -1379,8 +1390,7 @@ sunos_submit_transfer(struct usbi_transfer *itransfer)
1379
1390
 
1380
1391
  err = sunos_check_device_and_status_open(hdl,
1381
1392
  transfer->endpoint, transfer->type);
1382
- if (err < 0) {
1383
-
1393
+ if (err != 0) {
1384
1394
  return (_errno_to_libusb(err));
1385
1395
  }
1386
1396
 
@@ -32,8 +32,6 @@
32
32
  #elif defined(__NetBSD__)
33
33
  # include <lwp.h>
34
34
  #elif defined(__OpenBSD__)
35
- # define _BSD_SOURCE
36
- # include <sys/syscall.h>
37
35
  # include <unistd.h>
38
36
  #elif defined(__sun__)
39
37
  # include <sys/lwp.h>
@@ -109,9 +107,7 @@ unsigned int usbi_get_tid(void)
109
107
  #elif defined(__NetBSD__)
110
108
  tid = _lwp_self();
111
109
  #elif defined(__OpenBSD__)
112
- /* The following only works with OpenBSD > 5.1 as it requires
113
- * real thread support. For 5.1 and earlier, -1 is returned. */
114
- tid = syscall(SYS_getthrid);
110
+ tid = getthrid();
115
111
  #elif defined(__sun__)
116
112
  tid = _lwp_self();
117
113
  #else
@@ -279,6 +279,7 @@ enum libusb_transfer_status usbd_status_to_libusb_transfer_status(USBD_STATUS st
279
279
  case USBD_STATUS_CANCELED:
280
280
  return LIBUSB_TRANSFER_CANCELLED;
281
281
  case USBD_STATUS_ENDPOINT_HALTED:
282
+ case USBD_STATUS_STALL_PID:
282
283
  return LIBUSB_TRANSFER_STALL;
283
284
  case USBD_STATUS_DEVICE_GONE:
284
285
  return LIBUSB_TRANSFER_NO_DEVICE;
@@ -331,6 +332,9 @@ static enum windows_version get_windows_version(void)
331
332
  const char *w, *arch;
332
333
  bool ws;
333
334
 
335
+ #ifndef ENABLE_LOGGING
336
+ UNUSED(w); UNUSED(arch);
337
+ #endif
334
338
  memset(&vi, 0, sizeof(vi));
335
339
  vi.dwOSVersionInfoSize = sizeof(vi);
336
340
  if (!GetVersionExA((OSVERSIONINFOA *)&vi)) {
@@ -482,14 +486,15 @@ static unsigned __stdcall windows_iocp_thread(void *arg)
482
486
  usbi_mutex_unlock(&ctx->open_devs_lock);
483
487
 
484
488
  if (!found) {
485
- usbi_dbg(ctx, "ignoring overlapped %p for handle %p (device %u.%u)",
486
- overlapped, dev_handle, dev_handle->dev->bus_number, dev_handle->dev->device_address);
489
+ usbi_dbg(ctx, "ignoring overlapped %p for handle %p",
490
+ overlapped, dev_handle);
487
491
  continue;
488
492
  }
489
493
 
490
- itransfer = (struct usbi_transfer *)((unsigned char *)transfer_priv + PTR_ALIGN(sizeof(*transfer_priv)));
494
+ itransfer = TRANSFER_PRIV_TO_USBI_TRANSFER(transfer_priv);
495
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
491
496
  usbi_dbg(ctx, "transfer %p completed, length %lu",
492
- USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer), ULONG_CAST(num_bytes));
497
+ transfer, ULONG_CAST(num_bytes));
493
498
  usbi_signal_transfer_completion(itransfer);
494
499
  }
495
500
 
@@ -801,8 +806,9 @@ static int windows_handle_transfer_completion(struct usbi_transfer *itransfer)
801
806
  else
802
807
  result = GetLastError();
803
808
 
809
+ struct libusb_transfer *transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
804
810
  usbi_dbg(ctx, "handling transfer %p completion with errcode %lu, length %lu",
805
- USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer), ULONG_CAST(result), ULONG_CAST(bytes_transferred));
811
+ transfer, ULONG_CAST(result), ULONG_CAST(bytes_transferred));
806
812
 
807
813
  switch (result) {
808
814
  case NO_ERROR:
@@ -848,6 +854,7 @@ static int windows_handle_transfer_completion(struct usbi_transfer *itransfer)
848
854
  return usbi_handle_transfer_completion(itransfer, status);
849
855
  }
850
856
 
857
+ #ifndef HAVE_CLOCK_GETTIME
851
858
  void usbi_get_monotonic_time(struct timespec *tp)
852
859
  {
853
860
  static LONG hires_counter_init;
@@ -872,6 +879,7 @@ void usbi_get_monotonic_time(struct timespec *tp)
872
879
  tp->tv_sec = (long)(hires_counter.QuadPart / hires_frequency);
873
880
  tp->tv_nsec = (long)(((hires_counter.QuadPart % hires_frequency) * hires_ticks_to_ps) / UINT64_C(1000));
874
881
  }
882
+ #endif
875
883
 
876
884
  // NB: MSVC6 does not support named initializers.
877
885
  const struct usbi_os_backend usbi_backend = {
@@ -131,6 +131,7 @@ typedef LONG USBD_STATUS;
131
131
 
132
132
  #define USBD_SUCCESS(Status) ((USBD_STATUS)(Status) >= 0)
133
133
 
134
+ #define USBD_STATUS_STALL_PID ((USBD_STATUS)0xC0000004L)
134
135
  #define USBD_STATUS_ENDPOINT_HALTED ((USBD_STATUS)0xC0000030L)
135
136
  #define USBD_STATUS_TIMEOUT ((USBD_STATUS)0xC0006000L)
136
137
  #define USBD_STATUS_DEVICE_GONE ((USBD_STATUS)0xC0007000L)
@@ -257,6 +258,13 @@ struct winusb_device_priv {
257
258
  int current_altsetting;
258
259
  bool restricted_functionality; // indicates if the interface functionality is restricted
259
260
  // by Windows (eg. HID keyboards or mice cannot do R/W)
261
+ uint8_t num_associated_interfaces; // If non-zero, the interface is part of a grouped
262
+ // set of associated interfaces (defined by an IAD)
263
+ // and this is the number of interfaces within the
264
+ // associated group (bInterfaceCount in IAD).
265
+ uint8_t first_associated_interface; // For associated interfaces, this is the index of
266
+ // the first interface (bFirstInterface in IAD) for
267
+ // the grouped set of associated interfaces.
260
268
  } usb_interface[USB_MAXINTERFACES];
261
269
  struct hid_device_priv *hid;
262
270
  PUSB_CONFIGURATION_DESCRIPTOR *config_descriptor; // list of pointers to the cached config descriptors