xhci.c's XHCI_XFER_CONFIG_DESC_FULL case walked the descriptor set inline, in the event loop, where nothing could test it. The walk is now usb_config_parse() (kernel/src/usb/usb_config.c), returning what it found; the case acts on it as before -- the same messages, the same decisions: the first Interface descriptor only, a BOT interface's bulk endpoints (the last of each direction), a boot keyboard's first interrupt IN endpoint, bLength 0 ending the walk, nothing read past len. One difference, in debug output only: the bulk endpoints are logged IN then OUT, not in descriptor order. kernel/tests/test_usb_config.c, 7 checks, pins the walk as moved: a BOT stick as QEMU presents it, a boot keyboard with its HID descriptor, a mouse before a drive (the first interface only), a drive with bulk IN only, bLength 0, an endpoint cut by len, an interface cut before its protocol byte. All pass. Built for amd64, aarch64, riscv64; the boots come with the protocol (a data stick enumerates through this path). The fixes for #170 and #171 follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
36 lines
1.7 KiB
C
36 lines
1.7 KiB
C
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
|
|
* Copyright (c) 2023-2026 Robert A. James
|
|
*/
|
|
/* usb_config.h -- a USB configuration descriptor set, read: what xhci.c's event loop needs to know
|
|
* of a device (its first interface, and that interface's endpoints). Moved out of the loop's
|
|
* XHCI_XFER_CONFIG_DESC_FULL case unchanged, so it can be tested on the host
|
|
* (kernel/tests/test_usb_config.c; docs/v4.0.0/plans/2026-11-12-kernel-host-tests.md).
|
|
*/
|
|
#ifndef STARKERNEL_USB_CONFIG_H
|
|
#define STARKERNEL_USB_CONFIG_H
|
|
|
|
#include <stdint.h>
|
|
|
|
#define USB_CONFIG_NO_INTERFACE 0 /* no Interface descriptor in the set */
|
|
#define USB_CONFIG_MSC 1 /* Mass Storage / SCSI / Bulk-Only Transport */
|
|
#define USB_CONFIG_KBD 2 /* a HID boot keyboard */
|
|
#define USB_CONFIG_OTHER 3 /* anything else -- not used */
|
|
|
|
typedef struct {
|
|
int kind; /* USB_CONFIG_* */
|
|
uint8_t iface_class, iface_subclass, iface_protocol;
|
|
uint8_t config_value; /* bConfigurationValue, for SET_CONFIGURATION */
|
|
uint8_t bulk_in_ep, bulk_out_ep; /* USB_CONFIG_MSC: 0 when not found */
|
|
uint16_t bulk_in_max, bulk_out_max;
|
|
uint8_t hid_iface; /* USB_CONFIG_KBD */
|
|
uint8_t hid_ep, hid_interval; /* hid_ep 0 when not found */
|
|
uint16_t hid_max;
|
|
} usb_config_t;
|
|
|
|
/* Read the first `len` bytes of a configuration descriptor set (the Configuration descriptor and
|
|
* the Interface and Endpoint descriptors after it). Only the first Interface descriptor counts;
|
|
* a descriptor with bLength 0 ends the walk. Never reads past `len`. */
|
|
void usb_config_parse(const uint8_t *desc, uint16_t len, usb_config_t *out);
|
|
|
|
#endif
|