From 18ff62017a24939ff7d3b6cac696dc7af4f49fd3 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Wed, 4 Oct 2023 17:35:57 +0200 Subject: [PATCH 1/4] feat(lwip): Add support for PPP server Added support PPP_SERVER option in LWIP Added support for configuring preferred addresses of PPP endpoints. --- components/esp_netif/include/esp_netif_ppp.h | 4 +++ .../esp_netif/lwip/esp_netif_lwip_ppp.c | 31 ++++++++++++++++++- components/lwip/Kconfig | 7 +++++ components/lwip/port/include/lwipopts.h | 5 +++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/components/esp_netif/include/esp_netif_ppp.h b/components/esp_netif/include/esp_netif_ppp.h index c9856c6206..d3d576c463 100644 --- a/components/esp_netif/include/esp_netif_ppp.h +++ b/components/esp_netif/include/esp_netif_ppp.h @@ -28,6 +28,10 @@ typedef struct esp_netif_ppp_config { * The current session must be closed, settings will be applied upon connecting. * */ #endif // CONFIG_LWIP_ENABLE_LCP_ECHO +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + uint32_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ + uint32_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ +#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT } esp_netif_ppp_config_t; /** @brief event id offset for PHASE related events diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index a2490d897a..3ad8e9bc39 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -33,6 +33,10 @@ typedef struct lwip_peer2peer_ctx { bool ppp_error_event_enabled; #ifdef CONFIG_LWIP_ENABLE_LCP_ECHO bool ppp_lcp_echo_disabled; +#endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + uint32_t ppp_our_ip4_addr; // our desired IP (0 if no preference) + uint32_t ppp_their_ip4_addr; // their desired IP (0 if no preference) #endif ppp_pcb *ppp; } lwip_peer2peer_ctx_t; @@ -246,9 +250,25 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif) ppp_ctx->ppp->settings.lcp_echo_fails = LCP_MAXECHOFAILS; } #endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + if (ppp_ctx->ppp_our_ip4_addr != 0) { + // Set our preferred address, and accept the remote + ppp_ctx->ppp->ipcp_wantoptions.ouraddr = ppp_ctx->ppp_our_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.accept_remote = 1; + } + if (ppp_ctx->ppp_their_ip4_addr != 0) { + // Set their preferred address, and accept the local + ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.accept_local = 1; + } +#endif // CONFIG_LWIP_PPP_SERVER_SUPPORT ESP_LOGD(TAG, "%s: Starting PPP connection: %p", __func__, ppp_ctx->ppp); +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + esp_err_t err = ppp_listen(ppp_ctx->ppp); +#else err_t err = ppp_connect(ppp_ctx->ppp, 0); +#endif if (err != ESP_OK) { ESP_LOGE(TAG, "%s: PPP connection cannot be started", __func__); if (ppp_ctx->ppp_error_event_enabled) { @@ -303,6 +323,10 @@ esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_confi obj->ppp_error_event_enabled = config->ppp_error_event_enabled; #ifdef CONFIG_LWIP_ENABLE_LCP_ECHO obj->ppp_lcp_echo_disabled = config->ppp_lcp_echo_disabled; +#endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + obj->ppp_our_ip4_addr = config->ppp_our_ip4_addr; + obj->ppp_their_ip4_addr = config->ppp_their_ip4_addr; #endif return ESP_OK; } @@ -319,5 +343,10 @@ esp_err_t esp_netif_ppp_get_params(esp_netif_t *netif, esp_netif_ppp_config_t *c #ifdef CONFIG_LWIP_ENABLE_LCP_ECHO config->ppp_lcp_echo_disabled = obj->ppp_lcp_echo_disabled; #endif +#ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT + config->ppp_our_ip4_addr = obj->ppp_our_ip4_addr; + config->ppp_their_ip4_addr = obj->ppp_their_ip4_addr; +#endif + return ESP_OK; } diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 3132fae6b6..22a2478208 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -941,6 +941,13 @@ menu "LWIP" help Enable Microsoft Point-to-Point Encryption (MPPE) support + config LWIP_PPP_SERVER_SUPPORT + bool "Enable PPP server support" + depends on LWIP_PPP_SUPPORT + default n + help + Enable to use PPP server + config LWIP_ENABLE_LCP_ECHO bool "Enable LCP ECHO" depends on LWIP_PPP_SUPPORT diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index c3687319ab..b1e6e339b8 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -1082,6 +1082,11 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) */ #define MPPE_SUPPORT CONFIG_LWIP_PPP_MPPE_SUPPORT +/** + * PPP_SERVER==1: Enable PPP server support (waiting for incoming PPP session). + */ +#define PPP_SERVER CONFIG_LWIP_PPP_SERVER_SUPPORT + /** * PPP_MAXIDLEFLAG: Max Xmit idle time (in ms) before resend flag char. * TODO: If PPP_MAXIDLEFLAG > 0 and next package is send during PPP_MAXIDLEFLAG time, From 63e8e01646046536af7173e26d3ad419d1936348 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 8 Jan 2024 09:42:29 +0100 Subject: [PATCH 2/4] feat(lwip): Added PPP config option to control VJ header compression --- components/lwip/Kconfig | 10 ++++++++++ components/lwip/port/include/lwipopts.h | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/components/lwip/Kconfig b/components/lwip/Kconfig index 22a2478208..0279c8c2e7 100644 --- a/components/lwip/Kconfig +++ b/components/lwip/Kconfig @@ -948,6 +948,16 @@ menu "LWIP" help Enable to use PPP server + config LWIP_PPP_VJ_HEADER_COMPRESSION + bool "Enable VJ IP Header compression" + depends on LWIP_PPP_SUPPORT + default y + help + Enable support for VJ header compression. + Please disable this if you're using NAPT on PPP interface, + since the compressed IP header might not be correctly interpreted + in NAT causing the compressed packet to be dropped. + config LWIP_ENABLE_LCP_ECHO bool "Enable LCP ECHO" depends on LWIP_PPP_SUPPORT diff --git a/components/lwip/port/include/lwipopts.h b/components/lwip/port/include/lwipopts.h index b1e6e339b8..516fc78dd2 100644 --- a/components/lwip/port/include/lwipopts.h +++ b/components/lwip/port/include/lwipopts.h @@ -1087,6 +1087,11 @@ static inline uint32_t timeout_from_offered(uint32_t lease, uint32_t min) */ #define PPP_SERVER CONFIG_LWIP_PPP_SERVER_SUPPORT +/** + * VJ_SUPPORT==1: Support VJ header compression. + */ +#define VJ_SUPPORT CONFIG_LWIP_PPP_VJ_HEADER_COMPRESSION + /** * PPP_MAXIDLEFLAG: Max Xmit idle time (in ms) before resend flag char. * TODO: If PPP_MAXIDLEFLAG > 0 and next package is send during PPP_MAXIDLEFLAG time, From d70716188168d4bc2cab95089eb45c507726b8c9 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Mon, 8 Jan 2024 09:47:49 +0100 Subject: [PATCH 3/4] fix(lwip): esp_netif supports esp_netif_get_netif_impl() for PPP --- components/esp_netif/include/esp_netif_net_stack.h | 7 ++----- components/esp_netif/lwip/esp_netif_lwip.c | 3 +-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/components/esp_netif/include/esp_netif_net_stack.h b/components/esp_netif/include/esp_netif_net_stack.h index 42ab134935..82d3981362 100644 --- a/components/esp_netif/include/esp_netif_net_stack.h +++ b/components/esp_netif/include/esp_netif_net_stack.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -29,10 +29,7 @@ extern "C" { esp_netif_t* esp_netif_get_handle_from_netif_impl(void *dev); /** - * @brief Returns network stack specific implementation handle (if supported) - * - * Note that it is not supported to acquire PPP netif impl pointer and - * this function will return NULL for esp_netif instances configured to PPP mode + * @brief Returns network stack specific implementation handle * * @param[in] esp_netif Handle to esp-netif instance * diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index cf33078d32..7c48691089 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -495,8 +495,7 @@ esp_netif_t* esp_netif_get_handle_from_netif_impl(void *dev) void* esp_netif_get_netif_impl(esp_netif_t *esp_netif) { - // get impl ptr only for vanilla lwip impl (ppp_pcb not supported) - if (esp_netif && !ESP_NETIF_IS_POINT2POINT_TYPE(esp_netif, PPP_LWIP_NETIF)) { + if (esp_netif) { return esp_netif->lwip_netif; } return NULL; From 73102c60efddcf0290f9fb7186fd380dca66bee8 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Fri, 19 Jan 2024 17:47:55 +0100 Subject: [PATCH 4/4] fix(lwip): Used dedicated IP4 address type --- components/esp_netif/include/esp_netif_ppp.h | 4 ++-- components/esp_netif/lwip/esp_netif_lwip_ppp.c | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/esp_netif/include/esp_netif_ppp.h b/components/esp_netif/include/esp_netif_ppp.h index d3d576c463..ffdf4c6743 100644 --- a/components/esp_netif/include/esp_netif_ppp.h +++ b/components/esp_netif/include/esp_netif_ppp.h @@ -29,8 +29,8 @@ typedef struct esp_netif_ppp_config { * */ #endif // CONFIG_LWIP_ENABLE_LCP_ECHO #ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT - uint32_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ - uint32_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ + esp_ip4_addr_t ppp_our_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ + esp_ip4_addr_t ppp_their_ip4_addr; /**< Set our preferred address, typically used when we're the PPP server */ #endif // CONFIG_LWIP_PPP_SERVER_SUPPORT } esp_netif_ppp_config_t; diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index 3ad8e9bc39..db5e9f44f5 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -35,8 +35,8 @@ typedef struct lwip_peer2peer_ctx { bool ppp_lcp_echo_disabled; #endif #ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT - uint32_t ppp_our_ip4_addr; // our desired IP (0 if no preference) - uint32_t ppp_their_ip4_addr; // their desired IP (0 if no preference) + esp_ip4_addr_t ppp_our_ip4_addr; // our desired IP (IPADDR_ANY if no preference) + esp_ip4_addr_t ppp_their_ip4_addr; // their desired IP (IPADDR_ANY if no preference) #endif ppp_pcb *ppp; } lwip_peer2peer_ctx_t; @@ -251,14 +251,14 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif) } #endif #ifdef CONFIG_LWIP_PPP_SERVER_SUPPORT - if (ppp_ctx->ppp_our_ip4_addr != 0) { + if (ppp_ctx->ppp_our_ip4_addr.addr != IPADDR_ANY) { // Set our preferred address, and accept the remote - ppp_ctx->ppp->ipcp_wantoptions.ouraddr = ppp_ctx->ppp_our_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.ouraddr = ppp_ctx->ppp_our_ip4_addr.addr; ppp_ctx->ppp->ipcp_wantoptions.accept_remote = 1; } - if (ppp_ctx->ppp_their_ip4_addr != 0) { + if (ppp_ctx->ppp_their_ip4_addr.addr != IPADDR_ANY) { // Set their preferred address, and accept the local - ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr; + ppp_ctx->ppp->ipcp_wantoptions.hisaddr = ppp_ctx->ppp_their_ip4_addr.addr; ppp_ctx->ppp->ipcp_wantoptions.accept_local = 1; } #endif // CONFIG_LWIP_PPP_SERVER_SUPPORT