esp-netif: support for ipv6 addr types and indices
This commit is contained in:
parent
94ded5fb2f
commit
56725fa678
4 changed files with 43 additions and 3 deletions
|
@ -100,6 +100,24 @@ typedef struct _ip_addr {
|
|||
uint8_t type;
|
||||
} esp_ip_addr_t;
|
||||
|
||||
typedef enum {
|
||||
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
|
||||
} esp_ip6_addr_type_t;
|
||||
|
||||
/**
|
||||
* @brief Get the IPv6 address type
|
||||
*
|
||||
* @param[in] ip6_addr IPv6 type
|
||||
*
|
||||
* @return IPv6 type in form of enum esp_ip6_addr_type_t
|
||||
*/
|
||||
esp_ip6_addr_type_t esp_netif_ip6_get_addr_type(esp_ip6_addr_t* ip6_addr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -120,6 +120,7 @@ typedef struct {
|
|||
int if_index; /*!< Interface index for which the event is received (left for legacy compilation) */
|
||||
esp_netif_t *esp_netif; /*!< Pointer to corresponding esp-netif object */
|
||||
esp_netif_ip6_info_t ip6_info; /*!< IPv6 address of the interface */
|
||||
int ip_index; /*!< IPv6 address index */
|
||||
} ip_event_got_ip6_t;
|
||||
|
||||
/** Event structure for IP_EVENT_AP_STAIPASSIGNED event */
|
||||
|
|
|
@ -1370,7 +1370,26 @@ esp_err_t esp_netif_get_dns_info(esp_netif_t *esp_netif, esp_netif_dns_type_t ty
|
|||
return esp_netif_lwip_ipc_call(esp_netif_get_dns_info_api, esp_netif, (void *)&dns_param);
|
||||
}
|
||||
|
||||
static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
|
||||
esp_ip6_addr_type_t esp_netif_ip6_get_addr_type(esp_ip6_addr_t* ip6_addr)
|
||||
{
|
||||
ip6_addr_t* lwip_ip6_info = (ip6_addr_t*)ip6_addr;
|
||||
|
||||
if (ip6_addr_isglobal(lwip_ip6_info)) {
|
||||
return ESP_IP6_ADDR_IS_GLOBAL;
|
||||
} else if (ip6_addr_islinklocal(lwip_ip6_info)) {
|
||||
return ESP_IP6_ADDR_IS_LINK_LOCAL;
|
||||
} else if (ip6_addr_issitelocal(lwip_ip6_info)) {
|
||||
return ESP_IP6_ADDR_IS_SITE_LOCAL;
|
||||
} else if (ip6_addr_isuniquelocal(lwip_ip6_info)) {
|
||||
return ESP_IP6_ADDR_IS_UNIQUE_LOCAL;
|
||||
} else if (ip6_addr_isipv4mappedipv6(lwip_ip6_info)) {
|
||||
return ESP_IP6_ADDR_IS_IPV4_MAPPED_IPV6;
|
||||
}
|
||||
return ESP_IP6_ADDR_IS_UNKNOWN;
|
||||
|
||||
}
|
||||
|
||||
static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_index)
|
||||
{
|
||||
ESP_LOGD(TAG, "%s lwip-netif:%p", __func__, p_netif);
|
||||
if (!p_netif) {
|
||||
|
@ -1381,9 +1400,9 @@ static void esp_netif_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
|
|||
esp_netif_ip6_info_t ip6_info;
|
||||
ip6_addr_t lwip_ip6_info;
|
||||
//notify event
|
||||
ip_event_got_ip6_t evt = { .esp_netif = p_netif->state, .if_index = -1 };
|
||||
ip_event_got_ip6_t evt = { .esp_netif = p_netif->state, .if_index = -1, .ip_index = ip_index };
|
||||
|
||||
ip6_addr_set(&lwip_ip6_info, ip_2_ip6(&p_netif->ip6_addr[ip_idex]));
|
||||
ip6_addr_set(&lwip_ip6_info, ip_2_ip6(&p_netif->ip6_addr[ip_index]));
|
||||
#if LWIP_IPV6_SCOPES
|
||||
memcpy(&ip6_info.ip, &lwip_ip6_info, sizeof(esp_ip6_addr_t));
|
||||
#else
|
||||
|
|
|
@ -73,6 +73,8 @@ static void on_got_ipv6(void *arg, esp_event_base_t event_base,
|
|||
ESP_LOGI(TAG, "Got IPv6 event!");
|
||||
memcpy(&s_ipv6_addr, &event->ip6_info.ip, sizeof(s_ipv6_addr));
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue