aboutsummaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorjamie <git@skilet.ro>2026-08-29 22:15:55 +0100
committerjamie <git@skilet.ro>2026-08-29 22:15:55 +0100
commit3dd652c1d70da608c77d1ded9e6d44774fc10ebc (patch)
treecdd5d0ed985494f3ac66f19d4fedd8fd039b9357 /src/bin
parentc1110ac81f87ba374696e419f3807f48a3a06d6d (diff)
refactor: dedupe helpers, name protocol constants, testable daemon args
Diffstat (limited to '')
-rw-r--r--src/bin/probe.rs74
1 files changed, 25 insertions, 49 deletions
diff --git a/src/bin/probe.rs b/src/bin/probe.rs
index e77e6cd..008565c 100644
--- a/src/bin/probe.rs
+++ b/src/bin/probe.rs
@@ -1,8 +1,8 @@
//! mmx150-probe — reverse-engineering tool for the MMX 150 dongle protocol.
//!
-//! Phase 1 workflow: send candidate output reports to the dongle and observe
-//! what input reports come back, correlating fields with headset on/off,
-//! battery charge level and button presses.
+//! Sends candidate output reports to the dongle and prints what input
+//! reports come back. Kept for future protocol work: battery status, for
+//! example, is not exposed by any command found so far.
use std::process::ExitCode;
use std::time::Duration;
@@ -25,6 +25,22 @@ fn main() -> ExitCode {
}
}
+/// Find and open the dongle, printing an error and returning `None` if it
+/// is missing or cannot be opened.
+fn open_dongle() -> Option<Hidraw> {
+ let Some(dev) = mmx150::hid::find_mmx150().unwrap_or(None) else {
+ eprintln!("MMX 150 dongle not found");
+ return None;
+ };
+ match Hidraw::open(&dev.devnode) {
+ Ok(h) => Some(h),
+ Err(e) => {
+ eprintln!("open failed: {e}");
+ None
+ }
+ }
+}
+
fn cmd_list(_rest: &[String]) -> ExitCode {
match find_devices_by_vendor(BEYERDYNAMIC_VID) {
Ok(devices) => {
@@ -120,18 +136,9 @@ fn cmd_send(rest: &[String]) -> ExitCode {
data.extend(bytes);
}
- let Some(dev) = mmx150::hid::find_mmx150().unwrap_or(None) else {
- eprintln!("MMX 150 dongle not found");
+ let Some(mut hid) = open_dongle() else {
return ExitCode::FAILURE;
};
- let hid = match Hidraw::open(&dev.devnode) {
- Ok(h) => h,
- Err(e) => {
- eprintln!("open failed: {e}");
- return ExitCode::FAILURE;
- }
- };
- let mut hid = hid;
println!(
">> 0x{report_id:02x} [{}B] {}",
@@ -160,25 +167,12 @@ fn send_and_read(hid: &mut Hidraw, data: &[u8]) -> Option<Vec<u8>> {
.flatten()
}
-/// Sweep a set of candidate commands against the dongle, printing responses
-/// that differ from the all-zero baseline. Reports only non-trivial responses.
-///
-/// usage: mmx150-probe sweep <report_id> <B> ...
-/// <report_id> is the output report id to use,
-/// <B> is the report payload length (bytes, excluding the id byte).
+/// Send a fixed set of diagnostic commands (one per known report family)
+/// and print their responses side by side.
fn cmd_status_dump() -> ExitCode {
- let Some(dev) = mmx150::hid::find_mmx150().unwrap_or(None) else {
- eprintln!("MMX 150 dongle not found");
+ let Some(mut hid) = open_dongle() else {
return ExitCode::FAILURE;
};
- let hid = match Hidraw::open(&dev.devnode) {
- Ok(h) => h,
- Err(e) => {
- eprintln!("open failed: {e}");
- return ExitCode::FAILURE;
- }
- };
- let mut hid = hid;
// Each row: label, report id, command payload.
let cmds: Vec<(&str, u8, Vec<u8>)> = vec![
@@ -252,18 +246,9 @@ fn cmd_sel_enum(rest: &[String]) -> ExitCode {
.and_then(|s| u8::from_str_radix(s.trim_start_matches("0x"), 16).ok())
.unwrap_or(0x3a);
- let Some(dev) = mmx150::hid::find_mmx150().unwrap_or(None) else {
- eprintln!("MMX 150 dongle not found");
+ let Some(mut hid) = open_dongle() else {
return ExitCode::FAILURE;
};
- let hid = match Hidraw::open(&dev.devnode) {
- Ok(h) => h,
- Err(e) => {
- eprintln!("open failed: {e}");
- return ExitCode::FAILURE;
- }
- };
- let mut hid = hid;
println!("sweeping report 0x{report_id:02x}, selector range 0x00..0xff");
for sel in 0x00u8..=0xffu8 {
@@ -304,18 +289,9 @@ fn cmd_sweep(rest: &[String]) -> ExitCode {
};
let plen: usize = rest.get(1).and_then(|s| s.parse().ok()).unwrap_or(60);
- let Some(dev) = mmx150::hid::find_mmx150().unwrap_or(None) else {
- eprintln!("MMX 150 dongle not found");
+ let Some(mut hid) = open_dongle() else {
return ExitCode::FAILURE;
};
- let hid = match Hidraw::open(&dev.devnode) {
- Ok(h) => h,
- Err(e) => {
- eprintln!("open failed: {e}");
- return ExitCode::FAILURE;
- }
- };
- let mut hid = hid;
// Baseline: all-zero command.
let base = {