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;
425 #define MAX_INPUT_BYTES 2
428 static int tas_data_to_teensy(uint16_t b, uint8_t *data, FILE *logf)
434 /* ?0SA 00DU, ?1CB RLDU */
435 data[0] = (b & 0x13) | ((b >> 2) & 0x20);
436 data[1] = (b & 0x0f) | ((b >> 1) & 0x30);
439 fwrite(&data[0], 1, 1, logf);
440 t = data[1] | 0x40; // expected TH
441 fwrite(&t, 1, 1, logf);
450 uint32_t rerecord_count;
458 static uint8_t *import_gmv(FILE *f, long size, int *byte_count, FILE *logf)
470 if (size < (long)sizeof(*gmv)) {
471 fprintf(stderr, "bad gmv size: %ld\n", size);
477 fprintf(stderr, "OOM?\n");
480 ret = fread(gmv, 1, size, f);
482 fprintf(stderr, "fread %d/%ld: ", ret, size);
487 frame_count = (size - sizeof(*gmv)) / sizeof(gmv->data[0]);
489 /* check the GMV.. */
490 if (frame_count <= 0 || size != sizeof(*gmv) + frame_count * 3) {
491 fprintf(stderr, "broken gmv? frames=%d\n", frame_count);
495 if (strncmp(gmv->sig, "Gens Movie TEST", 15) != 0) {
496 fprintf(stderr, "bad GMV sig\n");
499 if (gmv->ctrl1 != '3') {
500 fprintf(stderr, "unhandled controlled config: '%c'\n", gmv->ctrl1);
503 if (gmv->ver >= 'A') {
504 if (gmv->flags & 0x40) {
505 fprintf(stderr, "unhandled flag: movie requires a savestate\n");
508 if (gmv->flags & 0x20) {
509 fprintf(stderr, "unhandled flag: 3-player movie\n");
512 if (gmv->flags & ~0x80) {
513 //fprintf(stderr, "unhandled flag(s): %04x\n", gmv->flags);
518 printf("loaded GMV: %s\n", gmv->name);
519 printf("%d frames, %u rerecords\n",
520 frame_count, gmv->rerecord_count);
522 out = malloc(frame_count * MAX_INPUT_BYTES);
524 fprintf(stderr, "OOM?\n");
528 for (i = 0; i < frame_count; i++) {
529 val = gmv->data[i][0] | ((gmv->data[i][2] & 0x0f) << 8);
530 count += tas_data_to_teensy(val, out + count, logf);
532 if (gmv->data[i][1] != 0xff || gmv->data[i][2] != 0xff)
534 fprintf(stderr, "f %d: unhandled byte(s) %02x %02x\n",
535 i, gmv->data[i][1], gmv->data[i][2]);
543 static int do_bkm_char(char c, char expect, uint16_t *val, int bit)
552 fprintf(stderr, "unexpected bkm char: '%c' instead of '%c'\n",
557 static uint8_t *import_bkm(FILE *f, int *byte_count, FILE *logf)
570 while ((p = fgets(buf, sizeof(buf), f)) != NULL)
578 if (p[30] != '\r' && p[30] != '\n')
582 if (count >= alloc - MAX_INPUT_BYTES) {
583 alloc = alloc * 2 + 64;
584 out = realloc(out, alloc * sizeof(out[0]));
586 fprintf(stderr, "OOM?\n");
593 if (strncmp(p, "|.|", 3) != 0)
597 const char ref[] = "UDLRABCS";
598 for (r = ref, i = 0; *r != 0; p++, r++, i++) {
599 if (do_bkm_char(*p, *r, &val, i))
603 if (strcmp(p, "....|............||") != 0)
606 count += tas_data_to_teensy(val, out + count, logf);
611 fprintf(stderr, "unhandled bkm line %d: '%s'\n", line, buf);
615 printf("loaded bkm, %d frames, %d bytes\n", frames, count);
620 static uint8_t *import_raw(FILE *f, int *byte_count, FILE *logf)
622 uint8_t *out = NULL, val;
631 while ((p = fgets(buf, sizeof(buf), f)) != NULL)
637 printf("skipping: %s", p);
643 for (i = 6; i >= 0; i--, p++) {
644 if (*p != '0' && *p != '1')
652 if (first && (val & 0x40))
656 if (count >= alloc) {
657 alloc = alloc * 2 + 64;
658 out = realloc(out, alloc * sizeof(out[0]));
660 fprintf(stderr, "OOM?\n");
666 fwrite(&val, 1, 1, logf);
668 out[count++] = val & 0x3f;
672 fprintf(stderr, "bad raw line %d: '%s'\n", line, buf);
676 printf("loaded raw, %d bytes\n", count);
681 static int write_bkm_frame(FILE *f, const uint8_t *data)
683 /* ?0SA 00DU, ?1CB RLDU */
684 static const char ref[] = "UDLRABCSXYZM";
685 static const char bits[] = { 0,1,2,3, 12,4,5,13, 16,16,16,16 };
690 fprintf(stderr, "%s called without outfile\n", __func__);
694 idata[0] = 0x10000 | (data[0] << 8) | data[1];
698 for (p = 0; p < 2; p++) {
699 for (i = 0; i < 12; i++)
700 fprintf(f, "%c", (idata[p] & (1 << bits[i])) ? '.' : ref[i]);
709 static int submit_urb(int fd, struct usbdevfs_urb *urb, int ep,
710 void *buf, size_t buf_size)
712 memset(urb, 0, sizeof(*urb));
713 urb->type = USBDEVFS_URB_TYPE_INTERRUPT;
716 urb->buffer_length = buf_size;
718 return ioctl(fd, USBDEVFS_SUBMITURB, urb);
728 static void missing_arg(int a)
730 fprintf(stderr, "missing arg: %d\n", a);
734 int main(int argc, char *argv[])
736 struct teensy_dev dev;
737 struct usbdevfs_urb urb[URB_CNT];
738 struct usbdevfs_urb *reaped_urb;
739 int fixed_input_changed = 0;
741 int evdev_fd_cnt = 0;
744 int pending_urbs = 0;
746 const char *tasfn = NULL;
747 const char *outfn = NULL;
748 const char *logfn = NULL;
749 uint8_t *tas_data = NULL;
750 int tas_data_size = 0;
752 int use_vsync = 0; // frame increment on vsync
753 int no_start_seq = 0;
758 char buf_dbg[64 + 1];
759 struct tas_pkt pkt_in;
760 struct tas_pkt pkt_out;
761 struct timeval *timeout = NULL;
768 for (i = 1; i < argc; i++) {
769 if (argv[i][0] == '-') {
770 switch (argv[i][1] | (argv[i][2] << 8)) {
796 fprintf(stderr, "bad arg: %s\n", argv[i]);
801 /* remaining args are evdev filenames */
802 if (evdev_fd_cnt >= ARRAY_SIZE(evdev_fds)) {
803 fprintf(stderr, "too many evdevs\n");
806 fd = open(argv[i], O_RDONLY);
808 fprintf(stderr, "open %s: ", argv[i]);
813 ret = ioctl(fd, EVIOCGBIT(0, sizeof(evdev_support)),
817 if (!(evdev_support & (1 << EV_KEY))) {
818 fprintf(stderr, "%s doesn't have keys\n", argv[i]);
822 evdev_fds[evdev_fd_cnt++] = fd;
826 logf = fopen(logfn, "wb");
828 fprintf(stderr, "fopen %s: ", logfn);
839 f = fopen(tasfn, "rb");
841 fprintf(stderr, "fopen %s: ", tasfn);
846 fseek(f, 0, SEEK_END);
848 fseek(f, 0, SEEK_SET);
850 fprintf(stderr, "bad size: %ld\n", size);
854 ext = strrchr(tasfn, '.');
860 if (strcasecmp(ext, "gmv") == 0)
861 tas_data = import_gmv(f, size, &tas_data_size, logf);
862 else if (strcasecmp(ext, "bkm") == 0)
863 tas_data = import_bkm(f, &tas_data_size, logf);
864 else if (strcasecmp(ext, "txt") == 0)
865 tas_data = import_raw(f, &tas_data_size, logf);
867 fprintf(stderr, "unknown movie type: '%s'\n", ext);
877 if (tas_data == NULL) {
878 fprintf(stderr, "failed fo parse %s\n", tasfn);
884 outf = fopen(outfn, "w");
886 fprintf(stderr, "fopen %s: ", outfn);
893 signal(SIGINT, signal_handler);
897 while (!g_exit || (pending_urbs & (1 << URB_DATA_OUT)))
900 ret = find_device(&dev, 0x16C0, 0x0486);
906 printf("waiting for device..\n");
918 /* we wait first, then send commands, but if teensy
919 * is started already, it won't send anything */
925 if (!(pending_urbs & (1 << URB_DATA_IN))) {
926 memset(&pkt_in, 0, sizeof(pkt_in));
927 ret = submit_urb(dev.fd, &urb[URB_DATA_IN], dev.ifaces[0].ep_in,
928 &pkt_in, sizeof(pkt_in));
930 perror("USBDEVFS_SUBMITURB URB_DATA_IN");
934 pending_urbs |= 1 << URB_DATA_IN;
936 if (!(pending_urbs & (1 << URB_DBG_IN))) {
937 ret = submit_urb(dev.fd, &urb[URB_DBG_IN], dev.ifaces[1].ep_in,
938 buf_dbg, sizeof(buf_dbg) - 1);
940 perror("USBDEVFS_SUBMITURB URB_DBG_IN");
944 pending_urbs |= 1 << URB_DBG_IN;
948 FD_SET(STDIN_FILENO, &rfds);
949 for (i = 0; i < evdev_fd_cnt; i++)
950 FD_SET(evdev_fds[i], &rfds);
953 FD_SET(dev.fd, &wfds);
955 ret = select(dev.fd + 1, &rfds, &wfds, NULL, timeout);
962 /* sometihng form stdin? */
963 if (FD_ISSET(STDIN_FILENO, &rfds)) {
965 ret = read(STDIN_FILENO, &c, 1);
967 perror("read stdin");
978 /* something from input devices? */
979 for (i = 0; i < evdev_fd_cnt; i++) {
980 if (FD_ISSET(evdev_fds[i], &rfds)) {
981 fixed_input_changed |=
982 do_evdev_input(evdev_fds[i]);
986 /* something from USB? */
987 if (FD_ISSET(dev.fd, &wfds))
989 unsigned int which_urb;
992 ret = ioctl(dev.fd, USBDEVFS_REAPURB, &reaped_urb);
996 perror("USBDEVFS_REAPURB");
999 which_urb = reaped_urb - urb;
1000 if (which_urb < ARRAY_SIZE(urb))
1001 pending_urbs &= ~(1 << which_urb);
1003 fprintf(stderr, "reaped unknown urb: %p #%u",
1004 reaped_urb, which_urb);
1007 if (reaped_urb != NULL && reaped_urb->status != 0) {
1008 errno = -reaped_urb->status;
1009 fprintf(stderr, "urb #%u: ", which_urb);
1011 if (reaped_urb->status == -EILSEQ) {
1012 /* this is usually a sign of disconnect.. */
1017 else if (reaped_urb == &urb[URB_DATA_IN])
1019 /* some request from teensy */
1020 switch (pkt_in.type) {
1021 case PKT_STREAM_REQ:
1022 printf("req: %d/%d/%d\n", pkt_in.req.frame * 2,
1023 bytes_sent, tas_data_size);
1026 if (bytes_sent < tas_data_size) {
1027 pkt_out.type = PKT_STREAM_DATA_TO;
1029 i = tas_data_size - bytes_sent;
1030 if (i > sizeof(pkt_out.data))
1031 i = sizeof(pkt_out.data);
1032 memcpy(pkt_out.data, tas_data + bytes_sent, i);
1037 pkt_out.type = PKT_STREAM_END;
1040 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT],
1041 dev.ifaces[0].ep_out, &pkt_out, sizeof(pkt_out));
1043 perror("USBDEVFS_SUBMITURB PKT_STREAM_DATA_TO");
1046 case PKT_STREAM_DATA_FROM:
1047 printf("f: %d\n", frame_count);
1048 if (pkt_in.size == 0 || pkt_in.size > sizeof(pkt_out.data)) {
1049 printf("host: got bad DATA_FROM size: %u\n", pkt_in.size);
1052 for (i = 0; i < pkt_in.size; ) {
1053 i += write_bkm_frame(outf, pkt_in.data + i);
1059 printf("host: got unknown pkt type: %04x\n", pkt_in.type);
1063 else if (reaped_urb == &urb[URB_DATA_OUT])
1066 else if (reaped_urb == &urb[URB_DBG_IN])
1069 buf_dbg[reaped_urb->actual_length] = 0;
1070 printf("%s", buf_dbg);
1072 // continue receiving debug before sending out stuff
1074 tout.tv_usec = 1000;
1079 fprintf(stderr, "reaped unknown urb? %p #%zu\n",
1080 reaped_urb, reaped_urb - urb);
1084 /* something to send? */
1085 if (pending_urbs & (1 << URB_DATA_OUT))
1086 // can't do that yet
1089 if ((tas_data != NULL || outf != NULL) && !enable_sent) {
1090 memset(&pkt_out, 0, sizeof(pkt_out));
1091 pkt_out.type = PKT_STREAM_ENABLE;
1092 pkt_out.enable.stream_to = (tas_data != NULL);
1093 pkt_out.enable.stream_from = (outf != NULL);
1094 pkt_out.enable.use_readinc = !use_vsync;
1095 pkt_out.enable.no_start_seq = no_start_seq;
1097 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT], dev.ifaces[0].ep_out,
1098 &pkt_out, sizeof(pkt_out));
1100 perror("USBDEVFS_SUBMITURB PKT_STREAM_ENABLE");
1103 pending_urbs |= 1 << URB_DATA_OUT;
1108 if (tas_data == NULL && fixed_input_changed) {
1109 memset(&pkt_out, 0, sizeof(pkt_out));
1110 pkt_out.type = PKT_FIXED_STATE;
1111 memcpy(pkt_out.data, fixed_input_state, sizeof(fixed_input_state));
1113 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT], dev.ifaces[0].ep_out,
1114 &pkt_out, sizeof(pkt_out));
1116 perror("USBDEVFS_SUBMITURB PKT_FIXED_STATE");
1119 fixed_input_changed = 0;
1120 pending_urbs |= 1 << URB_DATA_OUT;
1123 if (g_exit && !abort_sent) {
1124 memset(&pkt_out, 0, sizeof(pkt_out));
1125 pkt_out.type = PKT_STREAM_ABORT;
1127 ret = submit_urb(dev.fd, &urb[URB_DATA_OUT], dev.ifaces[0].ep_out,
1128 &pkt_out, sizeof(pkt_out));
1130 perror("USBDEVFS_SUBMITURB PKT_STREAM_ABORT");
1133 pending_urbs |= 1 << URB_DATA_OUT;
1151 /* deal with pending URBs */
1152 if (pending_urbs & (1 << URB_DATA_IN))
1153 ioctl(dev.fd, USBDEVFS_DISCARDURB, &urb[URB_DATA_IN]);
1154 if (pending_urbs & (1 << URB_DBG_IN))
1155 ioctl(dev.fd, USBDEVFS_DISCARDURB, &urb[URB_DBG_IN]);
1156 for (i = 0; i < URB_CNT; i++) {
1157 if (pending_urbs & (1 << i)) {
1158 ret = ioctl(dev.fd, USBDEVFS_REAPURB, &reaped_urb);
1160 perror("USBDEVFS_REAPURB");
1170 // vim: ts=2:sw=2:expandtab