1060ff233Sopenharmony_ci/*
2060ff233Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
3060ff233Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4060ff233Sopenharmony_ci * you may not use this file except in compliance with the License.
5060ff233Sopenharmony_ci * You may obtain a copy of the License at
6060ff233Sopenharmony_ci *
7060ff233Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8060ff233Sopenharmony_ci *
9060ff233Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10060ff233Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11060ff233Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12060ff233Sopenharmony_ci * See the License for the specific language governing permissions and
13060ff233Sopenharmony_ci * limitations under the License.
14060ff233Sopenharmony_ci */
15060ff233Sopenharmony_ci
16060ff233Sopenharmony_ci#include "trans_server_proxy.h"
17060ff233Sopenharmony_ci
18060ff233Sopenharmony_ci#include "iproxy_client.h"
19060ff233Sopenharmony_ci#include "samgr_lite.h"
20060ff233Sopenharmony_ci#include "serializer.h"
21060ff233Sopenharmony_ci#include "softbus_adapter_file.h"
22060ff233Sopenharmony_ci#include "softbus_adapter_mem.h"
23060ff233Sopenharmony_ci#include "softbus_adapter_timer.h"
24060ff233Sopenharmony_ci#include "softbus_def.h"
25060ff233Sopenharmony_ci#include "softbus_errcode.h"
26060ff233Sopenharmony_ci#include "softbus_server_ipc_interface_code.h"
27060ff233Sopenharmony_ci#include "trans_log.h"
28060ff233Sopenharmony_ci
29060ff233Sopenharmony_ci#define WAIT_SERVER_READY_INTERVAL_COUNT 50
30060ff233Sopenharmony_ci
31060ff233Sopenharmony_cistatic IClientProxy *g_serverProxy = NULL;
32060ff233Sopenharmony_ci
33060ff233Sopenharmony_cistatic int ProxyCallback(IOwner owner, int code, IpcIo *reply)
34060ff233Sopenharmony_ci{
35060ff233Sopenharmony_ci    if (code != SOFTBUS_OK) {
36060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "publish service callback errCode=%{public}d.", code);
37060ff233Sopenharmony_ci        return SOFTBUS_INVALID_PARAM;
38060ff233Sopenharmony_ci    }
39060ff233Sopenharmony_ci
40060ff233Sopenharmony_ci    ReadInt32(reply, (int *)owner);
41060ff233Sopenharmony_ci    TRANS_LOGI(TRANS_SDK, "publish service owner=%{public}d.", *(int32_t*)owner);
42060ff233Sopenharmony_ci    return SOFTBUS_OK;
43060ff233Sopenharmony_ci}
44060ff233Sopenharmony_ci
45060ff233Sopenharmony_cistatic int OpenSessionProxyCallback(IOwner owner, int code, IpcIo *reply)
46060ff233Sopenharmony_ci{
47060ff233Sopenharmony_ci    if (code != SOFTBUS_OK) {
48060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "publish service callback errCode=%{public}d.", code);
49060ff233Sopenharmony_ci        return SOFTBUS_INVALID_PARAM;
50060ff233Sopenharmony_ci    }
51060ff233Sopenharmony_ci    uint32_t size;
52060ff233Sopenharmony_ci    ReadUint32(reply, &size);
53060ff233Sopenharmony_ci    void *data = (void *)ReadBuffer(reply, size);
54060ff233Sopenharmony_ci    if (data == NULL) {
55060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "pop data is null.");
56060ff233Sopenharmony_ci        return SOFTBUS_MEM_ERR;
57060ff233Sopenharmony_ci    }
58060ff233Sopenharmony_ci    *(TransSerializer *)owner = *(TransSerializer *)data;
59060ff233Sopenharmony_ci    return SOFTBUS_OK;
60060ff233Sopenharmony_ci}
61060ff233Sopenharmony_ci
62060ff233Sopenharmony_cistatic bool WriteQosInfo(IpcIo *request, const SessionParam *param)
63060ff233Sopenharmony_ci{
64060ff233Sopenharmony_ci    if (!WriteBool(request, param->isQosLane)) {
65060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "OpenSession write qos flag failed!");
66060ff233Sopenharmony_ci        return false;
67060ff233Sopenharmony_ci    }
68060ff233Sopenharmony_ci
69060ff233Sopenharmony_ci    if (!param->isQosLane) {
70060ff233Sopenharmony_ci        return true;
71060ff233Sopenharmony_ci    }
72060ff233Sopenharmony_ci
73060ff233Sopenharmony_ci    if (!WriteUint32(request, param->qosCount)) {
74060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "OpenSession write count of qos failed!");
75060ff233Sopenharmony_ci        return false;
76060ff233Sopenharmony_ci    }
77060ff233Sopenharmony_ci
78060ff233Sopenharmony_ci    if (param->qosCount > 0) {
79060ff233Sopenharmony_ci        if (!WriteBuffer(request, param->qos, sizeof(QosTV) * param->qosCount)) {
80060ff233Sopenharmony_ci            TRANS_LOGE(TRANS_SDK, "OpenSession write qos info failed!");
81060ff233Sopenharmony_ci            return false;
82060ff233Sopenharmony_ci        }
83060ff233Sopenharmony_ci    }
84060ff233Sopenharmony_ci
85060ff233Sopenharmony_ci    return true;
86060ff233Sopenharmony_ci}
87060ff233Sopenharmony_ci
88060ff233Sopenharmony_ciint32_t TransServerProxyInit(void)
89060ff233Sopenharmony_ci{
90060ff233Sopenharmony_ci    if (g_serverProxy != NULL) {
91060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_INIT, "server proxy has init.");
92060ff233Sopenharmony_ci        return SOFTBUS_NO_INIT;
93060ff233Sopenharmony_ci    }
94060ff233Sopenharmony_ci
95060ff233Sopenharmony_ci    TRANS_LOGI(TRANS_INIT, "get trans server proxy");
96060ff233Sopenharmony_ci    int32_t proxyInitCount = 0;
97060ff233Sopenharmony_ci    while (g_serverProxy == NULL) {
98060ff233Sopenharmony_ci        proxyInitCount++;
99060ff233Sopenharmony_ci        if (proxyInitCount == WAIT_SERVER_READY_INTERVAL_COUNT) {
100060ff233Sopenharmony_ci            TRANS_LOGE(TRANS_SDK, "trans get server proxy error");
101060ff233Sopenharmony_ci            return SOFTBUS_OK;
102060ff233Sopenharmony_ci        }
103060ff233Sopenharmony_ci        IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SOFTBUS_SERVICE);
104060ff233Sopenharmony_ci        if (iUnknown == NULL) {
105060ff233Sopenharmony_ci            SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
106060ff233Sopenharmony_ci            continue;
107060ff233Sopenharmony_ci        }
108060ff233Sopenharmony_ci
109060ff233Sopenharmony_ci        int32_t ret = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&g_serverProxy);
110060ff233Sopenharmony_ci        if (ret != EC_SUCCESS || g_serverProxy == NULL) {
111060ff233Sopenharmony_ci            TRANS_LOGE(TRANS_SDK, "QueryInterface failed ret=%{public}d", ret);
112060ff233Sopenharmony_ci            SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
113060ff233Sopenharmony_ci            continue;
114060ff233Sopenharmony_ci        }
115060ff233Sopenharmony_ci    }
116060ff233Sopenharmony_ci    return SOFTBUS_OK;
117060ff233Sopenharmony_ci}
118060ff233Sopenharmony_ci
119060ff233Sopenharmony_civoid TransServerProxyDeInit(void)
120060ff233Sopenharmony_ci{
121060ff233Sopenharmony_ci    g_serverProxy = NULL;
122060ff233Sopenharmony_ci}
123060ff233Sopenharmony_ci
124060ff233Sopenharmony_ciint32_t ServerIpcCreateSessionServer(const char *pkgName, const char *sessionName)
125060ff233Sopenharmony_ci{
126060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "enter.");
127060ff233Sopenharmony_ci    if ((pkgName == NULL) || (sessionName == NULL)) {
128060ff233Sopenharmony_ci        TRANS_LOGW(TRANS_SDK, "Invalid param");
129060ff233Sopenharmony_ci        return SOFTBUS_INVALID_PARAM;
130060ff233Sopenharmony_ci    }
131060ff233Sopenharmony_ci
132060ff233Sopenharmony_ci    uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
133060ff233Sopenharmony_ci    IpcIo request = {0};
134060ff233Sopenharmony_ci    IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
135060ff233Sopenharmony_ci    WriteString(&request, pkgName);
136060ff233Sopenharmony_ci    WriteString(&request, sessionName);
137060ff233Sopenharmony_ci
138060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_NO_INIT;
139060ff233Sopenharmony_ci    /* sync */
140060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
141060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
142060ff233Sopenharmony_ci        return ret;
143060ff233Sopenharmony_ci    }
144060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_CREATE_SESSION_SERVER, &request, &ret, ProxyCallback);
145060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
146060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", ret);
147060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_INVOKE_FAILED;
148060ff233Sopenharmony_ci    }
149060ff233Sopenharmony_ci    return ret;
150060ff233Sopenharmony_ci}
151060ff233Sopenharmony_ci
152060ff233Sopenharmony_ciint32_t ServerIpcRemoveSessionServer(const char *pkgName, const char *sessionName)
153060ff233Sopenharmony_ci{
154060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "enter.");
155060ff233Sopenharmony_ci    if ((pkgName == NULL) || (sessionName == NULL)) {
156060ff233Sopenharmony_ci        TRANS_LOGW(TRANS_SDK, "Invalid param");
157060ff233Sopenharmony_ci        return SOFTBUS_INVALID_PARAM;
158060ff233Sopenharmony_ci    }
159060ff233Sopenharmony_ci
160060ff233Sopenharmony_ci    uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
161060ff233Sopenharmony_ci    IpcIo request = {0};
162060ff233Sopenharmony_ci    IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
163060ff233Sopenharmony_ci    WriteString(&request, pkgName);
164060ff233Sopenharmony_ci    WriteString(&request, sessionName);
165060ff233Sopenharmony_ci
166060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_NO_INIT;
167060ff233Sopenharmony_ci    /* sync */
168060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
169060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
170060ff233Sopenharmony_ci        return ret;
171060ff233Sopenharmony_ci    }
172060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_REMOVE_SESSION_SERVER, &request, &ret, ProxyCallback);
173060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
174060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", ret);
175060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_INVOKE_FAILED;
176060ff233Sopenharmony_ci    }
177060ff233Sopenharmony_ci    return ret;
178060ff233Sopenharmony_ci}
179060ff233Sopenharmony_ci
180060ff233Sopenharmony_cistatic bool TransWriteIpcSessionAttrs(IpcIo *request, const SessionAttribute *attrs)
181060ff233Sopenharmony_ci{
182060ff233Sopenharmony_ci    if (attrs == NULL || request == NULL) {
183060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "attrs is NULL!");
184060ff233Sopenharmony_ci        return false;
185060ff233Sopenharmony_ci    }
186060ff233Sopenharmony_ci
187060ff233Sopenharmony_ci    if (!WriteInt32(request, attrs->dataType)) {
188060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "OpenSession write my attrs dataType failed!");
189060ff233Sopenharmony_ci        return false;
190060ff233Sopenharmony_ci    }
191060ff233Sopenharmony_ci
192060ff233Sopenharmony_ci    if (!WriteInt32(request, attrs->linkTypeNum)) {
193060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "OpenSession write my attrs linkTypeNum failed!");
194060ff233Sopenharmony_ci        return false;
195060ff233Sopenharmony_ci    }
196060ff233Sopenharmony_ci
197060ff233Sopenharmony_ci    if (attrs->linkTypeNum > 0) {
198060ff233Sopenharmony_ci        if (!WriteBuffer(request, attrs->linkType, sizeof(LinkType) * attrs->linkTypeNum)) {
199060ff233Sopenharmony_ci            TRANS_LOGE(TRANS_SDK, "OpenSession write my attrs linkType failed!");
200060ff233Sopenharmony_ci            return false;
201060ff233Sopenharmony_ci        }
202060ff233Sopenharmony_ci    }
203060ff233Sopenharmony_ci
204060ff233Sopenharmony_ci    if (!WriteInt32(request, attrs->attr.streamAttr.streamType)) {
205060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "OpenSession write my attrs streamAttr failed!");
206060ff233Sopenharmony_ci        return false;
207060ff233Sopenharmony_ci    }
208060ff233Sopenharmony_ci
209060ff233Sopenharmony_ci    if (attrs->fastTransData != NULL) {
210060ff233Sopenharmony_ci        if (!WriteUint16(request, attrs->fastTransDataSize)) {
211060ff233Sopenharmony_ci            TRANS_LOGE(TRANS_SDK, "OpenSession write my attrs fastTransDataSize failed!");
212060ff233Sopenharmony_ci            return false;
213060ff233Sopenharmony_ci        }
214060ff233Sopenharmony_ci        if (!WriteRawData(request, attrs->fastTransData, attrs->fastTransDataSize)) {
215060ff233Sopenharmony_ci            TRANS_LOGE(TRANS_SDK, "OpenSession write my attrs fastTransData failed!");
216060ff233Sopenharmony_ci            return false;
217060ff233Sopenharmony_ci        }
218060ff233Sopenharmony_ci    } else {
219060ff233Sopenharmony_ci        if (!WriteUint16(request, 0)) {
220060ff233Sopenharmony_ci            TRANS_LOGE(TRANS_SDK, "OpenSession write my attrs fastTransDataSize failed!");
221060ff233Sopenharmony_ci            return false;
222060ff233Sopenharmony_ci        }
223060ff233Sopenharmony_ci    }
224060ff233Sopenharmony_ci
225060ff233Sopenharmony_ci    return true;
226060ff233Sopenharmony_ci}
227060ff233Sopenharmony_ci
228060ff233Sopenharmony_ciint32_t ServerIpcOpenSession(const SessionParam *param, TransInfo *info)
229060ff233Sopenharmony_ci{
230060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "enter.");
231060ff233Sopenharmony_ci    uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
232060ff233Sopenharmony_ci    IpcIo request = {0};
233060ff233Sopenharmony_ci    IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
234060ff233Sopenharmony_ci    WriteString(&request, param->sessionName);
235060ff233Sopenharmony_ci    WriteString(&request, param->peerSessionName);
236060ff233Sopenharmony_ci    WriteString(&request, param->peerDeviceId);
237060ff233Sopenharmony_ci    WriteString(&request, param->groupId);
238060ff233Sopenharmony_ci    WriteBool(&request, param->isAsync);
239060ff233Sopenharmony_ci    WriteInt32(&request, param->sessionId);
240060ff233Sopenharmony_ci    if (!TransWriteIpcSessionAttrs(&request, param->attr)) {
241060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "OpenSession write attr failed!");
242060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_WRITERAWDATA_FAILED;
243060ff233Sopenharmony_ci    }
244060ff233Sopenharmony_ci
245060ff233Sopenharmony_ci    if (!WriteQosInfo(&request, param)) {
246060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "OpenSession write qosinfo failed!");
247060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_WRITERAWDATA_FAILED;
248060ff233Sopenharmony_ci    }
249060ff233Sopenharmony_ci
250060ff233Sopenharmony_ci    TransSerializer transSerializer;
251060ff233Sopenharmony_ci    transSerializer.ret = SOFTBUS_NO_INIT;
252060ff233Sopenharmony_ci    /* sync */
253060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
254060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
255060ff233Sopenharmony_ci        return transSerializer.ret;
256060ff233Sopenharmony_ci    }
257060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_OPEN_SESSION, &request,
258060ff233Sopenharmony_ci        &transSerializer, OpenSessionProxyCallback);
259060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
260060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", transSerializer.ret);
261060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_INVOKE_FAILED;
262060ff233Sopenharmony_ci    }
263060ff233Sopenharmony_ci    if (param->isAsync) {
264060ff233Sopenharmony_ci        return transSerializer.ret;
265060ff233Sopenharmony_ci    }
266060ff233Sopenharmony_ci    info->channelId = transSerializer.transInfo.channelId;
267060ff233Sopenharmony_ci    info->channelType = transSerializer.transInfo.channelType;
268060ff233Sopenharmony_ci    return transSerializer.ret;
269060ff233Sopenharmony_ci}
270060ff233Sopenharmony_ci
271060ff233Sopenharmony_ciint32_t ServerIpcOpenAuthSession(const char *sessionName, const ConnectionAddr *addrInfo)
272060ff233Sopenharmony_ci{
273060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "enter.");
274060ff233Sopenharmony_ci    uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
275060ff233Sopenharmony_ci    IpcIo request = {0};
276060ff233Sopenharmony_ci    IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
277060ff233Sopenharmony_ci    WriteString(&request, sessionName);
278060ff233Sopenharmony_ci    bool value = WriteRawData(&request, (void*)addrInfo, sizeof(ConnectionAddr));
279060ff233Sopenharmony_ci    if (!value) {
280060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_WRITERAWDATA_FAILED;
281060ff233Sopenharmony_ci    }
282060ff233Sopenharmony_ci
283060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_NO_INIT;
284060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
285060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
286060ff233Sopenharmony_ci        return ret;
287060ff233Sopenharmony_ci    }
288060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_OPEN_AUTH_SESSION, &request, &ret, ProxyCallback);
289060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
290060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", ret);
291060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_INVOKE_FAILED;
292060ff233Sopenharmony_ci    }
293060ff233Sopenharmony_ci    return ret;
294060ff233Sopenharmony_ci}
295060ff233Sopenharmony_ci
296060ff233Sopenharmony_ciint32_t ServerIpcNotifyAuthSuccess(int32_t channelId, int32_t channelType)
297060ff233Sopenharmony_ci{
298060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "enter.");
299060ff233Sopenharmony_ci    uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
300060ff233Sopenharmony_ci    IpcIo request = {0};
301060ff233Sopenharmony_ci    IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
302060ff233Sopenharmony_ci    WriteInt32(&request, channelId);
303060ff233Sopenharmony_ci    WriteInt32(&request, channelType);
304060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_NO_INIT;
305060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
306060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
307060ff233Sopenharmony_ci        return ret;
308060ff233Sopenharmony_ci    }
309060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_NOTIFY_AUTH_SUCCESS, &request, &ret, ProxyCallback);
310060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
311060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", ret);
312060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_INVOKE_FAILED;
313060ff233Sopenharmony_ci    }
314060ff233Sopenharmony_ci    return ret;
315060ff233Sopenharmony_ci}
316060ff233Sopenharmony_ci
317060ff233Sopenharmony_ciint32_t ServerIpcReleaseResources(int32_t channelId)
318060ff233Sopenharmony_ci{
319060ff233Sopenharmony_ci    uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
320060ff233Sopenharmony_ci    IpcIo request = {0};
321060ff233Sopenharmony_ci    IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
322060ff233Sopenharmony_ci    WriteInt32(&request, channelId);
323060ff233Sopenharmony_ci
324060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_NO_INIT;
325060ff233Sopenharmony_ci    /* sync */
326060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
327060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
328060ff233Sopenharmony_ci        return ret;
329060ff233Sopenharmony_ci    }
330060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_RELEASE_RESOURCES, &request, &ret, ProxyCallback);
331060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
332060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", ret);
333060ff233Sopenharmony_ci        return SOFTBUS_IPC_ERR;
334060ff233Sopenharmony_ci    }
335060ff233Sopenharmony_ci    return ret;
336060ff233Sopenharmony_ci}
337060ff233Sopenharmony_ci
338060ff233Sopenharmony_ciint32_t ServerIpcCloseChannel(const char *sessionName, int32_t channelId, int32_t channelType)
339060ff233Sopenharmony_ci{
340060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "enter.");
341060ff233Sopenharmony_ci    uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
342060ff233Sopenharmony_ci    IpcIo request = {0};
343060ff233Sopenharmony_ci    IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
344060ff233Sopenharmony_ci    WriteInt32(&request, channelId);
345060ff233Sopenharmony_ci    WriteInt32(&request, channelType);
346060ff233Sopenharmony_ci    if (channelType == CHANNEL_TYPE_UNDEFINED) {
347060ff233Sopenharmony_ci        WriteString(&request, sessionName);
348060ff233Sopenharmony_ci    }
349060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_NO_INIT;
350060ff233Sopenharmony_ci    /* sync */
351060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
352060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
353060ff233Sopenharmony_ci        return ret;
354060ff233Sopenharmony_ci    }
355060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_CLOSE_CHANNEL, &request, &ret, ProxyCallback);
356060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
357060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", ret);
358060ff233Sopenharmony_ci        return ans;
359060ff233Sopenharmony_ci    }
360060ff233Sopenharmony_ci    return ret;
361060ff233Sopenharmony_ci}
362060ff233Sopenharmony_ci
363060ff233Sopenharmony_ciint32_t ServerIpcCloseChannelWithStatistics(int32_t channelId, int32_t channelType, uint64_t laneId,
364060ff233Sopenharmony_ci    const void *dataInfo, uint32_t len)
365060ff233Sopenharmony_ci{
366060ff233Sopenharmony_ci    (void)channelId;
367060ff233Sopenharmony_ci    (void)channelType;
368060ff233Sopenharmony_ci    (void)laneId;
369060ff233Sopenharmony_ci    (void)dataInfo;
370060ff233Sopenharmony_ci    (void)len;
371060ff233Sopenharmony_ci    return SOFTBUS_NOT_IMPLEMENT;
372060ff233Sopenharmony_ci}
373060ff233Sopenharmony_ci
374060ff233Sopenharmony_ciint32_t ServerIpcSendMessage(int32_t channelId, int32_t channelType, const void *data, uint32_t len, int32_t msgType)
375060ff233Sopenharmony_ci{
376060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "enter.");
377060ff233Sopenharmony_ci    uint32_t ipcDataLen = len + MAX_SOFT_BUS_IPC_LEN;
378060ff233Sopenharmony_ci    uint8_t *ipcData = (uint8_t *)SoftBusCalloc(ipcDataLen);
379060ff233Sopenharmony_ci    if (ipcData == NULL) {
380060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "malloc failed!");
381060ff233Sopenharmony_ci        return SOFTBUS_MALLOC_ERR;
382060ff233Sopenharmony_ci    }
383060ff233Sopenharmony_ci
384060ff233Sopenharmony_ci    IpcIo request = {0};
385060ff233Sopenharmony_ci    IpcIoInit(&request, ipcData, ipcDataLen, 0);
386060ff233Sopenharmony_ci    WriteInt32(&request, channelId);
387060ff233Sopenharmony_ci    WriteInt32(&request, channelType);
388060ff233Sopenharmony_ci    WriteInt32(&request, msgType);
389060ff233Sopenharmony_ci    WriteUint32(&request, len);
390060ff233Sopenharmony_ci    WriteBuffer(&request, data, len);
391060ff233Sopenharmony_ci
392060ff233Sopenharmony_ci    int32_t ret = SOFTBUS_NO_INIT;
393060ff233Sopenharmony_ci    /* sync */
394060ff233Sopenharmony_ci    if (g_serverProxy == NULL) {
395060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "server proxy not init");
396060ff233Sopenharmony_ci        SoftBusFree(ipcData);
397060ff233Sopenharmony_ci        return ret;
398060ff233Sopenharmony_ci    }
399060ff233Sopenharmony_ci    int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_SESSION_SENDMSG, &request, &ret, ProxyCallback);
400060ff233Sopenharmony_ci    SoftBusFree(ipcData);
401060ff233Sopenharmony_ci    if (ans != EC_SUCCESS) {
402060ff233Sopenharmony_ci        TRANS_LOGE(TRANS_SDK, "callback ret=%{public}d", ret);
403060ff233Sopenharmony_ci        return SOFTBUS_TRANS_PROXY_INVOKE_FAILED;
404060ff233Sopenharmony_ci    }
405060ff233Sopenharmony_ci    TRANS_LOGD(TRANS_SDK, "ok");
406060ff233Sopenharmony_ci    return ret;
407060ff233Sopenharmony_ci}
408060ff233Sopenharmony_ci
409060ff233Sopenharmony_ciint32_t ServerIpcQosReport(int32_t channelId, int32_t chanType, int32_t appType, int32_t quality)
410060ff233Sopenharmony_ci{
411060ff233Sopenharmony_ci    (void)channelId;
412060ff233Sopenharmony_ci    (void)chanType;
413060ff233Sopenharmony_ci    (void)appType;
414060ff233Sopenharmony_ci    (void)quality;
415060ff233Sopenharmony_ci    return SOFTBUS_NOT_IMPLEMENT;
416060ff233Sopenharmony_ci}
417060ff233Sopenharmony_ci
418060ff233Sopenharmony_ciint32_t ServerIpcGrantPermission(int uid, int pid, const char *sessionName)
419060ff233Sopenharmony_ci{
420060ff233Sopenharmony_ci    (void)uid;
421060ff233Sopenharmony_ci    (void)pid;
422060ff233Sopenharmony_ci    (void)sessionName;
423060ff233Sopenharmony_ci    return SOFTBUS_NOT_IMPLEMENT;
424060ff233Sopenharmony_ci}
425060ff233Sopenharmony_ci
426060ff233Sopenharmony_ciint32_t ServerIpcRemovePermission(const char *sessionName)
427060ff233Sopenharmony_ci{
428060ff233Sopenharmony_ci    (void)sessionName;
429060ff233Sopenharmony_ci    return SOFTBUS_NOT_IMPLEMENT;
430060ff233Sopenharmony_ci}
431060ff233Sopenharmony_ci
432060ff233Sopenharmony_ciint32_t ServerIpcStreamStats(int32_t channelId, int32_t channelType, const StreamSendStats *data)
433060ff233Sopenharmony_ci{
434060ff233Sopenharmony_ci    (void)channelId;
435060ff233Sopenharmony_ci    (void)channelType;
436060ff233Sopenharmony_ci    (void)data;
437060ff233Sopenharmony_ci    return SOFTBUS_NOT_IMPLEMENT;
438060ff233Sopenharmony_ci}
439060ff233Sopenharmony_ci
440060ff233Sopenharmony_ciint32_t ServerIpcRippleStats(int32_t channelId, int32_t channelType, const TrafficStats *data)
441060ff233Sopenharmony_ci{
442060ff233Sopenharmony_ci    (void)channelId;
443060ff233Sopenharmony_ci    (void)channelType;
444060ff233Sopenharmony_ci    (void)data;
445060ff233Sopenharmony_ci    return SOFTBUS_NOT_IMPLEMENT;
446060ff233Sopenharmony_ci}
447060ff233Sopenharmony_ci
448060ff233Sopenharmony_ciint32_t ServerIpcEvaluateQos(const char *peerNetworkId, TransDataType dataType, const QosTV *qos, uint32_t qosCount)
449060ff233Sopenharmony_ci{
450060ff233Sopenharmony_ci    (void)peerNetworkId;
451060ff233Sopenharmony_ci    (void)dataType;
452060ff233Sopenharmony_ci    (void)qos;
453060ff233Sopenharmony_ci    (void)qosCount;
454060ff233Sopenharmony_ci    return SOFTBUS_NOT_IMPLEMENT;
455060ff233Sopenharmony_ci}