Skip to content

Commit 7ad1379

Browse files
Merge pull request #1051 from LedgerHQ/spo-fix-recover
[protocol]: Handle empty last chunk
2 parents 52dab0b + f2e9785 commit 7ad1379

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

protocol/src/ledger_protocol.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ static ledger_protocol_result_t process_apdu_chunk(ledger_protocol_t *handle,
6666
ledger_protocol_result_t result = LP_ERROR_INVALID_PARAMETER;
6767
// Check the sequence number
6868
if ((length < 2) || ((uint16_t) U2BE(buffer, 0) != handle->rx_apdu_sequence_number)) {
69-
handle->rx_apdu_status = APDU_STATUS_WAITING;
70-
result = LP_ERROR_NOT_ENOUGH_SPACE;
71-
goto error;
69+
if (handle->rx_apdu_status == APDU_STATUS_NEED_MORE_DATA) {
70+
handle->rx_apdu_status = APDU_STATUS_WAITING;
71+
result = LP_ERROR_NOT_ENOUGH_SPACE;
72+
goto error;
73+
}
74+
else {
75+
// Ledger Live is well known for sending empty apdu chunk
76+
// after the last apdu chunk fits totally in the MTU
77+
return LP_SUCCESS;
78+
}
7279
}
7380
// Check total length presence
7481
if ((length < 4) && (handle->rx_apdu_sequence_number == 0)) {

0 commit comments

Comments
 (0)