bluetooth-mitm: misc minor improvements to EmulatedSwitchController

This commit is contained in:
ndeadly 2020-10-13 01:28:41 +02:00
parent abb87560ec
commit 8db2d95707
2 changed files with 18 additions and 18 deletions

View file

@ -61,8 +61,8 @@ namespace ams::controller {
this->UpdateControllerState(report);
// Prepare Switch report
auto switch_report = reinterpret_cast<SwitchReportData *>(s_input_report.data);
s_input_report.size = sizeof(SwitchInputReport0x30) + 1;
auto switch_report = reinterpret_cast<SwitchReportData *>(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<controller::SwitchReportData *>(&s_input_report.data);
s_input_report.size = sizeof(SwitchInputReport0x21) + 1;
auto report_data = reinterpret_cast<SwitchReportData *>(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

View file

@ -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;