1 /*
2  * Copyright (C) 2024 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 WPA_HAL_DEFINE_H
17 #define WPA_HAL_DEFINE_H
18 
19 /* Contains common header files. */
20 #include <stdint.h>
21 #include <stdio.h>
22 #include <string.h>
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 #define WIFI_COUNTRY_CODE_MAXLEN 2
28 #define WIFI_IFACE_NAME_MAXLEN 32
29 #define WIFI_P2P_WPS_NAME_LENGTH 128
30 #define WIFI_P2P_WPS_METHODS_LENGTH 256
31 #define WIFI_P2P_WFD_DEVICE_CONF_LENGTH 256
32 #define WIFI_P2P_SERVE_INFO_LENGTH 256
33 #define WIFI_P2P_SERVE_DISCOVER_MSG_LENGTH 256
34 #define WIFI_P2P_SERVER_DISCOVERY_SEQUENCE_LENGTH 64
35 #define WIFI_P2P_GROUP_IFNAME_LENGTH 128
36 #define WIFI_P2P_SERVER_NAME_LENGTH 256
37 #define WIFI_NETWORK_PSK_MAXLEN 64
38 #define WIFI_NAME_MAX_LENGTH 256
39 
40 #define WPA_SUPPLICANT_NAME "wpa_supplicant"
41 #define WPA_HOSTAPD_NAME "hostapd"
42 
43 #define HAL_SUCCESS 0
44 #define HAL_FAILURE (-1)
45 #define WIFI_HAL_FALSE 0
46 #define WIFI_HAL_TRUE 1
47 
48 #define WEAK_FUNC __attribute__((weak))
49 
50 #define STA_CB_SCAN_FAILED 1
51 #define STA_CB_SCAN_OVER_OK 2
52 
53 typedef enum WifiErrorNo {
54     WIFI_HAL_SUCCESS = 0,                /* Success. */
55     WIFI_HAL_FAILED = 1,                 /* Failed. */
56     WIFI_HAL_SCAN_BUSY = 2,              /* Scan failed. Scan busy. */
57     WIFI_HAL_PBC_OVERLAP = 3,            /* WPS PBC mode overlap. */
58     WIFI_HAL_SUPPLICANT_NOT_INIT = 4,    /* The wpa_supplicant is not initialized or fails to be initialized. */
59     WIFI_HAL_OPEN_SUPPLICANT_FAILED = 5, /* Start wpa_supplicant failed. */
60     WIFI_HAL_CONN_SUPPLICANT_FAILED = 6, /* Connect wpa_supplicant failed. */
61     WIFI_HAL_HOSTAPD_NOT_INIT = 7,       /* Hostapd is not initialized or initialization fails. */
62     WIFI_HAL_OPEN_HOSTAPD_FAILED = 8,    /* Start hostapd failed. */
63     WIFI_HAL_CONN_HOSTAPD_FAILED = 9,    /* Connect hostapd failed. */
64     WIFI_HAL_NOT_SUPPORT = 10,           /* Not supported currently. */
65     WIFI_HAL_GET_WIFI_COND_FAILED,       /* Initialized  wificond failed. */
66     WIFI_HAL_BUFFER_TOO_LITTLE,          /* request buffer size too small */
67     WIFI_HAL_INPUT_MAC_INVALID,
68     WIFI_HAL_GET_VENDOR_HAL_FAILED,      /* Initialized vendor hal failed. */
69     WIFI_HAL_VENDOR_UNKNOWN,
70     WIFI_HAL_VENDOR_UNINITIALIZED,
71     WIFI_HAL_VENDOR_NOT_AVAILABLE,
72     WIFI_HAL_VENDOR_INVALID_ARGS,
73     WIFI_HAL_VENDOR_INVALID_REQUEST_ID,
74     WIFI_HAL_VENDOR_TIMED_OUT,
75     WIFI_HAL_VENDOR_TOO_MANY_REQUESTS,
76     WIFI_HAL_VENDOR_OUT_OF_MEMORY,
77     WIFI_HAL_VENDOR_BUSY,
78     WIFI_HAL_INVALID_PARAM,
79     WIFI_HAL_GET_P2P_GROUP_INFACE_FAILED,
80 } WifiErrorNo;
81 
82 /* ID of the callback event for registering the Hal service. */
83 typedef enum WifiHalEvent {
84     WIFI_FAILURE_EVENT = 100,            /* Driver loading/unloading failure. */
85     WIFI_START_EVENT,                    /* The driver has been loaded. */
86     WIFI_STOP_EVENT,                     /* Driver uninstalled. */
87     WIFI_ADD_IFACE_EVENT,                /* The network device interface has been added. */
88     WIFI_REMOVE_IFACE_EVENT,             /* The network device interface has been deleted. */
89     WIFI_STA_JOIN_EVENT,                 /* STA connection notification in AP mode. */
90     WIFI_STA_LEAVE_EVENT,                /* STA disconnection notification in AP mode. */
91     WIFI_SCAN_INFO_NOTIFY_EVENT,         /* Scan info notification. */
92     WIFI_CONNECT_CHANGED_NOTIFY_EVENT,   /* Connection status change notification. */
93     WIFI_BSSID_CHANGED_NOTIFY_EVENT,     /* Bssid change notification. */
94     WIFI_AP_ENABLE_EVENT,                /* AP enabling notification. */
95     WIFI_AP_DISABLE_EVENT,               /* AP closure notification. */
96     WIFI_WPA_STATE_EVENT,                /* WPA status change. */
97     WIFI_SSID_WRONG_KEY,                 /* Incorrect password. */
98     WIFI_CONNECTION_FULL_EVENT,          /* connection is full */
99     WIFI_CONNECTION_REJECT_EVENT,        /* connection reject */
100     WIFI_WPS_OVERLAP,                    /* wps pbc overlap */
101     WIFI_WPS_TIME_OUT,                   /* wps connect time out */
102     WIFI_P2P_SUP_CONNECTION_EVENT,       /* Connection result of the wpa_supplicant client */
103     SUP_CONN_FAILED_EVENT,               /* Wpa_supplicant client connection failure event */
104     P2P_DEVICE_FOUND_EVENT,              /* Device discovery event */
105     P2P_DEVICE_LOST_EVENT,               /* Device loss event */
106     P2P_GO_NEGOTIATION_REQUEST_EVENT,    /* Event of receiving a GO negotiation request */
107     P2P_GO_NEGOTIATION_SUCCESS_EVENT,    /* The GO negotiation is successful */
108     P2P_GO_NEGOTIATION_FAILURE_EVENT,    /* The GO negotiation fails */
109     P2P_INVITATION_RECEIVED_EVENT,       /* P2P invitation request event */
110     P2P_INVITATION_RESULT_EVENT,         /* P2P invitation result */
111     P2P_GROUP_FORMATION_SUCCESS_EVENT,   /* The group is created successfully */
112     P2P_GROUP_FORMATION_FAILURE_EVENT,   /* The group is created failure */
113     P2P_GROUP_STARTED_EVENT,             /* Group Start Event */
114     P2P_GROUP_REMOVED_EVENT,             /* Group removed event */
115     P2P_PROV_DISC_PBC_REQ_EVENT,         /* Provision Discovery request event */
116     P2P_PROV_DISC_PBC_RSP_EVENT,         /* Provision Discovery Response Event */
117     P2P_PROV_DISC_ENTER_PIN_EVENT,       /* Provision Discovery PIN input event */
118     P2P_PROV_DISC_SHOW_PIN_EVENT,        /* Provision Discovery Display PIN Event */
119     P2P_FIND_STOPPED_EVENT,              /* Device search stop event */
120     P2P_SERV_DISC_RESP_EVENT,            /* Service response event */
121     P2P_PROV_DISC_FAILURE_EVENT,         /* Provision Discovery failure event */
122     AP_STA_DISCONNECTED_EVENT,           /* STA Disconnected from AP */
123     AP_STA_CONNECTED_EVENT,              /* STA and AP connected event */
124     P2P_SERV_DISC_REQ_EVENT,             /* Service discovery request event */
125     P2P_IFACE_CREATED_EVENT,             /* P2P interface created event */
126     WIFI_HAL_COMMON_EVENT,               /* CHBA recv common event */
127     AP_STA_PSK_MISMATH_EVENT,            /* AP STA possible PSK mismatch event */
128     P2P_CONNECT_FAILED,                  /* P2P connect failed */
129     WIFI_HAL_MAX_EVENT,
130 } WifiHalEvent;
131 
132 #define WIFI_BSSID_LENGTH 18
133 #define WIFI_NETWORK_FLAGS_LENGTH 64
134 #define WIFI_SSID_LENGTH 132
135 #define WIFI_SCAN_INFO_CAPABILITY_LENGTH 256
136 #define WIFI_NETWORK_CONFIG_NAME_LENGTH 64
137 #define WIFI_NETWORK_CONFIG_VALUE_LENGTH 2048
138 #define WIFI_P2P_GROUP_CONFIG_VALUE_LENGTH 256
139 #define WIFI_MAC_LENGTH 17
140 #define WIFI_REASON_LENGTH 32
141 #define WIFI_AP_PASSWORD_LENGTH 64
142 #define WIFI_PIN_CODE_LENGTH 8
143 
144 /* Wifi network configuration parameter flag. */
145 typedef enum DeviceConfigType {
146     DEVICE_CONFIG_SSID = 0,            /* Network Name. */
147     DEVICE_CONFIG_PSK = 1,             /* Password. */
148     /**
149      * Encryption Mode: WPA-PSK - wpa/wp2; NONE - password less network; WPA-EAP, SAE, wpa3.
150      */
151     DEVICE_CONFIG_KEYMGMT = 2,
152     DEVICE_CONFIG_PRIORITY = 3,        /* WPA network priority */
153     /**
154      * Set this bit to 1 and deliver it when the hidden network is connected.
155      * In other cases, set this bit to 0 but do not deliver it.
156      */
157     DEVICE_CONFIG_SCAN_SSID = 4,
158     DEVICE_CONFIG_EAP = 5,             /* EPA Mode:/EAP/PEAP. */
159     DEVICE_CONFIG_IDENTITY = 6,        /* Account name. */
160     DEVICE_CONFIG_PASSWORD = 7,        /* Account password. */
161     DEVICE_CONFIG_BSSID = 8,           /* bssid. */
162     DEVICE_CONFIG_AUTH_ALGORITHMS = 9, /* auth algorithms */
163     DEVICE_CONFIG_WEP_KEY_IDX = 10,    /* wep key idx */
164     DEVICE_CONFIG_WEP_KEY_0 = 11,
165     DEVICE_CONFIG_WEP_KEY_1 = 12,
166     DEVICE_CONFIG_WEP_KEY_2 = 13,
167     DEVICE_CONFIG_WEP_KEY_3 = 14,
168     DEVICE_CONFIG_EAP_CLIENT_CERT = 15,
169     DEVICE_CONFIG_EAP_PRIVATE_KEY = 16,
170     DEVICE_CONFIG_EAP_PHASE2METHOD = 17,
171     DEVICE_CONFIG_IEEE80211W = 18,
172     DEVICE_CONFIG_ALLOW_PROTOCOLS = 19,
173     DEVICE_CONFIG_GROUP_CIPHERS = 20,
174     DEVICE_CONFIG_PAIRWISE_CIPHERS = 21,
175     DEVICE_CONFIG_SAE_PASSWD = 22,
176     DEVICE_CONFIG_EAP_CA_CERT = 23,
177     DEVICE_CONFIG_EAP_CERT_PWD = 24,
178     DEVICE_CONFIG_WAPI_CA_CERT = 25,
179     DEVICE_CONFIG_WAPI_USER_CERT = 26,
180     DEVICE_CONFIG_WAPI_PSK_KEY_TYPE = 27,
181     DEVICE_CONFIG_WAPI_PSK = 28,
182     /**
183      * Number of network configuration parameters, which is used as the last
184      * parameter.
185      */
186     DEVICE_CONFIG_END_POS,
187 } DeviceConfigType;
188 
189 typedef enum P2pGroupConfigType {
190     GROUP_CONFIG_SSID = 0,
191     GROUP_CONFIG_BSSID,
192     GROUP_CONFIG_PSK,
193     GROUP_CONFIG_PROTO,
194     GROUP_CONFIG_KEY_MGMT,
195     GROUP_CONFIG_PAIRWISE,
196     GROUP_CONFIG_AUTH_ALG,
197     GROUP_CONFIG_MODE,
198     GROUP_CONFIG_DISABLED,
199     GROUP_CONFIG_END_POS,
200 } P2pGroupConfigType;
201 
202 /* AP Band */
203 typedef enum ApBand {
204     AP_NONE_BAND = 0, /* Unknown Band */
205     AP_2GHZ_BAND = 1, /* 2.4GHz Band */
206     AP_5GHZ_BAND = 2, /* 5GHz Band */
207     AP_ANY_BAND = 3,  /* Dual-mode frequency band */
208     AP_DFS_BAND = 4
209 } ApBand;
210 
211 /*  Encryption Mode */
212 typedef enum KeyMgmt {
213     NONE = 0,    /* WPA not used. */
214     WPA_PSK = 1, /* WPA pre-shared key ({@ preSharedKey} needs to be specified.) */
215     /**
216      * WPA with EAP authentication. It is usually used with an external
217      * authentication server.
218      */
219     WPA_EAP = 2,
220     /**
221      * IEEE 802.1X with EAP authentication and optionally dynamically generated
222      * WEP keys.
223      */
224     IEEE8021X = 3,
225     /**
226      * WPA2 pre-shared key, which is used for soft APs({@ preSharedKey} needs to
227      * be specified).
228      */
229     WPA2_PSK = 4,
230     OSEN = 5,
231     FT_PSK = 6,
232     FT_EAP = 7
233 } KeyMgmt;
234 
235 /* chip supported interface combination mode */
236 typedef enum WifiInterfaceCombMode {
237     STA_STA_MODE,
238     STA_AP_MODE,
239     STA_P2P_MODE,
240     STA_NAN_MODE,
241     AP_NAN_MODE,
242 } WifiInterfaceCombMode;
243 
244 typedef enum HalWpsMethod {
245     HAL_WPS_METHOD_PBC,
246     HAL_WPS_METHOD_DISPLAY,
247     HAL_WPS_METHOD_KEYPAD,
248     HAL_WPS_METHOD_LABEL,
249     HAL_WPS_METHOD_INVALID
250 } HalWpsMethod;
251 
252 typedef enum HalPortType {
253     HAL_PORT_TYPE_STATION    = 0,
254     HAL_PORT_TYPE_AP         = 1,
255     HAL_PORT_TYPE_P2P_CLIENT = 2,
256     HAL_PORT_TYPE_P2P_GO     = 3,
257     HAL_PORT_TYPE_P2P_DEVICE = 4,
258     HAL_PORT_TYPE_BUTT            // invalid type
259 }HalPortType;
260 
261 #ifdef __cplusplus
262 }
263 #endif
264 #endif
265