bluetooth-mitm: implement mitm modules for btdrv and btm

This commit is contained in:
ndeadly 2020-09-11 19:04:01 +02:00
parent a5486b07bb
commit e9866d1c12
5 changed files with 195 additions and 22 deletions

View file

@ -16,10 +16,8 @@
*/
#include <switch.h>
#include <stratosphere.hpp>
#include "btdrv_mitm/btdrv_mitm_service.hpp"
#include "btm_mitm/btm_mitm_service.hpp"
#include "btdrv_mitm/bluetooth/bluetooth_events.hpp"
#include <memory>
#include "btdrv_mitm/btdrvmitm_module.hpp"
#include "btm_mitm/btmmitm_module.hpp"
extern "C" {
@ -94,27 +92,19 @@ void __libnx_exception_handler(ThreadExceptionDump* ctx) {
ams::CrashHandler(ctx);
}
namespace {
void LaunchModules(void) {
ams::mitm::btdrv::Launch();
ams::mitm::btm::Launch();
}
constexpr sm::ServiceName BtdrvMitmServiceName = sm::ServiceName::Encode("btdrv");
struct ServerOptions {
static constexpr size_t PointerBufferSize = 0x1000;
static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
constexpr size_t MaxServers = 1;
constexpr size_t MaxSessions = 6;
void WaitModules(void) {
ams::mitm::btm::WaitFinished();
ams::mitm::btdrv::WaitFinished();
}
int main(int argc, char **argv) {
R_ABORT_UNLESS(bluetooth::events::Initialize());
auto server_manager = std::make_unique<sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions>>();
R_ABORT_UNLESS((server_manager->RegisterMitmServer<ams::mitm::btdrv::IBtdrvMitmInterface, ams::mitm::btdrv::BtdrvMitmService>(BtdrvMitmServiceName)));
server_manager->LoopProcess();
LaunchModules();
WaitModules();
return 0;
}

View file

@ -0,0 +1,68 @@
/*
* Copyright (C) 2020 ndeadly
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "btdrvmitm_module.hpp"
#include "btdrv_mitm_service.hpp"
#include "bluetooth/bluetooth_events.hpp"
#include <stratosphere.hpp>
#include <memory>
namespace ams::mitm::btdrv {
namespace {
constexpr sm::ServiceName MitmServiceName = sm::ServiceName::Encode("btdrv");
struct ServerOptions {
static constexpr size_t PointerBufferSize = 0x1000;
static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
constexpr size_t MaxServers = 1;
constexpr size_t MaxSessions = 6;
os::ThreadType g_btdrv_mitm_thread;
alignas(os::ThreadStackAlignment) u8 g_btdrv_mitm_thread_stack[0x4000];
constexpr s32 g_btdrv_mitm_thread_priority = 16;
}
void BtdrvMitmThreadFunction(void *arg) {
R_ABORT_UNLESS(bluetooth::events::Initialize());
auto server_manager = std::make_unique<sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions>>();
R_ABORT_UNLESS((server_manager->RegisterMitmServer<ams::mitm::btdrv::IBtdrvMitmInterface, ams::mitm::btdrv::BtdrvMitmService>(MitmServiceName)));
server_manager->LoopProcess();
}
void Launch(void) {
os::CreateThread(&g_btdrv_mitm_thread,
BtdrvMitmThreadFunction,
nullptr,
g_btdrv_mitm_thread_stack,
sizeof(g_btdrv_mitm_thread_stack),
g_btdrv_mitm_thread_priority
);
os::StartThread(&g_btdrv_mitm_thread);
}
void WaitFinished(void) {
os::WaitThread(&g_btdrv_mitm_thread);
}
}

View file

@ -0,0 +1,24 @@
/*
* Copyright (C) 2020 ndeadly
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
namespace ams::mitm::btdrv {
void Launch(void);
void WaitFinished(void);
}

View file

@ -0,0 +1,66 @@
/*
* Copyright (C) 2020 ndeadly
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "btmmitm_module.hpp"
#include "btm_mitm_service.hpp"
#include <stratosphere.hpp>
#include <memory>
namespace ams::mitm::btm {
namespace {
constexpr sm::ServiceName MitmServiceName = sm::ServiceName::Encode("btm");
struct ServerOptions {
static constexpr size_t PointerBufferSize = 0x1000;
static constexpr size_t MaxDomains = 0;
static constexpr size_t MaxDomainObjects = 0;
};
constexpr size_t MaxServers = 1;
constexpr size_t MaxSessions = 8;
os::ThreadType g_btm_mitm_thread;
alignas(os::ThreadStackAlignment) u8 g_btm_mitm_thread_stack[0x4000];
constexpr s32 g_btm_mitm_thread_priority = 36;
}
void BtmMitmThreadFunction(void *arg) {
auto server_manager = std::make_unique<sf::hipc::ServerManager<MaxServers, ServerOptions, MaxSessions>>();
R_ABORT_UNLESS((server_manager->RegisterMitmServer<ams::mitm::btm::IBtmMitmInterface, ams::mitm::btm::BtmMitmService>(MitmServiceName)));
server_manager->LoopProcess();
}
void Launch(void) {
os::CreateThread(&g_btm_mitm_thread,
BtmMitmThreadFunction,
nullptr,
g_btm_mitm_thread_stack,
sizeof(g_btm_mitm_thread_stack),
g_btm_mitm_thread_priority
);
os::StartThread(&g_btm_mitm_thread);
}
void WaitFinished(void) {
os::WaitThread(&g_btm_mitm_thread);
}
}

View file

@ -0,0 +1,25 @@
/*
* Copyright (C) 2020 ndeadly
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <stratosphere.hpp>
namespace ams::mitm::btm {
void Launch(void);
void WaitFinished(void);
}