usb 2.1.2 → 2.3.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 (288) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +20 -2
  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/dist/usb/index.js +7 -16
  10. package/dist/usb/index.js.map +1 -1
  11. package/dist/webusb/webusb-device.d.ts +2 -1
  12. package/dist/webusb/webusb-device.js +21 -14
  13. package/dist/webusb/webusb-device.js.map +1 -1
  14. package/libusb/.gitattributes +2 -6
  15. package/libusb/.private/appveyor_build.sh +22 -0
  16. package/libusb/.private/bm.sh +1 -1
  17. package/libusb/.private/ci-build.sh +67 -0
  18. package/libusb/.private/ci-container-build.sh +70 -0
  19. package/libusb/.private/post-rewrite.sh +5 -1
  20. package/libusb/.private/pre-commit.sh +5 -1
  21. package/libusb/.private/wbs.txt +4 -19
  22. package/libusb/.travis.yml +32 -23
  23. package/libusb/AUTHORS +86 -3
  24. package/libusb/ChangeLog +54 -3
  25. package/libusb/INSTALL_WIN.txt +22 -44
  26. package/libusb/Makefile.am +32 -10
  27. package/libusb/{README.md → README} +2 -2
  28. package/libusb/README.git +3 -3
  29. package/libusb/Xcode/common.xcconfig +23 -19
  30. package/libusb/Xcode/config.h +25 -13
  31. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
  32. package/libusb/android/README +90 -54
  33. package/libusb/android/config.h +23 -43
  34. package/libusb/android/examples/unrooted_android.c +300 -0
  35. package/libusb/android/examples/unrooted_android.h +36 -0
  36. package/libusb/android/jni/Android.mk +1 -1
  37. package/libusb/android/jni/Application.mk +16 -0
  38. package/libusb/android/jni/examples.mk +63 -29
  39. package/libusb/android/jni/libusb.mk +14 -8
  40. package/libusb/android/jni/tests.mk +13 -24
  41. package/libusb/appveyor.yml +73 -30
  42. package/libusb/autogen.sh +5 -3
  43. package/libusb/bootstrap.sh +6 -2
  44. package/libusb/configure.ac +314 -227
  45. package/libusb/doc/Makefile.in +22 -0
  46. package/libusb/doc/doxygen.cfg.in +460 -223
  47. package/libusb/examples/Makefile.am +6 -13
  48. package/libusb/examples/dpfp.c +276 -73
  49. package/libusb/examples/ezusb.c +18 -8
  50. package/libusb/examples/ezusb.h +6 -17
  51. package/libusb/examples/fxload.c +4 -5
  52. package/libusb/examples/hotplugtest.c +1 -1
  53. package/libusb/examples/sam3u_benchmark.c +59 -24
  54. package/libusb/examples/testlibusb.c +138 -104
  55. package/libusb/examples/xusb.c +26 -22
  56. package/libusb/libusb/Makefile.am +57 -70
  57. package/libusb/libusb/Makefile.am.extra +26 -0
  58. package/libusb/libusb/core.c +432 -423
  59. package/libusb/libusb/descriptor.c +365 -419
  60. package/libusb/libusb/hotplug.c +200 -104
  61. package/libusb/libusb/io.c +522 -535
  62. package/libusb/libusb/libusb-1.0.def +7 -3
  63. package/libusb/libusb/libusb-1.0.rc +1 -9
  64. package/libusb/libusb/libusb.h +302 -226
  65. package/libusb/libusb/libusbi.h +607 -316
  66. package/libusb/libusb/os/darwin_usb.c +703 -329
  67. package/libusb/libusb/os/darwin_usb.h +39 -15
  68. package/libusb/libusb/os/events_posix.c +300 -0
  69. package/libusb/libusb/os/events_posix.h +59 -0
  70. package/libusb/libusb/os/events_windows.c +214 -0
  71. package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
  72. package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
  73. package/libusb/libusb/os/haiku_usb.h +12 -12
  74. package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
  75. package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
  76. package/libusb/libusb/os/linux_netlink.c +55 -63
  77. package/libusb/libusb/os/linux_udev.c +61 -69
  78. package/libusb/libusb/os/linux_usbfs.c +926 -1015
  79. package/libusb/libusb/os/linux_usbfs.h +74 -57
  80. package/libusb/libusb/os/netbsd_usb.c +103 -168
  81. package/libusb/libusb/os/null_usb.c +111 -0
  82. package/libusb/libusb/os/openbsd_usb.c +71 -120
  83. package/libusb/libusb/os/sunos_usb.c +289 -375
  84. package/libusb/libusb/os/sunos_usb.h +0 -1
  85. package/libusb/libusb/os/threads_posix.c +81 -32
  86. package/libusb/libusb/os/threads_posix.h +19 -23
  87. package/libusb/libusb/os/threads_windows.c +9 -95
  88. package/libusb/libusb/os/threads_windows.h +33 -31
  89. package/libusb/libusb/os/windows_common.c +915 -0
  90. package/libusb/libusb/os/windows_common.h +330 -42
  91. package/libusb/libusb/os/windows_usbdk.c +161 -267
  92. package/libusb/libusb/os/windows_usbdk.h +5 -2
  93. package/libusb/libusb/os/windows_winusb.c +1355 -1192
  94. package/libusb/libusb/os/windows_winusb.h +167 -167
  95. package/libusb/libusb/strerror.c +20 -30
  96. package/libusb/libusb/sync.c +20 -21
  97. package/libusb/libusb/version.h +1 -1
  98. package/libusb/libusb/version_nano.h +1 -1
  99. package/libusb/msvc/.gitattributes +3 -0
  100. package/libusb/msvc/config.h +27 -20
  101. package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
  102. package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
  103. package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
  104. package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
  105. package/libusb/msvc/dpfp_2017.vcxproj +106 -0
  106. package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
  107. package/libusb/msvc/dpfp_2019.vcxproj +106 -0
  108. package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
  109. package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
  110. package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
  111. package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
  112. package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
  113. package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
  114. package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
  115. package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
  116. package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
  117. package/libusb/msvc/fxload_2013.vcxproj +6 -3
  118. package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
  119. package/libusb/msvc/fxload_2015.vcxproj +6 -3
  120. package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
  121. package/libusb/msvc/fxload_2017.vcxproj +6 -7
  122. package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
  123. package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
  124. package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
  125. package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
  126. package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
  127. package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
  128. package/libusb/msvc/getopt_2013.vcxproj +4 -5
  129. package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
  130. package/libusb/msvc/getopt_2015.vcxproj +4 -4
  131. package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
  132. package/libusb/msvc/getopt_2017.vcxproj +4 -10
  133. package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
  134. package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
  135. package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
  136. package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
  137. package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
  138. package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
  139. package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
  140. package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
  141. package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
  142. package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
  143. package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
  144. package/libusb/msvc/libusb_2013.sln +50 -20
  145. package/libusb/msvc/libusb_2015.sln +51 -21
  146. package/libusb/msvc/libusb_2017.sln +90 -36
  147. package/libusb/msvc/libusb_2019.sln +240 -0
  148. package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
  149. package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
  150. package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
  151. package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
  152. package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
  153. package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
  154. package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
  155. package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
  156. package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
  157. package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
  158. package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
  159. package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
  160. package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
  161. package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
  162. package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
  163. package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
  164. package/libusb/msvc/listdevs_2013.vcxproj +6 -3
  165. package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
  166. package/libusb/msvc/listdevs_2015.vcxproj +6 -3
  167. package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
  168. package/libusb/msvc/listdevs_2017.vcxproj +6 -7
  169. package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
  170. package/libusb/msvc/listdevs_2019.vcxproj +105 -0
  171. package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
  172. package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
  173. package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
  174. package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
  175. package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
  176. package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
  177. package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
  178. package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
  179. package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
  180. package/libusb/msvc/stress_2013.vcxproj +4 -2
  181. package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
  182. package/libusb/msvc/stress_2015.vcxproj +4 -2
  183. package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
  184. package/libusb/msvc/stress_2017.vcxproj +4 -6
  185. package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
  186. package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
  187. package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
  188. package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
  189. package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
  190. package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
  191. package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
  192. package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
  193. package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
  194. package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
  195. package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
  196. package/libusb/msvc/xusb_2013.vcxproj +6 -3
  197. package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
  198. package/libusb/msvc/xusb_2015.vcxproj +6 -3
  199. package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
  200. package/libusb/msvc/xusb_2017.vcxproj +6 -7
  201. package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
  202. package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
  203. package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
  204. package/libusb/tests/Makefile.am +13 -1
  205. package/libusb/tests/libusb_testlib.h +12 -43
  206. package/libusb/tests/stress.c +59 -50
  207. package/libusb/tests/testlib.c +78 -171
  208. package/libusb/tests/umockdev.c +1175 -0
  209. package/libusb.gypi +10 -11
  210. package/package.json +2 -2
  211. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  212. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  213. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  214. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  215. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  216. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  217. package/prebuilds/linux-ia32/node.napi.node +0 -0
  218. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  219. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  220. package/prebuilds/win32-ia32/node.napi.node +0 -0
  221. package/prebuilds/win32-x64/node.napi.node +0 -0
  222. package/src/device.cc +12 -7
  223. package/src/node_usb.cc +10 -0
  224. package/test/usb.coffee +6 -0
  225. package/tsc/index.ts +2 -0
  226. package/tsc/usb/bindings.ts +5 -0
  227. package/tsc/usb/device.ts +6 -0
  228. package/tsc/usb/index.ts +5 -8
  229. package/tsc/webusb/webusb-device.ts +12 -8
  230. package/libusb/.private/bd.cmd +0 -89
  231. package/libusb/.private/bwince.cmd +0 -57
  232. package/libusb/.private/wbs_wince.txt +0 -42
  233. package/libusb/Brewfile +0 -4
  234. package/libusb/appveyor_cygwin.bat +0 -11
  235. package/libusb/appveyor_minGW.bat +0 -19
  236. package/libusb/doc/Makefile.am +0 -9
  237. package/libusb/examples/dpfp_threaded.c +0 -557
  238. package/libusb/libusb/hotplug.h +0 -99
  239. package/libusb/libusb/os/poll_posix.c +0 -84
  240. package/libusb/libusb/os/poll_posix.h +0 -14
  241. package/libusb/libusb/os/poll_windows.c +0 -447
  242. package/libusb/libusb/os/poll_windows.h +0 -98
  243. package/libusb/libusb/os/wince_usb.c +0 -888
  244. package/libusb/libusb/os/wince_usb.h +0 -126
  245. package/libusb/libusb/os/windows_nt_common.c +0 -1010
  246. package/libusb/libusb/os/windows_nt_common.h +0 -110
  247. package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
  248. package/libusb/msvc/appveyor.bat +0 -27
  249. package/libusb/msvc/ddk_build.cmd +0 -219
  250. package/libusb/msvc/errno.h +0 -102
  251. package/libusb/msvc/fxload_sources +0 -23
  252. package/libusb/msvc/getopt_2005.vcproj +0 -288
  253. package/libusb/msvc/getopt_2010.vcxproj +0 -72
  254. package/libusb/msvc/getopt_sources +0 -24
  255. package/libusb/msvc/hotplugtest_sources +0 -20
  256. package/libusb/msvc/inttypes.h +0 -295
  257. package/libusb/msvc/libusb.dsw +0 -71
  258. package/libusb/msvc/libusb_2005.sln +0 -95
  259. package/libusb/msvc/libusb_2010.sln +0 -105
  260. package/libusb/msvc/libusb_2012.sln +0 -105
  261. package/libusb/msvc/libusb_dll.dsp +0 -194
  262. package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
  263. package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
  264. package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
  265. package/libusb/msvc/libusb_sources +0 -43
  266. package/libusb/msvc/libusb_static.dsp +0 -174
  267. package/libusb/msvc/libusb_static_2005.vcproj +0 -390
  268. package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
  269. package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
  270. package/libusb/msvc/libusb_wince.sln +0 -246
  271. package/libusb/msvc/listdevs.dsp +0 -103
  272. package/libusb/msvc/listdevs_2005.vcproj +0 -360
  273. package/libusb/msvc/listdevs_sources +0 -20
  274. package/libusb/msvc/listdevs_wince.vcproj +0 -1120
  275. package/libusb/msvc/missing.c +0 -80
  276. package/libusb/msvc/stdint.h +0 -256
  277. package/libusb/msvc/stress_2005.vcproj +0 -390
  278. package/libusb/msvc/stress_2012.vcxproj +0 -87
  279. package/libusb/msvc/stress_sources +0 -21
  280. package/libusb/msvc/stress_wince.vcproj +0 -1128
  281. package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
  282. package/libusb/msvc/testlibusb_sources +0 -20
  283. package/libusb/msvc/xusb.dsp +0 -102
  284. package/libusb/msvc/xusb_2005.vcproj +0 -344
  285. package/libusb/msvc/xusb_2012.vcxproj +0 -83
  286. package/libusb/msvc/xusb_sources +0 -20
  287. package/libusb/msvc/xusb_wince.vcproj +0 -1120
  288. package/libusb/travis-autogen.sh +0 -39
@@ -1,557 +0,0 @@
1
- /*
2
- * libusb example program to manipulate U.are.U 4000B fingerprint scanner.
3
- * Copyright © 2007 Daniel Drake <dsd@gentoo.org>
4
- * Copyright © 2016 Nathan Hjelm <hjelmn@mac.com>
5
- *
6
- * Basic image capture program only, does not consider the powerup quirks or
7
- * the fact that image encryption may be enabled. Not expected to work
8
- * flawlessly all of the time.
9
- *
10
- * This library is free software; you can redistribute it and/or
11
- * modify it under the terms of the GNU Lesser General Public
12
- * License as published by the Free Software Foundation; either
13
- * version 2.1 of the License, or (at your option) any later version.
14
- *
15
- * This library is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
- * Lesser General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU Lesser General Public
21
- * License along with this library; if not, write to the Free Software
22
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23
- */
24
-
25
- #include <errno.h>
26
- #include <pthread.h>
27
- #include <semaphore.h>
28
- #include <signal.h>
29
- #include <string.h>
30
- #include <stdio.h>
31
- #include <stdlib.h>
32
- #include <fcntl.h>
33
-
34
- #include "libusb.h"
35
-
36
- #define EP_INTR (1 | LIBUSB_ENDPOINT_IN)
37
- #define EP_DATA (2 | LIBUSB_ENDPOINT_IN)
38
- #define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN)
39
- #define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT)
40
- #define USB_RQ 0x04
41
- #define INTR_LENGTH 64
42
- #define SEM_NAME "/org.libusb.example.dpfp_threaded"
43
-
44
- enum {
45
- MODE_INIT = 0x00,
46
- MODE_AWAIT_FINGER_ON = 0x10,
47
- MODE_AWAIT_FINGER_OFF = 0x12,
48
- MODE_CAPTURE = 0x20,
49
- MODE_SHUT_UP = 0x30,
50
- MODE_READY = 0x80,
51
- };
52
-
53
- static int next_state(void);
54
-
55
- enum {
56
- STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON = 1,
57
- STATE_AWAIT_IRQ_FINGER_DETECTED,
58
- STATE_AWAIT_MODE_CHANGE_CAPTURE,
59
- STATE_AWAIT_IMAGE,
60
- STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF,
61
- STATE_AWAIT_IRQ_FINGER_REMOVED,
62
- };
63
-
64
- static int state = 0;
65
- static struct libusb_device_handle *devh = NULL;
66
- static unsigned char imgbuf[0x1b340];
67
- static unsigned char irqbuf[INTR_LENGTH];
68
- static struct libusb_transfer *img_transfer = NULL;
69
- static struct libusb_transfer *irq_transfer = NULL;
70
- static int img_idx = 0;
71
- static volatile sig_atomic_t do_exit = 0;
72
-
73
- static pthread_t poll_thread;
74
- static sem_t *exit_sem;
75
-
76
- static void request_exit(sig_atomic_t code)
77
- {
78
- do_exit = code;
79
- sem_post(exit_sem);
80
- }
81
-
82
- static void *poll_thread_main(void *arg)
83
- {
84
- int r = 0;
85
- printf("poll thread running\n");
86
-
87
- (void)arg;
88
-
89
- while (!do_exit) {
90
- struct timeval tv = { 1, 0 };
91
- r = libusb_handle_events_timeout(NULL, &tv);
92
- if (r < 0) {
93
- request_exit(2);
94
- break;
95
- }
96
- }
97
-
98
- printf("poll thread shutting down\n");
99
- return NULL;
100
- }
101
-
102
- static int find_dpfp_device(void)
103
- {
104
- devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a);
105
- return devh ? 0 : -EIO;
106
- }
107
-
108
- static int print_f0_data(void)
109
- {
110
- unsigned char data[0x10];
111
- int r;
112
- unsigned int i;
113
-
114
- r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0xf0, 0, data,
115
- sizeof(data), 0);
116
- if (r < 0) {
117
- fprintf(stderr, "F0 error %d\n", r);
118
- return r;
119
- }
120
- if ((unsigned int) r < sizeof(data)) {
121
- fprintf(stderr, "short read (%d)\n", r);
122
- return -1;
123
- }
124
-
125
- printf("F0 data:");
126
- for (i = 0; i < sizeof(data); i++)
127
- printf("%02x ", data[i]);
128
- printf("\n");
129
- return 0;
130
- }
131
-
132
- static int get_hwstat(unsigned char *status)
133
- {
134
- int r;
135
-
136
- r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0x07, 0, status, 1, 0);
137
- if (r < 0) {
138
- fprintf(stderr, "read hwstat error %d\n", r);
139
- return r;
140
- }
141
- if ((unsigned int) r < 1) {
142
- fprintf(stderr, "short read (%d)\n", r);
143
- return -1;
144
- }
145
-
146
- printf("hwstat reads %02x\n", *status);
147
- return 0;
148
- }
149
-
150
- static int set_hwstat(unsigned char data)
151
- {
152
- int r;
153
-
154
- printf("set hwstat to %02x\n", data);
155
- r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x07, 0, &data, 1, 0);
156
- if (r < 0) {
157
- fprintf(stderr, "set hwstat error %d\n", r);
158
- return r;
159
- }
160
- if ((unsigned int) r < 1) {
161
- fprintf(stderr, "short write (%d)", r);
162
- return -1;
163
- }
164
-
165
- return 0;
166
- }
167
-
168
- static int set_mode(unsigned char data)
169
- {
170
- int r;
171
- printf("set mode %02x\n", data);
172
-
173
- r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x4e, 0, &data, 1, 0);
174
- if (r < 0) {
175
- fprintf(stderr, "set mode error %d\n", r);
176
- return r;
177
- }
178
- if ((unsigned int) r < 1) {
179
- fprintf(stderr, "short write (%d)", r);
180
- return -1;
181
- }
182
-
183
- return 0;
184
- }
185
-
186
- static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer)
187
- {
188
- if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
189
- fprintf(stderr, "mode change transfer not completed!\n");
190
- request_exit(2);
191
- }
192
-
193
- printf("async cb_mode_changed length=%d actual_length=%d\n",
194
- transfer->length, transfer->actual_length);
195
- if (next_state() < 0)
196
- request_exit(2);
197
- }
198
-
199
- static int set_mode_async(unsigned char data)
200
- {
201
- unsigned char *buf = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
202
- struct libusb_transfer *transfer;
203
-
204
- if (!buf)
205
- return -ENOMEM;
206
-
207
- transfer = libusb_alloc_transfer(0);
208
- if (!transfer) {
209
- free(buf);
210
- return -ENOMEM;
211
- }
212
-
213
- printf("async set mode %02x\n", data);
214
- libusb_fill_control_setup(buf, CTRL_OUT, USB_RQ, 0x4e, 0, 1);
215
- buf[LIBUSB_CONTROL_SETUP_SIZE] = data;
216
- libusb_fill_control_transfer(transfer, devh, buf, cb_mode_changed, NULL,
217
- 1000);
218
-
219
- transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK
220
- | LIBUSB_TRANSFER_FREE_BUFFER | LIBUSB_TRANSFER_FREE_TRANSFER;
221
- return libusb_submit_transfer(transfer);
222
- }
223
-
224
- static int do_sync_intr(unsigned char *data)
225
- {
226
- int r;
227
- int transferred;
228
-
229
- r = libusb_interrupt_transfer(devh, EP_INTR, data, INTR_LENGTH,
230
- &transferred, 1000);
231
- if (r < 0) {
232
- fprintf(stderr, "intr error %d\n", r);
233
- return r;
234
- }
235
- if (transferred < INTR_LENGTH) {
236
- fprintf(stderr, "short read (%d)\n", r);
237
- return -1;
238
- }
239
-
240
- printf("recv interrupt %04x\n", *((uint16_t *) data));
241
- return 0;
242
- }
243
-
244
- static int sync_intr(unsigned char type)
245
- {
246
- int r;
247
- unsigned char data[INTR_LENGTH];
248
-
249
- while (1) {
250
- r = do_sync_intr(data);
251
- if (r < 0)
252
- return r;
253
- if (data[0] == type)
254
- return 0;
255
- }
256
- }
257
-
258
- static int save_to_file(unsigned char *data)
259
- {
260
- FILE *fd;
261
- char filename[64];
262
-
263
- snprintf(filename, sizeof(filename), "finger%d.pgm", img_idx++);
264
- fd = fopen(filename, "w");
265
- if (!fd)
266
- return -1;
267
-
268
- fputs("P5 384 289 255 ", fd);
269
- (void) fwrite(data + 64, 1, 384*289, fd);
270
- fclose(fd);
271
- printf("saved image to %s\n", filename);
272
- return 0;
273
- }
274
-
275
- static int next_state(void)
276
- {
277
- int r = 0;
278
- printf("old state: %d\n", state);
279
- switch (state) {
280
- case STATE_AWAIT_IRQ_FINGER_REMOVED:
281
- state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON;
282
- r = set_mode_async(MODE_AWAIT_FINGER_ON);
283
- break;
284
- case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON:
285
- state = STATE_AWAIT_IRQ_FINGER_DETECTED;
286
- break;
287
- case STATE_AWAIT_IRQ_FINGER_DETECTED:
288
- state = STATE_AWAIT_MODE_CHANGE_CAPTURE;
289
- r = set_mode_async(MODE_CAPTURE);
290
- break;
291
- case STATE_AWAIT_MODE_CHANGE_CAPTURE:
292
- state = STATE_AWAIT_IMAGE;
293
- break;
294
- case STATE_AWAIT_IMAGE:
295
- state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF;
296
- r = set_mode_async(MODE_AWAIT_FINGER_OFF);
297
- break;
298
- case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF:
299
- state = STATE_AWAIT_IRQ_FINGER_REMOVED;
300
- break;
301
- default:
302
- printf("unrecognised state %d\n", state);
303
- }
304
- if (r < 0) {
305
- fprintf(stderr, "error detected changing state\n");
306
- return r;
307
- }
308
-
309
- printf("new state: %d\n", state);
310
- return 0;
311
- }
312
-
313
- static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer)
314
- {
315
- unsigned char irqtype = transfer->buffer[0];
316
-
317
- if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
318
- fprintf(stderr, "irq transfer status %d?\n", transfer->status);
319
- irq_transfer = NULL;
320
- request_exit(2);
321
- return;
322
- }
323
-
324
- printf("IRQ callback %02x\n", irqtype);
325
- switch (state) {
326
- case STATE_AWAIT_IRQ_FINGER_DETECTED:
327
- if (irqtype == 0x01) {
328
- if (next_state() < 0) {
329
- request_exit(2);
330
- return;
331
- }
332
- } else {
333
- printf("finger-on-sensor detected in wrong state!\n");
334
- }
335
- break;
336
- case STATE_AWAIT_IRQ_FINGER_REMOVED:
337
- if (irqtype == 0x02) {
338
- if (next_state() < 0) {
339
- request_exit(2);
340
- return;
341
- }
342
- } else {
343
- printf("finger-on-sensor detected in wrong state!\n");
344
- }
345
- break;
346
- }
347
- if (libusb_submit_transfer(irq_transfer) < 0)
348
- request_exit(2);
349
- }
350
-
351
- static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer)
352
- {
353
- if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
354
- fprintf(stderr, "img transfer status %d?\n", transfer->status);
355
- img_transfer = NULL;
356
- request_exit(2);
357
- return;
358
- }
359
-
360
- printf("Image callback\n");
361
- save_to_file(imgbuf);
362
- if (next_state() < 0) {
363
- request_exit(2);
364
- return;
365
- }
366
- if (libusb_submit_transfer(img_transfer) < 0)
367
- request_exit(2);
368
- }
369
-
370
- static int init_capture(void)
371
- {
372
- int r;
373
-
374
- r = libusb_submit_transfer(irq_transfer);
375
- if (r < 0)
376
- return r;
377
-
378
- r = libusb_submit_transfer(img_transfer);
379
- if (r < 0) {
380
- libusb_cancel_transfer(irq_transfer);
381
- while (irq_transfer)
382
- if (libusb_handle_events(NULL) < 0)
383
- break;
384
- return r;
385
- }
386
-
387
- /* start state machine */
388
- state = STATE_AWAIT_IRQ_FINGER_REMOVED;
389
- return next_state();
390
- }
391
-
392
- static int do_init(void)
393
- {
394
- unsigned char status;
395
- int r;
396
-
397
- r = get_hwstat(&status);
398
- if (r < 0)
399
- return r;
400
-
401
- if (!(status & 0x80)) {
402
- r = set_hwstat(status | 0x80);
403
- if (r < 0)
404
- return r;
405
- r = get_hwstat(&status);
406
- if (r < 0)
407
- return r;
408
- }
409
-
410
- status &= ~0x80;
411
- r = set_hwstat(status);
412
- if (r < 0)
413
- return r;
414
-
415
- r = get_hwstat(&status);
416
- if (r < 0)
417
- return r;
418
-
419
- r = sync_intr(0x56);
420
- if (r < 0)
421
- return r;
422
-
423
- return 0;
424
- }
425
-
426
- static int alloc_transfers(void)
427
- {
428
- img_transfer = libusb_alloc_transfer(0);
429
- if (!img_transfer)
430
- return -ENOMEM;
431
-
432
- irq_transfer = libusb_alloc_transfer(0);
433
- if (!irq_transfer)
434
- return -ENOMEM;
435
-
436
- libusb_fill_bulk_transfer(img_transfer, devh, EP_DATA, imgbuf,
437
- sizeof(imgbuf), cb_img, NULL, 0);
438
- libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR, irqbuf,
439
- sizeof(irqbuf), cb_irq, NULL, 0);
440
-
441
- return 0;
442
- }
443
-
444
- static void sighandler(int signum)
445
- {
446
- (void)signum;
447
-
448
- request_exit(1);
449
- }
450
-
451
- int main(void)
452
- {
453
- struct sigaction sigact;
454
- int r = 1;
455
-
456
- exit_sem = sem_open (SEM_NAME, O_CREAT, 0);
457
- if (!exit_sem) {
458
- fprintf(stderr, "failed to initialise semaphore error %d", errno);
459
- exit(1);
460
- }
461
-
462
- /* only using this semaphore in this process so go ahead and unlink it now */
463
- sem_unlink (SEM_NAME);
464
-
465
- r = libusb_init(NULL);
466
- if (r < 0) {
467
- fprintf(stderr, "failed to initialise libusb\n");
468
- exit(1);
469
- }
470
-
471
- r = find_dpfp_device();
472
- if (r < 0) {
473
- fprintf(stderr, "Could not find/open device\n");
474
- goto out;
475
- }
476
-
477
- r = libusb_claim_interface(devh, 0);
478
- if (r < 0) {
479
- fprintf(stderr, "usb_claim_interface error %d %s\n", r, strerror(-r));
480
- goto out;
481
- }
482
- printf("claimed interface\n");
483
-
484
- r = print_f0_data();
485
- if (r < 0)
486
- goto out_release;
487
-
488
- r = do_init();
489
- if (r < 0)
490
- goto out_deinit;
491
-
492
- /* async from here onwards */
493
-
494
- sigact.sa_handler = sighandler;
495
- sigemptyset(&sigact.sa_mask);
496
- sigact.sa_flags = 0;
497
- sigaction(SIGINT, &sigact, NULL);
498
- sigaction(SIGTERM, &sigact, NULL);
499
- sigaction(SIGQUIT, &sigact, NULL);
500
-
501
- r = pthread_create(&poll_thread, NULL, poll_thread_main, NULL);
502
- if (r)
503
- goto out_deinit;
504
-
505
- r = alloc_transfers();
506
- if (r < 0) {
507
- request_exit(1);
508
- pthread_join(poll_thread, NULL);
509
- goto out_deinit;
510
- }
511
-
512
- r = init_capture();
513
- if (r < 0) {
514
- request_exit(1);
515
- pthread_join(poll_thread, NULL);
516
- goto out_deinit;
517
- }
518
-
519
- while (!do_exit)
520
- sem_wait(exit_sem);
521
-
522
- printf("shutting down...\n");
523
- pthread_join(poll_thread, NULL);
524
-
525
- r = libusb_cancel_transfer(irq_transfer);
526
- if (r < 0) {
527
- request_exit(1);
528
- goto out_deinit;
529
- }
530
-
531
- r = libusb_cancel_transfer(img_transfer);
532
- if (r < 0) {
533
- request_exit(1);
534
- goto out_deinit;
535
- }
536
-
537
- while (img_transfer || irq_transfer)
538
- if (libusb_handle_events(NULL) < 0)
539
- break;
540
-
541
- if (do_exit == 1)
542
- r = 0;
543
- else
544
- r = 1;
545
-
546
- out_deinit:
547
- libusb_free_transfer(img_transfer);
548
- libusb_free_transfer(irq_transfer);
549
- set_mode(0);
550
- set_hwstat(0x80);
551
- out_release:
552
- libusb_release_interface(devh, 0);
553
- out:
554
- libusb_close(devh);
555
- libusb_exit(NULL);
556
- return r >= 0 ? r : -r;
557
- }
@@ -1,99 +0,0 @@
1
- /* -*- Mode: C; indent-tabs-mode:t ; c-basic-offset:8 -*- */
2
- /*
3
- * Hotplug support for libusb
4
- * Copyright © 2012-2013 Nathan Hjelm <hjelmn@mac.com>
5
- * Copyright © 2012-2013 Peter Stuge <peter@stuge.se>
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
-
22
- #ifndef USBI_HOTPLUG_H
23
- #define USBI_HOTPLUG_H
24
-
25
- #include "libusbi.h"
26
-
27
- enum usbi_hotplug_flags {
28
- /* This callback is interested in device arrivals */
29
- USBI_HOTPLUG_DEVICE_ARRIVED = LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED,
30
-
31
- /* This callback is interested in device removals */
32
- USBI_HOTPLUG_DEVICE_LEFT = LIBUSB_HOTPLUG_EVENT_DEVICE_LEFT,
33
-
34
- /* IMPORTANT: The values for the below entries must start *after*
35
- * the highest value of the above entries!!!
36
- */
37
-
38
- /* The vendor_id field is valid for matching */
39
- USBI_HOTPLUG_VENDOR_ID_VALID = (1U << 3),
40
-
41
- /* The product_id field is valid for matching */
42
- USBI_HOTPLUG_PRODUCT_ID_VALID = (1U << 4),
43
-
44
- /* The dev_class field is valid for matching */
45
- USBI_HOTPLUG_DEV_CLASS_VALID = (1U << 5),
46
-
47
- /* This callback has been unregistered and needs to be freed */
48
- USBI_HOTPLUG_NEEDS_FREE = (1U << 6),
49
- };
50
-
51
- /** \ingroup hotplug
52
- * The hotplug callback structure. The user populates this structure with
53
- * libusb_hotplug_prepare_callback() and then calls libusb_hotplug_register_callback()
54
- * to receive notification of hotplug events.
55
- */
56
- struct libusb_hotplug_callback {
57
- /** Flags that control how this callback behaves */
58
- uint8_t flags;
59
-
60
- /** Vendor ID to match (if flags says this is valid) */
61
- uint16_t vendor_id;
62
-
63
- /** Product ID to match (if flags says this is valid) */
64
- uint16_t product_id;
65
-
66
- /** Device class to match (if flags says this is valid) */
67
- uint8_t dev_class;
68
-
69
- /** Callback function to invoke for matching event/device */
70
- libusb_hotplug_callback_fn cb;
71
-
72
- /** Handle for this callback (used to match on deregister) */
73
- libusb_hotplug_callback_handle handle;
74
-
75
- /** User data that will be passed to the callback function */
76
- void *user_data;
77
-
78
- /** List this callback is registered in (ctx->hotplug_cbs) */
79
- struct list_head list;
80
- };
81
-
82
- struct libusb_hotplug_message {
83
- /** The hotplug event that occurred */
84
- libusb_hotplug_event event;
85
-
86
- /** The device for which this hotplug event occurred */
87
- struct libusb_device *device;
88
-
89
- /** List this message is contained in (ctx->hotplug_msgs) */
90
- struct list_head list;
91
- };
92
-
93
- void usbi_hotplug_deregister(struct libusb_context *ctx, int forced);
94
- void usbi_hotplug_match(struct libusb_context *ctx, struct libusb_device *dev,
95
- libusb_hotplug_event event);
96
- void usbi_hotplug_notification(struct libusb_context *ctx, struct libusb_device *dev,
97
- libusb_hotplug_event event);
98
-
99
- #endif