• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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 "softbus_server_stub.h"
17 
18 #include "securec.h"
19 
20 #include "accesstoken_kit.h"
21 #include "access_control.h"
22 #include "ipc_skeleton.h"
23 #include "legacy/softbus_hisysevt_transreporter.h"
24 #include "softbus_access_token_adapter.h"
25 #include "softbus_adapter_mem.h"
26 #include "softbus_permission.h"
27 #include "softbus_server_frame.h"
28 #include "softbus_server_ipc_interface_code.h"
29 #include "trans_channel_common.h"
30 #include "trans_channel_manager.h"
31 #include "trans_log.h"
32 #include "trans_network_statistics.h"
33 #include "trans_session_manager.h"
34 
35 #ifdef SUPPORT_BUNDLENAME
36 #include "bundle_mgr_proxy.h"
37 #include "g_enhance_trans_func_pack.h"
38 #include "iservice_registry.h"
39 #include "ohos_account_kits.h"
40 #include "os_account_manager.h"
41 #include "system_ability_definition.h"
42 #endif
43 
44 #define SERVER_JOIN_LNN_NAME "SERVER_JOIN_LNN"
45 #define SERVER_LEAVE_LNN_NAME "SERVER_LEAVE_LNN"
46 #define SERVER_SET_NODE_DATA_CHANGE_FLAG_NAME "SERVER_SET_NODE_DATA_CHANGE_FLAG"
47 #define SERVER_ACTIVE_META_NODE_NAME "SERVER_ACTIVE_META_NODE"
48 #define SERVER_DEACTIVE_META_NODE_NAME "SERVER_DEACTIVE_META_NODE"
49 #define SERVER_GET_ALL_META_NODE_INFO_NAME "SERVER_GET_ALL_META_NODE_INFO"
50 #define SERVER_SHIFT_LNN_GEAR_NAME "SERVER_SHIFT_LNN_GEAR"
51 #define SERVER_SYNC_TRUSTED_RELATION_NAME "SERVER_SYNC_TRUSTED_RELATION"
52 #define SERVER_SET_DISPLAY_NAME_NAME "SERVER_SET_DISPLAY_NAME"
53 #define SERVER_SET_DATA_LEVEL_NAME "SERVER_SET_DATA_LEVEL"
54 #define SERVER_REG_DATA_LEVEL_CHANGE_CB_NAME "SERVER_REG_DATA_LEVEL_CHANGE_CB"
55 #define SERVER_UNREG_DATA_LEVEL_CHANGE_CB_NAME "SERVER_UNREG_DATA_LEVEL_CHANGE_CB"
56 #define SERVER_TRIGGER_RANGE_FOR_MSDP_NAME "SERVER_TRIGGER_RANGE_FOR_MSDP"
57 #define SERVER_STOP_RANGE_FOR_MSDP_NAME "SERVER_STOP_RANGE_FOR_MSDP"
58 #define SERVER_REG_RANGE_CB_FOR_MSDP_NAME "SERVER_REG_RANGE_CB_FOR_MSDP"
59 #define SERVER_UNREG_RANGE_CB_FOR_MSDP_NAME "SERVER_UNREG_RANGE_CB_FOR_MSDP"
60 
61 const char *g_limitPkgName = "ohos.distributedschedule.dms";
62 
63 #define READ_PARCEL_WITH_RET(parcel, type, data, retVal)        \
64     do {                                                        \
65         if (!(parcel).Read##type(data)) {                       \
66             COMM_LOGE(COMM_SVC, "read data failed.");           \
67             return (retVal);                                    \
68         }                                                       \
69     } while (false)                                             \
70 
71 namespace OHOS {
72     namespace {
73         constexpr int32_t MSG_MAX_SIZE = 1024 * 2;
74         constexpr int32_t DMS_CALLING_UID = 5522;
75         static const char *DB_PACKAGE_NAME = "distributeddata-default";
76         static const char *DM_PACKAGE_NAME = "ohos.distributedhardware.devicemanager";
77         static const char *MSDP_PACKAGE_NAME = "ohos.msdp.spatialawareness";
78     }
79 
CheckOpenSessionPermission(const SessionParam * param)80 int32_t SoftBusServerStub::CheckOpenSessionPermission(const SessionParam *param)
81 {
82     char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
83     if ((param == nullptr) ||
84         (TransGetPkgNameBySessionName(param->sessionName, pkgName, PKG_NAME_SIZE_MAX) != SOFTBUS_OK)) {
85         COMM_LOGE(COMM_SVC, "OpenSession pararm error or lock mutex or copy pkgName failed");
86         return SOFTBUS_INVALID_PARAM;
87     }
88 
89     pid_t callingUid = OHOS::IPCSkeleton::GetCallingUid();
90     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
91     if (CheckTransPermission(callingUid, callingPid, pkgName, param->sessionName, ACTION_OPEN) != SOFTBUS_OK) {
92         COMM_LOGE(COMM_SVC, "OpenSession no permission");
93         return SOFTBUS_PERMISSION_DENIED;
94     }
95 
96     if (!CheckUidAndPid(param->sessionName, callingUid, callingPid)) {
97         char *tmpName = NULL;
98         Anonymize(param->sessionName, &tmpName);
99         COMM_LOGE(COMM_SVC, "Check Uid and Pid failed, sessionName=%{public}s", AnonymizeWrapper(tmpName));
100         AnonymizeFree(tmpName);
101         return SOFTBUS_TRANS_CHECK_PID_ERROR;
102     }
103 
104     if (CheckTransSecLevel(param->sessionName, param->peerSessionName) != SOFTBUS_OK) {
105         COMM_LOGE(COMM_SVC, "OpenSession sec level invalid");
106         return SOFTBUS_PERMISSION_DENIED;
107     }
108     return SOFTBUS_OK;
109 }
110 
CheckChannelPermission(int32_t channelId,int32_t channelType)111 int32_t SoftBusServerStub::CheckChannelPermission(int32_t channelId, int32_t channelType)
112 {
113     char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
114     char sessionName[SESSION_NAME_SIZE_MAX] = { 0 };
115     int32_t ret = SOFTBUS_OK;
116     TransInfo info;
117     info.channelId = channelId;
118     info.channelType = channelType;
119     ret = TransGetNameByChanId(&info, pkgName, sessionName, PKG_NAME_SIZE_MAX, SESSION_NAME_SIZE_MAX);
120     if (ret != SOFTBUS_OK) {
121         COMM_LOGE(COMM_SVC, "ServerCloseChannel invalid channel info");
122         return ret;
123     }
124 
125     pid_t callingUid = OHOS::IPCSkeleton::GetCallingUid();
126     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
127     if (CheckTransPermission(callingUid, callingPid, pkgName, sessionName, ACTION_OPEN) != SOFTBUS_OK) {
128         return SOFTBUS_PERMISSION_DENIED;
129     }
130     return SOFTBUS_OK;
131 }
132 
SoftbusReportPermissionFaultEvt(uint32_t ipcCode)133 static void SoftbusReportPermissionFaultEvt(uint32_t ipcCode)
134 {
135     if (ipcCode == SERVER_OPEN_SESSION) {
136         SoftbusReportTransErrorEvt(SOFTBUS_ACCESS_TOKEN_DENIED);
137     }
138 }
139 
SoftBusServerStub()140 SoftBusServerStub::SoftBusServerStub()
141 {
142     InitMemberFuncMap();
143     InitMemberPermissionMap();
144     memberFuncMap_[MANAGE_REGISTER_BR_PROXY_SERVICE] = &SoftBusServerStub::SoftbusRegisterBrProxyServiceInner;
145     memberFuncMap_[SERVER_OPEN_BR_PROXY] = &SoftBusServerStub::OpenBrProxyInner;
146     memberFuncMap_[SERVER_CLOSE_BR_PROXY] = &SoftBusServerStub::CloseBrProxyInner;
147     memberFuncMap_[SERVER_SEND_BR_PROXY_DATA] = &SoftBusServerStub::SendBrProxyDataInner;
148     memberFuncMap_[SERVER_SET_BR_PROXY_LISTENER_STATE] = &SoftBusServerStub::SetBrProxyListenerStateInner;
149     memberFuncMap_[SERVER_GET_BR_PROXY_CHANNEL_STATE] = &SoftBusServerStub::GetBrProxyChannelStateInner;
150     memberFuncMap_[SERVER_REGISTER_PUSH_HOOK] = &SoftBusServerStub::RegisterPushHookInner;
151     memberPermissionMap_[MANAGE_REGISTER_BR_PROXY_SERVICE] = OHOS_PERMISSION_ACCESS_BLUETOOTH;
152     memberPermissionMap_[SERVER_OPEN_BR_PROXY] = OHOS_PERMISSION_ACCESS_BLUETOOTH;
153     memberPermissionMap_[SERVER_CLOSE_BR_PROXY] = OHOS_PERMISSION_ACCESS_BLUETOOTH;
154     memberPermissionMap_[SERVER_SEND_BR_PROXY_DATA] = OHOS_PERMISSION_ACCESS_BLUETOOTH;
155     memberPermissionMap_[SERVER_SET_BR_PROXY_LISTENER_STATE] = OHOS_PERMISSION_ACCESS_BLUETOOTH;
156     memberPermissionMap_[SERVER_GET_BR_PROXY_CHANNEL_STATE] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
157     memberPermissionMap_[SERVER_REGISTER_PUSH_HOOK] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
158 }
159 
InitMemberFuncMap()160 void SoftBusServerStub::InitMemberFuncMap()
161 {
162     memberFuncMap_[MANAGE_REGISTER_SERVICE] = &SoftBusServerStub::SoftbusRegisterServiceInner;
163     memberFuncMap_[SERVER_CREATE_SESSION_SERVER] = &SoftBusServerStub::CreateSessionServerInner;
164     memberFuncMap_[SERVER_REMOVE_SESSION_SERVER] = &SoftBusServerStub::RemoveSessionServerInner;
165     memberFuncMap_[SERVER_RELEASE_RESOURCES] = &SoftBusServerStub::ReleaseResourcesInner;
166     memberFuncMap_[SERVER_OPEN_SESSION] = &SoftBusServerStub::OpenSessionInner;
167     memberFuncMap_[SERVER_OPEN_AUTH_SESSION] = &SoftBusServerStub::OpenAuthSessionInner;
168     memberFuncMap_[SERVER_NOTIFY_AUTH_SUCCESS] = &SoftBusServerStub::NotifyAuthSuccessInner;
169     memberFuncMap_[SERVER_CLOSE_CHANNEL] = &SoftBusServerStub::CloseChannelInner;
170     memberFuncMap_[SERVER_CLOSE_CHANNEL_STATISTICS] = &SoftBusServerStub::CloseChannelWithStatisticsInner;
171     memberFuncMap_[SERVER_SESSION_SENDMSG] = &SoftBusServerStub::SendMessageInner;
172     memberFuncMap_[SERVER_EVALUATE_QOS] = &SoftBusServerStub::EvaluateQosInner;
173     memberFuncMap_[SERVER_JOIN_LNN] = &SoftBusServerStub::JoinLNNInner;
174     memberFuncMap_[SERVER_LEAVE_LNN] = &SoftBusServerStub::LeaveLNNInner;
175     memberFuncMap_[SERVER_GET_ALL_ONLINE_NODE_INFO] = &SoftBusServerStub::GetAllOnlineNodeInfoInner;
176     memberFuncMap_[SERVER_GET_LOCAL_DEVICE_INFO] = &SoftBusServerStub::GetLocalDeviceInfoInner;
177     memberFuncMap_[SERVER_GET_NODE_KEY_INFO] = &SoftBusServerStub::GetNodeKeyInfoInner;
178     memberFuncMap_[SERVER_SET_NODE_DATA_CHANGE_FLAG] = &SoftBusServerStub::SetNodeDataChangeFlagInner;
179     memberFuncMap_[SERVER_REG_DATA_LEVEL_CHANGE_CB] = &SoftBusServerStub::RegDataLevelChangeCbInner;
180     memberFuncMap_[SERVER_UNREG_DATA_LEVEL_CHANGE_CB] = &SoftBusServerStub::UnregDataLevelChangeCbInner;
181     memberFuncMap_[SERVER_SET_DATA_LEVEL] = &SoftBusServerStub::SetDataLevelInner;
182     memberFuncMap_[SERVER_START_TIME_SYNC] = &SoftBusServerStub::StartTimeSyncInner;
183     memberFuncMap_[SERVER_STOP_TIME_SYNC] = &SoftBusServerStub::StopTimeSyncInner;
184     memberFuncMap_[SERVER_QOS_REPORT] = &SoftBusServerStub::QosReportInner;
185     memberFuncMap_[SERVER_STREAM_STATS] = &SoftBusServerStub::StreamStatsInner;
186     memberFuncMap_[SERVER_GRANT_PERMISSION] = &SoftBusServerStub::GrantPermissionInner;
187     memberFuncMap_[SERVER_REMOVE_PERMISSION] = &SoftBusServerStub::RemovePermissionInner;
188     memberFuncMap_[SERVER_PUBLISH_LNN] = &SoftBusServerStub::PublishLNNInner;
189     memberFuncMap_[SERVER_STOP_PUBLISH_LNN] = &SoftBusServerStub::StopPublishLNNInner;
190     memberFuncMap_[SERVER_REFRESH_LNN] = &SoftBusServerStub::RefreshLNNInner;
191     memberFuncMap_[SERVER_STOP_REFRESH_LNN] = &SoftBusServerStub::StopRefreshLNNInner;
192     memberFuncMap_[SERVER_ACTIVE_META_NODE] = &SoftBusServerStub::ActiveMetaNodeInner;
193     memberFuncMap_[SERVER_DEACTIVE_META_NODE] = &SoftBusServerStub::DeactiveMetaNodeInner;
194     memberFuncMap_[SERVER_GET_ALL_META_NODE_INFO] = &SoftBusServerStub::GetAllMetaNodeInfoInner;
195     memberFuncMap_[SERVER_SHIFT_LNN_GEAR] = &SoftBusServerStub::ShiftLNNGearInner;
196     memberFuncMap_[SERVER_TRIGGER_RANGE_FOR_MSDP] = &SoftBusServerStub::TriggerRangeForMsdpInner;
197     memberFuncMap_[SERVER_STOP_RANGE_FOR_MSDP] = &SoftBusServerStub::StopRangeForMsdpInner;
198     memberFuncMap_[SERVER_REG_RANGE_CB_FOR_MSDP] = &SoftBusServerStub::RegRangeCbForMsdpInner;
199     memberFuncMap_[SERVER_UNREG_RANGE_CB_FOR_MSDP] = &SoftBusServerStub::UnregRangeCbForMsdpInner;
200     memberFuncMap_[SERVER_SYNC_TRUSTED_RELATION] = &SoftBusServerStub::SyncTrustedRelationShipInner;
201     memberFuncMap_[SERVER_RIPPLE_STATS] = &SoftBusServerStub::RippleStatsInner;
202     memberFuncMap_[SERVER_GET_SOFTBUS_SPEC_OBJECT] = &SoftBusServerStub::GetSoftbusSpecObjectInner;
203     memberFuncMap_[SERVER_GET_BUS_CENTER_EX_OBJ] = &SoftBusServerStub::GetBusCenterExObjInner;
204     memberFuncMap_[SERVER_PROCESS_INNER_EVENT] = &SoftBusServerStub::ProcessInnerEventInner;
205     memberFuncMap_[SERVER_PRIVILEGE_CLOSE_CHANNEL] = &SoftBusServerStub::PrivilegeCloseChannelInner;
206     memberFuncMap_[SERVER_SET_DISPLAY_NAME] = &SoftBusServerStub::SetDisplayNameInner;
207     memberFuncMap_[SERVER_GENERAL_CREATE_SERVER] = &SoftBusServerStub::CreateServerInner;
208     memberFuncMap_[SERVER_GENERAL_REMOVE_SERVER] = &SoftBusServerStub::RemoveServerInner;
209     memberFuncMap_[SERVER_GENERAL_CONNECT] = &SoftBusServerStub::ConnectInner;
210     memberFuncMap_[SERVER_GENERAL_DISCONNECT] = &SoftBusServerStub::DisconnectInner;
211     memberFuncMap_[SERVER_GENERAL_SEND] = &SoftBusServerStub::SendInner;
212     memberFuncMap_[SERVER_GENERAL_GET_PEER_DEVICE_ID] = &SoftBusServerStub::GetPeerDeviceIdInner;
213 }
214 
InitMemberPermissionMap()215 void SoftBusServerStub::InitMemberPermissionMap()
216 {
217     memberPermissionMap_[MANAGE_REGISTER_SERVICE] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
218     memberPermissionMap_[SERVER_CREATE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
219     memberPermissionMap_[SERVER_REMOVE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
220     memberPermissionMap_[SERVER_RELEASE_RESOURCES] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
221     memberPermissionMap_[SERVER_OPEN_SESSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
222     memberPermissionMap_[SERVER_OPEN_AUTH_SESSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
223     memberPermissionMap_[SERVER_NOTIFY_AUTH_SUCCESS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
224     memberPermissionMap_[SERVER_CLOSE_CHANNEL] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
225     memberPermissionMap_[SERVER_CLOSE_CHANNEL_STATISTICS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
226     memberPermissionMap_[SERVER_SESSION_SENDMSG] = nullptr;
227     memberPermissionMap_[SERVER_JOIN_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
228     memberPermissionMap_[SERVER_JOIN_METANODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
229     memberPermissionMap_[SERVER_LEAVE_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
230     memberPermissionMap_[SERVER_LEAVE_METANODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
231     memberPermissionMap_[SERVER_GET_ALL_ONLINE_NODE_INFO] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
232     memberPermissionMap_[SERVER_GET_LOCAL_DEVICE_INFO] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
233     memberPermissionMap_[SERVER_GET_NODE_KEY_INFO] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
234     memberPermissionMap_[SERVER_SET_NODE_DATA_CHANGE_FLAG] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
235     memberPermissionMap_[SERVER_REG_DATA_LEVEL_CHANGE_CB] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
236     memberPermissionMap_[SERVER_UNREG_DATA_LEVEL_CHANGE_CB] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
237     memberPermissionMap_[SERVER_SET_DATA_LEVEL] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
238     memberPermissionMap_[SERVER_START_TIME_SYNC] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
239     memberPermissionMap_[SERVER_STOP_TIME_SYNC] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
240     memberPermissionMap_[SERVER_QOS_REPORT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
241     memberPermissionMap_[SERVER_STREAM_STATS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
242     memberPermissionMap_[SERVER_GRANT_PERMISSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
243     memberPermissionMap_[SERVER_REMOVE_PERMISSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
244     memberPermissionMap_[SERVER_PUBLISH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
245     memberPermissionMap_[SERVER_STOP_PUBLISH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
246     memberPermissionMap_[SERVER_REFRESH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
247     memberPermissionMap_[SERVER_STOP_REFRESH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
248     memberPermissionMap_[SERVER_ACTIVE_META_NODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
249     memberPermissionMap_[SERVER_DEACTIVE_META_NODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
250     memberPermissionMap_[SERVER_GET_ALL_META_NODE_INFO] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
251     memberPermissionMap_[SERVER_SHIFT_LNN_GEAR] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
252     memberPermissionMap_[SERVER_TRIGGER_RANGE_FOR_MSDP] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
253     memberPermissionMap_[SERVER_STOP_RANGE_FOR_MSDP] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
254     memberPermissionMap_[SERVER_REG_RANGE_CB_FOR_MSDP] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
255     memberPermissionMap_[SERVER_UNREG_RANGE_CB_FOR_MSDP] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
256     memberPermissionMap_[SERVER_SYNC_TRUSTED_RELATION] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
257     memberPermissionMap_[SERVER_RIPPLE_STATS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
258     memberPermissionMap_[SERVER_GET_SOFTBUS_SPEC_OBJECT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
259     memberPermissionMap_[SERVER_GET_BUS_CENTER_EX_OBJ] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
260     memberPermissionMap_[SERVER_EVALUATE_QOS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
261     memberPermissionMap_[SERVER_PROCESS_INNER_EVENT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
262     memberPermissionMap_[SERVER_PRIVILEGE_CLOSE_CHANNEL] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
263     memberPermissionMap_[SERVER_SET_DISPLAY_NAME] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
264     memberPermissionMap_[SERVER_GENERAL_CREATE_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
265     memberPermissionMap_[SERVER_GENERAL_REMOVE_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
266     memberPermissionMap_[SERVER_GENERAL_CONNECT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
267     memberPermissionMap_[SERVER_GENERAL_DISCONNECT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
268     memberPermissionMap_[SERVER_GENERAL_SEND] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
269     memberPermissionMap_[SERVER_GENERAL_GET_PEER_DEVICE_ID] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
270 }
271 
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)272 int32_t SoftBusServerStub::OnRemoteRequest(
273     uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
274 {
275     SoftbusRecordCalledApiCnt(code);
276     if (data.ReadInterfaceToken() != GetDescriptor()) {
277         COMM_LOGE(COMM_SVC, "SOFTBUS_SERVER_NOT_INIT ReadInterfaceToken failed!");
278         return SOFTBUS_IPC_ERR;
279     }
280     if (!GetServerIsInit()) {
281         COMM_LOGE(COMM_SVC, "server not init");
282         if (!reply.WriteInt32(SOFTBUS_SERVER_NOT_INIT)) {
283             COMM_LOGE(COMM_SVC, "SOFTBUS_SERVER_NOT_INIT write reply failed!");
284         }
285         return SOFTBUS_IPC_ERR;
286     }
287 
288     auto itPerm = memberPermissionMap_.find(code);
289     if (itPerm != memberPermissionMap_.end()) {
290         const char *permission = itPerm->second;
291         uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
292         if ((permission != nullptr) &&
293             (!SoftBusCheckIsAccessAndRecordAccessToken(callingTokenId, permission))) {
294             SoftbusReportPermissionFaultEvt(code);
295             COMM_LOGE(COMM_SVC, "access token permission denied! permission=%{public}s, tokenId=%{public}d",
296                 permission, callingTokenId);
297             pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
298             TransAlarmExtra extra = {
299                 .callerPid = (int32_t)callingPid,
300                 .methodId = (int32_t)code,
301                 .conflictName = NULL,
302                 .conflictedName = NULL,
303                 .occupyedName = NULL,
304                 .permissionName = permission,
305                 .sessionName = NULL,
306             };
307             TRANS_ALARM(NO_PERMISSION_ALARM, CONTROL_ALARM_TYPE, extra);
308             return SOFTBUS_ACCESS_TOKEN_DENIED;
309         }
310     }
311 
312     const auto &itFunc = memberFuncMap_.find(code);
313     if (itFunc != memberFuncMap_.end()) {
314         auto memberFunc = itFunc->second;
315         if (memberFunc != nullptr) {
316             return (this->*memberFunc)(data, reply);
317         }
318     }
319     COMM_LOGI(COMM_SVC, "default case, need check.");
320     return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
321 }
322 
SoftbusRegisterServiceInner(MessageParcel & data,MessageParcel & reply)323 int32_t SoftBusServerStub::SoftbusRegisterServiceInner(MessageParcel &data, MessageParcel &reply)
324 {
325     COMM_LOGD(COMM_SVC, "enter");
326     auto remote = data.ReadRemoteObject();
327     if (remote == nullptr) {
328         COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read systemAbilityId failed!");
329         return SOFTBUS_TRANS_PROXY_REMOTE_NULL;
330     }
331     const char *pkgName = data.ReadCString();
332     if (pkgName == nullptr) {
333         COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read pkgName failed!");
334         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
335     }
336     uint32_t code = MANAGE_REGISTER_SERVICE;
337     SoftbusRecordCalledApiInfo(pkgName, code);
338     int32_t retReply = SoftbusRegisterService(pkgName, remote);
339     if (!reply.WriteInt32(retReply)) {
340         COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner write reply failed!");
341         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
342     }
343     return SOFTBUS_OK;
344 }
345 
346 #ifdef SUPPORT_BUNDLENAME
GetBundleName(pid_t callingUid,std::string & bundleName)347 static int32_t GetBundleName(pid_t callingUid, std::string &bundleName)
348 {
349     sptr<ISystemAbilityManager> systemAbilityManager =
350         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
351     if (systemAbilityManager == nullptr) {
352         COMM_LOGE(COMM_SVC, "Failed to get system ability manager.");
353         return SOFTBUS_TRANS_SYSTEM_ABILITY_MANAGER_FAILED;
354     }
355     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
356     if (remoteObject == nullptr) {
357         COMM_LOGE(COMM_SVC, "Failed to get bundle manager service.");
358         return SOFTBUS_TRANS_GET_SYSTEM_ABILITY_FAILED;
359     }
360     sptr<AppExecFwk::IBundleMgr> iBundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
361     if (iBundleMgr == nullptr) {
362         COMM_LOGE(COMM_SVC, "iface_cast failed");
363         return SOFTBUS_TRANS_GET_BUNDLE_MGR_FAILED;
364     }
365     if (iBundleMgr->GetNameForUid(callingUid, bundleName) != SOFTBUS_OK) {
366         COMM_LOGE(COMM_SVC, "get bundleName failed");
367         return SOFTBUS_TRANS_GET_BUNDLENAME_FAILED;
368     }
369     return SOFTBUS_OK;
370 }
371 
GetAppId(const std::string & bundleName,std::string & appId)372 static int32_t GetAppId(const std::string &bundleName, std::string &appId)
373 {
374     sptr<ISystemAbilityManager> systemAbilityManager =
375         SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
376     if (systemAbilityManager == nullptr) {
377         COMM_LOGE(COMM_SVC, "Failed to get system ability manager.");
378         return SOFTBUS_TRANS_SYSTEM_ABILITY_MANAGER_FAILED;
379     }
380     sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
381     if (remoteObject == nullptr) {
382         COMM_LOGE(COMM_SVC, "Failed to get bundle manager service.");
383         return SOFTBUS_TRANS_GET_SYSTEM_ABILITY_FAILED;
384     }
385     sptr<AppExecFwk::IBundleMgr> iBundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
386     if (iBundleMgr == nullptr) {
387         COMM_LOGE(COMM_SVC, "iface_cast failed");
388         return SOFTBUS_TRANS_GET_BUNDLE_MGR_FAILED;
389     }
390     int32_t userId;
391     auto result = AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(userId);
392     if (result != 0) {
393         COMM_LOGE(COMM_SVC, "GetForegroundOsAccountLocalId failed result=%{public}d", result);
394         return result;
395     }
396     AppExecFwk::BundleInfo bundleInfo;
397     result = iBundleMgr->GetBundleInfoV9(bundleName,
398         static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO),
399         bundleInfo, userId);
400     if (result != 0) {
401         COMM_LOGE(COMM_SVC, "GetBundleInfoV9 failed result=%{public}d", result);
402         return result;
403     }
404     appId = bundleInfo.appId;
405     return SOFTBUS_OK;
406 }
407 
CheckNormalAppSessionName(const char * sessionName,pid_t callingUid,std::string & strName,uint64_t callingFullTokenId)408 static int32_t CheckNormalAppSessionName(
409     const char *sessionName, pid_t callingUid, std::string &strName, uint64_t callingFullTokenId)
410 {
411     if (SoftBusCheckIsNormalApp(callingFullTokenId, sessionName)) {
412         std::string bundleName;
413         int32_t result = GetBundleName(callingUid, bundleName);
414         if (result != SOFTBUS_OK) {
415             COMM_LOGE(COMM_SVC, "get bundle name failed");
416             return result;
417         }
418         std::string appId;
419         result = GetAppId(bundleName, appId);
420         if (result != SOFTBUS_OK) {
421             COMM_LOGE(COMM_SVC, "get appId failed");
422             return result;
423         }
424         auto posName = strName.find("-");
425         if (posName == std::string::npos) {
426             COMM_LOGE(COMM_SVC, "not find bundleName");
427             return SOFTBUS_TRANS_NOT_FIND_BUNDLENAME;
428         }
429         auto posId = strName.find("-", posName + 1);
430         if (posId == std::string::npos) {
431             COMM_LOGE(COMM_SVC, "not find appId");
432             return SOFTBUS_TRANS_NOT_FIND_APPID;
433         }
434         if (strcmp(bundleName.c_str(), strName.substr(posName + 1, posId - posName - 1).c_str()) != 0) {
435             COMM_LOGE(COMM_SVC, "bundleName is different from session name");
436             return SOFTBUS_STRCMP_ERR;
437         }
438         if (strcmp(appId.c_str(), strName.substr(posId + 1).c_str()) != 0) {
439             COMM_LOGE(COMM_SVC, "appId is different from session name");
440             return SOFTBUS_STRCMP_ERR;
441         }
442         strName.erase(posId);
443     }
444     return SOFTBUS_OK;
445 }
446 
TransCheckSystemAppList(pid_t callingUid)447 static int32_t TransCheckSystemAppList(pid_t callingUid)
448 {
449     std::string bundleName;
450     int32_t ret = GetBundleName(callingUid, bundleName);
451     COMM_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, COMM_SVC, "get bundle name failed.");
452 
453     if (!IsInWhitelistPacked(bundleName.c_str())) {
454         COMM_LOGE(COMM_SVC, "not found bundleName in system app whitelist.");
455         return SOFTBUS_TRANS_NOT_FIND_BUNDLENAME;
456     }
457     return SOFTBUS_OK;
458 }
459 #endif
460 
SoftBusCheckTimestamp(MessageParcel & data,const char * sessionName)461 static int32_t SoftBusCheckTimestamp(MessageParcel &data, const char *sessionName)
462 {
463     uint64_t timestamp = 0;
464     if (!data.ReadUint64(timestamp)) {
465         COMM_LOGE(COMM_SVC, "CreateSessionServerInner read timestamp failed!");
466         return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
467     }
468     int32_t ret = CheckAndUpdateTimeBySessionName(sessionName, timestamp);
469     if (ret == SOFTBUS_TRANS_SESSION_NAME_NO_EXIST || ret == SOFTBUS_OK) {
470         return SOFTBUS_OK;
471     }
472     return SOFTBUS_TRANS_SESSION_TIME_NOT_EQUAL;
473 }
474 
CreateSessionServerInner(MessageParcel & data,MessageParcel & reply)475 int32_t SoftBusServerStub::CreateSessionServerInner(MessageParcel &data, MessageParcel &reply)
476 {
477     COMM_LOGD(COMM_SVC, "enter");
478     int32_t retReply;
479     pid_t callingUid;
480     pid_t callingPid;
481 #ifdef SUPPORT_BUNDLENAME
482     uint64_t callingFullTokenId = IPCSkeleton::GetCallingFullTokenID();
483 #endif
484     const char *pkgName = data.ReadCString();
485     if (pkgName == nullptr) {
486         COMM_LOGE(COMM_SVC, "CreateSessionServerInner read pkgName failed!");
487         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
488     }
489 
490     const char *sessionName = data.ReadCString();
491     std::string strName;
492     uint32_t code = SERVER_CREATE_SESSION_SERVER;
493     SoftbusRecordCalledApiInfo(pkgName, code);
494     if (pkgName == nullptr || sessionName == nullptr) {
495         retReply = SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
496         goto EXIT;
497     }
498     strName = sessionName;
499     callingUid = OHOS::IPCSkeleton::GetCallingUid();
500     callingPid = OHOS::IPCSkeleton::GetCallingPid();
501     if (CheckTransPermission(callingUid, callingPid, pkgName, sessionName, ACTION_CREATE) != SOFTBUS_OK) {
502         retReply = SOFTBUS_PERMISSION_DENIED;
503         goto EXIT;
504     }
505 #ifdef SUPPORT_BUNDLENAME
506     if (SoftBusCheckIsSystemApp(callingFullTokenId, sessionName) == true) {
507         if (TransCheckSystemAppList(callingUid) != SOFTBUS_OK) {
508             retReply = SOFTBUS_PERMISSION_DENIED;
509             goto EXIT;
510         }
511     } else {
512         if (CheckNormalAppSessionName(sessionName, callingUid, strName, callingFullTokenId) != SOFTBUS_OK) {
513             retReply = SOFTBUS_PERMISSION_DENIED;
514             goto EXIT;
515         }
516     }
517     sessionName = strName.c_str();
518 #endif
519     (void)SoftBusCheckTimestamp(data, sessionName);
520     retReply = CreateSessionServer(pkgName, sessionName, 0);
521 EXIT:
522     if (!reply.WriteInt32(retReply)) {
523         COMM_LOGE(COMM_SVC, "CreateSessionServerInner write reply failed!");
524         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
525     }
526     return SOFTBUS_OK;
527 }
528 
RemoveSessionServerInner(MessageParcel & data,MessageParcel & reply)529 int32_t SoftBusServerStub::RemoveSessionServerInner(MessageParcel &data, MessageParcel &reply)
530 {
531     COMM_LOGD(COMM_SVC, "enter");
532     int32_t retReply;
533     pid_t callingUid;
534     pid_t callingPid;
535     const char *pkgName = data.ReadCString();
536     if (pkgName == nullptr) {
537         COMM_LOGE(COMM_SVC, "RemoveSessionServerInner read pkgName failed!");
538         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
539     }
540 
541     const char *sessionName = data.ReadCString();
542     uint32_t code = SERVER_REMOVE_SESSION_SERVER;
543     SoftbusRecordCalledApiInfo(pkgName, code);
544     if (pkgName == nullptr || sessionName == nullptr) {
545         retReply = SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
546         goto EXIT;
547     }
548 
549     callingUid = OHOS::IPCSkeleton::GetCallingUid();
550     callingPid = OHOS::IPCSkeleton::GetCallingPid();
551     if (CheckTransPermission(callingUid, callingPid, pkgName, sessionName, ACTION_CREATE) != SOFTBUS_OK) {
552         COMM_LOGE(COMM_SVC, "RemoveSessionServerInner check perm failed");
553         retReply = SOFTBUS_PERMISSION_DENIED;
554         goto EXIT;
555     }
556 
557     if (!CheckUidAndPid(sessionName, callingUid, callingPid)) {
558         COMM_LOGE(COMM_SVC, "Check Uid and Pid failed!");
559         return SOFTBUS_TRANS_CHECK_PID_ERROR;
560     }
561     if (SoftBusCheckTimestamp(data, sessionName) != SOFTBUS_OK) {
562         retReply = SOFTBUS_TRANS_PROXY_READUINT_FAILED;
563         goto EXIT;
564     }
565     retReply = RemoveSessionServer(pkgName, sessionName, 0);
566 EXIT:
567     if (!reply.WriteInt32(retReply)) {
568         COMM_LOGE(COMM_SVC, "RemoveSessionServerInner write reply failed!");
569         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
570     }
571     return SOFTBUS_OK;
572 }
573 
ReadSessionAttrs(MessageParcel & data,SessionAttribute * getAttr)574 static void ReadSessionAttrs(MessageParcel &data, SessionAttribute *getAttr)
575 {
576     if (getAttr == nullptr) {
577         COMM_LOGE(COMM_SVC, "ReadSessionAttrs getAttr is nullptr");
578         return;
579     }
580     LinkType *pGetArr = nullptr;
581 
582     getAttr->dataType = data.ReadInt32();
583     getAttr->linkTypeNum = data.ReadInt32();
584 
585     if (getAttr->linkTypeNum > 0 && getAttr->linkTypeNum <= LINK_TYPE_MAX) {
586         pGetArr = const_cast<LinkType *>(
587             reinterpret_cast<const LinkType *>(data.ReadBuffer(sizeof(LinkType) * getAttr->linkTypeNum)));
588     }
589 
590     if (pGetArr != nullptr) {
591         if (memcpy_s(getAttr->linkType, sizeof(LinkType) * LINK_TYPE_MAX, pGetArr,
592             sizeof(LinkType) * getAttr->linkTypeNum) != EOK) {
593             COMM_LOGE(COMM_SVC, "LinkType copy failed linkTypeNum = %{public}d, dataType = %{public}d",
594                 getAttr->linkTypeNum, getAttr->dataType);
595         }
596     }
597 
598     getAttr->attr.streamAttr.streamType = data.ReadInt32();
599     getAttr->fastTransDataSize = data.ReadUint16();
600     if (getAttr->fastTransDataSize != 0) {
601         getAttr->fastTransData =
602             const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(data.ReadRawData(getAttr->fastTransDataSize)));
603     }
604 }
605 
ReadQosInfo(MessageParcel & data,SessionParam & param)606 static bool ReadQosInfo(MessageParcel &data, SessionParam &param)
607 {
608     if (!data.ReadBool(param.isQosLane)) {
609         COMM_LOGE(COMM_SVC, "failed to read isQosLane");
610         return false;
611     }
612     if (!param.isQosLane) {
613         return true;
614     }
615 
616     if (!data.ReadUint32(param.qosCount)) {
617         COMM_LOGE(COMM_SVC, "failed to read qosCount");
618         return false;
619     }
620     if (param.qosCount == 0) {
621         return true;
622     }
623 
624     if (param.qosCount > QOS_TYPE_BUTT) {
625         COMM_LOGE(COMM_SVC, "read invalid qosCount=%{public}" PRIu32, param.qosCount);
626         return false;
627     }
628 
629     const QosTV *qosInfo = (QosTV *)data.ReadBuffer(sizeof(QosTV) * param.qosCount);
630     if (qosInfo == nullptr) {
631         COMM_LOGE(COMM_SVC, "failed to read qos data");
632         return false;
633     }
634 
635     if (memcpy_s(param.qos, sizeof(QosTV) * QOS_TYPE_BUTT, qosInfo, sizeof(QosTV) * param.qosCount) != EOK) {
636         COMM_LOGE(COMM_SVC, "failed memcpy qos info");
637         return false;
638     }
639     return true;
640 }
641 
ReadSessionInfo(MessageParcel & data,SessionParam & param)642 static void ReadSessionInfo(MessageParcel &data, SessionParam &param)
643 {
644     param.sessionName = data.ReadCString();
645     param.peerSessionName = data.ReadCString();
646     param.peerDeviceId = data.ReadCString();
647     param.groupId = data.ReadCString();
648     param.isAsync = data.ReadBool();
649     param.sessionId = data.ReadInt32();
650     param.actionId = data.ReadUint32();
651     param.pid = OHOS::IPCSkeleton::GetCallingPid();
652     param.isLowLatency = data.ReadBool();
653     param.flowInfo.flowSize = data.ReadUint64();
654     param.flowInfo.sessionType = (FlowSessionType)data.ReadUint32();
655     param.flowInfo.flowQosType = (FlowQosType)data.ReadUint32();
656 }
657 
OpenSessionInner(MessageParcel & data,MessageParcel & reply)658 int32_t SoftBusServerStub::OpenSessionInner(MessageParcel &data, MessageParcel &reply)
659 {
660     COMM_LOGD(COMM_SVC, "enter");
661     int32_t retReply;
662     SessionParam param { 0 };
663     SessionAttribute getAttr { 0 };
664 
665     TransSerializer transSerializer;
666     int64_t timeStart = 0;
667     int64_t timediff = 0;
668     SoftBusOpenSessionStatus isSucc = SOFTBUS_EVT_OPEN_SESSION_FAIL;
669     ReadSessionInfo(data, param);
670     ReadSessionAttrs(data, &getAttr);
671     param.attr = &getAttr;
672     COMM_CHECK_AND_RETURN_RET_LOGE(ReadQosInfo(data, param), SOFTBUS_IPC_ERR, COMM_SVC, "failed to read qos info");
673 
674     if (param.sessionName == nullptr || param.peerSessionName == nullptr || param.peerDeviceId == nullptr ||
675         param.groupId == nullptr) {
676         retReply = SOFTBUS_INVALID_PARAM;
677         goto EXIT;
678     }
679 
680 #define DMS_COLLABATION_NAME_PREFIX "ohos.dtbcollab.dms"
681     if (strncmp(param.sessionName, DMS_COLLABATION_NAME_PREFIX, strlen(DMS_COLLABATION_NAME_PREFIX)) == 0) {
682         COMM_LOGI(COMM_SVC, "DMS bind request, need check collaboration relationship");
683         if (CheckSourceCollabRelation(param.peerDeviceId,
684             OHOS::IPCSkeleton::GetCallingPid(), OHOS::IPCSkeleton::GetCallingUid()) != SOFTBUS_OK) {
685             COMM_LOGE(COMM_SVC, "DMS check collaboration relationship failed, reject binding request");
686             retReply = SOFTBUS_TRANS_CHECK_RELATION_FAIL;
687             goto EXIT;
688         }
689     }
690 
691     if ((retReply = TransCheckClientAccessControl(param.peerDeviceId)) != SOFTBUS_OK) {
692         goto EXIT;
693     }
694     if (CheckOpenSessionPermission(&param) != SOFTBUS_OK) {
695         SoftbusReportTransErrorEvt(SOFTBUS_PERMISSION_DENIED);
696         retReply = SOFTBUS_PERMISSION_DENIED;
697         goto EXIT;
698     }
699 
700     timeStart = GetSoftbusRecordTimeMillis();
701     retReply = OpenSession(&param, &(transSerializer.transInfo));
702     timediff = GetSoftbusRecordTimeMillis() - timeStart;
703 
704     isSucc = (retReply == SOFTBUS_OK) ? SOFTBUS_EVT_OPEN_SESSION_SUCC : SOFTBUS_EVT_OPEN_SESSION_FAIL;
705     SoftbusRecordOpenSession(isSucc, static_cast<uint32_t>(timediff));
706 
707 EXIT:
708     transSerializer.ret = retReply;
709     bool result = reply.WriteRawData(&transSerializer, sizeof(TransSerializer));
710     COMM_CHECK_AND_RETURN_RET_LOGE(result, SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
711     return SOFTBUS_OK;
712 }
713 
OpenAuthSessionInner(MessageParcel & data,MessageParcel & reply)714 int32_t SoftBusServerStub::OpenAuthSessionInner(MessageParcel &data, MessageParcel &reply)
715 {
716     COMM_LOGD(COMM_SVC, "enter");
717     int32_t retReply;
718     const char *sessionName = data.ReadCString();
719     ConnectionAddr *addrInfo = const_cast<ConnectionAddr *>(
720         reinterpret_cast<const ConnectionAddr *>(data.ReadRawData(sizeof(ConnectionAddr))));
721     if (sessionName == nullptr || addrInfo == nullptr) {
722         COMM_LOGE(COMM_SVC, "OpenAuthSessionInner get param failed!");
723         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
724     }
725     SessionParam param;
726     param.sessionName = sessionName;
727     param.peerSessionName = sessionName;
728     retReply = CheckOpenSessionPermission(&param);
729     if (retReply != SOFTBUS_OK) {
730         goto EXIT;
731     }
732     retReply = OpenAuthSession(sessionName, addrInfo);
733     AddChannelStatisticsInfo(retReply, CHANNEL_TYPE_AUTH);
734     COMM_LOGI(COMM_SVC, "OpenAuthSession channelId=%{public}d", retReply);
735 EXIT:
736     if (!reply.WriteInt32(retReply)) {
737         COMM_LOGE(COMM_SVC, "OpenSessionInner write reply failed!");
738         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
739     }
740     return SOFTBUS_OK;
741 }
742 
NotifyAuthSuccessInner(MessageParcel & data,MessageParcel & reply)743 int32_t SoftBusServerStub::NotifyAuthSuccessInner(MessageParcel &data, MessageParcel &reply)
744 {
745     COMM_LOGD(COMM_SVC, "enter");
746     int32_t channelId;
747     int32_t channelType;
748     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
749     if (!data.ReadInt32(channelId)) {
750         COMM_LOGE(COMM_SVC, "NotifyAuthSuccessInner read channel Id failed!");
751         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
752     }
753     if (!data.ReadInt32(channelType)) {
754         COMM_LOGE(COMM_SVC, "NotifyAuthSuccessInner read channel type failed!");
755         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
756     }
757     int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
758     if (ret != SOFTBUS_OK) {
759         COMM_LOGE(COMM_SVC, "callingPid not equal pid, callingPid=%{public}d, channelId=%{public}d",
760             callingPid, channelId);
761         return ret;
762     }
763     int32_t retReply = NotifyAuthSuccess(channelId, channelType);
764     if (!reply.WriteInt32(retReply)) {
765         COMM_LOGE(COMM_SVC, "NotifyAuthSuccessInner write reply failed!");
766         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
767     }
768     return SOFTBUS_OK;
769 }
770 
ReleaseResourcesInner(MessageParcel & data,MessageParcel & reply)771 int32_t SoftBusServerStub::ReleaseResourcesInner(MessageParcel &data, MessageParcel &reply)
772 {
773     int32_t channelId;
774     if (!data.ReadInt32(channelId)) {
775         COMM_LOGE(COMM_SVC, "failed to read channel Id");
776         return SOFTBUS_IPC_ERR;
777     }
778 
779     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
780     int32_t ret = TransGetAndComparePid(callingPid, channelId, CHANNEL_TYPE_UDP);
781     if (ret != SOFTBUS_OK) {
782         COMM_LOGE(COMM_SVC, "Pid not find, ret = %{public}d", ret);
783         if (!reply.WriteInt32(ret)) {
784             COMM_LOGE(COMM_SVC, "failed to write ret failed");
785             return SOFTBUS_IPC_ERR;
786         }
787         return ret;
788     }
789     int32_t retReply = ReleaseResources(channelId);
790     if (!reply.WriteInt32(retReply)) {
791         COMM_LOGE(COMM_SVC, "failed to write reply failed");
792         return SOFTBUS_IPC_ERR;
793     }
794     return SOFTBUS_OK;
795 }
796 
CloseChannelInner(MessageParcel & data,MessageParcel & reply)797 int32_t SoftBusServerStub::CloseChannelInner(MessageParcel &data, MessageParcel &reply)
798 {
799     COMM_LOGD(COMM_SVC, "enter");
800     int32_t channelId;
801     if (!data.ReadInt32(channelId)) {
802         COMM_LOGE(COMM_SVC, "CloseChannelInner read channel Id failed!");
803         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
804     }
805     int32_t channelType;
806     if (!data.ReadInt32(channelType)) {
807         COMM_LOGE(COMM_SVC, "CloseChannelInner read channel channel type failed!");
808         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
809     }
810     const char *sessionName = nullptr;
811     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
812     if (channelType == CHANNEL_TYPE_UNDEFINED) {
813         sessionName = data.ReadCString();
814         if (sessionName == nullptr) {
815             COMM_LOGE(COMM_SVC, "CloseChannelInner get param failed!");
816             return SOFTBUS_IPC_ERR;
817         }
818         int32_t ret = TransGetAndComparePidBySession(callingPid, sessionName, channelId);
819         if (ret != SOFTBUS_OK) {
820             COMM_LOGE(COMM_SVC, "Pid can not close channel, pid=%{public}d, sessionId=%{public}d, ret=%{public}d",
821                 callingPid, channelId, ret);
822             return ret;
823         }
824     } else {
825         int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
826         if (ret != SOFTBUS_OK) {
827             COMM_LOGE(COMM_SVC, "Pid can not close channel, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
828                 callingPid, channelId, ret);
829             return ret;
830         }
831     }
832 
833     int32_t retReply = CloseChannel(sessionName, channelId, channelType);
834     if (!reply.WriteInt32(retReply)) {
835         COMM_LOGE(COMM_SVC, "CloseChannelInner write reply failed!");
836         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
837     }
838     return SOFTBUS_OK;
839 }
840 
CloseChannelWithStatisticsInner(MessageParcel & data,MessageParcel & reply)841 int32_t SoftBusServerStub::CloseChannelWithStatisticsInner(MessageParcel &data, MessageParcel &reply)
842 {
843     COMM_LOGD(COMM_SVC, "enter");
844     int32_t channelId;
845     if (!data.ReadInt32(channelId)) {
846         COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner read channel id failed!");
847         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
848     }
849     int32_t channelType;
850     if (!data.ReadInt32(channelType)) {
851         COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner read channel type failed!");
852         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
853     }
854     uint64_t laneId;
855     if (!data.ReadUint64(laneId)) {
856         COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner read lane id failed!");
857         return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
858     }
859     uint32_t len;
860     if (!data.ReadUint32(len)) {
861         COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner dataInfo len failed!");
862         return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
863     }
864 
865     auto rawData = data.ReadRawData(len);
866     COMM_CHECK_AND_RETURN_RET_LOGE(rawData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read len failed.");
867     void *dataInfo = const_cast<void *>(rawData);
868 
869     int32_t retReply = CloseChannelWithStatistics(channelId, channelType, laneId, dataInfo, len);
870     if (!reply.WriteInt32(retReply)) {
871         COMM_LOGE(COMM_SVC, "CloseChannelInner write reply failed!");
872         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
873     }
874     return SOFTBUS_OK;
875 }
876 
SendMessageInner(MessageParcel & data,MessageParcel & reply)877 int32_t SoftBusServerStub::SendMessageInner(MessageParcel &data, MessageParcel &reply)
878 {
879     int32_t channelId;
880     if (!data.ReadInt32(channelId)) {
881         COMM_LOGE(COMM_SVC, "SendMessage read channel Id failed!");
882         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
883     }
884     int32_t channelType;
885     if (!data.ReadInt32(channelType)) {
886         COMM_LOGE(COMM_SVC, "SendMessage read channel type failed!");
887         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
888     }
889     uint32_t len;
890     if (!data.ReadUint32(len)) {
891         COMM_LOGE(COMM_SVC, "SendMessage dataInfo len failed!");
892         return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
893     }
894 
895     auto rawData = data.ReadRawData(len);
896     COMM_CHECK_AND_RETURN_RET_LOGE(rawData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read rawData failed!");
897     void *dataInfo = const_cast<void *>(rawData);
898 
899     int32_t msgType;
900     if (!data.ReadInt32(msgType)) {
901         COMM_LOGE(COMM_SVC, "SendMessage message type failed!");
902         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
903     }
904     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
905     if (TransGetAndComparePid(callingPid, channelId, channelType) != SOFTBUS_OK) {
906         COMM_LOGE(COMM_SVC, "pid permission check failed!");
907         return SOFTBUS_PERMISSION_DENIED;
908     }
909 
910     int32_t retReply = SendMessage(channelId, channelType, dataInfo, len, msgType);
911     if (!reply.WriteInt32(retReply)) {
912         COMM_LOGE(COMM_SVC, "SendMessage write reply failed!");
913         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
914     }
915     return SOFTBUS_OK;
916 }
917 
EvaluateQosInner(MessageParcel & data,MessageParcel & reply)918 int32_t SoftBusServerStub::EvaluateQosInner(MessageParcel &data, MessageParcel &reply)
919 {
920     COMM_LOGD(COMM_SVC, "enter");
921     const char *peerNetworkId = data.ReadCString();
922     if (peerNetworkId == nullptr) {
923         COMM_LOGE(COMM_SVC, "EvaluateQos read peerNetworkId failed!");
924         return SOFTBUS_IPC_ERR;
925     }
926 
927     int32_t dataTypeNumber;
928     if (!data.ReadInt32(dataTypeNumber)) {
929         COMM_LOGE(COMM_SVC, "EvaluateQos read dataType failed!");
930         return SOFTBUS_IPC_ERR;
931     }
932 
933     TransDataType dataType = static_cast<TransDataType>(dataTypeNumber);
934     if (dataType < DATA_TYPE_MESSAGE || dataType >= DATA_TYPE_BUTT) {
935         COMM_LOGE(COMM_SVC, "EvaluateQos read dataType failed!");
936         return SOFTBUS_IPC_ERR;
937     }
938 
939     uint32_t qosCount;
940     if (!data.ReadUint32(qosCount)) {
941         COMM_LOGE(COMM_SVC, "EvaluateQos read qosCount failed!");
942         return SOFTBUS_IPC_ERR;
943     }
944 
945     if (qosCount > QOS_TYPE_BUTT) {
946         COMM_LOGE(COMM_SVC, "EvaluateQos invalid qosCount=%{public}" PRIu32, qosCount);
947         return SOFTBUS_IPC_ERR;
948     }
949 
950     const QosTV *qos = nullptr;
951     if (qosCount > 0) {
952         qos = (QosTV *)data.ReadBuffer(sizeof(QosTV) * qosCount);
953         if (qos == nullptr) {
954             COMM_LOGE(COMM_SVC, "EvaluateQos failed to read qos data");
955             return SOFTBUS_IPC_ERR;
956         }
957     }
958 
959     int32_t retReply = EvaluateQos(peerNetworkId, dataType, qos, qosCount);
960     if (!reply.WriteInt32(retReply)) {
961         COMM_LOGE(COMM_SVC, "EvaluateQos write reply failed!");
962         return SOFTBUS_IPC_ERR;
963     }
964     return SOFTBUS_OK;
965 }
966 
JoinLNNInner(MessageParcel & data,MessageParcel & reply)967 int32_t SoftBusServerStub::JoinLNNInner(MessageParcel &data, MessageParcel &reply)
968 {
969     COMM_LOGD(COMM_SVC, "enter");
970     int32_t ret = PermissionVerify(SERVER_JOIN_LNN);
971     if (ret != SOFTBUS_OK) {
972         COMM_LOGE(COMM_SVC, "permission verification failed");
973         return ret;
974     }
975     const char *clientName = data.ReadCString();
976     if (clientName == nullptr) {
977         COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner read clientName failed!");
978         return SOFTBUS_IPC_ERR;
979     }
980     uint32_t addrTypeLen;
981     if (!data.ReadUint32(addrTypeLen) || addrTypeLen != sizeof(ConnectionAddr)) {
982         COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner read addr type failed! length=%{public}d", addrTypeLen);
983         return SOFTBUS_IPC_ERR;
984     }
985 
986     auto rawData = data.ReadRawData(addrTypeLen);
987     COMM_CHECK_AND_RETURN_RET_LOGE(rawData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read addrTypeLen failed.");
988     void *addr = const_cast<void *>(rawData);
989     bool isForceJoin;
990     if (!data.ReadBool(isForceJoin)) {
991         COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner read force join flag failed!");
992         return SOFTBUS_IPC_ERR;
993     }
994     int32_t retReply = JoinLNN(clientName, addr, addrTypeLen, isForceJoin);
995     if (!reply.WriteInt32(retReply)) {
996         COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner write reply failed!");
997         return SOFTBUS_IPC_ERR;
998     }
999     return SOFTBUS_OK;
1000 }
1001 
LeaveLNNInner(MessageParcel & data,MessageParcel & reply)1002 int32_t SoftBusServerStub::LeaveLNNInner(MessageParcel &data, MessageParcel &reply)
1003 {
1004     COMM_LOGD(COMM_SVC, "enter");
1005     int32_t ret = PermissionVerify(SERVER_LEAVE_LNN);
1006     if (ret != SOFTBUS_OK) {
1007         COMM_LOGE(COMM_SVC, "permission verification failed");
1008         return ret;
1009     }
1010     const char *clientName = data.ReadCString();
1011     if (clientName == nullptr) {
1012         COMM_LOGE(COMM_SVC, "SoftbusLeaveLNNInner read clientName failed!");
1013         return SOFTBUS_IPC_ERR;
1014     }
1015     const char *networkId = data.ReadCString();
1016     if (networkId == nullptr) {
1017         COMM_LOGE(COMM_SVC, "SoftbusLeaveLNNInner read networkId failed!");
1018         return SOFTBUS_IPC_ERR;
1019     }
1020     int32_t retReply = LeaveLNN(clientName, networkId);
1021     if (!reply.WriteInt32(retReply)) {
1022         COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner write reply failed!");
1023         return SOFTBUS_IPC_ERR;
1024     }
1025     return SOFTBUS_OK;
1026 }
1027 
GetAllOnlineNodeInfoInner(MessageParcel & data,MessageParcel & reply)1028 int32_t SoftBusServerStub::GetAllOnlineNodeInfoInner(MessageParcel &data, MessageParcel &reply)
1029 {
1030     COMM_LOGD(COMM_SVC, "enter");
1031     void *nodeInfo = nullptr;
1032     int32_t infoNum;
1033     uint32_t infoTypeLen;
1034 
1035     const char *clientName = data.ReadCString();
1036     if (clientName == nullptr) {
1037         COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner read clientName failed!");
1038         return SOFTBUS_IPC_ERR;
1039     }
1040     if (!data.ReadUint32(infoTypeLen)) {
1041         COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner read info type length failed");
1042         return SOFTBUS_IPC_ERR;
1043     }
1044     int32_t retReply = GetAllOnlineNodeInfo(clientName, &nodeInfo, infoTypeLen, &infoNum);
1045     if (retReply != SOFTBUS_OK) {
1046         COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner get info failed, retReply=%{public}d", retReply);
1047         return retReply;
1048     }
1049     if (infoNum < 0 || (infoNum > 0 && nodeInfo == nullptr)) {
1050         COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner node info is invalid");
1051         return SOFTBUS_IPC_ERR;
1052     }
1053     if (!reply.WriteInt32(infoNum)) {
1054         COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner write infoNum failed!");
1055         SoftBusFree(nodeInfo);
1056         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1057     }
1058     if (infoNum > 0) {
1059         if (!reply.WriteRawData(nodeInfo, static_cast<int32_t>(infoTypeLen * infoNum))) {
1060             COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner write node info failed!");
1061             retReply = SOFTBUS_IPC_ERR;
1062         }
1063         SoftBusFree(nodeInfo);
1064     }
1065     return retReply;
1066 }
1067 
GetLocalDeviceInfoInner(MessageParcel & data,MessageParcel & reply)1068 int32_t SoftBusServerStub::GetLocalDeviceInfoInner(MessageParcel &data, MessageParcel &reply)
1069 {
1070     void *nodeInfo = nullptr;
1071     uint32_t infoTypeLen;
1072 
1073     const char *clientName = data.ReadCString();
1074     if (clientName == nullptr) {
1075         COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner read clientName failed!");
1076         return SOFTBUS_IPC_ERR;
1077     }
1078 
1079     infoTypeLen = data.ReadUint32();
1080     if (infoTypeLen != sizeof(NodeBasicInfo)) {
1081         COMM_LOGE(COMM_SVC, "read infoTypeLen failed!");
1082         return SOFTBUS_IPC_ERR;
1083     }
1084     nodeInfo = SoftBusCalloc(infoTypeLen);
1085     if (nodeInfo == nullptr) {
1086         COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner malloc info type length failed");
1087         return SOFTBUS_IPC_ERR;
1088     }
1089     int32_t retReply = GetLocalDeviceInfo(clientName, nodeInfo, infoTypeLen);
1090     if (!reply.WriteRawData(nodeInfo, infoTypeLen)) {
1091         COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner write node info failed!");
1092         SoftBusFree(nodeInfo);
1093         return SOFTBUS_IPC_ERR;
1094     }
1095     if (!reply.WriteInt32(retReply)) {
1096         COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner write reply failed!");
1097         SoftBusFree(nodeInfo);
1098         return SOFTBUS_IPC_ERR;
1099     }
1100     SoftBusFree(nodeInfo);
1101     return SOFTBUS_OK;
1102 }
1103 
GetNodeKeyInfoLen(int32_t key)1104 int32_t SoftBusServerStub::GetNodeKeyInfoLen(int32_t key)
1105 {
1106     return LnnGetNodeKeyInfoLen(key);
1107 }
1108 
GetNodeKeyInfoInner(MessageParcel & data,MessageParcel & reply)1109 int32_t SoftBusServerStub::GetNodeKeyInfoInner(MessageParcel &data, MessageParcel &reply)
1110 {
1111     const char *clientName = data.ReadCString();
1112     const char *networkId = data.ReadCString();
1113     if (clientName == nullptr || networkId == nullptr) {
1114         COMM_LOGE(COMM_SVC, "read clientName or networkId failed!");
1115         return SOFTBUS_IPC_ERR;
1116     }
1117     char *anonyNetworkId = nullptr;
1118     Anonymize(networkId, &anonyNetworkId);
1119     COMM_LOGD(COMM_SVC, "networkId=%{public}s", anonyNetworkId);
1120     AnonymizeFree(anonyNetworkId);
1121 
1122     int32_t key;
1123     READ_PARCEL_WITH_RET(data, Int32, key, SOFTBUS_IPC_ERR);
1124     int32_t infoLen = GetNodeKeyInfoLen(key);
1125     if (infoLen == SOFTBUS_ERR) {
1126         COMM_LOGE(COMM_SVC, "get info len failed!");
1127         return SOFTBUS_NETWORK_NODE_KEY_INFO_ERR;
1128     }
1129     uint32_t len;
1130     READ_PARCEL_WITH_RET(data, Uint32, len, SOFTBUS_IPC_ERR);
1131     if (len < (uint32_t)infoLen) {
1132         COMM_LOGE(COMM_SVC, "invalid param, len=%{public}u, infoLen=%{public}d", len, infoLen);
1133         return SOFTBUS_INVALID_PARAM;
1134     }
1135     void *buf = SoftBusCalloc(infoLen);
1136     if (buf == nullptr) {
1137         COMM_LOGE(COMM_SVC, "malloc buffer failed!");
1138         return SOFTBUS_MALLOC_ERR;
1139     }
1140     int32_t ret = GetNodeKeyInfo(clientName, networkId, key, static_cast<unsigned char *>(buf), infoLen);
1141     if (!reply.WriteInt32(infoLen)) {
1142         COMM_LOGE(COMM_SVC, "write info length failed!");
1143         SoftBusFree(buf);
1144         return SOFTBUS_IPC_ERR;
1145     }
1146     if (!reply.WriteRawData(buf, infoLen)) {
1147         COMM_LOGE(COMM_SVC, "write key info failed!");
1148         SoftBusFree(buf);
1149         return SOFTBUS_IPC_ERR;
1150     }
1151     if (!reply.WriteInt32(ret)) {
1152         COMM_LOGE(COMM_SVC, "write info length failed!");
1153         SoftBusFree(buf);
1154         return SOFTBUS_IPC_ERR;
1155     }
1156     SoftBusFree(buf);
1157     return SOFTBUS_OK;
1158 }
1159 
SetNodeDataChangeFlagInner(MessageParcel & data,MessageParcel & reply)1160 int32_t SoftBusServerStub::SetNodeDataChangeFlagInner(MessageParcel &data, MessageParcel &reply)
1161 {
1162     int32_t ret = PermissionVerify(SERVER_SET_NODE_DATA_CHANGE_FLAG);
1163     if (ret != SOFTBUS_OK) {
1164         COMM_LOGE(COMM_SVC, "permission verification failed");
1165         return ret;
1166     }
1167     const char *clientName = data.ReadCString();
1168     if (clientName == nullptr) {
1169         COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag read clientName failed!");
1170         return SOFTBUS_IPC_ERR;
1171     }
1172     const char *networkId = data.ReadCString();
1173     if (networkId == nullptr) {
1174         COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag read networkId failed!");
1175         return SOFTBUS_IPC_ERR;
1176     }
1177     uint16_t changeFlag;
1178     if (!data.ReadUint16(changeFlag)) {
1179         COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag read key failed!");
1180         return SOFTBUS_IPC_ERR;
1181     }
1182     int32_t retReply = SetNodeDataChangeFlag(clientName, networkId, changeFlag);
1183     if (!reply.WriteInt32(retReply)) {
1184         COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag write reply failed!");
1185         return SOFTBUS_IPC_ERR;
1186     }
1187     return SOFTBUS_OK;
1188 }
1189 
RegDataLevelChangeCbInner(MessageParcel & data,MessageParcel & reply)1190 int32_t SoftBusServerStub::RegDataLevelChangeCbInner(MessageParcel &data, MessageParcel &reply)
1191 {
1192 #ifndef ENHANCED_FLAG
1193     (void)data;
1194     (void)reply;
1195     (void)DB_PACKAGE_NAME;
1196     return SOFTBUS_FUNC_NOT_SUPPORT;
1197 #else
1198     int32_t ret = PermissionVerify(SERVER_REG_DATA_LEVEL_CHANGE_CB);
1199     if (ret != SOFTBUS_OK) {
1200         COMM_LOGE(COMM_SVC, "permission verification failed");
1201         return ret;
1202     }
1203     const char *pkgName = data.ReadCString();
1204     if (pkgName == nullptr) {
1205         COMM_LOGE(COMM_SVC, "RegDataLevelChangeCbInner read pkgName failed!");
1206         return SOFTBUS_IPC_ERR;
1207     }
1208     if (strcmp(DB_PACKAGE_NAME, pkgName) != 0) {
1209         COMM_LOGE(COMM_SVC, "RegDataLevelChangeCbInner read pkgName invalid!");
1210         return SOFTBUS_INVALID_PARAM;
1211     }
1212     int32_t retReply = RegDataLevelChangeCb(pkgName);
1213     if (!reply.WriteInt32(retReply)) {
1214         COMM_LOGE(COMM_SVC, "RegDataLevelChangeCbInner write reply failed!");
1215         return SOFTBUS_IPC_ERR;
1216     }
1217     return SOFTBUS_OK;
1218 #endif
1219 }
1220 
UnregDataLevelChangeCbInner(MessageParcel & data,MessageParcel & reply)1221 int32_t SoftBusServerStub::UnregDataLevelChangeCbInner(MessageParcel &data, MessageParcel &reply)
1222 {
1223 #ifndef ENHANCED_FLAG
1224     (void)data;
1225     (void)reply;
1226     (void)DB_PACKAGE_NAME;
1227     return SOFTBUS_FUNC_NOT_SUPPORT;
1228 #else
1229     int32_t ret = PermissionVerify(SERVER_UNREG_DATA_LEVEL_CHANGE_CB);
1230     if (ret != SOFTBUS_OK) {
1231         COMM_LOGE(COMM_SVC, "permission verification failed");
1232         return ret;
1233     }
1234     const char *pkgName = data.ReadCString();
1235     if (pkgName == nullptr) {
1236         COMM_LOGE(COMM_SVC, "UnregDataLevelChangeCbInner read pkgName failed!");
1237         return SOFTBUS_IPC_ERR;
1238     }
1239     if (strcmp(DB_PACKAGE_NAME, pkgName) != 0) {
1240         COMM_LOGE(COMM_SVC, "UnregDataLevelChangeCbInner read pkgName invalid!");
1241         return SOFTBUS_INVALID_PARAM;
1242     }
1243     int32_t retReply = UnregDataLevelChangeCb(pkgName);
1244     if (!reply.WriteInt32(retReply)) {
1245         COMM_LOGE(COMM_SVC, "UnregDataLevelChangeCbInner write reply failed!");
1246         return SOFTBUS_IPC_ERR;
1247     }
1248     return SOFTBUS_OK;
1249 #endif
1250 }
1251 
SetDataLevelInner(MessageParcel & data,MessageParcel & reply)1252 int32_t SoftBusServerStub::SetDataLevelInner(MessageParcel &data, MessageParcel &reply)
1253 {
1254 #ifndef ENHANCED_FLAG
1255     (void)data;
1256     (void)reply;
1257     return SOFTBUS_FUNC_NOT_SUPPORT;
1258 #else
1259     int32_t ret = PermissionVerify(SERVER_SET_DATA_LEVEL);
1260     if (ret != SOFTBUS_OK) {
1261         COMM_LOGE(COMM_SVC, "permission verification failed");
1262         return ret;
1263     }
1264     DataLevel *dataLevel = (DataLevel*)data.ReadRawData(sizeof(DataLevel));
1265     if (dataLevel == nullptr) {
1266         COMM_LOGE(COMM_SVC, "SetDataLevelInner read networkid failed!");
1267         return SOFTBUS_IPC_ERR;
1268     }
1269 
1270     int32_t retReply = SetDataLevel(dataLevel);
1271     if (!reply.WriteInt32(retReply)) {
1272         COMM_LOGE(COMM_SVC, "SetDataLevelInner write reply failed!");
1273         return SOFTBUS_IPC_ERR;
1274     }
1275     return SOFTBUS_OK;
1276 #endif
1277 }
1278 
StartTimeSyncInner(MessageParcel & data,MessageParcel & reply)1279 int32_t SoftBusServerStub::StartTimeSyncInner(MessageParcel &data, MessageParcel &reply)
1280 {
1281     COMM_LOGD(COMM_SVC, "enter");
1282     const char *pkgName = data.ReadCString();
1283     if (pkgName == nullptr) {
1284         COMM_LOGE(COMM_SVC, "StartTimeSyncInner read pkgName failed!");
1285         return SOFTBUS_IPC_ERR;
1286     }
1287     uint32_t code = SERVER_START_TIME_SYNC;
1288     SoftbusRecordCalledApiInfo(pkgName, code);
1289     const char *targetNetworkId = data.ReadCString();
1290     if (targetNetworkId == nullptr) {
1291         COMM_LOGE(COMM_SVC, "StartTimeSyncInner read targetNetworkId failed!");
1292         return SOFTBUS_IPC_ERR;
1293     }
1294     int32_t accuracy;
1295     if (!data.ReadInt32(accuracy)) {
1296         COMM_LOGE(COMM_SVC, "StartTimeSyncInner read accuracy failed!");
1297         return SOFTBUS_IPC_ERR;
1298     }
1299     int32_t period;
1300     if (!data.ReadInt32(period)) {
1301         COMM_LOGE(COMM_SVC, "StartTimeSyncInner read period failed!");
1302         return SOFTBUS_IPC_ERR;
1303     }
1304     int32_t retReply = StartTimeSync(pkgName, targetNetworkId, accuracy, period);
1305     if (!reply.WriteInt32(retReply)) {
1306         COMM_LOGE(COMM_SVC, "StartTimeSyncInner write reply failed!");
1307         return SOFTBUS_IPC_ERR;
1308     }
1309     return SOFTBUS_OK;
1310 }
1311 
StopTimeSyncInner(MessageParcel & data,MessageParcel & reply)1312 int32_t SoftBusServerStub::StopTimeSyncInner(MessageParcel &data, MessageParcel &reply)
1313 {
1314     COMM_LOGD(COMM_SVC, "enter");
1315     const char *pkgName = data.ReadCString();
1316     if (pkgName == nullptr) {
1317         COMM_LOGE(COMM_SVC, "StopTimeSyncInner read pkgName failed!");
1318         return SOFTBUS_IPC_ERR;
1319     }
1320     uint32_t code = SERVER_STOP_TIME_SYNC;
1321     SoftbusRecordCalledApiInfo(pkgName, code);
1322     const char *targetNetworkId = data.ReadCString();
1323     if (targetNetworkId == nullptr) {
1324         COMM_LOGE(COMM_SVC, "StopTimeSyncInner read targetNetworkId failed!");
1325         return SOFTBUS_IPC_ERR;
1326     }
1327     int32_t retReply = StopTimeSync(pkgName, targetNetworkId);
1328     if (!reply.WriteInt32(retReply)) {
1329         COMM_LOGE(COMM_SVC, "StopTimeSyncInner write reply failed!");
1330         return SOFTBUS_IPC_ERR;
1331     }
1332     return SOFTBUS_OK;
1333 }
1334 
QosReportInner(MessageParcel & data,MessageParcel & reply)1335 int32_t SoftBusServerStub::QosReportInner(MessageParcel &data, MessageParcel &reply)
1336 {
1337     COMM_LOGD(COMM_SVC, "enter");
1338     int32_t channelId;
1339     if (!data.ReadInt32(channelId)) {
1340         COMM_LOGE(COMM_SVC, "QosReportInner read channel Id failed!");
1341         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1342     }
1343     int32_t channelType;
1344     if (!data.ReadInt32(channelType)) {
1345         COMM_LOGE(COMM_SVC, "QosReportInner read channel channel type failed!");
1346         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1347     }
1348     int32_t appType;
1349     if (!data.ReadInt32(appType)) {
1350         COMM_LOGE(COMM_SVC, "QosReportInner read channel appType failed!");
1351         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1352     }
1353     int32_t quality;
1354     if (!data.ReadInt32(quality)) {
1355         COMM_LOGE(COMM_SVC, "QosReportInner read quality failed!");
1356         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1357     }
1358     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
1359     int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
1360     if (ret != SOFTBUS_OK) {
1361         COMM_LOGE(COMM_SVC, "Pid can not get qos report, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
1362             callingPid, channelId, ret);
1363         return ret;
1364     }
1365     int32_t retReply = QosReport(channelId, channelType, appType, quality);
1366     if (!reply.WriteInt32(retReply)) {
1367         COMM_LOGE(COMM_SVC, "QosReportInner write reply failed!");
1368         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1369     }
1370     return SOFTBUS_OK;
1371 }
1372 
StreamStatsInner(MessageParcel & data,MessageParcel & reply)1373 int32_t SoftBusServerStub::StreamStatsInner(MessageParcel &data, MessageParcel &reply)
1374 {
1375     int32_t channelId;
1376     if (!data.ReadInt32(channelId)) {
1377         COMM_LOGE(COMM_SVC, "StreamStatsInner read channelId fail");
1378         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1379     }
1380     int32_t channelType;
1381     if (!data.ReadInt32(channelType)) {
1382         COMM_LOGE(COMM_SVC, "StreamStatsInner read channelType fail");
1383         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1384     }
1385     StreamSendStats *stats = const_cast<StreamSendStats *>(
1386         reinterpret_cast<const StreamSendStats *>(data.ReadRawData(sizeof(StreamSendStats))));
1387     if (stats == nullptr) {
1388         COMM_LOGE(COMM_SVC, "read StreamSendStats fail, stats is nullptr");
1389         return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
1390     }
1391     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
1392     int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
1393     if (ret != SOFTBUS_OK) {
1394         COMM_LOGE(COMM_SVC, "Pid can not get stream stats, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
1395             callingPid, channelId, ret);
1396         return ret;
1397     }
1398     int32_t retReply = StreamStats(channelId, channelType, stats);
1399     if (!reply.WriteInt32(retReply)) {
1400         COMM_LOGE(COMM_SVC, "StreamStatsInner write reply fail");
1401         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1402     }
1403     return SOFTBUS_OK;
1404 }
1405 
RippleStatsInner(MessageParcel & data,MessageParcel & reply)1406 int32_t SoftBusServerStub::RippleStatsInner(MessageParcel &data, MessageParcel &reply)
1407 {
1408     int32_t channelId;
1409     if (!data.ReadInt32(channelId)) {
1410         COMM_LOGE(COMM_SVC, "rippleStatsInner read channelId fail");
1411         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1412     }
1413     int32_t channelType;
1414     if (!data.ReadInt32(channelType)) {
1415         COMM_LOGE(COMM_SVC, "rippleStatsInner read channelType fail");
1416         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1417     }
1418     TrafficStats *stats =
1419         const_cast<TrafficStats *>(reinterpret_cast<const TrafficStats *>(data.ReadRawData(sizeof(TrafficStats))));
1420     if (stats == nullptr) {
1421         COMM_LOGE(COMM_SVC, "read rippleStats fail, stats is nullptr");
1422         return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
1423     }
1424     pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
1425     int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
1426     if (ret != SOFTBUS_OK) {
1427         COMM_LOGE(COMM_SVC, "Pid can not get pipple stats, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
1428             callingPid, channelId, ret);
1429         return ret;
1430     }
1431     int32_t retReply = RippleStats(channelId, channelType, stats);
1432     if (!reply.WriteInt32(retReply)) {
1433         COMM_LOGE(COMM_SVC, "rippleStatsInner write reply fail");
1434         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1435     }
1436     return SOFTBUS_OK;
1437 }
1438 
GrantPermissionInner(MessageParcel & data,MessageParcel & reply)1439 int32_t SoftBusServerStub::GrantPermissionInner(MessageParcel &data, MessageParcel &reply)
1440 {
1441     int32_t uid = 0;
1442     int32_t pid = 0;
1443     const char *sessionName = nullptr;
1444     uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
1445     int32_t ret = SoftBusCheckDynamicPermission(callingTokenId);
1446     if (ret != SOFTBUS_OK) {
1447         COMM_LOGE(COMM_SVC, "GrantPermissionInner check permission failed. ret=%{public}d!", ret);
1448         goto EXIT;
1449     }
1450 
1451     uid = data.ReadInt32();
1452     pid = data.ReadInt32();
1453     sessionName = data.ReadCString();
1454     if (sessionName == nullptr) {
1455         COMM_LOGE(COMM_SVC, "GrantPermissionInner read sessionName failed!");
1456         goto EXIT;
1457     }
1458     ret = GrantTransPermission(uid, pid, sessionName);
1459 EXIT:
1460     if (!reply.WriteInt32(ret)) {
1461         COMM_LOGE(COMM_SVC, "GrantPermissionInner write reply failed!");
1462         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1463     }
1464     return SOFTBUS_OK;
1465 }
1466 
RemovePermissionInner(MessageParcel & data,MessageParcel & reply)1467 int32_t SoftBusServerStub::RemovePermissionInner(MessageParcel &data, MessageParcel &reply)
1468 {
1469     const char *sessionName = nullptr;
1470     uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
1471     int32_t ret = SoftBusCheckDynamicPermission(callingTokenId);
1472     if (ret != SOFTBUS_OK) {
1473         COMM_LOGE(COMM_SVC, "RemovePermissionInner check permission failed. ret=%{public}d!", ret);
1474         goto EXIT;
1475     }
1476 
1477     sessionName = data.ReadCString();
1478     if (sessionName == nullptr) {
1479         COMM_LOGE(COMM_SVC, "RemovePermissionInner read sessionName failed!");
1480         goto EXIT;
1481     }
1482     ret = RemoveTransPermission(sessionName);
1483 EXIT:
1484     if (!reply.WriteInt32(ret)) {
1485         COMM_LOGE(COMM_SVC, "RemovePermissionInner write reply failed!");
1486         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1487     }
1488     return SOFTBUS_OK;
1489 }
1490 
PublishLNNInner(MessageParcel & data,MessageParcel & reply)1491 int32_t SoftBusServerStub::PublishLNNInner(MessageParcel &data, MessageParcel &reply)
1492 {
1493     COMM_LOGD(COMM_SVC, "enter");
1494     const char *clientName = data.ReadCString();
1495     COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1496 
1497     PublishInfo info = {0};
1498     int32_t value = 0;
1499     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(info.publishId), SOFTBUS_IPC_ERR, COMM_SVC,
1500         "read publishId failed");
1501     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read mode failed");
1502     COMM_CHECK_AND_RETURN_RET_LOGE(value == DISCOVER_MODE_PASSIVE || value == DISCOVER_MODE_ACTIVE,
1503         SOFTBUS_INVALID_PARAM, COMM_SVC, "mode invalid");
1504     info.mode = static_cast<DiscoverMode>(value);
1505     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read medium failed");
1506     COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < MEDIUM_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC,
1507         "medium invalid");
1508     info.medium = static_cast<ExchangeMedium>(value);
1509     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read freq failed");
1510     COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < FREQ_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC, "freq invalid");
1511     info.freq = static_cast<ExchangeFreq>(value);
1512     info.capability = data.ReadCString();
1513     COMM_CHECK_AND_RETURN_RET_LOGE(info.capability != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capability failed");
1514     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadUint32(info.dataLen), SOFTBUS_IPC_ERR, COMM_SVC, "read dataLen failed");
1515     if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
1516         const char *capabilityData = data.ReadCString();
1517         COMM_CHECK_AND_RETURN_RET_LOGE(capabilityData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capaData failed");
1518         COMM_CHECK_AND_RETURN_RET_LOGE(strlen(capabilityData) == info.dataLen, SOFTBUS_INVALID_PARAM, COMM_SVC,
1519             "capabilityData invalid");
1520         info.capabilityData = const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(capabilityData));
1521     } else {
1522         info.capabilityData = nullptr;
1523         info.dataLen = 0;
1524     }
1525     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.ranging), SOFTBUS_IPC_ERR, COMM_SVC, "read ranging failed");
1526 
1527     int32_t retReply = PublishLNN(clientName, &info);
1528     COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1529     return SOFTBUS_OK;
1530 }
1531 
StopPublishLNNInner(MessageParcel & data,MessageParcel & reply)1532 int32_t SoftBusServerStub::StopPublishLNNInner(MessageParcel &data, MessageParcel &reply)
1533 {
1534     COMM_LOGD(COMM_SVC, "enter");
1535     const char *clientName = data.ReadCString();
1536     COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1537 
1538     int32_t publishId = 0;
1539     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(publishId), SOFTBUS_IPC_ERR, COMM_SVC, "read publishId failed");
1540 
1541     int32_t retReply = StopPublishLNN(clientName, publishId);
1542     COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1543     return SOFTBUS_OK;
1544 }
1545 
RefreshLNNInner(MessageParcel & data,MessageParcel & reply)1546 int32_t SoftBusServerStub::RefreshLNNInner(MessageParcel &data, MessageParcel &reply)
1547 {
1548     COMM_LOGD(COMM_SVC, "enter");
1549     const char *clientName = data.ReadCString();
1550     COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1551 
1552     SubscribeInfo info = {0};
1553     int32_t value = 0;
1554     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(info.subscribeId), SOFTBUS_IPC_ERR, COMM_SVC,
1555         "read subscribeId failed");
1556     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read mode failed");
1557     COMM_CHECK_AND_RETURN_RET_LOGE(value == DISCOVER_MODE_PASSIVE || value == DISCOVER_MODE_ACTIVE,
1558         SOFTBUS_INVALID_PARAM, COMM_SVC, "mode invalid");
1559     info.mode = static_cast<DiscoverMode>(value);
1560     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read medium failed");
1561     COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < MEDIUM_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC,
1562         "medium invalid");
1563     info.medium = static_cast<ExchangeMedium>(value);
1564     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read freq failed");
1565     COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < FREQ_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC, "freq invalid");
1566     info.freq = static_cast<ExchangeFreq>(value);
1567     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.isSameAccount), SOFTBUS_IPC_ERR, COMM_SVC,
1568         "read isSameAccount failed");
1569     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.isWakeRemote), SOFTBUS_IPC_ERR, COMM_SVC,
1570         "read isWakeRemote failed");
1571 
1572     info.capability = data.ReadCString();
1573     COMM_CHECK_AND_RETURN_RET_LOGE(info.capability != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capability failed");
1574     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadUint32(info.dataLen), SOFTBUS_IPC_ERR, COMM_SVC, "read dataLen failed");
1575     if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
1576         const char *capabilityData = data.ReadCString();
1577         COMM_CHECK_AND_RETURN_RET_LOGE(capabilityData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capaData failed");
1578         COMM_CHECK_AND_RETURN_RET_LOGE(strlen(capabilityData) == info.dataLen, SOFTBUS_INVALID_PARAM, COMM_SVC,
1579             "capabilityData invalid");
1580         info.capabilityData = const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(capabilityData));
1581     } else {
1582         info.capabilityData = nullptr;
1583         info.dataLen = 0;
1584     }
1585 
1586     int32_t retReply = RefreshLNN(clientName, &info);
1587     COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1588     return SOFTBUS_OK;
1589 }
1590 
StopRefreshLNNInner(MessageParcel & data,MessageParcel & reply)1591 int32_t SoftBusServerStub::StopRefreshLNNInner(MessageParcel &data, MessageParcel &reply)
1592 {
1593     COMM_LOGD(COMM_SVC, "enter");
1594     const char *clientName = data.ReadCString();
1595     COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1596 
1597     int32_t refreshId = 0;
1598     COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(refreshId), SOFTBUS_IPC_ERR, COMM_SVC, "read refreshId failed");
1599 
1600     int32_t retReply = StopRefreshLNN(clientName, refreshId);
1601     COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1602     return SOFTBUS_OK;
1603 }
1604 
ActiveMetaNodeInner(MessageParcel & data,MessageParcel & reply)1605 int32_t SoftBusServerStub::ActiveMetaNodeInner(MessageParcel &data, MessageParcel &reply)
1606 {
1607     COMM_LOGD(COMM_SVC, "enter");
1608     int32_t ret = PermissionVerify(SERVER_ACTIVE_META_NODE);
1609     if (ret != SOFTBUS_OK) {
1610         COMM_LOGE(COMM_SVC, "permission verification failed");
1611         return ret;
1612     }
1613     MetaNodeConfigInfo *info = const_cast<MetaNodeConfigInfo *>(
1614         reinterpret_cast<const MetaNodeConfigInfo *>(data.ReadRawData(sizeof(MetaNodeConfigInfo))));
1615     if (info == nullptr) {
1616         COMM_LOGE(COMM_SVC, "ActiveMetaNode read meta node config info failed!");
1617         return SOFTBUS_IPC_ERR;
1618     }
1619     char metaNodeId[NETWORK_ID_BUF_LEN] = { 0 };
1620     int32_t retReply = ActiveMetaNode(info, metaNodeId);
1621 
1622     if (!reply.WriteCString(metaNodeId)) {
1623         COMM_LOGE(COMM_SVC, "ActiveMetaNode write meta node id failed!");
1624         return SOFTBUS_IPC_ERR;
1625     }
1626     COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1627     return SOFTBUS_OK;
1628 }
1629 
DeactiveMetaNodeInner(MessageParcel & data,MessageParcel & reply)1630 int32_t SoftBusServerStub::DeactiveMetaNodeInner(MessageParcel &data, MessageParcel &reply)
1631 {
1632     COMM_LOGD(COMM_SVC, "enter");
1633     int32_t ret = PermissionVerify(SERVER_DEACTIVE_META_NODE);
1634     if (ret != SOFTBUS_OK) {
1635         COMM_LOGE(COMM_SVC, "permission verification failed");
1636         return ret;
1637     }
1638     const char *metaNodeId = reinterpret_cast<const char *>(data.ReadCString());
1639     if (metaNodeId == nullptr) {
1640         COMM_LOGE(COMM_SVC, "DeactiveMetaNode read meta node id failed!");
1641         return SOFTBUS_IPC_ERR;
1642     }
1643     ret = DeactiveMetaNode(metaNodeId);
1644     if (ret != SOFTBUS_OK) {
1645         return ret;
1646     }
1647     return SOFTBUS_OK;
1648 }
1649 
GetAllMetaNodeInfoInner(MessageParcel & data,MessageParcel & reply)1650 int32_t SoftBusServerStub::GetAllMetaNodeInfoInner(MessageParcel &data, MessageParcel &reply)
1651 {
1652     COMM_LOGD(COMM_SVC, "enter");
1653     int32_t infoNum;
1654     MetaNodeInfo infos[MAX_META_NODE_NUM];
1655     int32_t ret = PermissionVerify(SERVER_GET_ALL_META_NODE_INFO);
1656     if (ret != SOFTBUS_OK) {
1657         COMM_LOGE(COMM_SVC, "permission verification failed");
1658         return ret;
1659     }
1660     if (!data.ReadInt32(infoNum)) {
1661         COMM_LOGE(COMM_SVC, "GetAllMetaNodeInfo read infoNum failed!");
1662         return SOFTBUS_IPC_ERR;
1663     }
1664     if ((uint32_t)infoNum > MAX_META_NODE_NUM) {
1665         COMM_LOGE(COMM_SVC, "invalid param, infoNum=%{public}d, maxNum=%{public}d", infoNum, MAX_META_NODE_NUM);
1666         return SOFTBUS_IPC_ERR;
1667     }
1668     ret = GetAllMetaNodeInfo(infos, &infoNum);
1669     if (ret != SOFTBUS_OK) {
1670         return ret;
1671     }
1672     if (!reply.WriteInt32(infoNum)) {
1673         COMM_LOGE(COMM_SVC, "GetAllMetaNodeInfo write infoNum failed!");
1674         return SOFTBUS_IPC_ERR;
1675     }
1676     if (infoNum > 0 && !reply.WriteRawData(infos, infoNum * sizeof(MetaNodeInfo))) {
1677         COMM_LOGE(COMM_SVC, "GetAllMetaNodeInfo write meta node info failed!");
1678         return SOFTBUS_IPC_ERR;
1679     }
1680     return SOFTBUS_OK;
1681 }
1682 
ShiftLNNGearInner(MessageParcel & data,MessageParcel & reply)1683 int32_t SoftBusServerStub::ShiftLNNGearInner(MessageParcel &data, MessageParcel &reply)
1684 {
1685     COMM_LOGD(COMM_SVC, "enter");
1686     const char *targetNetworkId = nullptr;
1687     const GearMode *mode = nullptr;
1688     int32_t ret = PermissionVerify(SERVER_SHIFT_LNN_GEAR);
1689     if (ret != SOFTBUS_OK) {
1690         COMM_LOGE(COMM_SVC, "permission verification failed");
1691         return ret;
1692     }
1693     const char *pkgName = data.ReadCString();
1694     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1695         COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read pkgName failed!");
1696         return SOFTBUS_TRANS_PROXY_WRITECSTRING_FAILED;
1697     }
1698     uint32_t code = SERVER_SHIFT_LNN_GEAR;
1699     SoftbusRecordCalledApiInfo(pkgName, code);
1700     const char *callerId = data.ReadCString();
1701     if (callerId == nullptr || strnlen(callerId, CALLER_ID_MAX_LEN) >= CALLER_ID_MAX_LEN) {
1702         COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read callerId failed!");
1703         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1704     }
1705     if (!data.ReadBool()) {
1706         targetNetworkId = data.ReadCString();
1707         if (targetNetworkId == nullptr || strnlen(targetNetworkId, NETWORK_ID_BUF_LEN) != NETWORK_ID_BUF_LEN - 1) {
1708             COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read targetNetworkId failed!");
1709             return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1710         }
1711     }
1712     mode = reinterpret_cast<const GearMode *>(data.ReadRawData(sizeof(GearMode)));
1713     if (mode == nullptr) {
1714         COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read mode failed!");
1715         return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
1716     }
1717     int32_t retReply = ShiftLNNGear(pkgName, callerId, targetNetworkId, mode);
1718     if (!reply.WriteInt32(retReply)) {
1719         COMM_LOGE(COMM_SVC, "ShiftLNNGearInner write reply failed!");
1720         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1721     }
1722     return SOFTBUS_OK;
1723 }
1724 
TriggerRangeForMsdpInner(MessageParcel & data,MessageParcel & reply)1725 int32_t SoftBusServerStub::TriggerRangeForMsdpInner(MessageParcel &data, MessageParcel &reply)
1726 {
1727     COMM_LOGD(COMM_SVC, "enter");
1728     const RangeConfig *config = nullptr;
1729     int32_t ret = PermissionVerify(SERVER_TRIGGER_RANGE_FOR_MSDP);
1730     if (ret != SOFTBUS_OK) {
1731         COMM_LOGE(COMM_SVC, "permission verification failed");
1732         return ret;
1733     }
1734     const char *pkgName = data.ReadCString();
1735     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1736         COMM_LOGE(COMM_SVC, "read pkgName failed!");
1737         return SOFTBUS_TRANS_PROXY_WRITECSTRING_FAILED;
1738     }
1739     uint32_t code = SERVER_TRIGGER_RANGE_FOR_MSDP;
1740     SoftbusRecordCalledApiInfo(pkgName, code);
1741     config = reinterpret_cast<const RangeConfig *>(data.ReadRawData(sizeof(RangeConfig)));
1742     if (config == nullptr) {
1743         COMM_LOGE(COMM_SVC, "read config data failed!");
1744         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1745     }
1746     int32_t retReply = TriggerRangeForMsdp(pkgName, config);
1747     if (!reply.WriteInt32(retReply)) {
1748         COMM_LOGE(COMM_SVC, "write reply failed!");
1749         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1750     }
1751     return SOFTBUS_OK;
1752 }
1753 
StopRangeForMsdpInner(MessageParcel & data,MessageParcel & reply)1754 int32_t SoftBusServerStub::StopRangeForMsdpInner(MessageParcel &data, MessageParcel &reply)
1755 {
1756     COMM_LOGD(COMM_SVC, "enter");
1757     const RangeConfig *config = nullptr;
1758     int32_t ret = PermissionVerify(SERVER_STOP_RANGE_FOR_MSDP);
1759     if (ret != SOFTBUS_OK) {
1760         COMM_LOGE(COMM_SVC, "permission verification failed");
1761         return ret;
1762     }
1763     const char *pkgName = data.ReadCString();
1764     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1765         COMM_LOGE(COMM_SVC, "read pkgName failed!");
1766         return SOFTBUS_TRANS_PROXY_WRITECSTRING_FAILED;
1767     }
1768     uint32_t code = SERVER_STOP_RANGE_FOR_MSDP;
1769     SoftbusRecordCalledApiInfo(pkgName, code);
1770     config = reinterpret_cast<const RangeConfig *>(data.ReadRawData(sizeof(RangeConfig)));
1771     if (config == nullptr) {
1772         COMM_LOGE(COMM_SVC, "read config data failed!");
1773         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1774     }
1775     int32_t retReply = StopRangeForMsdp(pkgName, config);
1776     if (!reply.WriteInt32(retReply)) {
1777         COMM_LOGE(COMM_SVC, "write reply failed!");
1778         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1779     }
1780     return SOFTBUS_OK;
1781 }
1782 
RegRangeCbForMsdpInner(MessageParcel & data,MessageParcel & reply)1783 int32_t SoftBusServerStub::RegRangeCbForMsdpInner(MessageParcel &data, MessageParcel &reply)
1784 {
1785     COMM_LOGI(COMM_SVC, "enter");
1786 #ifndef ENHANCED_FLAG
1787     (void)data;
1788     (void)reply;
1789     (void)MSDP_PACKAGE_NAME;
1790     return SOFTBUS_FUNC_NOT_SUPPORT;
1791 #else
1792     int32_t ret = PermissionVerify(SERVER_REG_RANGE_CB_FOR_MSDP);
1793     if (ret != SOFTBUS_OK) {
1794         COMM_LOGE(COMM_SVC, "permission verification failed");
1795         return ret;
1796     }
1797     const char *pkgName = data.ReadCString();
1798     if (pkgName == nullptr) {
1799         COMM_LOGE(COMM_SVC, "read pkgName failed");
1800         return SOFTBUS_IPC_ERR;
1801     }
1802     if (strcmp(MSDP_PACKAGE_NAME, pkgName) != 0) {
1803         COMM_LOGE(COMM_SVC, "read pkgName invalid");
1804         return SOFTBUS_INVALID_PARAM;
1805     }
1806     int32_t retReply = RegisterRangeCallbackForMsdp(pkgName);
1807     if (!reply.WriteInt32(retReply)) {
1808         COMM_LOGE(COMM_SVC, "write reply failed");
1809         return SOFTBUS_IPC_ERR;
1810     }
1811     return SOFTBUS_OK;
1812 #endif
1813 }
1814 
UnregRangeCbForMsdpInner(MessageParcel & data,MessageParcel & reply)1815 int32_t SoftBusServerStub::UnregRangeCbForMsdpInner(MessageParcel &data, MessageParcel &reply)
1816 {
1817     COMM_LOGI(COMM_SVC, "enter");
1818 #ifndef ENHANCED_FLAG
1819     (void)data;
1820     (void)reply;
1821     (void)MSDP_PACKAGE_NAME;
1822     return SOFTBUS_FUNC_NOT_SUPPORT;
1823 #else
1824     int32_t ret = PermissionVerify(SERVER_UNREG_RANGE_CB_FOR_MSDP);
1825     if (ret != SOFTBUS_OK) {
1826         COMM_LOGE(COMM_SVC, "permission verification failed");
1827         return ret;
1828     }
1829     const char *pkgName = data.ReadCString();
1830     if (pkgName == nullptr) {
1831         COMM_LOGE(COMM_SVC, "read pkgName failed");
1832         return SOFTBUS_IPC_ERR;
1833     }
1834     if (strcmp(MSDP_PACKAGE_NAME, pkgName) != 0) {
1835         COMM_LOGE(COMM_SVC, "read pkgName invalid");
1836         return SOFTBUS_INVALID_PARAM;
1837     }
1838     int32_t retReply = UnregisterRangeCallbackForMsdp(pkgName);
1839     if (!reply.WriteInt32(retReply)) {
1840         COMM_LOGE(COMM_SVC, "write reply failed");
1841         return SOFTBUS_IPC_ERR;
1842     }
1843     return SOFTBUS_OK;
1844 #endif
1845 }
1846 
SyncTrustedRelationShipInner(MessageParcel & data,MessageParcel & reply)1847 int32_t SoftBusServerStub::SyncTrustedRelationShipInner(MessageParcel &data, MessageParcel &reply)
1848 {
1849     COMM_LOGD(COMM_SVC, "enter");
1850     int32_t ret = PermissionVerify(SERVER_SYNC_TRUSTED_RELATION);
1851     if (ret != SOFTBUS_OK) {
1852         COMM_LOGE(COMM_SVC, "permission verification failed");
1853         return ret;
1854     }
1855     const char *pkgName = data.ReadCString();
1856     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1857         COMM_LOGE(COMM_SVC, "read pkgName failed!");
1858         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1859     }
1860     if (strcmp(DM_PACKAGE_NAME, pkgName) != 0) {
1861         COMM_LOGE(COMM_SVC, "read pkgName invalid!");
1862         return SOFTBUS_INVALID_PARAM;
1863     }
1864     SoftbusRecordCalledApiInfo(pkgName, SERVER_SYNC_TRUSTED_RELATION);
1865     const char *msg = data.ReadCString();
1866     if (msg == nullptr) {
1867         COMM_LOGE(COMM_SVC, "read msg failed!");
1868         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1869     }
1870     uint32_t msgLen = data.ReadUint32();
1871     if (msgLen > MSG_MAX_SIZE || msgLen != strlen(msg)) {
1872         COMM_LOGE(COMM_SVC, "msgLen invalid!, msgLen=%{public}u", msgLen);
1873         return SOFTBUS_INVALID_PARAM;
1874     }
1875     int32_t retReply = SyncTrustedRelationShip(pkgName, msg, msgLen);
1876     if (!reply.WriteInt32(retReply)) {
1877         COMM_LOGE(COMM_SVC, "write reply failed");
1878         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1879     }
1880     return SOFTBUS_OK;
1881 }
1882 
GetSoftbusSpecObjectInner(MessageParcel & data,MessageParcel & reply)1883 int32_t SoftBusServerStub::GetSoftbusSpecObjectInner(MessageParcel &data, MessageParcel &reply)
1884 {
1885     sptr<IRemoteObject> object;
1886     int32_t ret = GetSoftbusSpecObject(object);
1887     if (!reply.WriteInt32(ret)) {
1888         COMM_LOGE(COMM_SVC, "GetSoftbusSpecObjectInner write reply failed!");
1889         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1890     }
1891     if (ret == SOFTBUS_OK) {
1892         if (!reply.WriteRemoteObject(object)) {
1893             COMM_LOGE(COMM_SVC, "GetSoftbusSpecObjectInner write object failed!");
1894             return SOFTBUS_TRANS_PROXY_WRITEOBJECT_FAILED;
1895         }
1896     }
1897     return SOFTBUS_OK;
1898 }
1899 
GetBusCenterExObjInner(MessageParcel & data,MessageParcel & reply)1900 int32_t SoftBusServerStub::GetBusCenterExObjInner(MessageParcel &data, MessageParcel &reply)
1901 {
1902     sptr<IRemoteObject> object;
1903     int32_t ret = GetBusCenterExObj(object);
1904     if (!reply.WriteInt32(ret)) {
1905         COMM_LOGE(COMM_SVC, "GetBusCenterExObjInner write reply failed!");
1906         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1907     }
1908     if (ret == SOFTBUS_OK) {
1909         if (!reply.WriteRemoteObject(object)) {
1910             COMM_LOGE(COMM_SVC, "GetBusCenterExObjInner write object failed!");
1911             return SOFTBUS_TRANS_PROXY_WRITEOBJECT_FAILED;
1912         }
1913     }
1914     return SOFTBUS_OK;
1915 }
1916 
ProcessInnerEventInner(MessageParcel & data,MessageParcel & reply)1917 int32_t SoftBusServerStub::ProcessInnerEventInner(MessageParcel &data, MessageParcel &reply)
1918 {
1919     int32_t eventType = 0;
1920     if (!data.ReadInt32(eventType)) {
1921         COMM_LOGE(COMM_SVC, "read eventType failed!");
1922         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1923     }
1924     uint32_t len = 0;
1925     if (!data.ReadUint32(len)) {
1926         COMM_LOGE(COMM_SVC, "read len failed!");
1927         return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
1928     }
1929     auto rawData = data.ReadRawData(len);
1930     if (rawData == NULL) {
1931         COMM_LOGE(COMM_SVC, "read rawData failed!");
1932         return SOFTBUS_IPC_ERR;
1933     }
1934     uint8_t *buf = const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(rawData));
1935     int32_t ret = ProcessInnerEvent(eventType, buf, len);
1936     COMM_CHECK_AND_RETURN_RET_LOGE(
1937         ret == SOFTBUS_OK, ret, COMM_SVC, "process inner event failed! eventType=%{public}d", eventType);
1938     return SOFTBUS_OK;
1939 }
1940 
PrivilegeCloseChannelInner(MessageParcel & data,MessageParcel & reply)1941 int32_t SoftBusServerStub::PrivilegeCloseChannelInner(MessageParcel &data, MessageParcel &reply)
1942 {
1943     COMM_LOGD(COMM_SVC, "enter");
1944     int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid();
1945     if (callingUid != DMS_CALLING_UID) {
1946         COMM_LOGE(COMM_PERM, "uid check failed");
1947         return SOFTBUS_PERMISSION_DENIED;
1948     }
1949     uint64_t callingTokenId = IPCSkeleton::GetCallingTokenID();
1950     int32_t ret = SoftBusCheckDmsServerPermission(callingTokenId);
1951     if (ret != SOFTBUS_OK) {
1952         COMM_LOGE(COMM_SVC, "check permission failed. ret=%{public}d", ret);
1953         if (!reply.WriteInt32(ret)) {
1954             COMM_LOGE(COMM_SVC, "write reply failed!");
1955             return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1956         }
1957         return ret;
1958     }
1959     uint64_t tokenId;
1960     if (!data.ReadUint64(tokenId)) {
1961         COMM_LOGE(COMM_SVC, "read tokenId failed!");
1962         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1963     }
1964     int32_t pid;
1965     if (!data.ReadInt32(pid)) {
1966         COMM_LOGE(COMM_SVC, "read pid failed!");
1967         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1968     }
1969     const char *peerNetworkId = data.ReadCString();
1970     if (peerNetworkId == nullptr) {
1971         COMM_LOGE(COMM_SVC, "network id is null!");
1972         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1973     }
1974     ret = PrivilegeCloseChannel(tokenId, pid, peerNetworkId);
1975     if (!reply.WriteInt32(ret)) {
1976         COMM_LOGE(COMM_SVC, "write reply failed, ret=%{public}d", ret);
1977         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1978     }
1979     return SOFTBUS_OK;
1980 }
1981 
SetDisplayNameInner(MessageParcel & data,MessageParcel & reply)1982 int32_t SoftBusServerStub::SetDisplayNameInner(MessageParcel &data, MessageParcel &reply)
1983 {
1984     COMM_LOGD(COMM_SVC, "enter");
1985     int32_t ret = PermissionVerify(SERVER_SET_DISPLAY_NAME);
1986     if (ret != SOFTBUS_OK) {
1987         COMM_LOGE(COMM_SVC, "permission verification failed");
1988         return ret;
1989     }
1990     const char *pkgName = data.ReadCString();
1991     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1992         COMM_LOGE(COMM_SVC, "read pkgName failed!");
1993         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1994     }
1995     if (strcmp(DM_PACKAGE_NAME, pkgName) != 0) {
1996         COMM_LOGE(COMM_SVC, "read pkgName invalid!");
1997         return SOFTBUS_INVALID_PARAM;
1998     }
1999     SoftbusRecordCalledApiInfo(pkgName, SERVER_SET_DISPLAY_NAME);
2000     const char *nameData = data.ReadCString();
2001     if (nameData == nullptr) {
2002         COMM_LOGE(COMM_SVC, "read nameData failed!");
2003         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
2004     }
2005     uint32_t len = data.ReadUint32();
2006     if (len > MSG_MAX_SIZE || len != strlen(nameData)) {
2007         COMM_LOGE(COMM_SVC, "len invalid!, len=%{public}u", len);
2008         return SOFTBUS_INVALID_PARAM;
2009     }
2010     int32_t retReply = SetDisplayName(pkgName, nameData, len);
2011     if (!reply.WriteInt32(retReply)) {
2012         COMM_LOGE(COMM_SVC, "write reply failed");
2013         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2014     }
2015     return SOFTBUS_OK;
2016 }
2017 
CheckPkgName(const char * pkgName)2018 static int32_t CheckPkgName(const char *pkgName)
2019 {
2020     if (strcmp(pkgName, g_limitPkgName) != 0) {
2021         COMM_LOGE(COMM_SVC, "invalid package name");
2022         return SOFTBUS_INVALID_PARAM;
2023     }
2024     return SOFTBUS_OK;
2025 }
2026 
CreateServerInner(MessageParcel & data,MessageParcel & reply)2027 int32_t SoftBusServerStub::CreateServerInner(MessageParcel &data, MessageParcel &reply)
2028 {
2029     const char *pkgName = data.ReadCString();
2030     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
2031         COMM_LOGE(COMM_SVC, "read pkgName failed!");
2032         return SOFTBUS_IPC_ERR;
2033     }
2034     if (CheckPkgName(pkgName) != SOFTBUS_OK) {
2035         return SOFTBUS_INVALID_PARAM;
2036     }
2037     const char *name = data.ReadCString();
2038     if (name == nullptr || strnlen(name, SESSION_NAME_SIZE_MAX) >= SESSION_NAME_SIZE_MAX) {
2039         COMM_LOGE(COMM_SVC, "read name failed!");
2040         return SOFTBUS_IPC_ERR;
2041     }
2042     int32_t retReply = CreateServer(pkgName, name);
2043     if (!reply.WriteInt32(retReply)) {
2044         COMM_LOGE(COMM_SVC, "write reply failed");
2045         return SOFTBUS_IPC_ERR;
2046     }
2047     return SOFTBUS_OK;
2048 }
2049 
RemoveServerInner(MessageParcel & data,MessageParcel & reply)2050 int32_t SoftBusServerStub::RemoveServerInner(MessageParcel &data, MessageParcel &reply)
2051 {
2052     const char *pkgName = data.ReadCString();
2053     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
2054         COMM_LOGE(COMM_SVC, "read pkgName failed!");
2055         return SOFTBUS_IPC_ERR;
2056     }
2057     if (CheckPkgName(pkgName) != SOFTBUS_OK) {
2058         return SOFTBUS_INVALID_PARAM;
2059     }
2060     const char *name = data.ReadCString();
2061     if (name == nullptr || strnlen(name, SESSION_NAME_SIZE_MAX) >= SESSION_NAME_SIZE_MAX) {
2062         COMM_LOGE(COMM_SVC, "read name failed!");
2063         return SOFTBUS_IPC_ERR;
2064     }
2065     int32_t retReply = RemoveServer(pkgName, name);
2066     if (!reply.WriteInt32(retReply)) {
2067         COMM_LOGE(COMM_SVC, "write reply failed");
2068         return SOFTBUS_IPC_ERR;
2069     }
2070     return SOFTBUS_OK;
2071 }
2072 
ConnectInner(MessageParcel & data,MessageParcel & reply)2073 int32_t SoftBusServerStub::ConnectInner(MessageParcel &data, MessageParcel &reply)
2074 {
2075     const char *pkgName = data.ReadCString();
2076     if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
2077         COMM_LOGE(COMM_SVC, "read pkgName failed!");
2078         return SOFTBUS_IPC_ERR;
2079     }
2080     if (CheckPkgName(pkgName) != SOFTBUS_OK) {
2081         return SOFTBUS_INVALID_PARAM;
2082     }
2083     const char *name = data.ReadCString();
2084     if (name == nullptr || strnlen(name, SESSION_NAME_SIZE_MAX) >= SESSION_NAME_SIZE_MAX) {
2085         COMM_LOGE(COMM_SVC, "read name failed!");
2086         return SOFTBUS_IPC_ERR;
2087     }
2088     Address connectAddress;
2089     const char *address = data.ReadCString();
2090     if (address == nullptr) {
2091         COMM_LOGE(COMM_SVC, "read address fail, address is nullptr");
2092         return SOFTBUS_IPC_ERR;
2093     }
2094     size_t len = strnlen(address, BT_MAC_LEN);
2095     if (len != (BT_MAC_LEN - 1) || strcpy_s(connectAddress.addr.ble.mac, BT_MAC_LEN, address) != EOK) {
2096         COMM_LOGE(COMM_SVC, "read address fail");
2097         return SOFTBUS_IPC_ERR;
2098     }
2099     int32_t addrType = data.ReadInt32();
2100     if (addrType < CONNECTION_ADDR_WLAN || addrType > CONNECTION_ADDR_MAX) {
2101         COMM_LOGE(COMM_SVC, "read addrType fail, addrType= %{public}d", addrType);
2102         return SOFTBUS_IPC_ERR;
2103     }
2104     connectAddress.addrType = static_cast<ConnectionAddrType>(addrType);
2105     int32_t handle = Connect(pkgName, name, &connectAddress);
2106     if (!reply.WriteInt32(handle)) {
2107         COMM_LOGE(COMM_SVC, "write handle failed");
2108         return SOFTBUS_IPC_ERR;
2109     }
2110     return SOFTBUS_OK;
2111 }
2112 
DisconnectInner(MessageParcel & data,MessageParcel & reply)2113 int32_t SoftBusServerStub::DisconnectInner(MessageParcel &data, MessageParcel &reply)
2114 {
2115     uint32_t handle;
2116     if (!data.ReadUint32(handle)) {
2117         COMM_LOGE(COMM_SVC, "read handle failed!");
2118         return SOFTBUS_IPC_ERR;
2119     }
2120     int32_t retReply = Disconnect(handle);
2121     if (!reply.WriteInt32(retReply)) {
2122         COMM_LOGE(COMM_SVC, "write reply failed");
2123         return SOFTBUS_IPC_ERR;
2124     }
2125     return SOFTBUS_OK;
2126 }
2127 
SendInner(MessageParcel & data,MessageParcel & reply)2128 int32_t SoftBusServerStub::SendInner(MessageParcel &data, MessageParcel &reply)
2129 {
2130     uint32_t handle;
2131     if (!data.ReadUint32(handle)) {
2132         COMM_LOGE(COMM_SVC, "read handle failed!");
2133         return SOFTBUS_IPC_ERR;
2134     }
2135     uint32_t len = 0;
2136     if (!data.ReadUint32(len)) {
2137         COMM_LOGE(COMM_SVC, "read len failed!");
2138         return SOFTBUS_IPC_ERR;
2139     }
2140     if (len > GENERAL_SEND_DATA_MAX_LEN) {
2141         COMM_LOGE(COMM_SVC, "len invalid!, len=%{public}u", len);
2142         return SOFTBUS_INVALID_PARAM;
2143     }
2144     auto dataMsg = data.ReadRawData(len);
2145     if (dataMsg == NULL) {
2146         COMM_LOGE(COMM_SVC, "read data failed!");
2147         return SOFTBUS_IPC_ERR;
2148     }
2149     uint8_t *buf = const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(dataMsg));
2150     int32_t retReply = Send(handle, buf, len);
2151     if (!reply.WriteInt32(retReply)) {
2152         COMM_LOGE(COMM_SVC, "write reply failed");
2153         return SOFTBUS_IPC_ERR;
2154     }
2155     return SOFTBUS_OK;
2156 }
2157 
GetPeerDeviceIdInner(MessageParcel & data,MessageParcel & reply)2158 int32_t SoftBusServerStub::GetPeerDeviceIdInner(MessageParcel &data, MessageParcel &reply)
2159 {
2160     uint32_t handle;
2161     if (!data.ReadUint32(handle)) {
2162         COMM_LOGE(COMM_SVC, "read handle failed!");
2163         return SOFTBUS_IPC_ERR;
2164     }
2165     uint32_t len = 0;
2166     if (!data.ReadUint32(len)) {
2167         COMM_LOGE(COMM_SVC, "read len failed!");
2168         return SOFTBUS_IPC_ERR;
2169     }
2170     if (len > BT_MAC_LEN) {
2171         COMM_LOGE(COMM_SVC, "len invalid!, len=%{public}u", len);
2172         return SOFTBUS_INVALID_PARAM;
2173     }
2174     char peerDeviceId[len];
2175     (void)memset_s(peerDeviceId, len, '\0', len);
2176     int32_t retReply = ConnGetPeerDeviceId(handle, peerDeviceId, len);
2177     if (!reply.WriteRawData(peerDeviceId, len)) {
2178         COMM_LOGE(COMM_SVC, "write peerDeviceId failed!");
2179         return SOFTBUS_IPC_ERR;
2180     }
2181     if (!reply.WriteInt32(retReply)) {
2182         COMM_LOGE(COMM_SVC, "write ret failed!");
2183         return SOFTBUS_IPC_ERR;
2184     }
2185     return SOFTBUS_OK;
2186 }
2187 
SoftbusRegisterBrProxyServiceInner(MessageParcel & data,MessageParcel & reply)2188 int32_t SoftBusServerStub::SoftbusRegisterBrProxyServiceInner(MessageParcel &data, MessageParcel &reply)
2189 {
2190     COMM_LOGD(COMM_SVC, "enter");
2191     auto remote = data.ReadRemoteObject();
2192     if (remote == nullptr) {
2193         COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read systemAbilityId failed!");
2194         return SOFTBUS_TRANS_PROXY_REMOTE_NULL;
2195     }
2196     const char *pkgName = data.ReadCString();
2197     if (pkgName == nullptr) {
2198         COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read pkgName failed!");
2199         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
2200     }
2201     uint32_t code = MANAGE_REGISTER_BR_PROXY_SERVICE;
2202     SoftbusRecordCalledApiInfo(pkgName, code);
2203     int32_t retReply = SoftbusRegisterService(pkgName, remote);
2204     if (!reply.WriteInt32(retReply)) {
2205         COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner write reply failed!");
2206         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2207     }
2208     return SOFTBUS_OK;
2209 }
2210 
OpenBrProxyInner(MessageParcel & data,MessageParcel & reply)2211 int32_t SoftBusServerStub::OpenBrProxyInner(MessageParcel &data, MessageParcel &reply)
2212 {
2213     const char *brMac = data.ReadCString();
2214     if (brMac == nullptr) {
2215         COMM_LOGE(COMM_SVC, "[br_proxy] read brMac failed!");
2216         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
2217     }
2218 
2219     const char *uuid = data.ReadCString();
2220     if (uuid == nullptr) {
2221         COMM_LOGE(COMM_SVC, "[br_proxy] read uuid failed!");
2222         return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
2223     }
2224 
2225     int32_t retReply = OpenBrProxy(brMac, uuid);
2226     if (!reply.WriteInt32(retReply)) {
2227         COMM_LOGE(COMM_SVC, "[br_proxy] write reply failed!");
2228         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2229     }
2230     return SOFTBUS_OK;
2231 }
2232 
CloseBrProxyInner(MessageParcel & data,MessageParcel & reply)2233 int32_t SoftBusServerStub::CloseBrProxyInner(MessageParcel &data, MessageParcel &reply)
2234 {
2235     int32_t channelId;
2236     if (!data.ReadInt32(channelId)) {
2237         COMM_LOGE(COMM_SVC, "[br_proxy] read channelId failed!");
2238         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
2239     }
2240 
2241     int32_t retReply = CloseBrProxy(channelId);
2242     if (!reply.WriteInt32(retReply)) {
2243         COMM_LOGE(COMM_SVC, "[br_proxy] write reply failed!");
2244         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2245     }
2246     return SOFTBUS_OK;
2247 }
2248 
SendBrProxyDataInner(MessageParcel & data,MessageParcel & reply)2249 int32_t SoftBusServerStub::SendBrProxyDataInner(MessageParcel &data, MessageParcel &reply)
2250 {
2251     int32_t channelId;
2252     if (!data.ReadInt32(channelId)) {
2253         COMM_LOGE(COMM_SVC, "[br_proxy] read channelId failed!");
2254         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
2255     }
2256 
2257     uint32_t dataLen;
2258     if (!data.ReadUint32(dataLen)) {
2259         COMM_LOGE(COMM_SVC, "[br_proxy] read dataLen failed!");
2260         return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
2261     }
2262 
2263     auto rawData = data.ReadRawData(dataLen);
2264     COMM_CHECK_AND_RETURN_RET_LOGE(rawData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "[br_proxy] read data failed!");
2265     void *dataInfo = const_cast<void *>(rawData);
2266 
2267     int32_t retReply = SendBrProxyData(channelId, (char *)dataInfo, dataLen);
2268     if (!reply.WriteInt32(retReply)) {
2269         COMM_LOGE(COMM_SVC, "[br_proxy] write reply failed!");
2270         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2271     }
2272     return SOFTBUS_OK;
2273 }
2274 
SetBrProxyListenerStateInner(MessageParcel & data,MessageParcel & reply)2275 int32_t SoftBusServerStub::SetBrProxyListenerStateInner(MessageParcel &data, MessageParcel &reply)
2276 {
2277     int32_t channelId;
2278     if (!data.ReadInt32(channelId)) {
2279         COMM_LOGE(COMM_SVC, "[br_proxy] read channelId failed!");
2280         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
2281     }
2282     int32_t type;
2283     if (!data.ReadInt32(type)) {
2284         COMM_LOGE(COMM_SVC, "[br_proxy] read type failed!");
2285         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
2286     }
2287     bool CbEnabled = false;
2288     if (!data.ReadBool(CbEnabled)) {
2289         COMM_LOGE(COMM_SVC, "[br_proxy] read CbEnabled failed");
2290         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
2291     }
2292 
2293     int32_t retReply = SetListenerState(channelId, type, CbEnabled);
2294     if (!reply.WriteInt32(retReply)) {
2295         COMM_LOGE(COMM_SVC, "[br_proxy] write reply failed!");
2296         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2297     }
2298     return SOFTBUS_OK;
2299 }
2300 
GetBrProxyChannelStateInner(MessageParcel & data,MessageParcel & reply)2301 int32_t SoftBusServerStub::GetBrProxyChannelStateInner(MessageParcel &data, MessageParcel &reply)
2302 {
2303     int32_t uid;
2304     if (!data.ReadInt32(uid)) {
2305         COMM_LOGE(COMM_SVC, "[br_proxy] read channelId failed!");
2306         return SOFTBUS_TRANS_PROXY_READINT_FAILED;
2307     }
2308 
2309     bool retReply = IsProxyChannelEnabled(uid);
2310     if (!reply.WriteBool(retReply)) {
2311         COMM_LOGE(COMM_SVC, "[br_proxy] write reply failed!");
2312         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2313     }
2314     return SOFTBUS_OK;
2315 }
2316 
RegisterPushHookInner(MessageParcel & data,MessageParcel & reply)2317 int32_t SoftBusServerStub::RegisterPushHookInner(MessageParcel &data, MessageParcel &reply)
2318 {
2319     int32_t ret = PushRegisterHook();
2320     if (!reply.WriteInt32(ret)) {
2321         COMM_LOGE(COMM_SVC, "[br_proxy] write reply failed!");
2322         return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
2323     }
2324     return SOFTBUS_OK;
2325 }
2326 
LabelTransformation(uint32_t code)2327 static const char* LabelTransformation(uint32_t code)
2328 {
2329     if (code == SERVER_JOIN_LNN) {
2330         return SERVER_JOIN_LNN_NAME;
2331     } else if (code == SERVER_LEAVE_LNN) {
2332         return SERVER_LEAVE_LNN_NAME;
2333     } else if (code == SERVER_SET_NODE_DATA_CHANGE_FLAG) {
2334         return SERVER_SET_NODE_DATA_CHANGE_FLAG_NAME;
2335     } else if (code == SERVER_ACTIVE_META_NODE) {
2336         return SERVER_ACTIVE_META_NODE_NAME;
2337     } else if (code == SERVER_DEACTIVE_META_NODE) {
2338         return SERVER_DEACTIVE_META_NODE_NAME;
2339     } else if (code == SERVER_GET_ALL_META_NODE_INFO) {
2340         return SERVER_GET_ALL_META_NODE_INFO_NAME;
2341     } else if (code == SERVER_SHIFT_LNN_GEAR) {
2342         return SERVER_SHIFT_LNN_GEAR_NAME;
2343     } else if (code == SERVER_SYNC_TRUSTED_RELATION) {
2344         return SERVER_SYNC_TRUSTED_RELATION_NAME;
2345     } else if (code == SERVER_SET_DISPLAY_NAME) {
2346         return SERVER_SET_DISPLAY_NAME_NAME;
2347     } else if (code == SERVER_SET_DATA_LEVEL) {
2348         return SERVER_SET_DATA_LEVEL_NAME;
2349     } else if (code == SERVER_REG_DATA_LEVEL_CHANGE_CB) {
2350         return SERVER_REG_DATA_LEVEL_CHANGE_CB_NAME;
2351     } else if (code == SERVER_UNREG_DATA_LEVEL_CHANGE_CB) {
2352         return SERVER_UNREG_DATA_LEVEL_CHANGE_CB_NAME;
2353     } else if (code == SERVER_TRIGGER_RANGE_FOR_MSDP) {
2354         return SERVER_TRIGGER_RANGE_FOR_MSDP_NAME;
2355     } else if (code == SERVER_STOP_RANGE_FOR_MSDP) {
2356         return SERVER_STOP_RANGE_FOR_MSDP_NAME;
2357     } else if (code == SERVER_REG_RANGE_CB_FOR_MSDP) {
2358         return SERVER_REG_RANGE_CB_FOR_MSDP_NAME;
2359     } else if (code == SERVER_UNREG_RANGE_CB_FOR_MSDP) {
2360         return SERVER_UNREG_RANGE_CB_FOR_MSDP_NAME;
2361     }
2362     return nullptr;
2363 }
2364 
PermissionVerify(uint32_t code)2365 int32_t SoftBusServerStub::PermissionVerify(uint32_t code)
2366 {
2367     uint32_t tokenId = IPCSkeleton::GetCallingTokenID();
2368     auto tokenType = OHOS::Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(
2369         static_cast<OHOS::Security::AccessToken::AccessTokenID>(tokenId));
2370     if (tokenType != OHOS::Security::AccessToken::ATokenTypeEnum::TOKEN_NATIVE) {
2371         COMM_LOGE(COMM_SVC, "not native call");
2372         return SOFTBUS_PERMISSION_DENIED;
2373     }
2374     OHOS::Security::AccessToken::NativeTokenInfo nativeTokenInfo;
2375     int32_t ret = OHOS::Security::AccessToken::AccessTokenKit::GetNativeTokenInfo(tokenId, nativeTokenInfo);
2376     if (ret != SOFTBUS_OK) {
2377         COMM_LOGE(COMM_SVC, "get nativeTokenInfo fail, ret=%{public}d", ret);
2378         return SOFTBUS_PERMISSION_DENIED;
2379     }
2380     const char* tagName = LabelTransformation(code);
2381     if (tagName == nullptr) {
2382         COMM_LOGE(COMM_SVC, "the tag does not add process verification, code=%{public}d", code);
2383         return SOFTBUS_PERMISSION_DENIED;
2384     }
2385     if (CheckLnnPermission(tagName, nativeTokenInfo.processName.c_str()) != SOFTBUS_OK) {
2386         COMM_LOGE(COMM_SVC, "the process does not have permission, code=%{public}u, processName=%{public}s",
2387             code, nativeTokenInfo.processName.c_str());
2388         return SOFTBUS_PERMISSION_DENIED;
2389     }
2390     return SOFTBUS_OK;
2391 }
2392 } // namespace OHOS
2393