summaryrefslogtreecommitdiffstats
path: root/tools/idevicedevmodectl.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/idevicedevmodectl.c')
-rw-r--r--tools/idevicedevmodectl.c45
1 files changed, 28 insertions, 17 deletions
diff --git a/tools/idevicedevmodectl.c b/tools/idevicedevmodectl.c
index 739bc13..bd1de6a 100644
--- a/tools/idevicedevmodectl.c
+++ b/tools/idevicedevmodectl.c
@@ -30,6 +30,7 @@
#include <string.h>
#include <getopt.h>
#include <sys/stat.h>
+#include <unistd.h>
#include <errno.h>
#ifndef WIN32
#include <signal.h>
@@ -40,6 +41,7 @@
#define __usleep(x) Sleep(x/1000)
#else
#include <arpa/inet.h>
+#include <unistd.h>
#define __usleep(x) usleep(x)
#endif
@@ -144,7 +146,6 @@ static int amfi_service_send_msg(property_list_service_client_t amfi, plist_t ms
plist_t reply = NULL;
perr = property_list_service_receive_plist(amfi, &reply);
if (perr == PROPERTY_LIST_SERVICE_E_SUCCESS) {
- uint8_t success = 0;
plist_t val = plist_dict_get_item(reply, "Error");
if (val) {
const char* err = plist_get_string_ptr(val, NULL);
@@ -155,15 +156,7 @@ static int amfi_service_send_msg(property_list_service_client_t amfi, plist_t ms
res = 1;
}
} else {
- val = plist_dict_get_item(reply, "success");
- if (val) {
- plist_get_bool_val(val, &success);
- }
- if (success) {
- res = 0;
- } else {
- res = 1;
- }
+ res = plist_dict_get_item(reply, "success") ? 0 : 1;
}
} else {
fprintf(stderr, "Could not receive reply from device: %d\n", perr);
@@ -396,6 +389,7 @@ int main(int argc, char *argv[])
if ((op == OP_ENABLE || op == OP_ARM) && dev_mode_status) {
if (dev_mode_status) {
+ idevice_free(device);
printf("DeveloperMode is already enabled.\n");
return 0;
}
@@ -409,13 +403,30 @@ int main(int argc, char *argv[])
} else {
printf("%s: Developer Mode armed, waiting for reboot...\n", udid);
- // waiting for device to disconnect...
- WAIT_FOR(!device_connected, 20);
-
- // waiting for device to reconnect...
- WAIT_FOR(device_connected, 60);
-
- res = amfi_send_action(device, DEV_MODE_ENABLE);
+ do {
+ // waiting for device to disconnect...
+ idevice_free(device);
+ device = NULL;
+ WAIT_FOR(!device_connected, 40);
+ if (device_connected) {
+ printf("%s: ERROR: Device didn't reboot?!\n", udid);
+ res = 2;
+ break;
+ }
+ printf("disconnected\n");
+
+ // waiting for device to reconnect...
+ WAIT_FOR(device_connected, 60);
+ if (!device_connected) {
+ printf("%s: ERROR: Device didn't re-connect?!\n", udid);
+ res = 2;
+ break;
+ }
+ printf("connected\n");
+
+ idevice_new(&device, udid);
+ res = amfi_send_action(device, DEV_MODE_ENABLE);
+ } while (0);
if (res == 0) {
printf("%s: Developer Mode successfully enabled.\n", udid);
} else {