From 858f85706d319e0ccba766f5481fcf1f852db0e8 Mon Sep 17 00:00:00 2001 From: David Cermak Date: Thu, 14 Aug 2025 17:29:26 +0200 Subject: [PATCH] feat(modem): Support esp-modem use without PPP Closes https://github.com/espressif/esp-protocols/issues/851 --- components/esp_modem/Kconfig | 10 ++++++++++ .../include/cxx_include/esp_modem_dce_factory.hpp | 4 ++++ components/esp_modem/src/esp_modem_netif.cpp | 11 +++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/components/esp_modem/Kconfig b/components/esp_modem/Kconfig index 2ab972935e..dd650f936a 100644 --- a/components/esp_modem/Kconfig +++ b/components/esp_modem/Kconfig @@ -103,4 +103,14 @@ menu "esp-modem" Set this to 'y' if you're making changes to the actual sources of the AT command definitions (typically in esp_modem_command_declare.inc) + config ESP_MODEM_USE_PPP_MODE + bool "Use PPP mode" + default y + select LWIP_PPP_SUPPORT + help + If enabled, the library can use PPP netif from lwip. + This is the default and most common setting. + But it's possible to disable it and use only AT commands, + in this case it's not required to enable LWIP_PPP_SUPPORT. + endmenu diff --git a/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp b/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp index faa4b179e7..8c86eb8a11 100644 --- a/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp +++ b/components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp @@ -62,12 +62,16 @@ class Creator { public: Creator(std::shared_ptr dte, esp_netif_t *esp_netif): dte(std::move(dte)), device(nullptr), netif(esp_netif) { +#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE ESP_MODEM_THROW_IF_FALSE(netif != nullptr, "Null netif"); +#endif } Creator(std::shared_ptr dte, esp_netif_t *esp_netif, std::shared_ptr dev): dte(std::move(dte)), device(std::move(dev)), netif(esp_netif) { +#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE ESP_MODEM_THROW_IF_FALSE(netif != nullptr, "Null netif"); +#endif } explicit Creator(std::shared_ptr dte): dte(std::move(dte)), device(nullptr), netif(nullptr) diff --git a/components/esp_modem/src/esp_modem_netif.cpp b/components/esp_modem/src/esp_modem_netif.cpp index 3bcb158e75..1220853fcb 100644 --- a/components/esp_modem/src/esp_modem_netif.cpp +++ b/components/esp_modem/src/esp_modem_netif.cpp @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -14,7 +14,6 @@ #include "cxx_include/esp_modem_dte.hpp" #include "esp_netif_ppp.h" - namespace esp_modem { void Netif::on_ppp_changed(void *arg, esp_event_base_t event_base, @@ -39,6 +38,7 @@ esp_err_t Netif::esp_modem_dte_transmit(void *h, void *buffer, size_t len) return ESP_FAIL; } +#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE esp_err_t Netif::esp_modem_post_attach(esp_netif_t *esp_netif, void *args) { auto d = (ppp_netif_driver *) args; @@ -62,6 +62,7 @@ esp_err_t Netif::esp_modem_post_attach(esp_netif_t *esp_netif, void *args) return ESP_OK; } +#endif // CONFIG_ESP_MODEM_USE_PPP_MODE void Netif::receive(uint8_t *data, size_t len) { @@ -73,12 +74,16 @@ Netif::Netif(std::shared_ptr e, esp_netif_t *ppp_netif) : { driver.base.netif = ppp_netif; driver.ppp = this; +#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE driver.base.post_attach = esp_modem_post_attach; ESP_MODEM_THROW_IF_ERROR(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, (void *) this)); +#endif ESP_MODEM_THROW_IF_ERROR(esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_GOT_IP, esp_netif_action_connected, ppp_netif)); ESP_MODEM_THROW_IF_ERROR( esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_LOST_IP, esp_netif_action_disconnected, ppp_netif)); +#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE ESP_MODEM_THROW_IF_ERROR(esp_netif_attach(ppp_netif, &driver)); +#endif } void Netif::start() @@ -120,7 +125,9 @@ Netif::~Netif() signal.clear(PPP_STARTED); signal.wait(PPP_EXIT, 30000); } +#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE esp_event_handler_unregister(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed); +#endif esp_event_handler_unregister(IP_EVENT, IP_EVENT_PPP_GOT_IP, esp_netif_action_connected); esp_event_handler_unregister(IP_EVENT, IP_EVENT_PPP_LOST_IP, esp_netif_action_disconnected); }