From 5b2a9f6136e5f26b22e8113795732096cb445de8 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Sat, 16 Sep 2023 21:22:37 +0200 Subject: [PATCH] ac: add SSID-related ac:i functions ACI_LoadNetworkSetting and ACI_GetNetworkWirelessEssidSecuritySsid, plus acGetSessionHandle. --- libctru/include/3ds/services/ac.h | 15 ++++++++++++ libctru/source/services/ac.c | 39 +++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/libctru/include/3ds/services/ac.h b/libctru/include/3ds/services/ac.h index bc1ad79c8..a39f389d7 100644 --- a/libctru/include/3ds/services/ac.h +++ b/libctru/include/3ds/services/ac.h @@ -27,6 +27,9 @@ Result acInit(void); /// Exits AC. void acExit(void); +/// Gets the current AC session handle. +Handle *acGetSessionHandle(void); + /// Waits for the system to connect to the internet. Result acWaitInternetConnection(void); @@ -128,3 +131,15 @@ Result ACU_SetRequestEulaVersion(acuConfig* config); * @param connectionHandle Handle created with svcCreateEvent to wait on until the connection succeeds or fails. */ Result ACU_ConnectAsync(const acuConfig* config, Handle connectionHandle); + +/** + * @brief Selects the WiFi configuration slot for further ac:i operations. + * @param slot WiFi slot (0, 1 or 2). + */ +Result ACI_LoadNetworkSetting(u32 slot); + +/** + * @brief Fetches the SSID of the previously selected WiFi configuration slot. + * @param[out] ssid Pointer to the output buffer of size 32B the SSID will be stored in. + */ +Result ACI_GetNetworkWirelessEssidSecuritySsid(void *ssid); diff --git a/libctru/source/services/ac.c b/libctru/source/services/ac.c index 007a70cca..db04f0794 100644 --- a/libctru/source/services/ac.c +++ b/libctru/source/services/ac.c @@ -6,6 +6,7 @@ #include <3ds/synchronization.h> #include <3ds/services/ac.h> #include <3ds/ipc.h> +#include static Handle acHandle; static int acRefCount; @@ -30,6 +31,11 @@ void acExit(void) svcCloseHandle(acHandle); } +Handle *acGetSessionHandle(void) +{ + return &acHandle; +} + Result acWaitInternetConnection(void) { Result ret = 0; @@ -284,3 +290,36 @@ Result ACU_GetProxyUserName(char *username) return (Result)cmdbuf[1]; } + +Result ACI_LoadNetworkSetting(u32 slot) +{ + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x401,1,0); // 0x04010040 + cmdbuf[1] = slot; + + Result ret = 0; + if(R_FAILED(ret = svcSendSyncRequest(acHandle))) return ret; + + return (Result)cmdbuf[1]; +} + +Result ACI_GetNetworkWirelessEssidSecuritySsid(void *ssid) +{ + u32* cmdbuf = getThreadCommandBuffer(); + u32* staticbufs = getThreadStaticBuffers(); + + cmdbuf[0] = IPC_MakeHeader(0x40F,0,0); // 0x040F0000 + + u32 staticbufBackup[2]; + memcpy(staticbufBackup, staticbufs, 8); + + staticbufs[0] = IPC_Desc_StaticBuffer(0x20, 0); // at most 32 bytes + staticbufs[1] = (u32)ssid; + + Result ret = svcSendSyncRequest(acHandle); + + memcpy(staticbufs, staticbufBackup, 8); + + return R_SUCCEEDED(ret) ? (Result)cmdbuf[1] : ret; +}