summaryrefslogtreecommitdiffstats
path: root/src/lockdown.c
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-05-18 22:29:39 +0200
committerGravatar Matt Colyer2009-05-18 18:47:20 -0700
commit8eaac0513bfb238edec22d46320669f5c9c76542 (patch)
tree2db842339bf525d67017525bcbd3f4d35181e5ca /src/lockdown.c
parentdca1758c4f9602fc240c6a7c9ae45839e154d15f (diff)
downloadlibimobiledevice-8eaac0513bfb238edec22d46320669f5c9c76542.tar.gz
libimobiledevice-8eaac0513bfb238edec22d46320669f5c9c76542.tar.bz2
Make use of usbmuxd and remove libusb dependencies
Signed-off-by: Matt Colyer <matt@colyer.name>
Diffstat (limited to 'src/lockdown.c')
-rw-r--r--src/lockdown.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/src/lockdown.c b/src/lockdown.c
index 5ade79a..28670de 100644
--- a/src/lockdown.c
+++ b/src/lockdown.c
@@ -19,7 +19,6 @@
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */ 20 */
21 21
22#include "usbmux.h"
23#include "utils.h" 22#include "utils.h"
24#include "iphone.h" 23#include "iphone.h"
25#include "lockdown.h" 24#include "lockdown.h"
@@ -53,13 +52,15 @@ iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone)
53{ 52{
54 if (!phone) 53 if (!phone)
55 return NULL; 54 return NULL;
56 iphone_lckd_client_t control = (iphone_lckd_client_t) malloc(sizeof(struct iphone_lckd_client_int));
57 55
58 if (IPHONE_E_SUCCESS != iphone_mux_new_client(phone, 0x0a00, 0xf27e, &control->connection)) { 56 int sfd = usbmuxd_connect(phone->handle, 0xf27e);
59 free(control); 57 if (sfd < 0) {
58 log_debug_msg("%s: could not connect to lockdownd (device handle %d)\n", __func__, phone->handle);
60 return NULL; 59 return NULL;
61 } 60 }
62 61
62 iphone_lckd_client_t control = (iphone_lckd_client_t) malloc(sizeof(struct iphone_lckd_client_int));
63 control->sfd = sfd;
63 control->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t)); 64 control->ssl_session = (gnutls_session_t *) malloc(sizeof(gnutls_session_t));
64 control->in_SSL = 0; 65 control->in_SSL = 0;
65 return control; 66 return control;
@@ -167,13 +168,13 @@ iphone_error_t iphone_lckd_free_client(iphone_lckd_client_t client)
167 168
168 iphone_lckd_stop_SSL_session(client); 169 iphone_lckd_stop_SSL_session(client);
169 170
170 if (client->connection) { 171 if (client->sfd > 0) {
171 lockdownd_close(client); 172 lockdownd_close(client);
172 173
173 // IMO, read of final "sessionUpcall connection closed" packet 174 // IMO, read of final "sessionUpcall connection closed" packet
174 // should come here instead of in iphone_free_device 175 // should come here instead of in iphone_free_device
175 176
176 ret = iphone_mux_free_client(client->connection); 177 ret = usbmuxd_disconnect(client->sfd);
177 } 178 }
178 179
179 free(client); 180 free(client);
@@ -197,7 +198,7 @@ iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist)
197 uint32_t datalen = 0, bytes = 0, received_bytes = 0; 198 uint32_t datalen = 0, bytes = 0, received_bytes = 0;
198 199
199 if (!client->in_SSL) 200 if (!client->in_SSL)
200 ret = iphone_mux_recv(client->connection, (char *) &datalen, sizeof(datalen), &bytes); 201 ret = usbmuxd_recv(client->sfd, (char *) &datalen, sizeof(datalen), &bytes);
201 else { 202 else {
202 bytes = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen)); 203 bytes = gnutls_record_recv(*client->ssl_session, &datalen, sizeof(datalen));
203 if (bytes > 0) 204 if (bytes > 0)
@@ -210,7 +211,7 @@ iphone_error_t iphone_lckd_recv(iphone_lckd_client_t client, plist_t * plist)
210 if (!client->in_SSL) { 211 if (!client->in_SSL) {
211 /* fill buffer and request more packets if needed */ 212 /* fill buffer and request more packets if needed */
212 while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) { 213 while ((received_bytes < datalen) && (ret == IPHONE_E_SUCCESS)) {
213 ret = iphone_mux_recv(client->connection, receive + received_bytes, datalen - received_bytes, &bytes); 214 ret = usbmuxd_recv(client->sfd, receive + received_bytes, datalen - received_bytes, &bytes); //iphone_mux_recv(client->connection, receive + received_bytes, datalen - received_bytes, &bytes);
214 received_bytes += bytes; 215 received_bytes += bytes;
215 } 216 }
216 } else { 217 } else {
@@ -271,7 +272,7 @@ iphone_error_t iphone_lckd_send(iphone_lckd_client_t client, plist_t plist)
271 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): made the query, sending it along\n"); 272 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_send(): made the query, sending it along\n");
272 273
273 if (!client->in_SSL) 274 if (!client->in_SSL)
274 ret = iphone_mux_send(client->connection, real_query, ntohl(length) + sizeof(length), &bytes); 275 ret = usbmuxd_send(client->sfd, real_query, ntohl(length) + sizeof(length), (uint32_t*)&bytes); //iphone_mux_send(client->connection, real_query, ntohl(length) + sizeof(length), &bytes);
275 else { 276 else {
276 gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length)); 277 gnutls_record_send(*client->ssl_session, real_query, ntohl(length) + sizeof(length));
277 ret = IPHONE_E_SUCCESS; 278 ret = IPHONE_E_SUCCESS;
@@ -465,7 +466,7 @@ iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid
465 * 466 *
466 * @note You most likely want lockdownd_init unless you are doing something special. 467 * @note You most likely want lockdownd_init unless you are doing something special.
467 * 468 *
468 * @return 1 on success and 0 on failure. 469 * @return IPHONE_E_SUCCESS on succes or an error value < 0 on failure.
469 */ 470 */
470iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key) 471iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, gnutls_datum_t * public_key)
471{ 472{
@@ -1026,7 +1027,7 @@ ssize_t lockdownd_secuwrite(gnutls_transport_ptr_t transport, char *buffer, size
1026 control = (iphone_lckd_client_t) transport; 1027 control = (iphone_lckd_client_t) transport;
1027 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_secuwrite() called\n"); 1028 log_dbg_msg(DBGMASK_LOCKDOWND, "lockdownd_secuwrite() called\n");
1028 log_dbg_msg(DBGMASK_LOCKDOWND, "pre-send\nlength = %zi\n", length); 1029 log_dbg_msg(DBGMASK_LOCKDOWND, "pre-send\nlength = %zi\n", length);
1029 iphone_mux_send(control->connection, buffer, length, &bytes); 1030 usbmuxd_send(control->sfd, buffer, length, &bytes);
1030 log_dbg_msg(DBGMASK_LOCKDOWND, "post-send\nsent %i bytes\n", bytes); 1031 log_dbg_msg(DBGMASK_LOCKDOWND, "post-send\nsent %i bytes\n", bytes);
1031 1032
1032 dump_debug_buffer("sslpacketwrite.out", buffer, length); 1033 dump_debug_buffer("sslpacketwrite.out", buffer, length);
@@ -1059,7 +1060,7 @@ ssize_t lockdownd_securead(gnutls_transport_ptr_t transport, char *buffer, size_
1059 1060
1060 // repeat until we have the full data or an error occurs. 1061 // repeat until we have the full data or an error occurs.
1061 do { 1062 do {
1062 if ((res = iphone_mux_recv(control->connection, recv_buffer, this_len, &bytes)) != IPHONE_E_SUCCESS) { 1063 if ((res = usbmuxd_recv(control->sfd, recv_buffer, this_len, &bytes)) != IPHONE_E_SUCCESS) {
1063 log_debug_msg("%s: ERROR: iphone_mux_recv returned %d\n", __func__, res); 1064 log_debug_msg("%s: ERROR: iphone_mux_recv returned %d\n", __func__, res);
1064 return res; 1065 return res;
1065 } 1066 }