From 8ed8e36a3944a6a47ff4a0dca28180b591089972 Mon Sep 17 00:00:00 2001 From: shibbo Date: Fri, 25 Jan 2019 00:10:33 -0500 Subject: [PATCH] Add in more NIFM functionality --- nx/include/switch/services/nifm.h | 8 ++ nx/source/services/nifm.c | 172 ++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+) diff --git a/nx/include/switch/services/nifm.h b/nx/include/switch/services/nifm.h index ca5dce2b..fa01465f 100644 --- a/nx/include/switch/services/nifm.h +++ b/nx/include/switch/services/nifm.h @@ -2,6 +2,7 @@ * @file nifm.h * @brief Network interface service IPC wrapper. * @author shadowninja108 + * @author shibboleet * @copyright libnx Authors */ @@ -16,3 +17,10 @@ Result nifmInitialize(void); void nifmExit(void); Result nifmGetCurrentIpAddress(u32* out); + +Result nifmIsWirelessCommunicationEnabled(bool* out); + +Result nifmIsEthernetCommunicationEnabled(bool* out); +Result nifmIsAnyForegroundRequestAccepted(bool* out); +Result nifmPutToSleep(void); +Result nifmWakeUp(void); diff --git a/nx/source/services/nifm.c b/nx/source/services/nifm.c index db421190..d2b20357 100644 --- a/nx/source/services/nifm.c +++ b/nx/source/services/nifm.c @@ -2,6 +2,7 @@ * @file nifm.h * @brief Network interface service IPC wrapper. * @author shadowninja108 + * @author shibboleet * @copyright libnx Authors */ @@ -81,6 +82,177 @@ Result nifmGetCurrentIpAddress(u32* out) { return rc; } +Result nifmIsWirelessCommunicationEnabled(bool* out) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = serviceIpcPrepareHeader(&g_nifmIGS, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 17; + + Result rc = serviceIpcDispatch(&g_nifmIGS); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + + struct { + u64 magic; + u64 result; + u8 out; + } *resp; + + serviceIpcParse(&g_nifmIGS, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + *out = resp->out; + } + + return rc; +} + +Result nifmIsEthernetCommunicationEnabled(bool* out) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = serviceIpcPrepareHeader(&g_nifmIGS, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 20; + + Result rc = serviceIpcDispatch(&g_nifmIGS); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + + struct { + u64 magic; + u64 result; + u8 out; + } *resp; + + serviceIpcParse(&g_nifmIGS, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + *out = resp->out; + } + + return rc; +} + +Result nifmIsAnyForegroundRequestAccepted(bool* out) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = serviceIpcPrepareHeader(&g_nifmIGS, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 22; + + Result rc = serviceIpcDispatch(&g_nifmIGS); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + + struct { + u64 magic; + u64 result; + u8 out; + } *resp; + + serviceIpcParse(&g_nifmIGS, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + *out = resp->out; + } + + return rc; +} + +Result nifmPutToSleep(void) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = serviceIpcPrepareHeader(&g_nifmIGS, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 23; + + 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 nifmWakeUp(void) { + IpcCommand c; + ipcInitialize(&c); + + struct { + u64 magic; + u64 cmd_id; + } *raw; + + raw = serviceIpcPrepareHeader(&g_nifmIGS, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 24; + + 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; +} + static Result _nifmCreateGeneralService(Service* out, u64 in) { IpcCommand c; ipcInitialize(&c);