SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
Loading...
Searching...
No Matches
wifi_saved.h
Go to the documentation of this file.
1/*******************************************************************************
2 * File: wifi_saved.h
3 *
4 * Description:
5 * Saved WiFi networks module — stores up to 6 network credentials in
6 * OPTIGA Trust M NVM via existing TESAIoT CRED_READ/WRITE/ERASE IPC.
7 *
8 * Each saved network (106 bytes) is stored in one OPTIGA Type 3 data
9 * object (140 bytes max). Uses slots 5, 6, 8, 9, 10, 11 (skipping
10 * slot 4=reserved and slot 7=API_KEY).
11 *
12 * LRU eviction: When all 6 slots are full, the entry with the
13 * smallest last_used timestamp is overwritten.
14 *
15 * NVRAM fallback: When OPTIGA is not connected, entries are stored
16 * in a RAM cache (persists within session, lost on reboot).
17 *
18 ******************************************************************************/
19
20#ifndef WIFI_SAVED_H
21#define WIFI_SAVED_H
22
23#include <stdint.h>
24#include <stdbool.h>
25
26#define WIFI_SAVED_MAX 6
27
28/* Per-slot binary format: 106 bytes packed */
29typedef struct __attribute__((packed)) {
30 char ssid[33]; /* null-terminated, max 32 chars */
31 char password[65]; /* null-terminated, max 63 chars (WPA2 standard) */
32 uint8_t security; /* 0=open, 1=WEP, 2=WPA, 3=WPA2, 4=WPA3 */
33 uint8_t flags; /* bit0 = auto_connect */
34 uint16_t reserved; /* alignment padding */
35 uint32_t last_used; /* epoch seconds (from RTC/NTP) for LRU eviction */
36} wifi_saved_entry_t; /* exactly 106 bytes */
37
38/*******************************************************************************
39 * Public API
40 ******************************************************************************/
41
48bool wifi_saved_load(int index, wifi_saved_entry_t *out);
49
56bool wifi_saved_store(int index, const wifi_saved_entry_t *entry);
57
63bool wifi_saved_erase(int index);
64
70int wifi_saved_find(const char *ssid);
71
81bool wifi_saved_add(const char *ssid, const char *password, uint8_t security);
82
88
95
96/*******************************************************************************
97 * Non-blocking OPTIGA probe API — use from LVGL callbacks to avoid blocking.
98 *
99 * Usage:
100 * 1. wifi_saved_probe_start() → send IPC probe, return immediately
101 * 2. wifi_saved_probe_ready() → poll periodically (100ms timer)
102 * 3. wifi_saved_probe_finish() → set OPTIGA state based on response
103 * 4. After probe, wifi_saved_load() skips probe (already done)
104 ******************************************************************************/
108
109/*******************************************************************************
110 * Non-blocking slot read API — async IPC send + poll for individual slots.
111 *
112 * Usage:
113 * 1. wifi_saved_read_start(index) → send IPC or instant (RAM fallback)
114 * 2. wifi_saved_read_ready() → poll periodically
115 * 3. wifi_saved_read_result(out) → get entry after ready==true
116 ******************************************************************************/
117bool wifi_saved_read_start(int index);
120
121#endif /* WIFI_SAVED_H */
bool wifi_saved_add(const char *ssid, const char *password, uint8_t security)
Add or update a network in saved list. If SSID already exists, updates in-place. If not,...
bool wifi_saved_store(int index, const wifi_saved_entry_t *entry)
Store a network entry to OPTIGA slot.
bool wifi_saved_probe_ready(void)
อาจเป็น true ทันทีหลัง probe_start() — ต้องรองรับเส้นทางลัดที่มาจากผลที่แคชไว้
int wifi_saved_find(const char *ssid)
Find a saved network by SSID.
bool wifi_saved_probe_start(void)
ส่ง probe ตรวจการมีอยู่ของ OPTIGA; ต้องเรียงลำดับ start → ready → finish อย่างเคร่งครัด
bool wifi_saved_read_ready(void)
ยังไม่พร้อมหมายถึงให้ลองใหม่ใน tick ถัดไป
bool wifi_saved_read_result(wifi_saved_entry_t *out)
เติมข้อมูลลงในรายการที่ผู้เรียกเป็นเจ้าของ; false หมายถึงไม่มีข้อมูลใน slot นั้น
int wifi_saved_count(void)
Count number of valid saved networks.
void wifi_saved_probe_finish(void)
เรียกเพียงครั้งเดียวต่อหนึ่ง probe และเฉพาะหลัง probe_ready() เท่านั้น; เป็นตัวตั้งสถานะ OPTIGA / RAM...
int wifi_saved_load_all(wifi_saved_entry_t *entries)
Load all saved networks into an array.
bool wifi_saved_load(int index, wifi_saved_entry_t *out)
Load a saved network from OPTIGA slot.
bool wifi_saved_erase(int index)
Erase a saved network from OPTIGA slot.
bool wifi_saved_read_start(int index)
มีการอ่าน slot ค้างอยู่ได้ครั้งละหนึ่งรายการเท่านั้น; การคืนค่า false หมายถึงข้าม slot นั้นไป
wifi_saved_entry_t
Definition wifi_saved.h:36
struct __attribute__((packed))
Definition wifi_saved.h:29