|
cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
|
NVS-backed implementation of the persistent device settings. More...
#include "settings.h"#include "settings_rules.h"#include "civil_time.h"#include <atomic>#include <stdio.h>#include <string.h>#include "nvs.h"#include "nvs_flash.h"#include "esp_log.h"#include "esp_random.h"#include "CW_Utils.h"#include "keccak256.h"#include "config.h"Go to the source code of this file.
Macros | |
| #define | TRON_ADDR_USDT "" |
| #define | TRON_ADDR_USDT_MAIN "" |
| #define | ADDR_USDC_MAIN "" |
| #define | NS_SETTINGS "settings" |
| #define | K_BRIGHTNESS "bright" |
| #define | K_WIFI_SSID "wifi_ssid" |
| #define | K_WIFI_PASS "wifi_pass" |
| #define | K_MAX_FEE "max_fee_gw" |
| #define | K_PRIO_FEE "prio_fee_gw" |
| #define | K_ADMIN_SALT "adm_salt" |
| #define | K_ADMIN_HASH "adm_hash" |
| #define | K_ADMIN_FAILS "adm_fails" |
| #define | K_CHAIN "chain" |
| #define | K_MAINNET "mainnet" |
| #define | K_TZ_OFFSET "tz_off" |
| #define | K_TZ_DST "tz_dst" |
| #define | K_TOUCH_X "touch_x" |
| #define | K_TOUCH_Y "touch_y" |
| #define | K_BUILD_ID "build_id" |
| #define | K_INFLIGHT "inflight" |
| #define | K_PAY_ETH "pay_eth" |
| #define | K_PAY_ETH2 "pay_eth_e" |
| #define | K_PAY_TRX "pay_trx" |
| #define | K_PAY_TRX2 "pay_trx_e" |
| #define | K_CT_ETH "ct_eth" |
| #define | K_CT_ETH2 "ct_eth_e" |
| #define | K_CT_TRX "ct_trx" |
| #define | K_CT_TRX2 "ct_trx_e" |
| #define | K_CT_ETH_M "ct_eth_m" |
| #define | K_CT_ETH_M2 "ct_eth_me" |
| #define | K_CT_TRX_M "ct_trx_m" |
| #define | K_CT_TRX_M2 "ct_trx_me" |
| #define | DEFAULT_BRIGHTNESS 80U |
| #define | WEI_PER_GWEI 1000000000ULL |
| #define | DEFAULT_MAX_FEE_GWEI (uint32_t)(MAX_FEE / WEI_PER_GWEI) |
| #define | DEFAULT_PRIORITY_FEE_GWEI (uint32_t)(MAX_PRIORITY_FEE / WEI_PER_GWEI) |
| #define | TOUCH_CAL_DEF_MIN 200U |
| #define | TOUCH_CAL_DEF_MAX 3800U |
Functions | |
| static uint8_t | nvs_u8_get (const char *key, uint8_t def) |
| static void | nvs_u8_set (const char *key, uint8_t val) |
| static uint32_t | nvs_u32_get (const char *key, uint32_t def) |
| static void | nvs_u32_set (const char *key, uint32_t val) |
| static void | cache_invalidate (void) |
| Forget both, so the next read goes back to flash. For the erase paths. | |
| pos_chain_t | settings_get_chain (void) |
| Selected chain, or POS_CHAIN_ETH_USDC if never set. | |
| void | settings_set_chain (pos_chain_t chain) |
| Persist the selected chain. | |
| bool | settings_get_mainnet (void) |
| true when the terminal is on the production networks. | |
| void | settings_set_mainnet (bool mainnet) |
| Persist the production/test network choice. | |
| const char * | settings_net_str (const char *testnet, const char *mainnet) |
| Pick the string belonging to the network the terminal is on. | |
| uint8_t | settings_get_brightness (void) |
| Backlight level in percent, or 80 if never set. | |
| void | settings_set_brightness (uint8_t pct) |
| Persist the backlight level (0..100). | |
| int16_t | settings_get_tz_offset_min (void) |
| The panel clock's standard (winter) offset from UTC, in minutes east. | |
| bool | settings_set_tz_offset_min (int16_t minutes) |
| Store the panel clock's UTC offset. | |
| uint8_t | settings_get_tz_dst (void) |
| The clock's DST rule, a civil_dst_t; CIVIL_DST_NONE when unset. | |
| bool | settings_set_tz_dst (uint8_t rule) |
| Store the DST rule. | |
| void | settings_get_touch_cal (uint16_t *x_min, uint16_t *x_max, uint16_t *y_min, uint16_t *y_max) |
| Raw XPT2046 range that maps to the panel's four edges. | |
| void | settings_set_touch_cal (uint16_t x_min, uint16_t x_max, uint16_t y_min, uint16_t y_max) |
| Persist a calibration. Rejected (and ignored) if an axis is inverted or collapsed — a bad store here makes the panel untappable, including the screen that would fix it. | |
| bool | settings_has_wifi (void) |
| true if a Wi-Fi SSID has been stored. | |
| bool | settings_get_wifi (char *ssid, size_t ssid_n, char *pass, size_t pass_n) |
| Read the stored Wi-Fi credentials. | |
| void | settings_set_wifi (const char *ssid, const char *pass) |
| Persist Wi-Fi credentials (plaintext — see README threat model). | |
| static uint32_t | fee_get (const char *key, uint32_t dflt) |
| uint32_t | settings_get_max_fee_gwei (void) |
| EIP-1559 max fee per gas, in Gwei. | |
| uint32_t | settings_get_priority_fee_gwei (void) |
| EIP-1559 max priority fee (tip) per gas, in Gwei. | |
| bool | settings_set_fees_gwei (uint32_t max_gwei, uint32_t prio_gwei) |
| Persist the max fee and the tip per gas (Gwei), as a pair. | |
| static void | admin_set_fails (uint8_t n) |
| bool | settings_has_admin_code (void) |
| true once an admin code exists. | |
| bool | settings_set_admin_code (const char *code) |
| Store a new admin code, with a fresh random salt. | |
| bool | settings_check_admin_code (const char *code) |
| Check a candidate code, maintaining the failure counter. | |
| uint8_t | settings_admin_fail_count (void) |
| Consecutive failed unlock attempts, persisted. | |
| static bool | dual_get (const char *k_val, const char *k_echo, const char *def, const char *what, char *out, size_t n) |
Read a dual-stored address, falling back to def on any doubt. | |
| static bool | dual_set (const char *k_val, const char *k_echo, bool tron, const char *what, const char *addr) |
| Write a dual-stored address, normalising Ethereum to "0x"-prefixed. | |
| bool | settings_get_payout (bool tron, char *out, size_t n) |
| Read the payout address for a network. | |
| bool | settings_has_payout (bool tron) |
| Whether an operator has actually set the payout address for a network. | |
| bool | settings_set_payout (bool tron, const char *addr) |
| Persist a payout address, writing both the value and its echo copy. | |
| bool | settings_get_contract (pos_chain_t chain, char *out, size_t n) |
| Read the token-contract address for a network. | |
| bool | settings_set_contract (pos_chain_t chain, const char *addr) |
| Persist a token-contract address, value and echo copy. | |
| bool | settings_wipe_if_new_build (void) |
| Erase NVS unless this exact build is the one that wrote it. | |
| void | settings_factory_reset (void) |
| Erase all stored settings (brightness, auto, Wi-Fi creds, fees). | |
| bool | settings_inflight_save (const void *rec, size_t n) |
| Persist the sale between broadcast and verdict (opaque record). | |
| bool | settings_inflight_load (void *rec, size_t n) |
Read the persisted sale back. false if none, or not n bytes. | |
| void | settings_inflight_clear (void) |
| Drop the persisted sale. Writes nothing when there is none. | |
Variables | |
| static const char *const | TAG = "settings" |
| static std::atomic< int16_t > | s_chain_cache {-1} |
| static std::atomic< int8_t > | s_mainnet_cache {-1} |
NVS-backed implementation of the persistent device settings.
Definition in file settings.cpp.
| #define ADDR_USDC_MAIN "" |
Definition at line 41 of file settings.cpp.
| #define DEFAULT_BRIGHTNESS 80U |
Definition at line 88 of file settings.cpp.
Referenced by settings_get_brightness().
| #define DEFAULT_MAX_FEE_GWEI (uint32_t)(MAX_FEE / WEI_PER_GWEI) |
Definition at line 92 of file settings.cpp.
Referenced by settings_get_max_fee_gwei().
| #define DEFAULT_PRIORITY_FEE_GWEI (uint32_t)(MAX_PRIORITY_FEE / WEI_PER_GWEI) |
Definition at line 93 of file settings.cpp.
Referenced by settings_get_priority_fee_gwei().
| #define K_ADMIN_FAILS "adm_fails" |
Definition at line 54 of file settings.cpp.
Referenced by admin_set_fails(), settings_admin_fail_count(), and settings_set_admin_code().
| #define K_ADMIN_HASH "adm_hash" |
Definition at line 53 of file settings.cpp.
Referenced by settings_check_admin_code(), settings_has_admin_code(), and settings_set_admin_code().
| #define K_ADMIN_SALT "adm_salt" |
Definition at line 52 of file settings.cpp.
Referenced by settings_check_admin_code(), and settings_set_admin_code().
| #define K_BRIGHTNESS "bright" |
Definition at line 47 of file settings.cpp.
Referenced by settings_get_brightness(), and settings_set_brightness().
| #define K_BUILD_ID "build_id" |
Definition at line 64 of file settings.cpp.
Referenced by settings_factory_reset(), and settings_wipe_if_new_build().
| #define K_CHAIN "chain" |
Definition at line 55 of file settings.cpp.
Referenced by settings_get_chain(), and settings_set_chain().
| #define K_CT_ETH "ct_eth" |
Definition at line 77 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_CT_ETH2 "ct_eth_e" |
Definition at line 78 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_CT_ETH_M "ct_eth_m" |
Definition at line 81 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_CT_ETH_M2 "ct_eth_me" |
Definition at line 82 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_CT_TRX "ct_trx" |
Definition at line 79 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_CT_TRX2 "ct_trx_e" |
Definition at line 80 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_CT_TRX_M "ct_trx_m" |
Definition at line 83 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_CT_TRX_M2 "ct_trx_me" |
Definition at line 84 of file settings.cpp.
Referenced by settings_get_contract(), and settings_set_contract().
| #define K_INFLIGHT "inflight" |
Definition at line 69 of file settings.cpp.
Referenced by settings_inflight_clear(), settings_inflight_load(), and settings_inflight_save().
| #define K_MAINNET "mainnet" |
Definition at line 56 of file settings.cpp.
Referenced by settings_get_mainnet(), and settings_set_mainnet().
| #define K_MAX_FEE "max_fee_gw" |
Definition at line 50 of file settings.cpp.
Referenced by settings_get_max_fee_gwei(), and settings_set_fees_gwei().
| #define K_PAY_ETH "pay_eth" |
Definition at line 71 of file settings.cpp.
Referenced by settings_get_payout(), and settings_set_payout().
| #define K_PAY_ETH2 "pay_eth_e" |
Definition at line 72 of file settings.cpp.
Referenced by settings_get_payout(), and settings_set_payout().
| #define K_PAY_TRX "pay_trx" |
Definition at line 73 of file settings.cpp.
Referenced by settings_get_payout(), and settings_set_payout().
| #define K_PAY_TRX2 "pay_trx_e" |
Definition at line 74 of file settings.cpp.
Referenced by settings_get_payout(), and settings_set_payout().
| #define K_PRIO_FEE "prio_fee_gw" |
Definition at line 51 of file settings.cpp.
Referenced by settings_get_priority_fee_gwei(), and settings_set_fees_gwei().
| #define K_TOUCH_X "touch_x" |
Definition at line 61 of file settings.cpp.
Referenced by settings_get_touch_cal(), and settings_set_touch_cal().
| #define K_TOUCH_Y "touch_y" |
Definition at line 62 of file settings.cpp.
Referenced by settings_get_touch_cal(), and settings_set_touch_cal().
| #define K_TZ_DST "tz_dst" |
Definition at line 59 of file settings.cpp.
Referenced by settings_get_tz_dst(), and settings_set_tz_dst().
| #define K_TZ_OFFSET "tz_off" |
Definition at line 58 of file settings.cpp.
Referenced by settings_get_tz_offset_min(), and settings_set_tz_offset_min().
| #define K_WIFI_PASS "wifi_pass" |
Definition at line 49 of file settings.cpp.
Referenced by settings_get_wifi(), and settings_set_wifi().
| #define K_WIFI_SSID "wifi_ssid" |
Definition at line 48 of file settings.cpp.
Referenced by settings_get_wifi(), settings_has_wifi(), and settings_set_wifi().
| #define NS_SETTINGS "settings" |
Definition at line 46 of file settings.cpp.
Referenced by dual_get(), dual_set(), nvs_u32_get(), nvs_u32_set(), nvs_u8_get(), nvs_u8_set(), settings_check_admin_code(), settings_factory_reset(), settings_get_wifi(), settings_has_admin_code(), settings_has_wifi(), settings_inflight_clear(), settings_inflight_load(), settings_inflight_save(), settings_set_admin_code(), settings_set_wifi(), and settings_wipe_if_new_build().
| #define TOUCH_CAL_DEF_MAX 3800U |
Definition at line 258 of file settings.cpp.
Referenced by settings_get_touch_cal().
| #define TOUCH_CAL_DEF_MIN 200U |
Definition at line 257 of file settings.cpp.
Referenced by settings_get_touch_cal().
| #define TRON_ADDR_USDT "" |
Definition at line 34 of file settings.cpp.
| #define TRON_ADDR_USDT_MAIN "" |
Definition at line 38 of file settings.cpp.
| #define WEI_PER_GWEI 1000000000ULL |
Definition at line 91 of file settings.cpp.
|
static |
Definition at line 367 of file settings.cpp.
References K_ADMIN_FAILS, and nvs_u8_set().
Referenced by settings_check_admin_code().
|
static |
Forget both, so the next read goes back to flash. For the erase paths.
Definition at line 159 of file settings.cpp.
References s_chain_cache, and s_mainnet_cache.
Referenced by settings_factory_reset(), and settings_wipe_if_new_build().
|
static |
Read a dual-stored address, falling back to def on any doubt.
| [in] | k_val | NVS key holding the value. |
| [in] | k_echo | NVS key holding its echo copy. |
| [in] | def | Compile-time fallback, already in the returned form. |
| [in] | what | Label for the log line when the copies disagree. |
Definition at line 466 of file settings.cpp.
References NS_SETTINGS, SETTINGS_PAYOUT_MAX, and TAG.
Referenced by settings_get_contract(), and settings_get_payout().
|
static |
Write a dual-stored address, normalising Ethereum to "0x"-prefixed.
Definition at line 501 of file settings.cpp.
References NS_SETTINGS, ok(), settings_addr_normalise(), SETTINGS_PAYOUT_MAX, and TAG.
Referenced by settings_set_contract(), and settings_set_payout().
|
static |
Definition at line 341 of file settings.cpp.
References FEE_GWEI_MAX, FEE_GWEI_MIN, and nvs_u32_get().
Referenced by settings_get_max_fee_gwei(), and settings_get_priority_fee_gwei().
|
static |
Definition at line 124 of file settings.cpp.
References NS_SETTINGS.
Referenced by fee_get(), settings_get_touch_cal(), and settings_get_tz_offset_min().
|
static |
Definition at line 135 of file settings.cpp.
References NS_SETTINGS, and TAG.
Referenced by settings_set_fees_gwei(), settings_set_touch_cal(), and settings_set_tz_offset_min().
|
static |
Definition at line 101 of file settings.cpp.
References NS_SETTINGS.
Referenced by settings_admin_fail_count(), settings_get_brightness(), settings_get_chain(), settings_get_mainnet(), and settings_get_tz_dst().
|
static |
Definition at line 112 of file settings.cpp.
References NS_SETTINGS, and TAG.
Referenced by admin_set_fails(), settings_set_brightness(), settings_set_chain(), settings_set_mainnet(), and settings_set_tz_dst().
| uint8_t settings_admin_fail_count | ( | void | ) |
Consecutive failed unlock attempts, persisted.
Kept in NVS so power-cycling does not clear the penalty the UI derives from it.
Definition at line 448 of file settings.cpp.
References K_ADMIN_FAILS, and nvs_u8_get().
Referenced by admin_submit(), open_admin_entry(), settings_check_admin_code(), and ui_show_prov_auth().
| bool settings_check_admin_code | ( | const char * | code | ) |
Check a candidate code, maintaining the failure counter.
| [in] | code | NUL-terminated candidate. |
Definition at line 414 of file settings.cpp.
References admin_derive(), ADMIN_HASH_LEN, ADMIN_SALT_LEN, admin_set_fails(), K_ADMIN_HASH, K_ADMIN_SALT, NS_SETTINGS, ok(), settings_admin_fail_count(), and TAG.
Referenced by admin_submit().
| void settings_factory_reset | ( | void | ) |
Erase all stored settings (brightness, auto, Wi-Fi creds, fees).
Definition at line 619 of file settings.cpp.
References cache_invalidate(), K_BUILD_ID, NS_SETTINGS, and TAG.
Referenced by btn_event_cb().
| uint8_t settings_get_brightness | ( | void | ) |
Backlight level in percent, or 80 if never set.
Definition at line 215 of file settings.cpp.
References DEFAULT_BRIGHTNESS, K_BRIGHTNESS, and nvs_u8_get().
Referenced by ui_task().
| pos_chain_t settings_get_chain | ( | void | ) |
Selected chain, or POS_CHAIN_ETH_USDC if never set.
Definition at line 165 of file settings.cpp.
References K_CHAIN, nvs_u8_get(), POS_CHAIN__COUNT, POS_CHAIN_ETH_USDC, and s_chain_cache.
Referenced by admin_submit(), amount_cents_max(), app_main(), chain_is_native_evm(), chain_is_polygon(), chain_is_tron(), evm_balance_ok(), make_asset_button(), open_admin_entry(), pay_sign_and_broadcast(), tron_balance_ok(), tx_amount_row(), and ui_refresh_addresses().
| bool settings_get_contract | ( | pos_chain_t | chain, |
| char * | out, | ||
| size_t | n ) |
Read the token-contract address for a network.
Same dual store and config.h fallback as settings_get_payout: the contract decides which asset moves, so a half-written NVS string must not redirect it. Only USDC on Ethereum and USDT on Tron are settable; any other chain returns false with out empty.
Stored separately per network (settings_get_mainnet): the same token is a different deployment on each, and one slot would leave a mainnet terminal calling a testnet contract that holds nothing.
| [in] | chain | The token's selection. |
| [out] | out | Buffer, >= SETTINGS_PAYOUT_MAX. Ethereum contracts are returned "0x"-prefixed. |
| [in] | n | Capacity of out. |
chain, nothing) was. Definition at line 549 of file settings.cpp.
References ADDR_USDC_MAIN, dual_get(), K_CT_ETH, K_CT_ETH2, K_CT_ETH_M, K_CT_ETH_M2, K_CT_TRX, K_CT_TRX2, K_CT_TRX_M, K_CT_TRX_M2, POS_CHAIN_ETH_USDC, POS_CHAIN_TRON_USDT, settings_get_mainnet(), TRON_ADDR_USDT, and TRON_ADDR_USDT_MAIN.
Referenced by state_get(), and token_load().
| bool settings_get_mainnet | ( | void | ) |
true when the terminal is on the production networks.
Picks the deployment (Ethereum/Sepolia, Polygon/Amoy, Tron/Nile), not the asset. Defaults to true: a unit coming up on a testnet would report every sale as paid and settle nothing. Endpoints, chain ids and contracts are read once at boot into the dual stores, so settings_set_mainnet takes effect only on a restart, which the caller performs.
Definition at line 189 of file settings.cpp.
References K_MAINNET, nvs_u8_get(), and s_mainnet_cache.
Referenced by add_test_chip(), network_post(), pos_boot(), settings_get_contract(), settings_net_str(), settings_set_contract(), sign_and_broadcast(), and state_get().
| uint32_t settings_get_max_fee_gwei | ( | void | ) |
EIP-1559 max fee per gas, in Gwei.
Definition at line 347 of file settings.cpp.
References DEFAULT_MAX_FEE_GWEI, fee_get(), and K_MAX_FEE.
Referenced by build_settings(), evm_fees_wei(), state_get(), and ui_task().
| bool settings_get_payout | ( | bool | tron, |
| char * | out, | ||
| size_t | n ) |
Read the payout address for a network.
Falls back to the config.h recipient when nothing is stored, so callers always get a parseable address. That fallback is for display and boot-time reasoning only: the payment path checks settings_has_payout first and refuses the sale, because an address nobody chose is somebody else's.
Dual-stored: the NVS value carries an echo copy compared here (the config.h value lives in the signed image and needs none). A mismatch falls back to config.h rather than paying out to a half-written string.
| [in] | tron | true for the Tron payout address, false for Ethereum. |
| [out] | out | Buffer, >= SETTINGS_PAYOUT_MAX. Ethereum addresses are returned "0x"-prefixed, ready to parse. |
| [in] | n | Capacity of out. |
out is valid. Definition at line 525 of file settings.cpp.
References dual_get(), K_PAY_ETH, K_PAY_ETH2, K_PAY_TRX, and K_PAY_TRX2.
Referenced by pos_boot(), resolve_evm_payout(), settings_has_payout(), and state_get().
| uint32_t settings_get_priority_fee_gwei | ( | void | ) |
EIP-1559 max priority fee (tip) per gas, in Gwei.
Definition at line 352 of file settings.cpp.
References DEFAULT_PRIORITY_FEE_GWEI, fee_get(), and K_PRIO_FEE.
Referenced by build_settings(), evm_fees_wei(), state_get(), and ui_task().
| void settings_get_touch_cal | ( | uint16_t * | x_min, |
| uint16_t * | x_max, | ||
| uint16_t * | y_min, | ||
| uint16_t * | y_max ) |
Raw XPT2046 range that maps to the panel's four edges.
Resistive overlays vary unit to unit, so this is stored per device. Defaults to 200..3800, close enough to reach the calibration screen uncalibrated.
Definition at line 260 of file settings.cpp.
References K_TOUCH_X, K_TOUCH_Y, nvs_u32_get(), TOUCH_CAL_DEF_MAX, and TOUCH_CAL_DEF_MIN.
Referenced by touch_cal_load().
| uint8_t settings_get_tz_dst | ( | void | ) |
The clock's DST rule, a civil_dst_t; CIVIL_DST_NONE when unset.
Definition at line 243 of file settings.cpp.
References CIVIL_DST_NONE, K_TZ_DST, nvs_u8_get(), and tz_dst_decode().
Referenced by clock_refresh(), pos_boot(), and state_get().
| int16_t settings_get_tz_offset_min | ( | void | ) |
The panel clock's standard (winter) offset from UTC, in minutes east.
Minutes because half- and quarter-hour zones exist. DST is added on top from settings_get_tz_dst() by civil_time.cpp (newlib's tzset costs 64 KB of flash).
Definition at line 226 of file settings.cpp.
References K_TZ_OFFSET, nvs_u32_get(), TZ_OFFSET_BIAS, and tz_offset_decode().
Referenced by clock_refresh(), pos_boot(), and state_get().
| bool settings_get_wifi | ( | char * | ssid, |
| size_t | ssid_n, | ||
| char * | pass, | ||
| size_t | pass_n ) |
Read the stored Wi-Fi credentials.
| [out] | ssid | Buffer for the SSID (>= 33 bytes recommended). |
| [in] | ssid_n | Capacity of ssid. |
| [out] | pass | Buffer for the password (>= 65 bytes recommended). |
| [in] | pass_n | Capacity of pass. |
Definition at line 298 of file settings.cpp.
References K_WIFI_PASS, K_WIFI_SSID, NS_SETTINGS, and ok().
Referenced by app_main(), build_settings(), state_get(), and wifi_try_saved().
| bool settings_has_admin_code | ( | void | ) |
true once an admin code exists.
Not "configured": an interrupted setup leaves a code and no payout address. Use settings_has_payout for "can this unit take money". Cleared by settings_factory_reset.
Definition at line 372 of file settings.cpp.
References ADMIN_HASH_LEN, K_ADMIN_HASH, and NS_SETTINGS.
Referenced by auth_post(), open_admin_entry(), and pos_boot().
| bool settings_has_payout | ( | bool | tron | ) |
Whether an operator has actually set the payout address for a network.
Decides whether an asset is offered at all: a unit set up for Ethereum only must not offer Tron payments to the compile-time recipient, which is somebody else's address.
Definition at line 534 of file settings.cpp.
References settings_get_payout(), and SETTINGS_PAYOUT_MAX.
Referenced by app_main(), build_settings(), open_network_picker(), pos_boot(), and run_wizard().
| bool settings_has_wifi | ( | void | ) |
true if a Wi-Fi SSID has been stored.
Definition at line 284 of file settings.cpp.
References K_WIFI_SSID, and NS_SETTINGS.
Referenced by pos_boot(), and run_wizard().
| void settings_inflight_clear | ( | void | ) |
Drop the persisted sale. Writes nothing when there is none.
Definition at line 673 of file settings.cpp.
References K_INFLIGHT, and NS_SETTINGS.
Referenced by app_main(), and settle_inflight().
| bool settings_inflight_load | ( | void * | rec, |
| size_t | n ) |
Read the persisted sale back. false if none, or not n bytes.
Definition at line 660 of file settings.cpp.
References K_INFLIGHT, and NS_SETTINGS.
Referenced by app_main().
| bool settings_inflight_save | ( | const void * | rec, |
| size_t | n ) |
Persist the sale between broadcast and verdict (opaque record).
Written just before the transaction leaves the terminal and cleared on the final verdict, so a brownout or panic while polling does not lose whether the customer paid: the next boot resumes polling the same hash. Layout is main.cpp's. Survives a power cut, not a firmware update (see settings_wipe_if_new_build) or a factory reset.
Definition at line 645 of file settings.cpp.
References K_INFLIGHT, NS_SETTINGS, ok(), and TAG.
Referenced by inflight_persist().
| const char * settings_net_str | ( | const char * | testnet, |
| const char * | mainnet ) |
Pick the string belonging to the network the terminal is on.
One place for every config.h testnet/mainnet pair (RPC URLs, contracts, names), so no call site can leave a mainnet sale pointed at a testnet contract.
Definition at line 210 of file settings.cpp.
References settings_get_mainnet().
Referenced by asset_network(), eth_rpc_select_for(), open_network_picker(), pos_boot(), and token_load().
| bool settings_set_admin_code | ( | const char * | code | ) |
Store a new admin code, with a fresh random salt.
Only a salted keccak256 digest is persisted, deliberately not stretched (see settings.cpp). Resets the failure counter.
| [in] | code | NUL-terminated code; the caller wipes its own copy. |
Definition at line 385 of file settings.cpp.
References admin_derive(), ADMIN_HASH_LEN, ADMIN_SALT_LEN, K_ADMIN_FAILS, K_ADMIN_HASH, K_ADMIN_SALT, NS_SETTINGS, ok(), and TAG.
Referenced by admin_submit().
| void settings_set_brightness | ( | uint8_t | pct | ) |
Persist the backlight level (0..100).
Definition at line 220 of file settings.cpp.
References K_BRIGHTNESS, and nvs_u8_set().
Referenced by settings_persist().
| void settings_set_chain | ( | pos_chain_t | chain | ) |
Persist the selected chain.
Definition at line 181 of file settings.cpp.
References K_CHAIN, nvs_u8_set(), and s_chain_cache.
Referenced by btn_event_cb(), and pos_boot().
| bool settings_set_contract | ( | pos_chain_t | chain, |
| const char * | addr ) |
Persist a token-contract address, value and echo copy.
Does not validate — same contract as settings_set_payout: the caller checks the address and has it accepted on the device screen first.
Definition at line 566 of file settings.cpp.
References dual_set(), K_CT_ETH, K_CT_ETH2, K_CT_ETH_M, K_CT_ETH_M2, K_CT_TRX, K_CT_TRX2, K_CT_TRX_M, K_CT_TRX_M2, POS_CHAIN_ETH_USDC, POS_CHAIN_TRON_USDT, and settings_get_mainnet().
Referenced by prov_pending_commit().
| bool settings_set_fees_gwei | ( | uint32_t | max_gwei, |
| uint32_t | prio_gwei ) |
Persist the max fee and the tip per gas (Gwei), as a pair.
fee_pair_check (settings_rules.h) refuses it. Definition at line 357 of file settings.cpp.
References fee_pair_check(), FEE_PAIR_OK, K_MAX_FEE, K_PRIO_FEE, and nvs_u32_set().
Referenced by fees_post().
| void settings_set_mainnet | ( | bool | mainnet | ) |
Persist the production/test network choice.
Definition at line 201 of file settings.cpp.
References K_MAINNET, nvs_u8_set(), and TAG.
Referenced by network_post().
| bool settings_set_payout | ( | bool | tron, |
| const char * | addr ) |
Persist a payout address, writing both the value and its echo copy.
Does not validate: the caller checks the EIP-55 / base58 checksum first and shows the address on the device screen for the operator to accept.
| [in] | tron | true for the Tron address, false for Ethereum. |
| [in] | addr | NUL-terminated address; Ethereum with or without "0x". |
Definition at line 542 of file settings.cpp.
References dual_set(), K_PAY_ETH, K_PAY_ETH2, K_PAY_TRX, and K_PAY_TRX2.
Referenced by prov_pending_commit().
| void settings_set_touch_cal | ( | uint16_t | x_min, |
| uint16_t | x_max, | ||
| uint16_t | y_min, | ||
| uint16_t | y_max ) |
Persist a calibration. Rejected (and ignored) if an axis is inverted or collapsed — a bad store here makes the panel untappable, including the screen that would fix it.
Definition at line 270 of file settings.cpp.
References K_TOUCH_X, K_TOUCH_Y, nvs_u32_set(), and TAG.
Referenced by btn_event_cb().
| bool settings_set_tz_dst | ( | uint8_t | rule | ) |
Store the DST rule.
Definition at line 248 of file settings.cpp.
References K_TZ_DST, nvs_u8_set(), and tz_dst_valid().
Referenced by clock_post().
| bool settings_set_tz_offset_min | ( | int16_t | minutes | ) |
Store the panel clock's UTC offset.
| [in] | minutes | Minutes east of UTC, TZ_OFFSET_MIN to TZ_OFFSET_MAX. |
Definition at line 234 of file settings.cpp.
References K_TZ_OFFSET, nvs_u32_set(), tz_offset_encode(), and tz_offset_valid().
Referenced by clock_post().
| void settings_set_wifi | ( | const char * | ssid, |
| const char * | pass ) |
Persist Wi-Fi credentials (plaintext — see README threat model).
Definition at line 324 of file settings.cpp.
References K_WIFI_PASS, K_WIFI_SSID, NS_SETTINGS, and TAG.
Referenced by app_main(), run_wizard(), and wifi_keep_or_drop().
| bool settings_wipe_if_new_build | ( | void | ) |
Erase NVS unless this exact build is the one that wrote it.
Call once at the top of app_main, right after nvs_flash_init() and before anything else opens NVS (nvs_flash_erase() cannot run with handles outstanding). Handles its own re-init and stamps BUILD_ID.
A security control: the firmware is open source, so any other image could have written anything into NVS, a payout address above all. The test is equality — newer, older and absent stamps all erase. A rollback therefore erases again; settings are cheaper to re-enter than a payout address to lose.
The stamp does not authenticate itself: a hostile image that runs can forge it. Secure Boot (and Flash Encryption in RELEASE) stops foreign images; this covers state left by non-hostile ones (old releases, engineering builds).
Erases the whole partition, Wi-Fi and provision.cpp namespaces included, so the unit comes up in first-run setup and stays unowned until an operator re-enters Wi-Fi and re-accepts the payout address.
Definition at line 578 of file settings.cpp.
References cache_invalidate(), K_BUILD_ID, NS_SETTINGS, and TAG.
Referenced by pos_boot().
|
static |
Definition at line 155 of file settings.cpp.
Referenced by cache_invalidate(), settings_get_chain(), and settings_set_chain().
|
static |
Definition at line 156 of file settings.cpp.
Referenced by cache_invalidate(), and settings_get_mainnet().
|
static |
Definition at line 44 of file settings.cpp.