diff options
| author | 2009-03-26 12:28:05 +0100 | |
|---|---|---|
| committer | 2009-03-26 12:28:05 +0100 | |
| commit | a9d3cca2b5a5f3f4ff66ffa08795d102a3e72183 (patch) | |
| tree | 61478bc38ddfe24394276fda083e92f9ac4718b0 /iproxy.c | |
| parent | 659110808d9ceef21593baca51b2b11ae92b43a3 (diff) | |
| download | usbmuxd-a9d3cca2b5a5f3f4ff66ffa08795d102a3e72183.tar.gz usbmuxd-a9d3cca2b5a5f3f4ff66ffa08795d102a3e72183.tar.bz2 | |
adopted for "hello" -> "scan" rename
Diffstat (limited to 'iproxy.c')
| -rw-r--r-- | iproxy.c | 127 |
1 files changed, 16 insertions, 111 deletions
| @@ -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 | } |
