What changed, and why it matters
This commit is a straightforward internal refactoring: it moves a few memory-related reads and writes (Bluetooth enabled flag, device name, platform type) behind an existing hardware abstraction layer (HAL). The actual behavior of the firmware is unchanged; the code just calls the same underlying functions through a different interface. There is no indication of a security fix or vulnerability being addressed.
No security action required. Review as normal refactoring if desired.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch extends the Memory HAL trait with ble_enabled() and ble_enable(), implements them for the real BitBox02 backend and the testing backend, and updates call sites in main_loop.rs, bluetooth.rs, and device_info.rs to use hal.memory() instead of direct bitbox02::memory::* calls. It also routes get_device_name() and get_platform() through the HAL in main_loop.rs. The diff shows no logic changes, input validation changes, bounds checks, or privilege changes.
Changed components
src/rust/bitbox02-rust/src/hal/bitbox02/memory.rssrc/rust/bitbox02-rust/src/hal/memory.rssrc/rust/bitbox02-rust/src/hal/testing/memory.rssrc/rust/bitbox02-rust/src/hww/api/bluetooth.rssrc/rust/bitbox02-rust/src/hww/api/device_info.rssrc/rust/bitbox02-rust/src/main_loop.rsInspect captured patch +30 / −6
diff --git a/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs b/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs
index 69442a5..9c5878f 100644
--- a/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs
+++ b/src/rust/bitbox02-rust/src/hal/bitbox02/memory.rs
@@ -61,6 +61,14 @@ pub(super) fn to_bitbox02_password_stretch_algo(
}
impl Memory for BitBox02Memory {
+ fn ble_enabled(&mut self) -> bool {
+ bitbox02::memory::ble_enabled()
+ }
+
+ fn ble_enable(&mut self, enable: bool) -> Result<(), ()> {
+ bitbox02::memory::ble_enable(enable)
+ }
+
fn get_securechip_type(&mut self) -> Result<SecurechipType, ()> {
bitbox02::memory::get_securechip_type().map(to_hal_securechip_type)
}
diff --git a/src/rust/bitbox02-rust/src/hal/memory.rs b/src/rust/bitbox02-rust/src/hal/memory.rs
index 632e67c..232de91 100644
--- a/src/rust/bitbox02-rust/src/hal/memory.rs
+++ b/src/rust/bitbox02-rust/src/hal/memory.rs
@@ -30,6 +30,8 @@ pub enum Error {
}
pub trait Memory {
+ fn ble_enabled(&mut self) -> bool;
+ fn ble_enable(&mut self, enable: bool) -> Result<(), ()>;
fn get_securechip_type(&mut self) -> Result<SecurechipType, ()>;
fn get_platform(&mut self) -> Result<Platform, ()>;
fn get_device_name(&mut self) -> String;
diff --git a/src/rust/bitbox02-rust/src/hal/testing/memory.rs b/src/rust/bitbox02-rust/src/hal/testing/memory.rs
index d09abb6..a315fd3 100644
--- a/src/rust/bitbox02-rust/src/hal/testing/memory.rs
+++ b/src/rust/bitbox02-rust/src/hal/testing/memory.rs
@@ -6,6 +6,7 @@ use alloc::vec::Vec;
use crate::hal::memory::{Error, PasswordStretchAlgo, Platform, SecurechipType};
pub struct TestingMemory {
+ ble_enabled: bool,
securechip_type: SecurechipType,
platform: Platform,
initialized: bool,
@@ -29,6 +30,7 @@ const MULTISIG_LIMIT: usize = 25;
impl TestingMemory {
pub fn new() -> Self {
Self {
+ ble_enabled: true,
securechip_type: SecurechipType::Optiga,
platform: Platform::BitBox02,
initialized: false,
@@ -80,6 +82,15 @@ impl TestingMemory {
}
impl crate::hal::Memory for TestingMemory {
+ fn ble_enabled(&mut self) -> bool {
+ self.ble_enabled
+ }
+
+ fn ble_enable(&mut self, enable: bool) -> Result<(), ()> {
+ self.ble_enabled = enable;
+ Ok(())
+ }
+
fn get_securechip_type(&mut self) -> Result<SecurechipType, ()> {
Ok(self.securechip_type)
}
diff --git a/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs b/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs
index 96e32e7..3538c4d 100644
--- a/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/bluetooth.rs
@@ -169,7 +169,7 @@ async fn process_upgrade(
}
async fn process_toggle_enabled(hal: &mut impl crate::hal::Hal) -> Result<Response, Error> {
- let enabled = memory::ble_enabled();
+ let enabled = hal.memory().ble_enabled();
let body = if enabled {
"Disable Bluetooth?"
} else {
@@ -184,7 +184,9 @@ async fn process_toggle_enabled(hal: &mut impl crate::hal::Hal) -> Result<Respon
})
.await?;
- memory::ble_enable(!enabled).map_err(|_| Error::Memory)?;
+ hal.memory()
+ .ble_enable(!enabled)
+ .map_err(|_| Error::Memory)?;
let status_text = if enabled {
"Bluetooth\ndisabled"
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 936f46f..f6b7b5d 100644
--- a/src/rust/bitbox02-rust/src/hww/api/device_info.rs
+++ b/src/rust/bitbox02-rust/src/hww/api/device_info.rs
@@ -15,7 +15,7 @@ pub fn process(hal: &mut impl crate::hal::Hal) -> Result<Response, Error> {
firmware_hash: ble_metadata.allowed_firmware_hash.to_vec(),
firmware_version: spi_mem::get_active_ble_firmware_version()
.map_err(|_| Error::Memory)?,
- enabled: memory::ble_enabled(),
+ enabled: hal.memory().ble_enabled(),
})
}
hal_memory::Platform::BitBox02 => None,
diff --git a/src/rust/bitbox02-rust/src/main_loop.rs b/src/rust/bitbox02-rust/src/main_loop.rs
index 878acca..77a8bee 100644
--- a/src/rust/bitbox02-rust/src/main_loop.rs
+++ b/src/rust/bitbox02-rust/src/main_loop.rs
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
+use crate::hal::Memory;
use alloc::boxed::Box;
use bitbox_executor::Executor;
use bitbox02::ringbuffer::RingBuffer;
@@ -32,7 +33,7 @@ fn main_loop(hal: &mut impl crate::hal::Hal) -> ! {
// If the bootloader has booted the BLE chip, the BLE chip isn't aware of the name according to
// the fw. Send it over.
- let device_name = bitbox02::memory::get_device_name();
+ let device_name = hal.memory().get_device_name();
bitbox02::da14531::set_name(&device_name, &mut uart_write_queue);
// This starts the async orientation screen workflow, which is processed by the loop below.
@@ -51,7 +52,7 @@ fn main_loop(hal: &mut impl crate::hal::Hal) -> ! {
#[cfg(feature = "app-u2f")]
let mut u2f_frame: USB_FRAME = unsafe { MaybeUninit::zeroed().assume_init() };
- if !bitbox02::memory::ble_enabled() {
+ if !hal.memory().ble_enabled() {
crate::communication_mode::ble_disable();
}
@@ -162,7 +163,7 @@ fn main_loop(hal: &mut impl crate::hal::Hal) -> ! {
if ORIENTATION_CHOSEN.swap(false, Ordering::Relaxed) {
// hww handler in usb_process must be setup before we can allow ble connections
- if let Ok(bitbox02::memory::Platform::BitBox02Plus) = bitbox02::memory::get_platform() {
+ if let Ok(crate::hal::memory::Platform::BitBox02Plus) = hal.memory().get_platform() {
let product = bitbox02::platform::product();
bitbox02::da14531_handler::set_product(product);
bitbox02::da14531::set_product(product, &mut uart_write_queue)
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.