wut  v1.7.0
Wii U Toolchain
nfp_cpp.h
Go to the documentation of this file.
1 #pragma once
2 #include <wut.h>
3 #include <nn/result.h>
4 #include <nn/ffl/miidata.h>
5 #include <coreinit/event.h>
6 #include <nfc/nfc.h>
7 
15 #ifdef __cplusplus
16 
17 namespace nn {
18 
19 namespace nfp {
20 
23 {
24  // Usage results
28 
29  // Status results
31  RESULT_INVALID_TAG = 0x0c800,
41 
42  // Fatal results
43  RESULT_FATAL = 0x5db00,
44 };
45 
46 enum class NfpState : uint32_t
47 {
49  Uninitialized = 0,
51  Initialized = 1,
53  Searching = 2,
55  Found = 3,
57  Removed = 4,
59  Mounted = 5,
60  Unknown6 = 6,
62  MountedROM = 7,
63 };
64 WUT_CHECK_SIZE(NfpState, 0x4);
65 
66 enum class AdminFlags : uint8_t
67 {
69  IsRegistered = 1 << 0,
71  HasApplicationData = 1 << 1,
72 };
73 WUT_CHECK_SIZE(AdminFlags, 0x1);
74 
75 enum class TagType : uint8_t
76 {
77  Unknown = 0,
78  Type1Tag = 1 << 0,
79  Type2Tag = 1 << 1,
80  Type3Tag = 1 << 2,
81  Iso15693 = 1 << 5,
82 };
83 WUT_CHECK_SIZE(TagType, 0x1);
84 
85 struct Date
86 {
88  uint16_t year;
90  uint8_t month;
92  uint8_t day;
93 };
94 WUT_CHECK_OFFSET(Date, 0x0, year);
95 WUT_CHECK_OFFSET(Date, 0x2, month);
96 WUT_CHECK_OFFSET(Date, 0x3, day);
97 WUT_CHECK_SIZE(Date, 0x4);
98 
100 {
102  uint32_t accessID;
104  void* data;
106  uint32_t size;
108  uint8_t reserved[0x30];
109 };
110 WUT_CHECK_OFFSET(ApplicationAreaCreateInfo, 0x0, accessID);
111 WUT_CHECK_OFFSET(ApplicationAreaCreateInfo, 0x4, data);
112 WUT_CHECK_OFFSET(ApplicationAreaCreateInfo, 0x8, size);
113 WUT_CHECK_OFFSET(ApplicationAreaCreateInfo, 0xC, reserved);
114 WUT_CHECK_SIZE(ApplicationAreaCreateInfo, 0x3C);
115 
116 struct TagId
117 {
119  uint8_t size;
121  uint8_t uid[10];
122 };
123 WUT_CHECK_OFFSET(TagId, 0x0, size);
124 WUT_CHECK_OFFSET(TagId, 0x1, uid);
125 WUT_CHECK_SIZE(TagId, 0xB);
126 
127 struct TagInfo
128 {
132  uint8_t reserved0[0x15];
138  uint8_t reserved1[0x32];
139 };
140 WUT_CHECK_OFFSET(TagInfo, 0x0, id);
141 WUT_CHECK_OFFSET(TagInfo, 0xB, reserved0);
142 WUT_CHECK_OFFSET(TagInfo, 0x20, technology);
143 WUT_CHECK_OFFSET(TagInfo, 0x21, tag_type);
144 WUT_CHECK_OFFSET(TagInfo, 0x22, reserved1);
145 WUT_CHECK_SIZE(TagInfo, 0x54);
146 
148 {
152  uint16_t writes;
154  uint8_t characterID[3];
156  uint8_t seriesID;
158  uint16_t numberingID;
160  uint8_t figureType;
162  uint8_t figureVersion;
166  uint8_t reserved[0x30];
167 };
168 WUT_CHECK_OFFSET(CommonInfo, 0x0, lastWriteDate);
169 WUT_CHECK_OFFSET(CommonInfo, 0x4, writes);
170 WUT_CHECK_OFFSET(CommonInfo, 0x6, characterID);
171 WUT_CHECK_OFFSET(CommonInfo, 0x9, seriesID);
172 WUT_CHECK_OFFSET(CommonInfo, 0xA, numberingID);
173 WUT_CHECK_OFFSET(CommonInfo, 0xC, figureType);
174 WUT_CHECK_OFFSET(CommonInfo, 0xD, figureVersion);
175 WUT_CHECK_OFFSET(CommonInfo, 0xE, applicationAreaSize);
176 WUT_CHECK_OFFSET(CommonInfo, 0x10, reserved);
177 WUT_CHECK_SIZE(CommonInfo, 0x40);
178 
179 struct WUT_PACKED RegisterInfo
180 {
184  uint16_t name[11];
186  uint8_t fontRegion;
188  uint8_t country;
192  uint8_t reserved[0x2c];
193 };
194 WUT_CHECK_OFFSET(RegisterInfo, 0x0, mii);
195 WUT_CHECK_OFFSET(RegisterInfo, 0x60, name);
196 WUT_CHECK_OFFSET(RegisterInfo, 0x76, fontRegion);
197 WUT_CHECK_OFFSET(RegisterInfo, 0x77, country);
198 WUT_CHECK_OFFSET(RegisterInfo, 0x78, registerDate);
199 WUT_CHECK_OFFSET(RegisterInfo, 0x7C, reserved);
200 WUT_CHECK_SIZE(RegisterInfo, 0xA8);
201 
202 struct WUT_PACKED ReadOnlyInfo
203 {
205  uint8_t characterID[3];
207  uint8_t seriesID;
209  uint16_t numberingID;
211  uint8_t figureType;
213  uint8_t reserved[0x2f];
214 };
215 WUT_CHECK_OFFSET(ReadOnlyInfo, 0x0, characterID);
216 WUT_CHECK_OFFSET(ReadOnlyInfo, 0x3, seriesID);
217 WUT_CHECK_OFFSET(ReadOnlyInfo, 0x4, numberingID);
218 WUT_CHECK_OFFSET(ReadOnlyInfo, 0x6, figureType);
219 WUT_CHECK_OFFSET(ReadOnlyInfo, 0x7, reserved);
220 WUT_CHECK_SIZE(ReadOnlyInfo, 0x36);
221 
222 // seems to be the same as ReadOnlyInfo
223 // maybe left over from an older library version?
225 WUT_CHECK_SIZE(RomInfo, 0x36);
226 
227 struct WUT_PACKED RegisterInfoSet
228 {
232  uint16_t name[11];
234  uint8_t fontRegion;
236  uint8_t reserved[0x2d];
237 };
238 WUT_CHECK_OFFSET(RegisterInfoSet, 0x0, mii);
239 WUT_CHECK_OFFSET(RegisterInfoSet, 0x60, name);
240 WUT_CHECK_OFFSET(RegisterInfoSet, 0x76, fontRegion);
241 WUT_CHECK_OFFSET(RegisterInfoSet, 0x77, reserved);
242 WUT_CHECK_SIZE(RegisterInfoSet, 0xA4);
243 
244 struct WUT_PACKED AdminInfo
245 {
247  uint64_t titleID;
249  uint32_t accessID;
255  uint8_t formatVersion;
257  uint8_t platform;
259  uint8_t reserved[0x2f];
260 };
261 WUT_CHECK_OFFSET(AdminInfo, 0x0, titleID);
262 WUT_CHECK_OFFSET(AdminInfo, 0x8, accessID);
263 WUT_CHECK_OFFSET(AdminInfo, 0xC, applicationAreaWrites);
264 WUT_CHECK_OFFSET(AdminInfo, 0xE, flags);
265 WUT_CHECK_OFFSET(AdminInfo, 0xF, formatVersion);
266 WUT_CHECK_OFFSET(AdminInfo, 0x10, platform);
267 WUT_CHECK_OFFSET(AdminInfo, 0x11, reserved);
268 WUT_CHECK_SIZE(AdminInfo, 0x40);
269 
276 NfpState
278  asm("GetNfpState__Q2_2nn3nfpFv");
279 
283 nn::Result
285  asm("Initialize__Q2_2nn3nfpFv");
286 
290 nn::Result
292  asm("Finalize__Q2_2nn3nfpFv");
293 
301 nn::Result
303  asm("AntennaCheck__Q2_2nn3nfpFv");
304 
312 nn::Result
314  asm("SetActivateEvent__Q2_2nn3nfpFP7OSEvent");
315 
323 nn::Result
325  asm("SetDeactivateEvent__Q2_2nn3nfpFP7OSEvent");
326 
331 nn::Result
333  asm("StartDetection__Q2_2nn3nfpFv");
334 
339 nn::Result
341  asm("StopDetection__Q2_2nn3nfpFv");
342 
348 nn::Result
350  asm("Mount__Q2_2nn3nfpFv");
351 
357 nn::Result
359  asm("MountReadOnly__Q2_2nn3nfpFv");
360 
366 nn::Result
368  asm("MountRom__Q2_2nn3nfpFv");
369 
375 nn::Result
377  asm("Flush__Q2_2nn3nfpFv");
378 
388 nn::Result
390  asm("Unmount__Q2_2nn3nfpFv");
391 
400 bool
402  asm("IsExistApplicationArea__Q2_2nn3nfpFv");
403 
410 nn::Result
412  asm("InitializeCreateInfo__Q2_2nn3nfpFPQ3_2nn3nfp25ApplicationAreaCreateInfo");
413 
423 nn::Result
425  asm("CreateApplicationArea__Q2_2nn3nfpFRCQ3_2nn3nfp25ApplicationAreaCreateInfo");
426 
436 nn::Result
437 OpenApplicationArea(uint32_t accessID)
438  asm("OpenApplicationArea__Q2_2nn3nfpFUi");
439 
446 nn::Result
448  asm("DeleteApplicationArea__Q2_2nn3nfpFv");
449 
465 nn::Result
466 WriteApplicationArea(const void *data, uint32_t size, const TagId &id)
467  asm("WriteApplicationArea__Q2_2nn3nfpFPCvUiRCQ3_2nn3nfp5TagId");
468 
481 nn::Result
482 ReadApplicationArea(void *outData, uint32_t size)
483  asm("ReadApplicationArea__Q2_2nn3nfpFPvUi");
484 
491 nn::Result
493  asm("InitializeRegisterInfoSet__Q2_2nn3nfpFPQ3_2nn3nfp15RegisterInfoSet");
494 
503 nn::Result
505  asm("SetNfpRegisterInfo__Q2_2nn3nfpFRCQ3_2nn3nfp15RegisterInfoSet");
506 
515 nn::Result
517  asm("GetNfpRegisterInfo__Q2_2nn3nfpFPQ3_2nn3nfp12RegisterInfo");
518 
524 nn::Result
526  asm("DeleteNfpRegisterInfo__Q2_2nn3nfpFv");
527 
536 nn::Result
538  asm("GetNfpCommonInfo__Q2_2nn3nfpFPQ3_2nn3nfp10CommonInfo");
539 
548 nn::Result
550  asm("GetNfpReadOnlyInfo__Q2_2nn3nfpFPQ3_2nn3nfp12ReadOnlyInfo");
551 
560 nn::Result
562  asm("GetNfpAdminInfo__Q2_2nn3nfpFPQ3_2nn3nfp9AdminInfo");
563 
572 nn::Result
574  asm("GetNfpRomInfo__Q2_2nn3nfpFPQ3_2nn3nfp7RomInfo");
575 
584 nn::Result
586  asm("GetTagInfo__Q2_2nn3nfpFPQ3_2nn3nfp7TagInfo");
587 
600 nn::Result
601 Format(const uint8_t *data, int32_t size)
602  asm("Format__Q2_2nn3nfpFPCUci");
603 
604 nn::Result
606  asm("Restore__Q2_2nn3nfpFv");
607 
614 uint32_t
615 GetErrorCode(const nn::Result &res)
616  asm("GetErrorCode__Q2_2nn3nfpFRCQ2_2nn6Result");
617 
618 } //namespace nfp
619 
620 } //namespace nn
621 
622 #endif
623 
Result value type used by nn libraries.
Definition: result.h:68
Definition: event.h:34
uint8_t NFCTechnology
Definition: nfc.h:18
nn::Result StopDetection() asm("StopDetection__Q2_2nn3nfpFv")
Stops searching for tags.
uint8_t reserved1[0x32]
reserved bytes
Definition: nfp_cpp.h:138
nn::Result WriteApplicationArea(const void *data, uint32_t size, const TagId &id) asm("WriteApplicationArea__Q2_2nn3nfpFPCvUiRCQ3_2nn3nfp5TagId")
Writes data to the opened application area.
uint64_t titleID
The titleID of the application which wrote to the application data.
Definition: nfp_cpp.h:247
uint8_t characterID[3]
The character id of the amiibo.
Definition: nfp_cpp.h:154
uint16_t numberingID
Numbering ID of the amiibo.
Definition: nfp_cpp.h:158
nn::Result DeleteNfpRegisterInfo() asm("DeleteNfpRegisterInfo__Q2_2nn3nfpFv")
Deletes the register info of the mounted tag.
NfpState GetNfpState() asm("GetNfpState__Q2_2nn3nfpFv")
Gets the state nfp is currently in.
TagType
Definition: nfp_cpp.h:76
NFCTechnology technology
Technology (always NFC_TECHNOLOGY_A)
Definition: nfp_cpp.h:134
nn::Result Mount() asm("Mount__Q2_2nn3nfpFv")
Mounts a found tag.
uint16_t applicationAreaWrites
The amount of times the application area was written to.
Definition: nfp_cpp.h:251
nn::Result Initialize() asm("Initialize__Q2_2nn3nfpFv")
Initializes NFP.
uint8_t month
Month (0 - 11)
Definition: nfp_cpp.h:90
uint16_t writes
The amount of times this tag was written to.
Definition: nfp_cpp.h:152
nn::Result DeleteApplicationArea() asm("DeleteApplicationArea__Q2_2nn3nfpFv")
Deletes the application area.
uint8_t figureVersion
The version of this figure (always 0x00)
Definition: nfp_cpp.h:162
nn::Result GetNfpAdminInfo(AdminInfo *outInfo) asm("GetNfpAdminInfo__Q2_2nn3nfpFPQ3_2nn3nfp9AdminInfo")
Gets the admin info of the mounted tag.
uint8_t platform
The platform which wrote to the amiibo (0x01 if Wii U)
Definition: nfp_cpp.h:257
nn::Result StartDetection() asm("StartDetection__Q2_2nn3nfpFv")
Starts searching for tags.
nn::Result Flush() asm("Flush__Q2_2nn3nfpFv")
Writes any changes done while mounted to the tag.
AdminFlags flags
Flags.
Definition: nfp_cpp.h:253
uint16_t year
Year (Starting at 0)
Definition: nfp_cpp.h:88
uint8_t figureType
The type of this figure.
Definition: nfp_cpp.h:160
nn::Result ReadApplicationArea(void *outData, uint32_t size) asm("ReadApplicationArea__Q2_2nn3nfpFPvUi")
Reads data from the opened application area.
uint8_t reserved0[0x15]
reserved bytes
Definition: nfp_cpp.h:132
FFLStoreData mii
The mii this figure was registered with.
Definition: nfp_cpp.h:182
uint8_t day
Day (0 - 30)
Definition: nfp_cpp.h:92
void * data
The initial data to write to the area.
Definition: nfp_cpp.h:104
uint8_t reserved[0x30]
reserved bytes, must be set to 0
Definition: nfp_cpp.h:108
ResultDescription
NN_NFP result descriptions for nn::Result::GetDescription.
Definition: nfp_cpp.h:23
@ RESULT_APP_AREA_ALREADY_EXISTS
Definition: nfp_cpp.h:37
@ RESULT_INVALID_TAG
Definition: nfp_cpp.h:31
@ RESULT_APP_AREA_TAGID_MISMATCH
Definition: nfp_cpp.h:36
@ RESULT_OUT_OF_RANGE
Definition: nfp_cpp.h:25
@ RESULT_SYSTEM_ERROR
Definition: nfp_cpp.h:40
@ RESULT_INVALID_PARAM
Definition: nfp_cpp.h:26
@ RESULT_NO_BACKUPENTRY
Definition: nfp_cpp.h:33
@ RESULT_FATAL
Definition: nfp_cpp.h:43
@ RESULT_INVALID_STATE
Definition: nfp_cpp.h:30
@ RESULT_INVALID_TAG_INFO
Definition: nfp_cpp.h:32
@ RESULT_APP_AREA_MISSING
Definition: nfp_cpp.h:35
@ RESULT_APP_AREA_ACCESS_ID_MISMATCH
Definition: nfp_cpp.h:38
@ RESULT_NO_BACKUP_SAVEDATA
Definition: nfp_cpp.h:39
@ RESULT_NO_REGISTER_INFO
Definition: nfp_cpp.h:34
@ RESULT_INVALID_ALIGNMENT
Definition: nfp_cpp.h:27
nn::Result InitializeRegisterInfoSet(RegisterInfoSet *infoSet) asm("InitializeRegisterInfoSet__Q2_2nn3nfpFPQ3_2nn3nfp15RegisterInfoSet")
Initializes a RegisterInfoSet struct.
uint8_t country
Country code.
Definition: nfp_cpp.h:188
nn::Result MountReadOnly() asm("MountReadOnly__Q2_2nn3nfpFv")
Mounts a found tag as read-only.
uint16_t applicationAreaSize
The size of the application area.
Definition: nfp_cpp.h:164
nn::Result SetNfpRegisterInfo(const RegisterInfoSet &info) asm("SetNfpRegisterInfo__Q2_2nn3nfpFRCQ3_2nn3nfp15RegisterInfoSet")
Sets the register info of the mounted tag.
nn::Result AntennaCheck() asm("AntennaCheck__Q2_2nn3nfpFv")
Checks if the NFC Antenna can be used.
nn::Result GetNfpReadOnlyInfo(ReadOnlyInfo *outInfo) asm("GetNfpReadOnlyInfo__Q2_2nn3nfpFPQ3_2nn3nfp12ReadOnlyInfo")
Gets the read only info of the mounted tag.
nn::Result GetNfpRegisterInfo(RegisterInfo *outInfo) asm("GetNfpRegisterInfo__Q2_2nn3nfpFPQ3_2nn3nfp12RegisterInfo")
Gets the register info of the mounted tag.
nn::Result MountRom() asm("MountRom__Q2_2nn3nfpFv")
Mounts a found tag in ROM mode.
Date registerDate
The date when the amiibo was registered.
Definition: nfp_cpp.h:190
AdminFlags
Definition: nfp_cpp.h:67
@ IsRegistered
The tag was registered and contains register info.
@ HasApplicationData
The tag contains an application area.
nn::Result GetTagInfo(TagInfo *outInfo) asm("GetTagInfo__Q2_2nn3nfpFPQ3_2nn3nfp7TagInfo")
Gets the tag info.
TagId id
The id of the tag.
Definition: nfp_cpp.h:130
nn::Result OpenApplicationArea(uint32_t accessID) asm("OpenApplicationArea__Q2_2nn3nfpFUi")
Opens the application area for reading and writing.
nn::Result SetDeactivateEvent(OSEvent *event) asm("SetDeactivateEvent__Q2_2nn3nfpFP7OSEvent")
Sets an event which will be signalled once a tag has been lost.
nn::Result SetActivateEvent(OSEvent *event) asm("SetActivateEvent__Q2_2nn3nfpFP7OSEvent")
Sets an event which will be signalled once a tag has been found.
nn::Result GetNfpCommonInfo(CommonInfo *outInfo) asm("GetNfpCommonInfo__Q2_2nn3nfpFPQ3_2nn3nfp10CommonInfo")
Gets the common info of the mounted tag.
nn::Result Unmount() asm("Unmount__Q2_2nn3nfpFv")
Unmounts a currently mounted tag.
uint32_t size
The size of the data.
Definition: nfp_cpp.h:106
nn::Result InitializeCreateInfo(ApplicationAreaCreateInfo *info) asm("InitializeCreateInfo__Q2_2nn3nfpFPQ3_2nn3nfp25ApplicationAreaCreateInfo")
Initializes a ApplicationAreaCreateInfo struct.
uint32_t accessID
The access ID with which the area should be created.
Definition: nfp_cpp.h:102
NfpState
Definition: nfp_cpp.h:47
@ Initialized
nn_nfp has been initialized
@ Found
A tag has been found.
@ Searching
Searching for a tag.
@ MountedROM
The tag was mounted in ROM mode.
@ Removed
Tag was removed.
@ Mounted
The tag is mounted.
@ Uninitialized
nn_nfp is uninitialized
nn::Result CreateApplicationArea(const ApplicationAreaCreateInfo &createInfo) asm("CreateApplicationArea__Q2_2nn3nfpFRCQ3_2nn3nfp25ApplicationAreaCreateInfo")
Initializes the application area of the tag.
TagType tag_type
Tag type (always TagType::Type2Tag)
Definition: nfp_cpp.h:136
uint8_t formatVersion
The version of the amiibo format (always 0x02)
Definition: nfp_cpp.h:255
nn::Result Restore() asm("Restore__Q2_2nn3nfpFv")
uint8_t seriesID
The series this amiibo is from.
Definition: nfp_cpp.h:156
uint8_t fontRegion
Font region.
Definition: nfp_cpp.h:186
uint8_t uid[10]
The uid of the tag.
Definition: nfp_cpp.h:121
uint32_t GetErrorCode(const nn::Result &res) asm("GetErrorCode__Q2_2nn3nfpFRCQ2_2nn6Result")
Converts a nn::Result to an error code.
nn::Result GetNfpRomInfo(RomInfo *outInfo) asm("GetNfpRomInfo__Q2_2nn3nfpFPQ3_2nn3nfp7RomInfo")
Gets the rom info of the mounted tag.
nn::Result Finalize() asm("Finalize__Q2_2nn3nfpFv")
Finalizes NFP.
bool IsExistApplicationArea() asm("IsExistApplicationArea__Q2_2nn3nfpFv")
Checks if the tag contains application data.
uint8_t size
The size of the id.
Definition: nfp_cpp.h:119
nn::Result Format(const uint8_t *data, int32_t size) asm("Format__Q2_2nn3nfpFPCUci")
Formats a found tag.
Date lastWriteDate
The date when the tag was last written to.
Definition: nfp_cpp.h:150
Definition: ac_cpp.h:15