summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/main.c22
-rw-r--r--src/usbmux.c13
-rw-r--r--src/usbmux.h2
3 files changed, 37 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 1a62f17..8e27d8f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -719,6 +719,7 @@ static void *usbmuxd_client_init_thread(void *arg)
logmsg(LOG_NOTICE,
"%s[%x]: No attached iPhone/iPod devices found.",
__func__, THREAD);
+ usbmuxd_send_result(cdata->socket, s_req->header.tag, -ENODEV);
goto leave;
}
@@ -846,6 +847,27 @@ static void *usbmuxd_client_init_thread(void *arg)
}
pthread_mutex_unlock(&cur_dev->mutex);
+ // wait for the initial handshake (SYN->SYN+ACK->ACKto complete
+ struct timespec ts;
+ ts.tv_sec = 0;
+ ts.tv_nsec = 100000000;
+
+ i = 0;
+ printf("waiting for handshake to complete...\n");
+ while (i < 10000) {
+ if (usbmux_is_connected(cdata->muxclient)) {
+ printf("handshake done\n");
+ break;
+ }
+ nanosleep(&ts, NULL);
+ i+=100;
+ }
+ if (!usbmux_is_connected(cdata->muxclient)) {
+ printf("handshake failed\n");
+ usbmuxd_send_result(cdata->socket, c_req->header.tag, -ENOTCONN);
+ goto leave;
+ }
+
// start connection handler thread
cdata->handler_dead = 0;
cdata->tag = c_req->header.tag;
diff --git a/src/usbmux.c b/src/usbmux.c
index 87cdede..927928e 100644
--- a/src/usbmux.c
+++ b/src/usbmux.c
@@ -100,6 +100,8 @@ struct usbmux_client_int {
int error;
int cleanup;
+
+ int connected;
};
@@ -734,6 +736,7 @@ int usbmux_new_client(usbmux_device_t device, uint16_t src_port,
add_connection(new_connection);
new_connection->error = 0;
new_connection->cleanup = 0;
+ new_connection->connected = 0;
hton_header(new_connection->header);
log_debug_msg("%s: send_to_device (%d --> %d)\n", __func__,
ntohs(new_connection->header->sport),
@@ -931,6 +934,8 @@ uint32_t append_receive_buffer(usbmux_client_t client, char *packet)
sizeof(usbmux_tcp_header)) <= 0) {
log_debug_msg("%s: error when pushing to usb...\n",
__func__);
+ } else {
+ client->connected = 1;
}
// need to revert some of the fields back to host notation.
ntoh_header(client->header);
@@ -1253,3 +1258,11 @@ int usbmux_recv_timeout(usbmux_client_t client, char *data,
return 0;
}
+
+int usbmux_is_connected(usbmux_client_t client)
+{
+ if (!client) {
+ return 0;
+ }
+ return client->connected;
+}
diff --git a/src/usbmux.h b/src/usbmux.h
index 2bcdb15..155316a 100644
--- a/src/usbmux.h
+++ b/src/usbmux.h
@@ -48,4 +48,6 @@ int usbmux_pullbulk(usbmux_device_t device);
int usbmux_get_error(usbmux_client_t client);
+int usbmux_is_connected(usbmux_client_t client);
+
#endif