1c29fa5a6Sopenharmony_ci/* 2c29fa5a6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License. 5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at 6c29fa5a6Sopenharmony_ci * 7c29fa5a6Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8c29fa5a6Sopenharmony_ci * 9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and 13c29fa5a6Sopenharmony_ci * limitations under the License. 14c29fa5a6Sopenharmony_ci */ 15c29fa5a6Sopenharmony_ci 16c29fa5a6Sopenharmony_ci#include "socket_server.h" 17c29fa5a6Sopenharmony_ci 18c29fa5a6Sopenharmony_ci#include "accesstoken_kit.h" 19c29fa5a6Sopenharmony_ci 20c29fa5a6Sopenharmony_ci#include "devicestatus_define.h" 21c29fa5a6Sopenharmony_ci#include "socket_params.h" 22c29fa5a6Sopenharmony_ci 23c29fa5a6Sopenharmony_ci#undef LOG_TAG 24c29fa5a6Sopenharmony_ci#define LOG_TAG "SocketServer" 25c29fa5a6Sopenharmony_ci 26c29fa5a6Sopenharmony_cinamespace OHOS { 27c29fa5a6Sopenharmony_cinamespace Msdp { 28c29fa5a6Sopenharmony_cinamespace DeviceStatus { 29c29fa5a6Sopenharmony_ci 30c29fa5a6Sopenharmony_ciSocketServer::SocketServer(IContext *context) 31c29fa5a6Sopenharmony_ci : context_(context) 32c29fa5a6Sopenharmony_ci{} 33c29fa5a6Sopenharmony_ci 34c29fa5a6Sopenharmony_ciint32_t SocketServer::Enable(CallingContext &context, MessageParcel &data, MessageParcel &reply) 35c29fa5a6Sopenharmony_ci{ 36c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 37c29fa5a6Sopenharmony_ci return RET_ERR; 38c29fa5a6Sopenharmony_ci} 39c29fa5a6Sopenharmony_ci 40c29fa5a6Sopenharmony_ciint32_t SocketServer::Disable(CallingContext &context, MessageParcel &data, MessageParcel &reply) 41c29fa5a6Sopenharmony_ci{ 42c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 43c29fa5a6Sopenharmony_ci return RET_ERR; 44c29fa5a6Sopenharmony_ci} 45c29fa5a6Sopenharmony_ci 46c29fa5a6Sopenharmony_ciint32_t SocketServer::Start(CallingContext &context, MessageParcel &data, MessageParcel &reply) 47c29fa5a6Sopenharmony_ci{ 48c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 49c29fa5a6Sopenharmony_ci return RET_ERR; 50c29fa5a6Sopenharmony_ci} 51c29fa5a6Sopenharmony_ci 52c29fa5a6Sopenharmony_ciint32_t SocketServer::Stop(CallingContext &context, MessageParcel &data, MessageParcel &reply) 53c29fa5a6Sopenharmony_ci{ 54c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 55c29fa5a6Sopenharmony_ci return RET_ERR; 56c29fa5a6Sopenharmony_ci} 57c29fa5a6Sopenharmony_ci 58c29fa5a6Sopenharmony_ciint32_t SocketServer::AddWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 59c29fa5a6Sopenharmony_ci{ 60c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 61c29fa5a6Sopenharmony_ci return RET_ERR; 62c29fa5a6Sopenharmony_ci} 63c29fa5a6Sopenharmony_ci 64c29fa5a6Sopenharmony_ciint32_t SocketServer::RemoveWatch(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 65c29fa5a6Sopenharmony_ci{ 66c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 67c29fa5a6Sopenharmony_ci return RET_ERR; 68c29fa5a6Sopenharmony_ci} 69c29fa5a6Sopenharmony_ci 70c29fa5a6Sopenharmony_ciint32_t SocketServer::SetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 71c29fa5a6Sopenharmony_ci{ 72c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 73c29fa5a6Sopenharmony_ci return RET_ERR; 74c29fa5a6Sopenharmony_ci} 75c29fa5a6Sopenharmony_ci 76c29fa5a6Sopenharmony_ciint32_t SocketServer::GetParam(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 77c29fa5a6Sopenharmony_ci{ 78c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 79c29fa5a6Sopenharmony_ci return RET_ERR; 80c29fa5a6Sopenharmony_ci} 81c29fa5a6Sopenharmony_ci 82c29fa5a6Sopenharmony_ciint32_t SocketServer::Control(CallingContext &context, uint32_t id, MessageParcel &data, MessageParcel &reply) 83c29fa5a6Sopenharmony_ci{ 84c29fa5a6Sopenharmony_ci CALL_DEBUG_ENTER; 85c29fa5a6Sopenharmony_ci if (id != SocketAction::SOCKET_ACTION_CONNECT) { 86c29fa5a6Sopenharmony_ci FI_HILOGE("Unsupported action"); 87c29fa5a6Sopenharmony_ci return RET_ERR; 88c29fa5a6Sopenharmony_ci } 89c29fa5a6Sopenharmony_ci AllocSocketPairParam param; 90c29fa5a6Sopenharmony_ci if (!param.Unmarshalling(data)) { 91c29fa5a6Sopenharmony_ci FI_HILOGE("AllocSocketPairParam::Unmarshalling fail"); 92c29fa5a6Sopenharmony_ci return RET_ERR; 93c29fa5a6Sopenharmony_ci } 94c29fa5a6Sopenharmony_ci int32_t tokenType = Security::AccessToken::AccessTokenKit::GetTokenTypeFlag(context.tokenId); 95c29fa5a6Sopenharmony_ci int32_t clientFd { -1 }; 96c29fa5a6Sopenharmony_ci CHKPR(context_, RET_ERR); 97c29fa5a6Sopenharmony_ci int32_t ret = context_->GetSocketSessionManager().AllocSocketFd( 98c29fa5a6Sopenharmony_ci param.programName, param.moduleType, tokenType, context.uid, context.pid, clientFd); 99c29fa5a6Sopenharmony_ci if (ret != RET_OK) { 100c29fa5a6Sopenharmony_ci FI_HILOGE("AllocSocketFd failed"); 101c29fa5a6Sopenharmony_ci return RET_ERR; 102c29fa5a6Sopenharmony_ci } 103c29fa5a6Sopenharmony_ci AllocSocketPairReply replyData(tokenType, clientFd); 104c29fa5a6Sopenharmony_ci if (!replyData.Marshalling(reply)) { 105c29fa5a6Sopenharmony_ci FI_HILOGE("AllocSocketPairReply::Marshalling fail"); 106c29fa5a6Sopenharmony_ci return RET_ERR; 107c29fa5a6Sopenharmony_ci } 108c29fa5a6Sopenharmony_ci return RET_OK; 109c29fa5a6Sopenharmony_ci} 110c29fa5a6Sopenharmony_ci} // namespace DeviceStatus 111c29fa5a6Sopenharmony_ci} // namespace Msdp 112c29fa5a6Sopenharmony_ci} // namespace OHOS 113