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