-
Notifications
You must be signed in to change notification settings - Fork 107
hww: _api_info write byte for initialized status #1229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks. Please add a CHANGELOG entry
src/hww.c
Outdated
@@ -97,6 +99,10 @@ static size_t _api_info(uint8_t* buf) | |||
*current = keystore_is_locked() ? 0x00 : 0x01; | |||
current++; | |||
|
|||
// 1 byte initialized status | |||
*current = memory_is_initialized() ? 0x00 : 0x01; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't 0x01
for "is_initialized" be more intuitive? If one interprets 0x00 as false and 0x01 as true.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
True, I just copy and pasted the above without thinking much. I'll change it, and also change the switch
in the go api then.
6f3fa21
to
0884c0e
Compare
0884c0e
to
a84f8c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Please also, in a new commit, adjust the Py lib in the same repo, add a CHANGELOG entry to the Py lib and bump the pylib version (major version bump as it's an incompatible change)
This is useful to get the version of the firmware when a usb descriptor is not available | ||
(via BitBoxBridge, etc.). | ||
Returns (version, platform, edition, unlocked, initialized). | ||
This is useful to get the version of the firmware or the device unlocked/initialized status |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the This is useful (...) part could be improved but I don't understand it well enough and also I'm bad at constructing concise sentences.
-> this is useful if there was no handshake yet too, otherwise we could just call the other info request that already has the initialized attribute in the response...how could this be phrased ? (when I tried to use the other request in api-go
it would throw an error like this: handshake must come first
but I guess it is fine to leave it as is?
initialized_byte = response[0] | ||
initialized = {0x00: False, 0x01: True}[initialized_byte] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will crash on firmware versions that don't support this yet. Maybe one way of dealing with this is to return Optional[bool]
and document that it is None
if not supported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yes thanks, it would throw index out of range for initialized_byte = response[0]
should I just try except
it and set initialized
to None
in except
or is there a better way of handling this (checking somehow if it is supported ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can check the firmware version, there are other examples. For now let's expect this to go into v9.20.0, but we can adjust the number if it lands quicker.
6fcdc15
to
5b74fa5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CI complains about code formatting. Apply black py/bitbox02/bitbox02/communication/bitbox_api_protocol.py
to format the file.
Returns (version, platform, edition, unlocked, initialized). | ||
This is useful to get the version of the firmware or the device unlocked/initialized status | ||
when a usb descriptor is not available (via BitBoxBridge, etc.). In case the firmware does not | ||
respond with the initialized byte yet None is returned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docstring could be more explicit: "The initialized status is supported from firmware v9.20.0 (it is None
if not supported)"
5b74fa5
to
c915e94
Compare
@benma thanks! rebased and re-formatted/changed docstring as suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please also bump version strings to 9.20.0, which is now possible after we released 9.19.0
return (version_str, platform, edition, unlocked) | ||
|
||
initialized = None | ||
if version_str >= semver.VersionInfo(9, 20, 0): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please test your changes - this check does not work, it crashes because version_str
is not a valid version string with the v
prefix.
Use parse_device_version(version_str) instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, thanks.
Write another byte for the initialized status in the _api_info function. This field can be used to check whether a device can be unlocked or not. The unlocked byte is not sufficient because unlocked = false could mean the device is locked or the device is uninitialized.
c915e94
to
62b4f29
Compare
The device now returns an additional byte from REQ_INFO: 0x00 if the device is not initialized and 0x01 if it is. Read this byte in get_info from the REQ_INFO response in case the firmware version supports it, and add it to the tuple that is returned, None if the firmware does not support it yet.
62b4f29
to
349983a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK, thanks!
Write another byte for the initialized status in the _api_info function. This field can be used to check whether a device can be unlocked or not. The unlocked byte is not sufficient because unlocked = false could mean the device is locked or the device is uninitialized.