1 /*
2  * Copyright (C) 2024 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 #pragma once
17 
18 #include <lib/tipc/tipc.h>
19 #include <trusty_ipc.h>
20 
21 #include "block_device_tipc.h"
22 #include "ipc.h"
23 #include "tipc_ns.h"
24 
25 /**
26  * struct client_port_context
27  * @tr_state:   Pointer to the backing filesystem.
28  * @client_ctx: Context for the port opened to clients.
29  */
30 struct client_port_context {
31     struct fs* tr_state;
32     struct ipc_port_context client_ctx;
33 };
34 
35 /**
36  * struct storage_tipc_service
37  * @fs_rpmb:      Client port for TP.
38  * @fs_rpmb_boot: Client port for TDEA.
39  * @fs_tdp:       Client port for TDP. If $HAS_FS_TDP is undefined, aliases TP.
40  *                Only initialized and available if ns is available.
41  * @fs_nsp:       Client port for NSP. If $HAS_FS_NSP is undefined, aliases TDP.
42  *                Only initialized and available if ns is available.
43  * @fs_ns:        Client port for TD. Only initialized and available if ns is
44  *                available.
45  */
46 struct storage_tipc_service {
47     struct client_port_context fs_rpmb;
48     struct client_port_context fs_rpmb_boot;
49 
50     struct client_port_context fs_tdp;
51     struct client_port_context fs_nsp;
52     struct client_port_context fs_ns;
53 };
54 
55 /**
56  * storage_tipc_service_init() - Initialize a &struct storage_tipc_service
57  *
58  * Opens tipc ports through which clients can make changes to storage.
59  *
60  * @self: Out param. Will contain the newly initialized &struct
61  * storage_tipc_service.
62  * @ctx: &struct block_device_tipc containing the filesystems backing the
63  * client ports.
64  * @hset: Handle set to handle incoming messages on the client ports.
65  */
66 int storage_tipc_service_init(struct storage_tipc_service* self,
67                               struct block_device_tipc* ctx,
68                               struct tipc_hset* hset);
69 
70 /**
71  * storage_tipc_service_destroy() - Deinitialize a &struct storage_tipc_service
72  *
73  * Closes all tipc client ports that were opened by storage_tipc_service_init().
74  *
75  * @self: The &struct storage_tipc_service to destroy. The backing memory is not
76  * freed.
77  * @ctx: The &struct block_device_tipc used to init @self.
78  */
79 void storage_tipc_service_destroy(struct storage_tipc_service* self,
80                                   struct block_device_tipc* ctx);