@@ -228,6 +228,8 @@ void nfc_write_response_chaining_plain(uint8_t req0, uint8_t * data, int len)
228
228
{
229
229
uint8_t res [32 ] = {0 };
230
230
res [0 ] = iBlock ;
231
+ res [1 ] = 0 ;
232
+ res [2 ] = 0 ;
231
233
if (len && data )
232
234
memcpy (& res [block_offset ], data , len );
233
235
nfc_write_frame (res , len + block_offset );
@@ -268,6 +270,19 @@ void nfc_write_response_chaining_plain(uint8_t req0, uint8_t * data, int len)
268
270
printf1 (TAG_NFC , "R block RX timeout %d/%d.\r\n" ,sendlen ,len );
269
271
break ;
270
272
}
273
+
274
+ if (!IS_RBLOCK (recbuf [0 ]))
275
+ {
276
+ printf1 (TAG_NFC , "R block RX error. Not a R block(0x%02x) %d/%d.\r\n" , recbuf [0 ], sendlen , len );
277
+ break ;
278
+ }
279
+
280
+ // NAK check
281
+ if (recbuf [0 ] & NFC_CMD_RBLOCK_ACK )
282
+ {
283
+ printf1 (TAG_NFC , "R block RX error. NAK received. %d/%d.\r\n" , recbuf [0 ], sendlen , len );
284
+ break ;
285
+ }
271
286
272
287
uint8_t rblock_offset = p14443_block_offset (recbuf [0 ]);
273
288
if (reclen != rblock_offset )
@@ -466,7 +481,8 @@ void rblock_acknowledge(uint8_t req0, bool ack)
466
481
NFC_STATE .block_num = !NFC_STATE .block_num ;
467
482
468
483
buf [0 ] = NFC_CMD_RBLOCK | (req0 & 0x0f );
469
- if (ack )
484
+ // iso14443-4:2001 page 16. ACK, if bit is set to 0, NAK, if bit is set to 1
485
+ if (!ack )
470
486
buf [0 ] |= NFC_CMD_RBLOCK_ACK ;
471
487
472
488
nfc_write_frame (buf , block_offset );
0 commit comments