diff options
author | Joshua Hill | 2010-06-09 04:29:51 +0800 |
---|---|---|
committer | rcg4u | 2010-06-09 17:17:30 +0800 |
commit | bd7a45ad71862da6ecd96a1156bf5b1e123e3c43 (patch) | |
tree | f46af328ae647a4d64c96cecad125f09263b44c5 /src | |
parent | cbac0617a78db20a5430ae49b4a3fd9e3d9009cc (diff) | |
download | idevicerestore-bd7a45ad71862da6ecd96a1156bf5b1e123e3c43.tar.gz idevicerestore-bd7a45ad71862da6ecd96a1156bf5b1e123e3c43.tar.bz2 |
Added debug info for recovery.c and a few minor fixes to asr.c
Diffstat (limited to 'src')
-rw-r--r-- | src/asr.c | 106 | ||||
-rw-r--r-- | src/asr.h | 5 | ||||
-rw-r--r-- | src/recovery.c | 4 |
3 files changed, 68 insertions, 47 deletions
@@ -48,7 +48,7 @@ int asr_open_with_timeout(idevice_t device, idevice_connection_t* asr) { if (device_error == IDEVICE_E_SUCCESS) { break; } - +plist_new_ if (i >= attempts) { error("ERROR: Unable to connect to ASR client\n"); return -1; @@ -103,6 +103,7 @@ int asr_send(idevice_connection_t asr, plist_t* data) { return -1; } + debug("Sent %d bytes:\n%s", bytes, debug_plist(data)); free(buffer); return 0; } @@ -117,7 +118,6 @@ int asr_send_buffer(idevice_connection_t asr, const char* data, uint32_t size) { return -1; } - debug("Sent %d bytes:\n%s", bytes, data); return 0; } @@ -165,12 +165,7 @@ int asr_perform_validation(idevice_connection_t asr, const char* filesystem) { } plist_free(packet_info); - char* oob_data = NULL; - uint64_t oob_offset = 0; - uint64_t oob_length = 0; - plist_t oob_length_node = NULL; - plist_t oob_offset_node = NULL; - do { + while (1) { if (asr_receive(asr, &packet) < 0) { error("ERROR: Unable to receive validation packet\n"); return -1; @@ -184,48 +179,69 @@ int asr_perform_validation(idevice_connection_t asr, const char* filesystem) { plist_get_string_val(node, &command); if (!strcmp(command, "OOBData")) { - oob_length_node = plist_dict_get_item(packet, "OOB Length"); - if (!oob_length_node || PLIST_UINT != plist_get_node_type(oob_length_node)) { - error("ERROR: Unable to find OOB data length\n"); - return -1; - } - plist_get_uint_val(oob_length_node, &oob_length); - - oob_offset_node = plist_dict_get_item(packet, "OOB Offset"); - if (!oob_offset_node || PLIST_UINT != plist_get_node_type(oob_offset_node)) { - error("ERROR: Unable to find OOB data offset\n"); - return -1; - } - plist_get_uint_val(oob_offset_node, &oob_offset); - - oob_data = (char*) malloc(oob_length); - if (oob_data == NULL) { - error("ERROR: Out of memory\n"); - plist_free(packet); - return -1; - } - - fseek(file, oob_offset, SEEK_SET); - if (fread(oob_data, 1, oob_length, file) != oob_length) { - error("ERROR: Unable to read OOB data from filesystem offset\n"); - plist_free(packet); - free(oob_data); - return -1; - } - - if (asr_send_buffer(asr, oob_data, oob_length) < 0) { - error("ERROR: Unable to send OOB data to ASR\n"); - plist_free(packet); - free(oob_data); - return -1; - } + asr_handle_oob_data_request(asr, packet, file); + plist_free(packet); - free(oob_data); + } else if(!strcmp(command, "Payload")) { + plist_free(packet); + break; + + } else { + error("ERROR: Unknown command received from ASR\n"); + plist_free(packet); + return -1; } + } - } while (strcmp(packet, "Payload")); + return 0; +} + +int asr_handle_oob_data_request(idevice_connection_t asr, plist_t packet, FILE* file) { + char* oob_data = NULL; + uint64_t oob_offset = 0; + uint64_t oob_length = 0; + plist_t oob_length_node = NULL; + plist_t oob_offset_node = NULL; + + oob_length_node = plist_dict_get_item(packet, "OOB Length"); + if (!oob_length_node || PLIST_UINT != plist_get_node_type(oob_length_node)) { + error("ERROR: Unable to find OOB data length\n"); + return -1; + } + plist_get_uint_val(oob_length_node, &oob_length); + + oob_offset_node = plist_dict_get_item(packet, "OOB Offset"); + if (!oob_offset_node || PLIST_UINT != plist_get_node_type(oob_offset_node)) { + error("ERROR: Unable to find OOB data offset\n"); + return -1; + } + plist_get_uint_val(oob_offset_node, &oob_offset); + + oob_data = (char*) malloc(oob_length); + if (oob_data == NULL) { + error("ERROR: Out of memory\n"); + plist_free(packet); + return -1; + } + + fseek(file, oob_offset, SEEK_SET); + if (fread(oob_data, 1, oob_length, file) != oob_length) { + error("ERROR: Unable to read OOB data from filesystem offset\n"); + plist_free(packet); + free(oob_data); + return -1; + } + + if (asr_send_buffer(asr, oob_data, oob_length) < 0) { + error("ERROR: Unable to send OOB data to ASR\n"); + plist_free(packet); + free(oob_data); + return -1; + } + free(oob_data); + return 0; } int asr_send_payload(idevice_connection_t asr, const char* filesystem) { @@ -1,6 +1,6 @@ /* - * dfu.h - * Functions for handling idevices in normal mode + * asr.h + * Functions for handling asr connections * * Copyright (c) 2010 Joshua Hill. All Rights Reserved. * @@ -31,5 +31,6 @@ int asr_send_buffer(idevice_connection_t asr, const char* data, uint32_t size); void asr_close(idevice_connection_t asr); int asr_perform_validation(idevice_connection_t asr, const char* filesystem); int asr_send_payload(idevice_connection_t asr, const char* filesystem); +int asr_handle_oob_data_request(idevice_connection_t asr, plist_t packet, FILE* file); #endif diff --git a/src/recovery.c b/src/recovery.c index 52f4802..361ce11 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -157,6 +157,10 @@ int recovery_open_with_timeout(irecv_client_t* client) { debug("Retrying connection...\n"); } + if (idevicerestore_debug) { + irecv_set_debug(recovery, idevicerestore_debug); + } + irecv_event_subscribe(recovery, IRECV_PROGRESS, &recovery_progress_callback, NULL); *client = recovery; return 0; |