diff --git a/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp b/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp index b05857437..8abd164a8 100644 --- a/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp +++ b/libraries/libstratosphere/include/stratosphere/htclow/htclow_types.hpp @@ -21,6 +21,8 @@ namespace ams::htclow { namespace impl { enum class DriverType { + Unknown = 0, + Debug = 1, Socket = 2, Usb = 3, HostBridge = 4, @@ -29,5 +31,6 @@ namespace ams::htclow { } + constexpr inline s16 ProtocolVersion = 5; } diff --git a/libraries/libstratosphere/include/stratosphere/settings.hpp b/libraries/libstratosphere/include/stratosphere/settings.hpp index 5b995f595..5f0419aaa 100644 --- a/libraries/libstratosphere/include/stratosphere/settings.hpp +++ b/libraries/libstratosphere/include/stratosphere/settings.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/libraries/libstratosphere/include/stratosphere/settings/factory/settings_configuration_id.hpp b/libraries/libstratosphere/include/stratosphere/settings/factory/settings_configuration_id.hpp new file mode 100644 index 000000000..4f46473e0 --- /dev/null +++ b/libraries/libstratosphere/include/stratosphere/settings/factory/settings_configuration_id.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 + +namespace ams::settings::factory { + + struct ConfigurationId1 { + char str[30]; + }; + static_assert(sizeof(ConfigurationId1) == 30); + static_assert(util::is_pod::value); + + void GetConfigurationId1(ConfigurationId1 *out); + +} diff --git a/libraries/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp b/libraries/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp index 301139cca..cfb096004 100644 --- a/libraries/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp +++ b/libraries/libstratosphere/include/stratosphere/settings/factory/settings_serial_number.hpp @@ -24,4 +24,6 @@ namespace ams::settings::factory { static_assert(sizeof(SerialNumber) == 0x18); static_assert(util::is_pod::value); + Result GetSerialNumber(SerialNumber *out); + } diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.cpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.cpp new file mode 100644 index 000000000..df719e155 --- /dev/null +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.cpp @@ -0,0 +1,77 @@ +/* + * 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 "htclow_ctrl_service.hpp" +#include "../mux/htclow_mux.hpp" + +namespace ams::htclow::ctrl { + + namespace { + + constexpr const char BeaconPacketResponseTemplate[] = + "{\r\n" + " \"Spec\" : \"%s\",\r\n" + " \"Conn\" : \"%s\",\r\n" + " \"HW\" : \"%s\",\r\n" + " \"Name\" : \"%s\",\r\n" + " \"SN\" : \"%s\",\r\n" + " \"FW\" : \"%s\",\r\n" + " \"Prot\" : \"%d\"\r\n" + "}\r\n"; + + } + + HtcctrlService::HtcctrlService(HtcctrlPacketFactory *pf, HtcctrlStateMachine *sm, mux::Mux *mux) + : m_settings_holder(), m_beacon_response(), m_1100(), m_packet_factory(pf), m_state_machine(sm), m_mux(mux), m_event(os::EventClearMode_ManualClear), + m_send_buffer(pf), m_mutex(), m_condvar(), m_2170(), m_version(ProtocolVersion) + { + /* Lock ourselves. */ + std::scoped_lock lk(m_mutex); + + /* Set the mux version. */ + m_mux->SetVersion(m_version); + + /* Update our beacon response. */ + this->UpdateBeaconResponse(this->GetConnectionType(impl::DriverType::Unknown)); + } + + const char *HtcctrlService::GetConnectionType(impl::DriverType driver_type) const { + switch (driver_type) { + case impl::DriverType::Socket: return "TCP"; + case impl::DriverType::Usb: return "USB-gen2"; + case impl::DriverType::PlainChannel: return "HBPC-gen2"; + default: return "Unknown"; + } + } + + void HtcctrlService::UpdateBeaconResponse(const char *connection) { + /* Load settings into the holder. */ + m_settings_holder.LoadSettings(); + + /* Print our beacon response. */ + util::SNPrintf(m_beacon_response, sizeof(m_beacon_response), BeaconPacketResponseTemplate, + m_settings_holder.GetSpec(), + connection, + m_settings_holder.GetHardwareType(), + m_settings_holder.GetTargetName(), + m_settings_holder.GetSerialNumber(), + m_settings_holder.GetFirmwareVersion(), + ProtocolVersion + ); + } + + +} diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp index 9c42fd258..39b0a0274 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_service.hpp @@ -40,17 +40,21 @@ namespace ams::htclow::ctrl { class HtcctrlService { private: SettingsHolder m_settings_holder; - u8 m_beacon_response[0x1000]; + char m_beacon_response[0x1000]; u8 m_1100[0x1000]; HtcctrlPacketFactory *m_packet_factory; HtcctrlStateMachine *m_state_machine; mux::Mux *m_mux; - os::EventType m_event; + os::Event m_event; HtcctrlSendBuffer m_send_buffer; os::SdkMutex m_mutex; os::SdkConditionVariable m_condvar; u8 m_2170[0x1000]; - u16 m_version; + s16 m_version; + private: + const char *GetConnectionType(impl::DriverType driver_type) const; + + void UpdateBeaconResponse(const char *connection); public: HtcctrlService(HtcctrlPacketFactory *pf, HtcctrlStateMachine *sm, mux::Mux *mux); }; diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.cpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.cpp new file mode 100644 index 000000000..6d17dde77 --- /dev/null +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.cpp @@ -0,0 +1,59 @@ +/* + * 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 "htclow_ctrl_settings_holder.hpp" + +namespace ams::htclow::ctrl { + + void SettingsHolder::LoadSettings() { + /* Load configuration id. */ + { + settings::factory::ConfigurationId1 cfg_id; + settings::factory::GetConfigurationId1(std::addressof(cfg_id)); + + if (cfg_id.str[0]) { + util::Strlcpy(m_hardware_type, cfg_id.str, sizeof(m_hardware_type)); + } else { + util::Strlcpy(m_hardware_type, "Unknown", sizeof(m_hardware_type)); + } + } + + /* Load device name. */ + { + char device_name[0x40]; + settings::fwdbg::GetSettingsItemValue(device_name, sizeof(device_name), "target_manager", "device_name"); + util::Strlcpy(m_target_name, device_name, sizeof(m_target_name)); + } + + /* Load serial number. */ + { + settings::factory::SerialNumber sn; + if (R_SUCCEEDED(settings::factory::GetSerialNumber(std::addressof(sn)))) { + util::Strlcpy(m_serial_number, sn.str, sizeof(m_serial_number)); + } else { + m_serial_number[0] = '\x00'; + } + } + + /* Load firmware version. */ + { + settings::system::FirmwareVersion fw_ver; + settings::system::GetFirmwareVersion(std::addressof(fw_ver)); + util::Strlcpy(m_firmware_version, fw_ver.display_name, sizeof(m_firmware_version)); + } + } + +} diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp index df956e832..ca4561008 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_settings_holder.hpp @@ -26,6 +26,14 @@ namespace ams::htclow::ctrl { char m_firmware_version[0x40]; public: SettingsHolder() { /* ... */ } + + void LoadSettings(); + + const char *GetSpec() { return "NX"; } + const char *GetHardwareType() { return m_hardware_type; } + const char *GetTargetName() { return m_target_name; } + const char *GetSerialNumber() { return m_serial_number; } + const char *GetFirmwareVersion() { return m_firmware_version; } }; } diff --git a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.cpp b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.cpp index 655a1f8c1..b740a4bad 100644 --- a/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.cpp +++ b/libraries/libstratosphere/source/htclow/ctrl/htclow_ctrl_state_machine.cpp @@ -20,6 +20,7 @@ namespace ams::htclow::ctrl { namespace { + /* TODO: Real module id names */ constexpr const impl::ChannelInternalType ServiceChannels[] = { { .channel_id = 0, diff --git a/libraries/libstratosphere/source/htclow/htclow_listener.cpp b/libraries/libstratosphere/source/htclow/htclow_listener.cpp new file mode 100644 index 000000000..cb2a2d7bc --- /dev/null +++ b/libraries/libstratosphere/source/htclow/htclow_listener.cpp @@ -0,0 +1,28 @@ +/* + * 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 "htclow_listener.hpp" + +namespace ams::htclow { + + Listener::Listener(mem::StandardAllocator *allocator, mux::Mux *mux, ctrl::HtcctrlService *ctrl_srv, Worker *worker) + : m_thread_stack_size(4_KB), m_allocator(allocator), m_mux(mux), m_service(ctrl_srv), m_worker(worker), m_event(os::EventClearMode_ManualClear), m_driver(nullptr), m_thread_running(false), m_cancelled(false) + { + /* Allocate stack. */ + m_listen_thread_stack = m_allocator->Allocate(m_thread_stack_size, os::ThreadStackAlignment); + } + +} diff --git a/libraries/libstratosphere/source/htclow/htclow_listener.hpp b/libraries/libstratosphere/source/htclow/htclow_listener.hpp index b6771cf87..0567a176f 100644 --- a/libraries/libstratosphere/source/htclow/htclow_listener.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_listener.hpp @@ -26,7 +26,7 @@ namespace ams::htclow { mux::Mux *m_mux; ctrl::HtcctrlService *m_service; Worker *m_worker; - os::EventType m_event; + os::Event m_event; os::ThreadType m_listen_thread; void *m_listen_thread_stack; driver::IDriver *m_driver; diff --git a/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp b/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp index 2bf71ffa0..e7154f25c 100644 --- a/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp +++ b/libraries/libstratosphere/source/htclow/htclow_manager_impl.cpp @@ -31,8 +31,10 @@ namespace ams::htclow { /* ... */ } - //Result HtclowManagerImpl::OpenDriver(impl::DriverType driver_type); - // + Result HtclowManagerImpl::OpenDriver(impl::DriverType driver_type) { + AMS_ABORT("TODO"); + } + //void HtclowManagerImpl::CloseDriver(); // //void HtclowManagerImpl::Disconnect(); diff --git a/libraries/libstratosphere/source/htclow/htclow_worker.cpp b/libraries/libstratosphere/source/htclow/htclow_worker.cpp new file mode 100644 index 000000000..bbe6ab99b --- /dev/null +++ b/libraries/libstratosphere/source/htclow/htclow_worker.cpp @@ -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 . + */ +#include +#include "htclow_worker.hpp" + +namespace ams::htclow { + + Worker::Worker(mem::StandardAllocator *allocator, mux::Mux *mux, ctrl::HtcctrlService *ctrl_srv) + : m_thread_stack_size(4_KB), m_allocator(allocator), m_mux(mux), m_service(ctrl_srv), m_driver(nullptr), m_event(os::EventClearMode_ManualClear), m_7C400() + { + /* Allocate stacks. */ + m_receive_thread_stack = m_allocator->Allocate(m_thread_stack_size, os::ThreadStackAlignment); + m_send_thread_stack = m_allocator->Allocate(m_thread_stack_size, os::ThreadStackAlignment); + } + +} diff --git a/libraries/libstratosphere/source/htclow/htclow_worker.hpp b/libraries/libstratosphere/source/htclow/htclow_worker.hpp index d4b046e76..7c3c9f34f 100644 --- a/libraries/libstratosphere/source/htclow/htclow_worker.hpp +++ b/libraries/libstratosphere/source/htclow/htclow_worker.hpp @@ -31,7 +31,7 @@ namespace ams::htclow { driver::IDriver *m_driver; os::ThreadType m_receive_thread; os::ThreadType m_send_thread; - os::EventType m_event; + os::Event m_event; void *m_receive_thread_stack; void *m_send_thread_stack; u8 m_7C400; diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp index d5a7a3e46..474470dbf 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux.cpp @@ -21,9 +21,20 @@ namespace ams::htclow::mux { Mux::Mux(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm) : m_packet_factory(pf), m_state_machine(sm), m_task_manager(), m_wake_event(os::EventClearMode_ManualClear), m_channel_impl_map(pf, sm, std::addressof(m_task_manager), std::addressof(m_wake_event)), m_global_send_buffer(pf), - m_mutex(), m_is_sleeping(false), m_version(5) + m_mutex(), m_is_sleeping(false), m_version(ProtocolVersion) { /* ... */ } + void Mux::SetVersion(u16 version) { + /* Set our version. */ + m_version = version; + + /* Set all entries in our map. */ + /* NOTE: Nintendo does this highly inefficiently... */ + for (auto &pair : m_channel_impl_map.GetMap()) { + m_channel_impl_map[pair.first].SetVersion(m_version); + } + } + } diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp index dbe9b856b..af8c27ae5 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux.hpp @@ -34,6 +34,8 @@ namespace ams::htclow::mux { u16 m_version; public: Mux(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm); + + void SetVersion(u16 version); }; } diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl.cpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl.cpp new file mode 100644 index 000000000..f10d81a2f --- /dev/null +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl.cpp @@ -0,0 +1,30 @@ +/* + * 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 "htclow_mux_channel_impl.hpp" + +namespace ams::htclow::mux { + + void ChannelImpl::SetVersion(s16 version) { + /* Sanity check the version. */ + AMS_ASSERT(version <= ProtocolVersion); + + /* Set version. */ + m_version = version; + m_send_buffer.SetVersion(version); + } + +} diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl.hpp new file mode 100644 index 000000000..e014cd05a --- /dev/null +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl.hpp @@ -0,0 +1,56 @@ +/* + * 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_mux_task_manager.hpp" +#include "htclow_mux_send_buffer.hpp" + +namespace ams::htclow { + + class PacketFactory; + + namespace ctrl { + + class HtcctrlStateMachine; + + } + +} + +namespace ams::htclow::mux { + + class ChannelImpl { + private: + impl::ChannelInternalType m_channel; + PacketFactory *m_packet_factory; + ctrl::HtcctrlStateMachine *m_state_machine; + TaskManager *m_task_manager; + os::Event *m_event; + SendBuffer m_send_buffer; + RingBuffer m_receive_buffer; + s16 m_version; + /* TODO: Channel config */ + /* TODO: tracking variables. */ + std::optional m_108; + os::Event m_send_packet_event; + /* TODO: Channel state. */ + public: + ChannelImpl(impl::ChannelInternalType channel, PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev); + + void SetVersion(s16 version); + }; + +} diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.cpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.cpp index 3e5e23119..cd3ccf955 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.cpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.cpp @@ -30,4 +30,17 @@ namespace ams::htclow::mux { } } + ChannelImpl &ChannelImplMap::GetChannelImpl(int index) { + return GetReference(m_channel_storage[index]); + } + + ChannelImpl &ChannelImplMap::GetChannelImpl(impl::ChannelInternalType channel) { + /* Find the channel. */ + auto it = m_map.find(channel); + AMS_ASSERT(it != m_map.end()); + + /* Return the implementation object. */ + return this->GetChannelImpl(it->second); + } + } diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp index 1dcdc36c4..14886b152 100644 --- a/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_channel_impl_map.hpp @@ -15,19 +15,7 @@ */ #pragma once #include -#include "htclow_mux_task_manager.hpp" - -namespace ams::htclow { - - class PacketFactory; - - namespace ctrl { - - class HtcctrlStateMachine; - - } - -} +#include "htclow_mux_channel_impl.hpp" namespace ams::htclow::mux { @@ -47,10 +35,22 @@ namespace ams::htclow::mux { os::Event *m_event; u8 m_map_buffer[MapRequiredMemorySize]; MapType m_map; - u8 m_storage[0x5200]; /* TODO */ + TYPED_STORAGE(ChannelImpl) m_channel_storage[MaxChannelCount]; bool m_storage_valid[MaxChannelCount]; public: ChannelImplMap(PacketFactory *pf, ctrl::HtcctrlStateMachine *sm, TaskManager *tm, os::Event *ev); + + ChannelImpl &GetChannelImpl(impl::ChannelInternalType channel); + private: + ChannelImpl &GetChannelImpl(int index); + public: + MapType &GetMap() { + return m_map; + } + + ChannelImpl &operator[](impl::ChannelInternalType channel) { + return this->GetChannelImpl(channel); + } }; } diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_ring_buffer.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_ring_buffer.hpp new file mode 100644 index 000000000..02557ea68 --- /dev/null +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_ring_buffer.hpp @@ -0,0 +1,34 @@ +/* + * 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::mux { + + class RingBuffer { + private: + void *m_buffer; + void *m_read_only_buffer; + bool m_is_read_only; + size_t m_buffer_size; + size_t m_data_size; + size_t m_offset; + bool m_has_copied; + public: + RingBuffer() : m_buffer(), m_read_only_buffer(), m_is_read_only(true), m_buffer_size(), m_data_size(), m_offset(), m_has_copied(false) { /* ... */ } + }; + +} diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_send_buffer.cpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_send_buffer.cpp new file mode 100644 index 000000000..2d3693428 --- /dev/null +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_send_buffer.cpp @@ -0,0 +1,26 @@ +/* + * 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 "htclow_mux_channel_impl.hpp" + +namespace ams::htclow::mux { + + void SendBuffer::SetVersion(s16 version) { + /* Set version. */ + m_version = version; + } + +} diff --git a/libraries/libstratosphere/source/htclow/mux/htclow_mux_send_buffer.hpp b/libraries/libstratosphere/source/htclow/mux/htclow_mux_send_buffer.hpp new file mode 100644 index 000000000..cfc5695be --- /dev/null +++ b/libraries/libstratosphere/source/htclow/mux/htclow_mux_send_buffer.hpp @@ -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 . + */ +#pragma once +#include +#include "../htclow_packet.hpp" +#include "htclow_mux_ring_buffer.hpp" + +namespace ams::htclow { + + class PacketFactory; + +} + +namespace ams::htclow::mux { + + class SendBuffer { + private: + using PacketList = util::IntrusiveListBaseTraits::ListType; + private: + impl::ChannelInternalType m_channel; + PacketFactory *m_packet_factory; + RingBuffer m_ring_buffer; + PacketList m_packet_list; + s16 m_version; + bool m_flow_control_enabled; + size_t m_max_packet_size; + public: + SendBuffer(impl::ChannelInternalType channel, PacketFactory *pf); + + void SetVersion(s16 version); + }; + +} diff --git a/libraries/libstratosphere/source/settings/impl/settings_configuration_id_impl.cpp b/libraries/libstratosphere/source/settings/impl/settings_configuration_id_impl.cpp new file mode 100644 index 000000000..48b3ecd3e --- /dev/null +++ b/libraries/libstratosphere/source/settings/impl/settings_configuration_id_impl.cpp @@ -0,0 +1,26 @@ +/* + * 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 "settings_serial_number_impl.hpp" + +namespace ams::settings::impl { + + Result GetConfigurationId1(settings::factory::ConfigurationId1 *out) { + static_assert(sizeof(*out) == sizeof(::SetCalConfigurationId1)); + return ::setcalGetConfigurationId1(reinterpret_cast<::SetCalConfigurationId1 *>(out)); + } + +} diff --git a/libraries/libstratosphere/source/settings/impl/settings_configuration_id_impl.hpp b/libraries/libstratosphere/source/settings/impl/settings_configuration_id_impl.hpp new file mode 100644 index 000000000..3d5624831 --- /dev/null +++ b/libraries/libstratosphere/source/settings/impl/settings_configuration_id_impl.hpp @@ -0,0 +1,23 @@ +/* + * 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::settings::impl { + + Result GetConfigurationId1(settings::factory::ConfigurationId1 *out); + +} diff --git a/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.cpp b/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.cpp index 56a073c02..93fe6facb 100644 --- a/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.cpp +++ b/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.cpp @@ -18,6 +18,11 @@ namespace ams::settings::impl { + Result GetSerialNumber(settings::factory::SerialNumber *out) { + static_assert(sizeof(*out) == sizeof(::SetCalSerialNumber)); + return ::setcalGetSerialNumber(reinterpret_cast<::SetCalSerialNumber *>(out)); + } + Result GetSerialNumber(settings::system::SerialNumber *out) { static_assert(sizeof(*out) == sizeof(::SetSysSerialNumber)); return ::setsysGetSerialNumber(reinterpret_cast<::SetSysSerialNumber *>(out)); diff --git a/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.hpp b/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.hpp index 87df5e90a..475ea27af 100644 --- a/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.hpp +++ b/libraries/libstratosphere/source/settings/impl/settings_serial_number_impl.hpp @@ -18,6 +18,7 @@ namespace ams::settings::impl { + Result GetSerialNumber(settings::factory::SerialNumber *out); Result GetSerialNumber(settings::system::SerialNumber *out); } diff --git a/libraries/libstratosphere/source/settings/settings_configuration_id.cpp b/libraries/libstratosphere/source/settings/settings_configuration_id.cpp new file mode 100644 index 000000000..f4baa6316 --- /dev/null +++ b/libraries/libstratosphere/source/settings/settings_configuration_id.cpp @@ -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 . + */ +#include +#include "impl/settings_configuration_id_impl.hpp" + +namespace ams::settings::factory { + + void GetConfigurationId1(ConfigurationId1 *out) { + R_ABORT_UNLESS(settings::impl::GetConfigurationId1(out)); + } + +} diff --git a/libraries/libstratosphere/source/settings/settings_serial_number.cpp b/libraries/libstratosphere/source/settings/settings_serial_number.cpp index 05e17c545..083dbb623 100644 --- a/libraries/libstratosphere/source/settings/settings_serial_number.cpp +++ b/libraries/libstratosphere/source/settings/settings_serial_number.cpp @@ -16,6 +16,20 @@ #include #include "impl/settings_serial_number_impl.hpp" +namespace ams::settings::factory { + + Result GetSerialNumber(SerialNumber *out) { + const Result result = settings::impl::GetSerialNumber(out); + + if (!settings::ResultCalibrationDataFileSystemCorrupted::Includes(result) && !settings::ResultCalibrationDataCrcError::Includes(result)) { + R_ABORT_UNLESS(result); + } + + return result; + } + +} + namespace ams::settings::system { void GetSerialNumber(SerialNumber *out) { diff --git a/libraries/libvapours/include/vapours/results/settings_results.hpp b/libraries/libvapours/include/vapours/results/settings_results.hpp index e704371b7..d01e41178 100644 --- a/libraries/libvapours/include/vapours/results/settings_results.hpp +++ b/libraries/libvapours/include/vapours/results/settings_results.hpp @@ -44,4 +44,9 @@ namespace ams::settings { R_DEFINE_ERROR_RESULT(SettingsItemKeyInvalidFormat, 262); R_DEFINE_ERROR_RESULT(SettingsItemValueInvalidFormat, 263); + R_DEFINE_ERROR_RANGE(CalibrationDataError, 580, 599); + R_DEFINE_ERROR_RESULT(CalibrationDataFileSystemCorrupted, 581); + R_DEFINE_ERROR_RESULT(CalibrationDataCrcError, 582); + R_DEFINE_ERROR_RESULT(CalibrationDataShaError, 583); + }