diff options
Diffstat (limited to 'src/libirecovery.c')
-rw-r--r-- | src/libirecovery.c | 118 |
1 files changed, 57 insertions, 61 deletions
diff --git a/src/libirecovery.c b/src/libirecovery.c index dc55c95..046c8ec 100644 --- a/src/libirecovery.c +++ b/src/libirecovery.c | |||
@@ -1089,11 +1089,52 @@ typedef struct usb_control_request { | |||
1089 | char data[]; | 1089 | char data[]; |
1090 | } usb_control_request; | 1090 | } usb_control_request; |
1091 | 1091 | ||
1092 | irecv_error_t mobiledevice_openpipes(irecv_client_t client); | 1092 | static irecv_error_t win32_openpipes(irecv_client_t client) |
1093 | void mobiledevice_closepipes(irecv_client_t client); | 1093 | { |
1094 | irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid); | 1094 | 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))) { |
1095 | irecv_close(client); | ||
1096 | return IRECV_E_UNABLE_TO_CONNECT; | ||
1097 | } | ||
1095 | 1098 | ||
1096 | irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | 1099 | if (client->DfuPath && !(client->hDFU = CreateFileA(client->DfuPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))) { |
1100 | irecv_close(client); | ||
1101 | return IRECV_E_UNABLE_TO_CONNECT; | ||
1102 | } | ||
1103 | |||
1104 | client->mode = 0; | ||
1105 | if (client->iBootPath == NULL) { | ||
1106 | if (strncmp(client->DfuPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { | ||
1107 | sscanf(client->DfuPath+21, "%x#", &client->mode); | ||
1108 | } | ||
1109 | client->handle = client->hDFU; | ||
1110 | } else { | ||
1111 | if (strncmp(client->iBootPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { | ||
1112 | sscanf(client->iBootPath+21, "%x#", &client->mode); | ||
1113 | } | ||
1114 | client->handle = client->hIB; | ||
1115 | } | ||
1116 | |||
1117 | if (client->mode == 0) { | ||
1118 | irecv_close(client); | ||
1119 | return IRECV_E_UNABLE_TO_CONNECT; | ||
1120 | } | ||
1121 | |||
1122 | return IRECV_E_SUCCESS; | ||
1123 | } | ||
1124 | |||
1125 | static void win32_closepipes(irecv_client_t client) | ||
1126 | { | ||
1127 | if (client->hDFU!=NULL) { | ||
1128 | CloseHandle(client->hDFU); | ||
1129 | client->hDFU = NULL; | ||
1130 | } | ||
1131 | if (client->hIB!=NULL) { | ||
1132 | CloseHandle(client->hIB); | ||
1133 | client->hIB = NULL; | ||
1134 | } | ||
1135 | } | ||
1136 | |||
1137 | static irecv_error_t win32_open_with_ecid(irecv_client_t* client, uint64_t ecid) | ||
1097 | { | 1138 | { |
1098 | int found = 0; | 1139 | int found = 0; |
1099 | SP_DEVICE_INTERFACE_DATA currentInterface; | 1140 | SP_DEVICE_INTERFACE_DATA currentInterface; |
@@ -1124,8 +1165,8 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1124 | free(details); | 1165 | free(details); |
1125 | 1166 | ||
1126 | _client->DfuPath = result; | 1167 | _client->DfuPath = result; |
1127 | if (mobiledevice_openpipes(_client) != IRECV_E_SUCCESS) { | 1168 | if (win32_openpipes(_client) != IRECV_E_SUCCESS) { |
1128 | mobiledevice_closepipes(_client); | 1169 | win32_closepipes(_client); |
1129 | continue; | 1170 | continue; |
1130 | } | 1171 | } |
1131 | 1172 | ||
@@ -1140,7 +1181,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1140 | 1181 | ||
1141 | if ((ecid != 0) && (_client->mode == IRECV_K_WTF_MODE)) { | 1182 | if ((ecid != 0) && (_client->mode == IRECV_K_WTF_MODE)) { |
1142 | /* we can't get ecid in WTF mode */ | 1183 | /* we can't get ecid in WTF mode */ |
1143 | mobiledevice_closepipes(_client); | 1184 | win32_closepipes(_client); |
1144 | continue; | 1185 | continue; |
1145 | } | 1186 | } |
1146 | 1187 | ||
@@ -1155,7 +1196,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1155 | } | 1196 | } |
1156 | 1197 | ||
1157 | if (serial_str[0] == '\0') { | 1198 | if (serial_str[0] == '\0') { |
1158 | mobiledevice_closepipes(_client); | 1199 | win32_closepipes(_client); |
1159 | continue; | 1200 | continue; |
1160 | } | 1201 | } |
1161 | 1202 | ||
@@ -1177,7 +1218,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1177 | 1218 | ||
1178 | if (ecid != 0) { | 1219 | if (ecid != 0) { |
1179 | if (_client->device_info.ecid != ecid) { | 1220 | if (_client->device_info.ecid != ecid) { |
1180 | mobiledevice_closepipes(_client); | 1221 | win32_closepipes(_client); |
1181 | continue; | 1222 | continue; |
1182 | } | 1223 | } |
1183 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); | 1224 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); |
@@ -1215,14 +1256,14 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1215 | free(details); | 1256 | free(details); |
1216 | 1257 | ||
1217 | _client->iBootPath = result; | 1258 | _client->iBootPath = result; |
1218 | if (mobiledevice_openpipes(_client) != IRECV_E_SUCCESS) { | 1259 | if (win32_openpipes(_client) != IRECV_E_SUCCESS) { |
1219 | mobiledevice_closepipes(_client); | 1260 | win32_closepipes(_client); |
1220 | continue; | 1261 | continue; |
1221 | } | 1262 | } |
1222 | 1263 | ||
1223 | if ((ecid != 0) && (_client->mode == IRECV_K_WTF_MODE)) { | 1264 | if ((ecid != 0) && (_client->mode == IRECV_K_WTF_MODE)) { |
1224 | /* we can't get ecid in WTF mode */ | 1265 | /* we can't get ecid in WTF mode */ |
1225 | mobiledevice_closepipes(_client); | 1266 | win32_closepipes(_client); |
1226 | continue; | 1267 | continue; |
1227 | } | 1268 | } |
1228 | 1269 | ||
@@ -1237,7 +1278,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1237 | } | 1278 | } |
1238 | 1279 | ||
1239 | if (serial_str[0] == '\0') { | 1280 | if (serial_str[0] == '\0') { |
1240 | mobiledevice_closepipes(_client); | 1281 | win32_closepipes(_client); |
1241 | continue; | 1282 | continue; |
1242 | } | 1283 | } |
1243 | 1284 | ||
@@ -1259,7 +1300,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1259 | 1300 | ||
1260 | if (ecid != 0) { | 1301 | if (ecid != 0) { |
1261 | if (_client->device_info.ecid != ecid) { | 1302 | if (_client->device_info.ecid != ecid) { |
1262 | mobiledevice_closepipes(_client); | 1303 | win32_closepipes(_client); |
1263 | continue; | 1304 | continue; |
1264 | } | 1305 | } |
1265 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); | 1306 | debug("found device with ECID %016" PRIx64 "\n", (uint64_t)ecid); |
@@ -1279,51 +1320,6 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) | |||
1279 | 1320 | ||
1280 | return IRECV_E_SUCCESS; | 1321 | return IRECV_E_SUCCESS; |
1281 | } | 1322 | } |
1282 | |||
1283 | irecv_error_t mobiledevice_openpipes(irecv_client_t client) | ||
1284 | { | ||
1285 | 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))) { | ||
1286 | irecv_close(client); | ||
1287 | return IRECV_E_UNABLE_TO_CONNECT; | ||
1288 | } | ||
1289 | |||
1290 | if (client->DfuPath && !(client->hDFU = CreateFileA(client->DfuPath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL))) { | ||
1291 | irecv_close(client); | ||
1292 | return IRECV_E_UNABLE_TO_CONNECT; | ||
1293 | } | ||
1294 | |||
1295 | client->mode = 0; | ||
1296 | if (client->iBootPath == NULL) { | ||
1297 | if (strncmp(client->DfuPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { | ||
1298 | sscanf(client->DfuPath+21, "%x#", &client->mode); | ||
1299 | } | ||
1300 | client->handle = client->hDFU; | ||
1301 | } else { | ||
1302 | if (strncmp(client->iBootPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { | ||
1303 | sscanf(client->iBootPath+21, "%x#", &client->mode); | ||
1304 | } | ||
1305 | client->handle = client->hIB; | ||
1306 | } | ||
1307 | |||
1308 | if (client->mode == 0) { | ||
1309 | irecv_close(client); | ||
1310 | return IRECV_E_UNABLE_TO_CONNECT; | ||
1311 | } | ||
1312 | |||
1313 | return IRECV_E_SUCCESS; | ||
1314 | } | ||
1315 | |||
1316 | void mobiledevice_closepipes(irecv_client_t client) | ||
1317 | { | ||
1318 | if (client->hDFU!=NULL) { | ||
1319 | CloseHandle(client->hDFU); | ||
1320 | client->hDFU = NULL; | ||
1321 | } | ||
1322 | if (client->hIB!=NULL) { | ||
1323 | CloseHandle(client->hIB); | ||
1324 | client->hIB = NULL; | ||
1325 | } | ||
1326 | } | ||
1327 | #endif | 1323 | #endif |
1328 | 1324 | ||
1329 | #ifdef HAVE_IOKIT | 1325 | #ifdef HAVE_IOKIT |
@@ -1856,7 +1852,7 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) | |||
1856 | error = libusb_open_with_ecid(pclient, ecid); | 1852 | error = libusb_open_with_ecid(pclient, ecid); |
1857 | #endif | 1853 | #endif |
1858 | #else | 1854 | #else |
1859 | error = mobiledevice_connect(pclient, ecid); | 1855 | error = win32_open_with_ecid(pclient, ecid); |
1860 | #endif | 1856 | #endif |
1861 | irecv_client_t client = *pclient; | 1857 | irecv_client_t client = *pclient; |
1862 | if (error != IRECV_E_SUCCESS) { | 1858 | if (error != IRECV_E_SUCCESS) { |
@@ -2987,7 +2983,7 @@ irecv_error_t irecv_close(irecv_client_t client) | |||
2987 | client->iBootPath = NULL; | 2983 | client->iBootPath = NULL; |
2988 | free(client->DfuPath); | 2984 | free(client->DfuPath); |
2989 | client->DfuPath = NULL; | 2985 | client->DfuPath = NULL; |
2990 | mobiledevice_closepipes(client); | 2986 | win32_closepipes(client); |
2991 | #endif | 2987 | #endif |
2992 | free(client->device_info.srnm); | 2988 | free(client->device_info.srnm); |
2993 | free(client->device_info.imei); | 2989 | free(client->device_info.imei); |