DeterministicESPAsyncWebServer v6.27.1
Zero-allocation, bounded-execution async HTTP server for ESP32
Loading...
Searching...
No Matches
physical.h
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file physical.h
6 * @brief Layer 1 (Physical) - link bring-up and live egress-interface reporting.
7 *
8 * On ESP32 the "physical" link is the 802.11 radio (or a wired Ethernet PHY).
9 * WiFi station bring-up is a thin wrapper over the Arduino WiFi library. Failover
10 * between interfaces is owned by the stack itself (lwIP/esp_netif reselect the
11 * default route when a link drops) - this layer adds no manager and no polling
12 * tick; it only *reports* which interface currently carries outbound traffic via
13 * det_net_egress(), read on demand from the live default route so the answer is
14 * always current.
15 *
16 * @author Douglas Quigg (dstroy0)
17 * @date 2026
18 */
19
20#ifndef DETERMINISTICESPASYNCWEBSERVER_PHYSICAL_H
21#define DETERMINISTICESPASYNCWEBSERVER_PHYSICAL_H
22
23#include "ServerConfig.h" // DetIface
25#include <stdint.h>
26
27/**
28 * @brief Connect to a WiFi access point.
29 *
30 * Calls `WiFi.begin()` and returns immediately; it does not block waiting for
31 * association. Poll wifi_ready() to check link status.
32 *
33 * @param ssid Network SSID (null-terminated).
34 * @param password WPA2 passphrase (null-terminated).
35 * @return Always returns true (WiFi.begin() is fire-and-forget).
36 */
37bool init_wifi_physical(const char *ssid, const char *password);
38
39/** @brief True if the WiFi station link is up (associated + an IP is assigned). */
40bool wifi_ready();
41
42/**
43 * @brief Bring up a wired Ethernet link (DETWS_ENABLE_ETHERNET).
44 *
45 * A thin wrapper over the Arduino ETH library (`ETH.begin()`); the RMII PHY pins / type /
46 * clock come from the standard `ETH_PHY_*` build flags for your board. Returns immediately
47 * (bring-up is asynchronous); poll eth_ready(). The egress reporting already classifies a
48 * wired route as DetIface::DETIFACE_ETH, so the server accepts on the link once it has an IP.
49 *
50 * @return true if ETH.begin() started the driver; false if Ethernet is disabled at build
51 * time or the driver failed to start (and always false on host builds).
52 */
53bool init_eth_physical(void);
54
55/** @brief True if the Ethernet link is up and an IP is assigned. */
56bool eth_ready(void);
57
58/**
59 * @brief Enable IPv6 (dual-stack) on the Wi-Fi interface (DETWS_ENABLE_IPV6).
60 *
61 * Turns on IPv6 for the netif so it acquires a SLAAC link-local address and, if the network
62 * advertises a prefix, a global address. Returns immediately (address configuration is
63 * asynchronous); poll ipv6_ready(). The listeners already bind IPADDR_TYPE_ANY, so the server
64 * answers over IPv6 as soon as an address is up.
65 *
66 * @return true if IPv6 was enabled; false if disabled at build time or on host builds.
67 */
68bool init_ipv6_physical(void);
69
70/**
71 * @brief The interface's global (routable) IPv6 address, if it has one.
72 * @param[out] out receives the address (family DetIpFamily::DET_IP_V6) when true is returned.
73 * @return true if a valid global IPv6 address is assigned; false otherwise (incl. host builds).
74 */
75bool net_global_ipv6(DetIp *out);
76
77/** @brief True once the interface has a global IPv6 address (see net_global_ipv6()). */
78bool ipv6_ready(void);
79
80/**
81 * @brief Which interface currently carries outbound traffic.
82 *
83 * Reads the live lwIP default route, so it reflects the current state after any
84 * failover the stack performed - no polling, no cached state. Returns
85 * DetIface::DETIFACE_ETH / DetIface::DETIFACE_STA / DetIface::DETIFACE_AP, or DetIface::DETIFACE_ANY when no route is
86 * up (and on host builds).
87 */
89
90/** @brief IPv4 (network byte order) of the current egress interface, or 0 if none. */
91uint32_t det_net_egress_ip(void);
92
93/**
94 * @brief Classify an egress IPv4 against the WiFi station / softAP IPs (pure helper,
95 * exposed for unit testing).
96 *
97 * A live egress IP equal to the station or softAP IP is that WiFi interface; any
98 * other live IP is a wired (Ethernet) route; 0 is no route.
99 *
100 * @param egress_ip Current default-route IPv4 (network order), 0 if none.
101 * @param sta_ip WiFi station IPv4 (network order), 0 if not connected.
102 * @param ap_ip softAP IPv4 (network order), 0 if the softAP is not up.
103 */
104DetIface det_net_classify_ip(uint32_t egress_ip, uint32_t sta_ip, uint32_t ap_ip);
105
106#endif
User-facing configuration for DeterministicESPAsyncWebServer.
DetIface
Network interface a connection arrived on (for per-route filtering).
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing,...
uint32_t det_net_egress_ip(void)
IPv4 (network byte order) of the current egress interface, or 0 if none.
Definition physical.cpp:118
bool ipv6_ready(void)
True once the interface has a global IPv6 address (see net_global_ipv6()).
Definition physical.cpp:112
bool eth_ready(void)
True if the Ethernet link is up and an IP is assigned.
Definition physical.cpp:59
bool wifi_ready()
True if the WiFi station link is up (associated + an IP is assigned).
Definition physical.cpp:30
bool init_wifi_physical(const char *ssid, const char *password)
Connect to a WiFi access point.
Definition physical.cpp:24
bool net_global_ipv6(DetIp *out)
The interface's global (routable) IPv6 address, if it has one.
Definition physical.cpp:108
DetIface det_net_egress(void)
Which interface currently carries outbound traffic.
Definition physical.cpp:124
bool init_ipv6_physical(void)
Enable IPv6 (dual-stack) on the Wi-Fi interface (DETWS_ENABLE_IPV6).
Definition physical.cpp:104
bool init_eth_physical(void)
Bring up a wired Ethernet link (DETWS_ENABLE_ETHERNET).
Definition physical.cpp:55
DetIface det_net_classify_ip(uint32_t egress_ip, uint32_t sta_ip, uint32_t ap_ip)
Classify an egress IPv4 against the WiFi station / softAP IPs (pure helper, exposed for unit testing)...
Definition physical.cpp:176
A v4 or v6 address in network (big-endian) byte order.
Definition ip.h:52