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 HARMONY_OS_LITE_WIFI_DEVICE_CONFIG_H
39 #define HARMONY_OS_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 Enumerates Wi-Fi security types.
94  *
95  * @since 7
96  */
97 typedef enum {
98     /** Invalid security type */
99     WIFI_SEC_TYPE_INVALID = -1,
100     /** Open */
101     WIFI_SEC_TYPE_OPEN,
102     /** Wired Equivalent Privacy (WEP) */
103     WIFI_SEC_TYPE_WEP,
104     /** Pre-shared key (PSK) */
105     WIFI_SEC_TYPE_PSK,
106     /** Simultaneous Authentication of Equals (SAE) */
107     WIFI_SEC_TYPE_SAE,
108 } WifiSecurityType;
109 
110 /**
111  * @brief Enumerates psk encryption types.
112  *
113  * @since 7
114  */
115 typedef enum {
116     /** Indicates that the ascii type of psk encryption type */
117     WIFI_PSK_TYPE_ASCII = 0,
118     /** Indicates that the hex type of psk encryption type */
119     WIFI_PSK_TYPE_HEX,
120 } WifiPskType;
121 
122 /**
123  * @brief Defines the IP configuration of the Wi-Fi device.
124  *
125  * The IP configuration is mainly used for connecting to the device. \n
126  *
127  * @since 3
128  */
129 typedef struct {
130     /** IP address of the Wi-Fi device */
131     unsigned int ipAddress;
132     /** Gateway of the Wi-Fi device */
133     unsigned int gateway;
134     /** DNS server addresses for the Wi-Fi device */
135     unsigned int dnsServers[WIFI_MAX_DNS_NUM];
136     /** Subnet mask of the Wi-Fi device */
137     unsigned int netmask;
138 } IpConfig;
139 
140 /**
141  * @brief Enumerates IP address types for the Wi-Fi device.
142  *
143  * @since 3
144  */
145 typedef enum {
146     /** Static IP address */
147     STATIC_IP,
148     /** IP address dynamically assigned by DHCP */
149     DHCP,
150     /** Unknown IP address type */
151     UNKNOWN
152 } IpType;
153 
154 /**
155  * @brief Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
156  *
157  * @since 7
158  */
159 typedef struct WifiDeviceConfig {
160     /** Service set ID (SSID). For its length, see {@link WIFI_MAX_SSID_LEN}. */
161     char ssid[WIFI_MAX_SSID_LEN];
162     /** Basic service set ID (BSSID). For its length, see {@link WIFI_MAC_LEN}. */
163     unsigned char bssid[WIFI_MAC_LEN];
164     /** Key. For its length, see {@link WIFI_MAX_KEY_LEN}. */
165     char preSharedKey[WIFI_MAX_KEY_LEN];
166     /** Security type. It is defined in {@link WifiSecurityType}. */
167     int securityType;
168     /** Allocated <b>networkId</b> */
169     int netId;
170     /** Frequency */
171     unsigned int freq;
172     /** PSK type, see {@link WifiPskType}. */
173     int wapiPskType;
174     /** IP address type */
175     IpType ipType;
176     /** Static IP address */
177     IpConfig staticIp;
178     /* 1 for hidden config */
179     int isHiddenSsid;
180 } WifiDeviceConfig;
181 
182 /**
183  * @brief Enumerates Wi-Fi scan types.
184  *
185  * @since 7
186  */
187 typedef enum {
188     /** A scan based on a specified frequency. */
189     WIFI_FREQ_SCAN,
190     /** A scan based on a specified SSID. */
191     WIFI_SSID_SCAN,
192     /** A scan based on a specified BSSID. */
193     WIFI_BSSID_SCAN,
194     /** A scan based on a specified frequency band. */
195     WIFI_BAND_SCAN
196 } WifiScanType;
197 
198 /**
199  * @brief Represents the Wi-Fi station configuration used to connect to a specified Wi-Fi device.
200  *
201  * @since 7
202  */
203 typedef struct {
204     /** Service set ID (SSID). Its maximum length is defined by {@link WIFI_MAX_SSID_LEN}. */
205     char ssid[WIFI_MAX_SSID_LEN];
206     /** Length of the SSID. */
207     char ssidLen;
208     /** Basic service set ID (BSSID). Its length is defined by {@link WIFI_MAC_LEN}. */
209     char bssid[WIFI_MAC_LEN];
210     /** Frequency. */
211     int freqs;
212     /** Frequency band. */
213     int band;
214     /** Wi-Fi scan type, which is defined by {@link WifiScanType}. */
215     WifiScanType scanType;
216 } WifiScanParams;
217 
218 /**
219  * @brief IP info
220  *
221  * @since 7
222  */
223 typedef struct {
224     unsigned int ipAddress;
225     unsigned int netMask;
226     unsigned int netGate;
227     unsigned int dns1;
228     unsigned int dns2;
229     unsigned int serverAddress;
230     int leaseDuration;
231 } IpInfo;
232 #endif // HARMONY_OS_LITE_WIFI_DEVICE_CONFIG_H
233 /** @} */
234