• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 //! Setting up the server for the Hello World Trusted HAL service.
18 use crate::hand_over_service::HandoverService;
19 use crate::hello_world_trusted_service::HelloWorldService;
20 use rpcbinder::RpcServer;
21 use std::ffi::CStr;
22 use std::sync::Arc;
23 use tipc::raw::{EventLoop, HandleSetWrapper};
24 use tipc::{PortCfg, TipcError};
25 
26 // Port for the handover service for the HelloWorld trusted service
27 pub const HANDOVER_SERVICE_PORT: &CStr = c"com.android.trusty.rust.handover.hello.service.V1";
28 
29 // Port for the HelloWorld trusted service
30 pub const HELLO_WORLD_TRUSTED_SERVICE_PORT: &CStr = c"com.android.trusty.rust.hello.service.V1";
31 
main_loop() -> Result<(), TipcError>32 pub fn main_loop() -> Result<(), TipcError> {
33     let handle_set_wrapper = Arc::new(HandleSetWrapper::new()?);
34     let handle_set_wrapper_clone = Arc::clone(&handle_set_wrapper);
35     let helloworld_binder = HelloWorldService::new_binder();
36     let helloworld_rpc_service = Arc::new(RpcServer::new(helloworld_binder.as_binder()));
37 
38     // Only the AuthMgr BE TA is allowed to connect
39     let handover_service_port_cfg =
40         PortCfg::new_raw(HANDOVER_SERVICE_PORT.into()).allow_ta_connect();
41 
42     let cb_per_session = move |uuid| {
43         HandoverService::new_handover_session(
44             uuid,
45             Arc::downgrade(&handle_set_wrapper),
46             Arc::clone(&helloworld_rpc_service),
47         )
48     };
49 
50     let handover_rpc_service = RpcServer::new_per_session(cb_per_session);
51     let _port_wrapper = handle_set_wrapper_clone
52         .add_port(&handover_service_port_cfg, Arc::new(handover_rpc_service))?;
53     let event_loop = EventLoop::new(handle_set_wrapper_clone.clone());
54     event_loop.run()
55 }
56