From 8eaac0513bfb238edec22d46320669f5c9c76542 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Mon, 18 May 2009 22:29:39 +0200 Subject: Make use of usbmuxd and remove libusb dependencies Signed-off-by: Matt Colyer --- dev/Makefile.am | 4 ++-- dev/afccheck.c | 2 +- dev/iphoneinfo.c | 6 +++--- dev/main.c | 15 +++++++++------ dev/msyncclient.c | 2 +- dev/syslog_relay.c | 25 ++++++++++++++----------- 6 files changed, 30 insertions(+), 24 deletions(-) (limited to 'dev') diff --git a/dev/Makefile.am b/dev/Makefile.am index 8afe2f9..3fa8f8c 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -1,7 +1,7 @@ INCLUDES = -I$(top_srcdir)/include -AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) -AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) +AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) +AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog diff --git a/dev/afccheck.c b/dev/afccheck.c index 152a8df..2f7d92c 100644 --- a/dev/afccheck.c +++ b/dev/afccheck.c @@ -106,7 +106,7 @@ int main(int argc, char *argv[]) return 1; } - iphone_afc_new_client(phone, 3432, port, &afc); + iphone_afc_new_client(phone, port, &afc); //makes sure thread environment is available if (!g_thread_supported()) diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 4995b9b..409ad2d 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -62,7 +62,7 @@ int main(int argc, char *argv[]) } } - if (bus_n != -1) { +/* if (bus_n != -1) { ret = iphone_get_specific_device(bus_n, dev_n, &phone); if (ret != IPHONE_E_SUCCESS) { printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n); @@ -70,13 +70,13 @@ int main(int argc, char *argv[]) } } else - { + {*/ ret = iphone_get_device(&phone); if (ret != IPHONE_E_SUCCESS) { printf("No device found, is it plugged in?\n"); return -1; } - } +/* }*/ if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); diff --git a/dev/main.c b/dev/main.c index 510c75f..5c9a5a7 100644 --- a/dev/main.c +++ b/dev/main.c @@ -42,7 +42,7 @@ void perform_notification(iphone_device_t phone, iphone_lckd_client_t control, c iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); if (nport) { printf("::::::::::::::: np was started ::::::::::::\n"); - iphone_np_new_client(phone, 3555, nport, &np); + iphone_np_new_client(phone, nport, &np); if (np) { printf("::::::::: PostNotification %s\n", notification); iphone_np_post_notification(np, notification); @@ -98,12 +98,12 @@ int main(int argc, char *argv[]) if (port) { iphone_afc_client_t afc = NULL; - iphone_afc_new_client(phone, 3432, port, &afc); + iphone_afc_new_client(phone, port, &afc); if (afc) { iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); if (npp) { printf("Notification Proxy started.\n"); - iphone_np_new_client(phone, 3756, npp, &gnp); + iphone_np_new_client(phone, npp, &gnp); } else { printf("ERROR: Notification proxy could not be started.\n"); } @@ -115,7 +115,7 @@ int main(int argc, char *argv[]) NULL }; iphone_np_observe_notifications(gnp, nspec); - //iphone_np_set_notify_callback(gnp, notifier); + iphone_np_set_notify_callback(gnp, notifier); } perform_notification(phone, control, NP_SYNC_WILL_START); @@ -209,15 +209,16 @@ int main(int argc, char *argv[]) if (gnp && lockfile) { char *noti; + /* noti = NULL; iphone_np_get_notification(gnp, ¬i); if (noti) { printf("------> received notification '%s'\n", noti); free(noti); - } + }*/ printf("XXX sleeping\n"); - for (i = 0; i < 5; i++) { + /*for (i = 0; i < 5; i++) { noti = NULL; printf("--- getting notification\n"); iphone_np_get_notification(gnp, ¬i); @@ -229,6 +230,8 @@ int main(int argc, char *argv[]) } sleep(1); } + */ + sleep(5); //perform_notification(phone, control, NP_SYNC_DID_FINISH); diff --git a/dev/msyncclient.c b/dev/msyncclient.c index 804e1ed..e3bb0c2 100644 --- a/dev/msyncclient.c +++ b/dev/msyncclient.c @@ -51,7 +51,7 @@ int main(int argc, char *argv[]) if (port) { iphone_msync_client_t msync = NULL; - iphone_msync_new_client(phone, 3432, port, &msync); + iphone_msync_new_client(phone, port, &msync); if (msync) { iphone_msync_get_all_contacts(msync); iphone_msync_free_client(msync); diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 56cf56c..35c684a 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -27,6 +27,7 @@ #include #include +#include static int quit_flag = 0; @@ -78,7 +79,7 @@ int main(int argc, char *argv[]) } } - if (bus_n != -1) { +/* if (bus_n != -1) { ret = iphone_get_specific_device(bus_n, dev_n, &phone); if (ret != IPHONE_E_SUCCESS) { printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n); @@ -86,13 +87,13 @@ int main(int argc, char *argv[]) } } else - { + {*/ ret = iphone_get_device(&phone); if (ret != IPHONE_E_SUCCESS) { printf("No device found, is it plugged in?\n"); return -1; } - } +/* }*/ if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); @@ -103,15 +104,19 @@ int main(int argc, char *argv[]) ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); if ((ret == IPHONE_E_SUCCESS) && port) { /* connect to socket relay messages */ - iphone_umux_client_t syslog_client = NULL; + //iphone_umux_client_t syslog_client = NULL; - ret = iphone_mux_new_client(phone, 514, port, &syslog_client); - if (ret == IPHONE_E_SUCCESS) { + //ret = iphone_mux_new_client(phone, 514, port, &syslog_client); + int sfd = usbmuxd_connect(iphone_get_device_handle(phone), port); + //if (ret == IPHONE_E_SUCCESS) { + if (sfd < 0) { + printf("ERROR: Could not open usbmux connection.\n"); + } else { while (!quit_flag) { char *receive = NULL; uint32_t datalen = 0, bytes = 0, recv_bytes = 0; - ret = iphone_mux_recv(syslog_client, (char *) &datalen, sizeof(datalen), &bytes); + ret = usbmuxd_recv(sfd, (char *) &datalen, sizeof(datalen), &bytes); datalen = ntohl(datalen); if (datalen == 0) @@ -121,7 +126,7 @@ int main(int argc, char *argv[]) receive = (char *) malloc(sizeof(char) * datalen); while (!quit_flag && (recv_bytes <= datalen)) { - ret = iphone_mux_recv(syslog_client, receive, datalen, &bytes); + ret = usbmuxd_recv(sfd, receive, datalen, &bytes); if (bytes == 0) break; @@ -133,10 +138,8 @@ int main(int argc, char *argv[]) free(receive); } - } else { - printf("ERROR: Could not open usbmux connection.\n"); } - iphone_mux_free_client(syslog_client); + usbmuxd_disconnect(sfd); //iphone_mux_free_client(syslog_client); } else { printf("ERROR: Could not start service com.apple.syslog_relay.\n"); } -- cgit v1.1-32-gdbae From 34b8e4d575876ace41b91fb6e25a5fa9f9290608 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 19 May 2009 12:44:19 +0200 Subject: lockdown: Check for gnutls errors and silence compiler warnings. general: Removed some commented-out code. [#39 state:resolved] Signed-off-by: Matt Colyer --- dev/syslog_relay.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'dev') diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 35c684a..6fc981b 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -104,11 +104,8 @@ int main(int argc, char *argv[]) ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); if ((ret == IPHONE_E_SUCCESS) && port) { /* connect to socket relay messages */ - //iphone_umux_client_t syslog_client = NULL; - //ret = iphone_mux_new_client(phone, 514, port, &syslog_client); int sfd = usbmuxd_connect(iphone_get_device_handle(phone), port); - //if (ret == IPHONE_E_SUCCESS) { if (sfd < 0) { printf("ERROR: Could not open usbmux connection.\n"); } else { @@ -139,7 +136,7 @@ int main(int argc, char *argv[]) free(receive); } } - usbmuxd_disconnect(sfd); //iphone_mux_free_client(syslog_client); + usbmuxd_disconnect(sfd); } else { printf("ERROR: Could not start service com.apple.syslog_relay.\n"); } -- cgit v1.1-32-gdbae From b61667e9eae1a588815453ccdaa8721e228cc0b8 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 19 May 2009 13:15:11 +0200 Subject: Adapted iphoneinfo and iphonesyslog to new API to allow device selection Added iphone_id tool to list devices attached and retrieve device name. Signed-off-by: Matt Colyer --- dev/Makefile.am | 7 +++- dev/iphone_id.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ dev/iphoneinfo.c | 22 +++++++------ dev/syslog_relay.c | 22 +++++++------ 4 files changed, 123 insertions(+), 21 deletions(-) create mode 100644 dev/iphone_id.c (limited to 'dev') diff --git a/dev/Makefile.am b/dev/Makefile.am index 3fa8f8c..9e06339 100644 --- a/dev/Makefile.am +++ b/dev/Makefile.am @@ -3,7 +3,7 @@ INCLUDES = -I$(top_srcdir)/include AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) -bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog +bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog iphone_id iphoneclient_SOURCES = main.c iphoneclient_LDADD = ../src/libiphone.la @@ -32,3 +32,8 @@ iphonesyslog_SOURCES = syslog_relay.c iphonesyslog_CFLAGS = $(AM_CFLAGS) iphonesyslog_LDFLAGS = $(AM_LDFLAGS) iphonesyslog_LDADD = ../src/libiphone.la + +iphone_id_SOURCES = iphone_id.c +iphone_id_CFLAGS = $(AM_CFLAGS) +iphone_id_LDFLAGS = $(AM_LDFLAGS) +iphone_id_LDADD = ../src/libiphone.la diff --git a/dev/iphone_id.c b/dev/iphone_id.c new file mode 100644 index 0000000..c191608 --- /dev/null +++ b/dev/iphone_id.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include +#include + +static void usage() +{ + printf("usage: iphone_id \n" + "\tdevice_uuid is the 40-digit hexadecimal UUID of the device\n" + "\tfor which the name should be retrieved.\n\n" + "usage: iphone_id -l\n" + "\tList all attached devices.\n"); + exit(0); +} + +int main(int argc, char **argv) +{ + iphone_device_t phone = NULL; + iphone_lckd_client_t control = NULL; + usbmuxd_scan_result *dev_list; + char *devname = NULL; + int ret = 0; + int c; + int i; + int opt_list = 0; + + while ((c = getopt(argc, argv, "lh")) != -1) { + switch (c) { + case 'l': + opt_list = 1; + break; + case 'h': + default: + usage(); + } + } + + if (argc < 2) { + usage(); + } + + argc -= optind; + argv += optind; + + if ((!opt_list) && (strlen(argv[0]) != 40)) { + usage(); + } + + if (opt_list) { + if (usbmuxd_scan(&dev_list) < 0) { + fprintf(stderr, "ERROR: usbmuxd is not running!\n"); + return -1; + } + for (i = 0; dev_list[i].handle > 0; i++) { + printf("handle=%d product_id=%04x uuid=%s\n", dev_list[i].handle, dev_list[i].product_id, dev_list[i].serial_number); + } + return 0; + } + + iphone_set_debug(0); + + iphone_get_device_by_uuid(&phone, argv[0]); + if (!phone) { + fprintf(stderr, "ERROR: No device with UUID=%s attached.\n", argv[0]); + return -2; + } + + if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { + iphone_free_device(phone); + fprintf(stderr, "ERROR: Connecting to device failed!\n"); + return -2; + } + + if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(control, &devname)) || !devname) { + fprintf(stderr, "ERROR: Could not get device name!\n"); + ret = -2; + } + + iphone_lckd_free_client(control); + iphone_free_device(phone); + + if (ret == 0) { + printf("%s\n", devname); + } + + if (devname) { + free(devname); + } + + return ret; +} diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c index 409ad2d..c28eb9e 100644 --- a/dev/iphoneinfo.c +++ b/dev/iphoneinfo.c @@ -22,7 +22,6 @@ #include #include #include -#include #include @@ -37,7 +36,8 @@ int main(int argc, char *argv[]) iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; - int bus_n = -1, dev_n = -1; + char uuid[41]; + uuid[0] = 0; /* parse cmdline args */ for (i = 1; i < argc; i++) { @@ -45,11 +45,13 @@ int main(int argc, char *argv[]) iphone_set_debug_mask(DBGMASK_ALL); continue; } - else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) { - if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) { + else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { + i++; + if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); return 0; } + strcpy(uuid, argv[i]); continue; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { @@ -62,21 +64,21 @@ int main(int argc, char *argv[]) } } -/* if (bus_n != -1) { - ret = iphone_get_specific_device(bus_n, dev_n, &phone); + if (uuid[0] != 0) { + ret = iphone_get_device_by_uuid(&phone, uuid); if (ret != IPHONE_E_SUCCESS) { - printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n); + printf("No device found with uuid %s, is it plugged in?\n", uuid); return -1; } } else - {*/ + { ret = iphone_get_device(&phone); if (ret != IPHONE_E_SUCCESS) { printf("No device found, is it plugged in?\n"); return -1; } -/* }*/ + } if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); @@ -108,7 +110,7 @@ void print_usage(int argc, char **argv) printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); printf("Show information about the first connected iPhone/iPod Touch.\n\n"); printf(" -d, --debug\t\tenable communication debugging\n"); - printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n"); + printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); printf(" -h, --help\t\tprints usage information\n"); printf("\n"); } diff --git a/dev/syslog_relay.c b/dev/syslog_relay.c index 6fc981b..3407f2f 100644 --- a/dev/syslog_relay.c +++ b/dev/syslog_relay.c @@ -24,7 +24,6 @@ #include #include #include -#include #include #include @@ -48,8 +47,9 @@ int main(int argc, char *argv[]) iphone_device_t phone = NULL; iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; int i; - int bus_n = -1, dev_n = -1; + char uuid[41]; int port = 0; + uuid[0] = 0; signal(SIGINT, clean_exit); signal(SIGQUIT, clean_exit); @@ -62,11 +62,13 @@ int main(int argc, char *argv[]) iphone_set_debug_mask(DBGMASK_ALL); continue; } - else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) { - if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) { + else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { + i++; + if (!argv[i] || (strlen(argv[i]) != 40)) { print_usage(argc, argv); return 0; } + strcpy(uuid, argv[i]); continue; } else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { @@ -79,21 +81,21 @@ int main(int argc, char *argv[]) } } -/* if (bus_n != -1) { - ret = iphone_get_specific_device(bus_n, dev_n, &phone); + if (uuid[0] != 0) { + ret = iphone_get_device_by_uuid(&phone, uuid); if (ret != IPHONE_E_SUCCESS) { - printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n); + printf("No device found with uuid %s, is it plugged in?\n", uuid); return -1; } } else - {*/ + { ret = iphone_get_device(&phone); if (ret != IPHONE_E_SUCCESS) { printf("No device found, is it plugged in?\n"); return -1; } -/* }*/ + } if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { iphone_free_device(phone); @@ -152,7 +154,7 @@ void print_usage(int argc, char **argv) printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); printf("Relay syslog of a connected iPhone/iPod Touch.\n\n"); printf(" -d, --debug\t\tenable communication debugging\n"); - printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n"); + printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); printf(" -h, --help\t\tprints usage information\n"); printf("\n"); } -- cgit v1.1-32-gdbae