summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/preboard.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/preboard.h')
-rw-r--r--include/libimobiledevice/preboard.h168
1 files changed, 168 insertions, 0 deletions
diff --git a/include/libimobiledevice/preboard.h b/include/libimobiledevice/preboard.h
new file mode 100644
index 0000000..dc4e5f3
--- /dev/null
+++ b/include/libimobiledevice/preboard.h
@@ -0,0 +1,168 @@
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
27extern "C" {
28#endif
29
30#include <libimobiledevice/libimobiledevice.h>
31#include <libimobiledevice/lockdown.h>
32
33#define PREBOARD_SERVICE_NAME "com.apple.preboardservice_v2"
34
35/** Error Codes */
36typedef enum {
37 PREBOARD_E_SUCCESS = 0,
38 PREBOARD_E_INVALID_ARG = -1,
39 PREBOARD_E_PLIST_ERROR = -2,
40 PREBOARD_E_MUX_ERROR = -3,
41 PREBOARD_E_SSL_ERROR = -4,
42 PREBOARD_E_NOT_ENOUGH_DATA = -5,
43 PREBOARD_E_TIMEOUT = -6,
44 PREBOARD_E_OP_IN_PROGRESS = -10,
45 PREBOARD_E_UNKNOWN_ERROR = -256
46} preboard_error_t;
47
48typedef struct preboard_client_private preboard_client_private;
49typedef preboard_client_private *preboard_client_t; /**< The client handle. */
50
51/** Reports the status response of the given command */
52typedef void (*preboard_status_cb_t) (plist_t message, void *user_data);
53
54/**
55 * Connects to the preboard service on the specified device.
56 *
57 * @param device The device to connect to.
58 * @param service The service descriptor returned by lockdownd_start_service.
59 * @param client Pointer that will point to a newly allocated
60 * preboard_client_t upon successful return. Must be freed using
61 * preboard_client_free() after use.
62 *
63 * @return PREBOARD_E_SUCCESS on success, PREBOARD_E_INVALID_ARG when
64 * client is NULL, or an PREBOARD_E_* error code otherwise.
65 */
66preboard_error_t preboard_client_new(idevice_t device, lockdownd_service_descriptor_t service, preboard_client_t * client);
67
68/**
69 * Starts a new preboard service on the specified device and connects to it.
70 *
71 * @param device The device to connect to.
72 * @param client Pointer that will point to a newly allocated
73 * preboard_client_t upon successful return. Must be freed using
74 * preboard_client_free() after use.
75 * @param label The label to use for communication. Usually the program name.
76 * Pass NULL to disable sending the label in requests to lockdownd.
77 *
78 * @return PREBOARD_E_SUCCESS on success, or a PREBOARD_E_* error
79 * code otherwise.
80 */
81preboard_error_t preboard_client_start_service(idevice_t device, preboard_client_t * client, const char* label);
82
83/**
84 * Disconnects a preboard client from the device and frees up the
85 * preboard client data.
86 *
87 * @param client The preboard client to disconnect and free.
88 *
89 * @return PREBOARD_E_SUCCESS on success, PREBOARD_E_INVALID_ARG when
90 * client is NULL, or a PREBOARD_E_* error code otherwise.
91 */
92preboard_error_t preboard_client_free(preboard_client_t client);
93
94/**
95 * Sends a plist to the service.
96 *
97 * @param client The preboard client
98 * @param plist The plist to send
99 *
100 * @return PREBOARD_E_SUCCESS on success,
101 * PREBOARD_E_INVALID_ARG when client or plist is NULL,
102 * or a PREBOARD_E_* error code on error
103 */
104preboard_error_t preboard_send(preboard_client_t client, plist_t plist);
105
106/**
107 * Receives a plist from the service.
108 *
109 * @param client The preboard client
110 * @param plist Pointer to a plist_t what will be set to the received plist
111 *
112 * @return PREBOARD_E_SUCCESS on success,
113 * PREBOARD_E_INVALID_ARG when client or plist is NULL,
114 * PREBOARD_E_TIMEOUT when no data was received after 5 seconds,
115 * or a PREBOARD_E_* error code on error
116 */
117preboard_error_t preboard_receive(preboard_client_t client, plist_t * plist);
118
119/**
120 * Receives a plist from the service with the specified timeout.
121 *
122 * @param client The preboard client
123 * @param plist Pointer to a plist_t what will be set to the received plist
124 *
125 * @return PREBOARD_E_SUCCESS on success,
126 * PREBOARD_E_INVALID_ARG when client or plist is NULL,
127 * PREBOARD_E_TIMEOUT when no data was received after the given timeout,
128 * or a PREBOARD_E_* error code on error.
129 */
130preboard_error_t preboard_receive_with_timeout(preboard_client_t client, plist_t * plist, uint32_t timeout_ms);
131
132/**
133 * Tells the preboard service to create a stashbag. This will make the device
134 * show a passcode entry so it can generate and store a token that is later
135 * used during restore.
136 *
137 * @param client The preboard client
138 * @param manifest An optional manifest
139 * @param status_cb Callback function that will receive status and error messages.
140 * Can be NULL if you want to handle receiving messages in your own code.
141 * @param user_data User data for callback function or NULL.
142 *
143 * @return PREBOARD_E_SUCCESS if the command was successfully submitted,
144 * PREBOARD_E_INVALID_ARG when client is invalid,
145 * or a PREBOARD_E_* error code on error.
146 */
147preboard_error_t preboard_create_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data);
148
149/**
150 * Instructs the preboard service to commit a previously created stashbag.
151 *
152 * @param client The preboard client to use for receiving
153 * @param manifest An optional manifest
154 * @param status_cb Callback function that will receive status and error messages
155 * Can be NULL if you want to handle receiving messages in your own code.
156 * @param user_data User data for callback function or NULL.
157 *
158 * @return PREBOARD_E_SUCCESS if the command was successfully submitted,
159 * PREBOARD_E_INVALID_ARG when client is invalid,
160 * or a PREBOARD_E_* error code on error.
161 */
162preboard_error_t preboard_commit_stashbag(preboard_client_t client, plist_t manifest, preboard_status_cb_t status_cb, void *user_data);
163
164#ifdef __cplusplus
165}
166#endif
167
168#endif