1 /* 2 * SPDX-FileCopyrightText: 2015-2022 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 #define ESP_ERR_ESP_NETIF_DHCPS_START_FAILED ESP_ERR_ESP_NETIF_BASE + 0x0D 37 38 39 /** 40 * @brief Definition of ESP-NETIF bridge controll 41 */ 42 #define ESP_NETIF_BR_FLOOD -1 43 #define ESP_NETIF_BR_DROP 0 44 #define ESP_NETIF_BR_FDW_CPU (1ULL << 63) 45 46 /** @brief Type of esp_netif_object server */ 47 struct esp_netif_obj; 48 49 typedef struct esp_netif_obj esp_netif_t; 50 51 52 /** @brief Type of DNS server */ 53 typedef enum { 54 ESP_NETIF_DNS_MAIN= 0, /**< DNS main server address*/ 55 ESP_NETIF_DNS_BACKUP, /**< DNS backup server address (Wi-Fi STA and Ethernet only) */ 56 ESP_NETIF_DNS_FALLBACK, /**< DNS fallback server address (Wi-Fi STA and Ethernet only) */ 57 ESP_NETIF_DNS_MAX 58 } esp_netif_dns_type_t; 59 60 /** @brief DNS server info */ 61 typedef struct { 62 esp_ip_addr_t ip; /**< IPV4 address of DNS server */ 63 } esp_netif_dns_info_t; 64 65 /** @brief Status of DHCP client or DHCP server */ 66 typedef enum { 67 ESP_NETIF_DHCP_INIT = 0, /**< DHCP client/server is in initial state (not yet started) */ 68 ESP_NETIF_DHCP_STARTED, /**< DHCP client/server has been started */ 69 ESP_NETIF_DHCP_STOPPED, /**< DHCP client/server has been stopped */ 70 ESP_NETIF_DHCP_STATUS_MAX 71 } esp_netif_dhcp_status_t; 72 73 74 /** @brief Mode for DHCP client or DHCP server option functions */ 75 typedef enum{ 76 ESP_NETIF_OP_START = 0, 77 ESP_NETIF_OP_SET, /**< Set option */ 78 ESP_NETIF_OP_GET, /**< Get option */ 79 ESP_NETIF_OP_MAX 80 } esp_netif_dhcp_option_mode_t; 81 82 /** @brief Supported options for DHCP client or DHCP server */ 83 typedef enum{ 84 ESP_NETIF_SUBNET_MASK = 1, /**< Network mask */ 85 ESP_NETIF_DOMAIN_NAME_SERVER = 6, /**< Domain name server */ 86 ESP_NETIF_ROUTER_SOLICITATION_ADDRESS = 32, /**< Solicitation router address */ 87 ESP_NETIF_REQUESTED_IP_ADDRESS = 50, /**< Request specific IP address */ 88 ESP_NETIF_IP_ADDRESS_LEASE_TIME = 51, /**< Request IP address lease time */ 89 ESP_NETIF_IP_REQUEST_RETRY_TIME = 52, /**< Request IP address retry counter */ 90 ESP_NETIF_VENDOR_CLASS_IDENTIFIER = 60, /**< Vendor Class Identifier of a DHCP client */ 91 ESP_NETIF_VENDOR_SPECIFIC_INFO = 43, /**< Vendor Specific Information of a DHCP server */ 92 } esp_netif_dhcp_option_id_t; 93 94 /** IP event declarations */ 95 typedef enum { 96 IP_EVENT_STA_GOT_IP, /*!< station got IP from connected AP */ 97 IP_EVENT_STA_LOST_IP, /*!< station lost IP and the IP is reset to 0 */ 98 IP_EVENT_AP_STAIPASSIGNED, /*!< soft-AP assign an IP to a connected station */ 99 IP_EVENT_GOT_IP6, /*!< station or ap or ethernet interface v6IP addr is preferred */ 100 IP_EVENT_ETH_GOT_IP, /*!< ethernet got IP from connected AP */ 101 IP_EVENT_ETH_LOST_IP, /*!< ethernet lost IP and the IP is reset to 0 */ 102 IP_EVENT_PPP_GOT_IP, /*!< PPP interface got IP */ 103 IP_EVENT_PPP_LOST_IP, /*!< PPP interface lost IP */ 104 } ip_event_t; 105 106 /** @brief IP event base declaration */ 107 ESP_EVENT_DECLARE_BASE(IP_EVENT); 108 109 /** Event structure for IP_EVENT_STA_GOT_IP, IP_EVENT_ETH_GOT_IP events */ 110 111 typedef struct { 112 esp_ip4_addr_t ip; /**< Interface IPV4 address */ 113 esp_ip4_addr_t netmask; /**< Interface IPV4 netmask */ 114 esp_ip4_addr_t gw; /**< Interface IPV4 gateway address */ 115 } esp_netif_ip_info_t; 116 117 /** @brief IPV6 IP address information 118 */ 119 typedef struct { 120 esp_ip6_addr_t ip; /**< Interface IPV6 address */ 121 } esp_netif_ip6_info_t; 122 123 124 /** 125 * @brief Event structure for IP_EVENT_GOT_IP event 126 * 127 */ 128 typedef struct { 129 esp_netif_t *esp_netif; /*!< Pointer to corresponding esp-netif object */ 130 esp_netif_ip_info_t ip_info; /*!< IP address, netmask, gatway IP address */ 131 bool ip_changed; /*!< Whether the assigned IP has changed or not */ 132 } ip_event_got_ip_t; 133 134 /** Event structure for IP_EVENT_GOT_IP6 event */ 135 typedef struct { 136 esp_netif_t *esp_netif; /*!< Pointer to corresponding esp-netif object */ 137 esp_netif_ip6_info_t ip6_info; /*!< IPv6 address of the interface */ 138 int ip_index; /*!< IPv6 address index */ 139 } ip_event_got_ip6_t; 140 141 /** Event structure for ADD_IP6 event */ 142 typedef struct { 143 esp_ip6_addr_t addr; /*!< The address to be added to the interface */ 144 bool preferred; /*!< The default preference of the address */ 145 } ip_event_add_ip6_t; 146 147 /** Event structure for IP_EVENT_AP_STAIPASSIGNED event */ 148 typedef struct { 149 esp_netif_t *esp_netif; /*!< Pointer to the associated netif handle */ 150 esp_ip4_addr_t ip; /*!< IP address which was assigned to the station */ 151 uint8_t mac[6]; /*!< MAC address of the connected client */ 152 } ip_event_ap_staipassigned_t; 153 154 155 typedef enum esp_netif_flags { 156 ESP_NETIF_DHCP_CLIENT = 1 << 0, 157 ESP_NETIF_DHCP_SERVER = 1 << 1, 158 ESP_NETIF_FLAG_AUTOUP = 1 << 2, 159 ESP_NETIF_FLAG_GARP = 1 << 3, 160 ESP_NETIF_FLAG_EVENT_IP_MODIFIED = 1 << 4, 161 ESP_NETIF_FLAG_IS_PPP = 1 << 5, 162 ESP_NETIF_FLAG_IS_BRIDGE = 1 << 6, 163 ESP_NETIF_FLAG_MLDV6_REPORT = 1 << 7, 164 } esp_netif_flags_t; 165 166 typedef enum esp_netif_ip_event_type { 167 ESP_NETIF_IP_EVENT_GOT_IP = 1, 168 ESP_NETIF_IP_EVENT_LOST_IP = 2, 169 } esp_netif_ip_event_type_t; 170 171 172 /** LwIP bridge configuration */ 173 typedef struct bridgeif_config { 174 uint16_t max_fdb_dyn_entries; /*!< maximum number of entries in dynamic forwarding database */ 175 uint16_t max_fdb_sta_entries; /*!< maximum number of entries in static forwarding database */ 176 uint8_t max_ports; /*!< maximum number of ports the bridge can consist of */ 177 } bridgeif_config_t; 178 179 // 180 // ESP-NETIF interface configuration: 181 // 1) general (behavioral) config (esp_netif_config_t) 182 // 2) (peripheral) driver specific config (esp_netif_driver_ifconfig_t) 183 // 3) network stack specific config (esp_netif_net_stack_ifconfig_t) -- no publicly available 184 // 185 186 /** 187 * @brief ESP-netif inherent config parameters 188 * 189 */ 190 typedef struct esp_netif_inherent_config { 191 esp_netif_flags_t flags; /*!< flags that define esp-netif behavior */ 192 uint8_t mac[6]; /*!< initial mac address for this interface */ 193 const esp_netif_ip_info_t* ip_info; /*!< initial ip address for this interface */ 194 uint32_t get_ip_event; /*!< event id to be raised when interface gets an IP */ 195 uint32_t lost_ip_event; /*!< event id to be raised when interface losts its IP */ 196 const char * if_key; /*!< string identifier of the interface */ 197 const char * if_desc; /*!< textual description of the interface */ 198 int route_prio; /*!< numeric priority of this interface to become a default 199 routing if (if other netifs are up). 200 A higher value of route_prio indicates 201 a higher priority */ 202 bridgeif_config_t *bridge_info; /*!< LwIP bridge configuration */ 203 } esp_netif_inherent_config_t; 204 205 typedef struct esp_netif_config esp_netif_config_t; 206 207 /** 208 * @brief IO driver handle type 209 */ 210 typedef void * esp_netif_iodriver_handle; 211 212 /** 213 * @brief ESP-netif driver base handle 214 * 215 */ 216 typedef struct esp_netif_driver_base_s { 217 esp_err_t (*post_attach)(esp_netif_t *netif, esp_netif_iodriver_handle h); /*!< post attach function pointer */ 218 esp_netif_t *netif; /*!< netif handle */ 219 } esp_netif_driver_base_t; 220 221 /** 222 * @brief Specific IO driver configuration 223 */ 224 struct esp_netif_driver_ifconfig { 225 esp_netif_iodriver_handle handle; /*!< io-driver handle */ 226 esp_err_t (*transmit)(void *h, void *buffer, size_t len); /*!< transmit function pointer */ 227 esp_err_t (*transmit_wrap)(void *h, void *buffer, size_t len, void *netstack_buffer); /*!< transmit wrap function pointer */ 228 void (*driver_free_rx_buffer)(void *h, void* buffer); /*!< free rx buffer function pointer */ 229 }; 230 231 typedef struct esp_netif_driver_ifconfig esp_netif_driver_ifconfig_t; 232 233 /** 234 * @brief Specific L3 network stack configuration 235 */ 236 237 typedef struct esp_netif_netstack_config esp_netif_netstack_config_t; 238 239 /** 240 * @brief Generic esp_netif configuration 241 */ 242 struct esp_netif_config { 243 const esp_netif_inherent_config_t *base; /*!< base config */ 244 const esp_netif_driver_ifconfig_t *driver; /*!< driver config */ 245 const esp_netif_netstack_config_t *stack; /*!< stack config */ 246 }; 247 248 /** 249 * @brief DHCP client's addr info (pair of MAC and IP address) 250 */ 251 typedef struct { 252 uint8_t mac[6]; /**< Clients MAC address */ 253 esp_ip4_addr_t ip; /**< Clients IP address */ 254 } esp_netif_pair_mac_ip_t; 255 256 /** 257 * @brief ESP-NETIF Receive function type 258 */ 259 typedef esp_err_t (*esp_netif_receive_t)(esp_netif_t *esp_netif, void *buffer, size_t len, void *eb); 260 261 #ifdef __cplusplus 262 } 263 #endif 264 265 #endif // _ESP_NETIF_TYPES_H_ 266