Skip to content

Commit cc03236

Browse files
authored
Merge pull request #16 from tectrolabs/enhance-device-detecting-logic
Enhanced device detecting logic
2 parents cbe234c + 29d4f9d commit cc03236

File tree

10 files changed

+47
-36
lines changed

10 files changed

+47
-36
lines changed

windows-x64/SwiftRNG/SwiftRngApi.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
Copyright (C) 2014-2023 TectroLabs L.L.C. https://tectrolabs.com
2+
Copyright (C) 2014-2024 TectroLabs L.L.C. https://tectrolabs.com
33
44
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
55
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -12,9 +12,9 @@
1212

1313
/**
1414
* @file SwiftRngApi.h
15-
* @date 9/17/2023
15+
* @date 05/01/2024
1616
* @Author: Andrian Belinski
17-
* @version 1.1
17+
* @version 1.2
1818
*
1919
* @brief Implements the API for interacting with the SwiftRNG device.
2020
*/
@@ -242,7 +242,7 @@ int SwiftRngApi::open(int devNum) {
242242
int portsConnected;
243243
int ports[c_max_cdc_com_ports];
244244
// Retrieve devices connected as USB CDC in Windows
245-
m_usb_serial_device->get_connected_ports(ports, c_max_cdc_com_ports, &portsConnected, (WCHAR*)c_hardware_id.c_str());
245+
m_usb_serial_device->get_connected_ports(ports, c_max_cdc_com_ports, &portsConnected, (WCHAR*)c_hardware_id.c_str(), (WCHAR*)L"SWRNG");
246246
if (portsConnected > devNum) {
247247
WCHAR portName[80];
248248
m_usb_serial_device->toPortName(ports[devNum], portName, 80);
@@ -729,7 +729,7 @@ int SwiftRngApi::get_device_list(DeviceInfoList *dev_info_list) {
729729
int portsConnected;
730730
int ports[c_max_cdc_com_ports];
731731
// Add devices connected as USB CDC in Windows
732-
usbComPort.get_connected_ports(ports, c_max_cdc_com_ports, &portsConnected, (WCHAR*)c_hardware_id.c_str());
732+
usbComPort.get_connected_ports(ports, c_max_cdc_com_ports, &portsConnected, (WCHAR*)c_hardware_id.c_str(), (WCHAR*)L"SWRNG");
733733
while (portsConnected-- > 0) {
734734
swrng_updateDevInfoList(dev_info_list, &curFoundDevNum);
735735
}

windows-x64/SwiftRNG/USBComPort.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* USBComPort.cpp
3-
* Ver 1.2
3+
* Ver 1.3
44
*/
55

66
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77
8-
Copyright (C) 2014-2023 TectroLabs L.L.C. https://tectrolabs.com
8+
Copyright (C) 2014-2024 TectroLabs L.L.C. https://tectrolabs.com
99
1010
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1111
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -241,11 +241,12 @@ void USBComPort::clear_comm_err() {
241241
* @param int maxPorts - the maximum number of SwiftRNG devices to discover
242242
* @param int *actualCount - a pointer to the actual number of SwiftRNG devices found
243243
* @param WCHAR *hardwareId - a pointer to SwiftRNG device hardware ID
244+
* @param WCHAR* serialId - a pointer to SwiftRNG device hardware serial ID
244245
*
245246
* @return 0 - successful operation, otherwise the error code
246247
*
247248
*/
248-
void USBComPort::get_connected_ports(int ports[], int maxPorts, int *actualCount, WCHAR *hardwareId) {
249+
void USBComPort::get_connected_ports(int ports[], int maxPorts, int *actualCount, WCHAR *hardwareId, WCHAR* serialId) {
249250

250251
DWORD devIdx = 0;
251252
int foundPortIndex = 0;
@@ -295,13 +296,22 @@ void USBComPort::get_connected_ports(int ports[], int maxPorts, int *actualCount
295296
if (_tcsnicmp(curPortName, _T("COM"), 3) == 0)
296297
{
297298
TCHAR* src = (TCHAR*)curHardwareId;
298-
int size = (int)_tcsnlen(hardwareId, 80);
299-
300299
if (_tcsnicmp(hardwareId, (TCHAR*)curHardwareId, _tcsnlen(hardwareId, 80)) == 0) {
301-
int nPortNr = _ttoi(curPortName + 3);
302-
if (nPortNr != 0)
300+
int port_nr = _ttoi(curPortName + 3);
301+
if (port_nr != 0)
303302
{
304-
ports[foundPortIndex++] = nPortNr;
303+
DEVINST dev_instance_parent_id;
304+
TCHAR sz_dev_instance_id[MAX_DEVICE_ID_LEN];
305+
CONFIGRET status = CM_Get_Parent(&dev_instance_parent_id, devInfoData.DevInst, 0);
306+
if (status == CR_SUCCESS)
307+
{
308+
status = CM_Get_Device_ID(dev_instance_parent_id, sz_dev_instance_id, MAX_DEVICE_ID_LEN, 0);
309+
if (status == CR_SUCCESS) {
310+
if (std::wstring(sz_dev_instance_id).find(serialId) != std::string::npos) {
311+
ports[foundPortIndex++] = port_nr;
312+
}
313+
}
314+
}
305315
}
306316
}
307317

windows-x64/SwiftRNG/USBComPort.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
22
* USBComPort.h
3-
* Ver 1.3
3+
* Ver 1.4
44
*/
55

66
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
77
8-
Copyright (C) 2014-2023 TectroLabs L.L.C. https://tectrolabs.com
8+
Copyright (C) 2014-2024 TectroLabs L.L.C. https://tectrolabs.com
99
1010
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1111
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -23,6 +23,7 @@ This class may only be used in conjunction with TectroLabs devices.
2323
#include <initguid.h>
2424
#include <windows.h>
2525
#include <Setupapi.h>
26+
#include <cfgmgr32.h>
2627
#include <stdio.h>
2728
#include <stdlib.h>
2829
#include <tchar.h>
@@ -41,7 +42,7 @@ class USBComPort
4142
std::string get_error_log() const;
4243
void clear_error_log();
4344
int execute_device_cmd(const unsigned char *snd, int sizeSnd, unsigned char *rcv, int sizeRcv);
44-
void get_connected_ports(int ports[], int maxPorts, int* actualCount, WCHAR *hardwareId);
45+
void get_connected_ports(int ports[], int maxPorts, int* actualCount, WCHAR *hardwareId, WCHAR* serialId);
4546
void toPortName(int portNum, WCHAR* portName, int portNameSize);
4647
int send_command(const unsigned char *snd, int sizeSnd, int *bytesSend);
4748
int receive_data(unsigned char *rcv, int sizeRcv, int *bytesReveived);

windows-x64/entropy-cl-server/entropy-cl-server.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* entropy-cl-server.c
3-
* Ver. 2.3
3+
* Ver. 2.4
44
*
55
*/
66

77
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
9-
Copyright (C) 2014-2023 TectroLabs L.L.C. https://tectrolabs.com
9+
Copyright (C) 2014-2024 TectroLabs L.L.C. https://tectrolabs.com
1010
1111
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1212
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -33,7 +33,7 @@ This program may only be used in conjunction with SwiftRNG devices.
3333
*/
3434
void displayUsage() {
3535
printf("*********************************************************************************\n");
36-
printf(" SwiftRNG entropy-cl-server Ver 2.3 \n");
36+
printf(" SwiftRNG entropy-cl-server Ver 2.4 \n");
3737
printf("*********************************************************************************\n");
3838
printf("NAME\n");
3939
printf(" entropy-cl-server - An application server for distributing random bytes \n");

windows-x64/entropy-server/entropy-server.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* entropy-server.c
3-
* Ver. 2.2
3+
* Ver. 2.3
44
*
55
*/
66

77
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
9-
Copyright (C) 2014-2023 TectroLabs, http://tectrolabs.com
9+
Copyright (C) 2014-2024 TectroLabs, http://tectrolabs.com
1010
1111
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1212
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

windows-x64/entropy-server/entropy-server.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* entropy-server.h
3-
* Ver. 2.1
3+
* Ver. 2.2
44
*
55
*/
66

77
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
9-
Copyright (C) 2014-2021 TectroLabs, http://tectrolabs.com
9+
Copyright (C) 2014-2024 TectroLabs, http://tectrolabs.com
1010
1111
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1212
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -103,7 +103,7 @@ DeviceVersion dv;
103103
static wchar_t pipeEndPoint[PIPENAME_MAX_CHARS + 1];
104104
static char defaultPipeEndpoint[] = "\\\\.\\pipe\\SwiftRNG";
105105
static char serverMajorVersion = 2;
106-
static char serverMinorVersion = 2;
106+
static char serverMinorVersion = 3;
107107
size_t numCharConverted;
108108
char embeddedCorrectionMethodStr[MAX_CORRECTION_NAME_SIZE];
109109
int embeddedCorrectionMethodId;

windows-x64/swdiag-cl/swdiag-cl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* swdiag-cl.c
3-
* Ver. 2.5
3+
* Ver. 2.6
44
*
55
*/
66

77
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
9-
Copyright (C) 2014-2023 TectroLabs, https://tectrolabs.com
9+
Copyright (C) 2014-2024 TectroLabs, https://tectrolabs.com
1010
1111
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1212
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -58,7 +58,7 @@ int main(int argc, char **argv) {
5858
int cluster_size = 2;
5959

6060
printf("------------------------------------------------------------------------------\n");
61-
printf("--- TectroLabs - swdiag-cl - SwiftRNG cluster diagnostics utility Ver 2.5 ---\n");
61+
printf("--- TectroLabs - swdiag-cl - SwiftRNG cluster diagnostics utility Ver 2.6 ---\n");
6262
printf("------------------------------------------------------------------------------\n");
6363

6464
setbuf(stdout, NULL);

windows-x64/swdiag/swdiag.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* swdiag.c
3-
* Ver. 2.7
3+
* Ver. 2.8
44
*
55
*/
66

77
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
9-
Copyright (C) 2014-2023 TectroLabs, https://tectrolabs.com
9+
Copyright (C) 2014-2024 TectroLabs, https://tectrolabs.com
1010
1111
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1212
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -73,7 +73,7 @@ int main() {
7373
uint16_t max_rct_failures_per_block;
7474

7575
printf("-------------------------------------------------------------------\n");
76-
printf("--- TectroLabs - swdiag - SwiftRNG diagnostics utility Ver 2.7 ---\n");
76+
printf("--- TectroLabs - swdiag - SwiftRNG diagnostics utility Ver 2.8 ---\n");
7777
printf("-------------------------------------------------------------------\n");
7878
printf("Searching for devices ------------------ ");
7979

windows-x64/swrng-cl/swrng-cl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* swrng-cl.c
3-
* ver. 3.5
3+
* ver. 3.6
44
*
55
*/
66

77
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
9-
Copyright (C) 2014-2023 TectroLabs, https://tectrolabs.com
9+
Copyright (C) 2014-2024 TectroLabs, https://tectrolabs.com
1010
1111
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1212
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -66,7 +66,7 @@ static int display_devices(void) {
6666
*/
6767
static void display_usage(void) {
6868
printf("*********************************************************************************\n");
69-
printf(" TectroLabs - swrng-cl - cluster download utility Ver 3.5 \n");
69+
printf(" TectroLabs - swrng-cl - cluster download utility Ver 3.6 \n");
7070
printf("*********************************************************************************\n");
7171
printf("NAME\n");
7272
printf(" swrng-cl - Download true random bytes from a cluster of SwiftRNG devices\n");

windows-x64/swrng/swrng.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* swrng.c
3-
* Ver. 3.5
3+
* Ver. 3.6
44
*
55
*/
66

77
/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
88
9-
Copyright (C) 2014-2023 TectroLabs, https://tectrolabs.com
9+
Copyright (C) 2014-2024 TectroLabs, https://tectrolabs.com
1010
1111
THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED,
1212
INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
@@ -70,7 +70,7 @@ static int display_devices(void) {
7070
*/
7171
static void display_usage(void) {
7272
printf("*********************************************************************************\n");
73-
printf(" TectroLabs - swrng - download utility Ver 3.5 \n");
73+
printf(" TectroLabs - swrng - download utility Ver 3.6 \n");
7474
printf("*********************************************************************************\n");
7575
printf("NAME\n");
7676
printf(" swrng - True Random Number Generator SwiftRNG download \n");

0 commit comments

Comments
 (0)