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

117 lines
3.1 KiB
C++

#pragma once
#include "EmulationTargetPDO.hpp"
namespace ViGEm::Bus::Targets
{
constexpr auto XUSB_POOL_TAG = 'EGiV';
typedef struct _XUSB_INTERRUPT_IN_PACKET
{
UCHAR Id;
UCHAR Size;
XUSB_REPORT Report;
} XUSB_INTERRUPT_IN_PACKET, *PXUSB_INTERRUPT_IN_PACKET;
constexpr bool xusb_is_data_pipe(_URB_BULK_OR_INTERRUPT_TRANSFER* pTransfer)
{
return (pTransfer->PipeHandle == reinterpret_cast<USBD_PIPE_HANDLE>(0xFFFF0081));
}
constexpr bool xusb_is_control_pipe(_URB_BULK_OR_INTERRUPT_TRANSFER* pTransfer)
{
return (pTransfer->PipeHandle == reinterpret_cast<USBD_PIPE_HANDLE>(0xFFFF0083));
}
class EmulationTargetXUSB : public Core::EmulationTargetPDO
{
public:
EmulationTargetXUSB(ULONG Serial, LONG SessionId, USHORT VendorId = 0x045E, USHORT ProductId = 0x028E);
~EmulationTargetXUSB() = 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;
#if defined(_X86_)
static const int XUSB_CONFIGURATION_SIZE = 0x00E4;
#else
static const int XUSB_CONFIGURATION_SIZE = 0x0130;
#endif
static const int XUSB_DESCRIPTOR_SIZE = 0x0099;
static const int XUSB_RUMBLE_SIZE = 0x08;
static const int XUSB_LEDSET_SIZE = 0x03;
static const int XUSB_LEDNUM_SIZE = 0x01;
static const int XUSB_INIT_STAGE_SIZE = 0x03;
static const int XUSB_BLOB_STORAGE_SIZE = 0x2A;
static const int XUSB_BLOB_00_OFFSET = 0x00;
static const int XUSB_BLOB_01_OFFSET = 0x03;
static const int XUSB_BLOB_02_OFFSET = 0x06;
static const int XUSB_BLOB_03_OFFSET = 0x09;
static const int XUSB_BLOB_04_OFFSET = 0x0C;
static const int XUSB_BLOB_05_OFFSET = 0x20;
static const int XUSB_BLOB_06_OFFSET = 0x23;
static const int XUSB_BLOB_07_OFFSET = 0x26;
//
// Rumble buffer
//
UCHAR _Rumble[XUSB_RUMBLE_SIZE];
//
// LED number (represents XInput slot index)
//
CHAR _LedNumber;
//
// Report packet
//
XUSB_INTERRUPT_IN_PACKET _Packet;
//
// Queue for incoming control interrupt transfer
//
WDFQUEUE _HoldingUsbInRequests;
//
// Required for XInputGetCapabilities to work
//
BOOLEAN _ReportedCapabilities;
//
// Required for XInputGetCapabilities to work
//
ULONG _InterruptInitStage;
//
// Storage of binary blobs (packets) for PDO initialization
//
WDFMEMORY _InterruptBlobStorage;
};
}