|
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 "config.h"Go to the source code of this file.
Macros | |
| #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_connect_loop (CryptnoxWallet &wallet) |
| Main application loop: connect, fetch card info, and disconnect. | |
| void | app_main (void) |
| ESP-IDF application entry point. | |
Variables | |
| static const char *const | TAG = "connect" |
| 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 |
| void app_main | ( | void | ) |
ESP-IDF application entry point.
Initialises NVS, starts Wi-Fi for full TRNG entropy, brings up the SPI bus and PN532 reader, then enters run_connect_loop.
Definition at line 192 of file main.cpp.
References ESP32Logger::begin(), NFC_CS, pn532_config_t::pin_cs, pn532_init(), Pn532NfcTransport::printFirmwareVersion(), run_connect_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, and wifi_start().
|
static |
Main application loop: connect, fetch card info, and disconnect.
Each iteration calls CryptnoxWallet::connect to establish the secure channel, retrieves owner info via CryptnoxWallet::getCardInfo, then tears down the channel with CryptnoxWallet::disconnect.
| [in] | wallet | Initialised wallet instance. |
Definition at line 160 of file main.cpp.
References 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 77 of file main.cpp.
References s_retry_num, s_wifi_event_group, WIFI_CONNECTED_BIT, WIFI_FAIL_BIT, and WIFI_MAX_RETRY.
|
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 112 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.