38#ifndef RCBENCH_WA_SESSION_H
39#define RCBENCH_WA_SESSION_H
54#define WA_SECRET_LEN 8u
56#define WA_SECRET_CHARS "abcdefghjkmnpqrstuvwxyz23456789"
58#define WA_NAME_MAX 13u
61#define WA_SSID_MAX 32u
65#define WA_PASS_MAX 63u
68#define WA_IDLE_MS (10u * 60u * 1000u)
70#define WA_JOIN_MS 20000u
78#define WA_AUTH_TRIES 3u
80#define WA_ADDRESS_MS 15000u
82#define WA_START_MS 10000u
87#define WA_SCAN_TRIES 3u
89#define WA_GUESS_MAX 16u
161 const char *pass,
size_t pass_len);
213#define WA_PENDING_RETRIES 3u
215#define WA_PENDING_RETRY_MS 10000u
268 const wa_conf_t *c,
bool *erase_ok,
bool *save_ok);
279 bool erase_ok,
bool save_ok, uint32_t now_ms);
286#define WA_CAN_AP 0x1u
288#define WA_CAN_JOIN 0x2u
301#define WA_SCAN_MAX 16u
633 unsigned read,
unsigned room);
#define s
Short name for esc_stick_s inside the five stick-class files.
Definition esc_stick_panel_int.h:295
What is kept: the home network and the code switch.
Definition wa_session.h:121
char pass[WA_PASS_MAX+1u]
Definition wa_session.h:124
bool code_on
Definition wa_session.h:125
bool have_net
Definition wa_session.h:122
char ssid[WA_SSID_MAX+1u]
Definition wa_session.h:123
One network of the scan list.
Definition wa_session.h:304
int8_t rssi
Definition wa_session.h:306
char ssid[WA_SSID_MAX+1u]
Definition wa_session.h:305
The writes owed to the store.
Definition wa_session.h:219
uint8_t left
Definition wa_session.h:223
bool erase
Definition wa_session.h:220
uint32_t next_ms
Definition wa_session.h:224
bool failed
Definition wa_session.h:222
bool save
Definition wa_session.h:221
uint32_t gen
Definition wa_session.h:225
The scan list, strongest first.
Definition wa_session.h:310
wa_net_t net[WA_SCAN_MAX]
Definition wa_session.h:311
unsigned dropped
Definition wa_session.h:313
unsigned n
Definition wa_session.h:312
The store a wa_conf_t is kept in.
Definition wa_session.h:164
void * ctx
Definition wa_session.h:171
bool(*) save(void *ctx, const wa_conf_t *c)
Write c; false when the write failed.
Definition wa_session.h:168
bool(*) load(void *ctx, wa_conf_t *out)
Definition wa_session.h:166
bool(*) erase(void *ctx)
Definition wa_session.h:170
A session: what the radio should do, and where it is.
Definition wa_session.h:394
uint32_t last_ms
Definition wa_session.h:400
char pass[WA_SECRET_LEN+1u]
Definition wa_session.h:412
unsigned auth_drops
Definition wa_session.h:403
bool linger
Definition wa_session.h:409
wa_join_err_t join_err
Definition wa_session.h:398
unsigned guesses
Definition wa_session.h:402
unsigned busy
Definition wa_session.h:401
wa_mode_t mode
Definition wa_session.h:396
char code[WA_SECRET_LEN+1u]
Definition wa_session.h:413
wa_off_t off
Definition wa_session.h:397
uint32_t since_ms
Definition wa_session.h:399
wa_state_t state
Definition wa_session.h:395
uint32_t scan_seq
Definition wa_session.h:407
unsigned scan_runs
Definition wa_session.h:405
uint32_t scan_tok
Definition wa_session.h:406
uint32_t ip
Definition wa_session.h:404
bool wa_pending_due(const wa_pending_t *p, bool may_write, uint32_t now_ms)
Whether a write is owed and due now.
Definition wa_session.c:165
#define WA_NAME_MAX
Definition wa_session.h:58
wa_scan_step_t
What the platform does with a scan the radio reports done (wa_on_scan_end()).
Definition wa_session.h:567
@ WA_SCAN_IGNORE
Definition wa_session.h:568
@ WA_SCAN_FAILED
Definition wa_session.h:572
@ WA_SCAN_AGAIN
Definition wa_session.h:571
@ WA_SCAN_TAKE
Definition wa_session.h:569
void wa_on_address(wa_t *w, uint32_t ip, uint32_t now_ms)
The station has an address.
Definition wa_session.c:485
uint32_t(*) wa_rand_fn(void *ctx)
A source of random 32-bit words.
Definition wa_session.h:99
unsigned wa_modes(const wa_conf_t *c)
Which ways the screen offers.
Definition wa_session.c:221
wa_off_t wa_start(wa_t *w, wa_mode_t mode, wa_off_t gate, uint32_t now_ms, wa_rand_fn rand, void *ctx)
Start in mode when gate is WA_OFF_NONE, with a fresh password and code.
Definition wa_session.c:320
void wa_request_begin(wa_t *w, uint32_t now_ms)
A request begins; one under way holds the idle time-out off.
Definition wa_session.c:587
void wa_scan_add(wa_scan_t *s, const uint8_t *ssid, size_t len, int8_t rssi, bool usable)
One network a scan saw.
Definition wa_session.c:252
void wa_on_associated(wa_t *w, uint32_t now_ms)
The station reached the home network.
Definition wa_session.c:478
void wa_conf_load(const wa_store_t *s, wa_conf_t *out)
What the store holds, or the defaults when it holds nothing.
Definition wa_session.c:103
bool wa_conf_save(const wa_store_t *s, const wa_conf_t *c)
Write c into the store.
Definition wa_session.c:122
void wa_pending_done(wa_pending_t *p, const wa_pending_t *snap, bool erase_ok, bool save_ok, uint32_t now_ms)
Record the results of a write that started from snap.
Definition wa_session.c:196
bool wa_radio(const wa_t *w)
Whether the platform's radio should be running.
Definition wa_session.c:380
#define WA_SCAN_MAX
Networks the scan list holds.
Definition wa_session.h:301
uint32_t wa_scan_pending(const wa_t *w)
The scan of this session under way, its done report still owed.
Definition wa_session.c:430
#define WA_SECRET_LEN
Definition wa_session.h:54
void wa_on_ap_up(wa_t *w, uint32_t now_ms)
The access point came up.
Definition wa_session.c:401
wa_conf_err_t
Why wa_conf_set_net() refused a home network.
Definition wa_session.h:129
@ WA_CONF_SSID_LONG
Definition wa_session.h:132
@ WA_CONF_PASS_LONG
Definition wa_session.h:135
@ WA_CONF_PASS_CHAR
Definition wa_session.h:136
@ WA_CONF_SSID_CHAR
Definition wa_session.h:133
@ WA_CONF_PASS_SHORT
Definition wa_session.h:134
@ WA_CONF_OK
Definition wa_session.h:130
@ WA_CONF_SSID_EMPTY
Definition wa_session.h:131
const char * wa_scan_pick(const wa_scan_t *s, unsigned i)
The name at row i.
Definition wa_session.c:285
wa_join_err_t
Why a join failed.
Definition wa_session.h:385
@ WA_JOIN_NO_ADDRESS
Definition wa_session.h:389
@ WA_JOIN_LOST
Definition wa_session.h:390
@ WA_JOIN_PASSWORD
Definition wa_session.h:387
@ WA_JOIN_OK
Definition wa_session.h:386
@ WA_JOIN_NOT_FOUND
Definition wa_session.h:388
bool wa_lingers(const wa_t *w)
Whether the radio may stay up past the session's end, for a request of the platform's own that is und...
Definition wa_session.c:385
bool wa_scan_refused(wa_t *w, uint32_t tok)
The radio refused to start the scan of tok: off WA_OFF_FAILED when it is the scan under way.
Definition wa_session.c:440
wa_mode_t
What a session is for.
Definition wa_session.h:349
@ WA_MODE_JOIN
Definition wa_session.h:351
@ WA_MODE_SCAN
Definition wa_session.h:352
@ WA_MODE_FETCH
Definition wa_session.h:355
@ WA_MODE_AP
Definition wa_session.h:350
void wa_unlinger(wa_t *w)
The platform needs the radio off now: a linger ends; a session that runs goes on.
Definition wa_session.c:390
#define WA_PASS_MAX
A WPA2/WPA3 passphrase's most characters.
Definition wa_session.h:65
wa_conf_err_t wa_conf_set_net(wa_conf_t *c, const char *ssid, size_t ssid_len, const char *pass, size_t pass_len)
Take a home network.
Definition wa_session.c:88
void wa_init(wa_t *w)
Off, nothing kept of any session.
Definition wa_session.c:292
void wa_close(wa_t *w, wa_off_t why)
Switch off for why.
Definition wa_session.c:362
bool wa_scan_is(const wa_t *w, uint32_t tok)
Whether the scan of tok is the one under way.
Definition wa_session.c:435
bool wa_serving(const wa_t *w)
Whether the page is being served.
Definition wa_session.c:395
wa_scan_step_t wa_on_scan_end(wa_t *w, uint32_t tok, bool ok, uint32_t *next)
The scan of tok reported done; ok as wa_scan_read_ok() says.
Definition wa_session.c:458
uint32_t wa_idle_left(const wa_t *w, uint32_t now_ms)
The time left before the idle time-out.
Definition wa_session.c:605
void wa_request_end(wa_t *w, uint32_t now_ms)
A request ends; the idle time counts from now.
Definition wa_session.c:595
wa_off_t wa_gate(bool armed, bool supply, bool run)
Why the radio may not run now.
Definition wa_session.c:297
void wa_on_failed(wa_t *w)
The radio could not be started: off WA_OFF_FAILED. A refused scan is wa_scan_refused().
Definition wa_session.c:525
bool wa_tick(wa_t *w, uint32_t now_ms, wa_off_t gate, bool stop)
Once a frame: the gate, STOP and the time-outs. Off, a gate or STOP ends a linger (wa_lingers()).
Definition wa_session.c:530
bool wa_on_drop(wa_t *w, bool auth)
The radio dropped the station.
Definition wa_session.c:503
#define WA_SSID_MAX
A home network's name, in bytes.
Definition wa_session.h:61
bool wa_scan_read_ok(uint32_t status, unsigned reported, bool read_ok, unsigned read, unsigned room)
Whether a scan reported done counts as done.
Definition wa_session.c:449
wa_state_t
Where a session is.
Definition wa_session.h:359
@ WA_ST_AP
Definition wa_session.h:362
@ WA_ST_ADDRESS
Definition wa_session.h:365
@ WA_ST_JOINED
Definition wa_session.h:366
@ WA_ST_OFF
Definition wa_session.h:360
@ WA_ST_SCANNING
Definition wa_session.h:363
@ WA_ST_JOINING
Definition wa_session.h:364
@ WA_ST_STARTING
Definition wa_session.h:361
void wa_secret_make(char out[WA_SECRET_LEN+1u], wa_rand_fn rand, void *ctx)
WA_SECRET_LEN characters of WA_SECRET_CHARS and a terminator, each drawn evenly from the alphabet (wo...
Definition wa_session.c:14
void wa_conf_defaults(wa_conf_t *c)
No home network, the code on: a fresh store, and what FORGET leaves.
Definition wa_session.c:48
void wa_pending_write(const wa_store_t *st, const wa_pending_t *snap, const wa_conf_t *c, bool *erase_ok, bool *save_ok)
Write what snap owes – the erase, then c – into st.
Definition wa_session.c:178
void wa_on_scan_done(wa_t *w)
A scan session's list was read: the session ends, off WA_OFF_NONE. wa_on_scan_end() does it with the ...
Definition wa_session.c:409
wa_code_t wa_code_check(wa_t *w, const char *given, bool code_on)
Check given against this session's code.
Definition wa_session.c:614
uint32_t wa_scan_begin(wa_t *w)
The radio's station started in a scan session: the token of the scan the platform starts now,...
Definition wa_session.c:416
wa_off_t
Why the radio is off.
Definition wa_session.h:370
@ WA_OFF_RUN
Definition wa_session.h:374
@ WA_OFF_ARMED
Definition wa_session.h:372
@ WA_OFF_INSTALL
Definition wa_session.h:379
@ WA_OFF_SUPPLY
Definition wa_session.h:373
@ WA_OFF_ASKED
Definition wa_session.h:378
@ WA_OFF_FAILED
Definition wa_session.h:380
@ WA_OFF_IDLE
Definition wa_session.h:376
@ WA_OFF_GUESSES
Definition wa_session.h:377
@ WA_OFF_NONE
Definition wa_session.h:371
@ WA_OFF_JOIN
Definition wa_session.h:381
@ WA_OFF_STOP
Definition wa_session.h:375
void wa_scan_clear(wa_scan_t *s)
Empty the scan list.
Definition wa_session.c:228
bool wa_conf_forget(const wa_store_t *s, wa_conf_t *c)
FORGET: erase the store and leave c at the defaults.
Definition wa_session.c:127
void wa_name(const uint8_t mac[6], char out[WA_NAME_MAX])
"rcbench-" and the last two bytes of mac in capital hex.
Definition wa_session.c:35
void wa_pending_change(wa_pending_t *p)
A change of the settings in memory: owe a save.
Definition wa_session.c:152
wa_code_t
What the access code check says of a request.
Definition wa_session.h:687
@ WA_CODE_OK
Definition wa_session.h:688
@ WA_CODE_MISSING
Definition wa_session.h:689
@ WA_CODE_CLOSED
Definition wa_session.h:691
@ WA_CODE_WRONG
Definition wa_session.h:690
void wa_pending_init(wa_pending_t *p)
Nothing owed.
Definition wa_session.c:135
void wa_on_join_failed(wa_t *w, wa_join_err_t why)
A join failed or a joined network went away.
Definition wa_session.c:494
void wa_pending_forget(wa_pending_t *p)
FORGET: owe an erase; a save owed before it is void.
Definition wa_session.c:158