2021-03-17 00:13:30 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-03-17 00:13:30 +00:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <vapours.hpp>
|
|
|
|
|
|
|
|
namespace ams::scs {
|
|
|
|
|
2021-07-29 04:52:55 +00:00
|
|
|
struct alignas(alignof(u32)) CommandHeader {
|
|
|
|
u64 id __attribute__((packed));
|
2021-03-17 00:13:30 +00:00
|
|
|
u32 command;
|
|
|
|
u32 body_size;
|
|
|
|
};
|
2021-07-29 04:52:55 +00:00
|
|
|
static_assert(sizeof(CommandHeader) == 0x10);
|
|
|
|
static_assert(alignof(CommandHeader) == alignof(u32));
|
2021-03-17 00:13:30 +00:00
|
|
|
|
2021-07-29 04:52:55 +00:00
|
|
|
struct alignas(alignof(u32)) ResponseHeader {
|
|
|
|
u64 id __attribute__((packed));
|
2021-03-17 00:13:30 +00:00
|
|
|
u32 response;
|
|
|
|
u32 body_size;
|
|
|
|
};
|
2021-07-29 04:52:55 +00:00
|
|
|
static_assert(sizeof(ResponseHeader) == 0x10);
|
|
|
|
static_assert(alignof(ResponseHeader) == alignof(u32));
|
2021-03-17 00:13:30 +00:00
|
|
|
|
|
|
|
class CommandProcessor {
|
|
|
|
protected:
|
|
|
|
enum Command {
|
|
|
|
Command_None = 0,
|
|
|
|
Command_LaunchProgramFromHost = 1,
|
|
|
|
Command_TerminateProcesses = 2,
|
|
|
|
Command_GetFirmwareVersion = 3,
|
|
|
|
Command_Reboot = 4,
|
|
|
|
Command_SetSafeMode = 5,
|
|
|
|
Command_RegisterTenvDefinitionFilePath = 6,
|
|
|
|
Command_TerminateApplication = 7,
|
|
|
|
Command_Shutdown = 8,
|
|
|
|
Command_SubscribeProcessEvent = 9,
|
|
|
|
Command_GetTitleName = 10,
|
|
|
|
Command_ControlVirtualTemperature = 11,
|
|
|
|
Command_LaunchInstalledApplication = 12,
|
|
|
|
Command_LaunchGameCardApplication = 13,
|
|
|
|
Command_LaunchInstalledSystemProcess = 14,
|
|
|
|
Command_TakeScreenShot = 15,
|
|
|
|
Command_TakeForegroundScreenShot = 16,
|
|
|
|
Command_SimulateGameCardDetection = 17,
|
|
|
|
Command_SimulateSdCardDetection = 18,
|
|
|
|
Command_DumpRunningApplication = 19,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Response {
|
2021-03-18 04:46:32 +00:00
|
|
|
Response_None = 0,
|
|
|
|
Response_Success = 1,
|
|
|
|
Response_Error = 2,
|
|
|
|
Response_ProgramExited = 3,
|
|
|
|
Response_FirmwareVersion = 4,
|
|
|
|
Response_JitDebug = 5,
|
|
|
|
Response_ProgramLaunched = 6,
|
|
|
|
Response_TitleName = 7,
|
|
|
|
Response_ScreenShot = 8,
|
2021-03-17 00:13:30 +00:00
|
|
|
};
|
|
|
|
public:
|
|
|
|
constexpr CommandProcessor() = default;
|
|
|
|
|
|
|
|
void Initialize();
|
|
|
|
public:
|
|
|
|
virtual bool ProcessCommand(const CommandHeader &header, const u8 *body, s32 socket);
|
|
|
|
protected:
|
2021-03-18 04:46:32 +00:00
|
|
|
static std::scoped_lock<os::SdkMutex> MakeSendGuardBlock();
|
|
|
|
static void Send(s32 socket, const void *data, size_t size);
|
|
|
|
|
2021-03-17 00:13:30 +00:00
|
|
|
static void SendSuccess(s32 socket, const CommandHeader &header);
|
|
|
|
static void SendErrorResult(s32 socket, const CommandHeader &header, Result result);
|
|
|
|
private:
|
|
|
|
static void SendErrorResult(s32 socket, u64 id, Result result);
|
2021-03-18 04:46:32 +00:00
|
|
|
static void SendExited(s32 socket, u64 id, u64 process_id);
|
|
|
|
static void SendJitDebug(s32 socket, u64 id);
|
|
|
|
static void SendLaunched(s32 socket, u64 id, u64 process_id);
|
2021-03-17 00:13:30 +00:00
|
|
|
|
|
|
|
static void OnProcessStart(u64 id, s32 socket, os::ProcessId process_id);
|
|
|
|
static void OnProcessExit(u64 id, s32 socket, os::ProcessId process_id);
|
|
|
|
static void OnProcessJitDebug(u64 id, s32 socket, os::ProcessId process_id);
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|