• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 Huawei Technologies Co., Ltd.
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #include "client_session_mgr.h"
14 #include <test_log.h>
15 
ClientSessionMgr()16 ClientSessionMgr::ClientSessionMgr()
17 {
18     initTag = false;
19 }
20 
Start(TEEC_UUID * uuid)21 TEEC_Result ClientSessionMgr::Start(TEEC_UUID *uuid)
22 {
23     TEEC_Result result;
24     TEEC_Operation operation = { 0 };
25 
26     result = TEEC_InitializeContext(NULL, &context);
27     if (result != TEEC_SUCCESS) {
28         TEST_PRINT_ERROR("TEEC_InitializeContext failed\n");
29         return result;
30     }
31 
32     operation.started = 1;
33     operation.paramTypes = TEEC_PARAM_TYPES(TEEC_NONE, TEEC_NONE, TEEC_NONE, TEEC_NONE);
34 
35     char str[64] = { 0 };
36     sprintf(str,"/data/local/tmp/%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x.sec", uuid->timeLow, uuid->timeMid,
37         uuid->timeHiAndVersion, uuid->clockSeqAndNode[0], uuid->clockSeqAndNode[1], uuid->clockSeqAndNode[2],
38         uuid->clockSeqAndNode[3], uuid->clockSeqAndNode[4], uuid->clockSeqAndNode[5], uuid->clockSeqAndNode[6],
39         uuid->clockSeqAndNode[7]);
40     context.ta_path = (uint8_t *)str;
41     result = TEEC_OpenSession(&context, &session, uuid, TEEC_LOGIN_IDENTIFY, NULL, &operation, NULL);
42     if (result != TEEC_SUCCESS) {
43         TEEC_FinalizeContext(&context);
44         TEST_PRINT_INFO("TEEC_OpenSession failed\n");
45     } else {
46         initTag = true;
47     }
48 
49     return result;
50 }
51 
Destroy()52 void ClientSessionMgr::Destroy()
53 {
54     if (initTag) {
55         TEEC_CloseSession(&session);
56         TEEC_FinalizeContext(&context);
57 
58         session = { 0 };
59         context = { 0 };
60         initTag = false;
61     }
62 }
63 
~ClientSessionMgr()64 ClientSessionMgr::~ClientSessionMgr()
65 {
66     Destroy();
67 }
68 
ClientShareMemMgr()69 ClientShareMemMgr::ClientShareMemMgr()
70 {
71 }
72 
Destroy()73 void ClientShareMemMgr::Destroy()
74 {
75     if (sharedMem.buffer != NULL) {
76         TEEC_ReleaseSharedMemory(&sharedMem);
77         sharedMem = { 0 };
78     }
79 }
80 
~ClientShareMemMgr()81 ClientShareMemMgr::~ClientShareMemMgr()
82 {
83     Destroy();
84 }