#usb #table #hid #usage #hidusbtable

no-std usbhidusage

A general purpose library for working with usb Human Interface Device Descriptors from the HID Usage Tables for Universal Serial Bus (USB) v1.5

1 unstable release

0.1.3 Nov 6, 2024
0.1.2 Oct 30, 2024
0.1.1 Oct 28, 2024
0.1.0 Oct 28, 2024

#60 in Visualization

Download history 341/week @ 2024-10-26 130/week @ 2024-11-02 16/week @ 2024-11-09

487 downloads per month

MIT license

285KB
8K SLoC

usbhidusage

A general purpose library for working with usb Human Interface Device Descriptors from the HID Usage Tables for Universal Serial Bus (USB) v1.5

License: MIT crates-badge API Docs

Overview

Usbhidusage is a general purpose library for working with usb Human Interface Device Descriptors from the HID Usage Tables for Universal Serial Bus (USB). It currently follows the HID Usage Tables for usb v1.5

Usbhidusage currently provides workable enums that tie Usage Names to their specified Usage ID, while also allowing you to retain the origanl value for those without a specified usage.

Example

A usb PCAP reader using usbhidusage.

Make sure you state usbhidusage as a dependency on Cargo.toml:

[dependencies]
usbhidusage = "0.1.0"
pcap = "2.2.0"
pnet = "0.35.0"

Then, import the project in your main.rs:

use pcap::Capture;
use pnet::packet::{usbpcap::MutableUsbPcapPacket, Packet};
use usbhidusage::keyboard::KeyboardUsage;

fn main() {
    let mut file = Capture::from_file("tests/usb.pcap").unwrap();
    let mut c = 1;
    fn key(code: u8) -> bool {
        let code = KeyboardUsage::from(code);
        match code == KeyboardUsage::Reserved00_00 || code == KeyboardUsage::KeyboardLeftAlt || code == KeyboardUsage::KeyboardLeftGUI || code == KeyboardUsage::KeyboardLeftShift || code == KeyboardUsage::KeyboardLeftControl || code == KeyboardUsage::KeyboardRightAlt || code == KeyboardUsage::KeyboardRightGUI || code == KeyboardUsage::KeyboardRightShift || code == KeyboardUsage::KeyboardRightControl {
                true => true,
                false => false
        }
    }
    while let Ok(packet) = file.next_packet() {
        let data = MutableUsbPcapPacket::owned(packet.to_vec());
        if let Some(array) = data {
            match array.get_data_length() == 8 && key(array.payload()[0]) && array.payload()[1] == 0
            {
                true => println!("{}", HIDData::from(array.payload())),
                false => println!("{}", HIDData::NOEVENT),
            }
        }
        c += 1
    }
}

This and other examples can be found here.

Resources

https://www.usb.org/hid

https://www.usb.org/sites/default/files/hut1_5.pdf

https://www.igsa.org/en/standards/gds-gaming-device-standards

https://www.unicode.org/versions/Unicode16.0.0/

Contributing

Feel free to leave any changes or suggestions, the goal would be to follow the spec as closely as possible and follow up with any revisions or updates as well.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion by you, shall be licensed as MIT, without any additional terms or conditions.

No runtime deps