|
|
@@ -103,6 +103,27 @@ struct lowlevel_device_info *lowlevel_scan()
|
|
|
return devinfo_list;
|
|
|
}
|
|
|
|
|
|
+bool _lowlevel_match_product(const struct lowlevel_device_info * const info, const char ** const needles)
|
|
|
+{
|
|
|
+ if (!info->product)
|
|
|
+ return false;
|
|
|
+ for (int i = 0; needles[i]; ++i)
|
|
|
+ if (!strstr(info->product, needles[i]))
|
|
|
+ return false;
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+bool lowlevel_match_id(const struct lowlevel_device_info * const info, const struct lowlevel_driver * const lowl, const int32_t vid, const int32_t pid)
|
|
|
+{
|
|
|
+ if (info->lowl != lowl)
|
|
|
+ return false;
|
|
|
+ if (vid != -1 && vid != info->vid)
|
|
|
+ return false;
|
|
|
+ if (pid != -1 && pid != info->pid)
|
|
|
+ return false;
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
#define DETECT_BEGIN \
|
|
|
struct lowlevel_device_info *info, *tmp; \
|
|
|
int found = 0; \
|
|
|
@@ -111,44 +132,29 @@ struct lowlevel_device_info *lowlevel_scan()
|
|
|
{ \
|
|
|
// END DETECT_BEGIN
|
|
|
|
|
|
-#define DETECT_PREEND \
|
|
|
+#define DETECT_END \
|
|
|
if (!cb(info, userp)) \
|
|
|
continue; \
|
|
|
LL_DELETE(devinfo_list, info); \
|
|
|
++found; \
|
|
|
-// END DETECT_PREEND
|
|
|
-
|
|
|
-#define DETECT_END \
|
|
|
} \
|
|
|
return found; \
|
|
|
// END DETECT_END
|
|
|
|
|
|
int _lowlevel_detect(lowl_found_devinfo_func_t cb, const char *serial, const char **product_needles, void * const userp)
|
|
|
{
|
|
|
- int i;
|
|
|
-
|
|
|
DETECT_BEGIN
|
|
|
if (serial && ((!info->serial) || strcmp(serial, info->serial)))
|
|
|
continue;
|
|
|
- if (product_needles[0] && !info->product)
|
|
|
+ if (product_needles[0] && !_lowlevel_match_product(info, product_needles))
|
|
|
continue;
|
|
|
- for (i = 0; product_needles[i]; ++i)
|
|
|
- if (!strstr(info->product, product_needles[i]))
|
|
|
- goto next;
|
|
|
- DETECT_PREEND
|
|
|
-next: ;
|
|
|
DETECT_END
|
|
|
}
|
|
|
|
|
|
int lowlevel_detect_id(const lowl_found_devinfo_func_t cb, void * const userp, const struct lowlevel_driver * const lowl, const int32_t vid, const int32_t pid)
|
|
|
{
|
|
|
DETECT_BEGIN
|
|
|
- if (info->lowl != lowl)
|
|
|
- continue;
|
|
|
- if (vid != -1 && vid != info->vid)
|
|
|
- continue;
|
|
|
- if (pid != -1 && pid != info->pid)
|
|
|
+ if (!lowlevel_match_id(info, lowl, vid, pid))
|
|
|
continue;
|
|
|
- DETECT_PREEND
|
|
|
DETECT_END
|
|
|
}
|