Skip to content

Commit 8e89773

Browse files
committed
squash later: change if clause to check AtLeast(9,2,0) and remove
inferVersionAndProduct. also correct the status to connected and NOT initialized
1 parent 091a22d commit 8e89773

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

api/firmware/device.go

+12-17
Original file line numberDiff line numberDiff line change
@@ -232,18 +232,6 @@ func (device *Device) Version() *semver.SemVer {
232232
return device.version
233233
}
234234

235-
// inferVersionAndProduct either sets the version and product by using REQ_INFO if they were not
236-
// provided. In this case, the firmware is assumed to be >=v4.3.0, before that REQ_INFO was not
237-
// available.
238-
func (device *Device) inferVersionAndProduct(version *semver.SemVer, product common.Product) {
239-
// The version has not been provided, so we try to get it from REQ_INFO.
240-
if device.version == nil {
241-
device.log.Info(fmt.Sprintf("REQ_INFO: version=%s, product=%s", version, product))
242-
device.version = version
243-
device.product = &product
244-
}
245-
}
246-
247235
// Init initializes the device. It changes the status to StatusRequireAppUpgrade if needed,
248236
// otherwise performs the attestation check, unlock, and noise pairing. This call is blocking.
249237
// After this call finishes, Status() will be either:
@@ -259,17 +247,24 @@ func (device *Device) Init() error {
259247
device.sendCipher = nil
260248
device.receiveCipher = nil
261249

262-
if device.version == nil || device.version.AtLeast(semver.NewSemVer(4, 3, 0)) {
250+
if device.version == nil || device.version.AtLeast(semver.NewSemVer(9, 2, 0)) {
263251
deviceInfo, err := device.info()
264252
if err != nil {
265253
return errp.New(
266254
"REQ_INFO unavailable; need to provide version and product via the USB HID descriptor")
267255
}
268-
// Does nothing if device.version == nil
269-
device.inferVersionAndProduct(deviceInfo.version, deviceInfo.product)
270-
271-
if deviceInfo.unlocked || (deviceInfo.initialized != nil && *deviceInfo.initialized) {
256+
device.log.Info(fmt.Sprintf("REQ_INFO: version=%s, product=%s", deviceInfo.version,
257+
deviceInfo.product))
258+
device.version = deviceInfo.version
259+
device.product = &deviceInfo.product
260+
261+
if !deviceInfo.version.AtLeast(semver.NewSemVer(9, 20, 0)) {
262+
device.changeStatus(StatusConnected)
263+
} else if deviceInfo.unlocked {
272264
device.changeStatus(StatusInitialized)
265+
} else if *deviceInfo.initialized {
266+
// deviceInfo.initialized is not nil if version is at least 9.20.0.
267+
device.changeStatus(StatusConnected)
273268
} else {
274269
device.changeStatus(StatusUninitialized)
275270
}

api/firmware/status.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const (
3939
// device. Use CreateBackup() to move to StatusInitialized.
4040
StatusSeeded Status = "seeded"
4141

42-
// StatusInitialized means the device is seeded and the backup was created.
42+
// StatusInitialized means the device is seeded and the backup was created, and the device is
43+
// unlocked. The keystore is ready to use.
4344
StatusInitialized Status = "initialized"
4445

4546
// StatusRequireFirmwareUpgrade means that the a firmware upgrade is required before being able

0 commit comments

Comments
 (0)