blob: 117c24e5a47c7650efdd97cc0203853050aafcfc [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),
Monika Singh51876762019-05-22 18:47:22 +053075 KEYMASTER_GET_DATE_SUPPORT = (KEYMASTER_UTILS_CMD_ID + 21UL),
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -070076
77 KEYMASTER_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL
78} keymaster_cmd_t;
79
Monika Singh0b15c022019-04-10 15:24:20 +053080typedef enum {
81 KM_ERROR_INVALID_TAG = -40,
82} keymaster_error_t;
83
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -070084
85/*
86 * Utils Api struct
87 */
Sridhar Parasuram843ab542015-07-27 15:45:28 -070088/**
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*/
96typedef 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*/
108typedef struct _km_set_rot_rsp_t {
109 int status;
110}__attribute__ ((packed)) km_set_rot_rsp_t;
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -0700111
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*/
120typedef struct send_cmd{
121 uint32 cmd_id;
122 uint32 data;
123 uint32 len;
124} __attribute__ ((packed)) send_cmd_t;
125
126/*
127typedef 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*/
139typedef 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*/
149typedef struct _km_set_milestone_rsp_t {
150 int status;
151}__attribute__ ((packed)) km_set_milestone_rsp_t;
152
Sridhar Parasuramed003282015-07-10 09:50:12 -0700153/*
154 * Structures for delete_all cmd
155 */
156/*
157 @brief
158 Data structure
159
160 @param[in] cmd_id Requested command
161*/
162typedef 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*/
172typedef struct _key_op_delete_all_rsp_t {
173 int status;
174}__attribute__ ((packed)) key_op_delete_all_rsp_t;
175
Sridhar Parasuramce1e5722015-09-29 12:13:05 -0700176typedef 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
193typedef 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
210typedef 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 Kadabi86b0c112016-03-16 19:23:16 -0700217/*
218 * * Structures for get_version
219 * */
220typedef struct _km_get_version_req_t
221{
222 uint32_t cmd_id;
223}__attribute__((packed)) km_get_version_req_t;
224
225typedef 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
234typedef 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 **/
253typedef 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 **/
267typedef struct _km_set_boot_state_rsp_t
268{
269 int status;
270}__attribute__((packed)) km_set_boot_state_rsp_t;
271
Monika Singh0b15c022019-04-10 15:24:20 +0530272typedef struct
273{
274 uint32_t cmd_id;
275 char vbh[32];
276} __attribute__ ((packed)) km_set_vbh_req_t;
277
278typedef struct
279{
280 int status;
281} __attribute__ ((packed)) km_set_vbh_rsp_t;
282
Monika Singh51876762019-05-22 18:47:22 +0530283typedef struct {
284 uint32_t cmd_id;
285} __attribute__ ((packed)) km_get_date_support_req;
286
287typedef struct {
288 int32_t status;
289} __attribute__ ((packed)) km_get_date_support_rsp;
290
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -0700291#endif /* KM_MAIN_H */