serial_win: Find BMP comport by serial number.

This commit is contained in:
Uwe Bonnes 2020-08-01 22:31:26 +02:00 committed by UweBonnes
parent 3eb51ce94f
commit fca8593d92
3 changed files with 49 additions and 7 deletions

View File

@ -37,9 +37,6 @@
#include "jlink.h"
#include "cmsis_dap.h"
#define VENDOR_ID_BMP 0x1d50
#define PRODUCT_ID_BMP 0x6018
#define VENDOR_ID_STLINK 0x0483
#define PRODUCT_ID_STLINK_MASK 0xffe0
#define PRODUCT_ID_STLINK_GROUP 0x3740

View File

@ -14,6 +14,9 @@ void platform_buffer_flush(void);
#define SET_IDLE_STATE(x)
#define SET_RUN_STATE(x)
#define VENDOR_ID_BMP 0x1d50
#define PRODUCT_ID_BMP 0x6018
typedef enum bmp_type_s {
BMP_TYPE_NONE = 0,
BMP_TYPE_BMP,

View File

@ -23,17 +23,59 @@
#include "remote.h"
#include "cl_utils.h"
HANDLE hComm;
static HANDLE hComm;
static char *find_bmp_by_serial(const char *serial)
{
char regpath[258];
/* First find the containers of the BMP comports */
sprintf(regpath,
"SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_%04X&PID_%04X\\%s",
VENDOR_ID_BMP, PRODUCT_ID_BMP, serial);
HKEY hkeySection;
LSTATUS res;
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &hkeySection);
if (res != ERROR_SUCCESS)
return NULL;
BYTE prefix[128];
DWORD maxlen = sizeof(prefix);
res = RegQueryValueEx(hkeySection, "ParentIdPrefix", NULL, NULL, prefix,
&maxlen);
RegCloseKey(hkeySection);
if (res != ERROR_SUCCESS)
return NULL;
printf("prefix %s\n", prefix);
sprintf(regpath,
"SYSTEM\\CurrentControlSet\\Enum\\USB\\VID_%04X&PID_%04X&MI_00\\%s"
"&0000\\Device Parameters",
VENDOR_ID_BMP, PRODUCT_ID_BMP, prefix);
printf("%s\n", regpath);
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, regpath, 0, KEY_READ, &hkeySection);
if (res != ERROR_SUCCESS) {
printf("Failuere\n");
return NULL;
}
BYTE port[128];
maxlen = sizeof(port);
res = RegQueryValueEx(hkeySection, "PortName", NULL, NULL, port, &maxlen);
RegCloseKey(hkeySection);
if (res != ERROR_SUCCESS)
return NULL;
printf("Portname %s\n", port);
return strdup((char*)port);
}
int serial_open(BMP_CL_OPTIONS_t *cl_opts, char * serial)
{
(void) serial; /* FIXME: Does Windows allow open with USB serial no? */
char device[256];
if (!cl_opts->opt_device)
cl_opts->opt_device = find_bmp_by_serial(serial);
if (!cl_opts->opt_device) {
DEBUG_WARN("Specify the serial device to use!\n");
DEBUG_WARN("Unexpected problems finding the device!\n");
return -1;
}
char device[256];
if (strstr(device, "\\\\.\\")) {
if (strstr(cl_opts->opt_device, "\\\\.\\")) {
strncpy(device, cl_opts->opt_device, sizeof(device) - 1);
} else {
strcpy(device, "\\\\.\\");