diff options
| author | 2009-03-28 01:29:57 +0100 | |
|---|---|---|
| committer | 2009-03-28 01:29:57 +0100 | |
| commit | 50fc7586b2abf8a5ce999235c82d9de1bab98bfd (patch) | |
| tree | 9d40ee339ca716bb43ad57817a4c0dc76b76d3b6 /testclient.c | |
| parent | 91d76eb4e449dec0cb23d56886817d9910963559 (diff) | |
| download | usbmuxd-50fc7586b2abf8a5ce999235c82d9de1bab98bfd.tar.gz usbmuxd-50fc7586b2abf8a5ce999235c82d9de1bab98bfd.tar.bz2 | |
debugging output fixed
'libusbmuxd' added to simplify use of usbmuxd in external tools
testclient removed
setting of configuration 3 disabled (to be handled by udev)
Diffstat (limited to 'testclient.c')
| -rw-r--r-- | testclient.c | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/testclient.c b/testclient.c deleted file mode 100644 index dc2dd28..0000000 --- a/testclient.c +++ /dev/null | |||
| @@ -1,146 +0,0 @@ | |||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <stddef.h> | ||
| 5 | #include <sys/socket.h> | ||
| 6 | #include <sys/un.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <arpa/inet.h> | ||
| 10 | #include "usbmuxd.h" | ||
| 11 | #include "sock_stuff.h" | ||
| 12 | |||
| 13 | int usbmuxd_get_result(int sfd, uint32_t tag, uint32_t *result) | ||
| 14 | { | ||
| 15 | struct usbmuxd_result res; | ||
| 16 | int recv_len; | ||
| 17 | |||
| 18 | if (!result) { | ||
| 19 | return -EINVAL; | ||
| 20 | } | ||
| 21 | |||
| 22 | if ((recv_len = recv_buf(sfd, &res, sizeof(res))) <= 0) { | ||
| 23 | perror("recv"); | ||
| 24 | return -errno; | ||
| 25 | } else { | ||
| 26 | if ((recv_len == sizeof(res)) | ||
| 27 | && (res.header.length == recv_len) | ||
| 28 | && (res.header.reserved == 0) | ||
| 29 | && (res.header.type == USBMUXD_RESULT) | ||
| 30 | ) { | ||
| 31 | *result = res.result; | ||
| 32 | if (res.header.tag == tag) { | ||
| 33 | return 1; | ||
| 34 | } else { | ||
| 35 | return 0; | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | return -1; | ||
| 41 | } | ||
| 42 | |||
| 43 | int main(int argc, char **argv) | ||
| 44 | { | ||
| 45 | int sfd; | ||
| 46 | int recv_len = 0; | ||
| 47 | int scan_done; | ||
| 48 | int connected; | ||
| 49 | uint32_t pktlen; | ||
| 50 | unsigned char *buf; | ||
| 51 | struct usbmuxd_scan_request scan; | ||
| 52 | struct am_device_info device_info; | ||
| 53 | |||
| 54 | sfd = connect_unix_socket(USBMUXD_SOCKET_FILE); | ||
| 55 | if (sfd < 0) { | ||
| 56 | printf("error opening socket, terminating.\n"); | ||
| 57 | return -1; | ||
| 58 | } | ||
| 59 | |||
| 60 | // send scan | ||
| 61 | scan.header.length = sizeof(struct usbmuxd_scan_request); | ||
| 62 | scan.header.reserved = 0; | ||
| 63 | scan.header.type = USBMUXD_SCAN; | ||
| 64 | scan.header.tag = 2; | ||
| 65 | |||
| 66 | scan_done = 0; | ||
| 67 | connected = 0; | ||
| 68 | |||
| 69 | fprintf(stdout, "sending scan packet\n"); | ||
| 70 | if (send(sfd, &scan, scan.header.length, 0) == scan.header.length) { | ||
| 71 | uint32_t res = -1; | ||
| 72 | // get response | ||
| 73 | if (usbmuxd_get_result(sfd, scan.header.tag, &res) && (res==0)) { | ||
| 74 | fprintf(stdout, "Got response to scan request!\n"); | ||
| 75 | scan_done = 1; | ||
| 76 | } else { | ||
| 77 | fprintf(stderr, "Did not get response to scan request (with result=0)...\n"); | ||
| 78 | close(sfd); | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | |||
| 82 | device_info.device_id = 0; | ||
| 83 | |||
| 84 | if (scan_done) { | ||
| 85 | // get all devices | ||
| 86 | while (1) { | ||
| 87 | if (recv_buf_timeout(sfd, &pktlen, 4, MSG_PEEK, 1000) == 4) { | ||
| 88 | buf = (unsigned char*)malloc(pktlen); | ||
| 89 | if (!buf) { | ||
| 90 | exit(-ENOMEM); | ||
| 91 | } | ||
| 92 | recv_len = recv_buf(sfd, buf, pktlen); | ||
| 93 | if (recv_len < pktlen) { | ||
| 94 | fprintf(stdout, "received less data than specified in header!\n"); | ||
| 95 | } | ||
| 96 | fprintf(stdout, "got device data:\n"); | ||
| 97 | //log_debug_buffer(stdout, (char*)buf, pktlen); | ||
| 98 | memcpy(&device_info, buf + sizeof(struct usbmuxd_header), sizeof(device_info)); | ||
| 99 | free(buf); | ||
| 100 | } else { | ||
| 101 | // we _should_ have all of them now. | ||
| 102 | // or perhaps an error occured. | ||
| 103 | break; | ||
| 104 | } | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | if (device_info.device_id > 0) { | ||
| 109 | struct usbmuxd_connect_request c_req; | ||
| 110 | |||
| 111 | // try to connect to last device found | ||
| 112 | c_req.header.length = sizeof(c_req); | ||
| 113 | c_req.header.reserved = 0; | ||
| 114 | c_req.header.type = USBMUXD_CONNECT; | ||
| 115 | c_req.header.tag = 3; | ||
| 116 | c_req.device_id = device_info.device_id; | ||
| 117 | c_req.tcp_dport = htons(22); | ||
| 118 | c_req.reserved = 0; | ||
| 119 | |||
| 120 | if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) { | ||
| 121 | perror("send"); | ||
| 122 | } else { | ||
| 123 | // read ACK | ||
| 124 | res = -1; | ||
| 125 | if (usbmuxd_get_result(sfd, c_req.header.tag, &res)) { | ||
| 126 | if (res == 0) { | ||
| 127 | fprintf(stdout, "Connect success!\n"); | ||
| 128 | connected = 1; | ||
| 129 | } else { | ||
| 130 | fprintf(stderr, "Connect failed, Error code=%d\n", res); | ||
| 131 | } | ||
| 132 | } | ||
| 133 | } | ||
| 134 | } | ||
| 135 | |||
| 136 | if (connected) { | ||
| 137 | |||
| 138 | |||
| 139 | // do communication now. | ||
| 140 | sleep(10); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | close(sfd); | ||
| 144 | |||
| 145 | return 0; | ||
| 146 | } | ||
