diff options
Diffstat (limited to 'include/libimobiledevice/preboard.h')
| -rw-r--r-- | include/libimobiledevice/preboard.h | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/include/libimobiledevice/preboard.h b/include/libimobiledevice/preboard.h new file mode 100644 index 0000000..0d89eb4 --- /dev/null +++ b/include/libimobiledevice/preboard.h | |||
| @@ -0,0 +1,187 @@ | |||
| 1 | /** | ||
| 2 | * @file libimobiledevice/preboard.h | ||
| 3 | * @brief Service to 'preboard' a device, which allows to ask for passcode during firmware updates. | ||
| 4 | * \internal | ||
| 5 | * | ||
| 6 | * Copyright (c) 2019 Nikias Bassen, All Rights Reserved. | ||
| 7 | * | ||
| 8 | * This library is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU Lesser General Public | ||
| 10 | * License as published by the Free Software Foundation; either | ||
| 11 | * version 2.1 of the License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This library is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 16 | * Lesser General Public License for more details. | ||
| 17 | * | ||
| 18 | * You should have received a copy of the GNU Lesser General Public | ||
| 19 | * License along with this library; if not, write to the Free Software | ||
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 21 | */ | ||
| 22 | |||
| 23 | #ifndef IPREBOARD_H | ||
| 24 | #define IPREBOARD_H | ||
| 25 | |||
| 26 | #ifdef __cplusplus | ||
| 27 | extern "C" { | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #include <libimobiledevice/libimobiledevice.h> | ||
| 31 | #include <libimobiledevice/lockdown.h> | ||
| 32 | |||
| 33 | /** Service identifier passed to lockdownd_start_service() to start the preboard service */ | ||
| 34 | #define PREBOARD_SERVICE_NAME "com.apple.preboardservice_v2" | ||
| 35 | |||
| 36 | /** Error Codes */ | ||
| 37 | typedef enum { | ||
| 38 | PREBOARD_E_SUCCESS = 0, | ||
| 39 | PREBOARD_E_INVALID_ARG = -1, | ||
| 40 | PREBOARD_E_PLIST_ERROR = -2, | ||
| 41 | PREBOARD_E_MUX_ERROR = -3, | ||
| 42 | PREBOARD_E_SSL_ERROR = -4, | ||
| 43 | PREBOARD_E_NOT_ENOUGH_DATA = -5, | ||
| 44 | PREBOARD_E_TIMEOUT = -6, | ||
| 45 | PREBOARD_E_OP_IN_PROGRESS = -10, | ||
| 46 | PREBOARD_E_UNKNOWN_ERROR = -256 | ||
| 47 | } preboard_error_t; | ||
| 48 | |||
| 49 | typedef struct preboard_client_private preboard_client_private; /**< \private */ | ||
| 50 | typedef preboard_client_private *preboard_client_t; /**< The client handle. */ | ||
| 51 | |||
| 52 | /** Reports the status response of the given command */ | ||
| 53 | typedef void (*preboard_status_cb_t) (plist_t message, void *user_data); | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Connects to the preboard service on the specified device. | ||
| 57 | * | ||
| 58 | * @param device The device to connect to. | ||
| 59 | * @param service The service descriptor returned by lockdownd_start_service. | ||
| 60 | * @param client Pointer that will point to a newly allocated | ||
| 61 | * preboard_client_t upon successful return. Must be freed using | ||
| 62 | * preboard_client_free() after use. | ||
| 63 | * | ||
| 64 | * @return PREBOARD_E_SUCCESS on success, PREBOARD_E_INVALID_ARG when | ||
| 65 | * client is NULL, or an PREBOARD_E_* error code otherwise. | ||
| 66 | */ | ||
| 67 | LIBIMOBILEDEVICE_API preboard_error_t preboard_client_new(idevice_t device, lockdownd_service_descriptor_t service, preboard_client_t * client); | ||
| 68 | |||
| 69 | /** | ||
| 70 | * Starts a new preboard service on the specified device and connects to it. | ||
| 71 | * | ||
| 72 | * @param device The device to connect to. | ||
| 73 | * @param client Pointer that will point to a newly allocated | ||
| 74 | * preboard_client_t upon successful return. Must be freed using | ||
| 75 | * preboard_client_free() after use. | ||
| 76 | * @param label The label to use for communication. Usually the program name. | ||
| 77 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
| 78 | * | ||
| 79 | * @return PREBOARD_E_SUCCESS on success, or a PREBOARD_E_* error | ||
| 80 | * code otherwise. | ||
| 81 | */ | ||
| 82 | LIBIMOBILEDEVICE_API preboard_error_t preboard_client_start_service(idevice_t device, preboard_client_t * client, const char* label); | ||
| 83 | |||
| 84 | /** | ||
| 85 | * Disconnects a preboard client from the device and frees up the | ||
| 86 | * preboard client data. | ||
| 87 | * | ||
| 88 | * @param client The preboard client to disconnect and free. | ||
| 89 | * | ||
| 90 | * @return PREBOARD_E_SUCCESS on success, PREBOARD_E_INVALID_ARG when | ||
| 91 | * client is NULL, or a PREBOARD_E_* error code otherwise. | ||
| 92 | */ | ||
| 93 | LIBIMOBILEDEVICE_API preboard_error_t preboard_client_free(preboard_client_t client); | ||
| 94 | |||
| 95 | /** | ||
| 96 | * Sends a plist to the service. | ||
| 97 | * | ||
| 98 | * @param client The preboard client | ||
| 99 | * @param plist The plist to send | ||
| 100 | * | ||
| 101 | * @return PREBOARD_E_SUCCESS on success, | ||
| 102 | * PREBOARD_E_INVALID_ARG when client or plist is NULL, | ||
| 103 | * or a PREBOARD_E_* error code on error | ||
| 104 | */ | ||
| 105 | LIBIMOBILEDEVICE_API preboard_error_t preboard_send(preboard_client_t client, plist_t plist); | ||
| 106 | |||
| 107 | /** | ||
| 108 | * Receives a plist from the service. | ||
| 109 | * | ||
| 110 | * @param client The preboard client | ||
| 111 | * @param plist Pointer to a plist_t what will be set to the received plist | ||
| 112 | * | ||
| 113 | * @return PREBOARD_E_SUCCESS on success, | ||
| 114 | * PREBOARD_E_INVALID_ARG when client or plist is NULL, | ||
| 115 | * PREBOARD_E_TIMEOUT when no data was received after 5 seconds, | ||
| 116 | * or a PREBOARD_E_* error code on error | ||
| 117 | */ | ||
| 118 | LIBIMOBILEDEVICE_API preboard_error_t preboard_receive(preboard_client_t client, plist_t * plist); | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Receives a plist from the service with the specified timeout. | ||
| 122 | * | ||
| 123 | * @param client The preboard client | ||
| 124 | * @param plist Pointer to a plist_t what will be set to the received plist | ||
| 125 | * @param timeout_ms Timeout in milliseconds | ||
| 126 | * | ||
| 127 | * @return PREBOARD_E_SUCCESS on success, | ||
| 128 | * PREBOARD_E_INVALID_ARG when client or plist is NULL, | ||
| 129 | * PREBOARD_E_TIMEOUT when no data was received after the given timeout, | ||
| 130 | * or a PREBOARD_E_* error code on error. | ||
| 131 | */ | ||
| 132 | LIBIMOBILEDEVICE_API preboard_error_t preboard_receive_with_timeout(preboard_client_t client, plist_t * plist, uint32_t timeout_ms); | ||
| 133 | |||
| 134 | /** | ||
| 135 | * Tells the preboard service to create a stashbag. This will make the device | ||
| 136 | * show a passcode entry so it can generate and store a token that is later | ||
| 137 | * used during restore. | ||
| 138 | * | ||
| 139 | * @param client The preboard client | ||
| 140 | * @param manifest An optional manifest | ||
| 141 | * @param status_cb Callback function that will receive status and error messages. | ||
| 142 | * Can be NULL if you want to handle receiving messages in your own code. | ||
| 143 | * @param user_data User data for callback function or NULL. | ||
| 144 | * | ||
| 145 | * The callback or following preboard_receive* invocations will usually | ||
| 146 | * receive a dictionary with: | ||
| 147 | * { ShowDialog: true } | ||
| 148 | * If the user does not enter a passcode, after 2 minutes a timeout is reached | ||
| 149 | * and the device sends a dictionary with: | ||
| 150 | * { Timeout: true } | ||
| 151 | * followed by { HideDialog: true } | ||
| 152 | * If the user aborts the passcode entry, the device sends a dictionary: | ||
| 153 | * { Error: 1, ErrorString: \<error string\> } | ||
| 154 | * followed by { HideDialog: true } | ||
| 155 | * | ||
| 156 | * @return PREBOARD_E_SUCCESS if the command was successfully submitted, | ||
| 157 | * PREBOARD_E_INVALID_ARG when client is invalid, | ||
| 158 | * or a PREBOARD_E_* error code on error. | ||
| 159 | */ | ||
| 160 | LIBIMOBILEDEVICE_API preboard_error_t preboard_create_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data); | ||
| 161 | |||
| 162 | /** | ||
| 163 | * Instructs the preboard service to commit a previously created stashbag. | ||
| 164 | * | ||
| 165 | * @param client The preboard client to use for receiving | ||
| 166 | * @param manifest An optional manifest | ||
| 167 | * @param status_cb Callback function that will receive status and error messages | ||
| 168 | * Can be NULL if you want to handle receiving messages in your own code. | ||
| 169 | * @param user_data User data for callback function or NULL. | ||
| 170 | * | ||
| 171 | * The callback or following preboard_receive* invocations will usually | ||
| 172 | * receive a dictionary with: | ||
| 173 | * { StashbagCommitComplete: true } | ||
| 174 | * or in case of an error: | ||
| 175 | * { StashbagCommitComplete: 0, Error: 1, \<optional\> ErrorString: \<error string\> } | ||
| 176 | * | ||
| 177 | * @return PREBOARD_E_SUCCESS if the command was successfully submitted, | ||
| 178 | * PREBOARD_E_INVALID_ARG when client is invalid, | ||
| 179 | * or a PREBOARD_E_* error code on error. | ||
| 180 | */ | ||
| 181 | LIBIMOBILEDEVICE_API preboard_error_t preboard_commit_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data); | ||
| 182 | |||
| 183 | #ifdef __cplusplus | ||
| 184 | } | ||
| 185 | #endif | ||
| 186 | |||
| 187 | #endif | ||
