mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-21 12:32:40 +02:00
wlaninf: Updated for new-ipc.
This commit is contained in:
parent
1c334bafb9
commit
be2cb63722
@ -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)
|
||||
|
@ -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) {
|
||||
void _wlaninfCleanup(void) {
|
||||
serviceClose(&g_wlaninfSrv);
|
||||
}
|
||||
}
|
||||
|
||||
Service* wlaninfGetServiceSession(void) {
|
||||
return &g_wlaninfSrv;
|
||||
}
|
||||
|
||||
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;
|
||||
static Result _wlaninfCmdNoInOutU32(Service* srv, u32 *out, u32 cmd_id) {
|
||||
return serviceDispatchOut(srv, cmd_id, *out);
|
||||
}
|
||||
|
||||
Result wlaninfGetState(WlanInfState* 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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user