summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2016-06-26 16:15:03 +0200
committerGravatar Nikias Bassen2016-06-26 16:15:03 +0200
commitc22fb01537f39cc1288b860b24a8ae48e49f06f9 (patch)
treed1fad4af5df6f1212d0bb2891ecbffe15ce63bef /src
parentd0129ee911ebbb7a5da7daf496231e23afb305a2 (diff)
downloadlibirecovery-c22fb01537f39cc1288b860b24a8ae48e49f06f9.tar.gz
libirecovery-c22fb01537f39cc1288b860b24a8ae48e49f06f9.tar.bz2
Add DFU error handling
Diffstat (limited to 'src')
-rw-r--r--src/libirecovery.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index 62c675a..33711c2 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -1693,11 +1693,26 @@ IRECV_API irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char*
if (recovery_mode) {
error = irecv_usb_control_transfer(client, 0x41, 0, 0, 0, NULL, 0, USB_TIMEOUT);
} else {
- unsigned char dump[4];
- if (irecv_usb_control_transfer(client, 0xa1, 5, 0, 0, dump, 1, USB_TIMEOUT) == 1) {
+ uint8_t state = 0;
+ if (irecv_usb_control_transfer(client, 0xa1, 5, 0, 0, (unsigned char*)&state, 1, USB_TIMEOUT) == 1) {
error = IRECV_E_SUCCESS;
} else {
+ return IRECV_E_USB_UPLOAD;
+ }
+ switch (state) {
+ case 2:
+ /* DFU IDLE */
+ break;
+ case 10:
+ debug("DFU ERROR, issuing CLRSTATUS\n");
+ irecv_usb_control_transfer(client, 0x21, 4, 0, 0, NULL, 0, USB_TIMEOUT);
error = IRECV_E_USB_UPLOAD;
+ break;
+ default:
+ debug("Unexpected state %d, issuing ABORT\n", state);
+ irecv_usb_control_transfer(client, 0x21, 6, 0, 0, NULL, 0, USB_TIMEOUT);
+ error = IRECV_E_USB_UPLOAD;
+ break;
}
}