diff --git a/local/recipes/system/evdevd/source/Cargo.toml b/local/recipes/system/evdevd/source/Cargo.toml index 0a884e65d0..3ce99a17b4 100644 --- a/local/recipes/system/evdevd/source/Cargo.toml +++ b/local/recipes/system/evdevd/source/Cargo.toml @@ -9,6 +9,7 @@ syscall = { package = "redox_syscall", version = "0.4" } log = { version = "0.4", features = ["std"] } thiserror = "2" orbclient = { version = "=0.3.47", default-features = false } +redox-driver-sys = { path = "../../../../recipes/drivers/redox-driver-sys/source" } [target.'cfg(target_os = "redox")'.dependencies] redox_event = "0.4" diff --git a/local/recipes/system/evdevd/source/src/main.rs b/local/recipes/system/evdevd/source/src/main.rs index fb8ae422b6..373ceabeee 100644 --- a/local/recipes/system/evdevd/source/src/main.rs +++ b/local/recipes/system/evdevd/source/src/main.rs @@ -1,6 +1,7 @@ mod device; mod gesture; mod key_filter; +mod quirks; mod scheme; mod translate; mod types; diff --git a/local/recipes/system/evdevd/source/src/quirks.rs b/local/recipes/system/evdevd/source/src/quirks.rs new file mode 100644 index 0000000000..d9512ce5d7 --- /dev/null +++ b/local/recipes/system/evdevd/source/src/quirks.rs @@ -0,0 +1,83 @@ +//! R1–R10 audit Gap 10: HID quirk flag reporting at evdevd device registration. +//! +//! HID quirks are observability-only in this tree (the same +//! situation as Blocker 3 in `usbhidd`). The lookup is purely +//! informational: `lookup_hid_quirks` returns a `HidQuirkFlags` +//! bitflags struct built from the compiled-in Linux 7.1 +//! `hid_quirks[]` table + the runtime `quirks.d/*.toml` files, +//! and the call site is responsible for logging the result. +//! +//! Caveat (carried forward from the R1–R10 audit, 2026-06-07): +//! evdevd currently constructs `InputDevice` with `vendor: 0` and +//! a synthetic `product` value, because the upstream `usbhidd` +//! produces `orbclient::Event`s without forwarding the real USB +//! vendor / product IDs. The lookup therefore returns empty +//! flags in practice. Once the orbclient event pipe is extended +//! to carry the device IDs, the wiring below will start logging +//! the matched flag sets without any further code change. +//! +//! Section markers: +//! - R10 unblock: HID device flags become visible at the +//! evdev registration boundary. + +use redox_driver_sys::quirks::lookup_hid_quirks; + +/// Log the HID quirk flags for the given device, if any. Runs +/// at the moment an `InputDevice` enters the scheme in +/// `EvdevScheme::add_device()`. +pub(crate) fn log_hid_quirks(vendor: u16, product: u16, kind: &str) { + let flags = lookup_hid_quirks(vendor, product); + if !flags.is_empty() { + log::info!( + "HID quirks for {} ({:04X}:{:04X}) flags=0x{:016X} bits={:?}", + kind, + vendor, + product, + flags.bits(), + flags, + ); + } else { + log::debug!("no HID quirks for {} ({:04X}:{:04X})", kind, vendor, product); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use redox_driver_sys::quirks::HidQuirkFlags; + + #[test] + fn hid_quirks_returns_empty_for_synthetic_zero_vendor() { + // vendor=0 is the current evdevd default; confirm we + // do not match anything accidentally. + let flags = lookup_hid_quirks(0, 0); + assert!(flags.is_empty()); + assert_eq!(flags, HidQuirkFlags::empty()); + } + + #[test] + fn hid_quirks_returns_empty_for_synthetic_product_id() { + // evdevd currently sets product = id (or id+0x10 / id+0x20) + // — small numbers that should not appear in the Linux + // HID quirk table. + for product in 0u16..32 { + let flags = lookup_hid_quirks(0, product); + assert!(flags.is_empty(), "unexpected match at product={}", product); + } + } + + #[test] + fn hid_quirks_returns_known_flag_for_real_device() { + // Real entry: 0x06d6:0x0025 → BADPAD (from hid_table.rs). + let flags = lookup_hid_quirks(0x06d6, 0x0025); + assert!(!flags.is_empty()); + assert!(flags.contains(HidQuirkFlags::BADPAD)); + } + + #[test] + fn log_helper_does_not_panic_on_synthetic_ids() { + log_hid_quirks(0, 0, "keyboard"); + log_hid_quirks(0, 0x10, "mouse"); + log_hid_quirks(0, 0x20, "touchpad"); + } +} diff --git a/local/recipes/system/evdevd/source/src/scheme.rs b/local/recipes/system/evdevd/source/src/scheme.rs index 2eb7738f98..57a8bbb411 100644 --- a/local/recipes/system/evdevd/source/src/scheme.rs +++ b/local/recipes/system/evdevd/source/src/scheme.rs @@ -276,6 +276,15 @@ impl EvdevScheme { DeviceKind::Mouse => InputDevice::new_mouse(id), DeviceKind::Touchpad => InputDevice::new_touchpad(id), }; + crate::quirks::log_hid_quirks( + device.input_id.vendor, + device.input_id.product, + match kind { + DeviceKind::Keyboard => "keyboard", + DeviceKind::Mouse => "mouse", + DeviceKind::Touchpad => "touchpad", + }, + ); self.devices.push(device); id }