[gnome-color-manager: 58/80] Add a method to get the USB control data from strace
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-color-manager: 58/80] Add a method to get the USB control data from strace
- Date: Mon, 19 Jul 2010 11:37:19 +0000 (UTC)
commit 9d752eceef35e88a7d7074c330ddc9f1b3cb782b
Author: Richard Hughes <richard hughsie com>
Date: Sat Jul 17 23:39:37 2010 +0100
Add a method to get the USB control data from strace
(You need my custom patch to strace to get the data)
.gitignore | 1 -
...t-usb-traffic-and-add-hex-output-pretty-p.patch | 53 ++++++
docs/huey/annotate.sh | 9 +
docs/huey/gcm-parse-huey.c | 185 +++++++++++++-------
4 files changed, 187 insertions(+), 61 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index db7368b..e47e354 100644
--- a/.gitignore
+++ b/.gitignore
@@ -30,4 +30,3 @@ intltool-extract.in
intltool-merge.in
intltool-update.in
.acb
-*.patch
diff --git a/docs/huey/0001-strace-print-usb-traffic-and-add-hex-output-pretty-p.patch b/docs/huey/0001-strace-print-usb-traffic-and-add-hex-output-pretty-p.patch
new file mode 100644
index 0000000..a2ef1b1
--- /dev/null
+++ b/docs/huey/0001-strace-print-usb-traffic-and-add-hex-output-pretty-p.patch
@@ -0,0 +1,53 @@
+From 6a7f215e02cc17e3939949deb6d19421188830d4 Mon Sep 17 00:00:00 2001
+From: Richard Hughes <richard hughsie com>
+Date: Fri, 16 Jul 2010 22:10:18 +0100
+Subject: [PATCH] strace: print usb traffic and add hex output pretty printing
+
+Based on a patch from http://iki.fi/lindi/strace-4.5.8-usbdevfs.diff
+---
+ Makefile.am | 2 +-
+ defs.h | 1 +
+ ioctl.c | 2 ++
+ 3 files changed, 4 insertions(+), 1 deletions(-)
+
+diff --git a/Makefile.am b/Makefile.am
+index c44762e..adb39dc 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -15,7 +15,7 @@ INCLUDES = -I$(srcdir)/$(OS)/$(ARCH) -I$(srcdir)/$(OS)
+ strace_SOURCES = strace.c syscall.c count.c util.c desc.c file.c ipc.c \
+ io.c ioctl.c mem.c net.c process.c bjm.c quota.c \
+ resource.c signal.c sock.c system.c term.c time.c \
+- proc.c scsi.c stream.c
++ usbdevfs.c proc.c scsi.c stream.c
+ noinst_HEADERS = defs.h
+
+ EXTRA_DIST = $(man_MANS) errnoent.sh signalent.sh syscallent.sh ioctlsort.c \
+diff --git a/defs.h b/defs.h
+index 419b12e..30a1eec 100644
+--- a/defs.h
++++ b/defs.h
+@@ -558,6 +558,7 @@ extern int stream_ioctl(struct tcb *, int, int);
+ #ifdef LINUX
+ extern int rtc_ioctl(struct tcb *, long, long);
+ extern int scsi_ioctl(struct tcb *, long, long);
++extern int usbdevfs_ioctl (struct tcb *, long, long);
+ #endif
+
+ extern int tv_nz(struct timeval *);
+diff --git a/ioctl.c b/ioctl.c
+index 906c71e..e75520c 100644
+--- a/ioctl.c
++++ b/ioctl.c
+@@ -154,6 +154,8 @@ long code, arg;
+ return rtc_ioctl(tcp, code, arg);
+ case 0x22:
+ return scsi_ioctl(tcp, code, arg);
++ case 0x55:
++ return usbdevfs_ioctl(tcp, code, arg);
+ #endif
+ default:
+ break;
+--
+1.7.1.1
+
diff --git a/docs/huey/annotate.sh b/docs/huey/annotate.sh
new file mode 100755
index 0000000..eb9e3f4
--- /dev/null
+++ b/docs/huey/annotate.sh
@@ -0,0 +1,9 @@
+./lcg-parse-huey usbdump usb-ambient.txt usb-ambient.parsed
+./lcg-parse-huey usbdump usb-init-cancel.txt usb-init-cancel.parsed
+./lcg-parse-huey usbdump usb-init.txt usb-init.parsed
+./lcg-parse-huey usbdump usb-profile-complete.txt usb-profile-complete.parsed
+./lcg-parse-huey usbdump usb-profile-complete-crt.txt usb-profile-complete-crt.parsed
+./lcg-parse-huey usbdump usb-startup.txt usb-startup.parsed
+./lcg-parse-huey usbdump usb-unlock.txt usb-unlock.parsed
+./lcg-parse-huey argylld9 argyll-spotread-verbose.txt argyll-spotread-verbose.parsed
+./lcg-parse-huey straceusb strace-spotread-usb.txt strace-spotread-usb.parsed
diff --git a/docs/huey/gcm-parse-huey.c b/docs/huey/gcm-parse-huey.c
index 2c5b318..f884935 100644
--- a/docs/huey/gcm-parse-huey.c
+++ b/docs/huey/gcm-parse-huey.c
@@ -95,7 +95,7 @@ get_command_string (guchar value)
}
static void
-parse_output (GString *output, const gchar *line, gboolean reply)
+parse_command_sequence (GString *output, const gchar *line, gboolean reply)
{
gchar **tok;
guint j;
@@ -129,6 +129,104 @@ out:
g_strfreev (tok);
}
+typedef enum {
+ GCM_PARSE_MODE_USBDUMP,
+ GCM_PARSE_MODE_ARGYLLD9,
+ GCM_PARSE_MODE_STRACEUSB
+} GcmParseMode;
+
+static void
+parse_line_argyll (GString *output, gchar *line, gboolean *reply)
+{
+ if (g_str_has_prefix (line, "huey: Sending cmd")) {
+ g_string_append (output, " ---> ");
+ *reply = FALSE;
+ }
+ if (g_str_has_prefix (line, "huey: Reading response")) {
+ g_string_append (output, " <--- ");
+ *reply = TRUE;
+ }
+ if (g_str_has_prefix (line, "icoms: Writing control data")) {
+ parse_command_sequence (output, &line[28], *reply);
+ }
+ if (g_str_has_prefix (line, " '")) {
+ line[21] = '\0';
+ /* argyll 'helpfully' removes the two bytes */
+ g_string_append (output, "00(success) xx(cmd) ");
+ g_string_append (output, &line[2]);
+ g_string_append (output, "\n");
+ }
+ if (g_strcmp0 (line, " ICOM err 0x0") == 0)
+ g_string_append (output, "\n");
+}
+
+static void
+parse_line_usbdump (GString *output, const gchar *line, gboolean *reply)
+{
+
+ /* timestamp */
+ if (line[0] == '[')
+ return;
+
+ /* function */
+ if (line[0] == '-') {
+ g_string_append (output, "\n");
+ if (g_str_has_suffix (line, "URB_FUNCTION_CLASS_INTERFACE:"))
+ g_string_append (output, "[class-interface] ");
+ else if (g_str_has_suffix (line, "URB_FUNCTION_CONTROL_TRANSFER:"))
+ g_string_append (output, "[control-transfer] ");
+ else if (g_str_has_suffix (line, "URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:"))
+ g_string_append (output, "[interrupt-transfer] ");
+ else
+ g_string_append (output, "[unknown] ");
+ }
+
+ if (g_strstr_len (line, -1, "USBD_TRANSFER_DIRECTION_IN") != NULL) {
+ g_string_append (output, " <--- ");
+ *reply = TRUE;
+ }
+ if (g_strstr_len (line, -1, "USBD_TRANSFER_DIRECTION_OUT") != NULL) {
+ g_string_append (output, " ---> ");
+ *reply = FALSE;
+ }
+
+ if (g_strstr_len (line, -1, "00000000:") != NULL) {
+ parse_command_sequence (output, &line[14], *reply);
+ }
+}
+
+static void
+parse_line_straceusb (GString *output, const gchar *line, gboolean *reply)
+{
+ gchar *tmp;
+
+ if (g_strstr_len (line, -1, "USBDEVFS") == NULL)
+ return;
+ if (g_strstr_len (line, -1, "EAGAIN") != NULL)
+ return;
+//make && ./gcm-parse-huey straceusb strace-spotread-usb.txt strace-spotread-usb.parsed && cat ./strace-spotread-usb.parsed
+ tmp = g_strstr_len (line, -1, "data=");
+ if (tmp == NULL) {
+ *reply = TRUE;
+ tmp = g_strstr_len (line, -1, "buffer=");
+ if (tmp == NULL)
+ return;
+ } else {
+ *reply = FALSE;
+ }
+
+ tmp[28] = '\0';
+ parse_command_sequence (output, tmp+5, *reply);
+ g_string_append (output, "\n");
+
+ return;
+
+ g_error ("@%s@", tmp+5);
+
+ g_string_append (output, line);
+ g_string_append (output, "\n");
+}
+
gint
main (gint argc, gchar *argv[])
{
@@ -140,16 +238,29 @@ main (gint argc, gchar *argv[])
guint i;
gchar *line;
gboolean reply = FALSE;
+ GcmParseMode mode = 0;
+
+ if (argc != 4) {
+ g_print ("need to specify mode then two files\n");
+ goto out;
+ }
- if (argc != 3) {
- g_print ("need to specify two files\n");
+ /* get the mode */
+ if (g_strcmp0 (argv[1], "usbdump") == 0)
+ mode = GCM_PARSE_MODE_USBDUMP;
+ else if (g_strcmp0 (argv[1], "argylld9") == 0)
+ mode = GCM_PARSE_MODE_ARGYLLD9;
+ else if (g_strcmp0 (argv[1], "straceusb") == 0)
+ mode = GCM_PARSE_MODE_STRACEUSB;
+ else {
+ g_print ("mode unrecognised, use strace, argylld9 or straceusb");
goto out;
}
- g_print ("parsing %s into %s... ", argv[1], argv[2]);
+ g_print ("parsing %s into %s... ", argv[2], argv[3]);
/* read file */
- ret = g_file_get_contents (argv[1], &data, NULL, &error);
+ ret = g_file_get_contents (argv[2], &data, NULL, &error);
if (!ret) {
g_print ("failed to read: %s\n", error->message);
g_error_free (error);
@@ -162,64 +273,18 @@ main (gint argc, gchar *argv[])
for (i=0; split[i] != NULL; i++) {
line = split[i];
- /* timestamp */
- if (line[0] == '[')
- continue;
-
- /* --------- argyll -D9 format --------- */
- if (g_str_has_prefix (line, "huey: Sending cmd")) {
- g_string_append (output, " ---> ");
- reply = FALSE;
- }
- if (g_str_has_prefix (line, "huey: Reading response")) {
- g_string_append (output, " <--- ");
- reply = TRUE;
- }
- if (g_str_has_prefix (line, "icoms: Writing control data")) {
- parse_output (output, &line[28], reply);
- }
- if (g_str_has_prefix (line, " '")) {
- line[21] = '\0';
- /* argyll 'helpfully' removes the two bytes */
- g_string_append (output, "00(success) xx(cmd) ");
- g_string_append (output, &line[2]);
- g_string_append (output, "\n");
- }
- if (g_strcmp0 (line, " ICOM err 0x0") == 0)
- g_string_append (output, "\n");
- /* --------- argyll -D9 format --------- */
-
- /* function */
- if (line[0] == '-') {
- g_string_append (output, "\n");
- if (g_str_has_suffix (line, "URB_FUNCTION_CLASS_INTERFACE:"))
- g_string_append (output, "[class-interface] ");
- else if (g_str_has_suffix (line, "URB_FUNCTION_CONTROL_TRANSFER:"))
- g_string_append (output, "[control-transfer] ");
- else if (g_str_has_suffix (line, "URB_FUNCTION_BULK_OR_INTERRUPT_TRANSFER:"))
- g_string_append (output, "[interrupt-transfer] ");
- else
- g_string_append (output, "[unknown] ");
- }
-
- if (g_strstr_len (line, -1, "USBD_TRANSFER_DIRECTION_IN") != NULL) {
- g_string_append (output, " <--- ");
- reply = TRUE;
- }
- if (g_strstr_len (line, -1, "USBD_TRANSFER_DIRECTION_OUT") != NULL) {
- g_string_append (output, " ---> ");
- reply = FALSE;
- }
-
- if (g_strstr_len (line, -1, "00000000:") != NULL) {
- parse_output (output, &line[14], reply);
- }
-
-// g_print ("%i:%s\n", i, split[i]);
+ if (mode == GCM_PARSE_MODE_ARGYLLD9)
+ parse_line_argyll (output, line, &reply);
+ else if (mode == GCM_PARSE_MODE_USBDUMP)
+ parse_line_usbdump (output, line, &reply);
+ else if (mode == GCM_PARSE_MODE_STRACEUSB)
+ parse_line_straceusb (output, line, &reply);
+ else
+ g_print ("%i:%s\n", i, split[i]);
}
/* write file */
- ret = g_file_set_contents (argv[2], output->str, -1, &error);
+ ret = g_file_set_contents (argv[3], output->str, -1, &error);
if (!ret) {
g_print ("failed to read: %s\n", error->message);
g_error_free (error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]