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