diff options
Diffstat (limited to 'tools/idevicedevmodectl.c')
| -rw-r--r-- | tools/idevicedevmodectl.c | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/tools/idevicedevmodectl.c b/tools/idevicedevmodectl.c index ba9b935..6bf1a1c 100644 --- a/tools/idevicedevmodectl.c +++ b/tools/idevicedevmodectl.c @@ -32,15 +32,16 @@ #include <sys/stat.h> #include <unistd.h> #include <errno.h> -#ifndef WIN32 +#ifndef _WIN32 #include <signal.h> #endif -#ifdef WIN32 +#ifdef _WIN32 #include <windows.h> #define __usleep(x) Sleep(x/1000) #else #include <arpa/inet.h> +#include <unistd.h> #define __usleep(x) usleep(x) #endif @@ -145,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); @@ -156,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); @@ -267,7 +259,7 @@ int main(int argc, char *argv[]) { NULL, 0, NULL, 0} }; -#ifndef WIN32 +#ifndef _WIN32 signal(SIGPIPE, SIG_IGN); #endif /* parse cmdline args */ @@ -397,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; } @@ -410,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 { |
