mirror of
https://github.com/espressif/esp-protocols.git
synced 2025-07-18 13:02:21 +02:00
common_connect: add support for getting multiple IPv6 addresses
* Original commit: espressif/esp-idf@63aa0d6e9c
This commit is contained in:
committed by
suren-gabrielyan-espressif
parent
9d9aac1569
commit
e24cc7d1ae
@ -175,9 +175,44 @@ menu "Example Connection Configuration"
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
config EXAMPLE_CONNECT_IPV6
|
config EXAMPLE_CONNECT_IPV6
|
||||||
bool "Obtain IPv6 link-local address"
|
bool "Obtain IPv6 address"
|
||||||
default y
|
default y
|
||||||
help
|
help
|
||||||
By default, examples will wait until IPv4 and IPv6 addresses are obtained.
|
By default, examples will wait until IPv4 and IPv6 local link addresses are obtained.
|
||||||
Disable this option if the network does not support IPv6.
|
Disable this option if the network does not support IPv6.
|
||||||
|
Choose the preferred IPv6 address type if the connection code should wait until other than
|
||||||
|
the local link address gets assigned.
|
||||||
|
|
||||||
|
if EXAMPLE_CONNECT_IPV6
|
||||||
|
choice EXAMPLE_CONNECT_PREFERRED_IPV6
|
||||||
|
prompt "Preferred IPv6 Type"
|
||||||
|
default EXAMPLE_CONNECT_IPV6_PREF_LOCAL_LINK
|
||||||
|
help
|
||||||
|
Select which kind of IPv6 address the connect logic waits for.
|
||||||
|
|
||||||
|
config EXAMPLE_CONNECT_IPV6_PREF_LOCAL_LINK
|
||||||
|
bool "Local Link Address"
|
||||||
|
help
|
||||||
|
Blocks until Local link address assigned.
|
||||||
|
|
||||||
|
config EXAMPLE_CONNECT_IPV6_PREF_GLOBAL
|
||||||
|
bool "Global Address"
|
||||||
|
help
|
||||||
|
Blocks until Global address assigned.
|
||||||
|
|
||||||
|
config EXAMPLE_CONNECT_IPV6_PREF_SITE_LOCAL
|
||||||
|
bool "Site Local Address"
|
||||||
|
help
|
||||||
|
Blocks until Site link address assigned.
|
||||||
|
|
||||||
|
config EXAMPLE_CONNECT_IPV6_PREF_UNIQUE_LOCAL
|
||||||
|
bool "Unique Local Link Address"
|
||||||
|
help
|
||||||
|
Blocks until Unique local address assigned.
|
||||||
|
|
||||||
|
endchoice
|
||||||
|
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@ -30,6 +30,17 @@
|
|||||||
|
|
||||||
#ifdef CONFIG_EXAMPLE_CONNECT_IPV6
|
#ifdef CONFIG_EXAMPLE_CONNECT_IPV6
|
||||||
#define CONNECTED_BITS (GOT_IPV4_BIT | GOT_IPV6_BIT)
|
#define CONNECTED_BITS (GOT_IPV4_BIT | GOT_IPV6_BIT)
|
||||||
|
|
||||||
|
#if defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_LOCAL_LINK)
|
||||||
|
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_LINK_LOCAL
|
||||||
|
#elif defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_GLOBAL)
|
||||||
|
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_GLOBAL
|
||||||
|
#elif defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_SITE_LOCAL)
|
||||||
|
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_SITE_LOCAL
|
||||||
|
#elif defined(CONFIG_EXAMPLE_CONNECT_IPV6_PREF_UNIQUE_LOCAL)
|
||||||
|
#define EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE ESP_IP6_ADDR_IS_UNIQUE_LOCAL
|
||||||
|
#endif // if-elif CONFIG_EXAMPLE_CONNECT_IPV6_PREF_...
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define CONNECTED_BITS (GOT_IPV4_BIT)
|
#define CONNECTED_BITS (GOT_IPV4_BIT)
|
||||||
#endif
|
#endif
|
||||||
@ -41,6 +52,16 @@ static esp_netif_t *s_example_esp_netif = NULL;
|
|||||||
|
|
||||||
#ifdef CONFIG_EXAMPLE_CONNECT_IPV6
|
#ifdef CONFIG_EXAMPLE_CONNECT_IPV6
|
||||||
static esp_ip6_addr_t s_ipv6_addr;
|
static esp_ip6_addr_t s_ipv6_addr;
|
||||||
|
|
||||||
|
/* types of ipv6 addresses to be displayed on ipv6 events */
|
||||||
|
static const char *s_ipv6_addr_types[] = {
|
||||||
|
"ESP_IP6_ADDR_IS_UNKNOWN",
|
||||||
|
"ESP_IP6_ADDR_IS_GLOBAL",
|
||||||
|
"ESP_IP6_ADDR_IS_LINK_LOCAL",
|
||||||
|
"ESP_IP6_ADDR_IS_SITE_LOCAL",
|
||||||
|
"ESP_IP6_ADDR_IS_UNIQUE_LOCAL",
|
||||||
|
"ESP_IP6_ADDR_IS_IPV4_MAPPED_IPV6"
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char *TAG = "example_connect";
|
static const char *TAG = "example_connect";
|
||||||
@ -70,11 +91,12 @@ static void on_got_ipv6(void *arg, esp_event_base_t event_base,
|
|||||||
ESP_LOGD(TAG, "Got IPv6 from another netif: ignored");
|
ESP_LOGD(TAG, "Got IPv6 from another netif: ignored");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "Got IPv6 event!");
|
esp_ip6_addr_type_t ipv6_type = esp_netif_ip6_get_addr_type(&event->ip6_info.ip);
|
||||||
|
ESP_LOGI(TAG, "Got IPv6 address: " IPV6STR ", type: %s", IPV62STR(event->ip6_info.ip), s_ipv6_addr_types[ipv6_type]);
|
||||||
|
if (ipv6_type == EXAMPLE_CONNECT_PREFERRED_IPV6_TYPE) {
|
||||||
memcpy(&s_ipv6_addr, &event->ip6_info.ip, sizeof(s_ipv6_addr));
|
memcpy(&s_ipv6_addr, &event->ip6_info.ip, sizeof(s_ipv6_addr));
|
||||||
xEventGroupSetBits(s_connect_event_group, GOT_IPV6_BIT);
|
xEventGroupSetBits(s_connect_event_group, GOT_IPV6_BIT);
|
||||||
ESP_LOGI(TAG, "IPv6 address: " IPV6STR ", index: %d, type: %d", IPV62STR(s_ipv6_addr), event->ip_index, esp_ip6_get_addr_type(&s_ipv6_addr));
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CONFIG_EXAMPLE_CONNECT_IPV6
|
#endif // CONFIG_EXAMPLE_CONNECT_IPV6
|
||||||
|
Reference in New Issue
Block a user