libusb 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.travis.yml +1 -0
  5. data/History.md +8 -0
  6. data/README.md +5 -15
  7. data/Rakefile +8 -1
  8. data/ext/extconf.rb +49 -12
  9. data/ext/{libusb-1.0.19 → libusb-1.0.20}/AUTHORS +12 -1
  10. data/ext/{libusb-1.0.19 → libusb-1.0.20}/COPYING +0 -0
  11. data/ext/{libusb-1.0.19 → libusb-1.0.20}/ChangeLog +18 -2
  12. data/ext/{libusb-1.0.19 → libusb-1.0.20}/INSTALL +0 -0
  13. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Makefile.am +0 -0
  14. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Makefile.in +31 -18
  15. data/ext/{libusb-1.0.19 → libusb-1.0.20}/NEWS +0 -0
  16. data/ext/{libusb-1.0.19 → libusb-1.0.20}/PORTING +0 -0
  17. data/ext/{libusb-1.0.19 → libusb-1.0.20}/README +5 -3
  18. data/ext/{libusb-1.0.19 → libusb-1.0.20}/TODO +0 -0
  19. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/common.xcconfig +0 -0
  20. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/config.h +0 -0
  21. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/debug.xcconfig +0 -0
  22. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb.xcconfig +0 -0
  23. data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +865 -0
  24. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb_debug.xcconfig +0 -0
  25. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/libusb_release.xcconfig +0 -0
  26. data/ext/{libusb-1.0.19 → libusb-1.0.20}/Xcode/release.xcconfig +0 -0
  27. data/ext/{libusb-1.0.19 → libusb-1.0.20}/aclocal.m4 +35 -32
  28. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/README +0 -0
  29. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/config.h +0 -0
  30. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/Android.mk +0 -0
  31. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/Application.mk +0 -0
  32. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/examples.mk +0 -0
  33. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/libusb.mk +0 -0
  34. data/ext/{libusb-1.0.19 → libusb-1.0.20}/android/jni/tests.mk +0 -0
  35. data/ext/{libusb-1.0.19 → libusb-1.0.20}/compile +1 -1
  36. data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.guess +13 -160
  37. data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.h.in +6 -0
  38. data/ext/{libusb-1.0.19 → libusb-1.0.20}/config.sub +26 -12
  39. data/ext/{libusb-1.0.19 → libusb-1.0.20}/configure +244 -20
  40. data/ext/{libusb-1.0.19 → libusb-1.0.20}/configure.ac +27 -4
  41. data/ext/{libusb-1.0.19 → libusb-1.0.20}/depcomp +1 -1
  42. data/ext/{libusb-1.0.19 → libusb-1.0.20}/doc/Makefile.am +0 -0
  43. data/ext/{libusb-1.0.19 → libusb-1.0.20}/doc/Makefile.in +19 -6
  44. data/ext/libusb-1.0.20/doc/doxygen.cfg.in +2334 -0
  45. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/Makefile.am +0 -0
  46. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/Makefile.in +19 -6
  47. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/dpfp.c +0 -0
  48. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/dpfp_threaded.c +15 -10
  49. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/ezusb.c +0 -0
  50. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/ezusb.h +0 -0
  51. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/fxload.c +28 -7
  52. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt.c +0 -0
  53. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt.h +0 -0
  54. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/getopt/getopt1.c +0 -0
  55. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/hotplugtest.c +21 -3
  56. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/listdevs.c +0 -0
  57. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/sam3u_benchmark.c +0 -0
  58. data/ext/{libusb-1.0.19 → libusb-1.0.20}/examples/xusb.c +2 -1
  59. data/ext/{libusb-1.0.19 → libusb-1.0.20}/install-sh +170 -196
  60. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb-1.0.pc.in +0 -0
  61. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/Makefile.am +15 -0
  62. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/Makefile.in +192 -53
  63. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/core.c +218 -100
  64. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/descriptor.c +3 -1
  65. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/hotplug.c +26 -9
  66. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/hotplug.h +8 -0
  67. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/io.c +432 -290
  68. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb-1.0.def +2 -0
  69. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb-1.0.rc +0 -0
  70. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusb.h +11 -10
  71. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/libusbi.h +106 -29
  72. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/darwin_usb.c +27 -67
  73. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/darwin_usb.h +3 -7
  74. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +5 -0
  75. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +810 -0
  76. data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +1193 -0
  77. data/ext/libusb-1.0.20/libusb/os/haiku/compile +347 -0
  78. data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +1421 -0
  79. data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +1807 -0
  80. data/ext/libusb-1.0.20/libusb/os/haiku/configure +17579 -0
  81. data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +8 -0
  82. data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +791 -0
  83. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +378 -0
  84. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +112 -0
  85. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +550 -0
  86. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +255 -0
  87. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +180 -0
  88. data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +501 -0
  89. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/ltmain.sh +0 -0
  90. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/libtool.m4 +0 -0
  91. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltoptions.m4 +0 -0
  92. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltsugar.m4 +0 -0
  93. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/ltversion.m4 +0 -0
  94. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/m4/lt~obsolete.m4 +0 -0
  95. data/ext/{libusb-1.0.19 → libusb-1.0.20/libusb/os/haiku}/missing +1 -1
  96. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_netlink.c +4 -4
  97. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_udev.c +1 -2
  98. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_usbfs.c +46 -49
  99. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/linux_usbfs.h +1 -1
  100. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/netbsd_usb.c +9 -73
  101. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/openbsd_usb.c +9 -73
  102. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_posix.c +2 -0
  103. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_posix.h +0 -0
  104. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_windows.c +3 -1
  105. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/poll_windows.h +0 -0
  106. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_posix.c +3 -3
  107. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_posix.h +0 -0
  108. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_windows.c +3 -1
  109. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/threads_windows.h +0 -0
  110. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/wince_usb.c +87 -250
  111. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/wince_usb.h +0 -0
  112. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_common.h +1 -1
  113. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_usb.c +267 -181
  114. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/os/windows_usb.h +22 -7
  115. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/strerror.c +5 -2
  116. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/sync.c +2 -1
  117. data/ext/{libusb-1.0.19 → libusb-1.0.20}/libusb/version.h +1 -1
  118. data/ext/libusb-1.0.20/libusb/version_nano.h +1 -0
  119. data/ext/libusb-1.0.20/ltmain.sh +9655 -0
  120. data/ext/libusb-1.0.20/m4/libtool.m4 +7992 -0
  121. data/ext/libusb-1.0.20/m4/ltoptions.m4 +384 -0
  122. data/ext/libusb-1.0.20/m4/ltsugar.m4 +123 -0
  123. data/ext/libusb-1.0.20/m4/ltversion.m4 +23 -0
  124. data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +98 -0
  125. data/ext/libusb-1.0.20/missing +215 -0
  126. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/Makefile.am +0 -0
  127. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/Makefile.in +19 -6
  128. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/libusb_testlib.h +0 -0
  129. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/stress.c +0 -0
  130. data/ext/{libusb-1.0.19 → libusb-1.0.20}/tests/testlib.c +0 -0
  131. data/lib/libusb.rb +1 -0
  132. data/lib/libusb/call.rb +1 -0
  133. data/lib/libusb/context.rb +5 -2
  134. data/lib/libusb/stdio.rb +25 -0
  135. data/lib/libusb/version_gem.rb +1 -1
  136. data/libusb.gemspec +2 -1
  137. metadata +152 -115
  138. metadata.gz.sig +0 -0
  139. data/ext/libusb-1.0.19/Xcode/libusb.xcodeproj/project.pbxproj +0 -1
  140. data/ext/libusb-1.0.19/doc/doxygen.cfg.in +0 -1288
  141. data/ext/libusb-1.0.19/libusb/version_nano.h +0 -1
@@ -3,7 +3,7 @@
3
3
 
4
4
  scriptversion=2013-10-28.13; # UTC
5
5
 
6
- # Copyright (C) 1996-2013 Free Software Foundation, Inc.
6
+ # Copyright (C) 1996-2014 Free Software Foundation, Inc.
7
7
  # Originally written by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996.
8
8
 
9
9
  # This program is free software; you can redistribute it and/or modify
@@ -20,10 +20,7 @@
20
20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
  */
22
22
 
23
- #include "config.h"
24
- #include "libusb.h"
25
- #include "libusbi.h"
26
- #include "linux_usbfs.h"
23
+ #include <config.h>
27
24
 
28
25
  #include <ctype.h>
29
26
  #include <dirent.h>
@@ -53,6 +50,9 @@
53
50
  #include <linux/filter.h>
54
51
  #endif
55
52
 
53
+ #include "libusbi.h"
54
+ #include "linux_usbfs.h"
55
+
56
56
  #define KERNEL 1
57
57
 
58
58
  static int linux_netlink_socket = -1;
@@ -20,7 +20,7 @@
20
20
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
21
  */
22
22
 
23
- #include "config.h"
23
+ #include <config.h>
24
24
 
25
25
  #include <assert.h>
26
26
  #include <ctype.h>
@@ -39,7 +39,6 @@
39
39
  #include <unistd.h>
40
40
  #include <libudev.h>
41
41
 
42
- #include "libusb.h"
43
42
  #include "libusbi.h"
44
43
  #include "linux_usbfs.h"
45
44
 
@@ -38,7 +38,6 @@
38
38
  #include <sys/utsname.h>
39
39
  #include <unistd.h>
40
40
 
41
- #include "libusb.h"
42
41
  #include "libusbi.h"
43
42
  #include "linux_usbfs.h"
44
43
 
@@ -199,7 +198,7 @@ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
199
198
 
200
199
  if (errno == ENOENT) {
201
200
  if (!silent)
202
- usbi_err(ctx, "File doesn't exist, wait %d ms and try again\n", delay/1000);
201
+ usbi_err(ctx, "File doesn't exist, wait %d ms and try again", delay/1000);
203
202
 
204
203
  /* Wait 10ms for USB device path creation.*/
205
204
  usleep(delay);
@@ -308,6 +307,14 @@ static const char *find_usbfs_path(void)
308
307
  }
309
308
  }
310
309
 
310
+ /* On udev based systems without any usb-devices /dev/bus/usb will not
311
+ * exist. So if we've not found anything and we're using udev for hotplug
312
+ * simply assume /dev/bus/usb rather then making libusb_init fail. */
313
+ #if defined(USE_UDEV)
314
+ if (ret == NULL)
315
+ ret = "/dev/bus/usb";
316
+ #endif
317
+
311
318
  if (ret != NULL)
312
319
  usbi_dbg("found usbfs at %s", ret);
313
320
 
@@ -632,9 +639,9 @@ int linux_get_device_address (struct libusb_context *ctx, int detached,
632
639
 
633
640
  /* will this work with all supported kernel versions? */
634
641
  if (!strncmp(dev_node, "/dev/bus/usb", 12)) {
635
- sscanf (dev_node, "/dev/bus/usb/%hhd/%hhd", busnum, devaddr);
642
+ sscanf (dev_node, "/dev/bus/usb/%hhu/%hhu", busnum, devaddr);
636
643
  } else if (!strncmp(dev_node, "/proc/bus/usb", 13)) {
637
- sscanf (dev_node, "/proc/bus/usb/%hhd/%hhd", busnum, devaddr);
644
+ sscanf (dev_node, "/proc/bus/usb/%hhu/%hhu", busnum, devaddr);
638
645
  }
639
646
 
640
647
  return LIBUSB_SUCCESS;
@@ -998,6 +1005,9 @@ static int linux_get_parent_info(struct libusb_device *dev, const char *sysfs_di
998
1005
  }
999
1006
 
1000
1007
  parent_sysfs_dir = strdup(sysfs_dir);
1008
+ if (NULL == parent_sysfs_dir) {
1009
+ return LIBUSB_ERROR_NO_MEM;
1010
+ }
1001
1011
  if (NULL != (tmp = strrchr(parent_sysfs_dir, '.')) ||
1002
1012
  NULL != (tmp = strrchr(parent_sysfs_dir, '-'))) {
1003
1013
  dev->port_number = atoi(tmp + 1);
@@ -1765,10 +1775,6 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer)
1765
1775
  int bulk_buffer_len, use_bulk_continuation;
1766
1776
  int r;
1767
1777
  int i;
1768
- size_t alloc_size;
1769
-
1770
- if (tpriv->urbs)
1771
- return LIBUSB_ERROR_BUSY;
1772
1778
 
1773
1779
  if (is_out && (transfer->flags & LIBUSB_TRANSFER_ADD_ZERO_PACKET) &&
1774
1780
  !(dpriv->caps & USBFS_CAP_ZERO_PACKET))
@@ -1827,8 +1833,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer)
1827
1833
  }
1828
1834
  usbi_dbg("need %d urbs for new transfer with length %d", num_urbs,
1829
1835
  transfer->length);
1830
- alloc_size = num_urbs * sizeof(struct usbfs_urb);
1831
- urbs = calloc(1, alloc_size);
1836
+ urbs = calloc(num_urbs, sizeof(struct usbfs_urb));
1832
1837
  if (!urbs)
1833
1838
  return LIBUSB_ERROR_NO_MEM;
1834
1839
  tpriv->urbs = urbs;
@@ -1946,18 +1951,11 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
1946
1951
  unsigned int packet_len;
1947
1952
  unsigned char *urb_buffer = transfer->buffer;
1948
1953
 
1949
- if (tpriv->iso_urbs)
1950
- return LIBUSB_ERROR_BUSY;
1951
-
1952
- /* usbfs places a 32kb limit on iso URBs. we divide up larger requests
1953
- * into smaller units to meet such restriction, then fire off all the
1954
- * units at once. it would be simpler if we just fired one unit at a time,
1955
- * but there is a big performance gain through doing it this way.
1956
- *
1957
- * Newer kernels lift the 32k limit (USBFS_CAP_NO_PACKET_SIZE_LIM),
1958
- * using arbritary large transfers is still be a bad idea though, as
1959
- * the kernel needs to allocate physical contiguous memory for this,
1960
- * which may fail for large buffers.
1954
+ /* usbfs places arbitrary limits on iso URBs. this limit has changed
1955
+ * at least three times, and it's difficult to accurately detect which
1956
+ * limit this running kernel might impose. so we attempt to submit
1957
+ * whatever the user has provided. if the kernel rejects the request
1958
+ * due to its size, we return an error indicating such to the user.
1961
1959
  */
1962
1960
 
1963
1961
  /* calculate how many URBs we need */
@@ -1968,14 +1966,16 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
1968
1966
  if (packet_len > space_remaining) {
1969
1967
  num_urbs++;
1970
1968
  this_urb_len = packet_len;
1969
+ /* check that we can actually support this packet length */
1970
+ if (this_urb_len > MAX_ISO_BUFFER_LENGTH)
1971
+ return LIBUSB_ERROR_INVALID_PARAM;
1971
1972
  } else {
1972
1973
  this_urb_len += packet_len;
1973
1974
  }
1974
1975
  }
1975
- usbi_dbg("need %d 32k URBs for transfer", num_urbs);
1976
+ usbi_dbg("need %d %dk URBs for transfer", num_urbs, MAX_ISO_BUFFER_LENGTH / 1024);
1976
1977
 
1977
- alloc_size = num_urbs * sizeof(*urbs);
1978
- urbs = calloc(1, alloc_size);
1978
+ urbs = calloc(num_urbs, sizeof(*urbs));
1979
1979
  if (!urbs)
1980
1980
  return LIBUSB_ERROR_NO_MEM;
1981
1981
 
@@ -2040,6 +2040,10 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
2040
2040
  if (r < 0) {
2041
2041
  if (errno == ENODEV) {
2042
2042
  r = LIBUSB_ERROR_NO_DEVICE;
2043
+ } else if (errno == EINVAL) {
2044
+ usbi_warn(TRANSFER_CTX(transfer),
2045
+ "submiturb failed, transfer too large");
2046
+ r = LIBUSB_ERROR_INVALID_PARAM;
2043
2047
  } else {
2044
2048
  usbi_err(TRANSFER_CTX(transfer),
2045
2049
  "submiturb failed error %d errno=%d", r, errno);
@@ -2093,9 +2097,6 @@ static int submit_control_transfer(struct usbi_transfer *itransfer)
2093
2097
  struct usbfs_urb *urb;
2094
2098
  int r;
2095
2099
 
2096
- if (tpriv->urbs)
2097
- return LIBUSB_ERROR_BUSY;
2098
-
2099
2100
  if (transfer->length - LIBUSB_CONTROL_SETUP_SIZE > MAX_CTRL_BUFFER_LENGTH)
2100
2101
  return LIBUSB_ERROR_INVALID_PARAM;
2101
2102
 
@@ -2153,6 +2154,14 @@ static int op_cancel_transfer(struct usbi_transfer *itransfer)
2153
2154
  struct linux_transfer_priv *tpriv = usbi_transfer_get_os_priv(itransfer);
2154
2155
  struct libusb_transfer *transfer =
2155
2156
  USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
2157
+ int r;
2158
+
2159
+ if (!tpriv->urbs)
2160
+ return LIBUSB_ERROR_NOT_FOUND;
2161
+
2162
+ r = discard_urbs(itransfer, 0, tpriv->num_urbs);
2163
+ if (r != 0)
2164
+ return r;
2156
2165
 
2157
2166
  switch (transfer->type) {
2158
2167
  case LIBUSB_TRANSFER_TYPE_BULK:
@@ -2160,21 +2169,11 @@ static int op_cancel_transfer(struct usbi_transfer *itransfer)
2160
2169
  if (tpriv->reap_action == ERROR)
2161
2170
  break;
2162
2171
  /* else, fall through */
2163
- case LIBUSB_TRANSFER_TYPE_CONTROL:
2164
- case LIBUSB_TRANSFER_TYPE_INTERRUPT:
2165
- case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
2166
- tpriv->reap_action = CANCELLED;
2167
- break;
2168
2172
  default:
2169
- usbi_err(TRANSFER_CTX(transfer),
2170
- "unknown endpoint type %d", transfer->type);
2171
- return LIBUSB_ERROR_INVALID_PARAM;
2173
+ tpriv->reap_action = CANCELLED;
2172
2174
  }
2173
2175
 
2174
- if (!tpriv->urbs)
2175
- return LIBUSB_ERROR_NOT_FOUND;
2176
-
2177
- return discard_urbs(itransfer, 0, tpriv->num_urbs);
2176
+ return 0;
2178
2177
  }
2179
2178
 
2180
2179
  static void op_clear_transfer_priv(struct usbi_transfer *itransfer)
@@ -2189,17 +2188,16 @@ static void op_clear_transfer_priv(struct usbi_transfer *itransfer)
2189
2188
  case LIBUSB_TRANSFER_TYPE_BULK:
2190
2189
  case LIBUSB_TRANSFER_TYPE_BULK_STREAM:
2191
2190
  case LIBUSB_TRANSFER_TYPE_INTERRUPT:
2192
- usbi_mutex_lock(&itransfer->lock);
2193
- if (tpriv->urbs)
2191
+ if (tpriv->urbs) {
2194
2192
  free(tpriv->urbs);
2195
- tpriv->urbs = NULL;
2196
- usbi_mutex_unlock(&itransfer->lock);
2193
+ tpriv->urbs = NULL;
2194
+ }
2197
2195
  break;
2198
2196
  case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
2199
- usbi_mutex_lock(&itransfer->lock);
2200
- if (tpriv->iso_urbs)
2197
+ if (tpriv->iso_urbs) {
2201
2198
  free_iso_urbs(tpriv);
2202
- usbi_mutex_unlock(&itransfer->lock);
2199
+ tpriv->iso_urbs = NULL;
2200
+ }
2203
2201
  break;
2204
2202
  default:
2205
2203
  usbi_err(TRANSFER_CTX(transfer),
@@ -2591,7 +2589,7 @@ static int op_handle_events(struct libusb_context *ctx,
2591
2589
  }
2592
2590
 
2593
2591
  if (!hpriv || hpriv->fd != pollfd->fd) {
2594
- usbi_err(ctx, "cannot find handle for fd %d\n",
2592
+ usbi_err(ctx, "cannot find handle for fd %d",
2595
2593
  pollfd->fd);
2596
2594
  continue;
2597
2595
  }
@@ -2691,5 +2689,4 @@ const struct usbi_os_backend linux_usbfs_backend = {
2691
2689
  .device_priv_size = sizeof(struct linux_device_priv),
2692
2690
  .device_handle_priv_size = sizeof(struct linux_device_handle_priv),
2693
2691
  .transfer_priv_size = sizeof(struct linux_transfer_priv),
2694
- .add_iso_packet_size = 0,
2695
2692
  };
@@ -81,7 +81,7 @@ struct usbfs_iso_packet_desc {
81
81
  unsigned int status;
82
82
  };
83
83
 
84
- #define MAX_ISO_BUFFER_LENGTH 32768
84
+ #define MAX_ISO_BUFFER_LENGTH 49152 * 128
85
85
  #define MAX_BULK_BUFFER_LENGTH 16384
86
86
  #define MAX_CTRL_BUFFER_LENGTH 4096
87
87
 
@@ -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
  /*
@@ -125,13 +124,13 @@ const struct usbi_os_backend netbsd_backend = {
125
124
  netbsd_cancel_transfer,
126
125
  netbsd_clear_transfer_priv,
127
126
 
128
- netbsd_handle_events,
127
+ NULL, /* handle_events() */
128
+ netbsd_handle_transfer_completion,
129
129
 
130
130
  netbsd_clock_gettime,
131
131
  sizeof(struct device_priv),
132
132
  sizeof(struct handle_priv),
133
133
  0, /* transfer_priv_size */
134
- 0, /* add_iso_packet_size */
135
134
  };
136
135
 
137
136
  int
@@ -222,10 +221,7 @@ netbsd_open(struct libusb_device_handle *handle)
222
221
 
223
222
  usbi_dbg("open %s: fd %d", dpriv->devnode, dpriv->fd);
224
223
 
225
- if (pipe(hpriv->pipe) < 0)
226
- return _errno_to_libusb(errno);
227
-
228
- return usbi_add_pollfd(HANDLE_CTX(handle), hpriv->pipe[0], POLLIN);
224
+ return (LIBUSB_SUCCESS);
229
225
  }
230
226
 
231
227
  void
@@ -238,11 +234,6 @@ netbsd_close(struct libusb_device_handle *handle)
238
234
 
239
235
  close(dpriv->fd);
240
236
  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
237
  }
247
238
 
248
239
  int
@@ -469,8 +460,7 @@ netbsd_submit_transfer(struct usbi_transfer *itransfer)
469
460
  if (err)
470
461
  return (err);
471
462
 
472
- if (write(hpriv->pipe[1], &itransfer, sizeof(itransfer)) < 0)
473
- return _errno_to_libusb(errno);
463
+ usbi_signal_transfer_completion(itransfer);
474
464
 
475
465
  return (LIBUSB_SUCCESS);
476
466
  }
@@ -492,63 +482,9 @@ netbsd_clear_transfer_priv(struct usbi_transfer *itransfer)
492
482
  }
493
483
 
494
484
  int
495
- netbsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds,
496
- int num_ready)
485
+ netbsd_handle_transfer_completion(struct usbi_transfer *itransfer)
497
486
  {
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);
487
+ return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
552
488
  }
553
489
 
554
490
  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
  /*
@@ -128,13 +127,13 @@ const struct usbi_os_backend openbsd_backend = {
128
127
  obsd_cancel_transfer,
129
128
  obsd_clear_transfer_priv,
130
129
 
131
- obsd_handle_events,
130
+ NULL, /* handle_events() */
131
+ obsd_handle_transfer_completion,
132
132
 
133
133
  obsd_clock_gettime,
134
134
  sizeof(struct device_priv),
135
135
  sizeof(struct handle_priv),
136
136
  0, /* transfer_priv_size */
137
- 0, /* add_iso_packet_size */
138
137
  };
139
138
 
140
139
  #define DEVPATH "/dev/"
@@ -262,10 +261,7 @@ obsd_open(struct libusb_device_handle *handle)
262
261
  usbi_dbg("open %s: fd %d", devnode, dpriv->fd);
263
262
  }
264
263
 
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);
264
+ return (LIBUSB_SUCCESS);
269
265
  }
270
266
 
271
267
  void
@@ -280,11 +276,6 @@ obsd_close(struct libusb_device_handle *handle)
280
276
  close(dpriv->fd);
281
277
  dpriv->fd = -1;
282
278
  }
283
-
284
- usbi_remove_pollfd(HANDLE_CTX(handle), hpriv->pipe[0]);
285
-
286
- close(hpriv->pipe[0]);
287
- close(hpriv->pipe[1]);
288
279
  }
289
280
 
290
281
  int
@@ -515,8 +506,7 @@ obsd_submit_transfer(struct usbi_transfer *itransfer)
515
506
  if (err)
516
507
  return (err);
517
508
 
518
- if (write(hpriv->pipe[1], &itransfer, sizeof(itransfer)) < 0)
519
- return _errno_to_libusb(errno);
509
+ usbi_signal_transfer_completion(itransfer);
520
510
 
521
511
  return (LIBUSB_SUCCESS);
522
512
  }
@@ -538,63 +528,9 @@ obsd_clear_transfer_priv(struct usbi_transfer *itransfer)
538
528
  }
539
529
 
540
530
  int
541
- obsd_handle_events(struct libusb_context *ctx, struct pollfd *fds, nfds_t nfds,
542
- int num_ready)
531
+ obsd_handle_transfer_completion(struct usbi_transfer *itransfer)
543
532
  {
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);
533
+ return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
598
534
  }
599
535
 
600
536
  int