Embedded SDK
Embedded SDK
Loading...
Searching...
No Matches
Macros | Typedefs | Enumerations | Functions
swap_error_code_helpers.h File Reference
#include "io.h"
#include "buffer.h"
Include dependency graph for swap_error_code_helpers.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define SWAP_ERROR_HELPER_MAX_BUFFER_COUNT   8
 
#define send_swap_error_with_string( status_word, common_error_code, application_specific_error_code, format, ...)
 

Typedefs

typedef enum swap_error_common_code_e swap_error_common_code_t
 

Enumerations

enum  swap_error_common_code_e {
  SWAP_EC_ERROR_INTERNAL = 0x00 , SWAP_EC_ERROR_WRONG_AMOUNT = 0x01 , SWAP_EC_ERROR_WRONG_DESTINATION = 0x02 , SWAP_EC_ERROR_WRONG_FEES = 0x03 ,
  SWAP_EC_ERROR_WRONG_METHOD = 0x04 , SWAP_EC_ERROR_CROSSCHAIN_WRONG_MODE = 0x05 , SWAP_EC_ERROR_CROSSCHAIN_WRONG_METHOD = 0x06 , SWAP_EC_ERROR_CROSSCHAIN_WRONG_HASH = 0x07 ,
  SWAP_EC_ERROR_GENERIC = 0xFF
}
 

Functions

NORETURN void send_swap_error_simple (uint16_t status_word, uint8_t common_error_code, uint8_t application_specific_error_code)
 
NORETURN void send_swap_error_with_buffer (uint16_t status_word, uint8_t common_error_code, uint8_t application_specific_error_code, const buffer_t buffer_data)
 
NORETURN void send_swap_error_with_buffers (uint16_t status_word, uint8_t common_error_code, uint8_t application_specific_error_code, const buffer_t *buffer_data, size_t count)
 

Macro Definition Documentation

◆ send_swap_error_with_string

#define send_swap_error_with_string (   status_word,
  common_error_code,
  application_specific_error_code,
  format,
  ... 
)
Value:
do { \
/* Up to a full data apdu minus the status word and the swap error code */ \
char format_buffer[sizeof(G_io_apdu_buffer) - sizeof(status_word) - 2] = {0}; \
/* snprintf always returns 0 on our platform, don't check the return value */ \
/* See https://github.com/LedgerHQ/ledger-secure-sdk/issues/236 */ \
snprintf(format_buffer, sizeof(format_buffer), format, ##__VA_ARGS__); \
PRINTF("send_swap_error_with_string %s\n", format_buffer); \
buffer_t string_buffer; \
string_buffer.ptr = (uint8_t *) &format_buffer; \
string_buffer.size = strnlen(format_buffer, sizeof(format_buffer)); \
string_buffer.offset = 0; \
send_swap_error_with_buffers( \
status_word, common_error_code, application_specific_error_code, &string_buffer, 1); \
} while (0)
uint8_t * ptr
Definition buffer.h:22
size_t size
Pointer to byte buffer.
Definition buffer.h:23
size_t offset
Size of byte buffer.
Definition buffer.h:24

Macro to send a swap error with a formatted string as data.

Constructs a buffer from a formatted string and passes it to send_swap_error_with_buffers.

Parameters
status_wordRAPDU status word.
common_error_codeCommon error code.
application_specific_error_codeApplication-specific error code.
formatprintf-style format string.
...Additional arguments for formatting.

Definition at line 127 of file swap_error_code_helpers.h.

◆ SWAP_ERROR_HELPER_MAX_BUFFER_COUNT

#define SWAP_ERROR_HELPER_MAX_BUFFER_COUNT   8

Sends a swap error with multiple buffers containing error details as data.

Parameters
status_wordRAPDU status word.
common_error_codeCommon error code.
application_specific_error_codeApplication-specific error code.
buffer_dataArray of buffers with error details. SWAP_ERROR_HELPER_MAX_BUFFER_COUNT
countNumber of buffers provided.

Definition at line 107 of file swap_error_code_helpers.h.

Typedef Documentation

◆ swap_error_common_code_t

Enumeration Type Documentation

◆ swap_error_common_code_e

Enumerator
SWAP_EC_ERROR_INTERNAL 
SWAP_EC_ERROR_WRONG_AMOUNT 
SWAP_EC_ERROR_WRONG_DESTINATION 
SWAP_EC_ERROR_WRONG_FEES 
SWAP_EC_ERROR_WRONG_METHOD 
SWAP_EC_ERROR_CROSSCHAIN_WRONG_MODE 
SWAP_EC_ERROR_CROSSCHAIN_WRONG_METHOD 
SWAP_EC_ERROR_CROSSCHAIN_WRONG_HASH 
SWAP_EC_ERROR_GENERIC 

Definition at line 61 of file swap_error_code_helpers.h.

Function Documentation

◆ send_swap_error_simple()

NORETURN void send_swap_error_simple ( uint16_t  status_word,
uint8_t  common_error_code,
uint8_t  application_specific_error_code 
)

Sends a basic swap error with no extra data.

Parameters
status_wordRAPDU status word.
common_error_codeCommon error code defined in swap_error_common_code_t.
application_specific_error_codeApplication-specific error code.

Definition at line 8 of file swap_error_code_helpers.c.

◆ send_swap_error_with_buffer()

NORETURN void send_swap_error_with_buffer ( uint16_t  status_word,
uint8_t  common_error_code,
uint8_t  application_specific_error_code,
const buffer_t  buffer_data 
)

Sends a swap error with one additional buffer data.

Parameters
status_wordRAPDU status word.
common_error_codeCommon error code.
application_specific_error_codeApplication-specific error code.
buffer_dataAdditional application-specific error details.

Definition at line 16 of file swap_error_code_helpers.c.

◆ send_swap_error_with_buffers()

NORETURN void send_swap_error_with_buffers ( uint16_t  status_word,
uint8_t  common_error_code,
uint8_t  application_specific_error_code,
const buffer_t buffer_data,
size_t  count 
)

Definition at line 25 of file swap_error_code_helpers.c.