• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2020 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 /**
17  * @addtogroup wifiservice
18  * @{
19  *
20  * @brief Provides functions for the Wi-Fi station and hotspot modes.
21  *
22  * You can use this module to enable and disable the Wi-Fi station or hotspot mode, connect to and disconnect from a
23  * station or hotspot, query the station or hotspot status, and listen for events. \n
24  *
25  * @since 7
26  */
27 
28 /**
29  * @file wifi_device_config.h
30  *
31  * @brief Defines the Wi-Fi station configuration.
32  *
33  * The Wi-Fi station configuration includes the security type and data length. \n
34  *
35  * @since 7
36  */
37 
38 #ifndef WIFI_LITE_WIFI_DEVICE_CONFIG_H
39 #define WIFI_LITE_WIFI_DEVICE_CONFIG_H
40 
41 /**
42  * @brief Indicates the maximum number of Wi-Fi station configurations that can be added using {@link AddDeviceConfig}.
43  *
44  * If the maximum number is reached, an error will be returned. In this case, you must delete at least one
45  * configuration before you can add new ones. \n
46  */
47 #define WIFI_MAX_CONFIG_SIZE 10
48 /**
49  * @brief Indicates the value of <b>networkId</b> when the configuration file is unavailable.
50  *
51  * Generally, the configuration file is unavailable because the configuration matching the <b>networkId</b> is
52  * uninitialized. \n
53  */
54 #define WIFI_CONFIG_INVALID (-1)
55 /**
56  * @brief Indicates the maximum length of a Wi-Fi SSID.
57  *
58  * The maximum length is 32, and the last bit is reserved and set to <b>\0</b>. \n
59  */
60 #define WIFI_MAX_SSID_LEN 33 // 32 + \0
61 /**
62  * @brief Indicates the maximum length of a Wi-Fi key.
63  *
64  * The maximum length is 64, and the last bit is reserved and set to <b>\0</b>. \n
65  */
66 #define WIFI_MAX_KEY_LEN 65 // 64 + \0
67 /**
68  * @brief Indicates the maximum length of a Wi-Fi MAC address or a Wi-Fi BSSID.
69  *
70  */
71 #define WIFI_MAC_LEN 6
72 
73 /**
74  * @brief Indicates the maximum length of a Wi-Fi PSK.
75  *
76  */
77 #define WIFI_PSK_LEN 32
78 
79 /**
80  * @brief Indicates the maximum number of DNS servers.
81  *
82  * A maximum of two DNS servers are allowed. \n
83  */
84 #define WIFI_MAX_DNS_NUM 2
85 
86 /**
87  * @brief Indicates the maximum length of a device name.
88  *
89  */
90 #define DEVICE_NAME_LEN 128
91 
92 /**
93  * @brief Indicates the maximum length of a ipv4 address.
94  *
95  */
96 #define WIFI_MAX_IPV4_LEN 16
97 
98 /**
99  * @brief Indicates the maximum length of IPV ADDRESS.
100  *
101  */
102 #define DEVICE_IPV6_MAX_LEN 128
103 
104 /**
105  * @brief Enumerates Wi-Fi security types.
106  *
107  * @since 7
108  */
109 typedef enum {
110     /** Invalid security type */
111     WIFI_SEC_TYPE_INVALID = -1,
112     /** Open */
113     WIFI_SEC_TYPE_OPEN = 0,
114     /** Wired Equivalent Privacy (WEP) */
115     WIFI_SEC_TYPE_WEP = 1,
116     /** Pre-shared key (PSK) */
117     WIFI_SEC_TYPE_PSK = 2,
118     /** Ethernet Automatic Protection (EAP) */
119     WIFI_SEC_TYPE_EAP = 3,
120     /** Simultaneous Authentication of Equals (SAE) */
121     WIFI_SEC_TYPE_SAE = 4,
122     /** EAP suite B */
123     WIFI_SEC_TYPE_EAP_SUITE_B = 5,
124     /** Opportunistic Wireless Encryption (OWE) */
125     WIFI_SEC_TYPE_OWE = 6,
126     /** WAPI cert */
127     WIFI_SEC_TYPE_WAPI_CERT = 7,
128     /** WAPI PSK */
129     WIFI_SEC_TYPE_WAPI_PSK = 8,
130 } WifiSecurityType;
131 
132 /**
133  * @brief Enumerates psk encryption types.
134  *
135  * @since 7
136  */
137 typedef enum {
138     /** Indicates that the ascii type of psk encryption type */
139     WIFI_PSK_TYPE_ASCII = 0,
140     /** Indicates that the hex type of psk encryption type */
141     WIFI_PSK_TYPE_HEX,
142 } WifiPskType;
143 
144 /**
145  * @brief Defines the IP configuration of the Wi-Fi device.
146  *
147  * The IP configuration is mainly used for connecting to the device. \n
148  *
149  * @since 3
150  */
151 typedef struct {
152     /** IP address of the Wi-Fi device */
153     unsigned int ipAddress;
154     /** Gateway of the Wi-Fi device */
155     unsigned int gateway;
156     /** DNS server addresses for the Wi-Fi device */
157     unsigned int dnsServers[WIFI_MAX_DNS_NUM];
158     /** Subnet mask of the Wi-Fi device */
159     unsigned int netmask;
160 } IpConfig;
161 
162 /**
163  * @brief Enumerates IP address types for the Wi-Fi device.
164  *
165  * @since 3
166  */
167 typedef enum {
168     /** Static IP address */
169     STATIC_IP,
170     /** IP address dynamically assigned by DHCP */
171     DHCP,
172     /** Unknown IP address type */
173     UNKNOWN
174 } IpType;
175 
176 /**
177  * @brief Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
178  *
179  * @since 7
180  */
181 typedef struct WifiDeviceConfig {
182     /** Service set ID (SSID). For its length, see {@link WIFI_MAX_SSID_LEN}. */
183     char ssid[WIFI_MAX_SSID_LEN];
184     /** Basic service set ID (BSSID). For its length, see {@link WIFI_MAC_LEN}. */
185     unsigned char bssid[WIFI_MAC_LEN];
186     /* bssid type. */
187     int bssidType;
188     /** Key. For its length, see {@link WIFI_MAX_KEY_LEN}. */
189     char preSharedKey[WIFI_MAX_KEY_LEN];
190     /** Security type. It is defined in {@link WifiSecurityType}. */
191     int securityType;
192     /** Allocated <b>networkId</b> */
193     int netId;
194     /** Frequency */
195     unsigned int freq;
196     /** PSK type, see {@link WifiPskType}. */
197     int wapiPskType;
198     /** IP address type */
199     IpType ipType;
200     /** Static IP address */
201     IpConfig staticIp;
202     /* 1 for hidden config */
203     int isHiddenSsid;
204     /* randomMacType */
205     int randomMacType;
206 } WifiDeviceConfig;
207 
208 /**
209  * @brief Enumerates Wi-Fi scan types.
210  *
211  * @since 7
212  */
213 typedef enum {
214     /** A scan based on a specified frequency. */
215     WIFI_FREQ_SCAN,
216     /** A scan based on a specified SSID. */
217     WIFI_SSID_SCAN,
218     /** A scan based on a specified BSSID. */
219     WIFI_BSSID_SCAN,
220     /** A scan based on a specified frequency band. */
221     WIFI_BAND_SCAN
222 } WifiScanType;
223 
224 /**
225  * @brief Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
226  *
227  * @since 7
228  */
229 typedef struct {
230     /** Service set ID (SSID). Its maximum length is defined by {@link WIFI_MAX_SSID_LEN}. */
231     char ssid[WIFI_MAX_SSID_LEN];
232     /** Length of the SSID. */
233     char ssidLen;
234     /** Basic service set ID (BSSID). Its length is defined by {@link WIFI_MAC_LEN}. */
235     unsigned char bssid[WIFI_MAC_LEN];
236     /** Frequency. */
237     int freqs;
238     /** Frequency band. */
239     int band;
240     /** Wi-Fi scan type, which is defined by {@link WifiScanType}. */
241     WifiScanType scanType;
242 } WifiScanParams;
243 
244 /**
245  * @brief IP info
246  *
247  * @since 7
248  */
249 typedef struct {
250     unsigned int ipAddress;
251     unsigned int netMask;
252     unsigned int netGate;
253     unsigned int dns1;
254     unsigned int dns2;
255     unsigned int serverAddress;
256     int leaseDuration;
257 } IpInfo;
258 
259 /* DHCP IpV6Info */
260 typedef struct {
261     char linkIpV6Address[DEVICE_IPV6_MAX_LEN];
262     char globalIpV6Address[DEVICE_IPV6_MAX_LEN];
263     char randGlobalIpV6Address[DEVICE_IPV6_MAX_LEN];
264     char gateway[DEVICE_IPV6_MAX_LEN];
265     char netmask[DEVICE_IPV6_MAX_LEN];
266     char primaryDns[DEVICE_IPV6_MAX_LEN];
267     char secondDns[DEVICE_IPV6_MAX_LEN];
268 } IpV6Info;
269 
270 #endif // WIFI_LITE_WIFI_DEVICE_CONFIG_H
271 /** @} */
272