diff options
Diffstat (limited to 'src/preflight.c')
| -rw-r--r-- | src/preflight.c | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/preflight.c b/src/preflight.c index 28485db..dc4b3dc 100644 --- a/src/preflight.c +++ b/src/preflight.c | |||
| @@ -49,9 +49,10 @@ struct idevice_private { | |||
| 49 | void *conn_data; | 49 | void *conn_data; |
| 50 | }; | 50 | }; |
| 51 | 51 | ||
| 52 | struct np_cb_data { | 52 | struct cb_data { |
| 53 | idevice_t dev; | 53 | idevice_t dev; |
| 54 | np_client_t np; | 54 | np_client_t np; |
| 55 | int is_device_connected; | ||
| 55 | }; | 56 | }; |
| 56 | 57 | ||
| 57 | extern uint16_t userpref_remove_device_record(const char* udid); | 58 | extern uint16_t userpref_remove_device_record(const char* udid); |
| @@ -65,9 +66,20 @@ static void lockdownd_set_untrusted_host_buid(lockdownd_client_t lockdown) | |||
| 65 | free(system_buid); | 66 | free(system_buid); |
| 66 | } | 67 | } |
| 67 | 68 | ||
| 69 | static void idevice_callback(const idevice_event_t* event, void* userdata) | ||
| 70 | { | ||
| 71 | struct cb_data *cbdata = (struct cb_data*)userdata; | ||
| 72 | idevice_t dev = cbdata->dev; | ||
| 73 | struct idevice_private *_dev = (struct idevice_private*)dev; | ||
| 74 | |||
| 75 | if (event->event == IDEVICE_DEVICE_REMOVE && !strcmp(_dev->udid, event->udid)) { | ||
| 76 | cbdata->is_device_connected = 0; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 68 | static void np_callback(const char* notification, void* userdata) | 80 | static void np_callback(const char* notification, void* userdata) |
| 69 | { | 81 | { |
| 70 | struct np_cb_data *cbdata = (struct np_cb_data*)userdata; | 82 | struct cb_data *cbdata = (struct cb_data*)userdata; |
| 71 | idevice_t dev = cbdata->dev; | 83 | idevice_t dev = cbdata->dev; |
| 72 | struct idevice_private *_dev = (struct idevice_private*)dev; | 84 | struct idevice_private *_dev = (struct idevice_private*)dev; |
| 73 | 85 | ||
| @@ -224,11 +236,13 @@ retry: | |||
| 224 | lockdownd_client_free(lockdown); | 236 | lockdownd_client_free(lockdown); |
| 225 | lockdown = NULL; | 237 | lockdown = NULL; |
| 226 | 238 | ||
| 227 | struct np_cb_data cbdata; | 239 | struct cb_data cbdata; |
| 228 | cbdata.dev = dev; | 240 | cbdata.dev = dev; |
| 229 | cbdata.np = np; | 241 | cbdata.np = np; |
| 242 | cbdata.is_device_connected = 1; | ||
| 230 | 243 | ||
| 231 | np_set_notify_callback(np, np_callback, (void*)&cbdata); | 244 | np_set_notify_callback(np, np_callback, (void*)&cbdata); |
| 245 | idevice_event_subscribe(idevice_callback, (void*)&cbdata); | ||
| 232 | 246 | ||
| 233 | const char* spec[] = { | 247 | const char* spec[] = { |
| 234 | "com.apple.mobile.lockdown.request_pair", | 248 | "com.apple.mobile.lockdown.request_pair", |
| @@ -237,11 +251,19 @@ retry: | |||
| 237 | }; | 251 | }; |
| 238 | np_observe_notifications(np, spec); | 252 | np_observe_notifications(np, spec); |
| 239 | 253 | ||
| 240 | usbmuxd_log(LL_INFO, "%s: Waiting for user to trust this computer on device %s", __func__, _dev->udid); | ||
| 241 | /* TODO send notification to user's desktop */ | 254 | /* TODO send notification to user's desktop */ |
| 242 | while (cbdata.np) { | 255 | |
| 256 | usbmuxd_log(LL_INFO, "%s: Waiting for user to trust this computer on device %s", __func__, _dev->udid); | ||
| 257 | |||
| 258 | /* make device visible anyways */ | ||
| 259 | client_device_add(info); | ||
| 260 | |||
| 261 | while (cbdata.np && cbdata.is_device_connected == 1) { | ||
| 243 | sleep(1); | 262 | sleep(1); |
| 244 | } | 263 | } |
| 264 | usbmuxd_log(LL_INFO, "%s: Finished waiting for notification from device %s, is_device_connected %d", __func__, _dev->udid, cbdata.is_device_connected); | ||
| 265 | |||
| 266 | idevice_event_unsubscribe(); | ||
| 245 | 267 | ||
| 246 | if (cbdata.np) { | 268 | if (cbdata.np) { |
| 247 | np_client_free(cbdata.np); | 269 | np_client_free(cbdata.np); |
