ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
wifi_link.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 wifi_link.h
6 * @brief Layer 1 (Physical) - the 802.11 station link under the idemIP stack (PROTOCORE_ENABLE_IDEMIP).
7 *
8 * This module is the IdemIpPhyDriver of one Wi-Fi station. The stack module binds it as an interface
9 * with ::protocore_wifi_link_driver and the two buffer arrays of this module.
10 *
11 * The receive ring is software. The radio gives each frame to ::protocore_wifi_link_frame_receive in
12 * its own task. That call puts the frame into a free buffer of the ring. Where no buffer is free, the
13 * link drops the frame and counts it.
14 *
15 * The entry rx_claim gives the frames out in arrival order. The entry rx_release names the buffer that
16 * it gives back, and only that buffer becomes free again. A unit can thus keep a frame past later
17 * frames, and no refill lands on its buffer.
18 *
19 * The radio copies a transmit frame before its send returns. A transmit buffer is thus free again at
20 * the reap of the next tick.
21 *
22 * The radio is a seam: protocore_wifi_radio_start, protocore_wifi_radio_frame_send and
23 * protocore_wifi_radio_mac_read. On an ESP part, test/core_setup/hal/esp/esp_wifi_radio.c answers it
24 * with esp_wifi, and no esp_netif. Elsewhere the weak default of each one refuses.
25 *
26 * @author Douglas Quigg (dstroy0)
27 * @date 2026
28 */
29
30#ifndef PROTOCORE_WIFI_LINK_H
31#define PROTOCORE_WIFI_LINK_H
32
33#include "protocore_config.h" // the entry point: the enable gate below, and the widths
34
35#if PROTOCORE_ENABLE_IDEMIP
36
37#include "src/ethernet/phy.h" // IdemIpPhyDriver, the table that the stack binds
38
39EMBED_BEGIN_DECLS
40
41/**
42 * @brief What ::protocore_wifi_link_start takes: the network that the station joins.
43 *
44 * @var WifiLinkStartArgs::ssid the SSID, a string of 1 to 32 octets [BORROWS]
45 * @var WifiLinkStartArgs::password the passphrase, a string of 8 to 63 octets, or empty for an open network [BORROWS]
46 */
47typedef struct
48{
49 const char *ssid;
50 const char *password;
51} WifiLinkStartArgs;
52
53/**
54 * @brief One frame, as the radio gives it or takes it: an Ethernet II frame with no frame check sequence.
55 *
56 * @var WifiLinkFrameArgs::frame the first octet of the frame [BORROWS]
57 * @var WifiLinkFrameArgs::len octets in the frame
58 */
59typedef struct
60{
61 const uint8_t *frame;
62 size_t len;
63} WifiLinkFrameArgs;
64
65/**
66 * @brief What ::protocore_wifi_link_state_set takes.
67 *
68 * @var WifiLinkStateArgs::up EMBED_TRUE once the station joins its network, and EMBED_FALSE after it leaves
69 */
70typedef struct
71{
72 embed_bool up;
73} WifiLinkStateArgs;
74
75/**
76 * @brief Starts the radio as a station, and joins the network of @p args.
77 *
78 * @param[in] args The network [BORROWS].
79 * @return EMBED_TRUE where the radio started. The association comes later, through
80 * ::protocore_wifi_link_state_set.
81 */
82embed_bool protocore_wifi_link_start(const WifiLinkStartArgs *args);
83
84/**
85 * @brief Puts one received frame into a free buffer of the receive ring. The radio calls it in its own task.
86 *
87 * @param[in] args The frame [BORROWS]. The call copies it with memor, which needs the frame on a word boundary.
88 * @return EMBED_FALSE where the frame is not on a word boundary, where it is longer than
89 * IDEMIP_DMA_FRAME_MAX, or where no buffer is free. The link then drops the frame and counts it
90 * in ::protocore_wifi_link_dropped.
91 */
92embed_bool protocore_wifi_link_frame_receive(const WifiLinkFrameArgs *args);
93
94/**
95 * @brief Records whether the station is in its network. The radio calls it in its own task.
96 *
97 * @param[in] args The state [BORROWS].
98 */
99void protocore_wifi_link_state_set(const WifiLinkStateArgs *args);
100
101/** @brief The IdemIpPhyDriver of the station, for StackBindArgs::driver. */
102const IdemIpPhyDriver *protocore_wifi_link_driver(void);
103
104/** @brief The IDEMIP_RX_DESCRIPTORS receive buffers, for StackBindArgs::rx_base. */
105uint8_t *protocore_wifi_link_rx_base(void);
106
107/** @brief The IDEMIP_TX_DESCRIPTORS transmit buffers, for StackBindArgs::tx_base. */
108uint8_t *protocore_wifi_link_tx_base(void);
109
110/** @brief The frames that the receive ring dropped since the start. */
111uint32_t protocore_wifi_link_dropped(void);
112
113/**
114 * @brief The radio seam: starts the station and joins the network of @p args. The weak default refuses.
115 *
116 * @param[in] args The network [BORROWS].
117 * @return EMBED_TRUE where the radio started.
118 */
119embed_bool protocore_wifi_radio_start(const WifiLinkStartArgs *args);
120
121/**
122 * @brief The radio seam: sends one frame. The radio copies the frame before it returns. The weak default refuses.
123 *
124 * @param[in] args The frame [BORROWS].
125 * @return EMBED_TRUE where the radio took the frame.
126 */
127embed_bool protocore_wifi_radio_frame_send(const WifiLinkFrameArgs *args);
128
129/**
130 * @brief The radio seam: reads the hardware address of the station. The weak default refuses.
131 *
132 * @param[out] mac IDEMIP_MAC_LEN octets.
133 * @return EMBED_TRUE where @p mac holds the address.
134 */
135embed_bool protocore_wifi_radio_mac_read(uint8_t *mac);
136
137EMBED_END_DECLS
138
139#endif // PROTOCORE_ENABLE_IDEMIP
140
141#endif // PROTOCORE_WIFI_LINK_H