aboutsummaryrefslogtreecommitdiff
path: root/main.c
blob: 077df39ef803a07a0211dd44618ecf4e30b30004 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
 * Copyright (C) 2015-2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#define TLOG_TAG "secure-storage"

#include <stdint.h>
#include <stdlib.h>

#include <interface/storage/storage.h>
#include <lib/tipc/tipc.h>
#include <lk/err_ptr.h>
#include <trusty_log.h>

#include "block_cache.h"
#include "crypt.h"
#include "ipc.h"
#include "proxy.h"
#include "tipc_limits.h"

#define SS_ERR(args...) fprintf(stderr, "ss: " args)

int main(void) {
    struct ipc_port_context ctx = {
            .ops = {.on_connect = proxy_connect},
    };
    uint32_t acl_flags = IPC_PORT_ALLOW_TA_CONNECT | IPC_PORT_ALLOW_NS_CONNECT;

    crypt_init();
    block_cache_init();

    struct tipc_hset* hset = tipc_hset_create();
    if (IS_ERR(hset)) {
        TLOGE("Failed to create handle set (%d)\n", PTR_ERR(hset));
        return EXIT_FAILURE;
    }

    int rc = ipc_port_create(hset, &ctx, STORAGE_DISK_PROXY_PORT, 1,
                             STORAGE_MAX_BUFFER_SIZE, acl_flags);
    if (rc < 0) {
        SS_ERR("fatal: unable to initialize proxy endpoint (%d)\n", rc);
        return rc;
    }

    rc = tipc_run_event_loop(hset);
    ipc_port_destroy(&ctx);
    return rc;
}