From 391c37f58757c4a60c7a47752d4ecc55cf513a55 Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Tue, 5 Jul 2011 18:53:32 -0300 Subject: [PATCH] tools/atrf-id/atrf-id.c: new option -D to read atusb debug log --- tools/atrf-id/atrf-id.c | 52 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/tools/atrf-id/atrf-id.c b/tools/atrf-id/atrf-id.c index 0679b35..7686fb7 100644 --- a/tools/atrf-id/atrf-id.c +++ b/tools/atrf-id/atrf-id.c @@ -112,6 +112,44 @@ static void show_usb_info(struct atrf_dsc *dsc) } +static void do_dump_debug(struct atrf_dsc *dsc) +{ + usb_dev_handle *dev; + uint8_t buf[1024]; + int res; + struct log { + uint16_t n; + uint8_t bmRequestType; + uint8_t bRequest; + uint16_t wValue; + uint16_t wIndex; + uint16_t wLength; + } *p; + + dev = atrf_usb_handle(dsc); + if (!dev) + return; + + res = usb_control_msg(dev, FROM_DEV, ATUSB_READ_LOG, 0, 0, + (void *) buf, sizeof(buf), 1000); + if (res < 0) { + fprintf(stderr, "ATUSB_READ_LOG: %s\n", usb_strerror()); + return; + } + + printf("Number\tbmRequestType\tbRequest\twValue\twIndex\twLength\n"); + for (p = (void *) buf; (uint8_t *) (p+1) <= buf+res; p++) { + printf("%u\t", p->n); + printf("0x%02x\t\t", p->bmRequestType); + printf("0x%02x\t\t", p->bRequest); + printf("0x%04x\t", p->wValue); + printf("0x%04x\t", p->wIndex); + printf("0x%04x\n", p->wLength); + + } +} + + #else /* HAVE_USB */ @@ -120,6 +158,11 @@ static void show_usb_info(struct atrf_dsc *dsc) } +static void do_dump_debug(struct atrf_dsc *dsc) +{ +} + + #endif /* !HAVE_USB */ @@ -161,6 +204,7 @@ static void usage(const char *name) fprintf(stderr, "usage: %s [-d driver[:arg]] [-s [-s]]\n\n" " -d driver[:arg] use the specified driver (default: %s)\n" +" -D dump atusb debug buffer\n" " -s print only the local driver specification\n" " -s -s print only the remote driver specification\n" , name, atrf_default_driver_name()); @@ -173,13 +217,17 @@ int main(int argc, char *const *argv) const char *driver = NULL; struct atrf_dsc *dsc; int spec_only = 0; + int dump_debug = 0; int c; - while ((c = getopt(argc, argv, "d:s")) != EOF) + while ((c = getopt(argc, argv, "d:Ds")) != EOF) switch (c) { case 'd': driver = optarg; break; + case 'D': + dump_debug = 1; + break; case 's': spec_only++; break; @@ -205,6 +253,8 @@ int main(int argc, char *const *argv) } else { show_info(dsc); } + if (dump_debug) + do_dump_debug(dsc); atrf_close(dsc);