From cae85d48c44a9cf9b947a91aef6fbf7309398c4a Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Fri, 9 Jan 2009 20:14:56 -0800 Subject: Add stricter warnings to the compile. --- src/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile.am b/src/Makefile.am index 785aacf..382be1f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,6 +1,6 @@ INCLUDES = -I$(top_srcdir)/include -AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g +AM_CFLAGS = $(libxml2_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) -g -Wall AM_LDFLAGS = $(libxml2_LIBS) $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) bin_PROGRAMS = libiphone-initconf -- cgit v1.1-32-gdbae From 89ad220b093b73e229207ca2da0ad568d81f69e3 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Thu, 8 Jan 2009 18:17:21 +0100 Subject: Perform proper goodby on lockdown shutdown. --- src/iphone.c | 59 +++++++++++++++++-- src/lockdown.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/lockdown.h | 1 + src/usbmux.c | 3 + src/utils.c | 34 +++++++++-- 5 files changed, 260 insertions(+), 15 deletions(-) diff --git a/src/iphone.c b/src/iphone.c index 32d27f6..1f68180 100644 --- a/src/iphone.c +++ b/src/iphone.c @@ -28,6 +28,49 @@ #include #include +/** + * This function sets the configuration of the given device to 3 + * and claims the interface 1. If usb_set_configuration fails, it detaches + * the kernel driver that blocks the device, and retries configuration. + * + * @param phone which device to configure + */ +static void iphone_config_usb_device(iphone_device_t phone) +{ + int ret; + + log_debug_msg("setting configuration... "); + ret = usb_set_configuration(phone->device, 3); + if (ret != 0) { + log_debug_msg("Hm, usb_set_configuration returned %d: %s, trying to fix:\n", ret, strerror(-ret)); + log_debug_msg("-> detaching kernel driver... "); + ret = + usb_detach_kernel_driver_np(phone->device, + phone->__device->config->interface->altsetting->bInterfaceNumber); + if (ret != 0) { + log_debug_msg("usb_detach_kernel_driver_np returned %d: %s\n", ret, strerror(-ret)); + } else { + log_debug_msg("done.\n"); + log_debug_msg("setting configuration again... "); + ret = usb_set_configuration(phone->device, 3); + if (ret != 0) { + log_debug_msg("Error: usb_set_configuration returned %d: %s\n", ret, strerror(-ret)); + } else { + log_debug_msg("done.\n"); + } + } + } else { + log_debug_msg("done.\n"); + } + + log_debug_msg("claiming interface... "); + ret = usb_claim_interface(phone->device, 1); + if (ret != 0) { + log_debug_msg("Error: usb_claim_interface returned %d: %s\n", ret, strerror(-ret)); + } else { + log_debug_msg("done.\n"); + } +} /** * Given a USB bus and device number, returns a device handle to the iPhone on @@ -73,8 +116,7 @@ static iphone_error_t iphone_get_specific_device(unsigned int bus_n, int dev_n, if (dev->devnum == dev_n) { phone->__device = dev; phone->device = usb_open(phone->__device); - usb_set_configuration(phone->device, 3); - usb_claim_interface(phone->device, 1); + iphone_config_usb_device(phone); goto found; } @@ -115,9 +157,10 @@ static iphone_error_t iphone_get_specific_device(unsigned int bus_n, int dev_n, return IPHONE_E_SUCCESS; } else { // Bad header + log_debug_msg("get_iPhone(): Received a bad header/invalid version number.\n"); + log_debug_buffer((char *) version, sizeof(*version)); iphone_free_device(phone); free(version); - log_debug_msg("get_iPhone(): Received a bad header/invalid version number."); return IPHONE_E_BAD_HEADER; } @@ -173,13 +216,21 @@ iphone_error_t iphone_free_device(iphone_device_t device) if (!device) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + int bytes; + unsigned char buf[512]; + + // read final package + bytes = usb_bulk_read(device->device, BULKIN, (void *) &buf, 512, 1000); + if (bytes > 0) { + log_debug_msg("iphone_free_device: final read returned\n"); + log_debug_buffer(buf, bytes); + } if (device->buffer) { free(device->buffer); } if (device->device) { usb_release_interface(device->device, 1); - usb_reset(device->device); usb_close(device->device); ret = IPHONE_E_SUCCESS; } diff --git a/src/lockdown.c b/src/lockdown.c index cf0d99e..ab168a3 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -92,6 +92,97 @@ iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone) return control; } +/** + * Closes the lockdownd communication session, by sending + * the StopSession Request to the device. + * + * @param control The lockdown client + */ +static void iphone_lckd_stop_session(iphone_lckd_client_t control) +{ + if (!control) + return; // IPHONE_E_INVALID_ARG; + xmlDocPtr plist = new_plist(); + xmlNode *dict, *key; + char **dictionary; + int bytes = 0, i = 0; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + log_debug_msg("lockdownd_stop_session() called\n"); + dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); + key = add_key_str_dict_element(plist, dict, "Request", "StopSession", 1); + key = add_key_str_dict_element(plist, dict, "SessionID", control->session_id, 1); + + char *XML_content; + uint32 length; + + xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); + ret = iphone_lckd_send(control, XML_content, length, &bytes); + + xmlFree(XML_content); + xmlFreeDoc(plist); + plist = NULL; + ret = iphone_lckd_recv(control, &XML_content, &bytes); + + plist = xmlReadMemory(XML_content, bytes, NULL, NULL, 0); + if (!plist) { + fprintf(stderr, "lockdownd_stop_session(): IPHONE_E_PLIST_ERROR\n"); + return; //IPHONE_E_PLIST_ERROR; + } + dict = xmlDocGetRootElement(plist); + for (dict = dict->children; dict; dict = dict->next) { + if (!xmlStrcmp(dict->name, "dict")) + break; + } + if (!dict) { + fprintf(stderr, "lockdownd_stop_session(): IPHONE_E_DICT_ERROR\n"); + return; //IPHONE_E_DICT_ERROR; + } + dictionary = read_dict_element_strings(dict); + xmlFreeDoc(plist); + free(XML_content); + + for (i = 0; dictionary[i]; i += 2) { + if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i + 1], "Success")) { + log_debug_msg("lockdownd_stop_session(): success\n"); + ret = IPHONE_E_SUCCESS; + break; + } + } + + free_dictionary(dictionary); + return; //ret; +} + +/** + * Shuts down the SSL session by first calling iphone_lckd_stop_session + * to cleanly close the lockdownd communication session, and then + * performing a close notify, which is done by "gnutls_bye". + * + * @param client The lockdown client + */ +static void iphone_lckd_stop_SSL_session(iphone_lckd_client_t client) +{ + if (!client) { + log_debug_msg("lockdownd_stop_SSL_session(): invalid argument!\n"); + return; + } + + if (client->in_SSL) { + log_debug_msg("Stopping SSL Session\n"); + iphone_lckd_stop_session(client); + log_debug_msg("Sending SSL close notify\n"); + gnutls_bye(*client->ssl_session, GNUTLS_SHUT_RDWR); + } + if (client->ssl_session) { + gnutls_deinit(*client->ssl_session); + free(client->ssl_session); + } + client->in_SSL = 0; + client->gtls_buffer_hack_len = 0; // dunno if required?! + + return; +} /** Closes the lockdownd client and does the necessary housekeeping. * @@ -103,13 +194,17 @@ iphone_error_t iphone_lckd_free_client(iphone_lckd_client_t client) return IPHONE_E_INVALID_ARG; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + iphone_lckd_stop_SSL_session(client); + if (client->connection) { + lockdownd_close(client); + + // IMO, read of final "sessionUpcall connection closed" packet + // should come here instead of in iphone_free_device + ret = iphone_mux_free_client(client->connection); } - if (client->ssl_session) - gnutls_deinit(*client->ssl_session); - free(client->ssl_session); free(client); return ret; } @@ -520,6 +615,66 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch return ret; } +/** + * Performs the Goodbye Request to tell the device the communication + * session is now closed. + * + * @param control The lockdown client + */ +void lockdownd_close(iphone_lckd_client_t control) +{ + if (!control) + return; // IPHONE_E_INVALID_ARG; + xmlDocPtr plist = new_plist(); + xmlNode *dict, *key; + char **dictionary; + int bytes = 0, i = 0; + iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; + + log_debug_msg("lockdownd_close() called\n"); + dict = add_child_to_plist(plist, "dict", "\n", NULL, 0); + key = add_key_str_dict_element(plist, dict, "Request", "Goodbye", 1); + char *XML_content; + uint32 length; + + xmlDocDumpMemory(plist, (xmlChar **) & XML_content, &length); + ret = iphone_lckd_send(control, XML_content, length, &bytes); + + xmlFree(XML_content); + xmlFreeDoc(plist); + plist = NULL; + ret = iphone_lckd_recv(control, &XML_content, &bytes); + + plist = xmlReadMemory(XML_content, bytes, NULL, NULL, 0); + if (!plist) { + fprintf(stderr, "lockdownd_close(): IPHONE_E_PLIST_ERROR\n"); + return; //IPHONE_E_PLIST_ERROR; + } + dict = xmlDocGetRootElement(plist); + for (dict = dict->children; dict; dict = dict->next) { + if (!xmlStrcmp(dict->name, "dict")) + break; + } + if (!dict) { + fprintf(stderr, "lockdownd_close(): IPHONE_E_DICT_ERROR\n"); + return; //IPHONE_E_DICT_ERROR; + } + dictionary = read_dict_element_strings(dict); + xmlFreeDoc(plist); + free(XML_content); + + for (i = 0; dictionary[i]; i += 2) { + if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i + 1], "Success")) { + log_debug_msg("lockdownd_close(): success\n"); + ret = IPHONE_E_SUCCESS; + break; + } + } + + free_dictionary(dictionary); + return; //ret; +} + /** Generates the device certificate from the public key as well as the host * and root certificates. * @@ -664,6 +819,8 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; // end variables + control->session_id[0] = '\0'; + key = add_key_str_dict_element(plist, dict, "HostID", HostID, 1); if (!key) { log_debug_msg("Couldn't add a key.\n"); @@ -699,6 +856,7 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c dictionary = read_dict_element_strings(dict); xmlFreeDoc(plist); free(what2send); + ret = IPHONE_E_SSL_ERROR; for (i = 0; dictionary[i]; i += 2) { if (!strcmp(dictionary[i], "Result") && !strcmp(dictionary[i + 1], "Success")) { // Set up GnuTLS... @@ -741,8 +899,6 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c return_me = gnutls_handshake(*control->ssl_session); log_debug_msg("GnuTLS handshake done...\n"); - free_dictionary(dictionary); - if (return_me != GNUTLS_E_SUCCESS) { log_debug_msg("GnuTLS reported something wrong.\n"); gnutls_perror(return_me); @@ -750,10 +906,20 @@ iphone_error_t lockdownd_start_SSL_session(iphone_lckd_client_t control, const c return IPHONE_E_SSL_ERROR; } else { control->in_SSL = 1; - return IPHONE_E_SUCCESS; + ret = IPHONE_E_SUCCESS; } + } else if (!strcmp(dictionary[i], "SessionID")) { + // we need to store the session ID for StopSession + strcpy(control->session_id, dictionary[i + 1]); + log_debug_msg("SessionID: %s\n", control->session_id); + free_dictionary(dictionary); + return ret; } } + if (ret == IPHONE_E_SUCCESS) { + log_debug_msg("Failed to get SessionID!\n"); + return ret; + } log_debug_msg("Apparently failed negotiating with lockdownd.\n"); log_debug_msg("Responding dictionary: \n"); diff --git a/src/lockdown.h b/src/lockdown.h index 79ca37e..8b4f27c 100644 --- a/src/lockdown.h +++ b/src/lockdown.h @@ -38,6 +38,7 @@ struct iphone_lckd_client_int { int in_SSL; char *gtls_buffer_hack; int gtls_buffer_hack_len; + char session_id[40]; }; char *lockdownd_generate_hostid(void); diff --git a/src/usbmux.c b/src/usbmux.c index 770d0db..c7ac7ef 100644 --- a/src/usbmux.c +++ b/src/usbmux.c @@ -182,8 +182,11 @@ iphone_error_t iphone_mux_free_client(iphone_umux_client_t client) return IPHONE_E_INVALID_ARG; client->header->tcp_flags = 0x04; + client->header->length = htonl(0x1C); client->header->scnt = htonl(client->header->scnt); client->header->ocnt = htonl(client->header->ocnt); + client->header->window = 0; + client->header->length16 = htons(0x1C); int bytes = 0; bytes = usb_bulk_write(client->phone->device, BULKOUT, (char *) client->header, sizeof(usbmux_tcp_header), 800); diff --git a/src/utils.c b/src/utils.c index 049777a..fb98471 100644 --- a/src/utils.c +++ b/src/utils.c @@ -46,7 +46,7 @@ void log_debug_msg(const char *format, ...) va_start(args, format); if (toto_debug) - fprintf(stderr, format, args); + vfprintf(stderr, format, args); va_end(args); @@ -56,11 +56,35 @@ void log_debug_msg(const char *format, ...) inline void log_debug_buffer(const char *data, const int length) { #ifndef STRIP_DEBUG_CODE + int i; + int j; + unsigned char c; - /* run the real fprintf */ - if (toto_debug) - fwrite(data, 1, length, stderr); - + if (toto_debug) { + for (i = 0; i < length; i += 16) { + fprintf(stderr, "%04x: ", i); + for (j = 0; j < 16; j++) { + if (i + j >= length) { + fprintf(stderr, " "); + continue; + } + fprintf(stderr, "%02hhx ", *(data + i + j)); + } + fprintf(stderr, " | "); + for (j = 0; j < 16; j++) { + if (i + j >= length) + break; + c = *(data + i + j); + if ((c < 32) || (c > 127)) { + fprintf(stderr, "."); + continue; + } + fprintf(stderr, "%c", c); + } + fprintf(stderr, "\n"); + } + fprintf(stderr, "\n"); + } #endif } -- cgit v1.1-32-gdbae From bf652fe9ec366cf7da27473566bcc30990193990 Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Tue, 13 Jan 2009 22:00:29 -0800 Subject: Removed old parts of the README that don't apply. --- README | 65 ----------------------------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/README b/README index 472547f..52d19df 100644 --- a/README +++ b/README @@ -47,71 +47,6 @@ run _once_. It MUST be run otherwise communication will not work: The generated keys are saved in '~/.config/libiphone/' in your home directory. -== Tools == - -There are currently two more executables 'ifuse' and 'iphoneclient', -both located in src/. - - -=== iFuse === - -This is probably what you're after; this mounts a view of your -iPhone/iPod Touch's filesystem over the USB interface using the native -Apple protocol (AFC/"com.apple.afc"). - -ifuse is a Fuse filesystem which allows you to mount your iPhone to a directory -like this: - - ./src/ifuse -s - -To unmount: - umount - -(nb: '-s' is to force single-threaded mode, as ifuse maybe unstable without it). - -Eg: - mkdir ~/iphone - - ifuse ~/iphone -s - ls -l ~/iphone - ... - umount ~/iphone - -Currently ifuse (via the AFC protocol) only gives access to the -'/var/root/Media/' chroot on the iPhone (containing music/pictures). - -If you have a device that has been jailedbreaked then an additional -("com.apple.afc2") service will have been installed, without the chroot. -On jailbroken devices only, you can do: - - ifuse ~/iphone --root -s - -And this will mount a full view of the iPhone's filesystem. - - -==== Setting up FUSE ==== - -Note that on some systems, you may have to load the 'fuse' kernel -module first and to ensure that you are a member of the 'fuse' group: - - sudo modprobe fuse - sudo adduser $USER fuse - -You can check your membership of the 'fuse' group with: - - id | grep fuse && echo yes! || echo not yet... - -If you have just added yourself, you will need to logout and log back -in for the group change to become visible. - - -=== iphoneclient === - -'iphoneclient' is a basic commandline interface for testing, it just -runs a few various test operations such as attempting to view/create a -test file in the iPhone, but is mainly a developer tool. - - == Who/what/where? == wiki: -- cgit v1.1-32-gdbae From dc165be9172878144da2fba50139748db32d2986 Mon Sep 17 00:00:00 2001 From: Zoltan Balaton Date: Tue, 13 Jan 2009 22:22:20 -0800 Subject: Correctly handle file modes. --- AUTHORS | 1 + include/libiphone/libiphone.h | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index 18eedb0..8ea17e2 100644 --- a/AUTHORS +++ b/AUTHORS @@ -6,3 +6,4 @@ Christophe Fergeau Martin S. Paul Sladen Patrick Walton +Zoltan Balaton diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index b3e3f95..e4500f0 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -52,10 +52,10 @@ extern "C" { typedef int16_t iphone_error_t; typedef enum { - IPHONE_AFC_FILE_READ = 0x00000002, // seems to be able to read and write files - IPHONE_AFC_FILE_WRITE = 0x00000003, // writes and creates a file, blanks it out, etc. - IPHONE_AFC_FILE_RW = 0x00000005, // seems to do the same as 2. Might even create the file. - IPHONE_AFC_FILE_OP4 = 0x00000004, // no idea -- appears to be "write" -- clears file beforehand like 3 + IPHONE_AFC_FILE_READ = 0x00000001, // seems to be able to read and write files + IPHONE_AFC_FILE_WRITE = 0x00000002, // writes and creates a file, blanks it out, etc. + IPHONE_AFC_FILE_RW = 0x00000003, // seems to do the same as 2. Might even create the file. + IPHONE_AFC_FILE_CREAT = 0x00000004, // no idea -- appears to be "write" -- clears file beforehand like 3 IPHONE_AFC_FILE_OP6 = 0x00000006, // no idea yet -- appears to be the same as 5. IPHONE_AFC_FILE_OP1 = 0x00000001, // no idea juuust yet... probably read. IPHONE_AFC_FILE_OP0 = 0x00000000, -- cgit v1.1-32-gdbae From bced0730e878aefebb53732702d8dd34486697a2 Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Tue, 13 Jan 2009 23:48:39 -0800 Subject: Removed fprintf, use the debug message method. --- src/AFC.c | 2 +- src/iphone.c | 2 +- src/lockdown.c | 18 +++++++++--------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/AFC.c b/src/AFC.c index 6027ed2..cd24cc6 100644 --- a/src/AFC.c +++ b/src/AFC.c @@ -228,7 +228,7 @@ static int receive_AFC_data(iphone_afc_client_t client, char **dump_here) iphone_mux_recv(client->connection, buffer, sizeof(AFCPacket) * 4, &bytes); if (bytes <= 0) { free(buffer); - fprintf(stderr, "Just didn't get enough.\n"); + log_debug_msg("Just didn't get enough.\n"); *dump_here = NULL; return -1; } diff --git a/src/iphone.c b/src/iphone.c index 1f68180..457d919 100644 --- a/src/iphone.c +++ b/src/iphone.c @@ -151,7 +151,7 @@ static iphone_error_t iphone_get_specific_device(unsigned int bus_n, int dev_n, // Check for correct version if (ntohl(version->major) == 1 && ntohl(version->minor) == 0) { // We're all ready to roll. - fprintf(stderr, "get_iPhone() success\n"); + log_debug_msg("get_iPhone() success\n"); free(version); *device = phone; return IPHONE_E_SUCCESS; diff --git a/src/lockdown.c b/src/lockdown.c index ab168a3..2d85a03 100644 --- a/src/lockdown.c +++ b/src/lockdown.c @@ -126,7 +126,7 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) plist = xmlReadMemory(XML_content, bytes, NULL, NULL, 0); if (!plist) { - fprintf(stderr, "lockdownd_stop_session(): IPHONE_E_PLIST_ERROR\n"); + log_debug_msg("lockdownd_stop_session(): IPHONE_E_PLIST_ERROR\n"); return; //IPHONE_E_PLIST_ERROR; } dict = xmlDocGetRootElement(plist); @@ -135,7 +135,7 @@ static void iphone_lckd_stop_session(iphone_lckd_client_t control) break; } if (!dict) { - fprintf(stderr, "lockdownd_stop_session(): IPHONE_E_DICT_ERROR\n"); + log_debug_msg("lockdownd_stop_session(): IPHONE_E_DICT_ERROR\n"); return; //IPHONE_E_DICT_ERROR; } dictionary = read_dict_element_strings(dict); @@ -460,7 +460,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client iphone_lckd_client_t client_loc = new_lockdownd_client(device); if (IPHONE_E_SUCCESS != lockdownd_hello(client_loc)) { - fprintf(stderr, "Hello failed in the lockdownd client.\n"); + log_debug_msg("Hello failed in the lockdownd client.\n"); ret = IPHONE_E_NOT_ENOUGH_DATA; } @@ -468,12 +468,12 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client char *uid = NULL; ret = lockdownd_get_device_uid(client_loc, &uid); if (IPHONE_E_SUCCESS != ret) { - fprintf(stderr, "Device refused to send uid.\n"); + log_debug_msg("Device refused to send uid.\n"); } host_id = get_host_id(); if (IPHONE_E_SUCCESS == ret && !host_id) { - fprintf(stderr, "No HostID found, run libiphone-initconf.\n"); + log_debug_msg("No HostID found, run libiphone-initconf.\n"); ret = IPHONE_E_INVALID_CONF; } @@ -488,7 +488,7 @@ iphone_error_t iphone_lckd_new_client(iphone_device_t device, iphone_lckd_client ret = lockdownd_start_SSL_session(client_loc, host_id); if (IPHONE_E_SUCCESS != ret) { ret = IPHONE_E_SSL_ERROR; - fprintf(stderr, "SSL Session opening failed.\n"); + log_debug_msg("SSL Session opening failed.\n"); } if (host_id) { @@ -526,7 +526,7 @@ iphone_error_t lockdownd_pair_device(iphone_lckd_client_t control, char *uid, ch ret = lockdownd_get_device_public_key(control, &public_key_b64); if (ret != IPHONE_E_SUCCESS) { - fprintf(stderr, "Device refused to send public key.\n"); + log_debug_msg("Device refused to send public key.\n"); return ret; } @@ -647,7 +647,7 @@ void lockdownd_close(iphone_lckd_client_t control) plist = xmlReadMemory(XML_content, bytes, NULL, NULL, 0); if (!plist) { - fprintf(stderr, "lockdownd_close(): IPHONE_E_PLIST_ERROR\n"); + log_debug_msg("lockdownd_close(): IPHONE_E_PLIST_ERROR\n"); return; //IPHONE_E_PLIST_ERROR; } dict = xmlDocGetRootElement(plist); @@ -656,7 +656,7 @@ void lockdownd_close(iphone_lckd_client_t control) break; } if (!dict) { - fprintf(stderr, "lockdownd_close(): IPHONE_E_DICT_ERROR\n"); + log_debug_msg("lockdownd_close(): IPHONE_E_DICT_ERROR\n"); return; //IPHONE_E_DICT_ERROR; } dictionary = read_dict_element_strings(dict); -- cgit v1.1-32-gdbae From 325470e5f298ed493dd813256571c154bfb71406 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 27 Jan 2009 21:21:08 -0800 Subject: Clear extra packets from buffers, in case something went wrong previously. Signed-off-by: Matt Colyer --- AUTHORS | 1 + src/iphone.c | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/AUTHORS b/AUTHORS index 8ea17e2..80c4ddf 100644 --- a/AUTHORS +++ b/AUTHORS @@ -7,3 +7,4 @@ Martin S. Paul Sladen Patrick Walton Zoltan Balaton +Nikias Bassen diff --git a/src/iphone.c b/src/iphone.c index 457d919..6eb56f7 100644 --- a/src/iphone.c +++ b/src/iphone.c @@ -38,6 +38,8 @@ static void iphone_config_usb_device(iphone_device_t phone) { int ret; + int bytes; + unsigned char buf[512]; log_debug_msg("setting configuration... "); ret = usb_set_configuration(phone->device, 3); @@ -70,6 +72,14 @@ static void iphone_config_usb_device(iphone_device_t phone) } else { log_debug_msg("done.\n"); } + + do { + bytes = usb_bulk_read(phone->device, BULKIN, (void *) &buf, 512, 800); + if (bytes > 0) { + log_debug_msg("iphone_config_usb_device: initial read returned %d bytes of data.\n", bytes); + log_debug_buffer(buf, bytes); + } + } while (bytes > 0); } /** @@ -219,12 +229,14 @@ iphone_error_t iphone_free_device(iphone_device_t device) int bytes; unsigned char buf[512]; - // read final package - bytes = usb_bulk_read(device->device, BULKIN, (void *) &buf, 512, 1000); - if (bytes > 0) { - log_debug_msg("iphone_free_device: final read returned\n"); - log_debug_buffer(buf, bytes); - } + // read final package(s) + do { + bytes = usb_bulk_read(device->device, BULKIN, (void *) &buf, 512, 800); + if (bytes > 0) { + log_debug_msg("iphone_free_device: final read returned\n"); + log_debug_buffer(buf, bytes); + } + } while (bytes > 0); if (device->buffer) { free(device->buffer); -- cgit v1.1-32-gdbae From f7fbac7803c5cb5934aab58925babc70af4ab848 Mon Sep 17 00:00:00 2001 From: Matt Colyer Date: Tue, 27 Jan 2009 21:24:20 -0800 Subject: Moved lockdownd_get_device_uid to be part of the public API. --- include/libiphone/libiphone.h | 1 + src/lockdown.h | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/include/libiphone/libiphone.h b/include/libiphone/libiphone.h index e4500f0..32d47d3 100644 --- a/include/libiphone/libiphone.h +++ b/include/libiphone/libiphone.h @@ -84,6 +84,7 @@ iphone_error_t iphone_free_device ( iphone_device_t device ); //lockdownd related functions +iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); iphone_error_t iphone_lckd_new_client ( iphone_device_t device, iphone_lckd_client_t *client ); iphone_error_t iphone_lckd_free_client( iphone_lckd_client_t client ); diff --git a/src/lockdown.h b/src/lockdown.h index 8b4f27c..91bcc77 100644 --- a/src/lockdown.h +++ b/src/lockdown.h @@ -47,7 +47,6 @@ iphone_lckd_client_t new_lockdownd_client(iphone_device_t phone); iphone_error_t lockdownd_hello(iphone_lckd_client_t control); iphone_error_t lockdownd_generic_get_value(iphone_lckd_client_t control, const char *req_key, const char *req_string, char **value); -iphone_error_t lockdownd_get_device_uid(iphone_lckd_client_t control, char **uid); iphone_error_t lockdownd_get_device_public_key(iphone_lckd_client_t control, char **public_key); iphone_error_t lockdownd_gen_pair_cert(char *public_key_b64, char **device_cert_b64, char **host_cert_b64, -- cgit v1.1-32-gdbae