Skip to content

Instantly share code, notes, and snippets.

@anonhostpi
Last active February 20, 2024 15:14
Show Gist options
  • Save anonhostpi/b8a1bc192d8b68896b33c4dc820f4f4d to your computer and use it in GitHub Desktop.
Save anonhostpi/b8a1bc192d8b68896b33c4dc820f4f4d to your computer and use it in GitHub Desktop.
ConfigFS, FunctionFS, GadgetFS, the Gadget API, Dual-Role, and OTG libraries - A comprehensive list of it all.

Ok, so I am writing a comprehensive list for all libraries, tools, modules, and scripts for any linux distro or kernel that I can find anywhere, so I can learn more about how to make use of it.

Currently this list contains Source Code with the following keywords:

  • FunctionFS, ConfigFS, GadgetFS, gadget mode, and USB Gadget API
  • USB 3.0 Dual-Role Device (DRD) and USB 2.0 On-The-Go (OTG)
  • libcomposite (the kernel library that ConfigFS uses to create USB gadgets)
  • DesignWare Core SuperSpeed 3.0 (DWC3)
    • appears to be the main proprieter of USB 3.0 Gadget hardware
  • MTP/PTP - one of the oldest and most stable implementations of the Gadget API

This list contains references to the following Source Code Repositories:

  • Google's Piper/Source Code Repositories:
    • Specifically, the Android Code Source
  • Github
  • PyPl (WIP)

What is this?

For those who don't know what any of the above APIs are, they are the underlying APIs that power things like the MTP protocol that is associated with your mobile electronics, such as smartphones and digital cameras. The Media Transfer Protocol (MTP) is the protocol that allows host devices to pretend to be peripheral storage devices to other hosts. This is what makes it possible for your cell phone or digital camera to show up as a storage device on your PC, even though they are technically small computers.

You can read more about these APIs from the kernel docs:

Why is this cool?

The really cool thing about these kernel APIs is that they can work at the USB protocol layer. Which means any USB device can be emulated by a linux machine any way you want. You are not limited to just the MTP protocol.

The reason I am exploring these tools is that I want to see exactly what kind of things I can do with this API.

Something that has interested me about this API since I came across it was whether or not it could support hosting a bootable mass storage device. This could allow me to do something like providing Ventoy (or Medicat) over the Gadget API.

  • I was thinking that I could build some kind of stack with this that would allow me to install an operating system dynamically on the host using live ISO, then once the OS has been installed, provision it via Ansible (over RNDIS) without ever having to reboot the gadget device.
    • Basically, it would provide a method for a fully unattended bare metal install that could fit in your pocket.

What's this about kernels (plural)?

Note that earlier, in the first paragraph, I said any linux distro as well as any kernel. Since implementations of this API typically require USB OTG or USB Dual Role hardware, the kernel that is likely to have the most stable tools/libraries is going to be the Android kernel. This is something to keep in mind when discussing these APIs.

(TL;DR) The list

  • Most of these libraries are on Github, but it is worth-while to at least point out the Android Code Search

This list is mostly all inclusive:

  • It contains the majority of repositories with noteworthy ConfigFS/FunctionFS features.
  • Most of the ignored repositories were ones that either:
    • had little documentation/were definitively unmaintained
    • were just some playground or test repos for learning/future development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment