summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c57
-rw-r--r--src/usbmux.c22
2 files changed, 36 insertions, 43 deletions
diff --git a/src/main.c b/src/main.c
index 1eb7af3..f672231 100644
--- a/src/main.c
+++ b/src/main.c
@@ -282,8 +282,8 @@ static void *usbmuxd_client_reader_thread(void *arg)
282 cdata->reader_dead = 0; 282 cdata->reader_dead = 0;
283 283
284 if (verbose >= 3) 284 if (verbose >= 3)
285 logmsg(LOG_NOTICE, "%s[%d:%d]: started", __func__, 285 logmsg(LOG_NOTICE, "%s[%x]: started (device %d:%d, use_count=%d)", __func__, THREAD,
286 cdata->dev->device_id, cdata->dev->use_count); 286 cdata->dev->device_id >> 16, cdata->dev->device_id & 0xFFFF, cdata->dev->use_count);
287 287
288 while (!quit_flag && !cdata->reader_quit) { 288 while (!quit_flag && !cdata->reader_quit) {
289 result = check_fd(cdata->socket, FD_WRITE, DEFAULT_TIMEOUT); 289 result = check_fd(cdata->socket, FD_WRITE, DEFAULT_TIMEOUT);
@@ -303,9 +303,8 @@ static void *usbmuxd_client_reader_thread(void *arg)
303 if (err != 0) { 303 if (err != 0) {
304 if (verbose >= 2) 304 if (verbose >= 2)
305 logmsg(LOG_ERR, 305 logmsg(LOG_ERR,
306 "%s[%d:%d]: encountered USB read error: %d", 306 "%s[%x]: encountered USB read error: %d",
307 __func__, cdata->dev->device_id, 307 __func__, THREAD, err);
308 cdata->dev->use_count, err);
309 break; 308 break;
310 } 309 }
311 310
@@ -332,8 +331,7 @@ static void *usbmuxd_client_reader_thread(void *arg)
332 } 331 }
333 332
334 if (verbose >= 3) 333 if (verbose >= 3)
335 logmsg(LOG_NOTICE, "%s[%d:%d]: terminated", __func__, 334 logmsg(LOG_NOTICE, "%s[%x]: terminated", __func__, THREAD);
336 cdata->dev->device_id, cdata->dev->use_count);
337 335
338 cdata->reader_dead = 1; 336 cdata->reader_dead = 1;
339 337
@@ -445,8 +443,8 @@ static void *usbmuxd_client_handler_thread(void *arg)
445 cdata = (struct client_data *) arg; 443 cdata = (struct client_data *) arg;
446 444
447 if (verbose >= 3) 445 if (verbose >= 3)
448 logmsg(LOG_NOTICE, "%s[%d:%d]: started", __func__, 446 logmsg(LOG_NOTICE, "%s[%x]: started (device %d:%d, use_count=%d)", __func__, THREAD,
449 cdata->dev->device_id, cdata->dev->use_count); 447 cdata->dev->device_id >> 16, cdata->dev->device_id & 0xFFFF, cdata->dev->use_count);
450 448
451 if (usbmuxd_handleConnectResult(cdata)) { 449 if (usbmuxd_handleConnectResult(cdata)) {
452 if (verbose >= 3) 450 if (verbose >= 3)
@@ -473,8 +471,7 @@ static void *usbmuxd_client_handler_thread(void *arg)
473 if (result <= 0) { 471 if (result <= 0) {
474 if (result < 0) { 472 if (result < 0) {
475 if (verbose >= 3) 473 if (verbose >= 3)
476 logmsg(LOG_ERR, "%s: Error: checkfd: %s", __func__, 474 logmsg(LOG_ERR, "%s[%x]: Error: checkfd: %s", __func__, THREAD, strerror(errno));
477 strerror(errno));
478 } 475 }
479 continue; 476 continue;
480 } 477 }
@@ -486,9 +483,7 @@ static void *usbmuxd_client_handler_thread(void *arg)
486 } 483 }
487 if (len < 0) { 484 if (len < 0) {
488 if (verbose >= 2) 485 if (verbose >= 2)
489 logmsg(LOG_ERR, "%s[%d:%d]: Error: recv: %s", __func__, 486 logmsg(LOG_ERR, "%s[%x]: Error: recv: %s", __func__, THREAD, strerror(errno));
490 cdata->dev->device_id, cdata->dev->use_count,
491 strerror(errno));
492 break; 487 break;
493 } 488 }
494 489
@@ -502,9 +497,7 @@ static void *usbmuxd_client_handler_thread(void *arg)
502 // some kind of timeout... just be patient and retry. 497 // some kind of timeout... just be patient and retry.
503 } else if (err < 0) { 498 } else if (err < 0) {
504 if (verbose >= 2) 499 if (verbose >= 2)
505 logmsg(LOG_ERR, "%s[%d:%d]: USB write error: %d", 500 logmsg(LOG_ERR, "%s[%x]: USB write error: %d", __func__, THREAD, err);
506 __func__, cdata->dev->device_id,
507 cdata->dev->use_count, err);
508 len = -1; 501 len = -1;
509 break; 502 break;
510 } 503 }
@@ -523,8 +516,7 @@ static void *usbmuxd_client_handler_thread(void *arg)
523 leave: 516 leave:
524 // cleanup 517 // cleanup
525 if (verbose >= 3) 518 if (verbose >= 3)
526 logmsg(LOG_NOTICE, "%s[%d:%d]: terminating", __func__, 519 logmsg(LOG_NOTICE, "%s[%x]: terminating", __func__, THREAD);
527 cdata->dev->device_id, cdata->dev->use_count);
528 if (cdata->reader != 0) { 520 if (cdata->reader != 0) {
529 cdata->reader_quit = 1; 521 cdata->reader_quit = 1;
530 pthread_join(cdata->reader, NULL); 522 pthread_join(cdata->reader, NULL);
@@ -533,8 +525,7 @@ static void *usbmuxd_client_handler_thread(void *arg)
533 cdata->handler_dead = 1; 525 cdata->handler_dead = 1;
534 526
535 if (verbose >= 3) 527 if (verbose >= 3)
536 logmsg(LOG_NOTICE, "%s[%d:%d]: terminated", __func__, 528 logmsg(LOG_NOTICE, "%s[%x]: terminated", __func__, THREAD);
537 cdata->dev->device_id, cdata->dev->use_count);
538 return NULL; 529 return NULL;
539} 530}
540 531
@@ -682,7 +673,10 @@ static void *usbmuxd_client_init_thread(void *arg)
682 memset(&dev_info_rec, 0, sizeof(dev_info_rec)); 673 memset(&dev_info_rec, 0, sizeof(dev_info_rec));
683 dev_info_rec.header.length = sizeof(dev_info_rec); 674 dev_info_rec.header.length = sizeof(dev_info_rec);
684 dev_info_rec.header.type = USBMUXD_DEVICE_INFO; 675 dev_info_rec.header.type = USBMUXD_DEVICE_INFO;
685 dev_info_rec.device.device_id = dev->devnum; 676 uint32_t dev_id =
677 strtol(dev->filename, NULL, 10)
678 + (strtoul(bus->dirname, NULL, 10) << 16);
679 dev_info_rec.device.device_id = dev_id;
686 dev_info_rec.device.product_id = dev->descriptor.idProduct; 680 dev_info_rec.device.product_id = dev->descriptor.idProduct;
687 if (dev->descriptor.iSerialNumber) { 681 if (dev->descriptor.iSerialNumber) {
688 usb_dev_handle *udev; 682 usb_dev_handle *udev;
@@ -755,9 +749,8 @@ static void *usbmuxd_client_init_thread(void *arg)
755 749
756 if (verbose >= 3) 750 if (verbose >= 3)
757 logmsg(LOG_NOTICE, 751 logmsg(LOG_NOTICE,
758 "%s[%x]: Setting up connection to usb device #%d on port %d", 752 "%s[%x]: Setting up connection to usb device %d:%d on port %d",
759 __func__, THREAD, c_req->device_id, 753 __func__, THREAD, c_req->device_id >> 16, c_req->device_id & 0xFFFF, ntohs(c_req->tcp_dport));
760 ntohs(c_req->tcp_dport));
761 754
762 // find the device, and open usb connection 755 // find the device, and open usb connection
763 pthread_mutex_lock(&usbmux_mutex); 756 pthread_mutex_lock(&usbmux_mutex);
@@ -780,16 +773,16 @@ static void *usbmuxd_client_init_thread(void *arg)
780 // if not found, make a new connection 773 // if not found, make a new connection
781 if (verbose >= 2) 774 if (verbose >= 2)
782 logmsg(LOG_NOTICE, 775 logmsg(LOG_NOTICE,
783 "%s[%x]: creating new usb connection, device_id=%d", 776 "%s[%x]: creating new usb connection, device %d:%d",
784 __func__, THREAD, c_req->device_id); 777 __func__, THREAD, c_req->device_id >> 16, c_req->device_id & 0xFFFF);
785 778
786 pthread_mutex_lock(&usb_mutex); 779 pthread_mutex_lock(&usb_mutex);
787 if (usbmux_get_specific_device(0, c_req->device_id, &phone) < 0) { 780 if (usbmux_get_specific_device(c_req->device_id >> 16, c_req->device_id & 0xFFFF, &phone) < 0) {
788 pthread_mutex_unlock(&usb_mutex); 781 pthread_mutex_unlock(&usb_mutex);
789 pthread_mutex_unlock(&usbmux_mutex); 782 pthread_mutex_unlock(&usbmux_mutex);
790 if (verbose >= 1) 783 if (verbose >= 1)
791 logmsg(LOG_ERR, "%s[%x]: device_id %d could not be opened", 784 logmsg(LOG_ERR, "%s[%x]: device %d:%d could not be opened",
792 __func__, THREAD, c_req->device_id); 785 __func__, THREAD, c_req->device_id >> 16, c_req->device_id & 0xFFFF);
793 usbmuxd_send_result(cdata->socket, c_req->header.tag, ENODEV); 786 usbmuxd_send_result(cdata->socket, c_req->header.tag, ENODEV);
794 goto leave; 787 goto leave;
795 } 788 }
@@ -825,8 +818,8 @@ static void *usbmuxd_client_init_thread(void *arg)
825 } else { 818 } else {
826 if (verbose >= 2) 819 if (verbose >= 2)
827 logmsg(LOG_NOTICE, 820 logmsg(LOG_NOTICE,
828 "%s[%x]: reusing usb connection, device_id=%d", 821 "%s[%x]: reusing usb connection, device %d:%d",
829 __func__, THREAD, c_req->device_id); 822 __func__, THREAD, c_req->device_id >> 16, c_req->device_id & 0xFFFF);
830 } 823 }
831 pthread_mutex_unlock(&usbmux_mutex); 824 pthread_mutex_unlock(&usbmux_mutex);
832 825
diff --git a/src/usbmux.c b/src/usbmux.c
index 90aeb84..c64d1a0 100644
--- a/src/usbmux.c
+++ b/src/usbmux.c
@@ -324,18 +324,18 @@ int usbmux_get_specific_device(int bus_n, int dev_n,
324 324
325 // Set the device configuration 325 // Set the device configuration
326 for (bus = usb_get_busses(); bus; bus = bus->next) 326 for (bus = usb_get_busses(); bus; bus = bus->next)
327 //if (bus->location == bus_n) 327 if (strtoul(bus->dirname, NULL, 10) == bus_n)
328 for (dev = bus->devices; dev != NULL; dev = dev->next) 328 for (dev = bus->devices; dev != NULL; dev = dev->next)
329 if (dev->devnum == dev_n) { 329 if (strtol(dev->filename, NULL, 10) == dev_n) {
330 newdevice->__device = dev; 330 newdevice->__device = dev;
331 newdevice->usbdev = usb_open(newdevice->__device); 331 newdevice->usbdev = usb_open(newdevice->__device);
332 if (!newdevice->usbdev) { 332 if (!newdevice->usbdev) {
333 fprintf(stderr, "%s: Error: usb_open(): %s\n", __func__, usb_strerror()); 333 fprintf(stderr, "%s: Error: usb_open(): %s\n", __func__, usb_strerror());
334 }
335 if (usbmux_config_usb_device(newdevice) == 0) {
336 goto found;
337 }
334 } 338 }
335 if (usbmux_config_usb_device(newdevice) == 0) {
336 goto found;
337 }
338 }
339 339
340 usbmux_free_device(newdevice); 340 usbmux_free_device(newdevice);
341 341