diff options
Diffstat (limited to 'libusbmuxd/libusbmuxd.c')
| -rw-r--r-- | libusbmuxd/libusbmuxd.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/libusbmuxd/libusbmuxd.c b/libusbmuxd/libusbmuxd.c index 584e930..a00ceb0 100644 --- a/libusbmuxd/libusbmuxd.c +++ b/libusbmuxd/libusbmuxd.c | |||
| @@ -296,7 +296,7 @@ int usbmuxd_unsubscribe() | |||
| 296 | return 0; | 296 | return 0; |
| 297 | } | 297 | } |
| 298 | 298 | ||
| 299 | int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | 299 | int usbmuxd_get_device_list(usbmuxd_device_info_t **device_list) |
| 300 | { | 300 | { |
| 301 | struct usbmuxd_listen_request s_req; | 301 | struct usbmuxd_listen_request s_req; |
| 302 | int sfd; | 302 | int sfd; |
| @@ -340,7 +340,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 340 | return -1; | 340 | return -1; |
| 341 | } | 341 | } |
| 342 | 342 | ||
| 343 | *available_devices = NULL; | 343 | *device_list = NULL; |
| 344 | // receive device list | 344 | // receive device list |
| 345 | while (1) { | 345 | while (1) { |
| 346 | if (recv_buf_timeout(sfd, &hdr, sizeof(hdr), 0, 1000) == sizeof(hdr)) { | 346 | if (recv_buf_timeout(sfd, &hdr, sizeof(hdr), 0, 1000) == sizeof(hdr)) { |
| @@ -362,7 +362,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 362 | fprintf(stderr, | 362 | fprintf(stderr, |
| 363 | "%s: received less data than specified in header!\n", __func__); | 363 | "%s: received less data than specified in header!\n", __func__); |
| 364 | } else { | 364 | } else { |
| 365 | newlist = (usbmuxd_device_info_t *) realloc(*available_devices, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); | 365 | newlist = (usbmuxd_device_info_t *) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); |
| 366 | if (newlist) { | 366 | if (newlist) { |
| 367 | newlist[dev_cnt].handle = | 367 | newlist[dev_cnt].handle = |
| 368 | (int) dev_info.device_id; | 368 | (int) dev_info.device_id; |
| @@ -373,7 +373,7 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 373 | memcpy(newlist[dev_cnt].uuid, | 373 | memcpy(newlist[dev_cnt].uuid, |
| 374 | dev_info.serial_number, | 374 | dev_info.serial_number, |
| 375 | sizeof(newlist[dev_cnt].uuid)); | 375 | sizeof(newlist[dev_cnt].uuid)); |
| 376 | *available_devices = newlist; | 376 | *device_list = newlist; |
| 377 | dev_cnt++; | 377 | dev_cnt++; |
| 378 | } else { | 378 | } else { |
| 379 | fprintf(stderr, | 379 | fprintf(stderr, |
| @@ -390,13 +390,48 @@ int usbmuxd_scan(usbmuxd_device_info_t ** available_devices) | |||
| 390 | } | 390 | } |
| 391 | 391 | ||
| 392 | // terminating zero record | 392 | // terminating zero record |
| 393 | newlist = (usbmuxd_device_info_t*) realloc(*available_devices, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); | 393 | newlist = (usbmuxd_device_info_t*) realloc(*device_list, sizeof(usbmuxd_device_info_t) * (dev_cnt + 1)); |
| 394 | memset(newlist + dev_cnt, 0, sizeof(usbmuxd_device_info_t)); | 394 | memset(newlist + dev_cnt, 0, sizeof(usbmuxd_device_info_t)); |
| 395 | *available_devices = newlist; | 395 | *device_list = newlist; |
| 396 | 396 | ||
| 397 | return dev_cnt; | 397 | return dev_cnt; |
| 398 | } | 398 | } |
| 399 | 399 | ||
| 400 | int usbmuxd_get_device_by_uuid(const char *uuid, usbmuxd_device_info_t *device) | ||
| 401 | { | ||
| 402 | usbmuxd_device_info_t *dev_list = NULL; | ||
| 403 | |||
| 404 | if (!device) { | ||
| 405 | return -EINVAL; | ||
| 406 | } | ||
| 407 | if (usbmuxd_get_device_list(&dev_list) < 0) { | ||
| 408 | return -ENODEV; | ||
| 409 | } | ||
| 410 | |||
| 411 | int i; | ||
| 412 | int result = 0; | ||
| 413 | for (i = 0; dev_list[i].handle > 0; i++) { | ||
| 414 | if (!uuid) { | ||
| 415 | device->handle = dev_list[i].handle; | ||
| 416 | device->product_id = dev_list[i].product_id; | ||
| 417 | strcpy(device->uuid, dev_list[i].uuid); | ||
| 418 | result = 1; | ||
| 419 | break; | ||
| 420 | } | ||
| 421 | if (!strcmp(uuid, dev_list[i].uuid)) { | ||
| 422 | device->handle = dev_list[i].handle; | ||
| 423 | device->product_id = dev_list[i].product_id; | ||
| 424 | strcpy(device->uuid, dev_list[i].uuid); | ||
| 425 | result = 1; | ||
| 426 | break; | ||
| 427 | } | ||
| 428 | } | ||
| 429 | |||
| 430 | free(dev_list); | ||
| 431 | |||
| 432 | return result; | ||
| 433 | } | ||
| 434 | |||
| 400 | int usbmuxd_connect(const int handle, const unsigned short port) | 435 | int usbmuxd_connect(const int handle, const unsigned short port) |
| 401 | { | 436 | { |
| 402 | int sfd; | 437 | int sfd; |
