diff options
Diffstat (limited to 'include/libimobiledevice/companion_proxy.h')
| -rw-r--r-- | include/libimobiledevice/companion_proxy.h | 212 |
1 files changed, 212 insertions, 0 deletions
diff --git a/include/libimobiledevice/companion_proxy.h b/include/libimobiledevice/companion_proxy.h new file mode 100644 index 0000000..544322a --- /dev/null +++ b/include/libimobiledevice/companion_proxy.h | |||
| @@ -0,0 +1,212 @@ | |||
| 1 | /** | ||
| 2 | * @file libimobiledevice/companion_proxy.h | ||
| 3 | * @brief Companion proxy support. | ||
| 4 | * \internal | ||
| 5 | * | ||
| 6 | * Copyright (c) 2019-2020 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 ICOMPANION_PROXY_H | ||
| 24 | #define ICOMPANION_PROXY_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 companion proxy service */ | ||
| 34 | #define COMPANION_PROXY_SERVICE_NAME "com.apple.companion_proxy" | ||
| 35 | |||
| 36 | /** Error Codes */ | ||
| 37 | typedef enum { | ||
| 38 | COMPANION_PROXY_E_SUCCESS = 0, | ||
| 39 | COMPANION_PROXY_E_INVALID_ARG = -1, | ||
| 40 | COMPANION_PROXY_E_PLIST_ERROR = -2, | ||
| 41 | COMPANION_PROXY_E_MUX_ERROR = -3, | ||
| 42 | COMPANION_PROXY_E_SSL_ERROR = -4, | ||
| 43 | COMPANION_PROXY_E_NOT_ENOUGH_DATA = -5, | ||
| 44 | COMPANION_PROXY_E_TIMEOUT = -6, | ||
| 45 | COMPANION_PROXY_E_OP_IN_PROGRESS = -7, | ||
| 46 | COMPANION_PROXY_E_NO_DEVICES = -100, | ||
| 47 | COMPANION_PROXY_E_UNSUPPORTED_KEY = -101, | ||
| 48 | COMPANION_PROXY_E_TIMEOUT_REPLY = -102, | ||
| 49 | COMPANION_PROXY_E_UNKNOWN_ERROR = -256 | ||
| 50 | } companion_proxy_error_t; | ||
| 51 | |||
| 52 | typedef struct companion_proxy_client_private companion_proxy_client_private; /**< \private */ | ||
| 53 | typedef companion_proxy_client_private *companion_proxy_client_t; /**< The client handle. */ | ||
| 54 | |||
| 55 | /** Callback for companion device events */ | ||
| 56 | typedef void (*companion_proxy_device_event_cb_t) (plist_t event, void* userdata); | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Connects to the companion_proxy service on the specified device. | ||
| 60 | * | ||
| 61 | * @param device The device to connect to. | ||
| 62 | * @param service The service descriptor returned by lockdownd_start_service. | ||
| 63 | * @param client Pointer that will point to a newly allocated | ||
| 64 | * companion_proxy_client_t upon successful return. Must be freed using | ||
| 65 | * companion_proxy_client_free() after use. | ||
| 66 | * | ||
| 67 | * @return COMPANION_PROXY_E_SUCCESS on success, COMPANION_PROXY_E_INVALID_ARG when | ||
| 68 | * the arguments are invalid, or an COMPANION_PROXY_E_* error code otherwise. | ||
| 69 | */ | ||
| 70 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_new(idevice_t device, lockdownd_service_descriptor_t service, companion_proxy_client_t* client); | ||
| 71 | |||
| 72 | /** | ||
| 73 | * Starts a new companion_proxy service on the specified device and connects to it. | ||
| 74 | * | ||
| 75 | * @param device The device to connect to. | ||
| 76 | * @param client Pointer that will point to a newly allocated | ||
| 77 | * companion_proxy_client_t upon successful return. Must be freed using | ||
| 78 | * companion_proxy_client_free() after use. | ||
| 79 | * @param label The label to use for communication. Usually the program name. | ||
| 80 | * Pass NULL to disable sending the label in requests to lockdownd. | ||
| 81 | * | ||
| 82 | * @return COMPANION_PROXY_E_SUCCESS on success, or an COMPANION_PROXY_E_* error | ||
| 83 | * code otherwise. | ||
| 84 | */ | ||
| 85 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_start_service(idevice_t device, companion_proxy_client_t* client, const char* label); | ||
| 86 | |||
| 87 | /** | ||
| 88 | * Disconnects a companion_proxy client from the device and frees up the | ||
| 89 | * companion_proxy client data. | ||
| 90 | * | ||
| 91 | * @param client The companion_proxy client to disconnect and free. | ||
| 92 | * | ||
| 93 | * @return COMPANION_PROXY_E_SUCCESS on success, COMPANION_PROXY_E_INVALID_ARG when | ||
| 94 | * client is NULL, or an COMPANION_PROXY_E_* error code otherwise. | ||
| 95 | */ | ||
| 96 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_client_free(companion_proxy_client_t client); | ||
| 97 | |||
| 98 | /** | ||
| 99 | * Sends a plist to the service. | ||
| 100 | * | ||
| 101 | * @param client The companion_proxy client | ||
| 102 | * @param plist The plist to send | ||
| 103 | * | ||
| 104 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 105 | * COMPANION_PROXY_E_INVALID_ARG when client or plist is NULL | ||
| 106 | */ | ||
| 107 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_send(companion_proxy_client_t client, plist_t plist); | ||
| 108 | |||
| 109 | /** | ||
| 110 | * Receives a plist from the service. | ||
| 111 | * | ||
| 112 | * @param client The companion_proxy client | ||
| 113 | * @param plist The plist to store the received data | ||
| 114 | * | ||
| 115 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 116 | * COMPANION_PROXY_E_INVALID_ARG when client or plist is NULL | ||
| 117 | */ | ||
| 118 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_receive(companion_proxy_client_t client, plist_t * plist); | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Retrieves a list of paired devices. | ||
| 122 | * | ||
| 123 | * @param client The companion_proxy client | ||
| 124 | * @param paired_devices Point that will receive a PLIST_ARRAY with paired device UDIDs | ||
| 125 | * | ||
| 126 | * @note The device closes the connection after sending the reply. | ||
| 127 | * | ||
| 128 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 129 | * COMPANION_PROXY_E_NO_DEVICES if no devices are paired, | ||
| 130 | * or a COMPANION_PROXY_E_* error code otherwise. | ||
| 131 | */ | ||
| 132 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_get_device_registry(companion_proxy_client_t client, plist_t* paired_devices); | ||
| 133 | |||
| 134 | /** | ||
| 135 | * Starts listening for paired devices. | ||
| 136 | * | ||
| 137 | * @param client The companion_proxy client | ||
| 138 | * @param callback Callback function that will be called when a new device is detected | ||
| 139 | * @param userdata Pointer that that will be passed to the callback function | ||
| 140 | * | ||
| 141 | * @note The event parameter that gets passed to the callback function is | ||
| 142 | * freed internally after returning from the callback. The consumer needs | ||
| 143 | * to make a copy if required. | ||
| 144 | * | ||
| 145 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 146 | * or a COMPANION_PROXY_E_* error code otherwise. | ||
| 147 | */ | ||
| 148 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_listening_for_devices(companion_proxy_client_t client, companion_proxy_device_event_cb_t callback, void* userdata); | ||
| 149 | |||
| 150 | /** | ||
| 151 | * Stops listening for paired devices | ||
| 152 | * | ||
| 153 | * @param client The companion_proxy client | ||
| 154 | * | ||
| 155 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 156 | * or a COMPANION_PROXY_E_* error code otherwise. | ||
| 157 | */ | ||
| 158 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_stop_listening_for_devices(companion_proxy_client_t client); | ||
| 159 | |||
| 160 | /** | ||
| 161 | * Returns a value for the given key. | ||
| 162 | * | ||
| 163 | * @param client The companion_proxy client | ||
| 164 | * @param companion_udid UDID of the (paired) companion device | ||
| 165 | * @param key The key to retrieve the value for | ||
| 166 | * @param value A pointer to a plist_t that will receive the value for the given key. | ||
| 167 | * The consumer is responsible for freeing the value with plist_free() when no longer needed. | ||
| 168 | * | ||
| 169 | * @note The device closes the connection after sending the reply. | ||
| 170 | * | ||
| 171 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 172 | * COMPANION_PROXY_E_INVALID_ARG when client or paired_devices is invalid, | ||
| 173 | * COMPANION_PROXY_E_UNSUPPORTED_KEY if the companion device doesn't support the given key, | ||
| 174 | * or a COMPANION_PROXY_E_* error code otherwise. | ||
| 175 | */ | ||
| 176 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_get_value_from_registry(companion_proxy_client_t client, const char* companion_udid, const char* key, plist_t* value); | ||
| 177 | |||
| 178 | /** | ||
| 179 | * Start forwarding a service port on the companion device to a port on the idevice. | ||
| 180 | * | ||
| 181 | * @see companion_proxy_stop_forwarding_service_port | ||
| 182 | * | ||
| 183 | * @param client The companion_proxy client | ||
| 184 | * @param remote_port remote port | ||
| 185 | * @param service_name The name of the service that shall be forwarded | ||
| 186 | * @param forward_port Pointer that will receive the newly-assigned port accessible via USB/Network on the idevice | ||
| 187 | * @param options PLIST_DICT with additional options. Currently known are | ||
| 188 | * IsServiceLowPriority (boolean) and PreferWifi (boolean). | ||
| 189 | * | ||
| 190 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 191 | * or a COMPANION_PROXY_E_* error code otherwise. | ||
| 192 | */ | ||
| 193 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_start_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port, const char* service_name, uint16_t* forward_port, plist_t options); | ||
| 194 | |||
| 195 | /** | ||
| 196 | * Stop forwarding a service port between companion device and idevice. | ||
| 197 | * | ||
| 198 | * @see companion_proxy_start_forwarding_service_port | ||
| 199 | * | ||
| 200 | * @param client The companion_proxy client | ||
| 201 | * @param remote_port remote port | ||
| 202 | * | ||
| 203 | * @return COMPANION_PROXY_E_SUCCESS on success, | ||
| 204 | * or a COMPANION_PROXY_E_* error code otherwise. | ||
| 205 | */ | ||
| 206 | LIBIMOBILEDEVICE_API companion_proxy_error_t companion_proxy_stop_forwarding_service_port(companion_proxy_client_t client, uint16_t remote_port); | ||
| 207 | |||
| 208 | #ifdef __cplusplus | ||
| 209 | } | ||
| 210 | #endif | ||
| 211 | |||
| 212 | #endif | ||
