Golioth Firmware SDK
Loading...
Searching...
No Matches
ota.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 Golioth, Inc.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifdef __cplusplus
8extern "C"
9{
10#endif
11
12#pragma once
13
14#include <stdint.h>
16#include <golioth/client.h>
17#include <golioth/config.h>
18
24
26#define GOLIOTH_OTA_COMPONENT_HEX_HASH_LEN 64
28#define GOLIOTH_OTA_COMPONENT_BIN_HASH_LEN 32
30#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN \
31 (CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN + CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN + 7)
32
45
74
89
100
110 size_t payload_size,
111 struct golioth_ota_manifest *manifest);
112
115size_t golioth_ota_size_to_nblocks(size_t component_size);
116
125 const struct golioth_ota_manifest *manifest,
126 const char *package);
127
138enum golioth_status golioth_ota_manifest_subscribe(struct golioth_client *client,
139 golioth_get_cb_fn callback,
140 void *arg);
141
150enum golioth_status golioth_ota_get_manifest_async(struct golioth_client *client,
151 golioth_get_cb_fn callback,
152 void *arg);
153
171enum golioth_status golioth_ota_blockwise_manifest_async(struct golioth_client *client,
172 size_t block_idx,
175 void *arg);
176
189 const struct golioth_ota_component *component,
190 uint32_t block_idx,
191 const uint8_t *block_buffer,
192 size_t block_buffer_len,
193 bool is_last,
194 size_t negotiated_block_size,
195 void *arg);
196
209 const struct golioth_coap_rsp_code *rsp_code,
210 const struct golioth_ota_component *component,
211 uint32_t block_idx,
212 void *arg);
213
239enum golioth_status golioth_ota_download_component(struct golioth_client *client,
240 const struct golioth_ota_component *component,
241 uint32_t block_idx,
244 void *arg);
245
274enum golioth_status golioth_ota_get_block_sync(struct golioth_client *client,
275 const char *package,
276 const char *version,
277 size_t block_index,
278 uint8_t *buf,
279 size_t *block_nbytes,
280 bool *is_last,
281 int32_t timeout_s);
282
298enum golioth_status golioth_ota_report_state_sync(struct golioth_client *client,
299 enum golioth_ota_state state,
300 enum golioth_ota_reason reason,
301 const char *package,
302 const char *current_version,
303 const char *target_version,
304 int32_t timeout_s);
305
310
312
313#ifdef __cplusplus
314}
315#endif
#define CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN
Definition config.h:77
#define CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS
Definition config.h:81
#define CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN
Definition config.h:73
golioth_status
void(* golioth_get_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
Definition client.h:158
void(* golioth_end_block_cb_fn)(struct golioth_client *client, enum golioth_status status, const struct golioth_coap_rsp_code *coap_rsp_code, const char *path, uint32_t block_idx, void *arg)
Definition client.h:227
enum golioth_status(* golioth_get_block_cb_fn)(struct golioth_client *client, const char *path, uint32_t block_idx, const uint8_t *block_buffer, size_t block_buffer_len, bool is_last, size_t negotiated_block_size, void *arg)
Definition client.h:195
enum golioth_status golioth_ota_report_state_sync(struct golioth_client *client, enum golioth_ota_state state, enum golioth_ota_reason reason, const char *package, const char *current_version, const char *target_version, int32_t timeout_s)
enum golioth_ota_state golioth_ota_get_state(void)
enum golioth_status golioth_ota_blockwise_manifest_async(struct golioth_client *client, size_t block_idx, golioth_get_block_cb_fn block_cb, golioth_end_block_cb_fn end_cb, void *arg)
size_t golioth_ota_size_to_nblocks(size_t component_size)
enum golioth_status golioth_ota_manifest_subscribe(struct golioth_client *client, golioth_get_cb_fn callback, void *arg)
void(* ota_component_download_end_cb)(enum golioth_status status, const struct golioth_coap_rsp_code *rsp_code, const struct golioth_ota_component *component, uint32_t block_idx, void *arg)
Definition ota.h:208
enum golioth_status(* ota_component_block_write_cb)(const struct golioth_ota_component *component, uint32_t block_idx, const uint8_t *block_buffer, size_t block_buffer_len, bool is_last, size_t negotiated_block_size, void *arg)
Definition ota.h:188
#define GOLIOTH_OTA_MAX_COMPONENT_URI_LEN
Maximum size of Relative URI to download binary (+ 7 bytes for Path)
Definition ota.h:30
const struct golioth_ota_component * golioth_ota_find_component(const struct golioth_ota_manifest *manifest, const char *package)
golioth_ota_state
State of OTA update, reported to Golioth server.
Definition ota.h:35
#define GOLIOTH_OTA_COMPONENT_BIN_HASH_LEN
Size of a SHA256 of Artifact bin array in bytes.
Definition ota.h:28
enum golioth_status golioth_ota_payload_as_manifest(const uint8_t *payload, size_t payload_size, struct golioth_ota_manifest *manifest)
enum golioth_status golioth_ota_get_block_sync(struct golioth_client *client, const char *package, const char *version, size_t block_index, uint8_t *buf, size_t *block_nbytes, bool *is_last, int32_t timeout_s)
enum golioth_status golioth_ota_get_manifest_async(struct golioth_client *client, golioth_get_cb_fn callback, void *arg)
enum golioth_status golioth_ota_download_component(struct golioth_client *client, const struct golioth_ota_component *component, uint32_t block_idx, ota_component_block_write_cb block_cb, ota_component_download_end_cb end_cb, void *arg)
golioth_ota_reason
A reason associated with state changes.
Definition ota.h:48
@ GOLIOTH_OTA_STATE_DOWNLOADED
OTA has been downloaded and written to flash.
Definition ota.h:41
@ GOLIOTH_OTA_STATE_IDLE
No OTA update in progress.
Definition ota.h:37
@ GOLIOTH_OTA_STATE_UPDATING
OTA is being applied to the system, but is not yet complete.
Definition ota.h:43
@ GOLIOTH_OTA_STATE_DOWNLOADING
OTA is being downloaded and written to flash.
Definition ota.h:39
@ GOLIOTH_OTA_REASON_IO
IO error while trying to store component.
Definition ota.h:70
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATE_FAILED
Firmware update was not successful.
Definition ota.h:66
@ GOLIOTH_OTA_REASON_OUT_OF_RAM
Insufficient RAM on device.
Definition ota.h:56
@ GOLIOTH_OTA_REASON_INVALID_URI
URI not valid.
Definition ota.h:64
@ GOLIOTH_OTA_REASON_CONNECTION_LOST
Lost connection to server during OTA update.
Definition ota.h:58
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PROTOCOL
Protocol not supported.
Definition ota.h:68
@ GOLIOTH_OTA_REASON_NOT_ENOUGH_FLASH_MEMORY
Insufficient flash memory on device.
Definition ota.h:54
@ GOLIOTH_OTA_REASON_READY
OTA update is ready to go. Also used for "no reason".
Definition ota.h:50
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATED_SUCCESSFULLY
Firmware update was successful.
Definition ota.h:52
@ GOLIOTH_OTA_REASON_INTEGRITY_CHECK_FAILURE
Data integrity check of downloaded artifact failed.
Definition ota.h:60
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PACKAGE_TYPE
Package type not supported.
Definition ota.h:62
@ GOLIOTH_OTA_REASON_AWAIT_RETRY
Awaiting retry.
Definition ota.h:72
CoAP response code returned by server.
Definition client.h:53
A component/artifact within an OTA manifest.
Definition ota.h:77
uint8_t hash[GOLIOTH_OTA_COMPONENT_BIN_HASH_LEN]
Artifact Hash.
Definition ota.h:85
char uri[GOLIOTH_OTA_MAX_COMPONENT_URI_LEN+1]
Artifact uri (e.g. "/.u/c/[email protected]")
Definition ota.h:87
char version[CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN+1]
Artifact version (e.g. "1.0.0")
Definition ota.h:81
int32_t size
Size of the artifact, in bytes.
Definition ota.h:83
char package[CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN+1]
Artifact package name (e.g. "main")
Definition ota.h:79
An OTA manifest, composed of multiple components/artifacts.
Definition ota.h:92
struct golioth_ota_component components[CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS]
An array of artifacts.
Definition ota.h:96
int32_t seqnum
OTA release sequence number.
Definition ota.h:94
size_t num_components
Number of artifacts.
Definition ota.h:98