summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Patrick Walton2008-10-17 22:58:50 -0700
committerGravatar Jonathan Beck2008-10-25 14:51:23 +0200
commitbbd813da84c1ff8484bbd3eb7f575775271424da (patch)
tree6ce51f659e09d45646f393d04eb13adeac8aed8f
parent37fff2713545f7d660097842acfeb67e6eb5026c (diff)
downloadlibimobiledevice-bbd813da84c1ff8484bbd3eb7f575775271424da.tar.gz
libimobiledevice-bbd813da84c1ff8484bbd3eb7f575775271424da.tar.bz2
Change iphone_debug to be an API call
Change the iphone_debug to use the new API
-rw-r--r--src/initconf.c3
-rw-r--r--src/iphone.c90
-rw-r--r--src/lckdclient.c2
-rw-r--r--src/main.c5
4 files changed, 54 insertions, 46 deletions
diff --git a/src/initconf.c b/src/initconf.c
index 412dd70..c8c6e84 100644
--- a/src/initconf.c
+++ b/src/initconf.c
@@ -29,7 +29,6 @@
29#include "userpref.h" 29#include "userpref.h"
30#include "lockdown.h" 30#include "lockdown.h"
31 31
32int debug = 1;
33 32
34/** Generates a 2048 byte key, split into a function so that it can be run in a 33/** Generates a 2048 byte key, split into a function so that it can be run in a
35 * thread. 34 * thread.
@@ -71,6 +70,8 @@ int main(int argc, char *argv[])
71 gnutls_x509_crt_t root_cert; 70 gnutls_x509_crt_t root_cert;
72 gnutls_x509_crt_t host_cert; 71 gnutls_x509_crt_t host_cert;
73 72
73 iphone_set_debug(1);
74
74 // Create the thread 75 // Create the thread
75 if (!g_thread_supported()) { 76 if (!g_thread_supported()) {
76 g_thread_init(NULL); 77 g_thread_init(NULL);
diff --git a/src/iphone.c b/src/iphone.c
index c14d61b..4980078 100644
--- a/src/iphone.c
+++ b/src/iphone.c
@@ -27,7 +27,18 @@
27#include <stdlib.h> 27#include <stdlib.h>
28#include <string.h> 28#include <string.h>
29 29
30extern int debug; 30int iphone_debug = 0;
31
32/**
33 * Sets the level of debugging. Currently the only acceptable values are 0 and
34 * 1.
35 *
36 * @param level Set to 0 for no debugging or 1 for debugging.
37 */
38void iphone_set_debug(int level)
39{
40 iphone_debug = level;
41}
31 42
32/** 43/**
33 * Given a USB bus and device number, returns a device handle to the iPhone on 44 * Given a USB bus and device number, returns a device handle to the iPhone on
@@ -42,8 +53,7 @@ extern int debug;
42 * descriptor on return. 53 * descriptor on return.
43 * @return IPHONE_E_SUCCESS if ok, otherwise an error code. 54 * @return IPHONE_E_SUCCESS if ok, otherwise an error code.
44 */ 55 */
45iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, 56iphone_error_t iphone_get_specific_device(int bus_n, int dev_n, iphone_device_t * device)
46 iphone_device_t *device)
47{ 57{
48 struct usb_bus *bus, *busses; 58 struct usb_bus *bus, *busses;
49 struct usb_device *dev; 59 struct usb_device *dev;
@@ -69,26 +79,26 @@ iphone_error_t iphone_get_specific_device(int bus_n, int dev_n,
69 79
70 // Set the device configuration 80 // Set the device configuration
71 for (bus = busses; bus; bus = bus->next) 81 for (bus = busses; bus; bus = bus->next)
72 if (bus->location == bus_n) 82 if (bus->location == bus_n)
73 for (dev = bus->devices; dev != NULL; dev = dev->next) 83 for (dev = bus->devices; dev != NULL; dev = dev->next)
74 if (dev->devnum == dev_n) { 84 if (dev->devnum == dev_n) {
75 phone->__device = dev; 85 phone->__device = dev;
76 phone->device = usb_open(phone->__device); 86 phone->device = usb_open(phone->__device);
77 usb_set_configuration(phone->device, 3); 87 usb_set_configuration(phone->device, 3);
78 usb_claim_interface(phone->device, 1); 88 usb_claim_interface(phone->device, 1);
79 goto found; 89 goto found;
80 } 90 }
81 91
82 iphone_free_device(phone); 92 iphone_free_device(phone);
83 if (debug) 93 if (iphone_debug)
84 fprintf(stderr, "iphone_get_specific_device: iPhone not found\n"); 94 fprintf(stderr, "iphone_get_specific_device: iPhone not found\n");
85 return IPHONE_E_NO_DEVICE; 95 return IPHONE_E_NO_DEVICE;
86 96
87found: 97 found:
88 // Send the version command to the phone 98 // Send the version command to the phone
89 version = version_header(); 99 version = version_header();
90 bytes = usb_bulk_write(phone->device, BULKOUT, (char *) version, sizeof(*version), 800); 100 bytes = usb_bulk_write(phone->device, BULKOUT, (char *) version, sizeof(*version), 800);
91 if (bytes < 20 && debug) { 101 if (bytes < 20 && iphone_debug) {
92 fprintf(stderr, "get_iPhone(): libusb did NOT send enough!\n"); 102 fprintf(stderr, "get_iPhone(): libusb did NOT send enough!\n");
93 if (bytes < 0) { 103 if (bytes < 0) {
94 fprintf(stderr, "get_iPhone(): libusb gave me the error %d: %s (%s)\n", 104 fprintf(stderr, "get_iPhone(): libusb gave me the error %d: %s (%s)\n",
@@ -102,9 +112,9 @@ found:
102 if (bytes < 20) { 112 if (bytes < 20) {
103 free(version); 113 free(version);
104 iphone_free_device(phone); 114 iphone_free_device(phone);
105 if (debug) 115 if (iphone_debug)
106 fprintf(stderr, "get_iPhone(): Invalid version message -- header too short.\n"); 116 fprintf(stderr, "get_iPhone(): Invalid version message -- header too short.\n");
107 if (debug && bytes < 0) 117 if (iphone_debug && bytes < 0)
108 fprintf(stderr, "get_iPhone(): libusb error message %d: %s (%s)\n", 118 fprintf(stderr, "get_iPhone(): libusb error message %d: %s (%s)\n",
109 bytes, usb_strerror(), strerror(-bytes)); 119 bytes, usb_strerror(), strerror(-bytes));
110 return IPHONE_E_NOT_ENOUGH_DATA; 120 return IPHONE_E_NOT_ENOUGH_DATA;
@@ -120,13 +130,13 @@ found:
120 // Bad header 130 // Bad header
121 iphone_free_device(phone); 131 iphone_free_device(phone);
122 free(version); 132 free(version);
123 if (debug) 133 if (iphone_debug)
124 fprintf(stderr, "get_iPhone(): Received a bad header/invalid version number."); 134 fprintf(stderr, "get_iPhone(): Received a bad header/invalid version number.");
125 return IPHONE_E_BAD_HEADER; 135 return IPHONE_E_BAD_HEADER;
126 } 136 }
127 137
128 // If it got to this point it's gotta be bad 138 // If it got to this point it's gotta be bad
129 if (debug) 139 if (iphone_debug)
130 fprintf(stderr, "get_iPhone(): Unknown error.\n"); 140 fprintf(stderr, "get_iPhone(): Unknown error.\n");
131 iphone_free_device(phone); 141 iphone_free_device(phone);
132 free(version); 142 free(version);
@@ -149,24 +159,22 @@ found:
149 * will be filled with a handle to the device. 159 * will be filled with a handle to the device.
150 * @return IPHONE_E_SUCCESS if ok, otherwise an error code. 160 * @return IPHONE_E_SUCCESS if ok, otherwise an error code.
151 */ 161 */
152iphone_error_t iphone_get_device(iphone_device_t *device) 162iphone_error_t iphone_get_device(iphone_device_t * device)
153{ 163{
154 struct usb_bus *bus, *busses; 164 struct usb_bus *bus, *busses;
155 struct usb_device *dev; 165 struct usb_device *dev;
156 166
157 usb_init(); 167 usb_init();
158 usb_find_busses(); 168 usb_find_busses();
159 usb_find_devices(); 169 usb_find_devices();
160 170
161 for (bus = usb_get_busses(); bus != NULL; bus = bus->next) 171 for (bus = usb_get_busses(); bus != NULL; bus = bus->next)
162 for (dev = bus->devices; dev != NULL; dev = dev->next) 172 for (dev = bus->devices; dev != NULL; dev = dev->next)
163 if (dev->descriptor.idVendor == 0x05ac 173 if (dev->descriptor.idVendor == 0x05ac
164 && dev->descriptor.idProduct >= 0x1290 174 && dev->descriptor.idProduct >= 0x1290 && dev->descriptor.idProduct <= 0x1293)
165 && dev->descriptor.idProduct <= 0x1293) 175 return iphone_get_specific_device(bus->location, dev->devnum, device);
166 return iphone_get_specific_device(bus->location, dev->devnum,
167 device);
168 176
169 return IPHONE_E_NO_DEVICE; 177 return IPHONE_E_NO_DEVICE;
170} 178}
171 179
172/** Cleans up an iPhone structure, then frees the structure itself. 180/** Cleans up an iPhone structure, then frees the structure itself.
@@ -210,12 +218,12 @@ int send_to_phone(iphone_device_t phone, char *data, int datalen)
210 218
211 if (!phone) 219 if (!phone)
212 return -1; 220 return -1;
213 if (debug) 221 if (iphone_debug)
214 fprintf(stderr, "send_to_phone: Attempting to send datalen = %i data = %p\n", datalen, data); 222 fprintf(stderr, "send_to_phone: Attempting to send datalen = %i data = %p\n", datalen, data);
215 223
216 bytes = usb_bulk_write(phone->device, BULKOUT, data, datalen, 800); 224 bytes = usb_bulk_write(phone->device, BULKOUT, data, datalen, 800);
217 if (bytes < datalen) { 225 if (bytes < datalen) {
218 if (debug && bytes < 0) 226 if (iphone_debug && bytes < 0)
219 fprintf(stderr, "send_to_iphone(): libusb gave me the error %d: %s - %s\n", bytes, usb_strerror(), 227 fprintf(stderr, "send_to_iphone(): libusb gave me the error %d: %s - %s\n", bytes, usb_strerror(),
220 strerror(-bytes)); 228 strerror(-bytes));
221 return -1; 229 return -1;
@@ -242,12 +250,12 @@ int recv_from_phone(iphone_device_t phone, char *data, int datalen)
242 250
243 if (!phone) 251 if (!phone)
244 return -1; 252 return -1;
245 if (debug) 253 if (iphone_debug)
246 fprintf(stderr, "recv_from_phone(): attempting to receive %i bytes\n", datalen); 254 fprintf(stderr, "recv_from_phone(): attempting to receive %i bytes\n", datalen);
247 255
248 bytes = usb_bulk_read(phone->device, BULKIN, data, datalen, 3500); 256 bytes = usb_bulk_read(phone->device, BULKIN, data, datalen, 3500);
249 if (bytes < 0) { 257 if (bytes < 0) {
250 if (debug) 258 if (iphone_debug)
251 fprintf(stderr, "recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(), 259 fprintf(stderr, "recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(),
252 strerror(-bytes)); 260 strerror(-bytes));
253 return -1; 261 return -1;
diff --git a/src/lckdclient.c b/src/lckdclient.c
index 7a40c93..b3b9942 100644
--- a/src/lckdclient.c
+++ b/src/lckdclient.c
@@ -30,7 +30,6 @@
30#include "iphone.h" 30#include "iphone.h"
31#include <libiphone/libiphone.h> 31#include <libiphone/libiphone.h>
32 32
33int debug = 1;
34 33
35int main(int argc, char *argv[]) 34int main(int argc, char *argv[])
36{ 35{
@@ -38,6 +37,7 @@ int main(int argc, char *argv[])
38 iphone_lckd_client_t control = NULL; 37 iphone_lckd_client_t control = NULL;
39 iphone_device_t phone = NULL; 38 iphone_device_t phone = NULL;
40 39
40 iphone_set_debug(1);
41 41
42 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { 42 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {
43 printf("No iPhone found, is it plugged in?\n"); 43 printf("No iPhone found, is it plugged in?\n");
diff --git a/src/main.c b/src/main.c
index c38103d..055cb4b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -32,7 +32,6 @@
32 32
33#include <libiphone/libiphone.h> 33#include <libiphone/libiphone.h>
34 34
35int debug = 1;
36 35
37int main(int argc, char *argv[]) 36int main(int argc, char *argv[])
38{ 37{
@@ -41,9 +40,9 @@ int main(int argc, char *argv[])
41 iphone_device_t phone = NULL; 40 iphone_device_t phone = NULL;
42 41
43 if (argc > 1 && !strcasecmp(argv[1], "--debug")) { 42 if (argc > 1 && !strcasecmp(argv[1], "--debug")) {
44 debug = 1; 43 iphone_set_debug(1);
45 } else { 44 } else {
46 debug = 0; 45 iphone_set_debug(0);
47 } 46 }
48 47
49 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) { 48 if (IPHONE_E_SUCCESS != iphone_get_device(&phone)) {