/**
* @file nfc.h
- * @brief NFC service.
+ * @brief NFC service. This can only be used with system-version >=9.3.0-X.
*/
#pragma once
+/// This is returned when the current state is invalid for this command.
+#define NFC_ERR_INVALID_STATE 0xC8A17600
+
+/// This is returned by nfcOpenAppData() when the appdata is uninitialized since nfcInitializeWriteAppData() wasn't used previously.
+#define NFC_ERR_APPDATA_UNINITIALIZED 0xC8A17620
+
+/// This is returned by nfcGetAmiiboSettings() when the amiibo wasn't setup by the amiibo Settings applet.
+#define NFC_ERR_AMIIBO_NOTSETUP 0xC8A17628
+
+/// This is returned by nfcOpenAppData() when the input AppID doesn't match the actual amiibo AppID.
+#define NFC_ERR_APPID_MISMATCH 0xC8A17638
+
+/// "Returned for HMAC-hash mismatch(data corruption), with HMAC-calculation input_buffer_size=0x34."
+#define NFC_ERR_DATACORRUPTION0 0xC8C1760C
+
+/// HMAC-hash mismatch with input_buffer_size=0x1DF, see here: https://www.3dbrew.org/wiki/Amiibo
+#define NFC_ERR_DATACORRUPTION1 0xC8A17618
+
+/// This can be used for nfcStartScanning().
+#define NFC_STARTSCAN_DEFAULTINPUT 0
+
+/// NFC operation type.
+typedef enum {
+ NFC_OpType_1 = 1, /// Unknown.
+ NFC_OpType_NFCTag = 2 /// This is the default.
+} NFC_OpType;
+
+typedef enum {
+ NFC_TagState_Uninitialized = 0, /// nfcInit() was not used yet.
+ NFC_TagState_ScanningStopped = 1, /// Not currently scanning for NFC tags. Set by nfcStopScanning() and nfcInit(), when successful.
+ NFC_TagState_Scanning = 2, /// Currently scanning for NFC tags. Set by nfcStartScanning() when successful.
+ NFC_TagState_InRange = 3, /// NFC tag is in range. The state automatically changes to this when the state was previously value 2, without using any NFC service commands.
+ NFC_TagState_OutOfRange = 4, /// NFC tag is now out of range, where the NFC tag was previously in range. This occurs automatically without using any NFC service commands. Once this state is entered, it won't automatically change to anything else when the tag is moved in range again. Hence, if you want to keep doing tag scanning after this, you must stop+start scanning.
+ NFC_TagState_DataReady = 5 /// NFC tag data was successfully loaded. This is set by nfcLoadAmiiboData() when successful.
+} NFC_TagState;
+
+/// Bit4-7 are always clear with nfcGetAmiiboSettings() due to "& 0xF".
+enum {
+ NFC_amiiboFlag_Setup = BIT(4), /// This indicates that the amiibo was setup with amiibo Settings. nfcGetAmiiboSettings() will return an all-zero struct when this is not set.
+ NFC_amiiboFlag_AppDataSetup = BIT(5) /// This indicates that the AppData was previously initialized via nfcInitializeWriteAppData(), that function can't be used again with this flag already set.
+};
+
+typedef struct {
+ u16 id_offset_size;/// "u16 size/offset of the below ID data. Normally this is 0x7. When this is <=10, this field is the size of the below ID data. When this is >10, this is the offset of the 10-byte ID data, relative to structstart+4+<offsetfield-10>. It's unknown in what cases this 10-byte ID data is used."
+ u8 unk_x2;//"Unknown u8, normally 0x0."
+ u8 unk_x3;//"Unknown u8, normally 0x2."
+ u8 id[0x28];//"ID data. When the above size field is 0x7, this is the 7-byte NFC tag UID, followed by all-zeros."
+} NFC_TagInfo;
+
+/// AmiiboSettings structure, see also here: https://3dbrew.org/wiki/NFC:GetAmiiboSettings
+typedef struct {
+ u8 mii[0x60];/// "Owner Mii."
+ u16 nickname[11];/// "UTF-16BE Amiibo nickname."
+ u8 flags;/// "This is plaintext_amiibosettingsdata[0] & 0xF." See also the NFC_amiiboFlag enums.
+ u8 countrycodeid;/// "This is plaintext_amiibosettingsdata[1]." "Country Code ID, from the system which setup this amiibo."
+ u16 setupdate_year;
+ u8 setupdate_month;
+ u8 setupdate_day;
+ u8 unk_x7c[0x2c];//Normally all-zero?
+} NFC_AmiiboSettings;
+
+/// AmiiboConfig structure, see also here: https://3dbrew.org/wiki/NFC:GetAmiiboConfig
+typedef struct {
+ u16 lastwritedate_year;
+ u8 lastwritedate_month;
+ u8 lastwritedate_day;
+ u16 write_counter;
+ u16 val_x6;
+ u8 val_x8;
+ u8 val_x9;
+ u16 val_xa;
+ u8 val_xc;
+ u8 pagex4_byte3;/// "This is byte[3] from NFC page[0x4]."
+ u8 appdata_size;/// "NFC module writes hard-coded u8 value 0xD8 here. This is the size of the Amiibo AppData, apps can use this with the AppData R/W commands. ..."
+ u8 zeros[0x31];/// "Unused / reserved: this is cleared by NFC module but never written after that."
+} NFC_AmiiboConfig;
+
+/// Used by nfcInitializeWriteAppData() internally, see also here: https://3dbrew.org/wiki/NFC:GetAppDataInitStruct
+typedef struct {
+ u8 data_x0[0xC];
+ u8 data_xc[0x30];/// "The data starting at struct offset 0xC is the 0x30-byte struct used by NFC:InitializeWriteAppData, sent by the user-process."
+} NFC_AppDataInitStruct;
+
+/// Used by nfcWriteAppData() internally, see also: https://3dbrew.org/wiki/NFC:WriteAppData
+typedef struct {
+ u8 id[10];//7-byte UID normally.
+ u8 id_size;
+ u8 unused_xb[0x15];
+} NFC_AppDataWriteStruct;
+
/**
* @brief Initializes NFC.
+ * @param type See the NFC_OpType enum.
*/
-Result nfcInit(void);
+Result nfcInit(NFC_OpType type);
/**
* @brief Shuts down NFC.
Handle nfcGetSessionHandle(void);
/**
- * @brief Initialize NFC module.
- * @param type Unknown, can be either value 0x1 or 0x2.
+ * @brief Starts scanning for NFC tags.
+ * @param inval Unknown. See NFC_STARTSCAN_DEFAULTINPUT.
*/
-Result NFC_Initialize(u8 type);
+Result nfcStartScanning(u16 inval);
/**
- * @brief Shutdown NFC module.
- * @param type Unknown.
+ * @brief Stops scanning for NFC tags.
*/
-Result NFC_Shutdown(u8 type);
+void nfcStopScanning(void);
/**
- * @brief O3DS starts communication with the O3DS NFC hardware. N3DS just checks state for this command.
+ * @brief Read amiibo NFC data and load in memory.
*/
-Result NFC_StartCommunication(void);
+Result nfcLoadAmiiboData(void);
/**
- * @brief O3DS stops communication with the O3DS NFC hardware. N3DS just uses code used internally by NFC:StopTagScanning for this.
+ * @brief If the tagstate is valid(NFC_TagState_DataReady or 6), it then sets the current tagstate to NFC_TagState_InRange.
*/
-Result NFC_StopCommunication(void);
+Result nfcResetTagScanState(void);
/**
- * @brief Starts scanning for NFC tags.
- * @param unknown Unknown.
+ * @brief This writes the amiibo data stored in memory to the actual amiibo data storage(which is normally the NFC data pages). This can only be used if NFC_LoadAmiiboData() was used previously.
*/
-Result NFC_StartTagScanning(u16 unknown);
+Result nfcUpdateStoredAmiiboData(void);
/**
- * @brief Stops scanning for NFC tags.
+ * @brief Returns the current NFC tag state.
+ * @param state Pointer to write NFC tag state.
*/
-Result NFC_StopTagScanning(void);
+Result nfcGetTagState(NFC_TagState *state);
/**
- * @brief Read Amiibo NFC data and load in memory.
+ * @brief Returns the current TagInfo.
+ * @param out Pointer to write the output TagInfo.
*/
-Result NFC_LoadAmiiboData(void);
+Result nfcGetTagInfo(NFC_TagInfo *out);
/**
- * @brief If the tagstate is valid, it then sets the current tagstate to 3.
+ * @brief Opens the appdata, when the amiibo appdata was previously initialized. This must be used before reading/writing the appdata. See also: https://3dbrew.org/wiki/NFC:OpenAppData
+ * @param amiibo_appid Amiibo AppID. See here: https://www.3dbrew.org/wiki/Amiibo
*/
-Result NFC_ResetTagScanState(void);
+Result nfcOpenAppData(u32 amiibo_appid);
/**
- * @brief Returns the current NFC tag state.
- * @param state Pointer to write NFC tag state.
- *
- * Tag state values:
- * - 0: NFC:Initialize was not used yet.
- * - 1: Not currently scanning for NFC tags. Set by NFC:StopTagScanning and NFC:Initialize, when successful.
- * - 2: Currently scanning for NFC tags. Set by NFC:StartTagScanning when successful.
- * - 3: NFC tag is in range. The state automatically changes to this when the state was previous value 3, without using any NFC service commands.
- * - 4: NFC tag is now out of range, where the NFC tag was previously in range. This occurs automatically without using any NFC service commands. Once this state is entered, it won't automatically change to anything else when the tag is moved in range again. Hence, if you want to keep doing tag scanning after this, you must stop+start scanning.
- * - 5: NFC tag data was successfully loaded. This is set by NFC:LoadAmiiboData when successful.
- */
-Result NFC_GetTagState(u8 *state);
+ * @brief This initializes the appdata using the specified input, when the appdata previously wasn't initialized. If the appdata is already initialized, you must first use the amiibo Settings applet menu option labeled "Delete amiibo Game Data". This automatically writes the amiibo data into the actual data storage(normally NFC data pages). See also nfcWriteAppData().
+ * @param amiibo_appid amiibo AppID. See also nfcOpenAppData().
+ * @param buf Input buffer.
+ * @param size Buffer size.
+ */
+Result nfcInitializeWriteAppData(u32 amiibo_appid, const void *buf, size_t size);
+
+/**
+ * @brief Reads the appdata. The size must be >=0xD8-bytes, but the actual used size is hard-coded to 0xD8. Note that areas of appdata which were never written to by applications are uninitialized in this output buffer.
+ * @param buf Output buffer.
+ * @param size Buffer size.
+ */
+Result nfcReadAppData(void *buf, size_t size);
+
+/**
+ * @brief Writes the appdata, after nfcOpenAppData() was used successfully. The size should be <=0xD8-bytes. See also: https://3dbrew.org/wiki/NFC:WriteAppData
+ * @param buf Input buffer.
+ * @param size Buffer size.
+ * @param taginfo TagInfo from nfcGetTagInfo().
+ */
+Result nfcWriteAppData(const void *buf, size_t size, NFC_TagInfo *taginfo);
+
+/**
+ * @brief Returns the current AmiiboSettings.
+ * @param out Pointer to write the output AmiiboSettings.
+ */
+Result nfcGetAmiiboSettings(NFC_AmiiboSettings *out);
+
+/**
+ * @brief Returns the current AmiiboConfig.
+ * @param out Pointer to write the output AmiiboConfig.
+ */
+Result nfcGetAmiiboConfig(NFC_AmiiboConfig *out);
+#include <string.h>\r
#include <3ds/types.h>\r
#include <3ds/result.h>\r
#include <3ds/svc.h>\r
#include <3ds/srv.h>\r
#include <3ds/synchronization.h>\r
#include <3ds/services/nfc.h>\r
+#include <3ds/services/apt.h>\r
#include <3ds/ipc.h>\r
\r
static Handle nfcHandle;\r
static int nfcRefCount;\r
+static NFC_OpType nfc_optype = NFC_OpType_NFCTag;\r
\r
-Result nfcInit(void)\r
+static Result NFC_Initialize(NFC_OpType type);\r
+static Result NFC_Shutdown(NFC_OpType type);\r
+\r
+static Result NFC_StartCommunication(void);\r
+static Result NFC_StopCommunication(void);\r
+static Result NFC_CommunicationGetStatus(u8 *out);\r
+static Result NFC_CommunicationGetResult(Result *out);\r
+\r
+static Result NFC_StartTagScanning(u16 unknown);\r
+static Result NFC_StopTagScanning(void);\r
+\r
+static Result NFC_InitializeWriteAppData(u32 amiibo_appid, NFC_AppDataInitStruct *initstruct, const void *buf, size_t size);\r
+static Result NFC_GetAppDataInitStruct(NFC_AppDataInitStruct *out);\r
+\r
+Result nfcInit(NFC_OpType type)\r
{\r
Result ret=0;\r
\r
if (AtomicPostIncrement(&nfcRefCount)) return 0;\r
\r
- ret = srvGetServiceHandle(&nfcHandle, "nfc:u");\r
+ ret = srvGetServiceHandle(&nfcHandle, "nfc:m");\r
+ if (R_FAILED(ret))ret = srvGetServiceHandle(&nfcHandle, "nfc:u");\r
if (R_SUCCEEDED(ret))\r
{\r
- ret = NFC_Initialize(0x02);\r
+ nfc_optype = type;\r
+ ret = NFC_Initialize(type);\r
if (R_FAILED(ret)) svcCloseHandle(nfcHandle);\r
}\r
if (R_FAILED(ret)) AtomicDecrement(&nfcRefCount);\r
void nfcExit(void)\r
{\r
if (AtomicDecrement(&nfcRefCount)) return;\r
+ NFC_Shutdown(nfc_optype);\r
svcCloseHandle(nfcHandle);\r
}\r
\r
return nfcHandle;\r
}\r
\r
-Result NFC_Initialize(u8 type)\r
+Result nfcStartScanning(u16 inval)\r
+{\r
+ Result ret, ret2;\r
+ u8 new3ds_flag = 0;\r
+ u8 status;\r
+\r
+ APT_CheckNew3DS(&new3ds_flag);\r
+\r
+ if(new3ds_flag==0)\r
+ {\r
+ ret = NFC_StartCommunication();\r
+ if(R_FAILED(ret))return ret;\r
+\r
+ while(1)\r
+ {\r
+ status = 0;\r
+ ret = NFC_CommunicationGetStatus(&status);\r
+ if(R_FAILED(ret))break;\r
+\r
+ if(status==1)//"Attempting to initialize Old3DS NFC adapter communication."\r
+ {\r
+ svcSleepThread(1000000*100);\r
+ continue;\r
+ }\r
+ else if(status==2)//"Old3DS NFC adapter communication initialization successfully finished."\r
+ {\r
+ break;\r
+ }\r
+\r
+ //An error occured with Old3DS NFC-adapter communication initialization.\r
+\r
+ ret = NFC_CommunicationGetResult(&ret2);\r
+ if(R_FAILED(ret))break;\r
+\r
+ return ret2;\r
+ }\r
+\r
+ if(R_FAILED(ret))return ret;\r
+ }\r
+\r
+ return NFC_StartTagScanning(inval);\r
+}\r
+\r
+void nfcStopScanning(void)\r
+{\r
+ u8 new3ds_flag = 0;\r
+\r
+ APT_CheckNew3DS(&new3ds_flag);\r
+\r
+ NFC_StopTagScanning();\r
+\r
+ if(new3ds_flag==0)\r
+ {\r
+ NFC_StopCommunication();\r
+ }\r
+}\r
+\r
+static Result NFC_Initialize(NFC_OpType type)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
\r
cmdbuf[0]=IPC_MakeHeader(0x1,1,0); // 0x10040\r
- cmdbuf[1]=type;\r
+ cmdbuf[1]=type & 0xff;\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
- \r
- ret = (Result)cmdbuf[1];\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_Shutdown(u8 type)\r
+static Result NFC_Shutdown(NFC_OpType type)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
\r
cmdbuf[0]=IPC_MakeHeader(0x2,1,0); // 0x20040\r
- cmdbuf[1]=type;\r
+ cmdbuf[1]=type & 0xff;\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
- \r
- ret = (Result)cmdbuf[1];\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_StartCommunication(void)\r
+static Result NFC_StartCommunication(void)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
cmdbuf[0]=IPC_MakeHeader(0x3,0,0); // 0x30000\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
- \r
- ret = (Result)cmdbuf[1];\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_StopCommunication(void)\r
+static Result NFC_StopCommunication(void)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
cmdbuf[0]=IPC_MakeHeader(0x4,0,0); // 0x40000\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
- \r
- ret = (Result)cmdbuf[1];\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_StartTagScanning(u16 unknown)\r
+static Result NFC_StartTagScanning(u16 unknown)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
cmdbuf[1]=unknown;\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
- \r
- ret = (Result)cmdbuf[1];\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_StopTagScanning(void)\r
+static Result NFC_StopTagScanning(void)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
cmdbuf[0]=IPC_MakeHeader(0x6,0,0); // 0x60000\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
- \r
- ret = (Result)cmdbuf[1];\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_LoadAmiiboData(void)\r
+Result nfcLoadAmiiboData(void)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
cmdbuf[0]=IPC_MakeHeader(0x7,0,0); // 0x70000\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
- \r
- ret = (Result)cmdbuf[1];\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_ResetTagScanState(void)\r
+Result nfcResetTagScanState(void)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
cmdbuf[0]=IPC_MakeHeader(0x8,0,0); // 0x80000\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ return ret;\r
+}\r
+\r
+Result nfcUpdateStoredAmiiboData(void)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x9,0,2); // 0x90002\r
+ cmdbuf[1]=IPC_Desc_CurProcessHandle();\r
\r
- ret = (Result)cmdbuf[1];\r
+ if(R_FAILED(ret=svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
\r
return ret;\r
}\r
\r
-Result NFC_GetTagState(u8 *state)\r
+Result nfcGetTagState(NFC_TagState *state)\r
{\r
Result ret=0;\r
u32* cmdbuf=getThreadCommandBuffer();\r
cmdbuf[0]=IPC_MakeHeader(0xD,0,0); // 0xD0000\r
\r
if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ if(R_SUCCEEDED(ret) && state)*state = cmdbuf[2] & 0xff;\r
+\r
+ return ret;\r
+}\r
+\r
+static Result NFC_CommunicationGetStatus(u8 *out)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0xF,0,0); // 0xF0000\r
\r
- ret = (Result)cmdbuf[1];\r
- *state = cmdbuf[2];\r
+ if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ if(R_SUCCEEDED(ret) && out)*out = cmdbuf[2];\r
+\r
+ return ret;\r
+}\r
+\r
+Result nfcGetTagInfo(NFC_TagInfo *out)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x11,0,0); // 0x110000\r
+ \r
+ if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ if(R_SUCCEEDED(ret) && out)memcpy(out, &cmdbuf[2], sizeof(NFC_TagInfo));\r
+\r
+ return ret;\r
+}\r
+\r
+static Result NFC_CommunicationGetResult(Result *out)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x12,0,0); // 0x120000\r
+ \r
+ if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ if(R_SUCCEEDED(ret) && out)*out = cmdbuf[2];\r
+\r
+ return ret;\r
+}\r
+\r
+Result nfcOpenAppData(u32 amiibo_appid)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x13,1,0); // 0x130040\r
+ cmdbuf[1]=amiibo_appid;\r
+ \r
+ if(R_FAILED(ret=svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ return ret;\r
+}\r
+\r
+Result nfcInitializeWriteAppData(u32 amiibo_appid, const void *buf, size_t size)\r
+{\r
+ Result ret=0;\r
+ NFC_AppDataInitStruct initstruct;\r
+\r
+ ret = NFC_GetAppDataInitStruct(&initstruct);\r
+ if(R_FAILED(ret))return ret;\r
+\r
+ return NFC_InitializeWriteAppData(amiibo_appid, &initstruct, buf, size);\r
+}\r
+\r
+static Result NFC_InitializeWriteAppData(u32 amiibo_appid, NFC_AppDataInitStruct *initstruct, const void *buf, size_t size)\r
+{\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x14,14,4); // 0x140384\r
+ cmdbuf[1]=amiibo_appid;\r
+ cmdbuf[2]=size;\r
+ memcpy(&cmdbuf[3], initstruct->data_xc, sizeof(initstruct->data_xc));\r
+ cmdbuf[15]=IPC_Desc_CurProcessHandle();\r
+ cmdbuf[17]=IPC_Desc_StaticBuffer(size, 0);\r
+ cmdbuf[18]=(u32)buf;\r
+\r
+ Result ret=0;\r
+ if(R_FAILED(ret=svcSendSyncRequest(nfcHandle)))return ret;\r
+\r
+ return cmdbuf[1];\r
+}\r
+\r
+Result nfcReadAppData(void *buf, size_t size)\r
+{\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+ u32 saved_threadstorage[2];\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x15,1,0); // 0x150040\r
+ cmdbuf[1]=size;\r
+\r
+ u32 * staticbufs = getThreadStaticBuffers();\r
+ saved_threadstorage[0] = staticbufs[0];\r
+ saved_threadstorage[1] = staticbufs[1];\r
+\r
+ staticbufs[0] = IPC_Desc_StaticBuffer(size,0);\r
+ staticbufs[1] = (u32)buf;\r
+\r
+ Result ret=0;\r
+ ret=svcSendSyncRequest(nfcHandle);\r
+\r
+ staticbufs[0] = saved_threadstorage[0];\r
+ staticbufs[1] = saved_threadstorage[1];\r
+\r
+ if(R_FAILED(ret))return ret;\r
+\r
+ ret = cmdbuf[1];\r
+\r
+ return ret;\r
+}\r
+\r
+Result nfcWriteAppData(const void *buf, size_t size, NFC_TagInfo *taginfo)\r
+{\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+ NFC_AppDataWriteStruct writestruct;\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x16,9,2); // 0x160242\r
+ cmdbuf[1]=size;\r
+ cmdbuf[10]=IPC_Desc_StaticBuffer(size, 0);\r
+ cmdbuf[11]=(u32)buf;\r
+\r
+ if(taginfo==NULL)return -1;\r
+ if(taginfo->id_offset_size>10)return -2;\r
+\r
+ memset(&writestruct, 0, sizeof(NFC_AppDataWriteStruct));\r
+ writestruct.id_size = taginfo->id_offset_size;\r
+ memcpy(writestruct.id, taginfo->id, sizeof(writestruct.id));\r
+\r
+ memcpy(&cmdbuf[2], &writestruct, sizeof(NFC_AppDataWriteStruct));\r
+\r
+ Result ret=0;\r
+ if(R_FAILED(ret=svcSendSyncRequest(nfcHandle)))return ret;\r
+\r
+ return cmdbuf[1];\r
+}\r
+\r
+Result nfcGetAmiiboSettings(NFC_AmiiboSettings *out)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x17,0,0); // 0x170000\r
+ \r
+ if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ if(R_SUCCEEDED(ret) && out)memcpy(out, &cmdbuf[2], sizeof(NFC_AmiiboSettings));\r
+\r
+ return ret;\r
+}\r
+\r
+Result nfcGetAmiiboConfig(NFC_AmiiboConfig *out)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x18,0,0); // 0x180000\r
+ \r
+ if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ if(R_SUCCEEDED(ret) && out)memcpy(out, &cmdbuf[2], sizeof(NFC_AmiiboConfig));\r
+\r
+ return ret;\r
+}\r
+\r
+static Result NFC_GetAppDataInitStruct(NFC_AppDataInitStruct *out)\r
+{\r
+ Result ret=0;\r
+ u32* cmdbuf=getThreadCommandBuffer();\r
+\r
+ cmdbuf[0]=IPC_MakeHeader(0x19,0,0); // 0x190000\r
+ \r
+ if(R_FAILED(ret = svcSendSyncRequest(nfcHandle)))return ret;\r
+ ret = cmdbuf[1];\r
+\r
+ if(R_SUCCEEDED(ret) && out)memcpy(out, &cmdbuf[2], sizeof(NFC_AppDataInitStruct));\r
\r
return ret;\r
}\r