ESP8266_RTOS_SDK  v1.4.0
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 ESP8266 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,
56  MAX_MODE
57 } WIFI_MODE;
58 
59 typedef enum {
60  AUTH_OPEN = 0,
65  AUTH_MAX
66 } AUTH_MODE;
67 
79 
91 
108 bool wifi_set_opmode(WIFI_MODE opmode);
109 
125 
126 typedef enum {
129  MAX_IF
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 
210 void wifi_status_led_install(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func);
211 
219 void wifi_status_led_uninstall(void);
220 
221 typedef enum {
225 } WIFI_PHY_MODE;
226 
235 
247 
248 typedef enum {
258  EVENT_MAX
259 } SYSTEM_EVENT;
260 
261 enum {
262  REASON_UNSPECIFIED = 1,
263  REASON_AUTH_EXPIRE = 2,
264  REASON_AUTH_LEAVE = 3,
265  REASON_ASSOC_EXPIRE = 4,
266  REASON_ASSOC_TOOMANY = 5,
267  REASON_NOT_AUTHED = 6,
268  REASON_NOT_ASSOCED = 7,
269  REASON_ASSOC_LEAVE = 8,
270  REASON_ASSOC_NOT_AUTHED = 9,
271  REASON_DISASSOC_PWRCAP_BAD = 10,
272  REASON_DISASSOC_SUPCHAN_BAD = 11,
273  REASON_IE_INVALID = 13,
274  REASON_MIC_FAILURE = 14,
275  REASON_4WAY_HANDSHAKE_TIMEOUT = 15,
276  REASON_GROUP_KEY_UPDATE_TIMEOUT = 16,
277  REASON_IE_IN_4WAY_DIFFERS = 17,
278  REASON_GROUP_CIPHER_INVALID = 18,
279  REASON_PAIRWISE_CIPHER_INVALID = 19,
280  REASON_AKMP_INVALID = 20,
281  REASON_UNSUPP_RSN_IE_VERSION = 21,
282  REASON_INVALID_RSN_IE_CAP = 22,
283  REASON_802_1X_AUTH_FAILED = 23,
284  REASON_CIPHER_SUITE_REJECTED = 24,
285 
286  REASON_BEACON_TIMEOUT = 200,
287  REASON_NO_AP_FOUND = 201,
288  REASON_AUTH_FAIL = 202,
289  REASON_ASSOC_FAIL = 203,
290  REASON_HANDSHAKE_TIMEOUT = 204,
291 };
292 
293 typedef struct {
294  uint32 status;
295  struct bss_info *bss;
297 
298 typedef struct {
299  uint8 ssid[32];
300  uint8 ssid_len;
301  uint8 bssid[6];
302  uint8 channel;
304 
305 typedef struct {
306  uint8 ssid[32];
307  uint8 ssid_len;
308  uint8 bssid[6];
309  uint8 reason;
311 
312 typedef struct {
313  uint8 old_mode;
314  uint8 new_mode;
316 
317 typedef struct {
318  struct ip_addr ip;
319  struct ip_addr mask;
320  struct ip_addr gw;
322 
323 typedef struct {
324  uint8 mac[6];
325  uint8 aid;
327 
328 typedef struct {
329  uint8 mac[6];
330  uint8 aid;
332 
333 typedef struct {
334  int rssi;
335  uint8 mac[6];
337 
338 typedef union {
347 } Event_Info_u;
348 
349 typedef struct _esp_event {
353 
364 typedef void (* wifi_event_handler_cb_t)(System_Event_t *event);
365 
375 
383 typedef void (*freedom_outside_cb_t)(uint8 status);
384 
397 
406 
429 sint32 wifi_send_pkt_freedom(uint8 *buf, uint16 len, bool sys_seq);
430 
439 sint32 wifi_rfid_locp_recv_open(void);
440 
448 void wifi_rfid_locp_recv_close(void);
449 
459 typedef void (*rfid_locp_cb_t)(uint8 *frm, int len, sint8 rssi);
460 
473 
482 
483 typedef enum {
484  NONE_SLEEP_T = 0,
485  LIGHT_SLEEP_T,
486  MODEM_SLEEP_T
487 } sleep_type;
488 
501 bool wifi_set_sleep_type(sleep_type type);
502 
510 sleep_type wifi_get_sleep_type(void);
511 
534 void wifi_fpm_open(void);
535 
543 void wifi_fpm_close(void);
544 
556 void wifi_fpm_do_wakeup(void);
557 
558 typedef void (*fpm_wakeup_cb)(void);
559 
575 void wifi_fpm_set_wakeup_cb(fpm_wakeup_cb cb);
576 
597 sint8 wifi_fpm_do_sleep(uint32 sleep_time_in_us);
598 
608 void wifi_fpm_set_sleep_type(sleep_type type);
609 
617 sleep_type wifi_fpm_get_sleep_type(void);
618 
631 enum FIXED_RATE {
632  PHY_RATE_48 = 0x8,
633  PHY_RATE_24 = 0x9,
634  PHY_RATE_12 = 0xA,
635  PHY_RATE_6 = 0xB,
636  PHY_RATE_54 = 0xC,
637  PHY_RATE_36 = 0xD,
638  PHY_RATE_18 = 0xE,
639  PHY_RATE_9 = 0xF
640 };
641 
642 #define FIXED_RATE_MASK_NONE 0x00
643 #define FIXED_RATE_MASK_STA 0x01
644 #define FIXED_RATE_MASK_AP 0x02
645 #define FIXED_RATE_MASK_ALL 0x03
646 
666 sint32 wifi_set_user_fixed_rate(uint8 enable_mask, uint8 rate);
667 
677 int wifi_get_user_fixed_rate(uint8 *enable_mask, uint8 *rate);
678 
679 enum support_rate {
680  RATE_11B5M = 0,
681  RATE_11B11M = 1,
682  RATE_11B1M = 2,
683  RATE_11B2M = 3,
684  RATE_11G6M = 4,
685  RATE_11G12M = 5,
686  RATE_11G24M = 6,
687  RATE_11G48M = 7,
688  RATE_11G54M = 8,
689  RATE_11G9M = 9,
690  RATE_11G18M = 10,
691  RATE_11G36M = 11
692 };
693 
711 sint32 wifi_set_user_sup_rate(uint8 min, uint8 max);
712 
713 enum RATE_11B_ID {
714  RATE_11B_B11M = 0,
715  RATE_11B_B5M = 1,
716  RATE_11B_B2M = 2,
717  RATE_11B_B1M = 3
718 };
719 
720 enum RATE_11G_ID {
721  RATE_11G_G54M = 0,
722  RATE_11G_G48M = 1,
723  RATE_11G_G36M = 2,
724  RATE_11G_G24M = 3,
725  RATE_11G_G18M = 4,
726  RATE_11G_G12M = 5,
727  RATE_11G_G9M = 6,
728  RATE_11G_G6M = 7,
729  RATE_11G_B5M = 8,
730  RATE_11G_B2M = 9,
731  RATE_11G_B1M = 10
732 };
733 
734 enum RATE_11N_ID {
735  RATE_11N_MCS7S = 0,
736  RATE_11N_MCS7 = 1,
737  RATE_11N_MCS6 = 2,
738  RATE_11N_MCS5 = 3,
739  RATE_11N_MCS4 = 4,
740  RATE_11N_MCS3 = 5,
741  RATE_11N_MCS2 = 6,
742  RATE_11N_MCS1 = 7,
743  RATE_11N_MCS0 = 8,
744  RATE_11N_B5M = 9,
745  RATE_11N_B2M = 10,
746  RATE_11N_B1M = 11
747 };
748 
749 #define RC_LIMIT_11B 0
750 #define RC_LIMIT_11G 1
751 #define RC_LIMIT_11N 2
752 #define RC_LIMIT_P2P_11G 3
753 #define RC_LIMIT_P2P_11N 4
754 #define RC_LIMIT_NUM 5
755 
756 #define LIMIT_RATE_MASK_NONE 0x00
757 #define LIMIT_RATE_MASK_STA 0x01
758 #define LIMIT_RATE_MASK_AP 0x02
759 #define LIMIT_RATE_MASK_ALL 0x03
760 
784 bool wifi_set_user_rate_limit(uint8 mode, uint8 ifidx, uint8 max, uint8 min);
785 
798 
812 bool wifi_set_user_limit_rate_mask(uint8 enable_mask);
813 
827 typedef enum {
828  USER_IE_BEACON = 0,
829  USER_IE_PROBE_REQ,
830  USER_IE_PROBE_RESP,
831  USER_IE_ASSOC_REQ,
832  USER_IE_ASSOC_RESP,
833  USER_IE_MAX
834 } user_ie_type;
835 
848 typedef void (*user_ie_manufacturer_recv_cb_t)(user_ie_type type, const uint8 sa[6], const uint8 m_oui[3], uint8 *ie, uint8 ie_len, sint32 rssi);
849 
871 bool wifi_set_user_ie(bool enable, uint8 *m_oui, user_ie_type type, uint8 *user_ie, uint8 len);
872 
882 
891 
914 typedef void (* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len);
915 
926 
934 uint8 wifi_get_channel(void);
935 
944 bool wifi_set_channel(uint8 channel);
945 
958 bool wifi_promiscuous_set_mac(const uint8_t *address);
959 
975 void wifi_promiscuous_enable(uint8 promiscuous);
976 
985 #ifdef __cplusplus
986 }
987 #endif
988 
989 #endif
void(* user_ie_manufacturer_recv_cb_t)(user_ie_type type, const uint8 sa[6], const uint8 m_oui[3], uint8 *ie, uint8 ie_len, sint32 rssi)
User IE received callback.
Definition: esp_wifi.h:848
void wifi_fpm_close(void)
Disable force sleep function.
bool wifi_set_opmode_current(WIFI_MODE opmode)
Set the WiFi operating mode, and will not save it to Flash.
Definition: esp_wifi.h:132
Definition: esp_wifi.h:64
int rssi
Definition: esp_wifi.h:334
WIFI_MODE
Definition: esp_wifi.h:51
Definition: esp_wifi.h:298
Definition: esp_wifi.h:293
bool wifi_set_phy_mode(WIFI_PHY_MODE mode)
Set the ESP8266 physical mode (802.11b/g/n).
void wifi_promiscuous_enable(uint8 promiscuous)
Enable the promiscuous mode.
Definition: esp_wifi.h:256
Definition: esp_wifi.h:349
void wifi_status_led_install(uint8 gpio_id, uint32 gpio_name, uint8 gpio_func)
Install the WiFi status LED.
Definition: esp_wifi.h:250
struct bss_info * bss
Definition: esp_wifi.h:295
Definition: esp_wifi.h:323
Definition: esp_wifi.h:257
uint8 reason
Definition: esp_wifi.h:309
sint32 wifi_set_user_sup_rate(uint8 min, uint8 max)
Set the support rate of ESP8266.
AUTH_MODE
Definition: esp_wifi.h:59
void wifi_rfid_locp_recv_close(void)
Disable RFID LOCP (Location Control Protocol) .
Definition: esp_wifi.h:128
Definition: esp_wifi.h:252
struct ip_addr ip
Definition: esp_wifi.h:133
bool wifi_set_user_rate_limit(uint8 mode, uint8 ifidx, uint8 max, uint8 min)
Limit the initial rate of sending data from ESP8266.
void(* rfid_locp_cb_t)(uint8 *frm, int len, sint8 rssi)
RFID LOCP (Location Control Protocol) receive callback .
Definition: esp_wifi.h:459
uint8 new_mode
Definition: esp_wifi.h:314
void wifi_status_led_uninstall(void)
Uninstall the WiFi status LED.
uint8 channel
Definition: esp_wifi.h:302
sint32 wifi_set_user_fixed_rate(uint8 enable_mask, uint8 rate)
Set the fixed rate and mask of sending data from ESP8266.
Definition: esp_wifi.h:255
uint32 status
Definition: esp_wifi.h:294
struct ip_addr gw
Definition: esp_wifi.h:135
Definition: esp_wifi.h:54
Definition: esp_wifi.h:253
WIFI_MODE wifi_get_opmode(void)
Get the current operating mode of the WiFi.
bool wifi_set_sleep_type(sleep_type type)
Sets sleep type.
sint32 wifi_register_rfid_locp_recv_cb(rfid_locp_cb_t cb)
Register a callback of receiving WDS packets.
Definition: esp_wifi.h:251
Definition: esp_wifi.h:305
sint32 wifi_register_send_pkt_freedom_cb(freedom_outside_cb_t cb)
Register a callback for sending user-define 802.11 packets.
bool wifi_set_ip_info(WIFI_INTERFACE if_index, struct ip_info *info)
Set the IP address of the ESP8266 WiFi station or the soft-AP interface.
sleep_type wifi_fpm_get_sleep_type(void)
Get sleep type of force sleep function.
void(* wifi_promiscuous_cb_t)(uint8 *buf, uint16 len)
The RX callback function in the promiscuous mode.
Definition: esp_wifi.h:914
Definition: esp_wifi.h:53
void wifi_unregister_send_pkt_freedom_cb(void)
Unregister the callback for sending user-define 802.11 packets.
Definition: esp_wifi.h:60
bool wifi_set_channel(uint8 channel)
Set the channel number for sniffer functions.
bool wifi_set_event_handler_cb(wifi_event_handler_cb_t cb)
Register the Wi-Fi event handler.
bool wifi_promiscuous_set_mac(const uint8_t *address)
Set the MAC address filter for the sniffer mode.
Event_StaMode_Disconnected_t disconnected
Definition: esp_wifi.h:341
bool wifi_set_opmode(WIFI_MODE opmode)
Set the WiFi operating mode, and save it to Flash.
Event_Info_u event_info
Definition: esp_wifi.h:351
bool wifi_set_user_limit_rate_mask(uint8 enable_mask)
Set the interfaces of ESP8266 whose rate of sending packets is limited by wifi_set_user_rate_limit.
WIFI_PHY_MODE wifi_get_phy_mode(void)
Get the ESP8266 physical mode (802.11b/g/n).
uint8 ssid_len
Definition: esp_wifi.h:307
Event_StaMode_Got_IP_t got_ip
Definition: esp_wifi.h:343
void(* freedom_outside_cb_t)(uint8 status)
Callback of sending user-define 802.11 packets.
Definition: esp_wifi.h:383
uint8 wifi_get_channel(void)
Get the channel number for sniffer functions.
void wifi_unregister_user_ie_manufacturer_recv_cb(void)
Unregister user IE received callback.
uint8 wifi_get_user_limit_rate_mask(void)
Get the interfaces of ESP8266 whose rate of sending data is limited by wifi_set_user_rate_limit.
Event_SoftAPMode_ProbeReqRecved_t ap_probereqrecved
Definition: esp_wifi.h:346
void wifi_fpm_set_sleep_type(sleep_type type)
Set sleep type for force sleep function.
bool wifi_set_macaddr(WIFI_INTERFACE if_index, uint8 *macaddr)
Set MAC address of the ESP8266 WiFi station or the soft-AP interface.
Definition: esp_wifi.h:338
Definition: esp_wifi.h:249
void wifi_fpm_do_wakeup(void)
Wake ESP8266 up from MODEM_SLEEP_T force sleep.
Definition: esp_wifi.h:222
Event_SoftAPMode_StaDisconnected_t sta_disconnected
Definition: esp_wifi.h:345
void wifi_unregister_rfid_locp_recv_cb(void)
Unregister the callback of receiving WDS packets.
uint8 bssid[6]
Definition: esp_sta.h:155
sint32 wifi_register_user_ie_manufacturer_recv_cb(user_ie_manufacturer_recv_cb_t cb)
Register user IE received callback.
sleep_type wifi_get_sleep_type(void)
Gets sleep type.
Definition: esp_wifi.h:317
Definition: esp_wifi.h:254
void wifi_fpm_open(void)
Enable force sleep function.
bool wifi_get_ip_info(WIFI_INTERFACE if_index, struct ip_info *info)
Get the IP address of the ESP8266 WiFi station or the soft-AP interface.
Definition: esp_wifi.h:52
uint8 old_mode
Definition: esp_wifi.h:313
WIFI_INTERFACE
Definition: esp_wifi.h:126
uint8 aid
Definition: esp_wifi.h:330
WIFI_MODE wifi_get_opmode_default(void)
Get the operating mode of the WiFi saved in the Flash.
void wifi_set_promiscuous_rx_cb(wifi_promiscuous_cb_t cb)
Register the RX callback function in the promiscuous mode.
Definition: esp_wifi.h:127
bool wifi_set_user_ie(bool enable, uint8 *m_oui, user_ie_type type, uint8 *user_ie, uint8 len)
Set user IE of ESP8266.
void(* wifi_event_handler_cb_t)(System_Event_t *event)
The Wi-Fi event handler.
Definition: esp_wifi.h:364
Definition: esp_wifi.h:55
uint8 aid
Definition: esp_wifi.h:325
int wifi_get_user_fixed_rate(uint8 *enable_mask, uint8 *rate)
Get the fixed rate and mask of ESP8266.
sint32 wifi_rfid_locp_recv_open(void)
Enable RFID LOCP (Location Control Protocol) to receive WDS packets.
void wifi_fpm_set_wakeup_cb(fpm_wakeup_cb cb)
Set a callback of waken up from force sleep because of time out.
Definition: esp_wifi.h:62
Event_StaMode_Connected_t connected
Definition: esp_wifi.h:340
Event_StaMode_AuthMode_Change_t auth_change
Definition: esp_wifi.h:342
Definition: esp_wifi.h:224
Definition: esp_wifi.h:61
Definition: esp_wifi.h:312
Event_SoftAPMode_StaConnected_t sta_connected
Definition: esp_wifi.h:344
sint32 wifi_send_pkt_freedom(uint8 *buf, uint16 len, bool sys_seq)
Send user-define 802.11 packets.
uint8 ssid[32]
Definition: esp_sta.h:156
Definition: esp_wifi.h:333
Definition: esp_wifi.h:223
Definition: esp_wifi.h:63
SYSTEM_EVENT event_id
Definition: esp_wifi.h:350
WIFI_PHY_MODE
Definition: esp_wifi.h:221
Event_StaMode_ScanDone_t scan_done
Definition: esp_wifi.h:339
Definition: esp_wifi.h:328
Definition: esp_sta.h:152
sint8 wifi_fpm_do_sleep(uint32 sleep_time_in_us)
Force ESP8266 enter sleep mode, and it will wake up automatically when time out.
SYSTEM_EVENT
Definition: esp_wifi.h:248
bool wifi_get_macaddr(WIFI_INTERFACE if_index, uint8 *macaddr)
Get MAC address of the ESP8266 WiFi station or the soft-AP interface.
uint8 ssid_len
Definition: esp_wifi.h:300
struct ip_addr netmask
Definition: esp_wifi.h:134