mirror of
https://github.com/espressif/esp-idf.git
synced 2026-05-04 03:52:01 +02:00
ipv6 interface: add branch for ipv6 interface
This commit is contained in:
@@ -64,18 +64,22 @@ typedef struct {
|
||||
ip4_addr_t gw;
|
||||
} tcpip_adapter_ip_info_t;
|
||||
|
||||
typedef struct {
|
||||
ip6_addr_t ip;
|
||||
} tcpip_adapter_ip6_info_t;
|
||||
|
||||
typedef dhcps_lease_t tcpip_adapter_dhcps_lease_t;
|
||||
|
||||
#if CONFIG_DHCP_STA_LIST
|
||||
typedef struct {
|
||||
uint8_t mac[6];
|
||||
ip4_addr_t ip;
|
||||
}tcpip_adapter_sta_info_t;
|
||||
} tcpip_adapter_sta_info_t;
|
||||
|
||||
typedef struct {
|
||||
tcpip_adapter_sta_info_t sta[ESP_WIFI_MAX_CONN_NUM];
|
||||
int num;
|
||||
}tcpip_adapter_sta_list_t;
|
||||
} tcpip_adapter_sta_list_t;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -211,6 +215,35 @@ esp_err_t tcpip_adapter_get_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i
|
||||
*/
|
||||
esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_ip_info_t *ip_info);
|
||||
|
||||
/**
|
||||
* @brief create interface's linklocal IPv6 information
|
||||
*
|
||||
* @note this function will create a linklocal IPv6 address about input interface,
|
||||
* if this address status changed to preferred, will call event call back ,
|
||||
* notify user linklocal IPv6 address has been verified
|
||||
*
|
||||
* @param[in] tcpip_if: the interface which we want to set IP information
|
||||
*
|
||||
*
|
||||
* @return ESP_OK
|
||||
* ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
|
||||
*/
|
||||
esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if);
|
||||
|
||||
/**
|
||||
* @brief get interface's linkloacl IPv6 information
|
||||
*
|
||||
* There has an IPv6 information copy in adapter library, if interface is up,and IPv6 info
|
||||
* is preferred,it will get IPv6 linklocal IP successfully
|
||||
*
|
||||
* @param[in] tcpip_if: the interface which we want to set IP information
|
||||
* @param[in] if_ip6: If successful, IPv6 information will be returned in this argument.
|
||||
*
|
||||
* @return ESP_OK
|
||||
* ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS
|
||||
*/
|
||||
esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6);
|
||||
|
||||
#if 0
|
||||
esp_err_t tcpip_adapter_get_mac(tcpip_adapter_if_t tcpip_if, uint8_t *mac);
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
#include "lwip/tcpip.h"
|
||||
#include "lwip/dhcp.h"
|
||||
#include "lwip/ip_addr.h"
|
||||
|
||||
#include "lwip/ip6_addr.h"
|
||||
#include "lwip/nd6.h"
|
||||
#include "netif/wlanif.h"
|
||||
|
||||
#include "apps/dhcpserver.h"
|
||||
@@ -32,6 +33,7 @@
|
||||
|
||||
static struct netif *esp_netif[TCPIP_ADAPTER_IF_MAX];
|
||||
static tcpip_adapter_ip_info_t esp_ip[TCPIP_ADAPTER_IF_MAX];
|
||||
static tcpip_adapter_ip6_info_t esp_ip6[TCPIP_ADAPTER_IF_MAX];
|
||||
|
||||
static tcpip_adapter_dhcp_status_t dhcps_status = TCPIP_ADAPTER_DHCP_INIT;
|
||||
static tcpip_adapter_dhcp_status_t dhcpc_status = TCPIP_ADAPTER_DHCP_INIT;
|
||||
@@ -234,6 +236,69 @@ esp_err_t tcpip_adapter_set_ip_info(tcpip_adapter_if_t tcpip_if, tcpip_adapter_i
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
static void tcpip_adapter_nd6_cb(struct netif *p_netif, uint8_t ip_idex)
|
||||
{
|
||||
tcpip_adapter_ip6_info_t *ip6_info;
|
||||
|
||||
if (!p_netif) {
|
||||
TCPIP_ADAPTER_DEBUG("null p_netif=%p\n", p_netif);
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_netif == esp_netif[TCPIP_ADAPTER_IF_STA]) {
|
||||
ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_STA];
|
||||
} else if(p_netif == esp_netif[TCPIP_ADAPTER_IF_AP]) {
|
||||
ip6_info = &esp_ip6[TCPIP_ADAPTER_IF_AP];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
system_event_t evt;
|
||||
|
||||
ip6_addr_set(&ip6_info->ip, ip_2_ip6(&p_netif->ip6_addr[ip_idex]));
|
||||
|
||||
//notify event
|
||||
evt.event_id = SYSTEM_EVENT_AP_STA_GOT_IP6;
|
||||
memcpy(&evt.event_info.got_ip6.ip6_info, ip6_info, sizeof(tcpip_adapter_ip6_info_t));
|
||||
esp_event_send(&evt);
|
||||
}
|
||||
|
||||
esp_err_t tcpip_adapter_create_ip6_linklocal(tcpip_adapter_if_t tcpip_if)
|
||||
{
|
||||
struct netif *p_netif;
|
||||
|
||||
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX) {
|
||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
p_netif = esp_netif[tcpip_if];
|
||||
if(p_netif != NULL && netif_is_up(p_netif)) {
|
||||
netif_create_ip6_linklocal_address(p_netif, 1);
|
||||
nd6_set_cb(p_netif, tcpip_adapter_nd6_cb);
|
||||
|
||||
return ESP_OK;
|
||||
} else {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
esp_err_t tcpip_adapter_get_ip6_linklocal(tcpip_adapter_if_t tcpip_if, ip6_addr_t *if_ip6)
|
||||
{
|
||||
struct netif *p_netif;
|
||||
|
||||
if (tcpip_if >= TCPIP_ADAPTER_IF_MAX || if_ip6 == NULL) {
|
||||
return ESP_ERR_TCPIP_ADAPTER_INVALID_PARAMS;
|
||||
}
|
||||
|
||||
p_netif = esp_netif[tcpip_if];
|
||||
if (p_netif != NULL && netif_is_up(p_netif) && ip6_addr_ispreferred(netif_ip6_addr_state(p_netif, 0))) {
|
||||
memcpy(if_ip6, &p_netif->ip6_addr[0], sizeof(ip6_addr_t));
|
||||
} else {
|
||||
return ESP_FAIL;
|
||||
}
|
||||
return ESP_OK;
|
||||
}
|
||||
|
||||
#if 0
|
||||
esp_err_t tcpip_adapter_get_mac(tcpip_adapter_if_t tcpip_if, uint8_t mac[6])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user