summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/lockdown.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/lockdown.h')
-rw-r--r--include/libimobiledevice/lockdown.h591
1 files changed, 531 insertions, 60 deletions
diff --git a/include/libimobiledevice/lockdown.h b/include/libimobiledevice/lockdown.h
index 97df6b0..21669ef 100644
--- a/include/libimobiledevice/lockdown.h
+++ b/include/libimobiledevice/lockdown.h
@@ -3,8 +3,10 @@
3 * @brief Manage device preferences, start services, pairing and activation. 3 * @brief Manage device preferences, start services, pairing and activation.
4 * \internal 4 * \internal
5 * 5 *
6 * Copyright (c) 2009-2014 Martin S. All Rights Reserved.
7 * Copyright (c) 2014 Koby Boyango All Rights Reserved.
8 * Copyright (c) 2010 Bryan Forbes All Rights Reserved.
6 * Copyright (c) 2008 Zach C. All Rights Reserved. 9 * Copyright (c) 2008 Zach C. All Rights Reserved.
7 * Copyright (c) 2009 Martin S. All Rights Reserved.
8 * 10 *
9 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public 12 * modify it under the terms of the GNU Lesser General Public
@@ -21,8 +23,8 @@
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */ 24 */
23 25
24#ifndef LOCKDOWN_H 26#ifndef ILOCKDOWN_H
25#define LOCKDOWN_H 27#define ILOCKDOWN_H
26 28
27#ifdef __cplusplus 29#ifdef __cplusplus
28extern "C" { 30extern "C" {
@@ -30,74 +32,543 @@ extern "C" {
30 32
31#include <libimobiledevice/libimobiledevice.h> 33#include <libimobiledevice/libimobiledevice.h>
32 34
33/** @name Error Codes */ 35/** Error Codes */
34/*@{*/ 36typedef enum {
35#define LOCKDOWN_E_SUCCESS 0 37 /* custom */
36#define LOCKDOWN_E_INVALID_ARG -1 38 LOCKDOWN_E_SUCCESS = 0,
37#define LOCKDOWN_E_INVALID_CONF -2 39 LOCKDOWN_E_INVALID_ARG = -1,
38#define LOCKDOWN_E_PLIST_ERROR -3 40 LOCKDOWN_E_INVALID_CONF = -2,
39#define LOCKDOWN_E_PAIRING_FAILED -4 41 LOCKDOWN_E_PLIST_ERROR = -3,
40#define LOCKDOWN_E_SSL_ERROR -5 42 LOCKDOWN_E_PAIRING_FAILED = -4,
41#define LOCKDOWN_E_DICT_ERROR -6 43 LOCKDOWN_E_SSL_ERROR = -5,
42#define LOCKDOWN_E_START_SERVICE_FAILED -7 44 LOCKDOWN_E_DICT_ERROR = -6,
43#define LOCKDOWN_E_NOT_ENOUGH_DATA -8 45 LOCKDOWN_E_RECEIVE_TIMEOUT = -7,
44#define LOCKDOWN_E_SET_VALUE_PROHIBITED -9 46 LOCKDOWN_E_MUX_ERROR = -8,
45#define LOCKDOWN_E_GET_VALUE_PROHIBITED -10 47 LOCKDOWN_E_NO_RUNNING_SESSION = -9,
46#define LOCKDOWN_E_REMOVE_VALUE_PROHIBITED -11 48 /* native */
47#define LOCKDOWN_E_MUX_ERROR -12 49 LOCKDOWN_E_INVALID_RESPONSE = -10,
48#define LOCKDOWN_E_ACTIVATION_FAILED -13 50 LOCKDOWN_E_MISSING_KEY = -11,
49#define LOCKDOWN_E_PASSWORD_PROTECTED -14 51 LOCKDOWN_E_MISSING_VALUE = -12,
50#define LOCKDOWN_E_NO_RUNNING_SESSION -15 52 LOCKDOWN_E_GET_PROHIBITED = -13,
51#define LOCKDOWN_E_INVALID_HOST_ID -16 53 LOCKDOWN_E_SET_PROHIBITED = -14,
52#define LOCKDOWN_E_INVALID_SERVICE -17 54 LOCKDOWN_E_REMOVE_PROHIBITED = -15,
53#define LOCKDOWN_E_INVALID_ACTIVATION_RECORD -18 55 LOCKDOWN_E_IMMUTABLE_VALUE = -16,
54 56 LOCKDOWN_E_PASSWORD_PROTECTED = -17,
55#define LOCKDOWN_E_UNKNOWN_ERROR -256 57 LOCKDOWN_E_USER_DENIED_PAIRING = -18,
56/*@}*/ 58 LOCKDOWN_E_PAIRING_DIALOG_RESPONSE_PENDING = -19,
57 59 LOCKDOWN_E_MISSING_HOST_ID = -20,
58/** Represents an error code. */ 60 LOCKDOWN_E_INVALID_HOST_ID = -21,
59typedef int16_t lockdownd_error_t; 61 LOCKDOWN_E_SESSION_ACTIVE = -22,
60 62 LOCKDOWN_E_SESSION_INACTIVE = -23,
61typedef struct lockdownd_client_private lockdownd_client_private; 63 LOCKDOWN_E_MISSING_SESSION_ID = -24,
64 LOCKDOWN_E_INVALID_SESSION_ID = -25,
65 LOCKDOWN_E_MISSING_SERVICE = -26,
66 LOCKDOWN_E_INVALID_SERVICE = -27,
67 LOCKDOWN_E_SERVICE_LIMIT = -28,
68 LOCKDOWN_E_MISSING_PAIR_RECORD = -29,
69 LOCKDOWN_E_SAVE_PAIR_RECORD_FAILED = -30,
70 LOCKDOWN_E_INVALID_PAIR_RECORD = -31,
71 LOCKDOWN_E_INVALID_ACTIVATION_RECORD = -32,
72 LOCKDOWN_E_MISSING_ACTIVATION_RECORD = -33,
73 LOCKDOWN_E_SERVICE_PROHIBITED = -34,
74 LOCKDOWN_E_ESCROW_LOCKED = -35,
75 LOCKDOWN_E_PAIRING_PROHIBITED_OVER_THIS_CONNECTION = -36,
76 LOCKDOWN_E_FMIP_PROTECTED = -37,
77 LOCKDOWN_E_MC_PROTECTED = -38,
78 LOCKDOWN_E_MC_CHALLENGE_REQUIRED = -39,
79 LOCKDOWN_E_UNKNOWN_ERROR = -256
80} lockdownd_error_t;
81
82typedef struct lockdownd_client_private lockdownd_client_private; /**< \private */
62typedef lockdownd_client_private *lockdownd_client_t; /**< The client handle. */ 83typedef lockdownd_client_private *lockdownd_client_t; /**< The client handle. */
63 84
64struct lockdownd_pair_record { 85struct lockdownd_pair_record {
65 char *device_certificate; /**< The device certificate */ 86 char *device_certificate; /**< The device certificate */
66 char *host_certificate; /**< The host certificate */ 87 char *host_certificate; /**< The host certificate */
67 char *host_id; /**< A unique HostID for the host computer */
68 char *root_certificate; /**< The root certificate */ 88 char *root_certificate; /**< The root certificate */
89 char *host_id; /**< A unique HostID for the host computer */
90 char *system_buid; /**< A unique system id */
69}; 91};
70/** A pair record holding device, host and root certificates along the host_id */ 92/** pair record holding device, host and root certificates along the host_id */
71typedef struct lockdownd_pair_record *lockdownd_pair_record_t; 93typedef struct lockdownd_pair_record *lockdownd_pair_record_t; /**< pair record */
94
95/** service descriptor */
96struct lockdownd_service_descriptor {
97 uint16_t port; /**< port number the service was started on */
98 uint8_t ssl_enabled; /**< an indicator if the service requires SSL */
99 char* identifier; /**< identifier of the service */
100};
101typedef struct lockdownd_service_descriptor *lockdownd_service_descriptor_t;
102
103/** Callback types used in #lockdownd_cu_pairing_cb_t */
104typedef enum {
105 LOCKDOWN_CU_PAIRING_PIN_REQUESTED, /**< PIN requested: data_ptr is a char* buffer, and data_size points to the size of this buffer that must not be exceeded and has to be updated to the actual number of characters filled into the buffer. */
106 LOCKDOWN_CU_PAIRING_DEVICE_INFO, /**< device information available: data_ptr is a plist_t, and data_size is ignored. The plist_t has to be copied if required, since it is freed when the callback function returns. */
107 LOCKDOWN_CU_PAIRING_ERROR /**< pairing error message available: data_ptr is a NULL-terminated char* buffer containing the error message, and data_size is ignored. Buffer needs to be copied if it shall persist outside the callback. */
108} lockdownd_cu_pairing_cb_type_t;
109
110/* CU pairing callback function prototype */
111/** Callback used to supply the pairing PIN during a CU pairing session,
112 * and to report device information and pairing error messages. */
113typedef void (*lockdownd_cu_pairing_cb_t) (lockdownd_cu_pairing_cb_type_t cb_type, void *user_data, void* data_ptr, unsigned int* data_size);
114
72 115
73/* Interface */ 116/* Interface */
74lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label); 117
75lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label); 118/**
76lockdownd_error_t lockdownd_client_free(lockdownd_client_t client); 119 * Creates a new lockdownd client for the device.
77 120 *
78lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type); 121 * @note This function does not pair with the device or start a session. This
79lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value); 122 * has to be done manually by the caller after the client is created.
80lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value); 123 * The device disconnects automatically if the lockdown connection idles
81lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key); 124 * for more than 10 seconds. Make sure to call lockdownd_client_free() as soon
82lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *service, uint16_t *port); 125 * as the connection is no longer needed.
83lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled); 126 *
84lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id); 127 * @param device The device to create a lockdownd client for
85lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist); 128 * @param client The pointer to the location of the new lockdownd_client
86lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist); 129 * @param label The label to use for communication. Usually the program name.
87lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); 130 *
88lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); 131 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL
89lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record); 132 */
90lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record); 133LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new(idevice_t device, lockdownd_client_t *client, const char *label);
91lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client); 134
92lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client); 135/**
93lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client); 136 * Creates a new lockdownd client for the device and starts initial handshake.
137 * The handshake consists out of query_type, validate_pair, pair and
138 * start_session calls. It uses the internal pairing record management.
139 *
140 * @note The device disconnects automatically if the lockdown connection idles
141 * for more than 10 seconds. Make sure to call lockdownd_client_free() as soon
142 * as the connection is no longer needed.
143 *
144 * @param device The device to create a lockdownd client for
145 * @param client The pointer to the location of the new lockdownd_client
146 * @param label The label to use for communication. Usually the program name.
147 * Pass NULL to disable sending the label in requests to lockdownd.
148 *
149 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL,
150 * LOCKDOWN_E_INVALID_CONF if configuration data is wrong
151 */
152LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_new_with_handshake(idevice_t device, lockdownd_client_t *client, const char *label);
153
154/**
155 * Closes the lockdownd client session if one is running and frees up the
156 * lockdownd_client struct.
157 *
158 * @param client The lockdown client
159 *
160 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL
161 */
162LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_client_free(lockdownd_client_t client);
163
164
165/**
166 * Query the type of the service daemon. Depending on whether the device is
167 * queried in normal mode or restore mode, different types will be returned.
168 *
169 * @param client The lockdownd client
170 * @param type The type returned by the service daemon. Pass NULL to ignore.
171 *
172 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL
173 */
174LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_query_type(lockdownd_client_t client, char **type);
175
176/**
177 * Retrieves a preferences plist using an optional domain and/or key name.
178 *
179 * @param client An initialized lockdownd client.
180 * @param domain The domain to query on or NULL for global domain
181 * @param key The key name to request or NULL to query for all keys
182 * @param value A plist node representing the result value node
183 *
184 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL
185 */
186LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value(lockdownd_client_t client, const char *domain, const char *key, plist_t *value);
187
188/**
189 * Sets a preferences value using a plist and optional by domain and/or key name.
190 *
191 * @param client an initialized lockdownd client.
192 * @param domain the domain to query on or NULL for global domain
193 * @param key the key name to set the value or NULL to set a value dict plist
194 * @param value a plist node of any node type representing the value to set
195 *
196 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or
197 * value is NULL
198 */
199LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_set_value(lockdownd_client_t client, const char *domain, const char *key, plist_t value);
200
201/**
202 * Removes a preference node by domain and/or key name.
203 *
204 * @note: Use with caution as this could remove vital information on the device
205 *
206 * @param client An initialized lockdownd client.
207 * @param domain The domain to query on or NULL for global domain
208 * @param key The key name to remove or NULL remove all keys for the current domain
209 *
210 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL
211 */
212LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_remove_value(lockdownd_client_t client, const char *domain, const char *key);
213
214/**
215 * Requests to start a service and retrieve it's port on success.
216 *
217 * @param client The lockdownd client
218 * @param identifier The identifier of the service to start
219 * @param service The service descriptor on success or NULL on failure
220 *
221 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if a parameter
222 * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known
223 * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not be
224 * started by the device
225 */
226LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_service(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service);
227
228/**
229 * Requests to start a service and retrieve it's port on success.
230 * Sends the escrow bag from the device's pair record.
231 *
232 * @param client The lockdownd client
233 * @param identifier The identifier of the service to start
234 * @param service The service descriptor on success or NULL on failure
235 *
236 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if a parameter
237 * is NULL, LOCKDOWN_E_INVALID_SERVICE if the requested service is not known
238 * by the device, LOCKDOWN_E_START_SERVICE_FAILED if the service could not because
239 * started by the device, LOCKDOWN_E_INVALID_CONF if the host id or escrow bag are
240 * missing from the device record.
241 */
242LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_service_with_escrow_bag(lockdownd_client_t client, const char *identifier, lockdownd_service_descriptor_t *service);
243
244/**
245 * Opens a session with lockdownd and switches to SSL mode if device wants it.
246 *
247 * @param client The lockdownd client
248 * @param host_id The HostID of the computer
249 * @param session_id The new session_id of the created session
250 * @param ssl_enabled Whether SSL communication is used in the session
251 *
252 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when a client
253 * or host_id is NULL, LOCKDOWN_E_PLIST_ERROR if the response plist had errors,
254 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the supplied HostID,
255 * LOCKDOWN_E_SSL_ERROR if enabling SSL communication failed
256 */
257LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_start_session(lockdownd_client_t client, const char *host_id, char **session_id, int *ssl_enabled);
258
259/**
260 * Closes the lockdownd session by sending the StopSession request.
261 *
262 * @see lockdownd_start_session
263 *
264 * @param client The lockdown client
265 * @param session_id The id of a running session
266 *
267 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL
268 */
269LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_stop_session(lockdownd_client_t client, const char *session_id);
270
271/**
272 * Sends a plist to lockdownd.
273 *
274 * @note This function is low-level and should only be used if you need to send
275 * a new type of message.
276 *
277 * @param client The lockdownd client
278 * @param plist The plist to send
279 *
280 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or
281 * plist is NULL
282 */
283LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_send(lockdownd_client_t client, plist_t plist);
284
285/**
286 * Receives a plist from lockdownd.
287 *
288 * @param client The lockdownd client
289 * @param plist The plist to store the received data
290 *
291 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or
292 * plist is NULL
293 */
294LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_receive(lockdownd_client_t client, plist_t *plist);
295
296/**
297 * Pairs the device using the supplied pair record.
298 *
299 * @param client The lockdown client
300 * @param pair_record The pair record to use for pairing. If NULL is passed, then
301 * the pair records from the current machine are used. New records will be
302 * generated automatically when pairing is done for the first time.
303 *
304 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL,
305 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
306 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
307 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
308 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
309 */
310LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record);
311
312 /**
313 * Pairs the device using the supplied pair record and passing the given options.
314 *
315 * @param client The lockdown client
316 * @param pair_record The pair record to use for pairing. If NULL is passed, then
317 * the pair records from the current machine are used. New records will be
318 * generated automatically when pairing is done for the first time.
319 * @param options The pairing options to pass. Can be NULL for no options.
320 * @param response If non-NULL a pointer to lockdownd's response dictionary is returned.
321 * The caller is responsible to free the response dictionary with plist_free().
322 *
323 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL,
324 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
325 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
326 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
327 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
328 */
329LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_with_options(lockdownd_client_t client, lockdownd_pair_record_t pair_record, plist_t options, plist_t *response);
330
331/**
332 * Validates if the device is paired with the given HostID. If successful the
333 * specified host will become trusted host of the device indicated by the
334 * lockdownd preference named TrustedHostAttached. Otherwise the host must be
335 * paired using lockdownd_pair() first.
336 *
337 * @param client The lockdown client
338 * @param pair_record The pair record to validate pairing with. If NULL is
339 * passed, then the pair record is read from the internal pairing record
340 * management.
341 *
342 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL,
343 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
344 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
345 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
346 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
347 */
348LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_validate_pair(lockdownd_client_t client, lockdownd_pair_record_t pair_record);
349
350/**
351 * Unpairs the device with the given HostID and removes the pairing records
352 * from the device and host if the internal pairing record management is used.
353 *
354 * @param client The lockdown client
355 * @param pair_record The pair record to use for unpair. If NULL is passed, then
356 * the pair records from the current machine are used.
357 *
358 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL,
359 * LOCKDOWN_E_PLIST_ERROR if the pair_record certificates are wrong,
360 * LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
361 * LOCKDOWN_E_PASSWORD_PROTECTED if the device is password protected,
362 * LOCKDOWN_E_INVALID_HOST_ID if the device does not know the caller's host id
363 */
364LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_unpair(lockdownd_client_t client, lockdownd_pair_record_t pair_record);
365
366/**
367 * Activates the device. Only works within an open session.
368 * The ActivationRecord plist dictionary must be obtained using the
369 * activation protocol requesting from Apple's https webservice.
370 *
371 * @param client The lockdown client
372 * @param activation_record The activation record plist dictionary
373 *
374 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client or
375 * activation_record is NULL, LOCKDOWN_E_NO_RUNNING_SESSION if no session is
376 * open, LOCKDOWN_E_PLIST_ERROR if the received plist is broken,
377 * LOCKDOWN_E_ACTIVATION_FAILED if the activation failed,
378 * LOCKDOWN_E_INVALID_ACTIVATION_RECORD if the device reports that the
379 * activation_record is invalid
380 */
381LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_activate(lockdownd_client_t client, plist_t activation_record);
382
383/**
384 * Deactivates the device, returning it to the locked “Activate with iTunes”
385 * screen.
386 *
387 * @param client The lockdown client
388 *
389 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL,
390 * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open,
391 * LOCKDOWN_E_PLIST_ERROR if the received plist is broken
392 */
393LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_deactivate(lockdownd_client_t client);
394
395/**
396 * Tells the device to immediately enter recovery mode.
397 *
398 * @param client The lockdown client
399 *
400 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client is NULL
401 */
402LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_enter_recovery(lockdownd_client_t client);
403
404/**
405 * Sends the Goodbye request to lockdownd signaling the end of communication.
406 *
407 * @param client The lockdown client
408 *
409 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client
410 * is NULL, LOCKDOWN_E_PLIST_ERROR if the device did not acknowledge the
411 * request
412 */
413LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_goodbye(lockdownd_client_t client);
414
415/**
416 * Creates a CU pairing session for the current lockdown client.
417 * This is required to allow lockdownd_cu_send_request_and_get_reply(),
418 * lockdownd_get_value_cu() and lockdonwd_pair_cu() requests, and eventually
419 * allows to perform an actual wireless pairing.
420 *
421 * Through the callback function, the PIN displayed on the device has to be
422 * supplied during the process. Currently, only AppleTV devices have this
423 * capability.
424 *
425 * @param client The lockdown client to perform the CU pairing for
426 * @param pairing_callback Callback function that is used to supply the PIN
427 * for the pairing process, but also to receive device information or
428 * pairing error messages.
429 * @param cb_user_data User data that will be passed as additional argument
430 * to the callback function.
431 * @param host_info (Optional) A dictionary containing host information to
432 * send to the device when finalizing the CU pairing. The supplied
433 * values will override the default values gathered for the current host.
434 * @param acl (Optional) A dictionary containing ACL information. Currently
435 * only com.apple.ScreenCapture:true and com.apple.developer:true are known
436 * valid ACL values, which are used as default when NULL is passed.
437 *
438 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if one of the
439 * parameters is invalid, LOCKDOWN_E_PAIRING_FAILED if the pairing failed,
440 * or a LOCKDOWN_E_* error code otherwise.
441 */
442LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_pairing_create(lockdownd_client_t client, lockdownd_cu_pairing_cb_t pairing_callback, void* cb_user_data, plist_t host_info, plist_t acl);
443
444/**
445 * Sends a request via lockdown client with established CU pairing session
446 * and attempts to retrieve a reply. This function is used internally
447 * by lockdownd_get_value_cu() and lockdownd_pair_cu(), but exposed here to
448 * allow custom requests being sent and their replies being received.
449 *
450 * @param client A lockdown client with an established CU pairing.
451 * @param request The request to perform.
452 * @param request_payload The payload for the request.
453 * @param reply (Optional) If not NULL, the plist_t will be set to the reply
454 * dictionary that has been received. Consumer is responsible to free it
455 * using plist_free() when no longer required.
456 *
457 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if one of the
458 * parameters is invalid, LOCKDOWN_E_NO_RUNNING_SESSION if the current
459 * lockdown client does not have an established CU pairing session,
460 * or a LOCKDOWN_E_* error code otherwise.
461 */
462LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_cu_send_request_and_get_reply(lockdownd_client_t client, const char* request, plist_t request_payload, plist_t* reply);
463
464/**
465 * Retrieves a value using an optional domain and/or key name from a lockdown
466 * client with established CU pairing session.
467 *
468 * This is used to retrieve values that are only accessible after a CU pairing
469 * has been established, and would otherwise only be accessible with a valid
470 * device pairing.
471 *
472 * @param client A lockdown client with an established CU pairing.
473 * @param domain The domain to query on or NULL for global domain
474 * @param key The key name to request or NULL to query for all keys
475 * @param value A plist node representing the result value node
476 *
477 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG if one of the
478 * parameters is invalid, LOCKDOWN_E_NO_RUNNING_SESSION if the current
479 * lockdown client does not have an established CU pairing session,
480 * or a LOCKDOWN_E_* error code otherwise.
481 */
482LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_value_cu(lockdownd_client_t client, const char* domain, const char* key, plist_t* value);
483
484/**
485 * Perform a device pairing with a lockdown client that has an established
486 * CU pairing session.
487 *
488 * @param client A lockdown client with an established CU pairing.
489 *
490 * @return LOCKDOWN_E_SUCCESS on success, LOCKDOWN_E_INVALID_ARG when client
491 * is NULL, LOCKDOWN_E_NO_RUNNING_SESSION if the current lockdown client
492 * does not have an established CU pairing session, or a LOCKDOWN_E_* error
493 * code otherwise.
494 */
495LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_pair_cu(lockdownd_client_t client);
496
94 497
95/* Helper */ 498/* Helper */
96void lockdownd_client_set_label(lockdownd_client_t client, const char *label); 499
97lockdownd_error_t lockdownd_get_device_uuid(lockdownd_client_t control, char **uuid); 500/**
98lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name); 501 * Sets the label to send for requests to lockdownd.
99lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count); 502 *
100lockdownd_error_t lockdownd_data_classes_free(char **classes); 503 * @param client The lockdown client
504 * @param label The label to set or NULL to disable sending a label
505 *
506 */
507LIBIMOBILEDEVICE_API void lockdownd_client_set_label(lockdownd_client_t client, const char *label);
508
509/**
510 * Returns the unique id of the device from lockdownd.
511 *
512 * @param client An initialized lockdownd client.
513 * @param udid Holds the unique id of the device. The caller is responsible
514 * for freeing the memory.
515 *
516 * @return LOCKDOWN_E_SUCCESS on success
517 */
518LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_device_udid(lockdownd_client_t client, char **udid);
519
520/**
521 * Retrieves the name of the device from lockdownd set by the user.
522 *
523 * @param client An initialized lockdownd client.
524 * @param device_name Holds the name of the device. The caller is
525 * responsible for freeing the memory.
526 *
527 * @return LOCKDOWN_E_SUCCESS on success
528 */
529LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_device_name(lockdownd_client_t client, char **device_name);
530
531/**
532 * Calculates and returns the data classes the device supports from lockdownd.
533 *
534 * @param client An initialized lockdownd client.
535 * @param classes A pointer to store an array of class names. The caller is responsible
536 * for freeing the memory which can be done using mobilesync_data_classes_free().
537 * @param count The number of items in the classes array.
538 *
539 * @return LOCKDOWN_E_SUCCESS on success,
540 * LOCKDOWN_E_INVALID_ARG when client is NULL,
541 * LOCKDOWN_E_NO_RUNNING_SESSION if no session is open,
542 * LOCKDOWN_E_PLIST_ERROR if the received plist is broken
543 */
544LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_get_sync_data_classes(lockdownd_client_t client, char ***classes, int *count);
545
546/**
547 * Frees memory of an allocated array of data classes as returned by lockdownd_get_sync_data_classes()
548 *
549 * @param classes An array of class names to free.
550 *
551 * @return LOCKDOWN_E_SUCCESS on success
552 */
553LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_data_classes_free(char **classes);
554
555/**
556 * Frees memory of a service descriptor as returned by lockdownd_start_service()
557 *
558 * @param service A service descriptor instance to free.
559 *
560 * @return LOCKDOWN_E_SUCCESS on success
561 */
562LIBIMOBILEDEVICE_API lockdownd_error_t lockdownd_service_descriptor_free(lockdownd_service_descriptor_t service);
563
564/**
565 * Gets a readable error string for a given lockdown error code.
566 *
567 * @param err A lockdownd error code
568 *
569 * @returns A readable error string
570 */
571LIBIMOBILEDEVICE_API const char* lockdownd_strerror(lockdownd_error_t err);
101 572
102#ifdef __cplusplus 573#ifdef __cplusplus
103} 574}