• 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_stub.h"
17 
18 #include <stdint.h>
19 
20 #include "ipc_skeleton.h"
21 #include "lnn_bus_center_ipc.h"
22 #include "securec.h"
23 #include "softbus_adapter_mem.h"
24 #include "softbus_bus_center.h"
25 #include "softbus_def.h"
26 #include "softbus_errcode.h"
27 #include "softbus_log.h"
28 #include "softbus_permission.h"
29 
CheckPermission(const char * pkgName,int32_t uid)30 static int32_t CheckPermission(const char *pkgName, int32_t uid)
31 {
32     if (pkgName == NULL) {
33         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "pkgName is null");
34         return SOFTBUS_ERR;
35     }
36     if (!CheckBusCenterPermission(uid, pkgName)) {
37         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "no permission.");
38         return SOFTBUS_PERMISSION_DENIED;
39     }
40     return SOFTBUS_OK;
41 }
42 
ServerJoinLNN(IpcIo * req,IpcIo * reply)43 int32_t ServerJoinLNN(IpcIo *req, IpcIo *reply)
44 {
45     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerJoinLNN ipc server pop.");
46     if (req == NULL || reply == NULL) {
47         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
48         return SOFTBUS_INVALID_PARAM;
49     }
50     size_t len;
51     const char *pkgName = (const char*)ReadString(req, &len);
52     uint32_t addrTypeLen;
53     ReadUint32(req, &addrTypeLen);
54     if (addrTypeLen != sizeof(ConnectionAddr)) {
55         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerJoinLNN read addrTypeLen:%d failed!", addrTypeLen);
56         return SOFTBUS_ERR;
57     }
58     void *addr = (void *)ReadBuffer(req, addrTypeLen);
59     if (addr == NULL) {
60         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerJoinLNN read addr is null.");
61         return SOFTBUS_ERR;
62     }
63     int32_t callingUid = GetCallingUid();
64     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
65         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerJoinLNN no permission.");
66         return SOFTBUS_PERMISSION_DENIED;
67     }
68     int32_t ret = LnnIpcServerJoin(pkgName, addr, addrTypeLen);
69     if (ret != SOFTBUS_OK) {
70         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerJoinLNN failed.");
71         return SOFTBUS_ERR;
72     }
73     return SOFTBUS_OK;
74 }
75 
ServerJoinMetaNode(IpcIo * req,IpcIo * reply)76 int32_t ServerJoinMetaNode(IpcIo *req, IpcIo *reply)
77 {
78     (void)req;
79     (void)reply;
80     return SOFTBUS_OK;
81 }
82 
ServerLeaveLNN(IpcIo * req,IpcIo * reply)83 int32_t ServerLeaveLNN(IpcIo *req, IpcIo *reply)
84 {
85     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerLeaveLNN ipc server pop.");
86     size_t len;
87     const char *pkgName = (const char*)ReadString(req, &len);
88     const char *networkId = (const char*)ReadString(req, &len);
89     if (networkId == NULL) {
90         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerLeaveLNN read networkId failed!");
91         return SOFTBUS_ERR;
92     }
93     int32_t callingUid = GetCallingUid();
94     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
95         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerLeaveLNN no permission.");
96         return SOFTBUS_PERMISSION_DENIED;
97     }
98     int32_t ret = LnnIpcServerLeave(pkgName, networkId);
99     if (ret != SOFTBUS_OK) {
100         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerLeaveLNN failed.");
101         return SOFTBUS_ERR;
102     }
103     return SOFTBUS_OK;
104 }
105 
ServerLeaveMetaNode(IpcIo * req,IpcIo * reply)106 int32_t ServerLeaveMetaNode(IpcIo *req, IpcIo *reply)
107 {
108     (void)req;
109     (void)reply;
110     return SOFTBUS_OK;
111 }
112 
ServerGetAllOnlineNodeInfo(IpcIo * req,IpcIo * reply)113 int32_t ServerGetAllOnlineNodeInfo(IpcIo *req, IpcIo *reply)
114 {
115     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerGetAllOnlineNodeInfo ipc server pop.");
116     void *nodeInfo = NULL;
117     int32_t infoNum = 0;
118     size_t len;
119     const char *pkgName = (const char*)ReadString(req, &len);
120     uint32_t infoTypeLen;
121     ReadUint32(req, &infoTypeLen);
122     int32_t callingUid = GetCallingUid();
123     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
124         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetAllOnlineNodeInfo no permission.");
125         WriteInt32(reply, SOFTBUS_PERMISSION_DENIED);
126         return SOFTBUS_PERMISSION_DENIED;
127     }
128     int32_t ret = LnnIpcGetAllOnlineNodeInfo(pkgName, &nodeInfo, infoTypeLen, &infoNum);
129     if (ret != SOFTBUS_OK) {
130         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetAllOnlineNodeInfo get info failed.");
131         WriteInt32(reply, SOFTBUS_ERR);
132         return SOFTBUS_ERR;
133     }
134     if (infoNum < 0 || (infoNum > 0 && nodeInfo == NULL)) {
135         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetAllOnlineNodeInfo node info is invalid");
136         WriteInt32(reply, SOFTBUS_ERR);
137         return SOFTBUS_ERR;
138     }
139     WriteInt32(reply, infoNum);
140     if (infoNum > 0) {
141         WriteUint32(reply, infoTypeLen * infoNum);
142         WriteBuffer(reply, nodeInfo, infoTypeLen * infoNum);
143         SoftBusFree(nodeInfo);
144     }
145     return SOFTBUS_OK;
146 }
147 
ServerGetLocalDeviceInfo(IpcIo * req,IpcIo * reply)148 int32_t ServerGetLocalDeviceInfo(IpcIo *req, IpcIo *reply)
149 {
150     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerGetLocalDeviceInfo ipc server pop.");
151     void *nodeInfo = NULL;
152     size_t len;
153     const char *pkgName = (const char*)ReadString(req, &len);
154     int32_t callingUid = GetCallingUid();
155     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
156         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetLocalDeviceInfo no permission.");
157         return SOFTBUS_PERMISSION_DENIED;
158     }
159     uint32_t infoTypeLen = sizeof(NodeBasicInfo);
160     nodeInfo = SoftBusCalloc(infoTypeLen);
161     if (nodeInfo == NULL) {
162         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetLocalDeviceInfo malloc info type length failed");
163         return SOFTBUS_ERR;
164     }
165     int32_t ret = LnnIpcGetLocalDeviceInfo(pkgName, nodeInfo, infoTypeLen);
166     if (ret != SOFTBUS_OK) {
167         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetLocalDeviceInfo get local info failed.");
168         SoftBusFree(nodeInfo);
169         return SOFTBUS_ERR;
170     }
171     WriteUint32(reply, infoTypeLen);
172     WriteBuffer(reply, nodeInfo, infoTypeLen);
173     SoftBusFree(nodeInfo);
174     return SOFTBUS_OK;
175 }
176 
ServerGetNodeKeyInfo(IpcIo * req,IpcIo * reply)177 int32_t ServerGetNodeKeyInfo(IpcIo *req, IpcIo *reply)
178 {
179     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerGetNodeKeyInfo ipc server pop.");
180     size_t length;
181     const char *pkgName = (const char*)ReadString(req, &length);
182     const char *networkId = (const char*)ReadString(req, &length);
183     if (networkId == NULL) {
184         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "GetNodeKeyInfoInner read networkId failed!");
185         return SOFTBUS_ERR;
186     }
187     int32_t key;
188     ReadInt32(req, &key);
189     int32_t infoLen  = LnnIpcGetNodeKeyInfoLen(key);
190     if (infoLen == SOFTBUS_ERR) {
191         return SOFTBUS_ERR;
192     }
193     int32_t len;
194     ReadInt32(req, &len);
195     if (len < infoLen) {
196         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "GetNodeKeyInfoInner read len is invalid param!");
197         return SOFTBUS_ERR;
198     }
199     void *buf = SoftBusCalloc(infoLen);
200     if (buf == NULL) {
201         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetNodeKeyInfo malloc buffer failed!");
202         return SOFTBUS_ERR;
203     }
204     int32_t callingUid = GetCallingUid();
205     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
206         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetNodeKeyInfo no permission.");
207         SoftBusFree(buf);
208         return SOFTBUS_PERMISSION_DENIED;
209     }
210     int32_t ret = LnnIpcGetNodeKeyInfo(pkgName, networkId, key, (unsigned char *)buf, infoLen);
211     if (ret != SOFTBUS_OK) {
212         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetNodeKeyInfo get local info failed.");
213         SoftBusFree(buf);
214         return SOFTBUS_ERR;
215     }
216     WriteInt32(reply, infoLen);
217     WriteBuffer(reply, buf, infoLen);
218     SoftBusFree(buf);
219     return SOFTBUS_OK;
220 }
221 
ServerSetNodeDataChangeFlag(IpcIo * req,IpcIo * reply)222 int32_t ServerSetNodeDataChangeFlag(IpcIo *req, IpcIo *reply)
223 {
224     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerSetNodeDataChangeFlag ipc server pop.");
225     size_t length;
226     const char *pkgName = (const char*)ReadString(req, &length);
227     const char *networkId = (const char*)ReadString(req, &length);
228     if (networkId == NULL) {
229         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "SetNodeDataChangeFlag read networkId failed!");
230         return SOFTBUS_ERR;
231     }
232     int16_t dataChangeFlag;
233     ReadInt16(req, &dataChangeFlag);
234     int32_t callingUid = GetCallingUid();
235     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
236         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerSetNodeDataChangeFlag no permission.");
237         return SOFTBUS_PERMISSION_DENIED;
238     }
239     int32_t ret = LnnIpcSetNodeDataChangeFlag(pkgName, networkId, dataChangeFlag);
240     if (ret != SOFTBUS_OK) {
241         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerSetNodeDataChangeFlag get local info failed.");
242         return SOFTBUS_ERR;
243     }
244     return SOFTBUS_OK;
245 }
246 
ServerStartTimeSync(IpcIo * req,IpcIo * reply)247 int32_t ServerStartTimeSync(IpcIo *req, IpcIo *reply)
248 {
249     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStartTimeSync ipc server pop.");
250     size_t length;
251     const char *pkgName = (const char*)ReadString(req, &length);
252     const char *targetNetworkId = (const char*)ReadString(req, &length);
253     if (targetNetworkId == NULL) {
254         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStartTimeSync read targetNetworkId failed!");
255         return SOFTBUS_ERR;
256     }
257     int32_t accuracy;
258     int32_t period;
259     ReadInt32(req, &accuracy);
260     ReadInt32(req, &period);
261     int32_t callingUid = GetCallingUid();
262     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
263         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStartTimeSync no permission.");
264         return SOFTBUS_PERMISSION_DENIED;
265     }
266     int32_t ret = LnnIpcStartTimeSync(pkgName, targetNetworkId, accuracy, period);
267     if (ret != SOFTBUS_OK) {
268         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStartTimeSync start time sync failed.");
269         return SOFTBUS_ERR;
270     }
271     return SOFTBUS_OK;
272 }
273 
ServerStopTimeSync(IpcIo * req,IpcIo * reply)274 int32_t ServerStopTimeSync(IpcIo *req, IpcIo *reply)
275 {
276     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStopTimeSync ipc server pop.");
277     size_t length;
278     const char *pkgName = (const char*)ReadString(req, &length);
279     const char *targetNetworkId = (const char*)ReadString(req, &length);
280     if (targetNetworkId == NULL) {
281         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopTimeSync read targetNetworkId failed!");
282         return SOFTBUS_ERR;
283     }
284     int32_t callingUid = GetCallingUid();
285     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
286         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopTimeSync no permission.");
287         return SOFTBUS_PERMISSION_DENIED;
288     }
289     int32_t ret = LnnIpcStopTimeSync(pkgName, targetNetworkId);
290     if (ret != SOFTBUS_OK) {
291         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopTimeSync start time sync failed.");
292         return SOFTBUS_ERR;
293     }
294     return SOFTBUS_OK;
295 }
296 
ServerPublishLNN(IpcIo * req,IpcIo * reply)297 int32_t ServerPublishLNN(IpcIo *req, IpcIo *reply)
298 {
299     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerPublishLNN ipc server pop.");
300     if (req == NULL || reply == NULL) {
301         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
302         return SOFTBUS_INVALID_PARAM;
303     }
304     size_t len;
305     const char *pkgName = (const char*)ReadString(req, &len);
306     uint32_t infoLen;
307     ReadUint32(req, &infoLen);
308     void *info = (void*)ReadBuffer(req, infoLen);
309     if (info == NULL) {
310         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerPublishLNN read info is null.");
311         return SOFTBUS_ERR;
312     }
313     int32_t callingUid = GetCallingUid();
314     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
315         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerPublishLNN no permission.");
316         return SOFTBUS_PERMISSION_DENIED;
317     }
318     int32_t ret = LnnIpcPublishLNN(pkgName, info, infoLen);
319     WriteInt32(reply, ret);
320     if (ret != SOFTBUS_OK) {
321         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerPublishLNN failed.");
322         return SOFTBUS_ERR;
323     }
324     return SOFTBUS_OK;
325 }
326 
ServerStopPublishLNN(IpcIo * req,IpcIo * reply)327 int32_t ServerStopPublishLNN(IpcIo *req, IpcIo *reply)
328 {
329     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStopPublishLNN ipc server pop.");
330     if (req == NULL || reply == NULL) {
331         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
332         return SOFTBUS_INVALID_PARAM;
333     }
334     size_t len;
335     const char *pkgName = (const char*)ReadString(req, &len);
336     int32_t publishId;
337     ReadInt32(req, &publishId);
338     int32_t callingUid = GetCallingUid();
339     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
340         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopPublishLNN no permission.");
341         return SOFTBUS_PERMISSION_DENIED;
342     }
343     int32_t ret = LnnIpcStopPublishLNN(pkgName, publishId);
344     if (ret != SOFTBUS_OK) {
345         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopPublishLNN failed.");
346         return SOFTBUS_ERR;
347     }
348     return SOFTBUS_OK;
349 }
350 
ServerRefreshLNN(IpcIo * req,IpcIo * reply)351 int32_t ServerRefreshLNN(IpcIo *req, IpcIo *reply)
352 {
353     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerRefreshLNN ipc server pop.");
354     if (req == NULL || reply == NULL) {
355         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
356         return SOFTBUS_INVALID_PARAM;
357     }
358     size_t len;
359     const char *pkgName = (const char*)ReadString(req, &len);
360     uint32_t infoTypeLen;
361     ReadUint32(req, &infoTypeLen);
362     void *info = (void*)ReadBuffer(req, infoTypeLen);
363     if (info == NULL) {
364         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerRefreshLNN read info is null.");
365         return SOFTBUS_ERR;
366     }
367     int32_t callingUid = GetCallingUid();
368     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
369         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerRefreshLNN no permission.");
370         return SOFTBUS_PERMISSION_DENIED;
371     }
372     int32_t ret = LnnIpcRefreshLNN(pkgName, info, infoTypeLen);
373     if (ret != SOFTBUS_OK) {
374         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerRefreshLNN failed.");
375         return SOFTBUS_ERR;
376     }
377     return SOFTBUS_OK;
378 }
379 
ServerStopRefreshLNN(IpcIo * req,IpcIo * reply)380 int32_t ServerStopRefreshLNN(IpcIo *req, IpcIo *reply)
381 {
382     SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStopRefreshLNN ipc server pop.");
383     if (req == NULL || reply == NULL) {
384         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
385         return SOFTBUS_INVALID_PARAM;
386     }
387     size_t len;
388     const char *pkgName = (const char*)ReadString(req, &len);
389     int32_t refreshId;
390     ReadInt32(req, &refreshId);
391     int32_t callingUid = GetCallingUid();
392     if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
393         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopRefreshLNN no permission.");
394         return SOFTBUS_PERMISSION_DENIED;
395     }
396     int32_t ret = LnnIpcStopRefreshLNN(pkgName, refreshId);
397     WriteInt32(reply, ret);
398     if (ret != SOFTBUS_OK) {
399         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopRefreshLNN failed.");
400         return SOFTBUS_ERR;
401     }
402     return SOFTBUS_OK;
403 }
404 
ServerActiveMetaNode(IpcIo * req,IpcIo * reply)405 int32_t ServerActiveMetaNode(IpcIo *req, IpcIo *reply)
406 {
407     uint32_t size;
408     const char *pkgName = (const char*)ReadString(req, &size);
409     MetaNodeConfigInfo *info = (MetaNodeConfigInfo *)ReadRawData(req, sizeof(MetaNodeConfigInfo));
410     if (info == NULL || size != sizeof(MetaNodeConfigInfo)) {
411         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerActiveMetaNode read meta node config info failed!");
412         WriteInt32(reply, SOFTBUS_INVALID_PARAM);
413         return SOFTBUS_ERR;
414     }
415     int32_t ret = CheckPermission(pkgName, GetCallingUid());
416     if (ret != SOFTBUS_OK) {
417         WriteInt32(reply, ret);
418         return SOFTBUS_ERR;
419     }
420     char metaNodeId[NETWORK_ID_BUF_LEN] = {0};
421     ret = LnnIpcActiveMetaNode(info, metaNodeId);
422     if (ret != SOFTBUS_OK) {
423         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerActiveMetaNode failed!");
424         WriteInt32(reply, ret);
425         return SOFTBUS_ERR;
426     }
427     WriteInt32(reply, SOFTBUS_OK);
428     WriteString(reply, metaNodeId);
429     return SOFTBUS_OK;
430 }
431 
ServerDeactiveMetaNode(IpcIo * req,IpcIo * reply)432 int32_t ServerDeactiveMetaNode(IpcIo *req, IpcIo *reply)
433 {
434     uint32_t size;
435     const char *pkgName = (const char*)ReadString(req, &size);
436     const char *metaNodeId = (const char*)ReadString(req, &size);
437     if (metaNodeId == NULL || size != (NETWORK_ID_BUF_LEN - 1)) {
438         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
439             "ServerDeactiveMetaNode read meta node id failed, size=%d", size);
440         WriteInt32(reply, SOFTBUS_INVALID_PARAM);
441         return SOFTBUS_ERR;
442     }
443     int32_t ret = CheckPermission(pkgName, GetCallingUid());
444     if (ret != SOFTBUS_OK) {
445         WriteInt32(reply, ret);
446         return SOFTBUS_ERR;
447     }
448     ret = LnnIpcDeactiveMetaNode(metaNodeId);
449     if (ret != SOFTBUS_OK) {
450         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerDeactiveMetaNode failed!");
451         WriteInt32(reply, ret);
452         return SOFTBUS_ERR;
453     }
454     WriteInt32(reply, SOFTBUS_OK);
455     return SOFTBUS_OK;
456 }
457 
ServerGetAllMetaNodeInfo(IpcIo * req,IpcIo * reply)458 int32_t ServerGetAllMetaNodeInfo(IpcIo *req, IpcIo *reply)
459 {
460     uint32_t size;
461     const char *pkgName = (const char*)ReadString(req, &size);
462     int32_t infoNum;
463     ReadInt32(req, &infoNum);
464     MetaNodeInfo infos[MAX_META_NODE_NUM];
465     int32_t ret = CheckPermission(pkgName, GetCallingUid());
466     if (ret != SOFTBUS_OK) {
467         WriteInt32(reply, ret);
468         return SOFTBUS_ERR;
469     }
470     ret = LnnIpcGetAllMetaNodeInfo(infos, &infoNum);
471     if (ret != SOFTBUS_OK) {
472         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetAllMetaNodeInfo failed!");
473         WriteInt32(reply, ret);
474         return SOFTBUS_ERR;
475     }
476     WriteInt32(reply, SOFTBUS_OK);
477     WriteInt32(reply, infoNum);
478     if (infoNum > 0) {
479         WriteUint32(reply, infoNum * sizeof(MetaNodeInfo));
480         WriteBuffer(reply, infos, infoNum * sizeof(MetaNodeInfo));
481     }
482     return SOFTBUS_OK;
483 }
484 
ServerShiftLnnGear(IpcIo * req,IpcIo * reply)485 int32_t ServerShiftLnnGear(IpcIo *req, IpcIo *reply)
486 {
487     size_t len;
488     bool targetNetworkIdIsNULL = false;
489     const char *targetNetworkId = NULL;
490 
491     const char *pkgName = (const char*)ReadString(req, &len);
492     if (pkgName == NULL || len >= PKG_NAME_SIZE_MAX) {
493         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read pkgName failed!");
494         WriteInt32(reply, SOFTBUS_INVALID_PARAM);
495         return SOFTBUS_ERR;
496     }
497     const char *callerId = (const char*)ReadString(req, &len);
498     if (callerId == NULL || len == 0 || len >= CALLER_ID_MAX_LEN) {
499         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read callerId failed!");
500         WriteInt32(reply, SOFTBUS_INVALID_PARAM);
501         return SOFTBUS_ERR;
502     }
503     if (!ReadBool(req, &targetNetworkIdIsNULL)) {
504         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read targetNetworkIdIsNULL failed!");
505         WriteInt32(reply, SOFTBUS_INVALID_PARAM);
506         return SOFTBUS_ERR;
507     }
508     if (!targetNetworkIdIsNULL) {
509         targetNetworkId = (const char*)ReadString(req, &len);
510         if (targetNetworkId == NULL || len != NETWORK_ID_BUF_LEN - 1) {
511             SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read targetNetworkId failed!");
512             WriteInt32(reply, SOFTBUS_INVALID_PARAM);
513             return SOFTBUS_ERR;
514         }
515     }
516     const GearMode *mode = (GearMode *)ReadRawData(req, sizeof(GearMode));
517     if (mode == NULL) {
518         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read gear mode info failed!");
519         WriteInt32(reply, SOFTBUS_INVALID_PARAM);
520         return SOFTBUS_ERR;
521     }
522     int32_t ret = CheckPermission(pkgName, GetCallingUid());
523     if (ret != SOFTBUS_OK) {
524         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear no permission.");
525         WriteInt32(reply, ret);
526         return SOFTBUS_PERMISSION_DENIED;
527     }
528     ret = LnnIpcShiftLNNGear(pkgName, callerId, targetNetworkId, mode);
529     if (ret != SOFTBUS_OK) {
530         SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear failed!");
531         WriteInt32(reply, ret);
532         return SOFTBUS_ERR;
533     }
534     WriteInt32(reply, SOFTBUS_OK);
535     return SOFTBUS_OK;
536 }
537