From ac5ba893d70ccec75d83f680cbc66041458f76ea Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Sat, 9 Aug 2014 18:35:57 +0200 Subject: hwstub: library now check version on open Change-Id: I672a882ad06780da93c1d811af2b28ff60d07469 --- utils/hwstub/lib/hwstub.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'utils/hwstub/lib/hwstub.c') 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 #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; -- cgit v1.2.3