Skip to content

Commit

Permalink
Implement cfgs and frd functions from Reisyukaku's ctrulib
Browse files Browse the repository at this point in the history
  • Loading branch information
joel16 committed Oct 12, 2016
1 parent 96507dc commit 83741b6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
26 changes: 26 additions & 0 deletions source/cfgs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "cfgs.h"

Result cfgsInit() //Already initialized with CFGUinit();
{
return srvGetServiceHandle(&cfgHandle, "cfg:s");
}

Result cfgsExit()
{
return svcCloseHandle(cfgHandle);
}

Result cfgsSecureInfoGetSerialNo(char *serial)
{
Result ret = 0;
u32 *cmdbuf = getThreadCommandBuffer();

cmdbuf[0] = IPC_MakeHeader(0x408,1,2); // 0x10082
cmdbuf[1] = 0xF;
cmdbuf[2] = 12 | (0xF << 4);
cmdbuf[3] = (u32)serial;

if(R_FAILED(ret = svcSendSyncRequest(cfgHandle)))return ret;

return (Result)cmdbuf[1];
}
7 changes: 7 additions & 0 deletions source/cfgs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include <3ds.h>

Handle cfgHandle;

Result cfgsInit();
Result cfgsExit();
Result cfgsSecureInfoGetSerialNo(char *serial);
58 changes: 58 additions & 0 deletions source/frd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "frd.h"

Result frdInit(u32 sdkVer)
{
srvGetServiceHandle(&frdHandle, "frd:u");
srvGetServiceHandle(&frdHandle, "frd:n");
srvGetServiceHandle(&frdHandle, "frd:a");
return frdSetClientSdkVersion(sdkVer);
}

Result frdExit()
{
return svcCloseHandle(frdHandle);
}

Result frdSetClientSdkVersion(u32 sdkVer)
{
Result ret=0;
u32 *cmdbuf = getThreadCommandBuffer();

cmdbuf[0] = IPC_MakeHeader(0x32,1,2); // 0x00320042
cmdbuf[1] = sdkVer;
cmdbuf[2] = 0x20;

if(R_FAILED(ret = svcSendSyncRequest(frdHandle)))return ret;

return (Result)cmdbuf[1];
}

u64 frdPrincipalIdToFriendCode(u64 *fc, u64 pid)
{
Result ret=0;
u32 *cmdbuf = getThreadCommandBuffer();

cmdbuf[0] = IPC_MakeHeader(0x24,1,0); // 0x00240040
cmdbuf[1] = pid;

if(R_FAILED(ret = svcSendSyncRequest(frdHandle)))return ret;

*fc = (u64)cmdbuf[2];

return (Result)cmdbuf[1];
}


Result frdGetMyFriendKey(FriendKey *key)
{
Result ret=0;
u32 *cmdbuf = getThreadCommandBuffer();

cmdbuf[0] = IPC_MakeHeader(5,0,0); // 0x00050000

if(R_FAILED(ret = svcSendSyncRequest(frdHandle)))return ret;

memcpy(key, &cmdbuf[2], 0x10);

return (Result)cmdbuf[1];
}
16 changes: 16 additions & 0 deletions source/frd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include <3ds.h>
#include <string.h>

Handle frdHandle;

typedef struct
{
u32 principalId;
u64 localFriendCode;
} FriendKey;

Result frdInit();
Result frdExit();
Result frdSetClientSdkVersion(u32 sdkVer);
u64 frdPrincipalIdToFriendCode(u64 *fc, u64 pid);
Result frdGetMyFriendKey(FriendKey *key);

0 comments on commit 83741b6

Please sign in to comment.