htc: implement (fixing linker errors) through HtclowManagerImpl::OpenDriver

This commit is contained in:
Michael Scire
2021-02-08 01:25:10 -08:00
committed by SciresM
parent 1687bf2e07
commit c878123274
30 changed files with 582 additions and 22 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#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
);
}
}

View File

@@ -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);
};

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
#include <stratosphere.hpp>
#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));
}
}
}

View File

@@ -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; }
};
}

View File

@@ -20,6 +20,7 @@ namespace ams::htclow::ctrl {
namespace {
/* TODO: Real module id names */
constexpr const impl::ChannelInternalType ServiceChannels[] = {
{
.channel_id = 0,