From 8db2d9570784db28932389f28da27a02fac4e9f4 Mon Sep 17 00:00:00 2001 From: ndeadly <24677491+ndeadly@users.noreply.github.com> Date: Tue, 13 Oct 2020 01:28:41 +0200 Subject: [PATCH] bluetooth-mitm: misc minor improvements to EmulatedSwitchController --- .../emulated_switch_controller.cpp | 6 ++-- .../source/controllers/switch_controller.hpp | 30 +++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/bluetooth-mitm/source/controllers/emulated_switch_controller.cpp b/bluetooth-mitm/source/controllers/emulated_switch_controller.cpp index c36b63e..dfd51df 100644 --- a/bluetooth-mitm/source/controllers/emulated_switch_controller.cpp +++ b/bluetooth-mitm/source/controllers/emulated_switch_controller.cpp @@ -61,8 +61,8 @@ namespace ams::controller { this->UpdateControllerState(report); // Prepare Switch report - auto switch_report = reinterpret_cast(s_input_report.data); s_input_report.size = sizeof(SwitchInputReport0x30) + 1; + auto switch_report = reinterpret_cast(s_input_report.data); switch_report->id = 0x30; switch_report->input0x30.conn_info = 0; switch_report->input0x30.battery = m_battery | m_charging; @@ -236,8 +236,8 @@ namespace ams::controller { } Result EmulatedSwitchController::FakeSubCmdResponse(const uint8_t response[], size_t size) { - auto report_data = reinterpret_cast(&s_input_report.data); s_input_report.size = sizeof(SwitchInputReport0x21) + 1; + auto report_data = reinterpret_cast(s_input_report.data); report_data->id = 0x21; report_data->input0x21.conn_info = 0; report_data->input0x21.battery = m_battery | m_charging; @@ -245,7 +245,7 @@ namespace ams::controller { report_data->input0x21.left_stick = m_left_stick; report_data->input0x21.right_stick = m_right_stick; report_data->input0x21.vibrator = 0; - std::memcpy(&report_data->input0x21.subcmd, response, size); + std::memcpy(&report_data->input0x21.response, response, size); report_data->input0x21.timer = os::ConvertToTimeSpan(os::GetSystemTick()).GetMilliSeconds() & 0xff; //Write a fake response into the report buffer diff --git a/bluetooth-mitm/source/controllers/switch_controller.hpp b/bluetooth-mitm/source/controllers/switch_controller.hpp index 1479825..1b0cd1f 100644 --- a/bluetooth-mitm/source/controllers/switch_controller.hpp +++ b/bluetooth-mitm/source/controllers/switch_controller.hpp @@ -81,7 +81,7 @@ namespace ams::controller { uint16_t gyro_3; } __attribute__ ((__packed__)); - enum SubCmdType : u8 { + enum SubCmdType : uint8_t { SubCmd_GetControllerState = 0x00, SubCmd_ManualPair = 0x01, SubCmd_RequestDeviceInfo = 0x02, @@ -110,6 +110,12 @@ namespace ams::controller { SubCmd_GetGpioPinValue = 0x52, }; + struct SwitchSubcommandResponse { + uint8_t ack; + uint8_t id; + uint8_t data[0x23]; + } __attribute__ ((__packed__)); + struct SwitchOutputReport0x01; struct SwitchOutputReport0x03; struct SwitchOutputReport0x10; @@ -117,20 +123,14 @@ namespace ams::controller { struct SwitchOutputReport0x12; struct SwitchInputReport0x21 { - uint8_t timer; - uint8_t conn_info : 4; - uint8_t battery : 4; - SwitchButtonData buttons; - SwitchStickData left_stick; - SwitchStickData right_stick; - uint8_t vibrator; - - struct { - uint8_t ack; - uint8_t id; - uint8_t reply; - uint8_t data[0x22]; - } subcmd; + uint8_t timer; + uint8_t conn_info : 4; + uint8_t battery : 4; + SwitchButtonData buttons; + SwitchStickData left_stick; + SwitchStickData right_stick; + uint8_t vibrator; + SwitchSubcommandResponse response; } __attribute__ ((__packed__)); struct SwitchInputReport0x23;