33#define SOTA_DEFAULT_CHECK_INTERVAL_S 3600u
34#define SOTA_DEFAULT_CONFIRM_TIMEOUT_S 300u
35#define SOTA_DEFAULT_HTTP_TIMEOUT_MS 15000u
38#define SOTA_TRIAL_RETRY_INTERVAL_S 10u
81typedef struct sota_engine {
sota_apply_result_t
sota_engine_apply() results, the same values as simpleota_result_t.
Definition sota_engine.h:41
@ SOTA_APPLY_OK
Flashed; the reboot is next.
Definition sota_engine.h:42
@ SOTA_APPLY_UNCONFIRMED
The running image is on trial; the offer is kept.
Definition sota_engine.h:48
@ SOTA_APPLY_CHECKSUM_FAIL
The download did not match its sha256.
Definition sota_engine.h:43
@ SOTA_APPLY_REBOOT_PENDING
A flashed update waits for its reboot.
Definition sota_engine.h:47
@ SOTA_APPLY_NO_OFFER
No offer from a successful check.
Definition sota_engine.h:45
@ SOTA_APPLY_SIGNATURE_FAIL
Required signature missing or wrong.
Definition sota_engine.h:46
@ SOTA_APPLY_DOWNGRADE
The offer's build is not above the running one.
Definition sota_engine.h:49
@ SOTA_APPLY_FLASH_FAIL
Network, URL, flash or state write failure.
Definition sota_engine.h:44
void sota_engine_validate_boot(sota_engine_t *e)
Work out what this boot means for a saved trial: start supervising it, queue its report,...
sota_apply_result_t sota_engine_apply(sota_engine_t *e)
Download, verify and flash the offer.
bool sota_engine_hold_pending_image(void)
For Arduino's verifyRollbackLater(): the running image is on probation and is a SimpleOTA trial.
void sota_engine_deinit(sota_engine_t *e)
Stop the timer and the watchdog, free the offer, and let another engine be set up.
bool sota_engine_check(sota_engine_t *e)
Check in.
uint32_t sota_engine_step(sota_engine_t *e, bool connected)
One pass of a managed task: service, then check and apply when connected.
bool sota_engine_init(sota_engine_t *e, const sota_config_t *cfg)
Set up an engine.
void sota_engine_service(sota_engine_t *e)
Roll back when the confirm timeout has fired.
bool sota_engine_reboot_for_update(sota_engine_t *e)
With auto_reboot off: post "reboot" for the waiting update and restart.
bool sota_engine_add_key(sota_engine_t *e, const char *key_id, const char *pem)
Pin an Ed25519 public key (PEM).
bool sota_engine_update_waiting(void)
A flashed update waits for its reboot (for this boot, every engine).
void sota_engine_timeout_fired(sota_engine_t *e)
Called by the port's timer, from any context: note the timeout and sota_app_wake().
sota_confirm_result_t
What sota_engine_confirm() did.
Definition sota_engine.h:53
@ SOTA_CONFIRM_NO_TRIAL
Nothing to confirm, or a rollback is under way.
Definition sota_engine.h:55
@ SOTA_CONFIRM_FAILED
The bootloader could not record it; the trial goes on.
Definition sota_engine.h:56
@ SOTA_CONFIRM_DONE
The trial is over and its report queued.
Definition sota_engine.h:54
sota_confirm_result_t sota_engine_confirm(sota_engine_t *e)
Confirm the running trial image.
The SimpleOTA HTTP API's request bodies and the check response.
#define SOTA_KEY_ID_MAX
The longest signing key id: the server and CLI allow 1 to 64 ASCII characters.
Definition sota_protocol.h:49
Delivery and polling policy for deferred status reports.
Ed25519 firmware-signature helpers for the SimpleOTA clients.
#define SOTA_VERIFIER_MAX_KEYS
Streaming Ed25519 verifier over one firmware image, for up to two candidate public keys (key rotation...
Definition sota_signing.h:107
Everything a client persists, and the order it is written.
Strings are borrowed: they must outlive the engine.
Definition sota_engine.h:60
bool auto_reboot
apply() restarts after a successful flash.
Definition sota_engine.h:74
const char * token
Project or device token.
Definition sota_engine.h:61
void * user
Passed to sota_net.h and sota_app.h.
Definition sota_engine.h:76
const char * project_id
The project the device belongs to, as its manifests name it.
Definition sota_engine.h:65
const char * server_url
NULL: SOTA_DEFAULT_SERVER_URL.
Definition sota_engine.h:62
bool rollback
Run new images as trials.
Definition sota_engine.h:75
uint32_t image_build
This image's build, reported when SimpleOTA did not install it (a USB flash).
Definition sota_engine.h:68
sota_device_info_t device
Sent on every check-in.
Definition sota_engine.h:63
const char * version_label
NULL: the stored one.
Definition sota_engine.h:64
uint32_t check_interval_s
0: the default.
Definition sota_engine.h:70
bool auto_confirm
A trial is confirmed by its first successful check-in.
Definition sota_engine.h:73
uint32_t http_timeout_ms
The transport's; sizes the watchdog margin.
Definition sota_engine.h:72
uint32_t confirm_timeout_s
0: the default.
Definition sota_engine.h:71
What the device says about itself on every check-in.
Definition sota_protocol.h:32
One engine's state.
Definition sota_engine.h:81
void * timer
The confirm timer, from sota_sys_timer_start().
Definition sota_engine.h:103
sota_state_t st
As stored, kept current.
Definition sota_engine.h:88
uint8_t net_failures
Managed steps in a row that failed on the network.
Definition sota_engine.h:91
bool net_failed
The step under way has: no answer, or a broken download.
Definition sota_engine.h:92
bool auth_warned
A rejected token was logged once.
Definition sota_engine.h:99
uint32_t report_failures
Report sends with no response this boot.
Definition sota_engine.h:90
uint8_t num_keys
Keys pinned.
Definition sota_engine.h:86
volatile bool timeout_pending
The confirm timeout fired, not handled yet.
Definition sota_engine.h:106
uint32_t retry_after_s
Retry-After of the last check-in's 429 or 503, else 0.
Definition sota_engine.h:93
bool has_offer
offer holds an update from the last check.
Definition sota_engine.h:96
volatile bool in_trial
The running image is an unconfirmed trial.
Definition sota_engine.h:104
uint32_t refused_build
The offer last refused as a downgrade,.
Definition sota_engine.h:100
sota_offer_t offer
offer.url is heap, NULL without an offer.
Definition sota_engine.h:95
bool last_check_ok
The last check-in got a 2xx.
Definition sota_engine.h:97
bool validated
sota_engine_validate_boot() has run.
Definition sota_engine.h:98
sota_outbox_t outbox
Guarded by sota_sys_lock().
Definition sota_engine.h:89
sota_config_t cfg
As given to sota_engine_init().
Definition sota_engine.h:82
volatile bool ending
A confirm or rollback has claimed the trial.
Definition sota_engine.h:105
An update the server offered.
Definition sota_protocol.h:52
The outbox, oldest report first.
Definition sota_report.h:136
Everything persisted except the outbox, as loaded at boot.
Definition sota_state.h:62