Skip to content

Commit

Permalink
Fix preflight for older devices
Browse files Browse the repository at this point in the history
On older devices with iOS 5 and even before there is no "ProductName", only
"ProductType" or "DeviceClass" (which is still present).
usbmuxd fails to connect these devices, because it can't receive product name.

"DeviceClass", like "ProductVersion", can be retrieved even in locked state,
so this commit changes it to use that instead.
  • Loading branch information
mexmer authored and nikias committed Sep 21, 2022
1 parent f50e52f commit 7f24e9a
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/preflight.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ static void* preflight_worker_handle_device_add(void* userdata)

plist_t value = NULL;
char* version_str = NULL;
char* platform_str = NULL;
char* deviceclass_str = NULL;

usbmuxd_log(LL_INFO, "%s: Starting preflight on device %s...", __func__, _dev->udid);

Expand Down Expand Up @@ -228,28 +228,28 @@ static void* preflight_worker_handle_device_add(void* userdata)
goto leave;
}

lerr = lockdownd_get_value(lockdown, NULL, "ProductName", &value);
lerr = lockdownd_get_value(lockdown, NULL, "DeviceClass", &value);
if (lerr != LOCKDOWN_E_SUCCESS) {
usbmuxd_log(LL_ERROR, "%s: ERROR: Could not get ProductName from device %s, lockdown error %d", __func__, _dev->udid, lerr);
usbmuxd_log(LL_ERROR, "%s: ERROR: Could not get DeviceClass from device %s, lockdown error %d", __func__, _dev->udid, lerr);
goto leave;
}
if (value && plist_get_node_type(value) == PLIST_STRING) {
plist_get_string_val(value, &platform_str);
plist_get_string_val(value, &deviceclass_str);
}
plist_free(value);

if (!platform_str) {
usbmuxd_log(LL_ERROR, "%s: Could not get ProductName string from device %s handle %d", __func__, _dev->udid, (int)(long)_dev->conn_data);
if (!deviceclass_str) {
usbmuxd_log(LL_ERROR, "%s: Could not get DeviceClass string from device %s handle %d", __func__, _dev->udid, (int)(long)_dev->conn_data);
goto leave;
}

int version_major = strtol(version_str, NULL, 10);
if ((!strcmp(platform_str, "iPhone OS") && version_major >= 7)
|| ((!strcmp(platform_str, "watchOS") || !strcmp(platform_str, "Watch OS")) && version_major >= 2)
|| (!strcmp(platform_str, "Apple TVOS") && version_major >= 9)
if (((!strcmp(deviceclass_str, "iPhone") || !strcmp(deviceclass_str, "iPad")) && version_major >= 7)
|| (!strcmp(deviceclass_str, "Watch") && version_major >= 2)
|| (!strcmp(deviceclass_str, "AppleTV") && version_major >= 9)
) {
/* iOS 7.0 / watchOS 2.0 / tvOS 9.0 and later */
usbmuxd_log(LL_INFO, "%s: Found %s %s device %s", __func__, platform_str, version_str, _dev->udid);
usbmuxd_log(LL_INFO, "%s: Found %s %s device %s", __func__, deviceclass_str, version_str, _dev->udid);

lockdownd_set_untrusted_host_buid(lockdown);

Expand Down Expand Up @@ -356,7 +356,7 @@ static void* preflight_worker_handle_device_add(void* userdata)
}

leave:
free(platform_str);
free(deviceclass_str);
free(version_str);
if (lockdown)
lockdownd_client_free(lockdown);
Expand Down

0 comments on commit 7f24e9a

Please sign in to comment.