1 /*
2 * Copyright (C) 2019 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 #include <app_mgmt_port_consts.h>
18 #include <app_mgmt_test.h>
19 #include <stdbool.h>
20 #include <stddef.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <trusty_ipc.h>
25 #include <uapi/err.h>
26
27 #define TLOG_TAG "boot-start-srv"
28
main(void)29 int main(void) {
30 int rc;
31 handle_t phandle;
32 handle_t chandle;
33 uevent_t uevt;
34 uuid_t peer_uuid;
35
36 rc = port_create(BOOT_START_PORT, 1, 1, IPC_PORT_ALLOW_TA_CONNECT);
37 if (rc < 0) {
38 TLOGI("failed (%d) to create ctrl port\n", rc);
39 return rc;
40 }
41 phandle = (handle_t)rc;
42
43 while (true) {
44 rc = wait(phandle, &uevt, INFINITE_TIME);
45 if (rc != NO_ERROR || !(uevt.event & IPC_HANDLE_POLL_READY)) {
46 TLOGI("Port wait failed(%d) event:%d handle:%d\n", rc, uevt.event,
47 phandle);
48 return rc;
49 }
50
51 rc = accept(uevt.handle, &peer_uuid);
52 if (rc == ERR_CHANNEL_CLOSED || rc == ERR_NO_MSG) {
53 /* client already closed connection or no message, nothing to do */
54 continue;
55 }
56 if (rc < 0) {
57 TLOGI("Accept failed %d\n", rc);
58 return rc;
59 }
60
61 chandle = (handle_t)rc;
62
63 rc = close(chandle);
64 if (rc < 0) {
65 TLOGI("Close failed(%d) handle:%d\n", rc, chandle);
66 return rc;
67 }
68 }
69
70 return 0;
71 }
72