Julian Hall | 65bb410 | 2023-01-19 12:09:02 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (c) 2023, Arm Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #include <assert.h> |
| 8 | #include <protocols/service/fwu/packed-c/metadata_v2.h> |
| 9 | #include "metadata_reader.h" |
| 10 | |
| 11 | class metadata_v2_reader : public metadata_version_specific_reader { |
| 12 | |
| 13 | public: |
| 14 | |
| 15 | metadata_v2_reader(); |
| 16 | ~metadata_v2_reader(); |
| 17 | |
| 18 | bool is_supported( |
| 19 | const uint8_t *buf, |
| 20 | size_t data_len) const; |
| 21 | |
| 22 | void get_version( |
| 23 | const uint8_t *buf, |
| 24 | size_t data_len, |
| 25 | unsigned int &version) const; |
| 26 | |
| 27 | void get_active_index( |
| 28 | const uint8_t *buf, |
| 29 | size_t data_len, |
| 30 | unsigned int &active_index) const; |
| 31 | }; |
| 32 | |
| 33 | /* Registers on static construction */ |
| 34 | static metadata_v2_reader the_v2_reader; |
| 35 | |
| 36 | |
| 37 | metadata_v2_reader::metadata_v2_reader() : |
| 38 | metadata_version_specific_reader() |
| 39 | { |
| 40 | metadata_reader::instance()->register_reader(this); |
| 41 | } |
| 42 | |
| 43 | metadata_v2_reader::~metadata_v2_reader() |
| 44 | { |
| 45 | |
| 46 | } |
| 47 | |
| 48 | bool metadata_v2_reader::is_supported( |
| 49 | const uint8_t *buf, |
| 50 | size_t data_len) const |
| 51 | { |
| 52 | assert(buf); |
| 53 | |
| 54 | const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf; |
| 55 | |
| 56 | return |
| 57 | (data_len >= sizeof(struct fwu_metadata)) && |
| 58 | (metadata->version == 2); |
| 59 | } |
| 60 | |
| 61 | void metadata_v2_reader::get_version( |
| 62 | const uint8_t *buf, |
| 63 | size_t data_len, |
| 64 | unsigned int &version) const |
| 65 | { |
| 66 | assert(buf); |
| 67 | assert(data_len >= sizeof(struct fwu_metadata)); |
| 68 | |
| 69 | const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf; |
| 70 | |
| 71 | version = metadata->version; |
| 72 | } |
| 73 | |
| 74 | void metadata_v2_reader::get_active_index( |
| 75 | const uint8_t *buf, |
| 76 | size_t data_len, |
| 77 | unsigned int &active_index) const |
| 78 | { |
| 79 | assert(buf); |
| 80 | assert(data_len >= sizeof(struct fwu_metadata)); |
| 81 | |
| 82 | const struct fwu_metadata *metadata = (const struct fwu_metadata *)buf; |
| 83 | |
| 84 | active_index = metadata->active_index; |
| 85 | } |