libnx v4.9.0
Loading...
Searching...
No Matches
nfc.h
Go to the documentation of this file.
1/**
2 * @file nfc.h
3 * @brief Nintendo Figurine (amiibo) Platform (nfp:user) service IPC wrapper.
4 * @author averne
5 * @copyright libnx Authors
6 */
7
8#pragma once
9#include "../types.h"
10#include "../sf/service.h"
11#include "../services/mii.h"
12
13/// NfpServiceType
14typedef enum {
15 NfpServiceType_User = 0, ///< Initializes nfp:user.
16 NfpServiceType_Debug = 1, ///< Initializes nfp:dbg.
17 NfpServiceType_System = 2, ///< Initializes nfp:sys.
19
20/// NfcServiceType
21typedef enum {
22 NfcServiceType_User = 0, ///< Initializes nfc:user.
23 NfcServiceType_System = 1, ///< Initializes nfc:sys.
25
26typedef enum {
27 NfpState_NonInitialized = 0,
28 NfpState_Initialized = 1,
29} NfpState;
30
31typedef enum {
32 NfcState_NonInitialized = 0,
33 NfcState_Initialized = 1,
34} NfcState;
35
36typedef enum {
37 NfpDeviceState_Initialized = 0,
38 NfpDeviceState_SearchingForTag = 1,
39 NfpDeviceState_TagFound = 2,
40 NfpDeviceState_TagRemoved = 3,
41 NfpDeviceState_TagMounted = 4,
42 NfpDeviceState_Unavailable = 5,
43 NfpDeviceState_Finalized = 6,
44} NfpDeviceState;
45
46typedef enum {
47 NfcDeviceState_Initialized = 0,
48 NfcDeviceState_SearchingForTag = 1,
49 NfcDeviceState_TagFound = 2,
50 NfcDeviceState_TagRemoved = 3,
51 NfcDeviceState_TagMounted = 4,
52 NfcDeviceState_Unavailable = 5,
53 NfcDeviceState_Finalized = 6,
54} NfcDeviceState;
55
56typedef enum {
57 NfpApplicationAreaVersion_3DS = 0,
58 NfpApplicationAreaVersion_WiiU = 1,
59 NfpApplicationAreaVersion_3DSv2 = 2,
60 NfpApplicationAreaVersion_Switch = 3,
61 NfpApplicationAreaVersion_NotSet = 0xFF,
62} NfpApplicationAreaVersion;
63
64typedef enum {
65 NfpDeviceType_Amiibo = 0,
66} NfpDeviceType;
67
68typedef enum {
69 NfpMountTarget_Rom = 1,
70 NfpMountTarget_Ram = 2,
71 NfpMountTarget_All = 3,
72} NfpMountTarget;
73
74typedef enum {
75 NfcProtocol_None = 0,
76 NfcProtocol_TypeA = BIT(0), ///< ISO14443A
77 NfcProtocol_TypeB = BIT(1), ///< ISO14443B
78 NfcProtocol_TypeF = BIT(2), ///< Sony FeliCa
79 NfcProtocol_All = 0xFFFFFFFF,
81
82typedef enum {
83 NfcTagType_None = 0,
84 NfcTagType_Type1 = BIT(0), ///< ISO14443A RW. Topaz
85 NfcTagType_Type2 = BIT(1), ///< ISO14443A RW. Ultralight, NTAGX, ST25TN
86 NfcTagType_Type3 = BIT(2), ///< ISO14443A RW/RO. Sony FeliCa
87 NfcTagType_Type4A = BIT(3), ///< ISO14443A RW/RO. DESFire
88 NfcTagType_Type4B = BIT(4), ///< ISO14443B RW/RO. DESFire
89 NfcTagType_Type5 = BIT(5), ///< ISO15693 RW/RO. SLI, SLIX, ST25TV
90 NfcTagType_Mifare = BIT(6), ///< Mifare clasic. Skylanders
91 NfcTagType_All = 0xFFFFFFFF,
93
94typedef enum {
95 NfcMifareCommand_Read = 0x30,
96 NfcMifareCommand_AuthA = 0x60,
97 NfcMifareCommand_AuthB = 0x61,
98 NfcMifareCommand_Write = 0xA0,
99 NfcMifareCommand_Transfer = 0xB0,
100 NfcMifareCommand_Decrement = 0xC0,
101 NfcMifareCommand_Increment = 0xC1,
102 NfcMifareCommand_Store = 0xC2,
103} NfcMifareCommand;
104
105typedef struct {
106 u8 uuid[10];
107 u8 uuid_length;
108 u8 reserved1[0x15];
109 u32 protocol;
110 u32 tag_type;
111 u8 reserved2[0x30];
113
114typedef struct {
115 u8 uuid[10];
116 u8 uuid_length;
117 u8 reserved1[0x15];
118 u32 protocol;
119 u32 tag_type;
120 u8 reserved2[0x30];
122
123typedef struct {
124 u16 last_write_year;
125 u8 last_write_month;
126 u8 last_write_day;
127 u16 write_counter;
128 u16 version;
129 u32 application_area_size;
130 u8 reserved[0x34];
132
133typedef struct {
134 u8 amiibo_id[0x8];
135 u8 reserved[0x38];
137
138typedef struct {
139 MiiCharInfo mii;
140 u16 first_write_year;
141 u8 first_write_month;
142 u8 first_write_day;
143 char amiibo_name[(10*4)+1]; ///< utf-8, null-terminated
144 u8 font_region;
145 u8 reserved[0x7A];
147
148typedef struct {
149 u8 mii_store_data[0x44];
150 u16 first_write_year;
151 u8 first_write_month;
152 u8 first_write_day;
153 char amiibo_name[(10*4)+1]; ///< utf-8, null-terminated
154 u8 font_region;
155 u8 reserved[0x8E];
157
158typedef struct {
159 u64 application_id;
160 u32 application_area_id;
161 u16 crc_change_counter;
162 u8 flags;
163 u8 tag_type;
164 u8 application_area_version;
165 u8 reserved[0x2F];
167
168typedef struct {
169 u8 magic;
170 u8 reserved1[0x1];
171 u8 write_counter;
172 u8 reserved2[0x1];
173 u32 settings_crc;
174 u8 reserved3[0x38];
175 u16 last_write_year;
176 u8 last_write_month;
177 u8 last_write_day;
178 u16 application_write_counter;
179 u16 version;
180 u32 application_area_size;
181 u8 reserved4[0x34];
182 MiiCharInfo mii;
183 MiiNfpStoreDataExtension mii_store_data_extension;
184 u16 first_write_year;
185 u8 first_write_month;
186 u8 first_write_day;
187 u16 amiibo_name[10+1]; ///< utf-16, null-terminated
188 u8 settings_flag; ///< bit4 = amiibo was initialized in console settings, bit5 = has application area
189 u8 unknown1; ///< Normally zero
190 u32 register_info_crc;
191 u32 unknown2[0x5]; ///< Normally zero
192 u8 reserved5[0x64];
193 u64 application_id;
194 u32 access_id;
195 u16 settings_crc_counter;
196 u8 font_region;
197 u8 tag_type;
198 u8 console_type;
199 u8 application_id_byte; ///< (Original Program ID >> 0x24) & 0xF byte (Program ID has this byte swapped with console type)
200 u8 reserved6[0x2E];
201 u8 application_area[0xD8];
203
204typedef struct {
205 u8 mifare_command;
206 u8 unknown; ///< Usually 1
207 u8 reserved1[0x6];
208 u8 sector_key[0x6];
209 u8 reserved2[0x2];
211
212typedef struct {
213 u8 sector_number;
214 u8 reserved[0x7];
215 NfcSectorKey sector_key;
217
218typedef struct {
219 u8 data[0x10];
220 u8 sector_number;
221 u8 reserved[0x7];
223
224typedef struct {
225 u8 data[0x10];
226 u8 sector_number;
227 u8 reserved[0x7];
228 NfcSectorKey sector_key;
230
231typedef struct {
232 u64 version;
233 u64 reserved[3];
235
236/// Nfc/Nfp DeviceHandle
237typedef struct {
238 u8 handle[0x8]; ///< Handle.
240
241/// Initialize nfp:*.
243
244/// Exit nfp:*.
245void nfpExit(void);
246
247/// Initialize nfc:*.
249
250/// Exit nfc:*.
251void nfcExit(void);
252
253/// Initialize nfc:mf:u.
255
256/// Exit nfc:mf:u.
257void nfcMfExit(void);
258
259/// Gets the Service object for the actual nfp:* service session.
261
262/// Gets the Service object for the interface from nfp:*.
264
265/// Gets the Service object for the actual nfc:* service session.
267
268/// Gets the Service object for the interface from nfc:*.
270
271/// Gets the Service object for the actual nfc:mf:u service session.
273
274/// Gets the Service object for the interface from nfc:mf:u.
276
277Result nfpListDevices(s32 *total_out, NfcDeviceHandle *out, s32 count);
278Result nfpStartDetection(const NfcDeviceHandle *handle);
279Result nfpStopDetection(const NfcDeviceHandle *handle);
280Result nfpMount(const NfcDeviceHandle *handle, NfpDeviceType device_type, NfpMountTarget mount_target);
281Result nfpUnmount(const NfcDeviceHandle *handle);
282
283/// Only available with [4.0.0+].
284Result nfcListDevices(s32 *total_out, NfcDeviceHandle *out, s32 count);
285/// Only available with [4.0.0+].
287/// Only available with [4.0.0+].
289
290Result nfcMfListDevices(s32 *total_out, NfcDeviceHandle *out, s32 count);
291Result nfcMfStartDetection(const NfcDeviceHandle *handle);
292Result nfcMfStopDetection(const NfcDeviceHandle *handle);
293
294/// Not available with ::NfpServiceType_System.
296
297/// Not available with ::NfpServiceType_System.
298Result nfpGetApplicationArea(const NfcDeviceHandle *handle, void* buf, size_t buf_size, u32 *out_size);
299
300/// Not available with ::NfpServiceType_System.
301Result nfpSetApplicationArea(const NfcDeviceHandle *handle, const void* buf, size_t buf_size);
302Result nfpFlush(const NfcDeviceHandle *handle);
303Result nfpRestore(const NfcDeviceHandle *handle);
304
305/// Not available with ::NfpServiceType_System.
306Result nfpCreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void* buf, size_t buf_size);
307
308/// Not available with ::NfpServiceType_System.
309/// Only available with [3.0.0+].
310Result nfpRecreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void* buf, size_t buf_size);
311
312/// Not available with ::NfpServiceType_System.
313Result nfpGetApplicationAreaSize(const NfcDeviceHandle *handle, u32 *out_app_area_size);
314
315/// Not available with ::NfpServiceType_User.
317
318/// Not available with ::NfpServiceType_User.
320
321Result nfpGetTagInfo(const NfcDeviceHandle *handle, NfpTagInfo *out);
322Result nfpGetRegisterInfo(const NfcDeviceHandle *handle, NfpRegisterInfo *out);
323Result nfpGetCommonInfo(const NfcDeviceHandle *handle, NfpCommonInfo *out);
324Result nfpGetModelInfo(const NfcDeviceHandle *handle, NfpModelInfo *out);
325/// Not available with ::NfpServiceType_User.
327
328/// Only available with [4.0.0+].
330
331Result nfcMfGetTagInfo(const NfcDeviceHandle *handle, NfcTagInfo *out);
332
333/// Returned event will have autoclear off.
335/// Returned event will have autoclear off.
337
338/// Returned event will have autoclear off.
339/// Only available with [4.0.0+].
341/// Returned event will have autoclear off.
342/// Only available with [4.0.0+].
344
345/// Returned event will have autoclear off.
347/// Returned event will have autoclear off.
349
350Result nfpGetState(NfpState *out);
351Result nfpGetDeviceState(const NfcDeviceHandle *handle, NfpDeviceState *out);
352Result nfpGetNpadId(const NfcDeviceHandle *handle, u32 *out);
353
354/// Only available with [4.0.0+].
355Result nfcGetState(NfcState *out);
356/// Only available with [4.0.0+].
357Result nfcGetDeviceState(const NfcDeviceHandle *handle, NfcDeviceState *out);
358/// Only available with [4.0.0+].
360
361Result nfcMfGetState(NfcState *out);
362Result nfcMfGetDeviceState(const NfcDeviceHandle *handle, NfcDeviceState *out);
363Result nfcMfGetNpadId(const NfcDeviceHandle *handle, u32 *out);
364
365/// Returned event will have autoclear on.
366/// Only available with [3.0.0+].
368/// Returned event will have autoclear on.
369/// Only available with [4.0.0+].
371/// Returned event will have autoclear on.
373
374/// Not available with ::NfpServiceType_User.
376
377/// Not available with ::NfpServiceType_User.
379/// Not available with ::NfpServiceType_User.
380Result nfpSetRegisterInfoPrivate(const NfcDeviceHandle *handle, const NfpRegisterInfoPrivate *register_info_private);
381/// Not available with ::NfpServiceType_User.
383
384/// Only available with ::NfpServiceType_Debug.
386/// Only available with ::NfpServiceType_Debug.
387Result nfpSetAll(const NfcDeviceHandle *handle, const NfpData *nfp_data);
388
389/// Only available with ::NfpServiceType_Debug.
391/// Only available with ::NfpServiceType_Debug.
392Result nfpBreakTag(const NfcDeviceHandle *handle, u32 break_type);
393/// Only available with ::NfpServiceType_Debug.
394Result nfpReadBackupData(const NfcDeviceHandle *handle, void* out_buf, size_t buf_size, u32 *out_size);
395/// Only available with ::NfpServiceType_Debug.
396Result nfpWriteBackupData(const NfcDeviceHandle *handle, const void* buf, size_t buf_size);
397/// Only available with ::NfpServiceType_Debug.
398Result nfpWriteNtf(const NfcDeviceHandle *handle, u32 write_type, const void* buf, size_t buf_size);
399
400/// This uses nfc:*.
402
403/// Only available with [4.0.0+].
404Result nfcReadMifare(const NfcDeviceHandle *handle, NfcMifareReadBlockData *out_block_data, const NfcMifareReadBlockParameter *read_block_parameter, s32 count);
405/// Only available with [4.0.0+].
406Result nfcWriteMifare(const NfcDeviceHandle *handle, const NfcMifareWriteBlockParameter *write_block_parameter, s32 count);
407
408Result nfcMfReadMifare(const NfcDeviceHandle *handle, NfcMifareReadBlockData *out_block_data, const NfcMifareReadBlockParameter *read_block_parameter, s32 count);
409Result nfcMfWriteMifare(const NfcDeviceHandle *handle, const NfcMifareWriteBlockParameter *write_block_parameter, s32 count);
410
411/// Only available with [4.0.0+].
412Result nfcSendCommandByPassThrough(const NfcDeviceHandle *handle, u64 timeout, const void* cmd_buf, size_t cmd_buf_size, void* reply_buf, size_t reply_buf_size, u64 *out_size);
413/// Only available with [4.0.0+].
415/// Only available with [4.0.0+].
Result nfcGetNpadId(const NfcDeviceHandle *handle, u32 *out)
Only available with [4.0.0+].
Result nfpBreakTag(const NfcDeviceHandle *handle, u32 break_type)
Only available with NfpServiceType_Debug.
Result nfpSetRegisterInfoPrivate(const NfcDeviceHandle *handle, const NfpRegisterInfoPrivate *register_info_private)
Not available with NfpServiceType_User.
Result nfcAttachActivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
Result nfpAttachActivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
NfcServiceType
NfcServiceType.
Definition nfc.h:21
@ NfcServiceType_System
Initializes nfc:sys.
Definition nfc.h:23
@ NfcServiceType_User
Initializes nfc:user.
Definition nfc.h:22
Result nfpWriteBackupData(const NfcDeviceHandle *handle, const void *buf, size_t buf_size)
Only available with NfpServiceType_Debug.
void nfcExit(void)
Exit nfc:*.
Result nfcAttachAvailabilityChangeEvent(Event *out_event)
Returned event will have autoclear on.
Result nfcMfAttachActivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
Result nfcInitialize(NfcServiceType service_type)
Initialize nfc:*.
Result nfcWriteMifare(const NfcDeviceHandle *handle, const NfcMifareWriteBlockParameter *write_block_parameter, s32 count)
Only available with [4.0.0+].
Result nfpInitialize(NfpServiceType service_type)
Initialize nfp:*.
Result nfpRecreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void *buf, size_t buf_size)
Not available with NfpServiceType_System.
Result nfpSetApplicationArea(const NfcDeviceHandle *handle, const void *buf, size_t buf_size)
Not available with NfpServiceType_System.
Result nfpGetApplicationAreaSize(const NfcDeviceHandle *handle, u32 *out_app_area_size)
Not available with NfpServiceType_System.
Result nfpAttachDeactivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
Result nfpReadBackupData(const NfcDeviceHandle *handle, void *out_buf, size_t buf_size, u32 *out_size)
Only available with NfpServiceType_Debug.
NfcProtocol
Definition nfc.h:74
@ NfcProtocol_TypeA
ISO14443A.
Definition nfc.h:76
@ NfcProtocol_TypeB
ISO14443B.
Definition nfc.h:77
@ NfcProtocol_TypeF
Sony FeliCa.
Definition nfc.h:78
Result nfcStartDetection(const NfcDeviceHandle *handle, NfcProtocol protocol)
Only available with [4.0.0+].
Result nfcMfAttachAvailabilityChangeEvent(Event *out_event)
Returned event will have autoclear on.
Result nfpWriteNtf(const NfcDeviceHandle *handle, u32 write_type, const void *buf, size_t buf_size)
Only available with NfpServiceType_Debug.
Result nfpAttachAvailabilityChangeEvent(Event *out_event)
Returned event will have autoclear on.
Result nfcGetState(NfcState *out)
Only available with [4.0.0+].
Result nfcGetTagInfo(const NfcDeviceHandle *handle, NfcTagInfo *out)
Only available with [4.0.0+].
Service * nfpGetServiceSession(void)
Gets the Service object for the actual nfp:* service session.
void nfcMfExit(void)
Exit nfc:mf:u.
Result nfpGetRegisterInfoPrivate(const NfcDeviceHandle *handle, NfpRegisterInfoPrivate *out)
Not available with NfpServiceType_User.
Result nfcAttachDeactivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
Result nfpFlushDebug(const NfcDeviceHandle *handle)
Only available with NfpServiceType_Debug.
Result nfpGetAdminInfo(const NfcDeviceHandle *handle, NfpAdminInfo *out)
Not available with NfpServiceType_User.
Result nfcStopDetection(const NfcDeviceHandle *handle)
Only available with [4.0.0+].
Result nfcListDevices(s32 *total_out, NfcDeviceHandle *out, s32 count)
Only available with [4.0.0+].
NfcTagType
Definition nfc.h:82
@ NfcTagType_Type4B
ISO14443B RW/RO. DESFire.
Definition nfc.h:88
@ NfcTagType_Type4A
ISO14443A RW/RO. DESFire.
Definition nfc.h:87
@ NfcTagType_Mifare
Mifare clasic. Skylanders.
Definition nfc.h:90
@ NfcTagType_Type3
ISO14443A RW/RO. Sony FeliCa.
Definition nfc.h:86
@ NfcTagType_Type2
ISO14443A RW. Ultralight, NTAGX, ST25TN.
Definition nfc.h:85
@ NfcTagType_Type1
ISO14443A RW. Topaz.
Definition nfc.h:84
@ NfcTagType_Type5
ISO15693 RW/RO. SLI, SLIX, ST25TV.
Definition nfc.h:89
Result nfcReleasePassThroughSession(const NfcDeviceHandle *handle)
Only available with [4.0.0+].
Result nfcMfInitialize()
Initialize nfc:mf:u.
Result nfpOpenApplicationArea(const NfcDeviceHandle *handle, u32 app_id)
Not available with NfpServiceType_System.
Result nfpGetApplicationArea(const NfcDeviceHandle *handle, void *buf, size_t buf_size, u32 *out_size)
Not available with NfpServiceType_System.
NfpServiceType
NfpServiceType.
Definition nfc.h:14
@ NfpServiceType_User
Initializes nfp:user.
Definition nfc.h:15
@ NfpServiceType_System
Initializes nfp:sys.
Definition nfc.h:17
@ NfpServiceType_Debug
Initializes nfp:dbg.
Definition nfc.h:16
Result nfcMfAttachDeactivateEvent(const NfcDeviceHandle *handle, Event *out_event)
Returned event will have autoclear off.
Result nfcReadMifare(const NfcDeviceHandle *handle, NfcMifareReadBlockData *out_block_data, const NfcMifareReadBlockParameter *read_block_parameter, s32 count)
Only available with [4.0.0+].
Result nfcSendCommandByPassThrough(const NfcDeviceHandle *handle, u64 timeout, const void *cmd_buf, size_t cmd_buf_size, void *reply_buf, size_t reply_buf_size, u64 *out_size)
Only available with [4.0.0+].
Result nfpDeleteApplicationArea(const NfcDeviceHandle *handle)
Not available with NfpServiceType_User.
Result nfcKeepPassThroughSession(const NfcDeviceHandle *handle)
Only available with [4.0.0+].
Service * nfpGetServiceSession_Interface(void)
Gets the Service object for the interface from nfp:*.
Service * nfcMfGetServiceSession(void)
Gets the Service object for the actual nfc:mf:u service session.
Result nfpCreateApplicationArea(const NfcDeviceHandle *handle, u32 app_id, const void *buf, size_t buf_size)
Not available with NfpServiceType_System.
Service * nfcGetServiceSession(void)
Gets the Service object for the actual nfc:* service session.
void nfpExit(void)
Exit nfp:*.
Result nfpFormat(const NfcDeviceHandle *handle)
Not available with NfpServiceType_User.
Result nfpDeleteRegisterInfo(const NfcDeviceHandle *handle)
Not available with NfpServiceType_User.
Service * nfcGetServiceSession_Interface(void)
Gets the Service object for the interface from nfc:*.
Result nfpExistsApplicationArea(const NfcDeviceHandle *handle, bool *out)
Not available with NfpServiceType_User.
Result nfcGetDeviceState(const NfcDeviceHandle *handle, NfcDeviceState *out)
Only available with [4.0.0+].
Result nfcIsNfcEnabled(bool *out)
This uses nfc:*.
Result nfpSetAll(const NfcDeviceHandle *handle, const NfpData *nfp_data)
Only available with NfpServiceType_Debug.
Result nfpGetAll(const NfcDeviceHandle *handle, NfpData *out)
Only available with NfpServiceType_Debug.
Service * nfcMfGetServiceSession_Interface(void)
Gets the Service object for the interface from nfc:mf:u.
Kernel-mode event structure.
Definition event.h:13
Definition mii.h:62
Definition mii.h:117
Nfc/Nfp DeviceHandle.
Definition nfc.h:237
Definition nfc.h:218
Definition nfc.h:212
Definition nfc.h:224
Definition nfc.h:231
Definition nfc.h:204
u8 unknown
Usually 1.
Definition nfc.h:206
Definition nfc.h:114
Definition nfc.h:158
Definition nfc.h:123
Definition nfc.h:168
u8 unknown1
Normally zero.
Definition nfc.h:189
u8 application_id_byte
(Original Program ID >> 0x24) & 0xF byte (Program ID has this byte swapped with console type)
Definition nfc.h:199
u8 settings_flag
bit4 = amiibo was initialized in console settings, bit5 = has application area
Definition nfc.h:188
Definition nfc.h:133
Definition nfc.h:148
Definition nfc.h:138
Definition nfc.h:105
Service object structure.
Definition service.h:14
#define BIT(n)
Creates a bitmask from a bit number.
Definition types.h:54
uint64_t u64
64-bit unsigned integer.
Definition types.h:22
uint8_t u8
8-bit unsigned integer.
Definition types.h:19
#define NX_PACKED
Packs a struct so that it won't include padding bytes.
Definition types.h:63
uint16_t u16
16-bit unsigned integer.
Definition types.h:20
u32 Result
Function error code result type.
Definition types.h:44
int32_t s32
32-bit signed integer.
Definition types.h:27
uint32_t u32
32-bit unsigned integer.
Definition types.h:21