esp-netif-ppp: support for setting ppp netif up and down

calling esp_netif_up() and esp_netif_down() was not supported if the
underlying netif wos of ppp type. Updated the code to enable setting
these interfaces up/down and registered actions in moden_netif glue for
connection/disconnection events to set the netif up/down.
This commit is contained in:
David Cermak 2020-03-04 12:41:32 +01:00 committed by bot
parent e8ff22b5fb
commit fffdc1d789
3 changed files with 18 additions and 3 deletions

View File

@ -47,8 +47,10 @@
#define ESP_NETIF_HOSTNAME_MAX_SIZE 32
/**
* @brief lwip thread safe tcpip function utility macro
* @brief lwip thread safe tcpip function utility macros
*/
#define _RUN_IN_LWIP_TASK(function, netif, param) { return esp_netif_lwip_ipc_call(function, netif, (void *)(param)); }
#define _RUN_IN_LWIP_TASK_IF_SUPPORTED(function, netif, param) \
{ \
if (netif->is_ppp_netif) { \
@ -1097,7 +1099,7 @@ static esp_err_t esp_netif_up_api(esp_netif_api_msg_t *msg)
return ESP_OK;
}
esp_err_t esp_netif_up(esp_netif_t *esp_netif) _RUN_IN_LWIP_TASK_IF_SUPPORTED(esp_netif_up_api, esp_netif, NULL)
esp_err_t esp_netif_up(esp_netif_t *esp_netif) _RUN_IN_LWIP_TASK(esp_netif_up_api, esp_netif, NULL)
static esp_err_t esp_netif_down_api(esp_netif_api_msg_t *msg)
{
@ -1131,7 +1133,7 @@ static esp_err_t esp_netif_down_api(esp_netif_api_msg_t *msg)
return ESP_OK;
}
esp_err_t esp_netif_down(esp_netif_t *esp_netif) _RUN_IN_LWIP_TASK_IF_SUPPORTED(esp_netif_down_api, esp_netif, NULL)
esp_err_t esp_netif_down(esp_netif_t *esp_netif) _RUN_IN_LWIP_TASK(esp_netif_down_api, esp_netif, NULL)
bool esp_netif_is_netif_up(esp_netif_t *esp_netif)
{

View File

@ -60,6 +60,11 @@ static void on_ppp_status_changed(ppp_pcb *pcb, int err_code, void *ctx)
case PPPERR_NONE: /* Connected */
ESP_LOGI(TAG, "Connected");
if (pcb->if4_up && !ip_addr_isany(&pppif->ip_addr)) {
esp_netif_ip_info_t *ip_info = netif->ip_info;
ip4_addr_set(&ip_info->ip, ip_2_ip4(&pppif->ip_addr));
ip4_addr_set(&ip_info->netmask, ip_2_ip4(&pppif->netmask));
ip4_addr_set(&ip_info->gw, ip_2_ip4(&pppif->gw));
evt.ip_info.ip.addr = pppif->ip_addr.u_addr.ip4.addr;
evt.ip_info.gw.addr = pppif->gw.u_addr.ip4.addr;
evt.ip_info.netmask.addr = pppif->netmask.u_addr.ip4.addr;

View File

@ -146,6 +146,14 @@ esp_err_t esp_modem_netif_set_default_handlers(void *h, esp_netif_t * esp_netif)
if (ret != ESP_OK) {
goto set_event_failed;
}
ret = esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_GOT_IP, esp_netif_action_connected, esp_netif);
if (ret != ESP_OK) {
goto set_event_failed;
}
ret = esp_event_handler_register(IP_EVENT, IP_EVENT_PPP_LOST_IP, esp_netif_action_disconnected, esp_netif);
if (ret != ESP_OK) {
goto set_event_failed;
}
return ESP_OK;
set_event_failed: