summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--iphone.c52
1 files changed, 14 insertions, 38 deletions
diff --git a/iphone.c b/iphone.c
index 8d1f96e..3c9a55e 100644
--- a/iphone.c
+++ b/iphone.c
@@ -105,7 +105,6 @@ struct iphone_umux_client_int {
105static pthread_mutex_t iphonemutex = PTHREAD_MUTEX_INITIALIZER; 105static pthread_mutex_t iphonemutex = PTHREAD_MUTEX_INITIALIZER;
106static iphone_umux_client_t *connlist = NULL; 106static iphone_umux_client_t *connlist = NULL;
107static int clients = 0; 107static int clients = 0;
108//static receivebuf_t usbReceive = {NULL, 0, 0};
109 108
110 109
111/** 110/**
@@ -395,8 +394,6 @@ iphone_error_t iphone_get_device(iphone_device_t * device)
395 struct usb_bus *bus; 394 struct usb_bus *bus;
396 struct usb_device *dev; 395 struct usb_device *dev;
397 396
398 pthread_mutex_init(&iphonemutex, NULL);
399
400 usb_init(); 397 usb_init();
401 usb_find_busses(); 398 usb_find_busses();
402 usb_find_devices(); 399 usb_find_devices();
@@ -443,8 +440,6 @@ iphone_error_t iphone_free_device(iphone_device_t device)
443 ret = IPHONE_E_SUCCESS; 440 ret = IPHONE_E_SUCCESS;
444 } 441 }
445 free(device); 442 free(device);
446
447 pthread_mutex_destroy(&iphonemutex);
448 443
449 return ret; 444 return ret;
450} 445}
@@ -488,8 +483,7 @@ int send_to_phone(iphone_device_t phone, char *data, int datalen)
488 return bytes; 483 return bytes;
489 } 484 }
490 else if (bytes < 0) { 485 else if (bytes < 0) {
491 fprintf(stderr, "usb_bulk_write failed with error. err:%d (%s)(%s)\n", 486 fprintf(stderr, "usb_bulk_write failed with error. err:%d (%s)(%s)\n", bytes, usb_strerror(), strerror(-bytes));
492 bytes, usb_strerror(), strerror(-bytes));
493 return -1; 487 return -1;
494 } 488 }
495 else if (bytes == 0) { 489 else if (bytes == 0) {
@@ -534,28 +528,23 @@ int send_to_phone(iphone_device_t phone, char *data, int datalen)
534 */ 528 */
535int recv_from_phone_timeout(iphone_device_t phone, char *data, int datalen, int timeoutmillis) 529int recv_from_phone_timeout(iphone_device_t phone, char *data, int datalen, int timeoutmillis)
536{ 530{
537 int bytes = 0;
538
539 if (!phone) 531 if (!phone)
540 return -EINVAL; 532 return -EINVAL;
541 //log_debug_msg("recv_from_phone(): attempting to receive %i bytes\n", datalen); 533 //log_debug_msg("recv_from_phone(): attempting to receive %i bytes\n", datalen);
542 534
543 bytes = usb_bulk_read(phone->device, BULKIN, data, datalen, timeoutmillis); 535 int bytes = usb_bulk_read(phone->device, BULKIN, data, datalen, timeoutmillis);
536 // There are some things which are errors, others which are no problem.
537 // It's not documented in libUSB, but it seems that the error values
538 // returned are just negated ERRNO values.
544 if (bytes < 0) { 539 if (bytes < 0) {
545 // there are some things which are errors, others which are no problem. 540 if (bytes == -ETIMEDOUT) {
546 // it's not documented in libUSB, but it seems that the error returns are 541 // ignore this. it just means timeout reached before we
547 // just negated ERRNO values. 542 // picked up any data. no problem.
548 if (bytes == -ETIMEDOUT) { 543 return 0;
549 // ignore this. it just means timeout reached before we 544 } else {
550 // picked up any data. no problem. 545 fprintf(stderr, "recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(), strerror(-bytes));
551 return 0; 546 log_debug_msg("recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(), strerror(-bytes));
552 } 547 }
553 else {
554 fprintf(stderr, "recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(),
555 strerror(-bytes));
556 log_debug_msg("recv_from_phone(): libusb gave me the error %d: %s (%s)\n", bytes, usb_strerror(),
557 strerror(-bytes));
558 }
559 return bytes; 548 return bytes;
560 } 549 }
561 550
@@ -573,19 +562,6 @@ int recv_from_phone_timeout(iphone_device_t phone, char *data, int datalen, int
573 return bytes; 562 return bytes;
574} 563}
575 564
576/** This function is a low-level (i.e. direct to iPhone) function.
577 *
578 * @param phone The iPhone to receive data from
579 * @param data Where to put data read
580 * @param datalen How much data to read in
581 *
582 * @return How many bytes were read in, or -1 on error.
583 */
584int recv_from_phone(iphone_device_t phone, char *data, int datalen) {
585 return recv_from_phone_timeout(phone, data, datalen, 100);
586}
587
588
589/** Creates a USBMux packet for the given set of ports. 565/** Creates a USBMux packet for the given set of ports.
590 * 566 *
591 * @param s_port The source port for the connection. 567 * @param s_port The source port for the connection.
@@ -1239,7 +1215,7 @@ iphone_error_t iphone_mux_recv_timeout(iphone_umux_client_t client, char *data,
1239 } 1215 }
1240 1216
1241 pthread_mutex_unlock(&client->mutex); 1217 pthread_mutex_unlock(&client->mutex);
1242 1218
1243 1219
1244 return IPHONE_E_SUCCESS; 1220 return IPHONE_E_SUCCESS;
1245} 1221}