1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <lk/compiler.h>
20 #include <stdint.h>
21 #include <trusty/uuid.h>
22 
23 __BEGIN_CDECLS
24 
25 #define COVERAGE_CLIENT_PORT "com.android.trusty.coverage.client"
26 
27 /**
28  * enum coverage_client_cmd - command identifiers for coverage client interface
29  * @COVERAGE_CLIENT_CMD_RESP_BIT:     response bit set as part of response
30  * @COVERAGE_CLIENT_CMD_SHIFT:        number of bits used by response bit
31  * @COVERAGE_CLIENT_CMD_OPEN:         command to open coverage record
32  * @COVERAGE_CLIENT_CMD_SHARE_RECORD: command to register a shared memory region
33  *                                    where coverage record will be written to
34  */
35 enum coverage_client_cmd {
36     COVERAGE_CLIENT_CMD_RESP_BIT = 1U,
37     COVERAGE_CLIENT_CMD_SHIFT = 1U,
38     COVERAGE_CLIENT_CMD_OPEN = (1U << COVERAGE_CLIENT_CMD_SHIFT),
39     COVERAGE_CLIENT_CMD_SHARE_RECORD = (2U << COVERAGE_CLIENT_CMD_SHIFT),
40 };
41 
42 /**
43  * struct coverage_client_hdr - header for coverage client messages
44  * @cmd: command identifier
45  *
46  * Note that no messages return a status code. Any error on the server side
47  * results in the connection being closed. So, operations can be assumed to be
48  * successful if they return a response.
49  */
50 struct coverage_client_hdr {
51     uint32_t cmd;
52 };
53 
54 /**
55  * struct coverage_client_open_req - arguments for request to open coverage
56  *                                   record
57  * @uuid: UUID of target TA
58  *
59  * There is one coverage record per TA. @uuid is used to identify both the TA
60  * and corresponding coverage record.
61  */
62 struct coverage_client_open_req {
63     struct uuid uuid;
64 };
65 
66 /**
67  * struct coverage_client_open_resp - arguments for response to open coverage
68  *                                    record
69  * @record_len: length of coverage record that will be emitted by target TA
70  *
71  * Shared memory allocated for this coverage record must larger than
72  * @record_len.
73  */
74 struct coverage_client_open_resp {
75     uint32_t record_len;
76 };
77 
78 /**
79  * struct coverage_client_share_record_req - arguments for request to share
80  *                                           memory for coverage record
81  * @shm_len: length of memory region being shared
82  *
83  * A handle to a memory region must be sent along with this message. This memory
84  * is used to store coverage record.
85  *
86  * Upon success, this memory region can be assumed to be shared between the
87  * client and target TA.
88  */
89 struct coverage_client_share_record_req {
90     uint32_t shm_len;
91 };
92 
93 /**
94  * struct coverage_client_req - structure for a coverage client request
95  * @hdr:               message header
96  * @open_args:         arguments for %COVERAGE_CLIENT_CMD_OPEN request
97  * @share_record_args: arguments for %COVERAGE_CLIENT_CMD_SHARE_RECORD request
98  */
99 struct coverage_client_req {
100     struct coverage_client_hdr hdr;
101     union {
102         struct coverage_client_open_req open_args;
103         struct coverage_client_share_record_req share_record_args;
104     };
105 };
106 
107 /**
108  * struct coverage_client_resp - structure for a coverage client response
109  * @hdr:       message header
110  * @open_args: arguments for %COVERAGE_CLIENT_CMD_OPEN response
111  */
112 struct coverage_client_resp {
113     struct coverage_client_hdr hdr;
114     union {
115         struct coverage_client_open_resp open_args;
116     };
117 };
118 
119 __END_CDECLS
120