diff options
Diffstat (limited to 'src/usb.c')
-rw-r--r-- | src/usb.c | 46 |
1 files changed, 23 insertions, 23 deletions
@@ -97,7 +97,7 @@ static void usb_disconnect(struct usb_device *dev) | |||
97 | tv.tv_sec = 0; | 97 | tv.tv_sec = 0; |
98 | tv.tv_usec = 1000; | 98 | tv.tv_usec = 1000; |
99 | if((res = libusb_handle_events_timeout(NULL, &tv)) < 0) { | 99 | if((res = libusb_handle_events_timeout(NULL, &tv)) < 0) { |
100 | usbmuxd_log(LL_ERROR, "libusb_handle_events_timeout for usb_disconnect failed: %d", res); | 100 | usbmuxd_log(LL_ERROR, "libusb_handle_events_timeout for usb_disconnect failed: %s", libusb_error_name(res)); |
101 | break; | 101 | break; |
102 | } | 102 | } |
103 | } | 103 | } |
@@ -169,7 +169,7 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length) | |||
169 | struct libusb_transfer *xfer = libusb_alloc_transfer(0); | 169 | struct libusb_transfer *xfer = libusb_alloc_transfer(0); |
170 | libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_out, (void*)buf, length, tx_callback, dev, 0); | 170 | libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_out, (void*)buf, length, tx_callback, dev, 0); |
171 | if((res = libusb_submit_transfer(xfer)) < 0) { | 171 | if((res = libusb_submit_transfer(xfer)) < 0) { |
172 | usbmuxd_log(LL_ERROR, "Failed to submit TX transfer %p len %d to device %d-%d: %d", buf, length, dev->bus, dev->address, res); | 172 | usbmuxd_log(LL_ERROR, "Failed to submit TX transfer %p len %d to device %d-%d: %s", buf, length, dev->bus, dev->address, libusb_error_name(res)); |
173 | libusb_free_transfer(xfer); | 173 | libusb_free_transfer(xfer); |
174 | return res; | 174 | return res; |
175 | } | 175 | } |
@@ -181,7 +181,7 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length) | |||
181 | void *buffer = malloc(1); | 181 | void *buffer = malloc(1); |
182 | libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_out, buffer, 0, tx_callback, dev, 0); | 182 | libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_out, buffer, 0, tx_callback, dev, 0); |
183 | if((res = libusb_submit_transfer(xfer)) < 0) { | 183 | if((res = libusb_submit_transfer(xfer)) < 0) { |
184 | usbmuxd_log(LL_ERROR, "Failed to submit TX ZLP transfer to device %d-%d: %d", dev->bus, dev->address, res); | 184 | usbmuxd_log(LL_ERROR, "Failed to submit TX ZLP transfer to device %d-%d: %s", dev->bus, dev->address, libusb_error_name(res)); |
185 | libusb_free_transfer(xfer); | 185 | libusb_free_transfer(xfer); |
186 | return res; | 186 | return res; |
187 | } | 187 | } |
@@ -248,7 +248,7 @@ static int start_rx_loop(struct usb_device *dev) | |||
248 | buf = malloc(USB_MRU); | 248 | buf = malloc(USB_MRU); |
249 | libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_in, buf, USB_MRU, rx_callback, dev, 0); | 249 | libusb_fill_bulk_transfer(xfer, dev->dev, dev->ep_in, buf, USB_MRU, rx_callback, dev, 0); |
250 | if((res = libusb_submit_transfer(xfer)) != 0) { | 250 | if((res = libusb_submit_transfer(xfer)) != 0) { |
251 | usbmuxd_log(LL_ERROR, "Failed to submit RX transfer to device %d-%d: %d", dev->bus, dev->address, res); | 251 | usbmuxd_log(LL_ERROR, "Failed to submit RX transfer to device %d-%d: %s", dev->bus, dev->address, libusb_error_name(res)); |
252 | libusb_free_transfer(xfer); | 252 | libusb_free_transfer(xfer); |
253 | return res; | 253 | return res; |
254 | } | 254 | } |
@@ -350,7 +350,7 @@ static void get_langid_callback(struct libusb_transfer *transfer) | |||
350 | libusb_fill_control_transfer(transfer, usbdev->dev, transfer->buffer, get_serial_callback, usbdev, 1000); | 350 | libusb_fill_control_transfer(transfer, usbdev->dev, transfer->buffer, get_serial_callback, usbdev, 1000); |
351 | 351 | ||
352 | if((res = libusb_submit_transfer(transfer)) < 0) { | 352 | if((res = libusb_submit_transfer(transfer)) < 0) { |
353 | usbmuxd_log(LL_ERROR, "Could not request transfer for device %d-%d (%d)", usbdev->bus, usbdev->address, res); | 353 | usbmuxd_log(LL_ERROR, "Could not request transfer for device %d-%d: %s", usbdev->bus, usbdev->address, libusb_error_name(res)); |
354 | libusb_free_transfer(transfer); | 354 | libusb_free_transfer(transfer); |
355 | } | 355 | } |
356 | } | 356 | } |
@@ -375,7 +375,7 @@ static int usb_device_add(libusb_device* dev) | |||
375 | return 0; //device already found | 375 | return 0; //device already found |
376 | 376 | ||
377 | if((res = libusb_get_device_descriptor(dev, &devdesc)) != 0) { | 377 | if((res = libusb_get_device_descriptor(dev, &devdesc)) != 0) { |
378 | usbmuxd_log(LL_WARNING, "Could not get device descriptor for device %d-%d: %d", bus, address, res); | 378 | usbmuxd_log(LL_WARNING, "Could not get device descriptor for device %d-%d: %s", bus, address, libusb_error_name(res)); |
379 | return -1; | 379 | return -1; |
380 | } | 380 | } |
381 | if(devdesc.idVendor != VID_APPLE) | 381 | if(devdesc.idVendor != VID_APPLE) |
@@ -389,7 +389,7 @@ static int usb_device_add(libusb_device* dev) | |||
389 | // No blocking operation can follow: it may be run in the libusb hotplug callback and libusb will refuse any | 389 | // No blocking operation can follow: it may be run in the libusb hotplug callback and libusb will refuse any |
390 | // blocking call | 390 | // blocking call |
391 | if((res = libusb_open(dev, &handle)) != 0) { | 391 | if((res = libusb_open(dev, &handle)) != 0) { |
392 | usbmuxd_log(LL_WARNING, "Could not open device %d-%d: %d", bus, address, res); | 392 | usbmuxd_log(LL_WARNING, "Could not open device %d-%d: %s", bus, address, libusb_error_name(res)); |
393 | return -1; | 393 | return -1; |
394 | } | 394 | } |
395 | 395 | ||
@@ -399,25 +399,25 @@ static int usb_device_add(libusb_device* dev) | |||
399 | } | 399 | } |
400 | int current_config = 0; | 400 | int current_config = 0; |
401 | if((res = libusb_get_configuration(handle, ¤t_config)) != 0) { | 401 | if((res = libusb_get_configuration(handle, ¤t_config)) != 0) { |
402 | usbmuxd_log(LL_WARNING, "Could not get configuration for device %d-%d: %d", bus, address, res); | 402 | usbmuxd_log(LL_WARNING, "Could not get configuration for device %d-%d: %s", bus, address, libusb_error_name(res)); |
403 | libusb_close(handle); | 403 | libusb_close(handle); |
404 | return -1; | 404 | return -1; |
405 | } | 405 | } |
406 | if (current_config != desired_config) { | 406 | if (current_config != desired_config) { |
407 | struct libusb_config_descriptor *config; | 407 | struct libusb_config_descriptor *config; |
408 | if((res = libusb_get_active_config_descriptor(dev, &config)) != 0) { | 408 | if((res = libusb_get_active_config_descriptor(dev, &config)) != 0) { |
409 | usbmuxd_log(LL_NOTICE, "Could not get old configuration descriptor for device %d-%d: %d", bus, address, res); | 409 | usbmuxd_log(LL_NOTICE, "Could not get old configuration descriptor for device %d-%d: %s", bus, address, libusb_error_name(res)); |
410 | } else { | 410 | } else { |
411 | for(j=0; j<config->bNumInterfaces; j++) { | 411 | for(j=0; j<config->bNumInterfaces; j++) { |
412 | const struct libusb_interface_descriptor *intf = &config->interface[j].altsetting[0]; | 412 | const struct libusb_interface_descriptor *intf = &config->interface[j].altsetting[0]; |
413 | if((res = libusb_kernel_driver_active(handle, intf->bInterfaceNumber)) < 0) { | 413 | if((res = libusb_kernel_driver_active(handle, intf->bInterfaceNumber)) < 0) { |
414 | usbmuxd_log(LL_NOTICE, "Could not check kernel ownership of interface %d for device %d-%d: %d", intf->bInterfaceNumber, bus, address, res); | 414 | usbmuxd_log(LL_NOTICE, "Could not check kernel ownership of interface %d for device %d-%d: %s", intf->bInterfaceNumber, bus, address, libusb_error_name(res)); |
415 | continue; | 415 | continue; |
416 | } | 416 | } |
417 | if(res == 1) { | 417 | if(res == 1) { |
418 | usbmuxd_log(LL_INFO, "Detaching kernel driver for device %d-%d, interface %d", bus, address, intf->bInterfaceNumber); | 418 | usbmuxd_log(LL_INFO, "Detaching kernel driver for device %d-%d, interface %d", bus, address, intf->bInterfaceNumber); |
419 | if((res = libusb_detach_kernel_driver(handle, intf->bInterfaceNumber)) < 0) { | 419 | if((res = libusb_detach_kernel_driver(handle, intf->bInterfaceNumber)) < 0) { |
420 | usbmuxd_log(LL_WARNING, "Could not detach kernel driver (%d), configuration change will probably fail!", res); | 420 | usbmuxd_log(LL_WARNING, "Could not detach kernel driver, configuration change will probably fail! %s", libusb_error_name(res)); |
421 | continue; | 421 | continue; |
422 | } | 422 | } |
423 | } | 423 | } |
@@ -427,7 +427,7 @@ static int usb_device_add(libusb_device* dev) | |||
427 | 427 | ||
428 | usbmuxd_log(LL_INFO, "Setting configuration for device %d-%d, from %d to %d", bus, address, current_config, desired_config); | 428 | usbmuxd_log(LL_INFO, "Setting configuration for device %d-%d, from %d to %d", bus, address, current_config, desired_config); |
429 | if((res = libusb_set_configuration(handle, desired_config)) != 0) { | 429 | if((res = libusb_set_configuration(handle, desired_config)) != 0) { |
430 | usbmuxd_log(LL_WARNING, "Could not set configuration %d for device %d-%d: %d", desired_config, bus, address, res); | 430 | usbmuxd_log(LL_WARNING, "Could not set configuration %d for device %d-%d: %s", desired_config, bus, address, libusb_error_name(res)); |
431 | libusb_close(handle); | 431 | libusb_close(handle); |
432 | return -1; | 432 | return -1; |
433 | } | 433 | } |
@@ -435,7 +435,7 @@ static int usb_device_add(libusb_device* dev) | |||
435 | 435 | ||
436 | struct libusb_config_descriptor *config; | 436 | struct libusb_config_descriptor *config; |
437 | if((res = libusb_get_active_config_descriptor(dev, &config)) != 0) { | 437 | if((res = libusb_get_active_config_descriptor(dev, &config)) != 0) { |
438 | usbmuxd_log(LL_WARNING, "Could not get configuration descriptor for device %d-%d: %d", bus, address, res); | 438 | usbmuxd_log(LL_WARNING, "Could not get configuration descriptor for device %d-%d: %s", bus, address, libusb_error_name(res)); |
439 | libusb_close(handle); | 439 | libusb_close(handle); |
440 | return -1; | 440 | return -1; |
441 | } | 441 | } |
@@ -484,7 +484,7 @@ static int usb_device_add(libusb_device* dev) | |||
484 | libusb_free_config_descriptor(config); | 484 | libusb_free_config_descriptor(config); |
485 | 485 | ||
486 | if((res = libusb_claim_interface(handle, usbdev->interface)) != 0) { | 486 | if((res = libusb_claim_interface(handle, usbdev->interface)) != 0) { |
487 | usbmuxd_log(LL_WARNING, "Could not claim interface %d for device %d-%d: %d", usbdev->interface, bus, address, res); | 487 | usbmuxd_log(LL_WARNING, "Could not claim interface %d for device %d-%d: %s", usbdev->interface, bus, address, libusb_error_name(res)); |
488 | libusb_close(handle); | 488 | libusb_close(handle); |
489 | free(usbdev); | 489 | free(usbdev); |
490 | return -1; | 490 | return -1; |
@@ -492,7 +492,7 @@ static int usb_device_add(libusb_device* dev) | |||
492 | 492 | ||
493 | transfer = libusb_alloc_transfer(0); | 493 | transfer = libusb_alloc_transfer(0); |
494 | if(!transfer) { | 494 | if(!transfer) { |
495 | usbmuxd_log(LL_WARNING, "Failed to allocate transfer for device %d-%d: %d", bus, address, res); | 495 | usbmuxd_log(LL_WARNING, "Failed to allocate transfer for device %d-%d: %s", bus, address, libusb_error_name(res)); |
496 | libusb_close(handle); | 496 | libusb_close(handle); |
497 | free(usbdev); | 497 | free(usbdev); |
498 | return -1; | 498 | return -1; |
@@ -500,7 +500,7 @@ static int usb_device_add(libusb_device* dev) | |||
500 | 500 | ||
501 | unsigned char *transfer_buffer = malloc(1024 + LIBUSB_CONTROL_SETUP_SIZE + 8); | 501 | unsigned char *transfer_buffer = malloc(1024 + LIBUSB_CONTROL_SETUP_SIZE + 8); |
502 | if (!transfer_buffer) { | 502 | if (!transfer_buffer) { |
503 | usbmuxd_log(LL_WARNING, "Failed to allocate transfer buffer for device %d-%d: %d", bus, address, res); | 503 | usbmuxd_log(LL_WARNING, "Failed to allocate transfer buffer for device %d-%d: %s", bus, address, libusb_error_name(res)); |
504 | libusb_close(handle); | 504 | libusb_close(handle); |
505 | free(usbdev); | 505 | free(usbdev); |
506 | return -1; | 506 | return -1; |
@@ -551,7 +551,7 @@ static int usb_device_add(libusb_device* dev) | |||
551 | libusb_fill_control_transfer(transfer, handle, transfer_buffer, get_langid_callback, usbdev, 1000); | 551 | libusb_fill_control_transfer(transfer, handle, transfer_buffer, get_langid_callback, usbdev, 1000); |
552 | 552 | ||
553 | if((res = libusb_submit_transfer(transfer)) < 0) { | 553 | if((res = libusb_submit_transfer(transfer)) < 0) { |
554 | usbmuxd_log(LL_ERROR, "Could not request transfer for device %d-%d (%d)", usbdev->bus, usbdev->address, res); | 554 | usbmuxd_log(LL_ERROR, "Could not request transfer for device %d-%d: %s", usbdev->bus, usbdev->address, libusb_error_name(res)); |
555 | libusb_free_transfer(transfer); | 555 | libusb_free_transfer(transfer); |
556 | libusb_close(handle); | 556 | libusb_close(handle); |
557 | free(transfer_buffer); | 557 | free(transfer_buffer); |
@@ -703,7 +703,7 @@ int usb_get_timeout(void) | |||
703 | if(res == 0) | 703 | if(res == 0) |
704 | return pollrem; | 704 | return pollrem; |
705 | if(res < 0) { | 705 | if(res < 0) { |
706 | usbmuxd_log(LL_ERROR, "libusb_get_next_timeout failed: %d", res); | 706 | usbmuxd_log(LL_ERROR, "libusb_get_next_timeout failed: %s", libusb_error_name(res)); |
707 | return pollrem; | 707 | return pollrem; |
708 | } | 708 | } |
709 | msec = tv.tv_sec * 1000; | 709 | msec = tv.tv_sec * 1000; |
@@ -720,7 +720,7 @@ int usb_process(void) | |||
720 | tv.tv_sec = tv.tv_usec = 0; | 720 | tv.tv_sec = tv.tv_usec = 0; |
721 | res = libusb_handle_events_timeout(NULL, &tv); | 721 | res = libusb_handle_events_timeout(NULL, &tv); |
722 | if(res < 0) { | 722 | if(res < 0) { |
723 | usbmuxd_log(LL_ERROR, "libusb_handle_events_timeout failed: %d", res); | 723 | usbmuxd_log(LL_ERROR, "libusb_handle_events_timeout failed: %s", libusb_error_name(res)); |
724 | return res; | 724 | return res; |
725 | } | 725 | } |
726 | 726 | ||
@@ -730,7 +730,7 @@ int usb_process(void) | |||
730 | if(dev_poll_remain_ms() <= 0) { | 730 | if(dev_poll_remain_ms() <= 0) { |
731 | res = usb_discover(); | 731 | res = usb_discover(); |
732 | if(res < 0) { | 732 | if(res < 0) { |
733 | usbmuxd_log(LL_ERROR, "usb_discover failed: %d", res); | 733 | usbmuxd_log(LL_ERROR, "usb_discover failed: %s", libusb_error_name(res)); |
734 | return res; | 734 | return res; |
735 | } | 735 | } |
736 | } | 736 | } |
@@ -755,7 +755,7 @@ int usb_process_timeout(int msec) | |||
755 | } | 755 | } |
756 | res = libusb_handle_events_timeout(NULL, &tleft); | 756 | res = libusb_handle_events_timeout(NULL, &tleft); |
757 | if(res < 0) { | 757 | if(res < 0) { |
758 | usbmuxd_log(LL_ERROR, "libusb_handle_events_timeout failed: %d", res); | 758 | usbmuxd_log(LL_ERROR, "libusb_handle_events_timeout failed: %s", libusb_error_name(res)); |
759 | return res; | 759 | return res; |
760 | } | 760 | } |
761 | // reap devices marked dead due to an RX error | 761 | // reap devices marked dead due to an RX error |
@@ -804,7 +804,7 @@ int usb_init(void) | |||
804 | libusb_set_debug(NULL, (log_level >= LL_DEBUG ? LIBUSB_LOG_LEVEL_DEBUG: (log_level >= LL_WARNING ? LIBUSB_LOG_LEVEL_WARNING: LIBUSB_LOG_LEVEL_NONE))); | 804 | libusb_set_debug(NULL, (log_level >= LL_DEBUG ? LIBUSB_LOG_LEVEL_DEBUG: (log_level >= LL_WARNING ? LIBUSB_LOG_LEVEL_WARNING: LIBUSB_LOG_LEVEL_NONE))); |
805 | 805 | ||
806 | if(res != 0) { | 806 | if(res != 0) { |
807 | usbmuxd_log(LL_FATAL, "libusb_init failed: %d", res); | 807 | usbmuxd_log(LL_FATAL, "libusb_init failed: %s", libusb_error_name(res)); |
808 | return -1; | 808 | return -1; |
809 | } | 809 | } |
810 | 810 | ||
@@ -817,7 +817,7 @@ int usb_init(void) | |||
817 | if (res == LIBUSB_SUCCESS) { | 817 | if (res == LIBUSB_SUCCESS) { |
818 | device_polling = 0; | 818 | device_polling = 0; |
819 | } else { | 819 | } else { |
820 | usbmuxd_log(LL_ERROR, "ERROR: Could not register for libusb hotplug events (%d)", res); | 820 | usbmuxd_log(LL_ERROR, "ERROR: Could not register for libusb hotplug events. %s", libusb_error_name(res)); |
821 | } | 821 | } |
822 | } else { | 822 | } else { |
823 | usbmuxd_log(LL_ERROR, "libusb does not support hotplug events"); | 823 | usbmuxd_log(LL_ERROR, "libusb does not support hotplug events"); |