summaryrefslogtreecommitdiffstats
path: root/src/libirecovery.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2024-01-04 15:59:54 +0100
committerGravatar Nikias Bassen2024-01-04 15:59:54 +0100
commit29592eb6cae8b25b214aa1e3cfb6ef4a6d555d43 (patch)
tree43fb398f74498ef24b31b549743d225d284bf009 /src/libirecovery.c
parent15fdc6ae46884208ef060dc84e32daa15e20ded8 (diff)
downloadlibirecovery-29592eb6cae8b25b214aa1e3cfb6ef4a6d555d43.tar.gz
libirecovery-29592eb6cae8b25b214aa1e3cfb6ef4a6d555d43.tar.bz2
Initialize KIS device in device callback
Also, print the detailed mode in irecovery -q and -m output.
Diffstat (limited to 'src/libirecovery.c')
-rw-r--r--src/libirecovery.c58
1 files changed, 47 insertions, 11 deletions
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
782static void irecv_copy_nonce_with_tag_from_buffer(const char* tag, unsigned char** nonce, unsigned int* nonce_size, const char *buf) 787static 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));