summaryrefslogtreecommitdiff
path: root/utils/hwstub/lib/hwstub.c
diff options
context:
space:
mode:
Diffstat (limited to 'utils/hwstub/lib/hwstub.c')
-rw-r--r--utils/hwstub/lib/hwstub.c15
1 files changed, 13 insertions, 2 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 @@
23#include <stdlib.h> 23#include <stdlib.h>
24 24
25#ifndef MIN 25#ifndef MIN
26#define MIN(a,b) ((a) < (b) ? (a) : (b)) 26#define MIN(a,b) ((a) <= (b) ? (a) : (b))
27#endif 27#endif
28 28
29struct hwstub_device_t 29struct hwstub_device_t
@@ -32,6 +32,7 @@ struct hwstub_device_t
32 int intf; 32 int intf;
33 unsigned buf_sz; 33 unsigned buf_sz;
34 uint16_t id; 34 uint16_t id;
35 uint8_t minor_ver;
35}; 36};
36 37
37int hwstub_probe(libusb_device *dev) 38int hwstub_probe(libusb_device *dev)
@@ -97,9 +98,19 @@ struct hwstub_device_t *hwstub_open(libusb_device_handle *handle)
97 dev->intf = hwstub_probe(mydev); 98 dev->intf = hwstub_probe(mydev);
98 if(dev->intf == -1) 99 if(dev->intf == -1)
99 goto Lerr; 100 goto Lerr;
101 /* try to get version */
102 struct hwstub_version_desc_t m_hwdev_ver;
103 int sz = hwstub_get_desc(dev, HWSTUB_DT_VERSION, &m_hwdev_ver, sizeof(m_hwdev_ver));
104 if(sz != sizeof(m_hwdev_ver))
105 goto Lerr;
106 /* major version must match, minor version is taken to be the minimum between
107 * what library and device support */
108 if(m_hwdev_ver.bMajor != HWSTUB_VERSION_MAJOR)
109 goto Lerr;
110 dev->minor_ver = MIN(m_hwdev_ver.bMinor, HWSTUB_VERSION_MINOR);
100 /* try to get actual buffer size */ 111 /* try to get actual buffer size */
101 struct hwstub_layout_desc_t layout; 112 struct hwstub_layout_desc_t layout;
102 int sz = hwstub_get_desc(dev, HWSTUB_DT_LAYOUT, &layout, sizeof(layout)); 113 sz = hwstub_get_desc(dev, HWSTUB_DT_LAYOUT, &layout, sizeof(layout));
103 if(sz == (int)sizeof(layout)) 114 if(sz == (int)sizeof(layout))
104 dev->buf_sz = layout.dBufferSize; 115 dev->buf_sz = layout.dBufferSize;
105 return dev; 116 return dev;