Golioth Firmware SDK
golioth_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 #pragma once
7 
8 #include <stdint.h>
9 #include "golioth_status.h"
10 #include "golioth_client.h"
11 #include "golioth_config.h"
12 
18 
20 #define GOLIOTH_OTA_BLOCKSIZE 1024
21 
23 typedef enum {
33 
35 typedef enum {
57 
59 typedef struct {
65  int32_t size;
69 
71 typedef struct {
73  int32_t seqnum;
79 
89  const uint8_t* payload,
90  size_t payload_size,
91  golioth_ota_manifest_t* manifest);
92 
94 size_t golioth_ota_size_to_nblocks(size_t component_size);
95 
104  const golioth_ota_manifest_t* manifest,
105  const char* package);
106 
113  golioth_client_t client,
114  golioth_get_cb_fn callback,
115  void* arg);
116 
146  golioth_client_t client,
147  const char* package,
148  const char* version,
149  size_t block_index,
150  uint8_t* buf,
151  size_t* block_nbytes,
152  bool* is_last,
153  int32_t timeout_s);
154 
171  golioth_client_t client,
172  golioth_ota_state_t state,
173  golioth_ota_reason_t reason,
174  const char* package,
175  const char* current_version,
176  const char* target_version,
177  int32_t timeout_s);
178 
183 
#define CONFIG_GOLIOTH_OTA_MAX_VERSION_LEN
#define CONFIG_GOLIOTH_OTA_MAX_NUM_COMPONENTS
#define CONFIG_GOLIOTH_OTA_MAX_PACKAGE_NAME_LEN
golioth_status_t
void(* golioth_get_cb_fn)(golioth_client_t client, const golioth_response_t *response, const char *path, const uint8_t *payload, size_t payload_size, void *arg)
void * golioth_client_t
Opaque handle to the Golioth client.
const golioth_ota_component_t * golioth_ota_find_component(const golioth_ota_manifest_t *manifest, const char *package)
golioth_status_t golioth_ota_observe_manifest_async(golioth_client_t client, golioth_get_cb_fn callback, void *arg)
golioth_ota_state_t golioth_ota_get_state(void)
size_t golioth_ota_size_to_nblocks(size_t component_size)
Convert a size in bytes to the number of blocks required (of size up to GOLIOTH_OTA_BLOCKSIZE)
golioth_status_t golioth_ota_get_block_sync(golioth_client_t 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)
golioth_status_t golioth_ota_payload_as_manifest(const uint8_t *payload, size_t payload_size, golioth_ota_manifest_t *manifest)
golioth_status_t golioth_ota_report_state_sync(golioth_client_t client, golioth_ota_state_t state, golioth_ota_reason_t reason, const char *package, const char *current_version, const char *target_version, int32_t timeout_s)
golioth_ota_reason_t
A reason associated with state changes.
Definition: golioth_ota.h:35
golioth_ota_state_t
State of OTA update, reported to Golioth server.
Definition: golioth_ota.h:23
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATE_FAILED
Firmware update was not successful.
Definition: golioth_ota.h:53
@ GOLIOTH_OTA_REASON_OUT_OF_RAM
Insufficient RAM on device.
Definition: golioth_ota.h:43
@ GOLIOTH_OTA_REASON_INVALID_URI
URI not valid.
Definition: golioth_ota.h:51
@ GOLIOTH_OTA_REASON_CONNECTION_LOST
Lost connection to server during OTA update.
Definition: golioth_ota.h:45
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PROTOCOL
Protocol not supported.
Definition: golioth_ota.h:55
@ GOLIOTH_OTA_REASON_NOT_ENOUGH_FLASH_MEMORY
Insufficient flash memory on device.
Definition: golioth_ota.h:41
@ GOLIOTH_OTA_REASON_READY
OTA update is ready to go. Also used for "no reason".
Definition: golioth_ota.h:37
@ GOLIOTH_OTA_REASON_FIRMWARE_UPDATED_SUCCESSFULLY
Firmware update was successful.
Definition: golioth_ota.h:39
@ GOLIOTH_OTA_REASON_INTEGRITY_CHECK_FAILURE
Data integrity check of downloaded artifact failed.
Definition: golioth_ota.h:47
@ GOLIOTH_OTA_REASON_UNSUPPORTED_PACKAGE_TYPE
Package type not supported.
Definition: golioth_ota.h:49
@ GOLIOTH_OTA_STATE_DOWNLOADED
OTA has been downloaded and written to flash.
Definition: golioth_ota.h:29
@ GOLIOTH_OTA_STATE_IDLE
No OTA update in progress.
Definition: golioth_ota.h:25
@ GOLIOTH_OTA_STATE_UPDATING
OTA is being applied to the system, but is not yet complete.
Definition: golioth_ota.h:31
@ GOLIOTH_OTA_STATE_DOWNLOADING
OTA is being downloaded and written to flash.
Definition: golioth_ota.h:27
A component/artifact within an OTA manifest.
Definition: golioth_ota.h:59
bool is_compressed
True, if the component is compressed and requires decompression.
Definition: golioth_ota.h:67
int32_t size
Size of the artifact, in bytes.
Definition: golioth_ota.h:65
An OTA manifest, composed of multiple components/artifacts.
Definition: golioth_ota.h:71
size_t num_components
Number of artifacts.
Definition: golioth_ota.h:77
int32_t seqnum
OTA release sequence number.
Definition: golioth_ota.h:73