libctru  v2.4.1
Data Structures | Macros | Enumerations | Functions
nfc.h File Reference

NFC service. More...

Go to the source code of this file.

Data Structures

struct  NFC_TagInfo
 
struct  NFC_AmiiboSettings
 AmiiboSettings structure, see also here: https://3dbrew.org/wiki/NFC:GetAmiiboSettings. More...
 
struct  NFC_AmiiboConfig
 AmiiboConfig structure, see also here: https://3dbrew.org/wiki/NFC:GetAmiiboConfig. More...
 
struct  NFC_AppDataInitStruct
 Used by nfcInitializeWriteAppData() internally, see also here: https://3dbrew.org/wiki/NFC:GetAppDataInitStruct. More...
 
struct  NFC_AppDataWriteStruct
 Used by nfcWriteAppData() internally, see also: https://3dbrew.org/wiki/NFC:WriteAppData. More...
 

Macros

#define NFC_ERR_INVALID_STATE   0xC8A17600
 This is returned when the current state is invalid for this command.
 
#define NFC_ERR_APPDATA_UNINITIALIZED   0xC8A17620
 This is returned by nfcOpenAppData() when the appdata is uninitialized since nfcInitializeWriteAppData() wasn't used previously.
 
#define NFC_ERR_AMIIBO_NOTSETUP   0xC8A17628
 This is returned by nfcGetAmiiboSettings() when the amiibo wasn't setup by the amiibo Settings applet.
 
#define NFC_ERR_APPID_MISMATCH   0xC8A17638
 This is returned by nfcOpenAppData() when the input AppID doesn't match the actual amiibo AppID.
 
#define NFC_ERR_DATACORRUPTION0   0xC8C1760C
 "Returned for HMAC-hash mismatch(data corruption), with HMAC-calculation input_buffer_size=0x34."
 
#define NFC_ERR_DATACORRUPTION1   0xC8A17618
 HMAC-hash mismatch with input_buffer_size=0x1DF, see here: https://www.3dbrew.org/wiki/Amiibo.
 
#define NFC_STARTSCAN_DEFAULTINPUT   0
 This can be used for nfcStartScanning().
 

Enumerations

enum  NFC_OpType {
  NFC_OpType_1 = 1 ,
  NFC_OpType_NFCTag = 2 ,
  NFC_OpType_RawNFC = 3
}
 NFC operation type. More...
 
enum  NFC_TagState {
  NFC_TagState_Uninitialized = 0 ,
  NFC_TagState_ScanningStopped = 1 ,
  NFC_TagState_Scanning = 2 ,
  NFC_TagState_InRange = 3 ,
  NFC_TagState_OutOfRange = 4 ,
  NFC_TagState_DataReady = 5
}
 
enum  {
  NFC_amiiboFlag_Setup = BIT(4) ,
  NFC_amiiboFlag_AppDataSetup = BIT(5)
}
 Bit4-7 are always clear with nfcGetAmiiboSettings() due to "& 0xF". More...
 

Functions

Result nfcInit (NFC_OpType type)
 Initializes NFC. More...
 
void nfcExit (void)
 Shuts down NFC.
 
Handle nfcGetSessionHandle (void)
 Gets the NFC service handle. More...
 
Result nfcStartScanning (u16 inval)
 Starts scanning for NFC tags. More...
 
void nfcStopScanning (void)
 Stops scanning for NFC tags.
 
Result nfcLoadAmiiboData (void)
 Read amiibo NFC data and load in memory.
 
Result nfcResetTagScanState (void)
 If the tagstate is valid(NFC_TagState_DataReady or 6), it then sets the current tagstate to NFC_TagState_InRange.
 
Result nfcUpdateStoredAmiiboData (void)
 This writes the amiibo data stored in memory to the actual amiibo data storage(which is normally the NFC data pages). More...
 
Result nfcGetTagState (NFC_TagState *state)
 Returns the current NFC tag state. More...
 
Result nfcGetTagInfo (NFC_TagInfo *out)
 Returns the current TagInfo. More...
 
Result nfcOpenAppData (u32 amiibo_appid)
 Opens the appdata, when the amiibo appdata was previously initialized. More...
 
Result nfcInitializeWriteAppData (u32 amiibo_appid, const void *buf, size_t size)
 This initializes the appdata using the specified input, when the appdata previously wasn't initialized. More...
 
Result nfcReadAppData (void *buf, size_t size)
 Reads the appdata. More...
 
Result nfcWriteAppData (const void *buf, size_t size, NFC_TagInfo *taginfo)
 Writes the appdata, after nfcOpenAppData() was used successfully. More...
 
Result nfcGetAmiiboSettings (NFC_AmiiboSettings *out)
 Returns the current AmiiboSettings. More...
 
Result nfcGetAmiiboConfig (NFC_AmiiboConfig *out)
 Returns the current AmiiboConfig. More...
 
Result nfcStartOtherTagScanning (u16 unk0, u32 unk1)
 Starts scanning for NFC tags when initialized with NFC_OpType_RawNFC. More...
 
Result nfcSendTagCommand (const void *inbuf, size_t insize, void *outbuf, size_t outsize, size_t *actual_transfer_size, u64 microseconds)
 This sends a raw NFC command to the tag. More...
 
Result nfcCmd21 (void)
 Unknown. More...
 
Result nfcCmd22 (void)
 Unknown. More...
 

Detailed Description

NFC service.

This can only be used with system-version >=9.3.0-X.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Bit4-7 are always clear with nfcGetAmiiboSettings() due to "& 0xF".

Enumerator
NFC_amiiboFlag_AppDataSetup 

This indicates that the amiibo was setup with amiibo Settings. nfcGetAmiiboSettings() will return an all-zero struct when this is not set.

◆ NFC_OpType

enum NFC_OpType

NFC operation type.

Enumerator
NFC_OpType_NFCTag 

Unknown.

NFC_OpType_RawNFC 

This is the default.

◆ NFC_TagState

Enumerator
NFC_TagState_ScanningStopped 

nfcInit() was not used yet.

NFC_TagState_Scanning 

Not currently scanning for NFC tags. Set by nfcStopScanning() and nfcInit(), when successful.

NFC_TagState_InRange 

Currently scanning for NFC tags. Set by nfcStartScanning() when successful.

NFC_TagState_OutOfRange 

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_DataReady 

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.

Function Documentation

◆ nfcCmd21()

Result nfcCmd21 ( void  )

Unknown.

This can only be used when initialized with NFC_OpType_RawNFC, and when the TagState is NFC_TagState_InRange.

◆ nfcCmd22()

Result nfcCmd22 ( void  )

Unknown.

This can only be used when initialized with NFC_OpType_RawNFC, and when the TagState is NFC_TagState_InRange.

◆ nfcGetAmiiboConfig()

Result nfcGetAmiiboConfig ( NFC_AmiiboConfig out)

Returns the current AmiiboConfig.

Parameters
outPointer to write the output AmiiboConfig.
Examples
nfc/source/main.c.

◆ nfcGetAmiiboSettings()

Result nfcGetAmiiboSettings ( NFC_AmiiboSettings out)

Returns the current AmiiboSettings.

Parameters
outPointer to write the output AmiiboSettings.
Examples
nfc/source/main.c.

◆ nfcGetSessionHandle()

Handle nfcGetSessionHandle ( void  )

Gets the NFC service handle.

Returns
The NFC service handle.

◆ nfcGetTagInfo()

Result nfcGetTagInfo ( NFC_TagInfo out)

Returns the current TagInfo.

Parameters
outPointer to write the output TagInfo.
Examples
nfc/source/main.c.

◆ nfcGetTagState()

Result nfcGetTagState ( NFC_TagState state)

Returns the current NFC tag state.

Parameters
statePointer to write NFC tag state.
Examples
nfc/source/main.c.

◆ nfcInit()

Result nfcInit ( NFC_OpType  type)

Initializes NFC.

Parameters
typeSee the NFC_OpType enum.
Examples
nfc/source/main.c.

◆ nfcInitializeWriteAppData()

Result nfcInitializeWriteAppData ( u32  amiibo_appid,
const void *  buf,
size_t  size 
)

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().

Parameters
amiibo_appidamiibo AppID. See also nfcOpenAppData().
bufInput buffer.
sizeBuffer size.
Examples
nfc/source/main.c.

◆ nfcOpenAppData()

Result nfcOpenAppData ( u32  amiibo_appid)

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

Parameters
amiibo_appidAmiibo AppID. See here: https://www.3dbrew.org/wiki/Amiibo
Examples
nfc/source/main.c.

◆ nfcReadAppData()

Result nfcReadAppData ( void *  buf,
size_t  size 
)

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.

Parameters
bufOutput buffer.
sizeBuffer size.
Examples
nfc/source/main.c.

◆ nfcSendTagCommand()

Result nfcSendTagCommand ( const void *  inbuf,
size_t  insize,
void *  outbuf,
size_t  outsize,
size_t *  actual_transfer_size,
u64  microseconds 
)

This sends a raw NFC command to the tag.

This can only be used when initialized with NFC_OpType_RawNFC, and when the TagState is NFC_TagState_InRange. See also: https://www.3dbrew.org/wiki/NFC:SendTagCommand

Parameters
inbufInput buffer.
insizeSize of the input buffer.
outbufOutput buffer.
outsizeSize of the output buffer.
actual_transfer_sizeOptional output ptr to write the actual output-size to, can be NULL.
microsecondsTiming-related field in microseconds.

◆ nfcStartOtherTagScanning()

Result nfcStartOtherTagScanning ( u16  unk0,
u32  unk1 
)

Starts scanning for NFC tags when initialized with NFC_OpType_RawNFC.

See also: https://www.3dbrew.org/wiki/NFC:StartOtherTagScanning

Parameters
unk0Same as nfcStartScanning() input.
unk1Unknown.

◆ nfcStartScanning()

Result nfcStartScanning ( u16  inval)

Starts scanning for NFC tags.

Parameters
invalUnknown. See NFC_STARTSCAN_DEFAULTINPUT.
Examples
nfc/source/main.c.

◆ nfcUpdateStoredAmiiboData()

Result nfcUpdateStoredAmiiboData ( void  )

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.

Examples
nfc/source/main.c.

◆ nfcWriteAppData()

Result nfcWriteAppData ( const void *  buf,
size_t  size,
NFC_TagInfo taginfo 
)

Writes the appdata, after nfcOpenAppData() was used successfully.

The size should be <=0xD8-bytes. See also: https://3dbrew.org/wiki/NFC:WriteAppData

Parameters
bufInput buffer.
sizeBuffer size.
taginfoTagInfo from nfcGetTagInfo().
Examples
nfc/source/main.c.