examples/mon_fido_enumeration_data_only.rs
use menomonmon::{
monitor,
CliArgs,
UsbmonFilter,
};
use nix::libc;
fn main() {
// get optional device filter from command-line args
let dev_filter = CliArgs::dev_filter();
// Start outputting packets when the device descriptor is fetched.
// This is the first thing linux does when a device is plugged in.
let start_filter = UsbmonFilter {
epnum: Some(|x: u8| x == 0x00), // EP 0
setup_request_type: Some(|x: u8| x == 0x80), // standard request
setup_request: Some(|x: u8| x == 0x06), // get descriptor
setup_value: Some(|x: u16| x == 0x0100), // device descriptor
setup_length: Some(|x: u16| x == 18), // 18-byte request
..Default::default()
};
// Stop outputting packets when the FIDO HID Report descriptor is
// fetched. This is approximately the last thing linux does when
// enumerating a FIDO/U2F device.
let end_filter = UsbmonFilter {
epnum: Some(|x: u8| x == 0x00), // EP 0
setup_request_type: Some(|x: u8| x == 0x81), // standard request
setup_request: Some(|x: u8| x == 0x06), // get descriptor
setup_value: Some(|x: u16| x == 0x2200), // HID Report
setup_index: Some(|x: u16| x == 0x0001), // FIDO descriptor
pkts_after: 1, // get reply
..Default::default()
};
// Only output data packets
let active_filter = UsbmonFilter {
data_len: Some(|x: libc::c_uint| x > 0),
..Default::default()
};
// output all packets for the selected device between the two
// filter events.
let usec = monitor(Some(&dev_filter), Some(&start_filter),
Some(&active_filter), Some(&end_filter));
println!("FIDO device enumerated in: {usec} µs")
}