From 64ca25891567b00cfe87944c6bc39e84a77d5766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Mon, 18 May 2020 19:58:05 +0200 Subject: [PATCH] Fixed PNP & Power Capabilities to reflect the actual caps of the physical devices closer Removed default derived destructors --- sys/Ds4Pdo.cpp | 15 +++++++++++++-- sys/Ds4Pdo.hpp | 1 - sys/EmulationTargetPDO.cpp | 36 +++++++++++++----------------------- sys/EmulationTargetPDO.hpp | 12 +++++++++++- sys/ViGEmBus.vcxproj | 8 ++++---- sys/XusbPdo.cpp | 26 ++++++++++++++++++++++++-- sys/XusbPdo.hpp | 1 - 7 files changed, 65 insertions(+), 34 deletions(-) diff --git a/sys/Ds4Pdo.cpp b/sys/Ds4Pdo.cpp index a6b226a..fe87634 100644 --- a/sys/Ds4Pdo.cpp +++ b/sys/Ds4Pdo.cpp @@ -39,8 +39,19 @@ ViGEm::Bus::Targets::EmulationTargetDS4::EmulationTargetDS4(ULONG Serial, LONG S USHORT ProductId) : EmulationTargetPDO( Serial, SessionId, VendorId, ProductId) { - _TargetType = DualShock4Wired; - _UsbConfigurationDescriptionSize = DS4_DESCRIPTOR_SIZE; + this->_TargetType = DualShock4Wired; + this->_UsbConfigurationDescriptionSize = DS4_DESCRIPTOR_SIZE; + + // + // Set PNP Capabilities + // + this->_PnpCapabilities.SurpriseRemovalOK = WdfTrue; + + // + // Set Power Capabilities + // + this->_PowerCapabilities.DeviceState[PowerSystemWorking] = PowerDeviceD0; + this->_PowerCapabilities.WakeFromD0 = WdfTrue; } NTSTATUS ViGEm::Bus::Targets::EmulationTargetDS4::PdoPrepareDevice(PWDFDEVICE_INIT DeviceInit, diff --git a/sys/Ds4Pdo.hpp b/sys/Ds4Pdo.hpp index 9b16e31..8fd94d7 100644 --- a/sys/Ds4Pdo.hpp +++ b/sys/Ds4Pdo.hpp @@ -59,7 +59,6 @@ namespace ViGEm::Bus::Targets { public: EmulationTargetDS4(ULONG Serial, LONG SessionId, USHORT VendorId = 0x054C, USHORT ProductId = 0x05C4); - ~EmulationTargetDS4() = default; NTSTATUS PdoPrepareDevice(PWDFDEVICE_INIT DeviceInit, PUNICODE_STRING DeviceId, diff --git a/sys/EmulationTargetPDO.cpp b/sys/EmulationTargetPDO.cpp index 289b19c..f536159 100644 --- a/sys/EmulationTargetPDO.cpp +++ b/sys/EmulationTargetPDO.cpp @@ -39,8 +39,6 @@ PCWSTR ViGEm::Bus::Core::EmulationTargetPDO::_deviceLocation = L"Virtual Gamepad NTSTATUS ViGEm::Bus::Core::EmulationTargetPDO::PdoCreateDevice(WDFDEVICE ParentDevice, PWDFDEVICE_INIT DeviceInit) { NTSTATUS status = STATUS_UNSUCCESSFUL; - WDF_DEVICE_PNP_CAPABILITIES pnpCaps; - WDF_DEVICE_POWER_CAPABILITIES powerCaps; WDF_PNPPOWER_EVENT_CALLBACKS pnpPowerCallbacks; WDF_OBJECT_ATTRIBUTES pdoAttributes; WDF_IO_QUEUE_CONFIG defaultPdoQueueConfig; @@ -276,35 +274,24 @@ NTSTATUS ViGEm::Bus::Core::EmulationTargetPDO::PdoCreateDevice(WDFDEVICE ParentD #pragma region PNP capabilities - WDF_DEVICE_PNP_CAPABILITIES_INIT(&pnpCaps); + // + // Other capabilities initialized in derived class + // - pnpCaps.Removable = WdfTrue; - pnpCaps.EjectSupported = WdfTrue; - pnpCaps.SurpriseRemovalOK = WdfTrue; + this->_PnpCapabilities.Address = this->_SerialNo; + this->_PnpCapabilities.UINumber = this->_SerialNo; - pnpCaps.Address = this->_SerialNo; - pnpCaps.UINumber = this->_SerialNo; - - WdfDeviceSetPnpCapabilities(this->_PdoDevice, &pnpCaps); + WdfDeviceSetPnpCapabilities(this->_PdoDevice, &this->_PnpCapabilities); #pragma endregion #pragma region Power capabilities - WDF_DEVICE_POWER_CAPABILITIES_INIT(&powerCaps); + // + // Capabilities initialized in derived class + // - powerCaps.DeviceD1 = WdfTrue; - powerCaps.WakeFromD1 = WdfTrue; - powerCaps.DeviceWake = PowerDeviceD1; - - powerCaps.DeviceState[PowerSystemWorking] = PowerDeviceD0; - powerCaps.DeviceState[PowerSystemSleeping1] = PowerDeviceD1; - powerCaps.DeviceState[PowerSystemSleeping2] = PowerDeviceD3; - powerCaps.DeviceState[PowerSystemSleeping3] = PowerDeviceD3; - powerCaps.DeviceState[PowerSystemHibernate] = PowerDeviceD3; - powerCaps.DeviceState[PowerSystemShutdown] = PowerDeviceD3; - - WdfDeviceSetPowerCapabilities(this->_PdoDevice, &powerCaps); + WdfDeviceSetPowerCapabilities(this->_PdoDevice, &this->_PowerCapabilities); #pragma endregion } while (FALSE); @@ -726,6 +713,9 @@ _ProductId(ProductId) { this->_OwnerProcessId = current_process_id(); KeInitializeEvent(&this->_PdoBootNotificationEvent, NotificationEvent, FALSE); + + WDF_DEVICE_PNP_CAPABILITIES_INIT(&this->_PnpCapabilities); + WDF_DEVICE_POWER_CAPABILITIES_INIT(&this->_PowerCapabilities); } bool ViGEm::Bus::Core::EmulationTargetPDO::GetPdoBySerial( diff --git a/sys/EmulationTargetPDO.hpp b/sys/EmulationTargetPDO.hpp index 65b8896..1a31a17 100644 --- a/sys/EmulationTargetPDO.hpp +++ b/sys/EmulationTargetPDO.hpp @@ -165,6 +165,16 @@ namespace ViGEm::Bus::Core virtual NTSTATUS SubmitReportImpl(PVOID NewReport) = 0; static VOID DumpAsHex(PCSTR Prefix, PVOID Buffer, ULONG BufferLength); + + // + // PNP Capabilities may differ from device to device + // + WDF_DEVICE_PNP_CAPABILITIES _PnpCapabilities; + + // + // Power Capabilities may differ from device to device + // + WDF_DEVICE_POWER_CAPABILITIES _PowerCapabilities; // // Unique serial number of the device on the bus @@ -217,7 +227,7 @@ namespace ViGEm::Bus::Core WDFDEVICE _PdoDevice{}; // - // Configuration descriptor size + // Configuration descriptor size (populated by derived class) // ULONG _UsbConfigurationDescriptionSize{}; diff --git a/sys/ViGEmBus.vcxproj b/sys/ViGEmBus.vcxproj index e170324..72cfa65 100644 --- a/sys/ViGEmBus.vcxproj +++ b/sys/ViGEmBus.vcxproj @@ -89,27 +89,27 @@ DbgengKernelDebugger $(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath) true - false + true DbgengKernelDebugger $(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath) true $(SolutionDir)bin\$(DDKPlatform)\ - false + true DbgengKernelDebugger $(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath) true - false + true DbgengKernelDebugger $(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath) true $(SolutionDir)bin\$(DDKPlatform)\ - false + true diff --git a/sys/XusbPdo.cpp b/sys/XusbPdo.cpp index 91b9bd5..106bbcd 100644 --- a/sys/XusbPdo.cpp +++ b/sys/XusbPdo.cpp @@ -41,8 +41,30 @@ ViGEm::Bus::Targets::EmulationTargetXUSB::EmulationTargetXUSB(ULONG Serial, LONG USHORT ProductId) : EmulationTargetPDO( Serial, SessionId, VendorId, ProductId) { - _TargetType = Xbox360Wired; - _UsbConfigurationDescriptionSize = XUSB_DESCRIPTOR_SIZE; + this->_TargetType = Xbox360Wired; + this->_UsbConfigurationDescriptionSize = XUSB_DESCRIPTOR_SIZE; + + // + // Set PNP Capabilities + // + this->_PnpCapabilities.Removable = WdfTrue; + this->_PnpCapabilities.SurpriseRemovalOK = WdfTrue; + this->_PnpCapabilities.UniqueID = WdfTrue; + + // + // Set Power Capabilities + // + this->_PowerCapabilities.DeviceState[PowerSystemWorking] = PowerDeviceD0; + this->_PowerCapabilities.DeviceState[PowerSystemSleeping1] = PowerDeviceD2; + this->_PowerCapabilities.DeviceState[PowerSystemSleeping2] = PowerDeviceD2; + this->_PowerCapabilities.DeviceState[PowerSystemSleeping3] = PowerDeviceD2; + this->_PowerCapabilities.DeviceState[PowerSystemHibernate] = PowerDeviceD2; + this->_PowerCapabilities.DeviceState[PowerSystemShutdown] = PowerDeviceD3; + this->_PowerCapabilities.DeviceD1 = WdfTrue; + this->_PowerCapabilities.DeviceD2 = WdfTrue; + this->_PowerCapabilities.WakeFromD0 = WdfTrue; + this->_PowerCapabilities.WakeFromD1 = WdfTrue; + this->_PowerCapabilities.WakeFromD2 = WdfTrue; } NTSTATUS ViGEm::Bus::Targets::EmulationTargetXUSB::PdoPrepareDevice(PWDFDEVICE_INIT DeviceInit, PUNICODE_STRING DeviceId, diff --git a/sys/XusbPdo.hpp b/sys/XusbPdo.hpp index 61d785c..5d7685d 100644 --- a/sys/XusbPdo.hpp +++ b/sys/XusbPdo.hpp @@ -55,7 +55,6 @@ namespace ViGEm::Bus::Targets { public: EmulationTargetXUSB(ULONG Serial, LONG SessionId, USHORT VendorId = 0x045E, USHORT ProductId = 0x028E); - ~EmulationTargetXUSB() = default; NTSTATUS PdoPrepareDevice(PWDFDEVICE_INIT DeviceInit, PUNICODE_STRING DeviceId,