SimpleOTA client v1.0.1
Shared core of the SimpleOTA Arduino and ESP-IDF clients
Loading...
Searching...
No Matches
sota_engine.h
Go to the documentation of this file.
1
18#ifndef SOTA_ENGINE_H
19#define SOTA_ENGINE_H
20
21#include <stdbool.h>
22#include <stdint.h>
23
24#include "sota_protocol.h"
25#include "sota_report.h"
26#include "sota_signing.h"
27#include "sota_state.h"
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
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
39
51
58
60typedef struct {
61 const char *token;
62 const char *server_url;
64 const char *version_label;
65 uint32_t image_build;
69 uint32_t http_timeout_ms;
72 bool rollback;
73 void *user;
75
78typedef struct sota_engine {
80 uint8_t keys[SOTA_VERIFIER_MAX_KEYS][32];
81 char key_ids[SOTA_VERIFIER_MAX_KEYS][64];
82 uint8_t num_keys;
86 uint32_t report_failures;
87 uint8_t net_failures;
91 bool has_offer;
93 bool validated;
95 uint32_t refused_build;
96 char refused_dep[sizeof(((sota_offer_t *)0)->deployment)];
98 void *timer;
99 volatile bool in_trial;
100 volatile bool ending;
101 volatile bool timeout_pending;
103
109
112bool sota_engine_add_key(sota_engine_t *e, const char *key_id, const char *pem);
113
117
121
125
128
132
136
140uint32_t sota_engine_step(sota_engine_t *e, bool connected);
141
145
149
152
156
157#ifdef __cplusplus
158}
159#endif
160
161#endif /* SOTA_ENGINE_H */
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.
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:95
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:71
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:73
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:72
uint32_t image_build
This image's build, reported when SimpleOTA did not install it (a USB flash).
Definition sota_engine.h:65
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:67
bool auto_confirm
A trial is confirmed by its first successful check-in.
Definition sota_engine.h:70
uint32_t http_timeout_ms
The transport's; sizes the watchdog margin.
Definition sota_engine.h:69
uint32_t confirm_timeout_s
0: the default.
Definition sota_engine.h:68
What the device says about itself on every check-in.
Definition sota_protocol.h:32
One engine's state.
Definition sota_engine.h:78
void * timer
The confirm timer, from sota_sys_timer_start().
Definition sota_engine.h:98
sota_state_t st
As stored, kept current.
Definition sota_engine.h:84
uint8_t net_failures
Managed steps in a row that failed on the network.
Definition sota_engine.h:87
bool net_failed
The step under way has: no answer, or a broken download.
Definition sota_engine.h:88
bool auth_warned
A rejected token was logged once.
Definition sota_engine.h:94
uint32_t report_failures
Report sends with no response this boot.
Definition sota_engine.h:86
uint8_t num_keys
Keys pinned.
Definition sota_engine.h:82
volatile bool timeout_pending
The confirm timeout fired, not handled yet.
Definition sota_engine.h:101
bool has_offer
offer holds an update from the last check.
Definition sota_engine.h:91
volatile bool in_trial
The running image is an unconfirmed trial.
Definition sota_engine.h:99
uint32_t refused_build
The offer last refused as a downgrade,.
Definition sota_engine.h:95
sota_offer_t offer
offer.url is heap, NULL without an offer.
Definition sota_engine.h:90
bool last_check_ok
The last check-in got a 2xx.
Definition sota_engine.h:92
bool validated
sota_engine_validate_boot() has run.
Definition sota_engine.h:93
sota_outbox_t outbox
Guarded by sota_sys_lock().
Definition sota_engine.h:85
sota_config_t cfg
As given to sota_engine_init().
Definition sota_engine.h:79
volatile bool ending
A confirm or rollback has claimed the trial.
Definition sota_engine.h:100
An update the server offered.
Definition sota_protocol.h:46
The outbox, oldest report first.
Definition sota_report.h:119
Everything persisted except the outbox, as loaded at boot.
Definition sota_state.h:62