1
0
Fork 0
forked from len0rd/rockbox

hwstub: library now check version on open

Change-Id: I672a882ad06780da93c1d811af2b28ff60d07469
This commit is contained in:
Amaury Pouly 2014-08-09 18:35:57 +02:00
parent 29de342134
commit ac5ba893d7
2 changed files with 14 additions and 3 deletions

View file

@ -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;