From 14c390cf0b683ccc7d4bba0e45673a241d4deb74 Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 10:43:39 +0000 Subject: [PATCH 1/9] extended certification Signed-off-by: shihaojie --- bundle.json | 1 + frameworks/js/napi/ethernet/BUILD.gn | 5 +- .../js/napi/ethernet/customeap/BUILD.gn | 71 ++++ .../napi/ethernet/customeap/eap_event_mgr.cpp | 349 ++++++++++++++++++ 4 files changed, 425 insertions(+), 1 deletion(-) create mode 100644 frameworks/js/napi/ethernet/customeap/BUILD.gn create mode 100644 frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp diff --git a/bundle.json b/bundle.json index efd7dccc..1354a8b5 100644 --- a/bundle.json +++ b/bundle.json @@ -40,6 +40,7 @@ "netmanager_ext_feature_vpn_for_user0", "netmanager_ext_share_traffic_limit_enable", "netmanager_ext_feature_networkslice", + "netmanager_ext_extensible_authentication", "netmanager_ext_share_notification_enable" ], "adapted_system_type": [ diff --git a/frameworks/js/napi/ethernet/BUILD.gn b/frameworks/js/napi/ethernet/BUILD.gn index feeb06e2..f7fd5d38 100644 --- a/frameworks/js/napi/ethernet/BUILD.gn +++ b/frameworks/js/napi/ethernet/BUILD.gn @@ -56,7 +56,10 @@ ohos_shared_library("ethernet") { "-O2", ] - deps = [ "$EXT_INNERKITS_ROOT/ethernetclient:ethernet_manager_if" ] + deps = [ + "$EXT_INNERKITS_ROOT/ethernetclient:ethernet_manager_if", + "$NETMANAGER_EXT_ROOT/frameworks/js/napi/ethernet/customeap:eap", + ] external_deps = [ "c_utils:utils", diff --git a/frameworks/js/napi/ethernet/customeap/BUILD.gn b/frameworks/js/napi/ethernet/customeap/BUILD.gn new file mode 100644 index 00000000..bd4f7466 --- /dev/null +++ b/frameworks/js/napi/ethernet/customeap/BUILD.gn @@ -0,0 +1,71 @@ +# Copyright (c) 2025-2025 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. + +import("//build/ohos.gni") +import("//foundation/communication/netmanager_ext/netmanager_ext_config.gni") + +ohos_shared_library("eap") { + sanitize = { + cfi = true + cfi_cross_dso = true + boundary_sanitize = true + ubsan = true + debug = true + } + + branch_protector_ret = "pac_ret" + + include_dirs = [ + "$NETMANAGER_EXT_ROOT/utils/log/include", + ] + + sources = [ + "eap_event_mgr.cpp", + "eap_module.cpp", + "eap_napi_event.cpp", + "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/eap_data.cpp", + ] + + cflags = [ + "-fstack-protector-strong", + "-D_FORTIFY_SOURCE=2", + "-O2", + ] + + cflags_cc = [ + "-fstack-protector-strong", + "-D_FORTIFY_SOURCE=2", + "-O2", + ] + + deps = [ "$EXT_INNERKITS_ROOT/ethernetclient:ethernet_manager_if" ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "ipc:ipc_core", + "napi:ace_napi", + "netmanager_base:napi_utils", + "netmanager_base:net_conn_manager_if", + "netmanager_base:net_manager_common", + "samgr:samgr_proxy", + ] + defines = [] + if (netmanager_ext_extensible_authentication) { + defines += [ "NET_EXTENSIBLE_AUTHENTICATION" ] + } + + relative_install_dir = "module/net" + part_name = "netmanager_ext" + subsystem_name = "communication" +} \ No newline at end of file diff --git a/frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp new file mode 100644 index 00000000..300e0a57 --- /dev/null +++ b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.cpp @@ -0,0 +1,349 @@ +/* + * Copyright (c) 2025-2025 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 +#include "napi/native_node_api.h" +#include "eap_event_mgr.h" +namespace OHOS { +namespace NetManagerStandard { + +#define REGISTERINFO_MAX_NUM 16 +#define WIFI_DEVICE_SA_ID 1120 +#define COMM_NET_CONN_MANAGER_SA_ID 1151 +static constexpr uint32_t INVALID_REF_COUNT = 0xff; +static constexpr const char *EAP_BUFFER = "eapBuffer"; +static constexpr const char *EAP_BUFFERLEN = "bufferLen"; +static constexpr const char *EAP_MSGID = "msgId"; +using TypeMapRegObj = std::map>; +static std::shared_mutex g_regInfoMutex; +static std::map g_eventRegisterInfo; + +int32_t NetEapPostBackCallback::OnEapSupplicantPostback(NetType netType, const sptr &eapData) +{ + if (eapData == nullptr) { + NETMANAGER_EXT_LOGE("%{public}s eapData is nullptr.", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + if (eapData->eapCode < EAP_CODE_MIN || eapData->eapCode > EAP_CODE_MAX) { + NETMANAGER_EXT_LOGE("eapCode %{public}d invalid.", eapData->eapCode); + return NETMANAGER_ERR_PARAMETER_ERROR; + } + if (eapData->eapBuffer.size() == 0) { + NETMANAGER_EXT_LOGE("%{public}s eapBuffer size is 0. %{public}s", __func__, eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_PARAMETER_ERROR; + } + NETMANAGER_EXT_LOGI("%{public}s: eapCode:%{public}d, eapType:%{public}d, buffsize:%{public}zu", __func__, + eapData->eapCode, eapData->eapType, eapData->eapBuffer.size()); + uint32_t composeParam = (eapData->eapCode << 8) | eapData->eapType; + return CheckAndNotifyApp(netType, composeParam, eapData); +} + +napi_value NetEapPostBackCallback::CreateResult(const napi_env& env, const sptr &eapData) +{ + napi_value obj = NapiUtils::CreateObject(env); + if (NapiUtils::GetValueType(env, obj) != napi_object) { + return NapiUtils::GetUndefined(env); + } + + NapiUtils::SetVectorUint8Property(env, obj, EAP_BUFFER, eapData->eapBuffer); + NapiUtils::SetUint32Property(env, obj, EAP_BUFFERLEN, eapData->bufferLen); + NapiUtils::SetUint32Property(env, obj, EAP_MSGID, eapData->msgId); + return obj; +} + +bool NetEapPostBackCallback::CheckAndNotifyApp(NetType netType, const int32_t key, const sptr &eapData) +{ + std::shared_lock lock(g_regInfoMutex); + auto netTypeIter = g_eventRegisterInfo.find(netType); + if (netTypeIter == g_eventRegisterInfo.end()) { + NETMANAGER_EXT_LOGE("%{public}s, netType %{public}d not find register info.", __func__, netType); + return false; + } + auto it = netTypeIter->second.find(key); + if (it == netTypeIter->second.end()) { + NETMANAGER_EXT_LOGE("%{public}s, not find register info.", __func__); + return false; + } + for (auto& each : it->second) { + auto func = [this, env = each.m_regEnv, eapData] () -> napi_value { return this->CreateResult(env, eapData); }; + std::shared_ptr asyncEvent = std::make_shared(each.m_regEnv, each.m_regHandlerRef, func); + asyncEvent->Init(key, netType, eapData->msgId); + EventNotify(asyncEvent); + } + return true; +} + +void NetEapPostBackCallback::SendTask(const std::shared_ptr &asyncEvent) +{ + napi_value handler = nullptr; + napi_value jsEvent = nullptr; + napi_value undefine; + uint32_t refCount = INVALID_REF_COUNT; + napi_status res; + bool unrefRef = false; + bool find = false; + InitScope(asyncEvent); + auto it = g_eventRegisterInfo[asyncEvent->netType_].find(asyncEvent->key_); + if (it == g_eventRegisterInfo[asyncEvent->netType_].end()) { + NETMANAGER_EXT_LOGE("%{public}s, event has been unregistered.", __func__); + EndSendTask(asyncEvent, unrefRef, refCount); + return; + } + for (auto& each : it->second) { + if (each.m_regEnv == asyncEvent->env_ && each.m_regHandlerRef == asyncEvent->callbackRef_) { + find = true; + break; + } + } + if (find == false) { + NETMANAGER_EXT_LOGE("%{public}s, NOT find the event.", __func__); + EndSendTask(asyncEvent, unrefRef, refCount); + return; + } + res = napi_reference_ref(asyncEvent->env_, asyncEvent->callbackRef_, &refCount); + NETMANAGER_EXT_LOGI("%{public}s, res: %{public}d, callbackRef: %{private}p, refCount: %{public}d", + __func__, res, asyncEvent->callbackRef_, refCount); + if (res != napi_ok || refCount <= 1) { + EndSendTask(asyncEvent, unrefRef, refCount); + return; + } + unrefRef = true; + res = napi_get_reference_value(asyncEvent->env_, asyncEvent->callbackRef_, &handler); + if (res != napi_ok || handler == nullptr) { + NETMANAGER_EXT_LOGE("%{public}s, handler is nullptr or res: %{public}d!", __func__, res); + EndSendTask(asyncEvent, unrefRef, refCount); + return; + } + napi_get_undefined(asyncEvent->env_, &undefine); + jsEvent = asyncEvent->packResult_(); + if (napi_call_function(asyncEvent->env_, nullptr, handler, 1, &jsEvent, &undefine) != napi_ok) { + NETMANAGER_EXT_LOGE("%{public}s, Report event to Js failed", __func__); + EndSendTask(asyncEvent, unrefRef, refCount); + return; + } +} + +void NetEapPostBackCallback::InitScope(const std::shared_ptr &asyncEvent) +{ + napi_open_handle_scope(asyncEvent->env_, &scope_); + if (scope_ == nullptr) { + NETMANAGER_EXT_LOGE("napi_send_event, scope is nullptr"); + EndSendTask(asyncEvent, false, INVALID_REF_COUNT); + } +} + +void NetEapPostBackCallback::EndSendTask(const std::shared_ptr &asyncEvent, bool unrefRef, uint32_t refCount) +{ + napi_close_handle_scope(asyncEvent->env_, scope_); + if (unrefRef) { + napi_reference_unref(asyncEvent->env_, asyncEvent->callbackRef_, &refCount); + } +} + +void NetEapPostBackCallback::EventNotify(const std::shared_ptr &asyncEvent) +{ + if (asyncEvent == nullptr) { + NETMANAGER_EXT_LOGE("asyncEvent is null!"); + return; + } + NETMANAGER_EXT_LOGI("Enter eap postback event notify, msgId: %{public}d", asyncEvent->msgId_); + auto sendTask = std::bind(&NetEapPostBackCallback::SendTask, this, asyncEvent); + if (napi_status::napi_ok != napi_send_event(asyncEvent->env_, sendTask, napi_eprio_immediate)) { + NETMANAGER_EXT_LOGE("%{public}s, Failed to SendEvent", __func__); + } +} + +void NetManagerNapiAbilityStatusChange::OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + NETMANAGER_EXT_LOGI("NetManagerNapiAbilityStatusChange OnAddSystemAbility systemAbilityId:%{public}d", + systemAbilityId); + std::vector event; + switch (systemAbilityId) { + case WIFI_DEVICE_SA_ID: + case COMM_NET_CONN_MANAGER_SA_ID: { + EapEventMgr::GetInstance().RegCustomEapHandler(NetType::WLAN0, RegTriggerMode::SA_LAUNCH); + break; + } + default: + NETMANAGER_EXT_LOGI("OnAddSystemAbility unhandled sysabilityId:%{public}d", systemAbilityId); + return; + } +} + +void NetManagerNapiAbilityStatusChange::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) +{ + NETMANAGER_EXT_LOGI("NetManagerNapiAbilityStatusChange OnRemoveSystemAbility systemAbilityId:%{public}d", + systemAbilityId); +} + +EapEventMgr &EapEventMgr::GetInstance() +{ + static EapEventMgr instance; + return instance; +} + +EapEventMgr::EapEventMgr():eapPostBackCallback_(new (std::nothrow) NetEapPostBackCallback()) +{ + auto samgrProxy = OHOS::SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgrProxy == nullptr) { + NETMANAGER_EXT_LOGE("samgrProxy is nullptr!"); + return; + } + mSaStatusListener = new OHOS::NetManagerStandard::NetManagerNapiAbilityStatusChange(); + if (mSaStatusListener == nullptr) { + NETMANAGER_EXT_LOGE("mSaStatusListener is nullptr!"); + return; + } + int32_t retWifiSa = samgrProxy->SubscribeSystemAbility((int32_t)WIFI_DEVICE_SA_ID, mSaStatusListener); + int32_t retNetManagerSa = samgrProxy->SubscribeSystemAbility( + (int32_t)COMM_NET_CONN_MANAGER_SA_ID, mSaStatusListener); + NETMANAGER_EXT_LOGI("EventRegister, SubscribeSystemAbility return retWifiSa:%{public}d, \ + retNetManagerSa:%{public}d!", retWifiSa, retNetManagerSa); +} + +bool EapEventMgr::RegCustomEapHandler(napi_env env, NetType netType, int eapCode, int eapType, napi_value handler) +{ + NETMANAGER_EXT_LOGI("%{public}s enter, netType:%{public}d, eapCode:%{public}d, eapType:%{public}d", __func__, + static_cast(netType), eapCode, eapType); + uint32_t composeParam = (eapCode << 8) | eapType; + napi_ref handlerRef = nullptr; + napi_create_reference(env, handler, 1, &handlerRef); + RegObj regObj(env, handlerRef); + + std::unique_lock guard(g_regInfoMutex); + auto netTypeMapIter = g_eventRegisterInfo.find(netType); + if (netTypeMapIter == g_eventRegisterInfo.end()) { + NETMANAGER_EXT_LOGI("%{public}s, new netType!", __func__); + TypeMapRegObj mapObj; + mapObj[composeParam] = std::vector{regObj}; + g_eventRegisterInfo[netType] = mapObj; + } else { + NETMANAGER_EXT_LOGI("%{public}s, exist netType!", __func__); + TypeMapRegObj mapObj = netTypeMapIter->second; + auto iter = mapObj.find(composeParam); + if (iter == mapObj.end()) { + NETMANAGER_EXT_LOGI("%{public}s, new eapCode:%{public}d, eapType:%{public}d!", __func__, + eapCode, eapType); + if (mapObj.size() > REGISTERINFO_MAX_NUM) { + NETMANAGER_EXT_LOGE("%{public}s, RegisterInfo Exceeding the maximum value!", __func__); + return false; + } + mapObj[composeParam] = std::vector{regObj}; + g_eventRegisterInfo[netType] = mapObj; + } else { + auto vecIter = std::find_if(iter->second.begin(), iter->second.end(), + [®Obj](const RegObj &obj){ return regObj.m_regEnv == obj.m_regEnv;}); + if (vecIter != iter->second.end()) + { + NETMANAGER_EXT_LOGE("%{public}s, eapCode:%{public}d, eapType:%{public}d callback is registered!", + __func__, eapCode, eapType); + return true; + } + iter->second.emplace_back(regObj); + NETMANAGER_EXT_LOGI("%{public}s, eapCode:%{public}d, eapType:%{public}d callback size:%{public}zu!", + __func__, eapCode, eapType, iter->second.size()); + } + } + guard.unlock(); + return RegCustomEapHandler(netType, RegTriggerMode::USER_REGISTER); +} + +bool EapEventMgr::RegCustomEapHandler(NetType netType, RegTriggerMode triggerMode) +{ + std::string regCmd; + { + std::shared_lock guard(g_regInfoMutex); + auto mNetTypeValueIter = g_eventRegisterInfo.find(netType); + if (mNetTypeValueIter == g_eventRegisterInfo.end()) { + NETMANAGER_EXT_LOGE("%{public}s g_eventRegisterInfo not have eapType:%{public}d", __func__, netType); + return false; + } + regCmd += std::to_string(static_cast(netType)); + regCmd += ":"; + regCmd += std::to_string(mNetTypeValueIter->second.size()); + for (auto &iter : mNetTypeValueIter->second) { + regCmd += ":"; + regCmd += std::to_string(iter.first); + } + } + NETMANAGER_EXT_LOGI("%{public}s enter, triggreMode:%{public}d, netType:%{public}d, regCmd:%{public}s", __func__, + static_cast(triggerMode), static_cast(netType), regCmd.c_str()); + int errorCode = DelayedSingleton::GetInstance()->RegCustomEapHandler(netType, regCmd, + eapPostBackCallback_); + if (errorCode != NETMANAGER_SUCCESS) { + NETMANAGER_EXT_LOGE("%{public}s failed errorCode: %{public}d", __func__, errorCode); + return NETMANAGER_ERR_OPERATION_FAILED; + } + return true; +} + +bool EapEventMgr::UnRegCustomEapHandler(napi_env env, NetType netType, int eapCode, int eapType, napi_value handler) +{ + NETMANAGER_EXT_LOGI("%{public}s enter, netType:%{public}d, eapCode:%{public}d, eapType:%{public}d", __func__, + static_cast(netType), eapCode, eapType); + uint32_t composeParam = (eapCode << 8) | eapType; + napi_ref handlerRef = nullptr; + napi_create_reference(env, handler, 1, &handlerRef); + RegObj regObj(env, handlerRef); + bool needUnregister = false; + { + std::unique_lock guard(g_regInfoMutex); + auto netTypeMapIter = g_eventRegisterInfo.find(netType); + if (netTypeMapIter == g_eventRegisterInfo.end()) { + NETMANAGER_EXT_LOGE("%{public}s, not netType %{public}d handler", __func__, netType); + return false; + } + TypeMapRegObj& mapObj = netTypeMapIter->second; + auto mapObjIter = mapObj.find(composeParam); + if (mapObjIter == mapObj.end()) { + NETMANAGER_EXT_LOGE("%{public}s, not composeParam %{public}d handler", __func__, composeParam); + return false; + } + auto new_end = std::remove_if(mapObjIter->second.begin(), mapObjIter->second.end(), + [env](const RegObj& obj) { return obj.m_regEnv == env; }); + mapObjIter->second.erase(new_end, mapObjIter->second.end()); + // if have no callbacks, supplicant unregister this eap code and type + if (mapObjIter->second.size() == 0) { + mapObj.erase(mapObjIter); + needUnregister = true; + } + } + if (needUnregister) { + NETMANAGER_EXT_LOGI("%{public}s, eapCode:%{public}d, eapType:%{public}d", __func__, eapCode, eapType); + return UnRegCustomEapHandler(netType); + } + return true; +} + +bool EapEventMgr::UnRegCustomEapHandler(NetType netType) +{ + return RegCustomEapHandler(netType, RegTriggerMode::UNREGISTER); +} + +int32_t EapEventMgr::ReplyCustomEapData(CustomResult result, const sptr &eapData) +{ + NETMANAGER_EXT_LOGI("%{public}s enter, result:%{public}d, eapData:%{public}s", __func__, + static_cast(result), eapData->PrintLogInfo().c_str()); + int32_t errorCode = DelayedSingleton::GetInstance()->ReplyCustomEapData(static_cast(result), + eapData); + if (errorCode != NETMANAGER_SUCCESS) { + NETMANAGER_EXT_LOGE("%{public}s failed errorCode: %{public}d", __func__, errorCode); + return NETMANAGER_ERR_OPERATION_FAILED; + } + return NETMANAGER_SUCCESS; +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file -- Gitee From 2656f2321295d685cb445d97d795198cf5645145 Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 10:47:52 +0000 Subject: [PATCH 2/9] extended certification Signed-off-by: shihaojie --- .../napi/ethernet/customeap/eap_event_mgr.h | 139 +++++++++++++++ .../js/napi/ethernet/customeap/eap_module.cpp | 77 ++++++++ .../js/napi/ethernet/customeap/eap_module.h | 38 ++++ .../ethernet/customeap/eap_napi_event.cpp | 167 ++++++++++++++++++ .../napi/ethernet/customeap/eap_napi_event.h | 32 ++++ .../native/ethernetclient/src/eap_data.cpp | 74 ++++++++ 6 files changed, 527 insertions(+) create mode 100644 frameworks/js/napi/ethernet/customeap/eap_event_mgr.h create mode 100644 frameworks/js/napi/ethernet/customeap/eap_module.cpp create mode 100644 frameworks/js/napi/ethernet/customeap/eap_module.h create mode 100644 frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp create mode 100644 frameworks/js/napi/ethernet/customeap/eap_napi_event.h create mode 100644 frameworks/native/ethernetclient/src/eap_data.cpp diff --git a/frameworks/js/napi/ethernet/customeap/eap_event_mgr.h b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.h new file mode 100644 index 00000000..a369da6d --- /dev/null +++ b/frameworks/js/napi/ethernet/customeap/eap_event_mgr.h @@ -0,0 +1,139 @@ +/* + * Copyright (c) 2025-2025 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 COMMUNICATION_NET_MANAGER_BASE_EAP_EVENT_MANAGER_H +#define COMMUNICATION_NET_MANAGER_BASE_EAP_EVENT_MANAGER_H + +#include +#include +#include +#include +#include "ethernet_client.h" +#include "napi_utils.h" +#include "net_eap_callback_stub.h" +#include "netmanager_ext_log.h" +#include "system_ability_status_change_stub.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace NetManagerStandard { + +class RegObj { +public: + RegObj() : m_regEnv(0), m_regHandlerRef(nullptr) + { + } + + explicit RegObj(const napi_env& env, const napi_ref& ref) + { + m_regEnv = env; + m_regHandlerRef = ref; + } + + ~RegObj() + { + } + + bool operator == (const RegObj& other) const + { + return m_regEnv == other.m_regEnv && m_regHandlerRef == other.m_regHandlerRef; + } + + bool operator != (const RegObj& other) const + { + return !(*this == other); + } + + bool operator < (const RegObj& other) const + { + return m_regEnv < other.m_regEnv || (m_regEnv == other.m_regEnv && m_regHandlerRef < other.m_regHandlerRef); + } + + napi_env m_regEnv; + napi_ref m_regHandlerRef; +}; + +class AsyncEventData { +public: + napi_env env_; + napi_ref callbackRef_; + std::function packResult_; + int key_; + NetType netType_; + int32_t msgId_; + + AsyncEventData(napi_env e, napi_ref r, std::function p) + { + env_ = e; + callbackRef_ = r; + packResult_ = p; + } + virtual ~AsyncEventData() { + } + + void Init(const int32_t key, NetType netType, int32_t msgId) + { + key_ = key; + netType_ = netType; + msgId_ = msgId; + } +}; + +class NetEapPostBackCallback : public NetEapPostbackCallbackStub { +public: + NetEapPostBackCallback() = default; + virtual ~NetEapPostBackCallback() = default; + +public: + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override; + +private: + bool CheckAndNotifyApp(NetType netType, const int32_t key, const sptr &eapData); + void EventNotify(const std::shared_ptr &asyncEvent); + void SendTask(const std::shared_ptr &asyncEvent); + void InitScope(const std::shared_ptr &asyncEvent); + void EndSendTask(const std::shared_ptr &asyncEvent, bool unrefRef, uint32_t refCount); + napi_value CreateResult(const napi_env& env, const sptr &eapData); + +private: + napi_handle_scope scope_ = nullptr; +}; + +class NetManagerNapiAbilityStatusChange : public SystemAbilityStatusChangeStub { +public: + void OnAddSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; + void OnRemoveSystemAbility(int32_t systemAbilityId, const std::string& deviceId) override; +}; + +class EapEventMgr final { +public: + EapEventMgr(); + ~EapEventMgr() = default; + + static EapEventMgr &GetInstance(); + bool RegCustomEapHandler(napi_env env, NetType netType, int eapCode, int eapType, napi_value handler); + bool UnRegCustomEapHandler(napi_env env, NetType netType, int eapCode, int eapType, napi_value handler); + int32_t ReplyCustomEapData(CustomResult result, const sptr &eapData); + bool RegCustomEapHandler(NetType netType, RegTriggerMode triggerMode); + bool UnRegCustomEapHandler(NetType netType); + +private: + sptr eapPostBackCallback_ = nullptr; + OHOS::sptr mSaStatusListener = nullptr; +}; +} // namespace NetManagerStandard +} // namespace OHOS + +#endif /* COMMUNICATION_NET_MANAGER_BASE_EAP_EVENT_MANAGER_H */ \ No newline at end of file diff --git a/frameworks/js/napi/ethernet/customeap/eap_module.cpp b/frameworks/js/napi/ethernet/customeap/eap_module.cpp new file mode 100644 index 00000000..417e84ec --- /dev/null +++ b/frameworks/js/napi/ethernet/customeap/eap_module.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2025-2025 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 "eap_module.h" +#include "netmanager_ext_log.h" + +static constexpr const char *EAP_MODULE_NAME = "net.eap"; +#define DECLARE_EAP_CUSTOM_RESULT(result) \ + DECLARE_NAPI_STATIC_PROPERTY(#result, NapiUtils::CreateUint32(env, static_cast(CustomResult::result))) + +namespace OHOS::NetManagerStandard { + +static void AddCleanupHook(napi_env env) +{ + NapiUtils::SetEnvValid(env); + auto envWrapper = new (std::nothrow) napi_env; + if (envWrapper == nullptr) { + NETMANAGER_EXT_LOGE("EnvWrapper create fail!"); + return; + } + *envWrapper = env; + napi_add_env_cleanup_hook(env, NapiUtils::HookForEnvCleanup, envWrapper); +} + +napi_value EapModule::InitEapModule(napi_env env, napi_value exports) +{ + std::initializer_list functions = { + DECLARE_NAPI_FUNCTION(FUNCTION_REG_CUSTOM_EAP_HANDLER, RegCustomEapHandler), + DECLARE_NAPI_FUNCTION(FUNCTION_UNREG_CUSTOM_EAP_HANDLER, UnRegCustomEapHandler), + DECLARE_NAPI_FUNCTION(FUNCTION_REPLY_CUSTOM_EAP_DATA, ReplyCustomEapData), + }; + NapiUtils::DefineProperties(env, exports, functions); + InitProperties(env, exports); + AddCleanupHook(env); + return exports; +} + +void EapModule::InitProperties(napi_env env, napi_value exports) +{ + std::initializer_list results = { + DECLARE_EAP_CUSTOM_RESULT(RESULT_FAIL), + DECLARE_EAP_CUSTOM_RESULT(RESULT_NEXT), + DECLARE_EAP_CUSTOM_RESULT(RESULT_FINISH), + }; + napi_value customResult = NapiUtils::CreateObject(env); + NapiUtils::DefineProperties(env, customResult, results); + NapiUtils::SetNamedProperty(env, exports, INTERFACE_NET_EAP_CUSTOM_RESULT, customResult); +} + +static napi_module g_eapModule = { + .nm_version = 1, + .nm_flags = 0, + .nm_filename = nullptr, + .nm_register_func = EapModule::InitEapModule, + .nm_modname = EAP_MODULE_NAME, + .nm_priv = nullptr, + .reserved = {nullptr}, +}; + +extern "C" __attribute__((constructor)) void RegisterEapModule(void) +{ + NETMANAGER_EXT_LOGI("RegisterEapModule success!"); + napi_module_register(&g_eapModule); +} +} // namespace OHOS::NetManagerStandard \ No newline at end of file diff --git a/frameworks/js/napi/ethernet/customeap/eap_module.h b/frameworks/js/napi/ethernet/customeap/eap_module.h new file mode 100644 index 00000000..7b7ecaaa --- /dev/null +++ b/frameworks/js/napi/ethernet/customeap/eap_module.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2025-2025 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 COMMUNICATION_NET_MANAGER_BASE_EAP_MODULE_H +#define COMMUNICATION_NET_MANAGER_BASE_EAP_MODULE_H + +#include +#include "eap_napi_event.h" + +namespace OHOS { +namespace NetManagerStandard { +class EapModule final { +public: + static constexpr const char *INTERFACE_NET_EAP_CUSTOM_RESULT = "CustomResult"; + static constexpr const char *FUNCTION_REG_CUSTOM_EAP_HANDLER = "regCustomEapHandler"; + static constexpr const char *FUNCTION_UNREG_CUSTOM_EAP_HANDLER = "unregCustomEapHandler"; + static constexpr const char *FUNCTION_REPLY_CUSTOM_EAP_DATA = "replyCustomEapData"; + + static napi_value InitEapModule(napi_env env, napi_value exports); +private: + static void InitProperties(napi_env env, napi_value exports); +}; +} // namespace OHOS::NetManagerStandard +} // OHOS + +#endif /* COMMUNICATION_NET_MANAGER_BASE_EAP_MODULE_H */ \ No newline at end of file diff --git a/frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp b/frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp new file mode 100644 index 00000000..7baf4ce7 --- /dev/null +++ b/frameworks/js/napi/ethernet/customeap/eap_napi_event.cpp @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2025-2025 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 "eap_napi_event.h" + #include "napi_constant.h" + +namespace OHOS { +namespace NetManagerStandard { + +namespace { +#ifdef NET_EXTENSIBLE_AUTHENTICATION +static bool CheckParamsType(napi_env env, napi_value *params, size_t paramsCount) +{ + if (static_cast(paramsCount) == PARAM_TRIPLE_OPTIONS_AND_CALLBACK) { + return NapiUtils::GetValueType(env, params[ARG_INDEX_0]) == napi_number && + NapiUtils::GetValueType(env, params[ARG_INDEX_1]) == napi_number && + NapiUtils::GetValueType(env, params[ARG_INDEX_2]) == napi_number && + NapiUtils::GetValueType(env, params[ARG_INDEX_3]) == napi_function; + } + if (static_cast(paramsCount) == PARAM_DOUBLE_OPTIONS) { + return NapiUtils::GetValueType(env, params[ARG_INDEX_0]) == napi_number && + NapiUtils::GetValueType(env, params[ARG_INDEX_1]) == napi_object; + } + return false; +} +#endif +} // namespace + +napi_value RegCustomEapHandler(napi_env env, napi_callback_info info) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + size_t requireArgc = 4; + size_t argc = 4; + napi_value argv[4] = {0}; + napi_value thisVar = 0; + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (requireArgc > argc) { + NETMANAGER_EXT_LOGE("requireArgc:%{public}zu, argc:%{public}zu", requireArgc, argc); + return NapiUtils::GetUndefined(env); + } + + if (!CheckParamsType(env, argv, argc)) { + NETMANAGER_EXT_LOGE("params type error"); + return NapiUtils::GetUndefined(env); + } + + int32_t netType = NapiUtils::GetInt32FromValue(env, argv[ARG_INDEX_0]); + if (netType < static_cast(NetType::WLAN0) || netType >= static_cast(NetType::INVALID)) { + NETMANAGER_EXT_LOGE("valid netType %{public}d", static_cast(netType)); + return NapiUtils::GetUndefined(env); + } + + int32_t eapCode = NapiUtils::GetInt32FromValue(env, argv[ARG_INDEX_1]); + if (eapCode < EAP_CODE_MIN || eapCode > EAP_CODE_MAX) { + NETMANAGER_EXT_LOGE("valid eapCode %{public}d", eapCode); + return NapiUtils::GetUndefined(env); + } + + int32_t eapType = NapiUtils::GetInt32FromValue(env, argv[ARG_INDEX_2]); + if (eapType < EAP_TYPE_MIN || eapType > EAP_TYPE_MAX) { + NETMANAGER_EXT_LOGE("valid eapType %{public}d", eapType); + return NapiUtils::GetUndefined(env); + } + + EapEventMgr::GetInstance().RegCustomEapHandler(env, static_cast(netType), + eapCode, eapType, argv[ARG_INDEX_3]); +#endif + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + +napi_value UnRegCustomEapHandler(napi_env env, napi_callback_info info) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + size_t requireArgc = 4; + size_t argc = 4; + napi_value argv[4] = {0}; + napi_value thisVar = 0; + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (requireArgc > argc) { + NETMANAGER_EXT_LOGE("requireArgc:%{public}zu, argc:%{public}zu", requireArgc, argc); + return NapiUtils::GetUndefined(env); + } + + if (!CheckParamsType(env, argv, argc)) { + NETMANAGER_EXT_LOGE("params type error"); + return NapiUtils::GetUndefined(env); + } + + int32_t netType = NapiUtils::GetInt32FromValue(env, argv[ARG_INDEX_0]); + if (netType < static_cast(NetType::WLAN0) || netType >= static_cast(NetType::INVALID)) { + NETMANAGER_EXT_LOGE("valid netType %{public}d", static_cast(netType)); + return NapiUtils::GetUndefined(env); + } + + int32_t eapCode = NapiUtils::GetInt32FromValue(env, argv[ARG_INDEX_1]); + if (eapCode < EAP_CODE_MIN || eapCode > EAP_CODE_MAX) { + NETMANAGER_EXT_LOGE("valid eapCode %{public}d", eapCode); + return NapiUtils::GetUndefined(env); + } + + int32_t eapType = NapiUtils::GetInt32FromValue(env, argv[ARG_INDEX_2]); + if (eapType < EAP_TYPE_MIN || eapType > EAP_TYPE_MAX) { + NETMANAGER_EXT_LOGE("valid eapType %{public}d", eapType); + return NapiUtils::GetUndefined(env); + } + + EapEventMgr::GetInstance().UnRegCustomEapHandler(env, static_cast(netType), + eapCode, eapType, argv[ARG_INDEX_3]); +#endif + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + +napi_value ReplyCustomEapData(napi_env env, napi_callback_info info) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + size_t requireArgc = 2; + size_t argc = 2; + napi_value argv[2] = {0}; + napi_value thisVar = 0; + napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr); + if (requireArgc > argc) { + NETMANAGER_EXT_LOGE("requireArgc:%{public}zu, argc:%{public}zu", requireArgc, argc); + return NapiUtils::GetUndefined(env); + } + + if (!CheckParamsType(env, argv, argc)) { + NETMANAGER_EXT_LOGE("params type error"); + return NapiUtils::GetUndefined(env); + } + + CustomResult customResult = static_cast(NapiUtils::GetInt32FromValue(env, argv[ARG_INDEX_0])); + sptr eapData = new (std::nothrow) EapData(); + if (eapData == nullptr) { + NETMANAGER_EXT_LOGE("%{public}s, eapData is nullptr", __func__); + return NapiUtils::GetUndefined(env); + } + eapData->msgId = NapiUtils::GetInt32Property(env, argv[ARG_INDEX_1], "msgId"); + eapData->bufferLen = NapiUtils::GetInt32Property(env, argv[ARG_INDEX_1], "bufferLen"); + NapiUtils::GetVectorUint8Property(env, argv[ARG_INDEX_1], "eapBuffer", eapData->eapBuffer); + + NETMANAGER_EXT_LOGI("%{public}s, msgId:%{public}d, bufferLen:%{public}d, result:%{public}d, buffsize:%{public}zu", + __func__, eapData->msgId, eapData->bufferLen, static_cast(customResult), eapData->eapBuffer.size()); + EapEventMgr::GetInstance().ReplyCustomEapData(customResult, eapData); +#endif + napi_value result = nullptr; + napi_get_undefined(env, &result); + return result; +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file diff --git a/frameworks/js/napi/ethernet/customeap/eap_napi_event.h b/frameworks/js/napi/ethernet/customeap/eap_napi_event.h new file mode 100644 index 00000000..722a5f05 --- /dev/null +++ b/frameworks/js/napi/ethernet/customeap/eap_napi_event.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2025-2025 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 EAP_NAPI_EVENT_H +#define EAP_NAPI_EVENT_H + +#include +#include "eap_data.h" +#include "eap_event_mgr.h" + +namespace OHOS { +namespace NetManagerStandard { + +napi_value RegCustomEapHandler(napi_env env, napi_callback_info cbinfo); +napi_value UnRegCustomEapHandler(napi_env env, napi_callback_info cbinfo); +napi_value ReplyCustomEapData(napi_env env, napi_callback_info cbinfo); + +} // namespace NetManagerStandard +} // namespace OHOS + +#endif // EAP_NAPI_EVENT_H \ No newline at end of file diff --git a/frameworks/native/ethernetclient/src/eap_data.cpp b/frameworks/native/ethernetclient/src/eap_data.cpp new file mode 100644 index 00000000..db37a7c5 --- /dev/null +++ b/frameworks/native/ethernetclient/src/eap_data.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2025-2025 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 "eap_data.h" +#include +#include "netmanager_base_log.h" +#include "refbase.h" + +namespace OHOS { +namespace NetManagerStandard { + +EapData::EapData() +{ +} + +EapData::~EapData() +{ +} + +bool EapData::Marshalling(Parcel &parcel) const +{ + if (!parcel.WriteInt32(eapCode)) { + return false; + } + if (!parcel.WriteInt32(eapType)) { + return false; + } + if (!parcel.WriteInt32(msgId)) { + return false; + } + if (!parcel.WriteInt32(bufferLen)) { + return false; + } + if (!parcel.WriteUInt8Vector(eapBuffer)) { + return false; + } + return true; +} + +sptr EapData::Unmarshalling(Parcel &parcel) +{ + sptr ptr = new EapData(); + ptr->eapCode = parcel.ReadInt32(); + ptr->eapType = parcel.ReadInt32(); + ptr->msgId = parcel.ReadInt32(); + ptr->bufferLen = parcel.ReadInt32(); + parcel.ReadUInt8Vector(&(ptr->eapBuffer)); + return ptr; +} + +std::string EapData::PrintLogInfo() +{ + std::ostringstream ss; + ss << "code:" << eapCode << " "; + ss << "type:" << eapType << " "; + ss << "msgId:" << msgId << " "; + ss << "bufferLen:" << bufferLen; + return ss.str(); +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file -- Gitee From 39b7aa376a80bca730f5a999740a58900838fe9c Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 10:52:54 +0000 Subject: [PATCH 3/9] extended certification Signed-off-by: shihaojie --- .../ethernetclient/src/ethernet_client.cpp | 86 +++++++++ .../src/proxy/net_eap_callback_stub.cpp | 165 ++++++++++++++++++ interfaces/innerkits/ethernetclient/BUILD.gn | 6 + .../ethernetclient/IEthernetService.idl | 8 + 4 files changed, 265 insertions(+) create mode 100644 frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp diff --git a/frameworks/native/ethernetclient/src/ethernet_client.cpp b/frameworks/native/ethernetclient/src/ethernet_client.cpp index 2e611a04..4b8ef044 100644 --- a/frameworks/native/ethernetclient/src/ethernet_client.cpp +++ b/frameworks/native/ethernetclient/src/ethernet_client.cpp @@ -276,6 +276,92 @@ int32_t EthernetClient::SetInterfaceConfig(const std::string &iface, OHOS::nmd:: return proxy->SetInterfaceConfig(iface, configIpc); } +int32_t EthernetClient::RegCustomEapHandler(NetType netType, const std::string ®Cmd, + const sptr &callback) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + if (callback == nullptr) { + NETMGR_EXT_LOG_E("%{public}s callback is nullptr.", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + sptr proxy = GetProxy(); + if (proxy == nullptr) { + NETMGR_EXT_LOG_E("%{public}s proxy is nullptr.", __func__); + return NETMANAGER_ERR_GET_PROXY_FAIL; + } + return proxy->RegCustomEapHandler(static_cast(netType), regCmd, callback); +#else + return NETMANAGER_SUCCESS; +#endif +} + +int32_t EthernetClient::ReplyCustomEapData(int result, const sptr &eapData) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + if (eapData == nullptr) { + NETMGR_EXT_LOG_E("%{public}s, eapData is nullptr", __func__); + return NETMANAGER_ERR_GET_PROXY_FAIL; + } + sptr proxy = GetProxy(); + if (proxy == nullptr) { + NETMGR_EXT_LOG_E("%{public}s, proxy is nullptr.", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + return proxy->ReplyCustomEapData(result, eapData); +#else + return NETMANAGER_SUCCESS; +#endif +} + +int32_t EthernetClient::RegisterCustomEapCallback(const NetType netType, const sptr &callback) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + sptr proxy = GetProxy(); + if (proxy == nullptr) { + NETMGR_EXT_LOG_E("%{public}s proxy is nullptr.", __func__); + return NETMANAGER_ERR_GET_PROXY_FAIL; + } + return proxy->RegisterCustomEapCallback(static_cast(netType), callback); +#else + return NETMANAGER_SUCCESS; +#endif +} + +int32_t EthernetClient::UnRegisterCustomEapCallback(const NetType netType, + const sptr &callback) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + sptr proxy = GetProxy(); + if (proxy == nullptr) { + NETMGR_EXT_LOG_E("%{public}s proxy is nullptr.", __func__); + return NETMANAGER_ERR_GET_PROXY_FAIL; + } + + return proxy->UnRegisterCustomEapCallback(static_cast(netType), callback); +#else + return NETMANAGER_SUCCESS; +#endif +} + +int32_t EthernetClient::NotifyWpaEapInterceptInfo(const NetType netType, const sptr &eapData) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + if (eapData == nullptr) { + NETMGR_EXT_LOG_E("%{public}s eapData is nullptr.", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + sptr proxy = GetProxy(); + if (proxy == nullptr) { + NETMGR_EXT_LOG_E("%{public}s proxy is nullptr.", __func__); + return NETMANAGER_ERR_GET_PROXY_FAIL; + } + + return proxy->NotifyWpaEapInterceptInfo(static_cast(netType), eapData); +#else + return NETMANAGER_SUCCESS; +#endif +} + int32_t EthernetClient::GetDeviceInformation(std::vector &deviceInfoList) { sptr proxy = GetProxy(); diff --git a/frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp b/frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp new file mode 100644 index 00000000..510876e9 --- /dev/null +++ b/frameworks/native/ethernetclient/src/proxy/net_eap_callback_stub.cpp @@ -0,0 +1,165 @@ +/* + * Copyright (c) 2025-2025 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 "net_eap_callback_stub.h" +#include "netmgr_ext_log_wrapper.h" + +namespace OHOS { +namespace NetManagerStandard { +NetEapPostbackCallbackStub::~NetEapPostbackCallbackStub() +{ +} + +NetEapPostbackCallbackStub::NetEapPostbackCallbackStub() +{ + memberFuncMap_[static_cast(NetEapIpcCode::NET_EAP_POSTBACK)] = + &NetEapPostbackCallbackStub::OnEapSupplicantResult; +} + +int32_t NetEapPostbackCallbackStub::OnEapSupplicantResult(MessageParcel &data, MessageParcel &reply) +{ + int32_t netType = 0; + if (!data.ReadInt32(netType)) { + return NETMANAGER_ERR_READ_DATA_FAIL; + } + + sptr eapData = EapData::Unmarshalling(data); + if (eapData == nullptr) { + NETMGR_EXT_LOG_E("%{public}s, failed new eapData", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + + if (eapData->eapBuffer.size() == 0) { + NETMGR_EXT_LOG_E("%{public}s, eapBuffer size is 0, %{public}s", __func__, eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_READ_DATA_FAIL; + } + + int32_t ret = OnEapSupplicantPostback(static_cast(netType), eapData); + if (!reply.WriteInt32(ret)) { + NETMGR_EXT_LOG_E("Write parcel failed"); + return ret; + } + + return NETMANAGER_SUCCESS; +} + +int32_t NetEapPostbackCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + NETMGR_EXT_LOG_D("Stub call start, code:[%{public}d]", code); + std::u16string myDescripter = NetEapPostbackCallbackStub::GetDescriptor(); + std::u16string remoteDescripter = data.ReadInterfaceToken(); + if (myDescripter != remoteDescripter) { + NETMGR_EXT_LOG_E("Descriptor checked failed"); + return NETMANAGER_ERR_DESCRIPTOR_MISMATCH; + } + + auto itFunc = memberFuncMap_.find(code); + if (itFunc != memberFuncMap_.end()) { + auto requestFunc = itFunc->second; + if (requestFunc != nullptr) { + return (this->*requestFunc)(data, reply); + } + } + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int32_t NetEapPostbackCallbackStub::OnEapSupplicantPostback(NetType netType, const sptr &eapData) +{ + return true; +} + +NetRegisterEapCallbackStub::NetRegisterEapCallbackStub() +{ + memberFuncMap_[static_cast(NetEapIpcCode::NET_REGISTER_CUSTOM_EAP_CALLBACK)] = + &NetRegisterEapCallbackStub::OnRegisterCustomEapCallback; + memberFuncMap_[static_cast(NetEapIpcCode::NET_REPLY_CUSTOM_EAPDATA)] = + &NetRegisterEapCallbackStub::OnReplyCustomEapDataEvent; +} + +NetRegisterEapCallbackStub::~NetRegisterEapCallbackStub() +{ +} + +int32_t NetRegisterEapCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel &data, MessageParcel &reply, + MessageOption &option) +{ + NETMGR_EXT_LOG_D("Stub call start, code:[%{public}d]", code); + std::u16string myDescripter = NetRegisterEapCallbackStub::GetDescriptor(); + std::u16string remoteDescripter = data.ReadInterfaceToken(); + if (myDescripter != remoteDescripter) { + NETMGR_EXT_LOG_E("Descriptor checked failed"); + return NETMANAGER_ERR_DESCRIPTOR_MISMATCH; + } + + auto itFunc = memberFuncMap_.find(code); + if (itFunc != memberFuncMap_.end()) { + auto requestFunc = itFunc->second; + if (requestFunc != nullptr) { + return (this->*requestFunc)(data, reply); + } + } + return IPCObjectStub::OnRemoteRequest(code, data, reply, option); +} + +int32_t NetRegisterEapCallbackStub::OnRegisterCustomEapCallback(MessageParcel &data, MessageParcel &reply) +{ + std::string regCmd; + if (!data.ReadString(regCmd)) { + return NETMANAGER_ERR_READ_DATA_FAIL; + } + + int32_t ret = OnRegisterCustomEapCallback(regCmd); + if (!reply.WriteInt32(ret)) { + NETMGR_EXT_LOG_E("Write parcel failed"); + return ret; + } + + return NETMANAGER_SUCCESS; +} + +int32_t NetRegisterEapCallbackStub::OnReplyCustomEapDataEvent(MessageParcel &data, MessageParcel &reply) +{ + int32_t result = -1; + if (!data.ReadInt32(result)) { + return NETMANAGER_ERR_READ_DATA_FAIL; + } + + sptr eapData = EapData::Unmarshalling(data); + if (eapData == nullptr) { + NETMGR_EXT_LOG_E("%{public}s, eapdata is nullptr", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + + int32_t ret = OnReplyCustomEapDataEvent(result, eapData); + if (!reply.WriteInt32(ret)) { + NETMGR_EXT_LOG_E("Write parcel failed"); + return ret; + } + + return NETMANAGER_SUCCESS; +} + +int32_t NetRegisterEapCallbackStub::OnRegisterCustomEapCallback(const std::string ®Cmd) +{ + return NETMANAGER_SUCCESS; +} + +int32_t NetRegisterEapCallbackStub::OnReplyCustomEapDataEvent(int result, const sptr &eapData) +{ + return NETMANAGER_SUCCESS; +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file diff --git a/interfaces/innerkits/ethernetclient/BUILD.gn b/interfaces/innerkits/ethernetclient/BUILD.gn index 7cbe6cfa..6dbb4281 100644 --- a/interfaces/innerkits/ethernetclient/BUILD.gn +++ b/interfaces/innerkits/ethernetclient/BUILD.gn @@ -56,6 +56,7 @@ ohos_static_library("ethernet_parcel") { "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/configuration_parcel_ipc.cpp", "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/interface_configuration.cpp", "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/mac_address_info.cpp", + "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/eap_data.cpp", "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/static_configuration.cpp", "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/ethernet_device_info.cpp", ] @@ -125,6 +126,7 @@ ohos_shared_library("ethernet_manager_if") { sources = [ "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/ethernet_client.cpp", + "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/proxy/net_eap_callback_stub.cpp", "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/proxy/interface_state_callback_proxy.cpp", "$ETHERNETMANAGER_INNERKITS_SOURCE_DIR/src/proxy/interface_state_callback_stub.cpp", ] @@ -160,6 +162,10 @@ ohos_shared_library("ethernet_manager_if") { defines += [ "NETMGR_DEBUG" ] } + if (netmanager_ext_extensible_authentication) { + defines += [ "NET_EXTENSIBLE_AUTHENTICATION" ] + } + external_deps += [ "hilog:libhilog" ] innerapi_tags = [ "platformsdk" ] diff --git a/interfaces/innerkits/ethernetclient/IEthernetService.idl b/interfaces/innerkits/ethernetclient/IEthernetService.idl index c35f2df7..8b415178 100644 --- a/interfaces/innerkits/ethernetclient/IEthernetService.idl +++ b/interfaces/innerkits/ethernetclient/IEthernetService.idl @@ -18,6 +18,9 @@ sequenceable OHOS.NetManagerStandard.InterfaceConfiguration; sequenceable OHOS.NetManagerStandard.ConfigurationParcelIpc; sequenceable OHOS.NetManagerStandard.MacAddressInfo; sequenceable OHOS.NetManagerStandard.EthernetDeviceInfo; +sequenceable OHOS.NetManagerStandard.EapData; +interface OHOS.NetManagerStandard.INetEapPostbackCallback; +interface OHOS.NetManagerStandard.INetRegisterEapCallback; interface OHOS.NetManagerStandard.IEthernetService { void GetMacAddress([out] List macAddrList); void SetIfaceConfig([in] String iface, [in] sptr ic); @@ -32,4 +35,9 @@ interface OHOS.NetManagerStandard.IEthernetService { void GetInterfaceConfig([in] String iface, [out] ConfigurationParcelIpc cfg); void SetInterfaceConfig([in] String iface, [in] ConfigurationParcelIpc cfg); void GetDeviceInformation([out] List deviceInfoList); + void RegCustomEapHandler([in] int netType, [in] String regCmd, [in] INetEapPostbackCallback cb); + void ReplyCustomEapData([in] int eapResult, [in] sptr eapData); + void RegisterCustomEapCallback([in] int netType, [in] INetRegisterEapCallback cb); + void UnRegisterCustomEapCallback([in] int netType, [in] INetRegisterEapCallback cb); + void NotifyWpaEapInterceptInfo([in] int netType, [in] sptr eapData); } -- Gitee From 2aebb9da327217e664e35226dc254d41dafcbaca Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 10:57:29 +0000 Subject: [PATCH 4/9] extended certification Signed-off-by: shihaojie --- .../ethernetclient/include/eap_data.h | 71 +++++++++++++++++++ .../ethernetclient/include/ethernet_client.h | 54 ++++++++++++++ .../proxy/inet_eap_postback_callback.h | 38 ++++++++++ .../proxy/inet_register_eap_callback.h | 41 +++++++++++ .../include/proxy/net_eap_callback_stub.h | 66 +++++++++++++++++ .../ethernetclient/libethernet_kits.map | 25 +++++++ 6 files changed, 295 insertions(+) create mode 100644 interfaces/innerkits/ethernetclient/include/eap_data.h create mode 100644 interfaces/innerkits/ethernetclient/include/proxy/inet_eap_postback_callback.h create mode 100644 interfaces/innerkits/ethernetclient/include/proxy/inet_register_eap_callback.h create mode 100644 interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h diff --git a/interfaces/innerkits/ethernetclient/include/eap_data.h b/interfaces/innerkits/ethernetclient/include/eap_data.h new file mode 100644 index 00000000..2dfe8afa --- /dev/null +++ b/interfaces/innerkits/ethernetclient/include/eap_data.h @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2025 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 EAP_DATA_H +#define EAP_DATA_H + +#include "parcel.h" +#include "refbase.h" + +namespace OHOS { +namespace NetManagerStandard { + +#define EAP_CODE_MIN 1 +#define EAP_CODE_MAX 4 +#define EAP_TYPE_MIN 0 +#define EAP_TYPE_MAX 255 + +enum class NetEapIpcCode { + NET_EAP_POSTBACK = 0, + NET_REGISTER_CUSTOM_EAP_CALLBACK = 1, + NET_REPLY_CUSTOM_EAPDATA = 2, +}; + +enum class CustomResult { + RESULT_FAIL = 0, + RESULT_NEXT = 1, + RESULT_FINISH = 2, +}; + +enum class NetType { + WLAN0 = 1, + ETH0 = 2, + INVALID +}; + +enum class RegTriggerMode { + SA_LAUNCH = 0, + USER_REGISTER = 1, + UNREGISTER =2, + INVALID +}; + +#define NET_SYMBOL_VISIBLE __attribute__ ((visibility("default"))) +struct NET_SYMBOL_VISIBLE EapData final : public Parcelable { + int32_t eapCode = -1; + int32_t eapType = -1; + int32_t msgId = -1; + int32_t bufferLen = -1; + std::vector eapBuffer; + + EapData(); + ~EapData(); + bool Marshalling(Parcel &parcel) const override; + static sptr Unmarshalling(Parcel &parcel); + std::string PrintLogInfo(); +}; +} // namespace NetManagerStandard +} // namespace OHOS +#endif // EAP_DATA_H \ No newline at end of file diff --git a/interfaces/innerkits/ethernetclient/include/ethernet_client.h b/interfaces/innerkits/ethernetclient/include/ethernet_client.h index f1aca7b3..282d2049 100644 --- a/interfaces/innerkits/ethernetclient/include/ethernet_client.h +++ b/interfaces/innerkits/ethernetclient/include/ethernet_client.h @@ -20,6 +20,7 @@ #include "iethernet_service.h" #include "interface_state_callback.h" +#include "net_eap_callback_stub.h" #include "parcel.h" #include "singleton.h" @@ -153,6 +154,59 @@ public: */ int32_t SetInterfaceConfig(const std::string &iface, OHOS::nmd::InterfaceConfigurationParcel &cfg); + /** + * Register custom eap info and callback + * @param netType Indicates net type need to customize + * @param regCmd Indicates some eapCode and eapType info. eg: 2:277:278 + * @param callback the func of post back eap data + * @return Returns 0, successfully register custom eap callback, otherwise it will failed + * @permission ohos.permission.ENTERPRISE_MANAGE_EAP + * @systemapi Hide this for inner system use. + */ + int32_t RegCustomEapHandler(NetType netType, const std::string ®Cmd, + const sptr &callback); + + /** + * Reply custom eap data of app + * + * @param result The result of app + * @param eapData sptr of EapData + * @return Returns 0, successfully replyl custom eap data, otherwise it will failed + * @permission ohos.permission.ENTERPRISE_MANAGE_EAP + * @systemapi Hide this for inner system use. + */ + int32_t ReplyCustomEapData(int result, const sptr &eapData); + + /** + * Register module callback, such as wifi or eth + * + * @param netType Indicates net interface type need to customize + * @param callback The callback of INetRegisterEapCallback interface + * @return Returns 0, successfully register custom eap callback, otherwise it will failed + * @systemapi Hide this for inner system use. + */ + int32_t RegisterCustomEapCallback(const NetType netType, const sptr &callback); + + /** + * unRegister custom eap callback + * + * @param netType Indicates net interface type need to customize + * @param callback The callback of INetRegisterEapCallback interface + * @return Returns 0, successfully unregister custom eap callback, otherwise it will failed + * @systemapi Hide this for inner system use. + */ + int32_t UnRegisterCustomEapCallback(const NetType netType, const sptr &callback); + + /** + * Notify Wap Eap Intercept Info + * + * @param netType Indicates net interface type need to customize + * @param eapData the sptr of eapData + * @return Returns 0, successfully notity success, otherwise it will failed + * @systemapi Hide this for inner system use. + */ + int32_t NotifyWpaEapInterceptInfo(const NetType netType, const sptr &eapData); + /** * Get the ethernet device infomation * diff --git a/interfaces/innerkits/ethernetclient/include/proxy/inet_eap_postback_callback.h b/interfaces/innerkits/ethernetclient/include/proxy/inet_eap_postback_callback.h new file mode 100644 index 00000000..3b69d351 --- /dev/null +++ b/interfaces/innerkits/ethernetclient/include/proxy/inet_eap_postback_callback.h @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2024-2025 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 I_NET_EAP_POSTBACK_CALLBACK_H +#define I_NET_EAP_POSTBACK_CALLBACK_H + +#include "iremote_broker.h" +#include "eap_data.h" +#include "net_manager_constants.h" +#include "refbase.h" + +namespace OHOS { +namespace NetManagerStandard { +class INetEapPostbackCallback : public IRemoteBroker { +public: + virtual ~INetEapPostbackCallback() = default; +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NetManagerStandard.EthernetService.INetEapPostbackCallback"); + +public: + virtual int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) = 0; +}; + +} // namespace NetManagerStandard +} // namespace OHOS +#endif // I_NET_EAP_POSTBACK_CALLBACK_H \ No newline at end of file diff --git a/interfaces/innerkits/ethernetclient/include/proxy/inet_register_eap_callback.h b/interfaces/innerkits/ethernetclient/include/proxy/inet_register_eap_callback.h new file mode 100644 index 00000000..c0749ca2 --- /dev/null +++ b/interfaces/innerkits/ethernetclient/include/proxy/inet_register_eap_callback.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2025-2025 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 I_NET_REGISTER_EAP_CALLBACK_H +#define I_NET_REGISTER_EAP_CALLBACK_H + +#include "iremote_broker.h" +#include "eap_data.h" +#include "net_manager_constants.h" +#include "refbase.h" + +namespace OHOS { +namespace NetManagerStandard { + +class INetRegisterEapCallback : public IRemoteBroker { +public: + INetRegisterEapCallback() = default; + virtual ~INetRegisterEapCallback() = default; +public: + DECLARE_INTERFACE_DESCRIPTOR(u"OHOS.NetManagerStandard.EthernetService.INetRegisterEapCallback"); + +public: + virtual int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) = 0; + virtual int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) = 0; +}; + +} // namespace NetManagerStandard +} // namespace OHOS +#endif // I_NET_REGISTER_EAP_CALLBACK_H \ No newline at end of file diff --git a/interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h b/interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h new file mode 100644 index 00000000..c617eb3f --- /dev/null +++ b/interfaces/innerkits/ethernetclient/include/proxy/net_eap_callback_stub.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 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 NET_EAP_CALLBACK_STUB_H +#define NET_EAP_CALLBACK_STUB_H + +#include +#include "iremote_stub.h" +#include "inet_register_eap_callback.h" +#include "inet_eap_postback_callback.h" + +namespace OHOS { +namespace NetManagerStandard { +class NetEapPostbackCallbackStub : public IRemoteStub { +public: + using NetEapPostbackCallbackFunc = int32_t (NetEapPostbackCallbackStub::*)(MessageParcel &, MessageParcel &); + NetEapPostbackCallbackStub(); + virtual ~NetEapPostbackCallbackStub(); + + int32_t OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override; + +private: + int32_t OnEapSupplicantResult(MessageParcel &data, MessageParcel &reply); + +private: + std::map memberFuncMap_; +}; + +class NetRegisterEapCallbackStub : public IRemoteStub { +public: + using NetRegisterEapCallbackFunc = int32_t (NetRegisterEapCallbackStub::*)(MessageParcel &, MessageParcel &); + NetRegisterEapCallbackStub(); + virtual ~NetRegisterEapCallbackStub(); + + int32_t OnRemoteRequest( + uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) override; + + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override; + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override; + +private: + int32_t OnRegisterCustomEapCallback(MessageParcel &data, MessageParcel &reply); + int32_t OnReplyCustomEapDataEvent(MessageParcel &data, MessageParcel &reply); + +private: + std::map memberFuncMap_; +}; + +} // namespace NetManagerStandard +} // namespace OHOS +#endif // NET_EAP_CALLBACK_STUB_H \ No newline at end of file diff --git a/interfaces/innerkits/ethernetclient/libethernet_kits.map b/interfaces/innerkits/ethernetclient/libethernet_kits.map index 4253db1a..956e6128 100644 --- a/interfaces/innerkits/ethernetclient/libethernet_kits.map +++ b/interfaces/innerkits/ethernetclient/libethernet_kits.map @@ -53,6 +53,31 @@ "OHOS::NetManagerStandard::HttpProxy::HttpProxy()"; "OHOS::NetManagerStandard::EthernetClient::GetDeviceInformation(std::__h::vector>&)"; "OHOS::NetManagerStandard::EthernetServiceProxy::GetDeviceInformation(std::__h::vector>&)"; + "OHOS::NetManagerStandard::NetRegisterEapCallbackStub::NetRegisterEapCallbackStub()"; + "OHOS::NetManagerStandard::NetRegisterEapCallbackStub::~NetRegisterEapCallbackStub()"; + "OHOS::NetManagerStandard::EapData::PrintLogInfo()"; + "OHOS::NetManagerStandard::EthernetClient::RegisterCustomEapCallback(OHOS::NetManagerStandard::NetType, OHOS::sptr const&)"; + "OHOS::NetManagerStandard::EthernetClient::UnRegisterCustomEapCallback(OHOS::NetManagerStandard::NetType, OHOS::sptr const&)"; + "OHOS::NetManagerStandard::EapData::EapData()"; + "OHOS::NetManagerStandard::EthernetClient::NotifyWpaEapInterceptInfo(OHOS::NetManagerStandard::NetType, OHOS::sptr const&)"; + "OHOS::NetManagerStandard::NetRegisterEapCallbackStub::OnRemoteRequest(unsigned int, OHOS::MessageParcel&, OHOS::MessageParcel&, OHOS::MessageOption&)"; + "OHOS::NetManagerStandard::NetRegisterEapCallbackStub::OnRegisterCustomEapCallback(std::__h::basic_string, std::__h::allocator> const&)"; + "OHOS::NetManagerStandard::NetRegisterEapCallbackStub::OnReplyCustomEapDataEvent(int, OHOS::sptr const&)"; + "non-virtual thunk to OHOS::NetManagerStandard::NetRegisterEapCallbackStub::~NetRegisterEapCallbackStub()"; + "non-virtual thunk to OHOS::NetManagerStandard::NetRegisterEapCallbackStub::OnRegisterCustomEapCallback(std::__h::basic_string, std::__h::allocator> const&)"; + "non-virtual thunk to OHOS::NetManagerStandard::NetRegisterEapCallbackStub::OnReplyCustomEapDataEvent(int, OHOS::sptr const&)"; + "virtual thunk to OHOS::NetManagerStandard::NetRegisterEapCallbackStub::~NetRegisterEapCallbackStub()"; + "OHOS::NetManagerStandard::EthernetClient::RegCustomEapHandler(OHOS::NetManagerStandard::NetType, std::__h::basic_string, std::__h::allocator> const&, OHOS::sptr const&)"; + "OHOS::NetManagerStandard::NetEapPostbackCallbackStub::NetEapPostbackCallbackStub()"; + "OHOS::NetManagerStandard::NetEapPostbackCallbackStub::~NetEapPostbackCallbackStub()"; + "OHOS::NetManagerStandard::EthernetClient::ReplyCustomEapData(int, OHOS::sptr const&)"; + "OHOS::NetManagerStandard::NetEapPostbackCallbackStub::OnRemoteRequest(unsigned int, OHOS::MessageParcel&, OHOS::MessageParcel&, OHOS::MessageOption&)"; + "OHOS::NetManagerStandard::NetEapPostbackCallbackStub::OnEapSupplicantPostback(OHOS::NetManagerStandard::NetType, OHOS::sptr const&)"; + "non-virtual thunk to OHOS::NetManagerStandard::NetEapPostbackCallbackStub::~NetEapPostbackCallbackStub()"; + "non-virtual thunk to OHOS::NetManagerStandard::NetEapPostbackCallbackStub::OnEapSupplicantPostback(OHOS::NetManagerStandard::NetType, OHOS::sptr const&)"; + "virtual thunk to OHOS::NetManagerStandard::NetEapPostbackCallbackStub::~NetEapPostbackCallbackStub()"; + "OHOS::NetManagerStandard::NetRegisterEapCallbackProxy::NetRegisterEapCallbackProxy(OHOS::sptr const&)"; + "OHOS::NetManagerStandard::NetEapPostbackCallbackProxy::NetEapPostbackCallbackProxy(OHOS::sptr const&)"; }; local: *; -- Gitee From af8ee88c275a48503461afe585b15578c3063c1f Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 11:02:42 +0000 Subject: [PATCH 5/9] extended certification Signed-off-by: shihaojie --- interfaces/kits/js/@ohos.net.eap.d.ts | 474 ++++++++++++++++++ netmanager_ext_config.gni | 1 + services/ethernetmanager/BUILD.gn | 6 + .../include/ethernet_service.h | 7 + .../include/net_eap_callback_proxy.h | 58 +++ .../ethernetmanager/include/net_eap_handler.h | 52 ++ .../ethernetmanager/src/ethernet_service.cpp | 41 ++ 7 files changed, 639 insertions(+) create mode 100644 interfaces/kits/js/@ohos.net.eap.d.ts create mode 100644 services/ethernetmanager/include/net_eap_callback_proxy.h create mode 100644 services/ethernetmanager/include/net_eap_handler.h diff --git a/interfaces/kits/js/@ohos.net.eap.d.ts b/interfaces/kits/js/@ohos.net.eap.d.ts new file mode 100644 index 00000000..44705fd8 --- /dev/null +++ b/interfaces/kits/js/@ohos.net.eap.d.ts @@ -0,0 +1,474 @@ +/* + * Copyright (C) 2025-2025 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. + */ + +import { Callback } from './@ohos.base'; +/** + * Provides interfaces to manage ethernet. + * @namespace eap + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ +declare namespace eap { + /** + * Customize eap packets by callback + * @permission ohos.permission.MANAGE_ENTERPRISE_WIFI_CONNECTION + * @param { number } netType Indicates net type need to customize. + * @param { number } eapCode Indicates eap code need to customize. + * @param { number } eapType Indicates eap type need to customize. + * @param { Callback } callback - the callback of eap packet customization. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 33200006 - Invalid net type + * @throws { BusinessError } 33200007 - Invalid eap code + * @throws { BusinessError } 33200008 - Invalid eap type + * @throws { BusinessError } 33200009 - netmanager stop + * @throws { BusinessError } 33200099 - internal error + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + function regCustomEapHandler(netType: number, eapCode: number, eapType: number, callback: Callback): void; + + /** + * unreg the callback of eap packet customization. + * @permission ohos.permission.MANAGE_ENTERPRISE_WIFI_CONNECTION + * @param { number } netType Indicates net type need to customize. + * @param { number } eapCode Indicates eap code need to customize. + * @param { number } eapType Indicates eap type need to customize. + * @param { Callback } callback - the callback of eap packet customization. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 33200006 - Invalid net type + * @throws { BusinessError } 33200007 - Invalid eap code + * @throws { BusinessError } 33200008 - Invalid eap type + * @throws { BusinessError } 33200009 - netmanager stop + * @throws { BusinessError } 33200099 - internal error + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + function unregCustomEapHandler(netType:number, eapCode: number, eapType: number, callback: Callback): void; + + /** + * send Customized eap packets to system + * @permission ohos.permission.MANAGE_ENTERPRISE_WIFI_CONNECTION + * @param { number } result Indicates the result of custom authentication. + * @param { EapData } data Indicates eap packet data after customization. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 33200004 - Invalid result + * @throws { BusinessError } 33200005 - Invalid size of eap data + * @throws { BusinessError } 33200009 - netmanager stop + * @throws { BusinessError } 33200099 - internal error + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + function replyCustomEapData(result: CustomResult, data: EapData): void; + + + /** + * Set the specified network interface parameters. + * @permission ohos.permission.MANAGE_ENTERPRISE_WIFI_CONNECTION + * @param { number } netId Indicates the eth network id to start EAP authentication. + * @param { EthEapProfile } profile Indicates the eap profile. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 33200001 - Invalid netId + * @throws { BusinessError } 33200003 - Invalid profile + * @throws { BusinessError } 33200009 - netmanager stop + * @throws { BusinessError } 33200010 - invalid eth state + * @throws { BusinessError } 33200099 - internal error + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + function startEthEap(netId: number, profile: EthEapProfile): void; + + /** + * Check whether the specified network is active. + * @permission ohos.permission.MANAGE_ENTERPRISE_WIFI_CONNECTION + * @param { number } netId Indicates the eth network id to log off EAP authentication. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 33200001 - Invalid netId + * @throws { BusinessError } 33200002 - Log off fail + * @throws { BusinessError } 33200009 - netmanager stop + * @throws { BusinessError } 33200010 - invalid eth state + * @throws { BusinessError } 33200099 - internal error + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + function logOffEthEap(netId: number): void; + + /** + * Describes the EAP information. + * + * @typedef EapData + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + interface EapData { + /** + * EAP message ID. + * + * @type { number } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + msgId: number; + /** + * EAP packet buffer. + * + * @type { Uint8Array } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + eapBuffer: Uint8Array; + /** + * EAP packet length. + * + * @type { number } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + bufferLen: number; + } + + /** + * custom 802.1x result. + * + * @enum { number } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + enum CustomResult { + /** + * custom authentication finished and fail + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + RESULT_FAIL, + + /** + * custom authentication success for current step, go to next step + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + RESULT_NEXT, + + /** + * custom authentication finished and success + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + RESULT_FINISH, + } + +/** + * 802.1x EAP method. + * + * @enum { number } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + enum EapMethod { + /** + * Not specified + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_NONE, + + /** + * Protected extensible authentication protocol + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_PEAP, + + /** + * Transport layer security + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_TLS, + + /** + * Tunneled transport layer security + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_TTLS, + + /** + * Password + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_PWD, + + /** + * Subscriber identity module + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_SIM, + + /** + * Authentication and key agreement + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_AKA, + + /** + * AKA prime + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_AKA_PRIME, + + /** + * Unauth TLS + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + EAP_UNAUTH_TLS + } + + /** + * 802.1x phase 2 method. + * + * @enum { number } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + enum Phase2Method { + /** + * Not specified + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_NONE, + + /** + * Password authentication protocol + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_PAP, + + /** + * Microsoft challenge handshake authentication protocol + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_MSCHAP, + + /** + * Microsoft challenge handshake authentication protocol version 2 + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_MSCHAPV2, + + /** + * Generic token card + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_GTC, + + /** + * Subscriber identity module + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_SIM, + + /** + * Authentication and key agreement + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_AKA, + + /** + * AKA Prime + * + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + PHASE2_AKA_PRIME + } + + /** + * Eth EAP profile. + * + * @typedef EthEapProfile + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + interface EthEapProfile { + /** + * EAP authentication method + * + * @type { EapMethod } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + eapMethod: EapMethod; + + /** + * Phase 2 authentication method + * + * @type { Phase2Method } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + phase2Method: Phase2Method; + + /** + * The identity + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + identity: string; + + /** + * Anonymous identity + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + anonymousIdentity: string; + + /** + * Password + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + password: string; + + /** + * CA certificate alias + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + caCertAliases: string; + + /** + * CA certificate path + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + caPath: string; + + /** + * Client certificate alias + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + clientCertAliases: string; + + /** + * content of user's certificate + * + * @type { Uint8Array } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + certEntry: Uint8Array; + + /** + * Password of user's certificate + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + certPassword: string; + + /** + * Alternate subject match + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + altSubjectMatch: string; + + /** + * Domain suffix match + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + domainSuffixMatch: string; + + /** + * Realm for Passpoint credential + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + realm: string; + + /** + * Public Land Mobile Network of the provider of Passpoint credential + * + * @type { string } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + plmn: string; + + /** + * Sub ID of the SIM card + * + * @type { number } + * @syscap SystemCapability.Communication.NetManager.Eap + * @since 20 + */ + eapSubId: number; + } + +} + +export default eap; \ No newline at end of file diff --git a/netmanager_ext_config.gni b/netmanager_ext_config.gni index 5185a78e..7bea9eb6 100644 --- a/netmanager_ext_config.gni +++ b/netmanager_ext_config.gni @@ -72,6 +72,7 @@ declare_args() { battery_manager_switch_enable = false netmanager_ext_share_notification_enable = false netmanager_ext_share_traffic_limit_enable = false + netmanager_ext_extensible_authentication = false netmanager_ext_feature_networkslice = false } diff --git a/services/ethernetmanager/BUILD.gn b/services/ethernetmanager/BUILD.gn index 9a627247..5e8351a3 100644 --- a/services/ethernetmanager/BUILD.gn +++ b/services/ethernetmanager/BUILD.gn @@ -33,6 +33,8 @@ ohos_shared_library("ethernet_manager") { "src/ethernet_management.cpp", "src/ethernet_service.cpp", "src/ethernet_service_common.cpp", + "src/net_eap_callback_proxy.cpp", + "src/net_eap_handler.cpp", ] include_dirs = [ @@ -75,6 +77,10 @@ ohos_shared_library("ethernet_manager") { "NETWORK_CONFIG_PATH = \"/system/etc/communication/netmanager_ext/ethernet_interfaces.json\"", ] + if (netmanager_ext_extensible_authentication) { + defines += [ "NET_EXTENSIBLE_AUTHENTICATION" ] + } + if (enable_netmgr_ext_debug) { defines += [ "NETMGR_DEBUG" ] } diff --git a/services/ethernetmanager/include/ethernet_service.h b/services/ethernetmanager/include/ethernet_service.h index c9ba1bcc..b1e081ea 100644 --- a/services/ethernetmanager/include/ethernet_service.h +++ b/services/ethernetmanager/include/ethernet_service.h @@ -28,6 +28,7 @@ #include "ethernet_service_stub.h" #include "event_handler.h" #include "netsys_controller_callback.h" +#include "net_eap_handler.h" #include "refbase.h" #include "singleton.h" #include "system_ability.h" @@ -79,6 +80,12 @@ public: int32_t SetInterfaceDown(const std::string &iface) override; int32_t GetInterfaceConfig(const std::string &iface, ConfigurationParcelIpc &cfgIpc) override; int32_t SetInterfaceConfig(const std::string &iface, const ConfigurationParcelIpc &cfgIpc) override; + int32_t RegCustomEapHandler(int netType, const std::string ®Cmd, + const sptr &callback) override; + int32_t ReplyCustomEapData(int result, const sptr &eapData) override; + int32_t RegisterCustomEapCallback(int netType, const sptr &callback) override; + int32_t UnRegisterCustomEapCallback(int netType, const sptr &callback) override; + int32_t NotifyWpaEapInterceptInfo(int netType, const sptr &eapData) override; int32_t GetDeviceInformation(std::vector &deviceInfoList) override; protected: diff --git a/services/ethernetmanager/include/net_eap_callback_proxy.h b/services/ethernetmanager/include/net_eap_callback_proxy.h new file mode 100644 index 00000000..219adb1c --- /dev/null +++ b/services/ethernetmanager/include/net_eap_callback_proxy.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2025-2025 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 NET_EAP_CALLBACK_PROXY_H +#define NET_EAP_CALLBACK_PROXY_H + +#include "iremote_proxy.h" +#include "inet_register_eap_callback.h" +#include "inet_eap_postback_callback.h" + +namespace OHOS { +namespace NetManagerStandard { +class NetEapPostbackCallbackProxy : public IRemoteProxy { +public: + explicit NetEapPostbackCallbackProxy(const sptr &impl); + virtual ~NetEapPostbackCallbackProxy(); + +public: + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + +private: + static inline BrokerDelegator delegator_; +}; + +class NetRegisterEapCallbackProxy : public IRemoteProxy { +public: + explicit NetRegisterEapCallbackProxy(const sptr &impl); + virtual ~NetRegisterEapCallbackProxy(); + +public: + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override; + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override; + +private: + bool WriteInterfaceToken(MessageParcel &data); + +private: + static inline BrokerDelegator delegator_; +}; + +} // namespace NetManagerStandard +} // namespace OHOS +#endif // NET_EAP_CALLBACK_PROXY_H \ No newline at end of file diff --git a/services/ethernetmanager/include/net_eap_handler.h b/services/ethernetmanager/include/net_eap_handler.h new file mode 100644 index 00000000..bd73006e --- /dev/null +++ b/services/ethernetmanager/include/net_eap_handler.h @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025-2025 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 NET_EAP_HANDLER_H +#define NET_EAP_HANDLER_H + +#include +#include +#include "eap_data.h" +#include "inet_register_eap_callback.h" +#include "inet_eap_postback_callback.h" + +namespace OHOS { +namespace NetManagerStandard { +class NetEapHandler : public std::enable_shared_from_this { +public: + NetEapHandler() = default; + ~NetEapHandler() = default; + + static NetEapHandler &GetInstance(); + int32_t RegisterCustomEapCallback(const NetType netType, const sptr &callback); + int32_t UnRegisterCustomEapCallback(const NetType netType, const sptr &callback); + int32_t NotifyWpaEapInterceptInfo(const NetType netType, const sptr &eapData); + int32_t RegCustomEapHandler(NetType netType, const std::string ®Cmd, + const sptr &postBackCb); + int32_t ReplyCustomEapData(int result, const sptr &eapData); +private: + void SetPostbackCallback(const sptr &postbackCallback); + sptr GetPostbackCallback(); + +private: + std::map nTMapMsgId_; + std::map> regEapCallBack_; + sptr postbackCallback_; + std::mutex callbackMutex_; + std::mutex mutex_; +}; +} // namespace NetManagerStandard +} // namespace OHOS +#endif // NET_EAP_H \ No newline at end of file diff --git a/services/ethernetmanager/src/ethernet_service.cpp b/services/ethernetmanager/src/ethernet_service.cpp index a8a8f714..3220232c 100644 --- a/services/ethernetmanager/src/ethernet_service.cpp +++ b/services/ethernetmanager/src/ethernet_service.cpp @@ -419,6 +419,47 @@ void EthernetService::NotifyMonitorIfaceCallbackAsync(OnFunctionT onFunction) ethernetServiceFfrtQueue_->wait(NotifyMonitorIfaceTask_); } +int32_t EthernetService::RegCustomEapHandler(int netType, const std::string ®Cmd, + const sptr &callback) +{ + NETMGR_EXT_LOG_I("Enter RegCustomEapHandler"); + if (!NetManagerPermission::CheckPermission(Permission::ENTERPRISE_MANAGE_EAP)) { + NETMGR_EXT_LOG_E("%{public}s no permission.", __func__); + return NETMANAGER_EXT_ERR_PERMISSION_DENIED; + } + return NetEapHandler::GetInstance().RegCustomEapHandler(static_cast(netType), regCmd, callback); +} + +int32_t EthernetService::ReplyCustomEapData(int eapResult, const sptr &eapData) +{ + NETMGR_EXT_LOG_D("Enter ReplyCustomEapData"); + if (!NetManagerPermission::CheckPermission(Permission::ENTERPRISE_MANAGE_EAP)) { + NETMGR_EXT_LOG_E("%{public}s no permission.", __func__); + return NETMANAGER_EXT_ERR_PERMISSION_DENIED; + } + return NetEapHandler::GetInstance().ReplyCustomEapData(eapResult, eapData); +} + +int32_t EthernetService::RegisterCustomEapCallback(int netType, const sptr &callback) +{ + NETMGR_EXT_LOG_D("Enter RegisterCustomEapCallback"); + return NetEapHandler::GetInstance().RegisterCustomEapCallback(static_cast(netType), callback); +} + +int32_t EthernetService::UnRegisterCustomEapCallback(int netType, + const sptr &callback) +{ + NETMGR_EXT_LOG_D("Enter UnRegisterCustomEapCallback"); + return NetEapHandler::GetInstance().UnRegisterCustomEapCallback(static_cast(netType), callback); + +} + +int32_t EthernetService::NotifyWpaEapInterceptInfo(int netType, const sptr &eapData) +{ + NETMGR_EXT_LOG_D("Enter NotifyWpaEapInterceptInfo"); + return NetEapHandler::GetInstance().NotifyWpaEapInterceptInfo(static_cast(netType), eapData); +} + int32_t EthernetService::GetDeviceInformation(std::vector &deviceInfoList) { if (!NetManagerPermission::IsSystemCaller()) { -- Gitee From 79ab6b960e3991a6b90e9b6085629af62622e680 Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 11:12:37 +0000 Subject: [PATCH 6/9] extended certification Signed-off-by: shihaojie --- .../ethernet_client_fuzzer.cpp | 146 ++++++++++++++++++ .../unittest/ethernet_manager_test/BUILD.gn | 6 + 2 files changed, 152 insertions(+) diff --git a/test/ethernetmanager/fuzztest/ethernetclient_fuzzer/ethernet_client_fuzzer.cpp b/test/ethernetmanager/fuzztest/ethernetclient_fuzzer/ethernet_client_fuzzer.cpp index c1783c9e..0899bd62 100644 --- a/test/ethernetmanager/fuzztest/ethernetclient_fuzzer/ethernet_client_fuzzer.cpp +++ b/test/ethernetmanager/fuzztest/ethernetclient_fuzzer/ethernet_client_fuzzer.cpp @@ -43,6 +43,8 @@ static constexpr uint32_t CREATE_BOOL_TYPE_VALUE = 2; size_t g_baseFuzzSize = 0; size_t g_baseFuzzPos; constexpr size_t IFACE_LEN = 5; +constexpr size_t NET_TYPE_LEN = 1; +constexpr size_t REG_CMD_LEN = 1024; } // namespace template T GetData() @@ -78,6 +80,29 @@ public: } }; +class NetRegisterEapCallbackTest : public NetRegisterEapCallbackStub { +public: + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override + { + return 0; + } + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override + { + return 0; + } +}; + +class NetEapPostBackCallbackTest : public NetEapPostbackCallbackStub { +public: + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override + { + return 0; + } +}; + +static inline sptr g_registerEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); +static inline sptr g_eapPostbackCallback = new (std::nothrow) NetEapPostBackCallbackTest(); + std::string GetStringFromData(int strlen) { char cstr[strlen]; @@ -325,6 +350,122 @@ void EthernetServiceCommonFuzzTest(const uint8_t *data, size_t size) ethernetServiceCommon->ResetEthernetFactory(); } +void RegCustomEapHandlerFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return; + } + g_baseFuzzData = data; + g_baseFuzzSize = size; + g_baseFuzzPos = 0; + MessageParcel parcel; + std::string netType = GetStringFromData(NET_TYPE_LEN); + std::string regCmd = GetStringFromData(REG_CMD_LEN); + WriteInterfaceToken(parcel); + if (!parcel.WriteInt32(std::stoi(netType))) { + return; + } + if (!parcel.WriteString(regCmd)) { + return; + } + if (!parcel.WriteRemoteObject(g_eapPostbackCallback->AsObject())) { + return; + } + OnRemoteRequest(static_cast(IEthernetServiceIpcCode::COMMAND_REG_CUSTOM_EAP_HANDLER), parcel); +} + +void ReplyCustomEapDataFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return; + } + g_baseFuzzData = data; + g_baseFuzzSize = size; + g_baseFuzzPos = 0; + MessageParcel parcel; + std::string result = GetStringFromData(NET_TYPE_LEN); + WriteInterfaceToken(parcel); + if (!parcel.WriteInt32(std::stoi(result))) { + return; + } + + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = std::stoi(GetStringFromData(NET_TYPE_LEN)); + eapData->eapType = std::stoi(GetStringFromData(NET_TYPE_LEN)); + eapData->msgId = std::stoi(GetStringFromData(NET_TYPE_LEN)); + eapData->bufferLen = std::stoi(GetStringFromData(REG_CMD_LEN)); + std::vector tmp = {0x11, 0x12, 0x13}; + eapData->eapBuffer = tmp; + eapData->Marshalling(parcel); + OnRemoteRequest(static_cast(IEthernetServiceIpcCode::COMMAND_REPLY_CUSTOM_EAP_DATA), parcel); +} + +void RegisterCustomEapCallbackFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return; + } + g_baseFuzzData = data; + g_baseFuzzSize = size; + g_baseFuzzPos = 0; + MessageParcel parcel; + std::string netType = GetStringFromData(NET_TYPE_LEN); + WriteInterfaceToken(parcel); + if (!parcel.WriteInt32(std::stoi(netType))) { + return; + } + if (!parcel.WriteRemoteObject(g_registerEapCallback->AsObject())) { + return; + } + OnRemoteRequest(static_cast(IEthernetServiceIpcCode::COMMAND_REGISTER_CUSTOM_EAP_CALLBACK), parcel); +} + +void UnRegisterCustomEapCallbackFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return; + } + g_baseFuzzData = data; + g_baseFuzzSize = size; + g_baseFuzzPos = 0; + MessageParcel parcel; + std::string netType = GetStringFromData(NET_TYPE_LEN); + WriteInterfaceToken(parcel); + if (!parcel.WriteInt32(std::stoi(netType))) { + return; + } + if (!parcel.WriteRemoteObject(g_registerEapCallback->AsObject())) { + return; + } + OnRemoteRequest(static_cast(IEthernetServiceIpcCode::COMMAND_UN_REGISTER_CUSTOM_EAP_CALLBACK), parcel); +} + +void NotifyWpaEapInterceptInfoFuzzTest(const uint8_t *data, size_t size) +{ + if (data == nullptr) { + return; + } + g_baseFuzzData = data; + g_baseFuzzSize = size; + g_baseFuzzPos = 0; + MessageParcel parcel; + std::string netType = GetStringFromData(NET_TYPE_LEN); + WriteInterfaceToken(parcel); + if (!parcel.WriteInt32(std::stoi(netType))) { + return; + } + + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = std::stoi(GetStringFromData(NET_TYPE_LEN)); + eapData->eapType = std::stoi(GetStringFromData(NET_TYPE_LEN)); + eapData->msgId = std::stoi(GetStringFromData(NET_TYPE_LEN)); + eapData->bufferLen = std::stoi(GetStringFromData(REG_CMD_LEN)); + std::vector tmp = {0x11, 0x12, 0x13}; + eapData->eapBuffer = tmp; + eapData->Marshalling(parcel); + OnRemoteRequest(static_cast(IEthernetServiceIpcCode::COMMAND_NOTIFY_WPA_EAP_INTERCEPT_INFO), parcel); +} + void GetDeviceInformationFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { @@ -421,5 +562,10 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::NetManagerStandard::EthernetServiceCommonFuzzTest(data, size); OHOS::NetManagerStandard::EthernetManagementFuzzTest(data, size); OHOS::NetManagerStandard::EthernetDhcpControllerFuzzTest(data, size); + OHOS::NetManagerStandard::RegCustomEapHandlerFuzzTest(data, size); + OHOS::NetManagerStandard::ReplyCustomEapDataFuzzTest(data, size); + OHOS::NetManagerStandard::RegisterCustomEapCallbackFuzzTest(data, size); + OHOS::NetManagerStandard::UnRegisterCustomEapCallbackFuzzTest(data, size); + OHOS::NetManagerStandard::NotifyWpaEapInterceptInfoFuzzTest(data, size); return 0; } diff --git a/test/ethernetmanager/unittest/ethernet_manager_test/BUILD.gn b/test/ethernetmanager/unittest/ethernet_manager_test/BUILD.gn index c3fa9624..f16f5de5 100644 --- a/test/ethernetmanager/unittest/ethernet_manager_test/BUILD.gn +++ b/test/ethernetmanager/unittest/ethernet_manager_test/BUILD.gn @@ -40,6 +40,8 @@ ohos_unittest("ethernet_manager_test") { "ethernet_service_test.cpp", "mac_address_info_test.cpp", "ethernet_device_info_test.cpp", + "net_eap_callback_stub_test.cpp", + "net_eap_handler_test.cpp", ] include_dirs = [ @@ -84,6 +86,10 @@ ohos_unittest("ethernet_manager_test") { defines += [ "NETMGR_DEBUG" ] } + if (netmanager_ext_extensible_authentication) { + defines += [ "NET_EXTENSIBLE_AUTHENTICATION" ] + } + external_deps += [ "hilog:libhilog" ] part_name = "netmanager_ext" -- Gitee From 90c9abfc24862be4861d1a04c768bcf3b49acfed Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 11:12:44 +0000 Subject: [PATCH 7/9] extended certification Signed-off-by: shihaojie --- .../ethernet_manager_test.cpp | 87 ++++++++ .../ethernet_service_stub_test.cpp | 189 ++++++++++++++++++ 2 files changed, 276 insertions(+) diff --git a/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_manager_test.cpp b/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_manager_test.cpp index 7bc9d842..5b4cf2da 100644 --- a/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_manager_test.cpp +++ b/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_manager_test.cpp @@ -1441,5 +1441,92 @@ HWTEST_F(EthernetManagerTest, DevInterfaceRemoveTest003, TestSize.Level1) ethernetmanagement.DevInterfaceRemove(devName); EXPECT_EQ(devName, "123"); } + +#ifdef NET_EXTENSIBLE_AUTHENTICATION + +class NetRegisterEapCallbackTest : public NetRegisterEapCallbackStub { +public: + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override + { + return 0; + } + + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override + { + return 0; + } +}; + +class EapPostbackCallbackTest : public NetEapPostbackCallbackStub { +public: + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override + { + return 0; + } +}; + +HWTEST_F(EthernetManagerTest, RegCustomEapHandlerTest, TestSize.Level1) +{ + const NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + sptr netRegisterEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); + int32_t ret = DelayedSingleton::GetInstance()->RegisterCustomEapCallback(netType, netRegisterEapCallback); + sptr eapPostBackCallback = new (std::nothrow) EapPostbackCallbackTest(); + ret = DelayedSingleton::GetInstance()->RegCustomEapHandler(netType, regCmd, eapPostBackCallback); + EXPECT_EQ(ret, NETMANAGER_EXT_ERR_PERMISSION_DENIED); +} + +HWTEST_F(EthernetManagerTest, ReplyCustomEapDataTest, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + int result = 1; + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 13; + eapData->msgId = 55; + eapData->bufferLen = 4; + std::vector tmp = {0x11, 0x12}; + eapData->eapBuffer = tmp; + + sptr eapPostBackCallback = new (std::nothrow) EapPostbackCallbackTest(); + sptr netRegisterEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); + + auto ret = DelayedSingleton::GetInstance()->ReplyCustomEapData(result, eapData); + EXPECT_EQ(ret, NETMANAGER_EXT_ERR_PERMISSION_DENIED); + +} + +HWTEST_F(EthernetManagerTest, RegisterCustomEapCallbackTest, TestSize.Level1) +{ + const NetType netType = NetType::WLAN0; + sptr netRegisterEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); + int32_t ret = DelayedSingleton::GetInstance()->RegisterCustomEapCallback(netType, netRegisterEapCallback); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} + +HWTEST_F(EthernetManagerTest, UnRegisterCustomEapCallbackTest, TestSize.Level1) +{ + const NetType netType = NetType::WLAN0; + sptr netRegisterEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); + int32_t ret = DelayedSingleton::GetInstance()->UnRegisterCustomEapCallback(netType, netRegisterEapCallback); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} + +HWTEST_F(EthernetManagerTest, NotifyWpaEapInterceptInfoTest, TestSize.Level1) +{ + const NetType netType = NetType::WLAN0; + sptr eapData =new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 13; + eapData->msgId = 55; + eapData->bufferLen = 4; + std::vector tmp = {0x11, 0x12}; + eapData->eapBuffer = tmp; + int32_t ret = DelayedSingleton::GetInstance()->NotifyWpaEapInterceptInfo(netType, eapData); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} +#endif + } // namespace NetManagerStandard } // namespace OHOS diff --git a/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_stub_test.cpp b/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_stub_test.cpp index a416577e..36074cdc 100755 --- a/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_stub_test.cpp +++ b/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_stub_test.cpp @@ -21,6 +21,7 @@ #endif #include "ethernet_service_stub.h" +#include "net_eap_callback_stub.h" #include "iethernet_service.h" #include "net_manager_constants.h" #include "configuration_parcel_ipc.h" @@ -94,6 +95,32 @@ public: return 0; } + int32_t RegCustomEapHandler(int netType, const std::string ®Cmd, + const sptr &callback) override + { + return 0; + } + + int32_t ReplyCustomEapData(int result, const sptr &eapData) override + { + return 0; + } + + int32_t RegisterCustomEapCallback(int netType, const sptr &callback) override + { + return 0; + } + + int32_t UnRegisterCustomEapCallback(int netType, const sptr &callback) override + { + return 0; + } + + int32_t NotifyWpaEapInterceptInfo(int netType, const sptr &eapData) override + { + return 0; + } + int32_t GetDeviceInformation(std::vector &deviceInfoList) override { return 0; @@ -101,6 +128,29 @@ public: }; } // namespace +class NetRegisterEapCallbackTest : public NetRegisterEapCallbackStub { +public: + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override + { + return 0; + } + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override + { + return 0; + } +}; + +class NetEapPostBackCallbackTest : public NetEapPostbackCallbackStub { +public: + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override + { + return 0; + } +}; + +static inline sptr g_registerEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); +static inline sptr g_eapPostbackCallback = new (std::nothrow) NetEapPostBackCallbackTest(); + using namespace testing::ext; class EthernetServiceStubTest : public testing::Test { public: @@ -368,6 +418,145 @@ HWTEST_F(EthernetServiceStubTest, OnSetInterfaceConfigTest001, TestSize.Level1) EXPECT_EQ(ret, 5); } +/** + * @tc.name: RegCustomEapHandlerTest001 + * @tc.desc: Test EthernetServiceStub RegCustomEapHandler. + * @tc.type: FUNC + */ +HWTEST_F(EthernetServiceStubTest, RegCustomEapHandlerTest001, TestSize.Level1) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(EthernetServiceStub::GetDescriptor())) { + return; + } + int netType = static_cast(NetType::WLAN0); + if (!data.WriteInt32(netType)) { + return; + } + if (data.WriteRemoteObject(g_eapPostbackCallback->AsObject())) { + return; + } + MessageParcel reply; + MessageOption option; + int32_t ret = instance_->OnRemoteRequest(static_cast( + IEthernetServiceIpcCode::COMMAND_REG_CUSTOM_EAP_HANDLER), data, reply, option); + EXPECT_EQ(ret, NETMANAGER_EXT_SUCCESS); +} + +/** + * @tc.name: ReplyCustomEapDataTest001 + * @tc.desc: Test EthernetServiceStub ReplyCustomEapData. + * @tc.type: FUNC + */ +HWTEST_F(EthernetServiceStubTest, ReplyCustomEapDataTest001, TestSize.Level1) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(EthernetServiceStub::GetDescriptor())) { + return; + } + int result = 1; + if (!data.WriteInt32(result)) { + return; + } + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 25; + eapData->msgId = 55; + eapData->bufferLen = 3; + std::vector tmp = {0x11, 0x12, 0x13}; + eapData->eapBuffer = tmp; + if (!eapData->Marshalling(data)) { + return; + } + MessageParcel reply; + MessageOption option; + int32_t ret = instance_->OnRemoteRequest(static_cast( + IEthernetServiceIpcCode::COMMAND_REPLY_CUSTOM_EAP_DATA), data, reply, option); + EXPECT_EQ(ret, NETMANAGER_EXT_SUCCESS); +} + +/** + * @tc.name: RegisterCustomEapCallbackTest001 + * @tc.desc: Test EthernetServiceStub RegisterCustomEapCallback. + * @tc.type: FUNC + */ +HWTEST_F(EthernetServiceStubTest, RegisterCustomEapCallbackTest001, TestSize.Level1) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(EthernetServiceStub::GetDescriptor())) { + return; + } + int netType = 1; + if (!data.WriteInt32(netType)) { + return; + } + if (data.WriteRemoteObject(g_registerEapCallback->AsObject())) { + return; + } + MessageParcel reply; + MessageOption option; + int32_t ret = instance_->OnRemoteRequest(static_cast( + IEthernetServiceIpcCode::COMMAND_REGISTER_CUSTOM_EAP_CALLBACK), data, reply, option); + EXPECT_EQ(ret, NETMANAGER_EXT_SUCCESS); +} + +/** + * @tc.name: UnRegisterCustomEapCallbackTest001 + * @tc.desc: Test EthernetServiceStub UnRegisterCustomEapCallback. + * @tc.type: FUNC + */ +HWTEST_F(EthernetServiceStubTest, UnRegisterCustomEapCallbackTest001, TestSize.Level1) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(EthernetServiceStub::GetDescriptor())) { + return; + } + int netType = 1; + if (!data.WriteInt32(netType)) { + return; + } + if (data.WriteRemoteObject(g_registerEapCallback->AsObject())) { + return; + } + MessageParcel reply; + MessageOption option; + int32_t ret = instance_->OnRemoteRequest(static_cast( + IEthernetServiceIpcCode::COMMAND_UN_REGISTER_CUSTOM_EAP_CALLBACK), data, reply, option); + EXPECT_EQ(ret, NETMANAGER_EXT_SUCCESS); +} + +/** + * @tc.name: NotifyWpaEapInterceptInfoTest001 + * @tc.desc: Test EthernetServiceStub NotifyWpaEapInterceptInfo. + * @tc.type: FUNC + */ +HWTEST_F(EthernetServiceStubTest, NotifyWpaEapInterceptInfoTest001, TestSize.Level1) +{ + MessageParcel data; + if (!data.WriteInterfaceToken(EthernetServiceStub::GetDescriptor())) { + return; + } + int netType = 1; + if (!data.WriteInt32(netType)) { + return; + } + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 25; + eapData->msgId = 55; + eapData->bufferLen = 3; + std::vector tmp = {0x11, 0x12, 0x13}; + eapData->eapBuffer = tmp; + if (!eapData->Marshalling(data)) { + return; + } + MessageParcel reply; + MessageOption option; + int32_t ret = instance_->OnRemoteRequest(static_cast( + IEthernetServiceIpcCode::COMMAND_NOTIFY_WPA_EAP_INTERCEPT_INFO), data, reply, option); + EXPECT_EQ(ret, NETMANAGER_EXT_SUCCESS); +} + /** * @tc.name: OnGetDeviceInformationTest001 * @tc.desc: Test EthernetServiceStub OnGetDeviceInformation. -- Gitee From 61bb51e85fab4c5083a2138e2be32815771a602f Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 11:12:48 +0000 Subject: [PATCH 8/9] extended certification Signed-off-by: shihaojie --- .../src/net_eap_callback_proxy.cpp | 163 ++++++++++++++++++ .../ethernetmanager/src/net_eap_handler.cpp | 160 +++++++++++++++++ 2 files changed, 323 insertions(+) create mode 100644 services/ethernetmanager/src/net_eap_callback_proxy.cpp create mode 100644 services/ethernetmanager/src/net_eap_handler.cpp diff --git a/services/ethernetmanager/src/net_eap_callback_proxy.cpp b/services/ethernetmanager/src/net_eap_callback_proxy.cpp new file mode 100644 index 00000000..9812cab9 --- /dev/null +++ b/services/ethernetmanager/src/net_eap_callback_proxy.cpp @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2021-2023 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 "net_eap_callback_proxy.h" +#include "net_manager_constants.h" +#include "netmgr_ext_log_wrapper.h" + +namespace OHOS { +namespace NetManagerStandard { +NetEapPostbackCallbackProxy::NetEapPostbackCallbackProxy(const sptr &impl) + : IRemoteProxy(impl) +{} + +NetEapPostbackCallbackProxy::~NetEapPostbackCallbackProxy() {} + +int32_t NetEapPostbackCallbackProxy::OnEapSupplicantPostback(NetType netType, const sptr &eapData) +{ + MessageParcel dataParcel; + if (!WriteInterfaceToken(dataParcel)) { + NETMGR_EXT_LOG_E("WriteInterfaceToken failed"); + return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL; + } + + if (eapData == nullptr) { + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + + if (!dataParcel.WriteInt32(static_cast(netType))) { + return NETMANAGER_ERR_WRITE_DATA_FAIL; + } + + if (!eapData->Marshalling(dataParcel)) { + return NETMANAGER_ERR_WRITE_DATA_FAIL; + } + + if (eapData->eapBuffer.size() == 0) { + NETMGR_EXT_LOG_E("%{public}s, eapBuffer size is 0, %{public}s", __func__, eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_WRITE_DATA_FAIL; + } + + sptr remote = Remote(); + if (remote == nullptr) { + NETMGR_EXT_LOG_E("Remote is null"); + return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL; + } + MessageParcel replyParcel; + MessageOption option; + int32_t retCode = remote->SendRequest(static_cast(NetEapIpcCode::NET_EAP_POSTBACK), + dataParcel, replyParcel, option); + if (retCode != ERR_NONE) { + NETMGR_EXT_LOG_E("proxy SendRequest failed, retCode: [%{public}d]", retCode); + return retCode; + } + + return replyParcel.ReadInt32(); +} + +bool NetEapPostbackCallbackProxy::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(NetEapPostbackCallbackProxy::GetDescriptor())) { + NETMGR_EXT_LOG_E("WriteInterfaceToken failed"); + return false; + } + return true; +} + +NetRegisterEapCallbackProxy::NetRegisterEapCallbackProxy(const sptr &impl) + : IRemoteProxy(impl) +{} + +NetRegisterEapCallbackProxy::~NetRegisterEapCallbackProxy() {} + +int32_t NetRegisterEapCallbackProxy::OnRegisterCustomEapCallback(const std::string ®Cmd) +{ + MessageParcel dataParcel; + if (!WriteInterfaceToken(dataParcel)) { + NETMGR_EXT_LOG_E("WriteInterfaceToken failed"); + return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL; + } + + if (!dataParcel.WriteString(regCmd)) { + return NETMANAGER_ERR_WRITE_DATA_FAIL; + } + + sptr remote = Remote(); + if (remote == nullptr) { + NETMGR_EXT_LOG_E("Remote is null"); + return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL; + } + MessageParcel replyParcel; + MessageOption option; + int32_t retCode = remote->SendRequest(static_cast(NetEapIpcCode::NET_REGISTER_CUSTOM_EAP_CALLBACK), + dataParcel, replyParcel, option); + if (retCode != ERR_NONE) { + NETMGR_EXT_LOG_E("proxy SendRequest failed, retCode: [%{public}d]", retCode); + return retCode; + } + + return replyParcel.ReadInt32(); +} + +int32_t NetRegisterEapCallbackProxy::OnReplyCustomEapDataEvent(int result, const sptr &eapData) +{ + MessageParcel dataParcel; + if (eapData == nullptr) { + NETMGR_EXT_LOG_E("%{public}s, eapData is nullptr", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + if (!WriteInterfaceToken(dataParcel)) { + NETMGR_EXT_LOG_E("%{public}s, WriteInterfaceToken failed, %{public}s", __func__, + eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_WRITE_DESCRIPTOR_TOKEN_FAIL; + } + + if (!dataParcel.WriteInt32(result)) { + NETMGR_EXT_LOG_E("%{public}s, WriteInt32 result failed, %{public}s", __func__, eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_WRITE_DATA_FAIL; + } + + if (!eapData->Marshalling(dataParcel)) { + return NETMANAGER_ERR_WRITE_DATA_FAIL; + } + + sptr remote = Remote(); + if (remote == nullptr) { + NETMGR_EXT_LOG_E("%{public}s, remote is nullptr, %{public}s", __func__, eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_IPC_CONNECT_STUB_FAIL; + } + MessageParcel replyParcel; + MessageOption option; + int32_t retCode = remote->SendRequest(static_cast(NetEapIpcCode::NET_REPLY_CUSTOM_EAPDATA), + dataParcel, replyParcel, option); + if (retCode != ERR_NONE) { + NETMGR_EXT_LOG_E("%{public}s, SendRequest failed, retCode: [%{public}d]", __func__, retCode); + return retCode; + } + + return replyParcel.ReadInt32(); +} + +bool NetRegisterEapCallbackProxy::WriteInterfaceToken(MessageParcel &data) +{ + if (!data.WriteInterfaceToken(NetRegisterEapCallbackProxy::GetDescriptor())) { + NETMGR_EXT_LOG_E("WriteInterfaceToken failed"); + return false; + } + return true; +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file diff --git a/services/ethernetmanager/src/net_eap_handler.cpp b/services/ethernetmanager/src/net_eap_handler.cpp new file mode 100644 index 00000000..02b283de --- /dev/null +++ b/services/ethernetmanager/src/net_eap_handler.cpp @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2025-2025 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 "net_eap_handler.h" +#include +#include + +#include "netmgr_ext_log_wrapper.h" +#include "net_manager_constants.h" + +namespace OHOS { +namespace NetManagerStandard { + +NetEapHandler &NetEapHandler::GetInstance() +{ + static NetEapHandler gNetEap; + return gNetEap; +} + +int32_t NetEapHandler::RegisterCustomEapCallback(const NetType netType, const sptr &callback) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + if (callback == nullptr) + { + NETMGR_EXT_LOG_E("%{public}s, callback is nullptr", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + if (netType < NetType::WLAN0 || netType > NetType::ETH0) { + NETMGR_EXT_LOG_E("NetEapHandler, RegisterCustomEapCallback invalid netType %{public}d", netType); + return NETMANAGER_ERR_PARAMETER_ERROR; + } + std::unique_lock lock(mutex_); + regEapCallBack_[netType] = callback; + lock.unlock(); + + NETMGR_EXT_LOG_E("RegisterCustomEapCallback success, netType:%{public}d", static_cast(netType)); +#endif + return NETMANAGER_SUCCESS; +} + +int32_t NetEapHandler::UnRegisterCustomEapCallback(NetType netType, const sptr &callback) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + if (callback == nullptr) + { + NETMGR_EXT_LOG_E("%{public}s, postBackCb is nullptr", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + if (netType < NetType::WLAN0 || netType > NetType::ETH0) { + NETMGR_EXT_LOG_E("NetEapHandler, UnRegisterCustomEapCallback invalid netType %{public}d", netType); + return NETMANAGER_ERR_PARAMETER_ERROR; + } + std::unique_lock lock(mutex_); + auto iter = regEapCallBack_.find(netType); + if (iter != regEapCallBack_.end()) { + regEapCallBack_.erase(iter); + } + lock.unlock(); +#endif + return NETMANAGER_SUCCESS; +} + +int32_t NetEapHandler::RegCustomEapHandler(NetType netType, const std::string ®Cmd, + const sptr &postBackCb) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + if (postBackCb == nullptr) + { + NETMGR_EXT_LOG_E("%{public}s, postBackCb is nullptr", __func__); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + SetPostbackCallback(postBackCb); + if (netType < NetType::WLAN0 || netType > NetType::ETH0) { + NETMGR_EXT_LOG_E("NetEapHandler, RegCustomEapHandler invalid netType %{public}d", static_cast(netType)); + return NETMANAGER_ERR_PARAMETER_ERROR; + } + std::unique_lock lock(mutex_); + auto iter = regEapCallBack_.find(netType); + lock.unlock(); + if (iter == regEapCallBack_.end()) { + NETMGR_EXT_LOG_E("RegCustomEapHandler not have callback, netType:%{public}d", static_cast(netType)); + return NETMANAGER_ERR_INVALID_PARAMETER; + } + + if (iter->second == nullptr) { + NETMGR_EXT_LOG_E("regEapCallBack ptr is nullptr, netType:%{public}d", static_cast(netType)); + return NETMANAGER_ERR_INVALID_PARAMETER; + } + iter->second->OnRegisterCustomEapCallback(regCmd); + NETMGR_EXT_LOG_I("RegCustomEapHandler success."); +#endif + return NETMANAGER_SUCCESS; +} + +int32_t NetEapHandler::NotifyWpaEapInterceptInfo(const NetType netType, const sptr &eapData) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + if (eapData == nullptr) { + NETMGR_EXT_LOG_E("%{public}s eapData is nullptr, %{public}s", __func__, eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_LOCAL_PTR_NULL; + } + if (eapData->eapBuffer.size() == 0) { + NETMGR_EXT_LOG_E("%{public}s eapData size is 0, %{public}s", __func__, eapData->PrintLogInfo().c_str()); + return NETMANAGER_ERR_INVALID_PARAMETER; + } + auto postbackCb = GetPostbackCallback(); + if (postbackCb) { + nTMapMsgId_[netType] = eapData->msgId; + postbackCb->OnEapSupplicantPostback(netType, eapData); + } +#endif + return NETMANAGER_SUCCESS; +} + +int32_t NetEapHandler::ReplyCustomEapData(int result, const sptr &eapData) +{ +#ifdef NET_EXTENSIBLE_AUTHENTICATION + auto iter = std::find_if(nTMapMsgId_.begin(), nTMapMsgId_.end(), + [eapData](const std::pair& p) { return p.second == eapData->msgId; }); + if (iter == nTMapMsgId_.end()) { + NETMGR_EXT_LOG_E("%{public}s, don't match msgId and type, WALN0:%{public}zu, ETH0:%{public}zu", __func__, + nTMapMsgId_.count(NetType::WLAN0), nTMapMsgId_.count(NetType::ETH0)); + return NETMANAGER_ERR_OPERATION_FAILED; + } + std::unique_lock lock(mutex_); + auto &callback = regEapCallBack_[iter->first]; + lock.unlock(); + if (callback == nullptr) { + NETMGR_EXT_LOG_E("%{public}s, callback is nullptr", __func__); + return NETMANAGER_ERR_OPERATION_FAILED; + } + callback->OnReplyCustomEapDataEvent(result, eapData); +#endif + return NETMANAGER_SUCCESS; +} + +void NetEapHandler::SetPostbackCallback(const sptr &postbackCallback) +{ + postbackCallback_ = postbackCallback; +} + +sptr NetEapHandler::GetPostbackCallback() +{ + return postbackCallback_; +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file -- Gitee From 5c0c2810f06cd0a8f3b27174eee19ffd48e92fb1 Mon Sep 17 00:00:00 2001 From: shihaojie Date: Sat, 21 Jun 2025 11:14:39 +0000 Subject: [PATCH 9/9] extended certification Signed-off-by: shihaojie Signed-off-by: yuanchen13 --- .../ethernet_service_test.cpp | 83 +++++++ .../net_eap_callback_stub_test.cpp | 159 +++++++++++++ .../net_eap_handler_test.cpp | 209 ++++++++++++++++++ 3 files changed, 451 insertions(+) create mode 100644 test/ethernetmanager/unittest/ethernet_manager_test/net_eap_callback_stub_test.cpp create mode 100644 test/ethernetmanager/unittest/ethernet_manager_test/net_eap_handler_test.cpp diff --git a/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_test.cpp b/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_test.cpp index 2154f601..f52f0680 100644 --- a/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_test.cpp +++ b/test/ethernetmanager/unittest/ethernet_manager_test/ethernet_service_test.cpp @@ -55,6 +55,30 @@ public: void TearDown(); }; +class NetRegisterEapCallbackTest : public NetRegisterEapCallbackStub { +public: + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override + { + return 0; + } + + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override + { + return 0; + } +}; + +class EapPostbackCallbackTest : public NetEapPostbackCallbackStub { +public: + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override + { + return 0; + } +}; + +static sptr g_registerEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); +static sptr g_eapPostbackCallback = new (std::nothrow) EapPostbackCallbackTest(); + sptr EtherNetServiceTest::GetIfaceConfig() { sptr ic = (std::make_unique()).release(); @@ -484,5 +508,64 @@ HWTEST_F(EtherNetServiceTest, GetDeviceInformationTest001, TestSize.Level1) int ret = ethernetService.GetDeviceInformation(devInfoList); EXPECT_EQ(ret, NETMANAGER_EXT_ERR_PERMISSION_DENIED); } + +#ifdef NET_EXTENSIBLE_AUTHENTICATION +HWTEST_F(EtherNetServiceTest, RegCustomEapHandlerTest001, TestSize.Level1) +{ + EthernetService ethernetService; + NetType netType = NetType::WLAN0; + sptr callback_ = nullptr; + std::string regCmd = "2:277:278"; + auto ret = ethernetService.RegCustomEapHandler(static_cast(netType), regCmd, callback_); + EXPECT_EQ(ret, NETMANAGER_EXT_ERR_PERMISSION_DENIED); +} + +HWTEST_F(EtherNetServiceTest, ReplyCustomEapDataTest001, TestSize.Level1) +{ + EthernetService ethernetService; + int result = 1; + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 13; + eapData->msgId = 55; + eapData->bufferLen = 4; + std::vector tmp = {0x11, 0x12}; + eapData->eapBuffer = tmp; + int ret = ethernetService.ReplyCustomEapData(result, eapData); + EXPECT_EQ(ret, NETMANAGER_EXT_ERR_PERMISSION_DENIED); +} + +HWTEST_F(EtherNetServiceTest, RegisterCustomEapCallbackTest001, TestSize.Level1) +{ + EthernetService ethernetService; + NetType netType = NetType::WLAN0; + auto ret = ethernetService.RegisterCustomEapCallback(static_cast(netType), g_registerEapCallback); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} + +HWTEST_F(EtherNetServiceTest, UnRegisterCustomEapCallbackTest001, TestSize.Level1) +{ + EthernetService ethernetService; + NetType netType = NetType::WLAN0; + auto ret = ethernetService.UnRegisterCustomEapCallback(static_cast(netType), g_registerEapCallback); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} + +HWTEST_F(EtherNetServiceTest, NotifyWpaEapInterceptInfoTest001, TestSize.Level1) +{ + EthernetService ethernetService; + NetType netType = NetType::WLAN0; + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 13; + eapData->msgId = 55; + eapData->bufferLen = 4; + std::vector tmp = {0x11, 0x12}; + eapData->eapBuffer = tmp; + auto ret = ethernetService.NotifyWpaEapInterceptInfo(static_cast(netType), eapData); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} +#endif + } // namespace NetManagerStandard } // namespace OHOS diff --git a/test/ethernetmanager/unittest/ethernet_manager_test/net_eap_callback_stub_test.cpp b/test/ethernetmanager/unittest/ethernet_manager_test/net_eap_callback_stub_test.cpp new file mode 100644 index 00000000..35cd3b5d --- /dev/null +++ b/test/ethernetmanager/unittest/ethernet_manager_test/net_eap_callback_stub_test.cpp @@ -0,0 +1,159 @@ +/* + * Copyright (c) 2025 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 +#include +#include +#include "net_eap_callback_stub.h" + +namespace OHOS { +namespace NetManagerStandard { +using namespace testing::ext; +class MockNetEapPostbackCallbackStubTest : public NetEapPostbackCallbackStub { +public: + MockNetEapPostbackCallbackStubTest() = default; + ~MockNetEapPostbackCallbackStubTest() override {} + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override + { + std::cout << std::endl; + std::cout << "OnEapSupplicantPostback" << std::endl; + return 0; + } +}; + +class MockNetRegisterEapCallbackStubTest : public NetRegisterEapCallbackStub { +public: + MockNetRegisterEapCallbackStubTest() = default; + ~MockNetRegisterEapCallbackStubTest() override {} + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override + { + std::cout << std::endl; + std::cout << "OnRegisterCustomEapCallback" << std::endl; + return 0; + } + + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override + { + std::cout << std::endl; + std::cout << "OnReplyCustomEapDataEvent" << std::endl; + return 0; + } +}; + +class NetEapCallbackStubTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); + + static inline std::shared_ptr eapPostbackPtr = + std::make_shared(); + static inline std::shared_ptr registerEapPtr = + std::make_shared(); +}; + +void NetEapCallbackStubTest::SetUpTestCase() {} + +void NetEapCallbackStubTest::TearDownTestCase() {} + +void NetEapCallbackStubTest::SetUp() {} + +void NetEapCallbackStubTest::TearDown() {} + +/** + * @tc.name: OnRemoteRequest001 + * @tc.desc: Test NetEapCallbackStubTest OnRemoteRequest. + * @tc.type: FUNC + */ +HWTEST_F(NetEapCallbackStubTest, OnRemoteRequest001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + int32_t ret = eapPostbackPtr->OnRemoteRequest(100, data, reply, option); + EXPECT_EQ(ret, NETMANAGER_ERR_DESCRIPTOR_MISMATCH); + + data.WriteInterfaceToken(NetEapPostbackCallbackStub::GetDescriptor()); + ret = eapPostbackPtr->OnRemoteRequest(100, data, reply, option); + EXPECT_EQ(ret, IPC_STUB_UNKNOW_TRANS_ERR); +} + +/** + * @tc.name: OnEapSupplicantPostbackTest001 + * @tc.desc: Test NetEapPostbackCallbackStub OnEapSupplicantPostback. + * @tc.type: FUNC + */ +HWTEST_F(NetEapCallbackStubTest, OnEapSupplicantPostbackTest001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(NetEapPostbackCallbackStub::GetDescriptor()); + data.WriteInt32(1); + sptr eapData = new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 13; + eapData->msgId = 55; + eapData->bufferLen = 4; + std::vector tmp = {0x11, 0x12}; + eapData->eapBuffer = tmp; + eapData->Marshalling(data); + int32_t ret = eapPostbackPtr->OnRemoteRequest(static_cast(NetEapIpcCode::NET_EAP_POSTBACK), + data, reply, option); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} + +/** + * @tc.name: OnRegisterCustomEapCallbackTest001 + * @tc.desc: Test NetRegisterEapCallbackStub OnRegisterCustomEapCallback. + * @tc.type: FUNC + */ +HWTEST_F(NetEapCallbackStubTest, OnRegisterCustomEapCallbackTest001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(NetRegisterEapCallbackStub::GetDescriptor()); + std::string regCmd = "2:277:278"; + data.WriteString(regCmd); + int32_t ret = registerEapPtr->OnRemoteRequest(static_cast(NetEapIpcCode::NET_REPLY_CUSTOM_EAPDATA), + data, reply, option); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} + +/** + * @tc.name: OnReplyCustomEapDataEventTest001 + * @tc.desc: Test NetRegisterEapCallbackStub OnReplyCustomEapDataEvent. + * @tc.type: FUNC + */ +HWTEST_F(NetEapCallbackStubTest, OnReplyCustomEapDataEventTest001, TestSize.Level1) +{ + MessageParcel data; + MessageParcel reply; + MessageOption option; + data.WriteInterfaceToken(NetRegisterEapCallbackStub::GetDescriptor()); + int result = 1; + std::string strEapData = "55:4:abcd"; + + data.WriteInt32(result); + data.WriteString(strEapData); + int32_t ret = registerEapPtr->OnRemoteRequest(static_cast(NetEapIpcCode::NET_REPLY_CUSTOM_EAPDATA), + data, reply, option); + EXPECT_EQ(ret, NETMANAGER_SUCCESS); +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file diff --git a/test/ethernetmanager/unittest/ethernet_manager_test/net_eap_handler_test.cpp b/test/ethernetmanager/unittest/ethernet_manager_test/net_eap_handler_test.cpp new file mode 100644 index 00000000..c4c694d4 --- /dev/null +++ b/test/ethernetmanager/unittest/ethernet_manager_test/net_eap_handler_test.cpp @@ -0,0 +1,209 @@ +/* + * Copyright (c) 2025 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 + +#ifdef GTEST_API_ +#define private public +#define protected public +#endif + +#include "net_eap_handler.h" +#include "net_eap_callback_stub.h" + +namespace OHOS { +namespace NetManagerStandard { +namespace { +constexpr bool TEST_BOOL_VALUE = false; +constexpr int32_t TEST_INT32_VALUE = 1; +constexpr uint32_t TEST_UINT32_VALUE = 1; +constexpr const char *TEST_STRING_VALUE = "test"; +constexpr const char *TEST_DOMAIN = "test.com"; +} // namespace + +class NetRegisterEapCallbackTest : public NetRegisterEapCallbackStub { +public: + int32_t OnRegisterCustomEapCallback(const std::string ®Cmd) override + { + return 0; + } + + int32_t OnReplyCustomEapDataEvent(int result, const sptr &eapData) override + { + return 0; + } +}; + +class EapPostbackCallbackTest : public NetEapPostbackCallbackStub { +public: + int32_t OnEapSupplicantPostback(NetType netType, const sptr &eapData) override + { + return 0; + } +}; + +static sptr g_registerEapCallback = new (std::nothrow) NetRegisterEapCallbackTest(); +static sptr g_eapPostbackCallback = new (std::nothrow) EapPostbackCallbackTest(); + +using namespace testing::ext; +class NetEapHandlerTest : public testing::Test { +public: + static void SetUpTestCase(); + static void TearDownTestCase(); + void SetUp(); + void TearDown(); +}; + +void NetEapHandlerTest::SetUpTestCase() {} + +void NetEapHandlerTest::TearDownTestCase() {} + +void NetEapHandlerTest::SetUp() {} + +void NetEapHandlerTest::TearDown() {} + +HWTEST_F(NetEapHandlerTest, RegisterCustomEapCallbackTest001, TestSize.Level1) +{ + NetType netType = NetType::INVALID; + int ret1 = NetEapHandler::GetInstance().RegisterCustomEapCallback(netType, g_registerEapCallback); + EXPECT_EQ(ret1, NETMANAGER_ERR_PARAMETER_ERROR); +} + +HWTEST_F(NetEapHandlerTest, RegisterCustomEapCallbackTest002, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + sptr callback = nullptr; + int ret1 = NetEapHandler::GetInstance().RegisterCustomEapCallback(netType, callback); + EXPECT_EQ(ret1, NETMANAGER_ERR_LOCAL_PTR_NULL); +} + +HWTEST_F(NetEapHandlerTest, RegisterCustomEapCallbackTest003, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + int ret1 = NetEapHandler::GetInstance().RegisterCustomEapCallback(netType, g_registerEapCallback); + EXPECT_EQ(ret1, NETMANAGER_SUCCESS); +} + +HWTEST_F(NetEapHandlerTest, UnRegisterCustomEapCallbackTest001, TestSize.Level1) +{ + NetType netType = NetType::INVALID; + int ret1 = NetEapHandler::GetInstance().UnRegisterCustomEapCallback(netType, g_registerEapCallback); + EXPECT_EQ(ret1, NETMANAGER_ERR_PARAMETER_ERROR); +} + +HWTEST_F(NetEapHandlerTest, UnRegisterCustomEapCallbackTest002, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + sptr callback = nullptr; + int ret1 = NetEapHandler::GetInstance().UnRegisterCustomEapCallback(netType, callback); + EXPECT_EQ(ret1, NETMANAGER_ERR_LOCAL_PTR_NULL); +} + +HWTEST_F(NetEapHandlerTest, UnRegisterCustomEapCallbackTest003, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + int ret1 = NetEapHandler::GetInstance().UnRegisterCustomEapCallback(netType, g_registerEapCallback); + EXPECT_EQ(ret1, NETMANAGER_SUCCESS); +} + +HWTEST_F(NetEapHandlerTest, RegCustomEapHandlerTest001, TestSize.Level1) +{ + NetType netType = NetType::INVALID; + std::string regCmd = "2:277:278"; + int ret1 = NetEapHandler::GetInstance().RegCustomEapHandler(netType, regCmd, g_eapPostbackCallback); + EXPECT_EQ(ret1, NETMANAGER_ERR_PARAMETER_ERROR); +} + +HWTEST_F(NetEapHandlerTest, RegCustomEapHandlerTest002, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + int ret1 = NetEapHandler::GetInstance().RegCustomEapHandler(netType, regCmd, g_eapPostbackCallback); + EXPECT_EQ(ret1, NETMANAGER_ERR_INVALID_PARAMETER); +} + +HWTEST_F(NetEapHandlerTest, RegCustomEapHandlerTest003, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + int ret1 = NetEapHandler::GetInstance().RegisterCustomEapCallback(netType, nullptr); + if (ret1 != NETMANAGER_SUCCESS) { + return; + } + int ret2 = NetEapHandler::GetInstance().RegCustomEapHandler(netType, regCmd, g_eapPostbackCallback); + EXPECT_EQ(ret2, NETMANAGER_ERR_INVALID_PARAMETER); +} + +HWTEST_F(NetEapHandlerTest, RegCustomEapHandlerTest004, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + int ret1 = NetEapHandler::GetInstance().RegisterCustomEapCallback(netType, g_registerEapCallback); + if (ret1 != NETMANAGER_SUCCESS) { + return; + } + int ret2 = NetEapHandler::GetInstance().RegCustomEapHandler(netType, regCmd, g_eapPostbackCallback); + EXPECT_EQ(ret2, NETMANAGER_SUCCESS); +} + +HWTEST_F(NetEapHandlerTest, RegCustomEapHandlerTest005, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + int ret1 = NetEapHandler::GetInstance().RegCustomEapHandler(netType, regCmd, nullptr); + EXPECT_EQ(ret1, NETMANAGER_ERR_LOCAL_PTR_NULL); +} + +HWTEST_F(NetEapHandlerTest, NotifyWpaEapInterceptInfoTest001, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + NetEapHandler::GetInstance().RegisterCustomEapCallback(netType, g_registerEapCallback); + NetEapHandler::GetInstance().RegCustomEapHandler(netType, regCmd, g_eapPostbackCallback); + sptr eapData =new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 13; + eapData->msgId = 55; + eapData->bufferLen = 4; + std::vector tmp = {0x11, 0x12}; + eapData->eapBuffer = tmp; + int ret1 = NetEapHandler::GetInstance().NotifyWpaEapInterceptInfo(netType, eapData); + EXPECT_EQ(ret1, NETMANAGER_SUCCESS); +} + +HWTEST_F(NetEapHandlerTest, ReplyCustomEapDataTest001, TestSize.Level1) +{ + NetType netType = NetType::WLAN0; + std::string regCmd = "2:277:278"; + NetEapHandler::GetInstance().RegisterCustomEapCallback(netType, g_registerEapCallback); + NetEapHandler::GetInstance().RegCustomEapHandler(netType, regCmd, g_eapPostbackCallback); + sptr eapData =new (std::nothrow) EapData(); + eapData->eapCode = 1; + eapData->eapType = 13; + eapData->msgId = 55; + eapData->bufferLen = 4; + std::vector tmp = {0x11, 0x12}; + eapData->eapBuffer = tmp; + NetEapHandler::GetInstance().NotifyWpaEapInterceptInfo(netType, eapData); + eapData->msgId = 54; + int ret1 = NetEapHandler::GetInstance().ReplyCustomEapData(1, eapData); + EXPECT_EQ(ret1, NETMANAGER_ERR_OPERATION_FAILED); + eapData->msgId = 55; + int ret2 = NetEapHandler::GetInstance().ReplyCustomEapData(1, eapData); + EXPECT_EQ(ret2, NETMANAGER_SUCCESS); +} + +} // namespace NetManagerStandard +} // namespace OHOS \ No newline at end of file -- Gitee