Ruview/firmware/esp32-csi-node/main/nvs_config.h
rUv d793c1f49f
feat(firmware): --channel and --filter-mac provisioning (ADR-060)
- provision.py: add --channel (CSI channel override) and --filter-mac
  (AA:BB:CC:DD:EE:FF format) arguments with validation
- nvs_config: add csi_channel, filter_mac[6], filter_mac_set fields;
  read from NVS on boot
- csi_collector: auto-detect AP channel when no NVS override is set;
  filter CSI frames by source MAC when filter_mac is configured
- ADR-060 documents the design and rationale

Fixes #247, fixes #229
2026-03-13 08:27:08 -04:00

69 lines
3 KiB
C

/**
* @file nvs_config.h
* @brief Runtime configuration via NVS (Non-Volatile Storage).
*
* Reads WiFi credentials and aggregator target from NVS.
* Falls back to compile-time Kconfig defaults if NVS keys are absent.
* This allows a single firmware binary to be shipped and configured
* per-device using the provisioning script.
*/
#ifndef NVS_CONFIG_H
#define NVS_CONFIG_H
#include <stdint.h>
/** Maximum lengths for NVS string fields. */
#define NVS_CFG_SSID_MAX 33
#define NVS_CFG_PASS_MAX 65
#define NVS_CFG_IP_MAX 16
/** Maximum channels in the hop list (must match CSI_HOP_CHANNELS_MAX). */
#define NVS_CFG_HOP_MAX 6
/** Runtime configuration loaded from NVS or Kconfig defaults. */
typedef struct {
char wifi_ssid[NVS_CFG_SSID_MAX];
char wifi_password[NVS_CFG_PASS_MAX];
char target_ip[NVS_CFG_IP_MAX];
uint16_t target_port;
uint8_t node_id;
/* ADR-029: Channel hopping and TDM configuration */
uint8_t channel_hop_count; /**< Number of channels to hop (1 = no hop). */
uint8_t channel_list[NVS_CFG_HOP_MAX]; /**< Channel numbers for hopping. */
uint32_t dwell_ms; /**< Dwell time per channel in ms. */
uint8_t tdm_slot_index; /**< This node's TDM slot index (0-based). */
uint8_t tdm_node_count; /**< Total nodes in the TDM schedule. */
/* ADR-039: Edge intelligence configuration */
uint8_t edge_tier; /**< Processing tier (0=raw, 1=basic, 2=full). */
float presence_thresh; /**< Presence threshold (0 = auto-calibrate). */
float fall_thresh; /**< Fall detection threshold (rad/s^2). */
uint16_t vital_window; /**< Phase history window for BPM. */
uint16_t vital_interval_ms; /**< Vitals packet interval (ms). */
uint8_t top_k_count; /**< Number of top subcarriers to track. */
uint8_t power_duty; /**< Power duty cycle (10-100%). */
/* ADR-040: WASM programmable sensing configuration */
uint8_t wasm_max_modules; /**< Max concurrent WASM modules (1-8). */
uint8_t wasm_verify; /**< Require Ed25519 signature for uploads. */
uint8_t wasm_pubkey[32]; /**< Ed25519 public key for WASM signature. */
uint8_t wasm_pubkey_valid; /**< 1 if pubkey was loaded from NVS. */
/* ADR-060: Channel override and MAC address filtering */
uint8_t csi_channel; /**< Explicit CSI channel override (0 = auto-detect). */
uint8_t filter_mac[6]; /**< MAC address to filter CSI frames. */
uint8_t filter_mac_set; /**< 1 if filter_mac was loaded from NVS. */
} nvs_config_t;
/**
* Load configuration from NVS, falling back to Kconfig defaults.
*
* Must be called after nvs_flash_init().
*
* @param cfg Output configuration struct.
*/
void nvs_config_load(nvs_config_t *cfg);
#endif /* NVS_CONFIG_H */