usb 2.17.0 → 3.0.0-alpha.2

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 (207) hide show
  1. package/LICENSE +18 -4
  2. package/README.md +25 -516
  3. package/dist/index.d.ts +67 -13
  4. package/dist/index.js +333 -64
  5. package/index.d.ts +89 -0
  6. package/index.js +583 -0
  7. package/package.json +53 -33
  8. package/CHANGELOG.md +0 -294
  9. package/binding.gyp +0 -128
  10. package/dist/index.js.map +0 -1
  11. package/dist/usb/bindings.d.ts +0 -266
  12. package/dist/usb/bindings.js +0 -10
  13. package/dist/usb/bindings.js.map +0 -1
  14. package/dist/usb/capability.d.ts +0 -13
  15. package/dist/usb/capability.js +0 -17
  16. package/dist/usb/capability.js.map +0 -1
  17. package/dist/usb/descriptors.d.ts +0 -128
  18. package/dist/usb/descriptors.js +0 -3
  19. package/dist/usb/descriptors.js.map +0 -1
  20. package/dist/usb/device.d.ts +0 -100
  21. package/dist/usb/device.js +0 -297
  22. package/dist/usb/device.js.map +0 -1
  23. package/dist/usb/endpoint.d.ts +0 -94
  24. package/dist/usb/endpoint.js +0 -219
  25. package/dist/usb/endpoint.js.map +0 -1
  26. package/dist/usb/index.d.ts +0 -31
  27. package/dist/usb/index.js +0 -116
  28. package/dist/usb/index.js.map +0 -1
  29. package/dist/usb/interface.d.ts +0 -80
  30. package/dist/usb/interface.js +0 -133
  31. package/dist/usb/interface.js.map +0 -1
  32. package/dist/webusb/index.d.ts +0 -64
  33. package/dist/webusb/index.js +0 -295
  34. package/dist/webusb/index.js.map +0 -1
  35. package/dist/webusb/webusb-device.d.ts +0 -54
  36. package/dist/webusb/webusb-device.js +0 -434
  37. package/dist/webusb/webusb-device.js.map +0 -1
  38. package/libusb/.clang-tidy +0 -34
  39. package/libusb/.codespellrc +0 -3
  40. package/libusb/.private/README.txt +0 -5
  41. package/libusb/.private/appveyor_build.sh +0 -26
  42. package/libusb/.private/bm.sh +0 -54
  43. package/libusb/.private/ci-build.sh +0 -92
  44. package/libusb/.private/ci-container-build.sh +0 -67
  45. package/libusb/.private/post-rewrite.sh +0 -32
  46. package/libusb/.private/pre-commit.sh +0 -52
  47. package/libusb/.private/wbs.txt +0 -43
  48. package/libusb/.travis.yml +0 -58
  49. package/libusb/AUTHORS +0 -231
  50. package/libusb/COPYING +0 -504
  51. package/libusb/ChangeLog +0 -365
  52. package/libusb/HACKING +0 -25
  53. package/libusb/INSTALL_WIN.txt +0 -52
  54. package/libusb/KEYS +0 -123
  55. package/libusb/Makefile.am +0 -50
  56. package/libusb/NEWS +0 -2
  57. package/libusb/PORTING +0 -94
  58. package/libusb/README +0 -29
  59. package/libusb/README.git +0 -41
  60. package/libusb/TODO +0 -2
  61. package/libusb/Xcode/common.xcconfig +0 -92
  62. package/libusb/Xcode/config.h +0 -31
  63. package/libusb/Xcode/debug.xcconfig +0 -32
  64. package/libusb/Xcode/libusb.xcconfig +0 -21
  65. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +0 -1391
  66. package/libusb/Xcode/libusb_debug.xcconfig +0 -21
  67. package/libusb/Xcode/libusb_release.xcconfig +0 -21
  68. package/libusb/Xcode/release.xcconfig +0 -30
  69. package/libusb/android/README +0 -152
  70. package/libusb/android/config.h +0 -55
  71. package/libusb/android/examples/unrooted_android.c +0 -301
  72. package/libusb/android/examples/unrooted_android.h +0 -36
  73. package/libusb/android/jni/Android.mk +0 -23
  74. package/libusb/android/jni/Application.mk +0 -40
  75. package/libusb/android/jni/examples.mk +0 -168
  76. package/libusb/android/jni/libusb.mk +0 -60
  77. package/libusb/android/jni/tests.mk +0 -45
  78. package/libusb/appveyor.yml +0 -108
  79. package/libusb/autogen.sh +0 -10
  80. package/libusb/bootstrap.sh +0 -10
  81. package/libusb/configure.ac +0 -450
  82. package/libusb/doc/Makefile.in +0 -22
  83. package/libusb/doc/doxygen.cfg.in +0 -2571
  84. package/libusb/doc/libusb.png +0 -0
  85. package/libusb/examples/Makefile.am +0 -12
  86. package/libusb/examples/dpfp.c +0 -711
  87. package/libusb/examples/ezusb.c +0 -846
  88. package/libusb/examples/ezusb.h +0 -109
  89. package/libusb/examples/fxload.c +0 -310
  90. package/libusb/examples/hotplugtest.c +0 -147
  91. package/libusb/examples/listdevs.c +0 -73
  92. package/libusb/examples/sam3u_benchmark.c +0 -228
  93. package/libusb/examples/testlibusb.c +0 -312
  94. package/libusb/examples/xusb.c +0 -1254
  95. package/libusb/libusb/Makefile.am +0 -98
  96. package/libusb/libusb/Makefile.am.extra +0 -26
  97. package/libusb/libusb/core.c +0 -2925
  98. package/libusb/libusb/descriptor.c +0 -1558
  99. package/libusb/libusb/hotplug.c +0 -489
  100. package/libusb/libusb/io.c +0 -2865
  101. package/libusb/libusb/libusb-1.0.def +0 -199
  102. package/libusb/libusb/libusb-1.0.rc +0 -53
  103. package/libusb/libusb/libusb.h +0 -2421
  104. package/libusb/libusb/libusbi.h +0 -1535
  105. package/libusb/libusb/os/darwin_usb.c +0 -2977
  106. package/libusb/libusb/os/darwin_usb.h +0 -156
  107. package/libusb/libusb/os/emscripten_webusb.cpp +0 -875
  108. package/libusb/libusb/os/events_posix.c +0 -340
  109. package/libusb/libusb/os/events_posix.h +0 -62
  110. package/libusb/libusb/os/events_windows.c +0 -214
  111. package/libusb/libusb/os/events_windows.h +0 -46
  112. package/libusb/libusb/os/haiku_pollfs.cpp +0 -372
  113. package/libusb/libusb/os/haiku_usb.h +0 -113
  114. package/libusb/libusb/os/haiku_usb_backend.cpp +0 -532
  115. package/libusb/libusb/os/haiku_usb_raw.cpp +0 -231
  116. package/libusb/libusb/os/haiku_usb_raw.h +0 -188
  117. package/libusb/libusb/os/linux_netlink.c +0 -401
  118. package/libusb/libusb/os/linux_udev.c +0 -321
  119. package/libusb/libusb/os/linux_usbfs.c +0 -2829
  120. package/libusb/libusb/os/linux_usbfs.h +0 -221
  121. package/libusb/libusb/os/netbsd_usb.c +0 -617
  122. package/libusb/libusb/os/null_usb.c +0 -111
  123. package/libusb/libusb/os/openbsd_usb.c +0 -700
  124. package/libusb/libusb/os/sunos_usb.c +0 -1619
  125. package/libusb/libusb/os/sunos_usb.h +0 -79
  126. package/libusb/libusb/os/threads_posix.c +0 -126
  127. package/libusb/libusb/os/threads_posix.h +0 -98
  128. package/libusb/libusb/os/threads_windows.c +0 -40
  129. package/libusb/libusb/os/threads_windows.h +0 -113
  130. package/libusb/libusb/os/windows_common.c +0 -923
  131. package/libusb/libusb/os/windows_common.h +0 -424
  132. package/libusb/libusb/os/windows_usbdk.c +0 -724
  133. package/libusb/libusb/os/windows_usbdk.h +0 -106
  134. package/libusb/libusb/os/windows_winusb.c +0 -4766
  135. package/libusb/libusb/os/windows_winusb.h +0 -787
  136. package/libusb/libusb/strerror.c +0 -223
  137. package/libusb/libusb/sync.c +0 -342
  138. package/libusb/libusb/version.h +0 -18
  139. package/libusb/libusb/version_nano.h +0 -1
  140. package/libusb/libusb-1.0.pc.in +0 -11
  141. package/libusb/msvc/Base.props +0 -60
  142. package/libusb/msvc/Configuration.Application.props +0 -7
  143. package/libusb/msvc/Configuration.Base.props +0 -47
  144. package/libusb/msvc/Configuration.DynamicLibrary.props +0 -21
  145. package/libusb/msvc/Configuration.StaticLibrary.props +0 -7
  146. package/libusb/msvc/ProjectConfigurations.Base.props +0 -69
  147. package/libusb/msvc/build_all.ps1 +0 -17
  148. package/libusb/msvc/config.h +0 -58
  149. package/libusb/msvc/dpfp.vcxproj +0 -33
  150. package/libusb/msvc/dpfp_threaded.vcxproj +0 -38
  151. package/libusb/msvc/fxload.vcxproj +0 -46
  152. package/libusb/msvc/getopt/getopt.c +0 -1060
  153. package/libusb/msvc/getopt/getopt.h +0 -180
  154. package/libusb/msvc/getopt/getopt1.c +0 -188
  155. package/libusb/msvc/getopt.vcxproj +0 -33
  156. package/libusb/msvc/hotplugtest.vcxproj +0 -32
  157. package/libusb/msvc/init_context.vcxproj +0 -35
  158. package/libusb/msvc/libusb.sln +0 -542
  159. package/libusb/msvc/libusb_dll.vcxproj +0 -61
  160. package/libusb/msvc/libusb_static.vcxproj +0 -49
  161. package/libusb/msvc/listdevs.vcxproj +0 -32
  162. package/libusb/msvc/sam3u_benchmark.vcxproj +0 -33
  163. package/libusb/msvc/set_option.vcxproj +0 -35
  164. package/libusb/msvc/stress.vcxproj +0 -35
  165. package/libusb/msvc/stress_mt.vcxproj +0 -33
  166. package/libusb/msvc/testlibusb.vcxproj +0 -32
  167. package/libusb/msvc/xusb.vcxproj +0 -38
  168. package/libusb/tests/Makefile.am +0 -40
  169. package/libusb/tests/init_context.c +0 -153
  170. package/libusb/tests/libusb_testlib.h +0 -76
  171. package/libusb/tests/macos.c +0 -130
  172. package/libusb/tests/set_option.c +0 -253
  173. package/libusb/tests/stress.c +0 -172
  174. package/libusb/tests/stress_mt.c +0 -267
  175. package/libusb/tests/testlib.c +0 -184
  176. package/libusb/tests/umockdev.c +0 -1175
  177. package/libusb/tests/webusb-test-shim/index.js +0 -12
  178. package/libusb/tests/webusb-test-shim/package-lock.json +0 -50
  179. package/libusb/tests/webusb-test-shim/package.json +0 -10
  180. package/libusb.gypi +0 -154
  181. package/libusb_config/config.h +0 -1
  182. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  183. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  184. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  185. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  186. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  187. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  188. package/prebuilds/linux-ia32/node.napi.node +0 -0
  189. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  190. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  191. package/prebuilds/win32-arm64/node.napi.node +0 -0
  192. package/prebuilds/win32-ia32/node.napi.node +0 -0
  193. package/prebuilds/win32-x64/node.napi.node +0 -0
  194. package/src/device.cc +0 -439
  195. package/src/helpers.h +0 -64
  196. package/src/hotplug/hotplug.h +0 -22
  197. package/src/hotplug/libusb.cc +0 -90
  198. package/src/hotplug/windows.cc +0 -168
  199. package/src/node_usb.cc +0 -314
  200. package/src/node_usb.h +0 -131
  201. package/src/thread_name.cc +0 -79
  202. package/src/thread_name.h +0 -11
  203. package/src/transfer.cc +0 -143
  204. package/src/uv_async_queue.h +0 -41
  205. package/test/usb.coffee +0 -250
  206. package/test/webusb.coffee +0 -227
  207. package/test/worker.cjs +0 -13
@@ -1,21 +0,0 @@
1
- //
2
- // libusb Xcode configuration file
3
- // Copyright © 2012 Pete Batard <pete@akeo.ie>
4
- // For more information, please visit: <https://libusb.info>
5
- //
6
- // This library is free software; you can redistribute it and/or
7
- // modify it under the terms of the GNU Lesser General Public
8
- // License as published by the Free Software Foundation; either
9
- // version 2.1 of the License, or (at your option) any later version.
10
- //
11
- // This library is distributed in the hope that it will be useful,
12
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- // Lesser General Public License for more details.
15
- //
16
- // You should have received a copy of the GNU Lesser General Public
17
- // License along with this library; if not, write to the Free Software
18
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
-
20
- #include "debug.xcconfig"
21
- #include "libusb.xcconfig"
@@ -1,21 +0,0 @@
1
- //
2
- // libusb Xcode configuration file
3
- // Copyright © 2012 Pete Batard <pete@akeo.ie>
4
- // For more information, please visit: <https://libusb.info>
5
- //
6
- // This library is free software; you can redistribute it and/or
7
- // modify it under the terms of the GNU Lesser General Public
8
- // License as published by the Free Software Foundation; either
9
- // version 2.1 of the License, or (at your option) any later version.
10
- //
11
- // This library is distributed in the hope that it will be useful,
12
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- // Lesser General Public License for more details.
15
- //
16
- // You should have received a copy of the GNU Lesser General Public
17
- // License along with this library; if not, write to the Free Software
18
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
-
20
- #include "release.xcconfig"
21
- #include "libusb.xcconfig"
@@ -1,30 +0,0 @@
1
- //
2
- // libusb Xcode configuration file
3
- // Copyright © 2012 Pete Batard <pete@akeo.ie>
4
- // For more information, please visit: <https://libusb.info>
5
- //
6
- // This library is free software; you can redistribute it and/or
7
- // modify it under the terms of the GNU Lesser General Public
8
- // License as published by the Free Software Foundation; either
9
- // version 2.1 of the License, or (at your option) any later version.
10
- //
11
- // This library is distributed in the hope that it will be useful,
12
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- // Lesser General Public License for more details.
15
- //
16
- // You should have received a copy of the GNU Lesser General Public
17
- // License along with this library; if not, write to the Free Software
18
- // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
-
20
- #include "common.xcconfig"
21
-
22
- // Put debug symbols in separate .dym file.
23
- DEBUG_INFORMATION_FORMAT = dwarf-with-dsym
24
-
25
- // Optimizations in release.
26
- GCC_OPTIMIZATION_LEVEL = s
27
- LLVM_LTO = YES
28
-
29
- // Define NDEBUG so asserts go away in release.
30
- GCC_PREPROCESSOR_DEFINITIONS = $(inherited) NDEBUG=1
@@ -1,152 +0,0 @@
1
- libusb for Android
2
- ==================
3
-
4
- Building:
5
- ---------
6
-
7
- To build libusb for Android do the following:
8
-
9
- 1. Download the latest NDK from:
10
- http://developer.android.com/tools/sdk/ndk/index.html
11
-
12
- 2. Extract the NDK.
13
-
14
- 3. Open a shell and make sure there exist an NDK global variable
15
- set to the directory where you extracted the NDK.
16
-
17
- 4. Change directory to libusb's "android/jni"
18
-
19
- 5. Run "$NDK/ndk-build".
20
-
21
- The libusb library, examples and tests can then be found in:
22
- "android/libs/$ARCH"
23
-
24
- Where $ARCH is one of:
25
- armeabi
26
- armeabi-v7a
27
- mips
28
- mips64
29
- x86
30
- x86_64
31
-
32
- Installing:
33
- -----------
34
-
35
- If you wish to use libusb from native code in own Android application
36
- then you should add the following line to your Android.mk file:
37
-
38
- include $(PATH_TO_LIBUSB_SRC)/android/jni/libusb.mk
39
-
40
- You will then need to add the following lines to the build
41
- configuration for each native binary which uses libusb:
42
-
43
- LOCAL_C_INCLUDES += $(LIBUSB_ROOT_ABS)
44
- LOCAL_SHARED_LIBRARIES += libusb1.0
45
-
46
- The Android build system will then correctly include libusb in the
47
- application package (APK) file, provided ndk-build is invoked before
48
- the package is built.
49
-
50
-
51
- Runtime Permissions:
52
- --------------------
53
-
54
- The Runtime Permissions on Android can be transferred from Java to Native
55
- over the following approach:
56
-
57
- JAVA:
58
-
59
- --> Obtain USB permissions over the android.hardware.usb.UsbManager class
60
-
61
- usbManager = (UsbManager) getSystemService(Context.USB_SERVICE);
62
- HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
63
- for (UsbDevice usbDevice : deviceList.values()) {
64
- usbManager.requestPermission(usbDevice, mPermissionIntent);
65
- }
66
-
67
- --> Get the native FileDescriptor of the UsbDevice and transfer it to
68
- Native over JNI or JNA
69
-
70
- UsbDeviceConnection usbDeviceConnection = usbManager.openDevice(camDevice);
71
- int fileDescriptor = usbDeviceConnection.getFileDescriptor();
72
-
73
- --> JNA sample method:
74
-
75
- JNA.INSTANCE.set_the_native_Descriptor(fileDescriptor);
76
-
77
- NATIVE:
78
-
79
- --> Initialize libusb on Android
80
-
81
- set_the_native_Descriptor(int fileDescriptor) {
82
- libusb_context *ctx;
83
- libusb_device_handle *devh;
84
- libusb_set_option(&ctx, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL);
85
- libusb_init(&ctx);
86
- libusb_wrap_sys_device(NULL, (intptr_t)fileDescriptor, &devh);
87
- }
88
- /* From this point you can regularly use all libusb functions as usual */
89
-
90
- About LIBUSB_OPTION_NO_DEVICE_DISCOVERY:
91
-
92
- The method libusb_set_option(&ctx, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL)
93
- does not affect the ctx.
94
- It allows initializing libusb on unrooted Android devices by skipping
95
- the device enumeration.
96
-
97
- Rooted Devices:
98
- ---------------
99
-
100
- For rooted devices the code using libusb could be executed as root
101
- using the "su" command. An alternative would be to use the "su" command
102
- to change the permissions on the appropriate /dev/bus/usb/ files.
103
-
104
- Users have reported success in using android.hardware.usb.UsbManager
105
- to request permission to use the UsbDevice and then opening the
106
- device. The difficulties in this method is that there is no guarantee
107
- that it will continue to work in the future Android versions, it
108
- requires invoking Java APIs and running code to match each
109
- android.hardware.usb.UsbDevice to a libusb_device.
110
-
111
- For a rooted device it is possible to install libusb into the system
112
- image of a running device:
113
-
114
- 1. Enable ADB on the device.
115
-
116
- 2. Connect the device to a machine running ADB.
117
-
118
- 3. Execute the following commands on the machine
119
- running ADB:
120
-
121
- # Make the system partition writable
122
- adb shell su -c "mount -o remount,rw /system"
123
-
124
- # Install libusb
125
- adb push obj/local/armeabi/libusb1.0.so /sdcard/
126
- adb shell su -c "cat > /system/lib/libusb1.0.so < /sdcard/libusb1.0.so"
127
- adb shell rm /sdcard/libusb1.0.so
128
-
129
- # Install the samples and tests
130
- for B in listdevs fxload xusb sam3u_benchmark hotplugtest stress
131
- do
132
- adb push "obj/local/armeabi/$B" /sdcard/
133
- adb shell su -c "cat > /system/bin/$B < /sdcard/$B"
134
- adb shell su -c "chmod 0755 /system/bin/$B"
135
- adb shell rm "/sdcard/$B"
136
- done
137
-
138
- # Make the system partition read only again
139
- adb shell su -c "mount -o remount,ro /system"
140
-
141
- # Run listdevs to
142
- adb shell su -c "listdevs"
143
-
144
- 4. If your device only has a single OTG port then ADB can generally
145
- be switched to using Wifi with the following commands when connected
146
- via USB:
147
-
148
- adb shell netcfg
149
- # Note the wifi IP address of the phone
150
- adb tcpip 5555
151
- # Use the IP address from netcfg
152
- adb connect 192.168.1.123:5555
@@ -1,55 +0,0 @@
1
- /*
2
- * Android build config for libusb
3
- * Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
4
- *
5
- * This library is free software; you can redistribute it and/or
6
- * modify it under the terms of the GNU Lesser General Public
7
- * License as published by the Free Software Foundation; either
8
- * version 2.1 of the License, or (at your option) any later version.
9
- *
10
- * This library is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
- * Lesser General Public License for more details.
14
- *
15
- * You should have received a copy of the GNU Lesser General Public
16
- * License along with this library; if not, write to the Free Software
17
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
- */
19
-
20
- /* Define to the attribute for default visibility. */
21
- #define DEFAULT_VISIBILITY __attribute__ ((visibility ("default")))
22
-
23
- /* Define to 1 to start with debug message logging enabled. */
24
- /* #undef ENABLE_DEBUG_LOGGING */
25
-
26
- /* Define to 1 to enable message logging. */
27
- #define ENABLE_LOGGING 1
28
-
29
- /* Define to 1 if you have the <asm/types.h> header file. */
30
- #define HAVE_ASM_TYPES_H 1
31
-
32
- /* Define to 1 if you have the `clock_gettime' function. */
33
- #define HAVE_CLOCK_GETTIME 1
34
-
35
- /* Define to 1 if the system has the type `nfds_t'. */
36
- #define HAVE_NFDS_T 1
37
-
38
- /* Define to 1 if you have the `pipe2' function. */
39
- #define HAVE_PIPE2 1
40
-
41
- /* Define to 1 if you have the <sys/time.h> header file. */
42
- #define HAVE_SYS_TIME_H 1
43
-
44
- /* Define to 1 if compiling for a POSIX platform. */
45
- #define PLATFORM_POSIX 1
46
-
47
- /* Define to the attribute for enabling parameter checks on printf-like
48
- functions. */
49
- #define PRINTF_FORMAT(a, b) __attribute__ ((__format__ (__printf__, a, b)))
50
-
51
- /* Define to 1 to output logging messages to the systemwide log. */
52
- #define USE_SYSTEM_LOGGING_FACILITY 1
53
-
54
- /* Enable GNU extensions. */
55
- #define _GNU_SOURCE 1
@@ -1,301 +0,0 @@
1
- /*
2
- * libusb example program for reading out USB descriptors on unrooted Android
3
- * (based on testlibusb.c)
4
- *
5
- * Copyright 2020-2021 Peter Stoiber
6
- *
7
- * This library is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU Lesser General Public
9
- * License as published by the Free Software Foundation; either
10
- * version 2.1 of the License, or (at your option) any later version.
11
- *
12
- * This library is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
- * Lesser General Public License for more details.
16
- *
17
- * You should have received a copy of the GNU Lesser General Public
18
- * License along with this library; if not, write to the Free Software
19
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
- *
21
- * Please contact the author if you need another license.
22
- * This Repository is provided "as is", without warranties of any kind.
23
- */
24
-
25
- /*
26
- * This example creates a shared object which can be accessed over JNA or JNI from Java or Kotlin in Android.
27
- * Hint: If you are using Android Studio, set the "Debug type" to "Java Only" to receive debug messages.
28
- */
29
-
30
- /*
31
- * Usage:
32
- * First, you have to connect your USB device from the Java side.
33
- * Use the android.hardware.usb class to find the USB device, claim the interfaces, and open the usb_device_connection
34
- * Obtain the native File Descriptor --> usb_device_connection.getFileDescriptor()
35
- * Pass the received int value to the unrooted_usb_description method of this code (over JNA)
36
- */
37
-
38
- /*
39
- * libusb can only be included in Android projects using NDK for now. (CMake is not supported at the moment)
40
- * Clone the libusb git repo into your Android project and include the Android.mk file in your build.gradle.
41
- */
42
-
43
- /*
44
- Example JNA Approach:
45
- public interface unrooted_sample extends Library {
46
- public static final unrooted_sample INSTANCE = Native.load("unrooted_android", unrooted_sample.class);
47
- public int unrooted_usb_description (int fileDescriptor);
48
- }
49
- unrooted_sample.INSTANCE.unrooted_usb_description( usbDeviceConnection.getFileDescriptor());
50
- */
51
-
52
- #include <jni.h>
53
- #include <string.h>
54
- #include "unrooted_android.h"
55
- #include "libusb.h"
56
- #include <android/log.h>
57
- #define LOG_TAG "LibUsb"
58
- #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
59
-
60
- int verbose = 0;
61
-
62
- static void print_endpoint_comp(const struct libusb_ss_endpoint_companion_descriptor *ep_comp)
63
- {
64
- LOGD(" USB 3.0 Endpoint Companion:\n");
65
- LOGD(" bMaxBurst: %u\n", ep_comp->bMaxBurst);
66
- LOGD(" bmAttributes: %02xh\n", ep_comp->bmAttributes);
67
- LOGD(" wBytesPerInterval: %u\n", ep_comp->wBytesPerInterval);
68
- }
69
-
70
- static void print_endpoint(const struct libusb_endpoint_descriptor *endpoint)
71
- {
72
- int i, ret;
73
-
74
- LOGD(" Endpoint:\n");
75
- LOGD(" bEndpointAddress: %02xh\n", endpoint->bEndpointAddress);
76
- LOGD(" bmAttributes: %02xh\n", endpoint->bmAttributes);
77
- LOGD(" wMaxPacketSize: %u\n", endpoint->wMaxPacketSize);
78
- LOGD(" bInterval: %u\n", endpoint->bInterval);
79
- LOGD(" bRefresh: %u\n", endpoint->bRefresh);
80
- LOGD(" bSynchAddress: %u\n", endpoint->bSynchAddress);
81
-
82
- for (i = 0; i < endpoint->extra_length;) {
83
- if (LIBUSB_DT_SS_ENDPOINT_COMPANION == endpoint->extra[i + 1]) {
84
- struct libusb_ss_endpoint_companion_descriptor *ep_comp;
85
-
86
- ret = libusb_get_ss_endpoint_companion_descriptor(NULL, endpoint, &ep_comp);
87
- if (LIBUSB_SUCCESS != ret)
88
- continue;
89
-
90
- print_endpoint_comp(ep_comp);
91
-
92
- libusb_free_ss_endpoint_companion_descriptor(ep_comp);
93
- }
94
-
95
- i += endpoint->extra[i];
96
- }
97
- }
98
-
99
- static void print_altsetting(const struct libusb_interface_descriptor *interface)
100
- {
101
- uint8_t i;
102
-
103
- LOGD(" Interface:\n");
104
- LOGD(" bInterfaceNumber: %u\n", interface->bInterfaceNumber);
105
- LOGD(" bAlternateSetting: %u\n", interface->bAlternateSetting);
106
- LOGD(" bNumEndpoints: %u\n", interface->bNumEndpoints);
107
- LOGD(" bInterfaceClass: %u\n", interface->bInterfaceClass);
108
- LOGD(" bInterfaceSubClass: %u\n", interface->bInterfaceSubClass);
109
- LOGD(" bInterfaceProtocol: %u\n", interface->bInterfaceProtocol);
110
- LOGD(" iInterface: %u\n", interface->iInterface);
111
-
112
- for (i = 0; i < interface->bNumEndpoints; i++)
113
- print_endpoint(&interface->endpoint[i]);
114
- }
115
-
116
- static void print_2_0_ext_cap(struct libusb_usb_2_0_extension_descriptor *usb_2_0_ext_cap)
117
- {
118
- LOGD(" USB 2.0 Extension Capabilities:\n");
119
- LOGD(" bDevCapabilityType: %u\n", usb_2_0_ext_cap->bDevCapabilityType);
120
- LOGD(" bmAttributes: %08xh\n", usb_2_0_ext_cap->bmAttributes);
121
- }
122
-
123
- static void print_ss_usb_cap(struct libusb_ss_usb_device_capability_descriptor *ss_usb_cap)
124
- {
125
- LOGD(" USB 3.0 Capabilities:\n");
126
- LOGD(" bDevCapabilityType: %u\n", ss_usb_cap->bDevCapabilityType);
127
- LOGD(" bmAttributes: %02xh\n", ss_usb_cap->bmAttributes);
128
- LOGD(" wSpeedSupported: %u\n", ss_usb_cap->wSpeedSupported);
129
- LOGD(" bFunctionalitySupport: %u\n", ss_usb_cap->bFunctionalitySupport);
130
- LOGD(" bU1devExitLat: %u\n", ss_usb_cap->bU1DevExitLat);
131
- LOGD(" bU2devExitLat: %u\n", ss_usb_cap->bU2DevExitLat);
132
- }
133
-
134
- static void print_bos(libusb_device_handle *handle)
135
- {
136
- struct libusb_bos_descriptor *bos;
137
- uint8_t i;
138
- int ret;
139
-
140
- ret = libusb_get_bos_descriptor(handle, &bos);
141
- if (ret < 0)
142
- return;
143
-
144
- LOGD(" Binary Object Store (BOS):\n");
145
- LOGD(" wTotalLength: %u\n", bos->wTotalLength);
146
- LOGD(" bNumDeviceCaps: %u\n", bos->bNumDeviceCaps);
147
-
148
- for (i = 0; i < bos->bNumDeviceCaps; i++) {
149
- struct libusb_bos_dev_capability_descriptor *dev_cap = bos->dev_capability[i];
150
-
151
- if (dev_cap->bDevCapabilityType == LIBUSB_BT_USB_2_0_EXTENSION) {
152
- struct libusb_usb_2_0_extension_descriptor *usb_2_0_extension;
153
-
154
- ret = libusb_get_usb_2_0_extension_descriptor(NULL, dev_cap, &usb_2_0_extension);
155
- if (ret < 0)
156
- return;
157
-
158
- print_2_0_ext_cap(usb_2_0_extension);
159
- libusb_free_usb_2_0_extension_descriptor(usb_2_0_extension);
160
- } else if (dev_cap->bDevCapabilityType == LIBUSB_BT_SS_USB_DEVICE_CAPABILITY) {
161
- struct libusb_ss_usb_device_capability_descriptor *ss_dev_cap;
162
-
163
- ret = libusb_get_ss_usb_device_capability_descriptor(NULL, dev_cap, &ss_dev_cap);
164
- if (ret < 0)
165
- return;
166
-
167
- print_ss_usb_cap(ss_dev_cap);
168
- libusb_free_ss_usb_device_capability_descriptor(ss_dev_cap);
169
- }
170
- }
171
-
172
- libusb_free_bos_descriptor(bos);
173
- }
174
-
175
- static void print_interface(const struct libusb_interface *interface)
176
- {
177
- int i;
178
-
179
- for (i = 0; i < interface->num_altsetting; i++)
180
- print_altsetting(&interface->altsetting[i]);
181
- }
182
-
183
- static void print_configuration(struct libusb_config_descriptor *config)
184
- {
185
- uint8_t i;
186
-
187
- LOGD(" Configuration:\n");
188
- LOGD(" wTotalLength: %u\n", config->wTotalLength);
189
- LOGD(" bNumInterfaces: %u\n", config->bNumInterfaces);
190
- LOGD(" bConfigurationValue: %u\n", config->bConfigurationValue);
191
- LOGD(" iConfiguration: %u\n", config->iConfiguration);
192
- LOGD(" bmAttributes: %02xh\n", config->bmAttributes);
193
- LOGD(" MaxPower: %u\n", config->MaxPower);
194
-
195
- for (i = 0; i < config->bNumInterfaces; i++)
196
- print_interface(&config->interface[i]);
197
- }
198
-
199
- static void print_device(libusb_device *dev, libusb_device_handle *handle)
200
- {
201
- struct libusb_device_descriptor desc;
202
- unsigned char string[256];
203
- const char *speed;
204
- int ret;
205
- uint8_t i;
206
-
207
- switch (libusb_get_device_speed(dev)) {
208
- case LIBUSB_SPEED_LOW: speed = "1.5M"; break;
209
- case LIBUSB_SPEED_FULL: speed = "12M"; break;
210
- case LIBUSB_SPEED_HIGH: speed = "480M"; break;
211
- case LIBUSB_SPEED_SUPER: speed = "5G"; break;
212
- case LIBUSB_SPEED_SUPER_PLUS: speed = "10G"; break;
213
- case LIBUSB_SPEED_SUPER_PLUS_X2: speed = "20G"; break;
214
- default: speed = "Unknown";
215
- }
216
-
217
- ret = libusb_get_device_descriptor(dev, &desc);
218
- if (ret < 0) {
219
- LOGD("failed to get device descriptor");
220
- return;
221
- }
222
-
223
- LOGD("Dev (bus %u, device %u): %04X - %04X speed: %s\n",
224
- libusb_get_bus_number(dev), libusb_get_device_address(dev),
225
- desc.idVendor, desc.idProduct, speed);
226
-
227
- if (!handle)
228
- libusb_open(dev, &handle);
229
-
230
- if (handle) {
231
- if (desc.iManufacturer) {
232
- ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
233
- if (ret > 0)
234
- LOGD(" Manufacturer: %s\n", (char *)string);
235
- }
236
-
237
- if (desc.iProduct) {
238
- ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
239
- if (ret > 0)
240
- LOGD(" Product: %s\n", (char *)string);
241
- }
242
-
243
- if (desc.iSerialNumber && verbose) {
244
- ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
245
- if (ret > 0)
246
- LOGD(" Serial Number: %s\n", (char *)string);
247
- }
248
- }
249
-
250
- if (verbose) {
251
- for (i = 0; i < desc.bNumConfigurations; i++) {
252
- struct libusb_config_descriptor *config;
253
-
254
- ret = libusb_get_config_descriptor(dev, i, &config);
255
- if (LIBUSB_SUCCESS != ret) {
256
- LOGD(" Couldn't retrieve descriptors\n");
257
- continue;
258
- }
259
-
260
- print_configuration(config);
261
-
262
- libusb_free_config_descriptor(config);
263
- }
264
-
265
- if (handle && desc.bcdUSB >= 0x0201)
266
- print_bos(handle);
267
- }
268
-
269
- if (handle)
270
- libusb_close(handle);
271
- }
272
-
273
-
274
- /* fileDescriptor = the native file descriptor obtained in Java and transferred to native over JNA, for example */
275
- int unrooted_usb_description(int fileDescriptor)
276
- {
277
- libusb_context *ctx = NULL;
278
- libusb_device_handle *devh = NULL;
279
- int r = 0;
280
- verbose = 1;
281
- r = libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL);
282
- if (r != LIBUSB_SUCCESS) {
283
- LOGD("libusb_set_option failed: %d\n", r);
284
- return -1;
285
- }
286
- r = libusb_init(&ctx);
287
- if (r < 0) {
288
- LOGD("libusb_init failed: %d\n", r);
289
- return r;
290
- }
291
- r = libusb_wrap_sys_device(ctx, (intptr_t)fileDescriptor, &devh);
292
- if (r < 0) {
293
- LOGD("libusb_wrap_sys_device failed: %d\n", r);
294
- return r;
295
- } else if (devh == NULL) {
296
- LOGD("libusb_wrap_sys_device returned invalid handle\n");
297
- return r;
298
- }
299
- print_device(libusb_get_device(devh), devh);
300
- return r;
301
- }
@@ -1,36 +0,0 @@
1
- /*
2
- * Copyright 2021 Peter Stoiber
3
- *
4
- * This library is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU Lesser General Public
6
- * License as published by the Free Software Foundation; either
7
- * version 2.1 of the License, or (at your option) any later version.
8
- *
9
- * This library is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- * Lesser General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU Lesser General Public
15
- * License along with this library; if not, write to the Free Software
16
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
- *
18
- * Please contact the author if you need another license.
19
- * This Repository is provided "as is", without warranties of any kind.
20
- */
21
-
22
- #ifndef unrooted_android_H
23
- #define unrooted_android_H
24
-
25
- #ifdef __cplusplus
26
- extern "C" {
27
- #endif
28
-
29
- extern int unrooted_usb_description(int fileDescriptor);
30
-
31
- #ifdef __cplusplus
32
- }
33
- #endif
34
-
35
- #endif
36
-
@@ -1,23 +0,0 @@
1
- # Android build config for libusb, examples and tests
2
- # Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
3
- #
4
- # This library is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU Lesser General Public
6
- # License as published by the Free Software Foundation; either
7
- # version 2.1 of the License, or (at your option) any later version.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
- #
18
-
19
- LOCAL_PATH := $(call my-dir)
20
-
21
- include $(LOCAL_PATH)/libusb.mk
22
- include $(LOCAL_PATH)/examples.mk
23
- include $(LOCAL_PATH)/tests.mk
@@ -1,40 +0,0 @@
1
- # Android application build config for libusb
2
- # Copyright © 2012-2013 RealVNC Ltd. <toby.gray@realvnc.com>
3
- #
4
- # This library is free software; you can redistribute it and/or
5
- # modify it under the terms of the GNU Lesser General Public
6
- # License as published by the Free Software Foundation; either
7
- # version 2.1 of the License, or (at your option) any later version.
8
- #
9
- # This library is distributed in the hope that it will be useful,
10
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- # Lesser General Public License for more details.
13
- #
14
- # You should have received a copy of the GNU Lesser General Public
15
- # License along with this library; if not, write to the Free Software
16
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
- #
18
-
19
- APP_ABI := all
20
-
21
- APP_CFLAGS := \
22
- -std=gnu11 \
23
- -Wall \
24
- -Wextra \
25
- -Wshadow \
26
- -Wunused \
27
- -Wwrite-strings \
28
- -Werror=format-security \
29
- -Werror=implicit-function-declaration \
30
- -Werror=implicit-int \
31
- -Werror=init-self \
32
- -Werror=missing-prototypes \
33
- -Werror=strict-prototypes \
34
- -Werror=undef \
35
- -Werror=uninitialized
36
-
37
- # Workaround for MIPS toolchain linker being unable to find liblog dependency
38
- # of shared object in NDK versions at least up to r9.
39
- #
40
- APP_LDFLAGS := -llog