diff options
| -rw-r--r-- | src/libirecovery.c | 169 |
1 files changed, 57 insertions, 112 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index a85cd97..e5369ce 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c | |||
| @@ -1174,8 +1174,6 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
| 1174 | } | 1174 | } |
| 1175 | 1175 | ||
| 1176 | irecv_load_device_info_from_iboot_string(_client, serial_str); | 1176 | irecv_load_device_info_from_iboot_string(_client, serial_str); |
| 1177 | irecv_copy_nonce_with_tag(_client, "NONC", &_client->device_info.ap_nonce, &_client->device_info.ap_nonce_size); | ||
| 1178 | irecv_copy_nonce_with_tag(_client, "SNON", &_client->device_info.sep_nonce, &_client->device_info.sep_nonce_size); | ||
| 1179 | 1177 | ||
| 1180 | if (ecid != 0) { | 1178 | if (ecid != 0) { |
| 1181 | if (_client->device_info.ecid != ecid) { | 1179 | if (_client->device_info.ecid != ecid) { |
| @@ -1258,8 +1256,6 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
| 1258 | } | 1256 | } |
| 1259 | 1257 | ||
| 1260 | irecv_load_device_info_from_iboot_string(_client, serial_str); | 1258 | irecv_load_device_info_from_iboot_string(_client, serial_str); |
| 1261 | irecv_copy_nonce_with_tag(_client, "NONC", &_client->device_info.ap_nonce, &_client->device_info.ap_nonce_size); | ||
| 1262 | irecv_copy_nonce_with_tag(_client, "SNON", &_client->device_info.sep_nonce, &_client->device_info.sep_nonce_size); | ||
| 1263 | 1259 | ||
| 1264 | if (ecid != 0) { | 1260 | if (ecid != 0) { |
| 1265 | if (_client->device_info.ecid != ecid) { | 1261 | if (_client->device_info.ecid != ecid) { |
| @@ -1569,7 +1565,6 @@ int irecv_usb_bulk_transfer(irecv_client_t client, | |||
| 1569 | static irecv_error_t iokit_usb_open_service(irecv_client_t *pclient, io_service_t service) | 1565 | static irecv_error_t iokit_usb_open_service(irecv_client_t *pclient, io_service_t service) |
| 1570 | { | 1566 | { |
| 1571 | IOReturn result; | 1567 | IOReturn result; |
| 1572 | irecv_error_t error; | ||
| 1573 | irecv_client_t client; | 1568 | irecv_client_t client; |
| 1574 | SInt32 score; | 1569 | SInt32 score; |
| 1575 | UInt16 mode; | 1570 | UInt16 mode; |
| @@ -1620,52 +1615,6 @@ static irecv_error_t iokit_usb_open_service(irecv_client_t *pclient, io_service_ | |||
| 1620 | return IRECV_E_UNABLE_TO_CONNECT; | 1615 | return IRECV_E_UNABLE_TO_CONNECT; |
| 1621 | } | 1616 | } |
| 1622 | 1617 | ||
| 1623 | error = irecv_usb_set_configuration(client, 1); | ||
| 1624 | if (error != IRECV_E_SUCCESS) { | ||
| 1625 | free(client); | ||
| 1626 | return error; | ||
| 1627 | } | ||
| 1628 | |||
| 1629 | // DFU mode has no endpoints, so no need to open the interface | ||
| 1630 | if (client->mode == IRECV_K_DFU_MODE || client->mode == IRECV_K_WTF_MODE || client->mode == KIS_PRODUCT_ID) { | ||
| 1631 | error = irecv_usb_set_interface(client, 0, 0); | ||
| 1632 | if (error != IRECV_E_SUCCESS) { | ||
| 1633 | free(client); | ||
| 1634 | return error; | ||
| 1635 | } | ||
| 1636 | } | ||
| 1637 | else { | ||
| 1638 | error = irecv_usb_set_interface(client, 0, 0); | ||
| 1639 | if (error != IRECV_E_SUCCESS) { | ||
| 1640 | free(client); | ||
| 1641 | return error; | ||
| 1642 | } | ||
| 1643 | if (client->mode > IRECV_K_RECOVERY_MODE_2) { | ||
| 1644 | error = irecv_usb_set_interface(client, 1, 1); | ||
| 1645 | if (error != IRECV_E_SUCCESS) { | ||
| 1646 | free(client); | ||
| 1647 | return error; | ||
| 1648 | } | ||
| 1649 | } | ||
| 1650 | } | ||
| 1651 | |||
| 1652 | if (client->mode == KIS_PRODUCT_ID) { | ||
| 1653 | error = irecv_kis_init(client); | ||
| 1654 | if (error != IRECV_E_SUCCESS) { | ||
| 1655 | debug("irecv_kis_init failed, error %d\n", error); | ||
| 1656 | return error; | ||
| 1657 | } | ||
| 1658 | |||
| 1659 | error = irecv_kis_load_device_info(client); | ||
| 1660 | if (error != IRECV_E_SUCCESS) { | ||
| 1661 | debug("irecv_kis_load_device_info failed, error %d\n", error); | ||
| 1662 | return error; | ||
| 1663 | } | ||
| 1664 | } else { | ||
| 1665 | irecv_copy_nonce_with_tag(client, "NONC", &client->device_info.ap_nonce, &client->device_info.ap_nonce_size); | ||
| 1666 | irecv_copy_nonce_with_tag(client, "SNON", &client->device_info.sep_nonce, &client->device_info.sep_nonce_size); | ||
| 1667 | } | ||
| 1668 | |||
| 1669 | *pclient = client; | 1618 | *pclient = client; |
| 1670 | return IRECV_E_SUCCESS; | 1619 | return IRECV_E_SUCCESS; |
| 1671 | } | 1620 | } |
| @@ -1789,7 +1738,8 @@ static irecv_error_t iokit_open_with_ecid(irecv_client_t* pclient, uint64_t ecid | |||
| 1789 | 1738 | ||
| 1790 | #ifndef WIN32 | 1739 | #ifndef WIN32 |
| 1791 | #ifndef HAVE_IOKIT | 1740 | #ifndef HAVE_IOKIT |
| 1792 | static irecv_error_t libusb_usb_open_handle_with_descriptor_and_ecid(irecv_client_t *pclient, struct libusb_device_handle *usb_handle, struct libusb_device_descriptor *usb_descriptor, uint64_t ecid){ | 1741 | static irecv_error_t libusb_usb_open_handle_with_descriptor_and_ecid(irecv_client_t *pclient, struct libusb_device_handle *usb_handle, struct libusb_device_descriptor *usb_descriptor, uint64_t ecid) |
| 1742 | { | ||
| 1793 | irecv_error_t ret = IRECV_E_UNABLE_TO_CONNECT; | 1743 | irecv_error_t ret = IRECV_E_UNABLE_TO_CONNECT; |
| 1794 | irecv_error_t error = IRECV_E_UNABLE_TO_CONNECT; | 1744 | irecv_error_t error = IRECV_E_UNABLE_TO_CONNECT; |
| 1795 | 1745 | ||
| @@ -1819,48 +1769,6 @@ static irecv_error_t libusb_usb_open_handle_with_descriptor_and_ecid(irecv_clien | |||
| 1819 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); | 1769 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); |
| 1820 | } | 1770 | } |
| 1821 | 1771 | ||
| 1822 | error = irecv_usb_set_configuration(client, 1); | ||
| 1823 | if (error != IRECV_E_SUCCESS) { | ||
| 1824 | irecv_close(client); | ||
| 1825 | return error; | ||
| 1826 | } | ||
| 1827 | |||
| 1828 | if ((client->mode != IRECV_K_DFU_MODE) && (client->mode != IRECV_K_WTF_MODE) && (client->mode != KIS_PRODUCT_ID)) { | ||
| 1829 | error = irecv_usb_set_interface(client, 0, 0); | ||
| 1830 | if (client->mode > IRECV_K_RECOVERY_MODE_2) { | ||
| 1831 | error = irecv_usb_set_interface(client, 1, 1); | ||
| 1832 | } | ||
| 1833 | } else { | ||
| 1834 | error = irecv_usb_set_interface(client, 0, 0); | ||
| 1835 | } | ||
| 1836 | |||
| 1837 | if (error != IRECV_E_SUCCESS) { | ||
| 1838 | irecv_close(client); | ||
| 1839 | return error; | ||
| 1840 | } | ||
| 1841 | |||
| 1842 | if (client->mode == KIS_PRODUCT_ID) { | ||
| 1843 | error = irecv_kis_init(client); | ||
| 1844 | if (error != IRECV_E_SUCCESS) { | ||
| 1845 | debug("irecv_kis_init failed, error %d\n", error); | ||
| 1846 | return error; | ||
| 1847 | } | ||
| 1848 | |||
| 1849 | error = irecv_kis_load_device_info(client); | ||
| 1850 | if (error != IRECV_E_SUCCESS) { | ||
| 1851 | debug("irecv_kis_load_device_info failed, error %d\n", error); | ||
| 1852 | return error; | ||
| 1853 | } | ||
| 1854 | if (ecid != 0 && client->device_info.ecid != ecid) { | ||
| 1855 | irecv_close(client); | ||
| 1856 | return IRECV_E_NO_DEVICE; //wrong device | ||
| 1857 | } | ||
| 1858 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); | ||
| 1859 | } else { | ||
| 1860 | irecv_copy_nonce_with_tag(client, "NONC", &client->device_info.ap_nonce, &client->device_info.ap_nonce_size); | ||
| 1861 | irecv_copy_nonce_with_tag(client, "SNON", &client->device_info.sep_nonce, &client->device_info.sep_nonce_size); | ||
| 1862 | } | ||
| 1863 | |||
| 1864 | ret = IRECV_E_SUCCESS; | 1772 | ret = IRECV_E_SUCCESS; |
| 1865 | *pclient = client; | 1773 | *pclient = client; |
| 1866 | return ret; | 1774 | return ret; |
| @@ -1936,36 +1844,73 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) | |||
| 1936 | #ifdef USE_DUMMY | 1844 | #ifdef USE_DUMMY |
| 1937 | return IRECV_E_UNSUPPORTED; | 1845 | return IRECV_E_UNSUPPORTED; |
| 1938 | #else | 1846 | #else |
| 1939 | int ret = IRECV_E_UNABLE_TO_CONNECT; | 1847 | irecv_error_t error = IRECV_E_UNABLE_TO_CONNECT; |
| 1940 | 1848 | ||
| 1941 | if (libirecovery_debug) { | 1849 | if (libirecovery_debug) { |
| 1942 | irecv_set_debug_level(libirecovery_debug); | 1850 | irecv_set_debug_level(libirecovery_debug); |
| 1943 | } | 1851 | } |
| 1944 | #ifndef WIN32 | 1852 | #ifndef WIN32 |
| 1945 | #ifdef HAVE_IOKIT | 1853 | #ifdef HAVE_IOKIT |
| 1946 | ret = iokit_open_with_ecid(pclient, ecid); | 1854 | error = iokit_open_with_ecid(pclient, ecid); |
| 1947 | #else | 1855 | #else |
| 1948 | ret = libusb_open_with_ecid(pclient, ecid); | 1856 | error = libusb_open_with_ecid(pclient, ecid); |
| 1949 | #endif | 1857 | #endif |
| 1950 | #else | 1858 | #else |
| 1951 | ret = mobiledevice_connect(pclient, ecid); | 1859 | error = mobiledevice_connect(pclient, ecid); |
| 1952 | if (ret == IRECV_E_SUCCESS) { | 1860 | #endif |
| 1953 | irecv_client_t client = *pclient; | 1861 | irecv_client_t client = *pclient; |
| 1954 | int error = IRECV_E_SUCCESS; | 1862 | if (error != IRECV_E_SUCCESS) { |
| 1955 | if ((client->mode != IRECV_K_DFU_MODE) && (client->mode != IRECV_K_WTF_MODE)) { | 1863 | irecv_close(client); |
| 1956 | error = irecv_usb_set_interface(client, 0, 0); | 1864 | return error; |
| 1957 | if (client->mode > IRECV_K_RECOVERY_MODE_2) { | 1865 | } |
| 1958 | error = irecv_usb_set_interface(client, 1, 1); | 1866 | |
| 1959 | } | 1867 | error = irecv_usb_set_configuration(client, 1); |
| 1960 | } else { | 1868 | if (error != IRECV_E_SUCCESS) { |
| 1961 | error = irecv_usb_set_interface(client, 0, 0); | 1869 | debug("Failed to set configuration, error %d\n", error); |
| 1870 | irecv_close(client); | ||
| 1871 | return error; | ||
| 1872 | } | ||
| 1873 | |||
| 1874 | if (client->mode == IRECV_K_DFU_MODE || client->mode == IRECV_K_WTF_MODE || client->mode == KIS_PRODUCT_ID) { | ||
| 1875 | error = irecv_usb_set_interface(client, 0, 0); | ||
| 1876 | } else { | ||
| 1877 | error = irecv_usb_set_interface(client, 0, 0); | ||
| 1878 | if (error == IRECV_E_SUCCESS && client->mode > IRECV_K_RECOVERY_MODE_2) { | ||
| 1879 | error = irecv_usb_set_interface(client, 1, 1); | ||
| 1962 | } | 1880 | } |
| 1881 | } | ||
| 1882 | |||
| 1883 | if (error != IRECV_E_SUCCESS) { | ||
| 1884 | debug("Failed to set interface, error %d\n", error); | ||
| 1885 | irecv_close(client); | ||
| 1886 | return error; | ||
| 1887 | } | ||
| 1888 | |||
| 1889 | if (client->mode == KIS_PRODUCT_ID) { | ||
| 1890 | error = irecv_kis_init(client); | ||
| 1963 | if (error != IRECV_E_SUCCESS) { | 1891 | if (error != IRECV_E_SUCCESS) { |
| 1964 | debug("WARNING: set interface failed, error %d\n", error); | 1892 | debug("irecv_kis_init failed, error %d\n", error); |
| 1893 | irecv_close(client); | ||
| 1894 | return error; | ||
| 1965 | } | 1895 | } |
| 1896 | |||
| 1897 | error = irecv_kis_load_device_info(client); | ||
| 1898 | if (error != IRECV_E_SUCCESS) { | ||
| 1899 | debug("irecv_kis_load_device_info failed, error %d\n", error); | ||
| 1900 | irecv_close(client); | ||
| 1901 | return error; | ||
| 1902 | } | ||
| 1903 | if (ecid != 0 && client->device_info.ecid != ecid) { | ||
| 1904 | irecv_close(client); | ||
| 1905 | return IRECV_E_NO_DEVICE; //wrong device | ||
| 1906 | } | ||
| 1907 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); | ||
| 1908 | } else { | ||
| 1909 | irecv_copy_nonce_with_tag(client, "NONC", &client->device_info.ap_nonce, &client->device_info.ap_nonce_size); | ||
| 1910 | irecv_copy_nonce_with_tag(client, "SNON", &client->device_info.sep_nonce, &client->device_info.sep_nonce_size); | ||
| 1966 | } | 1911 | } |
| 1967 | #endif | 1912 | |
| 1968 | if (ret == IRECV_E_SUCCESS) { | 1913 | if (error == IRECV_E_SUCCESS) { |
| 1969 | if ((*pclient)->connected_callback != NULL) { | 1914 | if ((*pclient)->connected_callback != NULL) { |
| 1970 | irecv_event_t event; | 1915 | irecv_event_t event; |
| 1971 | event.size = 0; | 1916 | event.size = 0; |
| @@ -1975,7 +1920,7 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) | |||
| 1975 | (*pclient)->connected_callback(*pclient, &event); | 1920 | (*pclient)->connected_callback(*pclient, &event); |
| 1976 | } | 1921 | } |
| 1977 | } | 1922 | } |
| 1978 | return ret; | 1923 | return error; |
| 1979 | #endif | 1924 | #endif |
| 1980 | } | 1925 | } |
| 1981 | 1926 | ||
