Skip to content

usb: gadget: configfs: add MS OS 2.0 descriptors support - #369

Open
evgeny-boger wants to merge 2 commits into
feature/webusb-bcdusb-0210-v6.8-rebase1from
feature/gadget-msos20-descriptors
Open

usb: gadget: configfs: add MS OS 2.0 descriptors support#369
evgeny-boger wants to merge 2 commits into
feature/webusb-bcdusb-0210-v6.8-rebase1from
feature/gadget-msos20-descriptors

Conversation

@evgeny-boger

Copy link
Copy Markdown
Member

Что происходит; кому и зачем нужно:

Windows 8.1+ читает MS OS 2.0 descriptors из BOS и при этом игнорирует MS OS 1.0, которые gadget-стек уже умеет. Из-за этого функции композитного гаджета невозможно сообщить Windows её DeviceInterfaceGUID: MS OS 1.0 extended properties Windows у функции композитного устройства не забирает, а свойства типа REG_MULTI_SZ ядро не отдаёт вовсе (composite.c отвергает USB_EXT_PROP_UNICODE_MULTI). Без зарегистрированного GUID Windows не создаёт device interface, приложение не может получить device path и вообще не может обратиться к устройству — например, Chromium не читает WebUSB landing page композитного гаджета.

MS OS 2.0 в linux-gadget отсутствует и в 6.8, и в mainline (grep по D8DD60DF/MS_OS_20 — пусто), готовых патчей найти не удалось.

Добавляется configfs-группа msos20, по образцу существующей webusb:

echo 0x02 > msos20/bVendorCode
cat descriptor_set.bin > msos20/descriptor_set
echo 1 > msos20/use

Сам набор дескрипторов для ядра непрозрачен и формируется в userspace — так интерфейс остаётся маленьким, а гаджет может описать любое число функций и свойств без новых патчей в ядре. При записи проверяется только заголовок набора, чтобы обрезанный или несогласованный блоб отвергался сразу, а не путал хост позже. При включении capability добавляется в BOS, и устройство отдаёт bcdUSB 0x0210, как требует спецификация.


Что поменялось для пользователей:

Само по себе ничего: без записи в msos20/ поведение прежнее. Когда wb-utils начнёт включать это для Debug Network, на Windows появится уведомление Chrome со ссылкой на веб-интерфейс контроллера.

Важно: набор дескрипторов обязан описывать все функции, которым нужен compatible ID. Windows, увидев MS OS 2.0, перестаёт читать MS OS 1.0, поэтому если не описать там RNDIS — он потеряет свой compat ID и сеть на хосте отвалится. В wb-utils это учтено и проверено.


Как проверял/а:

  • scripts/checkpatch.pl (mainline): 0 errors. Остаются два warning: про длину строки в changelog коммита и «does MAINTAINERS need updating?» на новый заголовок.
  • Собран libcomposite.ko для 6.8.0-wb161 и установлен на WB 8.5 (wirenboard-ALFLOJF3, musb HS), гаджет RNDIS + mass storage + FunctionFS:
    • configfs round-trip: 206 байт записываются в descriptor_set и читаются обратно; capability видна в BOS (57 байт, три капабилити), bcdUSB 2.10;
    • Windows 11 + Chrome 152: в реестре зарегистрированы DeviceInterfaceGUID/DeviceInterfaceGUIDs, а chrome://usb-internals показывает WebUSB Landing Page: https://10-200-200-1.<sn>.ip.wirenboard.com/ — без этого патча поле пустое;
    • RNDIS не пострадал (Ethernet 2 / Up), диск на месте, все четыре функции в состоянии OK.
  • Не проверял: Windows 7/8.0 (там MS OS 2.0 нет, работает старый путь 1.0), superspeed-гаджеты, поведение при descriptor_set больше 1024 байт (ограничено константой).

Патч имеет смысл и для mainline — фичи там нет.


AI-assisted:

Патч и changelog подготовлены с помощью LLM-ассистента (тег Assisted-by: LLM по Documentation/process/coding-assistants.rst). Signed-off-by проставлен по прямому указанию отправителя.

Windows 8.1 and later read the MS OS 2.0 descriptor set announced through a
BOS platform capability descriptor and ignore the older MS OS 1.0 descriptors
the gadget stack already supports. Without MS OS 2.0 there is no way to tell
Windows the DeviceInterfaceGUID of a function of a composite gadget: the MS
OS 1.0 extended properties are not picked up for composite functions, and
REG_MULTI_SZ properties cannot be emitted at all (composite.c rejects
USB_EXT_PROP_UNICODE_MULTI). Without a registered interface GUID Windows
creates no device interface for the function, so applications cannot obtain a
device path for it and cannot talk to the device at all -- for instance
Chromium fails to read the WebUSB landing page of a composite gadget.

Add an "msos20" configfs group, modelled after the existing "webusb" one:

  echo 0x02 > msos20/bVendorCode
  cat descriptor_set.bin > msos20/descriptor_set
  echo 1 > msos20/use

The descriptor set itself is opaque to the kernel and is supplied by
userspace, which keeps the interface small and lets gadgets describe any
number of functions and properties. Only the set header is validated on
write, so that a truncated or mismatched blob is rejected there rather than
confusing the host later. When enabled, the platform capability descriptor is
added to the BOS descriptor and the device reports bcdUSB 0x0210, as the
specification requires.

Tested on a Wiren Board 8 (musb high-speed UDC) with a composite RNDIS +
mass storage + FunctionFS gadget and Chromium 152 on Windows 11: the WinUSB
function gets its DeviceInterfaceGUIDs registered, the RNDIS function keeps
its compatible ID and the network interface keeps working, and the WebUSB
landing page is read by the browser, which it is not without this change.

Assisted-by: LLM
Signed-off-by: Evgeny Boger <boger@wirenboard.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant