• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015-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 #define TLOG_TAG "secure-storage"
17 
18 #include <stdint.h>
19 #include <stdlib.h>
20 
21 #include <interface/storage/storage.h>
22 #include <lib/tipc/tipc.h>
23 #include <lk/err_ptr.h>
24 #include <trusty_log.h>
25 
26 #include "aidl_service.h"
27 #include "block_cache.h"
28 #include "crypt.h"
29 #include "ipc.h"
30 #include "proxy.h"
31 #include "storage_limits.h"
32 #include "error_reporting.h"
33 
34 #define SS_ERR(args...) fprintf(stderr, "ss: " args)
35 
main(void)36 int main(void) {
37     struct proxy_connect_context ctx = {
38             .service = STORAGE_SERVICE_INITIAL_VALUE(.service),
39             .tipc_ctx = {.ops = {.on_connect = proxy_connect}},
40     };
41     uint32_t acl_flags = IPC_PORT_ALLOW_TA_CONNECT | IPC_PORT_ALLOW_NS_CONNECT;
42 
43     crypt_init();
44     block_cache_init();
45 
46     struct tipc_hset* hset = tipc_hset_create();
47     if (IS_ERR(hset)) {
48         TLOGE("Failed to create handle set (%d)\n", PTR_ERR(hset));
49         return EXIT_FAILURE;
50     }
51 
52     int rc = ipc_port_create(hset, &ctx.tipc_ctx, STORAGE_DISK_PROXY_PORT, 1,
53                              STORAGE_MAX_BUFFER_SIZE, acl_flags);
54     if (rc < 0) {
55         SS_ERR("fatal: unable to initialize proxy endpoint (%d)\n", rc);
56         return rc;
57     }
58 
59     rc = connect_metrics_ta();
60     if(rc != NO_ERROR)
61     {
62         SS_ERR("fatal: unable to connect to metrics TA (%d)\n", rc);
63         return rc;
64     }
65     rc = tipc_run_event_loop(hset);
66     proxy_destroy(&ctx);
67     return rc;
68 }
69