Files
ViGEmBus/sys/Ds4Pdo.hpp
Benjamin Höglinger-Stelzer 7b6776d36a Bugfixes from porting
2020-05-11 20:57:14 +02:00

105 lines
2.9 KiB
C++

#pragma once
#include "EmulationTargetPDO.hpp"
#include <ViGEm/km/BusShared.h>
#include "Util.h"
namespace ViGEm::Bus::Targets
{
constexpr unsigned char hid_get_report_id(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST* pReq)
{
return pReq->Value & 0xFF;
}
constexpr unsigned char hid_get_report_type(struct _URB_CONTROL_VENDOR_OR_CLASS_REQUEST* pReq)
{
return (pReq->Value >> 8) & 0xFF;
}
class EmulationTargetDS4 : public Core::EmulationTargetPDO
{
public:
EmulationTargetDS4(ULONG Serial, LONG SessionId, USHORT VendorId = 0x054C, USHORT ProductId = 0x05C4);
~EmulationTargetDS4() = default;
NTSTATUS PdoPrepareDevice(PWDFDEVICE_INIT DeviceInit,
PUNICODE_STRING DeviceId,
PUNICODE_STRING DeviceDescription) override;
NTSTATUS PdoPrepareHardware() override;
NTSTATUS PdoInitContext() override;
VOID GetConfigurationDescriptorType(PUCHAR Buffer, ULONG Length) override;
NTSTATUS UsbGetDeviceDescriptorType(PUSB_DEVICE_DESCRIPTOR pDescriptor) override;
NTSTATUS SelectConfiguration(PURB Urb) override;
void AbortPipe() override;
NTSTATUS UsbClassInterface(PURB Urb) override;
NTSTATUS UsbGetDescriptorFromInterface(PURB Urb) override;
NTSTATUS UsbSelectInterface(PURB Urb) override;
NTSTATUS UsbGetStringDescriptorType(PURB Urb) override;
NTSTATUS UsbBulkOrInterruptTransfer(_URB_BULK_OR_INTERRUPT_TRANSFER* pTransfer, WDFREQUEST Request) override;
NTSTATUS UsbControlTransfer(PURB Urb) override;
NTSTATUS SubmitReport(PVOID NewReport) override;
private:
static PCWSTR _deviceDescription;
static const int HID_REQUEST_GET_REPORT = 0x01;
static const int HID_REQUEST_SET_REPORT = 0x09;
static const int HID_REPORT_TYPE_FEATURE = 0x03;
static const int HID_REPORT_ID_0 = 0xA3;
static const int HID_REPORT_ID_1 = 0x02;
static const int HID_REPORT_MAC_ADDRESSES_ID = 0x12;
static const int HID_REPORT_ID_3 = 0x13;
static const int HID_REPORT_ID_4 = 0x14;
static const int DS4_DESCRIPTOR_SIZE = 0x0029;
#if defined(_X86_)
static const int DS4_CONFIGURATION_SIZE = 0x0050;
#else
static const int DS4_CONFIGURATION_SIZE = 0x0070;
#endif
static const int DS4_MANUFACTURER_NAME_LENGTH = 0x38;
static const int DS4_PRODUCT_NAME_LENGTH = 0x28;
static const int DS4_OUTPUT_BUFFER_OFFSET = 0x04;
static const int DS4_OUTPUT_BUFFER_LENGTH = 0x05;
static const int DS4_REPORT_SIZE = 0x40;
static const int DS4_QUEUE_FLUSH_PERIOD = 0x05;
//
// HID Input Report buffer
//
UCHAR _Report[DS4_REPORT_SIZE];
//
// Output report cache
//
DS4_OUTPUT_REPORT _OutputReport;
//
// Timer for dispatching interrupt transfer
//
WDFTIMER _PendingUsbInRequestsTimer;
//
// Auto-generated MAC address of the target device
//
MAC_ADDRESS _TargetMacAddress;
//
// Default MAC address of the host (not used)
//
MAC_ADDRESS _HostMacAddress;
static EVT_WDF_TIMER PendingUsbRequestsTimerFunc;
};
}