diff --git a/src_features/signTx/cmd_signTx.c b/src_features/signTx/cmd_signTx.c index c2d943cea8..ed7552d2e1 100644 --- a/src_features/signTx/cmd_signTx.c +++ b/src_features/signTx/cmd_signTx.c @@ -87,11 +87,10 @@ uint16_t handleSign(uint8_t p1, // We have encountered an error while trying to sign a SWAP type transaction // Return dedicated error code and flag an early exit back to Exchange G_swap_response_ready = true; - send_swap_error(ERROR_GENERIC, "Wrong mode", NULL); + send_swap_error(ERROR_GENERIC, APP_CODE_WRONG_SWAP_MODE, NULL, NULL); return APDU_NO_RESPONSE; - } else { - return APDU_RESPONSE_INVALID_DATA; } + return APDU_RESPONSE_INVALID_DATA; default: PRINTF("Unexpected parser status\n"); return APDU_RESPONSE_INVALID_DATA; diff --git a/src_features/signTx/feature_signTx.h b/src_features/signTx/feature_signTx.h index 223f0936b0..14478d15ab 100644 --- a/src_features/signTx/feature_signTx.h +++ b/src_features/signTx/feature_signTx.h @@ -12,6 +12,9 @@ #define ERROR_CROSSCHAIN_WRONG_METHOD 0x06 #define ERROR_GENERIC 0xFF +// App codes for detail. +typedef enum { APP_CODE_DEFAULT, APP_CODE_WRONG_SWAP_MODE, APP_CODE_NO_STANDARD_UI } app_code_t; + typedef enum { PLUGIN_UI_INSIDE = 0, @@ -24,6 +27,6 @@ uint16_t finalizeParsing(); void ux_approve_tx(bool fromPlugin); void start_signature_flow(void); -void send_swap_error(uint8_t error_code, const char *str1, const char *str2); +void send_swap_error(uint8_t error_code, app_code_t app_code, const char *str1, const char *str2); #endif // _SIGN_TX_H_ diff --git a/src_features/signTx/logic_signTx.c b/src_features/signTx/logic_signTx.c index 4498c36ed3..408b78e299 100644 --- a/src_features/signTx/logic_signTx.c +++ b/src_features/signTx/logic_signTx.c @@ -324,12 +324,12 @@ static int strcasecmp_workaround(const char *str1, const char *str2) { return 0; } -void send_swap_error(uint8_t error_code, const char *str1, const char *str2) { +void send_swap_error(uint8_t error_code, app_code_t app_code, const char *str1, const char *str2) { uint32_t tx = 0; PRINTF("APDU_RESPONSE_MODE_CHECK_FAILED: 0x%x\n", error_code); // Set RAPDU error codes G_io_apdu_buffer[tx++] = error_code; - G_io_apdu_buffer[tx++] = 0x00; + G_io_apdu_buffer[tx++] = app_code & 0xFF; // Set RAPDU error message if (str1 != NULL) { PRINTF("Expected %s\n", str1); @@ -486,13 +486,13 @@ __attribute__((noinline)) static uint16_t finalize_parsing_helper(void) { // User has just validated a swap but ETH received apdus about a non standard plugin / // contract if (!g_use_standard_ui) { - send_swap_error(ERROR_GENERIC, "No Standard UI", NULL); + send_swap_error(ERROR_GENERIC, APP_CODE_NO_STANDARD_UI, NULL, NULL); return APDU_NO_RESPONSE; } // Two success cases: we are in standard mode and no calldata was received // We are in crosschain mode and the correct calldata has been received if (G_swap_mode != SWAP_MODE_STANDARD && G_swap_mode != SWAP_MODE_CROSSCHAIN_SUCCESS) { - send_swap_error(ERROR_CROSSCHAIN_WRONG_MODE, "Wrong swap mode", NULL); + send_swap_error(ERROR_CROSSCHAIN_WRONG_MODE, APP_CODE_WRONG_SWAP_MODE, NULL, NULL); return APDU_NO_RESPONSE; } } @@ -519,7 +519,10 @@ __attribute__((noinline)) static uint16_t finalize_parsing_helper(void) { if (G_called_from_swap) { // Ensure the values are the same that the ones that have been previously validated if (strcasecmp_workaround(strings.common.toAddress, displayBuffer) != 0) { - send_swap_error(ERROR_WRONG_DESTINATION, strings.common.toAddress, displayBuffer); + send_swap_error(ERROR_WRONG_DESTINATION, + APP_CODE_DEFAULT, + strings.common.toAddress, + displayBuffer); return APDU_NO_RESPONSE; } } else { @@ -542,7 +545,10 @@ __attribute__((noinline)) static uint16_t finalize_parsing_helper(void) { if (G_called_from_swap) { // Ensure the values are the same that the ones that have been previously validated if (strcmp(strings.common.fullAmount, displayBuffer) != 0) { - send_swap_error(ERROR_WRONG_AMOUNT, strings.common.fullAmount, displayBuffer); + send_swap_error(ERROR_WRONG_AMOUNT, + APP_CODE_DEFAULT, + strings.common.fullAmount, + displayBuffer); return APDU_NO_RESPONSE; } } else { @@ -562,7 +568,10 @@ __attribute__((noinline)) static uint16_t finalize_parsing_helper(void) { if (G_called_from_swap) { // Ensure the values are the same that the ones that have been previously validated if (strcmp(strings.common.maxFee, displayBuffer) != 0) { - send_swap_error(ERROR_WRONG_FEES, strings.common.maxFee, displayBuffer); + send_swap_error(ERROR_WRONG_FEES, + APP_CODE_DEFAULT, + strings.common.maxFee, + displayBuffer); return APDU_NO_RESPONSE; } } else {