btdrv-mitm: simplify controller base types

This commit is contained in:
ndeadly 2020-08-24 22:47:27 +02:00
parent bae44c16f1
commit d333b39394
4 changed files with 22 additions and 57 deletions

View file

@ -6,28 +6,13 @@
namespace ams::controller {
Result EmulatedSwitchController::setVibration(void) {
Result EmulatedSwitchController::handleIncomingReport(const bluetooth::HidReport *report) {
this->convertReportFormat(report, &m_inputReport);
bluetooth::hid::report::WriteHidReportBuffer(&m_address, &m_inputReport);
return ams::ResultSuccess();
}
Result EmulatedSwitchController::setPlayerLed(u8 led_mask) {
return ams::ResultSuccess();
}
const bluetooth::HidReport * EmulatedSwitchController::handleIncomingReport(const bluetooth::HidReport *report) {
m_inputReport.size = 0;
u8 cmdId = report->data[0];
switch (cmdId) {
default:
break;
}
return &m_inputReport;;
}
const bluetooth::HidReport * EmulatedSwitchController::handleOutgoingReport(const bluetooth::HidReport *report) {
m_outputReport.size = 0;
@ -99,7 +84,7 @@ namespace ams::controller {
}
Result EmulatedSwitchController::subCmdSpiFlashRead(const bluetooth::HidReport *report) {
// Official Pro Controller reads these
// These are read from official Pro Controller
// @ 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)
// @ 0x00006080: 50 fd 00 00 c6 0f 0f 30 61 ae 90 d9 d4 14 54 41 15 54 c7 79 9c 33 36 63 <= Factory Sensor and Stick device parameters
@ -180,12 +165,10 @@ namespace ams::controller {
return this->fakeSubCmdResponse(response, sizeof(response));
}
/* Write a fake subcommand response into buffer */
Result EmulatedSwitchController::fakeSubCmdResponse(const u8 response[], size_t size) {
auto report = &m_inputReport;
auto reportData = reinterpret_cast<controller::SwitchReportData *>(&report->data);
report->size = sizeof(controller::SwitchInputReport0x21);
reportData->id = 0x21;
auto reportData = reinterpret_cast<controller::SwitchReportData *>(&m_inputReport.data);
m_inputReport.size = sizeof(controller::SwitchInputReport0x21);
reportData->id = 0x21;
reportData->input0x21.conn_info = 0;
reportData->input0x21.battery = m_battery | m_charging;
reportData->input0x21.buttons = {0x00, 0x00, 0x00};
@ -196,7 +179,8 @@ namespace ams::controller {
reportData->input0x21.timer = os::ConvertToTimeSpan(os::GetSystemTick()).GetMilliSeconds() & 0xff;
return bluetooth::hid::report::WriteFakeHidData(&m_address, report);
//Write a fake response into the report buffer
return bluetooth::hid::report::WriteHidReportBuffer(&m_address, &m_inputReport);
}
}

View file

@ -23,12 +23,14 @@ namespace ams::controller {
, m_charging(false)
, m_battery(BATTERY_MAX) { };
const bluetooth::HidReport * handleIncomingReport(const bluetooth::HidReport *report);
Result handleIncomingReport(const bluetooth::HidReport *report);
const bluetooth::HidReport * handleOutgoingReport(const bluetooth::HidReport *report);
protected:
virtual Result setVibration(void);
virtual Result setPlayerLed(u8 led_mask);
virtual void convertReportFormat(const bluetooth::HidReport *inReport, bluetooth::HidReport *outReport) {};
virtual Result setVibration(void) { return ams::ResultSuccess(); };
virtual Result setPlayerLed(u8 led_mask) { return ams::ResultSuccess(); };
Result handleSubCmdReport(const bluetooth::HidReport *report);
Result subCmdRequestDeviceInfo(const bluetooth::HidReport *report);

View file

@ -1,25 +1,10 @@
#include "switchcontroller.hpp"
#include "../bluetooth/bluetooth_hid_report.hpp"
namespace ams::controller {
const bluetooth::Address& SwitchController::address(void) const {
return m_address;
}
ControllerType SwitchController::type(void) {
return m_type;
}
bool SwitchController::isSwitchController(void) {
return m_switchController;
}
Result SwitchController::initialize(void) {
return ams::ResultSuccess();
}
const bluetooth::HidReport * SwitchController::handleIncomingReport(const bluetooth::HidReport *report) {
return report;
Result SwitchController::handleIncomingReport(const bluetooth::HidReport *report) {
return bluetooth::hid::report::WriteHidReportBuffer(&m_address, report);
}
const bluetooth::HidReport * SwitchController::handleOutgoingReport(const bluetooth::HidReport *report) {

View file

@ -126,27 +126,21 @@ namespace ams::controller {
class SwitchController {
public:
const bluetooth::Address& address(void) const;
ControllerType type(void);
bool isSwitchController(void);
const bluetooth::Address& address(void) const { return m_address; };
ControllerType type(void) { return m_type; };
virtual Result initialize(void);
virtual void convertReportFormat(const bluetooth::HidReport *inReport, bluetooth::HidReport *outReport) {};
virtual Result initialize(void) { return ams::ResultSuccess(); };
virtual const bluetooth::HidReport * handleIncomingReport(const bluetooth::HidReport *report);
virtual Result handleIncomingReport(const bluetooth::HidReport *report);
virtual const bluetooth::HidReport * handleOutgoingReport(const bluetooth::HidReport *report);
protected:
SwitchController(ControllerType type, const bluetooth::Address *address)
: m_type(type)
, m_address(*address)
, m_switchController((type == ControllerType_Joycon) || (type == ControllerType_SwitchPro)) { };
, m_address(*address) { };
ControllerType m_type;
bluetooth::Address m_address;
bool m_switchController;
};
}