diff --git a/components/esp_netif/include/esp_netif.h b/components/esp_netif/include/esp_netif.h index fc0cc2740..9c8057f9b 100644 --- a/components/esp_netif/include/esp_netif.h +++ b/components/esp_netif/include/esp_netif.h @@ -613,6 +613,22 @@ esp_err_t esp_netif_create_ip6_linklocal(esp_netif_t *esp_netif); */ esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6); +/** + * @brief Get interface global IPv6 address + * + * If the specified interface is up and a preferred global IPv6 address + * has been created for the interface, return a copy of it. + * + * @param[in] esp_netif Handle to esp-netif instance + * @param[out] if_ip6 IPv6 information will be returned in this argument if successful. + * + * @return + * - ESP_OK + * - ESP_FAIL If interface is down, does not have a global IPv6 address, + * or the global IPv6 address is not a preferred address. + */ +esp_err_t esp_netif_get_ip6_global(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6); + /** * @brief Sets IPv4 address to the specified octets * diff --git a/components/esp_netif/loopback/esp_netif_loopback.c b/components/esp_netif/loopback/esp_netif_loopback.c index a434ee960..bbe0d3592 100644 --- a/components/esp_netif/loopback/esp_netif_loopback.c +++ b/components/esp_netif/loopback/esp_netif_loopback.c @@ -412,6 +412,11 @@ esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if return ESP_ERR_NOT_SUPPORTED; } +esp_err_t esp_netif_get_ip6_global(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6) +{ + return ESP_ERR_NOT_SUPPORTED; +} + esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif) { return esp_netif->flags; diff --git a/components/esp_netif/lwip/esp_netif_lwip.c b/components/esp_netif/lwip/esp_netif_lwip.c index 56d238adc..195ddd3ff 100644 --- a/components/esp_netif/lwip/esp_netif_lwip.c +++ b/components/esp_netif/lwip/esp_netif_lwip.c @@ -1396,6 +1396,29 @@ esp_err_t esp_netif_get_ip6_linklocal(esp_netif_t *esp_netif, esp_ip6_addr_t *if return ESP_OK; } +esp_err_t esp_netif_get_ip6_global(esp_netif_t *esp_netif, esp_ip6_addr_t *if_ip6) +{ + ESP_LOGD(TAG, "%s esp-netif:%p", __func__, esp_netif); + + if (esp_netif == NULL || if_ip6 == NULL) { + return ESP_ERR_ESP_NETIF_INVALID_PARAMS; + } + + int i; + struct netif *p_netif = esp_netif->lwip_netif; + + if (p_netif != NULL && netif_is_up(p_netif)) { + for (i = 1; i < LWIP_IPV6_NUM_ADDRESSES; i++) { + if (ip6_addr_ispreferred(netif_ip6_addr_state(p_netif, i))) { + memcpy(if_ip6, &p_netif->ip6_addr[i], sizeof(ip6_addr_t)); + return ESP_OK; + } + } + } + + return ESP_FAIL; +} + esp_netif_flags_t esp_netif_get_flags(esp_netif_t *esp_netif) { return esp_netif->flags; diff --git a/components/lwip/lwip b/components/lwip/lwip index b4eaf11fe..066ffe0ab 160000 --- a/components/lwip/lwip +++ b/components/lwip/lwip @@ -1 +1 @@ -Subproject commit b4eaf11fe5e980a2d9b655e6617d4163c11465ec +Subproject commit 066ffe0abb83eee47808bf77c1bcfef51ad077fe diff --git a/components/tcpip_adapter/include/tcpip_adapter.h b/components/tcpip_adapter/include/tcpip_adapter.h index db23a2ae6..a30e946e4 100644 --- a/components/tcpip_adapter/include/tcpip_adapter.h +++ b/components/tcpip_adapter/include/tcpip_adapter.h @@ -60,6 +60,15 @@ esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i */ esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6); +/** + * @brief Translates to esp_netif_get_ip6_global + * + * @param tcpip_if Interface type corresponding to appropriate instance of esp-netif + * @param if_ip6 See esp_netif_get_ip6_global + * @return See esp_netif_get_ip6_global + */ +esp_err_t tcpip_adapter_get_ip6_global(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6); + /** * @brief`Translates to esp_netif_dhcpc_get_status * @param tcpip_if Interface type corresponding to appropriate instance of esp-netif diff --git a/components/tcpip_adapter/tcpip_adapter_compat.c b/components/tcpip_adapter/tcpip_adapter_compat.c index 7a81fbb13..cd970f4c8 100644 --- a/components/tcpip_adapter/tcpip_adapter_compat.c +++ b/components/tcpip_adapter/tcpip_adapter_compat.c @@ -200,6 +200,11 @@ esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_ return esp_netif_get_ip6_linklocal(netif_from_if(tcpip_if), (esp_ip6_addr_t*)if_ip6); } +esp_err_t tcpip_adapter_get_ip6_global(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6) +{ + return esp_netif_get_ip6_global(netif_from_if(tcpip_if), (esp_ip6_addr_t*)if_ip6); +} + esp_err_t tcpip_adapter_dhcpc_get_status(tcpip_adapter_if_t tcpip_if, tcpip_adapter_dhcp_status_t *status) { return esp_netif_dhcpc_get_status(netif_from_if(tcpip_if), status);