DemesneGH commented on code in PR #178:
URL: 
https://github.com/apache/incubator-teaclave-trustzone-sdk/pull/178#discussion_r2034367397


##########
optee-utee/src/ta_session.rs:
##########
@@ -0,0 +1,150 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use core::ptr;
+use optee_utee_sys as raw;
+
+use crate::{Error, Result, TeeParams, Uuid};
+
+/// Represents a connection between a trusted application and another trusted 
application (can be user TA or pseudo TA).
+pub struct TaSession {
+    raw: raw::TEE_TASessionHandle,
+    target_uuid: Uuid,
+    default_timeout: u32,
+}
+
+impl TaSession {
+    /// Start configuring a new TA session with infinite timeout by default.
+    pub fn new(uuid: Uuid) -> Self {
+        Self {
+            raw: core::ptr::null_mut(),
+            target_uuid: uuid,
+            default_timeout: raw::TEE_TIMEOUT_INFINITE,
+        }
+    }
+
+    /// Set the default timeout for this session.
+    /// Can be called both before and after opening the session.
+    pub fn timeout(mut self, timeout: u32) -> Self {
+        self.default_timeout = timeout;
+        self
+    }
+
+    /// Set the default timeout for this session (mutable version).
+    /// Returns self to allow method chaining with invoke().
+    pub fn with_timeout(&mut self, timeout: u32) -> &mut Self {
+        self.default_timeout = timeout;
+        self
+    }
+
+    /// Open the session without parameters.
+    pub fn open(mut self) -> Result<Self> {
+        let mut err_origin: u32 = 0;
+        let mut raw_session: raw::TEE_TASessionHandle = core::ptr::null_mut();
+
+        match unsafe {
+            raw::TEE_OpenTASession(
+                self.target_uuid.as_raw_ptr(),
+                self.default_timeout,
+                0,
+                ptr::null_mut(),
+                &mut raw_session,
+                &mut err_origin,
+            )
+        } {
+            raw::TEE_SUCCESS => {
+                self.raw = raw_session;
+                Ok(self)
+            }
+            code => Err(Error::from_raw_error(code)),
+        }
+    }
+
+    /// Open the session with parameters.
+    pub fn open_with_params(mut self, params: &mut TeeParams) -> Result<Self> {
+        let mut err_origin: u32 = 0;
+        let mut raw_session: raw::TEE_TASessionHandle = core::ptr::null_mut();
+        let mut raw_params = params.as_raw();
+        let param_types = params.raw_param_types();
+
+        match unsafe {
+            raw::TEE_OpenTASession(
+                self.target_uuid.as_raw_ptr(),
+                self.default_timeout,
+                param_types,
+                raw_params.as_mut_ptr(),
+                &mut raw_session,
+                &mut err_origin,
+            )
+        } {
+            raw::TEE_SUCCESS => {
+                // Update the parameters with any results
+                params.update_from_raw(&raw_params);
+                self.raw = raw_session;
+                Ok(self)
+            }
+            code => Err(Error::from_raw_error(code)),
+        }
+    }
+
+    /// Get the default timeout value for this session.
+    pub fn get_default_timeout(&self) -> u32 {
+        self.default_timeout
+    }
+
+    /// Invokes a command with the provided parameters using the session's 
default timeout.
+    /// Returns the result directly without allowing further method chaining.
+    pub fn invoke_command(&mut self, command_id: u32, params: &mut TeeParams) 
-> Result<()> {
+        let mut err_origin: u32 = 0;
+        let mut raw_params = params.as_raw();
+        let param_types = params.raw_param_types();
+
+        match unsafe {
+            raw::TEE_InvokeTACommand(
+                self.raw,
+                self.default_timeout,
+                command_id,
+                param_types,
+                raw_params.as_mut_ptr(),
+                &mut err_origin,
+            )
+        } {
+            raw::TEE_SUCCESS => {
+                // Update the parameters with the results
+                params.update_from_raw(&raw_params);
+                trace_println!("TEE_InvokeTACommand: command_id: {} finished", 
command_id);
+                Ok(())
+            }
+            code => Err(Error::from_raw_error(code)),
+        }
+    }
+
+    pub fn as_mut_raw_ptr(&mut self) -> *mut raw::TEE_TASessionHandle {

Review Comment:
   It is not used, removed the function.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to