example to measure CTAP get_info command
+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 a ctap init cmd is sent
+ let start_filter = UsbmonFilter {
+ epnum: Some(|x: u8| x == 0x04), // EP 4 (FIDO)
+ dir_out: Some(|x: bool| x), // out packet (command)
+ data: Some(|x: &[u8]| {
+ if x[0..5] == [
+ 0xff, 0xff, 0xff, 0xff, // CTAP broadcast ID
+ 0x86 // init cmd
+ ] {
+ return true;
+ }
+ false
+ }),
+ ..Default::default()
+ };
+
+ // Stop outputting packets when a bus error is reported, which
+ // seems to always happen right after the last get_info packet.
+ let end_filter = UsbmonFilter {
+ epnum: Some(|x: u8| x == 0x04), // EP 4 (FIDO)
+ dir_out: Some(|x: bool| !x), // in packet (response)
+ status: Some(|x: libc::c_int| x != 0), // error code
+ ..Default::default()
+ };
+
+ // output all packets for the selected device between the two
+ // filter events.
+ let usec = monitor(Some(&dev_filter), Some(&start_filter), None, Some(&end_filter));
+
+ println!("CTAP get_info in: {usec} µs")
+}