From d8c631b65ca3e54c5d4ad363dfef3ea89332c000 Mon Sep 17 00:00:00 2001 From: exelix Date: Sun, 3 Mar 2019 15:42:25 +0100 Subject: [PATCH] Init nifm in the proper context, add SetWirelessCommunicationEnabled --- nx/include/switch/services/nifm.h | 5 +++ nx/source/services/nifm.c | 56 ++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/services/nifm.h b/nx/include/switch/services/nifm.h index 5248f542..735e8a7e 100644 --- a/nx/include/switch/services/nifm.h +++ b/nx/include/switch/services/nifm.h @@ -16,6 +16,11 @@ Result nifmGetCurrentIpAddress(u32* out); Result nifmIsWirelessCommunicationEnabled(bool* out); +/** + * @note Works only if called from nifm:a or nifm:s. + */ +Result nifmSetWirelessCommunicationEnabled(bool enable); + Result nifmIsEthernetCommunicationEnabled(bool* out); Result nifmIsAnyForegroundRequestAccepted(bool* out); Result nifmPutToSleep(void); diff --git a/nx/source/services/nifm.c b/nx/source/services/nifm.c index 68dd0fd1..4a895039 100644 --- a/nx/source/services/nifm.c +++ b/nx/source/services/nifm.c @@ -8,6 +8,7 @@ #include "services/nifm.h" #include "arm/atomics.h" #include "runtime/hosversion.h" +#include "services/applet.h" static Service g_nifmSrv; static Service g_nifmIGS; @@ -23,7 +24,25 @@ Result nifmInitialize(void) { return 0; Result rc; - rc = smGetService(&g_nifmSrv, "nifm:u"); + + switch (appletGetAppletType()) { + case AppletType_None: + rc = smGetService(&g_nifmSrv, "nifm:s"); + break; + + case AppletType_Default: + case AppletType_Application: + case AppletType_SystemApplication: + default: + rc = smGetService(&g_nifmSrv, "nifm:u"); + break; + + case AppletType_SystemApplet: + case AppletType_LibraryApplet: + case AppletType_OverlayApplet: + rc = smGetService(&g_nifmSrv, "nifm:a"); + break; + } if (R_SUCCEEDED(rc)) rc = serviceConvertToDomain(&g_nifmSrv); @@ -119,6 +138,41 @@ Result nifmIsWirelessCommunicationEnabled(bool* out) { return rc; } +Result nifmSetWirelessCommunicationEnabled(bool enable) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + u8 value; + } *raw; + + raw = serviceIpcPrepareHeader(&g_nifmIGS, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 16; + raw->value = enable; + + Result rc = serviceIpcDispatch(&g_nifmIGS); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + + struct { + u64 magic; + u64 result; + } *resp; + + serviceIpcParse(&g_nifmIGS, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + Result nifmIsEthernetCommunicationEnabled(bool* out) { IpcCommand c; ipcInitialize(&c);