What changed, and why it matters
This commit is a routine code reorganization. It moves two C-callable Rust functions related to Bluetooth Low Energy (BLE) communication mode from one Rust source file to another, and adjusts which Rust crate features enable the relevant code. There is no visible change to what the code does, only where it lives in the project. No security issue is evident from the diff.
No security action required. Treat as normal refactoring.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The change relocates rust_communication_mode_ble_enabled() and rust_communication_mode_ble_disable() from bitbox02-rust/src/communication_mode.rs to a new bitbox02-rust-c/src/communication_mode.rs. It also updates feature-gating so the C API module is compiled for both the firmware feature and the bootloader+bitbox02plus feature combination, and adds the bitbox02 dependency for the bitbox02plus platform. The implementation logic is unchanged.
Changed components
bitbox02-firmware Rust C API layercommunication_mode moduleInspect captured patch +24 / −18
diff --git a/src/rust/bitbox02-rust-c/Cargo.toml b/src/rust/bitbox02-rust-c/Cargo.toml
index eb19eb1..bf8b311 100644
--- a/src/rust/bitbox02-rust-c/Cargo.toml
+++ b/src/rust/bitbox02-rust-c/Cargo.toml
@@ -62,7 +62,7 @@ target-c-unit-tests = [
]
platform-bitbox02 = []
-platform-bitbox02plus = ["util/sha2", "bitbox02-noise", "bitbox02-rust"]
+platform-bitbox02plus = ["util/sha2", "bitbox02-noise", "bitbox02-rust", "bitbox02"]
bootloader = []
firmware = [
diff --git a/src/rust/bitbox02-rust-c/src/communication_mode.rs b/src/rust/bitbox02-rust-c/src/communication_mode.rs
new file mode 100644
index 0000000..88425e7
--- /dev/null
+++ b/src/rust/bitbox02-rust-c/src/communication_mode.rs
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: Apache-2.0
+
+/// C interface.
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_communication_mode_ble_enabled() -> bool {
+ bitbox02_rust::communication_mode::ble_enabled(&mut crate::HalImpl::new())
+}
+
+/// C interface.
+#[unsafe(no_mangle)]
+pub extern "C" fn rust_communication_mode_ble_disable() {
+ bitbox02_rust::communication_mode::ble_disable();
+}
diff --git a/src/rust/bitbox02-rust-c/src/firmware_c_api.rs b/src/rust/bitbox02-rust-c/src/firmware_c_api.rs
index 195111b..988e8a5 100644
--- a/src/rust/bitbox02-rust-c/src/firmware_c_api.rs
+++ b/src/rust/bitbox02-rust-c/src/firmware_c_api.rs
@@ -1,10 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
-#[allow(unused)]
-type HalImpl = bitbox02::hal::BitBox02Hal;
-
#[cfg(not(any(feature = "c-unit-testing", feature = "simulator-graphical")))]
#[unsafe(no_mangle)]
pub extern "C" fn rust_main_loop() -> ! {
- bitbox02_rust::main_loop::main_loop(&mut HalImpl::new())
+ bitbox02_rust::main_loop::main_loop(&mut crate::HalImpl::new())
}
diff --git a/src/rust/bitbox02-rust-c/src/lib.rs b/src/rust/bitbox02-rust-c/src/lib.rs
index 57d267d..7879519 100644
--- a/src/rust/bitbox02-rust-c/src/lib.rs
+++ b/src/rust/bitbox02-rust-c/src/lib.rs
@@ -11,6 +11,11 @@ mod alloc;
#[cfg(feature = "firmware")]
pub mod async_usb;
+#[cfg(any(
+ feature = "firmware",
+ all(feature = "bootloader", feature = "platform-bitbox02plus")
+))]
+mod communication_mode;
#[cfg(feature = "firmware")]
mod der;
#[cfg(feature = "firmware")]
@@ -47,7 +52,10 @@ extern crate bitbox_framed_serial_link;
extern crate util;
#[allow(unused)]
-#[cfg(feature = "firmware")]
+#[cfg(any(
+ feature = "firmware",
+ all(feature = "bootloader", feature = "platform-bitbox02plus")
+))]
type HalImpl = bitbox02::hal::BitBox02Hal;
// Whenever execution reaches somewhere it isn't supposed to rust code will "panic". Our panic
diff --git a/src/rust/bitbox02-rust/src/communication_mode.rs b/src/rust/bitbox02-rust/src/communication_mode.rs
index b024829..48367f8 100644
--- a/src/rust/bitbox02-rust/src/communication_mode.rs
+++ b/src/rust/bitbox02-rust/src/communication_mode.rs
@@ -34,18 +34,6 @@ fn has_ble(hal: &mut impl crate::hal::Hal) -> bool {
has_ble
}
-/// C interface.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_communication_mode_ble_disable() {
- ble_disable();
-}
-
-/// C interface.
-#[unsafe(no_mangle)]
-pub extern "C" fn rust_communication_mode_ble_enabled() -> bool {
- ble_enabled(&mut crate::hal::BitBox02Hal::new())
-}
-
#[cfg(test)]
mod tests {
use super::*;
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.