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::Time;
21 use optee_utee::{
22 ta_close_session, ta_create, ta_destroy, ta_invoke_command, ta_open_session, trace_println,
23 };
24 use optee_utee::{Error, ErrorKind, Parameters, Result};
25 use proto::Command;
26
27 #[ta_create]
create() -> Result<()>28 fn create() -> Result<()> {
29 trace_println!("[+] TA create");
30 Ok(())
31 }
32
33 #[ta_open_session]
open_session(_params: &mut Parameters) -> Result<()>34 fn open_session(_params: &mut Parameters) -> Result<()> {
35 trace_println!("[+] TA open session");
36 Ok(())
37 }
38
39 #[ta_close_session]
close_session()40 fn close_session() {
41 trace_println!("[+] TA close session");
42 }
43
44 #[ta_destroy]
destroy()45 fn destroy() {
46 trace_println!("[+] TA destroy");
47 }
48
49 #[ta_invoke_command]
invoke_command(cmd_id: u32, _params: &mut Parameters) -> Result<()>50 fn invoke_command(cmd_id: u32, _params: &mut Parameters) -> Result<()> {
51 trace_println!("[+] TA invoke command");
52 match Command::from(cmd_id) {
53 Command::Test => {
54 time()?;
55 Ok(())
56 }
57 _ => Err(Error::new(ErrorKind::BadParameters)),
58 }
59 }
60
time() -> Result<()>61 fn time() -> Result<()> {
62 let mut time = Time::new();
63 time.ree_time();
64 trace_println!("[+] Get REE time {}.", time);
65 trace_println!("[+] Now wait 1 second in TEE ...");
66 Time::wait(1000)?;
67 time.system_time();
68 trace_println!("[+] Get system time {}.", time);
69 time.seconds = time.seconds + 5;
70 time.set_ta_time()?;
71 let mut time2 = Time::new();
72 time2.ta_time()?;
73 trace_println!("[+] After set the TA time 5 seconds ahead of system time, new TA time {}.", time2);
74 Ok(())
75 }
76 // TA configurations
77 const TA_FLAGS: u32 = 0;
78 const TA_DATA_SIZE: u32 = 32 * 1024;
79 const TA_STACK_SIZE: u32 = 2 * 1024;
80 const TA_VERSION: &[u8] = b"0.1\0";
81 const TA_DESCRIPTION: &[u8] = b"This is a time API example.\0";
82 const EXT_PROP_VALUE_1: &[u8] = b"Time TA\0";
83 const EXT_PROP_VALUE_2: u32 = 0x0010;
84 const TRACE_LEVEL: i32 = 4;
85 const TRACE_EXT_PREFIX: &[u8] = b"TA\0";
86 const TA_FRAMEWORK_STACK_SIZE: u32 = 2048;
87
88 include!(concat!(env!("OUT_DIR"), "/user_ta_header.rs"));
89