From 6b754bcb62fa2a898f684f54cb26249d244e57c6 Mon Sep 17 00:00:00 2001 From: pod2g Date: Sat, 1 Jan 2011 16:20:29 +0100 Subject: Now file transfers should also work at the iBoot level --- libirecovery.c | 32 ++++++++++++++++++++------------ 1 file 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, int length, int *transferred, unsigned int timeout) { + int ret; + + // pod2g 2011-01-01: switch to interface 1.1 for bulk transfers then switch back to 0.0 + irecv_set_interface(client, 0, 0); + #ifndef WIN32 - return libusb_bulk_transfer(client->handle, endpoint, data, length, transferred, timeout); + ret = libusb_bulk_transfer(client->handle, endpoint, data, length, transferred, timeout); #else - int ret; if (endpoint==0x4) { ret = DeviceIoControl(client->handle, 0x220195, data, length, data, length, (PDWORD) transferred, NULL); } else { ret = 0; } - return ret==0?-1:0; -#endif + ret==0?-1:0; +#endif + if (ret < 0) { + // pod2g 2010-12-28: MacOSX need a reset if read times out, also the reset seems to improve stability when switching interfaces + irecv_reset(client); + } + + irecv_set_interface(client, 1, 1); + return ret; } 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) { if (error != IRECV_E_SUCCESS) { return error; } - + if (client->mode != kDfuMode) { // pod2g 2010-12-28: switched to interface 1.1 by default on non DFU modes error = irecv_set_interface(client, 1, 1); } else { error = irecv_set_interface(client, 0, 0); } + if (error != IRECV_E_SUCCESS) { return error; } @@ -533,7 +545,8 @@ irecv_error_t irecv_close(irecv_client_t client) { #ifndef WIN32 if (client->handle != NULL) { if (client->mode != kDfuMode) { - libusb_release_interface(client->handle, client->interface); + // pod2g 2010-12-28: this crashes iBoot on MacOSX + //libusb_release_interface(client->handle, client->interface); } libusb_close(client->handle); client->handle = NULL; @@ -752,8 +765,7 @@ irecv_error_t irecv_receive(irecv_client_t client) { memset(buffer, '\0', BUFFER_SIZE); if (check_context(client) != IRECV_E_SUCCESS) return IRECV_E_NO_DEVICE; - // pod2g 2010-12-28: switch to interface 0 for console reading then return to interface 1 - irecv_set_interface(client, 0, 0); + // pod2g 2010-12-28: switch to interface 0 for bulk transfers then return to interface 1 int bytes = 0; while (irecv_bulk_transfer(client, 0x81, (unsigned char*) buffer, BUFFER_SIZE, &bytes, 1000) == 0) { if (bytes > 0) { @@ -763,7 +775,6 @@ irecv_error_t irecv_receive(irecv_client_t client) { event.data = buffer; event.type = IRECV_RECEIVED; if (client->received_callback(client, &event) != 0) { - irecv_set_interface(client, 1, 1); return IRECV_E_SUCCESS; } } @@ -771,9 +782,6 @@ irecv_error_t irecv_receive(irecv_client_t client) { } else break; } - // pod2g 2010-12-28: MacOSX need a reset if read times out, also the reset seems to improve stability when switching interfaces - irecv_reset(client); - irecv_set_interface(client, 1, 1); return IRECV_E_SUCCESS; } -- cgit v1.1-32-gdbae