Skip to content

Commit

Permalink
Make sure NFC response callback is called once
Browse files Browse the repository at this point in the history
Only call cb with error flag set on card disconnection
  • Loading branch information
yrichard-ledger committed Oct 22, 2024
1 parent 93c3a80 commit 189ad01
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/os_io_nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,26 +150,30 @@ void io_nfc_process_events(void)
if (G_io_reader_ctx.response_received) {
G_io_reader_ctx.response_received = false;
if (G_io_reader_ctx.resp_callback != NULL) {
G_io_reader_ctx.resp_callback(false,
false,
ledger_protocol_data.rx_apdu_buffer,
ledger_protocol_data.rx_apdu_length);
nfc_resp_callback_t resp_cb = G_io_reader_ctx.resp_callback;
G_io_reader_ctx.resp_callback = NULL;
resp_cb(false,
false,
ledger_protocol_data.rx_apdu_buffer,
ledger_protocol_data.rx_apdu_length);
}
memset(ledger_protocol_data.rx_apdu_buffer, 0, ledger_protocol_data.rx_apdu_length);
}

if (G_io_reader_ctx.resp_callback != NULL && G_io_reader_ctx.remaining_ms == 0) {
G_io_reader_ctx.resp_callback(false, true, NULL, 0);
nfc_resp_callback_t resp_cb = G_io_reader_ctx.resp_callback;
G_io_reader_ctx.resp_callback = NULL;
resp_cb(false, true, NULL, 0);
}

if (G_io_reader_ctx.event_happened) {
G_io_reader_ctx.event_happened = 0;

// if in_progress, call the resp_callback with an error
if (G_io_reader_ctx.resp_callback != NULL) {
G_io_reader_ctx.resp_callback(true, false, NULL, 0);
// If card is removed during an APDU processing, call the resp_callback with an error
if (G_io_reader_ctx.resp_callback != NULL && G_io_reader_ctx.last_event == CARD_REMOVED) {
nfc_resp_callback_t resp_cb = G_io_reader_ctx.resp_callback;
G_io_reader_ctx.resp_callback = NULL;
resp_cb(true, false, NULL, 0);
}

if (G_io_reader_ctx.evt_callback != NULL) {
Expand Down

0 comments on commit 189ad01

Please sign in to comment.