1 /* 2 * Copyright (c) 2018-2020, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 #ifndef __PS_OBJECT_TABLE_H__ 9 #define __PS_OBJECT_TABLE_H__ 10 11 #include <stdint.h> 12 13 #include "psa/protected_storage.h" 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /*! 20 * \struct ps_obj_table_info_t 21 * 22 * \brief Object table information structure. 23 */ 24 struct ps_obj_table_info_t { 25 uint32_t fid; /*!< File ID in the file system */ 26 #ifdef PS_ENCRYPTION 27 uint8_t *tag; /*!< Pointer to the MAC value of AEAD object */ 28 #else 29 uint32_t version; /*!< Object version */ 30 #endif 31 }; 32 33 /** 34 * \brief Creates object table. 35 * 36 * \return Returns error code as specified in \ref psa_status_t 37 */ 38 psa_status_t ps_object_table_create(void); 39 40 /** 41 * \brief Initializes object table. 42 * 43 * \param[in,out] obj_data Pointer to the static object data allocated 44 * in other to reuse that memory to allocated a 45 * temporary object table. 46 * 47 * \return Returns error code as specified in \ref psa_status_t 48 */ 49 psa_status_t ps_object_table_init(uint8_t *obj_data); 50 51 /** 52 * \brief Checks if there is an entry in the table for the provided UID and 53 * client ID pair. 54 * 55 * \param[in] uid Identifier for the data 56 * \param[in] client_id Identifier of the asset’s owner (client) 57 * 58 * \return Returns error code as specified in \ref psa_status_t 59 * 60 * \retval PSA_SUCCESS If there is a table entry for the object 61 * \retval PSA_ERROR_DOES_NOT_EXIST If no table entry exists for the object 62 */ 63 psa_status_t ps_object_table_obj_exist(psa_storage_uid_t uid, 64 int32_t client_id); 65 66 /** 67 * \brief Gets a not in use file ID. 68 * 69 * \param[in] fid_num Amount of file IDs that the function will check are 70 * free before returning one. 0 is an invalid input and 71 * will error. Note that this function will only ever 72 * return 1 file ID. 73 * \param[out] p_fid Pointer to the location to store the file ID 74 * 75 * \return Returns PSA_SUCCESS if the fid is valid and fid_num - 1 entries 76 * are still free in the table. Otherwise, it returns an error code as 77 * specified in \ref psa_status_t 78 */ 79 psa_status_t ps_object_table_get_free_fid(uint32_t fid_num, uint32_t *p_fid); 80 81 /** 82 * \brief Sets object table information in the object table and stores it 83 * persistently, for the provided UID and client ID pair. 84 * 85 * \param[in] uid Identifier for the data. 86 * \param[in] client_id Identifier of the asset’s owner (client) 87 * \param[in] obj_tbl_info Pointer to the location to store object table 88 * information \ref ps_obj_table_info_t 89 * 90 * \note A call to this function results in writing the table to the 91 * file system. 92 * 93 * \return Returns error code as specified in \ref psa_status_t 94 */ 95 psa_status_t ps_object_table_set_obj_tbl_info(psa_storage_uid_t uid, 96 int32_t client_id, 97 const struct ps_obj_table_info_t *obj_tbl_info); 98 99 /** 100 * \brief Gets object table information from the object table for the provided 101 * UID and client ID pair. 102 * 103 * \param[in] uid Identifier for the data. 104 * \param[in] client_id Identifier of the asset’s owner (client) 105 * \param[out] obj_tbl_info Pointer to the location to store object table 106 * information 107 * 108 * \return Returns PSA_SUCCESS if the object exists. Otherwise, it 109 * returns PSA_ERROR_DOES_NOT_EXIST. 110 */ 111 psa_status_t ps_object_table_get_obj_tbl_info(psa_storage_uid_t uid, 112 int32_t client_id, 113 struct ps_obj_table_info_t *obj_tbl_info); 114 115 /** 116 * \brief Deletes the table entry for the provided UID and client ID pair. 117 * 118 * \param[in] uid Identifier for the data. 119 * \param[in] client_id Identifier of the asset’s owner (client) 120 * 121 * \return Returns error code as specified in \ref psa_status_t 122 */ 123 psa_status_t ps_object_table_delete_object(psa_storage_uid_t uid, 124 int32_t client_id); 125 126 /** 127 * \brief Deletes old object table from the persistent area. 128 * 129 * \return Returns error code as specified in \ref psa_status_t 130 */ 131 psa_status_t ps_object_table_delete_old_table(void); 132 133 #ifdef __cplusplus 134 } 135 #endif 136 137 #endif /* __PS_OBJECT_TABLE_H__ */ 138