|
Safe Data API
CRC-protected (optionally redundant) data containers for Zephyr
|
|
v0.0-dev+gbb519af | |
#include <string.h>#include <zephyr/kernel.h>#include <zephyr/init.h>#include <zephyr/sys/crc.h>#include <zephyr/logging/log.h>#include <safe_data/safe_data.h>Go to the source code of this file.
Macros | |
| #define | SAFE_TAG_SEED 0x0u |
| #define | SAFE_DATA_KIND_COUNT (SAFE_DATA_FAULT_KIND_MUTATOR_CLAMPED + 1) |
| #define | SAFE_DATA_KAT_EXPECTED 0xCBF43926u |
Functions | |
| LOG_MODULE_REGISTER (safe_data, CONFIG_SAFE_DATA_LOG_LEVEL) | |
| static uint32_t | safe_tag_update (uint32_t c, const uint8_t *p, size_t len) |
| static uint32_t | safe_tag (const void *p, size_t len) |
| static uint32_t | safe_tag_inverted (const void *shadow, size_t len) |
| static bool | payload_matches_shadow (const void *payload, const void *shadow, size_t len) |
| void | safe_data_fault_handler (const void *payload, size_t len) |
| Legacy user-overridable (weak) fault handler. | |
| int | safe_data_fault_handler_register (safe_data_fault_cb_t cb) |
| Register the fault handler callback. | |
| int | safe_data_stats_get (struct safe_data_stats *out) |
| Snapshot the global statistics. | |
| void | safe_data_stats_reset (void) |
| Reset all statistics counters to zero. | |
| static void | safe_event (enum safe_data_fault_kind kind, const void *payload, size_t len) |
| int | safe_data_init (struct k_mutex *lock, void *payload, size_t len, uint32_t *crc, void *shadow) |
| Initialise the lock and seal the current payload contents. | |
| static int | verify_quiet (const void *payload, size_t len, uint32_t crc, const void *shadow) |
| int | safe_data_verify (const void *payload, size_t len, uint32_t crc, const void *shadow) |
| Verify payload integrity. Pure: read-only and lock-free; it NEVER modifies the payload, so it is safe to call concurrently with writers (a transient mismatch may then be reported - callers needing atomicity should use the higher-level helpers). | |
| int | safe_data_verify_repair (void *payload, size_t len, uint32_t crc, void *shadow) |
| Verify payload integrity and repair a recoverable fault in place. | |
| int | safe_data_read (struct k_mutex *lock, void *payload, size_t len, uint32_t *crc, void *shadow, void *out) |
Verify under lock and copy the payload out to out. | |
| int | safe_data_write (struct k_mutex *lock, void *payload, size_t len, uint32_t *crc, void *shadow, const void *in) |
Copy in into the payload under lock and reseal the integrity tag. | |
| int | safe_data_update (struct k_mutex *lock, void *payload, size_t len, uint32_t *crc, void *shadow, safe_data_mutator_t fn, void *user) |
Atomic read-modify-write: lock, verify, run fn, reseal on success. | |
| int | safe_data_commit (struct k_mutex *lock, void *payload, size_t len, uint32_t *crc, void *shadow) |
| Reseal after an explicit external modification (advanced use). Lock, recompute the integrity tag, unlock. | |
| int | safe_data_selftest (void) |
| Self-test of the integrity mechanism itself. | |
| int | safe_data_selftest_result (void) |
| Result of the boot-time self-test (CONFIG_SAFE_DATA_SELFTEST_BOOT). | |
| static int | safe_data_boot_selftest (void) |
| SYS_INIT (safe_data_boot_selftest, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT) | |
Variables | |
| static safe_data_fault_cb_t | fault_cb |
| static atomic_t | stat_counters [(SAFE_DATA_FAULT_KIND_MUTATOR_CLAMPED+1)] |
| static volatile bool | event_mute |
| static int | boot_selftest_result = -EAGAIN |
| #define SAFE_DATA_KAT_EXPECTED 0xCBF43926u |
Definition at line 487 of file safe_data.c.
Referenced by safe_data_selftest().
| #define SAFE_DATA_KIND_COUNT (SAFE_DATA_FAULT_KIND_MUTATOR_CLAMPED + 1) |
Definition at line 107 of file safe_data.c.
| #define SAFE_TAG_SEED 0x0u |
Definition at line 38 of file safe_data.c.
Referenced by safe_tag(), and safe_tag_inverted().
| LOG_MODULE_REGISTER | ( | safe_data | , |
| CONFIG_SAFE_DATA_LOG_LEVEL | ) |
|
static |
Definition at line 74 of file safe_data.c.
Referenced by safe_data_verify_repair(), and verify_quiet().
|
static |
Definition at line 556 of file safe_data.c.
References boot_selftest_result, and safe_data_selftest().
Referenced by SYS_INIT().
|
static |
Definition at line 168 of file safe_data.c.
References event_mute, fault_cb, safe_data_fault_info::kind, safe_data_fault_info::len, safe_data_fault_handler(), SAFE_DATA_FAULT_KIND_UNRECOVERABLE, and stat_counters.
Referenced by safe_data_commit(), safe_data_read(), safe_data_update(), safe_data_verify(), safe_data_verify_repair(), and safe_data_write().
|
inlinestatic |
Definition at line 45 of file safe_data.c.
References SAFE_TAG_SEED, and safe_tag_update().
Referenced by safe_data_selftest(), and verify_quiet().
|
static |
Definition at line 53 of file safe_data.c.
References SAFE_TAG_SEED, and safe_tag_update().
Referenced by verify_quiet().
|
inlinestatic |
Definition at line 39 of file safe_data.c.
Referenced by safe_tag(), and safe_tag_inverted().
| SYS_INIT | ( | safe_data_boot_selftest | , |
| POST_KERNEL | , | ||
| CONFIG_KERNEL_INIT_PRIORITY_DEFAULT | ) |
References safe_data_boot_selftest().
|
static |
Definition at line 242 of file safe_data.c.
References safe_data_fault_info::len, payload_matches_shadow(), SAFE_DATA_RECOVERED, safe_tag(), and safe_tag_inverted().
Referenced by safe_data_selftest(), safe_data_verify(), safe_data_verify_repair(), and safe_data_write().
|
static |
Definition at line 549 of file safe_data.c.
Referenced by safe_data_boot_selftest(), and safe_data_selftest_result().
|
static |
Definition at line 159 of file safe_data.c.
Referenced by safe_data_selftest(), and safe_event().
|
static |
Definition at line 95 of file safe_data.c.
Referenced by safe_data_fault_handler_register(), and safe_event().
|
static |
Definition at line 110 of file safe_data.c.
Referenced by safe_data_stats_get(), safe_data_stats_reset(), and safe_event().