libusb 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +8 -2
  3. data/Gemfile +2 -0
  4. data/History.md +12 -0
  5. data/README.md +25 -14
  6. data/Rakefile +64 -109
  7. data/appveyor.yml +23 -0
  8. data/ext/extconf.rb +10 -12
  9. data/ext/libusb_recipe.rb +29 -0
  10. data/lib/libusb/call.rb +14 -11
  11. data/lib/libusb/compat.rb +9 -9
  12. data/lib/libusb/context.rb +16 -1
  13. data/lib/libusb/dependencies.rb +7 -0
  14. data/lib/libusb/dev_handle.rb +13 -3
  15. data/lib/libusb/eventmachine.rb +4 -4
  16. data/lib/libusb/transfer.rb +71 -10
  17. data/lib/libusb/version_gem.rb +1 -1
  18. data/libusb.gemspec +7 -5
  19. data/ports/archives/libusb-1.0.21.tar.bz2 +0 -0
  20. data/test/test_libusb_bulk_stream_transfer.rb +1 -1
  21. data/test/test_libusb_descriptors.rb +4 -4
  22. data/test/test_libusb_event_machine.rb +7 -7
  23. data/test/test_libusb_hotplug.rb +15 -3
  24. data/test/test_libusb_iso_transfer.rb +1 -1
  25. data/test/test_libusb_mass_storage.rb +19 -19
  26. data/test/test_libusb_mass_storage2.rb +1 -1
  27. data/test/test_libusb_structs.rb +13 -0
  28. data/test/test_libusb_threads.rb +2 -2
  29. data/wireshark-usb-sniffer.png +0 -0
  30. metadata +32 -156
  31. checksums.yaml.gz.sig +0 -0
  32. data.tar.gz.sig +0 -0
  33. data/ext/libusb-1.0.20/AUTHORS +0 -89
  34. data/ext/libusb-1.0.20/COPYING +0 -504
  35. data/ext/libusb-1.0.20/ChangeLog +0 -227
  36. data/ext/libusb-1.0.20/INSTALL +0 -234
  37. data/ext/libusb-1.0.20/Makefile.am +0 -28
  38. data/ext/libusb-1.0.20/Makefile.in +0 -897
  39. data/ext/libusb-1.0.20/NEWS +0 -2
  40. data/ext/libusb-1.0.20/PORTING +0 -94
  41. data/ext/libusb-1.0.20/README +0 -29
  42. data/ext/libusb-1.0.20/TODO +0 -2
  43. data/ext/libusb-1.0.20/Xcode/common.xcconfig +0 -49
  44. data/ext/libusb-1.0.20/Xcode/config.h +0 -28
  45. data/ext/libusb-1.0.20/Xcode/debug.xcconfig +0 -29
  46. data/ext/libusb-1.0.20/Xcode/libusb.xcconfig +0 -21
  47. data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +0 -865
  48. data/ext/libusb-1.0.20/Xcode/libusb_debug.xcconfig +0 -21
  49. data/ext/libusb-1.0.20/Xcode/libusb_release.xcconfig +0 -21
  50. data/ext/libusb-1.0.20/Xcode/release.xcconfig +0 -30
  51. data/ext/libusb-1.0.20/aclocal.m4 +0 -1193
  52. data/ext/libusb-1.0.20/android/README +0 -114
  53. data/ext/libusb-1.0.20/android/config.h +0 -81
  54. data/ext/libusb-1.0.20/android/jni/Android.mk +0 -23
  55. data/ext/libusb-1.0.20/android/jni/Application.mk +0 -24
  56. data/ext/libusb-1.0.20/android/jni/examples.mk +0 -134
  57. data/ext/libusb-1.0.20/android/jni/libusb.mk +0 -54
  58. data/ext/libusb-1.0.20/android/jni/tests.mk +0 -56
  59. data/ext/libusb-1.0.20/compile +0 -347
  60. data/ext/libusb-1.0.20/config.guess +0 -1421
  61. data/ext/libusb-1.0.20/config.h.in +0 -155
  62. data/ext/libusb-1.0.20/config.sub +0 -1807
  63. data/ext/libusb-1.0.20/configure +0 -15466
  64. data/ext/libusb-1.0.20/configure.ac +0 -326
  65. data/ext/libusb-1.0.20/depcomp +0 -791
  66. data/ext/libusb-1.0.20/doc/Makefile.am +0 -9
  67. data/ext/libusb-1.0.20/doc/Makefile.in +0 -456
  68. data/ext/libusb-1.0.20/doc/doxygen.cfg.in +0 -2334
  69. data/ext/libusb-1.0.20/examples/Makefile.am +0 -19
  70. data/ext/libusb-1.0.20/examples/Makefile.in +0 -713
  71. data/ext/libusb-1.0.20/examples/dpfp.c +0 -506
  72. data/ext/libusb-1.0.20/examples/dpfp_threaded.c +0 -549
  73. data/ext/libusb-1.0.20/examples/ezusb.c +0 -831
  74. data/ext/libusb-1.0.20/examples/ezusb.h +0 -120
  75. data/ext/libusb-1.0.20/examples/fxload.c +0 -308
  76. data/ext/libusb-1.0.20/examples/getopt/getopt.c +0 -1060
  77. data/ext/libusb-1.0.20/examples/getopt/getopt.h +0 -180
  78. data/ext/libusb-1.0.20/examples/getopt/getopt1.c +0 -188
  79. data/ext/libusb-1.0.20/examples/hotplugtest.c +0 -122
  80. data/ext/libusb-1.0.20/examples/listdevs.c +0 -71
  81. data/ext/libusb-1.0.20/examples/sam3u_benchmark.c +0 -193
  82. data/ext/libusb-1.0.20/examples/xusb.c +0 -1130
  83. data/ext/libusb-1.0.20/install-sh +0 -501
  84. data/ext/libusb-1.0.20/libusb-1.0.pc.in +0 -11
  85. data/ext/libusb-1.0.20/libusb/Makefile.am +0 -90
  86. data/ext/libusb-1.0.20/libusb/Makefile.in +0 -1053
  87. data/ext/libusb-1.0.20/libusb/core.c +0 -2452
  88. data/ext/libusb-1.0.20/libusb/descriptor.c +0 -1201
  89. data/ext/libusb-1.0.20/libusb/hotplug.c +0 -344
  90. data/ext/libusb-1.0.20/libusb/hotplug.h +0 -90
  91. data/ext/libusb-1.0.20/libusb/io.c +0 -2760
  92. data/ext/libusb-1.0.20/libusb/libusb-1.0.def +0 -168
  93. data/ext/libusb-1.0.20/libusb/libusb-1.0.rc +0 -61
  94. data/ext/libusb-1.0.20/libusb/libusb.h +0 -1999
  95. data/ext/libusb-1.0.20/libusb/libusbi.h +0 -1102
  96. data/ext/libusb-1.0.20/libusb/os/darwin_usb.c +0 -1969
  97. data/ext/libusb-1.0.20/libusb/os/darwin_usb.h +0 -158
  98. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +0 -5
  99. data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +0 -810
  100. data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +0 -1193
  101. data/ext/libusb-1.0.20/libusb/os/haiku/compile +0 -347
  102. data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +0 -1421
  103. data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +0 -1807
  104. data/ext/libusb-1.0.20/libusb/os/haiku/configure +0 -17579
  105. data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +0 -8
  106. data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +0 -791
  107. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +0 -378
  108. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +0 -112
  109. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +0 -550
  110. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +0 -255
  111. data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +0 -180
  112. data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +0 -501
  113. data/ext/libusb-1.0.20/libusb/os/haiku/ltmain.sh +0 -9655
  114. data/ext/libusb-1.0.20/libusb/os/haiku/m4/libtool.m4 +0 -7992
  115. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltoptions.m4 +0 -384
  116. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltsugar.m4 +0 -123
  117. data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltversion.m4 +0 -23
  118. data/ext/libusb-1.0.20/libusb/os/haiku/m4/lt~obsolete.m4 +0 -98
  119. data/ext/libusb-1.0.20/libusb/os/haiku/missing +0 -215
  120. data/ext/libusb-1.0.20/libusb/os/linux_netlink.c +0 -369
  121. data/ext/libusb-1.0.20/libusb/os/linux_udev.c +0 -306
  122. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.c +0 -2692
  123. data/ext/libusb-1.0.20/libusb/os/linux_usbfs.h +0 -192
  124. data/ext/libusb-1.0.20/libusb/os/netbsd_usb.c +0 -674
  125. data/ext/libusb-1.0.20/libusb/os/openbsd_usb.c +0 -768
  126. data/ext/libusb-1.0.20/libusb/os/poll_posix.c +0 -53
  127. data/ext/libusb-1.0.20/libusb/os/poll_posix.h +0 -11
  128. data/ext/libusb-1.0.20/libusb/os/poll_windows.c +0 -728
  129. data/ext/libusb-1.0.20/libusb/os/poll_windows.h +0 -131
  130. data/ext/libusb-1.0.20/libusb/os/threads_posix.c +0 -82
  131. data/ext/libusb-1.0.20/libusb/os/threads_posix.h +0 -50
  132. data/ext/libusb-1.0.20/libusb/os/threads_windows.c +0 -214
  133. data/ext/libusb-1.0.20/libusb/os/threads_windows.h +0 -87
  134. data/ext/libusb-1.0.20/libusb/os/wince_usb.c +0 -869
  135. data/ext/libusb-1.0.20/libusb/os/wince_usb.h +0 -131
  136. data/ext/libusb-1.0.20/libusb/os/windows_common.h +0 -108
  137. data/ext/libusb-1.0.20/libusb/os/windows_usb.c +0 -4643
  138. data/ext/libusb-1.0.20/libusb/os/windows_usb.h +0 -973
  139. data/ext/libusb-1.0.20/libusb/strerror.c +0 -202
  140. data/ext/libusb-1.0.20/libusb/sync.c +0 -308
  141. data/ext/libusb-1.0.20/libusb/version.h +0 -18
  142. data/ext/libusb-1.0.20/libusb/version_nano.h +0 -1
  143. data/ext/libusb-1.0.20/ltmain.sh +0 -9655
  144. data/ext/libusb-1.0.20/m4/libtool.m4 +0 -7992
  145. data/ext/libusb-1.0.20/m4/ltoptions.m4 +0 -384
  146. data/ext/libusb-1.0.20/m4/ltsugar.m4 +0 -123
  147. data/ext/libusb-1.0.20/m4/ltversion.m4 +0 -23
  148. data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +0 -98
  149. data/ext/libusb-1.0.20/missing +0 -215
  150. data/ext/libusb-1.0.20/tests/Makefile.am +0 -6
  151. data/ext/libusb-1.0.20/tests/Makefile.in +0 -596
  152. data/ext/libusb-1.0.20/tests/libusb_testlib.h +0 -107
  153. data/ext/libusb-1.0.20/tests/stress.c +0 -160
  154. data/ext/libusb-1.0.20/tests/testlib.c +0 -277
  155. metadata.gz.sig +0 -0
@@ -1,192 +0,0 @@
1
- /*
2
- * usbfs header structures
3
- * Copyright © 2007 Daniel Drake <dsd@gentoo.org>
4
- * Copyright © 2001 Johannes Erdfelt <johannes@erdfelt.com>
5
- *
6
- * This library is free software; you can redistribute it and/or
7
- * modify it under the terms of the GNU Lesser General Public
8
- * License as published by the Free Software Foundation; either
9
- * version 2.1 of the License, or (at your option) any later version.
10
- *
11
- * This library is distributed in the hope that it will be useful,
12
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
- * Lesser General Public License for more details.
15
- *
16
- * You should have received a copy of the GNU Lesser General Public
17
- * License along with this library; if not, write to the Free Software
18
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
- */
20
-
21
- #ifndef LIBUSB_USBFS_H
22
- #define LIBUSB_USBFS_H
23
-
24
- #include <linux/types.h>
25
-
26
- #define SYSFS_DEVICE_PATH "/sys/bus/usb/devices"
27
-
28
- struct usbfs_ctrltransfer {
29
- /* keep in sync with usbdevice_fs.h:usbdevfs_ctrltransfer */
30
- uint8_t bmRequestType;
31
- uint8_t bRequest;
32
- uint16_t wValue;
33
- uint16_t wIndex;
34
- uint16_t wLength;
35
-
36
- uint32_t timeout; /* in milliseconds */
37
-
38
- /* pointer to data */
39
- void *data;
40
- };
41
-
42
- struct usbfs_bulktransfer {
43
- /* keep in sync with usbdevice_fs.h:usbdevfs_bulktransfer */
44
- unsigned int ep;
45
- unsigned int len;
46
- unsigned int timeout; /* in milliseconds */
47
-
48
- /* pointer to data */
49
- void *data;
50
- };
51
-
52
- struct usbfs_setinterface {
53
- /* keep in sync with usbdevice_fs.h:usbdevfs_setinterface */
54
- unsigned int interface;
55
- unsigned int altsetting;
56
- };
57
-
58
- #define USBFS_MAXDRIVERNAME 255
59
-
60
- struct usbfs_getdriver {
61
- unsigned int interface;
62
- char driver[USBFS_MAXDRIVERNAME + 1];
63
- };
64
-
65
- #define USBFS_URB_SHORT_NOT_OK 0x01
66
- #define USBFS_URB_ISO_ASAP 0x02
67
- #define USBFS_URB_BULK_CONTINUATION 0x04
68
- #define USBFS_URB_QUEUE_BULK 0x10
69
- #define USBFS_URB_ZERO_PACKET 0x40
70
-
71
- enum usbfs_urb_type {
72
- USBFS_URB_TYPE_ISO = 0,
73
- USBFS_URB_TYPE_INTERRUPT = 1,
74
- USBFS_URB_TYPE_CONTROL = 2,
75
- USBFS_URB_TYPE_BULK = 3,
76
- };
77
-
78
- struct usbfs_iso_packet_desc {
79
- unsigned int length;
80
- unsigned int actual_length;
81
- unsigned int status;
82
- };
83
-
84
- #define MAX_ISO_BUFFER_LENGTH 49152 * 128
85
- #define MAX_BULK_BUFFER_LENGTH 16384
86
- #define MAX_CTRL_BUFFER_LENGTH 4096
87
-
88
- struct usbfs_urb {
89
- unsigned char type;
90
- unsigned char endpoint;
91
- int status;
92
- unsigned int flags;
93
- void *buffer;
94
- int buffer_length;
95
- int actual_length;
96
- int start_frame;
97
- union {
98
- int number_of_packets; /* Only used for isoc urbs */
99
- unsigned int stream_id; /* Only used with bulk streams */
100
- };
101
- int error_count;
102
- unsigned int signr;
103
- void *usercontext;
104
- struct usbfs_iso_packet_desc iso_frame_desc[0];
105
- };
106
-
107
- struct usbfs_connectinfo {
108
- unsigned int devnum;
109
- unsigned char slow;
110
- };
111
-
112
- struct usbfs_ioctl {
113
- int ifno; /* interface 0..N ; negative numbers reserved */
114
- int ioctl_code; /* MUST encode size + direction of data so the
115
- * macros in <asm/ioctl.h> give correct values */
116
- void *data; /* param buffer (in, or out) */
117
- };
118
-
119
- struct usbfs_hub_portinfo {
120
- unsigned char numports;
121
- unsigned char port[127]; /* port to device num mapping */
122
- };
123
-
124
- #define USBFS_CAP_ZERO_PACKET 0x01
125
- #define USBFS_CAP_BULK_CONTINUATION 0x02
126
- #define USBFS_CAP_NO_PACKET_SIZE_LIM 0x04
127
- #define USBFS_CAP_BULK_SCATTER_GATHER 0x08
128
-
129
- #define USBFS_DISCONNECT_CLAIM_IF_DRIVER 0x01
130
- #define USBFS_DISCONNECT_CLAIM_EXCEPT_DRIVER 0x02
131
-
132
- struct usbfs_disconnect_claim {
133
- unsigned int interface;
134
- unsigned int flags;
135
- char driver[USBFS_MAXDRIVERNAME + 1];
136
- };
137
-
138
- struct usbfs_streams {
139
- unsigned int num_streams; /* Not used by USBDEVFS_FREE_STREAMS */
140
- unsigned int num_eps;
141
- unsigned char eps[0];
142
- };
143
-
144
- #define IOCTL_USBFS_CONTROL _IOWR('U', 0, struct usbfs_ctrltransfer)
145
- #define IOCTL_USBFS_BULK _IOWR('U', 2, struct usbfs_bulktransfer)
146
- #define IOCTL_USBFS_RESETEP _IOR('U', 3, unsigned int)
147
- #define IOCTL_USBFS_SETINTF _IOR('U', 4, struct usbfs_setinterface)
148
- #define IOCTL_USBFS_SETCONFIG _IOR('U', 5, unsigned int)
149
- #define IOCTL_USBFS_GETDRIVER _IOW('U', 8, struct usbfs_getdriver)
150
- #define IOCTL_USBFS_SUBMITURB _IOR('U', 10, struct usbfs_urb)
151
- #define IOCTL_USBFS_DISCARDURB _IO('U', 11)
152
- #define IOCTL_USBFS_REAPURB _IOW('U', 12, void *)
153
- #define IOCTL_USBFS_REAPURBNDELAY _IOW('U', 13, void *)
154
- #define IOCTL_USBFS_CLAIMINTF _IOR('U', 15, unsigned int)
155
- #define IOCTL_USBFS_RELEASEINTF _IOR('U', 16, unsigned int)
156
- #define IOCTL_USBFS_CONNECTINFO _IOW('U', 17, struct usbfs_connectinfo)
157
- #define IOCTL_USBFS_IOCTL _IOWR('U', 18, struct usbfs_ioctl)
158
- #define IOCTL_USBFS_HUB_PORTINFO _IOR('U', 19, struct usbfs_hub_portinfo)
159
- #define IOCTL_USBFS_RESET _IO('U', 20)
160
- #define IOCTL_USBFS_CLEAR_HALT _IOR('U', 21, unsigned int)
161
- #define IOCTL_USBFS_DISCONNECT _IO('U', 22)
162
- #define IOCTL_USBFS_CONNECT _IO('U', 23)
163
- #define IOCTL_USBFS_CLAIM_PORT _IOR('U', 24, unsigned int)
164
- #define IOCTL_USBFS_RELEASE_PORT _IOR('U', 25, unsigned int)
165
- #define IOCTL_USBFS_GET_CAPABILITIES _IOR('U', 26, __u32)
166
- #define IOCTL_USBFS_DISCONNECT_CLAIM _IOR('U', 27, struct usbfs_disconnect_claim)
167
- #define IOCTL_USBFS_ALLOC_STREAMS _IOR('U', 28, struct usbfs_streams)
168
- #define IOCTL_USBFS_FREE_STREAMS _IOR('U', 29, struct usbfs_streams)
169
-
170
- extern usbi_mutex_static_t linux_hotplug_lock;
171
-
172
- #if defined(HAVE_LIBUDEV)
173
- int linux_udev_start_event_monitor(void);
174
- int linux_udev_stop_event_monitor(void);
175
- int linux_udev_scan_devices(struct libusb_context *ctx);
176
- void linux_udev_hotplug_poll(void);
177
- #else
178
- int linux_netlink_start_event_monitor(void);
179
- int linux_netlink_stop_event_monitor(void);
180
- void linux_netlink_hotplug_poll(void);
181
- #endif
182
-
183
- 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);
185
-
186
- int linux_get_device_address (struct libusb_context *ctx, int detached,
187
- uint8_t *busnum, uint8_t *devaddr, const char *dev_node,
188
- const char *sys_name);
189
- int linux_enumerate_device(struct libusb_context *ctx,
190
- uint8_t busnum, uint8_t devaddr, const char *sysfs_dir);
191
-
192
- #endif
@@ -1,674 +0,0 @@
1
- /*
2
- * Copyright © 2011 Martin Pieuchot <mpi@openbsd.org>
3
- *
4
- * This library is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU Lesser General Public
6
- * License as published by the Free Software Foundation; either
7
- * version 2.1 of the License, or (at your option) any later version.
8
- *
9
- * This library is distributed in the hope that it will be useful,
10
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
- * Lesser General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU Lesser General Public
15
- * License along with this library; if not, write to the Free Software
16
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
- */
18
-
19
- #include <config.h>
20
-
21
- #include <sys/time.h>
22
- #include <sys/types.h>
23
-
24
- #include <errno.h>
25
- #include <fcntl.h>
26
- #include <stdio.h>
27
- #include <stdlib.h>
28
- #include <string.h>
29
- #include <unistd.h>
30
-
31
- #include <dev/usb/usb.h>
32
-
33
- #include "libusbi.h"
34
-
35
- struct device_priv {
36
- char devnode[16];
37
- int fd;
38
-
39
- unsigned char *cdesc; /* active config descriptor */
40
- usb_device_descriptor_t ddesc; /* usb device descriptor */
41
- };
42
-
43
- struct handle_priv {
44
- int endpoints[USB_MAX_ENDPOINTS];
45
- };
46
-
47
- /*
48
- * Backend functions
49
- */
50
- static int netbsd_get_device_list(struct libusb_context *,
51
- struct discovered_devs **);
52
- static int netbsd_open(struct libusb_device_handle *);
53
- static void netbsd_close(struct libusb_device_handle *);
54
-
55
- static int netbsd_get_device_descriptor(struct libusb_device *, unsigned char *,
56
- int *);
57
- static int netbsd_get_active_config_descriptor(struct libusb_device *,
58
- unsigned char *, size_t, int *);
59
- static int netbsd_get_config_descriptor(struct libusb_device *, uint8_t,
60
- unsigned char *, size_t, int *);
61
-
62
- static int netbsd_get_configuration(struct libusb_device_handle *, int *);
63
- static int netbsd_set_configuration(struct libusb_device_handle *, int);
64
-
65
- static int netbsd_claim_interface(struct libusb_device_handle *, int);
66
- static int netbsd_release_interface(struct libusb_device_handle *, int);
67
-
68
- static int netbsd_set_interface_altsetting(struct libusb_device_handle *, int,
69
- int);
70
- static int netbsd_clear_halt(struct libusb_device_handle *, unsigned char);
71
- static int netbsd_reset_device(struct libusb_device_handle *);
72
- static void netbsd_destroy_device(struct libusb_device *);
73
-
74
- static int netbsd_submit_transfer(struct usbi_transfer *);
75
- static int netbsd_cancel_transfer(struct usbi_transfer *);
76
- static void netbsd_clear_transfer_priv(struct usbi_transfer *);
77
- static int netbsd_handle_transfer_completion(struct usbi_transfer *);
78
- static int netbsd_clock_gettime(int, struct timespec *);
79
-
80
- /*
81
- * Private functions
82
- */
83
- static int _errno_to_libusb(int);
84
- static int _cache_active_config_descriptor(struct libusb_device *, int);
85
- static int _sync_control_transfer(struct usbi_transfer *);
86
- static int _sync_gen_transfer(struct usbi_transfer *);
87
- static int _access_endpoint(struct libusb_transfer *);
88
-
89
- const struct usbi_os_backend netbsd_backend = {
90
- "Synchronous NetBSD backend",
91
- 0,
92
- NULL, /* init() */
93
- NULL, /* exit() */
94
- netbsd_get_device_list,
95
- NULL, /* hotplug_poll */
96
- netbsd_open,
97
- netbsd_close,
98
-
99
- netbsd_get_device_descriptor,
100
- netbsd_get_active_config_descriptor,
101
- netbsd_get_config_descriptor,
102
- NULL, /* get_config_descriptor_by_value() */
103
-
104
- netbsd_get_configuration,
105
- netbsd_set_configuration,
106
-
107
- netbsd_claim_interface,
108
- netbsd_release_interface,
109
-
110
- netbsd_set_interface_altsetting,
111
- netbsd_clear_halt,
112
- netbsd_reset_device,
113
-
114
- NULL, /* alloc_streams */
115
- NULL, /* free_streams */
116
-
117
- NULL, /* kernel_driver_active() */
118
- NULL, /* detach_kernel_driver() */
119
- NULL, /* attach_kernel_driver() */
120
-
121
- netbsd_destroy_device,
122
-
123
- netbsd_submit_transfer,
124
- netbsd_cancel_transfer,
125
- netbsd_clear_transfer_priv,
126
-
127
- NULL, /* handle_events() */
128
- netbsd_handle_transfer_completion,
129
-
130
- netbsd_clock_gettime,
131
- sizeof(struct device_priv),
132
- sizeof(struct handle_priv),
133
- 0, /* transfer_priv_size */
134
- };
135
-
136
- int
137
- netbsd_get_device_list(struct libusb_context * ctx,
138
- struct discovered_devs **discdevs)
139
- {
140
- struct libusb_device *dev;
141
- struct device_priv *dpriv;
142
- struct usb_device_info di;
143
- unsigned long session_id;
144
- char devnode[16];
145
- int fd, err, i;
146
-
147
- usbi_dbg("");
148
-
149
- /* Only ugen(4) is supported */
150
- for (i = 0; i < USB_MAX_DEVICES; i++) {
151
- /* Control endpoint is always .00 */
152
- snprintf(devnode, sizeof(devnode), "/dev/ugen%d.00", i);
153
-
154
- if ((fd = open(devnode, O_RDONLY)) < 0) {
155
- if (errno != ENOENT && errno != ENXIO)
156
- usbi_err(ctx, "could not open %s", devnode);
157
- continue;
158
- }
159
-
160
- if (ioctl(fd, USB_GET_DEVICEINFO, &di) < 0)
161
- continue;
162
-
163
- session_id = (di.udi_bus << 8 | di.udi_addr);
164
- dev = usbi_get_device_by_session_id(ctx, session_id);
165
-
166
- if (dev == NULL) {
167
- dev = usbi_alloc_device(ctx, session_id);
168
- if (dev == NULL)
169
- return (LIBUSB_ERROR_NO_MEM);
170
-
171
- dev->bus_number = di.udi_bus;
172
- dev->device_address = di.udi_addr;
173
- dev->speed = di.udi_speed;
174
-
175
- dpriv = (struct device_priv *)dev->os_priv;
176
- strlcpy(dpriv->devnode, devnode, sizeof(devnode));
177
- dpriv->fd = -1;
178
-
179
- if (ioctl(fd, USB_GET_DEVICE_DESC, &dpriv->ddesc) < 0) {
180
- err = errno;
181
- goto error;
182
- }
183
-
184
- dpriv->cdesc = NULL;
185
- if (_cache_active_config_descriptor(dev, fd)) {
186
- err = errno;
187
- goto error;
188
- }
189
-
190
- if ((err = usbi_sanitize_device(dev)))
191
- goto error;
192
- }
193
- close(fd);
194
-
195
- if (discovered_devs_append(*discdevs, dev) == NULL)
196
- return (LIBUSB_ERROR_NO_MEM);
197
-
198
- libusb_unref_device(dev);
199
- }
200
-
201
- return (LIBUSB_SUCCESS);
202
-
203
- error:
204
- close(fd);
205
- libusb_unref_device(dev);
206
- return _errno_to_libusb(err);
207
- }
208
-
209
- int
210
- netbsd_open(struct libusb_device_handle *handle)
211
- {
212
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
213
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
214
-
215
- dpriv->fd = open(dpriv->devnode, O_RDWR);
216
- if (dpriv->fd < 0) {
217
- dpriv->fd = open(dpriv->devnode, O_RDONLY);
218
- if (dpriv->fd < 0)
219
- return _errno_to_libusb(errno);
220
- }
221
-
222
- usbi_dbg("open %s: fd %d", dpriv->devnode, dpriv->fd);
223
-
224
- return (LIBUSB_SUCCESS);
225
- }
226
-
227
- void
228
- netbsd_close(struct libusb_device_handle *handle)
229
- {
230
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
231
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
232
-
233
- usbi_dbg("close: fd %d", dpriv->fd);
234
-
235
- close(dpriv->fd);
236
- dpriv->fd = -1;
237
- }
238
-
239
- int
240
- netbsd_get_device_descriptor(struct libusb_device *dev, unsigned char *buf,
241
- int *host_endian)
242
- {
243
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
244
-
245
- usbi_dbg("");
246
-
247
- memcpy(buf, &dpriv->ddesc, DEVICE_DESC_LENGTH);
248
-
249
- *host_endian = 0;
250
-
251
- return (LIBUSB_SUCCESS);
252
- }
253
-
254
- int
255
- netbsd_get_active_config_descriptor(struct libusb_device *dev,
256
- unsigned char *buf, size_t len, int *host_endian)
257
- {
258
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
259
- usb_config_descriptor_t *ucd;
260
-
261
- ucd = (usb_config_descriptor_t *) dpriv->cdesc;
262
- len = MIN(len, UGETW(ucd->wTotalLength));
263
-
264
- usbi_dbg("len %d", len);
265
-
266
- memcpy(buf, dpriv->cdesc, len);
267
-
268
- *host_endian = 0;
269
-
270
- return len;
271
- }
272
-
273
- int
274
- netbsd_get_config_descriptor(struct libusb_device *dev, uint8_t idx,
275
- unsigned char *buf, size_t len, int *host_endian)
276
- {
277
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
278
- struct usb_full_desc ufd;
279
- int fd, err;
280
-
281
- usbi_dbg("index %d, len %d", idx, len);
282
-
283
- /* A config descriptor may be requested before opening the device */
284
- if (dpriv->fd >= 0) {
285
- fd = dpriv->fd;
286
- } else {
287
- fd = open(dpriv->devnode, O_RDONLY);
288
- if (fd < 0)
289
- return _errno_to_libusb(errno);
290
- }
291
-
292
- ufd.ufd_config_index = idx;
293
- ufd.ufd_size = len;
294
- ufd.ufd_data = buf;
295
-
296
- if ((ioctl(fd, USB_GET_FULL_DESC, &ufd)) < 0) {
297
- err = errno;
298
- if (dpriv->fd < 0)
299
- close(fd);
300
- return _errno_to_libusb(err);
301
- }
302
-
303
- if (dpriv->fd < 0)
304
- close(fd);
305
-
306
- *host_endian = 0;
307
-
308
- return len;
309
- }
310
-
311
- int
312
- netbsd_get_configuration(struct libusb_device_handle *handle, int *config)
313
- {
314
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
315
-
316
- usbi_dbg("");
317
-
318
- if (ioctl(dpriv->fd, USB_GET_CONFIG, config) < 0)
319
- return _errno_to_libusb(errno);
320
-
321
- usbi_dbg("configuration %d", *config);
322
-
323
- return (LIBUSB_SUCCESS);
324
- }
325
-
326
- int
327
- netbsd_set_configuration(struct libusb_device_handle *handle, int config)
328
- {
329
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
330
-
331
- usbi_dbg("configuration %d", config);
332
-
333
- if (ioctl(dpriv->fd, USB_SET_CONFIG, &config) < 0)
334
- return _errno_to_libusb(errno);
335
-
336
- return _cache_active_config_descriptor(handle->dev, dpriv->fd);
337
- }
338
-
339
- int
340
- netbsd_claim_interface(struct libusb_device_handle *handle, int iface)
341
- {
342
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
343
- int i;
344
-
345
- for (i = 0; i < USB_MAX_ENDPOINTS; i++)
346
- hpriv->endpoints[i] = -1;
347
-
348
- return (LIBUSB_SUCCESS);
349
- }
350
-
351
- int
352
- netbsd_release_interface(struct libusb_device_handle *handle, int iface)
353
- {
354
- struct handle_priv *hpriv = (struct handle_priv *)handle->os_priv;
355
- int i;
356
-
357
- for (i = 0; i < USB_MAX_ENDPOINTS; i++)
358
- if (hpriv->endpoints[i] >= 0)
359
- close(hpriv->endpoints[i]);
360
-
361
- return (LIBUSB_SUCCESS);
362
- }
363
-
364
- int
365
- netbsd_set_interface_altsetting(struct libusb_device_handle *handle, int iface,
366
- int altsetting)
367
- {
368
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
369
- struct usb_alt_interface intf;
370
-
371
- usbi_dbg("iface %d, setting %d", iface, altsetting);
372
-
373
- memset(&intf, 0, sizeof(intf));
374
-
375
- intf.uai_interface_index = iface;
376
- intf.uai_alt_no = altsetting;
377
-
378
- if (ioctl(dpriv->fd, USB_SET_ALTINTERFACE, &intf) < 0)
379
- return _errno_to_libusb(errno);
380
-
381
- return (LIBUSB_SUCCESS);
382
- }
383
-
384
- int
385
- netbsd_clear_halt(struct libusb_device_handle *handle, unsigned char endpoint)
386
- {
387
- struct device_priv *dpriv = (struct device_priv *)handle->dev->os_priv;
388
- struct usb_ctl_request req;
389
-
390
- usbi_dbg("");
391
-
392
- req.ucr_request.bmRequestType = UT_WRITE_ENDPOINT;
393
- req.ucr_request.bRequest = UR_CLEAR_FEATURE;
394
- USETW(req.ucr_request.wValue, UF_ENDPOINT_HALT);
395
- USETW(req.ucr_request.wIndex, endpoint);
396
- USETW(req.ucr_request.wLength, 0);
397
-
398
- if (ioctl(dpriv->fd, USB_DO_REQUEST, &req) < 0)
399
- return _errno_to_libusb(errno);
400
-
401
- return (LIBUSB_SUCCESS);
402
- }
403
-
404
- int
405
- netbsd_reset_device(struct libusb_device_handle *handle)
406
- {
407
- usbi_dbg("");
408
-
409
- return (LIBUSB_ERROR_NOT_SUPPORTED);
410
- }
411
-
412
- void
413
- netbsd_destroy_device(struct libusb_device *dev)
414
- {
415
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
416
-
417
- usbi_dbg("");
418
-
419
- free(dpriv->cdesc);
420
- }
421
-
422
- int
423
- netbsd_submit_transfer(struct usbi_transfer *itransfer)
424
- {
425
- struct libusb_transfer *transfer;
426
- struct handle_priv *hpriv;
427
- int err = 0;
428
-
429
- usbi_dbg("");
430
-
431
- transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
432
- hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
433
-
434
- switch (transfer->type) {
435
- case LIBUSB_TRANSFER_TYPE_CONTROL:
436
- err = _sync_control_transfer(itransfer);
437
- break;
438
- case LIBUSB_TRANSFER_TYPE_ISOCHRONOUS:
439
- if (IS_XFEROUT(transfer)) {
440
- /* Isochronous write is not supported */
441
- err = LIBUSB_ERROR_NOT_SUPPORTED;
442
- break;
443
- }
444
- err = _sync_gen_transfer(itransfer);
445
- break;
446
- case LIBUSB_TRANSFER_TYPE_BULK:
447
- case LIBUSB_TRANSFER_TYPE_INTERRUPT:
448
- if (IS_XFEROUT(transfer) &&
449
- transfer->flags & LIBUSB_TRANSFER_ADD_ZERO_PACKET) {
450
- err = LIBUSB_ERROR_NOT_SUPPORTED;
451
- break;
452
- }
453
- err = _sync_gen_transfer(itransfer);
454
- break;
455
- case LIBUSB_TRANSFER_TYPE_BULK_STREAM:
456
- err = LIBUSB_ERROR_NOT_SUPPORTED;
457
- break;
458
- }
459
-
460
- if (err)
461
- return (err);
462
-
463
- usbi_signal_transfer_completion(itransfer);
464
-
465
- return (LIBUSB_SUCCESS);
466
- }
467
-
468
- int
469
- netbsd_cancel_transfer(struct usbi_transfer *itransfer)
470
- {
471
- usbi_dbg("");
472
-
473
- return (LIBUSB_ERROR_NOT_SUPPORTED);
474
- }
475
-
476
- void
477
- netbsd_clear_transfer_priv(struct usbi_transfer *itransfer)
478
- {
479
- usbi_dbg("");
480
-
481
- /* Nothing to do */
482
- }
483
-
484
- int
485
- netbsd_handle_transfer_completion(struct usbi_transfer *itransfer)
486
- {
487
- return usbi_handle_transfer_completion(itransfer, LIBUSB_TRANSFER_COMPLETED);
488
- }
489
-
490
- int
491
- netbsd_clock_gettime(int clkid, struct timespec *tp)
492
- {
493
- usbi_dbg("clock %d", clkid);
494
-
495
- if (clkid == USBI_CLOCK_REALTIME)
496
- return clock_gettime(CLOCK_REALTIME, tp);
497
-
498
- if (clkid == USBI_CLOCK_MONOTONIC)
499
- return clock_gettime(CLOCK_MONOTONIC, tp);
500
-
501
- return (LIBUSB_ERROR_INVALID_PARAM);
502
- }
503
-
504
- int
505
- _errno_to_libusb(int err)
506
- {
507
- switch (err) {
508
- case EIO:
509
- return (LIBUSB_ERROR_IO);
510
- case EACCES:
511
- return (LIBUSB_ERROR_ACCESS);
512
- case ENOENT:
513
- return (LIBUSB_ERROR_NO_DEVICE);
514
- case ENOMEM:
515
- return (LIBUSB_ERROR_NO_MEM);
516
- }
517
-
518
- usbi_dbg("error: %s", strerror(err));
519
-
520
- return (LIBUSB_ERROR_OTHER);
521
- }
522
-
523
- int
524
- _cache_active_config_descriptor(struct libusb_device *dev, int fd)
525
- {
526
- struct device_priv *dpriv = (struct device_priv *)dev->os_priv;
527
- struct usb_config_desc ucd;
528
- struct usb_full_desc ufd;
529
- unsigned char* buf;
530
- int len;
531
-
532
- usbi_dbg("fd %d", fd);
533
-
534
- ucd.ucd_config_index = USB_CURRENT_CONFIG_INDEX;
535
-
536
- if ((ioctl(fd, USB_GET_CONFIG_DESC, &ucd)) < 0)
537
- return _errno_to_libusb(errno);
538
-
539
- usbi_dbg("active bLength %d", ucd.ucd_desc.bLength);
540
-
541
- len = UGETW(ucd.ucd_desc.wTotalLength);
542
- buf = malloc(len);
543
- if (buf == NULL)
544
- return (LIBUSB_ERROR_NO_MEM);
545
-
546
- ufd.ufd_config_index = ucd.ucd_config_index;
547
- ufd.ufd_size = len;
548
- ufd.ufd_data = buf;
549
-
550
- usbi_dbg("index %d, len %d", ufd.ufd_config_index, len);
551
-
552
- if ((ioctl(fd, USB_GET_FULL_DESC, &ufd)) < 0) {
553
- free(buf);
554
- return _errno_to_libusb(errno);
555
- }
556
-
557
- if (dpriv->cdesc)
558
- free(dpriv->cdesc);
559
- dpriv->cdesc = buf;
560
-
561
- return (0);
562
- }
563
-
564
- int
565
- _sync_control_transfer(struct usbi_transfer *itransfer)
566
- {
567
- struct libusb_transfer *transfer;
568
- struct libusb_control_setup *setup;
569
- struct device_priv *dpriv;
570
- struct usb_ctl_request req;
571
-
572
- transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
573
- dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
574
- setup = (struct libusb_control_setup *)transfer->buffer;
575
-
576
- usbi_dbg("type %d request %d value %d index %d length %d timeout %d",
577
- setup->bmRequestType, setup->bRequest,
578
- libusb_le16_to_cpu(setup->wValue),
579
- libusb_le16_to_cpu(setup->wIndex),
580
- libusb_le16_to_cpu(setup->wLength), transfer->timeout);
581
-
582
- req.ucr_request.bmRequestType = setup->bmRequestType;
583
- req.ucr_request.bRequest = setup->bRequest;
584
- /* Don't use USETW, libusb already deals with the endianness */
585
- (*(uint16_t *)req.ucr_request.wValue) = setup->wValue;
586
- (*(uint16_t *)req.ucr_request.wIndex) = setup->wIndex;
587
- (*(uint16_t *)req.ucr_request.wLength) = setup->wLength;
588
- req.ucr_data = transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE;
589
-
590
- if ((transfer->flags & LIBUSB_TRANSFER_SHORT_NOT_OK) == 0)
591
- req.ucr_flags = USBD_SHORT_XFER_OK;
592
-
593
- if ((ioctl(dpriv->fd, USB_SET_TIMEOUT, &transfer->timeout)) < 0)
594
- return _errno_to_libusb(errno);
595
-
596
- if ((ioctl(dpriv->fd, USB_DO_REQUEST, &req)) < 0)
597
- return _errno_to_libusb(errno);
598
-
599
- itransfer->transferred = req.ucr_actlen;
600
-
601
- usbi_dbg("transferred %d", itransfer->transferred);
602
-
603
- return (0);
604
- }
605
-
606
- int
607
- _access_endpoint(struct libusb_transfer *transfer)
608
- {
609
- struct handle_priv *hpriv;
610
- struct device_priv *dpriv;
611
- char *s, devnode[16];
612
- int fd, endpt;
613
- mode_t mode;
614
-
615
- hpriv = (struct handle_priv *)transfer->dev_handle->os_priv;
616
- dpriv = (struct device_priv *)transfer->dev_handle->dev->os_priv;
617
-
618
- endpt = UE_GET_ADDR(transfer->endpoint);
619
- mode = IS_XFERIN(transfer) ? O_RDONLY : O_WRONLY;
620
-
621
- usbi_dbg("endpoint %d mode %d", endpt, mode);
622
-
623
- if (hpriv->endpoints[endpt] < 0) {
624
- /* Pick the right node given the control one */
625
- strlcpy(devnode, dpriv->devnode, sizeof(devnode));
626
- s = strchr(devnode, '.');
627
- snprintf(s, 4, ".%02d", endpt);
628
-
629
- /* We may need to read/write to the same endpoint later. */
630
- if (((fd = open(devnode, O_RDWR)) < 0) && (errno == ENXIO))
631
- if ((fd = open(devnode, mode)) < 0)
632
- return (-1);
633
-
634
- hpriv->endpoints[endpt] = fd;
635
- }
636
-
637
- return (hpriv->endpoints[endpt]);
638
- }
639
-
640
- int
641
- _sync_gen_transfer(struct usbi_transfer *itransfer)
642
- {
643
- struct libusb_transfer *transfer;
644
- int fd, nr = 1;
645
-
646
- transfer = USBI_TRANSFER_TO_LIBUSB_TRANSFER(itransfer);
647
-
648
- /*
649
- * Bulk, Interrupt or Isochronous transfer depends on the
650
- * endpoint and thus the node to open.
651
- */
652
- if ((fd = _access_endpoint(transfer)) < 0)
653
- return _errno_to_libusb(errno);
654
-
655
- if ((ioctl(fd, USB_SET_TIMEOUT, &transfer->timeout)) < 0)
656
- return _errno_to_libusb(errno);
657
-
658
- if (IS_XFERIN(transfer)) {
659
- if ((transfer->flags & LIBUSB_TRANSFER_SHORT_NOT_OK) == 0)
660
- if ((ioctl(fd, USB_SET_SHORT_XFER, &nr)) < 0)
661
- return _errno_to_libusb(errno);
662
-
663
- nr = read(fd, transfer->buffer, transfer->length);
664
- } else {
665
- nr = write(fd, transfer->buffer, transfer->length);
666
- }
667
-
668
- if (nr < 0)
669
- return _errno_to_libusb(errno);
670
-
671
- itransfer->transferred = nr;
672
-
673
- return (0);
674
- }