usb 2.16.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 (114) hide show
  1. package/CHANGELOG.md +14 -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/endpoint.js +1 -1
  7. package/dist/usb/endpoint.js.map +1 -1
  8. package/dist/usb/index.d.ts +0 -29
  9. package/dist/usb/index.js +4 -18
  10. package/dist/usb/index.js.map +1 -1
  11. package/dist/webusb/index.d.ts +1 -1
  12. package/dist/webusb/index.js +1 -1
  13. package/dist/webusb/index.js.map +1 -1
  14. package/dist/webusb/webusb-device.d.ts +4 -4
  15. package/dist/webusb/webusb-device.js +5 -2
  16. package/dist/webusb/webusb-device.js.map +1 -1
  17. package/libusb/.clang-tidy +36 -0
  18. package/libusb/.private/ci-build.sh +5 -1
  19. package/libusb/AUTHORS +21 -0
  20. package/libusb/ChangeLog +29 -2
  21. package/libusb/KEYS +123 -0
  22. package/libusb/README +8 -9
  23. package/libusb/Xcode/common.xcconfig +20 -0
  24. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +16 -12
  25. package/libusb/android/examples/unrooted_android.c +1 -0
  26. package/libusb/configure.ac +12 -2
  27. package/libusb/examples/dpfp.c +1 -1
  28. package/libusb/examples/ezusb.c +6 -1
  29. package/libusb/examples/fxload.c +7 -5
  30. package/libusb/examples/hotplugtest.c +19 -11
  31. package/libusb/examples/listdevs.c +41 -3
  32. package/libusb/examples/testlibusb.c +1 -0
  33. package/libusb/examples/xusb.c +142 -77
  34. package/libusb/libusb/Makefile.am +4 -0
  35. package/libusb/libusb/core.c +183 -24
  36. package/libusb/libusb/descriptor.c +404 -96
  37. package/libusb/libusb/hotplug.c +27 -8
  38. package/libusb/libusb/io.c +10 -5
  39. package/libusb/libusb/libusb-1.0.def +14 -0
  40. package/libusb/libusb/libusb.h +179 -19
  41. package/libusb/libusb/libusbi.h +101 -25
  42. package/libusb/libusb/os/darwin_usb.c +216 -90
  43. package/libusb/libusb/os/darwin_usb.h +10 -8
  44. package/libusb/libusb/os/emscripten_webusb.cpp +38 -12
  45. package/libusb/libusb/os/events_posix.c +4 -4
  46. package/libusb/libusb/os/haiku_usb_raw.cpp +4 -0
  47. package/libusb/libusb/os/linux_usbfs.c +92 -33
  48. package/libusb/libusb/os/linux_usbfs.h +13 -3
  49. package/libusb/libusb/os/netbsd_usb.c +6 -4
  50. package/libusb/libusb/os/openbsd_usb.c +4 -2
  51. package/libusb/libusb/os/sunos_usb.c +7 -5
  52. package/libusb/libusb/os/threads_posix.c +20 -19
  53. package/libusb/libusb/os/threads_posix.h +9 -3
  54. package/libusb/libusb/os/threads_windows.h +4 -3
  55. package/libusb/libusb/os/windows_common.c +86 -1
  56. package/libusb/libusb/os/windows_common.h +20 -1
  57. package/libusb/libusb/os/windows_hotplug.c +321 -0
  58. package/libusb/libusb/os/windows_hotplug.h +28 -0
  59. package/libusb/libusb/os/windows_usbdk.c +16 -8
  60. package/libusb/libusb/os/windows_winusb.c +788 -56
  61. package/libusb/libusb/os/windows_winusb.h +11 -6
  62. package/libusb/libusb/sync.c +8 -5
  63. package/libusb/libusb/version.h +1 -1
  64. package/libusb/libusb/version_nano.h +1 -1
  65. package/libusb/msvc/Base.props +1 -1
  66. package/libusb/msvc/Configuration.Base.props +2 -1
  67. package/libusb/msvc/Configuration.DynamicLibrary.props +12 -0
  68. package/libusb/msvc/ProjectConfigurations.Base.props +69 -16
  69. package/libusb/msvc/build_all.ps1 +2 -2
  70. package/libusb/msvc/config.h +4 -0
  71. package/libusb/msvc/getopt/bits/getopt_core.h +96 -0
  72. package/libusb/msvc/getopt/bits/getopt_ext.h +77 -0
  73. package/libusb/msvc/getopt/features.h +21 -0
  74. package/libusb/msvc/getopt/getopt.c +456 -705
  75. package/libusb/msvc/getopt/getopt.h +16 -158
  76. package/libusb/msvc/getopt/getopt1.c +40 -69
  77. package/libusb/msvc/getopt/getopt_int.h +118 -0
  78. package/libusb/msvc/getopt/gettext.h +7 -0
  79. package/libusb/msvc/getopt/unistd.h +5 -0
  80. package/libusb/msvc/getopt.vcxproj +11 -4
  81. package/libusb/msvc/libusb.sln +515 -268
  82. package/libusb/msvc/libusb_dll.vcxproj +2 -0
  83. package/libusb/msvc/libusb_static.vcxproj +2 -0
  84. package/libusb/msvc/xusb.vcxproj +1 -1
  85. package/libusb/tests/Makefile.am +10 -1
  86. package/libusb/tests/fuzz/corpus/bos/min.bos +0 -0
  87. package/libusb/tests/fuzz/corpus/descriptor_parsers/min_valid_config.bin +0 -0
  88. package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_a_endpoint_null.bin +0 -0
  89. package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_b_iad_oob.bin +0 -0
  90. package/libusb/tests/fuzz/fuzz_bos_descriptor.c +49 -0
  91. package/libusb/tests/fuzz/fuzz_descriptor_parsers.c +83 -0
  92. package/libusb/tests/macos.c +2 -2
  93. package/libusb/tests/stress_mt.c +6 -3
  94. package/libusb/tests/webusb-test-shim/index.js +6 -5
  95. package/libusb.gypi +5 -0
  96. package/package.json +3 -3
  97. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  98. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  99. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  100. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  101. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  102. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  103. package/prebuilds/linux-ia32/node.napi.node +0 -0
  104. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  105. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  106. package/prebuilds/win32-arm64/node.napi.node +0 -0
  107. package/prebuilds/win32-ia32/node.napi.node +0 -0
  108. package/prebuilds/win32-x64/node.napi.node +0 -0
  109. package/src/{hotplug/libusb.cc → hotplug.cc} +2 -3
  110. package/src/{hotplug/hotplug.h → hotplug.h} +2 -6
  111. package/src/node_usb.cc +3 -3
  112. package/test/usb.coffee +4 -4
  113. package/test/webusb.coffee +22 -12
  114. package/src/hotplug/windows.cc +0 -168
@@ -103,6 +103,17 @@ typedef volatile LONG usbi_atomic_t;
103
103
  #define usbi_atomic_inc(a) InterlockedIncrement((a))
104
104
  #define usbi_atomic_dec(a) InterlockedDecrement((a))
105
105
  #else
106
+ #if defined(__HAIKU__) && defined(__GNUC__) && !defined(__clang__)
107
+ /* The Haiku port of libusb has some C++ files and GCC does not define
108
+ * anything in stdatomic.h when compiled in C++11 (only in C++23).
109
+ * This appears to be a bug in gcc's stdatomic.h, and should be fixed either
110
+ * in gcc or in Haiku. Until then, use the gcc builtins. */
111
+ typedef long usbi_atomic_t;
112
+ #define usbi_atomic_load(a) __atomic_load_n((a), __ATOMIC_SEQ_CST)
113
+ #define usbi_atomic_store(a, v) __atomic_store_n((a), (v), __ATOMIC_SEQ_CST)
114
+ #define usbi_atomic_inc(a) __atomic_add_fetch((a), 1, __ATOMIC_SEQ_CST)
115
+ #define usbi_atomic_dec(a) __atomic_sub_fetch((a), 1, __ATOMIC_SEQ_CST)
116
+ #else
106
117
  #include <stdatomic.h>
107
118
  typedef atomic_long usbi_atomic_t;
108
119
  #define usbi_atomic_load(a) atomic_load((a))
@@ -110,6 +121,7 @@ typedef atomic_long usbi_atomic_t;
110
121
  #define usbi_atomic_inc(a) (atomic_fetch_add((a), 1) + 1)
111
122
  #define usbi_atomic_dec(a) (atomic_fetch_add((a), -1) - 1)
112
123
  #endif
124
+ #endif
113
125
 
114
126
  /* Internal abstractions for event handling and thread synchronization */
115
127
  #if defined(PLATFORM_POSIX)
@@ -357,30 +369,30 @@ struct libusb_context {
357
369
  usbi_timer_t timer;
358
370
  #endif
359
371
 
360
- struct list_head usb_devs;
361
372
  usbi_mutex_t usb_devs_lock;
373
+ struct list_head usb_devs;
362
374
 
363
375
  /* A list of open handles. Backends are free to traverse this if required.
364
376
  */
365
- struct list_head open_devs;
366
377
  usbi_mutex_t open_devs_lock;
378
+ struct list_head open_devs;
367
379
 
368
380
  /* A list of registered hotplug callbacks */
381
+ usbi_mutex_t hotplug_cbs_lock;
369
382
  struct list_head hotplug_cbs;
370
383
  libusb_hotplug_callback_handle next_hotplug_cb_handle;
371
- usbi_mutex_t hotplug_cbs_lock;
372
384
 
373
385
  /* A flag to indicate that the context is ready for hotplug notifications */
374
386
  usbi_atomic_t hotplug_ready;
375
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;
376
391
  /* this is a list of in-flight transfer handles, sorted by timeout
377
392
  * expiration. URBs to timeout the soonest are placed at the beginning of
378
393
  * the list, URBs that will time out later are placed after, and urbs with
379
394
  * infinite timeout are always placed at the very end. */
380
395
  struct list_head flying_transfers;
381
- /* Note paths taking both this and usbi_transfer->lock must always
382
- * take this lock first */
383
- usbi_mutex_t flying_transfers_lock; /* for flying_transfers and timeout_flags */
384
396
 
385
397
  #if !defined(PLATFORM_WINDOWS)
386
398
  /* user callbacks for pollfd changes */
@@ -439,8 +451,8 @@ struct libusb_context {
439
451
  extern struct libusb_context *usbi_default_context;
440
452
  extern struct libusb_context *usbi_fallback_context;
441
453
 
442
- extern struct list_head active_contexts_list;
443
454
  extern usbi_mutex_static_t active_contexts_lock;
455
+ extern struct list_head active_contexts_list;
444
456
 
445
457
  static inline struct libusb_context *usbi_get_context(struct libusb_context *ctx)
446
458
  {
@@ -511,6 +523,8 @@ struct libusb_device {
511
523
 
512
524
  struct libusb_device_descriptor device_descriptor;
513
525
  usbi_atomic_t attached;
526
+
527
+ char * device_strings_utf8[LIBUSB_DEVICE_STRING_COUNT];
514
528
  };
515
529
 
516
530
  struct libusb_device_handle {
@@ -571,7 +585,17 @@ void usbi_get_real_time(struct timespec *tp);
571
585
  */
572
586
 
573
587
  struct usbi_transfer {
574
- 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
+
575
599
  struct list_head list;
576
600
  struct list_head completed_list;
577
601
  struct timespec timeout;
@@ -584,17 +608,6 @@ struct usbi_transfer {
584
608
  * even after dev_handle is set to NULL. */
585
609
  struct libusb_device *dev;
586
610
 
587
- /* this lock is held during libusb_submit_transfer() and
588
- * libusb_cancel_transfer() (allowing the OS backend to prevent duplicate
589
- * cancellation, submission-during-cancellation, etc). the OS backend
590
- * should also take this lock in the handle_events path, to prevent the user
591
- * cancelling the transfer from another thread while you are processing
592
- * its completion (presumably there would be races within your OS backend
593
- * if this were possible).
594
- * Note paths taking both this and the flying_transfers_lock must
595
- * always take the flying_transfers_lock first */
596
- usbi_mutex_t lock;
597
-
598
611
  void *priv;
599
612
  };
600
613
 
@@ -802,21 +815,26 @@ struct libusb_device *usbi_alloc_device(struct libusb_context *ctx,
802
815
  struct libusb_device *usbi_get_device_by_session_id(struct libusb_context *ctx,
803
816
  unsigned long session_id);
804
817
  int usbi_sanitize_device(struct libusb_device *dev);
805
- 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);
806
819
 
807
820
  int usbi_handle_transfer_completion(struct usbi_transfer *itransfer,
808
821
  enum libusb_transfer_status status);
809
822
  int usbi_handle_transfer_cancellation(struct usbi_transfer *itransfer);
810
823
  void usbi_signal_transfer_completion(struct usbi_transfer *itransfer);
811
824
 
825
+ void usbi_attach_device(struct libusb_device *dev);
826
+ void usbi_detach_device(struct libusb_device *dev);
827
+
812
828
  void usbi_connect_device(struct libusb_device *dev);
813
829
  void usbi_disconnect_device(struct libusb_device *dev);
814
830
 
831
+ struct usbi_event_source_data {
832
+ usbi_os_handle_t os_handle;
833
+ short poll_events;
834
+ };
835
+
815
836
  struct usbi_event_source {
816
- struct usbi_event_source_data {
817
- usbi_os_handle_t os_handle;
818
- short poll_events;
819
- } data;
837
+ struct usbi_event_source_data data;
820
838
  struct list_head list;
821
839
  };
822
840
 
@@ -983,7 +1001,9 @@ struct usbi_os_backend {
983
1001
  * this point, you should be ready to provide device descriptors and so
984
1002
  * on through the get_*_descriptor functions. Finally, call
985
1003
  * usbi_sanitize_device() to perform some final sanity checks on the
986
- * 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().
987
1007
  * If any of the above failed, remember to unreference the device that
988
1008
  * was returned by usbi_alloc_device().
989
1009
  *
@@ -1009,6 +1029,31 @@ struct usbi_os_backend {
1009
1029
  int (*get_device_list)(struct libusb_context *ctx,
1010
1030
  struct discovered_devs **discdevs);
1011
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
+
1012
1057
  /* Apps which were written before hotplug support, may listen for
1013
1058
  * hotplug events on their own and call libusb_get_device_list on
1014
1059
  * device addition. In this case libusb_get_device_list will likely
@@ -1341,6 +1386,37 @@ struct usbi_os_backend {
1341
1386
  int (*attach_kernel_driver)(struct libusb_device_handle *dev_handle,
1342
1387
  uint8_t interface_number);
1343
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
+
1344
1420
  /* Destroy a device. Optional.
1345
1421
  *
1346
1422
  * This function is called when the last reference to a device is