<<

USB gadget Congfs Userspace

Make your own USB gadget Kernel and userspace

Andrzej Pietrasiewicz

Samsung R&D Institute Poland Warsaw, Poland [email protected]

August 20, 2014

LinuxCon North America 2014 your own USB gadget 1 / 34 USB gadget Congfs Userspace Table of Contents

1 USB gadget USB and functions USB gadget Gadget implementation in

2 Congfs The idea, example On implementation Status

3 Userspace libusbg & tools gadgetd & application API

4 Q&A

LinuxCon North America 2014 Make your own USB gadget 2 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux += function

flash drive USB: host, device 4G MODEM 16 GB extend the host with some function(s)

LinuxCon North America 2014 Make your own USB gadget 3 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux USB device composition

CONFIG 1 CONFIG 2

CONFIG 3 functions

LinuxCon North America 2014 Make your own USB gadget 4 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux enumeration

Device connected, presents itself Host decides what to do and how to to it

LinuxCon North America 2014 Make your own USB gadget 5 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux gadget = UDC + function(s)

A piece in hardware: UDC/OTG/ Functions: HW or SW << something >>

usb_gadget_driver

HOST UDC (e.g. s3c-hsotg) "gadget" Linux system

LinuxCon North America 2014 Make your own USB gadget 6 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux composite framework

out repeated parts of code drivers/usb/gadget/composite.c reusable functions' implementations f_acm.c f_serial.c f_obex.c f_ecm.c, f_ecm_subset.c, f_eem.c, f_ncm.c, f_rndis.c f_phonet.c f_mass_storage.c f_uvc.c f_uac1.c, f_uac2.c f_midi.c ...

LinuxCon North America 2014 Make your own USB gadget 7 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux gadgets proper: g_xyz.c / g_xyz kernel modules

hardcoded (!) congurations/functions/identity module parameters

LinuxCon North America 2014 Make your own USB gadget 8 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux Greg

Fact Why I don't want He doesn't want my code! your code

Fact Linux Kernel Maintainers, He wouldn't want your code, why are they so grumpy

either :O Greg Kroah-Hartman [email protected]

LinuxCon North America 2014 Make your own USB gadget 9 / 34 USB gadget USB and functions Congfs USB gadget Userspace Gadget implementation in Linux Greg

Fact Why I don't want He doesn't want my code! your code

Fact Linux Kernel Maintainers, He wouldn't want your code, why are they so grumpy

either :O Greg Kroah-Hartman [email protected]

LinuxCon North America 2014 Make your own USB gadget 9 / 34 USB gadget The idea, example Congfs On implementation Userspace Status Separate code from data

decouple the information on actual gadget composition from implementation only provide building blocks (mechanism, not policy)

LinuxCon North America 2014 Make your own USB gadget 10 / 34 USB gadget The idea, example Congfs On implementation Userspace Status Let the user decide runtime

action lesystem create make directory destroy remove directory specify value get value (execute for directory) group things symlink ungroup things remove symlink

Command reference , 'something' > , file, directory -s,

LinuxCon North America 2014 Make your own USB gadget 11 / 34 drwxr-xr-x . drwxr-xr-x ./strings drwxr-xr-x ./configs drwxr-xr-x ./functions -rw-r--r-- ./UDC -rw-r--r-- ./bcdUSB $ none cfg -t configfs cfg/usb_gadget -rw-r--r-- ./bcdDevice $ mkdir cfg/usb_gadget/g1 -rw-r--r-- ./idProduct $ cfg/usb_gadget/g1 -rw-r--r-- ./idVendor -rw-r--r-- ./bMaxPacketSize0 $ echo "0x05e8" > idVendor -rw-r--r-- ./bDeviceProtocol $ echo "0xa4a1" > idProduct -rw-r--r-- ./bDeviceSubClass $ mkdir strings/0x409 -rw-r--r-- ./bDeviceClass $ echo "serialnumber" > strings/0x409/serialnumber $ echo "manufacturer" > strings/0x409/manufacturer $ echo "RNDIS Gadget" > strings/0x409/product

USB gadget The idea, example Congfs On implementation Userspace Status Example

Example's prologue $ modprobe libcomposite

LinuxCon North America 2014 Make your own USB gadget 12 / 34 drwxr-xr-x . drwxr-xr-x ./strings drwxr-xr-x ./configs drwxr-xr-x ./functions -rw-r--r-- ./UDC -rw-r--r-- ./bcdUSB -rw-r--r-- ./bcdDevice $ mkdir cfg/usb_gadget/g1 -rw-r--r-- ./idProduct $ cd cfg/usb_gadget/g1 -rw-r--r-- ./idVendor -rw-r--r-- ./bMaxPacketSize0 $ echo "0x05e8" > idVendor -rw-r--r-- ./bDeviceProtocol $ echo "0xa4a1" > idProduct -rw-r--r-- ./bDeviceSubClass $ mkdir strings/0x409 -rw-r--r-- ./bDeviceClass $ echo "serialnumber" > strings/0x409/serialnumber $ echo "manufacturer" > strings/0x409/manufacturer $ echo "RNDIS Gadget" > strings/0x409/product

USB gadget The idea, example Congfs On implementation Userspace Status Example

Example's prologue $ modprobe libcomposite $ mount none cfg -t configfs cfg/usb_gadget

LinuxCon North America 2014 Make your own USB gadget 12 / 34 $ echo "0x05e8" > idVendor $ echo "0xa4a1" > idProduct $ mkdir strings/0x409 $ echo "serialnumber" > strings/0x409/serialnumber $ echo "manufacturer" > strings/0x409/manufacturer $ echo "RNDIS Gadget" > strings/0x409/product

USB gadget The idea, example Congfs On implementation Userspace Status Example

drwxr-xr-x . drwxr-xr-x ./strings Example's prologue drwxr-xr-x ./configs drwxr-xr-x ./functions $ modprobe libcomposite -rw-r--r-- ./UDC -rw-r--r-- ./bcdUSB $ mount none cfg -t configfs cfg/usb_gadget -rw-r--r-- ./bcdDevice $ mkdir cfg/usb_gadget/g1 -rw-r--r-- ./idProduct $ cd cfg/usb_gadget/g1 -rw-r--r-- ./idVendor -rw-r--r-- ./bMaxPacketSize0 -rw-r--r-- ./bDeviceProtocol -rw-r--r-- ./bDeviceSubClass -rw-r--r-- ./bDeviceClass

LinuxCon North America 2014 Make your own USB gadget 12 / 34 $ mkdir strings/0x409 $ echo "serialnumber" > strings/0x409/serialnumber $ echo "manufacturer" > strings/0x409/manufacturer $ echo "RNDIS Gadget" > strings/0x409/product

USB gadget The idea, example Congfs On implementation Userspace Status Example

drwxr-xr-x . drwxr-xr-x ./strings Example's prologue drwxr-xr-x ./configs drwxr-xr-x ./functions $ modprobe libcomposite -rw-r--r-- ./UDC -rw-r--r-- ./bcdUSB $ mount none cfg -t configfs cfg/usb_gadget -rw-r--r-- ./bcdDevice $ mkdir cfg/usb_gadget/g1 -rw-r--r-- ./idProduct $ cd cfg/usb_gadget/g1 -rw-r--r-- ./idVendor -rw-r--r-- ./bMaxPacketSize0 $ echo "0x05e8" > idVendor -rw-r--r-- ./bDeviceProtocol $ echo "0xa4a1" > idProduct -rw-r--r-- ./bDeviceSubClass -rw-r--r-- ./bDeviceClass

LinuxCon North America 2014 Make your own USB gadget 12 / 34 USB gadget The idea, example Congfs On implementation Userspace Status Example

drwxr-xr-x . drwxr-xr-x ./strings Example's prologue drwxr-xr-x ./configs drwxr-xr-x ./functions $ modprobe libcomposite -rw-r--r-- ./UDC -rw-r--r-- ./bcdUSB $ mount none cfg -t configfs cfg/usb_gadget -rw-r--r-- ./bcdDevice $ mkdir cfg/usb_gadget/g1 -rw-r--r-- ./idProduct $ cd cfg/usb_gadget/g1 -rw-r--r-- ./idVendor -rw-r--r-- ./bMaxPacketSize0 $ echo "0x05e8" > idVendor -rw-r--r-- ./bDeviceProtocol $ echo "0xa4a1" > idProduct -rw-r--r-- ./bDeviceSubClass $ mkdir strings/0x409 -rw-r--r-- ./bDeviceClass $ echo "serialnumber" > strings/0x409/serialnumber $ echo "manufacturer" > strings/0x409/manufacturer $ echo "RNDIS Gadget" > strings/0x409/product

LinuxCon North America 2014 Make your own USB gadget 12 / 34 $ mkdir configs/c.1 $ mkdir configs/c.1/strings/0x409 $ echo Conf 1 > configs/c.1/strings/0x409/configuration $ echo 120 > configs/c.1/MaxPower $ ln -s functions/rndis.usb0 configs/c.1 $ echo 12480000.hsotg > UDC $ ls /sys/class/udc 12480000.hsotg bind! # formerly s3c-hsotg

USB gadget The idea, example Congfs On implementation Userspace Status One cong, one function

Example $ mkdir functions/rndis.usb0

LinuxCon North America 2014 Make your own USB gadget 13 / 34 $ ln -s functions/rndis.usb0 configs/c.1 $ echo 12480000.hsotg > UDC $ ls /sys/class/udc 12480000.hsotg bind! # formerly s3c-hsotg

USB gadget The idea, example Congfs On implementation Userspace Status One cong, one function

Example $ mkdir functions/rndis.usb0 $ mkdir configs/c.1 $ mkdir configs/c.1/strings/0x409 $ echo Conf 1 > configs/c.1/strings/0x409/configuration $ echo 120 > configs/c.1/MaxPower

LinuxCon North America 2014 Make your own USB gadget 13 / 34 $ echo 12480000.hsotg > UDC $ ls /sys/class/udc 12480000.hsotg bind! # formerly s3c-hsotg

USB gadget The idea, example Congfs On implementation Userspace Status One cong, one function

Example $ mkdir functions/rndis.usb0 $ mkdir configs/c.1 $ mkdir configs/c.1/strings/0x409 $ echo Conf 1 > configs/c.1/strings/0x409/configuration $ echo 120 > configs/c.1/MaxPower $ ln -s functions/rndis.usb0 configs/c.1

LinuxCon North America 2014 Make your own USB gadget 13 / 34 USB gadget The idea, example Congfs On implementation Userspace Status One cong, one function

Example $ mkdir functions/rndis.usb0 $ mkdir configs/c.1 $ mkdir configs/c.1/strings/0x409 $ echo Conf 1 > configs/c.1/strings/0x409/configuration $ echo 120 > configs/c.1/MaxPower $ ln -s functions/rndis.usb0 configs/c.1 $ echo 12480000.hsotg > UDC $ ls /sys/class/udc 12480000.hsotg bind! # formerly s3c-hsotg

LinuxCon North America 2014 Make your own USB gadget 13 / 34 $ cd functions # $CONFIGFS_ROOT/usb_gadget/g1/functions $ echo RNDIS > \ rndis.usb0/os_desc/interface.rndis/compatible_id

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

expected by some proprietary OSes (ab)use string #EE hex, language 0 if present and has expected structure, use custom requests "Extended Compatibility" descriptors "Extended Properties" descriptors

Example - extended compatibility

LinuxCon North America 2014 Make your own USB gadget 14 / 34 $ echo RNDIS > \ rndis.usb0/os_desc/interface.rndis/compatible_id

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

expected by some proprietary OSes (ab)use string #EE hex, language 0 if present and has expected structure, use custom requests "Extended Compatibility" descriptors "Extended Properties" descriptors

Example - extended compatibility $ cd functions # $CONFIGFS_ROOT/usb_gadget/g1/functions

LinuxCon North America 2014 Make your own USB gadget 14 / 34 USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

expected by some proprietary OSes (ab)use string #EE hex, language 0 if present and has expected structure, use custom requests "Extended Compatibility" descriptors "Extended Properties" descriptors

Example - extended compatibility $ cd functions # $CONFIGFS_ROOT/usb_gadget/g1/functions $ echo RNDIS > \ rndis.usb0/os_desc/interface.rndis/compatible_id

LinuxCon North America 2014 Make your own USB gadget 14 / 34 $ echo 2 \ > rndis.usb0/os_desc/interface.rndis/Icons/ $ echo "%SystemRoot%\system32\shell32.dll,-233" \ > rndis.usb0/os_desc/interface.rndis/Icons/data $ mkdir rndis.usb0/os_desc/interface.rndis/Label $ echo 1 \ > rndis.usb0/os_desc/interface.rndis/Label/type $ echo "XYZ Device" \ > rndis.usb0/os_desc/interface.rndis/Label/data

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - extended properties $ mkdir rndis.usb0/os_desc/interface.rndis/Icons

LinuxCon North America 2014 Make your own USB gadget 15 / 34 $ echo "%SystemRoot%\system32\shell32.dll,-233" \ > rndis.usb0/os_desc/interface.rndis/Icons/data $ mkdir rndis.usb0/os_desc/interface.rndis/Label $ echo 1 \ > rndis.usb0/os_desc/interface.rndis/Label/type $ echo "XYZ Device" \ > rndis.usb0/os_desc/interface.rndis/Label/data

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - extended properties $ mkdir rndis.usb0/os_desc/interface.rndis/Icons $ echo 2 \ > rndis.usb0/os_desc/interface.rndis/Icons/type

LinuxCon North America 2014 Make your own USB gadget 15 / 34 $ mkdir rndis.usb0/os_desc/interface.rndis/Label $ echo 1 \ > rndis.usb0/os_desc/interface.rndis/Label/type $ echo "XYZ Device" \ > rndis.usb0/os_desc/interface.rndis/Label/data

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - extended properties $ mkdir rndis.usb0/os_desc/interface.rndis/Icons $ echo 2 \ > rndis.usb0/os_desc/interface.rndis/Icons/type $ echo "%SystemRoot%\system32\shell32.dll,-233" \ > rndis.usb0/os_desc/interface.rndis/Icons/data

LinuxCon North America 2014 Make your own USB gadget 15 / 34 $ echo 1 \ > rndis.usb0/os_desc/interface.rndis/Label/type $ echo "XYZ Device" \ > rndis.usb0/os_desc/interface.rndis/Label/data

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - extended properties $ mkdir rndis.usb0/os_desc/interface.rndis/Icons $ echo 2 \ > rndis.usb0/os_desc/interface.rndis/Icons/type $ echo "%SystemRoot%\system32\shell32.dll,-233" \ > rndis.usb0/os_desc/interface.rndis/Icons/data $ mkdir rndis.usb0/os_desc/interface.rndis/Label

LinuxCon North America 2014 Make your own USB gadget 15 / 34 $ echo "XYZ Device" \ > rndis.usb0/os_desc/interface.rndis/Label/data

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - extended properties $ mkdir rndis.usb0/os_desc/interface.rndis/Icons $ echo 2 \ > rndis.usb0/os_desc/interface.rndis/Icons/type $ echo "%SystemRoot%\system32\shell32.dll,-233" \ > rndis.usb0/os_desc/interface.rndis/Icons/data $ mkdir rndis.usb0/os_desc/interface.rndis/Label $ echo 1 \ > rndis.usb0/os_desc/interface.rndis/Label/type

LinuxCon North America 2014 Make your own USB gadget 15 / 34 USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - extended properties $ mkdir rndis.usb0/os_desc/interface.rndis/Icons $ echo 2 \ > rndis.usb0/os_desc/interface.rndis/Icons/type $ echo "%SystemRoot%\system32\shell32.dll,-233" \ > rndis.usb0/os_desc/interface.rndis/Icons/data $ mkdir rndis.usb0/os_desc/interface.rndis/Label $ echo 1 \ > rndis.usb0/os_desc/interface.rndis/Label/type $ echo "XYZ Device" \ > rndis.usb0/os_desc/interface.rndis/Label/data

LinuxCon North America 2014 Make your own USB gadget 15 / 34 $ echo 0xcd > os_desc/b_vendor_code $ echo MSFT100 > os_desc/qw_sign $ ln -s configs/c.1 os_desc $ echo 1 > os_desc/use

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - activate $ cd ../ # $CONFIGFS_ROOT/usb_gadget/g1

LinuxCon North America 2014 Make your own USB gadget 16 / 34 $ echo MSFT100 > os_desc/qw_sign $ ln -s configs/c.1 os_desc $ echo 1 > os_desc/use

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - activate $ cd ../ # $CONFIGFS_ROOT/usb_gadget/g1 $ echo 0xcd > os_desc/b_vendor_code

LinuxCon North America 2014 Make your own USB gadget 16 / 34 $ ln -s configs/c.1 os_desc $ echo 1 > os_desc/use

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - activate $ cd ../ # $CONFIGFS_ROOT/usb_gadget/g1 $ echo 0xcd > os_desc/b_vendor_code $ echo MSFT100 > os_desc/qw_sign

LinuxCon North America 2014 Make your own USB gadget 16 / 34 $ echo 1 > os_desc/use

USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - activate $ cd ../ # $CONFIGFS_ROOT/usb_gadget/g1 $ echo 0xcd > os_desc/b_vendor_code $ echo MSFT100 > os_desc/qw_sign $ ln -s configs/c.1 os_desc

LinuxCon North America 2014 Make your own USB gadget 16 / 34 USB gadget The idea, example Congfs On implementation Userspace Status OS Descriptors

Example - activate $ cd ../ # $CONFIGFS_ROOT/usb_gadget/g1 $ echo 0xcd > os_desc/b_vendor_code $ echo MSFT100 > os_desc/qw_sign $ ln -s configs/c.1 os_desc $ echo 1 > os_desc/use

LinuxCon North America 2014 Make your own USB gadget 16 / 34 config functionfunction

config functionfunction

config function

No g_xyz.ko modules!

USB gadget The idea, example Congfs On implementation Userspace Status Static composittion vs composition with congfs

Traditional g_xyz.ko modules directly #included f_*.c!

static composition congfs composition

config function

config function

config function

LinuxCon North America 2014 Make your own USB gadget 17 / 34 Traditional g_xyz.ko modules directly #included f_*.c!

config functionfunction

config functionfunction

config function

No g_xyz.ko modules!

USB gadget The idea, example Congfs On implementation Userspace Status Static composittion vs composition with congfs

static composition congfs composition

config function config function

config function config function

config function

LinuxCon North America 2014 Make your own USB gadget 17 / 34 Traditional g_xyz.ko modules directly #included f_*.c!

config function

config function

config function

No g_xyz.ko modules!

USB gadget The idea, example Congfs On implementation Userspace Status Static composittion vs composition with congfs

static composition congfs composition

config function config function

config function config function

config function

LinuxCon North America 2014 Make your own USB gadget 17 / 34 Traditional g_xyz.ko modules directly #included f_*.c!

config functionfunction

config functionfunction

config function

No g_xyz.ko modules!

USB gadget The idea, example Congfs On implementation Userspace Status Static composittion vs composition with congfs

static composition congfs composition

config function config function

config function config function

config function config function

LinuxCon North America 2014 Make your own USB gadget 17 / 34 Traditional g_xyz.ko modules directly #included f_*.c!

config function

config function

config function

No g_xyz.ko modules!

USB gadget The idea, example Congfs On implementation Userspace Status Static composittion vs composition with congfs

static composition congfs composition

config function config function

config function config function

config function config function

LinuxCon North America 2014 Make your own USB gadget 17 / 34 Traditional g_xyz.ko modules directly #included f_*.c!

config function

config function

config function

USB gadget The idea, example Congfs On implementation Userspace Status Static composittion vs composition with congfs

static composition congfs composition

config function config function

config function config function

config function config function

No g_xyz.ko modules!

LinuxCon North America 2014 Make your own USB gadget 17 / 34 USB gadget The idea, example Congfs On implementation Userspace Status Function registration framework

$ mkdir function/rndis.usb0

request_module()

Sebastian Andrzej Siewior

LinuxCon North America 2014 Make your own USB gadget 18 / 34 USB gadget The idea, example Congfs On implementation Userspace Status Mapping of generic lesystem concepts to congfs entities

directory : cong_item (cong_group) le : congfs_attribute mkdir : congfs_mkdir()->make_item() (make_group()) read, write : show(), store() ln -s : allow_link() see : Documentation/lesystems/congfs/congfs.txt

structure data to be set

attribute (*show)(structure *, buffer) (*store)(structure *, buffer)

struct struct config_item configfs_attribute

dentry->d_fsdata->s_element $CONFIGFS_ROOT/structure/attribute

LinuxCon North America 2014 Make your own USB gadget 19 / 34 USB gadget The idea, example Congfs On implementation Userspace Status usb_function_instance

$ mkdir function/rndis.usb0

user-accessible conguration data of this specic instance legacy gadgets ≈ hardcoded

LinuxCon North America 2014 Make your own USB gadget 20 / 34 USB gadget The idea, example Congfs On implementation Userspace Status usb_function

$ ln -s function/rndis.usb0 configs/c.1

/* struct */

usb_function composite function - speci fi c

the same as in legacy gadgets composing a gadget (legacy/congfs) ends up providing this see: drivers/usb/gadget

LinuxCon North America 2014 Make your own USB gadget 21 / 34 USB gadget The idea, example Congfs On implementation Userspace Status FunctionFS vs congfs

delegate function implementation to userspace mount FunctionFS write descriptors to ep0 read/write/poll ep[1-]

ptp instance instance

ep0 ep0 ep0

ep1 ep1 ep1 ep2 ep2 ep3 congfs: only create FunctionFS instances eg $CONFIGFS_ROOT/usb_gadget/gadget/functions/s.ptp

LinuxCon North America 2014 Make your own USB gadget 22 / 34 USB gadget The idea, example Congfs On implementation Userspace Status Some

Sebastian Andrzej Siewior idea (Decmber 2011) function registration interface f_acm.c conversion to the function registration interface f_acm.c congfs support (December 2012) Andrzej Pietrasiewicz From where he left o, I took over

LinuxCon North America 2014 Make your own USB gadget 23 / 34 USB gadget The idea, example Congfs On implementation Userspace Status Status matrix

with congfs f_acm.c f_ecm.c f_eem.c f_ncm.c f_obex.c f_phonet.c f_rndis.c f_serial.c f_subset.c f_mass_storage.c f_fs.c f_loopback.c f_sourcesink.c f_uac1.c f_uac2.c f_uvc.c f_hid.c f_midi.c

legacy gadget components g_hid g_midi g_cdc g_ether g_ncm g_serial g_nokia g_multi g_acm_ms g_mass_storage g_s g_zero g_audio g_webcam gmainlineg lsent/RFCg ltodoj lunusedj LinuxCon North America 2014 Make your own USB gadget 24 / 34 USB gadget The idea, example Congfs On implementation Userspace Status TODO

f_midi, f_hid remove legacy gadgets - some (perhaps long) in the future gadgets not using composite framework

LinuxCon North America 2014 Make your own USB gadget 25 / 34 $ modprobe libcomposite $ mount none cfg -t configfs $ mkdir cfg/usb_gadget/g1 $ cd cfg/usb_gadget/g1 $ echo 0x04e8 > idVendor $ echo 0xa4a1 > idProduct $ echo Foo > strings/0x409/manufacturer $ echo Bar > strings/0x409/product $ echo 123 > strings/0x409/serialnumber $ mkdir configs/c.1 $ mkdir strings/0x409 $ mkdir configs/c.1/strings/0x409 $ echo "Conf 1" > configs/c.1/strings/0x409/configuration $ mkdir functions/ecm.usb0 $ ln -s functions/ecm.usb0 configs/c.1 $ echo 12480000.hsotg > UDC

USB gadget libusbg & tools Congfs gadgetd & application API Userspace userspace

With congfs ease of use is not concerned Composing is not dicult, but tedious (at the very least ≈20 shell commands) I want my "modprobe g_ether"!!! shell script dedicated userspace program

LinuxCon North America 2014 Make your own USB gadget 26 / 34 USB gadget libusbg & tools Congfs gadgetd & application API Userspace userspace

With congfs ease of use is not concerned Composing is not dicult, but tedious (at the very least ≈20 shell commands) I want my "modprobe g_ether"!!! shell script dedicated userspace program

$ modprobe libcomposite $ mount none cfg -t configfs $ mkdir cfg/usb_gadget/g1 $ cd cfg/usb_gadget/g1 $ echo 0x04e8 > idVendor $ echo 0xa4a1 > idProduct $ echo Foo > strings/0x409/manufacturer $ echo Bar > strings/0x409/product $ echo 123 > strings/0x409/serialnumber $ mkdir configs/c.1 $ mkdir strings/0x409 $ mkdir configs/c.1/strings/0x409 $ echo "Conf 1" > configs/c.1/strings/0x409/configuration $ mkdir functions/ecm.usb0 $ ln -s functions/ecm.usb0 configs/c.1 $ echo 12480000.hsotg > UDC

LinuxCon North America 2014 Make your own USB gadget 26 / 34 attrs = { idVendor = 0x04e8; idProduct = 0xa4a1; } strings = ( { lang = 0x409; manufacturer = "Foo"; product = "Bar"; serialnumber = "123"; } ) configs = ( { name = "c" id = 1 strings = ( { lang = 0x409; configuration = "Conf 1"; } ) functions = ( { function = { type = "ecm"; instance = "usb0"; } } ) } )

USB gadget libusbg & tools Congfs gadgetd & application API Userspace libusbg

C API for all (wrap lesystem operations) https://github.com/libusbg/libusbg, maintainer: Matt Porter active developer: Krzysztof Opasiak (73/85 commits) Pending pull requests: https://github.com/kopasiak/libusbg gadget-schemes gadget (composition) export to le gadget (composition) import from le

LinuxCon North America 2014 Make your own USB gadget 27 / 34 USB gadget libusbg & tools Congfs gadgetd & application API Userspace libusbg

C API for all (wrap lesystem operations) https://github.com/libusbg/libusbg, maintainer: Matt Porter most active developer: Krzysztof Opasiak (73/85 commits) Pending pull requests: https://github.com/kopasiak/libusbg gadget-schemes gadget (composition) export to le gadget (composition) import from le

attrs = { idVendor = 0x04e8; idProduct = 0xa4a1; } strings = ( { lang = 0x409; manufacturer = "Foo"; product = "Bar"; serialnumber = "123"; } ) configs = ( { name = "c" id = 1 strings = ( { lang = 0x409; configuration = "Conf 1"; } ) functions = ( { function = { type = "ecm"; instance = "usb0"; } } ) } ) LinuxCon North America 2014 Make your own USB gadget 27 / 34 USB gadget libusbg & tools Congfs gadgetd & application API Userspace gt

command line tool uses libusbg https://github.com/kopasiak/gt - _very_ initial stage libusbg provides example programs show-gadgets create a gadget remove a gadget gadget export (whole or parts) gadget import (whole or parts) gt should combine these concepts into one app

LinuxCon North America 2014 Make your own USB gadget 28 / 34 USB gadget libusbg & tools Congfs gadgetd & application API Userspace gadgetd

exposes gadgets' congfs throug DBUS https://github.com/gadgetd/gadgetd abstraction layer for in-kernel and FunctionFS functions FunctionFS functions accepts cong les for each function manages mounting FunctionFS (naming the instances!) opens ep0 and writes descriptors, opens other ep les starts daemons only when needed (passes ep les' descriptors) allows policing

LinuxCon North America 2014 Make your own USB gadget 29 / 34 USB gadget libusbg & tools Congfs gadgetd & application API Userspace the ecosystem - how it all ts together

LinuxCon North America 2014 Make your own USB gadget 30 / 34 USB gadget Congfs Userspace Q&A

Andrzej Pietrasiewicz [email protected]

LinuxCon North America 2014 Make your own USB gadget 31 / 34 USB gadget Congfs Userspace References

http://www.spinics.net/lists/linux-usb/msg74991.html http://www.spinics.net/lists/linux-usb/msg76378.html http://www.spinics.net/lists/linux-usb/msg83460.html http://www.spinics.net/lists/linux-usb/msg86311.html http://www.spinics.net/lists/linux-usb/msg86321.html http://www.spinics.net/lists/linux-usb/msg86327.html http://www.spinics.net/lists/linux-usb/msg86561.html http://www.spinics.net/lists/linux-usb/msg90757.html http://www.spinics.net/lists/linux-usb/msg90774.html http://www.spinics.net/lists/linux-usb/msg90776.html http://www.spinics.net/lists/linux-usb/msg97006.html http://www.spinics.net/lists/linux-usb/msg98731.html http://www.spinics.net/lists/linux-usb/msg110639.html http://www.spinics.net/lists/linux-usb/msg110718.html http://www.spinics.net/lists/linux-usb/msg110962.html https://github.com/libusbg/libusbg https://github.com/kopasiak/gt https://github.com/gadgetd/gadgetd https://github.com/gadgetd/gadgetd/wiki

LinuxCon North America 2014 Make your own USB gadget 32 / 34 USB gadget Congfs Userspace Images

http://openclipart.org/detail/174619/4g-modem-and-sim-by-witcombem-174619 - slide 3 http://openclipart.org/detail/1964/calcubot-by-johnny_automatic - slide 3

http://openclipart.org/detail/96913/mouse-by-yves_guillou - slide 3

http://openclipart.org/detail/27549/keyboard-keys-by-simanek - slide 3 http://openclipart.org/detail/17924/computer-by-aj - slide 3 http://openclipart.org/detail/176486/pen-drive-by-carloernesto-176486 - slide 3 http://openclipart.org/detail/6633/neo1973-%28tango%29-by-ryanlerch - slide 3 http://openclipart.org/detail/17026/icon_puzzle_blue-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17027/icon_puzzle_green-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17028/icon_puzzle_grey-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17029/icon_puzzle_purple-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17030/icon_puzzle_red-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17031/icon_puzzle_yellow-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17060/icon_cube_green-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17061/icon_cube_orange-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/17062/icon_cube_red-by-jean_victor_balin - slides 4, 8, 9, 10

http://openclipart.org/detail/122449/question-button-by-ricardomaia - slide 5 http://openclipart.org/detail/3705/usb-plug-by-klaasvangend - slide 5

LinuxCon North America 2014 Make your own USB gadget 33 / 34 USB gadget Congfs Userspace Images

http://www.linaro.org/documents/download/304a9a3e4024a2bb70312fc81d79446d51311e50ed8f4 - slide 9 http://openclipart.org/detail/10833/green-tick-by-ryan_taylor - slide 11

http://openclipart.org/detail/104197/calendriercalendar-by-lmproulx - slide 23 http://openclipart.org/detail/33265/liste-/-list-by-lmproulx - slide 25 http://openclipart.org/detail/12929/large-braces-by-anonymous-12929 - slide 20, 21

LinuxCon North America 2014 Make your own USB gadget 34 / 34