summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/hwstub/lib/hwstub.c15
-rw-r--r--utils/hwstub/lib/hwstub.h2
2 files changed, 14 insertions, 3 deletions
diff --git a/utils/hwstub/lib/hwstub.c b/utils/hwstub/lib/hwstub.c
index 8e5cb98d29..036c97a5d9 100644
--- a/utils/hwstub/lib/hwstub.c
+++ b/utils/hwstub/lib/hwstub.c
@@ -23,7 +23,7 @@
#include <stdlib.h>
#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#endif
struct hwstub_device_t
@@ -32,6 +32,7 @@ struct hwstub_device_t
int intf;
unsigned buf_sz;
uint16_t id;
+ uint8_t minor_ver;
};
int hwstub_probe(libusb_device *dev)
@@ -97,9 +98,19 @@ struct hwstub_device_t *hwstub_open(libusb_device_handle *handle)
dev->intf = hwstub_probe(mydev);
if(dev->intf == -1)
goto Lerr;
+ /* try to get version */
+ struct hwstub_version_desc_t m_hwdev_ver;
+ int sz = hwstub_get_desc(dev, HWSTUB_DT_VERSION, &m_hwdev_ver, sizeof(m_hwdev_ver));
+ if(sz != sizeof(m_hwdev_ver))
+ goto Lerr;
+ /* major version must match, minor version is taken to be the minimum between
+ * what library and device support */
+ if(m_hwdev_ver.bMajor != HWSTUB_VERSION_MAJOR)
+ goto Lerr;
+ dev->minor_ver = MIN(m_hwdev_ver.bMinor, HWSTUB_VERSION_MINOR);
/* try to get actual buffer size */
struct hwstub_layout_desc_t layout;
- int sz = hwstub_get_desc(dev, HWSTUB_DT_LAYOUT, &layout, sizeof(layout));
+ sz = hwstub_get_desc(dev, HWSTUB_DT_LAYOUT, &layout, sizeof(layout));
if(sz == (int)sizeof(layout))
dev->buf_sz = layout.dBufferSize;
return dev;
diff --git a/utils/hwstub/lib/hwstub.h b/utils/hwstub/lib/hwstub.h
index 1599f6508b..8fb98fe669 100644
--- a/utils/hwstub/lib/hwstub.h
+++ b/utils/hwstub/lib/hwstub.h
@@ -39,7 +39,7 @@ struct hwstub_device_t;
/* Returns hwstub interface, or -1 if none was found */
int hwstub_probe(libusb_device *dev);
/* Helper function which returns a list of all hwstub devices found. The caller
- * must unref all of them when done, possibly using libusb_free_device_list().
+ * must unref all of them when done, possibly using libusb_free_device_list().
* Return number of devices or <0 on error */
ssize_t hwstub_get_device_list(libusb_context *ctx, libusb_device ***list);
/* Returns NULL on error */