mc.mitm: add mitm for alternate WriteHidData function

This commit is contained in:
ndeadly 2023-02-15 21:12:56 +01:00
parent 7c719a31ec
commit ec53764c15
4 changed files with 27 additions and 4 deletions

View file

@ -87,7 +87,6 @@ namespace ams::mitm::bluetooth {
Result BtdrvMitmService::WriteHidData(ams::bluetooth::Address address, const sf::InPointerBuffer &buffer) {
auto report = reinterpret_cast<const ams::bluetooth::HidReport *>(buffer.GetPointer());
if (m_client_info.program_id == ncm::SystemProgramId::Hid) {
auto device = controller::LocateHandler(&address);
if (device) {
@ -101,6 +100,20 @@ namespace ams::mitm::bluetooth {
return ams::ResultSuccess();
}
Result BtdrvMitmService::WriteHidData2(ams::bluetooth::Address address, const sf::InPointerBuffer &buffer) {
if (m_client_info.program_id == ncm::SystemProgramId::Hid) {
auto device = controller::LocateHandler(&address);
if (device) {
device->HandleOutputDataReport(reinterpret_cast<const ams::bluetooth::HidReport *>(buffer.GetPointer()));
}
}
else {
R_TRY(btdrvWriteHidData2Fwd(m_forward_service.get(), &address, buffer.GetPointer(), buffer.GetSize()));
}
return ams::ResultSuccess();
}
Result BtdrvMitmService::GetHidEventInfo(sf::Out<ams::bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer) {
return ams::bluetooth::hid::GetEventInfo(out_type.GetPointer(), out_buffer.GetPointer(), out_buffer.GetSize());
}

View file

@ -23,6 +23,7 @@
AMS_SF_METHOD_INFO(C, H, 15, Result, GetEventInfo, (sf::Out<ams::bluetooth::EventType> out_type, const sf::OutPointerBuffer &out_buffer), (out_type, out_buffer)) \
AMS_SF_METHOD_INFO(C, H, 16, Result, InitializeHid, (sf::OutCopyHandle out_handle, u16 version), (out_handle, version)) \
AMS_SF_METHOD_INFO(C, H, 19, Result, WriteHidData, (ams::bluetooth::Address address, const sf::InPointerBuffer &buffer), (address, buffer)) \
AMS_SF_METHOD_INFO(C, H, 20, Result, WriteHidData2, (ams::bluetooth::Address address, const sf::InPointerBuffer &buffer), (address, buffer)) \
AMS_SF_METHOD_INFO(C, H, 27, Result, GetHidEventInfo, (sf::Out<ams::bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer), (out_type, out_buffer)) \
AMS_SF_METHOD_INFO(C, H, 28, Result, SetTsi, (ams::bluetooth::Address address, u8 tsi), (address, tsi)) \
AMS_SF_METHOD_INFO(C, H, 36, Result, RegisterHidReportEventDeprecated, (sf::OutCopyHandle out_handle), (out_handle), hos::Version_1_0_0, hos::Version_3_0_2) \
@ -62,6 +63,7 @@ namespace ams::mitm::bluetooth {
Result GetEventInfo(sf::Out<ams::bluetooth::EventType> out_type, const sf::OutPointerBuffer &out_buffer);
Result InitializeHid(sf::OutCopyHandle out_handle, u16 version);
Result WriteHidData(ams::bluetooth::Address address, const sf::InPointerBuffer &buffer);
Result WriteHidData2(ams::bluetooth::Address address, const sf::InPointerBuffer &buffer);
Result GetHidEventInfo(sf::Out<ams::bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer);
Result SetTsi(ams::bluetooth::Address address, u8 tsi);
Result RegisterHidReportEventDeprecated(sf::OutCopyHandle out_handle);

View file

@ -34,10 +34,17 @@ Result btdrvInitializeHidFwd(Service* srv, Handle *out_handle, u16 version) {
);
}
Result btdrvWriteHidDataFwd(Service* srv, const BtdrvAddress *address, const BtdrvHidReport *data) {
Result btdrvWriteHidDataFwd(Service* srv, const BtdrvAddress *address, const BtdrvHidReport *report) {
return serviceMitmDispatchIn(srv, 19, *address,
.buffer_attrs = { SfBufferAttr_FixedSize | SfBufferAttr_HipcPointer | SfBufferAttr_In },
.buffers = { {data, sizeof(BtdrvHidReport)} }
.buffers = { {report, sizeof(BtdrvHidReport)} }
);
}
Result btdrvWriteHidData2Fwd(Service* srv, const BtdrvAddress *address, const void *data, size_t size) {
return serviceMitmDispatchIn(srv, 20, *address,
.buffer_attrs = { SfBufferAttr_HipcPointer | SfBufferAttr_In },
.buffers = { {data, size} }
);
}

View file

@ -23,7 +23,8 @@ extern "C" {
Result btdrvInitializeBluetoothFwd(Service* srv, Handle *out_handle);
Result btdrvEnableBluetoothFwd(Service* srv);
Result btdrvInitializeHidFwd(Service* srv, Handle *out_handle, u16 version);
Result btdrvWriteHidDataFwd(Service* srv, const BtdrvAddress *address, const BtdrvHidReport *data);
Result btdrvWriteHidDataFwd(Service* srv, const BtdrvAddress *address, const BtdrvHidReport *report);
Result btdrvWriteHidData2Fwd(Service* srv, const BtdrvAddress *address, const void *data, size_t size);
Result btdrvRegisterHidReportEventFwd(Service* srv, Handle *out_handle);
Result btdrvGetHidReportEventInfoFwd(Service* srv, Handle *out_handle);
Result btdrvInitializeBleFwd(Service* srv, Handle *out_handle);