1 /*
2  * Copyright (C) 2021 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_WIFI_SUPPLICANT_HAL_INTERFACE_H
17 #define OHOS_WIFI_SUPPLICANT_HAL_INTERFACE_H
18 
19 #include <string>
20 #include "supplicant_event_callback.h"
21 #include "wifi_base_hal_interface.h"
22 #include "wifi_error_no.h"
23 #include "i_wifi_struct.h"
24 #include "define.h"
25 
26 namespace OHOS {
27 namespace Wifi {
28 class WifiSupplicantHalInterface : public WifiBaseHalInterface {
29 public:
30     /**
31      * @Description Get the Instance object.
32      *
33      * @return WifiSupplicantHalInterface&
34      */
35     static WifiSupplicantHalInterface &GetInstance(void);
36 
37     /**
38      * @Description Open Supplicant.
39      *
40      * @return WifiErrorNo
41      */
42     WifiErrorNo StartSupplicant(void) const;
43 
44     /**
45      * @Description Close Supplicant.
46      *
47      * @return WifiErrorNo
48      */
49     WifiErrorNo StopSupplicant(void) const;
50 
51     /**
52      * @Description Connect Supplicant.
53      *
54      * @return WifiErrorNo
55      */
56     WifiErrorNo ConnectSupplicant(void) const;
57 
58     /**
59      * @Description Disconnect Supplicant.
60      *
61      * @return WifiErrorNo
62      */
63     WifiErrorNo DisconnectSupplicant(void) const;
64 
65     /**
66      * @Description Request to Supplicant.
67      *
68      * @param request
69      * @return WifiErrorNo
70      */
71     WifiErrorNo RequestToSupplicant(const std::string &request) const;
72 
73     /**
74      * @Description Registers the supplementary event callback function.
75      *
76      * @param callback
77      * @return WifiErrorNo
78      */
79     WifiErrorNo RegisterSupplicantEventCallback(SupplicantEventCallback &callback);
80 
81     /**
82      * @Description Deregisters the supplementary event callback function.
83      *
84      * @return WifiErrorNo
85      */
86     WifiErrorNo UnRegisterSupplicantEventCallback(void);
87 
88     /**
89      * @Description Turn on/off power save mode for the interface.
90      *
91      * @param enable
92      * @return WifiErrorNo
93      */
94     WifiErrorNo SetPowerSave(bool enable) const;
95 
96     /**
97      * @Description Setting the country code.
98      *
99      * @param countryCode
100      * @return WifiErrorNo
101      */
102     WifiErrorNo WpaSetCountryCode(const std::string &countryCode) const;
103 
104     /**
105      * @Description Obtains the country code.
106      *
107      * @param countryCode
108      * @return WifiErrorNo
109      */
110     WifiErrorNo WpaGetCountryCode(std::string &countryCode) const;
111 
112     /**
113      * @Description Get register callback objects
114      *
115      * @return const SupplicantEventCallback& - register callback objects
116      */
117     const SupplicantEventCallback &GetCallbackInst(void) const;
118 
119     /**
120      * @Description  Set suspend mode to wpa
121      *
122      * @param mode - true for suspend mode, false for resume mode
123      *
124      * @Return success: WIFI_OPT_SUCCESS, fail: WIFI_OPT_FAILED
125      */
126     WifiErrorNo WpaSetSuspendMode(bool mode) const;
127 
128     /**
129      * @Description  Set power mode to wpa
130      *
131      * @param mode - true for power mode, false for resume mode
132      *
133      * @Return success: WIFI_OPT_SUCCESS, fail: WIFI_OPT_FAILED
134      */
135     WifiErrorNo WpaSetPowerMode(bool mode) const;
136 
137     void NotifyScanResultEvent();
138 private:
139     SupplicantEventCallback mCallback;
140     static std::mutex mSupplicantHalMutex;
141 };
142 }  // namespace Wifi
143 }  // namespace OHOS
144 
145 #endif