@@ -140,6 +140,8 @@ bool IsoDEP::transceiveINF(uint8_t* rx_inf, uint16_t& rx_inf_len, const uint8_t*
140140 uint8_t rx_buf[MAX_FRAME_SIZE ]{};
141141 uint16_t tx_off{};
142142 uint16_t rx_written{};
143+ bool received_i_block{};
144+ uint8_t last_picc_i_bn{};
143145
144146 // Transmit chaining
145147 while (tx_off < tx_inf_len) {
@@ -309,8 +311,10 @@ bool IsoDEP::transceiveINF(uint8_t* rx_inf, uint16_t& rx_inf_len, const uint8_t*
309311 memcpy (rx_inf + rx_written, rx_buf + idx, inf_len);
310312 rx_written = (uint16_t )(rx_written + inf_len);
311313
312- bool resp_more = i_has_more (pcb);
313- info->more = resp_more;
314+ bool resp_more = i_has_more (pcb);
315+ info->more = resp_more;
316+ received_i_block = true ;
317+ last_picc_i_bn = i_bn (pcb);
314318
315319 // Response chaining: send R-ACK and receive next I-Block (WTX may appear)
316320 while (resp_more) {
@@ -396,8 +400,9 @@ bool IsoDEP::transceiveINF(uint8_t* rx_inf, uint16_t& rx_inf_len, const uint8_t*
396400 memcpy (rx_inf + rx_written, rx_buf + idx2, inf_len2);
397401 rx_written = (uint16_t )(rx_written + inf_len2);
398402
399- pcb = pcb2;
400- resp_more = i_has_more (pcb2);
403+ pcb = pcb2;
404+ resp_more = i_has_more (pcb2);
405+ last_picc_i_bn = i_bn (pcb2);
401406 break ;
402407 }
403408 }
@@ -416,8 +421,8 @@ bool IsoDEP::transceiveINF(uint8_t* rx_inf, uint16_t& rx_inf_len, const uint8_t*
416421 }
417422
418423 // next chunk
419- tx_off = (uint16_t )(tx_off + chunk);
420- _block_num ^= 1 ;
424+ tx_off = (uint16_t )(tx_off + chunk);
425+ _block_num = received_i_block ? (last_picc_i_bn ^ 0x01 ) : (_block_num ^ 0x01 ) ;
421426 }
422427
423428 rx_inf_len = rx_written;
0 commit comments