diff --git a/nx/include/switch/services/wlaninf.h b/nx/include/switch/services/wlaninf.h index b3eb0006..01d2fffa 100644 --- a/nx/include/switch/services/wlaninf.h +++ b/nx/include/switch/services/wlaninf.h @@ -1,13 +1,13 @@ /** * @file wlaninf.h * @brief WLAN InfraManager service IPC wrapper. - * @author natinusala + * @author natinusala, yellows8 * @copyright libnx Authors */ #pragma once #include "../kernel/ipc.h" -#include "../services/sm.h" +#include "../sf/service.h" /// WLAN State. typedef enum { @@ -20,6 +20,7 @@ Result wlaninfInitialize(void); void wlaninfExit(void); Service* wlaninfGetServiceSession(void); +/// Gets \ref WlanInfState. Result wlaninfGetState(WlanInfState* out); /// Value goes from -30 (really good signal) to -90 (barely enough to stay connected) diff --git a/nx/source/services/wlaninf.c b/nx/source/services/wlaninf.c index 1eb0d854..49a984ad 100644 --- a/nx/source/services/wlaninf.c +++ b/nx/source/services/wlaninf.c @@ -1,111 +1,34 @@ -/** - * @file wlaninf.c - * @brief WLAN InfraManager service IPC wrapper. - * @author natinusala - * @copyright libnx Authors - */ - -#include "types.h" -#include "result.h" -#include "services/sm.h" +#define NX_SERVICE_ASSUME_NON_DOMAIN +#include "service_guard.h" #include "services/wlaninf.h" -#include "arm/atomics.h" static Service g_wlaninfSrv; -static u64 g_refCnt; -Result wlaninfInitialize(void) { - Result rc; +NX_GENERATE_SERVICE_GUARD(wlaninf); - atomicIncrement64(&g_refCnt); - - if (serviceIsActive(&g_wlaninfSrv)) - return 0; - - rc = smGetService(&g_wlaninfSrv, "wlan:inf"); - - if (R_FAILED(rc)) - wlaninfExit(); - - return rc; +Result _wlaninfInitialize(void) { + return smGetService(&g_wlaninfSrv, "wlan:inf"); } -void wlaninfExit(void) { - if (atomicDecrement64(&g_refCnt) == 0) { - serviceClose(&g_wlaninfSrv); - } +void _wlaninfCleanup(void) { + serviceClose(&g_wlaninfSrv); } Service* wlaninfGetServiceSession(void) { return &g_wlaninfSrv; } +static Result _wlaninfCmdNoInOutU32(Service* srv, u32 *out, u32 cmd_id) { + return serviceDispatchOut(srv, cmd_id, *out); +} + Result wlaninfGetState(WlanInfState* out) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_wlaninfSrv, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 10; - - Result rc = serviceIpcDispatch(&g_wlaninfSrv); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - - struct { - u64 magic; - u64 result; - u32 out; - } *resp; - - serviceIpcParse(&g_wlaninfSrv, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - *out = resp->out; - } - + u32 tmp=0; + Result rc = _wlaninfCmdNoInOutU32(&g_wlaninfSrv, &tmp, 10); + if (R_SUCCEEDED(rc) && out) *out = tmp; return rc; } Result wlaninfGetRSSI(s32* out) { - IpcCommand c; - ipcInitialize(&c); - - struct { - u64 magic; - u64 cmd_id; - } *raw; - - raw = serviceIpcPrepareHeader(&g_wlaninfSrv, &c, sizeof(*raw)); - - raw->magic = SFCI_MAGIC; - raw->cmd_id = 12; - - Result rc = serviceIpcDispatch(&g_wlaninfSrv); - - if (R_SUCCEEDED(rc)) { - IpcParsedCommand r; - - struct { - u64 magic; - u64 result; - s32 out; - } *resp; - - serviceIpcParse(&g_wlaninfSrv, &r, sizeof(*resp)); - resp = r.Raw; - - rc = resp->result; - *out = resp->out; - } - - return rc; + return _wlaninfCmdNoInOutU32(&g_wlaninfSrv, (u32*)out, 12); }