diff options
Diffstat (limited to 'utils/hwstub/lib')
-rw-r--r-- | utils/hwstub/lib/hwstub.c | 15 | ||||
-rw-r--r-- | utils/hwstub/lib/hwstub.h | 2 |
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 @@ | |||
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 | ||
29 | struct hwstub_device_t | 29 | struct 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 | ||
37 | int hwstub_probe(libusb_device *dev) | 38 | int 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; |
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; | |||
39 | /* Returns hwstub interface, or -1 if none was found */ | 39 | /* Returns hwstub interface, or -1 if none was found */ |
40 | int hwstub_probe(libusb_device *dev); | 40 | int hwstub_probe(libusb_device *dev); |
41 | /* Helper function which returns a list of all hwstub devices found. The caller | 41 | /* Helper function which returns a list of all hwstub devices found. The caller |
42 | * must unref all of them when done, possibly using libusb_free_device_list(). | 42 | * must unref all of them when done, possibly using libusb_free_device_list(). |
43 | * Return number of devices or <0 on error */ | 43 | * Return number of devices or <0 on error */ |
44 | ssize_t hwstub_get_device_list(libusb_context *ctx, libusb_device ***list); | 44 | ssize_t hwstub_get_device_list(libusb_context *ctx, libusb_device ***list); |
45 | /* Returns NULL on error */ | 45 | /* Returns NULL on error */ |