blob: 58faa23d7362eb5a88e19a43e09bcf764d6d9599 [file] [log] [blame]
/*
* Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <assert.h>
#include <protocols/service/fwu/packed-c/metadata_v1.h>
#include "metadata_reader.h"
class metadata_v1_reader : public metadata_version_specific_reader {
public:
metadata_v1_reader();
~metadata_v1_reader();
bool is_supported(
const uint8_t *buf,
size_t data_len) const;
void get_version(
const uint8_t *buf,
size_t data_len,
unsigned int &version) const;
void get_active_index(
const uint8_t *buf,
size_t data_len,
unsigned int &active_index) const;
};
/* Registers on static construction */
static metadata_v1_reader the_v1_reader;
metadata_v1_reader::metadata_v1_reader() :
metadata_version_specific_reader()
{
metadata_reader::instance()->register_reader(this);
}
metadata_v1_reader::~metadata_v1_reader()
{
}
bool metadata_v1_reader::is_supported(
const uint8_t *buf,
size_t data_len) const
{
assert(buf);
const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf;
return
(data_len >= sizeof(struct fwu_metadata)) &&
(metadata->version == 1);
}
void metadata_v1_reader::get_version(
const uint8_t *buf,
size_t data_len,
unsigned int &version) const
{
assert(buf);
assert(data_len >= sizeof(struct fwu_metadata));
const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf;
version = metadata->version;
}
void metadata_v1_reader::get_active_index(
const uint8_t *buf,
size_t data_len,
unsigned int &active_index) const
{
assert(buf);
assert(data_len >= sizeof(struct fwu_metadata));
const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf;
active_index = metadata->active_index;
}