1 /* 2 * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #pragma once 8 9 #include "esp_netif.h" 10 #include "esp_netif_ppp.h" 11 #include "lwip/netif.h" 12 #include "lwip/esp_netif_net_stack.h" 13 #ifdef CONFIG_LWIP_DHCPS 14 #include "dhcpserver/dhcpserver.h" 15 #endif 16 17 struct esp_netif_api_msg_s; 18 19 typedef int (*esp_netif_api_fn)(struct esp_netif_api_msg_s *msg); 20 21 typedef struct esp_netif_api_msg_s { 22 int type; /**< The first field MUST be int */ 23 int ret; 24 esp_netif_api_fn api_fn; 25 union { 26 esp_netif_t *esp_netif; 27 esp_netif_callback_fn user_fn; 28 }; 29 void *data; 30 } esp_netif_api_msg_t; 31 32 33 typedef struct esp_netif_dns_param_s { 34 esp_netif_dns_type_t dns_type; 35 esp_netif_dns_info_t *dns_info; 36 } esp_netif_dns_param_t; 37 38 typedef struct esp_netif_ip_lost_timer_s { 39 bool timer_running; 40 } esp_netif_ip_lost_timer_t; 41 42 /** 43 * @brief Check the netif if of a specific P2P type 44 */ 45 #if CONFIG_PPP_SUPPORT 46 #define ESP_NETIF_IS_POINT2POINT_TYPE(netif, type) (netif->related_data && netif->related_data->is_point2point && netif->related_data->netif_type == type) 47 #else 48 #define ESP_NETIF_IS_POINT2POINT_TYPE(netif, type) false 49 #endif 50 51 /** 52 * @brief Additional netif types when related data are needed 53 */ 54 enum netif_types { 55 COMMON_LWIP_NETIF, 56 PPP_LWIP_NETIF, 57 }; 58 59 /** 60 * @brief Related data to esp-netif (additional data for some special types of netif 61 * (typically for point-point network types, such as PPP) 62 */ 63 typedef struct netif_related_data { 64 bool is_point2point; 65 enum netif_types netif_type; 66 } netif_related_data_t; 67 68 /** 69 * @brief Main esp-netif container with interface related information 70 */ 71 struct esp_netif_obj { 72 // default interface addresses 73 uint8_t mac[NETIF_MAX_HWADDR_LEN]; 74 esp_netif_ip_info_t* ip_info; 75 esp_netif_ip_info_t* ip_info_old; 76 77 // lwip netif related 78 struct netif *lwip_netif; 79 err_t (*lwip_init_fn)(struct netif*); 80 esp_netif_recv_ret_t (*lwip_input_fn)(void *input_netif_handle, void *buffer, size_t len, void *eb); 81 void * netif_handle; // netif impl context (either vanilla lwip-netif or ppp_pcb) 82 netif_related_data_t *related_data; // holds additional data for specific netifs 83 #if ESP_DHCPS 84 dhcps_t *dhcps; 85 #endif 86 // io driver related 87 void* driver_handle; 88 esp_err_t (*driver_transmit)(void *h, void *buffer, size_t len); 89 esp_err_t (*driver_transmit_wrap)(void *h, void *buffer, size_t len, void *pbuf); 90 void (*driver_free_rx_buffer)(void *h, void* buffer); 91 92 // dhcp related 93 esp_netif_dhcp_status_t dhcpc_status; 94 esp_netif_dhcp_status_t dhcps_status; 95 bool timer_running; 96 97 // event translation 98 ip_event_t get_ip_event; 99 ip_event_t lost_ip_event; 100 101 // misc flags, types, keys, priority 102 esp_netif_flags_t flags; 103 char * hostname; 104 char * if_key; 105 char * if_desc; 106 int route_prio; 107 108 #if CONFIG_ESP_NETIF_BRIDGE_EN 109 // bridge configuration 110 uint16_t max_fdb_dyn_entries; 111 uint16_t max_fdb_sta_entries; 112 uint8_t max_ports; 113 #endif // CONFIG_ESP_NETIF_BRIDGE_EN 114 }; 115