Skip to content
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

DFU mode: improve programming robustness. #98

Merged
merged 2 commits into from
Jan 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [0.0.27] - 2021-01-20
- pin fido2 dep to 0.8 series @uli-heller
- improve programming robustness @enrikb

## [0.0.26] - 2020-07-17
- fix bungled reference to `STABLE_VERSION` file
Expand Down
25 changes: 20 additions & 5 deletions solo/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# http://opensource.org/licenses/MIT>, at your option. This file may not be
# copied, modified, or distributed except according to those terms.

import errno
import struct
import time

Expand Down Expand Up @@ -136,11 +137,25 @@ def init(self):
def close(self):
pass

def get_status(self):
# bmReqType, bmReq, wValue, wIndex, data/size
s = self.dev.ctrl_transfer(
DFU.type.RECEIVE, DFU.bmReq.GETSTATUS, 0, self.intNum, 6
)
def get_status(self,):
tries = 3
while True:
try:
# bmReqType, bmReq, wValue, wIndex, data/size
s = self.dev.ctrl_transfer(
DFU.type.RECEIVE, DFU.bmReq.GETSTATUS, 0, self.intNum, 6
)
break
except usb.core.USBError as e:
if e.errno == errno.EPIPE:
if tries > 0:
tries -= 1
time.sleep(0.01)
else:
# do not pass on EPIPE which might be swallowed by 'click'
raise RuntimeError("Failed to get status from DFU.")
else:
raise
return DFU.status(s)

def state(self):
Expand Down