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 "tee_service_public.h"
13 #include <securec.h>
14 #include "ta_framework.h"
15 #include "tee_log.h"
16 #include "ipclib.h"
17
tee_common_ipc_proc_cmd(const char * task_name,uint32_t snd_cmd,const tee_service_ipc_msg * snd_msg,uint32_t ack_cmd,tee_service_ipc_msg_rsp * rsp_msg)18 void tee_common_ipc_proc_cmd(const char *task_name,
19 uint32_t snd_cmd, const tee_service_ipc_msg *snd_msg,
20 uint32_t ack_cmd, tee_service_ipc_msg_rsp *rsp_msg)
21 {
22 #ifdef CONFIG_TEE_DYN_CLIENT_STUB
23 (void)task_name;
24 (void)snd_cmd;
25 (void)snd_msg;
26 (void)ack_cmd;
27 (void)rsp_msg;
28 #else
29 int32_t ret;
30 cref_t ch = 0;
31 struct tee_service_ipc_msg_req req_msg = {0};
32
33 if (task_name == NULL || snd_msg == NULL || rsp_msg == NULL)
34 return;
35
36 (void)ack_cmd;
37 req_msg.cmd = snd_cmd;
38 errno_t rc = memcpy_s(&req_msg.msg, sizeof(req_msg.msg), snd_msg, sizeof(*snd_msg));
39 if (rc != EOK) {
40 tloge("msg cpy failed, task=%s, rc=%d\n", task_name, rc);
41 return;
42 }
43
44 ret = ipc_get_ch_from_path(task_name, &ch);
45 if (ret != 0) {
46 tloge("get ch from pathmgr failed, task=%s, ret=0x%x\n", task_name, ret);
47 return;
48 }
49
50 ret = ipc_msg_call(ch, &req_msg, sizeof(req_msg), rsp_msg, sizeof(*rsp_msg), OS_WAIT_FOREVER);
51 if (ret != 0)
52 tloge("msg send to 0x%llx failed: 0x%x\n", ch, ret);
53
54 ret = (int32_t)ipc_release_from_path(task_name, ch);
55 if (ret != 0) {
56 tloge("release path failed, task=%s, ret=0x%x\n", task_name, ret);
57 return;
58 }
59 #endif
60 }
61