Skip to content

Commit

Permalink
ac: add SSID-related ac:i functions
Browse files Browse the repository at this point in the history
ACI_LoadNetworkSetting and ACI_GetNetworkWirelessEssidSecuritySsid, plus acGetSessionHandle.
  • Loading branch information
TuxSH committed Sep 16, 2023
1 parent 0f09885 commit 5b2a9f6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
15 changes: 15 additions & 0 deletions libctru/include/3ds/services/ac.h
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
39 changes: 39 additions & 0 deletions libctru/source/services/ac.c
Expand Up @@ -6,6 +6,7 @@
#include <3ds/synchronization.h>
#include <3ds/services/ac.h>
#include <3ds/ipc.h>
#include <string.h>

static Handle acHandle;
static int acRefCount;
Expand All @@ -30,6 +31,11 @@ void acExit(void)
svcCloseHandle(acHandle);
}

Handle *acGetSessionHandle(void)
{
return &acHandle;
}

Result acWaitInternetConnection(void)
{
Result ret = 0;
Expand Down Expand Up @@ -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;
}

0 comments on commit 5b2a9f6

Please sign in to comment.