2 * TeensyTAS, TAS input player for MegaDrive
3 * Copyright (c) 2014 notaz
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
20 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
21 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 #include <sys/types.h>
33 #include <sys/ioctl.h>
34 #include <sys/select.h>
40 #include <linux/usbdevice_fs.h>
41 #include <linux/usb/ch9.h>
42 #include <linux/input.h>
45 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
55 /* return 1 if founf, 0 if not, < 0 on error */
56 static int find_device(struct teensy_dev *dev,
57 uint16_t vendor, uint16_t product)
59 const char path_root[] = "/dev/bus/usb";
61 struct usb_descriptor_header hdr;
62 struct usb_device_descriptor d;
63 struct usb_config_descriptor c;
64 struct usb_interface_descriptor i;
65 struct usb_endpoint_descriptor e;
66 char space[0x100]; /* enough? */
68 char path_bus[256], path_dev[256];
69 struct dirent *ent, *ent_bus;
70 DIR *dir = NULL, *dir_bus = NULL;
76 memset(dev, 0xff, sizeof(*dev));
78 dir = opendir(path_root);
84 for (ent = readdir(dir); ent != NULL; ent = readdir(dir)) {
85 /* should be a number like 000 */
86 if (sscanf(ent->d_name, "%03d", &num) != 1)
89 snprintf(path_bus, sizeof(path_bus), "%s/%s",
90 path_root, ent->d_name);
92 dir_bus = opendir(path_bus);
96 ent_bus = readdir(dir_bus);
97 for (; ent_bus != NULL; ent_bus = readdir(dir_bus)) {
98 if (sscanf(ent->d_name, "%03d", &num) != 1)
101 snprintf(path_dev, sizeof(path_dev), "%s/%s/%s",
102 path_root, ent->d_name, ent_bus->d_name);
104 fd = open(path_dev, O_RDWR);
108 ret = read(fd, &desc.d, sizeof(desc.d));
109 if (ret != sizeof(desc.d)) {
110 fprintf(stderr, "desc read: %d/%zd: ", ret, sizeof(desc.d));
115 if (desc.d.bDescriptorType != USB_DT_DEVICE) {
116 fprintf(stderr, "%s: bad DT: 0x%02x\n",
117 path_dev, desc.d.bDescriptorType);
121 if (desc.d.idVendor == vendor && desc.d.idProduct == product)
138 if (desc.d.bNumConfigurations != 1) {
139 fprintf(stderr, "unexpected bNumConfigurations: %u\n",
140 desc.d.bNumConfigurations);
144 /* walk through all descriptors */
147 ret = read(fd, &desc.hdr, sizeof(desc.hdr));
150 if (ret != sizeof(desc.hdr)) {
151 fprintf(stderr, "desc.hdr read: %d/%zd: ", ret, sizeof(desc.hdr));
156 ret = (int)lseek(fd, -sizeof(desc.hdr), SEEK_CUR);
162 ret = read(fd, &desc, desc.hdr.bLength);
163 if (ret != desc.hdr.bLength) {
164 fprintf(stderr, "desc read: %d/%u: ", ret, desc.hdr.bLength);
169 switch (desc.hdr.bDescriptorType) {
171 if (desc.c.bNumInterfaces != 2) {
172 fprintf(stderr, "unexpected bNumInterfaces: %u\n",
173 desc.c.bNumInterfaces);
178 case USB_DT_INTERFACE:
179 if (desc.i.bInterfaceClass != USB_CLASS_HID
180 || desc.i.bInterfaceSubClass != 0
181 || desc.i.bInterfaceProtocol != 0) {
182 fprintf(stderr, "unexpected interface %x:%x:%x\n",
183 desc.i.bInterfaceClass, desc.i.bInterfaceSubClass,
184 desc.i.bInterfaceProtocol);
187 if (desc.i.bNumEndpoints != 2) {
188 fprintf(stderr, "unexpected bNumEndpoints: %u\n",
189 desc.i.bNumEndpoints);
195 case USB_DT_ENDPOINT:
196 if (iface < 0 || iface >= ARRAY_SIZE(dev->ifaces)) {
197 fprintf(stderr, "bad iface: %d\n", iface);
200 if (desc.e.wMaxPacketSize != 64 && desc.e.wMaxPacketSize != 32) {
201 fprintf(stderr, "iface %d, EP %02x: "
202 "unexpected wMaxPacketSize: %u\n",
203 iface, desc.e.bEndpointAddress, desc.e.wMaxPacketSize);
206 if (desc.e.bEndpointAddress & 0x80)
207 dev->ifaces[iface].ep_in = desc.e.bEndpointAddress; // & 0x7F;
209 dev->ifaces[iface].ep_out = desc.e.bEndpointAddress;
217 fprintf(stderr, "skipping desc 0x%02x\n",
218 desc.hdr.bDescriptorType);
223 /* claim interfaces */
224 for (iface = 0; iface < ARRAY_SIZE(dev->ifaces); iface++) {
225 struct usbdevfs_ioctl usbio;
227 if (dev->ifaces[iface].ep_in == -1) {
228 fprintf(stderr, "missing ep_in, iface: %d\n", iface);
231 if (dev->ifaces[iface].ep_out == -1) {
232 fprintf(stderr, "missing ep_out, iface: %d\n", iface);
236 /* disconnect default driver */
237 memset(&usbio, 0, sizeof(usbio));
239 usbio.ioctl_code = USBDEVFS_DISCONNECT;
240 ret = ioctl(fd, USBDEVFS_IOCTL, &usbio);
241 if (ret != 0 && errno != ENODATA)
242 perror("USBDEVFS_DISCONNECT");
244 ret = ioctl(fd, USBDEVFS_CLAIMINTERFACE, &iface);
246 perror("USBDEVFS_CLAIMINTERFACE");
264 static int enable_echo(int enable)
266 const char *portname = "/dev/tty";
272 memset(&tty, 0, sizeof(tty));
274 fd = open(portname, O_RDWR | O_NOCTTY | O_SYNC);
276 fprintf(stderr, "open %s: ", portname);
281 ret = tcgetattr(fd, &tty);
287 // printf("lflag: 0%o\n", tty.c_lflag);
289 tty.c_lflag |= ECHO | ICANON;
291 tty.c_lflag &= ~(ECHO | ICANON);
292 tty.c_cc[VMIN] = tty.c_cc[VTIME] = 0;
295 ret = tcsetattr(fd, TCSANOW, &tty);
310 static void signal_handler(int sig)
313 signal(sig, SIG_DFL);
316 /* ?0SA 00DU, ?1CB RLDU */
317 #define STATE_BYTES 2
319 static uint8_t fixed_input_state[STATE_BYTES] = { 0x33, 0x3f };
332 static const enum mdbtn evdev_md_map[KEY_CNT] = {
334 [KEY_DOWN] = MDBTN_DOWN,
335 [KEY_LEFT] = MDBTN_LEFT,
336 [KEY_RIGHT] = MDBTN_RIGHT,
337 [KEY_HOME] = MDBTN_A,
338 [KEY_PAGEDOWN] = MDBTN_B,
340 [KEY_LEFTALT] = MDBTN_START,
343 int do_evdev_input(int fd)
345 uint8_t old_state[STATE_BYTES];
346 uint8_t changed_bits[STATE_BYTES] = { 0, };
347 struct input_event ev;
351 ret = read(fd, &ev, sizeof(ev));
352 if (ret != sizeof(ev)) {
353 fprintf(stderr, "evdev read %d/%zd: ", ret, sizeof(ev));
358 if (ev.type != EV_KEY)
361 if (ev.value != 0 && ev.value != 1)
364 if ((uint32_t)ev.code >= ARRAY_SIZE(evdev_md_map)) {
365 fprintf(stderr, "evdev read bad key: %u\n", ev.code);
369 mdbtn = evdev_md_map[ev.code];
373 memcpy(old_state, fixed_input_state, STATE_BYTES);
375 /* ?0SA 00DU, ?1CB RLDU */
378 changed_bits[0] = 0x01;
379 changed_bits[1] = 0x01;
382 changed_bits[0] = 0x02;
383 changed_bits[1] = 0x02;
386 changed_bits[0] = 0x00;
387 changed_bits[1] = 0x04;
390 changed_bits[0] = 0x00;
391 changed_bits[1] = 0x08;
394 changed_bits[0] = 0x10;
395 changed_bits[1] = 0x00;
398 changed_bits[0] = 0x00;
399 changed_bits[1] = 0x10;
402 changed_bits[0] = 0x00;
403 changed_bits[1] = 0x20;
406 changed_bits[0] = 0x20;
407 changed_bits[1] = 0x00;
413 for (i = 0; i < STATE_BYTES; i++)
414 fixed_input_state[i] &= ~changed_bits[i];
418 for (i = 0; i < STATE_BYTES; i++)
419 fixed_input_state[i] |= changed_bits[i];
422 return memcmp(old_state, fixed_input_state, STATE_BYTES) ? 1 : 0;
428 uint32_t rerecord_count;
436 static uint8_t *import_gmv(FILE *f, long size, int *frame_count)
443 if (size < (long)sizeof(*gmv)) {
444 fprintf(stderr, "bad gmv size: %ld\n", size);
450 fprintf(stderr, "OOM?\n");
453 ret = fread(gmv, 1, size, f);
455 fprintf(stderr, "fread %d/%ld: ", ret, size);
460 *frame_count = (size - sizeof(*gmv)) / sizeof(gmv->data[0]);
462 /* check the GMV.. */
463 if (*frame_count <= 0 || size != sizeof(*gmv) + *frame_count * 3) {
464 fprintf(stderr, "broken gmv? frames=%d\n", *frame_count);
468 if (strncmp(gmv->sig, "Gens Movie TEST", 15) != 0) {
469 fprintf(stderr, "bad GMV sig\n");
472 if (gmv->ctrl1 != '3') {
473 fprintf(stderr, "unhandled controlled config: '%c'\n", gmv->ctrl1);
476 if (gmv->ver >= 'A') {
477 if (gmv->flags & 0x40) {
478 fprintf(stderr, "unhandled flag: movie requires a savestate\n");
481 if (gmv->flags & 0x20) {
482 fprintf(stderr, "unhandled flag: 3-player movie\n");
485 if (gmv->flags & ~0x80) {
486 //fprintf(stderr, "unhandled flag(s): %04x\n", gmv->flags);
491 printf("loaded GMV: %s\n", gmv->name);
492 printf("%d frames, %u rerecords\n",
493 *frame_count, gmv->rerecord_count);
495 out = malloc(*frame_count * sizeof(out[0]));
497 fprintf(stderr, "OOM?\n");
501 for (i = 0; i < *frame_count; i++) {
502 out[i] = gmv->data[i][0];
504 if (gmv->data[i][1] != 0xff || gmv->data[i][2] != 0xff)
506 fprintf(stderr, "f %d: unhandled byte(s) %02x %02x\n",
507 i, gmv->data[i][1], gmv->data[i][2]);
514 static int do_bkm_char(char c, char expect, uint8_t *val, int bit)
523 fprintf(stderr, "unexpected bkm char: '%c' instead of '%c'\n",
528 static uint8_t *import_bkm(FILE *f, int *frame_count)
530 uint8_t *out = NULL, val;
539 while ((p = fgets(buf, sizeof(buf), f)) != NULL) {
546 if (p[30] != '\r' && p[30] != '\n')
550 if (count >= alloc) {
551 alloc = alloc * 2 + 64;
552 out = realloc(out, alloc * sizeof(out[0]));
554 fprintf(stderr, "OOM?\n");
561 if (strncmp(p, "|.|", 3) != 0)
565 const char ref[] = "UDLRABCS";
566 for (r = ref, i = 0; *r != 0; p++, r++, i++) {
567 if (do_bkm_char(*p, *r, &val, i))
571 if (strcmp(p, "....|............||") != 0)
578 fprintf(stderr, "unhandled bkm line %d: '%s'\n", line, buf);
582 printf("loaded bkm, %d frames\n", count);
583 *frame_count = count;
587 static int write_bkm_frame(FILE *f, const uint8_t *data)
589 /* ?0SA 00DU, ?1CB RLDU */
590 static const char ref[] = "UDLRABCSXYZM";
591 static const char bits[] = { 0,1,2,3, 12,4,5,13, 16,16,16,16 };
596 fprintf(stderr, "%s called without outfile\n", __func__);
600 idata[0] = 0x10000 | (data[0] << 8) | data[1];
604 for (p = 0; p < 2; p++) {
605 for (i = 0; i < 12; i++)
606 fprintf(f, "%c", (idata[p] & (1 << bits[i])) ? '.' : ref[i]);
615 static int tas_data_to_teensy(uint8_t b, uint8_t *data, FILE *logf)
621 /* ?0SA 00DU, ?1CB RLDU */
622 data[0] = (b & 0x13) | ((b >> 2) & 0x20);
623 data[1] = (b & 0x0f) | ((b >> 1) & 0x30);
626 fwrite(&data[0], 1, 1, logf);
627 t = data[1] | 0x40; // expected TH
628 fwrite(&t, 1, 1, logf);
634 static int submit_urb(int fd, struct usbdevfs_urb *urb, int ep,
635 void *buf, size_t buf_size)
637 memset(urb, 0, sizeof(*urb));
638 urb->type = USBDEVFS_URB_TYPE_INTERRUPT;
641 urb->buffer_length = buf_size;
643 return ioctl(fd, USBDEVFS_SUBMITURB, urb);
653 static void missing_arg(int a)
655 fprintf(stderr, "missing arg: %d\n", a);
659 int main(int argc, char *argv[])
661 struct teensy_dev dev;
662 struct usbdevfs_urb urb[URB_CNT];
663 struct usbdevfs_urb *reaped_urb;
664 int fixed_input_changed;
666 int evdev_fd_cnt = 0;
669 int pending_urbs = 0;
671 const char *tasfn = NULL;
672 const char *outfn = NULL;
673 const char *logfn = NULL;
674 uint8_t *tas_data = NULL;
675 int use_vsync = 0; // frame increment on vsync
676 int no_start_seq = 0;
682 char buf_dbg[64 + 1];
683 struct tas_pkt pkt_in;
684 struct tas_pkt pkt_out;
685 struct timeval *timeout = NULL;
692 for (i = 1; i < argc; i++) {
693 if (argv[i][0] == '-') {
694 switch (argv[i][1] | (argv[i][2] << 8)) {
717 tas_skip = atoi(argv[i]);
726 fprintf(stderr, "bad arg: %s\n", argv[i]);
731 /* remaining args are evdev filenames */
732 if (evdev_fd_cnt >= ARRAY_SIZE(evdev_fds)) {
733 fprintf(stderr, "too many evdevs\n");
736 fd = open(argv[i], O_RDONLY);
738 fprintf(stderr, "open %s: ", argv[i]);
743 ret = ioctl(fd, EVIOCGBIT(0, sizeof(evdev_support)),
747 if (!(evdev_support & (1 << EV_KEY))) {
748 fprintf(stderr, "%s doesn't have keys\n", argv[i]);
752 evdev_fds[evdev_fd_cnt++] = fd;
760 f = fopen(tasfn, "rb");
762 fprintf(stderr, "fopen %s: ", tasfn);
767 fseek(f, 0, SEEK_END);
769 fseek(f, 0, SEEK_SET);
771 fprintf(stderr, "bad size: %ld\n", size);
775 ext = strrchr(tasfn, '.');
781 if (strcasecmp(ext, "gmv") == 0)
782 tas_data = import_gmv(f, size, &frame_count);
783 else if (strcasecmp(ext, "bkm") == 0)
784 tas_data = import_bkm(f, &frame_count);
786 fprintf(stderr, "unknown movie type: '%s'\n", ext);
791 if (tas_data == NULL) {
792 fprintf(stderr, "failed fo parse %s\n", tasfn);
797 if (tas_skip >= frame_count || tas_skip <= -frame_count) {
798 printf("skip out of range: %d/%d\n", tas_skip, frame_count);
802 frame_count -= tas_skip;
803 memmove(&tas_data[0], &tas_data[tas_skip],
804 sizeof(tas_data[0]) * frame_count);
807 tas_data = realloc(tas_data,
808 (frame_count - tas_skip) * sizeof(tas_data[0]));
809 if (tas_data == NULL) {
810 fprintf(stderr, "OOM?\n");
813 memmove(&tas_data[-tas_skip], &tas_data[0],
814 sizeof(tas_data[0]) * frame_count);
815 memset(&tas_data[0], 0xff, sizeof(tas_data[0]) * -tas_skip);
816 frame_count -= tas_skip;
822 outf = fopen(outfn, "w");
824 fprintf(stderr, "fopen %s: ", outfn);
831 logf = fopen(logfn, "wb");
833 fprintf(stderr, "fopen %s: ", logfn);
840 signal(SIGINT, signal_handler);
844 while (!g_exit || (pending_urbs & (1 << URB_DATA_OUT)))
847 ret = find_device(&dev, 0x16C0, 0x0486);
853 printf("waiting for device..\n");
865 /* we wait first, then send commands, but if teensy
866 * is started already, it won't send anything */
872 if (!(pending_urbs & (1 << URB_DATA_IN))) {
873 memset(&pkt_in, 0, sizeof(pkt_in));
874 ret = submit_urb(dev.fd, &urb[URB_DATA_IN], dev.ifaces[0].ep_in,
875 &pkt_in, sizeof(pkt_in));
877 perror("USBDEVFS_SUBMITURB URB_DATA_IN");
881 pending_urbs |= 1 << URB_DATA_IN;
883 if (!(pending_urbs & (1 << URB_DBG_IN))) {
884 ret = submit_urb(dev.fd, &urb[URB_DBG_IN], dev.ifaces[1].ep_in,
885 buf_dbg, sizeof(buf_dbg) - 1);
887 perror("USBDEVFS_SUBMITURB URB_DBG_IN");
891 pending_urbs |= 1 << URB_DBG_IN;
895 FD_SET(STDIN_FILENO, &rfds);
896 for (i = 0; i < evdev_fd_cnt; i++)
897 FD_SET(evdev_fds[i], &rfds);
900 FD_SET(dev.fd, &wfds);
902 ret = select(dev.fd + 1, &rfds, &wfds, NULL, timeout);
909 /* sometihng form stdin? */
910 if (FD_ISSET(STDIN_FILENO, &rfds)) {
912 ret = read(STDIN_FILENO, &c, 1);
914 perror("read stdin");
927 /* something from input devices? */
928 fixed_input_changed = 0;
929 for (i = 0; i < evdev_fd_cnt; i++) {
930 if (FD_ISSET(evdev_fds[i], &rfds)) {
931 fixed_input_changed |=
932 do_evdev_input(evdev_fds[i]);
936 /* something from USB? */
937 if (FD_ISSET(dev.fd, &wfds))
939 unsigned int which_urb;
942 ret = ioctl(dev.fd, USBDEVFS_REAPURB, &reaped_urb);
946 perror("USBDEVFS_REAPURB");
949 which_urb = reaped_urb - urb;
950 if (which_urb < ARRAY_SIZE(urb))
951 pending_urbs &= ~(1 << which_urb);
953 fprintf(stderr, "reaped unknown urb: %p #%u",
954 reaped_urb, which_urb);
957 if (reaped_urb != NULL && reaped_urb->status != 0) {
958 errno = -reaped_urb->status;
959 fprintf(stderr, "urb #%u: ", which_urb);
961 if (reaped_urb->status == -EILSEQ) {
962 /* this is usually a sign of disconnect.. */
967 else if (reaped_urb == &urb[URB_DATA_IN])
969 /* some request from teensy */
970 switch (pkt_in.type) {
972 printf("req: %d/%d/%d\n", pkt_in.req.frame,
973 frames_sent, frame_count);
976 if (frames_sent < frame_count) {
977 pkt_out.type = PKT_STREAM_DATA_TO;
979 for (i = 0; i < sizeof(pkt_out.data); ) {
980 i += tas_data_to_teensy(tas_data[frames_sent],
981 pkt_out.data + i, logf);
984 if (frames_sent >= frame_count)
990 pkt_out.type = PKT_STREAM_END;
995 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT],
996 dev.ifaces[0].ep_out, &pkt_out, sizeof(pkt_out));
998 perror("USBDEVFS_SUBMITURB PKT_STREAM_DATA_TO");
1001 case PKT_STREAM_DATA_FROM:
1002 printf("f: %d\n", frame_count);
1003 if (pkt_in.size == 0 || pkt_in.size > sizeof(pkt_out.data)) {
1004 printf("host: got bad DATA_FROM size: %u\n", pkt_in.size);
1007 for (i = 0; i < pkt_in.size; ) {
1008 i += write_bkm_frame(outf, pkt_in.data + i);
1014 printf("host: got unknown pkt type: %04x\n", pkt_in.type);
1018 else if (reaped_urb == &urb[URB_DATA_OUT])
1021 else if (reaped_urb == &urb[URB_DBG_IN])
1024 buf_dbg[reaped_urb->actual_length] = 0;
1025 printf("%s", buf_dbg);
1027 // continue receiving debug before sending out stuff
1029 tout.tv_usec = 1000;
1034 fprintf(stderr, "reaped unknown urb? %p #%zu\n",
1035 reaped_urb, reaped_urb - urb);
1039 /* something to send? */
1040 if (pending_urbs & (1 << URB_DATA_OUT))
1041 // can't do that yet
1044 if ((tas_data != NULL || outf != NULL) && !enable_sent) {
1045 memset(&pkt_out, 0, sizeof(pkt_out));
1046 pkt_out.type = PKT_STREAM_ENABLE;
1047 pkt_out.enable.stream_to = (tas_data != NULL);
1048 pkt_out.enable.stream_from = (outf != NULL);
1049 pkt_out.enable.use_readinc = !use_vsync;
1050 pkt_out.enable.no_start_seq = no_start_seq;
1052 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT], dev.ifaces[0].ep_out,
1053 &pkt_out, sizeof(pkt_out));
1055 perror("USBDEVFS_SUBMITURB PKT_STREAM_ENABLE");
1058 pending_urbs |= 1 << URB_DATA_OUT;
1063 if (tas_data == NULL && fixed_input_changed) {
1064 memset(&pkt_out, 0, sizeof(pkt_out));
1065 pkt_out.type = PKT_FIXED_STATE;
1066 memcpy(pkt_out.data, fixed_input_state, sizeof(fixed_input_state));
1068 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT], dev.ifaces[0].ep_out,
1069 &pkt_out, sizeof(pkt_out));
1071 perror("USBDEVFS_SUBMITURB PKT_FIXED_STATE");
1074 pending_urbs |= 1 << URB_DATA_OUT;
1077 if (g_exit && !abort_sent) {
1078 memset(&pkt_out, 0, sizeof(pkt_out));
1079 pkt_out.type = PKT_STREAM_ABORT;
1081 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT], dev.ifaces[0].ep_out,
1082 &pkt_out, sizeof(pkt_out));
1084 perror("USBDEVFS_SUBMITURB PKT_STREAM_ABORT");
1087 pending_urbs |= 1 << URB_DATA_OUT;
1107 /* deal with pending URBs */
1108 if (pending_urbs & (1 << URB_DATA_IN))
1109 ioctl(dev.fd, USBDEVFS_DISCARDURB, &urb[URB_DATA_IN]);
1110 if (pending_urbs & (1 << URB_DBG_IN))
1111 ioctl(dev.fd, USBDEVFS_DISCARDURB, &urb[URB_DBG_IN]);
1112 for (i = 0; i < URB_CNT; i++) {
1113 if (pending_urbs & (1 << i)) {
1114 ret = ioctl(dev.fd, USBDEVFS_REAPURB, &reaped_urb);
1116 perror("USBDEVFS_REAPURB");
1126 // vim: ts=2:sw=2:expandtab