USB_TEMPLATE(4)

πŸ’– USB_TEMPLATE(4) β€” the kernel interfaces manual page, but make it cute πŸ’–

okay bestie, gather round, because this is the page for usb_template β€” the USB device side templates module. it lives in the Kernel Interfaces Manual section, and honestly? it's giving backstage-pass energy. let's go πŸŽ€


✨ NAME ✨

usb_template β€” USB device side templates πŸ¦‹


🌸 SYNOPSIS 🌸

so you wanna get this module in the game. two ways, pick your fighter:

option one β€” compile it into the kernel. drop this line into your kernel configuration file:

device usb_template

option two β€” load it at boot time. put this line into loader.conf(5):

usb_template_load="YES"

periodt. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

okay so the usb_template module implements a whole lil wardrobe of USB templates β€” and you literally need these when you're programming a USB device side driver. no templates, no lewk. πŸ™ˆ

a USB template consists of:

  • an USB device descriptor
  • one or more USB configuration descriptors
  • one or more USB interface descriptors
  • one or more USB endpoint descriptors
  • USB strings
  • additional USB descriptors

basically the whole fit, head to toe. πŸ‘‘

you pick your template with the hw.usb.template sysctl and tunable, or with the usbconfig(8) set_template subcommand. and here's the thing, bestie β€” changing the hw.usb.template sysctl triggers reenumeration by the USB host. changes to other sysctls may not be visible to the host until reenumeration is performed. so like, the host won't see your new outfit until you do the lil twirl. ✨

πŸŽ€ available templates πŸŽ€

  • 0 β€” USB Mass Storage, see cfumass(4)
  • 1 β€” CDC Ethernet, see cdce(4)
  • 2 β€” Media Transfer Protocol (MTP)
  • 3 β€” USB serial port, see umodem(4)
  • 4 β€” USB audio
  • 5 β€” USB keyboard
  • 6 β€” USB mouse
  • 7 β€” USB phone
  • 8 β€” CDC Ethernet and serial port
  • 9 β€” USB MIDI
  • 10 β€” CDC Ethernet, serial port, and storage
  • 11 β€” CDC Ethernet Emulation Model, see cdceem(4)

twelve templates, twelve personalities, all iconic. πŸ’–


⭐ SYSCTL VARIABLES ⭐

the following variables are available as both sysctl(8) variables and loader(8) tunables. yes queen, both. multitasking. πŸ’…

  • hw.usb.template β€” the currently selected template. set it to -1 to make the device disappear from the USB host point of view. (poof. gone. ghosted. πŸ‘»)
  • hw.usb.template_power β€” USB bus power consumption in mA at 5V. must be between 0 and 500. setting to 0 marks the device as self-powered. defaults to 500mA.
  • hw.usb.templates.N β€” configuration for template number N.
  • hw.usb.templates.N.vendor_id β€” 16-bit vendor identifier (VID), usually assigned by USB-IF.
  • hw.usb.templates.N.product_id β€” 16-bit product identifier (PID).
  • hw.usb.templates.N.manufacturer β€” string containing human-readable manufacturer name.
  • hw.usb.templates.N.product β€” string containing human-readable product name.
ngl, N is doing a lot of heavy lifting here and honestly? we respect the range. 🫢

🌈 SEE ALSO 🌈

cfumass(4), usb(4), usfs(4), usbconfig(8)

iykyk πŸ’œ


πŸ‘‘ STANDARDS πŸ‘‘

the usb_template module complies to the USB 1.0, 2.0 and 3.0 standard. all three. ate and left no crumbs. πŸ”₯


🧚 HISTORY 🧚

the usb_template module was written by Hans Petter Selasky <hselasky@FreeBSD.org>. legend behaviour, fr fr. 🌸


πŸ’Œ the cute lil sign-off πŸ’Œ

and that's the whole page, bestie! this one came from the Debian source, dated August 7, 2019, and it's the USB_TEMPLATE(4) page in the Kernel Interfaces Manual. mwah. πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from