usb 1.7.2-prebuild
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/.github/workflows/prebuild.yml +62 -0
- package/.gitmodules +3 -0
- package/LICENSE +7 -0
- package/Readme.md +339 -0
- package/binding.gyp +90 -0
- package/libusb/.gitattributes +11 -0
- package/libusb/.private/README.txt +5 -0
- package/libusb/.private/bd.cmd +89 -0
- package/libusb/.private/bm.sh +54 -0
- package/libusb/.private/bwince.cmd +57 -0
- package/libusb/.private/post-rewrite.sh +28 -0
- package/libusb/.private/pre-commit.sh +42 -0
- package/libusb/.private/wbs.txt +61 -0
- package/libusb/.private/wbs_wince.txt +42 -0
- package/libusb/AUTHORS +78 -0
- package/libusb/COPYING +504 -0
- package/libusb/ChangeLog +211 -0
- package/libusb/INSTALL +234 -0
- package/libusb/INSTALL_WIN.txt +73 -0
- package/libusb/Makefile.am +28 -0
- package/libusb/NEWS +2 -0
- package/libusb/PORTING +94 -0
- package/libusb/README +28 -0
- package/libusb/README.git +41 -0
- package/libusb/TODO +2 -0
- package/libusb/Xcode/common.xcconfig +49 -0
- package/libusb/Xcode/debug.xcconfig +29 -0
- package/libusb/Xcode/libusb.xcconfig +21 -0
- package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +1 -0
- package/libusb/Xcode/libusb_debug.xcconfig +21 -0
- package/libusb/Xcode/libusb_release.xcconfig +21 -0
- package/libusb/Xcode/release.xcconfig +30 -0
- package/libusb/android/README +114 -0
- package/libusb/android/jni/Android.mk +23 -0
- package/libusb/android/jni/Application.mk +24 -0
- package/libusb/android/jni/examples.mk +134 -0
- package/libusb/android/jni/libusb.mk +54 -0
- package/libusb/android/jni/tests.mk +56 -0
- package/libusb/autogen.sh +8 -0
- package/libusb/bootstrap.sh +19 -0
- package/libusb/configure.ac +304 -0
- package/libusb/doc/Makefile.am +9 -0
- package/libusb/doc/doxygen.cfg.in +1288 -0
- package/libusb/doc/libusb.png +0 -0
- package/libusb/examples/Makefile.am +19 -0
- package/libusb/examples/dpfp.c +506 -0
- package/libusb/examples/dpfp_threaded.c +544 -0
- package/libusb/examples/ezusb.c +831 -0
- package/libusb/examples/ezusb.h +120 -0
- package/libusb/examples/fxload.c +287 -0
- package/libusb/examples/getopt/getopt.c +1060 -0
- package/libusb/examples/getopt/getopt.h +180 -0
- package/libusb/examples/getopt/getopt1.c +188 -0
- package/libusb/examples/hotplugtest.c +104 -0
- package/libusb/examples/listdevs.c +71 -0
- package/libusb/examples/sam3u_benchmark.c +193 -0
- package/libusb/examples/xusb.c +1129 -0
- package/libusb/libusb/Makefile.am +75 -0
- package/libusb/libusb/core.c +2342 -0
- package/libusb/libusb/descriptor.c +1199 -0
- package/libusb/libusb/hotplug.c +327 -0
- package/libusb/libusb/hotplug.h +82 -0
- package/libusb/libusb/io.c +2631 -0
- package/libusb/libusb/libusb-1.0.def +166 -0
- package/libusb/libusb/libusb-1.0.rc +61 -0
- package/libusb/libusb/libusb.h +1998 -0
- package/libusb/libusb/libusbi.h +1040 -0
- package/libusb/libusb/os/darwin_usb.c +2009 -0
- package/libusb/libusb/os/darwin_usb.h +162 -0
- package/libusb/libusb/os/linux_netlink.c +369 -0
- package/libusb/libusb/os/linux_udev.c +307 -0
- package/libusb/libusb/os/linux_usbfs.c +2695 -0
- package/libusb/libusb/os/linux_usbfs.h +192 -0
- package/libusb/libusb/os/netbsd_usb.c +738 -0
- package/libusb/libusb/os/openbsd_usb.c +832 -0
- package/libusb/libusb/os/poll_posix.c +51 -0
- package/libusb/libusb/os/poll_posix.h +11 -0
- package/libusb/libusb/os/poll_windows.c +796 -0
- package/libusb/libusb/os/poll_windows.h +131 -0
- package/libusb/libusb/os/threads_posix.c +82 -0
- package/libusb/libusb/os/threads_posix.h +50 -0
- package/libusb/libusb/os/threads_windows.c +212 -0
- package/libusb/libusb/os/threads_windows.h +87 -0
- package/libusb/libusb/os/wince_usb.c +1032 -0
- package/libusb/libusb/os/wince_usb.h +131 -0
- package/libusb/libusb/os/windows_common.h +108 -0
- package/libusb/libusb/os/windows_usb.c +5347 -0
- package/libusb/libusb/os/windows_usb.h +971 -0
- package/libusb/libusb/strerror.c +199 -0
- package/libusb/libusb/sync.c +307 -0
- package/libusb/libusb/version.h +18 -0
- package/libusb/libusb/version_nano.h +1 -0
- package/libusb/libusb-1.0.pc.in +11 -0
- package/libusb/msvc/config.h +50 -0
- package/libusb/msvc/ddk_build.cmd +175 -0
- package/libusb/msvc/errno.h +102 -0
- package/libusb/msvc/fxload_2010.vcxproj +170 -0
- package/libusb/msvc/fxload_2010.vcxproj.filters +25 -0
- package/libusb/msvc/fxload_2012.vcxproj +174 -0
- package/libusb/msvc/fxload_2012.vcxproj.filters +25 -0
- package/libusb/msvc/fxload_2013.vcxproj +174 -0
- package/libusb/msvc/fxload_sources +23 -0
- package/libusb/msvc/getopt_2005.vcproj +288 -0
- package/libusb/msvc/getopt_2010.vcxproj +131 -0
- package/libusb/msvc/getopt_2010.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2012.vcxproj +136 -0
- package/libusb/msvc/getopt_2012.vcxproj.filters +26 -0
- package/libusb/msvc/getopt_2013.vcxproj +136 -0
- package/libusb/msvc/getopt_sources +20 -0
- package/libusb/msvc/hotplugtest_2010.vcxproj +163 -0
- package/libusb/msvc/hotplugtest_2010.vcxproj.filters +14 -0
- package/libusb/msvc/hotplugtest_2012.vcxproj +167 -0
- package/libusb/msvc/hotplugtest_2012.vcxproj.filters +14 -0
- package/libusb/msvc/hotplugtest_2013.vcxproj +167 -0
- package/libusb/msvc/hotplugtest_sources +20 -0
- package/libusb/msvc/inttypes.h +295 -0
- package/libusb/msvc/libusb.dsw +71 -0
- package/libusb/msvc/libusb_2005.sln +95 -0
- package/libusb/msvc/libusb_2010.sln +94 -0
- package/libusb/msvc/libusb_2012.sln +94 -0
- package/libusb/msvc/libusb_2013.sln +100 -0
- package/libusb/msvc/libusb_2015.sln +100 -0
- package/libusb/msvc/libusb_dll.dsp +194 -0
- package/libusb/msvc/libusb_dll_2005.vcproj +436 -0
- package/libusb/msvc/libusb_dll_2010.vcxproj +170 -0
- package/libusb/msvc/libusb_dll_2010.vcxproj.filters +81 -0
- package/libusb/msvc/libusb_dll_2012.vcxproj +175 -0
- package/libusb/msvc/libusb_dll_2012.vcxproj.filters +84 -0
- package/libusb/msvc/libusb_dll_2013.vcxproj +175 -0
- package/libusb/msvc/libusb_dll_wince.vcproj +1243 -0
- package/libusb/msvc/libusb_sources +38 -0
- package/libusb/msvc/libusb_static.dsp +174 -0
- package/libusb/msvc/libusb_static_2005.vcproj +362 -0
- package/libusb/msvc/libusb_static_2010.vcxproj +156 -0
- package/libusb/msvc/libusb_static_2010.vcxproj.filters +74 -0
- package/libusb/msvc/libusb_static_2012.vcxproj +160 -0
- package/libusb/msvc/libusb_static_2012.vcxproj.filters +74 -0
- package/libusb/msvc/libusb_static_2013.vcxproj +160 -0
- package/libusb/msvc/libusb_static_wince.vcproj +1185 -0
- package/libusb/msvc/libusb_wince.sln +246 -0
- package/libusb/msvc/listdevs.dsp +103 -0
- package/libusb/msvc/listdevs_2005.vcproj +360 -0
- package/libusb/msvc/listdevs_2010.vcxproj +165 -0
- package/libusb/msvc/listdevs_2010.vcxproj.filters +14 -0
- package/libusb/msvc/listdevs_2012.vcxproj +169 -0
- package/libusb/msvc/listdevs_2012.vcxproj.filters +14 -0
- package/libusb/msvc/listdevs_2013.vcxproj +169 -0
- package/libusb/msvc/listdevs_sources +19 -0
- package/libusb/msvc/listdevs_wince.vcproj +1120 -0
- package/libusb/msvc/missing.c +80 -0
- package/libusb/msvc/missing.h +32 -0
- package/libusb/msvc/stdint.h +256 -0
- package/libusb/msvc/stress_2005.vcproj +390 -0
- package/libusb/msvc/stress_2010.vcxproj +167 -0
- package/libusb/msvc/stress_2010.vcxproj.filters +25 -0
- package/libusb/msvc/stress_2012.vcxproj +171 -0
- package/libusb/msvc/stress_2012.vcxproj.filters +25 -0
- package/libusb/msvc/stress_2013.vcxproj +171 -0
- package/libusb/msvc/stress_wince.vcproj +1128 -0
- package/libusb/msvc/xusb.dsp +102 -0
- package/libusb/msvc/xusb_2005.vcproj +344 -0
- package/libusb/msvc/xusb_2010.vcxproj +163 -0
- package/libusb/msvc/xusb_2010.vcxproj.filters +14 -0
- package/libusb/msvc/xusb_2012.vcxproj +167 -0
- package/libusb/msvc/xusb_2012.vcxproj.filters +14 -0
- package/libusb/msvc/xusb_2013.vcxproj +167 -0
- package/libusb/msvc/xusb_sources +20 -0
- package/libusb/msvc/xusb_wince.vcproj +1120 -0
- package/libusb/tests/Makefile.am +6 -0
- package/libusb/tests/libusb_testlib.h +107 -0
- package/libusb/tests/stress.c +160 -0
- package/libusb/tests/testlib.c +281 -0
- package/libusb.gypi +136 -0
- package/libusb_config/config.h +1 -0
- package/package.json +69 -0
- package/src/device.cc +412 -0
- package/src/helpers.h +64 -0
- package/src/node_usb.cc +319 -0
- package/src/node_usb.h +120 -0
- package/src/transfer.cc +148 -0
- package/src/uv_async_queue.h +33 -0
- package/test/usb.coffee +191 -0
- package/usb.js +524 -0
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
/* -*- Mode: C; c-basic-offset:8 ; indent-tabs-mode:t -*- */
|
|
2
|
+
/*
|
|
3
|
+
* Linux usbfs backend for libusb
|
|
4
|
+
* Copyright (C) 2007-2009 Daniel Drake <dsd@gentoo.org>
|
|
5
|
+
* Copyright (c) 2001 Johannes Erdfelt <johannes@erdfelt.com>
|
|
6
|
+
* Copyright (c) 2012-2013 Nathan Hjelm <hjelmn@mac.com>
|
|
7
|
+
*
|
|
8
|
+
* This library is free software; you can redistribute it and/or
|
|
9
|
+
* modify it under the terms of the GNU Lesser General Public
|
|
10
|
+
* License as published by the Free Software Foundation; either
|
|
11
|
+
* version 2.1 of the License, or (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This library is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
16
|
+
* Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public
|
|
19
|
+
* License along with this library; if not, write to the Free Software
|
|
20
|
+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
#include "config.h"
|
|
24
|
+
|
|
25
|
+
#include <assert.h>
|
|
26
|
+
#include <ctype.h>
|
|
27
|
+
#include <dirent.h>
|
|
28
|
+
#include <errno.h>
|
|
29
|
+
#include <fcntl.h>
|
|
30
|
+
#include <poll.h>
|
|
31
|
+
#include <stdio.h>
|
|
32
|
+
#include <stdlib.h>
|
|
33
|
+
#include <string.h>
|
|
34
|
+
#include <sys/ioctl.h>
|
|
35
|
+
#include <sys/stat.h>
|
|
36
|
+
#include <sys/types.h>
|
|
37
|
+
#include <sys/utsname.h>
|
|
38
|
+
#include <sys/socket.h>
|
|
39
|
+
#include <unistd.h>
|
|
40
|
+
#include <libudev.h>
|
|
41
|
+
|
|
42
|
+
#include "libusb.h"
|
|
43
|
+
#include "libusbi.h"
|
|
44
|
+
#include "linux_usbfs.h"
|
|
45
|
+
|
|
46
|
+
/* udev context */
|
|
47
|
+
static struct udev *udev_ctx = NULL;
|
|
48
|
+
static int udev_monitor_fd = -1;
|
|
49
|
+
static int udev_control_pipe[2] = {-1, -1};
|
|
50
|
+
static struct udev_monitor *udev_monitor = NULL;
|
|
51
|
+
static pthread_t linux_event_thread;
|
|
52
|
+
|
|
53
|
+
static void udev_hotplug_event(struct udev_device* udev_dev);
|
|
54
|
+
static void *linux_udev_event_thread_main(void *arg);
|
|
55
|
+
|
|
56
|
+
int linux_udev_start_event_monitor(void)
|
|
57
|
+
{
|
|
58
|
+
int r;
|
|
59
|
+
|
|
60
|
+
assert(udev_ctx == NULL);
|
|
61
|
+
udev_ctx = udev_new();
|
|
62
|
+
if (!udev_ctx) {
|
|
63
|
+
usbi_err(NULL, "could not create udev context");
|
|
64
|
+
goto err;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
udev_monitor = udev_monitor_new_from_netlink(udev_ctx, "udev");
|
|
68
|
+
if (!udev_monitor) {
|
|
69
|
+
usbi_err(NULL, "could not initialize udev monitor");
|
|
70
|
+
goto err_free_ctx;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
r = udev_monitor_filter_add_match_subsystem_devtype(udev_monitor, "usb", 0);
|
|
74
|
+
if (r) {
|
|
75
|
+
usbi_err(NULL, "could not initialize udev monitor filter for \"usb\" subsystem");
|
|
76
|
+
goto err_free_monitor;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (udev_monitor_enable_receiving(udev_monitor)) {
|
|
80
|
+
usbi_err(NULL, "failed to enable the udev monitor");
|
|
81
|
+
goto err_free_monitor;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
udev_monitor_fd = udev_monitor_get_fd(udev_monitor);
|
|
85
|
+
|
|
86
|
+
/* Some older versions of udev are not non-blocking by default,
|
|
87
|
+
* so make sure this is set */
|
|
88
|
+
r = fcntl(udev_monitor_fd, F_GETFL);
|
|
89
|
+
if (r == -1) {
|
|
90
|
+
usbi_err(NULL, "getting udev monitor fd flags (%d)", errno);
|
|
91
|
+
goto err_free_monitor;
|
|
92
|
+
}
|
|
93
|
+
r = fcntl(udev_monitor_fd, F_SETFL, r | O_NONBLOCK);
|
|
94
|
+
if (r) {
|
|
95
|
+
usbi_err(NULL, "setting udev monitor fd flags (%d)", errno);
|
|
96
|
+
goto err_free_monitor;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
r = usbi_pipe(udev_control_pipe);
|
|
100
|
+
if (r) {
|
|
101
|
+
usbi_err(NULL, "could not create udev control pipe");
|
|
102
|
+
goto err_free_monitor;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
r = pthread_create(&linux_event_thread, NULL, linux_udev_event_thread_main, NULL);
|
|
106
|
+
if (r) {
|
|
107
|
+
usbi_err(NULL, "creating hotplug event thread (%d)", r);
|
|
108
|
+
goto err_close_pipe;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return LIBUSB_SUCCESS;
|
|
112
|
+
|
|
113
|
+
err_close_pipe:
|
|
114
|
+
close(udev_control_pipe[0]);
|
|
115
|
+
close(udev_control_pipe[1]);
|
|
116
|
+
err_free_monitor:
|
|
117
|
+
udev_monitor_unref(udev_monitor);
|
|
118
|
+
udev_monitor = NULL;
|
|
119
|
+
udev_monitor_fd = -1;
|
|
120
|
+
err_free_ctx:
|
|
121
|
+
udev_unref(udev_ctx);
|
|
122
|
+
err:
|
|
123
|
+
udev_ctx = NULL;
|
|
124
|
+
return LIBUSB_ERROR_OTHER;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
int linux_udev_stop_event_monitor(void)
|
|
128
|
+
{
|
|
129
|
+
char dummy = 1;
|
|
130
|
+
int r;
|
|
131
|
+
|
|
132
|
+
assert(udev_ctx != NULL);
|
|
133
|
+
assert(udev_monitor != NULL);
|
|
134
|
+
assert(udev_monitor_fd != -1);
|
|
135
|
+
|
|
136
|
+
/* Write some dummy data to the control pipe and
|
|
137
|
+
* wait for the thread to exit */
|
|
138
|
+
r = usbi_write(udev_control_pipe[1], &dummy, sizeof(dummy));
|
|
139
|
+
if (r <= 0) {
|
|
140
|
+
usbi_warn(NULL, "udev control pipe signal failed");
|
|
141
|
+
}
|
|
142
|
+
pthread_join(linux_event_thread, NULL);
|
|
143
|
+
|
|
144
|
+
/* Release the udev monitor */
|
|
145
|
+
udev_monitor_unref(udev_monitor);
|
|
146
|
+
udev_monitor = NULL;
|
|
147
|
+
udev_monitor_fd = -1;
|
|
148
|
+
|
|
149
|
+
/* Clean up the udev context */
|
|
150
|
+
udev_unref(udev_ctx);
|
|
151
|
+
udev_ctx = NULL;
|
|
152
|
+
|
|
153
|
+
/* close and reset control pipe */
|
|
154
|
+
close(udev_control_pipe[0]);
|
|
155
|
+
close(udev_control_pipe[1]);
|
|
156
|
+
udev_control_pipe[0] = -1;
|
|
157
|
+
udev_control_pipe[1] = -1;
|
|
158
|
+
|
|
159
|
+
return LIBUSB_SUCCESS;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
static void *linux_udev_event_thread_main(void *arg)
|
|
163
|
+
{
|
|
164
|
+
char dummy;
|
|
165
|
+
int r;
|
|
166
|
+
struct udev_device* udev_dev;
|
|
167
|
+
struct pollfd fds[] = {
|
|
168
|
+
{.fd = udev_control_pipe[0],
|
|
169
|
+
.events = POLLIN},
|
|
170
|
+
{.fd = udev_monitor_fd,
|
|
171
|
+
.events = POLLIN},
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
usbi_dbg("udev event thread entering.");
|
|
175
|
+
|
|
176
|
+
while (poll(fds, 2, -1) >= 0) {
|
|
177
|
+
if (fds[0].revents & POLLIN) {
|
|
178
|
+
/* activity on control pipe, read the byte and exit */
|
|
179
|
+
r = usbi_read(udev_control_pipe[0], &dummy, sizeof(dummy));
|
|
180
|
+
if (r <= 0) {
|
|
181
|
+
usbi_warn(NULL, "udev control pipe read failed");
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
}
|
|
185
|
+
if (fds[1].revents & POLLIN) {
|
|
186
|
+
usbi_mutex_static_lock(&linux_hotplug_lock);
|
|
187
|
+
udev_dev = udev_monitor_receive_device(udev_monitor);
|
|
188
|
+
if (udev_dev)
|
|
189
|
+
udev_hotplug_event(udev_dev);
|
|
190
|
+
usbi_mutex_static_unlock(&linux_hotplug_lock);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
usbi_dbg("udev event thread exiting");
|
|
195
|
+
|
|
196
|
+
return NULL;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
static int udev_device_info(struct libusb_context *ctx, int detached,
|
|
200
|
+
struct udev_device *udev_dev, uint8_t *busnum,
|
|
201
|
+
uint8_t *devaddr, const char **sys_name) {
|
|
202
|
+
const char *dev_node;
|
|
203
|
+
|
|
204
|
+
dev_node = udev_device_get_devnode(udev_dev);
|
|
205
|
+
if (!dev_node) {
|
|
206
|
+
return LIBUSB_ERROR_OTHER;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
*sys_name = udev_device_get_sysname(udev_dev);
|
|
210
|
+
if (!*sys_name) {
|
|
211
|
+
return LIBUSB_ERROR_OTHER;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return linux_get_device_address(ctx, detached, busnum, devaddr,
|
|
215
|
+
dev_node, *sys_name);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
static void udev_hotplug_event(struct udev_device* udev_dev)
|
|
219
|
+
{
|
|
220
|
+
const char* udev_action;
|
|
221
|
+
const char* sys_name = NULL;
|
|
222
|
+
uint8_t busnum = 0, devaddr = 0;
|
|
223
|
+
int detached;
|
|
224
|
+
int r;
|
|
225
|
+
|
|
226
|
+
do {
|
|
227
|
+
udev_action = udev_device_get_action(udev_dev);
|
|
228
|
+
if (!udev_action) {
|
|
229
|
+
break;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
detached = !strncmp(udev_action, "remove", 6);
|
|
233
|
+
|
|
234
|
+
r = udev_device_info(NULL, detached, udev_dev, &busnum, &devaddr, &sys_name);
|
|
235
|
+
if (LIBUSB_SUCCESS != r) {
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
usbi_dbg("udev hotplug event. action: %s.", udev_action);
|
|
240
|
+
|
|
241
|
+
if (strncmp(udev_action, "add", 3) == 0) {
|
|
242
|
+
linux_hotplug_enumerate(busnum, devaddr, sys_name);
|
|
243
|
+
} else if (detached) {
|
|
244
|
+
linux_device_disconnected(busnum, devaddr, sys_name);
|
|
245
|
+
} else {
|
|
246
|
+
usbi_err(NULL, "ignoring udev action %s", udev_action);
|
|
247
|
+
}
|
|
248
|
+
} while (0);
|
|
249
|
+
|
|
250
|
+
udev_device_unref(udev_dev);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
int linux_udev_scan_devices(struct libusb_context *ctx)
|
|
254
|
+
{
|
|
255
|
+
struct udev_enumerate *enumerator;
|
|
256
|
+
struct udev_list_entry *devices, *entry;
|
|
257
|
+
struct udev_device *udev_dev;
|
|
258
|
+
const char *sys_name;
|
|
259
|
+
int r;
|
|
260
|
+
|
|
261
|
+
assert(udev_ctx != NULL);
|
|
262
|
+
|
|
263
|
+
enumerator = udev_enumerate_new(udev_ctx);
|
|
264
|
+
if (NULL == enumerator) {
|
|
265
|
+
usbi_err(ctx, "error creating udev enumerator");
|
|
266
|
+
return LIBUSB_ERROR_OTHER;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
udev_enumerate_add_match_subsystem(enumerator, "usb");
|
|
270
|
+
udev_enumerate_scan_devices(enumerator);
|
|
271
|
+
devices = udev_enumerate_get_list_entry(enumerator);
|
|
272
|
+
|
|
273
|
+
udev_list_entry_foreach(entry, devices) {
|
|
274
|
+
const char *path = udev_list_entry_get_name(entry);
|
|
275
|
+
uint8_t busnum = 0, devaddr = 0;
|
|
276
|
+
|
|
277
|
+
udev_dev = udev_device_new_from_syspath(udev_ctx, path);
|
|
278
|
+
|
|
279
|
+
r = udev_device_info(ctx, 0, udev_dev, &busnum, &devaddr, &sys_name);
|
|
280
|
+
if (r) {
|
|
281
|
+
udev_device_unref(udev_dev);
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
linux_enumerate_device(ctx, busnum, devaddr, sys_name);
|
|
286
|
+
udev_device_unref(udev_dev);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
udev_enumerate_unref(enumerator);
|
|
290
|
+
|
|
291
|
+
return LIBUSB_SUCCESS;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
void linux_udev_hotplug_poll(void)
|
|
295
|
+
{
|
|
296
|
+
struct udev_device* udev_dev;
|
|
297
|
+
|
|
298
|
+
usbi_mutex_static_lock(&linux_hotplug_lock);
|
|
299
|
+
do {
|
|
300
|
+
udev_dev = udev_monitor_receive_device(udev_monitor);
|
|
301
|
+
if (udev_dev) {
|
|
302
|
+
usbi_dbg("Handling hotplug event from hotplug_poll");
|
|
303
|
+
udev_hotplug_event(udev_dev);
|
|
304
|
+
}
|
|
305
|
+
} while (udev_dev);
|
|
306
|
+
usbi_mutex_static_unlock(&linux_hotplug_lock);
|
|
307
|
+
}
|