28 #ifdef HAVE_NFC_READER
29 #include "os_io_nfc.h"
35 #define SW_WRONG_RESPONSE_LENGTH 0xB000
39 #ifdef HAVE_NFC_READER
40 struct nfc_reader_context G_io_reader_ctx;
46 static uint32_t G_output_len = 0;
68 case SEPROXYHAL_TAG_BUTTON_PUSH_EVENT:
71 case SEPROXYHAL_TAG_STATUS_EVENT:
72 if (G_io_apdu_media == IO_APDU_MEDIA_USB_HID &&
74 SEPROXYHAL_TAG_STATUS_EVENT_FLAG_USB_POWERED)) {
75 THROW(EXCEPTION_IO_RESET);
78 case SEPROXYHAL_TAG_DISPLAY_PROCESSED_EVENT:
87 case SEPROXYHAL_TAG_FINGER_EVENT:
91 case SEPROXYHAL_TAG_TICKER_EVENT:
94 #ifdef HAVE_NFC_READER
96 io_nfc_process_events();
104 if (!io_seproxyhal_spi_is_status_sent()) {
105 io_seproxyhal_general_status();
113 switch (channel & ~(IO_FLAGS)) {
114 case CHANNEL_KEYBOARD:
118 io_seproxyhal_spi_send(G_io_apdu_buffer, tx_len);
120 if (channel & IO_RESET_AFTER_REPLIED) {
127 return io_seproxyhal_spi_recv(G_io_apdu_buffer,
sizeof(G_io_apdu_buffer), 0);
130 THROW(INVALID_PARAMETER);
147 switch (G_io_state) {
149 ret = io_exchange(CHANNEL_APDU | IO_CONTINUE_RX, G_output_len);
154 ret = io_exchange(CHANNEL_APDU | IO_ASYNCH_REPLY, G_output_len);
171 if (rdatalist && count > 0) {
172 for (
size_t i = 0; i < count; i++) {
173 const buffer_t *rdata = &rdatalist[i];
176 G_io_apdu_buffer + G_output_len,
177 sizeof(G_io_apdu_buffer) - G_output_len - 2)) {
182 PRINTF(
"<= FRAG (%u/%u) RData=%.*H\n", i + 1, count, rdata->
size, rdata->
ptr);
185 PRINTF(
"<= SW=%04X | RData=%.*H\n", sw, G_output_len, G_io_apdu_buffer);
188 PRINTF(
"<= SW=%04X | RData=\n", sw);
197 PRINTF(
"Swap answer is processed. Send it\n");
198 if (io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, G_output_len) == 0) {
199 swap_finalize_exchange_sign_transaction(sw ==
SW_OK);
202 PRINTF(
"Unrecoverable\n");
208 switch (G_io_state) {
213 #ifdef STANDARD_APP_SYNC_RAPDU
225 ret = io_exchange(CHANNEL_APDU | IO_RETURN_AFTER_TX, G_output_len);
234 #ifdef STANDARD_APP_SYNC_RAPDU
235 WEAK bool io_recv_and_process_event(
void)
237 int apdu_state = G_io_app.apdu_state;
239 os_io_seph_recv_and_process(0);
243 if (apdu_state == APDU_IDLE && G_io_app.apdu_state != APDU_IDLE) {
bool buffer_copy(const buffer_t *buffer, uint8_t *out, size_t out_len)
uint8_t G_io_seproxyhal_spi_buffer[IO_SEPROXYHAL_BUFFER_SIZE_B]
WEAK uint16_t io_exchange_al(uint8_t channel, uint16_t tx_len)
#define SW_WRONG_RESPONSE_LENGTH
WEAK int io_send_response_buffers(const buffer_t *rdatalist, size_t count, uint16_t sw)
WEAK uint8_t io_event(uint8_t channel)
WEAK int io_recv_command()
WEAK void app_ticker_event_callback(void)
@ RECEIVED
ready for new event
__attribute__((section("._nbgl_fonts_"))) const
return the non-unicode font corresponding to the given font ID
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
#define UX_TICKER_EVENT(seph_packet, callback)
#define UX_FINGER_EVENT(seph_packet)
void io_seproxyhal_display(const bagl_element_t *element)
void io_seproxyhal_display_default(const bagl_element_t *element)
#define UX_DEFAULT_EVENT()
#define UX_BUTTON_PUSH_EVENT(seph_packet)
#define UX_DISPLAYED_EVENT(displayed_callback)
void write_u16_be(uint8_t *ptr, size_t offset, uint16_t value)