Skip to content

Commit

Permalink
Keep reference to RX apdu buffer in NFC reader context
Browse files Browse the repository at this point in the history
  • Loading branch information
yrichard-ledger authored and srasoamiaramanana-ledger committed Nov 5, 2024
1 parent f600b58 commit 149a0a2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 3 additions & 0 deletions include/os_io_nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ struct nfc_reader_context {
unsigned int remaining_ms;
enum nfc_event last_event;
struct card_info card;
uint8_t *apdu_rx;
size_t apdu_rx_len; // Used length
size_t apdu_rx_max_size; // Max size of buffer
};

extern struct nfc_reader_context G_io_reader_ctx;
Expand Down
9 changes: 4 additions & 5 deletions src/os_io_nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ void io_nfc_init(void)
LEDGER_PROTOCOL_init(&ledger_protocol_data);
#ifdef HAVE_NFC_READER
memset((void *) &G_io_reader_ctx, 0, sizeof(G_io_reader_ctx));
G_io_reader_ctx.apdu_rx = rx_apdu_buffer;
G_io_reader_ctx.apdu_rx_max_size = sizeof(rx_apdu_buffer);
#endif // HAVE_NFC_READER
}

Expand All @@ -69,6 +71,7 @@ void io_nfc_recv_event(void)
#ifdef HAVE_NFC_READER
if (G_io_reader_ctx.reader_mode) {
G_io_reader_ctx.response_received = true;
G_io_reader_ctx.apdu_rx_len = ledger_protocol_data.rx_apdu_length;
return;
}
#endif // HAVE_NFC_READER
Expand Down Expand Up @@ -152,12 +155,8 @@ void io_nfc_process_events(void)
if (G_io_reader_ctx.resp_callback != NULL) {
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);
resp_cb(false, false, G_io_reader_ctx.apdu_rx, G_io_reader_ctx.apdu_rx_len);
}
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) {
Expand Down

0 comments on commit 149a0a2

Please sign in to comment.