diff --git a/libraries/libstratosphere/include/stratosphere/htc.hpp b/libraries/libstratosphere/include/stratosphere/htc.hpp index 571efc768..748ba3f6b 100644 --- a/libraries/libstratosphere/include/stratosphere/htc.hpp +++ b/libraries/libstratosphere/include/stratosphere/htc.hpp @@ -16,3 +16,4 @@ #pragma once #include +#include diff --git a/libraries/libstratosphere/include/stratosphere/htc/server/htc_htcmisc_channel_ids.hpp b/libraries/libstratosphere/include/stratosphere/htc/server/htc_htcmisc_channel_ids.hpp new file mode 100644 index 000000000..bba165b7e --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/htc/server/htc_htcmisc_channel_ids.hpp @@ -0,0 +1,25 @@ +/* + * 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 + +namespace ams::htc::server { + + constexpr inline htclow::ChannelId HtcmiscClientChannelId = 1; + constexpr inline htclow::ChannelId HtcmiscServerChannelId = 2; + +} diff --git a/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp b/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp index 8abd164a8..b7dacb118 100644 --- a/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp @@ -33,4 +33,8 @@ namespace ams::htclow { constexpr inline s16 ProtocolVersion = 5; + enum ReceiveOption { + /* ... */ + }; + } diff --git a/libraries/libstratosphere/source/htc/server/driver/htc_driver_manager.hpp b/libraries/libstratosphere/source/htc/server/driver/htc_driver_manager.hpp new file mode 100644 index 000000000..35757d778 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/driver/htc_driver_manager.hpp @@ -0,0 +1,29 @@ +/* + * 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_i_driver.hpp" + +namespace ams::htc::server::driver { + + class DriverManager { + private: + IDriver *m_driver; + public: + DriverManager(IDriver *driver) : m_driver(driver) { /* ... */ } + }; + +} diff --git a/libraries/libstratosphere/source/htc/server/driver/htc_htclow_driver.hpp b/libraries/libstratosphere/source/htc/server/driver/htc_htclow_driver.hpp new file mode 100644 index 000000000..9e600acdd --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/driver/htc_htclow_driver.hpp @@ -0,0 +1,47 @@ +/* + * 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" +#include "htc_i_driver.hpp" + +namespace ams::htc::server::driver { + + class HtclowDriver final : public IDriver { + private: + static constexpr size_t DefaultBufferSize = 128_KB; + private: + u8 m_default_receive_buffer[DefaultBufferSize]; + u8 m_default_send_buffer[DefaultBufferSize]; + htclow::HtclowManager *m_manager; + bool m_disconnection_emulation_enabled; + htclow::ModuleId m_module_id; + public: + HtclowDriver(htclow::HtclowManager *manager, htclow::ModuleId module_id) : m_manager(manager), m_disconnection_emulation_enabled(false), m_module_id(module_id) { /* ... */ } + public: + virtual void SetDisconnectionEmulationEnabled(bool en) override; + virtual Result Open(htclow::ChannelId channel) override; + virtual Result Open(htclow::ChannelId channel, void *receive_buffer, size_t receive_buffer_size, void *send_buffer, size_t send_buffer_size) override; + virtual void Close(htclow::ChannelId channel) override; + virtual Result Connect(htclow::ChannelId channel) override; + virtual void Shutdown(htclow::ChannelId channel) override; + virtual Result Send(s64 *out, const void *src, s64 src_size, htclow::ChannelId channel) override; + virtual Result Receive(s64 *out, void *dst, s64 dst_size, htclow::ChannelId channel, htclow::ReceiveOption option) override; + virtual htclow::ChannelState GetChannelState(htclow::ChannelId channel) override; + virtual os::EventType *GetChannelStateEvent(htclow::ChannelId channel) override; + }; + +} diff --git a/libraries/libstratosphere/source/htc/server/driver/htc_i_driver.hpp b/libraries/libstratosphere/source/htc/server/driver/htc_i_driver.hpp new file mode 100644 index 000000000..e1ca06a54 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/driver/htc_i_driver.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::htc::server::driver { + + class IDriver { + public: + virtual void SetDisconnectionEmulationEnabled(bool en) = 0; + virtual Result Open(htclow::ChannelId channel) = 0; + virtual Result Open(htclow::ChannelId channel, void *receive_buffer, size_t receive_buffer_size, void *send_buffer, size_t send_buffer_size) = 0; + virtual void Close(htclow::ChannelId channel) = 0; + virtual Result Connect(htclow::ChannelId channel) = 0; + virtual void Shutdown(htclow::ChannelId channel) = 0; + virtual Result Send(s64 *out, const void *src, s64 src_size, htclow::ChannelId channel) = 0; + virtual Result Receive(s64 *out, void *dst, s64 dst_size, htclow::ChannelId channel, htclow::ReceiveOption option) = 0; + virtual htclow::ChannelState GetChannelState(htclow::ChannelId channel) = 0; + virtual os::EventType *GetChannelStateEvent(htclow::ChannelId channel) = 0; + }; + +} diff --git a/libraries/libstratosphere/source/htc/server/htc_htc_service_object.cpp b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.cpp index b3f2a9525..be8e4c001 100644 --- a/libraries/libstratosphere/source/htc/server/htc_htc_service_object.cpp +++ b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.cpp @@ -18,13 +18,14 @@ namespace ams::htc::server { - HtcServiceObject::HtcServiceObject(htclow::HtclowManager *htclow_manager) { - AMS_ABORT("HtcServiceObject::HtcServiceObject"); + HtcServiceObject::HtcServiceObject(htclow::HtclowManager *htclow_manager) : m_set(), m_misc_impl(htclow_manager), m_observer(m_misc_impl), m_mutex(){ + /* Initialize our set. */ + m_set.Initialize(MaxSetElements, m_set_memory, sizeof(m_set_memory)); } HtcmiscImpl *HtcServiceObject::GetHtcmiscImpl() { - AMS_ABORT("HtcServiceObject::GetHtcmiscImpl"); + return std::addressof(m_misc_impl); } Result HtcServiceObject::GetEnvironmentVariable(sf::Out out_size, const sf::OutBuffer &out, const sf::InBuffer &name) { diff --git a/libraries/libstratosphere/source/htc/server/htc_htc_service_object.hpp b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.hpp index 0ff25a582..b478062a1 100644 --- a/libraries/libstratosphere/source/htc/server/htc_htc_service_object.hpp +++ b/libraries/libstratosphere/source/htc/server/htc_htc_service_object.hpp @@ -16,12 +16,21 @@ #pragma once #include #include "../../htclow/htclow_manager.hpp" +#include "htc_htcmisc_impl.hpp" +#include "htc_observer.hpp" namespace ams::htc::server { class HtcServiceObject { private: - /* TODO */ + static constexpr inline auto MaxSetElements = 0x48; + using Set = util::FixedSet; + private: + u8 m_set_memory[Set::GetRequiredMemorySize(MaxSetElements)]; + Set m_set; + HtcmiscImpl m_misc_impl; + Observer m_observer; + os::SdkMutex m_mutex; public: HtcServiceObject(htclow::HtclowManager *htclow_manager); public: diff --git a/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.hpp b/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.hpp new file mode 100644 index 000000000..d2cd85c1e --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/htc_htcmisc_impl.hpp @@ -0,0 +1,47 @@ +/* + * 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" +#include "driver/htc_htclow_driver.hpp" +#include "driver/htc_driver_manager.hpp" +#include "rpc/htc_rpc_client.hpp" +#include "rpc/htc_htcmisc_rpc_server.hpp" + +namespace ams::htc::server { + + class HtcmiscImpl { + private: + driver::HtclowDriver m_htclow_driver; + driver::DriverManager m_driver_manager; + rpc::RpcClient m_rpc_client; + rpc::HtcmiscRpcServer m_rpc_server; + os::ThreadType m_client_thread; + os::ThreadType m_server_thread; + os::Event m_event_61200; + u8 m_61228; + os::Event m_event_61230; + bool m_client_connected; + bool m_server_connected; + u8 m_6125A; + os::SdkMutex m_connection_mutex; + public: + HtcmiscImpl(htclow::HtclowManager *htclow_manager); + public: + /* TODO */ + }; + +} diff --git a/libraries/libstratosphere/source/htc/server/htc_observer.hpp b/libraries/libstratosphere/source/htc/server/htc_observer.hpp new file mode 100644 index 000000000..bde6d56cf --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/htc_observer.hpp @@ -0,0 +1,37 @@ +/* + * 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_htcmisc_impl.hpp" + +namespace ams::htc::server { + + class Observer { + private: + os::SystemEvent m_connect_event; + os::SystemEvent m_disconnect_event; + os::Event m_event_60; + os::ThreadType m_observer_thread; + const HtcmiscImpl &m_misc_impl; + bool m_thread_running; + bool m_stopped; + bool m_connected; + bool m_is_service_available; + public: + Observer(const HtcmiscImpl &misc_impl); + }; + +} diff --git a/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.hpp b/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_server.hpp new file mode 100644 index 000000000..71d028130 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/rpc/htc_htcmisc_rpc_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 +#include "../driver/htc_i_driver.hpp" + +namespace ams::htc::server::rpc { + + class HtcmiscRpcServer { + private: + u64 m_00; + driver::IDriver *m_driver; + htclow::ChannelId m_channel_id; + void *m_receive_thread_stack; + os::ThreadType m_receive_thread; + bool m_cancelled; + bool m_thread_running; + public: + HtcmiscRpcServer(driver::IDriver *driver, htclow::ChannelId channel); + }; + +} diff --git a/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp new file mode 100644 index 000000000..4ca916797 --- /dev/null +++ b/libraries/libstratosphere/source/htc/server/rpc/htc_rpc_client.hpp @@ -0,0 +1,44 @@ +/* + * 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 "../driver/htc_i_driver.hpp" + +namespace ams::htc::server::rpc { + + class RpcClient { + private: + u64 m_00; + driver::IDriver *m_driver; + htclow::ChannelId m_channel_id; + void *m_receive_thread_stack; + void *m_send_thread_stack; + os::ThreadType m_receive_thread; + os::ThreadType m_send_thread; + os::SdkMutex *m_p_mutex; + /* TODO: m_task_id_free_list */ + /* TODO: m_task_table */ + /* TODO: m_3C0[0x48] */ + /* TODO: m_rpc_task_queue */ + bool m_cancelled; + bool m_thread_running; + os::EventType m_5F8_events[0x48]; + os::EventType m_1138_events[0x48]; + public: + RpcClient(driver::IDriver *driver, htclow::ChannelId channel); + }; + +} diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp index d42bb45c0..96fd92fa6 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service_channels.hpp @@ -24,11 +24,11 @@ namespace ams::htclow::ctrl { .module_id = ModuleId::Htcfs, }, { - .channel_id = 1, /* TODO: htcmisc::ServerChannelId? */ + .channel_id = 1, /* TODO: htcmisc::ClientChannelId? */ .module_id = ModuleId::Htcmisc, }, { - .channel_id = 2, /* TODO: htcmisc::ClientChannelId? */ + .channel_id = 2, /* TODO: htcmisc::ServerChannelId? */ .module_id = ModuleId::Htcmisc, }, {