summaryrefslogtreecommitdiffstats
path: root/dev
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2009-05-24 00:25:03 +0200
committerGravatar Martin Szulecki2009-05-24 00:25:03 +0200
commit36ea32e0064f33d6a285684c3069f4d75bbac7a8 (patch)
tree039291b47e954fe8529f52e1fc71f7e924761a6a /dev
parent46f8d46845355e6a33a6dcb97ba11d4c4cab62eb (diff)
parent435f5feb4b5c501db52743a170908687d3ba6f60 (diff)
downloadlibimobiledevice-36ea32e0064f33d6a285684c3069f4d75bbac7a8.tar.gz
libimobiledevice-36ea32e0064f33d6a285684c3069f4d75bbac7a8.tar.bz2
Merge branch 'master' of git://github.com/MattColyer/libiphone into martin
Conflicts: src/Makefile.am
Diffstat (limited to 'dev')
-rw-r--r--dev/Makefile.am11
-rw-r--r--dev/afccheck.c2
-rw-r--r--dev/iphone_id.c93
-rw-r--r--dev/iphoneinfo.c18
-rw-r--r--dev/main.c15
-rw-r--r--dev/msyncclient.c2
-rw-r--r--dev/syslog_relay.c34
7 files changed, 140 insertions, 35 deletions
diff --git a/dev/Makefile.am b/dev/Makefile.am
index 8afe2f9..9e06339 100644
--- a/dev/Makefile.am
+++ b/dev/Makefile.am
@@ -1,9 +1,9 @@
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
+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/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/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 <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <libiphone/libiphone.h>
+#include <usbmuxd.h>
+
+static void usage()
+{
+ printf("usage: iphone_id <device_uuid>\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 4995b9b..c28eb9e 100644
--- a/dev/iphoneinfo.c
+++ b/dev/iphoneinfo.c
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
-#include <usb.h>
#include <libiphone/libiphone.h>
@@ -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,10 +64,10 @@ 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;
}
}
@@ -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/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, &noti);
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, &noti);
@@ -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..3407f2f 100644
--- a/dev/syslog_relay.c
+++ b/dev/syslog_relay.c
@@ -24,9 +24,9 @@
#include <errno.h>
#include <netinet/in.h>
#include <signal.h>
-#include <usb.h>
#include <libiphone/libiphone.h>
+#include <usbmuxd.h>
static int quit_flag = 0;
@@ -47,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);
@@ -61,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")) {
@@ -78,10 +81,10 @@ 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;
}
}
@@ -103,15 +106,16 @@ 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);
- if (ret == IPHONE_E_SUCCESS) {
+ int sfd = usbmuxd_connect(iphone_get_device_handle(phone), port);
+ 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 +125,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 +137,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);
} else {
printf("ERROR: Could not start service com.apple.syslog_relay.\n");
}
@@ -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");
}