1 // Licensed to the Apache Software Foundation (ASF) under one
2 // or more contributor license agreements.  See the NOTICE file
3 // distributed with this work for additional information
4 // regarding copyright ownership.  The ASF licenses this file
5 // to you under the Apache License, Version 2.0 (the
6 // "License"); you may not use this file except in compliance
7 // with the License.  You may obtain a copy of the License at
8 //
9 //   http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing,
12 // software distributed under the License is distributed on an
13 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 // KIND, either express or implied.  See the License for the
15 // specific language governing permissions and limitations
16 // under the License.
17 
18 #![no_std]
19 #![no_main]
20 #![feature(c_size_t)]
21 
22 extern crate alloc;
23 
24 use optee_utee::{
25     ta_close_session, ta_create, ta_destroy, ta_invoke_command, ta_open_session, trace_println,
26 };
27 use optee_utee::{Error, ErrorKind, Parameters, Result, Uuid};
28 use optee_utee::{LoadablePlugin};
29 use proto::{Command, PluginCommand, PLUGIN_SUBCMD_NULL, PLUGIN_UUID};
30 
31 #[ta_create]
create() -> Result<()>32 fn create() -> Result<()> {
33     trace_println!("[+] TA create");
34     Ok(())
35 }
36 
37 #[ta_open_session]
open_session(_params: &mut Parameters) -> Result<()>38 fn open_session(_params: &mut Parameters) -> Result<()> {
39     trace_println!("[+] TA open session");
40     Ok(())
41 }
42 
43 #[ta_close_session]
close_session()44 fn close_session() {
45     trace_println!("[+] TA close session");
46 }
47 
48 #[ta_destroy]
destroy()49 fn destroy() {
50     trace_println!("[+] TA destroy");
51 }
52 
53 #[ta_invoke_command]
invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()>54 fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
55     trace_println!("[+] TA invoke command");
56     let mut p0 = unsafe { params.0.as_memref().unwrap() };
57     let inbuf = p0.buffer().to_vec();
58     trace_println!("[+] TA received value {:?} then send to plugin", p0.buffer());
59     let uuid = Uuid::parse_str(PLUGIN_UUID).unwrap();
60 
61     match Command::from(cmd_id) {
62         Command::Ping => {
63             let mut plugin = LoadablePlugin::new(&uuid);
64             let outbuf = plugin.invoke(
65                 PluginCommand::Print as u32,
66                 PLUGIN_SUBCMD_NULL,
67                 &inbuf
68             ).unwrap();
69 
70             trace_println!("[+] TA received out value {:?} outlen {:?}", outbuf, outbuf.len());
71             trace_println!("[+] TA call invoke_supp_plugin finished");
72 
73             Ok(())
74         }
75         _ => Err(Error::new(ErrorKind::BadParameters)),
76     }
77 }
78 
79 // TA configurations
80 const TA_FLAGS: u32 = 0;
81 const TA_DATA_SIZE: u32 = 32 * 1024;
82 const TA_STACK_SIZE: u32 = 2 * 1024;
83 const TA_VERSION: &[u8] = b"0.1\0";
84 const TA_DESCRIPTION: &[u8] = b"This is a plugin example.\0";
85 const EXT_PROP_VALUE_1: &[u8] = b"Plugin TA\0";
86 const EXT_PROP_VALUE_2: u32 = 0x0010;
87 const TRACE_LEVEL: i32 = 4;
88 const TRACE_EXT_PREFIX: &[u8] = b"TA\0";
89 const TA_FRAMEWORK_STACK_SIZE: u32 = 2048;
90 
91 include!(concat!(env!("OUT_DIR"), "/user_ta_header.rs"));
92