ESP32_RTOS_SDK V1.1.0

- Main Page
- Modules
- Data Structures
- Files

- File List

esp_wifi.h
1 /*
2 * ESPRSSIF MIT License
3 *
4 * Copyright (c) 2015 <ESPRESSIF SYSTEMS (SHANGHAI) PTE LTD>
5 *
6 * Permission is hereby granted for use on ESPRESSIF SYSTEMS ESP32 only, in which case,
7 * it is free of charge, to any person obtaining a copy of this software and associated
8 * documentation files (the "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the Software is furnished
11 * to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or
14 * substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
18 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24
25 #ifndef __ESP_WIFI_H__
26 #define __ESP_WIFI_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
51 typedef enum {
52 NULL_MODE = 0,
53 STATION_MODE,
54 SOFTAP_MODE,
55 STATIONAP_MODE,
56 MAX_MODE
57 } WIFI_MODE;
58
59 typedef enum {
60 AUTH_OPEN = 0,
61 AUTH_WEP,
62 AUTH_WPA_PSK,
63 AUTH_WPA2_PSK,
64 AUTH_WPA_WPA2_PSK,
65 AUTH_MAX
66 } AUTH_MODE;
67
78 WIFI_MODE wifi_get_opmode(void);
79
90 WIFI_MODE wifi_get_opmode_default(void);
91
108 bool wifi_set_opmode(WIFI_MODE opmode);
109
124 bool wifi_set_opmode_current(WIFI_MODE opmode);
125
126 typedef enum {
127 STATION_IF = 0,
128 SOFTAP_IF,
129 MAX_IF
130 } WIFI_INTERFACE;
131
132 struct ip_info {
133 struct ip_addr ip;
134 struct ip_addr netmask;
135 struct ip_addr gw;
136 };
137
150 bool wifi_get_ip_info(WIFI_INTERFACE if_index, struct ip_info *info);
151
169 bool wifi_set_ip_info(WIFI_INTERFACE if_index, struct ip_info *info);
170
181 bool wifi_get_macaddr(WIFI_INTERFACE if_index, uint8 *macaddr);
182
199 bool wifi_set_macaddr(WIFI_INTERFACE if_index, uint8 *macaddr);
200
201 typedef enum {
202 EVENT_STAMODE_SCAN_DONE = 0,
203 EVENT_STAMODE_CONNECTED,
204 EVENT_STAMODE_DISCONNECTED,
205 EVENT_STAMODE_AUTHMODE_CHANGE,
206 EVENT_STAMODE_GOT_IP,
207 EVENT_STAMODE_DHCP_TIMEOUT,
208 EVENT_SOFTAPMODE_STACONNECTED,
209 EVENT_SOFTAPMODE_STADISCONNECTED,
210 EVENT_SOFTAPMODE_PROBEREQRECVED,
211 EVENT_MAX
212 } SYSTEM_EVENT;
213
214 enum {
215 REASON_UNSPECIFIED = 1,
216 REASON_AUTH_EXPIRE = 2,
217 REASON_AUTH_LEAVE = 3,
218 REASON_ASSOC_EXPIRE = 4,
219 REASON_ASSOC_TOOMANY = 5,
220 REASON_NOT_AUTHED = 6,
221 REASON_NOT_ASSOCED = 7,
222 REASON_ASSOC_LEAVE = 8,
223 REASON_ASSOC_NOT_AUTHED = 9,
224 REASON_DISASSOC_PWRCAP_BAD = 10,
225 REASON_DISASSOC_SUPCHAN_BAD = 11,
226 REASON_IE_INVALID = 13,
227 REASON_MIC_FAILURE = 14,
228 REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
229 REASON_GROUP_KEY_UPDATE_TIMEOUT = 16,
230 REASON_IE_IN_4WAY_DIFFERS = 17,
231 REASON_GROUP_CIPHER_INVALID = 18,
232 REASON_PAIRWISE_CIPHER_INVALID = 19,
233 REASON_AKMP_INVALID = 20,
234 REASON_UNSUPP_RSN_IE_VERSION = 21,
235 REASON_INVALID_RSN_IE_CAP = 22,
236 REASON_802_1X_AUTH_FAILED = 23,
237 REASON_CIPHER_SUITE_REJECTED = 24,
238
239 REASON_BEACON_TIMEOUT = 200,
240 REASON_NO_AP_FOUND = 201,
241 REASON_AUTH_FAIL = 202,
242 REASON_ASSOC_FAIL = 203,
243 REASON_HANDSHAKE_TIMEOUT = 204,
244 };
245
246 typedef struct {
247 uint32 status;
248 struct bss_info *bss;
249 } Event_StaMode_ScanDone_t;
250
251 typedef struct {
252 uint8 ssid[32];
253 uint8 ssid_len;
254 uint8 bssid[6];
255 uint8 channel;
256 } Event_StaMode_Connected_t;
257
258 typedef struct {
259 uint8 ssid[32];
260 uint8 ssid_len;
261 uint8 bssid[6];
262 uint8 reason;
263 } Event_StaMode_Disconnected_t;
264
265 typedef struct {
266 uint8 old_mode;
267 uint8 new_mode;
268 } Event_StaMode_AuthMode_Change_t;
269
270 typedef struct {
271 struct ip_addr ip;
272 struct ip_addr mask;
273 struct ip_addr gw;
274 } Event_StaMode_Got_IP_t;
275
276 typedef struct {
277 uint8 mac[6];
278 uint8 aid;
279 } Event_SoftAPMode_StaConnected_t;
280
281 typedef struct {
282 uint8 mac[6];
283 uint8 aid;
284 } Event_SoftAPMode_StaDisconnected_t;
285
286 typedef struct {
287 int rssi;
288 uint8 mac[6];
289 } Event_SoftAPMode_ProbeReqRecved_t;
290
291 typedef union {
292 Event_StaMode_ScanDone_t scan_done;
293 Event_StaMode_Connected_t connected;
294 Event_StaMode_Disconnected_t disconnected;
295 Event_StaMode_AuthMode_Change_t auth_change;
296 Event_StaMode_Got_IP_t got_ip;
297 Event_SoftAPMode_StaConnected_t sta_connected;
298 Event_SoftAPMode_StaDisconnected_t sta_disconnected;
299 Event_SoftAPMode_ProbeReqRecved_t ap_probereqrecved;
300 } Event_Info_u;
301
302 typedef struct _esp_event {
303 SYSTEM_EVENT event_id;
304 Event_Info_u event_info;
305 } System_Event_t;
306
317 typedef void (* wifi_event_handler_cb_t)(System_Event_t *event);
318
327 bool wifi_set_event_handler_cb(wifi_event_handler_cb_t cb);
328
352 typedef void (* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len);
353
363 void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb);
364
372 uint8 wifi_get_channel(void);
373
382 bool wifi_set_channel(uint8 channel);
383
399 void wifi_promiscuous_enable(uint8 promiscuous);
400
409 #ifdef __cplusplus
410 }
411 #endif
412
413 #endif
wifi_get_ip_info
bool wifi_get_ip_info(WIFI_INTERFACE if_index, struct ip_info *info)
Get the IP address of the ESP32 WiFi station or the soft-AP interface.
Event_StaMode_Connected_t::ssid_len
uint8 ssid_len
Definition: esp_wifi.h:253
ip_info
Definition: esp_wifi.h:132
wifi_promiscuous_enable
void wifi_promiscuous_enable(uint8 promiscuous)
Enable the promiscuous mode.
wifi_get_opmode_default
WIFI_MODE wifi_get_opmode_default(void)
Get the operating mode of the WiFi saved in the Flash.
Event_SoftAPMode_StaDisconnected_t::aid
uint8 aid
Definition: esp_wifi.h:283
EVENT_STAMODE_SCAN_DONE
Definition: esp_wifi.h:202
Event_Info_u::sta_connected
Event_SoftAPMode_StaConnected_t sta_connected
Definition: esp_wifi.h:297
_esp_event
Definition: esp_wifi.h:302
EVENT_STAMODE_DHCP_TIMEOUT
Definition: esp_wifi.h:207
ip_info::ip
struct ip_addr ip
Definition: esp_wifi.h:133
wifi_get_macaddr
bool wifi_get_macaddr(WIFI_INTERFACE if_index, uint8 *macaddr)
Get MAC address of the ESP32 WiFi station or the soft-AP interface.
ip_info::gw
struct ip_addr gw
Definition: esp_wifi.h:135
Event_StaMode_AuthMode_Change_t
Definition: esp_wifi.h:265
WIFI_MODE
WIFI_MODE
Definition: esp_wifi.h:51
WIFI_INTERFACE
WIFI_INTERFACE
Definition: esp_wifi.h:126
Event_Info_u::connected
Event_StaMode_Connected_t connected
Definition: esp_wifi.h:293
wifi_set_promiscuous_rx_cb
void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb)
Register the RX callback function in the promiscuous mode.
Event_Info_u::ap_probereqrecved
Event_SoftAPMode_ProbeReqRecved_t ap_probereqrecved
Definition: esp_wifi.h:299
Event_Info_u::scan_done
Event_StaMode_ScanDone_t scan_done
Definition: esp_wifi.h:292
wifi_set_event_handler_cb
bool wifi_set_event_handler_cb(wifi_event_handler_cb_t cb)
Register the Wi-Fi event handler.
NULL_MODE
Definition: esp_wifi.h:52
AUTH_WPA_WPA2_PSK
Definition: esp_wifi.h:64
Event_SoftAPMode_ProbeReqRecved_t
Definition: esp_wifi.h:286
Event_SoftAPMode_ProbeReqRecved_t::rssi
int rssi
Definition: esp_wifi.h:287
Event_StaMode_Disconnected_t
Definition: esp_wifi.h:258
Event_StaMode_Disconnected_t::ssid_len
uint8 ssid_len
Definition: esp_wifi.h:260
STATION_IF
Definition: esp_wifi.h:127
AUTH_WPA2_PSK
Definition: esp_wifi.h:63
AUTH_WPA_PSK
Definition: esp_wifi.h:62
Event_Info_u::sta_disconnected
Event_SoftAPMode_StaDisconnected_t sta_disconnected
Definition: esp_wifi.h:298
Event_SoftAPMode_StaDisconnected_t
Definition: esp_wifi.h:281
_esp_event::event_info
Event_Info_u event_info
Definition: esp_wifi.h:304
SOFTAP_IF
Definition: esp_wifi.h:128
Event_StaMode_Connected_t
Definition: esp_wifi.h:251
wifi_set_opmode_current
bool wifi_set_opmode_current(WIFI_MODE opmode)
Set the WiFi operating mode, and will not save it to Flash.
EVENT_STAMODE_GOT_IP
Definition: esp_wifi.h:206
Event_StaMode_AuthMode_Change_t::old_mode
uint8 old_mode
Definition: esp_wifi.h:266
Event_StaMode_Got_IP_t
Definition: esp_wifi.h:270
Event_StaMode_ScanDone_t::status
uint32 status
Definition: esp_wifi.h:247
EVENT_STAMODE_CONNECTED
Definition: esp_wifi.h:203
SYSTEM_EVENT
SYSTEM_EVENT
Definition: esp_wifi.h:201
Event_Info_u::got_ip
Event_StaMode_Got_IP_t got_ip
Definition: esp_wifi.h:296
Event_SoftAPMode_StaConnected_t
Definition: esp_wifi.h:276
wifi_set_opmode
bool wifi_set_opmode(WIFI_MODE opmode)
Set the WiFi operating mode, and save it to Flash.
bss_info::bssid
uint8 bssid[6]
Definition: esp_sta.h:155
Event_Info_u
Definition: esp_wifi.h:291
wifi_promiscuous_cb_t
void(* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len)
The RX callback function in the promiscuous mode.
Definition: esp_wifi.h:352
Event_Info_u::disconnected
Event_StaMode_Disconnected_t disconnected
Definition: esp_wifi.h:294
STATION_MODE
Definition: esp_wifi.h:53
wifi_event_handler_cb_t
void(* wifi_event_handler_cb_t)(System_Event_t *event)
The Wi-Fi event handler.
Definition: esp_wifi.h:317
AUTH_WEP
Definition: esp_wifi.h:61
SOFTAP_MODE
Definition: esp_wifi.h:54
Event_StaMode_AuthMode_Change_t::new_mode
uint8 new_mode
Definition: esp_wifi.h:267
Event_StaMode_Disconnected_t::reason
uint8 reason
Definition: esp_wifi.h:262
Event_StaMode_ScanDone_t
Definition: esp_wifi.h:246
Event_SoftAPMode_StaConnected_t::aid
uint8 aid
Definition: esp_wifi.h:278
EVENT_STAMODE_DISCONNECTED
Definition: esp_wifi.h:204
wifi_set_ip_info
bool wifi_set_ip_info(WIFI_INTERFACE if_index, struct ip_info *info)
Set the IP address of the ESP32 WiFi station or the soft-AP interface.
wifi_set_channel
bool wifi_set_channel(uint8 channel)
Set the channel number for sniffer functions.
EVENT_SOFTAPMODE_STACONNECTED
Definition: esp_wifi.h:208
EVENT_SOFTAPMODE_PROBEREQRECVED
Definition: esp_wifi.h:210
wifi_set_macaddr
bool wifi_set_macaddr(WIFI_INTERFACE if_index, uint8 *macaddr)
Set MAC address of the ESP32 WiFi station or the soft-AP interface.
STATIONAP_MODE
Definition: esp_wifi.h:55
Event_StaMode_Connected_t::channel
uint8 channel
Definition: esp_wifi.h:255
EVENT_STAMODE_AUTHMODE_CHANGE
Definition: esp_wifi.h:205
wifi_get_opmode
WIFI_MODE wifi_get_opmode(void)
Get the current operating mode of the WiFi.
bss_info::ssid
uint8 ssid[32]
Definition: esp_sta.h:156
Event_Info_u::auth_change
Event_StaMode_AuthMode_Change_t auth_change
Definition: esp_wifi.h:295
AUTH_OPEN
Definition: esp_wifi.h:60
Event_StaMode_ScanDone_t::bss
struct bss_info * bss
Definition: esp_wifi.h:248
_esp_event::event_id
SYSTEM_EVENT event_id
Definition: esp_wifi.h:303
wifi_get_channel
uint8 wifi_get_channel(void)
Get the channel number for sniffer functions.
bss_info
Definition: esp_sta.h:152
EVENT_SOFTAPMODE_STADISCONNECTED
Definition: esp_wifi.h:209
AUTH_MODE
AUTH_MODE
Definition: esp_wifi.h:59
ip_info::netmask
struct ip_addr netmask
Definition: esp_wifi.h:134