Files
LithosAnanke/kernel/include/starkernel/usb_config.h
T
Claude a882465573 fix(usb): a configuration of 9 bytes or less is refused, and a cut one is said (#170, #171)
After the configuration descriptor's first 9 bytes the event loop asked for
min(wTotalLength, 128) whatever it was. A wTotalLength of 9 or less was then
asked for again as "short" -- for ever, that slot never leaving enumeration
(#170); 0 also issued a zero-length data stage. A set longer than the 128-byte
buffer was cut without a word, its later interfaces never seen (#171).

The decision is usb_config_request_length() (moved out of the event loop,
then fixed): 9 or less is 0 -- "xhci: a configuration of N bytes has no
interface -- not used", and nothing more is asked; longer than the buffer is
cut and said -- "xhci: config of N bytes cut to 128 -- rest unseen" (at most
53 characters). The buffer stays 128 bytes; its size is #171's to rule.

kernel/tests/test_usb_config.c, seen to fail first against the decision as it
was (10 failures: wTotalLength 1 to 9 asked for again, the cut unsaid), now
20 checks, 0 failures. Both runs in logs/20261112-180140/kernel-tests/. Built for amd64,
aarch64 and riscv64; the boots come with the protocol. #171's other box, a
composite device on the SER5, is Captain Bob's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
2026-11-12 18:01:40 +00:00

41 lines
2.1 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);
/* After the configuration descriptor's first 9 bytes: how many bytes of the whole set to ask
* for, given its wTotalLength and the buffer's size `cap` -- 0 when wTotalLength is 9 or less (the
* device is not used: #170); *cut set to 1 when the set is longer than the buffer (#171). */
uint16_t usb_config_request_length(uint16_t total, uint16_t cap, int *cut);
#endif