diff --git a/BUILD.gn b/BUILD.gn index 296cc040a..ad0d45733 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -121,7 +121,10 @@ ohos_shared_library("tel_core_service") { "services/core/src/core_service_stub.cpp", ] if (core_service_support_esim) { - sources += [ "$TELEPHONY_SIM_ROOT/src/esim_file.cpp" ] + sources += [ + "$TELEPHONY_SIM_ROOT/src/esim_controller.cpp", + "$TELEPHONY_SIM_ROOT/src/esim_file.cpp", + ] } include_dirs = [ diff --git a/services/sim/include/esim_controller.h b/services/sim/include/esim_controller.h new file mode 100644 index 000000000..ea43ae39b --- /dev/null +++ b/services/sim/include/esim_controller.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TELEPHONY_ESIM_CONTROLLER_H +#define TELEPHONY_ESIM_CONTROLLER_H + +#include +#include + +namespace OHOS { +namespace Telephony { + +typedef int (*VerifyBind)(int slotId, const char* command, size_t commandLen); + +class EsimController : public DelayedRefSingleton { + DECLARE_DELAYED_REF_SINGLETON(EsimController); + +public: + bool ChecIsVerifyBindCommand(const std::string& cmdData); + void ProcessCommandMessage(int slotId, const std::string& cmdData); + void ProcessCommandByCa(int slotId, const std::string cmdData); +private: + std::mutex caMutex_; +}; +} // namespace Telephony +} // namespace OHOS +#endif // TELEPHONY_ESIM_CONTROLLER_H diff --git a/services/sim/src/esim_controller.cpp b/services/sim/src/esim_controller.cpp new file mode 100644 index 000000000..7ce8bfa08 --- /dev/null +++ b/services/sim/src/esim_controller.cpp @@ -0,0 +1,95 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "esim_controller.h" + +#include +#include +#include + +#include "ffrt.h" +#include "telephony_log_wrapper.h" + +namespace OHOS { +namespace Telephony { + +static const std::string CHECK_CMD_HEAD = "D0"; +static const std::string CHECK_CMD_TAG = "81"; +static const std::string CHECK_GET_INPUT_TAG = "23"; +static const std::string VERIFY_BIND_START_DATA = "0456657269667942696E645374617274"; +static const std::string VERIFY_BIND_END_DATA = "0456657269667942696E64456E64"; +static const std::string ESIM_CA_LIBPATH = "/system/lib64/libesim_ca.z.so"; + +constexpr size_t CHECK_CMD_HEAD_START = 0; +constexpr size_t CHECK_CMD_TAG_START = 4; +constexpr size_t CHECK_GET_INPUT_TAG_START = 10; +constexpr size_t GET_INPUT_DATA_START = 26; +constexpr size_t COMPARE_EQUAL_VALUE = 0; + +EsimController::EsimController() {} + +EsimController::~EsimController() {} + +bool EsimController::ChecIsVerifyBindCommand(const std::string& cmdData) +{ + std::string checkCmdData = cmdData; + std::transform(checkCmdData.begin(), checkCmdData.end(), checkCmdData.begin(), ::toupper); + if (checkCmdData.compare(CHECK_CMD_HEAD_START, CHECK_CMD_HEAD.length(), + CHECK_CMD_HEAD) != COMPARE_EQUAL_VALUE) { + return false; + } + if (checkCmdData.compare(CHECK_CMD_TAG_START, CHECK_CMD_TAG.length(), + CHECK_CMD_TAG) != COMPARE_EQUAL_VALUE) { + return false; + } + if (checkCmdData.compare(CHECK_GET_INPUT_TAG_START, CHECK_GET_INPUT_TAG.length(), + CHECK_GET_INPUT_TAG) != COMPARE_EQUAL_VALUE) { + return false; + } + if (checkCmdData.compare(GET_INPUT_DATA_START, VERIFY_BIND_START_DATA.length(), + VERIFY_BIND_START_DATA) == COMPARE_EQUAL_VALUE) { + return true; + } + return (checkCmdData.compare(GET_INPUT_DATA_START, VERIFY_BIND_END_DATA.length(), + VERIFY_BIND_END_DATA) == COMPARE_EQUAL_VALUE); +} + +void EsimController::ProcessCommandMessage(int slotId, const std::string& cmdData) +{ + TELEPHONY_LOGI("EsimController:Start process verify bind message."); + ffrt::submit([=]() { + this->ProcessCommandByCa(slotId, cmdData); + }); +} + +void EsimController::ProcessCommandByCa(int slotId, const std::string cmdData) +{ + std::lock_guard locker(caMutex_); + void *handler = dlopen(ESIM_CA_LIBPATH.c_str(), RTLD_LAZY); + if (handler == NULL) { + TELEPHONY_LOGE("open lib: %{public}s failed", ESIM_CA_LIBPATH.c_str()); + return; + } + + VerifyBind func = (VerifyBind)dlsym(handler, "CAEsimStartEuiccCheckBinding"); + if (func == NULL) { + TELEPHONY_LOGE("dlsym CAEsimStartEuiccCheckBinding failed, error:%{public}s", dlerror()); + } else { + func(slotId, cmdData.c_str(), cmdData.length()); + } + dlclose(handler); +} +} // namespace Telephony +} // namespace OHOS diff --git a/services/sim/src/stk_controller.cpp b/services/sim/src/stk_controller.cpp index cdd175646..5ab430233 100755 --- a/services/sim/src/stk_controller.cpp +++ b/services/sim/src/stk_controller.cpp @@ -22,6 +22,9 @@ #include "common_event_publish_info.h" #include "common_event_support.h" #include "extension_ability_info.h" +#ifdef CORE_SERVICE_SUPPORT_ESIM +#include "esim_controller.h" +#endif #include "tel_ril_types.h" #include "if_system_ability_manager.h" #include "iservice_registry.h" @@ -372,6 +375,13 @@ void StkController::OnSendRilProactiveCommand(const AppExecFwk::InnerEvent::Poin return; } +#ifdef CORE_SERVICE_SUPPORT_ESIM + if (EsimController::GetInstance().ChecIsVerifyBindCommand(cmdData)) { + EsimController::GetInstance().ProcessCommandMessage(slotId_, cmdData); + return; + } +#endif + AAFwk::Want want; want.SetAction(EventFwk::CommonEventSupport::COMMON_EVENT_STK_COMMAND); want.SetParam(PARAM_SLOTID, slotId_);