This is a first post on how to set up the sniffing of USB Power Delivery packets.
You need the following things. This is a rough list for an overview, details will follow:
- Linux machine to run Ubuntu
- A device that charges over USB-C
- Plugable USB-TKEY (hereafter called Twinkie)
- Software: Sigrok library/commandline utility to retrieve traffic from Twinkie, PulseView to decode/display it
If you don’t have a separate machine, then a virtual machine is also an option. We’ve prepared an Ubuntu image that’s usable in VirtualBox and made it available over BitTorrent: magnet link. If you use this, go straight to the section “Communication with the Twinkie”.
The most simple setup however remains a separate machine for sniffing. Here’s a picture:
What you see is a MacBook that charges over the white/silver Moshi USB-C cable. There’s the Twinkie in between, to sniff the traffic. The Dell Inspiron is an old laptop with Ubuntu installed, to communicate with the Twinkie over the black USB-A-to-micro-USB cable.
How to set this up
First, you’ll need a machine with Ubuntu 14.04.5 LTS (Trusty Tahr). Although not the latest version, this is by far the easiest way because then you won’t need to worry about dependencies and building from source. So download Ubuntu 14.04 and create a USB stick with for example UNetbootin.
When you’ve installed that on your PC/laptop, you’re now ready to install the software. Detailed instruction are provided by the Chromium team, but the short version is as follows:
Download the chromium-sigrok.list file and copy it to the apt sources directory. Then update apt, and install sigrok and PulseView:
$ wget "https://www.chromium.org/chromium-os/twinkie/chromium-sigrok.list" $ sudo cp chromium-sigrok.list /etc/apt/sources.list.d $ sudo apt-get update $ sudo apt-get install sigrok
Besides using sigrok, you can also connect to the Twinkie with a terminal because it can behave like a serial device. Add your user to the dialout group as follows:
$ sudo usermod -a -G dialout $(whoami)
This makes your user able to access the serial port. Log out and log in again. On the terminal check that you were added (the bold group):
$ id uid=1000(usbc)gid=1000(usbc)groups=1000(usbc),4(adm),20(dialout),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin),124(sambashare)
Then install minicom (a program to communicate with serial devices)
$ sudo apt-get install minicom
Communication with the Twinkie
To test, hook up the Twinkie without actually attaching any USB-C devices. Then type the following:
$ sudo sigrok-cli -d chromium-twinkie --time 3000 -o test.cr
This basically says, poll the twinkie for three seconds, and dump the results in a file called test.cr. If all is well, then after three seconds, the commandline should return.
Start minicom as follows:
$ minicom -D /dev/ttyUSB0
If all is well, then minicom appears full-screen. Press enter a couple of times, and you should be presented with a prompt.
Give the version command:
This should report the Twinkie version and should look as below. Exit minicom with CTRL-A, then press X.
Next post, we’ll detail how to actually display and decode USB-PD traffic!
Troubleshooting: driver chromium-twinkie not found
If you get the error “driver chromium-twinkie not found”, then somehow, you didn’t install the correct version of sigrok.
Troubleshooting: cannot open /dev/ttyUSB0
If the Twinkie is not connected, or there is a problem with Linux, you’ll get the response:
minicom: cannot open /dev/ttyUSB0: No such file or directory
This could mean a couple of things.
If you’re running Linux in VirtualBox, then your device might not be connected to the virtual machine. Go to menu Devices -> USB and make sure Plugable Twinkie is checked:
If you’ve done this, and you still get the message, then you need to disconnect the device, shutdown and start the virtual machine again, connect the Twinkie and use the Devices menu to connect it to the virtual machine.