da14531: add reset/status Rust helpers
What changed, and why it matters
This commit adds two new helper functions in Rust for talking to the Bluetooth chip inside the BitBox02 hardware wallet: one to reset the chip and one to ask for its current connection state. It also adds unit tests that check the exact bytes sent. There is no security issue visible in this change; it is a straightforward feature addition with tests.
No security action required. Review as normal code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds reset() and get_connection_state() helpers to src/rust/bitbox02/src/da14531.rs. Both enqueue a single-byte control command (CTRL_CMD_BLE_CHIP_RESET = 8 and CTRL_CMD_BLE_STATUS = 5) into a serial byte queue using the existing enqueue_ctrl_data() helper. The commit also adds unit tests verifying the framed serial frames match expected hex values (7eb401000877f67e and 7eb4010005b6337e). No logic changes to parsing, authentication, memory handling, or privileged operations are introduced.
Changed components
src/rust/bitbox02/src/da14531.rsInspect captured patch +46 / −0
diff --git a/src/rust/bitbox02/src/da14531.rs b/src/rust/bitbox02/src/da14531.rs
index cd93368..6cec8a5 100644
--- a/src/rust/bitbox02/src/da14531.rs
+++ b/src/rust/bitbox02/src/da14531.rs
@@ -6,7 +6,9 @@ use bitbox_bytequeue::ByteQueue;
use bitbox_framed_serial_link::{ProtocolPacketType, protocol_format};
const CTRL_CMD_DEVICE_NAME: u8 = 1;
+const CTRL_CMD_BLE_STATUS: u8 = 5;
const CTRL_CMD_PRODUCT_STRING: u8 = 7;
+const CTRL_CMD_BLE_CHIP_RESET: u8 = 8;
const CTRL_CMD_BLE_POWER_DOWN: u8 = 12;
const CTRL_PAYLOAD_MAX_LEN: usize = 64;
@@ -45,6 +47,16 @@ pub fn power_down(queue: &mut ByteQueue) {
enqueue_ctrl_data(&[CTRL_CMD_BLE_POWER_DOWN, 0], queue);
}
+/// Reset the BLE chip.
+pub fn reset(queue: &mut ByteQueue) {
+ enqueue_ctrl_data(&[CTRL_CMD_BLE_CHIP_RESET], queue);
+}
+
+/// Ask the BLE chip for its current connection state.
+pub fn get_connection_state(queue: &mut ByteQueue) {
+ enqueue_ctrl_data(&[CTRL_CMD_BLE_STATUS], queue);
+}
+
#[cfg(test)]
mod tests {
use super::*;
@@ -56,7 +68,9 @@ mod tests {
use hex_lit::hex;
const CTRL_CMD_DEVICE_NAME: u8 = 1;
+ const CTRL_CMD_BLE_STATUS: u8 = 5;
const CTRL_CMD_PRODUCT_STRING: u8 = 7;
+ const CTRL_CMD_BLE_CHIP_RESET: u8 = 8;
const CTRL_CMD_BLE_POWER_DOWN: u8 = 12;
fn drain(queue: &mut ByteQueue) -> Vec<u8> {
@@ -118,4 +132,36 @@ mod tests {
assert_eq!(actual, expected);
assert_eq!(actual, hex!("7eb4080001666f6f20626172db2f7e").to_vec());
}
+
+ #[test]
+ fn test_reset() {
+ let mut queue = ByteQueue::with_capacity(64);
+
+ reset(&mut queue);
+
+ let actual = drain(&mut queue);
+
+ let payload = vec![CTRL_CMD_BLE_CHIP_RESET];
+ let mut expected = vec![0u8; 140];
+ let expected_len = protocol_format(&mut expected, ProtocolPacketType::CtrlData, &payload);
+ expected.truncate(expected_len);
+ assert_eq!(actual, expected);
+ assert_eq!(actual, hex!("7eb401000877f67e").to_vec());
+ }
+
+ #[test]
+ fn test_get_connection_state() {
+ let mut queue = ByteQueue::with_capacity(64);
+
+ get_connection_state(&mut queue);
+
+ let actual = drain(&mut queue);
+
+ let payload = vec![CTRL_CMD_BLE_STATUS];
+ let mut expected = vec![0u8; 140];
+ let expected_len = protocol_format(&mut expected, ProtocolPacketType::CtrlData, &payload);
+ expected.truncate(expected_len);
+ assert_eq!(actual, expected);
+ assert_eq!(actual, hex!("7eb4010005b6337e").to_vec());
+ }
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.