1 /*
2  * Copyright (C) 2023 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 #ifdef HDI_WPA_INTERFACE_SUPPORT
17 #ifndef OHOS_WIFI_HDI_WPA_PROXY_H
18 #define OHOS_WIFI_HDI_WPA_PROXY_H
19 
20 #include <pthread.h>
21 #include "v1_0/ihostapd_interface.h"
22 #include "v1_0/ihostapd_callback.h"
23 #include "v1_1/iwpa_interface.h"
24 #include "v1_1/iwpa_callback.h"
25 #include "v1_1/wpa_types.h"
26 #include "wifi_error_no.h"
27 #include "securec.h"
28 #include "wifi_common_def.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef CHECK_HDI_WPA_INTERFACE
35 #define CHECK_HDI_WPA_INTERFACE(wpaObj) \
36 if (wpaObj == NULL) { \
37     LOGE("Hdi wpa proxy: wpaObj in %{public}s is NULL!", __func__); \
38     return; \
39 }
40 #endif
41 
42 #ifndef CHECK_HDI_WPA_INTERFACE_AND_RETURN
43 #define CHECK_HDI_WPA_INTERFACE_AND_RETURN(wpaObj, retValue) \
44 if (wpaObj == NULL) { \
45     LOGE("Hdi wpa proxy: wpaObj in %{public}s is NULL!", __func__); \
46     return retValue; \
47 }
48 #endif
49 
50 #ifndef CHECK_SECURE_FUNC
51 #define CHECK_SECURE_FUNC(ret) \
52 if (ret < 0) { \
53     LOGE("Hdi wpa proxy: call secure func failed in %{public}s", __func__); \
54     return; \
55 }
56 #endif
57 
58 #ifndef CHECK_SECURE_FUNC_AND_RETURN
59 #define CHECK_SECURE_FUNC_AND_RETURN(ret, retValue) \
60 if (ret < 0) { \
61     LOGE("Hdi wpa proxy: call secure func failed in %{public}s", __func__); \
62     return retValue; \
63 }
64 #endif
65 
66 #define EXEC_DISABLE 1
67 
68 /**
69  * @Description Create a channel between the HAL and the driver.
70  *
71  * @return WifiErrorNo - operation result
72  */
73 WifiErrorNo HdiWpaStart();
74 
75 /**
76  * @Description Stop the created channel.
77  *
78  * @return WifiErrorNo - operation result
79  */
80 WifiErrorNo HdiWpaStop();
81 
82 /**
83  * @Description check wpa hdi already stopped.
84  *
85  * @return WifiErrorNo - operation result
86  */
87 WifiErrorNo IsHdiWpaStopped();
88 
89 
90 /**
91  * @Description Add interface.
92  *
93  * @return WifiErrorNo - operation result
94  */
95 WifiErrorNo HdiAddWpaIface(const char *ifName, const char *confName);
96 
97 /**
98  * @Description Remove interface.
99  *
100  * @return WifiErrorNo - operation result
101  */
102 WifiErrorNo HdiRemoveWpaIface(const char *ifName);
103 
104 WifiErrorNo SetHdiStaIfaceName(const char *ifaceName, int instId);
105 const char *GetHdiStaIfaceName(int instId);
106 void ClearHdiStaIfaceName(int instId);
107 WifiErrorNo SetHdiP2pIfaceName(const char *ifaceName);
108 const char *GetHdiP2pIfaceName();
109 
110 /**
111  * @Description Create the WiFi object.
112  *
113  * @return WifiErrorNo - operation result
114  */
115 struct IWpaInterface* GetWpaInterface();
116 pthread_mutex_t* GetWpaObjMutex(void);
117 
118 /**
119  * @Description copy file.
120  *
121  * @return WifiErrorNo - operation result
122  */
123 WifiErrorNo CopyUserFile(const char *srcFilePath, const char* destFilePath);
124 
125 /**
126  * @Description copy wpa_supplicant config file.
127  *
128  * @return WifiErrorNo - operation result
129  */
130 WifiErrorNo CopyConfigFile(const char* configName);
131 
132 /**
133  * @Description Create a ap channel between the HAL and the driver.
134  *
135  * @return WifiErrorNo - operation result
136  */
137 WifiErrorNo HdiApStart(int id, const char *ifaceName);
138 
139 /**
140  * @Description Stop the created ap channel.
141  *
142  * @return WifiErrorNo - operation result
143  */
144 WifiErrorNo HdiApStop(int id);
145 
146 /**
147  * @Description check wpa hdi ap already stopped.
148  *
149  * @return WifiErrorNo - operation result
150  */
151 WifiErrorNo IsHdiApStopped();
152 
153 /**
154  * @Description Add death recipient callback.
155  *
156  * @return WifiErrorNo - operation result
157  */
158 WifiErrorNo SetNativeProcessCallback(void (*callback)(int));
159 
160 /**
161  * @Description Create the Ap object.
162  *
163  * @return WifiErrorNo - operation result
164  */
165 struct IHostapdInterface* GetApInterface();
166 
167 WifiErrorNo SetHdiApIfaceName(const char *ifaceName);
168 const char *GetHdiApIfaceName();
169 
170 void SetExecDisable(int execDisable);
171 int GetExecDisable();
172 
173 #ifdef __cplusplus
174 }
175 #endif
176 #endif
177 #endif
178