2015-02-27 03:13:08 +01:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-05-06 09:06:12 +02:00
|
|
|
#include "common/common_paths.h"
|
2015-02-27 03:13:08 +01:00
|
|
|
#include "common/file_util.h"
|
2015-05-06 09:06:12 +02:00
|
|
|
#include "common/logging/log.h"
|
2017-03-08 22:28:30 +01:00
|
|
|
#include "core/core.h"
|
2018-09-28 20:08:30 +02:00
|
|
|
#include "core/file_sys/archive_ncch.h"
|
2017-06-15 18:09:05 +02:00
|
|
|
#include "core/file_sys/file_backend.h"
|
2015-05-26 06:30:20 +02:00
|
|
|
#include "core/hle/applets/applet.h"
|
2016-09-20 17:21:23 +02:00
|
|
|
#include "core/hle/kernel/mutex.h"
|
|
|
|
#include "core/hle/kernel/shared_memory.h"
|
2017-06-15 18:09:05 +02:00
|
|
|
#include "core/hle/romfs.h"
|
2018-01-25 14:39:54 +01:00
|
|
|
#include "core/hle/service/apt/applet_manager.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "core/hle/service/apt/apt.h"
|
2015-02-27 03:13:08 +01:00
|
|
|
#include "core/hle/service/apt/apt_a.h"
|
|
|
|
#include "core/hle/service/apt/apt_s.h"
|
|
|
|
#include "core/hle/service/apt/apt_u.h"
|
2016-04-19 19:13:00 +02:00
|
|
|
#include "core/hle/service/apt/bcfnt/bcfnt.h"
|
2017-08-02 21:56:44 +02:00
|
|
|
#include "core/hle/service/cfg/cfg.h"
|
2015-12-04 22:05:23 +01:00
|
|
|
#include "core/hle/service/fs/archive.h"
|
2016-04-20 12:12:05 +02:00
|
|
|
#include "core/hle/service/ptm/ptm.h"
|
2016-09-18 02:38:01 +02:00
|
|
|
#include "core/hle/service/service.h"
|
2017-01-01 13:58:24 +01:00
|
|
|
#include "core/hw/aes/ccm.h"
|
|
|
|
#include "core/hw/aes/key.h"
|
2015-02-27 03:13:08 +01:00
|
|
|
|
2018-09-22 14:23:08 +02:00
|
|
|
namespace Service::APT {
|
2015-02-27 03:13:08 +01:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::Initialize(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x2, 2, 0); // 0x20080
|
2018-01-25 14:39:54 +01:00
|
|
|
AppletId app_id = rp.PopEnum<AppletId>();
|
2017-07-22 19:33:03 +02:00
|
|
|
u32 attributes = rp.Pop<u32>();
|
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called app_id={:#010X}, attributes={:#010X}", static_cast<u32>(app_id),
|
|
|
|
attributes);
|
2015-02-27 03:13:08 +01:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
auto result = apt->applet_manager->Initialize(app_id, attributes);
|
2018-01-25 14:39:54 +01:00
|
|
|
if (result.Failed()) {
|
2017-07-22 19:33:03 +02:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-01-25 14:39:54 +01:00
|
|
|
rb.Push(result.Code());
|
|
|
|
} else {
|
|
|
|
auto events = std::move(result).Unwrap();
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 3);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushCopyObjects(events.notification_event, events.parameter_event);
|
2017-09-23 20:59:07 +02:00
|
|
|
}
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2017-08-02 21:56:44 +02:00
|
|
|
static u32 DecompressLZ11(const u8* in, u8* out) {
|
|
|
|
u32_le decompressed_size;
|
|
|
|
memcpy(&decompressed_size, in, sizeof(u32));
|
|
|
|
in += 4;
|
|
|
|
|
|
|
|
u8 type = decompressed_size & 0xFF;
|
|
|
|
ASSERT(type == 0x11);
|
|
|
|
decompressed_size >>= 8;
|
|
|
|
|
|
|
|
u32 current_out_size = 0;
|
|
|
|
u8 flags = 0, mask = 1;
|
|
|
|
while (current_out_size < decompressed_size) {
|
|
|
|
if (mask == 1) {
|
|
|
|
flags = *(in++);
|
|
|
|
mask = 0x80;
|
|
|
|
} else {
|
|
|
|
mask >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flags & mask) {
|
|
|
|
u8 byte1 = *(in++);
|
|
|
|
u32 length = byte1 >> 4;
|
|
|
|
u32 offset;
|
|
|
|
if (length == 0) {
|
|
|
|
u8 byte2 = *(in++);
|
|
|
|
u8 byte3 = *(in++);
|
|
|
|
length = (((byte1 & 0x0F) << 4) | (byte2 >> 4)) + 0x11;
|
|
|
|
offset = (((byte2 & 0x0F) << 8) | byte3) + 0x1;
|
|
|
|
} else if (length == 1) {
|
|
|
|
u8 byte2 = *(in++);
|
|
|
|
u8 byte3 = *(in++);
|
|
|
|
u8 byte4 = *(in++);
|
|
|
|
length = (((byte1 & 0x0F) << 12) | (byte2 << 4) | (byte3 >> 4)) + 0x111;
|
|
|
|
offset = (((byte3 & 0x0F) << 8) | byte4) + 0x1;
|
|
|
|
} else {
|
|
|
|
u8 byte2 = *(in++);
|
|
|
|
length = (byte1 >> 4) + 0x1;
|
|
|
|
offset = (((byte1 & 0x0F) << 8) | byte2) + 0x1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (u32 i = 0; i < length; i++) {
|
|
|
|
*out = *(out - offset);
|
|
|
|
++out;
|
|
|
|
}
|
|
|
|
|
|
|
|
current_out_size += length;
|
|
|
|
} else {
|
|
|
|
*(out++) = *(in++);
|
|
|
|
current_out_size++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return decompressed_size;
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
bool Module::LoadSharedFont() {
|
2017-08-02 21:56:44 +02:00
|
|
|
u8 font_region_code;
|
2018-03-06 09:43:24 +01:00
|
|
|
switch (CFG::GetCurrentModule()->GetRegionValue()) {
|
2017-08-02 21:56:44 +02:00
|
|
|
case 4: // CHN
|
|
|
|
font_region_code = 2;
|
|
|
|
break;
|
|
|
|
case 5: // KOR
|
|
|
|
font_region_code = 3;
|
|
|
|
break;
|
|
|
|
case 6: // TWN
|
|
|
|
font_region_code = 4;
|
|
|
|
break;
|
|
|
|
default: // JPN/EUR/USA
|
|
|
|
font_region_code = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
const u64_le shared_font_archive_id_low = 0x0004009b00014002 | ((font_region_code - 1) << 8);
|
|
|
|
|
2018-09-28 20:08:30 +02:00
|
|
|
FileSys::NCCHArchive archive(shared_font_archive_id_low, Service::FS::MediaType::NAND);
|
2017-08-02 21:56:44 +02:00
|
|
|
std::vector<u8> romfs_path(20, 0); // 20-byte all zero path for opening RomFS
|
|
|
|
FileSys::Path file_path(romfs_path);
|
|
|
|
FileSys::Mode open_mode = {};
|
|
|
|
open_mode.read_flag.Assign(1);
|
2018-09-28 20:08:30 +02:00
|
|
|
auto file_result = archive.OpenFile(file_path, open_mode);
|
2017-08-02 21:56:44 +02:00
|
|
|
if (file_result.Failed())
|
|
|
|
return false;
|
|
|
|
|
|
|
|
auto romfs = std::move(file_result).Unwrap();
|
2018-09-28 20:08:30 +02:00
|
|
|
std::vector<u8> romfs_buffer(romfs->GetSize());
|
|
|
|
romfs->Read(0, romfs_buffer.size(), romfs_buffer.data());
|
|
|
|
romfs->Close();
|
2017-08-02 21:56:44 +02:00
|
|
|
|
|
|
|
const char16_t* file_name[4] = {u"cbf_std.bcfnt.lz", u"cbf_zh-Hans-CN.bcfnt.lz",
|
|
|
|
u"cbf_ko-Hang-KR.bcfnt.lz", u"cbf_zh-Hant-TW.bcfnt.lz"};
|
2018-07-26 12:59:31 +02:00
|
|
|
const RomFS::RomFSFile font_file =
|
|
|
|
RomFS::GetFile(romfs_buffer.data(), {file_name[font_region_code - 1]});
|
|
|
|
if (font_file.Data() == nullptr)
|
2017-08-02 21:56:44 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u32_le status;
|
|
|
|
u32_le region;
|
|
|
|
u32_le decompressed_size;
|
|
|
|
INSERT_PADDING_WORDS(0x1D);
|
|
|
|
} shared_font_header{};
|
|
|
|
static_assert(sizeof(shared_font_header) == 0x80, "shared_font_header has incorrect size");
|
|
|
|
|
|
|
|
shared_font_header.status = 2; // successfully loaded
|
|
|
|
shared_font_header.region = font_region_code;
|
|
|
|
shared_font_header.decompressed_size =
|
2018-07-26 12:59:31 +02:00
|
|
|
DecompressLZ11(font_file.Data(), shared_font_mem->GetPointer(0x80));
|
2017-08-02 21:56:44 +02:00
|
|
|
std::memcpy(shared_font_mem->GetPointer(), &shared_font_header, sizeof(shared_font_header));
|
|
|
|
*shared_font_mem->GetPointer(0x83) = 'U'; // Change the magic from "CFNT" to "CFNU"
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
bool Module::LoadLegacySharedFont() {
|
2017-08-02 21:56:44 +02:00
|
|
|
// This is the legacy method to load shared font.
|
|
|
|
// The expected format is a decrypted, uncompressed BCFNT file with the 0x80 byte header
|
|
|
|
// generated by the APT:U service. The best way to get is by dumping it from RAM. We've provided
|
|
|
|
// a homebrew app to do this: https://github.com/citra-emu/3dsutils. Put the resulting file
|
|
|
|
// "shared_font.bin" in the Citra "sysdata" directory.
|
2018-07-21 21:52:42 +02:00
|
|
|
std::string filepath = FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + SHARED_FONT;
|
2017-08-02 21:56:44 +02:00
|
|
|
|
|
|
|
FileUtil::CreateFullPath(filepath); // Create path if not already created
|
|
|
|
FileUtil::IOFile file(filepath, "rb");
|
|
|
|
if (file.IsOpen()) {
|
|
|
|
file.ReadBytes(shared_font_mem->GetPointer(), file.GetSize());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GetSharedFont(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x44, 0, 0); // 0x00440000
|
2017-03-18 11:47:40 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
|
2017-08-02 02:00:40 +02:00
|
|
|
|
|
|
|
// Log in telemetry if the game uses the shared font
|
|
|
|
Core::Telemetry().AddField(Telemetry::FieldType::Session, "RequiresSharedFont", true);
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
if (!apt->shared_font_loaded) {
|
2017-08-02 21:56:44 +02:00
|
|
|
// On real 3DS, font loading happens on booting. However, we load it on demand to coordinate
|
|
|
|
// with CFG region auto configuration, which happens later than APT initialization.
|
2018-02-03 12:49:23 +01:00
|
|
|
if (apt->LoadSharedFont()) {
|
|
|
|
apt->shared_font_loaded = true;
|
|
|
|
} else if (apt->LoadLegacySharedFont()) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "Loaded shared font by legacy method");
|
2018-02-03 12:49:23 +01:00
|
|
|
apt->shared_font_loaded = true;
|
2017-08-02 21:56:44 +02:00
|
|
|
} else {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(Service_APT, "shared font file missing - go dump it from your 3ds");
|
2017-08-02 21:56:44 +02:00
|
|
|
rb.Push<u32>(-1); // TODO: Find the right error code
|
2018-02-19 21:30:27 +01:00
|
|
|
rb.Push<u32>(0);
|
|
|
|
rb.PushCopyObjects<Kernel::Object>(nullptr);
|
2018-08-27 16:37:26 +02:00
|
|
|
Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles,
|
|
|
|
"Shared fonts");
|
2017-08-02 21:56:44 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-07-28 21:47:31 +02:00
|
|
|
}
|
|
|
|
|
2016-09-18 02:38:01 +02:00
|
|
|
// The shared font has to be relocated to the new address before being passed to the
|
|
|
|
// application.
|
2018-10-05 16:51:33 +02:00
|
|
|
auto maybe_vaddr =
|
|
|
|
Memory::PhysicalToVirtualAddress(apt->shared_font_mem->linear_heap_phys_address);
|
|
|
|
ASSERT(maybe_vaddr);
|
|
|
|
VAddr target_address = *maybe_vaddr;
|
2018-02-03 12:49:23 +01:00
|
|
|
if (!apt->shared_font_relocated) {
|
|
|
|
BCFNT::RelocateSharedFont(apt->shared_font_mem, target_address);
|
|
|
|
apt->shared_font_relocated = true;
|
2016-04-19 19:13:00 +02:00
|
|
|
}
|
2016-12-28 17:11:14 +01:00
|
|
|
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2016-09-18 02:38:01 +02:00
|
|
|
// Since the SharedMemory interface doesn't provide the address at which the memory was
|
2016-09-19 03:01:46 +02:00
|
|
|
// allocated, the real APT service calculates this address by scanning the entire address space
|
|
|
|
// (using svcQueryMemory) and searches for an allocation of the same size as the Shared Font.
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(target_address);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushCopyObjects(apt->shared_font_mem);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::NotifyToWait(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x43, 1, 0); // 0x430040
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 app_id = rp.Pop<u32>();
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) app_id={}", app_id);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GetLockHandle(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x1, 1, 0); // 0x10040
|
2016-12-28 17:11:14 +01:00
|
|
|
|
2015-07-24 01:52:57 +02:00
|
|
|
// Bits [0:2] are the applet type (System, Library, etc)
|
|
|
|
// Bit 5 tells the application that there's a pending APT parameter,
|
|
|
|
// this will cause the app to wait until parameter_event is signaled.
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 applet_attributes = rp.Pop<u32>();
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(3, 2);
|
2017-07-22 19:33:03 +02:00
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
|
|
|
|
|
|
|
// TODO(Subv): The output attributes should have an AppletPos of either Library or System |
|
|
|
|
// Library (depending on the type of the last launched applet) if the input attributes'
|
|
|
|
// AppletPos has the Library bit set.
|
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(applet_attributes); // Applet Attributes, this value is passed to Enable.
|
2017-02-11 15:07:12 +01:00
|
|
|
rb.Push<u32>(0); // Least significant bit = power button state
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushCopyObjects(apt->lock);
|
2016-12-28 17:11:14 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called applet_attributes={:#010X}", applet_attributes);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::Enable(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x3, 1, 0); // 0x30040
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 attributes = rp.Pop<u32>();
|
2017-07-22 19:33:03 +02:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called attributes={:#010X}", attributes);
|
2017-07-22 19:33:03 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->Enable(attributes));
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GetAppletManInfo(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x5, 1, 0); // 0x50040
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 unk = rp.Pop<u32>();
|
2017-03-19 01:33:56 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2017-02-11 15:07:12 +01:00
|
|
|
rb.Push<u32>(0);
|
|
|
|
rb.Push<u32>(0);
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(static_cast<u32>(AppletId::HomeMenu)); // Home menu AppID
|
|
|
|
rb.Push(static_cast<u32>(AppletId::Application)); // TODO(purpasmart96): Do this correctly
|
2015-02-27 03:13:08 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called unk={:#010X}", unk);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::IsRegistered(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x9, 1, 0); // 0x90040
|
|
|
|
AppletId app_id = rp.PopEnum<AppletId>();
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->IsRegistered(app_id));
|
2016-12-28 17:11:14 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called app_id={:#010X}", static_cast<u32>(app_id));
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::InquireNotification(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0xB, 1, 0); // 0xB0040
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 app_id = rp.Pop<u32>();
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
|
|
|
rb.Push(static_cast<u32>(SignalType::None)); // Signal type
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called app_id={:#010X}", app_id);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::SendParameter(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0xC, 4, 4); // 0xC0104
|
2018-01-25 14:39:54 +01:00
|
|
|
AppletId src_app_id = rp.PopEnum<AppletId>();
|
|
|
|
AppletId dst_app_id = rp.PopEnum<AppletId>();
|
|
|
|
SignalType signal_type = rp.PopEnum<SignalType>();
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 buffer_size = rp.Pop<u32>();
|
2018-02-03 12:49:23 +01:00
|
|
|
Kernel::SharedPtr<Kernel::Object> object = rp.PopGenericObject();
|
|
|
|
std::vector<u8> buffer = rp.PopStaticBuffer();
|
2016-09-18 02:38:01 +02:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT,
|
2018-06-29 15:56:12 +02:00
|
|
|
"called src_app_id={:#010X}, dst_app_id={:#010X}, signal_type={:#010X},"
|
|
|
|
"buffer_size={:#010X}",
|
|
|
|
static_cast<u32>(src_app_id), static_cast<u32>(dst_app_id),
|
|
|
|
static_cast<u32>(signal_type), buffer_size);
|
2017-07-21 22:03:06 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
|
2015-05-26 06:30:20 +02:00
|
|
|
MessageParameter param;
|
|
|
|
param.destination_id = dst_app_id;
|
|
|
|
param.sender_id = src_app_id;
|
2018-02-03 12:49:23 +01:00
|
|
|
param.object = std::move(object);
|
2015-05-26 06:30:20 +02:00
|
|
|
param.signal = signal_type;
|
2018-02-03 12:49:23 +01:00
|
|
|
param.buffer = std::move(buffer);
|
2015-05-26 06:30:20 +02:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->SendParameter(param));
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::ReceiveParameter(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0xD, 2, 0); // 0xD0080
|
2018-01-25 14:39:54 +01:00
|
|
|
AppletId app_id = rp.PopEnum<AppletId>();
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 buffer_size = rp.Pop<u32>();
|
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called app_id={:#010X}, buffer_size={:#010X}", static_cast<u32>(app_id),
|
|
|
|
buffer_size);
|
2017-07-21 22:03:06 +02:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
auto next_parameter = apt->applet_manager->ReceiveParameter(app_id);
|
2017-07-21 20:02:40 +02:00
|
|
|
|
2018-01-25 14:39:54 +01:00
|
|
|
if (next_parameter.Failed()) {
|
2017-07-21 20:02:40 +02:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-01-25 14:39:54 +01:00
|
|
|
rb.Push(next_parameter.Code());
|
2017-07-21 20:02:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(4, 4);
|
2017-07-21 20:01:21 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-01-25 14:39:54 +01:00
|
|
|
rb.PushEnum(next_parameter->sender_id);
|
|
|
|
rb.PushEnum(next_parameter->signal); // Signal type
|
2018-03-27 22:03:00 +02:00
|
|
|
ASSERT_MSG(next_parameter->buffer.size() <= buffer_size, "Input static buffer is too small!");
|
2017-07-21 20:01:21 +02:00
|
|
|
rb.Push(static_cast<u32>(next_parameter->buffer.size())); // Parameter buffer size
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushMoveObjects(next_parameter->object);
|
|
|
|
next_parameter->buffer.resize(buffer_size, 0); // APT always push a buffer with the maximum size
|
|
|
|
rb.PushStaticBuffer(next_parameter->buffer, 0);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GlanceParameter(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0xE, 2, 0); // 0xE0080
|
2018-01-25 14:39:54 +01:00
|
|
|
AppletId app_id = rp.PopEnum<AppletId>();
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 buffer_size = rp.Pop<u32>();
|
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called app_id={:#010X}, buffer_size={:#010X}", static_cast<u32>(app_id),
|
|
|
|
buffer_size);
|
2017-07-21 22:03:06 +02:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
auto next_parameter = apt->applet_manager->GlanceParameter(app_id);
|
2017-07-21 20:02:40 +02:00
|
|
|
|
2018-01-25 14:39:54 +01:00
|
|
|
if (next_parameter.Failed()) {
|
2017-07-21 20:02:40 +02:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-01-25 14:39:54 +01:00
|
|
|
rb.Push(next_parameter.Code());
|
2017-07-21 20:02:40 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(4, 4);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-01-25 14:39:54 +01:00
|
|
|
rb.PushEnum(next_parameter->sender_id);
|
|
|
|
rb.PushEnum(next_parameter->signal); // Signal type
|
2018-03-27 22:03:00 +02:00
|
|
|
ASSERT_MSG(next_parameter->buffer.size() <= buffer_size, "Input static buffer is too small!");
|
2017-07-21 20:01:21 +02:00
|
|
|
rb.Push(static_cast<u32>(next_parameter->buffer.size())); // Parameter buffer size
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushMoveObjects(next_parameter->object);
|
|
|
|
next_parameter->buffer.resize(buffer_size, 0); // APT always push a buffer with the maximum size
|
|
|
|
rb.PushStaticBuffer(next_parameter->buffer, 0);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::CancelParameter(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0xF, 4, 0); // 0xF0100
|
2016-12-28 17:11:14 +01:00
|
|
|
|
2017-07-21 20:09:45 +02:00
|
|
|
bool check_sender = rp.Pop<bool>();
|
2018-01-25 14:39:54 +01:00
|
|
|
AppletId sender_appid = rp.PopEnum<AppletId>();
|
2017-07-21 20:09:45 +02:00
|
|
|
bool check_receiver = rp.Pop<bool>();
|
2018-01-25 14:39:54 +01:00
|
|
|
AppletId receiver_appid = rp.PopEnum<AppletId>();
|
2017-07-21 20:09:45 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
2017-07-21 20:09:45 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->CancelParameter(check_sender, sender_appid, check_receiver,
|
|
|
|
receiver_appid));
|
2016-12-28 17:11:14 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT,
|
2018-06-29 15:56:12 +02:00
|
|
|
"called check_sender={}, sender_appid={:#010X}, "
|
|
|
|
"check_receiver={}, receiver_appid={:#010X}",
|
|
|
|
check_sender, static_cast<u32>(sender_appid), check_receiver,
|
|
|
|
static_cast<u32>(receiver_appid));
|
2015-03-08 02:54:16 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::PrepareToStartApplication(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x15, 5, 0); // 0x00150140
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 title_info1 = rp.Pop<u32>();
|
|
|
|
u32 title_info2 = rp.Pop<u32>();
|
|
|
|
u32 title_info3 = rp.Pop<u32>();
|
|
|
|
u32 title_info4 = rp.Pop<u32>();
|
|
|
|
u32 flags = rp.Pop<u32>();
|
2015-03-08 02:54:16 +01:00
|
|
|
|
2016-04-20 12:12:05 +02:00
|
|
|
if (flags & 0x00000100) {
|
2018-02-03 12:49:23 +01:00
|
|
|
apt->unknown_ns_state_field = 1;
|
2016-04-20 12:12:05 +02:00
|
|
|
}
|
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2015-03-08 02:54:16 +01:00
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_WARNING(Service_APT,
|
|
|
|
"(STUBBED) called title_info1={:#010X}, title_info2={:#010X}, title_info3={:#010X},"
|
|
|
|
"title_info4={:#010X}, flags={:#010X}",
|
|
|
|
title_info1, title_info2, title_info3, title_info4, flags);
|
2015-03-08 02:54:16 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::StartApplication(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x1B, 3, 4); // 0x001B00C4
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 buffer1_size = rp.Pop<u32>();
|
|
|
|
u32 buffer2_size = rp.Pop<u32>();
|
|
|
|
u32 flag = rp.Pop<u32>();
|
2018-02-03 12:49:23 +01:00
|
|
|
std::vector<u8> buffer1 = rp.PopStaticBuffer();
|
|
|
|
std::vector<u8> buffer2 = rp.PopStaticBuffer();
|
2015-03-08 02:54:16 +01:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2015-03-08 02:54:16 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT,
|
2018-06-29 15:56:12 +02:00
|
|
|
"(STUBBED) called buffer1_size={:#010X}, buffer2_size={:#010X}, flag={:#010X}",
|
|
|
|
buffer1_size, buffer2_size, flag);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::AppletUtility(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x4B, 3, 2); // 0x004B00C2
|
2015-02-27 03:13:08 +01:00
|
|
|
|
|
|
|
// These are from 3dbrew - I'm not really sure what they're used for.
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 utility_command = rp.Pop<u32>();
|
|
|
|
u32 input_size = rp.Pop<u32>();
|
|
|
|
u32 output_size = rp.Pop<u32>();
|
2018-02-03 12:49:23 +01:00
|
|
|
std::vector<u8> input = rp.PopStaticBuffer();
|
2016-12-28 17:11:14 +01:00
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2015-02-27 03:13:08 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT,
|
2018-06-29 15:56:12 +02:00
|
|
|
"(STUBBED) called command={:#010X}, input_size={:#010X}, output_size={:#010X}",
|
|
|
|
utility_command, input_size, output_size);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::SetAppCpuTimeLimit(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x4F, 2, 0); // 0x4F0080
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 value = rp.Pop<u32>();
|
2018-02-03 12:49:23 +01:00
|
|
|
apt->cpu_percent = rp.Pop<u32>();
|
2015-02-27 03:13:08 +01:00
|
|
|
|
|
|
|
if (value != 1) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(Service_APT, "This value should be one, but is actually {}!", value);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2015-02-27 03:13:08 +01:00
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called, cpu_percent={}, value={}", apt->cpu_percent, value);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GetAppCpuTimeLimit(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x50, 1, 0); // 0x500040
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 value = rp.Pop<u32>();
|
2015-02-27 03:13:08 +01:00
|
|
|
|
|
|
|
if (value != 1) {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(Service_APT, "This value should be one, but is actually {}!", value);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->cpu_percent);
|
2015-02-27 03:13:08 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called, value={}", value);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::PrepareToStartLibraryApplet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x18, 1, 0); // 0x180040
|
|
|
|
AppletId applet_id = rp.PopEnum<AppletId>();
|
2016-12-28 17:11:14 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called, applet_id={:08X}", static_cast<u32>(applet_id));
|
2017-09-25 02:09:13 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->PrepareToStartLibraryApplet(applet_id));
|
2015-07-24 04:09:43 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::PrepareToStartNewestHomeMenu(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x1A, 0, 0); // 0x1A0000
|
2017-09-23 21:01:04 +02:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
|
|
|
|
// TODO(Subv): This command can only be called by a System Applet (return 0xC8A0CC04 otherwise).
|
|
|
|
|
|
|
|
// This command must return an error when called, otherwise the Home Menu will try to reboot the
|
|
|
|
// system.
|
|
|
|
rb.Push(ResultCode(ErrorDescription::AlreadyExists, ErrorModule::Applet,
|
|
|
|
ErrorSummary::InvalidState, ErrorLevel::Status));
|
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called");
|
2017-09-23 21:01:04 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::PreloadLibraryApplet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x16, 1, 0); // 0x160040
|
|
|
|
AppletId applet_id = rp.PopEnum<AppletId>();
|
2016-12-28 17:11:14 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called, applet_id={:08X}", static_cast<u32>(applet_id));
|
2017-09-25 02:09:13 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->PreloadLibraryApplet(applet_id));
|
2015-05-26 06:30:20 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::FinishPreloadingLibraryApplet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x17, 1, 0); // 0x00170040
|
|
|
|
AppletId applet_id = rp.PopEnum<AppletId>();
|
2017-12-11 02:01:11 +01:00
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->FinishPreloadingLibraryApplet(applet_id));
|
2017-12-11 02:01:11 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called, applet_id={:#05X}", static_cast<u32>(applet_id));
|
2017-12-11 02:01:11 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::StartLibraryApplet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x1E, 2, 4); // 0x1E0084
|
|
|
|
AppletId applet_id = rp.PopEnum<AppletId>();
|
2015-05-26 06:30:20 +02:00
|
|
|
|
2018-09-06 22:03:28 +02:00
|
|
|
std::size_t buffer_size = rp.Pop<u32>();
|
2018-02-03 12:49:23 +01:00
|
|
|
Kernel::SharedPtr<Kernel::Object> object = rp.PopGenericObject();
|
|
|
|
std::vector<u8> buffer = rp.PopStaticBuffer();
|
2016-04-16 12:18:49 +02:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called, applet_id={:08X}", static_cast<u32>(applet_id));
|
2015-05-26 06:30:20 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(apt->applet_manager->StartLibraryApplet(applet_id, object, buffer));
|
2015-05-26 06:30:20 +02:00
|
|
|
}
|
|
|
|
|
2018-07-18 14:07:00 +02:00
|
|
|
void Module::Interface::CloseApplication(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x27, 1, 4);
|
|
|
|
u32 parameters_size = rp.Pop<u32>();
|
|
|
|
Kernel::SharedPtr<Kernel::Object> object = rp.PopGenericObject();
|
|
|
|
std::vector<u8> buffer = rp.PopStaticBuffer();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_APT, "called");
|
|
|
|
|
|
|
|
Core::System::GetInstance().RequestShutdown();
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::Interface::PrepareToDoApplicationJump(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x31, 4, 0);
|
|
|
|
u32 flags = rp.Pop<u8>();
|
|
|
|
u32 program_id_low = rp.Pop<u32>();
|
|
|
|
u32 program_id_high = rp.Pop<u32>();
|
|
|
|
Service::FS::MediaType media_type = static_cast<Service::FS::MediaType>(rp.Pop<u8>());
|
|
|
|
|
|
|
|
LOG_WARNING(Service_APT,
|
|
|
|
"(STUBBED) called, flags={:08X}, program_id_low={:08X}, program_id_high={:08X}, "
|
|
|
|
"media_type={:08X}",
|
|
|
|
flags, program_id_low, program_id_high, static_cast<u8>(media_type));
|
|
|
|
|
|
|
|
if (flags == 0x2) {
|
|
|
|
// It seems that flags 0x2 means jumping to the same application,
|
|
|
|
// and ignore the parameters. This is used in Pokemon main series
|
|
|
|
// to soft reset.
|
|
|
|
application_reset_prepared = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::Interface::DoApplicationJump(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x32, 2, 4);
|
|
|
|
u32 parameter_size = rp.Pop<u32>();
|
|
|
|
u32 hmac_size = rp.Pop<u32>();
|
|
|
|
std::vector<u8> parameter = rp.PopStaticBuffer();
|
|
|
|
std::vector<u8> hmac = rp.PopStaticBuffer();
|
|
|
|
|
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called");
|
|
|
|
|
|
|
|
if (application_reset_prepared) {
|
|
|
|
// Reset system
|
|
|
|
Core::System::GetInstance().RequestReset();
|
|
|
|
} else {
|
|
|
|
// After the jump, the application should shutdown
|
|
|
|
// TODO: Actually implement the jump
|
|
|
|
Core::System::GetInstance().RequestShutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::CancelLibraryApplet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x3B, 1, 0); // 0x003B0040
|
2017-02-11 15:07:12 +01:00
|
|
|
bool exiting = rp.Pop<bool>();
|
2016-11-24 04:57:56 +01:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
2017-03-19 01:33:56 +01:00
|
|
|
rb.Push<u32>(1); // TODO: Find the return code meaning
|
2016-11-24 04:57:56 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called exiting={}", exiting);
|
2016-11-24 04:57:56 +01:00
|
|
|
}
|
|
|
|
|
2018-07-24 17:13:40 +02:00
|
|
|
void Module::Interface::PrepareToCloseLibraryApplet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x25, 3, 0); // 0x002500C0
|
|
|
|
bool not_pause = rp.Pop<bool>();
|
|
|
|
bool exiting = rp.Pop<bool>();
|
|
|
|
bool jump_to_home = rp.Pop<bool>();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_APT, "called not_pause={} exiting={} jump_to_home={}", not_pause, exiting,
|
|
|
|
jump_to_home);
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(apt->applet_manager->PrepareToCloseLibraryApplet(not_pause, exiting, jump_to_home));
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::Interface::CloseLibraryApplet(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x28, 1, 4); // 0x00280044
|
|
|
|
u32 parameter_size = rp.Pop<u32>();
|
|
|
|
auto object = rp.PopGenericObject();
|
|
|
|
std::vector<u8> buffer = rp.PopStaticBuffer();
|
|
|
|
|
|
|
|
LOG_DEBUG(Service_APT, "called size={}", parameter_size);
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(apt->applet_manager->CloseLibraryApplet(std::move(object), std::move(buffer)));
|
|
|
|
}
|
|
|
|
|
2018-03-04 12:25:33 +01:00
|
|
|
void Module::Interface::SendCaptureBufferInfo(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x40, 1, 2); // 0x00400042
|
|
|
|
u32 size = rp.Pop<u32>();
|
|
|
|
ASSERT(size == 0x20);
|
|
|
|
apt->screen_capture_buffer = rp.PopStaticBuffer();
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Module::Interface::ReceiveCaptureBufferInfo(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x41, 1, 0); // 0x00410040
|
|
|
|
u32 size = rp.Pop<u32>();
|
|
|
|
ASSERT(size == 0x20);
|
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
rb.Push(static_cast<u32>(apt->screen_capture_buffer.size()));
|
|
|
|
rb.PushStaticBuffer(std::move(apt->screen_capture_buffer), 0);
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::SetScreenCapPostPermission(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x55, 1, 0); // 0x00550040
|
2016-04-20 12:12:05 +02:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
apt->screen_capture_post_permission = static_cast<ScreencapPostPermission>(rp.Pop<u32>() & 0xF);
|
2016-04-20 12:12:05 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called, screen_capture_post_permission={}",
|
2018-06-29 15:56:12 +02:00
|
|
|
static_cast<u32>(apt->screen_capture_post_permission));
|
2016-04-20 12:12:05 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GetScreenCapPostPermission(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x56, 0, 0); // 0x00560000
|
2016-04-20 12:12:05 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS); // No error
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.Push(static_cast<u32>(apt->screen_capture_post_permission));
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called, screen_capture_post_permission={}",
|
2018-06-29 15:56:12 +02:00
|
|
|
static_cast<u32>(apt->screen_capture_post_permission));
|
2016-04-20 12:12:05 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GetAppletInfo(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x6, 1, 0); // 0x60040
|
|
|
|
auto app_id = rp.PopEnum<AppletId>();
|
2015-12-04 22:05:23 +01:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called, app_id={}", static_cast<u32>(app_id));
|
2017-12-11 02:09:03 +01:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
auto info = apt->applet_manager->GetAppletInfo(app_id);
|
2018-01-25 14:39:54 +01:00
|
|
|
if (info.Failed()) {
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
|
|
|
|
rb.Push(info.Code());
|
|
|
|
} else {
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(7, 0);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
2018-01-25 14:39:54 +01:00
|
|
|
rb.Push(info->title_id);
|
|
|
|
rb.Push(static_cast<u8>(info->media_type));
|
|
|
|
rb.Push(info->registered);
|
|
|
|
rb.Push(info->loaded);
|
|
|
|
rb.Push(info->attributes);
|
2015-12-04 22:05:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::GetStartupArgument(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x51, 2, 0); // 0x00510080
|
2016-12-28 17:11:14 +01:00
|
|
|
u32 parameter_size = rp.Pop<u32>();
|
2017-03-19 01:33:56 +01:00
|
|
|
StartupArgumentType startup_argument_type = static_cast<StartupArgumentType>(rp.Pop<u8>());
|
2016-03-28 23:25:05 +02:00
|
|
|
|
2018-07-07 18:52:27 +02:00
|
|
|
const u32 max_parameter_size{0x1000};
|
|
|
|
|
|
|
|
if (parameter_size > max_parameter_size) {
|
|
|
|
LOG_ERROR(Service_APT,
|
|
|
|
"Parameter size is outside the valid range (capped to {:#010X}): "
|
|
|
|
"parameter_size={:#010X}",
|
|
|
|
max_parameter_size, parameter_size);
|
2018-07-11 09:00:05 +02:00
|
|
|
parameter_size = max_parameter_size;
|
2016-03-28 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
std::vector<u8> parameter(parameter_size, 0);
|
2016-11-02 19:48:10 +01:00
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called, startup_argument_type={}, parameter_size={:#010X}",
|
|
|
|
static_cast<u32>(startup_argument_type), parameter_size);
|
2016-03-28 23:25:05 +02:00
|
|
|
|
2017-03-18 11:47:40 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2017-02-11 15:07:12 +01:00
|
|
|
rb.Push<u32>(0);
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushStaticBuffer(parameter, 0);
|
2016-03-28 23:25:05 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::Wrap(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x46, 4, 4);
|
2017-01-01 13:58:24 +01:00
|
|
|
const u32 output_size = rp.Pop<u32>();
|
|
|
|
const u32 input_size = rp.Pop<u32>();
|
|
|
|
const u32 nonce_offset = rp.Pop<u32>();
|
|
|
|
u32 nonce_size = rp.Pop<u32>();
|
2018-02-03 12:49:23 +01:00
|
|
|
auto& input = rp.PopMappedBuffer();
|
|
|
|
ASSERT(input.GetSize() == input_size);
|
|
|
|
auto& output = rp.PopMappedBuffer();
|
|
|
|
ASSERT(output.GetSize() == output_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
|
|
|
// Note: real 3DS still returns SUCCESS when the sizes don't match. It seems that it doesn't
|
|
|
|
// check the buffer size and writes data with potential overflow.
|
|
|
|
ASSERT_MSG(output_size == input_size + HW::AES::CCM_MAC_SIZE,
|
2018-03-27 17:28:42 +02:00
|
|
|
"input_size ({}) doesn't match to output_size ({})", input_size, output_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called, output_size={}, input_size={}, nonce_offset={}, nonce_size={}",
|
|
|
|
output_size, input_size, nonce_offset, nonce_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
|
|
|
// Note: This weird nonce size modification is verified against real 3DS
|
|
|
|
nonce_size = std::min<u32>(nonce_size & ~3, HW::AES::CCM_NONCE_SIZE);
|
|
|
|
|
|
|
|
// Reads nonce and concatenates the rest of the input as plaintext
|
|
|
|
HW::AES::CCMNonce nonce{};
|
2018-02-03 12:49:23 +01:00
|
|
|
input.Read(nonce.data(), nonce_offset, nonce_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
u32 pdata_size = input_size - nonce_size;
|
|
|
|
std::vector<u8> pdata(pdata_size);
|
2018-02-03 12:49:23 +01:00
|
|
|
input.Read(pdata.data(), 0, nonce_offset);
|
|
|
|
input.Read(pdata.data() + nonce_offset, nonce_offset + nonce_size, pdata_size - nonce_offset);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
|
|
|
// Encrypts the plaintext using AES-CCM
|
|
|
|
auto cipher = HW::AES::EncryptSignCCM(pdata, nonce, HW::AES::KeySlotID::APTWrap);
|
|
|
|
|
|
|
|
// Puts the nonce to the beginning of the output, with ciphertext followed
|
2018-02-03 12:49:23 +01:00
|
|
|
output.Write(nonce.data(), 0, nonce_size);
|
|
|
|
output.Write(cipher.data(), nonce_size, cipher.size());
|
2017-01-01 13:58:24 +01:00
|
|
|
|
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 4);
|
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
|
|
|
|
// Unmap buffer
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushMappedBuffer(input);
|
|
|
|
rb.PushMappedBuffer(output);
|
2017-01-01 13:58:24 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::Unwrap(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x47, 4, 4);
|
2017-01-01 13:58:24 +01:00
|
|
|
const u32 output_size = rp.Pop<u32>();
|
|
|
|
const u32 input_size = rp.Pop<u32>();
|
|
|
|
const u32 nonce_offset = rp.Pop<u32>();
|
|
|
|
u32 nonce_size = rp.Pop<u32>();
|
2018-02-03 12:49:23 +01:00
|
|
|
auto& input = rp.PopMappedBuffer();
|
|
|
|
ASSERT(input.GetSize() == input_size);
|
|
|
|
auto& output = rp.PopMappedBuffer();
|
|
|
|
ASSERT(output.GetSize() == output_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
|
|
|
// Note: real 3DS still returns SUCCESS when the sizes don't match. It seems that it doesn't
|
|
|
|
// check the buffer size and writes data with potential overflow.
|
|
|
|
ASSERT_MSG(output_size == input_size - HW::AES::CCM_MAC_SIZE,
|
2018-03-27 17:28:42 +02:00
|
|
|
"input_size ({}) doesn't match to output_size ({})", input_size, output_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
2018-06-29 15:56:12 +02:00
|
|
|
LOG_DEBUG(Service_APT, "called, output_size={}, input_size={}, nonce_offset={}, nonce_size={}",
|
|
|
|
output_size, input_size, nonce_offset, nonce_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
|
|
|
// Note: This weird nonce size modification is verified against real 3DS
|
|
|
|
nonce_size = std::min<u32>(nonce_size & ~3, HW::AES::CCM_NONCE_SIZE);
|
|
|
|
|
|
|
|
// Reads nonce and cipher text
|
|
|
|
HW::AES::CCMNonce nonce{};
|
2018-02-03 12:49:23 +01:00
|
|
|
input.Read(nonce.data(), 0, nonce_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
u32 cipher_size = input_size - nonce_size;
|
|
|
|
std::vector<u8> cipher(cipher_size);
|
2018-02-03 12:49:23 +01:00
|
|
|
input.Read(cipher.data(), nonce_size, cipher_size);
|
2017-01-01 13:58:24 +01:00
|
|
|
|
|
|
|
// Decrypts the ciphertext using AES-CCM
|
|
|
|
auto pdata = HW::AES::DecryptVerifyCCM(cipher, nonce, HW::AES::KeySlotID::APTWrap);
|
|
|
|
|
2017-03-18 10:45:19 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(1, 4);
|
2017-01-01 13:58:24 +01:00
|
|
|
if (!pdata.empty()) {
|
|
|
|
// Splits the plaintext and put the nonce in between
|
2018-02-03 12:49:23 +01:00
|
|
|
output.Write(pdata.data(), 0, nonce_offset);
|
|
|
|
output.Write(nonce.data(), nonce_offset, nonce_size);
|
|
|
|
output.Write(pdata.data() + nonce_offset, nonce_offset + nonce_size,
|
|
|
|
pdata.size() - nonce_offset);
|
2017-01-01 13:58:24 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
|
|
|
} else {
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_ERROR(Service_APT, "Failed to decrypt data");
|
2017-01-01 13:58:24 +01:00
|
|
|
rb.Push(ResultCode(static_cast<ErrorDescription>(1), ErrorModule::PS,
|
|
|
|
ErrorSummary::WrongArgument, ErrorLevel::Status));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unmap buffer
|
2018-02-03 12:49:23 +01:00
|
|
|
rb.PushMappedBuffer(input);
|
|
|
|
rb.PushMappedBuffer(output);
|
2017-01-01 13:58:24 +01:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::CheckNew3DSApp(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x101, 0, 0); // 0x01010000
|
2016-04-20 12:12:05 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
2018-02-03 12:49:23 +01:00
|
|
|
if (apt->unknown_ns_state_field) {
|
2016-12-28 17:11:14 +01:00
|
|
|
rb.Push(RESULT_SUCCESS);
|
2017-02-11 15:07:12 +01:00
|
|
|
rb.Push<u32>(0);
|
2016-04-20 12:12:05 +02:00
|
|
|
} else {
|
2016-12-28 17:11:14 +01:00
|
|
|
PTM::CheckNew3DS(rb);
|
2016-04-20 12:12:05 +02:00
|
|
|
}
|
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called");
|
2016-04-20 12:12:05 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void Module::Interface::CheckNew3DS(Kernel::HLERequestContext& ctx) {
|
|
|
|
IPC::RequestParser rp(ctx, 0x102, 0, 0); // 0x01020000
|
2016-12-28 17:11:14 +01:00
|
|
|
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
|
2016-04-20 12:12:05 +02:00
|
|
|
|
2016-12-28 17:11:14 +01:00
|
|
|
PTM::CheckNew3DS(rb);
|
2016-04-20 12:12:05 +02:00
|
|
|
|
2018-06-29 13:18:07 +02:00
|
|
|
LOG_WARNING(Service_APT, "(STUBBED) called");
|
2016-04-20 12:12:05 +02:00
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
Module::Interface::Interface(std::shared_ptr<Module> apt, const char* name, u32 max_session)
|
|
|
|
: ServiceFramework(name, max_session), apt(std::move(apt)) {}
|
|
|
|
|
|
|
|
Module::Interface::~Interface() = default;
|
2017-06-15 18:09:05 +02:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
Module::Module() {
|
2018-01-25 14:39:54 +01:00
|
|
|
applet_manager = std::make_shared<AppletManager>();
|
2017-06-15 18:09:05 +02:00
|
|
|
|
|
|
|
using Kernel::MemoryPermission;
|
|
|
|
shared_font_mem =
|
|
|
|
Kernel::SharedMemory::Create(nullptr, 0x332000, // 3272 KB
|
|
|
|
MemoryPermission::ReadWrite, MemoryPermission::Read, 0,
|
|
|
|
Kernel::MemoryRegion::SYSTEM, "APT:SharedFont");
|
|
|
|
|
2015-02-27 03:13:08 +01:00
|
|
|
lock = Kernel::Mutex::Create(false, "APT_U:Lock");
|
|
|
|
}
|
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
Module::~Module() {}
|
2017-07-22 19:33:03 +02:00
|
|
|
|
2018-02-03 12:49:23 +01:00
|
|
|
void InstallInterfaces(SM::ServiceManager& service_manager) {
|
|
|
|
auto apt = std::make_shared<Module>();
|
|
|
|
std::make_shared<APT_U>(apt)->InstallAsService(service_manager);
|
|
|
|
std::make_shared<APT_S>(apt)->InstallAsService(service_manager);
|
|
|
|
std::make_shared<APT_A>(apt)->InstallAsService(service_manager);
|
2015-02-27 03:13:08 +01:00
|
|
|
}
|
|
|
|
|
2018-09-22 14:23:08 +02:00
|
|
|
} // namespace Service::APT
|