• Home
  • History
  • Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 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 #![no_std]
18 
19 use hwwsk::{HwWskReq, HWWSK_MAX_MSG_SIZE};
20 use tipc::{ConnectResult, Handle, Manager, MessageResult, PortCfg, Service, Uuid};
21 use trusty_std::{self, vec};
22 
23 struct HwWskService;
24 
25 impl Service for HwWskService {
26     type Connection = ();
27     type Message = HwWskReq;
28 
on_connect( &self, _port: &PortCfg, _handle: &Handle, _peer: &Uuid, ) -> tipc::Result<ConnectResult<Self::Connection>>29     fn on_connect(
30         &self,
31         _port: &PortCfg,
32         _handle: &Handle,
33         _peer: &Uuid,
34     ) -> tipc::Result<ConnectResult<Self::Connection>> {
35         /*
36             TODO: implement any nuance of extant hwwsk service
37         */
38         Ok(ConnectResult::Accept(()))
39     }
40 
on_message( &self, _connection: &Self::Connection, handle: &Handle, msg: Self::Message, ) -> tipc::Result<MessageResult>41     fn on_message(
42         &self,
43         _connection: &Self::Connection,
44         handle: &Handle,
45         msg: Self::Message,
46     ) -> tipc::Result<MessageResult> {
47         /*
48             TODO: this is a temporary placeholder for
49             a reference implementation of the hwwsk service.
50 
51             - parse incoming cmd
52             - generate, import, or export key depending on request
53         */
54         let response = msg.response_from(0, vec![]);
55         handle.send(&response)?;
56         Ok(MessageResult::MaintainConnection)
57     }
58 }
59 
main()60 fn main() {
61     trusty_log::init();
62 
63     let cfg = PortCfg::new("com.android.trusty.hwwsk")
64         .expect("Could not create port config")
65         .allow_ta_connect();
66 
67     // TODO: determine if it's necessary for the non-secure world to connect
68     // .allow_ns_connect();
69 
70     let service = HwWskService {};
71 
72     let buffer = [0u8; HWWSK_MAX_MSG_SIZE as usize];
73     Manager::<_, _, 1, 4>::new(service, cfg, buffer)
74         .expect("Could not create service manager")
75         .run_event_loop()
76         .expect("Hwwsk service quit unexpectedly");
77 }
78