|
cryptnox-sdk-esp32 1.0.0
ESP32 SDK for Cryptnox Hardware Wallet
|
#include <string.h>#include "freertos/FreeRTOS.h"#include "freertos/task.h"#include "freertos/event_groups.h"#include "driver/spi_master.h"#include "esp_log.h"#include "esp_wifi.h"#include "esp_netif.h"#include "esp_event.h"#include "nvs_flash.h"#include "pn532.h"#include "CryptnoxWallet.h"#include "Pn532NfcTransport.h"#include "ESP32Logger.h"#include "esp32_crypto_provider.h"#include "ESP32Platform.h"#include "CW_Utils.h"#include "config.h"Go to the source code of this file.
Macros | |
| #define | SPI_ENABLED 1 |
| #define | I2C_ENABLED 0 |
| #define | SPI_MOSI 11 |
| #define | SPI_MISO 13 |
| #define | SPI_SCLK 12 |
| #define | SPI_MAX_TRANSFER_SZ 4096 |
| #define | SPI_PIN_UNUSED (-1) |
| #define | NFC_CS 10 |
| #define | WIFI_CONNECTED_BIT BIT0 |
| #define | WIFI_FAIL_BIT BIT1 |
Functions | |
| static void | wifi_event_handler (void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) |
| FreeRTOS event handler driving the Wi-Fi station state machine. | |
| static void | wifi_start (void) |
| Initialise Wi-Fi station mode and block until connected or timeout. | |
| static void | run_basic_usage_loop (CryptnoxWallet &wallet) |
| Main application loop: connect, sign a test hash, wipe buffers, disconnect. | |
| void | app_main (void) |
| ESP-IDF application entry point. | |
Variables | |
| static const char *const | TAG = "basic_usage" |
| static const uint32_t | LOOP_DELAY_MS = 1000U |
| static const uint32_t | WIFI_TIMEOUT_MS = 10000U |
| static const int | WIFI_MAX_RETRY = 5 |
| static EventGroupHandle_t | s_wifi_event_group |
| static int | s_retry_num = 0 |
| static const uint8_t | DEFAULT_PIN [] = "000000000" |
| Demo PIN — replace with the PIN used during card initialisation. | |
| static const size_t | DEFAULT_PIN_LEN = sizeof(DEFAULT_PIN) - 1U |
| #define NFC_CS 10 |
Definition at line 59 of file main.cpp.
Referenced by app_main().
| #define SPI_MAX_TRANSFER_SZ 4096 |
Definition at line 57 of file main.cpp.
Referenced by app_main().
| #define SPI_MISO 13 |
Definition at line 55 of file main.cpp.
Referenced by app_main().
| #define SPI_MOSI 11 |
Definition at line 54 of file main.cpp.
Referenced by app_main().
| #define SPI_PIN_UNUSED (-1) |
Definition at line 58 of file main.cpp.
Referenced by app_main().
| #define SPI_SCLK 12 |
Definition at line 56 of file main.cpp.
Referenced by app_main().
| #define WIFI_CONNECTED_BIT BIT0 |
Definition at line 77 of file main.cpp.
Referenced by eth_rpc_wifi_connect(), wifi_event_handler(), wifi_event_handler(), and wifi_start().
| #define WIFI_FAIL_BIT BIT1 |
Definition at line 78 of file main.cpp.
Referenced by eth_rpc_wifi_connect(), wifi_event_handler(), wifi_event_handler(), and wifi_start().
| void app_main | ( | void | ) |
ESP-IDF application entry point.
Initialises NVS, starts Wi-Fi for full TRNG entropy, brings up the SPI or I²C bus and PN532 reader, then enters run_basic_usage_loop.
Definition at line 284 of file main.cpp.
References ESP32Logger::begin(), pn532_config_t::i2c_clock_hz, pn532_config_t::i2c_port, NFC_CS, pn532_config_t::pin_cs, pn532_config_t::pin_irq, pn532_config_t::pin_rst, pn532_config_t::pin_scl, pn532_config_t::pin_sda, pn532_init(), PN532_TRANSPORT_I2C, PN532_TRANSPORT_SPI, Pn532NfcTransport::printFirmwareVersion(), run_basic_usage_loop(), pn532_config_t::skip_bus_init, pn532_config_t::spi_host, SPI_MAX_TRANSFER_SZ, SPI_MISO, SPI_MOSI, SPI_PIN_UNUSED, SPI_SCLK, TAG, pn532_config_t::transport, and wifi_start().
|
static |
Main application loop: connect, sign a test hash, wipe buffers, disconnect.
Each iteration establishes the secure channel, signs a 32-byte test hash, prints the raw r‖s bytes, securely wipes sensitive buffers, then disconnects. Halts permanently on CW_SIGN_PIN_INCORRECT to protect the card's retry counter.
| [in] | wallet | Initialised wallet instance. |
Definition at line 192 of file main.cpp.
References DEFAULT_PIN, DEFAULT_PIN_LEN, LOOP_DELAY_MS, and TAG.
Referenced by app_main().
|
static |
FreeRTOS event handler driving the Wi-Fi station state machine.
Handles WIFI_EVENT_STA_START (triggers connection), WIFI_EVENT_STA_DISCONNECTED (retries up to WIFI_MAX_RETRY times), and IP_EVENT_STA_GOT_IP (signals success via the event group).
| [in] | arg | Unused. |
| [in] | event_base | Event base (WIFI_EVENT or IP_EVENT). |
| [in] | event_id | Event identifier within event_base. |
| [in] | event_data | Event-specific data (unused). |
Definition at line 95 of file main.cpp.
References s_retry_num, s_wifi_event_group, WIFI_CONNECTED_BIT, WIFI_FAIL_BIT, and WIFI_MAX_RETRY.
Referenced by eth_rpc_wifi_connect(), and wifi_start().
|
static |
Initialise Wi-Fi station mode and block until connected or timeout.
Starts the ESP Wi-Fi stack, registers wifi_event_handler, configures the SSID and password from WIFI_SSID / WIFI_PASSWORD in config.h, then waits up to WIFI_TIMEOUT_MS for an IP address. The radio must be active before crypto operations so the hardware TRNG operates with full entropy (SEC-001).
Definition at line 130 of file main.cpp.
References s_retry_num, s_wifi_event_group, TAG, WIFI_CONNECTED_BIT, wifi_event_handler(), WIFI_FAIL_BIT, WIFI_PASSWORD, WIFI_SSID, and WIFI_TIMEOUT_MS.
Referenced by app_main().
|
static |
Demo PIN — replace with the PIN used during card initialisation.
Definition at line 175 of file main.cpp.
Referenced by run_basic_usage_loop().
|
static |
Definition at line 176 of file main.cpp.
Referenced by run_basic_usage_loop().
|
static |
Definition at line 73 of file main.cpp.
Referenced by run_basic_usage_loop(), run_connect_loop(), run_sign_loop(), and run_verify_pin_loop().
|
static |
Definition at line 81 of file main.cpp.
Referenced by eth_rpc_wifi_connect(), wifi_event_handler(), wifi_event_handler(), and wifi_start().
|
static |
Definition at line 80 of file main.cpp.
Referenced by eth_rpc_wifi_connect(), wifi_event_handler(), wifi_event_handler(), and wifi_start().