Virgil IoT KIT
update.h
Go to the documentation of this file.
1 // Copyright (C) 2015-2020 Virgil Security, Inc.
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // (1) Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 //
12 // (2) Redistributions in binary form must reproduce the above copyright
13 // notice, this list of conditions and the following disclaimer in
14 // the documentation and/or other materials provided with the
15 // distribution.
16 //
17 // (3) Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
22 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 // DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
25 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
29 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30 // IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32 //
33 // Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
34 
48 #ifndef VS_UPDATE_H
49 #define VS_UPDATE_H
50 
51 #include <global-hal.h>
52 #include <stdbool.h>
56 
57 #ifdef __cplusplus
58 namespace VirgilIoTKit {
59 extern "C" {
60 #endif
61 
67 };
68 
70 typedef struct __attribute__((__packed__)) {
71  uint16_t type;
74 
76 
84 bool
85 vs_update_equal_file_type(vs_update_file_type_t *file_type, const vs_update_file_type_t *unknown_file_type);
86 
97 vs_update_compare_version(const vs_file_version_t *update_ver, const vs_file_version_t *current_ver);
98 
101 #define VS_UPDATE_DEFAULT_DESC_BUF_SZ (49)
102 
112 const char *
113 vs_update_file_version_str(const vs_file_version_t *version, char *opt_buf, size_t buf_sz);
114 
117 #define VS_UPDATE_FILE_VERSION_STR_STATIC(VER_PTR) vs_update_file_version_str(VER_PTR, NULL, 0)
118 
128 const char *
129 vs_update_file_type_str(const vs_update_file_type_t *file_type, char *opt_buf, size_t buf_sz);
130 
133 #define VS_UPDATE_FILE_TYPE_STR_STATIC(TYPE_PTR) vs_update_file_type_str(TYPE_PTR, NULL, 0)
134 
143 typedef vs_status_e (*vs_update_get_header_size_cb_t)(void *context, vs_update_file_type_t *file_type, uint32_t *header_size);
144 
154 typedef vs_status_e (*vs_update_get_file_size_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, uint32_t *file_size);
155 
164 typedef vs_status_e (*vs_update_has_footer_cb_t)(void *context, vs_update_file_type_t *file_type, bool *has_footer);
165 
178 typedef vs_status_e (*vs_update_inc_data_offset_cb_t)(void *context, vs_update_file_type_t *file_type, uint32_t current_offset, uint32_t loaded_data_size, uint32_t *next_offset);
179 
190 typedef vs_status_e (*vs_update_get_header_cb_t)(void *context, vs_update_file_type_t *file_type, void *header_buffer, uint32_t buffer_size, uint32_t *header_size);
191 
204 typedef vs_status_e (*vs_update_get_data_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, void *data_buffer, uint32_t buffer_size, uint32_t *data_size, uint32_t data_offset);
205 
217 typedef vs_status_e (*vs_update_get_footer_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, void *footer_buffer, uint32_t buffer_size, uint32_t *footer_size);
218 
229 typedef vs_status_e (*vs_update_set_header_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, uint32_t header_size, uint32_t *file_size);
230 
242 typedef vs_status_e (*vs_update_set_data_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, const void *file_data, uint32_t data_size, uint32_t data_offset);
243 
254 typedef vs_status_e (*vs_update_set_footer_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, const void *file_footer, uint32_t footer_size);
255 
264 typedef void (*vs_update_delete_object_cb_t)(void *context, vs_update_file_type_t *file_type);
265 
274 typedef vs_status_e (*vs_update_verify_object_cb_t)(void *context, vs_update_file_type_t *file_type);
275 
281 typedef void (*vs_update_free_item_cb_t)(void *context, vs_update_file_type_t *file_type);
282 
284 typedef struct __attribute__((__packed__)) vs_update_interface_t {
305 
306 #ifdef __cplusplus
307 } // extern "C"
308 } // namespace VirgilIoTKit
309 #endif
310 
311 #endif // VS_UPDATE_H
vs_update_interface_t::get_header
vs_update_get_header_cb_t get_header
Get header.
Definition: update.h:290
vs_update_interface_t::set_header
vs_update_set_header_cb_t set_header
Set header.
Definition: update.h:294
vs_update_file_type_t
File type information.
Definition: update.h:70
vs_update_interface_t::delete_object
vs_update_delete_object_cb_t delete_object
Delete item.
Definition: update.h:298
vs_update_set_data_cb_t
vs_status_e(* vs_update_set_data_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, const void *file_data, uint32_t data_size, uint32_t data_offset)
Set data.
Definition: update.h:242
vs_update_compare_version
vs_status_e vs_update_compare_version(const vs_file_version_t *update_ver, const vs_file_version_t *current_ver)
Compare two files versions.
vs_update_interface_t::set_data
vs_update_set_data_cb_t set_data
Set data.
Definition: update.h:295
vs_update_interface_t::storage_context
vs_storage_op_ctx_t * storage_context
Storage context.
Definition: update.h:302
vs_update_interface_t::get_header_size
vs_update_get_header_size_cb_t get_header_size
Get header.
Definition: update.h:285
vs_file_info_t
File information.
Definition: provision-structs.h:225
vs_update_interface_t::has_footer
vs_update_has_footer_cb_t has_footer
Has footer.
Definition: update.h:287
vs_status_e
vs_status_e
Status code.
Definition: status_code.h:77
vs_update_verify_object_cb_t
vs_status_e(* vs_update_verify_object_cb_t)(void *context, vs_update_file_type_t *file_type)
Verify object of defined type.
Definition: update.h:274
vs_update_get_data_cb_t
vs_status_e(* vs_update_get_data_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, void *data_buffer, uint32_t buffer_size, uint32_t *data_size, uint32_t data_offset)
Get file data.
Definition: update.h:204
vs_update_equal_file_type
bool vs_update_equal_file_type(vs_update_file_type_t *file_type, const vs_update_file_type_t *unknown_file_type)
Compare two files types.
vs_update_free_item_cb_t
void(* vs_update_free_item_cb_t)(void *context, vs_update_file_type_t *file_type)
Free item during update destruction.
Definition: update.h:281
vs_file_version_t
File version information.
Definition: provision-structs.h:216
vs_update_set_footer_cb_t
vs_status_e(* vs_update_set_footer_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, const void *file_footer, uint32_t footer_size)
Set footer.
Definition: update.h:254
vs_update_set_header_cb_t
vs_status_e(* vs_update_set_header_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, uint32_t header_size, uint32_t *file_size)
Set header.
Definition: update.h:229
provision.h
Provision interface.
VS_UPDATE_FIRMWARE
@ VS_UPDATE_FIRMWARE
Firmware files for different manufactures and device types.
Definition: update.h:64
vs_update_delete_object_cb_t
void(* vs_update_delete_object_cb_t)(void *context, vs_update_file_type_t *file_type)
Delete object of defined type.
Definition: update.h:264
vs_update_interface_t::get_footer
vs_update_get_footer_cb_t get_footer
Get footer.
Definition: update.h:292
vs_update_get_footer_cb_t
vs_status_e(* vs_update_get_footer_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, void *footer_buffer, uint32_t buffer_size, uint32_t *footer_size)
Get footer.
Definition: update.h:217
vs_update_get_file_size_cb_t
vs_status_e(* vs_update_get_file_size_cb_t)(void *context, vs_update_file_type_t *file_type, const void *file_header, uint32_t *file_size)
Get file size.
Definition: update.h:154
status_code.h
Status codes and macroses.
vs_update_interface_t::verify_object
vs_update_verify_object_cb_t verify_object
Verify item.
Definition: update.h:299
vs_update_file_type_id_t
vs_update_file_type_id_t
File types.
Definition: update.h:63
vs_update_interface_t::get_file_size
vs_update_get_file_size_cb_t get_file_size
Get file size.
Definition: update.h:286
vs_update_inc_data_offset_cb_t
vs_status_e(* vs_update_inc_data_offset_cb_t)(void *context, vs_update_file_type_t *file_type, uint32_t current_offset, uint32_t loaded_data_size, uint32_t *next_offset)
Increment data offset.
Definition: update.h:178
vs_update_file_type_str
const char * vs_update_file_type_str(const vs_update_file_type_t *file_type, char *opt_buf, size_t buf_sz)
Print file type description into memory buffer.
vs_update_interface_t::get_data
vs_update_get_data_cb_t get_data
Get data.
Definition: update.h:291
VS_UPDATE_TRUST_LIST
@ VS_UPDATE_TRUST_LIST
Trust List files.
Definition: update.h:65
vs_storage_op_ctx_t
Storage element context.
Definition: storage_hal.h:221
vs_update_interface_t::free_item
vs_update_free_item_cb_t free_item
Free item.
Definition: update.h:300
storage_hal.h
Storage HAL interface.
vs_update_file_type_t::info
vs_file_info_t info
Additional file information.
Definition: update.h:72
vs_update_interface_t::inc_data_offset
vs_update_inc_data_offset_cb_t inc_data_offset
Increment data offstet.
Definition: update.h:288
vs_update_file_version_str
const char * vs_update_file_version_str(const vs_file_version_t *version, char *opt_buf, size_t buf_sz)
Print file version into memory buffer.
vs_update_get_header_size_cb_t
vs_status_e(* vs_update_get_header_size_cb_t)(void *context, vs_update_file_type_t *file_type, uint32_t *header_size)
Get file type header size.
Definition: update.h:143
vs_update_interface_t
Update interface context.
Definition: update.h:284
vs_update_get_header_cb_t
vs_status_e(* vs_update_get_header_cb_t)(void *context, vs_update_file_type_t *file_type, void *header_buffer, uint32_t buffer_size, uint32_t *header_size)
Get file header.
Definition: update.h:190
vs_update_interface_t::set_footer
vs_update_set_footer_cb_t set_footer
Set footer.
Definition: update.h:296
vs_update_file_type_t::type
uint16_t type
vs_update_file_type_id_t
Definition: update.h:71
VS_UPDATE_USER_FILES
@ VS_UPDATE_USER_FILES
User file types must have an identifier that is not lower than this code.
Definition: update.h:66
vs_update_has_footer_cb_t
vs_status_e(* vs_update_has_footer_cb_t)(void *context, vs_update_file_type_t *file_type, bool *has_footer)
Checks that such file type has footer.
Definition: update.h:164