summaryrefslogtreecommitdiffstats
path: root/src/libusb-sniff.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2012-09-22 10:20:49 +0200
committerPali Rohár <pali.rohar@gmail.com>2012-09-22 10:20:49 +0200
commit805bafacef08fd8c05a75f939e536c32ede50e22 (patch)
tree2cf3537c0c90bdbe704c3dc5118b331b5a71671d /src/libusb-sniff.c
parent40cd74c506390f18bc22d3b5c0b1ba2e618c2b82 (diff)
download0xFFFF-805bafacef08fd8c05a75f939e536c32ede50e22.tar.bz2
libusb-sniff: Disable printing output of libusb function if env USBSNIFF_SKIP_* is set
Diffstat (limited to 'src/libusb-sniff.c')
-rw-r--r--src/libusb-sniff.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/src/libusb-sniff.c b/src/libusb-sniff.c
index 9477a3f..651e888 100644
--- a/src/libusb-sniff.c
+++ b/src/libusb-sniff.c
@@ -19,6 +19,7 @@
/* compile: gcc libusb-sniff.c -o libusb-sniff.so -W -Wall -O2 -fPIC -ldl -shared -m32 */
/* usage: sudo USBSNIFF_WAIT=1 LD_PRELOAD=./libusb-sniff.so flasher-3.5 ... */
+/* usage: sudo USBSNIFF_SKIP_READ=1 USBSNIFF_SKIP_WRITE=1 LD_PRELOAD=./libusb-sniff.so flasher-3.5 ... */
#define _GNU_SOURCE
#include <stdio.h>
@@ -69,12 +70,16 @@ int usb_bulk_write(usb_dev_handle * dev, int ep, const char * bytes, int size, i
if ( ! real_usb_bulk_write )
real_usb_bulk_write = dlsym(RTLD_NEXT, "usb_bulk_write");
- printf("\n==== usb_bulk_write (ep=%d size=%d timeout=%d) ====\n", ep, size, timeout);
- dump_bytes(bytes, size);
- printf("====\n");
+ if ( ! getenv("USBSNIFF_SKIP_WRITE") ) {
+
+ printf("\n==== usb_bulk_write (ep=%d size=%d timeout=%d) ====\n", ep, size, timeout);
+ dump_bytes(bytes, size);
+ printf("====\n");
+
+ if ( getenv("USBSNIFF_WAIT") ) {
+ printf("Press ENTER"); fflush(stdout); getchar();
+ }
- if ( getenv("USBSNIFF_WAIT") ) {
- printf("Press ENTER"); fflush(stdout); getchar();
}
return real_usb_bulk_write(dev, ep, bytes, size, timeout);
@@ -91,14 +96,18 @@ int usb_bulk_read(usb_dev_handle * dev, int ep, char * bytes, int size, int time
ret = real_usb_bulk_read(dev, ep, bytes, size, timeout);
- printf("\n==== usb_bulk_read (ep=%d size=%d timeout=%d) ret = %d ====\n", ep, size, timeout, ret);
- if ( ret > 0 ) {
- dump_bytes(bytes, ret);
- printf("====\n");
- }
+ if ( ! getenv("USBSNIFF_SKIP_READ") ) {
+
+ printf("\n==== usb_bulk_read (ep=%d size=%d timeout=%d) ret = %d ====\n", ep, size, timeout, ret);
+ if ( ret > 0 ) {
+ dump_bytes(bytes, ret);
+ printf("====\n");
+ }
+
+ if ( getenv("USBSNIFF_WAIT") ) {
+ printf("Press ENTER"); fflush(stdout); getchar();
+ }
- if ( getenv("USBSNIFF_WAIT") ) {
- printf("Press ENTER"); fflush(stdout); getchar();
}
return ret;
@@ -115,14 +124,18 @@ int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value
ret = real_usb_control_msg(dev, requesttype, request, value, index, bytes, size, timeout);
- printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ret = %d ====\n", requesttype, request, value, index, size, timeout, ret);
- if ( ret > 0 ) {
- dump_bytes(bytes, ret);
- printf("====\n");
- }
+ if ( ! getenv("USBSNIFF_SKIP_CONTROL") ) {
+
+ printf("\n==== usb_control_msg(requesttype=%d, request=%d, value=%d, index=%d, size=%d, timeout=%d) ret = %d ====\n", requesttype, request, value, index, size, timeout, ret);
+ if ( ret > 0 ) {
+ dump_bytes(bytes, ret);
+ printf("====\n");
+ }
+
+ if ( getenv("USBSNIFF_WAIT") ) {
+ printf("Press ENTER"); fflush(stdout); getchar();
+ }
- if ( getenv("USBSNIFF_WAIT") ) {
- printf("Press ENTER"); fflush(stdout); getchar();
}
return ret;