Skip to content

Commit

Permalink
feat: capture touchpads
Browse files Browse the repository at this point in the history
Touchpads are not captured by `hwinfo`.

We read `/proc/bus/input/devices` and `/run/udev/data` to find them and add corresponding `HardwareDevice` entries.

Note: `attached_to` is not currently supported, and will be set to 0. It's not obvious the logic for resolving the report entries that a touchpad is connected to.
Signed-off-by: Brian McGee <brian@bmcgee.ie>
  • Loading branch information
brianmcgee committed Nov 18, 2024
1 parent 5b4a7a8 commit b7473dd
Show file tree
Hide file tree
Showing 15 changed files with 2,186 additions and 3 deletions.
4 changes: 1 addition & 3 deletions nix/packages/nixos-facter/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ in
modules = ./gomod2nix.toml;

buildInputs = [
pkgs.libusb1
pkgs.systemdMinimal.dev
perSystem.hwinfo.default
];

Expand All @@ -48,9 +48,7 @@ in
];

runtimeInputs = with pkgs; [
libusb1
util-linux
pciutils
];

ldflags = [
Expand Down
133 changes: 133 additions & 0 deletions pkg/hwinfo/hardware.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,90 @@ const (
HardwareClassAll
)

// BaseClass values (superset of PCI classes)
//
//go:generate enumer -type=BaseClass -json -transform=snake -trimprefix BaseClass -output=./hardware_enum_base_class.go
type BaseClass uint16

// these *must* match standard PCI class numbers
const (
BaseClassNone BaseClass = iota
BaseClassStorage
BaseClassNetwork
BaseClassDisplay
BaseClassMultimedia

BaseClassMemory
BaseClassBridge
BaseClassComm
BaseClassSystem
BaseClassInput
BaseClassDocking

BaseClassProcessor
BaseClassSerial
BaseClassWireless
BaseClassI2o
BaseClassOther BaseClass = 0xff
)

// add our own base classes here (starting at 0x100 as PCI values are 8 bit)
const (
BaseClassMonitor BaseClass = iota + 0x100
BaseClassInternal
BaseClassModem
BaseClassIsdn
BaseClassPs2
BaseClassMouse

BaseClassStorageDevice
BaseClassNetworkInterface
BaseClassKeyboard
BaseClassPrinter

BaseClassHub
BaseClassBraille
BaseClassScanner
BaseClassJoystick
BaseClassChipcard
BaseClassCamera

BaseClassFramebuffer
BaseClassDvb
BaseClassTv
BaseClassPartition
BaseClassDsl
BaseClassBluetooth
BaseClassFingerprint

BaseClassMmcController
BaseClassTouchpad
)

// SubClassKeyboard values of BaseClassKeyboard
//
//go:generate enumer -type=SubClassKeyboard -json -transform=snake -trimprefix SubClassKeyboard -output=./hardware_enum_sub_class_keyboard.go
type SubClassKeyboard uint16

const (
SubClassKeyboardKbd SubClassKeyboard = iota
SubClassKeyboardConsole
)

// SubClassMouse values of BaseClassMouse
//
//go:generate enumer -type=SubClassMouse -json -transform=snake -trimprefix SubClassMouse -output=./hardware_enum_sub_class_mouse.go
type SubClassMouse uint16

const (
SubClassMousePs2 SubClassMouse = iota
SubClassMouseSer
SubClassMouseBus
SubClassMouseUsb
SubClassMouseSun
SubClassMouseOther SubClassMouse = 0x80
)

// Slot represents a bus and slot number.
// Bits 0-7: slot number, 8-31 bus number
type Slot uint
Expand Down Expand Up @@ -260,6 +344,55 @@ const (
HotplugFirewire
)

// Bus types similar to PCI bridge subclasses
//
//go:generate enumer -type=Bus -json -transform=snake -trimprefix Bus -output=./hardware_enum_bus.go
type Bus uint16

const (
BusNone Bus = iota
BusIsa
BusEisa
BusMc
BusPci
BusPcmcia
BusNubus

BusCardbus
BusOther
)

const (
/** outside the range of the PCI values **/

BusPs2 Bus = iota + 0x80
BusSerial
BusParallel
BusFloppy
BusScsi
BusIde
BusUsb

BusAdb
BusRaid
BusSbus
BusI2o
BusVio
BusCcw
BusIucv
BusPs3SystemBus

BusVirtio
BusIbmebus
BusGameport
BusUisvirtpci
BusMmc
BusSdio
BusNd

BusNvme
)

// HardwareDevice represents a hardware component detected in the system.
type HardwareDevice struct {
// Index is a unique index provided by hwinfo, starting at 1
Expand Down
Loading

0 comments on commit b7473dd

Please sign in to comment.