1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <lk/compiler.h>
20 #include <stdint.h>
21 
22 __BEGIN_CDECLS
23 
24 #define APPLOADER_PORT "com.android.trusty.apploader"
25 
26 enum apploader_command : uint32_t {
27     APPLOADER_REQ_SHIFT = 1,
28     APPLOADER_RESP_BIT = 1,
29 
30     APPLOADER_CMD_LOAD_APPLICATION = (0 << APPLOADER_REQ_SHIFT),
31     APPLOADER_CMD_GET_VERSION = (1 << APPLOADER_REQ_SHIFT),
32     APPLOADER_CMD_UNLOAD_APPLICATION = (2 << APPLOADER_REQ_SHIFT),
33 };
34 
35 /**
36  * enum apploader_error - error codes for apploader
37  * @APPLOADER_NO_ERROR:                 no error
38  * @APPLOADER_ERR_UNKNOWN_CMD:          unknown or not implemented command
39  * @APPLOADER_ERR_INVALID_CMD:          invalid arguments or inputs passed to
40  *                                      command
41  * @APPLOADER_ERR_NO_MEMORY:            failed to allocate memory
42  * @APPLOADER_ERR_VERIFICATION_FAILED:  failed to verify input application
43  *                                      package for any reason, e.g., signature
44  *                                      verification failed
45  * @APPLOADER_ERR_LOADING_FAILED:       Trusty kernel or apploader service
46  *                                      failed to load application
47  * @APPLOADER_ERR_ALREADY_EXISTS:       application has already been loaded
48  * @APPLOADER_ERR_INTERNAL:             miscellaneous or internal apploader
49  *                                      error not covered by the above
50  * @APPLOADER_ERR_INVALID_VERSION:      invalid application version
51  * @APPLOADER_ERR_POLICY_VIOLATION:     signature verification succeeded but
52  *                                      key+manifest combination not allowed
53  *                                      by app loader policy engine
54  * @APPLOADER_ERR_NOT_ENCRYPTED:        unmet application encryption requirement
55  */
56 enum apploader_error : uint32_t {
57     APPLOADER_NO_ERROR = 0,
58     APPLOADER_ERR_UNKNOWN_CMD,
59     APPLOADER_ERR_INVALID_CMD,
60     APPLOADER_ERR_NO_MEMORY,
61     APPLOADER_ERR_VERIFICATION_FAILED,
62     APPLOADER_ERR_LOADING_FAILED,
63     APPLOADER_ERR_ALREADY_EXISTS,
64     APPLOADER_ERR_INTERNAL,
65     APPLOADER_ERR_INVALID_VERSION,
66     APPLOADER_ERR_POLICY_VIOLATION,
67     APPLOADER_ERR_NOT_ENCRYPTED,
68 };
69 
70 /**
71  * apploader_header - Serial header for communicating with apploader
72  * @cmd: the command; one of &enum apploader_command values.
73  */
74 struct apploader_header {
75     uint32_t cmd;
76 } __PACKED;
77 
78 /**
79  * apploader_load_app_req - Serial arguments for LOAD_APPLICATION command
80  * @package_size: size of the application package.
81  *
82  * Load an application from a given memory region. The request message also
83  * contains a handle for a dmabuf that contains the application package.
84  *
85  * The response is a &struct apploader_resp with the error code or
86  * %APPLOADER_NO_ERROR on success.
87  */
88 struct apploader_load_app_req {
89     uint64_t package_size;
90 } __PACKED;
91 
92 /**
93  * apploader_resp - Common header for all apploader responses
94  * @hdr - header with command value.
95  * @error - error code returned by peer; one of &enum apploader_error values.
96  *
97  * This structure is followed by the response-specific payload, if the command
98  * has one.
99  */
100 struct apploader_resp {
101     struct apploader_header hdr;
102     uint32_t error;
103 } __PACKED;
104 
105 __END_CDECLS
106