aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac4
-rw-r--r--libjaylink/device.c61
-rw-r--r--libjaylink/discovery_usb.c4
-rw-r--r--libjaylink/libjaylink.h36
4 files changed, 101 insertions, 4 deletions
diff --git a/configure.ac b/configure.ac
index e63400c..7fc2a1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -27,7 +27,7 @@ AC_CONFIG_AUX_DIR([build-aux])
AC_CANONICAL_HOST
-AM_INIT_AUTOMAKE([-Wall -Werror check-news])
+AM_INIT_AUTOMAKE([-Wall -Werror])
# Enable additional compiler warnings via -Wall and -Wextra. Use hidden
# visibility for all non-static symbols by default with -fvisibility=hidden.
@@ -50,7 +50,7 @@ PKG_PROG_PKG_CONFIG
# Checks for libraries.
# Check for libusb-1.0 which is always needed.
-PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.9],
+PKG_CHECK_MODULES([libusb], [libusb-1.0 >= 1.0.16],
[HAVE_LIBUSB=yes], [HAVE_LIBUSB=no])
AS_IF([test "x$HAVE_LIBUSB" = "xyes"],
diff --git a/libjaylink/device.c b/libjaylink/device.c
index a3bddf6..3a5f7d2 100644
--- a/libjaylink/device.c
+++ b/libjaylink/device.c
@@ -68,6 +68,9 @@
#define REG_MAX_SIZE 0x200
/** Size of a connection entry in bytes. */
#define REG_CONN_INFO_SIZE 16
+
+/* The maximum path depth according to the USB 3.0 specification. */
+#define MAX_USB_PATH_DEPTH 7
/** @endcond */
/** @private */
@@ -286,6 +289,64 @@ JAYLINK_API int jaylink_device_get_usb_address(
}
/**
+ * Get the USB bus and port numbers of a device.
+ *
+ * @param[in] dev Device instance.
+ * @param[out] bus The bus number of the device on success and undefined on
+ * failure.
+ * @param[out] ports Newly allocated array which contains the port numbers on
+ * success and is undefined on failure. The array must be
+ * free'd by the caller.
+ * @param[out] length Length of the port array on success and undefined on
+ * failure.
+ *
+ * @retval JAYLINK_OK Success.
+ * @retval JAYLINK_ERR_ARG Invalid arguments.
+ * @retval JAYLINK_ERR_MALLOC Memory allocation error.
+ * @retval JAYLINK_ERR_NOT_SUPPORTED Supported for devices with host interface
+ * #JAYLINK_HIF_USB only.
+ *
+ * @since 0.2.0
+ */
+JAYLINK_API int jaylink_device_get_usb_bus_ports(
+ const struct jaylink_device *dev, uint8_t *bus,
+ uint8_t **ports, size_t *length)
+{
+ if (!dev || !bus || !ports || !length)
+ return JAYLINK_ERR_ARG;
+
+ if (dev->iface != JAYLINK_HIF_USB)
+ return JAYLINK_ERR_NOT_SUPPORTED;
+
+#ifdef HAVE_LIBUSB
+ struct jaylink_context *ctx = dev->ctx;
+ int ret;
+
+ *ports = malloc(MAX_USB_PATH_DEPTH * sizeof(uint8_t));
+
+ if (!*ports) {
+ return JAYLINK_ERR_MALLOC;
+ }
+
+ ret = libusb_get_port_numbers(dev->usb_dev, *ports,
+ MAX_USB_PATH_DEPTH);
+
+ if (ret == LIBUSB_ERROR_OVERFLOW) {
+ log_err(ctx, "Failed to get port numbers: %s.",
+ libusb_error_name(ret));
+ return JAYLINK_ERR_ARG;
+ }
+
+ *length = ret;
+ *bus = libusb_get_bus_number(dev->usb_dev);
+
+ return JAYLINK_OK;
+#else
+ return JAYLINK_ERR_NOT_SUPPORTED;
+#endif
+}
+
+/**
* Get the IPv4 address string of a device.
*
* @param[in] dev Device instance.
diff --git a/libjaylink/discovery_usb.c b/libjaylink/discovery_usb.c
index 48d5322..fe7b045 100644
--- a/libjaylink/discovery_usb.c
+++ b/libjaylink/discovery_usb.c
@@ -59,7 +59,9 @@ static const uint16_t pids[][2] = {
{0x1015, 0},
{0x1016, 0},
{0x1017, 0},
- {0x1018, 0}
+ {0x1018, 0},
+ {0x1020, 0},
+ {0x1055, 0}
};
/** Maximum length of the USB string descriptor for the serial number. */
diff --git a/libjaylink/libjaylink.h b/libjaylink/libjaylink.h
index 223aa84..1de95c9 100644
--- a/libjaylink/libjaylink.h
+++ b/libjaylink/libjaylink.h
@@ -169,7 +169,38 @@ enum jaylink_hardware_info {
/** Current consumption of the target in mA. */
JAYLINK_HW_INFO_ITARGET = (1 << 2),
/** Peak current consumption of the target in mA. */
- JAYLINK_HW_INFO_ITARGET_PEAK = (1 << 3)
+ JAYLINK_HW_INFO_ITARGET_PEAK = (1 << 3),
+ /**
+ * Device's IPv4 address in network byte order.
+ *
+ * If the address is 0.0.0.0 and DHCP is enabled, no address is
+ * assigned (yet).
+ *
+ * @note The value is valid only if the device is configured in DHCP
+ * mode.
+ */
+ JAYLINK_HW_INFO_IPV4_ADDRESS = (1 << 16),
+ /**
+ * IPv4 netmask in network byte order.
+ *
+ * @note The value is valid only if the device is configured in DHCP
+ * mode.
+ */
+ JAYLINK_HW_INFO_IPV4_NETMASK = (1 << 17),
+ /**
+ * Gateway IPv4 address in network byte order.
+ *
+ * @note The value is valid only if the device is configured in DHCP
+ * mode.
+ */
+ JAYLINK_HW_INFO_IPV4_GATEWAY = (1 << 18),
+ /**
+ * DNS server IPv4 address in network byte order.
+ *
+ * @note The value is valid only if the device is configured in DHCP
+ * mode.
+ */
+ JAYLINK_HW_INFO_IPV4_DNS = (1 << 19)
};
/** Device counters. */
@@ -430,6 +461,9 @@ JAYLINK_API int jaylink_device_get_serial_number(
JAYLINK_API int jaylink_device_get_usb_address(
const struct jaylink_device *dev,
enum jaylink_usb_address *address);
+JAYLINK_API int jaylink_device_get_usb_bus_ports(
+ const struct jaylink_device *dev, uint8_t *bus,
+ uint8_t **ports, size_t *length);
JAYLINK_API int jaylink_device_get_ipv4_address(
const struct jaylink_device *dev, char *address);
JAYLINK_API int jaylink_device_get_mac_address(