Skip to content

Commit 3fed84e

Browse files
committed
api/firmware: add Bluetooth info to DeviceInfo
1 parent 0bc64fb commit 3fed84e

File tree

5 files changed

+139
-32
lines changed

5 files changed

+139
-32
lines changed

api/firmware/device.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ type Device struct {
103103
log Logger
104104
}
105105

106+
// BluetoothInfo contains Bluetooth-related info.
107+
type BluetoothInfo struct {
108+
// FirmwareHash is the hex-encoded 32 byte Bluetooth firmware hash.
109+
FirmwareHash string `json:"firmwareHash"`
110+
}
111+
106112
// DeviceInfo is the data returned from the device info api call.
107113
type DeviceInfo struct {
108114
Name string `json:"name"`
@@ -112,6 +118,8 @@ type DeviceInfo struct {
112118
// This information is only available since firmwae v9.6.0. Will be an empty string for older
113119
// firmware versions.
114120
SecurechipModel string `json:"securechipModel"`
121+
// Available on Bluetooth-enabled devices, Will be `nil` otherwise.
122+
Bluetooth *BluetoothInfo `json:"bluetooth"`
115123
}
116124

117125
// NewDevice creates a new instance of Device.

api/firmware/messages/bitbox02_system.pb.go

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

api/firmware/messages/bitbox02_system.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@ message DeviceInfoRequest {
2626
}
2727

2828
message DeviceInfoResponse {
29+
message Bluetooth {
30+
// Hash of the currently active Bluetooth firmware on the device.
31+
bytes firmware_hash = 1;
32+
}
2933
string name = 1;
3034
bool initialized = 2;
3135
string version = 3;
3236
bool mnemonic_passphrase_enabled = 4;
3337
uint32 monotonic_increments_remaining = 5;
3438
// From v9.6.0: "ATECC608A" or "ATECC608B".
3539
string securechip_model = 6;
40+
// Only present in Bluetooth-enabled devices.
41+
optional Bluetooth bluetooth = 7;
3642
}
3743

3844
message InsertRemoveSDCardRequest {

api/firmware/system.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package firmware
1616

1717
import (
18+
"encoding/hex"
19+
1820
"github.com/BitBoxSwiss/bitbox02-api-go/api/firmware/messages"
1921
"github.com/BitBoxSwiss/bitbox02-api-go/util/errp"
2022
"github.com/BitBoxSwiss/bitbox02-api-go/util/semver"
@@ -64,12 +66,20 @@ func (device *Device) DeviceInfo() (*DeviceInfo, error) {
6466
return nil, errp.New("Failed to retrieve device info")
6567
}
6668

69+
var bluetooth *BluetoothInfo
70+
if deviceInfoResponse.DeviceInfo.Bluetooth != nil {
71+
bluetooth = &BluetoothInfo{
72+
FirmwareHash: hex.EncodeToString(deviceInfoResponse.DeviceInfo.Bluetooth.FirmwareHash),
73+
}
74+
}
75+
6776
deviceInfo := &DeviceInfo{
6877
Name: deviceInfoResponse.DeviceInfo.Name,
6978
Version: deviceInfoResponse.DeviceInfo.Version,
7079
Initialized: deviceInfoResponse.DeviceInfo.Initialized,
7180
MnemonicPassphraseEnabled: deviceInfoResponse.DeviceInfo.MnemonicPassphraseEnabled,
7281
SecurechipModel: deviceInfoResponse.DeviceInfo.SecurechipModel,
82+
Bluetooth: bluetooth,
7383
}
7484

7585
return deviceInfo, nil

cmd/playground/main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ func main() {
211211

212212
info, err := device.DeviceInfo()
213213
errpanic(err)
214-
fmt.Printf("Device info: %+v", info)
214+
infoJson, err := json.MarshalIndent(info, "", " ")
215+
errpanic(err)
216+
fmt.Printf("Device info: %s", infoJson)
215217
//signFromTxID(device, "48e83b2a44c21dab01fc7bad0df1b1d7a59e48af79069454a8320ec6a9d1aefb")
216218

217219
sig, err := device.ETHSignEIP1559(

0 commit comments

Comments
 (0)