summaryrefslogtreecommitdiffstats
path: root/dev/iphoneinfo.c
diff options
context:
space:
mode:
Diffstat (limited to 'dev/iphoneinfo.c')
-rw-r--r--dev/iphoneinfo.c189
1 files changed, 189 insertions, 0 deletions
diff --git a/dev/iphoneinfo.c b/dev/iphoneinfo.c
new file mode 100644
index 0000000..a58ec42
--- /dev/null
+++ b/dev/iphoneinfo.c
@@ -0,0 +1,189 @@
1/*
2 * iphoneinfo.c
3 * Simple utility to show information about an attached device
4 *
5 * Copyright (c) 2009 Martin Szulecki All Rights Reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include <stdio.h>
23#include <string.h>
24#include <errno.h>
25#include <usb.h>
26
27#include <libiphone/libiphone.h>
28
29void print_usage(int argc, char **argv);
30void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, const char *request, const char *key);
31
32int main(int argc, char *argv[])
33{
34 iphone_lckd_client_t control = NULL;
35 iphone_device_t phone = NULL;
36 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
37 int i;
38 int bus_n = -1, dev_n = -1;
39
40 /* parse cmdline args */
41 for (i = 1; i < argc; i++) {
42 if (!strcmp(argv[i], "-d") || !strcmp(argv[i], "--debug")) {
43 iphone_set_debug_mask(DBGMASK_ALL);
44 continue;
45 }
46 else if (!strcmp(argv[i], "-u") || !strcmp(argv[i], "--usb")) {
47 if (sscanf(argv[++i], "%d,%d", &bus_n, &dev_n) < 2) {
48 print_usage(argc, argv);
49 return 0;
50 }
51 continue;
52 }
53 else if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
54 print_usage(argc, argv);
55 return 0;
56 }
57 else {
58 print_usage(argc, argv);
59 return 0;
60 }
61 }
62
63 if (bus_n != -1) {
64 ret = iphone_get_specific_device(bus_n, dev_n, &phone);
65 if (ret != IPHONE_E_SUCCESS) {
66 printf("No device found for usb bus %d and dev %d, is it plugged in?\n", bus_n, dev_n);
67 return -1;
68 }
69 }
70 else
71 {
72 ret = iphone_get_device(&phone);
73 if (ret != IPHONE_E_SUCCESS) {
74 printf("No device found, is it plugged in?\n");
75 return -1;
76 }
77 }
78
79 if (IPHONE_E_SUCCESS != iphone_lckd_new_client(phone, &control)) {
80 iphone_free_device(phone);
81 return -1;
82 }
83
84 /* dump all information we can retrieve */
85 print_lckd_request_info(control, NULL, "GetValue", NULL);
86 print_lckd_request_info(control, "com.apple.disk_usage", "GetValue", NULL);
87 print_lckd_request_info(control, "com.apple.mobile.battery", "GetValue", NULL);
88 print_lckd_request_info(control, "com.apple.international", "GetValue", NULL);
89 print_lckd_request_info(control, "com.apple.mobile.sync_data_class", "GetValue", NULL);
90
91 iphone_lckd_free_client(control);
92 iphone_free_device(phone);
93
94 return 0;
95}
96
97void print_usage(int argc, char **argv)
98{
99 printf("Usage: %s [OPTIONS]\n", (strrchr(argv[0], '/') + 1));
100 printf("Show information about the first connected iPhone/iPod Touch.\n\n");
101 printf(" -d, --debug\t\tenable communication debugging\n");
102 printf(" -u, --usb=BUS,DEV\ttarget specific device by usb bus/dev number\n");
103 printf(" -h, --help\t\tprints usage information\n");
104 printf("\n");
105}
106
107void print_lckd_request_info(iphone_lckd_client_t control, const char *domain, const char *request, const char *key) {
108 iphone_error_t ret = IPHONE_E_UNKNOWN_ERROR;
109 plist_type t;
110
111 plist_t node = plist_new_dict();
112 if (domain) {
113 plist_add_sub_key_el(node, "Domain");
114 plist_add_sub_string_el(node, domain);
115 }
116 if (key) {
117 plist_add_sub_key_el(node, "Key");
118 plist_add_sub_string_el(node, key);
119 }
120 plist_add_sub_key_el(node, "Request");
121 plist_add_sub_string_el(node, request);
122
123 ret = iphone_lckd_send(control, node);
124 if (ret == IPHONE_E_SUCCESS) {
125 plist_free(node);
126 node = NULL;
127 ret = iphone_lckd_recv(control, &node);
128 if (ret == IPHONE_E_SUCCESS) {
129 /* seek to first dict node */
130 for (
131 node = plist_get_first_child(node);
132 (node != NULL) && (plist_get_node_type(node) != PLIST_DICT);
133 node = plist_get_next_sibling(node)
134 ) {
135 }
136
137 /* iterate over key/value pairs */
138 for (
139 node = plist_get_first_child(node);
140 node;
141 node = plist_get_next_sibling(node)
142 ) {
143 char *s = NULL;
144 uint8_t b;
145
146 t = plist_get_node_type(node);
147 if (t == PLIST_KEY) {
148 plist_get_key_val(node, &s);
149 node = plist_get_next_sibling(node);
150 t = plist_get_node_type(node);
151 /* only print string nodes for now */
152 if ((t != PLIST_STRING) &&
153 (t != PLIST_BOOLEAN) &&
154 (t != PLIST_UINT) &&
155 (t != PLIST_DICT)
156 ) {
157 free(s);
158 continue;
159 }
160 printf("%s: ", s);
161 }
162 uint64_t u = 0;
163 switch(t) {
164 case PLIST_DICT:
165 printf("<dict/>\n");
166 break;
167 case PLIST_UINT:
168 plist_get_uint_val(node, &u);
169 printf("%llu\n", u);
170 break;
171 case PLIST_STRING:
172 plist_get_string_val(node, &s);
173 printf("%s\n", s);
174 free(s);
175 break;
176 case PLIST_BOOLEAN:
177 plist_get_bool_val(node, &b);
178 printf("%s\n", (b ? "true" : "false"));
179 default:
180 continue;
181 }
182 }
183 }
184 }
185 if (node)
186 plist_free(node);
187 node = NULL;
188}
189