esp_netif: include tcpip_adapter legacy header by default to provide *implicit* compatiblity

This commit is contained in:
David Cermak 2019-09-13 15:44:23 +02:00
parent 3f60837de2
commit cf710a3cb1
19 changed files with 47 additions and 89 deletions

View file

@ -3,4 +3,4 @@
#
COMPONENT_ADD_INCLUDEDIRS := include
COMPONENT_PRIV_INCLUDEDIRS := private_include lwip
COMPONENT_SRCDIRS := . lwip
COMPONENT_SRCDIRS := . lwip loopback

View file

@ -38,7 +38,7 @@ const esp_netif_inherent_config_t _g_esp_netif_inherent_sta_config = {
.lost_ip_event = IP_EVENT_STA_LOST_IP,
.get_ip_event = IP_EVENT_STA_GOT_IP,
.if_key = "WIFI_STA_DEF",
.if_type = ESP_NETIF_TYPE_STA,
.if_desc = "sta",
.route_prio = 100
};
@ -53,7 +53,7 @@ const esp_netif_inherent_config_t _g_esp_netif_inherent_ap_config = {
.flags = ESP_NETIF_DHCPS | ESP_NETIF_FLAG_AUTOUP,
.ip_info = (esp_netif_ip_info_t*)&soft_ap_ip,
.if_key = "WIFI_AP_DEF",
.if_type = ESP_NETIF_TYPE_AP,
.if_desc = "ap",
.route_prio = 10
};
@ -62,6 +62,6 @@ const esp_netif_inherent_config_t _g_esp_netif_inherent_eth_config = {
.lost_ip_event = 0,
.flags = ESP_NETIF_DHCPC | ESP_NETIF_FLAG_GARP | ESP_NETIF_FLAG_EVENT_IP_MODIFIED,
.if_key = "ETH_DEF",
.if_type = ESP_NETIF_TYPE_ETH,
.if_desc = "eth",
.route_prio = 50
};

View file

@ -28,30 +28,6 @@
static const char *TAG = "esp_netif_handlers";
#define _STR(x) #x
/**
* @brief This function converts interface type to string, which
* helps with backward compatibility of test infrastructure
* to check for standard message that specific interface (sta, ap, eth)
* obtained IP address
*/
static const char* get_netif_type(esp_netif_t* netif) {
const char* s_esp_netif_type_desc[] = {
_STR(ESP_NETIF_TYPE_UNKNOWN),
"sta",
"ap",
"eth",
_STR(ESP_NETIF_TYPE_OTHER)
};
size_t type_nr = esp_netif_get_type(netif);
if (type_nr > sizeof(s_esp_netif_type_desc)/sizeof(s_esp_netif_type_desc[0])) {
type_nr = 0;
}
return s_esp_netif_type_desc[type_nr];
}
void esp_netif_action_start(void *esp_netif, esp_event_base_t base, int32_t event_id, void *data)
{
ESP_LOGD(TAG, "esp_netif action has started with netif%p from event_id=%d", esp_netif, event_id);
@ -117,7 +93,7 @@ void esp_netif_action_got_ip(void *esp_netif, esp_event_base_t base, int32_t eve
{
ESP_LOGD(TAG, "esp_netif action got_ip with netif%p from event_id=%d", esp_netif, event_id);
const ip_event_got_ip_t *event = (const ip_event_got_ip_t *) data;
ESP_LOGI(TAG, "%s ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR, get_netif_type(esp_netif),
ESP_LOGI(TAG, "%s ip: " IPSTR ", mask: " IPSTR ", gw: " IPSTR, esp_netif_get_desc(esp_netif),
IP2STR(&event->ip_info.ip),
IP2STR(&event->ip_info.netmask),
IP2STR(&event->ip_info.gw));

View file

@ -22,6 +22,16 @@
#include "esp_netif_types.h"
#include "esp_netif_defaults.h"
//
// Note: tcpip_adapter legacy API has to be included by default to provide full compatibility
// for applications that used tcpip_adapter API without explicit inclusion of tcpip_adapter.h
//
#if CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER
#define _ESP_NETIF_SUPPRESS_LEGACY_WARNING_
#include "tcpip_adapter.h"
#undef _ESP_NETIF_SUPPRESS_LEGACY_WARNING_
#endif // CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER
/**
* @defgroup ESP_NETIF_INIT_API ESP-NETIF Initialization API
* @brief Initialization and deinitialization of underlying TCP/IP stack and esp-netif instances
@ -679,7 +689,7 @@ const char *esp_netif_get_ifkey(esp_netif_t *esp_netif);
*
* @return Enumerated type of this interface, such as station, AP, ethernet
*/
esp_netif_type_t esp_netif_get_type(esp_netif_t *esp_netif);
const char *esp_netif_get_desc(esp_netif_t *esp_netif);
/**
* @brief Returns configured event for this esp-netif instance and supplied event type

View file

@ -130,15 +130,6 @@ typedef enum esp_netif_flags {
ESP_NETIF_FLAG_EVENT_IP_MODIFIED = 1 << 4
} esp_netif_flags_t;
typedef enum esp_netif_type {
ESP_NETIF_TYPE_UNKNOWN,
ESP_NETIF_TYPE_STA,
ESP_NETIF_TYPE_AP,
ESP_NETIF_TYPE_ETH,
ESP_NETIF_TYPE_OTHER,
ESP_NETIF_TYPE_MAX
} esp_netif_type_t;
typedef enum esp_netif_ip_event_type {
ESP_NETIF_IP_EVENT_GOT_IP = 1,
ESP_NETIF_IP_EVENT_LOST_IP = 2,
@ -158,8 +149,8 @@ typedef struct esp_netif_inherent_config {
esp_netif_ip_info_t* ip_info; /*!< initial ip address for this interface */
uint32_t get_ip_event; /*!< event id to be raised when interface gets an IP */
uint32_t lost_ip_event; /*!< event id to be raised when interface losts its IP */
esp_netif_type_t if_type; /*!< enum type of the interface */
const char * if_key; /*!< string identifier of the interface */
const char * if_desc; /*!< textual description of the interface */
int route_prio; /*!< numeric priority of this interface to become a default
routing if (if other netifs are up) */
} esp_netif_inherent_config_t;
@ -191,15 +182,6 @@ typedef struct esp_netif_driver_ifconfig esp_netif_driver_ifconfig_t;
/**
* @brief Specific L3 network stack configuration
*/
typedef enum esp_netif_netstack_type {
ESP_NETIF_NETWORK_STACK_IS_LWIP = 0,
ESP_NETIF_NETWORK_STACK_IS_LOOPBACK = 1,
ESP_NETIF_NETWORK_STACK_MAX,
} esp_netif_netstack_type_t;
typedef struct esp_netif_netstack_base_config {
esp_netif_netstack_type_t type;
} esp_netif_netstack_base_config_t;
typedef struct esp_netif_netstack_config esp_netif_netstack_config_t;

View file

@ -56,7 +56,7 @@ struct esp_netif_obj {
esp_netif_flags_t flags;
char * hostname;
char * if_key;
esp_netif_type_t if_type;
char * if_desc;
int route_prio;
};
@ -135,18 +135,14 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_
if (cfg->base->if_key) {
esp_netif->if_key = strdup(cfg->base->if_key);
}
if (cfg->base->if_type) {
esp_netif->if_type = cfg->base->if_type;
if (cfg->base->if_desc) {
esp_netif->if_desc = strdup(cfg->base->if_desc);
}
if (cfg->base->route_prio) {
esp_netif->route_prio = cfg->base->route_prio;
}
// Install network stack functions -- connects netif and L3 stack
if (cfg->stack->base.type != ESP_NETIF_NETWORK_STACK_IS_LOOPBACK) {
ESP_LOGE(TAG, "Failed to configure uknown network stack %d", cfg->stack->base.type);
return ESP_ERR_NOT_SUPPORTED;
}
// Network stack is bypassed in loopback interface
// Install IO functions only if provided -- connects driver and netif
// this configuration could be updated after esp_netif_new(), typically in post_attach callback
@ -215,6 +211,7 @@ void esp_netif_destroy(esp_netif_t *esp_netif)
free(esp_netif->ip_info);
free(esp_netif->ip_info_old);
free(esp_netif->if_key);
free(esp_netif->if_desc);
free(esp_netif);
}
}
@ -228,7 +225,7 @@ esp_err_t esp_netif_attach(esp_netif_t *esp_netif, esp_netif_iodriver_handle dri
esp_err_t ret = base_driver->post_attach(esp_netif, driver_handle);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Post-attach callback of driver(%p) failed with %d", driver_handle, ret);
return ESP_ERR_ESP_NETIF_DRIVER_ATACH_FAILED;
return ESP_ERR_ESP_NETIF_DRIVER_ATTACH_FAILED;
}
}
return ESP_OK;
@ -420,14 +417,14 @@ esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif)
return esp_netif->flags;
}
char *esp_netif_get_ifkey(esp_netif_t *esp_netif)
const char *esp_netif_get_ifkey(esp_netif_t *esp_netif)
{
return esp_netif->if_key;
}
esp_netif_type_t esp_netif_get_type(esp_netif_t *esp_netif)
const char *esp_netif_get_desc(esp_netif_t *esp_netif)
{
return esp_netif->if_type;
return esp_netif->if_desc;
}
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)

View file

@ -93,7 +93,7 @@ struct esp_netif_obj {
esp_netif_flags_t flags;
char * hostname;
char * if_key;
esp_netif_type_t if_type;
char * if_desc;
int route_prio;
};
@ -322,8 +322,8 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_
if (cfg->base->if_key) {
esp_netif->if_key = strdup(cfg->base->if_key);
}
if (cfg->base->if_type) {
esp_netif->if_type = cfg->base->if_type;
if (cfg->base->if_desc) {
esp_netif->if_desc = strdup(cfg->base->if_desc);
}
if (cfg->base->route_prio) {
esp_netif->route_prio = cfg->base->route_prio;
@ -331,10 +331,6 @@ static esp_err_t esp_netif_init_configuration(esp_netif_t *esp_netif, const esp_
// Install network stack functions -- connects netif and L3 stack
const esp_netif_netstack_config_t *esp_netif_stack_config = cfg->stack;
if (cfg->stack->base.type != ESP_NETIF_NETWORK_STACK_IS_LWIP) {
ESP_LOGE(TAG, "Failed to configure uknown network stack %d", cfg->stack->base.type);
return ESP_ERR_NOT_SUPPORTED;
}
if (esp_netif_stack_config->init_fn) {
esp_netif->lwip_init_fn = esp_netif_stack_config->init_fn;
}
@ -448,6 +444,7 @@ void esp_netif_destroy(esp_netif_t *esp_netif)
free(esp_netif->ip_info);
free(esp_netif->ip_info_old);
free(esp_netif->if_key);
free(esp_netif->if_desc);
esp_netif_lwip_remove(esp_netif);
free(esp_netif->lwip_netif);
free(esp_netif->hostname);
@ -1348,9 +1345,9 @@ const char *esp_netif_get_ifkey(esp_netif_t *esp_netif)
return esp_netif->if_key;
}
esp_netif_type_t esp_netif_get_type(esp_netif_t *esp_netif)
const char *esp_netif_get_desc(esp_netif_t *esp_netif)
{
return esp_netif->if_type;
return esp_netif->if_desc;
}
esp_netif_t *esp_netif_get_handle_from_ifkey(const char *if_key)

View file

@ -24,17 +24,14 @@
//
static const struct esp_netif_netstack_config s_eth_netif_config = {
.base = { .type = ESP_NETIF_NETWORK_STACK_IS_LWIP },
.init_fn = ethernetif_init,
.input_fn = ethernetif_input
};
static const struct esp_netif_netstack_config s_wifi_netif_config_ap = {
.base = { .type = ESP_NETIF_NETWORK_STACK_IS_LWIP },
.init_fn = wlanif_init_ap,
.input_fn = wlanif_input
};
static const struct esp_netif_netstack_config s_wifi_netif_config_sta = {
.base = { .type = ESP_NETIF_NETWORK_STACK_IS_LWIP },
.init_fn = wlanif_init_sta,
.input_fn = wlanif_input
};

View file

@ -19,7 +19,6 @@
// LWIP netif specific network stack configuration
struct esp_netif_netstack_config {
esp_netif_netstack_base_config_t base;
err_t (*init_fn)(struct netif*);
void (*input_fn)(struct netif *netif, void *buffer, size_t len, void *eb);
};

View file

@ -4,9 +4,7 @@
TEST_CASE("esp_netif: init and destroy", "[esp_netif][leaks=0]")
{
esp_netif_inherent_config_t base = {};
const esp_netif_netstack_base_config_t stack = { .type = ESP_NETIF_NETWORK_STACK_IS_LWIP };
esp_netif_config_t cfg = { .base = &base, .stack = (const esp_netif_netstack_config_t*)&stack };
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_WIFI_STA();
esp_netif_t *esp_netif = esp_netif_new(NULL);
TEST_ASSERT_EQUAL(NULL, esp_netif);

View file

@ -120,10 +120,6 @@ low_level_output(struct netif *netif, struct pbuf *p)
if (esp_netif == NULL) {
return ERR_IF;
}
esp_netif_type_t type = esp_netif_get_type(esp_netif);
if (type != ESP_NETIF_TYPE_STA && type != ESP_NETIF_TYPE_AP) {
return ERR_IF;
}
struct pbuf *q = p;
err_t ret;

View file

@ -11,20 +11,23 @@
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef _ESP_NETIF_SUPPRESS_LEGACY_WARNING_
#warning "This header is deprecated, please use new network related API in esp_netif.h"
#include "esp_netif.h"
#endif
#ifndef _TCPIP_ADAPTER_H_
#define _TCPIP_ADAPTER_H_
#warning "This header is deprecated, please use new network related API in esp_netif.h"
#include "esp_netif.h"
#include "tcpip_adapter_types.h"
/**
* @brief tcpip adapter legacy init. It is used only to set the compatibility mode of esp-netif, which
* will enable backward compatibility of esp-netif.
*/
void tcpip_adapter_init(void);
void tcpip_adapter_init(void) __attribute__ ((deprecated));
/**
* @brief Compatiblity mode: convert the esp-netif handle to tcpip_adapter legacy interface enum

View file

@ -1 +1,2 @@
CONFIG_ESP_HTTPS_SERVER_ENABLE=y
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n

View file

@ -5,4 +5,5 @@ CONFIG_EXAMPLE_BROKER_WSS_URI="wss://${EXAMPLE_MQTT_BROKER_WSS}/ws"
CONFIG_EXAMPLE_BROKER_CERTIFICATE_OVERRIDE="${EXAMPLE_MQTT_BROKER_CERTIFICATE}"
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=16384
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=16384
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n

View file

@ -10,3 +10,4 @@ CONFIG_MQTT_TASK_STACK_SIZE=6144
CONFIG_MBEDTLS_ASYMMETRIC_CONTENT_LEN=y
CONFIG_MBEDTLS_SSL_IN_CONTENT_LEN=16384
CONFIG_MBEDTLS_SSL_OUT_CONTENT_LEN=4096
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n

View file

@ -1,2 +1,3 @@
CONFIG_LOG_DEFAULT_LEVEL_DEBUG=y
CONFIG_BROKER_URL="FROM_STDIN"
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n

View file

@ -1 +1,2 @@
CONFIG_BROKER_URI="ws://${EXAMPLE_MQTT_BROKER_WS}/ws"
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n

View file

@ -1,3 +1,3 @@
CONFIG_BROKER_URI="wss://${EXAMPLE_MQTT_BROKER_WSS}/ws"
CONFIG_BROKER_CERTIFICATE_OVERRIDE="${EXAMPLE_MQTT_BROKER_CERTIFICATE}"
CONFIG_ESP_NETIF_TCPIP_ADAPTER_COMPATIBLE_LAYER=n

View file

@ -26,7 +26,6 @@ static struct netif *g_last_netif = NULL;
// LWIP netif specific defines
struct esp_netif_netstack_config {
esp_netif_netstack_base_config_t base;
err_t (*init_fn)(struct netif*);
void (*input_fn)(struct netif *netif, void *buffer, size_t len, void *eb);
};
@ -35,8 +34,7 @@ err_t testnetif_init(struct netif *netif);
void testnetif_input(struct netif *netif, void *buffer, size_t len, void *eb);
const struct esp_netif_netstack_config _g_test_netif_stack_config = { { ESP_NETIF_NETWORK_STACK_IS_LWIP }, testnetif_init, testnetif_input};
const struct esp_netif_netstack_config _g_test_netif_stack_config = { testnetif_init, testnetif_input};
err_t testnetif_output(struct netif *netif, struct pbuf *p)
{