The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

st/prober: Support for querying of 'Product name' from Bluetooth devices.

authored by

Nima01 and committed by
Jakob Bornecrantz
2a1e6deb a081bacc

+44 -18
+1
src/xrt/include/xrt/xrt_device.h
··· 11 11 #pragma once 12 12 13 13 #define XRT_DEVICE_NAME_LEN 256 14 + #define XRT_DEVICE_PRODUCT_NAME_LEN 64 // Incl. termination 14 15 15 16 #include "xrt/xrt_defines.h" 16 17
+1
src/xrt/include/xrt/xrt_prober.h
··· 131 131 { 132 132 uint16_t vendor_id; 133 133 uint16_t product_id; 134 + char product_name[XRT_DEVICE_PRODUCT_NAME_LEN]; 134 135 135 136 enum xrt_bus_type bus; 136 137
+24 -11
src/xrt/state_trackers/prober/p_prober.c
··· 279 279 char *str = NULL; 280 280 int ret = 0; 281 281 do { 282 - ret = snprintf(str, ret, "Unknown %s device: %04x:%04x", bus, pdev->base.vendor_id, 283 - pdev->base.product_id); 282 + if (strlen(pdev->base.product_name)) { 283 + 284 + ret = snprintf(str, ret, "%s device: %s", bus, pdev->base.product_name); 285 + } else { 286 + ret = snprintf(str, ret, "Unknown %s device: %04x:%04x", bus, pdev->base.vendor_id, 287 + pdev->base.product_id); 288 + } 284 289 if (ret <= 0) { 285 290 return; 286 291 } ··· 1107 1112 } 1108 1113 } 1109 1114 #endif 1110 - if (pdev->base.bus == XRT_BUS_TYPE_BLUETOOTH && which_string == XRT_PROBER_STRING_SERIAL_NUMBER) { 1111 - union { 1112 - uint8_t arr[8]; 1113 - uint64_t v; 1114 - } u; 1115 - u.v = pdev->bluetooth.id; 1116 - return snprintf((char *)buffer, max_length, "%02X:%02X:%02X:%02X:%02X:%02X", u.arr[5], u.arr[4], 1117 - u.arr[3], u.arr[2], u.arr[1], u.arr[0]); 1115 + if (pdev && pdev->base.bus == XRT_BUS_TYPE_BLUETOOTH) { 1116 + switch (which_string) { 1117 + case XRT_PROBER_STRING_SERIAL_NUMBER: { 1118 + union { 1119 + uint8_t arr[8]; 1120 + uint64_t v; 1121 + } u; 1122 + u.v = pdev->bluetooth.id; 1123 + ret = snprintf((char *)buffer, max_length, "%02X:%02X:%02X:%02X:%02X:%02X", u.arr[5], u.arr[4], 1124 + u.arr[3], u.arr[2], u.arr[1], u.arr[0]); 1125 + }; break; 1126 + case XRT_PROBER_STRING_PRODUCT: 1127 + ret = snprintf((char *)buffer, max_length, "%s", pdev->base.product_name); 1128 + break; 1129 + default: ret = 0; break; 1130 + } 1118 1131 } 1119 1132 1120 1133 //! @todo add more backends 1121 1134 //! @todo make this unicode (utf-16)? utf-8 would be better... 1122 - return 0; 1135 + return ret; 1123 1136 } 1124 1137 1125 1138 static bool
+18 -7
src/xrt/state_trackers/prober/p_udev.c
··· 55 55 p_udev_enumerate_hidraw(struct prober *p, struct udev *udev); 56 56 57 57 static void 58 - p_udev_add_hidraw(struct prober_device *pdev, uint32_t interface, const char *path); 58 + p_udev_add_hidraw(struct prober_device *pdev, uint32_t interface, const char *path, const char *product_name); 59 59 60 60 static int 61 61 p_udev_get_interface_number(struct udev_device *raw_dev, uint16_t *interface_number); ··· 65 65 uint32_t *out_bus_type, 66 66 uint16_t *out_vendor_id, 67 67 uint16_t *out_product_id, 68 + char (*out_product_name)[XRT_DEVICE_PRODUCT_NAME_LEN], 68 69 uint64_t *out_bluetooth_serial); 69 70 70 71 static int ··· 388 389 uint16_t usb_addr = 0; 389 390 uint32_t bus_type = 0; 390 391 uint64_t bluetooth_id = 0; 392 + char product_name[XRT_DEVICE_PRODUCT_NAME_LEN] = {0}; 391 393 const char *sysfs_path; 392 394 const char *dev_path; 393 395 int ret; ··· 400 402 dev_path = udev_device_get_devnode(raw_dev); 401 403 402 404 // Bus type, vendor_id and product_id. 403 - ret = p_udev_get_and_parse_uevent(raw_dev, &bus_type, &vendor_id, &product_id, &bluetooth_id); 405 + ret = p_udev_get_and_parse_uevent(raw_dev, &bus_type, &vendor_id, &product_id, &product_name, 406 + &bluetooth_id); 404 407 if (ret != 0) { 405 408 P_ERROR(p, "Failed to get uevent info from device"); 406 409 goto next; ··· 451 454 "\t\tbus_type: %i\n" 452 455 "\t\tvendor_id: %04x\n" 453 456 "\t\tproduct_id: %04x\n" 457 + "\t\tproduct_name: '%s'\n" 454 458 "\t\tinterface: %i\n" 455 459 "\t\tusb_bus: %i\n" 456 460 "\t\tusb_addr: %i\n" 457 461 "\t\tbluetooth_id: %012" PRIx64, 458 - (void *)pdev, ret, sysfs_path, dev_path, bus_type, vendor_id, product_id, interface, usb_bus, 459 - usb_addr, bluetooth_id); 462 + (void *)pdev, ret, sysfs_path, dev_path, bus_type, vendor_id, product_id, product_name, 463 + interface, usb_bus, usb_addr, bluetooth_id); 460 464 461 465 if (ret != 0) { 462 466 P_ERROR(p, "p_dev_get_usb_device failed!"); ··· 464 468 } 465 469 466 470 // Add this interface to the usb device. 467 - p_udev_add_hidraw(pdev, interface, dev_path); 471 + p_udev_add_hidraw(pdev, interface, dev_path, product_name); 468 472 469 473 next: 470 474 udev_device_unref(raw_dev); ··· 474 478 } 475 479 476 480 static void 477 - p_udev_add_hidraw(struct prober_device *pdev, uint32_t interface, const char *path) 481 + p_udev_add_hidraw(struct prober_device *pdev, uint32_t interface, const char *path, const char *product_name) 478 482 { 479 483 U_ARRAY_REALLOC_OR_FREE(pdev->hidraws, struct prober_hidraw, (pdev->num_hidraws + 1)); 480 484 ··· 483 487 484 488 hidraw->interface = interface; 485 489 hidraw->path = strdup(path); 490 + strncpy(pdev->base.product_name, product_name, 64); 486 491 } 487 492 488 493 static int ··· 538 543 uint32_t *out_bus_type, 539 544 uint16_t *out_vendor_id, 540 545 uint16_t *out_product_id, 546 + char (*out_product_name)[XRT_DEVICE_PRODUCT_NAME_LEN], 541 547 uint64_t *out_bluetooth_serial) 542 548 { 543 549 struct udev_device *hid_dev; 544 550 char *serial_utf8 = NULL; 545 551 uint64_t bluetooth_serial = 0; 546 552 uint16_t vendor_id = 0, product_id = 0; 553 + char product_name[sizeof(*out_product_name)]; 547 554 uint32_t bus_type; 548 555 const char *uevent; 549 556 char *saveptr; ··· 576 583 ok = true; 577 584 } 578 585 } else if (strncmp(line, "HID_NAME=", 9) == 0) { 579 - // U_LOG_D("\t\tprocuct_name: '%s'", line + 9); 586 + product_name[0] = '\0'; 587 + strncat(product_name, line + 9, sizeof(product_name)); 588 + 589 + // U_LOG_D("\t\tprocuct_name: '%s'", *out_product_name); 580 590 } else if (strncmp(line, "HID_UNIQ=", 9) == 0) { 581 591 serial_utf8 = &line[9]; 582 592 // U_LOG_D("\t\tserial: '%s'", line + 9); ··· 604 614 *out_bus_type = bus_type; 605 615 *out_vendor_id = vendor_id; 606 616 *out_product_id = product_id; 617 + strncpy(*out_product_name, product_name, sizeof(*out_product_name)); 607 618 *out_bluetooth_serial = bluetooth_serial; 608 619 return 0; 609 620 }