• 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 "lnn_log.h"
22 #include "samgr_lite.h"
23 #include "serializer.h"
24 #include "softbus_adapter_file.h"
25 #include "softbus_adapter_mem.h"
26 #include "softbus_adapter_timer.h"
27 #include "softbus_def.h"
28 #include "softbus_error_code.h"
29 #include "softbus_feature_config.h"
30 #include "softbus_server_ipc_interface_code.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     SHIFT_LNN_GEAR,
42     START_REFRESH_LNN,
43     START_PUBLISH_LNN,
44     STOP_DISCOVERY_LNN,
45     STOP_PUBLISH_LNN,
46 } FunID;
47 
48 typedef struct {
49     FunID id;
50     int32_t arg1;
51     int32_t retCode;
52     void* data;
53     int32_t dataLen;
54 } Reply;
55 
56 typedef int32_t (*ClientBusCenterFunIdHandler)(Reply *, IpcIo *, uint32_t);
57 
58 typedef struct {
59     int32_t funIdType;
60     ClientBusCenterFunIdHandler funIdHandler;
61 } ClientBusCenterStateHandler;
62 
63 static int32_t OnOnlineNodeInfo(Reply *info, IpcIo *reply, uint32_t infoSize);
64 static int32_t OnLocalDeviceInfo(Reply *info, IpcIo *reply, uint32_t infoSize);
65 static int32_t OnNodeKeyInfo(Reply *info, IpcIo *reply, uint32_t infoSize);
66 static int32_t OnActiveMetaNode(Reply *info, IpcIo *reply, uint32_t infoSize);
67 static int32_t OnDeactiveMetaNode(Reply *info, IpcIo *reply, uint32_t infoSize);
68 static int32_t OnAllMetaNode(Reply *info, IpcIo *reply, uint32_t infoSize);
69 static int32_t OnShiftLnnGear(Reply *info, IpcIo *reply, uint32_t infoSize);
70 static int32_t OnStartRefreshLnn(Reply *info, IpcIo *reply, uint32_t infoSize);
71 static int32_t OnStartPublishLnn(Reply *info, IpcIo *reply, uint32_t infoSize);
72 static int32_t OnStopDiscoveryLnn(Reply *info, IpcIo *reply, uint32_t infoSize);
73 static int32_t OnStopPublishLnn(Reply *info, IpcIo *reply, uint32_t infoSize);
74 
75 static ClientBusCenterStateHandler g_busCenterStateHandler[] = {
76     {GET_ALL_ONLINE_NODE_INFO, OnOnlineNodeInfo  },
77     { GET_LOCAL_DEVICE_INFO,   OnLocalDeviceInfo },
78     { GET_NODE_KEY_INFO,       OnNodeKeyInfo     },
79     { ACTIVE_META_NODE,        OnActiveMetaNode  },
80     { DEACTIVE_META_NODE,      OnDeactiveMetaNode},
81     { GET_ALL_META_NODE,       OnAllMetaNode     },
82     { SHIFT_LNN_GEAR,          OnShiftLnnGear    },
83     { START_REFRESH_LNN,       OnStartRefreshLnn },
84     { START_PUBLISH_LNN,       OnStartPublishLnn },
85     { STOP_DISCOVERY_LNN,      OnStopDiscoveryLnn},
86     { STOP_PUBLISH_LNN,        OnStopPublishLnn  },
87 };
88 
89 static IClientProxy *g_serverProxy = NULL;
90 
OnOnlineNodeInfo(Reply * info,IpcIo * reply,uint32_t infoSize)91 static int32_t OnOnlineNodeInfo(Reply *info, IpcIo *reply, uint32_t infoSize)
92 {
93     ReadInt32(reply, &(info->arg1));
94     if (info->arg1 > 0) {
95         ReadUint32(reply, &infoSize);
96         info->data = (void *)ReadBuffer(reply, infoSize);
97     }
98     return SOFTBUS_OK;
99 }
100 
OnLocalDeviceInfo(Reply * info,IpcIo * reply,uint32_t infoSize)101 static int32_t OnLocalDeviceInfo(Reply *info, IpcIo *reply, uint32_t infoSize)
102 {
103     ReadInt32(reply, &infoSize);
104     info->dataLen = infoSize;
105     info->data = (void *)ReadBuffer(reply, infoSize);
106     return SOFTBUS_OK;
107 }
108 
OnNodeKeyInfo(Reply * info,IpcIo * reply,uint32_t infoSize)109 static int32_t OnNodeKeyInfo(Reply *info, IpcIo *reply, uint32_t infoSize)
110 {
111     ReadInt32(reply, &infoSize);
112     info->dataLen = infoSize;
113     info->data = (void *)ReadBuffer(reply, infoSize);
114     return SOFTBUS_OK;
115 }
116 
OnActiveMetaNode(Reply * info,IpcIo * reply,uint32_t infoSize)117 static int32_t OnActiveMetaNode(Reply *info, IpcIo *reply, uint32_t infoSize)
118 {
119     ReadInt32(reply, &(info->retCode));
120     if (info->retCode == SOFTBUS_OK) {
121         info->data = (void *)ReadString(reply, &infoSize);
122         if (infoSize != (NETWORK_ID_BUF_LEN - 1)) {
123             LNN_LOGE(LNN_EVENT, "invalid meta node id length=%{public}u", infoSize);
124             return SOFTBUS_INVALID_PARAM;
125         }
126     }
127     return SOFTBUS_OK;
128 }
129 
OnDeactiveMetaNode(Reply * info,IpcIo * reply,uint32_t infoSize)130 static int32_t OnDeactiveMetaNode(Reply *info, IpcIo *reply, uint32_t infoSize)
131 {
132     ReadInt32(reply, &(info->retCode));
133     return SOFTBUS_OK;
134 }
135 
OnAllMetaNode(Reply * info,IpcIo * reply,uint32_t infoSize)136 static int32_t OnAllMetaNode(Reply *info, IpcIo *reply, uint32_t infoSize)
137 {
138     ReadInt32(reply, &(info->retCode));
139     if (info->retCode == SOFTBUS_OK) {
140         ReadInt32(reply, &(info->arg1));
141         if (info->arg1 > 0) {
142             ReadUint32(reply, &infoSize);
143             info->data = (void *)ReadBuffer(reply, infoSize);
144         }
145     }
146     return SOFTBUS_OK;
147 }
148 
OnShiftLnnGear(Reply * info,IpcIo * reply,uint32_t infoSize)149 static int32_t OnShiftLnnGear(Reply *info, IpcIo *reply, uint32_t infoSize)
150 {
151     ReadInt32(reply, &(info->retCode));
152     return SOFTBUS_OK;
153 }
154 
OnStartRefreshLnn(Reply * info,IpcIo * reply,uint32_t infoSize)155 static int32_t OnStartRefreshLnn(Reply *info, IpcIo *reply, uint32_t infoSize)
156 {
157     ReadInt32(reply, &(info->retCode));
158     return SOFTBUS_OK;
159 }
160 
OnStartPublishLnn(Reply * info,IpcIo * reply,uint32_t infoSize)161 static int32_t OnStartPublishLnn(Reply *info, IpcIo *reply, uint32_t infoSize)
162 {
163     ReadInt32(reply, &(info->retCode));
164     return SOFTBUS_OK;
165 }
166 
OnStopDiscoveryLnn(Reply * info,IpcIo * reply,uint32_t infoSize)167 static int32_t OnStopDiscoveryLnn(Reply *info, IpcIo *reply, uint32_t infoSize)
168 {
169     ReadInt32(reply, &(info->retCode));
170     return SOFTBUS_OK;
171 }
172 
OnStopPublishLnn(Reply * info,IpcIo * reply,uint32_t infoSize)173 static int32_t OnStopPublishLnn(Reply *info, IpcIo *reply, uint32_t infoSize)
174 {
175     ReadInt32(reply, &(info->retCode));
176     return SOFTBUS_OK;
177 }
178 
ClientBusCenterResultCb(Reply * info,int32_t ret,IpcIo * reply)179 static int32_t ClientBusCenterResultCb(Reply *info, int32_t ret, IpcIo *reply)
180 {
181     if (ret != SOFTBUS_OK) {
182         LNN_LOGE(LNN_EVENT, "ClientBusCenterResultCb failed. ret=%{public}d", ret);
183         return ret;
184     }
185     uint32_t infoSize;
186     uint32_t count = sizeof(g_busCenterStateHandler) / sizeof(ClientBusCenterStateHandler);
187     for (uint32_t i = 0; i < count; i++) {
188         if (g_busCenterStateHandler[i].funIdType == info->id) {
189             return (g_busCenterStateHandler[i].funIdHandler)(info, reply, infoSize);
190         }
191     }
192     LNN_LOGI(LNN_INIT, "funcId not exist");
193     return SOFTBUS_FUNC_NOT_SUPPORT;
194 }
195 
BusCenterServerProxyInit(void)196 int32_t BusCenterServerProxyInit(void)
197 {
198     if (g_serverProxy != NULL) {
199         LNN_LOGI(LNN_INIT, "server proxy has initialized");
200         return SOFTBUS_OK;
201     }
202 
203     LNN_LOGI(LNN_INIT, "bus center start get server proxy");
204     int32_t proxyInitCount = 0;
205     while (g_serverProxy == NULL) {
206         proxyInitCount++;
207         if (proxyInitCount == WAIT_SERVER_READY_INTERVAL_COUNT) {
208             LNN_LOGE(LNN_INIT, "bus center get server proxy error");
209             return SOFTBUS_SERVER_NOT_INIT;
210         }
211 
212         IUnknown *iUnknown = SAMGR_GetInstance()->GetDefaultFeatureApi(SOFTBUS_SERVICE);
213         if (iUnknown == NULL) {
214             SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
215             continue;
216         }
217 
218         int32_t ret = iUnknown->QueryInterface(iUnknown, CLIENT_PROXY_VER, (void **)&g_serverProxy);
219         if (ret != EC_SUCCESS || g_serverProxy == NULL) {
220             LNN_LOGE(LNN_INIT, "QueryInterface failed=%{public}d", ret);
221             SoftBusSleepMs(WAIT_SERVER_READY_INTERVAL);
222             continue;
223         }
224     }
225     LNN_LOGI(LNN_INIT, "bus center get server proxy ok");
226     return SOFTBUS_OK;
227 }
228 
BusCenterServerProxyDeInit(void)229 void BusCenterServerProxyDeInit(void)
230 {
231     g_serverProxy = NULL;
232 }
233 
ServerIpcGetAllOnlineNodeInfo(const char * pkgName,void ** info,uint32_t infoTypeLen,int32_t * infoNum)234 int32_t ServerIpcGetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int32_t *infoNum)
235 {
236     if (info == NULL || infoNum == NULL) {
237         LNN_LOGW(LNN_EVENT, "Invalid param");
238         return SOFTBUS_INVALID_PARAM;
239     }
240     if (g_serverProxy == NULL) {
241         LNN_LOGE(LNN_EVENT, "g_serverProxy is NULL");
242         return SOFTBUS_SERVER_NOT_INIT;
243     }
244     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
245     IpcIo request = {0};
246     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
247     WriteString(&request, pkgName);
248     WriteUint32(&request, infoTypeLen);
249     Reply reply = {0};
250     reply.id = GET_ALL_ONLINE_NODE_INFO;
251     /* asynchronous invocation */
252     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_ALL_ONLINE_NODE_INFO, &request, &reply,
253         ClientBusCenterResultCb);
254     if (ans != SOFTBUS_OK) {
255         LNN_LOGE(LNN_EVENT, "invoke failed=%{public}d", ans);
256         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
257     }
258     uint32_t maxConnCount = UINT32_MAX;
259     (void)SoftbusGetConfig(SOFTBUS_INT_MAX_LNN_CONNECTION_CNT, (unsigned char *)&maxConnCount, sizeof(maxConnCount));
260     *infoNum = reply.arg1;
261     if (*infoNum < 0 || (uint32_t)(*infoNum) > maxConnCount) {
262         LNN_LOGE(LNN_EVENT, "invoke failed=%{public}d", *infoNum);
263         return SOFTBUS_NETWORK_INVALID_REPLY_DATA;
264     }
265     int32_t infoSize = (*infoNum) * (int32_t)infoTypeLen;
266     *info = NULL;
267     if (infoSize > 0) {
268         if (reply.data == NULL) {
269             LNN_LOGE(LNN_EVENT, "read node info failed");
270             return SOFTBUS_NETWORK_INVALID_REPLY_DATA;
271         }
272         *info = SoftBusMalloc(infoSize);
273         if (*info == NULL) {
274             LNN_LOGE(LNN_EVENT, "malloc failed");
275             return SOFTBUS_MALLOC_ERR;
276         }
277         if (memcpy_s(*info, infoSize, reply.data, infoSize) != EOK) {
278             LNN_LOGE(LNN_EVENT, "copy node info failed");
279             SoftBusFree(*info);
280             *info = NULL;
281             return SOFTBUS_MEM_ERR;
282         }
283     }
284     return SOFTBUS_OK;
285 }
286 
ServerIpcGetLocalDeviceInfo(const char * pkgName,void * info,uint32_t infoTypeLen)287 int32_t ServerIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
288 {
289     if (info == NULL) {
290         return SOFTBUS_INVALID_PARAM;
291     }
292     if (g_serverProxy == NULL) {
293         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
294         return SOFTBUS_SERVER_NOT_INIT;
295     }
296 
297     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
298     IpcIo request = {0};
299     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
300     WriteString(&request, pkgName);
301     WriteUint32(&request, infoTypeLen);
302     Reply reply = {0};
303     reply.id = GET_LOCAL_DEVICE_INFO;
304     /* asynchronous invocation */
305     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_LOCAL_DEVICE_INFO, &request, &reply,
306         ClientBusCenterResultCb);
307     if (ans != SOFTBUS_OK) {
308         LNN_LOGE(LNN_EVENT, "invoke failed=%{public}d", ans);
309         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
310     }
311     if (reply.data == NULL) {
312         LNN_LOGE(LNN_EVENT, "read node info failed");
313         return SOFTBUS_NETWORK_INVALID_REPLY_DATA;
314     }
315     if (memcpy_s(info, infoTypeLen, reply.data, infoTypeLen) != EOK) {
316         LNN_LOGE(LNN_EVENT, "copy node info failed");
317         return SOFTBUS_MEM_ERR;
318     }
319     return SOFTBUS_OK;
320 }
321 
ServerIpcGetNodeKeyInfo(const char * pkgName,const char * networkId,int32_t key,unsigned char * buf,uint32_t len)322 int32_t ServerIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int32_t key, unsigned char *buf,
323     uint32_t len)
324 {
325     if (networkId == NULL || buf == NULL) {
326         LNN_LOGW(LNN_EVENT, "params are nullptr");
327         return SOFTBUS_INVALID_PARAM;
328     }
329     if (g_serverProxy == NULL) {
330         LNN_LOGW(LNN_EVENT, "g_serverProxy is nullptr");
331         return SOFTBUS_SERVER_NOT_INIT;
332     }
333 
334     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
335     IpcIo request = {0};
336     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
337     WriteString(&request, pkgName);
338     WriteString(&request, networkId);
339     WriteInt32(&request, key);
340     WriteUint32(&request, len);
341     Reply reply = {0};
342     reply.id = GET_NODE_KEY_INFO;
343     /* asynchronous invocation */
344     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_NODE_KEY_INFO, &request, &reply,
345         ClientBusCenterResultCb);
346     if (ans != SOFTBUS_OK) {
347         LNN_LOGE(LNN_EVENT, "GetNodeKeyInfo invoke failed=%{public}d", ans);
348         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
349     }
350     if (reply.data == NULL || reply.dataLen <= 0 || (uint32_t)reply.dataLen > len) {
351         LNN_LOGE(LNN_EVENT,
352             "GetNodeKeyInfo read retBuf failed, inlen=%{public}u, reply.dataLen=%{public}d", len, reply.dataLen);
353         return SOFTBUS_NETWORK_INVALID_REPLY_DATA;
354     }
355     if (memcpy_s(buf, len, reply.data, reply.dataLen) != EOK) {
356         LNN_LOGE(LNN_EVENT, "GetNodeKeyInfo copy node key info failed");
357         return SOFTBUS_MEM_ERR;
358     }
359     return SOFTBUS_OK;
360 }
361 
ServerIpcSetNodeDataChangeFlag(const char * pkgName,const char * networkId,uint16_t dataChangeFlag)362 int32_t ServerIpcSetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag)
363 {
364     if (networkId == NULL) {
365         LNN_LOGE(LNN_EVENT, "params are nullptr");
366         return SOFTBUS_INVALID_PARAM;
367     }
368     if (g_serverProxy == NULL) {
369         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
370         return SOFTBUS_SERVER_NOT_INIT;
371     }
372 
373     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
374     IpcIo request = {0};
375     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
376     WriteString(&request, pkgName);
377     WriteString(&request, networkId);
378     WriteInt16(&request, dataChangeFlag);
379     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_SET_NODE_DATA_CHANGE_FLAG, &request, NULL, NULL);
380     if (ans != SOFTBUS_OK) {
381         LNN_LOGE(LNN_EVENT, "invoke failed=%{public}d", ans);
382         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
383     }
384     return SOFTBUS_OK;
385 }
386 
ServerIpcRegDataLevelChangeCb(const char * pkgName)387 int32_t ServerIpcRegDataLevelChangeCb(const char *pkgName)
388 {
389     if (pkgName == NULL) {
390         LNN_LOGE(LNN_EVENT, "params are nullptr");
391         return SOFTBUS_INVALID_PARAM;
392     }
393     if (g_serverProxy == NULL) {
394         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
395         return SOFTBUS_SERVER_NOT_INIT;
396     }
397     IpcIo request = {0};
398     return g_serverProxy->Invoke(g_serverProxy, SERVER_REG_DATA_LEVEL_CHANGE_CB, &request, NULL, NULL);
399 }
400 
ServerIpcUnregDataLevelChangeCb(const char * pkgName)401 int32_t ServerIpcUnregDataLevelChangeCb(const char *pkgName)
402 {
403     if (pkgName == NULL) {
404         LNN_LOGE(LNN_EVENT, "params are nullptr");
405         return SOFTBUS_INVALID_PARAM;
406     }
407     if (g_serverProxy == NULL) {
408         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
409         return SOFTBUS_SERVER_NOT_INIT;
410     }
411     IpcIo request = {0};
412     return g_serverProxy->Invoke(g_serverProxy, SERVER_UNREG_DATA_LEVEL_CHANGE_CB, &request, NULL, NULL);
413 }
414 
ServerIpcSetDataLevel(const DataLevel * dataLevel)415 int32_t ServerIpcSetDataLevel(const DataLevel *dataLevel)
416 {
417     if (dataLevel == NULL) {
418         LNN_LOGE(LNN_EVENT, "params are nullptr");
419         return SOFTBUS_INVALID_PARAM;
420     }
421     if (g_serverProxy == NULL) {
422         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
423         return SOFTBUS_SERVER_NOT_INIT;
424     }
425     IpcIo request = {0};
426     return g_serverProxy->Invoke(g_serverProxy, SERVER_SET_DATA_LEVEL, &request, NULL, NULL);
427 }
428 
ServerIpcRegRangeCbForMsdp(const char * pkgName)429 int32_t ServerIpcRegRangeCbForMsdp(const char *pkgName)
430 {
431     if (pkgName == NULL) {
432         LNN_LOGE(LNN_EVENT, "params are nullptr");
433         return SOFTBUS_INVALID_PARAM;
434     }
435     if (g_serverProxy == NULL) {
436         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
437         return SOFTBUS_SERVER_NOT_INIT;
438     }
439     IpcIo request = {0};
440     return g_serverProxy->Invoke(g_serverProxy, SERVER_REG_RANGE_CB_FOR_MSDP, &request, NULL, NULL);
441 }
442 
ServerIpcUnregRangeCbForMsdp(const char * pkgName)443 int32_t ServerIpcUnregRangeCbForMsdp(const char *pkgName)
444 {
445     if (pkgName == NULL) {
446         LNN_LOGE(LNN_EVENT, "params are nullptr");
447         return SOFTBUS_INVALID_PARAM;
448     }
449     if (g_serverProxy == NULL) {
450         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
451         return SOFTBUS_SERVER_NOT_INIT;
452     }
453     IpcIo request = {0};
454     return g_serverProxy->Invoke(g_serverProxy, SERVER_UNREG_RANGE_CB_FOR_MSDP, &request, NULL, NULL);
455 }
456 
ServerIpcTriggerRangeForMsdp(const char * pkgName,const RangeConfig * config)457 int32_t ServerIpcTriggerRangeForMsdp(const char *pkgName, const RangeConfig *config)
458 {
459     if (pkgName == NULL || config == NULL) {
460         LNN_LOGE(LNN_EVENT, "params are nullptr");
461         return SOFTBUS_INVALID_PARAM;
462     }
463     if (g_serverProxy == NULL) {
464         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
465         return SOFTBUS_SERVER_NOT_INIT;
466     }
467     IpcIo request = {0};
468     return g_serverProxy->Invoke(g_serverProxy, SERVER_TRIGGER_RANGE_FOR_MSDP, &request, NULL, NULL);
469 }
470 
ServerIpcStopRangeForMsdp(const char * pkgName,const RangeConfig * config)471 int32_t ServerIpcStopRangeForMsdp(const char *pkgName, const RangeConfig *config)
472 {
473     if (pkgName == NULL || config == NULL) {
474         LNN_LOGE(LNN_EVENT, "params are nullptr");
475         return SOFTBUS_INVALID_PARAM;
476     }
477     if (g_serverProxy == NULL) {
478         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
479         return SOFTBUS_SERVER_NOT_INIT;
480     }
481     IpcIo request = {0};
482     return g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_RANGE_FOR_MSDP, &request, NULL, NULL);
483 }
484 
ServerIpcJoinLNN(const char * pkgName,void * addr,uint32_t addrTypeLen,bool isForceJoin)485 int32_t ServerIpcJoinLNN(const char *pkgName, void *addr, uint32_t addrTypeLen, bool isForceJoin)
486 {
487     LNN_LOGD(LNN_EVENT, "join Lnn ipc client push");
488     if (addr == NULL || pkgName == NULL) {
489         LNN_LOGW(LNN_EVENT, "Invalid param");
490         return SOFTBUS_INVALID_PARAM;
491     }
492     if (g_serverProxy == NULL) {
493         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
494         return SOFTBUS_SERVER_NOT_INIT;
495     }
496     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
497     IpcIo request = {0};
498     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
499     WriteString(&request, pkgName);
500     WriteUint32(&request, addrTypeLen);
501     WriteBuffer(&request, addr, addrTypeLen);
502     WriteBool(&request, isForceJoin);
503     /* asynchronous invocation */
504     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_JOIN_LNN, &request, NULL, NULL);
505     if (ans != SOFTBUS_OK) {
506         LNN_LOGE(LNN_EVENT, "join Lnn invoke failed=%{public}d", ans);
507         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
508     }
509     return SOFTBUS_OK;
510 }
511 
ServerIpcLeaveLNN(const char * pkgName,const char * networkId)512 int32_t ServerIpcLeaveLNN(const char *pkgName, const char *networkId)
513 {
514     LNN_LOGD(LNN_EVENT, "leave Lnn ipc client push");
515     if (pkgName == NULL || networkId == NULL) {
516         LNN_LOGW(LNN_EVENT, "Invalid param");
517         return SOFTBUS_INVALID_PARAM;
518     }
519     if (g_serverProxy == NULL) {
520         LNN_LOGE(LNN_EVENT, "ServerIpcLeaveLNN g_serverProxy is nullptr!\n");
521         return SOFTBUS_SERVER_NOT_INIT;
522     }
523     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
524     IpcIo request = {0};
525     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
526     WriteString(&request, pkgName);
527     WriteString(&request, networkId);
528     /* asynchronous invocation */
529     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_LEAVE_LNN, &request, NULL, NULL);
530     if (ans != SOFTBUS_OK) {
531         LNN_LOGE(LNN_EVENT, "leave Lnn invoke failed=%{public}d", ans);
532         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
533     }
534     return SOFTBUS_OK;
535 }
536 
ServerIpcStartTimeSync(const char * pkgName,const char * targetNetworkId,int32_t accuracy,int32_t period)537 int32_t ServerIpcStartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy, int32_t period)
538 {
539     LNN_LOGD(LNN_EVENT, "start time sync ipc client push");
540     if (targetNetworkId == NULL || pkgName == NULL) {
541         LNN_LOGW(LNN_EVENT, "Invalid param");
542         return SOFTBUS_INVALID_PARAM;
543     }
544     if (g_serverProxy == NULL) {
545         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
546         return SOFTBUS_SERVER_NOT_INIT;
547     }
548 
549     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
550     IpcIo request = {0};
551     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
552     WriteString(&request, pkgName);
553     WriteString(&request, targetNetworkId);
554     WriteInt32(&request, accuracy);
555     WriteInt32(&request, period);
556     /* asynchronous invocation */
557     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_START_TIME_SYNC, &request, NULL, NULL);
558     if (ans != SOFTBUS_OK) {
559         LNN_LOGE(LNN_EVENT, "StartTimeSync invoke failed=%{public}d", ans);
560         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
561     }
562     return SOFTBUS_OK;
563 }
564 
ServerIpcStopTimeSync(const char * pkgName,const char * targetNetworkId)565 int32_t ServerIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
566 {
567     LNN_LOGD(LNN_EVENT, "stop time sync ipc client push");
568     if (targetNetworkId == NULL || pkgName == NULL) {
569         LNN_LOGW(LNN_EVENT, "Invalid param");
570         return SOFTBUS_INVALID_PARAM;
571     }
572     if (g_serverProxy == NULL) {
573         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
574         return SOFTBUS_SERVER_NOT_INIT;
575     }
576 
577     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
578     IpcIo request = {0};
579     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
580     WriteString(&request, pkgName);
581     WriteString(&request, targetNetworkId);
582     /* asynchronous invocation */
583     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_TIME_SYNC, &request, NULL, NULL);
584     if (ans != SOFTBUS_OK) {
585         LNN_LOGE(LNN_EVENT, "StopTimeSync invoke failed=%{public}d", ans);
586         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
587     }
588     return SOFTBUS_OK;
589 }
590 
ServerIpcPublishLNN(const char * pkgName,const PublishInfo * info)591 int32_t ServerIpcPublishLNN(const char *pkgName, const PublishInfo *info)
592 {
593     LNN_LOGD(LNN_EVENT, "publish Lnn ipc client push");
594     if (info == NULL || pkgName == NULL) {
595         LNN_LOGW(LNN_EVENT, "Invalid param");
596         return SOFTBUS_INVALID_PARAM;
597     }
598     if (g_serverProxy == NULL) {
599         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
600         return SOFTBUS_SERVER_NOT_INIT;
601     }
602     uint8_t data[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
603     IpcIo request = {0};
604     Reply reply = {0};
605     reply.id = START_PUBLISH_LNN;
606     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN_EX, 0);
607     WriteString(&request, pkgName);
608     WriteInt32(&request, info->publishId);
609     WriteInt32(&request, info->mode);
610     WriteInt32(&request, info->medium);
611     WriteInt32(&request, info->freq);
612     WriteString(&request, info->capability);
613     WriteUint32(&request, info->dataLen);
614     if (info->dataLen != 0) {
615         WriteString(&request, info->capabilityData);
616     }
617     WriteBool(&request, info->ranging);
618     /* asynchronous invocation */
619     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_PUBLISH_LNN, &request, &reply, ClientBusCenterResultCb);
620     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
621         LNN_LOGE(LNN_EVENT, "publish Lnn invoke failed. ans=%{public}d, retCode=%{public}d", ans, reply.retCode);
622         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
623     }
624     return SOFTBUS_OK;
625 }
626 
ServerIpcStopPublishLNN(const char * pkgName,int32_t publishId)627 int32_t ServerIpcStopPublishLNN(const char *pkgName, int32_t publishId)
628 {
629     LNN_LOGD(LNN_EVENT, "stop publish lnn ipc client push");
630     if (pkgName == NULL) {
631         LNN_LOGW(LNN_EVENT, "Invalid param");
632         return SOFTBUS_INVALID_PARAM;
633     }
634     if (g_serverProxy == NULL) {
635         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
636         return SOFTBUS_SERVER_NOT_INIT;
637     }
638 
639     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
640     IpcIo request = {0};
641     Reply reply = {0};
642     reply.id = STOP_PUBLISH_LNN;
643     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
644     WriteString(&request, pkgName);
645     WriteInt32(&request, publishId);
646     /* asynchronous invocation */
647     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_PUBLISH_LNN, &request, &reply,
648         ClientBusCenterResultCb);
649     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
650         LNN_LOGE(LNN_EVENT, "ServerIpcStopPublishLNN invoke failed. ans=%{public}d, retCode=%{public}d",
651             ans, reply.retCode);
652         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
653     }
654     return SOFTBUS_OK;
655 }
656 
ServerIpcRefreshLNN(const char * pkgName,const SubscribeInfo * info)657 int32_t ServerIpcRefreshLNN(const char *pkgName, const SubscribeInfo *info)
658 {
659     LNN_LOGD(LNN_EVENT, "refresh Lnn ipc client push");
660     if (info == NULL || pkgName == NULL) {
661         LNN_LOGW(LNN_EVENT, "Invalid param");
662         return SOFTBUS_INVALID_PARAM;
663     }
664     if (g_serverProxy == NULL) {
665         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr!");
666         return SOFTBUS_SERVER_NOT_INIT;
667     }
668     uint8_t data[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
669     IpcIo request = {0};
670     Reply reply = {0};
671     reply.id = START_REFRESH_LNN;
672     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN_EX, 0);
673     WriteString(&request, pkgName);
674     WriteInt32(&request, info->subscribeId);
675     WriteInt32(&request, info->mode);
676     WriteInt32(&request, info->medium);
677     WriteInt32(&request, info->freq);
678     WriteBool(&request, info->isSameAccount);
679     WriteBool(&request, info->isWakeRemote);
680     WriteString(&request, info->capability);
681     WriteUint32(&request, info->dataLen);
682     if (info->dataLen != 0) {
683         WriteString(&request, info->capabilityData);
684     }
685     /* asynchronous invocation */
686     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_REFRESH_LNN, &request, &reply, ClientBusCenterResultCb);
687     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
688         LNN_LOGE(LNN_EVENT, "refresh Lnn invoke failed. ans=%{public}d, retCode=%{public}d", ans, reply.retCode);
689         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
690     }
691     return SOFTBUS_OK;
692 }
693 
ServerIpcStopRefreshLNN(const char * pkgName,int32_t refreshId)694 int32_t ServerIpcStopRefreshLNN(const char *pkgName, int32_t refreshId)
695 {
696     LNN_LOGD(LNN_EVENT, "stop refresh lnn ipc client push");
697     if (pkgName == NULL) {
698         LNN_LOGW(LNN_EVENT, "Invalid param");
699         return SOFTBUS_INVALID_PARAM;
700     }
701     if (g_serverProxy == NULL) {
702         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
703         return SOFTBUS_SERVER_NOT_INIT;
704     }
705 
706     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
707     IpcIo request = {0};
708     Reply reply = {0};
709     reply.id = STOP_DISCOVERY_LNN;
710     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
711     WriteString(&request, pkgName);
712     WriteInt32(&request, refreshId);
713     /* asynchronous invocation */
714     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_STOP_REFRESH_LNN, &request, &reply,
715         ClientBusCenterResultCb);
716     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
717         LNN_LOGE(LNN_EVENT, "ServerIpcStopRefreshLNN invoke failed. ans=%{public}d, retCode=%{public}d",
718             ans, reply.retCode);
719         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
720     }
721     return SOFTBUS_OK;
722 }
723 
ServerIpcActiveMetaNode(const char * pkgName,const MetaNodeConfigInfo * info,char * metaNodeId)724 int32_t ServerIpcActiveMetaNode(const char *pkgName, const MetaNodeConfigInfo *info, char *metaNodeId)
725 {
726     if (g_serverProxy == NULL) {
727         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
728         return SOFTBUS_SERVER_NOT_INIT;
729     }
730 
731     uint8_t data[MAX_SOFT_BUS_IPC_LEN_EX] = {0};
732     IpcIo request = {0};
733     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN_EX, 0);
734     WriteString(&request, pkgName);
735     bool ret = WriteRawData(&request, info, sizeof(MetaNodeConfigInfo));
736     if (!ret) {
737         return SOFTBUS_NETWORK_READRAWDATA_FAILED;
738     }
739     Reply reply = {0};
740     reply.id = ACTIVE_META_NODE;
741     /* asynchronous invocation */
742     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_ACTIVE_META_NODE, &request, &reply,
743         ClientBusCenterResultCb);
744     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
745         LNN_LOGE(LNN_EVENT, "invoke failed. ans=%{public}d, retCode=%{public}d", ans, reply.retCode);
746         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
747     }
748     if (reply.data == NULL) {
749         LNN_LOGE(LNN_EVENT, "read data failed");
750         return SOFTBUS_NETWORK_INVALID_REPLY_DATA;
751     }
752     if (strncpy_s(metaNodeId, NETWORK_ID_BUF_LEN, (char *)reply.data, strlen((char *)reply.data)) != EOK) {
753         LNN_LOGE(LNN_EVENT, "copy meta node id failed");
754         return SOFTBUS_MEM_ERR;
755     }
756     return SOFTBUS_OK;
757 }
758 
ServerIpcDeactiveMetaNode(const char * pkgName,const char * metaNodeId)759 int32_t ServerIpcDeactiveMetaNode(const char *pkgName, const char *metaNodeId)
760 {
761     if (g_serverProxy == NULL) {
762         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
763         return SOFTBUS_SERVER_NOT_INIT;
764     }
765 
766     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
767     IpcIo request = {0};
768     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
769     WriteString(&request, pkgName);
770     WriteString(&request, metaNodeId);
771     Reply reply = {0};
772     reply.id = DEACTIVE_META_NODE;
773     /* asynchronous invocation */
774     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_DEACTIVE_META_NODE, &request,
775         &reply, ClientBusCenterResultCb);
776     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
777         LNN_LOGE(LNN_EVENT, "invoke failed. ans=%{public}d, retCode=%{public}d", ans, reply.retCode);
778         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
779     }
780     return SOFTBUS_OK;
781 }
782 
ServerIpcGetAllMetaNodeInfo(const char * pkgName,MetaNodeInfo * infos,int32_t * infoNum)783 int32_t ServerIpcGetAllMetaNodeInfo(const char *pkgName, MetaNodeInfo *infos, int32_t *infoNum)
784 {
785     if (g_serverProxy == NULL) {
786         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
787         return SOFTBUS_SERVER_NOT_INIT;
788     }
789 
790     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
791     IpcIo request = {0};
792     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
793     WriteString(&request, pkgName);
794     WriteInt32(&request, *infoNum);
795     Reply reply = {0};
796     reply.id = GET_ALL_META_NODE;
797     /* asynchronous invocation */
798     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_GET_ALL_META_NODE_INFO, &request, &reply,
799         ClientBusCenterResultCb);
800     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
801         LNN_LOGE(LNN_EVENT, "invoke failed. ans=%{public}d, retCode=%{public}d", ans, reply.retCode);
802         return SOFTBUS_NETWORK_PROXY_INVOKE_FAILED;
803     }
804     if (reply.arg1 > 0) {
805         if (reply.data == NULL) {
806             LNN_LOGE(LNN_EVENT, "read meta node info failed");
807             return SOFTBUS_NETWORK_INVALID_REPLY_DATA;
808         }
809         if (memcpy_s(infos, *infoNum * sizeof(MetaNodeInfo), reply.data, reply.arg1 * sizeof(MetaNodeInfo)) != EOK) {
810             LNN_LOGE(LNN_EVENT, "copy meta node info failed");
811             return SOFTBUS_MEM_ERR;
812         }
813     }
814     *infoNum = reply.arg1;
815     return SOFTBUS_OK;
816 }
817 
ServerIpcShiftLNNGear(const char * pkgName,const char * callerId,const char * targetNetworkId,const GearMode * mode)818 int32_t ServerIpcShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId,
819     const GearMode *mode)
820 {
821     if (pkgName == NULL || callerId == NULL || mode == NULL) {
822         LNN_LOGW(LNN_EVENT, "Invalid param");
823         return SOFTBUS_INVALID_PARAM;
824     }
825     if (g_serverProxy == NULL) {
826         LNN_LOGE(LNN_EVENT, "g_serverProxy is nullptr");
827         return SOFTBUS_SERVER_NOT_INIT;
828     }
829 
830     uint8_t data[MAX_SOFT_BUS_IPC_LEN] = {0};
831     bool targetNetworkIdIsNull = targetNetworkId == NULL ? true : false;
832     IpcIo request = {0};
833     IpcIoInit(&request, data, MAX_SOFT_BUS_IPC_LEN, 0);
834     WriteString(&request, pkgName);
835     WriteString(&request, callerId);
836     WriteBool(&request, targetNetworkIdIsNull);
837     if (!targetNetworkIdIsNull) {
838         WriteString(&request, targetNetworkId);
839     }
840     WriteRawData(&request, mode, sizeof(GearMode));
841     Reply reply = {0};
842     reply.id = SHIFT_LNN_GEAR;
843     /* asynchronous invocation */
844     int32_t ans = g_serverProxy->Invoke(g_serverProxy, SERVER_SHIFT_LNN_GEAR, &request, &reply,
845         ClientBusCenterResultCb);
846     if (ans != SOFTBUS_OK || reply.retCode != SOFTBUS_OK) {
847         LNN_LOGE(LNN_EVENT, "invoke failed. ans=%{public}d, retCode=%{public}d", ans, reply.retCode);
848         return ans != SOFTBUS_OK ? SOFTBUS_NETWORK_PROXY_INVOKE_FAILED : reply.retCode;
849     }
850     return SOFTBUS_OK;
851 }
852 
ServerIpcSyncTrustedRelationShip(const char * pkgName,const char * msg,uint32_t msgLen)853 int32_t ServerIpcSyncTrustedRelationShip(const char *pkgName, const char *msg, uint32_t msgLen)
854 {
855     (void)pkgName;
856     (void)msg;
857     (void)msgLen;
858     return SOFTBUS_FUNC_NOT_SUPPORT;
859 }
860 
ServerIpcSetDisplayName(const char * pkgName,const char * nameData,uint32_t len)861 int32_t ServerIpcSetDisplayName(const char *pkgName, const char *nameData, uint32_t len)
862 {
863     (void)pkgName;
864     (void)nameData;
865     (void)len;
866     return SOFTBUS_FUNC_NOT_SUPPORT;
867 }