diff options
Diffstat (limited to 'libirecovery.c')
| -rw-r--r-- | libirecovery.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/libirecovery.c b/libirecovery.c index 0aed224..81bf6d5 100644 --- a/libirecovery.c +++ b/libirecovery.c | |||
| @@ -260,17 +260,28 @@ int irecv_bulk_transfer(irecv_client_t client, | |||
| 260 | int length, | 260 | int length, |
| 261 | int *transferred, | 261 | int *transferred, |
| 262 | unsigned int timeout) { | 262 | unsigned int timeout) { |
| 263 | int ret; | ||
| 264 | |||
| 265 | // pod2g 2011-01-01: switch to interface 1.1 for bulk transfers then switch back to 0.0 | ||
| 266 | irecv_set_interface(client, 0, 0); | ||
| 267 | |||
| 263 | #ifndef WIN32 | 268 | #ifndef WIN32 |
| 264 | return libusb_bulk_transfer(client->handle, endpoint, data, length, transferred, timeout); | 269 | ret = libusb_bulk_transfer(client->handle, endpoint, data, length, transferred, timeout); |
| 265 | #else | 270 | #else |
| 266 | int ret; | ||
| 267 | if (endpoint==0x4) { | 271 | if (endpoint==0x4) { |
| 268 | ret = DeviceIoControl(client->handle, 0x220195, data, length, data, length, (PDWORD) transferred, NULL); | 272 | ret = DeviceIoControl(client->handle, 0x220195, data, length, data, length, (PDWORD) transferred, NULL); |
| 269 | } else { | 273 | } else { |
| 270 | ret = 0; | 274 | ret = 0; |
| 271 | } | 275 | } |
| 272 | return ret==0?-1:0; | 276 | ret==0?-1:0; |
| 273 | #endif | 277 | #endif |
| 278 | if (ret < 0) { | ||
| 279 | // pod2g 2010-12-28: MacOSX need a reset if read times out, also the reset seems to improve stability when switching interfaces | ||
| 280 | irecv_reset(client); | ||
| 281 | } | ||
| 282 | |||
| 283 | irecv_set_interface(client, 1, 1); | ||
| 284 | return ret; | ||
| 274 | } | 285 | } |
| 275 | 286 | ||
| 276 | int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) { | 287 | int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) { |
| @@ -358,13 +369,14 @@ irecv_error_t irecv_open(irecv_client_t* pclient) { | |||
| 358 | if (error != IRECV_E_SUCCESS) { | 369 | if (error != IRECV_E_SUCCESS) { |
| 359 | return error; | 370 | return error; |
| 360 | } | 371 | } |
| 361 | 372 | ||
| 362 | if (client->mode != kDfuMode) { | 373 | if (client->mode != kDfuMode) { |
| 363 | // pod2g 2010-12-28: switched to interface 1.1 by default on non DFU modes | 374 | // pod2g 2010-12-28: switched to interface 1.1 by default on non DFU modes |
| 364 | error = irecv_set_interface(client, 1, 1); | 375 | error = irecv_set_interface(client, 1, 1); |
| 365 | } else { | 376 | } else { |
| 366 | error = irecv_set_interface(client, 0, 0); | 377 | error = irecv_set_interface(client, 0, 0); |
| 367 | } | 378 | } |
| 379 | |||
| 368 | if (error != IRECV_E_SUCCESS) { | 380 | if (error != IRECV_E_SUCCESS) { |
| 369 | return error; | 381 | return error; |
| 370 | } | 382 | } |
| @@ -533,7 +545,8 @@ irecv_error_t irecv_close(irecv_client_t client) { | |||
| 533 | #ifndef WIN32 | 545 | #ifndef WIN32 |
| 534 | if (client->handle != NULL) { | 546 | if (client->handle != NULL) { |
| 535 | if (client->mode != kDfuMode) { | 547 | if (client->mode != kDfuMode) { |
| 536 | libusb_release_interface(client->handle, client->interface); | 548 | // pod2g 2010-12-28: this crashes iBoot on MacOSX |
| 549 | //libusb_release_interface(client->handle, client->interface); | ||
| 537 | } | 550 | } |
| 538 | libusb_close(client->handle); | 551 | libusb_close(client->handle); |
| 539 | client->handle = NULL; | 552 | client->handle = NULL; |
| @@ -752,8 +765,7 @@ irecv_error_t irecv_receive(irecv_client_t client) { | |||
| 752 | memset(buffer, '\0', BUFFER_SIZE); | 765 | memset(buffer, '\0', BUFFER_SIZE); |
| 753 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; | 766 | if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; |
| 754 | 767 | ||
| 755 | // pod2g 2010-12-28: switch to interface 0 for console reading then return to interface 1 | 768 | // pod2g 2010-12-28: switch to interface 0 for bulk transfers then return to interface 1 |
| 756 | irecv_set_interface(client, 0, 0); | ||
| 757 | int bytes = 0; | 769 | int bytes = 0; |
| 758 | while (irecv_bulk_transfer(client, 0x81, (unsigned char*) buffer, BUFFER_SIZE, &bytes, 1000) == 0) { | 770 | while (irecv_bulk_transfer(client, 0x81, (unsigned char*) buffer, BUFFER_SIZE, &bytes, 1000) == 0) { |
| 759 | if (bytes > 0) { | 771 | if (bytes > 0) { |
| @@ -763,7 +775,6 @@ irecv_error_t irecv_receive(irecv_client_t client) { | |||
| 763 | event.data = buffer; | 775 | event.data = buffer; |
| 764 | event.type = IRECV_RECEIVED; | 776 | event.type = IRECV_RECEIVED; |
| 765 | if (client->received_callback(client, &event) != 0) { | 777 | if (client->received_callback(client, &event) != 0) { |
| 766 | irecv_set_interface(client, 1, 1); | ||
| 767 | return IRECV_E_SUCCESS; | 778 | return IRECV_E_SUCCESS; |
| 768 | } | 779 | } |
| 769 | } | 780 | } |
| @@ -771,9 +782,6 @@ irecv_error_t irecv_receive(irecv_client_t client) { | |||
| 771 | } else break; | 782 | } else break; |
| 772 | } | 783 | } |
| 773 | 784 | ||
| 774 | // pod2g 2010-12-28: MacOSX need a reset if read times out, also the reset seems to improve stability when switching interfaces | ||
| 775 | irecv_reset(client); | ||
| 776 | irecv_set_interface(client, 1, 1); | ||
| 777 | return IRECV_E_SUCCESS; | 785 | return IRECV_E_SUCCESS; |
| 778 | } | 786 | } |
| 779 | 787 | ||
