• 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_feature_config.h"
29 #include "softbus_ipc_def.h"
30 #include "softbus_log.h"
31 
32 #define WAIT_SERVER_READY_INTERVAL_COUNT 50
33 
34 typedef enum {
35     GET_ALL_ONLINE_NODE_INFO = 0,
36     GET_LOCAL_DEVICE_INFO,
37     GET_NODE_KEY_INFO,
38     ACTIVE_META_NODE,
39     DEACTIVE_META_NODE,
40     GET_ALL_META_NODE,
41 } FunID;
42 
43 typedef struct {
44     FunID id;
45     int32_t arg1;
46     int32_t retCode;
47     void* data;
48     int32_t dataLen;
49 } Reply;
50 
51 static IClientProxy *g_serverProxy = NULL;
52 
ClientBusCenterResultCb(IOwner owner,int code,IpcIo * reply)53 static int32_t ClientBusCenterResultCb(IOwner owner, int code, IpcIo *reply)
54 {
55     Reply *info = (Reply *)owner;
56     uint32_t infoSize;
57     switch (info->id) {
58         case GET_ALL_ONLINE_NODE_INFO:
59             info->arg1 = IpcIoPopInt32(reply);
60             if (info->arg1 > 0) {
61                 info->data = (void *)IpcIoPopFlatObj(reply, &infoSize);
62             }
63             break;
64         case GET_LOCAL_DEVICE_INFO:
65         case GET_NODE_KEY_INFO:
66             info->data = (void *)IpcIoPopFlatObj(reply, &infoSize);
67             info->dataLen = infoSize;
68             break;
69         case ACTIVE_META_NODE:
70             info->retCode = IpcIoPopInt32(reply);
71             if (info->retCode == SOFTBUS_OK) {
72                 info->data = (void *)IpcIoPopString(reply, &infoSize);
73                 if (infoSize != (NETWORK_ID_BUF_LEN - 1)) {
74                     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "invalid meta node id length: %d", infoSize);
75                     return SOFTBUS_ERR;
76                 }
77             }
78             break;
79         case DEACTIVE_META_NODE:
80             info->retCode = IpcIoPopInt32(reply);
81             break;
82         case GET_ALL_META_NODE:
83             info->retCode = IpcIoPopInt32(reply);
84             if (info->retCode == SOFTBUS_OK) {
85                 info->arg1 = IpcIoPopInt32(reply);
86                 if (info->arg1 > 0) {
87                     info->data = (void *)IpcIoPopFlatObj(reply, &infoSize);
88                 }
89             }
90             break;
91         default:
92             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "unknown funid");
93             return SOFTBUS_ERR;
94     }
95     return SOFTBUS_OK;
96 }
97 
BusCenterServerProxyInit(void)98 int32_t BusCenterServerProxyInit(void)
99 {
100     if (g_serverProxy != NULL) {
101         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "server proxy has initialized.");
102         return SOFTBUS_OK;
103     }
104 
105     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "bus center start get server proxy");
106     int32_t proxyInitCount = 0;
107     while (g_serverProxy == NULL) {
108         proxyInitCount++;
109         if (proxyInitCount == WAIT_SERVER_READY_INTERVAL_COUNT) {
110             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "bus center get server proxy error");
111             return SOFTBUS_ERR;
112         }
113 
114         IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SOFTBUS_SERVICE);
115         if (iUnknown == NULL) {
116             SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
117             continue;
118         }
119 
120         int32_t ret = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&g_serverProxy);
121         if (ret != EC_SUCCESS || g_serverProxy == NULL) {
122             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "QueryInterface failed [%d]", ret);
123             SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
124             continue;
125         }
126     }
127     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "bus center get server proxy ok");
128     return SOFTBUS_OK;
129 }
130 
BusCenterServerProxyDeInit(void)131 void BusCenterServerProxyDeInit(void)
132 {
133     g_serverProxy = NULL;
134 }
135 
ServerIpcGetAllOnlineNodeInfo(const char * pkgName,void ** info,uint32_t infoTypeLen,int32_t * infoNum)136 int32_t ServerIpcGetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int32_t *infoNum)
137 {
138     if (info == NULL || infoNum == NULL) {
139         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
140         return SOFTBUS_INVALID_PARAM;
141     }
142     if (g_serverProxy == NULL) {
143         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllOnlineNodeInfo g_serverProxy is NULL!\n");
144         return SOFTBUS_ERR;
145     }
146     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
147     IpcIo request = {0};
148     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
149     IpcIoPushString(&request, pkgName);
150     IpcIoPushUint32(&request, infoTypeLen);
151     Reply reply = {0};
152     reply.id = GET_ALL_ONLINE_NODE_INFO;
153     /* asynchronous invocation */
154     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_ALL_ONLINE_NODE_INFO, &request, &reply,
155         ClientBusCenterResultCb);
156     if (ans != SOFTBUS_OK) {
157         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo invoke failed[%d].", ans);
158         return SOFTBUS_ERR;
159     }
160     uint32_t maxConnCount = UINT32_MAX;
161     (void)SoftbusGetConfig(SOFTBUS_INT_MAX_LNN_CONNECTION_CNT, (unsigned char *)&maxConnCount, sizeof(maxConnCount));
162     *infoNum = reply.arg1;
163     if (*infoNum < 0 || (uint32_t)(*infoNum) > maxConnCount) {
164         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo invoke failed[%d].", *infoNum);
165         return SOFTBUS_ERR;
166     }
167     int32_t infoSize = (*infoNum) * (int32_t)infoTypeLen;
168     *info = NULL;
169     if (infoSize > 0) {
170         if (reply.data == NULL) {
171             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo read node info failed!");
172             return SOFTBUS_ERR;
173         }
174         *info = SoftBusMalloc(infoSize);
175         if (*info == NULL) {
176             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo malloc failed!");
177             return SOFTBUS_ERR;
178         }
179         if (memcpy_s(*info, infoSize, reply.data, infoSize) != EOK) {
180             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetAllOnlineNodeInfo copy node info failed!");
181             SoftBusFree(*info);
182             *info = NULL;
183             return SOFTBUS_ERR;
184         }
185     }
186     return SOFTBUS_OK;
187 }
188 
ServerIpcGetLocalDeviceInfo(const char * pkgName,void * info,uint32_t infoTypeLen)189 int32_t ServerIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
190 {
191     if (info == NULL) {
192         return SOFTBUS_ERR;
193     }
194     if (g_serverProxy == NULL) {
195         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetLocalDeviceInfo g_serverProxy is nullptr!\n");
196         return SOFTBUS_ERR;
197     }
198 
199     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
200     IpcIo request = {0};
201     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
202     IpcIoPushString(&request, pkgName);
203     IpcIoPushUint32(&request, infoTypeLen);
204     Reply reply = {0};
205     reply.id = GET_LOCAL_DEVICE_INFO;
206     /* asynchronous invocation */
207     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_LOCAL_DEVICE_INFO, &request, &reply,
208         ClientBusCenterResultCb);
209     if (ans != SOFTBUS_OK) {
210         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetLocalDeviceInfo invoke failed[%d].", ans);
211         return SOFTBUS_ERR;
212     }
213     if (reply.data == NULL) {
214         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetLocalDeviceInfo read node info failed!");
215         return SOFTBUS_ERR;
216     }
217     if (memcpy_s(info, infoTypeLen, reply.data, infoTypeLen) != EOK) {
218         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetLocalDeviceInfo copy node info failed!");
219         return SOFTBUS_ERR;
220     }
221     return SOFTBUS_OK;
222 }
223 
ServerIpcGetNodeKeyInfo(const char * pkgName,const char * networkId,int key,unsigned char * buf,uint32_t len)224 int32_t ServerIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf, uint32_t len)
225 {
226     if (networkId == NULL || buf == NULL) {
227         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "params are nullptr!");
228         return SOFTBUS_ERR;
229     }
230     if (g_serverProxy == NULL) {
231         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetNodeKeyInfo g_serverProxy is nullptr!\n");
232         return SOFTBUS_ERR;
233     }
234 
235     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
236     IpcIo request = {0};
237     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
238     IpcIoPushString(&request, pkgName);
239     IpcIoPushString(&request, networkId);
240     IpcIoPushInt32(&request, key);
241     IpcIoPushInt32(&request, len);
242     Reply reply = {0};
243     reply.id = GET_NODE_KEY_INFO;
244     /* asynchronous invocation */
245     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_NODE_KEY_INFO, &request, &reply,
246         ClientBusCenterResultCb);
247     if (ans != SOFTBUS_OK) {
248         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetNodeKeyInfo invoke failed[%d].", ans);
249         return SOFTBUS_ERR;
250     }
251     if (reply.data == NULL || reply.dataLen > len) {
252         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR,
253             "GetNodeKeyInfo read retBuf failed, len:%d, reply.dataLen:%d", len, reply.dataLen);
254         return SOFTBUS_ERR;
255     }
256     if (memcpy_s(buf, len, reply.data, reply.dataLen) != EOK) {
257         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "GetNodeKeyInfo copy node key info failed");
258         return SOFTBUS_ERR;
259     }
260     return SOFTBUS_OK;
261 }
262 
ServerIpcJoinLNN(const char * pkgName,void * addr,unsigned int addrTypeLen)263 int ServerIpcJoinLNN(const char *pkgName, void *addr, unsigned int addrTypeLen)
264 {
265     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "join Lnn ipc client push.");
266     if (addr == NULL || pkgName == NULL) {
267         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
268         return SOFTBUS_INVALID_PARAM;
269     }
270     if (g_serverProxy == NULL) {
271         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcJoinLNN g_serverProxy is nullptr!\n");
272         return SOFTBUS_ERR;
273     }
274     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
275     IpcIo request = {0};
276     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
277     IpcIoPushString(&request, pkgName);
278     IpcIoPushUint32(&request, addrTypeLen);
279     IpcIoPushFlatObj(&request, addr, addrTypeLen);
280     /* asynchronous invocation */
281     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_JOIN_LNN, &request, NULL, NULL);
282     if (ans != SOFTBUS_OK) {
283         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "join Lnn invoke failed[%d].", ans);
284         return SOFTBUS_ERR;
285     }
286     return SOFTBUS_OK;
287 }
288 
ServerIpcLeaveLNN(const char * pkgName,const char * networkId)289 int ServerIpcLeaveLNN(const char *pkgName, const char *networkId)
290 {
291     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "leave Lnn ipc client push.");
292     if (pkgName == NULL || networkId == NULL) {
293         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
294         return SOFTBUS_INVALID_PARAM;
295     }
296     if (g_serverProxy == NULL) {
297         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcLeaveLNN g_serverProxy is nullptr!\n");
298         return SOFTBUS_ERR;
299     }
300     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
301     IpcIo request = {0};
302     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
303     IpcIoPushString(&request, pkgName);
304     IpcIoPushString(&request, networkId);
305     /* asynchronous invocation */
306     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_LEAVE_LNN, &request, NULL, NULL);
307     if (ans != SOFTBUS_OK) {
308         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "leave Lnn invoke failed[%d].", ans);
309         return SOFTBUS_ERR;
310     }
311     return SOFTBUS_OK;
312 }
313 
ServerIpcStartTimeSync(const char * pkgName,const char * targetNetworkId,int32_t accuracy,int32_t period)314 int32_t ServerIpcStartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy, int32_t period)
315 {
316     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "start time sync ipc client push.");
317     if (targetNetworkId == NULL || pkgName == NULL) {
318         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
319         return SOFTBUS_ERR;
320     }
321     if (g_serverProxy == NULL) {
322         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStartTimeSync g_serverProxy is nullptr!");
323         return SOFTBUS_ERR;
324     }
325 
326     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
327     IpcIo request = {0};
328     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
329     IpcIoPushString(&request, pkgName);
330     IpcIoPushString(&request, targetNetworkId);
331     IpcIoPushInt32(&request, accuracy);
332     IpcIoPushInt32(&request, period);
333     /* asynchronous invocation */
334     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_START_TIME_SYNC, &request, NULL, NULL);
335     if (ans != SOFTBUS_OK) {
336         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "StartTimeSync invoke failed[%d].", ans);
337         return SOFTBUS_ERR;
338     }
339     return SOFTBUS_OK;
340 }
341 
ServerIpcStopTimeSync(const char * pkgName,const char * targetNetworkId)342 int32_t ServerIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
343 {
344     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop time sync ipc client push.");
345     if (targetNetworkId == NULL || pkgName == NULL) {
346         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
347         return SOFTBUS_ERR;
348     }
349     if (g_serverProxy == NULL) {
350         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopTimeSync g_serverProxy is nullptr!");
351         return SOFTBUS_ERR;
352     }
353 
354     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
355     IpcIo request = {0};
356     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
357     IpcIoPushString(&request, pkgName);
358     IpcIoPushString(&request, targetNetworkId);
359     /* asynchronous invocation */
360     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_TIME_SYNC, &request, NULL, NULL);
361     if (ans != SOFTBUS_OK) {
362         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "StopTimeSync invoke failed[%d].", ans);
363         return SOFTBUS_ERR;
364     }
365     return SOFTBUS_OK;
366 }
367 
ServerIpcPublishLNN(const char * pkgName,const PublishInfo * info)368 int32_t ServerIpcPublishLNN(const char *pkgName, const PublishInfo *info)
369 {
370     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "publish Lnn ipc client push.");
371     if (info == NULL || pkgName == NULL) {
372         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
373         return SOFTBUS_INVALID_PARAM;
374     }
375     if (g_serverProxy == NULL) {
376         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcPublishLNN g_serverProxy is nullptr!\n");
377         return SOFTBUS_ERR;
378     }
379     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
380     IpcIo request = {0};
381     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
382     IpcIoPushString(&request, pkgName);
383     IpcIoPushInt32(&request, info->publishId);
384     IpcIoPushInt32(&request, info->mode);
385     IpcIoPushInt32(&request, info->medium);
386     IpcIoPushInt32(&request, info->freq);
387     IpcIoPushString(&request, info->capability);
388     IpcIoPushUint32(&request, info->dataLen);
389     if (info->dataLen != 0) {
390         IpcIoPushFlatObj(&request, info->capabilityData, info->dataLen);
391     }
392     /* asynchronous invocation */
393     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_PUBLISH_LNN, &request, NULL, NULL);
394     if (ans != SOFTBUS_OK) {
395         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "publish Lnn invoke failed[%d].", ans);
396         return SOFTBUS_ERR;
397     }
398     return SOFTBUS_OK;
399 }
400 
ServerIpcStopPublishLNN(const char * pkgName,int32_t publishId)401 int32_t ServerIpcStopPublishLNN(const char *pkgName, int32_t publishId)
402 {
403     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop publish lnn ipc client push.");
404     if (pkgName == NULL) {
405         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
406         return SOFTBUS_ERR;
407     }
408     if (g_serverProxy == NULL) {
409         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN g_serverProxy is nullptr!");
410         return SOFTBUS_ERR;
411     }
412 
413     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
414     IpcIo request = {0};
415     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
416     IpcIoPushString(&request, pkgName);
417     IpcIoPushInt32(&request, publishId);
418     /* asynchronous invocation */
419     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_PUBLISH_LNN, &request, NULL, NULL);
420     if (ans != SOFTBUS_OK) {
421         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopPublishLNN invoke failed[%d].", ans);
422         return SOFTBUS_ERR;
423     }
424     return SOFTBUS_OK;
425 }
426 
ServerIpcRefreshLNN(const char * pkgName,const SubscribeInfo * info)427 int32_t ServerIpcRefreshLNN(const char *pkgName, const SubscribeInfo *info)
428 {
429     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "refresh Lnn ipc client push.");
430     if (info == NULL || pkgName == NULL) {
431         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
432         return SOFTBUS_INVALID_PARAM;
433     }
434     if (g_serverProxy == NULL) {
435         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcRefreshLNN g_serverProxy is nullptr!\n");
436         return SOFTBUS_ERR;
437     }
438     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
439     IpcIo request = {0};
440     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
441     IpcIoPushString(&request, pkgName);
442     IpcIoPushInt32(&request, info->subscribeId);
443     IpcIoPushInt32(&request, info->mode);
444     IpcIoPushInt32(&request, info->medium);
445     IpcIoPushInt32(&request, info->freq);
446     IpcIoPushBool(&request, info->isSameAccount);
447     IpcIoPushBool(&request, info->isWakeRemote);
448     IpcIoPushString(&request, info->capability);
449     IpcIoPushUint32(&request, info->dataLen);
450     if (info->dataLen != 0) {
451         IpcIoPushFlatObj(&request, info->capabilityData, info->dataLen);
452     }
453     /* asynchronous invocation */
454     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_REFRESH_LNN, &request, NULL, NULL);
455     if (ans != SOFTBUS_OK) {
456         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "refresh Lnn invoke failed[%d].", ans);
457         return SOFTBUS_ERR;
458     }
459     return SOFTBUS_OK;
460 }
461 
ServerIpcStopRefreshLNN(const char * pkgName,int32_t refreshId)462 int32_t ServerIpcStopRefreshLNN(const char *pkgName, int32_t refreshId)
463 {
464     SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_INFO, "stop refresh lnn ipc client push.");
465     if (pkgName == NULL) {
466         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "Invalid param");
467         return SOFTBUS_ERR;
468     }
469     if (g_serverProxy == NULL) {
470         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN g_serverProxy is nullptr!");
471         return SOFTBUS_ERR;
472     }
473 
474     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
475     IpcIo request = {0};
476     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
477     IpcIoPushString(&request, pkgName);
478     IpcIoPushInt32(&request, refreshId);
479     /* asynchronous invocation */
480     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_REFRESH_LNN, &request, NULL, NULL);
481     if (ans != SOFTBUS_OK) {
482         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcStopRefreshLNN invoke failed[%d].", ans);
483         return SOFTBUS_ERR;
484     }
485     return SOFTBUS_OK;
486 }
487 
ServerIpcActiveMetaNode(const char * pkgName,const MetaNodeConfigInfo * info,char * metaNodeId)488 int32_t ServerIpcActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId)
489 {
490     if (g_serverProxy == NULL) {
491         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode g_serverProxy is nullptr!");
492         return SOFTBUS_ERR;
493     }
494 
495     uint8_t data[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
496     IpcIo request = {0};
497     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN_EX, 0);
498     IpcIoPushString(&request, pkgName);
499     IpcIoPushFlatObj(&request, info, sizeof(MetaNodeConfigInfo));
500     Reply reply = {0};
501     reply.id = ACTIVE_META_NODE;
502     /* asynchronous invocation */
503     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_ACTIVE_META_NODE, &request, &reply,
504         ClientBusCenterResultCb);
505     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
506         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode invoke failed[%d, %d].",
507             ans, reply.retCode);
508         return SOFTBUS_ERR;
509     }
510     if (reply.data == NULL) {
511         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode read data failed!");
512         return SOFTBUS_ERR;
513     }
514     if (strncpy_s(metaNodeId, NETWORK_ID_BUF_LEN, (char *)reply.data, strlen((char *)reply.data)) != EOK) {
515         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcActiveMetaNode copy meta node id failed");
516         return SOFTBUS_ERR;
517     }
518     return SOFTBUS_OK;
519 }
520 
ServerIpcDeactiveMetaNode(const char * pkgName,const char * metaNodeId)521 int32_t ServerIpcDeactiveMetaNode(const char *pkgName, const char *metaNodeId)
522 {
523     if (g_serverProxy == NULL) {
524         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode g_serverProxy is nullptr!");
525         return SOFTBUS_ERR;
526     }
527 
528     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
529     IpcIo request = {0};
530     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
531     IpcIoPushString(&request, pkgName);
532     IpcIoPushString(&request, metaNodeId);
533     Reply reply = {0};
534     reply.id = DEACTIVE_META_NODE;
535     /* asynchronous invocation */
536     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_DEACTIVE_META_NODE, &request,
537         &reply, ClientBusCenterResultCb);
538     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
539         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcDeactiveMetaNode invoke failed[%d, %d]",
540             ans, reply.retCode);
541         return SOFTBUS_ERR;
542     }
543     return SOFTBUS_OK;
544 }
545 
ServerIpcGetAllMetaNodeInfo(const char * pkgName,MetaNodeInfo * infos,int32_t * infoNum)546 int32_t ServerIpcGetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum)
547 {
548     if (g_serverProxy == NULL) {
549         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo g_serverProxy is nullptr!");
550         return SOFTBUS_ERR;
551     }
552 
553     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
554     IpcIo request = {0};
555     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
556     IpcIoPushString(&request, pkgName);
557     IpcIoPushInt32(&request, *infoNum);
558     Reply reply = {0};
559     reply.id = GET_ALL_META_NODE;
560     /* asynchronous invocation */
561     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_ALL_META_NODE_INFO, &request, &reply,
562         ClientBusCenterResultCb);
563     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
564         SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo invoke failed[%d, %d]",
565             ans, reply.retCode);
566         return SOFTBUS_ERR;
567     }
568     if (reply.arg1 > 0) {
569         if (reply.data == NULL) {
570             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo read meta node info failed!");
571             return SOFTBUS_ERR;
572         }
573         if (memcpy_s(infos, *infoNum * sizeof(MetaNodeInfo), reply.data, reply.arg1 * sizeof(MetaNodeInfo)) != EOK) {
574             SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "ServerIpcGetAllMetaNodeInfo copy meta node info failed");
575             return SOFTBUS_ERR;
576         }
577     }
578     *infoNum = reply.arg1;
579     return SOFTBUS_OK;
580 }
581