mirror of
https://github.com/ndeadly/MissionControl
synced 2025-02-16 21:28:25 +00:00
btdrv-mitm: use static report buffers in EmulatedSwitchController class
This commit is contained in:
parent
c6d318c90a
commit
8ed74ca2c6
5 changed files with 35 additions and 31 deletions
|
@ -133,10 +133,10 @@ namespace ams::controller {
|
|||
Dualshock4OutputReport0x11 report = {0xa2, 0x11, 0xc0, 0x20, 0xf3, 0x04, 0x00, 0x00, 0x00, m_ledColour.r, m_ledColour.g, m_ledColour.b};
|
||||
report.crc = crc32Calculate(report.data, sizeof(report.data));
|
||||
|
||||
m_outputReport.size = sizeof(report) - 1;
|
||||
std::memcpy(m_outputReport.data, &report.data[1], m_outputReport.size);
|
||||
s_outputReport.size = sizeof(report) - 1;
|
||||
std::memcpy(s_outputReport.data, &report.data[1], s_outputReport.size);
|
||||
|
||||
R_TRY(bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport));
|
||||
R_TRY(bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport));
|
||||
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
|
|
@ -6,9 +6,12 @@
|
|||
|
||||
namespace ams::controller {
|
||||
|
||||
bluetooth::HidReport EmulatedSwitchController::s_inputReport;
|
||||
bluetooth::HidReport EmulatedSwitchController::s_outputReport;
|
||||
|
||||
Result EmulatedSwitchController::handleIncomingReport(const bluetooth::HidReport *report) {
|
||||
this->convertReportFormat(report, &m_inputReport);
|
||||
bluetooth::hid::report::WriteHidReportBuffer(&m_address, &m_inputReport);
|
||||
this->convertReportFormat(report, &s_inputReport);
|
||||
bluetooth::hid::report::WriteHidReportBuffer(&m_address, &s_inputReport);
|
||||
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
@ -165,8 +168,8 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result EmulatedSwitchController::fakeSubCmdResponse(const u8 response[], size_t size) {
|
||||
auto reportData = reinterpret_cast<controller::SwitchReportData *>(&m_inputReport.data);
|
||||
m_inputReport.size = sizeof(controller::SwitchInputReport0x21);
|
||||
auto reportData = reinterpret_cast<controller::SwitchReportData *>(&s_inputReport.data);
|
||||
s_inputReport.size = sizeof(controller::SwitchInputReport0x21);
|
||||
reportData->id = 0x21;
|
||||
reportData->input0x21.conn_info = 0;
|
||||
reportData->input0x21.battery = m_battery | m_charging;
|
||||
|
@ -179,7 +182,7 @@ namespace ams::controller {
|
|||
reportData->input0x21.timer = os::ConvertToTimeSpan(os::GetSystemTick()).GetMilliSeconds() & 0xff;
|
||||
|
||||
//Write a fake response into the report buffer
|
||||
return bluetooth::hid::report::WriteHidReportBuffer(&m_address, &m_inputReport);
|
||||
return bluetooth::hid::report::WriteHidReportBuffer(&m_address, &s_inputReport);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -50,8 +50,9 @@ namespace ams::controller {
|
|||
|
||||
bool m_charging;
|
||||
uint8_t m_battery;
|
||||
bluetooth::HidReport m_inputReport;
|
||||
bluetooth::HidReport m_outputReport;
|
||||
|
||||
static bluetooth::HidReport s_inputReport;
|
||||
static bluetooth::HidReport s_outputReport;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -287,61 +287,61 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result WiiController::writeMemory(uint32_t write_addr, const uint8_t *data, uint8_t size) {
|
||||
m_outputReport.size = sizeof(WiiOutputReport0x16) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(m_outputReport.data);
|
||||
s_outputReport.size = sizeof(WiiOutputReport0x16) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(s_outputReport.data);
|
||||
reportData->id = 0x16;
|
||||
reportData->output0x16.address = ams::util::SwapBytes(write_addr);
|
||||
reportData->output0x16.size = size;
|
||||
std::memcpy(&reportData->output0x16.data, data, size);
|
||||
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport);
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport);
|
||||
}
|
||||
|
||||
Result WiiController::readMemory(uint32_t read_addr, uint16_t size) {
|
||||
m_outputReport.size = sizeof(WiiOutputReport0x17) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(m_outputReport.data);
|
||||
s_outputReport.size = sizeof(WiiOutputReport0x17) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(s_outputReport.data);
|
||||
reportData->id = 0x17;
|
||||
reportData->output0x17.address = ams::util::SwapBytes(read_addr);
|
||||
reportData->output0x17.size = ams::util::SwapBytes(size);
|
||||
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport);
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport);
|
||||
}
|
||||
|
||||
Result WiiController::setReportMode(uint8_t mode) {
|
||||
m_outputReport.size = sizeof(WiiOutputReport0x12) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(m_outputReport.data);
|
||||
s_outputReport.size = sizeof(WiiOutputReport0x12) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(s_outputReport.data);
|
||||
reportData->id = 0x12;
|
||||
reportData->output0x12._unk = 0;
|
||||
reportData->output0x12.report_mode = mode;
|
||||
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport);
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport);
|
||||
}
|
||||
|
||||
Result WiiController::setPlayerLeds(uint8_t mask) {
|
||||
m_outputReport.size = sizeof(WiiOutputReport0x15) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(m_outputReport.data);
|
||||
s_outputReport.size = sizeof(WiiOutputReport0x15) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(s_outputReport.data);
|
||||
reportData->id = 0x11;
|
||||
reportData->output0x11.leds = mask;
|
||||
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport);
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport);
|
||||
}
|
||||
|
||||
Result WiiController::queryStatus(void) {
|
||||
m_outputReport.size = sizeof(WiiOutputReport0x15) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(m_outputReport.data);
|
||||
s_outputReport.size = sizeof(WiiOutputReport0x15) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(s_outputReport.data);
|
||||
reportData->id = 0x15;
|
||||
reportData->output0x15._unk = 0;
|
||||
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport);
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport);
|
||||
}
|
||||
|
||||
Result WiiController::setPlayerLed(uint8_t led_mask) {
|
||||
m_outputReport.size = sizeof(WiiOutputReport0x15) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(m_outputReport.data);
|
||||
s_outputReport.size = sizeof(WiiOutputReport0x15) + 1;
|
||||
auto reportData = reinterpret_cast<WiiReportData *>(s_outputReport.data);
|
||||
reportData->id = 0x11;
|
||||
reportData->output0x11.leds = (led_mask << 4) & 0xf0;;
|
||||
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport);
|
||||
return bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport);
|
||||
}
|
||||
|
||||
Result WiiController::sendInit1(void) {
|
||||
|
|
|
@ -17,9 +17,9 @@ namespace ams::controller {
|
|||
|
||||
const u8 init_packet[] = {0x05, 0x20, 0x00, 0x01, 0x00};
|
||||
|
||||
m_outputReport.size = sizeof(init_packet);
|
||||
std::memcpy(m_outputReport.data, init_packet, sizeof(init_packet));
|
||||
R_TRY(bluetooth::hid::report::SendHidReport(&m_address, &m_outputReport));
|
||||
s_outputReport.size = sizeof(init_packet);
|
||||
std::memcpy(s_outputReport.data, init_packet, sizeof(init_packet));
|
||||
R_TRY(bluetooth::hid::report::SendHidReport(&m_address, &s_outputReport));
|
||||
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue