usbmuxd.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /*
  2. * usbmuxd.h - A client library to talk to the usbmuxd daemon.
  3. *
  4. * Copyright (C) 2014 Martin Szulecki <m.szulecki@libimobiledevice.org>
  5. * Copyright (C) 2009 Nikias Bassen <nikias@gmx.li>
  6. * Copyright (C) 2009 Paul Sladen <libiphone@paul.sladen.org>
  7. *
  8. * This library is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU Lesser General Public License as
  10. * published by the Free Software Foundation, either version 2.1 of the
  11. * 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
  16. * GNU 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 program; if not, write to the Free Software
  20. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  21. */
  22. #ifndef USBMUXD_H
  23. #define USBMUXD_H
  24. #include <stdint.h>
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /**
  29. * Device information structure holding data to identify the device.
  30. * The relevant 'handle' should be passed to 'usbmuxd_connect()', to
  31. * start a proxy connection. The value 'handle' should be considered
  32. * opaque and no presumption made about the meaning of its value.
  33. */
  34. typedef struct {
  35. uint32_t handle;
  36. int product_id;
  37. char udid[41];
  38. } usbmuxd_device_info_t;
  39. /**
  40. * event types for event callback function
  41. */
  42. enum usbmuxd_event_type {
  43. UE_DEVICE_ADD = 1,
  44. UE_DEVICE_REMOVE
  45. };
  46. /**
  47. * Event structure that will be passed to the callback function.
  48. * 'event' will contains the type of the event, and 'device' will contains
  49. * information about the device.
  50. */
  51. typedef struct {
  52. int event;
  53. usbmuxd_device_info_t device;
  54. } usbmuxd_event_t;
  55. /**
  56. * Callback function prototype.
  57. */
  58. typedef void (*usbmuxd_event_cb_t) (const usbmuxd_event_t *event, void *user_data);
  59. /**
  60. * Subscribe a callback function so that applications get to know about
  61. * device add/remove events.
  62. *
  63. * @param callback A callback function that is executed when an event occurs.
  64. *
  65. * @return 0 on success or negative on error.
  66. */
  67. int usbmuxd_subscribe(usbmuxd_event_cb_t callback, void *user_data);
  68. /**
  69. * Unsubscribe callback.
  70. *
  71. * @return only 0 for now.
  72. */
  73. int usbmuxd_unsubscribe();
  74. /**
  75. * Contacts usbmuxd and retrieves a list of connected devices.
  76. *
  77. * @param device_list A pointer to an array of usbmuxd_device_info_t
  78. * that will hold records of the connected devices. The last record
  79. * is a null-terminated record with all fields set to 0/NULL.
  80. * @note The user has to free the list returned.
  81. *
  82. * @return number of attached devices, zero on no devices, or negative
  83. * if an error occured.
  84. */
  85. int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list);
  86. /**
  87. * Frees the device list returned by an usbmuxd_get_device_list call
  88. *
  89. * @param device_list A pointer to an array of usbmuxd_device_info_t to free.
  90. *
  91. * @return 0 on success, -1 on error.
  92. */
  93. int usbmuxd_device_list_free(usbmuxd_device_info_t **device_list);
  94. /**
  95. * Gets device information for the device specified by udid.
  96. *
  97. * @param udid A device UDID of the device to look for. If udid is NULL,
  98. * This function will return the first device found.
  99. * @param device Pointer to a previously allocated (or static)
  100. * usbmuxd_device_info_t that will be filled with the device info.
  101. *
  102. * @return 0 if no matching device is connected, 1 if the device was found,
  103. * or a negative value on error.
  104. */
  105. int usbmuxd_get_device_by_udid(const char *udid, usbmuxd_device_info_t *device);
  106. /**
  107. * Request proxy connect to
  108. *
  109. * @param handle returned by 'usbmuxd_scan()'
  110. *
  111. * @param tcp_port TCP port number on device, in range 0-65535.
  112. * common values are 62078 for lockdown, and 22 for SSH.
  113. *
  114. * @return file descriptor socket of the connection, or -1 on error
  115. */
  116. int usbmuxd_connect(const int handle, const unsigned short tcp_port);
  117. /**
  118. * Disconnect. For now, this just closes the socket file descriptor.
  119. *
  120. * @param sfd socker file descriptor returned by usbmuxd_connect()
  121. *
  122. * @return 0 on success, -1 on error.
  123. */
  124. int usbmuxd_disconnect(int sfd);
  125. /**
  126. * Send data to the specified socket.
  127. *
  128. * @param sfd socket file descriptor returned by usbmuxd_connect()
  129. * @param data buffer to send
  130. * @param len size of buffer to send
  131. * @param sent_bytes how many bytes sent
  132. *
  133. * @return 0 on success, a negative errno value otherwise.
  134. */
  135. int usbmuxd_send(int sfd, const char *data, uint32_t len, uint32_t *sent_bytes);
  136. /**
  137. * Receive data from the specified socket.
  138. *
  139. * @param sfd socket file descriptor returned by usbmuxd_connect()
  140. * @param data buffer to put the data to
  141. * @param len number of bytes to receive
  142. * @param recv_bytes number of bytes received
  143. * @param timeout how many milliseconds to wait for data
  144. *
  145. * @return 0 on success, a negative errno value otherwise.
  146. */
  147. int usbmuxd_recv_timeout(int sfd, char *data, uint32_t len, uint32_t *recv_bytes, unsigned int timeout);
  148. /**
  149. * Receive data from the specified socket with a default timeout.
  150. *
  151. * @param sfd socket file descriptor returned by usbmuxd_connect()
  152. * @param data buffer to put the data to
  153. * @param len number of bytes to receive
  154. * @param recv_bytes number of bytes received
  155. *
  156. * @return 0 on success, a negative errno value otherwise.
  157. */
  158. int usbmuxd_recv(int sfd, char *data, uint32_t len, uint32_t *recv_bytes);
  159. /**
  160. * Reads the SystemBUID
  161. *
  162. * @param buid pointer to a variable that will be set to point to a newly
  163. * allocated string with the System BUID returned by usbmuxd
  164. *
  165. * @return 0 on success, a negative errno value otherwise.
  166. */
  167. int usbmuxd_read_buid(char** buid);
  168. /**
  169. * Read a pairing record
  170. *
  171. * @param record_id the record identifier of the pairing record to retrieve
  172. * @param record_data pointer to a variable that will be set to point to a
  173. * newly allocated buffer containing the pairing record data
  174. * @param record_size pointer to a variable that will be set to the size of
  175. * the buffer returned in record_data
  176. *
  177. * @return 0 on success, a negative error value otherwise.
  178. */
  179. int usbmuxd_read_pair_record(const char* record_id, char **record_data, uint32_t *record_size);
  180. /**
  181. * Save a pairing record
  182. *
  183. * @param record_id the record identifier of the pairing record to save
  184. * @param record_data buffer containing the pairing record data
  185. * @param record_size size of the buffer passed in record_data
  186. *
  187. * @return 0 on success, a negative error value otherwise.
  188. */
  189. int usbmuxd_save_pair_record(const char* record_id, const char *record_data, uint32_t record_size);
  190. /**
  191. * Delete a pairing record
  192. *
  193. * @param record_id the record identifier of the pairing record to delete.
  194. *
  195. * @return 0 on success, a negative errno value otherwise.
  196. */
  197. int usbmuxd_delete_pair_record(const char* record_id);
  198. /**
  199. * Enable or disable the use of inotify extension. Enabled by default.
  200. * Use 0 to disable and 1 to enable inotify support.
  201. * This only has an effect on linux systems if inotify support has been built
  202. * in. Otherwise and on all other platforms this function has no effect.
  203. */
  204. void libusbmuxd_set_use_inotify(int set);
  205. void libusbmuxd_set_debug_level(int level);
  206. #ifdef __cplusplus
  207. }
  208. #endif
  209. #endif /* USBMUXD_H */