ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
physical.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - 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, the interface registry, and live egress reporting.
7 *
8 * The IETF host model's lowest layer is the link layer (RFC 1122 sec 1.1.3): it names no physical
9 * layer, and the media themselves are IEEE (802.3 wired, 802.11 wireless). What the IETF defines
10 * for this layer is what the calls below carry - IP over Ethernet (RFC 894), IP over IEEE 802
11 * networks (RFC 1042), the outbound route an interface is chosen by (RFC 1122 sec 3.3.1), IPv6
12 * stateless address autoconfiguration (RFC 4862) and the address forms it produces (RFC 4291
13 * sec 2.5.4 global unicast, sec 2.5.6 link-local), dual IP layer operation (RFC 4213 sec 2), and
14 * the 6-octet hardware address ARP resolves to (RFC 826 sec "Packet format", ar$hln = 6).
15 *
16 * Bring-up runs in the backend the PROTOCORE_VENDOR_* selector compiled
17 * (test/core_setup/physical/<vendor>/), reached through the seam declared below. Failover between
18 * interfaces belongs to the stack, which reselects the default route when a link drops, so this
19 * layer adds no manager and no tick. It reads the live default route each time it is asked which
20 * interface carries outbound traffic (RFC 1122 sec 3.3.1.2 gateway selection).
21 *
22 * @author Douglas Quigg (dstroy0)
23 * @date 2026
24 */
25
26#ifndef PROTOCORE_PHYSICAL_H
27#define PROTOCORE_PHYSICAL_H
28
29#include "config/platform/platform.h" // PROTOCORE_VENDOR_* selector (picks the L1 backend)
30#include "shared/ip/ip.h"
31
32#include "protocore_config.h" // protocore_if_kind
33
34// There is always a physical (L1) backend to drive. The bring-up (radio, Ethernet PHY, the stack's
35// interface access) lives beside its owner - test/core_setup/physical/<vendor>/ for silicon,
36// test/core_setup/hal/host/physical/ everywhere else, which is a link that can actually be up and
37// answers from it. Every build compiles one of the two, so a link is driven for real on a host as
38// well as on a part.
39#ifndef PROTOCORE_PHYSICAL_HAS_BACKEND
40#define PROTOCORE_PHYSICAL_HAS_BACKEND 1
41#endif
42
43// A backend may be written in C++ (it drives the platform's own WiFi and Ethernet objects), so the
44// seam below carries C linkage and links against either language unchanged.
45EMBED_BEGIN_DECLS
46
47// ---------------------------------------------------------------------------
48// The L1 backend seam. Not the caller API: every name here is defined once per build, by the
49// backend the PROTOCORE_VENDOR_* selector compiled or by the software backend beside it. A caller
50// reaches layer 1 through @ref Physical and never through a seam name.
51// ---------------------------------------------------------------------------
52
53/**
54 * @brief Start an 802.11 station join to an access point.
55 *
56 * Returns immediately; association and address configuration are asynchronous. Poll wifi_ready().
57 *
58 * @param ssid network SSID, null-terminated (IEEE 802.11-2020 9.4.2.2, at most 32 octets).
59 * @param password WPA2 passphrase, null-terminated (IEEE 802.11i, not an IETF protocol).
60 */
61embed_bool init_wifi_physical(const char *ssid, const char *password);
62
63/** @brief True when the station link is associated and holds an IPv4 address. */
64embed_bool wifi_ready(void);
65
66/**
67 * @brief Start the radio in station mode without associating.
68 *
69 * Runs the PHY with no IP link, for peer-to-peer radio messaging and promiscuous capture. Pins the
70 * radio to @p channel (1..14) when non-zero; 0 leaves the channel to a capture layer that sets its
71 * own (services/radio/promisc).
72 */
73embed_bool init_wifi_radio_physical(uint8_t channel);
74
75/**
76 * @brief Start a softAP, with AP and station coexistence so a station link runs alongside it.
77 *
78 * @param ssid softAP SSID, null-terminated.
79 * @param password softAP passphrase, null-terminated; >= 8 characters for WPA2, "" for an open AP.
80 */
81embed_bool init_wifi_ap_physical(const char *ssid, const char *password);
82
83/**
84 * @brief Start a wired Ethernet link (PROTOCORE_ENABLE_ETHERNET).
85 *
86 * The PHY pins, type and clock come from the platform's own Ethernet build flags. Returns
87 * immediately; poll eth_ready(). A wired route classifies as PROTOCORE_IF_ETH (RFC 894 framing).
88 */
89embed_bool init_eth_physical(void);
90
91/** @brief True when the wired link is up and holds an IPv4 address. */
92embed_bool eth_ready(void);
93
94/**
95 * @brief Enable dual IP layer operation on the WiFi interface (RFC 4213 sec 2, PROTOCORE_ENABLE_IPV6).
96 *
97 * The interface autoconfigures a link-local address (RFC 4291 sec 2.5.6) and, when a router
98 * advertises a prefix, a global unicast address (RFC 4862). Returns immediately; poll
99 * protocore_ipv6_ready().
100 */
101embed_bool init_ipv6_physical(void);
102
103/**
104 * @brief The interface's global unicast IPv6 address (RFC 4291 sec 2.5.4).
105 * @param[out] out receives the address with family PROTOCORE_IP_V6 when true is returned.
106 */
108
109/** @brief True once a global unicast IPv6 address is configured. */
110embed_bool protocore_ipv6_ready(void);
111
112/**
113 * @brief Which interface carries outbound traffic (RFC 1122 sec 3.3.1.2).
114 *
115 * Reads the live default route, so it reflects the current state after any failover the stack
116 * performed. PROTOCORE_IF_ETH / PROTOCORE_IF_WIFI_STA / PROTOCORE_IF_WIFI_AP, or PROTOCORE_IF_ANY
117 * when no route is up.
118 */
119protocore_if_kind protocore_net_egress(void);
120
121/** @brief IPv4 of the current default-route interface, network byte order (RFC 791 app. B), 0 if none. */
123
124/** @brief softAP IPv4, network byte order, or 0 when the softAP is down. */
125uint32_t protocore_net_ap_ip(void);
126
127/** @brief Station link RSSI in dBm, or 0 when not associated. */
129
130/**
131 * @brief Copy the 802.11 station hardware address into @p out (6 octets, RFC 826 ar$hln = 6).
132 *
133 * The station address, valid once the WiFi driver is up; a wired-only part reads back zeros. For
134 * the address in use on the wire right now whatever the link type, use protocore_net_egress_mac().
135 */
136embed_bool protocore_net_mac(uint8_t out[6]);
137
138/**
139 * @brief Copy the hardware address of the current default-route interface into @p out (6 octets).
140 *
141 * Link-neutral: the Ethernet PHY's address on a wired route, the station address on a wireless one,
142 * whichever interface protocore_net_egress_ip() reports. False when no route is up.
143 */
144embed_bool protocore_net_egress_mac(uint8_t out[6]);
145
146/**
147 * @brief Copy the associated SSID into @p out, null-terminated.
148 * @return SSID length in octets, or 0 when not associated or @p cap is 0.
149 */
150size_t protocore_net_ssid(char *out, size_t cap);
151
152/** @brief Station channel (1..14), or 0 when not associated. */
154
155/**
156 * @brief Map a live default-route IPv4 to the interface it belongs to.
157 *
158 * Defined in physical.c, so it answers the same on every backend: an egress IP equal to the station
159 * or softAP IP is that WiFi interface, any other live IP is a wired route, 0 is no route. A backend
160 * calls it from its own egress readout; a caller reaches it as PhysicalNs::classify_ip.
161 *
162 * @param egress_ip default-route IPv4, network byte order, 0 if none.
163 * @param sta_ip station IPv4, network byte order, 0 if not associated.
164 * @param ap_ip softAP IPv4, network byte order, 0 if the softAP is down.
165 */
166protocore_if_kind protocore_net_classify_ip(uint32_t egress_ip, uint32_t sta_ip, uint32_t ap_ip);
167
168/* --------------------------------------------------------------------------------------------
169 * Radio control (L1 capability contract)
170 *
171 * Power save and monitor mode are properties of the radio, so they belong to the layer that owns
172 * the radio. These names carry no platform vocabulary; the flavoring happens at the edge, in
173 * test/core_setup/physical/<vendor>/. Each one reports failure when the selected backend has no radio
174 * (PROTOCORE_PHYSICAL_HAS_BACKEND == 0), so callers build and run headless on any target. They are
175 * reached through PhysicalNs::radio, which is radio_power.h's handle.
176 * ------------------------------------------------------------------------------------------ */
177
178/** @brief Radio power-save mode, in the library's own vocabulary (IEEE 802.11 power management). */
179EMBED_ENUM_BYTE(protocore_phy_ps,
180 PROTOCORE_PHY_PS_NONE = 0, ///< Radio always on: lowest latency, highest average draw.
181 PROTOCORE_PHY_PS_MIN_MODEM = 1, ///< Wake on every DTIM beacon.
182 PROTOCORE_PHY_PS_MAX_MODEM = 2, ///< Wake on a longer listen interval: lowest draw, highest latency.
183);
184
185/**
186 * @brief One received frame, delivered in neutral terms.
187 *
188 * Not the platform's received-packet struct, so no platform type reaches a service. The FCS is
189 * already stripped.
190 *
191 * @param frame frame octets, valid only for the duration of the call.
192 * @param len frame length in octets, FCS excluded.
193 * @param rssi received signal strength, dBm.
194 * @param channel channel the frame arrived on.
195 */
196typedef void (*protocore_phy_frame_fn)(const uint8_t *frame, uint16_t len, int8_t rssi, uint8_t channel);
197
198/** @brief Apply a power-save mode. False when there is no radio backend. */
199embed_bool protocore_phy_ps_set(protocore_phy_ps mode);
200
201/** @brief The active power-save mode (PROTOCORE_PHY_PS_NONE when unsupported). */
202protocore_phy_ps protocore_phy_ps_get(void);
203
204/**
205 * @brief Cap transmit power.
206 * @param dbm maximum transmit power in whole dBm; the backend converts to its own unit.
207 */
208embed_bool protocore_phy_tx_power_set(int8_t dbm);
209
210/** @brief Enter monitor mode on @p channel, delivering frames to @p cb. */
212
213/** @brief Retune monitor mode to @p channel. */
215
216/** @brief Leave monitor mode. */
218
219#if PROTOCORE_PHYSICAL_HAS_BACKEND && !PROTOCORE_VENDOR_ESP
220/**
221 * @brief Hand one captured frame up to the armed monitor sink, the way the radio does.
222 *
223 * The mock backend's receive path: with no silicon to put the part in monitor mode, this is where
224 * a frame enters, so a caller above is driven by a real delivery rather than by its own input.
225 *
226 * @return false when monitor mode is not running or the frame is empty.
227 */
228embed_bool protocore_phy_mock_deliver(const uint8_t *frame, uint16_t len, int8_t rssi, uint8_t channel);
229#endif
230
231// ---------------------------------------------------------------------------
232// The interfaces this device has. An interface is an id, a kind, and the callback that puts octets
233// on the wire - all three physical facts, which is why the registry is here and not in the
234// forwarding plane that merely chooses between them. A device can carry several, of mixed kind: two
235// Ethernet ports, a station and a softAP, a bus bridged to a socket.
236// ---------------------------------------------------------------------------
237
238// protocore_if_kind is protocore_config.h's: one vocabulary for the kind and the filter.
239
240/**
241 * @brief Put @p len octets on interface @p if_id.
242 * @return true if the interface accepted them; false drops.
243 */
244typedef embed_bool (*protocore_if_send_fn)(uint8_t if_id, const uint8_t *data, uint16_t len, void *ctx);
245
246/** @brief No interface. Reported by PhysicalNs::iface_at for an empty row. */
247#define PROTOCORE_IF_NONE (-1)
248
249/** @brief What an 802.11 bring-up takes: the station join, the softAP, and the radio-only start. */
250typedef struct
251{
252 const char *ssid; ///< SSID a join or a softAP names (IEEE 802.11-2020 9.4.2.2, <= 32 octets)
253 const char *password; ///< WPA2 passphrase; "" opens the softAP
254 uint8_t channel; ///< channel a radio-only start pins (1..14); 0 leaves it to a capture layer
256
257/** @brief Where a readout copies to. */
258typedef struct
259{
260 uint8_t *mac; ///< receives a 6-octet hardware address (RFC 826 ar$hln = 6)
261 char *text; ///< receives the SSID, null-terminated
262 size_t cap; ///< how much room text has
263 protocore_ip *ip6; ///< receives the global unicast IPv6 address (RFC 4291 sec 2.5.4)
265
266/** @brief What the egress classifier judges: the live route and the two WiFi addresses. */
267typedef struct
268{
269 uint32_t egress_ip; ///< default-route IPv4, network byte order (RFC 791 app. B); 0 if no route
270 uint32_t sta_ip; ///< station IPv4, network byte order; 0 if not associated
271 uint32_t ap_ip; ///< softAP IPv4, network byte order; 0 if the softAP is down
273
274/** @brief What names an interface in the registry, and the frame a send puts on it. */
275typedef struct
276{
277 protocore_if_send_fn send; ///< how octets reach the interface being registered
278 void *ctx; ///< what that callback is handed back
279 const uint8_t *data; ///< the frame a send puts on the wire
280 uint16_t len; ///< its length in octets
281 protocore_if_kind kind; ///< what the interface being registered is
282 uint8_t id; ///< the interface a call acts on
283 uint8_t i; ///< the registry row a lookup names
285
286/**
287 * @brief Layer 1: link bring-up, what the live link reports, and the interfaces this device has.
288 *
289 * A caller sets the members a call takes, invokes it through ::Physical, and reads the outcome off
290 * the same handle. Bring-up and readout run in the compiled backend; the registry rows and the
291 * egress classifier are this module's own, held behind @ref internal.
292 *
293 * @var PhysicalNs::wifi what an 802.11 bring-up takes
294 * @var PhysicalNs::read where a readout copies to
295 * @var PhysicalNs::route what the egress classifier judges (RFC 1122 sec 3.3.1)
296 * @var PhysicalNs::iface what names an interface, and the frame a send puts on it
297 * @var PhysicalNs::ok a call's true/false outcome
298 * @var PhysicalNs::if_kind the interface kind a call reports
299 * @var PhysicalNs::u32 an IPv4 a call reports, network byte order
300 * @var PhysicalNs::n the SSID length a readout wrote
301 * @var PhysicalNs::u8 a channel or a registry count
302 * @var PhysicalNs::i8 the RSSI a readout reports, dBm
303 * @var PhysicalNs::i16 the interface id a registry row holds, or PROTOCORE_IF_NONE
304 * @var PhysicalNs::wifi_init start the station join to the named AP
305 * @var PhysicalNs::wifi_ready whether the station link is associated with an address
306 * @var PhysicalNs::wifi_radio_init start the radio with no IP link, pinned to a channel
307 * @var PhysicalNs::wifi_ap_init start the softAP alongside the station
308 * @var PhysicalNs::wifi_ssid the associated SSID
309 * @var PhysicalNs::wifi_channel the station channel
310 * @var PhysicalNs::wifi_rssi the station RSSI
311 * @var PhysicalNs::wifi_ap_ip the softAP IPv4
312 * @var PhysicalNs::wifi_mac the station hardware address (RFC 826 ar$hln = 6)
313 * @var PhysicalNs::eth_init start the wired link (RFC 894)
314 * @var PhysicalNs::eth_ready whether the wired link is up with an address
315 * @var PhysicalNs::ip6_init enable dual IP layer operation (RFC 4213 sec 2)
316 * @var PhysicalNs::ip6_global the global unicast IPv6 address (RFC 4291 sec 2.5.4)
317 * @var PhysicalNs::ip6_ready whether a global unicast address is configured (RFC 4862)
318 * @var PhysicalNs::egress which interface carries outbound traffic (RFC 1122 sec 3.3.1.2)
319 * @var PhysicalNs::egress_ip that interface's IPv4
320 * @var PhysicalNs::egress_mac that interface's hardware address
321 * @var PhysicalNs::classify_ip map a route's IPv4 to the interface it belongs to
322 * @var PhysicalNs::iface_add register an interface and how to send on it
323 * @var PhysicalNs::iface_reset forget every interface
324 * @var PhysicalNs::iface_present whether the named id is registered
325 * @var PhysicalNs::iface_kind what the named id is
326 * @var PhysicalNs::iface_at the id held in a registry row
327 * @var PhysicalNs::iface_count registered interfaces
328 * @var PhysicalNs::iface_send put the held frame on the named id
329 * @var PhysicalNs::radio the radio handle, radio_power.h's
330 */
331typedef struct
332{
337 embed_bool ok;
338 protocore_if_kind if_kind;
339 uint32_t u32;
340 size_t n;
341 uint8_t u8;
342 int8_t i8;
343 int16_t i16;
345
346/** @brief The operands and the outcome. */
348
349/** @brief The entries. */
350typedef struct
351{
352 void (*const wifi_init)(const uint8_t *work);
353 void (*const wifi_ready)(const uint8_t *work);
354 void (*const wifi_radio_init)(const uint8_t *work);
355 void (*const wifi_ap_init)(const uint8_t *work);
356 void (*const wifi_ssid)(const uint8_t *work);
357 void (*const wifi_channel)(const uint8_t *work);
358 void (*const wifi_rssi)(const uint8_t *work);
359 void (*const wifi_ap_ip)(const uint8_t *work);
360 void (*const wifi_mac)(const uint8_t *work);
361 void (*const eth_init)(const uint8_t *work);
362 void (*const eth_ready)(const uint8_t *work);
363 void (*const ip6_init)(const uint8_t *work);
364 void (*const ip6_global)(const uint8_t *work);
365 void (*const ip6_ready)(const uint8_t *work);
366 void (*const egress)(const uint8_t *work);
367 void (*const egress_ip)(const uint8_t *work);
368 void (*const egress_mac)(const uint8_t *work);
369 void (*const classify_ip)(const uint8_t *work);
370 void (*const iface_add)(uint8_t *work);
371 void (*const iface_reset)(uint8_t *work);
372 void (*const iface_present)(uint8_t *work);
373 void (*const iface_kind)(uint8_t *work);
374 void (*const iface_at)(uint8_t *work);
375 void (*const iface_count)(uint8_t *work);
376 void (*const iface_send)(uint8_t *work);
377} PhysicalNs;
378
379// What the table binds, defined once in the .c and taking one parameter each: everything
380// else an entry needs is an operand in PhysicalV or a region of the borrow at a fixed offset.
381void protocore_physical_wifi_init(const uint8_t *work);
382void protocore_physical_wifi_ready(const uint8_t *work);
383void protocore_physical_wifi_radio_init(const uint8_t *work);
384void protocore_physical_wifi_ap_init(const uint8_t *work);
385void protocore_physical_wifi_ssid(const uint8_t *work);
386void protocore_physical_wifi_channel(const uint8_t *work);
387void protocore_physical_wifi_rssi(const uint8_t *work);
388void protocore_physical_wifi_ap_ip(const uint8_t *work);
389void protocore_physical_wifi_mac(const uint8_t *work);
390void protocore_physical_eth_init(const uint8_t *work);
391void protocore_physical_eth_ready(const uint8_t *work);
392void protocore_physical_ip6_init(const uint8_t *work);
393void protocore_physical_ip6_global(const uint8_t *work);
394void protocore_physical_ip6_ready(const uint8_t *work);
395void protocore_physical_egress(const uint8_t *work);
396void protocore_physical_egress_ip(const uint8_t *work);
397void protocore_physical_egress_mac(const uint8_t *work);
398void protocore_physical_classify_ip(const uint8_t *work);
403void protocore_physical_iface_at(uint8_t *work);
406
407// `static const`, initialised HERE rather than `extern` against a definition in the .c: a
408// const object whose initializer every translation unit can see is a COMPILE-TIME FACT, so
409// `Physical.wifi_init(work)` resolves to a named function and becomes a DIRECT call. An extern table
410// leaves the call indirect and the symbol live at every level, -O2 -flto included.
411static const PhysicalNs Physical __attribute__((unused)) = {
412 .wifi_init = protocore_physical_wifi_init,
413 .wifi_ready = protocore_physical_wifi_ready,
414 .wifi_radio_init = protocore_physical_wifi_radio_init,
415 .wifi_ap_init = protocore_physical_wifi_ap_init,
416 .wifi_ssid = protocore_physical_wifi_ssid,
417 .wifi_channel = protocore_physical_wifi_channel,
418 .wifi_rssi = protocore_physical_wifi_rssi,
419 .wifi_ap_ip = protocore_physical_wifi_ap_ip,
420 .wifi_mac = protocore_physical_wifi_mac,
421 .eth_init = protocore_physical_eth_init,
422 .eth_ready = protocore_physical_eth_ready,
423 .ip6_init = protocore_physical_ip6_init,
424 .ip6_global = protocore_physical_ip6_global,
425 .ip6_ready = protocore_physical_ip6_ready,
427 .egress_ip = protocore_physical_egress_ip,
428 .egress_mac = protocore_physical_egress_mac,
429 .classify_ip = protocore_physical_classify_ip,
430 .iface_add = protocore_physical_iface_add,
431 .iface_reset = protocore_physical_iface_reset,
432 .iface_present = protocore_physical_iface_present,
433 .iface_kind = protocore_physical_iface_kind,
434 .iface_at = protocore_physical_iface_at,
435 .iface_count = protocore_physical_iface_count,
436 .iface_send = protocore_physical_iface_send,
437};
438
439/**
440 * @brief The PROTOCORE_PHYSICAL_BORROW bytes this module's state lives in.
441 *
442 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where
443 * that borrow comes from. Taken once from the end of the pool, which no mark and no release
444 * walks, so the state lasts the life of the program.
445 *
446 * @return the span.
447 */
449
450/** @brief Physical.wifi_ready as an expression, for a bring-up loop to wait on. */
451EMBED_INLINE embed_bool protocore_physical_wifi_up(void)
452{
453 Physical.wifi_ready(protocore_physical_span());
454 return PhysicalV.ok;
455}
456
457/** @brief Physical.eth_ready as an expression, for a bring-up loop to wait on. */
458EMBED_INLINE embed_bool protocore_physical_eth_up(void)
459{
460 Physical.eth_ready(protocore_physical_span());
461 return PhysicalV.ok;
462}
463
464/** @brief Physical.egress_ip as an expression: the address a sketch prints once its link is up. */
465EMBED_INLINE uint32_t protocore_physical_egress_ipv4(void)
466{
467 Physical.egress_ip(protocore_physical_span());
468 return PhysicalV.u32;
469}
470
471/** @brief Physical.egress as an expression: the kind of interface the default route leaves on. */
472EMBED_INLINE protocore_if_kind protocore_physical_egress_kind(void)
473{
474 Physical.egress(protocore_physical_span());
475 return PhysicalV.if_kind;
476}
477
478/** @brief Physical.wifi_rssi as an expression: the station's received signal strength, in dBm. */
479EMBED_INLINE int8_t protocore_physical_rssi(void)
480{
481 Physical.wifi_rssi(protocore_physical_span());
482 return PhysicalV.i8;
483}
484
485/** @brief Physical.wifi_channel as an expression: the 802.11 channel the radio is on. */
486EMBED_INLINE uint8_t protocore_physical_channel(void)
487{
488 Physical.wifi_channel(protocore_physical_span());
489 return PhysicalV.u8;
490}
491
492/** @brief Physical.wifi_ap_ip as an expression: the softAP IPv4, network byte order; 0 if it is down. */
493EMBED_INLINE uint32_t protocore_physical_ap_ipv4(void)
494{
495 Physical.wifi_ap_ip(protocore_physical_span());
496 return PhysicalV.u32;
497}
498
499EMBED_END_DECLS
500
501#endif
Layer 3 (Network) - a family-tagged IP address (IPv4 or IPv6) with RFC-faithful text parsing,...
EMBED_INLINE embed_bool protocore_physical_eth_up(void)
Physical.eth_ready as an expression, for a bring-up loop to wait on.
Definition physical.h:458
EMBED_INLINE uint32_t protocore_physical_egress_ipv4(void)
Physical.egress_ip as an expression: the address a sketch prints once its link is up.
Definition physical.h:465
void protocore_physical_egress_mac(const uint8_t *work)
EMBED_INLINE embed_bool protocore_physical_wifi_up(void)
Physical.wifi_ready as an expression, for a bring-up loop to wait on.
Definition physical.h:451
embed_bool(* protocore_if_send_fn)(uint8_t if_id, const uint8_t *data, uint16_t len, void *ctx)
Put len octets on interface if_id.
Definition physical.h:244
protocore_if_kind protocore_net_classify_ip(uint32_t egress_ip, uint32_t sta_ip, uint32_t ap_ip)
Map a live default-route IPv4 to the interface it belongs to.
void protocore_physical_ip6_init(const uint8_t *work)
uint8_t protocore_net_channel(void)
Station channel (1..14), or 0 when not associated.
embed_bool init_ipv6_physical(void)
Enable dual IP layer operation on the WiFi interface (RFC 4213 sec 2, PROTOCORE_ENABLE_IPV6).
EMBED_INLINE uint8_t protocore_physical_channel(void)
Physical.wifi_channel as an expression: the 802.11 channel the radio is on.
Definition physical.h:486
void protocore_physical_classify_ip(const uint8_t *work)
EMBED_ENUM_BYTE(protocore_phy_ps, PROTOCORE_PHY_PS_NONE=0, PROTOCORE_PHY_PS_MIN_MODEM=1, PROTOCORE_PHY_PS_MAX_MODEM=2,)
Radio power-save mode, in the library's own vocabulary (IEEE 802.11 power management).
EMBED_BEGIN_DECLS embed_bool init_wifi_physical(const char *ssid, const char *password)
Start an 802.11 station join to an access point.
void protocore_physical_iface_kind(uint8_t *work)
int8_t protocore_net_rssi(void)
Station link RSSI in dBm, or 0 when not associated.
PhysicalVars PhysicalV
The operands and the outcome.
void protocore_physical_iface_reset(uint8_t *work)
embed_bool protocore_phy_monitor_begin(uint8_t channel, protocore_phy_frame_fn cb)
Enter monitor mode on channel, delivering frames to cb.
void protocore_physical_egress(const uint8_t *work)
void protocore_physical_wifi_rssi(const uint8_t *work)
size_t protocore_net_ssid(char *out, size_t cap)
Copy the associated SSID into out, null-terminated.
void protocore_physical_wifi_ready(const uint8_t *work)
uint8_t * protocore_physical_span(void)
The PROTOCORE_PHYSICAL_BORROW bytes this module's state lives in.
uint32_t protocore_net_egress_ip(void)
IPv4 of the current default-route interface, network byte order (RFC 791 app. B), 0 if none.
embed_bool init_wifi_ap_physical(const char *ssid, const char *password)
Start a softAP, with AP and station coexistence so a station link runs alongside it.
void protocore_physical_wifi_init(const uint8_t *work)
void protocore_physical_iface_add(uint8_t *work)
embed_bool wifi_ready(void)
True when the station link is associated and holds an IPv4 address.
void protocore_physical_iface_count(uint8_t *work)
EMBED_INLINE uint32_t protocore_physical_ap_ipv4(void)
Physical.wifi_ap_ip as an expression: the softAP IPv4, network byte order; 0 if it is down.
Definition physical.h:493
embed_bool protocore_net_mac(uint8_t out[6])
Copy the 802.11 station hardware address into out (6 octets, RFC 826 ar$hln = 6).
embed_bool eth_ready(void)
True when the wired link is up and holds an IPv4 address.
embed_bool protocore_phy_tx_power_set(int8_t dbm)
Cap transmit power.
protocore_if_kind protocore_net_egress(void)
Which interface carries outbound traffic (RFC 1122 sec 3.3.1.2).
void protocore_phy_monitor_set_channel(uint8_t channel)
Retune monitor mode to channel.
uint32_t protocore_net_ap_ip(void)
softAP IPv4, network byte order, or 0 when the softAP is down.
void protocore_physical_ip6_ready(const uint8_t *work)
void protocore_physical_wifi_ap_init(const uint8_t *work)
void protocore_physical_eth_init(const uint8_t *work)
EMBED_INLINE int8_t protocore_physical_rssi(void)
Physical.wifi_rssi as an expression: the station's received signal strength, in dBm.
Definition physical.h:479
protocore_phy_ps protocore_phy_ps_get(void)
The active power-save mode (PROTOCORE_PHY_PS_NONE when unsupported).
embed_bool init_wifi_radio_physical(uint8_t channel)
Start the radio in station mode without associating.
void protocore_physical_wifi_mac(const uint8_t *work)
void protocore_physical_wifi_radio_init(const uint8_t *work)
void protocore_physical_wifi_ap_ip(const uint8_t *work)
void protocore_physical_iface_at(uint8_t *work)
embed_bool protocore_phy_ps_set(protocore_phy_ps mode)
Apply a power-save mode. False when there is no radio backend.
embed_bool net_global_ipv6(protocore_ip *out)
The interface's global unicast IPv6 address (RFC 4291 sec 2.5.4).
void protocore_physical_egress_ip(const uint8_t *work)
void protocore_physical_iface_send(uint8_t *work)
void protocore_physical_eth_ready(const uint8_t *work)
EMBED_INLINE protocore_if_kind protocore_physical_egress_kind(void)
Physical.egress as an expression: the kind of interface the default route leaves on.
Definition physical.h:472
void protocore_physical_ip6_global(const uint8_t *work)
void(* protocore_phy_frame_fn)(const uint8_t *frame, uint16_t len, int8_t rssi, uint8_t channel)
One received frame, delivered in neutral terms.
Definition physical.h:196
void protocore_physical_iface_present(uint8_t *work)
void protocore_phy_monitor_end(void)
Leave monitor mode.
void protocore_physical_wifi_channel(const uint8_t *work)
embed_bool protocore_ipv6_ready(void)
True once a global unicast IPv6 address is configured.
embed_bool init_eth_physical(void)
Start a wired Ethernet link (PROTOCORE_ENABLE_ETHERNET).
embed_bool protocore_net_egress_mac(uint8_t out[6])
Copy the hardware address of the current default-route interface into out (6 octets).
void protocore_physical_wifi_ssid(const uint8_t *work)
The platform contract: what the library asks of a target, in the library's own words.
What names an interface in the registry, and the frame a send puts on it.
Definition physical.h:276
uint8_t id
the interface a call acts on
Definition physical.h:282
const uint8_t * data
the frame a send puts on the wire
Definition physical.h:279
void * ctx
what that callback is handed back
Definition physical.h:278
uint16_t len
its length in octets
Definition physical.h:280
uint8_t i
the registry row a lookup names
Definition physical.h:283
protocore_if_send_fn send
how octets reach the interface being registered
Definition physical.h:277
protocore_if_kind kind
what the interface being registered is
Definition physical.h:281
The entries.
Definition physical.h:351
void(*const wifi_ssid)(const uint8_t *work)
Definition physical.h:356
void(*const iface_reset)(uint8_t *work)
Definition physical.h:371
void(*const iface_at)(uint8_t *work)
Definition physical.h:374
void(*const egress_mac)(const uint8_t *work)
Definition physical.h:368
void(*const iface_kind)(uint8_t *work)
Definition physical.h:373
void(*const wifi_ap_ip)(const uint8_t *work)
Definition physical.h:359
void(*const classify_ip)(const uint8_t *work)
Definition physical.h:369
void(*const wifi_rssi)(const uint8_t *work)
Definition physical.h:358
void(*const egress)(const uint8_t *work)
Definition physical.h:366
void(*const wifi_mac)(const uint8_t *work)
Definition physical.h:360
void(*const wifi_ready)(const uint8_t *work)
Definition physical.h:353
void(*const eth_ready)(const uint8_t *work)
Definition physical.h:362
void(*const iface_count)(uint8_t *work)
Definition physical.h:375
void(*const iface_add)(uint8_t *work)
Definition physical.h:370
void(*const wifi_init)(const uint8_t *work)
Definition physical.h:352
void(*const ip6_global)(const uint8_t *work)
Definition physical.h:364
void(*const ip6_init)(const uint8_t *work)
Definition physical.h:363
void(*const egress_ip)(const uint8_t *work)
Definition physical.h:367
void(*const wifi_ap_init)(const uint8_t *work)
Definition physical.h:355
void(*const eth_init)(const uint8_t *work)
Definition physical.h:361
void(*const wifi_channel)(const uint8_t *work)
Definition physical.h:357
void(*const wifi_radio_init)(const uint8_t *work)
Definition physical.h:354
void(*const ip6_ready)(const uint8_t *work)
Definition physical.h:365
void(*const iface_present)(uint8_t *work)
Definition physical.h:372
void(*const iface_send)(uint8_t *work)
Definition physical.h:376
Where a readout copies to.
Definition physical.h:259
uint8_t * mac
receives a 6-octet hardware address (RFC 826 ar$hln = 6)
Definition physical.h:260
size_t cap
how much room text has
Definition physical.h:262
protocore_ip * ip6
receives the global unicast IPv6 address (RFC 4291 sec 2.5.4)
Definition physical.h:263
char * text
receives the SSID, null-terminated
Definition physical.h:261
What the egress classifier judges: the live route and the two WiFi addresses.
Definition physical.h:268
uint32_t egress_ip
default-route IPv4, network byte order (RFC 791 app. B); 0 if no route
Definition physical.h:269
uint32_t ap_ip
softAP IPv4, network byte order; 0 if the softAP is down
Definition physical.h:271
uint32_t sta_ip
station IPv4, network byte order; 0 if not associated
Definition physical.h:270
int16_t i16
Definition physical.h:343
PhysicalWifiArgs wifi
Definition physical.h:333
embed_bool ok
Definition physical.h:337
int8_t i8
Definition physical.h:342
protocore_if_kind if_kind
Definition physical.h:338
uint8_t u8
Definition physical.h:341
PhysicalIfaceArgs iface
Definition physical.h:336
PhysicalReadArgs read
Definition physical.h:334
PhysicalRouteArgs route
Definition physical.h:335
uint32_t u32
Definition physical.h:339
What an 802.11 bring-up takes: the station join, the softAP, and the radio-only start.
Definition physical.h:251
uint8_t channel
channel a radio-only start pins (1..14); 0 leaves it to a capture layer
Definition physical.h:254
const char * ssid
SSID a join or a softAP names (IEEE 802.11-2020 9.4.2.2, <= 32 octets).
Definition physical.h:252
const char * password
WPA2 passphrase; "" opens the softAP.
Definition physical.h:253
A v4 or v6 address in network (big-endian) byte order.
Definition ip.h:54