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