usb 2.1.3 → 2.2.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 (279) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +3 -0
  3. package/dist/index.d.ts +2 -1
  4. package/dist/index.js +3 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/usb/bindings.d.ts +4 -0
  7. package/dist/usb/device.js +5 -0
  8. package/dist/usb/device.js.map +1 -1
  9. package/libusb/.gitattributes +2 -6
  10. package/libusb/.private/appveyor_build.sh +22 -0
  11. package/libusb/.private/bm.sh +1 -1
  12. package/libusb/.private/ci-build.sh +67 -0
  13. package/libusb/.private/post-rewrite.sh +5 -1
  14. package/libusb/.private/pre-commit.sh +5 -1
  15. package/libusb/.private/wbs.txt +4 -19
  16. package/libusb/.travis.yml +32 -23
  17. package/libusb/AUTHORS +76 -3
  18. package/libusb/ChangeLog +41 -3
  19. package/libusb/INSTALL_WIN.txt +22 -44
  20. package/libusb/Makefile.am +32 -10
  21. package/libusb/{README.md → README} +2 -2
  22. package/libusb/README.git +3 -3
  23. package/libusb/Xcode/common.xcconfig +23 -19
  24. package/libusb/Xcode/config.h +25 -13
  25. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
  26. package/libusb/android/README +90 -54
  27. package/libusb/android/config.h +23 -43
  28. package/libusb/android/examples/unrooted_android.c +301 -0
  29. package/libusb/android/examples/unrooted_android.h +36 -0
  30. package/libusb/android/jni/Android.mk +1 -1
  31. package/libusb/android/jni/Application.mk +16 -0
  32. package/libusb/android/jni/examples.mk +63 -29
  33. package/libusb/android/jni/libusb.mk +14 -8
  34. package/libusb/android/jni/tests.mk +13 -24
  35. package/libusb/appveyor.yml +69 -30
  36. package/libusb/autogen.sh +5 -3
  37. package/libusb/bootstrap.sh +6 -2
  38. package/libusb/configure.ac +302 -228
  39. package/libusb/doc/Makefile.in +22 -0
  40. package/libusb/doc/doxygen.cfg.in +460 -223
  41. package/libusb/examples/Makefile.am +6 -13
  42. package/libusb/examples/dpfp.c +276 -73
  43. package/libusb/examples/ezusb.c +18 -8
  44. package/libusb/examples/ezusb.h +6 -17
  45. package/libusb/examples/fxload.c +4 -5
  46. package/libusb/examples/hotplugtest.c +1 -1
  47. package/libusb/examples/sam3u_benchmark.c +59 -24
  48. package/libusb/examples/testlibusb.c +138 -104
  49. package/libusb/examples/xusb.c +26 -22
  50. package/libusb/libusb/Makefile.am +57 -70
  51. package/libusb/libusb/Makefile.am.extra +26 -0
  52. package/libusb/libusb/core.c +420 -423
  53. package/libusb/libusb/descriptor.c +365 -419
  54. package/libusb/libusb/hotplug.c +197 -104
  55. package/libusb/libusb/io.c +491 -528
  56. package/libusb/libusb/libusb-1.0.def +7 -3
  57. package/libusb/libusb/libusb-1.0.rc +1 -9
  58. package/libusb/libusb/libusb.h +295 -226
  59. package/libusb/libusb/libusbi.h +587 -314
  60. package/libusb/libusb/os/darwin_usb.c +634 -317
  61. package/libusb/libusb/os/darwin_usb.h +39 -15
  62. package/libusb/libusb/os/events_posix.c +300 -0
  63. package/libusb/libusb/os/events_posix.h +59 -0
  64. package/libusb/libusb/os/events_windows.c +214 -0
  65. package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
  66. package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
  67. package/libusb/libusb/os/haiku_usb.h +12 -12
  68. package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
  69. package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
  70. package/libusb/libusb/os/linux_netlink.c +55 -63
  71. package/libusb/libusb/os/linux_udev.c +61 -69
  72. package/libusb/libusb/os/linux_usbfs.c +926 -1015
  73. package/libusb/libusb/os/linux_usbfs.h +74 -57
  74. package/libusb/libusb/os/netbsd_usb.c +103 -168
  75. package/libusb/libusb/os/null_usb.c +111 -0
  76. package/libusb/libusb/os/openbsd_usb.c +71 -120
  77. package/libusb/libusb/os/sunos_usb.c +289 -375
  78. package/libusb/libusb/os/sunos_usb.h +0 -1
  79. package/libusb/libusb/os/threads_posix.c +81 -32
  80. package/libusb/libusb/os/threads_posix.h +19 -23
  81. package/libusb/libusb/os/threads_windows.c +9 -95
  82. package/libusb/libusb/os/threads_windows.h +33 -31
  83. package/libusb/libusb/os/windows_common.c +904 -0
  84. package/libusb/libusb/os/windows_common.h +329 -42
  85. package/libusb/libusb/os/windows_usbdk.c +161 -267
  86. package/libusb/libusb/os/windows_usbdk.h +5 -2
  87. package/libusb/libusb/os/windows_winusb.c +1326 -1190
  88. package/libusb/libusb/os/windows_winusb.h +167 -167
  89. package/libusb/libusb/strerror.c +20 -30
  90. package/libusb/libusb/sync.c +20 -21
  91. package/libusb/libusb/version.h +1 -1
  92. package/libusb/libusb/version_nano.h +1 -1
  93. package/libusb/msvc/.gitattributes +3 -0
  94. package/libusb/msvc/config.h +27 -20
  95. package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
  96. package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
  97. package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
  98. package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
  99. package/libusb/msvc/dpfp_2017.vcxproj +106 -0
  100. package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
  101. package/libusb/msvc/dpfp_2019.vcxproj +106 -0
  102. package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
  103. package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
  104. package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
  105. package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
  106. package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
  107. package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
  108. package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
  109. package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
  110. package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
  111. package/libusb/msvc/fxload_2013.vcxproj +6 -3
  112. package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
  113. package/libusb/msvc/fxload_2015.vcxproj +6 -3
  114. package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
  115. package/libusb/msvc/fxload_2017.vcxproj +6 -7
  116. package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
  117. package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
  118. package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
  119. package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
  120. package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
  121. package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
  122. package/libusb/msvc/getopt_2013.vcxproj +4 -5
  123. package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
  124. package/libusb/msvc/getopt_2015.vcxproj +4 -4
  125. package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
  126. package/libusb/msvc/getopt_2017.vcxproj +4 -10
  127. package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
  128. package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
  129. package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
  130. package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
  131. package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
  132. package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
  133. package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
  134. package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
  135. package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
  136. package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
  137. package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
  138. package/libusb/msvc/libusb_2013.sln +50 -20
  139. package/libusb/msvc/libusb_2015.sln +51 -21
  140. package/libusb/msvc/libusb_2017.sln +90 -36
  141. package/libusb/msvc/libusb_2019.sln +240 -0
  142. package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
  143. package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
  144. package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
  145. package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
  146. package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
  147. package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
  148. package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
  149. package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
  150. package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
  151. package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
  152. package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
  153. package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
  154. package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
  155. package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
  156. package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
  157. package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
  158. package/libusb/msvc/listdevs_2013.vcxproj +6 -3
  159. package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
  160. package/libusb/msvc/listdevs_2015.vcxproj +6 -3
  161. package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
  162. package/libusb/msvc/listdevs_2017.vcxproj +6 -7
  163. package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
  164. package/libusb/msvc/listdevs_2019.vcxproj +105 -0
  165. package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
  166. package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
  167. package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
  168. package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
  169. package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
  170. package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
  171. package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
  172. package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
  173. package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
  174. package/libusb/msvc/stress_2013.vcxproj +4 -2
  175. package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
  176. package/libusb/msvc/stress_2015.vcxproj +4 -2
  177. package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
  178. package/libusb/msvc/stress_2017.vcxproj +4 -6
  179. package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
  180. package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
  181. package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
  182. package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
  183. package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
  184. package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
  185. package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
  186. package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
  187. package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
  188. package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
  189. package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
  190. package/libusb/msvc/xusb_2013.vcxproj +6 -3
  191. package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
  192. package/libusb/msvc/xusb_2015.vcxproj +6 -3
  193. package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
  194. package/libusb/msvc/xusb_2017.vcxproj +6 -7
  195. package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
  196. package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
  197. package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
  198. package/libusb/tests/Makefile.am +1 -0
  199. package/libusb/tests/libusb_testlib.h +12 -43
  200. package/libusb/tests/stress.c +59 -50
  201. package/libusb/tests/testlib.c +78 -171
  202. package/libusb.gypi +10 -11
  203. package/package.json +1 -1
  204. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  205. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  206. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  207. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  208. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  209. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  210. package/prebuilds/linux-ia32/node.napi.node +0 -0
  211. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  212. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  213. package/prebuilds/win32-ia32/node.napi.node +0 -0
  214. package/prebuilds/win32-x64/node.napi.node +0 -0
  215. package/src/device.cc +12 -7
  216. package/src/node_usb.cc +10 -0
  217. package/test/usb.coffee +6 -0
  218. package/tsc/index.ts +2 -0
  219. package/tsc/usb/bindings.ts +5 -0
  220. package/tsc/usb/device.ts +6 -0
  221. package/libusb/.private/bd.cmd +0 -89
  222. package/libusb/.private/bwince.cmd +0 -57
  223. package/libusb/.private/wbs_wince.txt +0 -42
  224. package/libusb/Brewfile +0 -4
  225. package/libusb/appveyor_cygwin.bat +0 -11
  226. package/libusb/appveyor_minGW.bat +0 -19
  227. package/libusb/doc/Makefile.am +0 -9
  228. package/libusb/examples/dpfp_threaded.c +0 -557
  229. package/libusb/libusb/hotplug.h +0 -99
  230. package/libusb/libusb/os/poll_posix.c +0 -84
  231. package/libusb/libusb/os/poll_posix.h +0 -14
  232. package/libusb/libusb/os/poll_windows.c +0 -447
  233. package/libusb/libusb/os/poll_windows.h +0 -98
  234. package/libusb/libusb/os/wince_usb.c +0 -888
  235. package/libusb/libusb/os/wince_usb.h +0 -126
  236. package/libusb/libusb/os/windows_nt_common.c +0 -1010
  237. package/libusb/libusb/os/windows_nt_common.h +0 -110
  238. package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
  239. package/libusb/msvc/appveyor.bat +0 -27
  240. package/libusb/msvc/ddk_build.cmd +0 -219
  241. package/libusb/msvc/errno.h +0 -102
  242. package/libusb/msvc/fxload_sources +0 -23
  243. package/libusb/msvc/getopt_2005.vcproj +0 -288
  244. package/libusb/msvc/getopt_2010.vcxproj +0 -72
  245. package/libusb/msvc/getopt_sources +0 -24
  246. package/libusb/msvc/hotplugtest_sources +0 -20
  247. package/libusb/msvc/inttypes.h +0 -295
  248. package/libusb/msvc/libusb.dsw +0 -71
  249. package/libusb/msvc/libusb_2005.sln +0 -95
  250. package/libusb/msvc/libusb_2010.sln +0 -105
  251. package/libusb/msvc/libusb_2012.sln +0 -105
  252. package/libusb/msvc/libusb_dll.dsp +0 -194
  253. package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
  254. package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
  255. package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
  256. package/libusb/msvc/libusb_sources +0 -43
  257. package/libusb/msvc/libusb_static.dsp +0 -174
  258. package/libusb/msvc/libusb_static_2005.vcproj +0 -390
  259. package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
  260. package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
  261. package/libusb/msvc/libusb_wince.sln +0 -246
  262. package/libusb/msvc/listdevs.dsp +0 -103
  263. package/libusb/msvc/listdevs_2005.vcproj +0 -360
  264. package/libusb/msvc/listdevs_sources +0 -20
  265. package/libusb/msvc/listdevs_wince.vcproj +0 -1120
  266. package/libusb/msvc/missing.c +0 -80
  267. package/libusb/msvc/stdint.h +0 -256
  268. package/libusb/msvc/stress_2005.vcproj +0 -390
  269. package/libusb/msvc/stress_2012.vcxproj +0 -87
  270. package/libusb/msvc/stress_sources +0 -21
  271. package/libusb/msvc/stress_wince.vcproj +0 -1128
  272. package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
  273. package/libusb/msvc/testlibusb_sources +0 -20
  274. package/libusb/msvc/xusb.dsp +0 -102
  275. package/libusb/msvc/xusb_2005.vcproj +0 -344
  276. package/libusb/msvc/xusb_2012.vcxproj +0 -83
  277. package/libusb/msvc/xusb_sources +0 -20
  278. package/libusb/msvc/xusb_wince.vcproj +0 -1120
  279. package/libusb/travis-autogen.sh +0 -39
@@ -48,69 +48,105 @@ application package (APK) file, provided ndk-build is invoked before
48
48
  the package is built.
49
49
 
50
50
 
51
- For a rooted device it is possible to install libusb into the system
52
- image of a running device:
51
+ Runtime Permissions:
52
+ --------------------
53
53
 
54
- 1. Enable ADB on the device.
54
+ The Runtime Permissions on Android can be transferred from Java to Native
55
+ over the following approach:
55
56
 
56
- 2. Connect the device to a machine running ADB.
57
+ JAVA:
57
58
 
58
- 3. Execute the following commands on the machine
59
- running ADB:
59
+ --> Obtain USB permissions over the android.hardware.usb.UsbManager class
60
60
 
61
- # Make the system partition writable
62
- adb shell su -c "mount -o remount,rw /system"
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
+ }
63
66
 
64
- # Install libusb
65
- adb push obj/local/armeabi/libusb1.0.so /sdcard/
66
- adb shell su -c "cat > /system/lib/libusb1.0.so < /sdcard/libusb1.0.so"
67
- adb shell rm /sdcard/libusb1.0.so
67
+ --> Get the native FileDescriptor of the UsbDevice and transfer it to
68
+ Native over JNI or JNA
68
69
 
69
- # Install the samples and tests
70
- for B in listdevs fxload xusb sam3u_benchmark hotplugtest stress
71
- do
72
- adb push "obj/local/armeabi/$B" /sdcard/
73
- adb shell su -c "cat > /system/bin/$B < /sdcard/$B"
74
- adb shell su -c "chmod 0755 /system/bin/$B"
75
- adb shell rm "/sdcard/$B"
76
- done
70
+ UsbDeviceConnection usbDeviceConnection = usbManager.openDevice(camDevice);
71
+ int fileDescriptor = usbDeviceConnection.getFileDescriptor();
77
72
 
78
- # Make the system partition read only again
79
- adb shell su -c "mount -o remount,ro /system"
73
+ --> JNA sample method:
80
74
 
81
- # Run listdevs to
82
- adb shell su -c "listdevs"
75
+ JNA.INSTANCE.set_the_native_Descriptor(fileDescriptor);
83
76
 
84
- 4. If your device only has a single OTG port then ADB can generally
85
- be switched to using Wifi with the following commands when connected
86
- via USB:
77
+ NATIVE:
87
78
 
88
- adb shell netcfg
89
- # Note the wifi IP address of the phone
90
- adb tcpip 5555
91
- # Use the IP address from netcfg
92
- adb connect 192.168.1.123:5555
79
+ --> Initialize libusb on Android
93
80
 
94
- Runtime Permissions:
95
- --------------------
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:
96
147
 
97
- The default system configuration on most Android device will not allow
98
- access to USB devices. There are several options for changing this.
99
-
100
- If you have control of the system image then you can modify the
101
- ueventd.rc used in the image to change the permissions on
102
- /dev/bus/usb/*/*. If using this approach then it is advisable to
103
- create a new Android permission to protect access to these files.
104
- It is not advisable to give all applications read and write permissions
105
- to these files.
106
-
107
- For rooted devices the code using libusb could be executed as root
108
- using the "su" command. An alternative would be to use the "su" command
109
- to change the permissions on the appropriate /dev/bus/usb/ files.
110
-
111
- Users have reported success in using android.hardware.usb.UsbManager
112
- to request permission to use the UsbDevice and then opening the
113
- device. The difficulties in this method is that there is no guarantee
114
- that it will continue to work in the future Android versions, it
115
- requires invoking Java APIs and running code to match each
116
- android.hardware.usb.UsbDevice to a libusb_device.
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
@@ -17,59 +17,39 @@
17
17
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
18
  */
19
19
 
20
- /* Start with debug message logging enabled */
21
- /* #undef ENABLE_DEBUG_LOGGING */
22
-
23
- /* Message logging */
24
- #define ENABLE_LOGGING
25
-
26
- /* Define to 1 if you have the <dlfcn.h> header file. */
27
- #define HAVE_DLFCN_H 1
28
-
29
- /* Define to 1 if you have the <inttypes.h> header file. */
30
- #define HAVE_INTTYPES_H 1
20
+ /* Define to the attribute for default visibility. */
21
+ #define DEFAULT_VISIBILITY __attribute__ ((visibility ("default")))
31
22
 
32
- /* Linux backend */
33
- #define OS_LINUX 1
34
-
35
- /* Enable output to system log */
36
- #define USE_SYSTEM_LOGGING_FACILITY 1
37
-
38
- /* type of second poll() argument */
39
- #define POLL_NFDS_TYPE nfds_t
23
+ /* Define to 1 to start with debug message logging enabled. */
24
+ /* #undef ENABLE_DEBUG_LOGGING */
40
25
 
41
- /* Use POSIX Threads */
42
- #define THREADS_POSIX 1
26
+ /* Define to 1 to enable message logging. */
27
+ #define ENABLE_LOGGING 1
43
28
 
44
- /* Default visibility */
45
- #define DEFAULT_VISIBILITY __attribute__((visibility("default")))
29
+ /* Define to 1 if you have the <asm/types.h> header file. */
30
+ #define HAVE_ASM_TYPES_H 1
46
31
 
47
- /* Define to 1 if you have the <memory.h> header file. */
48
- #define HAVE_MEMORY_H 1
32
+ /* Define to 1 if you have the `clock_gettime' function. */
33
+ #define HAVE_CLOCK_GETTIME 1
49
34
 
50
- /* Define to 1 if you have the <poll.h> header file. */
51
- #define HAVE_POLL_H 1
35
+ /* Define to 1 if the system has the type `nfds_t'. */
36
+ #define HAVE_NFDS_T 1
52
37
 
53
- /* Define to 1 if you have the <sys/stat.h> header file. */
54
- #define HAVE_SYS_STAT_H 1
38
+ /* Define to 1 if you have the `pipe2' function. */
39
+ #define HAVE_PIPE2 1
55
40
 
56
41
  /* Define to 1 if you have the <sys/time.h> header file. */
57
42
  #define HAVE_SYS_TIME_H 1
58
43
 
59
- /* Define to 1 if you have the <sys/types.h> header file. */
60
- #define HAVE_SYS_TYPES_H 1
61
-
62
- /* Define to 1 if you have the <unistd.h> header file. */
63
- #define HAVE_UNISTD_H 1
64
-
65
- /* Define to 1 if you have the <linux/filter.h> header file. */
66
- #define HAVE_LINUX_FILTER_H 1
44
+ /* Define to 1 if compiling for a POSIX platform. */
45
+ #define PLATFORM_POSIX 1
67
46
 
68
- /* Define to 1 if you have the <linux/netlink.h> header file. */
69
- #define HAVE_LINUX_NETLINK_H 1
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)))
70
50
 
71
- /* Define to 1 if you have the <asm/types.h> header file. */
72
- #define HAVE_ASM_TYPES_H 1
51
+ /* Define to 1 to output logging messages to the systemwide log. */
52
+ #define USE_SYSTEM_LOGGING_FACILITY 1
73
53
 
74
- /* Define to 1 if you have the <sys/socket.h> header file. */
75
- #define HAVE_SYS_SOCKET_H 1
54
+ /* Enable GNU extensions. */
55
+ #define _GNU_SOURCE 1
@@ -0,0 +1,301 @@
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
+ default: speed = "Unknown";
214
+ }
215
+
216
+ ret = libusb_get_device_descriptor(dev, &desc);
217
+ if (ret < 0) {
218
+ LOGD("failed to get device descriptor");
219
+ return;
220
+ }
221
+
222
+ LOGD("Dev (bus %u, device %u): %04X - %04X speed: %s\n",
223
+ libusb_get_bus_number(dev), libusb_get_device_address(dev),
224
+ desc.idVendor, desc.idProduct, speed);
225
+
226
+ if (!handle)
227
+ libusb_open(dev, &handle);
228
+
229
+ if (handle) {
230
+ if (desc.iManufacturer) {
231
+ ret = libusb_get_string_descriptor_ascii(handle, desc.iManufacturer, string, sizeof(string));
232
+ if (ret > 0)
233
+ LOGD(" Manufacturer: %s\n", (char *)string);
234
+ }
235
+
236
+ if (desc.iProduct) {
237
+ ret = libusb_get_string_descriptor_ascii(handle, desc.iProduct, string, sizeof(string));
238
+ if (ret > 0)
239
+ LOGD(" Product: %s\n", (char *)string);
240
+ }
241
+
242
+ if (desc.iSerialNumber && verbose) {
243
+ ret = libusb_get_string_descriptor_ascii(handle, desc.iSerialNumber, string, sizeof(string));
244
+ if (ret > 0)
245
+ LOGD(" Serial Number: %s\n", (char *)string);
246
+ }
247
+ }
248
+
249
+ if (verbose) {
250
+ for (i = 0; i < desc.bNumConfigurations; i++) {
251
+ struct libusb_config_descriptor *config;
252
+
253
+ ret = libusb_get_config_descriptor(dev, i, &config);
254
+ if (LIBUSB_SUCCESS != ret) {
255
+ LOGD(" Couldn't retrieve descriptors\n");
256
+ continue;
257
+ }
258
+
259
+ print_configuration(config);
260
+
261
+ libusb_free_config_descriptor(config);
262
+ }
263
+
264
+ if (handle && desc.bcdUSB >= 0x0201)
265
+ print_bos(handle);
266
+ }
267
+
268
+ if (handle)
269
+ libusb_close(handle);
270
+ }
271
+
272
+
273
+ // fileDescriptor = is the native File Descriptor obtained in Java and transfered to native over JNA for Example.
274
+ int unrooted_usb_description(int fileDescriptor)
275
+ {
276
+ libusb_context *ctx = NULL;
277
+ libusb_device_handle *devh = NULL;
278
+ int r = 0;
279
+ verbose = 1;
280
+ r = libusb_set_option(NULL, LIBUSB_OPTION_NO_DEVICE_DISCOVERY, NULL);
281
+ if (r != LIBUSB_SUCCESS) {
282
+ LOGD("libusb_set_option failed: %d\n", r);
283
+ return -1;
284
+ }
285
+ r = libusb_init(&ctx);
286
+ if (r < 0) {
287
+ LOGD("libusb_init failed: %d\n", r);
288
+ return r;
289
+ }
290
+ r = libusb_wrap_sys_device(ctx, (intptr_t)fileDescriptor, &devh);
291
+ if (r < 0) {
292
+ LOGD("libusb_wrap_sys_device failed: %d\n", r);
293
+ return r;
294
+ } else if (devh == NULL) {
295
+ LOGD("libusb_wrap_sys_device returned invalid handle\n");
296
+ return r;
297
+ }
298
+ print_device(libusb_get_device(devh), devh);
299
+ return r;
300
+ }
301
+
@@ -0,0 +1,36 @@
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
+
@@ -16,7 +16,7 @@
16
16
  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
  #
18
18
 
19
- LOCAL_PATH:= $(call my-dir)
19
+ LOCAL_PATH := $(call my-dir)
20
20
 
21
21
  include $(LOCAL_PATH)/libusb.mk
22
22
  include $(LOCAL_PATH)/examples.mk
@@ -18,6 +18,22 @@
18
18
 
19
19
  APP_ABI := all
20
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
+
21
37
  # Workaround for MIPS toolchain linker being unable to find liblog dependency
22
38
  # of shared object in NDK versions at least up to r9.
23
39
  #