1 /* 2 * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _ESP_NETIF_TYPES_H_ 8 #define _ESP_NETIF_TYPES_H_ 9 10 #include <stdbool.h> 11 #include <stdint.h> 12 #include "esp_event_base.h" 13 #include "esp_err.h" 14 #include "esp_netif_ip_addr.h" 15 16 #ifdef __cplusplus 17 extern "C" { 18 #endif 19 20 /** 21 * @brief Definition of ESP-NETIF based errors 22 */ 23 #define ESP_ERR_ESP_NETIF_BASE 0x5000 24 #define ESP_ERR_ESP_NETIF_INVALID_PARAMS ESP_ERR_ESP_NETIF_BASE + 0x01 25 #define ESP_ERR_ESP_NETIF_IF_NOT_READY ESP_ERR_ESP_NETIF_BASE + 0x02 26 #define ESP_ERR_ESP_NETIF_DHCPC_START_FAILED ESP_ERR_ESP_NETIF_BASE + 0x03 27 #define ESP_ERR_ESP_NETIF_DHCP_ALREADY_STARTED ESP_ERR_ESP_NETIF_BASE + 0x04 28 #define ESP_ERR_ESP_NETIF_DHCP_ALREADY_STOPPED ESP_ERR_ESP_NETIF_BASE + 0x05 29 #define ESP_ERR_ESP_NETIF_NO_MEM ESP_ERR_ESP_NETIF_BASE + 0x06 30 #define ESP_ERR_ESP_NETIF_DHCP_NOT_STOPPED ESP_ERR_ESP_NETIF_BASE + 0x07 31 #define ESP_ERR_ESP_NETIF_DRIVER_ATTACH_FAILED ESP_ERR_ESP_NETIF_BASE + 0x08 32 #define ESP_ERR_ESP_NETIF_INIT_FAILED ESP_ERR_ESP_NETIF_BASE + 0x09 33 #define ESP_ERR_ESP_NETIF_DNS_NOT_CONFIGURED ESP_ERR_ESP_NETIF_BASE + 0x0A 34 #define ESP_ERR_ESP_NETIF_MLD6_FAILED ESP_ERR_ESP_NETIF_BASE + 0x0B 35 #define ESP_ERR_ESP_NETIF_IP6_ADDR_FAILED ESP_ERR_ESP_NETIF_BASE + 0x0C 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_VENDOR_CLASS_IDENTIFIER = 60, /**< Vendor Class Identifier of a DHCP client */ 83 ESP_NETIF_VENDOR_SPECIFIC_INFO = 43, /**< Vendor Specific Information of a DHCP server */ 84 } esp_netif_dhcp_option_id_t; 85 86 /** IP event declarations */ 87 typedef enum { 88 IP_EVENT_STA_GOT_IP, /*!< station got IP from connected AP */ 89 IP_EVENT_STA_LOST_IP, /*!< station lost IP and the IP is reset to 0 */ 90 IP_EVENT_AP_STAIPASSIGNED, /*!< soft-AP assign an IP to a connected station */ 91 IP_EVENT_GOT_IP6, /*!< station or ap or ethernet interface v6IP addr is preferred */ 92 IP_EVENT_ETH_GOT_IP, /*!< ethernet got IP from connected AP */ 93 IP_EVENT_ETH_LOST_IP, /*!< ethernet lost IP and the IP is reset to 0 */ 94 IP_EVENT_PPP_GOT_IP, /*!< PPP interface got IP */ 95 IP_EVENT_PPP_LOST_IP, /*!< PPP interface lost IP */ 96 } ip_event_t; 97 98 /** @brief IP event base declaration */ 99 ESP_EVENT_DECLARE_BASE(IP_EVENT); 100 101 /** Event structure for IP_EVENT_STA_GOT_IP, IP_EVENT_ETH_GOT_IP events */ 102 103 typedef struct { 104 esp_ip4_addr_t ip; /**< Interface IPV4 address */ 105 esp_ip4_addr_t netmask; /**< Interface IPV4 netmask */ 106 esp_ip4_addr_t gw; /**< Interface IPV4 gateway address */ 107 } esp_netif_ip_info_t; 108 109 /** @brief IPV6 IP address information 110 */ 111 typedef struct { 112 esp_ip6_addr_t ip; /**< Interface IPV6 address */ 113 } esp_netif_ip6_info_t; 114 115 typedef struct { 116 int if_index; /*!< Interface index for which the event is received (left for legacy compilation) */ 117 esp_netif_t *esp_netif; /*!< Pointer to corresponding esp-netif object */ 118 esp_netif_ip_info_t ip_info; /*!< IP address, netmask, gatway IP address */ 119 bool ip_changed; /*!< Whether the assigned IP has changed or not */ 120 } ip_event_got_ip_t; 121 122 /** Event structure for IP_EVENT_GOT_IP6 event */ 123 typedef struct { 124 int if_index; /*!< Interface index for which the event is received (left for legacy compilation) */ 125 esp_netif_t *esp_netif; /*!< Pointer to corresponding esp-netif object */ 126 esp_netif_ip6_info_t ip6_info; /*!< IPv6 address of the interface */ 127 int ip_index; /*!< IPv6 address index */ 128 } ip_event_got_ip6_t; 129 130 /** Event structure for ADD_IP6 event */ 131 typedef struct { 132 esp_ip6_addr_t addr; /*!< The address to be added to the interface */ 133 bool preferred; /*!< The default preference of the address */ 134 } ip_event_add_ip6_t; 135 136 /** Event structure for IP_EVENT_AP_STAIPASSIGNED event */ 137 typedef struct { 138 esp_ip4_addr_t ip; /*!< IP address which was assigned to the station */ 139 } ip_event_ap_staipassigned_t; 140 141 142 143 144 typedef enum esp_netif_flags { 145 ESP_NETIF_DHCP_CLIENT = 1 << 0, 146 ESP_NETIF_DHCP_SERVER = 1 << 1, 147 ESP_NETIF_FLAG_AUTOUP = 1 << 2, 148 ESP_NETIF_FLAG_GARP = 1 << 3, 149 ESP_NETIF_FLAG_EVENT_IP_MODIFIED = 1 << 4, 150 ESP_NETIF_FLAG_IS_PPP = 1 << 5, 151 ESP_NETIF_FLAG_IS_SLIP = 1 << 6, 152 } esp_netif_flags_t; 153 154 typedef enum esp_netif_ip_event_type { 155 ESP_NETIF_IP_EVENT_GOT_IP = 1, 156 ESP_NETIF_IP_EVENT_LOST_IP = 2, 157 } esp_netif_ip_event_type_t; 158 159 160 // 161 // ESP-NETIF interface configuration: 162 // 1) general (behavioral) config (esp_netif_config_t) 163 // 2) (peripheral) driver specific config (esp_netif_driver_ifconfig_t) 164 // 3) network stack specific config (esp_netif_net_stack_ifconfig_t) -- no publicly available 165 // 166 167 typedef struct esp_netif_inherent_config { 168 esp_netif_flags_t flags; /*!< flags that define esp-netif behavior */ 169 uint8_t mac[6]; /*!< initial mac address for this interface */ 170 const esp_netif_ip_info_t* ip_info; /*!< initial ip address for this interface */ 171 uint32_t get_ip_event; /*!< event id to be raised when interface gets an IP */ 172 uint32_t lost_ip_event; /*!< event id to be raised when interface losts its IP */ 173 const char * if_key; /*!< string identifier of the interface */ 174 const char * if_desc; /*!< textual description of the interface */ 175 int route_prio; /*!< numeric priority of this interface to become a default 176 routing if (if other netifs are up). 177 A higher value of route_prio indicates 178 a higher priority */ 179 } esp_netif_inherent_config_t; 180 181 typedef struct esp_netif_config esp_netif_config_t; 182 183 /** 184 * @brief IO driver handle type 185 */ 186 typedef void * esp_netif_iodriver_handle; 187 188 typedef struct esp_netif_driver_base_s { 189 esp_err_t (*post_attach)(esp_netif_t *netif, esp_netif_iodriver_handle h); 190 esp_netif_t *netif; 191 } esp_netif_driver_base_t; 192 193 /** 194 * @brief Specific IO driver configuration 195 */ 196 struct esp_netif_driver_ifconfig { 197 esp_netif_iodriver_handle handle; 198 esp_err_t (*transmit)(void *h, void *buffer, size_t len); 199 esp_err_t (*transmit_wrap)(void *h, void *buffer, size_t len, void *netstack_buffer); 200 void (*driver_free_rx_buffer)(void *h, void* buffer); 201 }; 202 203 typedef struct esp_netif_driver_ifconfig esp_netif_driver_ifconfig_t; 204 205 /** 206 * @brief Specific L3 network stack configuration 207 */ 208 209 typedef struct esp_netif_netstack_config esp_netif_netstack_config_t; 210 211 /** 212 * @brief Generic esp_netif configuration 213 */ 214 struct esp_netif_config { 215 const esp_netif_inherent_config_t *base; 216 const esp_netif_driver_ifconfig_t *driver; 217 const esp_netif_netstack_config_t *stack; 218 }; 219 220 /** 221 * @brief ESP-NETIF Receive function type 222 */ 223 typedef esp_err_t (*esp_netif_receive_t)(esp_netif_t *esp_netif, void *buffer, size_t len, void *eb); 224 225 #ifdef __cplusplus 226 } 227 #endif 228 229 #endif // _ESP_NETIF_TYPES_H_ 230