blob: 946683ec4037d9d6799692ed2c5d356dd51dd0e3 [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),
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -070074
75 KEYMASTER_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL
76} keymaster_cmd_t;
77
78
79/*
80 * Utils Api struct
81 */
Sridhar Parasuram843ab542015-07-27 15:45:28 -070082/**
83 @brief
84 Data structure
85
86 @param[in] cmd_id Requested command
87 @param[in] rot_ofset Offset from the top of the struct.
88 @param[in] rot_size Size of the ROT
89*/
90typedef struct _km_set_rot_req_t {
91 uint32 cmd_id;
92 uint32 rot_ofset;
93 uint32 rot_size;
94}__attribute__ ((packed)) km_set_rot_req_t;
95
96/**
97 @brief
98 Data structure
99
100 @param[out] status Status of the request
101*/
102typedef struct _km_set_rot_rsp_t {
103 int status;
104}__attribute__ ((packed)) km_set_rot_rsp_t;
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -0700105
106/**
107 @brief
108 Data structure
109
110 @param[in] cmd_id Requested command
111 @param[in] data information (could be data or a pointer to the memory that holds the data
112 @param[in] len if data is ptr to some buffer, len indicates length of the buffer
113*/
114typedef struct send_cmd{
115 uint32 cmd_id;
116 uint32 data;
117 uint32 len;
118} __attribute__ ((packed)) send_cmd_t;
119
120/*
121typedef struct send_cmd_rsp{
122 uint32 cmd_id;
123 uint32 data;
124 int32 status;
125} __attribute__ ((packed)) send_cmd_rsp_t; */
126
127/**
128 @brief
129 Data structure
130
131 @param[in] cmd_id Requested command
132*/
133typedef struct _km_set_milestone_req_t {
134 uint32 cmd_id;
135}__attribute__ ((packed)) km_set_milestone_req_t;
136
137/**
138 @brief
139 Data structure
140
141 @param[out] status Status of the request
142*/
143typedef struct _km_set_milestone_rsp_t {
144 int status;
145}__attribute__ ((packed)) km_set_milestone_rsp_t;
146
Sridhar Parasuramed003282015-07-10 09:50:12 -0700147/*
148 * Structures for delete_all cmd
149 */
150/*
151 @brief
152 Data structure
153
154 @param[in] cmd_id Requested command
155*/
156typedef struct _key_op_delete_all_req_t {
157 uint32 cmd_id;
158}__attribute__ ((packed)) key_op_delete_all_req_t;
159
160/*
161 @brief
162 Data structure
163
164 @param[out] status Status of the request
165*/
166typedef struct _key_op_delete_all_rsp_t {
167 int status;
168}__attribute__ ((packed)) key_op_delete_all_rsp_t;
169
Sridhar Parasuramce1e5722015-09-29 12:13:05 -0700170typedef enum _secure_write_prot_op_t
171{
172 SWP_READ_CONFIG,
173 SWP_WRITE_CONFIG,
174 SWP_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL
175} secure_write_prot_op_t;
176
177/*
178 @brief
179 Data structure
180
181 @param[in] cmd_id Command ID of the request
182 @param[in] op Secure write protect operation (enum from secure_write_prot_op_t)
183 @param[in] swp_write_data_offset Offset of data for SWP operation
184 @param[in] swp_write_data_len Length of data for SWP operation
185*/
186
187typedef struct _secure_write_prot_req_t
188{
189 uint32 cmd_id;
190 uint32 op;
191 uint32 swp_write_data_offset;
192 uint32 swp_write_data_len;
193}__attribute__((packed)) secure_write_prot_req_t;
194
195/*
196 @brief
197 Data structure
198
199 @param[out] status Status of the request
200 @param[out] swp_read_data_offset Offset of data for SWP operation
201 @param[out] swp_read_data_len Length of data for SWP operation
202*/
203
204typedef struct _secure_write_prot_rsp_t
205{
206 int status;
207 uint32 swp_read_data_offset;
208 uint32 swp_read_data_len;
209}__attribute__((packed)) secure_write_prot_rsp_t;
210
Channagoud Kadabi86b0c112016-03-16 19:23:16 -0700211/*
212 * * Structures for get_version
213 * */
214typedef struct _km_get_version_req_t
215{
216 uint32_t cmd_id;
217}__attribute__((packed)) km_get_version_req_t;
218
219typedef struct _km_get_version_rsp_t
220{
221 int status;
222 uint32_t major_version;
223 uint32_t minor_version;
224 uint32_t ta_major_version;
225 uint32_t ta_minor_version;
226}__attribute__((packed)) km_get_version_rsp_t;
227
228typedef struct _km_boot_state_t
229{
230 bool is_unlocked;
231 uint8_t public_key[32];
232 uint32_t color;
233 uint32_t system_version;
234 uint32_t system_security_level;
235}__attribute__((packed)) km_boot_state_t;
236
237/**
238 * @brief
239 * Data structure
240 * @param[in] cmd_id Requested command
241 * @param[in] boot_state_ofset Offset from the top of the struct.
242 * @param[in] boot_state_size Size of the Boot state
243 *
244 * The offset contains the following
245 * km_boot_state_t
246 **/
247typedef struct _km_set_boot_state_req_t
248{
249 uint32_t cmd_id;
250 uint32_t version;
251 uint32_t boot_state_offset;
252 uint32_t boot_state_size;
253}__attribute__((packed)) km_set_boot_state_req_t;
254
255/**
256 * @brief
257 * Data structure
258 *
259 * @param[out] status Status of the request
260 **/
261typedef struct _km_set_boot_state_rsp_t
262{
263 int status;
264}__attribute__((packed)) km_set_boot_state_rsp_t;
265
Sridhar Parasuram4d3f66d2015-07-27 15:34:18 -0700266#endif /* KM_MAIN_H */