From 5fc10cc4d06d4ad743c12a0ae0916050d46a62a3 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Tue, 19 Sep 2023 15:58:22 +0200 Subject: [PATCH] feat(esp_netif): PPP config option to allow disabling LCP runtime If LCP keepalive mechanism is enabled in menuconfig, it's statically configured on creation of an interface and cannot be changed runtime. In some cases it's useful to relax LCP criteria during runtime operation, for example before initiating OTA. This config option allows for disabling already enabled LCP echo (this setting becomes effective after reconnecting, i.e. initializing a new session) Closes https://github.com/espressif/esp-protocols/issues/287 --- components/esp_netif/include/esp_netif_ppp.h | 25 +++++++++---------- .../esp_netif/lwip/esp_netif_lwip_ppp.c | 21 +++++++++++++++- tools/ci/check_copyright_ignore.txt | 1 - 3 files changed, 32 insertions(+), 15 deletions(-) diff --git a/components/esp_netif/include/esp_netif_ppp.h b/components/esp_netif/include/esp_netif_ppp.h index 159388e80ea..c9856c6206f 100644 --- a/components/esp_netif/include/esp_netif_ppp.h +++ b/components/esp_netif/include/esp_netif_ppp.h @@ -1,16 +1,8 @@ -// Copyright 2019 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// 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. +/* + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ // #ifndef _ESP_NETIF_PPP_H_ @@ -29,6 +21,13 @@ ESP_EVENT_DECLARE_BASE(NETIF_PPP_STATUS); typedef struct esp_netif_ppp_config { bool ppp_phase_event_enabled; /**< Enables events coming from PPP PHASE change */ bool ppp_error_event_enabled; /**< Enables events from main PPP state machine producing errors */ +#ifdef CONFIG_LWIP_ENABLE_LCP_ECHO + bool ppp_lcp_echo_disabled; /**< Allows to temporarily disable LCP keepalive (runtime, if enabled compile time) + * When LCP echo is enabled in menuconfig, this option can be used to override the setting, + * if we have to relax LCP keepalive criteria during runtime operation, for example before OTA update. + * The current session must be closed, settings will be applied upon connecting. + * */ +#endif // CONFIG_LWIP_ENABLE_LCP_ECHO } 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 4bf697bc278..b9a3846c524 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-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -31,6 +31,9 @@ typedef struct lwip_peer2peer_ctx { // PPP specific fields follow bool ppp_phase_event_enabled; bool ppp_error_event_enabled; +#ifdef CONFIG_LWIP_ENABLE_LCP_ECHO + bool ppp_lcp_echo_disabled; +#endif ppp_pcb *ppp; } lwip_peer2peer_ctx_t; @@ -257,6 +260,16 @@ esp_err_t esp_netif_start_ppp(esp_netif_t *esp_netif) lwip_peer2peer_ctx_t *ppp_ctx = (lwip_peer2peer_ctx_t *)netif_related; assert(ppp_ctx->base.netif_type == PPP_LWIP_NETIF); +#ifdef CONFIG_LWIP_ENABLE_LCP_ECHO + if (ppp_ctx->ppp_lcp_echo_disabled) { + ppp_ctx->ppp->settings.lcp_echo_interval = 0; + ppp_ctx->ppp->settings.lcp_echo_fails = 0; + } else { + ppp_ctx->ppp->settings.lcp_echo_interval = LCP_ECHOINTERVAL; + ppp_ctx->ppp->settings.lcp_echo_fails = LCP_MAXECHOFAILS; + } +#endif + ESP_LOGD(TAG, "%s: Starting PPP connection: %p", __func__, ppp_ctx->ppp); esp_err_t err = pppapi_connect(ppp_ctx->ppp, 0); if (err != ESP_OK) { @@ -311,6 +324,9 @@ esp_err_t esp_netif_ppp_set_params(esp_netif_t *netif, const esp_netif_ppp_confi struct lwip_peer2peer_ctx *obj = (struct lwip_peer2peer_ctx *)netif->related_data; obj->ppp_phase_event_enabled = config->ppp_phase_event_enabled; 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 return ESP_OK; } @@ -323,5 +339,8 @@ esp_err_t esp_netif_ppp_get_params(esp_netif_t *netif, esp_netif_ppp_config_t *c struct lwip_peer2peer_ctx *obj = (struct lwip_peer2peer_ctx *)netif->related_data; config->ppp_phase_event_enabled = obj->ppp_phase_event_enabled; config->ppp_error_event_enabled = obj->ppp_error_event_enabled; +#ifdef CONFIG_LWIP_ENABLE_LCP_ECHO + config->ppp_lcp_echo_disabled = obj->ppp_lcp_echo_disabled; +#endif return ESP_OK; } diff --git a/tools/ci/check_copyright_ignore.txt b/tools/ci/check_copyright_ignore.txt index 9405c40e159..0c64d0b8412 100644 --- a/tools/ci/check_copyright_ignore.txt +++ b/tools/ci/check_copyright_ignore.txt @@ -422,7 +422,6 @@ components/esp_hid/src/esp_hid_common.c components/esp_local_ctrl/src/esp_local_ctrl_handler.c components/esp_local_ctrl/src/esp_local_ctrl_priv.h components/esp_local_ctrl/src/esp_local_ctrl_transport_ble.c -components/esp_netif/include/esp_netif_ppp.h components/esp_phy/test/test_phy_rtc.c components/esp_pm/include/esp_private/pm_trace.h components/esp_rom/esp32/ld/esp32.rom.api.ld