feat(m1): hardware status firmware with wifi web provisioning
Add the M1 milestone tree under poc/ (m1_hardware + poc_a apps, shared common components, evidence schema). Merges the plan's 'm1 baseline+fixes' and 'wifi provisioning' batches: the poc/ tree is entirely untracked and both concerns share files. M1 hardware baseline: - landscape ST7305 RIP display via LVGL I1 driver - TF-card status log: JSONL telemetry with CRC32C per line; append buffer widened to line[640] after the 512-byte truncation defect (payload ~550B with real values) was root-caused on-device - PCF85063 RTC read, SHTC3 temperature/humidity with plausibility checks, KEY input with short/long/portal press thresholds - boot-time partition identity check and M1-002 boot record fields (device_id, image_sha256, reset_reason, services status) WiFi web provisioning: - softAP portal Frame-Setup-xxxx with HTTP endpoints /scan, /connect, /clear; httpd handlers never call httpd_stop (deadlock hazard) — a 1s monitor task executes stop/start/connect actions - credentials persist to system_fs wifi.json (littlefs) per the SEC-010 development exception (plaintext, documented in _doc) - fallback: 5 disconnects without IP or 60s no-IP -> stop retry, portal returns; GOT_IP tears the AP down - KEY >=3s hold requests the portal; prov start/stop/status console commands; ap_active/ap_mode_requested surfaces in status JSON/text Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <[email protected]>
This commit is contained in:
@@ -0,0 +1 @@
|
||||
idf_component_register(INCLUDE_DIRS "include")
|
||||
@@ -0,0 +1,97 @@
|
||||
#ifndef FRAME_POC_FRAME_ABI_H
|
||||
#define FRAME_POC_FRAME_ABI_H
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int32_t frame_err_t;
|
||||
|
||||
enum {
|
||||
FRAME_OK = 0,
|
||||
FRAME_ERR_INVALID_PTR = -1,
|
||||
FRAME_ERR_TIMEOUT = -2,
|
||||
FRAME_ERR_QUOTA_EXCEEDED = -3,
|
||||
FRAME_ERR_LEASE_FULL = -4,
|
||||
FRAME_ERR_PLUGIN_NOT_FOUND = -5,
|
||||
FRAME_ERR_DEP_CYCLE = -6,
|
||||
FRAME_ERR_ABI_MISMATCH = -7,
|
||||
FRAME_ERR_BUSY = -8,
|
||||
FRAME_ERR_INVALID_CONTEXT = -9,
|
||||
FRAME_ERR_NET_AGAIN = -10,
|
||||
FRAME_ERR_WDT_TRIGGERED = -11,
|
||||
FRAME_ERR_ROLLBACK_FAILED = -12,
|
||||
FRAME_ERR_QUEUE_FULL = -13,
|
||||
FRAME_ERR_PLUGIN_STOPPING = -14,
|
||||
FRAME_ERR_CANCELLED = -15,
|
||||
FRAME_ERR_RESTART_REQUIRED = -16,
|
||||
FRAME_ERR_SIGNATURE_INVALID = -17,
|
||||
FRAME_ERR_PACKAGE_INVALID = -18,
|
||||
FRAME_ERR_HASH_MISMATCH = -19,
|
||||
FRAME_ERR_FS_NOT_FOUND = -20,
|
||||
FRAME_ERR_FS_TIMEOUT = -21,
|
||||
FRAME_ERR_FS_IO = -22,
|
||||
FRAME_ERR_FS_NO_TF = -23,
|
||||
FRAME_ERR_FS_RECOVERING = -24,
|
||||
FRAME_ERR_DURABILITY_DEGRADED = -25,
|
||||
FRAME_ERR_CAPACITY = -26,
|
||||
FRAME_ERR_NOT_FOUND = -27,
|
||||
FRAME_ERR_INVALID_ARGUMENT = -28,
|
||||
FRAME_ERR_RATE_LIMITED = -29,
|
||||
FRAME_ERR_MEM_FRAGMENTED = -30,
|
||||
FRAME_ERR_SEMVER_MISMATCH = -31,
|
||||
FRAME_ERR_IRAM_EXHAUSTED = -32,
|
||||
FRAME_ERR_STATE_SCHEMA = -33,
|
||||
FRAME_ERR_EPOCH_ROLLBACK = -34,
|
||||
FRAME_ERR_TARGET_MISMATCH = -35,
|
||||
};
|
||||
|
||||
enum {
|
||||
FRAME_ABI_MAJOR = 1,
|
||||
FRAME_ABI_MINOR = 0,
|
||||
};
|
||||
|
||||
typedef uint64_t plugin_instance_handle_t;
|
||||
typedef uint64_t frame_buffer_handle_t;
|
||||
typedef uint64_t steady_timer_handle_t;
|
||||
typedef uint64_t managed_task_handle_t;
|
||||
typedef uint64_t resource_handle_t;
|
||||
typedef uint64_t frame_request_handle_t;
|
||||
typedef uint64_t frame_allocation_handle_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t struct_size;
|
||||
uint16_t abi_major;
|
||||
uint16_t abi_minor;
|
||||
uint64_t feature_bits;
|
||||
} frame_abi_header_t;
|
||||
|
||||
typedef struct {
|
||||
void (*invoke)(void* user);
|
||||
void (*destroy)(void* user);
|
||||
void* user;
|
||||
} frame_post_operation_t;
|
||||
|
||||
typedef struct {
|
||||
void (*complete)(void* user, frame_err_t err);
|
||||
void (*destroy)(void* user);
|
||||
void* user;
|
||||
} frame_completion_operation_t;
|
||||
|
||||
static inline bool frame_abi_supports(const frame_abi_header_t* offered, uint16_t required_major,
|
||||
uint16_t required_minor, uint32_t required_size,
|
||||
uint64_t required_features) {
|
||||
return offered != NULL && offered->abi_major == required_major &&
|
||||
offered->abi_minor >= required_minor && offered->struct_size >= required_size &&
|
||||
(offered->feature_bits & required_features) == required_features;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,124 @@
|
||||
#ifndef FRAME_POC_FRAME_HANDLE_HH
|
||||
#define FRAME_POC_FRAME_HANDLE_HH
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
|
||||
#include "frame_poc/frame_abi.h"
|
||||
|
||||
namespace frame::poc {
|
||||
|
||||
struct handle_owner {
|
||||
plugin_instance_handle_t instance;
|
||||
uint64_t generation;
|
||||
};
|
||||
|
||||
enum class handle_type : uint16_t {
|
||||
invalid = 0,
|
||||
buffer = 1,
|
||||
timer,
|
||||
managed_task,
|
||||
resource,
|
||||
storage_request,
|
||||
network_request,
|
||||
};
|
||||
|
||||
template <typename Value, size_t Capacity> class handle_table {
|
||||
static_assert(Capacity > 0);
|
||||
static_assert(Capacity <= std::numeric_limits<uint32_t>::max());
|
||||
|
||||
public:
|
||||
frame_err_t acquire(handle_owner owner, handle_type type, Value value, uint64_t* out_handle) {
|
||||
if (out_handle == nullptr || owner.instance == 0 || owner.generation == 0) {
|
||||
return FRAME_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
for (size_t slot = 0; slot < entries_.size(); ++slot) {
|
||||
entry& candidate = entries_[slot];
|
||||
if (candidate.live) {
|
||||
continue;
|
||||
}
|
||||
if (candidate.retired) {
|
||||
continue;
|
||||
}
|
||||
|
||||
candidate.live = true;
|
||||
candidate.owner = owner;
|
||||
candidate.type = type;
|
||||
candidate.value = value;
|
||||
*out_handle = encode(slot, candidate.epoch);
|
||||
return FRAME_OK;
|
||||
}
|
||||
return FRAME_ERR_CAPACITY;
|
||||
}
|
||||
|
||||
frame_err_t get(uint64_t handle, handle_owner owner, handle_type type, Value** out_value) {
|
||||
if (out_value == nullptr) {
|
||||
return FRAME_ERR_INVALID_PTR;
|
||||
}
|
||||
|
||||
entry* candidate = find(handle);
|
||||
if (candidate == nullptr || candidate->owner.instance != owner.instance ||
|
||||
candidate->owner.generation != owner.generation || candidate->type != type) {
|
||||
return FRAME_ERR_INVALID_PTR;
|
||||
}
|
||||
|
||||
*out_value = &candidate->value;
|
||||
return FRAME_OK;
|
||||
}
|
||||
|
||||
frame_err_t release(uint64_t handle, handle_owner owner, handle_type type) {
|
||||
entry* candidate = find(handle);
|
||||
if (candidate == nullptr || candidate->owner.instance != owner.instance ||
|
||||
candidate->owner.generation != owner.generation || candidate->type != type) {
|
||||
return FRAME_ERR_INVALID_PTR;
|
||||
}
|
||||
|
||||
candidate->live = false;
|
||||
candidate->owner = {};
|
||||
if (candidate->epoch == std::numeric_limits<uint32_t>::max()) {
|
||||
candidate->retired = true;
|
||||
} else {
|
||||
++candidate->epoch;
|
||||
}
|
||||
return FRAME_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
struct entry {
|
||||
handle_owner owner{};
|
||||
handle_type type{handle_type::invalid};
|
||||
Value value{};
|
||||
uint32_t epoch{1};
|
||||
bool live{false};
|
||||
bool retired{false};
|
||||
};
|
||||
|
||||
static uint64_t encode(size_t slot, uint32_t epoch) {
|
||||
return (static_cast<uint64_t>(epoch) << 32) | (static_cast<uint64_t>(slot) + 1);
|
||||
}
|
||||
|
||||
entry* find(uint64_t handle) {
|
||||
const uint32_t encoded_slot = static_cast<uint32_t>(handle);
|
||||
const uint32_t epoch = static_cast<uint32_t>(handle >> 32);
|
||||
if (encoded_slot == 0 || epoch == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const size_t slot = encoded_slot - 1;
|
||||
if (slot >= entries_.size()) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
entry& candidate = entries_[slot];
|
||||
return candidate.live && candidate.epoch == epoch ? &candidate : nullptr;
|
||||
}
|
||||
|
||||
std::array<entry, Capacity> entries_{};
|
||||
};
|
||||
|
||||
} // namespace frame::poc
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,118 @@
|
||||
#ifndef FRAME_POC_LIFECYCLE_STATE_HH
|
||||
#define FRAME_POC_LIFECYCLE_STATE_HH
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
#include "frame_poc/frame_abi.h"
|
||||
|
||||
namespace frame::poc {
|
||||
|
||||
enum class plugin_state : uint8_t {
|
||||
staged,
|
||||
loading,
|
||||
prepared,
|
||||
active,
|
||||
pausing,
|
||||
paused,
|
||||
quiescing,
|
||||
unloading,
|
||||
unloaded,
|
||||
failed_restart_required,
|
||||
};
|
||||
|
||||
enum class lifecycle_event : uint8_t {
|
||||
begin_load,
|
||||
prepare_succeeded,
|
||||
activation_committed,
|
||||
begin_pause,
|
||||
pause_succeeded,
|
||||
resume_succeeded,
|
||||
begin_quiesce,
|
||||
quiesce_succeeded,
|
||||
unload_succeeded,
|
||||
discard_candidate,
|
||||
fail_restart_required,
|
||||
};
|
||||
|
||||
struct transition_result {
|
||||
frame_err_t error;
|
||||
plugin_state next;
|
||||
};
|
||||
|
||||
constexpr bool contains_plugin_code(plugin_state state) {
|
||||
return state != plugin_state::staged && state != plugin_state::unloaded &&
|
||||
state != plugin_state::failed_restart_required;
|
||||
}
|
||||
|
||||
constexpr transition_result transition(plugin_state current, lifecycle_event event) {
|
||||
if (event == lifecycle_event::fail_restart_required && contains_plugin_code(current)) {
|
||||
return {FRAME_OK, plugin_state::failed_restart_required};
|
||||
}
|
||||
|
||||
switch (current) {
|
||||
case plugin_state::staged:
|
||||
if (event == lifecycle_event::begin_load) {
|
||||
return {FRAME_OK, plugin_state::loading};
|
||||
}
|
||||
if (event == lifecycle_event::discard_candidate) {
|
||||
return {FRAME_OK, plugin_state::unloaded};
|
||||
}
|
||||
break;
|
||||
case plugin_state::loading:
|
||||
if (event == lifecycle_event::prepare_succeeded) {
|
||||
return {FRAME_OK, plugin_state::prepared};
|
||||
}
|
||||
if (event == lifecycle_event::discard_candidate) {
|
||||
return {FRAME_OK, plugin_state::unloaded};
|
||||
}
|
||||
break;
|
||||
case plugin_state::prepared:
|
||||
if (event == lifecycle_event::activation_committed) {
|
||||
return {FRAME_OK, plugin_state::active};
|
||||
}
|
||||
if (event == lifecycle_event::discard_candidate) {
|
||||
return {FRAME_OK, plugin_state::unloaded};
|
||||
}
|
||||
break;
|
||||
case plugin_state::active:
|
||||
if (event == lifecycle_event::begin_pause) {
|
||||
return {FRAME_OK, plugin_state::pausing};
|
||||
}
|
||||
if (event == lifecycle_event::begin_quiesce) {
|
||||
return {FRAME_OK, plugin_state::quiescing};
|
||||
}
|
||||
break;
|
||||
case plugin_state::pausing:
|
||||
if (event == lifecycle_event::pause_succeeded) {
|
||||
return {FRAME_OK, plugin_state::paused};
|
||||
}
|
||||
break;
|
||||
case plugin_state::paused:
|
||||
if (event == lifecycle_event::resume_succeeded) {
|
||||
return {FRAME_OK, plugin_state::active};
|
||||
}
|
||||
if (event == lifecycle_event::begin_quiesce) {
|
||||
return {FRAME_OK, plugin_state::quiescing};
|
||||
}
|
||||
break;
|
||||
case plugin_state::quiescing:
|
||||
if (event == lifecycle_event::quiesce_succeeded) {
|
||||
return {FRAME_OK, plugin_state::unloading};
|
||||
}
|
||||
break;
|
||||
case plugin_state::unloading:
|
||||
if (event == lifecycle_event::unload_succeeded) {
|
||||
return {FRAME_OK, plugin_state::unloaded};
|
||||
}
|
||||
break;
|
||||
case plugin_state::unloaded:
|
||||
case plugin_state::failed_restart_required:
|
||||
break;
|
||||
}
|
||||
|
||||
return {FRAME_ERR_INVALID_ARGUMENT, current};
|
||||
}
|
||||
|
||||
} // namespace frame::poc
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user