@@ -43,6 +43,8 @@ static void printbuf(char *prefix, u8* data, size_t len) {
4343#define DnfcStopScanning nfcStopScanning
4444
4545#else
46+
47+ //emulate the calls for running in citra
4648static Result DnfcStartOtherTagScanning (int a , int b ) {
4749 return 0 ;
4850}
@@ -89,7 +91,11 @@ Result nfc_readFull(u8 *data, int datalen) {
8991
9092 u32 kDown = hidKeysDown ();
9193
92- if (kDown & KEY_B ) break ;
94+ if (kDown & KEY_B ) {
95+ ret = -1 ;
96+ printf ("Cancelled.\n" );
97+ break ;
98+ }
9399
94100 ret = DnfcGetTagState (& curstate );
95101 if (R_FAILED (ret )) {
@@ -104,15 +110,17 @@ Result nfc_readFull(u8 *data, int datalen) {
104110 u8 tagdata [AMIIBO_MAX_SIZE ];
105111 memset (tagdata , 0 , sizeof (tagdata ));
106112
113+ printf ("Reading tag" );
114+
107115 for (int i = 0x00 ; i <=NTAG_215_LAST_PAGE ;i += NTAG_FAST_READ_PAGE_COUNT ) {
108- printf ("Page %d\n" , i );
116+ printf ("." );
109117 u8 cmd [] = CMD_FAST_READ (i , NTAG_FAST_READ_PAGE_COUNT );
110118 u8 cmdresult [NTAG_FAST_READ_PAGE_COUNT * NTAG_PAGE_SIZE ];
111- printbuf ("CMD " , cmd , sizeof (cmd ));
119+ // printbuf("CMD ", cmd, sizeof(cmd));
112120 memset (cmdresult , 0 , sizeof (cmdresult ));
113121 size_t resultsize = 0 ;
114122
115- printf ("page start %x end %x\n" , cmd [1 ], cmd [2 ]);
123+ // printf("page start %x end %x\n", cmd[1], cmd[2]);
116124 resultsize = NTAG_FAST_READ_PAGE_COUNT * NTAG_PAGE_SIZE ;
117125
118126 ret = DnfcSendTagCommand (cmd , sizeof (cmd ), cmdresult , sizeof (cmdresult ), & resultsize , NFC_TIMEOUT );
@@ -129,9 +137,8 @@ Result nfc_readFull(u8 *data, int datalen) {
129137 int copycount = sizeof (cmdresult );
130138 if (((i * NTAG_PAGE_SIZE ) + sizeof (cmdresult )) > sizeof (tagdata ))
131139 copycount = ((i * NTAG_PAGE_SIZE ) + sizeof (cmdresult )) - sizeof (tagdata );
132- printf (">%d " , copycount );
133140 memcpy (& tagdata [i * NTAG_PAGE_SIZE ], cmdresult , copycount );
134- printbuf ("result" , cmdresult , resultsize );
141+ // printbuf("result", cmdresult, resultsize);
135142 }
136143 if (ret == 0 ) {
137144 memcpy (data , tagdata , sizeof (tagdata ));
@@ -142,6 +149,7 @@ Result nfc_readFull(u8 *data, int datalen) {
142149 }
143150 }
144151
152+ printf ("\n" );
145153 DnfcStopScanning ();
146154 return ret ;
147155}
@@ -172,7 +180,11 @@ Result nfc_readBlock(int pageId, u8 *data, int datalen) {
172180
173181 u32 kDown = hidKeysDown ();
174182
175- if (kDown & KEY_B ) break ;
183+ if (kDown & KEY_B ) {
184+ ret = -1 ;
185+ printf ("Cancelled.\n" );
186+ break ;
187+ }
176188
177189 ret = DnfcGetTagState (& curstate );
178190 if (R_FAILED (ret ))
@@ -222,13 +234,6 @@ static Result writeTag(u8 *data, u8 *PWD, u8 *PACK) {
222234 //write normal pages
223235 int ret = 0 ;
224236
225- ret = nfcCmd21 (); //seems to put the NFC reader into a continious mode allowing all the requests to go through one session without powering the tag down.
226-
227- if (R_FAILED (ret )) {
228- printf ("nfcCmd21 failed : %d\n" , R_DESCRIPTION (ret ));
229- return ret ;
230- }
231-
232237 printf ("Writing normal pages\n" );
233238 for (int pageId = 0x04 ; pageId <= 0x81 ; pageId ++ ) {
234239 printf ("." );
@@ -244,6 +249,12 @@ static Result writeTag(u8 *data, u8 *PWD, u8 *PACK) {
244249 if (R_FAILED (ret ))
245250 return ret ;
246251
252+ ret = nfcCmd21 (); //seems to put the NFC reader into a continious mode allowing all the requests to go through one session without powering the tag down.
253+ if (R_FAILED (ret )) {
254+ printf ("nfcCmd21 failed : %d\n" , R_DESCRIPTION (ret ));
255+ return ret ;
256+ }
257+
247258 //write PACK
248259 printf ("Writing PACK\n" );
249260 ret = writePage (0x86 , PACK );
@@ -292,7 +303,7 @@ Result nfc_auth(u8 *PWD) {
292303 size_t resultsize = 0 ;
293304 u8 packres [2 ];
294305 int ret = DnfcSendTagCommand (pwdcmd , sizeof (pwdcmd ), packres , sizeof (packres ), & resultsize , NFC_TIMEOUT );
295- printbuf ("pack " , packres , sizeof (packres ));
306+ // printbuf("pack ", packres, sizeof(packres));
296307 if (R_FAILED (ret )) {
297308 printf ("PWD command failed failed : %d\n" , R_DESCRIPTION (ret ));
298309 return ret ;
@@ -327,7 +338,11 @@ Result nfc_write(u8 *data, int datalen, u8 *PWD, int PWDLength) {
327338
328339 u32 kDown = hidKeysDown ();
329340
330- if (kDown & KEY_B ) break ;
341+ if (kDown & KEY_B ) {
342+ ret = -1 ;
343+ printf ("Cancelled.\n" );
344+ break ;
345+ }
331346
332347 ret = DnfcGetTagState (& curstate );
333348 if (R_FAILED (ret )) {
0 commit comments