blob: 544dc55cfe59275568a4233acb2cb77d5ad8c642 [file] [log] [blame]
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -07001/*
Channagoud Kadabi86b0c112016-03-16 19:23:16 -07002 * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved.
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -07003 *
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 Kadabi86b0c112016-03-16 19:23:16 -070034#include <boot_verifier.h>
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -070035/**
36 * Commands supported
37 */
38#define KEYMASTER_CMD_ID 0x100UL
39#define KEYMASTER_UTILS_CMD_ID 0x200UL
40
41#define UINT32_MAX (0xffffffff)
42
43typedef enum {
44 /*
45 * List the commands supportedin by the hardware.
46 */
Sridhar Parasuram843ab542015-07-27 15:45:28 -070047 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 Kadabi86b0c112016-03-16 19:23:16 -070066 KEYMASTER_SET_BOOT_STATE = (KEYMASTER_UTILS_CMD_ID + 8UL),
Sridhar Parasuram843ab542015-07-27 15:45:28 -070067
Channagoud Kadabi86b0c112016-03-16 19:23:16 -070068 KEYMASTER_GET_VERSION = (KEYMASTER_UTILS_CMD_ID + 0UL),
Sridhar Parasuram843ab542015-07-27 15:45:28 -070069 KEYMASTER_SET_ROT = (KEYMASTER_UTILS_CMD_ID + 1UL),
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -070070 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 Parasuramce1e5722015-09-29 12:13:05 -070073 KEYMASTER_SECURE_WRITE_PROTECT = (KEYMASTER_UTILS_CMD_ID + 6UL),
Monika Singh0b15c022019-04-10 15:24:20 +053074 KEYMASTER_SET_VBH = (KEYMASTER_UTILS_CMD_ID + 17UL),
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -070075
76 KEYMASTER_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL
77} keymaster_cmd_t;
78
Monika Singh0b15c022019-04-10 15:24:20 +053079typedef enum {
80 KM_ERROR_INVALID_TAG = -40,
81} keymaster_error_t;
82
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -070083
84/*
85 * Utils Api struct
86 */
Sridhar Parasuram843ab542015-07-27 15:45:28 -070087/**
88 @brief
89 Data structure
90
91 @param[in] cmd_id Requested command
92 @param[in] rot_ofset Offset from the top of the struct.
93 @param[in] rot_size Size of the ROT
94*/
95typedef struct _km_set_rot_req_t {
96 uint32 cmd_id;
97 uint32 rot_ofset;
98 uint32 rot_size;
99}__attribute__ ((packed)) km_set_rot_req_t;
100
101/**
102 @brief
103 Data structure
104
105 @param[out] status Status of the request
106*/
107typedef struct _km_set_rot_rsp_t {
108 int status;
109}__attribute__ ((packed)) km_set_rot_rsp_t;
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -0700110
111/**
112 @brief
113 Data structure
114
115 @param[in] cmd_id Requested command
116 @param[in] data information (could be data or a pointer to the memory that holds the data
117 @param[in] len if data is ptr to some buffer, len indicates length of the buffer
118*/
119typedef struct send_cmd{
120 uint32 cmd_id;
121 uint32 data;
122 uint32 len;
123} __attribute__ ((packed)) send_cmd_t;
124
125/*
126typedef struct send_cmd_rsp{
127 uint32 cmd_id;
128 uint32 data;
129 int32 status;
130} __attribute__ ((packed)) send_cmd_rsp_t; */
131
132/**
133 @brief
134 Data structure
135
136 @param[in] cmd_id Requested command
137*/
138typedef struct _km_set_milestone_req_t {
139 uint32 cmd_id;
140}__attribute__ ((packed)) km_set_milestone_req_t;
141
142/**
143 @brief
144 Data structure
145
146 @param[out] status Status of the request
147*/
148typedef struct _km_set_milestone_rsp_t {
149 int status;
150}__attribute__ ((packed)) km_set_milestone_rsp_t;
151
Sridhar Parasuramed003282015-07-10 09:50:12 -0700152/*
153 * Structures for delete_all cmd
154 */
155/*
156 @brief
157 Data structure
158
159 @param[in] cmd_id Requested command
160*/
161typedef struct _key_op_delete_all_req_t {
162 uint32 cmd_id;
163}__attribute__ ((packed)) key_op_delete_all_req_t;
164
165/*
166 @brief
167 Data structure
168
169 @param[out] status Status of the request
170*/
171typedef struct _key_op_delete_all_rsp_t {
172 int status;
173}__attribute__ ((packed)) key_op_delete_all_rsp_t;
174
Sridhar Parasuramce1e5722015-09-29 12:13:05 -0700175typedef enum _secure_write_prot_op_t
176{
177 SWP_READ_CONFIG,
178 SWP_WRITE_CONFIG,
179 SWP_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL
180} secure_write_prot_op_t;
181
182/*
183 @brief
184 Data structure
185
186 @param[in] cmd_id Command ID of the request
187 @param[in] op Secure write protect operation (enum from secure_write_prot_op_t)
188 @param[in] swp_write_data_offset Offset of data for SWP operation
189 @param[in] swp_write_data_len Length of data for SWP operation
190*/
191
192typedef struct _secure_write_prot_req_t
193{
194 uint32 cmd_id;
195 uint32 op;
196 uint32 swp_write_data_offset;
197 uint32 swp_write_data_len;
198}__attribute__((packed)) secure_write_prot_req_t;
199
200/*
201 @brief
202 Data structure
203
204 @param[out] status Status of the request
205 @param[out] swp_read_data_offset Offset of data for SWP operation
206 @param[out] swp_read_data_len Length of data for SWP operation
207*/
208
209typedef struct _secure_write_prot_rsp_t
210{
211 int status;
212 uint32 swp_read_data_offset;
213 uint32 swp_read_data_len;
214}__attribute__((packed)) secure_write_prot_rsp_t;
215
Channagoud Kadabi86b0c112016-03-16 19:23:16 -0700216/*
217 * * Structures for get_version
218 * */
219typedef struct _km_get_version_req_t
220{
221 uint32_t cmd_id;
222}__attribute__((packed)) km_get_version_req_t;
223
224typedef struct _km_get_version_rsp_t
225{
226 int status;
227 uint32_t major_version;
228 uint32_t minor_version;
229 uint32_t ta_major_version;
230 uint32_t ta_minor_version;
231}__attribute__((packed)) km_get_version_rsp_t;
232
233typedef struct _km_boot_state_t
234{
235 bool is_unlocked;
236 uint8_t public_key[32];
237 uint32_t color;
238 uint32_t system_version;
239 uint32_t system_security_level;
240}__attribute__((packed)) km_boot_state_t;
241
242/**
243 * @brief
244 * Data structure
245 * @param[in] cmd_id Requested command
246 * @param[in] boot_state_ofset Offset from the top of the struct.
247 * @param[in] boot_state_size Size of the Boot state
248 *
249 * The offset contains the following
250 * km_boot_state_t
251 **/
252typedef struct _km_set_boot_state_req_t
253{
254 uint32_t cmd_id;
255 uint32_t version;
256 uint32_t boot_state_offset;
257 uint32_t boot_state_size;
258}__attribute__((packed)) km_set_boot_state_req_t;
259
260/**
261 * @brief
262 * Data structure
263 *
264 * @param[out] status Status of the request
265 **/
266typedef struct _km_set_boot_state_rsp_t
267{
268 int status;
269}__attribute__((packed)) km_set_boot_state_rsp_t;
270
Monika Singh0b15c022019-04-10 15:24:20 +0530271typedef struct
272{
273 uint32_t cmd_id;
274 char vbh[32];
275} __attribute__ ((packed)) km_set_vbh_req_t;
276
277typedef struct
278{
279 int status;
280} __attribute__ ((packed)) km_set_vbh_rsp_t;
281
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -0700282#endif /* KM_MAIN_H */