I'm trying to implement a simple WebUSB device on a Raspberry Pi 4. I've created a Linux USB Gadget for this purpose with a FunctionFS function. Currently I've taken the usb/ffs-test.c example from the Linux kernel as a basis.
According to this excellent Google blog by Reilly Grant on "Building a Device for WebUSB", I have to extend the Binary device Object Store (BOS) with the Microsoft OS compatibility descriptors to get this to work on Windows. I could also add the WebUSB descriptors to it but this is not a functional requirement.
However I'm stuck on this step, how do I extend the BOS with FunctionFS? This is my first experience with FunctionFS or USB for that matter, so I could be missing something obvious. I've found some usb_os_desc_header struct defined here in usb/functionfs.h, but I don't know if this is what I need or how I should use it.
I finally figured this out as well, so here's what I had to do (based on tools/usb/ffs-test.c).
A user space function must write all descriptors to ep0, so the trick is to extend your descriptors struct:
__le32 os_countafterss_countstruct usb_os_desc_header os_headerandstruct usb_ext_compat_desc os_descafterss_descsFUNCTIONFS_HAS_MS_OS_DESCneeds to be added toheader.flagsHere's how I initialise the new fields for WinUSB compatibility, I presume WebUSB in general works similar: