libusb 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. data/.travis.yml +2 -2
  2. data/Gemfile +0 -8
  3. data/History.md +5 -0
  4. data/README.md +6 -6
  5. data/Rakefile +9 -9
  6. data/ext/extconf.rb +1 -1
  7. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/AUTHORS +10 -0
  8. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/COPYING +0 -0
  9. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/ChangeLog +17 -9
  10. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/INSTALL +0 -0
  11. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/Makefile.am +0 -0
  12. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/Makefile.in +153 -178
  13. data/ext/libusb-1.0.18/NEWS +2 -0
  14. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/PORTING +13 -13
  15. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/README +9 -11
  16. data/ext/libusb-1.0.18/TODO +2 -0
  17. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/Xcode/common.xcconfig +3 -3
  18. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/Xcode/config.h +0 -0
  19. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/Xcode/debug.xcconfig +2 -2
  20. data/ext/{libusbx-1.0.17/Xcode/libusbx.xcconfig → libusb-1.0.18/Xcode/libusb.xcconfig} +2 -2
  21. data/ext/libusb-1.0.18/Xcode/libusb.xcodeproj/project.pbxproj +1 -0
  22. data/ext/{libusbx-1.0.17/Xcode/libusbx_debug.xcconfig → libusb-1.0.18/Xcode/libusb_debug.xcconfig} +3 -3
  23. data/ext/{libusbx-1.0.17/Xcode/libusbx_release.xcconfig → libusb-1.0.18/Xcode/libusb_release.xcconfig} +3 -3
  24. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/Xcode/release.xcconfig +2 -2
  25. data/ext/{libusbx-1.0.17/m4/libtool.m4 → libusb-1.0.18/aclocal.m4} +1731 -27
  26. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/android/README +0 -0
  27. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/android/config.h +1 -10
  28. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/android/jni/Android.mk +0 -0
  29. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/android/jni/Application.mk +6 -1
  30. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/android/jni/examples.mk +0 -0
  31. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/android/jni/libusb.mk +0 -0
  32. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/android/jni/tests.mk +0 -0
  33. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/compile +3 -7
  34. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/config.guess +19 -24
  35. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/config.h.in +0 -0
  36. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/config.sub +30 -47
  37. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/configure +118 -172
  38. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/configure.ac +24 -2
  39. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/depcomp +186 -268
  40. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/doc/Makefile.am +1 -1
  41. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/doc/Makefile.in +36 -73
  42. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/doc/doxygen.cfg.in +1 -1
  43. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/Makefile.am +0 -0
  44. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/Makefile.in +68 -132
  45. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/dpfp.c +1 -1
  46. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/dpfp_threaded.c +1 -1
  47. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/ezusb.c +57 -26
  48. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/ezusb.h +0 -0
  49. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/fxload.c +3 -3
  50. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/getopt/getopt.c +0 -0
  51. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/getopt/getopt.h +0 -0
  52. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/getopt/getopt1.c +0 -0
  53. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/hotplugtest.c +9 -2
  54. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/listdevs.c +1 -1
  55. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/sam3u_benchmark.c +0 -0
  56. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/examples/xusb.c +20 -4
  57. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/install-sh +7 -7
  58. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb-1.0.pc.in +1 -1
  59. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/Makefile.am +1 -1
  60. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/Makefile.in +94 -134
  61. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/core.c +95 -74
  62. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/descriptor.c +2 -2
  63. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/hotplug.c +3 -3
  64. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/hotplug.h +1 -1
  65. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/io.c +127 -116
  66. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/libusb-1.0.def +0 -0
  67. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/libusb-1.0.rc +1 -1
  68. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/libusb.h +42 -39
  69. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/libusbi.h +20 -11
  70. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/darwin_usb.c +20 -16
  71. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/darwin_usb.h +1 -1
  72. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/linux_netlink.c +0 -0
  73. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/linux_udev.c +0 -0
  74. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/linux_usbfs.c +15 -12
  75. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/linux_usbfs.h +0 -0
  76. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/netbsd_usb.c +2 -4
  77. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/openbsd_usb.c +5 -2
  78. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/poll_posix.c +0 -0
  79. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/poll_posix.h +0 -0
  80. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/poll_windows.c +2 -2
  81. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/poll_windows.h +0 -0
  82. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/threads_posix.c +1 -1
  83. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/threads_posix.h +1 -1
  84. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/threads_windows.c +1 -1
  85. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/threads_windows.h +1 -1
  86. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/wince_usb.c +1 -2
  87. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/wince_usb.h +2 -2
  88. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/windows_common.h +1 -1
  89. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/windows_usb.c +53 -33
  90. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/os/windows_usb.h +6 -1
  91. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/strerror.c +2 -2
  92. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/sync.c +6 -6
  93. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/libusb/version.h +1 -1
  94. data/ext/libusb-1.0.18/libusb/version_nano.h +1 -0
  95. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/ltmain.sh +3 -3
  96. data/ext/libusb-1.0.18/missing +331 -0
  97. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/tests/Makefile.am +1 -1
  98. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/tests/Makefile.in +69 -127
  99. data/ext/{libusbx-1.0.17/tests/libusbx_testlib.h → libusb-1.0.18/tests/libusb_testlib.h} +15 -15
  100. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/tests/stress.c +16 -16
  101. data/ext/{libusbx-1.0.17 → libusb-1.0.18}/tests/testlib.c +21 -20
  102. data/lib/libusb/version_gem.rb +1 -1
  103. data/libusb.gemspec +1 -6
  104. metadata +117 -135
  105. checksums.yaml +0 -7
  106. checksums.yaml.gz.sig +0 -0
  107. data.tar.gz.sig +0 -0
  108. data/ext/libusbx-1.0.17/NEWS +0 -2
  109. data/ext/libusbx-1.0.17/TODO +0 -2
  110. data/ext/libusbx-1.0.17/Xcode/libusbx.xcodeproj/project.pbxproj +0 -864
  111. data/ext/libusbx-1.0.17/aclocal.m4 +0 -1112
  112. data/ext/libusbx-1.0.17/libusb/version_nano.h +0 -1
  113. data/ext/libusbx-1.0.17/m4/ltoptions.m4 +0 -384
  114. data/ext/libusbx-1.0.17/m4/ltsugar.m4 +0 -123
  115. data/ext/libusbx-1.0.17/m4/ltversion.m4 +0 -23
  116. data/ext/libusbx-1.0.17/m4/lt~obsolete.m4 +0 -98
  117. data/ext/libusbx-1.0.17/missing +0 -215
  118. metadata.gz.sig +0 -0
@@ -1,5 +1,5 @@
1
1
  /*
2
- * darwin backend for libusbx 1.0
2
+ * darwin backend for libusb 1.0
3
3
  * Copyright © 2008-2013 Nathan Hjelm <hjelmn@users.sourceforge.net>
4
4
  *
5
5
  * This library is free software; you can redistribute it and/or
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C; c-basic-offset:8 ; indent-tabs-mode:t -*- */
2
2
  /*
3
- * Linux usbfs backend for libusbx
3
+ * Linux usbfs backend for libusb
4
4
  * Copyright © 2007-2009 Daniel Drake <dsd@gentoo.org>
5
5
  * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
6
6
  * Copyright © 2013 Nathan Hjelm <hjelmn@mac.com>
@@ -49,7 +49,7 @@
49
49
  * sysfs allows us to read the kernel's in-memory copies of device descriptors
50
50
  * and so forth, avoiding the need to open the device:
51
51
  * - The binary "descriptors" file contains all config descriptors since
52
- * 2.6.26, commit 217a9081d8e69026186067711131b77f0ce219ed
52
+ * 2.6.26, commit 217a9081d8e69026186067711131b77f0ce219ed
53
53
  * - The binary "descriptors" file was added in 2.6.23, commit
54
54
  * 69d42a78f935d19384d1f6e4f94b65bb162b36df, but it only contains the
55
55
  * active config descriptors
@@ -197,10 +197,10 @@ static int _get_usbfs_fd(struct libusb_device *dev, mode_t mode, int silent)
197
197
  return fd; /* Success */
198
198
 
199
199
  if (!silent) {
200
- usbi_err(ctx, "libusbx couldn't open USB device %s: %s",
200
+ usbi_err(ctx, "libusb couldn't open USB device %s: %s",
201
201
  path, strerror(errno));
202
202
  if (errno == EACCES && mode == O_RDWR)
203
- usbi_err(ctx, "libusbx requires write access to USB "
203
+ usbi_err(ctx, "libusb requires write access to USB "
204
204
  "device nodes.");
205
205
  }
206
206
 
@@ -564,7 +564,7 @@ static int op_get_device_descriptor(struct libusb_device *dev,
564
564
  static int sysfs_get_active_config(struct libusb_device *dev, int *config)
565
565
  {
566
566
  char *endptr;
567
- char tmp[4] = {0, 0, 0, 0};
567
+ char tmp[5] = {0, 0, 0, 0, 0};
568
568
  long num;
569
569
  int fd;
570
570
  ssize_t r;
@@ -576,7 +576,7 @@ static int sysfs_get_active_config(struct libusb_device *dev, int *config)
576
576
  r = read(fd, tmp, sizeof(tmp));
577
577
  close(fd);
578
578
  if (r < 0) {
579
- usbi_err(DEVICE_CTX(dev),
579
+ usbi_err(DEVICE_CTX(dev),
580
580
  "read bConfigurationValue failed ret=%d errno=%d", r, errno);
581
581
  return LIBUSB_ERROR_IO;
582
582
  } else if (r == 0) {
@@ -913,7 +913,7 @@ static int initialize_device(struct libusb_device *dev, uint8_t busnum,
913
913
  }
914
914
  priv->descriptors_len += r;
915
915
  } while (priv->descriptors_len == descriptors_size);
916
-
916
+
917
917
  close(fd);
918
918
 
919
919
  if (priv->descriptors_len < DEVICE_DESC_LENGTH) {
@@ -1048,9 +1048,11 @@ int linux_enumerate_device(struct libusb_context *ctx,
1048
1048
  usbi_dbg("busnum %d devaddr %d session_id %ld", busnum, devaddr,
1049
1049
  session_id);
1050
1050
 
1051
- if (usbi_get_device_by_session_id(ctx, session_id)) {
1051
+ dev = usbi_get_device_by_session_id(ctx, session_id);
1052
+ if (dev) {
1052
1053
  /* device already exists in the context */
1053
1054
  usbi_dbg("session_id %ld already exists", session_id);
1055
+ libusb_unref_device(dev);
1054
1056
  return LIBUSB_SUCCESS;
1055
1057
  }
1056
1058
 
@@ -1101,6 +1103,7 @@ void linux_device_disconnected(uint8_t busnum, uint8_t devaddr, const char *sys_
1101
1103
  dev = usbi_get_device_by_session_id (ctx, session_id);
1102
1104
  if (NULL != dev) {
1103
1105
  usbi_disconnect_device (dev);
1106
+ libusb_unref_device(dev);
1104
1107
  } else {
1105
1108
  usbi_dbg("device not found for session %x", session_id);
1106
1109
  }
@@ -1805,7 +1808,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer,
1805
1808
  "submiturb failed error %d errno=%d", r, errno);
1806
1809
  r = LIBUSB_ERROR_IO;
1807
1810
  }
1808
-
1811
+
1809
1812
  /* if the first URB submission fails, we can simply free up and
1810
1813
  * return failure immediately. */
1811
1814
  if (i == 0) {
@@ -1820,7 +1823,7 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer,
1820
1823
  * complications:
1821
1824
  * - discarding is asynchronous - discarded urbs will be reaped
1822
1825
  * later. the user must not have freed the transfer when the
1823
- * discarded URBs are reaped, otherwise libusbx will be using
1826
+ * discarded URBs are reaped, otherwise libusb will be using
1824
1827
  * freed memory.
1825
1828
  * - the earlier URBs may have completed successfully and we do
1826
1829
  * not want to throw away any data.
@@ -1982,7 +1985,7 @@ static int submit_iso_transfer(struct usbi_transfer *itransfer)
1982
1985
  * complications:
1983
1986
  * - discarding is asynchronous - discarded urbs will be reaped
1984
1987
  * later. the user must not have freed the transfer when the
1985
- * discarded URBs are reaped, otherwise libusbx will be using
1988
+ * discarded URBs are reaped, otherwise libusb will be using
1986
1989
  * freed memory.
1987
1990
  * - the earlier URBs may have completed successfully and we do
1988
1991
  * not want to throw away any data.
@@ -2157,7 +2160,7 @@ static int handle_bulk_completion(struct usbi_transfer *itransfer,
2157
2160
  *
2158
2161
  * When this happens, our objectives are not to lose any "surplus" data,
2159
2162
  * and also to stick it at the end of the previously-received data
2160
- * (closing any holes), so that libusbx reports the total amount of
2163
+ * (closing any holes), so that libusb reports the total amount of
2161
2164
  * transferred data and presents it in a contiguous chunk.
2162
2165
  */
2163
2166
  if (urb->actual_length > 0) {
@@ -161,9 +161,7 @@ netbsd_get_device_list(struct libusb_context * ctx,
161
161
  session_id = (di.udi_bus << 8 | di.udi_addr);
162
162
  dev = usbi_get_device_by_session_id(ctx, session_id);
163
163
 
164
- if (dev) {
165
- dev = libusb_ref_device(dev);
166
- } else {
164
+ if (dev == NULL) {
167
165
  dev = usbi_alloc_device(ctx, session_id);
168
166
  if (dev == NULL)
169
167
  return (LIBUSB_ERROR_NO_MEM);
@@ -641,7 +639,7 @@ _sync_control_transfer(struct usbi_transfer *itransfer)
641
639
 
642
640
  req.ucr_request.bmRequestType = setup->bmRequestType;
643
641
  req.ucr_request.bRequest = setup->bRequest;
644
- /* Don't use USETW, libusbx already deals with the endianness */
642
+ /* Don't use USETW, libusb already deals with the endianness */
645
643
  (*(uint16_t *)req.ucr_request.wValue) = setup->wValue;
646
644
  (*(uint16_t *)req.ucr_request.wIndex) = setup->wIndex;
647
645
  (*(uint16_t *)req.ucr_request.wLength) = setup->wLength;
@@ -215,8 +215,10 @@ obsd_get_device_list(struct libusb_context * ctx,
215
215
  continue;
216
216
  }
217
217
 
218
- if (usbi_sanitize_device(dev))
218
+ if (usbi_sanitize_device(dev)) {
219
219
  libusb_unref_device(dev);
220
+ continue;
221
+ }
220
222
  }
221
223
 
222
224
  ddd = discovered_devs_append(*discdevs, dev);
@@ -224,6 +226,7 @@ obsd_get_device_list(struct libusb_context * ctx,
224
226
  close(fd);
225
227
  return (LIBUSB_ERROR_NO_MEM);
226
228
  }
229
+ libusb_unref_device(dev);
227
230
 
228
231
  *discdevs = ddd;
229
232
  devices[addr] = 1;
@@ -697,7 +700,7 @@ _sync_control_transfer(struct usbi_transfer *itransfer)
697
700
  req.ucr_addr = transfer->dev_handle->dev->device_address;
698
701
  req.ucr_request.bmRequestType = setup->bmRequestType;
699
702
  req.ucr_request.bRequest = setup->bRequest;
700
- /* Don't use USETW, libusbx already deals with the endianness */
703
+ /* Don't use USETW, libusb already deals with the endianness */
701
704
  (*(uint16_t *)req.ucr_request.wValue) = setup->wValue;
702
705
  (*(uint16_t *)req.ucr_request.wIndex) = setup->wIndex;
703
706
  (*(uint16_t *)req.ucr_request.wLength) = setup->wLength;
@@ -22,7 +22,7 @@
22
22
  */
23
23
 
24
24
  /*
25
- * poll() and pipe() Windows compatibility layer for libusbx 1.0
25
+ * poll() and pipe() Windows compatibility layer for libusb 1.0
26
26
  *
27
27
  * The way this layer works is by using OVERLAPPED with async I/O transfers, as
28
28
  * OVERLAPPED have an associated event which is flagged for I/O completion.
@@ -252,7 +252,7 @@ void exit_polling(void)
252
252
 
253
253
  /*
254
254
  * Create a fake pipe.
255
- * As libusbx only uses pipes for signaling, all we need from a pipe is an
255
+ * As libusb only uses pipes for signaling, all we need from a pipe is an
256
256
  * event. To that extent, we create a single wfd and overlapped as a means
257
257
  * to access that event.
258
258
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * libusbx synchronization using POSIX Threads
2
+ * libusb synchronization using POSIX Threads
3
3
  *
4
4
  * Copyright © 2011 Vitali Lovich <vlovich@aliph.com>
5
5
  * Copyright © 2011 Peter Stuge <peter@stuge.se>
@@ -1,5 +1,5 @@
1
1
  /*
2
- * libusbx synchronization using POSIX Threads
2
+ * libusb synchronization using POSIX Threads
3
3
  *
4
4
  * Copyright © 2010 Peter Stuge <peter@stuge.se>
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /*
2
- * libusbx synchronization on Microsoft Windows
2
+ * libusb synchronization on Microsoft Windows
3
3
  *
4
4
  * Copyright © 2010 Michael Plante <michael.plante@gmail.com>
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /*
2
- * libusbx synchronization on Microsoft Windows
2
+ * libusb synchronization on Microsoft Windows
3
3
  *
4
4
  * Copyright © 2010 Michael Plante <michael.plante@gmail.com>
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Windows CE backend for libusbx 1.0
2
+ * Windows CE backend for libusb 1.0
3
3
  * Copyright © 2011-2013 RealVNC Ltd.
4
4
  * Large portions taken from Windows backend, which is
5
5
  * Copyright © 2009-2010 Pete Batard <pbatard@gmail.com>
@@ -372,7 +372,6 @@ static int wince_get_device_list(
372
372
  if (dev) {
373
373
  usbi_dbg("using existing device for %d/%d (session %ld)",
374
374
  bus_addr, dev_addr, session_id);
375
- libusb_ref_device(dev);
376
375
  // Release just this element in the device list (as we already hold a
377
376
  // reference to it).
378
377
  UkwReleaseDeviceList(driver_handle, &devices[i], 1);
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Windows CE backend for libusbx 1.0
2
+ * Windows CE backend for libusb 1.0
3
3
  * Copyright © 2011-2013 RealVNC Ltd.
4
4
  * Portions taken from Windows backend, which is
5
5
  * Copyright © 2009-2010 Pete Batard <pbatard@gmail.com>
@@ -36,7 +36,7 @@
36
36
  // This backend dynamically loads ceusbkwrapper.dll and doesn't include
37
37
  // ceusbkwrapper.h directly to simplify the build process. The kernel
38
38
  // side wrapper driver is built using the platform image build tools,
39
- // which makes it difficult to reference directly from the libusbx build
39
+ // which makes it difficult to reference directly from the libusb build
40
40
  // system.
41
41
  struct UKW_DEVICE_PRIV;
42
42
  typedef struct UKW_DEVICE_PRIV *UKW_DEVICE;
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Windows backend common header for libusbx 1.0
2
+ * Windows backend common header for libusb 1.0
3
3
  *
4
4
  * This file brings together header code common between
5
5
  * the desktop Windows and Windows CE backends.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * windows backend for libusbx 1.0
2
+ * windows backend for libusb 1.0
3
3
  * Copyright © 2009-2012 Pete Batard <pete@akeo.ie>
4
4
  * With contributions from Michael Plante, Orin Eman et al.
5
5
  * Parts of this code adapted from libusb-win32-v1 by Stephan Meyer
@@ -158,6 +158,20 @@ static char err_string[ERR_BUFFER_SIZE];
158
158
 
159
159
  safe_sprintf(err_string, ERR_BUFFER_SIZE, "[%u] ", error_code);
160
160
 
161
+ // Translate codes returned by SetupAPI. The ones we are dealing with are either
162
+ // in 0x0000xxxx or 0xE000xxxx and can be distinguished from standard error codes.
163
+ // See http://msdn.microsoft.com/en-us/library/windows/hardware/ff545011.aspx
164
+ switch (error_code & 0xE0000000) {
165
+ case 0:
166
+ error_code = HRESULT_FROM_WIN32(error_code); // Still leaves ERROR_SUCCESS unmodified
167
+ break;
168
+ case 0xE0000000:
169
+ error_code = 0x80000000 | (FACILITY_SETUPAPI << 16) | (error_code & 0x0000FFFF);
170
+ break;
171
+ default:
172
+ break;
173
+ }
174
+
161
175
  size = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error_code,
162
176
  MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), &err_string[safe_strlen(err_string)],
163
177
  ERR_BUFFER_SIZE - (DWORD)safe_strlen(err_string), NULL);
@@ -791,10 +805,10 @@ static void auto_release(struct usbi_transfer *itransfer)
791
805
  }
792
806
 
793
807
  /*
794
- * init: libusbx backend init function
808
+ * init: libusb backend init function
795
809
  *
796
810
  * This function enumerates the HCDs (Host Controller Drivers) and populates our private HCD list
797
- * In our implementation, we equate Windows' "HCD" to libusbx's "bus". Note that bus is zero indexed.
811
+ * In our implementation, we equate Windows' "HCD" to libusb's "bus". Note that bus is zero indexed.
798
812
  * HCDs are not expected to change after init (might not hold true for hot pluggable USB PCI card?)
799
813
  */
800
814
  static int windows_init(struct libusb_context *ctx)
@@ -1071,7 +1085,7 @@ static int cache_config_descriptors(struct libusb_device *dev, HANDLE hub_handle
1071
1085
  }
1072
1086
 
1073
1087
  /*
1074
- * Populate a libusbx device structure
1088
+ * Populate a libusb device structure
1075
1089
  */
1076
1090
  static int init_device(struct libusb_device* dev, struct libusb_device* parent_dev,
1077
1091
  uint8_t port_number, char* device_id, DWORD devinst)
@@ -1103,8 +1117,10 @@ static int init_device(struct libusb_device* dev, struct libusb_device* parent_d
1103
1117
  if (tmp_dev->bus_number != 0) {
1104
1118
  usbi_dbg("got bus number from ancestor #%d", i);
1105
1119
  parent_dev->bus_number = tmp_dev->bus_number;
1120
+ libusb_unref_device(tmp_dev);
1106
1121
  break;
1107
1122
  }
1123
+ libusb_unref_device(tmp_dev);
1108
1124
  }
1109
1125
  }
1110
1126
  if (parent_dev->bus_number == 0) {
@@ -1116,7 +1132,7 @@ static int init_device(struct libusb_device* dev, struct libusb_device* parent_d
1116
1132
  dev->port_number = port_number;
1117
1133
  priv->depth = parent_priv->depth + 1;
1118
1134
  priv->parent_dev = parent_dev;
1119
- dev->parent_dev = libusb_ref_device(parent_dev);
1135
+ dev->parent_dev = parent_dev;
1120
1136
 
1121
1137
  // If the device address is already set, we can stop here
1122
1138
  if (dev->device_address != 0) {
@@ -1323,7 +1339,7 @@ static int set_hid_interface(struct libusb_context* ctx, struct libusb_device* d
1323
1339
  }
1324
1340
 
1325
1341
  /*
1326
- * get_device_list: libusbx backend device enumeration function
1342
+ * get_device_list: libusb backend device enumeration function
1327
1343
  */
1328
1344
  static int windows_get_device_list(struct libusb_context *ctx, struct discovered_devs **_discdevs)
1329
1345
  {
@@ -1473,7 +1489,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
1473
1489
  if (!pSetupDiGetDeviceRegistryPropertyA(dev_info, &dev_info_data, SPDRP_DRIVER,
1474
1490
  &reg_type, (BYTE*)strbuf, size, &size)) {
1475
1491
  usbi_info(ctx, "The following device has no driver: '%s'", dev_id_path);
1476
- usbi_info(ctx, "libusbx will not be able to access it.");
1492
+ usbi_info(ctx, "libusb will not be able to access it.");
1477
1493
  }
1478
1494
  // ...and to add the additional device interface GUIDs
1479
1495
  key = pSetupDiOpenDevRegKey(dev_info, &dev_info_data, DICS_FLAG_GLOBAL, 0, DIREG_DEV, KEY_READ);
@@ -1537,6 +1553,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
1537
1553
  parent_priv = _device_priv(parent_dev);
1538
1554
  // virtual USB devices are also listed during GEN - don't process these yet
1539
1555
  if ( (pass == GEN_PASS) && (parent_priv->apib->id != USB_API_HUB) ) {
1556
+ libusb_unref_device(parent_dev);
1540
1557
  continue;
1541
1558
  }
1542
1559
  break;
@@ -1559,20 +1576,20 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
1559
1576
  LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
1560
1577
  }
1561
1578
  windows_device_priv_init(dev);
1562
- // Keep track of devices that need unref
1563
- unref_list[unref_cur++] = dev;
1564
- if (unref_cur >= unref_size) {
1565
- unref_size += 64;
1566
- unref_list = usbi_reallocf(unref_list, unref_size*sizeof(libusb_device*));
1567
- if (unref_list == NULL) {
1568
- usbi_err(ctx, "could not realloc list for unref - aborting.");
1569
- LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
1570
- }
1571
- }
1572
1579
  } else {
1573
1580
  usbi_dbg("found existing device for session [%X] (%d.%d)",
1574
1581
  session_id, dev->bus_number, dev->device_address);
1575
1582
  }
1583
+ // Keep track of devices that need unref
1584
+ unref_list[unref_cur++] = dev;
1585
+ if (unref_cur >= unref_size) {
1586
+ unref_size += 64;
1587
+ unref_list = usbi_reallocf(unref_list, unref_size*sizeof(libusb_device*));
1588
+ if (unref_list == NULL) {
1589
+ usbi_err(ctx, "could not realloc list for unref - aborting.");
1590
+ LOOP_BREAK(LIBUSB_ERROR_NO_MEM);
1591
+ }
1592
+ }
1576
1593
  priv = _device_priv(dev);
1577
1594
  }
1578
1595
 
@@ -1658,6 +1675,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
1658
1675
  break;
1659
1676
  }
1660
1677
  }
1678
+ libusb_unref_device(parent_dev);
1661
1679
  break;
1662
1680
  }
1663
1681
  }
@@ -1678,7 +1696,7 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered
1678
1696
  }
1679
1697
 
1680
1698
  /*
1681
- * exit: libusbx backend deinitialization function
1699
+ * exit: libusb backend deinitialization function
1682
1700
  */
1683
1701
  static void windows_exit(void)
1684
1702
  {
@@ -2074,7 +2092,7 @@ static void windows_transfer_callback(struct usbi_transfer *itransfer, uint32_t
2074
2092
  }
2075
2093
  break;
2076
2094
  default:
2077
- usbi_err(ITRANSFER_CTX(itransfer), "detected I/O error %d: %s", io_result, windows_error_str(0));
2095
+ usbi_err(ITRANSFER_CTX(itransfer), "detected I/O error %d: %s", io_result, windows_error_str(io_result));
2078
2096
  status = LIBUSB_TRANSFER_ERROR;
2079
2097
  break;
2080
2098
  }
@@ -2377,7 +2395,7 @@ static int common_configure_endpoints(int sub_api, struct libusb_device_handle *
2377
2395
  return LIBUSB_SUCCESS;
2378
2396
  }
2379
2397
  // These names must be uppercase
2380
- const char* hub_driver_names[] = {"USBHUB", "USBHUB3", "NUSB3HUB", "RUSB3HUB", "FLXHCIH", "TIHUB3", "ETRONHUB3", "VIAHUB3", "ASMTHUB3", "IUSB3HUB"};
2398
+ const char* hub_driver_names[] = {"USBHUB", "USBHUB3", "NUSB3HUB", "RUSB3HUB", "FLXHCIH", "TIHUB3", "ETRONHUB3", "VIAHUB3", "ASMTHUB3", "IUSB3HUB", "VUSB3HUB"};
2381
2399
  const char* composite_driver_names[] = {"USBCCGP"};
2382
2400
  const char* winusbx_driver_names[] = WINUSBX_DRV_NAMES;
2383
2401
  const char* hid_driver_names[] = {"HIDUSB", "MOUHID", "KBDHID"};
@@ -4157,19 +4175,21 @@ static int hid_copy_transfer_data(int sub_api, struct usbi_transfer *itransfer,
4157
4175
  if (transfer_priv->hid_buffer != NULL) {
4158
4176
  // If we have a valid hid_buffer, it means the transfer was async
4159
4177
  if (transfer_priv->hid_dest != NULL) { // Data readout
4160
- // First, check for overflow
4161
- if (corrected_size > transfer_priv->hid_expected_size) {
4162
- usbi_err(ctx, "OVERFLOW!");
4163
- corrected_size = (uint32_t)transfer_priv->hid_expected_size;
4164
- r = LIBUSB_TRANSFER_OVERFLOW;
4165
- }
4178
+ if (corrected_size > 0) {
4179
+ // First, check for overflow
4180
+ if (corrected_size > transfer_priv->hid_expected_size) {
4181
+ usbi_err(ctx, "OVERFLOW!");
4182
+ corrected_size = (uint32_t)transfer_priv->hid_expected_size;
4183
+ r = LIBUSB_TRANSFER_OVERFLOW;
4184
+ }
4166
4185
 
4167
- if (transfer_priv->hid_buffer[0] == 0) {
4168
- // Discard the 1 byte report ID prefix
4169
- corrected_size--;
4170
- memcpy(transfer_priv->hid_dest, transfer_priv->hid_buffer+1, corrected_size);
4171
- } else {
4172
- memcpy(transfer_priv->hid_dest, transfer_priv->hid_buffer, corrected_size);
4186
+ if (transfer_priv->hid_buffer[0] == 0) {
4187
+ // Discard the 1 byte report ID prefix
4188
+ corrected_size--;
4189
+ memcpy(transfer_priv->hid_dest, transfer_priv->hid_buffer+1, corrected_size);
4190
+ } else {
4191
+ memcpy(transfer_priv->hid_dest, transfer_priv->hid_buffer, corrected_size);
4192
+ }
4173
4193
  }
4174
4194
  transfer_priv->hid_dest = NULL;
4175
4195
  }
@@ -4297,7 +4317,7 @@ static int composite_submit_control_transfer(int sub_api, struct usbi_transfer *
4297
4317
  }
4298
4318
  }
4299
4319
 
4300
- usbi_err(ctx, "no libusbx supported interfaces to complete request");
4320
+ usbi_err(ctx, "no libusb supported interfaces to complete request");
4301
4321
  return LIBUSB_ERROR_NOT_FOUND;
4302
4322
  }
4303
4323