usbhidusage

Crates.iousbhidusage
lib.rsusbhidusage
version0.1.3
sourcesrc
created_at2024-10-28 23:20:11.029042
updated_at2024-11-06 09:27:33.098142
descriptionA general purpose library for working with usb Human Interface Device Descriptors from the HID Usage Tables for Universal Serial Bus (USB) v1.5
homepage
repositoryhttps://github.com/Cry-Tokyo/usbhidusage
max_upload_size
id1426173
size563,828
Matthew Cepeda (Cry-Tokyo)

documentation

README

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.

Commit count: 52

cargo fmt