esp_netif: Introduction of esp-netif component as a replacement of tcpip_adpter

- provides object oriented access to network intefaces
- not limited to default netifs
- more generic abstraction to network input output functions
- event handler registration removed from component responsibility
- backward compatibility layer for legacy tcpip_apapter APIs

Closes IDF-39
This commit is contained in:
David Cermak
2019-06-28 16:47:34 +02:00
parent ec9f245dd3
commit ffe043b1a8
56 changed files with 4344 additions and 2629 deletions

View File

@@ -49,7 +49,8 @@
#include <string.h>
#include "esp_eth.h"
#include "tcpip_adapter.h"
#include "esp_netif.h"
#include "esp_netif_net_stack.h"
/* Define those to better describe your network interface. */
#define IFNAME0 'e'
@@ -61,7 +62,7 @@
* @param buf memory alloc in L2 layer
* @note this function is also the callback when invoke pbuf_free
*/
static void ethernet_free_rx_buf_l2(void *buf)
static void ethernet_free_rx_buf_l2(struct netif *netif, void *buf)
{
free(buf);
}
@@ -105,17 +106,15 @@ static void ethernet_low_level_init(struct netif *netif)
static err_t ethernet_low_level_output(struct netif *netif, struct pbuf *p)
{
struct pbuf *q = p;
esp_interface_t eth_if = tcpip_adapter_get_esp_if(netif);
esp_netif_t *esp_netif = esp_netif_get_handle_from_netif_impl(netif);
esp_err_t ret = ESP_FAIL;
esp_eth_handle_t eth_handle = (esp_eth_handle_t)netif->state;
if (eth_if != ESP_IF_ETH) {
LWIP_DEBUGF(NETIF_DEBUG, ("eth_if=%d netif=%p pbuf=%p len=%d\n", eth_if, netif, p, p->len));
if (!esp_netif) {
LWIP_DEBUGF(NETIF_DEBUG, ("corresponding esp-netif is NULL: netif=%p pbuf=%p len=%d\n", netif, p, p->len));
return ERR_IF;
}
if (q->next == NULL) {
ret = esp_eth_transmit(eth_handle, q->payload, q->len);
ret = esp_netif_transmit(esp_netif, q->payload, q->len);
} else {
LWIP_DEBUGF(PBUF_DEBUG, ("low_level_output: pbuf is a list, application may has bug"));
q = pbuf_alloc(PBUF_RAW_TX, p->tot_len, PBUF_RAM);
@@ -129,7 +128,7 @@ static err_t ethernet_low_level_output(struct netif *netif, struct pbuf *p)
} else {
return ERR_MEM;
}
ret = esp_eth_transmit(eth_handle, q->payload, q->len);
ret = esp_netif_transmit(esp_netif, q->payload, q->len);
/* content in payload has been copied to DMA buffer, it's safe to free pbuf now */
pbuf_free(q);
}
@@ -152,13 +151,13 @@ static err_t ethernet_low_level_output(struct netif *netif, struct pbuf *p)
* @param buffer ethernet buffer
* @param len length of buffer
*/
void ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
void ethernetif_input(struct netif *netif, void *buffer, size_t len, void *eb)
{
struct pbuf *p;
if (buffer == NULL || !netif_is_up(netif)) {
if (buffer) {
ethernet_free_rx_buf_l2(buffer);
ethernet_free_rx_buf_l2(netif, buffer);
}
return;
}
@@ -166,7 +165,7 @@ void ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
/* acquire new pbuf, type: PBUF_REF */
p = pbuf_alloc(PBUF_RAW, len, PBUF_REF);
if (p == NULL) {
ethernet_free_rx_buf_l2(buffer);
ethernet_free_rx_buf_l2(netif, buffer);
return;
}
p->payload = buffer;
@@ -194,7 +193,8 @@ void ethernetif_input(struct netif *netif, void *buffer, uint16_t len)
err_t ethernetif_init(struct netif *netif)
{
LWIP_ASSERT("netif != NULL", (netif != NULL));
esp_eth_handle_t eth_handle = (esp_eth_handle_t)netif->state;
/* Have to get the esp-netif handle from netif first and then driver==ethernet handle from there */
esp_eth_handle_t eth_handle = esp_netif_get_io_driver(esp_netif_get_handle_from_netif_impl(netif));
/* Initialize interface hostname */
#if LWIP_NETIF_HOSTNAME
#if ESP_LWIP
@@ -207,6 +207,7 @@ err_t ethernetif_init(struct netif *netif)
/* Initialize the snmp variables and counters inside the struct netif. */
eth_speed_t speed;
esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &speed);
if (speed == ETH_SPEED_100M) {
NETIF_INIT_SNMP(netif, snmp_ifType_ethernet_csmacd, 100000000);