summaryrefslogtreecommitdiffstats
path: root/libusbmuxd.c
diff options
context:
space:
mode:
authorGravatar Paul Sladen2009-03-29 19:04:38 +0200
committerGravatar Nikias Bassen2009-03-29 19:04:38 +0200
commit15ea7e8a03ab519115b19b4b84c2ead96bf6c88c (patch)
treede0fb8f9ec61411d53bd82c9bdbed74a133f1bdc /libusbmuxd.c
parent50fc7586b2abf8a5ce999235c82d9de1bab98bfd (diff)
downloadusbmuxd-15ea7e8a03ab519115b19b4b84c2ead96bf6c88c.tar.gz
usbmuxd-15ea7e8a03ab519115b19b4b84c2ead96bf6c88c.tar.bz2
[PATCH] usbmuxd/libusbmuxd.h: separate logic from implementation
tweak public parameter and struct names for clarity fix usbmuxd_scan() to return number of devices per documentation expand public documentation in libusbmux.h Signed-off-by: Nikias Bassen <nikias@gmx.li>
Diffstat (limited to 'libusbmuxd.c')
-rw-r--r--libusbmuxd.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/libusbmuxd.c b/libusbmuxd.c
index 4e4ec10..ed331aa 100644
--- a/libusbmuxd.c
+++ b/libusbmuxd.c
@@ -7,7 +7,11 @@
#include <arpa/inet.h>
#include <unistd.h>
+// usbmuxd public interface
+#include <libusbmuxd.h>
+// usbmuxd protocol
#include <usbmuxd.h>
+// socket utility functions
#include "sock_stuff.h"
static int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result)
@@ -40,7 +44,7 @@ static int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result)
return -1;
}
-int usbmuxd_scan(usbmuxd_device_t **devices)
+int usbmuxd_scan(usbmuxd_scan_result **available_devices)
{
struct usbmuxd_scan_request s_req;
int sfd;
@@ -48,7 +52,7 @@ int usbmuxd_scan(usbmuxd_device_t **devices)
uint32_t res;
uint32_t pktlen;
int recv_len;
- usbmuxd_device_t *newlist = NULL;
+ usbmuxd_scan_result *newlist = NULL;
struct usbmuxd_device_info_record dev_info_pkt;
int dev_cnt = 0;
@@ -81,7 +85,7 @@ int usbmuxd_scan(usbmuxd_device_t **devices)
return -1;
}
- *devices = NULL;
+ *available_devices = NULL;
// receive device list
while (1) {
if (recv_buf_timeout(sfd, &pktlen, 4, MSG_PEEK, 500) == 4) {
@@ -99,10 +103,14 @@ int usbmuxd_scan(usbmuxd_device_t **devices)
fprintf(stderr, "%s: received less data than specified in header!\n", __func__);
} else {
//fprintf(stderr, "%s: got device record with id %d, UUID=%s\n", __func__, dev_info_pkt.device_info.device_id, dev_info_pkt.device_info.serial_number);
- newlist = (usbmuxd_device_t*)realloc(*devices, sizeof(usbmuxd_device_t) * (dev_cnt+1));
+ newlist = (usbmuxd_scan_result *)realloc(*available_devices, sizeof(usbmuxd_scan_result) * (dev_cnt+1));
if (newlist) {
- memcpy(newlist+dev_cnt, &dev_info_pkt.device, sizeof(usbmuxd_device_t));
- *devices = newlist;
+ newlist[dev_cnt].handle = (int)dev_info_pkt.device.device_id;
+ newlist[dev_cnt].product_id = dev_info_pkt.device.product_id;
+ memset(newlist[dev_cnt].serial_number, '\0', sizeof(newlist[dev_cnt].serial_number));
+ memcpy(newlist[dev_cnt].serial_number, dev_info_pkt.device.serial_number,
+ sizeof(dev_info_pkt.device.serial_number));
+ *available_devices = newlist;
dev_cnt++;
} else {
fprintf(stderr, "%s: ERROR: out of memory when trying to realloc!\n", __func__);
@@ -117,14 +125,14 @@ int usbmuxd_scan(usbmuxd_device_t **devices)
}
// terminating zero record
- newlist = (usbmuxd_device_t*)realloc(*devices, sizeof(usbmuxd_device_t) * (dev_cnt+1));
- memset(newlist+dev_cnt, 0, sizeof(usbmuxd_device_t));
- *devices = newlist;
+ newlist = (usbmuxd_scan_result *)realloc(*available_devices, sizeof(usbmuxd_scan_result) * (dev_cnt+1));
+ memset(newlist+dev_cnt, 0, sizeof(usbmuxd_scan_result));
+ *available_devices = newlist;
- return 0;
+ return dev_cnt;
}
-int usbmuxd_connect(uint32_t device_id, uint16_t port)
+int usbmuxd_connect(const int handle, const unsigned short tcp_port)
{
int sfd;
struct usbmuxd_connect_request c_req;
@@ -141,8 +149,8 @@ int usbmuxd_connect(uint32_t device_id, uint16_t port)
c_req.header.reserved = 0;
c_req.header.type = USBMUXD_CONNECT;
c_req.header.tag = 3;
- c_req.device_id = device_id;
- c_req.tcp_dport = htons(port);
+ c_req.device_id = (uint32_t)handle;
+ c_req.tcp_dport = htons(tcp_port);
c_req.reserved = 0;
if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) {