|
Packit |
f228a3 |
/*
|
|
Packit |
f228a3 |
* usbmuxd.h - A client library to talk to the usbmuxd daemon.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* Copyright (C) 2014 Martin Szulecki <m.szulecki@libimobiledevice.org>
|
|
Packit |
f228a3 |
* Copyright (C) 2009 Nikias Bassen <nikias@gmx.li>
|
|
Packit |
f228a3 |
* Copyright (C) 2009 Paul Sladen <libiphone@paul.sladen.org>
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* This library is free software; you can redistribute it and/or modify
|
|
Packit |
f228a3 |
* it under the terms of the GNU Lesser General Public License as
|
|
Packit |
f228a3 |
* published by the Free Software Foundation, either version 2.1 of the
|
|
Packit |
f228a3 |
* License, or (at your option) any later version.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
f228a3 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
f228a3 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit |
f228a3 |
* GNU General Public License for more details.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
f228a3 |
* License along with this program; if not, write to the Free Software
|
|
Packit |
f228a3 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#ifndef USBMUXD_H
|
|
Packit |
f228a3 |
#define USBMUXD_H
|
|
Packit |
f228a3 |
#include <stdint.h>
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#ifdef __cplusplus
|
|
Packit |
f228a3 |
extern "C" {
|
|
Packit |
f228a3 |
#endif
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Device information structure holding data to identify the device.
|
|
Packit |
f228a3 |
* The relevant 'handle' should be passed to 'usbmuxd_connect()', to
|
|
Packit |
f228a3 |
* start a proxy connection. The value 'handle' should be considered
|
|
Packit |
f228a3 |
* opaque and no presumption made about the meaning of its value.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
typedef struct {
|
|
Packit |
f228a3 |
uint32_t handle;
|
|
Packit |
f228a3 |
int product_id;
|
|
Packit |
f228a3 |
char udid[41];
|
|
Packit |
f228a3 |
} usbmuxd_device_info_t;
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* event types for event callback function
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
enum usbmuxd_event_type {
|
|
Packit |
f228a3 |
UE_DEVICE_ADD = 1,
|
|
Packit |
f228a3 |
UE_DEVICE_REMOVE
|
|
Packit |
f228a3 |
};
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Event structure that will be passed to the callback function.
|
|
Packit |
f228a3 |
* 'event' will contains the type of the event, and 'device' will contains
|
|
Packit |
f228a3 |
* information about the device.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
typedef struct {
|
|
Packit |
f228a3 |
int event;
|
|
Packit |
f228a3 |
usbmuxd_device_info_t device;
|
|
Packit |
f228a3 |
} usbmuxd_event_t;
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Callback function prototype.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
typedef void (*usbmuxd_event_cb_t) (const usbmuxd_event_t *event, void *user_data);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Subscribe a callback function so that applications get to know about
|
|
Packit |
f228a3 |
* device add/remove events.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param callback A callback function that is executed when an event occurs.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success or negative on error.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Unsubscribe callback.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return only 0 for now.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_unsubscribe();
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Contacts usbmuxd and retrieves a list of connected devices.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param device_list A pointer to an array of usbmuxd_device_info_t
|
|
Packit |
f228a3 |
* that will hold records of the connected devices. The last record
|
|
Packit |
f228a3 |
* is a null-terminated record with all fields set to 0/NULL.
|
|
Packit |
f228a3 |
* @note The user has to free the list returned.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return number of attached devices, zero on no devices, or negative
|
|
Packit |
f228a3 |
* if an error occured.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Frees the device list returned by an usbmuxd_get_device_list call
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param device_list A pointer to an array of usbmuxd_device_info_t to free.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, -1 on error.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Gets device information for the device specified by udid.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param udid A device UDID of the device to look for. If udid is NULL,
|
|
Packit |
f228a3 |
* This function will return the first device found.
|
|
Packit |
f228a3 |
* @param device Pointer to a previously allocated (or static)
|
|
Packit |
f228a3 |
* usbmuxd_device_info_t that will be filled with the device info.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 if no matching device is connected, 1 if the device was found,
|
|
Packit |
f228a3 |
* or a negative value on error.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Request proxy connect to
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param handle returned by 'usbmuxd_scan()'
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param tcp_port TCP port number on device, in range 0-65535.
|
|
Packit |
f228a3 |
* common values are 62078 for lockdown, and 22 for SSH.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return file descriptor socket of the connection, or -1 on error
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_connect(const int handle, const unsigned short tcp_port);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Disconnect. For now, this just closes the socket file descriptor.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param sfd socker file descriptor returned by usbmuxd_connect()
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, -1 on error.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_disconnect(int sfd);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Send data to the specified socket.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param sfd socket file descriptor returned by usbmuxd_connect()
|
|
Packit |
f228a3 |
* @param data buffer to send
|
|
Packit |
f228a3 |
* @param len size of buffer to send
|
|
Packit |
f228a3 |
* @param sent_bytes how many bytes sent
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, a negative errno value otherwise.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Receive data from the specified socket.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param sfd socket file descriptor returned by usbmuxd_connect()
|
|
Packit |
f228a3 |
* @param data buffer to put the data to
|
|
Packit |
f228a3 |
* @param len number of bytes to receive
|
|
Packit |
f228a3 |
* @param recv_bytes number of bytes received
|
|
Packit |
f228a3 |
* @param timeout how many milliseconds to wait for data
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, a negative errno value otherwise.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Receive data from the specified socket with a default timeout.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param sfd socket file descriptor returned by usbmuxd_connect()
|
|
Packit |
f228a3 |
* @param data buffer to put the data to
|
|
Packit |
f228a3 |
* @param len number of bytes to receive
|
|
Packit |
f228a3 |
* @param recv_bytes number of bytes received
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, a negative errno value otherwise.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Reads the SystemBUID
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param buid pointer to a variable that will be set to point to a newly
|
|
Packit |
f228a3 |
* allocated string with the System BUID returned by usbmuxd
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, a negative errno value otherwise.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_read_buid(char** buid);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Read a pairing record
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param record_id the record identifier of the pairing record to retrieve
|
|
Packit |
f228a3 |
* @param record_data pointer to a variable that will be set to point to a
|
|
Packit |
f228a3 |
* newly allocated buffer containing the pairing record data
|
|
Packit |
f228a3 |
* @param record_size pointer to a variable that will be set to the size of
|
|
Packit |
f228a3 |
* the buffer returned in record_data
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, a negative error value otherwise.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Save a pairing record
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param record_id the record identifier of the pairing record to save
|
|
Packit |
f228a3 |
* @param record_data buffer containing the pairing record data
|
|
Packit |
f228a3 |
* @param record_size size of the buffer passed in record_data
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, a negative error value otherwise.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Delete a pairing record
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @param record_id the record identifier of the pairing record to delete.
|
|
Packit |
f228a3 |
*
|
|
Packit |
f228a3 |
* @return 0 on success, a negative errno value otherwise.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
int usbmuxd_delete_pair_record(const char* record_id);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
/**
|
|
Packit |
f228a3 |
* Enable or disable the use of inotify extension. Enabled by default.
|
|
Packit |
f228a3 |
* Use 0 to disable and 1 to enable inotify support.
|
|
Packit |
f228a3 |
* This only has an effect on linux systems if inotify support has been built
|
|
Packit |
f228a3 |
* in. Otherwise and on all other platforms this function has no effect.
|
|
Packit |
f228a3 |
*/
|
|
Packit |
f228a3 |
void libusbmuxd_set_use_inotify(int set);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
void libusbmuxd_set_debug_level(int level);
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#ifdef __cplusplus
|
|
Packit |
f228a3 |
}
|
|
Packit |
f228a3 |
#endif
|
|
Packit |
f228a3 |
|
|
Packit |
f228a3 |
#endif /* USBMUXD_H */
|