usb 2.1.1 → 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.
- package/CHANGELOG.md +22 -0
- package/README.md +4 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/usb/bindings.d.ts +4 -0
- package/dist/usb/device.js +5 -0
- package/dist/usb/device.js.map +1 -1
- package/dist/usb/interface.d.ts +1 -1
- package/dist/usb/interface.js +1 -5
- package/dist/usb/interface.js.map +1 -1
- package/dist/webusb/webusb-device.d.ts +2 -1
- package/dist/webusb/webusb-device.js +21 -14
- package/dist/webusb/webusb-device.js.map +1 -1
- package/libusb/.gitattributes +2 -6
- package/libusb/.private/appveyor_build.sh +22 -0
- package/libusb/.private/bm.sh +1 -1
- package/libusb/.private/ci-build.sh +67 -0
- package/libusb/.private/post-rewrite.sh +5 -1
- package/libusb/.private/pre-commit.sh +5 -1
- package/libusb/.private/wbs.txt +4 -19
- package/libusb/.travis.yml +32 -23
- package/libusb/AUTHORS +76 -3
- package/libusb/ChangeLog +41 -3
- package/libusb/INSTALL_WIN.txt +22 -44
- package/libusb/Makefile.am +32 -10
- package/libusb/{README.md → README} +2 -2
- package/libusb/README.git +3 -3
- package/libusb/Xcode/common.xcconfig +23 -19
- package/libusb/Xcode/config.h +25 -13
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +511 -109
- package/libusb/android/README +90 -54
- package/libusb/android/config.h +23 -43
- package/libusb/android/examples/unrooted_android.c +301 -0
- package/libusb/android/examples/unrooted_android.h +36 -0
- package/libusb/android/jni/Android.mk +1 -1
- package/libusb/android/jni/Application.mk +16 -0
- package/libusb/android/jni/examples.mk +63 -29
- package/libusb/android/jni/libusb.mk +14 -8
- package/libusb/android/jni/tests.mk +13 -24
- package/libusb/appveyor.yml +69 -30
- package/libusb/autogen.sh +5 -3
- package/libusb/bootstrap.sh +6 -2
- package/libusb/configure.ac +302 -228
- package/libusb/doc/Makefile.in +22 -0
- package/libusb/doc/doxygen.cfg.in +460 -223
- package/libusb/examples/Makefile.am +6 -13
- package/libusb/examples/dpfp.c +276 -73
- package/libusb/examples/ezusb.c +18 -8
- package/libusb/examples/ezusb.h +6 -17
- package/libusb/examples/fxload.c +4 -5
- package/libusb/examples/hotplugtest.c +1 -1
- package/libusb/examples/sam3u_benchmark.c +59 -24
- package/libusb/examples/testlibusb.c +138 -104
- package/libusb/examples/xusb.c +26 -22
- package/libusb/libusb/Makefile.am +57 -70
- package/libusb/libusb/Makefile.am.extra +26 -0
- package/libusb/libusb/core.c +420 -423
- package/libusb/libusb/descriptor.c +365 -419
- package/libusb/libusb/hotplug.c +197 -104
- package/libusb/libusb/io.c +491 -528
- package/libusb/libusb/libusb-1.0.def +7 -3
- package/libusb/libusb/libusb-1.0.rc +1 -9
- package/libusb/libusb/libusb.h +295 -226
- package/libusb/libusb/libusbi.h +587 -314
- package/libusb/libusb/os/darwin_usb.c +634 -317
- package/libusb/libusb/os/darwin_usb.h +39 -15
- package/libusb/libusb/os/events_posix.c +300 -0
- package/libusb/libusb/os/events_posix.h +59 -0
- package/libusb/libusb/os/events_windows.c +214 -0
- package/libusb/{msvc/missing.h → libusb/os/events_windows.h} +25 -11
- package/libusb/libusb/os/haiku_pollfs.cpp +14 -9
- package/libusb/libusb/os/haiku_usb.h +12 -12
- package/libusb/libusb/os/haiku_usb_backend.cpp +36 -37
- package/libusb/libusb/os/haiku_usb_raw.cpp +80 -116
- package/libusb/libusb/os/linux_netlink.c +55 -63
- package/libusb/libusb/os/linux_udev.c +61 -69
- package/libusb/libusb/os/linux_usbfs.c +926 -1015
- package/libusb/libusb/os/linux_usbfs.h +74 -57
- package/libusb/libusb/os/netbsd_usb.c +103 -168
- package/libusb/libusb/os/null_usb.c +111 -0
- package/libusb/libusb/os/openbsd_usb.c +71 -120
- package/libusb/libusb/os/sunos_usb.c +289 -375
- package/libusb/libusb/os/sunos_usb.h +0 -1
- package/libusb/libusb/os/threads_posix.c +81 -32
- package/libusb/libusb/os/threads_posix.h +19 -23
- package/libusb/libusb/os/threads_windows.c +9 -95
- package/libusb/libusb/os/threads_windows.h +33 -31
- package/libusb/libusb/os/windows_common.c +904 -0
- package/libusb/libusb/os/windows_common.h +329 -42
- package/libusb/libusb/os/windows_usbdk.c +161 -267
- package/libusb/libusb/os/windows_usbdk.h +5 -2
- package/libusb/libusb/os/windows_winusb.c +1326 -1190
- package/libusb/libusb/os/windows_winusb.h +167 -167
- package/libusb/libusb/strerror.c +20 -30
- package/libusb/libusb/sync.c +20 -21
- package/libusb/libusb/version.h +1 -1
- package/libusb/libusb/version_nano.h +1 -1
- package/libusb/msvc/.gitattributes +3 -0
- package/libusb/msvc/config.h +27 -20
- package/libusb/msvc/{hotplugtest_2012.vcxproj → dpfp_2013.vcxproj} +14 -10
- package/libusb/msvc/dpfp_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{listdevs_2010.vcxproj → dpfp_2015.vcxproj} +14 -9
- package/libusb/msvc/dpfp_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_2017.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_2019.vcxproj +106 -0
- package/libusb/msvc/dpfp_2019.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2013.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj +87 -0
- package/libusb/msvc/dpfp_threaded_2015.vcxproj.filters +26 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj +106 -0
- package/libusb/msvc/dpfp_threaded_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{fxload_2012.vcxproj → dpfp_threaded_2019.vcxproj} +32 -17
- package/libusb/msvc/dpfp_threaded_2019.vcxproj.filters +26 -0
- package/libusb/msvc/fxload_2013.vcxproj +6 -3
- package/libusb/msvc/fxload_2013.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2015.vcxproj +6 -3
- package/libusb/msvc/fxload_2015.vcxproj.filters +35 -0
- package/libusb/msvc/fxload_2017.vcxproj +6 -7
- package/libusb/msvc/fxload_2017.vcxproj.filters +35 -0
- package/libusb/msvc/{fxload_2010.vcxproj → fxload_2019.vcxproj} +29 -6
- package/libusb/msvc/fxload_2019.vcxproj.filters +35 -0
- package/libusb/{examples → msvc}/getopt/getopt.c +0 -0
- package/libusb/{examples → msvc}/getopt/getopt.h +0 -0
- package/libusb/{examples → msvc}/getopt/getopt1.c +0 -0
- package/libusb/msvc/getopt_2013.vcxproj +4 -5
- package/libusb/msvc/getopt_2013.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2015.vcxproj +4 -4
- package/libusb/msvc/getopt_2015.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2017.vcxproj +4 -10
- package/libusb/msvc/getopt_2017.vcxproj.filters +26 -0
- package/libusb/msvc/{getopt_2012.vcxproj → getopt_2019.vcxproj} +25 -6
- package/libusb/msvc/getopt_2019.vcxproj.filters +26 -0
- package/libusb/msvc/hotplugtest_2013.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2013.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2015.vcxproj +6 -3
- package/libusb/msvc/hotplugtest_2015.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2017.vcxproj +6 -7
- package/libusb/msvc/hotplugtest_2017.vcxproj.filters +23 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj +105 -0
- package/libusb/msvc/hotplugtest_2019.vcxproj.filters +23 -0
- package/libusb/msvc/libusb_2013.sln +50 -20
- package/libusb/msvc/libusb_2015.sln +51 -21
- package/libusb/msvc/libusb_2017.sln +90 -36
- package/libusb/msvc/libusb_2019.sln +240 -0
- package/libusb/msvc/libusb_dll_2013.vcxproj +6 -9
- package/libusb/msvc/libusb_dll_2013.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2015.vcxproj +6 -8
- package/libusb/msvc/libusb_dll_2015.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_dll_2017.vcxproj +6 -16
- package/libusb/msvc/libusb_dll_2017.vcxproj.filters +94 -0
- package/libusb/msvc/{libusb_dll_2010.vcxproj → libusb_dll_2019.vcxproj} +27 -9
- package/libusb/msvc/libusb_dll_2019.vcxproj.filters +94 -0
- package/libusb/msvc/libusb_static_2013.vcxproj +5 -9
- package/libusb/msvc/libusb_static_2013.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2015.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2015.vcxproj.filters +80 -0
- package/libusb/msvc/libusb_static_2017.vcxproj +5 -8
- package/libusb/msvc/libusb_static_2017.vcxproj.filters +80 -0
- package/libusb/msvc/{libusb_static_2010.vcxproj → libusb_static_2019.vcxproj} +26 -9
- package/libusb/msvc/libusb_static_2019.vcxproj.filters +80 -0
- package/libusb/msvc/listdevs_2013.vcxproj +6 -3
- package/libusb/msvc/listdevs_2013.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2015.vcxproj +6 -3
- package/libusb/msvc/listdevs_2015.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2017.vcxproj +6 -7
- package/libusb/msvc/listdevs_2017.vcxproj.filters +23 -0
- package/libusb/msvc/listdevs_2019.vcxproj +105 -0
- package/libusb/msvc/listdevs_2019.vcxproj.filters +23 -0
- package/libusb/msvc/{listdevs_2012.vcxproj → sam3u_benchmark_2013.vcxproj} +13 -9
- package/libusb/msvc/sam3u_benchmark_2013.vcxproj.filters +26 -0
- package/libusb/msvc/{hotplugtest_2010.vcxproj → sam3u_benchmark_2015.vcxproj} +13 -8
- package/libusb/msvc/sam3u_benchmark_2015.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2017.vcxproj.filters +26 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj +106 -0
- package/libusb/msvc/sam3u_benchmark_2019.vcxproj.filters +26 -0
- package/libusb/msvc/stress_2013.vcxproj +4 -2
- package/libusb/msvc/stress_2013.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2015.vcxproj +4 -2
- package/libusb/msvc/stress_2015.vcxproj.filters +32 -0
- package/libusb/msvc/stress_2017.vcxproj +4 -6
- package/libusb/msvc/stress_2017.vcxproj.filters +32 -0
- package/libusb/msvc/{stress_2010.vcxproj → stress_2019.vcxproj} +26 -4
- package/libusb/msvc/stress_2019.vcxproj.filters +32 -0
- package/libusb/msvc/testlibusb_2013.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2015.vcxproj +6 -3
- package/libusb/msvc/testlibusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/testlibusb_2017.vcxproj +6 -7
- package/libusb/msvc/testlibusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{testlibusb_2010.vcxproj → testlibusb_2019.vcxproj} +28 -5
- package/libusb/msvc/testlibusb_2019.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2013.vcxproj +6 -3
- package/libusb/msvc/xusb_2013.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2015.vcxproj +6 -3
- package/libusb/msvc/xusb_2015.vcxproj.filters +23 -0
- package/libusb/msvc/xusb_2017.vcxproj +6 -7
- package/libusb/msvc/xusb_2017.vcxproj.filters +23 -0
- package/libusb/msvc/{xusb_2010.vcxproj → xusb_2019.vcxproj} +28 -5
- package/libusb/msvc/xusb_2019.vcxproj.filters +23 -0
- package/libusb/tests/Makefile.am +1 -0
- package/libusb/tests/libusb_testlib.h +12 -43
- package/libusb/tests/stress.c +59 -50
- package/libusb/tests/testlib.c +78 -171
- package/libusb.gypi +10 -11
- package/package.json +2 -2
- package/prebuilds/android-arm/node.napi.armv7.node +0 -0
- package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
- package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
- package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
- package/prebuilds/linux-ia32/node.napi.node +0 -0
- package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
- package/prebuilds/linux-x64/node.napi.musl.node +0 -0
- package/prebuilds/win32-ia32/node.napi.node +0 -0
- package/prebuilds/win32-x64/node.napi.node +0 -0
- package/src/device.cc +12 -7
- package/src/node_usb.cc +10 -0
- package/test/usb.coffee +6 -0
- package/tsc/index.ts +2 -0
- package/tsc/usb/bindings.ts +5 -0
- package/tsc/usb/device.ts +6 -0
- package/tsc/usb/interface.ts +2 -7
- package/tsc/webusb/webusb-device.ts +12 -8
- package/libusb/.private/bd.cmd +0 -89
- package/libusb/.private/bwince.cmd +0 -57
- package/libusb/.private/wbs_wince.txt +0 -42
- package/libusb/Brewfile +0 -4
- package/libusb/appveyor_cygwin.bat +0 -11
- package/libusb/appveyor_minGW.bat +0 -19
- package/libusb/doc/Makefile.am +0 -9
- package/libusb/examples/dpfp_threaded.c +0 -557
- package/libusb/libusb/hotplug.h +0 -99
- package/libusb/libusb/os/poll_posix.c +0 -84
- package/libusb/libusb/os/poll_posix.h +0 -14
- package/libusb/libusb/os/poll_windows.c +0 -447
- package/libusb/libusb/os/poll_windows.h +0 -98
- package/libusb/libusb/os/wince_usb.c +0 -888
- package/libusb/libusb/os/wince_usb.h +0 -126
- package/libusb/libusb/os/windows_nt_common.c +0 -1010
- package/libusb/libusb/os/windows_nt_common.h +0 -110
- package/libusb/libusb/os/windows_nt_shared_types.h +0 -147
- package/libusb/msvc/appveyor.bat +0 -27
- package/libusb/msvc/ddk_build.cmd +0 -219
- package/libusb/msvc/errno.h +0 -102
- package/libusb/msvc/fxload_sources +0 -23
- package/libusb/msvc/getopt_2005.vcproj +0 -288
- package/libusb/msvc/getopt_2010.vcxproj +0 -72
- package/libusb/msvc/getopt_sources +0 -24
- package/libusb/msvc/hotplugtest_sources +0 -20
- package/libusb/msvc/inttypes.h +0 -295
- package/libusb/msvc/libusb.dsw +0 -71
- package/libusb/msvc/libusb_2005.sln +0 -95
- package/libusb/msvc/libusb_2010.sln +0 -105
- package/libusb/msvc/libusb_2012.sln +0 -105
- package/libusb/msvc/libusb_dll.dsp +0 -194
- package/libusb/msvc/libusb_dll_2005.vcproj +0 -464
- package/libusb/msvc/libusb_dll_2012.vcxproj +0 -107
- package/libusb/msvc/libusb_dll_wince.vcproj +0 -1251
- package/libusb/msvc/libusb_sources +0 -43
- package/libusb/msvc/libusb_static.dsp +0 -174
- package/libusb/msvc/libusb_static_2005.vcproj +0 -390
- package/libusb/msvc/libusb_static_2012.vcxproj +0 -98
- package/libusb/msvc/libusb_static_wince.vcproj +0 -1179
- package/libusb/msvc/libusb_wince.sln +0 -246
- package/libusb/msvc/listdevs.dsp +0 -103
- package/libusb/msvc/listdevs_2005.vcproj +0 -360
- package/libusb/msvc/listdevs_sources +0 -20
- package/libusb/msvc/listdevs_wince.vcproj +0 -1120
- package/libusb/msvc/missing.c +0 -80
- package/libusb/msvc/stdint.h +0 -256
- package/libusb/msvc/stress_2005.vcproj +0 -390
- package/libusb/msvc/stress_2012.vcxproj +0 -87
- package/libusb/msvc/stress_sources +0 -21
- package/libusb/msvc/stress_wince.vcproj +0 -1128
- package/libusb/msvc/testlibusb_2012.vcxproj +0 -83
- package/libusb/msvc/testlibusb_sources +0 -20
- package/libusb/msvc/xusb.dsp +0 -102
- package/libusb/msvc/xusb_2005.vcproj +0 -344
- package/libusb/msvc/xusb_2012.vcxproj +0 -83
- package/libusb/msvc/xusb_sources +0 -20
- package/libusb/msvc/xusb_wince.vcproj +0 -1120
- package/libusb/travis-autogen.sh +0 -39
|
@@ -30,11 +30,12 @@ USBRoster gUsbRoster;
|
|
|
30
30
|
int32 gInitCount = 0;
|
|
31
31
|
|
|
32
32
|
static int haiku_get_config_descriptor(struct libusb_device *, uint8_t,
|
|
33
|
-
|
|
33
|
+
void *, size_t);
|
|
34
34
|
|
|
35
35
|
static int
|
|
36
36
|
haiku_init(struct libusb_context *ctx)
|
|
37
37
|
{
|
|
38
|
+
UNUSED(ctx);
|
|
38
39
|
if (atomic_add(&gInitCount, 1) == 0)
|
|
39
40
|
return gUsbRoster.Start();
|
|
40
41
|
return LIBUSB_SUCCESS;
|
|
@@ -51,7 +52,7 @@ haiku_exit(struct libusb_context *ctx)
|
|
|
51
52
|
static int
|
|
52
53
|
haiku_open(struct libusb_device_handle *dev_handle)
|
|
53
54
|
{
|
|
54
|
-
USBDevice *dev = *((USBDevice **)dev_handle->dev
|
|
55
|
+
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(dev_handle->dev));
|
|
55
56
|
USBDeviceHandle *handle = new(std::nothrow) USBDeviceHandle(dev);
|
|
56
57
|
if (handle == NULL)
|
|
57
58
|
return LIBUSB_ERROR_NO_MEM;
|
|
@@ -59,93 +60,79 @@ haiku_open(struct libusb_device_handle *dev_handle)
|
|
|
59
60
|
delete handle;
|
|
60
61
|
return LIBUSB_ERROR_NO_DEVICE;
|
|
61
62
|
}
|
|
62
|
-
*((USBDeviceHandle **)dev_handle
|
|
63
|
+
*((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle)) = handle;
|
|
63
64
|
return LIBUSB_SUCCESS;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
static void
|
|
67
68
|
haiku_close(struct libusb_device_handle *dev_handle)
|
|
68
69
|
{
|
|
69
|
-
USBDeviceHandle
|
|
70
|
+
USBDeviceHandle **pHandle = (USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle);
|
|
71
|
+
USBDeviceHandle *handle = *pHandle;
|
|
70
72
|
if (handle == NULL)
|
|
71
73
|
return;
|
|
72
74
|
delete handle;
|
|
73
|
-
*
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
static int
|
|
77
|
-
haiku_get_device_descriptor(struct libusb_device *device, unsigned char *buffer, int *host_endian)
|
|
78
|
-
{
|
|
79
|
-
USBDevice *dev = *((USBDevice **)device->os_priv);
|
|
80
|
-
memcpy(buffer, dev->Descriptor(), DEVICE_DESC_LENGTH);
|
|
81
|
-
*host_endian = 0;
|
|
82
|
-
return LIBUSB_SUCCESS;
|
|
75
|
+
*pHandle = NULL;
|
|
83
76
|
}
|
|
84
77
|
|
|
85
78
|
static int
|
|
86
|
-
haiku_get_active_config_descriptor(struct libusb_device *device,
|
|
79
|
+
haiku_get_active_config_descriptor(struct libusb_device *device, void *buffer, size_t len)
|
|
87
80
|
{
|
|
88
|
-
USBDevice *dev = *((USBDevice **)device
|
|
89
|
-
return haiku_get_config_descriptor(device, dev->ActiveConfigurationIndex(), buffer, len
|
|
81
|
+
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
|
|
82
|
+
return haiku_get_config_descriptor(device, dev->ActiveConfigurationIndex(), buffer, len);
|
|
90
83
|
}
|
|
91
84
|
|
|
92
85
|
static int
|
|
93
|
-
haiku_get_config_descriptor(struct libusb_device *device, uint8_t config_index,
|
|
86
|
+
haiku_get_config_descriptor(struct libusb_device *device, uint8_t config_index, void *buffer, size_t len)
|
|
94
87
|
{
|
|
95
|
-
USBDevice *dev = *((USBDevice **)device
|
|
88
|
+
USBDevice *dev = *((USBDevice **)usbi_get_device_priv(device));
|
|
96
89
|
const usb_configuration_descriptor *config = dev->ConfigurationDescriptor(config_index);
|
|
97
90
|
if (config == NULL) {
|
|
98
91
|
usbi_err(DEVICE_CTX(device), "failed getting configuration descriptor");
|
|
99
|
-
return
|
|
92
|
+
return LIBUSB_ERROR_IO;
|
|
100
93
|
}
|
|
101
94
|
if (len > config->total_length) {
|
|
102
95
|
len = config->total_length;
|
|
103
96
|
}
|
|
104
97
|
memcpy(buffer, config, len);
|
|
105
|
-
*host_endian = 0;
|
|
106
98
|
return len;
|
|
107
99
|
}
|
|
108
100
|
|
|
109
101
|
static int
|
|
110
102
|
haiku_set_configuration(struct libusb_device_handle *dev_handle, int config)
|
|
111
103
|
{
|
|
112
|
-
USBDeviceHandle *handle= *((USBDeviceHandle **)dev_handle
|
|
113
|
-
|
|
104
|
+
USBDeviceHandle *handle= *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
|
|
105
|
+
if (config <= 0)
|
|
106
|
+
return LIBUSB_ERROR_NOT_SUPPORTED; // cannot unconfigure
|
|
107
|
+
return handle->SetConfiguration((uint8)config);
|
|
114
108
|
}
|
|
115
109
|
|
|
116
110
|
static int
|
|
117
|
-
haiku_claim_interface(struct libusb_device_handle *dev_handle,
|
|
111
|
+
haiku_claim_interface(struct libusb_device_handle *dev_handle, uint8_t interface_number)
|
|
118
112
|
{
|
|
119
|
-
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle
|
|
113
|
+
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
|
|
120
114
|
return handle->ClaimInterface(interface_number);
|
|
121
115
|
}
|
|
122
116
|
|
|
123
117
|
static int
|
|
124
|
-
haiku_set_altsetting(struct libusb_device_handle *dev_handle,
|
|
118
|
+
haiku_set_altsetting(struct libusb_device_handle *dev_handle, uint8_t interface_number, uint8_t altsetting)
|
|
125
119
|
{
|
|
126
|
-
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle
|
|
120
|
+
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
|
|
127
121
|
return handle->SetAltSetting(interface_number, altsetting);
|
|
128
122
|
}
|
|
129
123
|
|
|
130
124
|
static int
|
|
131
125
|
haiku_clear_halt(struct libusb_device_handle *dev_handle, unsigned char endpoint)
|
|
132
126
|
{
|
|
133
|
-
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle
|
|
127
|
+
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
|
|
134
128
|
return handle->ClearHalt(endpoint);
|
|
135
129
|
}
|
|
136
130
|
|
|
137
131
|
static int
|
|
138
|
-
|
|
139
|
-
{
|
|
140
|
-
/* TODO */
|
|
141
|
-
return LIBUSB_ERROR_NOT_SUPPORTED;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
static int
|
|
145
|
-
haiku_release_interface(struct libusb_device_handle *dev_handle, int interface_number)
|
|
132
|
+
haiku_release_interface(struct libusb_device_handle *dev_handle, uint8_t interface_number)
|
|
146
133
|
{
|
|
147
|
-
USBDeviceHandle *handle = *((USBDeviceHandle **)dev_handle
|
|
148
|
-
haiku_set_altsetting(dev_handle,interface_number, 0);
|
|
134
|
+
USBDeviceHandle *handle = *((USBDeviceHandle **)usbi_get_device_handle_priv(dev_handle));
|
|
135
|
+
haiku_set_altsetting(dev_handle, interface_number, 0);
|
|
149
136
|
return handle->ReleaseInterface(interface_number);
|
|
150
137
|
}
|
|
151
138
|
|
|
@@ -153,7 +140,7 @@ static int
|
|
|
153
140
|
haiku_submit_transfer(struct usbi_transfer *itransfer)
|
|
154
141
|
{
|
|
155
142
|
struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
|
|
156
|
-
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle
|
|
143
|
+
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)usbi_get_device_handle_priv(fLibusbTransfer->dev_handle));
|
|
157
144
|
return fDeviceHandle->SubmitTransfer(itransfer);
|
|
158
145
|
}
|
|
159
146
|
|
|
@@ -161,27 +148,20 @@ static int
|
|
|
161
148
|
haiku_cancel_transfer(struct usbi_transfer *itransfer)
|
|
162
149
|
{
|
|
163
150
|
struct libusb_transfer *fLibusbTransfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
|
|
164
|
-
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)fLibusbTransfer->dev_handle
|
|
165
|
-
return fDeviceHandle->CancelTransfer(*((USBTransfer **)
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
static void
|
|
169
|
-
haiku_clear_transfer_priv(struct usbi_transfer *itransfer)
|
|
170
|
-
{
|
|
171
|
-
USBTransfer *transfer = *((USBTransfer **)usbi_transfer_get_os_priv(itransfer));
|
|
172
|
-
delete transfer;
|
|
173
|
-
*((USBTransfer **)usbi_transfer_get_os_priv(itransfer)) = NULL;
|
|
151
|
+
USBDeviceHandle *fDeviceHandle = *((USBDeviceHandle **)usbi_get_device_handle_priv(fLibusbTransfer->dev_handle));
|
|
152
|
+
return fDeviceHandle->CancelTransfer(*((USBTransfer **)usbi_get_transfer_priv(itransfer)));
|
|
174
153
|
}
|
|
175
154
|
|
|
176
155
|
static int
|
|
177
156
|
haiku_handle_transfer_completion(struct usbi_transfer *itransfer)
|
|
178
157
|
{
|
|
179
|
-
USBTransfer
|
|
158
|
+
USBTransfer **pTransfer = (USBTransfer **)usbi_get_transfer_priv(itransfer);
|
|
159
|
+
USBTransfer *transfer = *pTransfer;
|
|
180
160
|
|
|
181
161
|
usbi_mutex_lock(&itransfer->lock);
|
|
182
162
|
if (transfer->IsCancelled()) {
|
|
183
163
|
delete transfer;
|
|
184
|
-
*
|
|
164
|
+
*pTransfer = NULL;
|
|
185
165
|
usbi_mutex_unlock(&itransfer->lock);
|
|
186
166
|
if (itransfer->transferred < 0)
|
|
187
167
|
itransfer->transferred = 0;
|
|
@@ -194,74 +174,58 @@ haiku_handle_transfer_completion(struct usbi_transfer *itransfer)
|
|
|
194
174
|
itransfer->transferred = 0;
|
|
195
175
|
}
|
|
196
176
|
delete transfer;
|
|
197
|
-
*
|
|
177
|
+
*pTransfer = NULL;
|
|
198
178
|
usbi_mutex_unlock(&itransfer->lock);
|
|
199
179
|
return usbi_handle_transfer_completion(itransfer, status);
|
|
200
180
|
}
|
|
201
181
|
|
|
202
|
-
static int
|
|
203
|
-
haiku_clock_gettime(int clkid, struct timespec *tp)
|
|
204
|
-
{
|
|
205
|
-
if (clkid == USBI_CLOCK_REALTIME)
|
|
206
|
-
return clock_gettime(CLOCK_REALTIME, tp);
|
|
207
|
-
if (clkid == USBI_CLOCK_MONOTONIC)
|
|
208
|
-
return clock_gettime(CLOCK_MONOTONIC, tp);
|
|
209
|
-
return LIBUSB_ERROR_INVALID_PARAM;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
182
|
const struct usbi_os_backend usbi_backend = {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
#endif
|
|
262
|
-
|
|
263
|
-
.context_priv_size = 0,
|
|
264
|
-
.device_priv_size = sizeof(USBDevice *),
|
|
265
|
-
.device_handle_priv_size = sizeof(USBDeviceHandle *),
|
|
266
|
-
.transfer_priv_size = sizeof(USBTransfer *),
|
|
183
|
+
/*.name =*/ "Haiku usbfs",
|
|
184
|
+
/*.caps =*/ 0,
|
|
185
|
+
/*.init =*/ haiku_init,
|
|
186
|
+
/*.exit =*/ haiku_exit,
|
|
187
|
+
/*.set_option =*/ NULL,
|
|
188
|
+
/*.get_device_list =*/ NULL,
|
|
189
|
+
/*.hotplug_poll =*/ NULL,
|
|
190
|
+
/*.wrap_sys_device =*/ NULL,
|
|
191
|
+
/*.open =*/ haiku_open,
|
|
192
|
+
/*.close =*/ haiku_close,
|
|
193
|
+
|
|
194
|
+
/*.get_active_config_descriptor =*/ haiku_get_active_config_descriptor,
|
|
195
|
+
/*.get_config_descriptor =*/ haiku_get_config_descriptor,
|
|
196
|
+
/*.get_config_descriptor_by_value =*/ NULL,
|
|
197
|
+
|
|
198
|
+
/*.get_configuration =*/ NULL,
|
|
199
|
+
/*.set_configuration =*/ haiku_set_configuration,
|
|
200
|
+
|
|
201
|
+
/*.claim_interface =*/ haiku_claim_interface,
|
|
202
|
+
/*.release_interface =*/ haiku_release_interface,
|
|
203
|
+
/*.set_interface_altsetting =*/ haiku_set_altsetting,
|
|
204
|
+
|
|
205
|
+
/*.clear_halt =*/ haiku_clear_halt,
|
|
206
|
+
/*.reset_device =*/ NULL,
|
|
207
|
+
|
|
208
|
+
/*.alloc_streams =*/ NULL,
|
|
209
|
+
/*.free_streams =*/ NULL,
|
|
210
|
+
|
|
211
|
+
/*.dev_mem_alloc =*/ NULL,
|
|
212
|
+
/*.dev_mem_free =*/ NULL,
|
|
213
|
+
|
|
214
|
+
/*.kernel_driver_active =*/ NULL,
|
|
215
|
+
/*.detach_kernel_driver =*/ NULL,
|
|
216
|
+
/*.attach_kernel_driver =*/ NULL,
|
|
217
|
+
|
|
218
|
+
/*.destroy_device =*/ NULL,
|
|
219
|
+
|
|
220
|
+
/*.submit_transfer =*/ haiku_submit_transfer,
|
|
221
|
+
/*.cancel_transfer =*/ haiku_cancel_transfer,
|
|
222
|
+
/*.clear_transfer_priv =*/ NULL,
|
|
223
|
+
|
|
224
|
+
/*.handle_events =*/ NULL,
|
|
225
|
+
/*.handle_transfer_completion =*/ haiku_handle_transfer_completion,
|
|
226
|
+
|
|
227
|
+
/*.context_priv_size =*/ 0,
|
|
228
|
+
/*.device_priv_size =*/ sizeof(USBDevice *),
|
|
229
|
+
/*.device_handle_priv_size =*/ sizeof(USBDeviceHandle *),
|
|
230
|
+
/*.transfer_priv_size =*/ sizeof(USBTransfer *),
|
|
267
231
|
};
|
|
@@ -21,28 +21,22 @@
|
|
|
21
21
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
-
#include
|
|
24
|
+
#include "libusbi.h"
|
|
25
|
+
#include "linux_usbfs.h"
|
|
25
26
|
|
|
26
|
-
#include <assert.h>
|
|
27
27
|
#include <errno.h>
|
|
28
28
|
#include <fcntl.h>
|
|
29
29
|
#include <poll.h>
|
|
30
|
-
#include <
|
|
31
|
-
#include <stdlib.h>
|
|
30
|
+
#include <pthread.h>
|
|
32
31
|
#include <string.h>
|
|
33
32
|
#include <unistd.h>
|
|
34
|
-
#include <sys/types.h>
|
|
35
33
|
|
|
36
34
|
#ifdef HAVE_ASM_TYPES_H
|
|
37
35
|
#include <asm/types.h>
|
|
38
36
|
#endif
|
|
39
|
-
|
|
40
37
|
#include <sys/socket.h>
|
|
41
38
|
#include <linux/netlink.h>
|
|
42
39
|
|
|
43
|
-
#include "libusbi.h"
|
|
44
|
-
#include "linux_usbfs.h"
|
|
45
|
-
|
|
46
40
|
#define NL_GROUP_KERNEL 1
|
|
47
41
|
|
|
48
42
|
#ifndef SOCK_CLOEXEC
|
|
@@ -54,7 +48,7 @@
|
|
|
54
48
|
#endif
|
|
55
49
|
|
|
56
50
|
static int linux_netlink_socket = -1;
|
|
57
|
-
static
|
|
51
|
+
static usbi_event_t netlink_control_event = USBI_INVALID_EVENT;
|
|
58
52
|
static pthread_t libusb_linux_event_thread;
|
|
59
53
|
|
|
60
54
|
static void *linux_netlink_event_thread_main(void *arg);
|
|
@@ -68,12 +62,12 @@ static int set_fd_cloexec_nb(int fd, int socktype)
|
|
|
68
62
|
if (!(socktype & SOCK_CLOEXEC)) {
|
|
69
63
|
flags = fcntl(fd, F_GETFD);
|
|
70
64
|
if (flags == -1) {
|
|
71
|
-
usbi_err(NULL, "failed to get netlink fd flags
|
|
65
|
+
usbi_err(NULL, "failed to get netlink fd flags, errno=%d", errno);
|
|
72
66
|
return -1;
|
|
73
67
|
}
|
|
74
68
|
|
|
75
69
|
if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) {
|
|
76
|
-
usbi_err(NULL, "failed to set netlink fd flags
|
|
70
|
+
usbi_err(NULL, "failed to set netlink fd flags, errno=%d", errno);
|
|
77
71
|
return -1;
|
|
78
72
|
}
|
|
79
73
|
}
|
|
@@ -83,12 +77,12 @@ static int set_fd_cloexec_nb(int fd, int socktype)
|
|
|
83
77
|
if (!(socktype & SOCK_NONBLOCK)) {
|
|
84
78
|
flags = fcntl(fd, F_GETFL);
|
|
85
79
|
if (flags == -1) {
|
|
86
|
-
usbi_err(NULL, "failed to get netlink fd status flags
|
|
80
|
+
usbi_err(NULL, "failed to get netlink fd status flags, errno=%d", errno);
|
|
87
81
|
return -1;
|
|
88
82
|
}
|
|
89
83
|
|
|
90
84
|
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK) == -1) {
|
|
91
|
-
usbi_err(NULL, "failed to set netlink fd status flags
|
|
85
|
+
usbi_err(NULL, "failed to set netlink fd status flags, errno=%d", errno);
|
|
92
86
|
return -1;
|
|
93
87
|
}
|
|
94
88
|
}
|
|
@@ -105,13 +99,13 @@ int linux_netlink_start_event_monitor(void)
|
|
|
105
99
|
|
|
106
100
|
linux_netlink_socket = socket(PF_NETLINK, socktype, NETLINK_KOBJECT_UEVENT);
|
|
107
101
|
if (linux_netlink_socket == -1 && errno == EINVAL) {
|
|
108
|
-
usbi_dbg("failed to create netlink socket of type %d, attempting SOCK_RAW", socktype);
|
|
102
|
+
usbi_dbg(NULL, "failed to create netlink socket of type %d, attempting SOCK_RAW", socktype);
|
|
109
103
|
socktype = SOCK_RAW;
|
|
110
104
|
linux_netlink_socket = socket(PF_NETLINK, socktype, NETLINK_KOBJECT_UEVENT);
|
|
111
105
|
}
|
|
112
106
|
|
|
113
107
|
if (linux_netlink_socket == -1) {
|
|
114
|
-
usbi_err(NULL, "failed to create netlink socket
|
|
108
|
+
usbi_err(NULL, "failed to create netlink socket, errno=%d", errno);
|
|
115
109
|
goto err;
|
|
116
110
|
}
|
|
117
111
|
|
|
@@ -121,35 +115,33 @@ int linux_netlink_start_event_monitor(void)
|
|
|
121
115
|
|
|
122
116
|
ret = bind(linux_netlink_socket, (struct sockaddr *)&sa_nl, sizeof(sa_nl));
|
|
123
117
|
if (ret == -1) {
|
|
124
|
-
usbi_err(NULL, "failed to bind netlink socket
|
|
118
|
+
usbi_err(NULL, "failed to bind netlink socket, errno=%d", errno);
|
|
125
119
|
goto err_close_socket;
|
|
126
120
|
}
|
|
127
121
|
|
|
128
122
|
ret = setsockopt(linux_netlink_socket, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt));
|
|
129
123
|
if (ret == -1) {
|
|
130
|
-
usbi_err(NULL, "failed to set netlink socket SO_PASSCRED option
|
|
124
|
+
usbi_err(NULL, "failed to set netlink socket SO_PASSCRED option, errno=%d", errno);
|
|
131
125
|
goto err_close_socket;
|
|
132
126
|
}
|
|
133
127
|
|
|
134
|
-
ret =
|
|
128
|
+
ret = usbi_create_event(&netlink_control_event);
|
|
135
129
|
if (ret) {
|
|
136
|
-
usbi_err(NULL, "failed to create netlink control
|
|
130
|
+
usbi_err(NULL, "failed to create netlink control event");
|
|
137
131
|
goto err_close_socket;
|
|
138
132
|
}
|
|
139
133
|
|
|
140
134
|
ret = pthread_create(&libusb_linux_event_thread, NULL, linux_netlink_event_thread_main, NULL);
|
|
141
135
|
if (ret != 0) {
|
|
142
136
|
usbi_err(NULL, "failed to create netlink event thread (%d)", ret);
|
|
143
|
-
goto
|
|
137
|
+
goto err_destroy_event;
|
|
144
138
|
}
|
|
145
139
|
|
|
146
140
|
return LIBUSB_SUCCESS;
|
|
147
141
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
netlink_control_pipe[0] = -1;
|
|
152
|
-
netlink_control_pipe[1] = -1;
|
|
142
|
+
err_destroy_event:
|
|
143
|
+
usbi_destroy_event(&netlink_control_event);
|
|
144
|
+
netlink_control_event = (usbi_event_t)USBI_INVALID_EVENT;
|
|
153
145
|
err_close_socket:
|
|
154
146
|
close(linux_netlink_socket);
|
|
155
147
|
linux_netlink_socket = -1;
|
|
@@ -159,28 +151,23 @@ err:
|
|
|
159
151
|
|
|
160
152
|
int linux_netlink_stop_event_monitor(void)
|
|
161
153
|
{
|
|
162
|
-
|
|
163
|
-
ssize_t r;
|
|
154
|
+
int ret;
|
|
164
155
|
|
|
165
156
|
assert(linux_netlink_socket != -1);
|
|
166
157
|
|
|
167
|
-
/*
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
158
|
+
/* Signal the control event and wait for the thread to exit */
|
|
159
|
+
usbi_signal_event(&netlink_control_event);
|
|
160
|
+
|
|
161
|
+
ret = pthread_join(libusb_linux_event_thread, NULL);
|
|
162
|
+
if (ret)
|
|
163
|
+
usbi_warn(NULL, "failed to join netlink event thread (%d)", ret);
|
|
172
164
|
|
|
173
|
-
|
|
165
|
+
usbi_destroy_event(&netlink_control_event);
|
|
166
|
+
netlink_control_event = (usbi_event_t)USBI_INVALID_EVENT;
|
|
174
167
|
|
|
175
168
|
close(linux_netlink_socket);
|
|
176
169
|
linux_netlink_socket = -1;
|
|
177
170
|
|
|
178
|
-
/* close and reset control pipe */
|
|
179
|
-
close(netlink_control_pipe[0]);
|
|
180
|
-
close(netlink_control_pipe[1]);
|
|
181
|
-
netlink_control_pipe[0] = -1;
|
|
182
|
-
netlink_control_pipe[1] = -1;
|
|
183
|
-
|
|
184
171
|
return LIBUSB_SUCCESS;
|
|
185
172
|
}
|
|
186
173
|
|
|
@@ -217,7 +204,7 @@ static int linux_netlink_parse(const char *buffer, size_t len, int *detached,
|
|
|
217
204
|
} else if (strcmp(tmp, "remove") == 0) {
|
|
218
205
|
*detached = 1;
|
|
219
206
|
} else if (strcmp(tmp, "add") != 0) {
|
|
220
|
-
usbi_dbg("unknown device action %s", tmp);
|
|
207
|
+
usbi_dbg(NULL, "unknown device action %s", tmp);
|
|
221
208
|
return -1;
|
|
222
209
|
}
|
|
223
210
|
|
|
@@ -314,7 +301,7 @@ static int linux_netlink_read_message(void)
|
|
|
314
301
|
len = recvmsg(linux_netlink_socket, &msg, 0);
|
|
315
302
|
if (len == -1) {
|
|
316
303
|
if (errno != EAGAIN && errno != EINTR)
|
|
317
|
-
usbi_err(NULL, "error receiving message from netlink
|
|
304
|
+
usbi_err(NULL, "error receiving message from netlink, errno=%d", errno);
|
|
318
305
|
return -1;
|
|
319
306
|
}
|
|
320
307
|
|
|
@@ -324,20 +311,20 @@ static int linux_netlink_read_message(void)
|
|
|
324
311
|
}
|
|
325
312
|
|
|
326
313
|
if (sa_nl.nl_groups != NL_GROUP_KERNEL || sa_nl.nl_pid != 0) {
|
|
327
|
-
usbi_dbg("ignoring netlink message from unknown group/PID (%u/%u)",
|
|
314
|
+
usbi_dbg(NULL, "ignoring netlink message from unknown group/PID (%u/%u)",
|
|
328
315
|
(unsigned int)sa_nl.nl_groups, (unsigned int)sa_nl.nl_pid);
|
|
329
316
|
return -1;
|
|
330
317
|
}
|
|
331
318
|
|
|
332
319
|
cmsg = CMSG_FIRSTHDR(&msg);
|
|
333
320
|
if (!cmsg || cmsg->cmsg_type != SCM_CREDENTIALS) {
|
|
334
|
-
usbi_dbg("ignoring netlink message with no sender credentials");
|
|
321
|
+
usbi_dbg(NULL, "ignoring netlink message with no sender credentials");
|
|
335
322
|
return -1;
|
|
336
323
|
}
|
|
337
324
|
|
|
338
325
|
cred = (struct ucred *)CMSG_DATA(cmsg);
|
|
339
326
|
if (cred->uid != 0) {
|
|
340
|
-
usbi_dbg("ignoring netlink message with non-zero sender UID %u", (unsigned int)cred->uid);
|
|
327
|
+
usbi_dbg(NULL, "ignoring netlink message with non-zero sender UID %u", (unsigned int)cred->uid);
|
|
341
328
|
return -1;
|
|
342
329
|
}
|
|
343
330
|
|
|
@@ -345,7 +332,7 @@ static int linux_netlink_read_message(void)
|
|
|
345
332
|
if (r)
|
|
346
333
|
return r;
|
|
347
334
|
|
|
348
|
-
usbi_dbg("netlink hotplug found device busnum: %hhu, devaddr: %hhu, sys_name: %s, removed: %s",
|
|
335
|
+
usbi_dbg(NULL, "netlink hotplug found device busnum: %hhu, devaddr: %hhu, sys_name: %s, removed: %s",
|
|
349
336
|
busnum, devaddr, sys_name, detached ? "yes" : "no");
|
|
350
337
|
|
|
351
338
|
/* signal device is available (or not) to all contexts */
|
|
@@ -359,40 +346,45 @@ static int linux_netlink_read_message(void)
|
|
|
359
346
|
|
|
360
347
|
static void *linux_netlink_event_thread_main(void *arg)
|
|
361
348
|
{
|
|
362
|
-
char dummy;
|
|
363
|
-
int r;
|
|
364
|
-
ssize_t nb;
|
|
365
349
|
struct pollfd fds[] = {
|
|
366
|
-
{ .fd =
|
|
367
|
-
.events =
|
|
350
|
+
{ .fd = USBI_EVENT_OS_HANDLE(&netlink_control_event),
|
|
351
|
+
.events = USBI_EVENT_POLL_EVENTS },
|
|
368
352
|
{ .fd = linux_netlink_socket,
|
|
369
353
|
.events = POLLIN },
|
|
370
354
|
};
|
|
355
|
+
int r;
|
|
371
356
|
|
|
372
357
|
UNUSED(arg);
|
|
373
358
|
|
|
374
|
-
|
|
359
|
+
#if defined(HAVE_PTHREAD_SETNAME_NP)
|
|
360
|
+
r = pthread_setname_np(pthread_self(), "libusb_event");
|
|
361
|
+
if (r)
|
|
362
|
+
usbi_warn(NULL, "failed to set hotplug event thread name, error=%d", r);
|
|
363
|
+
#endif
|
|
375
364
|
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
365
|
+
usbi_dbg(NULL, "netlink event thread entering");
|
|
366
|
+
|
|
367
|
+
while (1) {
|
|
368
|
+
r = poll(fds, 2, -1);
|
|
369
|
+
if (r == -1) {
|
|
370
|
+
/* check for temporary failure */
|
|
371
|
+
if (errno == EINTR)
|
|
372
|
+
continue;
|
|
373
|
+
usbi_err(NULL, "poll() failed, errno=%d", errno);
|
|
374
|
+
break;
|
|
380
375
|
}
|
|
381
|
-
if (fds[0].revents
|
|
382
|
-
/* activity on control
|
|
383
|
-
nb = read(netlink_control_pipe[0], &dummy, sizeof(dummy));
|
|
384
|
-
if (nb <= 0)
|
|
385
|
-
usbi_warn(NULL, "netlink control pipe read failed");
|
|
376
|
+
if (fds[0].revents) {
|
|
377
|
+
/* activity on control event, exit */
|
|
386
378
|
break;
|
|
387
379
|
}
|
|
388
|
-
if (fds[1].revents
|
|
380
|
+
if (fds[1].revents) {
|
|
389
381
|
usbi_mutex_static_lock(&linux_hotplug_lock);
|
|
390
382
|
linux_netlink_read_message();
|
|
391
383
|
usbi_mutex_static_unlock(&linux_hotplug_lock);
|
|
392
384
|
}
|
|
393
385
|
}
|
|
394
386
|
|
|
395
|
-
usbi_dbg("netlink event thread exiting");
|
|
387
|
+
usbi_dbg(NULL, "netlink event thread exiting");
|
|
396
388
|
|
|
397
389
|
return NULL;
|
|
398
390
|
}
|