Files
ninlight-w600/src/net/nl_wifi_sm.h
T
Michael Sauer 3250b89986 fix: Onboarding-Test trennt die Verbindung
I1: fail_test() kehrte ohne gespeicherte Zugangsdaten stillschweigend nach
AP_ONBOARDING zurück, ohne den Stationsversuch zu trennen; ein danach doch
noch eintreffendes CONNECTED wurde in AP_ONBOARDING ignoriert, aber der
Treiber rief nl_mdns_on_ip_up() unabhängig vom Zustand auf - die Lampe
landete offen im LAN, ohne dass Zugangsdaten gespeichert wurden.

nl_wifi_actions_t bekommt ein neues Feld `disconnect`:
- fail_test() ohne Zugangsdaten setzt es (Timeout/Fehler beendet den
  Stationsversuch).
- Ein CONNECTED-Event in AP_ONBOARDING gilt als Ausreißer eines bereits
  gescheiterten Versuchs und wird ebenfalls getrennt (Zustand bleibt
  unverändert).
- M1: nl_wifi_sm_onboard() trennt jetzt immer vor dem Testverbindungsaufbau,
  damit veraltete Events eines vorherigen Versuchs nicht mehr zählen; der
  Treiber (nl_wifi_request_onboard) meldet zusätzlich "wifi busy" (503),
  solange bereits ein Onboarding-Test läuft.

Der Treiber (src/net/nl_wifi_w600.c) führt `disconnect` vor `connect` aus
und ruft nl_mdns_on_ip_up() nur noch, wenn der Zustand nach der Verarbeitung
tatsächlich STA_CONNECTED ist.

Tests (test_wifi_sm.c): Timeout/Fehler ohne Zugangsdaten -> disconnect;
CONNECTED während AP_ONBOARDING -> disconnect, Zustand unverändert;
erneutes Onboarding während laufendem Test -> disconnect vor dem neuen
connect.
2026-09-11 23:51:03 +02:00

64 lines
2.5 KiB
C

#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
#define NL_WIFI_CONNECT_TIMEOUT_MS 30000u /* no event after a connect -> treat as failed */
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 disconnect; /* drop a stray/failed station attempt (before any connect in the same set) */
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;
bool awaiting; /* waiting for response to a connect */
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;
uint32_t connect_at; /* when the pending connect was issued */
} 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