diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 3d3c22a58c..799b4f78bd 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -51,8 +51,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) { \ @@ -144,6 +146,8 @@ static esp_netif_t* esp_netif_is_active(esp_netif_t *arg) * @brief This function sets default netif no matter which implementation used * * @param esp_netif handle to network interface + * + * @note: This function must be called from lwip thread */ static void esp_netif_set_default_netif(esp_netif_t *esp_netif) { @@ -155,14 +159,17 @@ static void esp_netif_set_default_netif(esp_netif_t *esp_netif) } /** - * @brief This function sets default routing netif based on priorities of all interfaces which are up - * @param esp_netif current interface which just updated state - * @param action updating action (on-off) - * - * @note: This function must be called from lwip thread + * @brief tcpip thread version of esp_netif_update_default_netif * + * @note This function and all functions called from this must be called from lwip task context */ -static void esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_action_t action) { +static esp_err_t esp_netif_update_default_netif_lwip(esp_netif_api_msg_t *msg) +{ + esp_netif_t *esp_netif = msg->esp_netif; + esp_netif_action_t action = (esp_netif_action_t)msg->data; + + ESP_LOGD(TAG, "%s %p", __func__, esp_netif); + switch (action) { case ESP_NETIF_STARTED: { @@ -204,6 +211,18 @@ static void esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_act } break; } + return ESP_OK; +} + +/** + * @brief This function sets default routing netif based on priorities of all interfaces which are up + * + * @param esp_netif current interface which just updated state + * @param action updating action (on-off) + */ +static esp_err_t esp_netif_update_default_netif(esp_netif_t *esp_netif, esp_netif_action_t action) +{ + return esp_netif_lwip_ipc_call(esp_netif_update_default_netif_lwip, esp_netif, (void*)action); } void esp_netif_set_ip4_addr(esp_ip4_addr_t *addr, uint8_t a, uint8_t b, uint8_t c, uint8_t d) @@ -1104,7 +1123,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) { @@ -1141,7 +1160,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) { diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.c b/components/esp_netif/lwip/esp_netif_lwip_ppp.c index 68f6205d46..95f7201026 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.c +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.c @@ -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; @@ -248,7 +253,7 @@ esp_err_t esp_netif_ppp_set_auth(esp_netif_t *netif, esp_netif_auth_type_t autht void esp_netif_ppp_set_default_netif(lwip_ppp_ctx_t* ppp_ctx) { - pppapi_set_default(ppp_ctx->ppp); + ppp_set_default(ppp_ctx->ppp); } lwip_ppp_ctx_t* esp_netif_new_ppp(esp_netif_t *esp_netif, const esp_netif_netstack_config_t *esp_netif_stack_config) diff --git a/components/esp_netif/lwip/esp_netif_lwip_ppp.h b/components/esp_netif/lwip/esp_netif_lwip_ppp.h index 25047f795e..8b306e3454 100644 --- a/components/esp_netif/lwip/esp_netif_lwip_ppp.h +++ b/components/esp_netif/lwip/esp_netif_lwip_ppp.h @@ -70,6 +70,8 @@ esp_err_t esp_netif_stop_ppp(lwip_ppp_ctx_t *ppp); /** * @brief Sets default netif for routing priority config * + * @note: This function must be called from lwip thread + * */ void esp_netif_ppp_set_default_netif(lwip_ppp_ctx_t* ppp_ctx); diff --git a/examples/protocols/pppos_client/components/modem/src/esp_modem_netif.c b/examples/protocols/pppos_client/components/modem/src/esp_modem_netif.c index a926d8fe1d..e04e822086 100644 --- a/examples/protocols/pppos_client/components/modem/src/esp_modem_netif.c +++ b/examples/protocols/pppos_client/components/modem/src/esp_modem_netif.c @@ -145,6 +145,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: