2018-12-28 22:06:18 +01:00
|
|
|
#include "es.h"
|
|
|
|
|
|
|
|
#include <switch/arm/atomics.h>
|
|
|
|
#include <switch/kernel/ipc.h>
|
|
|
|
#include <switch/services/sm.h>
|
|
|
|
|
|
|
|
static Service g_esSrv;
|
|
|
|
static u64 g_esRefCnt;
|
|
|
|
|
|
|
|
Result esInitialize() {
|
|
|
|
atomicIncrement64(&g_esRefCnt);
|
|
|
|
|
|
|
|
if (serviceIsActive(&g_esSrv))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return smGetService(&g_esSrv, "es");
|
|
|
|
}
|
|
|
|
|
|
|
|
void esExit()
|
|
|
|
{
|
|
|
|
if (atomicDecrement64(&g_esRefCnt) == 0) {
|
|
|
|
serviceClose(&g_esSrv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Result esCountCommonTicket(u32 *num_tickets)
|
|
|
|
{
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
} *raw;
|
|
|
|
|
|
|
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 9;
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(&g_esSrv);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
ipcParse(&r);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
u32 num_tickets;
|
|
|
|
} *resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
*num_tickets = resp->num_tickets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 17:06:32 +01:00
|
|
|
return rc;
|
2018-12-28 22:06:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result esCountPersonalizedTicket(u32 *num_tickets)
|
|
|
|
{
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
} *raw;
|
|
|
|
|
|
|
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
|
|
|
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 10;
|
|
|
|
|
|
|
|
Result rc = serviceIpcDispatch(&g_esSrv);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
ipcParse(&r);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
u32 num_tickets;
|
|
|
|
} *resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
*num_tickets = resp->num_tickets;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-07 17:06:32 +01:00
|
|
|
return rc;
|
2018-12-28 22:06:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Result esListCommonTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize) {
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
ipcAddRecvBuffer(&c, outBuf, bufSize, BufferType_Normal);
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
} *raw;
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 11;
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
Result rc = serviceIpcDispatch(&g_esSrv);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
ipcParse(&r);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
u32 num_rights_ids_written;
|
|
|
|
} *resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
if (numRightsIdsWritten) *numRightsIdsWritten = resp->num_rights_ids_written;
|
|
|
|
}
|
|
|
|
}
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
Result esListPersonalizedTicket(u32 *numRightsIdsWritten, NcmRightsId *outBuf, size_t bufSize) {
|
|
|
|
IpcCommand c;
|
|
|
|
ipcInitialize(&c);
|
|
|
|
ipcAddRecvBuffer(&c, outBuf, bufSize, BufferType_Normal);
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 cmd_id;
|
|
|
|
} *raw;
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
raw = ipcPrepareHeader(&c, sizeof(*raw));
|
|
|
|
raw->magic = SFCI_MAGIC;
|
|
|
|
raw->cmd_id = 12;
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
Result rc = serviceIpcDispatch(&g_esSrv);
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
IpcParsedCommand r;
|
|
|
|
ipcParse(&r);
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u64 magic;
|
|
|
|
u64 result;
|
|
|
|
u32 num_rights_ids_written;
|
|
|
|
} *resp = r.Raw;
|
|
|
|
|
|
|
|
rc = resp->result;
|
|
|
|
|
|
|
|
if (R_SUCCEEDED(rc)) {
|
|
|
|
if (numRightsIdsWritten) *numRightsIdsWritten = resp->num_rights_ids_written;
|
|
|
|
}
|
|
|
|
}
|
2019-03-07 17:06:32 +01:00
|
|
|
|
2018-12-28 22:06:18 +01:00
|
|
|
return rc;
|
|
|
|
}
|