summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2009-03-26 12:28:05 +0100
committerGravatar Nikias Bassen2009-03-26 12:28:05 +0100
commita9d3cca2b5a5f3f4ff66ffa08795d102a3e72183 (patch)
tree61478bc38ddfe24394276fda083e92f9ac4718b0
parent659110808d9ceef21593baca51b2b11ae92b43a3 (diff)
downloadusbmuxd-a9d3cca2b5a5f3f4ff66ffa08795d102a3e72183.tar.gz
usbmuxd-a9d3cca2b5a5f3f4ff66ffa08795d102a3e72183.tar.bz2
adopted for "hello" -> "scan" rename
-rw-r--r--iproxy.c127
-rw-r--r--testclient.c32
2 files changed, 32 insertions, 127 deletions
diff --git a/iproxy.c b/iproxy.c
index 775b819..93bbf89 100644
--- a/iproxy.c
+++ b/iproxy.c
@@ -179,12 +179,12 @@ void *acceptor_thread(void *arg)
179{ 179{
180 struct client_data *cdata; 180 struct client_data *cdata;
181 int recv_len = 0; 181 int recv_len = 0;
182 int hello_done; 182 int scan_done;
183 int connected; 183 int connected;
184 uint32_t pktlen; 184 uint32_t pktlen;
185 unsigned char *buf; 185 unsigned char *buf;
186 struct usbmuxd_hello hello; 186 struct usbmuxd_scan_request scan;
187 struct usbmuxd_device_info device_info; 187 struct am_device_info device_info;
188 pthread_t ctos; 188 pthread_t ctos;
189 189
190 if (!arg) { 190 if (!arg) {
@@ -200,24 +200,24 @@ void *acceptor_thread(void *arg)
200 return NULL; 200 return NULL;
201 } 201 }
202 202
203 // send hello 203 // send scan
204 hello.header.length = sizeof(struct usbmuxd_hello); 204 scan.header.length = sizeof(struct usbmuxd_scan_request);
205 hello.header.reserved = 0; 205 scan.header.reserved = 0;
206 hello.header.type = USBMUXD_HELLO; 206 scan.header.type = USBMUXD_SCAN;
207 hello.header.tag = 2; 207 scan.header.tag = 2;
208 208
209 hello_done = 0; 209 scan_done = 0;
210 connected = 0; 210 connected = 0;
211 211
212 fprintf(stdout, "sending Hello packet\n"); 212 fprintf(stdout, "sending scan packet\n");
213 if (send(cdata->sfd, &hello, hello.header.length, 0) == hello.header.length) { 213 if (send(cdata->sfd, &scan, scan.header.length, 0) == scan.header.length) {
214 uint32_t res = -1; 214 uint32_t res = -1;
215 // get response 215 // get response
216 if (usbmuxd_get_result(cdata->sfd, hello.header.tag, &res) && (res==0)) { 216 if (usbmuxd_get_result(cdata->sfd, scan.header.tag, &res) && (res==0)) {
217 fprintf(stdout, "Got Hello Response!\n"); 217 fprintf(stdout, "Got response to scan request!\n");
218 hello_done = 1; 218 scan_done = 1;
219 } else { 219 } else {
220 fprintf(stderr, "Did not get Hello response (with result=0)...\n"); 220 fprintf(stderr, "Did not get response to scan request (with result=0)...\n");
221 close(cdata->sfd); 221 close(cdata->sfd);
222 cdata->sfd = -1; 222 cdata->sfd = -1;
223 return NULL; 223 return NULL;
@@ -225,7 +225,7 @@ void *acceptor_thread(void *arg)
225 225
226 device_info.device_id = 0; 226 device_info.device_id = 0;
227 227
228 if (hello_done) { 228 if (scan_done) {
229 // get all devices 229 // get all devices
230 while (1) { 230 while (1) {
231 if (recv_buf_timeout(cdata->sfd, &pktlen, 4, MSG_PEEK, 1000) == 4) { 231 if (recv_buf_timeout(cdata->sfd, &pktlen, 4, MSG_PEEK, 1000) == 4) {
@@ -343,100 +343,5 @@ int main(int argc, char **argv)
343 close(mysock); 343 close(mysock);
344 } 344 }
345 345
346/*
347 sfd = connect_unix_socket(USBMUXD_SOCKET_FILE);
348 if (sfd < 0) {
349 printf("error opening socket, terminating.\n");
350 return -1;
351 }
352
353 // send hello
354 hello.header.length = sizeof(hello);
355 hello.header.reserved = 0;
356 hello.header.type = USBMUXD_HELLO;
357 hello.header.tag = 2;
358
359 hello_done = 0;
360 connected = 0;
361
362 fprintf(stdout, "sending Hello packet\n");
363 if (send(sfd, &hello, hello.header.length, 0) == hello.header.length) {
364 uint32_t res = -1;
365 // get response
366 if (usbmuxd_get_result(sfd, hello.header.tag, &res) && (res==0)) {
367 fprintf(stdout, "Got Hello Response!\n");
368 hello_done = 1;
369 } else {
370 fprintf(stderr, "Did not get Hello response (with result=0)...\n");
371 close(sfd);
372 return -1;
373 }
374
375 device_info.device_id = 0;
376
377 if (hello_done) {
378 // get all devices
379 while (1) {
380 if (recv_buf_timeout(sfd, &pktlen, 4, MSG_PEEK, 1000) == 4) {
381 buf = (unsigned char*)malloc(pktlen);
382 if (!buf) {
383 exit(-ENOMEM);
384 }
385 recv_len = recv_buf(sfd, buf, pktlen);
386 if (recv_len < pktlen) {
387 fprintf(stdout, "received less data than specified in header!\n");
388 }
389 fprintf(stdout, "Received device data\n");
390 //log_debug_buffer(stdout, (char*)buf, pktlen);
391 memcpy(&device_info, buf + sizeof(struct usbmuxd_header), sizeof(device_info));
392 free(buf);
393 } else {
394 // we _should_ have all of them now.
395 // or perhaps an error occured.
396 break;
397 }
398 }
399 }
400
401 if (device_info.device_id > 0) {
402 struct usbmuxd_connect_request c_req;
403
404 fprintf(stdout, "Requesting connecion to device %d port %d\n", device_info.device_id, device_port);
405
406 // try to connect to last device found
407 c_req.header.length = sizeof(c_req);
408 c_req.header.reserved = 0;
409 c_req.header.type = USBMUXD_CONNECT;
410 c_req.header.tag = 3;
411 c_req.device_id = device_info.device_id;
412 c_req.tcp_dport = htons(device_port);
413 c_req.reserved = 0;
414
415 if (send_buf(sfd, &c_req, sizeof(c_req)) < 0) {
416 perror("send");
417 } else {
418 // read ACK
419 res = -1;
420 fprintf(stdout, "Reading connect result...\n");
421 if (usbmuxd_get_result(sfd, c_req.header.tag, &res)) {
422 if (res == 0) {
423 fprintf(stdout, "Connect success!\n");
424 connected = 1;
425 } else {
426 fprintf(stderr, "Connect failed, Error code=%d\n", res);
427 }
428 }
429 }
430 }
431
432 if (connected) {
433 //
434 } else {
435 fprintf(stderr, "No attached device found?!\n");
436 }
437 }
438 close(sfd);
439*/
440
441 return 0; 346 return 0;
442} 347}
diff --git a/testclient.c b/testclient.c
index 679b6d0..dc2dd28 100644
--- a/testclient.c
+++ b/testclient.c
@@ -44,12 +44,12 @@ int main(int argc, char **argv)
44{ 44{
45 int sfd; 45 int sfd;
46 int recv_len = 0; 46 int recv_len = 0;
47 int hello_done; 47 int scan_done;
48 int connected; 48 int connected;
49 uint32_t pktlen; 49 uint32_t pktlen;
50 unsigned char *buf; 50 unsigned char *buf;
51 struct usbmuxd_hello hello; 51 struct usbmuxd_scan_request scan;
52 struct usbmuxd_device_info device_info; 52 struct am_device_info device_info;
53 53
54 sfd = connect_unix_socket(USBMUXD_SOCKET_FILE); 54 sfd = connect_unix_socket(USBMUXD_SOCKET_FILE);
55 if (sfd < 0) { 55 if (sfd < 0) {
@@ -57,31 +57,31 @@ int main(int argc, char **argv)
57 return -1; 57 return -1;
58 } 58 }
59 59
60 // send hello 60 // send scan
61 hello.header.length = sizeof(struct usbmuxd_hello); 61 scan.header.length = sizeof(struct usbmuxd_scan_request);
62 hello.header.reserved = 0; 62 scan.header.reserved = 0;
63 hello.header.type = USBMUXD_HELLO; 63 scan.header.type = USBMUXD_SCAN;
64 hello.header.tag = 2; 64 scan.header.tag = 2;
65 65
66 hello_done = 0; 66 scan_done = 0;
67 connected = 0; 67 connected = 0;
68 68
69 fprintf(stdout, "sending Hello packet\n"); 69 fprintf(stdout, "sending scan packet\n");
70 if (send(sfd, &hello, hello.header.length, 0) == hello.header.length) { 70 if (send(sfd, &scan, scan.header.length, 0) == scan.header.length) {
71 uint32_t res = -1; 71 uint32_t res = -1;
72 // get response 72 // get response
73 if (usbmuxd_get_result(sfd, hello.header.tag, &res) && (res==0)) { 73 if (usbmuxd_get_result(sfd, scan.header.tag, &res) && (res==0)) {
74 fprintf(stdout, "Got Hello Response!\n"); 74 fprintf(stdout, "Got response to scan request!\n");
75 hello_done = 1; 75 scan_done = 1;
76 } else { 76 } else {
77 fprintf(stderr, "Did not get Hello response (with result=0)...\n"); 77 fprintf(stderr, "Did not get response to scan request (with result=0)...\n");
78 close(sfd); 78 close(sfd);
79 return -1; 79 return -1;
80 } 80 }
81 81
82 device_info.device_id = 0; 82 device_info.device_id = 0;
83 83
84 if (hello_done) { 84 if (scan_done) {
85 // get all devices 85 // get all devices
86 while (1) { 86 while (1) {
87 if (recv_buf_timeout(sfd, &pktlen, 4, MSG_PEEK, 1000) == 4) { 87 if (recv_buf_timeout(sfd, &pktlen, 4, MSG_PEEK, 1000) == 4) {