diff options
| author | 2024-01-04 15:59:54 +0100 | |
|---|---|---|
| committer | 2024-01-04 15:59:54 +0100 | |
| commit | 29592eb6cae8b25b214aa1e3cfb6ef4a6d555d43 (patch) | |
| tree | 43fb398f74498ef24b31b549743d225d284bf009 | |
| parent | 15fdc6ae46884208ef060dc84e32daa15e20ded8 (diff) | |
| download | libirecovery-29592eb6cae8b25b214aa1e3cfb6ef4a6d555d43.tar.gz libirecovery-29592eb6cae8b25b214aa1e3cfb6ef4a6d555d43.tar.bz2 | |
Initialize KIS device in device callback
Also, print the detailed mode in irecovery -q and -m output.
| -rw-r--r-- | include/libirecovery.h | 1 | ||||
| -rw-r--r-- | src/libirecovery.c | 58 | ||||
| -rw-r--r-- | tools/irecovery.c | 20 |
3 files changed, 64 insertions, 15 deletions
diff --git a/include/libirecovery.h b/include/libirecovery.h index 33879a4..9909f04 100644 --- a/include/libirecovery.h +++ b/include/libirecovery.h | |||
| @@ -110,6 +110,7 @@ struct irecv_device_info { | |||
| 110 | unsigned int ap_nonce_size; | 110 | unsigned int ap_nonce_size; |
| 111 | unsigned char* sep_nonce; | 111 | unsigned char* sep_nonce; |
| 112 | unsigned int sep_nonce_size; | 112 | unsigned int sep_nonce_size; |
| 113 | uint16_t pid; | ||
| 113 | }; | 114 | }; |
| 114 | 115 | ||
| 115 | typedef enum { | 116 | typedef enum { |
diff --git a/src/libirecovery.c b/src/libirecovery.c index 7ddb2b5..5d9d6fa 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c | |||
| @@ -777,6 +777,11 @@ static void irecv_load_device_info_from_iboot_string(irecv_client_t client, cons | |||
| 777 | } | 777 | } |
| 778 | client->device_info.srtg = strdup(tmp); | 778 | client->device_info.srtg = strdup(tmp); |
| 779 | } | 779 | } |
| 780 | |||
| 781 | client->device_info.pid = client->mode; | ||
| 782 | if (client->isKIS) { | ||
| 783 | client->device_info.pid = KIS_PRODUCT_ID; | ||
| 784 | } | ||
| 780 | } | 785 | } |
| 781 | 786 | ||
| 782 | static void irecv_copy_nonce_with_tag_from_buffer(const char* tag, unsigned char** nonce, unsigned int* nonce_size, const char *buf) | 787 | static void irecv_copy_nonce_with_tag_from_buffer(const char* tag, unsigned char** nonce, unsigned int* nonce_size, const char *buf) |
| @@ -2185,6 +2190,8 @@ static void* _irecv_handle_device_add(void *userdata) | |||
| 2185 | char serial_str[256]; | 2190 | char serial_str[256]; |
| 2186 | uint32_t location = 0; | 2191 | uint32_t location = 0; |
| 2187 | uint16_t product_id = 0; | 2192 | uint16_t product_id = 0; |
| 2193 | irecv_error_t error = 0; | ||
| 2194 | irecv_client_t client = NULL; | ||
| 2188 | 2195 | ||
| 2189 | memset(serial_str, 0, 256); | 2196 | memset(serial_str, 0, 256); |
| 2190 | #ifdef WIN32 | 2197 | #ifdef WIN32 |
| @@ -2263,18 +2270,14 @@ static void* _irecv_handle_device_add(void *userdata) | |||
| 2263 | 2270 | ||
| 2264 | if (product_id == KIS_PRODUCT_ID) { | 2271 | if (product_id == KIS_PRODUCT_ID) { |
| 2265 | IOObjectRetain(device); | 2272 | IOObjectRetain(device); |
| 2266 | irecv_client_t client; | ||
| 2267 | 2273 | ||
| 2268 | irecv_error_t error = iokit_usb_open_service(&client, device); | 2274 | error = iokit_usb_open_service(&client, device); |
| 2269 | if (error != IRECV_E_SUCCESS) { | 2275 | if (error != IRECV_E_SUCCESS) { |
| 2270 | debug("%s: ERROR: could not open KIS device!\n", __func__); | 2276 | debug("%s: ERROR: could not open KIS device!\n", __func__); |
| 2271 | return NULL; | 2277 | return NULL; |
| 2272 | } | 2278 | } |
| 2273 | 2279 | ||
| 2274 | strcpy(serial_str, client->device_info.serial_string); | ||
| 2275 | product_id = client->mode; | 2280 | product_id = client->mode; |
| 2276 | |||
| 2277 | irecv_close(client); | ||
| 2278 | } else { | 2281 | } else { |
| 2279 | CFStringRef serialString = (CFStringRef)IORegistryEntryCreateCFProperty(device, CFSTR(kUSBSerialNumberString), kCFAllocatorDefault, 0); | 2282 | CFStringRef serialString = (CFStringRef)IORegistryEntryCreateCFProperty(device, CFSTR(kUSBSerialNumberString), kCFAllocatorDefault, 0); |
| 2280 | if (serialString) { | 2283 | if (serialString) { |
| @@ -2307,17 +2310,13 @@ static void* _irecv_handle_device_add(void *userdata) | |||
| 2307 | } | 2310 | } |
| 2308 | 2311 | ||
| 2309 | if (product_id == KIS_PRODUCT_ID) { | 2312 | if (product_id == KIS_PRODUCT_ID) { |
| 2310 | irecv_client_t client; | 2313 | error = libusb_usb_open_handle_with_descriptor_and_ecid(&client, usb_handle, &devdesc, 0); |
| 2311 | irecv_error_t error = libusb_usb_open_handle_with_descriptor_and_ecid(&client, usb_handle, &devdesc, 0); | ||
| 2312 | if (error != IRECV_E_SUCCESS) { | 2314 | if (error != IRECV_E_SUCCESS) { |
| 2313 | debug("%s: ERROR: could not open KIS device!\n", __func__); | 2315 | debug("%s: ERROR: could not open KIS device!\n", __func__); |
| 2314 | return NULL; | 2316 | return NULL; |
| 2315 | } | 2317 | } |
| 2316 | 2318 | ||
| 2317 | strcpy(serial_str, client->device_info.serial_string); | ||
| 2318 | product_id = client->mode; | 2319 | product_id = client->mode; |
| 2319 | |||
| 2320 | irecv_close(client); | ||
| 2321 | } else { | 2320 | } else { |
| 2322 | libusb_error = libusb_get_string_descriptor_ascii(usb_handle, devdesc.iSerialNumber, (unsigned char*)serial_str, 255); | 2321 | libusb_error = libusb_get_string_descriptor_ascii(usb_handle, devdesc.iSerialNumber, (unsigned char*)serial_str, 255); |
| 2323 | if (libusb_error < 0) { | 2322 | if (libusb_error < 0) { |
| @@ -2329,8 +2328,45 @@ static void* _irecv_handle_device_add(void *userdata) | |||
| 2329 | #endif /* !HAVE_IOKIT */ | 2328 | #endif /* !HAVE_IOKIT */ |
| 2330 | #endif /* !WIN32 */ | 2329 | #endif /* !WIN32 */ |
| 2331 | memset(&client_loc, '\0', sizeof(client_loc)); | 2330 | memset(&client_loc, '\0', sizeof(client_loc)); |
| 2332 | irecv_load_device_info_from_iboot_string(&client_loc, serial_str); | 2331 | if (product_id == KIS_PRODUCT_ID) { |
| 2332 | error = irecv_usb_set_configuration(client, 1); | ||
| 2333 | if (error != IRECV_E_SUCCESS) { | ||
| 2334 | debug("Failed to set configuration, error %d\n", error); | ||
| 2335 | irecv_close(client); | ||
| 2336 | return NULL; | ||
| 2337 | } | ||
| 2338 | |||
| 2339 | error = irecv_usb_set_interface(client, 0, 0); | ||
| 2340 | if (error != IRECV_E_SUCCESS) { | ||
| 2341 | debug("Failed to set interface, error %d\n", error); | ||
| 2342 | irecv_close(client); | ||
| 2343 | return NULL; | ||
| 2344 | } | ||
| 2345 | |||
| 2346 | error = irecv_kis_init(client); | ||
| 2347 | if (error != IRECV_E_SUCCESS) { | ||
| 2348 | debug("irecv_kis_init failed, error %d\n", error); | ||
| 2349 | irecv_close(client); | ||
| 2350 | return NULL; | ||
| 2351 | } | ||
| 2352 | |||
| 2353 | error = irecv_kis_load_device_info(client); | ||
| 2354 | if (error != IRECV_E_SUCCESS) { | ||
| 2355 | debug("irecv_kis_load_device_info failed, error %d\n", error); | ||
| 2356 | irecv_close(client); | ||
| 2357 | return NULL; | ||
| 2358 | } | ||
| 2359 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)client->device_info.ecid); | ||
| 2360 | strncpy(serial_str, client->device_info.serial_string, 256); | ||
| 2361 | product_id = client->mode; | ||
| 2362 | client_loc.isKIS = 1; | ||
| 2363 | } | ||
| 2364 | if (client) { | ||
| 2365 | irecv_close(client); | ||
| 2366 | } | ||
| 2367 | |||
| 2333 | client_loc.mode = product_id; | 2368 | client_loc.mode = product_id; |
| 2369 | irecv_load_device_info_from_iboot_string(&client_loc, serial_str); | ||
| 2334 | 2370 | ||
| 2335 | struct irecv_usb_device_info *usb_dev_info = (struct irecv_usb_device_info*)malloc(sizeof(struct irecv_usb_device_info)); | 2371 | struct irecv_usb_device_info *usb_dev_info = (struct irecv_usb_device_info*)malloc(sizeof(struct irecv_usb_device_info)); |
| 2336 | memcpy(&(usb_dev_info->device_info), &(client_loc.device_info), sizeof(struct irecv_device_info)); | 2372 | memcpy(&(usb_dev_info->device_info), &(client_loc.device_info), sizeof(struct irecv_device_info)); |
diff --git a/tools/irecovery.c b/tools/irecovery.c index 34e80bf..5546ac2 100644 --- a/tools/irecovery.c +++ b/tools/irecovery.c | |||
| @@ -179,7 +179,14 @@ static void print_device_info(irecv_client_t client) | |||
| 179 | 179 | ||
| 180 | ret = irecv_get_mode(client, &mode); | 180 | ret = irecv_get_mode(client, &mode); |
| 181 | if (ret == IRECV_E_SUCCESS) { | 181 | if (ret == IRECV_E_SUCCESS) { |
| 182 | printf("MODE: %s\n", mode_to_str(mode)); | 182 | switch (devinfo->pid) { |
| 183 | case 0x1881: | ||
| 184 | printf("MODE: DFU via Debug USB (KIS)\n"); | ||
| 185 | break; | ||
| 186 | default: | ||
| 187 | printf("MODE: %s\n", mode_to_str(mode)); | ||
| 188 | break; | ||
| 189 | } | ||
| 183 | } | 190 | } |
| 184 | 191 | ||
| 185 | irecv_devices_get_device_by_client(client, &device); | 192 | irecv_devices_get_device_by_client(client, &device); |
| @@ -630,11 +637,16 @@ int main(int argc, char* argv[]) | |||
| 630 | } | 637 | } |
| 631 | break; | 638 | break; |
| 632 | 639 | ||
| 633 | case kShowMode: | 640 | case kShowMode: { |
| 641 | const struct irecv_device_info *devinfo = irecv_get_device_info(client); | ||
| 634 | irecv_get_mode(client, &mode); | 642 | irecv_get_mode(client, &mode); |
| 635 | printf("%s Mode\n", mode_to_str(mode)); | 643 | printf("%s Mode", mode_to_str(mode)); |
| 644 | if (devinfo->pid == 0x1881) { | ||
| 645 | printf(" via Debug USB (KIS)"); | ||
| 646 | } | ||
| 647 | printf("\n"); | ||
| 636 | break; | 648 | break; |
| 637 | 649 | } | |
| 638 | case kRebootToNormalMode: | 650 | case kRebootToNormalMode: |
| 639 | error = irecv_setenv(client, "auto-boot", "true"); | 651 | error = irecv_setenv(client, "auto-boot", "true"); |
| 640 | if (error != IRECV_E_SUCCESS) { | 652 | if (error != IRECV_E_SUCCESS) { |
