mirror of
https://github.com/switchbrew/libnx.git
synced 2025-06-22 04:52:39 +02:00
bpc: update for new-ipc
This commit is contained in:
parent
040767ce57
commit
77563f027a
@ -6,7 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "../types.h"
|
#include "../types.h"
|
||||||
#include "../services/sm.h"
|
#include "../sf/service.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
BpcSleepButtonState_Held = 0,
|
BpcSleepButtonState_Held = 0,
|
||||||
|
@ -1,134 +1,41 @@
|
|||||||
#include "types.h"
|
#define NX_SERVICE_ASSUME_NON_DOMAIN
|
||||||
#include "result.h"
|
#include "service_guard.h"
|
||||||
#include "arm/atomics.h"
|
|
||||||
#include "kernel/ipc.h"
|
|
||||||
#include "runtime/hosversion.h"
|
|
||||||
#include "services/bpc.h"
|
#include "services/bpc.h"
|
||||||
#include "services/sm.h"
|
#include "runtime/hosversion.h"
|
||||||
|
|
||||||
static Service g_bpcSrv;
|
static Service g_bpcSrv;
|
||||||
static u64 g_refCnt;
|
|
||||||
|
|
||||||
Result bpcInitialize(void)
|
NX_GENERATE_SERVICE_GUARD(bpc);
|
||||||
{
|
|
||||||
Result rc = 0;
|
|
||||||
|
|
||||||
atomicIncrement64(&g_refCnt);
|
Result _bpcInitialize(void) {
|
||||||
|
return smGetService(&g_bpcSrv, hosversionAtLeast(2,0,0) ? "bpc" : "bpc:c");
|
||||||
if (serviceIsActive(&g_bpcSrv))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
rc = smGetService(&g_bpcSrv, hosversionAtLeast(2,0,0) ? "bpc" : "bpc:c");
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void bpcExit(void)
|
void _bpcCleanup(void) {
|
||||||
{
|
serviceClose(&g_bpcSrv);
|
||||||
if (atomicDecrement64(&g_refCnt) == 0)
|
|
||||||
serviceClose(&g_bpcSrv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Service* bpcGetServiceSession(void) {
|
Service* bpcGetServiceSession(void) {
|
||||||
return &g_bpcSrv;
|
return &g_bpcSrv;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result bpcShutdownSystem(void)
|
static Result _bpcCmdNoIO(Service *srv, u32 cmd_id) {
|
||||||
{
|
return serviceDispatch(srv, cmd_id);
|
||||||
IpcCommand c;
|
|
||||||
ipcInitialize(&c);
|
|
||||||
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_bpcSrv, &c, sizeof(*raw));
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 0;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_bpcSrv);
|
|
||||||
|
|
||||||
if(R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_bpcSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result bpcRebootSystem(void)
|
Result bpcShutdownSystem(void) {
|
||||||
{
|
return _bpcCmdNoIO(&g_bpcSrv, 0);
|
||||||
IpcCommand c;
|
}
|
||||||
ipcInitialize(&c);
|
|
||||||
|
|
||||||
struct {
|
Result bpcRebootSystem(void) {
|
||||||
u64 magic;
|
return _bpcCmdNoIO(&g_bpcSrv, 1);
|
||||||
u64 cmd_id;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_bpcSrv, &c, sizeof(*raw));
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 1;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_bpcSrv);
|
|
||||||
|
|
||||||
if(R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_bpcSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Result bpcGetSleepButtonState(BpcSleepButtonState *out) {
|
Result bpcGetSleepButtonState(BpcSleepButtonState *out) {
|
||||||
IpcCommand c;
|
u8 tmp = 0;
|
||||||
ipcInitialize(&c);
|
Result rc = serviceDispatchOut(&g_bpcSrv, 6, tmp);
|
||||||
|
|
||||||
struct {
|
if (R_SUCCEEDED(rc) && out) *out = tmp;
|
||||||
u64 magic;
|
|
||||||
u64 cmd_id;
|
|
||||||
} *raw;
|
|
||||||
|
|
||||||
raw = serviceIpcPrepareHeader(&g_bpcSrv, &c, sizeof(*raw));
|
|
||||||
raw->magic = SFCI_MAGIC;
|
|
||||||
raw->cmd_id = 6;
|
|
||||||
|
|
||||||
Result rc = serviceIpcDispatch(&g_bpcSrv);
|
|
||||||
|
|
||||||
if(R_SUCCEEDED(rc)) {
|
|
||||||
IpcParsedCommand r;
|
|
||||||
struct {
|
|
||||||
u64 magic;
|
|
||||||
u64 result;
|
|
||||||
u8 state;
|
|
||||||
} *resp;
|
|
||||||
|
|
||||||
serviceIpcParse(&g_bpcSrv, &r, sizeof(*resp));
|
|
||||||
resp = r.Raw;
|
|
||||||
|
|
||||||
rc = resp->result;
|
|
||||||
|
|
||||||
if (R_SUCCEEDED(rc)) {
|
|
||||||
*out = (BpcSleepButtonState)resp->state;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user