diff options
author | 2023-05-13 03:37:38 +0200 | |
---|---|---|
committer | 2023-05-13 03:37:38 +0200 | |
commit | 0360cdc603abbfbce76c4c10d20cf80d98c0b1d6 (patch) | |
tree | 6771cee2c78aeb43f0bb900384e299b745b8284c /src/libirecovery.c | |
parent | 3b4ef6a3d109702694435087311258355df1b63a (diff) | |
download | libirecovery-0360cdc603abbfbce76c4c10d20cf80d98c0b1d6.tar.gz libirecovery-0360cdc603abbfbce76c4c10d20cf80d98c0b1d6.tar.bz2 |
Coding style changes
Diffstat (limited to 'src/libirecovery.c')
-rw-r--r-- | src/libirecovery.c | 229 |
1 files changed, 136 insertions, 93 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index a91a742..6e7647b 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c | |||
@@ -2,7 +2,7 @@ | |||
2 | * libirecovery.c | 2 | * libirecovery.c |
3 | * Communication to iBoot/iBSS on Apple iOS devices via USB | 3 | * Communication to iBoot/iBSS on Apple iOS devices via USB |
4 | * | 4 | * |
5 | * Copyright (c) 2011-2020 Nikias Bassen <nikias@gmx.li> | 5 | * Copyright (c) 2011-2023 Nikias Bassen <nikias@gmx.li> |
6 | * Copyright (c) 2012-2020 Martin Szulecki <martin.szulecki@libimobiledevice.org> | 6 | * Copyright (c) 2012-2020 Martin Szulecki <martin.szulecki@libimobiledevice.org> |
7 | * Copyright (c) 2010 Chronic-Dev Team | 7 | * Copyright (c) 2010 Chronic-Dev Team |
8 | * Copyright (c) 2010 Joshua Hill | 8 | * Copyright (c) 2010 Joshua Hill |
@@ -94,7 +94,7 @@ struct irecv_client_private { | |||
94 | #define APPLE_VENDOR_ID 0x05AC | 94 | #define APPLE_VENDOR_ID 0x05AC |
95 | 95 | ||
96 | #define BUFFER_SIZE 0x1000 | 96 | #define BUFFER_SIZE 0x1000 |
97 | #define debug(...) if(libirecovery_debug) fprintf(stderr, __VA_ARGS__) | 97 | #define debug(...) if (libirecovery_debug) fprintf(stderr, __VA_ARGS__) |
98 | 98 | ||
99 | static int libirecovery_debug = 0; | 99 | static int libirecovery_debug = 0; |
100 | #ifndef USE_DUMMY | 100 | #ifndef USE_DUMMY |
@@ -506,8 +506,8 @@ BOOL WINAPI DllMain(HINSTANCE hModule, DWORD dwReason, LPVOID lpReserved) | |||
506 | #endif | 506 | #endif |
507 | 507 | ||
508 | #ifdef HAVE_IOKIT | 508 | #ifdef HAVE_IOKIT |
509 | static int iokit_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) { | 509 | static int iokit_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) |
510 | 510 | { | |
511 | IOReturn result; | 511 | IOReturn result; |
512 | IOUSBDevRequest request; | 512 | IOUSBDevRequest request; |
513 | unsigned char descriptor[256]; | 513 | unsigned char descriptor[256]; |
@@ -554,7 +554,8 @@ static int iokit_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc | |||
554 | } | 554 | } |
555 | #endif | 555 | #endif |
556 | 556 | ||
557 | static int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) { | 557 | static int irecv_get_string_descriptor_ascii(irecv_client_t client, uint8_t desc_index, unsigned char * buffer, int size) |
558 | { | ||
558 | #ifndef WIN32 | 559 | #ifndef WIN32 |
559 | #ifdef HAVE_IOKIT | 560 | #ifdef HAVE_IOKIT |
560 | return iokit_get_string_descriptor_ascii(client, desc_index, buffer, size); | 561 | return iokit_get_string_descriptor_ascii(client, desc_index, buffer, size); |
@@ -640,10 +641,10 @@ static void irecv_load_device_info_from_iboot_string(irecv_client_t client, cons | |||
640 | char tmp[256]; | 641 | char tmp[256]; |
641 | tmp[0] = '\0'; | 642 | tmp[0] = '\0'; |
642 | ptr = strstr(iboot_string, "SRNM:["); | 643 | ptr = strstr(iboot_string, "SRNM:["); |
643 | if(ptr != NULL) { | 644 | if (ptr != NULL) { |
644 | sscanf(ptr, "SRNM:[%s]", tmp); | 645 | sscanf(ptr, "SRNM:[%s]", tmp); |
645 | ptr = strrchr(tmp, ']'); | 646 | ptr = strrchr(tmp, ']'); |
646 | if(ptr != NULL) { | 647 | if (ptr != NULL) { |
647 | *ptr = '\0'; | 648 | *ptr = '\0'; |
648 | } | 649 | } |
649 | client->device_info.srnm = strdup(tmp); | 650 | client->device_info.srnm = strdup(tmp); |
@@ -651,10 +652,10 @@ static void irecv_load_device_info_from_iboot_string(irecv_client_t client, cons | |||
651 | 652 | ||
652 | tmp[0] = '\0'; | 653 | tmp[0] = '\0'; |
653 | ptr = strstr(iboot_string, "IMEI:["); | 654 | ptr = strstr(iboot_string, "IMEI:["); |
654 | if(ptr != NULL) { | 655 | if (ptr != NULL) { |
655 | sscanf(ptr, "IMEI:[%s]", tmp); | 656 | sscanf(ptr, "IMEI:[%s]", tmp); |
656 | ptr = strrchr(tmp, ']'); | 657 | ptr = strrchr(tmp, ']'); |
657 | if(ptr != NULL) { | 658 | if (ptr != NULL) { |
658 | *ptr = '\0'; | 659 | *ptr = '\0'; |
659 | } | 660 | } |
660 | client->device_info.imei = strdup(tmp); | 661 | client->device_info.imei = strdup(tmp); |
@@ -662,10 +663,10 @@ static void irecv_load_device_info_from_iboot_string(irecv_client_t client, cons | |||
662 | 663 | ||
663 | tmp[0] = '\0'; | 664 | tmp[0] = '\0'; |
664 | ptr = strstr(iboot_string, "SRTG:["); | 665 | ptr = strstr(iboot_string, "SRTG:["); |
665 | if(ptr != NULL) { | 666 | if (ptr != NULL) { |
666 | sscanf(ptr, "SRTG:[%s]", tmp); | 667 | sscanf(ptr, "SRTG:[%s]", tmp); |
667 | ptr = strrchr(tmp, ']'); | 668 | ptr = strrchr(tmp, ']'); |
668 | if(ptr != NULL) { | 669 | if (ptr != NULL) { |
669 | *ptr = '\0'; | 670 | *ptr = '\0'; |
670 | } | 671 | } |
671 | client->device_info.srtg = strdup(tmp); | 672 | client->device_info.srtg = strdup(tmp); |
@@ -774,7 +775,8 @@ irecv_error_t mobiledevice_openpipes(irecv_client_t client); | |||
774 | void mobiledevice_closepipes(irecv_client_t client); | 775 | void mobiledevice_closepipes(irecv_client_t client); |
775 | irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid); | 776 | irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid); |
776 | 777 | ||
777 | irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | 778 | irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) |
779 | { | ||
778 | int found = 0; | 780 | int found = 0; |
779 | SP_DEVICE_INTERFACE_DATA currentInterface; | 781 | SP_DEVICE_INTERFACE_DATA currentInterface; |
780 | HDEVINFO usbDevices; | 782 | HDEVINFO usbDevices; |
@@ -786,7 +788,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | |||
786 | usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DFU, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); | 788 | usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_DFU, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); |
787 | memset(¤tInterface, '\0', sizeof(SP_DEVICE_INTERFACE_DATA)); | 789 | memset(¤tInterface, '\0', sizeof(SP_DEVICE_INTERFACE_DATA)); |
788 | currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); | 790 | currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); |
789 | for(i = 0; usbDevices && SetupDiEnumDeviceInterfaces(usbDevices, NULL, &GUID_DEVINTERFACE_DFU, i, ¤tInterface); i++) { | 791 | for (i = 0; usbDevices && SetupDiEnumDeviceInterfaces(usbDevices, NULL, &GUID_DEVINTERFACE_DFU, i, ¤tInterface); i++) { |
790 | free(_client->DfuPath); | 792 | free(_client->DfuPath); |
791 | _client->DfuPath = NULL; | 793 | _client->DfuPath = NULL; |
792 | _client->handle = NULL; | 794 | _client->handle = NULL; |
@@ -795,7 +797,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | |||
795 | SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, NULL, 0, &requiredSize, NULL); | 797 | SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, NULL, 0, &requiredSize, NULL); |
796 | details = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A) malloc(requiredSize); | 798 | details = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A) malloc(requiredSize); |
797 | details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); | 799 | details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); |
798 | if(!SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, details, requiredSize, NULL, NULL)) { | 800 | if (!SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, details, requiredSize, NULL, NULL)) { |
799 | free(details); | 801 | free(details); |
800 | continue; | 802 | continue; |
801 | } else { | 803 | } else { |
@@ -879,7 +881,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | |||
879 | usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_IBOOT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); | 881 | usbDevices = SetupDiGetClassDevs(&GUID_DEVINTERFACE_IBOOT, NULL, NULL, DIGCF_PRESENT | DIGCF_DEVICEINTERFACE); |
880 | memset(¤tInterface, '\0', sizeof(SP_DEVICE_INTERFACE_DATA)); | 882 | memset(¤tInterface, '\0', sizeof(SP_DEVICE_INTERFACE_DATA)); |
881 | currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); | 883 | currentInterface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA); |
882 | for(i = 0; usbDevices && SetupDiEnumDeviceInterfaces(usbDevices, NULL, &GUID_DEVINTERFACE_IBOOT, i, ¤tInterface); i++) { | 884 | for (i = 0; usbDevices && SetupDiEnumDeviceInterfaces(usbDevices, NULL, &GUID_DEVINTERFACE_IBOOT, i, ¤tInterface); i++) { |
883 | free(_client->iBootPath); | 885 | free(_client->iBootPath); |
884 | _client->iBootPath = NULL; | 886 | _client->iBootPath = NULL; |
885 | _client->handle = NULL; | 887 | _client->handle = NULL; |
@@ -888,7 +890,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | |||
888 | SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, NULL, 0, &requiredSize, NULL); | 890 | SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, NULL, 0, &requiredSize, NULL); |
889 | details = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A) malloc(requiredSize); | 891 | details = (PSP_DEVICE_INTERFACE_DETAIL_DATA_A) malloc(requiredSize); |
890 | details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); | 892 | details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); |
891 | if(!SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, details, requiredSize, NULL, NULL)) { | 893 | if (!SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, details, requiredSize, NULL, NULL)) { |
892 | free(details); | 894 | free(details); |
893 | continue; | 895 | continue; |
894 | } else { | 896 | } else { |
@@ -964,7 +966,8 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) { | |||
964 | return IRECV_E_SUCCESS; | 966 | return IRECV_E_SUCCESS; |
965 | } | 967 | } |
966 | 968 | ||
967 | irecv_error_t mobiledevice_openpipes(irecv_client_t client) { | 969 | irecv_error_t mobiledevice_openpipes(irecv_client_t client) |
970 | { | ||
968 | if (client->iBootPath && !(client->hIB = CreateFileA(client->iBootPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))) { | 971 | if (client->iBootPath && !(client->hIB = CreateFileA(client->iBootPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))) { |
969 | irecv_close(client); | 972 | irecv_close(client); |
970 | return IRECV_E_UNABLE_TO_CONNECT; | 973 | return IRECV_E_UNABLE_TO_CONNECT; |
@@ -996,7 +999,8 @@ irecv_error_t mobiledevice_openpipes(irecv_client_t client) { | |||
996 | return IRECV_E_SUCCESS; | 999 | return IRECV_E_SUCCESS; |
997 | } | 1000 | } |
998 | 1001 | ||
999 | void mobiledevice_closepipes(irecv_client_t client) { | 1002 | void mobiledevice_closepipes(irecv_client_t client) |
1003 | { | ||
1000 | if (client->hDFU!=NULL) { | 1004 | if (client->hDFU!=NULL) { |
1001 | CloseHandle(client->hDFU); | 1005 | CloseHandle(client->hDFU); |
1002 | client->hDFU = NULL; | 1006 | client->hDFU = NULL; |
@@ -1021,7 +1025,8 @@ static void iokit_cfdictionary_set_short(CFMutableDictionaryRef dict, const void | |||
1021 | } | 1025 | } |
1022 | #endif | 1026 | #endif |
1023 | 1027 | ||
1024 | static int check_context(irecv_client_t client) { | 1028 | static int check_context(irecv_client_t client) |
1029 | { | ||
1025 | if (client == NULL || client->handle == NULL) { | 1030 | if (client == NULL || client->handle == NULL) { |
1026 | return IRECV_E_NO_DEVICE; | 1031 | return IRECV_E_NO_DEVICE; |
1027 | } | 1032 | } |
@@ -1079,7 +1084,8 @@ static int iokit_usb_control_transfer(irecv_client_t client, uint8_t bm_request_ | |||
1079 | #endif | 1084 | #endif |
1080 | #endif | 1085 | #endif |
1081 | 1086 | ||
1082 | int irecv_usb_control_transfer(irecv_client_t client, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, unsigned char *data, uint16_t w_length, unsigned int timeout) { | 1087 | int irecv_usb_control_transfer(irecv_client_t client, uint8_t bm_request_type, uint8_t b_request, uint16_t w_value, uint16_t w_index, unsigned char *data, uint16_t w_length, unsigned int timeout) |
1088 | { | ||
1083 | #ifdef USE_DUMMY | 1089 | #ifdef USE_DUMMY |
1084 | return IRECV_E_UNSUPPORTED; | 1090 | return IRECV_E_UNSUPPORTED; |
1085 | #else | 1091 | #else |
@@ -1140,8 +1146,8 @@ static int iokit_usb_bulk_transfer(irecv_client_t client, | |||
1140 | unsigned char *data, | 1146 | unsigned char *data, |
1141 | int length, | 1147 | int length, |
1142 | int *transferred, | 1148 | int *transferred, |
1143 | unsigned int timeout) { | 1149 | unsigned int timeout) |
1144 | 1150 | { | |
1145 | IOReturn result; | 1151 | IOReturn result; |
1146 | IOUSBInterfaceInterface300 **intf = client->usbInterface; | 1152 | IOUSBInterfaceInterface300 **intf = client->usbInterface; |
1147 | UInt32 size = length; | 1153 | UInt32 size = length; |
@@ -1194,7 +1200,8 @@ int irecv_usb_bulk_transfer(irecv_client_t client, | |||
1194 | unsigned char *data, | 1200 | unsigned char *data, |
1195 | int length, | 1201 | int length, |
1196 | int *transferred, | 1202 | int *transferred, |
1197 | unsigned int timeout) { | 1203 | unsigned int timeout) |
1204 | { | ||
1198 | #ifdef USE_DUMMY | 1205 | #ifdef USE_DUMMY |
1199 | return IRECV_E_UNSUPPORTED; | 1206 | return IRECV_E_UNSUPPORTED; |
1200 | #else | 1207 | #else |
@@ -1224,8 +1231,8 @@ int irecv_usb_bulk_transfer(irecv_client_t client, | |||
1224 | 1231 | ||
1225 | #ifndef USE_DUMMY | 1232 | #ifndef USE_DUMMY |
1226 | #ifdef HAVE_IOKIT | 1233 | #ifdef HAVE_IOKIT |
1227 | static irecv_error_t iokit_usb_open_service(irecv_client_t *pclient, io_service_t service) { | 1234 | static irecv_error_t iokit_usb_open_service(irecv_client_t *pclient, io_service_t service) |
1228 | 1235 | { | |
1229 | IOReturn result; | 1236 | IOReturn result; |
1230 | irecv_error_t error; | 1237 | irecv_error_t error; |
1231 | irecv_client_t client; | 1238 | irecv_client_t client; |
@@ -1315,8 +1322,8 @@ static irecv_error_t iokit_usb_open_service(irecv_client_t *pclient, io_service_ | |||
1315 | return IRECV_E_SUCCESS; | 1322 | return IRECV_E_SUCCESS; |
1316 | } | 1323 | } |
1317 | 1324 | ||
1318 | static io_iterator_t iokit_usb_get_iterator_for_pid(UInt16 pid) { | 1325 | static io_iterator_t iokit_usb_get_iterator_for_pid(UInt16 pid) |
1319 | 1326 | { | |
1320 | IOReturn result; | 1327 | IOReturn result; |
1321 | io_iterator_t iterator; | 1328 | io_iterator_t iterator; |
1322 | CFMutableDictionaryRef matchingDict; | 1329 | CFMutableDictionaryRef matchingDict; |
@@ -1332,8 +1339,8 @@ static io_iterator_t iokit_usb_get_iterator_for_pid(UInt16 pid) { | |||
1332 | return iterator; | 1339 | return iterator; |
1333 | } | 1340 | } |
1334 | 1341 | ||
1335 | static irecv_error_t iokit_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) { | 1342 | static irecv_error_t iokit_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) |
1336 | 1343 | { | |
1337 | io_service_t service, ret_service; | 1344 | io_service_t service, ret_service; |
1338 | io_iterator_t iterator; | 1345 | io_iterator_t iterator; |
1339 | CFStringRef usbSerial = NULL; | 1346 | CFStringRef usbSerial = NULL; |
@@ -1410,13 +1417,14 @@ static irecv_error_t iokit_open_with_ecid(irecv_client_t* pclient, uint64_t ecid | |||
1410 | #endif | 1417 | #endif |
1411 | #endif | 1418 | #endif |
1412 | 1419 | ||
1413 | irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) { | 1420 | irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) |
1421 | { | ||
1414 | #ifdef USE_DUMMY | 1422 | #ifdef USE_DUMMY |
1415 | return IRECV_E_UNSUPPORTED; | 1423 | return IRECV_E_UNSUPPORTED; |
1416 | #else | 1424 | #else |
1417 | int ret = IRECV_E_UNABLE_TO_CONNECT; | 1425 | int ret = IRECV_E_UNABLE_TO_CONNECT; |
1418 | 1426 | ||
1419 | if(libirecovery_debug) { | 1427 | if (libirecovery_debug) { |
1420 | irecv_set_debug_level(libirecovery_debug); | 1428 | irecv_set_debug_level(libirecovery_debug); |
1421 | } | 1429 | } |
1422 | #ifndef WIN32 | 1430 | #ifndef WIN32 |
@@ -1563,7 +1571,8 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) { | |||
1563 | #endif | 1571 | #endif |
1564 | } | 1572 | } |
1565 | 1573 | ||
1566 | irecv_error_t irecv_usb_set_configuration(irecv_client_t client, int configuration) { | 1574 | irecv_error_t irecv_usb_set_configuration(irecv_client_t client, int configuration) |
1575 | { | ||
1567 | #ifdef USE_DUMMY | 1576 | #ifdef USE_DUMMY |
1568 | return IRECV_E_UNSUPPORTED; | 1577 | return IRECV_E_UNSUPPORTED; |
1569 | #else | 1578 | #else |
@@ -1599,8 +1608,8 @@ irecv_error_t irecv_usb_set_configuration(irecv_client_t client, int configurati | |||
1599 | 1608 | ||
1600 | #ifndef USE_DUMMY | 1609 | #ifndef USE_DUMMY |
1601 | #ifdef HAVE_IOKIT | 1610 | #ifdef HAVE_IOKIT |
1602 | static IOReturn iokit_usb_get_interface(IOUSBDeviceInterface320 **device, uint8_t ifc, io_service_t *usbInterfacep) { | 1611 | static IOReturn iokit_usb_get_interface(IOUSBDeviceInterface320 **device, uint8_t ifc, io_service_t *usbInterfacep) |
1603 | 1612 | { | |
1604 | IOUSBFindInterfaceRequest request; | 1613 | IOUSBFindInterfaceRequest request; |
1605 | uint8_t current_interface; | 1614 | uint8_t current_interface; |
1606 | kern_return_t kresult; | 1615 | kern_return_t kresult; |
@@ -1627,7 +1636,8 @@ static IOReturn iokit_usb_get_interface(IOUSBDeviceInterface320 **device, uint8_ | |||
1627 | return kIOReturnSuccess; | 1636 | return kIOReturnSuccess; |
1628 | } | 1637 | } |
1629 | 1638 | ||
1630 | static irecv_error_t iokit_usb_set_interface(irecv_client_t client, int usb_interface, int usb_alt_interface) { | 1639 | static irecv_error_t iokit_usb_set_interface(irecv_client_t client, int usb_interface, int usb_alt_interface) |
1640 | { | ||
1631 | IOReturn result; | 1641 | IOReturn result; |
1632 | io_service_t interface_service = IO_OBJECT_NULL; | 1642 | io_service_t interface_service = IO_OBJECT_NULL; |
1633 | IOCFPlugInInterface **plugInInterface = NULL; | 1643 | IOCFPlugInInterface **plugInInterface = NULL; |
@@ -1679,7 +1689,8 @@ static irecv_error_t iokit_usb_set_interface(irecv_client_t client, int usb_inte | |||
1679 | #endif | 1689 | #endif |
1680 | #endif | 1690 | #endif |
1681 | 1691 | ||
1682 | irecv_error_t irecv_usb_set_interface(irecv_client_t client, int usb_interface, int usb_alt_interface) { | 1692 | irecv_error_t irecv_usb_set_interface(irecv_client_t client, int usb_interface, int usb_alt_interface) |
1693 | { | ||
1683 | #ifdef USE_DUMMY | 1694 | #ifdef USE_DUMMY |
1684 | return IRECV_E_UNSUPPORTED; | 1695 | return IRECV_E_UNSUPPORTED; |
1685 | #else | 1696 | #else |
@@ -1715,7 +1726,8 @@ irecv_error_t irecv_usb_set_interface(irecv_client_t client, int usb_interface, | |||
1715 | #endif | 1726 | #endif |
1716 | } | 1727 | } |
1717 | 1728 | ||
1718 | irecv_error_t irecv_reset(irecv_client_t client) { | 1729 | irecv_error_t irecv_reset(irecv_client_t client) |
1730 | { | ||
1719 | #ifdef USE_DUMMY | 1731 | #ifdef USE_DUMMY |
1720 | return IRECV_E_UNSUPPORTED; | 1732 | return IRECV_E_UNSUPPORTED; |
1721 | #else | 1733 | #else |
@@ -1748,14 +1760,15 @@ irecv_error_t irecv_reset(irecv_client_t client) { | |||
1748 | #endif | 1760 | #endif |
1749 | } | 1761 | } |
1750 | 1762 | ||
1751 | irecv_error_t irecv_open_with_ecid_and_attempts(irecv_client_t* pclient, uint64_t ecid, int attempts) { | 1763 | irecv_error_t irecv_open_with_ecid_and_attempts(irecv_client_t* pclient, uint64_t ecid, int attempts) |
1764 | { | ||
1752 | #ifdef USE_DUMMY | 1765 | #ifdef USE_DUMMY |
1753 | return IRECV_E_UNSUPPORTED; | 1766 | return IRECV_E_UNSUPPORTED; |
1754 | #else | 1767 | #else |
1755 | int i; | 1768 | int i; |
1756 | 1769 | ||
1757 | for (i = 0; i < attempts; i++) { | 1770 | for (i = 0; i < attempts; i++) { |
1758 | if(*pclient) { | 1771 | if (*pclient) { |
1759 | irecv_close(*pclient); | 1772 | irecv_close(*pclient); |
1760 | *pclient = NULL; | 1773 | *pclient = NULL; |
1761 | } | 1774 | } |
@@ -1771,7 +1784,8 @@ irecv_error_t irecv_open_with_ecid_and_attempts(irecv_client_t* pclient, uint64_ | |||
1771 | #endif | 1784 | #endif |
1772 | } | 1785 | } |
1773 | 1786 | ||
1774 | irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type, irecv_event_cb_t callback, void* user_data) { | 1787 | irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type, irecv_event_cb_t callback, void* user_data) |
1788 | { | ||
1775 | #ifdef USE_DUMMY | 1789 | #ifdef USE_DUMMY |
1776 | return IRECV_E_UNSUPPORTED; | 1790 | return IRECV_E_UNSUPPORTED; |
1777 | #else | 1791 | #else |
@@ -1808,7 +1822,8 @@ irecv_error_t irecv_event_subscribe(irecv_client_t client, irecv_event_type type | |||
1808 | #endif | 1822 | #endif |
1809 | } | 1823 | } |
1810 | 1824 | ||
1811 | irecv_error_t irecv_event_unsubscribe(irecv_client_t client, irecv_event_type type) { | 1825 | irecv_error_t irecv_event_unsubscribe(irecv_client_t client, irecv_event_type type) |
1826 | { | ||
1812 | #ifdef USE_DUMMY | 1827 | #ifdef USE_DUMMY |
1813 | return IRECV_E_UNSUPPORTED; | 1828 | return IRECV_E_UNSUPPORTED; |
1814 | #else | 1829 | #else |
@@ -2230,7 +2245,7 @@ static void *_irecv_event_handler(void* data) | |||
2230 | details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); | 2245 | details->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_A); |
2231 | SP_DEVINFO_DATA devinfodata; | 2246 | SP_DEVINFO_DATA devinfodata; |
2232 | devinfodata.cbSize = sizeof(SP_DEVINFO_DATA); | 2247 | devinfodata.cbSize = sizeof(SP_DEVINFO_DATA); |
2233 | if(!SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, details, requiredSize, NULL, &devinfodata)) { | 2248 | if (!SetupDiGetDeviceInterfaceDetailA(usbDevices, ¤tInterface, details, requiredSize, NULL, &devinfodata)) { |
2234 | free(details); | 2249 | free(details); |
2235 | continue; | 2250 | continue; |
2236 | } | 2251 | } |
@@ -2528,12 +2543,13 @@ irecv_error_t irecv_device_event_unsubscribe(irecv_device_event_context_t contex | |||
2528 | #endif | 2543 | #endif |
2529 | } | 2544 | } |
2530 | 2545 | ||
2531 | irecv_error_t irecv_close(irecv_client_t client) { | 2546 | irecv_error_t irecv_close(irecv_client_t client) |
2547 | { | ||
2532 | #ifdef USE_DUMMY | 2548 | #ifdef USE_DUMMY |
2533 | return IRECV_E_UNSUPPORTED; | 2549 | return IRECV_E_UNSUPPORTED; |
2534 | #else | 2550 | #else |
2535 | if (client != NULL) { | 2551 | if (client != NULL) { |
2536 | if(client->disconnected_callback != NULL) { | 2552 | if (client->disconnected_callback != NULL) { |
2537 | irecv_event_t event; | 2553 | irecv_event_t event; |
2538 | event.size = 0; | 2554 | event.size = 0; |
2539 | event.data = NULL; | 2555 | event.data = NULL; |
@@ -2584,12 +2600,13 @@ irecv_error_t irecv_close(irecv_client_t client) { | |||
2584 | #endif | 2600 | #endif |
2585 | } | 2601 | } |
2586 | 2602 | ||
2587 | void irecv_set_debug_level(int level) { | 2603 | void irecv_set_debug_level(int level) |
2604 | { | ||
2588 | libirecovery_debug = level; | 2605 | libirecovery_debug = level; |
2589 | #ifndef USE_DUMMY | 2606 | #ifndef USE_DUMMY |
2590 | #ifndef WIN32 | 2607 | #ifndef WIN32 |
2591 | #ifndef HAVE_IOKIT | 2608 | #ifndef HAVE_IOKIT |
2592 | if(libirecovery_context) { | 2609 | if (libirecovery_context) { |
2593 | #if LIBUSB_API_VERSION >= 0x01000106 | 2610 | #if LIBUSB_API_VERSION >= 0x01000106 |
2594 | libusb_set_option(libirecovery_context, LIBUSB_OPTION_LOG_LEVEL, libirecovery_debug > 2 ? 1: 0); | 2611 | libusb_set_option(libirecovery_context, LIBUSB_OPTION_LOG_LEVEL, libirecovery_debug > 2 ? 1: 0); |
2595 | #else | 2612 | #else |
@@ -2602,7 +2619,8 @@ void irecv_set_debug_level(int level) { | |||
2602 | } | 2619 | } |
2603 | 2620 | ||
2604 | #ifndef USE_DUMMY | 2621 | #ifndef USE_DUMMY |
2605 | static irecv_error_t irecv_send_command_raw(irecv_client_t client, const char* command, uint8_t b_request) { | 2622 | static irecv_error_t irecv_send_command_raw(irecv_client_t client, const char* command, uint8_t b_request) |
2623 | { | ||
2606 | unsigned int length = strlen(command); | 2624 | unsigned int length = strlen(command); |
2607 | if (length >= 0x100) { | 2625 | if (length >= 0x100) { |
2608 | return IRECV_E_INVALID_INPUT; | 2626 | return IRECV_E_INVALID_INPUT; |
@@ -2616,7 +2634,8 @@ static irecv_error_t irecv_send_command_raw(irecv_client_t client, const char* c | |||
2616 | } | 2634 | } |
2617 | #endif | 2635 | #endif |
2618 | 2636 | ||
2619 | irecv_error_t irecv_send_command_breq(irecv_client_t client, const char* command, uint8_t b_request) { | 2637 | irecv_error_t irecv_send_command_breq(irecv_client_t client, const char* command, uint8_t b_request) |
2638 | { | ||
2620 | #ifdef USE_DUMMY | 2639 | #ifdef USE_DUMMY |
2621 | return IRECV_E_UNSUPPORTED; | 2640 | return IRECV_E_UNSUPPORTED; |
2622 | #else | 2641 | #else |
@@ -2631,11 +2650,11 @@ irecv_error_t irecv_send_command_breq(irecv_client_t client, const char* command | |||
2631 | } | 2650 | } |
2632 | 2651 | ||
2633 | irecv_event_t event; | 2652 | irecv_event_t event; |
2634 | if(client->precommand_callback != NULL) { | 2653 | if (client->precommand_callback != NULL) { |
2635 | event.size = length; | 2654 | event.size = length; |
2636 | event.data = command; | 2655 | event.data = command; |
2637 | event.type = IRECV_PRECOMMAND; | 2656 | event.type = IRECV_PRECOMMAND; |
2638 | if(client->precommand_callback(client, &event)) { | 2657 | if (client->precommand_callback(client, &event)) { |
2639 | return IRECV_E_SUCCESS; | 2658 | return IRECV_E_SUCCESS; |
2640 | } | 2659 | } |
2641 | } | 2660 | } |
@@ -2647,11 +2666,11 @@ irecv_error_t irecv_send_command_breq(irecv_client_t client, const char* command | |||
2647 | return error; | 2666 | return error; |
2648 | } | 2667 | } |
2649 | 2668 | ||
2650 | if(client->postcommand_callback != NULL) { | 2669 | if (client->postcommand_callback != NULL) { |
2651 | event.size = length; | 2670 | event.size = length; |
2652 | event.data = command; | 2671 | event.data = command; |
2653 | event.type = IRECV_POSTCOMMAND; | 2672 | event.type = IRECV_POSTCOMMAND; |
2654 | if(client->postcommand_callback(client, &event)) { | 2673 | if (client->postcommand_callback(client, &event)) { |
2655 | return IRECV_E_SUCCESS; | 2674 | return IRECV_E_SUCCESS; |
2656 | } | 2675 | } |
2657 | } | 2676 | } |
@@ -2660,11 +2679,13 @@ irecv_error_t irecv_send_command_breq(irecv_client_t client, const char* command | |||
2660 | #endif | 2679 | #endif |
2661 | } | 2680 | } |
2662 | 2681 | ||
2663 | irecv_error_t irecv_send_command(irecv_client_t client, const char* command) { | 2682 | irecv_error_t irecv_send_command(irecv_client_t client, const char* command) |
2683 | { | ||
2664 | return irecv_send_command_breq(client, command, 0); | 2684 | return irecv_send_command_breq(client, command, 0); |
2665 | } | 2685 | } |
2666 | 2686 | ||
2667 | irecv_error_t irecv_send_file(irecv_client_t client, const char* filename, int dfu_notify_finished) { | 2687 | irecv_error_t irecv_send_file(irecv_client_t client, const char* filename, int dfu_notify_finished) |
2688 | { | ||
2668 | #ifdef USE_DUMMY | 2689 | #ifdef USE_DUMMY |
2669 | return IRECV_E_UNSUPPORTED; | 2690 | return IRECV_E_UNSUPPORTED; |
2670 | #else | 2691 | #else |
@@ -2704,7 +2725,8 @@ irecv_error_t irecv_send_file(irecv_client_t client, const char* filename, int d | |||
2704 | } | 2725 | } |
2705 | 2726 | ||
2706 | #ifndef USE_DUMMY | 2727 | #ifndef USE_DUMMY |
2707 | static irecv_error_t irecv_get_status(irecv_client_t client, unsigned int* status) { | 2728 | static irecv_error_t irecv_get_status(irecv_client_t client, unsigned int* status) |
2729 | { | ||
2708 | if (check_context(client) != IRECV_E_SUCCESS) { | 2730 | if (check_context(client) != IRECV_E_SUCCESS) { |
2709 | *status = 0; | 2731 | *status = 0; |
2710 | return IRECV_E_NO_DEVICE; | 2732 | return IRECV_E_NO_DEVICE; |
@@ -2723,7 +2745,8 @@ static irecv_error_t irecv_get_status(irecv_client_t client, unsigned int* statu | |||
2723 | } | 2745 | } |
2724 | #endif | 2746 | #endif |
2725 | 2747 | ||
2726 | irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, unsigned long length, int dfu_notify_finished) { | 2748 | irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, unsigned long length, int dfu_notify_finished) |
2749 | { | ||
2727 | #ifdef USE_DUMMY | 2750 | #ifdef USE_DUMMY |
2728 | return IRECV_E_UNSUPPORTED; | 2751 | return IRECV_E_UNSUPPORTED; |
2729 | #else | 2752 | #else |
@@ -2856,7 +2879,7 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un | |||
2856 | } | 2879 | } |
2857 | 2880 | ||
2858 | count += size; | 2881 | count += size; |
2859 | if(client->progress_callback != NULL) { | 2882 | if (client->progress_callback != NULL) { |
2860 | irecv_event_t event; | 2883 | irecv_event_t event; |
2861 | event.progress = ((double) count/ (double) length) * 100.0; | 2884 | event.progress = ((double) count/ (double) length) * 100.0; |
2862 | event.type = IRECV_PROGRESS; | 2885 | event.type = IRECV_PROGRESS; |
@@ -2896,7 +2919,8 @@ irecv_error_t irecv_send_buffer(irecv_client_t client, unsigned char* buffer, un | |||
2896 | #endif | 2919 | #endif |
2897 | } | 2920 | } |
2898 | 2921 | ||
2899 | irecv_error_t irecv_receive(irecv_client_t client) { | 2922 | irecv_error_t irecv_receive(irecv_client_t client) |
2923 | { | ||
2900 | #ifdef USE_DUMMY | 2924 | #ifdef USE_DUMMY |
2901 | return IRECV_E_UNSUPPORTED; | 2925 | return IRECV_E_UNSUPPORTED; |
2902 | #else | 2926 | #else |
@@ -2930,7 +2954,8 @@ irecv_error_t irecv_receive(irecv_client_t client) { | |||
2930 | #endif | 2954 | #endif |
2931 | } | 2955 | } |
2932 | 2956 | ||
2933 | irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value) { | 2957 | irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** value) |
2958 | { | ||
2934 | #ifdef USE_DUMMY | 2959 | #ifdef USE_DUMMY |
2935 | return IRECV_E_UNSUPPORTED; | 2960 | return IRECV_E_UNSUPPORTED; |
2936 | #else | 2961 | #else |
@@ -2941,18 +2966,18 @@ irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** v | |||
2941 | 2966 | ||
2942 | *value = NULL; | 2967 | *value = NULL; |
2943 | 2968 | ||
2944 | if(variable == NULL) { | 2969 | if (variable == NULL) { |
2945 | return IRECV_E_INVALID_INPUT; | 2970 | return IRECV_E_INVALID_INPUT; |
2946 | } | 2971 | } |
2947 | 2972 | ||
2948 | memset(command, '\0', sizeof(command)); | 2973 | memset(command, '\0', sizeof(command)); |
2949 | snprintf(command, sizeof(command)-1, "getenv %s", variable); | 2974 | snprintf(command, sizeof(command)-1, "getenv %s", variable); |
2950 | irecv_error_t error = irecv_send_command_raw(client, command, 0); | 2975 | irecv_error_t error = irecv_send_command_raw(client, command, 0); |
2951 | if(error == IRECV_E_PIPE) { | 2976 | if (error == IRECV_E_PIPE) { |
2952 | return IRECV_E_SUCCESS; | 2977 | return IRECV_E_SUCCESS; |
2953 | } | 2978 | } |
2954 | 2979 | ||
2955 | if(error != IRECV_E_SUCCESS) { | 2980 | if (error != IRECV_E_SUCCESS) { |
2956 | return error; | 2981 | return error; |
2957 | } | 2982 | } |
2958 | 2983 | ||
@@ -2970,7 +2995,8 @@ irecv_error_t irecv_getenv(irecv_client_t client, const char* variable, char** v | |||
2970 | #endif | 2995 | #endif |
2971 | } | 2996 | } |
2972 | 2997 | ||
2973 | irecv_error_t irecv_getret(irecv_client_t client, unsigned int* value) { | 2998 | irecv_error_t irecv_getret(irecv_client_t client, unsigned int* value) |
2999 | { | ||
2974 | #ifdef USE_DUMMY | 3000 | #ifdef USE_DUMMY |
2975 | return IRECV_E_UNSUPPORTED; | 3001 | return IRECV_E_UNSUPPORTED; |
2976 | #else | 3002 | #else |
@@ -2993,7 +3019,8 @@ irecv_error_t irecv_getret(irecv_client_t client, unsigned int* value) { | |||
2993 | #endif | 3019 | #endif |
2994 | } | 3020 | } |
2995 | 3021 | ||
2996 | irecv_error_t irecv_get_mode(irecv_client_t client, int* mode) { | 3022 | irecv_error_t irecv_get_mode(irecv_client_t client, int* mode) |
3023 | { | ||
2997 | #ifdef USE_DUMMY | 3024 | #ifdef USE_DUMMY |
2998 | return IRECV_E_UNSUPPORTED; | 3025 | return IRECV_E_UNSUPPORTED; |
2999 | #else | 3026 | #else |
@@ -3020,7 +3047,8 @@ const struct irecv_device_info* irecv_get_device_info(irecv_client_t client) | |||
3020 | 3047 | ||
3021 | #ifndef USE_DUMMY | 3048 | #ifndef USE_DUMMY |
3022 | #ifdef HAVE_IOKIT | 3049 | #ifdef HAVE_IOKIT |
3023 | static void *iokit_limera1n_usb_submit_request(void *argv) { | 3050 | static void *iokit_limera1n_usb_submit_request(void *argv) |
3051 | { | ||
3024 | void **args = argv; | 3052 | void **args = argv; |
3025 | IOUSBDeviceInterface320 **dev = args[0]; | 3053 | IOUSBDeviceInterface320 **dev = args[0]; |
3026 | IOUSBDevRequest *req = args[1]; | 3054 | IOUSBDevRequest *req = args[1]; |
@@ -3034,7 +3062,8 @@ static void *iokit_limera1n_usb_submit_request(void *argv) { | |||
3034 | #endif | 3062 | #endif |
3035 | #endif | 3063 | #endif |
3036 | 3064 | ||
3037 | irecv_error_t irecv_trigger_limera1n_exploit(irecv_client_t client) { | 3065 | irecv_error_t irecv_trigger_limera1n_exploit(irecv_client_t client) |
3066 | { | ||
3038 | #ifdef USE_DUMMY | 3067 | #ifdef USE_DUMMY |
3039 | return IRECV_E_UNSUPPORTED; | 3068 | return IRECV_E_UNSUPPORTED; |
3040 | #else | 3069 | #else |
@@ -3085,7 +3114,8 @@ irecv_error_t irecv_trigger_limera1n_exploit(irecv_client_t client) { | |||
3085 | #endif | 3114 | #endif |
3086 | } | 3115 | } |
3087 | 3116 | ||
3088 | irecv_error_t irecv_execute_script(irecv_client_t client, const char* script) { | 3117 | irecv_error_t irecv_execute_script(irecv_client_t client, const char* script) |
3118 | { | ||
3089 | #ifdef USE_DUMMY | 3119 | #ifdef USE_DUMMY |
3090 | return IRECV_E_UNSUPPORTED; | 3120 | return IRECV_E_UNSUPPORTED; |
3091 | #else | 3121 | #else |
@@ -3096,15 +3126,15 @@ irecv_error_t irecv_execute_script(irecv_client_t client, const char* script) { | |||
3096 | char* body = strdup(script); | 3126 | char* body = strdup(script); |
3097 | char* line = strtok(body, "\n"); | 3127 | char* line = strtok(body, "\n"); |
3098 | 3128 | ||
3099 | while(line != NULL) { | 3129 | while (line != NULL) { |
3100 | if(line[0] != '#') { | 3130 | if (line[0] != '#') { |
3101 | error = irecv_send_command(client, line); | 3131 | error = irecv_send_command(client, line); |
3102 | if(error != IRECV_E_SUCCESS) { | 3132 | if (error != IRECV_E_SUCCESS) { |
3103 | break; | 3133 | break; |
3104 | } | 3134 | } |
3105 | 3135 | ||
3106 | error = irecv_receive(client); | 3136 | error = irecv_receive(client); |
3107 | if(error != IRECV_E_SUCCESS) { | 3137 | if (error != IRECV_E_SUCCESS) { |
3108 | break; | 3138 | break; |
3109 | } | 3139 | } |
3110 | } | 3140 | } |
@@ -3117,12 +3147,13 @@ irecv_error_t irecv_execute_script(irecv_client_t client, const char* script) { | |||
3117 | #endif | 3147 | #endif |
3118 | } | 3148 | } |
3119 | 3149 | ||
3120 | irecv_error_t irecv_saveenv(irecv_client_t client) { | 3150 | irecv_error_t irecv_saveenv(irecv_client_t client) |
3151 | { | ||
3121 | #ifdef USE_DUMMY | 3152 | #ifdef USE_DUMMY |
3122 | return IRECV_E_UNSUPPORTED; | 3153 | return IRECV_E_UNSUPPORTED; |
3123 | #else | 3154 | #else |
3124 | irecv_error_t error = irecv_send_command_raw(client, "saveenv", 0); | 3155 | irecv_error_t error = irecv_send_command_raw(client, "saveenv", 0); |
3125 | if(error != IRECV_E_SUCCESS) { | 3156 | if (error != IRECV_E_SUCCESS) { |
3126 | return error; | 3157 | return error; |
3127 | } | 3158 | } |
3128 | 3159 | ||
@@ -3130,7 +3161,8 @@ irecv_error_t irecv_saveenv(irecv_client_t client) { | |||
3130 | #endif | 3161 | #endif |
3131 | } | 3162 | } |
3132 | 3163 | ||
3133 | irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const char* value) { | 3164 | irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const char* value) |
3165 | { | ||
3134 | #ifdef USE_DUMMY | 3166 | #ifdef USE_DUMMY |
3135 | return IRECV_E_UNSUPPORTED; | 3167 | return IRECV_E_UNSUPPORTED; |
3136 | #else | 3168 | #else |
@@ -3139,14 +3171,14 @@ irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const ch | |||
3139 | if (check_context(client) != IRECV_E_SUCCESS) | 3171 | if (check_context(client) != IRECV_E_SUCCESS) |
3140 | return IRECV_E_NO_DEVICE; | 3172 | return IRECV_E_NO_DEVICE; |
3141 | 3173 | ||
3142 | if(variable == NULL || value == NULL) { | 3174 | if (variable == NULL || value == NULL) { |
3143 | return IRECV_E_UNKNOWN_ERROR; | 3175 | return IRECV_E_UNKNOWN_ERROR; |
3144 | } | 3176 | } |
3145 | 3177 | ||
3146 | memset(command, '\0', sizeof(command)); | 3178 | memset(command, '\0', sizeof(command)); |
3147 | snprintf(command, sizeof(command)-1, "setenv %s %s", variable, value); | 3179 | snprintf(command, sizeof(command)-1, "setenv %s %s", variable, value); |
3148 | irecv_error_t error = irecv_send_command_raw(client, command, 0); | 3180 | irecv_error_t error = irecv_send_command_raw(client, command, 0); |
3149 | if(error != IRECV_E_SUCCESS) { | 3181 | if (error != IRECV_E_SUCCESS) { |
3150 | return error; | 3182 | return error; |
3151 | } | 3183 | } |
3152 | 3184 | ||
@@ -3154,7 +3186,8 @@ irecv_error_t irecv_setenv(irecv_client_t client, const char* variable, const ch | |||
3154 | #endif | 3186 | #endif |
3155 | } | 3187 | } |
3156 | 3188 | ||
3157 | irecv_error_t irecv_setenv_np(irecv_client_t client, const char* variable, const char* value) { | 3189 | irecv_error_t irecv_setenv_np(irecv_client_t client, const char* variable, const char* value) |
3190 | { | ||
3158 | #ifdef USE_DUMMY | 3191 | #ifdef USE_DUMMY |
3159 | return IRECV_E_UNSUPPORTED; | 3192 | return IRECV_E_UNSUPPORTED; |
3160 | #else | 3193 | #else |
@@ -3163,14 +3196,14 @@ irecv_error_t irecv_setenv_np(irecv_client_t client, const char* variable, const | |||
3163 | if (check_context(client) != IRECV_E_SUCCESS) | 3196 | if (check_context(client) != IRECV_E_SUCCESS) |
3164 | return IRECV_E_NO_DEVICE; | 3197 | return IRECV_E_NO_DEVICE; |
3165 | 3198 | ||
3166 | if(variable == NULL || value == NULL) { | 3199 | if (variable == NULL || value == NULL) { |
3167 | return IRECV_E_UNKNOWN_ERROR; | 3200 | return IRECV_E_UNKNOWN_ERROR; |
3168 | } | 3201 | } |
3169 | 3202 | ||
3170 | memset(command, '\0', sizeof(command)); | 3203 | memset(command, '\0', sizeof(command)); |
3171 | snprintf(command, sizeof(command)-1, "setenvnp %s %s", variable, value); | 3204 | snprintf(command, sizeof(command)-1, "setenvnp %s %s", variable, value); |
3172 | irecv_error_t error = irecv_send_command_raw(client, command, 0); | 3205 | irecv_error_t error = irecv_send_command_raw(client, command, 0); |
3173 | if(error != IRECV_E_SUCCESS) { | 3206 | if (error != IRECV_E_SUCCESS) { |
3174 | return error; | 3207 | return error; |
3175 | } | 3208 | } |
3176 | 3209 | ||
@@ -3178,12 +3211,13 @@ irecv_error_t irecv_setenv_np(irecv_client_t client, const char* variable, const | |||
3178 | #endif | 3211 | #endif |
3179 | } | 3212 | } |
3180 | 3213 | ||
3181 | irecv_error_t irecv_reboot(irecv_client_t client) { | 3214 | irecv_error_t irecv_reboot(irecv_client_t client) |
3215 | { | ||
3182 | #ifdef USE_DUMMY | 3216 | #ifdef USE_DUMMY |
3183 | return IRECV_E_UNSUPPORTED; | 3217 | return IRECV_E_UNSUPPORTED; |
3184 | #else | 3218 | #else |
3185 | irecv_error_t error = irecv_send_command_raw(client, "reboot", 0); | 3219 | irecv_error_t error = irecv_send_command_raw(client, "reboot", 0); |
3186 | if(error != IRECV_E_SUCCESS) { | 3220 | if (error != IRECV_E_SUCCESS) { |
3187 | return error; | 3221 | return error; |
3188 | } | 3222 | } |
3189 | 3223 | ||
@@ -3191,7 +3225,8 @@ irecv_error_t irecv_reboot(irecv_client_t client) { | |||
3191 | #endif | 3225 | #endif |
3192 | } | 3226 | } |
3193 | 3227 | ||
3194 | const char* irecv_strerror(irecv_error_t error) { | 3228 | const char* irecv_strerror(irecv_error_t error) |
3229 | { | ||
3195 | switch (error) { | 3230 | switch (error) { |
3196 | case IRECV_E_SUCCESS: | 3231 | case IRECV_E_SUCCESS: |
3197 | return "Command completed successfully"; | 3232 | return "Command completed successfully"; |
@@ -3239,7 +3274,8 @@ const char* irecv_strerror(irecv_error_t error) { | |||
3239 | return NULL; | 3274 | return NULL; |
3240 | } | 3275 | } |
3241 | 3276 | ||
3242 | irecv_error_t irecv_reset_counters(irecv_client_t client) { | 3277 | irecv_error_t irecv_reset_counters(irecv_client_t client) |
3278 | { | ||
3243 | #ifdef USE_DUMMY | 3279 | #ifdef USE_DUMMY |
3244 | return IRECV_E_UNSUPPORTED; | 3280 | return IRECV_E_UNSUPPORTED; |
3245 | #else | 3281 | #else |
@@ -3254,7 +3290,8 @@ irecv_error_t irecv_reset_counters(irecv_client_t client) { | |||
3254 | #endif | 3290 | #endif |
3255 | } | 3291 | } |
3256 | 3292 | ||
3257 | irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned long length) { | 3293 | irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned long length) |
3294 | { | ||
3258 | #ifdef USE_DUMMY | 3295 | #ifdef USE_DUMMY |
3259 | return IRECV_E_UNSUPPORTED; | 3296 | return IRECV_E_UNSUPPORTED; |
3260 | #else | 3297 | #else |
@@ -3284,7 +3321,7 @@ irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned lo | |||
3284 | } | 3321 | } |
3285 | 3322 | ||
3286 | count += size; | 3323 | count += size; |
3287 | if(client->progress_callback != NULL) { | 3324 | if (client->progress_callback != NULL) { |
3288 | irecv_event_t event; | 3325 | irecv_event_t event; |
3289 | event.progress = ((double) count/ (double) length) * 100.0; | 3326 | event.progress = ((double) count/ (double) length) * 100.0; |
3290 | event.type = IRECV_PROGRESS; | 3327 | event.type = IRECV_PROGRESS; |
@@ -3300,7 +3337,8 @@ irecv_error_t irecv_recv_buffer(irecv_client_t client, char* buffer, unsigned lo | |||
3300 | #endif | 3337 | #endif |
3301 | } | 3338 | } |
3302 | 3339 | ||
3303 | irecv_error_t irecv_finish_transfer(irecv_client_t client) { | 3340 | irecv_error_t irecv_finish_transfer(irecv_client_t client) |
3341 | { | ||
3304 | #ifdef USE_DUMMY | 3342 | #ifdef USE_DUMMY |
3305 | return IRECV_E_UNSUPPORTED; | 3343 | return IRECV_E_UNSUPPORTED; |
3306 | #else | 3344 | #else |
@@ -3312,7 +3350,7 @@ irecv_error_t irecv_finish_transfer(irecv_client_t client) { | |||
3312 | 3350 | ||
3313 | irecv_usb_control_transfer(client, 0x21, 1, 0, 0, 0, 0, USB_TIMEOUT); | 3351 | irecv_usb_control_transfer(client, 0x21, 1, 0, 0, 0, 0, USB_TIMEOUT); |
3314 | 3352 | ||
3315 | for(i = 0; i < 3; i++){ | 3353 | for (i = 0; i < 3; i++){ |
3316 | irecv_get_status(client, &status); | 3354 | irecv_get_status(client, &status); |
3317 | } | 3355 | } |
3318 | 3356 | ||
@@ -3322,11 +3360,13 @@ irecv_error_t irecv_finish_transfer(irecv_client_t client) { | |||
3322 | #endif | 3360 | #endif |
3323 | } | 3361 | } |
3324 | 3362 | ||
3325 | irecv_device_t irecv_devices_get_all(void) { | 3363 | irecv_device_t irecv_devices_get_all(void) |
3364 | { | ||
3326 | return irecv_devices; | 3365 | return irecv_devices; |
3327 | } | 3366 | } |
3328 | 3367 | ||
3329 | irecv_error_t irecv_devices_get_device_by_client(irecv_client_t client, irecv_device_t* device) { | 3368 | irecv_error_t irecv_devices_get_device_by_client(irecv_client_t client, irecv_device_t* device) |
3369 | { | ||
3330 | #ifdef USE_DUMMY | 3370 | #ifdef USE_DUMMY |
3331 | return IRECV_E_UNSUPPORTED; | 3371 | return IRECV_E_UNSUPPORTED; |
3332 | #else | 3372 | #else |
@@ -3352,7 +3392,8 @@ irecv_error_t irecv_devices_get_device_by_client(irecv_client_t client, irecv_de | |||
3352 | #endif | 3392 | #endif |
3353 | } | 3393 | } |
3354 | 3394 | ||
3355 | irecv_error_t irecv_devices_get_device_by_product_type(const char* product_type, irecv_device_t* device) { | 3395 | irecv_error_t irecv_devices_get_device_by_product_type(const char* product_type, irecv_device_t* device) |
3396 | { | ||
3356 | int i = 0; | 3397 | int i = 0; |
3357 | 3398 | ||
3358 | if (!product_type || !device) | 3399 | if (!product_type || !device) |
@@ -3370,7 +3411,8 @@ irecv_error_t irecv_devices_get_device_by_product_type(const char* product_type, | |||
3370 | return IRECV_E_NO_DEVICE; | 3411 | return IRECV_E_NO_DEVICE; |
3371 | } | 3412 | } |
3372 | 3413 | ||
3373 | irecv_error_t irecv_devices_get_device_by_hardware_model(const char* hardware_model, irecv_device_t* device) { | 3414 | irecv_error_t irecv_devices_get_device_by_hardware_model(const char* hardware_model, irecv_device_t* device) |
3415 | { | ||
3374 | int i = 0; | 3416 | int i = 0; |
3375 | 3417 | ||
3376 | if (!hardware_model || !device) | 3418 | if (!hardware_model || !device) |
@@ -3388,7 +3430,8 @@ irecv_error_t irecv_devices_get_device_by_hardware_model(const char* hardware_mo | |||
3388 | return IRECV_E_NO_DEVICE; | 3430 | return IRECV_E_NO_DEVICE; |
3389 | } | 3431 | } |
3390 | 3432 | ||
3391 | irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause) { | 3433 | irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause) |
3434 | { | ||
3392 | #ifdef USE_DUMMY | 3435 | #ifdef USE_DUMMY |
3393 | return NULL; | 3436 | return NULL; |
3394 | #else | 3437 | #else |
@@ -3413,7 +3456,7 @@ irecv_client_t irecv_reconnect(irecv_client_t client, int initial_pause) { | |||
3413 | } | 3456 | } |
3414 | 3457 | ||
3415 | error = irecv_open_with_ecid_and_attempts(&new_client, ecid, 10); | 3458 | error = irecv_open_with_ecid_and_attempts(&new_client, ecid, 10); |
3416 | if(error != IRECV_E_SUCCESS) { | 3459 | if (error != IRECV_E_SUCCESS) { |
3417 | return NULL; | 3460 | return NULL; |
3418 | } | 3461 | } |
3419 | 3462 | ||