mirror of
https://github.com/ndeadly/MissionControl
synced 2024-11-22 04:13:07 +00:00
Implement mc service
(cherry picked from commit 5c67198728e6f946512d0b637f39d31f63bdc28a)
This commit is contained in:
parent
5a27ad85c1
commit
44e85a60e0
8 changed files with 223 additions and 3 deletions
6
Makefile
6
Makefile
|
@ -4,6 +4,8 @@ MC_MITM_TID := 010000000000bd00
|
|||
GIT_BRANCH := $(shell git symbolic-ref --short HEAD | sed s/[^a-zA-Z0-9_-]/_/g)
|
||||
GIT_HASH := $(shell git rev-parse --short HEAD)
|
||||
GIT_TAG := $(shell git describe --tags `git rev-list --tags --max-count=1`)
|
||||
|
||||
VERSION := $(shell [[ $(GIT_TAG) =~ ^v([0-9]+).([0-9]+).([0-9]+) ]] && printf '0x%02X%02X%02X' $${BASH_REMATCH[1]} $${BASH_REMATCH[2]} $${BASH_REMATCH[3]})
|
||||
BUILD_VERSION := $(GIT_TAG:v%=%)-$(GIT_BRANCH)-$(GIT_HASH)
|
||||
|
||||
TARGETS := mcmitm_version.cpp mc_mitm
|
||||
|
@ -11,7 +13,7 @@ TARGETS := mcmitm_version.cpp mc_mitm
|
|||
all: $(TARGETS)
|
||||
|
||||
mcmitm_version.cpp: .git/HEAD .git/index
|
||||
echo "namespace ams::mitm { const char *version_string = \"$(BUILD_VERSION)\"; const char *build_date = \"$$(date)\"; }" > mc_mitm/source/$@
|
||||
echo "namespace ams::mitm { unsigned int mc_version = $(VERSION); const char *mc_build_name = \"$(BUILD_VERSION)\"; const char *mc_build_date = \"$$(date)\"; }" > mc_mitm/source/$@
|
||||
|
||||
mc_mitm:
|
||||
$(MAKE) -C $@
|
||||
|
@ -24,6 +26,8 @@ clean:
|
|||
dist: all
|
||||
rm -rf dist
|
||||
|
||||
|
||||
|
||||
mkdir -p dist/atmosphere/contents/$(MC_MITM_TID)
|
||||
cp mc_mitm/out/nintendo_nx_arm64_armv8a/release/mc_mitm.nsp dist/atmosphere/contents/$(MC_MITM_TID)/exefs.nsp
|
||||
echo "btdrv" >> dist/atmosphere/contents/$(MC_MITM_TID)/mitm.lst
|
||||
|
|
83
mc_mitm/source/mc/mc_module.cpp
Normal file
83
mc_mitm/source/mc/mc_module.cpp
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 ndeadly
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 "mc_module.hpp"
|
||||
#include "mc_service.hpp"
|
||||
#include "../utils.hpp"
|
||||
|
||||
namespace ams::mitm::mc {
|
||||
|
||||
namespace {
|
||||
|
||||
enum PortIndex {
|
||||
PortIndex_MissionControl,
|
||||
PortIndex_Count,
|
||||
};
|
||||
|
||||
constexpr sm::ServiceName MissionControlServiceName = sm::ServiceName::Encode("mc");
|
||||
|
||||
using ServerOptions = sf::hipc::DefaultServerManagerOptions;
|
||||
|
||||
constexpr size_t MaxSessions = 4;
|
||||
|
||||
class ServerManager final : public sf::hipc::ServerManager<PortIndex_Count, ServerOptions, MaxSessions> {
|
||||
private:
|
||||
virtual Result OnNeedsToAccept(int port_index, Server *server) override;
|
||||
};
|
||||
|
||||
ServerManager g_server_manager;
|
||||
|
||||
sf::UnmanagedServiceObject<IMissionControlInterface, MissionControlService> g_mission_control_service;
|
||||
|
||||
ams::Result ServerManager::OnNeedsToAccept(int port_index, Server *server) {
|
||||
switch (port_index) {
|
||||
case PortIndex_MissionControl:
|
||||
return this->AcceptImpl(server, g_mission_control_service.GetShared());
|
||||
AMS_UNREACHABLE_DEFAULT_CASE();
|
||||
}
|
||||
}
|
||||
|
||||
const s32 ThreadPriority = 20;
|
||||
const size_t ThreadStackSize = 0x1000;
|
||||
alignas(os::ThreadStackAlignment) u8 g_thread_stack[ThreadStackSize];
|
||||
os::ThreadType g_thread;
|
||||
|
||||
void MissionControlThreadFunction(void *) {
|
||||
R_ABORT_UNLESS(g_server_manager.RegisterServer(PortIndex_MissionControl, MissionControlServiceName, MaxSessions));
|
||||
g_server_manager.LoopProcess();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Result Launch(void) {
|
||||
R_TRY(os::CreateThread(&g_thread,
|
||||
MissionControlThreadFunction,
|
||||
nullptr,
|
||||
g_thread_stack,
|
||||
ThreadStackSize,
|
||||
ThreadPriority
|
||||
));
|
||||
|
||||
os::SetThreadNamePointer(&g_thread, "mc::MissionControlThread");
|
||||
os::StartThread(&g_thread);
|
||||
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
||||
void WaitFinished(void) {
|
||||
os::WaitThread(&g_thread);
|
||||
}
|
||||
|
||||
}
|
24
mc_mitm/source/mc/mc_module.hpp
Normal file
24
mc_mitm/source/mc/mc_module.hpp
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 ndeadly
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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::mc {
|
||||
|
||||
Result Launch(void);
|
||||
void WaitFinished(void);
|
||||
|
||||
}
|
37
mc_mitm/source/mc/mc_service.cpp
Normal file
37
mc_mitm/source/mc/mc_service.cpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 ndeadly
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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 "mc_service.hpp"
|
||||
#include "../mcmitm_version.hpp"
|
||||
#include <cstring>
|
||||
|
||||
namespace ams::mitm::mc {
|
||||
|
||||
Result MissionControlService::GetVersion(sf::Out<u32> version) {
|
||||
version.SetValue(mc_version);
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
||||
Result MissionControlService::GetBuildVersionString(sf::Out<mc::VersionString> version) {
|
||||
std::strncpy(version.GetPointer()->version, mc_build_name, sizeof(mc::VersionString));
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
||||
Result MissionControlService::GetBuildDateString(sf::Out<ams::mitm::mc::DateString> date) {
|
||||
std::strncpy(date.GetPointer()->date, mc_build_date, sizeof(mc::DateString));
|
||||
return ams::ResultSuccess();
|
||||
}
|
||||
|
||||
}
|
40
mc_mitm/source/mc/mc_service.hpp
Normal file
40
mc_mitm/source/mc/mc_service.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021 ndeadly
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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>
|
||||
#include "mc_types.hpp"
|
||||
#include "../bluetooth_mitm/bluetooth/bluetooth_types.hpp"
|
||||
|
||||
#define AMS_MISSION_CONTROL_INTERFACE_INFO(C, H) \
|
||||
AMS_SF_METHOD_INFO(C, H, 0, Result, GetVersion, (sf::Out<u32> version), (version)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 1, Result, GetBuildVersionString, (sf::Out<ams::mitm::mc::VersionString> version), (version)) \
|
||||
AMS_SF_METHOD_INFO(C, H, 2, Result, GetBuildDateString, (sf::Out<ams::mitm::mc::DateString> version), (version)) \
|
||||
|
||||
AMS_SF_DEFINE_INTERFACE(ams::mitm::mc, IMissionControlInterface, AMS_MISSION_CONTROL_INTERFACE_INFO, 0x30eba3d4)
|
||||
|
||||
namespace ams::mitm::mc {
|
||||
|
||||
class MissionControlService {
|
||||
private:
|
||||
|
||||
public:
|
||||
Result GetVersion(sf::Out<u32> version);
|
||||
Result GetBuildVersionString(sf::Out<ams::mitm::mc::VersionString> version);
|
||||
Result GetBuildDateString(sf::Out<ams::mitm::mc::DateString> date);
|
||||
};
|
||||
static_assert(IsIMissionControlInterface<MissionControlService>);
|
||||
|
||||
}
|
28
mc_mitm/source/mc/mc_types.hpp
Normal file
28
mc_mitm/source/mc/mc_types.hpp
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2022 ndeadly
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms and conditions of the GNU General Public License,
|
||||
* version 2, as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope 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::mc {
|
||||
|
||||
struct VersionString {
|
||||
char version[32];
|
||||
};
|
||||
|
||||
struct DateString {
|
||||
char date[32];
|
||||
};
|
||||
|
||||
}
|
|
@ -21,6 +21,7 @@
|
|||
#include "bluetooth_mitm/btdrv_mitm_service.hpp"
|
||||
#include "bluetooth_mitm/bluetoothmitm_module.hpp"
|
||||
#include "btm_mitm/btmmitm_module.hpp"
|
||||
#include "mc/mc_module.hpp"
|
||||
#include "bluetooth_mitm/bluetooth/bluetooth_events.hpp"
|
||||
#include "bluetooth_mitm/bluetooth/bluetooth_core.hpp"
|
||||
#include "bluetooth_mitm/bluetooth/bluetooth_hid.hpp"
|
||||
|
@ -111,9 +112,11 @@ namespace ams::mitm {
|
|||
void LaunchModules(void) {
|
||||
R_ABORT_UNLESS(ams::mitm::bluetooth::Launch());
|
||||
R_ABORT_UNLESS(ams::mitm::btm::Launch());
|
||||
R_ABORT_UNLESS(ams::mitm::mc::Launch());
|
||||
}
|
||||
|
||||
void WaitModules(void) {
|
||||
ams::mitm::mc::WaitFinished();
|
||||
ams::mitm::btm::WaitFinished();
|
||||
ams::mitm::bluetooth::WaitFinished();
|
||||
}
|
||||
|
|
|
@ -17,7 +17,8 @@
|
|||
|
||||
namespace ams::mitm {
|
||||
|
||||
extern const char *version_string;
|
||||
extern const char *build_date;
|
||||
extern const unsigned int mc_version;
|
||||
extern const char *mc_build_name;
|
||||
extern const char *mc_build_date;
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue