Squashed commit of the following:

commit c6f34babb7
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 17:04:37 2024 +0200

    Undo unnecessary change to nwm_uds.cpp

commit 219cc83c41
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 16:46:11 2024 +0200

    Fixed remaining coding style errors

commit 5f00bb04c7
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 16:43:42 2024 +0200

    Removed log messages

commit d469c6b583
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 16:42:49 2024 +0200

    Fixed coding style errors

commit 60f7dbd4f8
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 15:18:03 2024 +0200

    Potential fix for wrongly storing mac

commit 1ac5500fff
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 14:58:57 2024 +0200

    Fixed format error

commit c2d1819609
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 14:50:22 2024 +0200

    Truly fixed log message this time

commit a36d12d3f4
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 14:44:44 2024 +0200

    Fixed log message error

commit c00705f9a4
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 14:34:38 2024 +0200

    Added log message for checking MAC address

commit c4f6bffd91
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 14:31:31 2024 +0200

    Added forgotten log message

commit d461a44e8b
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 14:14:59 2024 +0200

    Added assert statement as sanity check

commit c24b0c2e88
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 14:14:47 2024 +0200

    Added temp loggers for tracking where error occurs

commit 923d1d30da
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 13:42:39 2024 +0200

    Removed now-redundant log messages and updated comments

commit 471efa4c8c
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 12:42:23 2024 +0200

    Changed retrieval of values to be dependent on VAddr instead of pointer

commit dd16c0b6a0
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 00:48:49 2024 +0200

    Added extra log messages for debugging

commit 97c856b2b5
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 00:22:23 2024 +0200

    Fixed casting error

commit 1dd28eedc5
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 00:13:26 2024 +0200

    Fixed missing call to Kernel()

commit 40ca69fafd
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Sat Aug 24 00:01:21 2024 +0200

    Fixed MemorySystem retrieval

commit bb08716752
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 23:57:24 2024 +0200

    Fixed lingering remnant of old value

commit d76311bb1b
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 23:56:44 2024 +0200

    Fixed missing argument

commit 01655fbbb0
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 23:44:16 2024 +0200

    Added retrieval of VAddr from input

commit 3f76dd3678
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 23:42:49 2024 +0200

    Revert independency of UDS

commit 28021f5578
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 23:06:37 2024 +0200

    Fixed NWM_INF implementation reference to NWM_UDS method

commit ca85f92e0e
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 23:06:21 2024 +0200

    Fixed debug log message

commit a061a3dcec
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 22:14:36 2024 +0200

    Updated include statements

commit 2fd28a883d
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 21:51:02 2024 +0200

    Removed dependency on NWM_UDS

commit b5d616bbed
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 21:17:13 2024 +0200

    Fixed wrong dummy data

commit 60ee7abc38
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 20:56:11 2024 +0200

    Potential fix of cmd buffer header

commit e47d9af750
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 19:54:04 2024 +0200

    Additional logging

commit d5d0301702
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 19:36:55 2024 +0200

    Added temp logging for debugging

commit a41fc80eab
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 18:59:48 2024 +0200

    Fixed use of mapped buffer

commit f88ebb65a3
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 18:51:48 2024 +0200

    Reverted 4th value to unknown

commit b1d1757eaa
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 17:26:24 2024 +0200

    Updated includes

commit 60c453b5bb
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 17:21:11 2024 +0200

    Fixed argument

commit b7777a7b47
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 17:00:49 2024 +0200

    Added include

commit 4b3ac391d8
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 16:53:56 2024 +0200

    Fixed wrong arguments

commit 13f32bd384
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 16:33:54 2024 +0200

    Fixed call return value

commit 826d6bed2d
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 16:32:37 2024 +0200

    Changed implementation to rely on parser instead of raw

commit 5dea8a125b
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 16:00:35 2024 +0200

    Moved kernel retrieval to argument

commit bb4de89652
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:50:37 2024 +0200

    Fixed method call

commit 8b9e04c541
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:48:58 2024 +0200

    Fixed type name

commit 29fc438086
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:41:35 2024 +0200

    Fixed includes

commit a6fe44f81f
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:41:29 2024 +0200

    Fixed method name

commit 67380edbc9
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:41:09 2024 +0200

    Fixed method call

commit babec1bb5c
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:34:32 2024 +0200

    Fixed kernel reference

commit 6238f52819
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:30:10 2024 +0200

    Fixed missing namespace

commit c4a99ccbe9
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:29:29 2024 +0200

    Fixed missing argument

commit 916849691b
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:26:39 2024 +0200

    Fixed wrong mac

commit 7a997ea8ae
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:19:13 2024 +0200

    Potentially fixed calling NWM_INF

commit 320a82bb5d
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 15:05:24 2024 +0200

    Potential fix for calling NWM_UDS version

commit 0b0534400d
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 13:56:05 2024 +0200

    Added include for NWM_UDS

commit d61dfdaf2e
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 13:51:03 2024 +0200

    Fixed cast to u32 and dummy value

commit a14e398157
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 13:50:17 2024 +0200

    Added correct transition from INF to UDS

commit 54e4da1753
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 13:30:13 2024 +0200

    Initial full ScanAPs implementation

commit aeb1e224f3
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 13:18:17 2024 +0200

    Fixed member reference

commit c3b1beae1c
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 13:11:30 2024 +0200

    Readded NWM_UDS header

commit 6b03ca58a2
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 12:44:40 2024 +0200

    Updated include statements

commit 36c4adf431
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 00:58:25 2024 +0200

    Potential member reference fix

commit 6d28737856
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 00:48:51 2024 +0200

    Fixed missing void return type

commit 14eb312678
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Fri Aug 23 00:14:41 2024 +0200

    Using correct way to call UDS service

commit 2acc2a35a9
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Thu Aug 22 22:39:15 2024 +0200

    Updated API

commit d204bfa05c
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Thu Aug 22 22:38:49 2024 +0200

    Initial NWM_INF::RecvBeaconBroadcastData implementation

commit 01baadf7a4
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Thu Aug 22 19:23:17 2024 +0200

    Included member type

commit 36f416469f
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Thu Aug 22 19:06:52 2024 +0200

    Coding style fixes

commit 4e73a1d057
Author: PTRCoder <pj.de.bruijne@gmail.com>
Date:   Thu Aug 22 19:02:37 2024 +0200

    Starting tests
This commit is contained in:
PTRCoder 2024-08-24 20:07:04 +02:00
parent c89cdb597d
commit f182ea3f2c
2 changed files with 42 additions and 45 deletions

View File

@ -24,6 +24,8 @@
#include "network/network.h"
#include "network/room.h"
#include "core/memory.h"
#include "network/network.h"
#include "network/room.h"
SERIALIZE_EXPORT_IMPL(Service::AC::Module)
SERVICE_CONSTRUCT_IMPL(Service::AC::Module)
@ -192,65 +194,62 @@ void Module::Interface::ScanAPs(Kernel::HLERequestContext& ctx) {
// Arg 0 is Header code, which is ignored
// Arg 1 is Size
const u32 size = rp.Pop<u32>();
LOG_WARNING(Service_AC, "Size: {}", size);
// Arg 2 is CallingPID value (PID Header)
// Arg 3 is PID
const u32 pid = rp.PopPID();
LOG_WARNING(Service_AC, "PID: {}", pid);
std::shared_ptr<Kernel::Thread> thread = ctx.ClientThread();
auto current_process = Core::System::GetInstance().Kernel().GetCurrentProcess();
Memory::MemorySystem& memory = Core::System::GetInstance().Memory();
LOG_WARNING(Service_AC, "Retrieved thread, process and memory");
// According to 3dbrew, the output structure pointer is located 0x100 bytes after the beginning
// of cmd_buff
VAddr cmd_addr = thread->GetCommandBufferAddress();
VAddr buffer_vaddr = cmd_addr + 0x100;
const u32 descr = memory.Read32(buffer_vaddr);
LOG_WARNING(Service_AC, "Buffer descriptor: 0x{:08X}, expected: 0x{:08X}", descr, (size << 14) | 2);
ASSERT(descr == ((size << 14) | 2)); // preliminary check
ASSERT(descr == ((size << 14) | 2)); // preliminary check
const VAddr output_buffer = memory.Read32(buffer_vaddr + 0x4); // address to output buffer
LOG_WARNING(Service_AC, "Buffer VAddr: 0x{:08X}", output_buffer);
// At this point, we have all the input given to us
// 3dbrew stated that AC:ScanAPs relies on NWM_INF:RecvBeaconBroadcastData to obtain
// info on all nearby APs
// Thus this method prepares to call that service
// Since I do not know the proper way, I copied various pieces of code that seemed to work
// MAC address gets split, but I am not sure this is the proper way to do so
Network::MacAddress mac = Network::BroadcastMac;
u32 mac1 = (mac[0] << 8) | (mac[1]);
u32 mac2 = (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | (mac[5]);
std::array<u32, IPC::COMMAND_BUFFER_LENGTH + 2 * IPC::MAX_STATIC_BUFFERS> cmd_buf;
cmd_buf[0] = 0x000603C4;
cmd_buf[1] = size;
cmd_buf[2] = 0; // dummy data
cmd_buf[3] = 0; // dummy data
cmd_buf[4] = mac1;
cmd_buf[5] = mac2;
cmd_buf[16] = 0;
cmd_buf[17] = 0; // set to 0 to ignore it
cmd_buf[0] = 0x000603C4; // Command header
cmd_buf[1] = size; // size of buffer
cmd_buf[2] = 0; // dummy data
cmd_buf[3] = 0; // dummy data
std::memcpy(cmd_buf.data() + 4, mac.data(), sizeof(Network::MacAddress));
cmd_buf[16] = 0; // 0x0 handle header
cmd_buf[17] = 0; // set to 0 to ignore it
cmd_buf[18] = (size << 4) | 12; // should be considered correct for mapped buffer
cmd_buf[19] = output_buffer;
cmd_buf[19] = output_buffer; // address of output buffer
LOG_WARNING(Service_AC, "Finished setting up command buffer");
auto context =
std::make_shared<Kernel::HLERequestContext>(Core::System::GetInstance().Kernel(),
ctx.Session(), thread);
LOG_WARNING(Service_AC, "Created context");
// Create context for call to NWM_INF::RecvBeaconBroadcastData
auto context = std::make_shared<Kernel::HLERequestContext>(Core::System::GetInstance().Kernel(),
ctx.Session(), thread);
context->PopulateFromIncomingCommandBuffer(cmd_buf.data(), current_process);
LOG_WARNING(Service_AC, "Finished setting up context");
auto nwm_inf =
Core::System::GetInstance().ServiceManager().GetService<Service::NWM::NWM_INF>("nwm::INF");
LOG_WARNING(Service_AC, "Calling NWM_INF::RecvBeaconBroadcastData");
// Retrieve service from service manager
auto nwm_inf =
Core::System::GetInstance().ServiceManager().GetService<Service::NWM::NWM_INF>("nwm::INF");
// Perform delegated task
nwm_inf->HandleSyncRequest(*context);
LOG_WARNING(Service_AC, "Returned to AC::ScanAPs");
// Response should be
// 0: Header Code (ignored)
// 1: Result Code (Success/Unknown/etc.)
// 2: ¿Parsed? beacon data
// Since the way to parse is yet unknown, it is currently only passing on raw
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
IPC::RequestParser rp2(*context);
rb.Push(rp2.Pop<u32>());
// Mapped buffer at virtual address output_buffer
Kernel::MappedBuffer mapped_buffer = rp2.PopMappedBuffer();
rb.PushMappedBuffer(mapped_buffer);
LOG_WARNING(Service_AC, "(STUBBED) called, pid={}", pid);

View File

@ -21,9 +21,12 @@ namespace Service::NWM {
void NWM_INF::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
LOG_WARNING(Service_NWM, "Started NWM_INF::RecvBeaconBroadcastData");
// Using a standalone implementation requires copying private methods as well
// I am not sure if that should be done
// adding in extra context value for transition from INF to UDS
// Replacing header,
// adding in extra context value
// and replacing dummy value with 2 dummy id's
std::array<u32, IPC::COMMAND_BUFFER_LENGTH + 2 * IPC::MAX_STATIC_BUFFERS> cmd_buf;
cmd_buf[0] = 0x000F0404;
int i;
@ -31,33 +34,28 @@ void NWM_INF::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) {
cmd_buf[i] = rp.Pop<u32>();
}
rp.Pop<u32>();
cmd_buf[15] = 0; // dummy wlan_comm_id
cmd_buf[16] = 0; // dummy id
cmd_buf[15] = 0; // dummy wlan_comm_id
cmd_buf[16] = 0; // dummy id
for (i = 17; i <= 20; i++) {
cmd_buf[i] = rp.Pop<u32>();
}
// Prepare for call to NWM_UDS
std::shared_ptr<Kernel::Thread> thread = ctx.ClientThread();
auto current_process = thread->owner_process.lock();
auto context =
std::make_shared<Kernel::HLERequestContext>(Core::System::GetInstance().Kernel(),
ctx.Session(), thread);
auto context = std::make_shared<Kernel::HLERequestContext>(Core::System::GetInstance().Kernel(),
ctx.Session(), thread);
context->PopulateFromIncomingCommandBuffer(cmd_buf.data(), current_process);
LOG_WARNING(Service_NWM, "Finished converting context");
auto nwm_uds = Core::System::GetInstance().ServiceManager().GetService<Service::NWM::NWM_UDS>("nwm::UDS");
LOG_WARNING(Service_NWM, "Calling NWM_UDS::RecvBeaconBroadcastData");
auto nwm_uds =
Core::System::GetInstance().ServiceManager().GetService<Service::NWM::NWM_UDS>("nwm::UDS");
nwm_uds->HandleSyncRequest(*context);
LOG_WARNING(Service_NWM, "Returned to NWM_INF::RecvBeaconBroadcastData");
// Push results of delegated call to caller
IPC::RequestParser rp2(*context);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(rp2.Pop<u32>());
rb.PushMappedBuffer(rp2.PopMappedBuffer());
LOG_WARNING(Service_NWM, "Finished NWM_INF::RecvBeaconBroadcastData");
}
NWM_INF::NWM_INF() : ServiceFramework("nwm::INF") {