diff --git a/app/ui/view_internal.h b/app/ui/view_internal.h index e3f6f41..940cdc1 100644 --- a/app/ui/view_internal.h +++ b/app/ui/view_internal.h @@ -1,47 +1,48 @@ /******************************************************************************* -* (c) 2018 - 2022 Zondax AG -* (c) 2016 Ledger -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * (c) 2016 Ledger + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #pragma once -#include #include +#include + #include "coin.h" -#include "zxerror.h" #include "view.h" +#include "zxerror.h" -#define CUR_FLOW G_ux.flow_stack[G_ux.stack_count-1] +#define CUR_FLOW G_ux.flow_stack[G_ux.stack_count - 1] #if defined(TARGET_NANOX) || defined(TARGET_NANOS2) -#define MAX_CHARS_PER_KEY_LINE 64 -#define MAX_CHARS_PER_VALUE1_LINE 4096 -#define MAX_CHARS_HEXMESSAGE 160 -#elif defined(TARGET_STAX) +#define MAX_CHARS_PER_KEY_LINE 64 +#define MAX_CHARS_PER_VALUE1_LINE 4096 +#define MAX_CHARS_HEXMESSAGE 160 +#elif defined(TARGET_STAX) || defined(TARGET_FLEX) #include "nbgl_use_case.h" -#define MAX_LINES_PER_PAGE_REVIEW NB_MAX_LINES_IN_REVIEW -#define MAX_CHARS_PER_KEY_LINE 64 -#define MAX_CHARS_PER_VALUE1_LINE 180 -#define MAX_CHARS_HEXMESSAGE 160 +#define MAX_LINES_PER_PAGE_REVIEW NB_MAX_LINES_IN_REVIEW +#define MAX_CHARS_PER_KEY_LINE 64 +#define MAX_CHARS_PER_VALUE1_LINE 180 +#define MAX_CHARS_HEXMESSAGE 160 #else #ifndef MAX_CHARS_PER_VALUE_LINE -#define MAX_CHARS_PER_VALUE_LINE (17) +#define MAX_CHARS_PER_VALUE_LINE (17) #endif -#define MAX_CHARS_PER_KEY_LINE (MAX_CHARS_PER_VALUE_LINE+1) -#define MAX_CHARS_PER_VALUE1_LINE (2*MAX_CHARS_PER_VALUE_LINE+1) -#define MAX_CHARS_PER_VALUE2_LINE (MAX_CHARS_PER_VALUE_LINE+1) -#define MAX_CHARS_HEXMESSAGE 40 +#define MAX_CHARS_PER_KEY_LINE (MAX_CHARS_PER_VALUE_LINE + 1) +#define MAX_CHARS_PER_VALUE1_LINE (2 * MAX_CHARS_PER_VALUE_LINE + 1) +#define MAX_CHARS_PER_VALUE2_LINE (MAX_CHARS_PER_VALUE_LINE + 1) +#define MAX_CHARS_HEXMESSAGE 40 #endif // This takes data from G_io_apdu_buffer that is prefilled with the address @@ -53,18 +54,18 @@ #define SHORTCUT_VALUE "fields" #define SHORTCUT_STR "Skip fields" -//Review string can be customizable in each app +// Review string can be customizable in each app #if !defined(REVIEW_SCREEN_TITLE) && !defined(REVIEW_SCREEN_TX_VALUE) && !defined(REVIEW_SCREEN_ADDR_VALUE) - #define REVIEW_SCREEN_TITLE "Please" - #define REVIEW_SCREEN_TXN_VALUE "review" - #define REVIEW_SCREEN_ADDR_VALUE "review" +#define REVIEW_SCREEN_TITLE "Please" +#define REVIEW_SCREEN_TXN_VALUE "review" +#define REVIEW_SCREEN_ADDR_VALUE "review" #endif -static const char* review_key = REVIEW_SCREEN_TITLE; -static const char* review_txvalue = REVIEW_SCREEN_TXN_VALUE; -static const char* review_addrvalue = REVIEW_SCREEN_ADDR_VALUE; -static const char* review_keyconfig = "Review"; -static const char* review_configvalue = "configuration"; +static const char *review_key = REVIEW_SCREEN_TITLE; +static const char *review_txvalue = REVIEW_SCREEN_TXN_VALUE; +static const char *review_addrvalue = REVIEW_SCREEN_ADDR_VALUE; +static const char *review_keyconfig = "Review"; +static const char *review_configvalue = "configuration"; // Review msg string can be customizable in each app #if !defined(REVIEW_MSG_TITLE) && !defined(REVIEW_MSG_VALUE) @@ -75,26 +76,26 @@ static const char* review_configvalue = "configuration"; static const char *review_msgKey = REVIEW_MSG_TITLE; static const char *review_msgValue = REVIEW_MSG_VALUE; -static const char* shortcut_key = SHORTCUT_TITLE; -static const char* shortcut_value = SHORTCUT_VALUE; +static const char *shortcut_key = SHORTCUT_TITLE; +static const char *shortcut_value = SHORTCUT_VALUE; #if defined(TARGET_NANOS) - #if defined(REVIEW_SCREEN_ENABLED) && defined(SHORTCUT_MODE_ENABLED) - #define INTRO_PAGES 2 - #elif defined(REVIEW_SCREEN_ENABLED) || defined(SHORTCUT_MODE_ENABLED) - #define INTRO_PAGES 1 - #else - #define INTRO_PAGES 0 - #endif +#if defined(REVIEW_SCREEN_ENABLED) && defined(SHORTCUT_MODE_ENABLED) +#define INTRO_PAGES 2 +#elif defined(REVIEW_SCREEN_ENABLED) || defined(SHORTCUT_MODE_ENABLED) +#define INTRO_PAGES 1 +#else +#define INTRO_PAGES 0 +#endif #else - #define INTRO_PAGES 0 +#define INTRO_PAGES 0 #endif typedef struct { struct { -#if defined(TARGET_STAX) - char* key; - char* value; +#if defined(TARGET_STAX) || defined(TARGET_FLEX) + char *key; + char *value; char keys[NB_MAX_DISPLAYED_PAIRS_IN_REVIEW][MAX_CHARS_PER_KEY_LINE]; char values[NB_MAX_DISPLAYED_PAIRS_IN_REVIEW][MAX_CHARS_PER_VALUE1_LINE]; #else diff --git a/app/ui/view_stax.c b/app/ui/view_nbgl.c similarity index 67% rename from app/ui/view_stax.c rename to app/ui/view_nbgl.c index 6822744..293366b 100644 --- a/app/ui/view_stax.c +++ b/app/ui/view_nbgl.c @@ -1,30 +1,29 @@ /******************************************************************************* -* (c) 2018 - 2022 Zondax AG -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "bolos_target.h" -#if defined(TARGET_STAX) +#if defined(TARGET_STAX) || defined(TARGET_FLEX) -#include "view_internal.h" -#include "ux.h" -#include "app_mode.h" -#include "nbgl_use_case.h" #include "actions.h" - +#include "app_mode.h" #include "nbgl_page.h" +#include "nbgl_use_case.h" +#include "ux.h" +#include "view_internal.h" #ifdef APP_SECRET_MODE_ENABLED zxerr_t secret_enabled(); @@ -34,12 +33,13 @@ zxerr_t secret_enabled(); zxerr_t account_enabled(); #endif -#define APPROVE_LABEL_STAX "Sign transaction?" -#define REJECT_LABEL_STAX "Reject transaction" +#define APPROVE_LABEL_NBGL "Sign transaction?" +#define REJECT_LABEL_NBGL "Reject transaction" #define CANCEL_LABEL "Cancel" #define HOLD_TO_APPROVE_MSG "Hold to sign" -static const char HOME_TEXT[] = "This application enables\nsigning transactions on the\n" MENU_MAIN_APP_LINE1 " network"; +static const char HOME_TEXT[] = + "This application enables\nsigning transactions on the\n" MENU_MAIN_APP_LINE1 " network"; ux_state_t G_ux; bolos_ux_params_t G_ux_params; @@ -65,11 +65,10 @@ typedef enum { #endif } settings_list_e; - typedef enum { - EXPERT_MODE_TOKEN = FIRST_USER_TOKEN, - ACCOUNT_MODE_TOKEN, - SECRET_MODE_TOKEN, + EXPERT_MODE_TOKEN = FIRST_USER_TOKEN, + ACCOUNT_MODE_TOKEN, + SECRET_MODE_TOKEN, } config_token_e; void app_quit(void) { @@ -77,41 +76,37 @@ void app_quit(void) { os_sched_exit(-1); } -static void h_reject_internal(void) { - h_reject(review_type); -} +static void h_reject_internal(void) { h_reject(review_type); } -static void h_approve_internal(void) { - h_approve(review_type); -} +static void h_approve_internal(void) { h_approve(review_type); } -static void view_idle_show_impl_callback() { - view_idle_show_impl(0, NULL); -} +static void view_idle_show_impl_callback() { view_idle_show_impl(0, NULL); } -static const char* const INFO_KEYS[] = {"Version", "Developed by", "Website", "License"}; -static const char* const INFO_VALUES[] = {APPVERSION, "Zondax AG", "https://zondax.ch", "Apache 2.0"}; +#ifdef TARGET_STAX +#define MAX_INFO_LIST_ITEM_PER_PAGE 3 +#else // TARGET_FLEX +#define MAX_INFO_LIST_ITEM_PER_PAGE 2 +#endif -static const char* txn_choice_message = "Reject transaction?"; -static const char* add_choice_message = "Reject address?"; -static const char* ui_choice_message = "Reject configuration?"; +static const char *const INFO_KEYS_PAGE[] = {"Version", "Developed by", "Website", "License"}; +static const char *const INFO_VALUES_PAGE[] = {APPVERSION, "Zondax AG", "https://zondax.ch", "Apache 2.0"}; -static const char* txn_verified = "TRANSACTION\nSIGNED"; -static const char* txn_cancelled = "Transaction rejected"; +static const char *txn_choice_message = "Reject transaction?"; +static const char *add_choice_message = "Reject address?"; +static const char *ui_choice_message = "Reject configuration?"; -static const char* add_verified = "ADDRESS\nVERIFIED"; -static const char* add_cancelled = "Address verification\ncancelled"; +static const char *txn_verified = "TRANSACTION\nSIGNED"; +static const char *txn_cancelled = "Transaction rejected"; -static void h_expert_toggle() { - app_mode_set_expert(!app_mode_expert()); -} +static const char *add_verified = "ADDRESS\nVERIFIED"; +static const char *add_cancelled = "Address verification\ncancelled"; -static void confirm_error(__Z_UNUSED bool confirm) { - h_error_accept(0); -} +static void h_expert_toggle() { app_mode_set_expert(!app_mode_expert()); } + +static void confirm_error(__Z_UNUSED bool confirm) { h_error_accept(0); } static void confirm_callback(bool confirm) { - const char* message = NULL; + const char *message = NULL; switch (review_type) { case REVIEW_ADDRESS: message = confirm ? add_verified : add_cancelled; @@ -141,7 +136,7 @@ static void action_callback(bool confirm) { return; } - const char* message = NULL; + const char *message = NULL; switch (review_type) { case REVIEW_UI: message = ui_choice_message; @@ -161,16 +156,10 @@ static void action_callback(bool confirm) { return; } - nbgl_useCaseConfirm(message, - NULL, - "Yes, reject", - "Go back", - cancel); + nbgl_useCaseConfirm(message, NULL, "Yes, reject", "Go back", cancel); } -static void check_cancel(void) { - action_callback(false); -} +static void check_cancel(void) { action_callback(false); } static void confirm_setting(bool confirm) { if (confirm && viewdata.viewfuncAccept != NULL) { @@ -198,11 +187,11 @@ void view_custom_error_show(const char *upper, const char *lower) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", upper); snprintf(viewdata.value, MAX_CHARS_PER_VALUE1_LINE, "%s", lower); - nbgl_useCaseChoice(&C_round_warning_64px, viewdata.key, viewdata.value, "Ok", "", confirm_error); + nbgl_useCaseChoice(&C_Important_Circle_64px, viewdata.key, viewdata.value, "Ok", "", confirm_error); } void view_error_show_impl() { - nbgl_useCaseChoice(&C_round_warning_64px, viewdata.key, viewdata.value, "Ok", NULL, confirm_setting); + nbgl_useCaseChoice(&C_Important_Circle_64px, viewdata.key, viewdata.value, "Ok", NULL, confirm_setting); } static uint8_t get_pair_number() { @@ -210,11 +199,8 @@ static uint8_t get_pair_number() { uint8_t numPairs = 0; viewdata.viewfuncGetNumItems(&numItems); for (uint8_t i = 0; i < numItems; i++) { - viewdata.viewfuncGetItem( - i, - viewdata.key, MAX_CHARS_PER_KEY_LINE, - viewdata.value, MAX_CHARS_PER_VALUE1_LINE, - 0, &viewdata.pageCount); + viewdata.viewfuncGetItem(i, viewdata.key, MAX_CHARS_PER_KEY_LINE, viewdata.value, MAX_CHARS_PER_VALUE1_LINE, 0, + &viewdata.pageCount); numPairs += viewdata.pageCount; } return numPairs; @@ -243,11 +229,8 @@ zxerr_t h_review_update_data() { uint8_t accPages = 0; for (uint8_t i = 0; i < viewdata.itemCount; i++) { - CHECK_ZXERR(viewdata.viewfuncGetItem( - i, - viewdata.key, MAX_CHARS_PER_KEY_LINE, - viewdata.value, MAX_CHARS_PER_VALUE1_LINE, - 0, &viewdata.pageCount)) + CHECK_ZXERR(viewdata.viewfuncGetItem(i, viewdata.key, MAX_CHARS_PER_KEY_LINE, viewdata.value, + MAX_CHARS_PER_VALUE1_LINE, 0, &viewdata.pageCount)) if (viewdata.pageCount == 0) { ZEMU_LOGF(50, "pageCount is 0!") return zxerr_no_data; @@ -255,14 +238,12 @@ zxerr_t h_review_update_data() { if (accPages + viewdata.pageCount > viewdata.itemIdx) { const uint8_t innerIdx = viewdata.itemIdx - accPages; - CHECK_ZXERR(viewdata.viewfuncGetItem( - i, - viewdata.key, MAX_CHARS_PER_KEY_LINE, - viewdata.value, MAX_CHARS_PER_VALUE1_LINE, - innerIdx, &viewdata.pageCount)) + CHECK_ZXERR(viewdata.viewfuncGetItem(i, viewdata.key, MAX_CHARS_PER_KEY_LINE, viewdata.value, + MAX_CHARS_PER_VALUE1_LINE, innerIdx, &viewdata.pageCount)) if (viewdata.pageCount > 1) { const uint8_t titleLen = strnlen(viewdata.key, MAX_CHARS_PER_KEY_LINE); - snprintf(viewdata.key + titleLen, MAX_CHARS_PER_KEY_LINE - titleLen, " (%d/%d)", innerIdx + 1, viewdata.pageCount); + snprintf(viewdata.key + titleLen, MAX_CHARS_PER_KEY_LINE - titleLen, " (%d/%d)", innerIdx + 1, + viewdata.pageCount); } return zxerr_ok; } @@ -274,7 +255,7 @@ zxerr_t h_review_update_data() { void h_review_update() { zxerr_t err = h_review_update_data(); - switch(err) { + switch (err) { case zxerr_ok: case zxerr_no_data: break; @@ -285,18 +266,28 @@ void h_review_update() { } } -static bool settings_screen_callback(uint8_t page, nbgl_pageContent_t* content) { - switch (page) - { +static bool settings_screen_callback(uint8_t page, nbgl_pageContent_t *content) { + const uint16_t infoElements = sizeof(INFO_KEYS_PAGE) / sizeof(INFO_KEYS_PAGE[0]); + switch (page) { + // Info page 0 case 0: { content->type = INFOS_LIST; - content->infosList.nbInfos = sizeof(INFO_KEYS)/sizeof(INFO_KEYS[0]); - content->infosList.infoContents = INFO_VALUES; - content->infosList.infoTypes = INFO_KEYS; + content->infosList.nbInfos = MAX_INFO_LIST_ITEM_PER_PAGE; + content->infosList.infoContents = INFO_VALUES_PAGE; + content->infosList.infoTypes = INFO_KEYS_PAGE; break; } + // Info page 1 case 1: { + content->type = INFOS_LIST; + content->infosList.nbInfos = infoElements - MAX_INFO_LIST_ITEM_PER_PAGE; + content->infosList.infoContents = &INFO_VALUES_PAGE[MAX_INFO_LIST_ITEM_PER_PAGE]; + content->infosList.infoTypes = &INFO_KEYS_PAGE[MAX_INFO_LIST_ITEM_PER_PAGE]; + break; + } + + case 2: { // Config content->type = SWITCHES_LIST; content->switchesList.nbSwitches = 1; @@ -362,18 +353,18 @@ static void settings_toggle_callback(int token, __Z_UNUSED uint8_t index) { } void setting_screen() { - //Set return button top-left (true) botton-left (false) + // Set return button top-left (true) botton-left (false) const bool return_button_top_left = false; const uint8_t init_page = 0; - const uint8_t settings_pages = 2; + const uint8_t settings_pages = 3; nbgl_useCaseSettings(MENU_MAIN_APP_LINE1, init_page, settings_pages, return_button_top_left, - view_idle_show_impl_callback, settings_screen_callback, settings_toggle_callback); + view_idle_show_impl_callback, settings_screen_callback, settings_toggle_callback); } void view_idle_show_impl(__Z_UNUSED uint8_t item_idx, const char *statusString) { viewdata.key = viewdata.keys[0]; const char *home_text = HOME_TEXT; - if (statusString == NULL ) { + if (statusString == NULL) { #ifdef APP_SECRET_MODE_ENABLED if (app_mode_secret()) { snprintf(viewdata.key, MAX_CHARS_PER_KEY_LINE, "%s", MENU_MAIN_APP_LINE2_SECRET); @@ -412,15 +403,14 @@ static void review_configuration() { view_error_show(); } - nbgl_useCaseChoice(&C_round_warning_64px, viewdata.key, viewdata.value, "Accept", "Reject", confirm_setting); + nbgl_useCaseChoice(&C_Important_Circle_64px, viewdata.key, viewdata.value, "Accept", "Reject", confirm_setting); } static void review_address() { - nbgl_layoutTagValueList_t* extraPagesPtr = NULL; + nbgl_layoutTagValueList_t *extraPagesPtr = NULL; uint8_t numItems = 0; - if (viewdata.viewfuncGetNumItems == NULL || - viewdata.viewfuncGetNumItems(&numItems) != zxerr_ok || + if (viewdata.viewfuncGetNumItems == NULL || viewdata.viewfuncGetNumItems(&numItems) != zxerr_ok || numItems > NB_MAX_DISPLAYED_PAIRS_IN_REVIEW) { ZEMU_LOGF(50, "Show address error\n") view_error_show(); @@ -449,7 +439,7 @@ static void review_address() { nbgl_useCaseAddressConfirmationExt(viewdata.value, action_callback, extraPagesPtr); } -static nbgl_layoutTagValue_t* update_item_callback(uint8_t index) { +static nbgl_layoutTagValue_t *update_item_callback(uint8_t index) { uint8_t internalIndex = index % NB_MAX_DISPLAYED_PAIRS_IN_REVIEW; viewdata.itemIdx = index; @@ -470,29 +460,28 @@ static void review_transaction_static() { } infoLongPress.icon = &C_icon_stax_64; - infoLongPress.text = APPROVE_LABEL_STAX; + infoLongPress.text = APPROVE_LABEL_NBGL; infoLongPress.longPressText = HOLD_TO_APPROVE_MSG; pairList.nbMaxLinesForValue = NB_MAX_LINES_IN_REVIEW; pairList.nbPairs = get_pair_number(); - pairList.pairs = NULL; // to indicate that callback should be used + pairList.pairs = NULL; // to indicate that callback should be used pairList.callback = update_item_callback; pairList.startIndex = 0; - nbgl_useCaseStaticReview(&pairList, &infoLongPress, REJECT_LABEL_STAX, action_callback); + nbgl_useCaseStaticReview(&pairList, &infoLongPress, REJECT_LABEL_NBGL, action_callback); } -void view_review_show_impl(unsigned int requireReply){ - review_type = (review_type_e) requireReply; +void view_review_show_impl(unsigned int requireReply) { + review_type = (review_type_e)requireReply; // Retrieve intro text for transaction txn_intro_message = NULL; viewdata.key = viewdata.keys[0]; viewdata.value = viewdata.values[0]; if (viewdata.viewfuncGetItem != NULL) { - const zxerr_t err = viewdata.viewfuncGetItem(0xFF, viewdata.key, MAX_CHARS_PER_KEY_LINE, - viewdata.value, MAX_CHARS_PER_VALUE1_LINE, - 0, &viewdata.pageCount); + const zxerr_t err = viewdata.viewfuncGetItem(0xFF, viewdata.key, MAX_CHARS_PER_KEY_LINE, viewdata.value, + MAX_CHARS_PER_VALUE1_LINE, 0, &viewdata.pageCount); if (err == zxerr_ok) { txn_intro_message = viewdata.value; } @@ -501,35 +490,23 @@ void view_review_show_impl(unsigned int requireReply){ switch (review_type) { case REVIEW_UI: - nbgl_useCaseReviewStart(&C_icon_stax_64, - "Review configuration", - NULL, - CANCEL_LABEL, - review_configuration, + nbgl_useCaseReviewStart(&C_icon_stax_64, "Review configuration", NULL, CANCEL_LABEL, review_configuration, cancel); break; case REVIEW_ADDRESS: { - #if defined(CUSTOM_ADDRESS_TEXT) - const char ADDRESS_TEXT[] = CUSTOM_ADDRESS_TEXT; - #else - const char ADDRESS_TEXT[] = "Verify " MENU_MAIN_APP_LINE1 "\naddress"; - #endif - nbgl_useCaseReviewStart(&C_icon_stax_64, - ADDRESS_TEXT, - NULL, - CANCEL_LABEL, - review_address, - cancel); +#if defined(CUSTOM_ADDRESS_TEXT) + const char ADDRESS_TEXT[] = CUSTOM_ADDRESS_TEXT; +#else + const char ADDRESS_TEXT[] = "Verify " MENU_MAIN_APP_LINE1 "\naddress"; +#endif + nbgl_useCaseReviewStart(&C_icon_stax_64, ADDRESS_TEXT, NULL, CANCEL_LABEL, review_address, cancel); break; } case REVIEW_TXN: default: nbgl_useCaseReviewStart(&C_icon_stax_64, - (txn_intro_message == NULL ? "Review transaction" : txn_intro_message), - NULL, - REJECT_LABEL_STAX, - review_transaction_static, - check_cancel); + (txn_intro_message == NULL ? "Review transaction" : txn_intro_message), NULL, + REJECT_LABEL_NBGL, review_transaction_static, check_cancel); } } diff --git a/dockerized_build.mk b/dockerized_build.mk index 8ffb165..4c94406 100644 --- a/dockerized_build.mk +++ b/dockerized_build.mk @@ -28,11 +28,13 @@ DOCKER_BOLOS_SDKS = NANOS_SDK DOCKER_BOLOS_SDKX = NANOX_SDK DOCKER_BOLOS_SDKS2 = NANOSP_SDK DOCKER_BOLOS_SDKST = STAX_SDK +DOCKER_BOLOS_SDKFL = FLEX_SDK TARGET_S = nanos TARGET_X = nanox TARGET_S2 = nanos2 TARGET_ST = stax +TARGET_FL = flex # Note: This is not an SSH key, and being public represents no risk SCP_PUBKEY=049bc79d139c70c83a4b19e8922e5ee3e0080bb14a2e8b0752aa42cda90a1463f689b0fa68c1c0246845c2074787b649d0d8a6c0b97d4607065eee3057bdf16b83 @@ -47,7 +49,7 @@ $(info TESTS_ZEMU_DIR : $(TESTS_ZEMU_DIR)) $(info TESTS_JS_DIR : $(TESTS_JS_DIR)) $(info TESTS_JS_PACKAGE : $(TESTS_JS_PACKAGE)) -DOCKER_IMAGE_ZONDAX=zondax/ledger-app-builder:ledger-b72eadb7412689490aad1433cb0e913533d00e34 +DOCKER_IMAGE_ZONDAX=zondax/ledger-app-builder:ledger-ec93499de7f17076ee90caaca5953fdb9d3daf6c DOCKER_IMAGE_LEDGER=ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest ifdef INTERACTIVE @@ -94,9 +96,8 @@ all: @$(MAKE) buildS @$(MAKE) buildX @$(MAKE) buildS2 -ifeq ($(ZXLIB_COMPILE_STAX),1) @$(MAKE) buildST -endif # ZXLIB_COMPILE_STAX + @$(MAKE) buildFL .PHONY: check_python check_python: @@ -132,6 +133,10 @@ build_rustS2: build_rustST: $(call run_docker,$(DOCKER_BOLOS_SDKST),$(TARGET_ST),make -j $(NPROC) rust) +.PHONY: build_rustFL +build_rustFL: + $(call run_docker,$(DOCKER_BOLOS_SDKFL),$(TARGET_FL),make -j $(NPROC) rust) + .PHONY: convert_icon convert_icon: @convert $(LEDGER_SRC)/tmp.gif -monochrome -size 16x16 -depth 1 $(LEDGER_SRC)/nanos_icon.gif @@ -153,6 +158,10 @@ buildS2: buildST: $(call run_docker,$(DOCKER_BOLOS_SDKST),$(TARGET_ST),make -j $(NPROC)) +.PHONY: buildFL +buildFL: + $(call run_docker,$(DOCKER_BOLOS_SDKFL),$(TARGET_FL),make -j $(NPROC)) + .PHONY: clean_output clean_output: @echo "Removing output files" @@ -181,6 +190,14 @@ shellX: shellS2: $(call run_docker,$(DOCKER_BOLOS_SDKS2) -t,$(TARGET_S2),bash) +.PHONY: shellST +shellST: + $(call run_docker,$(DOCKER_BOLOS_SDKST) -t,$(TARGET_ST),bash) + +.PHONY: shellFL +shellFL: + $(call run_docker,$(DOCKER_BOLOS_SDKFL) -t,$(TARGET_FL),bash) + .PHONY: loadS loadS: ${LEDGER_SRC}/pkg/installer_s.sh load @@ -205,6 +222,14 @@ loadST: deleteST: ${LEDGER_SRC}/pkg/installer_stax.sh delete +.PHONY: loadFL +loadFL: + ${LEDGER_SRC}/pkg/installer_flex.sh load + +.PHONY: deleteFL +deleteFL: + ${LEDGER_SRC}/pkg/installer_flex.sh delete + .PHONY: sizeS sizeS: $(CURDIR)/deps/ledger-zxlib/scripts/getSize.py nanos @@ -221,6 +246,10 @@ sizeX: sizeST: $(CURDIR)/deps/ledger-zxlib/scripts/getSize.py stax +.PHONY: sizeFL +sizeFL: + $(CURDIR)/deps/ledger-zxlib/scripts/getSize.py flex + .PHONY: show_info_recovery_mode show_info_recovery_mode: @echo "This command requires a Ledger Nano S in recovery mode. To go into recovery mode, follow:" @@ -259,6 +288,26 @@ dev_caS2: check_python dev_ca_deleteS2: check_python @python -m ledgerblue.resetCustomCA --targetId 0x33100004 +# TODO: verify that targetId is correct and if it works on a real device +# This target will setup a custom developer certificate +.PHONY: dev_caST +dev_caST: check_python + @python -m ledgerblue.setupCustomCA --targetId 0x33200004 --public $(SCP_PUBKEY) --name zondax + +.PHONY: dev_ca_deleteST +dev_ca_deleteST: check_python + @python -m ledgerblue.resetCustomCA --targetId 0x33200004 + +# TODO: complete with Flex targetId +# This target will setup a custom developer certificate +.PHONY: dev_caFL +dev_caFL: check_python + @python -m ledgerblue.setupCustomCA --targetId 0x33200004 --public $(SCP_PUBKEY) --name zondax + +.PHONY: dev_ca_deleteFL +dev_ca_deleteFL: check_python + @python -m ledgerblue.resetCustomCA --targetId 0x33200004 + .PHONY: zemu_install_js_link ifeq ($(TESTS_JS_DIR),) zemu_install_js_link: diff --git a/include/zxmacros.h b/include/zxmacros.h index 6abe80e..6fbc0e0 100644 --- a/include/zxmacros.h +++ b/include/zxmacros.h @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #pragma once #ifdef __cplusplus @@ -28,17 +28,18 @@ extern "C" { #include #include #include + #include "string.h" #ifndef __APPLE__ -extern void explicit_bzero(void *s, size_t n) __THROW __nonnull ((1)); +extern void explicit_bzero(void *s, size_t n) __THROW __nonnull((1)); #endif #define __Z_INLINE inline __attribute__((always_inline)) static #define __Z_UNUSED __attribute__((unused)) -#define NV_ALIGN __attribute__ ((aligned(64))) +#define NV_ALIGN __attribute__((aligned(64))) #ifndef UNUSED #define UNUSED(x) (void)x @@ -48,7 +49,8 @@ extern void explicit_bzero(void *s, size_t n) __THROW __nonnull ((1)); #include "bolos_target.h" #endif -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ + defined(TARGET_FLEX) #include "zxmacros_ledger.h" #else @@ -57,22 +59,24 @@ extern void explicit_bzero(void *s, size_t n) __THROW __nonnull ((1)); #endif #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ -#define ZX_SWAP(v) (((v) & 0x000000FFu) << 24u | ((v) & 0x0000FF00u) << 8u | ((v) & 0x00FF0000u) >> 8u | ((v) & 0xFF000000u) >> 24u) -#define HtoNL(v) ZX_SWAP( v ) -#define NtoHL(v) ZX_SWAP( v ) +#define ZX_SWAP(v) \ + (((v) & 0x000000FFu) << 24u | ((v) & 0x0000FF00u) << 8u | ((v) & 0x00FF0000u) >> 8u | ((v) & 0xFF000000u) >> 24u) +#define HtoNL(v) ZX_SWAP(v) +#define NtoHL(v) ZX_SWAP(v) #else #define HtoNL(x) (x) #define NtoHL(x) (x) #endif -#define SET_NV(DST, TYPE, VAL) { \ - TYPE nvset_tmp=(VAL); \ - MEMCPY_NV((void*) PIC(DST), (void *) PIC(&nvset_tmp), sizeof(TYPE)); \ -} +#define SET_NV(DST, TYPE, VAL) \ + { \ + TYPE nvset_tmp = (VAL); \ + MEMCPY_NV((void *)PIC(DST), (void *)PIC(&nvset_tmp), sizeof(TYPE)); \ + } __Z_INLINE void strncpy_s(char *dst, const char *src, size_t dstSize) { MEMZERO(dst, dstSize); - if(dstSize > 0) { + if (dstSize > 0) { strncpy(dst, src, dstSize - 1); } } @@ -82,7 +86,7 @@ __Z_INLINE void strncpy_s(char *dst, const char *src, size_t dstSize) { void zemu_trace(const char *file, uint32_t line); -#define ZEMU_TRACE() zemu_trace( __func__, __LINE__ ); +#define ZEMU_TRACE() zemu_trace(__func__, __LINE__); __attribute__((unused)) void check_app_canary(); @@ -90,39 +94,41 @@ void handle_stack_overflow(); void zemu_log_stack(const char *ctx); -#define CHECK_PIN_VALIDATED() \ -if( os_global_pin_is_validated() != BOLOS_UX_OK ) { \ - THROW(APDU_CODE_COMMAND_NOT_ALLOWED); \ -} +#define CHECK_PIN_VALIDATED() \ + if (os_global_pin_is_validated() != BOLOS_UX_OK) { \ + THROW(APDU_CODE_COMMAND_NOT_ALLOWED); \ + } -#if (defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)) +#if (defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)) || \ + defined(TARGET_FLEX) #if defined(ZEMU_LOGGING) -__Z_INLINE void zemu_log(const char *buf) -{ - asm volatile ( - "movs r0, #0x04\n" - "movs r1, %0\n" - "svc 0xab\n" - :: "r"(buf) : "r0", "r1" - ); +__Z_INLINE void zemu_log(const char *buf) { + asm volatile( + "movs r0, #0x04\n" + "movs r1, %0\n" + "svc 0xab\n" ::"r"(buf) + : "r0", "r1"); } #else __Z_INLINE void zemu_log(__Z_UNUSED const char *_) {} #endif #else -__Z_INLINE void zemu_log(__Z_UNUSED const char *msg) { - printf("%s\n", msg); -} +__Z_INLINE void zemu_log(__Z_UNUSED const char *msg) { printf("%s\n", msg); } #endif #if defined(APP_TESTING) -#define ZEMU_LOGF(SIZE, ...) { char tmp[(SIZE)]; snprintf(tmp, (SIZE), __VA_ARGS__); zemu_log(tmp); } +#define ZEMU_LOGF(SIZE, ...) \ + { \ + char tmp[(SIZE)]; \ + snprintf(tmp, (SIZE), __VA_ARGS__); \ + zemu_log(tmp); \ + } #else -#define ZEMU_LOGF(SIZE, ...) {} +#define ZEMU_LOGF(SIZE, ...) \ + {} #endif #ifdef __cplusplus } #pragma clang diagnostic pop #endif - diff --git a/include/zxmacros_ledger.h b/include/zxmacros_ledger.h index 404fe7b..0bead54 100644 --- a/include/zxmacros_ledger.h +++ b/include/zxmacros_ledger.h @@ -1,24 +1,25 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #pragma once -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ + defined(TARGET_FLEX) -#include "os.h" #include "cx.h" +#include "os.h" #include "os_io_seproxyhal.h" #include "ux.h" #include "zxerror.h" @@ -34,10 +35,8 @@ #define MEMZERO explicit_bzero #define IS_UX_ALLOWED (G_ux_params.len != BOLOS_UX_IGNORE && G_ux_params.len != BOLOS_UX_CONTINUE) -#if defined(TARGET_NANOX) || defined(TARGET_NANOS2) -#define NV_CONST const -#define NV_VOLATILE volatile -#elif defined(TARGET_NANOS) + +#if defined(TARGET_NANOS) #define NV_CONST #define NV_VOLATILE #else @@ -52,39 +51,42 @@ extern unsigned int app_stack_canary; #define WAIT_EVENT() io_seproxyhal_spi_recv(G_io_seproxyhal_spi_buffer, sizeof(G_io_seproxyhal_spi_buffer), 0) #if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) -#define UX_WAIT() \ - while (!UX_DISPLAYED()) { WAIT_EVENT(); UX_DISPLAY_NEXT_ELEMENT(); } \ - WAIT_EVENT(); \ +#define UX_WAIT() \ + while (!UX_DISPLAYED()) { \ + WAIT_EVENT(); \ + UX_DISPLAY_NEXT_ELEMENT(); \ + } \ + WAIT_EVENT(); \ io_seproxyhal_general_status(); \ WAIT_EVENT() #else -#define UX_WAIT(){} +#define UX_WAIT() \ + {} #endif // Macros for handling no-throw methods error check -#define CHECK_CXERROR(CALL) \ - do { \ - cx_err_t __cx_err = CALL; \ - if (__cx_err != CX_OK) { \ - return __cx_err; \ - } \ - } while (0) - +#define CHECK_CXERROR(CALL) \ + do { \ + cx_err_t __cx_err = CALL; \ + if (__cx_err != CX_OK) { \ + return __cx_err; \ + } \ + } while (0) -#define CATCH_CXERROR(CALL) \ - do { \ - cx_err_t __cx_err = CALL; \ - if (__cx_err != CX_OK) { \ - goto catch_cx_error; \ - } \ - } while (0) +#define CATCH_CXERROR(CALL) \ + do { \ + cx_err_t __cx_err = CALL; \ + if (__cx_err != CX_OK) { \ + goto catch_cx_error; \ + } \ + } while (0) -#define CHECK_CX_OK(CALL) \ - do { \ - cx_err_t __cx_err = CALL; \ - if (__cx_err != CX_OK) { \ - return zxerr_unknown; \ - } \ - } while (0) +#define CHECK_CX_OK(CALL) \ + do { \ + cx_err_t __cx_err = CALL; \ + if (__cx_err != CX_OK) { \ + return zxerr_unknown; \ + } \ + } while (0) #endif diff --git a/include/zxmacros_x64.h b/include/zxmacros_x64.h index c3bb918..2bfa65d 100644 --- a/include/zxmacros_x64.h +++ b/include/zxmacros_x64.h @@ -1,21 +1,22 @@ /******************************************************************************* -* (c) 2018 - 2023 Zondax AG -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #pragma once -#if !defined (TARGET_NANOS) && !defined(TARGET_NANOX) && !defined(TARGET_NANOS2) && !defined(TARGET_STAX) +#if !defined(TARGET_NANOS) && !defined(TARGET_NANOX) && !defined(TARGET_NANOS2) && !defined(TARGET_STAX) && \ + !defined(TARGET_FLEX) // This macros are kept for backwards compatibility // the most recent SDK has unified implementations and deprecated the original os_*** @@ -27,7 +28,8 @@ #define CX_OK 0 #define PIC(x) (x) -#define CHECK_APP_CANARY() {} +#define CHECK_APP_CANARY() \ + {} #define CX_ECCINFO_PARITY_ODD 1u #define CX_ECCINFO_xGTn 2u diff --git a/include/zxversion.h b/include/zxversion.h index 3c39189..97f3021 100644 --- a/include/zxversion.h +++ b/include/zxversion.h @@ -15,6 +15,6 @@ ********************************************************************************/ #pragma once -#define ZXLIB_MAJOR 27 +#define ZXLIB_MAJOR 28 #define ZXLIB_MINOR 0 #define ZXLIB_PATCH 0 diff --git a/makefiles/Makefile.devices b/makefiles/Makefile.devices index cead77c..cd4ec7a 100644 --- a/makefiles/Makefile.devices +++ b/makefiles/Makefile.devices @@ -69,3 +69,14 @@ OUTPUT_ELF ?= $(CURDIR)/output/$(ELF_NAME)_stax.elf OUTPUT_INSTALLER:= $(CURDIR)/pkg/$(INSTALLER_NAME)_stax.sh endif ####################################### +ifeq ($(TARGET_NAME),TARGET_FLEX) +ifeq ($(HAVE_SWAP),1) +APP_LOAD_PARAMS += --appFlags 0xA00 +else +APP_LOAD_PARAMS += --appFlags 0x200 +endif +ICONNAME:=$(CURDIR)/flex_$(ICON_NAME).gif +OUTPUT_ELF ?= $(CURDIR)/output/$(ELF_NAME)_flex.elf +OUTPUT_INSTALLER:= $(CURDIR)/pkg/$(INSTALLER_NAME)_flex.sh +endif +####################################### diff --git a/makefiles/Makefile.platform b/makefiles/Makefile.platform index 3cb5a7b..1f497a6 100644 --- a/makefiles/Makefile.platform +++ b/makefiles/Makefile.platform @@ -1,6 +1,6 @@ #******************************************************************************* # Ledger App -# (c) 2018 - 2023 Zondax AG +# (c) 2018 - 2024 Zondax AG # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -39,8 +39,8 @@ ifeq ($(TARGET_NAME),TARGET_NANOS) # Nano S DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=128 DEFINES += HAVE_BAGL -else ifeq ($(TARGET_NAME),TARGET_STAX) -# Stax +else ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX)) +# Stax and Flex DEFINES += IO_SEPROXYHAL_BUFFER_SIZE_B=300 DEFINES += NBGL_QRCODE SDK_SOURCE_PATH += qrcode @@ -60,7 +60,7 @@ DEFINES += HAVE_BAGL_FONT_OPEN_SANS_LIGHT_16PX DEFINES += HAVE_UX_FLOW endif -BLE_TARGETS := TARGET_STAX TARGET_NANOX +BLE_TARGETS := TARGET_STAX TARGET_NANOX TARGET_FLEX ifeq ($(TARGET_NAME),$(filter $(TARGET_NAME), $(BLE_TARGETS))) # X/Stax specific DEFINES += HAVE_BLE @@ -113,6 +113,6 @@ APP_SOURCE_PATH += $(ZXLIB_DIR)/app/ui SDK_SOURCE_PATH += lib_stusb lib_stusb_impl -ifneq ($(TARGET_NAME),TARGET_STAX) +ifneq ($(TARGET_NAME),$(filter $(TARGET_NAME),TARGET_STAX TARGET_FLEX)) SDK_SOURCE_PATH += lib_ux endif diff --git a/src/app_mode.c b/src/app_mode.c index 365c75f..6094f6b 100644 --- a/src/app_mode.c +++ b/src/app_mode.c @@ -1,18 +1,18 @@ /******************************************************************************* -* (c) 2020 Zondax GmbH -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "app_mode.h" @@ -28,39 +28,36 @@ typedef struct { app_mode_temporary_t app_mode_temporary; -#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ + defined(TARGET_FLEX) ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// -app_mode_persistent_t NV_CONST N_appmode_impl __attribute__ ((aligned(64))); +app_mode_persistent_t NV_CONST N_appmode_impl __attribute__((aligned(64))); #define N_appmode (*(NV_VOLATILE app_mode_persistent_t *)PIC(&N_appmode_impl)) -void app_mode_reset(){ +void app_mode_reset() { app_mode_temporary.secret = 0; app_mode_temporary.shortcut = 0; } -bool app_mode_expert() { - return N_appmode.expert; -} +bool app_mode_expert() { return N_appmode.expert; } -bool app_mode_account() { - return N_appmode.account; -} +bool app_mode_account() { return N_appmode.account; } void app_mode_set_expert(uint8_t val) { app_mode_persistent_t mode; mode.expert = val; mode.account = N_appmode.account; - MEMCPY_NV( (void*) PIC(&N_appmode_impl), (void*) &mode, sizeof(app_mode_persistent_t)); + MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t)); } void app_mode_set_account(uint8_t val) { app_mode_persistent_t mode; mode.expert = N_appmode.expert; mode.account = val; - MEMCPY_NV( (void*) PIC(&N_appmode_impl), (void*) &mode, sizeof(app_mode_persistent_t)); + MEMCPY_NV((void *)PIC(&N_appmode_impl), (void *)&mode, sizeof(app_mode_persistent_t)); } #else @@ -78,21 +75,13 @@ void app_mode_reset() { app_mode_temporary.shortcut = 0; } -bool app_mode_expert() { - return app_mode.expert; -} +bool app_mode_expert() { return app_mode.expert; } -bool app_mode_account() { - return app_mode.account; -} +bool app_mode_account() { return app_mode.account; } -void app_mode_set_expert(uint8_t val) { - app_mode.expert = val; -} +void app_mode_set_expert(uint8_t val) { app_mode.expert = val; } -void app_mode_set_account(uint8_t val) { - app_mode.account = val; -} +void app_mode_set_account(uint8_t val) { app_mode.account = val; } ////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////// @@ -101,18 +90,10 @@ void app_mode_set_account(uint8_t val) { #endif -bool app_mode_secret() { - return app_mode_temporary.secret; -} +bool app_mode_secret() { return app_mode_temporary.secret; } -void app_mode_set_secret(uint8_t val) { - app_mode_temporary.secret = val; -} +void app_mode_set_secret(uint8_t val) { app_mode_temporary.secret = val; } -bool app_mode_shortcut() { - return app_mode_temporary.shortcut; -} +bool app_mode_shortcut() { return app_mode_temporary.shortcut; } -void app_mode_set_shortcut(uint8_t val) { - app_mode_temporary.shortcut = val; -} +void app_mode_set_shortcut(uint8_t val) { app_mode_temporary.shortcut = val; } diff --git a/src/zxmacros.c b/src/zxmacros.c index 443fcbe..a8ae69f 100644 --- a/src/zxmacros.c +++ b/src/zxmacros.c @@ -1,19 +1,20 @@ /******************************************************************************* -* (c) 2018 Zondax GmbH -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -********************************************************************************/ + * (c) 2018 - 2024 Zondax AG + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ********************************************************************************/ #include "zxmacros.h" + #include "zxcanary.h" #ifdef __cplusplus @@ -23,7 +24,8 @@ void handle_stack_overflow() { zemu_log("!!!!!!!!!!!!!!!!!!!!!! CANARY TRIGGERED!!! STACK OVERFLOW DETECTED\n"); -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ + defined(TARGET_FLEX) io_seproxyhal_se_reset(); #else while (1); @@ -35,31 +37,31 @@ void handle_stack_overflow() { #endif __Z_UNUSED void check_app_canary() { -#if defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) +#if defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX) || \ + defined(TARGET_FLEX) if (app_stack_canary != APP_STACK_CANARY_MAGIC) handle_stack_overflow(); check_zondax_canary(); #endif } -#if defined(ZEMU_LOGGING) && (defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)) +#if defined(ZEMU_LOGGING) && (defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ + defined(TARGET_STAX) || defined(TARGET_FLEX)) void zemu_log_stack(const char *ctx) { - #define STACK_SHIFT 20 - void* p = NULL; +#define STACK_SHIFT 20 + void *p = NULL; char buf[70]; #if defined(HAVE_ZONDAX_CANARY) // When Zondax canary is enabled, we add a random canary just above `APP_STACK_CANARY_MAGIC 0xDEAD0031` - const uint32_t availableStack = ((uint32_t)((void*)&p)+STACK_SHIFT - (uint32_t)&app_stack_canary) - sizeof(uint32_t); + const uint32_t availableStack = + ((uint32_t)((void *)&p) + STACK_SHIFT - (uint32_t)&app_stack_canary) - sizeof(uint32_t); #else - const uint32_t availableStack = (uint32_t)((void*)&p)+STACK_SHIFT - (uint32_t)&app_stack_canary; + const uint32_t availableStack = (uint32_t)((void *)&p) + STACK_SHIFT - (uint32_t)&app_stack_canary; #endif - snprintf(buf, sizeof(buf), "|SP| %p %p (%d) : %s\n", - &app_stack_canary, - ((void*)&p)+STACK_SHIFT, - availableStack, - ctx); + snprintf(buf, sizeof(buf), "|SP| %p %p (%d) : %s\n", &app_stack_canary, ((void *)&p) + STACK_SHIFT, availableStack, + ctx); zemu_log(buf); - (void) ctx; + (void)ctx; } #else @@ -67,8 +69,8 @@ void zemu_log_stack(__Z_UNUSED const char *ctx) {} #endif - -#if defined(ZEMU_LOGGING) && (defined (TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || defined(TARGET_STAX)) +#if defined(ZEMU_LOGGING) && (defined(TARGET_NANOS) || defined(TARGET_NANOX) || defined(TARGET_NANOS2) || \ + defined(TARGET_STAX) || defined(TARGET_FLEX)) void zemu_trace(const char *file, uint32_t line) { char buf[200]; snprintf(buf, sizeof(buf), "|TRACE| %s:%d\n", file, line);