|
@@ -9,6 +9,7 @@
|
|
|
|
|
|
|
|
#include "config.h"
|
|
#include "config.h"
|
|
|
|
|
|
|
|
|
|
+#include <stdint.h>
|
|
|
#include <stdlib.h>
|
|
#include <stdlib.h>
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
@@ -19,6 +20,18 @@
|
|
|
|
|
|
|
|
static struct lowlevel_device_info *devinfo_list;
|
|
static struct lowlevel_device_info *devinfo_list;
|
|
|
|
|
|
|
|
|
|
+void lowlevel_devinfo_semicpy(struct lowlevel_device_info * const dst, const struct lowlevel_device_info * const src)
|
|
|
|
|
+{
|
|
|
|
|
+#define COPYSTR(key) BFGINIT(dst->key, maybe_strdup(src->key))
|
|
|
|
|
+ COPYSTR(manufacturer);
|
|
|
|
|
+ COPYSTR(product);
|
|
|
|
|
+ COPYSTR(serial);
|
|
|
|
|
+ COPYSTR(path);
|
|
|
|
|
+ COPYSTR(devid);
|
|
|
|
|
+ BFGINIT(dst->vid, src->vid);
|
|
|
|
|
+ BFGINIT(dst->pid, src->pid);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void lowlevel_devinfo_free(struct lowlevel_device_info * const info)
|
|
void lowlevel_devinfo_free(struct lowlevel_device_info * const info)
|
|
|
{
|
|
{
|
|
|
if (info->lowl->devinfo_free)
|
|
if (info->lowl->devinfo_free)
|
|
@@ -51,6 +64,11 @@ void lowlevel_scan()
|
|
|
|
|
|
|
|
lowlevel_scan_free();
|
|
lowlevel_scan_free();
|
|
|
|
|
|
|
|
|
|
+#ifdef HAVE_LIBUSB
|
|
|
|
|
+ devinfo_mid_list = lowl_usb.devinfo_scan();
|
|
|
|
|
+ LL_CONCAT(devinfo_list, devinfo_mid_list);
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
#ifdef USE_X6500
|
|
#ifdef USE_X6500
|
|
|
devinfo_mid_list = lowl_ft232r.devinfo_scan();
|
|
devinfo_mid_list = lowl_ft232r.devinfo_scan();
|
|
|
LL_CONCAT(devinfo_list, devinfo_mid_list);
|
|
LL_CONCAT(devinfo_list, devinfo_mid_list);
|
|
@@ -68,22 +86,41 @@ void lowlevel_scan()
|
|
|
|
|
|
|
|
LL_FOREACH(devinfo_list, devinfo_mid_list)
|
|
LL_FOREACH(devinfo_list, devinfo_mid_list)
|
|
|
{
|
|
{
|
|
|
- applog(LOG_DEBUG, "%s: Found %s device at %s (path=%s, manuf=%s, prod=%s, serial=%s)",
|
|
|
|
|
|
|
+ applog(LOG_DEBUG, "%s: Found %s device at %s (path=%s, vid=%04x, pid=%04x, manuf=%s, prod=%s, serial=%s)",
|
|
|
__func__,
|
|
__func__,
|
|
|
devinfo_mid_list->lowl->dname,
|
|
devinfo_mid_list->lowl->dname,
|
|
|
devinfo_mid_list->devid,
|
|
devinfo_mid_list->devid,
|
|
|
devinfo_mid_list->path,
|
|
devinfo_mid_list->path,
|
|
|
|
|
+ (unsigned)devinfo_mid_list->vid, (unsigned)devinfo_mid_list->pid,
|
|
|
devinfo_mid_list->manufacturer, devinfo_mid_list->product, devinfo_mid_list->serial);
|
|
devinfo_mid_list->manufacturer, devinfo_mid_list->product, devinfo_mid_list->serial);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-int _lowlevel_detect(lowl_found_devinfo_func_t cb, const char *serial, const char **product_needles, void *userp)
|
|
|
|
|
|
|
+#define DETECT_BEGIN \
|
|
|
|
|
+ struct lowlevel_device_info *info, *tmp; \
|
|
|
|
|
+ int found = 0; \
|
|
|
|
|
+ \
|
|
|
|
|
+ LL_FOREACH_SAFE(devinfo_list, info, tmp) \
|
|
|
|
|
+ { \
|
|
|
|
|
+// END DETECT_BEGIN
|
|
|
|
|
+
|
|
|
|
|
+#define DETECT_PREEND \
|
|
|
|
|
+ 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)
|
|
|
{
|
|
{
|
|
|
- struct lowlevel_device_info *info, *tmp;
|
|
|
|
|
- int found = 0, i;
|
|
|
|
|
|
|
+ int i;
|
|
|
|
|
|
|
|
- LL_FOREACH_SAFE(devinfo_list, info, tmp)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ DETECT_BEGIN
|
|
|
if (serial && ((!info->serial) || strcmp(serial, info->serial)))
|
|
if (serial && ((!info->serial) || strcmp(serial, info->serial)))
|
|
|
continue;
|
|
continue;
|
|
|
if (product_needles[0] && !info->product)
|
|
if (product_needles[0] && !info->product)
|
|
@@ -91,12 +128,20 @@ int _lowlevel_detect(lowl_found_devinfo_func_t cb, const char *serial, const cha
|
|
|
for (i = 0; product_needles[i]; ++i)
|
|
for (i = 0; product_needles[i]; ++i)
|
|
|
if (!strstr(info->product, product_needles[i]))
|
|
if (!strstr(info->product, product_needles[i]))
|
|
|
goto next;
|
|
goto next;
|
|
|
- if (!cb(info, userp))
|
|
|
|
|
- continue;
|
|
|
|
|
- LL_DELETE(devinfo_list, info);
|
|
|
|
|
- ++found;
|
|
|
|
|
|
|
+ DETECT_PREEND
|
|
|
next: ;
|
|
next: ;
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- return found;
|
|
|
|
|
|
|
+ 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)
|
|
|
|
|
+ continue;
|
|
|
|
|
+ DETECT_PREEND
|
|
|
|
|
+ DETECT_END
|
|
|
}
|
|
}
|