@@ -777,6 +777,11 @@ static void irecv_load_device_info_from_iboot_string(irecv_client_t client, cons
777777 }
778778 client -> device_info .srtg = strdup (tmp );
779779 }
780+
781+ client -> device_info .pid = client -> mode ;
782+ if (client -> isKIS ) {
783+ client -> device_info .pid = KIS_PRODUCT_ID ;
784+ }
780785}
781786
782787static 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)
21852190 char serial_str [256 ];
21862191 uint32_t location = 0 ;
21872192 uint16_t product_id = 0 ;
2193+ irecv_error_t error = 0 ;
2194+ irecv_client_t client = NULL ;
21882195
21892196 memset (serial_str , 0 , 256 );
21902197#ifdef WIN32
@@ -2263,18 +2270,14 @@ static void* _irecv_handle_device_add(void *userdata)
22632270
22642271 if (product_id == KIS_PRODUCT_ID ) {
22652272 IOObjectRetain (device );
2266- irecv_client_t client ;
22672273
2268- irecv_error_t error = iokit_usb_open_service (& client , device );
2274+ error = iokit_usb_open_service (& client , device );
22692275 if (error != IRECV_E_SUCCESS ) {
22702276 debug ("%s: ERROR: could not open KIS device!\n" , __func__ );
22712277 return NULL ;
22722278 }
22732279
2274- strcpy (serial_str , client -> device_info .serial_string );
22752280 product_id = client -> mode ;
2276-
2277- irecv_close (client );
22782281 } else {
22792282 CFStringRef serialString = (CFStringRef )IORegistryEntryCreateCFProperty (device , CFSTR (kUSBSerialNumberString ), kCFAllocatorDefault , 0 );
22802283 if (serialString ) {
@@ -2307,17 +2310,13 @@ static void* _irecv_handle_device_add(void *userdata)
23072310 }
23082311
23092312 if (product_id == KIS_PRODUCT_ID ) {
2310- irecv_client_t client ;
2311- irecv_error_t error = libusb_usb_open_handle_with_descriptor_and_ecid (& client , usb_handle , & devdesc , 0 );
2313+ error = libusb_usb_open_handle_with_descriptor_and_ecid (& client , usb_handle , & devdesc , 0 );
23122314 if (error != IRECV_E_SUCCESS ) {
23132315 debug ("%s: ERROR: could not open KIS device!\n" , __func__ );
23142316 return NULL ;
23152317 }
23162318
2317- strcpy (serial_str , client -> device_info .serial_string );
23182319 product_id = client -> mode ;
2319-
2320- irecv_close (client );
23212320 } else {
23222321 libusb_error = libusb_get_string_descriptor_ascii (usb_handle , devdesc .iSerialNumber , (unsigned char * )serial_str , 255 );
23232322 if (libusb_error < 0 ) {
@@ -2329,8 +2328,45 @@ static void* _irecv_handle_device_add(void *userdata)
23292328#endif /* !HAVE_IOKIT */
23302329#endif /* !WIN32 */
23312330 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+
23332368 client_loc .mode = product_id ;
2369+ irecv_load_device_info_from_iboot_string (& client_loc , serial_str );
23342370
23352371 struct irecv_usb_device_info * usb_dev_info = (struct irecv_usb_device_info * )malloc (sizeof (struct irecv_usb_device_info ));
23362372 memcpy (& (usb_dev_info -> device_info ), & (client_loc .device_info ), sizeof (struct irecv_device_info ));
0 commit comments