Skip to content

Commit ecb7dae

Browse files
authored
Merge pull request #863 from david-cermak/feat/modem_without_ppp
[modem]: Support esp-modem use without PPP
2 parents 958ff6a + 858f857 commit ecb7dae

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

components/esp_modem/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,14 @@ menu "esp-modem"
103103
Set this to 'y' if you're making changes to the actual sources of
104104
the AT command definitions (typically in esp_modem_command_declare.inc)
105105

106+
config ESP_MODEM_USE_PPP_MODE
107+
bool "Use PPP mode"
108+
default y
109+
select LWIP_PPP_SUPPORT
110+
help
111+
If enabled, the library can use PPP netif from lwip.
112+
This is the default and most common setting.
113+
But it's possible to disable it and use only AT commands,
114+
in this case it's not required to enable LWIP_PPP_SUPPORT.
115+
106116
endmenu

components/esp_modem/include/cxx_include/esp_modem_dce_factory.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,16 @@ class Creator {
6262
public:
6363
Creator(std::shared_ptr<DTE> dte, esp_netif_t *esp_netif): dte(std::move(dte)), device(nullptr), netif(esp_netif)
6464
{
65+
#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE
6566
ESP_MODEM_THROW_IF_FALSE(netif != nullptr, "Null netif");
67+
#endif
6668
}
6769

6870
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)
6971
{
72+
#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE
7073
ESP_MODEM_THROW_IF_FALSE(netif != nullptr, "Null netif");
74+
#endif
7175
}
7276

7377
explicit Creator(std::shared_ptr<DTE> dte): dte(std::move(dte)), device(nullptr), netif(nullptr)

components/esp_modem/src/esp_modem_netif.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2021-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -14,7 +14,6 @@
1414
#include "cxx_include/esp_modem_dte.hpp"
1515
#include "esp_netif_ppp.h"
1616

17-
1817
namespace esp_modem {
1918

2019
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)
3938
return ESP_FAIL;
4039
}
4140

41+
#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE
4242
esp_err_t Netif::esp_modem_post_attach(esp_netif_t *esp_netif, void *args)
4343
{
4444
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)
6262

6363
return ESP_OK;
6464
}
65+
#endif // CONFIG_ESP_MODEM_USE_PPP_MODE
6566

6667
void Netif::receive(uint8_t *data, size_t len)
6768
{
@@ -73,12 +74,16 @@ Netif::Netif(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif) :
7374
{
7475
driver.base.netif = ppp_netif;
7576
driver.ppp = this;
77+
#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE
7678
driver.base.post_attach = esp_modem_post_attach;
7779
ESP_MODEM_THROW_IF_ERROR(esp_event_handler_register(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed, (void *) this));
80+
#endif
7881
ESP_MODEM_THROW_IF_ERROR(esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_GOT_IP, esp_netif_action_connected, ppp_netif));
7982
ESP_MODEM_THROW_IF_ERROR(
8083
esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_LOST_IP, esp_netif_action_disconnected, ppp_netif));
84+
#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE
8185
ESP_MODEM_THROW_IF_ERROR(esp_netif_attach(ppp_netif, &driver));
86+
#endif
8287
}
8388

8489
void Netif::start()
@@ -120,7 +125,9 @@ Netif::~Netif()
120125
signal.clear(PPP_STARTED);
121126
signal.wait(PPP_EXIT, 30000);
122127
}
128+
#ifdef CONFIG_ESP_MODEM_USE_PPP_MODE
123129
esp_event_handler_unregister(NETIF_PPP_STATUS, ESP_EVENT_ANY_ID, &on_ppp_changed);
130+
#endif
124131
esp_event_handler_unregister(IP_EVENT, IP_EVENT_PPP_GOT_IP, esp_netif_action_connected);
125132
esp_event_handler_unregister(IP_EVENT, IP_EVENT_PPP_LOST_IP, esp_netif_action_disconnected);
126133
}

0 commit comments

Comments
 (0)