Kleidos API Search

In development. It changes without notice.

Topic

Wi-Fi & HTTP Server

Wi-Fi as an access point and as a station, the HTTP server, the time from the network, and addresses.

The access point and the server run only in the portal (Wi-Fi Admin Portal). The station runs only for a time sync (Network Services). Bluetooth is off before either comes up, and both are down before the board sleeps.

The access point is WPA3 only, with protected management frames, unless its caller asks otherwise; a release build refuses that.

ap.start( { .ssid = "Kleidos", .password = "...", .wpa3Only = true } );
srv.start( { .port = 80 }, dispatch, nullptr );
See also
Wi-Fi Admin Portal, Network Services

Files

file src/platform/connectivity/http_server.cpp
ESP-IDF HTTP server facade implementation.
file src/platform/connectivity/http_server.h
HTTP server facade for the admin portal and OTA upload.
file src/platform/connectivity/ipv4_literal.h
Strict literal-IPv4 (dotted-quad) validator — pure, host-testable.
file src/platform/connectivity/ipv4_mapped.h
IPv4 address carried in an IPv4-mapped IPv6 address — pure, host-testable.
file src/platform/connectivity/sntp_client.cpp
One-shot SNTP query implementation (capture-only, IP-literal servers).
file src/platform/connectivity/sntp_client.h
One-shot SNTP time query against a literal IPv4 address (no DNS).
file src/platform/connectivity/udp_socket.cpp
IPv4 UDP socket implementation.
file src/platform/connectivity/udp_socket.h
UDP socket facade (IPv4 datagrams).
file src/platform/connectivity/wifi_access_point.cpp
WiFi SoftAP session implementation.
file src/platform/connectivity/wifi_access_point.h
WiFi SoftAP facade for ADMIN_MODE.
file src/platform/connectivity/wifi_channel_choice.h
Choosing the access point's channel from a survey of the networks around it.
file src/platform/connectivity/wifi_control.cpp
WiFi stop-and-deinit implementation.
file src/platform/connectivity/wifi_control.h
WiFi lifecycle facade.
file src/platform/connectivity/wifi_driver_config.h
Filling and wiping the Wi-Fi driver's configuration record.
file src/platform/connectivity/wifi_station.cpp
WiFi station session implementation.
file src/platform/connectivity/wifi_station.h
WiFi station (STA) facade for joining an existing network.

Classes

struct kleidos::platform::http::ServerConfig
HTTP server configuration. More about kleidos::platform::http::ServerConfig
class kleidos::platform::http::Server
RAII HTTP server; stops on destruction. More about kleidos::platform::http::Server
struct kleidos::platform::http::TestBackend
Function-pointer backend that drives the request/response free functions in host (non-ESP) builds. More about kleidos::platform::http::TestBackend
struct kleidos::platform::net::UdpEndpoint
IPv4 UDP endpoint. More about kleidos::platform::net::UdpEndpoint
struct kleidos::platform::net::ReceiveResult
Result of UdpSocket::receiveFrom(). More about kleidos::platform::net::ReceiveResult
class kleidos::platform::net::UdpSocket
RAII UDP socket; closes its file descriptor on destruction. More about kleidos::platform::net::UdpSocket
struct kleidos::platform::wifi::AccessPointConfig
SoftAP configuration. More about kleidos::platform::wifi::AccessPointConfig
struct kleidos::platform::wifi::AccessPointSnapshot
Runtime snapshot of the access point. More about kleidos::platform::wifi::AccessPointSnapshot
class kleidos::platform::wifi::AccessPointSession
RAII SoftAP session; stops the access point on destruction. More about kleidos::platform::wifi::AccessPointSession
struct kleidos::platform::wifi::ChannelObservation
One network a survey heard: where it transmits and how strongly. More about kleidos::platform::wifi::ChannelObservation
struct kleidos::platform::wifi::RadioSettings
Radio settings the running Wi-Fi driver holds, read back from it rather than from the configuration a session asked for. More about kleidos::platform::wifi::RadioSettings
struct kleidos::platform::wifi::Protocols
The 802.11 generations one interface offers. More about kleidos::platform::wifi::Protocols
struct kleidos::platform::wifi::PhyCalibration
Where this build and this boot got the PHY's RF calibration. More about kleidos::platform::wifi::PhyCalibration
struct kleidos::platform::wifi::PhySettings
The PHY and MAC posture under a session's RadioSettings: the band each interface occupies, the generations it offers, whether the station sleeps, and the calibration behind the radio. More about kleidos::platform::wifi::PhySettings
class kleidos::platform::wifi::WifiConfigScrubber
Wipes a stack-local wifi_config_t when the scope that built it ends. More about kleidos::platform::wifi::WifiConfigScrubber
struct kleidos::platform::wifi::BssPin
Which access point of the target network to join, if the caller cares. More about kleidos::platform::wifi::BssPin
struct kleidos::platform::wifi::MacPin
Which address the station presents to the network, if the caller cares. More about kleidos::platform::wifi::MacPin
struct kleidos::platform::wifi::StationConfig
Station connection configuration. More about kleidos::platform::wifi::StationConfig
struct kleidos::platform::wifi::StationSnapshot
Runtime snapshot of the station. More about kleidos::platform::wifi::StationSnapshot
class kleidos::platform::wifi::StationSession
RAII WiFi station session; stops the station on destruction. More about kleidos::platform::wifi::StationSession
struct kleidos::platform::wifi::ScanRecord
One access point discovered by scanNetworks. More about kleidos::platform::wifi::ScanRecord

Typedefs

usingkleidos::platform::http::RequestHandle
Opaque per-request handle.
usingkleidos::platform::http::DispatchHandler
Request callback.
usingkleidos::platform::sntp::AbortPredicate
Predicate polled during the wait; return true to abort the query early.
usingkleidos::platform::wifi::AccessPointEventCallback
AP event callback.

Enumerations

enum class kleidos::platform::http::Method : uint8_t { kleidos::platform::http::Method::Any , kleidos::platform::http::Method::Get , kleidos::platform::http::Method::Post , kleidos::platform::http::Method::Delete }
enum class kleidos::platform::http::HeaderPresence : uint8_t { kleidos::platform::http::HeaderPresence::Present , kleidos::platform::http::HeaderPresence::Absent , kleidos::platform::http::HeaderPresence::Unknown }
enum class kleidos::platform::sntp::QueryStatus : uint8_t { QueryStatus::Synced, QueryStatus::InvalidAddress, QueryStatus::Busy, QueryStatus::Timeout, QueryStatus::Aborted }
enum class kleidos::platform::net::ReceiveStatus : uint8_t { kleidos::platform::net::ReceiveStatus::Data , kleidos::platform::net::ReceiveStatus::Retry , kleidos::platform::net::ReceiveStatus::Closed , kleidos::platform::net::ReceiveStatus::Error }
Outcome of a receive attempt. More about kleidos::platform::net::ReceiveStatus
enum class kleidos::platform::wifi::AccessPointStatus : uint8_t { kleidos::platform::wifi::AccessPointStatus::Stopped, kleidos::platform::wifi::AccessPointStatus::Started, kleidos::platform::wifi::AccessPointStatus::NetifInitFailed, kleidos::platform::wifi::AccessPointStatus::EventLoopFailed, kleidos::platform::wifi::AccessPointStatus::NetifCreateFailed, kleidos::platform::wifi::AccessPointStatus::WifiInitFailed, kleidos::platform::wifi::AccessPointStatus::EventRegisterFailed, kleidos::platform::wifi::AccessPointStatus::StorageFailed, kleidos::platform::wifi::AccessPointStatus::ModeFailed, kleidos::platform::wifi::AccessPointStatus::ConfigFailed, kleidos::platform::wifi::AccessPointStatus::StartFailed, kleidos::platform::wifi::AccessPointStatus::BandwidthFailed }
enum class kleidos::platform::wifi::SecondaryChannel : uint8_t { kleidos::platform::wifi::SecondaryChannel::None , kleidos::platform::wifi::SecondaryChannel::Above , kleidos::platform::wifi::SecondaryChannel::Below }
Where a 40 MHz network's secondary channel lies relative to its primary one. More about kleidos::platform::wifi::SecondaryChannel
enum class kleidos::platform::wifi::SaePwe : uint8_t { kleidos::platform::wifi::SaePwe::Unspecified , kleidos::platform::wifi::SaePwe::HuntAndPeck , kleidos::platform::wifi::SaePwe::HashToElement , kleidos::platform::wifi::SaePwe::Both }
enum class kleidos::platform::wifi::PowerSave : uint8_t { kleidos::platform::wifi::PowerSave::None , kleidos::platform::wifi::PowerSave::MinModem , kleidos::platform::wifi::PowerSave::MaxModem , kleidos::platform::wifi::PowerSave::Unknown }
enum class kleidos::platform::wifi::ShutdownStatus : uint8_t { kleidos::platform::wifi::ShutdownStatus::Stopped , kleidos::platform::wifi::ShutdownStatus::AlreadyOff , kleidos::platform::wifi::ShutdownStatus::StopFailed , kleidos::platform::wifi::ShutdownStatus::DeinitFailed }
enum class kleidos::platform::wifi::StationBandwidth : uint8_t { kleidos::platform::wifi::StationBandwidth::Twenty , kleidos::platform::wifi::StationBandwidth::Forty }
enum class kleidos::platform::wifi::StationStatus : uint8_t { kleidos::platform::wifi::StationStatus::Stopped, kleidos::platform::wifi::StationStatus::Connected, kleidos::platform::wifi::StationStatus::NetifInitFailed, kleidos::platform::wifi::StationStatus::EventLoopFailed, kleidos::platform::wifi::StationStatus::NetifCreateFailed, kleidos::platform::wifi::StationStatus::WifiInitFailed, kleidos::platform::wifi::StationStatus::EventRegisterFailed, kleidos::platform::wifi::StationStatus::StorageFailed, kleidos::platform::wifi::StationStatus::ModeFailed, kleidos::platform::wifi::StationStatus::LocalMacFailed, kleidos::platform::wifi::StationStatus::ConfigFailed, kleidos::platform::wifi::StationStatus::StartFailed, kleidos::platform::wifi::StationStatus::ConnectFailed, kleidos::platform::wifi::StationStatus::IpTimeout }
enum class kleidos::platform::wifi::StationAuth : uint8_t { kleidos::platform::wifi::StationAuth::Open, kleidos::platform::wifi::StationAuth::Wep, kleidos::platform::wifi::StationAuth::WpaPsk, kleidos::platform::wifi::StationAuth::Wpa2Psk, kleidos::platform::wifi::StationAuth::Wpa3Psk, kleidos::platform::wifi::StationAuth::Enterprise, kleidos::platform::wifi::StationAuth::Other }

Functions

const char *kleidos::platform::http::methodName (Method method)
Return a human-readable name for an HTTP method.
constexpr boolkleidos::platform::net::isLiteralIpv4 (const char *text)
True when text is exactly a literal dotted-quad IPv4 address.
constexpr boolkleidos::platform::net::ipv4FromMappedIpv6 (std::span< const uint8_t, kIpv6AddressBytes > ipv6, uint32_t &outNetOrder)
Extract the IPv4 address from an IPv4-mapped IPv6 address.
QueryStatuskleidos::platform::sntp::queryTime (const char *serverIpv4, uint32_t timeoutMs, int64_t &epochOut, AbortPredicate shouldAbort=nullptr)
Query the current UTC time from one NTP server given by literal IPv4.
const char *kleidos::platform::sntp::queryStatusName (QueryStatus status)
Return a compact lowercase label for a QueryStatus value.
uint32_tkleidos::platform::net::parseIpv4Address (const char *address)
Parse a dotted-decimal IPv4 string to a network-order uint32.
boolkleidos::platform::net::isInvalidIpv4Address (uint32_t address)
True when an IPv4 address value indicates a parse failure.
const char *kleidos::platform::wifi::accessPointStatusName (AccessPointStatus status)
Return a human-readable name for an AccessPointStatus value.
constexpr uint64_tkleidos::platform::wifi::networkLoad (int8_t rssi)
Load one network adds to a channel it overlaps.
constexpr boolkleidos::platform::wifi::overlaps (const ChannelObservation &observation, uint8_t channel)
Whether a network's band overlaps a 20 MHz candidate channel.
constexpr uint64_tkleidos::platform::wifi::channelLoad (uint8_t channel, std::span< const ChannelObservation > observations)
Load the surveyed networks put on channel.
constexpr const char *kleidos::platform::wifi::secondaryChannelName (SecondaryChannel secondary)
Short name for where a network's secondary 20 MHz sits.
constexpr uint8_tkleidos::platform::wifi::leastLoadedChannel (std::span< const ChannelObservation > observations)
The candidate channel the surveyed networks load least.
boolkleidos::platform::wifi::applyMaxTxPower (int8_t qdbm)
Set the transmit power ceiling of the Wi-Fi bring-up in progress.
boolkleidos::platform::wifi::readRadioSettings (RadioSettings &out)
Read the radio settings the running Wi-Fi driver holds.
const char *kleidos::platform::wifi::saePweName (SaePwe pwe)
Return a short name for an SaePwe value.
boolkleidos::platform::wifi::readPhySettings (PhySettings &out)
Read the PHY and MAC posture the chip is running.
const char *kleidos::platform::wifi::powerSaveName (PowerSave mode)
Return a short name for a PowerSave value.
const char *kleidos::platform::wifi::calibrationModeName (uint8_t mode)
Return a short name for a PhyCalibration::mode value.
ShutdownStatuskleidos::platform::wifi::stopAndDeinit ()
Stop WiFi and de-initialize the driver stack.
boolkleidos::platform::wifi::releaseEventLoop ()
Delete ESP-IDF's default event loop once the Wi-Fi driver is off.
boolkleidos::platform::wifi::driverInitialized ()
Whether the Wi-Fi driver is initialized.
const char *kleidos::platform::wifi::shutdownStatusName (ShutdownStatus status)
Return a human-readable name for a ShutdownStatus value.
template<size_t N>
boolkleidos::platform::wifi::copyDriverField (uint8_t(&field)[N], const char *text)
Copy text into a fixed-size driver field, whole or not at all.
SecondaryChannelkleidos::platform::wifi::secondaryFrom (wifi_second_chan_t second)
Map the driver's secondary-channel position onto SecondaryChannel.
wifi_second_chan_tkleidos::platform::wifi::driverSecondaryFor (SecondaryChannel secondary)
Map SecondaryChannel onto the driver's secondary-channel value.
const char *kleidos::platform::wifi::stationStatusName (StationStatus status)
Return a human-readable name for a StationStatus value.
size_tkleidos::platform::wifi::scanNetworks (ScanRecord *out, size_t capacity)
Blocking one-shot scan for nearby access points (STA mode).
const char *kleidos::platform::wifi::stationAuthName (StationAuth auth)
Return a compact lowercase label for a StationAuth value.

Variables

constexpr size_tkleidos::platform::net::kIpv4TextMaxLen
Longest dotted-quad text: "255.255.255.255" (15 chars, excluding the NUL).
constexpr size_tkleidos::platform::net::kIpv6AddressBytes
Bytes in an IPv6 address.
constexpr size_tkleidos::platform::net::kIpv4AddressBytes
Bytes in an IPv4 address.
constexpr std::array< uint8_t, kIpv6AddressBytes - kIpv4AddressBytes >kleidos::platform::net::kIpv4MappedPrefix
Leading bytes of every IPv4-mapped IPv6 address (the ::ffff:0:0/96 prefix).
constexpr uint8_tkleidos::platform::wifi::kIpAddressTextLength
Buffer size for a dotted IPv4 string.
constexpr uint8_tkleidos::platform::wifi::kSurveyChannel
constexpr int8_tkleidos::platform::wifi::kDefaultMaxTxPowerQdbm
constexpr std::array< uint8_t, 3 >kleidos::platform::wifi::kAccessPointChannels
constexpr uint8_tkleidos::platform::wifi::kFallbackAccessPointChannel
Channel taken when no survey is available.
constexpr intkleidos::platform::wifi::kHalfBandChannels
constexpr intkleidos::platform::wifi::kSecondaryOffsetChannels
Channels from a 40 MHz network's primary to the center of its secondary.
constexpr intkleidos::platform::wifi::kLoadFloorDbm
Received power at and below which a network adds the least load, dBm.
constexpr intkleidos::platform::wifi::kLoadCeilingDbm
Received power at and above which a network adds the most load, dBm.
constexpr intkleidos::platform::wifi::kDbPerDoubling
dB per doubling of a network's load: 3 dB doubles the power.
constexpr uint8_tkleidos::platform::wifi::kCountryCodeTextLength
Characters of a country code, two letters plus the terminator.
constexpr int8_tkleidos::platform::wifi::kFullTxPowerQdbm
constexpr uint8_tkleidos::platform::wifi::kPhyVersionTextLength
Characters of the PHY library's version string, with room to spare.
constexpr uint8_tkleidos::platform::wifi::kStationIpTextLength
constexpr size_tkleidos::platform::wifi::kPassphraseTextLength
constexpr size_tkleidos::platform::wifi::kBssidBytes
Length of a 802.11 basic service set identifier (the access point's MAC).
constexpr size_tkleidos::platform::wifi::kScanSsidTextLength
Buffer size for a NUL-terminated SSID (802.11 max 32 bytes + NUL).
constexpr size_tkleidos::platform::wifi::kScanMaxResults
Maximum access points returned by scanNetworks.

Request inspection

const char *kleidos::platform::http::requestUri (RequestHandle request)
Return the request URI string.
Methodkleidos::platform::http::requestMethod (RequestHandle request)
Return the request method.
size_tkleidos::platform::http::requestContentLength (RequestHandle request)
Return the declared Content-Length of the request body.
size_tkleidos::platform::http::requestHeaderValueLength (RequestHandle request, const char *name)
Return the length of a request header value.
HeaderPresencekleidos::platform::http::requestHeaderPresence (RequestHandle request, const char *name)
Whether the request carries header name at all.
boolkleidos::platform::http::requestHeaderValue (RequestHandle request, const char *name, char *output, size_t outputLength)
Copy a request header value into output.
intkleidos::platform::http::receive (RequestHandle request, void *output, size_t outputLength)
Read body bytes from the request.
boolkleidos::platform::http::isReceiveTimeout (int receiveResult)
True when receive() returned a timeout result.
intkleidos::platform::http::requestSocketFd (RequestHandle request)
Return the underlying socket file descriptor for a request.
uint32_tkleidos::platform::http::requestPeerIpv4 (RequestHandle request)
Return the peer IPv4 address for a request.

Response building

boolkleidos::platform::http::setResponseStatus (RequestHandle request, const char *statusText)
Set the HTTP response status line.
boolkleidos::platform::http::setResponseType (RequestHandle request, const char *contentType)
Set the Content-Type header.
boolkleidos::platform::http::setResponseHeader (RequestHandle request, const char *name, const char *value)
Add a response header.
boolkleidos::platform::http::sendResponse (RequestHandle request, const void *data, size_t length)
Send the response body.
boolkleidos::platform::http::sendResponseChunk (RequestHandle request, const void *data, size_t length)
Send one chunk of a chunked (streaming) response.

Native test seam

voidkleidos::platform::http::setTestBackend (const TestBackend *backend)
Install a host-test backend for the request/response free functions.

Back to the top

Enumeration Type Documentation

AccessPointStatus #

enum class kleidos::platform::wifi::AccessPointStatus : uint8_t

Access point start/error status.

Value Meaning
Stopped AP is not running (initial state and after stop()).
Started AP started successfully.
NetifInitFailed esp_netif_init() failed.
EventLoopFailed Default event loop creation failed.
NetifCreateFailed AP netif allocation failed.
WifiInitFailed WiFi driver init failed.
EventRegisterFailed WiFi event handler registration failed.
StorageFailed WiFi storage configuration failed.
ModeFailed Setting AP mode failed.
ConfigFailed The SSID or password does not fit the driver, or applying the AP config failed.
StartFailed Starting WiFi failed.
BandwidthFailed The driver refused the 40 MHz width AccessPointConfig::secondary asked for.
Enumerator
Stopped 

Not running.

Started 

Running.

NetifInitFailed 

netif init failed.

EventLoopFailed 

Event loop creation failed.

NetifCreateFailed 

AP netif creation failed.

WifiInitFailed 

WiFi driver init failed.

EventRegisterFailed 

Event handler registration failed.

StorageFailed 

WiFi storage configuration failed.

ModeFailed 

Setting AP mode failed.

ConfigFailed 

SSID/password too long, or applying AP config failed.

StartFailed 

Starting WiFi failed.

BandwidthFailed 

The driver refused the 40 MHz width asked for.

HeaderPresence #

enum class kleidos::platform::http::HeaderPresence : uint8_t

Whether a request carries a header, as the transport answers.

Value Meaning
Present The request carries the header; its value may be empty.
Absent The request carries no such header.
Unknown The transport could not say (no request, or one it does not hold).
Enumerator
Present 

Carried, possibly with an empty value.

Absent 

Not carried.

Unknown 

The transport could not say.

Method #

enum class kleidos::platform::http::Method : uint8_t

HTTP request method.

Value Meaning
Any Wildcard — accepts any HTTP method (used by handlers that branch internally).
Get HTTP GET.
Post HTTP POST.
Delete HTTP DELETE.
Enumerator
Any 

Match any method.

Get 

GET.

Post 

POST.

Delete 

DELETE.

PowerSave #

enum class kleidos::platform::wifi::PowerSave : uint8_t

Whether and how a station sleeps between its access point's beacons.

Value Meaning
None The receiver stays on; what every Kleidos station session asks for.
MinModem The station wakes for each DTIM beacon.
MaxModem The station wakes on its own longer listen interval.
Unknown The driver reported something else.
Enumerator
None 

Receiver always on.

MinModem 

Wakes for every DTIM beacon.

MaxModem 

Wakes on a longer listen interval.

Unknown 

Anything else.

QueryStatus #

enum class kleidos::platform::sntp::QueryStatus : uint8_t

Result of a one-shot SNTP query.

Value Meaning
Synced A server response arrived; the epoch output is valid.
InvalidAddress The server string did not parse as a literal IPv4.
Busy Another query is already in flight.
Timeout No response within the configured window.
Aborted The abort predicate returned true mid-wait.
Enumerator
Synced 

Response received; epoch output valid.

InvalidAddress 

Not a literal IPv4 address.

Busy 

A query is already running.

Timeout 

No server response before the deadline.

Aborted 

Cancelled by the abort predicate.

ReceiveStatus #

enum class kleidos::platform::net::ReceiveStatus : uint8_t

Outcome of a receive attempt.

Enumerator
Data 

A datagram was received.

Retry 

No data yet; retry (timeout/would-block).

Closed 

Socket was closed.

Error 

Receive failed.

SaePwe #

enum class kleidos::platform::wifi::SaePwe : uint8_t

SAE password-element derivation an access point accepts.

Value Meaning
Unspecified The driver's default.
HuntAndPeck The legacy hunting-and-pecking derivation only.
HashToElement Hash-to-element (H2E) only.
Both Either derivation.
Enumerator
Unspecified 

Driver default.

HuntAndPeck 

Hunting-and-pecking only.

HashToElement 

Hash-to-element only.

Both 

Either derivation.

SecondaryChannel #

enum class kleidos::platform::wifi::SecondaryChannel : uint8_t

Where a 40 MHz network's secondary channel lies relative to its primary one.

Enumerator
None 

A 20 MHz network.

Above 

The secondary 20 MHz sits above the primary.

Below 

The secondary 20 MHz sits below the primary.

ShutdownStatus #

enum class kleidos::platform::wifi::ShutdownStatus : uint8_t

Result of stopAndDeinit().

Value Meaning
Stopped WiFi was running, was stopped, and was de-initialized.
AlreadyOff The driver was not initialized when the call ran.
StopFailed esp_wifi_stop() returned an error other than NOT-INIT / NOT-STARTED.
DeinitFailed esp_wifi_deinit() returned an error.
Enumerator
Stopped 

WiFi stopped and de-initialized.

AlreadyOff 

WiFi was already off.

StopFailed 

Stopping WiFi failed.

DeinitFailed 

De-initializing WiFi failed.

StationAuth #

enum class kleidos::platform::wifi::StationAuth : uint8_t

Coarse authentication class of a scanned access point.

Collapses the esp_wifi authmode zoo into the classes Kleidos cares about: whether a PSK join is possible and which family protects it.

Enumerator
Open 

No authentication (joinable without a passphrase).

Wep 

Legacy WEP (not supported for joining).

WpaPsk 

WPA-PSK.

Wpa2Psk 

WPA2-PSK (incl. WPA/WPA2 mixed).

Wpa3Psk 

WPA3-SAE (incl. WPA2/WPA3 mixed).

Enterprise 

802.1X enterprise (not supported for joining).

Other 

Anything else / unknown.

StationBandwidth #

enum class kleidos::platform::wifi::StationBandwidth : uint8_t

How wide a channel the station offers to use.

A station negotiates its width with the access point: left at the driver's own default it accepts a 40 MHz network's secondary half, and the driver configures the PHY for both halves before the authentication exchange. The width is therefore stated on every join rather than inherited, as the access point's is.

Twenty is the default because 20 MHz is what every shipping station session needs – the clock sync is a handful of packets – and what Espressif recommends on a crowded channel. It is a posture, not a remedy for a join that fails. Forty is asked for by the debug-only QA video stream alone, the one station consumer whose job is throughput.

Enumerator
Twenty 

20 MHz: the station never takes a network's secondary half.

Forty 

40 MHz where the network offers it (the driver's own default).

StationStatus #

enum class kleidos::platform::wifi::StationStatus : uint8_t

Station start/error status.

Value Meaning
Stopped STA is not running (initial state and after stop()).
Connected Joined the network and obtained an IP.
NetifInitFailed esp_netif_init() failed.
EventLoopFailed Default event loop creation failed.
NetifCreateFailed STA netif allocation failed.
WifiInitFailed WiFi driver init failed.
EventRegisterFailed Event handler registration failed.
StorageFailed WiFi storage configuration failed.
ModeFailed Setting STA mode failed.
LocalMacFailed The driver refused the address StationConfig::localMac named.
ConfigFailed The SSID or passphrase does not fit the driver, or applying the STA config failed.
StartFailed Starting WiFi failed.
ConnectFailed esp_wifi_connect() returned an error.
IpTimeout No IP lease within the configured timeout.
Enumerator
Stopped 

Not running.

Connected 

Connected with an IP.

NetifInitFailed 

netif init failed.

EventLoopFailed 

Event loop creation failed.

NetifCreateFailed 

STA netif creation failed.

WifiInitFailed 

WiFi driver init failed.

EventRegisterFailed 

Event handler registration failed.

StorageFailed 

WiFi storage configuration failed.

ModeFailed 

Setting STA mode failed.

LocalMacFailed 

The driver refused the pinned station address.

ConfigFailed 

SSID/passphrase too long, or applying STA config failed.

StartFailed 

Starting WiFi failed.

ConnectFailed 

esp_wifi_connect() failed.

IpTimeout 

No DHCP lease before timeout.

Back to the top

Function Documentation

accessPointStatusName() #

const char * kleidos::platform::wifi::accessPointStatusName(AccessPointStatus status)

Return a human-readable name for an AccessPointStatus value.

Parameters
NameMeaning
statusStatus enum value to name.
Returns
Pointer to a static string.

applyMaxTxPower() #

bool kleidos::platform::wifi::applyMaxTxPower(int8_t qdbm)

Set the transmit power ceiling of the Wi-Fi bring-up in progress.

The driver keeps the last ceiling it was given through esp_wifi_deinit(), so every bring-up states its own once esp_wifi_start() has returned: the access point its arm's-length cap, a station session and a scan kFullTxPowerQdbm. A station or a scan that left it alone after the access point ran would transmit at the access point's cap until the next reset. A refusal is logged; the radio then keeps the ceiling it had.

Parameters
NameMeaning
qdbmCeiling in 0.25 dBm steps, within [8, 84].
Return values
ValueMeaning
trueThe driver took the ceiling.
falseThe driver refused it (not started, out of range), or on the native build.

calibrationModeName() #

const char * kleidos::platform::wifi::calibrationModeName(uint8_t mode)

Return a short name for a PhyCalibration::mode value.

Parameters
NameMeaning
modeESP-IDF's calibration-mode number.
Returns
"partial", "none", "full" or "unknown".

channelLoad() #

uint64_t kleidos::platform::wifi::channelLoad(uint8_t channel, std::span< const ChannelObservation > observations)
constexpr

Load the surveyed networks put on channel.

Parameters
NameMeaning
channelCandidate channel.
observationsNetworks the survey heard.
Returns
Sum of networkLoad over the networks that overlap channel.

copyDriverField() #

template<size_t N>
bool kleidos::platform::wifi::copyDriverField(uint8_t(&) field[N], const char * text)

Copy text into a fixed-size driver field, whole or not at all.

The field is zeroed first, so a shorter value is zero-padded and a value of exactly N bytes fills the field without a terminator, which is how the driver reads a full-length SSID or a hex PSK.

Template Parameters
NameMeaning
NSize of the field in bytes.
Parameters
NameDirectionMeaning
fieldoutDriver field (an SSID or password member of the record).
textinNUL-terminated value; nullptr reads as empty.
Return values
ValueMeaning
truetext fit and was copied.
falsetext is longer than N bytes; the field is left zeroed.

driverInitialized() #

bool kleidos::platform::wifi::driverInitialized()

Whether the Wi-Fi driver is initialized.

True from esp_wifi_init() until esp_wifi_deinit(), whichever mode the driver runs and whether or not it is started: the span during which the Wi-Fi MAC and radio depend on the clocks the driver was brought up on. The CPU clock control (system.h) asks the driver the same question itself, since it sits below this facade.

Return values
ValueMeaning
trueThe driver is initialized.
falseThe driver is not initialized, or on the native build.

driverSecondaryFor() #

wifi_second_chan_t kleidos::platform::wifi::driverSecondaryFor(SecondaryChannel secondary)
inline

Map SecondaryChannel onto the driver's secondary-channel value.

Parameters
NameMeaning
secondaryWhere the secondary 20 MHz should sit.
Returns
The driver's spelling of it.

ipv4FromMappedIpv6() #

bool kleidos::platform::net::ipv4FromMappedIpv6(std::span< const uint8_t, kIpv6AddressBytes > ipv6, uint32_t & outNetOrder)
constexpr

Extract the IPv4 address from an IPv4-mapped IPv6 address.

Accepts only the ::ffff:0:0/96 prefix. Every other IPv6 address — a native IPv6 peer, the unspecified address, the deprecated IPv4-compatible form ::a.b.c.d — is refused, so a caller that treats a refusal as "unknown peer" fails closed.

Parameters
NameDirectionMeaning
ipv6inThe 16 address bytes, in wire (network) order.
outNetOrderoutThe IPv4 address in network byte order (the layout of sockaddr_in::sin_addr.s_addr). Written only on success; left untouched otherwise.
Return values
ValueMeaning
trueipv6 is IPv4-mapped; outNetOrder holds its IPv4 address.
falseipv6 is not IPv4-mapped.

isInvalidIpv4Address() #

bool kleidos::platform::net::isInvalidIpv4Address(uint32_t address)

True when an IPv4 address value indicates a parse failure.

Parameters
NameDirectionMeaning
addressinNetwork-byte-order value returned by parseIpv4Address().
Return values
ValueMeaning
trueaddress equals INADDR_NONE (parse failure marker).
falseaddress is a valid IPv4 value.

isLiteralIpv4() #

bool kleidos::platform::net::isLiteralIpv4(const char * text)
constexpr

True when text is exactly a literal dotted-quad IPv4 address.

Strict: exactly four decimal octets 0..255 separated by single dots, digits and dots only. Anything else — letters (hostnames), empty octets, leading '+'/'-', a fifth octet, IPv6 colons, ports, whitespace — is rejected. Leading zeros are accepted ("010.0.0.1" reads as 10.0.0.1, matching the lwIP parser the SNTP facade re-checks with).

Parameters
NameDirectionMeaning
textinNUL-terminated candidate string (nullptr is rejected).
Return values
ValueMeaning
truetext is a literal IPv4 address.
falseNot a plain dotted quad; must not reach any resolver.

isReceiveTimeout() #

bool kleidos::platform::http::isReceiveTimeout(int receiveResult)

True when receive() returned a timeout result.

Parameters
NameMeaning
receiveResultReturn value of receive().
Return values
ValueMeaning
truereceiveResult indicates a timeout.
falsereceiveResult indicates success or a non-timeout error.

leastLoadedChannel() #

uint8_t kleidos::platform::wifi::leastLoadedChannel(std::span< const ChannelObservation > observations)
constexpr

The candidate channel the surveyed networks load least.

A tie goes to the earlier candidate in kAccessPointChannels, so an empty survey keeps kFallbackAccessPointChannel.

Parameters
NameMeaning
observationsNetworks the survey heard.
Returns
One of kAccessPointChannels.

methodName() #

const char * kleidos::platform::http::methodName(Method method)

Return a human-readable name for an HTTP method.

Parameters
NameMeaning
methodHTTP method enum value.
Returns
Static string such as "GET", "POST", or "DELETE".

networkLoad() #

uint64_t kleidos::platform::wifi::networkLoad(int8_t rssi)
constexpr

Load one network adds to a channel it overlaps.

Its power above kLoadFloorDbm, doubled every kDbPerDoubling dB: a network 3 dB stronger counts twice as much, as its power does.

Parameters
NameMeaning
rssiReceived power, dBm.
Returns
Load, at least 1.

overlaps() #

bool kleidos::platform::wifi::overlaps(const ChannelObservation & observation, uint8_t channel)
constexpr

Whether a network's band overlaps a 20 MHz candidate channel.

Bands are compared on the 5 MHz channel grid: a 20 MHz band spans its center plus or minus kHalfBandChannels, a 40 MHz one its primary and secondary 20 MHz halves.

Parameters
NameMeaning
observationThe network.
channelCandidate channel.
Return values
ValueMeaning
trueTheir bands overlap.

parseIpv4Address() #

uint32_t kleidos::platform::net::parseIpv4Address(const char * address)

Parse a dotted-decimal IPv4 string to a network-order uint32.

Parameters
NameDirectionMeaning
addressinNUL-terminated IPv4 string (e.g., "192.168.4.1").
Returns
Network-byte-order IPv4 address, or INADDR_NONE on parse failure.

powerSaveName() #

const char * kleidos::platform::wifi::powerSaveName(PowerSave mode)

Return a short name for a PowerSave value.

Parameters
NameMeaning
modePosture to name.
Returns
"none", "min_modem", "max_modem" or "unknown".

queryStatusName() #

const char * kleidos::platform::sntp::queryStatusName(QueryStatus status)

Return a compact lowercase label for a QueryStatus value.

Parameters
NameMeaning
statusStatus enum value to name.
Returns
Pointer to a static string.

queryTime() #

QueryStatus kleidos::platform::sntp::queryTime(const char * serverIpv4, uint32_t timeoutMs, int64_t & epochOut, AbortPredicate shouldAbort = nullptr)

Query the current UTC time from one NTP server given by literal IPv4.

Parses serverIpv4 with the lwIP address parser (no DNS lookup on any path), runs the SNTP app in poll mode until the first response or the deadline, and ALWAYS stops the SNTP app before returning. The system clock is not modified.

Parameters
NameDirectionMeaning
serverIpv4inLiteral dotted-quad server address (e.g. "162.159.200.1").
timeoutMsinMaximum wait for a server response.
epochOutoutReceives the server UTC time as UNIX seconds on Synced; untouched otherwise.
shouldAbortinOptional predicate polled every wait slice; return true to abort early (may be nullptr).
Returns
The query outcome (see QueryStatus).

readPhySettings() #

bool kleidos::platform::wifi::readPhySettings(PhySettings & out)

Read the PHY and MAC posture the chip is running.

The calibration half is filled either way; the rest needs the driver initialized, since channel, width, generations and power save are the driver's to report.

Parameters
NameDirectionMeaning
outoutSnapshot; reset to its defaults first.
Return values
ValueMeaning
trueSomething was filled: on device, always.
falseOn the native build, where there is no PHY.

readRadioSettings() #

bool kleidos::platform::wifi::readRadioSettings(RadioSettings & out)

Read the radio settings the running Wi-Fi driver holds.

Channel, country (code, allowed channel range, whether a station follows its access point's), transmit power ceiling and, with the access point on, its beacon interval and WPA3 / PMF configuration: what the driver applied, which can be compared between two boards on the air.

Parameters
NameDirectionMeaning
outoutSnapshot; reset to its defaults first.
Return values
ValueMeaning
trueThe driver is initialized; out holds its settings.
falseThe driver is off, or on the native build.

receive() #

int kleidos::platform::http::receive(RequestHandle request, void * output, size_t outputLength)

Read body bytes from the request.

Parameters
NameMeaning
requestOpaque per-request handle.
outputDestination buffer.
outputLengthMaximum bytes to read.
Returns
Bytes read on success; negative on error (use isReceiveTimeout() to distinguish).

releaseEventLoop() #

bool kleidos::platform::wifi::releaseEventLoop()

Delete ESP-IDF's default event loop once the Wi-Fi driver is off.

Every Wi-Fi bring-up (the access point, a station session, a one-shot scan) creates the default event loop and its sys_evt task. Each one's teardown calls this last, after its netif is destroyed, so the loop and its task go with the radio. lwIP's tcpip task stays: ESP-IDF cannot de-initialize lwIP (esp_netif_deinit answers ESP_ERR_NOT_SUPPORTED), so the first bring-up of a boot starts it for the rest of that boot.

Left alone while the driver is still initialized: a bring-up that owns the loop is then still running.

Return values
ValueMeaning
trueThe loop was deleted, or none was running.
falseThe driver is still initialized, or the deletion failed.

requestContentLength() #

size_t kleidos::platform::http::requestContentLength(RequestHandle request)

Return the declared Content-Length of the request body.

Parameters
NameMeaning
requestOpaque per-request handle.
Returns
Content-Length in bytes; 0 when absent.

requestHeaderPresence() #

HeaderPresence kleidos::platform::http::requestHeaderPresence(RequestHandle request, const char * name)

Whether the request carries header name at all.

Tells a header sent empty from one not sent, which requestHeaderValueLength reports alike as 0. Copies nothing of the value.

Parameters
NameMeaning
requestOpaque per-request handle.
nameHeader field name (case-insensitive).
Returns
Present, Absent, or Unknown when the transport could not say.

requestHeaderValue() #

bool kleidos::platform::http::requestHeaderValue(RequestHandle request, const char * name, char * output, size_t outputLength)

Copy a request header value into output.

Parameters
NameMeaning
requestOpaque per-request handle.
nameHeader field name.
outputDestination buffer.
outputLengthBuffer size in bytes.
Returns
True when the header was found and the value fits in the buffer.

requestHeaderValueLength() #

size_t kleidos::platform::http::requestHeaderValueLength(RequestHandle request, const char * name)

Return the length of a request header value.

Parameters
NameMeaning
requestOpaque per-request handle.
nameHeader field name (case-insensitive).
Returns
Header value length in bytes; 0 if not present.

requestMethod() #

Method kleidos::platform::http::requestMethod(RequestHandle request)

Return the request method.

Parameters
NameMeaning
requestOpaque per-request handle.
Return values
ValueMeaning
Method::AnyWildcard method (no parsed value).
Method::GetHTTP GET.
Method::PostHTTP POST.
Method::DeleteHTTP DELETE.

requestPeerIpv4() #

uint32_t kleidos::platform::http::requestPeerIpv4(RequestHandle request)

Return the peer IPv4 address for a request.

The server's listening socket is dual-stack whenever lwIP is built with IPv6, so getpeername() reports an IPv4 client as the IPv4-mapped IPv6 address ::ffff:a.b.c.d; the IPv4 address is taken from its last four bytes (kleidos::platform::net::ipv4FromMappedIpv6). An IPv4-only build reports AF_INET and the address is read as is.

Parameters
NameMeaning
requestOpaque per-request handle.
Returns
IPv4 address in network byte order, or 0 when the peer has none to report: the socket is gone, getpeername() fails, or the peer is a native IPv6 client. Callers keying state by peer must treat 0 as one shared "unknown peer", never as a distinct client.

requestSocketFd() #

int kleidos::platform::http::requestSocketFd(RequestHandle request)

Return the underlying socket file descriptor for a request.

Parameters
NameMeaning
requestOpaque per-request handle.
Returns
Socket fd; negative on error.

requestUri() #

const char * kleidos::platform::http::requestUri(RequestHandle request)

Return the request URI string.

Parameters
NameMeaning
requestOpaque per-request handle.
Returns
NUL-terminated URI string; valid for the lifetime of the request.

saePweName() #

const char * kleidos::platform::wifi::saePweName(SaePwe pwe)

Return a short name for an SaePwe value.

Parameters
NameMeaning
pweDerivation to name.
Returns
"unspecified", "hnp", "h2e" or "both".

scanNetworks() #

size_t kleidos::platform::wifi::scanNetworks(ScanRecord * out, size_t capacity)

Blocking one-shot scan for nearby access points (STA mode).

Brings the WiFi driver up in station mode just for the scan and ALWAYS tears it back down before returning (via stopAndDeinit, then the scan netif and releaseEventLoop), so the radio and the event loop's task are off on every exit path; only lwIP's tcpip task stays (see releaseEventLoop). Hidden-SSID entries are skipped. Results are ordered strongest-RSSI first.

Warning
Do not call while a StationSession, the SoftAP admin portal, or BLE is active — the caller owns the radio-exclusivity policy.
Note
Blocks the calling task for the duration of the scan (typically 1.5–3 s). Call from a services/console task, never the render loop.
Parameters
NameDirectionMeaning
outoutDestination array for the discovered access points.
capacityinCapacity of out in records.
Returns
Number of records written to out (0 on failure or empty air).

secondaryChannelName() #

const char * kleidos::platform::wifi::secondaryChannelName(SecondaryChannel secondary)
constexpr

Short name for where a network's secondary 20 MHz sits.

Parameters
NameMeaning
secondaryThe position to name.
Returns
"20" for a 20 MHz network, "40u" for a secondary above the primary, "40d" for one below.

secondaryFrom() #

SecondaryChannel kleidos::platform::wifi::secondaryFrom(wifi_second_chan_t second)
inline

Map the driver's secondary-channel position onto SecondaryChannel.

Parameters
NameMeaning
secondThe driver's value.
Returns
SecondaryChannel::Above or Below for a 40 MHz network, None for a 20 MHz one.

sendResponse() #

bool kleidos::platform::http::sendResponse(RequestHandle request, const void * data, size_t length)

Send the response body.

Parameters
NameMeaning
requestOpaque per-request handle.
dataPointer to the body data.
lengthNumber of bytes to send.
Return values
ValueMeaning
trueResponse body was sent.
falseServer reported a send error.

sendResponseChunk() #

bool kleidos::platform::http::sendResponseChunk(RequestHandle request, const void * data, size_t length)

Send one chunk of a chunked (streaming) response.

Wraps httpd_resp_send_chunk. The first call begins a chunked transfer; subsequent calls append more bytes. Terminate the stream with a final call of length 0 (sends the zero-length terminating chunk). Used by the debug-only QA video stream to push framebuffer frames continuously.

Parameters
NameMeaning
requestOpaque per-request handle.
dataPointer to the chunk bytes (may be null when length is 0).
lengthNumber of bytes in this chunk; 0 terminates the response.
Return values
ValueMeaning
trueChunk was sent (or the stream was terminated).
falseServer reported a send error (e.g. the peer disconnected).

setResponseHeader() #

bool kleidos::platform::http::setResponseHeader(RequestHandle request, const char * name, const char * value)

Add a response header.

Parameters
NameMeaning
requestOpaque per-request handle.
nameHeader field name.
valueHeader field value.
Return values
ValueMeaning
trueHeader was added to the response.
falseServer reported an error adding the header.

setResponseStatus() #

bool kleidos::platform::http::setResponseStatus(RequestHandle request, const char * statusText)

Set the HTTP response status line.

Parameters
NameMeaning
requestOpaque per-request handle.
statusTextStatus string, e.g., "200 OK" or "404 Not Found".
Return values
ValueMeaning
trueStatus line was set on the response.
falseServer reported an error setting the status.

setResponseType() #

bool kleidos::platform::http::setResponseType(RequestHandle request, const char * contentType)

Set the Content-Type header.

Parameters
NameMeaning
requestOpaque per-request handle.
contentTypeMIME type string.
Return values
ValueMeaning
trueContent-Type was set on the response.
falseServer reported an error setting the header.

setTestBackend() #

void kleidos::platform::http::setTestBackend(const TestBackend * backend)

Install a host-test backend for the request/response free functions.

Parameters
NameMeaning
backendPointer to a backend that outlives the test; nullptr clears it.

shutdownStatusName() #

const char * kleidos::platform::wifi::shutdownStatusName(ShutdownStatus status)

Return a human-readable name for a ShutdownStatus value.

Parameters
NameMeaning
statusStatus enum value to name.
Returns
Pointer to a static string.

stationAuthName() #

const char * kleidos::platform::wifi::stationAuthName(StationAuth auth)

Return a compact lowercase label for a StationAuth value.

Parameters
NameMeaning
authAuthentication class to name.
Returns
Pointer to a static string ("open", "wep", "wpa", "wpa2", "wpa3", "enterprise" or "other").

stationStatusName() #

const char * kleidos::platform::wifi::stationStatusName(StationStatus status)

Return a human-readable name for a StationStatus value.

Parameters
NameMeaning
statusStatus enum value to name.
Returns
Pointer to a static string.

stopAndDeinit() #

ShutdownStatus kleidos::platform::wifi::stopAndDeinit()

Stop WiFi and de-initialize the driver stack.

Return values
ValueMeaning
ShutdownStatus::StoppedWiFi was running, was stopped, and de-initialized.
ShutdownStatus::AlreadyOffWiFi was not initialized when called.
ShutdownStatus::StopFailedesp_wifi_stop() returned an unexpected error.
ShutdownStatus::DeinitFailedesp_wifi_deinit() returned an error.

Back to the top

Variable Documentation

kAccessPointChannels #

std::array<uint8_t, 3> kleidos::platform::wifi::kAccessPointChannels
constexpr

The candidates: the three 2.4 GHz channels that do not overlap one another, allowed in every regulatory domain, including ESP-IDF's world safe mode.

kDefaultMaxTxPowerQdbm #

int8_t kleidos::platform::wifi::kDefaultMaxTxPowerQdbm
constexpr

Default SoftAP max TX power in 0.25 dBm steps (11 dBm). Caps the RF radius to an arm's-length admin use case and lowers TX current; range is [8, 84].

kFullTxPowerQdbm #

int8_t kleidos::platform::wifi::kFullTxPowerQdbm
constexpr

Transmit power ceiling of a station session or a scan, 0.25 dBm steps: the PHY's 20 dBm maximum, the ceiling the driver starts at after a reset.

kHalfBandChannels #

int kleidos::platform::wifi::kHalfBandChannels
constexpr

Channels, of 5 MHz each, a 20 MHz band spans beyond its center on either side short of the next band that no longer overlaps it.

kPassphraseTextLength #

size_t kleidos::platform::wifi::kPassphraseTextLength
constexpr

Buffer size for a NUL-terminated station passphrase: the driver's 64-byte field (a 63-character WPA passphrase or a 64-digit hex PSK) plus the NUL.

kStationIpTextLength #

uint8_t kleidos::platform::wifi::kStationIpTextLength
constexpr

Buffer size for a dotted IPv4 string.

kSurveyChannel #

uint8_t kleidos::platform::wifi::kSurveyChannel
constexpr

AccessPointConfig::channel value that has the session choose the channel: it surveys the networks around it and takes the least loaded of 1, 6 and 11.

Back to the top