usb 1.7.2 → 1.8.1-libusb.4

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 (188) hide show
  1. package/.gitmodules +1 -1
  2. package/Readme.md +2 -2
  3. package/binding.gyp +2 -2
  4. package/libusb/.private/pre-commit.sh +7 -1
  5. package/libusb/.travis.yml +49 -0
  6. package/libusb/AUTHORS +44 -3
  7. package/libusb/Brewfile +4 -0
  8. package/libusb/ChangeLog +74 -2
  9. package/libusb/README.md +32 -0
  10. package/libusb/TODO +1 -1
  11. package/libusb/Xcode/common.xcconfig +12 -0
  12. package/libusb/Xcode/config.h +25 -0
  13. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +959 -1
  14. package/libusb/android/README +4 -2
  15. package/libusb/android/config.h +75 -0
  16. package/libusb/appveyor.yml +41 -0
  17. package/libusb/appveyor_cygwin.bat +11 -0
  18. package/libusb/appveyor_minGW.bat +19 -0
  19. package/libusb/autogen.sh +1 -1
  20. package/libusb/bootstrap.sh +3 -16
  21. package/libusb/configure.ac +108 -80
  22. package/libusb/doc/doxygen.cfg.in +1785 -739
  23. package/libusb/examples/Makefile.am +1 -1
  24. package/libusb/examples/dpfp.c +3 -1
  25. package/libusb/examples/dpfp_threaded.c +23 -10
  26. package/libusb/examples/ezusb.c +3 -3
  27. package/libusb/examples/ezusb.h +2 -2
  28. package/libusb/examples/fxload.c +31 -9
  29. package/libusb/examples/hotplugtest.c +35 -7
  30. package/libusb/examples/listdevs.c +3 -1
  31. package/libusb/examples/sam3u_benchmark.c +3 -3
  32. package/libusb/examples/testlibusb.c +277 -0
  33. package/libusb/examples/xusb.c +40 -34
  34. package/libusb/libusb/Makefile.am +49 -23
  35. package/libusb/libusb/core.c +855 -457
  36. package/libusb/libusb/descriptor.c +72 -78
  37. package/libusb/libusb/hotplug.c +122 -76
  38. package/libusb/libusb/hotplug.h +42 -25
  39. package/libusb/libusb/io.c +625 -390
  40. package/libusb/libusb/libusb-1.0.def +12 -0
  41. package/libusb/libusb/libusb.h +218 -150
  42. package/libusb/libusb/libusbi.h +346 -176
  43. package/libusb/libusb/os/darwin_usb.c +604 -319
  44. package/libusb/libusb/os/darwin_usb.h +61 -20
  45. package/libusb/libusb/os/haiku_pollfs.cpp +367 -0
  46. package/libusb/libusb/os/haiku_usb.h +113 -0
  47. package/libusb/libusb/os/haiku_usb_backend.cpp +533 -0
  48. package/libusb/libusb/os/haiku_usb_raw.cpp +267 -0
  49. package/libusb/libusb/os/haiku_usb_raw.h +188 -0
  50. package/libusb/libusb/os/linux_netlink.c +186 -146
  51. package/libusb/libusb/os/linux_udev.c +36 -14
  52. package/libusb/libusb/os/linux_usbfs.c +426 -225
  53. package/libusb/libusb/os/linux_usbfs.h +5 -3
  54. package/libusb/libusb/os/netbsd_usb.c +21 -77
  55. package/libusb/libusb/os/openbsd_usb.c +32 -115
  56. package/libusb/libusb/os/poll_posix.c +38 -5
  57. package/libusb/libusb/os/poll_posix.h +3 -0
  58. package/libusb/libusb/os/poll_windows.c +277 -626
  59. package/libusb/libusb/os/poll_windows.h +11 -44
  60. package/libusb/libusb/os/sunos_usb.c +1695 -0
  61. package/libusb/libusb/os/sunos_usb.h +80 -0
  62. package/libusb/libusb/os/threads_posix.c +24 -26
  63. package/libusb/libusb/os/threads_posix.h +73 -21
  64. package/libusb/libusb/os/threads_windows.c +71 -157
  65. package/libusb/libusb/os/threads_windows.h +68 -44
  66. package/libusb/libusb/os/wince_usb.c +276 -420
  67. package/libusb/libusb/os/wince_usb.h +23 -28
  68. package/libusb/libusb/os/windows_common.h +78 -58
  69. package/libusb/libusb/os/windows_nt_common.c +1010 -0
  70. package/libusb/libusb/os/windows_nt_common.h +110 -0
  71. package/libusb/libusb/os/windows_nt_shared_types.h +147 -0
  72. package/libusb/libusb/os/windows_usbdk.c +830 -0
  73. package/libusb/libusb/os/windows_usbdk.h +103 -0
  74. package/libusb/libusb/os/windows_winusb.c +4391 -0
  75. package/libusb/libusb/os/windows_winusb.h +783 -0
  76. package/libusb/libusb/strerror.c +41 -7
  77. package/libusb/libusb/sync.c +41 -13
  78. package/libusb/libusb/version.h +1 -1
  79. package/libusb/libusb/version_nano.h +1 -1
  80. package/libusb/libusb-1.0.pc.in +1 -1
  81. package/libusb/msvc/appveyor.bat +27 -0
  82. package/libusb/msvc/config.h +5 -4
  83. package/libusb/msvc/ddk_build.cmd +87 -43
  84. package/libusb/msvc/fxload_2010.vcxproj +24 -104
  85. package/libusb/msvc/fxload_2012.vcxproj +24 -107
  86. package/libusb/msvc/fxload_2013.vcxproj +24 -107
  87. package/libusb/msvc/fxload_2015.vcxproj +91 -0
  88. package/libusb/msvc/fxload_2017.vcxproj +114 -0
  89. package/libusb/msvc/fxload_sources +1 -1
  90. package/libusb/msvc/getopt_2010.vcxproj +16 -75
  91. package/libusb/msvc/getopt_2012.vcxproj +16 -79
  92. package/libusb/msvc/getopt_2013.vcxproj +16 -79
  93. package/libusb/msvc/getopt_2015.vcxproj +73 -0
  94. package/libusb/msvc/getopt_2017.vcxproj +98 -0
  95. package/libusb/msvc/getopt_sources +6 -2
  96. package/libusb/msvc/hotplugtest_2010.vcxproj +18 -99
  97. package/libusb/msvc/hotplugtest_2012.vcxproj +18 -102
  98. package/libusb/msvc/hotplugtest_2013.vcxproj +18 -102
  99. package/libusb/msvc/hotplugtest_2015.vcxproj +83 -0
  100. package/libusb/msvc/hotplugtest_2017.vcxproj +106 -0
  101. package/libusb/msvc/hotplugtest_sources +1 -1
  102. package/libusb/msvc/libusb_2005.sln +20 -20
  103. package/libusb/msvc/libusb_2010.sln +57 -46
  104. package/libusb/msvc/libusb_2012.sln +57 -46
  105. package/libusb/msvc/libusb_2013.sln +57 -50
  106. package/libusb/msvc/libusb_2015.sln +59 -52
  107. package/libusb/msvc/libusb_2017.sln +186 -0
  108. package/libusb/msvc/libusb_dll.dsp +2 -2
  109. package/libusb/msvc/libusb_dll_2005.vcproj +30 -2
  110. package/libusb/msvc/libusb_dll_2010.vcxproj +26 -90
  111. package/libusb/msvc/libusb_dll_2012.vcxproj +28 -96
  112. package/libusb/msvc/libusb_dll_2013.vcxproj +28 -96
  113. package/libusb/msvc/libusb_dll_2015.vcxproj +107 -0
  114. package/libusb/msvc/libusb_dll_2017.vcxproj +134 -0
  115. package/libusb/msvc/libusb_dll_wince.vcproj +9 -1
  116. package/libusb/msvc/libusb_sources +10 -5
  117. package/libusb/msvc/libusb_static.dsp +2 -2
  118. package/libusb/msvc/libusb_static_2005.vcproj +32 -4
  119. package/libusb/msvc/libusb_static_2010.vcxproj +24 -83
  120. package/libusb/msvc/libusb_static_2012.vcxproj +25 -87
  121. package/libusb/msvc/libusb_static_2013.vcxproj +25 -87
  122. package/libusb/msvc/libusb_static_2015.vcxproj +98 -0
  123. package/libusb/msvc/libusb_static_2017.vcxproj +117 -0
  124. package/libusb/msvc/libusb_static_wince.vcproj +20 -26
  125. package/libusb/msvc/libusb_wince.sln +88 -88
  126. package/libusb/msvc/listdevs_2010.vcxproj +16 -99
  127. package/libusb/msvc/listdevs_2012.vcxproj +16 -102
  128. package/libusb/msvc/listdevs_2013.vcxproj +16 -102
  129. package/libusb/msvc/listdevs_2015.vcxproj +83 -0
  130. package/libusb/msvc/listdevs_2017.vcxproj +106 -0
  131. package/libusb/msvc/listdevs_sources +2 -1
  132. package/libusb/msvc/stress_2010.vcxproj +20 -101
  133. package/libusb/msvc/stress_2012.vcxproj +20 -104
  134. package/libusb/msvc/stress_2013.vcxproj +20 -104
  135. package/libusb/msvc/stress_2015.vcxproj +87 -0
  136. package/libusb/msvc/stress_2017.vcxproj +110 -0
  137. package/libusb/msvc/stress_sources +21 -0
  138. package/libusb/msvc/testlibusb_2010.vcxproj +82 -0
  139. package/libusb/msvc/testlibusb_2012.vcxproj +83 -0
  140. package/libusb/msvc/testlibusb_2013.vcxproj +83 -0
  141. package/libusb/msvc/testlibusb_2015.vcxproj +83 -0
  142. package/libusb/msvc/testlibusb_2017.vcxproj +106 -0
  143. package/libusb/msvc/testlibusb_sources +20 -0
  144. package/libusb/msvc/xusb_2010.vcxproj +17 -98
  145. package/libusb/msvc/xusb_2012.vcxproj +17 -101
  146. package/libusb/msvc/xusb_2013.vcxproj +17 -101
  147. package/libusb/msvc/xusb_2015.vcxproj +83 -0
  148. package/libusb/msvc/xusb_2017.vcxproj +106 -0
  149. package/libusb/msvc/xusb_sources +1 -1
  150. package/libusb/tests/stress.c +2 -2
  151. package/libusb/tests/testlib.c +0 -4
  152. package/libusb/travis-autogen.sh +39 -0
  153. package/libusb.gypi +13 -2
  154. package/package.json +20 -11
  155. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  156. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  157. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  158. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  159. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  160. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  161. package/prebuilds/linux-ia32/node.napi.node +0 -0
  162. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  163. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  164. package/prebuilds/win32-ia32/node.napi.node +0 -0
  165. package/prebuilds/win32-x64/node.napi.node +0 -0
  166. package/src/device.cc +1 -1
  167. package/usb.js +51 -5
  168. package/.github/workflows/prebuild.yml +0 -49
  169. package/libusb/INSTALL +0 -234
  170. package/libusb/README +0 -28
  171. package/libusb/libusb/os/windows_usb.c +0 -5347
  172. package/libusb/libusb/os/windows_usb.h +0 -971
  173. package/libusb/msvc/fxload_2010.vcxproj.filters +0 -25
  174. package/libusb/msvc/fxload_2012.vcxproj.filters +0 -25
  175. package/libusb/msvc/getopt_2010.vcxproj.filters +0 -26
  176. package/libusb/msvc/getopt_2012.vcxproj.filters +0 -26
  177. package/libusb/msvc/hotplugtest_2010.vcxproj.filters +0 -14
  178. package/libusb/msvc/hotplugtest_2012.vcxproj.filters +0 -14
  179. package/libusb/msvc/libusb_dll_2010.vcxproj.filters +0 -81
  180. package/libusb/msvc/libusb_dll_2012.vcxproj.filters +0 -84
  181. package/libusb/msvc/libusb_static_2010.vcxproj.filters +0 -74
  182. package/libusb/msvc/libusb_static_2012.vcxproj.filters +0 -74
  183. package/libusb/msvc/listdevs_2010.vcxproj.filters +0 -14
  184. package/libusb/msvc/listdevs_2012.vcxproj.filters +0 -14
  185. package/libusb/msvc/stress_2010.vcxproj.filters +0 -25
  186. package/libusb/msvc/stress_2012.vcxproj.filters +0 -25
  187. package/libusb/msvc/xusb_2010.vcxproj.filters +0 -14
  188. package/libusb/msvc/xusb_2012.vcxproj.filters +0 -14
@@ -81,10 +81,11 @@ struct usbfs_iso_packet_desc {
81
81
  unsigned int status;
82
82
  };
83
83
 
84
- #define MAX_ISO_BUFFER_LENGTH 32768
85
84
  #define MAX_BULK_BUFFER_LENGTH 16384
86
85
  #define MAX_CTRL_BUFFER_LENGTH 4096
87
86
 
87
+ #define MAX_ISO_PACKETS_PER_URB 128
88
+
88
89
  struct usbfs_urb {
89
90
  unsigned char type;
90
91
  unsigned char endpoint;
@@ -125,6 +126,7 @@ struct usbfs_hub_portinfo {
125
126
  #define USBFS_CAP_BULK_CONTINUATION 0x02
126
127
  #define USBFS_CAP_NO_PACKET_SIZE_LIM 0x04
127
128
  #define USBFS_CAP_BULK_SCATTER_GATHER 0x08
129
+ #define USBFS_CAP_REAP_AFTER_DISCONNECT 0x10
128
130
 
129
131
  #define USBFS_DISCONNECT_CLAIM_IF_DRIVER 0x01
130
132
  #define USBFS_DISCONNECT_CLAIM_EXCEPT_DRIVER 0x02
@@ -181,11 +183,11 @@ void linux_netlink_hotplug_poll(void);
181
183
  #endif
182
184
 
183
185
  void linux_hotplug_enumerate(uint8_t busnum, uint8_t devaddr, const char *sys_name);
184
- void linux_device_disconnected(uint8_t busnum, uint8_t devaddr, const char *sys_name);
186
+ void linux_device_disconnected(uint8_t busnum, uint8_t devaddr);
185
187
 
186
188
  int linux_get_device_address (struct libusb_context *ctx, int detached,
187
189
  uint8_t *busnum, uint8_t *devaddr, const char *dev_node,
188
- const char *sys_name);
190
+ const char *sys_name, int fd);
189
191
  int linux_enumerate_device(struct libusb_context *ctx,
190
192
  uint8_t busnum, uint8_t devaddr, const char *sysfs_dir);
191
193
 
@@ -16,6 +16,8 @@
16
16
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
  */
18
18
 
19
+ #include <config.h>
20
+
19
21
  #include <sys/time.h>
20
22
  #include <sys/types.h>
21
23
 
@@ -28,7 +30,6 @@
28
30
 
29
31
  #include <dev/usb/usb.h>
30
32
 
31
- #include "libusb.h"
32
33
  #include "libusbi.h"
33
34
 
34
35
  struct device_priv {
@@ -40,7 +41,6 @@ struct device_priv {
40
41
  };
41
42
 
42
43
  struct handle_priv {
43
- int pipe[2]; /* for event notification */
44
44
  int endpoints[USB_MAX_ENDPOINTS];
45
45
  };
46
46
 
@@ -74,8 +74,7 @@ static void netbsd_destroy_device(struct libusb_device *);
74
74
  static int netbsd_submit_transfer(struct usbi_transfer *);
75
75
  static int netbsd_cancel_transfer(struct usbi_transfer *);
76
76
  static void netbsd_clear_transfer_priv(struct usbi_transfer *);
77
- static int netbsd_handle_events(struct libusb_context *ctx, struct pollfd *,
78
- nfds_t, int);
77
+ static int netbsd_handle_transfer_completion(struct usbi_transfer *);
79
78
  static int netbsd_clock_gettime(int, struct timespec *);
80
79
 
81
80
  /*
@@ -87,11 +86,12 @@ static int _sync_control_transfer(struct usbi_transfer *);
87
86
  static int _sync_gen_transfer(struct usbi_transfer *);
88
87
  static int _access_endpoint(struct libusb_transfer *);
89
88
 
90
- const struct usbi_os_backend netbsd_backend = {
89
+ const struct usbi_os_backend usbi_backend = {
91
90
  "Synchronous NetBSD backend",
92
- USBI_CAP_HAS_POLLABLE_DEVICE_FD,
91
+ 0,
93
92
  NULL, /* init() */
94
93
  NULL, /* exit() */
94
+ NULL, /* set_option() */
95
95
  netbsd_get_device_list,
96
96
  NULL, /* hotplug_poll */
97
97
  netbsd_open,
@@ -115,6 +115,9 @@ const struct usbi_os_backend netbsd_backend = {
115
115
  NULL, /* alloc_streams */
116
116
  NULL, /* free_streams */
117
117
 
118
+ NULL, /* dev_mem_alloc() */
119
+ NULL, /* dev_mem_free() */
120
+
118
121
  NULL, /* kernel_driver_active() */
119
122
  NULL, /* detach_kernel_driver() */
120
123
  NULL, /* attach_kernel_driver() */
@@ -125,13 +128,14 @@ const struct usbi_os_backend netbsd_backend = {
125
128
  netbsd_cancel_transfer,
126
129
  netbsd_clear_transfer_priv,
127
130
 
128
- netbsd_handle_events,
131
+ NULL, /* handle_events() */
132
+ netbsd_handle_transfer_completion,
129
133
 
130
134
  netbsd_clock_gettime,
135
+ 0, /* context_priv_size */
131
136
  sizeof(struct device_priv),
132
137
  sizeof(struct handle_priv),
133
138
  0, /* transfer_priv_size */
134
- 0, /* add_iso_packet_size */
135
139
  };
136
140
 
137
141
  int
@@ -210,8 +214,9 @@ error:
210
214
  int
211
215
  netbsd_open(struct libusb_device_handle *handle)
212
216
  {
213
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
214
217
  struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
218
+ struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
219
+ int i;
215
220
 
216
221
  dpriv->fd = open(dpriv->devnode, O_RDWR);
217
222
  if (dpriv->fd < 0) {
@@ -220,29 +225,23 @@ netbsd_open(struct libusb_device_handle *handle)
220
225
  return _errno_to_libusb(errno);
221
226
  }
222
227
 
223
- usbi_dbg("open %s: fd %d", dpriv->devnode, dpriv->fd);
228
+ for (i = 0; i < USB_MAX_ENDPOINTS; i++)
229
+ hpriv->endpoints[i] = -1;
224
230
 
225
- if (pipe(hpriv->pipe) < 0)
226
- return _errno_to_libusb(errno);
231
+ usbi_dbg("open %s: fd %d", dpriv->devnode, dpriv->fd);
227
232
 
228
- return usbi_add_pollfd(HANDLE_CTX(handle), hpriv->pipe[0], POLLIN);
233
+ return (LIBUSB_SUCCESS);
229
234
  }
230
235
 
231
236
  void
232
237
  netbsd_close(struct libusb_device_handle *handle)
233
238
  {
234
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
235
239
  struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
236
240
 
237
241
  usbi_dbg("close: fd %d", dpriv->fd);
238
242
 
239
243
  close(dpriv->fd);
240
244
  dpriv->fd = -1;
241
-
242
- usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->pipe[0]);
243
-
244
- close(hpriv->pipe[0]);
245
- close(hpriv->pipe[1]);
246
245
  }
247
246
 
248
247
  int
@@ -469,8 +468,7 @@ netbsd_submit_transfer(struct usbi_transfer *itransfer)
469
468
  if (err)
470
469
  return (err);
471
470
 
472
- if (write(hpriv->pipe[1], &itransfer, sizeof(itransfer)) < 0)
473
- return _errno_to_libusb(errno);
471
+ usbi_signal_transfer_completion(itransfer);
474
472
 
475
473
  return (LIBUSB_SUCCESS);
476
474
  }
@@ -492,63 +490,9 @@ netbsd_clear_transfer_priv(struct usbi_transfer *itransfer)
492
490
  }
493
491
 
494
492
  int
495
- netbsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds,
496
- int num_ready)
493
+ netbsd_handle_transfer_completion(struct usbi_transfer *itransfer)
497
494
  {
498
- struct libusb_device_handle *handle;
499
- struct handle_priv *hpriv = NULL;
500
- struct usbi_transfer *itransfer;
501
- struct pollfd *pollfd;
502
- int i, err = 0;
503
-
504
- usbi_dbg("");
505
-
506
- pthread_mutex_lock(&ctx->open_devs_lock);
507
- for (i = 0; i < nfds && num_ready > 0; i++) {
508
- pollfd = &fds[i];
509
-
510
- if (!pollfd->revents)
511
- continue;
512
-
513
- hpriv = NULL;
514
- num_ready--;
515
- list_for_each_entry(handle, &ctx->open_devs, list,
516
- struct libusb_device_handle) {
517
- hpriv = (struct handle_priv *)handle->os_priv;
518
-
519
- if (hpriv->pipe[0] == pollfd->fd)
520
- break;
521
-
522
- hpriv = NULL;
523
- }
524
-
525
- if (NULL == hpriv) {
526
- usbi_dbg("fd %d is not an event pipe!", pollfd->fd);
527
- err = ENOENT;
528
- break;
529
- }
530
-
531
- if (pollfd->revents & POLLERR) {
532
- usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->pipe[0]);
533
- usbi_handle_disconnect(handle);
534
- continue;
535
- }
536
-
537
- if (read(hpriv->pipe[0], &itransfer, sizeof(itransfer)) < 0) {
538
- err = errno;
539
- break;
540
- }
541
-
542
- if ((err = usbi_handle_transfer_completion(itransfer,
543
- LIBUSB_TRANSFER_COMPLETED)))
544
- break;
545
- }
546
- pthread_mutex_unlock(&ctx->open_devs_lock);
547
-
548
- if (err)
549
- return _errno_to_libusb(err);
550
-
551
- return (LIBUSB_SUCCESS);
495
+ return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
552
496
  }
553
497
 
554
498
  int
@@ -16,6 +16,8 @@
16
16
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
  */
18
18
 
19
+ #include <config.h>
20
+
19
21
  #include <sys/time.h>
20
22
  #include <sys/types.h>
21
23
 
@@ -28,7 +30,6 @@
28
30
 
29
31
  #include <dev/usb/usb.h>
30
32
 
31
- #include "libusb.h"
32
33
  #include "libusbi.h"
33
34
 
34
35
  struct device_priv {
@@ -40,7 +41,6 @@ struct device_priv {
40
41
  };
41
42
 
42
43
  struct handle_priv {
43
- int pipe[2]; /* for event notification */
44
44
  int endpoints[USB_MAX_ENDPOINTS];
45
45
  };
46
46
 
@@ -74,8 +74,7 @@ static void obsd_destroy_device(struct libusb_device *);
74
74
  static int obsd_submit_transfer(struct usbi_transfer *);
75
75
  static int obsd_cancel_transfer(struct usbi_transfer *);
76
76
  static void obsd_clear_transfer_priv(struct usbi_transfer *);
77
- static int obsd_handle_events(struct libusb_context *ctx, struct pollfd *,
78
- nfds_t, int);
77
+ static int obsd_handle_transfer_completion(struct usbi_transfer *);
79
78
  static int obsd_clock_gettime(int, struct timespec *);
80
79
 
81
80
  /*
@@ -90,51 +89,36 @@ static int _access_endpoint(struct libusb_transfer *);
90
89
  static int _bus_open(int);
91
90
 
92
91
 
93
- const struct usbi_os_backend openbsd_backend = {
94
- "Synchronous OpenBSD backend",
95
- USBI_CAP_HAS_POLLABLE_DEVICE_FD,
96
- NULL, /* init() */
97
- NULL, /* exit() */
98
- obsd_get_device_list,
99
- NULL, /* hotplug_poll */
100
- obsd_open,
101
- obsd_close,
102
-
103
- obsd_get_device_descriptor,
104
- obsd_get_active_config_descriptor,
105
- obsd_get_config_descriptor,
106
- NULL, /* get_config_descriptor_by_value() */
107
-
108
- obsd_get_configuration,
109
- obsd_set_configuration,
92
+ const struct usbi_os_backend usbi_backend = {
93
+ .name = "Synchronous OpenBSD backend",
94
+ .get_device_list = obsd_get_device_list,
95
+ .open = obsd_open,
96
+ .close = obsd_close,
110
97
 
111
- obsd_claim_interface,
112
- obsd_release_interface,
98
+ .get_device_descriptor = obsd_get_device_descriptor,
99
+ .get_active_config_descriptor = obsd_get_active_config_descriptor,
100
+ .get_config_descriptor = obsd_get_config_descriptor,
113
101
 
114
- obsd_set_interface_altsetting,
115
- obsd_clear_halt,
116
- obsd_reset_device,
102
+ .get_configuration = obsd_get_configuration,
103
+ .set_configuration = obsd_set_configuration,
117
104
 
118
- NULL, /* alloc_streams */
119
- NULL, /* free_streams */
105
+ .claim_interface = obsd_claim_interface,
106
+ .release_interface = obsd_release_interface,
120
107
 
121
- NULL, /* kernel_driver_active() */
122
- NULL, /* detach_kernel_driver() */
123
- NULL, /* attach_kernel_driver() */
108
+ .set_interface_altsetting = obsd_set_interface_altsetting,
109
+ .clear_halt = obsd_clear_halt,
110
+ .reset_device = obsd_reset_device,
111
+ .destroy_device = obsd_destroy_device,
124
112
 
125
- obsd_destroy_device,
113
+ .submit_transfer = obsd_submit_transfer,
114
+ .cancel_transfer = obsd_cancel_transfer,
115
+ .clear_transfer_priv = obsd_clear_transfer_priv,
126
116
 
127
- obsd_submit_transfer,
128
- obsd_cancel_transfer,
129
- obsd_clear_transfer_priv,
117
+ .handle_transfer_completion = obsd_handle_transfer_completion,
130
118
 
131
- obsd_handle_events,
132
-
133
- obsd_clock_gettime,
134
- sizeof(struct device_priv),
135
- sizeof(struct handle_priv),
136
- 0, /* transfer_priv_size */
137
- 0, /* add_iso_packet_size */
119
+ .clock_gettime = obsd_clock_gettime,
120
+ .device_priv_size = sizeof(struct device_priv),
121
+ .device_handle_priv_size = sizeof(struct handle_priv),
138
122
  };
139
123
 
140
124
  #define DEVPATH "/dev/"
@@ -244,7 +228,6 @@ obsd_get_device_list(struct libusb_context * ctx,
244
228
  int
245
229
  obsd_open(struct libusb_device_handle *handle)
246
230
  {
247
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
248
231
  struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
249
232
  char devnode[16];
250
233
 
@@ -262,16 +245,12 @@ obsd_open(struct libusb_device_handle *handle)
262
245
  usbi_dbg("open %s: fd %d", devnode, dpriv->fd);
263
246
  }
264
247
 
265
- if (pipe(hpriv->pipe) < 0)
266
- return _errno_to_libusb(errno);
267
-
268
- return usbi_add_pollfd(HANDLE_CTX(handle), hpriv->pipe[0], POLLIN);
248
+ return (LIBUSB_SUCCESS);
269
249
  }
270
250
 
271
251
  void
272
252
  obsd_close(struct libusb_device_handle *handle)
273
253
  {
274
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
275
254
  struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
276
255
 
277
256
  if (dpriv->devname) {
@@ -280,11 +259,6 @@ obsd_close(struct libusb_device_handle *handle)
280
259
  close(dpriv->fd);
281
260
  dpriv->fd = -1;
282
261
  }
283
-
284
- usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->pipe[0]);
285
-
286
- close(hpriv->pipe[0]);
287
- close(hpriv->pipe[1]);
288
262
  }
289
263
 
290
264
  int
@@ -311,7 +285,7 @@ obsd_get_active_config_descriptor(struct libusb_device *dev,
311
285
 
312
286
  len = MIN(len, UGETW(ucd->wTotalLength));
313
287
 
314
- usbi_dbg("len %d", len);
288
+ usbi_dbg("len %zu", len);
315
289
 
316
290
  memcpy(buf, dpriv->cdesc, len);
317
291
 
@@ -336,7 +310,7 @@ obsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
336
310
  udf.udf_size = len;
337
311
  udf.udf_data = buf;
338
312
 
339
- usbi_dbg("index %d, len %d", udf.udf_config_index, len);
313
+ usbi_dbg("index %d, len %zu", udf.udf_config_index, len);
340
314
 
341
315
  if (ioctl(fd, USB_DEVICE_GET_FDESC, &udf) < 0) {
342
316
  err = errno;
@@ -515,8 +489,7 @@ obsd_submit_transfer(struct usbi_transfer *itransfer)
515
489
  if (err)
516
490
  return (err);
517
491
 
518
- if (write(hpriv->pipe[1], &itransfer, sizeof(itransfer)) < 0)
519
- return _errno_to_libusb(errno);
492
+ usbi_signal_transfer_completion(itransfer);
520
493
 
521
494
  return (LIBUSB_SUCCESS);
522
495
  }
@@ -538,70 +511,14 @@ obsd_clear_transfer_priv(struct usbi_transfer *itransfer)
538
511
  }
539
512
 
540
513
  int
541
- obsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds,
542
- int num_ready)
514
+ obsd_handle_transfer_completion(struct usbi_transfer *itransfer)
543
515
  {
544
- struct libusb_device_handle *handle;
545
- struct handle_priv *hpriv = NULL;
546
- struct usbi_transfer *itransfer;
547
- struct pollfd *pollfd;
548
- int i, err = 0;
549
-
550
- usbi_dbg("");
551
-
552
- pthread_mutex_lock(&ctx->open_devs_lock);
553
- for (i = 0; i < nfds && num_ready > 0; i++) {
554
- pollfd = &fds[i];
555
-
556
- if (!pollfd->revents)
557
- continue;
558
-
559
- hpriv = NULL;
560
- num_ready--;
561
- list_for_each_entry(handle, &ctx->open_devs, list,
562
- struct libusb_device_handle) {
563
- hpriv = (struct handle_priv *)handle->os_priv;
564
-
565
- if (hpriv->pipe[0] == pollfd->fd)
566
- break;
567
-
568
- hpriv = NULL;
569
- }
570
-
571
- if (NULL == hpriv) {
572
- usbi_dbg("fd %d is not an event pipe!", pollfd->fd);
573
- err = ENOENT;
574
- break;
575
- }
576
-
577
- if (pollfd->revents & POLLERR) {
578
- usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->pipe[0]);
579
- usbi_handle_disconnect(handle);
580
- continue;
581
- }
582
-
583
- if (read(hpriv->pipe[0], &itransfer, sizeof(itransfer)) < 0) {
584
- err = errno;
585
- break;
586
- }
587
-
588
- if ((err = usbi_handle_transfer_completion(itransfer,
589
- LIBUSB_TRANSFER_COMPLETED)))
590
- break;
591
- }
592
- pthread_mutex_unlock(&ctx->open_devs_lock);
593
-
594
- if (err)
595
- return _errno_to_libusb(err);
596
-
597
- return (LIBUSB_SUCCESS);
516
+ return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
598
517
  }
599
518
 
600
519
  int
601
520
  obsd_clock_gettime(int clkid, struct timespec *tp)
602
521
  {
603
- usbi_dbg("clock %d", clkid);
604
-
605
522
  if (clkid == USBI_CLOCK_REALTIME)
606
523
  return clock_gettime(CLOCK_REALTIME, tp);
607
524
 
@@ -18,6 +18,8 @@
18
18
  *
19
19
  */
20
20
 
21
+ #include <config.h>
22
+
21
23
  #include <unistd.h>
22
24
  #include <fcntl.h>
23
25
  #include <errno.h>
@@ -27,25 +29,56 @@
27
29
 
28
30
  int usbi_pipe(int pipefd[2])
29
31
  {
32
+ #if defined(HAVE_PIPE2)
33
+ int ret = pipe2(pipefd, O_CLOEXEC);
34
+ #else
30
35
  int ret = pipe(pipefd);
36
+ #endif
37
+
31
38
  if (ret != 0) {
39
+ usbi_err(NULL, "failed to create pipe (%d)", errno);
32
40
  return ret;
33
41
  }
42
+
43
+ #if !defined(HAVE_PIPE2) && defined(FD_CLOEXEC)
44
+ ret = fcntl(pipefd[0], F_GETFD);
45
+ if (ret == -1) {
46
+ usbi_err(NULL, "failed to get pipe fd flags (%d)", errno);
47
+ goto err_close_pipe;
48
+ }
49
+ ret = fcntl(pipefd[0], F_SETFD, ret | FD_CLOEXEC);
50
+ if (ret == -1) {
51
+ usbi_err(NULL, "failed to set pipe fd flags (%d)", errno);
52
+ goto err_close_pipe;
53
+ }
54
+
55
+ ret = fcntl(pipefd[1], F_GETFD);
56
+ if (ret == -1) {
57
+ usbi_err(NULL, "failed to get pipe fd flags (%d)", errno);
58
+ goto err_close_pipe;
59
+ }
60
+ ret = fcntl(pipefd[1], F_SETFD, ret | FD_CLOEXEC);
61
+ if (ret == -1) {
62
+ usbi_err(NULL, "failed to set pipe fd flags (%d)", errno);
63
+ goto err_close_pipe;
64
+ }
65
+ #endif
66
+
34
67
  ret = fcntl(pipefd[1], F_GETFL);
35
68
  if (ret == -1) {
36
- usbi_dbg("Failed to get pipe fd flags: %d", errno);
69
+ usbi_err(NULL, "failed to get pipe fd status flags (%d)", errno);
37
70
  goto err_close_pipe;
38
71
  }
39
72
  ret = fcntl(pipefd[1], F_SETFL, ret | O_NONBLOCK);
40
- if (ret != 0) {
41
- usbi_dbg("Failed to set non-blocking on new pipe: %d", errno);
73
+ if (ret == -1) {
74
+ usbi_err(NULL, "failed to set pipe fd status flags (%d)", errno);
42
75
  goto err_close_pipe;
43
76
  }
44
77
 
45
78
  return 0;
46
79
 
47
80
  err_close_pipe:
48
- usbi_close(pipefd[0]);
49
- usbi_close(pipefd[1]);
81
+ close(pipefd[0]);
82
+ close(pipefd[1]);
50
83
  return ret;
51
84
  }
@@ -8,4 +8,7 @@
8
8
 
9
9
  int usbi_pipe(int pipefd[2]);
10
10
 
11
+ #define usbi_inc_fds_ref(x, y)
12
+ #define usbi_dec_fds_ref(x, y)
13
+
11
14
  #endif /* LIBUSB_POLL_POSIX_H */