From 4e6e3d3abebfdde3b655c421cc4b849b0a7f5012 Mon Sep 17 00:00:00 2001 From: PTRCoder Date: Sat, 24 Aug 2024 20:03:24 +0200 Subject: [PATCH] Squashed commit of the following: commit b5d616bbed73eee08d0e66af045892e2c63eb5ff Author: PTRCoder Date: Fri Aug 23 21:17:13 2024 +0200 Fixed wrong dummy data commit 60ee7abc385186eb41013e21512441d7546d1b59 Author: PTRCoder Date: Fri Aug 23 20:56:11 2024 +0200 Potential fix of cmd buffer header commit e47d9af7501c6c7cec2069668d5f09c506827c2f Author: PTRCoder Date: Fri Aug 23 19:54:04 2024 +0200 Additional logging commit d5d0301702086cc9f02e30888b94a3c2029fcd27 Author: PTRCoder Date: Fri Aug 23 19:36:55 2024 +0200 Added temp logging for debugging commit a41fc80eab3fabb2bf6961c468fa30b14245a6b3 Author: PTRCoder Date: Fri Aug 23 18:59:48 2024 +0200 Fixed use of mapped buffer commit f88ebb65a3cdd99f6a3436e8ab6419a7f7cf3ad5 Author: PTRCoder Date: Fri Aug 23 18:51:48 2024 +0200 Reverted 4th value to unknown commit b1d1757eaabe551a4ed3219cb9d65036cc2da748 Author: PTRCoder Date: Fri Aug 23 17:26:24 2024 +0200 Updated includes commit 60c453b5bbee44fef06fa7964664b19384a348fe Author: PTRCoder Date: Fri Aug 23 17:21:11 2024 +0200 Fixed argument commit b7777a7b479447febca1b5b8ad1390f37fdb63af Author: PTRCoder Date: Fri Aug 23 17:00:49 2024 +0200 Added include commit 4b3ac391d89b533712e51a7dbec3edc074949a74 Author: PTRCoder Date: Fri Aug 23 16:53:56 2024 +0200 Fixed wrong arguments commit 13f32bd384f50df99b2fbb427a7310e73d07446a Author: PTRCoder Date: Fri Aug 23 16:33:54 2024 +0200 Fixed call return value commit 826d6bed2d9abb22c2d50d7a4d1ea0b64b873dac Author: PTRCoder Date: Fri Aug 23 16:32:37 2024 +0200 Changed implementation to rely on parser instead of raw commit 5dea8a125bad8632893ab33a48465fe5ec5c8a63 Author: PTRCoder Date: Fri Aug 23 16:00:35 2024 +0200 Moved kernel retrieval to argument commit bb4de89652cf23ad9e17c57a2f3f9cb0362b6bdc Author: PTRCoder Date: Fri Aug 23 15:50:37 2024 +0200 Fixed method call commit 8b9e04c541bd9d160627baa993e354e736521f57 Author: PTRCoder Date: Fri Aug 23 15:48:58 2024 +0200 Fixed type name commit 29fc438086391f24c6bc167d0dc9d5b0199b1347 Author: PTRCoder Date: Fri Aug 23 15:41:35 2024 +0200 Fixed includes commit a6fe44f81f3f3dcd060475ad3871e2ad54795776 Author: PTRCoder Date: Fri Aug 23 15:41:29 2024 +0200 Fixed method name commit 67380edbc9eed88b0bdcb30c2bacd4a0ab857c8d Author: PTRCoder Date: Fri Aug 23 15:41:09 2024 +0200 Fixed method call commit babec1bb5c358dec64ae691a5a88729ac166453d Author: PTRCoder Date: Fri Aug 23 15:34:32 2024 +0200 Fixed kernel reference commit 6238f52819bddd313d834978493fdf0066de6340 Author: PTRCoder Date: Fri Aug 23 15:30:10 2024 +0200 Fixed missing namespace commit c4a99ccbe9ee6468c47f365d485ca204f23cbbd9 Author: PTRCoder Date: Fri Aug 23 15:29:29 2024 +0200 Fixed missing argument commit 916849691b902065daa7d3bb606494a120ed0cf0 Author: PTRCoder Date: Fri Aug 23 15:26:39 2024 +0200 Fixed wrong mac commit 7a997ea8ae6c49d0a06694a7e8794002ba4b2715 Author: PTRCoder Date: Fri Aug 23 15:19:13 2024 +0200 Potentially fixed calling NWM_INF commit 320a82bb5d2164faa1f618fd994208effcd7319a Author: PTRCoder Date: Fri Aug 23 15:05:24 2024 +0200 Potential fix for calling NWM_UDS version commit 0b0534400d4937623e6d6354e75d0f8cd237503c Author: PTRCoder Date: Fri Aug 23 13:56:05 2024 +0200 Added include for NWM_UDS commit d61dfdaf2ed62174fc5abe8646f3e987cc4adb83 Author: PTRCoder Date: Fri Aug 23 13:51:03 2024 +0200 Fixed cast to u32 and dummy value commit a14e3981579c968c5e554f8ca013bbc572ea0cd5 Author: PTRCoder Date: Fri Aug 23 13:50:17 2024 +0200 Added correct transition from INF to UDS commit 54e4da175303835201c1b501a9490fb569693dcd Author: PTRCoder Date: Fri Aug 23 13:30:13 2024 +0200 Initial full ScanAPs implementation commit aeb1e224f32ae688df1df3fe31c1b45b87378f50 Author: PTRCoder Date: Fri Aug 23 13:18:17 2024 +0200 Fixed member reference commit c3b1beae1c14609cbcc82419122d0ccea24fed4f Author: PTRCoder Date: Fri Aug 23 13:11:30 2024 +0200 Readded NWM_UDS header commit 6b03ca58a294a74fd0eeb36a81de4121f2ff382e Author: PTRCoder Date: Fri Aug 23 12:44:40 2024 +0200 Updated include statements commit 36c4adf4312e96401525d57b9a4afdc306024269 Author: PTRCoder Date: Fri Aug 23 00:58:25 2024 +0200 Potential member reference fix commit 6d28737856f5bc6f39694f076abd83ef6f8e9ce0 Author: PTRCoder Date: Fri Aug 23 00:48:51 2024 +0200 Fixed missing void return type commit 14eb3126780d565487dce1da0703281c4aee9d45 Author: PTRCoder Date: Fri Aug 23 00:14:41 2024 +0200 Using correct way to call UDS service commit 2acc2a35a9443e56cb67513403442a8e84bf7297 Author: PTRCoder Date: Thu Aug 22 22:39:15 2024 +0200 Updated API commit d204bfa05c851d21c48d965622a0e61c54ba68a2 Author: PTRCoder Date: Thu Aug 22 22:38:49 2024 +0200 Initial NWM_INF::RecvBeaconBroadcastData implementation commit 01baadf7a46c575600dbe06600dd2c4c77edadc0 Author: PTRCoder Date: Thu Aug 22 19:23:17 2024 +0200 Included member type commit 36f416469f2a6d29d07788d403ab12f437c229cd Author: PTRCoder Date: Thu Aug 22 19:06:52 2024 +0200 Coding style fixes commit 4e73a1d057bcf3b701b164724322e12959a34075 Author: PTRCoder Date: Thu Aug 22 19:02:37 2024 +0200 Starting tests --- src/core/hle/service/ac/ac.cpp | 79 +++++++++++++++++++++++----- src/core/hle/service/nwm/nwm_inf.cpp | 43 ++++++++++++++- src/core/hle/service/nwm/nwm_uds.cpp | 1 + 3 files changed, 109 insertions(+), 14 deletions(-) diff --git a/src/core/hle/service/ac/ac.cpp b/src/core/hle/service/ac/ac.cpp index 8e6e7f803..233dbbf49 100644 --- a/src/core/hle/service/ac/ac.cpp +++ b/src/core/hle/service/ac/ac.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include "common/archives.h" #include "common/common_types.h" #include "common/logging/log.h" @@ -18,7 +19,10 @@ #include "core/hle/service/ac/ac.h" #include "core/hle/service/ac/ac_i.h" #include "core/hle/service/ac/ac_u.h" +#include "core/hle/service/nwm/nwm_inf.h" #include "core/hle/service/soc/soc_u.h" +#include "network/network.h" +#include "network/room.h" #include "core/memory.h" SERIALIZE_EXPORT_IMPL(Service::AC::Module) @@ -182,20 +186,69 @@ void Module::Interface::GetStatus(Kernel::HLERequestContext& ctx) { void Module::Interface::ScanAPs(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp(ctx); - const u32 arg1 = rp.Pop(); - LOG_WARNING(Service_AC, "val1: {}", arg1); - const u32 arg2 = rp.Pop(); - LOG_WARNING(Service_AC, "val2: {}", arg2); - const u32 arg3 = rp.Pop(); - LOG_WARNING(Service_AC, "val3: {}", arg3); - const u32 arg4 = rp.Pop(); - LOG_WARNING(Service_AC, "val4: {}", arg4); - const u32 arg5 = rp.Pop(); - LOG_WARNING(Service_AC, "val5: {}", arg5); - IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); - rb.Push(ResultUnknown); - LOG_WARNING(Service_AC, "(STUBBED) called"); + // I used 3dbrew.org for the information on the individual request inputs + + // Arg 0 is Header code, which is ignored + // Arg 1 is Size + const u32 size = rp.Pop(); + 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); + // Likely time transpired between consecutive calls of this method. + // First call has value 0 or 1. Second call has value 0xFFFF0000. + const u32 unknown = rp.Pop(); + LOG_WARNING(Service_AC, "val4: {}", unknown); + + std::vector buffer(size); + + 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 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[18] = (size << 4) | 12; // should be considered correct for mapped buffer + cmd_buf[19] = 0; // if i interpreted the code correctly, this value won't matter + + LOG_WARNING(Service_AC, "Finished setting up command buffer"); + std::shared_ptr thread = ctx.ClientThread(); + auto current_process = thread->owner_process.lock(); + LOG_WARNING(Service_AC, "Retrieved thread and process"); + + auto context = + std::make_shared(Core::System::GetInstance().Kernel(), + ctx.Session(), thread); + LOG_WARNING(Service_AC, "Created context"); + context->PopulateFromIncomingCommandBuffer(cmd_buf.data(), current_process); + + LOG_WARNING(Service_AC, "Finished setting up context"); + + auto nwm_inf = + Core::System::GetInstance().ServiceManager().GetService("nwm::INF"); + LOG_WARNING(Service_AC, "Calling NWM_INF::RecvBeaconBroadcastData"); + 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 + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); + IPC::RequestParser rp2(*context); + rb.Push(rp2.Pop()); + Kernel::MappedBuffer mapped_buffer = rp2.PopMappedBuffer(); + mapped_buffer.Read(buffer.data(), 0, buffer.size()); + rb.PushStaticBuffer(buffer, 0); + LOG_WARNING(Service_AC, "(STUBBED) called, pid={}, unknown={}", pid, unknown); } void Module::Interface::GetInfraPriority(Kernel::HLERequestContext& ctx) { diff --git a/src/core/hle/service/nwm/nwm_inf.cpp b/src/core/hle/service/nwm/nwm_inf.cpp index 69ffd7d64..5ccb36cef 100644 --- a/src/core/hle/service/nwm/nwm_inf.cpp +++ b/src/core/hle/service/nwm/nwm_inf.cpp @@ -2,8 +2,12 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include "common/archives.h" +#include "common/logging/log.h" #include "core/core.h" +#include "core/hle/ipc.h" +#include "core/hle/ipc_helpers.h" #include "core/hle/service/nwm/nwm_inf.h" #include "core/hle/service/nwm/nwm_uds.h" @@ -12,9 +16,46 @@ SERIALIZE_EXPORT_IMPL(Service::NWM::NWM_INF) namespace Service::NWM { void NWM_INF::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx); // TODO(PTR) Update implementation to cover differences between NWM_INF and NWM_UDS + + LOG_WARNING(Service_NWM, "Started NWM_INF::RecvBeaconBroadcastData"); + + // adding in extra context value for transition from INF to UDS + std::array cmd_buf; + cmd_buf[0] = 0x000F0404; + int i; + for (i = 1; i < 15; i++) { + cmd_buf[i] = rp.Pop(); + } + rp.Pop(); + 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(); + } + + std::shared_ptr thread = ctx.ClientThread(); + auto current_process = thread->owner_process.lock(); + auto context = + std::make_shared(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("nwm::UDS"); - nwm_uds->HandleSyncRequest(ctx); + + LOG_WARNING(Service_NWM, "Calling NWM_UDS::RecvBeaconBroadcastData"); + nwm_uds->HandleSyncRequest(*context); + LOG_WARNING(Service_NWM, "Returned to NWM_INF::RecvBeaconBroadcastData"); + + IPC::RequestParser rp2(*context); + + IPC::RequestBuilder rb = rp.MakeBuilder(1, 2); + rb.Push(rp2.Pop()); + rb.PushMappedBuffer(rp2.PopMappedBuffer()); + + LOG_WARNING(Service_NWM, "Finished NWM_INF::RecvBeaconBroadcastData"); } NWM_INF::NWM_INF() : ServiceFramework("nwm::INF") { diff --git a/src/core/hle/service/nwm/nwm_uds.cpp b/src/core/hle/service/nwm/nwm_uds.cpp index 58b2f4e35..bd2c038f1 100644 --- a/src/core/hle/service/nwm/nwm_uds.cpp +++ b/src/core/hle/service/nwm/nwm_uds.cpp @@ -14,6 +14,7 @@ #include "core/core_timing.h" #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/event.h" +#include "core/hle/kernel/handle_table.h" #include "core/hle/kernel/shared_memory.h" #include "core/hle/kernel/shared_page.h" #include "core/hle/result.h"