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 @@
1INCLUDES = -I$(top_srcdir)/include 1INCLUDES = -I$(top_srcdir)/include
2 2
3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libusb_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS) 3AM_CFLAGS = $(GLOBAL_CFLAGS) $(libglib2_CFLAGS) $(libgnutls_CFLAGS) $(libtasn1_CFLAGS) $(libgthread2_CFLAGS) $(LFS_CFLAGS)
4AM_LDFLAGS = $(libusb_LIBS) $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS) 4AM_LDFLAGS = $(libglib2_LIBS) $(libgnutls_LIBS) $(libtasn1_LIBS) $(libgthread2_LIBS)
5 5
6bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog 6bin_PROGRAMS = iphoneclient lckd-client afccheck msyncclient iphoneinfo iphonesyslog iphone_id
7 7
8iphoneclient_SOURCES = main.c 8iphoneclient_SOURCES = main.c
9iphoneclient_LDADD = ../src/libiphone.la 9iphoneclient_LDADD = ../src/libiphone.la
@@ -32,3 +32,8 @@ iphonesyslog_SOURCES = syslog_relay.c
32iphonesyslog_CFLAGS = $(AM_CFLAGS) 32iphonesyslog_CFLAGS = $(AM_CFLAGS)
33iphonesyslog_LDFLAGS = $(AM_LDFLAGS) 33iphonesyslog_LDFLAGS = $(AM_LDFLAGS)
34iphonesyslog_LDADD = ../src/libiphone.la 34iphonesyslog_LDADD = ../src/libiphone.la
35
36iphone_id_SOURCES = iphone_id.c
37iphone_id_CFLAGS = $(AM_CFLAGS)
38iphone_id_LDFLAGS = $(AM_LDFLAGS)
39iphone_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[])
106 return 1; 106 return 1;
107 } 107 }
108 108
109 iphone_afc_new_client(phone, 3432, port, &afc); 109 iphone_afc_new_client(phone, port, &afc);
110 110
111 //makes sure thread environment is available 111 //makes sure thread environment is available
112 if (!g_thread_supported()) 112 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 @@
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
8static 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
18int 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 4995b9b..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,10 +64,10 @@ 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 }
@@ -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/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
42 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport); 42 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &nport);
43 if (nport) { 43 if (nport) {
44 printf("::::::::::::::: np was started ::::::::::::\n"); 44 printf("::::::::::::::: np was started ::::::::::::\n");
45 iphone_np_new_client(phone, 3555, nport, &np); 45 iphone_np_new_client(phone, nport, &np);
46 if (np) { 46 if (np) {
47 printf("::::::::: PostNotification %s\n", notification); 47 printf("::::::::: PostNotification %s\n", notification);
48 iphone_np_post_notification(np, notification); 48 iphone_np_post_notification(np, notification);
@@ -98,12 +98,12 @@ int main(int argc, char *argv[])
98 98
99 if (port) { 99 if (port) {
100 iphone_afc_client_t afc = NULL; 100 iphone_afc_client_t afc = NULL;
101 iphone_afc_new_client(phone, 3432, port, &afc); 101 iphone_afc_new_client(phone, port, &afc);
102 if (afc) { 102 if (afc) {
103 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp); 103 iphone_lckd_start_service(control, "com.apple.mobile.notification_proxy", &npp);
104 if (npp) { 104 if (npp) {
105 printf("Notification Proxy started.\n"); 105 printf("Notification Proxy started.\n");
106 iphone_np_new_client(phone, 3756, npp, &gnp); 106 iphone_np_new_client(phone, npp, &gnp);
107 } else { 107 } else {
108 printf("ERROR: Notification proxy could not be started.\n"); 108 printf("ERROR: Notification proxy could not be started.\n");
109 } 109 }
@@ -115,7 +115,7 @@ int main(int argc, char *argv[])
115 NULL 115 NULL
116 }; 116 };
117 iphone_np_observe_notifications(gnp, nspec); 117 iphone_np_observe_notifications(gnp, nspec);
118 //iphone_np_set_notify_callback(gnp, notifier); 118 iphone_np_set_notify_callback(gnp, notifier);
119 } 119 }
120 120
121 perform_notification(phone, control, NP_SYNC_WILL_START); 121 perform_notification(phone, control, NP_SYNC_WILL_START);
@@ -209,15 +209,16 @@ int main(int argc, char *argv[])
209 if (gnp && lockfile) { 209 if (gnp && lockfile) {
210 char *noti; 210 char *noti;
211 211
212 /*
212 noti = NULL; 213 noti = NULL;
213 iphone_np_get_notification(gnp, &noti); 214 iphone_np_get_notification(gnp, &noti);
214 if (noti) { 215 if (noti) {
215 printf("------> received notification '%s'\n", noti); 216 printf("------> received notification '%s'\n", noti);
216 free(noti); 217 free(noti);
217 } 218 }*/
218 219
219 printf("XXX sleeping\n"); 220 printf("XXX sleeping\n");
220 for (i = 0; i < 5; i++) { 221 /*for (i = 0; i < 5; i++) {
221 noti = NULL; 222 noti = NULL;
222 printf("--- getting notification\n"); 223 printf("--- getting notification\n");
223 iphone_np_get_notification(gnp, &noti); 224 iphone_np_get_notification(gnp, &noti);
@@ -229,6 +230,8 @@ int main(int argc, char *argv[])
229 } 230 }
230 sleep(1); 231 sleep(1);
231 } 232 }
233 */
234 sleep(5);
232 235
233 //perform_notification(phone, control, NP_SYNC_DID_FINISH); 236 //perform_notification(phone, control, NP_SYNC_DID_FINISH);
234 237
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[])
51 51
52 if (port) { 52 if (port) {
53 iphone_msync_client_t msync = NULL; 53 iphone_msync_client_t msync = NULL;
54 iphone_msync_new_client(phone, 3432, port, &msync); 54 iphone_msync_new_client(phone, port, &msync);
55 if (msync) { 55 if (msync) {
56 iphone_msync_get_all_contacts(msync); 56 iphone_msync_get_all_contacts(msync);
57 iphone_msync_free_client(msync); 57 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 @@
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>
29#include <usbmuxd.h>
30 30
31static int quit_flag = 0; 31static int quit_flag = 0;
32 32
@@ -47,8 +47,9 @@ int main(int argc, char *argv[])
47 iphone_device_t phone = NULL; 47 iphone_device_t phone = NULL;
48 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR; 48 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
49 int i; 49 int i;
50 int bus_n = -1, dev_n = -1; 50 char uuid[41];
51 int port = 0; 51 int port = 0;
52 uuid[0] = 0;
52 53
53 signal(SIGINT, clean_exit); 54 signal(SIGINT, clean_exit);
54 signal(SIGQUIT, clean_exit); 55 signal(SIGQUIT, clean_exit);
@@ -61,11 +62,13 @@ int main(int argc, char *argv[])
61 iphone_set_debug_mask(DBGMASK_ALL); 62 iphone_set_debug_mask(DBGMASK_ALL);
62 continue; 63 continue;
63 } 64 }
64 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) { 65 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--uuid")) {
65 if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) { 66 i++;
67 if (!argv[i] || (strlen(argv[i]) != 40)) {
66 print_usage(argc, argv); 68 print_usage(argc, argv);
67 return 0; 69 return 0;
68 } 70 }
71 strcpy(uuid, argv[i]);
69 continue; 72 continue;
70 } 73 }
71 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) { 74 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
@@ -78,10 +81,10 @@ int main(int argc, char *argv[])
78 } 81 }
79 } 82 }
80 83
81 if (bus_n != -1) { 84 if (uuid[0] != 0) {
82 ret = iphone_get_specific_device(bus_n, dev_n, &phone); 85 ret = iphone_get_device_by_uuid(&phone, uuid);
83 if (ret != IPHONE_E_SUCCESS) { 86 if (ret != IPHONE_E_SUCCESS) {
84 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);
85 return -1; 88 return -1;
86 } 89 }
87 } 90 }
@@ -103,15 +106,16 @@ int main(int argc, char *argv[])
103 ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port); 106 ret = iphone_lckd_start_service(control, "com.apple.syslog_relay", &port);
104 if ((ret == IPHONE_E_SUCCESS) && port) { 107 if ((ret == IPHONE_E_SUCCESS) && port) {
105 /* connect to socket relay messages */ 108 /* connect to socket relay messages */
106 iphone_umux_client_t syslog_client = NULL;
107 109
108 ret = iphone_mux_new_client(phone, 514, port, &syslog_client); 110 int sfd = usbmuxd_connect(iphone_get_device_handle(phone), port);
109 if (ret == IPHONE_E_SUCCESS) { 111 if (sfd < 0) {
112 printf("ERROR: Could not open usbmux connection.\n");
113 } else {
110 while (!quit_flag) { 114 while (!quit_flag) {
111 char *receive = NULL; 115 char *receive = NULL;
112 uint32_t datalen = 0, bytes = 0, recv_bytes = 0; 116 uint32_t datalen = 0, bytes = 0, recv_bytes = 0;
113 117
114 ret = iphone_mux_recv(syslog_client, (char *) &datalen, sizeof(datalen), &bytes); 118 ret = usbmuxd_recv(sfd, (char *) &datalen, sizeof(datalen), &bytes);
115 datalen = ntohl(datalen); 119 datalen = ntohl(datalen);
116 120
117 if (datalen == 0) 121 if (datalen == 0)
@@ -121,7 +125,7 @@ int main(int argc, char *argv[])
121 receive = (char *) malloc(sizeof(char) * datalen); 125 receive = (char *) malloc(sizeof(char) * datalen);
122 126
123 while (!quit_flag && (recv_bytes <= datalen)) { 127 while (!quit_flag && (recv_bytes <= datalen)) {
124 ret = iphone_mux_recv(syslog_client, receive, datalen, &bytes); 128 ret = usbmuxd_recv(sfd, receive, datalen, &bytes);
125 129
126 if (bytes == 0) 130 if (bytes == 0)
127 break; 131 break;
@@ -133,10 +137,8 @@ int main(int argc, char *argv[])
133 137
134 free(receive); 138 free(receive);
135 } 139 }
136 } else {
137 printf("ERROR: Could not open usbmux connection.\n");
138 } 140 }
139 iphone_mux_free_client(syslog_client); 141 usbmuxd_disconnect(sfd);
140 } else { 142 } else {
141 printf("ERROR: Could not start service com.apple.syslog_relay.\n"); 143 printf("ERROR: Could not start service com.apple.syslog_relay.\n");
142 } 144 }
@@ -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}