Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,18 @@ pub fn run_tap_command(device: &HidDevice, tap_bytes: &[u8]) -> Result<String, E
tap_bytes.escape_ascii()
);

let result = response_report[1..].split(|&x| x == 0).next().unwrap();
// hidapi's get_feature_report() on Linux strips the report ID from the response,
// so the actual string data starts at index 0. Some devices may prepend a length/status
// byte before the string, so we check for that.
let data_start = if response_report[0] < 0x20 || response_report[0] > 0x7E {
1 // Skip non-printable length/status byte
} else {
0 // Data starts immediately
};
let result = response_report[data_start..]
.split(|&x| x == 0)
.next()
.unwrap();

Ok(std::str::from_utf8(result)
.map_err(|e| Error::ProtocolError(e.into()))?
Expand Down