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 use crate::{Param, ParamTypes}; 19 use optee_teec_sys as raw; 20 use std::marker::PhantomData; 21 use std::mem; 22 23 /// This type defines the payload of either an open session operation or an 24 /// invoke command operation. It is also used for cancellation of operations, 25 /// which may be desirable even if no payload is passed. 26 pub struct Operation<A, B, C, D> { 27 pub raw: raw::TEEC_Operation, 28 phantom0: PhantomData<A>, 29 phantom1: PhantomData<B>, 30 phantom2: PhantomData<C>, 31 phantom3: PhantomData<D>, 32 } 33 34 impl<A: Param, B: Param, C: Param, D: Param> Operation<A, B, C, D> { new(started: u32, mut p0: A, mut p1: B, mut p2: C, mut p3: D) -> Operation<A, B, C, D>35 pub fn new(started: u32, mut p0: A, mut p1: B, mut p2: C, mut p3: D) -> Operation<A, B, C, D> { 36 let mut raw_op: raw::TEEC_Operation = unsafe { mem::zeroed() }; 37 raw_op.started = started; 38 raw_op.paramTypes = ParamTypes::new( 39 p0.param_type(), 40 p1.param_type(), 41 p2.param_type(), 42 p3.param_type(), 43 ) 44 .into(); 45 raw_op.params = [p0.into_raw(), p1.into_raw(), p2.into_raw(), p3.into_raw()]; 46 Operation { 47 raw: raw_op, 48 phantom0: PhantomData, 49 phantom1: PhantomData, 50 phantom2: PhantomData, 51 phantom3: PhantomData, 52 } 53 } 54 as_mut_raw_ptr(&mut self) -> *mut raw::TEEC_Operation55 pub fn as_mut_raw_ptr(&mut self) -> *mut raw::TEEC_Operation { 56 &mut self.raw 57 } 58 parameters(&self) -> (A, B, C, D)59 pub fn parameters(&self) -> (A, B, C, D) { 60 let (f0, f1, f2, f3) = ParamTypes::from(self.raw.paramTypes).into_flags(); 61 ( 62 A::from_raw(self.raw.params[0], f0), 63 B::from_raw(self.raw.params[1], f1), 64 C::from_raw(self.raw.params[2], f2), 65 D::from_raw(self.raw.params[3], f3), 66 ) 67 } 68 } 69