serial gadget howto?

1,532 views
Skip to first unread message

Bass

unread,
Feb 14, 2017, 10:10:54 PM2/14/17
to USB armory
Has anyone gotten the USB CDC-ACM serial gadget device to work?  I'm not interested in having another login shell, but would like to use the serial gadget as a way for bidirectional serial communication with the USB Armory.

Thanks!

Bass

unread,
Feb 28, 2017, 7:11:15 PM2/28/17
to USB armory
For anyone that's curious, I got this working, but had to go the Linux configfs route with libcomposite.

Bass

unread,
Mar 3, 2017, 12:59:21 AM3/3/17
to USB armory
I had a request for how I set this up.  Here's a shell script below that should expose serial, ethernet, and storage to a Linux host (Windows hosts are possible, but a pain due to driver issues).  Adding additional gadgets, such as HID, MIDI, etc., just requires digging into configfs and researching how those devices are created.  
Here's a doc to help get started: https://www.kernel.org/doc/Documentation/usb/gadget_configfs.txt
This was a helpful tutorial too: https://hackaday.io/project/10387-gadget/log/34463-on-windows-drivers-and-usb-gadgets


#!/bin/bash

set -euf -o pipefail

readonly GADGET_BASE_DIR="/sys/kernel/config/usb_gadget/g1"
readonly DEV_ETH_ADDR="aa:bb:cc:dd:ee:f1"
readonly HOST_ETH_ADDR="aa:bb:cc:dd:ee:f2"
readonly USBDISK="/usbdisk.img"

modprobe -r g_ether usb_f_ecm u_ether
modprobe libcomposite

# Create directory structure
mkdir "${GADGET_BASE_DIR}"
cd "${GADGET_BASE_DIR}"
mkdir -p configs/c.1/strings/0x409
mkdir -p strings/0x409

# Serial device
###
mkdir functions/acm.usb0
ln -s functions/acm.usb0 configs/c.1/
###

# Ethernet device
###
mkdir functions/ecm.usb0
echo "${DEV_ETH_ADDR}" > functions/ecm.usb0/dev_addr
echo "${HOST_ETH_ADDR}" > functions/ecm.usb0/host_addr
ln -s functions/ecm.usb0 configs/c.1/
###

# Mass Storage device
###
mkdir functions/mass_storage.usb0
echo 1 > functions/mass_storage.usb0/stall
echo 0 > functions/mass_storage.usb0/lun.0/cdrom
echo 0 > functions/mass_storage.usb0/lun.0/ro
echo 0 > functions/mass_storage.usb0/lun.0/nofua
echo "${USBDISK}" > functions/mass_storage.usb0/lun.0/file
ln -s functions/mass_storage.usb0 configs/c.1/
###

# Composite Gadget Setup
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
echo "0123456789abcdef" > strings/0x409/serialnumber
echo "USBArmory" > strings/0x409/manufacturer
echo "USBArmory Gadget" > strings/0x409/product
echo "Conf1" > configs/c.1/strings/0x409/configuration
echo 120 > configs/c.1/MaxPower

# Activate gadgets
echo ci_hdrc.0 > UDC
Reply all
Reply to author
Forward
0 new messages