aboutsummaryrefslogtreecommitdiff
path: root/interface/src/tfm_audit_func_api.c
blob: 4141970a69fceb04f96b610e27c42da16734fdbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
 * Copyright (c) 2018-2021, Arm Limited. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 *
 */

#include "psa/client.h"
#include "psa_audit_api.h"
#include "tfm_veneers.h"
#include "tfm_ns_interface.h"

#define API_DISPATCH(sfn_name)                                    \
    tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer, \
        (uint32_t)in_vec, IOVEC_LEN(in_vec),                      \
        (uint32_t)out_vec, IOVEC_LEN(out_vec))

#define API_DISPATCH_NO_INVEC(sfn_name)                           \
    tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer, \
        (uint32_t)NULL, 0,                                        \
        (uint32_t)out_vec, IOVEC_LEN(out_vec))

#define API_DISPATCH_NO_OUTVEC(sfn_name)                          \
    tfm_ns_interface_dispatch((veneer_fn)tfm_##sfn_name##_veneer, \
        (uint32_t)in_vec, IOVEC_LEN(in_vec),                      \
        (uint32_t)NULL, 0)

psa_status_t psa_audit_retrieve_record(const uint32_t record_index,
                                       const uint32_t buffer_size,
                                       const uint8_t *token,
                                       const uint32_t token_size,
                                       uint8_t *buffer,
                                       uint32_t *record_size)
{
    psa_status_t status;
    psa_invec in_vec[] = {
        {.base = &record_index, .len = sizeof(uint32_t)},
        {.base = token, .len = token_size},
    };
    psa_outvec out_vec[] = {
        {.base = buffer, .len = buffer_size},
    };

    status = API_DISPATCH(audit_core_retrieve_record);

    *record_size = out_vec[0].len;

    return status;
}

psa_status_t psa_audit_get_info(uint32_t *num_records, uint32_t *size)
{
    psa_status_t status;
    psa_outvec out_vec[] = {
        {.base = num_records, .len = sizeof(uint32_t)},
        {.base = size, .len = sizeof(uint32_t)},
    };

    status = API_DISPATCH_NO_INVEC(audit_core_get_info);

    return status;
}

psa_status_t psa_audit_get_record_info(const uint32_t record_index,
                                       uint32_t *size)
{
    psa_status_t status;
    psa_invec in_vec[] = {
        {.base = &record_index, .len = sizeof(uint32_t)},
    };
    psa_outvec out_vec[] = {
        {.base = size, .len = sizeof(uint32_t)},
    };

    status = API_DISPATCH(audit_core_get_record_info);

    return status;
}

psa_status_t psa_audit_delete_record(const uint32_t record_index,
                                     const uint8_t *token,
                                     const uint32_t token_size)
{
    psa_status_t status;
    psa_invec in_vec[] = {
        {.base = &record_index, .len = sizeof(uint32_t)},
        {.base = token, .len = token_size},
    };

    status = API_DISPATCH_NO_OUTVEC(audit_core_delete_record);

    return status;
}

psa_status_t psa_audit_add_record(const struct psa_audit_record *record)
{
    /* This API supports only Secure world calls. As this is the implementation
     * of the Non-Secure interface, always directly return an error without
     * routing the call to TF-M in the Secure world.
     */
    (void)record;
    return PSA_ERROR_NOT_PERMITTED;
}