diff options
author | Nikias Bassen | 2023-11-18 00:42:01 +0100 |
---|---|---|
committer | Nikias Bassen | 2023-11-18 00:42:01 +0100 |
commit | 1a12fc2877a5aac5ef28b196753c83188fc13ef0 (patch) | |
tree | b49d88078687ca166d89587f26192a25d0322fff /src | |
parent | d15e34768865ff2348a88bc095f341a15da44677 (diff) | |
download | libirecovery-1a12fc2877a5aac5ef28b196753c83188fc13ef0.tar.gz libirecovery-1a12fc2877a5aac5ef28b196753c83188fc13ef0.tar.bz2 |
win32: Rename and reorder internal functions
Diffstat (limited to 'src')
-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 { char data[]; } usb_control_request; -irecv_error_t mobiledevice_openpipes(irecv_client_t client); -void mobiledevice_closepipes(irecv_client_t client); -irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid); +static irecv_error_t win32_openpipes(irecv_client_t client) +{ + 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))) { + irecv_close(client); + return IRECV_E_UNABLE_TO_CONNECT; + } -irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) + 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))) { + irecv_close(client); + return IRECV_E_UNABLE_TO_CONNECT; + } + + client->mode = 0; + if (client->iBootPath == NULL) { + if (strncmp(client->DfuPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { + sscanf(client->DfuPath+21, "%x#", &client->mode); + } + client->handle = client->hDFU; + } else { + if (strncmp(client->iBootPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { + sscanf(client->iBootPath+21, "%x#", &client->mode); + } + client->handle = client->hIB; + } + + if (client->mode == 0) { + irecv_close(client); + return IRECV_E_UNABLE_TO_CONNECT; + } + + return IRECV_E_SUCCESS; +} + +static void win32_closepipes(irecv_client_t client) +{ + if (client->hDFU!=NULL) { + CloseHandle(client->hDFU); + client->hDFU = NULL; + } + if (client->hIB!=NULL) { + CloseHandle(client->hIB); + client->hIB = NULL; + } +} + +static irecv_error_t win32_open_with_ecid(irecv_client_t* client, uint64_t ecid) { int found = 0; SP_DEVICE_INTERFACE_DATA currentInterface; @@ -1124,8 +1165,8 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) free(details); _client->DfuPath = result; - if (mobiledevice_openpipes(_client) != IRECV_E_SUCCESS) { - mobiledevice_closepipes(_client); + if (win32_openpipes(_client) != IRECV_E_SUCCESS) { + win32_closepipes(_client); continue; } @@ -1140,7 +1181,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) if ((ecid != 0) && (_client->mode == IRECV_K_WTF_MODE)) { /* we can't get ecid in WTF mode */ - mobiledevice_closepipes(_client); + win32_closepipes(_client); continue; } @@ -1155,7 +1196,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) } if (serial_str[0] == '\0') { - mobiledevice_closepipes(_client); + win32_closepipes(_client); continue; } @@ -1177,7 +1218,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) if (ecid != 0) { if (_client->device_info.ecid != ecid) { - mobiledevice_closepipes(_client); + win32_closepipes(_client); continue; } 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) free(details); _client->iBootPath = result; - if (mobiledevice_openpipes(_client) != IRECV_E_SUCCESS) { - mobiledevice_closepipes(_client); + if (win32_openpipes(_client) != IRECV_E_SUCCESS) { + win32_closepipes(_client); continue; } if ((ecid != 0) && (_client->mode == IRECV_K_WTF_MODE)) { /* we can't get ecid in WTF mode */ - mobiledevice_closepipes(_client); + win32_closepipes(_client); continue; } @@ -1237,7 +1278,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) } if (serial_str[0] == '\0') { - mobiledevice_closepipes(_client); + win32_closepipes(_client); continue; } @@ -1259,7 +1300,7 @@ irecv_error_t mobiledevice_connect(irecv_client_t* client, uint64_t ecid) if (ecid != 0) { if (_client->device_info.ecid != ecid) { - mobiledevice_closepipes(_client); + win32_closepipes(_client); continue; } 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) return IRECV_E_SUCCESS; } - -irecv_error_t mobiledevice_openpipes(irecv_client_t client) -{ - 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))) { - irecv_close(client); - return IRECV_E_UNABLE_TO_CONNECT; - } - - 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))) { - irecv_close(client); - return IRECV_E_UNABLE_TO_CONNECT; - } - - client->mode = 0; - if (client->iBootPath == NULL) { - if (strncmp(client->DfuPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { - sscanf(client->DfuPath+21, "%x#", &client->mode); - } - client->handle = client->hDFU; - } else { - if (strncmp(client->iBootPath, "\\\\?\\usb#vid_05ac&pid_", 21) == 0) { - sscanf(client->iBootPath+21, "%x#", &client->mode); - } - client->handle = client->hIB; - } - - if (client->mode == 0) { - irecv_close(client); - return IRECV_E_UNABLE_TO_CONNECT; - } - - return IRECV_E_SUCCESS; -} - -void mobiledevice_closepipes(irecv_client_t client) -{ - if (client->hDFU!=NULL) { - CloseHandle(client->hDFU); - client->hDFU = NULL; - } - if (client->hIB!=NULL) { - CloseHandle(client->hIB); - client->hIB = NULL; - } -} #endif #ifdef HAVE_IOKIT @@ -1856,7 +1852,7 @@ irecv_error_t irecv_open_with_ecid(irecv_client_t* pclient, uint64_t ecid) error = libusb_open_with_ecid(pclient, ecid); #endif #else - error = mobiledevice_connect(pclient, ecid); + error = win32_open_with_ecid(pclient, ecid); #endif irecv_client_t client = *pclient; if (error != IRECV_E_SUCCESS) { @@ -2987,7 +2983,7 @@ irecv_error_t irecv_close(irecv_client_t client) client->iBootPath = NULL; free(client->DfuPath); client->DfuPath = NULL; - mobiledevice_closepipes(client); + win32_closepipes(client); #endif free(client->device_info.srnm); free(client->device_info.imei); |