mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/win32-vd_agent
synced 2026-02-03 14:46:49 +00:00
vdservice: use "com.redhat.spice.0" symbolic link as virtio-serial port path
remove get_device_path() by GUID & dependency on setupapi.lib
This commit is contained in:
parent
f2f2f874e1
commit
b5edf7c800
@ -15,23 +15,15 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <windows.h>
|
||||
#include <setupapi.h>
|
||||
#include "stdio.h"
|
||||
#include "vdi_port.h"
|
||||
#include "vdlog.h"
|
||||
|
||||
const GUID GUID_VIOSERIAL_PORT =
|
||||
{0x6fde7521, 0x1b65, 0x48ae, 0xb6, 0x28, 0x80, 0xbe, 0x62, 0x1, 0x60, 0x26};
|
||||
#define VIOSERIAL_PORT_PATH L"\\\\.\\Global\\com.redhat.spice.0"
|
||||
|
||||
// Current limitation of virtio-serial windows driver (RHBZ 617000)
|
||||
#define VIOSERIAL_PORT_MAX_WRITE_BYTES 2048
|
||||
|
||||
// Retry initial connection to device. On boot when vdservice is started the device is
|
||||
// not immediately available (takes 2 seconds, 30 is for extreme load).
|
||||
#define VIOSERIAL_PORT_DEVICE_OPEN_MAX_RETRIES 30
|
||||
#define VIOSERIAL_PORT_DEVICE_OPEN_RETRY_INTERVAL_MS 1000
|
||||
|
||||
#define MIN(a, b) ((a) > (b) ? (b) : (a))
|
||||
|
||||
VDIPort* VDIPort::_singleton;
|
||||
@ -59,61 +51,9 @@ VDIPort::~VDIPort()
|
||||
}
|
||||
}
|
||||
|
||||
//Based on device.cpp from vioserial test app
|
||||
//FIXME: remove this call & lib?
|
||||
PTCHAR get_device_path(IN LPGUID interface_guid)
|
||||
{
|
||||
HDEVINFO dev_info;
|
||||
SP_DEVICE_INTERFACE_DATA dev_interface;
|
||||
PSP_DEVICE_INTERFACE_DETAIL_DATA dev_interface_detail = NULL;
|
||||
ULONG len, req_len = 0;
|
||||
|
||||
dev_info = SetupDiGetClassDevs(interface_guid, NULL, NULL,
|
||||
DIGCF_PRESENT | DIGCF_DEVICEINTERFACE);
|
||||
if (dev_info == INVALID_HANDLE_VALUE) {
|
||||
vd_printf("Cannot get class devices");
|
||||
return NULL;
|
||||
}
|
||||
dev_interface.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);
|
||||
if (!SetupDiEnumDeviceInterfaces(dev_info, 0, interface_guid, 0, &dev_interface)) {
|
||||
vd_printf("Cannot get enumerate device interfaces");
|
||||
SetupDiDestroyDeviceInfoList(dev_info);
|
||||
return NULL;
|
||||
}
|
||||
SetupDiGetDeviceInterfaceDetail(dev_info, &dev_interface, NULL, 0, &req_len, NULL);
|
||||
dev_interface_detail = (PSP_DEVICE_INTERFACE_DETAIL_DATA)LocalAlloc(LMEM_FIXED, req_len);
|
||||
if (dev_interface_detail == NULL) {
|
||||
vd_printf("Cannot allocate memory");
|
||||
SetupDiDestroyDeviceInfoList(dev_info);
|
||||
return NULL;
|
||||
}
|
||||
dev_interface_detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA);
|
||||
len = req_len;
|
||||
if (!SetupDiGetDeviceInterfaceDetail(dev_info, &dev_interface, dev_interface_detail, len,
|
||||
&req_len, NULL)) {
|
||||
vd_printf("Cannot get device interface details");
|
||||
SetupDiDestroyDeviceInfoList(dev_info);
|
||||
LocalFree(dev_interface_detail);
|
||||
return NULL;
|
||||
}
|
||||
return dev_interface_detail->DevicePath;
|
||||
}
|
||||
|
||||
bool VDIPort::init()
|
||||
{
|
||||
PTCHAR path = NULL;
|
||||
|
||||
for (int retry = 0; retry < VIOSERIAL_PORT_DEVICE_OPEN_MAX_RETRIES && path == NULL; retry++) {
|
||||
if (path = get_device_path((LPGUID)&GUID_VIOSERIAL_PORT)) {
|
||||
break;
|
||||
}
|
||||
Sleep(VIOSERIAL_PORT_DEVICE_OPEN_RETRY_INTERVAL_MS);
|
||||
}
|
||||
if (path == NULL) {
|
||||
vd_printf("GetDevicePath failed - device/driver missing?");
|
||||
return false;
|
||||
}
|
||||
_handle = CreateFile(path, GENERIC_READ | GENERIC_WRITE , 0, NULL,
|
||||
_handle = CreateFile(VIOSERIAL_PORT_PATH, GENERIC_READ | GENERIC_WRITE , 0, NULL,
|
||||
OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL);
|
||||
if (_handle == INVALID_HANDLE_VALUE) {
|
||||
vd_printf("CreateFile() failed: %u", GetLastError());
|
||||
|
||||
@ -65,7 +65,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
@ -142,7 +142,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
|
||||
LinkIncremental="2"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
@ -216,7 +216,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
@ -293,7 +293,7 @@
|
||||
/>
|
||||
<Tool
|
||||
Name="VCLinkerTool"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib setupapi.lib"
|
||||
AdditionalDependencies="WtsApi32.lib Userenv.lib Version.lib"
|
||||
LinkIncremental="1"
|
||||
GenerateDebugInformation="true"
|
||||
SubSystem="1"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user