Skip to content

Commit

Permalink
wip fix pr
Browse files Browse the repository at this point in the history
  • Loading branch information
yrichard-ledger committed May 17, 2024
1 parent 3187eaf commit f246e72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
6 changes: 4 additions & 2 deletions lib_blewbxx_impl/src/ledger_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,8 @@ static void attribute_modified(const uint8_t *buffer, uint16_t length)
copy_apdu_to_app(true);
}
else if (ledger_ble_data.resp_length) {
LEDGER_PROTOCOL_tx(&ledger_protocol_data, ledger_ble_data.resp, ledger_ble_data.resp_length);
LEDGER_PROTOCOL_tx(
&ledger_protocol_data, ledger_ble_data.resp, ledger_ble_data.resp_length);
ledger_ble_data.resp_length = 0;
notify_chunk();
}
Expand Down Expand Up @@ -1058,7 +1059,8 @@ void LEDGER_BLE_send(const uint8_t *packet, uint16_t packet_length)
}
else {
if ((ledger_ble_data.resp_length != 0) && (U2BE(ledger_ble_data.resp, 0) != SWO_SUCCESS)) {
LEDGER_PROTOCOL_tx(&ledger_protocol_data, ledger_ble_data.resp, ledger_ble_data.resp_length);
LEDGER_PROTOCOL_tx(
&ledger_protocol_data, ledger_ble_data.resp, ledger_ble_data.resp_length);
}
else {
LEDGER_PROTOCOL_tx(&ledger_protocol_data, packet, packet_length);
Expand Down
35 changes: 19 additions & 16 deletions src/os_io_nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "os_io_seproxyhal.h"
#include <string.h>


#ifdef DEBUG
#define LOG printf
#else
Expand All @@ -39,15 +38,17 @@
#include "os.h"
#include "ledger_protocol.h"

static uint8_t rx_apdu_buffer[IO_APDU_BUFFER_SIZE];
static uint8_t rx_apdu_buffer[IO_APDU_BUFFER_SIZE];
static ledger_protocol_t ledger_protocol_data;

void io_nfc_init(void){
void io_nfc_init(void)
{
memset(&rx_apdu_buffer, 0, sizeof(rx_apdu_buffer));
memset(&ledger_protocol_data, 0, sizeof(ledger_protocol_data));
ledger_protocol_data.rx_apdu_buffer = rx_apdu_buffer;
ledger_protocol_data.rx_apdu_buffer_max_length = sizeof(rx_apdu_buffer);
ledger_protocol_data.mtu = MIN(sizeof(ledger_protocol_data.tx_chunk), sizeof(G_io_seproxyhal_spi_buffer) - 3);
ledger_protocol_data.mtu
= MIN(sizeof(ledger_protocol_data.tx_chunk), sizeof(G_io_seproxyhal_spi_buffer) - 3);
#ifdef HAVE_LOCAL_APDU_BUFFER
ledger_protocol_data.rx_dst_buffer = NULL;
#else
Expand All @@ -60,8 +61,8 @@ void io_nfc_recv_event(void)
{
size_t size = U2BE(G_io_seproxyhal_spi_buffer, 1);

//TODO check max size
LEDGER_PROTOCOL_rx(&ledger_protocol_data, G_io_seproxyhal_spi_buffer+3, size);
// TODO check max size
LEDGER_PROTOCOL_rx(&ledger_protocol_data, G_io_seproxyhal_spi_buffer + 3, size);

if (ledger_protocol_data.rx_apdu_status == APDU_STATUS_COMPLETE) {
memcpy(ledger_protocol_data.rx_dst_buffer,
Expand All @@ -75,18 +76,19 @@ void io_nfc_recv_event(void)
}
}



void io_nfc_send_response(const uint8_t *packet, uint16_t 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);
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);
}

while (ledger_protocol_data.tx_apdu_buffer) {
Expand All @@ -96,12 +98,13 @@ void io_nfc_send_response(const uint8_t *packet, uint16_t packet_length){
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);
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);
}
}
}

#endif // HAVE_NFC


0 comments on commit f246e72

Please sign in to comment.