summaryrefslogtreecommitdiffstats
path: root/usbmuxd
diff options
context:
space:
mode:
Diffstat (limited to 'usbmuxd')
-rw-r--r--usbmuxd/CMakeLists.txt8
-rw-r--r--usbmuxd/client.c36
-rw-r--r--usbmuxd/client.h50
-rw-r--r--usbmuxd/utils.c110
-rw-r--r--usbmuxd/utils.h65
5 files changed, 26 insertions, 243 deletions
diff --git a/usbmuxd/CMakeLists.txt b/usbmuxd/CMakeLists.txt
index b982dc0..7d0d3d8 100644
--- a/usbmuxd/CMakeLists.txt
+++ b/usbmuxd/CMakeLists.txt
@@ -2,8 +2,12 @@ find_package(USB REQUIRED)
include_directories(${USB_INCLUDE_DIRS})
set(LIBS ${LIBS} ${USB_LIBRARIES})
-add_definitions(-Wall -O2 -g)
-add_executable(usbmuxd main.c usb-linux.c log.c utils.c device.c client.c)
+include_directories (${CMAKE_SOURCE_DIR}/common)
+include_directories (${CMAKE_SOURCE_DIR}/usbmuxd)
+include_directories (${CMAKE_SOURCE_DIR}/libusbmuxd)
+
+add_definitions(-Wall -O2 -g -DUSBMUXD_DAEMON)
+add_executable(usbmuxd main.c usb-linux.c log.c ../common/utils.c device.c client.c)
target_link_libraries(usbmuxd ${LIBS})
install(TARGETS usbmuxd RUNTIME DESTINATION sbin) \ No newline at end of file
diff --git a/usbmuxd/client.c b/usbmuxd/client.c
index 7a3160f..0e47e84 100644
--- a/usbmuxd/client.c
+++ b/usbmuxd/client.c
@@ -150,10 +150,10 @@ void client_get_fds(struct fdlist *list)
} ENDFOREACH
}
-static int send_pkt(struct mux_client *client, uint32_t tag, enum client_msgtype msg, void *payload, int payload_length)
+static int send_pkt(struct mux_client *client, uint32_t tag, enum usbmuxd_msgtype msg, void *payload, int payload_length)
{
- struct client_header hdr;
- hdr.version = CLIENT_PROTOCOL_VERSION;
+ struct usbmuxd_header hdr;
+ hdr.version = USBMUXD_PROTOCOL_VERSION;
hdr.length = sizeof(hdr) + payload_length;
hdr.message = msg;
hdr.tag = tag;
@@ -176,7 +176,7 @@ static int send_result(struct mux_client *client, uint32_t tag, uint32_t result)
return send_pkt(client, tag, MESSAGE_RESULT, &result, sizeof(uint32_t));
}
-int client_notify_connect(struct mux_client *client, enum client_result result)
+int client_notify_connect(struct mux_client *client, enum usbmuxd_result result)
{
usbmuxd_log(LL_SPEW, "client_notify_connect fd %d result %d", client->fd, result);
if(client->state == CLIENT_DEAD)
@@ -201,13 +201,13 @@ int client_notify_connect(struct mux_client *client, enum client_result result)
static int notify_device(struct mux_client *client, struct device_info *dev)
{
- struct client_msg_dev dmsg;
+ struct usbmuxd_device_record dmsg;
memset(&dmsg, 0, sizeof(dmsg));
dmsg.device_id = dev->id;
- strncpy(dmsg.device_serial, dev->serial, 256);
- dmsg.device_serial[255] = 0;
+ strncpy(dmsg.serial_number, dev->serial, 256);
+ dmsg.serial_number[255] = 0;
dmsg.location = dev->location;
- dmsg.device_pid = dev->pid;
+ dmsg.product_id = dev->pid;
return send_pkt(client, 0, MESSAGE_DEVICE_ADD, &dmsg, sizeof(dmsg));
}
@@ -225,7 +225,7 @@ static int start_listen(struct mux_client *client)
count = device_get_list(devs);
// going to need a larger buffer for many devices
- int needed_buffer = count * (sizeof(struct client_msg_dev) + sizeof(struct client_header)) + REPLY_BUF_SIZE;
+ int needed_buffer = count * (sizeof(struct usbmuxd_device_record) + sizeof(struct usbmuxd_header)) + REPLY_BUF_SIZE;
if(client->ob_capacity < needed_buffer) {
usbmuxd_log(LL_DEBUG, "Enlarging client %d reply buffer %d -> %d to make space for device notifications", client->fd, client->ob_capacity, needed_buffer);
client->ob_buf = realloc(client->ob_buf, needed_buffer);
@@ -242,7 +242,7 @@ static int start_listen(struct mux_client *client)
return count;
}
-static int client_command(struct mux_client *client, struct client_header *hdr, const char *payload)
+static int client_command(struct mux_client *client, struct usbmuxd_header *hdr, const char *payload)
{
int res;
usbmuxd_log(LL_DEBUG, "Client command in fd %d len %d ver %d msg %d tag %d", client->fd, hdr->length, hdr->version, hdr->message, hdr->tag);
@@ -255,7 +255,7 @@ static int client_command(struct mux_client *client, struct client_header *hdr,
return -1;
}
- struct client_msg_connect *ch;
+ struct usbmuxd_connect_request *ch;
switch(hdr->message) {
case MESSAGE_LISTEN:
if(send_result(client, hdr->tag, 0) < 0)
@@ -318,8 +318,8 @@ static void process_recv(struct mux_client *client)
{
int res;
int did_read = 0;
- if(client->ib_size < sizeof(struct client_header)) {
- res = recv(client->fd, client->ib_buf + client->ib_size, sizeof(struct client_header) - client->ib_size, 0);
+ if(client->ib_size < sizeof(struct usbmuxd_header)) {
+ res = recv(client->fd, client->ib_buf + client->ib_size, sizeof(struct usbmuxd_header) - client->ib_size, 0);
if(res <= 0) {
if(res < 0)
usbmuxd_log(LL_ERROR, "Receive from client fd %d failed: %s", client->fd, strerror(errno));
@@ -329,20 +329,20 @@ static void process_recv(struct mux_client *client)
return;
}
client->ib_size += res;
- if(client->ib_size < sizeof(struct client_header))
+ if(client->ib_size < sizeof(struct usbmuxd_header))
return;
did_read = 1;
}
- struct client_header *hdr = (void*)client->ib_buf;
- if(hdr->version != CLIENT_PROTOCOL_VERSION) {
- usbmuxd_log(LL_INFO, "Client %d version mismatch: expected %d, got %d", client->fd, CLIENT_PROTOCOL_VERSION, hdr->version);
+ struct usbmuxd_header *hdr = (void*)client->ib_buf;
+ if(hdr->version != USBMUXD_PROTOCOL_VERSION) {
+ usbmuxd_log(LL_INFO, "Client %d version mismatch: expected %d, got %d", client->fd, USBMUXD_PROTOCOL_VERSION, hdr->version);
client_close(client);
}
if(hdr->length > client->ib_capacity) {
usbmuxd_log(LL_INFO, "Client %d message is too long (%d bytes)", client->fd, hdr->length);
client_close(client);
}
- if(hdr->length < sizeof(struct client_header)) {
+ if(hdr->length < sizeof(struct usbmuxd_header)) {
usbmuxd_log(LL_ERROR, "Client %d message is too short (%d bytes)", client->fd, hdr->length);
client_close(client);
}
diff --git a/usbmuxd/client.h b/usbmuxd/client.h
index 0cda676..4fc1ab4 100644
--- a/usbmuxd/client.h
+++ b/usbmuxd/client.h
@@ -22,62 +22,16 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#define __CLIENT_H__
#include <stdint.h>
+#include "usbmuxd-proto.h"
struct device_info;
struct mux_client;
-enum client_result {
- RESULT_OK = 0,
- RESULT_BADCOMMAND = 1,
- RESULT_BADDEV = 2,
- RESULT_CONNREFUSED = 3,
- // ???
- // ???
- RESULT_BADVERSION = 6,
-};
-
-enum client_msgtype {
- MESSAGE_RESULT = 1,
- MESSAGE_CONNECT = 2,
- MESSAGE_LISTEN = 3,
- MESSAGE_DEVICE_ADD = 4,
- MESSAGE_DEVICE_REMOVE = 5,
- //???
- //???
- //MESSAGE_PLIST = 8,
-};
-
-#define CLIENT_PROTOCOL_VERSION 0
-
-struct client_header {
- uint32_t length;
- uint32_t version;
- uint32_t message;
- uint32_t tag;
-};
-
-struct client_msg_result {
- uint32_t result;
-};
-
-struct client_msg_connect {
- uint32_t device_id;
- uint16_t port;
-};
-
-struct client_msg_dev {
- uint32_t device_id;
- uint16_t device_pid;
- char device_serial[256];
- uint16_t padding;
- uint32_t location;
-};
-
int client_read(struct mux_client *client, void *buffer, int len);
int client_write(struct mux_client *client, void *buffer, int len);
int client_set_events(struct mux_client *client, short events);
void client_close(struct mux_client *client);
-int client_notify_connect(struct mux_client *client, enum client_result result);
+int client_notify_connect(struct mux_client *client, enum usbmuxd_result result);
void client_device_add(struct device_info *dev);
void client_device_remove(int device_id);
diff --git a/usbmuxd/utils.c b/usbmuxd/utils.c
deleted file mode 100644
index 1ffa04a..0000000
--- a/usbmuxd/utils.c
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- usbmuxd - iPhone/iPod Touch USB multiplex server daemon
-
-Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 or version 3.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdlib.h>
-#include <string.h>
-#include "utils.h"
-#include "log.h"
-
-void fdlist_create(struct fdlist *list)
-{
- list->count = 0;
- list->capacity = 4;
- list->owners = malloc(sizeof(*list->owners) * list->capacity);
- list->fds = malloc(sizeof(*list->fds) * list->capacity);
-}
-void fdlist_add(struct fdlist *list, enum fdowner owner, int fd, short events)
-{
- if(list->count == list->capacity) {
- list->capacity *= 2;
- list->owners = realloc(list->owners, sizeof(*list->owners) * list->capacity);
- list->fds = realloc(list->fds, sizeof(*list->fds) * list->capacity);
- }
- list->owners[list->count] = owner;
- list->fds[list->count].fd = fd;
- list->fds[list->count].events = events;
- list->fds[list->count].revents = 0;
- list->count++;
-}
-
-void fdlist_free(struct fdlist *list)
-{
- list->count = 0;
- list->capacity = 0;
- free(list->owners);
- list->owners = NULL;
- free(list->fds);
- list->fds = NULL;
-}
-
-void collection_init(struct collection *col)
-{
- col->list = malloc(sizeof(void *));
- memset(col->list, 0, sizeof(void *));
- col->capacity = 1;
-}
-
-void collection_free(struct collection *col)
-{
- free(col->list);
- col->list = NULL;
- col->capacity = 0;
-}
-
-void collection_add(struct collection *col, void *element)
-{
- int i;
- for(i=0; i<col->capacity; i++) {
- if(!col->list[i]) {
- col->list[i] = element;
- return;
- }
- }
- col->list = realloc(col->list, sizeof(void*) * col->capacity * 2);
- memset(&col->list[col->capacity], 0, sizeof(void *) * col->capacity);
- col->list[col->capacity] = element;
- col->capacity *= 2;
-}
-
-void collection_remove(struct collection *col, void *element)
-{
- int i;
- for(i=0; i<col->capacity; i++) {
- if(col->list[i] == element) {
- col->list[i] = NULL;
- return;
- }
- }
- usbmuxd_log(LL_ERROR, "collection_remove: element %p not present in collection %p (cap %d)", element, col, col->capacity);
-}
-
-int collection_count(struct collection *col)
-{
- int i, cnt = 0;
- for(i=0; i<col->capacity; i++) {
- if(col->list[i])
- cnt++;
- }
- return cnt;
-}
diff --git a/usbmuxd/utils.h b/usbmuxd/utils.h
deleted file mode 100644
index ad4ac9d..0000000
--- a/usbmuxd/utils.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- usbmuxd - iPhone/iPod Touch USB multiplex server daemon
-
-Copyright (C) 2009 Hector Martin "marcan" <hector@marcansoft.com>
-
-This program is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 or version 3.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-
-*/
-
-#ifndef __UTILS_H__
-#define __UTILS_H__
-
-#include <poll.h>
-
-enum fdowner {
- FD_LISTEN,
- FD_CLIENT,
- FD_USB
-};
-
-struct fdlist {
- int count;
- int capacity;
- enum fdowner *owners;
- struct pollfd *fds;
-};
-
-void fdlist_create(struct fdlist *list);
-void fdlist_add(struct fdlist *list, enum fdowner owner, int fd, short events);
-void fdlist_free(struct fdlist *list);
-
-struct collection {
- void **list;
- int capacity;
-};
-
-void collection_init(struct collection *col);
-void collection_add(struct collection *col, void *element);
-void collection_remove(struct collection *col, void *element);
-int collection_count(struct collection *col);
-void collection_free(struct collection *col);
-
-#define FOREACH(var, col) \
- do { \
- int _iter; \
- for(_iter=0; _iter<(col)->capacity; _iter++) { \
- if(!(col)->list[_iter]) continue; \
- var = (col)->list[_iter];
-
-#define ENDFOREACH \
- } \
- } while(0);
-
-#endif