@@ -127,7 +127,7 @@ static uint16_t ISO144434ProcessBlock(uint8_t *Buffer, uint16_t ByteCount, uint1
127
127
ISO144434SwitchState (ISO14443_4_STATE_ACTIVE );
128
128
const char * debugPrintStr = PSTR ("ISO14443-4: SEND RATS" );
129
129
LogDebuggingMsg (debugPrintStr );
130
- return GetAndSetBufferCRCA ( Buffer , ByteCount );
130
+ return ByteCount * BITS_PER_BYTE ; // PM3 expects no CRCA bytes
131
131
}
132
132
case ISO14443_4_STATE_ACTIVE : {
133
133
/* See: ISO/IEC 14443-4; 7.1 Block format */
@@ -277,6 +277,7 @@ Iso144433AStateType Iso144433AIdleState = ISO14443_3A_STATE_IDLE;
277
277
278
278
void ISO144433ASwitchState (Iso144433AStateType NewState ) {
279
279
Iso144433AState = NewState ;
280
+ StateRetryCount = 0x00 ;
280
281
DesfireLogISOStateChange (Iso144433AState , LOG_ISO14443_3A_STATE );
281
282
}
282
283
@@ -316,9 +317,9 @@ uint16_t ISO144433APiccProcess(uint8_t *Buffer, uint16_t BitCount) {
316
317
REQA bytes, in between which we would have already sent
317
318
back a response, so that we should not reset. */
318
319
decrementRetryCount = false;
319
- } else if (Cmd == ISO14443A_CMD_REQA || Cmd == ISO14443A_CMD_WUPA ) {
320
+ } else if (Cmd == ISO14443A_CMD_REQA || ISO14443ACmdIsWUPA ( Cmd ) ) {
320
321
ISO144434Reset ();
321
- ISO144433ASwitchState (ISO14443_3A_STATE_READY1 );
322
+ ISO144433ASwitchState (ISO14443_3A_STATE_IDLE );
322
323
decrementRetryCount = false;
323
324
} else if (ISO144433AIsHalt (Buffer , BitCount )) {
324
325
LogEntry (LOG_INFO_APP_CMD_HALT , NULL , 0 );
@@ -339,7 +340,7 @@ uint16_t ISO144433APiccProcess(uint8_t *Buffer, uint16_t BitCount) {
339
340
/* See: ISO/IEC 14443-3, clause 6.2 */
340
341
switch (Iso144433AState ) {
341
342
case ISO14443_3A_STATE_HALT :
342
- if (Cmd != ISO14443A_CMD_WUPA ) {
343
+ if (! ISO14443ACmdIsWUPA ( Cmd ) ) {
343
344
const char * debugPrintStr = PSTR ("ISO14443-4: HALT / NOT WUPA" );
344
345
LogDebuggingMsg (debugPrintStr );
345
346
break ;
@@ -349,12 +350,6 @@ uint16_t ISO144433APiccProcess(uint8_t *Buffer, uint16_t BitCount) {
349
350
/* Fall-through */
350
351
351
352
case ISO14443_3A_STATE_IDLE :
352
- if (Cmd != ISO14443A_CMD_REQA &&
353
- Cmd != ISO14443A_CMD_WUPA ) {
354
- const char * debugPrintStr = PSTR ("ISO14443-4: IDLE / NOT WUPA 0x%02x" );
355
- DEBUG_PRINT_P (debugPrintStr );
356
- break ;
357
- }
358
353
Iso144433AIdleState = Iso144433AState ;
359
354
ISO144433ASwitchState (ISO14443_3A_STATE_READY1 );
360
355
Buffer [0 ] = (ATQA_VALUE ) & 0x00FF ;
@@ -364,7 +359,7 @@ uint16_t ISO144433APiccProcess(uint8_t *Buffer, uint16_t BitCount) {
364
359
return ISO14443A_ATQA_FRAME_SIZE_BYTES * BITS_PER_BYTE ;
365
360
366
361
case ISO14443_3A_STATE_READY1 :
367
- if (Cmd == ISO14443A_CMD_SELECT_CL1 || Cmd == ISO14443A_CMD_REQA || Cmd == ISO14443A_CMD_WUPA ) {
362
+ if (Cmd == ISO14443A_CMD_SELECT_CL1 || Cmd == ISO14443A_CMD_REQA || ISO14443ACmdIsWUPA ( Cmd ) ) {
368
363
/* Load UID CL1 and perform anticollision. */
369
364
ConfigurationUidType Uid ;
370
365
ApplicationGetUid (Uid );
@@ -414,10 +409,14 @@ uint16_t ISO144433APiccProcess(uint8_t *Buffer, uint16_t BitCount) {
414
409
/* Recognise the HLTA command */
415
410
if (ISO144433AIsHalt (Buffer , BitCount )) {
416
411
LogEntry (LOG_INFO_APP_CMD_HALT , NULL , 0 );
417
- ISO144433ASwitchState (ISO14443_3A_STATE_HALT );
412
+ ISO144434SwitchState (ISO14443_3A_STATE_HALT );
418
413
const char * logMsg = PSTR ("ISO14443-3: Got HALT" );
419
414
LogDebuggingMsg (logMsg );
420
415
return ISO14443A_APP_NO_RESPONSE ;
416
+ } else if (Cmd == ISO14443A_CMD_RATS ) {
417
+ ISO144433ASwitchState (ISO14443_4_STATE_EXPECT_RATS );
418
+ const char * logMsg = PSTR ("ISO14443-3/4: EXPECTING RATS" );
419
+ LogDebuggingMsg (logMsg );
421
420
}
422
421
/* Forward to ISO/IEC 14443-4 processing code */
423
422
uint16_t ByteCount = (BitCount + BITS_PER_BYTE - 1 ) / BITS_PER_BYTE ;
0 commit comments