summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libirecovery.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c
index f932684..c4659e0 100644
--- a/src/libirecovery.c
+++ b/src/libirecovery.c
@@ -325,6 +325,11 @@ static libusb_context* irecv_hotplug_ctx = NULL;
325 325
326static void _irecv_init(void) 326static void _irecv_init(void)
327{ 327{
328 char* dbglvl = getenv("LIBIRECOVERY_DEBUG_LEVEL");
329 if (dbglvl) {
330 libirecovery_debug = strtol(dbglvl, NULL, 0);
331 irecv_set_debug_level(libirecovery_debug);
332 }
328#ifndef USE_DUMMY 333#ifndef USE_DUMMY
329#ifndef WIN32 334#ifndef WIN32
330#ifndef HAVE_IOKIT 335#ifndef HAVE_IOKIT
@@ -1814,7 +1819,7 @@ static void* _irecv_handle_device_add(void *userdata)
1814 1819
1815 unsigned int pid = 0; 1820 unsigned int pid = 0;
1816 if (!p || (sscanf(p, "\\usb#vid_%*04x&pid_%04x#%s", &pid, serial_str) != 2) || (serial_str[0] == '\0')) { 1821 if (!p || (sscanf(p, "\\usb#vid_%*04x&pid_%04x#%s", &pid, serial_str) != 2) || (serial_str[0] == '\0')) {
1817 fprintf(stderr, "%s: ERROR: failed to parse DevicePath?!\n", __func__); 1822 debug("%s: ERROR: failed to parse DevicePath?!\n", __func__);
1818 return NULL; 1823 return NULL;
1819 } 1824 }
1820 if (!_irecv_is_recovery_device(p)) { 1825 if (!_irecv_is_recovery_device(p)) {
@@ -1843,17 +1848,17 @@ static void* _irecv_handle_device_add(void *userdata)
1843 IOUSBDeviceInterface **dev = iokit_ctx->dev; 1848 IOUSBDeviceInterface **dev = iokit_ctx->dev;
1844 1849
1845 if (!device) { 1850 if (!device) {
1846 fprintf(stderr, "%s: ERROR: no device?!\n", __func__); 1851 debug("%s: ERROR: no device?!\n", __func__);
1847 return NULL; 1852 return NULL;
1848 } 1853 }
1849 if (!dev) { 1854 if (!dev) {
1850 fprintf(stderr, "%s: ERROR: no device interface?!\n", __func__); 1855 debug("%s: ERROR: no device interface?!\n", __func__);
1851 return NULL; 1856 return NULL;
1852 } 1857 }
1853 1858
1854 (*dev)->GetDeviceProduct(dev, &product_id); 1859 (*dev)->GetDeviceProduct(dev, &product_id);
1855 if (!product_id) { 1860 if (!product_id) {
1856 fprintf(stderr, "%s: ERROR: could not get product id?!\n", __func__); 1861 debug("%s: ERROR: could not get product id?!\n", __func__);
1857 return NULL; 1862 return NULL;
1858 } 1863 }
1859 CFNumberRef locationNum = (CFNumberRef)IORegistryEntryCreateCFProperty(device, CFSTR(kUSBDevicePropertyLocationID), kCFAllocatorDefault, 0); 1864 CFNumberRef locationNum = (CFNumberRef)IORegistryEntryCreateCFProperty(device, CFSTR(kUSBDevicePropertyLocationID), kCFAllocatorDefault, 0);
@@ -1862,7 +1867,7 @@ static void* _irecv_handle_device_add(void *userdata)
1862 CFRelease(locationNum); 1867 CFRelease(locationNum);
1863 } 1868 }
1864 if (!location) { 1869 if (!location) {
1865 fprintf(stderr, "%s: ERROR: could not get locationID?!\n", __func__); 1870 debug("%s: ERROR: could not get locationID?!\n", __func__);
1866 return NULL; 1871 return NULL;
1867 } 1872 }
1868 CFStringRef serialString = (CFStringRef)IORegistryEntryCreateCFProperty(device, CFSTR(kUSBSerialNumberString), kCFAllocatorDefault, 0); 1873 CFStringRef serialString = (CFStringRef)IORegistryEntryCreateCFProperty(device, CFSTR(kUSBSerialNumberString), kCFAllocatorDefault, 0);
@@ -1878,7 +1883,7 @@ static void* _irecv_handle_device_add(void *userdata)
1878 1883
1879 libusb_error = libusb_get_device_descriptor(device, &devdesc); 1884 libusb_error = libusb_get_device_descriptor(device, &devdesc);
1880 if (libusb_error != 0) { 1885 if (libusb_error != 0) {
1881 fprintf(stderr, "%s: ERROR: failed to get device descriptor: %s\n", __func__, libusb_error_name(libusb_error)); 1886 debug("%s: ERROR: failed to get device descriptor: %s\n", __func__, libusb_error_name(libusb_error));
1882 return NULL; 1887 return NULL;
1883 } 1888 }
1884 product_id = devdesc.idProduct; 1889 product_id = devdesc.idProduct;
@@ -1889,14 +1894,14 @@ static void* _irecv_handle_device_add(void *userdata)
1889 1894
1890 libusb_error = libusb_open(device, &usb_handle); 1895 libusb_error = libusb_open(device, &usb_handle);
1891 if (usb_handle == NULL || libusb_error != 0) { 1896 if (usb_handle == NULL || libusb_error != 0) {
1892 fprintf(stderr, "%s: ERROR: can't connect to device: %s\n", __func__, libusb_error_name(libusb_error)); 1897 debug("%s: ERROR: can't connect to device: %s\n", __func__, libusb_error_name(libusb_error));
1893 libusb_close(usb_handle); 1898 libusb_close(usb_handle);
1894 return 0; 1899 return 0;
1895 } 1900 }
1896 1901
1897 libusb_error = libusb_get_string_descriptor_ascii(usb_handle, devdesc.iSerialNumber, (unsigned char*)serial_str, 255); 1902 libusb_error = libusb_get_string_descriptor_ascii(usb_handle, devdesc.iSerialNumber, (unsigned char*)serial_str, 255);
1898 if (libusb_error < 0) { 1903 if (libusb_error < 0) {
1899 fprintf(stderr, "%s: Failed to get string descriptor: %s\n", __func__, libusb_error_name(libusb_error)); 1904 debug("%s: Failed to get string descriptor: %s\n", __func__, libusb_error_name(libusb_error));
1900 return 0; 1905 return 0;
1901 } 1906 }
1902 libusb_close(usb_handle); 1907 libusb_close(usb_handle);
@@ -1965,7 +1970,7 @@ static void iokit_device_added(void *refcon, io_iterator_t iterator)
1965 while ((device = IOIteratorNext(iterator))) { 1970 while ((device = IOIteratorNext(iterator))) {
1966 kr = IOCreatePlugInInterfaceForService(device, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score); 1971 kr = IOCreatePlugInInterfaceForService(device, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, &plugInInterface, &score);
1967 if ((kIOReturnSuccess != kr) || !plugInInterface) { 1972 if ((kIOReturnSuccess != kr) || !plugInInterface) {
1968 fprintf(stderr, "%s: ERROR: Unable to create a plug-in (%08x)\n", __func__, kr); 1973 debug("%s: ERROR: Unable to create a plug-in (%08x)\n", __func__, kr);
1969 kr = IOObjectRelease(device); 1974 kr = IOObjectRelease(device);
1970 continue; 1975 continue;
1971 } 1976 }
@@ -1973,7 +1978,7 @@ static void iokit_device_added(void *refcon, io_iterator_t iterator)
1973 (*plugInInterface)->Release(plugInInterface); 1978 (*plugInInterface)->Release(plugInInterface);
1974 1979
1975 if (result || !dev) { 1980 if (result || !dev) {
1976 fprintf(stderr, "%s: ERROR: Couldn't create a device interface (%08x)\n", __func__, (int)result); 1981 debug("%s: ERROR: Couldn't create a device interface (%08x)\n", __func__, (int)result);
1977 kr = IOObjectRelease(device); 1982 kr = IOObjectRelease(device);
1978 continue; 1983 continue;
1979 } 1984 }
@@ -2028,7 +2033,7 @@ static int _irecv_usb_hotplug_cb(libusb_context *ctx, libusb_device *device, lib
2028 if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) { 2033 if (event == LIBUSB_HOTPLUG_EVENT_DEVICE_ARRIVED) {
2029 THREAD_T th_device; 2034 THREAD_T th_device;
2030 if (thread_new(&th_device, _irecv_handle_device_add, device) != 0) { 2035 if (thread_new(&th_device, _irecv_handle_device_add, device) != 0) {
2031 fprintf(stderr, "%s: FATAL: failed to create thread to handle device add\n", __func__); 2036 debug("%s: FATAL: failed to create thread to handle device add\n", __func__);
2032 return 0; 2037 return 0;
2033 } 2038 }
2034 thread_detach(th_device); 2039 thread_detach(th_device);
@@ -2063,7 +2068,7 @@ static void *_irecv_event_handler(void* unused)
2063 for (k = 0; guids[k]; k++) { 2068 for (k = 0; guids[k]; k++) {
2064 usbDevices = SetupDiGetClassDevs(guids[k], NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); 2069 usbDevices = SetupDiGetClassDevs(guids[k], NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
2065 if (!usbDevices) { 2070 if (!usbDevices) {
2066 fprintf(stderr, "%s: ERROR: SetupDiGetClassDevs failed\n", __func__); 2071 debug("%s: ERROR: SetupDiGetClassDevs failed\n", __func__);
2067 return NULL; 2072 return NULL;
2068 } 2073 }
2069 2074
@@ -2090,13 +2095,13 @@ static void *_irecv_event_handler(void* unused)
2090 char driver[256]; 2095 char driver[256];
2091 driver[0] = '\0'; 2096 driver[0] = '\0';
2092 if (!SetupDiGetDeviceRegistryProperty(usbDevices, &devinfodata, SPDRP_DRIVER, &sz, (PBYTE)driver, sizeof(driver), NULL)) { 2097 if (!SetupDiGetDeviceRegistryProperty(usbDevices, &devinfodata, SPDRP_DRIVER, &sz, (PBYTE)driver, sizeof(driver), NULL)) {
2093 fprintf(stderr, "%s: ERROR: Failed to get driver key\n", __func__); 2098 debug("%s: ERROR: Failed to get driver key\n", __func__);
2094 free(details); 2099 free(details);
2095 continue; 2100 continue;
2096 } 2101 }
2097 char *p = strrchr(driver, '\\'); 2102 char *p = strrchr(driver, '\\');
2098 if (!p) { 2103 if (!p) {
2099 fprintf(stderr, "%s: ERROR: Failed to parse device location\n", __func__); 2104 debug("%s: ERROR: Failed to parse device location\n", __func__);
2100 free(details); 2105 free(details);
2101 continue; 2106 continue;
2102 } 2107 }
@@ -2195,7 +2200,7 @@ static void *_irecv_event_handler(void* unused)
2195 do { 2200 do {
2196 cnt = libusb_get_device_list(irecv_hotplug_ctx, &devs); 2201 cnt = libusb_get_device_list(irecv_hotplug_ctx, &devs);
2197 if (cnt < 0) { 2202 if (cnt < 0) {
2198 fprintf(stderr, "%s: FATAL: Failed to get device list: %s\n", __func__, libusb_error_name(cnt)); 2203 debug("%s: FATAL: Failed to get device list: %s\n", __func__, libusb_error_name(cnt));
2199 return NULL; 2204 return NULL;
2200 } 2205 }
2201 2206