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_main]
19 
20 use optee_utee::{
21     ta_close_session, ta_create, ta_destroy, ta_invoke_command, ta_open_session, trace_println,
22 };
23 use optee_utee::{Error, ErrorKind, Parameters, Result};
24 use proto::Command;
25 
26 #[ta_create]
create() -> Result<()>27 fn create() -> Result<()> {
28     trace_println!("[+] TA create");
29     Ok(())
30 }
31 
32 #[ta_open_session]
open_session(_params: &mut Parameters) -> Result<()>33 fn open_session(_params: &mut Parameters) -> Result<()> {
34     trace_println!("[+] TA open session");
35     Ok(())
36 }
37 
38 #[ta_close_session]
close_session()39 fn close_session() {
40     trace_println!("[+] TA close session");
41 }
42 
43 #[ta_destroy]
destroy()44 fn destroy() {
45     trace_println!("[+] TA destroy");
46 }
47 
48 #[ta_invoke_command]
invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()>49 fn invoke_command(cmd_id: u32, params: &mut Parameters) -> Result<()> {
50     trace_println!("[+] TA invoke command");
51     let mut values = unsafe { params.0.as_value().unwrap() };
52     match Command::from(cmd_id) {
53         Command::IncValue => {
54             values.set_a(values.a() + 100);
55             Ok(())
56         }
57         Command::DecValue => {
58             values.set_a(values.a() - 100);
59             Ok(())
60         }
61         _ => Err(Error::new(ErrorKind::BadParameters)),
62     }
63 }
64 
65 // TA configurations
66 const TA_FLAGS: u32 = 0;
67 const TA_DATA_SIZE: u32 = 32 * 1024;
68 const TA_STACK_SIZE: u32 = 2 * 1024;
69 const TA_VERSION: &[u8] = b"0.1\0";
70 const TA_DESCRIPTION: &[u8] = b"This is a hello world example.\0";
71 const EXT_PROP_VALUE_1: &[u8] = b"Hello World TA\0";
72 const EXT_PROP_VALUE_2: u32 = 0x0010;
73 const TRACE_LEVEL: i32 = 4;
74 const TRACE_EXT_PREFIX: &[u8] = b"TA\0";
75 const TA_FRAMEWORK_STACK_SIZE: u32 = 2048;
76 
77 include!(concat!(env!("OUT_DIR"), "/user_ta_header.rs"));
78