diff options
| author | 2011-11-03 22:42:18 +0100 | |
|---|---|---|
| committer | 2011-11-03 22:42:18 +0100 | |
| commit | 1c678f92d1dc6500a8e2a3637b442872c2e6ae79 (patch) | |
| tree | 5ee87fdfbf89bd26623201008128d2596204c4e0 | |
| parent | 15e2b3c5e6f7daf55da66756f9529bdeeb454197 (diff) | |
| download | libirecovery-1c678f92d1dc6500a8e2a3637b442872c2e6ae79.tar.gz libirecovery-1c678f92d1dc6500a8e2a3637b442872c2e6ae79.tar.bz2 | |
use a larger usb communication timeout. fixes a lot of problems.
| -rw-r--r-- | libirecovery.c | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/libirecovery.c b/libirecovery.c index 278a529..1a6d58f 100644 --- a/libirecovery.c +++ b/libirecovery.c | |||
| @@ -33,6 +33,8 @@ | |||
| 33 | 33 | ||
| 34 | #include "libirecovery.h" | 34 | #include "libirecovery.h" |
| 35 | 35 | ||
| 36 | #define USB_TIMEOUT 5000 | ||
| 37 | |||
| 36 | #define BUFFER_SIZE 0x1000 | 38 | #define BUFFER_SIZE 0x1000 |
| 37 | #define debug(...) if(libirecovery_debug) fprintf(stderr, __VA_ARGS__) | 39 | #define debug(...) if(libirecovery_debug) fprintf(stderr, __VA_ARGS__) |
| 38 | 40 | ||
| @@ -291,7 +293,7 @@ int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, | |||
| 291 | memset(data, 0, sizeof(data)); | 293 | memset(data, 0, sizeof(data)); |
| 292 | memset(buffer, 0, size); | 294 | memset(buffer, 0, size); |
| 293 | 295 | ||
| 294 | ret = irecv_control_transfer(client, 0x80, 0x06, (0x03 << 8) | desc_index, langid, data, sizeof(data), 1000); | 296 | ret = irecv_control_transfer(client, 0x80, 0x06, (0x03 << 8) | desc_index, langid, data, sizeof(data), USB_TIMEOUT); |
| 295 | 297 | ||
| 296 | if (ret < 0) return ret; | 298 | if (ret < 0) return ret; |
| 297 | if (data[1] != 0x03) return IRECV_E_UNKNOWN_ERROR; | 299 | if (data[1] != 0x03) return IRECV_E_UNKNOWN_ERROR; |
| @@ -581,7 +583,7 @@ static irecv_error_t irecv_send_command_raw(irecv_client_t client, char* command | |||
| 581 | } | 583 | } |
| 582 | 584 | ||
| 583 | if (length > 0) { | 585 | if (length > 0) { |
| 584 | int ret = irecv_control_transfer(client, 0x40, 0, 0, 0, (unsigned char*) command, length + 1, 1000); | 586 | int ret = irecv_control_transfer(client, 0x40, 0, 0, 0, (unsigned char*) command, length + 1, USB_TIMEOUT); |
| 585 | } | 587 | } |
| 586 | 588 | ||
| 587 | return IRECV_E_SUCCESS; | 589 | return IRECV_E_SUCCESS; |
| @@ -664,7 +666,7 @@ irecv_error_t irecv_get_status(irecv_client_t client, unsigned int* status) { | |||
| 664 | 666 | ||
| 665 | unsigned char buffer[6]; | 667 | unsigned char buffer[6]; |
| 666 | memset(buffer, '\0', 6); | 668 | memset(buffer, '\0', 6); |
| 667 | if (irecv_control_transfer(client, 0xA1, 3, 0, 0, buffer, 6, 1000) != 6) { | 669 | if (irecv_control_transfer(client, 0xA1, 3, 0, 0, buffer, 6, USB_TIMEOUT) != 6) { |
| 668 | *status = 0; | 670 | *status = 0; |
| 669 | return IRECV_E_USB_STATUS; | 671 | return IRECV_E_USB_STATUS; |
| 670 | } | 672 | } |
| @@ -689,9 +691,9 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un | |||
| 689 | 691 | ||
| 690 | /* initiate transfer */ | 692 | /* initiate transfer */ |
| 691 | if (recovery_mode) { | 693 | if (recovery_mode) { |
| 692 | error = irecv_control_transfer(client, 0x41, 0, 0, 0, NULL, 0, 1000); | 694 | error = irecv_control_transfer(client, 0x41, 0, 0, 0, NULL, 0, USB_TIMEOUT); |
| 693 | } else { | 695 | } else { |
| 694 | error = irecv_control_transfer(client, 0x21, 4, 0, 0, NULL, 0, 1000); | 696 | error = irecv_control_transfer(client, 0x21, 4, 0, 0, NULL, 0, USB_TIMEOUT); |
| 695 | } | 697 | } |
| 696 | if (error != IRECV_E_SUCCESS) { | 698 | if (error != IRECV_E_SUCCESS) { |
| 697 | return error; | 699 | return error; |
| @@ -707,9 +709,9 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un | |||
| 707 | 709 | ||
| 708 | /* Use bulk transfer for recovery mode and control transfer for DFU and WTF mode */ | 710 | /* Use bulk transfer for recovery mode and control transfer for DFU and WTF mode */ |
| 709 | if (recovery_mode) { | 711 | if (recovery_mode) { |
| 710 | error = irecv_bulk_transfer(client, 0x04, &buffer[i * packet_size], size, &bytes, 1000); | 712 | error = irecv_bulk_transfer(client, 0x04, &buffer[i * packet_size], size, &bytes, USB_TIMEOUT); |
| 711 | } else { | 713 | } else { |
| 712 | bytes = irecv_control_transfer(client, 0x21, 1, 0, 0, &buffer[i * packet_size], size, 1000); | 714 | bytes = irecv_control_transfer(client, 0x21, 1, 0, 0, &buffer[i * packet_size], size, USB_TIMEOUT); |
| 713 | } | 715 | } |
| 714 | 716 | ||
| 715 | if (bytes != size) { | 717 | if (bytes != size) { |
| @@ -742,7 +744,7 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un | |||
| 742 | } | 744 | } |
| 743 | 745 | ||
| 744 | if (dfuNotifyFinished && !recovery_mode) { | 746 | if (dfuNotifyFinished && !recovery_mode) { |
| 745 | irecv_control_transfer(client, 0x21, 1, 0, 0, (unsigned char*) buffer, 0, 1000); | 747 | irecv_control_transfer(client, 0x21, 1, 0, 0, (unsigned char*) buffer, 0, USB_TIMEOUT); |
| 746 | 748 | ||
| 747 | for (i = 0; i < 3; i++) { | 749 | for (i = 0; i < 3; i++) { |
| 748 | error = irecv_get_status(client, &status); | 750 | error = irecv_get_status(client, &status); |
| @@ -806,7 +808,7 @@ irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** v | |||
| 806 | } | 808 | } |
| 807 | 809 | ||
| 808 | memset(response, '\0', 256); | 810 | memset(response, '\0', 256); |
| 809 | ret = irecv_control_transfer(client, 0xC0, 0, 0, 0, (unsigned char*) response, 255, 1000); | 811 | ret = irecv_control_transfer(client, 0xC0, 0, 0, 0, (unsigned char*) response, 255, USB_TIMEOUT); |
| 810 | 812 | ||
| 811 | *value = response; | 813 | *value = response; |
| 812 | return IRECV_E_SUCCESS; | 814 | return IRECV_E_SUCCESS; |
| @@ -823,7 +825,7 @@ irecv_error_t irecv_getret(irecv_client_t client, unsigned int* value) { | |||
| 823 | } | 825 | } |
| 824 | 826 | ||
| 825 | memset(response, '\0', 256); | 827 | memset(response, '\0', 256); |
| 826 | ret = irecv_control_transfer(client, 0xC0, 0, 0, 0, (unsigned char*) response, 255, 1000); | 828 | ret = irecv_control_transfer(client, 0xC0, 0, 0, 0, (unsigned char*) response, 255, USB_TIMEOUT); |
| 827 | 829 | ||
| 828 | *value = (unsigned int) *response; | 830 | *value = (unsigned int) *response; |
| 829 | return IRECV_E_SUCCESS; | 831 | return IRECV_E_SUCCESS; |
| @@ -909,7 +911,7 @@ irecv_error_t irecv_get_imei(irecv_client_t client, unsigned char* imei) { | |||
| 909 | 911 | ||
| 910 | irecv_error_t irecv_send_exploit(irecv_client_t client) { | 912 | irecv_error_t irecv_send_exploit(irecv_client_t client) { |
| 911 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | 913 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; |
| 912 | irecv_control_transfer(client, 0x21, 2, 0, 0, NULL, 0, 1000); | 914 | irecv_control_transfer(client, 0x21, 2, 0, 0, NULL, 0, USB_TIMEOUT); |
| 913 | return IRECV_E_SUCCESS; | 915 | return IRECV_E_SUCCESS; |
| 914 | } | 916 | } |
| 915 | 917 | ||
| @@ -1078,7 +1080,7 @@ int irecv_read_file(const char* filename, char** data, uint32_t* size) { | |||
| 1078 | irecv_error_t irecv_reset_counters(irecv_client_t client) { | 1080 | irecv_error_t irecv_reset_counters(irecv_client_t client) { |
| 1079 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | 1081 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; |
| 1080 | if (client->mode == kDfuMode) { | 1082 | if (client->mode == kDfuMode) { |
| 1081 | irecv_control_transfer(client, 0x21, 4, 0, 0, 0, 0, 1000); | 1083 | irecv_control_transfer(client, 0x21, 4, 0, 0, 0, 0, USB_TIMEOUT); |
| 1082 | } | 1084 | } |
| 1083 | return IRECV_E_SUCCESS; | 1085 | return IRECV_E_SUCCESS; |
| 1084 | } | 1086 | } |
| @@ -1105,7 +1107,7 @@ irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned lo | |||
| 1105 | unsigned int status = 0; | 1107 | unsigned int status = 0; |
| 1106 | for (i = 0; i < packets; i++) { | 1108 | for (i = 0; i < packets; i++) { |
| 1107 | unsigned short size = (i+1) < packets ? packet_size : last; | 1109 | unsigned short size = (i+1) < packets ? packet_size : last; |
| 1108 | bytes = irecv_control_transfer(client, 0xA1, 2, 0, 0, &buffer[i * packet_size], size, 1000); | 1110 | bytes = irecv_control_transfer(client, 0xA1, 2, 0, 0, &buffer[i * packet_size], size, USB_TIMEOUT); |
| 1109 | 1111 | ||
| 1110 | if (bytes != size) { | 1112 | if (bytes != size) { |
| 1111 | return IRECV_E_USB_UPLOAD; | 1113 | return IRECV_E_USB_UPLOAD; |
| @@ -1133,7 +1135,7 @@ irecv_error_t irecv_finish_transfer(irecv_client_t client) { | |||
| 1133 | 1135 | ||
| 1134 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | 1136 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; |
| 1135 | 1137 | ||
| 1136 | irecv_control_transfer(client, 0x21, 1, 0, 0, 0, 0, 1000); | 1138 | irecv_control_transfer(client, 0x21, 1, 0, 0, 0, 0, USB_TIMEOUT); |
| 1137 | 1139 | ||
| 1138 | for(i = 0; i < 3; i++){ | 1140 | for(i = 0; i < 3; i++){ |
| 1139 | irecv_get_status(client, &status); | 1141 | irecv_get_status(client, &status); |
| @@ -1231,19 +1233,19 @@ irecv_error_t irecv_get_device(irecv_client_t client, irecv_device_t* device) { | |||
| 1231 | } | 1233 | } |
| 1232 | 1234 | ||
| 1233 | switch (bdid) { | 1235 | switch (bdid) { |
| 1234 | case BDID_IPAD21 | 1236 | case BDID_IPAD21: |
| 1235 | device_id = DEVICE_IPAD21; | 1237 | device_id = DEVICE_IPAD21; |
| 1236 | break; | 1238 | break; |
| 1237 | 1239 | ||
| 1238 | case BDID_IPAD22 | 1240 | case BDID_IPAD22: |
| 1239 | device_id = DEVICE_IPAD22; | 1241 | device_id = DEVICE_IPAD22; |
| 1240 | break; | 1242 | break; |
| 1241 | 1243 | ||
| 1242 | case BDID_IPAD23 | 1244 | case BDID_IPAD23: |
| 1243 | device_id = DEVICE_IPAD23; | 1245 | device_id = DEVICE_IPAD23; |
| 1244 | break; | 1246 | break; |
| 1245 | 1247 | ||
| 1246 | case BDID_IPHONE4S | 1248 | case BDID_IPHONE4S: |
| 1247 | device_id = DEVICE_IPHONE4S; | 1249 | device_id = DEVICE_IPHONE4S; |
| 1248 | break; | 1250 | break; |
| 1249 | 1251 | ||
