btdrv-mitm: rename FakeSwitchController to EmulatedSwitchController

This commit is contained in:
ndeadly 2020-08-17 23:17:02 +02:00
parent ec37e65e69
commit 73532cfc9f
7 changed files with 37 additions and 34 deletions

View file

@ -21,7 +21,7 @@ namespace ams::controller {
}
Result Dualshock4Controller::initialize(void) {
R_TRY(FakeSwitchController::initialize());
R_TRY(EmulatedSwitchController::initialize());
R_TRY(this->updateControllerState());
return ams::ResultSuccess();

View file

@ -1,5 +1,5 @@
#pragma once
#include "fakeswitchcontroller.hpp"
#include "emulatedswitchcontroller.hpp"
namespace ams::controller {
@ -105,7 +105,7 @@ namespace ams::controller {
};
} __attribute__((packed));
class Dualshock4Controller : public FakeSwitchController {
class Dualshock4Controller : public EmulatedSwitchController {
public:
static constexpr const HardwareID hardwareIds[] = {
@ -114,7 +114,7 @@ namespace ams::controller {
};
Dualshock4Controller(const bluetooth::Address *address)
: FakeSwitchController(ControllerType_Dualshock4, address), m_ledColour({0, 0, 0}) { };
: EmulatedSwitchController(ControllerType_Dualshock4, address), m_ledColour({0, 0, 0}) { };
Result initialize(void);
Result setPlayerLed(u8 led_mask);

View file

@ -1,24 +1,26 @@
#include "fakeswitchcontroller.hpp"
#include "emulatedswitchcontroller.hpp"
#include <memory>
#include "../bluetooth/bluetooth_hid_report.hpp"
#include "../btdrv_mitm_logging.hpp"
namespace ams::controller {
Result FakeSwitchController::setVibration(void) {
Result EmulatedSwitchController::setVibration(void) {
return ams::ResultSuccess();
}
Result FakeSwitchController::setPlayerLed(u8 led_mask) {
Result EmulatedSwitchController::setPlayerLed(u8 led_mask) {
return ams::ResultSuccess();
}
const bluetooth::HidReport * FakeSwitchController::handleIncomingReport(const bluetooth::HidReport *report) {
const bluetooth::HidReport * EmulatedSwitchController::handleIncomingReport(const bluetooth::HidReport *report) {
m_inputReport.size = 0;
u8 cmdId = report->data[0];
switch (cmdId) {
default:
break;
}
@ -26,7 +28,7 @@ namespace ams::controller {
return &m_inputReport;;
}
const bluetooth::HidReport * FakeSwitchController::handleOutgoingReport(const bluetooth::HidReport *report) {
const bluetooth::HidReport * EmulatedSwitchController::handleOutgoingReport(const bluetooth::HidReport *report) {
m_outputReport.size = 0;
u8 cmdId = report->data[0];
@ -34,7 +36,6 @@ namespace ams::controller {
case 0x01: // Subcmd
this->handleSubCmdReport(report);
break;
case 0x10: // Rumble
default:
break;
@ -43,9 +44,10 @@ namespace ams::controller {
return &m_outputReport;
}
Result FakeSwitchController::handleSubCmdReport(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::handleSubCmdReport(const bluetooth::HidReport *report) {
const u8 *subCmd = &report->data[10];
auto subCmdId = static_cast<bluetooth::SubCmdType>(subCmd[0]);
switch (subCmdId) {
case bluetooth::SubCmd_RequestDeviceInfo:
R_TRY(this->subCmdRequestDeviceInfo(report));
@ -84,18 +86,19 @@ namespace ams::controller {
R_TRY(this->subCmdEnableVibration(report));
break;
default:
BTDRV_LOG_FMT("Unrecognised subcmd: 0x%02x", subCmdId);
break;
}
return ams::ResultSuccess();
}
Result FakeSwitchController::subCmdRequestDeviceInfo(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdRequestDeviceInfo(const bluetooth::HidReport *report) {
const u8 response[] = {0x82, 0x02, 0x03, 0x48, 0x03, 0x02, m_address.address[0], m_address.address[1], m_address.address[2], m_address.address[3], m_address.address[4], m_address.address[5], 0x01, 0x02};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdSpiFlashRead(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSpiFlashRead(const bluetooth::HidReport *report) {
// Official Pro Controller reads these
// @ 0x00006000: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff <= Serial
// @ 0x00006050: 32 32 32 ff ff ff ff ff ff ff ff ff <= RGB colours (body, buttons, left grip, right grip)
@ -123,42 +126,42 @@ namespace ams::controller {
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response.get(), response_size);
}
Result FakeSwitchController::subCmdSpiFlashWrite(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSpiFlashWrite(const bluetooth::HidReport *report) {
const u8 response[] = {0x80, bluetooth::SubCmd_SpiFlashWrite, 0x01};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdSpiSectorErase(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSpiSectorErase(const bluetooth::HidReport *report) {
const u8 response[] = {0x80, bluetooth::SubCmd_SpiSectorErase, 0x01};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdSetInputReportMode(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSetInputReportMode(const bluetooth::HidReport *report) {
const u8 response[] = {0x80, bluetooth::SubCmd_SetInputReportMode};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdTriggersElapsedTime(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdTriggersElapsedTime(const bluetooth::HidReport *report) {
const u8 response[] = {0x83, bluetooth::SubCmd_TriggersElapsedTime};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdSetShipPowerState(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSetShipPowerState(const bluetooth::HidReport *report) {
const u8 response[] = {0x80, bluetooth::SubCmd_SetShipPowerState, 0x00};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdSetMcuConfig(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSetMcuConfig(const bluetooth::HidReport *report) {
const u8 response[] = {0xa0, bluetooth::SubCmd_SetMcuConfig, 0x01, 0x00, 0xff, 0x00, 0x03, 0x00, 0x05, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5c};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdSetMcuState(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSetMcuState(const bluetooth::HidReport *report) {
const u8 response[] = {0x80, bluetooth::SubCmd_SetMcuState};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdSetPlayerLeds(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdSetPlayerLeds(const bluetooth::HidReport *report) {
const u8 *subCmd = &report->data[10];
u8 led_mask = subCmd[1];
R_TRY(this->setPlayerLed(led_mask));
@ -167,12 +170,12 @@ namespace ams::controller {
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdEnableImu(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdEnableImu(const bluetooth::HidReport *report) {
const u8 response[] = {0x80, bluetooth::SubCmd_EnableImu};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}
Result FakeSwitchController::subCmdEnableVibration(const bluetooth::HidReport *report) {
Result EmulatedSwitchController::subCmdEnableVibration(const bluetooth::HidReport *report) {
const u8 response[] = {0x80, bluetooth::SubCmd_EnableVibration};
return bluetooth::hid::report::FakeSubCmdResponse(&m_address, response, sizeof(response));
}

View file

@ -3,10 +3,10 @@
namespace ams::controller {
class FakeSwitchController : public SwitchController {
class EmulatedSwitchController : public SwitchController {
public:
FakeSwitchController(ControllerType type, const bluetooth::Address *address)
EmulatedSwitchController(ControllerType type, const bluetooth::Address *address)
: SwitchController(type, address) { };
const bluetooth::HidReport * handleIncomingReport(const bluetooth::HidReport *report);

View file

@ -1,5 +1,5 @@
#pragma once
#include "fakeswitchcontroller.hpp"
#include "emulatedswitchcontroller.hpp"
namespace ams::controller {
@ -253,7 +253,7 @@ namespace ams::controller {
};
} __attribute__ ((__packed__));
class WiiController : public FakeSwitchController {
class WiiController : public EmulatedSwitchController {
public:
Result initialize(void);
@ -261,7 +261,7 @@ namespace ams::controller {
protected:
WiiController(ControllerType type, const bluetooth::Address *address)
: FakeSwitchController(type, address)
: EmulatedSwitchController(type, address)
, m_extension(WiiExtensionController_None) { };
void handleInputReport0x20(const WiiReportData *src, SwitchReportData *dst);

View file

@ -13,7 +13,7 @@ namespace ams::controller {
}
Result XboxOneController::initialize(void) {
R_TRY(FakeSwitchController::initialize());
R_TRY(EmulatedSwitchController::initialize());
// Todo: may need to check controller version to determine whether or not to send this
const u8 init_packet[] = {0x05, 0x20, 0x00, 0x01, 0x00};

View file

@ -1,5 +1,5 @@
#pragma once
#include "fakeswitchcontroller.hpp"
#include "emulatedswitchcontroller.hpp"
namespace ams::controller {
@ -93,16 +93,16 @@ namespace ams::controller {
};
} __attribute__ ((__packed__));
class XboxOneController : public FakeSwitchController {
class XboxOneController : public EmulatedSwitchController {
public:
static constexpr const HardwareID hardwareIds[] = {
{0x045e, 0x02e0}, // Official Xbox One S Controller (old FW?)
{0x045e, 0x02e0}, // Official Xbox One S Controller
{0x045e, 0x02fd} // Official Xbox One S Controller
};
XboxOneController(const bluetooth::Address *address)
: FakeSwitchController(ControllerType_XboxOne, address) { };
: EmulatedSwitchController(ControllerType_XboxOne, address) { };
Result initialize(void);
void convertReportFormat(const bluetooth::HidReport *inReport, bluetooth::HidReport *outReport);