diff --git a/components/esp_netif/CMakeLists.txt b/components/esp_netif/CMakeLists.txt index 77a10dad84..7c6f04e41b 100644 --- a/components/esp_netif/CMakeLists.txt +++ b/components/esp_netif/CMakeLists.txt @@ -24,7 +24,7 @@ if(${target} STREQUAL "linux") endif() if(CONFIG_PPP_SUPPORT) - list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c) + list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c lwip/netif/ppp.c) endif() diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index b9a3846c52..5233dd31a5 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -17,6 +17,7 @@ #include "esp_netif_lwip_internal.h" #include #include "lwip/ip6_addr.h" +#include "netif/pppif.h" ESP_EVENT_DEFINE_BASE(NETIF_PPP_STATUS); @@ -285,7 +286,7 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif) esp_netif_recv_ret_t esp_netif_lwip_ppp_input(void *ppp_ctx, void *buffer, size_t len, void *eb) { struct lwip_peer2peer_ctx * obj = ppp_ctx; - err_t ret = pppos_input_tcpip(obj->ppp, buffer, len); + err_t ret = pppos_input_tcpip_as_ram_pbuf(obj->ppp, buffer, len); if (ret != ERR_OK) { ESP_LOGE(TAG, "pppos_input_tcpip failed with %d", ret); return ESP_NETIF_OPTIONAL_RETURN_CODE(ESP_FAIL); diff --git a/components/esp_netif/lwip/netif/ppp.c b/components/esp_netif/lwip/netif/ppp.c new file mode 100644 index 0000000000..f28627520c --- /dev/null +++ b/components/esp_netif/lwip/netif/ppp.c @@ -0,0 +1,28 @@ +/* + * SPDX-FileCopyrightText: 2001-2004 Swedish Institute of Computer Science + * + * SPDX-License-Identifier: BSD-3-Clause + * + * SPDX-FileContributor: 2023 Espressif Systems (Shanghai) CO LTD + */ +#include "pppif.h" +#include "lwip/tcpip.h" + +/* + * Similar to pppos_input_tcpip() from lwip's ppp netif, but instead + * of PBUF_POOL, we use PBUF_RAM type of the pbuf we pass to the stack + */ +err_t pppos_input_tcpip_as_ram_pbuf(ppp_pcb *ppp, u8_t *s, int l) +{ + struct pbuf *p = pbuf_alloc(PBUF_RAW, l, PBUF_RAM); + if (!p) { + return ERR_MEM; + } + pbuf_take(p, s, l); + + err_t err = tcpip_inpkt(p, ppp_netif(ppp), pppos_input_sys); + if (err != ERR_OK) { + pbuf_free(p); + } + return err; +} diff --git a/components/esp_netif/lwip/netif/pppif.h b/components/esp_netif/lwip/netif/pppif.h new file mode 100644 index 0000000000..9689116559 --- /dev/null +++ b/components/esp_netif/lwip/netif/pppif.h @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2001-2004 Swedish Institute of Computer Science + * + * SPDX-License-Identifier: BSD-3-Clause + * + * SPDX-FileContributor: 2023 Espressif Systems (Shanghai) CO LTD + */ +#include "lwip/pbuf.h" +#include "netif/ppp/pppos.h" + +/** Pass received raw characters to PPPoS to be decoded through lwIP TCPIP thread. + * + * This function uses allocated packet buffers of exact size for input to TCP/IP stack + * to consume less memory in download mode, compared to the pppos_input_tcpip() from lwIP. + * (original implementation uses `PBUF_POOL`, which on ESP port uses standard malloc + * to allocate a fixed size pbuf) + * + * @param ppp PPP descriptor index, returned by pppos_create() + * @param s received data + * @param l length of received data + */ + err_t pppos_input_tcpip_as_ram_pbuf(ppp_pcb *ppp, u8_t *s, int l);