Skip to content

Commit f71b22f

Browse files
authored
Merge pull request #1444 from benma/ble-version
api/device_info: add ble fw version
2 parents 4eae413 + 1bb7f8d commit f71b22f

File tree

8 files changed

+54
-18
lines changed

8 files changed

+54
-18
lines changed

messages/bitbox02_system.proto

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ message DeviceInfoResponse {
2929
message Bluetooth {
3030
// Hash of the currently active Bluetooth firmware on the device.
3131
bytes firmware_hash = 1;
32+
// Firmware version, formated as "major.minor.patch".
33+
string firmware_version = 2;
3234
}
3335
string name = 1;
3436
bool initialized = 2;

py/bitbox02/bitbox02/bitbox02/bitbox02.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,8 @@ def device_info(self) -> Dict[str, Any]:
177177
result["securechip_model"] = response.device_info.securechip_model
178178
if response.device_info.bluetooth is not None:
179179
result["bluetooth"] = {
180-
"firwmare_hash": response.device_info.bluetooth.firmware_hash,
180+
"firmware_hash": response.device_info.bluetooth.firmware_hash,
181+
"firmware_version": response.device_info.bluetooth.firmware_version,
181182
}
182183
else:
183184
result["bluetooth"] = None

py/bitbox02/bitbox02/communication/generated/bitbox02_system_pb2.py

Lines changed: 15 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02/bitbox02/communication/generated/bitbox02_system_pb2.pyi

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,19 @@ class DeviceInfoResponse(google.protobuf.message.Message):
3939
class Bluetooth(google.protobuf.message.Message):
4040
DESCRIPTOR: google.protobuf.descriptor.Descriptor
4141
FIRMWARE_HASH_FIELD_NUMBER: builtins.int
42+
FIRMWARE_VERSION_FIELD_NUMBER: builtins.int
4243
firmware_hash: builtins.bytes
4344
"""Hash of the currently active Bluetooth firmware on the device."""
4445

46+
firmware_version: typing.Text
47+
"""Firmware version, formated as "major.minor.patch"."""
48+
4549
def __init__(self,
4650
*,
4751
firmware_hash: builtins.bytes = ...,
52+
firmware_version: typing.Text = ...,
4853
) -> None: ...
49-
def ClearField(self, field_name: typing_extensions.Literal["firmware_hash",b"firmware_hash"]) -> None: ...
54+
def ClearField(self, field_name: typing_extensions.Literal["firmware_hash",b"firmware_hash","firmware_version",b"firmware_version"]) -> None: ...
5055

5156
NAME_FIELD_NUMBER: builtins.int
5257
INITIALIZED_FIELD_NUMBER: builtins.int

src/rust/bitbox02-rust/src/hww/api/device_info.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@ use crate::pb;
1717

1818
use pb::response::Response;
1919

20-
use bitbox02::{memory, securechip};
20+
use bitbox02::{memory, securechip, spi_mem};
2121

2222
pub fn process() -> Result<Response, Error> {
2323
let bluetooth = match memory::get_platform().map_err(|_| Error::Memory)? {
2424
memory::Platform::BitBox02Plus => {
2525
let ble_metadata = memory::get_ble_metadata();
2626
Some(pb::device_info_response::Bluetooth {
2727
firmware_hash: ble_metadata.allowed_firmware_hash.to_vec(),
28+
firmware_version: spi_mem::get_active_ble_firmware_version()
29+
.map_err(|_| Error::Memory)?,
2830
})
2931
}
3032
memory::Platform::BitBox02 => None,

src/rust/bitbox02-rust/src/shiftcrypto.bitbox02.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ pub mod device_info_response {
138138
/// Hash of the currently active Bluetooth firmware on the device.
139139
#[prost(bytes = "vec", tag = "1")]
140140
pub firmware_hash: ::prost::alloc::vec::Vec<u8>,
141+
/// Firmware version, formated as "major.minor.patch".
142+
#[prost(string, tag = "2")]
143+
pub firmware_version: ::prost::alloc::string::String,
141144
}
142145
}
143146
#[allow(clippy::derive_partial_eq_without_eq)]

src/rust/bitbox02-sys/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const ALLOWLIST_FNS: &[&str] = &[
108108
"memory_get_ble_metadata",
109109
"memory_set_ble_metadata",
110110
"memory_get_platform",
111+
"memory_spi_get_active_ble_firmware_version",
111112
"spi_mem_write",
112113
"menu_create",
113114
"mock_memory_factoryreset",

src/rust/bitbox02/src/spi_mem.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,31 @@ pub use bitbox02_sys::MEMORY_SPI_BLE_FIRMWARE_1_ADDR as BLE_FIRMWARE_1_ADDR;
1818
pub use bitbox02_sys::MEMORY_SPI_BLE_FIRMWARE_2_ADDR as BLE_FIRMWARE_2_ADDR;
1919
pub use bitbox02_sys::MEMORY_SPI_BLE_FIRMWARE_MAX_SIZE as BLE_FIRMWARE_MAX_SIZE;
2020

21+
use alloc::string::String;
22+
2123
pub fn write(address: u32, data: &[u8]) -> Result<(), ()> {
2224
match unsafe { bitbox02_sys::spi_mem_write(address, data.as_ptr(), data.len()) } {
2325
true => Ok(()),
2426
false => Err(()),
2527
}
2628
}
29+
30+
pub fn get_active_ble_firmware_version() -> Result<String, ()> {
31+
let mut ble_fw_version = core::mem::MaybeUninit::uninit();
32+
unsafe {
33+
match bitbox02_sys::memory_spi_get_active_ble_firmware_version(ble_fw_version.as_mut_ptr())
34+
{
35+
true => {
36+
let ble_fw_version = ble_fw_version.assume_init();
37+
// Copy to avoid taking references to unaligned struct fields.
38+
let (major, minor, patch) = (
39+
ble_fw_version.major,
40+
ble_fw_version.minor,
41+
ble_fw_version.patch,
42+
);
43+
Ok(format!("{}.{}.{}", major, minor, patch))
44+
}
45+
false => Err(()),
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)