ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
wifi_hal_core.c
Go to the documentation of this file.
1
23
24#include <stdint.h>
25
26#include "ra8_err.h"
27#include "ra8_wifi.h"
28#include "wifi_hal_join.h"
29
31 "wifi_hal: PASS ra8_wifi joined the bench Wi-Fi and DHCP leased an address\r\n";
33 "wifi_hal: FAIL Wi-Fi join to a DHCP lease did not complete\r\n";
34
52static bool wifi_hal_settle(ra8_wifi_t* wifi, uint32_t budget)
53{
54 ra8_wifi_status_t st = {};
55 for (uint32_t i = 0U; i < budget; i++) {
56 if (ra8_wifi_status(wifi, &st) != k_ra8_ok) {
57 return false;
58 }
59 if (st.associated) {
60 return true;
61 }
63 (void)ra8_wifi_poll(wifi, &link);
64 }
65 if (ra8_wifi_status(wifi, &st) != k_ra8_ok) {
66 return false;
67 }
68 return st.associated;
69}
70
72{
73 if (out == nullptr) {
74 return false;
75 }
76 *out = (wifi_hal_result_t){};
80 if ((cfg == nullptr) || (cfg->wifi == nullptr) || (cfg->wifi_cfg == nullptr) ||
81 (cfg->ssid == nullptr)) {
82 return false;
83 }
84
85 out->init_err = ra8_wifi_init(cfg->wifi, cfg->wifi_cfg);
86 if (out->init_err != k_ra8_ok) {
87 return false;
88 }
89 out->init_ok = true;
90
91 if (cfg->ssid[0] == '\0') {
92 return false; /* runtime provisioning must provide a non-empty SSID */
93 }
94
95 out->connect_err = ra8_wifi_connect(cfg->wifi, cfg->ssid, cfg->psk);
96 out->associated = wifi_hal_settle(cfg->wifi, cfg->poll_budget);
97 if (!out->associated) {
98 return false;
99 }
100
101 (void)ra8_wifi_get_mac(cfg->wifi, &out->mac);
102 (void)ra8_wifi_get_ap(cfg->wifi, &out->ap);
103
104 out->ip_err = ra8_wifi_wait_ip(cfg->wifi, &out->lease);
105 if (out->ip_err != k_ra8_ok) {
106 return false;
107 }
108 out->ip_bound = true;
109 out->passed = true;
110 return true;
111}
Error Code Definitions for ra8-firmware.
@ k_ra8_err_not_initialized
Module not initialized – _init() not yet called successfully.
Definition ra8_err.h:235
@ k_ra8_ok
Success – operation completed with all postconditions satisfied.
Definition ra8_err.h:119
A small, uniform Wi-Fi facade: init, connect, get an IP, disconnect.
ra8_err_t ra8_wifi_init(ra8_wifi_t *wifi, const ra8_wifi_cfg_t *cfg)
Bring the radio and its link up and make a handle usable.
Definition ra8_wifi.c:166
ra8_err_t ra8_wifi_get_mac(ra8_wifi_t *wifi, ra8_wifi_mac_t *out)
Read the station's own MAC address.
Definition ra8_wifi.c:434
ra8_err_t ra8_wifi_get_ap(ra8_wifi_t *wifi, ra8_wifi_ap_t *out)
Read what the backend knows about the associated AP.
Definition ra8_wifi.c:462
struct ra8_wifi ra8_wifi_t
ra8_err_t ra8_wifi_wait_ip(ra8_wifi_t *wifi, ra8_wifi_lease_t *out)
Obtain an IP address for the associated station, blocking until bound.
Definition ra8_wifi.c:353
ra8_wifi_link_t
The instantaneous association state a backend reports.
Definition ra8_wifi.h:182
@ k_ra8_wifi_link_down
Station is not associated.
Definition ra8_wifi.h:183
ra8_err_t ra8_wifi_status(const ra8_wifi_t *wifi, ra8_wifi_status_t *out)
Read a handle's cached status without touching the wire.
Definition ra8_wifi.c:394
struct ra8_wifi_status ra8_wifi_status_t
ra8_err_t ra8_wifi_connect(ra8_wifi_t *wifi, const char *ssid, const char *psk)
Join a network by SSID and passphrase, blocking until associated.
Definition ra8_wifi.c:311
ra8_err_t ra8_wifi_poll(ra8_wifi_t *wifi, ra8_wifi_link_t *out)
Service the link once and refresh the cached association state.
Definition ra8_wifi.c:411
bool associated
The station is joined.
Definition ra8_wifi.h:297
ra8_wifi_lease_t lease
The DHCP lease, once bound.
ra8_wifi_ap_t ap
AP record, once associated.
ra8_err_t init_err
What ra8_wifi_init returned.
bool passed
The whole journey completed.
bool associated
The station joined the network.
bool ip_bound
A DHCP lease was obtained.
ra8_wifi_mac_t mac
Station MAC, once associated.
ra8_err_t ip_err
What ra8_wifi_wait_ip returned.
ra8_err_t connect_err
What ra8_wifi_connect returned.
bool init_ok
The facade initialised.
const char * psk
Passphrase, or null for an open network.
uint32_t poll_budget
Association poll attempts after connect.
ra8_wifi_t * wifi
Caller-allocated facade handle.
const ra8_wifi_cfg_t * wifi_cfg
Facade config: backend + ip provider.
const char * ssid
Target SSID; empty means "no creds".
static bool wifi_hal_settle(ra8_wifi_t *wifi, uint32_t budget)
Poll the Wi-Fi facade until association or budget exhaustion.
bool wifi_hal_join_run(const wifi_hal_run_cfg_t *cfg, wifi_hal_result_t *out)
The example's whole network journey, hardware-free: init, join, DHCP.
Constants, console formatters and the DHCP provider for the HAL join.
const char k_wifi_hal_pass_line[]
The exact PASS line the run prints; the HIL gate keys on it.
struct wifi_hal_run_cfg wifi_hal_run_cfg_t
struct wifi_hal_result wifi_hal_result_t
const char k_wifi_hal_fail_line[]
The summary FAIL line the run prints when it did not reach an IP.