1 /*
2 * Copyright (C) 2022 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 #define TLOG_TAG "boot_done_client"
18
19 #include <assert.h>
20 #include <lib/tipc/tipc.h>
21 #include <string.h>
22 #include <trusty_log.h>
23 #include <uapi/err.h>
24
25 #include <BpBootDone.h>
26 #include <lib/tidl/lk_strerror.h>
27
28 /**
29 * boot_done_connect()
30 * @param boot_done reference to the proxy instance
31 *
32 * Return: 0 on success, or an error code < 0 on failure.
33 */
boot_done_connect(BpBootDone & boot_done)34 int boot_done_connect(BpBootDone& boot_done) {
35 int rc;
36 rc = boot_done.connect(IBootDone::PORT, IPC_CONNECT_WAIT_FOR_PORT);
37 if (rc < 0) {
38 TLOGE("Failed to connect to %s: %d\n", IBootDone::PORT, rc);
39 return rc;
40 }
41 return rc;
42 }
43
44 /**
45 * boot_done_set_boot_done()
46 *
47 * @return: 0 on success, or an error code < 0 on failure.
48 */
boot_done_set_boot_done(void)49 extern "C" int boot_done_set_boot_done(void) {
50 int rc;
51 BpBootDone boot_done;
52 rc = boot_done_connect(boot_done);
53 if (rc < 0) {
54 return rc;
55 }
56
57 rc = boot_done.set_boot_done();
58 if (rc != NO_ERROR) {
59 TLOGE("set_boot_done failed - %s(%d).\n", lk_strerror(rc), rc);
60 return rc;
61 }
62 return rc;
63 }
64