Eavesdropping on USB

I would like to use my Arduino to eavesdrop on a USB cable. I tried chopping the cable in half, and connecting the data lines to the Arduino, but USB is half duplex, so the Arduino ports need to read and write at the same time, which they can't do (otherwise, I could just write the data from one port to another). My knowledge of electronics isn't great, so it is possible that I am trying to do something impossible. Many thanks for any help.

Not easy to do at all. Here's a commercial product version of what you're trying to do:

http://www.totalphase.com/solutions/apps/usb_analyzer_guide/

Given that it starts at $400, that should give you a sense for the complexity of the problem.

--
The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

If you want to "spy" on serial data, such as capturing a trace of communication between to serial devices, the following software can be used.

http://com0com.sourceforge.net/

cybergeek11:
I would like to use my Arduino to eavesdrop on a USB cable. I tried chopping the cable in half, and connecting the data lines to the Arduino, but USB is half duplex, so the Arduino ports need to read and write at the same time, which they can't do (otherwise, I could just write the data from one port to another).

Actually USB is master/slave, so the slave only replies when the master asks it to. However after spending quite some time analyzing USB, I concluded that it is very complex. With a USB shield you might have some hope.

Since there are free programs to analyze USB traffic on the computer, couldn't I just use the Arduino to capture the raw data and then feed it into the computer? If so, how I can use the Arduino to capture raw traffic from a bidirectional cable? Again, many thanks.

Your issues are:

  1. USB is bi-directional.
    USB is a point to point protocol between the Host/Hub or the Device. However, there is only 1 set of differential signal lines. You need to monitor the JK chirps to determine which direction data is traveling. This isn't overly difficult but it isn't trivial either.

  2. There is a protocol stack.
    The 1's and 0's on USB are virtually meaningless. After you get the 1's and 0's you need to convert those into packets. Once you have the packets, you can decode the packets to determine what kind of transactions are happening. Once you decode the transactions, you can determine payloads. Until you know the transaction, you won't know if you are looking at "serial traffic" or enumeration data. The Payload then needs to be decoded so that you can get your "serial data."

This is why commercial USB sniffers tend to be expensive. There is a lot of stuff going on you don't really care about, but you have to measure and monitor so that you can see the stuff you care about.

  1. If the bus jumps to 12Mbit or 480Mbit, your arduino solution won't be able to keep up.
    Theoretically you could probably ignore the bit rate changes, but it'll likely to cause your data to be corrupted.

Long story short, the Arduino would make for a lousy USB analyzer.

Since there are free programs to analyze USB traffic on the computer

I don't think these are capturing data you think they are... They are probably giving you information very upstream on the protocol stack. They are probably not analyzing the 1's and 0's from the raw bus.

I would use Linux / wireshark to sniff on USB.

sudo modprobe usbmon
sudo wireshark &