libusb 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -2
- data/Gemfile +2 -0
- data/History.md +12 -0
- data/README.md +25 -14
- data/Rakefile +64 -109
- data/appveyor.yml +23 -0
- data/ext/extconf.rb +10 -12
- data/ext/libusb_recipe.rb +29 -0
- data/lib/libusb/call.rb +14 -11
- data/lib/libusb/compat.rb +9 -9
- data/lib/libusb/context.rb +16 -1
- data/lib/libusb/dependencies.rb +7 -0
- data/lib/libusb/dev_handle.rb +13 -3
- data/lib/libusb/eventmachine.rb +4 -4
- data/lib/libusb/transfer.rb +71 -10
- data/lib/libusb/version_gem.rb +1 -1
- data/libusb.gemspec +7 -5
- data/ports/archives/libusb-1.0.21.tar.bz2 +0 -0
- data/test/test_libusb_bulk_stream_transfer.rb +1 -1
- data/test/test_libusb_descriptors.rb +4 -4
- data/test/test_libusb_event_machine.rb +7 -7
- data/test/test_libusb_hotplug.rb +15 -3
- data/test/test_libusb_iso_transfer.rb +1 -1
- data/test/test_libusb_mass_storage.rb +19 -19
- data/test/test_libusb_mass_storage2.rb +1 -1
- data/test/test_libusb_structs.rb +13 -0
- data/test/test_libusb_threads.rb +2 -2
- data/wireshark-usb-sniffer.png +0 -0
- metadata +32 -156
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ext/libusb-1.0.20/AUTHORS +0 -89
- data/ext/libusb-1.0.20/COPYING +0 -504
- data/ext/libusb-1.0.20/ChangeLog +0 -227
- data/ext/libusb-1.0.20/INSTALL +0 -234
- data/ext/libusb-1.0.20/Makefile.am +0 -28
- data/ext/libusb-1.0.20/Makefile.in +0 -897
- data/ext/libusb-1.0.20/NEWS +0 -2
- data/ext/libusb-1.0.20/PORTING +0 -94
- data/ext/libusb-1.0.20/README +0 -29
- data/ext/libusb-1.0.20/TODO +0 -2
- data/ext/libusb-1.0.20/Xcode/common.xcconfig +0 -49
- data/ext/libusb-1.0.20/Xcode/config.h +0 -28
- data/ext/libusb-1.0.20/Xcode/debug.xcconfig +0 -29
- data/ext/libusb-1.0.20/Xcode/libusb.xcconfig +0 -21
- data/ext/libusb-1.0.20/Xcode/libusb.xcodeproj/project.pbxproj +0 -865
- data/ext/libusb-1.0.20/Xcode/libusb_debug.xcconfig +0 -21
- data/ext/libusb-1.0.20/Xcode/libusb_release.xcconfig +0 -21
- data/ext/libusb-1.0.20/Xcode/release.xcconfig +0 -30
- data/ext/libusb-1.0.20/aclocal.m4 +0 -1193
- data/ext/libusb-1.0.20/android/README +0 -114
- data/ext/libusb-1.0.20/android/config.h +0 -81
- data/ext/libusb-1.0.20/android/jni/Android.mk +0 -23
- data/ext/libusb-1.0.20/android/jni/Application.mk +0 -24
- data/ext/libusb-1.0.20/android/jni/examples.mk +0 -134
- data/ext/libusb-1.0.20/android/jni/libusb.mk +0 -54
- data/ext/libusb-1.0.20/android/jni/tests.mk +0 -56
- data/ext/libusb-1.0.20/compile +0 -347
- data/ext/libusb-1.0.20/config.guess +0 -1421
- data/ext/libusb-1.0.20/config.h.in +0 -155
- data/ext/libusb-1.0.20/config.sub +0 -1807
- data/ext/libusb-1.0.20/configure +0 -15466
- data/ext/libusb-1.0.20/configure.ac +0 -326
- data/ext/libusb-1.0.20/depcomp +0 -791
- data/ext/libusb-1.0.20/doc/Makefile.am +0 -9
- data/ext/libusb-1.0.20/doc/Makefile.in +0 -456
- data/ext/libusb-1.0.20/doc/doxygen.cfg.in +0 -2334
- data/ext/libusb-1.0.20/examples/Makefile.am +0 -19
- data/ext/libusb-1.0.20/examples/Makefile.in +0 -713
- data/ext/libusb-1.0.20/examples/dpfp.c +0 -506
- data/ext/libusb-1.0.20/examples/dpfp_threaded.c +0 -549
- data/ext/libusb-1.0.20/examples/ezusb.c +0 -831
- data/ext/libusb-1.0.20/examples/ezusb.h +0 -120
- data/ext/libusb-1.0.20/examples/fxload.c +0 -308
- data/ext/libusb-1.0.20/examples/getopt/getopt.c +0 -1060
- data/ext/libusb-1.0.20/examples/getopt/getopt.h +0 -180
- data/ext/libusb-1.0.20/examples/getopt/getopt1.c +0 -188
- data/ext/libusb-1.0.20/examples/hotplugtest.c +0 -122
- data/ext/libusb-1.0.20/examples/listdevs.c +0 -71
- data/ext/libusb-1.0.20/examples/sam3u_benchmark.c +0 -193
- data/ext/libusb-1.0.20/examples/xusb.c +0 -1130
- data/ext/libusb-1.0.20/install-sh +0 -501
- data/ext/libusb-1.0.20/libusb-1.0.pc.in +0 -11
- data/ext/libusb-1.0.20/libusb/Makefile.am +0 -90
- data/ext/libusb-1.0.20/libusb/Makefile.in +0 -1053
- data/ext/libusb-1.0.20/libusb/core.c +0 -2452
- data/ext/libusb-1.0.20/libusb/descriptor.c +0 -1201
- data/ext/libusb-1.0.20/libusb/hotplug.c +0 -344
- data/ext/libusb-1.0.20/libusb/hotplug.h +0 -90
- data/ext/libusb-1.0.20/libusb/io.c +0 -2760
- data/ext/libusb-1.0.20/libusb/libusb-1.0.def +0 -168
- data/ext/libusb-1.0.20/libusb/libusb-1.0.rc +0 -61
- data/ext/libusb-1.0.20/libusb/libusb.h +0 -1999
- data/ext/libusb-1.0.20/libusb/libusbi.h +0 -1102
- data/ext/libusb-1.0.20/libusb/os/darwin_usb.c +0 -1969
- data/ext/libusb-1.0.20/libusb/os/darwin_usb.h +0 -158
- data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.am +0 -5
- data/ext/libusb-1.0.20/libusb/os/haiku/Makefile.in +0 -810
- data/ext/libusb-1.0.20/libusb/os/haiku/aclocal.m4 +0 -1193
- data/ext/libusb-1.0.20/libusb/os/haiku/compile +0 -347
- data/ext/libusb-1.0.20/libusb/os/haiku/config.guess +0 -1421
- data/ext/libusb-1.0.20/libusb/os/haiku/config.sub +0 -1807
- data/ext/libusb-1.0.20/libusb/os/haiku/configure +0 -17579
- data/ext/libusb-1.0.20/libusb/os/haiku/configure.ac +0 -8
- data/ext/libusb-1.0.20/libusb/os/haiku/depcomp +0 -791
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_pollfs.cpp +0 -378
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb.h +0 -112
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_backend.cpp +0 -550
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.cpp +0 -255
- data/ext/libusb-1.0.20/libusb/os/haiku/haiku_usb_raw.h +0 -180
- data/ext/libusb-1.0.20/libusb/os/haiku/install-sh +0 -501
- data/ext/libusb-1.0.20/libusb/os/haiku/ltmain.sh +0 -9655
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/libtool.m4 +0 -7992
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltoptions.m4 +0 -384
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltsugar.m4 +0 -123
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/ltversion.m4 +0 -23
- data/ext/libusb-1.0.20/libusb/os/haiku/m4/lt~obsolete.m4 +0 -98
- data/ext/libusb-1.0.20/libusb/os/haiku/missing +0 -215
- data/ext/libusb-1.0.20/libusb/os/linux_netlink.c +0 -369
- data/ext/libusb-1.0.20/libusb/os/linux_udev.c +0 -306
- data/ext/libusb-1.0.20/libusb/os/linux_usbfs.c +0 -2692
- data/ext/libusb-1.0.20/libusb/os/linux_usbfs.h +0 -192
- data/ext/libusb-1.0.20/libusb/os/netbsd_usb.c +0 -674
- data/ext/libusb-1.0.20/libusb/os/openbsd_usb.c +0 -768
- data/ext/libusb-1.0.20/libusb/os/poll_posix.c +0 -53
- data/ext/libusb-1.0.20/libusb/os/poll_posix.h +0 -11
- data/ext/libusb-1.0.20/libusb/os/poll_windows.c +0 -728
- data/ext/libusb-1.0.20/libusb/os/poll_windows.h +0 -131
- data/ext/libusb-1.0.20/libusb/os/threads_posix.c +0 -82
- data/ext/libusb-1.0.20/libusb/os/threads_posix.h +0 -50
- data/ext/libusb-1.0.20/libusb/os/threads_windows.c +0 -214
- data/ext/libusb-1.0.20/libusb/os/threads_windows.h +0 -87
- data/ext/libusb-1.0.20/libusb/os/wince_usb.c +0 -869
- data/ext/libusb-1.0.20/libusb/os/wince_usb.h +0 -131
- data/ext/libusb-1.0.20/libusb/os/windows_common.h +0 -108
- data/ext/libusb-1.0.20/libusb/os/windows_usb.c +0 -4643
- data/ext/libusb-1.0.20/libusb/os/windows_usb.h +0 -973
- data/ext/libusb-1.0.20/libusb/strerror.c +0 -202
- data/ext/libusb-1.0.20/libusb/sync.c +0 -308
- data/ext/libusb-1.0.20/libusb/version.h +0 -18
- data/ext/libusb-1.0.20/libusb/version_nano.h +0 -1
- data/ext/libusb-1.0.20/ltmain.sh +0 -9655
- data/ext/libusb-1.0.20/m4/libtool.m4 +0 -7992
- data/ext/libusb-1.0.20/m4/ltoptions.m4 +0 -384
- data/ext/libusb-1.0.20/m4/ltsugar.m4 +0 -123
- data/ext/libusb-1.0.20/m4/ltversion.m4 +0 -23
- data/ext/libusb-1.0.20/m4/lt~obsolete.m4 +0 -98
- data/ext/libusb-1.0.20/missing +0 -215
- data/ext/libusb-1.0.20/tests/Makefile.am +0 -6
- data/ext/libusb-1.0.20/tests/Makefile.in +0 -596
- data/ext/libusb-1.0.20/tests/libusb_testlib.h +0 -107
- data/ext/libusb-1.0.20/tests/stress.c +0 -160
- data/ext/libusb-1.0.20/tests/testlib.c +0 -277
- metadata.gz.sig +0 -0
@@ -1,549 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* libusb example program to manipulate U.are.U 4000B fingerprint scanner.
|
3
|
-
* Copyright © 2007 Daniel Drake <dsd@gentoo.org>
|
4
|
-
*
|
5
|
-
* Basic image capture program only, does not consider the powerup quirks or
|
6
|
-
* the fact that image encryption may be enabled. Not expected to work
|
7
|
-
* flawlessly all of the time.
|
8
|
-
*
|
9
|
-
* This library is free software; you can redistribute it and/or
|
10
|
-
* modify it under the terms of the GNU Lesser General Public
|
11
|
-
* License as published by the Free Software Foundation; either
|
12
|
-
* version 2.1 of the License, or (at your option) any later version.
|
13
|
-
*
|
14
|
-
* This library is distributed in the hope that it will be useful,
|
15
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
17
|
-
* Lesser General Public License for more details.
|
18
|
-
*
|
19
|
-
* You should have received a copy of the GNU Lesser General Public
|
20
|
-
* License along with this library; if not, write to the Free Software
|
21
|
-
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
22
|
-
*/
|
23
|
-
|
24
|
-
#include <errno.h>
|
25
|
-
#include <pthread.h>
|
26
|
-
#include <semaphore.h>
|
27
|
-
#include <signal.h>
|
28
|
-
#include <string.h>
|
29
|
-
#include <stdio.h>
|
30
|
-
#include <stdlib.h>
|
31
|
-
|
32
|
-
#include "libusb.h"
|
33
|
-
|
34
|
-
#define EP_INTR (1 | LIBUSB_ENDPOINT_IN)
|
35
|
-
#define EP_DATA (2 | LIBUSB_ENDPOINT_IN)
|
36
|
-
#define CTRL_IN (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_IN)
|
37
|
-
#define CTRL_OUT (LIBUSB_REQUEST_TYPE_VENDOR | LIBUSB_ENDPOINT_OUT)
|
38
|
-
#define USB_RQ 0x04
|
39
|
-
#define INTR_LENGTH 64
|
40
|
-
|
41
|
-
enum {
|
42
|
-
MODE_INIT = 0x00,
|
43
|
-
MODE_AWAIT_FINGER_ON = 0x10,
|
44
|
-
MODE_AWAIT_FINGER_OFF = 0x12,
|
45
|
-
MODE_CAPTURE = 0x20,
|
46
|
-
MODE_SHUT_UP = 0x30,
|
47
|
-
MODE_READY = 0x80,
|
48
|
-
};
|
49
|
-
|
50
|
-
static int next_state(void);
|
51
|
-
|
52
|
-
enum {
|
53
|
-
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON = 1,
|
54
|
-
STATE_AWAIT_IRQ_FINGER_DETECTED,
|
55
|
-
STATE_AWAIT_MODE_CHANGE_CAPTURE,
|
56
|
-
STATE_AWAIT_IMAGE,
|
57
|
-
STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF,
|
58
|
-
STATE_AWAIT_IRQ_FINGER_REMOVED,
|
59
|
-
};
|
60
|
-
|
61
|
-
static int state = 0;
|
62
|
-
static struct libusb_device_handle *devh = NULL;
|
63
|
-
static unsigned char imgbuf[0x1b340];
|
64
|
-
static unsigned char irqbuf[INTR_LENGTH];
|
65
|
-
static struct libusb_transfer *img_transfer = NULL;
|
66
|
-
static struct libusb_transfer *irq_transfer = NULL;
|
67
|
-
static int img_idx = 0;
|
68
|
-
static volatile sig_atomic_t do_exit = 0;
|
69
|
-
|
70
|
-
static pthread_t poll_thread;
|
71
|
-
static sem_t exit_sem;
|
72
|
-
|
73
|
-
static void request_exit(sig_atomic_t code)
|
74
|
-
{
|
75
|
-
do_exit = code;
|
76
|
-
sem_post(&exit_sem);
|
77
|
-
}
|
78
|
-
|
79
|
-
static void *poll_thread_main(void *arg)
|
80
|
-
{
|
81
|
-
int r = 0;
|
82
|
-
printf("poll thread running\n");
|
83
|
-
|
84
|
-
while (!do_exit) {
|
85
|
-
struct timeval tv = { 1, 0 };
|
86
|
-
r = libusb_handle_events_timeout(NULL, &tv);
|
87
|
-
if (r < 0) {
|
88
|
-
request_exit(2);
|
89
|
-
break;
|
90
|
-
}
|
91
|
-
}
|
92
|
-
|
93
|
-
printf("poll thread shutting down\n");
|
94
|
-
return NULL;
|
95
|
-
}
|
96
|
-
|
97
|
-
static int find_dpfp_device(void)
|
98
|
-
{
|
99
|
-
devh = libusb_open_device_with_vid_pid(NULL, 0x05ba, 0x000a);
|
100
|
-
return devh ? 0 : -EIO;
|
101
|
-
}
|
102
|
-
|
103
|
-
static int print_f0_data(void)
|
104
|
-
{
|
105
|
-
unsigned char data[0x10];
|
106
|
-
int r;
|
107
|
-
unsigned int i;
|
108
|
-
|
109
|
-
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0xf0, 0, data,
|
110
|
-
sizeof(data), 0);
|
111
|
-
if (r < 0) {
|
112
|
-
fprintf(stderr, "F0 error %d\n", r);
|
113
|
-
return r;
|
114
|
-
}
|
115
|
-
if ((unsigned int) r < sizeof(data)) {
|
116
|
-
fprintf(stderr, "short read (%d)\n", r);
|
117
|
-
return -1;
|
118
|
-
}
|
119
|
-
|
120
|
-
printf("F0 data:");
|
121
|
-
for (i = 0; i < sizeof(data); i++)
|
122
|
-
printf("%02x ", data[i]);
|
123
|
-
printf("\n");
|
124
|
-
return 0;
|
125
|
-
}
|
126
|
-
|
127
|
-
static int get_hwstat(unsigned char *status)
|
128
|
-
{
|
129
|
-
int r;
|
130
|
-
|
131
|
-
r = libusb_control_transfer(devh, CTRL_IN, USB_RQ, 0x07, 0, status, 1, 0);
|
132
|
-
if (r < 0) {
|
133
|
-
fprintf(stderr, "read hwstat error %d\n", r);
|
134
|
-
return r;
|
135
|
-
}
|
136
|
-
if ((unsigned int) r < 1) {
|
137
|
-
fprintf(stderr, "short read (%d)\n", r);
|
138
|
-
return -1;
|
139
|
-
}
|
140
|
-
|
141
|
-
printf("hwstat reads %02x\n", *status);
|
142
|
-
return 0;
|
143
|
-
}
|
144
|
-
|
145
|
-
static int set_hwstat(unsigned char data)
|
146
|
-
{
|
147
|
-
int r;
|
148
|
-
|
149
|
-
printf("set hwstat to %02x\n", data);
|
150
|
-
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x07, 0, &data, 1, 0);
|
151
|
-
if (r < 0) {
|
152
|
-
fprintf(stderr, "set hwstat error %d\n", r);
|
153
|
-
return r;
|
154
|
-
}
|
155
|
-
if ((unsigned int) r < 1) {
|
156
|
-
fprintf(stderr, "short write (%d)", r);
|
157
|
-
return -1;
|
158
|
-
}
|
159
|
-
|
160
|
-
return 0;
|
161
|
-
}
|
162
|
-
|
163
|
-
static int set_mode(unsigned char data)
|
164
|
-
{
|
165
|
-
int r;
|
166
|
-
printf("set mode %02x\n", data);
|
167
|
-
|
168
|
-
r = libusb_control_transfer(devh, CTRL_OUT, USB_RQ, 0x4e, 0, &data, 1, 0);
|
169
|
-
if (r < 0) {
|
170
|
-
fprintf(stderr, "set mode error %d\n", r);
|
171
|
-
return r;
|
172
|
-
}
|
173
|
-
if ((unsigned int) r < 1) {
|
174
|
-
fprintf(stderr, "short write (%d)", r);
|
175
|
-
return -1;
|
176
|
-
}
|
177
|
-
|
178
|
-
return 0;
|
179
|
-
}
|
180
|
-
|
181
|
-
static void LIBUSB_CALL cb_mode_changed(struct libusb_transfer *transfer)
|
182
|
-
{
|
183
|
-
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
184
|
-
fprintf(stderr, "mode change transfer not completed!\n");
|
185
|
-
request_exit(2);
|
186
|
-
}
|
187
|
-
|
188
|
-
printf("async cb_mode_changed length=%d actual_length=%d\n",
|
189
|
-
transfer->length, transfer->actual_length);
|
190
|
-
if (next_state() < 0)
|
191
|
-
request_exit(2);
|
192
|
-
}
|
193
|
-
|
194
|
-
static int set_mode_async(unsigned char data)
|
195
|
-
{
|
196
|
-
unsigned char *buf = (unsigned char*) malloc(LIBUSB_CONTROL_SETUP_SIZE + 1);
|
197
|
-
struct libusb_transfer *transfer;
|
198
|
-
|
199
|
-
if (!buf)
|
200
|
-
return -ENOMEM;
|
201
|
-
|
202
|
-
transfer = libusb_alloc_transfer(0);
|
203
|
-
if (!transfer) {
|
204
|
-
free(buf);
|
205
|
-
return -ENOMEM;
|
206
|
-
}
|
207
|
-
|
208
|
-
printf("async set mode %02x\n", data);
|
209
|
-
libusb_fill_control_setup(buf, CTRL_OUT, USB_RQ, 0x4e, 0, 1);
|
210
|
-
buf[LIBUSB_CONTROL_SETUP_SIZE] = data;
|
211
|
-
libusb_fill_control_transfer(transfer, devh, buf, cb_mode_changed, NULL,
|
212
|
-
1000);
|
213
|
-
|
214
|
-
transfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK
|
215
|
-
| LIBUSB_TRANSFER_FREE_BUFFER | LIBUSB_TRANSFER_FREE_TRANSFER;
|
216
|
-
return libusb_submit_transfer(transfer);
|
217
|
-
}
|
218
|
-
|
219
|
-
static int do_sync_intr(unsigned char *data)
|
220
|
-
{
|
221
|
-
int r;
|
222
|
-
int transferred;
|
223
|
-
|
224
|
-
r = libusb_interrupt_transfer(devh, EP_INTR, data, INTR_LENGTH,
|
225
|
-
&transferred, 1000);
|
226
|
-
if (r < 0) {
|
227
|
-
fprintf(stderr, "intr error %d\n", r);
|
228
|
-
return r;
|
229
|
-
}
|
230
|
-
if (transferred < INTR_LENGTH) {
|
231
|
-
fprintf(stderr, "short read (%d)\n", r);
|
232
|
-
return -1;
|
233
|
-
}
|
234
|
-
|
235
|
-
printf("recv interrupt %04x\n", *((uint16_t *) data));
|
236
|
-
return 0;
|
237
|
-
}
|
238
|
-
|
239
|
-
static int sync_intr(unsigned char type)
|
240
|
-
{
|
241
|
-
int r;
|
242
|
-
unsigned char data[INTR_LENGTH];
|
243
|
-
|
244
|
-
while (1) {
|
245
|
-
r = do_sync_intr(data);
|
246
|
-
if (r < 0)
|
247
|
-
return r;
|
248
|
-
if (data[0] == type)
|
249
|
-
return 0;
|
250
|
-
}
|
251
|
-
}
|
252
|
-
|
253
|
-
static int save_to_file(unsigned char *data)
|
254
|
-
{
|
255
|
-
FILE *fd;
|
256
|
-
char filename[64];
|
257
|
-
|
258
|
-
snprintf(filename, sizeof(filename), "finger%d.pgm", img_idx++);
|
259
|
-
fd = fopen(filename, "w");
|
260
|
-
if (!fd)
|
261
|
-
return -1;
|
262
|
-
|
263
|
-
fputs("P5 384 289 255 ", fd);
|
264
|
-
(void) fwrite(data + 64, 1, 384*289, fd);
|
265
|
-
fclose(fd);
|
266
|
-
printf("saved image to %s\n", filename);
|
267
|
-
return 0;
|
268
|
-
}
|
269
|
-
|
270
|
-
static int next_state(void)
|
271
|
-
{
|
272
|
-
int r = 0;
|
273
|
-
printf("old state: %d\n", state);
|
274
|
-
switch (state) {
|
275
|
-
case STATE_AWAIT_IRQ_FINGER_REMOVED:
|
276
|
-
state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON;
|
277
|
-
r = set_mode_async(MODE_AWAIT_FINGER_ON);
|
278
|
-
break;
|
279
|
-
case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_ON:
|
280
|
-
state = STATE_AWAIT_IRQ_FINGER_DETECTED;
|
281
|
-
break;
|
282
|
-
case STATE_AWAIT_IRQ_FINGER_DETECTED:
|
283
|
-
state = STATE_AWAIT_MODE_CHANGE_CAPTURE;
|
284
|
-
r = set_mode_async(MODE_CAPTURE);
|
285
|
-
break;
|
286
|
-
case STATE_AWAIT_MODE_CHANGE_CAPTURE:
|
287
|
-
state = STATE_AWAIT_IMAGE;
|
288
|
-
break;
|
289
|
-
case STATE_AWAIT_IMAGE:
|
290
|
-
state = STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF;
|
291
|
-
r = set_mode_async(MODE_AWAIT_FINGER_OFF);
|
292
|
-
break;
|
293
|
-
case STATE_AWAIT_MODE_CHANGE_AWAIT_FINGER_OFF:
|
294
|
-
state = STATE_AWAIT_IRQ_FINGER_REMOVED;
|
295
|
-
break;
|
296
|
-
default:
|
297
|
-
printf("unrecognised state %d\n", state);
|
298
|
-
}
|
299
|
-
if (r < 0) {
|
300
|
-
fprintf(stderr, "error detected changing state\n");
|
301
|
-
return r;
|
302
|
-
}
|
303
|
-
|
304
|
-
printf("new state: %d\n", state);
|
305
|
-
return 0;
|
306
|
-
}
|
307
|
-
|
308
|
-
static void LIBUSB_CALL cb_irq(struct libusb_transfer *transfer)
|
309
|
-
{
|
310
|
-
unsigned char irqtype = transfer->buffer[0];
|
311
|
-
|
312
|
-
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
313
|
-
fprintf(stderr, "irq transfer status %d?\n", transfer->status);
|
314
|
-
irq_transfer = NULL;
|
315
|
-
request_exit(2);
|
316
|
-
return;
|
317
|
-
}
|
318
|
-
|
319
|
-
printf("IRQ callback %02x\n", irqtype);
|
320
|
-
switch (state) {
|
321
|
-
case STATE_AWAIT_IRQ_FINGER_DETECTED:
|
322
|
-
if (irqtype == 0x01) {
|
323
|
-
if (next_state() < 0) {
|
324
|
-
request_exit(2);
|
325
|
-
return;
|
326
|
-
}
|
327
|
-
} else {
|
328
|
-
printf("finger-on-sensor detected in wrong state!\n");
|
329
|
-
}
|
330
|
-
break;
|
331
|
-
case STATE_AWAIT_IRQ_FINGER_REMOVED:
|
332
|
-
if (irqtype == 0x02) {
|
333
|
-
if (next_state() < 0) {
|
334
|
-
request_exit(2);
|
335
|
-
return;
|
336
|
-
}
|
337
|
-
} else {
|
338
|
-
printf("finger-on-sensor detected in wrong state!\n");
|
339
|
-
}
|
340
|
-
break;
|
341
|
-
}
|
342
|
-
if (libusb_submit_transfer(irq_transfer) < 0)
|
343
|
-
request_exit(2);
|
344
|
-
}
|
345
|
-
|
346
|
-
static void LIBUSB_CALL cb_img(struct libusb_transfer *transfer)
|
347
|
-
{
|
348
|
-
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
|
349
|
-
fprintf(stderr, "img transfer status %d?\n", transfer->status);
|
350
|
-
img_transfer = NULL;
|
351
|
-
request_exit(2);
|
352
|
-
return;
|
353
|
-
}
|
354
|
-
|
355
|
-
printf("Image callback\n");
|
356
|
-
save_to_file(imgbuf);
|
357
|
-
if (next_state() < 0) {
|
358
|
-
request_exit(2);
|
359
|
-
return;
|
360
|
-
}
|
361
|
-
if (libusb_submit_transfer(img_transfer) < 0)
|
362
|
-
request_exit(2);
|
363
|
-
}
|
364
|
-
|
365
|
-
static int init_capture(void)
|
366
|
-
{
|
367
|
-
int r;
|
368
|
-
|
369
|
-
r = libusb_submit_transfer(irq_transfer);
|
370
|
-
if (r < 0)
|
371
|
-
return r;
|
372
|
-
|
373
|
-
r = libusb_submit_transfer(img_transfer);
|
374
|
-
if (r < 0) {
|
375
|
-
libusb_cancel_transfer(irq_transfer);
|
376
|
-
while (irq_transfer)
|
377
|
-
if (libusb_handle_events(NULL) < 0)
|
378
|
-
break;
|
379
|
-
return r;
|
380
|
-
}
|
381
|
-
|
382
|
-
/* start state machine */
|
383
|
-
state = STATE_AWAIT_IRQ_FINGER_REMOVED;
|
384
|
-
return next_state();
|
385
|
-
}
|
386
|
-
|
387
|
-
static int do_init(void)
|
388
|
-
{
|
389
|
-
unsigned char status;
|
390
|
-
int r;
|
391
|
-
|
392
|
-
r = get_hwstat(&status);
|
393
|
-
if (r < 0)
|
394
|
-
return r;
|
395
|
-
|
396
|
-
if (!(status & 0x80)) {
|
397
|
-
r = set_hwstat(status | 0x80);
|
398
|
-
if (r < 0)
|
399
|
-
return r;
|
400
|
-
r = get_hwstat(&status);
|
401
|
-
if (r < 0)
|
402
|
-
return r;
|
403
|
-
}
|
404
|
-
|
405
|
-
status &= ~0x80;
|
406
|
-
r = set_hwstat(status);
|
407
|
-
if (r < 0)
|
408
|
-
return r;
|
409
|
-
|
410
|
-
r = get_hwstat(&status);
|
411
|
-
if (r < 0)
|
412
|
-
return r;
|
413
|
-
|
414
|
-
r = sync_intr(0x56);
|
415
|
-
if (r < 0)
|
416
|
-
return r;
|
417
|
-
|
418
|
-
return 0;
|
419
|
-
}
|
420
|
-
|
421
|
-
static int alloc_transfers(void)
|
422
|
-
{
|
423
|
-
img_transfer = libusb_alloc_transfer(0);
|
424
|
-
if (!img_transfer)
|
425
|
-
return -ENOMEM;
|
426
|
-
|
427
|
-
irq_transfer = libusb_alloc_transfer(0);
|
428
|
-
if (!irq_transfer)
|
429
|
-
return -ENOMEM;
|
430
|
-
|
431
|
-
libusb_fill_bulk_transfer(img_transfer, devh, EP_DATA, imgbuf,
|
432
|
-
sizeof(imgbuf), cb_img, NULL, 0);
|
433
|
-
libusb_fill_interrupt_transfer(irq_transfer, devh, EP_INTR, irqbuf,
|
434
|
-
sizeof(irqbuf), cb_irq, NULL, 0);
|
435
|
-
|
436
|
-
return 0;
|
437
|
-
}
|
438
|
-
|
439
|
-
static void sighandler(int signum)
|
440
|
-
{
|
441
|
-
request_exit(1);
|
442
|
-
}
|
443
|
-
|
444
|
-
int main(void)
|
445
|
-
{
|
446
|
-
struct sigaction sigact;
|
447
|
-
int r = 1;
|
448
|
-
|
449
|
-
r = sem_init(&exit_sem, 0, 0);
|
450
|
-
if (r) {
|
451
|
-
fprintf(stderr, "failed to initialise semaphore error %d", errno);
|
452
|
-
exit(1);
|
453
|
-
}
|
454
|
-
|
455
|
-
r = libusb_init(NULL);
|
456
|
-
if (r < 0) {
|
457
|
-
fprintf(stderr, "failed to initialise libusb\n");
|
458
|
-
sem_destroy(&exit_sem);
|
459
|
-
exit(1);
|
460
|
-
}
|
461
|
-
|
462
|
-
r = find_dpfp_device();
|
463
|
-
if (r < 0) {
|
464
|
-
fprintf(stderr, "Could not find/open device\n");
|
465
|
-
goto out;
|
466
|
-
}
|
467
|
-
|
468
|
-
r = libusb_claim_interface(devh, 0);
|
469
|
-
if (r < 0) {
|
470
|
-
fprintf(stderr, "usb_claim_interface error %d %s\n", r, strerror(-r));
|
471
|
-
goto out;
|
472
|
-
}
|
473
|
-
printf("claimed interface\n");
|
474
|
-
|
475
|
-
r = print_f0_data();
|
476
|
-
if (r < 0)
|
477
|
-
goto out_release;
|
478
|
-
|
479
|
-
r = do_init();
|
480
|
-
if (r < 0)
|
481
|
-
goto out_deinit;
|
482
|
-
|
483
|
-
/* async from here onwards */
|
484
|
-
|
485
|
-
sigact.sa_handler = sighandler;
|
486
|
-
sigemptyset(&sigact.sa_mask);
|
487
|
-
sigact.sa_flags = 0;
|
488
|
-
sigaction(SIGINT, &sigact, NULL);
|
489
|
-
sigaction(SIGTERM, &sigact, NULL);
|
490
|
-
sigaction(SIGQUIT, &sigact, NULL);
|
491
|
-
|
492
|
-
r = pthread_create(&poll_thread, NULL, poll_thread_main, NULL);
|
493
|
-
if (r)
|
494
|
-
goto out_deinit;
|
495
|
-
|
496
|
-
r = alloc_transfers();
|
497
|
-
if (r < 0) {
|
498
|
-
request_exit(1);
|
499
|
-
pthread_join(poll_thread, NULL);
|
500
|
-
goto out_deinit;
|
501
|
-
}
|
502
|
-
|
503
|
-
r = init_capture();
|
504
|
-
if (r < 0) {
|
505
|
-
request_exit(1);
|
506
|
-
pthread_join(poll_thread, NULL);
|
507
|
-
goto out_deinit;
|
508
|
-
}
|
509
|
-
|
510
|
-
while (!do_exit)
|
511
|
-
sem_wait(&exit_sem);
|
512
|
-
|
513
|
-
printf("shutting down...\n");
|
514
|
-
pthread_join(poll_thread, NULL);
|
515
|
-
|
516
|
-
r = libusb_cancel_transfer(irq_transfer);
|
517
|
-
if (r < 0) {
|
518
|
-
request_exit(1);
|
519
|
-
goto out_deinit;
|
520
|
-
}
|
521
|
-
|
522
|
-
r = libusb_cancel_transfer(img_transfer);
|
523
|
-
if (r < 0) {
|
524
|
-
request_exit(1);
|
525
|
-
goto out_deinit;
|
526
|
-
}
|
527
|
-
|
528
|
-
while (img_transfer || irq_transfer)
|
529
|
-
if (libusb_handle_events(NULL) < 0)
|
530
|
-
break;
|
531
|
-
|
532
|
-
if (do_exit == 1)
|
533
|
-
r = 0;
|
534
|
-
else
|
535
|
-
r = 1;
|
536
|
-
|
537
|
-
out_deinit:
|
538
|
-
libusb_free_transfer(img_transfer);
|
539
|
-
libusb_free_transfer(irq_transfer);
|
540
|
-
set_mode(0);
|
541
|
-
set_hwstat(0x80);
|
542
|
-
out_release:
|
543
|
-
libusb_release_interface(devh, 0);
|
544
|
-
out:
|
545
|
-
libusb_close(devh);
|
546
|
-
libusb_exit(NULL);
|
547
|
-
sem_destroy(&exit_sem);
|
548
|
-
return r >= 0 ? r : -r;
|
549
|
-
}
|