• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
2 //
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 #ifndef _ESP_NETIF_TYPES_H_
16 #define _ESP_NETIF_TYPES_H_
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 /**
23  * @brief Definition of ESP-NETIF based errors
24  */
25 #define ESP_ERR_ESP_NETIF_BASE                  0x5000
26 #define ESP_ERR_ESP_NETIF_INVALID_PARAMS        ESP_ERR_ESP_NETIF_BASE + 0x01
27 #define ESP_ERR_ESP_NETIF_IF_NOT_READY          ESP_ERR_ESP_NETIF_BASE + 0x02
28 #define ESP_ERR_ESP_NETIF_DHCPC_START_FAILED    ESP_ERR_ESP_NETIF_BASE + 0x03
29 #define ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED  ESP_ERR_ESP_NETIF_BASE + 0x04
30 #define ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED  ESP_ERR_ESP_NETIF_BASE + 0x05
31 #define ESP_ERR_ESP_NETIF_NO_MEM                ESP_ERR_ESP_NETIF_BASE + 0x06
32 #define ESP_ERR_ESP_NETIF_DHCP_NOT_STOPPED      ESP_ERR_ESP_NETIF_BASE + 0x07
33 #define ESP_ERR_ESP_NETIF_DRIVER_ATTACH_FAILED   ESP_ERR_ESP_NETIF_BASE + 0x08
34 #define ESP_ERR_ESP_NETIF_INIT_FAILED           ESP_ERR_ESP_NETIF_BASE + 0x09
35 #define ESP_ERR_ESP_NETIF_DNS_NOT_CONFIGURED    ESP_ERR_ESP_NETIF_BASE + 0x0A
36 
37 
38 /** @brief Type of esp_netif_object server */
39 struct esp_netif_obj;
40 
41 typedef struct esp_netif_obj esp_netif_t;
42 
43 
44 /** @brief Type of DNS server */
45 typedef enum {
46     ESP_NETIF_DNS_MAIN= 0,       /**< DNS main server address*/
47     ESP_NETIF_DNS_BACKUP,        /**< DNS backup server address (Wi-Fi STA and Ethernet only) */
48     ESP_NETIF_DNS_FALLBACK,      /**< DNS fallback server address (Wi-Fi STA and Ethernet only) */
49     ESP_NETIF_DNS_MAX
50 } esp_netif_dns_type_t;
51 
52 /** @brief DNS server info */
53 typedef struct {
54     esp_ip_addr_t ip; /**< IPV4 address of DNS server */
55 } esp_netif_dns_info_t;
56 
57 /** @brief Status of DHCP client or DHCP server */
58 typedef enum {
59     ESP_NETIF_DHCP_INIT = 0,    /**< DHCP client/server is in initial state (not yet started) */
60     ESP_NETIF_DHCP_STARTED,     /**< DHCP client/server has been started */
61     ESP_NETIF_DHCP_STOPPED,     /**< DHCP client/server has been stopped */
62     ESP_NETIF_DHCP_STATUS_MAX
63 } esp_netif_dhcp_status_t;
64 
65 
66 /** @brief Mode for DHCP client or DHCP server option functions */
67 typedef enum{
68     ESP_NETIF_OP_START = 0,
69     ESP_NETIF_OP_SET,           /**< Set option */
70     ESP_NETIF_OP_GET,           /**< Get option */
71     ESP_NETIF_OP_MAX
72 } esp_netif_dhcp_option_mode_t;
73 
74 /** @brief Supported options for DHCP client or DHCP server */
75 typedef enum{
76     ESP_NETIF_SUBNET_MASK                   = 1,    /**< Network mask */
77     ESP_NETIF_DOMAIN_NAME_SERVER            = 6,    /**< Domain name server */
78     ESP_NETIF_ROUTER_SOLICITATION_ADDRESS   = 32,   /**< Solicitation router address */
79     ESP_NETIF_REQUESTED_IP_ADDRESS          = 50,   /**< Request specific IP address */
80     ESP_NETIF_IP_ADDRESS_LEASE_TIME         = 51,   /**< Request IP address lease time */
81     ESP_NETIF_IP_REQUEST_RETRY_TIME         = 52,   /**< Request IP address retry counter */
82 } esp_netif_dhcp_option_id_t;
83 
84 /** IP event declarations */
85 typedef enum {
86     IP_EVENT_STA_GOT_IP,               /*!< station got IP from connected AP */
87     IP_EVENT_STA_LOST_IP,              /*!< station lost IP and the IP is reset to 0 */
88     IP_EVENT_AP_STAIPASSIGNED,         /*!< soft-AP assign an IP to a connected station */
89     IP_EVENT_GOT_IP6,                  /*!< station or ap or ethernet interface v6IP addr is preferred */
90     IP_EVENT_ETH_GOT_IP,               /*!< ethernet got IP from connected AP */
91     IP_EVENT_PPP_GOT_IP,               /*!< PPP interface got IP */
92     IP_EVENT_PPP_LOST_IP,              /*!< PPP interface lost IP */
93 } ip_event_t;
94 
95 /** @brief IP event base declaration */
96 ESP_EVENT_DECLARE_BASE(IP_EVENT);
97 
98 /** Event structure for IP_EVENT_STA_GOT_IP, IP_EVENT_ETH_GOT_IP events  */
99 
100 typedef struct {
101     esp_ip4_addr_t ip;      /**< Interface IPV4 address */
102     esp_ip4_addr_t netmask; /**< Interface IPV4 netmask */
103     esp_ip4_addr_t gw;      /**< Interface IPV4 gateway address */
104 } esp_netif_ip_info_t;
105 
106 /** @brief IPV6 IP address information
107  */
108 typedef struct {
109     esp_ip6_addr_t ip; /**< Interface IPV6 address */
110 } esp_netif_ip6_info_t;
111 
112 typedef struct {
113     int if_index;                    /*!< Interface index for which the event is received (left for legacy compilation) */
114     esp_netif_t *esp_netif;          /*!< Pointer to corresponding esp-netif object */
115     esp_netif_ip_info_t ip_info;     /*!< IP address, netmask, gatway IP address */
116     bool ip_changed;                 /*!< Whether the assigned IP has changed or not */
117 } ip_event_got_ip_t;
118 
119 /** Event structure for IP_EVENT_GOT_IP6 event */
120 typedef struct {
121     int if_index;                    /*!< Interface index for which the event is received (left for legacy compilation) */
122     esp_netif_t *esp_netif;          /*!< Pointer to corresponding esp-netif object */
123     esp_netif_ip6_info_t ip6_info;   /*!< IPv6 address of the interface */
124     int ip_index;                    /*!< IPv6 address index */
125 } ip_event_got_ip6_t;
126 
127 /** Event structure for IP_EVENT_AP_STAIPASSIGNED event */
128 typedef struct {
129     esp_ip4_addr_t ip; /*!< IP address which was assigned to the station */
130 } ip_event_ap_staipassigned_t;
131 
132 
133 
134 
135 typedef enum esp_netif_flags {
136     ESP_NETIF_DHCP_CLIENT = 1 << 0,
137     ESP_NETIF_DHCP_SERVER = 1 << 1,
138     ESP_NETIF_FLAG_AUTOUP = 1 << 2,
139     ESP_NETIF_FLAG_GARP   = 1 << 3,
140     ESP_NETIF_FLAG_EVENT_IP_MODIFIED = 1 << 4,
141     ESP_NETIF_FLAG_IS_PPP = 1 << 5,
142     ESP_NETIF_FLAG_IS_SLIP = 1 << 6,
143 } esp_netif_flags_t;
144 
145 typedef enum esp_netif_ip_event_type {
146     ESP_NETIF_IP_EVENT_GOT_IP = 1,
147     ESP_NETIF_IP_EVENT_LOST_IP = 2,
148 } esp_netif_ip_event_type_t;
149 
150 
151 //
152 //    ESP-NETIF interface configuration:
153 //      1) general (behavioral) config (esp_netif_config_t)
154 //      2) (peripheral) driver specific config (esp_netif_driver_ifconfig_t)
155 //      3) network stack specific config (esp_netif_net_stack_ifconfig_t) -- no publicly available
156 //
157 
158 typedef struct esp_netif_inherent_config {
159     esp_netif_flags_t flags;         /*!< flags that define esp-netif behavior */
160     uint8_t mac[6];                  /*!< initial mac address for this interface */
161     const esp_netif_ip_info_t* ip_info;    /*!< initial ip address for this interface */
162     uint32_t get_ip_event;           /*!< event id to be raised when interface gets an IP */
163     uint32_t lost_ip_event;          /*!< event id to be raised when interface losts its IP */
164     const char * if_key;             /*!< string identifier of the interface */
165     const char * if_desc;            /*!< textual description of the interface */
166     int route_prio;                  /*!< numeric priority of this interface to become a default
167                                           routing if (if other netifs are up).
168                                           A higher value of route_prio indicates
169                                           a higher priority */
170 } esp_netif_inherent_config_t;
171 
172 typedef struct esp_netif_config esp_netif_config_t;
173 
174 /**
175  * @brief  IO driver handle type
176  */
177 typedef void * esp_netif_iodriver_handle;
178 
179 typedef struct esp_netif_driver_base_s {
180     esp_err_t (*post_attach)(esp_netif_t *netif, esp_netif_iodriver_handle h);
181     esp_netif_t *netif;
182 } esp_netif_driver_base_t;
183 
184 /**
185  * @brief  Specific IO driver configuration
186  */
187 struct esp_netif_driver_ifconfig {
188     esp_netif_iodriver_handle handle;
189     esp_err_t (*transmit)(void *h, void *buffer, size_t len);
190     esp_err_t (*transmit_wrap)(void *h, void *buffer, size_t len, void *netstack_buffer);
191     void (*driver_free_rx_buffer)(void *h, void* buffer);
192 };
193 
194 typedef struct esp_netif_driver_ifconfig esp_netif_driver_ifconfig_t;
195 
196 /**
197  * @brief  Specific L3 network stack configuration
198  */
199 
200 typedef struct esp_netif_netstack_config esp_netif_netstack_config_t;
201 
202 /**
203  * @brief  Generic esp_netif configuration
204  */
205 struct esp_netif_config {
206     const esp_netif_inherent_config_t *base;
207     const esp_netif_driver_ifconfig_t *driver;
208     const esp_netif_netstack_config_t *stack;
209 };
210 
211 /**
212  * @brief  ESP-NETIF Receive function type
213  */
214 typedef esp_err_t (*esp_netif_receive_t)(esp_netif_t *esp_netif, void *buffer, size_t len, void *eb);
215 
216 #ifdef __cplusplus
217 }
218 #endif
219 
220 #endif // _ESP_NETIF_TYPES_H_
221