From f182ea3f2c9d6f18db32806507681caff61670ce Mon Sep 17 00:00:00 2001 From: PTRCoder Date: Sat, 24 Aug 2024 20:07:04 +0200 Subject: [PATCH] Squashed commit of the following: commit c6f34babb7620b1f75101acad79618a97a939891 Author: PTRCoder Date: Sat Aug 24 17:04:37 2024 +0200 Undo unnecessary change to nwm_uds.cpp commit 219cc83c41a56d13675ae9af55d3777123140f72 Author: PTRCoder Date: Sat Aug 24 16:46:11 2024 +0200 Fixed remaining coding style errors commit 5f00bb04c7a21d41e535ef27f16a3df5dcb51d0c Author: PTRCoder Date: Sat Aug 24 16:43:42 2024 +0200 Removed log messages commit d469c6b583d3ab34f752f52b6baeae7c5951252c Author: PTRCoder Date: Sat Aug 24 16:42:49 2024 +0200 Fixed coding style errors commit 60f7dbd4f843155f9565fd419cdb075db27c2fec Author: PTRCoder Date: Sat Aug 24 15:18:03 2024 +0200 Potential fix for wrongly storing mac commit 1ac5500fff9b3736e2297f4cb4d1d88c510642d1 Author: PTRCoder Date: Sat Aug 24 14:58:57 2024 +0200 Fixed format error commit c2d18196095013c78619955484b918cc5f30a3a1 Author: PTRCoder Date: Sat Aug 24 14:50:22 2024 +0200 Truly fixed log message this time commit a36d12d3f4249bd99d037e05745d8438baa5ca23 Author: PTRCoder Date: Sat Aug 24 14:44:44 2024 +0200 Fixed log message error commit c00705f9a41208f422e6908904d2d1b37f5ac241 Author: PTRCoder Date: Sat Aug 24 14:34:38 2024 +0200 Added log message for checking MAC address commit c4f6bffd9138345986ce0e340243dae7ca374510 Author: PTRCoder Date: Sat Aug 24 14:31:31 2024 +0200 Added forgotten log message commit d461a44e8b37116f1b155894724636b251e23c1f Author: PTRCoder Date: Sat Aug 24 14:14:59 2024 +0200 Added assert statement as sanity check commit c24b0c2e88f61fd18b774507c04b4da3a1595f6a Author: PTRCoder Date: Sat Aug 24 14:14:47 2024 +0200 Added temp loggers for tracking where error occurs commit 923d1d30dae6d4e48ac402cb974c75f1fc8c0af3 Author: PTRCoder Date: Sat Aug 24 13:42:39 2024 +0200 Removed now-redundant log messages and updated comments commit 471efa4c8c9f3420cd2ee9e7eeb84677a528c6a3 Author: PTRCoder Date: Sat Aug 24 12:42:23 2024 +0200 Changed retrieval of values to be dependent on VAddr instead of pointer commit dd16c0b6a0924caa1f55b4a9ab6c912a3313d953 Author: PTRCoder Date: Sat Aug 24 00:48:49 2024 +0200 Added extra log messages for debugging commit 97c856b2b53c08fe6ac96c3cf8d80b32f3629c86 Author: PTRCoder Date: Sat Aug 24 00:22:23 2024 +0200 Fixed casting error commit 1dd28eedc53610295b14f586010d6a8acbd311fc Author: PTRCoder Date: Sat Aug 24 00:13:26 2024 +0200 Fixed missing call to Kernel() commit 40ca69fafdfb0be39e2350da58e84465853d6ffb Author: PTRCoder Date: Sat Aug 24 00:01:21 2024 +0200 Fixed MemorySystem retrieval commit bb08716752099bc9fa0a23698f19cbd6561b7ca6 Author: PTRCoder Date: Fri Aug 23 23:57:24 2024 +0200 Fixed lingering remnant of old value commit d76311bb1bcece2e1ce2f0022fd711ed390335df Author: PTRCoder Date: Fri Aug 23 23:56:44 2024 +0200 Fixed missing argument commit 01655fbbb0b32e774a69e31a9866597357d32014 Author: PTRCoder Date: Fri Aug 23 23:44:16 2024 +0200 Added retrieval of VAddr from input commit 3f76dd367851fd88f9c5f5f8df0642ef0128b12b Author: PTRCoder Date: Fri Aug 23 23:42:49 2024 +0200 Revert independency of UDS commit 28021f557844f0af097d54b544e0563a262324c0 Author: PTRCoder Date: Fri Aug 23 23:06:37 2024 +0200 Fixed NWM_INF implementation reference to NWM_UDS method commit ca85f92e0ee6cf5210c5548e52d943ef7607ba81 Author: PTRCoder Date: Fri Aug 23 23:06:21 2024 +0200 Fixed debug log message commit a061a3dcec515d532209f58984221d11bf8d71bf Author: PTRCoder Date: Fri Aug 23 22:14:36 2024 +0200 Updated include statements commit 2fd28a883d847c4c9b5dd6108213751221acf826 Author: PTRCoder Date: Fri Aug 23 21:51:02 2024 +0200 Removed dependency on NWM_UDS 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 | 59 ++++++++++++++-------------- src/core/hle/service/nwm/nwm_inf.cpp | 28 ++++++------- 2 files changed, 42 insertions(+), 45 deletions(-) diff --git a/src/core/hle/service/ac/ac.cpp b/src/core/hle/service/ac/ac.cpp index eb5318da0..b9e8ebc89 100644 --- a/src/core/hle/service/ac/ac.cpp +++ b/src/core/hle/service/ac/ac.cpp @@ -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(); - 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 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 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(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(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("nwm::INF"); - LOG_WARNING(Service_AC, "Calling NWM_INF::RecvBeaconBroadcastData"); + // Retrieve service from service manager + auto nwm_inf = + Core::System::GetInstance().ServiceManager().GetService("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()); + // 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); diff --git a/src/core/hle/service/nwm/nwm_inf.cpp b/src/core/hle/service/nwm/nwm_inf.cpp index 2257b5ef1..d174db23b 100644 --- a/src/core/hle/service/nwm/nwm_inf.cpp +++ b/src/core/hle/service/nwm/nwm_inf.cpp @@ -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 cmd_buf; cmd_buf[0] = 0x000F0404; int i; @@ -31,33 +34,28 @@ void NWM_INF::RecvBeaconBroadcastData(Kernel::HLERequestContext& ctx) { cmd_buf[i] = rp.Pop(); } rp.Pop(); - 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(); } + // Prepare for call to NWM_UDS 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); + 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"); - - LOG_WARNING(Service_NWM, "Calling NWM_UDS::RecvBeaconBroadcastData"); + auto nwm_uds = + Core::System::GetInstance().ServiceManager().GetService("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()); rb.PushMappedBuffer(rp2.PopMappedBuffer()); - - LOG_WARNING(Service_NWM, "Finished NWM_INF::RecvBeaconBroadcastData"); } NWM_INF::NWM_INF() : ServiceFramework("nwm::INF") {