From 42996d6b1ce93ad22367211e13c417cd49337fe5 Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Fri, 12 Feb 2021 02:44:00 +0100 Subject: [PATCH] os/hid: Add get_physical_address() --- src/xrt/auxiliary/os/os_hid.h | 17 +++++++++++++++++ src/xrt/auxiliary/os/os_hid_hidraw.c | 8 ++++++++ 2 files changed, 25 insertions(+) diff --git a/src/xrt/auxiliary/os/os_hid.h b/src/xrt/auxiliary/os/os_hid.h index 89fde6216..146463c09 100644 --- a/src/xrt/auxiliary/os/os_hid.h +++ b/src/xrt/auxiliary/os/os_hid.h @@ -37,6 +37,8 @@ struct os_hid_device int (*set_feature)(struct os_hid_device *hid_dev, const uint8_t *data, size_t size); + int (*get_physical_address)(struct os_hid_device *hid_dev, uint8_t *data, size_t size); + void (*destroy)(struct os_hid_device *hid_dev); }; @@ -104,6 +106,21 @@ os_hid_set_feature(struct os_hid_device *hid_dev, const uint8_t *data, size_t si return hid_dev->set_feature(hid_dev, data, size); } +/*! + * Get the physical address. + * + * For USB devices, the string contains the physical path to the device (the + * USB controller, hubs, ports, etc). For Bluetooth *devices, the string + * contains the hardware (MAC) address of the device. + * + * @public @memberof os_hid_device + */ +static inline int +os_hid_get_physical_address(struct os_hid_device *hid_dev, uint8_t *data, size_t size) +{ + return hid_dev->get_physical_address(hid_dev, data, size); +} + /*! * Close and free the given device. * diff --git a/src/xrt/auxiliary/os/os_hid_hidraw.c b/src/xrt/auxiliary/os/os_hid_hidraw.c index ca95b3d2a..56c6e3b3e 100644 --- a/src/xrt/auxiliary/os/os_hid_hidraw.c +++ b/src/xrt/auxiliary/os/os_hid_hidraw.c @@ -89,6 +89,13 @@ os_hidraw_get_feature(struct os_hid_device *ohdev, uint8_t report_num, uint8_t * return ioctl(hrdev->fd, HIDIOCGFEATURE(length), data); } +static int +os_hidraw_get_physical_address(struct os_hid_device *ohdev, uint8_t *data, size_t length) +{ + struct hid_hidraw *hrdev = (struct hid_hidraw *)ohdev; + return ioctl(hrdev->fd, HIDIOCGRAWPHYS(length), data); +} + static int os_hidraw_get_feature_timeout(struct os_hid_device *ohdev, void *data, size_t length, uint32_t timeout) { @@ -138,6 +145,7 @@ os_hid_open_hidraw(const char *path, struct os_hid_device **out_hid) hrdev->base.get_feature = os_hidraw_get_feature; hrdev->base.get_feature_timeout = os_hidraw_get_feature_timeout; hrdev->base.set_feature = os_hidraw_set_feature; + hrdev->base.get_physical_address = os_hidraw_get_physical_address; hrdev->base.destroy = os_hidraw_destroy; hrdev->fd = open(path, O_RDWR); if (hrdev->fd < 0) {