diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..9e32cdef1625daed25cf365c865f01050877cff3 --- /dev/null +++ b/LICENSE @@ -0,0 +1,127 @@ + 木兰宽松许可证, 第2版 + + 木兰宽松许可证, 第2版 + 2020年1月 http://license.coscl.org.cn/MulanPSL2 + + + 您对“软件”的复制、使用、修改及分发受木兰宽松许可证,第2版(“本许可证”)的如下条款的约束: + + 0. 定义 + + “软件”是指由“贡献”构成的许可在“本许可证”下的程序和相关文档的集合。 + + “贡献”是指由任一“贡献者”许可在“本许可证”下的受版权法保护的作品。 + + “贡献者”是指将受版权法保护的作品许可在“本许可证”下的自然人或“法人实体”。 + + “法人实体”是指提交贡献的机构及其“关联实体”。 + + “关联实体”是指,对“本许可证”下的行为方而言,控制、受控制或与其共同受控制的机构,此处的控制是指有受控方或共同受控方至少50%直接或间接的投票权、资金或其他有价证券。 + + 1. 授予版权许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的版权许可,您可以复制、使用、修改、分发其“贡献”,不论修改与否。 + + 2. 授予专利许可 + + 每个“贡献者”根据“本许可证”授予您永久性的、全球性的、免费的、非独占的、不可撤销的(根据本条规定撤销除外)专利许可,供您制造、委托制造、使用、许诺销售、销售、进口其“贡献”或以其他方式转移其“贡献”。前述专利许可仅限于“贡献者”现在或将来拥有或控制的其“贡献”本身或其“贡献”与许可“贡献”时的“软件”结合而将必然会侵犯的专利权利要求,不包括对“贡献”的修改或包含“贡献”的其他结合。如果您或您的“关联实体”直接或间接地,就“软件”或其中的“贡献”对任何人发起专利侵权诉讼(包括反诉或交叉诉讼)或其他专利维权行动,指控其侵犯专利权,则“本许可证”授予您对“软件”的专利许可自您提起诉讼或发起维权行动之日终止。 + + 3. 无商标许可 + + “本许可证”不提供对“贡献者”的商品名称、商标、服务标志或产品名称的商标许可,但您为满足第4条规定的声明义务而必须使用除外。 + + 4. 分发限制 + + 您可以在任何媒介中将“软件”以源程序形式或可执行形式重新分发,不论修改与否,但您必须向接收者提供“本许可证”的副本,并保留“软件”中的版权、商标、专利及免责声明。 + + 5. 免责声明与责任限制 + + “软件”及其中的“贡献”在提供时不带任何明示或默示的担保。在任何情况下,“贡献者”或版权所有者不对任何人因使用“软件”或其中的“贡献”而引发的任何直接或间接损失承担责任,不论因何种原因导致或者基于何种法律理论,即使其曾被建议有此种损失的可能性。 + + 6. 语言 + “本许可证”以中英文双语表述,中英文版本具有同等法律效力。如果中英文版本存在任何冲突不一致,以中文版为准。 + + 条款结束 + + 如何将木兰宽松许可证,第2版,应用到您的软件 + + 如果您希望将木兰宽松许可证,第2版,应用到您的新软件,为了方便接收者查阅,建议您完成如下三步: + + 1, 请您补充如下声明中的空白,包括软件名、软件的首次发表年份以及您作为版权人的名字; + + 2, 请您在软件包的一级目录下创建以“LICENSE”为名的文件,将整个许可证文本放入该文件中; + + 3, 请将如下声明文本放入每个源文件的头部注释中。 + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. + + + Mulan Permissive Software License,Version 2 + + Mulan Permissive Software License,Version 2 (Mulan PSL v2) + January 2020 http://license.coscl.org.cn/MulanPSL2 + + Your reproduction, use, modification and distribution of the Software shall be subject to Mulan PSL v2 (this License) with the following terms and conditions: + + 0. Definition + + Software means the program and related documents which are licensed under this License and comprise all Contribution(s). + + Contribution means the copyrightable work licensed by a particular Contributor under this License. + + Contributor means the Individual or Legal Entity who licenses its copyrightable work under this License. + + Legal Entity means the entity making a Contribution and all its Affiliates. + + Affiliates means entities that control, are controlled by, or are under common control with the acting entity under this License, ‘control’ means direct or indirect ownership of at least fifty percent (50%) of the voting power, capital or other securities of controlled or commonly controlled entity. + + 1. Grant of Copyright License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable copyright license to reproduce, use, modify, or distribute its Contribution, with modification or not. + + 2. Grant of Patent License + + Subject to the terms and conditions of this License, each Contributor hereby grants to you a perpetual, worldwide, royalty-free, non-exclusive, irrevocable (except for revocation under this Section) patent license to make, have made, use, offer for sale, sell, import or otherwise transfer its Contribution, where such patent license is only limited to the patent claims owned or controlled by such Contributor now or in future which will be necessarily infringed by its Contribution alone, or by combination of the Contribution with the Software to which the Contribution was contributed. The patent license shall not apply to any modification of the Contribution, and any other combination which includes the Contribution. If you or your Affiliates directly or indirectly institute patent litigation (including a cross claim or counterclaim in a litigation) or other patent enforcement activities against any individual or entity by alleging that the Software or any Contribution in it infringes patents, then any patent license granted to you under this License for the Software shall terminate as of the date such litigation or activity is filed or taken. + + 3. No Trademark License + + No trademark license is granted to use the trade names, trademarks, service marks, or product names of Contributor, except as required to fulfill notice requirements in Section 4. + + 4. Distribution Restriction + + You may distribute the Software in any medium with or without modification, whether in source or executable forms, provided that you provide recipients with a copy of this License and retain copyright, patent, trademark and disclaimer statements in the Software. + + 5. Disclaimer of Warranty and Limitation of Liability + + THE SOFTWARE AND CONTRIBUTION IN IT ARE PROVIDED WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL ANY CONTRIBUTOR OR COPYRIGHT HOLDER BE LIABLE TO YOU FOR ANY DAMAGES, INCLUDING, BUT NOT LIMITED TO ANY DIRECT, OR INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING FROM YOUR USE OR INABILITY TO USE THE SOFTWARE OR THE CONTRIBUTION IN IT, NO MATTER HOW IT’S CAUSED OR BASED ON WHICH LEGAL THEORY, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. + + 6. Language + + THIS LICENSE IS WRITTEN IN BOTH CHINESE AND ENGLISH, AND THE CHINESE VERSION AND ENGLISH VERSION SHALL HAVE THE SAME LEGAL EFFECT. IN THE CASE OF DIVERGENCE BETWEEN THE CHINESE AND ENGLISH VERSIONS, THE CHINESE VERSION SHALL PREVAIL. + + END OF THE TERMS AND CONDITIONS + + How to Apply the Mulan Permissive Software License,Version 2 (Mulan PSL v2) to Your Software + + To apply the Mulan PSL v2 to your work, for easy identification by recipients, you are suggested to complete following three steps: + + i Fill in the blanks in following statement, including insert your software name, the year of the first publication of your software, and your name identified as the copyright owner; + + ii Create a file named “LICENSE” which contains the whole context of this License in the first directory of your software package; + + iii Attach the statement to the appropriate annotated syntax at the beginning of each source file. + + + Copyright (c) [Year] [name of copyright holder] + [Software Name] is licensed under Mulan PSL v2. + You can use this software according to the terms and conditions of the Mulan PSL v2. + You may obtain a copy of Mulan PSL v2 at: + http://license.coscl.org.cn/MulanPSL2 + THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + See the Mulan PSL v2 for more details. diff --git a/README.en.md b/README.en.md deleted file mode 100644 index d8868027b956351eda83695f6751a4996927d2d2..0000000000000000000000000000000000000000 --- a/README.en.md +++ /dev/null @@ -1,36 +0,0 @@ -# tee-gp-proxy - -#### Description -This project aims to provide an implementation for RPC invoking TEE to facilitate the use of Kunpeng confidential computing in cloud scennarios. - -#### Software Architecture -Software architecture description - -#### Installation - -1. xxxx -2. xxxx -3. xxxx - -#### Instructions - -1. xxxx -2. xxxx -3. xxxx - -#### Contribution - -1. Fork the repository -2. Create Feat_xxx branch -3. Commit your code -4. Create Pull Request - - -#### Gitee Feature - -1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md -2. Gitee blog [blog.gitee.com](https://blog.gitee.com) -3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) -4. The most valuable open source project [GVP](https://gitee.com/gvp) -5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) -6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) diff --git a/README.md b/README.md index 400e2dd966696a25967e2a204ba85f3e7266ca60..b45312eb616d39deb1076159dbae81c3fd3faaa1 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,34 @@ -# tee-gp-proxy +# cc-resource-pooling #### 介绍 -This project aims to provide an implementation for RPC invoking TEE to facilitate the use of Kunpeng confidential computing in cloud scennarios. +机密计算资源池(Confidential Computeing Resource Pooling)项目旨在通过资源池化TrustZone的算力,方便鲲鹏机密计算的可信应用在云上部署。 +详细内容可参考仓库中的设计文档。 #### 软件架构 -软件架构说明 +![TrustZone资源池架构](docs/pic/arch-II.png) + +本项目借助了gPRC这一字节流框架,扩展新创建了可部署在任意位置的GP(Globle Platform) API 库-下文称为GP Client,用于部署在云上的TrustZone的Client APP访问真实的TrustZone TEE。同时在Host上 新建了 GP API proxy,用于接收来自远程的CA的 GP API的调用。 + +GP Client用于序列化CA的GP接口调用,GP Proxy则收到调用合反序列化后,将GP调用转化为本地TEE Client接口调用。考虑到并发处理的情况,GP API Proxy可管理多任时的队列。 +使用此方法,解决在VM或Docker中穿透虚拟化层访问TEE驱动的问题。如果需要,你也可以进一步开发,将多泰山服务器集群化管理。 + #### 安装教程 -1. xxxx -2. xxxx -3. xxxx +参考部署文档。 #### 使用说明 -1. xxxx -2. xxxx -3. xxxx +1. 本项目原项目中引入了Host端对客户端的认证机制,并在GP API 以及Service侧提供了透传JWT的API,JWT的获取以及确认需要应用实现; +2. 在配置gPRC时,建议启用TLS以及基于证书的双向认证,注意证书私钥为机密数据,在部署系统时需要考虑保护机制; +3. 本项目不包含其它开源项目的代码,涉及的第三方开源组件均需要使用者自行获取。 -#### 参与贡献 -1. Fork 本仓库 -2. 新建 Feat_xxx 分支 -3. 提交代码 -4. 新建 Pull Request +#### 参与贡献 #### 特技 - -1. 使用 Readme\_XXX.md 来支持不同的语言,例如 Readme\_en.md, Readme\_zh.md -2. Gitee 官方博客 [blog.gitee.com](https://blog.gitee.com) -3. 你可以 [https://gitee.com/explore](https://gitee.com/explore) 这个地址来了解 Gitee 上的优秀开源项目 -4. [GVP](https://gitee.com/gvp) 全称是 Gitee 最有价值开源项目,是综合评定出的优秀开源项目 -5. Gitee 官方提供的使用手册 [https://gitee.com/help](https://gitee.com/help) -6. Gitee 封面人物是一档用来展示 Gitee 会员风采的栏目 [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/) +1. 项目提供接口与原接口完全适配,用户仅需更换libteec.so文件即可直接使用 +2. 增加了token验证机制,并添加了两个扩展程序,作为token验证的中间件 +3. 性能上相较于一期项目显著提升 diff --git a/demo/clientapp/parallel/p.sh b/demo/clientapp/parallel/p.sh new file mode 100644 index 0000000000000000000000000000000000000000..de4f5826a9aad14c354b85f7bc08b0136e58d7b4 --- /dev/null +++ b/demo/clientapp/parallel/p.sh @@ -0,0 +1,17 @@ +# ! /bin/bash + +# set maximal number of parallel jobs +MAX_NUM_LCOUNT=100 +MAX_NUM_CCA=9 +# END_NUM=$(($MAX_NUM_CCA-1)) +END_NUM=$MAX_NUM_CCA + +if true; then +for ((LCOUNT = 0; LCOUNT < $MAX_NUM_LCOUNT; LCOUNT++)) +do + echo -e "\n"remove {}_$LCOUNT.log ::: $(eval echo "{1..$END_NUM}") + parallel -j $MAX_NUM_CCA rm "-f" {}_$LCOUNT.log ::: $(eval echo "{1..$END_NUM}") + parallel -j $MAX_NUM_CCA --ungroup bash ../testcase{}/build/test.sh "| tee" {}_$LCOUNT.log ::: $(eval echo "{1..$END_NUM}") + # parallel -j $MAX_NUM_CCA --ungroup ../testcase0/build/testcase "| tee" {}_$LCOUNT.log ::: $(eval echo "{0..$END_NUM}") +done +fi diff --git a/demo/clientapp/testcase1/CMakeLists.txt b/demo/clientapp/testcase1/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase1/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase1/build/cmake.sh b/demo/clientapp/testcase1/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase1/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase1/build/test.sh b/demo/clientapp/testcase1/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase1/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase1/testcase.c b/demo/clientapp/testcase1/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..6c4450aca5db5660415d008cbe7d8a4084bb50df --- /dev/null +++ b/demo/clientapp/testcase1/testcase.c @@ -0,0 +1,1042 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 1 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) + { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) + { + if (i % PRINTF_SIZE == 0) + { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) + { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) + { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *) param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t) pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) + { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) + { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) + { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) + { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) + { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); + exit: + return (void *) ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) + { + pthread_create(&tid[i], NULL, thread_function, (void *) &context); + } + + for (i = 0; i < THREAD_COUNT; i++) + { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result) thread_ret != TEEC_SUCCESS) + { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result) thread_ret); + ret = TEEC_FAIL; + } + } + + exit: + TEEC_FinalizeContext(&context); + if (!ret) + { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *) "/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) + { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) + { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) + { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) + { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) + { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) + { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) + { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) + { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) + { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) + { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) + { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) + { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) + { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char *msgBuf, uint32_t msgLen, char *signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) + { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result) RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) + { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) + { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else + { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) + { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *) TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) + { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_10(void) +{ + + TEEC_Result ret; + char infile_path[1024]; + char *subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + //basic_function + sprintf(infile_path, + "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", + TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta(size <= 1M) failed. \n"); + return ret; + } else + { + printf("Deploy ta(size <= 1M) succed. \n"); + } + //8M_TA_TEST + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase1/8M_TA_TEST.sec"); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta(size = 8M) failed. \n", TESTCASE); + return ret; + } else + { + printf("Deploy ta(size = 8M) succed. \n", TESTCASE); + } + + //TA_NOT_FOUND + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase1/not_found.sec"); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret == TEEC_INFILE_NOT_FOUND) + { + printf("Deploy ta not found test success\n"); + } else + { + printf("Deploy TA not found test failed \n"); + return ret; + } + + //outfile_path_not_exist + subdir = "not_exist_path"; + sprintf(infile_path, + "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", + TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta outfile_path_not_exist failed. \n"); + return ret; + } else + { + printf("Deploy ta outfile_path_not_exist succed. \n"); + } + + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) + { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif + +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char *subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, + "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", + TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) + { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + case 10: + ret = testcase_10(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase1/testcase.h b/demo/clientapp/testcase1/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase1/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase2/CMakeLists.txt b/demo/clientapp/testcase2/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase2/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase2/build/cmake.sh b/demo/clientapp/testcase2/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase2/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase2/build/test.sh b/demo/clientapp/testcase2/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase2/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase2/testcase.c b/demo/clientapp/testcase2/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..9082b63d57621d8857e1714e166f1dd8db8ce615 --- /dev/null +++ b/demo/clientapp/testcase2/testcase.c @@ -0,0 +1,941 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 2 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif + +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase2/testcase.h b/demo/clientapp/testcase2/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase2/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase3/CMakeLists.txt b/demo/clientapp/testcase3/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase3/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase3/build/cmake.sh b/demo/clientapp/testcase3/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase3/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase3/build/test.sh b/demo/clientapp/testcase3/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase3/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase3/testcase.c b/demo/clientapp/testcase3/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..918b48dc430e630687ba0f74c57ba1643c0a7ecd --- /dev/null +++ b/demo/clientapp/testcase3/testcase.c @@ -0,0 +1,941 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 3 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif + +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase3/testcase.h b/demo/clientapp/testcase3/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase3/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase4/CMakeLists.txt b/demo/clientapp/testcase4/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase4/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase4/build/cmake.sh b/demo/clientapp/testcase4/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase4/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase4/build/test.sh b/demo/clientapp/testcase4/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase4/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase4/testcase.c b/demo/clientapp/testcase4/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..44498ac7e8e633bf6ea7e42f7def524033bb6f1a --- /dev/null +++ b/demo/clientapp/testcase4/testcase.c @@ -0,0 +1,940 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 4 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase4/testcase.h b/demo/clientapp/testcase4/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase4/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase5/CMakeLists.txt b/demo/clientapp/testcase5/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase5/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase5/build/cmake.sh b/demo/clientapp/testcase5/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase5/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase5/build/test.sh b/demo/clientapp/testcase5/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase5/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase5/testcase.c b/demo/clientapp/testcase5/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..df56bf45b7dd6ef6b3ed30288a87777c2ab7ac90 --- /dev/null +++ b/demo/clientapp/testcase5/testcase.c @@ -0,0 +1,940 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 5 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase5/testcase.h b/demo/clientapp/testcase5/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase5/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase6/CMakeLists.txt b/demo/clientapp/testcase6/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase6/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase6/build/cmake.sh b/demo/clientapp/testcase6/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase6/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase6/build/test.sh b/demo/clientapp/testcase6/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase6/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase6/testcase.c b/demo/clientapp/testcase6/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..860332487cfe347bca3716c44701ed38e8c90ef8 --- /dev/null +++ b/demo/clientapp/testcase6/testcase.c @@ -0,0 +1,940 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 6 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase6/testcase.h b/demo/clientapp/testcase6/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase6/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase7/CMakeLists.txt b/demo/clientapp/testcase7/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase7/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase7/build/cmake.sh b/demo/clientapp/testcase7/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase7/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase7/build/test.sh b/demo/clientapp/testcase7/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase7/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase7/testcase.c b/demo/clientapp/testcase7/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..0078f5808e09356d7e207bf532a7e8383ac6a05f --- /dev/null +++ b/demo/clientapp/testcase7/testcase.c @@ -0,0 +1,940 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 7 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase7/testcase.h b/demo/clientapp/testcase7/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase7/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase8/CMakeLists.txt b/demo/clientapp/testcase8/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase8/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase8/build/cmake.sh b/demo/clientapp/testcase8/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase8/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase8/build/test.sh b/demo/clientapp/testcase8/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase8/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase8/testcase.c b/demo/clientapp/testcase8/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..6ac5d90758e56a883fb46f9dbbf2bf03c07e0302 --- /dev/null +++ b/demo/clientapp/testcase8/testcase.c @@ -0,0 +1,940 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 8 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase8/testcase.h b/demo/clientapp/testcase8/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase8/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/clientapp/testcase9/CMakeLists.txt b/demo/clientapp/testcase9/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..80b4384789023e3b1820d1bc2c6d01eab44eb1e0 --- /dev/null +++ b/demo/clientapp/testcase9/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.5.1) + +project(testcase C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +add_executable(testcase testcase.c) +target_link_libraries( + testcase + pthread + libteecc.so + libdbusc_jwt.so +) diff --git a/demo/clientapp/testcase9/build/cmake.sh b/demo/clientapp/testcase9/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/clientapp/testcase9/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/clientapp/testcase9/build/test.sh b/demo/clientapp/testcase9/build/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73734d2e4afdd0962e129bb29fcd67d2cf954d4 --- /dev/null +++ b/demo/clientapp/testcase9/build/test.sh @@ -0,0 +1,11 @@ +CUR_DIR=$( dirname -- "$0"; ) + +${CUR_DIR}/testcase 1 +${CUR_DIR}/testcase 2 +${CUR_DIR}/testcase 3 +${CUR_DIR}/testcase 4 +# ${CUR_DIR}/testcase 5 +${CUR_DIR}/testcase 6 +${CUR_DIR}/testcase 7 +${CUR_DIR}/testcase 8 +${CUR_DIR}/testcase 9 diff --git a/demo/clientapp/testcase9/testcase.c b/demo/clientapp/testcase9/testcase.c new file mode 100644 index 0000000000000000000000000000000000000000..11816905d334cb386678fc94e9703454015d417e --- /dev/null +++ b/demo/clientapp/testcase9/testcase.c @@ -0,0 +1,940 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo + */ + +#include "testcase.h" +#include +#include +#include +#include +#include +#include +// #include +// #include +// #include +// #include +#include +#include +#include +#include + +// #include "tee_client_api.h" +#include "teecc/teec_client_api.h" +#include "dbusc_jwt.h" + +#define TESTCASE 9 + +#if TESTCASE == 2 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530002.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x02} +}; +#elif TESTCASE == 3 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530003.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x03} +}; +#elif TESTCASE == 4 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530004.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x04} +}; +#elif TESTCASE == 5 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530005.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x05} +}; +#elif TESTCASE == 6 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530006.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x06} +}; +#elif TESTCASE == 7 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530007.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x07} +}; +#elif TESTCASE == 8 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530008.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x08} +}; +#elif TESTCASE == 9 +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530009.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x09} +}; +#else +#define TEST_CASE_TA_PATH "/data/testcase/b8ff9049-9cbb-46b0-bcae-7aaa02530001.sec" +static const TEEC_UUID TEST_CASE_UUID = { + 0xb8ff9049, 0x9cbb, 0x46b0, + {0xbc, 0xae, 0x7a, 0xaa, 0x02, 0x53, 0x00, 0x01} +}; +#endif + +static void DumpBuff(const char *buffer, size_t bufLen) +{ + size_t i; + if (buffer == NULL || bufLen == 0) { + return; + } + + printf("\n--------------------------------------------------\n"); + printf("bufLen = %d\n", bufLen); + for (i = 0; i < bufLen; i++) { + if (i % PRINTF_SIZE == 0) { + printf("\n"); + } + printf("%02x ", *(buffer + i)); + } + printf("\n--------------------------------------------------\n"); + return; +} + +static TEEC_Result testcase_1() +{ + TEEC_Context context; + // uint64_t context_addr; + TEEC_Session session; + TEEC_Operation operation; + uint32_t origin; + TEEC_Result ret; + + //Interface_Function-001 + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + //Interface_Function-002 + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- no param + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + //Interface_Function-003 -- value param + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_A); + assert(operation.params[0].value.b == VALUE_B); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].value.a = 55; + operation.params[0].value.b = 33; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(operation.params[0].value.a == VALUE_B); + assert(operation.params[0].value.b == VALUE_A); + + // Interface_Function-003 -- temp buf param + char tmpbuf[TEMP_BUF_SIZE] = REE_TEMP_BUF; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_TEMP_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].tmpref.buffer = tmpbuf; + operation.params[0].tmpref.size = TEMP_BUF_SIZE; + memset(tmpbuf, 0, TEMP_BUF_SIZE); + memcpy(tmpbuf, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(!ret); + assert(!strcmp(tmpbuf, TEE_TEMP_BUF)); + + //Interface_Function-004 + TEEC_CloseSession(&session); + //Interface_Function-005 + TEEC_FinalizeContext(&context); + if (!ret) { + printf("interface_testcase pass\n"); + } + return ret; +} + +static void share_mem_test( + TEEC_Session *session, + TEEC_SharedMemory *sharebuf +) +{ + TEEC_Result ret; + TEEC_Operation operation; + uint32_t origin; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_FULL, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_OUTPUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); + + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_PARTIAL_INOUT, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = sharebuf; + operation.params[0].memref.offset = 1; + operation.params[0].memref.size = TEMP_BUF_SIZE - 1; + memset(sharebuf->buffer, 0, sharebuf->size); + memcpy(sharebuf->buffer + 1, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + ret = TEEC_InvokeCommand(session, CMD_SHARE_MEM_PATR, &operation, &origin); + assert(!ret); + assert(!strcmp(sharebuf->buffer + 1, TEE_TEMP_BUF)); +} + +static TEEC_Result testcase_2() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + char tmpbuf[TEMP_BUF_SIZE]; + uint32_t origin; + TEEC_Result ret; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Function-006 + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-011 + share_mem_test(&session, &sharebuf); + + // Interface_Function-008 + TEEC_ReleaseSharedMemory(&sharebuf); + + // Interface_Function-007 + memset(&sharebuf, 0, sizeof(sharebuf)); + sharebuf.buffer = tmpbuf; + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_RegisterSharedMemory(&context, &sharebuf); + assert(!ret); + + // Interface_Function-012 + share_mem_test(&session, &sharebuf); + + TEEC_ReleaseSharedMemory(&sharebuf); + +// exit: + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("sharemem_interface_testcase pass\n"); + } + return ret; +} + + +static void *thread_function(void *param) +{ + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharebuf; + TEEC_Context *context = (TEEC_Context *)param; + pthread_t tid; + uint32_t origin; + struct timeval start, end, tokenset; + + tid = (pthread_t)pthread_self(); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + ret = TEEC_OpenSession(context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("thread %u open session failed, ret=%x\n", tid, ret); + goto exit; + } + + sharebuf.size = TEMP_BUF_SIZE; + sharebuf.flags = TEEC_MEM_INOUT; + ret = TEEC_AllocateSharedMemory(context, &sharebuf); + if (ret) { + printf("thread %u share buffer alloc failed, ret=%x\n", tid, ret); + goto exit; + } + + printf("begin multi-thread test, during %u\n", TEST_TIME); + gettimeofday(&start, NULL); + gettimeofday(&tokenset, NULL); + while (1) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_VALUE_INOUT, TEEC_NONE, TEEC_NONE); + memset(sharebuf.buffer, 0, sharebuf.size); + memcpy(sharebuf.buffer, REE_TEMP_BUF, strlen(REE_TEMP_BUF)); + operation.params[0].memref.parent = &sharebuf; + operation.params[1].value.a = 1; + + ret = TEEC_InvokeCommand(&session, CMD_MUL_THREAD, &operation, &origin); + if (ret) { + printf("thread %u invoke failed, ret=%x, origin=%u\n", tid, ret, origin); + break; + } + + if (strcmp(sharebuf.buffer, TEE_TEMP_BUF) || operation.params[1].value.a || operation.params[1].value.b != 1) { + printf("thread %u get wrong comptue result.\n", tid); + break; + } + gettimeofday(&end, NULL); + if (end.tv_sec - start.tv_sec > TEST_TIME) + break; + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + + sleep(1); + } + + TEEC_CloseSession(&session); +exit: + return (void *)ret; +} + +static TEEC_Result testcase_3() +{ + TEEC_Result ret; + TEEC_Operation operation; + TEEC_Context context; + pthread_t tid[THREAD_COUNT]; + void *thread_ret = NULL; + uint32_t i; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_create(&tid[i], NULL, thread_function, (void *)&context); + } + + for (i = 0; i < THREAD_COUNT; i++) { + pthread_join(tid[i], &thread_ret); + if ((TEEC_Result)thread_ret != TEEC_SUCCESS) { + printf("thread %u return fail, ret=%x\n", tid[i], (TEEC_Result)thread_ret); + ret = TEEC_FAIL; + } + } + +exit: + TEEC_FinalizeContext(&context); + if (!ret) { + printf("multi_thread_testcase pass\n"); + } + return ret; +} + + +// Exception Test +static TEEC_Result testcase_4() +{ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 + TEEC_Result ret = TEEC_SUCCESS; + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_SharedMemory sharemem; + uint32_t origin; + + // Interface_Exception_001ll + ret = TEEC_InitializeContext(NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + + // Interface_Exception_002 + ret = TEEC_OpenSession(NULL, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + NULL, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + ret = TEEC_OpenSession(&context, + &session, NULL, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + context.ta_path = (uint8_t *)"/data/not_found.sec"; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_TRUSTED_APP_LOAD_ERROR); + // assert(ret == TEEC_ERROR_NOT_IMPLEMENTED); + printf("OpenSession tapath not_found.sec case, ret = 0x %16.16lx. \n", ret); + assert(ret); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // Interface_Exception_003 + ret = TEEC_InvokeCommand(NULL, CMD_NULL, &operation, &origin); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + session.session_id++; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + // assert(ret == TEEC_ERROR_ACCESS_DENIED); + assert(ret == TEEC_ERROR_NO_WORKER_MATCHED); + + session.session_id--; + operation.paramTypes = TEEC_PARAM_TYPES(TEEC_MEMREF_WHOLE, TEEC_NONE, TEEC_NONE, TEEC_NONE); + operation.params[0].memref.parent = &sharemem; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + assert(ret); + + ret = TEEC_InvokeCommand(&session, CMD_NULL, NULL, NULL); + assert(ret == TEEC_ERROR_BAD_PARAMETERS); + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, NULL); + assert(!ret); + + // Interface_Exception_004 + TEEC_CloseSession(NULL); + + // Interface_Exception_005 + TEEC_FinalizeContext(NULL); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + + if (!ret) { + printf("exception_testcase pass\n"); + } + return ret; +} + +static TEEC_Result testcase_5() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + assert(!ret); + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + assert(!ret); + + // CA_KILL_Test_001 + printf("CA Killed Test begin!, process exit!\n"); + exit(0); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_6() +{ + TEEC_Context context; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + gettimeofday(&start, NULL); + ret = TEEC_InitializeContext(NULL, &context); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_FinalizeContext(&context); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InitializeContext cost: %f us\n", cost * 1.0 / count); + } + return ret; +} + +static TEEC_Result testcase_7() +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + gettimeofday(&start, NULL); + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + TEEC_CloseSession(&session); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_OpenSession cost: %f us\n", cost * 1.0 / count); + } + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result testcase_8(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + struct timeval start, end, tokenset; + uint32_t cost = 0; + uint32_t i; + TEEC_Result ret; + uint32_t count = 1000; + uint32_t origin; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + gettimeofday(&tokenset, NULL); + for (i = 0; i < count; i++) { + operation.started = 1; + memset(&operation.paramTypes, 0, sizeof(operation.paramTypes)); + gettimeofday(&start, NULL); + ret = TEEC_InvokeCommand(&session, CMD_NULL, &operation, &origin); + gettimeofday(&end, NULL); + if (ret) { + break; + } + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (end.tv_sec - tokenset.tv_sec > EXPIRE_TIME) + { + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + break; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + break; + } + printf("Token set succed. \n"); + gettimeofday(&tokenset, NULL); + } + } + + if (!ret) { + printf("TEEC_InvokeCommand cost: %f us\n", cost * 1.0 / count); + } + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +static TEEC_Result RsaSignCmd(char* msgBuf, uint32_t msgLen, char* signBuf, uint32_t *bufLen, + TEEC_Session *session) +{ + TEEC_Operation operation; + TEEC_Result result; + uint32_t origin; + + if (msgBuf == NULL || signBuf == NULL || (bufLen == NULL)) { + TEEC_Error("invoke RsaSignCmd has wrong params."); + return (TEEC_Result)RSA_INPUT_ERROR_PARAMETER; + } + + operation.started = 1; + operation.paramTypes = TEEC_PARAM_TYPES( + TEEC_VALUE_INPUT, + TEEC_NONE, + TEEC_MEMREF_TEMP_INPUT, + TEEC_MEMREF_TEMP_OUTPUT); + + operation.params[0].value.a = RSA_KEY_1; + operation.params[0].value.b = RSA_ALG_PSS_SHA256; + operation.params[PARAMS_INDEX_2].tmpref.buffer = msgBuf; + operation.params[PARAMS_INDEX_2].tmpref.size = msgLen; + operation.params[PARAMS_INDEX_3].tmpref.buffer = signBuf; + operation.params[PARAMS_INDEX_3].tmpref.size = *bufLen; + + result = TEEC_InvokeCommand(session, CMD_SIGN_PSS_MGF1_SHA256, &operation, &origin); + if (result != TEEC_SUCCESS) { + TEEC_Error("invoke RsaSignCmd failed, codes=0x%x, origin=0x%x.", result, origin); + } else if (operation.params[PARAMS_INDEX_3].tmpref.size != RSA_KEY_SIZE) { + TEEC_Error("invoke RsaSignCmd failed, returned Encrypted data size is %d.", + operation.params[PARAMS_INDEX_3].tmpref.size); + } else { + printf("signBuf is : \n"); + DumpBuff(signBuf, operation.params[PARAMS_INDEX_3].tmpref.size); + *bufLen = operation.params[PARAMS_INDEX_3].tmpref.size; + } + + return result; +} + +static TEEC_Result testcase_9(void) +{ + TEEC_Context context; + TEEC_Session session; + TEEC_Operation operation; + TEEC_Result ret; + uint32_t origin; + char msgBuf[RSA_KEY_SIZE] = {0}; + char signature[RSA_KEY_SIZE] = {0}; + uint32_t bufLen = RSA_KEY_SIZE; + + ret = TEEC_InitializeContext(NULL, &context); + if (ret) { + printf("initail conatext failed\n"); + return ret; + } + context.ta_path = (uint8_t *)TEST_CASE_TA_PATH; + + memset(&operation, 0, sizeof(operation)); + operation.started = 1; + ret = TEEC_OpenSession(&context, + &session, &TEST_CASE_UUID, TEEC_LOGIN_IDENTIFY, NULL, &operation, &origin); + if (ret) { + printf("opensession failed!, ret=%x, origin=%u\n", ret, origin); + TEEC_FinalizeContext(&context); + return ret; + } + + ret = RsaSignCmd(msgBuf, RSA_MASSAGE_SIZE, signature, &bufLen, &session); + printf("TEE RSA Sign %s.\n", ret ? "failed" : "success"); + + TEEC_CloseSession(&session); + TEEC_FinalizeContext(&context); + return ret; +} + +void help_print(void) +{ + printf("Usage: \n \ + 1.function_interface_testcase\n \ + 2.sharemem_interface_testcase\n \ + 3.multi_thread_testcase\n \ + 4.exception_testcase\n \ + 5.client_killed_testcase\n \ + 6.TEEC_InitializeContext perform-test\n \ + 7.TEEC_OpenSession perform-test\n \ + 8.TEEC_InvokeCommand perform-test\n \ + 9.RSA Sign test\n"); +} + +int main(int argc, char **argv) +{ + TEEC_Result ret; + struct timeval start, end; + gettimeofday(&start, NULL); + int choice = -1; + + if (argc == 1 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) { + help_print(); + return 1; + } + +#if 0 + char token[1024]; + int iret; + iret = + dbusmethodcall_fetch_jwt( + token + ); + if (iret != 0) + { + printf("Token fetching failed. \n"); + return 0; + } + printf("The fetched token: %s \n", token); + + ret = + TEEC_SetJwt( + token + ); + if (ret != TEEC_SUCCESS) + { + printf("Token set failed. \n"); + return 0; + } + printf("Token set succed. \n"); +#endif +#if 1 + ret = + TEEC_UnsetJwt( + ); + if (ret != TEEC_SUCCESS) + { + printf("Token unset failed. \n"); + return 0; + } + printf("Token unset succed. \n"); +#endif + + char infile_path[1024]; + char * subdir = "testcase"; + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", TESTCASE, TESTCASE); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", TESTCASE); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", TESTCASE); + } + + /* + for (int ita = 1; ita < 10; ita ++) + { + memset(infile_path, 0, sizeof(infile_path)); + sprintf(infile_path, "/home/john/projects/tzc02/09/demo/ta/itrustee_sdk/output/testcase/testcase%d/b8ff9049-9cbb-46b0-bcae-7aaa0253000%d.sec", ita, ita); + ret = TEEC_DeployTa(infile_path, subdir, NULL); + if (ret != TEEC_SUCCESS) + { + printf("Deploy ta %d failed. \n", ita); + return 0; + } + else + { + printf("Deploy ta %d succed. \n", ita); + } + } + */ + + choice = atoi(argv[1]); + + switch (choice) { + case 1: + ret = testcase_1(); + break; + case 2: + ret = testcase_2(); + break; + case 3: + ret = testcase_3(); + break; + case 4: + ret = testcase_4(); + break; + case 5: + ret = testcase_5(); + break; + case 6: + ret = testcase_6(); + break; + case 7: + ret = testcase_7(); + break; + case 8: + ret = testcase_8(); + break; + case 9: + ret = testcase_9(); + break; + default: + printf("Error: invalid choice!\n"); + help_print(); + ret = -1; + break; + } + + return ret; +} diff --git a/demo/clientapp/testcase9/testcase.h b/demo/clientapp/testcase9/testcase.h new file mode 100644 index 0000000000000000000000000000000000000000..7ced8e259991fe6433141780b63c9bb016be5314 --- /dev/null +++ b/demo/clientapp/testcase9/testcase.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved. + * Description: multi_core_demo CA application header file + */ + +#ifndef __MULTI_CORE_CA_H +#define __MULTI_CORE_CA_H + +// #define TEST_CASE_TA_PATH "/data/ebc87fc2-05dc-41b3-85b9-f9f0ef481bad.sec" + +#define VALUE_A 55 +#define VALUE_B 33 +#define REE_TEMP_BUF "hello tee" +#define TEE_TEMP_BUF "hello ree" +#define TEMP_BUF_SIZE 20 +#define THREAD_COUNT 3 + +#define TEST_TIME 10 * 6 +#define EXPIRE_TIME 10 * 6 * 5 + +#define RSA_KEY_SIZE 256 // 2048bits +#define RSA_MASSAGE_SIZE 100 +#define RSA_INPUT_ERROR_PARAMETER 0x10000001 +#define RSA_KEY_1 1 +#define RSA_ALG_PSS_SHA256 2 // use TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256 mode for sign + +#define PARAMS_INDEX_2 2 // params参数的下标索引 2 +#define PARAMS_INDEX_3 3 // params参数的下标索引 3 +#define PRINTF_SIZE 32 + +enum { + CMD_NULL = 0, + CMD_SHARE_MEM_FULL, + CMD_SHARE_MEM_PATR, + CMD_MUL_THREAD, + CMD_SIGN_PSS_MGF1_SHA256, +}; + +#endif diff --git a/demo/dbusjwt/CMakeLists.txt b/demo/dbusjwt/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0c23113c2e2f79c9818fbb264c62151385df5d7f --- /dev/null +++ b/demo/dbusjwt/CMakeLists.txt @@ -0,0 +1,71 @@ +# + +cmake_minimum_required(VERSION 3.5.1) + +project(dbus_jwt C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") +# include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include/) +include_directories(/usr/include/dbus-1.0/) +include_directories(/usr/lib64/dbus-1.0/include/) + +# Introduce variables: +# - CMAKE_INSTALL_LIBDIR +# - CMAKE_INSTALL_BINDIR +# - CMAKE_INSTALL_INCLUDEDIR +include(GNUInstallDirs) + + +set(lib_dbusc_jwt + ${PROJECT_SOURCE_DIR}/dbusc_jwt.c +) +# Install Headers: +set(HEADERS_DBUSC_JWT + ${PROJECT_SOURCE_DIR}/dbusc_jwt.h +) +install( + FILES ${HEADERS_DBUSC_JWT} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_NAME}" +) + +add_library(dbusc_jwt SHARED ${lib_dbusc_jwt}) +target_link_libraries( + dbusc_jwt + libdbus-1.so +) + +# Install lib: +install( + TARGETS "dbusc_jwt" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) + + +set(dbuss_fetchjwt + ${PROJECT_SOURCE_DIR}/dbuss_fetchjwt.c +) +add_executable(dbuss_fetchjwt "${dbuss_fetchjwt}") +target_link_libraries( + dbuss_fetchjwt + libdbus-1.so + spiffejwt +) + +set(dbuss_validatejwt + ${PROJECT_SOURCE_DIR}/dbuss_validatejwt.c +) +add_executable(dbuss_validatejwt "${dbuss_validatejwt}") +target_link_libraries( + dbuss_validatejwt + libdbus-1.so + spiffejwt +) + +# Install bin: +install( + TARGETS "dbuss_fetchjwt" "dbuss_validatejwt" + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR$}" +) diff --git a/demo/dbusjwt/build/cmake.sh b/demo/dbusjwt/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/dbusjwt/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/dbusjwt/dbus_return_code.h b/demo/dbusjwt/dbus_return_code.h new file mode 100644 index 0000000000000000000000000000000000000000..e59e9b5054cd8fb5b71442c28de895a212795e20 --- /dev/null +++ b/demo/dbusjwt/dbus_return_code.h @@ -0,0 +1,26 @@ +// +// Created by 62754 on 2022/8/19. +// + +#ifndef _DBUS_RETURN_CODE_H +#define _DBUS_RETURN_CODE_H + +enum TEEC_ReturnCode +{ + TEEC_ERROR_JWTVALIDATE_FAIL = 0xAAAA0020, /* jwt validate fail */ + TEEC_ERROR_GRPC_ERROR = 0xAAAA0021, /* grpc transmission error */ + TEEC_ERROR_DBUS_CONN_NULL = 0xAAAA0022, /* dbus connection null */ + TEEC_ERROR_DBUS_NAME_ERROR = 0xAAAA0023, /* dbus name set is error */ + TEEC_ERROR_DBUS_MSG_NULL = 0xAAAA0024, /* dbus message is null */ + TEEC_ERROR_DBUS_APPEND_ERROR = 0xAAAA0025, /* dbus append argument error */ + TEEC_ERROR_DBUS_REPLY_ERROR = 0xAAAA0026, /* dbus send with reply error */ + TEEC_ERROR_DBUS_ARG_NULL = 0xAAAA0027, /* dbus argument is null */ + TEEC_ERROR_DBUS_ARG_TYPE_ERROR = 0xAAAA0028, /* dbus argument type error */ + TEEC_ERROR_TOKEN_NULL = 0xAAAA0029, /* fetch token is null */ + TEEC_ERROR_TOKEN_SIZE_ERROR = 0xAAAA0030, /* token size is error */ + TEEC_ERROR_FETCHJWT_ERROR = 0xAAAA0031, /* fetch jwt error */ + TEEC_INFILE_PATH_NULL = 0xAAAA0032 /* deployta infile patn is null*/ +}; + +typedef enum TEEC_ReturnCode TEEC_Result; +#endif //_DBUS_RETURN_CODE_H diff --git a/demo/dbusjwt/dbusc_jwt.c b/demo/dbusjwt/dbusc_jwt.c new file mode 100644 index 0000000000000000000000000000000000000000..244560299f23e46e29a66417414271aba0f8b7ec --- /dev/null +++ b/demo/dbusjwt/dbusc_jwt.c @@ -0,0 +1,458 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dbus_return_code.h" + + +TEEC_Result dbusmethodcall_fetch_jwt( + char *token +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + int ret; + int iType; + + unsigned char *charp; + unsigned char param[12] = "fetchtoken"; + DBusMessageIter structIter; + dbus_uint32_t retcode; + unsigned char *token_temp = NULL; + + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return TEEC_ERROR_DBUS_CONN_NULL; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + "fetchjwt", + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_NAME_ERROR; + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_NAME_ERROR; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", "fetchjwt"); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", "fetchjwt"); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", "fetchjwt"); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "fetch_jwtsvid" // method name + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null \n"); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_MSG_NULL; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + + charp = param; + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &charp)) + { + fprintf(stderr, "Out Of Memory. \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_APPEND_ERROR; + } + + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbusc_jwt: fetchjwt send_with_reply_and_block error %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_REPLY_ERROR; + } + if (reply == NULL) + { + fprintf(stderr, "libdbusc_jwt: fetchjwt dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_REPLY_ERROR; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments. \n"); + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_ARG_NULL; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32. \n"); + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_ARG_TYPE_ERROR; + } + dbus_message_iter_get_basic( + &structIter, + &retcode + ); + + if (retcode == 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments! \n"); + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_ARG_NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_ARG_TYPE_ERROR; + } + dbus_message_iter_get_basic( + &structIter, + &token_temp); + + if (token == NULL) + { + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_TOKEN_NULL; + } else + { + if (sizeof(token) < sizeof(token_temp)) + { + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_TOKEN_SIZE_ERROR; + } else + { + memset(token, '\0', sizeof(token)); + strcpy(token, token_temp); + } + } + + } + + // free reply + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return retcode; +} + + +TEEC_Result dbusmethodcall_validate_jwt( + char *token +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + int ret; + int iType; + + unsigned char *charp; + dbus_uint32_t retcode; + + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return TEEC_ERROR_DBUS_CONN_NULL; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + "validatejwt", + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_NAME_ERROR; + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_NAME_ERROR; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", "validatejwt"); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", "validatejwt"); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", "validatejwt"); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "validate_jwtsvid" // method name + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null \n"); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_MSG_NULL; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + + if (token == NULL) + { + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_TOKEN_NULL; + } + + charp = token; + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &charp)) + { + fprintf(stderr, "Out Of Memory. \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_APPEND_ERROR; + } + + + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbusc_jwt: validatejwt send_with_reply_and_block error, %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_REPLY_ERROR; + } + if (reply == NULL) + { + fprintf(stderr, "libdbusc_jwt: validatejwt dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_REPLY_ERROR; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments. \n"); + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_ARG_NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &args + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32. \n"); + dbus_message_unref(msg); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return TEEC_ERROR_DBUS_ARG_TYPE_ERROR; + } + dbus_message_iter_get_basic( + &args, + &retcode + ); + + printf("libdbusc_jwt: got reply of methodcall validate_jwtsvid \n"); + printf(" retcode = 0x %8x \n", retcode); + + // free reply + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return retcode; +} + diff --git a/demo/dbusjwt/dbusc_jwt.h b/demo/dbusjwt/dbusc_jwt.h new file mode 100644 index 0000000000000000000000000000000000000000..5f2b495dab5281635706bcac903f2385747ceec8 --- /dev/null +++ b/demo/dbusjwt/dbusc_jwt.h @@ -0,0 +1,27 @@ +#ifndef _DBUSC_JWT_H +#define _DBUSC_JWT_H + +#ifdef __cplusplus +extern "C" { +#endif + +int dbusmethodcall_fetch_jwt( + char *token +); + +int dbusmethodcall_validate_jwt( + // const char * taname, + char *token +); + +/* +int dbusmethodcall_restart( + const char * taname +); + */ + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/demo/dbusjwt/dbuss_fetchjwt.c b/demo/dbusjwt/dbuss_fetchjwt.c new file mode 100644 index 0000000000000000000000000000000000000000..7762a1f1f8a4fbc3687bdb55824d2896b2966c40 --- /dev/null +++ b/demo/dbusjwt/dbuss_fetchjwt.c @@ -0,0 +1,253 @@ +#include +#include +#include +#include +#include +#include +#include +#include "spiffejwt.h" + +#include "dbus_return_code.h" + +#define NO_ERROR 0 + + +void * +reply_methodcall_fetch_jwtsvid( + DBusMessage *msg, + DBusConnection *conn +) +{ + DBusMessage *reply; + DBusMessageIter args; + dbus_bool_t bResult; + dbus_uint32_t retcode; + dbus_uint32_t serial = 0; + DBusMessageIter structIter; + char token[1024] = "noToken"; + + printf("\n"); + printf("Received mechod call fetch_jwtsvid. \n"); + + // read the arguments + if (!dbus_message_iter_init(msg, &args)) + { + fprintf(stderr, "Message has no arguments!\n"); + retcode = TEEC_ERROR_DBUS_MSG_NULL; + } else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) + { + fprintf(stderr, "Argument is not string!\n"); + retcode = TEEC_ERROR_DBUS_ARG_TYPE_ERROR; + } else + { + dbus_message_iter_get_basic(&args, &token); + + int iResult = spiffe_fetch_jwtsvid( + token + ); + if (iResult == NO_ERROR) + { + printf("Token fetching succed, token = %s \n", token); + retcode = 0; + } else + { + retcode = TEEC_ERROR_FETCHJWT_ERROR; + } + } + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &retcode + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory! \n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + return NULL; + } + + if (retcode == 0) + { + unsigned char *charp; + charp = token; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &charp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory! \n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + return NULL; + } + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory! \n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + return NULL; + } + + dbus_message_unref(reply); + dbus_connection_flush(conn); + + return NULL; +} + +/** + * Server that exposes a method call and waits for it to be called + */ +void +receive_methodcall( +) +{ + DBusMessage *msg; + DBusConnection *conn; + DBusError err; + int ret; + dbus_bool_t bResult; + + + printf("Dbus server for fetching jwt is listening for method calls ... \n"); + + // initialise the error + dbus_error_init(&err); + + dbus_threads_init_default(); + + // connect to the bus and check for errors + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + // conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + exit(1); + } + + if (NULL == conn) + { + fprintf(stderr, "Connection Null. \n"); + exit(1); + } + + char dbusname[1024]; + memset((char *) dbusname, 0, 1024); + // sprintf(dbusname, "%s.method.server", argv[1]); + sprintf(dbusname, "%s.method.server", "fetchjwt"); + // request our name on the bus and check for errors + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + exit(1); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + fprintf(stderr, "Not Primary Owner (%d)\n", ret); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + exit(1); + } + + // loop, testing for new messages + memset((char *) dbusname, 0, 1024); + // sprintf(dbusname, "%s.method.Type", argv[1]); + sprintf(dbusname, "%s.method.Type", "fetchjwt"); + while (true) + { + // non blocking read of the next available message + dbus_connection_read_write(conn, 0); + msg = dbus_connection_pop_message(conn); + + // loop again if we haven't got a message + if (NULL == msg) + { + usleep(10000); + continue; + } + + // printf("Received one method call. \n"); + + // check this is a method call for the right interface & method + bResult = dbus_message_is_method_call( + msg, + dbusname, + "fetch_jwtsvid" + ); + if (bResult == TRUE) + { + reply_methodcall_fetch_jwtsvid( + msg, + conn + ); + } + + // free the message + dbus_message_unref(msg); + + } // end of the while true + +} // end of the function + + +int main(int argc, char *argv[]) +{ + int iResult; + + iResult = spiffe_start_conn(); + if (iResult != NO_ERROR) + { + fprintf(stderr, "Spiffe start conn failed. \n"); + return -1; + } + + receive_methodcall( + ); + + return 0; +} diff --git a/demo/dbusjwt/dbuss_validatejwt.c b/demo/dbusjwt/dbuss_validatejwt.c new file mode 100644 index 0000000000000000000000000000000000000000..87d603a95e3ee3002a5d35b06564707c26025af2 --- /dev/null +++ b/demo/dbusjwt/dbuss_validatejwt.c @@ -0,0 +1,219 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "spiffejwt.h" +#include "dbus_return_code.h" + +#define NO_ERROR 0 + + +void * +reply_methodcall_validate_jwtsvid( + DBusMessage *msg, + DBusConnection *conn +) +{ + DBusMessage *reply; + DBusMessageIter args; + char *token = NULL; + dbus_bool_t bResult; + dbus_uint32_t retcode; + dbus_uint32_t serial = 0; + + // read the arguments + if (!dbus_message_iter_init(msg, &args)) + { + fprintf(stderr, "Message has no arguments!\n"); + retcode = TEEC_ERROR_DBUS_MSG_NULL;; + } else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) + { + fprintf(stderr, "Argument is not string!\n"); + retcode = TEEC_ERROR_DBUS_ARG_TYPE_ERROR;; + } else + { + dbus_message_iter_get_basic(&args, &token); + printf("\n"); + printf("Received mechod call validate_jwtsvid: \n"); + printf(" token = %s \n", token); + struct timeval start, end; + gettimeofday(&start, NULL); + int iResult = spiffe_validate_jwtsvid( + token + ); + gettimeofday(&end, NULL); + int64_t i64Time_jwt; + i64Time_jwt = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + printf("spiffe validate jwt used time: %ld us. \n", i64Time_jwt); + + if (iResult == NO_ERROR) + { + printf("Token validate succed \n"); + retcode = NO_ERROR; + } else + { + printf("Token validate failed \n"); + retcode = TEEC_ERROR_JWTVALIDATE_FAIL; + } + } + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + bResult = + dbus_message_iter_append_basic( + &args, + DBUS_TYPE_UINT32, + &retcode + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + return NULL; + } + + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + return NULL; + } + + dbus_message_unref(reply); + dbus_connection_flush(conn); + + return NULL; +} + +/** + * Server that exposes a method call and waits for it to be called + */ +void +receive_methodcall( +) +{ + DBusMessage *msg; + DBusConnection *conn; + DBusError err; + int ret; + dbus_bool_t bResult; + + + printf("Dbus server for validating jwt is listening for method calls ... \n"); + + // initialise the error + dbus_error_init(&err); + + dbus_threads_init_default(); + + // connect to the bus and check for errors + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + // conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + exit(1); + } + + if (NULL == conn) + { + fprintf(stderr, "Connection Null\n"); + exit(1); + } + + char dbusname[1024]; + memset((char *) dbusname, 0, 1024); + // sprintf(dbusname, "%s.method.server", argv[1]); + sprintf(dbusname, "%s.method.server", "validatejwt"); + // request our name on the bus and check for errors + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + exit(1); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + fprintf(stderr, "Not Primary Owner (%d)\n", ret); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + exit(1); + } + + // loop, testing for new messages + memset((char *) dbusname, 0, 1024); + // sprintf(dbusname, "%s.method.Type", argv[1]); + sprintf(dbusname, "%s.method.Type", "validatejwt"); + while (true) + { + // non blocking read of the next available message + dbus_connection_read_write(conn, 0); + msg = dbus_connection_pop_message(conn); + + // loop again if we haven't got a message + if (NULL == msg) + { + usleep(10000); + continue; + } + + // check this is a method call for the right interface & method + bResult = dbus_message_is_method_call( + msg, + dbusname, + "validate_jwtsvid" + ); + if (bResult == TRUE) + { + reply_methodcall_validate_jwtsvid( + msg, + conn + ); + } + + // free the message + dbus_message_unref(msg); + + } // end of the while true + +} // end of the function + + +int main(int argc, char *argv[]) +{ + int iResult; + + iResult = spiffe_start_conn(); + if (iResult != NO_ERROR) + { + fprintf(stderr, "Spiffe start conn failed. \n"); + return -1; + } + + receive_methodcall( + ); + + return 0; +} diff --git a/demo/libspiffejwt/CMakeLists.txt b/demo/libspiffejwt/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..f20ce4481085649d635bcaacb9d39fc045cfb3cd --- /dev/null +++ b/demo/libspiffejwt/CMakeLists.txt @@ -0,0 +1,56 @@ +# +# + +cmake_minimum_required(VERSION 3.5.1) + +project(spiffejwt C CXX) + +# include_directories("${CMAKE_CURRENT_BINARY_DIR}") + +# Introduce variables: +# - CMAKE_INSTALL_LIBDIR +# - CMAKE_INSTALL_BINDIR +# - CMAKE_INSTALL_INCLUDEDIR +include(GNUInstallDirs) + + +set(LIB_SPIFFEJWT + ${PROJECT_SOURCE_DIR}/spiffejwt.c +) +# Install Headers: +set(HEADERS_SPIFFEJWT + ${PROJECT_SOURCE_DIR}/spiffejwt.h +) +install( + FILES ${HEADERS_SPIFFEJWT} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_NAME}" +) + +add_library(spiffejwt SHARED ${LIB_SPIFFEJWT}) +target_link_libraries(spiffejwt + libclient.so +) + +# Install lib: +install( + TARGETS "spiffejwt" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) + +set(TEST_SPIFFEJWT + ${PROJECT_SOURCE_DIR}/test_spiffejwt.c +) +add_executable(test_spiffejwt "${TEST_SPIFFEJWT}") +target_link_libraries( + test_spiffejwt + spiffejwt +) + +# Install bin: +# install( +# TARGETS test_spiffejwt +# RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR$}" +# ) + + + diff --git a/demo/libspiffejwt/build/cmake.sh b/demo/libspiffejwt/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/demo/libspiffejwt/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/demo/libspiffejwt/spiffejwt.c b/demo/libspiffejwt/spiffejwt.c new file mode 100644 index 0000000000000000000000000000000000000000..49a060e2485a68540cf2a3325817860c8cd4ab98 --- /dev/null +++ b/demo/libspiffejwt/spiffejwt.c @@ -0,0 +1,254 @@ +#include +#include +#include + +#include "c-spiffe/workload/client.h" + +#include "spiffejwt.h" + + +workloadapi_Client *client; + + +int spiffe_start_conn() +{ + err_t error = NO_ERROR; + + client = workloadapi_NewClient(&error); + + workloadapi_Client_SetAddress(client, "unix:///tmp/spire-agent/public/api.sock"); + + workloadapi_Client_SetHeader(client, "workload.spiffe.io", "true"); + if (error != NO_ERROR) + { + // printf("client error! %d\n", (int) error); + return error; + } + + error = workloadapi_Client_Connect(client); + if (error != NO_ERROR) + { + // printf("conn error! %d\n", (int) error); + return error; + } + + return NO_ERROR; +} + + +int spiffe_close_conn() +{ + if (client == NULL) + { + return -1; + } + + err_t error = NO_ERROR; + + error = workloadapi_Client_Close(client); + if (error != NO_ERROR) + { + // printf("close error! %d\n", (int) error); + return error; + } + + workloadapi_Client_Free(client); + if (error != NO_ERROR) + { + // printf("client free error! %d\n", (int) error); + return error; + } + + return NO_ERROR; +} + +bool utf8_check_is_valid(const char *string) +{ + if (!string) + return 0; + + const unsigned char *bytes = (const unsigned char *) string; + while (*bytes) + { + if ((// ASCII + // use bytes[0] <= 0x7F to allow ASCII control characters + bytes[0] == 0x09 || + bytes[0] == 0x0A || + bytes[0] == 0x0D || + (0x20 <= bytes[0] && bytes[0] <= 0x7E) + ) + ) + { + bytes += 1; + continue; + } + + if ((// non-overlong 2-byte + (0xC2 <= bytes[0] && bytes[0] <= 0xDF) && + (0x80 <= bytes[1] && bytes[1] <= 0xBF) + ) + ) + { + bytes += 2; + continue; + } + + if ((// excluding overlongs + bytes[0] == 0xE0 && + (0xA0 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) + ) || + (// straight 3-byte + ((0xE1 <= bytes[0] && bytes[0] <= 0xEC) || + bytes[0] == 0xEE || + bytes[0] == 0xEF) && + (0x80 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) + ) || + (// excluding surrogates + bytes[0] == 0xED && + (0x80 <= bytes[1] && bytes[1] <= 0x9F) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) + ) + ) + { + bytes += 3; + continue; + } + + if ((// planes 1-3 + bytes[0] == 0xF0 && + (0x90 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) && + (0x80 <= bytes[3] && bytes[3] <= 0xBF) + ) || + (// planes 4-15 + (0xF1 <= bytes[0] && bytes[0] <= 0xF3) && + (0x80 <= bytes[1] && bytes[1] <= 0xBF) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) && + (0x80 <= bytes[3] && bytes[3] <= 0xBF) + ) || + (// plane 16 + bytes[0] == 0xF4 && + (0x80 <= bytes[1] && bytes[1] <= 0x8F) && + (0x80 <= bytes[2] && bytes[2] <= 0xBF) && + (0x80 <= bytes[3] && bytes[3] <= 0xBF) + ) + ) + { + bytes += 4; + continue; + } + + return 0; + } + + return 1; +} + + +int spiffe_fetch_jwtsvid( + char *token +) +{ + err_t error = NO_ERROR; + + if (client == NULL) + { + return -1; + } + + spiffeid_ID id = {string_new("example.org"), + string_new("/myservice")}; + string_t audience = string_new("spiffe://example.org/audience"); + jwtsvid_Params params + = {.audience = audience, .extra_audiences = NULL, .subject = id}; + jwtsvid_SVID *svid + = workloadapi_Client_FetchJWTSVID(client, ¶ms, &error); + if (error != NO_ERROR) + { + // printf("fetch error! %d\n", (int) error); + return error; + } + // printf("Address: %p\n", svid); + + spiffeid_ID_Free(&id); + arrfree(audience); + + if (svid) + { + if (token == NULL) + { + jwtsvid_SVID_Free(svid); + return -1; + } else + { + if (sizeof(token) < sizeof(svid->token)) + { + jwtsvid_SVID_Free(svid); + return -1; + } else + { + bool bResult; + bResult = utf8_check_is_valid(svid->token); + if (bResult == false) + { + return -1; + } + + memset(token, '\0', sizeof(token)); + strcpy(token, svid->token); + jwtsvid_SVID_Free(svid); + } + } + } else + { + return -1; + } + + return NO_ERROR; +} + + +int spiffe_validate_jwtsvid( + char *token +) +{ + err_t error = NO_ERROR; + + if (client == NULL) + { + return -1; + } + + if (token == NULL) + { + return -1; + } + + bool bResult; + bResult = utf8_check_is_valid(token); + if (bResult == false) + { + return -1; + } + + // string_t audience = string_new(audience_name); + string_t audience = string_new("spiffe://example.org/audience"); + jwtsvid_SVID *svid = workloadapi_Client_ValidateJWTSVID( + client, token, audience, &error); + // printf("%s %d: spiffe_validate_jwtsvid error = %d \n", __FILE__, __LINE__, (int)error); + printf("libspiffejwt: spiffe_validate_jwtsvid error = %d \n", (int) error); + if (error != NO_ERROR) + { + return error; + } + + if (svid) + { + jwtsvid_SVID_Free(svid); + } + arrfree(audience); + + return NO_ERROR; +} diff --git a/demo/libspiffejwt/spiffejwt.h b/demo/libspiffejwt/spiffejwt.h new file mode 100644 index 0000000000000000000000000000000000000000..0d2e7743443347876a668b4556ec14e95f6b5d66 --- /dev/null +++ b/demo/libspiffejwt/spiffejwt.h @@ -0,0 +1,13 @@ +#ifndef _SPIFFEJWT_H +#define _SPIFFEJWT_H + +int spiffe_start_conn(); +int spiffe_close_conn(); +int spiffe_fetch_jwtsvid( + char * token +); +int spiffe_validate_jwtsvid( + char * token +); + +#endif // _SPIFFEJWT_H diff --git a/demo/libspiffejwt/test_spiffejwt.c b/demo/libspiffejwt/test_spiffejwt.c new file mode 100644 index 0000000000000000000000000000000000000000..b4a3f42d5788ab92cb3ee7e888ecadd4152f6647 --- /dev/null +++ b/demo/libspiffejwt/test_spiffejwt.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include + +#include "spiffejwt.h" + + +#define NO_ERROR 0 + + +int main() +{ + char token[1024]; + int iResult; + + + iResult = spiffe_start_conn(); + if (iResult != NO_ERROR) + { + return -1; + } + + iResult = spiffe_fetch_jwtsvid( + token + ); + if (iResult != NO_ERROR) + { + return -1; + } else + { + printf("The feteched token: %s \n", token); + } + + iResult = spiffe_validate_jwtsvid( + token + ); + if (iResult != NO_ERROR) + { + printf("Token validate failed. \n"); + return -1; + } else + { + printf("Token validate succed. \n"); + } + + spiffe_close_conn(); + + return 0; +} + diff --git a/demo/scripts/dbus.sh b/demo/scripts/dbus.sh new file mode 100644 index 0000000000000000000000000000000000000000..78602a72b0c23061b245daee87b56cd05c887bd0 --- /dev/null +++ b/demo/scripts/dbus.sh @@ -0,0 +1,10 @@ +# export $(dbus-launch) +# echo $DBUS_SESSION_BUS_ADDRESS + + +export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-mE1jFGBAsx,guid=dad6b93cccad1aeca78dd84162f7968b +echo $DBUS_SESSION_BUS_ADDRESS + + +export DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-TdbAmwQsui,guid=3556dc166fba4469e0f7f87762f4d56a +echo $DBUS_SESSION_BUS_ADDRESS diff --git a/demo/scripts/spire/createentry_workload.sh b/demo/scripts/spire/createentry_workload.sh new file mode 100644 index 0000000000000000000000000000000000000000..e18be75946a64a185f50f69af1d7eb1ca26e38c1 --- /dev/null +++ b/demo/scripts/spire/createentry_workload.sh @@ -0,0 +1,9 @@ +# bin/spire-server entry create \ +# -parentID spiffe://example.org/myagent \ +# -spiffeID spiffe://example.org/myservice \ +# -selector unix:uid:$(id -u) + +bin/spire-server entry create \ + -parentID spiffe://example.org/myagent \ + -spiffeID spiffe://example.org/myservice \ + -selector unix:uid:1000 diff --git a/demo/scripts/spire/gentoken_agent.sh b/demo/scripts/spire/gentoken_agent.sh new file mode 100644 index 0000000000000000000000000000000000000000..afda869ccbb1d2ff67e74b782f329939db523597 --- /dev/null +++ b/demo/scripts/spire/gentoken_agent.sh @@ -0,0 +1 @@ +bin/spire-server token generate -spiffeID spiffe://example.org/myagent diff --git a/demo/scripts/spire/runagent.sh b/demo/scripts/spire/runagent.sh new file mode 100644 index 0000000000000000000000000000000000000000..41918e9d4d95c47985f3e63c04d0cd46eba3cd75 --- /dev/null +++ b/demo/scripts/spire/runagent.sh @@ -0,0 +1 @@ +bin/spire-agent run -config conf/agent/agent.conf -joinToken 16047f93-a133-494e-865e-033617d33eec diff --git a/demo/scripts/spire/runserver.sh b/demo/scripts/spire/runserver.sh new file mode 100644 index 0000000000000000000000000000000000000000..1907eec87de83ea5a1b2805bc90db002c9c3eaa0 --- /dev/null +++ b/demo/scripts/spire/runserver.sh @@ -0,0 +1 @@ +bin/spire-server run -config conf/server/server.conf diff --git a/demo/scripts/spire/showdelentry.sh b/demo/scripts/spire/showdelentry.sh new file mode 100644 index 0000000000000000000000000000000000000000..6a0183f524255beeed95be8cdefab3b700bc8943 --- /dev/null +++ b/demo/scripts/spire/showdelentry.sh @@ -0,0 +1,10 @@ +bin/spire-server entry show + +# bin/spire-server entry delete -entryID + +# rm -f .data/agent_svid.der +# rm -f .data/agent-data.json +# rm -f .data/keys.json +# bin/spire-server entry delete -entryID + +bin/spire-server entry show diff --git a/demo/scripts/tcpdump.sh b/demo/scripts/tcpdump.sh new file mode 100644 index 0000000000000000000000000000000000000000..a01f5d67031301f2b32d703490d93f66769f6799 --- /dev/null +++ b/demo/scripts/tcpdump.sh @@ -0,0 +1,2 @@ +tcpdump -vvvv -XX -i lo '(port 50051)' -w 01.cap +tcpdump -vvv -XX -r 01.cap | more diff --git a/docs/Design/design.docx b/docs/Design/design.docx new file mode 100644 index 0000000000000000000000000000000000000000..c76d0359572a00c9579991a630aa3f96c25cfc29 Binary files /dev/null and b/docs/Design/design.docx differ diff --git a/docs/deployment/deployment.docx b/docs/deployment/deployment.docx new file mode 100644 index 0000000000000000000000000000000000000000..27a3d335c73bb4f2d28f8c3b6329d49452a1c98a Binary files /dev/null and b/docs/deployment/deployment.docx differ diff --git a/docs/pic/arch-II.png b/docs/pic/arch-II.png new file mode 100644 index 0000000000000000000000000000000000000000..4f04d8fef21615c12a139428819f8c2c36f8a7df Binary files /dev/null and b/docs/pic/arch-II.png differ diff --git a/docs/test.docx b/docs/test.docx new file mode 100644 index 0000000000000000000000000000000000000000..452c1aa3d03b3aeb4597c641c043cf0c3bc36ddf Binary files /dev/null and b/docs/test.docx differ diff --git a/patch/c-spiffe_patch b/patch/c-spiffe_patch new file mode 100644 index 0000000000000000000000000000000000000000..d3f52bffe70ce1e60313ca7556b34da1977ee37e --- /dev/null +++ b/patch/c-spiffe_patch @@ -0,0 +1,507 @@ +diff -Nur c-spiffe_orign/cmake/cmake.sh c-spiffe/cmake/cmake.sh +--- c-spiffe_orign/cmake/cmake.sh 1970-01-01 08:00:00.000000000 +0800 ++++ c-spiffe/cmake/cmake.sh 2022-08-29 21:33:28.000000000 +0800 +@@ -0,0 +1,3 @@ ++# cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR .. ++cmake -DCMAKE_BUILD_TYPE=Debug .. ++ +diff -Nur c-spiffe_orign/cmake/config.h.in c-spiffe/cmake/config.h.in +--- c-spiffe_orign/cmake/config.h.in 2022-08-29 22:07:28.600000000 +0800 ++++ c-spiffe/cmake/config.h.in 1970-01-01 08:00:00.000000000 +0800 +@@ -1,24 +0,0 @@ +-/*-*- mode:C; -*- */ +-/* config.h. Generated from build/cmake/config.h.in by cmake configure */ +- +-/* +- * Ensure we have C99-style int64_t, etc, all defined. +- */ +- +-/* First, we need to know if the system has already defined them. */ +-#cmakedefine HAVE_INTMAX_T +-#cmakedefine HAVE_UINTMAX_T +- +-/* Define to `int' if doesn't define. */ +-#cmakedefine pid_t ${pid_t} +- +-/* Define intmax_t and uintmax_t if they are not already defined. */ +-#if !defined(HAVE_INTMAX_T) +-typedef int64_t intmax_t; +-#define INTMAX_MIN INT64_MIN +-#define INTMAX_MAX INT64_MAX +-#endif +- +-#if !defined(HAVE_UINTMAX_T) +-typedef uint64_t uintmax_t; +-#endif +diff -Nur c-spiffe_orign/cmake/COPYING-CMAKE-SCRIPTS.txt c-spiffe/cmake/COPYING-CMAKE-SCRIPTS.txt +--- c-spiffe_orign/cmake/COPYING-CMAKE-SCRIPTS.txt 2022-08-29 22:07:28.600000000 +0800 ++++ c-spiffe/cmake/COPYING-CMAKE-SCRIPTS.txt 1970-01-01 08:00:00.000000000 +0800 +@@ -1,22 +0,0 @@ +-Redistribution and use in source and binary forms, with or without +-modification, are permitted provided that the following conditions +-are met: +- +-1. Redistributions of source code must retain the copyright +- notice, this list of conditions and the following disclaimer. +-2. Redistributions in binary form must reproduce the copyright +- notice, this list of conditions and the following disclaimer in the +- documentation and/or other materials provided with the distribution. +-3. The name of the author may not be used to endorse or promote products +- derived from this software without specific prior written permission. +- +-THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +-IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +-OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +-IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +-NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +-THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +-THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +diff -Nur c-spiffe_orign/cmake/FindCheck.cmake c-spiffe/cmake/FindCheck.cmake +--- c-spiffe_orign/cmake/FindCheck.cmake 2022-08-29 22:07:28.600000000 +0800 ++++ c-spiffe/cmake/FindCheck.cmake 1970-01-01 08:00:00.000000000 +0800 +@@ -1,57 +0,0 @@ +-# - Try to find the CHECK libraries +-# Once done this will define +-# +-# CHECK_FOUND - system has check +-# CHECK_INCLUDE_DIR - the check include directory +-# CHECK_LIBRARIES - check library +-# +-# This configuration file for finding libcheck is originally from +-# the opensync project. The originally was downloaded from here: +-# opensync.org/browser/branches/3rd-party-cmake-modules/modules/FindCheck.cmake +-# +-# Copyright (c) 2007 Daniel Gollub +-# Copyright (c) 2007 Bjoern Ricks +-# +-# Redistribution and use is allowed according to the terms of the New +-# BSD license. +-# For details see the accompanying COPYING-CMAKE-SCRIPTS file. +- +- +-INCLUDE( FindPkgConfig ) +- +-# Take care about check.pc settings +-PKG_SEARCH_MODULE( CHECK Check ) +- +-# Look for CHECK include dir and libraries +-IF( NOT CHECK_FOUND ) +- IF ( CHECK_INSTALL_DIR ) +- MESSAGE ( STATUS "Using override CHECK_INSTALL_DIR to find Check" ) +- SET ( CHECK_INCLUDE_DIR "${CHECK_INSTALL_DIR}/include" ) +- SET ( CHECK_INCLUDE_DIRS "${CHECK_INCLUDE_DIR}" ) +- FIND_LIBRARY( CHECK_LIBRARY NAMES check PATHS "${CHECK_INSTALL_DIR}/lib" ) +- FIND_LIBRARY( COMPAT_LIBRARY NAMES compat PATHS "${CHECK_INSTALL_DIR}/lib" ) +- SET ( CHECK_LIBRARIES "${CHECK_LIBRARY}" "${COMPAT_LIBRARY}" ) +- ELSE ( CHECK_INSTALL_DIR ) +- FIND_PATH( CHECK_INCLUDE_DIR check.h ) +- FIND_LIBRARY( CHECK_LIBRARIES NAMES check ) +- ENDIF ( CHECK_INSTALL_DIR ) +- +- IF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) +- SET( CHECK_FOUND 1 ) +- IF ( NOT Check_FIND_QUIETLY ) +- MESSAGE ( STATUS "Found CHECK: ${CHECK_LIBRARIES}" ) +- ENDIF ( NOT Check_FIND_QUIETLY ) +- ELSE ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) +- IF ( Check_FIND_REQUIRED ) +- MESSAGE( FATAL_ERROR "Could NOT find CHECK" ) +- ELSE ( Check_FIND_REQUIRED ) +- IF ( NOT Check_FIND_QUIETLY ) +- MESSAGE( STATUS "Could NOT find CHECK" ) +- ENDIF ( NOT Check_FIND_QUIETLY ) +- ENDIF ( Check_FIND_REQUIRED ) +- ENDIF ( CHECK_INCLUDE_DIR AND CHECK_LIBRARIES ) +-ENDIF( NOT CHECK_FOUND ) +- +-# Hide advanced variables from CMake GUIs +-MARK_AS_ADVANCED( CHECK_INCLUDE_DIR CHECK_LIBRARIES ) +- +diff -Nur c-spiffe_orign/CMakeLists.txt c-spiffe/CMakeLists.txt +--- c-spiffe_orign/CMakeLists.txt 2022-08-29 22:07:28.596000000 +0800 ++++ c-spiffe/CMakeLists.txt 2022-08-29 21:33:28.000000000 +0800 +@@ -28,33 +28,10 @@ + set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + + set(CMAKE_CXX_STANDARD 14) +-set(protobuf_MODULE_COMPATIBLE TRUE) + +-find_package(Protobuf 3.13.0 REQUIRED) +-find_package(gRPC 1.34.0 REQUIRED) + +-message(STATUS "Using protobuf ${Protobuf_VERSION}") ++include(common.cmake) + +-set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) +-set(_REFLECTION gRPC::grpc++_reflection) +- +-if(CMAKE_CROSSCOMPILING) +- find_program(_PROTOBUF_PROTOC protoc) +-else() +- set(_PROTOBUF_PROTOC $) +-endif() +- +-# Find gRPC installation +-# Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. +-find_package(gRPC CONFIG REQUIRED) +-message(STATUS "Using gRPC ${gRPC_VERSION}") +- +-set(_GRPC_GRPCPP gRPC::grpc++) +-if(CMAKE_CROSSCOMPILING) +- find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) +-else() +- set(_GRPC_CPP_PLUGIN_EXECUTABLE $) +-endif() + + # Enable Coverage Tests + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fprofile-arcs -ftest-coverage -g -O0") +diff -Nur c-spiffe_orign/common.cmake c-spiffe/common.cmake +--- c-spiffe_orign/common.cmake 1970-01-01 08:00:00.000000000 +0800 ++++ c-spiffe/common.cmake 2022-08-29 21:33:28.000000000 +0800 +@@ -0,0 +1,129 @@ ++# Copyright 2018 gRPC authors. ++# ++# Licensed 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. ++# ++# cmake build file for C++ route_guide example. ++# Assumes protobuf and gRPC have been installed using cmake. ++# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build ++# that automatically builds all the dependencies before building route_guide. ++ ++cmake_minimum_required(VERSION 3.5.1) ++ ++# set (CMAKE_CXX_STANDARD 11) ++set (CMAKE_CXX_STANDARD 14) ++ ++set (GRPC_FETCHCONTENT 1) ++ ++ ++if(MSVC) ++ add_definitions(-D_WIN32_WINNT=0x600) ++endif() ++ ++find_package(Threads REQUIRED) ++ ++if(GRPC_AS_SUBMODULE) ++ # One way to build a projects that uses gRPC is to just include the ++ # entire gRPC project tree via "add_subdirectory". ++ # This approach is very simple to use, but the are some potential ++ # disadvantages: ++ # * it includes gRPC's CMakeLists.txt directly into your build script ++ # without and that can make gRPC's internal setting interfere with your ++ # own build. ++ # * depending on what's installed on your system, the contents of submodules ++ # in gRPC's third_party/* might need to be available (and there might be ++ # additional prerequisites required to build them). Consider using ++ # the gRPC_*_PROVIDER options to fine-tune the expected behavior. ++ # ++ # A more robust approach to add dependency on gRPC is using ++ # cmake's ExternalProject_Add (see cmake_externalproject/CMakeLists.txt). ++ ++ # Include the gRPC's cmake build (normally grpc source code would live ++ # in a git submodule called "third_party/grpc", but this example lives in ++ # the same repository as gRPC sources, so we just look a few directories up) ++ add_subdirectory(../../.. ${CMAKE_CURRENT_BINARY_DIR}/grpc EXCLUDE_FROM_ALL) ++ message(STATUS "Using gRPC via add_subdirectory.") ++ ++ # After using add_subdirectory, we can now use the grpc targets directly from ++ # this build. ++ set(_PROTOBUF_LIBPROTOBUF libprotobuf) ++ set(_REFLECTION grpc++_reflection) ++ if(CMAKE_CROSSCOMPILING) ++ find_program(_PROTOBUF_PROTOC protoc) ++ else() ++ set(_PROTOBUF_PROTOC $) ++ endif() ++ set(_GRPC_GRPCPP grpc++) ++ if(CMAKE_CROSSCOMPILING) ++ find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) ++ else() ++ set(_GRPC_CPP_PLUGIN_EXECUTABLE $) ++ endif() ++elseif(GRPC_FETCHCONTENT) ++ # Another way is to use CMake's FetchContent module to clone gRPC at ++ # configure time. This makes gRPC's source code available to your project, ++ # similar to a git submodule. ++ message(STATUS "Using gRPC via add_subdirectory (FetchContent).") ++ include(FetchContent) ++ FetchContent_Declare( ++ grpc ++ GIT_REPOSITORY https://github.com/grpc/grpc.git ++ # when using gRPC, you will actually set this to an existing tag, such as ++ # v1.25.0, v1.26.0 etc.. ++ # For the purpose of testing, we override the tag used to the commit ++ # that's currently under test. ++ # GIT_TAG vGRPC_TAG_VERSION_OF_YOUR_CHOICE) ++ GIT_TAG v1.48.0 ++ ) ++ FetchContent_MakeAvailable(grpc) ++ ++ # Since FetchContent uses add_subdirectory under the hood, we can use ++ # the grpc targets directly from this build. ++ set(_PROTOBUF_LIBPROTOBUF libprotobuf) ++ set(_REFLECTION grpc++_reflection) ++ set(_PROTOBUF_PROTOC $) ++ set(_GRPC_GRPCPP grpc++) ++ if(CMAKE_CROSSCOMPILING) ++ find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) ++ else() ++ set(_GRPC_CPP_PLUGIN_EXECUTABLE $) ++ endif() ++else() ++ # This branch assumes that gRPC and all its dependencies are already installed ++ # on this system, so they can be located by find_package(). ++ ++ # Find Protobuf installation ++ # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation. ++ set(protobuf_MODULE_COMPATIBLE TRUE) ++ find_package(Protobuf CONFIG REQUIRED) ++ message(STATUS "Using protobuf ${Protobuf_VERSION}") ++ ++ set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) ++ set(_REFLECTION gRPC::grpc++_reflection) ++ if(CMAKE_CROSSCOMPILING) ++ find_program(_PROTOBUF_PROTOC protoc) ++ else() ++ set(_PROTOBUF_PROTOC $) ++ endif() ++ ++ # Find gRPC installation ++ # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. ++ find_package(gRPC CONFIG REQUIRED) ++ message(STATUS "Using gRPC ${gRPC_VERSION}") ++ ++ set(_GRPC_GRPCPP gRPC::grpc++) ++ if(CMAKE_CROSSCOMPILING) ++ find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) ++ else() ++ set(_GRPC_CPP_PLUGIN_EXECUTABLE $) ++ endif() ++endif() +diff -Nur c-spiffe_orign/protos/google/protobuf/struct.proto c-spiffe/protos/google/protobuf/struct.proto +--- c-spiffe_orign/protos/google/protobuf/struct.proto 1970-01-01 08:00:00.000000000 +0800 ++++ c-spiffe/protos/google/protobuf/struct.proto 2022-08-29 21:33:28.000000000 +0800 +@@ -0,0 +1,95 @@ ++// Protocol Buffers - Google's data interchange format ++// Copyright 2008 Google Inc. All rights reserved. ++// https://developers.google.com/protocol-buffers/ ++// ++// Redistribution and use in source and binary forms, with or without ++// modification, are permitted provided that the following conditions are ++// met: ++// ++// * Redistributions of source code must retain the above copyright ++// notice, this list of conditions and the following disclaimer. ++// * Redistributions in binary form must reproduce the above ++// copyright notice, this list of conditions and the following disclaimer ++// in the documentation and/or other materials provided with the ++// distribution. ++// * Neither the name of Google Inc. nor the names of its ++// contributors may be used to endorse or promote products derived from ++// this software without specific prior written permission. ++// ++// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ++// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ++// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ++// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ++// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ++// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ++// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ++// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ++// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ++// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ++// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ++ ++syntax = "proto3"; ++ ++package google.protobuf; ++ ++option csharp_namespace = "Google.Protobuf.WellKnownTypes"; ++option cc_enable_arenas = true; ++option go_package = "google.golang.org/protobuf/types/known/structpb"; ++option java_package = "com.google.protobuf"; ++option java_outer_classname = "StructProto"; ++option java_multiple_files = true; ++option objc_class_prefix = "GPB"; ++ ++// `Struct` represents a structured data value, consisting of fields ++// which map to dynamically typed values. In some languages, `Struct` ++// might be supported by a native representation. For example, in ++// scripting languages like JS a struct is represented as an ++// object. The details of that representation are described together ++// with the proto support for the language. ++// ++// The JSON representation for `Struct` is JSON object. ++message Struct { ++ // Unordered map of dynamically typed values. ++ map fields = 1; ++} ++ ++// `Value` represents a dynamically typed value which can be either ++// null, a number, a string, a boolean, a recursive struct value, or a ++// list of values. A producer of value is expected to set one of these ++// variants. Absence of any variant indicates an error. ++// ++// The JSON representation for `Value` is JSON value. ++message Value { ++ // The kind of value. ++ oneof kind { ++ // Represents a null value. ++ NullValue null_value = 1; ++ // Represents a double value. ++ double number_value = 2; ++ // Represents a string value. ++ string string_value = 3; ++ // Represents a boolean value. ++ bool bool_value = 4; ++ // Represents a structured value. ++ Struct struct_value = 5; ++ // Represents a repeated `Value`. ++ ListValue list_value = 6; ++ } ++} ++ ++// `NullValue` is a singleton enumeration to represent the null value for the ++// `Value` type union. ++// ++// The JSON representation for `NullValue` is JSON `null`. ++enum NullValue { ++ // Null value. ++ NULL_VALUE = 0; ++} ++ ++// `ListValue` is a wrapper around a repeated field of values. ++// ++// The JSON representation for `ListValue` is JSON array. ++message ListValue { ++ // Repeated field of dynamically typed values. ++ repeated Value values = 1; ++} +diff -Nur c-spiffe_orign/spiffetls/CMakeLists.txt c-spiffe/spiffetls/CMakeLists.txt +--- c-spiffe_orign/spiffetls/CMakeLists.txt 2022-08-29 22:07:28.628000000 +0800 ++++ c-spiffe/spiffetls/CMakeLists.txt 2022-08-29 21:33:28.000000000 +0800 +@@ -49,7 +49,7 @@ + + target_link_libraries(${TARGET_NAME} + svid +- ssl ++ # ssl + spiffeid + internal + bundle +@@ -61,7 +61,10 @@ + rt + m + pthread +- crypto) ++ # crypto ++ libcrypto.so ++ libssl.so ++ ) + + # Install Headers: + set(HEADERS_SPIFFETLS +diff -Nur c-spiffe_orign/svid/jwtsvid/parse.c c-spiffe/svid/jwtsvid/parse.c +--- c-spiffe_orign/svid/jwtsvid/parse.c 2022-08-29 22:07:28.632000000 +0800 ++++ c-spiffe/svid/jwtsvid/parse.c 2022-08-29 21:33:28.000000000 +0800 +@@ -85,6 +85,17 @@ + payload_str_len, 0, NULL); + + char *signature = strtok(NULL, dot); ++ ////////////////////////////////////////////////////////////////////// ++ // fjyu@whu.edu.cn debug 2022.07.08 ++ if (signature == NULL) { ++ printf("%s %d: parsed signature is null \n", __FILE__, __LINE__); ++ jwtsvid_JWT_Free(jwt); ++ *err = ERR_PARSING; ++ return NULL; ++ } else { ++ // printf("%s %d: parsed signature is %s \n", __FILE__, __LINE__, signature); ++ } ++ ////////////////////////////////////////////////////////////////////// + signature[-1] = '.'; + jwt->signature = string_new(signature); + free(header_str); +diff -Nur c-spiffe_orign/workload/client.cc c-spiffe/workload/client.cc +--- c-spiffe_orign/workload/client.cc 2022-08-29 22:07:28.636000000 +0800 ++++ c-spiffe/workload/client.cc 2022-08-29 21:33:28.000000000 +0800 +@@ -244,6 +244,7 @@ + return NO_ERROR; + } + ++ + err_t workloadapi_Client_Connect(workloadapi_Client *client) + { + if(!client) { +@@ -252,7 +253,7 @@ + // if client already has a stub, we don't create a new one. + if(!client->stub) { + std::shared_ptr chan = grpc::CreateChannel( +- client->address, grpc::InsecureChannelCredentials()); ++ client->address, grpc::InsecureChannelCredentials()); + if(!chan) { + return ERR_NULL; + } +@@ -737,7 +738,13 @@ + char *token, char *audience, + err_t *err) + { +- grpc::ClientContext ctx; ++ // grpc::ClientContext ctx; ++ grpc::ClientContext *ctx = new grpc::ClientContext(); ++ ++ if(client->headers) { ++ for(int i = 0; i < arrlen(client->headers); i += 2) ++ ctx->AddMetadata(client->headers[i], client->headers[i + 1]); ++ } + + ValidateJWTSVIDRequest req; + req.set_svid(token); +@@ -745,9 +752,10 @@ + + ValidateJWTSVIDResponse resp; + grpc::Status status = ((SpiffeWorkloadAPI::StubInterface *) client->stub) +- ->ValidateJWTSVID(&ctx, req, &resp); +- ++ ->ValidateJWTSVID(ctx, req, &resp); ++ // ->ValidateJWTSVID(&ctx, req, &resp); + if(status.ok()) { ++ // printf("%s %d: workloadapi_Client_ValidateJWTSVID, status ok \n", __FILE__, __LINE__); + // parse response + string_arr_t audiences_array = NULL; + arrput(audiences_array, audience); +@@ -757,6 +765,7 @@ + + return svid; + } else { ++ // printf("%s %d: workloadapi_Client_ValidateJWTSVID, err = %d \n", __FILE__, __LINE__, (int)ERR_BAD_REQUEST); + // could not validate jwt svid + *err = ERR_BAD_REQUEST; + return NULL; +diff -Nur c-spiffe_orign/workload/CMakeLists.txt c-spiffe/workload/CMakeLists.txt +--- c-spiffe_orign/workload/CMakeLists.txt 2022-08-29 22:07:28.636000000 +0800 ++++ c-spiffe/workload/CMakeLists.txt 2022-08-29 21:33:28.000000000 +0800 +@@ -70,7 +70,9 @@ + rt + m + pthread +-crypto) ++# crypto ++libcrypto.so ++) + + + # Install Headers: diff --git a/teeproxy/gpproxy/CMakeLists.txt b/teeproxy/gpproxy/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..2b333c50477bbd44a7984392a81700470fa42590 --- /dev/null +++ b/teeproxy/gpproxy/CMakeLists.txt @@ -0,0 +1,107 @@ +# +# + +cmake_minimum_required(VERSION 3.5.1) + +project(gpp C CXX) + +include(common.cmake) + +# Proto file +get_filename_component(gt_proto "./protos/gt.proto" ABSOLUTE) +get_filename_component(gt_proto_path "${gt_proto}" PATH) +# [[get_filename_component(proto "../protos/${proto_name}.proto" ABSOLUTE) +# get_filename_component(proto_dir "${proto}" DIRECTORY)]] + +# Generated sources +set(gt_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/gt.pb.cc") +set(gt_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gt.pb.h") +set(gt_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/gt.grpc.pb.cc") +set(gt_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gt.grpc.pb.h") + +add_custom_command( + OUTPUT "${gt_proto_srcs}" "${gt_proto_hdrs}" "${gt_grpc_srcs}" "${gt_grpc_hdrs}" + COMMAND ${_PROTOBUF_PROTOC} + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" + -I "${gt_proto_path}" + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + "${gt_proto}" + DEPENDS "${gt_proto}" +) + +# Include generated *.pb.h files +include_directories("${CMAKE_CURRENT_BINARY_DIR}") +include_directories(/usr/include/dbus-1.0/) +include_directories(/usr/lib64/dbus-1.0/include/) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include) + +# Introduce variables: +# - CMAKE_INSTALL_LIBDIR +# - CMAKE_INSTALL_BINDIR +# - CMAKE_INSTALL_INCLUDEDIR +include(GNUInstallDirs) + +# gt_grpc_proto +add_library(gt_grpc_proto + ${gt_grpc_srcs} + ${gt_grpc_hdrs} + ${gt_proto_srcs} + ${gt_proto_hdrs} +) +target_link_libraries(gt_grpc_proto + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF} +) + + +add_executable(gpproxy + "gpproxy.cc" + ${gt_grpc_srcs} + ${gt_proto_srcs} +) +target_link_libraries(gpproxy + gt_grpc_proto + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF} + libdbusc_gpw.so + libdbusc_jwt.so + yaml-cpp.a +) + +# Install bin +install( + TARGETS gpproxy + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" +) +# Install config file +set(gpp_config_dir "$ENV{HOME}/.gpp") +install( + FILES "conf/gpproxy_config.yaml" + DESTINATION ${gpp_config_dir} +) +# Install certs +set(gpp_certs_dir "$ENV{HOME}/.gpp/certs") +install( + FILES + "certs/server_key.pem" + "certs/server_crt.pem" + "certs/ca_key.pem" + "certs/ca_crt.pem" + "certs/gen_ca_keycrt.sh" + "certs/gen_server_keycrt.sh" + "certs/gen_client_keycsr.sh" + "certs/msg.txt" + "certs/check_ca_key.sh" + "certs/check_ca_crt.sh" + "certs/check_server_key.sh" + "certs/check_server_crt.sh" + "certs/check_client_key.sh" + "certs/check_client_crt.sh" + "certs/gen_ca_crt.sh" + "certs/gen_server_crt.sh" + "certs/gen_client_crt.sh" + DESTINATION ${gpp_certs_dir} +) diff --git a/teeproxy/gpproxy/build/cmake.sh b/teeproxy/gpproxy/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..4511f0072874fb7ebcf80b133d708950744f98d0 --- /dev/null +++ b/teeproxy/gpproxy/build/cmake.sh @@ -0,0 +1,3 @@ +# cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR .. +cmake -DCMAKE_BUILD_TYPE=Debug .. + diff --git a/teeproxy/gpproxy/certs/ca_crt.pem b/teeproxy/gpproxy/certs/ca_crt.pem new file mode 100644 index 0000000000000000000000000000000000000000..c1f851aedaf68806e3d67e41c984d5f1ff2ba96e --- /dev/null +++ b/teeproxy/gpproxy/certs/ca_crt.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDozCCAougAwIBAgIUZoRrQX6TrtP0Reyf9DbHVJRNDoQwDQYJKoZIhvcNAQEL +BQAwYTELMAkGA1UEBhMCQ04xDjAMBgNVBAgMBUh1YmVpMQ4wDAYDVQQHDAVXdWhh +bjESMBAGA1UECgwJVHJ1c3RDdXRlMQ0wCwYDVQQLDARnUlBDMQ8wDQYDVQQDDAZj +YS5vcmcwHhcNMjIwODIwMDQ1OTUyWhcNMzIwODE3MDQ1OTUyWjBhMQswCQYDVQQG +EwJDTjEOMAwGA1UECAwFSHViZWkxDjAMBgNVBAcMBVd1aGFuMRIwEAYDVQQKDAlU +cnVzdEN1dGUxDTALBgNVBAsMBGdSUEMxDzANBgNVBAMMBmNhLm9yZzCCASIwDQYJ +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMYdYD9GChLzSOWmaIcHMqx8itp/7Zvx +7y2qgb23EWCWIz01kPQaCXpuSOi38dFipXFBWo5o3GaezIoSCp66eN3kHGpcluu2 +0nbyh7zdUVCSXhNWbEiwlhC53DDs2SBYWr2KGTRDEcJEXli110v8sEGZQvkj3XGF +B6IbTczMbhpVfJ82RMqGqNYSJ5jCvqw3XOX6xoN4CP3PuAKC6MtEkLLkXQOS72oL +TSE9XoZNqlyhmymAVwQwCV1zT28W/hwKbCN4tVoO+1bwc3togNYO0W7x1GgOoNoZ +va1UNDX1sfW6B041TgSTGQ0OhGzgKWadKHm2UpG2d5NLkaiBUPpvuokCAwEAAaNT +MFEwHQYDVR0OBBYEFKrFU5qoBe2AkvvTiOfwY24T36zTMB8GA1UdIwQYMBaAFKrF +U5qoBe2AkvvTiOfwY24T36zTMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL +BQADggEBACjfqOa6G596NbFfAAhBFFS+RIueRWdDkBxR7kk+eQ3Z5j4hIBmrA0OS +R6KCrvmvnXxqSBRmuwRfs0e7G76jkUAFFHkslTPLwgklWCarsGXeAkrdgQU7WL4n +NYBNnjUNK11JREUdAXgvzyuLOhjf4l5UvhujWivhviChFB8xpTQfq2d1oE9jsotv +r2opic4ynu69LXd8HZiShabXgQ60/BNOX8D+wb1YzoZlUCKzSH15QRuuEbkj4/Hy +R2+qxUODbuwfqI4fkOvQIIrD2NO89nHpWFtui4ByQEQaeTesus8M8corCekrxr08 +VkxuOGg2U3zWUlLuSZMD2G7KWuDXU78= +-----END CERTIFICATE----- diff --git a/teeproxy/gpproxy/certs/ca_key.pem b/teeproxy/gpproxy/certs/ca_key.pem new file mode 100644 index 0000000000000000000000000000000000000000..8a1fb51d7af46a42a0db7c8236e2bb3d13558425 --- /dev/null +++ b/teeproxy/gpproxy/certs/ca_key.pem @@ -0,0 +1,30 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-192-CBC,39D9C0B289197FF4451BD03C066C8895 + +HZGExFo0mzCidPeXEb1DWkawC2XnTOZfZoHw7+aZGdTXnnbK8x72UuX7CgfyqVrQ +nVgGHJioD/0TpwhhRhgFCs8xPPVmKWIHssgXKz1ZzSHwQSamby/1aGq1bJtVY7VL +qAgUjkMVClErKIiR4ZAAC/Z95BW3ap/K9GmagAFdcGlaiLyXImS/gC3KRxkTZLNn +5Zfq7+XwBp3tWDjM6SLHvYtvsALs2+g8bJUXZFA9OvRZogPnL9EEaTfrjlYBuN2z +0lf2NSQhuAxPN/Qo80l7u6wKIojM+OnWZITbiMit/QmYAEa6znJbt9EWNEYdnIXr +P1NP0zU9ycBDFELNJwZcEUj+Ua9BxPwN01NgBBbPDuFikpyojzcNzm++ZG/uFc5s +LuSYm3lLuhsENVAXx7iwBTBAAWbQxYf8XOP3Nnhj83K/hgL5rfIKMkaFC2+FMvfo +SnIWitAImbn0IB9XncdRkJ9BTOLks/2VOWuVPknNCEGcNEJuL5p/FWCBHQa0eqeT +a84FdLXhN9wSjPaskb8gk+QDSh0L0bTByJC584u2P4Wwb/aJNPzicBBJWVc2DObL +OUYfad1NOvl7uXoe8vRsdYGQOtcUYjfw82MB1855JsuFj7CQwp+ZnO2tu7crnf0Q +v3YL4FAAIHFUi+/w5w6Vp2By86BTApCiStFuSxI+1VabbfpWLk/rtQE9uMTfFLaF +LFQszev4POfEC1u3XegJc+ccYcADxuXseHj07UtCKQkoqAX/lahvOCK2hk2BYQdh +sHtrcJjZqSjDtm4Ec08pfjSKjISVoT5aWlFK0W9RJFsQNoWip7ZIAZwRy8ZPrVOx +bvBiSTYeuwa3Z7J5uGJZKH0Y0zYbwtsWvfIH8jgB+BRSBLQPKqlbPCCSNSfR8iVy +x446hB/a9HONTot5TCDuJ5T12Kw61mTupWGRLzImg6cm+anTXNSHDopTN9eugHE7 +eUvbzzpVYZ1AJduIdPYvzznOYq6T+jbBPiDTg1zUr3R3eLqOBpYJABnDxJlcOyCD +YHL2Ns/EFSMjLm0EyRGNP6a5NdsYljAFqrHMU2MHdj/GqNKWDzdVtMSZXG/1Xui7 +/Iu5xRMPtE7qEudVIupDFfgMzj9hZfM984N6B5exq6ZGMhwlJ/YBB8VpxRuW4Adi +32VTO5nF4M7m71jcOfFmaKz85u2g6RIctEIzJRZ0F4YmI33bj8HPTodV2bmtxd9V +6jipxZ4gO3zuKUsOUnmCkAp3Y9WgPZXsTS3WksFY4+Q3+vjQAlx3xMsTXpi2wKvi +uxYflNKeWPJQzBsdUAhEsffbIN+RTomnZh9ze4nO+8i1B/Hob3mxlTOVzIP6udvc +6NaZV6n42z1cv/X+5mexB74umFkpicMveNpaSGZO43v8ai6gppI4SaO9Wa7T3gWu +d6dchs+/gG0nZWsrq8XZmoEqywxqUEI/OR2dp/298cQYZug+psw4QJ3kXmRwu8qG +l3qjxpFyak64GLGNcfsd4KYOmsAtEZY/EDfVhVG4lexMInxDNMSziBEphocHbQlR +LpxryE9vfZZHOtbQuN1Bp/6KiH3kuVVLMNvIWrik6aeO8xc7vnT6ExKk8PENGo1L +-----END RSA PRIVATE KEY----- diff --git a/teeproxy/gpproxy/certs/check_ca_crt.sh b/teeproxy/gpproxy/certs/check_ca_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..83cffa1ecbc4be261b799111ad3b464cd8940322 --- /dev/null +++ b/teeproxy/gpproxy/certs/check_ca_crt.sh @@ -0,0 +1,42 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the cert expiry date in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# CACRTPEM=$HOME/.gpp/certs/ca_crt.pem +# REGENCRTSCRIPT=${HOME}/gen_ca_crt.sh +CUR_DIR=$( dirname -- "$0"; ) +CACRTPEM=$CUR_DIR/ca_crt.pem +REGENCRTSCRIPT=${CUR_DIR}/gen_ca_crt.sh + +# 7 days in seconds +DAYS="604800" + +# Email settings +_sub=$CACRTPEM" will expire within $DAYS seconds (7 days)" +# _sub="${CACRTPEM} will expire within $DAYS seconds (7 days)" +_from="system-account@your-dommain" +_to="sysadmin@your-domain" + +echo -e '\n'get date of $CACRTPEM: +openssl x509 -in $CACRTPEM -noout -dates + +echo -e '\n'check expiry of $CACRTPEM: +$_openssl x509 -enddate -noout -in "$CACRTPEM" -checkend "$DAYS" +$_openssl x509 -enddate -noout -in "$CACRTPEM" -checkend "$DAYS" | grep -q 'Certificate will expire' +# If will expire, regenerate key and certifcate +# // , and send email +if [ $? -eq 0 ] +then + echo "${_sub}" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${REGENCRTSCRIPT} +fi diff --git a/teeproxy/gpproxy/certs/check_ca_key.sh b/teeproxy/gpproxy/certs/check_ca_key.sh new file mode 100644 index 0000000000000000000000000000000000000000..4461e1f3018171abd4013f9b5355cd362b0a1360 --- /dev/null +++ b/teeproxy/gpproxy/certs/check_ca_key.sh @@ -0,0 +1,63 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the interity of key in advance +# Author: under license +# ------------------------------------------------------------------------------- + +_openssl="openssl" + + +CUR_DIR=$( dirname -- "$0"; ) + + +# KEYPEM=$HOME/.gpp/certs/ca_key.pem +# PUBPEM=$HOME/.gpp/certs/ca_pubkey.pem +# CRTPEM=$HOME/.gpp/certs/ca_crt.pem +# MSGTXT=$HOME/.gpp/certs/msg.txt +# MSGSIG=$HOME/.gpp/certs/msg.sig +# GENKEYCRTSCRIPT=${HOME}/.gpp/certs/gen_ca_keycrt.sh +KEYPEM=$CUR_DIR/ca_key.pem +PUBPEM=$CUR_DIR/ca_pubkey.pem +CRTPEM=$CUR_DIR/ca_crt.pem +MSGTXT=${CUR_DIR}/msg.txt +MSGSIG=${CUR_DIR}/msg.sig +GENKEYCRTSCRIPT=${CUR_DIR}/gen_ca_keycrt.sh + +echo -e '\n'check integrity of ${KEYPEM}: +# ${_openssl} rsa -in ${KEYPEM} -passin pass:111111 -check -noout +# ${_openssl} rsa -in ${KEYPEM} -check -noout +${_openssl} rsa -in ${KEYPEM} -check -noout | grep -q 'RSA key ok' +if [ $? -ne 0 ] +then + echo "the integrity of "${KEYPEM}" is broken" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +else + echo -e "RSA key ok" +fi + +echo -e '\n'use private ${KEYPEM} to sign ${MSGTXT}: +# ${_openssl} dgst -sha256 -sign ${KEYPEM} -passin pass:111111 -out msg.sig msg.txt +${_openssl} dgst -sha256 -sign ${KEYPEM} -out ${MSGSIG} ${MSGTXT} + +echo -e '\n'get public key from ${CRTPEM}: +${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + +echo -e '\n'use public key in ${CRTPEM} to verify signature of ${MSGTXT}: +# ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} | grep -q 'Verified OK' +if [ $? -ne 0 ] +then + echo ${KEYPEM}" is not matched with "${CRTPEM} + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +fi +rm -f ${PUBPEM} diff --git a/teeproxy/gpproxy/certs/check_client_crt.sh b/teeproxy/gpproxy/certs/check_client_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..769041a5541580a71f056a5575b489c476135f19 --- /dev/null +++ b/teeproxy/gpproxy/certs/check_client_crt.sh @@ -0,0 +1,43 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the cert expiry date in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# CRTPEM=$HOME/.gpp/certs/client_crt.pem +# REGENCRTSCRIPT=${HOME}/gen_client_crt.sh +CUR_DIR=$( dirname -- "$0"; ) +CRTPEM=$CUR_DIR/client_crt.pem +REGENCRTSCRIPT=${CUR_DIR}/gen_client_crt.sh + +# 7 days in seconds +DAYS="604800" + +# Email settings +_sub=$CRTPEM" will expire within $DAYS seconds (7 days)" +# _sub="${CRTPEM} will expire within $DAYS seconds (7 days)" +_from="system-account@your-dommain" +_to="sysadmin@your-domain" + + +echo -e '\n'get date of $CRTPEM: +openssl x509 -in $CRTPEM -noout -dates + +echo -e '\n'check expiry of $CRTPEM: +$_openssl x509 -enddate -noout -in "$CRTPEM" -checkend "$DAYS" +$_openssl x509 -enddate -noout -in "$CRTPEM" -checkend "$DAYS" | grep -q 'Certificate will expire' +# If will expire, regenerate key and certifcate +# // , and send email +if [ $? -eq 0 ] +then + echo "${_sub}" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${REGENCRTSCRIPT} +fi diff --git a/teeproxy/gpproxy/certs/check_client_key.sh b/teeproxy/gpproxy/certs/check_client_key.sh new file mode 100644 index 0000000000000000000000000000000000000000..c62d32c772e3d7546db67d07b041efc2ddd2e060 --- /dev/null +++ b/teeproxy/gpproxy/certs/check_client_key.sh @@ -0,0 +1,62 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the interity of key in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# KEYPEM=$HOME/.gpp/certs/client_key.pem +# PUBPEM=$HOME/.gpp/certs/client_pubkey.pem +# CRTPEM=$HOME/.gpp/certs/client_crt.pem +# MSGTXT=$HOME/.gpp/certs/msg.txt +# MSGSIG=$HOME/.gpp/certs/msg.sig +# GENKEYCRTSCRIPT=${HOME}/.gpp/certs/gen_client_keycrt.sh +CUR_DIR=$( dirname -- "$0"; ) +KEYPEM=$CUR_DIR/client_key.pem +PUBPEM=$CUR_DIR/client_pubkey.pem +CRTPEM=$CUR_DIR/client_crt.pem +MSGTXT=${CUR_DIR}/msg.txt +MSGSIG=${CUR_DIR}/msg.sig +GENKEYCRTSCRIPT=${CUR_DIR}/gen_client_keycrt.sh + +echo -e '\n'check integrity of ${KEYPEM}: +# ${_openssl} rsa -in ${KEYPEM} -passin pass:111111 -check -noout +# ${_openssl} rsa -in ${KEYPEM} -check -noout +${_openssl} rsa -in ${KEYPEM} -check -noout | grep -q 'RSA key ok' +if [ $? -ne 0 ] +then + echo "the integrity of "${KEYPEM}" is broken" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +else + echo -e "RSA key ok" +fi + +echo -e '\n'use private ${KEYPEM} to sign ${MSGTXT}: +# ${_openssl} dgst -sha256 -sign ${KEYPEM} -passin pass:111111 -out msg.sig msg.txt +${_openssl} dgst -sha256 -sign ${KEYPEM} -out ${MSGSIG} ${MSGTXT} + +echo -e '\n'get public key from ${CRTPEM}: +${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + +echo -e '\n'use public key in ${CRTPEM} to verify signature of ${MSGTXT}: +# ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} | grep -q 'Verified OK' +if [ $? -ne 0 ] +then + echo ${KEYPEM}" is not matched with "${CRTPEM} + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +fi +rm -f ${PUBPEM} diff --git a/teeproxy/gpproxy/certs/check_server_crt.sh b/teeproxy/gpproxy/certs/check_server_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..acedfcea0ff3953029889d87196de46689cac166 --- /dev/null +++ b/teeproxy/gpproxy/certs/check_server_crt.sh @@ -0,0 +1,43 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the cert expiry date in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# CRTPEM=$HOME/.gpp/certs/server_crt.pem +# REGENCRTSCRIPT=${HOME}/gen_server_crt.sh +CUR_DIR=$( dirname -- "$0"; ) +CRTPEM=$CUR_DIR/server_crt.pem +REGENCRTSCRIPT=${CUR_DIR}/gen_server_crt.sh + +# 7 days in seconds +DAYS="604800" + +# Email settings +_sub=$CRTPEM" will expire within $DAYS seconds (7 days)" +# _sub="${CRTPEM} will expire within $DAYS seconds (7 days)" +_from="system-account@your-dommain" +_to="sysadmin@your-domain" + + +echo -e '\n'get date of $CRTPEM: +openssl x509 -in $CRTPEM -noout -dates + +echo -e '\n'check expiry of $CRTPEM: +$_openssl x509 -enddate -noout -in "$CRTPEM" -checkend "$DAYS" +$_openssl x509 -enddate -noout -in "$CRTPEM" -checkend "$DAYS" | grep -q 'Certificate will expire' +# If will expire, regenerate key and certifcate +# // , and send email +if [ $? -eq 0 ] +then + echo "${_sub}" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${REGENCRTSCRIPT} +fi diff --git a/teeproxy/gpproxy/certs/check_server_key.sh b/teeproxy/gpproxy/certs/check_server_key.sh new file mode 100644 index 0000000000000000000000000000000000000000..9445f550610e4805e67f2801a9f26b7a9d087537 --- /dev/null +++ b/teeproxy/gpproxy/certs/check_server_key.sh @@ -0,0 +1,62 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the interity of key in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# KEYPEM=$HOME/.gpp/certs/server_key.pem +# PUBPEM=$HOME/.gpp/certs/server_pubkey.pem +# CRTPEM=$HOME/.gpp/certs/server_crt.pem +# MSGTXT=$HOME/.gpp/certs/msg.txt +# MSGSIG=$HOME/.gpp/certs/msg.sig +# GENKEYCRTSCRIPT=${HOME}/.gpp/certs/gen_server_keycrt.sh +CUR_DIR=$( dirname -- "$0"; ) +KEYPEM=$CUR_DIR/server_key.pem +PUBPEM=$CUR_DIR/server_pubkey.pem +CRTPEM=$CUR_DIR/server_crt.pem +MSGTXT=${CUR_DIR}/msg.txt +MSGSIG=${CUR_DIR}/msg.sig +GENKEYCRTSCRIPT=${CUR_DIR}/gen_server_keycrt.sh + +echo -e '\n'check integrity of ${KEYPEM}: +# ${_openssl} rsa -in ${KEYPEM} -passin pass:111111 -check -noout +# ${_openssl} rsa -in ${KEYPEM} -check -noout +${_openssl} rsa -in ${KEYPEM} -check -noout | grep -q 'RSA key ok' +if [ $? -ne 0 ] +then + echo "the integrity of "${KEYPEM}" is broken" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +else + echo -e "RSA key ok" +fi + +echo -e '\n'use private ${KEYPEM} to sign ${MSGTXT}: +# ${_openssl} dgst -sha256 -sign ${KEYPEM} -passin pass:111111 -out msg.sig msg.txt +${_openssl} dgst -sha256 -sign ${KEYPEM} -out ${MSGSIG} ${MSGTXT} + +echo -e '\n'get public key from ${CRTPEM}: +${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + +echo -e '\n'use public key in ${CRTPEM} to verify signature of ${MSGTXT}: +# ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} | grep -q 'Verified OK' +if [ $? -ne 0 ] +then + echo ${KEYPEM}" is not matched with "${CRTPEM} + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +fi +rm -f ${PUBPEM} diff --git a/teeproxy/gpproxy/certs/gen_ca_crt.sh b/teeproxy/gpproxy/certs/gen_ca_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..267cac5a329940d61ce1ba4c93285a91b690e85b --- /dev/null +++ b/teeproxy/gpproxy/certs/gen_ca_crt.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +_openssl="openssl" + +CUR_DIR=$( dirname -- "$0"; ) + + +# CAKEYPEM=$HOME/.gpp/certs/ca_key.pem +# CACRTPEM=$HOME/.gpp/certs/ca_crt.pem +CAKEYPEM=$CUR_DIR/ca_key.pem +CACRTPEM=$CUR_DIR/ca_crt.pem +RSAKEYLEN=2048 +EXPIREDAYS=3650 +SUBSTR="/C=CN/ST=Hubei/L=Wuhan/O=TrustCute/OU=gRPC/CN=ca.org" + +# echo -e '\n'generate $CAKEYPEM: +# $_openssl genrsa -passout pass:111111 -aes192 -out $CAKEYPEM ${RSAKEYLEN} +# $_openssl genrsa -aes192 -out $CAKEYPEM ${RSAKEYLEN} + +echo -e '\n'generate $CACRTPEM: +# $_openssl req -passin pass:111111 -new -x509 -days 3650 -key $CAKEYPEM -out $CACRTPEM -subj ${SUBSTR} +$_openssl req -new -x509 -days ${EXPIREDAYS} -key $CAKEYPEM -out $CACRTPEM -subj ${SUBSTR} diff --git a/teeproxy/gpproxy/certs/gen_ca_keycrt.sh b/teeproxy/gpproxy/certs/gen_ca_keycrt.sh new file mode 100644 index 0000000000000000000000000000000000000000..5110ba92c71f0a988737c6765675c096b8c5bbeb --- /dev/null +++ b/teeproxy/gpproxy/certs/gen_ca_keycrt.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +_openssl="openssl" + +CUR_DIR=$( dirname -- "$0"; ) + + +# CAKEYPEM=$HOME/.gpp/certs/ca_key.pem +# CACRTPEM=$HOME/.gpp/certs/ca_crt.pem +CAKEYPEM=$CUR_DIR/ca_key.pem +CACRTPEM=$CUR_DIR/ca_crt.pem +RSAKEYLEN=2048 +EXPIREDAYS=3650 +SUBSTR="/C=CN/ST=Hubei/L=Wuhan/O=TrustCute/OU=gRPC/CN=ca.org" + +echo -e '\n'generate $CAKEYPEM: +# $_openssl genrsa -passout pass:111111 -aes192 -out $CAKEYPEM ${RSAKEYLEN} +$_openssl genrsa -aes192 -out $CAKEYPEM ${RSAKEYLEN} + +echo -e '\n'generate $CACRTPEM: +# $_openssl req -passin pass:111111 -new -x509 -days 3650 -key $CAKEYPEM -out $CACRTPEM -subj ${SUBSTR} +$_openssl req -new -x509 -days ${EXPIREDAYS} -key $CAKEYPEM -out $CACRTPEM -subj ${SUBSTR} diff --git a/teeproxy/gpproxy/certs/gen_client_crt.sh b/teeproxy/gpproxy/certs/gen_client_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..8bfa94f92ba833f5ec22184224cc5dd77d6539b1 --- /dev/null +++ b/teeproxy/gpproxy/certs/gen_client_crt.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +_openssl="openssl" + +CUR_DIR=$( dirname -- "$0"; ) + + +# CAKEYPEM=$HOME/.gpp/certs/ca_key.pem +# CACRTPEM=$HOME/.gpp/certs/ca_crt.pem +# CSRPEM=$HOME/.gpp/certs/client_csr.pem +# CRTPEM=$HOME/.gpp/certs/client_crt.pem +CAKEYPEM=$CUR_DIR/ca_key.pem +CACRTPEM=$CUR_DIR/ca_crt.pem +CSRPEM=$CUR_DIR/client_csr.pem +CRTPEM=$CUR_DIR/client_crt.pem +RSAKEYLEN=2048 +EXPIREDAYS=3650 +SUBSTR="/C=CN/ST=Hubei/L=Wuhan/O=TrustCute/OU=gRPC/CN=gpclient.org" + +echo -e '\n'generate $CRTPEM: +# ${_openssl} x509 -req -passin pass:111111 -days ${EXPIREDAYS} -in $CSRPEM -CA $CACRTPEM -CAkey $CAKEYPEM -CAcreateserial -out $CRTPEM +${_openssl} x509 -req -days ${EXPIREDAYS} -in $CSRPEM -CA $CACRTPEM -CAkey $CAKEYPEM -CAcreateserial -out $CRTPEM diff --git a/teeproxy/gpproxy/certs/gen_client_keycsr.sh b/teeproxy/gpproxy/certs/gen_client_keycsr.sh new file mode 100644 index 0000000000000000000000000000000000000000..cbf8077e1a339c8afc240b47d21c707e032ded0e --- /dev/null +++ b/teeproxy/gpproxy/certs/gen_client_keycsr.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +_openssl="openssl" + +CUR_DIR=$( dirname -- "$0"; ) + + +# KEYPEM=$HOME/.teecc/certs/client_key.pem +# CSRPEM=$HOME/.teecc/certs/client_csr.pem +KEYPEM=$CUR_DIR/client_key.pem +CSRPEM=$CUR_DIR/client_csr.pem +RSAKEYLEN=2048 +SUBSTR="/C=CN/ST=Hubei/L=Wuhan/O=TrustCute/OU=gRPC/CN=gpclient.org" + +echo -e '\n'generate $KEYPEM: +# $_openssl genrsa -passout pass:111111 -aes192 -out $KEYPEM ${RSAKEYLEN} +$_openssl genrsa -aes192 -out $KEYPEM ${RSAKEYLEN} + +echo -e '\n'generate certgen request $CSRPEM: +# $_openssl req -passin pass:111111 -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} +$_openssl req -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} + diff --git a/teeproxy/gpproxy/certs/gen_server_crt.sh b/teeproxy/gpproxy/certs/gen_server_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..56399b04fe13ecabf5867b60794f93c3b1cc078a --- /dev/null +++ b/teeproxy/gpproxy/certs/gen_server_crt.sh @@ -0,0 +1,32 @@ +#! /bin/sh + +_openssl="openssl" + +CUR_DIR=$( dirname -- "$0"; ) + + +# CAKEYPEM=$HOME/.gpp/certs/ca_key.pem +# CACRTPEM=$HOME/.gpp/certs/ca_crt.pem +# KEYPEM=$HOME/.gpp/certs/server_key.pem +# CSRPEM=$HOME/.gpp/certs/server_csr.pem +# CRTPEM=$HOME/.gpp/certs/server_crt.pem +CAKEYPEM=$CUR_DIR/ca_key.pem +CACRTPEM=$CUR_DIR/ca_crt.pem +KEYPEM=$CUR_DIR/server_key.pem +CSRPEM=$CUR_DIR/server_csr.pem +CRTPEM=$CUR_DIR/server_crt.pem +RSAKEYLEN=2048 +EXPIREDAYS=3650 +SUBSTR="/C=CN/ST=Hubei/L=Wuhan/O=TrustCute/OU=gRPC/CN=gpserver.org" + +# echo -e '\n'generate $KEYPEM: +# $_openssl genrsa -passout pass:111111 -aes192 -out $KEYPEM ${RSAKEYLEN} +# $_openssl genrsa -aes192 -out $KEYPEM ${RSAKEYLEN} + +echo -e '\n'generate certgen request $CSRPEM: +# $_openssl req -passin pass:111111 -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} +$_openssl req -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} + +echo -e '\n'generate $CRTPEM: +# ${_openssl} x509 -req -passin pass:111111 -days ${EXPIREDAYS} -in $CSRPEM -CA $CACRTPEM -CAkey $CAKEYPEM -CAcreateserial -out $CRTPEM +${_openssl} x509 -req -days ${EXPIREDAYS} -in $CSRPEM -CA $CACRTPEM -CAkey $CAKEYPEM -CAcreateserial -out $CRTPEM diff --git a/teeproxy/gpproxy/certs/gen_server_keycrt.sh b/teeproxy/gpproxy/certs/gen_server_keycrt.sh new file mode 100644 index 0000000000000000000000000000000000000000..977c6fdd9b6801cb249c8697d7aea8d189075e6c --- /dev/null +++ b/teeproxy/gpproxy/certs/gen_server_keycrt.sh @@ -0,0 +1,32 @@ +#! /bin/sh + +_openssl="openssl" + +CUR_DIR=$( dirname -- "$0"; ) + + +# CAKEYPEM=$HOME/.gpp/certs/ca_key.pem +# CACRTPEM=$HOME/.gpp/certs/ca_crt.pem +# KEYPEM=$HOME/.gpp/certs/server_key.pem +# CSRPEM=$HOME/.gpp/certs/server_csr.pem +# CRTPEM=$HOME/.gpp/certs/server_crt.pem +CAKEYPEM=$CUR_DIR/ca_key.pem +CACRTPEM=$CUR_DIR/ca_crt.pem +KEYPEM=$CUR_DIR/server_key.pem +CSRPEM=$CUR_DIR/server_csr.pem +CRTPEM=$CUR_DIR/server_crt.pem +RSAKEYLEN=2048 +EXPIREDAYS=3650 +SUBSTR="/C=CN/ST=Hubei/L=Wuhan/O=TrustCute/OU=gRPC/CN=gpserver.org" + +echo -e '\n'generate $KEYPEM: +# $_openssl genrsa -passout pass:111111 -aes192 -out $KEYPEM ${RSAKEYLEN} +$_openssl genrsa -aes192 -out $KEYPEM ${RSAKEYLEN} + +echo -e '\n'generate certgen request $CSRPEM: +# $_openssl req -passin pass:111111 -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} +$_openssl req -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} + +echo -e '\n'generate $CRTPEM: +# ${_openssl} x509 -req -passin pass:111111 -days ${EXPIREDAYS} -in $CSRPEM -CA $CACRTPEM -CAkey $CAKEYPEM -CAcreateserial -out $CRTPEM +${_openssl} x509 -req -days ${EXPIREDAYS} -in $CSRPEM -CA $CACRTPEM -CAkey $CAKEYPEM -CAcreateserial -out $CRTPEM diff --git a/teeproxy/gpproxy/certs/msg.txt b/teeproxy/gpproxy/certs/msg.txt new file mode 100644 index 0000000000000000000000000000000000000000..93388adad70f215f4ec4a71af666d65b30a0cc87 --- /dev/null +++ b/teeproxy/gpproxy/certs/msg.txt @@ -0,0 +1 @@ +verify the integrity of a certificate and private key pair diff --git a/teeproxy/gpproxy/certs/server_crt.pem b/teeproxy/gpproxy/certs/server_crt.pem new file mode 100644 index 0000000000000000000000000000000000000000..7c4aef6076539837aa6adfc61d1adb11c04675bd --- /dev/null +++ b/teeproxy/gpproxy/certs/server_crt.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDTzCCAjcCFD3UsYh/aU1yUsNsej6x2MjHaxBNMA0GCSqGSIb3DQEBCwUAMGEx +CzAJBgNVBAYTAkNOMQ4wDAYDVQQIDAVIdWJlaTEOMAwGA1UEBwwFV3VoYW4xEjAQ +BgNVBAoMCVRydXN0Q3V0ZTENMAsGA1UECwwEZ1JQQzEPMA0GA1UEAwwGY2Eub3Jn +MB4XDTIyMDgyMDA1MDAwN1oXDTMyMDgxNzA1MDAwN1owZzELMAkGA1UEBhMCQ04x +DjAMBgNVBAgMBUh1YmVpMQ4wDAYDVQQHDAVXdWhhbjESMBAGA1UECgwJVHJ1c3RD +dXRlMQ0wCwYDVQQLDARnUlBDMRUwEwYDVQQDDAxncHNlcnZlci5vcmcwggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDGXHn+5sLRKB2RUG3PF+rzLbCVfrfW +2Lgq6PB11M0Qg7+yHCKuZJPZYo1M4DyAjVaF/h24IMr7Vg5j/MqVjwW2Q84DMkmI +WkaHgo+7bqfZ2fIOlrRiUo9ilALRDL2S/NJfRF2Z5e6lu4XvchjnRpC+Pu3YrxhB ++2LJ7F061OyKal5ylXfbb0+/TE4zM30nrJR8R4OvPeQvrmea//s5m1DLy6p5R6ZJ +YZH33xRo2zCYLmID6RwHChJHQX6f48e2u2nqXk20Q6wIrBh5jY2ATL3l6b/mqZ5K +U0IdzrPPGrtUz9hiT8H0tnjarnvIp6ffEqx9cBAulNocIAfBSAiOK2zfAgMBAAEw +DQYJKoZIhvcNAQELBQADggEBACS+qheuLHDKewqkyFBoDOy4T16b7ula9oRl0NsZ +Veh7jiu6BT5xcAbSUIAS5oxlhGb+CEzwMHT9r5D5ZBmSk6MWeG8my5SfWq7GKa6Y +DsjwNM2Wm0lM9brQZObr4BWorSYhHz6rfiSc5IfpiDPe7wluTJX0RuHUsp2rbjwO +EPdiEISQYu8ugMbMc8uyTV9L0/3X9Hy210FDIgZ+B9Z7udqsgZkQ/DjmWITXpgd5 +1T8O91v3lp9LuFKv2PvzlD6h3fSc5ITlRqlzY52ql3Xece7jfNCpDsuGEWO00//q +x3hM5EYI8qp0FCLvfxD16TBIq34yCXq3NmdinGc/1PGulLU= +-----END CERTIFICATE----- diff --git a/teeproxy/gpproxy/certs/server_key.pem b/teeproxy/gpproxy/certs/server_key.pem new file mode 100644 index 0000000000000000000000000000000000000000..be30821ed81dd6bf5f955b9ed765effb8dbc9f94 --- /dev/null +++ b/teeproxy/gpproxy/certs/server_key.pem @@ -0,0 +1,30 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-192-CBC,FE8794441B351ACA7569D5F49605C874 + +YYmoW3nUds/a4CumjFwyZEyXcT5qVXOX3nxpFKnAQRu0oA83CmyLPxxKksKfpmu5 +RbTFCS06XP+1jKpnP7Bx9gT31WdfMdwlb1xQaQJkxWBqAQZNPdUHoY2aiyqy7Mzt +j5P6wmFdVsauOnfvh+lcIDP6AjxGfsLtqTXe7JXtxyR+VVXlNcyRewwRfcy5eEUT +OnSfcsgY9lgHkUT2gbzttvmUfWWhCHU4U+IMpC1pGFZx5njJV/pkKXNzESvoYmeb +PrKu0PN9oKg8i0Iina3/G5/uiRgUl3+EfhpUm2XtTXimNeVJ/s4/9yB/ysFIrura +QqzFMVxyMESD+eoGrcelX1Ow0bj8JKMzGvcQNRIE9dHuZ8htyhd5QV3N7jKzEiAE +wDoQdvOHzhblepibm0pfndi6BTy7tSRYC3wINF2e8rmxoMSVT+jIfTnpRG4finj+ +0ZTFHoDCyitgqvEAztG9+b4gel3lK5Xm1CayyGkBoFLDhl3iWlUIfDkd2mEaUyjf +N/mjs/AXZKZCT9ApNm6X2hzVrNPZBbOgTPdeQfstVJjxj4heCGn/kn2wciEpmZPG +geXAh357+wGngs+kzAy0p/nso1Lp2fYUui3uh5o8Acbc0/D1b1ysWyxvlE3vtkJ3 +uXqz3hgJNFmLLOk1/K8akGnQd9Hc15pQrNoE6of5w9FvkO7r3pIMNOptJDlz/ogj +Jn2TP2UJGC6EwCSJM+lUxum6BKt6nz+4n8Sl8aPGiBpr4tQIrEodWRHsixd+Vy6u +yUffB0DfL41X28O7bGOIpdhcIQG25mE65/idMoTYAtrvExQymZjCCBsbzlBiQcwk +4bzA+Wv5tCWyJjwJKJBKSYFBVcNf3P9micB5YDyIcpDmgwqYZxo5KAj4K4Fmm7er +hYMA+Jzd3SYemH/lUSDSlK438bv9d7P7qIm27QC6TngKW9or4b2F/gDy7iYjXm5Q +Gk7C39xTlIUwSQR/WMVCG8MhkkamuDWTiaj9BEydO8VeIQf7jWEsY5ShGTr+VxtI +3SeUjkmD6whqRrKJBgdlIINuBUpB8dVzVufchhtR9GNPqCWdaMFquVK1JcgWISb6 +LuXAGPmumhFER4oK7xmITmlIRxjgXkld5Qcj9wzmmISO7ChxCWhXKNd/fabPRrO1 +gNO2C41/JbNoshF9qZfyR/0uVJZGLFy+/YsHh0Hk6s7o+g1SxpWYc2QG1fcvPvIS +vPI/I0+J8MUzL0BjdJf8lb/A2kCGRRn2P7AfGiUsbkGT3lnshudWQDe+sEdxJpm4 +OcrFpbyghiJuxYoE6LwDb2wgMbujsHDccL8eKpBvdlqcxU48dl3sF1C6rTjFgRPT +KI8KMcyWxVNfjYn1pMPPLkz3TEQd/mwu8g7yU2JAe3oH79pZE5Qdjji5uPRXSqF/ +c2FAFH10cyct5UISeMofFnECecx7XbxaurjiDQ0wCzcKZ1aO07XIyfLtWoQZHFOi +UlceygZQgISxsofxNLXfx4mur1yI6snOg/BH8dBKzmi7UvaffGv1o0U4JMAGavXT +DyZPod78wf3DImX/FQT1QVCVXH11igUUQl0RrHUc0y+dAKxxFxevSmedNP++wkNm +-----END RSA PRIVATE KEY----- diff --git a/teeproxy/gpproxy/changelog.md b/teeproxy/gpproxy/changelog.md new file mode 100644 index 0000000000000000000000000000000000000000..f66c4e154099ba0dd4245c0a51460aa71a4ad76e --- /dev/null +++ b/teeproxy/gpproxy/changelog.md @@ -0,0 +1,7 @@ +# 更新日志 + +## [1.0.0] - 2022-10-11 + +### 新增 + +* 项目初始化,上传第一版 diff --git a/teeproxy/gpproxy/common.cmake b/teeproxy/gpproxy/common.cmake new file mode 100644 index 0000000000000000000000000000000000000000..62099c51139eed8eed06510d9f76b71dfed36b3a --- /dev/null +++ b/teeproxy/gpproxy/common.cmake @@ -0,0 +1,129 @@ +# Copyright 2018 gRPC authors. +# +# Licensed 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. +# +# cmake build file for C++ route_guide example. +# Assumes protobuf and gRPC have been installed using cmake. +# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build +# that automatically builds all the dependencies before building route_guide. + +cmake_minimum_required(VERSION 3.5.1) + +# set (CMAKE_CXX_STANDARD 11) +set (CMAKE_CXX_STANDARD 14) + +set (GRPC_FETCHCONTENT 1) + + +if(MSVC) + add_definitions(-D_WIN32_WINNT=0x600) +endif() + +find_package(Threads REQUIRED) + +if(GRPC_AS_SUBMODULE) + # One way to build a projects that uses gRPC is to just include the + # entire gRPC project tree via "add_subdirectory". + # This approach is very simple to use, but the are some potential + # disadvantages: + # * it includes gRPC's CMakeLists.txt directly into your build script + # without and that can make gRPC's internal setting interfere with your + # own build. + # * depending on what's installed on your system, the contents of submodules + # in gRPC's third_party/* might need to be available (and there might be + # additional prerequisites required to build them). Consider using + # the gRPC_*_PROVIDER options to fine-tune the expected behavior. + # + # A more robust approach to add dependency on gRPC is using + # cmake's ExternalProject_Add (see cmake_externalproject/CMakeLists.txt). + + # Include the gRPC's cmake build (normally grpc source code would live + # in a git submodule called "third_party/grpc", but this example lives in + # the same repository as gRPC sources, so we just look a few directories up) + add_subdirectory(../../.. ${CMAKE_CURRENT_BINARY_DIR}/grpc EXCLUDE_FROM_ALL) + message(STATUS "Using gRPC via add_subdirectory.") + + # After using add_subdirectory, we can now use the grpc targets directly from + # this build. + set(_PROTOBUF_LIBPROTOBUF libprotobuf) + set(_REFLECTION grpc++_reflection) + if(CMAKE_CROSSCOMPILING) + find_program(_PROTOBUF_PROTOC protoc) + else() + set(_PROTOBUF_PROTOC $) + endif() + set(_GRPC_GRPCPP grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +elseif(GRPC_FETCHCONTENT) + # Another way is to use CMake's FetchContent module to clone gRPC at + # configure time. This makes gRPC's source code available to your project, + # similar to a git submodule. + message(STATUS "Using gRPC via add_subdirectory (FetchContent).") + include(FetchContent) + FetchContent_Declare( + grpc + GIT_REPOSITORY https://github.com/grpc/grpc.git + # when using gRPC, you will actually set this to an existing tag, such as + # v1.25.0, v1.26.0 etc.. + # For the purpose of testing, we override the tag used to the commit + # that's currently under test. + # GIT_TAG vGRPC_TAG_VERSION_OF_YOUR_CHOICE + GIT_TAG v1.48.0 + ) + FetchContent_MakeAvailable(grpc) + + # Since FetchContent uses add_subdirectory under the hood, we can use + # the grpc targets directly from this build. + set(_PROTOBUF_LIBPROTOBUF libprotobuf) + set(_REFLECTION grpc++_reflection) + set(_PROTOBUF_PROTOC $) + set(_GRPC_GRPCPP grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +else() + # This branch assumes that gRPC and all its dependencies are already installed + # on this system, so they can be located by find_package(). + + # Find Protobuf installation + # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation. + set(protobuf_MODULE_COMPATIBLE TRUE) + find_package(Protobuf CONFIG REQUIRED) + message(STATUS "Using protobuf ${Protobuf_VERSION}") + + set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) + set(_REFLECTION gRPC::grpc++_reflection) + if(CMAKE_CROSSCOMPILING) + find_program(_PROTOBUF_PROTOC protoc) + else() + set(_PROTOBUF_PROTOC $) + endif() + + # Find gRPC installation + # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. + find_package(gRPC CONFIG REQUIRED) + message(STATUS "Using gRPC ${gRPC_VERSION}") + + set(_GRPC_GRPCPP gRPC::grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +endif() diff --git a/teeproxy/gpproxy/conf/gpproxy_config.yaml b/teeproxy/gpproxy/conf/gpproxy_config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..978cc8487f2779c7bfcbf99dbe6a282b34a621ca --- /dev/null +++ b/teeproxy/gpproxy/conf/gpproxy_config.yaml @@ -0,0 +1,19 @@ +GPPROXY_ADDRESS: "[::]:50051" + +NAME_SERVER_KEY: "server_key.pem" +NAME_SERVER_CERT: "server_crt.pem" +NAME_CLIENTCA_CERT: "ca_crt.pem" + +# 0, no tls +# 1, only server certificate +# 2, server and client certificates +GRPC_TLS: 1 + +# 0, do not validate jwt +# 1, foreced to validate jwt +FORCE_VALIDATE_JWT: 1 + +MAX_NUM_THREAD: 128 +MAX_NUM_WORKER: 128 +TIMEDOUT_SESSION: 60 +TIMEDOUT_CONTEXT: 90 diff --git a/teeproxy/gpproxy/gpproxy.cc b/teeproxy/gpproxy/gpproxy.cc new file mode 100644 index 0000000000000000000000000000000000000000..b510d087bfd9ae0a5d8648f3ebae93bc497f0610 --- /dev/null +++ b/teeproxy/gpproxy/gpproxy.cc @@ -0,0 +1,4195 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gt.grpc.pb.h" +#include "gt.pb.h" + +#include "gpproxy.h" + +extern "C" { +#include "dbusc_gpw.h" +} + +#include "dbusc_jwt.h" +#include "yaml-cpp/yaml.h" + + +using grpc::Server; +using grpc::ServerBuilder; +using grpc::ServerContext; +using grpc::Status; +using grpc::ServerCompletionQueue; +using grpc::ServerAsyncResponseWriter; +using grpc::ServerAsyncReader; + +using grpc::experimental::AltsServerCredentials; +using grpc::experimental::AltsServerCredentialsOptions; + +using gt::gpp; +using gt::Inicont_Request; +using gt::Inicont_Reply; +using gt::Fincont_Request; +using gt::Fincont_Reply; +using gt::Opes_Reply; +using gt::Opes_Request; +using gt::Close_Reply; +using gt::Close_Request; +using gt::Invo_Reply; +using gt::Invo_Request; +using gt::TA_Chunk; +using gt::TA_Reply; +using gt::Setjwt_Request; +using gt::Setjwt_Reply; + + +#define NO_ERROR 0 + +std::string global_strcfgfiletemp = getenv("HOME"); +std::string global_strcfgfile = global_strcfgfiletemp + "/.gpp/gpproxy_config.yaml"; +YAML::Node glo_config = YAML::LoadFile(global_strcfgfile); +std::string gpproxy_address = glo_config["GPPROXY_ADDRESS"].as(); +std::string global_servercert_path = + global_strcfgfiletemp + "/.gpp/certs/" + glo_config["NAME_SERVER_CERT"].as(); +std::string global_serverkey_path = + global_strcfgfiletemp + "/.gpp/certs/" + glo_config["NAME_SERVER_KEY"].as(); +std::string global_clientcacert_path = + global_strcfgfiletemp + "/.gpp/certs/" + glo_config["NAME_CLIENTCA_CERT"].as(); +int grpc_tls = glo_config["GRPC_TLS"].as(); +int global_force_valideta_jwt = glo_config["FORCE_VALIDATE_JWT"].as(); + +int global_max_num_thread = glo_config["MAX_NUM_THREAD"].as(); +int global_max_num_worker = glo_config["MAX_NUM_WORKER"].as(); +int global_timeout_session = glo_config["TIMEDOUT_SESSION"].as(); +int global_timeout_context = glo_config["TIMEDOUT_CONTEXT"].as(); + + +static std::string get_file_contents(std::string fpath) +{ + std::ifstream finstream(fpath); + std::string contents; + contents.assign((std::istreambuf_iterator(finstream)), + std::istreambuf_iterator()); + finstream.close(); + return contents; +} + +bool utf8_check_is_valid(std::string &string) +{ + int c, i, ix, n, j; + for (i = 0, ix = string.length(); i < ix; i++) + { + c = (unsigned char) string[i]; + //if (c==0x09 || c==0x0a || c==0x0d || (0x20 <= c && c <= 0x7e) ) n = 0; // is_printable_ascii + if (0x00 <= c && c <= 0x7f) n = 0; // 0bbbbbbb + else if ((c & 0xE0) == 0xC0) n = 1; // 110bbbbb + else if (c == 0xed && i < (ix - 1) && ((unsigned char) string[i + 1] & 0xa0) == 0xa0) + return false; //U+d800 to U+dfff + else if ((c & 0xF0) == 0xE0) n = 2; // 1110bbbb + else if ((c & 0xF8) == 0xF0) n = 3; // 11110bbb + //else if (($c & 0xFC) == 0xF8) n=4; // 111110bb //byte 5, unnecessary in 4 byte UTF-8 + //else if (($c & 0xFE) == 0xFC) n=5; // 1111110b //byte 6, unnecessary in 4 byte UTF-8 + else return false; + for (j = 0; j < n && i < ix; j++) + { // n bytes matching 10bbbbbb follow ? + if ((++i == ix) || (((unsigned char) string[i] & 0xC0) != 0x80)) + return false; + } + } + return true; +} + + +#define MAX_DATA_LEN 50*1024 +#define SHA256_LENTH 32 + +int get_file_sha256(char *file_path, char *val) +{ + SHA256_CTX sha256_ctx; + FILE *fp = NULL; + char *strFilePath = file_path; + unsigned char SHA256result[SHA256_LENTH]; + char DataBuff[MAX_DATA_LEN]; + int len; + int t = 0; + int i; + std::string sha256; + + fp = fopen(strFilePath, "rb"); + + SHA256_Init(&sha256_ctx); + + while (!feof(fp)) + { + memset(DataBuff, 0x00, sizeof(DataBuff)); + + len = fread(DataBuff, 1, MAX_DATA_LEN, fp); + if (len) + { + t += len; + SHA256_Update(&sha256_ctx, DataBuff, len); + } + } + + fclose(fp); + SHA256_Final(SHA256result, &sha256_ctx); + + if (val == NULL || (sizeof(val) * 4) < SHA256_LENTH) + { + return -1; + } else + { + memset(val, 0, sizeof(val)); + memcpy(val, SHA256result, SHA256_LENTH); + } + + return 0; +} + +bool isFileExists_ifstream(std::string &name) +{ + std::ifstream f(name.c_str()); + return f.good(); +} + +void check_config() +{ + if (grpc_tls != 0 && grpc_tls != 1 && grpc_tls != 2) + { + std::cout << global_strcfgfile << " grpc_tls should be 0 or 1 or 2 " << std::endl; + exit(-1); + } + if (global_force_valideta_jwt != 0 && global_force_valideta_jwt != 1) + { + std::cout << global_strcfgfile << " global_force_valideta_jwt should be 0 or 1 " << std::endl; + exit(-1); + } + if (global_max_num_thread < 0 || global_max_num_thread > 128) + { + std::cout << global_strcfgfile << " global_max_num_thread should between 0 and 128 " << std::endl; + exit(-1); + } + if (global_max_num_worker < 0 || global_max_num_worker > 128) + { + std::cout << global_strcfgfile << " global_max_num_worker should between 0 and 128 " << std::endl; + exit(-1); + } + if (global_timeout_session <= 0) + { + std::cout << global_strcfgfile << " global_timeout_session should > 0 " << std::endl; + exit(-1); + } + if (global_timeout_context <= 0) + { + std::cout << global_strcfgfile << " global_timeout_context should > 0 " << std::endl; + exit(-1); + } + if (grpc_tls == 2) + { + if (!isFileExists_ifstream(global_servercert_path)) + { + std::cout << "error file : " << global_servercert_path << " is not exist " << std::endl; + exit(-1); + } + if (!isFileExists_ifstream(global_serverkey_path)) + { + std::cout << "error file : " << global_serverkey_path << " is not exist " << std::endl; + exit(-1); + } + if (!isFileExists_ifstream(global_clientcacert_path)) + { + std::cout << "error file : " << global_clientcacert_path << " is not exist " << std::endl; + exit(-1); + } + } + if (grpc_tls == 1) + { + if (!isFileExists_ifstream(global_servercert_path)) + { + std::cout << "error file : " << global_servercert_path << " is not exist " << std::endl; + exit(-1); + } + if (!isFileExists_ifstream(global_serverkey_path)) + { + std::cout << "error file : " << global_serverkey_path << " is not exist " << std::endl; + exit(-1); + } + } +} + +class ServerImpl final +{ +public: + ~ServerImpl() + { + server_->Shutdown(); + for (auto &cq: cq_) + cq->Shutdown(); + delete[] workerrec; + } + + ServerImpl() + { + pthread_mutex_init(&mutex_workerrec, NULL); + pthread_cond_init(&cond_notbusy, NULL); + for (int iworker = 0; iworker < global_max_num_worker; iworker++) + { + workerrec[iworker].busy = 0; + workerrec[iworker].context_fd = 0; + workerrec[iworker].context_addr = 0xffffffff; + workerrec[iworker].sessionid_count = 0; + workerrec[iworker].first = NULL; + workerrec[iworker].last = NULL; + } + } + + class CallData + { + + public: + + enum ServiceType + { + SS_TEECC_InitializeContext = 0, + SS_TEECC_FinalizeContext = 1, + SS_TEECC_OpenSession = 2, + SS_TEECC_CloseSession = 3, + SS_TEECC_InvokeCommand = 4, + SS_TEECC_TA = 5, + SS_TEECC_SetJwt = 6 + }; + + ~CallData() + { + + } + + CallData(gpp::AsyncService *service, + ServerCompletionQueue *cq, + ServiceType s_type, + pthread_mutex_t *mutex_workerrec, + pthread_cond_t *cond_notbusy, + wr_t *workerrec) + : service_(service), + cq_(cq), + s_type_(s_type), + mutex_workerrec_(mutex_workerrec), + cond_notbusy_(cond_notbusy), + workerrec_(workerrec), + inicont_response(&ctx_), + fincont_response(&ctx_), + opes_response(&ctx_), + close_response(&ctx_), + invo_response(&ctx_), + ta_response(&ctx_), + setjwt_response(&ctx_), + status_(CREATE) + { + Process(); + } + + void Process() + { + if (status_ == CREATE) + { + status_ = PROCESS; + switch (s_type_) + { + case ServerImpl::CallData::SS_TEECC_InitializeContext: + service_->RequestTEECC_InitializeContext(&ctx_, &inicont_request, &inicont_response, cq_, cq_, + this); + break; + case ServerImpl::CallData::SS_TEECC_FinalizeContext: + service_->RequestTEECC_FinalizeContext(&ctx_, &fincont_request, &fincont_response, cq_, cq_, this); + break; + case ServerImpl::CallData::SS_TEECC_OpenSession: + service_->RequestTEECC_OpenSession(&ctx_, &opes_request, &opes_response, cq_, cq_, this); + break; + case ServerImpl::CallData::SS_TEECC_InvokeCommand: + service_->RequestTEECC_InvokeCommand(&ctx_, &invo_request, &invo_response, cq_, cq_, this); + break; + case ServerImpl::CallData::SS_TEECC_CloseSession: + service_->RequestTEECC_CloseSession(&ctx_, &close_request, &close_response, cq_, cq_, this); + break; + case ServerImpl::CallData::SS_TEECC_TA: + service_->RequestTEECC_TA(&ctx_, &ta_chunk, &ta_response, cq_, cq_, this); + break; + case ServerImpl::CallData::SS_TEECC_SetJwt: + service_->RequestTEECC_SetJwt(&ctx_, &setjwt_request, &setjwt_response, cq_, cq_, this); + break; + default: + break; + } + + } else if (status_ == PROCESS) + { + status_ = FINISH; + new CallData(service_, cq_, this->s_type_, mutex_workerrec_, cond_notbusy_, workerrec_); + + switch (s_type_) + { + case ServerImpl::CallData::SS_TEECC_InitializeContext: + { + struct timeval start, end, jwt_validate_start, jwt_validate_end; + gettimeofday(&start, NULL); + + std::string name; + const uint8_t *name_temp = reinterpret_cast(name.c_str()); + std::size_t name_size; + std::int32_t in_context_fd; + std::string in_context_tapath; + const uint8_t *in_context_tapath_temp = NULL; + std::int32_t in_context_tapath_size; + unsigned char *charp = NULL; + std::string charpp; + std::uint64_t in_context_sessionlist_next; + std::uint64_t in_context_sessionlist_prev; + std::uint64_t in_context_shrdmemlist_next; + std::uint64_t in_context_shrdmemlist_prev; + std::uint64_t in_context_sharebuffer_buffer; + std::int64_t in_context_sharebuffer_bufferbarrier; + + std::uint32_t teecresult; + std::int32_t fd; + + unsigned char *ta_path = NULL; + std::int32_t ta_path_size = 0; + + std::uint64_t session_list_next; + std::uint64_t session_list_prev; + std::uint64_t shrd_mem_list_next; + std::uint64_t shrd_mem_list_prev; + std::uint64_t share_buffer_buffer; + std::int64_t share_buffer_buffer_barrier; + std::uint64_t context_addr; + + in_context_fd = 0; + in_context_tapath_size = 0; + in_context_sessionlist_next = 0; + in_context_sessionlist_prev = 0; + in_context_shrdmemlist_next = 0; + in_context_shrdmemlist_prev = 0; + in_context_sharebuffer_buffer = 0; + in_context_sharebuffer_bufferbarrier = 0; + + name_size = inicont_request.name_size(); + if (name_size > 0) + { + name = inicont_request.name(); + std::cout << "gpp received name: " << name << std::endl; + } + + std::uint32_t serial = 0; + std::int32_t flag = 0; + + std::string token; + token = inicont_request.token(); + + std::string noToken("noToken"); + int ivaljwtResult = -1; + int iforceValidateJwt = global_force_valideta_jwt; + + if + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + ) + { + char Token[1024]; + strcpy(Token, (char *) token.data()); + + gettimeofday(&jwt_validate_start, NULL); + ivaljwtResult = + dbusmethodcall_validate_jwt( + Token + ); + gettimeofday(&jwt_validate_end, NULL); + int64_t i64Time_jwt; + i64Time_jwt = (jwt_validate_end.tv_sec - jwt_validate_start.tv_sec) * 1000000 + + (jwt_validate_end.tv_usec - jwt_validate_start.tv_usec); + printf("gpp initcont validate jwt used time: %ld us. \n", i64Time_jwt); + + std::cout << "gpp validate initcont jwtsvid" << std::endl; + } else + { + std::cout << "gpp no validate initcont jwtsvid" << std::endl; + } + + if + ( + iforceValidateJwt != 1 + || + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + && + ivaljwtResult == NO_ERROR + ) + ) + { + std::cout << "gpp does not need validate initcont jwtsvid or validate jwt succed" << std::endl; + std::cout << "gpp received init context" << std::endl; + std::cout << "gpp received namesize: " << name_size << std::endl; + + ta_path = (unsigned char *) malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *) ta_path, 0, 1024); + uint32_t context_tapath_outsize; + + char workername[1024]; + memset((char *) workername, 0, 1024); + int ifound = 0; + int iworker; + + for (;;) + { + pthread_mutex_lock(mutex_workerrec_); + for (iworker = 0; iworker < global_max_num_worker; iworker++) + { + if (workerrec_[iworker].busy == 0) + { + sprintf(workername, "%s%d", "gpworker", iworker); + std::cout << "gpp method call worker No: " << std::dec << iworker << std::endl; + workerrec_[iworker].busy = 1; + ifound = 1; + break; + } + } + if (ifound == 0) + { + pthread_cond_wait(cond_notbusy_, mutex_workerrec_); + } + pthread_mutex_unlock(mutex_workerrec_); + + if (ifound == 1) + { + break; + } + } + + method_call_teec_inicont( + workername, + + name_temp, + name_size, + in_context_fd, + in_context_tapath_temp, + in_context_tapath_size, + in_context_sessionlist_next, + in_context_sessionlist_prev, + in_context_shrdmemlist_next, + in_context_shrdmemlist_prev, + in_context_sharebuffer_buffer, + in_context_sharebuffer_bufferbarrier, + + &teecresult, + + &fd, + ta_path, + ta_path_size, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + &context_addr, + &context_tapath_outsize + ); + + if (teecresult == 0) + { + pthread_mutex_lock(mutex_workerrec_); + workerrec_[iworker].context_fd = fd; + workerrec_[iworker].context_addr = context_addr; + workerrec_[iworker].first = NULL; + workerrec_[iworker].last = NULL; + workerrec_[iworker].sessionid_count = 0; + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + workerrec_[iworker].context_createtime = tvcreate; + pthread_mutex_unlock(mutex_workerrec_); + } else + { + workerrec_[iworker].busy = 0; + } + + if (ta_path_size >= context_tapath_outsize) + { + ta_path_size = context_tapath_outsize; + charp = ta_path; + } else + { + ta_path_size = 0; + charp = NULL; + } + inicont_reply.set_teecresult(teecresult); + inicont_reply.set_context_fd(fd); + inicont_reply.set_context_tapath_outsize(ta_path_size); + + if (ta_path_size > 0 && + charp != NULL && + strlen((const char *) charp) > 0 + ) + { + charpp = (const char *) charp; + if (utf8_check_is_valid(charpp)) + { + ta_path_size = strlen((const char *) charp); + } else + { + ta_path_size = 0; + } + } else + { + ta_path_size = 0; + } + if (ta_path_size > 0) + { + inicont_reply.set_context_tapath(charpp); + } + + inicont_reply.set_context_sessionlist_next(session_list_next); + inicont_reply.set_context_sessionlist_prev(session_list_prev); + inicont_reply.set_context_shrdmemlist_prev(shrd_mem_list_prev); + inicont_reply.set_context_shrdmemlist_next(shrd_mem_list_next); + inicont_reply.set_context_sharebuffer_buffer(share_buffer_buffer); + inicont_reply.set_context_sharebuffer_bufferbarrier(share_buffer_buffer_barrier); + inicont_reply.set_context_addr(context_addr); + + status_ = FINISH; + gettimeofday(&end, NULL); + int64_t i64Time; + i64Time = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + printf("gpp initcont used time: %ld us. \n", i64Time); + + inicont_response.Finish(inicont_reply, Status::OK, this); + } else + { + std::cout << "gpp receive no initcont jwtsvid or validate jwt failed" << std::endl; + flag = 2; + inicont_reply.set_flag(flag); + status_ = FINISH; + + inicont_response.Finish(inicont_reply, Status::OK, this); + } + break; + } + + case ServerImpl::CallData::SS_TEECC_FinalizeContext: + { + struct timeval start, end, jwt_validate_start, jwt_validate_end; + gettimeofday(&start, NULL); + + std::int32_t in_context_fd; + std::string in_context_tapath; + const uint8_t *in_context_tapath_temp = NULL; + std::int32_t in_context_tapath_size; + unsigned char *charp = NULL; + std::string charpp; + std::uint64_t in_context_sessionlist_next; + std::uint64_t in_context_sessionlist_prev; + std::uint64_t in_context_shrdmemlist_next; + std::uint64_t in_context_shrdmemlist_prev; + std::uint64_t in_context_sharebuffer_buffer; + std::int64_t in_context_sharebuffer_bufferbarrier; + std::uint64_t in_context_addr; + + std::uint32_t teecresult; + std::int32_t fd; + + unsigned char *ta_path = NULL; + std::int32_t ta_path_size = 0; + + std::uint64_t session_list_next; + std::uint64_t session_list_prev; + std::uint64_t shrd_mem_list_next; + std::uint64_t shrd_mem_list_prev; + std::uint64_t share_buffer_buffer; + std::int64_t share_buffer_buffer_barrier; + + std::uint32_t serial = 0; + std::int32_t flag = 0; + std::string token; + token = fincont_request.token(); + std::string noToken("noToken"); + int ivaljwtResult = -1; + int iforceValidateJwt = global_force_valideta_jwt; + if + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + ) + { + char Token[1024]; + strcpy(Token, (char *) token.data()); + + gettimeofday(&jwt_validate_start, NULL); + ivaljwtResult = + dbusmethodcall_validate_jwt( + Token + ); + gettimeofday(&jwt_validate_end, NULL); + int64_t i64Time_jwt; + i64Time_jwt = (jwt_validate_end.tv_sec - jwt_validate_start.tv_sec) * 1000000 + + (jwt_validate_end.tv_usec - jwt_validate_start.tv_usec); + printf("gpp finacont validate jwt used time: %ld us. \n", i64Time_jwt); + + std::cout << "gpp validate finacont jwtsvid" << std::endl; + } else + { + std::cout << "gpp no validate finacont jwtsvid" << std::endl; + } + + if + ( + iforceValidateJwt != 1 + || + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + && + ivaljwtResult == NO_ERROR + ) + ) + { + std::cout << "gpp does not need validate finacont jwtsvid or validate jwt succed" << std::endl; + std::cout << "gpp received fincontext" << std::endl; + in_context_fd = fincont_request.in_context_fd(); + in_context_tapath_size = fincont_request.in_context_tapath_size(); + if (in_context_tapath_size > 0) + { + in_context_tapath = fincont_request.in_context_tapath(); + in_context_tapath_temp = reinterpret_cast(in_context_tapath.c_str()); + std::cout << "gpp received in_context_tapath_temp: " << in_context_tapath_temp + << std::endl; + } + + std::cout << "gpp received in_context_fd: " << in_context_fd << std::endl; + in_context_sessionlist_next = fincont_request.in_context_sessionlist_next(); + in_context_sessionlist_prev = fincont_request.in_context_sessionlist_prev(); + in_context_shrdmemlist_next = fincont_request.in_context_shrdmemlist_next(); + in_context_shrdmemlist_prev = fincont_request.in_context_shrdmemlist_prev(); + in_context_sharebuffer_buffer = fincont_request.in_context_shrdmemlist_prev(); + in_context_sharebuffer_bufferbarrier = fincont_request.in_context_sharebuffer_bufferbarrier(); + in_context_addr = fincont_request.in_context_addr(); + + + ta_path = (unsigned char *) malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *) ta_path, 0, 1024); + uint32_t context_tapath_outsize; + + char workername[1024]; + memset((char *) workername, 0, 1024); + int ifound = 0; + int iworker; + pthread_mutex_lock(mutex_workerrec_); + for (iworker = 0; iworker < global_max_num_worker; iworker++) + { + if (workerrec_[iworker].context_fd == in_context_fd && + workerrec_[iworker].context_addr == in_context_addr + ) + { + sprintf(workername, "%s%d", "gpworker", iworker); + std::cout << "gpp method call worker No: " << std::dec << iworker << std::endl; + ifound = 1; + break; + } + } + pthread_mutex_unlock(mutex_workerrec_); + + if (ifound == 0) + { + printf("gpp can't find the worker for the context. \n"); + + fd = 0; + ta_path_size = 0; + charp = NULL; + session_list_prev = 0; + shrd_mem_list_next = 0; + shrd_mem_list_prev = 0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0; + + fincont_reply.set_context_fd(fd); + fincont_reply.set_context_tapath_outsize(ta_path_size); + fincont_reply.set_context_sessionlist_prev(session_list_prev); + fincont_reply.set_context_shrdmemlist_prev(shrd_mem_list_prev); + fincont_reply.set_context_shrdmemlist_next(shrd_mem_list_next); + fincont_reply.set_context_sharebuffer_buffer(share_buffer_buffer); + fincont_reply.set_context_sharebuffer_bufferbarrier(share_buffer_buffer_barrier); + + status_ = FINISH; + + fincont_response.Finish(fincont_reply, Status::OK, this); + } else + { + pthread_mutex_unlock(mutex_workerrec_); + sin_t *sinIns = NULL; + sin_t *sinInsPrev = NULL; + sinIns = workerrec_[iworker].last; + if (sinIns != NULL) + { + uint32_t in_session_seesionid; + uint32_t in_session_serviceid_timelow = 0; + uint32_t in_session_serviceid_timemid = 0; + uint32_t in_session_serviceid_timehiandver = 0; + uint32_t in_session_serviceid_clockseqandnode_size = 8; + uint32_t in_session_serviceid_clockseqandnode[8]; + uint32_t in_session_opscnt = 0; + uint64_t in_session_head_next = 0; + uint64_t in_session_head_prev = 0; + uint64_t in_session_context; + + uint32_t seesionid; + uint32_t serviceid_timelow; + uint32_t serviceid_timemid; + uint32_t serviceid_timehiandver; + uint32_t *serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + uint32_t opscnt; + uint64_t head_next; + uint64_t head_prev; + uint64_t session_context; + + for (;;) + { + in_session_seesionid = sinIns->session_id; + in_session_context = workerrec_[iworker].context_addr; + + pthread_mutex_unlock(mutex_workerrec_); + + for (int iind = 0; iind < 8; iind++) + { + in_session_serviceid_clockseqandnode[iind] = 0; + } + + uint32_t serviceid_clockseqandnode_outsize_temp; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + + printf("\ngpp self method call teec closesession before finalizecontext \n"); + method_call_teec_closesession( + workername, + + in_session_seesionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + &seesionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &session_context + ); + + if (serviceid_clockseqandnode != NULL) + { + free(serviceid_clockseqandnode); + } + + pthread_mutex_lock(mutex_workerrec_); + + sinInsPrev = sinIns->prev; + free(sinIns); + if (sinInsPrev == NULL) + { + break; + } + sinIns = sinInsPrev; + } + } + pthread_mutex_unlock(mutex_workerrec_); + + method_call_teec_fincont( + workername, + + in_context_fd, + in_context_tapath_temp, + in_context_tapath_size, + in_context_sessionlist_next, + in_context_sessionlist_prev, + in_context_shrdmemlist_next, + in_context_shrdmemlist_prev, + in_context_sharebuffer_buffer, + in_context_sharebuffer_bufferbarrier, + in_context_addr, + + &fd, + ta_path, + ta_path_size, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + &context_tapath_outsize + ); + + pthread_mutex_lock(mutex_workerrec_); + workerrec_[iworker].busy = 0; + pthread_cond_signal(cond_notbusy_); + workerrec_[iworker].context_fd = 0; + workerrec_[iworker].context_addr = 0xffffffff; + workerrec_[iworker].sessionid_count = 0; + workerrec_[iworker].first = NULL; + workerrec_[iworker].last = NULL; + pthread_mutex_unlock(mutex_workerrec_); + + if (ta_path_size >= context_tapath_outsize) + { + ta_path_size = context_tapath_outsize; + charp = ta_path; + } else + { + ta_path_size = 0; + charp = NULL; + } + fincont_reply.set_context_fd(fd); + fincont_reply.set_context_tapath_outsize(ta_path_size); + + if (ta_path_size > 0 && + charp != NULL && + strlen((const char *) charp) > 0 + ) + { + charpp = (const char *) charp; + if (utf8_check_is_valid(charpp)) + { + ta_path_size = strlen((const char *) charp); + } else + { + ta_path_size = 0; + } + } else + { + ta_path_size = 0; + } + if (ta_path_size > 0) + { + fincont_reply.set_context_tapath(charpp); + } + + fincont_reply.set_context_sessionlist_next(session_list_next); + fincont_reply.set_context_sessionlist_prev(session_list_prev); + fincont_reply.set_context_shrdmemlist_prev(shrd_mem_list_prev); + fincont_reply.set_context_shrdmemlist_next(shrd_mem_list_next); + fincont_reply.set_context_sharebuffer_buffer(share_buffer_buffer); + fincont_reply.set_context_sharebuffer_bufferbarrier(share_buffer_buffer_barrier); + + status_ = FINISH; + gettimeofday(&end, NULL); + int64_t i64Time; + i64Time = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + printf("gpp finalcontext used time: %ld us. \n", i64Time); + + fincont_response.Finish(fincont_reply, Status::OK, this); + } + }else + { + std::cout << "gpp receive no finacont jwtsvid or validate jwt failed" << std::endl; + flag = 2; + fincont_reply.set_flag(flag); + status_ = FINISH; + fincont_response.Finish(fincont_reply, Status::OK, this); + } + break; + } + + case ServerImpl::CallData::SS_TEECC_OpenSession: + { + struct timeval start, end, jwt_validate_start, jwt_validate_end; + gettimeofday(&start, NULL); + + std::int32_t in_context_fd; + std::string in_context_tapath; + const uint8_t *in_context_tapath_temp = NULL; + std::int32_t in_context_tapath_size; + unsigned char *charp = NULL; + std::string charpp; + std::uint64_t in_context_sessionlist_next; + std::uint64_t in_context_sessionlist_prev; + std::uint64_t in_context_shrdmemlist_next; + std::uint64_t in_context_shrdmemlist_prev; + std::uint64_t in_context_sharebuffer_buffer; + std::int64_t in_context_sharebuffer_bufferbarrier; + + std::uint32_t teecresult; + std::int32_t fd; + + std::uint32_t in_destination_timelow; + std::uint32_t in_destination_timemid; + std::uint32_t in_destination_timehiandver; + + std::uint32_t in_connectionmethod; + std::uint64_t in_connectiondata; + std::uint32_t in_operation_started; + std::uint32_t in_operation_paramtypes; + std::int32_t in_destination_clockseqandnode_size; + std::uint32_t *in_destination_clockseqandnode; + + std::uint64_t in_operation_param1_tmpref_buffer; + std::uint32_t in_operation_param1_tmpref_size; + std::uint64_t in_operation_param1_memref_parent; + std::uint32_t in_operation_param1_memref_size; + std::uint32_t in_operation_param1_memref_offset; + std::uint32_t in_operation_param1_value_a; + std::uint32_t in_operation_param1_value_b; + std::int32_t in_operation_param1_ionref_ionsharefd; + std::uint32_t in_operation_param1_ionref_ionsize; + + std::uint64_t in_operation_param2_tmpref_buffer; + std::uint32_t in_operation_param2_tmpref_size; + std::uint64_t in_operation_param2_memref_parent; + std::uint32_t in_operation_param2_memref_size; + std::uint32_t in_operation_param2_memref_offset; + std::uint32_t in_operation_param2_value_a; + std::uint32_t in_operation_param2_value_b; + std::int32_t in_operation_param2_ionref_ionsharefd; + std::uint32_t in_operation_param2_ionref_ionsize; + + std::uint64_t in_operation_param3_tmpref_buffer; + std::uint32_t in_operation_param3_tmpref_size; + std::uint64_t in_operation_param3_memref_parent; + std::uint32_t in_operation_param3_memref_size; + std::uint32_t in_operation_param3_memref_offset; + std::uint32_t in_operation_param3_value_a; + std::uint32_t in_operation_param3_value_b; + std::int32_t in_operation_param3_ionref_ionsharefd; + std::uint32_t in_operation_param3_ionref_ionsize; + + std::uint64_t in_operation_param4_tmpref_buffer; + std::uint32_t in_operation_param4_tmpref_size; + std::uint64_t in_operation_param4_memref_parent; + std::uint32_t in_operation_param4_memref_size; + std::uint32_t in_operation_param4_memref_offset; + std::uint32_t in_operation_param4_value_a; + std::uint32_t in_operation_param4_value_b; + std::int32_t in_operation_param4_ionref_ionsharefd; + std::uint32_t in_operation_param4_ionref_ionsize; + + std::uint64_t in_operation_session; + std::int32_t in_operation_cancelflag; + std::uint32_t in_returnorigin; + + std::uint64_t in_context_addr; + + unsigned char *ta_path = NULL; + std::int32_t ta_path_size = 0; + + std::uint64_t session_list_next; + std::uint64_t session_list_prev; + std::uint64_t shrd_mem_list_next; + std::uint64_t shrd_mem_list_prev; + std::uint64_t share_buffer_buffer; + std::int64_t share_buffer_buffer_barrier; + + std::uint32_t sessionid; + std::uint32_t serviceid_timelow; + std::uint32_t serviceid_timemid; + std::uint32_t serviceid_timehiandver; + std::uint32_t *serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + std::int32_t serviceid_clockseqandnode_outsize; + std::uint32_t opscnt; + std::uint64_t head_next; + std::uint64_t head_prev; + std::uint64_t session_context; + std::uint32_t started; + std::uint32_t paramtypes; + std::uint64_t operation_param1_tmpref_buffer; + std::uint32_t operation_param1_tmpref_size; + std::uint64_t operation_param1_memref_parent; + std::uint32_t operation_param1_memref_size; + std::uint32_t operation_param1_memref_offset; + std::uint32_t operation_param1_value_a; + std::uint32_t operation_param1_value_b; + std::int32_t operation_param1_ionref_ionsharefd; + std::uint32_t operation_param1_ionref_ionsize; + std::uint64_t operation_param2_tmpref_buffer; + std::uint32_t operation_param2_tmpref_size; + std::uint64_t operation_param2_memref_parent; + std::uint32_t operation_param2_memref_size; + std::uint32_t operation_param2_memref_offset; + std::uint32_t operation_param2_value_a; + std::uint32_t operation_param2_value_b; + std::int32_t operation_param2_ionref_ionsharefd; + std::uint32_t operation_param2_ionref_ionsize; + std::uint64_t operation_param3_tmpref_buffer; + std::uint32_t operation_param3_tmpref_size; + std::uint64_t operation_param3_memref_parent; + std::uint32_t operation_param3_memref_size; + std::uint32_t operation_param3_memref_offset; + std::uint32_t operation_param3_value_a; + std::uint32_t operation_param3_value_b; + std::int32_t operation_param3_ionref_ionsharefd; + std::uint32_t operation_param3_ionref_ionsize; + std::uint64_t operation_param4_tmpref_buffer; + std::uint32_t operation_param4_tmpref_size; + std::uint64_t operation_param4_memref_parent; + std::uint32_t operation_param4_memref_size; + std::uint32_t operation_param4_memref_offset; + std::uint32_t operation_param4_value_a; + std::uint32_t operation_param4_value_b; + std::int32_t operation_param4_ionref_ionsharefd; + std::uint32_t operation_param4_ionref_ionsize; + std::uint64_t operation_session; + std::int32_t operation_cancelflag; + std::uint32_t returnorigin; + + std::uint32_t serial = 0; + std::int32_t flag = 0; + std::string token; + token = opes_request.token(); + + std::string noToken("noToken"); + + int ivaljwtResult = -1; + int iforceValidateJwt = global_force_valideta_jwt; + + if + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + ) + { + char Token[1024]; + strcpy(Token, (char *) token.data()); + gettimeofday(&jwt_validate_start, NULL); + ivaljwtResult = + dbusmethodcall_validate_jwt( + Token + ); + gettimeofday(&jwt_validate_end, NULL); + int64_t i64Time_jwt; + i64Time_jwt = (jwt_validate_end.tv_sec - jwt_validate_start.tv_sec) * 1000000 + + (jwt_validate_end.tv_usec - jwt_validate_start.tv_usec); + printf("gpp opensession validate jwt used time: %ld us. \n", i64Time_jwt); + std::cout << "gpp validate opensession jwtsvid" << std::endl; + } else + { + std::cout << "gpp no validate opensession jwtsvid" << std::endl; + } + + if + ( + iforceValidateJwt != 1 + || + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + && + ivaljwtResult == NO_ERROR + ) + ) + { + std::cout << "gpp does not need validate opensession jwtsvid or validate jwt succed" + << std::endl; + std::cout << "gpp received OpenSession" << std::endl; + in_context_fd = opes_request.in_context_fd(); + in_context_tapath_size = opes_request.in_context_tapath_size(); + if (in_context_tapath_size > 0) + { + in_context_tapath = opes_request.in_context_tapath(); + in_context_tapath_temp = reinterpret_cast(in_context_tapath.c_str()); + std::cout << "gpp received in_context_tapath_temp: " << in_context_tapath_temp + << std::endl; + } + std::cout << "gpp received in_context_fd: " << std::dec << in_context_fd + << std::endl; + std::cout << "gpp received in_context_tapath_size: " << std::dec + << in_context_tapath_size + << std::endl; + in_context_sessionlist_next = opes_request.in_context_sessionlist_next(); + in_context_sessionlist_prev = opes_request.in_context_sessionlist_prev(); + in_context_shrdmemlist_next = opes_request.in_context_shrdmemlist_next(); + in_context_shrdmemlist_prev = opes_request.in_context_shrdmemlist_prev(); + in_context_sharebuffer_buffer = opes_request.in_context_shrdmemlist_prev(); + in_context_sharebuffer_bufferbarrier = opes_request.in_context_sharebuffer_bufferbarrier(); + in_destination_timelow = opes_request.in_destination_timelow(); + in_destination_timemid = opes_request.in_destination_timemid(); + + in_destination_timehiandver = opes_request.in_destination_timehiandver(); + in_destination_clockseqandnode_size = opes_request.in_destination_clockseqandnode_size(); + if (in_destination_clockseqandnode_size > 0) + { + in_destination_clockseqandnode = new uint32_t[in_destination_clockseqandnode_size]; + for (int i = 0; i < in_destination_clockseqandnode_size; i++) + { + in_destination_clockseqandnode[i] = opes_request.in_destination_clockseqandnode( + i); + } + } + + in_connectionmethod = opes_request.in_connectionmethod(); + in_connectiondata = opes_request.in_connectiondata(); + in_operation_started = opes_request.in_operation_started(); + in_operation_paramtypes = opes_request.in_operation_paramtypes(); + in_operation_param1_tmpref_buffer = opes_request.in_operation_param1_tmpref_buffer(); + in_operation_param1_tmpref_size = opes_request.in_operation_param1_tmpref_size(); + in_operation_param1_memref_parent = opes_request.in_operation_param1_memref_parent(); + in_operation_param1_memref_size = opes_request.in_operation_param1_memref_size(); + in_operation_param1_memref_offset = opes_request.in_operation_param1_memref_offset(); + in_operation_param1_value_a = opes_request.in_operation_param1_value_a(); + in_operation_param1_value_b = opes_request.in_operation_param1_value_b(); + in_operation_param1_ionref_ionsharefd = opes_request.in_operation_param1_ionref_ionsharefd(); + in_operation_param1_ionref_ionsize = opes_request.in_operation_param1_ionref_ionsize(); + + in_operation_param2_tmpref_buffer = opes_request.in_operation_param2_tmpref_buffer(); + in_operation_param2_tmpref_size = opes_request.in_operation_param2_tmpref_size(); + in_operation_param2_memref_parent = opes_request.in_operation_param2_memref_parent(); + in_operation_param2_memref_size = opes_request.in_operation_param2_memref_size(); + in_operation_param2_memref_offset = opes_request.in_operation_param2_memref_offset(); + in_operation_param2_value_a = opes_request.in_operation_param2_value_a(); + in_operation_param2_value_b = opes_request.in_operation_param2_value_b(); + in_operation_param2_ionref_ionsharefd = opes_request.in_operation_param2_ionref_ionsharefd(); + in_operation_param2_ionref_ionsize = opes_request.in_operation_param2_ionref_ionsize(); + + in_operation_param3_tmpref_buffer = opes_request.in_operation_param3_tmpref_buffer(); + in_operation_param3_tmpref_size = opes_request.in_operation_param3_tmpref_size(); + in_operation_param3_memref_parent = opes_request.in_operation_param3_memref_parent(); + in_operation_param3_memref_size = opes_request.in_operation_param3_memref_size(); + in_operation_param3_memref_offset = opes_request.in_operation_param3_memref_offset(); + in_operation_param3_value_a = opes_request.in_operation_param3_value_a(); + in_operation_param3_value_b = opes_request.in_operation_param3_value_b(); + in_operation_param3_ionref_ionsharefd = opes_request.in_operation_param3_ionref_ionsharefd(); + in_operation_param3_ionref_ionsize = opes_request.in_operation_param3_ionref_ionsize(); + + in_operation_param4_tmpref_buffer = opes_request.in_operation_param4_tmpref_buffer(); + in_operation_param4_tmpref_size = opes_request.in_operation_param4_tmpref_size(); + in_operation_param4_memref_parent = opes_request.in_operation_param4_memref_parent(); + in_operation_param4_memref_size = opes_request.in_operation_param4_memref_size(); + in_operation_param4_memref_offset = opes_request.in_operation_param4_memref_offset(); + in_operation_param4_value_a = opes_request.in_operation_param4_value_a(); + in_operation_param4_value_b = opes_request.in_operation_param4_value_b(); + in_operation_param4_ionref_ionsharefd = opes_request.in_operation_param4_ionref_ionsharefd(); + in_operation_param4_ionref_ionsize = opes_request.in_operation_param4_ionref_ionsize(); + + in_operation_session = opes_request.in_operation_session(); + in_operation_cancelflag = opes_request.in_operation_cancelflag(); + in_returnorigin = opes_request.in_returnorigin(); + in_context_addr = opes_request.in_context_addr(); +#if 0 + printf(" in_session_list_next = 0x %16.16lx \n", in_context_sessionlist_next); + printf(" in_session_list_prev = 0x %16.16lx \n", in_context_sessionlist_prev); + printf(" in_shrd_mem_list_next = 0x %16.16lx \n", in_context_shrdmemlist_next); + printf(" in_shrd_mem_list_prev = 0x %16.16lx \n", in_context_shrdmemlist_prev); + printf(" in_share_buffer_buffer = 0x %16.16lx \n", in_context_sharebuffer_buffer); + printf(" in_share_buffer_buffer_barrier = 0x %16.16lx \n", in_context_sharebuffer_bufferbarrier); + + printf(" in_destination_timelow = 0x %8.8x \n", in_destination_timelow); + printf(" in_destination_timemid = 0x %8.8x \n", in_destination_timemid); + printf(" in_destination_timehiandver = 0x %8.8x \n", in_destination_timehiandver); + if ( in_destination_clockseqandnode_size > 0 ) + { + printf(" in_destination_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < in_destination_clockseqandnode_size; i++) { + printf(" %8.8x", in_destination_clockseqandnode[i]); + } + printf("\n"); + } + else + { + printf(" in_destination_clockseqandnode addr = 0x %16.16lx \n", + (long unsigned int)in_destination_clockseqandnode + ); + } + printf(" in_destination_clockseqandnode_size = 0x %8.8x \n", in_destination_clockseqandnode_size); + + printf(" in_connectionmethod = 0x %8.8x \n", in_connectionmethod); + printf(" in_connectiondata = 0x %16.16lx \n", in_connectiondata); + + printf(" in_operation_started = 0x %8.8x \n", in_operation_started); + printf(" in_operation_paramtypes = 0x %8.8x \n", in_operation_paramtypes); + + printf(" in_operation_param1_tmpref_buffer = 0x %16.16lx \n", in_operation_param1_tmpref_buffer); + printf(" in_operation_param1_tmpref_size = 0x %8.8x \n", in_operation_param1_tmpref_size); + printf(" in_operation_param1_memref_parent = 0x %16.16lx \n", in_operation_param1_memref_parent); + printf(" in_operation_param1_memref_size = 0x %8.8x \n", in_operation_param1_memref_size); + printf(" in_operation_param1_memref_offset = 0x %8.8x \n", in_operation_param1_memref_offset); + printf(" in_operation_param1_value_a = 0x %8.8x \n", in_operation_param1_value_a); + printf(" in_operation_param1_value_b = 0x %8.8x \n", in_operation_param1_value_b); + printf(" in_operation_param1_ionref_ionsharefd = 0x %8.8x \n", + in_operation_param1_ionref_ionsharefd); + printf(" in_operation_param1_ionref_ionsize = 0x %8.8x \n", in_operation_param1_ionref_ionsize); + + printf(" in_operation_param2_tmpref_buffer = 0x %16.16lx \n", in_operation_param2_tmpref_buffer); + printf(" in_operation_param2_tmpref_size = 0x %8.8x \n", in_operation_param2_tmpref_size); + printf(" in_operation_param2_memref_parent = 0x %16.16lx \n", in_operation_param2_memref_parent); + printf(" in_operation_param2_memref_size = 0x %8.8x \n", in_operation_param2_memref_size); + printf(" in_operation_param2_memref_offset = 0x %8.8x \n", in_operation_param2_memref_offset); + printf(" in_operation_param2_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param2_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param2_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param2_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param3_tmpref_buffer = 0x %16.16lx \n", in_operation_param3_tmpref_buffer); + printf(" in_operation_param3_tmpref_size = 0x %8.8x \n", in_operation_param3_tmpref_size); + printf(" in_operation_param3_memref_parent = 0x %16.16lx \n", in_operation_param3_memref_parent); + printf(" in_operation_param3_memref_size = 0x %8.8x \n", in_operation_param3_memref_size); + printf(" in_operation_param3_memref_offset = 0x %8.8x \n", in_operation_param3_memref_offset); + printf(" in_operation_param3_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param3_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param3_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param3_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param4_tmpref_buffer = 0x %16.16lx \n", in_operation_param4_tmpref_buffer); + printf(" in_operation_param4_tmpref_size = 0x %8.8x \n", in_operation_param4_tmpref_size); + printf(" in_operation_param4_memref_parent = 0x %16.16lx \n", in_operation_param4_memref_parent); + printf(" in_operation_param4_memref_size = 0x %8.8x \n", in_operation_param4_memref_size); + printf(" in_operation_param4_memref_offset = 0x %8.8x \n", in_operation_param4_memref_offset); + printf(" in_operation_param4_value_a = 0x %8.8x \n", in_operation_param4_value_a); + printf(" in_operation_param4_value_b = 0x %8.8x \n", in_operation_param4_value_b); + printf(" in_operation_param4_ionref_ionsharefd = 0x %8.8x \n", in_operation_param4_ionref_ionsharefd); + printf(" in_operation_param4_ionref_ionsize = 0x %8.8x \n", in_operation_param4_ionref_ionsize); + + printf(" in_operation_session = 0x %16.16lx \n", in_operation_session); + printf(" in_operation_cancelflag = 0x %8.8x \n", in_operation_cancelflag); + + printf(" in_returnorigin = 0x %8.8x \n", in_returnorigin); +#endif + std::cout << "gpp received in_context_addr: 0x " << std::hex << std::setfill('0') + << std::setw(16) << in_context_addr << std::endl; + ta_path = (unsigned char *) malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *) ta_path, 0, 1024); + + uint32_t context_tapath_outsize; + uint32_t serviceid_clockseqandnode_outsize_temp; + uint32_t returnorigin_temp; + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (std::uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(std::uint32_t) + ); + + char workername[1024]; + memset((char *) workername, 0, 1024); + int ifound = 0; + int iworker; + + pthread_mutex_lock(mutex_workerrec_); + for (iworker = 0; iworker < global_max_num_worker; iworker++) + { + if (workerrec_[iworker].context_fd == in_context_fd && + workerrec_[iworker].context_addr == in_context_addr + ) + { + sprintf(workername, "%s%d", "gpworker", iworker); + std::cout << "gpp method call worker No: " << std::dec << iworker << std::endl; + ifound = 1; + break; + } + } + pthread_mutex_unlock(mutex_workerrec_); + if (ifound == 0) + { + printf("gpp can't find the woker for the context. \n"); + + teecresult = 0xAAAA0017; + + fd = 0x0; + ta_path = NULL; + charp = ta_path; + session_list_next = 0x0; + session_list_prev = 0x0; + shrd_mem_list_next = 0x0; + shrd_mem_list_prev = 0x0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0x0; + + sessionid = 0x0; + serviceid_timelow = 0x0; + serviceid_timemid = 0x0; + serviceid_timehiandver = 0x0; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + for (int i = 0; i < serviceid_clockseqandnode_realsize; i++) + { + serviceid_clockseqandnode[i] = 0x0; + } + serviceid_clockseqandnode_outsize = 8; + opscnt = 0x0; + head_next = 0x0; + head_prev = 0x0; + session_context = 0x0; + + started = 0x0; + paramtypes = 0x0; + + operation_param1_tmpref_buffer = 0x0; + operation_param1_tmpref_size = 0x0; + operation_param1_memref_parent = 0x0; + operation_param1_memref_size = 0x0; + operation_param1_memref_offset = 0x0; + operation_param1_value_a = 0x0; + operation_param1_value_b = 0x0; + operation_param1_ionref_ionsharefd = 0x0; + operation_param1_ionref_ionsize = 0x0; + + operation_param2_tmpref_buffer = 0x0; + operation_param2_tmpref_size = 0x0; + operation_param2_memref_parent = 0x0; + operation_param2_memref_size = 0x0; + operation_param2_memref_offset = 0x0; + operation_param2_value_a = 0x0; + operation_param2_value_b = 0x0; + operation_param2_ionref_ionsharefd = 0x0; + operation_param2_ionref_ionsize = 0x0; + + operation_param3_tmpref_buffer = 0x0; + operation_param3_tmpref_size = 0x0; + operation_param3_memref_parent = 0x0; + operation_param3_memref_size = 0x0; + operation_param3_memref_offset = 0x0; + operation_param3_value_a = 0x0; + operation_param3_value_b = 0x0; + operation_param3_ionref_ionsharefd = 0x0; + operation_param3_ionref_ionsize = 0x0; + + operation_param4_tmpref_buffer = 0x0; + operation_param4_tmpref_size = 0x0; + operation_param4_memref_parent = 0x0; + operation_param4_memref_size = 0x0; + operation_param4_memref_offset = 0x0; + operation_param4_value_a = 0x0; + operation_param4_value_b = 0x0; + operation_param4_ionref_ionsharefd = 0x0; + operation_param4_ionref_ionsize = 0x0; + + operation_session = 0x0; + operation_cancelflag = 0x0; + + returnorigin = 0x0; + + opes_reply.set_teecresult(teecresult); + opes_reply.set_context_fd(fd); + opes_reply.set_context_tapath_outsize(ta_path_size); + opes_reply.set_context_sessionlist_next(session_list_next); + opes_reply.set_context_sessionlist_prev(session_list_prev); + opes_reply.set_context_shrdmemlist_prev(shrd_mem_list_prev); + opes_reply.set_context_shrdmemlist_next(shrd_mem_list_next); + opes_reply.set_context_sharebuffer_buffer(share_buffer_buffer); + opes_reply.set_context_sharebuffer_bufferbarrier(share_buffer_buffer_barrier); + opes_reply.set_session_sessionid(sessionid); + opes_reply.set_session_serviceid_timelow(serviceid_timelow); + opes_reply.set_session_serviceid_timemid(serviceid_timemid); + opes_reply.set_session_serviceid_timehiandver(serviceid_timehiandver); + opes_reply.set_session_serviceid_clockseqandnode_outsize( + serviceid_clockseqandnode_outsize); + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < serviceid_clockseqandnode_outsize; i++) + opes_reply.add_session_serviceid_clockseqandnode( + serviceid_clockseqandnode[i]); + } + opes_reply.set_session_opscnt(opscnt); + opes_reply.set_session_head_next(head_next); + opes_reply.set_session_head_prev(head_prev); + opes_reply.set_session_context(session_context); + opes_reply.set_operation_started(started); + opes_reply.set_operation_paramtypes(paramtypes); + opes_reply.set_operation_param1_tmpref_buffer(operation_param1_tmpref_buffer); + opes_reply.set_operation_param1_tmpref_size(operation_param1_tmpref_size); + opes_reply.set_operation_param1_memref_parent(operation_param1_memref_parent); + opes_reply.set_operation_param1_memref_size(operation_param1_memref_size); + opes_reply.set_operation_param1_memref_offset(operation_param1_memref_offset); + opes_reply.set_operation_param1_value_a(operation_param1_value_a); + opes_reply.set_operation_param1_value_b(operation_param1_value_b); + opes_reply.set_operation_param1_ionref_ionsharefd( + operation_param1_ionref_ionsharefd); + opes_reply.set_operation_param1_ionref_ionsize(operation_param1_ionref_ionsize); + + opes_reply.set_operation_param2_tmpref_buffer(operation_param2_tmpref_buffer); + opes_reply.set_operation_param2_tmpref_size(operation_param2_tmpref_size); + opes_reply.set_operation_param2_memref_parent(operation_param2_memref_parent); + opes_reply.set_operation_param2_memref_size(operation_param2_memref_size); + opes_reply.set_operation_param2_memref_offset(operation_param2_memref_offset); + opes_reply.set_operation_param2_value_a(operation_param2_value_a); + opes_reply.set_operation_param2_value_b(operation_param2_value_b); + opes_reply.set_operation_param2_ionref_ionsharefd( + operation_param2_ionref_ionsharefd); + opes_reply.set_operation_param2_ionref_ionsize(operation_param2_ionref_ionsize); + + opes_reply.set_operation_param3_tmpref_buffer(operation_param3_tmpref_buffer); + opes_reply.set_operation_param3_tmpref_size(operation_param3_tmpref_size); + opes_reply.set_operation_param3_memref_parent(operation_param3_memref_parent); + opes_reply.set_operation_param3_memref_size(operation_param3_memref_size); + opes_reply.set_operation_param3_memref_offset(operation_param3_memref_offset); + opes_reply.set_operation_param3_value_a(operation_param3_value_a); + opes_reply.set_operation_param3_value_b(operation_param3_value_b); + opes_reply.set_operation_param3_ionref_ionsharefd( + operation_param3_ionref_ionsharefd); + opes_reply.set_operation_param3_ionref_ionsize(operation_param3_ionref_ionsize); + + opes_reply.set_operation_param4_tmpref_buffer(operation_param4_tmpref_buffer); + opes_reply.set_operation_param4_tmpref_size(operation_param4_tmpref_size); + opes_reply.set_operation_param4_memref_parent(operation_param4_memref_parent); + opes_reply.set_operation_param4_memref_size(operation_param4_memref_size); + opes_reply.set_operation_param4_memref_offset(operation_param4_memref_offset); + opes_reply.set_operation_param4_value_a(operation_param4_value_a); + opes_reply.set_operation_param4_value_b(operation_param4_value_b); + opes_reply.set_operation_param4_ionref_ionsharefd( + operation_param4_ionref_ionsharefd); + opes_reply.set_operation_param4_ionref_ionsize(operation_param4_ionref_ionsize); + + opes_reply.set_operation_session(operation_session); + opes_reply.set_operation_cancelflag(operation_cancelflag); + opes_reply.set_returnorigin(returnorigin); + + status_ = FINISH; + + opes_response.Finish(opes_reply, Status::OK, this); + } else + { + method_call_teec_opensession( + workername, + + in_context_fd, + in_context_tapath_temp, + in_context_tapath_size, + in_context_sessionlist_next, + in_context_sessionlist_prev, + in_context_shrdmemlist_next, + in_context_shrdmemlist_prev, + in_context_sharebuffer_buffer, + in_context_sharebuffer_bufferbarrier, + + in_destination_timelow, + in_destination_timemid, + in_destination_timehiandver, + in_destination_clockseqandnode, + in_destination_clockseqandnode_size, + + in_connectionmethod, + in_connectiondata, + + in_operation_started, + in_operation_paramtypes, + + in_operation_param1_tmpref_buffer, + in_operation_param1_tmpref_size, + in_operation_param1_memref_parent, + in_operation_param1_memref_size, + in_operation_param1_memref_offset, + in_operation_param1_value_a, + in_operation_param1_value_b, + in_operation_param1_ionref_ionsharefd, + in_operation_param1_ionref_ionsize, + + in_operation_param2_tmpref_buffer, + in_operation_param2_tmpref_size, + in_operation_param2_memref_parent, + in_operation_param2_memref_size, + in_operation_param2_memref_offset, + in_operation_param2_value_a, + in_operation_param2_value_b, + in_operation_param2_ionref_ionsharefd, + in_operation_param2_ionref_ionsize, + + in_operation_param3_tmpref_buffer, + in_operation_param3_tmpref_size, + in_operation_param3_memref_parent, + in_operation_param3_memref_size, + in_operation_param3_memref_offset, + in_operation_param3_value_a, + in_operation_param3_value_b, + in_operation_param3_ionref_ionsharefd, + in_operation_param3_ionref_ionsize, + + in_operation_param4_tmpref_buffer, + in_operation_param4_tmpref_size, + in_operation_param4_memref_parent, + in_operation_param4_memref_size, + in_operation_param4_memref_offset, + in_operation_param4_value_a, + in_operation_param4_value_b, + in_operation_param4_ionref_ionsharefd, + in_operation_param4_ionref_ionsize, + + in_operation_session, + in_operation_cancelflag, + + in_returnorigin, + + in_context_addr, + + + &teecresult, + + &fd, + ta_path, + ta_path_size, + &context_tapath_outsize, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + + &sessionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &session_context, + + &started, + ¶mtypes, + + &operation_param1_tmpref_buffer, + &operation_param1_tmpref_size, + &operation_param1_memref_parent, + &operation_param1_memref_size, + &operation_param1_memref_offset, + &operation_param1_value_a, + &operation_param1_value_b, + &operation_param1_ionref_ionsharefd, + &operation_param1_ionref_ionsize, + + &operation_param2_tmpref_buffer, + &operation_param2_tmpref_size, + &operation_param2_memref_parent, + &operation_param2_memref_size, + &operation_param2_memref_offset, + &operation_param2_value_a, + &operation_param2_value_b, + &operation_param2_ionref_ionsharefd, + &operation_param2_ionref_ionsize, + + &operation_param3_tmpref_buffer, + &operation_param3_tmpref_size, + &operation_param3_memref_parent, + &operation_param3_memref_size, + &operation_param3_memref_offset, + &operation_param3_value_a, + &operation_param3_value_b, + &operation_param3_ionref_ionsharefd, + &operation_param3_ionref_ionsize, + + &operation_param4_tmpref_buffer, + &operation_param4_tmpref_size, + &operation_param4_memref_parent, + &operation_param4_memref_size, + &operation_param4_memref_offset, + &operation_param4_value_a, + &operation_param4_value_b, + &operation_param4_ionref_ionsharefd, + &operation_param4_ionref_ionsize, + + &operation_session, + &operation_cancelflag, + + &returnorigin_temp + ); + if (teecresult == 0) + { + pthread_mutex_lock(mutex_workerrec_); + sin_t *sinIns = (sin_t *) malloc(sizeof(sin_t)); + sinIns->session_id = sessionid; + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + sinIns->session_createtime = tvcreate; + workerrec_[iworker].context_createtime = tvcreate; + if (workerrec_[iworker].first == NULL) + { + sinIns->next = NULL; + sinIns->prev = NULL; + workerrec_[iworker].first = sinIns; + workerrec_[iworker].last = sinIns; + workerrec_[iworker].sessionid_count = 1; + } else + { + sinIns->prev = workerrec_[iworker].last; + sinIns->next = NULL; + workerrec_[iworker].last->next = sinIns; + workerrec_[iworker].last = sinIns; + workerrec_[iworker].sessionid_count = + workerrec_[iworker].sessionid_count + 1; + } + pthread_mutex_unlock(mutex_workerrec_); + } + serviceid_clockseqandnode_outsize = + serviceid_clockseqandnode_outsize_temp; + returnorigin = returnorigin_temp; + + if (ta_path_size >= context_tapath_outsize) + { + ta_path_size = context_tapath_outsize; + charp = ta_path; + } else + { + ta_path_size = 0; + charp = NULL; + } + + if ( + serviceid_clockseqandnode_realsize >= serviceid_clockseqandnode_outsize && + 8 >= serviceid_clockseqandnode_outsize + ) + { + serviceid_clockseqandnode_realsize = serviceid_clockseqandnode_outsize; + } else + { + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode_outsize = 0; + } + opes_reply.set_teecresult(teecresult); + opes_reply.set_context_fd(fd); + opes_reply.set_context_tapath_outsize(ta_path_size); + + if (ta_path_size > 0 && + charp != NULL && + strlen((const char *) charp) > 0 + ) + { + charpp = (const char *) charp; + if (utf8_check_is_valid(charpp)) + { + ta_path_size = strlen((const char *) charp); + } else + { + ta_path_size = 0; + } + } else + { + ta_path_size = 0; + } + if (ta_path_size > 0) + { + opes_reply.set_context_tapath(charpp); + } + + opes_reply.set_context_sessionlist_next(session_list_next); + opes_reply.set_context_sessionlist_prev(session_list_prev); + opes_reply.set_context_shrdmemlist_prev(shrd_mem_list_prev); + opes_reply.set_context_shrdmemlist_next(shrd_mem_list_next); + opes_reply.set_context_sharebuffer_buffer(share_buffer_buffer); + opes_reply.set_context_sharebuffer_bufferbarrier(share_buffer_buffer_barrier); + opes_reply.set_session_sessionid(sessionid); + opes_reply.set_session_serviceid_timelow(serviceid_timelow); + opes_reply.set_session_serviceid_timemid(serviceid_timemid); + opes_reply.set_session_serviceid_timehiandver(serviceid_timehiandver); + opes_reply.set_session_serviceid_clockseqandnode_outsize( + serviceid_clockseqandnode_outsize); + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < serviceid_clockseqandnode_outsize; i++) + opes_reply.add_session_serviceid_clockseqandnode( + serviceid_clockseqandnode[i]); + } + opes_reply.set_session_opscnt(opscnt); + opes_reply.set_session_head_next(head_next); + opes_reply.set_session_head_prev(head_prev); + opes_reply.set_session_context(session_context); + opes_reply.set_operation_started(started); + opes_reply.set_operation_paramtypes(paramtypes); + opes_reply.set_operation_param1_tmpref_buffer(operation_param1_tmpref_buffer); + opes_reply.set_operation_param1_tmpref_size(operation_param1_tmpref_size); + opes_reply.set_operation_param1_memref_parent(operation_param1_memref_parent); + opes_reply.set_operation_param1_memref_size(operation_param1_memref_size); + opes_reply.set_operation_param1_memref_offset(operation_param1_memref_offset); + opes_reply.set_operation_param1_value_a(operation_param1_value_a); + opes_reply.set_operation_param1_value_b(operation_param1_value_b); + opes_reply.set_operation_param1_ionref_ionsharefd( + operation_param1_ionref_ionsharefd); + opes_reply.set_operation_param1_ionref_ionsize(operation_param1_ionref_ionsize); + + opes_reply.set_operation_param2_tmpref_buffer(operation_param2_tmpref_buffer); + opes_reply.set_operation_param2_tmpref_size(operation_param2_tmpref_size); + opes_reply.set_operation_param2_memref_parent(operation_param2_memref_parent); + opes_reply.set_operation_param2_memref_size(operation_param2_memref_size); + opes_reply.set_operation_param2_memref_offset(operation_param2_memref_offset); + opes_reply.set_operation_param2_value_a(operation_param2_value_a); + opes_reply.set_operation_param2_value_b(operation_param2_value_b); + opes_reply.set_operation_param2_ionref_ionsharefd( + operation_param2_ionref_ionsharefd); + opes_reply.set_operation_param2_ionref_ionsize(operation_param2_ionref_ionsize); + + opes_reply.set_operation_param3_tmpref_buffer(operation_param3_tmpref_buffer); + opes_reply.set_operation_param3_tmpref_size(operation_param3_tmpref_size); + opes_reply.set_operation_param3_memref_parent(operation_param3_memref_parent); + opes_reply.set_operation_param3_memref_size(operation_param3_memref_size); + opes_reply.set_operation_param3_memref_offset(operation_param3_memref_offset); + opes_reply.set_operation_param3_value_a(operation_param3_value_a); + opes_reply.set_operation_param3_value_b(operation_param3_value_b); + opes_reply.set_operation_param3_ionref_ionsharefd( + operation_param3_ionref_ionsharefd); + opes_reply.set_operation_param3_ionref_ionsize(operation_param3_ionref_ionsize); + + opes_reply.set_operation_param4_tmpref_buffer(operation_param4_tmpref_buffer); + opes_reply.set_operation_param4_tmpref_size(operation_param4_tmpref_size); + opes_reply.set_operation_param4_memref_parent(operation_param4_memref_parent); + opes_reply.set_operation_param4_memref_size(operation_param4_memref_size); + opes_reply.set_operation_param4_memref_offset(operation_param4_memref_offset); + opes_reply.set_operation_param4_value_a(operation_param4_value_a); + opes_reply.set_operation_param4_value_b(operation_param4_value_b); + opes_reply.set_operation_param4_ionref_ionsharefd( + operation_param4_ionref_ionsharefd); + opes_reply.set_operation_param4_ionref_ionsize(operation_param4_ionref_ionsize); + + opes_reply.set_operation_session(operation_session); + opes_reply.set_operation_cancelflag(operation_cancelflag); + opes_reply.set_returnorigin(returnorigin); + + status_ = FINISH; + gettimeofday(&end, NULL); + int64_t i64Time; + i64Time = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + printf("gpp opensession used time: %ld us. \n", i64Time); + + status_ = FINISH; + + opes_response.Finish(opes_reply, Status::OK, this); + } + }else + { + std::cout << "gpp receive no opensession jwtsvid or validate jwt failed" << std::endl; + flag = 2; + opes_reply.set_flag(flag); + status_ = FINISH; + opes_response.Finish(opes_reply, Status::OK, this); + } + break; + } + + case ServerImpl::CallData::SS_TEECC_CloseSession: + { + struct timeval start, end, jwt_validate_start, jwt_validate_end; + gettimeofday(&start, NULL); + + std::uint32_t in_session_sessionid; + std::uint32_t in_session_serviceid_timelow; + std::uint32_t in_session_serviceid_timemid; + std::uint32_t in_session_serviceid_timehiandver; + std::uint32_t in_session_serviceid_clockseqandnode_size; + std::uint32_t *in_session_serviceid_clockseqandnode; + std::uint32_t in_session_opscnt; + std::uint64_t in_session_head_next; + std::uint64_t in_session_head_prev; + std::uint64_t in_session_context; + + std::uint32_t sessionid; + std::uint32_t serviceid_timelow; + std::uint32_t serviceid_timemid; + std::uint32_t serviceid_timehiandver; + std::uint32_t *serviceid_clockseqandnode; + std::uint32_t serviceid_clockseqandnode_outsize; + int serviceid_clockseqandnode_realsize; + std::uint32_t opscnt; + std::uint64_t head_next; + std::uint64_t head_prev; + std::uint64_t session_context; + + std::uint32_t serial = 0; + std::int32_t flag = 0; + + std::string token; + token = close_request.token(); + + std::string noToken("noToken"); + int ivaljwtResult = -1; + int iforceValidateJwt = global_force_valideta_jwt; + + if + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + ) + { + char Token[1024]; + strcpy(Token, (char *) token.data()); + gettimeofday(&jwt_validate_start, NULL); + ivaljwtResult = + dbusmethodcall_validate_jwt( + Token + ); + gettimeofday(&jwt_validate_end, NULL); + int64_t i64Time_jwt; + i64Time_jwt = (jwt_validate_end.tv_sec - jwt_validate_start.tv_sec) * 1000000 + + (jwt_validate_end.tv_usec - jwt_validate_start.tv_usec); + printf("gpp closesession validate jwt used time: %ld us. \n", i64Time_jwt); + std::cout << "gpp validate closesession jwtsvid" << std::endl; + } else + { + std::cout << "gpp no validate closesession jwtsvid" << std::endl; + } + + if + ( + iforceValidateJwt != 1 + || + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + && + ivaljwtResult == NO_ERROR + ) + ) + { + std::cout << "gpp does not need validate closesession jwtsvid or validate jwt succed" + << std::endl; + std::cout << "gpp received CloseSesssion " << std::endl; + in_session_sessionid = close_request.in_session_sessionid(); + in_session_serviceid_timelow = close_request.in_session_serviceid_timelow(); + in_session_serviceid_timemid = close_request.in_session_serviceid_timemid(); + in_session_serviceid_timehiandver = close_request.in_session_serviceid_timehiandver(); + in_session_serviceid_clockseqandnode_size = close_request.in_session_serviceid_clockseqandnode_size(); + if (in_session_serviceid_clockseqandnode_size > 0) + { + in_session_serviceid_clockseqandnode = new uint32_t[in_session_serviceid_clockseqandnode_size]; + for (int i = 0; i < in_session_serviceid_clockseqandnode_size; i++) + { + in_session_serviceid_clockseqandnode[i] = close_request.in_session_serviceid_clockseqandnode( + i); + } + } + in_session_opscnt = close_request.in_session_opscnt(); + in_session_head_next = close_request.in_session_head_next(); + in_session_head_prev = close_request.in_session_head_prev(); + in_session_context = close_request.in_session_context(); +#if 0 + printf(" in_session_serviceid_timelow = 0x %8.8x \n", in_session_serviceid_timelow); + printf(" in_session_serviceid_timemid = 0x %8.8x \n", in_session_serviceid_timemid); + printf(" in_session_serviceid_timehiandver = 0x %8.8x \n", + in_session_serviceid_timehiandver); + printf(" in_session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < in_session_serviceid_clockseqandnode_size; i++) { + printf(" %8.8x", in_session_serviceid_clockseqandnode[i]); + } + printf("\n"); + printf(" in_session_serviceid_clockseqandnode_size = 0x %8.8x \n", + in_session_serviceid_clockseqandnode_size); + printf(" in_session_opscnt = 0x %8.8x \n", in_session_opscnt); + printf(" in_session_head_next = 0x %16.16lx \n", in_session_head_next); + printf(" in_session_head_prev = 0x %16.16lx \n", in_session_head_prev); +#endif + std::cout << "gpp received in_session_sessionid: 0x " << std::hex << std::setfill('0') + << std::setw(8) << in_session_sessionid << std::endl; + std::cout << "gpp received in_session_context: 0x " << std::hex << std::setfill('0') + << std::setw(16) << in_session_context << std::endl; + + uint32_t serviceid_clockseqandnode_outsize_temp; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (std::uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(std::uint32_t) + ); + char workername[1024]; + memset((char *) workername, 0, 1024); + int ifound = 0; + int iworker; + sin_t *sinIns; + + pthread_mutex_lock(mutex_workerrec_); + for (iworker = 0; iworker < global_max_num_worker; iworker++) + { + if (workerrec_[iworker].context_addr == in_session_context) + { + sinIns = NULL; + if (workerrec_[iworker].first != NULL) + { + sinIns = workerrec_[iworker].first; + do + { + if (sinIns->session_id == in_session_sessionid) + { + sprintf(workername, "%s%d", "gpworker", iworker); + std::cout << "gpp method call worker No: " << std::dec << iworker << std::endl; + ifound = 1; + break; + } + sinIns = sinIns->next; + } while (sinIns != NULL); + + if (ifound == 1) + { + break; + } + } + } + } + pthread_mutex_unlock(mutex_workerrec_); + if (ifound == 0) + { + printf("gpp can't find the worker for the session and the context. \n"); + + sessionid = 0x0; + serviceid_timelow = 0x0; + serviceid_timemid = 0x0; + serviceid_timehiandver = 0x0; + opscnt = 0x0; + head_next = 0x0; + head_prev = 0x0; + session_context = 0x0; + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + for (int i = 0; i < serviceid_clockseqandnode_realsize; i++) + { + serviceid_clockseqandnode[i] = 0x0; + } + serviceid_clockseqandnode_outsize = 8; + close_reply.set_session_sessionid(sessionid); + close_reply.set_session_serviceid_timelow(serviceid_timelow); + close_reply.set_session_serviceid_timemid(serviceid_timemid); + close_reply.set_session_serviceid_timehiandver(serviceid_timehiandver); + close_reply.set_session_serviceid_cad_outsize(serviceid_clockseqandnode_outsize); + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < serviceid_clockseqandnode_outsize; i++) + close_reply.add_session_serviceid_clockseqandnode(serviceid_clockseqandnode[i]); + } + close_reply.set_session_opscnt(opscnt); + close_reply.set_session_head_next(head_next); + close_reply.set_session_head_prev(head_prev); + close_reply.set_session_context(session_context); + + status_ = FINISH; + + close_response.Finish(close_reply, Status::OK, this); + } else + { + method_call_teec_closesession( + workername, + + in_session_sessionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + &sessionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &session_context + ); + pthread_mutex_lock(mutex_workerrec_); + sin_t *sinTemp; + sinTemp = sinIns->prev; + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + workerrec_[iworker].context_createtime = tvcreate; + if (sinTemp != NULL) + { + sinTemp->next = sinIns->next; + } + sinTemp = sinIns->next; + if (sinTemp != NULL) + { + sinTemp->prev = sinIns->prev; + } + if (workerrec_[iworker].last == sinIns) + { + workerrec_[iworker].last = sinIns->prev; + } + if (workerrec_[iworker].first == sinIns) + { + workerrec_[iworker].first = sinIns->next; + } + free(sinIns); + workerrec_[iworker].sessionid_count = + workerrec_[iworker].sessionid_count - 1; + pthread_mutex_unlock(mutex_workerrec_); + + serviceid_clockseqandnode_outsize = serviceid_clockseqandnode_outsize_temp; + + if ( + serviceid_clockseqandnode_realsize >= serviceid_clockseqandnode_outsize && + 8 >= serviceid_clockseqandnode_outsize + ) + { + serviceid_clockseqandnode_realsize = serviceid_clockseqandnode_outsize; + } else + { + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode_outsize = 0; + } + close_reply.set_session_sessionid(sessionid); + close_reply.set_session_serviceid_timelow(serviceid_timelow); + close_reply.set_session_serviceid_timemid(serviceid_timemid); + close_reply.set_session_serviceid_timehiandver(serviceid_timehiandver); + close_reply.set_session_serviceid_cad_outsize(serviceid_clockseqandnode_outsize); + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < serviceid_clockseqandnode_outsize; i++) + close_reply.add_session_serviceid_clockseqandnode(serviceid_clockseqandnode[i]); + } + close_reply.set_session_opscnt(opscnt); + close_reply.set_session_head_next(head_next); + close_reply.set_session_head_prev(head_prev); + close_reply.set_session_context(session_context); + + gettimeofday(&end, NULL); + int64_t i64Time; + i64Time = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + printf("gpp closesession used time: %ld us. \n", i64Time); + + status_ = FINISH; + + close_response.Finish(close_reply, Status::OK, this); + } + }else + { + std::cout << "gpp receive no closesession jwtsvid or validate jwt failed" << std::endl; + flag = 2; + close_reply.set_flag(flag); + status_ = FINISH; + + close_response.Finish(close_reply, Status::OK, this); + } + + break; + } + + case ServerImpl::CallData::SS_TEECC_InvokeCommand: + { + struct timeval start, end, jwt_validate_start, jwt_validate_end; + gettimeofday(&start, NULL); + + std::uint32_t in_session_sessionid; + std::uint32_t in_session_serviceid_timelow; + std::uint32_t in_session_serviceid_timemid; + std::uint32_t in_session_serviceid_timehiandver; + std::uint32_t in_session_serviceid_clockseqandnode_size; + std::uint32_t *in_session_serviceid_clockseqandnode; + int in_session_serviceid_clockseqandnode_realsize; + std::uint32_t in_session_opscnt; + std::uint64_t in_session_head_next; + std::uint64_t in_session_head_prev; + std::uint64_t in_session_context; + + std::uint32_t in_commandid; + + std::uint32_t in_operation_started; + std::uint32_t in_operation_paramtypes; + + std::uint64_t in_operation_param1_tmpref_buffer; + std::uint32_t in_operation_param1_tmpref_size; + std::uint64_t in_operation_param1_memref_parent; + std::uint32_t in_operation_param1_memref_parent_flag; + std::uint32_t in_operation_param1_memref_size; + std::uint32_t in_operation_param1_memref_offset; + std::uint32_t in_operation_param1_value_a; + std::uint32_t in_operation_param1_value_b; + std::int32_t in_operation_param1_ionref_ionsharefd; + std::uint32_t in_operation_param1_ionref_ionsize; + + std::uint64_t in_operation_param2_tmpref_buffer; + std::uint32_t in_operation_param2_tmpref_size; + std::uint64_t in_operation_param2_memref_parent; + std::uint32_t in_operation_param2_memref_parent_flag; + std::uint32_t in_operation_param2_memref_size; + std::uint32_t in_operation_param2_memref_offset; + std::uint32_t in_operation_param2_value_a; + std::uint32_t in_operation_param2_value_b; + std::int32_t in_operation_param2_ionref_ionsharefd; + std::uint32_t in_operation_param2_ionref_ionsize; + + std::uint64_t in_operation_param3_tmpref_buffer; + std::uint32_t in_operation_param3_tmpref_size; + std::uint64_t in_operation_param3_memref_parent; + std::uint32_t in_operation_param3_memref_parent_flag; + std::uint32_t in_operation_param3_memref_size; + std::uint32_t in_operation_param3_memref_offset; + std::uint32_t in_operation_param3_value_a; + std::uint32_t in_operation_param3_value_b; + std::int32_t in_operation_param3_ionref_ionsharefd; + std::uint32_t in_operation_param3_ionref_ionsize; + + std::uint64_t in_operation_param4_tmpref_buffer; + std::uint32_t in_operation_param4_tmpref_size; + std::uint64_t in_operation_param4_memref_parent; + std::uint32_t in_operation_param4_memref_parent_flag; + std::uint32_t in_operation_param4_memref_size; + std::uint32_t in_operation_param4_memref_offset; + std::uint32_t in_operation_param4_value_a; + std::uint32_t in_operation_param4_value_b; + std::int32_t in_operation_param4_ionref_ionsharefd; + std::uint32_t in_operation_param4_ionref_ionsize; + + std::uint64_t in_operation_session; + std::int32_t in_operation_cancelflag; + + std::uint32_t in_returnorigin; + + std::uint32_t in_buffer1_size; + std::uint32_t *in_buffer1; + int in_buffer1_realsize; + std::uint32_t in_buffer2_size; + std::uint32_t *in_buffer2; + int in_buffer2_realsize; + std::uint32_t in_buffer3_size; + std::uint32_t *in_buffer3; + int in_buffer3_realsize; + std::uint32_t in_buffer4_size; + std::uint32_t *in_buffer4; + int in_buffer4_realsize; + + std::uint32_t teecresult; + + std::uint32_t sessionid; + std::uint32_t serviceid_timelow; + std::uint32_t serviceid_timemid; + std::uint32_t serviceid_timehiandver; + std::uint32_t *serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + std::int32_t serviceid_clockseqandnode_outsize; + std::uint32_t opscnt; + std::uint64_t head_next; + std::uint64_t head_prev; + std::uint64_t session_context; + std::uint32_t started; + std::uint32_t paramtypes; + std::uint64_t operation_param1_tmpref_buffer; + std::uint32_t operation_param1_tmpref_size; + std::uint64_t operation_param1_memref_parent; + std::uint32_t operation_param1_memref_parent_flag; + std::uint32_t operation_param1_memref_size; + std::uint32_t operation_param1_memref_offset; + std::uint32_t operation_param1_value_a; + std::uint32_t operation_param1_value_b; + std::int32_t operation_param1_ionref_ionsharefd; + std::uint32_t operation_param1_ionref_ionsize; + std::uint64_t operation_param2_tmpref_buffer; + std::uint32_t operation_param2_tmpref_size; + std::uint64_t operation_param2_memref_parent; + std::uint32_t operation_param2_memref_parent_flag; + std::uint32_t operation_param2_memref_size; + std::uint32_t operation_param2_memref_offset; + std::uint32_t operation_param2_value_a; + std::uint32_t operation_param2_value_b; + std::int32_t operation_param2_ionref_ionsharefd; + std::uint32_t operation_param2_ionref_ionsize; + std::uint64_t operation_param3_tmpref_buffer; + std::uint32_t operation_param3_tmpref_size; + std::uint64_t operation_param3_memref_parent; + std::uint32_t operation_param3_memref_parent_flag; + std::uint32_t operation_param3_memref_size; + std::uint32_t operation_param3_memref_offset; + std::uint32_t operation_param3_value_a; + std::uint32_t operation_param3_value_b; + std::int32_t operation_param3_ionref_ionsharefd; + std::uint32_t operation_param3_ionref_ionsize; + std::uint64_t operation_param4_tmpref_buffer; + std::uint32_t operation_param4_tmpref_size; + std::uint64_t operation_param4_memref_parent; + std::uint32_t operation_param4_memref_parent_flag; + std::uint32_t operation_param4_memref_size; + std::uint32_t operation_param4_memref_offset; + std::uint32_t operation_param4_value_a; + std::uint32_t operation_param4_value_b; + std::int32_t operation_param4_ionref_ionsharefd; + std::uint32_t operation_param4_ionref_ionsize; + std::uint64_t operation_session; + std::int32_t operation_cancelflag; + std::uint32_t returnorigin; + + std::uint32_t *buffer1; + int buffer1_realsize; + std::uint32_t buffer1_outsize; + std::uint32_t *buffer2; + int buffer2_realsize; + std::uint32_t buffer2_outsize; + std::uint32_t *buffer3; + int buffer3_realsize; + std::uint32_t buffer3_outsize; + std::uint32_t *buffer4; + int buffer4_realsize; + std::uint32_t buffer4_outsize; + + std::uint32_t serial = 0; + std::int32_t flag = 0; + std::string token; + token = invo_request.token(); + + std::string noToken("noToken"); + int ivaljwtResult = -1; + int iforceValidateJwt = global_force_valideta_jwt; + + if + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + ) + { + char Token[1024]; + strcpy(Token, (char *) token.data()); + gettimeofday(&jwt_validate_start, NULL); + ivaljwtResult = + dbusmethodcall_validate_jwt( + Token + ); + gettimeofday(&jwt_validate_end, NULL); + int64_t i64Time_jwt; + i64Time_jwt = (jwt_validate_end.tv_sec - jwt_validate_start.tv_sec) * 1000000 + + (jwt_validate_end.tv_usec - jwt_validate_start.tv_usec); + printf("gpp invokecommand validate jwt used time: %ld us. \n", i64Time_jwt); + std::cout << "gpp validate invokecommand jwtsvid" << std::endl; + } else + { + std::cout << "gpp no validate invokecommand jwtsvid" << std::endl; + } + + if + ( + iforceValidateJwt != 1 + || + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + && + ivaljwtResult == NO_ERROR + ) + ) + { + std::cout << "gpp does not need validate invokecommand jwtsvid or validate jwt succed" + << std::endl; + + in_session_sessionid = invo_request.in_session_sessionid(); + in_session_serviceid_timelow = invo_request.in_session_serviceid_timelow(); + in_session_serviceid_timemid = invo_request.in_session_serviceid_timemid(); + in_session_serviceid_timehiandver = invo_request.in_session_serviceid_timehiandver(); + + in_session_serviceid_clockseqandnode_size = invo_request.in_session_serviceid_clockseqandnode_size(); + in_session_serviceid_clockseqandnode_realsize = in_session_serviceid_clockseqandnode_size; + if (in_session_serviceid_clockseqandnode_size > 0) + { + in_session_serviceid_clockseqandnode = new uint32_t[in_session_serviceid_clockseqandnode_size]; + for (int i = 0; i < in_session_serviceid_clockseqandnode_size; i++) + { + in_session_serviceid_clockseqandnode[i] = invo_request.in_session_serviceid_clockseqandnode( + i); + } + } + in_session_opscnt = invo_request.in_session_opscnt(); + in_session_head_next = invo_request.in_session_head_next(); + in_session_head_prev = invo_request.in_session_head_prev(); + in_session_context = invo_request.in_session_context(); + in_commandid = invo_request.in_commandid(); + in_operation_started = invo_request.in_operation_started(); + in_operation_paramtypes = invo_request.in_operation_paramtypes(); + in_operation_param1_tmpref_buffer = invo_request.in_operation_param1_tmpref_buffer(); + in_operation_param1_tmpref_size = invo_request.in_operation_param1_tmpref_size(); + in_operation_param1_memref_parent_flag = invo_request.in_operation_param1_memref_parent_flag(); + in_operation_param1_memref_parent = invo_request.in_operation_param1_memref_parent(); + in_operation_param1_memref_size = invo_request.in_operation_param1_memref_size(); + in_operation_param1_memref_offset = invo_request.in_operation_param1_memref_offset(); + in_operation_param1_value_a = invo_request.in_operation_param1_value_a(); + in_operation_param1_value_b = invo_request.in_operation_param1_value_b(); + in_operation_param1_ionref_ionsharefd = invo_request.in_operation_param1_ionref_ionsharefd(); + in_operation_param1_ionref_ionsize = invo_request.in_operation_param1_ionref_ionsize(); + + in_operation_param2_tmpref_buffer = invo_request.in_operation_param2_tmpref_buffer(); + in_operation_param2_tmpref_size = invo_request.in_operation_param2_tmpref_size(); + in_operation_param2_memref_parent = invo_request.in_operation_param2_memref_parent(); + in_operation_param2_memref_parent_flag = invo_request.in_operation_param2_memref_parent_flag(); + in_operation_param2_memref_size = invo_request.in_operation_param2_memref_size(); + in_operation_param2_memref_offset = invo_request.in_operation_param2_memref_offset(); + in_operation_param2_value_a = invo_request.in_operation_param2_value_a(); + in_operation_param2_value_b = invo_request.in_operation_param2_value_b(); + in_operation_param2_ionref_ionsharefd = invo_request.in_operation_param2_ionref_ionsharefd(); + in_operation_param2_ionref_ionsize = invo_request.in_operation_param2_ionref_ionsize(); + + in_operation_param3_tmpref_buffer = invo_request.in_operation_param3_tmpref_buffer(); + in_operation_param3_tmpref_size = invo_request.in_operation_param3_tmpref_size(); + in_operation_param3_memref_parent = invo_request.in_operation_param3_memref_parent(); + in_operation_param3_memref_parent_flag = invo_request.in_operation_param3_memref_parent_flag(); + in_operation_param3_memref_size = invo_request.in_operation_param3_memref_size(); + in_operation_param3_memref_offset = invo_request.in_operation_param3_memref_offset(); + in_operation_param3_value_a = invo_request.in_operation_param3_value_a(); + in_operation_param3_value_b = invo_request.in_operation_param3_value_b(); + in_operation_param3_ionref_ionsharefd = invo_request.in_operation_param3_ionref_ionsharefd(); + in_operation_param3_ionref_ionsize = invo_request.in_operation_param3_ionref_ionsize(); + + in_operation_param4_tmpref_buffer = invo_request.in_operation_param4_tmpref_buffer(); + in_operation_param4_tmpref_size = invo_request.in_operation_param4_tmpref_size(); + in_operation_param4_memref_parent = invo_request.in_operation_param4_memref_parent(); + in_operation_param4_memref_parent_flag = invo_request.in_operation_param4_memref_parent_flag(); + in_operation_param4_memref_size = invo_request.in_operation_param4_memref_size(); + in_operation_param4_memref_offset = invo_request.in_operation_param4_memref_offset(); + in_operation_param4_value_a = invo_request.in_operation_param4_value_a(); + in_operation_param4_value_b = invo_request.in_operation_param4_value_b(); + in_operation_param4_ionref_ionsharefd = invo_request.in_operation_param4_ionref_ionsharefd(); + in_operation_param4_ionref_ionsize = invo_request.in_operation_param4_ionref_ionsize(); + + in_operation_session = invo_request.in_operation_session(); + in_operation_cancelflag = invo_request.in_operation_cancelflag(); + in_returnorigin = invo_request.in_returnorigin(); + + in_buffer1_size = invo_request.in_buffer1_size(); + in_buffer1_realsize = in_buffer1_size; + if (in_buffer1_size > 0) + { + in_buffer1 = new uint32_t[in_buffer1_size]; + for (int i = 0; i < in_buffer1_size; i++) + { + in_buffer1[i] = invo_request.in_buffer1(i); + } + } + + in_buffer2_size = invo_request.in_buffer2_size(); + in_buffer2_realsize = in_buffer2_size; + if (in_buffer2_size > 0) + { + in_buffer2 = new uint32_t[in_buffer2_size]; + for (int i = 0; i < in_buffer2_size; i++) + { + in_buffer2[i] = invo_request.in_buffer2(i); + } + } + + in_buffer3_size = invo_request.in_buffer3_size(); + in_buffer3_realsize = in_buffer3_size; + if (in_buffer3_size > 0) + { + in_buffer3 = new uint32_t[in_buffer3_size]; + for (int i = 0; i < in_buffer3_size; i++) + { + in_buffer3[i] = invo_request.in_buffer3(i); + } + } + + in_buffer4_size = invo_request.in_buffer4_size(); + in_buffer4_realsize = in_buffer4_size; + if (in_buffer4_size > 0) + { + in_buffer4 = new uint32_t[in_buffer4_size]; + for (int i = 0; i < in_buffer4_size; i++) + { + in_buffer4[i] = invo_request.in_buffer4(i); + } + } + + std::cout << "gpp received InvokeCommand " << std::endl; + std::cout << "gpp received in_session_sessionid: 0x " + << std::hex << std::setfill('0') << std::setw(8) << in_session_sessionid << std::endl; +#if 0 + printf(" in_session_serviceid_timelow = 0x %8.8x \n", in_session_serviceid_timelow); + printf(" in_session_serviceid_timemid = 0x %8.8x \n", in_session_serviceid_timemid); + printf(" in_session_serviceid_timehiandver = 0x %8.8x \n", + in_session_serviceid_timehiandver); + printf(" in_session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < in_session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", in_session_serviceid_clockseqandnode[i]); + } + printf("\n"); + printf(" in serviceid_clockseqandnode_size = 0x %8.8x \n", + in_session_serviceid_clockseqandnode_size); + printf(" in_session_opscnt = 0x %8.8x \n", in_session_opscnt); + printf(" in_session_head_next = 0x %16.16lx \n", in_session_head_next); + printf(" in_session_head_prev = 0x %16.16lx \n", in_session_head_prev); +#endif + std::cout << "gpp received in_session_context: 0x " << std::hex << std::setfill('0') + << std::setw(16) << in_session_context << std::endl; + +#if 0 + printf(" commandid = 0x %8.8x \n", in_commandid); + printf(" in_operation_started = 0x %8.8x \n", in_operation_started); + printf(" in_operation_paramtypes = 0x %8.8x \n", in_operation_paramtypes); + printf(" in_operation_param1_tmpref_buffer = 0x %16.16lx \n", in_operation_param1_tmpref_buffer); + printf(" in_operation_param1_tmpref_size = 0x %8.8x \n", in_operation_param1_tmpref_size); + printf(" in_operation_param1_memref_parent = 0x %16.16lx \n", in_operation_param1_memref_parent); + printf(" in_operation_param1_memref_size = 0x %8.8x \n", in_operation_param1_memref_size); + printf(" in_operation_param1_memref_offset = 0x %8.8x \n", in_operation_param1_memref_offset); + printf(" in_operation_param1_value_a = 0x %8.8x \n", in_operation_param1_value_a); + printf(" in_operation_param1_value_b = 0x %8.8x \n", in_operation_param1_value_b); + printf(" in_operation_param1_ionref_ionsharefd = 0x %8.8x \n",in_operation_param2_ionref_ionsharefd); + printf(" in_operation_param1_ionref_ionsize = 0x %8.8x \n", in_operation_param2_ionref_ionsize); + + printf(" in_operation_param2_tmpref_buffer = 0x %16.16lx \n", in_operation_param2_tmpref_buffer); + printf(" in_operation_param2_tmpref_size = 0x %8.8x \n", in_operation_param2_tmpref_size); + printf(" in_operation_param2_memref_parent = 0x %16.16lx \n", in_operation_param2_memref_parent); + printf(" in_operation_param2_memref_size = 0x %8.8x \n", in_operation_param2_memref_size); + printf(" in_operation_param2_memref_offset = 0x %8.8x \n", in_operation_param2_memref_offset); + printf(" in_operation_param2_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param2_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param2_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param2_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param3_tmpref_buffer = 0x %16.16lx \n", in_operation_param3_tmpref_buffer); + printf(" in_operation_param3_tmpref_size = 0x %8.8x \n", in_operation_param3_tmpref_size); + printf(" in_operation_param3_memref_parent = 0x %16.16lx \n", in_operation_param3_memref_parent); + printf(" in_operation_param3_memref_size = 0x %8.8x \n", in_operation_param3_memref_size); + printf(" in_operation_param3_memref_offset = 0x %8.8x \n", in_operation_param3_memref_offset); + printf(" in_operation_param3_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param3_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param3_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param3_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param4_tmpref_buffer = 0x %16.16lx \n", in_operation_param4_tmpref_buffer); + printf(" in_operation_param4_tmpref_size = 0x %8.8x \n", in_operation_param4_tmpref_size); + printf(" in_operation_param4_memref_parent = 0x %16.16lx \n", in_operation_param4_memref_parent); + printf(" in_operation_param4_memref_size = 0x %8.8x \n", in_operation_param4_memref_size); + printf(" in_operation_param4_memref_offset = 0x %8.8x \n", in_operation_param4_memref_offset); + printf(" in_operation_param4_value_a = 0x %8.8x \n", in_operation_param4_value_a); + printf(" in_operation_param4_value_b = 0x %8.8x \n", in_operation_param4_value_b); + printf(" in_operation_param4_ionref_ionsharefd = 0x %8.8x \n", in_operation_param4_ionref_ionsharefd); + printf(" in_operation_param4_ionref_ionsize = 0x %8.8x \n", in_operation_param4_ionref_ionsize); + + printf(" in_operation_session = 0x %16.16lx \n", in_operation_session); + printf(" in_operation_cancelflag = 0x %8.8x \n", in_operation_cancelflag); + + printf(" in_returnorigin = 0x %8.8x \n", in_returnorigin); + + printf(" in_buffer1 = \n"); + if (in_buffer1_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer1_realsize; i++) { + printf(" %2.2x", in_buffer1[i]); + } + printf("\n"); + } +#endif + +#if 0 + printf(" in_buffer1_size = 0x %8.8x \n", + in_buffer1_size); +#endif + +#if 0 + printf(" in_buffer2 = \n"); + if (in_buffer2_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer2_realsize; i++) { + printf(" %2.2x", in_buffer2[i]); + } + printf("\n"); + } + printf(" in_buffer2_size = 0x %8.8x \n", + in_buffer2_size); + + printf(" in_buffer3 = \n"); + if (in_buffer3_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer3_realsize; i++) { + printf(" %2.2x", in_buffer3[i]); + } + printf("\n"); + } + printf(" in_buffer3_size = 0x %8.8x \n", + in_buffer3_size); + + printf(" in_buffer4 = \n"); + if (in_buffer4_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer4_realsize; i++) { + printf(" %2.2x", in_buffer4[i]); + } + printf("\n"); + } + printf(" in_buffer4_size = 0x %8.8x \n", + in_buffer4_size); + +#endif + if (in_buffer1_size > 0) + { + } else + { + in_buffer1_realsize = 0; + } + if (in_buffer2_size > 0) + { + } else + { + in_buffer2_realsize = 0; + } + if (in_buffer3_size > 0) + { + } else + { + in_buffer3_realsize = 0; + } + if (in_buffer4_size > 0) + { + } else + { + in_buffer4_realsize = 0; + } + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + uint32_t serviceid_clockseqandnode_outsize_temp; + uint32_t returnorigin_temp; + + uint32_t *buffer1_temp = NULL; + uint32_t buffer1_size = 4096; + uint32_t buffer1_outsize_temp; + buffer1_temp = + (uint32_t *) malloc(buffer1_size * sizeof(uint32_t)); + + uint32_t buffer2_size = 4096; + uint32_t *buffer2_temp = NULL; + uint32_t buffer2_outsize_temp; + buffer2_temp = + (uint32_t *) malloc(buffer2_size * sizeof(uint32_t)); + + uint32_t buffer3_size = 4096; + uint32_t *buffer3_temp = NULL; + uint32_t buffer3_outsize_temp; + buffer3_temp = + (uint32_t *) malloc(buffer3_size * sizeof(uint32_t)); + + uint32_t buffer4_size = 4096; + uint32_t *buffer4_temp = NULL; + uint32_t buffer4_outsize_temp; + buffer4_temp = + (uint32_t *) malloc(buffer4_size * sizeof(uint32_t)); + + char workername[1024]; + memset((char *) workername, 0, 1024); + int ifound = 0; + int iworker; + sin_t *sinIns; + + pthread_mutex_lock(mutex_workerrec_); + for (iworker = 0; iworker < global_max_num_worker; iworker++) + { + if (workerrec_[iworker].context_addr == in_session_context) + { + sinIns = NULL; + if (workerrec_[iworker].first != NULL) + { + sinIns = workerrec_[iworker].first; + do + { + if (sinIns->session_id == in_session_sessionid) + { + sprintf(workername, "%s%d", "gpworker", iworker); + std::cout << "gpp method call worker No: " << std::dec << iworker << std::endl; + ifound = 1; + break; + } + sinIns = sinIns->next; + } while (sinIns != NULL); + if (ifound == 1) + { + break; + } + } + } + } + pthread_mutex_unlock(mutex_workerrec_); + + if (ifound == 0) + { + printf("gpp can't find the worker for the session and the context. \n"); + + teecresult = 0xAAAA0017; + + sessionid = 0x0; + serviceid_timelow = 0x0; + serviceid_timemid = 0x0; + serviceid_timehiandver = 0x0; + opscnt = 0x0; + head_next = 0x0; + head_prev = 0x0; + session_context = 0x0; + started = 0x0; + paramtypes = 0x0; + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + for (int i = 0; i < serviceid_clockseqandnode_realsize; i++) + { + serviceid_clockseqandnode[i] = 0x0; + } + serviceid_clockseqandnode_outsize = 8; + + operation_param1_tmpref_buffer = 0x0; + operation_param1_tmpref_size = 0x0; + operation_param1_memref_parent = 0x0; + operation_param1_memref_size = 0x0; + operation_param1_memref_offset = 0x0; + operation_param1_value_a = 0x0; + operation_param1_value_b = 0x0; + operation_param1_ionref_ionsharefd = 0x0; + operation_param1_ionref_ionsize = 0x0; + + operation_param2_tmpref_buffer = 0x0; + operation_param2_tmpref_size = 0x0; + operation_param2_memref_parent = 0x0; + operation_param2_memref_size = 0x0; + operation_param2_memref_offset = 0x0; + operation_param2_value_a = 0x0; + operation_param2_value_b = 0x0; + operation_param2_ionref_ionsharefd = 0x0; + operation_param2_ionref_ionsize = 0x0; + + operation_param3_tmpref_buffer = 0x0; + operation_param3_tmpref_size = 0x0; + operation_param3_memref_parent = 0x0; + operation_param3_memref_size = 0x0; + operation_param3_memref_offset = 0x0; + operation_param3_value_a = 0x0; + operation_param3_value_b = 0x0; + operation_param3_ionref_ionsharefd = 0x0; + operation_param3_ionref_ionsize = 0x0; + + operation_param4_tmpref_buffer = 0x0; + operation_param4_tmpref_size = 0x0; + operation_param4_memref_parent = 0x0; + operation_param4_memref_size = 0x0; + operation_param4_memref_offset = 0x0; + operation_param4_value_a = 0x0; + operation_param4_value_b = 0x0; + operation_param4_ionref_ionsharefd = 0x0; + operation_param4_ionref_ionsize = 0x0; + + operation_session = 0x0; + operation_cancelflag = 0x0; + + returnorigin = 0x0; + + buffer1_realsize = 0; + buffer1_outsize = buffer1_realsize; + + buffer2_realsize = 0; + buffer2_outsize = buffer2_realsize; + + buffer3_realsize = 0; + buffer3_outsize = buffer3_realsize; + + buffer4_realsize = 0; + buffer4_outsize = buffer4_realsize; + + invo_reply.set_teecresult(teecresult); + invo_reply.set_session_sessionid(sessionid); + invo_reply.set_session_serviceid_timelow(serviceid_timelow); + invo_reply.set_session_serviceid_timemid(serviceid_timemid); + invo_reply.set_session_serviceid_timehiandver(serviceid_timehiandver); + invo_reply.set_session_serviceid_clockseqandnode_outsize(serviceid_clockseqandnode_outsize); + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < serviceid_clockseqandnode_outsize; i++) + invo_reply.add_session_serviceid_clockseqandnode(serviceid_clockseqandnode[i]); + } + invo_reply.set_session_opscnt(opscnt); + invo_reply.set_session_head_next(head_next); + invo_reply.set_session_head_prev(head_prev); + invo_reply.set_session_context(session_context); + invo_reply.set_operation_started(started); + invo_reply.set_operation_paramtypes(paramtypes); + + invo_reply.set_operation_param1_tmpref_buffer(operation_param1_tmpref_buffer); + invo_reply.set_operation_param1_tmpref_size(operation_param1_tmpref_size); + invo_reply.set_operation_param1_memref_parent(operation_param1_memref_parent); + invo_reply.set_operation_param1_memref_parent_flag(in_operation_param1_memref_parent_flag); + invo_reply.set_operation_param1_memref_size(operation_param1_memref_size); + invo_reply.set_operation_param1_memref_offset(operation_param1_memref_offset); + invo_reply.set_operation_param1_value_a(operation_param1_value_a); + invo_reply.set_operation_param1_value_b(operation_param1_value_b); + invo_reply.set_operation_param1_ionref_ionsharefd(operation_param1_ionref_ionsharefd); + invo_reply.set_operation_param1_ionref_ionsize(operation_param1_ionref_ionsize); + + invo_reply.set_operation_param2_tmpref_buffer(operation_param2_tmpref_buffer); + invo_reply.set_operation_param2_tmpref_size(operation_param2_tmpref_size); + invo_reply.set_operation_param2_memref_parent(operation_param2_memref_parent); + invo_reply.set_operation_param2_memref_parent_flag(in_operation_param2_memref_parent_flag); + invo_reply.set_operation_param2_memref_size(operation_param2_memref_size); + invo_reply.set_operation_param2_memref_offset(operation_param2_memref_offset); + invo_reply.set_operation_param2_value_a(operation_param2_value_a); + invo_reply.set_operation_param2_value_b(operation_param2_value_b); + invo_reply.set_operation_param2_ionref_ionsharefd(operation_param2_ionref_ionsharefd); + invo_reply.set_operation_param2_ionref_ionsize(operation_param2_ionref_ionsize); + + invo_reply.set_operation_param3_tmpref_buffer(operation_param3_tmpref_buffer); + invo_reply.set_operation_param3_tmpref_size(operation_param3_tmpref_size); + invo_reply.set_operation_param3_memref_parent(operation_param3_memref_parent); + invo_reply.set_operation_param3_memref_parent_flag(in_operation_param3_memref_parent_flag); + invo_reply.set_operation_param3_memref_size(operation_param3_memref_size); + invo_reply.set_operation_param3_memref_offset(operation_param3_memref_offset); + invo_reply.set_operation_param3_value_a(operation_param3_value_a); + invo_reply.set_operation_param3_value_b(operation_param3_value_b); + invo_reply.set_operation_param3_ionref_ionsharefd(operation_param3_ionref_ionsharefd); + invo_reply.set_operation_param3_ionref_ionsize(operation_param3_ionref_ionsize); + + invo_reply.set_operation_param4_tmpref_buffer(operation_param4_tmpref_buffer); + invo_reply.set_operation_param4_tmpref_size(operation_param4_tmpref_size); + invo_reply.set_operation_param4_memref_parent(operation_param4_memref_parent); + invo_reply.set_operation_param4_memref_parent_flag(in_operation_param4_memref_parent_flag); + invo_reply.set_operation_param4_memref_size(operation_param4_memref_size); + invo_reply.set_operation_param4_memref_offset(operation_param4_memref_offset); + invo_reply.set_operation_param4_value_a(operation_param4_value_a); + invo_reply.set_operation_param4_value_b(operation_param4_value_b); + invo_reply.set_operation_param4_ionref_ionsharefd(operation_param4_ionref_ionsharefd); + invo_reply.set_operation_param4_ionref_ionsize(operation_param4_ionref_ionsize); + + invo_reply.set_operation_session(operation_session); + invo_reply.set_operation_cancelflag(operation_cancelflag); + invo_reply.set_returnorigin(returnorigin); + + invo_reply.set_buffer1_outsize(buffer1_realsize); + invo_reply.set_buffer2_outsize(buffer2_realsize); + invo_reply.set_buffer3_outsize(buffer3_realsize); + invo_reply.set_buffer4_outsize(buffer4_realsize); + + if (buffer1_realsize > 0 && + buffer1 != NULL + ) + { + for (int i = 0; i < buffer1_realsize; i++) + + invo_reply.add_buffer1(buffer1[i]); + } + + if (buffer2_realsize > 0 && + buffer2 != NULL + ) + { + for (int i = 0; i < buffer2_realsize; i++) + invo_reply.add_buffer2(buffer2[i]); + } + + if (buffer3_realsize > 0 && + buffer3 != NULL + ) + { + for (int i = 0; i < buffer3_realsize; i++) + invo_reply.add_buffer3(buffer3[i]); + } + + if (buffer4_realsize > 0 && + buffer4 != NULL + ) + { + for (int i = 0; i < buffer4_realsize; i++) + invo_reply.add_buffer4(buffer4[i]); + } + status_ = FINISH; + + invo_response.Finish(invo_reply, Status::OK, this); + } else + { + method_call_teec_invokecommand( + workername, + + in_session_sessionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_realsize, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + in_commandid, + + in_operation_started, + in_operation_paramtypes, + + in_operation_param1_tmpref_buffer, + in_operation_param1_tmpref_size, + in_operation_param1_memref_parent, + in_operation_param1_memref_parent_flag, + in_operation_param1_memref_size, + in_operation_param1_memref_offset, + in_operation_param1_value_a, + in_operation_param1_value_b, + in_operation_param1_ionref_ionsharefd, + in_operation_param1_ionref_ionsize, + + in_operation_param2_tmpref_buffer, + in_operation_param2_tmpref_size, + in_operation_param2_memref_parent, + in_operation_param2_memref_parent_flag, + in_operation_param2_memref_size, + in_operation_param2_memref_offset, + in_operation_param2_value_a, + in_operation_param2_value_b, + in_operation_param2_ionref_ionsharefd, + in_operation_param2_ionref_ionsize, + + in_operation_param3_tmpref_buffer, + in_operation_param3_tmpref_size, + in_operation_param3_memref_parent, + in_operation_param3_memref_parent_flag, + in_operation_param3_memref_size, + in_operation_param3_memref_offset, + in_operation_param3_value_a, + in_operation_param3_value_b, + in_operation_param3_ionref_ionsharefd, + in_operation_param3_ionref_ionsize, + + in_operation_param4_tmpref_buffer, + in_operation_param4_tmpref_size, + in_operation_param4_memref_parent, + in_operation_param4_memref_parent_flag, + in_operation_param4_memref_size, + in_operation_param4_memref_offset, + in_operation_param4_value_a, + in_operation_param4_value_b, + in_operation_param4_ionref_ionsharefd, + in_operation_param4_ionref_ionsize, + + in_operation_session, + in_operation_cancelflag, + + in_returnorigin, + + in_buffer1, + in_buffer1_realsize, + in_buffer2, + in_buffer2_realsize, + in_buffer3, + in_buffer3_realsize, + in_buffer4, + in_buffer4_realsize, + + + &teecresult, + + &sessionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + + &opscnt, + &head_next, + &head_prev, + &session_context, + + &started, + ¶mtypes, + + &operation_param1_tmpref_buffer, + &operation_param1_tmpref_size, + &operation_param1_memref_parent, + &operation_param1_memref_parent_flag, + &operation_param1_memref_size, + &operation_param1_memref_offset, + &operation_param1_value_a, + &operation_param1_value_b, + &operation_param1_ionref_ionsharefd, + &operation_param1_ionref_ionsize, + + &operation_param2_tmpref_buffer, + &operation_param2_tmpref_size, + &operation_param2_memref_parent, + &operation_param2_memref_parent_flag, + &operation_param2_memref_size, + &operation_param2_memref_offset, + &operation_param2_value_a, + &operation_param2_value_b, + &operation_param2_ionref_ionsharefd, + &operation_param2_ionref_ionsize, + + &operation_param3_tmpref_buffer, + &operation_param3_tmpref_size, + &operation_param3_memref_parent, + &operation_param3_memref_parent_flag, + &operation_param3_memref_size, + &operation_param3_memref_offset, + &operation_param3_value_a, + &operation_param3_value_b, + &operation_param3_ionref_ionsharefd, + &operation_param3_ionref_ionsize, + + &operation_param4_tmpref_buffer, + &operation_param4_tmpref_size, + &operation_param4_memref_parent, + &operation_param4_memref_parent_flag, + &operation_param4_memref_size, + &operation_param4_memref_offset, + &operation_param4_value_a, + &operation_param4_value_b, + &operation_param4_ionref_ionsharefd, + &operation_param4_ionref_ionsize, + + &operation_session, + &operation_cancelflag, + + &returnorigin_temp, + + buffer1_temp, + buffer1_size, + &buffer1_outsize_temp, + buffer2_temp, + buffer2_size, + &buffer2_outsize_temp, + buffer3_temp, + buffer3_size, + &buffer3_outsize_temp, + buffer4_temp, + buffer4_size, + &buffer4_outsize_temp + ); + + pthread_mutex_lock(mutex_workerrec_); + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + workerrec_[iworker].context_createtime = tvcreate; + sinIns->session_createtime = tvcreate; + pthread_mutex_unlock(mutex_workerrec_); + + serviceid_clockseqandnode_outsize = + serviceid_clockseqandnode_outsize_temp; + + returnorigin = returnorigin_temp; + + buffer1_outsize = buffer1_outsize_temp; + buffer2_outsize = buffer2_outsize_temp; + buffer3_outsize = buffer3_outsize_temp; + buffer4_outsize = buffer4_outsize_temp; + + + buffer1_realsize = buffer1_outsize; + if (buffer1_realsize > 0) + { + buffer1 = + (uint32_t *) malloc( + buffer1_realsize * sizeof(uint32_t) + ); + for (int i = 0; i < buffer1_realsize; i++) + { + buffer1[i] = (uint32_t) buffer1_temp[i]; + } + } + buffer2_realsize = buffer2_outsize; + if (buffer2_realsize > 0) + { + buffer2 = + (uint32_t *) malloc( + buffer2_realsize * sizeof(uint32_t) + ); + for (int i = 0; i < buffer2_realsize; i++) + { + buffer2[i] = (uint32_t) buffer2_temp[i]; + } + } + + buffer3_realsize = buffer3_outsize; + if (buffer3_realsize > 0) + { + buffer3 = + (uint32_t *) malloc( + buffer3_realsize * sizeof(uint32_t) + ); + for (int i = 0; i < buffer3_realsize; i++) + { + buffer3[i] = (uint32_t) buffer3_temp[i]; + } + } + + buffer4_realsize = buffer4_outsize; + if (buffer4_realsize > 0) + { + buffer4 = + (uint32_t *) malloc( + buffer4_realsize * sizeof(uint32_t) + ); + for (int i = 0; i < buffer4_realsize; i++) + { + buffer4[i] = (uint32_t) buffer4_temp[i]; + } + } + if (buffer1_temp != NULL) + { + free(buffer1_temp); + } + if (buffer2_temp != NULL) + { + free(buffer2_temp); + } + if (buffer3_temp != NULL) + { + free(buffer3_temp); + } + if (buffer4_temp != NULL) + { + free(buffer4_temp); + } + + invo_reply.set_teecresult(teecresult); + invo_reply.set_session_sessionid(sessionid); + invo_reply.set_session_serviceid_timelow(serviceid_timelow); + invo_reply.set_session_serviceid_timemid(serviceid_timemid); + invo_reply.set_session_serviceid_timehiandver(serviceid_timehiandver); + invo_reply.set_session_serviceid_clockseqandnode_outsize(serviceid_clockseqandnode_outsize); + + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < serviceid_clockseqandnode_outsize; i++) + invo_reply.add_session_serviceid_clockseqandnode(serviceid_clockseqandnode[i]); + } + invo_reply.set_session_opscnt(opscnt); + invo_reply.set_session_head_next(head_next); + invo_reply.set_session_head_prev(head_prev); + invo_reply.set_session_context(session_context); + invo_reply.set_operation_started(started); + invo_reply.set_operation_paramtypes(paramtypes); + + invo_reply.set_operation_param1_tmpref_buffer(operation_param1_tmpref_buffer); + invo_reply.set_operation_param1_tmpref_size(operation_param1_tmpref_size); + invo_reply.set_operation_param1_memref_parent(operation_param1_memref_parent); + invo_reply.set_operation_param1_memref_parent_flag(in_operation_param1_memref_parent_flag); + invo_reply.set_operation_param1_memref_size(operation_param1_memref_size); + invo_reply.set_operation_param1_memref_offset(operation_param1_memref_offset); + invo_reply.set_operation_param1_value_a(operation_param1_value_a); + invo_reply.set_operation_param1_value_b(operation_param1_value_b); + invo_reply.set_operation_param1_ionref_ionsharefd(operation_param1_ionref_ionsharefd); + invo_reply.set_operation_param1_ionref_ionsize(operation_param1_ionref_ionsize); + + invo_reply.set_operation_param2_tmpref_buffer(operation_param2_tmpref_buffer); + invo_reply.set_operation_param2_tmpref_size(operation_param2_tmpref_size); + invo_reply.set_operation_param2_memref_parent(operation_param2_memref_parent); + invo_reply.set_operation_param2_memref_parent_flag(in_operation_param2_memref_parent_flag); + invo_reply.set_operation_param2_memref_size(operation_param2_memref_size); + invo_reply.set_operation_param2_memref_offset(operation_param2_memref_offset); + invo_reply.set_operation_param2_value_a(operation_param2_value_a); + invo_reply.set_operation_param2_value_b(operation_param2_value_b); + invo_reply.set_operation_param2_ionref_ionsharefd(operation_param2_ionref_ionsharefd); + invo_reply.set_operation_param2_ionref_ionsize(operation_param2_ionref_ionsize); + + invo_reply.set_operation_param3_tmpref_buffer(operation_param3_tmpref_buffer); + invo_reply.set_operation_param3_tmpref_size(operation_param3_tmpref_size); + invo_reply.set_operation_param3_memref_parent(operation_param3_memref_parent); + invo_reply.set_operation_param3_memref_parent_flag(in_operation_param3_memref_parent_flag); + invo_reply.set_operation_param3_memref_size(operation_param3_memref_size); + invo_reply.set_operation_param3_memref_offset(operation_param3_memref_offset); + invo_reply.set_operation_param3_value_a(operation_param3_value_a); + invo_reply.set_operation_param3_value_b(operation_param3_value_b); + invo_reply.set_operation_param3_ionref_ionsharefd(operation_param3_ionref_ionsharefd); + invo_reply.set_operation_param3_ionref_ionsize(operation_param3_ionref_ionsize); + + invo_reply.set_operation_param4_tmpref_buffer(operation_param4_tmpref_buffer); + invo_reply.set_operation_param4_tmpref_size(operation_param4_tmpref_size); + invo_reply.set_operation_param4_memref_parent(operation_param4_memref_parent); + invo_reply.set_operation_param4_memref_parent_flag(in_operation_param4_memref_parent_flag); + invo_reply.set_operation_param4_memref_size(operation_param4_memref_size); + invo_reply.set_operation_param4_memref_offset(operation_param4_memref_offset); + invo_reply.set_operation_param4_value_a(operation_param4_value_a); + invo_reply.set_operation_param4_value_b(operation_param4_value_b); + invo_reply.set_operation_param4_ionref_ionsharefd(operation_param4_ionref_ionsharefd); + invo_reply.set_operation_param4_ionref_ionsize(operation_param4_ionref_ionsize); + + invo_reply.set_operation_session(operation_session); + invo_reply.set_operation_cancelflag(operation_cancelflag); + invo_reply.set_returnorigin(returnorigin); + + invo_reply.set_buffer1_outsize(buffer1_realsize); + invo_reply.set_buffer2_outsize(buffer2_realsize); + invo_reply.set_buffer3_outsize(buffer3_realsize); + invo_reply.set_buffer4_outsize(buffer4_realsize); + + if (buffer1_realsize > 0 && + buffer1 != NULL + ) + { + for (int i = 0; i < buffer1_realsize; i++) + + invo_reply.add_buffer1(buffer1[i]); + } + + if (buffer2_realsize > 0 && + buffer2 != NULL + ) + { + for (int i = 0; i < buffer2_realsize; i++) + invo_reply.add_buffer2(buffer2[i]); + } + + if (buffer3_realsize > 0 && + buffer3 != NULL + ) + { + for (int i = 0; i < buffer3_realsize; i++) + invo_reply.add_buffer3(buffer3[i]); + } + + if (buffer4_realsize > 0 && + buffer4 != NULL + ) + { + for (int i = 0; i < buffer4_realsize; i++) + invo_reply.add_buffer4(buffer4[i]); + } + status_ = FINISH; + gettimeofday(&end, NULL); + int64_t i64Time; + i64Time = (end.tv_sec - start.tv_sec) * 1000000 + + (end.tv_usec - start.tv_usec); + printf("gpp invokecommand used time: %ld us. \n", i64Time); + + invo_response.Finish(invo_reply, Status::OK, this); + } + }else + { + std::cout << "gpp receive no invokecommand jwtsvid or validate jwt failed" << std::endl; + flag = 2; + invo_reply.set_flag(flag); + status_ = FINISH; + + invo_response.Finish(invo_reply, Status::OK, this); + } + break; + } + + case ServerImpl::CallData::SS_TEECC_TA: + { + std::string token; + token = ta_chunk.token(); + std::int32_t flag = 0; + + std::string noToken("noToken"); + int ivaljwtResult = -1; + int iforceValidateJwt = global_force_valideta_jwt; + + if + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + ) + { + char Token[1024]; + strcpy(Token, (char *) token.data()); + ivaljwtResult = + dbusmethodcall_validate_jwt( + Token + ); + std::cout << "gpp validate deployta jwtsvid" << std::endl; + } else + { + std::cout << "gpp no validate deployta jwtsvid" << std::endl; + } + + if + ( + iforceValidateJwt != 1 + || + ( + iforceValidateJwt == 1 + && + token.compare(noToken) != 0 + && + ivaljwtResult == NO_ERROR + ) + ) + { + std::cout << "gpp does not need validate deployta jwtsvid or validate jwt succed" << std::endl; + std::cout << "gpp received deployta " << std::endl; + + std::string remote_sha256 = ta_chunk.sha256(); + + std::string subdir = ta_chunk.subdir(); + + std::string name = ta_chunk.name(); + name = "/data/" + subdir + "/" + name; + const char *filename = name.data(); + + std::cout << "gpp deployta, full namepath: " << name << std::endl; + + if (access(name.c_str(), F_OK) != -1) + { + std::cout << "gpp deloyta: ta file exist" << std::endl; + + char *name_temp = const_cast(name.data()); + char local_sha256_temp[SHA256_LENTH]; + int iRet; + iRet = get_file_sha256((char *) name_temp, local_sha256_temp); + if (iRet != 0) + { + ta_reply.set_code(-2); + status_ = FINISH; + + ta_response.Finish(ta_reply, Status::OK, this); + } else + { + + char remote_sha256_temp[SHA256_LENTH + 1]; + strcpy(remote_sha256_temp, remote_sha256.c_str()); + + + + if (memcmp(local_sha256_temp, remote_sha256_temp, SHA256_LENTH) == 0) + { + std::cout << "gpp deloyta: sha256 vals are the same" << std::endl; + + status_ = FINISH; + ta_reply.set_code(0); + + ta_response.Finish(ta_reply, Status::OK, this); + } else + { + std::cout << "gpp deloyta: sha256 vals are different, replace " << filename + << std::endl; + + std::ofstream outfile; + outfile.open(filename, + std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); + + const char *data; + data = ta_chunk.buffer().c_str(); + outfile.write(data, ta_chunk.buffer().length()); + outfile.close(); + + status_ = FINISH; + ta_reply.set_code(0); + + ta_response.Finish(ta_reply, Status::OK, this); + } + + } + } else + { + std::string wholedir; + wholedir = "/data/" + subdir; + const char *charwholedir = wholedir.data(); + + std::cout << "gpp deployta, wholedir: " << wholedir << std::endl; + + struct stat st = {0}; + if (stat(charwholedir, &st) == -1) + { + std::cout << "gpp deployta, make a new dir " << wholedir << std::endl; + + int iResult; + iResult = mkdir(charwholedir, 0600); + + if (iResult != 0) + { + std::cout << "gpp deployta, make a new dir falied" << wholedir << std::endl; + } + } + + if (stat(charwholedir, &st) == 0) + { + std::cout << "gpp deloyta: write a new file " << filename << std::endl; + + std::ofstream outfile; + outfile.open(filename, std::ofstream::out | std::ofstream::trunc | std::ofstream::binary); + + const char *data; + data = ta_chunk.buffer().c_str(); + outfile.write(data, ta_chunk.buffer().length()); + outfile.close(); + + status_ = FINISH; + ta_reply.set_code(0); + + ta_response.Finish(ta_reply, Status::OK, this); + } else + { + ta_reply.set_code(-3); + status_ = FINISH; + + ta_response.Finish(ta_reply, Status::OK, this); + } + } + + }else + { + std::cout << "gpp receive no deployta jwtsvid or validate jwt failed" << std::endl; + ta_reply.set_code(-1); + ta_reply.set_flag(flag); + status_ = FINISH; + + ta_response.Finish(ta_reply, Status::OK, this); + } + + break; + } + + default: + break; + } + } else + { + GPR_ASSERT(status_ == FINISH); + delete this; + std::cout << std::endl; + } + } + + private: + gpp::AsyncService *service_; + ServerCompletionQueue *cq_; + ServerContext ctx_; + ServiceType s_type_; + Inicont_Request inicont_request; + Inicont_Reply inicont_reply; + ServerAsyncResponseWriter inicont_response; + Fincont_Request fincont_request; + Fincont_Reply fincont_reply; + ServerAsyncResponseWriter fincont_response; + Opes_Request opes_request; + Opes_Reply opes_reply; + ServerAsyncResponseWriter opes_response; + Close_Request close_request; + Close_Reply close_reply; + ServerAsyncResponseWriter close_response; + Invo_Request invo_request; + Invo_Reply invo_reply; + ServerAsyncResponseWriter invo_response; + TA_Chunk ta_chunk; + TA_Reply ta_reply; + ServerAsyncResponseWriter ta_response; + Setjwt_Request setjwt_request; + Setjwt_Reply setjwt_reply; + ServerAsyncResponseWriter setjwt_response; + + enum CallStatus + { + CREATE, PROCESS, CHECKCANCEL, FINISH + }; + CallStatus status_; + + pthread_mutex_t *mutex_workerrec_; + pthread_cond_t *cond_notbusy_; + wr_t *workerrec_; + }; + + void RunServer() + { + std::string server_address(gpproxy_address); + grpc::EnableDefaultHealthCheckService(true); + grpc::reflection::InitProtoReflectionServerBuilderPlugin(); + + + ServerBuilder builder; + builder.SetMaxReceiveMessageSize(50 * 1024 * 1024); + + std::cout << "gpproxy server key path = " << global_serverkey_path << std::endl; + std::cout << "gpproxy server cert path = " << global_servercert_path << std::endl; + std::cout << "gpproxy client ca cert path = " << global_clientcacert_path << std::endl; + + int igrpctls = grpc_tls; + switch (igrpctls) + { + case 0: + { + builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); + + break; + } + + case 1: + { + FILE *pipe; + char buffer[128]; + std::string result; + + std::string strcmd = "openssl rsa -in " + global_serverkey_path + " -out " + + global_serverkey_path + ".nopass"; + std::string nopass_serverkey_path = global_serverkey_path + ".nopass"; + + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + + + strcmd = "openssl rsa -in " + nopass_serverkey_path + " -check -noout"; + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + std::string keyok("RSA key ok\n"); + + if (result.compare(keyok) != 0) + { + std::cout << "gpp '" + global_serverkey_path + "' integrity is broken" << std::endl; + exit(1); + } + + std::string sigfile_path = global_strcfgfiletemp + "/.gpp/certs/msg.sig"; + std::string msgfile_path = global_strcfgfiletemp + "/.gpp/certs/msg.txt"; + strcmd = + "openssl dgst -sha256 -sign " + nopass_serverkey_path + " -out " + sigfile_path + " " + msgfile_path; + system(strcmd.c_str()); + // ${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + std::string pubkeyfile_path = global_strcfgfiletemp + "/.gpp/certs/server_pubkey.pem"; + strcmd = "openssl x509 -in " + global_servercert_path + " -pubkey -out " + pubkeyfile_path; + system(strcmd.c_str()); + + // ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt + strcmd = "openssl dgst -sha256 -verify " + pubkeyfile_path + " -signature " + sigfile_path + " " + + msgfile_path; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + std::string verifyok("Verified OK\n"); + if (result.compare(verifyok) != 0) + { + std::cout << "gpp '" + global_serverkey_path + "' is not matched with '" + global_servercert_path + "'" + << std::endl; + exit(1); + } + + std::string strdayseconds; + char *resulttemp; + const char slash[] = "\n"; + char *parresult; + std::string strparresult; + std::string willexpire("Certificate will expire"); + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_servercert_path + " -checkend " + strdayseconds; + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); +; + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "gpp '" << global_servercert_path << "' will expire in 7 days, please reget it" + << std::endl; + exit(1); + } + + auto serverkey = get_file_contents(nopass_serverkey_path); + strcmd = "rm -f " + global_serverkey_path + ".nopass"; + system(strcmd.c_str()); + strcmd = "rm -f " + pubkeyfile_path; + system(strcmd.c_str()); + strcmd = "rm -f " + sigfile_path; + system(strcmd.c_str()); + + auto servercert = get_file_contents(global_servercert_path); + grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp = { + serverkey.c_str(), servercert.c_str() + }; + + grpc::SslServerCredentialsOptions ssl_opts(GRPC_SSL_DONT_REQUEST_CLIENT_CERTIFICATE); + ssl_opts.pem_key_cert_pairs.push_back(pkcp); + std::shared_ptr creds; + creds = grpc::SslServerCredentials(ssl_opts); + + builder.AddListeningPort(server_address, creds); + + break; + } + + case 2: + { + FILE *pipe; + char buffer[128]; + std::string result; + + std::string strcmd = "openssl rsa -in " + global_serverkey_path + " -out " + + global_serverkey_path + ".nopass"; + std::string nopass_serverkey_path = global_serverkey_path + ".nopass"; + system(strcmd.c_str()); + + strcmd = "openssl rsa -in " + nopass_serverkey_path + " -check -noout"; + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + std::string keyok("RSA key ok\n"); + if (result.compare(keyok) != 0) + { + std::cout << "gpp '" + global_serverkey_path + "' integrity is broken" << std::endl; + exit(1); + } + + std::string sigfile_path = global_strcfgfiletemp + "/.gpp/certs/msg.sig"; + std::string msgfile_path = global_strcfgfiletemp + "/.gpp/certs/msg.txt"; + strcmd = + "openssl dgst -sha256 -sign " + nopass_serverkey_path + " -out " + sigfile_path + " " + msgfile_path; + system(strcmd.c_str()); + // ${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + std::string pubkeyfile_path = global_strcfgfiletemp + "/.gpp/certs/server_pubkey.pem"; + strcmd = "openssl x509 -in " + global_servercert_path + " -pubkey -out " + pubkeyfile_path; + system(strcmd.c_str()); + + // ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt + strcmd = "openssl dgst -sha256 -verify " + pubkeyfile_path + " -signature " + sigfile_path + " " + + msgfile_path; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + std::string verifyok("Verified OK\n"); + if (result.compare(verifyok) != 0) + { + std::cout << "gpp '" + global_serverkey_path + "' is not matched with '" + global_servercert_path + "'" + << std::endl; + exit(1); + } + + std::string strdayseconds; + char *resulttemp; + const char slash[] = "\n"; + char *parresult; + std::string strparresult; + std::string willexpire("Certificate will expire"); + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_servercert_path + " -checkend " + strdayseconds; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "gpp '" << global_servercert_path << "' will expire in 7 days, please reget it" + << std::endl; + exit(1); + } + + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_clientcacert_path + " -checkend " + strdayseconds; + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "gpp popen '" << strcmd << "' failed" << std::endl; + exit(1); + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "gpp '" << global_clientcacert_path << "' will expire in 7 days, please reget it" + << std::endl; + exit(1); + } + + auto serverkey = get_file_contents(nopass_serverkey_path); + strcmd = "rm -f " + global_serverkey_path + ".nopass"; + system(strcmd.c_str()); + strcmd = "rm -f " + pubkeyfile_path; + system(strcmd.c_str()); + strcmd = "rm -f " + sigfile_path; + system(strcmd.c_str()); + + auto servercert = get_file_contents(global_servercert_path); + auto clientcacert = get_file_contents(global_clientcacert_path); // for verifying clients + grpc::SslServerCredentialsOptions::PemKeyCertPair pkcp = { + serverkey.c_str(), servercert.c_str() + }; + + grpc::SslServerCredentialsOptions ssl_opts(GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY); + ssl_opts.pem_root_certs = clientcacert; + ssl_opts.pem_key_cert_pairs.push_back(pkcp); + std::shared_ptr creds; + creds = grpc::SslServerCredentials(ssl_opts); + + builder.AddListeningPort(server_address, creds); + + break; + } + + default: + { + builder.AddListeningPort(server_address, grpc::InsecureServerCredentials()); + } + } + + + // Register "service" as the instance through which we'll communicate with + // clients. In this case it corresponds to an *synchronous* service. + builder.RegisterService(&service_); + + for (int i = 0; i < global_max_num_thread; i++) + { + cq_.emplace_back(builder.AddCompletionQueue()); + } + server_ = builder.BuildAndStart(); + //Finally assemble the server. + std::cout << "gpproxy is listening on " << server_address << std::endl; + + server_threads_.emplace_back(std::thread( + [this] + { + this->session_timeout_process(&mutex_workerrec, workerrec); + } + )); + server_threads_.emplace_back(std::thread( + [this] + { + this->context_timeout_process(&mutex_workerrec, &cond_notbusy, workerrec); + } + )); + + for (unsigned int i = 0; i < global_max_num_thread; i++) + { + server_threads_.emplace_back(std::thread( + [this, i] + { + this->HandleRpcs(i); + })); + std::cout << "thread " << i << " created." << std::endl; + } + std::this_thread::sleep_until(std::chrono::time_point::max()); + } + + void HandleRpcs(int i) + { + new CallData(&service_, + cq_[i].get(), + ServerImpl::CallData::SS_TEECC_InitializeContext, + &mutex_workerrec, + &cond_notbusy, + workerrec); + new CallData(&service_, + cq_[i].get(), + ServerImpl::CallData::SS_TEECC_FinalizeContext, + &mutex_workerrec, &cond_notbusy, + workerrec); + new CallData(&service_, + cq_[i].get(), + ServerImpl::CallData::SS_TEECC_OpenSession, + &mutex_workerrec, + &cond_notbusy, + workerrec); + new CallData(&service_, + cq_[i].get(), + ServerImpl::CallData::SS_TEECC_CloseSession, + &mutex_workerrec, + &cond_notbusy, + workerrec); + new CallData(&service_, + cq_[i].get(), + ServerImpl::CallData::SS_TEECC_InvokeCommand, + &mutex_workerrec, + &cond_notbusy, + workerrec); + new CallData(&service_, + cq_[i].get(), + ServerImpl::CallData::SS_TEECC_TA, + &mutex_workerrec, + &cond_notbusy, + workerrec); + + new CallData(&service_, + cq_[i].get(), + ServerImpl::CallData::SS_TEECC_SetJwt, + &mutex_workerrec, + &cond_notbusy, + workerrec); + + void *tag; + bool ok; + + while (true) + { + GPR_ASSERT(cq_[i]->Next(&tag, &ok)); + std::cout << "gpp thread[" << i << "], cq_[" << i << "]" + << std::endl; + + static_cast(tag)->Process(); + } + } + + void + session_timeout_process( + pthread_mutex_t *mutex_workerrec, + wr_t *workerrec + ) + { + struct timeval tv; + uint64_t u64time; + + char workername[1024]; + memset((char *) workername, 0, 1024); + int iworker; + + uint32_t in_session_seesionid; + uint32_t in_session_serviceid_timelow = 0; + uint32_t in_session_serviceid_timemid = 0; + uint32_t in_session_serviceid_timehiandver = 0; + uint32_t in_session_serviceid_clockseqandnode_size = 8; + uint32_t in_session_serviceid_clockseqandnode[8]; + uint32_t in_session_opscnt = 0; + uint64_t in_session_head_next = 0; + uint64_t in_session_head_prev = 0; + uint64_t in_session_context; + + uint32_t seesionid; + uint32_t serviceid_timelow; + uint32_t serviceid_timemid; + uint32_t serviceid_timehiandver; + uint32_t *serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + uint32_t opscnt; + uint64_t head_next; + uint64_t head_prev; + uint64_t session_context; + + sin_t *sinIns; + + while (1) + { + sleep(global_timeout_session); + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < global_max_num_worker; iworker++) + { + if (workerrec[iworker].busy == 1) + { + sinIns = NULL; + if (workerrec[iworker].first != NULL) + { + sinIns = workerrec[iworker].first; + do + { + gettimeofday(&tv, NULL); + u64time = (long unsigned int) (tv.tv_sec - + sinIns->session_createtime.tv_sec + ); + sin_t *sinTemp = NULL; + + if (u64time > global_timeout_session) + { + sprintf(workername, "%s%d", "gpworker", iworker); + + in_session_seesionid = sinIns->session_id; + in_session_context = workerrec[iworker].context_addr; + + for (int iind = 0; iind < 8; iind++) + { + in_session_serviceid_clockseqandnode[iind] = 0; + } + + pthread_mutex_unlock(mutex_workerrec); + + uint32_t serviceid_clockseqandnode_outsize_temp; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + + printf("\ngpp method call teec closesession for timeout process \n"); + method_call_teec_closesession( + workername, + + in_session_seesionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + &seesionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &session_context + ); + + if (serviceid_clockseqandnode != NULL) + { + free(serviceid_clockseqandnode); + } + + pthread_mutex_lock(mutex_workerrec); + + sinTemp = sinIns->prev; + if (sinTemp != NULL) + { + sinTemp->next = sinIns->next; + } + sinTemp = sinIns->next; + if (sinTemp != NULL) + { + sinTemp->prev = sinIns->prev; + } + if (workerrec[iworker].last == sinIns) + { + workerrec[iworker].last = sinIns->prev; + } + if (workerrec[iworker].first == sinIns) + { + workerrec[iworker].first = sinIns->next; + } + + sinTemp = sinIns; + workerrec[iworker].sessionid_count = + workerrec[iworker].sessionid_count - 1; + + } // end of if timedout + sinIns = sinIns->next; + if (sinTemp != NULL) + { + free(sinTemp); + } + } while (sinIns != NULL); + + } // end of the first not null + } // end of the busy = 1 + } // end of the for iworker + pthread_mutex_unlock(mutex_workerrec); + } // end of while 1 + // return NULL; + } + + void + context_timeout_process( + pthread_mutex_t *mutex_workerrec, + pthread_cond_t *cond_notbusy, + wr_t *workerrec + ) + { + struct timeval tv; + uint64_t u64time; + + char workername[1024]; + memset((char *) workername, 0, 1024); + int iworker; + + int32_t in_fd; + unsigned char *in_ta_path = NULL; + int32_t in_ta_path_size = 0; + uint64_t in_session_list_next = 0; + uint64_t in_session_list_prev = 0; + uint64_t in_shrd_mem_list_next = 0; + uint64_t in_shrd_mem_list_prev = 0; + uint64_t in_share_buffer_buffer = 0; + int64_t in_share_buffer_buffer_barrier = 0; + uint64_t in_context_addr; + + int32_t fd; + unsigned char *ta_path; + int32_t ta_path_size; + uint64_t session_list_next; + uint64_t session_list_prev; + uint64_t shrd_mem_list_next; + uint64_t shrd_mem_list_prev; + uint64_t share_buffer_buffer; + int64_t share_buffer_buffer_barrier; + uint32_t context_tapath_outsize; + + while (1) + { + sleep(global_timeout_context); + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < global_max_num_worker; iworker++) + { + if (workerrec[iworker].busy == 1) + { + sprintf(workername, "%s%d", "gpworker", iworker); + gettimeofday(&tv, NULL); + u64time = (long unsigned int) (tv.tv_sec - + workerrec[iworker].context_createtime.tv_sec + ); + + if (u64time > global_timeout_context + && + workerrec[iworker].sessionid_count == 0 + ) + { + in_fd = workerrec[iworker].context_fd; + in_context_addr = workerrec[iworker].context_addr; + ta_path = (unsigned char *) malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *) ta_path, 0, 1024); + + pthread_mutex_unlock(mutex_workerrec); + + printf("\ngpp method call teec finalizecontext for timeout process \n"); + method_call_teec_fincont( + workername, + + in_fd, + in_ta_path, + in_ta_path_size, + in_session_list_next, + in_session_list_prev, + in_shrd_mem_list_next, + in_shrd_mem_list_prev, + in_share_buffer_buffer, + in_share_buffer_buffer_barrier, + in_context_addr, + + &fd, + ta_path, + ta_path_size, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + + &context_tapath_outsize + ); + + if (ta_path != NULL) + { + free(ta_path); + } + + pthread_mutex_lock(mutex_workerrec); + + workerrec[iworker].busy = 0; + pthread_cond_signal(cond_notbusy); + workerrec[iworker].context_fd = 0; + workerrec[iworker].context_addr = 0xffffffff; + workerrec[iworker].sessionid_count = 0; + sin_t *sinIns; + sin_t *sinInsPrev; + sinIns = workerrec[iworker].last; + if (sinIns != NULL) + { + for (;;) + { + sinInsPrev = sinIns->prev; + free(sinIns); + sinIns = sinInsPrev; + if (sinIns == NULL) + { + break; + } + } + } + + } // end of the if timeed out + } // end of the if busy = 1 + } // end of the for iworker + pthread_mutex_unlock(mutex_workerrec); + + } // end of while 1 + } + +private: + std::vector > cq_; + gpp::AsyncService service_; + std::unique_ptr server_; + std::vector server_threads_; + + pthread_mutex_t mutex_workerrec; + pthread_cond_t cond_notbusy; + wr_t *workerrec = new wr_t[global_max_num_worker]; +}; + + +int main(int argc, char **argv) +{ + std::cout << "gpproxy glo_config file = " << global_strcfgfile << std::endl; + check_config(); + ServerImpl server; + + server.RunServer(); + + return 0; +} diff --git a/teeproxy/gpproxy/gpproxy.h b/teeproxy/gpproxy/gpproxy.h new file mode 100644 index 0000000000000000000000000000000000000000..18fe311c59b34bc898767633bdb96b1159a237ac --- /dev/null +++ b/teeproxy/gpproxy/gpproxy.h @@ -0,0 +1,21 @@ +#ifndef _GPPROXY_H +#define _GPPROXY_H +typedef struct sessionid_node +{ + uint32_t session_id; + struct timeval session_createtime; + struct sessionid_node *next; + struct sessionid_node *prev; +} sin_t; + +typedef struct worker_rec +{ + uint8_t busy; + int32_t context_fd; + uint64_t context_addr; + struct timeval context_createtime; + int sessionid_count; + sin_t *first; + sin_t *last; +} wr_t; +#endif // _GPPROXY_H diff --git a/teeproxy/gpproxy/protos/gt.proto b/teeproxy/gpproxy/protos/gt.proto new file mode 100644 index 0000000000000000000000000000000000000000..3eeff06dea0dec6e6c5445cd3957bcb5d7c6a069 --- /dev/null +++ b/teeproxy/gpproxy/protos/gt.proto @@ -0,0 +1,392 @@ +// + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.gt"; +option java_outer_classname = "gtProto"; +option objc_class_prefix = "HLW"; + +package gt; + +// The gpp service definition. +service gpp { + rpc TEECC_InitializeContext (Inicont_Request) returns (Inicont_Reply) {} + rpc TEECC_FinalizeContext (Fincont_Request) returns (Fincont_Reply) {} + rpc TEECC_OpenSession (Opes_Request) returns (Opes_Reply) {} + rpc TEECC_InvokeCommand (Invo_Request) returns (Invo_Reply) {} + rpc TEECC_CloseSession (Close_Request) returns (Close_Reply) {} + rpc TEECC_TA(TA_Chunk) returns (TA_Reply) {} + rpc TEECC_SetJwt(Setjwt_Request) returns (Setjwt_Reply) {} +} + + +message Inicont_Request { + uint64 name_size = 1; + string name = 2; + string token = 3; + string taname = 4; +} + +message Inicont_Reply { + uint32 teecresult = 1; + int32 context_fd = 2; + uint64 context_tapath_outsize = 3; + bytes context_tapath = 4; + uint64 context_sessionlist_next = 5; + uint64 context_sessionlist_prev = 6; + uint64 context_shrdmemlist_next = 7; + uint64 context_shrdmemlist_prev = 8; + uint64 context_sharebuffer_buffer = 9; + int64 context_sharebuffer_bufferbarrier = 10; + uint64 context_addr = 11; + int32 flag = 12; +} + +message Fincont_Request { + int32 in_context_fd = 1; + uint64 in_context_tapath_size= 2; + bytes in_context_tapath = 3; + uint64 in_context_sessionlist_next = 4; + uint64 in_context_sessionlist_prev = 5; + uint64 in_context_shrdmemlist_next = 6; + uint64 in_context_shrdmemlist_prev = 7; + uint64 in_context_sharebuffer_buffer = 8; + int64 in_context_sharebuffer_bufferbarrier = 9; + uint64 in_context_addr = 10; + string token = 11; + string taname = 12; +} + +message Fincont_Reply { + int32 context_fd = 1; + uint64 context_tapath_outsize = 2; + bytes context_tapath = 3; + uint64 context_sessionlist_next = 4; + uint64 context_sessionlist_prev = 5; + uint64 context_shrdmemlist_next = 6; + uint64 context_shrdmemlist_prev = 7; + uint64 context_sharebuffer_buffer = 8; + int64 context_sharebuffer_bufferbarrier = 9; + uint64 context_addr = 10; + int32 flag = 11; +} + +message Opes_Request { + int32 in_context_fd = 1; + uint64 in_context_tapath_size= 2; + bytes in_context_tapath = 3; + uint64 in_context_sessionlist_next = 4; + uint64 in_context_sessionlist_prev = 5; + uint64 in_context_shrdmemlist_next = 6; + uint64 in_context_shrdmemlist_prev = 7; + uint64 in_context_sharebuffer_buffer = 8; + int64 in_context_sharebuffer_bufferbarrier = 9; + uint32 in_destination_timelow = 10; + uint32 in_destination_timemid = 11; + uint32 in_destination_timehiandver = 12; + uint64 in_destination_cad_size = 13; + repeated uint32 in_destination_clockseqandnode = 14; + uint32 in_connectionmethod = 15; + uint64 in_connectiondata = 16; + uint32 in_operation_started = 17; + uint32 in_operation_paramtypes = 18; + uint64 in_operation_param1_tmpref_buffer = 19; + uint32 in_operation_param1_tmpref_size = 20; + uint64 in_operation_param1_memref_parent = 21; + uint32 in_operation_param1_memref_size = 22; + uint32 in_operation_param1_memref_offset = 23; + uint32 in_operation_param1_value_a = 24; + uint32 in_operation_param1_value_b = 25; + int32 in_operation_param1_ionref_ionsharefd = 26; + uint32 in_operation_param1_ionref_ionsize = 27; + uint64 in_operation_param2_tmpref_buffer = 28; + uint32 in_operation_param2_tmpref_size = 29; + uint64 in_operation_param2_memref_parent = 30; + uint32 in_operation_param2_memref_size = 31; + uint32 in_operation_param2_memref_offset = 32; + uint32 in_operation_param2_value_a = 33; + uint32 in_operation_param2_value_b = 34; + int32 in_operation_param2_ionref_ionsharefd = 35; + uint32 in_operation_param2_ionref_ionsize = 36; + uint64 in_operation_param3_tmpref_buffer = 37; + uint32 in_operation_param3_tmpref_size = 38; + uint64 in_operation_param3_memref_parent = 39; + uint32 in_operation_param3_memref_size = 40; + uint32 in_operation_param3_memref_offset = 41; + uint32 in_operation_param3_value_a = 42; + uint32 in_operation_param3_value_b = 43; + int32 in_operation_param3_ionref_ionsharefd = 44; + uint32 in_operation_param3_ionref_ionsize = 45; + uint64 in_operation_param4_tmpref_buffer = 46; + uint32 in_operation_param4_tmpref_size = 47; + uint64 in_operation_param4_memref_parent = 48; + uint32 in_operation_param4_memref_size = 49; + uint32 in_operation_param4_memref_offset = 50; + uint32 in_operation_param4_value_a = 51; + uint32 in_operation_param4_value_b = 52; + int32 in_operation_param4_ionref_ionsharefd = 53; + uint32 in_operation_param4_ionref_ionsize = 54; + uint64 in_operation_session = 55; + int32 in_operation_cancelflag = 56; + uint32 in_returnorigin = 57; + uint64 in_context_addr = 58; + string token = 59; + string taname = 60; +} + +message Opes_Reply { + uint32 teecresult = 1; + int32 context_fd = 2; + bytes context_tapath = 3 ; + uint64 context_tapath_outsize = 4; + uint64 context_sessionlist_next = 5; + uint64 context_sessionlist_prev = 6; + uint64 context_shrdmemlist_next = 7; + uint64 context_shrdmemlist_prev = 8; + uint64 context_sharebuffer_buffer = 9; + int64 context_sharebuffer_bufferbarrier = 10; + uint32 session_sessionid = 11; + uint32 session_serviceid_timelow = 12; + uint32 session_serviceid_timemid = 13; + uint32 session_serviceid_timehiandver = 14; + uint64 session_serviceid_clockseqandnode_outsize = 15; + repeated uint32 session_serviceid_clockseqandnode = 16; + uint32 session_opscnt = 17; + uint64 session_head_next = 18; + uint64 session_head_prev = 19; + uint64 session_context = 20; + uint32 operation_started = 21; + uint32 operation_paramtypes = 22; + uint64 operation_param1_tmpref_buffer = 23; + uint32 operation_param1_tmpref_size = 24; + uint64 operation_param1_memref_parent = 25; + uint32 operation_param1_memref_size = 26; + uint32 operation_param1_memref_offset = 27; + uint32 operation_param1_value_a = 28; + uint32 operation_param1_value_b = 29; + int32 operation_param1_ionref_ionsharefd = 30; + uint32 operation_param1_ionref_ionsize = 31; + uint64 operation_param2_tmpref_buffer = 32; + uint32 operation_param2_tmpref_size = 33; + uint64 operation_param2_memref_parent = 34; + uint32 operation_param2_memref_size = 35; + uint32 operation_param2_memref_offset = 36; + uint32 operation_param2_value_a = 37; + uint32 operation_param2_value_b = 38; + int32 operation_param2_ionref_ionsharefd = 39; + uint32 operation_param2_ionref_ionsize = 40; + uint64 operation_param3_tmpref_buffer = 41; + uint32 operation_param3_tmpref_size = 42; + uint64 operation_param3_memref_parent = 43; + uint32 operation_param3_memref_size = 44; + uint32 operation_param3_memref_offset = 45; + uint32 operation_param3_value_a = 46; + uint32 operation_param3_value_b = 47; + int32 operation_param3_ionref_ionsharefd = 48; + uint32 operation_param3_ionref_ionsize = 49; + uint64 operation_param4_tmpref_buffer = 50; + uint32 operation_param4_tmpref_size = 51; + uint64 operation_param4_memref_parent = 52; + uint32 operation_param4_memref_size = 53; + uint32 operation_param4_memref_offset = 54; + uint32 operation_param4_value_a = 55; + uint32 operation_param4_value_b = 56; + int32 operation_param4_ionref_ionsharefd = 57; + uint32 operation_param4_ionref_ionsize = 58; + uint64 operation_session = 59; + int32 operation_cancelflag = 60; + uint32 returnorigin = 61; + int32 flag = 62; +} + +message Invo_Request { + uint32 in_session_sessionid = 1; + uint32 in_session_serviceid_timelow = 2; + uint32 in_session_serviceid_timemid = 3; + uint32 in_session_serviceid_timehiandver = 4; + uint64 in_session_serviceid_cad_size = 5; + repeated uint32 in_session_serviceid_clockseqandnode = 6; + uint32 in_session_opscnt = 7; + uint64 in_session_head_next = 8; + uint64 in_session_head_prev = 9; + uint64 in_session_context = 10; + uint32 in_commandid = 11; + uint32 in_operation_started = 12; + uint32 in_operation_paramtypes = 13; + uint64 in_operation_param1_tmpref_buffer = 14; + uint32 in_operation_param1_tmpref_size = 15; + uint64 in_operation_param1_memref_parent = 16; + uint32 in_operation_param1_memref_parent_flag = 17; + uint32 in_operation_param1_memref_size = 18; + uint32 in_operation_param1_memref_offset = 19; + uint32 in_operation_param1_value_a = 20; + uint32 in_operation_param1_value_b = 21; + int32 in_operation_param1_ionref_ionsharefd = 22; + uint32 in_operation_param1_ionref_ionsize = 23; + uint64 in_operation_param2_tmpref_buffer = 24; + uint32 in_operation_param2_tmpref_size = 25; + uint64 in_operation_param2_memref_parent = 26; + uint32 in_operation_param2_memref_parent_flag = 27; + uint32 in_operation_param2_memref_size = 28; + uint32 in_operation_param2_memref_offset = 29; + uint32 in_operation_param2_value_a = 30; + uint32 in_operation_param2_value_b = 31; + int32 in_operation_param2_ionref_ionsharefd = 32; + uint32 in_operation_param2_ionref_ionsize = 33; + uint64 in_operation_param3_tmpref_buffer = 34; + uint32 in_operation_param3_tmpref_size = 35; + uint64 in_operation_param3_memref_parent = 36; + uint32 in_operation_param3_memref_parent_flag = 37; + uint32 in_operation_param3_memref_size = 38; + uint32 in_operation_param3_memref_offset = 39; + uint32 in_operation_param3_value_a = 40; + uint32 in_operation_param3_value_b = 41; + int32 in_operation_param3_ionref_ionsharefd = 42; + uint32 in_operation_param3_ionref_ionsize = 43; + uint64 in_operation_param4_tmpref_buffer = 44; + uint32 in_operation_param4_tmpref_size = 45; + uint64 in_operation_param4_memref_parent = 46; + uint32 in_operation_param4_memref_parent_flag = 47; + uint32 in_operation_param4_memref_size = 48; + uint32 in_operation_param4_memref_offset = 49; + uint32 in_operation_param4_value_a = 50; + uint32 in_operation_param4_value_b = 51; + int32 in_operation_param4_ionref_ionsharefd = 52; + uint32 in_operation_param4_ionref_ionsize = 53; + uint64 in_operation_session = 54; + int32 in_operation_cancelflag = 55; + uint32 in_returnorigin = 56; + uint64 in_bufer1_size = 57; + repeated uint32 in_buffer1 = 58; + uint64 in_bufer2_size = 59; + repeated uint32 in_buffer2 = 60; + uint64 in_bufer3_size = 61; + repeated uint32 in_buffer3 = 62; + uint64 in_bufer4_size = 63; + repeated uint32 in_buffer4 = 64; + string token = 65; + string taname = 66; +} + +message Invo_Reply { + uint32 teecresult = 1; + uint32 session_sessionid = 2; + uint32 session_serviceid_timelow = 3; + uint32 session_serviceid_timemid = 4; + uint32 session_serviceid_timehiandver = 5; + uint64 session_serviceid_clockseqandnode_outsize = 6; + repeated uint32 session_serviceid_clockseqandnode = 7; + uint32 session_opscnt = 8; + uint64 session_head_next = 9; + uint64 session_head_prev = 10; + uint64 session_context = 11; + uint32 operation_started = 12; + uint32 operation_paramtypes = 13; + uint64 operation_param1_tmpref_buffer = 14; + uint32 operation_param1_tmpref_size = 15; + uint64 operation_param1_memref_parent = 16; + uint32 operation_param1_memref_parent_flag = 17; + uint32 operation_param1_memref_size = 18; + uint32 operation_param1_memref_offset = 19; + uint32 operation_param1_value_a = 20; + uint32 operation_param1_value_b = 21; + int32 operation_param1_ionref_ionsharefd = 22; + uint32 operation_param1_ionref_ionsize = 23; + uint64 operation_param2_tmpref_buffer = 24; + uint32 operation_param2_tmpref_size = 25; + uint64 operation_param2_memref_parent = 26; + uint32 operation_param2_memref_parent_flag = 27; + uint32 operation_param2_memref_size = 28; + uint32 operation_param2_memref_offset = 29; + uint32 operation_param2_value_a = 30; + uint32 operation_param2_value_b = 31; + int32 operation_param2_ionref_ionsharefd = 32; + uint32 operation_param2_ionref_ionsize = 33; + uint64 operation_param3_tmpref_buffer = 34; + uint32 operation_param3_tmpref_size = 35; + uint64 operation_param3_memref_parent = 36; + uint32 operation_param3_memref_parent_flag = 37; + uint32 operation_param3_memref_size = 38; + uint32 operation_param3_memref_offset = 39; + uint32 operation_param3_value_a = 40; + uint32 operation_param3_value_b = 41; + int32 operation_param3_ionref_ionsharefd = 42; + uint32 operation_param3_ionref_ionsize = 43; + uint64 operation_param4_tmpref_buffer = 44; + uint32 operation_param4_tmpref_size = 45; + uint64 operation_param4_memref_parent = 46; + uint32 operation_param4_memref_parent_flag = 47; + uint32 operation_param4_memref_size = 48; + uint32 operation_param4_memref_offset = 49; + uint32 operation_param4_value_a = 50; + uint32 operation_param4_value_b = 51; + int32 operation_param4_ionref_ionsharefd = 52; + uint32 operation_param4_ionref_ionsize = 53; + uint64 operation_session = 54; + int32 operation_cancelflag = 55; + uint32 returnorigin = 56; + + uint64 buffer1_outsize = 57; + uint64 buffer2_outsize = 58; + uint64 buffer3_outsize = 59; + uint64 buffer4_outsize = 60; + + repeated uint32 buffer1 = 61; + repeated uint32 buffer2 = 62; + repeated uint32 buffer3 = 63; + repeated uint32 buffer4 = 64; + int32 flag = 65; +} + +message Close_Request { + uint32 in_session_sessionid = 1; + uint32 in_session_serviceid_timelow = 2; + uint32 in_session_serviceid_timemid = 3; + uint32 in_session_serviceid_timehiandver = 4; + uint64 in_session_serviceid_cad_size = 5; + repeated uint32 in_session_serviceid_clockseqandnode = 6; + uint32 in_session_opscnt = 7; + uint64 in_session_head_next = 8; + uint64 in_session_head_prev = 9; + uint64 in_session_context = 10; + string token = 11; + string taname = 12; +} + +message Close_Reply { + uint32 session_sessionid = 1; + uint32 session_serviceid_timelow = 2; + uint32 session_serviceid_timemid = 3; + uint32 session_serviceid_timehiandver = 4; + uint64 session_serviceid_cad_outsize = 5; + repeated uint32 session_serviceid_clockseqandnode = 6; + uint32 session_opscnt = 7; + uint64 session_head_next = 8; + uint64 session_head_prev = 9; + uint64 session_context = 10; + int32 flag = 11; +} + +message TA_Chunk{ + string name = 1; + bytes buffer = 2; + string token = 3; + string taname = 4; + bytes sha256 = 5; + string subdir = 6; +} + +message TA_Reply{ + int32 code = 1; + int32 flag = 2; +} + +message Setjwt_Request{ + string taname = 1; + string token = 2; +} + +message Setjwt_Reply{ + int32 retcode = 1; +} diff --git a/teeproxy/gpworker/README b/teeproxy/gpworker/README new file mode 100644 index 0000000000000000000000000000000000000000..28ceb8717f49628e0d3524e0e964bf3b925e8444 --- /dev/null +++ b/teeproxy/gpworker/README @@ -0,0 +1,8 @@ +DBus IPC + +packages installed: +dbus +libdbus-1-3 +libdbus-1-dev +libdbus-glib-1-2 + diff --git a/teeproxy/gpworker/build/Makefile b/teeproxy/gpworker/build/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..45cd2121b9907610487b082cfccf8905c86fbf9b --- /dev/null +++ b/teeproxy/gpworker/build/Makefile @@ -0,0 +1,28 @@ +CUR_DIR=$(shell pwd) +iTrustee_SDK_PATH=${CUR_DIR}/../../../.. + +TARGET_APP := gpworker + +APP_SOURCES := ../gpworker.c ../threadpool.c ../condition.c ../tzcp_dbus.c + +# APP_SOURCES += $(iTrustee_SDK_PATH)/src/CA/cloud/libteec_adaptor.c + +APP_CFLAGS += -fstack-protector-strong -fPIC -g + +APP_CFLAGS += -I$(iTrustee_SDK_PATH)/include/CA -I$(iTrustee_SDK_PATH)/thirdparty/open_source/libboundscheck/include + +APP_CFLAGS += -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include + +APP_LDFLAGS += -ldl -lpthread -lboundscheck -lteec -lm + +APP_LDFLAGS += -z text -z now -z relro -z noexecstack -pie + +APP_LDFLAGS += `pkg-config --libs --cflags dbus-1` + +APP_OBJECTS := $(APP_SOURCES:.c=.o) +$(TARGET_APP): $(APP_SOURCES) + @$(CC) $(APP_CFLAGS) -o $@ $(APP_SOURCES) $(APP_LDFLAGS) +# aarch64-linux-gnu-gcc $(APP_CFLAGS) -o $@ $(APP_SOURCES) $(APP_LDFLAGS) + +clean: + rm -f *.o $(TARGET_APP) diff --git a/teeproxy/gpworker/build/r.sh b/teeproxy/gpworker/build/r.sh new file mode 100644 index 0000000000000000000000000000000000000000..5f02fd210a76d66b317ef2f41865d1b9bb60a32b --- /dev/null +++ b/teeproxy/gpworker/build/r.sh @@ -0,0 +1,7 @@ +#!bin/bash + +pkill gpworker +cp -r gpworker /vendor/bin/gpworker +rm -f *.log + +parallel -j 128 --ungroup /vendor/bin/gpworker gpworker{} ::: {0..127} diff --git a/teeproxy/gpworker/changelog.md b/teeproxy/gpworker/changelog.md new file mode 100644 index 0000000000000000000000000000000000000000..f66c4e154099ba0dd4245c0a51460aa71a4ad76e --- /dev/null +++ b/teeproxy/gpworker/changelog.md @@ -0,0 +1,7 @@ +# 更新日志 + +## [1.0.0] - 2022-10-11 + +### 新增 + +* 项目初始化,上传第一版 diff --git a/teeproxy/gpworker/condition.c b/teeproxy/gpworker/condition.c new file mode 100644 index 0000000000000000000000000000000000000000..cf135cc39dca1024c301742262933e501d092698 --- /dev/null +++ b/teeproxy/gpworker/condition.c @@ -0,0 +1,55 @@ +#include "condition.h" + +int condition_init(condition_t *cond) +{ + int status; + if ((status = pthread_mutex_init(&cond->pmutex, NULL))) + return status; + + if ((status = pthread_cond_init(&cond->pcond, NULL))) + return status; + + return 0; +} + +int condition_lock(condition_t *cond) +{ + return pthread_mutex_lock(&cond->pmutex); +} + +int condition_unlock(condition_t *cond) +{ + return pthread_mutex_unlock(&cond->pmutex); +} + +int condition_wait(condition_t *cond) +{ + return pthread_cond_wait(&cond->pcond, &cond->pmutex); +} + +int condition_timedwait(condition_t *cond, const struct timespec *abstime) +{ + return pthread_cond_timedwait(&cond->pcond, &cond->pmutex, abstime); +} + +int condition_signal(condition_t *cond) +{ + return pthread_cond_signal(&cond->pcond); +} + +int condition_broadcast(condition_t *cond) +{ + return pthread_cond_broadcast(&cond->pcond); +} + +int condition_destroy(condition_t *cond) +{ + int status; + if ((status = pthread_mutex_destroy(&cond->pmutex))) + return status; + + if ((status = pthread_cond_destroy(&cond->pcond))) + return status; + + return 0; +} diff --git a/teeproxy/gpworker/condition.h b/teeproxy/gpworker/condition.h new file mode 100644 index 0000000000000000000000000000000000000000..8c89945796dde985af7c795602815aad00af7671 --- /dev/null +++ b/teeproxy/gpworker/condition.h @@ -0,0 +1,28 @@ +#ifndef _CONDITION_H_ +#define _CONDITION_H_ + +#include + +typedef struct condition +{ + pthread_mutex_t pmutex; + pthread_cond_t pcond; +} condition_t; + +int condition_init(condition_t *cond); + +int condition_lock(condition_t *cond); + +int condition_unlock(condition_t *cond); + +int condition_wait(condition_t *cond); + +int condition_timedwait(condition_t *cond, const struct timespec *abstime); + +int condition_signal(condition_t *cond); + +int condition_broadcast(condition_t *cond); + +int condition_destroy(condition_t *cond); + +#endif /* _CONDITION_H_ */ diff --git a/teeproxy/gpworker/gpworker.c b/teeproxy/gpworker/gpworker.c new file mode 100644 index 0000000000000000000000000000000000000000..838a0f99c16029b0c76716b617819a76cea41142 --- /dev/null +++ b/teeproxy/gpworker/gpworker.c @@ -0,0 +1,50 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * Description: rsa-demo + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "tee_client_api.h" + +#include "tzcp_dbus.h" +#include "threadpool.h" + + +int main(int argc, char *argv[]) +{ + threadpool_t pool; + pthread_mutex_t mutex_tcl; + pthread_mutex_t mutex_tsl; + tcl_t tcl; + tsl_t tsl; + + if (argc < 2) + { + printf("There is no argument as a worker name. \n"); + return -1; + } + if (argc > 2) + { + printf("Only need one argument as a worker name. \n"); + return -1; + } + + receive_methodcall( + &pool, + &mutex_tcl, + &mutex_tsl, + &tcl, + &tsl, + argv[1] + ); + + return 0; +} diff --git a/teeproxy/gpworker/threadpool.c b/teeproxy/gpworker/threadpool.c new file mode 100644 index 0000000000000000000000000000000000000000..265d4b737c1bb5fcd33a0ecf79b118513cac5c69 --- /dev/null +++ b/teeproxy/gpworker/threadpool.c @@ -0,0 +1,155 @@ +#include "threadpool.h" +#include +#include +#include +#include +#include + + +void *thread_routine(void *arg) +{ + // struct timespec abstime; + int timeout; + printf("\n"); + printf("thread 0x%x is starting\n", (int) pthread_self()); + threadpool_t *pool = (threadpool_t *) arg; + while (1) + { + timeout = 0; + condition_lock(&pool->ready); + pool->idle++; + // 等待队列有任务到来或者线程池销毁通知 + while (pool->first == NULL && !pool->quit) + { + printf("thread 0x%x is waiting\n", (int) pthread_self()); + condition_wait(&pool->ready); + } + + // 等待到条件,处于工作状态 + pool->idle--; + + // 等待到任务 + if (pool->first != NULL) + { + // 从队头取出任务 + task_t *t = pool->first; + pool->first = t->next; + // 执行任务需要一定的时间,所以要先解锁,以便生产者进程 + // 能够往队列中添加任务,其它消费者线程能够进入等待任务 + condition_unlock(&pool->ready); + printf("thread 0x%x is working\n", (int) pthread_self()); + t->run(t->arg); + printf("\n"); + printf("thread 0x%x work done \n", (int) pthread_self()); + free(t); + condition_lock(&pool->ready); + } + // 如果等待到线程池销毁通知, 且任务都执行完毕 + if (pool->quit && pool->first == NULL) + { + pool->counter--; + if (pool->counter == 0) + condition_signal(&pool->ready); + + condition_unlock(&pool->ready); + // 跳出循环之前要记得解锁 + break; + } + + if (timeout && pool->first == NULL) + { + pool->counter--; + condition_unlock(&pool->ready); + // 跳出循环之前要记得解锁 + break; + } + condition_unlock(&pool->ready); + } + + printf("thread 0x%x is exting\n", (int) pthread_self()); + return NULL; + +} + + +// 初始化线程池 +void threadpool_init( + threadpool_t *pool, + int threads, + tcl_t *tcl, + tsl_t *tsl +) +{ + // 对线程池中的各个字段初始化 + condition_init(&pool->ready); + pool->first = NULL; + pool->last = NULL; + pool->counter = 0; + pool->idle = 0; + pool->max_threads = threads; + pool->quit = 0; + + tcl->first = NULL; + tcl->last = NULL; + tcl->count = 0; + + tsl->first = NULL; + tsl->last = NULL; + tsl->count = 0; +} + + +// 往线程池中添加任务 +void threadpool_add_task(threadpool_t *pool, void *(*run)(void *arg), void *arg) +{ + // 生成新任务 + task_t *newtask = (task_t *) malloc(sizeof(task_t)); + newtask->run = run; + newtask->arg = arg; + newtask->next = NULL; + + condition_lock(&pool->ready); + // 将任务添加到队列 + if (pool->first == NULL) + pool->first = newtask; + else + pool->last->next = newtask; + pool->last = newtask; + + // 如果有等待线程,则唤醒其中一个 + if (pool->idle > 0) + condition_signal(&pool->ready); + else if (pool->counter < pool->max_threads) + { + // 没有等待线程,并且当前线程数不超过最大线程数,则创建一个新线程 + pthread_t tid; + pthread_create(&tid, NULL, thread_routine, pool); + pool->counter++; + } + condition_unlock(&pool->ready); +} + + +// 销毁线程池 +void threadpool_destroy(threadpool_t *pool) +{ + if (pool->quit) + { + return; + } + condition_lock(&pool->ready); + pool->quit = 1; + if (pool->counter > 0) + { + if (pool->idle > 0) + condition_broadcast(&pool->ready); + + // 处于执行任务状态中的线程,不会收到广播 + // 线程池需要等待执行任务状态中的线程全部退出 + + while (pool->counter > 0) + condition_wait(&pool->ready); + } + condition_unlock(&pool->ready); + condition_destroy(&pool->ready); +} diff --git a/teeproxy/gpworker/threadpool.h b/teeproxy/gpworker/threadpool.h new file mode 100644 index 0000000000000000000000000000000000000000..f70b3d16012c1aa6b46b686ff9e373a89f448c37 --- /dev/null +++ b/teeproxy/gpworker/threadpool.h @@ -0,0 +1,108 @@ +#ifndef _THREAD_POOL_H_ +#define _THREAD_POOL_H_ + +#include "condition.h" + +#define GP_WORKER 3 + +#ifdef GP_WORKER + +#include "tee_client_api.h" +#include "tee_client_list.h" + +#endif + + + +#ifdef GP_PROXY +typedef struct sessionid_node +{ + uint32_t session_id; + struct timeval session_createtime; + struct sessionid_node * next; + struct sessionid_node * prev; +} sin_t; + +typedef struct worker_rec +{ + uint8_t busy; + int32_t context_fd; + uint64_t context_addr; + struct timeval context_createtime; + int sessionid_count; + sin_t * first; + sin_t * last; +} wr_t; +#endif + +#ifdef GP_WORKER +typedef struct teec_session_node +{ + TEEC_Session *self; + struct timeval createtime; + struct teec_session_node *next; + struct teec_session_node *prev; +} tsn_t; + +typedef struct teec_session_list +{ + int count; // 线程池中当前线程数 + tsn_t *first; + tsn_t *last; +} tsl_t; + +typedef struct teec_context_node +{ + TEEC_Context *self; + struct timeval createtime; + struct teec_context_node *next; + struct teec_context_node *prev; +} tcn_t; + +typedef struct teec_context_list +{ + int count; // 线程池中当前线程数 + tcn_t *first; + tcn_t *last; +} tcl_t; +#endif + + +// 任务结构体,将任务放入队列由线程池中的线程来执行 +typedef struct task +{ + void *(*run)(void *arg); // 任务回调函数 + void *arg; // 回调函数参数 + struct task *next; +} task_t; + +// 线程池结构体 +typedef struct threadpool +{ + condition_t ready; // mutex and condition var, 任务准备就绪或者线程池销毁通知 + task_t *first; // 任务队列头指针 + task_t *last; // 任务队列尾指针 + int counter; // 线程池中当前线程数 + int idle; // 线程池中当前正在等待任务的线程数 + int max_threads; // 线程池中最大允许的线程数 + int quit; // 销毁线程池的时候置1 +} threadpool_t; + +// 初始化线程池 +void threadpool_init( + threadpool_t *pool, + int threads +#ifdef GP_WORKER + , + tcl_t *tcl, + tsl_t *tsl +#endif +); + +// 往线程池中添加任务 +void threadpool_add_task(threadpool_t *pool, void *(*run)(void *arg), void *arg); + +// 销毁线程池 +void threadpool_destroy(threadpool_t *pool); + +#endif /* _THREAD_POOL_H_ */ diff --git a/teeproxy/gpworker/tzcp_dbus.c b/teeproxy/gpworker/tzcp_dbus.c new file mode 100644 index 0000000000000000000000000000000000000000..345ece193c20d47c3e9896c1898368f3ac21aab6 --- /dev/null +++ b/teeproxy/gpworker/tzcp_dbus.c @@ -0,0 +1,22889 @@ +/* + * Using low-level D-Bus C API code. + * Written by + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "tzcp_dbus.h" + +#ifdef GP_PROXY_WORKER + +#include "threadpool.h" + +#ifdef GP_WORKER + +#include "tee_client_api.h" +#include "tee_client_list.h" + +#endif +#endif + + +/** + * Listens for signals on the bus + */ +void +receive_signal(void) +{ + DBusMessage *msg; + DBusMessageIter args; + DBusConnection *conn; + DBusError err; + int ret; + char *sigvalue; + + printf("Listening for signals\n"); + + // initialise the errors + dbus_error_init(&err); + + // connect to the bus and check for errors + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + exit(1); + } + + // request our name on the bus and check for errors + ret = dbus_bus_request_name(conn, "test.signal.sink", DBUS_NAME_FLAG_REPLACE_EXISTING, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + exit(1); + } + + // add a rule for which messages we want to see + dbus_bus_add_match(conn, "type='signal',interface='test.signal.Type'", &err); + // see signals from the given interface + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Match Error (%s)\n", err.message); + exit(1); + } + // printf("Match rule sent\n"); + + // loop listening for signals being emmitted + while (true) + { + + // non blocking read of the next available message + dbus_connection_read_write(conn, 0); + msg = dbus_connection_pop_message(conn); + + // loop again if we haven't read a message + if (NULL == msg) + { + usleep(10000); + continue; + } + + // check if the message is a signal from the correct interface and with the correct name + if (dbus_message_is_signal(msg, "test.signal.Type", "Test")) + { + + // read the parameters + if (!dbus_message_iter_init(msg, &args)) + fprintf(stderr, "Message Has No Parameters\n"); + else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) + fprintf(stderr, "Argument is not string!\n"); + else + dbus_message_iter_get_basic(&args, &sigvalue); + + printf("Got Signal with value %s\n", sigvalue); + } + + // free the message + dbus_message_unref(msg); + } +} + + +/** + * Connect to the DBUS bus and send a broadcast signal + */ +void +send_signal( + char *sigvalue +) +{ + DBusMessage *msg; + DBusMessageIter args; + DBusConnection *conn; + DBusError err; + int ret; + dbus_uint32_t sigserial = 0; + + printf("Sending signal with value %s\n", sigvalue); + + // initialise the error value + dbus_error_init(&err); + + // connect to the DBUS system bus, and check for errors + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + exit(1); + } + + // register our name on the bus, and check for errors + ret = dbus_bus_request_name(conn, "test.signal.source", DBUS_NAME_FLAG_REPLACE_EXISTING, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + exit(1); + } + + // create a signal & check for errors + msg = dbus_message_new_signal("/test/signal/Object", // object name of the signal + "test.signal.Type", // interface name of the signal + "Test"); // name of the signal + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + exit(1); + } + + // append arguments onto signal + dbus_message_iter_init_append(msg, &args); + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &sigvalue)) + { + fprintf(stderr, "Out Of Memory!\n"); + exit(1); + } + + // send the message and flush the connection + if (!dbus_connection_send(conn, msg, &sigserial)) + { + fprintf(stderr, "Out Of Memory!\n"); + exit(1); + } + dbus_connection_flush(conn); + + printf("Signal Sent\n"); + + // free the message + dbus_message_unref(msg); +} + + +#ifdef GP_PROXY_WORKER + +/** + * Server that exposes a method call and waits for it to be called + */ +void +receive_methodcall( + threadpool_t *pool, + pthread_mutex_t *mutex_tcl, + pthread_mutex_t *mutex_tsl, + tcl_t *tcl, + tsl_t *tsl, + char *workername +) +{ + DBusMessage *msg; + DBusConnection *conn; + DBusError err; + int ret; + dbus_bool_t bResult; + + threadpool_init(pool, +#ifdef GP_PROXY + MAX_NUM_THREAD + 2 +#endif +#ifdef GP_WORKER + MAX_NUM_THREAD, tcl, tsl +#endif + ); + +#ifdef GP_WORKER + pthread_mutex_init(mutex_tcl, NULL); + pthread_mutex_init(mutex_tsl, NULL); +#endif + +#ifdef GP_PROXY + pthread_mutex_init(mutex_workerrec, NULL); + pthread_cond_init(cond_notbusy, NULL); + for (int iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + workerrec[iworker].busy = 0; + workerrec[iworker].context_fd = 0; + // workerrec[iworker].context_addr = 0; + workerrec[iworker].context_addr = 0xffffffff; + workerrec[iworker].sessionid_count = 0; + workerrec[iworker].first = NULL; + workerrec[iworker].last = NULL; + } + + DBusMsgConn* thdfargs_stp = (DBusMsgConn*)malloc(sizeof(DBusMsgConn)); + thdfargs_stp->mutex_workerrec = mutex_workerrec; + thdfargs_stp->workerrec = workerrec; + threadpool_add_task( + pool, + session_timeout_process, + thdfargs_stp + ); + + DBusMsgConn* thdfargs_ctp = (DBusMsgConn*)malloc(sizeof(DBusMsgConn)); + thdfargs_ctp->mutex_workerrec = mutex_workerrec; + thdfargs_ctp->workerrec = workerrec; + thdfargs_ctp->cond_notbusy = cond_notbusy; + threadpool_add_task( + pool, + context_timeout_process, + thdfargs_ctp + ); +#endif + + printf("%s is listening for method calls ... \n", workername); + + // initialise the error + dbus_error_init(&err); + + dbus_threads_init_default(); + + // connect to the bus and check for errors + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + // conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + fprintf(stderr, "Connection Null\n"); + exit(1); + } + + char dbusname[1024]; + memset((char *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + int64_t workernum = 0; + for (int iind = 0; iind < strlen(workername) - 6; iind++) + { + workernum = workernum + + (workername[strlen(workername) - 1 - iind] - '0') * pow(10, iind); +#if 0 + printf( + "workername[%d] = %c. \n", + strlen(workername) - 1 - iind, + workername[strlen(workername) - 1 - iind] + ); +#endif + } + // printf("The worker num is 0x %16.16lx. \n", workernum); + // request our name on the bus and check for errors + ret = + dbus_bus_request_name( + conn, + // "test.method.server", + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + fprintf(stderr, "Not Primary Owner (%d)\n", ret); + exit(1); + } + + // loop, testing for new messages + memset((char *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.Type", workername); + while (true) + { + // non blocking read of the next available message + dbus_connection_read_write(conn, 0); + msg = dbus_connection_pop_message(conn); + + // loop again if we haven't got a message + if (NULL == msg) + { + usleep(10000); + continue; + } + + // check this is a method call for the right interface & method + bResult = dbus_message_is_method_call( + msg, + // "test.method.Type", + dbusname, + "TEEC_InitializeContext" + ); + if (bResult == TRUE) + { + DBusMsgConn *thdfargs = (DBusMsgConn *) malloc(sizeof(DBusMsgConn)); + thdfargs->msg = msg; + thdfargs->conn = conn; +#ifdef GP_PROXY + thdfargs->mutex_workerrec = mutex_workerrec; + thdfargs->cond_notbusy = cond_notbusy; + thdfargs->workerrec = workerrec; +#endif +#ifdef GP_WORKER + thdfargs->workernum = workernum; + thdfargs->mutex_tcl = mutex_tcl; + thdfargs->mutex_tsl = mutex_tsl; + thdfargs->tcl = tcl; + thdfargs->tsl = tsl; +#endif + threadpool_add_task( + pool, + reply_to_method_call_teec_inicont, + thdfargs + ); + } + + // check this is a method call for the right interface & method + bResult = dbus_message_is_method_call( + msg, + // "test.method.Type", + dbusname, + "TEEC_FinalizeContext" + ); + if (bResult == TRUE) + { + DBusMsgConn *thdfargs = (DBusMsgConn *) malloc(sizeof(DBusMsgConn)); + thdfargs->msg = msg; + thdfargs->conn = conn; +#ifdef GP_PROXY + thdfargs->mutex_workerrec = mutex_workerrec; + thdfargs->cond_notbusy = cond_notbusy; + thdfargs->workerrec = workerrec; +#endif +#ifdef GP_WORKER + thdfargs->workernum = workernum; + thdfargs->mutex_tcl = mutex_tcl; + thdfargs->mutex_tsl = mutex_tsl; + thdfargs->tcl = tcl; + thdfargs->tsl = tsl; +#endif + threadpool_add_task( + pool, + reply_to_method_call_teec_fincont, + thdfargs + ); + } + + // check this is a method call for the right interface & method + bResult = dbus_message_is_method_call( + msg, + // "test.method.Type", + dbusname, + "TEEC_OpenSession" + ); + if (bResult == TRUE) + { + DBusMsgConn *thdfargs = (DBusMsgConn *) malloc(sizeof(DBusMsgConn)); + thdfargs->msg = msg; + thdfargs->conn = conn; +#ifdef GP_PROXY + thdfargs->mutex_workerrec = mutex_workerrec; + thdfargs->cond_notbusy = cond_notbusy; + thdfargs->workerrec = workerrec; +#endif +#ifdef GP_WORKER + thdfargs->workernum = workernum; + thdfargs->mutex_tcl = mutex_tcl; + thdfargs->mutex_tsl = mutex_tsl; + thdfargs->tcl = tcl; + thdfargs->tsl = tsl; +#endif + threadpool_add_task( + pool, + reply_to_method_call_teec_opensession, + thdfargs + ); + } + + // check this is a method call for the right interface & method + bResult = dbus_message_is_method_call( + msg, + // "test.method.Type", + dbusname, + "TEEC_CloseSession" + ); + if (bResult == TRUE) + { + DBusMsgConn *thdfargs = (DBusMsgConn *) malloc(sizeof(DBusMsgConn)); + thdfargs->msg = msg; + thdfargs->conn = conn; +#ifdef GP_PROXY + thdfargs->mutex_workerrec = mutex_workerrec; + thdfargs->cond_notbusy = cond_notbusy; + thdfargs->workerrec = workerrec; +#endif +#ifdef GP_WORKER + thdfargs->workernum = workernum; + thdfargs->mutex_tcl = mutex_tcl; + thdfargs->mutex_tsl = mutex_tsl; + thdfargs->tcl = tcl; + thdfargs->tsl = tsl; +#endif + threadpool_add_task( + pool, + reply_to_method_call_teec_closesession, + thdfargs + ); + } + + bResult = dbus_message_is_method_call( + msg, + // "test.method.Type", + dbusname, + "TEEC_InvokeCommand" + ); + if (bResult == TRUE) + { + DBusMsgConn *thdfargs = (DBusMsgConn *) malloc(sizeof(DBusMsgConn)); + thdfargs->msg = msg; + thdfargs->conn = conn; +#ifdef GP_PROXY + thdfargs->mutex_workerrec = mutex_workerrec; + thdfargs->cond_notbusy = cond_notbusy; + thdfargs->workerrec = workerrec; +#endif +#ifdef GP_WORKER + thdfargs->workernum = workernum; + thdfargs->mutex_tcl = mutex_tcl; + thdfargs->mutex_tsl = mutex_tsl; + thdfargs->tcl = tcl; + thdfargs->tsl = tsl; +#endif + threadpool_add_task( + pool, + reply_to_method_call_teec_invokecommand, + thdfargs + ); + } + + // check this is a method call for the right interface & method + bResult = dbus_message_is_method_call( + msg, + // "test.method.Type", + dbusname, + "Destroy" + ); + if (bResult == TRUE) + { + reply_to_method_call_destroy_threadpool( + msg, + conn, + pool +#ifdef GP_WORKER + , + mutex_tcl, + mutex_tsl +#endif + +#ifdef GP_PROXY + , + mutex_workerrec, + cond_notbusy +#endif + ); + } + + // free the message + // dbus_message_unref(msg); + + } // end of the while true +} // end of the function +#endif + + + +/** + * Call a method on a remote object + */ +int32_t +method_call_teec_inicont( + const char *workername, + + const uint8_t *name, size_t name_size, + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t *teecresult, + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint64_t *context_addr, + uint32_t *context_tapath_outsize +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + int ret; + int iType; + unsigned char *context_tapath_temp = NULL; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_int64_t di64Temp; + dbus_uint64_t dui64Temp; + + // initialiset the errors + dbus_error_init(&err); + + dbus_threads_init_default(); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + // conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_InitializeContext" // method name + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + di32Temp = name_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (name_size > 0 && name != NULL) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &name + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + di32Temp = in_context_fd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_context_tapath_size > 0 && + in_context_tapath != NULL && + strlen((const char *) in_context_tapath) > 0 + ) + { + if (dbus_validate_utf8((const char *) in_context_tapath, &err) == true) + { + di32Temp = strlen((const char *) in_context_tapath); + } else + { + di32Temp = 0; + } + } else + { + di32Temp = 0; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + // if (in_context_tapath_size > 0 && in_context_tapath != NULL) + if (di32Temp > 0) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &in_context_tapath + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + dui64Temp = in_context_sessionlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sessionlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sharebuffer_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di64Temp = in_context_sharebuffer_bufferbarrier; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &di64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Init Contex Sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + // free the pending message handle + dbus_pending_call_unref(pending); + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *teecresult = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *context_fd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *context_tapath_outsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + if (*context_tapath_outsize > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &context_tapath_temp); + + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sharebuffer_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di64Temp + ); + *context_sharebuffer_bufferbarrier = di64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_addr = dui64Temp; + + printf("Got Reply of Method Call Teec Init Contex: \n"); + printf(" teecresult = 0x %8.8x \n", *teecresult); + printf(" fd = 0x %8.8x \n", (unsigned int) *context_fd); + printf(" ta_path = %s \n", context_tapath_temp); + printf(" ta_path_size = %d \n", (int) *context_tapath_outsize); +#if 0 + printf(" TEEC_Context session_list.next = 0x %16.16lx \n", + *context_sessionlist_next + ); + printf(" TEEC_Context session_list.prev = 0x %16.16lx \n", + *context_sessionlist_prev + ); + printf(" TEEC_Context shrd_mem_list.next = 0x %16.16lx \n", + *context_shrdmemlist_next + ); + printf(" TEEC_Context shrd_mem_list.prev = 0x %16.16lx \n", + *context_shrdmemlist_prev + ); + printf(" TEEC_Context share_buffer.buffer = 0x %16.16lx \n", + *context_sharebuffer_buffer + ); + printf(" TEEC_Context share_buffer.buffer_barrier = 0x %16.16lx \n", + (long unsigned int)*context_sharebuffer_bufferbarrier + ); +#endif + printf(" context addr = 0x %16.16lx \n", + (long unsigned int) *context_addr + ); + + if ( + context_tapath_insize > *context_tapath_outsize && + *context_tapath_outsize > 0 && + context_tapath != NULL && + context_tapath_temp != NULL + ) + { + memcpy(context_tapath, context_tapath_temp, *context_tapath_outsize); + *(context_tapath + *context_tapath_outsize) = 0; + } else + { + // dbus_message_unref(msg); + // return -1; + *(context_tapath + 0) = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +/** + * Call a method on a remote object + */ +int32_t +method_call_teec_fincont( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + uint64_t in_context_addr, + + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint32_t *context_tapath_outsize +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + int ret; + int iType; + unsigned char *context_tapath_temp = NULL; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_int64_t di64Temp; + dbus_uint64_t dui64Temp; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_FinalizeContext" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + di32Temp = in_context_fd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_context_tapath_size > 0 && + in_context_tapath != NULL && + strlen((const char *) in_context_tapath) > 0 + ) + { + if (dbus_validate_utf8((const char *) in_context_tapath, &err) == true) + { + di32Temp = strlen((const char *) in_context_tapath); + } else + { + di32Temp = 0; + } + } else + { + di32Temp = 0; + } + + // fprintf(stderr, "in_context_tapath_size = %ld \n", in_context_tapath_size); + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + // if (in_context_tapath_size > 0 && in_context_tapath != NULL) + if (di32Temp > 0) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &in_context_tapath + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + dui64Temp = in_context_sessionlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sessionlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sharebuffer_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di64Temp = in_context_sharebuffer_bufferbarrier; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &di64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_addr; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Fin Contex Sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + // free the pending message handle + dbus_pending_call_unref(pending); + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *context_fd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *context_tapath_outsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + if (*context_tapath_outsize > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &context_tapath_temp); + + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sharebuffer_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di64Temp + ); + *context_sharebuffer_bufferbarrier = di64Temp; + + printf("Got Reply of Method Call Teec Fin Contex: \n"); + printf(" fd = 0x %8.8x \n", (unsigned int) *context_fd); + printf(" ta_path = %s \n", context_tapath_temp); + printf(" ta_path_size = %d \n", (int) *context_tapath_outsize); +#if 0 + printf(" TEEC_Context session_list.next = 0x %16.16lx \n", + *context_sessionlist_next + ); + printf(" TEEC_Context session_list.prev = 0x %16.16lx \n", + *context_sessionlist_prev + ); + printf(" TEEC_Context shrd_mem_list.next = 0x %16.16lx \n", + *context_shrdmemlist_next + ); + printf(" TEEC_Context shrd_mem_list.prev = 0x %16.16lx \n", + *context_shrdmemlist_prev + ); + printf(" TEEC_Context share_buffer.buffer = 0x %16.16lx \n", + *context_sharebuffer_buffer + ); + printf(" TEEC_Context share_buffer.buffer_barrier = 0x %16.16lx \n", + (long unsigned int)*context_sharebuffer_bufferbarrier + ); +#endif + + if ( + context_tapath_insize > *context_tapath_outsize && + *context_tapath_outsize > 0 && + context_tapath != NULL && + context_tapath_temp != NULL + ) + { + memcpy(context_tapath, context_tapath_temp, *context_tapath_outsize); + *(context_tapath + *context_tapath_outsize) = 0; + } else + { + // dbus_message_unref(msg); + // return -1; + *(context_tapath + 0) = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +/** + * Call a method on a remote object + */ +int32_t +method_call_teec_opensession( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, + size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t in_destination_timelow, + uint32_t in_destination_timemid, + uint32_t in_destination_timehiandver, + uint32_t *in_destination_clockseqandnode, + int32_t in_destination_clockseqandnode_size, + + uint32_t in_connectionmethod, + uint64_t in_connectiondata, + + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint64_t in_context_addr, + + + uint32_t *teecresult, + + int32_t *context_fd, + uint8_t *context_tapath, + size_t context_tapath_size, + uint32_t *context_tapath_outsize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int ret; + int iType; + unsigned char *context_tapath_temp = NULL; + dbus_uint32_t *session_serviceid_clockseqandnode_temp = NULL; + int session_serviceid_clockseqandnode_realsize; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_int64_t di64Temp; + dbus_uint64_t dui64Temp; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_OpenSession" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + di32Temp = in_context_fd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_context_tapath_size > 0 && + in_context_tapath != NULL && + strlen((const char *) in_context_tapath) > 0 + ) + { + if (dbus_validate_utf8((const char *) in_context_tapath, &err) == true) + { + di32Temp = strlen((const char *) in_context_tapath); + } else + { + di32Temp = 0; + } + } else + { + di32Temp = 0; + } + + // fprintf(stderr, "in_context_tapath_size = %ld \n", in_context_tapath_size); + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + // if (in_context_tapath_size > 0 && in_context_tapath != NULL) + if (di32Temp > 0) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &in_context_tapath + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + dui64Temp = in_context_sessionlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sessionlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sharebuffer_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di64Temp = in_context_sharebuffer_bufferbarrier; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &di64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_destination_timelow; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_destination_timemid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_destination_timehiandver; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_destination_clockseqandnode_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_destination_clockseqandnode_size > 0 && + in_destination_clockseqandnode != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_destination_clockseqandnode, + in_destination_clockseqandnode_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_connectionmethod; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_connectiondata; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui32Temp = in_operation_started; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_paramtypes; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param1_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param2_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param3_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param4_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_session; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_cancelflag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_returnorigin; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_addr; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + /////////////////////////////////////////////////////////////////// + + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Open Session Sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + + // free the pending message handle + dbus_pending_call_unref(pending); + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *teecresult = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *context_fd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *context_tapath_outsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + if (*context_tapath_outsize > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &context_tapath_temp); + + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sharebuffer_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di64Temp + ); + *context_sharebuffer_bufferbarrier = di64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_seesionid = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timelow = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timemid = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timehiandver = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_clockseqandnode_outsize = dui32Temp; + + if (*session_serviceid_clockseqandnode_outsize > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &session_serviceid_clockseqandnode_temp, + &session_serviceid_clockseqandnode_realsize + ); + } + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_opscnt = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_context = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_started = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_paramtypes = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param1_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param2_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param3_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param4_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_session = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_cancelflag = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *returnorigin = dui32Temp; + + printf("Got Reply of Method Call Teec Open Session: \n"); + printf(" teecresult = 0x %8.8x \n", *teecresult); + printf(" fd = 0x %8.8x \n", (unsigned int) *context_fd); + printf(" ta_path = %s \n", context_tapath_temp); + printf(" ta_path_size = %d \n", (int) *context_tapath_outsize); + printf(" session_seesionid = 0x %8.8x \n", + *session_seesionid + ); +#if 0 + printf(" TEEC_Context session_list.next = 0x %16.16lx \n", + *context_sessionlist_next + ); + printf(" TEEC_Context session_list.prev = 0x %16.16lx \n", + *context_sessionlist_prev + ); + printf(" TEEC_Context shrd_mem_list.next = 0x %16.16lx \n", + *context_shrdmemlist_next + ); + printf(" TEEC_Context shrd_mem_list.prev = 0x %16.16lx \n", + *context_shrdmemlist_prev + ); + printf(" TEEC_Context share_buffer.buffer = 0x %16.16lx \n", + *context_sharebuffer_buffer + ); + printf(" TEEC_Context share_buffer.buffer_barrier = 0x %16.16lx \n", + (long unsigned int)*context_sharebuffer_bufferbarrier + ); + + printf(" TEEC_Session session_serviceid_timelow = 0x %8.8x \n", + *session_serviceid_timelow + ); + printf(" TEEC_Session session_serviceid_timehiandver = 0x %8.8x \n", + *session_serviceid_timehiandver + ); + + printf(" TEEC_Session session_serviceid_clockseqandnode = \n"); + if (*session_serviceid_clockseqandnode_outsize > 0 && + session_serviceid_clockseqandnode_temp != NULL) + { + printf(" "); + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", + session_serviceid_clockseqandnode_temp[i] + ); + } + printf("\n"); + } + printf(" TEEC_Session clockseqandnode_outsize = 0x %8.8x \n", + *session_serviceid_clockseqandnode_outsize + ); + + printf(" TEEC_Session session_opscnt = 0x %8.8x \n", + *session_opscnt + ); + printf(" TEEC_Session session_head_next = 0x %16.16lx \n", + *session_head_next + ); + printf(" TEEC_Session session_head_prev = 0x %16.16lx \n", + *session_head_prev + ); + printf(" TEEC_Session session_context = 0x %16.16lx \n", + *session_context + ); + printf(" TEEC_Session operation_started = 0x %8.8x \n", + *operation_started + ); + printf(" TEEC_Session operation_paramtypes = 0x %8.8x \n", + *operation_paramtypes + ); + + printf(" TEEC_Session operation_param1_tmpref_buffer = 0x %16.16lx \n", + *operation_param1_tmpref_buffer + ); + printf(" TEEC_Session operation_param1_tmpref_size = 0x %8.8x \n", + *operation_param1_tmpref_size + ); + printf(" TEEC_Session operation_param1_memref_parent = 0x %16.16lx \n", + *operation_param1_memref_parent + ); + printf(" TEEC_Session operation_param1_memref_size = 0x %8.8x \n", + *operation_param1_memref_size + ); + printf(" TEEC_Session operation_param1_memref_offse = 0x %8.8x \n", + *operation_param1_memref_offset + ); + printf(" TEEC_Session operation_param1_value_a = 0x %8.8x \n", + *operation_param1_value_a + ); + printf(" TEEC_Session operation_param1_value_b = 0x %8.8x \n", + *operation_param1_value_b + ); + printf(" TEEC_Session operation_param1_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param1_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param1_ionref_ionsize = 0x %8.8x \n", + *operation_param1_ionref_ionsize + ); + + printf(" TEEC_Session operation_param2_tmpref_buffer = 0x %16.16lx \n", + *operation_param2_tmpref_buffer + ); + printf(" TEEC_Session operation_param2_tmpref_size = 0x %8.8x \n", + *operation_param2_tmpref_size + ); + printf(" TEEC_Session operation_param2_memref_parent = 0x %16.16lx \n", + *operation_param2_memref_parent + ); + printf(" TEEC_Session operation_param2_memref_size = 0x %8.8x \n", + *operation_param2_memref_size + ); + printf(" TEEC_Session operation_param2_memref_offset = 0x %8.8x \n", + *operation_param2_memref_offset + ); + printf(" TEEC_Session operation_param2_value_a = 0x %8.8x \n", + *operation_param2_value_a + ); + printf(" TEEC_Session operation_param2_value_b = 0x %8.8x \n", + *operation_param2_value_b + ); + printf(" TEEC_Session operation_param2_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param2_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param2_ionref_ionsize = 0x %8.8x \n", + *operation_param2_ionref_ionsize + ); + + printf(" TEEC_Session operation_param3_tmpref_buffer = 0x %16.16lx \n", + *operation_param3_tmpref_buffer + ); + printf(" TEEC_Session operation_param3_tmpref_size = 0x %8.8x \n", + *operation_param3_tmpref_size + ); + printf(" TEEC_Session operation_param3_memref_parent = 0x %16.16lx \n", + *operation_param3_memref_parent + ); + printf(" TEEC_Session operation_param3_memref_size = 0x %8.8x \n", + *operation_param3_memref_size + ); + printf(" TEEC_Session operation_param3_memref_offset = 0x %8.8x \n", + *operation_param3_memref_offset + ); + printf(" TEEC_Session operation_param3_value_a = 0x %8.8x \n", + *operation_param3_value_a + ); + printf(" TEEC_Session operation_param3_value_b = 0x %8.8x \n", + *operation_param3_value_b + ); + printf(" TEEC_Session operation_param3_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param3_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param3_ionref_ionsize = 0x %8.8x \n", + *operation_param3_ionref_ionsize + ); + + printf(" TEEC_Session operation_param4_tmpref_buffer = 0x %16.16lx \n", + *operation_param4_tmpref_buffer + ); + printf(" TEEC_Session operation_param4_tmpref_size = 0x %8.8x \n", + *operation_param4_tmpref_size + ); + printf(" TEEC_Session operation_param4_memref_parent = 0x %16.16lx \n", + *operation_param4_memref_parent + ); + printf(" TEEC_Session operation_param4_memref_size = 0x %8.8x \n", + *operation_param4_memref_size + ); + printf(" TEEC_Session operation_param4_memref_offset = 0x %8.8x \n", + *operation_param4_memref_offset + ); + printf(" TEEC_Session operation_param4_value_a = 0x %8.8x \n", + *operation_param4_value_a + ); + printf(" TEEC_Session operation_param4_value_b = 0x %8.8x \n", + *operation_param4_value_b + ); + printf(" TEEC_Session operation_param4_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param4_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param4_ionref_ionsize = 0x %8.8x \n", + *operation_param4_ionref_ionsize + ); + + printf(" TEEC_Session operation_session = 0x %16.16lx \n", + *operation_session + ); + printf(" TEEC_Session operation_cancelflag = 0x %8.8x \n", + (unsigned int)*operation_cancelflag + ); + printf(" TEEC_Session returnorigin = 0x %8.8x \n", + *returnorigin + ); +#endif + + if (context_tapath_size > *context_tapath_outsize) + { + memcpy(context_tapath, context_tapath_temp, *context_tapath_outsize); + *(context_tapath + *context_tapath_outsize) = 0; + } else + { + dbus_message_unref(msg); + return -1; + } + + if (session_serviceid_clockseqandnode_size >= session_serviceid_clockseqandnode_realsize && + session_serviceid_clockseqandnode_temp != NULL && + session_serviceid_clockseqandnode_realsize > 0 + ) + { + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) + { + session_serviceid_clockseqandnode[i] = + session_serviceid_clockseqandnode_temp[i]; + + } + *session_serviceid_clockseqandnode_outsize = session_serviceid_clockseqandnode_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *session_serviceid_clockseqandnode_outsize = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +int32_t +method_call_teec_closesession( + const char *workername, + + uint32_t in_session_seesionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + int32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int ret; + int iType; + dbus_uint32_t *session_serviceid_clockseqandnode_temp = NULL; + int session_serviceid_clockseqandnode_realsize; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_uint64_t dui64Temp; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_CloseSession" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + dui32Temp = in_session_seesionid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timelow; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timemid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timehiandver; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_session_serviceid_clockseqandnode_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_session_serviceid_clockseqandnode_size > 0 && + in_session_serviceid_clockseqandnode != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_session_opscnt; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui64Temp = in_session_head_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_head_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_context; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Close Session Sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + + // free the pending message handle + dbus_pending_call_unref(pending); + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_seesionid = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timelow = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timemid = dui32Temp; + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timehiandver = dui32Temp; + + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_clockseqandnode_outsize = dui32Temp; + + if (*session_serviceid_clockseqandnode_outsize > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &session_serviceid_clockseqandnode_temp, + &session_serviceid_clockseqandnode_realsize + ); + } + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_opscnt = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_context = dui64Temp; + + + printf("Got Reply of Method Call Teec Close Session: \n"); + printf(" session_seesionid = 0x %8.8x \n", + *session_seesionid + ); +#if 0 + printf(" TEEC_Session session_serviceid_timelow = 0x %8.8x \n", + *session_serviceid_timelow + ); + printf(" TEEC_Session session_serviceid_timemid = 0x %8.8x \n", + *session_serviceid_timemid + ); + printf(" TEEC_Session session_serviceid_timehiandver = 0x %8.8x \n", + *session_serviceid_timehiandver + ); + printf(" TEEC_Session session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", + session_serviceid_clockseqandnode_temp[i] + ); + } + printf("\n"); + printf(" TEEC_Session clockseqandnode_outsize = 0x %8.8x \n", + *session_serviceid_clockseqandnode_outsize + ); + printf(" TEEC_Session session_opscnt = 0x %8.8x \n", + *session_opscnt + ); + printf(" TEEC_Session session_head_next = 0x %16.16lx \n", + *session_head_next + ); + printf(" TEEC_Session session_head_prev = 0x %16.16lx \n", + *session_head_prev + ); +#endif + printf(" session_context = 0x %16.16lx \n", + *session_context + ); + + if (session_serviceid_clockseqandnode_size >= session_serviceid_clockseqandnode_realsize && + session_serviceid_clockseqandnode_temp != NULL && + session_serviceid_clockseqandnode_realsize > 0 + ) + { + memcpy( + session_serviceid_clockseqandnode, + session_serviceid_clockseqandnode_temp, + session_serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + *session_serviceid_clockseqandnode_outsize = session_serviceid_clockseqandnode_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *session_serviceid_clockseqandnode_outsize = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +int32_t +method_call_teec_invokecommand( + const char *workername, + + uint32_t in_session_sessionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + uint32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t commandid, + + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_parent_flag, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_parent_flag, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_parent_flag, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_parent_flag, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint32_t *in_buffer1, + uint32_t in_buffer1_size, + uint32_t *in_buffer2, + uint32_t in_buffer2_size, + uint32_t *in_buffer3, + uint32_t in_buffer3_size, + uint32_t *in_buffer4, + uint32_t in_buffer4_size, + + + uint32_t *teecresult, + + uint32_t *session_sessionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_parent_flag, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_parent_flag, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_parent_flag, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_parent_flag, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin, + + uint32_t *buffer1, + uint32_t buffer1_size, + uint32_t *buffer1_outsize, + uint32_t *buffer2, + uint32_t buffer2_size, + uint32_t *buffer2_outsize, + uint32_t *buffer3, + uint32_t buffer3_size, + uint32_t *buffer3_outsize, + uint32_t *buffer4, + uint32_t buffer4_size, + uint32_t *buffer4_outsize +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int ret; + int iType; + dbus_uint32_t *session_serviceid_clockseqandnode_temp = NULL; + int session_serviceid_clockseqandnode_realsize; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_uint64_t dui64Temp; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + dbus_uint32_t *buffer1_temp = NULL; + int buffer1_realsize; + dbus_uint32_t *buffer2_temp = NULL; + int buffer2_realsize; + dbus_uint32_t *buffer3_temp = NULL; + int buffer3_realsize; + dbus_uint32_t *buffer4_temp = NULL; + int buffer4_realsize; + + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_InvokeCommand" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + + dui32Temp = in_session_sessionid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timelow; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timemid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timehiandver; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_clockseqandnode_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_session_serviceid_clockseqandnode_size > 0 && + in_session_serviceid_clockseqandnode != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_session_opscnt; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_head_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_head_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_context; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui32Temp = commandid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui32Temp = in_operation_started; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_paramtypes; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param1_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param2_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param3_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param4_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_session; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_cancelflag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_returnorigin; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_buffer1_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer1_size > 0 && + in_buffer1 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer1, + in_buffer1_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_buffer2_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer2_size > 0 && + in_buffer2 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer2, + in_buffer2_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_buffer3_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer3_size > 0 && + in_buffer3 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer3, + in_buffer3_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_buffer4_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer4_size > 0 && + in_buffer4 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer4, + in_buffer4_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Invoke Command Sent. \n"); + + ///////////////////////////////////////////////////////////////////////////////////// + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + + // free the pending message handle + dbus_pending_call_unref(pending); + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *teecresult = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_sessionid = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timelow = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timemid = dui32Temp; + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timehiandver = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_clockseqandnode_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*session_serviceid_clockseqandnode_outsize > 0) + { + + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &session_serviceid_clockseqandnode_temp, + &session_serviceid_clockseqandnode_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_opscnt = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_context = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_started = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_paramtypes = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param1_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param2_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param3_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param4_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_session = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_cancelflag = di32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *returnorigin = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer1_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*buffer1_outsize > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer1_temp, + &buffer1_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer2_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*buffer2_outsize > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer2_temp, + &buffer2_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer3_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*buffer3_outsize > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer3_temp, + &buffer3_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer4_outsize = dui32Temp; + + if (*buffer4_outsize > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer4_temp, + &buffer4_realsize + ); + } + + + printf("Got Reply of Method Call Teec Invoke Command: \n"); + printf(" teecresult = 0x %8.8x \n", + *teecresult); + printf(" session_seesionid = 0x %8.8x \n", + *session_sessionid + ); +#if 0 + printf(" TEEC_Session session_serviceid_timelow = 0x %8.8x \n", + *session_serviceid_timelow + ); + printf(" TEEC_Session session_serviceid_timemid = 0x %8.8x \n", + *session_serviceid_timemid + ); + printf(" TEEC_Session session_serviceid_timehiandver = 0x %8.8x \n", + *session_serviceid_timehiandver + ); + printf(" TEEC_Session session_serviceid_clockseqandnode = \n"); + if ( *session_serviceid_clockseqandnode_outsize > 0 && + session_serviceid_clockseqandnode_temp != NULL + ) + { + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", + session_serviceid_clockseqandnode_temp[i] + ); + } + printf("\n"); + } + printf(" TEEC_Session clockseqandnode_outsize = 0x %8.8x \n", + *session_serviceid_clockseqandnode_outsize + ); + printf(" TEEC_Session session_opscnt = 0x %8.8x \n", + *session_opscnt + ); + printf(" TEEC_Session session_head_next = 0x %16.16lx \n", + *session_head_next + ); + printf(" TEEC_Session session_head_prev = 0x %16.16lx \n", + *session_head_prev + ); + printf(" TEEC_Session session_context = 0x %16.16lx \n", + *session_context + ); + printf(" TEEC_Session session_context = 0x %16.16lx \n", + *session_context + ); + printf(" TEEC_Session operation_started = 0x %8.8x \n", + *operation_started + ); + printf(" TEEC_Session operation_paramtypes = 0x %8.8x \n", + *operation_paramtypes + ); + printf(" TEEC_Session operation_param1_tmpref_buffer = 0x %16.16lx \n", + *operation_param1_tmpref_buffer + ); + printf(" TEEC_Session operation_param1_tmpref_size = 0x %8.8x \n", + *operation_param1_tmpref_size + ); + printf(" TEEC_Session operation_param1_memref_parent = 0x %16.16lx \n", + *operation_param1_memref_parent + ); + printf(" TEEC_Session operation_param1_memref_size = 0x %8.8x \n", + *operation_param1_memref_size + ); + printf(" TEEC_Session operation_param1_memref_offse = 0x %8.8x \n", + *operation_param1_memref_offset + ); + printf(" TEEC_Session operation_param1_value_a = 0x %8.8x \n", + *operation_param1_value_a + ); + printf(" TEEC_Session operation_param1_value_b = 0x %8.8x \n", + *operation_param1_value_b + ); + printf(" TEEC_Session operation_param1_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param1_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param1_ionref_ionsize = 0x %8.8x \n", + *operation_param1_ionref_ionsize + ); + + printf(" TEEC_Session operation_param2_tmpref_buffer = 0x %16.16lx \n", + *operation_param2_tmpref_buffer + ); + printf(" TEEC_Session operation_param2_tmpref_size = 0x %8.8x \n", + *operation_param2_tmpref_size + ); + printf(" TEEC_Session operation_param2_memref_parent = 0x %16.16lx \n", + *operation_param2_memref_parent + ); + printf(" TEEC_Session operation_param2_memref_size = 0x %8.8x \n", + *operation_param2_memref_size + ); + printf(" TEEC_Session operation_param2_memref_offset = 0x %8.8x \n", + *operation_param2_memref_offset + ); + printf(" TEEC_Session operation_param2_value_a = 0x %8.8x \n", + *operation_param2_value_a + ); + printf(" TEEC_Session operation_param2_value_b = 0x %8.8x \n", + *operation_param2_value_b + ); + printf(" TEEC_Session operation_param2_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param2_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param2_ionref_ionsize = 0x %8.8x \n", + *operation_param2_ionref_ionsize + ); + + printf(" TEEC_Session operation_param3_tmpref_buffer = 0x %16.16lx \n", + *operation_param3_tmpref_buffer + ); + printf(" TEEC_Session operation_param3_tmpref_size = 0x %8.8x \n", + *operation_param3_tmpref_size + ); + printf(" TEEC_Session operation_param3_memref_parent = 0x %16.16lx \n", + *operation_param3_memref_parent + ); + printf(" TEEC_Session operation_param3_memref_size = 0x %8.8x \n", + *operation_param3_memref_size + ); + printf(" TEEC_Session operation_param3_memref_offset = 0x %8.8x \n", + *operation_param3_memref_offset + ); + printf(" TEEC_Session operation_param3_value_a = 0x %8.8x \n", + *operation_param3_value_a + ); + printf(" TEEC_Session operation_param3_value_b = 0x %8.8x \n", + *operation_param3_value_b + ); + printf(" TEEC_Session operation_param3_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param3_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param3_ionref_ionsize = 0x %8.8x \n", + *operation_param3_ionref_ionsize + ); + + printf(" TEEC_Session operation_param4_tmpref_buffer = 0x %16.16lx \n", + *operation_param4_tmpref_buffer + ); + printf(" TEEC_Session operation_param4_tmpref_size = 0x %8.8x \n", + *operation_param4_tmpref_size + ); + printf(" TEEC_Session operation_param4_memref_parent = 0x %16.16lx \n", + *operation_param4_memref_parent + ); + printf(" TEEC_Session operation_param4_memref_size = 0x %8.8x \n", + *operation_param4_memref_size + ); + printf(" TEEC_Session operation_param4_memref_offset = 0x %8.8x \n", + *operation_param4_memref_offset + ); + printf(" TEEC_Session operation_param4_value_a = 0x %8.8x \n", + *operation_param4_value_a + ); + printf(" TEEC_Session operation_param4_value_b = 0x %8.8x \n", + *operation_param4_value_b + ); + printf(" TEEC_Session operation_param4_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param4_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param4_ionref_ionsize = 0x %8.8x \n", + *operation_param4_ionref_ionsize + ); + + printf(" TEEC_Session operation_session = 0x %16.16lx \n", + *operation_session + ); + printf(" TEEC_Session operation_cancelflag = 0x %8.8x \n", + (unsigned int)*operation_cancelflag + ); + printf(" returnorigin = 0x %8.8x \n", + *returnorigin + ); + + printf(" buffer1 = \n"); + if (buffer1_temp != NULL) + { + for (int i = 0; i < buffer1_realsize; i++) { + printf(" %2.2x", + buffer1_temp[i] + ); + } + printf("\n"); + } + printf(" buffer1_outsize = 0x %8.8x \n", + *buffer1_outsize + ); + + printf(" buffer2 = \n"); + if (buffer2_temp != NULL) + { + for (int i = 0; i < buffer2_realsize; i++) { + printf(" %2.2x", + buffer2_temp[i] + ); + } + printf("\n"); + } + printf(" buffer2_outsize = 0x %8.8x \n", + *buffer2_outsize + ); + + printf(" buffer3 = \n"); + if (buffer3_temp != NULL) + { + for (int i = 0; i < buffer3_realsize; i++) { + printf(" %2.2x", + buffer3_temp[i] + ); + } + printf("\n"); + } + printf(" buffer3_outsize = 0x %8.8x \n", + *buffer3_outsize + ); + + if (buffer4_temp != NULL) + { + printf(" buffer4 = \n"); + for (int i = 0; i < buffer4_realsize; i++) { + printf(" %2.2x", + buffer4_temp[i] + ); + } + printf("\n"); + } + printf(" buffer4_outsize = 0x %8.8x \n", + *buffer4_outsize + ); +#endif + + if (session_serviceid_clockseqandnode_size >= session_serviceid_clockseqandnode_realsize && + session_serviceid_clockseqandnode != NULL && + session_serviceid_clockseqandnode_temp != NULL && + session_serviceid_clockseqandnode_realsize > 0 + ) + { + memcpy( + session_serviceid_clockseqandnode, + session_serviceid_clockseqandnode_temp, + session_serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + *session_serviceid_clockseqandnode_outsize = session_serviceid_clockseqandnode_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *session_serviceid_clockseqandnode_outsize = 0; + } + + if (buffer1_size >= (uint32_t) buffer1_realsize && + buffer1 != NULL && + buffer1_temp != NULL && + buffer1_realsize > 0 + ) + { + memcpy( + buffer1, + buffer1_temp, + buffer1_realsize * sizeof(uint32_t) + ); + *buffer1_outsize = buffer1_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer1_outsize = 0; + } + + if (buffer2_size >= (uint32_t) buffer2_realsize && + buffer2 != NULL && + buffer2_temp != NULL && + buffer2_realsize > 0 + ) + { + memcpy( + buffer2, + buffer2_temp, + buffer2_realsize * sizeof(uint32_t) + ); + *buffer2_outsize = buffer2_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer2_outsize = 0; + } + + if (buffer3_size >= (uint32_t) buffer3_realsize && + buffer3 != NULL && + buffer3_temp != NULL && + buffer3_realsize > 0 + ) + { + memcpy( + buffer3, + buffer3_temp, + buffer3_realsize * sizeof(uint32_t) + ); + *buffer3_outsize = buffer3_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer3_outsize = 0; + } + + if (buffer4_size >= (uint32_t) buffer4_realsize && + buffer4 != NULL && + buffer4_temp != NULL && + buffer4_realsize > 0 + ) + { + memcpy( + buffer4, + buffer4_temp, + buffer4_realsize * sizeof(uint32_t) + ); + *buffer4_outsize = buffer4_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer4_outsize = 0; + } + + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +/** + * Call a method on a remote object + */ +void +method_call_destroy_threadpool( + const char *workername +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + // DBusConnection* conn; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + int ret; + int iType; + unsigned char name[] = "threadpool"; + unsigned char *charp; + dbus_uint32_t retcode; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "Destroy" // method name + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return; + } + + + // append arguments + dbus_message_iter_init_append(msg, &args); + + charp = name; + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &charp)) + { + fprintf(stderr, "Out Of Memory!\n"); + exit(1); + } + + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + exit(1); + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + exit(1); + } + dbus_connection_flush(conn); + + printf("\n"); + printf("Method Call Destroy Threadpool Sent. \n"); + + // free message + dbus_message_unref(msg); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + exit(1); + } + // free the pending message handle + dbus_pending_call_unref(pending); + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + exit(1); + } + + iType = + dbus_message_iter_get_arg_type( + &args + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + exit(1); + } + dbus_message_iter_get_basic( + &args, + &retcode + ); + + printf("Got Reply of Method Call Destroy Threadpool: \n"); + printf(" retcode = 0x%8x \n", retcode); + + // free reply + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); +} + + +#ifdef GP_PROXY_WORKER + +void * +reply_to_method_call_teec_inicont( + // DBusMessage* msg, + // DBusConnection* conn + void *thdfargs +) +{ + DBusMsgConn *DBusMCP; + DBusMessage *msg; + DBusConnection *conn; + DBusMessage *reply; + DBusMessageIter args; + dbus_bool_t bResult; + DBusMessageIter structIter; + int iType; + unsigned char *charp; + // char* param = ""; + unsigned char *name = NULL; + dbus_int32_t name_size; + dbus_int32_t in_fd; + unsigned char *in_ta_path = NULL; + dbus_int32_t in_ta_path_size; + dbus_uint64_t in_session_list_next; + dbus_uint64_t in_session_list_prev; + dbus_uint64_t in_shrd_mem_list_next; + dbus_uint64_t in_shrd_mem_list_prev; + dbus_uint64_t in_share_buffer_buffer; + dbus_int64_t in_share_buffer_buffer_barrier; + dbus_uint32_t teecresult; + dbus_int32_t fd; + // unsigned char ta_path[] = "/vendor/bin/rsa_demo_ta"; + // dbus_int32_t ta_path_size = strlen((const char *)ta_path); + unsigned char *ta_path = NULL; + dbus_int32_t ta_path_size = 0; + dbus_uint64_t session_list_next; + dbus_uint64_t session_list_prev; + dbus_uint64_t shrd_mem_list_next; + dbus_uint64_t shrd_mem_list_prev; + dbus_uint64_t share_buffer_buffer; + dbus_int64_t share_buffer_buffer_barrier; + dbus_uint64_t context_addr; + dbus_uint32_t serial = 0; + +#ifdef GP_PROXY + pthread_mutex_t * mutex_workerrec; + pthread_cond_t * cond_notbusy; + wr_t * workerrec; +#endif + +#ifdef GP_WORKER + pthread_mutex_t *mutex_tcl; + pthread_mutex_t *mutex_tsl; + tcl_t *tcl; + tsl_t *tsl; +#endif + + DBusMCP = (DBusMsgConn *) thdfargs; + msg = DBusMCP->msg; + conn = DBusMCP->conn; +#ifdef GP_PROXY + mutex_workerrec = DBusMCP->mutex_workerrec; + cond_notbusy = DBusMCP->cond_notbusy; + workerrec = DBusMCP->workerrec; +#endif +#ifdef GP_WORKER + mutex_tcl = DBusMCP->mutex_tcl; + mutex_tsl = DBusMCP->mutex_tsl; + tcl = DBusMCP->tcl; + tsl = DBusMCP->tsl; +#endif + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &name_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (name_size > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &name); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_fd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_ta_path_size + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + // fprintf(stderr, "Debug in_ta_path_size = %d \n", in_ta_path_size); + if (in_ta_path_size > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_ta_path); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_list_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_list_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_shrd_mem_list_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_shrd_mem_list_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_share_buffer_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_share_buffer_buffer_barrier); + + printf("Received method call Teec Initialize Context: \n"); + printf(" in name = %s \n", name); + printf(" in name_size = %d \n", name_size); + printf(" in_fd = 0x %8.8x \n", in_fd); + printf(" in_ta_path = %s \n", in_ta_path); + printf(" in_ta_path_size = %d \n", in_ta_path_size); +#if 0 + printf(" in_session_list_next = 0x %16.16lx \n", in_session_list_next); + printf(" in_session_list_prev = 0x %16.16lx \n", in_session_list_prev); + printf(" in_shrd_mem_list_next = 0x %16.16lx \n", in_shrd_mem_list_next); + printf(" in_shrd_mem_list_prev = 0x %16.16lx \n", in_shrd_mem_list_prev); + printf(" in_share_buffer_buffer = 0x %16.16lx \n", in_share_buffer_buffer); + printf(" in_share_buffer_buffer_barrier = 0x %16.16lx \n", in_share_buffer_buffer_barrier); +#endif + +#ifdef GP_WORKER + //////////////////////////////////////////////////////////////////////////////////////////////// + TEEC_Context *contextIns = (TEEC_Context *) malloc(sizeof(TEEC_Context)); + + TEEC_Result result; + + contextIns->fd = in_fd; + contextIns->ta_path = in_ta_path; + contextIns->session_list.next = (struct ListNode *) in_session_list_next; + contextIns->session_list.prev = (struct ListNode *) in_session_list_prev; + contextIns->shrd_mem_list.next = (struct ListNode *) in_shrd_mem_list_next; + contextIns->shrd_mem_list.prev = (struct ListNode *) in_shrd_mem_list_prev; + contextIns->share_buffer.buffer = (void *) in_share_buffer_buffer; + contextIns->share_buffer.buffer_barrier.__align = (long long int) in_share_buffer_buffer_barrier; + // typedef struct { + // volatile int __val[4*sizeof(long)/sizeof(int)]; + // } sem_t; + // + // typedef union + // { + // char __size[__SIZEOF_SEM_T]; + // long long int __align; + // } sem_t; + struct timeval start, end; + gettimeofday(&start, NULL); + result = TEEC_InitializeContext(NULL, contextIns); + gettimeofday(&end, NULL); + uint32_t cost = 0; + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + if (result != TEEC_SUCCESS) + { + printf("Teec InitilizeContext Failed.\n"); + printf(" teecresult = 0x %8.8x.\n", result); + + teecresult = result; + fd = 0; + ta_path_size = 0; + ta_path = NULL; + charp = ta_path; + session_list_next = 0; + session_list_prev = 0; + shrd_mem_list_next = 0; + shrd_mem_list_prev = 0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0; + context_addr = 0; + } else + { + printf("Teec InitilizeContext Succed, cost time: %ld us \n", cost); + + tcn_t *tcnIns = (tcn_t *) malloc(sizeof(tcn_t)); + tcnIns->self = contextIns; + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + tcnIns->createtime = tvcreate; + + pthread_mutex_lock(mutex_tcl); + if (tcl->first == NULL) + { + tcnIns->next = NULL; + tcnIns->prev = NULL; + tcl->first = tcnIns; + tcl->last = tcnIns; + tcl->count = 1; + } else + { + tcnIns->prev = tcl->last; + tcnIns->next = NULL; + tcl->last->next = tcnIns; + tcl->last = tcnIns; + tcl->count = tcl->count + 1; + } + pthread_mutex_unlock(mutex_tcl); + + teecresult = result; + fd = contextIns->fd; + if (contextIns->ta_path != NULL) + { + ta_path_size = strlen((const char *) contextIns->ta_path); + } else + { + ta_path_size = 0; + } + ta_path = contextIns->ta_path; + charp = ta_path; + session_list_next = (dbus_uint64_t) contextIns->session_list.next; + session_list_prev = (dbus_uint64_t) contextIns->session_list.prev; + shrd_mem_list_next = (dbus_uint64_t) contextIns->shrd_mem_list.next; + shrd_mem_list_prev = (dbus_uint64_t) contextIns->shrd_mem_list.prev; + share_buffer_buffer = (dbus_uint64_t) contextIns->share_buffer.buffer; + share_buffer_buffer_barrier = contextIns->share_buffer.buffer_barrier.__align; + + // context_addr = (dbus_uint64_t)contextIns; + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + context_addr = (dbus_uint64_t) DBusMCP->workernum + + u64time + + (long unsigned int) rand(); + + printf(" context fd = 0x %8.8x \n", contextIns->fd); + printf(" context address = 0x %16.16lx \n", context_addr); + } + + // TEEC_FinalizeContext(&contextIns); + // printf("Teec FinalizedContext.\n"); + //////////////////////////////////////////////////////////////////////////////////////////////// +#else + ta_path = (unsigned char *)malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *)ta_path, 0, 1024); + uint32_t context_tapath_outsize; + + char workername[1024]; + memset((char *)workername, 0, 1024); + int ifound = 0; + int iworker; + for( ; ; ) + { + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + if (workerrec[iworker].busy == 0) + { + sprintf(workername, "%s%d", "gpworker", iworker); + workerrec[iworker].busy = 1; + ifound = 1; + break; + } + } + if (ifound == 0) + { + pthread_cond_wait(cond_notbusy, mutex_workerrec); + } + pthread_mutex_unlock(mutex_workerrec); + + if (ifound == 1) + { + break; + } + } + + method_call_teec_inicont( + workername, + + name, + name_size, + in_fd, + in_ta_path, + in_ta_path_size, + in_session_list_next, + in_session_list_prev, + in_shrd_mem_list_next, + in_shrd_mem_list_prev, + in_share_buffer_buffer, + in_share_buffer_buffer_barrier, + + + &teecresult, + + &fd, + ta_path, + ta_path_size, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + &context_addr, + + &context_tapath_outsize + ); + + if (teecresult == 0) + { + pthread_mutex_lock(mutex_workerrec); + workerrec[iworker].context_fd = fd; + workerrec[iworker].context_addr = context_addr; + workerrec[iworker].first = NULL; + workerrec[iworker].last = NULL; + workerrec[iworker].sessionid_count = 0; + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + workerrec[iworker].context_createtime = tvcreate; + pthread_mutex_unlock(mutex_workerrec); + } + else + { + workerrec[iworker].busy = 0; + } + + if (ta_path_size >= context_tapath_outsize) { + ta_path_size = context_tapath_outsize; + charp = ta_path; + } + else + { + ta_path_size = 0; + charp = NULL; + } + + //////////////////////////////////////////////////////////////////////////////////////////////// +#endif + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + +#if 0 + teecresult = 0; + fd = 0x04; + charp = ta_path; + session_list_next = 0xea3500a8; + session_list_prev = 0xea3500a8; + shrd_mem_list_next = 0xea3500b8; + shrd_mem_list_prev = 0xea3500b8; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0xdd901c10; +#endif + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &teecresult + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &fd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + DBusError err; + // initialise the errors + dbus_error_init(&err); + + if (ta_path_size > 0 && + charp != NULL && + strlen((const char *) charp) > 0 + ) + { + if (dbus_validate_utf8((const char *) charp, &err) == true) + { + ta_path_size = strlen((const char *) charp); + } else + { + ta_path_size = 0; + } + } else + { + ta_path_size = 0; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &ta_path_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (ta_path_size > 0) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &charp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &session_list_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &session_list_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &shrd_mem_list_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &shrd_mem_list_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &share_buffer_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &share_buffer_buffer_barrier + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &context_addr + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send the reply && flush the connection + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_unref(reply); + dbus_message_unref(msg); + dbus_connection_flush(conn); + // dbus_connection_close(conn); + // dbus_connection_unref(conn); + + free(thdfargs); + + // sleep(2); + +#if 0 + #ifdef GP_WORKER + +#else + if (ta_path == NULL) + { + free(ta_path); + } +#endif +#endif + + return NULL; +} + + +void * +reply_to_method_call_teec_fincont( + void *thdfargs +) +{ + DBusMsgConn *DBusMCP; + DBusMessage *msg; + DBusConnection *conn; + DBusMessage *reply; + DBusMessageIter args; + dbus_bool_t bResult; + DBusMessageIter structIter; + int iType; + unsigned char *charp; + // char* param = ""; + dbus_int32_t in_fd; + unsigned char *in_ta_path = NULL; + dbus_int32_t in_ta_path_size; + dbus_uint64_t in_session_list_next; + dbus_uint64_t in_session_list_prev; + dbus_uint64_t in_shrd_mem_list_next; + dbus_uint64_t in_shrd_mem_list_prev; + dbus_uint64_t in_share_buffer_buffer; + dbus_int64_t in_share_buffer_buffer_barrier; + dbus_uint64_t in_context_addr; + + dbus_int32_t fd; + dbus_int32_t ta_path_size = 0; + dbus_uint64_t session_list_next; + dbus_uint64_t session_list_prev; + dbus_uint64_t shrd_mem_list_next; + dbus_uint64_t shrd_mem_list_prev; + dbus_uint64_t share_buffer_buffer; + dbus_int64_t share_buffer_buffer_barrier; + dbus_uint32_t serial = 0; + +#ifdef GP_PROXY + pthread_mutex_t * mutex_workerrec; + pthread_cond_t * cond_notbusy; + wr_t * workerrec; +#endif + +#ifdef GP_WORKER + pthread_mutex_t *mutex_tcl; + tcl_t *tcl; + tsl_t *tsl; +#endif + + DBusMCP = (DBusMsgConn *) thdfargs; + msg = DBusMCP->msg; + conn = DBusMCP->conn; +#ifdef GP_PROXY + mutex_workerrec = DBusMCP->mutex_workerrec; + cond_notbusy = DBusMCP->cond_notbusy; + workerrec = DBusMCP->workerrec; +#endif +#ifdef GP_WORKER + mutex_tcl = DBusMCP->mutex_tcl; + tcl = DBusMCP->tcl; + tsl = DBusMCP->tsl; +#endif + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_fd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_ta_path_size + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + // fprintf(stderr, "Debug in_ta_path_size = %d \n", in_ta_path_size); + if (in_ta_path_size > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_ta_path); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_list_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_list_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_shrd_mem_list_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_shrd_mem_list_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_share_buffer_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_share_buffer_buffer_barrier); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_context_addr); + + printf("Received method call Teec Finalize Context: \n"); + printf(" in_fd = 0x %8.8x \n", in_fd); + printf(" in_ta_path_size = %d \n", in_ta_path_size); + + DBusError err; + dbus_error_init(&err); + if (in_ta_path_size > 0 && in_ta_path != NULL && dbus_validate_path((const char *) in_ta_path, &err) == true) + { + printf(" in_ta_path = %s \n", in_ta_path); + } +#if 0 + printf(" in_session_list_next = 0x %16.16lx \n", in_session_list_next); + printf(" in_session_list_prev = 0x %16.16lx \n", in_session_list_prev); + printf(" in_shrd_mem_list_next = 0x %16.16lx \n", in_shrd_mem_list_next); + printf(" in_shrd_mem_list_prev = 0x %16.16lx \n", in_shrd_mem_list_prev); + printf(" in_share_buffer_buffer = 0x %16.16lx \n", in_share_buffer_buffer); + printf(" in_share_buffer_buffer_barrier = 0x %16.16lx \n", in_share_buffer_buffer_barrier); +#endif + printf(" in_context_addr = 0x %16.16lx \n", in_context_addr); + + + unsigned char *ta_path = NULL; +#ifdef GP_WORKER + //////////////////////////////////////////////////////////////////////////////////////////////// + TEEC_Context *contextIns; + tcn_t *tcnIns; + TEEC_Result result; + + contextIns = NULL; + pthread_mutex_lock(mutex_tcl); + if (tcl->first != NULL) + { + tcnIns = tcl->first; + do + { + if (tcnIns->self->fd == in_fd) + { + contextIns = tcnIns->self; + break; + } + tcnIns = tcnIns->next; + } while (tcnIns != NULL); + } + pthread_mutex_unlock(mutex_tcl); + + if (contextIns == NULL) + { + if (tcl->first == NULL) + { + printf("The teec context list is null. \n"); + // teecresult = TEEC_ERROR_CONTEXT_LIST_NULL; + } else + { + printf("Can't find the teec context. \n"); + // teecresult = TEEC_ERROR_NO_CONTEXT_MATCH; + } + + fd = 0; + ta_path_size = 0; + charp = NULL; + session_list_prev = 0; + shrd_mem_list_next = 0; + shrd_mem_list_prev = 0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0; + } else + { + // contextIns.fd = in_fd; + contextIns->ta_path = in_ta_path; + contextIns->session_list.next = (struct ListNode *) in_session_list_next; + contextIns->session_list.prev = (struct ListNode *) in_session_list_prev; + contextIns->shrd_mem_list.next = (struct ListNode *) in_shrd_mem_list_next; + contextIns->shrd_mem_list.prev = (struct ListNode *) in_shrd_mem_list_prev; + contextIns->share_buffer.buffer = (void *) in_share_buffer_buffer; + contextIns->share_buffer.buffer_barrier.__align = (long long int) in_share_buffer_buffer_barrier; + // typedef struct { + // volatile int __val[4*sizeof(long)/sizeof(int)]; + // } sem_t; + // + // typedef union + // { + // char __size[__SIZEOF_SEM_T]; + // long long int __align; + // } sem_t; + + struct timeval start, end; + gettimeofday(&start, NULL); + TEEC_FinalizeContext(contextIns); + gettimeofday(&end, NULL); + uint32_t cost = 0; + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + printf("Teec FinalizeContext executed, cost time: %ld us \n", cost); + + fd = contextIns->fd; + if (contextIns->ta_path != NULL) + { + ta_path_size = strlen((const char *) contextIns->ta_path); + ta_path = contextIns->ta_path; + } else + { + ta_path_size = 0; + ta_path = NULL; + } + charp = ta_path; + session_list_next = (dbus_uint64_t) contextIns->session_list.next; + session_list_prev = (dbus_uint64_t) contextIns->session_list.prev; + shrd_mem_list_next = (dbus_uint64_t) contextIns->shrd_mem_list.next; + shrd_mem_list_prev = (dbus_uint64_t) contextIns->shrd_mem_list.prev; + share_buffer_buffer = (dbus_uint64_t) contextIns->share_buffer.buffer; + share_buffer_buffer_barrier = contextIns->share_buffer.buffer_barrier.__align; + + tcn_t *tcnTemp; + tcnTemp = tcnIns->prev; + if (tcnTemp != NULL) + { + tcnTemp->next = tcnIns->next; + } + tcnTemp = tcnIns->next; + if (tcnTemp != NULL) + { + tcnTemp->prev = tcnIns->prev; + } + pthread_mutex_lock(mutex_tcl); + if (tcl->last == tcnIns) + { + tcl->last = tcnIns->prev; + } + if (tcl->first == tcnIns) + { + tcl->first = tcnIns->next; + } + tcl->count = tcl->count - 1; + pthread_mutex_unlock(mutex_tcl); + free(contextIns); + free(tcnIns); + } + //////////////////////////////////////////////////////////////////////////////////////////////// +#else + ta_path = (unsigned char *)malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *)ta_path, 0, 1024); + uint32_t context_tapath_outsize; + + char workername[1024]; + memset((char *)workername, 0, 1024); + int ifound = 0; + int iworker; + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + if (workerrec[iworker].context_fd == in_fd && + workerrec[iworker].context_addr == in_context_addr + ) + { + sprintf(workername, "%s%d", "gpworker", iworker); + ifound = 1; + break; + } + } + pthread_mutex_unlock(mutex_workerrec); + + if (ifound == 0) + { + printf("Can't find the worker for the context. \n"); + + // teecresult = 0xAAAA0017; + + fd = 0; + ta_path_size = 0; + charp = NULL; + session_list_prev = 0; + shrd_mem_list_next = 0; + shrd_mem_list_prev = 0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0; + } + else + { + pthread_mutex_unlock(mutex_workerrec); + sin_t * sinIns = NULL; + sin_t * sinInsPrev = NULL; + sinIns = workerrec[iworker].last; + if (sinIns != NULL) + { + dbus_uint32_t in_session_seesionid; + dbus_uint32_t in_session_serviceid_timelow = 0; + dbus_uint32_t in_session_serviceid_timemid = 0; + dbus_uint32_t in_session_serviceid_timehiandver = 0; + dbus_uint32_t in_session_serviceid_clockseqandnode_size = 8; + dbus_uint32_t in_session_serviceid_clockseqandnode[8]; + dbus_uint32_t in_session_opscnt = 0; + dbus_uint64_t in_session_head_next = 0; + dbus_uint64_t in_session_head_prev = 0; + dbus_uint64_t in_session_context; + + dbus_uint32_t seesionid; + dbus_uint32_t serviceid_timelow; + dbus_uint32_t serviceid_timemid; + dbus_uint32_t serviceid_timehiandver; + dbus_uint32_t * serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + dbus_uint32_t opscnt; + dbus_uint64_t head_next; + dbus_uint64_t head_prev; + dbus_uint64_t context; + + for ( ; ; ) + { + in_session_seesionid = sinIns->session_id; + in_session_context = workerrec[iworker].context_addr; + + pthread_mutex_unlock(mutex_workerrec); + + for (int iind = 0; iind < 8; iind++) + { + in_session_serviceid_clockseqandnode[iind] = 0; + } + + uint32_t serviceid_clockseqandnode_outsize_temp; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + + printf("\nMethod call teec closesession. (Called by Proxy before fin context) \n"); + + method_call_teec_closesession( + workername, + + in_session_seesionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + &seesionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &context + ); + + if (serviceid_clockseqandnode != NULL) { + free(serviceid_clockseqandnode); + } + + pthread_mutex_lock(mutex_workerrec); + + sinInsPrev = sinIns->prev; + free(sinIns); + if (sinInsPrev == NULL) + // if (sinIns == workerrec[iworker].first) + { + // free(sinIns); + break; + } + sinIns = sinInsPrev; + } + } + pthread_mutex_unlock(mutex_workerrec); + + method_call_teec_fincont( + workername, + + in_fd, + in_ta_path, + in_ta_path_size, + in_session_list_next, + in_session_list_prev, + in_shrd_mem_list_next, + in_shrd_mem_list_prev, + in_share_buffer_buffer, + in_share_buffer_buffer_barrier, + in_context_addr, + + &fd, + ta_path, + ta_path_size, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + + &context_tapath_outsize + ); + + pthread_mutex_lock(mutex_workerrec); + workerrec[iworker].busy = 0; + pthread_cond_signal(cond_notbusy); + workerrec[iworker].context_fd = 0; + workerrec[iworker].context_addr = 0xffffffff; + workerrec[iworker].sessionid_count = 0; + workerrec[iworker].first = NULL; + workerrec[iworker].last = NULL; + pthread_mutex_unlock(mutex_workerrec); + + if (ta_path_size >= context_tapath_outsize) { + ta_path_size = context_tapath_outsize; + charp = ta_path; + } + else + { + ta_path_size = 0; + charp = NULL; + } + + } // end of else found == 1 + //////////////////////////////////////////////////////////////////////////////////////////////// + +#endif + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &fd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + // DBusError err; + // initialise the errors + // dbus_error_init(&err); + + if (ta_path_size > 0 && + charp != NULL + // && strlen((const char *) charp) > 0 + ) + { + // if (dbus_validate_utf8((const char *) charp, &err) == true) + if (dbus_validate_path((const char *) charp, &err) == true) + { + ta_path_size = strlen((const char *) charp); + } else + { + ta_path_size = 0; + } + } else + { + ta_path_size = 0; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &ta_path_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + fprintf(stderr, "%s %d: reply fincont, tapath size = %d \n", __FILE__, __LINE__, ta_path_size); + if (ta_path_size > 0) + { + fprintf(stderr, "%s %d: reply fincont, tapath = %s \n", __FILE__, __LINE__, charp); + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &charp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &session_list_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &session_list_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &shrd_mem_list_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &shrd_mem_list_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &share_buffer_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &share_buffer_buffer_barrier + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send the reply && flush the connection + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_unref(reply); + dbus_message_unref(msg); + dbus_connection_flush(conn); + // dbus_connection_close(conn); + // dbus_connection_unref(conn); + free(thdfargs); + + // sleep(2); + +#if 0 + #ifdef GP_WORKER + +#else + if (ta_path == NULL) + { + free(ta_path); + } +#endif +#endif + + return NULL; +} + + +void * +reply_to_method_call_teec_opensession( + void *thdfargs +) +{ + DBusMsgConn *DBusMCP; + DBusMessage *msg; + DBusConnection *conn; + DBusMessage *reply; + DBusMessageIter args; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int iType; + unsigned char *charp; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + // char* param = ""; + dbus_int32_t in_fd; + unsigned char *in_ta_path = NULL; + dbus_int32_t in_ta_path_size; + dbus_uint64_t in_session_list_next; + dbus_uint64_t in_session_list_prev; + dbus_uint64_t in_shrd_mem_list_next; + dbus_uint64_t in_shrd_mem_list_prev; + dbus_uint64_t in_share_buffer_buffer; + dbus_int64_t in_share_buffer_buffer_barrier; + dbus_uint32_t teecresult; + dbus_int32_t fd; + + dbus_uint32_t in_destination_timelow; + dbus_uint32_t in_destination_timemid; + dbus_uint32_t in_destination_timehiandver; + + dbus_uint32_t in_connectionmethod; + dbus_uint64_t in_connectiondata; + dbus_uint32_t in_operation_started; + dbus_uint32_t in_operation_paramtypes; + dbus_int32_t in_destination_clockseqandnode_size; + int in_destination_clockseqandnode_realsize; + dbus_uint32_t *in_destination_clockseqandnode; + + dbus_uint64_t in_operation_param1_tmpref_buffer; + dbus_uint32_t in_operation_param1_tmpref_size; + dbus_uint64_t in_operation_param1_memref_parent; + dbus_uint32_t in_operation_param1_memref_size; + dbus_uint32_t in_operation_param1_memref_offset; + dbus_uint32_t in_operation_param1_value_a; + dbus_uint32_t in_operation_param1_value_b; + dbus_int32_t in_operation_param1_ionref_ionsharefd; + dbus_uint32_t in_operation_param1_ionref_ionsize; + + dbus_uint64_t in_operation_param2_tmpref_buffer; + dbus_uint32_t in_operation_param2_tmpref_size; + dbus_uint64_t in_operation_param2_memref_parent; + dbus_uint32_t in_operation_param2_memref_size; + dbus_uint32_t in_operation_param2_memref_offset; + dbus_uint32_t in_operation_param2_value_a; + dbus_uint32_t in_operation_param2_value_b; + dbus_int32_t in_operation_param2_ionref_ionsharefd; + dbus_uint32_t in_operation_param2_ionref_ionsize; + + dbus_uint64_t in_operation_param3_tmpref_buffer; + dbus_uint32_t in_operation_param3_tmpref_size; + dbus_uint64_t in_operation_param3_memref_parent; + dbus_uint32_t in_operation_param3_memref_size; + dbus_uint32_t in_operation_param3_memref_offset; + dbus_uint32_t in_operation_param3_value_a; + dbus_uint32_t in_operation_param3_value_b; + dbus_int32_t in_operation_param3_ionref_ionsharefd; + dbus_uint32_t in_operation_param3_ionref_ionsize; + + dbus_uint64_t in_operation_param4_tmpref_buffer; + dbus_uint32_t in_operation_param4_tmpref_size; + dbus_uint64_t in_operation_param4_memref_parent; + dbus_uint32_t in_operation_param4_memref_size; + dbus_uint32_t in_operation_param4_memref_offset; + dbus_uint32_t in_operation_param4_value_a; + dbus_uint32_t in_operation_param4_value_b; + dbus_int32_t in_operation_param4_ionref_ionsharefd; + dbus_uint32_t in_operation_param4_ionref_ionsize; + + dbus_uint64_t in_operation_session; + dbus_int32_t in_operation_cancelflag; + dbus_uint32_t in_returnorigin; + + dbus_uint64_t in_context_addr; + + // unsigned char ta_path[] = "/vendor/bin/rsa_demo_ta"; + // dbus_int32_t ta_path_size = strlen((const char *)ta_path); + unsigned char *ta_path; + dbus_int32_t ta_path_size; + dbus_uint64_t session_list_next; + dbus_uint64_t session_list_prev; + dbus_uint64_t shrd_mem_list_next; + dbus_uint64_t shrd_mem_list_prev; + dbus_uint64_t share_buffer_buffer; + dbus_int64_t share_buffer_buffer_barrier; + + dbus_uint32_t seesionid; + dbus_uint32_t serviceid_timelow; + dbus_uint32_t serviceid_timemid; + dbus_uint32_t serviceid_timehiandver; + dbus_uint32_t *serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + dbus_int32_t serviceid_clockseqandnode_outsize; + dbus_uint32_t opscnt; + dbus_uint64_t head_next; + dbus_uint64_t head_prev; + dbus_uint64_t context; + + dbus_uint32_t started; + dbus_uint32_t paramtypes; + + dbus_uint64_t operation_param1_tmpref_buffer; + dbus_uint32_t operation_param1_tmpref_size; + dbus_uint64_t operation_param1_memref_parent; + dbus_uint32_t operation_param1_memref_size; + dbus_uint32_t operation_param1_memref_offset; + dbus_uint32_t operation_param1_value_a; + dbus_uint32_t operation_param1_value_b; + dbus_int32_t operation_param1_ionref_ionsharefd; + dbus_uint32_t operation_param1_ionref_ionsize; + + dbus_uint64_t operation_param2_tmpref_buffer; + dbus_uint32_t operation_param2_tmpref_size; + dbus_uint64_t operation_param2_memref_parent; + dbus_uint32_t operation_param2_memref_size; + dbus_uint32_t operation_param2_memref_offset; + dbus_uint32_t operation_param2_value_a; + dbus_uint32_t operation_param2_value_b; + dbus_int32_t operation_param2_ionref_ionsharefd; + dbus_uint32_t operation_param2_ionref_ionsize; + + dbus_uint64_t operation_param3_tmpref_buffer; + dbus_uint32_t operation_param3_tmpref_size; + dbus_uint64_t operation_param3_memref_parent; + dbus_uint32_t operation_param3_memref_size; + dbus_uint32_t operation_param3_memref_offset; + dbus_uint32_t operation_param3_value_a; + dbus_uint32_t operation_param3_value_b; + dbus_int32_t operation_param3_ionref_ionsharefd; + dbus_uint32_t operation_param3_ionref_ionsize; + + dbus_uint64_t operation_param4_tmpref_buffer; + dbus_uint32_t operation_param4_tmpref_size; + dbus_uint64_t operation_param4_memref_parent; + dbus_uint32_t operation_param4_memref_size; + dbus_uint32_t operation_param4_memref_offset; + dbus_uint32_t operation_param4_value_a; + dbus_uint32_t operation_param4_value_b; + dbus_int32_t operation_param4_ionref_ionsharefd; + dbus_uint32_t operation_param4_ionref_ionsize; + + dbus_uint64_t operation_session; + dbus_int32_t operation_cancelflag; + dbus_uint32_t returnorigin; + dbus_uint32_t serial = 0; + +#ifdef GP_PROXY + pthread_mutex_t * mutex_workerrec; + wr_t * workerrec; +#endif + +#ifdef GP_WORKER + pthread_mutex_t *mutex_tcl; + pthread_mutex_t *mutex_tsl; + tcl_t *tcl; + tsl_t *tsl; +#endif + + DBusMCP = (DBusMsgConn *) thdfargs; + msg = DBusMCP->msg; + conn = DBusMCP->conn; +#ifdef GP_PROXY + mutex_workerrec = DBusMCP->mutex_workerrec; + workerrec = DBusMCP->workerrec; +#endif +#ifdef GP_WORKER + mutex_tcl = DBusMCP->mutex_tcl; + mutex_tsl = DBusMCP->mutex_tsl; + tcl = DBusMCP->tcl; + tsl = DBusMCP->tsl; +#endif + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_get_basic( + &structIter, + &in_fd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_ta_path_size + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + // fprintf(stderr, "Debug in_ta_path_size = %d \n", in_ta_path_size); + if (in_ta_path_size > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_ta_path); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_list_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_list_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_shrd_mem_list_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_shrd_mem_list_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_share_buffer_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_share_buffer_buffer_barrier); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_destination_timelow); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_destination_timemid); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_destination_timehiandver); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_destination_clockseqandnode_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (in_destination_clockseqandnode_size > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &in_destination_clockseqandnode, + &in_destination_clockseqandnode_realsize + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_get_basic( + &structIter, + &in_connectionmethod); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_connectiondata); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_started); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_paramtypes); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_tmpref_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_tmpref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_memref_parent); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_memref_size); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_value_a); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_value_b); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_tmpref_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_tmpref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_memref_parent); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_memref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_value_a); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_value_b); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_tmpref_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_tmpref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_memref_parent); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_memref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_value_a); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_value_b); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_tmpref_buffer); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_tmpref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_memref_parent); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_memref_size); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_value_a); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_value_b); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_session); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_cancelflag); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_returnorigin); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_context_addr); + + printf("Received method call Teec Open Session: \n"); + printf(" in_fd = 0x %8.8x \n", in_fd); + printf(" in_ta_path = %s \n", in_ta_path); + printf(" in_ta_path_size = %d \n", in_ta_path_size); +#if 0 + printf(" in_session_list_next = 0x %16.16lx \n", in_session_list_next); + printf(" in_session_list_prev = 0x %16.16lx \n", in_session_list_prev); + printf(" in_shrd_mem_list_next = 0x %16.16lx \n", in_shrd_mem_list_next); + printf(" in_shrd_mem_list_prev = 0x %16.16lx \n", in_shrd_mem_list_prev); + printf(" in_share_buffer_buffer = 0x %16.16lx \n", in_share_buffer_buffer); + printf(" in_share_buffer_buffer_barrier = 0x %16.16lx \n", in_share_buffer_buffer_barrier); + + printf(" in_destination_timelow = 0x %8.8x \n", in_destination_timelow); + printf(" in_destination_timemid = 0x %8.8x \n", in_destination_timemid); + printf(" in_destination_timehiandver = 0x %8.8x \n", in_destination_timehiandver); + if ( in_destination_clockseqandnode_realsize > 0 ) + { + printf(" in_destination_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < in_destination_clockseqandnode_realsize; i++) { + printf(" %8.8x", in_destination_clockseqandnode[i]); + } + printf("\n"); + } + else + { + printf(" in_destination_clockseqandnode addr = 0x %16.16lx \n", + (long unsigned int)in_destination_clockseqandnode + ); + } + printf(" in_destination_clockseqandnode_size = 0x %8.8x \n", in_destination_clockseqandnode_size); + + printf(" in_connectionmethod = 0x %8.8x \n", in_connectionmethod); + printf(" in_connectiondata = 0x %16.16lx \n", in_connectiondata); + + printf(" in_operation_started = 0x %8.8x \n", in_operation_started); + printf(" in_operation_paramtypes = 0x %8.8x \n", in_operation_paramtypes); + + printf(" in_operation_param1_tmpref_buffer = 0x %16.16lx \n", in_operation_param1_tmpref_buffer); + printf(" in_operation_param1_tmpref_size = 0x %8.8x \n", in_operation_param1_tmpref_size); + printf(" in_operation_param1_memref_parent = 0x %16.16lx \n", in_operation_param1_memref_parent); + printf(" in_operation_param1_memref_size = 0x %8.8x \n", in_operation_param1_memref_size); + printf(" in_operation_param1_memref_offset = 0x %8.8x \n", in_operation_param1_memref_offset); + printf(" in_operation_param1_value_a = 0x %8.8x \n", in_operation_param1_value_a); + printf(" in_operation_param1_value_b = 0x %8.8x \n", in_operation_param1_value_b); + printf(" in_operation_param1_ionref_ionsharefd = 0x %8.8x \n", + in_operation_param1_ionref_ionsharefd); + printf(" in_operation_param1_ionref_ionsize = 0x %8.8x \n", in_operation_param1_ionref_ionsize); + + printf(" in_operation_param2_tmpref_buffer = 0x %16.16lx \n", in_operation_param2_tmpref_buffer); + printf(" in_operation_param2_tmpref_size = 0x %8.8x \n", in_operation_param2_tmpref_size); + printf(" in_operation_param2_memref_parent = 0x %16.16lx \n", in_operation_param2_memref_parent); + printf(" in_operation_param2_memref_size = 0x %8.8x \n", in_operation_param2_memref_size); + printf(" in_operation_param2_memref_offset = 0x %8.8x \n", in_operation_param2_memref_offset); + printf(" in_operation_param2_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param2_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param2_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param2_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param3_tmpref_buffer = 0x %16.16lx \n", in_operation_param3_tmpref_buffer); + printf(" in_operation_param3_tmpref_size = 0x %8.8x \n", in_operation_param3_tmpref_size); + printf(" in_operation_param3_memref_parent = 0x %16.16lx \n", in_operation_param3_memref_parent); + printf(" in_operation_param3_memref_size = 0x %8.8x \n", in_operation_param3_memref_size); + printf(" in_operation_param3_memref_offset = 0x %8.8x \n", in_operation_param3_memref_offset); + printf(" in_operation_param3_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param3_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param3_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param3_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param4_tmpref_buffer = 0x %16.16lx \n", in_operation_param4_tmpref_buffer); + printf(" in_operation_param4_tmpref_size = 0x %8.8x \n", in_operation_param4_tmpref_size); + printf(" in_operation_param4_memref_parent = 0x %16.16lx \n", in_operation_param4_memref_parent); + printf(" in_operation_param4_memref_size = 0x %8.8x \n", in_operation_param4_memref_size); + printf(" in_operation_param4_memref_offset = 0x %8.8x \n", in_operation_param4_memref_offset); + printf(" in_operation_param4_value_a = 0x %8.8x \n", in_operation_param4_value_a); + printf(" in_operation_param4_value_b = 0x %8.8x \n", in_operation_param4_value_b); + printf(" in_operation_param4_ionref_ionsharefd = 0x %8.8x \n", in_operation_param4_ionref_ionsharefd); + printf(" in_operation_param4_ionref_ionsize = 0x %8.8x \n", in_operation_param4_ionref_ionsize); + + printf(" in_operation_session = 0x %16.16lx \n", in_operation_session); + printf(" in_operation_cancelflag = 0x %8.8x \n", in_operation_cancelflag); + + printf(" in_returnorigin = 0x %8.8x \n", in_returnorigin); +#endif + printf(" in_context_addr = 0x %16.16lx \n", in_context_addr); + +#ifdef GP_WORKER + //////////////////////////////////////////////////////////////////////////////////////////////// + + TEEC_Context *contextIns; + tcn_t *tcnIns; + + TEEC_UUID destinationIns; + void *in_connectiondata_temp; + TEEC_Operation operationIns; + uint32_t origin; + TEEC_Result result; + + contextIns = NULL; + pthread_mutex_lock(mutex_tcl); + if (tcl->first != NULL) + { + tcnIns = tcl->first; + do + { + if (tcnIns->self->fd == in_fd) + { + contextIns = tcnIns->self; + break; + } + tcnIns = tcnIns->next; + } while (tcnIns != NULL); + } + pthread_mutex_unlock(mutex_tcl); + + if (contextIns == NULL) + { + if (tcl->first == NULL) + { + printf("The teec context list is null. \n"); + teecresult = TEEC_ERROR_CONTEXT_LIST_NULL; + } else + { + printf("Can't find the teec context. \n"); + teecresult = TEEC_ERROR_NO_CONTEXT_MATCH; + } + + fd = 0; + ta_path_size = 0; + ta_path = NULL; + charp = ta_path; + session_list_next = 0; + session_list_prev = 0; + shrd_mem_list_next = 0; + shrd_mem_list_prev = 0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0; + + seesionid = 0; + serviceid_timelow = 0; + serviceid_timemid = 0; + serviceid_timehiandver = 0; + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + opscnt = 0; + head_next = 0; + head_prev = 0; + context = 0; + + started = 0; + paramtypes = 0; + + operation_param1_tmpref_buffer = 0; + operation_param1_tmpref_size = 0; + operation_param1_memref_parent = 0; + operation_param1_memref_size = 0; + operation_param1_memref_offset = 0; + operation_param1_value_a = 0; + operation_param1_value_b = 0; + operation_param1_ionref_ionsharefd = 0; + operation_param1_ionref_ionsize = 0; + + operation_param2_tmpref_buffer = 0; + operation_param2_tmpref_size = 0; + operation_param2_memref_parent = 0; + operation_param2_memref_size = 0; + operation_param2_memref_offset = 0; + operation_param2_value_a = 0; + operation_param2_value_b = 0; + operation_param2_ionref_ionsharefd = 0; + operation_param2_ionref_ionsize = 0; + + operation_param3_tmpref_buffer = 0; + operation_param3_tmpref_size = 0; + operation_param3_memref_parent = 0; + operation_param3_memref_size = 0; + operation_param3_memref_offset = 0; + operation_param3_value_a = 0; + operation_param3_value_b = 0; + operation_param3_ionref_ionsharefd = 0; + operation_param3_ionref_ionsize = 0; + + operation_param4_tmpref_buffer = 0; + operation_param4_tmpref_size = 0; + operation_param4_memref_parent = 0; + operation_param4_memref_size = 0; + operation_param4_memref_offset = 0; + operation_param4_value_a = 0; + operation_param4_value_b = 0; + operation_param4_ionref_ionsharefd = 0; + operation_param4_ionref_ionsize = 0; + + operation_session = 0; + operation_cancelflag = 0; + + returnorigin = 0; + } else + { + TEEC_Session *sessionIns = (TEEC_Session *) malloc(sizeof(TEEC_Session)); + + // contextIns->fd = in_fd; + contextIns->ta_path = in_ta_path; + // typedef struct { + // volatile int __val[4*sizeof(long)/sizeof(int)]; + // } sem_t; + // + // typedef union + // { + // char __size[__SIZEOF_SEM_T]; + // long long int __align; + // } sem_t; + + destinationIns.timeLow = in_destination_timelow; + destinationIns.timeMid = in_destination_timemid; + destinationIns.timeHiAndVersion = in_destination_timehiandver; + for (int i = 0; + i < in_destination_clockseqandnode_size; + i++) + { + destinationIns.clockSeqAndNode[i] = in_destination_clockseqandnode[i]; + } + + in_connectiondata_temp = (void *) in_connectiondata; + // in_connectiondata_temp = NULL; + + + memset(&operationIns, 0, sizeof(operationIns)); + operationIns.started = in_operation_started; + operationIns.paramTypes = in_operation_paramtypes; + + origin = in_returnorigin; + + struct timeval start, end; + gettimeofday(&start, NULL); + result = + TEEC_OpenSession( + contextIns, + sessionIns, + &destinationIns, + in_connectionmethod, + in_connectiondata_temp, // NULL + &operationIns, + &origin + ); + gettimeofday(&end, NULL); + uint32_t cost = 0; + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (result != TEEC_SUCCESS) + { + printf("Teec OpenSession Failed. \n"); + printf(" teecresult = 0x %8.8x.\n", result); + + teecresult = result; + + fd = 0; + ta_path_size = 0; + ta_path = NULL; + charp = ta_path; + session_list_next = 0; + session_list_prev = 0; + shrd_mem_list_next = 0; + shrd_mem_list_prev = 0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0; + + seesionid = 0; + serviceid_timelow = 0; + serviceid_timemid = 0; + serviceid_timehiandver = 0; + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + opscnt = 0; + head_next = 0; + head_prev = 0; + context = 0; + + started = 0; + paramtypes = 0; + + operation_param1_tmpref_buffer = 0; + operation_param1_tmpref_size = 0; + operation_param1_memref_parent = 0; + operation_param1_memref_size = 0; + operation_param1_memref_offset = 0; + operation_param1_value_a = 0; + operation_param1_value_b = 0; + operation_param1_ionref_ionsharefd = 0; + operation_param1_ionref_ionsize = 0; + + operation_param2_tmpref_buffer = 0; + operation_param2_tmpref_size = 0; + operation_param2_memref_parent = 0; + operation_param2_memref_size = 0; + operation_param2_memref_offset = 0; + operation_param2_value_a = 0; + operation_param2_value_b = 0; + operation_param2_ionref_ionsharefd = 0; + operation_param2_ionref_ionsize = 0; + + operation_param3_tmpref_buffer = 0; + operation_param3_tmpref_size = 0; + operation_param3_memref_parent = 0; + operation_param3_memref_size = 0; + operation_param3_memref_offset = 0; + operation_param3_value_a = 0; + operation_param3_value_b = 0; + operation_param3_ionref_ionsharefd = 0; + operation_param3_ionref_ionsize = 0; + + operation_param4_tmpref_buffer = 0; + operation_param4_tmpref_size = 0; + operation_param4_memref_parent = 0; + operation_param4_memref_size = 0; + operation_param4_memref_offset = 0; + operation_param4_value_a = 0; + operation_param4_value_b = 0; + operation_param4_ionref_ionsharefd = 0; + operation_param4_ionref_ionsize = 0; + + operation_session = 0; + operation_cancelflag = 0; + + returnorigin = 0; + } else + { + printf("Teec OpenSession Succed, cost time: %ld us \n", cost); + + tsn_t *tsnIns = (tsn_t *) malloc(sizeof(tsn_t)); + tsnIns->self = sessionIns; + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + tsnIns->createtime = tvcreate; + pthread_mutex_lock(mutex_tsl); + if (tsl->first == NULL) + { + tsnIns->next = NULL; + tsnIns->prev = NULL; + tsl->first = tsnIns; + tsl->last = tsnIns; + tsl->count = 1; + } else + { + tsnIns->prev = tsl->last; + tsnIns->next = NULL; + tsl->last->next = tsnIns; + tsl->last = tsnIns; + tsl->count = tsl->count + 1; + } + pthread_mutex_unlock(mutex_tsl); + + teecresult = result; + + fd = contextIns->fd; + if (contextIns->ta_path != NULL) + { + ta_path_size = strlen((const char *) contextIns->ta_path); + } else + { + ta_path_size = 0; + } + ta_path = contextIns->ta_path; + charp = ta_path; + session_list_next = (dbus_uint64_t) contextIns->session_list.next; + session_list_prev = (dbus_uint64_t) contextIns->session_list.prev; + shrd_mem_list_next = (dbus_uint64_t) contextIns->shrd_mem_list.next; + shrd_mem_list_prev = (dbus_uint64_t) contextIns->shrd_mem_list.prev; + share_buffer_buffer = (dbus_uint64_t) contextIns->share_buffer.buffer; + share_buffer_buffer_barrier = contextIns->share_buffer.buffer_barrier.__align; + + seesionid = sessionIns->session_id; + serviceid_timelow = sessionIns->service_id.timeLow; + serviceid_timemid = sessionIns->service_id.timeMid; + serviceid_timehiandver = sessionIns->service_id.timeHiAndVersion; + if (sessionIns->service_id.clockSeqAndNode != NULL) + { + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < 8; iind++) + { + uint8_t u8Temp; + u8Temp = sessionIns->service_id.clockSeqAndNode[iind]; + serviceid_clockseqandnode[iind] = (dbus_uint32_t) u8Temp; + } + serviceid_clockseqandnode_outsize = 8; + } else + { + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + } + opscnt = sessionIns->ops_cnt; + head_next = (dbus_uint64_t) sessionIns->head.next; + head_prev = (dbus_uint64_t) sessionIns->head.prev; + context = (dbus_uint64_t) sessionIns->context; + + started = operationIns.started; + paramtypes = operationIns.paramTypes; + + operation_param1_tmpref_buffer = (dbus_uint64_t) operationIns.params[0].tmpref.buffer; + operation_param1_tmpref_size = operationIns.params[0].tmpref.size; + operation_param1_memref_parent = (dbus_uint64_t) operationIns.params[0].memref.parent; + operation_param1_memref_size = operationIns.params[0].memref.size; + operation_param1_memref_offset = operationIns.params[0].memref.offset; + operation_param1_value_a = operationIns.params[0].value.a; + operation_param1_value_b = operationIns.params[0].value.b; + operation_param1_ionref_ionsharefd = operationIns.params[0].ionref.ion_share_fd; + operation_param1_ionref_ionsize = operationIns.params[0].ionref.ion_size; + + operation_param2_tmpref_buffer = (dbus_uint64_t) operationIns.params[1].tmpref.buffer; + operation_param2_tmpref_size = operationIns.params[1].tmpref.size; + operation_param2_memref_parent = (dbus_uint64_t) operationIns.params[1].memref.parent; + operation_param2_memref_size = operationIns.params[1].memref.size; + operation_param2_memref_offset = operationIns.params[1].memref.offset; + operation_param2_value_a = operationIns.params[1].value.a; + operation_param2_value_b = operationIns.params[1].value.b; + operation_param2_ionref_ionsharefd = operationIns.params[1].ionref.ion_share_fd; + operation_param2_ionref_ionsize = operationIns.params[1].ionref.ion_size; + + operation_param3_tmpref_buffer = (dbus_uint64_t) operationIns.params[2].tmpref.buffer; + operation_param3_tmpref_size = operationIns.params[2].tmpref.size; + operation_param3_memref_parent = (dbus_uint64_t) operationIns.params[2].memref.parent; + operation_param3_memref_size = operationIns.params[2].memref.size; + operation_param3_memref_offset = operationIns.params[2].memref.offset; + operation_param3_value_a = operationIns.params[2].value.a; + operation_param3_value_b = operationIns.params[2].value.b; + operation_param3_ionref_ionsharefd = operationIns.params[2].ionref.ion_share_fd; + operation_param3_ionref_ionsize = operationIns.params[2].ionref.ion_size; + + operation_param4_tmpref_buffer = (dbus_uint64_t) operationIns.params[3].tmpref.buffer; + operation_param4_tmpref_size = operationIns.params[3].tmpref.size; + operation_param4_memref_parent = (dbus_uint64_t) operationIns.params[3].memref.parent; + operation_param4_memref_size = operationIns.params[3].memref.size; + operation_param4_memref_offset = operationIns.params[3].memref.offset; + operation_param4_value_a = operationIns.params[3].value.a; + operation_param4_value_b = operationIns.params[3].value.b; + operation_param4_ionref_ionsharefd = operationIns.params[3].ionref.ion_share_fd; + operation_param4_ionref_ionsize = operationIns.params[3].ionref.ion_size; + + operation_session = (dbus_uint64_t) operationIns.session; + operation_cancelflag = operationIns.cancel_flag; + + returnorigin = origin; + + printf(" ret sessionid = 0x %8.8x \n", seesionid); + printf(" ret context = 0x %16.16lx \n", context); + +#if 0 + printf("Call TEEC_CloseSession inputs: \n"); + printf(" session_seesionid = 0x %8.8x \n", sessionIns->session_id); + printf(" session_serviceid_timelow = 0x %8.8x \n", sessionIns->service_id.timeLow); + printf(" session_serviceid_timemid = 0x %4.4x \n", sessionIns->service_id.timeMid); + printf(" session_serviceid_timehiandver = 0x %4.4x \n", + sessionIns->service_id.timeHiAndVersion); + printf(" session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < 8; i++) { + printf(" %2.2x", sessionIns->service_id.clockSeqAndNode[i]); + } + printf("\n"); + printf(" session_opscnt = 0x %8.8x \n", sessionIns->ops_cnt); + printf(" session_head_next = 0x %16.16lx \n", sessionIns->head.next); + printf(" session_head_prev = 0x %16.16lx \n", sessionIns->head.prev); + printf(" session_context = 0x %16.16lx \n", sessionIns->context); + + // TEEC_CloseSession(sessionIns); + // printf("Teec CloseSession. \n"); +#endif + } + } + //////////////////////////////////////////////////////////////////////////////////////////////// +#else + ta_path = (unsigned char *)malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *)ta_path, 0, 1024); + uint32_t context_tapath_outsize; + uint32_t serviceid_clockseqandnode_outsize_temp; + uint32_t returnorigin_temp; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + + char workername[1024]; + memset((char *)workername, 0, 1024); + int ifound = 0; + int iworker; + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + if (workerrec[iworker].context_fd == in_fd && + workerrec[iworker].context_addr == in_context_addr + ) + { + sprintf(workername, "%s%d", "gpworker", iworker); + ifound = 1; + break; + } + } + pthread_mutex_unlock(mutex_workerrec); + + if (ifound == 0) + { + printf("Can't find the woker for the context. \n"); + + teecresult = 0xAAAA0017; + + fd = 0x0; + ta_path = NULL; + charp = ta_path; + session_list_next = 0x0; + session_list_prev = 0x0; + shrd_mem_list_next = 0x0; + shrd_mem_list_prev = 0x0; + share_buffer_buffer = 0; + share_buffer_buffer_barrier = 0x0; + + seesionid = 0x0; + serviceid_timelow = 0x0; + serviceid_timemid = 0x0; + serviceid_timehiandver = 0x0; + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < serviceid_clockseqandnode_realsize ; i++) { + serviceid_clockseqandnode[i] = 0x0; + } + serviceid_clockseqandnode_outsize = 0; + opscnt = 0x0; + head_next = 0x0; + head_prev = 0x0; + context = 0x0; + + started = 0x0; + paramtypes = 0x0; + + operation_param1_tmpref_buffer = 0x0; + operation_param1_tmpref_size = 0x0; + operation_param1_memref_parent = 0x0; + operation_param1_memref_size = 0x0; + operation_param1_memref_offset = 0x0; + operation_param1_value_a = 0x0; + operation_param1_value_b = 0x0; + operation_param1_ionref_ionsharefd = 0x0; + operation_param1_ionref_ionsize = 0x0; + + operation_param2_tmpref_buffer = 0x0; + operation_param2_tmpref_size = 0x0; + operation_param2_memref_parent = 0x0; + operation_param2_memref_size = 0x0; + operation_param2_memref_offset = 0x0; + operation_param2_value_a = 0x0; + operation_param2_value_b = 0x0; + operation_param2_ionref_ionsharefd = 0x0; + operation_param2_ionref_ionsize = 0x0; + + operation_param3_tmpref_buffer = 0x0; + operation_param3_tmpref_size = 0x0; + operation_param3_memref_parent = 0x0; + operation_param3_memref_size = 0x0; + operation_param3_memref_offset = 0x0; + operation_param3_value_a = 0x0; + operation_param3_value_b = 0x0; + operation_param3_ionref_ionsharefd = 0x0; + operation_param3_ionref_ionsize = 0x0; + + operation_param4_tmpref_buffer = 0x0; + operation_param4_tmpref_size = 0x0; + operation_param4_memref_parent = 0x0; + operation_param4_memref_size = 0x0; + operation_param4_memref_offset = 0x0; + operation_param4_value_a = 0x0; + operation_param4_value_b = 0x0; + operation_param4_ionref_ionsharefd = 0x0; + operation_param4_ionref_ionsize = 0x0; + + operation_session = 0x0; + operation_cancelflag = 0x0; + + returnorigin = 0x0; + } + else + { + method_call_teec_opensession( + workername, + + in_fd, + in_ta_path, + in_ta_path_size, + in_session_list_next, + in_session_list_prev, + in_shrd_mem_list_next, + in_shrd_mem_list_prev, + in_share_buffer_buffer, + in_share_buffer_buffer_barrier, + + in_destination_timelow, + in_destination_timemid, + in_destination_timehiandver, + in_destination_clockseqandnode, + in_destination_clockseqandnode_realsize, + + in_connectionmethod, + in_connectiondata, + + in_operation_started, + in_operation_paramtypes, + + in_operation_param1_tmpref_buffer, + in_operation_param1_tmpref_size, + in_operation_param1_memref_parent, + in_operation_param1_memref_size, + in_operation_param1_memref_offset, + in_operation_param1_value_a, + in_operation_param1_value_b, + in_operation_param1_ionref_ionsharefd, + in_operation_param1_ionref_ionsize, + + in_operation_param2_tmpref_buffer, + in_operation_param2_tmpref_size, + in_operation_param2_memref_parent, + in_operation_param2_memref_size, + in_operation_param2_memref_offset, + in_operation_param2_value_a, + in_operation_param2_value_b, + in_operation_param2_ionref_ionsharefd, + in_operation_param2_ionref_ionsize, + + in_operation_param3_tmpref_buffer, + in_operation_param3_tmpref_size, + in_operation_param3_memref_parent, + in_operation_param3_memref_size, + in_operation_param3_memref_offset, + in_operation_param3_value_a, + in_operation_param3_value_b, + in_operation_param3_ionref_ionsharefd, + in_operation_param3_ionref_ionsize, + + in_operation_param4_tmpref_buffer, + in_operation_param4_tmpref_size, + in_operation_param4_memref_parent, + in_operation_param4_memref_size, + in_operation_param4_memref_offset, + in_operation_param4_value_a, + in_operation_param4_value_b, + in_operation_param4_ionref_ionsharefd, + in_operation_param4_ionref_ionsize, + + in_operation_session, + in_operation_cancelflag, + + in_returnorigin, + + in_context_addr, + + + &teecresult, + + &fd, + ta_path, + ta_path_size, + &context_tapath_outsize, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + + &seesionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &context, + + &started, + ¶mtypes, + + &operation_param1_tmpref_buffer, + &operation_param1_tmpref_size, + &operation_param1_memref_parent, + &operation_param1_memref_size, + &operation_param1_memref_offset, + &operation_param1_value_a, + &operation_param1_value_b, + &operation_param1_ionref_ionsharefd, + &operation_param1_ionref_ionsize, + + &operation_param2_tmpref_buffer, + &operation_param2_tmpref_size, + &operation_param2_memref_parent, + &operation_param2_memref_size, + &operation_param2_memref_offset, + &operation_param2_value_a, + &operation_param2_value_b, + &operation_param2_ionref_ionsharefd, + &operation_param2_ionref_ionsize, + + &operation_param3_tmpref_buffer, + &operation_param3_tmpref_size, + &operation_param3_memref_parent, + &operation_param3_memref_size, + &operation_param3_memref_offset, + &operation_param3_value_a, + &operation_param3_value_b, + &operation_param3_ionref_ionsharefd, + &operation_param3_ionref_ionsize, + + &operation_param4_tmpref_buffer, + &operation_param4_tmpref_size, + &operation_param4_memref_parent, + &operation_param4_memref_size, + &operation_param4_memref_offset, + &operation_param4_value_a, + &operation_param4_value_b, + &operation_param4_ionref_ionsharefd, + &operation_param4_ionref_ionsize, + + &operation_session, + &operation_cancelflag, + + &returnorigin_temp + ); + + if (teecresult == 0) { + pthread_mutex_lock(mutex_workerrec); + + sin_t * sinIns = (sin_t *)malloc(sizeof(sin_t)); + sinIns->session_id = seesionid; + struct timeval tvcreate; + gettimeofday(&tvcreate, NULL); + sinIns->session_createtime = tvcreate; + if (workerrec[iworker].first == NULL) + { + sinIns->next = NULL; + sinIns->prev = NULL; + workerrec[iworker].first = sinIns; + workerrec[iworker].last = sinIns; + workerrec[iworker].sessionid_count = 1; + } + else + { + sinIns->prev = workerrec[iworker].last; + sinIns->next = NULL; + workerrec[iworker].last->next = sinIns; + workerrec[iworker].last = sinIns; + workerrec[iworker].sessionid_count = + workerrec[iworker].sessionid_count + 1; + } + pthread_mutex_unlock(mutex_workerrec); + } + + serviceid_clockseqandnode_outsize = + serviceid_clockseqandnode_outsize_temp; + returnorigin = returnorigin_temp; + + if (ta_path_size >= context_tapath_outsize) { + ta_path_size = context_tapath_outsize; + charp = ta_path; + } + else + { + ta_path_size = 0; + charp = NULL; + } + + if ( + serviceid_clockseqandnode_realsize >= serviceid_clockseqandnode_outsize && + 8 >= serviceid_clockseqandnode_outsize + ) + { + serviceid_clockseqandnode_realsize = serviceid_clockseqandnode_outsize; + } + else + { + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode_outsize = 0; + } + + } // end of else found == 1 + + //////////////////////////////////////////////////////////////////////////////////////////////// +#endif + + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &teecresult + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &fd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + DBusError err; + // initialise the errors + dbus_error_init(&err); + + if (ta_path_size > 0 && + charp != NULL && + strlen((const char *) charp) > 0 + ) + { + if (dbus_validate_utf8((const char *) charp, &err) == true) + { + ta_path_size = strlen((const char *) charp); + } else + { + ta_path_size = 0; + } + } else + { + ta_path_size = 0; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &ta_path_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (ta_path_size > 0) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &charp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &session_list_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &session_list_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &shrd_mem_list_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &shrd_mem_list_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &share_buffer_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &share_buffer_buffer_barrier + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &seesionid + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timelow + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timemid + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timehiandver + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_clockseqandnode_outsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize + ); + + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &opscnt + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &head_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &head_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &context + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &started + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + ¶mtypes + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param1_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param1_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param1_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param2_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param2_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param2_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param3_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param3_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param3_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param4_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param4_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param4_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_session + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_cancelflag + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &returnorigin + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send the reply && flush the connection + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + // dbus_connection_close(conn); + // dbus_connection_unref(conn); + free(thdfargs); + + // sleep(2); + +#if 0 + #ifdef GP_WORKER + +#else + if (ta_path == NULL) + { + free(ta_path); + } + if (serviceid_clockseqandnode == NULL) + { + free(serviceid_clockseqandnode); + } +#endif +#endif + + return NULL; +} + + +void * +reply_to_method_call_teec_closesession( + void *thdfargs +) +{ + DBusMsgConn *DBusMCP; + DBusMessage *msg; + DBusConnection *conn; + DBusMessage *reply; + DBusMessageIter args; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int iType; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + dbus_uint32_t in_session_seesionid; + dbus_uint32_t in_session_serviceid_timelow; + dbus_uint32_t in_session_serviceid_timemid; + dbus_uint32_t in_session_serviceid_timehiandver; + dbus_uint32_t in_session_serviceid_clockseqandnode_size; + dbus_uint32_t *in_session_serviceid_clockseqandnode; + int in_session_serviceid_clockseqandnode_realsize; + dbus_uint32_t in_session_opscnt; + dbus_uint64_t in_session_head_next; + dbus_uint64_t in_session_head_prev; + dbus_uint64_t in_session_context; + + dbus_uint32_t seesionid; + dbus_uint32_t serviceid_timelow; + dbus_uint32_t serviceid_timemid; + dbus_uint32_t serviceid_timehiandver; + dbus_uint32_t *serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + dbus_int32_t serviceid_clockseqandnode_outsize; + dbus_uint32_t opscnt; + dbus_uint64_t head_next; + dbus_uint64_t head_prev; + dbus_uint64_t context; + + dbus_uint32_t serial = 0; + +#ifdef GP_PROXY + pthread_mutex_t * mutex_workerrec; + wr_t * workerrec; +#endif + +#ifdef GP_WORKER + pthread_mutex_t *mutex_tcl; + pthread_mutex_t *mutex_tsl; + tcl_t *tcl; + tsl_t *tsl; +#endif + + DBusMCP = (DBusMsgConn *) thdfargs; + msg = DBusMCP->msg; + conn = DBusMCP->conn; +#ifdef GP_PROXY + mutex_workerrec = DBusMCP->mutex_workerrec; + workerrec = DBusMCP->workerrec; +#endif +#ifdef GP_WORKER + mutex_tcl = DBusMCP->mutex_tcl; + mutex_tsl = DBusMCP->mutex_tsl; + tcl = DBusMCP->tcl; + tsl = DBusMCP->tsl; +#endif + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_get_basic( + &structIter, + &in_session_seesionid); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_timelow + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_timemid); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_timehiandver); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_clockseqandnode_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (in_session_serviceid_clockseqandnode_size > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &in_session_serviceid_clockseqandnode, + &in_session_serviceid_clockseqandnode_realsize + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_get_basic( + &structIter, + &in_session_opscnt); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_head_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_head_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_context); + + printf("Received method call Teec Close Session: \n"); + printf(" in_session_seesionid = 0x %8.8x \n", in_session_seesionid); +#if 0 + printf(" in_session_serviceid_timelow = 0x %8.8x \n", in_session_serviceid_timelow); + printf(" in_session_serviceid_timemid = 0x %8.8x \n", in_session_serviceid_timemid); + printf(" in_session_serviceid_timehiandver = 0x %8.8x \n", + in_session_serviceid_timehiandver); + printf(" in_session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < in_session_serviceid_clockseqandnode_realsize; i++) { + printf(" %8.8x", in_session_serviceid_clockseqandnode[i]); + } + printf("\n"); + printf(" in_session_serviceid_clockseqandnode_size = 0x %8.8x \n", + in_session_serviceid_clockseqandnode_size); + printf(" in_session_opscnt = 0x %8.8x \n", in_session_opscnt); + printf(" in_session_head_next = 0x %16.16lx \n", in_session_head_next); + printf(" in_session_head_prev = 0x %16.16lx \n", in_session_head_prev); +#endif + printf(" in_session_context = 0x %16.16lx \n", in_session_context); + + +#ifdef GP_WORKER + //////////////////////////////////////////////////////////////////////////////////////////////// + + + TEEC_Session *sessionIns; + tsn_t *tsnIns; + + sessionIns = NULL; + pthread_mutex_lock(mutex_tsl); + if (tsl->first != NULL) + { + tsnIns = tsl->first; + do + { + if (tsnIns->self->session_id == in_session_seesionid) + { + sessionIns = tsnIns->self; + break; + } + tsnIns = tsnIns->next; + } while (tsnIns != NULL); + } + pthread_mutex_unlock(mutex_tsl); + + if (sessionIns == NULL) + { + if (tsl->first == NULL) + { + printf("The teec session list is null. \n"); + // teecresult = TEEC_ERROR_SESSION_LIST_NULL; + } else + { + printf("Can't find the teec session. \n"); + // teecresult = TEEC_ERROR_NO_SESSION_MATCH; + } + + seesionid = 0x0; + serviceid_timelow = 0x0; + serviceid_timemid = 0x0; + serviceid_timehiandver = 0x0; + opscnt = 0x0; + head_next = 0x0; + head_prev = 0x0; + context = 0x0; + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < serviceid_clockseqandnode_realsize; i++) + { + serviceid_clockseqandnode[i] = 0x0; + } + serviceid_clockseqandnode_outsize = 8; + } else + { + sessionIns->session_id = in_session_seesionid; +#if 0 + sessionIns->service_id.timeLow = in_session_serviceid_timelow; + sessionIns->service_id.timeMid = in_session_serviceid_timemid; + sessionIns->service_id.timeHiAndVersion = in_session_serviceid_timehiandver; + if ( in_session_serviceid_clockseqandnode_realsize <= 8 && + in_session_serviceid_clockseqandnode_realsize > 0 && + in_session_serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < in_session_serviceid_clockseqandnode_realsize; i++) { + sessionIns->service_id.clockSeqAndNode[i] = + (uint8_t)(in_session_serviceid_clockseqandnode[i] & 0x000000ff); + } + } + else + { + for (int i = 0; i < 8; i++) { + sessionIns->service_id.clockSeqAndNode[i] = 0; + } + } + sessionIns->ops_cnt = in_session_opscnt; + sessionIns->head.next = (struct ListNode *)in_session_head_next; + sessionIns->head.prev = (struct ListNode *)in_session_head_prev; + // sessionIns->context = (TEEC_Context *)in_session_context; +#endif + +#if 0 + printf("Call TEEC_CloseSession inputs: \n"); + printf(" session_seesionid = 0x %8.8x \n", sessionIns->session_id); + printf(" session_serviceid_timelow = 0x %8.8x \n", sessionIns->service_id.timeLow); + printf(" session_serviceid_timemid = 0x %4.4x \n", sessionIns->service_id.timeMid); + printf(" session_serviceid_timehiandver = 0x %4.4x \n", + sessionIns->service_id.timeHiAndVersion); + printf(" session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < 8; i++) { + printf(" %2.2x", sessionIns->service_id.clockSeqAndNode[i]); + } + printf("\n"); + printf(" session_opscnt = 0x %8.8x \n", sessionIns->ops_cnt); + printf(" session_head_next = 0x %16.16lx \n", sessionIns->head.next); + printf(" session_head_prev = 0x %16.16lx \n", sessionIns->head.prev); + printf(" session_context = 0x %16.16lx \n", sessionIns->context); +#endif + struct timeval start, end; + gettimeofday(&start, NULL); + TEEC_CloseSession( + sessionIns + ); + gettimeofday(&end, NULL); + uint32_t cost = 0; + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + printf("Teec CloseSession executed, cost time: %ld us \n", cost); + + seesionid = sessionIns->session_id; + serviceid_timelow = sessionIns->service_id.timeLow; + serviceid_timemid = sessionIns->service_id.timeMid; + serviceid_timehiandver = sessionIns->service_id.timeHiAndVersion; +#if 0 + printf(" in_session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < 8; i++) { + printf(" %2.2x", in_session_serviceid_clockseqandnode[i]); + } + printf("\n"); +#endif + if (sessionIns->service_id.clockSeqAndNode != NULL) + { + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < 8; iind++) + { + uint8_t u8Temp; + u8Temp = sessionIns->service_id.clockSeqAndNode[iind]; + serviceid_clockseqandnode[iind] = (dbus_uint32_t) u8Temp; + } + serviceid_clockseqandnode_outsize = 8; + } else + { + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + } + opscnt = sessionIns->ops_cnt; + head_next = (dbus_uint64_t) sessionIns->head.next; + head_prev = (dbus_uint64_t) sessionIns->head.prev; + context = (dbus_uint64_t) sessionIns->context; + + printf(" ret sessionid = 0x %8.8x \n", seesionid); + printf(" ret context = 0x %16.16lx \n", context); + + tsn_t *tsnTemp; + tsnTemp = tsnIns->prev; + if (tsnTemp != NULL) + { + tsnTemp->next = tsnIns->next; + } + tsnTemp = tsnIns->next; + if (tsnTemp != NULL) + { + tsnTemp->prev = tsnIns->prev; + } + pthread_mutex_lock(mutex_tsl); + if (tsl->last == tsnIns) + { + tsl->last = tsnIns->prev; + } + if (tsl->first == tsnIns) + { + tsl->first = tsnIns->next; + } + tsl->count = tsl->count - 1; + pthread_mutex_unlock(mutex_tsl); + free(sessionIns); + free(tsnIns); + } + //////////////////////////////////////////////////////////////////////////////////////////////// +#else + + uint32_t serviceid_clockseqandnode_outsize_temp; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + + char workername[1024]; + memset((char *)workername, 0, 1024); + // sprintf(workername, "%s", "gpworker1"); + int ifound = 0; + int iworker; + sin_t * sinIns; + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + if (workerrec[iworker].context_addr == in_session_context) + { + sinIns = NULL; + if (workerrec[iworker].first != NULL) + { + sinIns = workerrec[iworker].first; + do + { + if (sinIns->session_id == in_session_seesionid) + { + sprintf(workername, "%s%d", "gpworker", iworker); + ifound = 1; + break; + } + sinIns = sinIns->next; + }while (sinIns != NULL); + + + if ( ifound == 1 ) + { + break; + } + } + } + } + pthread_mutex_unlock(mutex_workerrec); + + + if (ifound == 0) + { + printf("Can't find the worker for the session and the context. \n"); + + seesionid = 0x0; + serviceid_timelow = 0x0; + serviceid_timemid = 0x0; + serviceid_timehiandver = 0x0; + opscnt = 0x0; + head_next = 0x0; + head_prev = 0x0; + context = 0x0; + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < serviceid_clockseqandnode_realsize ; i++) { + serviceid_clockseqandnode[i] = 0x0; + } + serviceid_clockseqandnode_outsize = 8; + } + else + { + method_call_teec_closesession( + workername, + + in_session_seesionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_realsize, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + &seesionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &context + ); + + pthread_mutex_lock(mutex_workerrec); + sin_t * sinTemp; + sinTemp = sinIns->prev; + if (sinTemp != NULL) + { + sinTemp->next = sinIns->next; + } + sinTemp = sinIns->next; + if (sinTemp != NULL) + { + sinTemp->prev = sinIns->prev; + } + if (workerrec[iworker].last == sinIns) + { + workerrec[iworker].last = sinIns->prev; + } + if (workerrec[iworker].first == sinIns) + { + workerrec[iworker].first = sinIns->next; + } + free(sinIns); + workerrec[iworker].sessionid_count = + workerrec[iworker].sessionid_count - 1; + pthread_mutex_unlock(mutex_workerrec); + + serviceid_clockseqandnode_outsize = serviceid_clockseqandnode_outsize_temp; + + if ( + serviceid_clockseqandnode_realsize >= serviceid_clockseqandnode_outsize && + 8 >= serviceid_clockseqandnode_outsize + ) + { + serviceid_clockseqandnode_realsize = serviceid_clockseqandnode_outsize; + } + else + { + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode_outsize = 0; + } + + }// end of else found == 1 +#endif + + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &seesionid + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timelow + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timemid + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timehiandver + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_clockseqandnode_outsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize + ); + + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &opscnt + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &head_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &head_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &context + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send the reply && flush the connection + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + // dbus_connection_close(conn); + // dbus_connection_unref(conn); + free(thdfargs); + + // sleep(2); + + return NULL; +} + + +void * +reply_to_method_call_teec_invokecommand( + void *thdfargs +) +{ + DBusMsgConn *DBusMCP; + DBusMessage *msg; + DBusConnection *conn; + DBusMessage *reply; + DBusMessageIter args; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int iType; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + dbus_uint32_t in_session_sessionid; + dbus_uint32_t in_session_serviceid_timelow; + dbus_uint32_t in_session_serviceid_timemid; + dbus_uint32_t in_session_serviceid_timehiandver; + dbus_uint32_t in_session_serviceid_clockseqandnode_size; + dbus_uint32_t *in_session_serviceid_clockseqandnode; + int in_session_serviceid_clockseqandnode_realsize; + dbus_uint32_t in_session_opscnt; + dbus_uint64_t in_session_head_next; + dbus_uint64_t in_session_head_prev; + dbus_uint64_t in_session_context; + + dbus_uint32_t in_commandid; + + dbus_uint32_t in_operation_started; + dbus_uint32_t in_operation_paramtypes; + + dbus_uint64_t in_operation_param1_tmpref_buffer; + dbus_uint32_t in_operation_param1_tmpref_size; + dbus_uint64_t in_operation_param1_memref_parent; + dbus_uint32_t in_operation_param1_memref_parent_flag; + dbus_uint32_t in_operation_param1_memref_size; + dbus_uint32_t in_operation_param1_memref_offset; + dbus_uint32_t in_operation_param1_value_a; + dbus_uint32_t in_operation_param1_value_b; + dbus_int32_t in_operation_param1_ionref_ionsharefd; + dbus_uint32_t in_operation_param1_ionref_ionsize; + + dbus_uint64_t in_operation_param2_tmpref_buffer; + dbus_uint32_t in_operation_param2_tmpref_size; + dbus_uint64_t in_operation_param2_memref_parent; + dbus_uint32_t in_operation_param2_memref_parent_flag; + dbus_uint32_t in_operation_param2_memref_size; + dbus_uint32_t in_operation_param2_memref_offset; + dbus_uint32_t in_operation_param2_value_a; + dbus_uint32_t in_operation_param2_value_b; + dbus_int32_t in_operation_param2_ionref_ionsharefd; + dbus_uint32_t in_operation_param2_ionref_ionsize; + + dbus_uint64_t in_operation_param3_tmpref_buffer; + dbus_uint32_t in_operation_param3_tmpref_size; + dbus_uint64_t in_operation_param3_memref_parent; + dbus_uint32_t in_operation_param3_memref_parent_flag; + dbus_uint32_t in_operation_param3_memref_size; + dbus_uint32_t in_operation_param3_memref_offset; + dbus_uint32_t in_operation_param3_value_a; + dbus_uint32_t in_operation_param3_value_b; + dbus_int32_t in_operation_param3_ionref_ionsharefd; + dbus_uint32_t in_operation_param3_ionref_ionsize; + + dbus_uint64_t in_operation_param4_tmpref_buffer; + dbus_uint32_t in_operation_param4_tmpref_size; + dbus_uint64_t in_operation_param4_memref_parent; + dbus_uint32_t in_operation_param4_memref_parent_flag; + dbus_uint32_t in_operation_param4_memref_size; + dbus_uint32_t in_operation_param4_memref_offset; + dbus_uint32_t in_operation_param4_value_a; + dbus_uint32_t in_operation_param4_value_b; + dbus_int32_t in_operation_param4_ionref_ionsharefd; + dbus_uint32_t in_operation_param4_ionref_ionsize; + + dbus_uint64_t in_operation_session; + dbus_int32_t in_operation_cancelflag; + + dbus_uint32_t in_returnorigin; + + dbus_uint32_t in_buffer1_size; + dbus_uint32_t *in_buffer1; + int in_buffer1_realsize; + dbus_uint32_t in_buffer2_size; + dbus_uint32_t *in_buffer2; + int in_buffer2_realsize; + dbus_uint32_t in_buffer3_size; + dbus_uint32_t *in_buffer3; + int in_buffer3_realsize; + dbus_uint32_t in_buffer4_size; + dbus_uint32_t *in_buffer4; + int in_buffer4_realsize; + + dbus_uint32_t teecresult; + + dbus_uint32_t sessionid; + dbus_uint32_t serviceid_timelow; + dbus_uint32_t serviceid_timemid; + dbus_uint32_t serviceid_timehiandver; + dbus_uint32_t *serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + dbus_uint32_t serviceid_clockseqandnode_outsize; + dbus_uint32_t opscnt; + dbus_uint64_t head_next; + dbus_uint64_t head_prev; + dbus_uint64_t context; + + dbus_uint32_t started; + dbus_uint32_t paramtypes; + + dbus_uint64_t operation_param1_tmpref_buffer; + dbus_uint32_t operation_param1_tmpref_size; + dbus_uint64_t operation_param1_memref_parent; + dbus_uint32_t operation_param1_memref_parent_flag; + dbus_uint32_t operation_param1_memref_size; + dbus_uint32_t operation_param1_memref_offset; + dbus_uint32_t operation_param1_value_a; + dbus_uint32_t operation_param1_value_b; + dbus_int32_t operation_param1_ionref_ionsharefd; + dbus_uint32_t operation_param1_ionref_ionsize; + + dbus_uint64_t operation_param2_tmpref_buffer; + dbus_uint32_t operation_param2_tmpref_size; + dbus_uint64_t operation_param2_memref_parent; + dbus_uint32_t operation_param2_memref_parent_flag; + dbus_uint32_t operation_param2_memref_size; + dbus_uint32_t operation_param2_memref_offset; + dbus_uint32_t operation_param2_value_a; + dbus_uint32_t operation_param2_value_b; + dbus_int32_t operation_param2_ionref_ionsharefd; + dbus_uint32_t operation_param2_ionref_ionsize; + + dbus_uint64_t operation_param3_tmpref_buffer; + dbus_uint32_t operation_param3_tmpref_size; + dbus_uint64_t operation_param3_memref_parent; + dbus_uint32_t operation_param3_memref_parent_flag; + dbus_uint32_t operation_param3_memref_size; + dbus_uint32_t operation_param3_memref_offset; + dbus_uint32_t operation_param3_value_a; + dbus_uint32_t operation_param3_value_b; + dbus_int32_t operation_param3_ionref_ionsharefd; + dbus_uint32_t operation_param3_ionref_ionsize; + + dbus_uint64_t operation_param4_tmpref_buffer; + dbus_uint32_t operation_param4_tmpref_size; + dbus_uint64_t operation_param4_memref_parent; + dbus_uint32_t operation_param4_memref_parent_flag; + dbus_uint32_t operation_param4_memref_size; + dbus_uint32_t operation_param4_memref_offset; + dbus_uint32_t operation_param4_value_a; + dbus_uint32_t operation_param4_value_b; + dbus_int32_t operation_param4_ionref_ionsharefd; + dbus_uint32_t operation_param4_ionref_ionsize; + + dbus_uint64_t operation_session; + dbus_int32_t operation_cancelflag; + + dbus_uint32_t returnorigin; + + dbus_uint32_t *buffer1; + int buffer1_realsize; + dbus_uint32_t buffer1_outsize; + dbus_uint32_t *buffer2; + int buffer2_realsize; + dbus_uint32_t buffer2_outsize; + dbus_uint32_t *buffer3; + int buffer3_realsize; + dbus_uint32_t buffer3_outsize; + dbus_uint32_t *buffer4; + int buffer4_realsize; + dbus_uint32_t buffer4_outsize; + + dbus_uint32_t serial = 0; + +#ifdef GP_PROXY + pthread_mutex_t * mutex_workerrec; + wr_t * workerrec; +#endif + +#ifdef GP_WORKER + pthread_mutex_t *mutex_tcl; + pthread_mutex_t *mutex_tsl; + tcl_t *tcl; + tsl_t *tsl; +#endif + + DBusMCP = (DBusMsgConn *) thdfargs; + msg = DBusMCP->msg; + conn = DBusMCP->conn; +#ifdef GP_PROXY + mutex_workerrec = DBusMCP->mutex_workerrec; + workerrec = DBusMCP->workerrec; +#endif +#ifdef GP_WORKER + mutex_tcl = DBusMCP->mutex_tcl; + mutex_tsl = DBusMCP->mutex_tsl; + tcl = DBusMCP->tcl; + tsl = DBusMCP->tsl; +#endif + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_sessionid); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_timelow + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_timemid); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_timehiandver); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_serviceid_clockseqandnode_size); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (in_session_serviceid_clockseqandnode_size > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &in_session_serviceid_clockseqandnode, + &in_session_serviceid_clockseqandnode_realsize + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_get_basic( + &structIter, + &in_session_opscnt); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_head_next); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_head_prev); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_session_context); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_commandid); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_started); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_paramtypes); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_tmpref_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_tmpref_size); + + bResult = dbus_message_iter_next(&structIter); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT64) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_memref_parent); + + bResult = dbus_message_iter_next(&structIter); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32. \n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_memref_parent_flag); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_memref_size); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_value_a); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_value_b); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param1_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_tmpref_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_tmpref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_memref_parent); + + bResult = dbus_message_iter_next(&structIter); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32. \n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_memref_parent_flag); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_memref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_value_a); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_value_b); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param2_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_tmpref_buffer); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_tmpref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_memref_parent); + + bResult = dbus_message_iter_next(&structIter); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32. \n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_memref_parent_flag); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_memref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_value_a); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_value_b); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param3_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_tmpref_buffer); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_tmpref_size); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_memref_parent); + + bResult = dbus_message_iter_next(&structIter); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32. \n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_memref_parent_flag); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_memref_size); + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_memref_offset); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_value_a); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_value_b); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_ionref_ionsharefd); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_param4_ionref_ionsize); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_session); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_operation_cancelflag); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_returnorigin); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_buffer1_size); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (in_buffer1_size > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &in_buffer1, + &in_buffer1_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_buffer2_size); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (in_buffer2_size > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &in_buffer2, + &in_buffer2_realsize + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_buffer3_size); + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (in_buffer3_size > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &in_buffer3, + &in_buffer3_realsize + ); + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_basic( + &structIter, + &in_buffer4_size); + + if (in_buffer4_size > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32, line %d. \n", __LINE__); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &in_buffer4, + &in_buffer4_realsize + ); + } + + printf("Received method call TEEC_InvokeCommand: \n"); + printf(" in_session_sessionid = 0x %8.8x \n", in_session_sessionid); +#if 0 + printf(" in_session_serviceid_timelow = 0x %8.8x \n", in_session_serviceid_timelow); + printf(" in_session_serviceid_timemid = 0x %8.8x \n", in_session_serviceid_timemid); + printf(" in_session_serviceid_timehiandver = 0x %8.8x \n", + in_session_serviceid_timehiandver); + printf(" in_session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < in_session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", in_session_serviceid_clockseqandnode[i]); + } + printf("\n"); + printf(" in serviceid_clockseqandnode_size = 0x %8.8x \n", + in_session_serviceid_clockseqandnode_size); + printf(" in_session_opscnt = 0x %8.8x \n", in_session_opscnt); + printf(" in_session_head_next = 0x %16.16lx \n", in_session_head_next); + printf(" in_session_head_prev = 0x %16.16lx \n", in_session_head_prev); +#endif + printf(" in_session_context = 0x %16.16lx \n", in_session_context); +#if 0 + printf(" commandid = 0x %8.8x \n", in_commandid); + + printf(" in_operation_started = 0x %8.8x \n", in_operation_started); + printf(" in_operation_paramtypes = 0x %8.8x \n", in_operation_paramtypes); + + printf(" in_operation_param1_tmpref_buffer = 0x %16.16lx \n", in_operation_param1_tmpref_buffer); + printf(" in_operation_param1_tmpref_size = 0x %8.8x \n", in_operation_param1_tmpref_size); + printf(" in_operation_param1_memref_parent = 0x %16.16lx \n", in_operation_param1_memref_parent); + printf(" in_operation_param1_memref_size = 0x %8.8x \n", in_operation_param1_memref_size); + printf(" in_operation_param1_memref_offset = 0x %8.8x \n", in_operation_param1_memref_offset); + printf(" in_operation_param1_value_a = 0x %8.8x \n", in_operation_param1_value_a); + printf(" in_operation_param1_value_b = 0x %8.8x \n", in_operation_param1_value_b); + printf(" in_operation_param1_ionref_ionsharefd = 0x %8.8x \n",in_operation_param2_ionref_ionsharefd); + printf(" in_operation_param1_ionref_ionsize = 0x %8.8x \n", in_operation_param2_ionref_ionsize); + + printf(" in_operation_param2_tmpref_buffer = 0x %16.16lx \n", in_operation_param2_tmpref_buffer); + printf(" in_operation_param2_tmpref_size = 0x %8.8x \n", in_operation_param2_tmpref_size); + printf(" in_operation_param2_memref_parent = 0x %16.16lx \n", in_operation_param2_memref_parent); + printf(" in_operation_param2_memref_size = 0x %8.8x \n", in_operation_param2_memref_size); + printf(" in_operation_param2_memref_offset = 0x %8.8x \n", in_operation_param2_memref_offset); + printf(" in_operation_param2_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param2_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param2_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param2_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param3_tmpref_buffer = 0x %16.16lx \n", in_operation_param3_tmpref_buffer); + printf(" in_operation_param3_tmpref_size = 0x %8.8x \n", in_operation_param3_tmpref_size); + printf(" in_operation_param3_memref_parent = 0x %16.16lx \n", in_operation_param3_memref_parent); + printf(" in_operation_param3_memref_size = 0x %8.8x \n", in_operation_param3_memref_size); + printf(" in_operation_param3_memref_offset = 0x %8.8x \n", in_operation_param3_memref_offset); + printf(" in_operation_param3_value_a = 0x %8.8x \n", in_operation_param3_value_a); + printf(" in_operation_param3_value_b = 0x %8.8x \n", in_operation_param3_value_b); + printf(" in_operation_param3_ionref_ionsharefd = 0x %8.8x \n", in_operation_param3_ionref_ionsharefd); + printf(" in_operation_param3_ionref_ionsize = 0x %8.8x \n", in_operation_param3_ionref_ionsize); + + printf(" in_operation_param4_tmpref_buffer = 0x %16.16lx \n", in_operation_param4_tmpref_buffer); + printf(" in_operation_param4_tmpref_size = 0x %8.8x \n", in_operation_param4_tmpref_size); + printf(" in_operation_param4_memref_parent = 0x %16.16lx \n", in_operation_param4_memref_parent); + printf(" in_operation_param4_memref_size = 0x %8.8x \n", in_operation_param4_memref_size); + printf(" in_operation_param4_memref_offset = 0x %8.8x \n", in_operation_param4_memref_offset); + printf(" in_operation_param4_value_a = 0x %8.8x \n", in_operation_param4_value_a); + printf(" in_operation_param4_value_b = 0x %8.8x \n", in_operation_param4_value_b); + printf(" in_operation_param4_ionref_ionsharefd = 0x %8.8x \n", in_operation_param4_ionref_ionsharefd); + printf(" in_operation_param4_ionref_ionsize = 0x %8.8x \n", in_operation_param4_ionref_ionsize); + + printf(" in_operation_session = 0x %16.16lx \n", in_operation_session); + printf(" in_operation_cancelflag = 0x %8.8x \n", in_operation_cancelflag); + + printf(" in_returnorigin = 0x %8.8x \n", in_returnorigin); + + printf(" in_buffer1 = \n"); + if (in_buffer1_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer1_realsize; i++) { + printf(" %2.2x", in_buffer1[i]); + } + printf("\n"); + } +#endif + +#if 0 + printf(" in_buffer1_size = 0x %8.8x \n", + in_buffer1_size); +#endif + +#if 0 + printf(" in_buffer2 = \n"); + if (in_buffer2_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer2_realsize; i++) { + printf(" %2.2x", in_buffer2[i]); + } + printf("\n"); + } + printf(" in_buffer2_size = 0x %8.8x \n", + in_buffer2_size); + + printf(" in_buffer3 = \n"); + if (in_buffer3_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer3_realsize; i++) { + printf(" %2.2x", in_buffer3[i]); + } + printf("\n"); + } + printf(" in_buffer3_size = 0x %8.8x \n", + in_buffer3_size); + + printf(" in_buffer4 = \n"); + if (in_buffer4_size > 0) { + printf(" "); + for (int i = 0; i < in_buffer4_realsize; i++) { + printf(" %2.2x", in_buffer4[i]); + } + printf("\n"); + } + printf(" in_buffer4_size = 0x %8.8x \n", + in_buffer4_size); +#endif + +#ifdef GP_WORKER + ////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////////// + TEEC_Session *sessionIns; + tsn_t *tsnIns; + + sessionIns = NULL; + pthread_mutex_lock(mutex_tsl); + if (tsl->first != NULL) + { + tsnIns = tsl->first; + do + { + if (tsnIns->self->session_id == in_session_sessionid) + { + sessionIns = tsnIns->self; + break; + } + tsnIns = tsnIns->next; + } while (tsnIns != NULL); + } + pthread_mutex_unlock(mutex_tsl); + + TEEC_Context *contextIns; + tcn_t *tcnIns; + + contextIns = NULL; + if (sessionIns != NULL) + { + pthread_mutex_lock(mutex_tcl); + if (tcl->first != NULL) + { + tcnIns = tcl->first; + do + { + contextIns = tcnIns->self; + if (contextIns == sessionIns->context) + { + break; + } + tcnIns = tcnIns->next; + } while (tcnIns != NULL); + } + pthread_mutex_unlock(mutex_tcl); + } + + if (sessionIns == NULL || contextIns == NULL) + { + if (sessionIns == NULL) + { + if (tsl->first == NULL) + { + printf("The teec session list is null. \n"); + teecresult = TEEC_ERROR_SESSION_LIST_NULL; + } else + { + printf("Can't find the teec session. \n"); + teecresult = TEEC_ERROR_NO_SESSION_MATCH; + } + } + + if (contextIns == NULL) + { + if (tcl->first == NULL) + { + printf("The teec context list is null. \n"); + teecresult = TEEC_ERROR_CONTEXT_LIST_NULL; + } else + { + printf("Can't find the teec context. \n"); + teecresult = TEEC_ERROR_NO_CONTEXT_MATCH; + } + } + + sessionid = 0; + serviceid_timelow = 0; + serviceid_timemid = 0; + serviceid_timehiandver = 0; + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + opscnt = 0; + head_next = 0; + head_prev = 0; + context = 0; + + started = 0; + paramtypes = 0; + + operation_param1_tmpref_buffer = 0; + operation_param1_tmpref_size = 0; + operation_param1_memref_parent = 0; + operation_param1_memref_parent_flag = 0; + operation_param1_memref_size = 0; + operation_param1_memref_offset = 0; + operation_param1_value_a = 0; + operation_param1_value_b = 0; + operation_param1_ionref_ionsharefd = 0; + operation_param1_ionref_ionsize = 0; + + operation_param2_tmpref_buffer = 0; + operation_param2_tmpref_size = 0; + operation_param2_memref_parent = 0; + operation_param2_memref_parent_flag = 0; + operation_param2_memref_size = 0; + operation_param2_memref_offset = 0; + operation_param2_value_a = 0; + operation_param2_value_b = 0; + operation_param2_ionref_ionsharefd = 0; + operation_param2_ionref_ionsize = 0; + + operation_param3_tmpref_buffer = 0; + operation_param3_tmpref_size = 0; + operation_param3_memref_parent = 0; + operation_param3_memref_parent_flag = 0; + operation_param3_memref_size = 0; + operation_param3_memref_offset = 0; + operation_param3_value_a = 0; + operation_param3_value_b = 0; + operation_param3_ionref_ionsharefd = 0; + operation_param3_ionref_ionsize = 0; + + operation_param4_tmpref_buffer = 0; + operation_param4_tmpref_size = 0; + operation_param4_memref_parent = 0; + operation_param4_memref_parent_flag = 0; + operation_param4_memref_size = 0; + operation_param4_memref_offset = 0; + operation_param4_value_a = 0; + operation_param4_value_b = 0; + operation_param4_ionref_ionsharefd = 0; + operation_param4_ionref_ionsize = 0; + + operation_session = 0; + operation_cancelflag = 0; + + returnorigin = 0xff; + + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + } else + { + teecresult = TEEC_SUCCESS; + + sessionIns->session_id = in_session_sessionid; + sessionIns->service_id.timeLow = in_session_serviceid_timelow; + sessionIns->service_id.timeMid = in_session_serviceid_timemid; + sessionIns->service_id.timeHiAndVersion = in_session_serviceid_timehiandver; + if (in_session_serviceid_clockseqandnode_realsize <= 8 && + in_session_serviceid_clockseqandnode_realsize > 0 && + in_session_serviceid_clockseqandnode != NULL + ) + { + for (int i = 0; i < in_session_serviceid_clockseqandnode_realsize; i++) + { + sessionIns->service_id.clockSeqAndNode[i] = + (uint8_t)(in_session_serviceid_clockseqandnode[i] & 0x000000ff); + } + } else + { + for (int i = 0; i < 8; i++) + { + sessionIns->service_id.clockSeqAndNode[i] = 0; + } + } + sessionIns->ops_cnt = in_session_opscnt; + sessionIns->head.next = (struct ListNode *) in_session_head_next; + sessionIns->head.prev = (struct ListNode *) in_session_head_prev; + // sessionIns->context = (TEEC_Context *)in_session_context; + + + TEEC_Operation operationIns; + + operationIns.started = in_operation_started; + operationIns.paramTypes = in_operation_paramtypes; + + ///////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////// + + uint8_t *buffer1_temp = NULL; + TEEC_SharedMemory shareBuffer1; + bool sb1AllReged = false; + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 0) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + operationIns.params[0].value.a = in_operation_param1_value_a; + operationIns.params[0].value.b = in_operation_param1_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + in_buffer1 != NULL && + in_buffer1_size > 0 + ) + { + uint32_t buffer1_temp_size; + buffer1_temp_size = in_buffer1_size; + buffer1_temp = (uint8_t *) malloc(buffer1_temp_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer1_size; isize++) + { + buffer1_temp[isize] = (uint8_t)(in_buffer1[isize] & 0x000000ff); + } + + operationIns.params[0].tmpref.buffer = (void *) buffer1_temp; + operationIns.params[0].tmpref.size = buffer1_temp_size; + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + in_operation_param1_tmpref_size > 0 + ) + { + buffer1_temp = (uint8_t *) malloc(in_operation_param1_tmpref_size * sizeof(uint8_t)); + operationIns.params[0].tmpref.buffer = (void *) buffer1_temp; + operationIns.params[0].tmpref.size = in_operation_param1_tmpref_size; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (in_operation_param1_memref_parent_flag) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + in_buffer1 != NULL && + in_buffer1_size > 0 + ) + { + memset(&shareBuffer1, 0, sizeof(shareBuffer1)); + shareBuffer1.size = in_buffer1_size; + shareBuffer1.flags = in_operation_param1_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer1); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb1AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer1.buffer, 0, shareBuffer1.size); + for (int isize = 0; isize < in_buffer1_size; isize++) + { + *((uint8_t * )(shareBuffer1.buffer) + isize) = + (uint8_t)(in_buffer1[isize] & 0x000000ff); + } + operationIns.params[0].memref.parent = &shareBuffer1; + // operationIns.params[0].memref.parent->flags = + // in_operation_param1_memref_parent_flag; + operationIns.params[0].memref.size = shareBuffer1.size; + } + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + in_operation_param1_memref_size > 0 + ) + { + memset(&shareBuffer1, 0, sizeof(shareBuffer1)); + shareBuffer1.size = in_operation_param1_memref_size; + shareBuffer1.flags = in_operation_param1_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer1); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb1AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[0].memref.parent = &shareBuffer1; + operationIns.params[0].memref.size = shareBuffer1.size; + } + + } + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if ( + in_buffer1 != NULL && + in_buffer1_size > 0 + ) + { + memset(&shareBuffer1, 0, sizeof(shareBuffer1)); + shareBuffer1.size = in_buffer1_size; + shareBuffer1.flags = in_operation_param1_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer1); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb1AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer1.buffer, 0, shareBuffer1.size); + for (int isize = 0; isize < in_buffer1_size; isize++) + { + *((uint8_t * )(shareBuffer1.buffer) + isize) = + (uint8_t)(in_buffer1[isize] & 0x000000ff); + } + operationIns.params[0].memref.parent = &shareBuffer1; + operationIns.params[0].memref.offset = in_operation_param1_memref_offset; + operationIns.params[0].memref.size = in_operation_param1_memref_size; + } + } + + break; + } + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (in_operation_param1_memref_size > 0) + { + memset(&shareBuffer1, 0, sizeof(shareBuffer1)); + shareBuffer1.size = in_buffer1_size; + shareBuffer1.flags = in_operation_param1_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer1); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb1AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[0].memref.parent = &shareBuffer1; + operationIns.params[0].memref.offset = in_operation_param1_memref_offset; + operationIns.params[0].memref.size = in_operation_param1_memref_size; + } + + } + + break; + } + + + default: + break; + } + + ///////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////// + + uint8_t *buffer2_temp = NULL; + TEEC_SharedMemory shareBuffer2; + bool sb2AllReged = false; + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 1) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + operationIns.params[1].value.a = in_operation_param2_value_a; + operationIns.params[1].value.b = in_operation_param2_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + in_buffer2 != NULL && + in_buffer2_size > 0 + ) + { + uint32_t buffer2_temp_size; + buffer2_temp_size = in_buffer2_size; + buffer2_temp = (uint8_t *) malloc(buffer2_temp_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer2_size; isize++) + { + buffer2_temp[isize] = (uint8_t)(in_buffer2[isize] & 0x000000ff); + } + + operationIns.params[1].tmpref.buffer = (void *) buffer2_temp; + operationIns.params[1].tmpref.size = buffer2_temp_size; + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + in_operation_param2_tmpref_size > 0 + ) + { + buffer2_temp = (uint8_t *) malloc(in_operation_param2_tmpref_size * sizeof(uint8_t)); + operationIns.params[1].tmpref.buffer = (void *) buffer2_temp; + operationIns.params[1].tmpref.size = in_operation_param2_tmpref_size; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (in_operation_param2_memref_parent_flag) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + in_buffer2 != NULL && + in_buffer2_size > 0 + ) + { + memset(&shareBuffer2, 0, sizeof(shareBuffer2)); + shareBuffer2.size = in_buffer2_size; + shareBuffer2.flags = in_operation_param2_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer2); + if (retASM) + { + printf("alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb2AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer2.buffer, 0, shareBuffer2.size); + for (int isize = 0; isize < in_buffer2_size; isize++) + { + *((uint8_t * )(shareBuffer2.buffer) + isize) = + (uint8_t)(in_buffer2[isize] & 0x000000ff); + } + operationIns.params[1].memref.parent = &shareBuffer2; + // operationIns.params[1].memref.parent->flags = + // in_operation_param2_memref_parent_flag; + operationIns.params[1].memref.size = shareBuffer2.size; + } + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + in_operation_param2_memref_size > 0 + ) + { + memset(&shareBuffer2, 0, sizeof(shareBuffer2)); + shareBuffer2.size = in_operation_param2_memref_size; + shareBuffer2.flags = in_operation_param2_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer2); + if (retASM) + { + printf("alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb2AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[1].memref.parent = &shareBuffer2; + // operationIns.params[1].memref.parent->flags = + // in_operation_param2_memref_parent_flag; + operationIns.params[1].memref.size = shareBuffer2.size; + } + + } + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if ( + in_buffer2 != NULL && + in_buffer2_size > 0 + ) + { + memset(&shareBuffer2, 0, sizeof(shareBuffer2)); + shareBuffer2.size = in_buffer2_size; + shareBuffer2.flags = in_operation_param2_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer2); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb2AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer2.buffer, 0, shareBuffer2.size); + for (int isize = 0; isize < in_buffer2_size; isize++) + { + *((uint8_t * )(shareBuffer2.buffer) + isize) = + (uint8_t)(in_buffer2[isize] & 0x000000ff); + } + operationIns.params[1].memref.parent = &shareBuffer2; + operationIns.params[1].memref.offset = in_operation_param2_memref_offset; + operationIns.params[1].memref.size = in_operation_param2_memref_size; + } + } + + break; + } + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (in_operation_param2_memref_size > 0) + { + memset(&shareBuffer2, 0, sizeof(shareBuffer2)); + shareBuffer2.size = in_buffer2_size; + shareBuffer2.flags = in_operation_param2_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer2); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb2AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[1].memref.parent = &shareBuffer2; + operationIns.params[1].memref.offset = in_operation_param2_memref_offset; + operationIns.params[1].memref.size = in_operation_param2_memref_size; + } + + } + + break; + } + + + default: + break; + } + + ///////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////// + + uint8_t *buffer3_temp = NULL; + TEEC_SharedMemory shareBuffer3; + bool sb3AllReged = false; + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 2) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + operationIns.params[2].value.a = in_operation_param3_value_a; + operationIns.params[2].value.b = in_operation_param3_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + in_buffer3 != NULL && + in_buffer3_size > 0 + ) + { + uint32_t buffer3_temp_size; + buffer3_temp_size = in_buffer3_size; + buffer3_temp = (uint8_t *) malloc(buffer3_temp_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer3_size; isize++) + { + buffer3_temp[isize] = (uint8_t)(in_buffer3[isize] & 0x000000ff); + } + + operationIns.params[2].tmpref.buffer = (void *) buffer3_temp; + operationIns.params[2].tmpref.size = buffer3_temp_size; + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + in_operation_param3_tmpref_size > 0 + ) + { + buffer3_temp = (uint8_t *) malloc(in_operation_param3_tmpref_size * sizeof(uint8_t)); + operationIns.params[2].tmpref.buffer = (void *) buffer3_temp; + operationIns.params[2].tmpref.size = in_operation_param3_tmpref_size; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (in_operation_param3_memref_parent_flag) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + in_buffer3 != NULL && + in_buffer3_size > 0 + ) + { + memset(&shareBuffer3, 0, sizeof(shareBuffer3)); + shareBuffer3.size = in_buffer3_size; + shareBuffer3.flags = in_operation_param3_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer3); + if (retASM) + { + printf("alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb3AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer3.buffer, 0, shareBuffer3.size); + for (int isize = 0; isize < in_buffer3_size; isize++) + { + *((uint8_t * )(shareBuffer3.buffer) + isize) = + (uint8_t)(in_buffer3[isize] & 0x000000ff); + } + operationIns.params[2].memref.parent = &shareBuffer3; + // operationIns.params[2].memref.parent->flags = + // in_operation_param3_memref_parent_flag; + operationIns.params[2].memref.size = shareBuffer3.size; + } + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + in_operation_param3_memref_size > 0 + ) + { + memset(&shareBuffer3, 0, sizeof(shareBuffer3)); + shareBuffer3.size = in_operation_param3_memref_size; + shareBuffer3.flags = in_operation_param3_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer3); + if (retASM) + { + printf("alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb3AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[2].memref.parent = &shareBuffer3; + // operationIns.params[2].memref.parent->flags = + // in_operation_param3_memref_parent_flag; + operationIns.params[2].memref.size = shareBuffer3.size; + } + + } + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if ( + in_buffer3 != NULL && + in_buffer3_size > 0 + ) + { + memset(&shareBuffer3, 0, sizeof(shareBuffer3)); + shareBuffer3.size = in_buffer3_size; + shareBuffer3.flags = in_operation_param3_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer3); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb3AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer3.buffer, 0, shareBuffer3.size); + for (int isize = 0; isize < in_buffer3_size; isize++) + { + *((uint8_t * )(shareBuffer3.buffer) + isize) = + (uint8_t)(in_buffer3[isize] & 0x000000ff); + } + operationIns.params[2].memref.parent = &shareBuffer3; + operationIns.params[2].memref.offset = in_operation_param3_memref_offset; + operationIns.params[2].memref.size = in_operation_param3_memref_size; + } + } + + break; + } + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (in_operation_param3_memref_size > 0) + { + memset(&shareBuffer3, 0, sizeof(shareBuffer3)); + shareBuffer3.size = in_buffer3_size; + shareBuffer3.flags = in_operation_param3_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer3); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb3AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[2].memref.parent = &shareBuffer3; + operationIns.params[2].memref.offset = in_operation_param3_memref_offset; + operationIns.params[2].memref.size = in_operation_param3_memref_size; + } + + } + + break; + } + + + default: + break; + } + + ///////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////// + + uint8_t *buffer4_temp = NULL; + TEEC_SharedMemory shareBuffer4; + bool sb4AllReged = false; + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 3) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + operationIns.params[3].value.a = in_operation_param4_value_a; + operationIns.params[3].value.b = in_operation_param4_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + in_buffer4 != NULL && + in_buffer4_size > 0 + ) + { + uint32_t buffer4_temp_size; + buffer4_temp_size = in_buffer4_size; + buffer4_temp = (uint8_t *) malloc(buffer4_temp_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer4_size; isize++) + { + buffer4_temp[isize] = (uint8_t)(in_buffer4[isize] & 0x000000ff); + } + + operationIns.params[3].tmpref.buffer = (void *) buffer4_temp; + operationIns.params[3].tmpref.size = buffer4_temp_size; + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + in_operation_param4_tmpref_size > 0 + ) + { + buffer4_temp = (uint8_t *) malloc(in_operation_param4_tmpref_size * sizeof(uint8_t)); + operationIns.params[3].tmpref.buffer = (void *) buffer4_temp; + operationIns.params[3].tmpref.size = in_operation_param4_tmpref_size; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (in_operation_param4_memref_parent_flag) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + in_buffer4 != NULL && + in_buffer4_size > 0 + ) + { + memset(&shareBuffer4, 0, sizeof(shareBuffer4)); + shareBuffer4.size = in_buffer4_size; + shareBuffer4.flags = in_operation_param4_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer4); + if (retASM) + { + printf("alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb4AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer4.buffer, 0, shareBuffer4.size); + for (int isize = 0; isize < in_buffer4_size; isize++) + { + *((uint8_t * )(shareBuffer4.buffer) + isize) = + (uint8_t)(in_buffer4[isize] & 0x000000ff); + } + operationIns.params[3].memref.parent = &shareBuffer4; + // operationIns.params[3].memref.parent->flags = + // in_operation_param4_memref_parent_flag; + operationIns.params[3].memref.size = shareBuffer4.size; + } + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + in_operation_param4_memref_size > 0 + ) + { + memset(&shareBuffer4, 0, sizeof(shareBuffer4)); + shareBuffer4.size = in_operation_param4_memref_size; + shareBuffer4.flags = in_operation_param4_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer4); + if (retASM) + { + printf("alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb4AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[3].memref.parent = &shareBuffer4; + // operationIns.params[3].memref.parent->flags = + // in_operation_param4_memref_parent_flag; + operationIns.params[3].memref.size = shareBuffer4.size; + } + + } + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if ( + in_buffer4 != NULL && + in_buffer4_size > 0 + ) + { + memset(&shareBuffer4, 0, sizeof(shareBuffer4)); + shareBuffer4.size = in_buffer4_size; + shareBuffer4.flags = in_operation_param4_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer4); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb4AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + memset(shareBuffer4.buffer, 0, shareBuffer4.size); + for (int isize = 0; isize < in_buffer4_size; isize++) + { + *((uint8_t * )(shareBuffer4.buffer) + isize) = + (uint8_t)(in_buffer4[isize] & 0x000000ff); + } + operationIns.params[3].memref.parent = &shareBuffer4; + operationIns.params[3].memref.offset = in_operation_param4_memref_offset; + operationIns.params[3].memref.size = in_operation_param4_memref_size; + } + } + + break; + } + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (in_operation_param4_memref_size > 0) + { + memset(&shareBuffer4, 0, sizeof(shareBuffer4)); + shareBuffer4.size = in_buffer4_size; + shareBuffer4.flags = in_operation_param4_memref_parent_flag; + TEEC_Result retASM = 0; + retASM = TEEC_AllocateSharedMemory(contextIns, &shareBuffer4); + if (retASM) + { + printf("Alloc share memory failed, ret=0x%x.\n", retASM); + teecresult = retASM; + } else + { + sb4AllReged = true; + printf("TEEC_AllocateSharedMemory succecced. \n"); + operationIns.params[3].memref.parent = &shareBuffer4; + operationIns.params[3].memref.offset = in_operation_param4_memref_offset; + operationIns.params[3].memref.size = in_operation_param4_memref_size; + } + + } + + break; + } + + + default: + break; + } + + ///////////////////////////////////////////////////////////////////////////////////////////// + ///////////////////////////////////////////////////////////////////////////////////////////// + + if (teecresult != TEEC_SUCCESS) + { + sessionid = 0; + serviceid_timelow = 0; + serviceid_timemid = 0; + serviceid_timehiandver = 0; + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + opscnt = 0; + head_next = 0; + head_prev = 0; + context = 0; + + started = 0; + paramtypes = 0; + + operation_param1_tmpref_buffer = 0; + operation_param1_tmpref_size = 0; + operation_param1_memref_parent = 0; + operation_param1_memref_parent_flag = 0; + operation_param1_memref_size = 0; + operation_param1_memref_offset = 0; + operation_param1_value_a = 0; + operation_param1_value_b = 0; + operation_param1_ionref_ionsharefd = 0; + operation_param1_ionref_ionsize = 0; + + operation_param2_tmpref_buffer = 0; + operation_param2_tmpref_size = 0; + operation_param2_memref_parent = 0; + operation_param2_memref_parent_flag = 0; + operation_param2_memref_size = 0; + operation_param2_memref_offset = 0; + operation_param2_value_a = 0; + operation_param2_value_b = 0; + operation_param2_ionref_ionsharefd = 0; + operation_param2_ionref_ionsize = 0; + + operation_param3_tmpref_buffer = 0; + operation_param3_tmpref_size = 0; + operation_param3_memref_parent = 0; + operation_param3_memref_parent_flag = 0; + operation_param3_memref_size = 0; + operation_param3_memref_offset = 0; + operation_param3_value_a = 0; + operation_param3_value_b = 0; + operation_param3_ionref_ionsharefd = 0; + operation_param3_ionref_ionsize = 0; + + operation_param4_tmpref_buffer = 0; + operation_param4_tmpref_size = 0; + operation_param4_memref_parent = 0; + operation_param4_memref_parent_flag = 0; + operation_param4_memref_size = 0; + operation_param4_memref_offset = 0; + operation_param4_value_a = 0; + operation_param4_value_b = 0; + operation_param4_ionref_ionsharefd = 0; + operation_param4_ionref_ionsize = 0; + + operation_session = 0; + operation_cancelflag = 0; + + returnorigin = 0xff; + + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + } else + { //start of the input parameter operation success +#if 0 + operationIns.params[0].ionref.ion_share_fd = in_operation_param1_ionref_ionsharefd; + operationIns.params[0].ionref.ion_size = in_operation_param1_ionref_ionsize; + + operationIns.params[1].ionref.ion_share_fd = in_operation_param2_ionref_ionsharefd; + operationIns.params[1].ionref.ion_size = in_operation_param2_ionref_ionsize; + + operationIns.params[2].ionref.ion_share_fd = in_operation_param3_ionref_ionsharefd; + operationIns.params[2].ionref.ion_size = in_operation_param3_ionref_ionsize; + + operationIns.params[3].ionref.ion_share_fd = in_operation_param4_ionref_ionsharefd; + operationIns.params[3].ionref.ion_size = in_operation_param4_ionref_ionsize; +#endif + + operationIns.session = sessionIns; + operationIns.cancel_flag = in_operation_cancelflag; + + uint32_t origin; + origin = in_returnorigin; + + TEEC_Result result; + + struct timeval start, end; + gettimeofday(&start, NULL); + result = + TEEC_InvokeCommand( + sessionIns, + in_commandid, + &operationIns, + &origin + ); + gettimeofday(&end, NULL); + uint32_t cost = 0; + cost += (1000000 * end.tv_sec + end.tv_usec) - (1000000 * start.tv_sec + start.tv_usec); + + if (result != TEEC_SUCCESS) + { + printf("Teec InvokeCommand Failed. \n"); + printf(" teecresult = 0x %8.8x.\n", result); + + teecresult = result; + + sessionid = 0; + serviceid_timelow = 0; + serviceid_timemid = 0; + serviceid_timehiandver = 0; + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + opscnt = 0; + head_next = 0; + head_prev = 0; + context = 0; + + started = 0; + paramtypes = 0; + + operation_param1_tmpref_buffer = 0; + operation_param1_tmpref_size = 0; + operation_param1_memref_parent = 0; + operation_param1_memref_parent_flag = 0; + operation_param1_memref_size = 0; + operation_param1_memref_offset = 0; + operation_param1_value_a = 0; + operation_param1_value_b = 0; + operation_param1_ionref_ionsharefd = 0; + operation_param1_ionref_ionsize = 0; + + operation_param2_tmpref_buffer = 0; + operation_param2_tmpref_size = 0; + operation_param2_memref_parent = 0; + operation_param2_memref_parent_flag = 0; + operation_param2_memref_size = 0; + operation_param2_memref_offset = 0; + operation_param2_value_a = 0; + operation_param2_value_b = 0; + operation_param2_ionref_ionsharefd = 0; + operation_param2_ionref_ionsize = 0; + + operation_param3_tmpref_buffer = 0; + operation_param3_tmpref_size = 0; + operation_param3_memref_parent = 0; + operation_param3_memref_parent_flag = 0; + operation_param3_memref_size = 0; + operation_param3_memref_offset = 0; + operation_param3_value_a = 0; + operation_param3_value_b = 0; + operation_param3_ionref_ionsharefd = 0; + operation_param3_ionref_ionsize = 0; + + operation_param4_tmpref_buffer = 0; + operation_param4_tmpref_size = 0; + operation_param4_memref_parent = 0; + operation_param4_memref_parent_flag = 0; + operation_param4_memref_size = 0; + operation_param4_memref_offset = 0; + operation_param4_value_a = 0; + operation_param4_value_b = 0; + operation_param4_ionref_ionsharefd = 0; + operation_param4_ionref_ionsize = 0; + + operation_session = 0; + operation_cancelflag = 0; + + returnorigin = 0xff; + + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + } else + { // start of the invoke command success + printf("Teec InvokeCommand Succed, cost time: %ld us \n", cost); + + teecresult = result; + + sessionid = sessionIns->session_id; + serviceid_timelow = sessionIns->service_id.timeLow; + serviceid_timemid = sessionIns->service_id.timeMid; + serviceid_timehiandver = sessionIns->service_id.timeHiAndVersion; + if (sessionIns->service_id.clockSeqAndNode != NULL) + { + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *) malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < 8; iind++) + { + uint8_t u8Temp; + u8Temp = sessionIns->service_id.clockSeqAndNode[iind]; + serviceid_clockseqandnode[iind] = (dbus_uint32_t) u8Temp; + } + serviceid_clockseqandnode_outsize = 8; + } else + { + serviceid_clockseqandnode_realsize = 0; + serviceid_clockseqandnode = NULL; + serviceid_clockseqandnode_outsize = 0; + } + opscnt = sessionIns->ops_cnt; + head_next = (dbus_uint64_t) sessionIns->head.next; + head_prev = (dbus_uint64_t) sessionIns->head.prev; + context = (dbus_uint64_t) sessionIns->context; + + started = operationIns.started; + paramtypes = operationIns.paramTypes; + + ////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////// + + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 0) + ) + { + case TEEC_VALUE_INOUT: + case TEEC_VALUE_OUTPUT: + { + operation_param1_value_a = operationIns.params[0].value.a; + operation_param1_value_b = operationIns.params[0].value.b; + + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + + break; + } + + case TEEC_MEMREF_TEMP_INOUT: + case TEEC_MEMREF_TEMP_OUTPUT: + { + if (operationIns.params[0].tmpref.buffer != NULL && + operationIns.params[0].tmpref.size > 0 + ) + { + buffer1_realsize = operationIns.params[0].tmpref.size; + buffer1 = + (dbus_uint32_t *) malloc( + buffer1_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer1_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * )(operationIns.params[0].tmpref.buffer) + iind); + buffer1[iind] = (dbus_uint32_t) u8Temp; + } + buffer1_outsize = buffer1_realsize; + } else + { + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + } + + operation_param1_tmpref_buffer = (dbus_uint64_t) operationIns.params[0].tmpref.buffer; + operation_param1_tmpref_size = operationIns.params[0].tmpref.size; + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (operationIns.params[0].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + + if (operationIns.params[0].memref.parent->buffer != NULL && + operationIns.params[0].memref.parent->size > 0 + ) + { + buffer1_realsize = operationIns.params[0].memref.parent->size; + buffer1 = + (dbus_uint32_t *) malloc( + buffer1_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer1_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[0].memref.parent->buffer) + iind); + buffer1[iind] = (dbus_uint32_t) u8Temp; + } + buffer1_outsize = buffer1_realsize; + } else + { + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + } + + operation_param1_memref_parent = + (dbus_uint64_t) operationIns.params[0].memref.parent->buffer; + operation_param1_memref_parent_flag = + (dbus_uint32_t) operationIns.params[0].memref.parent->flags; + operation_param1_memref_size = + operationIns.params[0].memref.parent->size; + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operationIns.params[0].memref.parent->buffer != NULL && + operationIns.params[0].memref.parent->size > 0 + ) + { + buffer1_realsize = operationIns.params[0].memref.parent->size; + buffer1 = + (dbus_uint32_t *) malloc(buffer1_realsize * sizeof(dbus_uint32_t)); + for (int iind = 0; iind < buffer1_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[0].memref.parent->buffer) + iind); + buffer1[iind] = (dbus_uint32_t) u8Temp; + } + buffer1_outsize = buffer1_realsize; + } else + { + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + } + + operation_param1_memref_parent = + (dbus_uint64_t) operationIns.params[0].memref.parent->buffer; + operation_param1_memref_parent_flag = + (dbus_uint32_t) operationIns.params[0].memref.parent->flags; + operation_param1_memref_offset = operationIns.params[0].memref.offset; + operation_param1_memref_size = + operationIns.params[0].memref.size; + + break; + } + + + default: + { + buffer1_realsize = 0; + buffer1 = NULL; + buffer1_outsize = 0; + } + } + + operation_param1_ionref_ionsharefd = operationIns.params[0].ionref.ion_share_fd; + operation_param1_ionref_ionsize = operationIns.params[0].ionref.ion_size; + + ////////////////////////////////////////////////////////////////////////////////// + + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 1) + ) + { + case TEEC_VALUE_INOUT: + case TEEC_VALUE_OUTPUT: + { + operation_param2_value_a = operationIns.params[1].value.a; + operation_param2_value_b = operationIns.params[1].value.b; + + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + + break; + } + + case TEEC_MEMREF_TEMP_INOUT: + case TEEC_MEMREF_TEMP_OUTPUT: + { + if (operationIns.params[1].tmpref.buffer != NULL && + operationIns.params[1].tmpref.size > 0 + ) + { + buffer2_realsize = operationIns.params[1].tmpref.size; + buffer2 = + (dbus_uint32_t *) malloc( + buffer2_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer2_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * )(operationIns.params[1].tmpref.buffer) + iind); + buffer2[iind] = (dbus_uint32_t) u8Temp; + } + buffer2_outsize = buffer2_realsize; + } else + { + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + } + + operation_param2_tmpref_buffer = (dbus_uint64_t) operationIns.params[1].tmpref.buffer; + operation_param2_tmpref_size = operationIns.params[1].tmpref.size; + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (operationIns.params[1].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + + if (operationIns.params[1].memref.parent->buffer != NULL && + operationIns.params[1].memref.parent->size > 0 + ) + { + buffer2_realsize = operationIns.params[1].memref.parent->size; + buffer2 = + (dbus_uint32_t *) malloc( + buffer2_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer2_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[1].memref.parent->buffer) + iind); + buffer2[iind] = (dbus_uint32_t) u8Temp; + } + buffer2_outsize = buffer2_realsize; + } else + { + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + } + + operation_param2_memref_parent = + (dbus_uint64_t) operationIns.params[1].memref.parent->buffer; + operation_param2_memref_parent_flag = + (dbus_uint32_t) operationIns.params[1].memref.parent->flags; + operation_param2_memref_size = + operationIns.params[1].memref.parent->size; + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operationIns.params[1].memref.parent->buffer != NULL && + operationIns.params[1].memref.parent->size > 0 + ) + { + buffer2_realsize = operationIns.params[1].memref.parent->size; + buffer2 = + (dbus_uint32_t *) malloc(buffer2_realsize * sizeof(dbus_uint32_t)); + for (int iind = 0; iind < buffer2_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[1].memref.parent->buffer) + iind); + buffer2[iind] = (dbus_uint32_t) u8Temp; + } + buffer2_outsize = buffer2_realsize; + } else + { + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + } + + operation_param2_memref_parent = + (dbus_uint64_t) operationIns.params[1].memref.parent->buffer; + operation_param2_memref_parent_flag = + (dbus_uint32_t) operationIns.params[1].memref.parent->flags; + operation_param2_memref_offset = operationIns.params[1].memref.offset; + operation_param2_memref_size = + operationIns.params[1].memref.size; + + break; + } + + + default: + { + buffer2_realsize = 0; + buffer2 = NULL; + buffer2_outsize = 0; + } + } + + operation_param2_ionref_ionsharefd = operationIns.params[1].ionref.ion_share_fd; + operation_param2_ionref_ionsize = operationIns.params[1].ionref.ion_size; + + ////////////////////////////////////////////////////////////////////////////////// + + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 2) + ) + { + case TEEC_VALUE_INOUT: + case TEEC_VALUE_OUTPUT: + { + operation_param3_value_a = operationIns.params[2].value.a; + operation_param3_value_b = operationIns.params[2].value.b; + + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + + break; + } + + case TEEC_MEMREF_TEMP_INOUT: + case TEEC_MEMREF_TEMP_OUTPUT: + { + if (operationIns.params[2].tmpref.buffer != NULL && + operationIns.params[2].tmpref.size > 0 + ) + { + buffer3_realsize = operationIns.params[2].tmpref.size; + buffer3 = + (dbus_uint32_t *) malloc( + buffer3_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer3_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * )(operationIns.params[2].tmpref.buffer) + iind); + buffer3[iind] = (dbus_uint32_t) u8Temp; + } + buffer3_outsize = buffer3_realsize; + } else + { + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + } + + operation_param3_tmpref_buffer = (dbus_uint64_t) operationIns.params[2].tmpref.buffer; + operation_param3_tmpref_size = operationIns.params[2].tmpref.size; + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (operationIns.params[2].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + + if (operationIns.params[2].memref.parent->buffer != NULL && + operationIns.params[2].memref.parent->size > 0 + ) + { + buffer3_realsize = operationIns.params[2].memref.parent->size; + buffer3 = + (dbus_uint32_t *) malloc( + buffer3_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer3_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[2].memref.parent->buffer) + iind); + buffer3[iind] = (dbus_uint32_t) u8Temp; + } + buffer3_outsize = buffer3_realsize; + } else + { + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + } + + operation_param3_memref_parent = + (dbus_uint64_t) operationIns.params[2].memref.parent->buffer; + operation_param3_memref_parent_flag = + (dbus_uint32_t) operationIns.params[2].memref.parent->flags; + operation_param3_memref_size = + operationIns.params[2].memref.parent->size; + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operationIns.params[2].memref.parent->buffer != NULL && + operationIns.params[2].memref.parent->size > 0 + ) + { + buffer3_realsize = operationIns.params[2].memref.parent->size; + buffer3 = + (dbus_uint32_t *) malloc(buffer3_realsize * sizeof(dbus_uint32_t)); + for (int iind = 0; iind < buffer3_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[2].memref.parent->buffer) + iind); + buffer3[iind] = (dbus_uint32_t) u8Temp; + } + buffer3_outsize = buffer3_realsize; + } else + { + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + } + + operation_param3_memref_parent = + (dbus_uint64_t) operationIns.params[2].memref.parent->buffer; + operation_param3_memref_parent_flag = + (dbus_uint32_t) operationIns.params[2].memref.parent->flags; + operation_param3_memref_offset = operationIns.params[2].memref.offset; + operation_param3_memref_size = + operationIns.params[2].memref.size; + + break; + } + + + default: + { + buffer3_realsize = 0; + buffer3 = NULL; + buffer3_outsize = 0; + } + } + + operation_param3_ionref_ionsharefd = operationIns.params[2].ionref.ion_share_fd; + operation_param3_ionref_ionsize = operationIns.params[2].ionref.ion_size; + + ////////////////////////////////////////////////////////////////////////////////// + + switch ( + TEEC_PARAM_TYPE_GET(operationIns.paramTypes, 3) + ) + { + case TEEC_VALUE_INOUT: + case TEEC_VALUE_OUTPUT: + { + operation_param4_value_a = operationIns.params[3].value.a; + operation_param4_value_b = operationIns.params[3].value.b; + + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + + break; + } + + case TEEC_MEMREF_TEMP_INOUT: + case TEEC_MEMREF_TEMP_OUTPUT: + { + if (operationIns.params[3].tmpref.buffer != NULL && + operationIns.params[3].tmpref.size > 0 + ) + { + buffer4_realsize = operationIns.params[3].tmpref.size; + buffer4 = + (dbus_uint32_t *) malloc( + buffer4_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer4_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * )(operationIns.params[3].tmpref.buffer) + iind); + buffer4[iind] = (dbus_uint32_t) u8Temp; + } + buffer4_outsize = buffer4_realsize; + } else + { + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + } + + operation_param4_tmpref_buffer = (dbus_uint64_t) operationIns.params[3].tmpref.buffer; + operation_param4_tmpref_size = operationIns.params[3].tmpref.size; + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (operationIns.params[3].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + + if (operationIns.params[3].memref.parent->buffer != NULL && + operationIns.params[3].memref.parent->size > 0 + ) + { + buffer4_realsize = operationIns.params[3].memref.parent->size; + buffer4 = + (dbus_uint32_t *) malloc( + buffer4_realsize * sizeof(dbus_uint32_t) + ); + for (int iind = 0; iind < buffer4_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[3].memref.parent->buffer) + iind); + buffer4[iind] = (dbus_uint32_t) u8Temp; + } + buffer4_outsize = buffer4_realsize; + } else + { + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + } + + operation_param4_memref_parent = + (dbus_uint64_t) operationIns.params[3].memref.parent->buffer; + operation_param4_memref_parent_flag = + (dbus_uint32_t) operationIns.params[3].memref.parent->flags; + operation_param4_memref_size = + operationIns.params[3].memref.parent->size; + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operationIns.params[3].memref.parent->buffer != NULL && + operationIns.params[3].memref.parent->size > 0 + ) + { + buffer4_realsize = operationIns.params[3].memref.parent->size; + buffer4 = + (dbus_uint32_t *) malloc(buffer4_realsize * sizeof(dbus_uint32_t)); + for (int iind = 0; iind < buffer4_realsize; iind++) + { + uint8_t u8Temp; + u8Temp = (uint8_t) * ((uint8_t * ) + (operationIns.params[3].memref.parent->buffer) + iind); + buffer4[iind] = (dbus_uint32_t) u8Temp; + } + buffer4_outsize = buffer4_realsize; + } else + { + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + } + + operation_param4_memref_parent = + (dbus_uint64_t) operationIns.params[3].memref.parent->buffer; + operation_param4_memref_parent_flag = + (dbus_uint32_t) operationIns.params[3].memref.parent->flags; + operation_param4_memref_offset = operationIns.params[3].memref.offset; + operation_param4_memref_size = + operationIns.params[3].memref.size; + + break; + } + + + default: + { + buffer4_realsize = 0; + buffer4 = NULL; + buffer4_outsize = 0; + } + } + + operation_param4_ionref_ionsharefd = operationIns.params[3].ionref.ion_share_fd; + operation_param4_ionref_ionsize = operationIns.params[3].ionref.ion_size; + + ////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////// + + operation_session = (dbus_uint64_t) operationIns.session; + operation_cancelflag = operationIns.cancel_flag; + + returnorigin = origin; + } + + if (buffer1_temp != NULL) + { + free(buffer1_temp); + } + if (buffer2_temp != NULL) + { + free(buffer2_temp); + } + if (buffer3_temp != NULL) + { + free(buffer3_temp); + } + if (buffer4_temp != NULL) + { + free(buffer4_temp); + } + + if (sb1AllReged == true) + { + TEEC_ReleaseSharedMemory(&shareBuffer1); + printf("TEEC_ReleaseSharedMemory. \n"); + } + + if (sb2AllReged == true) + { + TEEC_ReleaseSharedMemory(&shareBuffer2); + printf("TEEC_ReleaseSharedMemory. \n"); + } + + if (sb3AllReged == true) + { + TEEC_ReleaseSharedMemory(&shareBuffer3); + printf("TEEC_ReleaseSharedMemory. \n"); + } + + if (sb4AllReged == true) + { + TEEC_ReleaseSharedMemory(&shareBuffer4); + printf("TEEC_ReleaseSharedMemory. \n"); + } + + } // end of the invoke command success + + } // end of the input parameter operation success + + + ////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////////////// +#else + if (in_buffer1_size > 0) { + } + else + { + in_buffer1_realsize = 0; + } + if (in_buffer2_size > 0) { + } + else + { + in_buffer2_realsize = 0; + } + if (in_buffer3_size > 0) { + } + else + { + in_buffer3_realsize = 0; + } + if (in_buffer4_size > 0) { + } + else + { + in_buffer4_realsize = 0; + } + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + uint32_t serviceid_clockseqandnode_outsize_temp; + uint32_t returnorigin_temp; + + uint32_t * buffer1_temp = NULL; + uint32_t buffer1_size = 4096; + uint32_t buffer1_outsize_temp; + buffer1_temp = + (uint32_t *)malloc( buffer1_size * sizeof(uint32_t) ); + + uint32_t buffer2_size = 4096; + uint32_t * buffer2_temp = NULL; + uint32_t buffer2_outsize_temp; + buffer2_temp = + (uint32_t *)malloc( buffer2_size * sizeof(uint32_t) ); + + uint32_t buffer3_size = 4096; + uint32_t * buffer3_temp = NULL; + uint32_t buffer3_outsize_temp; + buffer3_temp = + (uint32_t *)malloc( buffer3_size * sizeof(uint32_t) ); + + uint32_t buffer4_size = 4096; + uint32_t * buffer4_temp = NULL; + uint32_t buffer4_outsize_temp; + buffer4_temp = + (uint32_t *)malloc( buffer4_size * sizeof(uint32_t) ); + + char workername[1024]; + memset((char *)workername, 0, 1024); + int ifound = 0; + int iworker; + sin_t * sinIns; + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + if (workerrec[iworker].context_addr == in_session_context) + { + sinIns = NULL; + if (workerrec[iworker].first != NULL) + { + sinIns = workerrec[iworker].first; + do + { + if (sinIns->session_id == in_session_sessionid) + { + sprintf(workername, "%s%d", "gpworker", iworker); + ifound = 1; + break; + } + sinIns = sinIns->next; + }while (sinIns != NULL); + + if ( ifound == 1 ) + { + break; + } + } + } + } + pthread_mutex_unlock(mutex_workerrec); + + if (ifound == 0) + { + printf("Can't find the worker for the session and the context. \n"); + + teecresult = 0xAAAA0017; + + sessionid = 0x0; + serviceid_timelow = 0x0; + serviceid_timemid = 0x0; + serviceid_timehiandver = 0x0; + opscnt = 0x0; + head_next = 0x0; + head_prev = 0x0; + context = 0x0; + started = 0x0; + paramtypes = 0x0; + + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < serviceid_clockseqandnode_realsize ; i++) { + serviceid_clockseqandnode[i] = 0x0; + } + serviceid_clockseqandnode_outsize = 8; + + operation_param1_tmpref_buffer = 0x0; + operation_param1_tmpref_size = 0x0; + operation_param1_memref_parent = 0x0; + operation_param1_memref_size = 0x0; + operation_param1_memref_offset = 0x0; + operation_param1_value_a = 0x0; + operation_param1_value_b = 0x0; + operation_param1_ionref_ionsharefd = 0x0; + operation_param1_ionref_ionsize = 0x0; + + operation_param2_tmpref_buffer = 0x0; + operation_param2_tmpref_size = 0x0; + operation_param2_memref_parent = 0x0; + operation_param2_memref_size = 0x0; + operation_param2_memref_offset = 0x0; + operation_param2_value_a = 0x0; + operation_param2_value_b = 0x0; + operation_param2_ionref_ionsharefd = 0x0; + operation_param2_ionref_ionsize = 0x0; + + operation_param3_tmpref_buffer = 0x0; + operation_param3_tmpref_size = 0x0; + operation_param3_memref_parent = 0x0; + operation_param3_memref_size = 0x0; + operation_param3_memref_offset = 0x0; + operation_param3_value_a = 0x0; + operation_param3_value_b = 0x0; + operation_param3_ionref_ionsharefd = 0x0; + operation_param3_ionref_ionsize = 0x0; + + operation_param4_tmpref_buffer = 0x0; + operation_param4_tmpref_size = 0x0; + operation_param4_memref_parent = 0x0; + operation_param4_memref_size = 0x0; + operation_param4_memref_offset = 0x0; + operation_param4_value_a = 0x0; + operation_param4_value_b = 0x0; + operation_param4_ionref_ionsharefd = 0x0; + operation_param4_ionref_ionsize = 0x0; + + operation_session = 0x0; + operation_cancelflag = 0x0; + + returnorigin = 0x0; + + buffer1_realsize = 0; + buffer1_outsize = buffer1_realsize; + + buffer2_realsize = 0; + buffer2_outsize = buffer2_realsize; + + buffer3_realsize = 0; + buffer3_outsize = buffer3_realsize; + + buffer4_realsize = 0; + buffer4_outsize = buffer4_realsize; + } + else + { + method_call_teec_invokecommand( + workername, + + in_session_sessionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_realsize, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + in_commandid, + + in_operation_started, + in_operation_paramtypes, + + in_operation_param1_tmpref_buffer, + in_operation_param1_tmpref_size, + in_operation_param1_memref_parent, + in_operation_param1_memref_parent_flag, + in_operation_param1_memref_size, + in_operation_param1_memref_offset, + in_operation_param1_value_a, + in_operation_param1_value_b, + in_operation_param1_ionref_ionsharefd, + in_operation_param1_ionref_ionsize, + + in_operation_param2_tmpref_buffer, + in_operation_param2_tmpref_size, + in_operation_param2_memref_parent, + in_operation_param2_memref_parent_flag, + in_operation_param2_memref_size, + in_operation_param2_memref_offset, + in_operation_param2_value_a, + in_operation_param2_value_b, + in_operation_param2_ionref_ionsharefd, + in_operation_param2_ionref_ionsize, + + in_operation_param3_tmpref_buffer, + in_operation_param3_tmpref_size, + in_operation_param3_memref_parent, + in_operation_param3_memref_parent_flag, + in_operation_param3_memref_size, + in_operation_param3_memref_offset, + in_operation_param3_value_a, + in_operation_param3_value_b, + in_operation_param3_ionref_ionsharefd, + in_operation_param3_ionref_ionsize, + + in_operation_param4_tmpref_buffer, + in_operation_param4_tmpref_size, + in_operation_param4_memref_parent, + in_operation_param4_memref_parent_flag, + in_operation_param4_memref_size, + in_operation_param4_memref_offset, + in_operation_param4_value_a, + in_operation_param4_value_b, + in_operation_param4_ionref_ionsharefd, + in_operation_param4_ionref_ionsize, + + in_operation_session, + in_operation_cancelflag, + + in_returnorigin, + + in_buffer1, + in_buffer1_realsize, + in_buffer2, + in_buffer2_realsize, + in_buffer3, + in_buffer3_realsize, + in_buffer4, + in_buffer4_realsize, + + + &teecresult, + + &sessionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + + &opscnt, + &head_next, + &head_prev, + &context, + + &started, + ¶mtypes, + + &operation_param1_tmpref_buffer, + &operation_param1_tmpref_size, + &operation_param1_memref_parent, + &operation_param1_memref_parent_flag, + &operation_param1_memref_size, + &operation_param1_memref_offset, + &operation_param1_value_a, + &operation_param1_value_b, + &operation_param1_ionref_ionsharefd, + &operation_param1_ionref_ionsize, + + &operation_param2_tmpref_buffer, + &operation_param2_tmpref_size, + &operation_param2_memref_parent, + &operation_param2_memref_parent_flag, + &operation_param2_memref_size, + &operation_param2_memref_offset, + &operation_param2_value_a, + &operation_param2_value_b, + &operation_param2_ionref_ionsharefd, + &operation_param2_ionref_ionsize, + + &operation_param3_tmpref_buffer, + &operation_param3_tmpref_size, + &operation_param3_memref_parent, + &operation_param3_memref_parent_flag, + &operation_param3_memref_size, + &operation_param3_memref_offset, + &operation_param3_value_a, + &operation_param3_value_b, + &operation_param3_ionref_ionsharefd, + &operation_param3_ionref_ionsize, + + &operation_param4_tmpref_buffer, + &operation_param4_tmpref_size, + &operation_param4_memref_parent, + &operation_param4_memref_parent_flag, + &operation_param4_memref_size, + &operation_param4_memref_offset, + &operation_param4_value_a, + &operation_param4_value_b, + &operation_param4_ionref_ionsharefd, + &operation_param4_ionref_ionsize, + + &operation_session, + &operation_cancelflag, + + &returnorigin_temp, + + buffer1_temp, + buffer1_size, + &buffer1_outsize_temp, + buffer2_temp, + buffer2_size, + &buffer2_outsize_temp, + buffer3_temp, + buffer3_size, + &buffer3_outsize_temp, + buffer4_temp, + buffer4_size, + &buffer4_outsize_temp + ); + + serviceid_clockseqandnode_outsize = + serviceid_clockseqandnode_outsize_temp; + + returnorigin = returnorigin_temp; + + buffer1_outsize = buffer1_outsize_temp; + buffer2_outsize = buffer2_outsize_temp; + buffer3_outsize = buffer3_outsize_temp; + buffer4_outsize = buffer4_outsize_temp; + + buffer1_realsize = buffer1_outsize; + if (buffer1_realsize > 0) + { + buffer1 = + (dbus_uint32_t *)malloc( + buffer1_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < buffer1_realsize ; i++) { + buffer1[i] = (dbus_uint32_t)buffer1_temp[i]; + } + } + + buffer2_realsize = buffer2_outsize; + if (buffer2_realsize > 0) + { + buffer2 = + (dbus_uint32_t *)malloc( + buffer2_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < buffer2_realsize ; i++) { + buffer2[i] = (dbus_uint32_t)buffer2_temp[i]; + } + } + + buffer3_realsize = buffer3_outsize; + if (buffer3_realsize > 0) + { + buffer3 = + (dbus_uint32_t *)malloc( + buffer3_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < buffer3_realsize ; i++) { + buffer3[i] = (dbus_uint32_t)buffer3_temp[i]; + } + } + + buffer4_realsize = buffer4_outsize; + if (buffer4_realsize > 0) + { + buffer4 = + (dbus_uint32_t *)malloc( + buffer4_realsize * sizeof(dbus_uint32_t) + ); + for (int i = 0; i < buffer4_realsize ; i++) { + buffer4[i] = (dbus_uint32_t)buffer4_temp[i]; + } + } + + } // end of the else found == 1 + + if ( buffer1_temp != NULL ) + { + free(buffer1_temp); + } + if ( buffer2_temp != NULL ) + { + free(buffer2_temp); + } + if ( buffer3_temp != NULL ) + { + free(buffer3_temp); + } + if ( buffer4_temp != NULL ) + { + free(buffer4_temp); + } +#endif + /////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////////////// + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &teecresult + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &sessionid + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timelow + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timemid + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_timehiandver + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &serviceid_clockseqandnode_outsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (serviceid_clockseqandnode_outsize > 0 && + serviceid_clockseqandnode != NULL + ) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize + ); + + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &opscnt + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &head_next + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &head_prev + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &context + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &started + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + ¶mtypes + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param1_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param1_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_memref_parent_flag + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param1_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param1_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param2_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param2_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_memref_parent_flag + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param2_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param2_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param3_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param3_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_memref_parent_flag + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param3_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param3_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param4_tmpref_buffer + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_tmpref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_param4_memref_parent + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_memref_parent_flag + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_memref_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_memref_offset + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_value_a + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_value_b + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_param4_ionref_ionsharefd + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &operation_param4_ionref_ionsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &operation_session + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &operation_cancelflag + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &returnorigin + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &buffer1_outsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (buffer1_outsize > 0 && + buffer1 != NULL + ) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &buffer1, + buffer1_realsize + ); + + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &buffer2_outsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (buffer2_outsize > 0 && + buffer2 != NULL + ) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &buffer2, + buffer2_realsize + ); + + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &buffer3_outsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (buffer3_outsize > 0 && + buffer3 != NULL + ) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &buffer3, + buffer3_realsize + ); + + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &buffer4_outsize + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + if (buffer4_outsize > 0 && + buffer4 != NULL + ) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &buffer4, + buffer4_realsize + ); + + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + // send the reply && flush the connection + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + free(thdfargs); + return NULL; + } + + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + // dbus_connection_close(conn); + // dbus_connection_unref(conn); + free(thdfargs); + + // sleep(2); + + return NULL; +} + + +#ifdef GP_PROXY + void* +session_timeout_process ( + void* thdfargs +) +{ + DBusMsgConn* DBusMCP; + pthread_mutex_t * mutex_workerrec; + wr_t * workerrec; + + DBusMCP = (DBusMsgConn*)thdfargs; + mutex_workerrec = DBusMCP->mutex_workerrec; + workerrec = DBusMCP->workerrec; + + struct timeval tv; + uint64_t u64time; + + char workername[1024]; + memset((char *)workername, 0, 1024); + int iworker; + + dbus_uint32_t in_session_seesionid; + dbus_uint32_t in_session_serviceid_timelow = 0; + dbus_uint32_t in_session_serviceid_timemid = 0; + dbus_uint32_t in_session_serviceid_timehiandver = 0; + dbus_uint32_t in_session_serviceid_clockseqandnode_size = 8; + dbus_uint32_t in_session_serviceid_clockseqandnode[8]; + dbus_uint32_t in_session_opscnt = 0; + dbus_uint64_t in_session_head_next = 0; + dbus_uint64_t in_session_head_prev = 0; + dbus_uint64_t in_session_context; + + dbus_uint32_t seesionid; + dbus_uint32_t serviceid_timelow; + dbus_uint32_t serviceid_timemid; + dbus_uint32_t serviceid_timehiandver; + dbus_uint32_t * serviceid_clockseqandnode; + int serviceid_clockseqandnode_realsize; + dbus_uint32_t opscnt; + dbus_uint64_t head_next; + dbus_uint64_t head_prev; + dbus_uint64_t context; + + sin_t * sinIns; + + while (1) + { + sleep(TIMEDOUT_SESSION); + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + if (workerrec[iworker].busy == 1) + { + sinIns = NULL; + if (workerrec[iworker].first != NULL) + { + sinIns = workerrec[iworker].first; + do + { + gettimeofday(&tv, NULL); + u64time = (long unsigned int)(tv.tv_sec - + sinIns->session_createtime.tv_sec + ); + sin_t * sinTemp = NULL; + + if (u64time > TIMEDOUT_SESSION) + { + sprintf(workername, "%s%d", "gpworker", iworker); + + in_session_seesionid = sinIns->session_id; + in_session_context = workerrec[iworker].context_addr; + + for (int iind = 0; iind < 8; iind++) + { + in_session_serviceid_clockseqandnode[iind] = 0; + } + + pthread_mutex_unlock(mutex_workerrec); + + uint32_t serviceid_clockseqandnode_outsize_temp; + serviceid_clockseqandnode_realsize = 8; + serviceid_clockseqandnode = + (dbus_uint32_t *)malloc( + serviceid_clockseqandnode_realsize * sizeof(dbus_uint32_t) + ); + + printf("\nMethod call teec closesession. (Called by Proxy for timeout process) \n"); + method_call_teec_closesession( + workername, + + in_session_seesionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + &seesionid, + &serviceid_timelow, + &serviceid_timemid, + &serviceid_timehiandver, + serviceid_clockseqandnode, + serviceid_clockseqandnode_realsize, + &serviceid_clockseqandnode_outsize_temp, + &opscnt, + &head_next, + &head_prev, + &context + ); + + if (serviceid_clockseqandnode != NULL) { + free(serviceid_clockseqandnode); + } + + pthread_mutex_lock(mutex_workerrec); + + sinTemp = sinIns->prev; + if (sinTemp != NULL) + { + sinTemp->next = sinIns->next; + } + sinTemp = sinIns->next; + if (sinTemp != NULL) + { + sinTemp->prev = sinIns->prev; + } + if (workerrec[iworker].last == sinIns) + { + workerrec[iworker].last = sinIns->prev; + } + if (workerrec[iworker].first == sinIns) + { + workerrec[iworker].first = sinIns->next; + } + + // free(sinIns); + sinTemp = sinIns; + workerrec[iworker].sessionid_count = + workerrec[iworker].sessionid_count - 1; + + } // end of if timedout + sinIns = sinIns->next; + if (sinTemp != NULL) + { + free(sinTemp); + } + }while (sinIns != NULL); + + + } // end of the first not null + } // end of the busy = 1 + } // end of the for iworker + pthread_mutex_unlock(mutex_workerrec); + + } // end of while 1 + + + free(thdfargs); + return NULL; +} + + +void* +context_timeout_process ( + void* thdfargs +) +{ + DBusMsgConn* DBusMCP; + pthread_mutex_t * mutex_workerrec; + pthread_cond_t * cond_notbusy; + wr_t * workerrec; + + DBusMCP = (DBusMsgConn*)thdfargs; + mutex_workerrec = DBusMCP->mutex_workerrec; + cond_notbusy = DBusMCP->cond_notbusy; + workerrec = DBusMCP->workerrec; + + + + struct timeval tv; + uint64_t u64time; + + char workername[1024]; + memset((char *)workername, 0, 1024); + int iworker; + + dbus_int32_t in_fd; + unsigned char * in_ta_path = NULL; + dbus_int32_t in_ta_path_size = 0; + dbus_uint64_t in_session_list_next = 0; + dbus_uint64_t in_session_list_prev = 0; + dbus_uint64_t in_shrd_mem_list_next = 0; + dbus_uint64_t in_shrd_mem_list_prev = 0; + dbus_uint64_t in_share_buffer_buffer = 0; + dbus_int64_t in_share_buffer_buffer_barrier = 0; + dbus_uint64_t in_context_addr; + + dbus_int32_t fd; + unsigned char * ta_path; + dbus_int32_t ta_path_size; + dbus_uint64_t session_list_next; + dbus_uint64_t session_list_prev; + dbus_uint64_t shrd_mem_list_next; + dbus_uint64_t shrd_mem_list_prev; + dbus_uint64_t share_buffer_buffer; + dbus_int64_t share_buffer_buffer_barrier; + uint32_t context_tapath_outsize; + + while(1) + { + sleep(TIMEDOUT_CONTEXT); + + pthread_mutex_lock(mutex_workerrec); + for (iworker = 0; iworker < MAX_NUM_WORKER; iworker++) + { + if (workerrec[iworker].busy == 1) + { + sprintf(workername, "%s%d", "gpworker", iworker); + gettimeofday(&tv, NULL); + u64time = (long unsigned int)(tv.tv_sec - + workerrec[iworker].context_createtime.tv_sec + ); + if (u64time > TIMEDOUT_CONTEXT + && + workerrec[iworker].sessionid_count == 0 + ) + { + in_fd = workerrec[iworker].context_fd; + in_context_addr = workerrec[iworker].context_addr; + ta_path = (unsigned char *)malloc(1024 * sizeof(char)); + ta_path_size = 1024; + memset((char *)ta_path, 0, 1024); + + pthread_mutex_unlock(mutex_workerrec); + + printf("\nMethod call teec fincont. (Called by Proxy for timeout process) \n"); + method_call_teec_fincont( + workername, + + in_fd, + in_ta_path, + in_ta_path_size, + in_session_list_next, + in_session_list_prev, + in_shrd_mem_list_next, + in_shrd_mem_list_prev, + in_share_buffer_buffer, + in_share_buffer_buffer_barrier, + in_context_addr, + + &fd, + ta_path, + ta_path_size, + &session_list_next, + &session_list_prev, + &shrd_mem_list_next, + &shrd_mem_list_prev, + &share_buffer_buffer, + &share_buffer_buffer_barrier, + + &context_tapath_outsize + ); + + if (ta_path != NULL) + { + free(ta_path); + } + + pthread_mutex_lock(mutex_workerrec); + + workerrec[iworker].busy = 0; + pthread_cond_signal(cond_notbusy); + workerrec[iworker].context_fd = 0; + workerrec[iworker].context_addr = 0xffffffff; + workerrec[iworker].sessionid_count = 0; + sin_t * sinIns; + sin_t * sinInsPrev; + sinIns = workerrec[iworker].last; + if (sinIns != NULL) + { + for ( ; ; ) + { + sinInsPrev = sinIns->prev; + free(sinIns); + sinIns = sinInsPrev; + if (sinIns == NULL) + { + break; + } + } + } + + } // end of the if timeed out + } // end of the if busy = 1 + } // end of the for iworker + pthread_mutex_unlock(mutex_workerrec); + + } // end of while 1 + + free(thdfargs); + return NULL; +} +#endif + + +void * +reply_to_method_call_destroy_threadpool( + DBusMessage *msg, + DBusConnection *conn, + threadpool_t *pool +#ifdef GP_WORKER + , + pthread_mutex_t *mutex_tcl, + pthread_mutex_t *mutex_tsl +#endif + +#ifdef GP_PROXY + , + pthread_mutex_t * mutex_workerrec, + pthread_cond_t * cond_notbusy +#endif +) +{ + DBusMessage *reply; + DBusMessageIter args; + // char* param = ""; + char *param = NULL; + dbus_bool_t bResult; + dbus_uint32_t retcode; + dbus_uint32_t serial = 0; + + // read the arguments + if (!dbus_message_iter_init(msg, &args)) + fprintf(stderr, "Message has no arguments!\n"); + else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) + fprintf(stderr, "Argument is not string!\n"); + else + dbus_message_iter_get_basic(&args, ¶m); + + printf("\n"); + printf("Received mechod call Destroy: \n"); + printf(" param = %s \n", param); + printf("\n"); + + // create a reply from the message + reply = dbus_message_new_method_return(msg); + + retcode = 0x00; + + // add the arguments to the reply + dbus_message_iter_init_append(reply, &args); + bResult = + dbus_message_iter_append_basic( + &args, + DBUS_TYPE_UINT32, + &retcode + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + serial = 100; + if (!dbus_connection_send(conn, reply, &serial)) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return NULL; + } + + dbus_message_unref(reply); + dbus_connection_flush(conn); + dbus_message_unref(msg); + // dbus_connection_close(conn); + // dbus_connection_unref(conn); + + + threadpool_destroy(pool); + +#ifdef GP_WORKER + pthread_mutex_destroy(mutex_tcl); + pthread_mutex_destroy(mutex_tsl); +#endif + +#ifdef GP_PROXY + pthread_mutex_destroy(mutex_workerrec); + pthread_cond_destroy(cond_notbusy); +#endif + + printf("\n"); + printf("This process exits. \n"); + printf("\n"); + + exit(1); + + return NULL; +} + +#endif diff --git a/teeproxy/gpworker/tzcp_dbus.h b/teeproxy/gpworker/tzcp_dbus.h new file mode 100644 index 0000000000000000000000000000000000000000..d92f224a8866ae0bc645e0a7afd367dd247c0701 --- /dev/null +++ b/teeproxy/gpworker/tzcp_dbus.h @@ -0,0 +1,550 @@ +#ifndef _TZCP_DBUS_H_ +#define _TZCP_DBUS_H_ + +#include +#include + +#define GP_PROXY_WORKER 1 +// #define GP_PROXY 2 +#define GP_WORKER 3 + +#ifdef GP_PROXY_WORKER + +#include "threadpool.h" + +#define MAX_NUM_THREAD 128 +#define MAX_NUM_WORKER 128 +#define TIMEDOUT_SESSION 60 //seconds +#define TIMEDOUT_CONTEXT 90 //seconds + +#define TEEC_ERROR_CONTEXT_NULL 0xAAAA0001 /* null context */ +#define TEEC_ERROR_CONTEXT_TAPATH_NULL 0xAAAA0002 /* null context ta path */ +#define TEEC_ERROR_PARAM0_TEMPMEM_NULL 0xAAAA0003 /* null param0 tempmem buf */ +#define TEEC_ERROR_PARAM0_TEMPMEM_LESS 0xAAAA0004 /* param0 tempmem buf is less */ +#define TEEC_ERROR_PARAM1_TEMPMEM_NULL 0xAAAA0005 /* null param1 tempmem buf */ +#define TEEC_ERROR_PARAM1_TEMPMEM_LESS 0xAAAA0006 /* param1 tempmem buf is less */ +#define TEEC_ERROR_PARAM2_TEMPMEM_NULL 0xAAAA0007 /* null param2 tempmem buf */ +#define TEEC_ERROR_PARAM2_TEMPMEM_LESS 0xAAAA0008 /* param2 tempmem buf is less */ +#define TEEC_ERROR_PARAM3_TEMPMEM_NULL 0xAAAA0009 /* null param3 tempmem buf */ +#define TEEC_ERROR_PARAM3_TEMPMEM_LESS 0xAAAA000A /* param3 tempmem buf is less */ +#define TEEC_ERROR_CONTEXT_LIST_NULL 0xAAAA000B /* null context list in woker */ +#define TEEC_ERROR_NO_CONTEXT_MATCH 0xAAAA000C /* no context match in woker */ +#define TEEC_ERROR_SESSION_LIST_NULL 0xAAAA000D /* null session list in woker */ +#define TEEC_ERROR_NO_SESSION_MATCH 0xAAAA000E /* no session match in woker */ +#define TEEC_ERROR_PARAM0_MEMREF_NULL 0xAAAA000F /* null param0 memref buf */ +#define TEEC_ERROR_PARAM0_MEMREF_LESS 0xAAAA0010 /* param0 memref buf is less */ +#define TEEC_ERROR_PARAM1_MEMREF_NULL 0xAAAA0011 /* null param1 memref buf */ +#define TEEC_ERROR_PARAM1_MEMREF_LESS 0xAAAA0012 /* param1 memref buf is less */ +#define TEEC_ERROR_PARAM2_MEMREF_NULL 0xAAAA0013 /* null param2 memref buf */ +#define TEEC_ERROR_PARAM2_MEMREF_LESS 0xAAAA0014 /* param2 memref buf is less */ +#define TEEC_ERROR_PARAM3_MEMREF_NULL 0xAAAA0015 /* null param3 memref buf */ +#define TEEC_ERROR_PARAM3_MEMREF_LESS 0xAAAA0016 /* param3 memref buf is less */ +#define TEEC_ERROR_NO_WORKER_MATCHED 0xAAAA0017 /* No woker mateched with the context or/and session */ +#define TEEC_ERROR_SESSION_NULL 0xAAAA0018 /* null session */ +#define TEEC_ERROR_NO_SHAREMEMFLAG 0xAAAA0019 /* no share memmory flag */ + +#endif + + +#ifdef GP_PROXY_WORKER +typedef struct +{ + DBusMessage *msg; + DBusConnection *conn; +#ifdef GP_PROXY + pthread_mutex_t * mutex_workerrec; + pthread_cond_t * cond_notbusy; + wr_t * workerrec; +#endif +#ifdef GP_WORKER + int64_t workernum; + pthread_mutex_t *mutex_tcl; + pthread_mutex_t *mutex_tsl; + tcl_t *tcl; + tsl_t *tsl; +#endif +} DBusMsgConn; +#endif + +void +receive_signal(void); + +void +send_signal( + char *sigvalue +); + +#ifdef GP_PROXY_WORKER + +void +receive_methodcall( + threadpool_t *pool, +#ifdef GP_WORKER + pthread_mutex_t *mutex_tcl, + pthread_mutex_t *mutex_tsl, + tcl_t *tcl, + tsl_t *tsl, +#endif + char *workername + +#ifdef GP_PROXY + , + pthread_mutex_t * mutex_workerrec, + pthread_cond_t * cond_notbusy, + wr_t * workerrec +#endif +); + +#endif + +int32_t +method_call_teec_inicont( + const char *workername, + + const uint8_t *name, size_t name_size, + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t *teecresult, + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint64_t *context_addr, + uint32_t *context_tapath_outsize +); + +int32_t +method_call_teec_fincont( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + uint64_t in_context_addr, + + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint32_t *context_tapath_outsize +); + +int32_t +method_call_teec_opensession( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, + size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t in_destination_timelow, + uint32_t in_destination_timemid, + uint32_t in_destination_timehiandver, + uint32_t *in_destination_clockseqandnode, + int32_t in_destination_clockseqandnode_size, + uint32_t in_connectionmethod, + uint64_t in_connectiondata, + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint64_t in_context_addr, + + + uint32_t *teecresult, + + int32_t *context_fd, + uint8_t *context_tapath, + size_t context_tapath_size, + uint32_t *context_tapath_outsize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin +); + +int32_t +method_call_teec_closesession( + const char *workername, + + uint32_t in_session_seesionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + int32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context +); + +int32_t +method_call_teec_invokecommand( + const char *workername, + + uint32_t in_session_seesionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + uint32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t commandid, + + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_parent_flag, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_parent_flag, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_parent_flag, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_parent_flag, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint32_t *in_buffer1, + uint32_t in_buffer1_size, + uint32_t *in_buffer2, + uint32_t in_buffer2_size, + uint32_t *in_buffer3, + uint32_t in_buffer3_size, + uint32_t *in_buffer4, + uint32_t in_buffer4_size, + + + uint32_t *teecresult, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_parent_flag, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_parent_flag, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_parent_flag, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_parent_flag, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin, + + uint32_t *buffer1, + uint32_t buffer1_size, + uint32_t *buffer1_outsize, + uint32_t *buffer2, + uint32_t buffer2_size, + uint32_t *buffer2_outsize, + uint32_t *buffer3, + uint32_t buffer3_size, + uint32_t *buffer3_outsize, + uint32_t *buffer4, + uint32_t buffer4_size, + uint32_t *buffer4_outsize +); + +void +method_call_destroy_threadpool( + const char *workername +); + + +#ifdef GP_PROXY_WORKER + +void * +reply_to_method_call_teec_inicont( + void *thdfargs +); + +void * +reply_to_method_call_teec_fincont( + void *thdfargs +); + +void * +reply_to_method_call_teec_opensession( + void *thdfargs +); + +void * +reply_to_method_call_teec_closesession( + void *thdfargs +); + +void * +reply_to_method_call_teec_invokecommand( + void *thdfargs +); + +#ifdef GP_PROXY +void* +session_timeout_process ( + void* thdfargs +); + +void* +context_timeout_process ( + void* thdfargs +); +#endif + +void * +reply_to_method_call_destroy_threadpool( + DBusMessage *msg, + DBusConnection *conn, + threadpool_t *pool +#ifdef GP_WORKER + , + pthread_mutex_t *mutex_tcl, + pthread_mutex_t *mutex_tsl +#endif +#ifdef GP_PROXY + , + pthread_mutex_t * mutex_workerbusy, + pthread_cond_t * cond_notbusy +#endif +); + +#endif + + +#endif /* _TZCP_DBUS_H_ */ diff --git a/teeproxy/libdbuscgpw/CMakeLists.txt b/teeproxy/libdbuscgpw/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..236a2ec4a68e414d47bda86a9ce6bad98b36306b --- /dev/null +++ b/teeproxy/libdbuscgpw/CMakeLists.txt @@ -0,0 +1,45 @@ +# + +cmake_minimum_required(VERSION 3.5.1) + +project(libdbusc_gpw C CXX) + +# set(CMAKE_C_FLAGS "${CMAKE_}") +# set(CMAKE_CONFIGURATION_TYPES "Debug" CACHE STRING "" FORCE) + +include_directories("${CMAKE_CURRENT_BINARY_DIR}") +# include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include/) +include_directories(/usr/include/dbus-1.0/) +include_directories(/usr/lib64/dbus-1.0/include/) + +# Introduce variables: +# - CMAKE_INSTALL_LIBDIR +# - CMAKE_INSTALL_BINDIR +# - CMAKE_INSTALL_INCLUDEDIR +include(GNUInstallDirs) + +set(LIB_DBUSC_GPW + ${PROJECT_SOURCE_DIR}/dbusc_gpw.c +) +# Install Headers: +set(HEADERS_DBUSC_GPW + dbusc_gpw.h +) +install( + FILES ${HEADERS_DBUSC_GPW} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${TARGET_NAME}" +) + +add_library(dbusc_gpw SHARED ${LIB_DBUSC_GPW}) +target_link_libraries(dbusc_gpw + libdbus-1.so +) +# set_target_properties(dbusc_gpw +# PROPERTIES IMPORTED_LOCATION +# ) + +# Install lib: +install( + TARGETS "dbusc_gpw" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) diff --git a/teeproxy/libdbuscgpw/build/cmake.sh b/teeproxy/libdbuscgpw/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..bef7b3e835a5c4c5aa8420ff771f5b58cb7bd2c0 --- /dev/null +++ b/teeproxy/libdbuscgpw/build/cmake.sh @@ -0,0 +1 @@ +cmake -DCMAKE_BUILD_TYPE=Debug .. diff --git a/teeproxy/libdbuscgpw/dbusc_gpw.c b/teeproxy/libdbuscgpw/dbusc_gpw.c new file mode 100644 index 0000000000000000000000000000000000000000..106992991c11016b51361e48e4aebbf45109dc1c --- /dev/null +++ b/teeproxy/libdbuscgpw/dbusc_gpw.c @@ -0,0 +1,9291 @@ +/* + * Using low-level D-Bus C API code. + * Written by + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dbusc_gpw.h" + + +/** + * Listens for signals on the bus + */ +void +receive_signal(void) +{ + DBusMessage *msg; + DBusMessageIter args; + DBusConnection *conn; + DBusError err; + int ret; + char *sigvalue; + + printf("Listening for signals\n"); + + // initialise the errors + dbus_error_init(&err); + + // connect to the bus and check for errors + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + exit(1); + } + + // request our name on the bus and check for errors + ret = dbus_bus_request_name(conn, "test.signal.sink", DBUS_NAME_FLAG_REPLACE_EXISTING, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + exit(1); + } + + // add a rule for which messages we want to see + dbus_bus_add_match(conn, "type='signal',interface='test.signal.Type'", &err); + // see signals from the given interface + dbus_connection_flush(conn); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Match Error (%s)\n", err.message); + exit(1); + } + // printf("Match rule sent\n"); + + // loop listening for signals being emmitted + while (true) + { + + // non blocking read of the next available message + dbus_connection_read_write(conn, 0); + msg = dbus_connection_pop_message(conn); + + // loop again if we haven't read a message + if (NULL == msg) + { + usleep(10000); + continue; + } + + // check if the message is a signal from the correct interface and with the correct name + if (dbus_message_is_signal(msg, "test.signal.Type", "Test")) + { + + // read the parameters + if (!dbus_message_iter_init(msg, &args)) + fprintf(stderr, "Message Has No Parameters\n"); + else if (DBUS_TYPE_STRING != dbus_message_iter_get_arg_type(&args)) + fprintf(stderr, "Argument is not string!\n"); + else + dbus_message_iter_get_basic(&args, &sigvalue); + + printf("Got Signal with value %s\n", sigvalue); + } + + // free the message + dbus_message_unref(msg); + } +} + + +/** + * Connect to the DBUS bus and send a broadcast signal + */ +void +send_signal( + char *sigvalue +) +{ + DBusMessage *msg; + DBusMessageIter args; + DBusConnection *conn; + DBusError err; + int ret; + dbus_uint32_t sigserial = 0; + + printf("Sending signal with value %s\n", sigvalue); + + // initialise the error value + dbus_error_init(&err); + + // connect to the DBUS system bus, and check for errors + conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + exit(1); + } + + // register our name on the bus, and check for errors + ret = dbus_bus_request_name(conn, "test.signal.source", DBUS_NAME_FLAG_REPLACE_EXISTING, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + exit(1); + } + + // create a signal & check for errors + msg = dbus_message_new_signal("/test/signal/Object", // object name of the signal + "test.signal.Type", // interface name of the signal + "Test"); // name of the signal + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + exit(1); + } + + // append arguments onto signal + dbus_message_iter_init_append(msg, &args); + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &sigvalue)) + { + fprintf(stderr, "Out Of Memory!\n"); + exit(1); + } + + // send the message and flush the connection + if (!dbus_connection_send(conn, msg, &sigserial)) + { + fprintf(stderr, "Out Of Memory!\n"); + exit(1); + } + dbus_connection_flush(conn); + + printf("Signal Sent\n"); + + // free the message + dbus_message_unref(msg); +} + + +/** + * Call a method on a remote object + */ +int32_t +method_call_teec_inicont( + const char *workername, + + const uint8_t *name, size_t name_size, + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t *teecresult, + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint64_t *context_addr, + uint32_t *context_tapath_outsize +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + int ret; + int iType; + unsigned char *context_tapath_temp = NULL; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_int64_t di64Temp; + dbus_uint64_t dui64Temp; + + // initialiset the errors + dbus_error_init(&err); + + dbus_threads_init_default(); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + // conn = dbus_bus_get(DBUS_BUS_SESSION, &err); + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_InitializeContext" // method name + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + di32Temp = name_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (name_size > 0 && name != NULL) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &name + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + di32Temp = in_context_fd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_context_tapath_size > 0 && + in_context_tapath != NULL && + strlen((const char *) in_context_tapath) > 0 + ) + { + if (dbus_validate_utf8((const char *) in_context_tapath, &err) == true) + { + di32Temp = strlen((const char *) in_context_tapath); + } else + { + di32Temp = 0; + } + } else + { + di32Temp = 0; + } + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + // if (in_context_tapath_size > 0 && in_context_tapath != NULL) + if (di32Temp > 0) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &in_context_tapath + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + dui64Temp = in_context_sessionlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sessionlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sharebuffer_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di64Temp = in_context_sharebuffer_bufferbarrier; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &di64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + /* + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Init Contex Sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + // free the pending message handle + dbus_pending_call_unref(pending); + */ + + // printf("\n"); + printf("libdbuscgpw method call teec init contex sent. \n"); + + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbuscgpw: initcontext send_with_reply_and_block error, %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + if (reply == NULL) + { + fprintf(stderr, "libdbuscgpw: initcontext dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *teecresult = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *context_fd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *context_tapath_outsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + if (*context_tapath_outsize > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &context_tapath_temp); + + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sharebuffer_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di64Temp + ); + *context_sharebuffer_bufferbarrier = di64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_addr = dui64Temp; + + printf("libdbuscgpw got reply of method call teec init contex: \n"); + printf(" teecresult = 0x %8.8x \n", *teecresult); + printf(" fd = 0x %8.8x \n", (unsigned int) *context_fd); + printf(" ta_path = %s \n", context_tapath_temp); + printf(" ta_path_size = %d \n", (int) *context_tapath_outsize); +#if 0 + printf(" TEEC_Context session_list.next = 0x %16.16lx \n", + *context_sessionlist_next + ); + printf(" TEEC_Context session_list.prev = 0x %16.16lx \n", + *context_sessionlist_prev + ); + printf(" TEEC_Context shrd_mem_list.next = 0x %16.16lx \n", + *context_shrdmemlist_next + ); + printf(" TEEC_Context shrd_mem_list.prev = 0x %16.16lx \n", + *context_shrdmemlist_prev + ); + printf(" TEEC_Context share_buffer.buffer = 0x %16.16lx \n", + *context_sharebuffer_buffer + ); + printf(" TEEC_Context share_buffer.buffer_barrier = 0x %16.16lx \n", + (long unsigned int)*context_sharebuffer_bufferbarrier + ); +#endif + printf(" context addr = 0x %16.16lx \n", + (long unsigned int) *context_addr + ); + + if ( + context_tapath_insize > *context_tapath_outsize && + *context_tapath_outsize > 0 && + context_tapath != NULL && + context_tapath_temp != NULL + ) + { + memcpy(context_tapath, context_tapath_temp, *context_tapath_outsize); + *(context_tapath + *context_tapath_outsize) = 0; + } else + { + // dbus_message_unref(msg); + // return -1; + *(context_tapath + 0) = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +/** + * Call a method on a remote object + */ +int32_t +method_call_teec_fincont( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + uint64_t in_context_addr, + + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint32_t *context_tapath_outsize +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + int ret; + int iType; + unsigned char *context_tapath_temp = NULL; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_int64_t di64Temp; + dbus_uint64_t dui64Temp; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_FinalizeContext" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + di32Temp = in_context_fd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_context_tapath_size > 0 && + in_context_tapath != NULL && + strlen((const char *) in_context_tapath) > 0 + ) + { + // if (dbus_validate_utf8((const char *) in_context_tapath, &err) == true) + if (dbus_validate_path((const char *) in_context_tapath, &err) == true) + { + di32Temp = strlen((const char *) in_context_tapath); + } else + { + di32Temp = 0; + } + } else + { + di32Temp = 0; + } + + fprintf(stderr, "libdbuscgpw finalizecontext, in_context_tapath_size, di32Temp = %ld \n", di32Temp); + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + // if (in_context_tapath_size > 0 && in_context_tapath != NULL) + if (di32Temp > 0) + { + fprintf(stderr, "libdbuscgpw finalizecontext, in_context_tapath = %s \n", in_context_tapath); + + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &in_context_tapath + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + dui64Temp = in_context_sessionlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sessionlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sharebuffer_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di64Temp = in_context_sharebuffer_bufferbarrier; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &di64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_addr; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + + /* + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + // printf("\n"); + printf("libdbuscgpw method call teec fin contex sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + // free the pending message handle + dbus_pending_call_unref(pending); + */ + + + // printf("\n"); + printf("libdbuscgpw method call teec fin contex sent. \n"); + + dbus_error_init(&err); + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbuscgpw: finalizecontext send_with_reply_and_block error, %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + if (reply == NULL) + { + fprintf(stderr, "libdbuscgpw: finalizecontext dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *context_fd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *context_tapath_outsize = dui32Temp; + + if (*context_tapath_outsize > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &context_tapath_temp); + + } + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sharebuffer_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di64Temp + ); + *context_sharebuffer_bufferbarrier = di64Temp; + + printf("libdbuscgpw got reply of method call teec fin contex: \n"); + printf(" fd = 0x %8.8x \n", (unsigned int) *context_fd); + printf(" ta_path_size = %d \n", (int) *context_tapath_outsize); + if ((int) *context_tapath_outsize > 0 && context_tapath_temp != NULL && + dbus_validate_path((const char *) context_tapath_temp, &err) == true) + { + printf(" ta_path = %s \n", context_tapath_temp); + } +#if 0 + printf(" TEEC_Context session_list.next = 0x %16.16lx \n", + *context_sessionlist_next + ); + printf(" TEEC_Context session_list.prev = 0x %16.16lx \n", + *context_sessionlist_prev + ); + printf(" TEEC_Context shrd_mem_list.next = 0x %16.16lx \n", + *context_shrdmemlist_next + ); + printf(" TEEC_Context shrd_mem_list.prev = 0x %16.16lx \n", + *context_shrdmemlist_prev + ); + printf(" TEEC_Context share_buffer.buffer = 0x %16.16lx \n", + *context_sharebuffer_buffer + ); + printf(" TEEC_Context share_buffer.buffer_barrier = 0x %16.16lx \n", + (long unsigned int)*context_sharebuffer_bufferbarrier + ); +#endif + + if ( + context_tapath_insize > *context_tapath_outsize && + *context_tapath_outsize > 0 && + context_tapath != NULL && + context_tapath_temp != NULL + ) + { + memcpy(context_tapath, context_tapath_temp, *context_tapath_outsize); + *(context_tapath + *context_tapath_outsize) = 0; + } else + { + // dbus_message_unref(msg); + // return -1; + *(context_tapath + 0) = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +/** + * Call a method on a remote object + */ +int32_t +method_call_teec_opensession( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, + size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t in_destination_timelow, + uint32_t in_destination_timemid, + uint32_t in_destination_timehiandver, + uint32_t *in_destination_clockseqandnode, + int32_t in_destination_clockseqandnode_size, + + uint32_t in_connectionmethod, + uint64_t in_connectiondata, + + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint64_t in_context_addr, + + + uint32_t *teecresult, + + int32_t *context_fd, + uint8_t *context_tapath, + size_t context_tapath_size, + uint32_t *context_tapath_outsize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int ret; + int iType; + unsigned char *context_tapath_temp = NULL; + dbus_uint32_t *session_serviceid_clockseqandnode_temp = NULL; + int session_serviceid_clockseqandnode_realsize; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_int64_t di64Temp; + dbus_uint64_t dui64Temp; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_OpenSession" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + di32Temp = in_context_fd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_context_tapath_size > 0 && + in_context_tapath != NULL && + strlen((const char *) in_context_tapath) > 0 + ) + { + if (dbus_validate_utf8((const char *) in_context_tapath, &err) == true) + { + di32Temp = strlen((const char *) in_context_tapath); + } else + { + di32Temp = 0; + } + } else + { + di32Temp = 0; + } + + // fprintf(stderr, "in_context_tapath_size = %ld \n", in_context_tapath_size); + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + // if (in_context_tapath_size > 0 && in_context_tapath != NULL) + if (di32Temp > 0) + { + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_STRING, + &in_context_tapath + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + } + + dui64Temp = in_context_sessionlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sessionlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_shrdmemlist_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_sharebuffer_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di64Temp = in_context_sharebuffer_bufferbarrier; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT64, + &di64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_destination_timelow; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_destination_timemid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_destination_timehiandver; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_destination_clockseqandnode_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_destination_clockseqandnode_size > 0 && + in_destination_clockseqandnode != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_destination_clockseqandnode, + in_destination_clockseqandnode_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_connectionmethod; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_connectiondata; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui32Temp = in_operation_started; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_paramtypes; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param1_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param2_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param3_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param4_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_session; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_cancelflag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_returnorigin; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_context_addr; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + /////////////////////////////////////////////////////////////////// + + /* + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Open Session Sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + + // free the pending message handle + dbus_pending_call_unref(pending); + */ + + // printf("\n"); + printf("libdbuscgpw method call teec open session sent. \n"); + + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbuscgpw: opensession send_with_reply_and_block error, %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + if (reply == NULL) + { + fprintf(stderr, "libdbuscgpw: opensession dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *teecresult = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *context_fd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *context_tapath_outsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + if (*context_tapath_outsize > 0) + { + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_STRING + ) + { + fprintf(stderr, "Argument is not STRING.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &context_tapath_temp); + + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sessionlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_shrdmemlist_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *context_sharebuffer_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT64 + ) + { + fprintf(stderr, "Argument is not INT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di64Temp + ); + *context_sharebuffer_bufferbarrier = di64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_seesionid = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timelow = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timemid = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timehiandver = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_clockseqandnode_outsize = dui32Temp; + + if (*session_serviceid_clockseqandnode_outsize > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &session_serviceid_clockseqandnode_temp, + &session_serviceid_clockseqandnode_realsize + ); + } + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_opscnt = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_context = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_started = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_paramtypes = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param1_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param2_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param3_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_memref_parent = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param4_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_session = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_cancelflag = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *returnorigin = dui32Temp; + + printf("libdbuscgpw got reply of method call teec open session: \n"); + printf(" teecresult = 0x %8.8x \n", *teecresult); + printf(" fd = 0x %8.8x \n", (unsigned int) *context_fd); + printf(" ta_path = %s \n", context_tapath_temp); + printf(" ta_path_size = %d \n", (int) *context_tapath_outsize); + printf(" session_seesionid = 0x %8.8x \n", + *session_seesionid + ); +#if 0 + printf(" TEEC_Context session_list.next = 0x %16.16lx \n", + *context_sessionlist_next + ); + printf(" TEEC_Context session_list.prev = 0x %16.16lx \n", + *context_sessionlist_prev + ); + printf(" TEEC_Context shrd_mem_list.next = 0x %16.16lx \n", + *context_shrdmemlist_next + ); + printf(" TEEC_Context shrd_mem_list.prev = 0x %16.16lx \n", + *context_shrdmemlist_prev + ); + printf(" TEEC_Context share_buffer.buffer = 0x %16.16lx \n", + *context_sharebuffer_buffer + ); + printf(" TEEC_Context share_buffer.buffer_barrier = 0x %16.16lx \n", + (long unsigned int)*context_sharebuffer_bufferbarrier + ); + + printf(" TEEC_Session session_serviceid_timelow = 0x %8.8x \n", + *session_serviceid_timelow + ); + printf(" TEEC_Session session_serviceid_timehiandver = 0x %8.8x \n", + *session_serviceid_timehiandver + ); + + printf(" TEEC_Session session_serviceid_clockseqandnode = \n"); + if (*session_serviceid_clockseqandnode_outsize > 0 && + session_serviceid_clockseqandnode_temp != NULL) + { + printf(" "); + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", + session_serviceid_clockseqandnode_temp[i] + ); + } + printf("\n"); + } + printf(" TEEC_Session clockseqandnode_outsize = 0x %8.8x \n", + *session_serviceid_clockseqandnode_outsize + ); + + printf(" TEEC_Session session_opscnt = 0x %8.8x \n", + *session_opscnt + ); + printf(" TEEC_Session session_head_next = 0x %16.16lx \n", + *session_head_next + ); + printf(" TEEC_Session session_head_prev = 0x %16.16lx \n", + *session_head_prev + ); + printf(" TEEC_Session session_context = 0x %16.16lx \n", + *session_context + ); + printf(" TEEC_Session operation_started = 0x %8.8x \n", + *operation_started + ); + printf(" TEEC_Session operation_paramtypes = 0x %8.8x \n", + *operation_paramtypes + ); + + printf(" TEEC_Session operation_param1_tmpref_buffer = 0x %16.16lx \n", + *operation_param1_tmpref_buffer + ); + printf(" TEEC_Session operation_param1_tmpref_size = 0x %8.8x \n", + *operation_param1_tmpref_size + ); + printf(" TEEC_Session operation_param1_memref_parent = 0x %16.16lx \n", + *operation_param1_memref_parent + ); + printf(" TEEC_Session operation_param1_memref_size = 0x %8.8x \n", + *operation_param1_memref_size + ); + printf(" TEEC_Session operation_param1_memref_offse = 0x %8.8x \n", + *operation_param1_memref_offset + ); + printf(" TEEC_Session operation_param1_value_a = 0x %8.8x \n", + *operation_param1_value_a + ); + printf(" TEEC_Session operation_param1_value_b = 0x %8.8x \n", + *operation_param1_value_b + ); + printf(" TEEC_Session operation_param1_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param1_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param1_ionref_ionsize = 0x %8.8x \n", + *operation_param1_ionref_ionsize + ); + + printf(" TEEC_Session operation_param2_tmpref_buffer = 0x %16.16lx \n", + *operation_param2_tmpref_buffer + ); + printf(" TEEC_Session operation_param2_tmpref_size = 0x %8.8x \n", + *operation_param2_tmpref_size + ); + printf(" TEEC_Session operation_param2_memref_parent = 0x %16.16lx \n", + *operation_param2_memref_parent + ); + printf(" TEEC_Session operation_param2_memref_size = 0x %8.8x \n", + *operation_param2_memref_size + ); + printf(" TEEC_Session operation_param2_memref_offset = 0x %8.8x \n", + *operation_param2_memref_offset + ); + printf(" TEEC_Session operation_param2_value_a = 0x %8.8x \n", + *operation_param2_value_a + ); + printf(" TEEC_Session operation_param2_value_b = 0x %8.8x \n", + *operation_param2_value_b + ); + printf(" TEEC_Session operation_param2_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param2_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param2_ionref_ionsize = 0x %8.8x \n", + *operation_param2_ionref_ionsize + ); + + printf(" TEEC_Session operation_param3_tmpref_buffer = 0x %16.16lx \n", + *operation_param3_tmpref_buffer + ); + printf(" TEEC_Session operation_param3_tmpref_size = 0x %8.8x \n", + *operation_param3_tmpref_size + ); + printf(" TEEC_Session operation_param3_memref_parent = 0x %16.16lx \n", + *operation_param3_memref_parent + ); + printf(" TEEC_Session operation_param3_memref_size = 0x %8.8x \n", + *operation_param3_memref_size + ); + printf(" TEEC_Session operation_param3_memref_offset = 0x %8.8x \n", + *operation_param3_memref_offset + ); + printf(" TEEC_Session operation_param3_value_a = 0x %8.8x \n", + *operation_param3_value_a + ); + printf(" TEEC_Session operation_param3_value_b = 0x %8.8x \n", + *operation_param3_value_b + ); + printf(" TEEC_Session operation_param3_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param3_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param3_ionref_ionsize = 0x %8.8x \n", + *operation_param3_ionref_ionsize + ); + + printf(" TEEC_Session operation_param4_tmpref_buffer = 0x %16.16lx \n", + *operation_param4_tmpref_buffer + ); + printf(" TEEC_Session operation_param4_tmpref_size = 0x %8.8x \n", + *operation_param4_tmpref_size + ); + printf(" TEEC_Session operation_param4_memref_parent = 0x %16.16lx \n", + *operation_param4_memref_parent + ); + printf(" TEEC_Session operation_param4_memref_size = 0x %8.8x \n", + *operation_param4_memref_size + ); + printf(" TEEC_Session operation_param4_memref_offset = 0x %8.8x \n", + *operation_param4_memref_offset + ); + printf(" TEEC_Session operation_param4_value_a = 0x %8.8x \n", + *operation_param4_value_a + ); + printf(" TEEC_Session operation_param4_value_b = 0x %8.8x \n", + *operation_param4_value_b + ); + printf(" TEEC_Session operation_param4_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param4_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param4_ionref_ionsize = 0x %8.8x \n", + *operation_param4_ionref_ionsize + ); + + printf(" TEEC_Session operation_session = 0x %16.16lx \n", + *operation_session + ); + printf(" TEEC_Session operation_cancelflag = 0x %8.8x \n", + (unsigned int)*operation_cancelflag + ); + printf(" TEEC_Session returnorigin = 0x %8.8x \n", + *returnorigin + ); +#endif + + if (context_tapath_size > *context_tapath_outsize) + { + memcpy(context_tapath, context_tapath_temp, *context_tapath_outsize); + *(context_tapath + *context_tapath_outsize) = 0; + } else + { + dbus_message_unref(msg); + return -1; + } + + if (session_serviceid_clockseqandnode_size >= session_serviceid_clockseqandnode_realsize && + session_serviceid_clockseqandnode_temp != NULL && + session_serviceid_clockseqandnode_realsize > 0 + ) + { + /* + memcpy( + session_serviceid_clockseqandnode, + session_serviceid_clockseqandnode_temp, + session_serviceid_clockseqandnode_realsize + ); + */ + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) + { + session_serviceid_clockseqandnode[i] = + session_serviceid_clockseqandnode_temp[i]; + + } + *session_serviceid_clockseqandnode_outsize = session_serviceid_clockseqandnode_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *session_serviceid_clockseqandnode_outsize = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +int32_t +method_call_teec_closesession( + const char *workername, + + uint32_t in_session_seesionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + int32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int ret; + int iType; + dbus_uint32_t *session_serviceid_clockseqandnode_temp = NULL; + int session_serviceid_clockseqandnode_realsize; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_uint64_t dui64Temp; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_CloseSession" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + dui32Temp = in_session_seesionid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timelow; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timemid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timehiandver; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_session_serviceid_clockseqandnode_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_session_serviceid_clockseqandnode_size > 0 && + in_session_serviceid_clockseqandnode != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_session_opscnt; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui64Temp = in_session_head_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_head_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_context; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + /* + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Close Session Sent. \n"); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + + // free the pending message handle + dbus_pending_call_unref(pending); + */ + + // printf("\n"); + printf("libdbuscgpw method call teec close session sent. \n"); + + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbuscgpw: closesession send_with_reply_and_block error, %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + if (reply == NULL) + { + fprintf(stderr, "libdbuscgpw: closesession dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_seesionid = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timelow = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timemid = dui32Temp; + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timehiandver = dui32Temp; + + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_clockseqandnode_outsize = dui32Temp; + + if (*session_serviceid_clockseqandnode_outsize > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + + dbus_message_iter_recurse( + &structIter, + &ArrayIter); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &session_serviceid_clockseqandnode_temp, + &session_serviceid_clockseqandnode_realsize + ); + } + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_opscnt = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_context = dui64Temp; + + + printf("libdbuscgpw got reply of method call teec close session: \n"); + printf(" session_seesionid = 0x %8.8x \n", + *session_seesionid + ); +#if 0 + printf(" TEEC_Session session_serviceid_timelow = 0x %8.8x \n", + *session_serviceid_timelow + ); + printf(" TEEC_Session session_serviceid_timemid = 0x %8.8x \n", + *session_serviceid_timemid + ); + printf(" TEEC_Session session_serviceid_timehiandver = 0x %8.8x \n", + *session_serviceid_timehiandver + ); + printf(" TEEC_Session session_serviceid_clockseqandnode = \n"); + printf(" "); + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", + session_serviceid_clockseqandnode_temp[i] + ); + } + printf("\n"); + printf(" TEEC_Session clockseqandnode_outsize = 0x %8.8x \n", + *session_serviceid_clockseqandnode_outsize + ); + printf(" TEEC_Session session_opscnt = 0x %8.8x \n", + *session_opscnt + ); + printf(" TEEC_Session session_head_next = 0x %16.16lx \n", + *session_head_next + ); + printf(" TEEC_Session session_head_prev = 0x %16.16lx \n", + *session_head_prev + ); +#endif + printf(" session_context = 0x %16.16lx \n", + *session_context + ); + + if (session_serviceid_clockseqandnode_size >= session_serviceid_clockseqandnode_realsize && + session_serviceid_clockseqandnode_temp != NULL && + session_serviceid_clockseqandnode_realsize > 0 + ) + { + memcpy( + session_serviceid_clockseqandnode, + session_serviceid_clockseqandnode_temp, + session_serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + *session_serviceid_clockseqandnode_outsize = session_serviceid_clockseqandnode_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *session_serviceid_clockseqandnode_outsize = 0; + } + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +int32_t +method_call_teec_invokecommand( + const char *workername, + + uint32_t in_session_sessionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + uint32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t commandid, + + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_parent_flag, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_parent_flag, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_parent_flag, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_parent_flag, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint32_t *in_buffer1, + uint32_t in_buffer1_size, + uint32_t *in_buffer2, + uint32_t in_buffer2_size, + uint32_t *in_buffer3, + uint32_t in_buffer3_size, + uint32_t *in_buffer4, + uint32_t in_buffer4_size, + + + uint32_t *teecresult, + + uint32_t *session_sessionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_parent_flag, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_parent_flag, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_parent_flag, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_parent_flag, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin, + + uint32_t *buffer1, + uint32_t buffer1_size, + uint32_t *buffer1_outsize, + uint32_t *buffer2, + uint32_t buffer2_size, + uint32_t *buffer2_outsize, + uint32_t *buffer3, + uint32_t buffer3_size, + uint32_t *buffer3_outsize, + uint32_t *buffer4, + uint32_t buffer4_size, + uint32_t *buffer4_outsize +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + DBusMessageIter structIter; + DBusMessageIter ArrayIter; + int ret; + int iType; + dbus_uint32_t *session_serviceid_clockseqandnode_temp = NULL; + int session_serviceid_clockseqandnode_realsize; + dbus_int32_t di32Temp; + dbus_uint32_t dui32Temp; + dbus_uint64_t dui64Temp; + char buf[2]; + buf[0] = DBUS_TYPE_UINT32; + buf[1] = '\0'; + + dbus_uint32_t *buffer1_temp = NULL; + int buffer1_realsize; + dbus_uint32_t *buffer2_temp = NULL; + int buffer2_realsize; + dbus_uint32_t *buffer3_temp = NULL; + int buffer3_realsize; + dbus_uint32_t *buffer4_temp = NULL; + int buffer4_realsize; + + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return -1; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return -1; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "TEEC_InvokeCommand" + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return -1; + } + + + // append arguments + dbus_message_iter_init_append(msg, &args); + dbus_message_iter_open_container( + &args, + DBUS_TYPE_STRUCT, + NULL, + &structIter + ); + + + dui32Temp = in_session_sessionid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timelow; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timemid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_timehiandver; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_session_serviceid_clockseqandnode_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_session_serviceid_clockseqandnode_size > 0 && + in_session_serviceid_clockseqandnode != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_session_opscnt; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_head_next; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_head_prev; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_session_context; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui32Temp = commandid; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + + dui32Temp = in_operation_started; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_paramtypes; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param1_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param1_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param1_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param2_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param2_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param2_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param3_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param3_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param3_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_tmpref_buffer; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_tmpref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_param4_memref_parent; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_parent_flag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_memref_offset; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_a; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_value_b; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_param4_ionref_ionsharefd; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_operation_param4_ionref_ionsize; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui64Temp = in_operation_session; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT64, + &dui64Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + di32Temp = in_operation_cancelflag; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_INT32, + &di32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_returnorigin; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dui32Temp = in_buffer1_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer1_size > 0 && + in_buffer1 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer1, + in_buffer1_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_buffer2_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer2_size > 0 && + in_buffer2 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer2, + in_buffer2_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_buffer3_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer3_size > 0 && + in_buffer3 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer3, + in_buffer3_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dui32Temp = in_buffer4_size; + bResult = + dbus_message_iter_append_basic( + &structIter, + DBUS_TYPE_UINT32, + &dui32Temp + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + if (in_buffer4_size > 0 && + in_buffer4 != NULL) + { + dbus_message_iter_open_container( + &structIter, + DBUS_TYPE_ARRAY, + buf, + &ArrayIter + ); + + bResult = + dbus_message_iter_append_fixed_array( + &ArrayIter, + DBUS_TYPE_UINT32, + &in_buffer4, + in_buffer4_size + ); + if (!bResult) + { + fprintf(stderr, "Out Of Memory!\n"); + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + dbus_message_iter_close_container( + &args, + &structIter + ); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_close_container( + &structIter, + &ArrayIter + ); + } + + dbus_message_iter_close_container( + &args, + &structIter + ); + + /* + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + dbus_connection_flush(conn); + dbus_message_unref(msg); + return -1; + } + + dbus_connection_flush(conn); + dbus_message_unref(msg); + + printf("\n"); + printf("Method Call Teec Invoke Command Sent. \n"); + + ///////////////////////////////////////////////////////////////////////////////////// + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return -1; + } + + // free the pending message handle + dbus_pending_call_unref(pending); + */ + + // printf("\n"); + printf("libdbuscgpw method call teec invoke command sent. \n"); + + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbuscgpw: invokecommand send_with_reply_and_block error, %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + if (reply == NULL) + { + fprintf(stderr, "libdbuscgpw: invokecommand dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return -1; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + dbus_message_iter_recurse( + &args, + &structIter + ); + + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *teecresult = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_sessionid = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timelow = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timemid = dui32Temp; + + + bResult = + dbus_message_iter_next( + &structIter + ); + if (!bResult) + { + fprintf(stderr, "Message has too few arguments!\n"); + dbus_message_unref(msg); + return -1; + } + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_timehiandver = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_serviceid_clockseqandnode_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*session_serviceid_clockseqandnode_outsize > 0) + { + + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &session_serviceid_clockseqandnode_temp, + &session_serviceid_clockseqandnode_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *session_opscnt = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_next = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_head_prev = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *session_context = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_started = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_paramtypes = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param1_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param1_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param1_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param2_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param2_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param2_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param3_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param3_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param3_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_tmpref_buffer = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_tmpref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_param4_memref_parent = dui64Temp; + + bResult = dbus_message_iter_next(&structIter); + iType = dbus_message_iter_get_arg_type(&structIter); + if (iType != DBUS_TYPE_UINT32) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_parent_flag = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_size = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_memref_offset = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_a = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_value_b = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_param4_ionref_ionsharefd = di32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *operation_param4_ionref_ionsize = dui32Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT64 + ) + { + fprintf(stderr, "Argument is not UINT64.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui64Temp + ); + *operation_session = dui64Temp; + + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_INT32 + ) + { + fprintf(stderr, "Argument is not INT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &di32Temp + ); + *operation_cancelflag = di32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *returnorigin = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer1_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*buffer1_outsize > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer1_temp, + &buffer1_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer2_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*buffer2_outsize > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer2_temp, + &buffer2_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer3_outsize = dui32Temp; + bResult = + dbus_message_iter_next( + &structIter + ); + + if (*buffer3_outsize > 0) + { + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer3_temp, + &buffer3_realsize + ); + bResult = + dbus_message_iter_next( + &structIter + ); + } + + iType = + dbus_message_iter_get_arg_type( + &structIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_basic( + &structIter, + &dui32Temp + ); + *buffer4_outsize = dui32Temp; + + if (*buffer4_outsize > 0) + { + bResult = + dbus_message_iter_next( + &structIter + ); + + dbus_message_iter_recurse( + &structIter, + &ArrayIter + ); + + iType = + dbus_message_iter_get_arg_type( + &ArrayIter + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + dbus_message_unref(msg); + return -1; + } + dbus_message_iter_get_fixed_array( + &ArrayIter, + &buffer4_temp, + &buffer4_realsize + ); + } + + + printf("libdbuscgpw got reply of method call teec invoke command: \n"); + printf(" teecresult = 0x %8.8x \n", + *teecresult); + printf(" session_seesionid = 0x %8.8x \n", + *session_sessionid + ); +#if 0 + printf(" TEEC_Session session_serviceid_timelow = 0x %8.8x \n", + *session_serviceid_timelow + ); + printf(" TEEC_Session session_serviceid_timemid = 0x %8.8x \n", + *session_serviceid_timemid + ); + printf(" TEEC_Session session_serviceid_timehiandver = 0x %8.8x \n", + *session_serviceid_timehiandver + ); + printf(" TEEC_Session session_serviceid_clockseqandnode = \n"); + if ( *session_serviceid_clockseqandnode_outsize > 0 && + session_serviceid_clockseqandnode_temp != NULL + ) + { + for (int i = 0; i < session_serviceid_clockseqandnode_realsize; i++) { + printf(" %2.2x", + session_serviceid_clockseqandnode_temp[i] + ); + } + printf("\n"); + } + printf(" TEEC_Session clockseqandnode_outsize = 0x %8.8x \n", + *session_serviceid_clockseqandnode_outsize + ); + printf(" TEEC_Session session_opscnt = 0x %8.8x \n", + *session_opscnt + ); + printf(" TEEC_Session session_head_next = 0x %16.16lx \n", + *session_head_next + ); + printf(" TEEC_Session session_head_prev = 0x %16.16lx \n", + *session_head_prev + ); + printf(" TEEC_Session session_context = 0x %16.16lx \n", + *session_context + ); + printf(" TEEC_Session session_context = 0x %16.16lx \n", + *session_context + ); + printf(" TEEC_Session operation_started = 0x %8.8x \n", + *operation_started + ); + printf(" TEEC_Session operation_paramtypes = 0x %8.8x \n", + *operation_paramtypes + ); + printf(" TEEC_Session operation_param1_tmpref_buffer = 0x %16.16lx \n", + *operation_param1_tmpref_buffer + ); + printf(" TEEC_Session operation_param1_tmpref_size = 0x %8.8x \n", + *operation_param1_tmpref_size + ); + printf(" TEEC_Session operation_param1_memref_parent = 0x %16.16lx \n", + *operation_param1_memref_parent + ); + printf(" TEEC_Session operation_param1_memref_size = 0x %8.8x \n", + *operation_param1_memref_size + ); + printf(" TEEC_Session operation_param1_memref_offse = 0x %8.8x \n", + *operation_param1_memref_offset + ); + printf(" TEEC_Session operation_param1_value_a = 0x %8.8x \n", + *operation_param1_value_a + ); + printf(" TEEC_Session operation_param1_value_b = 0x %8.8x \n", + *operation_param1_value_b + ); + printf(" TEEC_Session operation_param1_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param1_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param1_ionref_ionsize = 0x %8.8x \n", + *operation_param1_ionref_ionsize + ); + + printf(" TEEC_Session operation_param2_tmpref_buffer = 0x %16.16lx \n", + *operation_param2_tmpref_buffer + ); + printf(" TEEC_Session operation_param2_tmpref_size = 0x %8.8x \n", + *operation_param2_tmpref_size + ); + printf(" TEEC_Session operation_param2_memref_parent = 0x %16.16lx \n", + *operation_param2_memref_parent + ); + printf(" TEEC_Session operation_param2_memref_size = 0x %8.8x \n", + *operation_param2_memref_size + ); + printf(" TEEC_Session operation_param2_memref_offset = 0x %8.8x \n", + *operation_param2_memref_offset + ); + printf(" TEEC_Session operation_param2_value_a = 0x %8.8x \n", + *operation_param2_value_a + ); + printf(" TEEC_Session operation_param2_value_b = 0x %8.8x \n", + *operation_param2_value_b + ); + printf(" TEEC_Session operation_param2_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param2_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param2_ionref_ionsize = 0x %8.8x \n", + *operation_param2_ionref_ionsize + ); + + printf(" TEEC_Session operation_param3_tmpref_buffer = 0x %16.16lx \n", + *operation_param3_tmpref_buffer + ); + printf(" TEEC_Session operation_param3_tmpref_size = 0x %8.8x \n", + *operation_param3_tmpref_size + ); + printf(" TEEC_Session operation_param3_memref_parent = 0x %16.16lx \n", + *operation_param3_memref_parent + ); + printf(" TEEC_Session operation_param3_memref_size = 0x %8.8x \n", + *operation_param3_memref_size + ); + printf(" TEEC_Session operation_param3_memref_offset = 0x %8.8x \n", + *operation_param3_memref_offset + ); + printf(" TEEC_Session operation_param3_value_a = 0x %8.8x \n", + *operation_param3_value_a + ); + printf(" TEEC_Session operation_param3_value_b = 0x %8.8x \n", + *operation_param3_value_b + ); + printf(" TEEC_Session operation_param3_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param3_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param3_ionref_ionsize = 0x %8.8x \n", + *operation_param3_ionref_ionsize + ); + + printf(" TEEC_Session operation_param4_tmpref_buffer = 0x %16.16lx \n", + *operation_param4_tmpref_buffer + ); + printf(" TEEC_Session operation_param4_tmpref_size = 0x %8.8x \n", + *operation_param4_tmpref_size + ); + printf(" TEEC_Session operation_param4_memref_parent = 0x %16.16lx \n", + *operation_param4_memref_parent + ); + printf(" TEEC_Session operation_param4_memref_size = 0x %8.8x \n", + *operation_param4_memref_size + ); + printf(" TEEC_Session operation_param4_memref_offset = 0x %8.8x \n", + *operation_param4_memref_offset + ); + printf(" TEEC_Session operation_param4_value_a = 0x %8.8x \n", + *operation_param4_value_a + ); + printf(" TEEC_Session operation_param4_value_b = 0x %8.8x \n", + *operation_param4_value_b + ); + printf(" TEEC_Session operation_param4_ionref_ionsharefd = 0x %8.8x \n", + (unsigned int)*operation_param4_ionref_ionsharefd + ); + printf(" TEEC_Session operation_param4_ionref_ionsize = 0x %8.8x \n", + *operation_param4_ionref_ionsize + ); + + printf(" TEEC_Session operation_session = 0x %16.16lx \n", + *operation_session + ); + printf(" TEEC_Session operation_cancelflag = 0x %8.8x \n", + (unsigned int)*operation_cancelflag + ); + printf(" returnorigin = 0x %8.8x \n", + *returnorigin + ); + + printf(" buffer1 = \n"); + if (buffer1_temp != NULL) + { + for (int i = 0; i < buffer1_realsize; i++) { + printf(" %2.2x", + buffer1_temp[i] + ); + } + printf("\n"); + } + printf(" buffer1_outsize = 0x %8.8x \n", + *buffer1_outsize + ); + + printf(" buffer2 = \n"); + if (buffer2_temp != NULL) + { + for (int i = 0; i < buffer2_realsize; i++) { + printf(" %2.2x", + buffer2_temp[i] + ); + } + printf("\n"); + } + printf(" buffer2_outsize = 0x %8.8x \n", + *buffer2_outsize + ); + + printf(" buffer3 = \n"); + if (buffer3_temp != NULL) + { + for (int i = 0; i < buffer3_realsize; i++) { + printf(" %2.2x", + buffer3_temp[i] + ); + } + printf("\n"); + } + printf(" buffer3_outsize = 0x %8.8x \n", + *buffer3_outsize + ); + + if (buffer4_temp != NULL) + { + printf(" buffer4 = \n"); + for (int i = 0; i < buffer4_realsize; i++) { + printf(" %2.2x", + buffer4_temp[i] + ); + } + printf("\n"); + } + printf(" buffer4_outsize = 0x %8.8x \n", + *buffer4_outsize + ); +#endif + + if (session_serviceid_clockseqandnode_size >= session_serviceid_clockseqandnode_realsize && + session_serviceid_clockseqandnode != NULL && + session_serviceid_clockseqandnode_temp != NULL && + session_serviceid_clockseqandnode_realsize > 0 + ) + { + memcpy( + session_serviceid_clockseqandnode, + session_serviceid_clockseqandnode_temp, + session_serviceid_clockseqandnode_realsize * sizeof(uint32_t) + ); + *session_serviceid_clockseqandnode_outsize = session_serviceid_clockseqandnode_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *session_serviceid_clockseqandnode_outsize = 0; + } + + if (buffer1_size >= (uint32_t) buffer1_realsize && + buffer1 != NULL && + buffer1_temp != NULL && + buffer1_realsize > 0 + ) + { + memcpy( + buffer1, + buffer1_temp, + buffer1_realsize * sizeof(uint32_t) + ); + *buffer1_outsize = buffer1_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer1_outsize = 0; + } + + if (buffer2_size >= (uint32_t) buffer2_realsize && + buffer2 != NULL && + buffer2_temp != NULL && + buffer2_realsize > 0 + ) + { + memcpy( + buffer2, + buffer2_temp, + buffer2_realsize * sizeof(uint32_t) + ); + *buffer2_outsize = buffer2_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer2_outsize = 0; + } + + if (buffer3_size >= (uint32_t) buffer3_realsize && + buffer3 != NULL && + buffer3_temp != NULL && + buffer3_realsize > 0 + ) + { + memcpy( + buffer3, + buffer3_temp, + buffer3_realsize * sizeof(uint32_t) + ); + *buffer3_outsize = buffer3_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer3_outsize = 0; + } + + if (buffer4_size >= (uint32_t) buffer4_realsize && + buffer4 != NULL && + buffer4_temp != NULL && + buffer4_realsize > 0 + ) + { + memcpy( + buffer4, + buffer4_temp, + buffer4_realsize * sizeof(uint32_t) + ); + *buffer4_outsize = buffer4_realsize; + } else + { + // dbus_message_unref(msg); + // return -1; + *buffer4_outsize = 0; + } + + + // free msg + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); + + return 0; +} + + +/** + * Call a method on a remote object + */ +void +method_call_destroy_threadpool( + const char *workername +) +{ + DBusConnection *conn = NULL; + DBusMessage *msg; + DBusMessageIter args; + // DBusConnection* conn; + DBusError err; + DBusPendingCall *pending; + dbus_bool_t bResult; + int ret; + int iType; + unsigned char name[] = "threadpool"; + unsigned char *charp; + dbus_uint32_t retcode; + + // initialiset the errors + dbus_error_init(&err); + + char dbusname[1024]; + if (conn == NULL) + { + // connect to the system bus and check for errors + conn = dbus_bus_get_private(DBUS_BUS_SESSION, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Connection Error (%s)\n", err.message); + dbus_error_free(&err); + } + if (NULL == conn) + { + return; + } + + memset((uint8_t *) dbusname, 0, 1024); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t u64time = (long unsigned int) (tv.tv_sec * 1000000 + tv.tv_usec); + srand(u64time); + sprintf(dbusname, + "%s.method.caller%16.16lx%16.16lx", + workername, + u64time, + (long unsigned int) rand() + ); + // request our name on the bus + ret = + dbus_bus_request_name( + conn, + dbusname, + DBUS_NAME_FLAG_REPLACE_EXISTING, + &err + ); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "Name Error (%s)\n", err.message); + dbus_error_free(&err); + dbus_connection_flush(conn); + } + if (DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER != ret) + { + dbus_connection_flush(conn); + return; + } + } + + // create a new method call and check for errors + char objname[1024]; + char interfacename[1024]; + memset((uint8_t *) dbusname, 0, 1024); + sprintf(dbusname, "%s.method.server", workername); + memset((uint8_t *) objname, 0, 1024); + sprintf(objname, "/%s/method/Object", workername); + memset((uint8_t *) interfacename, 0, 1024); + sprintf(interfacename, "%s.method.Type", workername); + msg = + dbus_message_new_method_call( + // "test.method.server", // target for the method call + dbusname, + // "/test/method/Object", // object to call on + objname, + // "test.method.Type", // interface to call on + interfacename, + "Destroy" // method name + ); + if (NULL == msg) + { + fprintf(stderr, "Message Null\n"); + dbus_connection_flush(conn); + return; + } + + // append arguments + dbus_message_iter_init_append(msg, &args); + + charp = name; + if (!dbus_message_iter_append_basic(&args, DBUS_TYPE_STRING, &charp)) + { + fprintf(stderr, "Out Of Memory!\n"); + return; + } + + /* + // send message and get a handle for a reply + if (!dbus_connection_send_with_reply(conn, msg, &pending, -1)) + { // -1 is default timeout + fprintf(stderr, "Out Of Memory!\n"); + return; + } + if (NULL == pending) + { + fprintf(stderr, "Pending Call Null\n"); + return; + } + dbus_connection_flush(conn); + + printf("\n"); + printf("Method Call Destroy Threadpool Sent. \n"); + + // free message + dbus_message_unref(msg); + + // block until we recieve a reply + dbus_pending_call_block(pending); + + // get the reply message + msg = dbus_pending_call_steal_reply(pending); + if (NULL == msg) + { + fprintf(stderr, "Reply Null\n"); + return; + } + // free the pending message handle + dbus_pending_call_unref(pending); + */ + + // printf("\n"); + printf("libdbuscgpw method call destroygpw sent. \n"); + + DBusMessage *reply; + reply = dbus_connection_send_with_reply_and_block(conn, msg, -1, &err); + if (dbus_error_is_set(&err)) + { + fprintf(stderr, "libdbuscgpw: destroygpw send_with_reply_and_block error, %s \n", err.message); + dbus_error_free(&err); + + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return; + } + if (reply == NULL) + { + fprintf(stderr, "libdbuscgpw: destroygpw dbus reply error \n"); + dbus_message_unref(msg); + dbus_connection_flush(conn); + dbus_connection_close(conn); + dbus_connection_unref(conn); + return; + } + + dbus_message_unref(msg); + dbus_connection_flush(conn); + msg = reply; + + // read the parameters + bResult = + dbus_message_iter_init( + msg, + &args + ); + if (!bResult) + { + fprintf(stderr, "Message has no arguments!\n"); + return; + } + + iType = + dbus_message_iter_get_arg_type( + &args + ); + if ( + iType != DBUS_TYPE_UINT32 + ) + { + fprintf(stderr, "Argument is not UINT32.\n"); + return; + } + dbus_message_iter_get_basic( + &args, + &retcode + ); + + printf("libdbusgpw got reply of method call destroygpw: \n"); + printf(" retcode = 0x%8x \n", retcode); + + // free reply + dbus_message_unref(msg); + + dbus_connection_close(conn); + dbus_connection_unref(conn); +} diff --git a/teeproxy/libdbuscgpw/dbusc_gpw.h b/teeproxy/libdbuscgpw/dbusc_gpw.h new file mode 100644 index 0000000000000000000000000000000000000000..714c08c7309eefce077fa8ec9c2fd038c99ffc4e --- /dev/null +++ b/teeproxy/libdbuscgpw/dbusc_gpw.h @@ -0,0 +1,406 @@ +#ifndef _DBUSC_GPW_H_ +#define _DBUSC_GPW_H_ + +#include +#include + + +void +receive_signal(void); + +void +send_signal( + char *sigvalue +); + +int32_t +method_call_teec_inicont( + const char *workername, + + const uint8_t *name, size_t name_size, + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t *teecresult, + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint64_t *context_addr, + uint32_t *context_tapath_outsize +); + +int32_t +method_call_teec_fincont( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + uint64_t in_context_addr, + + int32_t *context_fd, + uint8_t *context_tapath, size_t context_tapath_insize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + uint32_t *context_tapath_outsize +); + +int32_t +method_call_teec_opensession( + const char *workername, + + int32_t in_context_fd, + const uint8_t *in_context_tapath, + size_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + + uint32_t in_destination_timelow, + uint32_t in_destination_timemid, + uint32_t in_destination_timehiandver, + uint32_t *in_destination_clockseqandnode, + int32_t in_destination_clockseqandnode_size, + uint32_t in_connectionmethod, + uint64_t in_connectiondata, + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint64_t in_context_addr, + + + uint32_t *teecresult, + + int32_t *context_fd, + uint8_t *context_tapath, + size_t context_tapath_size, + uint32_t *context_tapath_outsize, + uint64_t *context_sessionlist_next, + uint64_t *context_sessionlist_prev, + uint64_t *context_shrdmemlist_next, + uint64_t *context_shrdmemlist_prev, + uint64_t *context_sharebuffer_buffer, + int64_t *context_sharebuffer_bufferbarrier, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin +); + +int32_t +method_call_teec_closesession( + const char *workername, + + uint32_t in_session_seesionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + int32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context +); + +int32_t +method_call_teec_invokecommand( + const char *workername, + + uint32_t in_session_seesionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint32_t *in_session_serviceid_clockseqandnode, + uint32_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + + uint32_t commandid, + + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_parent_flag, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_parent_flag, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_parent_flag, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_parent_flag, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + + uint32_t in_returnorigin, + + uint32_t *in_buffer1, + uint32_t in_buffer1_size, + uint32_t *in_buffer2, + uint32_t in_buffer2_size, + uint32_t *in_buffer3, + uint32_t in_buffer3_size, + uint32_t *in_buffer4, + uint32_t in_buffer4_size, + + + uint32_t *teecresult, + + uint32_t *session_seesionid, + uint32_t *session_serviceid_timelow, + uint32_t *session_serviceid_timemid, + uint32_t *session_serviceid_timehiandver, + uint32_t *session_serviceid_clockseqandnode, + int32_t session_serviceid_clockseqandnode_size, + uint32_t *session_serviceid_clockseqandnode_outsize, + uint32_t *session_opscnt, + uint64_t *session_head_next, + uint64_t *session_head_prev, + uint64_t *session_context, + + uint32_t *operation_started, + uint32_t *operation_paramtypes, + + uint64_t *operation_param1_tmpref_buffer, + uint32_t *operation_param1_tmpref_size, + uint64_t *operation_param1_memref_parent, + uint32_t *operation_param1_memref_parent_flag, + uint32_t *operation_param1_memref_size, + uint32_t *operation_param1_memref_offset, + uint32_t *operation_param1_value_a, + uint32_t *operation_param1_value_b, + int32_t *operation_param1_ionref_ionsharefd, + uint32_t *operation_param1_ionref_ionsize, + + uint64_t *operation_param2_tmpref_buffer, + uint32_t *operation_param2_tmpref_size, + uint64_t *operation_param2_memref_parent, + uint32_t *operation_param2_memref_parent_flag, + uint32_t *operation_param2_memref_size, + uint32_t *operation_param2_memref_offset, + uint32_t *operation_param2_value_a, + uint32_t *operation_param2_value_b, + int32_t *operation_param2_ionref_ionsharefd, + uint32_t *operation_param2_ionref_ionsize, + + uint64_t *operation_param3_tmpref_buffer, + uint32_t *operation_param3_tmpref_size, + uint64_t *operation_param3_memref_parent, + uint32_t *operation_param3_memref_parent_flag, + uint32_t *operation_param3_memref_size, + uint32_t *operation_param3_memref_offset, + uint32_t *operation_param3_value_a, + uint32_t *operation_param3_value_b, + int32_t *operation_param3_ionref_ionsharefd, + uint32_t *operation_param3_ionref_ionsize, + + uint64_t *operation_param4_tmpref_buffer, + uint32_t *operation_param4_tmpref_size, + uint64_t *operation_param4_memref_parent, + uint32_t *operation_param4_memref_parent_flag, + uint32_t *operation_param4_memref_size, + uint32_t *operation_param4_memref_offset, + uint32_t *operation_param4_value_a, + uint32_t *operation_param4_value_b, + int32_t *operation_param4_ionref_ionsharefd, + uint32_t *operation_param4_ionref_ionsize, + + uint64_t *operation_session, + int32_t *operation_cancelflag, + + uint32_t *returnorigin, + + uint32_t *buffer1, + uint32_t buffer1_size, + uint32_t *buffer1_outsize, + uint32_t *buffer2, + uint32_t buffer2_size, + uint32_t *buffer2_outsize, + uint32_t *buffer3, + uint32_t buffer3_size, + uint32_t *buffer3_outsize, + uint32_t *buffer4, + uint32_t buffer4_size, + uint32_t *buffer4_outsize +); + +void +method_call_destroy_threadpool( + const char *workername +); + +#endif /* _DBUSC_GPW_H_ */ diff --git a/teeproxy/libteecc/CMakeLists.txt b/teeproxy/libteecc/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..d27d3919aab34012fd2d69bf16dcb5af8a9d5347 --- /dev/null +++ b/teeproxy/libteecc/CMakeLists.txt @@ -0,0 +1,119 @@ +# +# + +cmake_minimum_required(VERSION 3.5.1) + +project(teecc C CXX) + +include(common.cmake) + +# Proto file +get_filename_component(gt_proto "./protos/gt.proto" ABSOLUTE) +get_filename_component(gt_proto_path "${gt_proto}" PATH) +# [[get_filename_component(proto "../protos/${proto_name}.proto" ABSOLUTE) +# get_filename_component(proto_dir "${proto}" DIRECTORY)]] + +# Generated sources +set(gt_proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/gt.pb.cc") +set(gt_proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gt.pb.h") +set(gt_grpc_srcs "${CMAKE_CURRENT_BINARY_DIR}/gt.grpc.pb.cc") +set(gt_grpc_hdrs "${CMAKE_CURRENT_BINARY_DIR}/gt.grpc.pb.h") + +add_custom_command( + OUTPUT "${gt_proto_srcs}" "${gt_proto_hdrs}" "${gt_grpc_srcs}" "${gt_grpc_hdrs}" + COMMAND ${_PROTOBUF_PROTOC} + ARGS --grpc_out "${CMAKE_CURRENT_BINARY_DIR}" + --cpp_out "${CMAKE_CURRENT_BINARY_DIR}" + -I "${gt_proto_path}" + --plugin=protoc-gen-grpc="${_GRPC_CPP_PLUGIN_EXECUTABLE}" + "${gt_proto}" + DEPENDS "${gt_proto}" +) + +# Include generated *.pb.h files +include_directories("${CMAKE_CURRENT_BINARY_DIR}") +include_directories(/usr/include/dbus-1.0/) +include_directories(/usr/lib64/dbus-1.0/include/) +include_directories(${CMAKE_CURRENT_BINARY_DIR}/../include) + +# Introduce variables: +# - CMAKE_INSTALL_LIBDIR +# - CMAKE_INSTALL_BINDIR +# - CMAKE_INSTALL_INCLUDEDIR +include(GNUInstallDirs) + + +set(TEECC_NAME "teecc") +set(LIB_TEECC + ${PROJECT_SOURCE_DIR}/teecc.cc + ${gt_grpc_srcs} + ${gt_proto_srcs} +) +# Install Headers: +set(HEADERS_TEECC + ${PROJECT_SOURCE_DIR}/include/teecc/teec_client_api.h + ${PROJECT_SOURCE_DIR}/include/teecc/tee_client_constants.h + ${PROJECT_SOURCE_DIR}/include/teecc/tee_client_list.h + ${PROJECT_SOURCE_DIR}/include/teecc/tee_client_log.h + ${PROJECT_SOURCE_DIR}/include/teecc/tee_client_type.h +) +install( + FILES ${HEADERS_TEECC} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${TEECC_NAME}/${TARGET_NAME}" +) + + +# gt_grpc_proto +add_library(gt_grpc_proto + ${gt_grpc_srcs} + ${gt_grpc_hdrs} + ${gt_proto_srcs} + ${gt_proto_hdrs} +) +target_link_libraries(gt_grpc_proto + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF} +) + + + +add_library(teecc SHARED + ${LIB_TEECC} +) +target_link_libraries(teecc + gt_grpc_proto + ${_REFLECTION} + ${_GRPC_GRPCPP} + ${_PROTOBUF_LIBPROTOBUF} + yaml-cpp.a +) + +# Install lib +install( + TARGETS "teecc" + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}" +) +# Install config file +set(teecc_config_dir "$ENV{HOME}/.teecc") +# install( +# DIRECTORY +# DESTINATION ${gpp_config_dir}) +install( + FILES "conf/teecc_config.yaml" + DESTINATION ${teecc_config_dir} +) +# Install certs +set(teecc_certs_dir "$ENV{HOME}/.teecc/certs") +install( + FILES + "certs/ca_crt.pem" + "certs/client_key.pem" + "certs/client_crt.pem" + "certs/gen_client_keycsr.sh" + "certs/msg.txt" + "certs/check_ca_crt.sh" + "certs/check_client_key.sh" + "certs/check_client_crt.sh" + DESTINATION ${teecc_certs_dir} +) diff --git a/teeproxy/libteecc/build/cmake.sh b/teeproxy/libteecc/build/cmake.sh new file mode 100644 index 0000000000000000000000000000000000000000..4511f0072874fb7ebcf80b133d708950744f98d0 --- /dev/null +++ b/teeproxy/libteecc/build/cmake.sh @@ -0,0 +1,3 @@ +# cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=$MY_INSTALL_DIR .. +cmake -DCMAKE_BUILD_TYPE=Debug .. + diff --git a/teeproxy/libteecc/certs/ca_crt.pem b/teeproxy/libteecc/certs/ca_crt.pem new file mode 100644 index 0000000000000000000000000000000000000000..c1f851aedaf68806e3d67e41c984d5f1ff2ba96e --- /dev/null +++ b/teeproxy/libteecc/certs/ca_crt.pem @@ -0,0 +1,22 @@ +-----BEGIN CERTIFICATE----- +MIIDozCCAougAwIBAgIUZoRrQX6TrtP0Reyf9DbHVJRNDoQwDQYJKoZIhvcNAQEL +BQAwYTELMAkGA1UEBhMCQ04xDjAMBgNVBAgMBUh1YmVpMQ4wDAYDVQQHDAVXdWhh +bjESMBAGA1UECgwJVHJ1c3RDdXRlMQ0wCwYDVQQLDARnUlBDMQ8wDQYDVQQDDAZj +YS5vcmcwHhcNMjIwODIwMDQ1OTUyWhcNMzIwODE3MDQ1OTUyWjBhMQswCQYDVQQG +EwJDTjEOMAwGA1UECAwFSHViZWkxDjAMBgNVBAcMBVd1aGFuMRIwEAYDVQQKDAlU +cnVzdEN1dGUxDTALBgNVBAsMBGdSUEMxDzANBgNVBAMMBmNhLm9yZzCCASIwDQYJ +KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMYdYD9GChLzSOWmaIcHMqx8itp/7Zvx +7y2qgb23EWCWIz01kPQaCXpuSOi38dFipXFBWo5o3GaezIoSCp66eN3kHGpcluu2 +0nbyh7zdUVCSXhNWbEiwlhC53DDs2SBYWr2KGTRDEcJEXli110v8sEGZQvkj3XGF +B6IbTczMbhpVfJ82RMqGqNYSJ5jCvqw3XOX6xoN4CP3PuAKC6MtEkLLkXQOS72oL +TSE9XoZNqlyhmymAVwQwCV1zT28W/hwKbCN4tVoO+1bwc3togNYO0W7x1GgOoNoZ +va1UNDX1sfW6B041TgSTGQ0OhGzgKWadKHm2UpG2d5NLkaiBUPpvuokCAwEAAaNT +MFEwHQYDVR0OBBYEFKrFU5qoBe2AkvvTiOfwY24T36zTMB8GA1UdIwQYMBaAFKrF +U5qoBe2AkvvTiOfwY24T36zTMA8GA1UdEwEB/wQFMAMBAf8wDQYJKoZIhvcNAQEL +BQADggEBACjfqOa6G596NbFfAAhBFFS+RIueRWdDkBxR7kk+eQ3Z5j4hIBmrA0OS +R6KCrvmvnXxqSBRmuwRfs0e7G76jkUAFFHkslTPLwgklWCarsGXeAkrdgQU7WL4n +NYBNnjUNK11JREUdAXgvzyuLOhjf4l5UvhujWivhviChFB8xpTQfq2d1oE9jsotv +r2opic4ynu69LXd8HZiShabXgQ60/BNOX8D+wb1YzoZlUCKzSH15QRuuEbkj4/Hy +R2+qxUODbuwfqI4fkOvQIIrD2NO89nHpWFtui4ByQEQaeTesus8M8corCekrxr08 +VkxuOGg2U3zWUlLuSZMD2G7KWuDXU78= +-----END CERTIFICATE----- diff --git a/teeproxy/libteecc/certs/check_ca_crt.sh b/teeproxy/libteecc/certs/check_ca_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..83cffa1ecbc4be261b799111ad3b464cd8940322 --- /dev/null +++ b/teeproxy/libteecc/certs/check_ca_crt.sh @@ -0,0 +1,42 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the cert expiry date in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# CACRTPEM=$HOME/.gpp/certs/ca_crt.pem +# REGENCRTSCRIPT=${HOME}/gen_ca_crt.sh +CUR_DIR=$( dirname -- "$0"; ) +CACRTPEM=$CUR_DIR/ca_crt.pem +REGENCRTSCRIPT=${CUR_DIR}/gen_ca_crt.sh + +# 7 days in seconds +DAYS="604800" + +# Email settings +_sub=$CACRTPEM" will expire within $DAYS seconds (7 days)" +# _sub="${CACRTPEM} will expire within $DAYS seconds (7 days)" +_from="system-account@your-dommain" +_to="sysadmin@your-domain" + +echo -e '\n'get date of $CACRTPEM: +openssl x509 -in $CACRTPEM -noout -dates + +echo -e '\n'check expiry of $CACRTPEM: +$_openssl x509 -enddate -noout -in "$CACRTPEM" -checkend "$DAYS" +$_openssl x509 -enddate -noout -in "$CACRTPEM" -checkend "$DAYS" | grep -q 'Certificate will expire' +# If will expire, regenerate key and certifcate +# // , and send email +if [ $? -eq 0 ] +then + echo "${_sub}" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${REGENCRTSCRIPT} +fi diff --git a/teeproxy/libteecc/certs/check_client_crt.sh b/teeproxy/libteecc/certs/check_client_crt.sh new file mode 100644 index 0000000000000000000000000000000000000000..769041a5541580a71f056a5575b489c476135f19 --- /dev/null +++ b/teeproxy/libteecc/certs/check_client_crt.sh @@ -0,0 +1,43 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the cert expiry date in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# CRTPEM=$HOME/.gpp/certs/client_crt.pem +# REGENCRTSCRIPT=${HOME}/gen_client_crt.sh +CUR_DIR=$( dirname -- "$0"; ) +CRTPEM=$CUR_DIR/client_crt.pem +REGENCRTSCRIPT=${CUR_DIR}/gen_client_crt.sh + +# 7 days in seconds +DAYS="604800" + +# Email settings +_sub=$CRTPEM" will expire within $DAYS seconds (7 days)" +# _sub="${CRTPEM} will expire within $DAYS seconds (7 days)" +_from="system-account@your-dommain" +_to="sysadmin@your-domain" + + +echo -e '\n'get date of $CRTPEM: +openssl x509 -in $CRTPEM -noout -dates + +echo -e '\n'check expiry of $CRTPEM: +$_openssl x509 -enddate -noout -in "$CRTPEM" -checkend "$DAYS" +$_openssl x509 -enddate -noout -in "$CRTPEM" -checkend "$DAYS" | grep -q 'Certificate will expire' +# If will expire, regenerate key and certifcate +# // , and send email +if [ $? -eq 0 ] +then + echo "${_sub}" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${REGENCRTSCRIPT} +fi diff --git a/teeproxy/libteecc/certs/check_client_key.sh b/teeproxy/libteecc/certs/check_client_key.sh new file mode 100644 index 0000000000000000000000000000000000000000..c62d32c772e3d7546db67d07b041efc2ddd2e060 --- /dev/null +++ b/teeproxy/libteecc/certs/check_client_key.sh @@ -0,0 +1,62 @@ +#! /bin/sh +# Purpose: Alert sysadmin/developer about the interity of key in advance +# Author: under license +# ------------------------------------------------------------------------------- + + +_openssl="openssl" + + +# KEYPEM=$HOME/.gpp/certs/client_key.pem +# PUBPEM=$HOME/.gpp/certs/client_pubkey.pem +# CRTPEM=$HOME/.gpp/certs/client_crt.pem +# MSGTXT=$HOME/.gpp/certs/msg.txt +# MSGSIG=$HOME/.gpp/certs/msg.sig +# GENKEYCRTSCRIPT=${HOME}/.gpp/certs/gen_client_keycrt.sh +CUR_DIR=$( dirname -- "$0"; ) +KEYPEM=$CUR_DIR/client_key.pem +PUBPEM=$CUR_DIR/client_pubkey.pem +CRTPEM=$CUR_DIR/client_crt.pem +MSGTXT=${CUR_DIR}/msg.txt +MSGSIG=${CUR_DIR}/msg.sig +GENKEYCRTSCRIPT=${CUR_DIR}/gen_client_keycrt.sh + +echo -e '\n'check integrity of ${KEYPEM}: +# ${_openssl} rsa -in ${KEYPEM} -passin pass:111111 -check -noout +# ${_openssl} rsa -in ${KEYPEM} -check -noout +${_openssl} rsa -in ${KEYPEM} -check -noout | grep -q 'RSA key ok' +if [ $? -ne 0 ] +then + echo "the integrity of "${KEYPEM}" is broken" + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +else + echo -e "RSA key ok" +fi + +echo -e '\n'use private ${KEYPEM} to sign ${MSGTXT}: +# ${_openssl} dgst -sha256 -sign ${KEYPEM} -passin pass:111111 -out msg.sig msg.txt +${_openssl} dgst -sha256 -sign ${KEYPEM} -out ${MSGSIG} ${MSGTXT} + +echo -e '\n'get public key from ${CRTPEM}: +${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + +echo -e '\n'use public key in ${CRTPEM} to verify signature of ${MSGTXT}: +# ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} +${_openssl} dgst -sha256 -verify ${PUBPEM} -signature ${MSGSIG} ${MSGTXT} | grep -q 'Verified OK' +if [ $? -ne 0 ] +then + echo ${KEYPEM}" is not matched with "${CRTPEM} + # mail -s "$_sub" -r "$_from" "$_to" <<< "Warning: The certificate ($CACRTPEM) will expire soon on $HOSTNAME [$(date)]" + # See https://www.cyberciti.biz/mobile-devices/android/how-to-push-send-message-to-ios-and-android-from-linux-cli/ # + # source ~/bin/cli_app.sh + # push_to_mobile "$0" "$_sub. See $_to email for detailed log. -- $HOSTNAME " >/dev/null + + # bash ${GENKEYCRTSCRIPT} +fi +rm -f ${PUBPEM} diff --git a/teeproxy/libteecc/certs/client_crt.pem b/teeproxy/libteecc/certs/client_crt.pem new file mode 100644 index 0000000000000000000000000000000000000000..4056b748e5ab3552823bb58ca00ab532d41b838f --- /dev/null +++ b/teeproxy/libteecc/certs/client_crt.pem @@ -0,0 +1,20 @@ +-----BEGIN CERTIFICATE----- +MIIDTzCCAjcCFD3UsYh/aU1yUsNsej6x2MjHaxBOMA0GCSqGSIb3DQEBCwUAMGEx +CzAJBgNVBAYTAkNOMQ4wDAYDVQQIDAVIdWJlaTEOMAwGA1UEBwwFV3VoYW4xEjAQ +BgNVBAoMCVRydXN0Q3V0ZTENMAsGA1UECwwEZ1JQQzEPMA0GA1UEAwwGY2Eub3Jn +MB4XDTIyMDgyMDA1MDYzNVoXDTMyMDgxNzA1MDYzNVowZzELMAkGA1UEBhMCQ04x +DjAMBgNVBAgMBUh1YmVpMQ4wDAYDVQQHDAVXdWhhbjESMBAGA1UECgwJVHJ1c3RD +dXRlMQ0wCwYDVQQLDARnUlBDMRUwEwYDVQQDDAxncGNsaWVudC5vcmcwggEiMA0G +CSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCi8gFUTU1Fd5quFIUvmO/ViRrN416n +EaDyzt1qFfMU7CMyp6vmw5+xb7+z0bsSlucdCtWTHNFBt7ovZuAuUqRHAUm6Of7B +JNCpLY9aaWnhhwfCBO20wQs82djcMhVpWLfWAwUTrdkPubVpC+5pKUM1e7qWkF5Y +72edrtYjBkmhteq5mc3sZyHz4W0BjdO7vnYJ1PSqNvZt+z5krV1KNJ9D+HPC6CjH +syugS7hYSBVSMvGRk/B6VhhjcEV4QABZV7tCt1z9pfV28N7ODFw3kPbZo1rgAd+O +Os0XaUJx/exoVj9Ky93SPyIVh/pNdNtUFaoSx9VGg8osBFawPDEagPD3AgMBAAEw +DQYJKoZIhvcNAQELBQADggEBAIigZPrS0XsUQ38SSCSjMmqRx4bJcAdjkFnmwCAf +NiEjfdreKF67ID/DuXwNUSp0imNnlpb8Zvim4TiSU+YoT6zPr1o9+KTiE0FHK+lE ++FTyNlKthbIC+x0hShFSQFoxjQzPZXQNcSWWHiGbapzjW5VTa807YUp7rmXopvrP +f3gTw6gzuZKUN+FSTv284kEqrPYA4KsuLJgsZz78uaH1RgHnRwqCRmwNdBLI2Mr8 ++G/mVOL/3gmi87mhqXdxWjCnoPQN+3stop8ZaZOPKtkR9e1vbdPfNZhuUTCG45zf +AyhVFCa2ykfFTE7rP10iGLH8Ek7AYOueImH3esVB5KpJSzM= +-----END CERTIFICATE----- diff --git a/teeproxy/libteecc/certs/client_key.pem b/teeproxy/libteecc/certs/client_key.pem new file mode 100644 index 0000000000000000000000000000000000000000..d0a2b54a89b80381f5dffc00909dc9a1e5b51a95 --- /dev/null +++ b/teeproxy/libteecc/certs/client_key.pem @@ -0,0 +1,30 @@ +-----BEGIN RSA PRIVATE KEY----- +Proc-Type: 4,ENCRYPTED +DEK-Info: AES-192-CBC,4C084D8A0A073B8F63DD51AEE7F3EF9F + +mQNTKrxaKmWUhzJxNTW9Q74HZ+e9q+oJ1NqlkM5+qQTdoXo/JAblgSDuAWWRby1Y +RgmoFerqp+MDu8SpOHpWr0msvUgGSZ8tDrcjw4762qEnu/aT+q1FAq7tHM1waOtK +Euse0FFXrN4a0vesjQi3u/N4lrv53cl9fXDfg/eVhn+MncrR6sQo+XzhDPskKKhU +ecMn2cEtfb9ozXkSU3VfmOukM6FeA6zIcEr8QjLIP1n258TJmoxilUdebacZZZoO +N2t1gzTLxXmvUKYBt7CIJOeJhY8edQHByUQGCjzt2ZV3hv1AX+eNGYN5Sod/76aT +VbJhKgSXI4necPSc5l8UWV304gQEqcVk+aCyZJiXBF3Z46Fqw8LOQV0llsAsjiPs +llLbKQay8/NeF9XWRKclMeuDfQnU5qGuBblfM5YjWZqmxkC9MFVYgPrMrIxqXZnV +/ZTiApFvE25HJBlbiBo2JIv1jTWRduedq2XchtyUVUCcJ+U0xutpQ3A862Kygaa3 +IBA61BgpmJyrE7V2obgH+W6dY2D5N8W1PVFGONiCdU2ejXXuzuRT+0+TYfkvZHaR +dIvQwF35hzm4GlpHU73q/ZO5axqkPpyaLb6Y8I2+8JZi7Ns2eWjGRNjvs9kbOd0N +WI5JkjYdTPXDAjxA6pOntD2yx0Da9hgPbRf3HBazHUQg8RUQGRg9+mkJOfK720l0 +8DEUq29CUvYfAcWT+bIcZL+DDoHmLmNRi//+tmC0kRs9goRmm8FmgXSl8mQfAm4K +IYBFOd2KEmKItPklCuGWhzneri4qVAzhI8fODGzyLNaEXJkn2CFavgQRo2LIL26V +hGMiafuvtoQOj3HJg9yf5rinodo8agtxlnN0ZI5Li377b9vHJqLBvNdotpscXZk5 +qTlBeWhznFbK+p/VOESk1Lav2oFO7nxph6pV3gOhgRON2BMRp3LlqBsbLaxiNcp2 +RuQSp8QjBOypldmHn1SmTMXqlTxYI7/nzJrLOzlVGOkPJjDeZ3Kf9mvnXsolxjlS +GrhrBcdypG0bsQZO7PcqXr4p9NSlZZHHZXu78hvWZszoWWNHSUdpqnwnxHAn4AsK +X2Ge1n/XBzYCtXbofhjB7uaUqIdoR3O0CaWxl/MKw89v+64tU90fTzbSqKScmBgZ +oM7MEgdRQ/MmJ1kGb9GLVbJuhLdfwocjzRAFyrMI1jScSKP61qqwBNbxDe1n/zC/ +6OPQYh4g35kLBYR/Aht/9KlZ6Yfu5/bX4VZZ+ZgM3skryJsidafdNLttjVz8Nm5l +aqrJepxmCBuUz1r274gtTewEyjLHGkaoUSJ/Z+Q8P99dJ0mnp3yXghx3FNQCdKzU +gqjLk6tauCith9OEskzoZcOPNiigIaqY5J9JWr0VRscOkKaPHFo4rYK9GFBc+WlP +oaUbpBqxG1aGwida62l5gXJ3s9L7GHdea/7J/QJHu4bqWrBJ+PCwqkjaJdvnpIiI +EdcQXy3wbQJPkP2HdusF/FnC/9aSk4PR+X6gX+owDD/qAKNurss7XP0yHm4PRKI9 +kLa/+8sfFNCsny9KJTRYRV8lWz0sag52c3qUlZSRD/63ghKEI2mZdcouTMabCS4F +-----END RSA PRIVATE KEY----- diff --git a/teeproxy/libteecc/certs/gen_client_keycsr.sh b/teeproxy/libteecc/certs/gen_client_keycsr.sh new file mode 100644 index 0000000000000000000000000000000000000000..cbf8077e1a339c8afc240b47d21c707e032ded0e --- /dev/null +++ b/teeproxy/libteecc/certs/gen_client_keycsr.sh @@ -0,0 +1,22 @@ +#! /bin/sh + +_openssl="openssl" + +CUR_DIR=$( dirname -- "$0"; ) + + +# KEYPEM=$HOME/.teecc/certs/client_key.pem +# CSRPEM=$HOME/.teecc/certs/client_csr.pem +KEYPEM=$CUR_DIR/client_key.pem +CSRPEM=$CUR_DIR/client_csr.pem +RSAKEYLEN=2048 +SUBSTR="/C=CN/ST=Hubei/L=Wuhan/O=TrustCute/OU=gRPC/CN=gpclient.org" + +echo -e '\n'generate $KEYPEM: +# $_openssl genrsa -passout pass:111111 -aes192 -out $KEYPEM ${RSAKEYLEN} +$_openssl genrsa -aes192 -out $KEYPEM ${RSAKEYLEN} + +echo -e '\n'generate certgen request $CSRPEM: +# $_openssl req -passin pass:111111 -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} +$_openssl req -new -key $KEYPEM -out $CSRPEM -subj ${SUBSTR} + diff --git a/teeproxy/libteecc/certs/msg.txt b/teeproxy/libteecc/certs/msg.txt new file mode 100644 index 0000000000000000000000000000000000000000..93388adad70f215f4ec4a71af666d65b30a0cc87 --- /dev/null +++ b/teeproxy/libteecc/certs/msg.txt @@ -0,0 +1 @@ +verify the integrity of a certificate and private key pair diff --git a/teeproxy/libteecc/changelog.md b/teeproxy/libteecc/changelog.md new file mode 100644 index 0000000000000000000000000000000000000000..f66c4e154099ba0dd4245c0a51460aa71a4ad76e --- /dev/null +++ b/teeproxy/libteecc/changelog.md @@ -0,0 +1,7 @@ +# 更新日志 + +## [1.0.0] - 2022-10-11 + +### 新增 + +* 项目初始化,上传第一版 diff --git a/teeproxy/libteecc/common.cmake b/teeproxy/libteecc/common.cmake new file mode 100644 index 0000000000000000000000000000000000000000..62099c51139eed8eed06510d9f76b71dfed36b3a --- /dev/null +++ b/teeproxy/libteecc/common.cmake @@ -0,0 +1,129 @@ +# Copyright 2018 gRPC authors. +# +# Licensed 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. +# +# cmake build file for C++ route_guide example. +# Assumes protobuf and gRPC have been installed using cmake. +# See cmake_externalproject/CMakeLists.txt for all-in-one cmake build +# that automatically builds all the dependencies before building route_guide. + +cmake_minimum_required(VERSION 3.5.1) + +# set (CMAKE_CXX_STANDARD 11) +set (CMAKE_CXX_STANDARD 14) + +set (GRPC_FETCHCONTENT 1) + + +if(MSVC) + add_definitions(-D_WIN32_WINNT=0x600) +endif() + +find_package(Threads REQUIRED) + +if(GRPC_AS_SUBMODULE) + # One way to build a projects that uses gRPC is to just include the + # entire gRPC project tree via "add_subdirectory". + # This approach is very simple to use, but the are some potential + # disadvantages: + # * it includes gRPC's CMakeLists.txt directly into your build script + # without and that can make gRPC's internal setting interfere with your + # own build. + # * depending on what's installed on your system, the contents of submodules + # in gRPC's third_party/* might need to be available (and there might be + # additional prerequisites required to build them). Consider using + # the gRPC_*_PROVIDER options to fine-tune the expected behavior. + # + # A more robust approach to add dependency on gRPC is using + # cmake's ExternalProject_Add (see cmake_externalproject/CMakeLists.txt). + + # Include the gRPC's cmake build (normally grpc source code would live + # in a git submodule called "third_party/grpc", but this example lives in + # the same repository as gRPC sources, so we just look a few directories up) + add_subdirectory(../../.. ${CMAKE_CURRENT_BINARY_DIR}/grpc EXCLUDE_FROM_ALL) + message(STATUS "Using gRPC via add_subdirectory.") + + # After using add_subdirectory, we can now use the grpc targets directly from + # this build. + set(_PROTOBUF_LIBPROTOBUF libprotobuf) + set(_REFLECTION grpc++_reflection) + if(CMAKE_CROSSCOMPILING) + find_program(_PROTOBUF_PROTOC protoc) + else() + set(_PROTOBUF_PROTOC $) + endif() + set(_GRPC_GRPCPP grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +elseif(GRPC_FETCHCONTENT) + # Another way is to use CMake's FetchContent module to clone gRPC at + # configure time. This makes gRPC's source code available to your project, + # similar to a git submodule. + message(STATUS "Using gRPC via add_subdirectory (FetchContent).") + include(FetchContent) + FetchContent_Declare( + grpc + GIT_REPOSITORY https://github.com/grpc/grpc.git + # when using gRPC, you will actually set this to an existing tag, such as + # v1.25.0, v1.26.0 etc.. + # For the purpose of testing, we override the tag used to the commit + # that's currently under test. + # GIT_TAG vGRPC_TAG_VERSION_OF_YOUR_CHOICE + GIT_TAG v1.48.0 + ) + FetchContent_MakeAvailable(grpc) + + # Since FetchContent uses add_subdirectory under the hood, we can use + # the grpc targets directly from this build. + set(_PROTOBUF_LIBPROTOBUF libprotobuf) + set(_REFLECTION grpc++_reflection) + set(_PROTOBUF_PROTOC $) + set(_GRPC_GRPCPP grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +else() + # This branch assumes that gRPC and all its dependencies are already installed + # on this system, so they can be located by find_package(). + + # Find Protobuf installation + # Looks for protobuf-config.cmake file installed by Protobuf's cmake installation. + set(protobuf_MODULE_COMPATIBLE TRUE) + find_package(Protobuf CONFIG REQUIRED) + message(STATUS "Using protobuf ${Protobuf_VERSION}") + + set(_PROTOBUF_LIBPROTOBUF protobuf::libprotobuf) + set(_REFLECTION gRPC::grpc++_reflection) + if(CMAKE_CROSSCOMPILING) + find_program(_PROTOBUF_PROTOC protoc) + else() + set(_PROTOBUF_PROTOC $) + endif() + + # Find gRPC installation + # Looks for gRPCConfig.cmake file installed by gRPC's cmake installation. + find_package(gRPC CONFIG REQUIRED) + message(STATUS "Using gRPC ${gRPC_VERSION}") + + set(_GRPC_GRPCPP gRPC::grpc++) + if(CMAKE_CROSSCOMPILING) + find_program(_GRPC_CPP_PLUGIN_EXECUTABLE grpc_cpp_plugin) + else() + set(_GRPC_CPP_PLUGIN_EXECUTABLE $) + endif() +endif() diff --git a/teeproxy/libteecc/conf/teecc_config.yaml b/teeproxy/libteecc/conf/teecc_config.yaml new file mode 100644 index 0000000000000000000000000000000000000000..a9cfe64acda205f88ca4a491941c840793c092ab --- /dev/null +++ b/teeproxy/libteecc/conf/teecc_config.yaml @@ -0,0 +1,10 @@ +GPPROXY_ADDRESS: "gpserver.org:50051" + +NAME_SERVERCA_CERT: "ca_crt.pem" +NAME_CLIENT_KEY: "client_key.pem" +NAME_CLIENT_CERT: "client_crt.pem" + +# 0, no tls +# 1, only server certificate +# 2, server and client certificates +GRPC_TLS: 1 diff --git a/teeproxy/libteecc/include/teecc/tee_client_api.h b/teeproxy/libteecc/include/teecc/tee_client_api.h new file mode 100644 index 0000000000000000000000000000000000000000..2cdc80a0b7c3e06d393be3dedd630e5d5890475c --- /dev/null +++ b/teeproxy/libteecc/include/teecc/tee_client_api.h @@ -0,0 +1,184 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved. + * iTrustee licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Description: TEE client API definitions + */ + +#ifndef _TEE_CLIENT_API_H_ +#define _TEE_CLIENT_API_H_ + +#ifndef LOG_TAG +#define LOG_TAG NULL +#endif + +#ifdef LOG_NDEBUG +#undef LOG_NDEBUG +#endif +#define LOG_NDEBUG 0 + +#include +#include "tee_client_type.h" +#include "tee_client_log.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define S_VAR_NOT_USED(variable) do { (void)(variable); } while (0) + +#define TEEC_PARAM_TYPES(param0Type, param1Type, param2Type, param3Type) \ + ((param3Type) << 12 | (param2Type) << 8 | (param1Type) << 4 | (param0Type)) + +#define TEEC_PARAM_TYPE_GET(paramTypes, index) \ + (((paramTypes) >> (4*(index))) & 0x0F) + +#define TEEC_VALUE_UNDEF 0xFFFFFFFF + +/* + * initializes a new TEE Context, forming a connection between this Client Application and the TEE + * + * @param name [IN] TEE name (unused) + * @param context [IN/OUT] pointer to TEEC_Context to be initialized + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter + * @return TEEC_ERROR_GENERIC system error unhandled + */ +TEEC_Result TEEC_InitializeContext( + const char *name, + TEEC_Context *context); + +/* + * finalizes an initialized TEE Context, closing the connection between the Client Application and the TEE + * + * @param context [IN/OUT] pointer to TEEC_Context initialized by TEEC_InitializeContext + * + * @return void + */ +void TEEC_FinalizeContext( + TEEC_Context *context); + +/* + * opens a new Session between the Client Application and the specified Trusted Application + * + * @param context [IN/OUT] a pointer to an initialized TEE Context + * @param session [OUT] a pointer to a Session structure to be opened + * @param destination [IN] a pointer to a structure containing the UUID of the destination Trusted Application + * @param connectionMethod [IN] the method of connection to use + * @param connectionData [IN] any necessary data required to support the connection method + * @param operation [IN/OUT] a pointer to an Operation containing a set of Parameters to exchange with the + * Trusted Application + * @param returnOrigin [IN/OUT] a pointer to a variable which will contain the return origin, This field may be NULL + * if the return origin is not needed + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parametercontext or session or destination is NULL + * @return TEEC_ERROR_ACCESS_DENIED client Application's connection request is denied + * @return TEEC_ERROR_OUT_OF_MEMORY system resource is out of use + * @return TEEC_ERROR_TRUSTED_APP_LOAD_ERROR load Trusted Application failed + * @return others refer TEEC_ReturnCode + */ +TEEC_Result TEEC_OpenSession( + TEEC_Context *context, + TEEC_Session *session, + const TEEC_UUID *destination, + uint32_t connectionMethod, + const void *connectionData, + TEEC_Operation *operation, + uint32_t *returnOrigin); + +/* + * closes a Session which has been opened with a Trusted Application + * + * @param session [IN/OUT] pointer to a session to be closed + * + * @return void + */ +void TEEC_CloseSession( + TEEC_Session *session); + +/* + * invokes a Command within the specified Session + * + * @param session [IN/OUT] the open Session in which the command will be invoked + * @param commandID [IN] the identifier of the Command within the Trusted Application to invoke + * @param operation [IN/OUT] a pointer to a Client Application initialized TEEC_Operation structure + * @param returnOrigin [IN/OUT] a pointer to a variable which will contain the return origin + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parametersession is NULL or operation data invalid + * @return TEEC_ERROR_ACCESS_DENIED invoke command operation is denied + * @return TEEC_ERROR_OUT_OF_MEMORY system resource is out of use + * @return others refer TEEC_ReturnCode + */ +TEEC_Result TEEC_InvokeCommand( + TEEC_Session *session, + uint32_t commandID, + TEEC_Operation *operation, + uint32_t *returnOrigin); + +/* + * registers a block of existing Client Application memory as a block of Shared Memory within + * the scope of the specified TEE Context, in accordance with the parameters which have been set by the + * Client Application inside the sharedMem structure (don't support 0 size data) + * + * @param context [IN/OUT] a pointer to an initialized TEE Context + * @param sharedMem [IN/OUT] a pointer to a Shared Memory structure to register + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter, context or sharedMem is NULL + */ +TEEC_Result TEEC_RegisterSharedMemory( + TEEC_Context *context, + TEEC_SharedMemory *sharedMem); + +/* + * allocates a new block of memory as a block of Shared Memory within the scope of the specified TEE Context + * size of sharedMem should not be 0 + * + * @param context [IN/OUT] a pointer to an initialized TEE Context + * @param sharedMem [IN/OUT] a pointer to a Shared Memory structure to allocate + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter, context or sharedMem is NULL + * @return TEEC_ERROR_OUT_OF_MEMORY system resource is out of use + */ +TEEC_Result TEEC_AllocateSharedMemory( + TEEC_Context *context, + TEEC_SharedMemory *sharedMem); + +/* + * deregisters or deallocates a previously initialized block of Shared Memory + * if memory is allocated by TEEC_AllocateSharedMemory, system will free this memory + * if memory is registered by TEEC_RegisterSharedMemory, system will not free this memory + * + * @param sharedMem [IN/OUT] a pointer to a valid Shared Memory structure + * + * @return void + */ +void TEEC_ReleaseSharedMemory( + TEEC_SharedMemory *sharedMem); + +/* + * requests the cancellation of a pending open Session operation or a Command invocation operation + * this operation is not supported currently + * + * @param operation [IN/OUT] a pointer to a Client Application instantiated Operation structure + * + * @return void + */ +void TEEC_RequestCancellation( + TEEC_Operation *operation); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/teeproxy/libteecc/include/teecc/tee_client_constants.h b/teeproxy/libteecc/include/teecc/tee_client_constants.h new file mode 100644 index 0000000000000000000000000000000000000000..eb31c89c943ea9fbd2847827d3689695e72cc7ad --- /dev/null +++ b/teeproxy/libteecc/include/teecc/tee_client_constants.h @@ -0,0 +1,165 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved. + * iTrustee licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Description: static definitions of client API + */ + +#ifndef _TEE_CLIENT_CONSTANTS_H_ +#define _TEE_CLIENT_CONSTANTS_H_ + +enum TEEC_ReturnCode { + TEEC_SUCCESS = 0x0, /* success */ + TEEC_ERROR_INVALID_CMD, /* invalid command */ + TEEC_ERROR_SERVICE_NOT_EXIST, /* target service is not exist */ + TEEC_ERROR_SESSION_NOT_EXIST, /* session between client and service is not exist */ + TEEC_ERROR_SESSION_MAXIMUM, /* exceed max num of sessions */ + TEEC_ERROR_REGISTER_EXIST_SERVICE, /* cannot register the service which already exist */ + TEEC_ERROR_TAGET_DEAD_FATAL, /* system error occurs in TEE */ + TEEC_ERROR_READ_DATA, /* failed to read data in file */ + TEEC_ERROR_WRITE_DATA, /* failed to write data to file */ + TEEC_ERROR_TRUNCATE_OBJECT, /* data is truncated */ + TEEC_ERROR_SEEK_DATA, /* failed to seek data in file */ + TEEC_ERROR_FSYNC_DATA, /* failed to sync data in file */ + TEEC_ERROR_RENAME_OBJECT, /* failed to rename file */ + TEEC_ERROR_TRUSTED_APP_LOAD_ERROR, /* failed to load Trusted Application */ + TEEC_ERROR_GENERIC = 0xFFFF0000, /* generic error occurs */ + TEEC_ERROR_ACCESS_DENIED = 0xFFFF0001, /* permission check failed, in initilize context or + open session or invoke commnad */ + TEEC_ERROR_CANCEL = 0xFFFF0002, /* operation is already canceled */ + TEEC_ERROR_ACCESS_CONFLICT = 0xFFFF0003, /* confilct occurs in concurrent access to data, + error occurs in file operaions generally */ + TEEC_ERROR_EXCESS_DATA = 0xFFFF0004, /* exceed max data to be handled by system */ + TEEC_ERROR_BAD_FORMAT = 0xFFFF0005, /* data format is invalid, Trusted Application cannot + handle it */ + TEEC_ERROR_BAD_PARAMETERS = 0xFFFF0006, /* invalid parameters */ + TEEC_ERROR_BAD_STATE = 0xFFFF0007, /* operation failed in current state, when try to access + storage without initilize storage service */ + TEEC_ERROR_ITEM_NOT_FOUND = 0xFFFF0008, /* cannot find target item */ + TEEC_ERROR_NOT_IMPLEMENTED = 0xFFFF0009, /* request operation is not implemented */ + TEEC_ERROR_NOT_SUPPORTED = 0xFFFF000A, /* request operation is not supported */ + TEEC_ERROR_NO_DATA = 0xFFFF000B, /* no data present for current operation */ + TEEC_ERROR_OUT_OF_MEMORY = 0xFFFF000C, /* system resource if out of use */ + TEEC_ERROR_BUSY = 0xFFFF000D, /* system is too busy to handle current operation */ + TEEC_ERROR_COMMUNICATION = 0xFFFF000E, /* error occurs when client try to communicate + with Trusted Application */ + TEEC_ERROR_SECURITY = 0xFFFF000F, /* security error occurs */ + TEEC_ERROR_SHORT_BUFFER = 0xFFFF0010, /* out buffer is not enough for current request */ + TEEC_ERROR_MAC_INVALID = 0xFFFF3071, /* MAC value check failed */ + TEEC_ERROR_TARGET_DEAD = 0xFFFF3024, /* Trusted Application is crashed */ + TEEC_FAIL = 0xFFFF5002, /* common error */ + TEEC_ERROR_EXTERNAL_CANCEL = 0xFFFF0011, /* used by adapt only, event caused User Interface operation aborted */ + TEEC_ERROR_OVERFLOW = 0xFFFF300F, /* used by adapt only */ + TEEC_ERROR_STORAGE_NO_SPACE = 0xFFFF3041, /* used by adapt only */ + TEEC_ERROR_SIGNATURE_INVALID = 0xFFFF3072, /* used by adapt only */ + TEEC_ERROR_TIME_NOT_SET = 0xFFFF5000, /* used by adapt only */ + TEEC_ERROR_TIME_NEEDS_RESET = 0xFFFF5001, /* used by adapt only */ + + TEEC_ERROR_CONTEXT_NULL = 0xAAAA0001, /* null context */ + TEEC_ERROR_CONTEXT_TAPATH_NULL = 0xAAAA0002, /* null context ta path */ + TEEC_ERROR_PARAM0_TEMPMEM_NULL = 0xAAAA0003, /* null param0 tempmem buf */ + TEEC_ERROR_PARAM0_TEMPMEM_LESS = 0xAAAA0004, /* param0 tempmem buf is less */ + TEEC_ERROR_PARAM1_TEMPMEM_NULL = 0xAAAA0005, /* null param1 tempmem buf */ + TEEC_ERROR_PARAM1_TEMPMEM_LESS = 0xAAAA0006, /* param1 tempmem buf is less */ + TEEC_ERROR_PARAM2_TEMPMEM_NULL = 0xAAAA0007, /* null param2 tempmem buf */ + TEEC_ERROR_PARAM2_TEMPMEM_LESS = 0xAAAA0008, /* param2 tempmem buf is less */ + TEEC_ERROR_PARAM3_TEMPMEM_NULL = 0xAAAA0009, /* null param3 tempmem buf */ + TEEC_ERROR_PARAM3_TEMPMEM_LESS = 0xAAAA000A, /* param3 tempmem buf is less */ + TEEC_ERROR_CONTEXT_LIST_NULL = 0xAAAA000B, /* null context list in woker */ + TEEC_ERROR_NO_CONTEXT_MATCH = 0xAAAA000C, /* no context match in woker */ + TEEC_ERROR_SESSION_LIST_NULL = 0xAAAA000D, /* null session list in woker */ + TEEC_ERROR_NO_SESSION_MATCH = 0xAAAA000E, /* no session match in woker */ + TEEC_ERROR_PARAM0_MEMREF_NULL = 0xAAAA000F, /* null param0 memref buf */ + TEEC_ERROR_PARAM0_MEMREF_LESS = 0xAAAA0010, /* param0 memref buf is less */ + TEEC_ERROR_PARAM1_MEMREF_NULL = 0xAAAA0011, /* null param1 memref buf */ + TEEC_ERROR_PARAM1_MEMREF_LESS = 0xAAAA0012, /* param1 memref buf is less */ + TEEC_ERROR_PARAM2_MEMREF_NULL = 0xAAAA0013, /* null param2 memref buf */ + TEEC_ERROR_PARAM2_MEMREF_LESS = 0xAAAA0014, /* param2 memref buf is less */ + TEEC_ERROR_PARAM3_MEMREF_NULL = 0xAAAA0015, /* null param3 memref buf */ + TEEC_ERROR_PARAM3_MEMREF_LESS = 0xAAAA0016, /* param3 memref buf is less */ + TEEC_ERROR_NO_WORKER_MATCHED = 0xAAAA0017, /* No woker mateched with the context or/and session */ + TEEC_ERROR_SESSION_NULL = 0xAAAA0018, /* null session */ + TEEC_ERROR_NO_SHAREMEMFLAG = 0xAAAA0019, /* no share memmory flag */ + + TEEC_ERROR_JWTVALIDATE_FAIL = 0xAAAA0020, /* jwt validate fail */ + TEEC_ERROR_GRPC_ERROR = 0xAAAA0021, /* grpc transmission error */ + TEEC_ERROR_DBUS_CONN_NULL = 0xAAAA0022, /* dbus connection null */ + TEEC_ERROR_DBUS_NAME_ERROR = 0xAAAA0023, /* dbus name set is error */ + TEEC_ERROR_DBUS_MSG_NULL = 0xAAAA0024, /* dbus message is null */ + TEEC_ERROR_DBUS_APPEND_ERROR = 0xAAAA0025, /* dbus append argument error */ + TEEC_ERROR_DBUS_REPLY_ERROR = 0xAAAA0026, /* dbus send with reply error */ + TEEC_ERROR_DBUS_ARG_NULL = 0xAAAA0027, /* dbus argument is null */ + TEEC_ERROR_DBUS_ARG_TYPE_ERROR = 0xAAAA0028, /* dbus argument type error */ + TEEC_ERROR_TOKEN_NULL = 0xAAAA0029, /* fetch token is null */ + TEEC_ERROR_TOKEN_SIZE_ERROR = 0xAAAA0030, /* token size is error */ + TEEC_ERROR_FETCHJWT_ERROR = 0xAAAA0031, /* fetch jwt error */ + TEEC_INFILE_PATH_NULL = 0xAAAA0032, /* deployta infile path is null*/ + TEEC_INFILE_NOT_FOUND = 0xAAAA0033 /* deployta infile is not found*/ +}; + +enum TEEC_ReturnCodeOrigin { + TEEC_ORIGIN_API = 0x1, /* error occurs in handling client API */ + TEEC_ORIGIN_COMMS = 0x2, /* error occurs in communicating between REE and TEE */ + TEEC_ORIGIN_TEE = 0x3, /* error occurs in TEE */ + TEEC_ORIGIN_TRUSTED_APP = 0x4, /* error occurs in Trusted Application */ +}; + +enum TEEC_SharedMemCtl { + TEEC_MEM_INPUT = 0x1, /* input type of memroy */ + TEEC_MEM_OUTPUT = 0x2, /* output type of memory */ + TEEC_MEM_INOUT = 0x3, /* memory is used as both input and output */ +}; + +enum TEEC_ParamType { + TEEC_NONE = 0x0, /* unused parameter */ + TEEC_VALUE_INPUT = 0x01, /* input type of value, refer TEEC_Value */ + TEEC_VALUE_OUTPUT = 0x02, /* output type of value, refer TEEC_Value */ + TEEC_VALUE_INOUT = 0x03, /* value is used as both input and output, refer TEEC_Value */ + TEEC_MEMREF_TEMP_INPUT = 0x05, /* input type of temp memory reference, refer TEEC_TempMemoryReference */ + TEEC_MEMREF_TEMP_OUTPUT = 0x06, /* output type of temp memory reference, refer TEEC_TempMemoryReference */ + TEEC_MEMREF_TEMP_INOUT = 0x07, /* temp memory reference used as both input and output, + refer TEEC_TempMemoryReference */ + TEEC_ION_INPUT = 0x08, /* input type of icon memory reference, refer TEEC_IonReference */ + TEEC_ION_SGLIST_INPUT = 0x09, /* input type of ion memory block reference, refer TEEC_IonSglistReference */ + TEEC_MEMREF_WHOLE = 0xc, /* use whole memory block, refer TEEC_RegisteredMemoryReference */ + TEEC_MEMREF_PARTIAL_INPUT = 0xd, /* input type of memory reference, refer TEEC_RegisteredMemoryReference */ + TEEC_MEMREF_PARTIAL_OUTPUT = 0xe, /* output type of memory reference, refer TEEC_RegisteredMemoryReference */ + TEEC_MEMREF_PARTIAL_INOUT = 0xf /* memory reference used as both input and output, + refer TEEC_RegisteredMemoryReference */ +}; + +/**************************************************** + * Session Login Methods + ****************************************************/ +enum TEEC_LoginMethod { + TEEC_LOGIN_PUBLIC = 0x0, /* no Login data is provided */ + TEEC_LOGIN_USER, /* Login data about the user running the + Client Application process is provided */ + TEEC_LOGIN_GROUP, /* Login data about the group running + the Client Application process is provided */ + TEEC_LOGIN_APPLICATION = 0x4, /* Login data about the running Client + Application itself is provided */ + TEEC_LOGIN_USER_APPLICATION = 0x5, /* Login data about the user running the + Client Application and about the + Client Application itself is provided */ + TEEC_LOGIN_GROUP_APPLICATION = 0x6, /* Login data about the group running + the Client Application and about the + Client Application itself is provided */ + TEEC_LOGIN_IDENTIFY = 0x7, /* Login data is provided by REE system */ +}; +enum TST_CMD_ID { + TST_CMD_ID_01 = 1, + TST_CMD_ID_02, + TST_CMD_ID_03, + TST_CMD_ID_04, + TST_CMD_ID_05 +}; + +#define TEEC_PARAM_NUM 4 /* teec param max number */ +#endif diff --git a/teeproxy/libteecc/include/teecc/tee_client_list.h b/teeproxy/libteecc/include/teecc/tee_client_list.h new file mode 100644 index 0000000000000000000000000000000000000000..03e295fdea6a10b6f5e4904de887c227c1afd681 --- /dev/null +++ b/teeproxy/libteecc/include/teecc/tee_client_list.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved. + * iTrustee licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Description: linked list data types and basic operations + */ + +#ifndef TEE_CLIENT_LIST_H +#define TEE_CLIENT_LIST_H + +struct ListNode { + struct ListNode *next; /* point to next node */ + struct ListNode *prev; /* point to prev node */ +}; + +#define OFFSET_OF(type, member) (unsigned long)(&(((type *)0)->member)) +#define CONTAINER_OF(pos, type, member) (type *)(((char *)(pos)) - OFFSET_OF(type, member)) + +#define LIST_DECLARE(name) \ + struct ListNode name = { \ + .next = &name, \ + .prev = &name, \ + } + +static inline void ListInit(struct ListNode *list) +{ + list->next = list; + list->prev = list; +} + +#define LIST_HEAD(list) ((list)->next) +#define LIST_TAIL(list) ((list)->prev) +#define LIST_EMPTY(list) ((list) == (list)->next) + +static inline void ListInsertHead(struct ListNode *list, struct ListNode *entry) +{ + list->next->prev = entry; + entry->next = list->next; + entry->prev = list; + list->next = entry; +} + +static inline void ListInsertTail(struct ListNode *list, struct ListNode *entry) +{ + entry->next = list; + entry->prev = list->prev; + list->prev->next = entry; + list->prev = entry; +} + +static inline void ListRemoveEntry(struct ListNode *entry) +{ + entry->prev->next = entry->next; + entry->next->prev = entry->prev; +} + +static inline struct ListNode *ListRemoveHead(struct ListNode *list) +{ + struct ListNode *entry = NULL; + if (!LIST_EMPTY(list)) { + entry = list->next; + ListRemoveEntry(entry); + } + return entry; +} + +static inline struct ListNode *ListRemoveTail(struct ListNode *list) +{ + struct ListNode *entry = NULL; + if (!LIST_EMPTY(list)) { + entry = list->prev; + ListRemoveEntry(entry); + } + return entry; +} + +#define LIST_ENTRY(ptr, type, member) \ + ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) + +#define LIST_FOR_EACH(pos, list) \ + for (pos = (list)->next; pos != (list); pos = pos->next) + +#define LIST_FOR_EACH_SAFE(pos, n, list) \ + for ((pos) = (list)->next, (n) = (pos)->next; (pos) != (list); (pos) = (n), (n) = (pos)->next) + +#define LIST_FOR_EACH_ENTRY(pos, list, member) \ + for (pos = LIST_ENTRY((list)->next, typeof(*pos), member); &pos->member != (list); \ + pos = LIST_ENTRY(pos->member.next, typeof(*pos), member)) + +#define LIST_FOR_EACH_ENTRY_SAFE(pos, n, list, member) \ + for (pos = LIST_ENTRY((list)->next, typeof(*pos), member), n = LIST_ENTRY(pos->member.next, typeof(*pos), \ + member); &pos->member != (list); pos = n, n = LIST_ENTRY(n->member.next, typeof(*n), member)) + +#endif diff --git a/teeproxy/libteecc/include/teecc/tee_client_log.h b/teeproxy/libteecc/include/teecc/tee_client_log.h new file mode 100644 index 0000000000000000000000000000000000000000..9ba1fdada17ba4007e16c5cee30b0304f045ed8b --- /dev/null +++ b/teeproxy/libteecc/include/teecc/tee_client_log.h @@ -0,0 +1,29 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved. + * iTrustee licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Description: TEE client log api + */ + +#ifndef TEE_CLIENT_LOG_H +#define TEE_CLIENT_LOG_H + +#include + +// #define TEEC_DEBUG + +#ifdef TEEC_DEBUG +#define TEEC_Debug(...) syslog(LOG_USER | LOG_INFO, __VA_ARGS__); +#else +#define TEEC_Debug(...) +#endif + +#define TEEC_Error(...) syslog(LOG_USER | LOG_INFO, __VA_ARGS__); + +#endif diff --git a/teeproxy/libteecc/include/teecc/tee_client_type.h b/teeproxy/libteecc/include/teecc/tee_client_type.h new file mode 100644 index 0000000000000000000000000000000000000000..f5906159b7025f3fbc010341a4cc978584e48fbf --- /dev/null +++ b/teeproxy/libteecc/include/teecc/tee_client_type.h @@ -0,0 +1,150 @@ +/* + * Copyright (c) Huawei Technologies Co., Ltd. 2013-2020. All rights reserved. + * iTrustee licensed under the Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR + * PURPOSE. + * See the Mulan PSL v2 for more details. + * Description: data type and structure definition according to GP + */ + +#ifndef _TEE_CLIENT_TYPE_H_ +#define _TEE_CLIENT_TYPE_H_ + +#include +#include +#include +#include +#include "tee_client_list.h" +#include "tee_client_constants.h" + +#ifndef __cplusplus +#ifndef bool +#define bool uint8_t +#endif +#endif + +#ifndef true +#define true 1 +#endif + +#ifndef false +#define false 0 +#endif + +#ifndef NULL +#define NULL 0 +#endif + +typedef enum TEEC_ReturnCode TEEC_Result; + +typedef struct { + uint32_t timeLow; + uint16_t timeMid; + uint16_t timeHiAndVersion; + uint8_t clockSeqAndNode[8]; +} TEEC_UUID; + +typedef struct { + int32_t fd; + uint8_t *ta_path; + struct ListNode session_list; + struct ListNode shrd_mem_list; + union { + struct { + void *buffer; + sem_t buffer_barrier; + } share_buffer; + uint64_t imp; /* for adapt */ + }; +} TEEC_Context; + +typedef struct { + uint32_t session_id; + TEEC_UUID service_id; + uint32_t ops_cnt; + union { + struct ListNode head; + uint64_t imp; /* for adapt */ + }; + TEEC_Context *context; +} TEEC_Session; + +typedef struct { + void *buffer; + uint32_t size; + uint32_t flags; /* reference to TEEC_SharedMemCtl */ + uint32_t ops_cnt; + bool is_allocated; /* identify whether the memory is registered or allocated */ + union { + struct ListNode head; + void* imp; /* for adapt, imp is not used by system CA, only for vendor CA */ + }; + TEEC_Context *context; +} TEEC_SharedMemory; + +/* + * the corresponding param types are + * TEEC_MEMREF_TEMP_INPUT/TEEC_MEMREF_TEMP_OUTPUT/TEEC_MEMREF_TEMP_INOUT + */ +typedef struct { + void *buffer; + uint32_t size; +} TEEC_TempMemoryReference; + +/* + * the corresponding param types are + * TEEC_MEMREF_WHOLE/TEEC_MEMREF_PARTIAL_INPUT + * TEEC_MEMREF_PARTIAL_OUTPUT/TEEC_MEMREF_PARTIAL_INOUT + */ +typedef struct { + TEEC_SharedMemory *parent; + uint32_t size; + uint32_t offset; +} TEEC_RegisteredMemoryReference; + +/* + * the corresponding param types are + * TEEC_VALUE_INPUT/TEEC_VALUE_OUTPUT/TEEC_VALUE_INOUT + */ +typedef struct { + uint32_t a; + uint32_t b; +} TEEC_Value; + +typedef struct { + int ion_share_fd; + uint32_t ion_size; +} TEEC_IonReference; + +typedef union { + TEEC_TempMemoryReference tmpref; + TEEC_RegisteredMemoryReference memref; + TEEC_Value value; + TEEC_IonReference ionref; +} TEEC_Parameter; + +typedef struct { + uint32_t event_type; /* Tui event type */ + uint32_t value; /* return value, is keycode if tui event is getKeycode */ + uint32_t notch; /* notch size of the screen for tui */ + uint32_t width; /* width of foldable screen */ + uint32_t height; /* height of foldable screen */ + uint32_t fold_state; /* state of foldable screen */ + uint32_t display_state; /* one state of folded state */ + uint32_t phy_width; /* real width of the mobile */ + uint32_t phy_height; /* real height of the mobile */ +} TEEC_TUI_Parameter; + +typedef struct { + uint32_t started; /* 0 means cancel this operation, others mean to perform this operation */ + uint32_t paramTypes; /* use TEEC_PARAM_TYPES to construct this value */ + TEEC_Parameter params[TEEC_PARAM_NUM]; + TEEC_Session *session; + bool cancel_flag; +} TEEC_Operation; + +#endif diff --git a/teeproxy/libteecc/include/teecc/teec_client_api.h b/teeproxy/libteecc/include/teecc/teec_client_api.h new file mode 100644 index 0000000000000000000000000000000000000000..996b5e784264f3cfeef7b99d823e59d504438b70 --- /dev/null +++ b/teeproxy/libteecc/include/teecc/teec_client_api.h @@ -0,0 +1,192 @@ +#ifndef teec_client_api_h__ +#define teec_client_api_h__ + +#include "tee_client_type.h" +#include "tee_client_log.h" + + +#define TEEC_PARAM_TYPES(param0Type, param1Type, param2Type, param3Type) \ + ((param3Type) << 12 | (param2Type) << 8 | (param1Type) << 4 | (param0Type)) + +#define TEEC_PARAM_TYPE_GET(paramTypes, index) \ + (((paramTypes) >> (4*(index))) & 0x0F) + +#ifdef __cplusplus +extern "C"{ +#endif + +/* + * initializes a new TEE Context, forming a connection between this Client Application and the TEE + * + * @param name [IN] TEE name (unused) + * @param context [IN/OUT] pointer to TEEC_Context to be initialized + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter + * @return TEEC_ERROR_GENERIC system error unhandled + */ +extern TEEC_Result +TEEC_InitializeContext( + const char *name, + TEEC_Context *context); + + +/* + * finalizes an initialized TEE Context, closing the connection between the Client Application and the TEE + * + * @param context [IN/OUT] pointer to TEEC_Context initialized by TEEC_InitializeContext + * @param context_addr [IN] the context address in gp woker process + * + * @return void + */ +extern void +TEEC_FinalizeContext( + TEEC_Context *context); + + +/* + * opens a new Session between the Client Application and the specified Trusted Application + * + * @param context [IN/OUT] a pointer to an initialized TEE Context + * @param context_addr [IN] the context address in gp woker process + * @param session [OUT] a pointer to a Session structure to be opened + * @param destination [IN] a pointer to a structure containing the UUID of the destination Trusted Application + * @param connectionMethod [IN] the method of connection to use + * @param connectionData [IN] any necessary data required to support the connection method + * @param operation [IN/OUT] a pointer to an Operation containing a set of Parameters to exchange with the + * Trusted Application + * @param returnOrigin [IN/OUT] a pointer to a variable which will contain the return origin, This field may be NULL + * if the return origin is not needed + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter£¬context or session or destination is NULL + * @return TEEC_ERROR_ACCESS_DENIED client Application's connection request is denied + * @return TEEC_ERROR_OUT_OF_MEMORY system resource is out of use + * @return TEEC_ERROR_TRUSTED_APP_LOAD_ERROR load Trusted Application failed + * @return others refer TEEC_ReturnCode + */ +extern TEEC_Result +TEEC_OpenSession( + TEEC_Context *context, + TEEC_Session *session, + const TEEC_UUID *destination, + uint32_t connectionMethod, + const void *connectionData, + TEEC_Operation *operation, + uint32_t *returnOrigin); + + +/* + * closes a Session which has been opened with a Trusted Application + * + * @param session [IN/OUT] pointer to a session to be closed + * + * @return void + */ +extern void +TEEC_CloseSession( + TEEC_Session *session); + + +/* + * invokes a Command within the specified Session + * + * @param session [IN/OUT] the open Session in which the command will be invoked + * @param commandID [IN] the identifier of the Command within the Trusted Application to invoke + * @param operation [IN/OUT] a pointer to a Client Application initialized TEEC_Operation structure + * @param returnOrigin [IN/OUT] a pointer to a variable which will contain the return origin + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter£¬session is NULL or operation data invalid + * @return TEEC_ERROR_ACCESS_DENIED invoke command operation is denied + * @return TEEC_ERROR_OUT_OF_MEMORY system resource is out of use + * @return others refer TEEC_ReturnCode + */ +extern TEEC_Result +TEEC_InvokeCommand( + TEEC_Session *session, + uint32_t commandID, + TEEC_Operation *operation, + uint32_t *returnOrigin); + + +/* + * allocates a new block of memory as a block of Shared Memory within the scope of the specified TEE Context + * size of sharedMem should not be 0 + * + * @param context [IN/OUT] a pointer to an initialized TEE Context + * @param sharedMem [IN/OUT] a pointer to a Shared Memory structure to allocate + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter, context or sharedMem is NULL + * @return TEEC_ERROR_OUT_OF_MEMORY system resource is out of use + */ +TEEC_Result TEEC_AllocateSharedMemory( + TEEC_Context *context, + TEEC_SharedMemory *sharedMem); + + +/* + * registers a block of existing Client Application memory as a block of Shared Memory within + * the scope of the specified TEE Context, in accordance with the parameters which have been set by the + * Client Application inside the sharedMem structure (don't support 0 size data) + * + * @param context [IN/OUT] a pointer to an initialized TEE Context + * @param sharedMem [IN/OUT] a pointer to a Shared Memory structure to register + * + * @return TEEC_SUCCESS operation success + * @return TEEC_ERROR_BAD_PARAMETERS invalid parameter, context or sharedMem is NULL + */ +TEEC_Result TEEC_RegisterSharedMemory( + TEEC_Context *context, + TEEC_SharedMemory *sharedMem); + + +/* + * deregisters or deallocates a previously initialized block of Shared Memory + * if memory is allocated by TEEC_AllocateSharedMemory, system will free this memory + * if memory is registered by TEEC_RegisterSharedMemory, system will not free this memory + * + * @param sharedMem [IN/OUT] a pointer to a valid Shared Memory structure + * + * @return void + */ +extern +void TEEC_ReleaseSharedMemory( + TEEC_SharedMemory *sharedMem); + + +/* + */ +extern +TEEC_Result +TEEC_DeployTa( + char * infile_path, + char * subdir, + char * outfile_name +); + + +/* + */ +extern +TEEC_Result +TEEC_SetJwt( + char * token +); + + +/* + */ +extern +TEEC_Result +TEEC_UnsetJwt( +); + + + +#ifdef __cplusplus +} +#endif + +#endif // teec_client_api_h__ diff --git a/teeproxy/libteecc/protos/gt.proto b/teeproxy/libteecc/protos/gt.proto new file mode 100644 index 0000000000000000000000000000000000000000..3eeff06dea0dec6e6c5445cd3957bcb5d7c6a069 --- /dev/null +++ b/teeproxy/libteecc/protos/gt.proto @@ -0,0 +1,392 @@ +// + +syntax = "proto3"; + +option java_multiple_files = true; +option java_package = "io.grpc.gt"; +option java_outer_classname = "gtProto"; +option objc_class_prefix = "HLW"; + +package gt; + +// The gpp service definition. +service gpp { + rpc TEECC_InitializeContext (Inicont_Request) returns (Inicont_Reply) {} + rpc TEECC_FinalizeContext (Fincont_Request) returns (Fincont_Reply) {} + rpc TEECC_OpenSession (Opes_Request) returns (Opes_Reply) {} + rpc TEECC_InvokeCommand (Invo_Request) returns (Invo_Reply) {} + rpc TEECC_CloseSession (Close_Request) returns (Close_Reply) {} + rpc TEECC_TA(TA_Chunk) returns (TA_Reply) {} + rpc TEECC_SetJwt(Setjwt_Request) returns (Setjwt_Reply) {} +} + + +message Inicont_Request { + uint64 name_size = 1; + string name = 2; + string token = 3; + string taname = 4; +} + +message Inicont_Reply { + uint32 teecresult = 1; + int32 context_fd = 2; + uint64 context_tapath_outsize = 3; + bytes context_tapath = 4; + uint64 context_sessionlist_next = 5; + uint64 context_sessionlist_prev = 6; + uint64 context_shrdmemlist_next = 7; + uint64 context_shrdmemlist_prev = 8; + uint64 context_sharebuffer_buffer = 9; + int64 context_sharebuffer_bufferbarrier = 10; + uint64 context_addr = 11; + int32 flag = 12; +} + +message Fincont_Request { + int32 in_context_fd = 1; + uint64 in_context_tapath_size= 2; + bytes in_context_tapath = 3; + uint64 in_context_sessionlist_next = 4; + uint64 in_context_sessionlist_prev = 5; + uint64 in_context_shrdmemlist_next = 6; + uint64 in_context_shrdmemlist_prev = 7; + uint64 in_context_sharebuffer_buffer = 8; + int64 in_context_sharebuffer_bufferbarrier = 9; + uint64 in_context_addr = 10; + string token = 11; + string taname = 12; +} + +message Fincont_Reply { + int32 context_fd = 1; + uint64 context_tapath_outsize = 2; + bytes context_tapath = 3; + uint64 context_sessionlist_next = 4; + uint64 context_sessionlist_prev = 5; + uint64 context_shrdmemlist_next = 6; + uint64 context_shrdmemlist_prev = 7; + uint64 context_sharebuffer_buffer = 8; + int64 context_sharebuffer_bufferbarrier = 9; + uint64 context_addr = 10; + int32 flag = 11; +} + +message Opes_Request { + int32 in_context_fd = 1; + uint64 in_context_tapath_size= 2; + bytes in_context_tapath = 3; + uint64 in_context_sessionlist_next = 4; + uint64 in_context_sessionlist_prev = 5; + uint64 in_context_shrdmemlist_next = 6; + uint64 in_context_shrdmemlist_prev = 7; + uint64 in_context_sharebuffer_buffer = 8; + int64 in_context_sharebuffer_bufferbarrier = 9; + uint32 in_destination_timelow = 10; + uint32 in_destination_timemid = 11; + uint32 in_destination_timehiandver = 12; + uint64 in_destination_cad_size = 13; + repeated uint32 in_destination_clockseqandnode = 14; + uint32 in_connectionmethod = 15; + uint64 in_connectiondata = 16; + uint32 in_operation_started = 17; + uint32 in_operation_paramtypes = 18; + uint64 in_operation_param1_tmpref_buffer = 19; + uint32 in_operation_param1_tmpref_size = 20; + uint64 in_operation_param1_memref_parent = 21; + uint32 in_operation_param1_memref_size = 22; + uint32 in_operation_param1_memref_offset = 23; + uint32 in_operation_param1_value_a = 24; + uint32 in_operation_param1_value_b = 25; + int32 in_operation_param1_ionref_ionsharefd = 26; + uint32 in_operation_param1_ionref_ionsize = 27; + uint64 in_operation_param2_tmpref_buffer = 28; + uint32 in_operation_param2_tmpref_size = 29; + uint64 in_operation_param2_memref_parent = 30; + uint32 in_operation_param2_memref_size = 31; + uint32 in_operation_param2_memref_offset = 32; + uint32 in_operation_param2_value_a = 33; + uint32 in_operation_param2_value_b = 34; + int32 in_operation_param2_ionref_ionsharefd = 35; + uint32 in_operation_param2_ionref_ionsize = 36; + uint64 in_operation_param3_tmpref_buffer = 37; + uint32 in_operation_param3_tmpref_size = 38; + uint64 in_operation_param3_memref_parent = 39; + uint32 in_operation_param3_memref_size = 40; + uint32 in_operation_param3_memref_offset = 41; + uint32 in_operation_param3_value_a = 42; + uint32 in_operation_param3_value_b = 43; + int32 in_operation_param3_ionref_ionsharefd = 44; + uint32 in_operation_param3_ionref_ionsize = 45; + uint64 in_operation_param4_tmpref_buffer = 46; + uint32 in_operation_param4_tmpref_size = 47; + uint64 in_operation_param4_memref_parent = 48; + uint32 in_operation_param4_memref_size = 49; + uint32 in_operation_param4_memref_offset = 50; + uint32 in_operation_param4_value_a = 51; + uint32 in_operation_param4_value_b = 52; + int32 in_operation_param4_ionref_ionsharefd = 53; + uint32 in_operation_param4_ionref_ionsize = 54; + uint64 in_operation_session = 55; + int32 in_operation_cancelflag = 56; + uint32 in_returnorigin = 57; + uint64 in_context_addr = 58; + string token = 59; + string taname = 60; +} + +message Opes_Reply { + uint32 teecresult = 1; + int32 context_fd = 2; + bytes context_tapath = 3 ; + uint64 context_tapath_outsize = 4; + uint64 context_sessionlist_next = 5; + uint64 context_sessionlist_prev = 6; + uint64 context_shrdmemlist_next = 7; + uint64 context_shrdmemlist_prev = 8; + uint64 context_sharebuffer_buffer = 9; + int64 context_sharebuffer_bufferbarrier = 10; + uint32 session_sessionid = 11; + uint32 session_serviceid_timelow = 12; + uint32 session_serviceid_timemid = 13; + uint32 session_serviceid_timehiandver = 14; + uint64 session_serviceid_clockseqandnode_outsize = 15; + repeated uint32 session_serviceid_clockseqandnode = 16; + uint32 session_opscnt = 17; + uint64 session_head_next = 18; + uint64 session_head_prev = 19; + uint64 session_context = 20; + uint32 operation_started = 21; + uint32 operation_paramtypes = 22; + uint64 operation_param1_tmpref_buffer = 23; + uint32 operation_param1_tmpref_size = 24; + uint64 operation_param1_memref_parent = 25; + uint32 operation_param1_memref_size = 26; + uint32 operation_param1_memref_offset = 27; + uint32 operation_param1_value_a = 28; + uint32 operation_param1_value_b = 29; + int32 operation_param1_ionref_ionsharefd = 30; + uint32 operation_param1_ionref_ionsize = 31; + uint64 operation_param2_tmpref_buffer = 32; + uint32 operation_param2_tmpref_size = 33; + uint64 operation_param2_memref_parent = 34; + uint32 operation_param2_memref_size = 35; + uint32 operation_param2_memref_offset = 36; + uint32 operation_param2_value_a = 37; + uint32 operation_param2_value_b = 38; + int32 operation_param2_ionref_ionsharefd = 39; + uint32 operation_param2_ionref_ionsize = 40; + uint64 operation_param3_tmpref_buffer = 41; + uint32 operation_param3_tmpref_size = 42; + uint64 operation_param3_memref_parent = 43; + uint32 operation_param3_memref_size = 44; + uint32 operation_param3_memref_offset = 45; + uint32 operation_param3_value_a = 46; + uint32 operation_param3_value_b = 47; + int32 operation_param3_ionref_ionsharefd = 48; + uint32 operation_param3_ionref_ionsize = 49; + uint64 operation_param4_tmpref_buffer = 50; + uint32 operation_param4_tmpref_size = 51; + uint64 operation_param4_memref_parent = 52; + uint32 operation_param4_memref_size = 53; + uint32 operation_param4_memref_offset = 54; + uint32 operation_param4_value_a = 55; + uint32 operation_param4_value_b = 56; + int32 operation_param4_ionref_ionsharefd = 57; + uint32 operation_param4_ionref_ionsize = 58; + uint64 operation_session = 59; + int32 operation_cancelflag = 60; + uint32 returnorigin = 61; + int32 flag = 62; +} + +message Invo_Request { + uint32 in_session_sessionid = 1; + uint32 in_session_serviceid_timelow = 2; + uint32 in_session_serviceid_timemid = 3; + uint32 in_session_serviceid_timehiandver = 4; + uint64 in_session_serviceid_cad_size = 5; + repeated uint32 in_session_serviceid_clockseqandnode = 6; + uint32 in_session_opscnt = 7; + uint64 in_session_head_next = 8; + uint64 in_session_head_prev = 9; + uint64 in_session_context = 10; + uint32 in_commandid = 11; + uint32 in_operation_started = 12; + uint32 in_operation_paramtypes = 13; + uint64 in_operation_param1_tmpref_buffer = 14; + uint32 in_operation_param1_tmpref_size = 15; + uint64 in_operation_param1_memref_parent = 16; + uint32 in_operation_param1_memref_parent_flag = 17; + uint32 in_operation_param1_memref_size = 18; + uint32 in_operation_param1_memref_offset = 19; + uint32 in_operation_param1_value_a = 20; + uint32 in_operation_param1_value_b = 21; + int32 in_operation_param1_ionref_ionsharefd = 22; + uint32 in_operation_param1_ionref_ionsize = 23; + uint64 in_operation_param2_tmpref_buffer = 24; + uint32 in_operation_param2_tmpref_size = 25; + uint64 in_operation_param2_memref_parent = 26; + uint32 in_operation_param2_memref_parent_flag = 27; + uint32 in_operation_param2_memref_size = 28; + uint32 in_operation_param2_memref_offset = 29; + uint32 in_operation_param2_value_a = 30; + uint32 in_operation_param2_value_b = 31; + int32 in_operation_param2_ionref_ionsharefd = 32; + uint32 in_operation_param2_ionref_ionsize = 33; + uint64 in_operation_param3_tmpref_buffer = 34; + uint32 in_operation_param3_tmpref_size = 35; + uint64 in_operation_param3_memref_parent = 36; + uint32 in_operation_param3_memref_parent_flag = 37; + uint32 in_operation_param3_memref_size = 38; + uint32 in_operation_param3_memref_offset = 39; + uint32 in_operation_param3_value_a = 40; + uint32 in_operation_param3_value_b = 41; + int32 in_operation_param3_ionref_ionsharefd = 42; + uint32 in_operation_param3_ionref_ionsize = 43; + uint64 in_operation_param4_tmpref_buffer = 44; + uint32 in_operation_param4_tmpref_size = 45; + uint64 in_operation_param4_memref_parent = 46; + uint32 in_operation_param4_memref_parent_flag = 47; + uint32 in_operation_param4_memref_size = 48; + uint32 in_operation_param4_memref_offset = 49; + uint32 in_operation_param4_value_a = 50; + uint32 in_operation_param4_value_b = 51; + int32 in_operation_param4_ionref_ionsharefd = 52; + uint32 in_operation_param4_ionref_ionsize = 53; + uint64 in_operation_session = 54; + int32 in_operation_cancelflag = 55; + uint32 in_returnorigin = 56; + uint64 in_bufer1_size = 57; + repeated uint32 in_buffer1 = 58; + uint64 in_bufer2_size = 59; + repeated uint32 in_buffer2 = 60; + uint64 in_bufer3_size = 61; + repeated uint32 in_buffer3 = 62; + uint64 in_bufer4_size = 63; + repeated uint32 in_buffer4 = 64; + string token = 65; + string taname = 66; +} + +message Invo_Reply { + uint32 teecresult = 1; + uint32 session_sessionid = 2; + uint32 session_serviceid_timelow = 3; + uint32 session_serviceid_timemid = 4; + uint32 session_serviceid_timehiandver = 5; + uint64 session_serviceid_clockseqandnode_outsize = 6; + repeated uint32 session_serviceid_clockseqandnode = 7; + uint32 session_opscnt = 8; + uint64 session_head_next = 9; + uint64 session_head_prev = 10; + uint64 session_context = 11; + uint32 operation_started = 12; + uint32 operation_paramtypes = 13; + uint64 operation_param1_tmpref_buffer = 14; + uint32 operation_param1_tmpref_size = 15; + uint64 operation_param1_memref_parent = 16; + uint32 operation_param1_memref_parent_flag = 17; + uint32 operation_param1_memref_size = 18; + uint32 operation_param1_memref_offset = 19; + uint32 operation_param1_value_a = 20; + uint32 operation_param1_value_b = 21; + int32 operation_param1_ionref_ionsharefd = 22; + uint32 operation_param1_ionref_ionsize = 23; + uint64 operation_param2_tmpref_buffer = 24; + uint32 operation_param2_tmpref_size = 25; + uint64 operation_param2_memref_parent = 26; + uint32 operation_param2_memref_parent_flag = 27; + uint32 operation_param2_memref_size = 28; + uint32 operation_param2_memref_offset = 29; + uint32 operation_param2_value_a = 30; + uint32 operation_param2_value_b = 31; + int32 operation_param2_ionref_ionsharefd = 32; + uint32 operation_param2_ionref_ionsize = 33; + uint64 operation_param3_tmpref_buffer = 34; + uint32 operation_param3_tmpref_size = 35; + uint64 operation_param3_memref_parent = 36; + uint32 operation_param3_memref_parent_flag = 37; + uint32 operation_param3_memref_size = 38; + uint32 operation_param3_memref_offset = 39; + uint32 operation_param3_value_a = 40; + uint32 operation_param3_value_b = 41; + int32 operation_param3_ionref_ionsharefd = 42; + uint32 operation_param3_ionref_ionsize = 43; + uint64 operation_param4_tmpref_buffer = 44; + uint32 operation_param4_tmpref_size = 45; + uint64 operation_param4_memref_parent = 46; + uint32 operation_param4_memref_parent_flag = 47; + uint32 operation_param4_memref_size = 48; + uint32 operation_param4_memref_offset = 49; + uint32 operation_param4_value_a = 50; + uint32 operation_param4_value_b = 51; + int32 operation_param4_ionref_ionsharefd = 52; + uint32 operation_param4_ionref_ionsize = 53; + uint64 operation_session = 54; + int32 operation_cancelflag = 55; + uint32 returnorigin = 56; + + uint64 buffer1_outsize = 57; + uint64 buffer2_outsize = 58; + uint64 buffer3_outsize = 59; + uint64 buffer4_outsize = 60; + + repeated uint32 buffer1 = 61; + repeated uint32 buffer2 = 62; + repeated uint32 buffer3 = 63; + repeated uint32 buffer4 = 64; + int32 flag = 65; +} + +message Close_Request { + uint32 in_session_sessionid = 1; + uint32 in_session_serviceid_timelow = 2; + uint32 in_session_serviceid_timemid = 3; + uint32 in_session_serviceid_timehiandver = 4; + uint64 in_session_serviceid_cad_size = 5; + repeated uint32 in_session_serviceid_clockseqandnode = 6; + uint32 in_session_opscnt = 7; + uint64 in_session_head_next = 8; + uint64 in_session_head_prev = 9; + uint64 in_session_context = 10; + string token = 11; + string taname = 12; +} + +message Close_Reply { + uint32 session_sessionid = 1; + uint32 session_serviceid_timelow = 2; + uint32 session_serviceid_timemid = 3; + uint32 session_serviceid_timehiandver = 4; + uint64 session_serviceid_cad_outsize = 5; + repeated uint32 session_serviceid_clockseqandnode = 6; + uint32 session_opscnt = 7; + uint64 session_head_next = 8; + uint64 session_head_prev = 9; + uint64 session_context = 10; + int32 flag = 11; +} + +message TA_Chunk{ + string name = 1; + bytes buffer = 2; + string token = 3; + string taname = 4; + bytes sha256 = 5; + string subdir = 6; +} + +message TA_Reply{ + int32 code = 1; + int32 flag = 2; +} + +message Setjwt_Request{ + string taname = 1; + string token = 2; +} + +message Setjwt_Reply{ + int32 retcode = 1; +} diff --git a/teeproxy/libteecc/teecc.cc b/teeproxy/libteecc/teecc.cc new file mode 100644 index 0000000000000000000000000000000000000000..c4a661796e24809b22a8f93657162fae1a00dc92 --- /dev/null +++ b/teeproxy/libteecc/teecc.cc @@ -0,0 +1,4148 @@ +/* + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "gt.grpc.pb.h" + +#include "teecc.h" +#include "teecc/teec_client_api.h" +#include "yaml-cpp/yaml.h" + +#ifdef __cplusplus +extern "C" { +#endif + +using grpc::Channel; +using grpc::ChannelArguments; +using grpc::experimental::AltsCredentials; +using grpc::experimental::AltsCredentialsOptions; +using grpc::ClientContext; +using grpc::Status; +using grpc::ClientWriter; +using gt::gpp; +using gt::Inicont_Reply; +using gt::Inicont_Request; +using gt::Fincont_Reply; +using gt::Fincont_Request; +using gt::Opes_Reply; +using gt::Opes_Request; +using gt::Invo_Reply; +using gt::Invo_Request; +using gt::Close_Reply; +using gt::Close_Request; +using gt::TA_Chunk; +using gt::TA_Reply; + + +char glo_token[1024] = "noToken"; + + +bool utf8_check_is_valid(std::string &string) +{ + int c, i, ix, n, j; + for (i = 0, ix = string.length(); i < ix; i++) + { + c = (unsigned char) string[i]; + //if (c==0x09 || c==0x0a || c==0x0d || (0x20 <= c && c <= 0x7e) ) n = 0; // is_printable_ascii + if (0x00 <= c && c <= 0x7f) n = 0; // 0bbbbbbb + else if ((c & 0xE0) == 0xC0) n = 1; // 110bbbbb + else if (c == 0xed && i < (ix - 1) && ((unsigned char) string[i + 1] & 0xa0) == 0xa0) + return false; //U+d800 to U+dfff + else if ((c & 0xF0) == 0xE0) n = 2; // 1110bbbb + else if ((c & 0xF8) == 0xF0) n = 3; // 11110bbb + //else if (($c & 0xFC) == 0xF8) n=4; // 111110bb //byte 5, unnecessary in 4 byte UTF-8 + //else if (($c & 0xFE) == 0xFC) n=5; // 1111110b //byte 6, unnecessary in 4 byte UTF-8 + else return false; + for (j = 0; j < n && i < ix; j++) + { // n bytes matching 10bbbbbb follow ? + if ((++i == ix) || (((unsigned char) string[i] & 0xC0) != 0x80)) + return false; + } + } + return true; +} + +#define MAX_DATA_LEN 50*1024 +#define SHA256_LENTH 32 + +int get_file_sha256(char *file_path, char *val) +{ + SHA256_CTX sha256_ctx; + FILE *fp = NULL; + char *strFilePath = file_path; + unsigned char SHA256result[SHA256_LENTH]; + char DataBuff[MAX_DATA_LEN]; + int len; + int t = 0; + int i; + std::string sha256; + + + fp = fopen(strFilePath, "rb"); + + SHA256_Init(&sha256_ctx); + + while (!feof(fp)) + { + memset(DataBuff, 0x00, sizeof(DataBuff)); + + len = fread(DataBuff, 1, MAX_DATA_LEN, fp); + if (len) + { + t += len; + SHA256_Update(&sha256_ctx, DataBuff, len); + } + } + + fclose(fp); + SHA256_Final(SHA256result, &sha256_ctx); + + + if (val == NULL || sizeof(val) * 4 < SHA256_LENTH) + { + return -1; + } else + { + memset(val, 0, sizeof(val)); + for (int itemp = 0; itemp < SHA256_LENTH; itemp++) + { + val[itemp] = SHA256result[itemp]; + } + + } + + return 0; +} + + +class GppClient +{ +public: + GppClient(std::shared_ptr channel) + : stub_(gpp::NewStub(channel)) + {} + + // Assembles the client's payload, + // sends it and presents the response back from the server. + retstru_teec_inicont externc_teec_initializecontext( + std::uint8_t *name, + std::size_t name_size + ) + { + // Data we are sending to the server. + Inicont_Request request; + request.set_name_size(name_size); + if (name_size > 0) + { + std::string name_temp((char *) name); + request.set_name(name_temp); + } + request.set_token(glo_token); + + // Container for the data we expect from the server. + Inicont_Reply reply; + + ClientContext context; + retstru_teec_inicont rreply; + + // The actual RPC. + Status status = stub_->TEECC_InitializeContext(&context, request, &reply); + retstru_teec_inicont error; + + rreply.teecresult = reply.teecresult(); + rreply.context_fd = reply.context_fd(); + rreply.context_tapath_outsize = reply.context_tapath_outsize(); + if (rreply.context_tapath_outsize > 0) + { + rreply.context_tapath = (uint8_t *) malloc((rreply.context_tapath_outsize + 1) * sizeof(uint8_t));; + reply.context_tapath().copy((char *) rreply.context_tapath, rreply.context_tapath_outsize, 0); + } + rreply.context_sessionlist_next = reply.context_sessionlist_next(); + rreply.context_sessionlist_prev = reply.context_sessionlist_prev(); + rreply.context_shrdmemlist_prev = reply.context_shrdmemlist_prev(); + rreply.context_shrdmemlist_next = reply.context_shrdmemlist_next(); + rreply.context_sharebuffer_buffer = reply.context_sharebuffer_buffer(); + rreply.context_sharebuffer_bufferbarrier = reply.context_sharebuffer_bufferbarrier(); + rreply.context_addr = reply.context_addr(); + rreply.flag = reply.flag(); + // Act upon its status. + if (status.ok()) + { + return rreply; + } else + { + std::cout << "libteecc initcontext grpc error: " << status.error_code() << ", " << status.error_message() + << std::endl; + return error; + } + } + + retstru_teec_fincont externc_teec_finalizecontext( + std::int32_t in_context_fd, + std::uint8_t *in_context_tapath, + std::int32_t in_context_tapath_size, + std::uint64_t in_context_sessionlist_next, + std::uint64_t in_context_sessionlist_prev, + std::uint64_t in_context_shrdmemlist_next, + std::uint64_t in_context_shrdmemlist_prev, + std::uint64_t in_context_sharebuffer_buffer, + std::int64_t in_context_sharebuffer_bufferbarrier, + std::uint64_t in_context_addr + ) + { + // Data we are sending to the server. + Fincont_Request request; + + request.set_in_context_fd(in_context_fd); + request.set_in_context_tapath_size(in_context_tapath_size); + if (in_context_tapath_size > 0) + { + std::string in_context_tapath_temp((char *) in_context_tapath); + request.set_in_context_tapath(in_context_tapath_temp); + } + request.set_in_context_sessionlist_next(in_context_sessionlist_next); + request.set_in_context_sessionlist_prev(in_context_sessionlist_prev); + request.set_in_context_shrdmemlist_prev(in_context_shrdmemlist_prev); + request.set_in_context_shrdmemlist_next(in_context_shrdmemlist_next); + request.set_in_context_sharebuffer_buffer(in_context_sharebuffer_buffer); + request.set_in_context_sharebuffer_bufferbarrier(in_context_sharebuffer_bufferbarrier); + request.set_in_context_addr(in_context_addr); + request.set_token(glo_token); + + //questntainer for the data we expect from the server. + Fincont_Reply reply; + ClientContext context; + retstru_teec_fincont rreply; + + // The actual RPC. + Status status = stub_->TEECC_FinalizeContext(&context, request, &reply); + retstru_teec_fincont error; + + rreply.context_fd = reply.context_fd(); + rreply.context_tapath_outsize = reply.context_tapath_outsize(); + if (rreply.context_tapath_outsize > 0) + { + rreply.context_tapath = (uint8_t *) malloc((rreply.context_tapath_outsize + 1) * sizeof(uint8_t));; + reply.context_tapath().copy((char *) rreply.context_tapath, rreply.context_tapath_outsize, 0); + } + rreply.context_sessionlist_next = reply.context_sessionlist_next(); + rreply.context_sessionlist_prev = reply.context_sessionlist_prev(); + rreply.context_shrdmemlist_prev = reply.context_shrdmemlist_prev(); + rreply.context_shrdmemlist_next = reply.context_shrdmemlist_next(); + rreply.context_sharebuffer_buffer = reply.context_sharebuffer_buffer(); + rreply.context_sharebuffer_bufferbarrier = reply.context_sharebuffer_bufferbarrier(); + rreply.flag = reply.flag(); + // Act upon its status. + if (status.ok()) + { + return rreply; + } else + { + std::cout << "libteecc finalizecontext grpc error: " << status.error_code() << ", " << status.error_message() + << std::endl; + return error; + } + } + + retstru_teec_opensession externc_teec_opensession( + std::int32_t in_context_fd, + std::uint8_t *in_context_tapath, + std::int32_t in_context_tapath_size, + std::uint64_t in_context_sessionlist_next, + std::uint64_t in_context_sessionlist_prev, + std::uint64_t in_context_shrdmemlist_next, + std::uint64_t in_context_shrdmemlist_prev, + std::uint64_t in_context_sharebuffer_buffer, + std::int64_t in_context_sharebuffer_bufferbarrier, + std::uint32_t in_destination_timelow, + std::uint32_t in_destination_timemid, + std::uint32_t in_destination_timehiandver, + std::uint8_t *in_destination_clockseqandnode, + std::int32_t in_destination_clockseqandnode_size, + std::uint32_t in_connectionmethod, + std::uint64_t in_connectiondata, + std::uint32_t in_operation_started, + std::uint32_t in_operation_paramtypes, + std::uint64_t in_operation_param1_tmpref_buffer, + std::uint32_t in_operation_param1_tmpref_size, + std::uint64_t in_operation_param1_memref_parent, + std::uint32_t in_operation_param1_memref_size, + std::uint32_t in_operation_param1_memref_offset, + std::uint32_t in_operation_param1_value_a, + std::uint32_t in_operation_param1_value_b, + std::int32_t in_operation_param1_ionref_ionsharefd, + std::uint32_t in_operation_param1_ionref_ionsize, + std::uint64_t in_operation_param2_tmpref_buffer, + std::uint32_t in_operation_param2_tmpref_size, + std::uint64_t in_operation_param2_memref_parent, + std::uint32_t in_operation_param2_memref_size, + std::uint32_t in_operation_param2_memref_offset, + std::uint32_t in_operation_param2_value_a, + std::uint32_t in_operation_param2_value_b, + std::int32_t in_operation_param2_ionref_ionsharefd, + std::uint32_t in_operation_param2_ionref_ionsize, + std::uint64_t in_operation_param3_tmpref_buffer, + std::uint32_t in_operation_param3_tmpref_size, + std::uint64_t in_operation_param3_memref_parent, + std::uint32_t in_operation_param3_memref_size, + std::uint32_t in_operation_param3_memref_offset, + std::uint32_t in_operation_param3_value_a, + std::uint32_t in_operation_param3_value_b, + std::int32_t in_operation_param3_ionref_ionsharefd, + std::uint32_t in_operation_param3_ionref_ionsize, + std::uint64_t in_operation_param4_tmpref_buffer, + std::uint32_t in_operation_param4_tmpref_size, + std::uint64_t in_operation_param4_memref_parent, + std::uint32_t in_operation_param4_memref_size, + std::uint32_t in_operation_param4_memref_offset, + std::uint32_t in_operation_param4_value_a, + std::uint32_t in_operation_param4_value_b, + std::int32_t in_operation_param4_ionref_ionsharefd, + std::uint32_t in_operation_param4_ionref_ionsize, + std::uint64_t in_operation_session, + std::int32_t in_operation_cancelflag, + std::uint32_t in_returnorigin, + std::uint64_t in_context_addr + ) + { + // Data we are sending to the server. + Opes_Request request; + request.set_in_context_fd(in_context_fd); + request.set_in_context_tapath_size(in_context_tapath_size); + if (in_context_tapath_size > 0) + { + std::string in_context_tapath_temp((char *) in_context_tapath); + request.set_in_context_tapath(in_context_tapath_temp); + } + request.set_in_context_sessionlist_next(in_context_sessionlist_next); + request.set_in_context_sessionlist_prev(in_context_sessionlist_prev); + request.set_in_context_shrdmemlist_prev(in_context_shrdmemlist_prev); + request.set_in_context_shrdmemlist_next(in_context_shrdmemlist_next); + request.set_in_context_sharebuffer_buffer(in_context_sharebuffer_buffer); + request.set_in_context_sharebuffer_bufferbarrier(in_context_sharebuffer_bufferbarrier); + request.set_in_destination_timelow(in_destination_timelow); + request.set_in_destination_timemid(in_destination_timemid); + request.set_in_destination_timehiandver(in_destination_timehiandver); + request.set_in_destination_cad_size(in_destination_clockseqandnode_size); + if (in_destination_clockseqandnode_size > 0) + { + for (int i = 0; i < in_destination_clockseqandnode_size; i++) + { + request.add_in_destination_clockseqandnode(in_destination_clockseqandnode[i]); + } + + } + request.set_in_connectionmethod(in_connectionmethod); + request.set_in_connectiondata(in_connectiondata); + request.set_in_operation_started(in_operation_started); + request.set_in_operation_paramtypes(in_operation_paramtypes); + request.set_in_operation_param1_tmpref_buffer(in_operation_param1_tmpref_buffer); + request.set_in_operation_param1_tmpref_size(in_operation_param1_tmpref_size); + request.set_in_operation_param1_memref_parent(in_operation_param1_memref_parent); + request.set_in_operation_param1_memref_size(in_operation_param1_memref_size); + request.set_in_operation_param1_memref_offset(in_operation_param1_memref_offset); + request.set_in_operation_param1_value_a(in_operation_param1_value_a); + request.set_in_operation_param1_value_b(in_operation_param1_value_b); + request.set_in_operation_param1_ionref_ionsharefd(in_operation_param1_ionref_ionsharefd); + request.set_in_operation_param1_ionref_ionsize(in_operation_param1_ionref_ionsize); + request.set_in_operation_param2_tmpref_buffer(in_operation_param2_tmpref_buffer); + request.set_in_operation_param2_tmpref_size(in_operation_param2_tmpref_size); + request.set_in_operation_param2_memref_parent(in_operation_param2_memref_parent); + request.set_in_operation_param2_memref_size(in_operation_param2_memref_size); + request.set_in_operation_param2_memref_offset(in_operation_param2_memref_offset); + request.set_in_operation_param2_value_a(in_operation_param2_value_a); + request.set_in_operation_param2_value_b(in_operation_param2_value_b); + request.set_in_operation_param2_ionref_ionsharefd(in_operation_param2_ionref_ionsharefd); + request.set_in_operation_param2_ionref_ionsize(in_operation_param2_ionref_ionsize); + request.set_in_operation_param3_tmpref_buffer(in_operation_param3_tmpref_buffer); + request.set_in_operation_param3_tmpref_size(in_operation_param3_tmpref_size); + request.set_in_operation_param3_memref_parent(in_operation_param3_memref_parent); + request.set_in_operation_param3_memref_size(in_operation_param3_memref_size); + request.set_in_operation_param3_memref_offset(in_operation_param3_memref_offset); + request.set_in_operation_param3_value_a(in_operation_param3_value_a); + request.set_in_operation_param3_value_b(in_operation_param3_value_b); + request.set_in_operation_param3_ionref_ionsharefd(in_operation_param3_ionref_ionsharefd); + request.set_in_operation_param3_ionref_ionsize(in_operation_param3_ionref_ionsize); + request.set_in_operation_param4_tmpref_buffer(in_operation_param4_tmpref_buffer); + request.set_in_operation_param4_tmpref_size(in_operation_param4_tmpref_size); + request.set_in_operation_param4_memref_parent(in_operation_param4_memref_parent); + request.set_in_operation_param4_memref_size(in_operation_param4_memref_size); + request.set_in_operation_param4_memref_offset(in_operation_param4_memref_offset); + request.set_in_operation_param4_value_a(in_operation_param4_value_a); + request.set_in_operation_param4_value_b(in_operation_param4_value_b); + request.set_in_operation_param4_ionref_ionsharefd(in_operation_param4_ionref_ionsharefd); + request.set_in_operation_param4_ionref_ionsize(in_operation_param4_ionref_ionsize); + request.set_in_operation_session(in_operation_session); + request.set_in_operation_cancelflag(in_operation_cancelflag); + request.set_in_returnorigin(in_returnorigin); + request.set_in_context_addr(in_context_addr); + + request.set_token(glo_token); + //questntainer for the data we expect from the server. + Opes_Reply reply; + ClientContext context; + retstru_teec_opensession rreply; + + // The actual RPC. + Status status = stub_->TEECC_OpenSession(&context, request, &reply); + retstru_teec_opensession error; + + rreply.teecresult = reply.teecresult(); + rreply.context_fd = reply.context_fd(); + rreply.context_tapath_outsize = reply.context_tapath_outsize(); + if (rreply.context_tapath_outsize > 0) + { + rreply.context_tapath = (uint8_t *) malloc((rreply.context_tapath_outsize + 1) * sizeof(uint8_t));; + reply.context_tapath().copy((char *) rreply.context_tapath, rreply.context_tapath_outsize, 0); + } + rreply.context_sessionlist_next = reply.context_sessionlist_next(); + rreply.context_sessionlist_prev = reply.context_sessionlist_prev(); + rreply.context_shrdmemlist_prev = reply.context_shrdmemlist_prev(); + rreply.context_shrdmemlist_next = reply.context_shrdmemlist_next(); + rreply.context_sharebuffer_buffer = reply.context_sharebuffer_buffer(); + rreply.session_sessionid = reply.session_sessionid(); + rreply.session_serviceid_timelow = reply.session_serviceid_timelow(); + rreply.session_serviceid_timemid = reply.session_serviceid_timemid(); + rreply.session_serviceid_timehiandver = reply.session_serviceid_timehiandver(); + rreply.session_serviceid_clockseqandnode_outsize = reply.session_serviceid_clockseqandnode_outsize(); + if (rreply.session_serviceid_clockseqandnode_outsize > 0) + { + rreply.session_serviceid_clockseqandnode = new uint8_t[rreply.session_serviceid_clockseqandnode_outsize]; + for (int i = 0; i < rreply.session_serviceid_clockseqandnode_outsize; i++) + { + rreply.session_serviceid_clockseqandnode[i] = reply.session_serviceid_clockseqandnode(i); + } + } + rreply.session_opscnt = reply.session_opscnt(); + rreply.session_head_next = reply.session_head_next(); + rreply.session_head_prev = reply.session_head_prev(); + rreply.session_context = reply.session_context(); + rreply.operation_started = reply.operation_started(); + rreply.operation_paramtypes = reply.operation_paramtypes(); + rreply.operation_param1_tmpref_buffer = reply.operation_param1_tmpref_buffer(); + rreply.operation_param1_tmpref_size = reply.operation_param1_tmpref_size(); + rreply.operation_param1_memref_parent = reply.operation_param1_memref_parent(); + rreply.operation_param1_memref_size = reply.operation_param1_memref_size(); + rreply.operation_param1_memref_offset = reply.operation_param1_memref_offset(); + rreply.operation_param1_value_a = reply.operation_param1_value_a(); + rreply.operation_param1_value_b = reply.operation_param1_value_b(); + rreply.operation_param1_ionref_ionsharefd = reply.operation_param1_ionref_ionsharefd(); + rreply.operation_param1_ionref_ionsize = reply.operation_param1_ionref_ionsize(); + rreply.operation_param2_tmpref_buffer = reply.operation_param2_tmpref_buffer(); + rreply.operation_param2_tmpref_size = reply.operation_param2_tmpref_size(); + rreply.operation_param2_memref_parent = reply.operation_param2_memref_parent(); + rreply.operation_param2_memref_size = reply.operation_param2_memref_size(); + rreply.operation_param2_memref_offset = reply.operation_param2_memref_offset(); + rreply.operation_param2_value_a = reply.operation_param2_value_a(); + rreply.operation_param2_value_b = reply.operation_param2_value_b(); + rreply.operation_param2_ionref_ionsharefd = reply.operation_param2_ionref_ionsharefd(); + rreply.operation_param2_ionref_ionsize = reply.operation_param2_ionref_ionsize(); + rreply.operation_param3_tmpref_buffer = reply.operation_param3_tmpref_buffer(); + rreply.operation_param3_tmpref_size = reply.operation_param3_tmpref_size(); + rreply.operation_param3_memref_parent = reply.operation_param3_memref_parent(); + rreply.operation_param3_memref_size = reply.operation_param3_memref_size(); + rreply.operation_param3_memref_offset = reply.operation_param3_memref_offset(); + rreply.operation_param3_value_a = reply.operation_param3_value_a(); + rreply.operation_param3_value_b = reply.operation_param3_value_b(); + rreply.operation_param3_ionref_ionsharefd = reply.operation_param3_ionref_ionsharefd(); + rreply.operation_param3_ionref_ionsize = reply.operation_param3_ionref_ionsize(); + rreply.operation_param4_tmpref_buffer = reply.operation_param4_tmpref_buffer(); + rreply.operation_param4_tmpref_size = reply.operation_param4_tmpref_size(); + rreply.operation_param4_memref_parent = reply.operation_param4_memref_parent(); + rreply.operation_param4_memref_size = reply.operation_param4_memref_size(); + rreply.operation_param4_memref_offset = reply.operation_param4_memref_offset(); + rreply.operation_param4_value_a = reply.operation_param4_value_a(); + rreply.operation_param4_value_b = reply.operation_param4_value_b(); + rreply.operation_param4_ionref_ionsharefd = reply.operation_param4_ionref_ionsharefd(); + rreply.operation_param4_ionref_ionsize = reply.operation_param4_ionref_ionsize(); + rreply.operation_session = reply.operation_session(); + rreply.operation_cancelflag = reply.operation_cancelflag(); + rreply.returnorigin = reply.returnorigin(); + rreply.flag = reply.flag(); + + // Act upon its status. + if (status.ok()) + { + return rreply; + } else + { + std::cout << "libteecc opensession grpc error: " << status.error_code() << ", " << status.error_message() + << std::endl; + return error; + } + } + + retstru_teec_invokecommand externc_teec_invokecommand( + std::uint32_t in_session_sessionid, + std::uint32_t in_session_serviceid_timelow, + std::uint32_t in_session_serviceid_timemid, + std::uint32_t in_session_serviceid_timehiandver, + std::uint8_t *in_session_serviceid_clockseqandnode, + std::uintptr_t in_session_serviceid_clockseqandnode_size, + std::uint32_t in_session_opscnt, + std::uint64_t in_session_head_next, + std::uint64_t in_session_head_prev, + std::uint64_t in_session_context, + std::uint32_t in_commandid, + std::uint32_t in_operation_started, + std::uint32_t in_operation_paramtypes, + std::uint64_t in_operation_param1_tmpref_buffer, + std::uint32_t in_operation_param1_tmpref_size, + std::uint64_t in_operation_param1_memref_parent, + std::uint32_t in_operation_param1_memref_parent_flag, + std::uint32_t in_operation_param1_memref_size, + std::uint32_t in_operation_param1_memref_offset, + std::uint32_t in_operation_param1_value_a, + std::uint32_t in_operation_param1_value_b, + std::int32_t in_operation_param1_ionref_ionsharefd, + std::uint32_t in_operation_param1_ionref_ionsize, + std::uint64_t in_operation_param2_tmpref_buffer, + std::uint32_t in_operation_param2_tmpref_size, + std::uint64_t in_operation_param2_memref_parent, + std::uint32_t in_operation_param2_memref_parent_flag, + std::uint32_t in_operation_param2_memref_size, + std::uint32_t in_operation_param2_memref_offset, + std::uint32_t in_operation_param2_value_a, + std::uint32_t in_operation_param2_value_b, + std::int32_t in_operation_param2_ionref_ionsharefd, + std::uint32_t in_operation_param2_ionref_ionsize, + std::uint64_t in_operation_param3_tmpref_buffer, + std::uint32_t in_operation_param3_tmpref_size, + std::uint64_t in_operation_param3_memref_parent, + std::uint32_t in_operation_param3_memref_parent_flag, + std::uint32_t in_operation_param3_memref_size, + std::uint32_t in_operation_param3_memref_offset, + std::uint32_t in_operation_param3_value_a, + std::uint32_t in_operation_param3_value_b, + std::int32_t in_operation_param3_ionref_ionsharefd, + std::uint32_t in_operation_param3_ionref_ionsize, + std::uint64_t in_operation_param4_tmpref_buffer, + std::uint32_t in_operation_param4_tmpref_size, + std::uint64_t in_operation_param4_memref_parent, + std::uint32_t in_operation_param4_memref_parent_flag, + std::uint32_t in_operation_param4_memref_size, + std::uint32_t in_operation_param4_memref_offset, + std::uint32_t in_operation_param4_value_a, + std::uint32_t in_operation_param4_value_b, + std::int32_t in_operation_param4_ionref_ionsharefd, + std::uint32_t in_operation_param4_ionref_ionsize, + std::uint64_t in_operation_session, + std::int32_t in_operation_cancelflag, + std::uint32_t in_returnorigin, + std::uint8_t *in_buffer1, + std::uintptr_t in_buffer1_size, + std::uint8_t *in_buffer2, + std::uintptr_t in_buffer2_size, + std::uint8_t *in_buffer3, + std::uintptr_t in_buffer3_size, + std::uint8_t *in_buffer4, + std::uintptr_t in_buffer4_size + ) + { + // Data we are sending to the server. + Invo_Request request; + request.set_in_session_sessionid(in_session_sessionid); + + request.set_in_session_serviceid_timelow(in_session_serviceid_timelow); + request.set_in_session_serviceid_timemid(in_session_serviceid_timemid); + request.set_in_session_serviceid_timehiandver(in_session_serviceid_timehiandver); + request.set_in_session_serviceid_cad_size(in_session_serviceid_clockseqandnode_size); + if (in_session_serviceid_clockseqandnode_size > 0) + { + for (int i = 0; i < in_session_serviceid_clockseqandnode_size; i++) + { + request.add_in_session_serviceid_clockseqandnode(in_session_serviceid_clockseqandnode[i]); + } + + } + request.set_in_session_opscnt(in_session_opscnt); + request.set_in_session_head_next(in_session_head_next); + request.set_in_session_head_prev(in_session_head_prev); + request.set_in_session_context(in_session_context); + request.set_in_commandid(in_commandid); + request.set_in_operation_started(in_operation_started); + request.set_in_operation_paramtypes(in_operation_paramtypes); + request.set_in_operation_param1_tmpref_buffer(in_operation_param1_tmpref_buffer); + request.set_in_operation_param1_tmpref_size(in_operation_param1_tmpref_size); + request.set_in_operation_param1_memref_parent(in_operation_param1_memref_parent); + request.set_in_operation_param1_memref_parent_flag(in_operation_param1_memref_parent_flag); + request.set_in_operation_param1_memref_size(in_operation_param1_memref_size); + request.set_in_operation_param1_memref_offset(in_operation_param1_memref_offset); + request.set_in_operation_param1_value_a(in_operation_param1_value_a); + request.set_in_operation_param1_value_b(in_operation_param1_value_b); + request.set_in_operation_param1_ionref_ionsharefd(in_operation_param1_ionref_ionsharefd); + request.set_in_operation_param1_ionref_ionsize(in_operation_param1_ionref_ionsize); + request.set_in_operation_param2_tmpref_buffer(in_operation_param2_tmpref_buffer); + request.set_in_operation_param2_tmpref_size(in_operation_param2_tmpref_size); + request.set_in_operation_param2_memref_parent(in_operation_param2_memref_parent); + request.set_in_operation_param2_memref_parent_flag(in_operation_param2_memref_parent_flag); + request.set_in_operation_param2_memref_size(in_operation_param2_memref_size); + request.set_in_operation_param2_memref_offset(in_operation_param2_memref_offset); + request.set_in_operation_param2_value_a(in_operation_param2_value_a); + request.set_in_operation_param2_value_b(in_operation_param2_value_b); + request.set_in_operation_param2_ionref_ionsharefd(in_operation_param2_ionref_ionsharefd); + request.set_in_operation_param2_ionref_ionsize(in_operation_param2_ionref_ionsize); + request.set_in_operation_param3_tmpref_buffer(in_operation_param3_tmpref_buffer); + request.set_in_operation_param3_tmpref_size(in_operation_param3_tmpref_size); + request.set_in_operation_param3_memref_parent(in_operation_param3_memref_parent); + request.set_in_operation_param3_memref_parent_flag(in_operation_param3_memref_parent_flag); + request.set_in_operation_param3_memref_size(in_operation_param3_memref_size); + request.set_in_operation_param3_memref_offset(in_operation_param3_memref_offset); + request.set_in_operation_param3_value_a(in_operation_param3_value_a); + request.set_in_operation_param3_value_b(in_operation_param3_value_b); + request.set_in_operation_param3_ionref_ionsharefd(in_operation_param3_ionref_ionsharefd); + request.set_in_operation_param3_ionref_ionsize(in_operation_param3_ionref_ionsize); + request.set_in_operation_param4_tmpref_buffer(in_operation_param4_tmpref_buffer); + request.set_in_operation_param4_tmpref_size(in_operation_param4_tmpref_size); + request.set_in_operation_param4_memref_parent(in_operation_param4_memref_parent); + request.set_in_operation_param4_memref_parent_flag(in_operation_param4_memref_parent_flag); + request.set_in_operation_param4_memref_size(in_operation_param4_memref_size); + request.set_in_operation_param4_memref_offset(in_operation_param4_memref_offset); + request.set_in_operation_param4_value_a(in_operation_param4_value_a); + request.set_in_operation_param4_value_b(in_operation_param4_value_b); + request.set_in_operation_param4_ionref_ionsharefd(in_operation_param4_ionref_ionsharefd); + request.set_in_operation_param4_ionref_ionsize(in_operation_param4_ionref_ionsize); + request.set_in_operation_session(in_operation_session); + request.set_in_operation_cancelflag(in_operation_cancelflag); + request.set_in_returnorigin(in_returnorigin); + request.set_in_bufer1_size(in_buffer1_size); + if (in_buffer1_size > 0) + { + for (int i = 0; i < in_buffer1_size; i++) + { + request.add_in_buffer1(in_buffer1[i]); + } + } + request.set_in_bufer2_size(in_buffer2_size); + if (in_buffer2_size > 0) + { + for (int i = 0; i < in_buffer2_size; i++) + { + request.add_in_buffer2(in_buffer2[i]); + } + } + request.set_in_bufer3_size(in_buffer3_size); + if (in_buffer3_size > 0) + { + for (int i = 0; i < in_buffer3_size; i++) + { + request.add_in_buffer3(in_buffer3[i]); + } + } + request.set_in_bufer4_size(in_buffer4_size); + if (in_buffer4_size > 0) + { + for (int i = 0; i < in_buffer4_size; i++) + { + request.add_in_buffer4(in_buffer4[i]); + } + } + request.set_token(glo_token); + //questntainer for the data we expect from the server. + Invo_Reply reply; + ClientContext context; + retstru_teec_invokecommand rreply; + + // The actual RPC. + Status status = stub_->TEECC_InvokeCommand(&context, request, &reply); + retstru_teec_invokecommand error; + + rreply.teecresult = reply.teecresult(); + rreply.session_sessionid = reply.session_sessionid(); + rreply.session_serviceid_timelow = reply.session_serviceid_timelow(); + rreply.session_serviceid_timemid = reply.session_serviceid_timemid(); + rreply.session_serviceid_timehiandver = reply.session_serviceid_timehiandver(); + rreply.session_serviceid_clockseqandnode_outsize = reply.session_serviceid_clockseqandnode_outsize(); + if (rreply.session_serviceid_clockseqandnode_outsize > 0) + { + rreply.session_serviceid_clockseqandnode = new uint8_t[rreply.session_serviceid_clockseqandnode_outsize]; + for (int i = 0; i < rreply.session_serviceid_clockseqandnode_outsize; i++) + { + rreply.session_serviceid_clockseqandnode[i] = reply.session_serviceid_clockseqandnode(i); + } + } + rreply.session_opscnt = reply.session_opscnt(); + rreply.session_head_next = reply.session_head_next(); + rreply.session_head_prev = reply.session_head_prev(); + rreply.session_context = reply.session_context(); + rreply.operation_started = reply.operation_started(); + rreply.operation_paramtypes = reply.operation_paramtypes(); + rreply.operation_param1_tmpref_buffer = reply.operation_param1_tmpref_buffer(); + rreply.operation_param1_tmpref_size = reply.operation_param1_tmpref_size(); + rreply.operation_param1_memref_parent = reply.operation_param1_memref_parent(); + rreply.operation_param1_memref_parent_flag = reply.operation_param1_memref_parent_flag(); + rreply.operation_param1_memref_size = reply.operation_param1_memref_size(); + rreply.operation_param1_memref_offset = reply.operation_param1_memref_offset(); + rreply.operation_param1_value_a = reply.operation_param1_value_a(); + rreply.operation_param1_value_b = reply.operation_param1_value_b(); + rreply.operation_param1_ionref_ionsharefd = reply.operation_param1_ionref_ionsharefd(); + rreply.operation_param1_ionref_ionsize = reply.operation_param1_ionref_ionsize(); + + rreply.operation_param2_tmpref_buffer = reply.operation_param2_tmpref_buffer(); + rreply.operation_param2_tmpref_size = reply.operation_param2_tmpref_size(); + rreply.operation_param2_memref_parent = reply.operation_param2_memref_parent(); + rreply.operation_param2_memref_parent_flag = reply.operation_param2_memref_parent_flag(); + rreply.operation_param2_memref_size = reply.operation_param2_memref_size(); + rreply.operation_param2_memref_offset = reply.operation_param2_memref_offset(); + rreply.operation_param2_value_a = reply.operation_param2_value_a(); + rreply.operation_param2_value_b = reply.operation_param2_value_b(); + rreply.operation_param2_ionref_ionsharefd = reply.operation_param2_ionref_ionsharefd(); + rreply.operation_param2_ionref_ionsize = reply.operation_param2_ionref_ionsize(); + + rreply.operation_param3_tmpref_buffer = reply.operation_param3_tmpref_buffer(); + rreply.operation_param3_tmpref_size = reply.operation_param3_tmpref_size(); + rreply.operation_param3_memref_parent = reply.operation_param3_memref_parent(); + rreply.operation_param3_memref_parent_flag = reply.operation_param3_memref_parent_flag(); + rreply.operation_param3_memref_size = reply.operation_param3_memref_size(); + rreply.operation_param3_memref_offset = reply.operation_param3_memref_offset(); + rreply.operation_param3_value_a = reply.operation_param3_value_a(); + rreply.operation_param3_value_b = reply.operation_param3_value_b(); + rreply.operation_param3_ionref_ionsharefd = reply.operation_param3_ionref_ionsharefd(); + rreply.operation_param3_ionref_ionsize = reply.operation_param3_ionref_ionsize(); + + rreply.operation_param4_tmpref_buffer = reply.operation_param4_tmpref_buffer(); + rreply.operation_param4_tmpref_size = reply.operation_param4_tmpref_size(); + rreply.operation_param4_memref_parent = reply.operation_param4_memref_parent(); + rreply.operation_param4_memref_parent_flag = reply.operation_param4_memref_parent_flag(); + rreply.operation_param4_memref_size = reply.operation_param4_memref_size(); + rreply.operation_param4_memref_offset = reply.operation_param4_memref_offset(); + rreply.operation_param4_value_a = reply.operation_param4_value_a(); + rreply.operation_param4_value_b = reply.operation_param4_value_b(); + rreply.operation_param4_ionref_ionsharefd = reply.operation_param4_ionref_ionsharefd(); + rreply.operation_param4_ionref_ionsize = reply.operation_param4_ionref_ionsize(); + + rreply.operation_session = reply.operation_session(); + rreply.operation_cancelflag = reply.operation_cancelflag(); + rreply.returnorigin = reply.returnorigin(); + rreply.buffer1_outsize = reply.buffer1_outsize(); + if (rreply.buffer1_outsize > 0) + { + rreply.buffer1 = new uint8_t[rreply.buffer1_outsize]; + for (int i = 0; i < rreply.buffer1_outsize; i++) + { + rreply.buffer1[i] = reply.buffer1(i); + } + } + rreply.buffer2_outsize = reply.buffer2_outsize(); + if (rreply.buffer2_outsize > 0) + { + rreply.buffer2 = new uint8_t[rreply.buffer2_outsize]; + for (int i = 0; i < rreply.buffer2_outsize; i++) + { + rreply.buffer2[i] = reply.buffer2(i); + } + } + rreply.buffer3_outsize = reply.buffer3_outsize(); + if (rreply.buffer3_outsize > 0) + { + rreply.buffer3 = new uint8_t[rreply.buffer3_outsize]; + for (int i = 0; i < rreply.buffer3_outsize; i++) + { + rreply.buffer3[i] = reply.buffer3(i); + } + } + rreply.buffer4_outsize = reply.buffer4_outsize(); + if (rreply.buffer4_outsize > 0) + { + rreply.buffer4 = new uint8_t[rreply.buffer4_outsize]; + for (int i = 0; i < rreply.buffer4_outsize; i++) + { + rreply.buffer4[i] = reply.buffer4(i); + } + } + rreply.flag = reply.flag(); + + // Act upon its status. + if (status.ok()) + { + return rreply; + } else + { + std::cout << "libteec invokecommand grpc error: " << status.error_code() << ", " << status.error_message() + << std::endl; + return error; + } + } + + retstru_teec_closesession externc_teec_closesession( + std::uint32_t in_session_sessionid, + std::uint32_t in_session_serviceid_timelow, + std::uint32_t in_session_serviceid_timemid, + std::uint32_t in_session_serviceid_timehiandver, + std::uint8_t *in_session_serviceid_clockseqandnode, + std::uintptr_t in_session_serviceid_clockseqandnode_size, + std::uint32_t in_session_opscnt, + std::uint64_t in_session_head_next, + std::uint64_t in_session_head_prev, + std::uint64_t in_session_context + ) + { + Close_Request request; + + request.set_in_session_sessionid(in_session_sessionid); + request.set_in_session_serviceid_timelow(in_session_serviceid_timelow); + request.set_in_session_serviceid_timemid(in_session_serviceid_timemid); + request.set_in_session_serviceid_timehiandver(in_session_serviceid_timehiandver); + request.set_in_session_serviceid_cad_size(in_session_serviceid_clockseqandnode_size); + if (in_session_serviceid_clockseqandnode_size > 0) + { + for (int i = 0; i < in_session_serviceid_clockseqandnode_size; i++) + { + request.add_in_session_serviceid_clockseqandnode(in_session_serviceid_clockseqandnode[i]); + } + } + request.set_in_session_opscnt(in_session_opscnt); + request.set_in_session_head_next(in_session_head_next); + request.set_in_session_head_prev(in_session_head_prev); + request.set_in_session_context(in_session_context); + request.set_token(glo_token); + + Close_Reply reply; + ClientContext context; + retstru_teec_closesession rreply; + // The actual RPC. + Status status = stub_->TEECC_CloseSession(&context, request, &reply); + retstru_teec_closesession error; + + rreply.session_sessionid = reply.session_sessionid(); + rreply.session_serviceid_timelow = reply.session_serviceid_timelow(); + rreply.session_serviceid_timemid = reply.session_serviceid_timemid(); + rreply.session_serviceid_timehiandver = reply.session_serviceid_timehiandver(); + rreply.session_serviceid_clockseqandnode_outsize = reply.session_serviceid_cad_outsize(); + + if (rreply.session_serviceid_clockseqandnode_outsize > 0) + { + rreply.session_serviceid_clockseqandnode = new uint8_t[rreply.session_serviceid_clockseqandnode_outsize]; + for (int i = 0; i < rreply.session_serviceid_clockseqandnode_outsize; i++) + { + rreply.session_serviceid_clockseqandnode[i] = reply.session_serviceid_clockseqandnode(i); + } + } + + rreply.session_opscnt = reply.session_opscnt(); + rreply.session_head_next = reply.session_head_next(); + rreply.session_head_prev = reply.session_head_prev(); + rreply.session_context = reply.session_context(); + rreply.flag = reply.flag(); + + // Act upon its status. + if (status.ok()) + { + return rreply; + } else + { + std::cout << "libteec closesession grpc error: " << status.error_code() << ", " << status.error_message() + << std::endl; + return error; + } + } + + + int + Upload( + std::string infile_path, + std::string subdir, + std::string outfile_name + ) + { + TA_Chunk chunk; + TA_Reply stats; + ClientContext context; + const char *filename = infile_path.data(); + std::ifstream infile; + int retcode = 0; + + struct timeval start, end; + gettimeofday(&start, NULL); + + infile.open(filename, std::ifstream::in | std::ifstream::binary); + if (!infile) + { + return TEEC_INFILE_NOT_FOUND; + } + + long beginoffset, endoffset; + beginoffset = infile.tellg(); + infile.seekg(0, std::ios::end); + endoffset = infile.tellg(); + long filesize = endoffset - beginoffset; + infile.seekg(0, std::ios::beg); + char *data = new char[filesize]; + infile.read(data, filesize); + + chunk.set_buffer(data, infile.gcount()); + + delete[]data; + infile.close(); + + if (subdir.empty()) + { + std::string strsubdirdefault("default"); + chunk.set_subdir(strsubdirdefault); + } else + { + bool bResult; + bResult = utf8_check_is_valid(subdir); + if (bResult == false) + { + return TEEC_FAIL; + } + + chunk.set_subdir(subdir); + } + + std::string stroutname; + std::string infile_path_temp = infile_path; + if (outfile_name.empty()) + { + char *filenametemp = const_cast(infile_path_temp.data()); + const char slash[] = "/"; + char *nametemp = strtok(filenametemp, slash); + while (nametemp != NULL) + { + stroutname = std::string(nametemp); + nametemp = strtok(NULL, slash); + } + chunk.set_name(stroutname); + } else + { + chunk.set_name(outfile_name); + } + + chunk.set_token(glo_token); + + char sha256[SHA256_LENTH]; + int iRet; + iRet = get_file_sha256((char *) filename, sha256); + if (iRet != 0) + { + return TEEC_FAIL; + } + + chunk.set_sha256(sha256, SHA256_LENTH); + + Status status = stub_->TEECC_TA(&context, chunk, &stats); + + + if (status.ok()) + { + retcode = stats.code(); + + if (stats.code() == 0) + { + retcode = 0; + } else if (stats.code() == -1) + { + std::cout << "libteeccc: deployta jwt validate error" << std::endl; + retcode = TEEC_ERROR_JWTVALIDATE_FAIL; + } else + { + retcode = TEEC_FAIL; + } + } else + { + std::cout << "libteec deployta grpc error: " << status.error_code() << ", " + << status.error_message() << std::endl; + retcode = TEEC_FAIL; + } + + return retcode; + } + + // Out of the passed in Channel comes the stub, stored here, our view of the + // server's exposed services. + std::unique_ptr stub_; +}; + + +static GppClient *client = NULL; +std::shared_ptr gpp_channel = NULL; + + +std::string global_strcfgfiletemp = getenv("HOME"); +std::string global_strcfgfile = global_strcfgfiletemp + "/.teecc/teecc_config.yaml"; +YAML::Node glo_config = YAML::LoadFile(global_strcfgfile); +std::string global_target_str = glo_config["GPPROXY_ADDRESS"].as(); +std::string global_servercacert_path = global_strcfgfiletemp + "/.teecc/certs/" + glo_config["NAME_SERVERCA_CERT"].as(); +std::string global_clientkey_path = global_strcfgfiletemp + "/.teecc/certs/" + glo_config["NAME_CLIENT_KEY"].as(); +std::string global_clientcert_path = global_strcfgfiletemp + "/.teecc/certs/" + glo_config["NAME_CLIENT_CERT"].as(); +int grpc_tls = glo_config["GRPC_TLS"].as(); + + +int64_t glob_scontaddr; + +bool isFileExists_ifstream(std::string &name) +{ + std::ifstream f(name.c_str()); + return f.good(); +} + +static std::string get_file_contents(std::string fpath) +{ + std::ifstream finstream(fpath); + std::string contents; + contents.assign((std::istreambuf_iterator(finstream)), + std::istreambuf_iterator()); + finstream.close(); + return contents; +} + + +TEEC_Result +TEEC_InitializeContext(const char *name, TEEC_Context *context) +{ + if (gpp_channel == NULL) + { + int igrpctls = grpc_tls; + + if (grpc_tls != 0 && grpc_tls != 1 && grpc_tls != 2) + { + std::cout << global_strcfgfile << " grpc_tls should be 0 or 1 or 2 " << std::endl; + return TEEC_FAIL; + } + + switch (igrpctls) + { + case 0: + { + gpp_channel = grpc::CreateChannel(global_target_str, grpc::InsecureChannelCredentials()); + + break; + } + + case 1: + { + if (!isFileExists_ifstream(global_servercacert_path)) + { + std::cout << "error file : " << global_servercacert_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + + std::string strcmd; + FILE *pipe; + char buffer[128]; + std::string result; + + std::string strdayseconds; + char *resulttemp; + const char slash[] = "\n"; + char *parresult; + std::string strparresult; + std::string willexpire("Certificate will expire"); + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_servercacert_path + " -checkend " + strdayseconds; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "gpp '" << global_servercacert_path << "' will expire in 7 days, please reget it" << std::endl; + return TEEC_FAIL; + } + + auto servercacert = get_file_contents(global_servercacert_path); + grpc::SslCredentialsOptions ssl_opts; + ssl_opts.pem_root_certs = servercacert; + std::shared_ptr creds = grpc::SslCredentials(ssl_opts); + gpp_channel = grpc::CreateChannel(global_target_str, creds); + + break; + } + + case 2: + { + if (!isFileExists_ifstream(global_servercacert_path)) + { + std::cout << "error file : " << global_servercacert_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + if (!isFileExists_ifstream(global_clientkey_path)) + { + std::cout << "error file : " << global_clientkey_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + if (!isFileExists_ifstream(global_clientcert_path)) + { + std::cout << "error file : " << global_clientcert_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + + std::string strcmd; + FILE *pipe; + char buffer[128]; + std::string result; + + std::string strdayseconds; + char *resulttemp; + const char slash[] = "\n"; + char *parresult; + std::string strparresult; + std::string willexpire("Certificate will expire"); + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_servercacert_path + " -checkend " + strdayseconds; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "libteecc '" << global_servercacert_path << "' will expire in 7 days, please reget it" + << std::endl; + return TEEC_FAIL; + } + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_clientcert_path + " -checkend " + strdayseconds; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "libteecc '" << global_clientcert_path << "' will expire in 7 days, please reget it" << std::endl; + return TEEC_FAIL; + } + + strcmd = "openssl rsa -in " + global_clientkey_path + " -out " + + global_clientkey_path + ".nopass"; + std::string nopass_clientkey_path = global_clientkey_path + ".nopass"; + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + + strcmd = "openssl rsa -in " + nopass_clientkey_path + " -check -noout"; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + std::string keyok("RSA key ok\n"); + if (result.compare(keyok) != 0) + { + std::cout << "libteecc '" + global_clientkey_path + "' integrity is broken" << std::endl; + return TEEC_FAIL; + } + + std::string sigfile_path = global_strcfgfiletemp + "/.teecc/certs/msg.sig"; + std::string msgfile_path = global_strcfgfiletemp + "/.teecc/certs/msg.txt"; + strcmd = + "openssl dgst -sha256 -sign " + nopass_clientkey_path + " -out " + sigfile_path + " " + msgfile_path; + system(strcmd.c_str()); + // ${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + std::string pubkeyfile_path = global_strcfgfiletemp + "/.teecc/certs/client_pubkey.pem"; + strcmd = "openssl x509 -in " + global_clientcert_path + " -pubkey -out " + pubkeyfile_path; + system(strcmd.c_str()); + + // ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt + strcmd = "openssl dgst -sha256 -verify " + pubkeyfile_path + " -signature " + sigfile_path + " " + + msgfile_path; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + // std::cout << "gpp popen " << strcmd << " succed, result: " << result < creds = grpc::SslCredentials(ssl_opts); + gpp_channel = grpc::CreateChannel(global_target_str, creds); + + break; + } + + default: + { + gpp_channel = grpc::CreateChannel(global_target_str, grpc::InsecureChannelCredentials()); + } + } + + client = new GppClient( + gpp_channel + ); + } + + std::uint8_t *name_temp = NULL; + std::uint32_t name_size; + struct retstru_teec_inicont rs_inicont_ins; + + if (name != NULL) + { + name_temp = (uint8_t *) name; + name_size = strlen(name); + } else + { + name_size = 0; + } + + if (context == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + rs_inicont_ins = client->externc_teec_initializecontext(name_temp, + name_size + ); + if (rs_inicont_ins.flag == 1) + { + std::cout << "libteecc: inicont token null" << std::endl; + + return TEEC_ERROR_BAD_PARAMETERS; + } + if (rs_inicont_ins.flag == 2) + { + std::cout << "libteecc: inicont jwt validate error" << std::endl; + return TEEC_ERROR_BAD_PARAMETERS; + } + + if (rs_inicont_ins.teecresult == TEEC_SUCCESS) + { + context->fd = rs_inicont_ins.context_fd; + + if ( + rs_inicont_ins.context_tapath_outsize > 0 && + rs_inicont_ins.context_tapath != NULL + ) + { + if (context->ta_path == NULL) + { + return TEEC_ERROR_CONTEXT_TAPATH_NULL; + } else + { + memcpy( + context->ta_path, + rs_inicont_ins.context_tapath, + rs_inicont_ins.context_tapath_outsize + ); + *(context->ta_path + rs_inicont_ins.context_tapath_outsize) = 0; + } + } else + { + context->ta_path = NULL; + } + context->session_list.next = (struct ListNode *) rs_inicont_ins.context_sessionlist_next; + context->session_list.prev = (struct ListNode *) rs_inicont_ins.context_sessionlist_prev; + context->shrd_mem_list.next = (struct ListNode *) rs_inicont_ins.context_shrdmemlist_next; + context->shrd_mem_list.prev = (struct ListNode *) rs_inicont_ins.context_shrdmemlist_prev; + context->share_buffer.buffer = (void *) rs_inicont_ins.context_sharebuffer_buffer; + context->share_buffer.buffer_barrier.__align = rs_inicont_ins.context_sharebuffer_bufferbarrier; + glob_scontaddr = rs_inicont_ins.context_addr; + } + return static_cast(rs_inicont_ins.teecresult); +} + +void +TEEC_FinalizeContext(TEEC_Context *context) +{ + std::int32_t in_context_fd; + std::uint8_t *in_context_tapath; + std::int32_t in_context_tapath_size; + std::uint64_t in_context_sessionlist_next; + std::uint64_t in_context_sessionlist_prev; + std::uint64_t in_context_shrdmemlist_next; + std::uint64_t in_context_shrdmemlist_prev; + std::uint64_t in_context_sharebuffer_buffer; + std::int64_t in_context_sharebuffer_bufferbarrier; + struct retstru_teec_fincont rs_fincont_ins; + + + if (gpp_channel == NULL) + { + std::cout << "libteecc: the grpc client or channel is null, when executing TEEC_FinalizeContext." << std::endl; + return; + } + + if (context == NULL) + { + return; + } + + in_context_fd = context->fd; + in_context_tapath = context->ta_path; + if (in_context_tapath == NULL) + { + in_context_tapath_size = 0; + } else + { + std::string strtmp((char *) in_context_tapath); + bool bResult; + bResult = utf8_check_is_valid(strtmp); + if (bResult == true) + { + in_context_tapath_size = strtmp.length(); + } else + { + in_context_tapath_size = 0; + } + } + in_context_sessionlist_next = (uint64_t) context->session_list.next; + in_context_sessionlist_prev = (uint64_t) context->session_list.prev; + in_context_shrdmemlist_next = (uint64_t) context->shrd_mem_list.next; + in_context_shrdmemlist_prev = (uint64_t) context->shrd_mem_list.prev; + in_context_sharebuffer_buffer = (uint64_t) context->share_buffer.buffer; + in_context_sharebuffer_bufferbarrier = context->share_buffer.buffer_barrier.__align; + + rs_fincont_ins = client->externc_teec_finalizecontext(in_context_fd, + in_context_tapath, + in_context_tapath_size, + in_context_sessionlist_next, + in_context_sessionlist_prev, + in_context_shrdmemlist_next, + in_context_shrdmemlist_prev, + in_context_sharebuffer_buffer, + in_context_sharebuffer_bufferbarrier, + glob_scontaddr); + if (rs_fincont_ins.flag == 1) + { + std::cout << "libteecc: fincont token null" << std::endl; + return; + } + if (rs_fincont_ins.flag == 2) + { + std::cout << "libteecc: fincont jwt validate error" << std::endl; + return; + } +#if 0 + std::cout << "externc_teec_finalizecontext: " << std::endl; + std::cout << "gpp reply context_fd: " << rs_fincont_ins.context_fd < 0){ + std::cout << "gpp reply context_tapath: " << rs_fincont_ins.context_tapath <fd = rs_fincont_ins.context_fd; + if ( + rs_fincont_ins.context_tapath_outsize > 0 && + rs_fincont_ins.context_tapath != NULL + ) + { + if (context->ta_path == NULL) + { + return; + } + } + context->session_list.next = (struct ListNode *) rs_fincont_ins.context_sessionlist_next; + context->session_list.prev = (struct ListNode *) rs_fincont_ins.context_sessionlist_prev; + context->shrd_mem_list.next = (struct ListNode *) rs_fincont_ins.context_shrdmemlist_next; + context->shrd_mem_list.prev = (struct ListNode *) rs_fincont_ins.context_shrdmemlist_prev; + context->share_buffer.buffer = (void *) rs_fincont_ins.context_sharebuffer_buffer; + context->share_buffer.buffer_barrier.__align = rs_fincont_ins.context_sharebuffer_bufferbarrier; + + gpp_channel.reset(); + delete gpp_channel.get(); + delete client; +} + +TEEC_Result +TEEC_OpenSession(TEEC_Context *context, + TEEC_Session *session, + const TEEC_UUID *destination, + uint32_t connectionMethod, + const void *connectionData, + TEEC_Operation *operation, + uint32_t *returnOrigin +) +{ + + std::int32_t in_context_fd; + std::uint8_t *in_context_tapath; + std::int32_t in_context_tapath_size; + std::uint64_t in_context_sessionlist_next; + std::uint64_t in_context_sessionlist_prev; + std::uint64_t in_context_shrdmemlist_next; + std::uint64_t in_context_shrdmemlist_prev; + std::uint64_t in_context_sharebuffer_buffer; + std::int64_t in_context_sharebuffer_bufferbarrier; + + if (gpp_channel == NULL) + { + std::cout << "libteecc: the grpc client or channel is null, when executing TEEC_OpenSession." << std::endl; + return TEEC_ERROR_GRPC_ERROR; + } + + if (context == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + if (session == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + if (destination == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + in_context_fd = context->fd; + in_context_tapath = context->ta_path; + + if (in_context_tapath == NULL) + { + in_context_tapath_size = 0; + } else + { + in_context_tapath_size = strlen((const char *) in_context_tapath); + } + in_context_sessionlist_next = (uint64_t) context->session_list.next; + in_context_sessionlist_prev = (uint64_t) context->session_list.prev; + in_context_shrdmemlist_next = (uint64_t) context->shrd_mem_list.next; + in_context_shrdmemlist_prev = (uint64_t) context->shrd_mem_list.prev; + in_context_sharebuffer_buffer = (uint64_t) context->share_buffer.buffer; + in_context_sharebuffer_bufferbarrier = context->share_buffer.buffer_barrier.__align; + + uint32_t in_destination_timelow; + uint32_t in_destination_timemid; + uint32_t in_destination_timehiandver; + uint8_t in_destination_clockseqandnode[8]; + int32_t in_destination_clockseqandnode_size; + + uint32_t in_connectionmethod; + uint64_t in_connectiondata; + + uint32_t in_operation_started; + uint32_t in_operation_paramtypes; + + uint64_t in_operation_param1_tmpref_buffer; + uint32_t in_operation_param1_tmpref_size; + uint64_t in_operation_param1_memref_parent; + uint32_t in_operation_param1_memref_size; + uint32_t in_operation_param1_memref_offset; + uint32_t in_operation_param1_value_a; + uint32_t in_operation_param1_value_b; + int32_t in_operation_param1_ionref_ionsharefd; + uint32_t in_operation_param1_ionref_ionsize; + + uint64_t in_operation_param2_tmpref_buffer; + uint32_t in_operation_param2_tmpref_size; + uint64_t in_operation_param2_memref_parent; + uint32_t in_operation_param2_memref_size; + uint32_t in_operation_param2_memref_offset; + uint32_t in_operation_param2_value_a; + uint32_t in_operation_param2_value_b; + int32_t in_operation_param2_ionref_ionsharefd; + uint32_t in_operation_param2_ionref_ionsize; + + uint64_t in_operation_param3_tmpref_buffer; + uint32_t in_operation_param3_tmpref_size; + uint64_t in_operation_param3_memref_parent; + uint32_t in_operation_param3_memref_size; + uint32_t in_operation_param3_memref_offset; + uint32_t in_operation_param3_value_a; + uint32_t in_operation_param3_value_b; + int32_t in_operation_param3_ionref_ionsharefd; + uint32_t in_operation_param3_ionref_ionsize; + + uint64_t in_operation_param4_tmpref_buffer; + uint32_t in_operation_param4_tmpref_size; + uint64_t in_operation_param4_memref_parent; + uint32_t in_operation_param4_memref_size; + uint32_t in_operation_param4_memref_offset; + uint32_t in_operation_param4_value_a; + uint32_t in_operation_param4_value_b; + int32_t in_operation_param4_ionref_ionsharefd; + uint32_t in_operation_param4_ionref_ionsize; + + uint64_t in_operation_session; + int32_t in_operation_cancelflag; + + uint32_t in_returnorigin; + + struct retstru_teec_opensession rs_opensession_ins; + + + in_destination_timelow = destination->timeLow; + in_destination_timemid = destination->timeMid; + in_destination_timehiandver = destination->timeHiAndVersion; + for (int i = 0; i < 8; i++) + { + in_destination_clockseqandnode[i] = destination->clockSeqAndNode[i]; + } + in_destination_clockseqandnode_size = 8; + + in_connectionmethod = connectionMethod; + in_connectiondata = (uint64_t) connectionData; + + in_operation_started = operation->started; + in_operation_paramtypes = operation->paramTypes; + + in_operation_param1_tmpref_buffer = (uint64_t) operation->params[0].tmpref.buffer; + in_operation_param1_tmpref_size = operation->params[0].tmpref.size; + in_operation_param1_memref_parent = (uint64_t) operation->params[0].memref.parent; + in_operation_param1_memref_size = operation->params[0].memref.size; + in_operation_param1_memref_offset = operation->params[0].memref.offset; + in_operation_param1_value_a = operation->params[0].value.a; + in_operation_param1_value_b = operation->params[0].value.b; + in_operation_param1_ionref_ionsharefd = operation->params[0].ionref.ion_share_fd; + in_operation_param1_ionref_ionsize = operation->params[0].ionref.ion_size; + + in_operation_param2_tmpref_buffer = (uint64_t) operation->params[1].tmpref.buffer; + in_operation_param2_tmpref_size = operation->params[1].tmpref.size; + in_operation_param2_memref_parent = (uint64_t) operation->params[1].memref.parent; + in_operation_param2_memref_size = operation->params[1].memref.size; + in_operation_param2_memref_offset = operation->params[1].memref.offset; + in_operation_param2_value_a = operation->params[1].value.a; + in_operation_param2_value_b = operation->params[1].value.b; + in_operation_param2_ionref_ionsharefd = operation->params[1].ionref.ion_share_fd; + in_operation_param2_ionref_ionsize = operation->params[1].ionref.ion_size; + + in_operation_param3_tmpref_buffer = (uint64_t) operation->params[2].tmpref.buffer; + in_operation_param3_tmpref_size = operation->params[2].tmpref.size; + in_operation_param3_memref_parent = (uint64_t) operation->params[2].memref.parent; + in_operation_param3_memref_size = operation->params[2].memref.size; + in_operation_param3_memref_offset = operation->params[2].memref.offset; + in_operation_param3_value_a = operation->params[2].value.a; + in_operation_param3_value_b = operation->params[2].value.b; + in_operation_param3_ionref_ionsharefd = operation->params[2].ionref.ion_share_fd; + in_operation_param3_ionref_ionsize = operation->params[2].ionref.ion_size; + + in_operation_param4_tmpref_buffer = (uint64_t) operation->params[3].tmpref.buffer; + in_operation_param4_tmpref_size = operation->params[3].tmpref.size; + in_operation_param4_memref_parent = (uint64_t) operation->params[3].memref.parent; + in_operation_param4_memref_size = operation->params[3].memref.size; + in_operation_param4_memref_offset = operation->params[3].memref.offset; + in_operation_param4_value_a = operation->params[3].value.a; + in_operation_param4_value_b = operation->params[3].value.b; + in_operation_param4_ionref_ionsharefd = operation->params[3].ionref.ion_share_fd; + in_operation_param4_ionref_ionsize = operation->params[3].ionref.ion_size; + + in_operation_session = (uint64_t) operation->session; + in_operation_cancelflag = operation->cancel_flag; + + in_returnorigin = *returnOrigin; + + rs_opensession_ins = + client->externc_teec_opensession( + in_context_fd, + in_context_tapath, + in_context_tapath_size, + in_context_sessionlist_next, + in_context_sessionlist_prev, + in_context_shrdmemlist_next, + in_context_shrdmemlist_prev, + in_context_sharebuffer_buffer, + in_context_sharebuffer_bufferbarrier, + + in_destination_timelow, + in_destination_timemid, + in_destination_timehiandver, + in_destination_clockseqandnode, + in_destination_clockseqandnode_size, + + in_connectionmethod, + in_connectiondata, + + in_operation_started, + in_operation_paramtypes, + + in_operation_param1_tmpref_buffer, + in_operation_param1_tmpref_size, + in_operation_param1_memref_parent, + in_operation_param1_memref_size, + in_operation_param1_memref_offset, + in_operation_param1_value_a, + in_operation_param1_value_b, + in_operation_param1_ionref_ionsharefd, + in_operation_param1_ionref_ionsize, + + in_operation_param2_tmpref_buffer, + in_operation_param2_tmpref_size, + in_operation_param2_memref_parent, + in_operation_param2_memref_size, + in_operation_param2_memref_offset, + in_operation_param2_value_a, + in_operation_param2_value_b, + in_operation_param2_ionref_ionsharefd, + in_operation_param2_ionref_ionsize, + + in_operation_param3_tmpref_buffer, + in_operation_param3_tmpref_size, + in_operation_param3_memref_parent, + in_operation_param3_memref_size, + in_operation_param3_memref_offset, + in_operation_param3_value_a, + in_operation_param3_value_b, + in_operation_param3_ionref_ionsharefd, + in_operation_param3_ionref_ionsize, + + in_operation_param4_tmpref_buffer, + in_operation_param4_tmpref_size, + in_operation_param4_memref_parent, + in_operation_param4_memref_size, + in_operation_param4_memref_offset, + in_operation_param4_value_a, + in_operation_param4_value_b, + in_operation_param4_ionref_ionsharefd, + in_operation_param4_ionref_ionsize, + + in_operation_session, + in_operation_cancelflag, + in_returnorigin, + glob_scontaddr + ); + if (rs_opensession_ins.flag == 1) + { + std::cout << "libteecc: opensession token null" << std::endl; + return TEEC_ERROR_BAD_PARAMETERS; + } + if (rs_opensession_ins.flag == 2) + { + std::cout << "libteecc: opensession jwt validate error" << std::endl; + return TEEC_ERROR_BAD_PARAMETERS; + } + +#if 0 + std::cout << "externc_teec_opensession:" << std::endl; + std::cout << "gpp request in_context_fd: 0x " << std::hex << std::setfill('0') << std::setw(8) << in_context_fd + << std::endl; + std::cout << "gpp request in_context_addr: 0x" << std::hex << std::setfill('0') << std::setw(8) + << (unsigned long) glob_scontaddr << std::endl; + std::cout << "gpp reply teecresult: " << std::hex << std::setfill('0') << std::setw(8) + << rs_opensession_ins.teecresult << std::endl; + std::cout << "gpp reply context_fd: " << std::hex << std::setfill('0') << std::setw(8) + << rs_opensession_ins.context_fd << std::endl; + + if ( + rs_opensession_ins.context_tapath_outsize > 0 + && + rs_opensession_ins.context_tapath != NULL + ) + { + std::cout << "gpp reply context_tapath: " << rs_opensession_ins.context_tapath << std::endl; + } + printf("gpp reply context_tapath outsize = %ld\n", + rs_opensession_ins.context_tapath_outsize); +#endif + +#if 0 + printf("ret context_sessionlist_next = 0x %16.16lx\n", + rs_opensession_ins.context_sessionlist_next); + printf("ret context_sessionlist_prev = 0x %16.16lx\n", + rs_opensession_ins.context_sessionlist_prev); + printf("ret context_shrdmemlist_next = 0x %16.16lx\n", + rs_opensession_ins.context_shrdmemlist_next); + printf("ret context_shrdmemlist_prev = 0x %16.16lx\n", + rs_opensession_ins.context_shrdmemlist_prev); + printf("ret context_sharebuffer_buffer = 0x %16.16lx\n", + rs_opensession_ins.context_sharebuffer_buffer); + printf("ret context_sharebuffer_bufferbarrier = 0x %16.16lx\n", + (long unsigned int) rs_opensession_ins.context_sharebuffer_bufferbarrier); +#endif + +#if 0 + std::cout << "gpp reply session_sessionid: 0x " << std::hex << std::setfill('0') << std::setw(8) + << rs_opensession_ins.session_sessionid << std::endl; +#endif + +#if 0 + printf("ret session_serviceid_timelow = 0x %8.8x\n", + rs_opensession_ins.session_serviceid_timelow); + printf("ret session_serviceid_timemid = 0x %8.8x\n", + rs_opensession_ins.session_serviceid_timemid); + printf("ret session_serviceid_timehiandver = 0x %8.8x\n", + rs_opensession_ins.session_serviceid_timehiandver); + if ( + rs_opensession_ins.session_serviceid_clockseqandnode_outsize > 0 + && + rs_opensession_ins.session_serviceid_clockseqandnode != NULL + ) { + printf("ret session_serviceid_clockseqandnode = \n"); + for (uintptr_t uisize = 0; + uisize < rs_opensession_ins.session_serviceid_clockseqandnode_outsize; + uisize++) { + printf(" %2.2x", *(rs_opensession_ins.session_serviceid_clockseqandnode + uisize)); + } + printf("\n"); + } else { + printf("ret clockseqandnode addr = 0x %16.16lx\n", + (unsigned long) rs_opensession_ins.session_serviceid_clockseqandnode); + } + printf("ret clockseqandnode_outsize = %ld\n", + rs_opensession_ins.session_serviceid_clockseqandnode_outsize); + printf("ret session_opscnt = 0x %8.8x\n", + rs_opensession_ins.session_opscnt); + printf("ret session_head_next = 0x %16.16lx\n", + rs_opensession_ins.session_head_next); + printf("ret session_head_prev = 0x %16.16lx\n", + rs_opensession_ins.session_head_prev); +#endif + +#if 0 + std::cout << "gpp reply session_context: 0x " << std::hex << std::setfill('0') << std::setw(16) + << rs_opensession_ins.session_context << std::endl; +#endif + if (rs_opensession_ins.teecresult == TEEC_SUCCESS) + { + context->fd = rs_opensession_ins.context_fd; + + if ( + rs_opensession_ins.context_tapath_outsize > 0 && + rs_opensession_ins.context_tapath != NULL + ) + { + if (context->ta_path == NULL) + { + return TEEC_ERROR_CONTEXT_TAPATH_NULL; + } + } + context->session_list.next = (struct ListNode *) rs_opensession_ins.context_sessionlist_next; + context->session_list.prev = (struct ListNode *) rs_opensession_ins.context_sessionlist_prev; + context->shrd_mem_list.next = (struct ListNode *) rs_opensession_ins.context_shrdmemlist_next; + context->shrd_mem_list.prev = (struct ListNode *) rs_opensession_ins.context_shrdmemlist_prev; + context->share_buffer.buffer = (void *) rs_opensession_ins.context_sharebuffer_buffer; + context->share_buffer.buffer_barrier.__align = rs_opensession_ins.context_sharebuffer_bufferbarrier; + + session->session_id = rs_opensession_ins.session_sessionid; + session->service_id.timeLow = rs_opensession_ins.session_serviceid_timelow; + session->service_id.timeMid = rs_opensession_ins.session_serviceid_timemid; + session->service_id.timeHiAndVersion = rs_opensession_ins.session_serviceid_timehiandver; + + if (rs_opensession_ins.session_serviceid_clockseqandnode_outsize <= 8 && + rs_opensession_ins.session_serviceid_clockseqandnode_outsize > 0 && + rs_opensession_ins.session_serviceid_clockseqandnode != NULL && + session->service_id.clockSeqAndNode != NULL + ) + { + for (int i = 0; i < rs_opensession_ins.session_serviceid_clockseqandnode_outsize; i++) + { + session->service_id.clockSeqAndNode[i] = + (uint8_t)(rs_opensession_ins.session_serviceid_clockseqandnode[i] & 0x000000ff); + } + } else + { + for (int i = 0; i < 8; i++) + { + session->service_id.clockSeqAndNode[i] = 0; + } + } + session->ops_cnt = rs_opensession_ins.session_opscnt; + session->head.next = (struct ListNode *) rs_opensession_ins.session_head_next; + session->head.prev = (struct ListNode *) rs_opensession_ins.session_head_prev; + session->context = (TEEC_Context *) rs_opensession_ins.session_context; + + + operation->started = rs_opensession_ins.operation_started; + operation->paramTypes = rs_opensession_ins.operation_paramtypes; + +#if 0 + uint32_t * buffer1_temp = NULL; + if ( + (rs_opensession_ins.operation_paramtypes & 0x000000ff) == TEEC_MEMREF_TEMP_OUTPUT || + (rs_opensession_ins.operation_paramtypes & 0x000000ff) == TEEC_MEMREF_TEMP_INOUT + ) + { + if (operation->params[0].tmpref.buffer == NULL) + { + externc_retstru_teec_opensession_free(rs_opensession_ins); + return TEEC_ERROR_PARAM0_TEMPMEM_NULL; + } + } +#endif + + operation->params[0].tmpref.buffer = (void *) rs_opensession_ins.operation_param1_tmpref_buffer; + operation->params[0].tmpref.size = rs_opensession_ins.operation_param1_tmpref_size; + operation->params[0].memref.parent = + (TEEC_SharedMemory *) rs_opensession_ins.operation_param1_memref_parent; + operation->params[0].memref.size = rs_opensession_ins.operation_param1_memref_size; + operation->params[0].memref.offset = rs_opensession_ins.operation_param1_memref_offset; + operation->params[0].value.a = rs_opensession_ins.operation_param1_value_a; + operation->params[0].value.b = rs_opensession_ins.operation_param1_value_b; + operation->params[0].ionref.ion_share_fd = rs_opensession_ins.operation_param1_ionref_ionsharefd; + operation->params[0].ionref.ion_size = rs_opensession_ins.operation_param1_ionref_ionsize; + + operation->params[1].tmpref.buffer = (void *) rs_opensession_ins.operation_param2_tmpref_buffer; + operation->params[1].tmpref.size = rs_opensession_ins.operation_param2_tmpref_size; + operation->params[1].memref.parent = + (TEEC_SharedMemory *) rs_opensession_ins.operation_param2_memref_parent; + operation->params[1].memref.size = rs_opensession_ins.operation_param2_memref_size; + operation->params[1].memref.offset = rs_opensession_ins.operation_param2_memref_offset; + operation->params[1].value.a = rs_opensession_ins.operation_param2_value_a; + operation->params[1].value.b = rs_opensession_ins.operation_param2_value_b; + operation->params[1].ionref.ion_share_fd = rs_opensession_ins.operation_param2_ionref_ionsharefd; + operation->params[1].ionref.ion_size = rs_opensession_ins.operation_param2_ionref_ionsize; + + operation->params[2].tmpref.buffer = (void *) rs_opensession_ins.operation_param3_tmpref_buffer; + operation->params[2].tmpref.size = rs_opensession_ins.operation_param3_tmpref_size; + operation->params[2].memref.parent = + (TEEC_SharedMemory *) rs_opensession_ins.operation_param3_memref_parent; + operation->params[2].memref.size = rs_opensession_ins.operation_param3_memref_size; + operation->params[2].memref.offset = rs_opensession_ins.operation_param3_memref_offset; + operation->params[2].value.a = rs_opensession_ins.operation_param3_value_a; + operation->params[2].value.b = rs_opensession_ins.operation_param3_value_b; + operation->params[2].ionref.ion_share_fd = rs_opensession_ins.operation_param3_ionref_ionsharefd; + operation->params[2].ionref.ion_size = rs_opensession_ins.operation_param3_ionref_ionsize; + + operation->params[3].tmpref.buffer = (void *) rs_opensession_ins.operation_param4_tmpref_buffer; + operation->params[3].tmpref.size = rs_opensession_ins.operation_param4_tmpref_size; + operation->params[3].memref.parent = + (TEEC_SharedMemory *) rs_opensession_ins.operation_param4_memref_parent; + operation->params[3].memref.size = rs_opensession_ins.operation_param4_memref_size; + operation->params[3].memref.offset = rs_opensession_ins.operation_param4_memref_offset; + operation->params[3].value.a = rs_opensession_ins.operation_param4_value_a; + operation->params[3].value.b = rs_opensession_ins.operation_param4_value_b; + operation->params[3].ionref.ion_share_fd = rs_opensession_ins.operation_param4_ionref_ionsharefd; + operation->params[3].ionref.ion_size = rs_opensession_ins.operation_param4_ionref_ionsize; + + operation->session = (TEEC_Session *) rs_opensession_ins.operation_session; + operation->cancel_flag = rs_opensession_ins.operation_cancelflag; + + *returnOrigin = in_returnorigin; + } + return static_cast(rs_opensession_ins.teecresult); +} + +extern +TEEC_Result +TEEC_InvokeCommand(TEEC_Session *session, + uint32_t commandID, + TEEC_Operation *operation, + uint32_t *returnOrigin +) +{ + uint32_t in_session_sessionid; + uint32_t in_session_serviceid_timelow; + uint32_t in_session_serviceid_timemid; + uint32_t in_session_serviceid_timehiandver; + uint8_t in_session_serviceid_clockseqandnode[8]; + uintptr_t in_session_serviceid_clockseqandnode_size; + uint32_t in_session_opscnt; + uint64_t in_session_head_next; + int64_t in_session_head_prev; + uint64_t in_session_context; + + uint32_t in_commandid; + + uint32_t in_operation_started; + uint32_t in_operation_paramtypes; + + uint64_t in_operation_param1_tmpref_buffer; + uint32_t in_operation_param1_tmpref_size; + uint64_t in_operation_param1_memref_parent; + uint32_t in_operation_param1_memref_parent_flag; + uint32_t in_operation_param1_memref_size; + uint32_t in_operation_param1_memref_offset; + uint32_t in_operation_param1_value_a; + uint32_t in_operation_param1_value_b; + int32_t in_operation_param1_ionref_ionsharefd; + uint32_t in_operation_param1_ionref_ionsize; + + uint64_t in_operation_param2_tmpref_buffer; + uint32_t in_operation_param2_tmpref_size; + uint64_t in_operation_param2_memref_parent; + uint32_t in_operation_param2_memref_parent_flag; + uint32_t in_operation_param2_memref_size; + uint32_t in_operation_param2_memref_offset; + uint32_t in_operation_param2_value_a; + uint32_t in_operation_param2_value_b; + int32_t in_operation_param2_ionref_ionsharefd; + uint32_t in_operation_param2_ionref_ionsize; + + uint64_t in_operation_param3_tmpref_buffer; + uint32_t in_operation_param3_tmpref_size; + uint64_t in_operation_param3_memref_parent; + uint32_t in_operation_param3_memref_parent_flag; + uint32_t in_operation_param3_memref_size; + uint32_t in_operation_param3_memref_offset; + uint32_t in_operation_param3_value_a; + uint32_t in_operation_param3_value_b; + int32_t in_operation_param3_ionref_ionsharefd; + uint32_t in_operation_param3_ionref_ionsize; + + uint64_t in_operation_param4_tmpref_buffer; + uint32_t in_operation_param4_tmpref_size; + uint64_t in_operation_param4_memref_parent; + uint32_t in_operation_param4_memref_parent_flag; + uint32_t in_operation_param4_memref_size; + uint32_t in_operation_param4_memref_offset; + uint32_t in_operation_param4_value_a; + uint32_t in_operation_param4_value_b; + int32_t in_operation_param4_ionref_ionsharefd; + uint32_t in_operation_param4_ionref_ionsize; + + uint64_t in_operation_session; + int32_t in_operation_cancelflag; + + uint32_t in_returnorigin; + struct retstru_teec_invokecommand rs_invokecommand_ins; + + if (gpp_channel == NULL) + { + std::cout << "libteecc: the grpc client or channel is null, when executing TEEC_InvokeCommand." << std::endl; + return TEEC_ERROR_GRPC_ERROR; + } + + if (session == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + if (operation == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + in_session_sessionid = session->session_id; + in_session_serviceid_timelow = session->service_id.timeLow; + in_session_serviceid_timemid = session->service_id.timeMid; + in_session_serviceid_timehiandver = session->service_id.timeHiAndVersion; + if ( + session->service_id.clockSeqAndNode != NULL + ) + { + for (int i = 0; i < 8; i++) + { + in_session_serviceid_clockseqandnode[i] = + session->service_id.clockSeqAndNode[i]; + } + } else + { + for (int i = 0; i < 8; i++) + { + in_session_serviceid_clockseqandnode[i] = 0; + } + } + in_session_serviceid_clockseqandnode_size = 8; + in_session_opscnt = session->ops_cnt; + in_session_head_next = (uint64_t) session->head.next; + in_session_head_prev = (uint64_t) session->head.prev; + in_session_context = glob_scontaddr; + + in_commandid = commandID; + + in_operation_started = operation->started; + in_operation_paramtypes = operation->paramTypes; + + in_operation_param1_ionref_ionsharefd = operation->params[0].ionref.ion_share_fd; + in_operation_param1_ionref_ionsize = operation->params[0].ionref.ion_size; + + in_operation_param2_ionref_ionsharefd = operation->params[1].ionref.ion_share_fd; + in_operation_param2_ionref_ionsize = operation->params[1].ionref.ion_size; + + in_operation_param3_ionref_ionsharefd = operation->params[2].ionref.ion_share_fd; + in_operation_param3_ionref_ionsize = operation->params[2].ionref.ion_size; + + in_operation_param4_ionref_ionsharefd = operation->params[3].ionref.ion_share_fd; + in_operation_param4_ionref_ionsize = operation->params[3].ionref.ion_size; + + uint8_t *in_buffer1 = NULL; + uintptr_t in_buffer1_size = 0; + + switch ( + TEEC_PARAM_TYPE_GET(operation->paramTypes, 0) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + in_operation_param1_value_a = operation->params[0].value.a; + in_operation_param1_value_b = operation->params[0].value.b; + + break; + } + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + operation->params[0].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_NULL; + } + if ( + operation->params[0].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_LESS; + } + + in_operation_param1_tmpref_buffer = (uint64_t) operation->params[0].tmpref.buffer; + in_operation_param1_tmpref_size = operation->params[0].tmpref.size; + + in_buffer1_size = operation->params[0].tmpref.size; + in_buffer1 = (uint8_t *) malloc(in_buffer1_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer1_size; isize++) + { + in_buffer1[isize] = (uint8_t) * ((uint8_t * )(operation->params[0].tmpref.buffer) + isize); + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + operation->params[0].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_NULL; + } + if ( + operation->params[0].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_LESS; + } + + in_operation_param1_tmpref_buffer = (uint64_t) operation->params[0].tmpref.buffer; + in_operation_param1_tmpref_size = operation->params[0].tmpref.size; + + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (operation->params[0].memref.parent->flags) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[0].memref.parent->buffer == NULL || + operation->params[0].memref.parent->ops_cnt != 0xfffe + ) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if ( + operation->params[0].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + in_operation_param1_memref_parent = + (uint64_t) operation->params[0].memref.parent->buffer; + in_operation_param1_memref_parent_flag = + (uint32_t) operation->params[0].memref.parent->flags; + in_operation_param1_memref_size = operation->params[0].memref.size; + + in_buffer1_size = operation->params[0].memref.parent->size; + in_buffer1 = (uint8_t *) malloc(in_buffer1_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer1_size; isize++) + { + in_buffer1[isize] = + (uint8_t) * ((uint8_t * )( + operation->params[0].memref.parent->buffer + ) + + isize + ); + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + operation->params[0].memref.parent->buffer == NULL || + operation->params[0].memref.parent->ops_cnt != 0xfffe + ) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if ( + operation->params[0].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + in_operation_param1_memref_parent = + (uint64_t) operation->params[0].memref.parent->buffer; + in_operation_param1_memref_parent_flag = + (uint32_t) operation->params[0].memref.parent->flags; + in_operation_param1_memref_size = operation->params[0].memref.size; + + break; + } + + default: + { + return TEEC_ERROR_NO_SHAREMEMFLAG; + break; + } + + } // end of switch(operation->params[0].memref.parent->flags) + + break; + } + // end of case TEEC_MEMREF_WHOLE + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[0].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if (operation->params[0].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + in_operation_param1_memref_parent = + (uint64_t) operation->params[0].memref.parent->buffer; + in_operation_param1_memref_parent_flag = + (uint32_t) operation->params[0].memref.parent->flags; + in_operation_param1_memref_offset = operation->params[0].memref.offset; + in_operation_param1_memref_size = operation->params[0].memref.size; + + in_buffer1_size = operation->params[0].memref.parent->size; + in_buffer1 = (uint8_t *) malloc(in_buffer1_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer1_size; isize++) + { + in_buffer1[isize] = + (uint8_t) * ((uint8_t * )(operation->params[0].memref.parent->buffer) + isize); + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_INPUT INOUT + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (operation->params[0].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if (operation->params[0].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + in_operation_param1_memref_parent = + (uint64_t) operation->params[0].memref.parent->buffer; + in_operation_param1_memref_parent_flag = + (uint32_t) operation->params[0].memref.parent->flags; + in_operation_param1_memref_offset = operation->params[0].memref.offset; + in_operation_param1_memref_size = operation->params[0].memref.size; + + in_buffer1_size = operation->params[0].memref.parent->size; + in_buffer1 = (uint8_t *) malloc(in_buffer1_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer1_size; isize++) + { + in_buffer1[isize] = 0x0; + } + + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT + + + default: + break; + } + + + uint8_t *in_buffer2 = NULL; + uintptr_t in_buffer2_size = 0; + switch ( + TEEC_PARAM_TYPE_GET(operation->paramTypes, 1) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + in_operation_param2_value_a = operation->params[1].value.a; + in_operation_param2_value_b = operation->params[1].value.b; + + break; + } + + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + operation->params[1].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM1_TEMPMEM_NULL; + } + if ( + operation->params[1].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM1_TEMPMEM_LESS; + } + + in_operation_param2_tmpref_buffer = (uint64_t) operation->params[1].tmpref.buffer; + in_operation_param2_tmpref_size = operation->params[1].tmpref.size; + + in_buffer2_size = operation->params[1].tmpref.size; + in_buffer2 = (uint8_t *) malloc(in_buffer2_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer2_size; isize++) + { + in_buffer2[isize] = (uint8_t) * ((uint8_t * )(operation->params[1].tmpref.buffer) + isize); + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + operation->params[1].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM1_TEMPMEM_NULL; + } + if ( + operation->params[1].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM1_TEMPMEM_LESS; + } + + in_operation_param2_tmpref_buffer = (uint64_t) operation->params[1].tmpref.buffer; + in_operation_param2_tmpref_size = operation->params[1].tmpref.size; + + break; + } + + case TEEC_MEMREF_WHOLE: + { + switch (operation->params[1].memref.parent->flags) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[1].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM1_MEMREF_NULL; + } + if ( + operation->params[1].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM1_MEMREF_LESS; + } + + in_operation_param2_memref_parent = + (uint64_t) operation->params[1].memref.parent->buffer; + in_operation_param2_memref_parent_flag = + (uint32_t) operation->params[1].memref.parent->flags; + in_operation_param2_memref_size = operation->params[1].memref.size; + + in_buffer2_size = operation->params[1].memref.parent->size; + in_buffer2 = (uint8_t *) malloc(in_buffer2_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer2_size; isize++) + { + in_buffer2[isize] = + (uint8_t) * ((uint8_t * )( + operation->params[1].memref.parent->buffer + ) + + isize + ); + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + operation->params[1].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM1_MEMREF_NULL; + } + if ( + operation->params[1].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM1_MEMREF_LESS; + } + + in_operation_param2_memref_parent = + (uint64_t) operation->params[1].memref.parent->buffer; + in_operation_param2_memref_parent_flag = + (uint32_t) operation->params[1].memref.parent->flags; + in_operation_param2_memref_size = operation->params[1].memref.size; + + break; + } + + default: + { + return TEEC_ERROR_NO_SHAREMEMFLAG; + break; + } + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[1].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if (operation->params[1].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + in_operation_param2_memref_parent = + (uint64_t) operation->params[1].memref.parent->buffer; + in_operation_param2_memref_parent_flag = + (uint32_t) operation->params[1].memref.parent->flags; + in_operation_param2_memref_offset = operation->params[1].memref.offset; + in_operation_param2_memref_size = operation->params[1].memref.size; + + in_buffer2_size = operation->params[1].memref.parent->size; + in_buffer2 = (uint8_t *) malloc(in_buffer2_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer2_size; isize++) + { + in_buffer2[isize] = + (uint8_t) * ((uint8_t * )(operation->params[1].memref.parent->buffer) + isize); + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_INPUT INOUT + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (operation->params[1].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM1_MEMREF_NULL; + } + if (operation->params[1].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM1_MEMREF_LESS; + } + + in_operation_param2_memref_parent = + (uint64_t) operation->params[1].memref.parent->buffer; + in_operation_param2_memref_parent_flag = + (uint32_t) operation->params[1].memref.parent->flags; + in_operation_param2_memref_offset = operation->params[1].memref.offset; + in_operation_param2_memref_size = operation->params[1].memref.size; + + in_buffer2_size = operation->params[1].memref.parent->size; + in_buffer2 = (uint8_t *) malloc(in_buffer2_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer2_size; isize++) + { + in_buffer2[isize] = 0x0; + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT + + + default: + break; + } + + uint8_t *in_buffer3 = NULL; + uintptr_t in_buffer3_size = 0; + switch ( + TEEC_PARAM_TYPE_GET(operation->paramTypes, 2) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + in_operation_param3_value_a = operation->params[2].value.a; + in_operation_param3_value_b = operation->params[2].value.b; + + break; + } + + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + operation->params[2].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM2_TEMPMEM_NULL; + } + if ( + operation->params[2].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM2_TEMPMEM_LESS; + } + + in_operation_param3_tmpref_buffer = (uint64_t) operation->params[2].tmpref.buffer; + in_operation_param3_tmpref_size = operation->params[2].tmpref.size; + + in_buffer3_size = operation->params[2].tmpref.size; + in_buffer3 = (uint8_t *) malloc(in_buffer3_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer3_size; isize++) + { + in_buffer3[isize] = (uint8_t) * ((uint8_t * )(operation->params[2].tmpref.buffer) + isize); + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + operation->params[2].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM2_TEMPMEM_NULL; + } + if ( + operation->params[2].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM2_TEMPMEM_LESS; + } + + in_operation_param3_tmpref_buffer = (uint64_t) operation->params[2].tmpref.buffer; + in_operation_param3_tmpref_size = operation->params[2].tmpref.size; + + break; + } + + case TEEC_MEMREF_WHOLE: + { + switch (operation->params[2].memref.parent->flags) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[2].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM2_MEMREF_NULL; + } + if ( + operation->params[2].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM2_MEMREF_LESS; + } + + in_operation_param3_memref_parent = + (uint64_t) operation->params[2].memref.parent->buffer; + in_operation_param3_memref_parent_flag = + (uint32_t) operation->params[2].memref.parent->flags; + in_operation_param3_memref_size = operation->params[2].memref.size; + + in_buffer3_size = operation->params[2].memref.parent->size; + in_buffer3 = (uint8_t *) malloc(in_buffer3_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer3_size; isize++) + { + in_buffer3[isize] = + (uint8_t) * ((uint8_t * )( + operation->params[2].memref.parent->buffer + ) + + isize + ); + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + operation->params[2].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM2_MEMREF_NULL; + } + if ( + operation->params[2].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM2_MEMREF_LESS; + } + + in_operation_param3_memref_parent = + (uint64_t) operation->params[2].memref.parent->buffer; + in_operation_param3_memref_parent_flag = + (uint32_t) operation->params[2].memref.parent->flags; + in_operation_param3_memref_size = operation->params[2].memref.size; + + break; + } + + default: + { + return TEEC_ERROR_NO_SHAREMEMFLAG; + break; + } + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[2].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM2_MEMREF_NULL; + } + if (operation->params[2].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM2_MEMREF_LESS; + } + + in_operation_param3_memref_parent = + (uint64_t) operation->params[2].memref.parent->buffer; + in_operation_param3_memref_parent_flag = + (uint32_t) operation->params[2].memref.parent->flags; + in_operation_param3_memref_offset = operation->params[2].memref.offset; + in_operation_param3_memref_size = operation->params[2].memref.size; + + in_buffer3_size = operation->params[2].memref.parent->size; + in_buffer3 = (uint8_t *) malloc(in_buffer3_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer3_size; isize++) + { + in_buffer3[isize] = + (uint8_t) * ((uint8_t * )(operation->params[2].memref.parent->buffer) + isize); + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_INPUT INOUT + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (operation->params[2].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if (operation->params[2].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + in_operation_param3_memref_parent = + (uint64_t) operation->params[2].memref.parent->buffer; + in_operation_param3_memref_parent_flag = + (uint32_t) operation->params[2].memref.parent->flags; + in_operation_param3_memref_offset = operation->params[2].memref.offset; + in_operation_param3_memref_size = operation->params[2].memref.size; + + in_buffer3_size = operation->params[2].memref.parent->size; + in_buffer3 = (uint8_t *) malloc(in_buffer3_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer3_size; isize++) + { + in_buffer3[isize] = 0x0; + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT + + default: + break; + } + + + uint8_t *in_buffer4 = NULL; + uintptr_t in_buffer4_size = 0; + switch ( + TEEC_PARAM_TYPE_GET(operation->paramTypes, 3) + ) + { + case TEEC_VALUE_INPUT: + case TEEC_VALUE_INOUT: + { + in_operation_param4_value_a = operation->params[3].value.a; + in_operation_param4_value_b = operation->params[3].value.b; + + break; + } + + case TEEC_MEMREF_TEMP_INPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if ( + operation->params[3].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM3_TEMPMEM_NULL; + } + if ( + operation->params[3].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM3_TEMPMEM_LESS; + } + + in_operation_param4_tmpref_buffer = (uint64_t) operation->params[3].tmpref.buffer; + in_operation_param4_tmpref_size = operation->params[3].tmpref.size; + + in_buffer4_size = operation->params[3].tmpref.size; + in_buffer4 = (uint8_t *) malloc(in_buffer4_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer4_size; isize++) + { + in_buffer4[isize] = (uint8_t) * ((uint8_t * )(operation->params[3].tmpref.buffer) + isize); + } + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + { + if ( + operation->params[3].tmpref.buffer == NULL + ) + { + return TEEC_ERROR_PARAM3_TEMPMEM_NULL; + } + if ( + operation->params[3].tmpref.size <= 0 + ) + { + return TEEC_ERROR_PARAM3_TEMPMEM_LESS; + } + + in_operation_param4_tmpref_buffer = (uint64_t) operation->params[3].tmpref.buffer; + in_operation_param4_tmpref_size = operation->params[3].tmpref.size; + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + switch (operation->params[3].memref.parent->flags) + { + case TEEC_MEM_INPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[3].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM3_MEMREF_NULL; + } + if ( + operation->params[3].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM3_MEMREF_LESS; + } + + in_operation_param4_memref_parent = + (uint64_t) operation->params[3].memref.parent->buffer; + in_operation_param4_memref_parent_flag = + (uint32_t) operation->params[3].memref.parent->flags; + in_operation_param4_memref_size = operation->params[3].memref.size; + + in_buffer4_size = operation->params[3].memref.parent->size; + in_buffer4 = (uint8_t *) malloc(in_buffer4_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer4_size; isize++) + { + in_buffer4[isize] = + (uint8_t) * ((uint8_t * )( + operation->params[3].memref.parent->buffer + ) + + isize + ); + } + + break; + } + + case TEEC_MEM_OUTPUT: + { + if ( + operation->params[3].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM3_MEMREF_NULL; + } + if ( + operation->params[3].memref.parent->size <= 0 + ) + { + return TEEC_ERROR_PARAM3_MEMREF_LESS; + } + + in_operation_param4_memref_parent = + (uint64_t) operation->params[3].memref.parent->buffer; + in_operation_param4_memref_parent_flag = + (uint32_t) operation->params[3].memref.parent->flags; + in_operation_param4_memref_size = operation->params[3].memref.size; + + break; + } + + default: + { + return TEEC_ERROR_NO_SHAREMEMFLAG; + break; + } + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_INPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[3].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM3_MEMREF_NULL; + } + if (operation->params[3].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM3_MEMREF_LESS; + } + + in_operation_param4_memref_parent = + (uint64_t) operation->params[3].memref.parent->buffer; + in_operation_param4_memref_parent_flag = + (uint32_t) operation->params[3].memref.parent->flags; + in_operation_param4_memref_offset = operation->params[3].memref.offset; + in_operation_param4_memref_size = operation->params[3].memref.size; + + in_buffer4_size = operation->params[3].memref.parent->size; + in_buffer4 = (uint8_t *) malloc(in_buffer4_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer4_size; isize++) + { + in_buffer4[isize] = + (uint8_t) * ((uint8_t * )(operation->params[3].memref.parent->buffer) + isize); + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_INPUT INOUT + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + { + if (operation->params[3].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if (operation->params[3].memref.parent->size <= 0) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + in_operation_param4_memref_parent = + (uint64_t) operation->params[3].memref.parent->buffer; + in_operation_param4_memref_parent_flag = + (uint32_t) operation->params[3].memref.parent->flags; + in_operation_param4_memref_offset = operation->params[3].memref.offset; + in_operation_param4_memref_size = operation->params[3].memref.size; + + in_buffer4_size = operation->params[3].memref.parent->size; + in_buffer4 = (uint8_t *) malloc(in_buffer4_size * sizeof(uint8_t)); + for (int isize = 0; isize < in_buffer4_size; isize++) + { + in_buffer4[isize] = 0x0; + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT + + + default: + break; + } + + + in_operation_session = (uint64_t) operation->session; + in_operation_cancelflag = operation->cancel_flag; + + if (returnOrigin == NULL) + { + in_returnorigin = 0; + } else + { + in_returnorigin = *returnOrigin; + } + + rs_invokecommand_ins = + client->externc_teec_invokecommand( + in_session_sessionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context, + + in_commandid, + + in_operation_started, + in_operation_paramtypes, + + in_operation_param1_tmpref_buffer, + in_operation_param1_tmpref_size, + in_operation_param1_memref_parent, + in_operation_param1_memref_parent_flag, + in_operation_param1_memref_size, + in_operation_param1_memref_offset, + in_operation_param1_value_a, + in_operation_param1_value_b, + in_operation_param1_ionref_ionsharefd, + in_operation_param1_ionref_ionsize, + + in_operation_param2_tmpref_buffer, + in_operation_param2_tmpref_size, + in_operation_param2_memref_parent, + in_operation_param2_memref_parent_flag, + in_operation_param2_memref_size, + in_operation_param2_memref_offset, + in_operation_param2_value_a, + in_operation_param2_value_b, + in_operation_param2_ionref_ionsharefd, + in_operation_param2_ionref_ionsize, + + in_operation_param3_tmpref_buffer, + in_operation_param3_tmpref_size, + in_operation_param3_memref_parent, + in_operation_param3_memref_parent_flag, + in_operation_param3_memref_size, + in_operation_param3_memref_offset, + in_operation_param3_value_a, + in_operation_param3_value_b, + in_operation_param3_ionref_ionsharefd, + in_operation_param3_ionref_ionsize, + + in_operation_param4_tmpref_buffer, + in_operation_param4_tmpref_size, + in_operation_param4_memref_parent, + in_operation_param4_memref_parent_flag, + in_operation_param4_memref_size, + in_operation_param4_memref_offset, + in_operation_param4_value_a, + in_operation_param4_value_b, + in_operation_param4_ionref_ionsharefd, + in_operation_param4_ionref_ionsize, + + in_operation_session, + in_operation_cancelflag, + + in_returnorigin, + + in_buffer1, + in_buffer1_size, + in_buffer2, + in_buffer2_size, + in_buffer3, + in_buffer3_size, + in_buffer4, + in_buffer4_size + ); + if (rs_invokecommand_ins.flag == 1) + { + std::cout << "libteecc: invoke token null" << std::endl; + return TEEC_ERROR_TOKEN_NULL; + } + if (rs_invokecommand_ins.flag == 2) + { + std::cout << "libteecc: invoke jwt validate error" << std::endl; + return TEEC_ERROR_JWTVALIDATE_FAIL; + } + if (rs_invokecommand_ins.teecresult == TEEC_SUCCESS) + { + session->session_id = rs_invokecommand_ins.session_sessionid; + session->service_id.timeLow = rs_invokecommand_ins.session_serviceid_timelow; + session->service_id.timeMid = rs_invokecommand_ins.session_serviceid_timemid; + session->service_id.timeHiAndVersion = rs_invokecommand_ins.session_serviceid_timehiandver; + if (rs_invokecommand_ins.session_serviceid_clockseqandnode_outsize <= 8 && + rs_invokecommand_ins.session_serviceid_clockseqandnode_outsize > 0 && + rs_invokecommand_ins.session_serviceid_clockseqandnode != NULL && + session->service_id.clockSeqAndNode != NULL + ) + { + for (int i = 0; i < rs_invokecommand_ins.session_serviceid_clockseqandnode_outsize; i++) + { + session->service_id.clockSeqAndNode[i] = + (uint8_t)(rs_invokecommand_ins.session_serviceid_clockseqandnode[i] & 0x000000ff); + } + } else + { + for (int i = 0; i < 8; i++) + { + session->service_id.clockSeqAndNode[i] = 0; + } + } + session->ops_cnt = rs_invokecommand_ins.session_opscnt; + session->head.next = (struct ListNode *) rs_invokecommand_ins.session_head_next; + session->head.prev = (struct ListNode *) rs_invokecommand_ins.session_head_prev; + session->context = (TEEC_Context *) rs_invokecommand_ins.session_context; + + operation->started = rs_invokecommand_ins.operation_started; + operation->paramTypes = rs_invokecommand_ins.operation_paramtypes; + + switch ( + TEEC_PARAM_TYPE_GET(rs_invokecommand_ins.operation_paramtypes, 0) + ) + { + case TEEC_VALUE_OUTPUT: + case TEEC_VALUE_INOUT: + { + operation->params[0].value.a = rs_invokecommand_ins.operation_param1_value_a; + operation->params[0].value.b = rs_invokecommand_ins.operation_param1_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if (operation->params[0].tmpref.buffer == NULL) + { + return TEEC_ERROR_PARAM0_TEMPMEM_NULL; + } + + if (operation->params[0].tmpref.size < + rs_invokecommand_ins.buffer1_outsize + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_LESS; + } + + if (rs_invokecommand_ins.buffer1 != NULL && + rs_invokecommand_ins.buffer1_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer1_outsize; iind++) + { + *((uint8_t * )(operation->params[0].tmpref.buffer) + iind) = + *(rs_invokecommand_ins.buffer1 + iind); + } + operation->params[0].tmpref.size = rs_invokecommand_ins.buffer1_outsize; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + operation->params[0].memref.parent->flags = + rs_invokecommand_ins.operation_param1_memref_parent_flag; + switch (operation->params[0].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[0].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if ( + operation->params[0].memref.parent->size < + rs_invokecommand_ins.buffer1_outsize + ) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer1 != NULL && + rs_invokecommand_ins.buffer1_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer1_outsize; iind++) + { + *((uint8_t * )(operation->params[0].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer1 + iind); + } + operation->params[0].memref.size = rs_invokecommand_ins.buffer1_outsize; + operation->params[0].memref.parent->size = rs_invokecommand_ins.buffer1_outsize; + } + + break; + } + + default: + break; + } + + break; + + } + // end of case TEEC_MEMREF_WHOLE: + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[0].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM0_MEMREF_NULL; + } + if (operation->params[0].memref.parent->size < + rs_invokecommand_ins.buffer1_outsize + ) + { + return TEEC_ERROR_PARAM0_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer1 != NULL && + rs_invokecommand_ins.buffer1_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer1_outsize; iind++) + { + *((uint8_t * )(operation->params[0].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer1 + iind); + } + operation->params[0].memref.parent->size = rs_invokecommand_ins.buffer1_outsize; + + operation->params[0].memref.offset = rs_invokecommand_ins.operation_param1_memref_offset; + operation->params[0].memref.size = rs_invokecommand_ins.operation_param1_memref_size; + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT, INOUT + + + default: + break; + } + + operation->params[0].ionref.ion_share_fd = rs_invokecommand_ins.operation_param1_ionref_ionsharefd; + operation->params[0].ionref.ion_size = rs_invokecommand_ins.operation_param1_ionref_ionsize; + + + switch ( + TEEC_PARAM_TYPE_GET(rs_invokecommand_ins.operation_paramtypes, 1) + ) + { + case TEEC_VALUE_OUTPUT: + case TEEC_VALUE_INOUT: + { + operation->params[1].value.a = rs_invokecommand_ins.operation_param2_value_a; + operation->params[1].value.b = rs_invokecommand_ins.operation_param2_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if (operation->params[1].tmpref.buffer == NULL) + { + return TEEC_ERROR_PARAM0_TEMPMEM_NULL; + } + + if (operation->params[1].tmpref.size < + rs_invokecommand_ins.buffer2_outsize + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_LESS; + } + + if (rs_invokecommand_ins.buffer2 != NULL && + rs_invokecommand_ins.buffer2_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer2_outsize; iind++) + { + *((uint8_t * )(operation->params[1].tmpref.buffer) + iind) = + *(rs_invokecommand_ins.buffer2 + iind); + } + operation->params[1].tmpref.size = rs_invokecommand_ins.buffer2_outsize; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + operation->params[1].memref.parent->flags = + rs_invokecommand_ins.operation_param2_memref_parent_flag; + switch (operation->params[1].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[1].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM1_MEMREF_NULL; + } + if ( + operation->params[1].memref.parent->size < + rs_invokecommand_ins.buffer2_outsize + ) + { + return TEEC_ERROR_PARAM1_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer2 != NULL && + rs_invokecommand_ins.buffer2_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer2_outsize; iind++) + { + *((uint8_t * )(operation->params[1].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer2 + iind); + } + operation->params[1].memref.size = rs_invokecommand_ins.buffer2_outsize; + operation->params[1].memref.parent->size = rs_invokecommand_ins.buffer2_outsize; + } + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[1].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM1_MEMREF_NULL; + } + if (operation->params[1].memref.parent->size < + rs_invokecommand_ins.buffer2_outsize + ) + { + return TEEC_ERROR_PARAM1_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer2 != NULL && + rs_invokecommand_ins.buffer2_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer2_outsize; iind++) + { + *((uint8_t * )(operation->params[1].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer2 + iind); + } + operation->params[1].memref.parent->size = rs_invokecommand_ins.buffer2_outsize; + + operation->params[1].memref.offset = rs_invokecommand_ins.operation_param2_memref_offset; + operation->params[1].memref.size = rs_invokecommand_ins.operation_param2_memref_size; + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT, INOUT + + + default: + break; + } + + operation->params[1].ionref.ion_share_fd = rs_invokecommand_ins.operation_param2_ionref_ionsharefd; + operation->params[1].ionref.ion_size = rs_invokecommand_ins.operation_param2_ionref_ionsize; + + + switch ( + TEEC_PARAM_TYPE_GET(rs_invokecommand_ins.operation_paramtypes, 2) + ) + { + case TEEC_VALUE_OUTPUT: + case TEEC_VALUE_INOUT: + { + operation->params[2].value.a = rs_invokecommand_ins.operation_param3_value_a; + operation->params[2].value.b = rs_invokecommand_ins.operation_param3_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if (operation->params[2].tmpref.buffer == NULL) + { + return TEEC_ERROR_PARAM0_TEMPMEM_NULL; + } + + if (operation->params[2].tmpref.size < + rs_invokecommand_ins.buffer3_outsize + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_LESS; + } + + if (rs_invokecommand_ins.buffer3 != NULL && + rs_invokecommand_ins.buffer3_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer3_outsize; iind++) + { + *((uint8_t * )(operation->params[2].tmpref.buffer) + iind) = + *(rs_invokecommand_ins.buffer3 + iind); + } + operation->params[2].tmpref.size = rs_invokecommand_ins.buffer3_outsize; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + operation->params[2].memref.parent->flags = + rs_invokecommand_ins.operation_param3_memref_parent_flag; + switch (operation->params[2].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[2].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM2_MEMREF_NULL; + } + if ( + operation->params[2].memref.parent->size < + rs_invokecommand_ins.buffer3_outsize + ) + { + return TEEC_ERROR_PARAM2_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer3 != NULL && + rs_invokecommand_ins.buffer3_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer3_outsize; iind++) + { + *((uint8_t * )(operation->params[2].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer3 + iind); + } + operation->params[2].memref.size = rs_invokecommand_ins.buffer3_outsize; + operation->params[2].memref.parent->size = rs_invokecommand_ins.buffer3_outsize; + } + + break; + } + + default: + break; + } + + break; + + } + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[2].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM2_MEMREF_NULL; + } + if (operation->params[2].memref.parent->size < + rs_invokecommand_ins.buffer3_outsize + ) + { + return TEEC_ERROR_PARAM2_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer3 != NULL && + rs_invokecommand_ins.buffer3_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer3_outsize; iind++) + { + *((uint8_t * )(operation->params[2].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer3 + iind); + } + operation->params[2].memref.parent->size = rs_invokecommand_ins.buffer3_outsize; + + operation->params[2].memref.offset = rs_invokecommand_ins.operation_param3_memref_offset; + operation->params[2].memref.size = rs_invokecommand_ins.operation_param3_memref_size; + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT, INOUT + + + default: + break; + } + + operation->params[2].ionref.ion_share_fd = rs_invokecommand_ins.operation_param3_ionref_ionsharefd; + operation->params[2].ionref.ion_size = rs_invokecommand_ins.operation_param3_ionref_ionsize; + + + switch ( + TEEC_PARAM_TYPE_GET(rs_invokecommand_ins.operation_paramtypes, 3) + ) + { + case TEEC_VALUE_OUTPUT: + case TEEC_VALUE_INOUT: + { + operation->params[3].value.a = rs_invokecommand_ins.operation_param4_value_a; + operation->params[3].value.b = rs_invokecommand_ins.operation_param4_value_b; + + break; + } + + case TEEC_MEMREF_TEMP_OUTPUT: + case TEEC_MEMREF_TEMP_INOUT: + { + if (operation->params[3].tmpref.buffer == NULL) + { + return TEEC_ERROR_PARAM0_TEMPMEM_NULL; + } + + if (operation->params[3].tmpref.size < + rs_invokecommand_ins.buffer4_outsize + ) + { + return TEEC_ERROR_PARAM0_TEMPMEM_LESS; + } + + if (rs_invokecommand_ins.buffer4 != NULL && + rs_invokecommand_ins.buffer4_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer4_outsize; iind++) + { + *((uint8_t * )(operation->params[3].tmpref.buffer) + iind) = + *(rs_invokecommand_ins.buffer4 + iind); + } + operation->params[3].tmpref.size = rs_invokecommand_ins.buffer4_outsize; + } + + break; + } + + + case TEEC_MEMREF_WHOLE: + { + operation->params[3].memref.parent->flags = + rs_invokecommand_ins.operation_param4_memref_parent_flag; + switch (operation->params[3].memref.parent->flags) + { + case TEEC_MEM_OUTPUT: + case TEEC_MEM_INOUT: + { + if ( + operation->params[3].memref.parent->buffer == NULL + ) + { + return TEEC_ERROR_PARAM3_MEMREF_NULL; + } + if ( + operation->params[3].memref.parent->size < + rs_invokecommand_ins.buffer4_outsize + ) + { + return TEEC_ERROR_PARAM3_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer4 != NULL && + rs_invokecommand_ins.buffer4_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer4_outsize; iind++) + { + *((uint8_t * )(operation->params[3].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer4 + iind); + } + operation->params[3].memref.size = rs_invokecommand_ins.buffer3_outsize; + operation->params[3].memref.parent->size = rs_invokecommand_ins.buffer3_outsize; + } + + break; + } + + default: + break; + } + + break; + } + + + case TEEC_MEMREF_PARTIAL_OUTPUT: + case TEEC_MEMREF_PARTIAL_INOUT: + { + if (operation->params[3].memref.parent->buffer == NULL) + { + return TEEC_ERROR_PARAM3_MEMREF_NULL; + } + if (operation->params[3].memref.parent->size < + rs_invokecommand_ins.buffer4_outsize + ) + { + return TEEC_ERROR_PARAM3_MEMREF_LESS; + } + + if (rs_invokecommand_ins.buffer4 != NULL && + rs_invokecommand_ins.buffer4_outsize > 0) + { + for (int iind = 0; iind < rs_invokecommand_ins.buffer4_outsize; iind++) + { + *((uint8_t * )(operation->params[3].memref.parent->buffer) + iind) = + *(rs_invokecommand_ins.buffer4 + iind); + } + operation->params[3].memref.parent->size = rs_invokecommand_ins.buffer4_outsize; + + operation->params[3].memref.offset = rs_invokecommand_ins.operation_param4_memref_offset; + operation->params[3].memref.size = rs_invokecommand_ins.operation_param4_memref_size; + } + + break; + } + // end of case TEEC_MEMREF_PARTIAL_OUTPUT, INOUT + + + default: + break; + } + + operation->params[3].ionref.ion_share_fd = rs_invokecommand_ins.operation_param4_ionref_ionsharefd; + operation->params[3].ionref.ion_size = rs_invokecommand_ins.operation_param4_ionref_ionsize; + + + operation->session = (TEEC_Session *) rs_invokecommand_ins.operation_session; + operation->cancel_flag = rs_invokecommand_ins.operation_cancelflag; + + if (returnOrigin != NULL) + { + *returnOrigin = in_returnorigin; + } + } + return static_cast(rs_invokecommand_ins.teecresult); + +} + +void +TEEC_CloseSession(TEEC_Session *session) +{ + if (gpp_channel == NULL) + { + printf("libteec: the grpc client or channel is null, when executing TEEC_CloseSession. \n"); + return; + } + + uint32_t in_session_sessionid; + uint32_t in_session_serviceid_timelow; + uint32_t in_session_serviceid_timemid; + uint32_t in_session_serviceid_timehiandver; + uint8_t in_session_serviceid_clockseqandnode[8]; + uintptr_t in_session_serviceid_clockseqandnode_size; + uint32_t in_session_opscnt; + uint64_t in_session_head_next; + int64_t in_session_head_prev; + uint64_t in_session_context; + + if (session == NULL) + { + return; + } + struct retstru_teec_closesession rs_closesession_ins; + + in_session_sessionid = session->session_id; + in_session_serviceid_timelow = session->service_id.timeLow; + in_session_serviceid_timemid = session->service_id.timeMid; + in_session_serviceid_timehiandver = session->service_id.timeHiAndVersion; + if ( + session->service_id.clockSeqAndNode != NULL + ) + { + for (int i = 0; i < 8; i++) + { + in_session_serviceid_clockseqandnode[i] = + session->service_id.clockSeqAndNode[i]; + } + } else + { + for (int i = 0; i < 8; i++) + { + in_session_serviceid_clockseqandnode[i] = 0; + } + } + in_session_serviceid_clockseqandnode_size = 8; + in_session_opscnt = session->ops_cnt; + in_session_head_next = (uint64_t) session->head.next; + in_session_head_prev = (uint64_t) session->head.prev; + in_session_context = glob_scontaddr; + + rs_closesession_ins = + client->externc_teec_closesession( + in_session_sessionid, + in_session_serviceid_timelow, + in_session_serviceid_timemid, + in_session_serviceid_timehiandver, + in_session_serviceid_clockseqandnode, + in_session_serviceid_clockseqandnode_size, + in_session_opscnt, + in_session_head_next, + in_session_head_prev, + in_session_context + ); + + if (rs_closesession_ins.flag == 1) + { + std::cout << "libteecc: closesession token null" << std::endl; + return; + } + if (rs_closesession_ins.flag == 2) + { + std::cout << "libteecc: closesession jwt validate error" << std::endl; + return; + } +#if 0 + std::cout << "externc_teec_closesession: " << std::endl; + std::cout << "gpp request sessionid: " << in_session_sessionid < 0 + && + rs_closesession_ins.session_serviceid_clockseqandnode != NULL + ) + { + printf("ret session_serviceid_clockseqandnode = \n"); + for (uintptr_t uisize = 0; + uisize < rs_closesession_ins.session_serviceid_clockseqandnode_outsize; + uisize ++) + { + printf(" %2.2x", *(rs_closesession_ins.session_serviceid_clockseqandnode + uisize)); + } + printf("\n"); + } + else + { + printf("ret clockseqandnode addr = 0x %16.16lx\n", + (unsigned long)rs_closesession_ins.session_serviceid_clockseqandnode); + } + printf("ret clockseqandnode_outsize = %ld\n", + rs_closesession_ins.session_serviceid_clockseqandnode_outsize); + printf("ret session_opscnt = 0x %8.8x\n", + rs_closesession_ins.session_opscnt); + printf("ret session_head_next = 0x %16.16lx\n", + rs_closesession_ins.session_head_next); + printf("ret session_head_prev = 0x %16.16lx\n", + rs_closesession_ins.session_head_prev); +#endif + session->session_id = rs_closesession_ins.session_sessionid; + session->service_id.timeLow = rs_closesession_ins.session_serviceid_timelow; + session->service_id.timeMid = rs_closesession_ins.session_serviceid_timemid; + session->service_id.timeHiAndVersion = rs_closesession_ins.session_serviceid_timehiandver; + if (rs_closesession_ins.session_serviceid_clockseqandnode_outsize <= 8 && + rs_closesession_ins.session_serviceid_clockseqandnode_outsize > 0 && + rs_closesession_ins.session_serviceid_clockseqandnode != NULL && + session->service_id.clockSeqAndNode != NULL + ) + { + for (int i = 0; i < rs_closesession_ins.session_serviceid_clockseqandnode_outsize; i++) + { + session->service_id.clockSeqAndNode[i] = + (uint8_t)(rs_closesession_ins.session_serviceid_clockseqandnode[i] & 0x000000ff); + } + } else + { + for (int i = 0; i < 8; i++) + { + session->service_id.clockSeqAndNode[i] = 0; + } + } + session->ops_cnt = rs_closesession_ins.session_opscnt; + session->head.next = (struct ListNode *) rs_closesession_ins.session_head_next; + session->head.prev = (struct ListNode *) rs_closesession_ins.session_head_prev; + session->context = (TEEC_Context *) rs_closesession_ins.session_context; + return; +} + +TEEC_Result +TEEC_AllocateSharedMemory( + TEEC_Context *context, + TEEC_SharedMemory *sharedMem) +{ + if (context == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + if (sharedMem == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + if (sharedMem->size <= 0) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + sharedMem->buffer = (uint8_t *) malloc(sharedMem->size); + if (sharedMem->buffer == NULL) + { + return TEEC_ERROR_OUT_OF_MEMORY; + } + + sharedMem->is_allocated = true; + sharedMem->context = context; + sharedMem->ops_cnt = 0xfffe; + + return TEEC_SUCCESS; +} + +TEEC_Result +TEEC_RegisterSharedMemory( + TEEC_Context *context, + TEEC_SharedMemory *sharedMem) +{ + if (context == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + if (sharedMem == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + if (sharedMem->size <= 0) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + if (sharedMem->buffer == NULL) + { + return TEEC_ERROR_BAD_PARAMETERS; + } + + sharedMem->is_allocated = false; + sharedMem->context = context; + sharedMem->ops_cnt = 0xfffe; + + return TEEC_SUCCESS; +} + +void +TEEC_ReleaseSharedMemory( + TEEC_SharedMemory *sharedMem) +{ + if (sharedMem == NULL) + { + return; + } + if (sharedMem->buffer == NULL) + { + return; + } + + sharedMem->ops_cnt = 0x0; + if (sharedMem->is_allocated == true) + { + free(sharedMem->buffer); + } +} + + +TEEC_Result +TEEC_DeployTa( + char *infile_path, + char *subdir, + char *outfile_name +) +{ + + if (infile_path == NULL) + { + return TEEC_INFILE_PATH_NULL; + } + + std::string str_infile_path(infile_path); + std::string str_subdir; + std::string str_outfile_name; + + if (subdir != NULL) + { + str_subdir = std::string(subdir); + } + + if (outfile_name != NULL) + { + str_outfile_name = std::string(outfile_name); + } + + int iret; + + if (gpp_channel == NULL) + { + int igrpctls = grpc_tls; + + if (grpc_tls != 0 && grpc_tls != 1 && grpc_tls != 2) + { + std::cout << global_strcfgfile << " grpc_tls should be 0 or 1 or 2 " << std::endl; + return TEEC_FAIL; + } + + switch (igrpctls) + { + case 0: + { + gpp_channel = grpc::CreateChannel(global_target_str, grpc::InsecureChannelCredentials()); + + break; + } + + case 1: + { + if (!isFileExists_ifstream(global_servercacert_path)) + { + std::cout << "error file : " << global_servercacert_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + + std::string strcmd; + FILE *pipe; + char buffer[128]; + std::string result; + + std::string strdayseconds; + char *resulttemp; + const char slash[] = "\n"; + char *parresult; + std::string strparresult; + std::string willexpire("Certificate will expire"); + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_servercacert_path + " -checkend " + strdayseconds; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "gpp '" << global_servercacert_path << "' will expire in 7 days, please reget it" << std::endl; + return TEEC_FAIL; + } + + auto servercacert = get_file_contents(global_servercacert_path); + grpc::SslCredentialsOptions ssl_opts; + ssl_opts.pem_root_certs = servercacert; + std::shared_ptr creds = grpc::SslCredentials(ssl_opts); + gpp_channel = grpc::CreateChannel(global_target_str, creds); + + break; + } + + case 2: + { + if (!isFileExists_ifstream(global_servercacert_path)) + { + std::cout << "error file : " << global_servercacert_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + if (!isFileExists_ifstream(global_clientkey_path)) + { + std::cout << "error file : " << global_clientkey_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + if (!isFileExists_ifstream(global_clientcert_path)) + { + std::cout << "error file : " << global_clientcert_path << " is not exist " << std::endl; + return TEEC_FAIL; + } + + std::string strcmd; + FILE *pipe; + char buffer[128]; + std::string result; + + std::string strdayseconds; + char *resulttemp; + const char slash[] = "\n"; + char *parresult; + std::string strparresult; + std::string willexpire("Certificate will expire"); + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_servercacert_path + " -checkend " + strdayseconds; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "libteecc '" << global_servercacert_path << "' will expire in 7 days, please reget it" + << std::endl; + return TEEC_FAIL; + } + + // 7 days in seconds + strdayseconds = "604800"; + strcmd = "openssl x509 -enddate -noout -in " + global_clientcert_path + " -checkend " + strdayseconds; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + resulttemp = const_cast(result.data()); + parresult = strtok(resulttemp, slash); + while (parresult != NULL) + { + strparresult = std::string(parresult); + parresult = strtok(NULL, slash); + } + if (strparresult.compare(willexpire) == 0) + { + std::cout << "libteecc '" << global_clientcert_path << "' will expire in 7 days, please reget it" << std::endl; + return TEEC_FAIL; + } + strcmd = "openssl rsa -in " + global_clientkey_path + " -out " + + global_clientkey_path + ".nopass"; + std::string nopass_clientkey_path = global_clientkey_path + ".nopass"; + + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + + strcmd = "openssl rsa -in " + nopass_clientkey_path + " -check -noout"; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + std::string keyok("RSA key ok\n"); + if (result.compare(keyok) != 0) + { + std::cout << "libteecc '" + global_clientkey_path + "' integrity is broken" << std::endl; + return TEEC_FAIL; + } + + std::string sigfile_path = global_strcfgfiletemp + "/.teecc/certs/msg.sig"; + std::string msgfile_path = global_strcfgfiletemp + "/.teecc/certs/msg.txt"; + strcmd = + "openssl dgst -sha256 -sign " + nopass_clientkey_path + " -out " + sigfile_path + " " + msgfile_path; + system(strcmd.c_str()); + // ${_openssl} x509 -in ${CRTPEM} -pubkey -out ${PUBPEM} + std::string pubkeyfile_path = global_strcfgfiletemp + "/.teecc/certs/client_pubkey.pem"; + strcmd = "openssl x509 -in " + global_clientcert_path + " -pubkey -out " + pubkeyfile_path; + system(strcmd.c_str()); + + // ${_openssl} dgst -sha256 -verify ${PUBPEM} -signature msg.sig msg.txt + strcmd = "openssl dgst -sha256 -verify " + pubkeyfile_path + " -signature " + sigfile_path + " " + + msgfile_path; + // system(strcmd.c_str()); + pipe = popen(strcmd.c_str(), "r"); + if (!pipe) + { + std::cout << "libteecc popen '" << strcmd << "' failed" << std::endl; + return TEEC_FAIL; + } + result = ""; + // read till end of process: + while (!feof(pipe)) + { + // use buffer to read and add to result + if (fgets(buffer, 128, pipe) != NULL) + result += buffer; + } + pclose(pipe); + std::string verifyok("Verified OK\n"); + if (result.compare(verifyok) != 0) + { + std::cout << "libteecc '" + global_clientkey_path + "' is not matched with '" + global_clientcert_path + "'" + << std::endl; + return TEEC_FAIL; + } + + auto clientkey = get_file_contents(nopass_clientkey_path); + strcmd = "rm -f " + global_clientkey_path + ".nopass"; + system(strcmd.c_str()); + strcmd = "rm -f " + pubkeyfile_path; + system(strcmd.c_str()); + strcmd = "rm -f " + sigfile_path; + system(strcmd.c_str()); + + auto servercacert = get_file_contents(global_servercacert_path); + auto clientcert = get_file_contents(global_clientcert_path); + grpc::SslCredentialsOptions ssl_opts; + ssl_opts.pem_root_certs = servercacert; + ssl_opts.pem_private_key = clientkey; + ssl_opts.pem_cert_chain = clientcert; + std::shared_ptr creds = grpc::SslCredentials(ssl_opts); + gpp_channel = grpc::CreateChannel(global_target_str, creds); + + break; + } + + default: + { + gpp_channel = grpc::CreateChannel(global_target_str, grpc::InsecureChannelCredentials()); + } + } + + client = new GppClient( + gpp_channel + ); + } + + iret = client->Upload(str_infile_path, str_subdir, str_outfile_name); + + return (TEEC_Result) iret; +} + + +TEEC_Result +TEEC_SetJwt( + char *token +) +{ + if (token == NULL || sizeof(token) > 1024) + { + return TEEC_FAIL; + } + + memset(glo_token, '\0', sizeof(glo_token)); + strcpy(glo_token, token); + + return TEEC_SUCCESS; +} + + +TEEC_Result +TEEC_UnsetJwt( +) +{ + memset(glo_token, '\0', sizeof(glo_token)); + strcpy(glo_token, "noToken"); + + return TEEC_SUCCESS; +} + + +#ifdef __cplusplus +}; +#endif diff --git a/teeproxy/libteecc/teecc.h b/teeproxy/libteecc/teecc.h new file mode 100644 index 0000000000000000000000000000000000000000..47abd0f7868f7130a4216db3abd5c767ca7769f2 --- /dev/null +++ b/teeproxy/libteecc/teecc.h @@ -0,0 +1,351 @@ +#ifndef _TEECC_H +#define _TEECC_H + +#include + +struct retstru_teec_inicont { + uint32_t teecresult; + int32_t context_fd; + uint8_t *context_tapath; + uintptr_t context_tapath_outsize; + uint64_t context_sessionlist_next; + uint64_t context_sessionlist_prev; + uint64_t context_shrdmemlist_next; + uint64_t context_shrdmemlist_prev; + uint64_t context_sharebuffer_buffer; + int64_t context_sharebuffer_bufferbarrier; + uint64_t context_addr; + int32_t flag; +}; + +struct retstru_teec_fincont { + int32_t context_fd; + uint8_t *context_tapath; + uintptr_t context_tapath_outsize; + uint64_t context_sessionlist_next; + uint64_t context_sessionlist_prev; + uint64_t context_shrdmemlist_next; + uint64_t context_shrdmemlist_prev; + uint64_t context_sharebuffer_buffer; + int64_t context_sharebuffer_bufferbarrier; + int32_t flag; +}; + +struct retstru_teec_opensession { + uint32_t teecresult; + int32_t context_fd; + uint8_t *context_tapath; + uintptr_t context_tapath_outsize; + uint64_t context_sessionlist_next; + uint64_t context_sessionlist_prev; + uint64_t context_shrdmemlist_next; + uint64_t context_shrdmemlist_prev; + uint64_t context_sharebuffer_buffer; + int64_t context_sharebuffer_bufferbarrier; + uint32_t session_sessionid; + uint32_t session_serviceid_timelow; + uint32_t session_serviceid_timemid; + uint32_t session_serviceid_timehiandver; + uint8_t *session_serviceid_clockseqandnode; + uintptr_t session_serviceid_clockseqandnode_outsize; + uint32_t session_opscnt; + uint64_t session_head_next; + uint64_t session_head_prev; + uint64_t session_context; + uint32_t operation_started; + uint32_t operation_paramtypes; + uint64_t operation_param1_tmpref_buffer; + uint32_t operation_param1_tmpref_size; + uint64_t operation_param1_memref_parent; + uint32_t operation_param1_memref_size; + uint32_t operation_param1_memref_offset; + uint32_t operation_param1_value_a; + uint32_t operation_param1_value_b; + int32_t operation_param1_ionref_ionsharefd; + uint32_t operation_param1_ionref_ionsize; + uint64_t operation_param2_tmpref_buffer; + uint32_t operation_param2_tmpref_size; + uint64_t operation_param2_memref_parent; + uint32_t operation_param2_memref_size; + uint32_t operation_param2_memref_offset; + uint32_t operation_param2_value_a; + uint32_t operation_param2_value_b; + int32_t operation_param2_ionref_ionsharefd; + uint32_t operation_param2_ionref_ionsize; + uint64_t operation_param3_tmpref_buffer; + uint32_t operation_param3_tmpref_size; + uint64_t operation_param3_memref_parent; + uint32_t operation_param3_memref_size; + uint32_t operation_param3_memref_offset; + uint32_t operation_param3_value_a; + uint32_t operation_param3_value_b; + int32_t operation_param3_ionref_ionsharefd; + uint32_t operation_param3_ionref_ionsize; + uint64_t operation_param4_tmpref_buffer; + uint32_t operation_param4_tmpref_size; + uint64_t operation_param4_memref_parent; + uint32_t operation_param4_memref_size; + uint32_t operation_param4_memref_offset; + uint32_t operation_param4_value_a; + uint32_t operation_param4_value_b; + int32_t operation_param4_ionref_ionsharefd; + uint32_t operation_param4_ionref_ionsize; + uint64_t operation_session; + int32_t operation_cancelflag; + uint32_t returnorigin; + int32_t flag; + +}; + +struct retstru_teec_closesession { + uint32_t session_sessionid; + uint32_t session_serviceid_timelow; + uint32_t session_serviceid_timemid; + uint32_t session_serviceid_timehiandver; + uint8_t *session_serviceid_clockseqandnode; + uintptr_t session_serviceid_clockseqandnode_outsize; + uint32_t session_opscnt; + uint64_t session_head_next; + uint64_t session_head_prev; + uint64_t session_context; + int32_t flag; + +}; + +struct retstru_teec_invokecommand { + uint32_t teecresult; + uint32_t session_sessionid; + uint32_t session_serviceid_timelow; + uint32_t session_serviceid_timemid; + uint32_t session_serviceid_timehiandver; + uint8_t *session_serviceid_clockseqandnode; + uintptr_t session_serviceid_clockseqandnode_outsize; + uint32_t session_opscnt; + uint64_t session_head_next; + uint64_t session_head_prev; + uint64_t session_context; + uint32_t operation_started; + uint32_t operation_paramtypes; + uint64_t operation_param1_tmpref_buffer; + uint32_t operation_param1_tmpref_size; + uint64_t operation_param1_memref_parent; + uint32_t operation_param1_memref_parent_flag; + uint32_t operation_param1_memref_size; + uint32_t operation_param1_memref_offset; + uint32_t operation_param1_value_a; + uint32_t operation_param1_value_b; + int32_t operation_param1_ionref_ionsharefd; + uint32_t operation_param1_ionref_ionsize; + uint64_t operation_param2_tmpref_buffer; + uint32_t operation_param2_tmpref_size; + uint64_t operation_param2_memref_parent; + uint32_t operation_param2_memref_parent_flag; + uint32_t operation_param2_memref_size; + uint32_t operation_param2_memref_offset; + uint32_t operation_param2_value_a; + uint32_t operation_param2_value_b; + int32_t operation_param2_ionref_ionsharefd; + uint32_t operation_param2_ionref_ionsize; + uint64_t operation_param3_tmpref_buffer; + uint32_t operation_param3_tmpref_size; + uint64_t operation_param3_memref_parent; + uint32_t operation_param3_memref_parent_flag; + uint32_t operation_param3_memref_size; + uint32_t operation_param3_memref_offset; + uint32_t operation_param3_value_a; + uint32_t operation_param3_value_b; + int32_t operation_param3_ionref_ionsharefd; + uint32_t operation_param3_ionref_ionsize; + uint64_t operation_param4_tmpref_buffer; + uint32_t operation_param4_tmpref_size; + uint64_t operation_param4_memref_parent; + uint32_t operation_param4_memref_parent_flag; + uint32_t operation_param4_memref_size; + uint32_t operation_param4_memref_offset; + uint32_t operation_param4_value_a; + uint32_t operation_param4_value_b; + int32_t operation_param4_ionref_ionsharefd; + uint32_t operation_param4_ionref_ionsize; + uint64_t operation_session; + int32_t operation_cancelflag; + uint32_t returnorigin; + uint8_t *buffer1; + uintptr_t buffer1_outsize; + uint8_t *buffer2; + uintptr_t buffer2_outsize; + uint8_t *buffer3; + uintptr_t buffer3_outsize; + uint8_t *buffer4; + uintptr_t buffer4_outsize; + int32_t flag; +}; + + +struct retstru_teec_inicont externc_teec_initializecontext(uint8_t *name, + uint32_t name_size, + int32_t in_context_fd, + uint8_t *in_context_tapath, + int32_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier); + +void externc_retstru_teec_inicont_free(struct retstru_teec_inicont rs_ins); + +struct retstru_teec_fincont externc_teec_finalizecontext(int32_t in_context_fd, + uint8_t *in_context_tapath, + int32_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + uint64_t in_context_addr); + +void externc_retstru_teec_fincont_free(struct retstru_teec_fincont rs_ins); + +struct retstru_teec_opensession externc_teec_opensession(int32_t in_context_fd, + uint8_t *in_context_tapath, + int32_t in_context_tapath_size, + uint64_t in_context_sessionlist_next, + uint64_t in_context_sessionlist_prev, + uint64_t in_context_shrdmemlist_next, + uint64_t in_context_shrdmemlist_prev, + uint64_t in_context_sharebuffer_buffer, + int64_t in_context_sharebuffer_bufferbarrier, + uint32_t in_destination_timelow, + uint32_t in_destination_timemid, + uint32_t in_destination_timehiandver, + uint8_t *in_destination_clockseqandnode, + int32_t in_destination_clockseqandnode_size, + uint32_t in_connectionmethod, + uint64_t in_connectiondata, + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + uint32_t in_returnorigin, + uint64_t in_context_addr); + +void externc_retstru_teec_opensession_free(struct retstru_teec_opensession rs_ins); + +struct retstru_teec_closesession externc_teec_closesession(uint32_t in_session_sessionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint8_t *in_session_serviceid_clockseqandnode, + uintptr_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context); + +void externc_retstru_teec_closesession_free(struct retstru_teec_closesession rs_ins); + +struct retstru_teec_invokecommand externc_teec_invokecommand(uint32_t in_session_sessionid, + uint32_t in_session_serviceid_timelow, + uint32_t in_session_serviceid_timemid, + uint32_t in_session_serviceid_timehiandver, + uint8_t *in_session_serviceid_clockseqandnode, + uintptr_t in_session_serviceid_clockseqandnode_size, + uint32_t in_session_opscnt, + uint64_t in_session_head_next, + uint64_t in_session_head_prev, + uint64_t in_session_context, + uint32_t in_commandid, + uint32_t in_operation_started, + uint32_t in_operation_paramtypes, + uint64_t in_operation_param1_tmpref_buffer, + uint32_t in_operation_param1_tmpref_size, + uint64_t in_operation_param1_memref_parent, + uint32_t in_operation_param1_memref_parent_flag, + uint32_t in_operation_param1_memref_size, + uint32_t in_operation_param1_memref_offset, + uint32_t in_operation_param1_value_a, + uint32_t in_operation_param1_value_b, + int32_t in_operation_param1_ionref_ionsharefd, + uint32_t in_operation_param1_ionref_ionsize, + uint64_t in_operation_param2_tmpref_buffer, + uint32_t in_operation_param2_tmpref_size, + uint64_t in_operation_param2_memref_parent, + uint32_t in_operation_param2_memref_parent_flag, + uint32_t in_operation_param2_memref_size, + uint32_t in_operation_param2_memref_offset, + uint32_t in_operation_param2_value_a, + uint32_t in_operation_param2_value_b, + int32_t in_operation_param2_ionref_ionsharefd, + uint32_t in_operation_param2_ionref_ionsize, + uint64_t in_operation_param3_tmpref_buffer, + uint32_t in_operation_param3_tmpref_size, + uint64_t in_operation_param3_memref_parent, + uint32_t in_operation_param3_memref_parent_flag, + uint32_t in_operation_param3_memref_size, + uint32_t in_operation_param3_memref_offset, + uint32_t in_operation_param3_value_a, + uint32_t in_operation_param3_value_b, + int32_t in_operation_param3_ionref_ionsharefd, + uint32_t in_operation_param3_ionref_ionsize, + uint64_t in_operation_param4_tmpref_buffer, + uint32_t in_operation_param4_tmpref_size, + uint64_t in_operation_param4_memref_parent, + uint32_t in_operation_param4_memref_parent_flag, + uint32_t in_operation_param4_memref_size, + uint32_t in_operation_param4_memref_offset, + uint32_t in_operation_param4_value_a, + uint32_t in_operation_param4_value_b, + int32_t in_operation_param4_ionref_ionsharefd, + uint32_t in_operation_param4_ionref_ionsize, + uint64_t in_operation_session, + int32_t in_operation_cancelflag, + uint32_t in_returnorigin, + uint8_t *in_buffer1, + uintptr_t in_buffer1_size, + uint8_t *in_buffer2, + uintptr_t in_buffer2_size, + uint8_t *in_buffer3, + uintptr_t in_buffer3_size, + uint8_t *in_buffer4, + uintptr_t in_buffer4_size); + +void externc_retstru_teec_invokecommand_free(struct retstru_teec_invokecommand rs_ins); +#endif // _TEECC_H \ No newline at end of file