| 538 | } |
| 539 | |
| 540 | static struct hid_device_info *create_device_info_with_usage(IOHIDDeviceRef dev, int32_t usage_page, int32_t usage) |
| 541 | { |
| 542 | unsigned short dev_vid; |
| 543 | unsigned short dev_pid; |
| 544 | int BUF_LEN = 256; |
| 545 | wchar_t buf[BUF_LEN]; |
| 546 | CFTypeRef transport_prop; |
| 547 | |
| 548 | struct hid_device_info *cur_dev; |
| 549 | io_service_t hid_service; |
| 550 | kern_return_t res; |
| 551 | uint64_t entry_id = 0; |
| 552 | |
| 553 | if (dev == NULL) { |
| 554 | return NULL; |
| 555 | } |
| 556 | |
| 557 | cur_dev = (struct hid_device_info *)calloc(1, sizeof(struct hid_device_info)); |
| 558 | if (cur_dev == NULL) { |
| 559 | return NULL; |
| 560 | } |
| 561 | |
| 562 | dev_vid = get_vendor_id(dev); |
| 563 | dev_pid = get_product_id(dev); |
| 564 | |
| 565 | cur_dev->usage_page = usage_page; |
| 566 | cur_dev->usage = usage; |
| 567 | |
| 568 | /* Fill out the record */ |
| 569 | cur_dev->next = NULL; |
| 570 | |
| 571 | /* Fill in the path (as a unique ID of the service entry) */ |
| 572 | cur_dev->path = NULL; |
| 573 | hid_service = IOHIDDeviceGetService(dev); |
| 574 | if (hid_service != MACH_PORT_NULL) { |
| 575 | res = IORegistryEntryGetRegistryEntryID(hid_service, &entry_id); |
| 576 | } |
| 577 | else { |
| 578 | res = KERN_INVALID_ARGUMENT; |
| 579 | } |
| 580 | |
| 581 | if (res == KERN_SUCCESS) { |
| 582 | /* max value of entry_id(uint64_t) is 18446744073709551615 which is 20 characters long, |
| 583 | so for (max) "path" string 'DevSrvsID:18446744073709551615' we would need |
| 584 | 9+1+20+1=31 bytes buffer, but allocate 32 for simple alignment */ |
| 585 | const size_t path_len = 32; |
| 586 | cur_dev->path = calloc(1, path_len); |
| 587 | if (cur_dev->path != NULL) { |
| 588 | snprintf(cur_dev->path, path_len, "DevSrvsID:%llu", entry_id); |
| 589 | } |
| 590 | } |
| 591 | |
| 592 | if (cur_dev->path == NULL) { |
| 593 | /* for whatever reason, trying to keep it a non-NULL string */ |
| 594 | cur_dev->path = strdup(""); |
| 595 | } |
| 596 | |
| 597 | /* Serial Number */ |
no test coverage detected