feat: WLAN-Zustandsautomat mit Onboarding, Backoff und AP-Fallback

This commit is contained in:
Michael Sauer
2026-09-11 22:35:30 +02:00
parent dc23d3d887
commit 2bdeaed98d
5 changed files with 415 additions and 0 deletions
+59
View File
@@ -0,0 +1,59 @@
#ifndef NL_WIFI_SM_H
#define NL_WIFI_SM_H
#include <stdbool.h>
#include <stdint.h>
#define NL_WIFI_FALLBACK_MS 300000u /* 5 min without connection -> AP+STA */
#define NL_WIFI_ONBOARD_TIMEOUT_MS 30000u
#define NL_WIFI_AP_CLOSE_ONBOARD_MS 60000u
#define NL_WIFI_AP_CLOSE_FALLBACK_MS 10000u
#define NL_WIFI_BACKOFF_MIN_MS 1000u
#define NL_WIFI_BACKOFF_MAX_MS 60000u
typedef enum {
NL_WIFI_ST_AP_ONBOARDING = 0,
NL_WIFI_ST_STA_CONNECTING,
NL_WIFI_ST_STA_CONNECTED,
NL_WIFI_ST_APSTA_FALLBACK,
NL_WIFI_ST_ONBOARD_TEST
} nl_wifi_state_t;
typedef enum { NL_WIFI_ERR_NONE = 0, NL_WIFI_ERR_AUTH, NL_WIFI_ERR_NOT_FOUND, NL_WIFI_ERR_TIMEOUT } nl_wifi_error_t;
typedef enum { NL_WIFI_EV_CONNECTED = 0, NL_WIFI_EV_JOIN_FAILED, NL_WIFI_EV_DISCONNECTED } nl_wifi_event_t;
/* What the driver has to do after a state machine call. */
typedef struct {
bool start_ap;
bool stop_ap;
bool connect; /* connect the station ... */
bool use_test_creds; /* ... with the onboarding credentials instead of the stored ones */
bool save_test_creds; /* onboarding succeeded: persist the onboarding credentials */
bool pulse_on;
bool pulse_off;
} nl_wifi_actions_t;
typedef struct {
nl_wifi_state_t state;
nl_wifi_error_t error; /* result of the last onboarding test */
bool have_creds;
bool ap_up;
bool pulsing;
bool retry_armed;
bool ap_stop_armed;
uint32_t since; /* start of the current connecting phase */
uint32_t retry_at;
uint32_t backoff;
uint32_t deadline; /* onboarding test */
uint32_t ap_stop_at;
} nl_wifi_sm_t;
nl_wifi_actions_t nl_wifi_sm_start(nl_wifi_sm_t *sm, bool have_creds, uint32_t now);
nl_wifi_actions_t nl_wifi_sm_event(nl_wifi_sm_t *sm, nl_wifi_event_t ev, nl_wifi_error_t err, uint32_t now);
nl_wifi_actions_t nl_wifi_sm_tick(nl_wifi_sm_t *sm, uint32_t now);
nl_wifi_actions_t nl_wifi_sm_onboard(nl_wifi_sm_t *sm, uint32_t now);
bool nl_wifi_sm_open_access(const nl_wifi_sm_t *sm);
const char *nl_wifi_sm_mode(const nl_wifi_sm_t *sm);
const char *nl_wifi_error_name(nl_wifi_error_t e);
#endif