summary history branches tags files
commit:83a10f2ac430be3d69c779c99ba7ae8baf101c29
author:Trevor Bentley
committer:Trevor Bentley
date:Tue May 7 02:55:52 2024 +0200
parents:01f8b4b6f85388ddd0e20901c4f46bdd020e4496
example to measure CTAP get_info command
diff --git a/examples/mon_ctap_get_info.rs b/examples/mon_ctap_get_info.rs
line changes: +43/-0
index 0000000..e5c3fb3
--- /dev/null
+++ b/examples/mon_ctap_get_info.rs
@@ -0,0 +1,43 @@
+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")
+}