Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 1 | /* |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 2 | * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef KM_MAIN_H |
| 31 | #define KM_MAIN_H |
| 32 | |
| 33 | #include <sys/types.h> |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 34 | #include <boot_verifier.h> |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 35 | /** |
| 36 | * Commands supported |
| 37 | */ |
| 38 | #define KEYMASTER_CMD_ID 0x100UL |
| 39 | #define KEYMASTER_UTILS_CMD_ID 0x200UL |
| 40 | |
| 41 | #define UINT32_MAX (0xffffffff) |
| 42 | |
| 43 | typedef enum { |
| 44 | /* |
| 45 | * List the commands supportedin by the hardware. |
| 46 | */ |
Sridhar Parasuram | 843ab54 | 2015-07-27 15:45:28 -0700 | [diff] [blame] | 47 | KEYMASTER_GET_SUPPORTED_ALGORITHMS = (KEYMASTER_CMD_ID + 1UL), |
| 48 | KEYMASTER_GET_SUPPORTED_BLOCK_MODES = (KEYMASTER_CMD_ID + 2UL), |
| 49 | KEYMASTER_GET_SUPPORTED_PADDING_MODES = (KEYMASTER_CMD_ID + 3UL), |
| 50 | KEYMASTER_GET_SUPPORTED_DIGESTS = (KEYMASTER_CMD_ID + 4UL), |
| 51 | KEYMASTER_GET_SUPPORTED_IMPORT_FORMATS = (KEYMASTER_CMD_ID + 5UL), |
| 52 | KEYMASTER_GET_SUPPORTED_EXPORT_FORMATS = (KEYMASTER_CMD_ID + 6UL), |
| 53 | KEYMASTER_ADD_RNG_ENTROPY = (KEYMASTER_CMD_ID + 7UL), |
| 54 | KEYMASTER_GENERATE_KEY = (KEYMASTER_CMD_ID + 8UL), |
| 55 | KEYMASTER_GET_KEY_CHARACTERISTICS = (KEYMASTER_CMD_ID + 9UL), |
| 56 | KEYMASTER_RESCOPE = (KEYMASTER_CMD_ID + 10UL), |
| 57 | KEYMASTER_IMPORT_KEY = (KEYMASTER_CMD_ID + 11UL), |
| 58 | KEYMASTER_EXPORT_KEY = (KEYMASTER_CMD_ID + 12UL), |
| 59 | KEYMASTER_DELETE_KEY = (KEYMASTER_CMD_ID + 13UL), |
| 60 | KEYMASTER_DELETE_ALL_KEYS = (KEYMASTER_CMD_ID + 14UL), |
| 61 | KEYMASTER_BEGIN = (KEYMASTER_CMD_ID + 15UL), |
| 62 | KEYMASTER_GET_OUTPUT_SIZE = (KEYMASTER_CMD_ID + 16UL), |
| 63 | KEYMASTER_UPDATE = (KEYMASTER_CMD_ID + 17UL), |
| 64 | KEYMASTER_FINISH = (KEYMASTER_CMD_ID + 18UL), |
| 65 | KEYMASTER_ABORT = (KEYMASTER_CMD_ID + 19UL), |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 66 | KEYMASTER_SET_BOOT_STATE = (KEYMASTER_UTILS_CMD_ID + 8UL), |
Sridhar Parasuram | 843ab54 | 2015-07-27 15:45:28 -0700 | [diff] [blame] | 67 | |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 68 | KEYMASTER_GET_VERSION = (KEYMASTER_UTILS_CMD_ID + 0UL), |
Sridhar Parasuram | 843ab54 | 2015-07-27 15:45:28 -0700 | [diff] [blame] | 69 | KEYMASTER_SET_ROT = (KEYMASTER_UTILS_CMD_ID + 1UL), |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 70 | KEYMASTER_READ_LK_DEVICE_STATE = (KEYMASTER_UTILS_CMD_ID + 2UL), |
| 71 | KEYMASTER_WRITE_LK_DEVICE_STATE = (KEYMASTER_UTILS_CMD_ID + 3UL), |
| 72 | KEYMASTER_MILESTONE_CALL = (KEYMASTER_UTILS_CMD_ID + 4UL), |
Sridhar Parasuram | ce1e572 | 2015-09-29 12:13:05 -0700 | [diff] [blame] | 73 | KEYMASTER_SECURE_WRITE_PROTECT = (KEYMASTER_UTILS_CMD_ID + 6UL), |
Monika Singh | 0b15c02 | 2019-04-10 15:24:20 +0530 | [diff] [blame] | 74 | KEYMASTER_SET_VBH = (KEYMASTER_UTILS_CMD_ID + 17UL), |
Monika Singh | 5187676 | 2019-05-22 18:47:22 +0530 | [diff] [blame] | 75 | KEYMASTER_GET_DATE_SUPPORT = (KEYMASTER_UTILS_CMD_ID + 21UL), |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 76 | |
| 77 | KEYMASTER_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL |
| 78 | } keymaster_cmd_t; |
| 79 | |
Monika Singh | 0b15c02 | 2019-04-10 15:24:20 +0530 | [diff] [blame] | 80 | typedef enum { |
| 81 | KM_ERROR_INVALID_TAG = -40, |
| 82 | } keymaster_error_t; |
| 83 | |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 84 | |
| 85 | /* |
| 86 | * Utils Api struct |
| 87 | */ |
Sridhar Parasuram | 843ab54 | 2015-07-27 15:45:28 -0700 | [diff] [blame] | 88 | /** |
| 89 | @brief |
| 90 | Data structure |
| 91 | |
| 92 | @param[in] cmd_id Requested command |
| 93 | @param[in] rot_ofset Offset from the top of the struct. |
| 94 | @param[in] rot_size Size of the ROT |
| 95 | */ |
| 96 | typedef struct _km_set_rot_req_t { |
| 97 | uint32 cmd_id; |
| 98 | uint32 rot_ofset; |
| 99 | uint32 rot_size; |
| 100 | }__attribute__ ((packed)) km_set_rot_req_t; |
| 101 | |
| 102 | /** |
| 103 | @brief |
| 104 | Data structure |
| 105 | |
| 106 | @param[out] status Status of the request |
| 107 | */ |
| 108 | typedef struct _km_set_rot_rsp_t { |
| 109 | int status; |
| 110 | }__attribute__ ((packed)) km_set_rot_rsp_t; |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | @brief |
| 114 | Data structure |
| 115 | |
| 116 | @param[in] cmd_id Requested command |
| 117 | @param[in] data information (could be data or a pointer to the memory that holds the data |
| 118 | @param[in] len if data is ptr to some buffer, len indicates length of the buffer |
| 119 | */ |
| 120 | typedef struct send_cmd{ |
| 121 | uint32 cmd_id; |
| 122 | uint32 data; |
| 123 | uint32 len; |
| 124 | } __attribute__ ((packed)) send_cmd_t; |
| 125 | |
| 126 | /* |
| 127 | typedef struct send_cmd_rsp{ |
| 128 | uint32 cmd_id; |
| 129 | uint32 data; |
| 130 | int32 status; |
| 131 | } __attribute__ ((packed)) send_cmd_rsp_t; */ |
| 132 | |
| 133 | /** |
| 134 | @brief |
| 135 | Data structure |
| 136 | |
| 137 | @param[in] cmd_id Requested command |
| 138 | */ |
| 139 | typedef struct _km_set_milestone_req_t { |
| 140 | uint32 cmd_id; |
| 141 | }__attribute__ ((packed)) km_set_milestone_req_t; |
| 142 | |
| 143 | /** |
| 144 | @brief |
| 145 | Data structure |
| 146 | |
| 147 | @param[out] status Status of the request |
| 148 | */ |
| 149 | typedef struct _km_set_milestone_rsp_t { |
| 150 | int status; |
| 151 | }__attribute__ ((packed)) km_set_milestone_rsp_t; |
| 152 | |
Sridhar Parasuram | ed00328 | 2015-07-10 09:50:12 -0700 | [diff] [blame] | 153 | /* |
| 154 | * Structures for delete_all cmd |
| 155 | */ |
| 156 | /* |
| 157 | @brief |
| 158 | Data structure |
| 159 | |
| 160 | @param[in] cmd_id Requested command |
| 161 | */ |
| 162 | typedef struct _key_op_delete_all_req_t { |
| 163 | uint32 cmd_id; |
| 164 | }__attribute__ ((packed)) key_op_delete_all_req_t; |
| 165 | |
| 166 | /* |
| 167 | @brief |
| 168 | Data structure |
| 169 | |
| 170 | @param[out] status Status of the request |
| 171 | */ |
| 172 | typedef struct _key_op_delete_all_rsp_t { |
| 173 | int status; |
| 174 | }__attribute__ ((packed)) key_op_delete_all_rsp_t; |
| 175 | |
Sridhar Parasuram | ce1e572 | 2015-09-29 12:13:05 -0700 | [diff] [blame] | 176 | typedef enum _secure_write_prot_op_t |
| 177 | { |
| 178 | SWP_READ_CONFIG, |
| 179 | SWP_WRITE_CONFIG, |
| 180 | SWP_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL |
| 181 | } secure_write_prot_op_t; |
| 182 | |
| 183 | /* |
| 184 | @brief |
| 185 | Data structure |
| 186 | |
| 187 | @param[in] cmd_id Command ID of the request |
| 188 | @param[in] op Secure write protect operation (enum from secure_write_prot_op_t) |
| 189 | @param[in] swp_write_data_offset Offset of data for SWP operation |
| 190 | @param[in] swp_write_data_len Length of data for SWP operation |
| 191 | */ |
| 192 | |
| 193 | typedef struct _secure_write_prot_req_t |
| 194 | { |
| 195 | uint32 cmd_id; |
| 196 | uint32 op; |
| 197 | uint32 swp_write_data_offset; |
| 198 | uint32 swp_write_data_len; |
| 199 | }__attribute__((packed)) secure_write_prot_req_t; |
| 200 | |
| 201 | /* |
| 202 | @brief |
| 203 | Data structure |
| 204 | |
| 205 | @param[out] status Status of the request |
| 206 | @param[out] swp_read_data_offset Offset of data for SWP operation |
| 207 | @param[out] swp_read_data_len Length of data for SWP operation |
| 208 | */ |
| 209 | |
| 210 | typedef struct _secure_write_prot_rsp_t |
| 211 | { |
| 212 | int status; |
| 213 | uint32 swp_read_data_offset; |
| 214 | uint32 swp_read_data_len; |
| 215 | }__attribute__((packed)) secure_write_prot_rsp_t; |
| 216 | |
Channagoud Kadabi | 86b0c11 | 2016-03-16 19:23:16 -0700 | [diff] [blame] | 217 | /* |
| 218 | * * Structures for get_version |
| 219 | * */ |
| 220 | typedef struct _km_get_version_req_t |
| 221 | { |
| 222 | uint32_t cmd_id; |
| 223 | }__attribute__((packed)) km_get_version_req_t; |
| 224 | |
| 225 | typedef struct _km_get_version_rsp_t |
| 226 | { |
| 227 | int status; |
| 228 | uint32_t major_version; |
| 229 | uint32_t minor_version; |
| 230 | uint32_t ta_major_version; |
| 231 | uint32_t ta_minor_version; |
| 232 | }__attribute__((packed)) km_get_version_rsp_t; |
| 233 | |
| 234 | typedef struct _km_boot_state_t |
| 235 | { |
| 236 | bool is_unlocked; |
| 237 | uint8_t public_key[32]; |
| 238 | uint32_t color; |
| 239 | uint32_t system_version; |
| 240 | uint32_t system_security_level; |
| 241 | }__attribute__((packed)) km_boot_state_t; |
| 242 | |
| 243 | /** |
| 244 | * @brief |
| 245 | * Data structure |
| 246 | * @param[in] cmd_id Requested command |
| 247 | * @param[in] boot_state_ofset Offset from the top of the struct. |
| 248 | * @param[in] boot_state_size Size of the Boot state |
| 249 | * |
| 250 | * The offset contains the following |
| 251 | * km_boot_state_t |
| 252 | **/ |
| 253 | typedef struct _km_set_boot_state_req_t |
| 254 | { |
| 255 | uint32_t cmd_id; |
| 256 | uint32_t version; |
| 257 | uint32_t boot_state_offset; |
| 258 | uint32_t boot_state_size; |
| 259 | }__attribute__((packed)) km_set_boot_state_req_t; |
| 260 | |
| 261 | /** |
| 262 | * @brief |
| 263 | * Data structure |
| 264 | * |
| 265 | * @param[out] status Status of the request |
| 266 | **/ |
| 267 | typedef struct _km_set_boot_state_rsp_t |
| 268 | { |
| 269 | int status; |
| 270 | }__attribute__((packed)) km_set_boot_state_rsp_t; |
| 271 | |
Monika Singh | 0b15c02 | 2019-04-10 15:24:20 +0530 | [diff] [blame] | 272 | typedef struct |
| 273 | { |
| 274 | uint32_t cmd_id; |
| 275 | char vbh[32]; |
| 276 | } __attribute__ ((packed)) km_set_vbh_req_t; |
| 277 | |
| 278 | typedef struct |
| 279 | { |
| 280 | int status; |
| 281 | } __attribute__ ((packed)) km_set_vbh_rsp_t; |
| 282 | |
Monika Singh | 5187676 | 2019-05-22 18:47:22 +0530 | [diff] [blame] | 283 | typedef struct { |
| 284 | uint32_t cmd_id; |
| 285 | } __attribute__ ((packed)) km_get_date_support_req; |
| 286 | |
| 287 | typedef struct { |
| 288 | int32_t status; |
| 289 | } __attribute__ ((packed)) km_get_date_support_rsp; |
| 290 | |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 291 | #endif /* KM_MAIN_H */ |