1 /*
2  * Copyright (C) 2016 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 "hwcrypto_srv"
18 
19 #include <assert.h>
20 #include <inttypes.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <uapi/err.h>
24 
25 #include <hwcrypto/hwrng_dev.h>
26 #include <lib/tipc/tipc.h>
27 #include <lk/err_ptr.h>
28 #include <trusty_log.h>
29 
30 #include "hwkey_srv_priv.h"
31 #include "hwrng_srv_priv.h"
32 
33 #include "keybox/srv.h"
34 
35 /*
36  *  Main application event loop
37  */
main(void)38 int main(void) {
39     int rc;
40     struct tipc_hset* hset;
41 
42     TLOGD("Initializing\n");
43 
44     hset = tipc_hset_create();
45     if (IS_ERR(hset)) {
46         rc = PTR_ERR(hset);
47         TLOGE("tipc_hset_create failed (%d)\n", rc);
48         goto out;
49     }
50 
51     /* initialize service providers */
52 #if WITH_HWCRYPTO_HWRNG
53     rc = hwrng_start_service(hset);
54     if (rc != NO_ERROR) {
55         TLOGE("Failed (%d) to initialize HWRNG service\n", rc);
56         goto out;
57     }
58 #endif
59 
60     rc = hwkey_init_srv_provider(hset);
61     if (rc != NO_ERROR) {
62         TLOGE("Failed (%d) to initialize HwKey service\n", rc);
63         goto out;
64     }
65 
66 #if defined(WITH_FAKE_KEYBOX)
67     rc = keybox_start_service(hset);
68     if (rc != NO_ERROR) {
69         TLOGE("Failed (%d) to initialize Keybox service\n", rc);
70         goto out;
71     }
72 #endif
73 
74     TLOGD("enter main event loop\n");
75 
76     /* enter main event loop */
77     rc = tipc_run_event_loop(hset);
78 
79 out:
80     return rc;
81 }
82