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, 0, 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, 0, 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_MEM_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 int32_t callingUid = GetCallingUid();
183 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
184 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetNodeKeyInfo no permission.");
185 return SOFTBUS_PERMISSION_DENIED;
186 }
187 const char *networkId = (const char*)ReadString(req, &length);
188 if (networkId == NULL) {
189 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "GetNodeKeyInfoInner read networkId failed!");
190 return SOFTBUS_ERR;
191 }
192 int32_t key;
193 ReadInt32(req, &key);
194 int32_t infoLen = LnnIpcGetNodeKeyInfoLen(key);
195 if (infoLen == SOFTBUS_ERR) {
196 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "GetNodeKeyInfoInner get infoLen failed!");
197 return SOFTBUS_ERR;
198 }
199 int32_t len;
200 ReadInt32(req, &len);
201 if (len < infoLen) {
202 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
203 "GetNodeKeyInfoInner read len is invalid param, len:%d, infoLen:%d", len, infoLen);
204 return SOFTBUS_ERR;
205 }
206 void *buf = SoftBusCalloc(infoLen);
207 if (buf == NULL) {
208 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetNodeKeyInfo malloc buffer failed!");
209 return SOFTBUS_MEM_ERR;
210 }
211 int32_t ret = LnnIpcGetNodeKeyInfo(pkgName, networkId, key, (unsigned char *)buf, infoLen);
212 if (ret != SOFTBUS_OK) {
213 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetNodeKeyInfo get local info failed.");
214 SoftBusFree(buf);
215 return SOFTBUS_ERR;
216 }
217 WriteInt32(reply, infoLen);
218 WriteBuffer(reply, buf, infoLen);
219 SoftBusFree(buf);
220 return SOFTBUS_OK;
221 }
222
ServerSetNodeDataChangeFlag(IpcIo * req,IpcIo * reply)223 int32_t ServerSetNodeDataChangeFlag(IpcIo *req, IpcIo *reply)
224 {
225 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerSetNodeDataChangeFlag ipc server pop.");
226 size_t length;
227 const char *pkgName = (const char*)ReadString(req, &length);
228 const char *networkId = (const char*)ReadString(req, &length);
229 if (networkId == NULL) {
230 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "SetNodeDataChangeFlag read networkId failed!");
231 return SOFTBUS_ERR;
232 }
233 int16_t dataChangeFlag;
234 ReadInt16(req, &dataChangeFlag);
235 int32_t callingUid = GetCallingUid();
236 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
237 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerSetNodeDataChangeFlag no permission.");
238 return SOFTBUS_PERMISSION_DENIED;
239 }
240 int32_t ret = LnnIpcSetNodeDataChangeFlag(pkgName, networkId, dataChangeFlag);
241 if (ret != SOFTBUS_OK) {
242 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerSetNodeDataChangeFlag get local info failed.");
243 return SOFTBUS_ERR;
244 }
245 return SOFTBUS_OK;
246 }
247
ServerStartTimeSync(IpcIo * req,IpcIo * reply)248 int32_t ServerStartTimeSync(IpcIo *req, IpcIo *reply)
249 {
250 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStartTimeSync ipc server pop.");
251 size_t length;
252 const char *pkgName = (const char*)ReadString(req, &length);
253 const char *targetNetworkId = (const char*)ReadString(req, &length);
254 if (targetNetworkId == NULL) {
255 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStartTimeSync read targetNetworkId failed!");
256 return SOFTBUS_ERR;
257 }
258 int32_t accuracy;
259 int32_t period;
260 ReadInt32(req, &accuracy);
261 ReadInt32(req, &period);
262 int32_t callingUid = GetCallingUid();
263 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
264 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStartTimeSync no permission.");
265 return SOFTBUS_PERMISSION_DENIED;
266 }
267 int32_t ret = LnnIpcStartTimeSync(pkgName, 0, targetNetworkId, accuracy, period);
268 if (ret != SOFTBUS_OK) {
269 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStartTimeSync start time sync failed.");
270 return SOFTBUS_ERR;
271 }
272 return SOFTBUS_OK;
273 }
274
ServerStopTimeSync(IpcIo * req,IpcIo * reply)275 int32_t ServerStopTimeSync(IpcIo *req, IpcIo *reply)
276 {
277 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStopTimeSync ipc server pop.");
278 size_t length;
279 const char *pkgName = (const char*)ReadString(req, &length);
280 const char *targetNetworkId = (const char*)ReadString(req, &length);
281 if (targetNetworkId == NULL) {
282 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopTimeSync read targetNetworkId failed!");
283 return SOFTBUS_ERR;
284 }
285 int32_t callingUid = GetCallingUid();
286 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
287 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopTimeSync no permission.");
288 return SOFTBUS_PERMISSION_DENIED;
289 }
290 int32_t ret = LnnIpcStopTimeSync(pkgName, targetNetworkId, 0);
291 if (ret != SOFTBUS_OK) {
292 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopTimeSync start time sync failed.");
293 return SOFTBUS_ERR;
294 }
295 return SOFTBUS_OK;
296 }
297
ServerPublishLNN(IpcIo * req,IpcIo * reply)298 int32_t ServerPublishLNN(IpcIo *req, IpcIo *reply)
299 {
300 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerPublishLNN ipc server pop.");
301 if (req == NULL || reply == NULL) {
302 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
303 return SOFTBUS_INVALID_PARAM;
304 }
305 size_t len;
306 const char *pkgName = (const char*)ReadString(req, &len);
307 int32_t callingUid = GetCallingUid();
308 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
309 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerPublishLNN no permission.");
310 return SOFTBUS_PERMISSION_DENIED;
311 }
312
313 PublishInfo info;
314 (void)memset_s(&info, sizeof(PublishInfo), 0, sizeof(PublishInfo));
315 ReadInt32(req, &info.publishId);
316 int32_t mode, medium, freq;
317 ReadInt32(req, &mode);
318 ReadInt32(req, &medium);
319 ReadInt32(req, &freq);
320 info.mode = (DiscoverMode)mode;
321 info.medium = (ExchangeMedium)medium;
322 info.freq = (ExchangeFreq)freq;
323 info.capability = (const char *)ReadString(req, &len);
324 if (info.capability == NULL) {
325 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerPublishLNN read capability is null.");
326 return SOFTBUS_IPC_ERR;
327 }
328 ReadUint32(req, &info.dataLen);
329 if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
330 info.capabilityData = (unsigned char *)ReadString(req, &len);
331 if (info.capabilityData == NULL) {
332 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerPublishLNN read capabilityData is null.");
333 return SOFTBUS_IPC_ERR;
334 }
335 } else {
336 info.capabilityData = NULL;
337 info.dataLen = 0;
338 }
339 ReadBool(req, &info.ranging);
340 int32_t ret = LnnIpcPublishLNN(pkgName, &info);
341 WriteInt32(reply, ret);
342 if (ret != SOFTBUS_OK) {
343 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerPublishLNN failed.");
344 return SOFTBUS_ERR;
345 }
346 return SOFTBUS_OK;
347 }
348
ServerStopPublishLNN(IpcIo * req,IpcIo * reply)349 int32_t ServerStopPublishLNN(IpcIo *req, IpcIo *reply)
350 {
351 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStopPublishLNN ipc server pop.");
352 if (req == NULL || reply == NULL) {
353 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
354 return SOFTBUS_INVALID_PARAM;
355 }
356 size_t len;
357 const char *pkgName = (const char*)ReadString(req, &len);
358 int32_t publishId;
359 ReadInt32(req, &publishId);
360 int32_t callingUid = GetCallingUid();
361 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
362 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopPublishLNN no permission.");
363 return SOFTBUS_PERMISSION_DENIED;
364 }
365 int32_t ret = LnnIpcStopPublishLNN(pkgName, publishId);
366 if (ret != SOFTBUS_OK) {
367 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopPublishLNN failed.");
368 return SOFTBUS_ERR;
369 }
370 return SOFTBUS_OK;
371 }
372
ServerRefreshLNN(IpcIo * req,IpcIo * reply)373 int32_t ServerRefreshLNN(IpcIo *req, IpcIo *reply)
374 {
375 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerRefreshLNN ipc server pop.");
376 if (req == NULL || reply == NULL) {
377 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
378 return SOFTBUS_INVALID_PARAM;
379 }
380 size_t len;
381 const char *pkgName = (const char*)ReadString(req, &len);
382 int32_t callingUid = GetCallingUid();
383 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
384 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerRefreshLNN no permission.");
385 return SOFTBUS_PERMISSION_DENIED;
386 }
387
388 SubscribeInfo info;
389 (void)memset_s(&info, sizeof(SubscribeInfo), 0, sizeof(SubscribeInfo));
390 ReadInt32(req, &info.subscribeId);
391 int32_t mode, medium, freq;
392 ReadInt32(req, &mode);
393 ReadInt32(req, &medium);
394 ReadInt32(req, &freq);
395 info.mode = (DiscoverMode)mode;
396 info.medium = (ExchangeMedium)medium;
397 info.freq = (ExchangeFreq)freq;
398 ReadBool(req, &info.isSameAccount);
399 ReadBool(req, &info.isWakeRemote);
400 info.capability = (const char *)ReadString(req, &len);
401 if (info.capability == NULL) {
402 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerRefreshLNN read capability is null.");
403 return SOFTBUS_IPC_ERR;
404 }
405 ReadUint32(req, &info.dataLen);
406 if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
407 info.capabilityData = (unsigned char *)ReadString(req, &len);
408 if (info.capabilityData == NULL) {
409 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerRefreshLNN read capabilityData is null.");
410 return SOFTBUS_IPC_ERR;
411 }
412 } else {
413 info.capabilityData = NULL;
414 info.dataLen = 0;
415 }
416 int32_t ret = LnnIpcRefreshLNN(pkgName, 0, &info);
417 WriteInt32(reply, ret);
418 if (ret != SOFTBUS_OK) {
419 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerRefreshLNN failed.");
420 return SOFTBUS_ERR;
421 }
422 return SOFTBUS_OK;
423 }
424
ServerStopRefreshLNN(IpcIo * req,IpcIo * reply)425 int32_t ServerStopRefreshLNN(IpcIo *req, IpcIo *reply)
426 {
427 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "ServerStopRefreshLNN ipc server pop.");
428 if (req == NULL || reply == NULL) {
429 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "%s:invalid param.", __func__);
430 return SOFTBUS_INVALID_PARAM;
431 }
432 size_t len;
433 const char *pkgName = (const char*)ReadString(req, &len);
434 int32_t refreshId;
435 ReadInt32(req, &refreshId);
436 int32_t callingUid = GetCallingUid();
437 if (CheckPermission(pkgName, callingUid) != SOFTBUS_OK) {
438 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopRefreshLNN no permission.");
439 return SOFTBUS_PERMISSION_DENIED;
440 }
441 int32_t ret = LnnIpcStopRefreshLNN(pkgName, 0, refreshId);
442 if (ret != SOFTBUS_OK) {
443 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerStopRefreshLNN failed.");
444 return SOFTBUS_ERR;
445 }
446 return SOFTBUS_OK;
447 }
448
ServerActiveMetaNode(IpcIo * req,IpcIo * reply)449 int32_t ServerActiveMetaNode(IpcIo *req, IpcIo *reply)
450 {
451 uint32_t size;
452 const char *pkgName = (const char*)ReadString(req, &size);
453 MetaNodeConfigInfo *info = (MetaNodeConfigInfo *)ReadRawData(req, sizeof(MetaNodeConfigInfo));
454 if (info == NULL || size != sizeof(MetaNodeConfigInfo)) {
455 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerActiveMetaNode read meta node config info failed!");
456 WriteInt32(reply, SOFTBUS_INVALID_PARAM);
457 return SOFTBUS_ERR;
458 }
459 int32_t ret = CheckPermission(pkgName, GetCallingUid());
460 if (ret != SOFTBUS_OK) {
461 WriteInt32(reply, ret);
462 return SOFTBUS_ERR;
463 }
464 char metaNodeId[NETWORK_ID_BUF_LEN] = {0};
465 ret = LnnIpcActiveMetaNode(info, metaNodeId);
466 if (ret != SOFTBUS_OK) {
467 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerActiveMetaNode failed!");
468 WriteInt32(reply, ret);
469 return SOFTBUS_ERR;
470 }
471 WriteInt32(reply, SOFTBUS_OK);
472 WriteString(reply, metaNodeId);
473 return SOFTBUS_OK;
474 }
475
ServerDeactiveMetaNode(IpcIo * req,IpcIo * reply)476 int32_t ServerDeactiveMetaNode(IpcIo *req, IpcIo *reply)
477 {
478 uint32_t size;
479 const char *pkgName = (const char*)ReadString(req, &size);
480 const char *metaNodeId = (const char*)ReadString(req, &size);
481 if (metaNodeId == NULL || size != (NETWORK_ID_BUF_LEN - 1)) {
482 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
483 "ServerDeactiveMetaNode read meta node id failed, size=%d", size);
484 WriteInt32(reply, SOFTBUS_INVALID_PARAM);
485 return SOFTBUS_ERR;
486 }
487 int32_t ret = CheckPermission(pkgName, GetCallingUid());
488 if (ret != SOFTBUS_OK) {
489 WriteInt32(reply, ret);
490 return SOFTBUS_ERR;
491 }
492 ret = LnnIpcDeactiveMetaNode(metaNodeId);
493 if (ret != SOFTBUS_OK) {
494 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerDeactiveMetaNode failed!");
495 WriteInt32(reply, ret);
496 return SOFTBUS_ERR;
497 }
498 WriteInt32(reply, SOFTBUS_OK);
499 return SOFTBUS_OK;
500 }
501
ServerGetAllMetaNodeInfo(IpcIo * req,IpcIo * reply)502 int32_t ServerGetAllMetaNodeInfo(IpcIo *req, IpcIo *reply)
503 {
504 uint32_t size;
505 const char *pkgName = (const char*)ReadString(req, &size);
506 int32_t infoNum;
507 ReadInt32(req, &infoNum);
508 MetaNodeInfo infos[MAX_META_NODE_NUM];
509 int32_t ret = CheckPermission(pkgName, GetCallingUid());
510 if (ret != SOFTBUS_OK) {
511 WriteInt32(reply, ret);
512 return SOFTBUS_ERR;
513 }
514 ret = LnnIpcGetAllMetaNodeInfo(infos, &infoNum);
515 if (ret != SOFTBUS_OK) {
516 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerGetAllMetaNodeInfo failed!");
517 WriteInt32(reply, ret);
518 return SOFTBUS_ERR;
519 }
520 WriteInt32(reply, SOFTBUS_OK);
521 WriteInt32(reply, infoNum);
522 if (infoNum > 0) {
523 WriteUint32(reply, infoNum * sizeof(MetaNodeInfo));
524 WriteBuffer(reply, infos, infoNum * sizeof(MetaNodeInfo));
525 }
526 return SOFTBUS_OK;
527 }
528
ServerShiftLnnGear(IpcIo * req,IpcIo * reply)529 int32_t ServerShiftLnnGear(IpcIo *req, IpcIo *reply)
530 {
531 size_t len;
532 bool targetNetworkIdIsNULL = false;
533 const char *targetNetworkId = NULL;
534
535 const char *pkgName = (const char*)ReadString(req, &len);
536 if (pkgName == NULL || len >= PKG_NAME_SIZE_MAX) {
537 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read pkgName failed!");
538 WriteInt32(reply, SOFTBUS_INVALID_PARAM);
539 return SOFTBUS_ERR;
540 }
541 const char *callerId = (const char*)ReadString(req, &len);
542 if (callerId == NULL || len == 0 || len >= CALLER_ID_MAX_LEN) {
543 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read callerId failed!");
544 WriteInt32(reply, SOFTBUS_INVALID_PARAM);
545 return SOFTBUS_ERR;
546 }
547 if (!ReadBool(req, &targetNetworkIdIsNULL)) {
548 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read targetNetworkIdIsNULL failed!");
549 WriteInt32(reply, SOFTBUS_INVALID_PARAM);
550 return SOFTBUS_ERR;
551 }
552 if (!targetNetworkIdIsNULL) {
553 targetNetworkId = (const char*)ReadString(req, &len);
554 if (targetNetworkId == NULL || len != NETWORK_ID_BUF_LEN - 1) {
555 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read targetNetworkId failed!");
556 WriteInt32(reply, SOFTBUS_INVALID_PARAM);
557 return SOFTBUS_ERR;
558 }
559 }
560 const GearMode *mode = (GearMode *)ReadRawData(req, sizeof(GearMode));
561 if (mode == NULL) {
562 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear read gear mode info failed!");
563 WriteInt32(reply, SOFTBUS_INVALID_PARAM);
564 return SOFTBUS_ERR;
565 }
566 int32_t ret = CheckPermission(pkgName, GetCallingUid());
567 if (ret != SOFTBUS_OK) {
568 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear no permission.");
569 WriteInt32(reply, ret);
570 return SOFTBUS_PERMISSION_DENIED;
571 }
572 ret = LnnIpcShiftLNNGear(pkgName, callerId, targetNetworkId, mode);
573 if (ret != SOFTBUS_OK) {
574 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "ServerShiftLnnGear failed!");
575 WriteInt32(reply, ret);
576 return SOFTBUS_ERR;
577 }
578 WriteInt32(reply, SOFTBUS_OK);
579 return SOFTBUS_OK;
580 }
581