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