21#include "os_io_legacy_types.h"
22#include "os_io_seph_cmd.h"
23#include "os_io_seph_ux.h"
24#include "os_io_default_apdu.h"
25#include "seproxyhal_protocol.h"
31#include "usbd_ledger.h"
35#include "ble_ledger.h"
49#define SW_WRONG_RESPONSE_LENGTH 0xB000
51static uint8_t need_to_start_io;
58 io_seph_ux_display_bagl_element(element);
69 case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT:
73 case SEPROXYHAL_TAG_FINGER_EVENT:
77 case SEPROXYHAL_TAG_TICKER_EVENT:
82 io_nfc_process_events();
86 case SEPROXYHAL_TAG_NFC_EVENT:
88 io_nfc_process_events();
102 need_to_start_io = 1;
109 if (need_to_start_io) {
110#ifndef USE_OS_IO_STACK
111 io_seproxyhal_io_heartbeat();
112 io_seproxyhal_io_heartbeat();
113 io_seproxyhal_io_heartbeat();
116 need_to_start_io = 0;
120 for (uint8_t retries = 5; retries && status <= 0; retries--) {
122 while (status <= 0) {
124 status = io_legacy_apdu_rx(1);
135 if (rdatalist && count > 0) {
136 for (
size_t i = 0; i < count; i++) {
137 const buffer_t *rdata = &rdatalist[i];
139 if (!
buffer_copy(rdata, G_io_tx_buffer + length,
sizeof(G_io_tx_buffer) - length - 2)) {
144 PRINTF(
"<= FRAG (%u/%u) RData=%.*H\n", i + 1, count, rdata->
size, rdata->
ptr);
147 PRINTF(
"<= SW=%04X | RData=%.*H\n", sw, length, G_io_tx_buffer);
150 PRINTF(
"<= SW=%04X | RData=\n", sw);
159 PRINTF(
"Swap answer is processed. Send it\n");
161 if (io_legacy_apdu_tx(G_io_tx_buffer, length) >= 0) {
162 PRINTF(
"Returning to Exchange with status %d\n", (sw ==
SW_OK));
164 PRINTF(
"os_lib_end\n");
168 PRINTF(
"Unrecoverable\n");
174 status = io_legacy_apdu_tx(G_io_tx_buffer, length);
183#ifdef STANDARD_APP_SYNC_RAPDU
184WEAK bool io_recv_and_process_event(
void)
186 int status = io_legacy_apdu_rx(1);
bool buffer_copy(const buffer_t *buffer, uint8_t *out, size_t out_len)
uint8_t G_io_seproxyhal_spi_buffer[OS_IO_SEPH_BUFFER_SIZE]
WEAK unsigned char io_event(unsigned char channel)
#define SW_WRONG_RESPONSE_LENGTH
WEAK int io_send_response_buffers(const buffer_t *rdatalist, size_t count, uint16_t sw)
WEAK int io_recv_command()
WEAK void app_ticker_event_callback(void)
size_t size
Pointer to byte buffer.
size_t offset
Size of byte buffer.
volatile bool G_called_from_swap
volatile bool G_swap_response_ready
volatile uint8_t * G_swap_signing_return_value_address
#define UX_TICKER_EVENT(seph_packet, callback)
#define UX_FINGER_EVENT(seph_packet)
void io_seproxyhal_display(const bagl_element_t *element)
#define UX_DEFAULT_EVENT()
#define UX_BUTTON_PUSH_EVENT(seph_packet)
void write_u16_be(uint8_t *ptr, size_t offset, uint16_t value)