diff options
| author | 2009-05-19 13:15:11 +0200 | |
|---|---|---|
| committer | 2009-05-19 07:30:34 -0700 | |
| commit | b61667e9eae1a588815453ccdaa8721e228cc0b8 (patch) | |
| tree | 7a14a6cb7af138abbca7be4bb822dda9df2dafb7 | |
| parent | 34b8e4d575876ace41b91fb6e25a5fa9f9290608 (diff) | |
| download | libimobiledevice-b61667e9eae1a588815453ccdaa8721e228cc0b8.tar.gz libimobiledevice-b61667e9eae1a588815453ccdaa8721e228cc0b8.tar.bz2 | |
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 <matt@colyer.name>
| -rw-r--r-- | dev/Makefile.am | 7 | ||||
| -rw-r--r-- | dev/iphone_id.c | 93 | ||||
| -rw-r--r-- | dev/iphoneinfo.c | 22 | ||||
| -rw-r--r-- | dev/syslog_relay.c | 22 |
4 files changed, 123 insertions, 21 deletions
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 | |||
| 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) | 3 | AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) |
| 4 | AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) | 4 | AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) |
| 5 | 5 | ||
| 6 | bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog | 6 | bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog iphone_id |
| 7 | 7 | ||
| 8 | iphoneclient_SOURCES = main.c | 8 | iphoneclient_SOURCES = main.c |
| 9 | iphoneclient_LDADD = ../src/libiphone.la | 9 | iphoneclient_LDADD = ../src/libiphone.la |
| @@ -32,3 +32,8 @@ iphonesyslog_SOURCES = syslog_relay.c | |||
| 32 | iphonesyslog_CFLAGS = $(AM_CFLAGS) | 32 | iphonesyslog_CFLAGS = $(AM_CFLAGS) |
| 33 | iphonesyslog_LDFLAGS = $(AM_LDFLAGS) | 33 | iphonesyslog_LDFLAGS = $(AM_LDFLAGS) |
| 34 | iphonesyslog_LDADD = ../src/libiphone.la | 34 | iphonesyslog_LDADD = ../src/libiphone.la |
| 35 | |||
| 36 | iphone_id_SOURCES = iphone_id.c | ||
| 37 | iphone_id_CFLAGS = $(AM_CFLAGS) | ||
| 38 | iphone_id_LDFLAGS = $(AM_LDFLAGS) | ||
| 39 | 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 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <getopt.h> | ||
| 5 | #include <libiphone/libiphone.h> | ||
| 6 | #include <usbmuxd.h> | ||
| 7 | |||
| 8 | static void usage() | ||
| 9 | { | ||
| 10 | printf("usage: iphone_id <device_uuid>\n" | ||
| 11 | "\tdevice_uuid is the 40-digit hexadecimal UUID of the device\n" | ||
| 12 | "\tfor which the name should be retrieved.\n\n" | ||
| 13 | "usage: iphone_id -l\n" | ||
| 14 | "\tList all attached devices.\n"); | ||
| 15 | exit(0); | ||
| 16 | } | ||
| 17 | |||
| 18 | int main(int argc, char **argv) | ||
| 19 | { | ||
| 20 | iphone_device_t phone = NULL; | ||
| 21 | iphone_lckd_client_t control = NULL; | ||
| 22 | usbmuxd_scan_result *dev_list; | ||
| 23 | char *devname = NULL; | ||
| 24 | int ret = 0; | ||
| 25 | int c; | ||
| 26 | int i; | ||
| 27 | int opt_list = 0; | ||
| 28 | |||
| 29 | while ((c = getopt(argc, argv, "lh")) != -1) { | ||
| 30 | switch (c) { | ||
| 31 | case 'l': | ||
| 32 | opt_list = 1; | ||
| 33 | break; | ||
| 34 | case 'h': | ||
| 35 | default: | ||
| 36 | usage(); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | if (argc < 2) { | ||
| 41 | usage(); | ||
| 42 | } | ||
| 43 | |||
| 44 | argc -= optind; | ||
| 45 | argv += optind; | ||
| 46 | |||
| 47 | if ((!opt_list) && (strlen(argv[0]) != 40)) { | ||
| 48 | usage(); | ||
| 49 | } | ||
| 50 | |||
| 51 | if (opt_list) { | ||
| 52 | if (usbmuxd_scan(&dev_list) < 0) { | ||
| 53 | fprintf(stderr, "ERROR: usbmuxd is not running!\n"); | ||
| 54 | return -1; | ||
| 55 | } | ||
| 56 | for (i = 0; dev_list[i].handle > 0; i++) { | ||
| 57 | printf("handle=%d product_id=%04x uuid=%s\n", dev_list[i].handle, dev_list[i].product_id, dev_list[i].serial_number); | ||
| 58 | } | ||
| 59 | return 0; | ||
| 60 | } | ||
| 61 | |||
| 62 | iphone_set_debug(0); | ||
| 63 | |||
| 64 | iphone_get_device_by_uuid(&phone, argv[0]); | ||
| 65 | if (!phone) { | ||
| 66 | fprintf(stderr, "ERROR: No device with UUID=%s attached.\n", argv[0]); | ||
| 67 | return -2; | ||
| 68 | } | ||
| 69 | |||
| 70 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | ||
| 71 | iphone_free_device(phone); | ||
| 72 | fprintf(stderr, "ERROR: Connecting to device failed!\n"); | ||
| 73 | return -2; | ||
| 74 | } | ||
| 75 | |||
| 76 | if ((IPHONE_E_SUCCESS != lockdownd_get_device_name(control, &devname)) || !devname) { | ||
| 77 | fprintf(stderr, "ERROR: Could not get device name!\n"); | ||
| 78 | ret = -2; | ||
| 79 | } | ||
| 80 | |||
| 81 | iphone_lckd_free_client(control); | ||
| 82 | iphone_free_device(phone); | ||
| 83 | |||
| 84 | if (ret == 0) { | ||
| 85 | printf("%s\n", devname); | ||
| 86 | } | ||
| 87 | |||
| 88 | if (devname) { | ||
| 89 | free(devname); | ||
| 90 | } | ||
| 91 | |||
| 92 | return ret; | ||
| 93 | } | ||
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 @@ | |||
| 22 | #include <stdio.h> | 22 | #include <stdio.h> |
| 23 | #include <string.h> | 23 | #include <string.h> |
| 24 | #include <errno.h> | 24 | #include <errno.h> |
| 25 | #include <usb.h> | ||
| 26 | 25 | ||
| 27 | #include <libiphone/libiphone.h> | 26 | #include <libiphone/libiphone.h> |
| 28 | 27 | ||
| @@ -37,7 +36,8 @@ int main(int argc, char *argv[]) | |||
| 37 | iphone_device_t phone = NULL; | 36 | iphone_device_t phone = NULL; |
| 38 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 37 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 39 | int i; | 38 | int i; |
| 40 | int bus_n = -1, dev_n = -1; | 39 | char uuid[41]; |
| 40 | uuid[0] = 0; | ||
| 41 | 41 | ||
| 42 | /* parse cmdline args */ | 42 | /* parse cmdline args */ |
| 43 | for (i = 1; i < argc; i++) { | 43 | for (i = 1; i < argc; i++) { |
| @@ -45,11 +45,13 @@ int main(int argc, char *argv[]) | |||
| 45 | iphone_set_debug_mask(DBGMASK_ALL); | 45 | iphone_set_debug_mask(DBGMASK_ALL); |
| 46 | continue; | 46 | continue; |
| 47 | } | 47 | } |
| 48 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) { | 48 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { |
| 49 | if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) { | 49 | i++; |
| 50 | if (!argv[i] || (strlen(argv[i]) != 40)) { | ||
| 50 | print_usage(argc, argv); | 51 | print_usage(argc, argv); |
| 51 | return 0; | 52 | return 0; |
| 52 | } | 53 | } |
| 54 | strcpy(uuid, argv[i]); | ||
| 53 | continue; | 55 | continue; |
| 54 | } | 56 | } |
| 55 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | 57 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { |
| @@ -62,21 +64,21 @@ int main(int argc, char *argv[]) | |||
| 62 | } | 64 | } |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 65 | /* if (bus_n != -1) { | 67 | if (uuid[0] != 0) { |
| 66 | ret = iphone_get_specific_device(bus_n, dev_n, &phone); | 68 | ret = iphone_get_device_by_uuid(&phone, uuid); |
| 67 | if (ret != IPHONE_E_SUCCESS) { | 69 | if (ret != IPHONE_E_SUCCESS) { |
| 68 | printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n); | 70 | printf("No device found with uuid %s, is it plugged in?\n", uuid); |
| 69 | return -1; | 71 | return -1; |
| 70 | } | 72 | } |
| 71 | } | 73 | } |
| 72 | else | 74 | else |
| 73 | {*/ | 75 | { |
| 74 | ret = iphone_get_device(&phone); | 76 | ret = iphone_get_device(&phone); |
| 75 | if (ret != IPHONE_E_SUCCESS) { | 77 | if (ret != IPHONE_E_SUCCESS) { |
| 76 | printf("No device found, is it plugged in?\n"); | 78 | printf("No device found, is it plugged in?\n"); |
| 77 | return -1; | 79 | return -1; |
| 78 | } | 80 | } |
| 79 | /* }*/ | 81 | } |
| 80 | 82 | ||
| 81 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | 83 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { |
| 82 | iphone_free_device(phone); | 84 | iphone_free_device(phone); |
| @@ -108,7 +110,7 @@ void print_usage(int argc, char **argv) | |||
| 108 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); | 110 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); |
| 109 | printf("Show information about the first connected iPhone/iPod Touch.\n\n"); | 111 | printf("Show information about the first connected iPhone/iPod Touch.\n\n"); |
| 110 | printf(" -d, --debug\t\tenable communication debugging\n"); | 112 | printf(" -d, --debug\t\tenable communication debugging\n"); |
| 111 | printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n"); | 113 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); |
| 112 | printf(" -h, --help\t\tprints usage information\n"); | 114 | printf(" -h, --help\t\tprints usage information\n"); |
| 113 | printf("\n"); | 115 | printf("\n"); |
| 114 | } | 116 | } |
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 @@ | |||
| 24 | #include <errno.h> | 24 | #include <errno.h> |
| 25 | #include <netinet/in.h> | 25 | #include <netinet/in.h> |
| 26 | #include <signal.h> | 26 | #include <signal.h> |
| 27 | #include <usb.h> | ||
| 28 | 27 | ||
| 29 | #include <libiphone/libiphone.h> | 28 | #include <libiphone/libiphone.h> |
| 30 | #include <usbmuxd.h> | 29 | #include <usbmuxd.h> |
| @@ -48,8 +47,9 @@ int main(int argc, char *argv[]) | |||
| 48 | iphone_device_t phone = NULL; | 47 | iphone_device_t phone = NULL; |
| 49 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; | 48 | iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; |
| 50 | int i; | 49 | int i; |
| 51 | int bus_n = -1, dev_n = -1; | 50 | char uuid[41]; |
| 52 | int port = 0; | 51 | int port = 0; |
| 52 | uuid[0] = 0; | ||
| 53 | 53 | ||
| 54 | signal(SIGINT, clean_exit); | 54 | signal(SIGINT, clean_exit); |
| 55 | signal(SIGQUIT, clean_exit); | 55 | signal(SIGQUIT, clean_exit); |
| @@ -62,11 +62,13 @@ int main(int argc, char *argv[]) | |||
| 62 | iphone_set_debug_mask(DBGMASK_ALL); | 62 | iphone_set_debug_mask(DBGMASK_ALL); |
| 63 | continue; | 63 | continue; |
| 64 | } | 64 | } |
| 65 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) { | 65 | else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) { |
| 66 | if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) { | 66 | i++; |
| 67 | if (!argv[i] || (strlen(argv[i]) != 40)) { | ||
| 67 | print_usage(argc, argv); | 68 | print_usage(argc, argv); |
| 68 | return 0; | 69 | return 0; |
| 69 | } | 70 | } |
| 71 | strcpy(uuid, argv[i]); | ||
| 70 | continue; | 72 | continue; |
| 71 | } | 73 | } |
| 72 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { | 74 | else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { |
| @@ -79,21 +81,21 @@ int main(int argc, char *argv[]) | |||
| 79 | } | 81 | } |
| 80 | } | 82 | } |
| 81 | 83 | ||
| 82 | /* if (bus_n != -1) { | 84 | if (uuid[0] != 0) { |
| 83 | ret = iphone_get_specific_device(bus_n, dev_n, &phone); | 85 | ret = iphone_get_device_by_uuid(&phone, uuid); |
| 84 | if (ret != IPHONE_E_SUCCESS) { | 86 | if (ret != IPHONE_E_SUCCESS) { |
| 85 | printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n); | 87 | printf("No device found with uuid %s, is it plugged in?\n", uuid); |
| 86 | return -1; | 88 | return -1; |
| 87 | } | 89 | } |
| 88 | } | 90 | } |
| 89 | else | 91 | else |
| 90 | {*/ | 92 | { |
| 91 | ret = iphone_get_device(&phone); | 93 | ret = iphone_get_device(&phone); |
| 92 | if (ret != IPHONE_E_SUCCESS) { | 94 | if (ret != IPHONE_E_SUCCESS) { |
| 93 | printf("No device found, is it plugged in?\n"); | 95 | printf("No device found, is it plugged in?\n"); |
| 94 | return -1; | 96 | return -1; |
| 95 | } | 97 | } |
| 96 | /* }*/ | 98 | } |
| 97 | 99 | ||
| 98 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { | 100 | if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) { |
| 99 | iphone_free_device(phone); | 101 | iphone_free_device(phone); |
| @@ -152,7 +154,7 @@ void print_usage(int argc, char **argv) | |||
| 152 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); | 154 | printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1)); |
| 153 | printf("Relay syslog of a connected iPhone/iPod Touch.\n\n"); | 155 | printf("Relay syslog of a connected iPhone/iPod Touch.\n\n"); |
| 154 | printf(" -d, --debug\t\tenable communication debugging\n"); | 156 | printf(" -d, --debug\t\tenable communication debugging\n"); |
| 155 | printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n"); | 157 | printf(" -u, --uuid UUID\ttarget specific device by its 40-digit device UUID\n"); |
| 156 | printf(" -h, --help\t\tprints usage information\n"); | 158 | printf(" -h, --help\t\tprints usage information\n"); |
| 157 | printf("\n"); | 159 | printf("\n"); |
| 158 | } | 160 | } |
