1 /* 2 * Copyright (C) 2023 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 /* This file needs to be kept in-sync with its counterpart on Trusty side */ 18 19 #pragma once 20 21 #include <stdint.h> 22 #include <trusty/line-coverage/uuid.h> 23 24 25 #define LINE_COVERAGE_CLIENT_PORT "com.android.trusty.linecoverage.client" 26 27 /** 28 * enum line_coverage_client_cmd - command identifiers for coverage client interface 29 * @LINE_COVERAGE_CLIENT_CMD_RESP_BIT: response bit set as part of response 30 * @LINE_COVERAGE_CLIENT_CMD_SHIFT: number of bits used by response bit 31 * @LINE_COVERAGE_CLIENT_CMD_OPEN: command to open coverage record 32 * @LINE_COVERAGE_CLIENT_CMD_SHARE_RECORD: command to register a shared memory region 33 * where coverage record will be written to 34 */ 35 enum line_coverage_client_cmd { 36 LINE_COVERAGE_CLIENT_CMD_RESP_BIT = 1U, 37 LINE_COVERAGE_CLIENT_CMD_SHIFT = 1U, 38 LINE_COVERAGE_CLIENT_CMD_OPEN = (1U << LINE_COVERAGE_CLIENT_CMD_SHIFT), 39 LINE_COVERAGE_CLIENT_CMD_SHARE_RECORD = (2U << LINE_COVERAGE_CLIENT_CMD_SHIFT), 40 LINE_COVERAGE_CLIENT_CMD_SEND_LIST = (3U << LINE_COVERAGE_CLIENT_CMD_SHIFT), 41 }; 42 43 /** 44 * struct line_coverage_client_hdr - header for coverage client messages 45 * @cmd: command identifier 46 * 47 * Note that no messages return a status code. Any error on the server side 48 * results in the connection being closed. So, operations can be assumed to be 49 * successful if they return a response. 50 */ 51 struct line_coverage_client_hdr { 52 uint32_t cmd; 53 }; 54 55 /** 56 * struct line_coverage_client_open_req - arguments for request to open coverage 57 * record 58 * @uuid: UUID of target TA 59 * 60 * There is one coverage record per TA. @uuid is used to identify both the TA 61 * and corresponding coverage record. 62 */ 63 struct line_coverage_client_open_req { 64 struct uuid uuid; 65 }; 66 67 /** 68 * struct line_coverage_client_open_resp - arguments for response to open coverage 69 * record 70 * @record_len: length of coverage record that will be emitted by target TA 71 * 72 * Shared memory allocated for this coverage record must larger than 73 * @record_len. 74 */ 75 struct line_coverage_client_open_resp { 76 uint32_t record_len; 77 }; 78 79 /** 80 * struct line_coverage_client_send_list_resp - arguments for response to send list 81 * record 82 * @uuid: UUID of TA that connected to aggregator 83 */ 84 struct line_coverage_client_send_list_resp { 85 struct uuid uuid; 86 }; 87 88 /** 89 * struct line_coverage_client_send_list_resp - arguments for response to send list 90 * record 91 * @index: index of the list being requested 92 */ 93 struct line_coverage_client_send_list_req { 94 uint32_t index; 95 }; 96 97 /** 98 * struct line_coverage_client_share_record_req - arguments for request to share 99 * memory for coverage record 100 * @shm_len: length of memory region being shared 101 * 102 * A handle to a memory region must be sent along with this message. This memory 103 * is used to store coverage record. 104 * 105 * Upon success, this memory region can be assumed to be shared between the 106 * client and target TA. 107 */ 108 struct line_coverage_client_share_record_req { 109 uint32_t shm_len; 110 }; 111 112 /** 113 * struct line_coverage_client_req - structure for a coverage client request 114 * @hdr: message header 115 * @open_args: arguments for %COVERAGE_CLIENT_CMD_OPEN request 116 * @share_record_args: arguments for %COVERAGE_CLIENT_CMD_SHARE_RECORD request 117 * @index: arguments for %COVERAGE_CLIENT_CMD_SHARE_RECORD request 118 */ 119 struct line_coverage_client_req { 120 struct line_coverage_client_hdr hdr; 121 union { 122 struct line_coverage_client_open_req open_args; 123 struct line_coverage_client_share_record_req share_record_args; 124 struct line_coverage_client_send_list_req send_list_args; 125 }; 126 }; 127 128 /** 129 * struct line_coverage_client_resp - structure for a coverage client response 130 * @hdr: message header 131 * @open_args: arguments for %COVERAGE_CLIENT_CMD_OPEN response 132 * @send_list_args: arguments for %COVERAGE_CLIENT_CMD_SHARE_RECORD response 133 */ 134 struct line_coverage_client_resp { 135 struct line_coverage_client_hdr hdr; 136 union { 137 struct line_coverage_client_open_resp open_args; 138 struct line_coverage_client_send_list_resp send_list_args; 139 }; 140 }; 141