1 /*
2  * Copyright (C) 2015 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 <trusty_ipc.h>
18 #include <uapi/trusty_uuid.h>
19 
20 #include "aidl_service.h"
21 #include "block_device_tipc.h"
22 #include "crypt.h"
23 #include "ipc.h"
24 #include "tipc_service.h"
25 
26 #include "crypt.h"
27 #include "ipc.h"
28 #include "tipc_service.h"
29 
30 struct storage_service {
31     bool initialized;
32     struct key key;
33     struct block_device_tipc block_device;
34     struct storage_service_aidl_context aidl;
35 };
36 
37 #define STORAGE_SERVICE_INITIAL_VALUE(self)                        \
38     (struct storage_service) {                                     \
39         .initialized = false,                                      \
40         .aidl = STORAGE_SERVICE_AIDL_CONTEXT_INITIAL_VALUE(.aidl), \
41     }
42 
43 /* SSSC (Secure Storage Session Context) */
44 #define STORAGE_SESSION_MAGIC 0x53535343
45 
46 /**
47  * storage_session - Session that exists for the duration of a proxy connection
48  * @magic:        a sentinel value used for checking for data corruption.
49  *                Initialized to STORAGE_SESSION_MAGIC.
50  * @service:      storage app state that persists across connections
51  * @tipc:         tipc service accepting client connections and requests
52  * @proxy_ctx:    the context object on the proxy channel
53  */
54 struct storage_session {
55     uint32_t magic;
56     struct storage_service* service;
57     struct storage_tipc_service tipc;
58 
59     struct ipc_channel_context proxy_ctx;
60 };
61 
62 /**
63  * proxy_connect_context - Context for opening a connection to storageproxy
64  *
65  * @service: storage app state
66  * @tipc_ctx: context object for the proxy port
67  */
68 struct proxy_connect_context {
69     struct storage_service service;
70     struct ipc_port_context tipc_ctx;
71 };
72 
73 /*
74  * @parent_ctx must be a pointer to the &tipc_ctx member of a
75  * &struct proxy_connect_context
76  */
77 struct ipc_channel_context* proxy_connect(struct ipc_port_context* parent_ctx,
78                                           const uuid_t* peer_uuid,
79                                           handle_t chan_handle);
80 
81 /** proxy_destroy() - Clean up a &struct proxy_connect_context
82  *
83  * Does not free @self.
84  *
85  * @self: The proxy context to delete. Must have been previously connected to
86  * the proxy (see &proxy_connect()), but no longer have an active connection
87  * (see &proxy_disconnect()).
88  */
89 void proxy_destroy(struct proxy_connect_context* self);