• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "bus_center_server_proxy.h"
17 
18 #include "securec.h"
19 
20 #include "iproxy_client.h"
21 #include "samgr_lite.h"
22 #include "serializer.h"
23 #include "softbus_adapter_file.h"
24 #include "softbus_adapter_mem.h"
25 #include "softbus_adapter_timer.h"
26 #include "softbus_def.h"
27 #include "softbus_errcode.h"
28 #include "softbus_ipc_def.h"
29 #include "softbus_log.h"
30 
31 #define WAIT_SERVER_READY_INTERVAL_COUNT 50
32 
33 typedef enum {
34     GET_ALL_ONLINE_NODE_INFO = 0,
35     GET_LOCAL_DEVICE_INFO,
36     GET_NODE_KEY_INFO,
37     ACTIVE_META_NODE,
38     DEACTIVE_META_NODE,
39     GET_ALL_META_NODE,
40     SHIFT_LNN_GEAR,
41     START_REFRESH_LNN,
42     START_PUBLISH_LNN,
43 } FunID;
44 
45 typedef struct {
46     FunID id;
47     int32_t arg1;
48     int32_t retCode;
49     void* data;
50     int32_t dataLen;
51 } Reply;
52 
53 static IClientProxy *g_serverProxy = NULL;
54 
ClientBusCenterResultCb(Reply * info,int ret,IpcIo * reply)55 static int32_t ClientBusCenterResultCb(Reply* info, int ret, IpcIo *reply)
56 {
57     if (ret != SOFTBUS_OK) {
58         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ClientBusCenterResultCb failed. ret: %d", ret);
59         return SOFTBUS_ERR;
60     }
61     uint32_t infoSize;
62     switch (info->id) {
63         case GET_ALL_ONLINE_NODE_INFO:
64             ReadInt32(reply, &(info->arg1));
65             if (info->arg1 > 0) {
66                 ReadUint32(reply, &infoSize);
67                 info->data = (void *)ReadBuffer(reply, infoSize);
68             }
69             break;
70         case GET_LOCAL_DEVICE_INFO:
71         case GET_NODE_KEY_INFO:
72             ReadInt32(reply, &infoSize);
73             info->dataLen = infoSize;
74             info->data = (void *)ReadBuffer(reply, infoSize);
75             break;
76         case ACTIVE_META_NODE:
77             ReadInt32(reply, &(info->retCode));
78             if (info->retCode == SOFTBUS_OK) {
79                 info->data = (void *)ReadString(reply, &infoSize);
80                 if (infoSize != (NETWORK_ID_BUF_LEN - 1)) {
81                     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid meta node id length: %d", infoSize);
82                     return SOFTBUS_ERR;
83                 }
84             }
85             break;
86         case DEACTIVE_META_NODE:
87             ReadInt32(reply, &(info->retCode));
88             break;
89         case GET_ALL_META_NODE:
90             ReadInt32(reply, &(info->retCode));
91             if (info->retCode == SOFTBUS_OK) {
92                 ReadInt32(reply, &(info->arg1));
93                 if (info->arg1 > 0) {
94                     ReadUint32(reply, &infoSize);
95                     info->data = (void *)ReadBuffer(reply, infoSize);
96                 }
97             }
98             break;
99         case SHIFT_LNN_GEAR:
100             ReadInt32(reply, &(info->retCode));
101             break;
102         case START_REFRESH_LNN:
103             ReadInt32(reply, &(info->retCode));
104             break;
105         case START_PUBLISH_LNN:
106             ReadInt32(reply, &(info->retCode));
107             break;
108         default:
109             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "unknown funid");
110             return SOFTBUS_ERR;
111     }
112     return SOFTBUS_OK;
113 }
114 
BusCenterServerProxyInit(void)115 int32_t BusCenterServerProxyInit(void)
116 {
117     if (g_serverProxy != NULL) {
118         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "server proxy has initialized.");
119         return SOFTBUS_OK;
120     }
121 
122     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "bus center start get server proxy");
123     int32_t proxyInitCount = 0;
124     while (g_serverProxy == NULL) {
125         proxyInitCount++;
126         if (proxyInitCount == WAIT_SERVER_READY_INTERVAL_COUNT) {
127             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "bus center get server proxy error");
128             return SOFTBUS_ERR;
129         }
130 
131         IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SOFTBUS_SERVICE);
132         if (iUnknown == NULL) {
133             SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
134             continue;
135         }
136 
137         int32_t ret = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&g_serverProxy);
138         if (ret != EC_SUCCESS || g_serverProxy == NULL) {
139             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "QueryInterface failed [%d]", ret);
140             SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
141             continue;
142         }
143     }
144     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "bus center get server proxy ok");
145     return SOFTBUS_OK;
146 }
147 
BusCenterServerProxyDeInit(void)148 void BusCenterServerProxyDeInit(void)
149 {
150     g_serverProxy = NULL;
151 }
152 
ServerIpcGetAllOnlineNodeInfo(const char * pkgName,void ** info,uint32_t infoTypeLen,int32_t * infoNum)153 int ServerIpcGetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int32_t *infoNum)
154 {
155     if (info == NULL || infoNum == NULL) {
156         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
157         return SOFTBUS_INVALID_PARAM;
158     }
159     if (g_serverProxy == NULL) {
160         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllOnlineNodeInfo g_serverProxy is NULL!\n");
161         return SOFTBUS_ERR;
162     }
163     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
164     IpcIo request = {0};
165     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
166     WriteString(&request, pkgName);
167     WriteUint32(&request, infoTypeLen);
168     Reply reply = {0};
169     reply.id = GET_ALL_ONLINE_NODE_INFO;
170     /* asynchronous invocation */
171     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_ALL_ONLINE_NODE_INFO, &request, &reply,
172         ClientBusCenterResultCb);
173     if (ans != SOFTBUS_OK) {
174         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo invoke failed[%d].", ans);
175         return SOFTBUS_ERR;
176     }
177     *infoNum = reply.arg1;
178     if (*infoNum < 0) {
179         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo invoke failed[%d].", *infoNum);
180         return SOFTBUS_ERR;
181     }
182     int32_t infoSize = (*infoNum) * (int32_t)infoTypeLen;
183     *info = NULL;
184     if (infoSize > 0) {
185         if (reply.data == NULL) {
186             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo read node info failed!");
187             return SOFTBUS_ERR;
188         }
189         *info = SoftBusMalloc(infoSize);
190         if (*info == NULL) {
191             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo malloc failed!");
192             return SOFTBUS_ERR;
193         }
194         if (memcpy_s(*info, infoSize, reply.data, infoSize) != EOK) {
195             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo copy node info failed!");
196             SoftBusFree(*info);
197             *info = NULL;
198             return SOFTBUS_ERR;
199         }
200     }
201     return SOFTBUS_OK;
202 }
203 
ServerIpcGetLocalDeviceInfo(const char * pkgName,void * info,uint32_t infoTypeLen)204 int32_t ServerIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
205 {
206     if (info == NULL) {
207         return SOFTBUS_ERR;
208     }
209     if (g_serverProxy == NULL) {
210         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetLocalDeviceInfo g_serverProxy is nullptr!\n");
211         return SOFTBUS_ERR;
212     }
213 
214     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
215     IpcIo request = {0};
216     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
217     WriteString(&request, pkgName);
218     WriteUint32(&request, infoTypeLen);
219     Reply reply = {0};
220     reply.id = GET_LOCAL_DEVICE_INFO;
221     /* asynchronous invocation */
222     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_LOCAL_DEVICE_INFO, &request, &reply,
223         ClientBusCenterResultCb);
224     if (ans != SOFTBUS_OK) {
225         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetLocalDeviceInfo invoke failed[%d].", ans);
226         return SOFTBUS_ERR;
227     }
228     if (reply.data == NULL) {
229         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetLocalDeviceInfo read node info failed!");
230         return SOFTBUS_ERR;
231     }
232     if (memcpy_s(info, infoTypeLen, reply.data, infoTypeLen) != EOK) {
233         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetLocalDeviceInfo copy node info failed!");
234         return SOFTBUS_ERR;
235     }
236     return SOFTBUS_OK;
237 }
238 
ServerIpcGetNodeKeyInfo(const char * pkgName,const char * networkId,int key,unsigned char * buf,uint32_t len)239 int32_t ServerIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf, uint32_t len)
240 {
241     if (networkId == NULL || buf == NULL) {
242         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "params are nullptr!");
243         return SOFTBUS_ERR;
244     }
245     if (g_serverProxy == NULL) {
246         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetNodeKeyInfo g_serverProxy is nullptr!\n");
247         return SOFTBUS_ERR;
248     }
249 
250     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
251     IpcIo request = {0};
252     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
253     WriteString(&request, pkgName);
254     WriteString(&request, networkId);
255     WriteInt32(&request, key);
256     WriteInt32(&request, len);
257     Reply reply = {0};
258     reply.id = GET_NODE_KEY_INFO;
259     /* asynchronous invocation */
260     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_NODE_KEY_INFO, &request, &reply,
261         ClientBusCenterResultCb);
262     if (ans != SOFTBUS_OK) {
263         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetNodeKeyInfo invoke failed[%d].", ans);
264         return SOFTBUS_ERR;
265     }
266     if (reply.data == NULL) {
267         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetNodeKeyInfo read retBuf failed!");
268         return SOFTBUS_ERR;
269     }
270     if (memcpy_s(buf, len, reply.data, reply.dataLen) != EOK) {
271         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetNodeKeyInfo copy node key info failed");
272         return SOFTBUS_ERR;
273     }
274     return SOFTBUS_OK;
275 }
276 
ServerIpcSetNodeDataChangeFlag(const char * pkgName,const char * networkId,uint16_t dataChangeFlag)277 int32_t ServerIpcSetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag)
278 {
279     if (networkId == NULL) {
280         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "params are nullptr!");
281         return SOFTBUS_ERR;
282     }
283     if (g_serverProxy == NULL) {
284         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcSetNodeDataChangeFlag g_serverProxy is nullptr!\n");
285         return SOFTBUS_ERR;
286     }
287 
288     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
289     IpcIo request = {0};
290     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
291     WriteString(&request, pkgName);
292     WriteString(&request, networkId);
293     WriteInt16(&request, dataChangeFlag);
294     Reply reply = {0};
295     reply.id = GET_NODE_KEY_INFO;
296     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_SET_NODE_DATA_CHANGE_FLAG, &request, &reply,
297         ClientBusCenterResultCb);
298     if (ans != SOFTBUS_OK) {
299         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "SetNodeDataChangeFlag invoke failed[%d].", ans);
300         return SOFTBUS_ERR;
301     }
302     return SOFTBUS_OK;
303 }
304 
ServerIpcJoinLNN(const char * pkgName,void * addr,unsigned int addrTypeLen)305 int ServerIpcJoinLNN(const char *pkgName, void *addr, unsigned int addrTypeLen)
306 {
307     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "join Lnn ipc client push.");
308     if (addr == NULL || pkgName == NULL) {
309         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
310         return SOFTBUS_INVALID_PARAM;
311     }
312     if (g_serverProxy == NULL) {
313         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinLNN g_serverProxy is nullptr!\n");
314         return SOFTBUS_ERR;
315     }
316     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
317     IpcIo request = {0};
318     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
319     WriteString(&request, pkgName);
320     WriteUint32(&request, addrTypeLen);
321     WriteBuffer(&request, addr, addrTypeLen);
322     /* asynchronous invocation */
323     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_JOIN_LNN, &request, NULL, NULL);
324     if (ans != SOFTBUS_OK) {
325         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "join Lnn invoke failed[%d].", ans);
326         return SOFTBUS_ERR;
327     }
328     return SOFTBUS_OK;
329 }
330 
ServerIpcJoinMetaNode(const char * pkgName,void * addr,CustomData * customData,unsigned int addrTypeLen)331 int32_t ServerIpcJoinMetaNode(const char *pkgName, void *addr, CustomData *customData, unsigned int addrTypeLen)
332 {
333     (void)pkgName;
334     (void)addr;
335     (void)customData;
336     (void)addrTypeLen;
337     return SOFTBUS_OK;
338 }
339 
ServerIpcLeaveLNN(const char * pkgName,const char * networkId)340 int ServerIpcLeaveLNN(const char *pkgName, const char *networkId)
341 {
342     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "leave Lnn ipc client push.");
343     if (pkgName == NULL || networkId == NULL) {
344         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
345         return SOFTBUS_INVALID_PARAM;
346     }
347     if (g_serverProxy == NULL) {
348         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveLNN g_serverProxy is nullptr!\n");
349         return SOFTBUS_ERR;
350     }
351     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
352     IpcIo request = {0};
353     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
354     WriteString(&request, pkgName);
355     WriteString(&request, networkId);
356     /* asynchronous invocation */
357     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_LEAVE_LNN, &request, NULL, NULL);
358     if (ans != SOFTBUS_OK) {
359         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "leave Lnn invoke failed[%d].", ans);
360         return SOFTBUS_ERR;
361     }
362     return SOFTBUS_OK;
363 }
364 
ServerIpcLeaveMetaNode(const char * pkgName,const char * networkId)365 int32_t ServerIpcLeaveMetaNode(const char *pkgName, const char *networkId)
366 {
367     (void)pkgName;
368     (void)networkId;
369     return SOFTBUS_OK;
370 }
371 
ServerIpcStartTimeSync(const char * pkgName,const char * targetNetworkId,int32_t accuracy,int32_t period)372 int32_t ServerIpcStartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy, int32_t period)
373 {
374     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "start time sync ipc client push.");
375     if (targetNetworkId == NULL || pkgName == NULL) {
376         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
377         return SOFTBUS_ERR;
378     }
379     if (g_serverProxy == NULL) {
380         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStartTimeSync g_serverProxy is nullptr!");
381         return SOFTBUS_ERR;
382     }
383 
384     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
385     IpcIo request = {0};
386     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
387     WriteString(&request, pkgName);
388     WriteString(&request, targetNetworkId);
389     WriteInt32(&request, accuracy);
390     WriteInt32(&request, period);
391     /* asynchronous invocation */
392     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_START_TIME_SYNC, &request, NULL, NULL);
393     if (ans != SOFTBUS_OK) {
394         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "StartTimeSync invoke failed[%d].", ans);
395         return SOFTBUS_ERR;
396     }
397     return SOFTBUS_OK;
398 }
399 
ServerIpcStopTimeSync(const char * pkgName,const char * targetNetworkId)400 int32_t ServerIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
401 {
402     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop time sync ipc client push.");
403     if (targetNetworkId == NULL || pkgName == NULL) {
404         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
405         return SOFTBUS_ERR;
406     }
407     if (g_serverProxy == NULL) {
408         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopTimeSync g_serverProxy is nullptr!");
409         return SOFTBUS_ERR;
410     }
411 
412     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
413     IpcIo request = {0};
414     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
415     WriteString(&request, pkgName);
416     WriteString(&request, targetNetworkId);
417     /* asynchronous invocation */
418     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_TIME_SYNC, &request, NULL, NULL);
419     if (ans != SOFTBUS_OK) {
420         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "StopTimeSync invoke failed[%d].", ans);
421         return SOFTBUS_ERR;
422     }
423     return SOFTBUS_OK;
424 }
425 
ServerIpcPublishLNN(const char * pkgName,const void * info,uint32_t infoLen)426 int32_t ServerIpcPublishLNN(const char *pkgName, const void *info, uint32_t infoLen)
427 {
428     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "publish Lnn ipc client push.");
429     if (info == NULL || pkgName == NULL) {
430         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
431         return SOFTBUS_INVALID_PARAM;
432     }
433     if (g_serverProxy == NULL) {
434         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcPublishLNN g_serverProxy is nullptr!\n");
435         return SOFTBUS_ERR;
436     }
437     uint8_t data[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
438     IpcIo request = {0};
439     Reply reply = {0};
440     reply.id = START_PUBLISH_LNN;
441     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN_EX, 0);
442     WriteString(&request, pkgName);
443     WriteUint32(&request, infoLen);
444     WriteBuffer(&request, info, infoLen);
445     /* asynchronous invocation */
446     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_PUBLISH_LNN, &request, &reply, NULL);
447     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
448         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "publish Lnn invoke failed[%d, %d].", ans, reply.retCode);
449         return SOFTBUS_ERR;
450     }
451     return SOFTBUS_OK;
452 }
453 
ServerIpcStopPublishLNN(const char * pkgName,int32_t publishId)454 int32_t ServerIpcStopPublishLNN(const char *pkgName, int32_t publishId)
455 {
456     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop publish lnn ipc client push.");
457     if (pkgName == NULL) {
458         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
459         return SOFTBUS_ERR;
460     }
461     if (g_serverProxy == NULL) {
462         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN g_serverProxy is nullptr!");
463         return SOFTBUS_ERR;
464     }
465 
466     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
467     IpcIo request = {0};
468     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
469     WriteString(&request, pkgName);
470     WriteInt32(&request, publishId);
471     /* asynchronous invocation */
472     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_PUBLISH_LNN, &request, NULL, NULL);
473     if (ans != SOFTBUS_OK) {
474         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN invoke failed[%d].", ans);
475         return SOFTBUS_ERR;
476     }
477     return SOFTBUS_OK;
478 }
479 
ServerIpcRefreshLNN(const char * pkgName,const void * info,uint32_t infoTypeLen)480 int32_t ServerIpcRefreshLNN(const char *pkgName, const void *info, uint32_t infoTypeLen)
481 {
482     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "refresh Lnn ipc client push.");
483     if (info == NULL || pkgName == NULL) {
484         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
485         return SOFTBUS_INVALID_PARAM;
486     }
487     if (g_serverProxy == NULL) {
488         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcRefreshLNN g_serverProxy is nullptr!\n");
489         return SOFTBUS_ERR;
490     }
491     uint8_t data[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
492     IpcIo request = {0};
493     Reply reply = {0};
494     reply.id = START_REFRESH_LNN;
495     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN_EX, 0);
496     WriteString(&request, pkgName);
497     WriteUint32(&request, infoTypeLen);
498     WriteBuffer(&request, info, infoTypeLen);
499     /* asynchronous invocation */
500     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_REFRESH_LNN, &request, &reply, ClientBusCenterResultCb);
501     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
502         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "refresh Lnn invoke failed[%d, %d].", ans, reply.retCode);
503         return SOFTBUS_ERR;
504     }
505     return SOFTBUS_OK;
506 }
507 
ServerIpcStopRefreshLNN(const char * pkgName,int32_t refreshId)508 int32_t ServerIpcStopRefreshLNN(const char *pkgName, int32_t refreshId)
509 {
510     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop refresh lnn ipc client push.");
511     if (pkgName == NULL) {
512         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
513         return SOFTBUS_ERR;
514     }
515     if (g_serverProxy == NULL) {
516         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN g_serverProxy is nullptr!");
517         return SOFTBUS_ERR;
518     }
519 
520     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
521     IpcIo request = {0};
522     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
523     WriteString(&request, pkgName);
524     WriteInt32(&request, refreshId);
525     /* asynchronous invocation */
526     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_REFRESH_LNN, &request, NULL, NULL);
527     if (ans != SOFTBUS_OK) {
528         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN invoke failed[%d].", ans);
529         return SOFTBUS_ERR;
530     }
531 
532     return SOFTBUS_OK;
533 }
534 
ServerIpcActiveMetaNode(const char * pkgName,const MetaNodeConfigInfo * info,char * metaNodeId)535 int32_t ServerIpcActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId)
536 {
537     if (g_serverProxy == NULL) {
538         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode g_serverProxy is nullptr!");
539         return SOFTBUS_ERR;
540     }
541 
542     uint8_t data[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
543     IpcIo request = {0};
544     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN_EX, 0);
545     WriteString(&request, pkgName);
546     bool ret = WriteRawData(&request, info, sizeof(MetaNodeConfigInfo));
547     if (!ret) {
548         return SOFTBUS_ERR;
549     }
550     Reply reply = {0};
551     reply.id = ACTIVE_META_NODE;
552     /* asynchronous invocation */
553     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_ACTIVE_META_NODE, &request, &reply,
554         ClientBusCenterResultCb);
555     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
556         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode invoke failed[%d, %d].",
557             ans, reply.retCode);
558         return SOFTBUS_ERR;
559     }
560     if (reply.data == NULL) {
561         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode read data failed!");
562         return SOFTBUS_ERR;
563     }
564     if (strncpy_s(metaNodeId, NETWORK_ID_BUF_LEN, (char *)reply.data, strlen((char *)reply.data)) != EOK) {
565         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode copy meta node id failed");
566         return SOFTBUS_ERR;
567     }
568     return SOFTBUS_OK;
569 }
570 
ServerIpcDeactiveMetaNode(const char * pkgName,const char * metaNodeId)571 int32_t ServerIpcDeactiveMetaNode(const char *pkgName, const char *metaNodeId)
572 {
573     if (g_serverProxy == NULL) {
574         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode g_serverProxy is nullptr!");
575         return SOFTBUS_ERR;
576     }
577 
578     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
579     IpcIo request = {0};
580     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
581     WriteString(&request, pkgName);
582     WriteString(&request, metaNodeId);
583     Reply reply = {0};
584     reply.id = DEACTIVE_META_NODE;
585     /* asynchronous invocation */
586     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_DEACTIVE_META_NODE, &request,
587         &reply, ClientBusCenterResultCb);
588     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
589         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode invoke failed[%d, %d]",
590             ans, reply.retCode);
591         return SOFTBUS_ERR;
592     }
593     return SOFTBUS_OK;
594 }
595 
ServerIpcGetAllMetaNodeInfo(const char * pkgName,MetaNodeInfo * infos,int32_t * infoNum)596 int32_t ServerIpcGetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum)
597 {
598     if (g_serverProxy == NULL) {
599         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo g_serverProxy is nullptr!");
600         return SOFTBUS_ERR;
601     }
602 
603     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
604     IpcIo request = {0};
605     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
606     WriteString(&request, pkgName);
607     WriteInt32(&request, *infoNum);
608     Reply reply = {0};
609     reply.id = GET_ALL_META_NODE;
610     /* asynchronous invocation */
611     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_ALL_META_NODE_INFO, &request, &reply,
612         ClientBusCenterResultCb);
613     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
614         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo invoke failed[%d, %d]",
615             ans, reply.retCode);
616         return SOFTBUS_ERR;
617     }
618     if (reply.arg1 > 0) {
619         if (reply.data == NULL) {
620             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo read meta node info failed!");
621             return SOFTBUS_ERR;
622         }
623         if (memcpy_s(infos, *infoNum * sizeof(MetaNodeInfo), reply.data, reply.arg1 * sizeof(MetaNodeInfo)) != EOK) {
624             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo copy meta node info failed");
625             return SOFTBUS_ERR;
626         }
627     }
628     *infoNum = reply.arg1;
629     return SOFTBUS_OK;
630 }
631 
ServerIpcShiftLNNGear(const char * pkgName,const char * callerId,const char * targetNetworkId,const GearMode * mode)632 int32_t ServerIpcShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId,
633     const GearMode *mode)
634 {
635     if (pkgName == NULL || callerId == NULL || mode == NULL) {
636         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
637         return SOFTBUS_ERR;
638     }
639     if (g_serverProxy == NULL) {
640         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcShiftLNNGear g_serverProxy is nullptr!");
641         return SOFTBUS_ERR;
642     }
643 
644     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
645     bool targetNetworkIdIsNull = targetNetworkId == NULL ? true : false;
646     IpcIo request = {0};
647     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
648     WriteString(&request, pkgName);
649     WriteString(&request, callerId);
650     WriteBool(&request, targetNetworkIdIsNull);
651     if (!targetNetworkIdIsNull) {
652         WriteString(&request, targetNetworkId);
653     }
654     WriteRawData(&request, mode, sizeof(GearMode));
655     Reply reply = {0};
656     reply.id = SHIFT_LNN_GEAR;
657     /* asynchronous invocation */
658     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_SHIFT_LNN_GEAR, &request, &reply,
659         ClientBusCenterResultCb);
660     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
661         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcShiftLNNGear invoke failed[%d, %d]",
662             ans, reply.retCode);
663         return ans != SOFTBUS_OK ? SOFTBUS_ERR : reply.retCode;
664     }
665     return SOFTBUS_OK;
666 }
667