From 632f9866e6add98c70222b2c9f157ecc42c6629e Mon Sep 17 00:00:00 2001 From: Joel Date: Sat, 28 Oct 2017 04:12:16 -0500 Subject: [PATCH] Add a few more CFGI functions (#380) * CFGI_SecureInfoGetSerialNumber * CFGU_IsNFCSupported (IsFangateSupported) * CFGI_GetLocalFriendCodeSeed * CFGI_GetLocalFriendCodeSeedData --- libctru/include/3ds/services/cfgu.h | 24 ++++++++++++ libctru/source/services/cfgu.c | 58 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/libctru/include/3ds/services/cfgu.h b/libctru/include/3ds/services/cfgu.h index 926e005..d8db9dd 100644 --- a/libctru/include/3ds/services/cfgu.h +++ b/libctru/include/3ds/services/cfgu.h @@ -84,6 +84,12 @@ Result CFGU_GetCountryCodeString(u16 code, u16* string); */ Result CFGU_GetCountryCodeID(u16 string, u16* code); +/** + * @brief Checks if NFC (code name: fangate) is supported. + * @param isSupported pointer to the output the result to. + */ +Result CFGU_IsNFCSupported(bool* isSupported); + /** * @brief Gets a config info block with flags = 2. * @param size Size of the data to retrieve. @@ -170,3 +176,21 @@ Result CFGI_VerifySigLocalFriendCodeSeed(void); * @brief Verifies the RSA signature for the SecureInfo data already stored in memory. */ Result CFGI_VerifySigSecureInfo(void); + +/** + * @brief Gets the system's serial number. + * @param serial Pointer to output the serial to. (This is normally 0xF) + */ +Result CFGI_SecureInfoGetSerialNumber(u8 *serial); + +/** + * @brief Gets the 0x110-byte buffer containing the data for the LocalFriendCodeSeed. + * @param data Pointer to output the buffer. (The size must be at least 0x110-bytes) + */ +Result CFGI_GetLocalFriendCodeSeedData(u8 *data); + +/** + * @brief Gets the 64-bit local friend code seed. + * @param seed Pointer to write the friend code seed to. + */ +Result CFGI_GetLocalFriendCodeSeed(u64* seed); diff --git a/libctru/source/services/cfgu.c b/libctru/source/services/cfgu.c index 48ea174..cc960bc 100644 --- a/libctru/source/services/cfgu.c +++ b/libctru/source/services/cfgu.c @@ -133,6 +133,20 @@ Result CFGU_GetCountryCodeID(u16 string, u16* code) return (Result)cmdbuf[1]; } +Result CFGU_IsNFCSupported(bool* isSupported) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0xB,0,0); // 0x000B0000 + + if(R_FAILED(ret = svcSendSyncRequest(cfguHandle)))return ret; + + *isSupported = cmdbuf[2] & 0xFF; + + return (Result)cmdbuf[1]; +} + // See here for block IDs: // http://3dbrew.org/wiki/Config_Savegame#Configuration_blocks Result CFGU_GetConfigInfoBlk2(u32 size, u32 blkID, u8* outData) @@ -315,3 +329,47 @@ Result CFGI_VerifySigSecureInfo(void) return (Result)cmdbuf[1]; } + +Result CFGI_SecureInfoGetSerialNumber(u8 *serial) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x408,1,2); // 0x4080042 + cmdbuf[1] = 0xF; + cmdbuf[2] = IPC_Desc_Buffer(0xF, IPC_BUFFER_W); + cmdbuf[3] = (u32)serial; + + if(R_FAILED(ret = svcSendSyncRequest(cfguHandle)))return ret; + + return (Result)cmdbuf[1]; +} + +Result CFGI_GetLocalFriendCodeSeedData(u8 *data) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x404,1,2); // 0x4040042 + cmdbuf[1] = (u32)0x110; + cmdbuf[2] = IPC_Desc_Buffer((u32)0x110, IPC_BUFFER_W); + cmdbuf[3] = (u32)data; + + if(R_FAILED(ret = svcSendSyncRequest(cfguHandle)))return ret; + + return (Result)cmdbuf[1]; +} + +Result CFGI_GetLocalFriendCodeSeed(u64* seed) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = IPC_MakeHeader(0x405,0,0); // 0x4050000 + + if(R_FAILED(ret = svcSendSyncRequest(cfguHandle)))return ret; + + *seed = (u64)cmdbuf[2] | (u64)cmdbuf[3] << 32; + + return (Result)cmdbuf[1]; +}