Fixed PNP & Power Capabilities to reflect the actual caps of the physical devices closer

Removed default derived destructors
This commit is contained in:
Benjamin Höglinger-Stelzer
2020-05-18 19:58:05 +02:00
parent 2fe83018c0
commit 64ca258915
7 changed files with 65 additions and 34 deletions

View File

@@ -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,

View File

@@ -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,

View File

@@ -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(

View File

@@ -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{};

View File

@@ -89,27 +89,27 @@
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<IncludePath>$(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath)</IncludePath>
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
<EnableInf2cat>false</EnableInf2cat>
<EnableInf2cat>true</EnableInf2cat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<IncludePath>$(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath)</IncludePath>
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
<OutDir>$(SolutionDir)bin\$(DDKPlatform)\</OutDir>
<EnableInf2cat>false</EnableInf2cat>
<EnableInf2cat>true</EnableInf2cat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<IncludePath>$(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath)</IncludePath>
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
<EnableInf2cat>false</EnableInf2cat>
<EnableInf2cat>true</EnableInf2cat>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<DebuggerFlavor>DbgengKernelDebugger</DebuggerFlavor>
<IncludePath>$(SolutionDir)include;$(SolutionDir)client\include;$(IncludePath)</IncludePath>
<Inf2CatUseLocalTime>true</Inf2CatUseLocalTime>
<OutDir>$(SolutionDir)bin\$(DDKPlatform)\</OutDir>
<EnableInf2cat>false</EnableInf2cat>
<EnableInf2cat>true</EnableInf2cat>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Inf>

View File

@@ -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,

View File

@@ -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,