1 /* 2 * Copyright (c) 2025 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_EAP_HDI_WPA_MANAGER_H 17 #define OHOS_EAP_HDI_WPA_MANAGER_H 18 19 #ifdef NET_EXTENSIBLE_AUTHENTICATION 20 21 #include <vector> 22 #include <mutex> 23 #include <pthread.h> 24 25 #include "eap_data.h" 26 #include "eth_eap_profile.h" 27 #include "devmgr_hdi.h" 28 #include "hdf_remote_service.h" 29 #include "servmgr_hdi.h" 30 #include "v1_0/iethernet.h" 31 #include "v1_0/iethernet_callback.h" 32 33 namespace OHOS { 34 namespace NetManagerStandard { 35 36 class EapHdiWpaManager : public std::enable_shared_from_this<EapHdiWpaManager> { 37 public: 38 EapHdiWpaManager(); 39 ~EapHdiWpaManager() = default; 40 41 int32_t LoadEthernetHdiService(); 42 int32_t StartEap(const std::string& ifName, const EthEapProfile& profile); 43 int32_t StopEap(const std::string& ifName); 44 int32_t RegisterCustomEapCallback(const std::string &ifName, const std::string ®Cmd); 45 int32_t ReplyCustomEapData(const std::string &ifName, int32_t result, const sptr<EapData> &eapData); 46 47 private: 48 int32_t SetEapConfig(const EthEapProfile& config, const std::string& ifName); 49 int32_t EapShellCmd(const std::string& ifName, const std::string& cmd); 50 int32_t RegisterEapEventCallback(const std::string& ifName); 51 int32_t UnregisterEapEventCallback(const std::string& ifName); 52 static int32_t OnEapEventReport(IEthernetCallback *self, const char *ifName, const char *value); 53 54 bool WriteEapConfigToFile(const std::string &fileContext); 55 std::string Phase2MethodToStr(EapMethod eap, Phase2Method method); 56 void RemoveHistoryCtrl(); 57 void UnloadDeviceManager(); 58 static bool ConvertStrToInt(const std::string &str, int32_t &value); 59 60 private: 61 struct IEthernet *iEthernet_ = nullptr; 62 struct HDIDeviceManager *devMgr_ = nullptr; 63 std::mutex wpaMutex_; 64 struct IEthernetCallback ethCallback_; 65 }; 66 } // namespace NetManagerStandard 67 } // namespace OHOS 68 #endif // NET_EXTENSIBLE_AUTHENTICATION 69 #endif // OHOS_EAP_HDI_WPA_CALLBACK_H 70