hal: add get_active_ble_firmware_version to Memory
What changed, and why it matters
This commit is a small internal code cleanup. It moves the way the device reads its Bluetooth firmware version from a direct hardware call into a shared memory interface, so the same code can be used in both real devices and automated tests. There is no visible change in behavior for end users, and nothing in the commit suggests a security fix or vulnerability.
No security action needed. Review as normal code-quality change.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change adds get_active_ble_firmware_version() to the Memory trait and implements it for both the real BitBox02Memory (delegating to the existing crate::spi_mem::get_active_ble_firmware_version) and the testing stub (returning a fixed “0.0.0” string). device_info.rs is updated to call the trait method instead of calling spi_mem directly. This is a refactoring for testability; the error mapping changes from Error::Memory to Error::Unknown in the real implementation, but the underlying SPI memory call is unchanged.
Changed components
src/rust/bitbox-hal/src/memory.rssrc/rust/bitbox02-rust/src/hal/testing/memory.rssrc/rust/bitbox02-rust/src/hww/api/device_info.rssrc/rust/bitbox02/src/hal/memory.rsInspect captured patch +12 / −3
diff --git a/src/rust/bitbox-hal/src/memory.rs b/src/rust/bitbox-hal/src/memory.rs
index 6269262..00fbbdc 100644
--- a/src/rust/bitbox-hal/src/memory.rs
+++ b/src/rust/bitbox-hal/src/memory.rs
@@ -46,6 +46,7 @@ pub struct BleMetadata {
pub trait Memory {
fn ble_enabled(&mut self) -> bool;
fn ble_enable(&mut self, enable: bool) -> Result<(), ()>;
+ fn get_active_ble_firmware_version(&mut self) -> Result<String, Error>;
fn ble_get_metadata(&mut self) -> BleMetadata;
fn set_ble_metadata(&mut self, metadata: &BleMetadata) -> Result<(), Error>;
fn get_securechip_type(&mut self) -> Result<SecurechipType, ()>;
diff --git a/src/rust/bitbox02-rust/src/hal/testing/memory.rs b/src/rust/bitbox02-rust/src/hal/testing/memory.rs
index eda5083..be2f36e 100644
--- a/src/rust/bitbox02-rust/src/hal/testing/memory.rs
+++ b/src/rust/bitbox02-rust/src/hal/testing/memory.rs
@@ -8,6 +8,7 @@ use crate::hal::memory::{BleMetadata, Error, PasswordStretchAlgo, Platform, Secu
pub struct TestingMemory {
ble_enabled: bool,
ble_metadata: BleMetadata,
+ active_ble_firmware_version: String,
securechip_type: SecurechipType,
platform: Platform,
initialized: bool,
@@ -38,6 +39,7 @@ impl TestingMemory {
firmware_sizes: [0; 2],
firmware_checksums: [0; 2],
},
+ active_ble_firmware_version: "0.0.0".into(),
securechip_type: SecurechipType::Optiga,
platform: Platform::BitBox02,
initialized: false,
@@ -98,6 +100,10 @@ impl crate::hal::Memory for TestingMemory {
Ok(())
}
+ fn get_active_ble_firmware_version(&mut self) -> Result<String, Error> {
+ Ok(self.active_ble_firmware_version.clone())
+ }
+
fn ble_get_metadata(&mut self) -> BleMetadata {
self.ble_metadata
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/device_info.rs b/src/rust/bitbox02-rust/src/hww/api/device_info.rs
index 99d8e62..e3cc386 100644
--- a/src/rust/bitbox02-rust/src/hww/api/device_info.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/device_info.rs
@@ -4,7 +4,6 @@ use super::Error;
use crate::hal::{Memory, SecureChip, memory as hal_memory, securechip};
use crate::pb;
-use bitbox02::spi_mem;
use pb::response::Response;
pub fn process(hal: &mut impl crate::hal::Hal) -> Result<Response, Error> {
@@ -13,8 +12,7 @@ pub fn process(hal: &mut impl crate::hal::Hal) -> Result<Response, Error> {
let ble_metadata = hal.memory().ble_get_metadata();
Some(pb::device_info_response::Bluetooth {
firmware_hash: ble_metadata.allowed_firmware_hash.to_vec(),
- firmware_version: spi_mem::get_active_ble_firmware_version()
- .map_err(|_| Error::Memory)?,
+ firmware_version: hal.memory().get_active_ble_firmware_version()?,
enabled: hal.memory().ble_enabled(),
})
}
diff --git a/src/rust/bitbox02/src/hal/memory.rs b/src/rust/bitbox02/src/hal/memory.rs
index b60b19b..e46e146 100644
--- a/src/rust/bitbox02/src/hal/memory.rs
+++ b/src/rust/bitbox02/src/hal/memory.rs
@@ -85,6 +85,10 @@ impl Memory for BitBox02Memory {
crate::memory::ble_enable(enable)
}
+ fn get_active_ble_firmware_version(&mut self) -> Result<String, Error> {
+ crate::spi_mem::get_active_ble_firmware_version().map_err(|_| Error::Unknown)
+ }
+
fn ble_get_metadata(&mut self) -> BleMetadata {
to_hal_ble_metadata(crate::memory::get_ble_metadata())
}
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.