@@ -178,13 +178,13 @@ bool UnitST25R3916::configure_emulation_a()
178178}
179179
180180uint32_t UnitST25R3916::nfcaTransceive (uint8_t * rx, uint16_t & rx_len, const uint8_t * tx, const uint16_t tx_len,
181- const uint32_t timeout_ms)
181+ const uint32_t timeout_ms, const uint16_t min_rx_len )
182182{
183183 if (!nfcaTransmit (tx, tx_len, timeout_ms)) {
184184 M5_LIB_LOGE (" nfcaTransmit FAILED tx_len=%u" , tx_len);
185185 return false ;
186186 }
187- return nfcaReceive (rx, rx_len, timeout_ms);
187+ return nfcaReceive (rx, rx_len, timeout_ms, min_rx_len );
188188}
189189
190190bool UnitST25R3916::nfcaTransmit (const uint8_t * tx, const uint16_t tx_len, const uint32_t timeout_ms)
@@ -215,7 +215,7 @@ bool UnitST25R3916::nfcaEmulationTransmit(const uint8_t* tx, const uint16_t tx_l
215215 writeNumberOfTransmittedBytes (tx_len, 0 ) && writeDirectCommand (CMD_TRANSMIT_WITH_CRC );
216216}
217217
218- bool UnitST25R3916::nfcaReceive (uint8_t * rx, uint16_t & rx_len, const uint32_t timeout_ms)
218+ bool UnitST25R3916::nfcaReceive (uint8_t * rx, uint16_t & rx_len, const uint32_t timeout_ms, const uint16_t min_rx_len )
219219{
220220 CHECK_MODE ();
221221
@@ -225,7 +225,7 @@ bool UnitST25R3916::nfcaReceive(uint8_t* rx, uint16_t& rx_len, const uint32_t ti
225225 return false ;
226226 }
227227
228- if (!wait_for_FIFO (timeout_ms, rx_len_org )) {
228+ if (!wait_for_FIFO (timeout_ms, min_rx_len )) {
229229 // M5_LIB_LOGE("nfcaReceive timeout rx_len=%u timeout_ms=%u", rx_len_org, timeout_ms);
230230 M5_LIB_LOGD (" Timeout" );
231231 return false ;
@@ -392,7 +392,7 @@ bool UnitST25R3916::nfcaSelectWithAnticollision(bool& completed, PICC& picc, con
392392
393393 // Select
394394 uint16_t rx_len{3 };
395- if (!nfcaTransceive (rbuf, rx_len, select_frame, sizeof (select_frame), TIMEOUT_SELECT ) || rx_len != 3 ) {
395+ if (!nfcaTransceive (rbuf, rx_len, select_frame, sizeof (select_frame), TIMEOUT_SELECT , 3 ) || rx_len != 3 ) {
396396 M5_LIB_LOGD (" Failed to select" );
397397 return false ;
398398 }
@@ -461,7 +461,7 @@ bool UnitST25R3916::nfcaSelect(const PICC& picc)
461461
462462 // Select
463463 uint16_t rx_len{3 };
464- if (!nfcaTransceive (rbuf, rx_len, select_frame, sizeof (select_frame), TIMEOUT_SELECT ) || rx_len != 3 ) {
464+ if (!nfcaTransceive (rbuf, rx_len, select_frame, sizeof (select_frame), TIMEOUT_SELECT , 3 ) || rx_len != 3 ) {
465465 M5_LIB_LOGD (" Failed to select" );
466466 return false ;
467467 }
@@ -514,7 +514,7 @@ bool UnitST25R3916::nfcaReadBlock(uint8_t rx[16], const uint8_t addr)
514514 if (_encrypted) {
515515 return mifare_classic_transceive_encrypt (rx, rx_len, cmd, sizeof (cmd), TIMEOUT_READ , true , true );
516516 }
517- return nfcaTransceive (rx, rx_len, cmd, sizeof (cmd), TIMEOUT_READ );
517+ return nfcaTransceive (rx, rx_len, cmd, sizeof (cmd), TIMEOUT_READ , 16 );
518518}
519519
520520bool UnitST25R3916::nfcaWriteBlock (const uint8_t addr, const uint8_t tx[16 ])
@@ -553,9 +553,9 @@ bool UnitST25R3916::nfcaWriteBlock(const uint8_t addr, const uint8_t tx[16])
553553 }
554554
555555 //
556- if (nfcaTransceive (rx, rx_len, cmd, sizeof (cmd), TIMEOUT_WRITE1 ) && rx[0 ] == ACK_NIBBLE ) {
556+ if (nfcaTransceive (rx, rx_len, cmd, sizeof (cmd), TIMEOUT_WRITE1 , 1 ) && rx[0 ] == ACK_NIBBLE ) {
557557 rx_len = 1 ;
558- if (nfcaTransceive (rx, rx_len, buf, sizeof (buf), TIMEOUT_WRITE2 ) && rx[0 ] == ACK_NIBBLE ) {
558+ if (nfcaTransceive (rx, rx_len, buf, sizeof (buf), TIMEOUT_WRITE2 , 1 ) && rx[0 ] == ACK_NIBBLE ) {
559559 return true ;
560560 }
561561 }
@@ -702,7 +702,7 @@ bool UnitST25R3916::mifare_classic_authenticate(const Command cmd, const PICC& p
702702 return false ;
703703 }
704704 } else {
705- if (!nfcaTransceive (RB , rlen, auth_frame, sizeof (auth_frame), TIMEOUT_AUTH1 )) {
705+ if (!nfcaTransceive (RB , rlen, auth_frame, sizeof (auth_frame), TIMEOUT_AUTH1 , 4 )) {
706706 M5_LIB_LOGD (" Failed to send AUTH1(plain) %u" , rlen);
707707 return false ;
708708 }
0 commit comments