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::{Error, Result, Uuid}; 19 use optee_utee_sys as raw; 20 21 pub struct LoadablePlugin { 22 uuid: Uuid 23 } 24 25 impl LoadablePlugin { new(uuid: &Uuid) -> Self26 pub fn new(uuid: &Uuid) -> Self { 27 Self { uuid: uuid.to_owned() } 28 } invoke(&mut self, command_id: u32, subcommand_id: u32, data: &[u8]) -> Result<Vec<u8>>29 pub fn invoke(&mut self, command_id: u32, subcommand_id: u32, data: &[u8]) -> Result<Vec<u8>> { 30 let raw_uuid: Uuid = self.uuid; 31 let mut outlen: u32 = 0; 32 match unsafe { 33 raw::tee_invoke_supp_plugin( 34 raw_uuid.as_raw_ptr(), 35 command_id as u32, 36 subcommand_id as u32, 37 data.as_ptr() as _, 38 data.len() as u32, 39 &mut outlen as *mut u32, 40 ) 41 } { 42 raw::TEE_SUCCESS => { 43 assert!(outlen <= (data.len() as u32)); 44 let mut outbuf = vec![0; outlen as usize]; 45 outbuf.copy_from_slice(&data[..(outlen as usize)]); 46 47 Ok(outbuf) 48 }, 49 code => Err(Error::from_raw_error(code)), 50 } 51 52 } 53 } 54