Loading...
Searching...
No Matches
storage.h
1/*
2 * Copyright (C) 2020 Koen Zandberg
3 * 2020 Inria
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
98#ifndef SUIT_STORAGE_H
99#define SUIT_STORAGE_H
100
101#include "suit.h"
102
103#ifdef __cplusplus
104extern "C" {
105#endif
106
111
115typedef struct suit_storage_driver {
116
122 int (*init)(suit_storage_t *storage);
123
134 int (*start)(suit_storage_t *storage, const suit_manifest_t *manifest,
135 size_t len);
136
149 int (*write)(suit_storage_t *storage, const suit_manifest_t *manifest, const
150 uint8_t *buf, size_t offset, size_t len);
151
161 int (*finish)(suit_storage_t *storage, const suit_manifest_t *manifest);
162
174 int (*read)(suit_storage_t *storage, uint8_t *buf, size_t offset,
175 size_t len);
176
189 int (*read_ptr)(suit_storage_t *storage,
190 const uint8_t **buf, size_t *len);
191
201 int (*install)(suit_storage_t *storage, const suit_manifest_t *manifest);
202
211 int (*erase)(suit_storage_t *storage);
212
222 bool (*has_location)(const suit_storage_t *storage, const char *location);
223
237 bool (*match_offset)(const suit_storage_t *storage, size_t offset);
238
257 int (*set_active_location)(suit_storage_t *storage, const char *location);
258
271 int (*get_seq_no)(const suit_storage_t *storage, uint32_t *seq_no);
272
282 int (*set_seq_no)(suit_storage_t *storage, uint32_t seq_no);
283
289
296
306
318 const suit_component_t *component);
319
324
334
344int suit_storage_set_seq_no_all(uint32_t seq_no);
345
360static inline char suit_storage_get_separator(const suit_storage_t *storage)
361{
362 return storage->driver->separator;
363}
364
374static inline bool suit_storage_has_readptr(const suit_storage_t *storage)
375{
376 return (storage->driver->read_ptr);
377}
378
388static inline bool suit_storage_has_offset(const suit_storage_t *storage)
389{
390 return (storage->driver->match_offset);
391}
392
398static inline int suit_storage_init(suit_storage_t *storage)
399{
400 return storage->driver->init(storage);
401}
402
413static inline int suit_storage_start(suit_storage_t *storage,
414 const suit_manifest_t *manifest,
415 size_t len)
416{
417 return storage->driver->start(storage, manifest, len);
418}
419
432static inline int suit_storage_write(suit_storage_t *storage,
433 const suit_manifest_t *manifest,
434 const uint8_t *buf, size_t offset,
435 size_t len)
436{
437 return storage->driver->write(storage, manifest, buf, offset, len);
438}
439
449static inline int suit_storage_finish(suit_storage_t *storage,
450 const suit_manifest_t *manifest)
451{
452 return storage->driver->finish(storage, manifest);
453}
454
466static inline int suit_storage_read(suit_storage_t *storage, uint8_t *buf,
467 size_t offset, size_t len)
468{
469 return storage->driver->read(storage, buf, offset, len);
470}
471
484static inline int suit_storage_read_ptr(suit_storage_t *storage, const uint8_t
485 **buf, size_t *len)
486{
487 return storage->driver->read_ptr(storage, buf, len);
488}
489
499static inline int suit_storage_install(suit_storage_t *storage,
500 const suit_manifest_t *manifest)
501{
502 return storage->driver->install(storage, manifest);
503}
504
513static inline int suit_storage_erase(suit_storage_t *storage)
514{
515 return storage->driver->erase(storage);
516}
517
527static inline bool suit_storage_has_location(suit_storage_t *storage,
528 const char *location)
529{
530 return storage->driver->has_location(storage, location);
531}
532
546static inline int suit_storage_match_offset(const suit_storage_t *storage,
547 size_t offset)
548{
549 return storage->driver->match_offset(storage, offset);
550}
551
571 const char *location)
572{
573 return storage->driver->set_active_location(storage, location);
574}
575
588static inline int suit_storage_get_seq_no(const suit_storage_t *storage,
589 uint32_t *seq_no)
590{
591 return storage->driver->get_seq_no(storage, seq_no);
592}
593
603static inline int suit_storage_set_seq_no(suit_storage_t *storage,
604 uint32_t seq_no)
605{
606 return storage->driver->set_seq_no(storage, seq_no);
607}
610#ifdef __cplusplus
611}
612#endif
613
614#endif /* SUIT_STORAGE_H */
static int suit_storage_read(suit_storage_t *storage, uint8_t *buf, size_t offset, size_t len)
Read a chunk of previously written data back.
Definition storage.h:466
static bool suit_storage_has_location(suit_storage_t *storage, const char *location)
Check if this storage backend services a location.
Definition storage.h:527
static int suit_storage_get_seq_no(const suit_storage_t *storage, uint32_t *seq_no)
Retrieve the sequence number from the storage backend.
Definition storage.h:588
static int suit_storage_match_offset(const suit_storage_t *storage, size_t offset)
Checks if the supplied offset is true or false for the current location.
Definition storage.h:546
static char suit_storage_get_separator(const suit_storage_t *storage)
get the separator for a storage backend
Definition storage.h:360
static int suit_storage_install(suit_storage_t *storage, const suit_manifest_t *manifest)
Install the payload or mark the payload as valid.
Definition storage.h:499
static int suit_storage_read_ptr(suit_storage_t *storage, const uint8_t **buf, size_t *len)
retrieve a direct read pointer for this storage backend
Definition storage.h:484
static bool suit_storage_has_readptr(const suit_storage_t *storage)
Check if the storage backend implements the suit_storage_driver_t::read_ptr function.
Definition storage.h:374
static bool suit_storage_has_offset(const suit_storage_t *storage)
Check if the storage backend implements the suit_storage_driver_t::match_offset function.
Definition storage.h:388
static int suit_storage_erase(suit_storage_t *storage)
Erase the previously loaded payload.
Definition storage.h:513
static int suit_storage_set_seq_no(suit_storage_t *storage, uint32_t seq_no)
Set a new sequence number in the storage backend.
Definition storage.h:603
static int suit_storage_start(suit_storage_t *storage, const suit_manifest_t *manifest, size_t len)
Start a new payload write sequence.
Definition storage.h:413
suit_storage_t * suit_storage_find_by_component(const suit_manifest_t *manifest, const suit_component_t *component)
retrieve a storage backend based on the suit component
void suit_storage_init_all(void)
initialize all storage backends
static int suit_storage_init(suit_storage_t *storage)
One-time initialization function.
Definition storage.h:398
static int suit_storage_finish(suit_storage_t *storage, const suit_manifest_t *manifest)
Signal that the payload write stage done to the storage backend.
Definition storage.h:449
static int suit_storage_set_active_location(suit_storage_t *storage, const char *location)
Set the active location of the storage handler.
Definition storage.h:570
int suit_storage_get_highest_seq_no(uint32_t *seq_no)
Get the highest sequence number among available backends.
int suit_storage_set_seq_no_all(uint32_t seq_no)
Set the new sequence number on all available backends.
suit_storage_t * suit_storage_find_by_id(const char *id)
retrieve a storage backend based on the location ID string
struct suit_storage_driver suit_storage_driver_t
SUIT storage backend driver struct.
static int suit_storage_write(suit_storage_t *storage, const suit_manifest_t *manifest, const uint8_t *buf, size_t offset, size_t len)
Write a new chunk of the payload to the storage backend.
Definition storage.h:432
SUIT component struct as decoded from the manifest.
Definition suit.h:215
SUIT manifest struct.
Definition suit.h:234
SUIT storage backend driver struct.
Definition storage.h:115
int(* erase)(suit_storage_t *storage)
Erase the previously loaded payload.
Definition storage.h:211
int(* get_seq_no)(const suit_storage_t *storage, uint32_t *seq_no)
Retrieve the sequence number from the storage backend.
Definition storage.h:271
int(* write)(suit_storage_t *storage, const suit_manifest_t *manifest, const uint8_t *buf, size_t offset, size_t len)
Write a new chunk of the payload to the storage backend.
Definition storage.h:149
int(* set_seq_no)(suit_storage_t *storage, uint32_t seq_no)
Set a new sequence number in the storage backend.
Definition storage.h:282
int(* install)(suit_storage_t *storage, const suit_manifest_t *manifest)
Install the payload or mark the payload as valid.
Definition storage.h:201
int(* start)(suit_storage_t *storage, const suit_manifest_t *manifest, size_t len)
Start a new payload write sequence.
Definition storage.h:134
int(* set_active_location)(suit_storage_t *storage, const char *location)
Set the active location of the storage handler.
Definition storage.h:257
bool(* has_location)(const suit_storage_t *storage, const char *location)
Check if this storage backend services a location.
Definition storage.h:222
bool(* match_offset)(const suit_storage_t *storage, size_t offset)
Checks if the supplied offset is true or false for the current location.
Definition storage.h:237
int(* init)(suit_storage_t *storage)
One-time initialization function.
Definition storage.h:122
int(* finish)(suit_storage_t *storage, const suit_manifest_t *manifest)
Signal that the payload write stage done to the storage backend.
Definition storage.h:161
char separator
Component ID separator used by this storage driver.
Definition storage.h:287
int(* read)(suit_storage_t *storage, uint8_t *buf, size_t offset, size_t len)
Read a chunk of previously written data back.
Definition storage.h:174
int(* read_ptr)(suit_storage_t *storage, const uint8_t **buf, size_t *len)
retrieve a direct read pointer for this storage backend
Definition storage.h:189
Generic storage backend state.
Definition storage.h:293
const suit_storage_driver_t * driver
Storage driver functions.
Definition storage.h:294