
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 Make your own USB gadget 1 / 34 USB gadget Congfs Userspace Table of Contents 1 USB gadget USB and functions USB gadget Gadget implementation in Linux 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 host += 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 talk 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 factor 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 at runtime action lesystem create make directory destroy remove directory specify value write get value read (execute for directory) group things symlink ungroup things remove symlink Command reference mkdir, rmdir echo 'something' > file, cat file, ls directory ln -s, rm 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 $ 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 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
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages60 Page
-
File Size-