mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-22 20:33:07 +00:00
mc.mitm: add locks to control access to controller io buffers
This commit is contained in:
parent
dca863fb51
commit
6be4ebb7ad
7 changed files with 33 additions and 2 deletions
|
@ -265,6 +265,8 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result DualsenseController::PushRumbleLedState() {
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
DualsenseReportData report = {};
|
||||
report.id = 0x31;
|
||||
report.output0x31.data[0] = 0x02;
|
||||
|
|
|
@ -224,6 +224,8 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result Dualshock4Controller::PushRumbleLedState() {
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
Dualshock4ReportData report = {};
|
||||
report.id = 0x11;
|
||||
report.output0x11.data[0] = static_cast<uint8_t>(0xc0 | (m_report_rate & 0xff));
|
||||
|
|
|
@ -556,6 +556,8 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result EmulatedSwitchController::FakeSubCmdResponse(const SwitchSubcommandResponse *response) {
|
||||
std::scoped_lock lk(m_input_mutex);
|
||||
|
||||
m_input_report.size = sizeof(SwitchInputReport0x21) + 1;
|
||||
auto report_data = reinterpret_cast<SwitchReportData *>(m_input_report.data);
|
||||
report_data->id = 0x21;
|
||||
|
|
|
@ -97,6 +97,8 @@ namespace ams::controller {
|
|||
}
|
||||
}
|
||||
|
||||
std::scoped_lock lk(m_input_mutex);
|
||||
|
||||
this->UpdateControllerState(report);
|
||||
|
||||
auto switch_report = reinterpret_cast<SwitchReportData *>(m_input_report.data);
|
||||
|
|
|
@ -350,7 +350,9 @@ namespace ams::controller {
|
|||
SwitchController(const bluetooth::Address *address, HardwareID id)
|
||||
: m_address(*address)
|
||||
, m_id(id)
|
||||
, m_settsi_supported(true) { }
|
||||
, m_settsi_supported(true)
|
||||
, m_input_mutex(false)
|
||||
, m_output_mutex(false) { }
|
||||
|
||||
virtual ~SwitchController() { };
|
||||
|
||||
|
@ -382,7 +384,10 @@ namespace ams::controller {
|
|||
|
||||
bool m_settsi_supported;
|
||||
|
||||
os::Mutex m_input_mutex;
|
||||
bluetooth::HidReport m_input_report;
|
||||
|
||||
os::Mutex m_output_mutex;
|
||||
bluetooth::HidReport m_output_report;
|
||||
|
||||
std::queue<std::shared_ptr<HidResponse>> m_future_responses;
|
||||
|
|
|
@ -737,6 +737,8 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result WiiController::SetReportMode(uint8_t mode) {
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
m_output_report.size = sizeof(WiiOutputReport0x12) + 1;
|
||||
auto report_data = reinterpret_cast<WiiReportData *>(m_output_report.data);
|
||||
report_data->id = 0x12;
|
||||
|
@ -748,6 +750,8 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result WiiController::QueryStatus() {
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
m_output_report.size = sizeof(WiiOutputReport0x15) + 1;
|
||||
auto report_data = reinterpret_cast<WiiReportData *>(m_output_report.data);
|
||||
report_data->id = 0x15;
|
||||
|
@ -757,12 +761,14 @@ namespace ams::controller {
|
|||
return ams::ResultSuccess();
|
||||
}
|
||||
|
||||
Result WiiController::WriteMemory(uint32_t write_addr, const void *data, uint8_t size) {
|
||||
Result WiiController::WriteMemory(uint32_t write_addr, const void *data, uint8_t size) {
|
||||
os::SleepThread(ams::TimeSpan::FromMilliSeconds(30));
|
||||
|
||||
Result result;
|
||||
auto output = std::make_unique<bluetooth::HidReport>();
|
||||
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
int attempts = 0;
|
||||
do {
|
||||
m_output_report.size = sizeof(WiiOutputReport0x16) + 1;
|
||||
|
@ -786,6 +792,8 @@ namespace ams::controller {
|
|||
Result result;
|
||||
auto output = std::make_unique<bluetooth::HidReport>();
|
||||
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
int attempts = 0;
|
||||
do {
|
||||
m_output_report.size = sizeof(WiiOutputReport0x17) + 1;
|
||||
|
@ -909,6 +917,8 @@ namespace ams::controller {
|
|||
rumble_data[1].low_band_amp > 0 ||
|
||||
rumble_data[1].high_band_amp > 0;
|
||||
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
m_output_report.size = sizeof(WiiOutputReport0x10) + 1;
|
||||
auto report_data = reinterpret_cast<WiiReportData *>(m_output_report.data);
|
||||
report_data->id = 0x10;
|
||||
|
@ -920,6 +930,8 @@ namespace ams::controller {
|
|||
Result WiiController::CancelVibration() {
|
||||
m_rumble_state = 0;
|
||||
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
m_output_report.size = sizeof(WiiOutputReport0x10) + 1;
|
||||
auto report_data = reinterpret_cast<WiiReportData *>(m_output_report.data);
|
||||
report_data->id = 0x10;
|
||||
|
@ -929,6 +941,8 @@ namespace ams::controller {
|
|||
}
|
||||
|
||||
Result WiiController::SetPlayerLed(uint8_t led_mask) {
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
m_output_report.size = sizeof(WiiOutputReport0x11) + 1;
|
||||
auto report_data = reinterpret_cast<WiiReportData *>(m_output_report.data);
|
||||
report_data->id = 0x11;
|
||||
|
|
|
@ -29,9 +29,13 @@ namespace ams::controller {
|
|||
|
||||
Result XiaomiController::Initialize() {
|
||||
R_TRY(EmulatedSwitchController::Initialize());
|
||||
|
||||
std::scoped_lock lk(m_output_mutex);
|
||||
|
||||
m_output_report.size = sizeof(init_packet);
|
||||
std::memcpy(m_output_report.data, init_packet, sizeof(init_packet));
|
||||
R_TRY(this->WriteDataReport(&m_output_report));
|
||||
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue