@@ -33,7 +33,7 @@ void print_hex(void *buf, size_t size) {
3333 consoleUpdate (NULL );
3434}
3535
36- Result process_amiibo (u32 app_id ) {
36+ Result process_amiibo () {
3737 Result rc = 0 ;
3838
3939 // Get the handle of the first controller with NFC capabilities.
@@ -94,15 +94,34 @@ Result process_amiibo(u32 app_id) {
9494 rc = eventWaitLoop (& activate_event );
9595
9696 if (R_SUCCEEDED (rc )) {
97- printf ("A tag was detected, please do not remove it from the NFC spot.\n" );
97+ printf ("A tag was detected, please do not remove it from the NFC spot.\n\n " );
9898 consoleUpdate (NULL );
9999 }
100100 }
101101
102+ // Retrieve the tag info data, which contains the protocol, type and uuid.
103+ if (R_SUCCEEDED (rc )) {
104+ NfpTagInfo tag_info = {0 };
105+ rc = nfpGetTagInfo (& handle , & tag_info );
106+
107+ if (R_SUCCEEDED (rc )) {
108+ printf ("Tag protocol: 0x%02x, type: 0x%02x, UUID: " , tag_info .protocol , tag_info .tag_type );
109+ print_hex (tag_info .uuid , tag_info .uuid_length );
110+ printf ("\n" );
111+ }
112+ }
113+
102114 // If a tag was successfully detected, load it into memory.
103- if (R_SUCCEEDED (rc ))
115+ if (R_SUCCEEDED (rc )) {
104116 rc = nfpMount (& handle , NfpDeviceType_Amiibo , NfpMountTarget_All );
105117
118+ if (rc == 0x11073 ) // 2115-0136
119+ printf ("This tag is corrupted and has a backup in system.\n" );
120+
121+ if (rc == 0x12073 ) // 2115-0144
122+ printf ("This tag is corrupted.\n" );
123+ }
124+
106125 // Retrieve the model info data, which contains the amiibo id.
107126 if (R_SUCCEEDED (rc )) {
108127 NfpModelInfo model_info = {0 };
@@ -111,6 +130,7 @@ Result process_amiibo(u32 app_id) {
111130 if (R_SUCCEEDED (rc )) {
112131 printf ("Amiibo ID: " );
113132 print_hex (model_info .amiibo_id , 8 );
133+ printf ("\n" );
114134 }
115135 }
116136
@@ -120,8 +140,43 @@ Result process_amiibo(u32 app_id) {
120140 NfpCommonInfo common_info = {0 };
121141 rc = nfpGetCommonInfo (& handle , & common_info );
122142
123- if (R_SUCCEEDED (rc ))
143+ if (R_SUCCEEDED (rc )) {
124144 app_area_size = common_info .application_area_size ;
145+ printf ("Write counter: %d, last write date %d/%d/%d\n\n" , common_info .write_counter , common_info .last_write_day , common_info .last_write_month , common_info .last_write_year );
146+ }
147+ }
148+
149+ u32 app_id = 0 ;
150+ // Retrieve the admin info data, which contains the app id.
151+ if (R_SUCCEEDED (rc )) {
152+ NfpAdminInfo admin_info = {0 };
153+ rc = nfpGetAdminInfo (& handle , & admin_info );
154+
155+ if (R_SUCCEEDED (rc )) {
156+ app_id = admin_info .application_area_id ;
157+ printf ("App area: 0x%x, game ID: 0x%lx, console: " , app_id , admin_info .application_id );
158+ switch (admin_info .application_area_version ) {
159+ case NfpApplicationAreaVersion_3DS :
160+ printf ("Old 3ds" );
161+ break ;
162+ case NfpApplicationAreaVersion_WiiU :
163+ printf ("Wii U" );
164+ break ;
165+ case NfpApplicationAreaVersion_3DSv2 :
166+ printf ("New 3ds" );
167+ break ;
168+ case NfpApplicationAreaVersion_Switch :
169+ printf ("Switch" );
170+ break ;
171+ case NfpApplicationAreaVersion_NotSet :
172+ printf ("Not set" );
173+ break ;
174+ default :
175+ printf ("0x%x" , admin_info .application_area_version );
176+ break ;
177+ }
178+ printf ("\n" );
179+ }
125180 }
126181
127182 if (R_SUCCEEDED (rc )) {
@@ -134,13 +189,15 @@ Result process_amiibo(u32 app_id) {
134189 }
135190
136191 u8 app_area [0xd8 ] = {0 }; // Maximum size of the application area.
192+ u32 app_area_read_size = 0 ; // Actual number of bytes set by nfpGetApplicationArea.
137193 if (app_area_size > sizeof (app_area )) app_area_size = sizeof (app_area );
138194 if (R_SUCCEEDED (rc )) {
139- rc = nfpGetApplicationArea (& handle , app_area , app_area_size );
195+ rc = nfpGetApplicationArea (& handle , app_area , app_area_size , & app_area_read_size );
140196
141197 if (R_SUCCEEDED (rc )) {
142- printf ("App area:\n" );
143- print_hex (app_area , app_area_size );
198+ printf ("App data:\n" );
199+ print_hex (app_area , app_area_read_size );
200+ printf ("\n" );
144201 }
145202 }
146203
@@ -171,11 +228,7 @@ Result process_amiibo(u32 app_id) {
171228int main (int argc , char * argv [])
172229{
173230 Result rc = 0 ;
174-
175- // Hardcoded for Super Smash Bros. Ultimate.
176- // See also: https://switchbrew.org/wiki/NFC_services#Application_IDs
177- u32 app_id = 0x34f80200 ;
178-
231+
179232 // This example uses a text console, as a simple way to output text to the screen.
180233 // If you want to write a software-rendered graphics application,
181234 // take a look at the graphics/simplegfx example, which uses the libnx Framebuffer API instead.
@@ -194,7 +247,9 @@ int main(int argc, char* argv[])
194247 consoleUpdate (NULL );
195248
196249 // Initialize the nfp:* service.
197- rc = nfpInitialize (NfpServiceType_User );
250+ // Use the NfpServiceType as required by your app, only use Debug if actually needed.
251+ // This example uses nfpGetAdminInfo which is only available on the debug interface.
252+ rc = nfpInitialize (NfpServiceType_Debug );
198253
199254 // Check if NFC is enabled. If not, wait until it is.
200255 // Note that various official games don't use nfc*().
@@ -237,7 +292,7 @@ int main(int argc, char* argv[])
237292 // padGetButtonsDown returns the set of buttons that have been
238293 // newly pressed in this frame compared to the previous one
239294 if (padGetButtonsDown (& pad ) & HidNpadButton_A ) {
240- rc = process_amiibo (app_id );
295+ rc = process_amiibo ();
241296
242297 // If an error happened, print it.
243298 if (R_FAILED (rc ))
0 commit comments