TF-M Reference Manual  1.2.0
TrustedFirmware-M
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ps_object_table.c File Reference
#include "ps_object_table.h"
#include <stddef.h>
#include "cmsis_compiler.h"
#include "crypto/ps_crypto_interface.h"
#include "flash_layout.h"
#include "nv_counters/ps_nv_counters.h"
#include "psa/internal_trusted_storage.h"
#include "tfm_memory_utils.h"
#include "ps_utils.h"
#include "tfm_ps_defs.h"
Include dependency graph for ps_object_table.c:

Go to the source code of this file.

Data Structures

struct  ps_obj_table_entry_t
 
struct  ps_obj_table_t
 Object table structure. More...
 
struct  ps_obj_table_ctx_t
 Object table context structure. More...
 
struct  ps_obj_table_init_ctx_t
 

Macros

#define PS_FLASH_DEFAULT_VAL   0xFFU
 
#define PS_OBJECT_SYSTEM_VERSION   0x01
 Current object system version. More...
 
#define PS_OBJ_TABLE_ENTRIES   (PS_NUM_ASSETS + 1)
 
#define PS_OBJ_TABLE_IDX_0   0
 
#define PS_OBJ_TABLE_IDX_1   1
 
#define PS_NUM_OBJ_TABLES   2
 
#define PS_TABLE_FS_ID(idx)   (idx + 1)
 File ID to be used in order to store the object table in the file system. More...
 
#define PS_OBJECT_FS_ID(idx)
 File ID to be used in order to store an object in the file system. More...
 
#define PS_OBJECT_FS_ID_TO_IDX(fid)
 Gets object index in the table based on the file ID. More...
 
#define PS_OBJ_TABLE_SIZE   sizeof(struct ps_obj_table_t)
 
#define PS_OBJECTS_TABLE_ENTRY_SIZE   sizeof(struct ps_obj_table_entry_t)
 
#define PS_NON_AUTH_OBJ_TABLE_SIZE   sizeof(union ps_crypto_t)
 
#define PS_OBJECT_TABLE_OBJECT_OFFSET   0
 
#define PS_CRYPTO_ASSOCIATED_DATA(crypto)
 
#define PS_CRYPTO_ASSOCIATED_DATA_LEN
 
#define PS_INVALID_NVC_VALUE   0
 

Typedefs

typedef char OBJ_TABLE_NOT_FIT_IN_STATIC_OBJ_DATA_BUF [(sizeof(struct ps_obj_table_t)<=PS_MAX_ASSET_SIZE)*2-1]
 

Enumerations

enum  ps_obj_table_state { PS_OBJ_TABLE_VALID = 0, PS_OBJ_TABLE_INVALID, PS_OBJ_TABLE_NVC_1_VALID, PS_OBJ_TABLE_NVC_3_VALID }
 

Functions

__STATIC_INLINE void ps_object_table_fs_read_table (struct ps_obj_table_init_ctx_t *init_ctx)
 Reads object table from persistent memory. More...
 
__STATIC_INLINE psa_status_t ps_object_table_fs_write_table (struct ps_obj_table_t *obj_table)
 Writes object table in persistent memory. More...
 
__STATIC_INLINE void ps_object_table_validate_version (struct ps_obj_table_init_ctx_t *init_ctx)
 Checks the validity of the table version. More...
 
__STATIC_INLINE psa_status_t ps_table_free_idx (uint32_t idx_num, uint32_t *idx)
 Gets free index in the table. More...
 
psa_status_t ps_object_table_create (void)
 Creates object table. More...
 
psa_status_t ps_object_table_init (uint8_t *obj_data)
 Initializes object table. More...
 
psa_status_t ps_object_table_obj_exist (psa_storage_uid_t uid, int32_t client_id)
 Checks if there is an entry in the table for the provided UID and client ID pair. More...
 
psa_status_t ps_object_table_get_free_fid (uint32_t fid_num, uint32_t *p_fid)
 Gets a not in use file ID. More...
 
psa_status_t ps_object_table_set_obj_tbl_info (psa_storage_uid_t uid, int32_t client_id, const struct ps_obj_table_info_t *obj_tbl_info)
 Sets object table information in the object table and stores it persistently, for the provided UID and client ID pair. More...
 
psa_status_t ps_object_table_get_obj_tbl_info (psa_storage_uid_t uid, int32_t client_id, struct ps_obj_table_info_t *obj_tbl_info)
 Gets object table information from the object table for the provided UID and client ID pair. More...
 
psa_status_t ps_object_table_delete_object (psa_storage_uid_t uid, int32_t client_id)
 Deletes the table entry for the provided UID and client ID pair. More...
 
psa_status_t ps_object_table_delete_old_table (void)
 Deletes old object table from the persistent area. More...
 

Macro Definition Documentation

#define PS_CRYPTO_ASSOCIATED_DATA (   crypto)
Value:
((uint8_t *)crypto + \
#define PS_NON_AUTH_OBJ_TABLE_SIZE

Definition at line 147 of file ps_object_table.c.

#define PS_CRYPTO_ASSOCIATED_DATA_LEN
Value:
#define PS_OBJ_TABLE_SIZE
#define PS_NON_AUTH_OBJ_TABLE_SIZE

Definition at line 164 of file ps_object_table.c.

#define PS_FLASH_DEFAULT_VAL   0xFFU

Definition at line 22 of file ps_object_table.c.

#define PS_INVALID_NVC_VALUE   0

Definition at line 188 of file ps_object_table.c.

#define PS_NON_AUTH_OBJ_TABLE_SIZE   sizeof(union ps_crypto_t)

Definition at line 141 of file ps_object_table.c.

#define PS_NUM_OBJ_TABLES   2

Definition at line 80 of file ps_object_table.c.

#define PS_OBJ_TABLE_ENTRIES   (PS_NUM_ASSETS + 1)

Definition at line 50 of file ps_object_table.c.

#define PS_OBJ_TABLE_IDX_0   0

Definition at line 76 of file ps_object_table.c.

#define PS_OBJ_TABLE_IDX_1   1

Definition at line 77 of file ps_object_table.c.

#define PS_OBJ_TABLE_SIZE   sizeof(struct ps_obj_table_t)

Definition at line 135 of file ps_object_table.c.

#define PS_OBJECT_FS_ID (   idx)
Value:
((idx + 1) + \
#define PS_TABLE_FS_ID(idx)
File ID to be used in order to store the object table in the file system.
#define PS_OBJ_TABLE_IDX_1

File ID to be used in order to store an object in the file system.

Parameters
[in]idxObject table index to convert into a file ID.
Returns
Returns file ID

Definition at line 105 of file ps_object_table.c.

#define PS_OBJECT_FS_ID_TO_IDX (   fid)
Value:
((fid - 1) - \
#define PS_TABLE_FS_ID(idx)
File ID to be used in order to store the object table in the file system.
#define PS_OBJ_TABLE_IDX_1

Gets object index in the table based on the file ID.

Parameters
[in]fidFile ID of an object in the object table
Returns
Returns object table index

Definition at line 117 of file ps_object_table.c.

#define PS_OBJECT_SYSTEM_VERSION   0x01

Current object system version.

Definition at line 29 of file ps_object_table.c.

#define PS_OBJECT_TABLE_OBJECT_OFFSET   0

Definition at line 144 of file ps_object_table.c.

#define PS_OBJECTS_TABLE_ENTRY_SIZE   sizeof(struct ps_obj_table_entry_t)

Definition at line 138 of file ps_object_table.c.

#define PS_TABLE_FS_ID (   idx)    (idx + 1)

File ID to be used in order to store the object table in the file system.

Parameters
[in]idxTable index to convert into a file ID.
Returns
Returns file ID

Definition at line 93 of file ps_object_table.c.

Typedef Documentation

typedef char OBJ_TABLE_NOT_FIT_IN_STATIC_OBJ_DATA_BUF[(sizeof(struct ps_obj_table_t)<=PS_MAX_ASSET_SIZE)*2-1]

Definition at line 178 of file ps_object_table.c.

Enumeration Type Documentation

Enumerator
PS_OBJ_TABLE_VALID 

Table content is valid

PS_OBJ_TABLE_INVALID 

Table content is invalid

PS_OBJ_TABLE_NVC_1_VALID 

Table content valid with NVC 1 value

PS_OBJ_TABLE_NVC_3_VALID 

Table content valid with NVC 3 value

Definition at line 180 of file ps_object_table.c.

Function Documentation

psa_status_t ps_object_table_create ( void  )

Creates object table.

Returns
Returns error code as specified in psa_status_t

Definition at line 809 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

psa_status_t ps_object_table_delete_object ( psa_storage_uid_t  uid,
int32_t  client_id 
)

Deletes the table entry for the provided UID and client ID pair.

Parameters
[in]uidIdentifier for the data.
[in]client_idIdentifier of the asset’s owner (client)
Returns
Returns error code as specified in psa_status_t

Definition at line 1020 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

psa_status_t ps_object_table_delete_old_table ( void  )

Deletes old object table from the persistent area.

Returns
Returns error code as specified in psa_status_t

Definition at line 1056 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

__STATIC_INLINE void ps_object_table_fs_read_table ( struct ps_obj_table_init_ctx_t init_ctx)

Reads object table from persistent memory.

Parameters
[out]init_ctxPointer to the init object table context

Definition at line 218 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

__STATIC_INLINE psa_status_t ps_object_table_fs_write_table ( struct ps_obj_table_t obj_table)

Writes object table in persistent memory.

Parameters
[in,out]obj_tablePointer to the object table to generate authentication
Returns
Returns error code as specified in psa_status_t

Definition at line 255 of file ps_object_table.c.

Here is the call graph for this function:

psa_status_t ps_object_table_get_free_fid ( uint32_t  fid_num,
uint32_t *  p_fid 
)

Gets a not in use file ID.

Parameters
[in]fid_numAmount of file IDs that the function will check are free before returning one. 0 is an invalid input and will error. Note that this function will only ever return 1 file ID.
[out]p_fidPointer to the location to store the file ID
Returns
Returns PSA_SUCCESS if the fid is valid and fid_num - 1 entries are still free in the table. Otherwise, it returns an error code as specified in psa_status_t

Definition at line 908 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

psa_status_t ps_object_table_get_obj_tbl_info ( psa_storage_uid_t  uid,
int32_t  client_id,
struct ps_obj_table_info_t obj_tbl_info 
)

Gets object table information from the object table for the provided UID and client ID pair.

Parameters
[in]uidIdentifier for the data.
[in]client_idIdentifier of the asset’s owner (client)
[out]obj_tbl_infoPointer to the location to store object table information
Returns
Returns PSA_SUCCESS if the object exists. Otherwise, it returns PSA_ERROR_DOES_NOT_EXIST.

Definition at line 995 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

psa_status_t ps_object_table_init ( uint8_t *  obj_data)

Initializes object table.

Parameters
[in,out]obj_dataPointer to the static object data allocated in other to reuse that memory to allocated a temporary object table.
Returns
Returns error code as specified in psa_status_t

Definition at line 829 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

psa_status_t ps_object_table_obj_exist ( psa_storage_uid_t  uid,
int32_t  client_id 
)

Checks if there is an entry in the table for the provided UID and client ID pair.

Parameters
[in]uidIdentifier for the data
[in]client_idIdentifier of the asset’s owner (client)
Returns
Returns error code as specified in psa_status_t
Return values
PSA_SUCCESSIf there is a table entry for the object
PSA_ERROR_DOES_NOT_EXISTIf no table entry exists for the object

Definition at line 900 of file ps_object_table.c.

psa_status_t ps_object_table_set_obj_tbl_info ( psa_storage_uid_t  uid,
int32_t  client_id,
const struct ps_obj_table_info_t obj_tbl_info 
)

Sets object table information in the object table and stores it persistently, for the provided UID and client ID pair.

Parameters
[in]uidIdentifier for the data.
[in]client_idIdentifier of the asset’s owner (client)
[in]obj_tbl_infoPointer to the location to store object table information ps_obj_table_info_t
Note
A call to this function results in writing the table to the file system.
Returns
Returns error code as specified in psa_status_t

Definition at line 939 of file ps_object_table.c.

Here is the call graph for this function:

Here is the caller graph for this function:

__STATIC_INLINE void ps_object_table_validate_version ( struct ps_obj_table_init_ctx_t init_ctx)

Checks the validity of the table version.

Parameters
[in,out]init_ctxPointer to the init object table context

Definition at line 597 of file ps_object_table.c.

Here is the caller graph for this function:

__STATIC_INLINE psa_status_t ps_table_free_idx ( uint32_t  idx_num,
uint32_t *  idx 
)

Gets free index in the table.

Parameters
[in]idx_numThe number of indices required to be free before one can be allocated. Primarily used to prevent index exhaustion.Note that this function will only ever return 1 index.
[out]idxPointer to store the free index
Note
The table is dimensioned to fit PS_NUM_ASSETS + 1
Returns
Returns PSA_SUCCESS and a table index if idx_num free indices are available. Otherwise, it returns PSA_ERROR_INSUFFICIENT_STORAGE.

Definition at line 770 of file ps_object_table.c.

Here is the caller graph for this function: