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 "access_control.h"
21 #include "ipc_skeleton.h"
22 #include "legacy/softbus_hisysevt_transreporter.h"
23 #include "softbus_access_token_adapter.h"
24 #include "softbus_adapter_mem.h"
25 #include "softbus_permission.h"
26 #include "softbus_server_frame.h"
27 #include "softbus_server_ipc_interface_code.h"
28 #include "trans_channel_common.h"
29 #include "trans_channel_manager.h"
30 #include "trans_log.h"
31 #include "trans_network_statistics.h"
32 #include "trans_session_manager.h"
33
34 #ifdef SUPPORT_BUNDLENAME
35 #include "bundle_mgr_proxy.h"
36 #include "iservice_registry.h"
37 #include "ohos_account_kits.h"
38 #include "os_account_manager.h"
39 #include "system_ability_definition.h"
40 #endif
41
42 #define READ_PARCEL_WITH_RET(parcel, type, data, retVal) \
43 do { \
44 if (!(parcel).Read##type(data)) { \
45 COMM_LOGE(COMM_SVC, "read data failed."); \
46 return (retVal); \
47 } \
48 } while (false) \
49
50 namespace OHOS {
51 namespace {
52 constexpr int32_t MSG_MAX_SIZE = 1024 * 2;
53 constexpr int32_t DMS_CALLING_UID = 5522;
54 static const char *DB_PACKAGE_NAME = "distributeddata-default";
55 static const char *DM_PACKAGE_NAME = "ohos.distributedhardware.devicemanager";
56 static const char *MSDP_PACKAGE_NAME = "ohos.msdp.spatialawareness";
57 }
58
CheckOpenSessionPermission(const SessionParam * param)59 int32_t SoftBusServerStub::CheckOpenSessionPermission(const SessionParam *param)
60 {
61 char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
62 if ((param == nullptr) ||
63 (TransGetPkgNameBySessionName(param->sessionName, pkgName, PKG_NAME_SIZE_MAX) != SOFTBUS_OK)) {
64 COMM_LOGE(COMM_SVC, "OpenSession pararm error or lock mutex or copy pkgName failed");
65 return SOFTBUS_INVALID_PARAM;
66 }
67
68 pid_t callingUid = OHOS::IPCSkeleton::GetCallingUid();
69 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
70 if (CheckTransPermission(callingUid, callingPid, pkgName, param->sessionName, ACTION_OPEN) != SOFTBUS_OK) {
71 COMM_LOGE(COMM_SVC, "OpenSession no permission");
72 return SOFTBUS_PERMISSION_DENIED;
73 }
74
75 if (!CheckUidAndPid(param->sessionName, callingUid, callingPid)) {
76 char *tmpName = NULL;
77 Anonymize(param->sessionName, &tmpName);
78 COMM_LOGE(COMM_SVC, "Check Uid and Pid failed, sessionName=%{public}s", AnonymizeWrapper(tmpName));
79 AnonymizeFree(tmpName);
80 return SOFTBUS_TRANS_CHECK_PID_ERROR;
81 }
82
83 if (CheckTransSecLevel(param->sessionName, param->peerSessionName) != SOFTBUS_OK) {
84 COMM_LOGE(COMM_SVC, "OpenSession sec level invalid");
85 return SOFTBUS_PERMISSION_DENIED;
86 }
87 return SOFTBUS_OK;
88 }
89
CheckChannelPermission(int32_t channelId,int32_t channelType)90 int32_t SoftBusServerStub::CheckChannelPermission(int32_t channelId, int32_t channelType)
91 {
92 char pkgName[PKG_NAME_SIZE_MAX] = { 0 };
93 char sessionName[SESSION_NAME_SIZE_MAX] = { 0 };
94 int32_t ret = SOFTBUS_OK;
95 TransInfo info;
96 info.channelId = channelId;
97 info.channelType = channelType;
98 ret = TransGetNameByChanId(&info, pkgName, sessionName, PKG_NAME_SIZE_MAX, SESSION_NAME_SIZE_MAX);
99 if (ret != SOFTBUS_OK) {
100 COMM_LOGE(COMM_SVC, "ServerCloseChannel invalid channel info");
101 return ret;
102 }
103
104 pid_t callingUid = OHOS::IPCSkeleton::GetCallingUid();
105 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
106 if (CheckTransPermission(callingUid, callingPid, pkgName, sessionName, ACTION_OPEN) != SOFTBUS_OK) {
107 return SOFTBUS_PERMISSION_DENIED;
108 }
109 return SOFTBUS_OK;
110 }
111
SoftbusReportPermissionFaultEvt(uint32_t ipcCode)112 static void SoftbusReportPermissionFaultEvt(uint32_t ipcCode)
113 {
114 if (ipcCode == SERVER_OPEN_SESSION) {
115 SoftbusReportTransErrorEvt(SOFTBUS_ACCESS_TOKEN_DENIED);
116 }
117 }
118
SoftBusServerStub()119 SoftBusServerStub::SoftBusServerStub()
120 {
121 InitMemberFuncMap();
122 InitMemberPermissionMap();
123 }
124
InitMemberFuncMap()125 void SoftBusServerStub::InitMemberFuncMap()
126 {
127 memberFuncMap_[MANAGE_REGISTER_SERVICE] = &SoftBusServerStub::SoftbusRegisterServiceInner;
128 memberFuncMap_[SERVER_CREATE_SESSION_SERVER] = &SoftBusServerStub::CreateSessionServerInner;
129 memberFuncMap_[SERVER_REMOVE_SESSION_SERVER] = &SoftBusServerStub::RemoveSessionServerInner;
130 memberFuncMap_[SERVER_RELEASE_RESOURCES] = &SoftBusServerStub::ReleaseResourcesInner;
131 memberFuncMap_[SERVER_OPEN_SESSION] = &SoftBusServerStub::OpenSessionInner;
132 memberFuncMap_[SERVER_OPEN_AUTH_SESSION] = &SoftBusServerStub::OpenAuthSessionInner;
133 memberFuncMap_[SERVER_NOTIFY_AUTH_SUCCESS] = &SoftBusServerStub::NotifyAuthSuccessInner;
134 memberFuncMap_[SERVER_CLOSE_CHANNEL] = &SoftBusServerStub::CloseChannelInner;
135 memberFuncMap_[SERVER_CLOSE_CHANNEL_STATISTICS] = &SoftBusServerStub::CloseChannelWithStatisticsInner;
136 memberFuncMap_[SERVER_SESSION_SENDMSG] = &SoftBusServerStub::SendMessageInner;
137 memberFuncMap_[SERVER_EVALUATE_QOS] = &SoftBusServerStub::EvaluateQosInner;
138 memberFuncMap_[SERVER_JOIN_LNN] = &SoftBusServerStub::JoinLNNInner;
139 memberFuncMap_[SERVER_LEAVE_LNN] = &SoftBusServerStub::LeaveLNNInner;
140 memberFuncMap_[SERVER_GET_ALL_ONLINE_NODE_INFO] = &SoftBusServerStub::GetAllOnlineNodeInfoInner;
141 memberFuncMap_[SERVER_GET_LOCAL_DEVICE_INFO] = &SoftBusServerStub::GetLocalDeviceInfoInner;
142 memberFuncMap_[SERVER_GET_NODE_KEY_INFO] = &SoftBusServerStub::GetNodeKeyInfoInner;
143 memberFuncMap_[SERVER_SET_NODE_DATA_CHANGE_FLAG] = &SoftBusServerStub::SetNodeDataChangeFlagInner;
144 memberFuncMap_[SERVER_REG_DATA_LEVEL_CHANGE_CB] = &SoftBusServerStub::RegDataLevelChangeCbInner;
145 memberFuncMap_[SERVER_UNREG_DATA_LEVEL_CHANGE_CB] = &SoftBusServerStub::UnregDataLevelChangeCbInner;
146 memberFuncMap_[SERVER_SET_DATA_LEVEL] = &SoftBusServerStub::SetDataLevelInner;
147 memberFuncMap_[SERVER_START_TIME_SYNC] = &SoftBusServerStub::StartTimeSyncInner;
148 memberFuncMap_[SERVER_STOP_TIME_SYNC] = &SoftBusServerStub::StopTimeSyncInner;
149 memberFuncMap_[SERVER_QOS_REPORT] = &SoftBusServerStub::QosReportInner;
150 memberFuncMap_[SERVER_STREAM_STATS] = &SoftBusServerStub::StreamStatsInner;
151 memberFuncMap_[SERVER_GRANT_PERMISSION] = &SoftBusServerStub::GrantPermissionInner;
152 memberFuncMap_[SERVER_REMOVE_PERMISSION] = &SoftBusServerStub::RemovePermissionInner;
153 memberFuncMap_[SERVER_PUBLISH_LNN] = &SoftBusServerStub::PublishLNNInner;
154 memberFuncMap_[SERVER_STOP_PUBLISH_LNN] = &SoftBusServerStub::StopPublishLNNInner;
155 memberFuncMap_[SERVER_REFRESH_LNN] = &SoftBusServerStub::RefreshLNNInner;
156 memberFuncMap_[SERVER_STOP_REFRESH_LNN] = &SoftBusServerStub::StopRefreshLNNInner;
157 memberFuncMap_[SERVER_ACTIVE_META_NODE] = &SoftBusServerStub::ActiveMetaNodeInner;
158 memberFuncMap_[SERVER_DEACTIVE_META_NODE] = &SoftBusServerStub::DeactiveMetaNodeInner;
159 memberFuncMap_[SERVER_GET_ALL_META_NODE_INFO] = &SoftBusServerStub::GetAllMetaNodeInfoInner;
160 memberFuncMap_[SERVER_SHIFT_LNN_GEAR] = &SoftBusServerStub::ShiftLNNGearInner;
161 memberFuncMap_[SERVER_TRIGGER_HB_FOR_RANGE] = &SoftBusServerStub::TriggerHbForMeasureDistanceInner;
162 memberFuncMap_[SERVER_REG_BLE_RANGE_CB] = &SoftBusServerStub::RegBleRangeCbInner;
163 memberFuncMap_[SERVER_UNREG_BLE_RANGE_CB] = &SoftBusServerStub::UnregBleRangeCbInner;
164 memberFuncMap_[SERVER_SYNC_TRUSTED_RELATION] = &SoftBusServerStub::SyncTrustedRelationShipInner;
165 memberFuncMap_[SERVER_RIPPLE_STATS] = &SoftBusServerStub::RippleStatsInner;
166 memberFuncMap_[SERVER_GET_SOFTBUS_SPEC_OBJECT] = &SoftBusServerStub::GetSoftbusSpecObjectInner;
167 memberFuncMap_[SERVER_GET_BUS_CENTER_EX_OBJ] = &SoftBusServerStub::GetBusCenterExObjInner;
168 memberFuncMap_[SERVER_PROCESS_INNER_EVENT] = &SoftBusServerStub::ProcessInnerEventInner;
169 memberFuncMap_[SERVER_PRIVILEGE_CLOSE_CHANNEL] = &SoftBusServerStub::PrivilegeCloseChannelInner;
170 memberFuncMap_[SERVER_SET_DISPLAY_NAME] = &SoftBusServerStub::SetDisplayNameInner;
171 }
172
InitMemberPermissionMap()173 void SoftBusServerStub::InitMemberPermissionMap()
174 {
175 memberPermissionMap_[MANAGE_REGISTER_SERVICE] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
176 memberPermissionMap_[SERVER_CREATE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
177 memberPermissionMap_[SERVER_REMOVE_SESSION_SERVER] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
178 memberPermissionMap_[SERVER_RELEASE_RESOURCES] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
179 memberPermissionMap_[SERVER_OPEN_SESSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
180 memberPermissionMap_[SERVER_OPEN_AUTH_SESSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
181 memberPermissionMap_[SERVER_NOTIFY_AUTH_SUCCESS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
182 memberPermissionMap_[SERVER_CLOSE_CHANNEL] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
183 memberPermissionMap_[SERVER_CLOSE_CHANNEL_STATISTICS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
184 memberPermissionMap_[SERVER_SESSION_SENDMSG] = nullptr;
185 memberPermissionMap_[SERVER_JOIN_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
186 memberPermissionMap_[SERVER_JOIN_METANODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
187 memberPermissionMap_[SERVER_LEAVE_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
188 memberPermissionMap_[SERVER_LEAVE_METANODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
189 memberPermissionMap_[SERVER_GET_ALL_ONLINE_NODE_INFO] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
190 memberPermissionMap_[SERVER_GET_LOCAL_DEVICE_INFO] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
191 memberPermissionMap_[SERVER_GET_NODE_KEY_INFO] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
192 memberPermissionMap_[SERVER_SET_NODE_DATA_CHANGE_FLAG] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
193 memberPermissionMap_[SERVER_REG_DATA_LEVEL_CHANGE_CB] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
194 memberPermissionMap_[SERVER_UNREG_DATA_LEVEL_CHANGE_CB] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
195 memberPermissionMap_[SERVER_SET_DATA_LEVEL] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
196 memberPermissionMap_[SERVER_START_TIME_SYNC] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
197 memberPermissionMap_[SERVER_STOP_TIME_SYNC] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
198 memberPermissionMap_[SERVER_QOS_REPORT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
199 memberPermissionMap_[SERVER_STREAM_STATS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
200 memberPermissionMap_[SERVER_GRANT_PERMISSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
201 memberPermissionMap_[SERVER_REMOVE_PERMISSION] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
202 memberPermissionMap_[SERVER_PUBLISH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
203 memberPermissionMap_[SERVER_STOP_PUBLISH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
204 memberPermissionMap_[SERVER_REFRESH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
205 memberPermissionMap_[SERVER_STOP_REFRESH_LNN] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
206 memberPermissionMap_[SERVER_ACTIVE_META_NODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
207 memberPermissionMap_[SERVER_DEACTIVE_META_NODE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
208 memberPermissionMap_[SERVER_GET_ALL_META_NODE_INFO] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
209 memberPermissionMap_[SERVER_SHIFT_LNN_GEAR] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
210 memberPermissionMap_[SERVER_TRIGGER_HB_FOR_RANGE] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
211 memberPermissionMap_[SERVER_REG_BLE_RANGE_CB] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
212 memberPermissionMap_[SERVER_UNREG_BLE_RANGE_CB] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
213 memberPermissionMap_[SERVER_SYNC_TRUSTED_RELATION] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
214 memberPermissionMap_[SERVER_RIPPLE_STATS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
215 memberPermissionMap_[SERVER_GET_SOFTBUS_SPEC_OBJECT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
216 memberPermissionMap_[SERVER_GET_BUS_CENTER_EX_OBJ] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
217 memberPermissionMap_[SERVER_EVALUATE_QOS] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
218 memberPermissionMap_[SERVER_PROCESS_INNER_EVENT] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
219 memberPermissionMap_[SERVER_PRIVILEGE_CLOSE_CHANNEL] = OHOS_PERMISSION_DISTRIBUTED_DATASYNC;
220 memberPermissionMap_[SERVER_SET_DISPLAY_NAME] = OHOS_PERMISSION_DISTRIBUTED_SOFTBUS_CENTER;
221 }
222
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)223 int32_t SoftBusServerStub::OnRemoteRequest(
224 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
225 {
226 SoftbusRecordCalledApiCnt(code);
227 if (data.ReadInterfaceToken() != GetDescriptor()) {
228 COMM_LOGE(COMM_SVC, "SOFTBUS_SERVER_NOT_INIT ReadInterfaceToken failed!");
229 return SOFTBUS_IPC_ERR;
230 }
231 if (!GetServerIsInit()) {
232 COMM_LOGE(COMM_SVC, "server not init");
233 if (!reply.WriteInt32(SOFTBUS_SERVER_NOT_INIT)) {
234 COMM_LOGE(COMM_SVC, "SOFTBUS_SERVER_NOT_INIT write reply failed!");
235 }
236 return SOFTBUS_IPC_ERR;
237 }
238
239 auto itPerm = memberPermissionMap_.find(code);
240 if (itPerm != memberPermissionMap_.end()) {
241 const char *permission = itPerm->second;
242 uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
243 if ((permission != nullptr) &&
244 (!SoftBusCheckIsAccessAndRecordAccessToken(callingTokenId, permission))) {
245 SoftbusReportPermissionFaultEvt(code);
246 COMM_LOGE(COMM_SVC, "access token permission denied! permission=%{public}s, tokenId=%{public}d",
247 permission, callingTokenId);
248 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
249 TransAlarmExtra extra = {
250 .callerPid = (int32_t)callingPid,
251 .methodId = (int32_t)code,
252 .conflictName = NULL,
253 .conflictedName = NULL,
254 .occupyedName = NULL,
255 .permissionName = permission,
256 .sessionName = NULL,
257 };
258 TRANS_ALARM(NO_PERMISSION_ALARM, CONTROL_ALARM_TYPE, extra);
259 return SOFTBUS_ACCESS_TOKEN_DENIED;
260 }
261 }
262
263 const auto &itFunc = memberFuncMap_.find(code);
264 if (itFunc != memberFuncMap_.end()) {
265 auto memberFunc = itFunc->second;
266 if (memberFunc != nullptr) {
267 return (this->*memberFunc)(data, reply);
268 }
269 }
270 COMM_LOGI(COMM_SVC, "default case, need check.");
271 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
272 }
273
SoftbusRegisterServiceInner(MessageParcel & data,MessageParcel & reply)274 int32_t SoftBusServerStub::SoftbusRegisterServiceInner(MessageParcel &data, MessageParcel &reply)
275 {
276 COMM_LOGD(COMM_SVC, "enter");
277 auto remote = data.ReadRemoteObject();
278 if (remote == nullptr) {
279 COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read systemAbilityId failed!");
280 return SOFTBUS_TRANS_PROXY_REMOTE_NULL;
281 }
282 const char *pkgName = data.ReadCString();
283 if (pkgName == nullptr) {
284 COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner read pkgName failed!");
285 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
286 }
287 uint32_t code = MANAGE_REGISTER_SERVICE;
288 SoftbusRecordCalledApiInfo(pkgName, code);
289 int32_t retReply = SoftbusRegisterService(pkgName, remote);
290 if (!reply.WriteInt32(retReply)) {
291 COMM_LOGE(COMM_SVC, "SoftbusRegisterServiceInner write reply failed!");
292 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
293 }
294 return SOFTBUS_OK;
295 }
296
297 #ifdef SUPPORT_BUNDLENAME
GetBundleName(pid_t callingUid,std::string & bundleName)298 static int32_t GetBundleName(pid_t callingUid, std::string &bundleName)
299 {
300 sptr<ISystemAbilityManager> systemAbilityManager =
301 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
302 if (systemAbilityManager == nullptr) {
303 COMM_LOGE(COMM_SVC, "Failed to get system ability manager.");
304 return SOFTBUS_TRANS_SYSTEM_ABILITY_MANAGER_FAILED;
305 }
306 sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
307 if (remoteObject == nullptr) {
308 COMM_LOGE(COMM_SVC, "Failed to get bundle manager service.");
309 return SOFTBUS_TRANS_GET_SYSTEM_ABILITY_FAILED;
310 }
311 sptr<AppExecFwk::IBundleMgr> iBundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
312 if (iBundleMgr == nullptr) {
313 COMM_LOGE(COMM_SVC, "iface_cast failed");
314 return SOFTBUS_TRANS_GET_BUNDLE_MGR_FAILED;
315 }
316 if (iBundleMgr->GetNameForUid(callingUid, bundleName) != SOFTBUS_OK) {
317 COMM_LOGE(COMM_SVC, "get bundleName failed");
318 return SOFTBUS_TRANS_GET_BUNDLENAME_FAILED;
319 }
320 return SOFTBUS_OK;
321 }
322
GetAppId(const std::string & bundleName,std::string & appId)323 static int32_t GetAppId(const std::string &bundleName, std::string &appId)
324 {
325 sptr<ISystemAbilityManager> systemAbilityManager =
326 SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager();
327 if (systemAbilityManager == nullptr) {
328 COMM_LOGE(COMM_SVC, "Failed to get system ability manager.");
329 return SOFTBUS_TRANS_SYSTEM_ABILITY_MANAGER_FAILED;
330 }
331 sptr<IRemoteObject> remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID);
332 if (remoteObject == nullptr) {
333 COMM_LOGE(COMM_SVC, "Failed to get bundle manager service.");
334 return SOFTBUS_TRANS_GET_SYSTEM_ABILITY_FAILED;
335 }
336 sptr<AppExecFwk::IBundleMgr> iBundleMgr = iface_cast<AppExecFwk::IBundleMgr>(remoteObject);
337 if (iBundleMgr == nullptr) {
338 COMM_LOGE(COMM_SVC, "iface_cast failed");
339 return SOFTBUS_TRANS_GET_BUNDLE_MGR_FAILED;
340 }
341 int32_t userId;
342 auto result = AccountSA::OsAccountManager::GetForegroundOsAccountLocalId(userId);
343 if (result != 0) {
344 COMM_LOGE(COMM_SVC, "GetForegroundOsAccountLocalId failed result=%{public}d", result);
345 return result;
346 }
347 AppExecFwk::BundleInfo bundleInfo;
348 result = iBundleMgr->GetBundleInfoV9(bundleName,
349 static_cast<int32_t>(AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_SIGNATURE_INFO),
350 bundleInfo, userId);
351 if (result != 0) {
352 COMM_LOGE(COMM_SVC, "GetBundleInfoV9 failed result=%{public}d", result);
353 return result;
354 }
355 appId = bundleInfo.appId;
356 return SOFTBUS_OK;
357 }
358
CheckNormalAppSessionName(const char * sessionName,pid_t callingUid,std::string & strName)359 static int32_t CheckNormalAppSessionName(
360 const char *sessionName, pid_t callingUid, std::string &strName)
361 {
362 uint64_t callingFullTokenId = IPCSkeleton::GetCallingFullTokenID();
363 if (SoftBusCheckIsNormalApp(callingFullTokenId, sessionName)) {
364 std::string bundleName;
365 int32_t result = GetBundleName(callingUid, bundleName);
366 if (result != SOFTBUS_OK) {
367 COMM_LOGE(COMM_SVC, "get bundle name failed");
368 return result;
369 }
370 std::string appId;
371 result = GetAppId(bundleName, appId);
372 if (result != SOFTBUS_OK) {
373 COMM_LOGE(COMM_SVC, "get appId failed");
374 return result;
375 }
376 auto posName = strName.find("-");
377 if (posName == std::string::npos) {
378 COMM_LOGE(COMM_SVC, "not find bundleName");
379 return SOFTBUS_TRANS_NOT_FIND_BUNDLENAME;
380 }
381 auto posId = strName.find("-", posName + 1);
382 if (posId == std::string::npos) {
383 COMM_LOGE(COMM_SVC, "not find appId");
384 return SOFTBUS_TRANS_NOT_FIND_APPID;
385 }
386 if (strcmp(bundleName.c_str(), strName.substr(posName + 1, posId - posName - 1).c_str()) != 0) {
387 COMM_LOGE(COMM_SVC, "bundleName is different from session name");
388 return SOFTBUS_STRCMP_ERR;
389 }
390 if (strcmp(appId.c_str(), strName.substr(posId + 1).c_str()) != 0) {
391 COMM_LOGE(COMM_SVC, "appId is different from session name");
392 return SOFTBUS_STRCMP_ERR;
393 }
394 strName.erase(posId);
395 }
396 return SOFTBUS_OK;
397 }
398 #endif
399
CreateSessionServerInner(MessageParcel & data,MessageParcel & reply)400 int32_t SoftBusServerStub::CreateSessionServerInner(MessageParcel &data, MessageParcel &reply)
401 {
402 COMM_LOGD(COMM_SVC, "enter");
403 int32_t retReply;
404 pid_t callingUid;
405 pid_t callingPid;
406 const char *pkgName = data.ReadCString();
407 if (pkgName == nullptr) {
408 COMM_LOGE(COMM_SVC, "CreateSessionServerInner read pkgName failed!");
409 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
410 }
411
412 const char *sessionName = data.ReadCString();
413 std::string strName;
414 uint32_t code = SERVER_CREATE_SESSION_SERVER;
415 SoftbusRecordCalledApiInfo(pkgName, code);
416 if (pkgName == nullptr || sessionName == nullptr) {
417 retReply = SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
418 goto EXIT;
419 }
420 strName = sessionName;
421 callingUid = OHOS::IPCSkeleton::GetCallingUid();
422 callingPid = OHOS::IPCSkeleton::GetCallingPid();
423 if (CheckTransPermission(callingUid, callingPid, pkgName, sessionName, ACTION_CREATE) != SOFTBUS_OK) {
424 retReply = SOFTBUS_PERMISSION_DENIED;
425 goto EXIT;
426 }
427 #ifdef SUPPORT_BUNDLENAME
428 if (CheckNormalAppSessionName(sessionName, callingUid, strName) != SOFTBUS_OK) {
429 retReply = SOFTBUS_PERMISSION_DENIED;
430 goto EXIT;
431 }
432 sessionName = strName.c_str();
433 #endif
434 retReply = CreateSessionServer(pkgName, sessionName);
435 EXIT:
436 if (!reply.WriteInt32(retReply)) {
437 COMM_LOGE(COMM_SVC, "CreateSessionServerInner write reply failed!");
438 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
439 }
440 return SOFTBUS_OK;
441 }
442
RemoveSessionServerInner(MessageParcel & data,MessageParcel & reply)443 int32_t SoftBusServerStub::RemoveSessionServerInner(MessageParcel &data, MessageParcel &reply)
444 {
445 COMM_LOGD(COMM_SVC, "enter");
446 int32_t retReply;
447 pid_t callingUid;
448 pid_t callingPid;
449 const char *pkgName = data.ReadCString();
450 if (pkgName == nullptr) {
451 COMM_LOGE(COMM_SVC, "RemoveSessionServerInner read pkgName failed!");
452 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
453 }
454
455 const char *sessionName = data.ReadCString();
456 uint32_t code = SERVER_REMOVE_SESSION_SERVER;
457 SoftbusRecordCalledApiInfo(pkgName, code);
458 if (pkgName == nullptr || sessionName == nullptr) {
459 retReply = SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
460 goto EXIT;
461 }
462
463 callingUid = OHOS::IPCSkeleton::GetCallingUid();
464 callingPid = OHOS::IPCSkeleton::GetCallingPid();
465 if (CheckTransPermission(callingUid, callingPid, pkgName, sessionName, ACTION_CREATE) != SOFTBUS_OK) {
466 COMM_LOGE(COMM_SVC, "RemoveSessionServerInner check perm failed");
467 retReply = SOFTBUS_PERMISSION_DENIED;
468 goto EXIT;
469 }
470
471 if (!CheckUidAndPid(sessionName, callingUid, callingPid)) {
472 COMM_LOGE(COMM_SVC, "Check Uid and Pid failed!");
473 return SOFTBUS_TRANS_CHECK_PID_ERROR;
474 }
475 retReply = RemoveSessionServer(pkgName, sessionName);
476 EXIT:
477 if (!reply.WriteInt32(retReply)) {
478 COMM_LOGE(COMM_SVC, "RemoveSessionServerInner write reply failed!");
479 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
480 }
481 return SOFTBUS_OK;
482 }
483
ReadSessionAttrs(MessageParcel & data,SessionAttribute * getAttr)484 static void ReadSessionAttrs(MessageParcel &data, SessionAttribute *getAttr)
485 {
486 if (getAttr == nullptr) {
487 COMM_LOGE(COMM_SVC, "ReadSessionAttrs getAttr is nullptr");
488 return;
489 }
490 LinkType *pGetArr = nullptr;
491
492 getAttr->dataType = data.ReadInt32();
493 getAttr->linkTypeNum = data.ReadInt32();
494
495 if (getAttr->linkTypeNum > 0 && getAttr->linkTypeNum <= LINK_TYPE_MAX) {
496 pGetArr = const_cast<LinkType *>(
497 reinterpret_cast<const LinkType *>(data.ReadBuffer(sizeof(LinkType) * getAttr->linkTypeNum)));
498 }
499
500 if (pGetArr != nullptr) {
501 if (memcpy_s(getAttr->linkType, sizeof(LinkType) * LINK_TYPE_MAX, pGetArr,
502 sizeof(LinkType) * getAttr->linkTypeNum) != EOK) {
503 COMM_LOGE(COMM_SVC, "LinkType copy failed linkTypeNum = %{public}d, dataType = %{public}d",
504 getAttr->linkTypeNum, getAttr->dataType);
505 }
506 }
507
508 getAttr->attr.streamAttr.streamType = data.ReadInt32();
509 getAttr->fastTransDataSize = data.ReadUint16();
510 if (getAttr->fastTransDataSize != 0) {
511 getAttr->fastTransData =
512 const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(data.ReadRawData(getAttr->fastTransDataSize)));
513 }
514 }
515
ReadQosInfo(MessageParcel & data,SessionParam & param)516 static bool ReadQosInfo(MessageParcel &data, SessionParam ¶m)
517 {
518 if (!data.ReadBool(param.isQosLane)) {
519 COMM_LOGE(COMM_SVC, "failed to read isQosLane");
520 return false;
521 }
522 if (!param.isQosLane) {
523 return true;
524 }
525
526 if (!data.ReadUint32(param.qosCount)) {
527 COMM_LOGE(COMM_SVC, "failed to read qosCount");
528 return false;
529 }
530 if (param.qosCount == 0) {
531 return true;
532 }
533
534 if (param.qosCount > QOS_TYPE_BUTT) {
535 COMM_LOGE(COMM_SVC, "read invalid qosCount=%{public}" PRIu32, param.qosCount);
536 return false;
537 }
538
539 const QosTV *qosInfo = (QosTV *)data.ReadBuffer(sizeof(QosTV) * param.qosCount);
540 if (qosInfo == nullptr) {
541 COMM_LOGE(COMM_SVC, "failed to read qos data");
542 return false;
543 }
544
545 if (memcpy_s(param.qos, sizeof(QosTV) * QOS_TYPE_BUTT, qosInfo, sizeof(QosTV) * param.qosCount) != EOK) {
546 COMM_LOGE(COMM_SVC, "failed memcpy qos info");
547 return false;
548 }
549 return true;
550 }
551
ReadSessionInfo(MessageParcel & data,SessionParam & param)552 static void ReadSessionInfo(MessageParcel &data, SessionParam ¶m)
553 {
554 param.sessionName = data.ReadCString();
555 param.peerSessionName = data.ReadCString();
556 param.peerDeviceId = data.ReadCString();
557 param.groupId = data.ReadCString();
558 param.isAsync = data.ReadBool();
559 param.sessionId = data.ReadInt32();
560 param.actionId = data.ReadUint32();
561 param.pid = OHOS::IPCSkeleton::GetCallingPid();
562 }
563
OpenSessionInner(MessageParcel & data,MessageParcel & reply)564 int32_t SoftBusServerStub::OpenSessionInner(MessageParcel &data, MessageParcel &reply)
565 {
566 COMM_LOGD(COMM_SVC, "enter");
567 int32_t retReply;
568 SessionParam param { 0 };
569 SessionAttribute getAttr { 0 };
570
571 TransSerializer transSerializer;
572 int64_t timeStart = 0;
573 int64_t timediff = 0;
574 SoftBusOpenSessionStatus isSucc = SOFTBUS_EVT_OPEN_SESSION_FAIL;
575 ReadSessionInfo(data, param);
576 ReadSessionAttrs(data, &getAttr);
577 param.attr = &getAttr;
578 COMM_CHECK_AND_RETURN_RET_LOGE(ReadQosInfo(data, param), SOFTBUS_IPC_ERR, COMM_SVC, "failed to read qos info");
579
580 if (param.sessionName == nullptr || param.peerSessionName == nullptr || param.peerDeviceId == nullptr ||
581 param.groupId == nullptr) {
582 retReply = SOFTBUS_INVALID_PARAM;
583 goto EXIT;
584 }
585
586 #define DMS_COLLABATION_NAME_PREFIX "ohos.dtbcollab.dms"
587 if (strncmp(param.sessionName, DMS_COLLABATION_NAME_PREFIX, strlen(DMS_COLLABATION_NAME_PREFIX)) == 0) {
588 COMM_LOGI(COMM_SVC, "DMS bind request, need check collaboration relationship");
589 if (CheckSourceCollabRelation(param.peerDeviceId, OHOS::IPCSkeleton::GetCallingPid()) != SOFTBUS_OK) {
590 COMM_LOGE(COMM_SVC, "DMS check collaboration relationship failed, reject binding request");
591 retReply = SOFTBUS_TRANS_CHECK_RELATION_FAIL;
592 goto EXIT;
593 }
594 }
595
596 if ((retReply = TransCheckClientAccessControl(param.peerDeviceId)) != SOFTBUS_OK) {
597 goto EXIT;
598 }
599 if (CheckOpenSessionPermission(¶m) != SOFTBUS_OK) {
600 SoftbusReportTransErrorEvt(SOFTBUS_PERMISSION_DENIED);
601 retReply = SOFTBUS_PERMISSION_DENIED;
602 goto EXIT;
603 }
604
605 timeStart = GetSoftbusRecordTimeMillis();
606 retReply = OpenSession(¶m, &(transSerializer.transInfo));
607 timediff = GetSoftbusRecordTimeMillis() - timeStart;
608
609 isSucc = (retReply == SOFTBUS_OK) ? SOFTBUS_EVT_OPEN_SESSION_SUCC : SOFTBUS_EVT_OPEN_SESSION_FAIL;
610 SoftbusRecordOpenSession(isSucc, static_cast<uint32_t>(timediff));
611
612 EXIT:
613 transSerializer.ret = retReply;
614 bool result = reply.WriteRawData(&transSerializer, sizeof(TransSerializer));
615 COMM_CHECK_AND_RETURN_RET_LOGE(result, SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
616 return SOFTBUS_OK;
617 }
618
OpenAuthSessionInner(MessageParcel & data,MessageParcel & reply)619 int32_t SoftBusServerStub::OpenAuthSessionInner(MessageParcel &data, MessageParcel &reply)
620 {
621 COMM_LOGD(COMM_SVC, "enter");
622 int32_t retReply;
623 const char *sessionName = data.ReadCString();
624 ConnectionAddr *addrInfo = const_cast<ConnectionAddr *>(
625 reinterpret_cast<const ConnectionAddr *>(data.ReadRawData(sizeof(ConnectionAddr))));
626 if (sessionName == nullptr || addrInfo == nullptr) {
627 COMM_LOGE(COMM_SVC, "OpenAuthSessionInner get param failed!");
628 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
629 }
630 SessionParam param;
631 param.sessionName = sessionName;
632 param.peerSessionName = sessionName;
633 retReply = CheckOpenSessionPermission(¶m);
634 if (retReply != SOFTBUS_OK) {
635 goto EXIT;
636 }
637 retReply = OpenAuthSession(sessionName, addrInfo);
638 AddChannelStatisticsInfo(retReply, CHANNEL_TYPE_AUTH);
639 COMM_LOGI(COMM_SVC, "OpenAuthSession channelId=%{public}d", retReply);
640 EXIT:
641 if (!reply.WriteInt32(retReply)) {
642 COMM_LOGE(COMM_SVC, "OpenSessionInner write reply failed! retReply=%{public}d", retReply);
643 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
644 }
645 return SOFTBUS_OK;
646 }
647
NotifyAuthSuccessInner(MessageParcel & data,MessageParcel & reply)648 int32_t SoftBusServerStub::NotifyAuthSuccessInner(MessageParcel &data, MessageParcel &reply)
649 {
650 COMM_LOGD(COMM_SVC, "enter");
651 int32_t channelId;
652 int32_t channelType;
653 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
654 if (!data.ReadInt32(channelId)) {
655 COMM_LOGE(COMM_SVC, "NotifyAuthSuccessInner read channel Id failed!");
656 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
657 }
658 if (!data.ReadInt32(channelType)) {
659 COMM_LOGE(COMM_SVC, "NotifyAuthSuccessInner read channel type failed!");
660 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
661 }
662 int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
663 if (ret != SOFTBUS_OK) {
664 COMM_LOGE(COMM_SVC, "callingPid not equal pid, callingPid=%{public}d, channelId=%{public}d",
665 callingPid, channelId);
666 return ret;
667 }
668 int32_t retReply = NotifyAuthSuccess(channelId, channelType);
669 if (!reply.WriteInt32(retReply)) {
670 COMM_LOGE(COMM_SVC, "NotifyAuthSuccessInner write reply failed!");
671 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
672 }
673 return SOFTBUS_OK;
674 }
675
ReleaseResourcesInner(MessageParcel & data,MessageParcel & reply)676 int32_t SoftBusServerStub::ReleaseResourcesInner(MessageParcel &data, MessageParcel &reply)
677 {
678 int32_t channelId;
679 if (!data.ReadInt32(channelId)) {
680 COMM_LOGE(COMM_SVC, "failed to read channel Id");
681 return SOFTBUS_IPC_ERR;
682 }
683
684 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
685 int32_t ret = TransGetAndComparePid(callingPid, channelId, CHANNEL_TYPE_UDP);
686 if (ret != SOFTBUS_OK) {
687 COMM_LOGE(COMM_SVC, "Pid not find, ret = %{public}d", ret);
688 if (!reply.WriteInt32(ret)) {
689 COMM_LOGE(COMM_SVC, "failed to write ret failed");
690 return SOFTBUS_IPC_ERR;
691 }
692 return ret;
693 }
694 int32_t retReply = ReleaseResources(channelId);
695 if (!reply.WriteInt32(retReply)) {
696 COMM_LOGE(COMM_SVC, "failed to write reply failed");
697 return SOFTBUS_IPC_ERR;
698 }
699 return SOFTBUS_OK;
700 }
701
CloseChannelInner(MessageParcel & data,MessageParcel & reply)702 int32_t SoftBusServerStub::CloseChannelInner(MessageParcel &data, MessageParcel &reply)
703 {
704 COMM_LOGD(COMM_SVC, "enter");
705 int32_t channelId;
706 if (!data.ReadInt32(channelId)) {
707 COMM_LOGE(COMM_SVC, "CloseChannelInner read channel Id failed!");
708 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
709 }
710 int32_t channelType;
711 if (!data.ReadInt32(channelType)) {
712 COMM_LOGE(COMM_SVC, "CloseChannelInner read channel channel type failed!");
713 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
714 }
715 const char *sessionName = nullptr;
716 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
717 if (channelType == CHANNEL_TYPE_UNDEFINED) {
718 sessionName = data.ReadCString();
719 if (sessionName == nullptr) {
720 COMM_LOGE(COMM_SVC, "CloseChannelInner get param failed!");
721 return SOFTBUS_IPC_ERR;
722 }
723 int32_t ret = TransGetAndComparePidBySession(callingPid, sessionName, channelId);
724 if (ret != SOFTBUS_OK) {
725 COMM_LOGE(COMM_SVC, "Pid can not close channel, pid=%{public}d, sessionId=%{public}d, ret=%{public}d",
726 callingPid, channelId, ret);
727 return ret;
728 }
729 } else {
730 int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
731 if (ret != SOFTBUS_OK) {
732 COMM_LOGE(COMM_SVC, "Pid can not close channel, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
733 callingPid, channelId, ret);
734 return ret;
735 }
736 }
737
738 int32_t retReply = CloseChannel(sessionName, channelId, channelType);
739 if (!reply.WriteInt32(retReply)) {
740 COMM_LOGE(COMM_SVC, "CloseChannelInner write reply failed!");
741 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
742 }
743 return SOFTBUS_OK;
744 }
745
CloseChannelWithStatisticsInner(MessageParcel & data,MessageParcel & reply)746 int32_t SoftBusServerStub::CloseChannelWithStatisticsInner(MessageParcel &data, MessageParcel &reply)
747 {
748 COMM_LOGD(COMM_SVC, "enter");
749 int32_t channelId;
750 if (!data.ReadInt32(channelId)) {
751 COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner read channel id failed!");
752 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
753 }
754 int32_t channelType;
755 if (!data.ReadInt32(channelType)) {
756 COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner read channel type failed!");
757 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
758 }
759 uint64_t laneId;
760 if (!data.ReadUint64(laneId)) {
761 COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner read lane id failed!");
762 return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
763 }
764 uint32_t len;
765 if (!data.ReadUint32(len)) {
766 COMM_LOGE(COMM_SVC, "CloseChannelWithStatisticsInner dataInfo len failed!");
767 return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
768 }
769
770 auto rawData = data.ReadRawData(len);
771 COMM_CHECK_AND_RETURN_RET_LOGE(rawData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read len failed.");
772 void *dataInfo = const_cast<void *>(rawData);
773
774 int32_t retReply = CloseChannelWithStatistics(channelId, channelType, laneId, dataInfo, len);
775 if (!reply.WriteInt32(retReply)) {
776 COMM_LOGE(COMM_SVC, "CloseChannelInner write reply failed!");
777 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
778 }
779 return SOFTBUS_OK;
780 }
781
SendMessageInner(MessageParcel & data,MessageParcel & reply)782 int32_t SoftBusServerStub::SendMessageInner(MessageParcel &data, MessageParcel &reply)
783 {
784 int32_t channelId;
785 if (!data.ReadInt32(channelId)) {
786 COMM_LOGE(COMM_SVC, "SendMessage read channel Id failed!");
787 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
788 }
789 int32_t channelType;
790 if (!data.ReadInt32(channelType)) {
791 COMM_LOGE(COMM_SVC, "SendMessage read channel type failed!");
792 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
793 }
794 uint32_t len;
795 if (!data.ReadUint32(len)) {
796 COMM_LOGE(COMM_SVC, "SendMessage dataInfo len failed!");
797 return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
798 }
799
800 auto rawData = data.ReadRawData(len);
801 COMM_CHECK_AND_RETURN_RET_LOGE(rawData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read rawData failed!");
802 void *dataInfo = const_cast<void *>(rawData);
803
804 int32_t msgType;
805 if (!data.ReadInt32(msgType)) {
806 COMM_LOGE(COMM_SVC, "SendMessage message type failed!");
807 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
808 }
809 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
810 if (TransGetAndComparePid(callingPid, channelId, channelType) != SOFTBUS_OK) {
811 COMM_LOGE(COMM_SVC, "pid permission check failed!");
812 return SOFTBUS_PERMISSION_DENIED;
813 }
814
815 int32_t retReply = SendMessage(channelId, channelType, dataInfo, len, msgType);
816 if (!reply.WriteInt32(retReply)) {
817 COMM_LOGE(COMM_SVC, "SendMessage write reply failed!");
818 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
819 }
820 return SOFTBUS_OK;
821 }
822
EvaluateQosInner(MessageParcel & data,MessageParcel & reply)823 int32_t SoftBusServerStub::EvaluateQosInner(MessageParcel &data, MessageParcel &reply)
824 {
825 COMM_LOGD(COMM_SVC, "enter");
826 const char *peerNetworkId = data.ReadCString();
827 if (peerNetworkId == nullptr) {
828 COMM_LOGE(COMM_SVC, "EvaluateQos read peerNetworkId failed!");
829 return SOFTBUS_IPC_ERR;
830 }
831
832 int32_t dataTypeNumber;
833 if (!data.ReadInt32(dataTypeNumber)) {
834 COMM_LOGE(COMM_SVC, "EvaluateQos read dataType failed!");
835 return SOFTBUS_IPC_ERR;
836 }
837
838 TransDataType dataType = static_cast<TransDataType>(dataTypeNumber);
839 if (dataType < DATA_TYPE_MESSAGE || dataType >= DATA_TYPE_BUTT) {
840 COMM_LOGE(COMM_SVC, "EvaluateQos read dataType failed!");
841 return SOFTBUS_IPC_ERR;
842 }
843
844 uint32_t qosCount;
845 if (!data.ReadUint32(qosCount)) {
846 COMM_LOGE(COMM_SVC, "EvaluateQos read qosCount failed!");
847 return SOFTBUS_IPC_ERR;
848 }
849
850 if (qosCount > QOS_TYPE_BUTT) {
851 COMM_LOGE(COMM_SVC, "EvaluateQos invalid qosCount=%{public}" PRIu32, qosCount);
852 return SOFTBUS_IPC_ERR;
853 }
854
855 const QosTV *qos = nullptr;
856 if (qosCount > 0) {
857 qos = (QosTV *)data.ReadBuffer(sizeof(QosTV) * qosCount);
858 if (qos == nullptr) {
859 COMM_LOGE(COMM_SVC, "EvaluateQos failed to read qos data");
860 return SOFTBUS_IPC_ERR;
861 }
862 }
863
864 int32_t retReply = EvaluateQos(peerNetworkId, dataType, qos, qosCount);
865 if (!reply.WriteInt32(retReply)) {
866 COMM_LOGE(COMM_SVC, "EvaluateQos write reply failed!");
867 return SOFTBUS_IPC_ERR;
868 }
869 return SOFTBUS_OK;
870 }
871
JoinLNNInner(MessageParcel & data,MessageParcel & reply)872 int32_t SoftBusServerStub::JoinLNNInner(MessageParcel &data, MessageParcel &reply)
873 {
874 COMM_LOGD(COMM_SVC, "enter");
875 const char *clientName = data.ReadCString();
876 if (clientName == nullptr) {
877 COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner read clientName failed!");
878 return SOFTBUS_IPC_ERR;
879 }
880 uint32_t addrTypeLen;
881 if (!data.ReadUint32(addrTypeLen) || addrTypeLen != sizeof(ConnectionAddr)) {
882 COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner read addr type failed! length=%{public}d", addrTypeLen);
883 return SOFTBUS_IPC_ERR;
884 }
885
886 auto rawData = data.ReadRawData(addrTypeLen);
887 COMM_CHECK_AND_RETURN_RET_LOGE(rawData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read addrTypeLen failed.");
888 void *addr = const_cast<void *>(rawData);
889 bool isForceJoin;
890 if (!data.ReadBool(isForceJoin)) {
891 COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner read force join flag failed!");
892 return SOFTBUS_IPC_ERR;
893 }
894 int32_t retReply = JoinLNN(clientName, addr, addrTypeLen, isForceJoin);
895 if (!reply.WriteInt32(retReply)) {
896 COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner write reply failed!");
897 return SOFTBUS_IPC_ERR;
898 }
899 return SOFTBUS_OK;
900 }
901
LeaveLNNInner(MessageParcel & data,MessageParcel & reply)902 int32_t SoftBusServerStub::LeaveLNNInner(MessageParcel &data, MessageParcel &reply)
903 {
904 COMM_LOGD(COMM_SVC, "enter");
905 const char *clientName = data.ReadCString();
906 if (clientName == nullptr) {
907 COMM_LOGE(COMM_SVC, "SoftbusLeaveLNNInner read clientName failed!");
908 return SOFTBUS_IPC_ERR;
909 }
910 const char *networkId = data.ReadCString();
911 if (networkId == nullptr) {
912 COMM_LOGE(COMM_SVC, "SoftbusLeaveLNNInner read networkId failed!");
913 return SOFTBUS_IPC_ERR;
914 }
915 int32_t retReply = LeaveLNN(clientName, networkId);
916 if (!reply.WriteInt32(retReply)) {
917 COMM_LOGE(COMM_SVC, "SoftbusJoinLNNInner write reply failed!");
918 return SOFTBUS_IPC_ERR;
919 }
920 return SOFTBUS_OK;
921 }
922
GetAllOnlineNodeInfoInner(MessageParcel & data,MessageParcel & reply)923 int32_t SoftBusServerStub::GetAllOnlineNodeInfoInner(MessageParcel &data, MessageParcel &reply)
924 {
925 COMM_LOGD(COMM_SVC, "enter");
926 void *nodeInfo = nullptr;
927 int32_t infoNum;
928 uint32_t infoTypeLen;
929
930 const char *clientName = data.ReadCString();
931 if (clientName == nullptr) {
932 COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner read clientName failed!");
933 return SOFTBUS_IPC_ERR;
934 }
935 if (!data.ReadUint32(infoTypeLen)) {
936 COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner read info type length failed");
937 return SOFTBUS_IPC_ERR;
938 }
939 if (GetAllOnlineNodeInfo(clientName, &nodeInfo, infoTypeLen, &infoNum) != SOFTBUS_OK) {
940 COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner get info failed");
941 return SOFTBUS_NETWORK_GET_ALL_NODE_INFO_ERR;
942 }
943 if (infoNum < 0 || (infoNum > 0 && nodeInfo == nullptr)) {
944 COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner node info is invalid");
945 return SOFTBUS_IPC_ERR;
946 }
947 if (!reply.WriteInt32(infoNum)) {
948 COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner write infoNum failed!");
949 SoftBusFree(nodeInfo);
950 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
951 }
952 int32_t ret = SOFTBUS_OK;
953 if (infoNum > 0) {
954 if (!reply.WriteRawData(nodeInfo, static_cast<int32_t>(infoTypeLen * infoNum))) {
955 COMM_LOGE(COMM_SVC, "GetAllOnlineNodeInfoInner write node info failed!");
956 ret = SOFTBUS_IPC_ERR;
957 }
958 SoftBusFree(nodeInfo);
959 }
960 return ret;
961 }
962
GetLocalDeviceInfoInner(MessageParcel & data,MessageParcel & reply)963 int32_t SoftBusServerStub::GetLocalDeviceInfoInner(MessageParcel &data, MessageParcel &reply)
964 {
965 void *nodeInfo = nullptr;
966 uint32_t infoTypeLen;
967
968 const char *clientName = data.ReadCString();
969 if (clientName == nullptr) {
970 COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner read clientName failed!");
971 return SOFTBUS_IPC_ERR;
972 }
973
974 infoTypeLen = data.ReadUint32();
975 if (infoTypeLen != sizeof(NodeBasicInfo)) {
976 COMM_LOGE(COMM_SVC, "read infoTypeLen failed!");
977 return SOFTBUS_IPC_ERR;
978 }
979 nodeInfo = SoftBusCalloc(infoTypeLen);
980 if (nodeInfo == nullptr) {
981 COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner malloc info type length failed");
982 return SOFTBUS_IPC_ERR;
983 }
984 int32_t retReply = GetLocalDeviceInfo(clientName, nodeInfo, infoTypeLen);
985 if (!reply.WriteRawData(nodeInfo, infoTypeLen)) {
986 COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner write node info failed!");
987 SoftBusFree(nodeInfo);
988 return SOFTBUS_IPC_ERR;
989 }
990 if (!reply.WriteInt32(retReply)) {
991 COMM_LOGE(COMM_SVC, "GetLocalDeviceInfoInner write reply failed!");
992 SoftBusFree(nodeInfo);
993 return SOFTBUS_IPC_ERR;
994 }
995 SoftBusFree(nodeInfo);
996 return SOFTBUS_OK;
997 }
998
GetNodeKeyInfoLen(int32_t key)999 int32_t SoftBusServerStub::GetNodeKeyInfoLen(int32_t key)
1000 {
1001 return LnnGetNodeKeyInfoLen(key);
1002 }
1003
GetNodeKeyInfoInner(MessageParcel & data,MessageParcel & reply)1004 int32_t SoftBusServerStub::GetNodeKeyInfoInner(MessageParcel &data, MessageParcel &reply)
1005 {
1006 const char *clientName = data.ReadCString();
1007 const char *networkId = data.ReadCString();
1008 if (clientName == nullptr || networkId == nullptr) {
1009 COMM_LOGE(COMM_SVC, "read clientName or networkId failed!");
1010 return SOFTBUS_IPC_ERR;
1011 }
1012 char *anonyNetworkId = nullptr;
1013 Anonymize(networkId, &anonyNetworkId);
1014 COMM_LOGD(COMM_SVC, "networkId=%{public}s", anonyNetworkId);
1015 AnonymizeFree(anonyNetworkId);
1016
1017 int32_t key;
1018 READ_PARCEL_WITH_RET(data, Int32, key, SOFTBUS_IPC_ERR);
1019 int32_t infoLen = GetNodeKeyInfoLen(key);
1020 if (infoLen == SOFTBUS_ERR) {
1021 COMM_LOGE(COMM_SVC, "get info len failed!");
1022 return SOFTBUS_NETWORK_NODE_KEY_INFO_ERR;
1023 }
1024 uint32_t len;
1025 READ_PARCEL_WITH_RET(data, Uint32, len, SOFTBUS_IPC_ERR);
1026 if (len < (uint32_t)infoLen) {
1027 COMM_LOGE(COMM_SVC, "invalid param, len=%{public}u, infoLen=%{public}d", len, infoLen);
1028 return SOFTBUS_INVALID_PARAM;
1029 }
1030 void *buf = SoftBusCalloc(infoLen);
1031 if (buf == nullptr) {
1032 COMM_LOGE(COMM_SVC, "malloc buffer failed!");
1033 return SOFTBUS_MALLOC_ERR;
1034 }
1035 int32_t ret = GetNodeKeyInfo(clientName, networkId, key, static_cast<unsigned char *>(buf), infoLen);
1036 if (!reply.WriteInt32(infoLen)) {
1037 COMM_LOGE(COMM_SVC, "write info length failed!");
1038 SoftBusFree(buf);
1039 return SOFTBUS_IPC_ERR;
1040 }
1041 if (!reply.WriteRawData(buf, infoLen)) {
1042 COMM_LOGE(COMM_SVC, "write key info failed!");
1043 SoftBusFree(buf);
1044 return SOFTBUS_IPC_ERR;
1045 }
1046 if (!reply.WriteInt32(ret)) {
1047 COMM_LOGE(COMM_SVC, "write info length failed!");
1048 SoftBusFree(buf);
1049 return SOFTBUS_IPC_ERR;
1050 }
1051 SoftBusFree(buf);
1052 return SOFTBUS_OK;
1053 }
1054
SetNodeDataChangeFlagInner(MessageParcel & data,MessageParcel & reply)1055 int32_t SoftBusServerStub::SetNodeDataChangeFlagInner(MessageParcel &data, MessageParcel &reply)
1056 {
1057 const char *clientName = data.ReadCString();
1058 if (clientName == nullptr) {
1059 COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag read clientName failed!");
1060 return SOFTBUS_IPC_ERR;
1061 }
1062 const char *networkId = data.ReadCString();
1063 if (networkId == nullptr) {
1064 COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag read networkId failed!");
1065 return SOFTBUS_IPC_ERR;
1066 }
1067 uint16_t changeFlag;
1068 if (!data.ReadUint16(changeFlag)) {
1069 COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag read key failed!");
1070 return SOFTBUS_IPC_ERR;
1071 }
1072 int32_t retReply = SetNodeDataChangeFlag(clientName, networkId, changeFlag);
1073 if (!reply.WriteInt32(retReply)) {
1074 COMM_LOGE(COMM_SVC, "SetNodeDataChangeFlag write reply failed!");
1075 return SOFTBUS_IPC_ERR;
1076 }
1077 return SOFTBUS_OK;
1078 }
1079
RegDataLevelChangeCbInner(MessageParcel & data,MessageParcel & reply)1080 int32_t SoftBusServerStub::RegDataLevelChangeCbInner(MessageParcel &data, MessageParcel &reply)
1081 {
1082 #ifndef ENHANCED_FLAG
1083 (void)data;
1084 (void)reply;
1085 (void)DB_PACKAGE_NAME;
1086 return SOFTBUS_FUNC_NOT_SUPPORT;
1087 #else
1088 const char *pkgName = data.ReadCString();
1089 if (pkgName == nullptr) {
1090 COMM_LOGE(COMM_SVC, "RegDataLevelChangeCbInner read pkgName failed!");
1091 return SOFTBUS_IPC_ERR;
1092 }
1093 if (strcmp(DB_PACKAGE_NAME, pkgName) != 0) {
1094 COMM_LOGE(COMM_SVC, "RegDataLevelChangeCbInner read pkgName invalid!");
1095 return SOFTBUS_INVALID_PARAM;
1096 }
1097 int32_t retReply = RegDataLevelChangeCb(pkgName);
1098 if (!reply.WriteInt32(retReply)) {
1099 COMM_LOGE(COMM_SVC, "RegDataLevelChangeCbInner write reply failed!");
1100 return SOFTBUS_IPC_ERR;
1101 }
1102 return SOFTBUS_OK;
1103 #endif
1104 }
1105
UnregDataLevelChangeCbInner(MessageParcel & data,MessageParcel & reply)1106 int32_t SoftBusServerStub::UnregDataLevelChangeCbInner(MessageParcel &data, MessageParcel &reply)
1107 {
1108 #ifndef ENHANCED_FLAG
1109 (void)data;
1110 (void)reply;
1111 (void)DB_PACKAGE_NAME;
1112 return SOFTBUS_FUNC_NOT_SUPPORT;
1113 #else
1114 const char *pkgName = data.ReadCString();
1115 if (pkgName == nullptr) {
1116 COMM_LOGE(COMM_SVC, "UnregDataLevelChangeCbInner read pkgName failed!");
1117 return SOFTBUS_IPC_ERR;
1118 }
1119 if (strcmp(DB_PACKAGE_NAME, pkgName) != 0) {
1120 COMM_LOGE(COMM_SVC, "UnregDataLevelChangeCbInner read pkgName invalid!");
1121 return SOFTBUS_INVALID_PARAM;
1122 }
1123 int32_t retReply = UnregDataLevelChangeCb(pkgName);
1124 if (!reply.WriteInt32(retReply)) {
1125 COMM_LOGE(COMM_SVC, "UnregDataLevelChangeCbInner write reply failed!");
1126 return SOFTBUS_IPC_ERR;
1127 }
1128 return SOFTBUS_OK;
1129 #endif
1130 }
1131
SetDataLevelInner(MessageParcel & data,MessageParcel & reply)1132 int32_t SoftBusServerStub::SetDataLevelInner(MessageParcel &data, MessageParcel &reply)
1133 {
1134 #ifndef ENHANCED_FLAG
1135 (void)data;
1136 (void)reply;
1137 return SOFTBUS_FUNC_NOT_SUPPORT;
1138 #else
1139 DataLevel *dataLevel = (DataLevel*)data.ReadRawData(sizeof(DataLevel));
1140 if (dataLevel == nullptr) {
1141 COMM_LOGE(COMM_SVC, "SetDataLevelInner read networkid failed!");
1142 return SOFTBUS_IPC_ERR;
1143 }
1144
1145 int32_t retReply = SetDataLevel(dataLevel);
1146 if (!reply.WriteInt32(retReply)) {
1147 COMM_LOGE(COMM_SVC, "SetDataLevelInner write reply failed!");
1148 return SOFTBUS_IPC_ERR;
1149 }
1150 return SOFTBUS_OK;
1151 #endif
1152 }
1153
StartTimeSyncInner(MessageParcel & data,MessageParcel & reply)1154 int32_t SoftBusServerStub::StartTimeSyncInner(MessageParcel &data, MessageParcel &reply)
1155 {
1156 COMM_LOGD(COMM_SVC, "enter");
1157 const char *pkgName = data.ReadCString();
1158 if (pkgName == nullptr) {
1159 COMM_LOGE(COMM_SVC, "StartTimeSyncInner read pkgName failed!");
1160 return SOFTBUS_IPC_ERR;
1161 }
1162 uint32_t code = SERVER_START_TIME_SYNC;
1163 SoftbusRecordCalledApiInfo(pkgName, code);
1164 const char *targetNetworkId = data.ReadCString();
1165 if (targetNetworkId == nullptr) {
1166 COMM_LOGE(COMM_SVC, "StartTimeSyncInner read targetNetworkId failed!");
1167 return SOFTBUS_IPC_ERR;
1168 }
1169 int32_t accuracy;
1170 if (!data.ReadInt32(accuracy)) {
1171 COMM_LOGE(COMM_SVC, "StartTimeSyncInner read accuracy failed!");
1172 return SOFTBUS_IPC_ERR;
1173 }
1174 int32_t period;
1175 if (!data.ReadInt32(period)) {
1176 COMM_LOGE(COMM_SVC, "StartTimeSyncInner read period failed!");
1177 return SOFTBUS_IPC_ERR;
1178 }
1179 int32_t retReply = StartTimeSync(pkgName, targetNetworkId, accuracy, period);
1180 if (!reply.WriteInt32(retReply)) {
1181 COMM_LOGE(COMM_SVC, "StartTimeSyncInner write reply failed!");
1182 return SOFTBUS_IPC_ERR;
1183 }
1184 return SOFTBUS_OK;
1185 }
1186
StopTimeSyncInner(MessageParcel & data,MessageParcel & reply)1187 int32_t SoftBusServerStub::StopTimeSyncInner(MessageParcel &data, MessageParcel &reply)
1188 {
1189 COMM_LOGD(COMM_SVC, "enter");
1190 const char *pkgName = data.ReadCString();
1191 if (pkgName == nullptr) {
1192 COMM_LOGE(COMM_SVC, "StopTimeSyncInner read pkgName failed!");
1193 return SOFTBUS_IPC_ERR;
1194 }
1195 uint32_t code = SERVER_STOP_TIME_SYNC;
1196 SoftbusRecordCalledApiInfo(pkgName, code);
1197 const char *targetNetworkId = data.ReadCString();
1198 if (targetNetworkId == nullptr) {
1199 COMM_LOGE(COMM_SVC, "StopTimeSyncInner read targetNetworkId failed!");
1200 return SOFTBUS_IPC_ERR;
1201 }
1202 int32_t retReply = StopTimeSync(pkgName, targetNetworkId);
1203 if (!reply.WriteInt32(retReply)) {
1204 COMM_LOGE(COMM_SVC, "StopTimeSyncInner write reply failed!");
1205 return SOFTBUS_IPC_ERR;
1206 }
1207 return SOFTBUS_OK;
1208 }
1209
QosReportInner(MessageParcel & data,MessageParcel & reply)1210 int32_t SoftBusServerStub::QosReportInner(MessageParcel &data, MessageParcel &reply)
1211 {
1212 COMM_LOGD(COMM_SVC, "enter");
1213 int32_t channelId;
1214 if (!data.ReadInt32(channelId)) {
1215 COMM_LOGE(COMM_SVC, "QosReportInner read channel Id failed!");
1216 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1217 }
1218 int32_t channelType;
1219 if (!data.ReadInt32(channelType)) {
1220 COMM_LOGE(COMM_SVC, "QosReportInner read channel channel type failed!");
1221 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1222 }
1223 int32_t appType;
1224 if (!data.ReadInt32(appType)) {
1225 COMM_LOGE(COMM_SVC, "QosReportInner read channel appType failed!");
1226 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1227 }
1228 int32_t quality;
1229 if (!data.ReadInt32(quality)) {
1230 COMM_LOGE(COMM_SVC, "QosReportInner read quality failed!");
1231 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1232 }
1233 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
1234 int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
1235 if (ret != SOFTBUS_OK) {
1236 COMM_LOGE(COMM_SVC, "Pid can not get qos report, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
1237 callingPid, channelId, ret);
1238 return ret;
1239 }
1240 int32_t retReply = QosReport(channelId, channelType, appType, quality);
1241 if (!reply.WriteInt32(retReply)) {
1242 COMM_LOGE(COMM_SVC, "QosReportInner write reply failed!");
1243 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1244 }
1245 return SOFTBUS_OK;
1246 }
1247
StreamStatsInner(MessageParcel & data,MessageParcel & reply)1248 int32_t SoftBusServerStub::StreamStatsInner(MessageParcel &data, MessageParcel &reply)
1249 {
1250 int32_t channelId;
1251 if (!data.ReadInt32(channelId)) {
1252 COMM_LOGE(COMM_SVC, "StreamStatsInner read channelId fail");
1253 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1254 }
1255 int32_t channelType;
1256 if (!data.ReadInt32(channelType)) {
1257 COMM_LOGE(COMM_SVC, "StreamStatsInner read channelType fail");
1258 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1259 }
1260 StreamSendStats *stats = const_cast<StreamSendStats *>(
1261 reinterpret_cast<const StreamSendStats *>(data.ReadRawData(sizeof(StreamSendStats))));
1262 if (stats == nullptr) {
1263 COMM_LOGE(COMM_SVC, "read StreamSendStats fail, stats is nullptr");
1264 return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
1265 }
1266 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
1267 int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
1268 if (ret != SOFTBUS_OK) {
1269 COMM_LOGE(COMM_SVC, "Pid can not get stream stats, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
1270 callingPid, channelId, ret);
1271 return ret;
1272 }
1273 int32_t retReply = StreamStats(channelId, channelType, stats);
1274 if (!reply.WriteInt32(retReply)) {
1275 COMM_LOGE(COMM_SVC, "StreamStatsInner write reply fail");
1276 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1277 }
1278 return SOFTBUS_OK;
1279 }
1280
RippleStatsInner(MessageParcel & data,MessageParcel & reply)1281 int32_t SoftBusServerStub::RippleStatsInner(MessageParcel &data, MessageParcel &reply)
1282 {
1283 int32_t channelId;
1284 if (!data.ReadInt32(channelId)) {
1285 COMM_LOGE(COMM_SVC, "rippleStatsInner read channelId fail");
1286 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1287 }
1288 int32_t channelType;
1289 if (!data.ReadInt32(channelType)) {
1290 COMM_LOGE(COMM_SVC, "rippleStatsInner read channelType fail");
1291 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1292 }
1293 TrafficStats *stats =
1294 const_cast<TrafficStats *>(reinterpret_cast<const TrafficStats *>(data.ReadRawData(sizeof(TrafficStats))));
1295 if (stats == nullptr) {
1296 COMM_LOGE(COMM_SVC, "read rippleStats fail, stats is nullptr");
1297 return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
1298 }
1299 pid_t callingPid = OHOS::IPCSkeleton::GetCallingPid();
1300 int32_t ret = TransGetAndComparePid(callingPid, channelId, channelType);
1301 if (ret != SOFTBUS_OK) {
1302 COMM_LOGE(COMM_SVC, "Pid can not get pipple stats, pid=%{public}d, channelId=%{public}d, ret=%{public}d",
1303 callingPid, channelId, ret);
1304 return ret;
1305 }
1306 int32_t retReply = RippleStats(channelId, channelType, stats);
1307 if (!reply.WriteInt32(retReply)) {
1308 COMM_LOGE(COMM_SVC, "rippleStatsInner write reply fail");
1309 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1310 }
1311 return SOFTBUS_OK;
1312 }
1313
GrantPermissionInner(MessageParcel & data,MessageParcel & reply)1314 int32_t SoftBusServerStub::GrantPermissionInner(MessageParcel &data, MessageParcel &reply)
1315 {
1316 int32_t uid = 0;
1317 int32_t pid = 0;
1318 const char *sessionName = nullptr;
1319 uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
1320 int32_t ret = SoftBusCheckDynamicPermission(callingTokenId);
1321 if (ret != SOFTBUS_OK) {
1322 COMM_LOGE(COMM_SVC, "GrantPermissionInner check permission failed. ret=%{public}d!", ret);
1323 goto EXIT;
1324 }
1325
1326 uid = data.ReadInt32();
1327 pid = data.ReadInt32();
1328 sessionName = data.ReadCString();
1329 if (sessionName == nullptr) {
1330 COMM_LOGE(COMM_SVC, "GrantPermissionInner read sessionName failed!");
1331 goto EXIT;
1332 }
1333 ret = GrantTransPermission(uid, pid, sessionName);
1334 EXIT:
1335 if (!reply.WriteInt32(ret)) {
1336 COMM_LOGE(COMM_SVC, "GrantPermissionInner write reply failed!");
1337 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1338 }
1339 return SOFTBUS_OK;
1340 }
1341
RemovePermissionInner(MessageParcel & data,MessageParcel & reply)1342 int32_t SoftBusServerStub::RemovePermissionInner(MessageParcel &data, MessageParcel &reply)
1343 {
1344 const char *sessionName = nullptr;
1345 uint32_t callingTokenId = IPCSkeleton::GetCallingTokenID();
1346 int32_t ret = SoftBusCheckDynamicPermission(callingTokenId);
1347 if (ret != SOFTBUS_OK) {
1348 COMM_LOGE(COMM_SVC, "RemovePermissionInner check permission failed. ret=%{public}d!", ret);
1349 goto EXIT;
1350 }
1351
1352 sessionName = data.ReadCString();
1353 if (sessionName == nullptr) {
1354 COMM_LOGE(COMM_SVC, "RemovePermissionInner read sessionName failed!");
1355 goto EXIT;
1356 }
1357 ret = RemoveTransPermission(sessionName);
1358 EXIT:
1359 if (!reply.WriteInt32(ret)) {
1360 COMM_LOGE(COMM_SVC, "RemovePermissionInner write reply failed!");
1361 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1362 }
1363 return SOFTBUS_OK;
1364 }
1365
PublishLNNInner(MessageParcel & data,MessageParcel & reply)1366 int32_t SoftBusServerStub::PublishLNNInner(MessageParcel &data, MessageParcel &reply)
1367 {
1368 COMM_LOGD(COMM_SVC, "enter");
1369 const char *clientName = data.ReadCString();
1370 COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1371
1372 PublishInfo info = {0};
1373 int32_t value = 0;
1374 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(info.publishId), SOFTBUS_IPC_ERR, COMM_SVC,
1375 "read publishId failed");
1376 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read mode failed");
1377 COMM_CHECK_AND_RETURN_RET_LOGE(value == DISCOVER_MODE_PASSIVE || value == DISCOVER_MODE_ACTIVE,
1378 SOFTBUS_INVALID_PARAM, COMM_SVC, "mode invalid");
1379 info.mode = static_cast<DiscoverMode>(value);
1380 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read medium failed");
1381 COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < MEDIUM_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC,
1382 "medium invalid");
1383 info.medium = static_cast<ExchangeMedium>(value);
1384 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read freq failed");
1385 COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < FREQ_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC, "freq invalid");
1386 info.freq = static_cast<ExchangeFreq>(value);
1387 info.capability = data.ReadCString();
1388 COMM_CHECK_AND_RETURN_RET_LOGE(info.capability != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capability failed");
1389 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadUint32(info.dataLen), SOFTBUS_IPC_ERR, COMM_SVC, "read dataLen failed");
1390 if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
1391 const char *capabilityData = data.ReadCString();
1392 COMM_CHECK_AND_RETURN_RET_LOGE(capabilityData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capaData failed");
1393 COMM_CHECK_AND_RETURN_RET_LOGE(strlen(capabilityData) == info.dataLen, SOFTBUS_INVALID_PARAM, COMM_SVC,
1394 "capabilityData invalid");
1395 info.capabilityData = const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(capabilityData));
1396 } else {
1397 info.capabilityData = nullptr;
1398 info.dataLen = 0;
1399 }
1400 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.ranging), SOFTBUS_IPC_ERR, COMM_SVC, "read ranging failed");
1401
1402 int32_t retReply = PublishLNN(clientName, &info);
1403 COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1404 return SOFTBUS_OK;
1405 }
1406
StopPublishLNNInner(MessageParcel & data,MessageParcel & reply)1407 int32_t SoftBusServerStub::StopPublishLNNInner(MessageParcel &data, MessageParcel &reply)
1408 {
1409 COMM_LOGD(COMM_SVC, "enter");
1410 const char *clientName = data.ReadCString();
1411 COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1412
1413 int32_t publishId = 0;
1414 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(publishId), SOFTBUS_IPC_ERR, COMM_SVC, "read publishId failed");
1415
1416 int32_t retReply = StopPublishLNN(clientName, publishId);
1417 COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1418 return SOFTBUS_OK;
1419 }
1420
RefreshLNNInner(MessageParcel & data,MessageParcel & reply)1421 int32_t SoftBusServerStub::RefreshLNNInner(MessageParcel &data, MessageParcel &reply)
1422 {
1423 COMM_LOGD(COMM_SVC, "enter");
1424 const char *clientName = data.ReadCString();
1425 COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1426
1427 SubscribeInfo info = {0};
1428 int32_t value = 0;
1429 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(info.subscribeId), SOFTBUS_IPC_ERR, COMM_SVC,
1430 "read subscribeId failed");
1431 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read mode failed");
1432 COMM_CHECK_AND_RETURN_RET_LOGE(value == DISCOVER_MODE_PASSIVE || value == DISCOVER_MODE_ACTIVE,
1433 SOFTBUS_INVALID_PARAM, COMM_SVC, "mode invalid");
1434 info.mode = static_cast<DiscoverMode>(value);
1435 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read medium failed");
1436 COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < MEDIUM_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC,
1437 "medium invalid");
1438 info.medium = static_cast<ExchangeMedium>(value);
1439 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(value), SOFTBUS_IPC_ERR, COMM_SVC, "read freq failed");
1440 COMM_CHECK_AND_RETURN_RET_LOGE(0 <= value && value < FREQ_BUTT, SOFTBUS_INVALID_PARAM, COMM_SVC, "freq invalid");
1441 info.freq = static_cast<ExchangeFreq>(value);
1442 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.isSameAccount), SOFTBUS_IPC_ERR, COMM_SVC,
1443 "read isSameAccount failed");
1444 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadBool(info.isWakeRemote), SOFTBUS_IPC_ERR, COMM_SVC,
1445 "read isWakeRemote failed");
1446
1447 info.capability = data.ReadCString();
1448 COMM_CHECK_AND_RETURN_RET_LOGE(info.capability != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capability failed");
1449 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadUint32(info.dataLen), SOFTBUS_IPC_ERR, COMM_SVC, "read dataLen failed");
1450 if (info.dataLen > 0 && info.dataLen < MAX_CAPABILITYDATA_LEN) {
1451 const char *capabilityData = data.ReadCString();
1452 COMM_CHECK_AND_RETURN_RET_LOGE(capabilityData != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read capaData failed");
1453 COMM_CHECK_AND_RETURN_RET_LOGE(strlen(capabilityData) == info.dataLen, SOFTBUS_INVALID_PARAM, COMM_SVC,
1454 "capabilityData invalid");
1455 info.capabilityData = const_cast<unsigned char *>(reinterpret_cast<const unsigned char *>(capabilityData));
1456 } else {
1457 info.capabilityData = nullptr;
1458 info.dataLen = 0;
1459 }
1460
1461 int32_t retReply = RefreshLNN(clientName, &info);
1462 COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1463 return SOFTBUS_OK;
1464 }
1465
StopRefreshLNNInner(MessageParcel & data,MessageParcel & reply)1466 int32_t SoftBusServerStub::StopRefreshLNNInner(MessageParcel &data, MessageParcel &reply)
1467 {
1468 COMM_LOGD(COMM_SVC, "enter");
1469 const char *clientName = data.ReadCString();
1470 COMM_CHECK_AND_RETURN_RET_LOGE(clientName != nullptr, SOFTBUS_IPC_ERR, COMM_SVC, "read clientName failed");
1471
1472 int32_t refreshId = 0;
1473 COMM_CHECK_AND_RETURN_RET_LOGE(data.ReadInt32(refreshId), SOFTBUS_IPC_ERR, COMM_SVC, "read refreshId failed");
1474
1475 int32_t retReply = StopRefreshLNN(clientName, refreshId);
1476 COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1477 return SOFTBUS_OK;
1478 }
1479
ActiveMetaNodeInner(MessageParcel & data,MessageParcel & reply)1480 int32_t SoftBusServerStub::ActiveMetaNodeInner(MessageParcel &data, MessageParcel &reply)
1481 {
1482 COMM_LOGD(COMM_SVC, "enter");
1483 MetaNodeConfigInfo *info = const_cast<MetaNodeConfigInfo *>(
1484 reinterpret_cast<const MetaNodeConfigInfo *>(data.ReadRawData(sizeof(MetaNodeConfigInfo))));
1485 if (info == nullptr) {
1486 COMM_LOGE(COMM_SVC, "ActiveMetaNode read meta node config info failed!");
1487 return SOFTBUS_IPC_ERR;
1488 }
1489 char metaNodeId[NETWORK_ID_BUF_LEN] = { 0 };
1490 int32_t retReply = ActiveMetaNode(info, metaNodeId);
1491
1492 if (!reply.WriteCString(metaNodeId)) {
1493 COMM_LOGE(COMM_SVC, "ActiveMetaNode write meta node id failed!");
1494 return SOFTBUS_IPC_ERR;
1495 }
1496 COMM_CHECK_AND_RETURN_RET_LOGE(reply.WriteInt32(retReply), SOFTBUS_IPC_ERR, COMM_SVC, "write reply failed");
1497 return SOFTBUS_OK;
1498 }
1499
DeactiveMetaNodeInner(MessageParcel & data,MessageParcel & reply)1500 int32_t SoftBusServerStub::DeactiveMetaNodeInner(MessageParcel &data, MessageParcel &reply)
1501 {
1502 COMM_LOGD(COMM_SVC, "enter");
1503 const char *metaNodeId = reinterpret_cast<const char *>(data.ReadCString());
1504 if (metaNodeId == nullptr) {
1505 COMM_LOGE(COMM_SVC, "DeactiveMetaNode read meta node id failed!");
1506 return SOFTBUS_IPC_ERR;
1507 }
1508 if (DeactiveMetaNode(metaNodeId) != SOFTBUS_OK) {
1509 return SOFTBUS_NETWORK_DEACTIVE_META_NODE_ERR;
1510 }
1511 return SOFTBUS_OK;
1512 }
1513
GetAllMetaNodeInfoInner(MessageParcel & data,MessageParcel & reply)1514 int32_t SoftBusServerStub::GetAllMetaNodeInfoInner(MessageParcel &data, MessageParcel &reply)
1515 {
1516 COMM_LOGD(COMM_SVC, "enter");
1517 int32_t infoNum;
1518 MetaNodeInfo infos[MAX_META_NODE_NUM];
1519
1520 if (!data.ReadInt32(infoNum)) {
1521 COMM_LOGE(COMM_SVC, "GetAllMetaNodeInfo read infoNum failed!");
1522 return SOFTBUS_IPC_ERR;
1523 }
1524 if ((uint32_t)infoNum > MAX_META_NODE_NUM) {
1525 COMM_LOGE(COMM_SVC, "invalid param, infoNum=%{public}d, maxNum=%{public}d", infoNum, MAX_META_NODE_NUM);
1526 return SOFTBUS_IPC_ERR;
1527 }
1528 if (GetAllMetaNodeInfo(infos, &infoNum) != SOFTBUS_OK) {
1529 return SOFTBUS_NETWORK_GET_META_NODE_INFO_ERR;
1530 }
1531 if (!reply.WriteInt32(infoNum)) {
1532 COMM_LOGE(COMM_SVC, "GetAllMetaNodeInfo write infoNum failed!");
1533 return SOFTBUS_IPC_ERR;
1534 }
1535 if (infoNum > 0 && !reply.WriteRawData(infos, infoNum * sizeof(MetaNodeInfo))) {
1536 COMM_LOGE(COMM_SVC, "GetAllMetaNodeInfo write meta node info failed!");
1537 return SOFTBUS_IPC_ERR;
1538 }
1539 return SOFTBUS_OK;
1540 }
1541
ShiftLNNGearInner(MessageParcel & data,MessageParcel & reply)1542 int32_t SoftBusServerStub::ShiftLNNGearInner(MessageParcel &data, MessageParcel &reply)
1543 {
1544 COMM_LOGD(COMM_SVC, "enter");
1545 const char *targetNetworkId = nullptr;
1546 const GearMode *mode = nullptr;
1547
1548 const char *pkgName = data.ReadCString();
1549 if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1550 COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read pkgName failed!");
1551 return SOFTBUS_TRANS_PROXY_WRITECSTRING_FAILED;
1552 }
1553 uint32_t code = SERVER_SHIFT_LNN_GEAR;
1554 SoftbusRecordCalledApiInfo(pkgName, code);
1555 const char *callerId = data.ReadCString();
1556 if (callerId == nullptr || strnlen(callerId, CALLER_ID_MAX_LEN) >= CALLER_ID_MAX_LEN) {
1557 COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read callerId failed!");
1558 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1559 }
1560 if (!data.ReadBool()) {
1561 targetNetworkId = data.ReadCString();
1562 if (targetNetworkId == nullptr || strnlen(targetNetworkId, NETWORK_ID_BUF_LEN) != NETWORK_ID_BUF_LEN - 1) {
1563 COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read targetNetworkId failed!");
1564 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1565 }
1566 }
1567 mode = reinterpret_cast<const GearMode *>(data.ReadRawData(sizeof(GearMode)));
1568 if (mode == nullptr) {
1569 COMM_LOGE(COMM_SVC, "ShiftLNNGearInner read mode failed!");
1570 return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
1571 }
1572 int32_t retReply = ShiftLNNGear(pkgName, callerId, targetNetworkId, mode);
1573 if (!reply.WriteInt32(retReply)) {
1574 COMM_LOGE(COMM_SVC, "ShiftLNNGearInner write reply failed!");
1575 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1576 }
1577 return SOFTBUS_OK;
1578 }
1579
TriggerHbForMeasureDistanceInner(MessageParcel & data,MessageParcel & reply)1580 int32_t SoftBusServerStub::TriggerHbForMeasureDistanceInner(MessageParcel &data, MessageParcel &reply)
1581 {
1582 COMM_LOGD(COMM_SVC, "enter");
1583 const HbMode *mode = nullptr;
1584
1585 const char *pkgName = data.ReadCString();
1586 if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1587 COMM_LOGE(COMM_SVC, "read pkgName failed!");
1588 return SOFTBUS_TRANS_PROXY_WRITECSTRING_FAILED;
1589 }
1590 uint32_t code = SERVER_TRIGGER_HB_FOR_RANGE;
1591 SoftbusRecordCalledApiInfo(pkgName, code);
1592 const char *callerId = data.ReadCString();
1593 if (callerId == nullptr || strnlen(callerId, CALLER_ID_MAX_LEN) >= CALLER_ID_MAX_LEN) {
1594 COMM_LOGE(COMM_SVC, "read callerId failed!");
1595 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1596 }
1597 mode = reinterpret_cast<const HbMode *>(data.ReadRawData(sizeof(HbMode)));
1598 if (mode == nullptr) {
1599 COMM_LOGE(COMM_SVC, "read mode failed!");
1600 return SOFTBUS_TRANS_PROXY_READRAWDATA_FAILED;
1601 }
1602 int32_t retReply = TriggerHbForMeasureDistance(pkgName, callerId, mode);
1603 if (!reply.WriteInt32(retReply)) {
1604 COMM_LOGE(COMM_SVC, "write reply failed!");
1605 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1606 }
1607 return SOFTBUS_OK;
1608 }
1609
RegBleRangeCbInner(MessageParcel & data,MessageParcel & reply)1610 int32_t SoftBusServerStub::RegBleRangeCbInner(MessageParcel &data, MessageParcel &reply)
1611 {
1612 COMM_LOGI(COMM_SVC, "enter");
1613 #ifndef ENHANCED_FLAG
1614 (void)data;
1615 (void)reply;
1616 (void)MSDP_PACKAGE_NAME;
1617 return SOFTBUS_FUNC_NOT_SUPPORT;
1618 #else
1619 const char *pkgName = data.ReadCString();
1620 if (pkgName == nullptr) {
1621 COMM_LOGE(COMM_SVC, "read pkgName failed");
1622 return SOFTBUS_IPC_ERR;
1623 }
1624 if (strcmp(MSDP_PACKAGE_NAME, pkgName) != 0) {
1625 COMM_LOGE(COMM_SVC, "read pkgName invalid");
1626 return SOFTBUS_INVALID_PARAM;
1627 }
1628 int32_t retReply = RegBleRangeCb(pkgName);
1629 if (!reply.WriteInt32(retReply)) {
1630 COMM_LOGE(COMM_SVC, "write reply failed");
1631 return SOFTBUS_IPC_ERR;
1632 }
1633 return SOFTBUS_OK;
1634 #endif
1635 }
1636
UnregBleRangeCbInner(MessageParcel & data,MessageParcel & reply)1637 int32_t SoftBusServerStub::UnregBleRangeCbInner(MessageParcel &data, MessageParcel &reply)
1638 {
1639 COMM_LOGI(COMM_SVC, "enter");
1640 #ifndef ENHANCED_FLAG
1641 (void)data;
1642 (void)reply;
1643 (void)MSDP_PACKAGE_NAME;
1644 return SOFTBUS_FUNC_NOT_SUPPORT;
1645 #else
1646 const char *pkgName = data.ReadCString();
1647 if (pkgName == nullptr) {
1648 COMM_LOGE(COMM_SVC, "read pkgName failed");
1649 return SOFTBUS_IPC_ERR;
1650 }
1651 if (strcmp(MSDP_PACKAGE_NAME, pkgName) != 0) {
1652 COMM_LOGE(COMM_SVC, "read pkgName invalid");
1653 return SOFTBUS_INVALID_PARAM;
1654 }
1655 int32_t retReply = UnregBleRangeCb(pkgName);
1656 if (!reply.WriteInt32(retReply)) {
1657 COMM_LOGE(COMM_SVC, "write reply failed");
1658 return SOFTBUS_IPC_ERR;
1659 }
1660 return SOFTBUS_OK;
1661 #endif
1662 }
1663
SyncTrustedRelationShipInner(MessageParcel & data,MessageParcel & reply)1664 int32_t SoftBusServerStub::SyncTrustedRelationShipInner(MessageParcel &data, MessageParcel &reply)
1665 {
1666 COMM_LOGD(COMM_SVC, "enter");
1667
1668 const char *pkgName = data.ReadCString();
1669 if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1670 COMM_LOGE(COMM_SVC, "read pkgName failed!");
1671 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1672 }
1673 if (strcmp(DM_PACKAGE_NAME, pkgName) != 0) {
1674 COMM_LOGE(COMM_SVC, "read pkgName invalid!");
1675 return SOFTBUS_INVALID_PARAM;
1676 }
1677 SoftbusRecordCalledApiInfo(pkgName, SERVER_SYNC_TRUSTED_RELATION);
1678 const char *msg = data.ReadCString();
1679 if (msg == nullptr) {
1680 COMM_LOGE(COMM_SVC, "read msg failed!");
1681 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1682 }
1683 uint32_t msgLen = data.ReadUint32();
1684 if (msgLen > MSG_MAX_SIZE || msgLen != strlen(msg)) {
1685 COMM_LOGE(COMM_SVC, "msgLen invalid!, msgLen=%{public}u", msgLen);
1686 return SOFTBUS_INVALID_PARAM;
1687 }
1688 int32_t retReply = SyncTrustedRelationShip(pkgName, msg, msgLen);
1689 if (!reply.WriteInt32(retReply)) {
1690 COMM_LOGE(COMM_SVC, "write reply failed");
1691 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1692 }
1693 return SOFTBUS_OK;
1694 }
1695
GetSoftbusSpecObjectInner(MessageParcel & data,MessageParcel & reply)1696 int32_t SoftBusServerStub::GetSoftbusSpecObjectInner(MessageParcel &data, MessageParcel &reply)
1697 {
1698 sptr<IRemoteObject> object;
1699 int32_t ret = GetSoftbusSpecObject(object);
1700 if (!reply.WriteInt32(ret)) {
1701 COMM_LOGE(COMM_SVC, "GetSoftbusSpecObjectInner write reply failed!");
1702 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1703 }
1704 if (ret == SOFTBUS_OK) {
1705 if (!reply.WriteRemoteObject(object)) {
1706 COMM_LOGE(COMM_SVC, "GetSoftbusSpecObjectInner write object failed!");
1707 return SOFTBUS_TRANS_PROXY_WRITEOBJECT_FAILED;
1708 }
1709 }
1710 return SOFTBUS_OK;
1711 }
1712
GetBusCenterExObjInner(MessageParcel & data,MessageParcel & reply)1713 int32_t SoftBusServerStub::GetBusCenterExObjInner(MessageParcel &data, MessageParcel &reply)
1714 {
1715 sptr<IRemoteObject> object;
1716 int32_t ret = GetBusCenterExObj(object);
1717 if (!reply.WriteInt32(ret)) {
1718 COMM_LOGE(COMM_SVC, "GetBusCenterExObjInner write reply failed!");
1719 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1720 }
1721 if (ret == SOFTBUS_OK) {
1722 if (!reply.WriteRemoteObject(object)) {
1723 COMM_LOGE(COMM_SVC, "GetBusCenterExObjInner write object failed!");
1724 return SOFTBUS_TRANS_PROXY_WRITEOBJECT_FAILED;
1725 }
1726 }
1727 return SOFTBUS_OK;
1728 }
1729
ProcessInnerEventInner(MessageParcel & data,MessageParcel & reply)1730 int32_t SoftBusServerStub::ProcessInnerEventInner(MessageParcel &data, MessageParcel &reply)
1731 {
1732 int32_t eventType = 0;
1733 if (!data.ReadInt32(eventType)) {
1734 COMM_LOGE(COMM_SVC, "read eventType failed!");
1735 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1736 }
1737 uint32_t len = 0;
1738 if (!data.ReadUint32(len)) {
1739 COMM_LOGE(COMM_SVC, "read len failed!");
1740 return SOFTBUS_TRANS_PROXY_READUINT_FAILED;
1741 }
1742 auto rawData = data.ReadRawData(len);
1743 if (rawData == NULL) {
1744 COMM_LOGE(COMM_SVC, "read rawData failed!");
1745 return SOFTBUS_IPC_ERR;
1746 }
1747 uint8_t *buf = const_cast<uint8_t *>(reinterpret_cast<const uint8_t *>(rawData));
1748 int32_t ret = ProcessInnerEvent(eventType, buf, len);
1749 COMM_CHECK_AND_RETURN_RET_LOGE(
1750 ret == SOFTBUS_OK, ret, COMM_SVC, "process inner event failed! eventType=%{public}d", eventType);
1751 return SOFTBUS_OK;
1752 }
1753
PrivilegeCloseChannelInner(MessageParcel & data,MessageParcel & reply)1754 int32_t SoftBusServerStub::PrivilegeCloseChannelInner(MessageParcel &data, MessageParcel &reply)
1755 {
1756 COMM_LOGD(COMM_SVC, "enter");
1757 int32_t callingUid = OHOS::IPCSkeleton::GetCallingUid();
1758 if (callingUid != DMS_CALLING_UID) {
1759 COMM_LOGE(COMM_PERM, "uid check failed");
1760 return SOFTBUS_PERMISSION_DENIED;
1761 }
1762 uint64_t callingTokenId = IPCSkeleton::GetCallingTokenID();
1763 int32_t ret = SoftBusCheckDmsServerPermission(callingTokenId);
1764 if (ret != SOFTBUS_OK) {
1765 COMM_LOGE(COMM_SVC, "check permission failed. ret=%{public}d", ret);
1766 if (!reply.WriteInt32(ret)) {
1767 COMM_LOGE(COMM_SVC, "write reply failed!");
1768 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1769 }
1770 return ret;
1771 }
1772 uint64_t tokenId;
1773 if (!data.ReadUint64(tokenId)) {
1774 COMM_LOGE(COMM_SVC, "read tokenId failed!");
1775 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1776 }
1777 int32_t pid;
1778 if (!data.ReadInt32(pid)) {
1779 COMM_LOGE(COMM_SVC, "read pid failed!");
1780 return SOFTBUS_TRANS_PROXY_READINT_FAILED;
1781 }
1782 const char *peerNetworkId = data.ReadCString();
1783 if (peerNetworkId == nullptr) {
1784 COMM_LOGE(COMM_SVC, "network id is null!");
1785 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1786 }
1787 ret = PrivilegeCloseChannel(tokenId, pid, peerNetworkId);
1788 if (!reply.WriteInt32(ret)) {
1789 COMM_LOGE(COMM_SVC, "write reply failed, ret=%{public}d", ret);
1790 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1791 }
1792 return SOFTBUS_OK;
1793 }
1794
SetDisplayNameInner(MessageParcel & data,MessageParcel & reply)1795 int32_t SoftBusServerStub::SetDisplayNameInner(MessageParcel &data, MessageParcel &reply)
1796 {
1797 COMM_LOGD(COMM_SVC, "enter");
1798 const char *pkgName = data.ReadCString();
1799 if (pkgName == nullptr || strnlen(pkgName, PKG_NAME_SIZE_MAX) >= PKG_NAME_SIZE_MAX) {
1800 COMM_LOGE(COMM_SVC, "read pkgName failed!");
1801 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1802 }
1803 if (strcmp(DM_PACKAGE_NAME, pkgName) != 0) {
1804 COMM_LOGE(COMM_SVC, "read pkgName invalid!");
1805 return SOFTBUS_INVALID_PARAM;
1806 }
1807 SoftbusRecordCalledApiInfo(pkgName, SERVER_SET_DISPLAY_NAME);
1808 const char *nameData = data.ReadCString();
1809 if (nameData == nullptr) {
1810 COMM_LOGE(COMM_SVC, "read nameData failed!");
1811 return SOFTBUS_TRANS_PROXY_READCSTRING_FAILED;
1812 }
1813 uint32_t len = data.ReadUint32();
1814 if (len > MSG_MAX_SIZE || len != strlen(nameData)) {
1815 COMM_LOGE(COMM_SVC, "len invalid!, len=%{public}u", len);
1816 return SOFTBUS_INVALID_PARAM;
1817 }
1818 int32_t retReply = SetDisplayName(pkgName, nameData, len);
1819 if (!reply.WriteInt32(retReply)) {
1820 COMM_LOGE(COMM_SVC, "write reply failed");
1821 return SOFTBUS_TRANS_PROXY_WRITEINT_FAILED;
1822 }
1823 return SOFTBUS_OK;
1824 }
1825
1826 } // namespace OHOS
1827