• 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 #include <errno.h>
13 #include <ipclib.h>
14 #include <securec.h>
15 #include <pthread.h>
16 #include <tee_log.h>
17 #include <tee_ext_api.h>
18 #include "huk_service_msg_call.h"
19 
20 static pthread_mutex_t g_msg_call_mutex = PTHREAD_MUTEX_INITIALIZER;
huk_srv_msg_call(struct huk_srv_msg * msg,struct huk_srv_rsp * rsp)21 int32_t huk_srv_msg_call(struct huk_srv_msg *msg, struct huk_srv_rsp *rsp)
22 {
23     errno_t rc;
24     cref_t rslot = 0;
25 
26     if (msg == NULL || rsp == NULL) {
27         tloge("msg or rsp is NULL\n");
28         return -1;
29     }
30 
31     if (pthread_mutex_lock(&g_msg_call_mutex) != 0) {
32         tloge("huk msg call mutex lock failed\n");
33         return -1;
34     }
35     rc = ipc_get_ch_from_path(HUK_PATH, &rslot);
36     if (rc == -1) {
37         tloge("huksrv: get channel from pathmgr failed\n");
38         if (pthread_mutex_unlock(&g_msg_call_mutex) != 0)
39             tloge("huk msg call mutex unlock failed\n");
40         return rc;
41     }
42 
43     rc = ipc_msg_call(rslot, msg, sizeof(*msg), rsp, sizeof(*rsp), -1);
44     if (rc < 0)
45         tloge("msg send 0x%llx failed: 0x%x\n", rslot, rc);
46 
47     (void)ipc_release_from_path(HUK_PATH, rslot);
48     if (pthread_mutex_unlock(&g_msg_call_mutex) != 0) {
49         tloge("huk msg call mutex unlock failed\n");
50         return -1;
51     }
52     return rc;
53 }
54 
55