OPTEE下,CA和TA通信实现

这里以optee_examples中的hello_world为例,该例是实现整数加一操作。
1、 CA 需要与 OPTEE OS 之间建立一个 Context(InitializeContext),以后此 CA 与 TEE 环境的所有通信均基于此 Context来实现的;

/* 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);
	
2、 CA 会向 OPTEE OS 申请与请求的 TA 建立一个 Session(OpenSession);
/*
	 * Open a session to the "hello world" TA, the TA will print "hello
	 * world!" in the log when the session is created.
	 */
	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);
3、CA 与 TA 之间的 Session 建立完成后,CA 就可以向 TA 发送 Command(InvokeCommand);
/*
	 * TA_HELLO_WORLD_CMD_INC_VALUE is the actual function in the TA to be
	 * called.
	 */
	printf("Invoking TA to increment %d\n", op.params[0].value.a);
	res = TEEC_InvokeCommand(&sess, TA_HELLO_WORLD_CMD_INC_VALUE, &op,
				 &err_origin);
	if (res != TEEC_SUCCESS)
		errx(1, "TEEC_InvokeCommand failed with code 0x%x origin 0x%x",
			res, err_origin);
	printf("TA incremented value to %d\n", op.params[0].value.a);
Command 及其参数会通过共享内存的方式传递,TA 从共享内存中获取到 CA 的请求以及请求参数,
TA 在 TEE 环境下执行处理,得到的处理结果重新填充到共享内存中,CA 通过共享内存就可以获取到处理结果。

4、获得处理结果后,如不需要进一步请求,则由 CA 发起关闭 Session 的请求(CloseSession),OPTEE OS 回收 TA 相关资源,

/*
	 * We're done with the TA, close the session and
	 * destroy the context.
	 *
	 * The TA will print "Goodbye!" in the log when the
	 * session is closed.
	 */


	TEEC_CloseSession(&sess);
5、 CA 发起销毁 Context 的请求(FinalizeContext),完成一次完整交互。
TEEC_FinalizeContext(&ctx);
到这里 就完成一次操作,OPTEE是遵循GP标准的,这些也是GP标准的接口。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值