1 /**
2  * @file netmgr_wifi.h
3  * netmgr Wi-Fi API header file.
4  *
5  * @version   V2.0
6  * @date      2020-11-22
7  * @copyright Copyright (C) 2015-2019 Alibaba Group Holding Limited
8  */
9 
10 #ifndef NETMGR_WIFI_H
11 #define NETMGR_WIFI_H
12 
13 #include <stdint.h>
14 #include <stdbool.h>
15 #include <netmgr.h>
16 
17 #if defined(__cplusplus)
18 extern "C"
19 {
20 #endif
21 
22 typedef enum {
23     RET_WIFI_OK                  = 0,
24     RET_WIFI_COMMON_FAIL         = -1,
25     RET_WIFI_INVALID_ARG         = -2,  //invalid argument
26     RET_WIFI_INVALID_PASSWORD    = -3,  //invalid password
27     RET_WIFI_MEMORY_ERROR        = -4,  //no memory to allocate resource
28     RET_WIFI_INIT_FAIL           = -5,  //init wifi fail
29     RET_WIFI_NOT_INITED          = -6,  //wifi is not initialized
30     RET_WIFI_STATUS_ERROR        = -7,  //request in error STATUS
31     RET_WIFI_SCAN_REQ_FAIL       = -8,  //scan fail to start
32     RET_WIFI_SCAN_NO_AP_FOUND    = -9,  //scan result is NULL (didn't find any SSID)
33     RET_WIFI_NO_SUITABLE_NETWORK = -10,  //no suitable network to connect
34     RET_WIFI_CONN_REQ_FAIL       = -11, //connect fail to start
35     RET_WIFI_CONN_FAIL           = -12, //connect procedure result in fail
36     RET_WIFI_CONN_NO_SSID_CONFIG = -13, //no saved SSID config to connect
37     RET_WIFI_DISC_FAIL           = -14, //disconnect procedure result in fail
38     RET_WIFI_WPS_NOT_FOUND       = -15, //couldn't find WPS AP
39     RET_WIFI_WPS_REQ_FAIL        = -16, //WPS fail to start
40 }wifi_result_t;
41 
42 typedef struct {
43     uint8_t dhcp;     /* DHCP mode: @ref DHCP_Disable, @ref DHCP_Client, @ref DHCP_Server. */
44     char    ip[16];   /* Local IP address on the target wlan interface: @ref wlanInterfaceTypedef. */
45     char    gate[16]; /* Router IP address on the target wlan interface: @ref wlanInterfaceTypedef. */
46     char    mask[16]; /* Netmask on the target wlan interface: @ref wlanInterfaceTypedef. */
47     char    dns[16];  /* DNS server IP address. */
48     char    mac[16];  /* MAC address, example: "C89346112233". */
49     char    broadcastip[16];
50 } netmgr_wifi_ip_stat_t;
51 
52 typedef enum netmgr_wifi_ip_mode_e {
53     NETMGR_WIFI_IP_MODE_AUTO,             /* Use dhcp to get ip address */
54     NETMGR_WIFI_IP_MODE_STATIC,           /* Use static ip address */
55 } netmgr_wifi_ip_mode_t;
56 
57 typedef enum netmgr_wifi_ssid_format_e {
58     NETMGR_WIFI_SSID_FORMAT_UTF8,
59     NETMGR_WIFI_SSID_FORMAT_GBK,
60 } netmgra_wifi_ssid_format_t;
61 
62 typedef enum netmgr_wifi_scan_type_e {
63     NETMGR_WIFI_SCAN_TYPE_FULL,
64     NETMGR_WIFI_SCAN_TYPE_SPECIFIED,
65     NETMGR_WIFI_SCAN_TYPE_FULL_MERGE
66 } netmgr_wifi_scan_type_t;
67 
68 
69 #define MAX_SSID_SIZE  32
70 #define MAX_PWD_SIZE   64
71 
72 #ifndef MAX_SSID_LEN
73 #define MAX_SSID_LEN (MAX_SSID_SIZE+1)
74 #endif
75 #ifndef ETH_ALEN
76 #define ETH_ALEN                        (6)
77 #endif
78 
79 /**
80  * @brief net manager init
81  * @return 0 on success, others on error
82  */
83 int netmgr_wifi_init(netmgr_hdl_t hdl);
84 
85 /**
86  * @brief net manager deinit
87  */
88 void netmgr_wifi_deinit(netmgr_hdl_t hdl);
89 
90 /**
91  * @brief get wifi netmgr handler
92  * @param  [in] hdl
93  * @return NULL on error
94  */
95 netmgr_hdl_t netmgr_wifi_get_dev(const char* name);
96 
97 /**
98  * @brief  set if config information
99  * @param  [in] hdl
100  * @param  [in] if config information
101  * @return 0 on success, others on error
102  */
103 int netmgr_wifi_set_ifconfig(netmgr_hdl_t hdl, netmgr_ifconfig_info_t* info);
104 
105 /**
106  * @brief  get if config information
107  * @param  [in] hdl
108  * @param  [out] if config information
109  * @return 0 on success, others on error
110  */
111 int netmgr_wifi_get_ifconfig(netmgr_hdl_t hdl, netmgr_ifconfig_info_t* info);
112 
113 /**
114  * @brief  set auto reconnect flag
115  * @param  [in] hdl
116  * @param  [in] enable
117  */
118 void netmgr_wifi_set_auto_reconnect(netmgr_hdl_t hdl, bool enable);
119 
120 /**
121  * @brief  get config information
122  * @param  [in] hdl
123  * @param  [out] config information
124  * @return 0 on success, others on error
125  */
126 int netmgr_wifi_get_config(netmgr_hdl_t hdl, netmgr_wifi_config_t* config);
127 
128 /**
129  * @brief  delete config information
130  * @param  [in] hdl
131  * @param  [in] ssid which config is to delete
132  * @return 0 on success, others on error
133  */
134 int netmgr_wifi_del_config(netmgr_hdl_t, const char* ssid);
135 
136 /**
137  * @brief  get state of hdl
138  * @param  [in] hdl
139  * @return >=0 on success, others on error
140  */
141 int netmgr_wifi_get_state(netmgr_hdl_t hdl);
142 
143 /**
144  * @brief  netmgr connect network
145  * @param  [in] hdl
146  * @param  [in] params
147  * @return 0 on success, others on error
148  */
149 int netmgr_wifi_connect(netmgr_hdl_t hdl, netmgr_wifi_params_t* params);
150 
151 /**
152  * @brief  netmgr disconnect network
153  * @param  [in] hdl
154  * @return 0 on success, others on error
155  */
156 int netmgr_wifi_disconnect(netmgr_hdl_t hdl);
157 
158 /**
159  * @brief  netmgr save config
160  * @param  [in] hdl
161  * @return 0 on success, others on error
162  */
163 int netmgr_wifi_save_config(netmgr_hdl_t hdl);
164 
165 /**
166  * @brief  netmgr set connect params
167  * @param  [in] hdl
168  * @param  [in] ap_info
169  * @param  [in] num
170  * @param  [in] type
171  * @return 0 on success, others on error
172  */
173 int netmgr_wifi_set_connect_params(netmgr_hdl_t hdl, netmgr_connect_params_t* params);
174 
175 int netmgr_wifi_set_msg_cb(netmgr_hdl_t hdl, netmgr_msg_cb_t cb);
176 
177 int netmgr_wifi_del_msg_cb(netmgr_hdl_t hdl, netmgr_msg_cb_t cb);
178 
179 /**
180  * @brief  netmgr set auto save ap config
181  * @param  [in] auto_save_ap
182  * @return 0 on success, others on error
183  */
184 int netmgr_wifi_set_auto_save_ap(bool auto_save_ap);
185 
186 /**
187  * @brief  set if config information
188  * @param  [in] hdl
189  * @param  [in] channel_array channel array for wifi specific scan
190  * @param  [in] channel_num channel num for wifi specific scan
191  * @return 0 on success, others on error
192  */
193 int netmgr_wifi_set_channelist(netmgr_hdl_t hdl, int *channel_array, int channel_num);
194 
195 /**
196  * @brief  set if config information
197  * @param  [in] hdl
198  * @param  [out] channel_array channel array for wifi specific scan
199  * @param  [out] channel_num channel num for wifi specific scan
200  * @return 0 on success, others on error
201  */
202 int netmgr_wifi_get_channelist(netmgr_hdl_t hdl, int **channel_array, int *channel_num);
203 
204 /** @} */
205 
206 #if defined(__cplusplus)
207 }
208 #endif
209 
210 #endif /* NETMGR_WIFI_H */
211