首页 > 其他分享 >optee CA和TA 例程 - 值传递

optee CA和TA 例程 - 值传递

时间:2024-07-31 10:58:08浏览次数:11  
标签:optee 例程 CA TEE value TEEC params PARAM void

CA

如下实现一个简单的CA代码示例,它使用了不同的Params类型

#include <err.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

/* OP-TEE TEE client API (built by optee_client) */
#include <tee_client_api.h>

/* To the the UUID (found the the TA's h-file(s)) */
#include <hello_world_ta.h>

#define CMD_TEST_VALUE  0x001 
#define CMD_TEST_BUFFER 0x002
#define TA_HELLO_WORLD_UUID  { 0xc02ffd4f, 0xa7a3, 0xb1c3,
									{ 0x92, 0x08, 0x37, 0x06, 0xe4, 0xc8, 0xb1, 0xaf } }
int main(int argc ,char **argv)
{
        TEEC_Result res;
        TEEC_Context ctx;
        TEEC_Session sess;
        TEEC_Operation op;
        TEEC_UUID uuid = TA_HELLO_WORLD_UUID;
        uint32_t err_origin;

        /* Initialize a context connecting us to the TEE */
        res = TEEC_InitializeContext(NULL, &ctx);
        if (res != TEEC_SUCCESS)
                errx(1, "TEEC_InitializeContext failed with code 0x%x", res);

        /*
         * Open a session
         */
        res = TEEC_OpenSession(&ctx, &sess, &uuid,
                               TEEC_LOGIN_PUBLIC, NULL, NULL, &err_origin);
        if (res != TEEC_SUCCESS)
                errx(1, "TEEC_Opensession failed with code 0x%x origin 0x%x",
                        res, err_origin);

        /* Clear the TEEC_Operation struct */
        memset(&op, 0, sizeof(op));
		/*
         * Prepare the argument. 
         */
        op.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_VALUE_OUTPUT,
                                         TEEC_VALUE_INOUT, TEEC_NONE);
        op.params[0].value.a = 10;
		op.params[2].value.a = 11;

        res = TEEC_InvokeCommand(&sess, CMD_TEST_VALUE, &op,
                                 &err_origin);
        if (res != TEEC_SUCCESS)
                errx(1, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x",
                        res, err_origin);
     

        TEEC_CloseSession(&sess);

        TEEC_FinalizeContext(&ctx);

        return 0;
}

TA

如下实现一个简单的TA代码示例,它实现了不同的Params类型,处理CA数据

#include <tee_internal_api.h>
#include <tee_internal_api_extensions.h>

#include <hello_world_ta.h>


TEE_Result TA_CreateEntryPoint(void)
{
        DMSG("has been called");

        return TEE_SUCCESS;
}


void TA_DestroyEntryPoint(void)
{
        DMSG("has been called");
}

TEE_Result TA_OpenSessionEntryPoint(uint32_t param_types,
                TEE_Param __maybe_unused params[4],
                void __maybe_unused **sess_ctx)
{
        uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_NONE,
                                                   TEE_PARAM_TYPE_NONE,
                                                   TEE_PARAM_TYPE_NONE,
                                                   TEE_PARAM_TYPE_NONE);

        DMSG("has been called");

        if (param_types != exp_param_types)
                return TEE_ERROR_BAD_PARAMETERS;

        (void)&params;
        (void)&sess_ctx;

        IMSG("Hello World!\n");

        return TEE_SUCCESS;
}

void TA_CloseSessionEntryPoint(void __maybe_unused *sess_ctx)
{
        (void)&sess_ctx; /* Unused parameter */
        IMSG("Goodbye!\n");
}

static TEE_Result test_value(uint32_t param_types,
        TEE_Param params[4])
{
        uint32_t exp_param_types = TEE_PARAM_TYPES(TEE_PARAM_TYPE_VALUE_INPUT,
                                                   TEE_PARAM_TYPE_VALUE_OUTPUT,
                                                   TEE_PARAM_TYPE_INOUT,
                                                   TEE_PARAM_TYPE_NONE);
	    uint32_t value = 0;
        DMSG("has been called");

        if (param_types != exp_param_types)
                return TEE_ERROR_BAD_PARAMETERS;

        IMSG("Got value: %u from CA", params[0].value.a);
     	value = params[0].value.a;
     	value += 100;
        IMSG("increase value to: %u",value);
        params[1].value.a = value;
        IMSG("return increase data to normal world by params[1]");
        params[2].value.a = 12;
        IMSG("change data to normal world by params[2]");

        return TEE_SUCCESS;
}

TEE_Result TA_InvokeCommandEntryPoint(void __maybe_unused *sess_ctx,
                        uint32_t cmd_id,
                        uint32_t param_types, TEE_Param params[4])
{
        (void)&sess_ctx; /* Unused parameter */

        switch (cmd_id) {
      	  case CMD_TEST_VALUE:
      	  	test_value(param_types, params);
        
        default:
                return TEE_ERROR_BAD_PARAMETERS;
        }
}

本文 实现了一个使用3种 值传递 的params方式

  • TEEC_VALUE_INPUT 只能ca向ta传递数据
  • TEEC_VALUE_OUTPUT 只能ta向ca传递数据
  • TEEC_VALUE_INOUT 双向传递数据

标签:optee,例程,CA,TEE,value,TEEC,params,PARAM,void
From: https://blog.csdn.net/coversky2016/article/details/140748085

相关文章

  • OPTEE TA的类型区分
    OP-TEETA的三种类型目录PTA(伪TA)EarlyTAUserTAPTA(伪TA)编译位置:BL32运行模式:内核态功能限制:不能调用GP(通用目的)接口兼容性:可以在Uboot和Linux上运行EarlyTA编译位置:BL32运行模式:用户态功能:可以调用GP(通用目的)接口兼容性:可以在Uboot和Linux上运......
  • optee环境基本组成
    本文介绍optee全部环境的各部分组成,及其相互之间的关系optee各部分组成TeelinuxdriverTee_SupplicantOptee_ClientOpteeOsCA&TATeelinuxdriver这是Linux内核中的一个驱动程序,负责与OP-TEE操作系统进行通信。它提供了用户空间与安全世界(即OP-TEEOS)之间的接......
  • Educational Codeforces Round 168 (Rated for Div. 2) 补题记录(A~E)
    A直接暴力枚举字符添加在哪里,以及添加的字符是什么即可。#include<bits/stdc++.h>#defineintlonglongusingnamespacestd;constintN=500100;signedmain(){intT;cin>>T;while(T--){strings;cin>>s;stringans;i......
  • python导入包报错ImportError: cannot import name ‘Protocol‘
    python32.pyTraceback(mostrecentcalllast):File"2.py",line5,in<module>importptwt#use"fromsrcimportptwt"foraclonedtherepoFile"……lib/python3.6/site-packages/ptwt/_util.py",line2......
  • 一文带你了解CAP的全部特性,你学会了吗?
    目录前言消息发布携带消息头设置消息前缀原生支持的延迟消息并行发布消息事务消息事务消息发送事务消息消费事务补偿消息处理序列化过滤器消息重试多线程处理自动恢复/重连分布式存储锁消息版本隔离优化的雪花算法消息自动清理消费者特性Attribute订阅多Attribute订阅通配符订阅......
  • 第十三届先进材料与工程材料国际会议(ICAMEM 2024)
    https://www.icamem.org/**会议简介**2024年第十三届国际先进材料与工程材料会议(ICAMEM2024)将于2024年12月16日至18日在迪拜举行。自2011年以来,ICAMEM已在沈阳、宁波、北京、香港、泰国、新加坡等多个国家和地区成功举办,成为国际性的重要学术盛会。ICAMEM旨在为研究人员、学......
  • 【3DOF关节式(RRR)机械臂设计与运动学】3DOF关节式(RRR)机械臂的设计及其正向与逆向运
      ......
  • CSAPP:Cache模拟器
    实验要求实现一个组相联的DataCache,达到最高命中率DataCache最大只能使用16KB的数据存储空间附加功能:实现指令Cache分析实验的框架代码已经给出(直接映射),要改成组相联的结构,无非就是修改访问DataCache的接口,确定组号后遍历组内每一行的Tag,若能与Address匹配上则hit,否则......
  • 【flash attention安装】成功解决flash attention安装: undefined symbol: _ZN2at4_op
    【大模型-flashattention安装】成功解决flashattention安装site-packages/flash_attn_2_cuda.cpython-310-x86_64-linux-gnu.so:undefinedsymbol:_ZN2at4_ops9_pad_enum4callERKNS_6TensorEN3c108ArrayRefINS5_6SymIntEEElNS5_8optionalIdEE本次修炼方法请往下查看......
  • 卡特兰数(Catalan)
    1.简介:卡特兰数是组合数学中一个常出现于各种计数问题中的数列。十以内的卡特兰数,方便打表找规律,稍微记记。125144213242914304862167962.catalan递推式子(1)点击查看代码#include<bits/stdc++.h>usingnamespacestd;#defineintlonglongconstintN=1e5+10......