summaryrefslogtreecommitdiffstats
path: root/include/libimobiledevice/libimobiledevice.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libimobiledevice/libimobiledevice.h')
-rw-r--r--include/libimobiledevice/libimobiledevice.h390
1 files changed, 349 insertions, 41 deletions
diff --git a/include/libimobiledevice/libimobiledevice.h b/include/libimobiledevice/libimobiledevice.h
index d0923d6..a9d270b 100644
--- a/include/libimobiledevice/libimobiledevice.h
+++ b/include/libimobiledevice/libimobiledevice.h
@@ -3,25 +3,28 @@
3 * @brief Device/Connection handling and communication 3 * @brief Device/Connection handling and communication
4 * \internal 4 * \internal
5 * 5 *
6 * Copyright (c) 2010-2019 Nikias Bassen All Rights Reserved.
7 * Copyright (c) 2010-2014 Martin Szulecki All Rights Reserved.
8 * Copyright (c) 2014 Christophe Fergeau All Rights Reserved.
6 * Copyright (c) 2008 Jonathan Beck All Rights Reserved. 9 * Copyright (c) 2008 Jonathan Beck All Rights Reserved.
7 * 10 *
8 * This library is free software; you can redistribute it and/or 11 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 12 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 13 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version. 14 * version 2.1 of the License, or (at your option) any later version.
12 * 15 *
13 * This library is distributed in the hope that it will be useful, 16 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details. 19 * Lesser General Public License for more details.
17 * 20 *
18 * You should have received a copy of the GNU Lesser General Public 21 * 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 22 * 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 23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */ 24 */
22 25
23#ifndef LIBIMOBILEDEVICE_H 26#ifndef IMOBILEDEVICE_H
24#define LIBIMOBILEDEVICE_H 27#define IMOBILEDEVICE_H
25 28
26#ifdef __cplusplus 29#ifdef __cplusplus
27extern "C" { 30extern "C" {
@@ -32,72 +35,377 @@ extern "C" {
32#include <sys/stat.h> 35#include <sys/stat.h>
33#include <plist/plist.h> 36#include <plist/plist.h>
34 37
35/** @name Error Codes */ 38#ifndef LIBIMOBILEDEVICE_API
36/*@{*/ 39 #ifdef LIBIMOBILEDEVICE_STATIC
37#define IDEVICE_E_SUCCESS 0 40 #define LIBIMOBILEDEVICE_API
38#define IDEVICE_E_INVALID_ARG -1 41 #elif defined(_WIN32)
39#define IDEVICE_E_UNKNOWN_ERROR -2 42 #define LIBIMOBILEDEVICE_API __declspec(dllimport)
40#define IDEVICE_E_NO_DEVICE -3 43 #else
41#define IDEVICE_E_NOT_ENOUGH_DATA -4 44 #define LIBIMOBILEDEVICE_API
42#define IDEVICE_E_BAD_HEADER -5 45 #endif
43#define IDEVICE_E_SSL_ERROR -6 46#endif
44/*@}*/ 47
45 48/** Error Codes */
46/** Represents an error code. */ 49typedef enum {
47typedef int16_t idevice_error_t; 50 IDEVICE_E_SUCCESS = 0,
48 51 IDEVICE_E_INVALID_ARG = -1,
49typedef struct idevice_private idevice_private; 52 IDEVICE_E_UNKNOWN_ERROR = -2,
53 IDEVICE_E_NO_DEVICE = -3,
54 IDEVICE_E_NOT_ENOUGH_DATA = -4,
55 IDEVICE_E_CONNREFUSED = -5,
56 IDEVICE_E_SSL_ERROR = -6,
57 IDEVICE_E_TIMEOUT = -7
58} idevice_error_t;
59
60typedef struct idevice_private idevice_private; /**< \private */
50typedef idevice_private *idevice_t; /**< The device handle. */ 61typedef idevice_private *idevice_t; /**< The device handle. */
51 62
52typedef struct idevice_connection_private idevice_connection_private; 63typedef struct idevice_connection_private idevice_connection_private; /**< \private */
53typedef idevice_connection_private *idevice_connection_t; /**< The connection handle. */ 64typedef idevice_connection_private *idevice_connection_t; /**< The connection handle. */
54 65
55/* generic */ 66/** Options for idevice_new_with_options() */
56void idevice_set_debug_level(int level); 67enum idevice_options {
68 IDEVICE_LOOKUP_USBMUX = 1 << 1, /**< include USBMUX devices during lookup */
69 IDEVICE_LOOKUP_NETWORK = 1 << 2, /**< include network devices during lookup */
70 IDEVICE_LOOKUP_PREFER_NETWORK = 1 << 3 /**< prefer network connection if device is available via USBMUX *and* network */
71};
72
73/** Type of connection a device is available on */
74enum idevice_connection_type {
75 CONNECTION_USBMUXD = 1, /**< device is available via USBMUX */
76 CONNECTION_NETWORK /**< device is available via network */
77};
78
79/** Device information returned by #idevice_get_device_list_extended API */
80struct idevice_info {
81 char *udid; /**< UDID of the device */
82 enum idevice_connection_type conn_type; /**< Type of connection the device is available on */
83 void* conn_data; /**< Connection data, depending on the connection type */
84};
85typedef struct idevice_info* idevice_info_t;
57 86
58/* discovery (events/asynchronous) */ 87/* discovery (events/asynchronous) */
59/** The event type for device add or removal */ 88/** The event type for device add or removal */
60enum idevice_event_type { 89enum idevice_event_type {
61 IDEVICE_DEVICE_ADD = 1, 90 IDEVICE_DEVICE_ADD = 1, /**< device was added */
62 IDEVICE_DEVICE_REMOVE 91 IDEVICE_DEVICE_REMOVE, /**< device was removed */
92 IDEVICE_DEVICE_PAIRED /**< device completed pairing process */
63}; 93};
64 94
65/* event data structure */ 95/* event data structure */
66/** Provides information about the occured event. */ 96/** Provides information about the occurred event. */
67typedef struct { 97typedef struct {
68 enum idevice_event_type event; /**< The event type. */ 98 enum idevice_event_type event; /**< The event type. */
69 const char *uuid; /**< The device unique id. */ 99 const char *udid; /**< The device unique id. */
70 int conn_type; /**< The connection type. Currently only 1 for usbmuxd. */ 100 enum idevice_connection_type conn_type; /**< The connection type. */
71} idevice_event_t; 101} idevice_event_t;
72 102
73/* event callback function prototype */ 103/* event callback function prototype */
74/** Callback to notifiy if a device was added or removed. */ 104/** Callback to notifiy if a device was added or removed. */
75typedef void (*idevice_event_cb_t) (const idevice_event_t *event, void *user_data); 105typedef void (*idevice_event_cb_t) (const idevice_event_t *event, void *user_data);
76 106
107/** Event subscription context type */
108typedef struct idevice_subscription_context* idevice_subscription_context_t;
109
77/* functions */ 110/* functions */
78idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data); 111
79idevice_error_t idevice_event_unsubscribe(); 112/**
113 * Set the level of debugging.
114 *
115 * @param level Set to 0 for no debug output or 1 to enable debug output.
116 */
117LIBIMOBILEDEVICE_API void idevice_set_debug_level(int level);
118
119/**
120 * Subscribe a callback function that will be called when device add/remove
121 * events occur.
122 *
123 * @param context A pointer to a idevice_subscription_context_t that will be
124 * set upon creation of the subscription. The returned context must be
125 * passed to idevice_events_unsubscribe() to unsubscribe the callback.
126 * @param callback Callback function to call.
127 * @param user_data Application-specific data passed as parameter
128 * to the registered callback function.
129 *
130 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
131 */
132LIBIMOBILEDEVICE_API idevice_error_t idevice_events_subscribe(idevice_subscription_context_t *context, idevice_event_cb_t callback, void *user_data);
133
134/**
135 * Unsubscribe the event callback function that has been registered with
136 * idevice_events_subscribe().
137 *
138 * @param context A valid context as returned from idevice_events_subscribe().
139 *
140 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
141 */
142LIBIMOBILEDEVICE_API idevice_error_t idevice_events_unsubscribe(idevice_subscription_context_t context);
143
144/**
145 * (DEPRECATED) Register a callback function that will be called when device add/remove
146 * events occur.
147 *
148 * @deprecated Use idevice_events_subscribe() instead.
149 *
150 * @param callback Callback function to call.
151 * @param user_data Application-specific data passed as parameter
152 * to the registered callback function.
153 *
154 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
155 */
156LIBIMOBILEDEVICE_API idevice_error_t idevice_event_subscribe(idevice_event_cb_t callback, void *user_data);
157
158/**
159 * (DEPRECATED) Release the event callback function that has been registered with
160 * idevice_event_subscribe().
161 *
162 * @deprecated Use idevice_events_unsubscribe() instead.
163 *
164 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
165 */
166LIBIMOBILEDEVICE_API idevice_error_t idevice_event_unsubscribe(void);
80 167
81/* discovery (synchronous) */ 168/* discovery (synchronous) */
82idevice_error_t idevice_get_device_list(char ***devices, int *count); 169
83idevice_error_t idevice_device_list_free(char **devices); 170/**
171 * Get a list of UDIDs of currently available devices (USBMUX devices only).
172 *
173 * @param devices List of UDIDs of devices that are currently available.
174 * This list is terminated by a NULL pointer.
175 * @param count Number of devices found.
176 *
177 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
178 *
179 * @note This function only returns the UDIDs of USBMUX devices. To also include
180 * network devices in the list, use idevice_get_device_list_extended().
181 * @see idevice_get_device_list_extended
182 */
183LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list(char ***devices, int *count);
184
185/**
186 * Free a list of device UDIDs.
187 *
188 * @param devices List of UDIDs to free.
189 *
190 * @return Always returnes IDEVICE_E_SUCCESS.
191 */
192LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_free(char **devices);
193
194/**
195 * Get a list of currently available devices
196 *
197 * @param devices List of idevice_info_t records with device information.
198 * This list is terminated by a NULL pointer.
199 * @param count Number of devices included in the list.
200 *
201 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
202 */
203LIBIMOBILEDEVICE_API idevice_error_t idevice_get_device_list_extended(idevice_info_t **devices, int *count);
204
205/**
206 * Free an extended device list retrieved through idevice_get_device_list_extended().
207 *
208 * @param devices Device list to free.
209 *
210 * @return IDEVICE_E_SUCCESS on success or an error value when an error occurred.
211 */
212LIBIMOBILEDEVICE_API idevice_error_t idevice_device_list_extended_free(idevice_info_t *devices);
84 213
85/* device structure creation and destruction */ 214/* device structure creation and destruction */
86idevice_error_t idevice_new(idevice_t *device, const char *uuid); 215
87idevice_error_t idevice_free(idevice_t device); 216/**
217 * Creates an idevice_t structure for the device specified by UDID,
218 * if the device is available (USBMUX devices only).
219 *
220 * @note The resulting idevice_t structure has to be freed with
221 * idevice_free() if it is no longer used.
222 * If you need to connect to a device available via network, use
223 * idevice_new_with_options() and include IDEVICE_LOOKUP_NETWORK in options.
224 *
225 * @see idevice_new_with_options
226 *
227 * @param device Upon calling this function, a pointer to a location of type
228 * idevice_t. On successful return, this location will be populated.
229 * @param udid The UDID to match.
230 *
231 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
232 */
233LIBIMOBILEDEVICE_API idevice_error_t idevice_new(idevice_t *device, const char *udid);
234
235/**
236 * Creates an idevice_t structure for the device specified by UDID,
237 * if the device is available, with the given lookup options.
238 *
239 * @note The resulting idevice_t structure has to be freed with
240 * idevice_free() if it is no longer used.
241 *
242 * @param device Upon calling this function, a pointer to a location of type
243 * idevice_t. On successful return, this location will be populated.
244 * @param udid The UDID to match.
245 * @param options Specifies what connection types should be considered
246 * when looking up devices. Accepts bitwise or'ed values of idevice_options.
247 * If 0 (no option) is specified it will default to IDEVICE_LOOKUP_USBMUX.
248 * To lookup both USB and network-connected devices, pass
249 * IDEVICE_LOOKUP_USBMUX | IDEVICE_LOOKUP_NETWORK. If a device is available
250 * both via USBMUX *and* network, it will select the USB connection.
251 * This behavior can be changed by adding IDEVICE_LOOKUP_PREFER_NETWORK
252 * to the options in which case it will select the network connection.
253 *
254 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
255 */
256LIBIMOBILEDEVICE_API idevice_error_t idevice_new_with_options(idevice_t *device, const char *udid, enum idevice_options options);
257
258/**
259 * Cleans up an idevice structure, then frees the structure itself.
260 *
261 * @param device idevice_t to free.
262 */
263LIBIMOBILEDEVICE_API idevice_error_t idevice_free(idevice_t device);
88 264
89/* connection/disconnection */ 265/* connection/disconnection */
90idevice_error_t idevice_connect(idevice_t device, uint16_t port, idevice_connection_t *connection); 266
91idevice_error_t idevice_disconnect(idevice_connection_t connection); 267/**
268 * Set up a connection to the given device.
269 *
270 * @param device The device to connect to.
271 * @param port The destination port to connect to.
272 * @param connection Pointer to an idevice_connection_t that will be filled
273 * with the necessary data of the connection.
274 *
275 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
276 */
277LIBIMOBILEDEVICE_API idevice_error_t idevice_connect(idevice_t device, uint16_t port, idevice_connection_t *connection);
278
279/**
280 * Disconnect from the device and clean up the connection structure.
281 *
282 * @param connection The connection to close.
283 *
284 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
285 */
286LIBIMOBILEDEVICE_API idevice_error_t idevice_disconnect(idevice_connection_t connection);
92 287
93/* communication */ 288/* communication */
94idevice_error_t idevice_connection_send(idevice_connection_t connection, const char *data, uint32_t len, uint32_t *sent_bytes); 289
95idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout); 290/**
96idevice_error_t idevice_connection_receive(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes); 291 * Send data to a device via the given connection.
292 *
293 * @param connection The connection to send data over.
294 * @param data Buffer with data to send.
295 * @param len Size of the buffer to send.
296 * @param sent_bytes Pointer to an uint32_t that will be filled
297 * with the number of bytes actually sent.
298 *
299 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
300 */
301LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_send(idevice_connection_t connection, const char *data, uint32_t len, uint32_t *sent_bytes);
302
303/**
304 * Receive data from a device via the given connection.
305 * This function will return after the given timeout even if no data has been
306 * received.
307 *
308 * @param connection The connection to receive data from.
309 * @param data Buffer that will be filled with the received data.
310 * This buffer has to be large enough to hold len bytes.
311 * @param len Buffer size or number of bytes to receive.
312 * @param recv_bytes Number of bytes actually received.
313 * @param timeout Timeout in milliseconds after which this function should
314 * return even if no data has been received.
315 *
316 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
317 */
318LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_receive_timeout(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout);
319
320/**
321 * Receive data from a device via the given connection.
322 * This function is like idevice_connection_receive_timeout, but with a
323 * predefined reasonable timeout.
324 *
325 * @param connection The connection to receive data from.
326 * @param data Buffer that will be filled with the received data.
327 * This buffer has to be large enough to hold len bytes.
328 * @param len Buffer size or number of bytes to receive.
329 * @param recv_bytes Number of bytes actually received.
330 *
331 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
332 */
333LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_receive(idevice_connection_t connection, char *data, uint32_t len, uint32_t *recv_bytes);
334
335/**
336 * Enables SSL for the given connection.
337 *
338 * @param connection The connection to enable SSL for.
339 *
340 * @return IDEVICE_E_SUCCESS on success, IDEVICE_E_INVALID_ARG when connection
341 * is NULL or connection->ssl_data is non-NULL, or IDEVICE_E_SSL_ERROR when
342 * SSL initialization, setup, or handshake fails.
343 */
344LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_enable_ssl(idevice_connection_t connection);
345
346/**
347 * Disable SSL for the given connection.
348 *
349 * @param connection The connection to disable SSL for.
350 *
351 * @return IDEVICE_E_SUCCESS on success, IDEVICE_E_INVALID_ARG when connection
352 * is NULL. This function also returns IDEVICE_E_SUCCESS when SSL is not
353 * enabled and does no further error checking on cleanup.
354 */
355LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_disable_ssl(idevice_connection_t connection);
356
357/**
358 * Disable bypass SSL for the given connection without sending out terminate messages.
359 *
360 * @param connection The connection to disable SSL for.
361 * @param sslBypass if true ssl connection will not be terminated but just cleaned up, allowing
362 * plain text data going on underlying connection
363 *
364 * @return IDEVICE_E_SUCCESS on success, IDEVICE_E_INVALID_ARG when connection
365 * is NULL. This function also returns IDEVICE_E_SUCCESS when SSL is not
366 * enabled and does no further error checking on cleanup.
367 */
368LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_disable_bypass_ssl(idevice_connection_t connection, uint8_t sslBypass);
369
370
371/**
372 * Get the underlying file descriptor for a connection
373 *
374 * @param connection The connection to get fd of
375 * @param fd Pointer to an int where the fd is stored
376 *
377 * @return IDEVICE_E_SUCCESS if ok, otherwise an error code.
378 */
379LIBIMOBILEDEVICE_API idevice_error_t idevice_connection_get_fd(idevice_connection_t connection, int *fd);
97 380
98/* misc */ 381/* misc */
99idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle); 382
100idevice_error_t idevice_get_uuid(idevice_t device, char **uuid); 383/**
384 * Gets the handle or (USBMUX device id) of the device.
385 *
386 * @param device The device to get the USBMUX device id for.
387 * @param handle Pointer to a uint32_t that will be set to the USBMUX handle value.
388 *
389 * @return IDEVICE_E_SUCCESS on success, otherwise an error code.
390 */
391LIBIMOBILEDEVICE_API idevice_error_t idevice_get_handle(idevice_t device, uint32_t *handle);
392
393/**
394 * Gets the Unique Device ID for the device.
395 *
396 * @param device The device to get the Unique Device ID for.
397 * @param udid Pointer that will be set to an allocated buffer with the device UDID. The consumer is responsible for releasing the allocated memory.
398 *
399 * @return IDEVICE_E_SUCCESS on success, otherwise an error code.
400 */
401LIBIMOBILEDEVICE_API idevice_error_t idevice_get_udid(idevice_t device, char **udid);
402
403/**
404 * Returns a static string of the libimobiledevice version.
405 *
406 * @return The libimobiledevice version as static ascii string
407 */
408LIBIMOBILEDEVICE_API const char* libimobiledevice_version();
101 409
102#ifdef __cplusplus 410#ifdef __cplusplus
103} 411}