btdrv-mitm: update to use new service interface definition methodology

This commit is contained in:
ndeadly 2020-08-05 00:04:52 +02:00
parent d2742a17f9
commit 9ced06f2a6
2 changed files with 33 additions and 60 deletions

View file

@ -6,35 +6,39 @@
namespace ams::mitm::btdrv {
class BtdrvMitmService : public sf::IMitmServiceObject {
namespace {
private:
enum class CommandId {
InitializeBluetooth = 1,
FinalizeBluetooth = 4,
GetEventInfo = 15,
InitializeHid = 16,
WriteHidData = 19,
GetPairedDeviceInfo = 25,
FinalizeHid = 26,
GetHidEventInfo = 27,
RegisterHidReportEventDeprecated = 36,
RegisterHidReportEvent = 37,
GetHidReportEventInfoDeprecated1 = 37,
GetHidReportEventInfoDeprecated2 = 38,
GetHidReportEventInfo = 38,
/* 5.0.0+ */
InitializeBle = 46,
FinalizeBle = 49,
GetBleManagedEventInfoDeprecated = 78,
GetBleManagedEventInfo = 79,
#define AMS_BTDRV_MITM_INTERFACE_INFO(C, H) \
AMS_SF_METHOD_INFO(C, H, 1, Result, InitializeBluetooth, (sf::OutCopyHandle out_handle)) \
AMS_SF_METHOD_INFO(C, H, 4, Result, FinalizeBluetooth, (void)) \
AMS_SF_METHOD_INFO(C, H, 15, Result, GetEventInfo, (sf::Out<bluetooth::EventType> out_type, const sf::OutPointerBuffer &out_buffer)) \
AMS_SF_METHOD_INFO(C, H, 16, Result, InitializeHid, (sf::OutCopyHandle out_handle, u16 version)) \
AMS_SF_METHOD_INFO(C, H, 19, Result, WriteHidData, (bluetooth::Address address, const sf::InPointerBuffer &buffer)) \
AMS_SF_METHOD_INFO(C, H, 25, Result, GetPairedDeviceInfo, (sf::Out<bluetooth::DeviceSettings> out, bluetooth::Address address)) \
AMS_SF_METHOD_INFO(C, H, 26, Result, FinalizeHid, (void)) \
AMS_SF_METHOD_INFO(C, H, 27, Result, GetHidEventInfo, (sf::Out<bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer)) \
AMS_SF_METHOD_INFO(C, H, 36, Result, RegisterHidReportEventDeprecated, (sf::OutCopyHandle out_handle), hos::Version_1_0_0, hos::Version_3_0_2) \
AMS_SF_METHOD_INFO(C, H, 37, Result, RegisterHidReportEvent, (sf::OutCopyHandle out_handle), hos::Version_4_0_0) \
AMS_SF_METHOD_INFO(C, H, 37, Result, GetHidReportEventInfoDeprecated1, (sf::Out<bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer), hos::Version_1_0_0, hos::Version_3_0_2) \
AMS_SF_METHOD_INFO(C, H, 38, Result, GetHidReportEventInfoDeprecated2, (sf::Out<bluetooth::HidEventType> out_type, const sf::OutPointerBuffer &out_buffer), hos::Version_4_0_0, hos::Version_6_2_0) \
AMS_SF_METHOD_INFO(C, H, 38, Result, GetHidReportEventInfo, (sf::OutCopyHandle out_handle), hos::Version_7_0_0) \
AMS_SF_METHOD_INFO(C, H, 46, Result, InitializeBle, (sf::OutCopyHandle out_handle), hos::Version_5_0_0) \
AMS_SF_METHOD_INFO(C, H, 49, Result, FinalizeBle, (void), hos::Version_5_0_0) \
AMS_SF_METHOD_INFO(C, H, 78, Result, GetBleManagedEventInfoDeprecated, (sf::Out<bluetooth::BleEventType> out_type, const sf::OutPointerBuffer &out_buffer), hos::Version_5_0_0, hos::Version_5_0_2) \
AMS_SF_METHOD_INFO(C, H, 79, Result, GetBleManagedEventInfo, (sf::Out<bluetooth::BleEventType> out_type, const sf::OutPointerBuffer &out_buffer), hos::Version_5_1_0) \
AMS_SF_METHOD_INFO(C, H, 65000, void, RedirectCoreEvents, (bool redirect)) \
AMS_SF_METHOD_INFO(C, H, 65001, void, RedirectHidEvents, (bool redirect)) \
AMS_SF_METHOD_INFO(C, H, 65002, void, RedirectHidReportEvents, (bool redirect)) \
AMS_SF_METHOD_INFO(C, H, 65003, void, RedirectBleEvents, (bool redirect)) \
/* Extensions */
RedirectCoreEvents = 65000,
RedirectHidEvents = 65001,
RedirectHidReportEvents = 65002,
RedirectBleEvents = 65003,
};
AMS_SF_DEFINE_MITM_INTERFACE(IBtdrvMitmInterface, AMS_BTDRV_MITM_INTERFACE_INFO)
}
class BtdrvMitmService : public sf::MitmServiceImplBase {
public:
using MitmServiceImplBase::MitmServiceImplBase;
public:
static bool ShouldMitm(const sm::MitmProcessInfo &client_info) {
@ -42,12 +46,6 @@ namespace ams::mitm::btdrv {
}
public:
SF_MITM_SERVICE_OBJECT_CTOR(BtdrvMitmService) {
u32 ver = hosversionGet();
BTDRV_LOG_FMT("*** btdrv-mitm [%d.%d.%d] ***", HOSVER_MAJOR(ver), HOSVER_MINOR(ver), HOSVER_MICRO(ver));
}
protected:
Result InitializeBluetooth(sf::OutCopyHandle out_handle);
Result FinalizeBluetooth(void);
Result GetEventInfo(sf::Out<bluetooth::EventType> out_type, const sf::OutPointerBuffer &out_buffer);
@ -73,32 +71,7 @@ namespace ams::mitm::btdrv {
void RedirectHidReportEvents(bool redirect);
void RedirectBleEvents(bool redirect);
public:
DEFINE_SERVICE_DISPATCH_TABLE {
MAKE_SERVICE_COMMAND_META(InitializeBluetooth),
MAKE_SERVICE_COMMAND_META(FinalizeBluetooth),
MAKE_SERVICE_COMMAND_META(GetEventInfo),
MAKE_SERVICE_COMMAND_META(InitializeHid),
MAKE_SERVICE_COMMAND_META(WriteHidData),
MAKE_SERVICE_COMMAND_META(GetPairedDeviceInfo),
MAKE_SERVICE_COMMAND_META(FinalizeHid),
MAKE_SERVICE_COMMAND_META(GetHidEventInfo),
MAKE_SERVICE_COMMAND_META(RegisterHidReportEventDeprecated, hos::Version_1_0_0, hos::Version_3_0_2),
MAKE_SERVICE_COMMAND_META(RegisterHidReportEvent, hos::Version_4_0_0),
MAKE_SERVICE_COMMAND_META(GetHidReportEventInfoDeprecated1, hos::Version_1_0_0, hos::Version_3_0_2),
MAKE_SERVICE_COMMAND_META(GetHidReportEventInfoDeprecated2, hos::Version_4_0_0, hos::Version_6_2_0),
MAKE_SERVICE_COMMAND_META(GetHidReportEventInfo, hos::Version_7_0_0),
MAKE_SERVICE_COMMAND_META(InitializeBle, hos::Version_5_0_0),
MAKE_SERVICE_COMMAND_META(FinalizeBle, hos::Version_5_0_0),
MAKE_SERVICE_COMMAND_META(GetBleManagedEventInfoDeprecated, hos::Version_5_0_0, hos::Version_5_0_2),
MAKE_SERVICE_COMMAND_META(GetBleManagedEventInfo, hos::Version_5_1_0),
MAKE_SERVICE_COMMAND_META(RedirectCoreEvents),
MAKE_SERVICE_COMMAND_META(RedirectHidEvents),
MAKE_SERVICE_COMMAND_META(RedirectHidReportEvents),
MAKE_SERVICE_COMMAND_META(RedirectBleEvents),
};
};
static_assert(IsIBtdrvMitmInterface<BtdrvMitmService>);
}

View file

@ -99,7 +99,7 @@ int main(int argc, char **argv) {
auto server_manager = std::make_unique<sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions>>();
R_ABORT_UNLESS(server_manager->RegisterMitmServer<ams::mitm::btdrv::BtdrvMitmService>(BtdrvMitmServiceName));
R_ABORT_UNLESS((server_manager->RegisterMitmServer<ams::mitm::btdrv::IBtdrvMitmInterface, ams::mitm::btdrv::BtdrvMitmService>(BtdrvMitmServiceName)));
R_ABORT_UNLESS(bluetooth::events::Initialize());