Skip to content

[modem]: Support esp-modem use without PPP #863

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions components/esp_modem/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ class Creator {
public:
Creator(std::shared_ptr<DTE> 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> dte, esp_netif_t *esp_netif, std::shared_ptr<T_Module> 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): dte(std::move(dte)), device(nullptr), netif(nullptr)
Expand Down
11 changes: 9 additions & 2 deletions components/esp_modem/src/esp_modem_netif.cpp
Original file line number Diff line number Diff line change
@@ -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
*/
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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)
{
Expand All @@ -73,12 +74,16 @@ Netif::Netif(std::shared_ptr<DTE> 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()
Expand Down Expand Up @@ -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);
}
Expand Down
Loading