diff --git a/nx/include/switch/services/nifm.h b/nx/include/switch/services/nifm.h index ca5dce2b..c8cf1a25 100644 --- a/nx/include/switch/services/nifm.h +++ b/nx/include/switch/services/nifm.h @@ -1,7 +1,7 @@ /** * @file nifm.h * @brief Network interface service IPC wrapper. - * @author shadowninja108 + * @author shadowninja108, shibboleet * @copyright libnx Authors */ @@ -16,3 +16,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..8c421bb8 100644 --- a/nx/source/services/nifm.c +++ b/nx/source/services/nifm.c @@ -1,7 +1,7 @@ /** - * @file nifm.h + * @file nifm.c * @brief Network interface service IPC wrapper. - * @author shadowninja108 + * @author shadowninja108, shibboleet * @copyright libnx Authors */ @@ -20,7 +20,7 @@ Result nifmInitialize(void) { if (serviceIsActive(&g_nifmSrv)) return 0; - + Result rc; rc = smGetService(&g_nifmSrv, "nifm:u"); @@ -81,6 +81,183 @@ 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; + + if (R_SUCCEEDED(rc) && out) + *out = resp->out != 0; + } + + 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; + + if (R_SUCCEEDED(rc) && out) + *out = resp->out != 0; + } + + 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; + + if (R_SUCCEEDED(rc) && out) + *out = resp->out != 0; + } + + 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);