summaryrefslogtreecommitdiffstats
path: root/src/normal.c
diff options
context:
space:
mode:
authorGravatar Joshua Hill2010-06-21 05:03:27 -0400
committerGravatar Joshua Hill2010-06-21 05:03:27 -0400
commitef2a1037524ad559658a31793d4a96e07773cebc (patch)
tree45416d3eadabe83df85c97a7ce326f27258376c3 /src/normal.c
parent8708123ecfd708239137445c9f83c86a96ae63b7 (diff)
parentb39abb66ffa5e26f38cb2ba03562d091decafc84 (diff)
downloadidevicerestore-ef2a1037524ad559658a31793d4a96e07773cebc.tar.gz
idevicerestore-ef2a1037524ad559658a31793d4a96e07773cebc.tar.bz2
Merge branch 'rcg'
Diffstat (limited to 'src/normal.c')
-rw-r--r--src/normal.c194
1 files changed, 193 insertions, 1 deletions
diff --git a/src/normal.c b/src/normal.c
index c7baefd..b9270d8 100644
--- a/src/normal.c
+++ b/src/normal.c
@@ -19,10 +19,202 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <stdio.h>
#include <stdint.h>
+#include <libirecovery.h>
+#include <libimobiledevice/lockdown.h>
+#include <libimobiledevice/libimobiledevice.h>
#include "normal.h"
+#include "recovery.h"
+#include "idevicerestore.h"
-int normal_get_ecid(uint64_t* ecid) {
+int normal_check_mode(const char* uuid) {
+ char* type = NULL;
+ idevice_t device = NULL;
+ lockdownd_client_t lockdown = NULL;
+ idevice_error_t device_error = IDEVICE_E_SUCCESS;
+ lockdownd_error_t lockdown_error = IDEVICE_E_SUCCESS;
+
+ device_error = idevice_new(&device, uuid);
+ if (device_error != IDEVICE_E_SUCCESS) {
+ return -1;
+ }
+
+ lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore");
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ idevice_free(device);
+ return -1;
+ }
+
+ lockdown_error = lockdownd_query_type(lockdown, &type);
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ return -1;
+ }
+
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ lockdown = NULL;
+ device = NULL;
+ return 0;
+}
+
+int normal_check_device(const char* uuid) {
+ int i = 0;
+ idevice_t device = NULL;
+ char* product_type = NULL;
+ plist_t product_type_node = NULL;
+ lockdownd_client_t lockdown = NULL;
+ idevice_error_t device_error = IDEVICE_E_SUCCESS;
+ lockdownd_error_t lockdown_error = IDEVICE_E_SUCCESS;
+
+ device_error = idevice_new(&device, uuid);
+ if (device_error != IDEVICE_E_SUCCESS) {
+ return -1;
+ }
+
+ lockdown_error = lockdownd_client_new_with_handshake(device, &lockdown, "idevicerestore");
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ idevice_free(device);
+ return -1;
+ }
+
+ lockdown_error = lockdownd_get_value(lockdown, NULL, "ProductType", &product_type_node);
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ return -1;
+ }
+
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ lockdown = NULL;
+ device = NULL;
+
+ if (!product_type_node || plist_get_node_type(product_type_node) != PLIST_STRING) {
+ if (product_type_node) plist_free(product_type_node);
+ return -1;
+ }
+ plist_get_string_val(product_type_node, &product_type);
+ plist_free(product_type_node);
+
+ for (i = 0; idevicerestore_devices[i].product != NULL; i++) {
+ if (!strcmp(product_type, idevicerestore_devices[i].product)) {
+ break;
+ }
+ }
+
+ return idevicerestore_devices[i].device_id;
+}
+
+int normal_enter_recovery(const char* uuid) {
+ idevice_t device = NULL;
+ irecv_client_t recovery = NULL;
+ lockdownd_client_t lockdown = NULL;
+ irecv_error_t recovery_error = IRECV_E_SUCCESS;
+ idevice_error_t device_error = IDEVICE_E_SUCCESS;
+ lockdownd_error_t lockdown_error = LOCKDOWN_E_SUCCESS;
+
+ device_error = idevice_new(&device, uuid);
+ if (device_error != IDEVICE_E_SUCCESS) {
+ error("ERROR: Unable to find device\n");
+ return -1;
+ }
+
+ lockdown_error = lockdownd_client_new(device, &lockdown, "idevicerestore");
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ error("ERROR: Unable to connect to lockdownd service\n");
+ idevice_free(device);
+ return -1;
+ }
+
+ lockdown_error = lockdownd_enter_recovery(lockdown);
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ error("ERROR: Unable to place device in recovery mode\n");
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ return -1;
+ }
+
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ lockdown = NULL;
+ device = NULL;
+
+ if (recovery_open_with_timeout(&recovery) < 0) {
+ error("ERROR: Unable to enter recovery mode\n");
+ return -1;
+ }
+
+ recovery_error = irecv_send_command(recovery, "setenv auto-boot true");
+ if (recovery_error != IRECV_E_SUCCESS) {
+ error("ERROR: Unable to reset auto-boot variable\n");
+ irecv_close(recovery);
+ return -1;
+ }
+
+ recovery_error = irecv_send_command(recovery, "saveenv");
+ if (recovery_error != IRECV_E_SUCCESS) {
+ error("ERROR: Unable to save auto-boot variable\n");
+ irecv_close(recovery);
+ return -1;
+ }
+
+ idevicerestore_mode = MODE_RECOVERY;
+ irecv_close(recovery);
+ recovery = NULL;
+ return 0;
+}
+
+int normal_get_cpid(const char* uuid, uint32_t* cpid) {
+ return 0;
+}
+
+int normal_get_bdid(const char* uuid, uint32_t* bdid) {
+ return 0;
+}
+
+int normal_get_ecid(const char* uuid, uint64_t* ecid) {
+ idevice_t device = NULL;
+ plist_t unique_chip_node = NULL;
+ lockdownd_client_t lockdown = NULL;
+ idevice_error_t device_error = IDEVICE_E_SUCCESS;
+ lockdownd_error_t lockdown_error = IDEVICE_E_SUCCESS;
+
+ device_error = idevice_new(&device, uuid);
+ if (device_error != IDEVICE_E_SUCCESS) {
+ return -1;
+ }
+
+ lockdown_error = lockdownd_client_new_with_handshake(device, &lockdown, "idevicerestore");
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ error("ERROR: Unable to connect to lockdownd\n");
+ idevice_free(device);
+ return -1;
+ }
+
+ lockdown_error = lockdownd_get_value(lockdown, NULL, "UniqueChipID", &unique_chip_node);
+ if (lockdown_error != LOCKDOWN_E_SUCCESS) {
+ error("ERROR: Unable to get UniqueChipID from lockdownd\n");
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ return -1;
+ }
+
+ if (!unique_chip_node || plist_get_node_type(unique_chip_node) != PLIST_UINT) {
+ error("ERROR: Unable to get ECID\n");
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ return -1;
+ }
+ plist_get_uint_val(unique_chip_node, ecid);
+ plist_free(unique_chip_node);
+
+ lockdownd_client_free(lockdown);
+ idevice_free(device);
+ lockdown = NULL;
+ device = NULL;
return 0;
}