Skip to content

Commit

Permalink
feat(esp_netif): PPP config option to allow disabling LCP runtime
Browse files Browse the repository at this point in the history
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 espressif/esp-protocols#287
  • Loading branch information
david-cermak authored and movsb committed Dec 1, 2023
1 parent 019984a commit 5fc10cc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
25 changes: 12 additions & 13 deletions components/esp_netif/include/esp_netif_ppp.h
Original file line number Diff line number Diff line change
@@ -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_
Expand All @@ -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
Expand Down
21 changes: 20 additions & 1 deletion components/esp_netif/lwip/esp_netif_lwip_ppp.c
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
1 change: 0 additions & 1 deletion tools/ci/check_copyright_ignore.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5fc10cc

Please sign in to comment.