diff --git a/libraries/libstratosphere/include/stratosphere.hpp b/libraries/libstratosphere/include/stratosphere.hpp index a05c6edad..d032cab3c 100644 --- a/libraries/libstratosphere/include/stratosphere.hpp +++ b/libraries/libstratosphere/include/stratosphere.hpp @@ -82,6 +82,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libstratosphere/include/stratosphere/htc.hpp b/libraries/libstratosphere/include/stratosphere/htc.hpp index 999d1a35e..571efc768 100644 --- a/libraries/libstratosphere/include/stratosphere/htc.hpp +++ b/libraries/libstratosphere/include/stratosphere/htc.hpp @@ -15,3 +15,4 @@ */ #pragma once +#include diff --git a/libraries/libstratosphere/include/stratosphere/htc/server/htc_htcmisc_hipc_server.hpp b/libraries/libstratosphere/include/stratosphere/htc/server/htc_htcmisc_hipc_server.hpp new file mode 100644 index 000000000..42f3e3e5d --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/htc/server/htc_htcmisc_hipc_server.hpp @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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::htclow { + + class HtclowManager; + +} + +namespace ams::htc::server { + + void InitializeHtcmiscServer(htclow::HtclowManager *htclow_manager); + void FinalizeHtcmiscServer(); + void LoopHtcmiscServer(); + void RequestStopHtcmiscServer(); + + class HtcmiscImpl; + HtcmiscImpl *GetHtcmiscImpl(); + +} diff --git a/libraries/libstratosphere/include/stratosphere/tma.hpp b/libraries/libstratosphere/include/stratosphere/tma.hpp new file mode 100644 index 000000000..fbb181ebe --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/tma.hpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 diff --git a/libraries/libstratosphere/include/stratosphere/tma/tma_i_htc_manager.hpp b/libraries/libstratosphere/include/stratosphere/tma/tma_i_htc_manager.hpp new file mode 100644 index 000000000..f9175ab9f --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/tma/tma_i_htc_manager.hpp @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 + +/* NOTE: Minimum firmware version not enforced for any commands. */ +#define AMS_TMA_I_HTC_MANAGER_INTERFACE_INFO(C, H) \ + AMS_SF_METHOD_INFO(C, H, 0, Result, GetEnvironmentVariable, (sf::Out out_size, const sf::OutBuffer &out, const sf::InBuffer &name), (out_size, out, name)) \ + AMS_SF_METHOD_INFO(C, H, 1, Result, GetEnvironmentVariableLength, (sf::Out out_size, const sf::InBuffer &name), (out_size, name)) \ + AMS_SF_METHOD_INFO(C, H, 2, Result, GetHostConnectionEvent, (sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 3, Result, GetHostDisconnectionEvent, (sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 4, Result, GetHostConnectionEventForSystem, (sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 5, Result, GetHostDisconnectionEventForSystem, (sf::OutCopyHandle out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 6, Result, GetBridgeIpAddress, (const sf::OutBuffer &out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 7, Result, GetBridgePort, (const sf::OutBuffer &out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 8, Result, SetCradleAttached, (bool attached), (attached)) \ + AMS_SF_METHOD_INFO(C, H, 9, Result, GetBridgeSubnetMask, (const sf::OutBuffer &out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 10, Result, GetBridgeMacAddress, (const sf::OutBuffer &out), (out)) \ + AMS_SF_METHOD_INFO(C, H, 11, Result, GetWorkingDirectoryPath, (const sf::OutBuffer &out, s32 max_len), (out, max_len)) \ + AMS_SF_METHOD_INFO(C, H, 12, Result, GetWorkingDirectoryPathSize, (sf::Out out_size), (out_size)) \ + AMS_SF_METHOD_INFO(C, H, 13, Result, RunOnHostStart, (sf::Out out_id, sf::OutCopyHandle out, const sf::InBuffer &args), (out_id, out, args)) \ + AMS_SF_METHOD_INFO(C, H, 14, Result, RunOnHostResults, (sf::Out out_result, u32 id), (out_result, id)) \ + AMS_SF_METHOD_INFO(C, H, 15, Result, SetBridgeIpAddress, (const sf::InBuffer &arg), (arg)) \ + AMS_SF_METHOD_INFO(C, H, 16, Result, SetBridgeSubnetMask, (const sf::InBuffer &arg), (arg)) \ + AMS_SF_METHOD_INFO(C, H, 17, Result, SetBridgePort, (const sf::InBuffer &arg), (arg)) + +AMS_SF_DEFINE_INTERFACE(ams::tma, IHtcManager, AMS_TMA_I_HTC_MANAGER_INTERFACE_INFO) diff --git a/libraries/libstratosphere/source/htc/server/htc_htc_service_object.cpp b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.cpp new file mode 100644 index 000000000..b3f2a9525 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 +#include "htc_htc_service_object.hpp" + +namespace ams::htc::server { + + HtcServiceObject::HtcServiceObject(htclow::HtclowManager *htclow_manager) { + AMS_ABORT("HtcServiceObject::HtcServiceObject"); + } + + + HtcmiscImpl *HtcServiceObject::GetHtcmiscImpl() { + AMS_ABORT("HtcServiceObject::GetHtcmiscImpl"); + } + + Result HtcServiceObject::GetEnvironmentVariable(sf::Out out_size, const sf::OutBuffer &out, const sf::InBuffer &name) { + AMS_ABORT("HtcServiceObject::GetEnvironmentVariable"); + } + + Result HtcServiceObject::GetEnvironmentVariableLength(sf::Out out_size, const sf::InBuffer &name) { + AMS_ABORT("HtcServiceObject::GetEnvironmentVariableLength"); + } + + Result HtcServiceObject::GetHostConnectionEvent(sf::OutCopyHandle out) { + AMS_ABORT("HtcServiceObject::GetHostConnectionEvent"); + } + + Result HtcServiceObject::GetHostDisconnectionEvent(sf::OutCopyHandle out) { + AMS_ABORT("HtcServiceObject::GetHostDisconnectionEvent"); + } + + Result HtcServiceObject::GetHostConnectionEventForSystem(sf::OutCopyHandle out) { + AMS_ABORT("HtcServiceObject::GetHostConnectionEventForSystem"); + } + + Result HtcServiceObject::GetHostDisconnectionEventForSystem(sf::OutCopyHandle out) { + AMS_ABORT("HtcServiceObject::GetHostDisconnectionEventForSystem"); + } + + Result HtcServiceObject::GetBridgeIpAddress(const sf::OutBuffer &out) { + AMS_ABORT("HtcServiceObject::GetBridgeIpAddress"); + } + + Result HtcServiceObject::GetBridgePort(const sf::OutBuffer &out) { + AMS_ABORT("HtcServiceObject::GetBridgePort"); + } + + Result HtcServiceObject::SetCradleAttached(bool attached) { + AMS_ABORT("HtcServiceObject::SetCradleAttached"); + } + + Result HtcServiceObject::GetBridgeSubnetMask(const sf::OutBuffer &out) { + AMS_ABORT("HtcServiceObject::GetBridgeSubnetMask"); + } + + Result HtcServiceObject::GetBridgeMacAddress(const sf::OutBuffer &out) { + AMS_ABORT("HtcServiceObject::GetBridgeMacAddress"); + } + + Result HtcServiceObject::GetWorkingDirectoryPath(const sf::OutBuffer &out, s32 max_len) { + AMS_ABORT("HtcServiceObject::GetWorkingDirectoryPath"); + } + + Result HtcServiceObject::GetWorkingDirectoryPathSize(sf::Out out_size) { + AMS_ABORT("HtcServiceObject::GetWorkingDirectoryPathSize"); + } + + Result HtcServiceObject::RunOnHostStart(sf::Out out_id, sf::OutCopyHandle out, const sf::InBuffer &args) { + AMS_ABORT("HtcServiceObject::RunOnHostStart"); + } + + Result HtcServiceObject::RunOnHostResults(sf::Out out_result, u32 id) { + AMS_ABORT("HtcServiceObject::RunOnHostResults"); + } + + Result HtcServiceObject::SetBridgeIpAddress(const sf::InBuffer &arg) { + AMS_ABORT("HtcServiceObject::SetBridgeIpAddress"); + } + + Result HtcServiceObject::SetBridgeSubnetMask(const sf::InBuffer &arg) { + AMS_ABORT("HtcServiceObject::SetBridgeSubnetMask"); + } + + Result HtcServiceObject::SetBridgePort(const sf::InBuffer &arg) { + AMS_ABORT("HtcServiceObject::SetBridgePort"); + } + +} diff --git a/libraries/libstratosphere/source/htc/server/htc_htc_service_object.hpp b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.hpp new file mode 100644 index 000000000..0ff25a582 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.hpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 "../../htclow/htclow_manager.hpp" + +namespace ams::htc::server { + + class HtcServiceObject { + private: + /* TODO */ + public: + HtcServiceObject(htclow::HtclowManager *htclow_manager); + public: + HtcmiscImpl *GetHtcmiscImpl(); + public: + Result GetEnvironmentVariable(sf::Out out_size, const sf::OutBuffer &out, const sf::InBuffer &name); + Result GetEnvironmentVariableLength(sf::Out out_size, const sf::InBuffer &name); + Result GetHostConnectionEvent(sf::OutCopyHandle out); + Result GetHostDisconnectionEvent(sf::OutCopyHandle out); + Result GetHostConnectionEventForSystem(sf::OutCopyHandle out); + Result GetHostDisconnectionEventForSystem(sf::OutCopyHandle out); + Result GetBridgeIpAddress(const sf::OutBuffer &out); + Result GetBridgePort(const sf::OutBuffer &out); + Result SetCradleAttached(bool attached); + Result GetBridgeSubnetMask(const sf::OutBuffer &out); + Result GetBridgeMacAddress(const sf::OutBuffer &out); + Result GetWorkingDirectoryPath(const sf::OutBuffer &out, s32 max_len); + Result GetWorkingDirectoryPathSize(sf::Out out_size); + Result RunOnHostStart(sf::Out out_id, sf::OutCopyHandle out, const sf::InBuffer &args); + Result RunOnHostResults(sf::Out out_result, u32 id); + Result SetBridgeIpAddress(const sf::InBuffer &arg); + Result SetBridgeSubnetMask(const sf::InBuffer &arg); + Result SetBridgePort(const sf::InBuffer &arg); + + }; + static_assert(tma::IsIHtcManager); + +} diff --git a/libraries/libstratosphere/source/htc/server/htc_htcmisc_hipc_server.cpp b/libraries/libstratosphere/source/htc/server/htc_htcmisc_hipc_server.cpp new file mode 100644 index 000000000..f9ebb2b86 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/htc_htcmisc_hipc_server.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 +#include "htc_htc_service_object.hpp" +#include "htc_htcmisc_manager.hpp" + +namespace ams::htc::server { + + namespace { + + static constexpr inline size_t NumServers = 1; + static constexpr inline size_t MaxSessions = 30; + static constexpr inline sm::ServiceName ServiceName = sm::ServiceName::Encode("htc"); + + using ServerOptions = sf::hipc::DefaultServerManagerOptions; + using ServerManager = sf::hipc::ServerManager; + + constinit TYPED_STORAGE(ServerManager) g_server_manager_storage; + constinit ServerManager *g_server_manager = nullptr; + + constinit HtcmiscImpl *g_misc_impl = nullptr; + + } + + void InitializeHtcmiscServer(htclow::HtclowManager *htclow_manager) { + /* Check that we haven't already initialized. */ + AMS_ASSERT(g_server_manager == nullptr); + + /* Create the server manager. */ + std::construct_at(GetPointer(g_server_manager_storage)); + + /* Set the server manager pointer. */ + g_server_manager = GetPointer(g_server_manager_storage); + + /* Create and register the htc manager object. */ + HtcServiceObject *service_object; + R_ABORT_UNLESS(g_server_manager->RegisterObjectForServer(CreateHtcmiscManager(std::addressof(service_object), htclow_manager), ServiceName, MaxSessions)); + + /* Set the misc impl. */ + g_misc_impl = service_object->GetHtcmiscImpl(); + + /* Start the server. */ + g_server_manager->ResumeProcessing(); + } + + void FinalizeHtcmiscServer() { + /* Check that we've already initialized. */ + AMS_ASSERT(g_server_manager != nullptr); + + /* Clear the misc impl. */ + g_misc_impl = nullptr; + + /* Clear and destroy. */ + std::destroy_at(g_server_manager); + g_server_manager = nullptr; + } + + void LoopHtcmiscServer() { + /* Check that we've already initialized. */ + AMS_ASSERT(g_server_manager != nullptr); + + g_server_manager->LoopProcess(); + } + + void RequestStopHtcmiscServer() { + /* Check that we've already initialized. */ + AMS_ASSERT(g_server_manager != nullptr); + + g_server_manager->RequestStopProcessing(); + } + + HtcmiscImpl *GetHtcmiscImpl() { + return g_misc_impl; + } + +} diff --git a/libraries/libstratosphere/source/htc/server/htc_htcmisc_manager.cpp b/libraries/libstratosphere/source/htc/server/htc_htcmisc_manager.cpp new file mode 100644 index 000000000..304451bea --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/htc_htcmisc_manager.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 +#include "htc_htcmisc_manager.hpp" + +namespace ams::htc::server { + + namespace { + + + mem::StandardAllocator g_allocator; + sf::StandardAllocatorMemoryResource g_sf_resource(std::addressof(g_allocator)); + + alignas(os::MemoryPageSize) constinit u8 g_heap[util::AlignUp(sizeof(HtcServiceObject), os::MemoryPageSize) + 12_KB]; + + class StaticAllocatorInitializer { + public: + StaticAllocatorInitializer() { + g_allocator.Initialize(g_heap, sizeof(g_heap)); + } + } g_static_allocator_initializer; + + using ObjectFactory = sf::ObjectFactory; + + } + + sf::SharedPointer CreateHtcmiscManager(HtcServiceObject **out, htclow::HtclowManager *htclow_manager) { + auto obj = ObjectFactory::CreateSharedEmplaced(std::addressof(g_sf_resource), htclow_manager); + *out = std::addressof(obj.GetImpl()); + return obj; + } + +} diff --git a/libraries/libstratosphere/source/htc/server/htc_htcmisc_manager.hpp b/libraries/libstratosphere/source/htc/server/htc_htcmisc_manager.hpp new file mode 100644 index 000000000..8d36f90a4 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/htc_htcmisc_manager.hpp @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2018-2020 Atmosphère-NX + * + * 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 "htc_htc_service_object.hpp" + +namespace ams::htc::server { + + sf::SharedPointer CreateHtcmiscManager(HtcServiceObject **out, htclow::HtclowManager *htclow_manager); + +} diff --git a/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp b/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp index 865c82dcc..34e530bd6 100644 --- a/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp +++ b/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp @@ -52,8 +52,12 @@ namespace ams::htclow { return ResultSuccess(); } - //void HtclowManagerImpl::CloseDriver(); - // - //void HtclowManagerImpl::Disconnect(); + void HtclowManagerImpl::CloseDriver() { + AMS_ABORT("HtclowManagerImpl::CloseDriver"); + } + + void HtclowManagerImpl::Disconnect() { + AMS_ABORT("HtclowManagerImpl::Disconnect"); + } } diff --git a/stratosphere/htc/source/htc_main.cpp b/stratosphere/htc/source/htc_main.cpp index 17e0a5c03..e83193b81 100644 --- a/stratosphere/htc/source/htc_main.cpp +++ b/stratosphere/htc/source/htc_main.cpp @@ -185,7 +185,7 @@ namespace ams::htc { } void HtcIpcThreadFunction(void *arg) { - //htc::server::LoopHtcmiscServer(); + htc::server::LoopHtcmiscServer(); } void HtcfsIpcThreadFunction(void *arg) { @@ -218,7 +218,7 @@ int main(int argc, char **argv) auto *htclow_manager = htclow::HtclowManagerHolder::GetHtclowManager(); /* Initialize the htc misc server. */ - //htc::server::InitializeHtcmiscServer(htclow_manager); + htc::server::InitializeHtcmiscServer(htclow_manager); /* Create the htc misc ipc thread. */ os::ThreadType htc_ipc_thread;