usb 2.17.0 → 2.18.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 (94) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +14 -0
  3. package/binding.gyp +2 -9
  4. package/dist/usb/bindings.d.ts +27 -2
  5. package/dist/usb/bindings.js.map +1 -1
  6. package/dist/usb/index.d.ts +0 -29
  7. package/dist/usb/index.js +4 -18
  8. package/dist/usb/index.js.map +1 -1
  9. package/libusb/.clang-tidy +5 -3
  10. package/libusb/.private/ci-build.sh +5 -1
  11. package/libusb/AUTHORS +14 -0
  12. package/libusb/ChangeLog +15 -2
  13. package/libusb/README +8 -5
  14. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +4 -0
  15. package/libusb/configure.ac +12 -2
  16. package/libusb/examples/hotplugtest.c +19 -11
  17. package/libusb/examples/listdevs.c +41 -3
  18. package/libusb/examples/xusb.c +6 -1
  19. package/libusb/libusb/Makefile.am +4 -0
  20. package/libusb/libusb/core.c +175 -14
  21. package/libusb/libusb/descriptor.c +163 -14
  22. package/libusb/libusb/io.c +7 -3
  23. package/libusb/libusb/libusb-1.0.def +10 -0
  24. package/libusb/libusb/libusb.h +59 -9
  25. package/libusb/libusb/libusbi.h +89 -25
  26. package/libusb/libusb/os/darwin_usb.c +126 -46
  27. package/libusb/libusb/os/darwin_usb.h +10 -8
  28. package/libusb/libusb/os/emscripten_webusb.cpp +31 -10
  29. package/libusb/libusb/os/haiku_usb_raw.cpp +4 -0
  30. package/libusb/libusb/os/linux_usbfs.c +73 -25
  31. package/libusb/libusb/os/netbsd_usb.c +2 -0
  32. package/libusb/libusb/os/openbsd_usb.c +2 -0
  33. package/libusb/libusb/os/sunos_usb.c +2 -0
  34. package/libusb/libusb/os/threads_posix.c +3 -3
  35. package/libusb/libusb/os/threads_posix.h +8 -2
  36. package/libusb/libusb/os/threads_windows.h +2 -1
  37. package/libusb/libusb/os/windows_common.c +86 -1
  38. package/libusb/libusb/os/windows_common.h +20 -1
  39. package/libusb/libusb/os/windows_hotplug.c +321 -0
  40. package/libusb/libusb/os/windows_hotplug.h +28 -0
  41. package/libusb/libusb/os/windows_usbdk.c +16 -8
  42. package/libusb/libusb/os/windows_winusb.c +753 -41
  43. package/libusb/libusb/os/windows_winusb.h +11 -6
  44. package/libusb/libusb/version.h +1 -1
  45. package/libusb/libusb/version_nano.h +1 -1
  46. package/libusb/msvc/Base.props +1 -1
  47. package/libusb/msvc/Configuration.Base.props +2 -1
  48. package/libusb/msvc/Configuration.DynamicLibrary.props +12 -0
  49. package/libusb/msvc/ProjectConfigurations.Base.props +69 -16
  50. package/libusb/msvc/build_all.ps1 +2 -2
  51. package/libusb/msvc/config.h +4 -0
  52. package/libusb/msvc/getopt/bits/getopt_core.h +96 -0
  53. package/libusb/msvc/getopt/bits/getopt_ext.h +77 -0
  54. package/libusb/msvc/getopt/features.h +21 -0
  55. package/libusb/msvc/getopt/getopt.c +456 -705
  56. package/libusb/msvc/getopt/getopt.h +16 -158
  57. package/libusb/msvc/getopt/getopt1.c +40 -69
  58. package/libusb/msvc/getopt/getopt_int.h +118 -0
  59. package/libusb/msvc/getopt/gettext.h +7 -0
  60. package/libusb/msvc/getopt/unistd.h +5 -0
  61. package/libusb/msvc/getopt.vcxproj +11 -4
  62. package/libusb/msvc/libusb.sln +515 -268
  63. package/libusb/msvc/libusb_dll.vcxproj +2 -0
  64. package/libusb/msvc/libusb_static.vcxproj +2 -0
  65. package/libusb/msvc/xusb.vcxproj +1 -1
  66. package/libusb/tests/Makefile.am +10 -1
  67. package/libusb/tests/fuzz/corpus/bos/min.bos +0 -0
  68. package/libusb/tests/fuzz/corpus/descriptor_parsers/min_valid_config.bin +0 -0
  69. package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_a_endpoint_null.bin +0 -0
  70. package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_b_iad_oob.bin +0 -0
  71. package/libusb/tests/fuzz/fuzz_bos_descriptor.c +49 -0
  72. package/libusb/tests/fuzz/fuzz_descriptor_parsers.c +83 -0
  73. package/libusb/tests/stress_mt.c +2 -1
  74. package/libusb/tests/webusb-test-shim/index.js +6 -5
  75. package/libusb.gypi +5 -0
  76. package/package.json +1 -1
  77. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  78. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  79. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  80. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  81. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  82. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  83. package/prebuilds/linux-ia32/node.napi.node +0 -0
  84. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  85. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  86. package/prebuilds/win32-arm64/node.napi.node +0 -0
  87. package/prebuilds/win32-ia32/node.napi.node +0 -0
  88. package/prebuilds/win32-x64/node.napi.node +0 -0
  89. package/src/{hotplug/libusb.cc → hotplug.cc} +2 -3
  90. package/src/{hotplug/hotplug.h → hotplug.h} +2 -6
  91. package/src/node_usb.cc +3 -3
  92. package/test/usb.coffee +4 -4
  93. package/test/webusb.coffee +22 -12
  94. package/src/hotplug/windows.cc +0 -168
@@ -65,9 +65,6 @@ typedef SSIZE_T ssize_t;
65
65
  #if defined(interface)
66
66
  #undef interface
67
67
  #endif
68
- #if !defined(__CYGWIN__)
69
- #include <winsock.h>
70
- #endif
71
68
  #endif /* _WIN32 || __CYGWIN__ */
72
69
 
73
70
  #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5))
@@ -168,9 +165,10 @@ typedef SSIZE_T ssize_t;
168
165
  * <li>libusb version 1.0.27: LIBUSB_API_VERSION = 0x0100010A
169
166
  * <li>libusb version 1.0.28: LIBUSB_API_VERSION = 0x0100010A
170
167
  * <li>libusb version 1.0.29: LIBUSB_API_VERSION = 0x0100010B
168
+ * <li>libusb version 1.0.30: LIBUSB_API_VERSION = 0x0100010C
171
169
  * </ul>
172
170
  */
173
- #define LIBUSB_API_VERSION 0x0100010B
171
+ #define LIBUSB_API_VERSION 0x0100010C
174
172
 
175
173
  /** \def LIBUSBX_API_VERSION
176
174
  * \ingroup libusb_misc
@@ -192,7 +190,7 @@ extern "C" {
192
190
  * \param x the host-endian value to convert
193
191
  * \returns the value in little-endian byte order
194
192
  */
195
- static inline uint16_t libusb_cpu_to_le16(const uint16_t x)
193
+ static inline uint16_t libusb_cpu_to_le16(uint16_t x)
196
194
  {
197
195
  union {
198
196
  uint8_t b8[2];
@@ -264,6 +262,24 @@ enum libusb_class_code {
264
262
  /** Personal Healthcare */
265
263
  LIBUSB_CLASS_PERSONAL_HEALTHCARE = 0x0f,
266
264
 
265
+ /** Audio & Video */
266
+ LIBUSB_CLASS_AUDIO_VIDEO = 0x10,
267
+
268
+ /** Billboard */
269
+ LIBUSB_CLASS_BILLBOARD = 0x11,
270
+
271
+ /** Interface class */
272
+ LIBUSB_CLASS_TYPE_C_BRIDGE = 0x12,
273
+
274
+ /** Bulk display */
275
+ LIBUSB_CLASS_BULK_DISPLAY_PROTOCOL = 0x13,
276
+
277
+ /** MCTP */
278
+ LIBUSB_CLASS_MCTP = 0x14,
279
+
280
+ /** I3C */
281
+ LIBUSB_CLASS_I3C = 0x3c,
282
+
267
283
  /** Diagnostic Device */
268
284
  LIBUSB_CLASS_DIAGNOSTIC_DEVICE = 0xdc,
269
285
 
@@ -1182,16 +1198,16 @@ struct libusb_device_handle;
1182
1198
  */
1183
1199
  struct libusb_version {
1184
1200
  /** Library major version. */
1185
- const uint16_t major;
1201
+ uint16_t major;
1186
1202
 
1187
1203
  /** Library minor version. */
1188
- const uint16_t minor;
1204
+ uint16_t minor;
1189
1205
 
1190
1206
  /** Library micro version. */
1191
- const uint16_t micro;
1207
+ uint16_t micro;
1192
1208
 
1193
1209
  /** Library nano version. */
1194
- const uint16_t nano;
1210
+ uint16_t nano;
1195
1211
 
1196
1212
  /** Library release candidate suffix string, e.g. "-rc4". */
1197
1213
  const char *rc;
@@ -1649,6 +1665,29 @@ enum libusb_option {
1649
1665
  LIBUSB_OPTION_MAX = 4
1650
1666
  };
1651
1667
 
1668
+ /** \ingroup libusb_desc
1669
+ * The device string type.
1670
+ */
1671
+ enum libusb_device_string_type {
1672
+ LIBUSB_DEVICE_STRING_MANUFACTURER,
1673
+ LIBUSB_DEVICE_STRING_PRODUCT,
1674
+ LIBUSB_DEVICE_STRING_SERIAL_NUMBER,
1675
+ LIBUSB_DEVICE_STRING_COUNT /* The total number of string types. */
1676
+ };
1677
+
1678
+ /** \ingroup libusb_desc
1679
+ * The maximum length for a device string descriptor in UTF-8.
1680
+ *
1681
+ * 255 max descriptor length with 2 byte header
1682
+ * => 253 bytes UTF-16LE, no null termination (USB 2.0 9.6.7)
1683
+ * => 126.5 codepoints
1684
+ * => 127 * 3 + 1
1685
+ * => 382 bytes
1686
+ *
1687
+ * Stay with 256 * 3/2 = 384 to be safe.
1688
+ */
1689
+ #define LIBUSB_DEVICE_STRING_BYTES_MAX (384U)
1690
+
1652
1691
  /** \ingroup libusb_lib
1653
1692
  * Callback function for handling log messages.
1654
1693
  * \param ctx the context which is related to the log message, or NULL if it
@@ -1696,6 +1735,8 @@ void LIBUSB_CALL libusb_free_device_list(libusb_device **list,
1696
1735
  libusb_device * LIBUSB_CALL libusb_ref_device(libusb_device *dev);
1697
1736
  void LIBUSB_CALL libusb_unref_device(libusb_device *dev);
1698
1737
 
1738
+ int LIBUSB_CALL libusb_get_device_string(libusb_device *dev,
1739
+ enum libusb_device_string_type string_type, char *data, int length);
1699
1740
  int LIBUSB_CALL libusb_get_configuration(libusb_device_handle *dev,
1700
1741
  int *config);
1701
1742
  int LIBUSB_CALL libusb_get_device_descriptor(libusb_device *dev,
@@ -1745,6 +1786,7 @@ int LIBUSB_CALL libusb_get_platform_descriptor(libusb_context *ctx,
1745
1786
  struct libusb_platform_descriptor **platform_descriptor);
1746
1787
  void LIBUSB_CALL libusb_free_platform_descriptor(
1747
1788
  struct libusb_platform_descriptor *platform_descriptor);
1789
+ unsigned long LIBUSB_CALL libusb_get_session_data(libusb_device *dev);
1748
1790
  uint8_t LIBUSB_CALL libusb_get_bus_number(libusb_device *dev);
1749
1791
  uint8_t LIBUSB_CALL libusb_get_port_number(libusb_device *dev);
1750
1792
  int LIBUSB_CALL libusb_get_port_numbers(libusb_device *dev, uint8_t *port_numbers, int port_numbers_len);
@@ -1807,6 +1849,14 @@ int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev_handle,
1807
1849
  int LIBUSB_CALL libusb_set_auto_detach_kernel_driver(
1808
1850
  libusb_device_handle *dev_handle, int enable);
1809
1851
 
1852
+ int LIBUSB_CALL libusb_endpoint_supports_raw_io(libusb_device_handle* dev_handle,
1853
+ uint8_t endpoint);
1854
+ int LIBUSB_CALL libusb_endpoint_set_raw_io(libusb_device_handle *dev_handle,
1855
+ uint8_t endpoint, int enable);
1856
+ int LIBUSB_CALL libusb_get_max_raw_io_transfer_size(
1857
+ libusb_device_handle *dev_handle,
1858
+ uint8_t endpoint);
1859
+
1810
1860
  /* async I/O */
1811
1861
 
1812
1862
  /** \ingroup libusb_asyncio
@@ -369,30 +369,30 @@ struct libusb_context {
369
369
  usbi_timer_t timer;
370
370
  #endif
371
371
 
372
- struct list_head usb_devs;
373
372
  usbi_mutex_t usb_devs_lock;
373
+ struct list_head usb_devs;
374
374
 
375
375
  /* A list of open handles. Backends are free to traverse this if required.
376
376
  */
377
- struct list_head open_devs;
378
377
  usbi_mutex_t open_devs_lock;
378
+ struct list_head open_devs;
379
379
 
380
380
  /* A list of registered hotplug callbacks */
381
+ usbi_mutex_t hotplug_cbs_lock;
381
382
  struct list_head hotplug_cbs;
382
383
  libusb_hotplug_callback_handle next_hotplug_cb_handle;
383
- usbi_mutex_t hotplug_cbs_lock;
384
384
 
385
385
  /* A flag to indicate that the context is ready for hotplug notifications */
386
386
  usbi_atomic_t hotplug_ready;
387
387
 
388
+ /* Note paths taking both this and usbi_transfer->lock must always
389
+ * take this lock first */
390
+ usbi_mutex_t flying_transfers_lock;
388
391
  /* this is a list of in-flight transfer handles, sorted by timeout
389
392
  * expiration. URBs to timeout the soonest are placed at the beginning of
390
393
  * the list, URBs that will time out later are placed after, and urbs with
391
394
  * infinite timeout are always placed at the very end. */
392
395
  struct list_head flying_transfers;
393
- /* Note paths taking both this and usbi_transfer->lock must always
394
- * take this lock first */
395
- usbi_mutex_t flying_transfers_lock; /* for flying_transfers and timeout_flags */
396
396
 
397
397
  #if !defined(PLATFORM_WINDOWS)
398
398
  /* user callbacks for pollfd changes */
@@ -451,8 +451,8 @@ struct libusb_context {
451
451
  extern struct libusb_context *usbi_default_context;
452
452
  extern struct libusb_context *usbi_fallback_context;
453
453
 
454
- extern struct list_head active_contexts_list;
455
454
  extern usbi_mutex_static_t active_contexts_lock;
455
+ extern struct list_head active_contexts_list;
456
456
 
457
457
  static inline struct libusb_context *usbi_get_context(struct libusb_context *ctx)
458
458
  {
@@ -523,6 +523,8 @@ struct libusb_device {
523
523
 
524
524
  struct libusb_device_descriptor device_descriptor;
525
525
  usbi_atomic_t attached;
526
+
527
+ char * device_strings_utf8[LIBUSB_DEVICE_STRING_COUNT];
526
528
  };
527
529
 
528
530
  struct libusb_device_handle {
@@ -583,7 +585,17 @@ void usbi_get_real_time(struct timespec *tp);
583
585
  */
584
586
 
585
587
  struct usbi_transfer {
586
- int num_iso_packets;
588
+ /* this lock is held during libusb_submit_transfer() and
589
+ * libusb_cancel_transfer() (allowing the OS backend to prevent duplicate
590
+ * cancellation, submission-during-cancellation, etc). the OS backend
591
+ * should also take this lock in the handle_events path, to prevent the user
592
+ * cancelling the transfer from another thread while you are processing
593
+ * its completion (presumably there would be races within your OS backend
594
+ * if this were possible).
595
+ * Note paths taking both this and the flying_transfers_lock must
596
+ * always take the flying_transfers_lock first */
597
+ usbi_mutex_t lock;
598
+
587
599
  struct list_head list;
588
600
  struct list_head completed_list;
589
601
  struct timespec timeout;
@@ -596,17 +608,6 @@ struct usbi_transfer {
596
608
  * even after dev_handle is set to NULL. */
597
609
  struct libusb_device *dev;
598
610
 
599
- /* this lock is held during libusb_submit_transfer() and
600
- * libusb_cancel_transfer() (allowing the OS backend to prevent duplicate
601
- * cancellation, submission-during-cancellation, etc). the OS backend
602
- * should also take this lock in the handle_events path, to prevent the user
603
- * cancelling the transfer from another thread while you are processing
604
- * its completion (presumably there would be races within your OS backend
605
- * if this were possible).
606
- * Note paths taking both this and the flying_transfers_lock must
607
- * always take the flying_transfers_lock first */
608
- usbi_mutex_t lock;
609
-
610
611
  void *priv;
611
612
  };
612
613
 
@@ -814,21 +815,26 @@ struct libusb_device *usbi_alloc_device(struct libusb_context *ctx,
814
815
  struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
815
816
  unsigned long session_id);
816
817
  int usbi_sanitize_device(struct libusb_device *dev);
817
- void usbi_handle_disconnect(struct libusb_device_handle *dev_handle);
818
+ void usbi_handle_disconnect(struct libusb_context *ctx, struct libusb_device_handle *dev_handle);
818
819
 
819
820
  int usbi_handle_transfer_completion(struct usbi_transfer *itransfer,
820
821
  enum libusb_transfer_status status);
821
822
  int usbi_handle_transfer_cancellation(struct usbi_transfer *itransfer);
822
823
  void usbi_signal_transfer_completion(struct usbi_transfer *itransfer);
823
824
 
825
+ void usbi_attach_device(struct libusb_device *dev);
826
+ void usbi_detach_device(struct libusb_device *dev);
827
+
824
828
  void usbi_connect_device(struct libusb_device *dev);
825
829
  void usbi_disconnect_device(struct libusb_device *dev);
826
830
 
831
+ struct usbi_event_source_data {
832
+ usbi_os_handle_t os_handle;
833
+ short poll_events;
834
+ };
835
+
827
836
  struct usbi_event_source {
828
- struct usbi_event_source_data {
829
- usbi_os_handle_t os_handle;
830
- short poll_events;
831
- } data;
837
+ struct usbi_event_source_data data;
832
838
  struct list_head list;
833
839
  };
834
840
 
@@ -995,7 +1001,9 @@ struct usbi_os_backend {
995
1001
  * this point, you should be ready to provide device descriptors and so
996
1002
  * on through the get_*_descriptor functions. Finally, call
997
1003
  * usbi_sanitize_device() to perform some final sanity checks on the
998
- * device. Assuming all of the above succeeded, we can now continue.
1004
+ * device. Assuming all of the above succeeded, call
1005
+ * usbi_connect_device() to add the device to the context's device list
1006
+ * and make it discoverable by usbi_get_device_by_session_id().
999
1007
  * If any of the above failed, remember to unreference the device that
1000
1008
  * was returned by usbi_alloc_device().
1001
1009
  *
@@ -1021,6 +1029,31 @@ struct usbi_os_backend {
1021
1029
  int (*get_device_list)(struct libusb_context *ctx,
1022
1030
  struct discovered_devs **discdevs);
1023
1031
 
1032
+ /* Retrieve a device string without needing to open the device.
1033
+ *
1034
+ * The string should be retrieved without opening the device
1035
+ * and ideally without performing USB transactions to the device.
1036
+ * Most operating systems read and cache the common string
1037
+ * descriptors. Use the OS-specific calls to retrieve these strings.
1038
+ *
1039
+ * Since the USB string descriptor could be processed by the OS,
1040
+ * this function returns a UTF-8 encoded string.
1041
+ *
1042
+ * The string will be returned untranslated or in the default OS language
1043
+ * when supported by the OS and USB device.
1044
+ *
1045
+ * This function must not write more than length bytes into data,
1046
+ * including the null terminator.
1047
+ *
1048
+ * Return:
1049
+ * - The actual length in bytes including the null termintor on success.
1050
+ * - LIBUSB_ERROR_NO_DEVICE if device not found.
1051
+ * - LIBUSB_ERROR_INVALID_PARAM if any parameter is invalid.
1052
+ * - another LIBUSB_ERROR code on other failure
1053
+ */
1054
+ int (*get_device_string)(libusb_device *dev,
1055
+ enum libusb_device_string_type string_type, char *data, int length);
1056
+
1024
1057
  /* Apps which were written before hotplug support, may listen for
1025
1058
  * hotplug events on their own and call libusb_get_device_list on
1026
1059
  * device addition. In this case libusb_get_device_list will likely
@@ -1353,6 +1386,37 @@ struct usbi_os_backend {
1353
1386
  int (*attach_kernel_driver)(struct libusb_device_handle *dev_handle,
1354
1387
  uint8_t interface_number);
1355
1388
 
1389
+ /** Check if RAW_IO is supported by an endpoint.
1390
+ *
1391
+ * Return:
1392
+ * - 1 if yes
1393
+ * - 0 if no
1394
+ * - a LIBUSB_ERROR code on failure
1395
+ */
1396
+ int (*endpoint_supports_raw_io)(struct libusb_device_handle* dev_handle,
1397
+ uint8_t endpoint);
1398
+
1399
+ /** Enable/disable RAW_IO for an endpoint.
1400
+ *
1401
+ * Return:
1402
+ * - 0 on success
1403
+ * - LIBUSB_ERROR_NOT_SUPPORTED if RAW_IO is not supported by the endpoint
1404
+ * - another LIBUSB_ERROR code on other failure
1405
+ */
1406
+ int (*endpoint_set_raw_io)(struct libusb_device_handle* dev_handle,
1407
+ uint8_t endpoint, int enable);
1408
+
1409
+ /* Retrieve the maximum transfer size in bytes supported for WinUSB RAW_IO
1410
+ * for an inbound bulk or interrupt endpoint on an open device. Optional.
1411
+ *
1412
+ * Return:
1413
+ * - a positive maximum transfer size on success
1414
+ * - a LIBUSB_ERROR code on failure
1415
+ */
1416
+ int (*get_max_raw_io_transfer_size)(
1417
+ struct libusb_device_handle *dev_handle,
1418
+ uint8_t endpoint);
1419
+
1356
1420
  /* Destroy a device. Optional.
1357
1421
  *
1358
1422
  * This function is called when the last reference to a device is