|
cryptnox-pos 1.0.0
Standalone USDC payment terminal firmware (ESP32 + Cryptnox smart card)
|
Network bring-up: Wi-Fi station (init/scan/connect/RSSI) and SNTP time sync. No application-protocol logic lives here — the Ethereum JSON-RPC client is in eth_rpc.h. More...
#include <stdint.h>#include <stdbool.h>Go to the source code of this file.
Classes | |
| struct | net_wifi_ap_t |
| A scanned access point (subset of fields the UI needs). More... | |
Functions | |
| void | net_wifi_init (void) |
| Bring up the WiFi driver in station mode (idempotent). | |
| uint16_t | net_wifi_scan (net_wifi_ap_t *out, uint16_t max) |
| Scan for nearby access points (blocking). | |
| bool | net_wifi_connect (const char *ssid, const char *password) |
| Connect to a WiFi network and block until an IP is obtained (up to 30 s). May be called repeatedly to switch networks. | |
| void | net_wifi_disconnect (void) |
| Drop the station association, without the retry loop pulling it back. | |
| bool | net_ap_start (const char *ssid, const char *pass) |
| Raise a WPA2 SoftAP as the radio's only interface, for phone-based configuration. | |
| void | net_ap_stop (void) |
| Drop the SoftAP, return the radio to station-only, and re-join. | |
| void | net_wifi_keep_trying (void) |
| Hold on to the network last configured, even though it is down now. | |
| bool | net_wifi_online (void) |
| true while the station holds an IP address. | |
| bool | net_wifi_reconnecting (void) |
| true while a kept network is down and the re-join is running. | |
| bool | net_wifi_rssi (int8_t *rssi_out) |
| Read the RSSI of the currently associated access point. | |
| bool | net_time_sync (uint32_t timeout_ms) |
| Block until the system clock has been set via SNTP and sanity-checked. | |
| void | net_time_background (void) |
| Subscribe SNTP without waiting, so the clock is set whenever the network comes back. | |
Network bring-up: Wi-Fi station (init/scan/connect/RSSI) and SNTP time sync. No application-protocol logic lives here — the Ethereum JSON-RPC client is in eth_rpc.h.
Definition in file net.h.
| bool net_ap_start | ( | const char * | ssid, |
| const char * | pass ) |
Raise a WPA2 SoftAP as the radio's only interface, for phone-based configuration.
AP-only, not APSTA, and the station association is dropped on the way in. The config portal's HTTP server binds every interface (esp_http_server offers no bind address), so an APSTA terminal answers the payout forms on the venue LAN as well as on the AP — which is exactly where the AP passphrase guards nothing. Taking the station down makes the AP the only door there is.
The station is borrowed back where it is genuinely needed and only for as long as that takes: net_wifi_scan flips to APSTA for the scan itself, and net_wifi_connect for the join the operator asked for. net_ap_stop re-associates afterwards.
One radio, one channel: when the station associates, the SoftAP is dragged onto the station's channel and any joined phone is dropped. That is expected — the setup page warns before it submits Wi-Fi credentials, and the device screen, not the phone, reports the outcome.
| [in] | ssid | AP SSID. |
| [in] | pass | WPA2 passphrase; must be at least 8 characters. |
Definition at line 215 of file net.cpp.
References net_wifi_disconnect(), net_wifi_init(), s_ap_netif, s_ap_up, and TAG.
Referenced by prov_start().
| void net_ap_stop | ( | void | ) |
Drop the SoftAP, return the radio to station-only, and re-join.
The association net_ap_start displaced is put back if it is not already up: the driver still holds the credentials, so only the association went away. Without it, closing the config page would leave a working terminal offline until somebody rebooted it.
Definition at line 286 of file net.cpp.
References s_ap_netif, s_ap_up, s_keep, s_retry_num, and TAG.
Referenced by prov_start(), and prov_stop().
| void net_time_background | ( | void | ) |
Subscribe SNTP without waiting, so the clock is set whenever the network comes back.
For a boot that could not sync in the foreground. lwIP retries on its own; the build-time floor net_time_sync enforces is applied to every update, so a back-dated packet clears the clock rather than setting it. Idempotent.
Definition at line 529 of file net.cpp.
References s_sntp_running, sntp_start(), and TAG.
Referenced by pos_boot().
| bool net_time_sync | ( | uint32_t | timeout_ms | ) |
Block until the system clock has been set via SNTP and sanity-checked.
Must be called after net_wifi_connect() and before any HTTPS request: without real time, TLS certificate validity-period checks are meaningless. Those checks are only actually compiled in when CONFIG_MBEDTLS_HAVE_TIME_DATE is set (see sdkconfig.defaults) — HAVE_TIME alone is not enough. SNTP keeps running in the background for periodic resyncs.
Callable repeatedly: each call re-subscribes and waits for a fresh packet, so it doubles as a probe for whether the network just joined reaches the internet.
SNTP is unauthenticated, so a synced time earlier than the firmware's own build timestamp is rejected: back-dating is what an attacker needs to make an expired certificate look valid again. Moving the clock forward is harmless and is not restricted. A rejection returns false like any other failure, so the caller's existing "no network time" path applies.
| [in] | timeout_ms | Maximum time to wait for the sync. |
Definition at line 536 of file net.cpp.
References build_time_floor(), s_sntp_running, sntp_start(), TAG, and wdt_feed().
Referenced by app_main(), run_wizard(), and sync_time().
| bool net_wifi_connect | ( | const char * | ssid, |
| const char * | password ) |
Connect to a WiFi network and block until an IP is obtained (up to 30 s). May be called repeatedly to switch networks.
| [in] | ssid | Network SSID. |
| [in] | password | Passphrase (empty string for an open network). |
Definition at line 376 of file net.cpp.
References net_wifi_init(), rejoin_cancel(), s_ap_up, s_keep, s_retry_num, s_wifi_event_group, TAG, wdt_feed(), WIFI_CONNECTED_BIT, WIFI_FAIL_BIT, and WIFI_TIMEOUT_MS.
Referenced by app_main(), run_wizard(), wifi_picker(), and wifi_try_saved().
| void net_wifi_disconnect | ( | void | ) |
Drop the station association, without the retry loop pulling it back.
For a join that worked but is not being kept: the setup portal's HTTP server binds every interface, so an associated station puts the setup forms on the venue LAN as well as on the SoftAP. Leaving a test association up while that portal is still running hands the forms to everyone holding the venue PSK. With a SoftAP up this also returns the radio to AP-only, so the station interface goes down with the association rather than lingering idle. Idempotent, and safe before any connect.
Definition at line 268 of file net.cpp.
References rejoin_cancel(), s_ap_up, s_keep, s_retry_num, s_wifi_inited, TAG, and WIFI_MAX_RETRY.
Referenced by app_main(), net_ap_start(), and run_wizard().
| void net_wifi_init | ( | void | ) |
Bring up the WiFi driver in station mode (idempotent).
Initialises netif, the event loop and the WiFi driver and starts the STA. Call once before scanning or connecting. Safe to call repeatedly.
Definition at line 175 of file net.cpp.
References rejoin_cb(), s_rejoin_timer, s_retry_num, s_wifi_event_group, s_wifi_inited, and wifi_event_handler().
Referenced by net_ap_start(), net_wifi_connect(), net_wifi_scan(), pos_boot(), and prov_start().
| void net_wifi_keep_trying | ( | void | ) |
Hold on to the network last configured, even though it is down now.
A join that succeeds already does this: from then on a drop past the immediate retries hands over to a background re-join (2 s doubling to every 30 s, for as long as it takes). This is for the unit that boots while its router is still coming up — the saved network was tried and failed, and should be tried again in the background rather than never. No-op while the SoftAP is up, and undone by net_wifi_disconnect and net_wifi_connect.
Definition at line 430 of file net.cpp.
References rejoin_schedule(), s_ap_up, s_keep, and s_wifi_inited.
Referenced by app_main(), and pos_boot().
| bool net_wifi_online | ( | void | ) |
true while the station holds an IP address.
Definition at line 437 of file net.cpp.
References s_wifi_event_group, and WIFI_CONNECTED_BIT.
Referenced by app_main(), and net_wifi_reconnecting().
| bool net_wifi_reconnecting | ( | void | ) |
true while a kept network is down and the re-join is running.
Definition at line 443 of file net.cpp.
References net_wifi_online(), and s_keep.
Referenced by signal_refresh().
| bool net_wifi_rssi | ( | int8_t * | rssi_out | ) |
Read the RSSI of the currently associated access point.
| [out] | rssi_out | Signal strength in dBm (closer to 0 = stronger); untouched when not associated. |
rssi_out was written, false otherwise. Definition at line 448 of file net.cpp.
Referenced by build_settings(), and signal_refresh().
| uint16_t net_wifi_scan | ( | net_wifi_ap_t * | out, |
| uint16_t | max ) |
Scan for nearby access points (blocking).
| [out] | out | Array to fill with de-duplicated APs. |
| [in] | max | Capacity of out. |
Definition at line 322 of file net.cpp.
References net_wifi_init(), net_wifi_ap_t::open, net_wifi_ap_t::rssi, s_ap_up, net_wifi_ap_t::ssid, and wdt_feed().
Referenced by app_main(), run_wizard(), and wifi_picker().