Skip to content

Commit

Permalink
PR review, factorize code
Browse files Browse the repository at this point in the history
  • Loading branch information
yrichard-ledger committed May 30, 2024
1 parent 41fe67e commit b08c539
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions src/os_io_nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,33 +76,32 @@ void io_nfc_recv_event(void)
}
}

static void nfc_send_rapdu(const uint8_t *packet, uint16_t packet_length)
{
if ((size_t) (packet_length + 3) > sizeof(G_io_seproxyhal_spi_buffer)) {
return;
}

G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_NFC_RAPDU;
G_io_seproxyhal_spi_buffer[1] = (packet_length & 0xff00) >> 8;
G_io_seproxyhal_spi_buffer[2] = packet_length & 0xff;
memcpy(G_io_seproxyhal_spi_buffer + 3, packet, packet_length);
io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer, 3 + packet_length);
}

void io_nfc_send_response(const uint8_t *packet, uint16_t packet_length)
{
LEDGER_PROTOCOL_tx(&ledger_protocol_data, packet, packet_length);
if (ledger_protocol_data.tx_chunk_length >= 2) {
// reply the NFC APDU over SEPROXYHAL protocol
G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_NFC_RAPDU;
G_io_seproxyhal_spi_buffer[1] = (ledger_protocol_data.tx_chunk_length) >> 8;
G_io_seproxyhal_spi_buffer[2] = (ledger_protocol_data.tx_chunk_length);
memcpy(G_io_seproxyhal_spi_buffer + 3,
ledger_protocol_data.tx_chunk,
ledger_protocol_data.tx_chunk_length);
io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer,
3 + ledger_protocol_data.tx_chunk_length);
// send the NFC APDU chunk
nfc_send_rapdu(ledger_protocol_data.tx_chunk, ledger_protocol_data.tx_chunk_length);
}

while (ledger_protocol_data.tx_apdu_buffer) {
LEDGER_PROTOCOL_tx(&ledger_protocol_data, NULL, 0);
if (ledger_protocol_data.tx_chunk_length >= 2) {
// reply the NFC APDU over SEPROXYHAL protocol
G_io_seproxyhal_spi_buffer[0] = SEPROXYHAL_TAG_NFC_RAPDU;
G_io_seproxyhal_spi_buffer[1] = (ledger_protocol_data.tx_chunk_length) >> 8;
G_io_seproxyhal_spi_buffer[2] = (ledger_protocol_data.tx_chunk_length);
memcpy(G_io_seproxyhal_spi_buffer + 3,
ledger_protocol_data.tx_chunk,
ledger_protocol_data.tx_chunk_length);
io_seproxyhal_spi_send(G_io_seproxyhal_spi_buffer,
3 + ledger_protocol_data.tx_chunk_length);
// send the NFC APDU chunk
nfc_send_rapdu(ledger_protocol_data.tx_chunk, ledger_protocol_data.tx_chunk_length);
}
}
}
Expand Down

0 comments on commit b08c539

Please sign in to comment.