From 78416a40c8d9b6e54c345959d0afdaa17e245472 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 2 Feb 2012 03:49:38 +0100 Subject: recovery: merge recovery_open_with_timeout into recovery_client_new --- src/dfu.c | 4 ++-- src/normal.c | 2 +- src/recovery.c | 43 +++++++++++++------------------------------ src/recovery.h | 1 - 4 files changed, 16 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/dfu.c b/src/dfu.c index 0b3ad51..60eeaf1 100644 --- a/src/dfu.c +++ b/src/dfu.c @@ -113,7 +113,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide const char* component = "iBSS"; irecv_error_t dfu_error = IRECV_E_SUCCESS; - if (recovery_open_with_timeout(client) < 0 || dfu->mode != kDfuMode) { + if (recovery_client_new(client) < 0 || dfu->mode != kDfuMode) { error("ERROR: Unable to connect to DFU device\n"); if (dfu) irecv_close(dfu); @@ -136,7 +136,7 @@ int dfu_enter_recovery(struct idevicerestore_client_t* client, plist_t build_ide client->dfu->client = NULL; // Reconnect to device, but this time make sure we're not still in DFU mode - if (recovery_open_with_timeout(client) < 0 || client->mode->index != kDfuMode) { + if (recovery_client_new(client) < 0 || client->mode->index != kDfuMode) { error("ERROR: Unable to connect to recovery device\n"); if (client->dfu->client) irecv_close(client->dfu->client); diff --git a/src/normal.c b/src/normal.c index 509ed93..97cb0c1 100644 --- a/src/normal.c +++ b/src/normal.c @@ -260,7 +260,7 @@ int normal_enter_recovery(struct idevicerestore_client_t* client) { lockdown = NULL; device = NULL; - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { error("ERROR: Unable to enter recovery mode\n"); return -1; } diff --git a/src/recovery.c b/src/recovery.c index 0642028..624279d 100644 --- a/src/recovery.c +++ b/src/recovery.c @@ -39,24 +39,6 @@ int recovery_progress_callback(irecv_client_t client, const irecv_event_t* event return 0; } -int recovery_client_new(struct idevicerestore_client_t* client) { - struct recovery_client_t* recovery = (struct recovery_client_t*) malloc(sizeof(struct recovery_client_t)); - if (recovery == NULL) { - error("ERROR: Out of memory\n"); - return -1; - } - - client->recovery = recovery; - - if (recovery_open_with_timeout(client) < 0) { - recovery_client_free(client); - return -1; - } - - client->recovery = recovery; - return 0; -} - void recovery_client_free(struct idevicerestore_client_t* client) { if(client) { if (client->recovery) { @@ -70,18 +52,19 @@ void recovery_client_free(struct idevicerestore_client_t* client) { } } -int recovery_open_with_timeout(struct idevicerestore_client_t* client) { +int recovery_client_new(struct idevicerestore_client_t* client) { int i = 0; int attempts = 10; irecv_client_t recovery = NULL; irecv_error_t recovery_error = IRECV_E_UNKNOWN_ERROR; if(client->recovery == NULL) { - if(recovery_client_new(client) < 0) { - error("ERROR: Unable to open device in recovery mode\n"); + client->recovery = (struct recovery_client_t*)malloc(sizeof(struct recovery_client_t)); + if (client->recovery == NULL) { + error("ERROR: Out of memory\n"); return -1; } - return 0; + memset(client->recovery, 0, sizeof(struct recovery_client_t)); } for (i = 1; i <= attempts; i++) { @@ -195,7 +178,7 @@ int recovery_enter_restore(struct idevicerestore_client_t* client, plist_t build } info("Waiting for device to enter restore mode\n"); - if (restore_open_with_timeout(client) < 0) { + if (restore_client_new(client) < 0) { error("ERROR: Unable to connect to device in restore mode\n"); return -1; } @@ -276,7 +259,7 @@ int recovery_send_applelogo(struct idevicerestore_client_t* client, plist_t buil irecv_error_t recovery_error = IRECV_E_SUCCESS; info("Sending %s...\n", component); - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { return -1; } @@ -305,7 +288,7 @@ int recovery_send_devicetree(struct idevicerestore_client_t* client, plist_t bui irecv_error_t recovery_error = IRECV_E_SUCCESS; if(client->recovery == NULL) { - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { return -1; } } @@ -329,7 +312,7 @@ int recovery_send_ramdisk(struct idevicerestore_client_t* client, plist_t build_ irecv_error_t recovery_error = IRECV_E_SUCCESS; if(client->recovery == NULL) { - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { return -1; } } @@ -352,7 +335,7 @@ int recovery_send_kernelcache(struct idevicerestore_client_t* client, plist_t bu const char* component = "RestoreKernelCache"; irecv_error_t recovery_error = IRECV_E_SUCCESS; - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { return -1; } @@ -374,7 +357,7 @@ int recovery_get_ecid(struct idevicerestore_client_t* client, uint64_t* ecid) { irecv_error_t recovery_error = IRECV_E_SUCCESS; if(client->recovery == NULL) { - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { return -1; } } @@ -391,7 +374,7 @@ int recovery_get_cpid(struct idevicerestore_client_t* client, uint32_t* cpid) { irecv_error_t recovery_error = IRECV_E_SUCCESS; if(client->recovery == NULL) { - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { return -1; } } @@ -408,7 +391,7 @@ int recovery_get_bdid(struct idevicerestore_client_t* client, uint32_t* bdid) { irecv_error_t recovery_error = IRECV_E_SUCCESS; if(client->recovery == NULL) { - if (recovery_open_with_timeout(client) < 0) { + if (recovery_client_new(client) < 0) { return -1; } } diff --git a/src/recovery.h b/src/recovery.h index 278bd93..118ed4f 100644 --- a/src/recovery.h +++ b/src/recovery.h @@ -42,7 +42,6 @@ struct recovery_client_t { }; int recovery_check_mode(); -int recovery_open_with_timeout(struct idevicerestore_client_t* client); int recovery_client_new(struct idevicerestore_client_t* client); void recovery_client_free(struct idevicerestore_client_t* client); int recovery_send_component(struct idevicerestore_client_t* client, plist_t build_identity, const char* component); -- cgit v1.1-32-gdbae