summaryrefslogtreecommitdiffstats
path: root/src/usbmux.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/usbmux.c')
-rw-r--r--src/usbmux.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/usbmux.c b/src/usbmux.c
index cf1a2d9..2114758 100644
--- a/src/usbmux.c
+++ b/src/usbmux.c
@@ -27,8 +27,6 @@
27 27
28#include "usbmux.h" 28#include "usbmux.h"
29 29
30extern int debug;
31
32static iphone_umux_client_t *connlist = NULL; 30static iphone_umux_client_t *connlist = NULL;
33static int clients = 0; 31static int clients = 0;
34 32
@@ -151,8 +149,7 @@ iphone_error_t iphone_mux_new_client(iphone_device_t device, uint16_t src_port,
151 } else { 149 } else {
152 free(response); 150 free(response);
153 151
154 if (debug) 152 log_debug_msg("mux_connect: connection success\n");
155 printf("mux_connect: connection success\n");
156 new_connection->header->tcp_flags = 0x10; 153 new_connection->header->tcp_flags = 0x10;
157 new_connection->header->scnt = 1; 154 new_connection->header->scnt = 1;
158 new_connection->header->ocnt = 1; 155 new_connection->header->ocnt = 1;
@@ -189,12 +186,12 @@ iphone_error_t iphone_mux_free_client(iphone_umux_client_t client)
189 int bytes = 0; 186 int bytes = 0;
190 187
191 bytes = usb_bulk_write(client->phone->device, BULKOUT, (char *) client->header, sizeof(usbmux_tcp_header), 800); 188 bytes = usb_bulk_write(client->phone->device, BULKOUT, (char *) client->header, sizeof(usbmux_tcp_header), 800);
192 if (debug && bytes < 0) 189 if (bytes < 0)
193 printf("iphone_muxèfree_client(): when writing, libusb gave me the error: %s\n", usb_strerror()); 190 log_debug_msg("iphone_muxèfree_client(): when writing, libusb gave me the error: %s\n", usb_strerror());
194 191
195 bytes = usb_bulk_read(client->phone->device, BULKIN, (char *) client->header, sizeof(usbmux_tcp_header), 800); 192 bytes = usb_bulk_read(client->phone->device, BULKIN, (char *) client->header, sizeof(usbmux_tcp_header), 800);
196 if (debug && bytes < 0) 193 if (bytes < 0)
197 printf("get_iPhone(): when reading, libusb gave me the error: %s\n", usb_strerror()); 194 log_debug_msg("get_iPhone(): when reading, libusb gave me the error: %s\n", usb_strerror());
198 195
199 delete_connection(client); 196 delete_connection(client);
200 197
@@ -220,8 +217,7 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui
220 // client->scnt and client->ocnt should already be in host notation... 217 // client->scnt and client->ocnt should already be in host notation...
221 // we don't need to change them juuuust yet. 218 // we don't need to change them juuuust yet.
222 *sent_bytes = 0; 219 *sent_bytes = 0;
223 if (debug) 220 log_debug_msg("mux_send(): client wants to send %i bytes\n", datalen);
224 printf("mux_send(): client wants to send %i bytes\n", datalen);
225 char *buffer = (char *) malloc(sizeof(usbmux_tcp_header) + datalen + 2); // allow 2 bytes of safety padding 221 char *buffer = (char *) malloc(sizeof(usbmux_tcp_header) + datalen + 2); // allow 2 bytes of safety padding
226 // Set the length and pre-emptively htonl/htons it 222 // Set the length and pre-emptively htonl/htons it
227 client->header->length = htonl(sizeof(usbmux_tcp_header) + datalen); 223 client->header->length = htonl(sizeof(usbmux_tcp_header) + datalen);
@@ -235,21 +231,13 @@ iphone_error_t iphone_mux_send(iphone_umux_client_t client, const char *data, ui
235 memcpy(buffer + sizeof(usbmux_tcp_header), data, datalen); 231 memcpy(buffer + sizeof(usbmux_tcp_header), data, datalen);
236 232
237 // We have a buffer full of data, we should now send it to the phone. 233 // We have a buffer full of data, we should now send it to the phone.
238 if (debug) 234 log_debug_msg("actually sending %zi bytes of data at %p\n", sizeof(usbmux_tcp_header) + datalen, buffer);
239 printf("actually sending %zi bytes of data at %p\n", sizeof(usbmux_tcp_header) + datalen, buffer);
240 235
241 236
242 *sent_bytes = send_to_phone(client->phone, buffer, sizeof(usbmux_tcp_header) + datalen); 237 *sent_bytes = send_to_phone(client->phone, buffer, sizeof(usbmux_tcp_header) + datalen);
243 if (debug) 238 log_debug_msg("mux_send: sent %i bytes!\n", *sent_bytes);
244 printf("mux_send: sent %i bytes!\n", *sent_bytes);
245 // Now that we've sent it off, we can clean up after our sloppy selves. 239 // Now that we've sent it off, we can clean up after our sloppy selves.
246 if (debug) { 240 dump_debug_buffer("packet", buffer, *sent_bytes);
247 FILE *packet = fopen("packet", "a+");
248 fwrite(buffer, 1, *sent_bytes, packet);
249 fclose(packet);
250 printf("\n");
251 }
252
253 if (buffer) 241 if (buffer)
254 free(buffer); 242 free(buffer);
255 // Re-calculate scnt and ocnt 243 // Re-calculate scnt and ocnt
@@ -294,8 +282,7 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
294 * a.) Check incoming packet's ports. If proper, follow proper buffering and receiving operation. 282 * a.) Check incoming packet's ports. If proper, follow proper buffering and receiving operation.
295 * b.) If not, find the client the ports belong to and fill that client's buffer, then return mux_recv with the same args to try again. 283 * b.) If not, find the client the ports belong to and fill that client's buffer, then return mux_recv with the same args to try again.
296 */ 284 */
297 if (debug) 285 log_debug_msg("mux_recv: datalen == %i\n", datalen);
298 printf("mux_recv: datalen == %i\n", datalen);
299 int bytes = 0, i = 0, complex = 0, offset = 0; 286 int bytes = 0, i = 0, complex = 0, offset = 0;
300 *recv_bytes = 0; 287 *recv_bytes = 0;
301 char *buffer = NULL; 288 char *buffer = NULL;
@@ -333,8 +320,7 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
333 bytes = recv_from_phone(client->phone, buffer, 131072); 320 bytes = recv_from_phone(client->phone, buffer, 131072);
334 if (bytes < 28) { 321 if (bytes < 28) {
335 free(buffer); 322 free(buffer);
336 if (debug) 323 log_debug_msg("mux_recv: Did not even get the header.\n");
337 printf("mux_recv: Did not even get the header.\n");
338 return IPHONE_E_NOT_ENOUGH_DATA; 324 return IPHONE_E_NOT_ENOUGH_DATA;
339 } 325 }
340 326
@@ -390,7 +376,6 @@ iphone_error_t iphone_mux_recv(iphone_umux_client_t client, char *data, uint32_t
390 } 376 }
391 377
392 // If we get to this point, 'tis probably bad. 378 // If we get to this point, 'tis probably bad.
393 if (debug) 379 log_debug_msg("mux_recv: Heisenbug: bytes and datalen not matching up\n");
394 printf("mux_recv: Heisenbug: bytes and datalen not matching up\n");
395 return IPHONE_E_UNKNOWN_ERROR; 380 return IPHONE_E_UNKNOWN_ERROR;
396} 381}