diff --git a/Makefile b/Makefile
index b4ec0f2..139486a 100644
--- a/Makefile
+++ b/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
diff --git a/mc_mitm/source/mc/mc_module.cpp b/mc_mitm/source/mc/mc_module.cpp
new file mode 100644
index 0000000..6d00903
--- /dev/null
+++ b/mc_mitm/source/mc/mc_module.cpp
@@ -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 .
+ */
+#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 {
+ private:
+ virtual Result OnNeedsToAccept(int port_index, Server *server) override;
+ };
+
+ ServerManager g_server_manager;
+
+ sf::UnmanagedServiceObject 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);
+ }
+
+}
diff --git a/mc_mitm/source/mc/mc_module.hpp b/mc_mitm/source/mc/mc_module.hpp
new file mode 100644
index 0000000..3ee22f4
--- /dev/null
+++ b/mc_mitm/source/mc/mc_module.hpp
@@ -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 .
+ */
+#pragma once
+#include
+
+namespace ams::mitm::mc {
+
+ Result Launch(void);
+ void WaitFinished(void);
+
+}
diff --git a/mc_mitm/source/mc/mc_service.cpp b/mc_mitm/source/mc/mc_service.cpp
new file mode 100644
index 0000000..6f18144
--- /dev/null
+++ b/mc_mitm/source/mc/mc_service.cpp
@@ -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 .
+ */
+#include "mc_service.hpp"
+#include "../mcmitm_version.hpp"
+#include
+
+namespace ams::mitm::mc {
+
+ Result MissionControlService::GetVersion(sf::Out version) {
+ version.SetValue(mc_version);
+ return ams::ResultSuccess();
+ }
+
+ Result MissionControlService::GetBuildVersionString(sf::Out version) {
+ std::strncpy(version.GetPointer()->version, mc_build_name, sizeof(mc::VersionString));
+ return ams::ResultSuccess();
+ }
+
+ Result MissionControlService::GetBuildDateString(sf::Out date) {
+ std::strncpy(date.GetPointer()->date, mc_build_date, sizeof(mc::DateString));
+ return ams::ResultSuccess();
+ }
+
+}
diff --git a/mc_mitm/source/mc/mc_service.hpp b/mc_mitm/source/mc/mc_service.hpp
new file mode 100644
index 0000000..fbcc5ce
--- /dev/null
+++ b/mc_mitm/source/mc/mc_service.hpp
@@ -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 .
+ */
+#pragma once
+#include
+#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 version), (version)) \
+ AMS_SF_METHOD_INFO(C, H, 1, Result, GetBuildVersionString, (sf::Out version), (version)) \
+ AMS_SF_METHOD_INFO(C, H, 2, Result, GetBuildDateString, (sf::Out 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 version);
+ Result GetBuildVersionString(sf::Out version);
+ Result GetBuildDateString(sf::Out date);
+ };
+ static_assert(IsIMissionControlInterface);
+
+}
diff --git a/mc_mitm/source/mc/mc_types.hpp b/mc_mitm/source/mc/mc_types.hpp
new file mode 100644
index 0000000..a0e5396
--- /dev/null
+++ b/mc_mitm/source/mc/mc_types.hpp
@@ -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 .
+ */
+#pragma once
+
+namespace ams::mitm::mc {
+
+ struct VersionString {
+ char version[32];
+ };
+
+ struct DateString {
+ char date[32];
+ };
+
+}
diff --git a/mc_mitm/source/mcmitm_initialization.cpp b/mc_mitm/source/mcmitm_initialization.cpp
index af7b9ae..f9dedfc 100644
--- a/mc_mitm/source/mcmitm_initialization.cpp
+++ b/mc_mitm/source/mcmitm_initialization.cpp
@@ -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();
}
diff --git a/mc_mitm/source/mcmitm_version.hpp b/mc_mitm/source/mcmitm_version.hpp
index 2f69a8f..43ee3e6 100644
--- a/mc_mitm/source/mcmitm_version.hpp
+++ b/mc_mitm/source/mcmitm_version.hpp
@@ -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;
}