The open source OpenXR runtime
0
fork

Configure Feed

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

st/prober: Print serial, product and manufacturer from udev

+45 -10
+45 -10
src/xrt/state_trackers/prober/p_udev.c
··· 84 84 uint16_t *out_vendor_id, 85 85 uint16_t *out_product_id, 86 86 uint16_t *out_usb_bus, 87 - uint16_t *out_usb_addr); 87 + uint16_t *out_usb_addr, 88 + struct udev_device **out_usb_device); 88 89 89 90 static int 90 91 p_udev_get_vendor_id_product(struct udev_device *usb_device_dev, ··· 174 175 struct udev_device *raw_dev = NULL; 175 176 const char *sysfs_path = NULL; 176 177 const char *dev_path = NULL; 178 + const char *serial = NULL; 177 179 const char *product = NULL; 180 + const char *manufacturer = NULL; 178 181 uint8_t dev_class = 0; 179 182 uint16_t vendor_id = 0; 180 183 uint16_t product_id = 0; ··· 188 191 raw_dev = udev_device_new_from_syspath(udev, sysfs_path); 189 192 // The thing we will open. 190 193 dev_path = udev_device_get_devnode(raw_dev); 194 + // Serial number. 195 + serial = udev_device_get_sysattr_value(raw_dev, "serial"); 191 196 // Product name. 192 197 product = udev_device_get_sysattr_value(raw_dev, "product"); 198 + // Manufacturer name. 199 + manufacturer = 200 + udev_device_get_sysattr_value(raw_dev, "manufacturer"); 193 201 194 202 195 203 ret = p_udev_get_usb_device_info(raw_dev, &dev_class, ··· 213 221 "\t\tproduct_id: %04x\n" 214 222 "\t\tusb_bus: %i\n" 215 223 "\t\tusb_addr: %i\n" 216 - "\t\tproduct: '%s'", 224 + "\t\tserial: '%s'\n" 225 + "\t\tproduct: '%s'\n" 226 + "\t\tmanufacturer: '%s'", 217 227 (void *)pdev, ret, sysfs_path, dev_path, dev_class, 218 - vendor_id, product_id, usb_bus, usb_addr, product); 228 + vendor_id, product_id, usb_bus, usb_addr, serial, 229 + product, manufacturer); 219 230 220 231 if (ret != 0) { 221 232 P_ERROR(p, "p_dev_get_usb_device failed!"); ··· 264 275 { 265 276 struct prober_device *pdev = NULL; 266 277 struct udev_device *raw_dev = NULL; 278 + struct udev_device *usb_device = NULL; 267 279 const char *sysfs_path = NULL; 268 280 const char *dev_path = NULL; 281 + const char *serial = NULL; 282 + const char *product = NULL; 283 + const char *manufacturer = NULL; 269 284 uint8_t dev_class = 0; 270 285 uint16_t vendor_id = 0; 271 286 uint16_t product_id = 0; ··· 284 299 285 300 ret = p_udev_try_usb_relation_get_address( 286 301 raw_dev, &dev_class, &vendor_id, &product_id, &usb_bus, 287 - &usb_addr); 302 + &usb_addr, &usb_device); 288 303 if (ret != 0) { 289 304 P_ERROR(p, "skipping non-usb v4l device '%s'", 290 305 dev_path); 291 306 goto next; 292 307 } 293 308 309 + // Serial number. 310 + serial = udev_device_get_sysattr_value(usb_device, "serial"); 311 + // Product name. 312 + product = udev_device_get_sysattr_value(usb_device, "product"); 313 + // Manufacturer name. 314 + manufacturer = 315 + udev_device_get_sysattr_value(usb_device, "manufacturer"); 316 + 294 317 // USB interface. 295 318 ret = p_udev_get_interface_number(raw_dev, &usb_iface); 296 319 if (ret != 0) { ··· 322 345 "\t\tv4l_index: %u\n" 323 346 "\t\tusb_iface: %i\n" 324 347 "\t\tusb_bus: %i\n" 325 - "\t\tusb_addr: %i\n", 348 + "\t\tusb_addr: %i\n" 349 + "\t\tserial: '%s'\n" 350 + "\t\tproduct: '%s'\n" 351 + "\t\tmanufacturer: '%s'", 326 352 (void *)pdev, ret, sysfs_path, dev_path, vendor_id, 327 - product_id, v4l_index, usb_iface, usb_bus, usb_addr); 353 + product_id, v4l_index, usb_iface, usb_bus, usb_addr, 354 + serial, product, manufacturer); 328 355 329 356 if (ret != 0) { 330 357 P_ERROR(p, "p_dev_get_usb_device failed!"); ··· 625 652 uint16_t *out_vendor_id, 626 653 uint16_t *out_product_id, 627 654 uint16_t *out_usb_bus, 628 - uint16_t *out_usb_addr) 655 + uint16_t *out_usb_addr, 656 + struct udev_device **out_usb_device) 629 657 { 630 658 struct udev_device *parent_dev, *usb_interface, *usb_device; 631 659 ··· 653 681 return -1; 654 682 } 655 683 656 - return p_udev_get_usb_device_info(usb_device, out_dev_class, 657 - out_vendor_id, out_product_id, 658 - out_usb_bus, out_usb_addr); 684 + int ret = p_udev_get_usb_device_info(usb_device, out_dev_class, 685 + out_vendor_id, out_product_id, 686 + out_usb_bus, out_usb_addr); 687 + if (ret != 0) { 688 + return ret; 689 + } 690 + 691 + *out_usb_device = usb_device; 692 + 693 + return 0; 659 694 } 660 695 661 696 static int