Skip to content

Commit

Permalink
fix(modem): Fix netif data race causing PPP startup delays
Browse files Browse the repository at this point in the history
Removes PPP_started signal on reception, since lwip handles data
reception if the netif is up/down (which we correctly set in start()
stop() methods)

Closes #308
  • Loading branch information
david-cermak committed Aug 28, 2023
1 parent cb6e03a commit c8c0507
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
3 changes: 2 additions & 1 deletion components/esp_modem/include/cxx_include/esp_modem_netif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,10 @@ class Netif {
*/
void stop();

private:
void receive(uint8_t *data, size_t len);

private:

static esp_err_t esp_modem_dte_transmit(void *h, void *buffer, size_t len);

static esp_err_t esp_modem_post_attach(esp_netif_t *esp_netif, void *args);
Expand Down
11 changes: 9 additions & 2 deletions components/esp_modem/src/esp_modem_dce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ static bool exit_data(DTE &dte, ModuleIf &device, Netif &netif)
netif.stop();
auto signal = std::make_shared<SignalGroup>();
std::weak_ptr<SignalGroup> weak_signal = signal;
dte.set_read_cb([weak_signal](uint8_t *data, size_t len) -> bool {
dte.set_read_cb([&netif, weak_signal](uint8_t *data, size_t len) -> bool {
// post the transitioning data to the network layers if it contains PPP SOF marker
if (memchr(data, 0x7E, len))
{
ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data (PPP)", data, len, ESP_LOG_DEBUG);
netif.receive(data, len);
}
// treat the transitioning data as a textual message if it contains a newline char
if (memchr(data, '\n', len))
{
ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data", data, len, ESP_LOG_DEBUG);
ESP_LOG_BUFFER_HEXDUMP("esp-modem: debug_data (CMD)", data, len, ESP_LOG_DEBUG);
const auto pass = std::list<std::string_view>({"NO CARRIER", "DISCONNECTED"});
std::string_view response((char *) data, len);
for (auto &it : pass)
Expand Down
6 changes: 2 additions & 4 deletions components/esp_modem/src/esp_modem_netif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ esp_err_t Netif::esp_modem_post_attach(esp_netif_t *esp_netif, void *args)

void Netif::receive(uint8_t *data, size_t len)
{
if (signal.is_any(PPP_STARTED)) {
esp_netif_receive(driver.base.netif, data, len, nullptr);
}
esp_netif_receive(driver.base.netif, data, len, nullptr);
}

Netif::Netif(std::shared_ptr<DTE> e, esp_netif_t *ppp_netif) :
Expand All @@ -89,8 +87,8 @@ void Netif::start()
receive(data, len);
return true;
});
esp_netif_action_start(driver.base.netif, nullptr, 0, nullptr);
signal.set(PPP_STARTED);
esp_netif_action_start(driver.base.netif, nullptr, 0, nullptr);
}

void Netif::stop()
Expand Down

0 comments on commit c8c0507

Please sign in to comment.