1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef TRUSTY_INTERFACE_AVB_H_
26 #define TRUSTY_INTERFACE_AVB_H_
27 
28 #include <trusty/sysdeps.h>
29 
30 #define AVB_PORT "com.android.trusty.avb"
31 #define AVB_MAX_BUFFER_LENGTH 2048
32 
33 enum avb_command {
34     AVB_REQ_SHIFT = 1,
35     AVB_RESP_BIT = 1,
36 
37     READ_ROLLBACK_INDEX = (0 << AVB_REQ_SHIFT),
38     WRITE_ROLLBACK_INDEX = (1 << AVB_REQ_SHIFT),
39     AVB_GET_VERSION = (2 << AVB_REQ_SHIFT),
40     READ_PERMANENT_ATTRIBUTES = (3 << AVB_REQ_SHIFT),
41     WRITE_PERMANENT_ATTRIBUTES = (4 << AVB_REQ_SHIFT),
42     READ_LOCK_STATE = (5 << AVB_REQ_SHIFT),
43     WRITE_LOCK_STATE = (6 << AVB_REQ_SHIFT),
44     LOCK_BOOT_STATE = (7 << AVB_REQ_SHIFT),
45 };
46 
47 /**
48  * enum avb_error - error codes for AVB protocol
49  * @AVB_ERROR_NONE:         All OK
50  * @AVB_ERROR_INVALID:      Invalid input
51  * @AVB_ERROR_INTERNAL:     Error occurred during an operation in Trusty
52  */
53 enum avb_error {
54     AVB_ERROR_NONE = 0,
55     AVB_ERROR_INVALID = 1,
56     AVB_ERROR_INTERNAL = 2,
57 };
58 
59 /**
60  * avb_message - Serial header for communicating with AVB server
61  * @cmd:     the command. Payload must be a serialized buffer of the
62  *           corresponding request object.
63  * @result:  resulting error code for message, one of avb_error.
64  * @payload: start of the serialized command specific payload
65  */
66 struct avb_message {
67     uint32_t cmd;
68     uint32_t result;
69     uint8_t payload[0];
70 };
71 
72 /**
73  * avb_rollback_req - request format for [READ|WRITE]_ROLLBACK_INDEX
74  * @value: value to write to rollback index. Ignored for read.
75  * @slot:  slot number of rollback index to write
76  */
77 struct avb_rollback_req {
78     uint64_t value;
79     uint32_t slot;
80 } TRUSTY_ATTR_PACKED;
81 
82 /**
83  * avb_rollback_resp - response format for [READ|WRITE]_ROLLBACK_INDEX.
84  * @value: value of the requested rollback index.
85  */
86 struct avb_rollback_resp {
87     uint64_t value;
88 };
89 
90 /**
91  * avb_get_version_resp - response format for AVB_GET_VERSION.
92  * @version: version of AVB message format
93  */
94 struct avb_get_version_resp {
95     uint32_t version;
96 };
97 
98 #endif /* TRUSTY_INTERFACE_AVB_H_ */
99