summaryrefslogtreecommitdiff
path: root/utils/hwstub
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2014-08-09 18:35:57 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2014-09-07 17:46:27 +0200
commitac5ba893d70ccec75d83f680cbc66041458f76ea (patch)
tree3d4d6d644fc73d2c36d3abacf1bf5ab528a7d978 /utils/hwstub
parent29de3421341ff0b4d33279eeb344f779b6ef5d3e (diff)
hwstub: library now check version on open
Change-Id: I672a882ad06780da93c1d811af2b28ff60d07469
Diffstat (limited to 'utils/hwstub')
-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 */