• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 WIFI_NET_EAP_OBSERVER_H
17 #define WIFI_NET_EAP_OBSERVER_H
18 
19 #include <memory>
20 #include <string>
21 #include <vector>
22 #include "wifi_log.h"
23 #include "wifi_msg.h"
24 #include "iremote_broker.h"
25 #include "ethernet_client.h"
26 
27 namespace OHOS {
28 namespace Wifi {
29 
30 class NetEapCallback : public NetManagerStandard::NetRegisterEapCallbackStub {
31 public:
32 
33     /**
34      * @Description Construct of NetEapObserver
35      */
36     NetEapCallback();
37 
38     /**
39      * @Description Destructor function
40      */
41     ~NetEapCallback();
42 
43     /**
44      * @Description registers the EapCustomHandler callback function of the Wi-Fi state machine.
45      *
46      * @param callback - callback func
47      */
48     bool SetRegisterCustomEapCallback(const std::function<void(const std::string &)> &callback);
49 
50     /**
51      * @Description registers the ReplyCustomEapData function of the Wi-Fi state machine.
52      *
53      * @param callback - callback func
54      */
55     bool SetReplyCustomEapDataCallback(const std::function<void(int, const std::string&)> &callback);
56 
57 public:
58     /**
59      * @Description Register Custom Eap Callback
60      *
61      * @param regCmd - register command. eg: 2:277:278
62      */
63     int32_t OnRegisterCustomEapCallback(const std::string &regCmd) override;
64 
65     /**
66      * @Description callback function used to Reply Custom EapData Event
67      * @param result - Indicates the result of custom authentication
68      * @param eapData - Indicates sptr of eap data
69      */
70     int32_t OnReplyCustomEapDataEvent(int result, const sptr<NetManagerStandard::EapData> &eapData) override;
71 
72     std::function<void(const std::string &)> GetRegisterCustomEapCallback();
73 public:
74     std::function<void(const std::string &)> regCallback_ = nullptr;
75     std::function<void(int, const std::string&)> replyCallback_ = nullptr;
76     std::string regCmd_ = {};
77 };
78 
79 class NetEapObserver {
80 public:
81     static NetEapObserver &GetInstance();
82     ~NetEapObserver();
83 
84     bool StartNetEapObserver();
85     bool StopNetEapObserver();
86     bool SetRegisterCustomEapCallback(const std::function<void(const std::string &)> &callback);
87     bool SetReplyCustomEapDataCallback(const std::function<void(int, const std::string&)> &callback);
88     void ReRegisterCustomEapCallback();
89     bool NotifyWpaEapInterceptInfo(const WpaEapData &wpaEapData);
GetNetEapCallbackPtr()90     sptr<NetEapCallback> GetNetEapCallbackPtr()
91     {
92         return netEapCallback_;
93     }
94 
95 public:
96     sptr<NetEapCallback> netEapCallback_ = nullptr;
97 
98 private:
99     NetEapObserver();
100     std::mutex mutex_;
101 };
102 
103 }
104 }
105 #endif