Ethernet + IPv6 got addres but ping not work.
Posted: Thu Sep 16, 2021 9:02 am
Hello!
I try to start ESP32+Ethernet+IPv6. i use very easy code for this:
System start got IPv4 addres and IPv6. IPv4 work fine. But IPv6 not have trouble, system got valid address from router but not answer on ping. If i acirvate debug i see this message "ip6_input: packet not for us."
How i can fix this?
I try to start ESP32+Ethernet+IPv6. i use very easy code for this:
Code: Select all
#define E_ETH_PHY_ADDR 0
#define E_ETH_PHY_RST_GPIO -1
#define E_ETH_MDC_GPIO 23
#define E_ETH_MDIO_GPIO 18
static esp_eth_handle_t s_eth_handle = NULL;
static uint8_t s_eth_mac[6];
esp_netif_t *eth_netif;
static void eth_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data){
uint32_t speed, duplex;
esp_eth_handle_t eth_handle = *(esp_eth_handle_t *)event_data;
switch (event_id) {
case ETHERNET_EVENT_CONNECTED:
printf("Ethernet Link Up\r\n");
esp_eth_ioctl(eth_handle, ETH_CMD_G_SPEED, &speed);
esp_eth_ioctl(eth_handle, ETH_CMD_G_DUPLEX_MODE, &duplex);
printf("Link: %sMb\\s %s Duplex\r\n", ((speed == ETH_SPEED_100M) ? "100" : "10"), ((duplex == ETH_DUPLEX_HALF) ? "Half" : "Full"));
s_eth_mac[0] = s_eth_mac[2] = s_eth_mac[3] = s_eth_mac[4] = s_eth_mac[5] = 0xAA;
esp_eth_ioctl(eth_handle, ETH_CMD_G_MAC_ADDR, s_eth_mac);
printf("MAC:%02X:%02X:%02X:%02X:%02X:%02X\r\n", s_eth_mac[0], s_eth_mac[1], s_eth_mac[2], s_eth_mac[3], s_eth_mac[4],s_eth_mac[5]);
printf("Start DHCP: %d\r\n", esp_netif_dhcpc_start(eth_netif));
esp_netif_create_ip6_linklocal(eth_netif);
break;
case ETHERNET_EVENT_DISCONNECTED:
esp_netif_dhcpc_stop(eth_netif);
printf("Link Down\r\n");
break;
case ETHERNET_EVENT_START:
printf("Ethernet Start\r\n");
break;
case ETHERNET_EVENT_STOP:
printf("Ethernet Stop\r\n");
break;
default:
break;
}
}
static void phyPowerUp(){
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = GPIO_SEL_12;
io_conf.pull_down_en = 0;
io_conf.pull_up_en = 0;
gpio_config(&io_conf);
gpio_set_level(12, 1);
}
esp_eth_phy_t *esp_eth_phy_new_lan87xx(const eth_phy_config_t *config);
void initEthernet(){
phyPowerUp();
ESP_ERROR_CHECK(esp_event_handler_register(ETH_EVENT, ESP_EVENT_ANY_ID, eth_event_handler, 0));
eth_mac_config_t mac_config = ETH_MAC_DEFAULT_CONFIG();
eth_phy_config_t phy_config = ETH_PHY_DEFAULT_CONFIG();
phy_config.phy_addr =E_ETH_PHY_ADDR;
phy_config.reset_gpio_num = E_ETH_PHY_RST_GPIO;
esp_eth_phy_t *phy = esp_eth_phy_new_lan8720(&phy_config);
mac_config.smi_mdc_gpio_num = E_ETH_MDC_GPIO;
mac_config.smi_mdio_gpio_num = E_ETH_MDIO_GPIO;
esp_eth_mac_t *mac = esp_eth_mac_new_esp32(&mac_config);
esp_eth_config_t config = ETH_DEFAULT_CONFIG(mac, phy);
printf("esp_eth_driver_install = %d\r\n", ESP_OK == esp_eth_driver_install(&config, &s_eth_handle)); // install driver
esp_netif_config_t cfg = ESP_NETIF_DEFAULT_ETH();
eth_netif = esp_netif_new(&cfg);
esp_eth_set_default_handlers(eth_netif);
printf("ETH NETIF_ATTACH: %d\r\n", esp_netif_attach(eth_netif, esp_eth_new_netif_glue(s_eth_handle)));
printf("NETIF: %08X\r\n", (uint32_t)eth_netif);
esp_eth_start(s_eth_handle);
}
static void ip_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data){
ip_event_got_ip_t *event = (ip_event_got_ip_t *) event_data;
ip_event_got_ip6_t *event1 = (ip_event_got_ip_t *) event_data;
switch (event_id){
case IP_EVENT_GOT_IP6:{
esp_netif_ip6_info_t *ip_info = &event1->ip6_info;
printf("Ethernet Got IPv6 Address\r\n");
printf("ETH IPv6:"IPV6STR"\r\n", IPV62STR(event1->ip6_info.ip));
}break;
case IP_EVENT_ETH_GOT_IP:{
esp_netif_ip_info_t *ip_info = &event->ip_info;
printf("Ethernet Got IP Address\r\n");
printf("ETH IP:"IPSTR"\r\n", IP2STR(&ip_info->ip));
printf("ETH MASK:"IPSTR"\r\n", IP2STR(&ip_info->netmask));
printf("ETH GW:"IPSTR"\r\n", IP2STR(&ip_info->gw));
printf("IPV6 Enable: %d\r\n", esp_netif_create_ip6_linklocal(event->esp_netif));
} break;
}
}
void initIPStack(){
printf("Start IP Stack\r\n");
esp_netif_init();
esp_event_handler_register(IP_EVENT, ESP_EVENT_ANY_ID, &ip_event_handler, NULL);
}
void app_main(void){
ESP_ERROR_CHECK(esp_event_loop_create_default());
initIPStack();
initEthernet();
}
How i can fix this?